1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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
74 -- entry families of 128K should be reasonable in all cases, and is a
75 -- documented 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_Entry_Count_Expression
140 (Concurrent_Type
: Node_Id
;
141 Component_List
: List_Id
;
142 Loc
: Source_Ptr
) return Node_Id
;
143 -- Compute number of entries for concurrent object. This is a count of
144 -- simple entries, followed by an expression that computes the length
145 -- of the range of each entry family. A single array with that size is
146 -- allocated for each concurrent object of the type.
148 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
149 -- Build the function that translates the entry index in the call
150 -- (which depends on the size of entry families) into an index into the
151 -- Entry_Bodies_Array, to determine the body and barrier function used
152 -- in a protected entry call. A pointer to this function appears in every
155 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
156 -- Build subprogram declaration for previous one
158 function Build_Lock_Free_Protected_Subprogram_Body
161 Unprot_Spec
: Node_Id
) return Node_Id
;
162 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
163 -- the subprogram specification of the unprotected version of N. Transform
164 -- N such that it invokes the unprotected version of the body.
166 function Build_Lock_Free_Unprotected_Subprogram_Body
168 Prot_Typ
: Node_Id
) return Node_Id
;
169 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
170 -- of N where the original statements of N are synchronized through atomic
171 -- actions such as compare and exchange. Prior to invoking this routine, it
172 -- has been established that N can be implemented in a lock-free fashion.
174 function Build_Parameter_Block
178 Decls
: List_Id
) return Entity_Id
;
179 -- Generate an access type for each actual parameter in the list Actuals.
180 -- Create an encapsulating record that contains all the actuals and return
181 -- its type. Generate:
182 -- type Ann1 is access all <actual1-type>
184 -- type AnnN is access all <actualN-type>
185 -- type Pnn is record
191 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
192 -- Build body of wrapper procedure for an entry or entry family that has
193 -- pre/postconditions. The body gathers the PPC's and expands them in the
194 -- usual way, and performs the entry call itself. This way preconditions
195 -- are evaluated before the call is queued. E is the entry in question,
196 -- and Decl is the enclosing synchronized type declaration at whose
197 -- freeze point the generated body is analyzed.
199 function Build_Protected_Entry
202 Pid
: Node_Id
) return Node_Id
;
203 -- Build the procedure implementing the statement sequence of the specified
206 function Build_Protected_Entry_Specification
209 Ent_Id
: Entity_Id
) return Node_Id
;
210 -- Build a specification for the procedure implementing the statements of
211 -- the specified entry body. Add attributes associating it with the entry
212 -- defining identifier Ent_Id.
214 function Build_Protected_Spec
216 Obj_Type
: Entity_Id
;
218 Unprotected
: Boolean := False) return List_Id
;
219 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
220 -- Subprogram_Type. Builds signature of protected subprogram, adding the
221 -- formal that corresponds to the object itself. For an access to protected
222 -- subprogram, there is no object type to specify, so the parameter has
223 -- type Address and mode In. An indirect call through such a pointer will
224 -- convert the address to a reference to the actual object. The object is
225 -- a limited record and therefore a by_reference type.
227 function Build_Protected_Subprogram_Body
230 N_Op_Spec
: Node_Id
) return Node_Id
;
231 -- This function is used to construct the protected version of a protected
232 -- subprogram. Its statement sequence first defers abort, then locks
233 -- the associated protected object, and then enters a block that contains
234 -- a call to the unprotected version of the subprogram (for details, see
235 -- Build_Unprotected_Subprogram_Body). This block statement requires
236 -- a cleanup handler that unlocks the object in all cases.
237 -- (see Exp_Ch7.Expand_Cleanup_Actions).
239 function Build_Renamed_Formal_Declaration
243 Renamed_Formal
: Node_Id
) return Node_Id
;
244 -- Create a renaming declaration for a formal, within a protected entry
245 -- body or an accept body. The renamed object is a component of the
246 -- parameter block that is a parameter in the entry call.
248 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
249 -- does not dereference the corresponding component to prevent an illegal
250 -- use of the incomplete type (AI05-0151).
252 function Build_Selected_Name
254 Selector
: Entity_Id
;
255 Append_Char
: Character := ' ') return Name_Id
;
256 -- Build a name in the form of Prefix__Selector, with an optional
257 -- character appended. This is used for internal subprograms generated
258 -- for operations of protected types, including barrier functions.
259 -- For the subprograms generated for entry bodies and entry barriers,
260 -- the generated name includes a sequence number that makes names
261 -- unique in the presence of entry overloading. This is necessary
262 -- because entry body procedures and barrier functions all have the
265 procedure Build_Simple_Entry_Call
270 -- Some comments here would be useful ???
272 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
273 -- This routine constructs a specification for the procedure that we will
274 -- build for the task body for task type T. The spec has the form:
276 -- procedure tnameB (_Task : access tnameV);
278 -- where name is the character name taken from the task type entity that
279 -- is passed as the argument to the procedure, and tnameV is the task
280 -- value type that is associated with the task type.
282 function Build_Unprotected_Subprogram_Body
284 Pid
: Node_Id
) return Node_Id
;
285 -- This routine constructs the unprotected version of a protected
286 -- subprogram body, which is contains all of the code in the
287 -- original, unexpanded body. This is the version of the protected
288 -- subprogram that is called from all protected operations on the same
289 -- object, including the protected version of the same subprogram.
291 procedure Build_Wrapper_Bodies
295 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
296 -- record of a concurrent type. N is the insertion node where all bodies
297 -- will be placed. This routine builds the bodies of the subprograms which
298 -- serve as an indirection mechanism to overriding primitives of concurrent
299 -- types, entries and protected procedures. Any new body is analyzed.
301 procedure Build_Wrapper_Specs
305 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
306 -- record of a concurrent type. N is the insertion node where all specs
307 -- will be placed. This routine builds the specs of the subprograms which
308 -- serve as an indirection mechanism to overriding primitives of concurrent
309 -- types, entries and protected procedures. Any new spec is analyzed.
311 procedure Collect_Entry_Families
314 Current_Node
: in out Node_Id
;
315 Conctyp
: Entity_Id
);
316 -- For each entry family in a concurrent type, create an anonymous array
317 -- type of the right size, and add a component to the corresponding_record.
319 function Concurrent_Object
320 (Spec_Id
: Entity_Id
;
321 Conc_Typ
: Entity_Id
) return Entity_Id
;
322 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
323 -- the entity associated with the concurrent object in the Protected_Body_
324 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
325 -- denotes formal parameter _O, _object or _task.
327 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
328 -- Copy the result type of a function specification, when building the
329 -- internal operation corresponding to a protected function, or when
330 -- expanding an access to protected function. If the result is an anonymous
331 -- access to subprogram itself, we need to create a new signature with the
332 -- same parameter names and the same resolved types, but with new entities
335 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
336 -- Decls is a list which may contain the declarations created by Install_
337 -- Private_Data_Declarations. All generated entities are marked as needing
338 -- debug info and debug nodes are manually generation where necessary. This
339 -- step of the expansion must to be done after private data has been moved
340 -- to its final resting scope to ensure proper visibility of debug objects.
342 procedure Extract_Dispatching_Call
344 Call_Ent
: out Entity_Id
;
345 Object
: out Entity_Id
;
346 Actuals
: out List_Id
;
347 Formals
: out List_Id
);
348 -- Given a dispatching call, extract the entity of the name of the call,
349 -- its actual dispatching object, its actual parameters and the formal
350 -- parameters of the overridden interface-level version. If the type of
351 -- the dispatching object is an access type then an explicit dereference
352 -- is returned in Object.
354 procedure Extract_Entry
356 Concval
: out Node_Id
;
358 Index
: out Node_Id
);
359 -- Given an entry call, returns the associated concurrent object,
360 -- the entry name, and the entry family index.
362 function Family_Offset
367 Cap
: Boolean) return Node_Id
;
368 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in
369 -- an accept statement, or the upper bound in the discrete subtype of
370 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
371 -- the concurrent type of the entry. If Cap is true, the result is
372 -- capped according to Entry_Family_Bound.
379 Cap
: Boolean) return Node_Id
;
380 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
381 -- a family, and handle properly the superflat case. This is equivalent
382 -- to the use of 'Length on the index type, but must use Family_Offset
383 -- to handle properly the case of bounds that depend on discriminants.
384 -- If Cap is true, the result is capped according to Entry_Family_Bound.
386 procedure Find_Enclosing_Context
388 Context
: out Node_Id
;
389 Context_Id
: out Entity_Id
;
390 Context_Decls
: out List_Id
);
391 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
392 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
393 -- nearest enclosing body, block, package or return statement and return
394 -- its constituents. Context is the enclosing construct, Context_Id is
395 -- the scope of Context_Id and Context_Decls is the declarative list of
398 function Find_Task_Or_Protected_Pragma
400 P
: Name_Id
) return Node_Id
;
401 -- Searches the task or protected definition T for the first occurrence
402 -- of the pragma whose name is given by P. The caller has ensured that
403 -- the pragma is present in the task definition. A special case is that
404 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
405 -- ??? Should be implemented with the rep item chain mechanism.
407 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
408 -- Given a subprogram identifier, return the entity which is associated
409 -- with the protection entry index in the Protected_Body_Subprogram or the
410 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
413 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
414 -- Tell whether a given subprogram cannot raise an exception
416 function Is_Potentially_Large_Family
417 (Base_Index
: Entity_Id
;
420 Hi
: Node_Id
) return Boolean;
422 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
423 -- Determine whether Id is a function or a procedure and is marked as a
424 -- private primitive.
426 function Null_Statements
(Stats
: List_Id
) return Boolean;
427 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
428 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
429 -- well to still count as null. Returns True for a null sequence. The
430 -- argument is the list of statements from the DO-END sequence.
432 function Parameter_Block_Pack
438 Stmts
: List_Id
) return Entity_Id
;
439 -- Set the components of the generated parameter block with the values of
440 -- the actual parameters. Generate aliased temporaries to capture the
441 -- values for types that are passed by copy. Otherwise generate a reference
442 -- to the actual's value. Return the address of the aggregate block.
444 -- Jnn1 : alias <formal-type1>;
445 -- Jnn1 := <actual1>;
448 -- Jnn1'unchecked_access;
449 -- <actual2>'reference;
452 function Parameter_Block_Unpack
456 Formals
: List_Id
) return List_Id
;
457 -- Retrieve the values of the components from the parameter block and
458 -- assign then to the original actual parameters. Generate:
459 -- <actual1> := P.<formal1>;
461 -- <actualN> := P.<formalN>;
463 function Trivial_Accept_OK
return Boolean;
464 -- If there is no DO-END block for an accept, or if the DO-END block has
465 -- only null statements, then it is possible to do the Rendezvous with much
466 -- less overhead using the Accept_Trivial routine in the run-time library.
467 -- However, this is not always a valid optimization. Whether it is valid or
468 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
469 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
470 -- a rescheduling is required, so this optimization is not allowed. This
471 -- function returns True if the optimization is permitted.
473 -----------------------------
474 -- Actual_Index_Expression --
475 -----------------------------
477 function Actual_Index_Expression
481 Tsk
: Entity_Id
) return Node_Id
483 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
491 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
492 -- Compute difference between bounds of entry family
494 --------------------------
495 -- Actual_Family_Offset --
496 --------------------------
498 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
500 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
501 -- Replace a reference to a discriminant with a selected component
502 -- denoting the discriminant of the target task.
504 -----------------------------
505 -- Actual_Discriminant_Ref --
506 -----------------------------
508 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
509 Typ
: constant Entity_Id
:= Etype
(Bound
);
513 if not Is_Entity_Name
(Bound
)
514 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
516 if Nkind
(Bound
) = N_Attribute_Reference
then
519 B
:= New_Copy_Tree
(Bound
);
524 Make_Selected_Component
(Sloc
,
525 Prefix
=> New_Copy_Tree
(Tsk
),
526 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
528 Analyze_And_Resolve
(B
, Typ
);
532 Make_Attribute_Reference
(Sloc
,
533 Attribute_Name
=> Name_Pos
,
534 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
535 Expressions
=> New_List
(B
));
536 end Actual_Discriminant_Ref
;
538 -- Start of processing for Actual_Family_Offset
542 Make_Op_Subtract
(Sloc
,
543 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
544 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
545 end Actual_Family_Offset
;
547 -- Start of processing for Actual_Index_Expression
550 -- The queues of entries and entry families appear in textual order in
551 -- the associated record. The entry index is computed as the sum of the
552 -- number of queues for all entries that precede the designated one, to
553 -- which is added the index expression, if this expression denotes a
554 -- member of a family.
556 -- The following is a place holder for the count of simple entries
558 Num
:= Make_Integer_Literal
(Sloc
, 1);
560 -- We construct an expression which is a series of addition operations.
561 -- See comments in Entry_Index_Expression, which is identical in
564 if Present
(Index
) then
565 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
572 Actual_Family_Offset
(
573 Make_Attribute_Reference
(Sloc
,
574 Attribute_Name
=> Name_Pos
,
575 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
576 Expressions
=> New_List
(Relocate_Node
(Index
))),
577 Type_Low_Bound
(S
)));
582 -- Now add lengths of preceding entries and entry families
584 Prev
:= First_Entity
(Ttyp
);
586 while Chars
(Prev
) /= Chars
(Ent
)
587 or else (Ekind
(Prev
) /= Ekind
(Ent
))
588 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
590 if Ekind
(Prev
) = E_Entry
then
591 Set_Intval
(Num
, Intval
(Num
) + 1);
593 elsif Ekind
(Prev
) = E_Entry_Family
then
595 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
597 -- The need for the following full view retrieval stems from
598 -- this complex case of nested generics and tasking:
601 -- type Formal_Index is range <>;
604 -- type Index is private;
611 -- type Index is new Formal_Index range 1 .. 10;
614 -- package body Outer is
616 -- entry Fam (Index); -- (2)
619 -- package body Inner is -- (3)
627 -- We are currently building the index expression for the entry
628 -- call "T.E" (1). Part of the expansion must mention the range
629 -- of the discrete type "Index" (2) of entry family "Fam".
630 -- However only the private view of type "Index" is available to
631 -- the inner generic (3) because there was no prior mention of
632 -- the type inside "Inner". This visibility requirement is
633 -- implicit and cannot be detected during the construction of
634 -- the generic trees and needs special handling.
637 and then Is_Private_Type
(S
)
638 and then Present
(Full_View
(S
))
643 Lo
:= Type_Low_Bound
(S
);
644 Hi
:= Type_High_Bound
(S
);
652 Actual_Family_Offset
(Hi
, Lo
),
654 Make_Integer_Literal
(Sloc
, 1)));
656 -- Other components are anonymous types to be ignored
666 end Actual_Index_Expression
;
668 --------------------------
669 -- Add_Formal_Renamings --
670 --------------------------
672 procedure Add_Formal_Renamings
678 Ptr
: constant Entity_Id
:=
680 (Next
(First
(Parameter_Specifications
(Spec
))));
681 -- The name of the formal that holds the address of the parameter block
688 Renamed_Formal
: Node_Id
;
691 Formal
:= First_Formal
(Ent
);
692 while Present
(Formal
) loop
693 Comp
:= Entry_Component
(Formal
);
695 Make_Defining_Identifier
(Sloc
(Formal
),
696 Chars
=> Chars
(Formal
));
697 Set_Etype
(New_F
, Etype
(Formal
));
698 Set_Scope
(New_F
, Ent
);
700 -- Now we set debug info needed on New_F even though it does not
701 -- come from source, so that the debugger will get the right
702 -- information for these generated names.
704 Set_Debug_Info_Needed
(New_F
);
706 if Ekind
(Formal
) = E_In_Parameter
then
707 Set_Ekind
(New_F
, E_Constant
);
709 Set_Ekind
(New_F
, E_Variable
);
710 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
713 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
716 Make_Selected_Component
(Loc
,
718 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
719 Make_Identifier
(Loc
, Chars
(Ptr
))),
720 Selector_Name
=> New_Reference_To
(Comp
, Loc
));
723 Build_Renamed_Formal_Declaration
724 (New_F
, Formal
, Comp
, Renamed_Formal
);
726 Append
(Decl
, Decls
);
727 Set_Renamed_Object
(Formal
, New_F
);
728 Next_Formal
(Formal
);
730 end Add_Formal_Renamings
;
732 ------------------------
733 -- Add_Object_Pointer --
734 ------------------------
736 procedure Add_Object_Pointer
738 Conc_Typ
: Entity_Id
;
741 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
746 -- Create the renaming declaration for the Protection object of a
747 -- protected type. _Object is used by Complete_Entry_Body.
748 -- ??? An attempt to make this a renaming was unsuccessful.
750 -- Build the entity for the access type
753 Make_Defining_Identifier
(Loc
,
754 New_External_Name
(Chars
(Rec_Typ
), 'P'));
757 -- _object : poVP := poVP!O;
760 Make_Object_Declaration
(Loc
,
761 Defining_Identifier
=>
762 Make_Defining_Identifier
(Loc
, Name_uObject
),
764 New_Reference_To
(Obj_Ptr
, Loc
),
766 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
767 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
768 Prepend_To
(Decls
, Decl
);
771 -- type poVP is access poV;
774 Make_Full_Type_Declaration
(Loc
,
775 Defining_Identifier
=>
778 Make_Access_To_Object_Definition
(Loc
,
779 Subtype_Indication
=>
780 New_Reference_To
(Rec_Typ
, Loc
)));
781 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
782 Prepend_To
(Decls
, Decl
);
783 end Add_Object_Pointer
;
785 -----------------------
786 -- Build_Accept_Body --
787 -----------------------
789 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
790 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
791 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
798 -- At the end of the statement sequence, Complete_Rendezvous is called.
799 -- A label skipping the Complete_Rendezvous, and all other accept
800 -- processing, has already been added for the expansion of requeue
801 -- statements. The Sloc is copied from the last statement since it
802 -- is really part of this last statement.
806 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
807 Insert_Before
(Last
(Statements
(Stats
)), Call
);
810 -- If exception handlers are present, then append Complete_Rendezvous
811 -- calls to the handlers, and construct the required outer block. As
812 -- above, the Sloc is copied from the last statement in the sequence.
814 if Present
(Exception_Handlers
(Stats
)) then
815 Hand
:= First
(Exception_Handlers
(Stats
));
816 while Present
(Hand
) loop
819 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
820 Append
(Call
, Statements
(Hand
));
826 Make_Handled_Sequence_Of_Statements
(Loc
,
827 Statements
=> New_List
(
828 Make_Block_Statement
(Loc
,
829 Handled_Statement_Sequence
=> Stats
)));
835 -- At this stage we know that the new statement sequence does not
836 -- have an exception handler part, so we supply one to call
837 -- Exceptional_Complete_Rendezvous. This handler is
839 -- when all others =>
840 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
842 -- We handle Abort_Signal to make sure that we properly catch the abort
843 -- case and wake up the caller.
845 Ohandle
:= Make_Others_Choice
(Loc
);
846 Set_All_Others
(Ohandle
);
848 Set_Exception_Handlers
(New_S
,
850 Make_Implicit_Exception_Handler
(Loc
,
851 Exception_Choices
=> New_List
(Ohandle
),
853 Statements
=> New_List
(
854 Make_Procedure_Call_Statement
(Sloc
(Stats
),
855 Name
=> New_Reference_To
(
856 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
857 Parameter_Associations
=> New_List
(
858 Make_Function_Call
(Sloc
(Stats
),
859 Name
=> New_Reference_To
(
860 RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
862 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
863 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
864 Expand_Exception_Handlers
(New_S
);
866 -- Exceptional_Complete_Rendezvous must be called with abort
867 -- still deferred, which is the case for a "when all others" handler.
870 end Build_Accept_Body
;
872 -----------------------------------
873 -- Build_Activation_Chain_Entity --
874 -----------------------------------
876 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
877 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
878 -- Determine whether an extended return statement has an activation
881 --------------------------
882 -- Has_Activation_Chain --
883 --------------------------
885 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
889 Decl
:= First
(Return_Object_Declarations
(Stmt
));
890 while Present
(Decl
) loop
891 if Nkind
(Decl
) = N_Object_Declaration
892 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
901 end Has_Activation_Chain
;
906 Context_Id
: Entity_Id
;
909 -- Start of processing for Build_Activation_Chain_Entity
912 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
914 -- If an activation chain entity has not been declared already, create
917 if Nkind
(Context
) = N_Extended_Return_Statement
918 or else No
(Activation_Chain_Entity
(Context
))
920 -- Since extended return statements do not store the entity of the
921 -- chain, examine the return object declarations to avoid creating
924 if Nkind
(Context
) = N_Extended_Return_Statement
925 and then Has_Activation_Chain
(Context
)
931 Loc
: constant Source_Ptr
:= Sloc
(Context
);
936 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
938 -- Note: An extended return statement is not really a task
939 -- activator, but it does have an activation chain on which to
940 -- store the tasks temporarily. On successful return, the tasks
941 -- on this chain are moved to the chain passed in by the caller.
942 -- We do not build an Activation_Chain_Entity for an extended
943 -- return statement, because we do not want to build a call to
944 -- Activate_Tasks. Task activation is the responsibility of the
947 if Nkind
(Context
) /= N_Extended_Return_Statement
then
948 Set_Activation_Chain_Entity
(Context
, Chain
);
952 Make_Object_Declaration
(Loc
,
953 Defining_Identifier
=> Chain
,
954 Aliased_Present
=> True,
956 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
));
958 Prepend_To
(Decls
, Decl
);
960 -- Ensure that the _chain appears in the proper scope of the
963 if Context_Id
/= Current_Scope
then
964 Push_Scope
(Context_Id
);
972 end Build_Activation_Chain_Entity
;
974 ----------------------------
975 -- Build_Barrier_Function --
976 ----------------------------
978 function Build_Barrier_Function
981 Pid
: Node_Id
) return Node_Id
983 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
984 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
985 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
986 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
987 Op_Decls
: constant List_Id
:= New_List
;
992 -- Add a declaration for the Protection object, renaming declarations
993 -- for the discriminals and privals and finally a declaration for the
994 -- entry family index (if applicable).
996 Install_Private_Data_Declarations
(Sloc
(N
),
1002 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1004 -- If compiling with -fpreserve-control-flow, make sure we insert an
1005 -- IF statement so that the back-end knows to generate a conditional
1006 -- branch instruction, even if the condition is just the name of a
1009 if Opt
.Suppress_Control_Flow_Optimizations
then
1010 Stmt
:= Make_Implicit_If_Statement
(Cond
,
1012 Then_Statements
=> New_List
(
1013 Make_Simple_Return_Statement
(Loc
,
1014 New_Occurrence_Of
(Standard_True
, Loc
))),
1015 Else_Statements
=> New_List
(
1016 Make_Simple_Return_Statement
(Loc
,
1017 New_Occurrence_Of
(Standard_False
, Loc
))));
1020 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1023 -- Note: the condition in the barrier function needs to be properly
1024 -- processed for the C/Fortran boolean possibility, but this happens
1025 -- automatically since the return statement does this normalization.
1028 Make_Subprogram_Body
(Loc
,
1030 Build_Barrier_Function_Specification
(Loc
,
1031 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1032 Declarations
=> Op_Decls
,
1033 Handled_Statement_Sequence
=>
1034 Make_Handled_Sequence_Of_Statements
(Loc
,
1035 Statements
=> New_List
(Stmt
)));
1036 Set_Is_Entry_Barrier_Function
(Func_Body
);
1039 end Build_Barrier_Function
;
1041 ------------------------------------------
1042 -- Build_Barrier_Function_Specification --
1043 ------------------------------------------
1045 function Build_Barrier_Function_Specification
1047 Def_Id
: Entity_Id
) return Node_Id
1050 Set_Debug_Info_Needed
(Def_Id
);
1052 return Make_Function_Specification
(Loc
,
1053 Defining_Unit_Name
=> Def_Id
,
1054 Parameter_Specifications
=> New_List
(
1055 Make_Parameter_Specification
(Loc
,
1056 Defining_Identifier
=>
1057 Make_Defining_Identifier
(Loc
, Name_uO
),
1059 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1061 Make_Parameter_Specification
(Loc
,
1062 Defining_Identifier
=>
1063 Make_Defining_Identifier
(Loc
, Name_uE
),
1065 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1067 Result_Definition
=>
1068 New_Reference_To
(Standard_Boolean
, Loc
));
1069 end Build_Barrier_Function_Specification
;
1071 --------------------------
1072 -- Build_Call_With_Task --
1073 --------------------------
1075 function Build_Call_With_Task
1077 E
: Entity_Id
) return Node_Id
1079 Loc
: constant Source_Ptr
:= Sloc
(N
);
1082 Make_Function_Call
(Loc
,
1083 Name
=> New_Reference_To
(E
, Loc
),
1084 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1085 end Build_Call_With_Task
;
1087 -----------------------------
1088 -- Build_Class_Wide_Master --
1089 -----------------------------
1091 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1092 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1093 Master_Id
: Entity_Id
;
1094 Master_Scope
: Entity_Id
;
1096 Related_Node
: Node_Id
;
1100 -- Nothing to do if there is no task hierarchy
1102 if Restriction_Active
(No_Task_Hierarchy
) then
1106 -- Find the declaration that created the access type. It is either a
1107 -- type declaration, or an object declaration with an access definition,
1108 -- in which case the type is anonymous.
1110 if Is_Itype
(Typ
) then
1111 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1113 Related_Node
:= Parent
(Typ
);
1116 Master_Scope
:= Find_Master_Scope
(Typ
);
1118 -- Nothing to do if the master scope already contains a _master entity.
1119 -- The only exception to this is the following scenario:
1122 -- Transient_Scope_1
1125 -- Transient_Scope_2
1128 -- In this case the source scope is marked as having the master entity
1129 -- even though the actual declaration appears inside an inner scope. If
1130 -- the second transient scope requires a _master, it cannot use the one
1131 -- already declared because the entity is not visible.
1133 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1135 if not Has_Master_Entity
(Master_Scope
)
1136 or else No
(Current_Entity_In_Scope
(Name_Id
))
1139 Master_Decl
: Node_Id
;
1142 Set_Has_Master_Entity
(Master_Scope
);
1145 -- _master : constant Integer := Current_Master.all;
1148 Make_Object_Declaration
(Loc
,
1149 Defining_Identifier
=>
1150 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1151 Constant_Present
=> True,
1152 Object_Definition
=>
1153 New_Reference_To
(Standard_Integer
, Loc
),
1155 Make_Explicit_Dereference
(Loc
,
1156 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
1158 Insert_Action
(Related_Node
, Master_Decl
);
1159 Analyze
(Master_Decl
);
1161 -- Mark the containing scope as a task master. Masters associated
1162 -- with return statements are already marked at this stage (see
1163 -- Analyze_Subprogram_Body).
1165 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1167 Par
: Node_Id
:= Related_Node
;
1170 while Nkind
(Par
) /= N_Compilation_Unit
loop
1171 Par
:= Parent
(Par
);
1173 -- If we fall off the top, we are at the outer level, and
1174 -- the environment task is our effective master, so
1177 if Nkind_In
(Par
, N_Block_Statement
,
1181 Set_Is_Task_Master
(Par
);
1191 Make_Defining_Identifier
(Loc
,
1192 New_External_Name
(Chars
(Typ
), 'M'));
1195 -- Mnn renames _master;
1198 Make_Object_Renaming_Declaration
(Loc
,
1199 Defining_Identifier
=> Master_Id
,
1200 Subtype_Mark
=> New_Reference_To
(Standard_Integer
, Loc
),
1203 Insert_Action
(Related_Node
, Ren_Decl
);
1205 Set_Master_Id
(Typ
, Master_Id
);
1206 end Build_Class_Wide_Master
;
1208 --------------------------------
1209 -- Build_Corresponding_Record --
1210 --------------------------------
1212 function Build_Corresponding_Record
1215 Loc
: Source_Ptr
) return Node_Id
1217 Rec_Ent
: constant Entity_Id
:=
1218 Make_Defining_Identifier
1219 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1222 New_Disc
: Entity_Id
;
1226 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1227 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1228 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1229 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1230 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1231 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1234 -- Use discriminals to create list of discriminants for record, and
1235 -- create new discriminals for use in default expressions, etc. It is
1236 -- worth noting that a task discriminant gives rise to 5 entities;
1238 -- a) The original discriminant.
1239 -- b) The discriminal for use in the task.
1240 -- c) The discriminant of the corresponding record.
1241 -- d) The discriminal for the init proc of the corresponding record.
1242 -- e) The local variable that renames the discriminant in the procedure
1243 -- for the task body.
1245 -- In fact the discriminals b) are used in the renaming declarations
1246 -- for e). See details in einfo (Handling of Discriminants).
1248 if Present
(Discriminant_Specifications
(N
)) then
1250 Disc
:= First_Discriminant
(Ctyp
);
1252 while Present
(Disc
) loop
1253 New_Disc
:= CR_Discriminant
(Disc
);
1256 Make_Discriminant_Specification
(Loc
,
1257 Defining_Identifier
=> New_Disc
,
1258 Discriminant_Type
=>
1259 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1261 New_Copy
(Discriminant_Default_Value
(Disc
))));
1263 Next_Discriminant
(Disc
);
1270 -- Now we can construct the record type declaration. Note that this
1271 -- record is "limited tagged". It is "limited" to reflect the underlying
1272 -- limitedness of the task or protected object that it represents, and
1273 -- ensuring for example that it is properly passed by reference. It is
1274 -- "tagged" to give support to dispatching calls through interfaces. We
1275 -- propagate here the list of interfaces covered by the concurrent type
1276 -- (Ada 2005: AI-345).
1279 Make_Full_Type_Declaration
(Loc
,
1280 Defining_Identifier
=> Rec_Ent
,
1281 Discriminant_Specifications
=> Dlist
,
1283 Make_Record_Definition
(Loc
,
1285 Make_Component_List
(Loc
,
1286 Component_Items
=> Cdecls
),
1288 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1289 Interface_List
=> Interface_List
(N
),
1290 Limited_Present
=> True));
1291 end Build_Corresponding_Record
;
1293 ----------------------------------
1294 -- Build_Entry_Count_Expression --
1295 ----------------------------------
1297 function Build_Entry_Count_Expression
1298 (Concurrent_Type
: Node_Id
;
1299 Component_List
: List_Id
;
1300 Loc
: Source_Ptr
) return Node_Id
1312 -- Count number of non-family entries
1315 Ent
:= First_Entity
(Concurrent_Type
);
1316 while Present
(Ent
) loop
1317 if Ekind
(Ent
) = E_Entry
then
1324 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1326 -- Loop through entry families building the addition nodes
1328 Ent
:= First_Entity
(Concurrent_Type
);
1329 Comp
:= First
(Component_List
);
1330 while Present
(Ent
) loop
1331 if Ekind
(Ent
) = E_Entry_Family
then
1332 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1336 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1337 Hi
:= Type_High_Bound
(Typ
);
1338 Lo
:= Type_Low_Bound
(Typ
);
1339 Large
:= Is_Potentially_Large_Family
1340 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1343 Left_Opnd
=> Ecount
,
1344 Right_Opnd
=> Family_Size
1345 (Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1352 end Build_Entry_Count_Expression
;
1354 -----------------------
1355 -- Build_Entry_Names --
1356 -----------------------
1358 function Build_Entry_Names
(Conc_Typ
: Entity_Id
) return Node_Id
is
1359 Loc
: constant Source_Ptr
:= Sloc
(Conc_Typ
);
1365 Typ
: Entity_Id
:= Conc_Typ
;
1367 procedure Build_Entry_Family_Name
(Id
: Entity_Id
);
1369 -- for Lnn in Family_Low .. Family_High loop
1372 -- (_init._object <or> _init._task_id,
1374 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1376 -- Note that the bounds of the range may reference discriminants. The
1377 -- above construct is added directly to the statements of the block.
1379 procedure Build_Entry_Name
(Id
: Entity_Id
);
1383 -- (_init._object <or>_init._task_id,
1385 -- new String ("<Entry name>");
1386 -- The above construct is added directly to the statements of the block.
1388 function Build_Set_Entry_Name_Call
(Arg3
: Node_Id
) return Node_Id
;
1389 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1390 -- _init._task_id or _init._object, Inn and Arg3.
1392 procedure Increment_Index
(Stmts
: List_Id
);
1393 -- Generate the following and add it to Stmts
1396 -----------------------------
1397 -- Build_Entry_Family_Name --
1398 -----------------------------
1400 procedure Build_Entry_Family_Name
(Id
: Entity_Id
) is
1401 Def
: constant Node_Id
:=
1402 Discrete_Subtype_Definition
(Parent
(Id
));
1403 L_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
1404 L_Stmts
: constant List_Id
:= New_List
;
1407 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1408 -- Given a discrete subtype definition of an entry family, generate a
1409 -- range node which covers the range of Def's type.
1415 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1416 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1417 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1420 -- If a bound references a discriminant, generate an identifier
1421 -- with the same name. Resolution will map it to the formals of
1424 if Is_Entity_Name
(Low
)
1425 and then Ekind
(Entity
(Low
)) = E_Discriminant
1427 Low
:= Make_Identifier
(Loc
, Chars
(Low
));
1429 Low
:= New_Copy_Tree
(Low
);
1432 if Is_Entity_Name
(High
)
1433 and then Ekind
(Entity
(High
)) = E_Discriminant
1435 High
:= Make_Identifier
(Loc
, Chars
(High
));
1437 High
:= New_Copy_Tree
(High
);
1443 High_Bound
=> High
);
1446 -- Start of processing for Build_Entry_Family_Name
1449 Get_Name_String
(Chars
(Id
));
1451 -- Add a leading '('
1453 Add_Char_To_Name_Buffer
('(');
1456 -- new String'("<Entry name>(" & Lnn'Img & ")");
1458 -- This is an implicit heap allocation, and Comes_From_Source is
1459 -- False, which ensures that it will get flagged as a violation of
1460 -- No_Implicit_Heap_Allocations when that restriction applies.
1463 Make_Allocator
(Loc
,
1464 Make_Qualified_Expression
(Loc
,
1466 New_Reference_To
(Standard_String
, Loc
),
1468 Make_Op_Concat
(Loc
,
1470 Make_Op_Concat
(Loc
,
1472 Make_String_Literal
(Loc
,
1473 Strval
=> String_From_Name_Buffer
),
1475 Make_Attribute_Reference
(Loc
,
1477 New_Reference_To
(L_Id
, Loc
),
1478 Attribute_Name
=> Name_Img
)),
1480 Make_String_Literal
(Loc
,
1483 Increment_Index
(L_Stmts
);
1484 Append_To
(L_Stmts
, Build_Set_Entry_Name_Call
(Val
));
1487 -- for Lnn in Family_Low .. Family_High loop
1490 -- (_init._object <or> _init._task_id, Inn, <Val>);
1494 Make_Loop_Statement
(Loc
,
1496 Make_Iteration_Scheme
(Loc
,
1497 Loop_Parameter_Specification
=>
1498 Make_Loop_Parameter_Specification
(Loc
,
1499 Defining_Identifier
=> L_Id
,
1500 Discrete_Subtype_Definition
=> Build_Range
(Def
))),
1501 Statements
=> L_Stmts
,
1502 End_Label
=> Empty
));
1503 end Build_Entry_Family_Name
;
1505 ----------------------
1506 -- Build_Entry_Name --
1507 ----------------------
1509 procedure Build_Entry_Name
(Id
: Entity_Id
) is
1513 Get_Name_String
(Chars
(Id
));
1515 -- This is an implicit heap allocation, and Comes_From_Source is
1516 -- False, which ensures that it will get flagged as a violation of
1517 -- No_Implicit_Heap_Allocations when that restriction applies.
1520 Make_Allocator
(Loc
,
1521 Make_Qualified_Expression
(Loc
,
1523 New_Reference_To
(Standard_String
, Loc
),
1525 Make_String_Literal
(Loc
,
1526 String_From_Name_Buffer
)));
1528 Increment_Index
(B_Stmts
);
1529 Append_To
(B_Stmts
, Build_Set_Entry_Name_Call
(Val
));
1530 end Build_Entry_Name
;
1532 -------------------------------
1533 -- Build_Set_Entry_Name_Call --
1534 -------------------------------
1536 function Build_Set_Entry_Name_Call
(Arg3
: Node_Id
) return Node_Id
is
1541 -- Determine the proper name for the first argument and the RTS
1544 if Is_Protected_Type
(Typ
) then
1545 Arg1
:= Name_uObject
;
1546 Proc
:= RO_PE_Set_Entry_Name
;
1548 else pragma Assert
(Is_Task_Type
(Typ
));
1549 Arg1
:= Name_uTask_Id
;
1550 Proc
:= RO_TS_Set_Entry_Name
;
1554 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1557 Make_Procedure_Call_Statement
(Loc
,
1559 New_Reference_To
(RTE
(Proc
), Loc
),
1560 Parameter_Associations
=> New_List
(
1561 Make_Selected_Component
(Loc
, -- _init._object
1562 Prefix
=> -- _init._task_id
1563 Make_Identifier
(Loc
, Name_uInit
),
1565 Make_Identifier
(Loc
, Arg1
)),
1566 New_Reference_To
(Index
, Loc
), -- Inn
1568 end Build_Set_Entry_Name_Call
;
1570 ---------------------
1571 -- Increment_Index --
1572 ---------------------
1574 procedure Increment_Index
(Stmts
: List_Id
) is
1580 Make_Assignment_Statement
(Loc
,
1582 New_Reference_To
(Index
, Loc
),
1586 New_Reference_To
(Index
, Loc
),
1588 Make_Integer_Literal
(Loc
, 1))));
1589 end Increment_Index
;
1591 -- Start of processing for Build_Entry_Names
1594 -- Retrieve the original concurrent type
1596 if Is_Concurrent_Record_Type
(Typ
) then
1597 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1600 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
1602 -- Nothing to do if the type has no entries
1604 if not Has_Entries
(Typ
) then
1608 -- Avoid generating entry names for a protected type with only one entry
1610 if Is_Protected_Type
(Typ
)
1611 and then Find_Protection_Type
(Typ
) /= RTE
(RE_Protection_Entries
)
1616 Index
:= Make_Temporary
(Loc
, 'I');
1618 -- Step 1: Generate the declaration of the index variable:
1619 -- Inn : Protected_Entry_Index := 0;
1621 -- Inn : Task_Entry_Index := 0;
1623 if Is_Protected_Type
(Typ
) then
1624 Index_Typ
:= RE_Protected_Entry_Index
;
1626 Index_Typ
:= RE_Task_Entry_Index
;
1629 B_Decls
:= New_List
;
1631 Make_Object_Declaration
(Loc
,
1632 Defining_Identifier
=> Index
,
1633 Object_Definition
=> New_Reference_To
(RTE
(Index_Typ
), Loc
),
1634 Expression
=> Make_Integer_Literal
(Loc
, 0)));
1636 B_Stmts
:= New_List
;
1638 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1641 Comp
:= First_Entity
(Typ
);
1642 while Present
(Comp
) loop
1643 if Ekind
(Comp
) = E_Entry
then
1644 Build_Entry_Name
(Comp
);
1646 elsif Ekind
(Comp
) = E_Entry_Family
then
1647 Build_Entry_Family_Name
(Comp
);
1653 -- Step 3: Wrap the statements in a block
1656 Make_Block_Statement
(Loc
,
1657 Declarations
=> B_Decls
,
1658 Handled_Statement_Sequence
=>
1659 Make_Handled_Sequence_Of_Statements
(Loc
,
1660 Statements
=> B_Stmts
));
1661 end Build_Entry_Names
;
1663 ---------------------------
1664 -- Build_Parameter_Block --
1665 ---------------------------
1667 function Build_Parameter_Block
1671 Decls
: List_Id
) return Entity_Id
1677 Has_Comp
: Boolean := False;
1681 Actual
:= First
(Actuals
);
1683 Formal
:= Defining_Identifier
(First
(Formals
));
1685 while Present
(Actual
) loop
1686 if not Is_Controlling_Actual
(Actual
) then
1689 -- type Ann is access all <actual-type>
1691 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1694 Make_Full_Type_Declaration
(Loc
,
1695 Defining_Identifier
=> Comp_Nam
,
1697 Make_Access_To_Object_Definition
(Loc
,
1698 All_Present
=> True,
1699 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1700 Subtype_Indication
=>
1701 New_Reference_To
(Etype
(Actual
), Loc
))));
1707 Make_Component_Declaration
(Loc
,
1708 Defining_Identifier
=>
1709 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1710 Component_Definition
=>
1711 Make_Component_Definition
(Loc
,
1714 Subtype_Indication
=>
1715 New_Reference_To
(Comp_Nam
, Loc
))));
1720 Next_Actual
(Actual
);
1721 Next_Formal_With_Extras
(Formal
);
1724 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1729 -- type Pnn is record
1734 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1735 -- the original parameter names and Ann1 .. AnnN are the access to
1739 Make_Full_Type_Declaration
(Loc
,
1740 Defining_Identifier
=>
1743 Make_Record_Definition
(Loc
,
1745 Make_Component_List
(Loc
, Comps
))));
1748 -- type Pnn is null record;
1751 Make_Full_Type_Declaration
(Loc
,
1752 Defining_Identifier
=>
1755 Make_Record_Definition
(Loc
,
1756 Null_Present
=> True,
1757 Component_List
=> Empty
)));
1761 end Build_Parameter_Block
;
1763 --------------------------------------
1764 -- Build_Renamed_Formal_Declaration --
1765 --------------------------------------
1767 function Build_Renamed_Formal_Declaration
1771 Renamed_Formal
: Node_Id
) return Node_Id
1773 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1777 -- If the formal is a tagged incomplete type, it is already passed
1778 -- by reference, so it is sufficient to rename the pointer component
1779 -- that corresponds to the actual. Otherwise we need to dereference
1780 -- the pointer component to obtain the actual.
1782 if Is_Incomplete_Type
(Etype
(Formal
))
1783 and then Is_Tagged_Type
(Etype
(Formal
))
1786 Make_Object_Renaming_Declaration
(Loc
,
1787 Defining_Identifier
=> New_F
,
1788 Subtype_Mark
=> New_Reference_To
(Etype
(Comp
), Loc
),
1789 Name
=> Renamed_Formal
);
1793 Make_Object_Renaming_Declaration
(Loc
,
1794 Defining_Identifier
=> New_F
,
1795 Subtype_Mark
=> New_Reference_To
(Etype
(Formal
), Loc
),
1797 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1801 end Build_Renamed_Formal_Declaration
;
1803 -----------------------
1804 -- Build_PPC_Wrapper --
1805 -----------------------
1807 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1808 Loc
: constant Source_Ptr
:= Sloc
(E
);
1809 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1811 Wrapper_Id
: constant Entity_Id
:=
1812 Make_Defining_Identifier
(Loc
,
1813 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1814 -- the wrapper procedure name
1816 Wrapper_Body
: Node_Id
;
1818 Synch_Id
: constant Entity_Id
:=
1819 Make_Defining_Identifier
(Loc
,
1820 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1821 -- The parameter that designates the synchronized object in the call
1823 Actuals
: constant List_Id
:= New_List
;
1824 -- The actuals in the entry call
1826 Decls
: constant List_Id
:= New_List
;
1828 Entry_Call
: Node_Id
;
1829 Entry_Name
: Node_Id
;
1832 -- The specification of the wrapper procedure
1836 -- Only build the wrapper if entry has pre/postconditions.
1837 -- Should this be done unconditionally instead ???
1843 P
:= Spec_PPC_List
(Contract
(E
));
1848 -- Transfer ppc pragmas to the declarations of the wrapper
1850 while Present
(P
) loop
1851 if Pragma_Name
(P
) = Name_Precondition
1852 or else Pragma_Name
(P
) = Name_Postcondition
1854 Append
(Relocate_Node
(P
), Decls
);
1855 Set_Analyzed
(Last
(Decls
), False);
1858 P
:= Next_Pragma
(P
);
1862 -- First formal is synchronized object
1865 Make_Parameter_Specification
(Loc
,
1866 Defining_Identifier
=> Synch_Id
,
1867 Out_Present
=> True,
1869 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1872 Make_Selected_Component
(Loc
,
1873 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1874 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1876 -- If entity is entry family, second formal is the corresponding index,
1877 -- and entry name is an indexed component.
1879 if Ekind
(E
) = E_Entry_Family
then
1881 Index
: constant Entity_Id
:=
1882 Make_Defining_Identifier
(Loc
, Name_I
);
1885 Make_Parameter_Specification
(Loc
,
1886 Defining_Identifier
=> Index
,
1888 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
1891 Make_Indexed_Component
(Loc
,
1892 Prefix
=> Entry_Name
,
1893 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
1898 Make_Procedure_Call_Statement
(Loc
,
1900 Parameter_Associations
=> Actuals
);
1902 -- Now add formals that match those of the entry, and build actuals for
1903 -- the nested entry call.
1907 New_Form
: Entity_Id
;
1908 Parm_Spec
: Node_Id
;
1911 Form
:= First_Formal
(E
);
1912 while Present
(Form
) loop
1913 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
1915 Make_Parameter_Specification
(Loc
,
1916 Defining_Identifier
=> New_Form
,
1917 Out_Present
=> Out_Present
(Parent
(Form
)),
1918 In_Present
=> In_Present
(Parent
(Form
)),
1919 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
1921 Append
(Parm_Spec
, Specs
);
1922 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
1927 -- Add renaming declarations for the discriminants of the enclosing
1928 -- type, which may be visible in the preconditions.
1930 if Has_Discriminants
(Synch_Type
) then
1936 D
:= First_Discriminant
(Synch_Type
);
1937 while Present
(D
) loop
1939 Make_Object_Renaming_Declaration
(Loc
,
1940 Defining_Identifier
=>
1941 Make_Defining_Identifier
(Loc
, Chars
(D
)),
1942 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
1944 Make_Selected_Component
(Loc
,
1945 Prefix
=> New_Reference_To
(Synch_Id
, Loc
),
1946 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
1947 Prepend
(Decl
, Decls
);
1948 Next_Discriminant
(D
);
1953 Set_PPC_Wrapper
(E
, Wrapper_Id
);
1955 Make_Subprogram_Body
(Loc
,
1957 Make_Procedure_Specification
(Loc
,
1958 Defining_Unit_Name
=> Wrapper_Id
,
1959 Parameter_Specifications
=> Specs
),
1960 Declarations
=> Decls
,
1961 Handled_Statement_Sequence
=>
1962 Make_Handled_Sequence_Of_Statements
(Loc
,
1963 Statements
=> New_List
(Entry_Call
)));
1965 -- The wrapper body is analyzed when the enclosing type is frozen
1967 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
1968 end Build_PPC_Wrapper
;
1970 --------------------------
1971 -- Build_Wrapper_Bodies --
1972 --------------------------
1974 procedure Build_Wrapper_Bodies
1979 Rec_Typ
: Entity_Id
;
1981 function Build_Wrapper_Body
1983 Subp_Id
: Entity_Id
;
1984 Obj_Typ
: Entity_Id
;
1985 Formals
: List_Id
) return Node_Id
;
1986 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1987 -- associated with a protected or task type. Subp_Id is the subprogram
1988 -- name which will be wrapped. Obj_Typ is the type of the new formal
1989 -- parameter which handles dispatching and object notation. Formals are
1990 -- the original formals of Subp_Id which will be explicitly replicated.
1992 ------------------------
1993 -- Build_Wrapper_Body --
1994 ------------------------
1996 function Build_Wrapper_Body
1998 Subp_Id
: Entity_Id
;
1999 Obj_Typ
: Entity_Id
;
2000 Formals
: List_Id
) return Node_Id
2002 Body_Spec
: Node_Id
;
2005 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
2007 -- The subprogram is not overriding or is not a primitive declared
2008 -- between two views.
2010 if No
(Body_Spec
) then
2015 Actuals
: List_Id
:= No_List
;
2017 First_Form
: Node_Id
;
2022 -- Map formals to actuals. Use the list built for the wrapper
2023 -- spec, skipping the object notation parameter.
2025 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
2027 Formal
:= First_Form
;
2030 if Present
(Formal
) then
2031 Actuals
:= New_List
;
2032 while Present
(Formal
) loop
2034 Make_Identifier
(Loc
,
2035 Chars
=> Chars
(Defining_Identifier
(Formal
))));
2040 -- Special processing for primitives declared between a private
2041 -- type and its completion: the wrapper needs a properly typed
2042 -- parameter if the wrapped operation has a controlling first
2043 -- parameter. Note that this might not be the case for a function
2044 -- with a controlling result.
2046 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
2047 if No
(Actuals
) then
2048 Actuals
:= New_List
;
2051 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
2052 Prepend_To
(Actuals
,
2053 Unchecked_Convert_To
2054 (Corresponding_Concurrent_Type
(Obj_Typ
),
2055 Make_Identifier
(Loc
, Name_uO
)));
2058 Prepend_To
(Actuals
,
2059 Make_Identifier
(Loc
,
2060 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
2063 Nam
:= New_Reference_To
(Subp_Id
, Loc
);
2065 -- An access-to-variable object parameter requires an explicit
2066 -- dereference in the unchecked conversion. This case occurs
2067 -- when a protected entry wrapper must override an interface
2068 -- level procedure with interface access as first parameter.
2070 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2072 if Nkind
(Parameter_Type
(First_Form
)) =
2076 Make_Explicit_Dereference
(Loc
,
2077 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
2079 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
2083 Make_Selected_Component
(Loc
,
2085 Unchecked_Convert_To
2086 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
2087 Selector_Name
=> New_Reference_To
(Subp_Id
, Loc
));
2090 -- Create the subprogram body. For a function, the call to the
2091 -- actual subprogram has to be converted to the corresponding
2092 -- record if it is a controlling result.
2094 if Ekind
(Subp_Id
) = E_Function
then
2100 Make_Function_Call
(Loc
,
2102 Parameter_Associations
=> Actuals
);
2104 if Has_Controlling_Result
(Subp_Id
) then
2106 Unchecked_Convert_To
2107 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
2111 Make_Subprogram_Body
(Loc
,
2112 Specification
=> Body_Spec
,
2113 Declarations
=> Empty_List
,
2114 Handled_Statement_Sequence
=>
2115 Make_Handled_Sequence_Of_Statements
(Loc
,
2116 Statements
=> New_List
(
2117 Make_Simple_Return_Statement
(Loc
, Res
))));
2122 Make_Subprogram_Body
(Loc
,
2123 Specification
=> Body_Spec
,
2124 Declarations
=> Empty_List
,
2125 Handled_Statement_Sequence
=>
2126 Make_Handled_Sequence_Of_Statements
(Loc
,
2127 Statements
=> New_List
(
2128 Make_Procedure_Call_Statement
(Loc
,
2130 Parameter_Associations
=> Actuals
))));
2133 end Build_Wrapper_Body
;
2135 -- Start of processing for Build_Wrapper_Bodies
2138 if Is_Concurrent_Type
(Typ
) then
2139 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2144 -- Generate wrapper bodies for a concurrent type which implements an
2147 if Present
(Interfaces
(Rec_Typ
)) then
2149 Insert_Nod
: Node_Id
;
2151 Prim_Elmt
: Elmt_Id
;
2152 Prim_Decl
: Node_Id
;
2154 Wrap_Body
: Node_Id
;
2155 Wrap_Id
: Entity_Id
;
2160 -- Examine all primitive operations of the corresponding record
2161 -- type, looking for wrapper specs. Generate bodies in order to
2164 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2165 while Present
(Prim_Elmt
) loop
2166 Prim
:= Node
(Prim_Elmt
);
2168 if (Ekind
(Prim
) = E_Function
2169 or else Ekind
(Prim
) = E_Procedure
)
2170 and then Is_Primitive_Wrapper
(Prim
)
2172 Subp
:= Wrapped_Entity
(Prim
);
2173 Prim_Decl
:= Parent
(Parent
(Prim
));
2176 Build_Wrapper_Body
(Loc
,
2179 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2180 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2182 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2183 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2185 Insert_After
(Insert_Nod
, Wrap_Body
);
2186 Insert_Nod
:= Wrap_Body
;
2188 Analyze
(Wrap_Body
);
2191 Next_Elmt
(Prim_Elmt
);
2195 end Build_Wrapper_Bodies
;
2197 ------------------------
2198 -- Build_Wrapper_Spec --
2199 ------------------------
2201 function Build_Wrapper_Spec
2202 (Subp_Id
: Entity_Id
;
2203 Obj_Typ
: Entity_Id
;
2204 Formals
: List_Id
) return Node_Id
2206 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2207 First_Param
: Node_Id
;
2209 Iface_Elmt
: Elmt_Id
;
2210 Iface_Op
: Entity_Id
;
2211 Iface_Op_Elmt
: Elmt_Id
;
2213 function Overriding_Possible
2214 (Iface_Op
: Entity_Id
;
2215 Wrapper
: Entity_Id
) return Boolean;
2216 -- Determine whether a primitive operation can be overridden by Wrapper.
2217 -- Iface_Op is the candidate primitive operation of an interface type,
2218 -- Wrapper is the generated entry wrapper.
2220 function Replicate_Formals
2222 Formals
: List_Id
) return List_Id
;
2223 -- An explicit parameter replication is required due to the Is_Entry_
2224 -- Formal flag being set for all the formals of an entry. The explicit
2225 -- replication removes the flag that would otherwise cause a different
2226 -- path of analysis.
2228 -------------------------
2229 -- Overriding_Possible --
2230 -------------------------
2232 function Overriding_Possible
2233 (Iface_Op
: Entity_Id
;
2234 Wrapper
: Entity_Id
) return Boolean
2236 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2237 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2239 function Type_Conformant_Parameters
2240 (Iface_Op_Params
: List_Id
;
2241 Wrapper_Params
: List_Id
) return Boolean;
2242 -- Determine whether the parameters of the generated entry wrapper
2243 -- and those of a primitive operation are type conformant. During
2244 -- this check, the first parameter of the primitive operation is
2245 -- skipped if it is a controlling argument: protected functions
2246 -- may have a controlling result.
2248 --------------------------------
2249 -- Type_Conformant_Parameters --
2250 --------------------------------
2252 function Type_Conformant_Parameters
2253 (Iface_Op_Params
: List_Id
;
2254 Wrapper_Params
: List_Id
) return Boolean
2256 Iface_Op_Param
: Node_Id
;
2257 Iface_Op_Typ
: Entity_Id
;
2258 Wrapper_Param
: Node_Id
;
2259 Wrapper_Typ
: Entity_Id
;
2262 -- Skip the first (controlling) parameter of primitive operation
2264 Iface_Op_Param
:= First
(Iface_Op_Params
);
2266 if Present
(First_Formal
(Iface_Op
))
2267 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2269 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2272 Wrapper_Param
:= First
(Wrapper_Params
);
2273 while Present
(Iface_Op_Param
)
2274 and then Present
(Wrapper_Param
)
2276 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2277 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2279 -- The two parameters must be mode conformant
2281 if not Conforming_Types
2282 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2287 Next
(Iface_Op_Param
);
2288 Next
(Wrapper_Param
);
2291 -- One of the lists is longer than the other
2293 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2298 end Type_Conformant_Parameters
;
2300 -- Start of processing for Overriding_Possible
2303 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2307 -- If an inherited subprogram is implemented by a protected procedure
2308 -- or an entry, then the first parameter of the inherited subprogram
2309 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2311 if Ekind
(Iface_Op
) = E_Procedure
2312 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2315 Obj_Param
: constant Node_Id
:=
2316 First
(Parameter_Specifications
(Iface_Op_Spec
));
2318 if not Out_Present
(Obj_Param
)
2319 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2328 Type_Conformant_Parameters
(
2329 Parameter_Specifications
(Iface_Op_Spec
),
2330 Parameter_Specifications
(Wrapper_Spec
));
2331 end Overriding_Possible
;
2333 -----------------------
2334 -- Replicate_Formals --
2335 -----------------------
2337 function Replicate_Formals
2339 Formals
: List_Id
) return List_Id
2341 New_Formals
: constant List_Id
:= New_List
;
2343 Param_Type
: Node_Id
;
2346 Formal
:= First
(Formals
);
2348 -- Skip the object parameter when dealing with primitives declared
2349 -- between two views.
2351 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2352 and then not Has_Controlling_Result
(Subp_Id
)
2354 Formal
:= Next
(Formal
);
2357 while Present
(Formal
) loop
2359 -- Create an explicit copy of the entry parameter
2361 -- When creating the wrapper subprogram for a primitive operation
2362 -- of a protected interface we must construct an equivalent
2363 -- signature to that of the overriding operation. For regular
2364 -- parameters we can just use the type of the formal, but for
2365 -- access to subprogram parameters we need to reanalyze the
2366 -- parameter type to create local entities for the signature of
2367 -- the subprogram type. Using the entities of the overriding
2368 -- subprogram will result in out-of-scope errors in the back-end.
2370 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2371 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2374 New_Reference_To
(Etype
(Parameter_Type
(Formal
)), Loc
);
2377 Append_To
(New_Formals
,
2378 Make_Parameter_Specification
(Loc
,
2379 Defining_Identifier
=>
2380 Make_Defining_Identifier
(Loc
,
2381 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2382 In_Present
=> In_Present
(Formal
),
2383 Out_Present
=> Out_Present
(Formal
),
2384 Parameter_Type
=> Param_Type
));
2390 end Replicate_Formals
;
2392 -- Start of processing for Build_Wrapper_Spec
2395 -- There is no point in building wrappers for non-tagged concurrent
2398 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2400 -- An entry or a protected procedure can override a routine where the
2401 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2402 -- type. Since the wrapper must have the exact same signature as that of
2403 -- the overridden subprogram, we try to find the overriding candidate
2404 -- and use its controlling formal.
2406 First_Param
:= Empty
;
2408 -- Check every implemented interface
2410 if Present
(Interfaces
(Obj_Typ
)) then
2411 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2412 Search
: while Present
(Iface_Elmt
) loop
2413 Iface
:= Node
(Iface_Elmt
);
2415 -- Check every interface primitive
2417 if Present
(Primitive_Operations
(Iface
)) then
2418 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2419 while Present
(Iface_Op_Elmt
) loop
2420 Iface_Op
:= Node
(Iface_Op_Elmt
);
2422 -- Ignore predefined primitives
2424 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2425 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2427 -- The current primitive operation can be overridden by
2428 -- the generated entry wrapper.
2430 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2432 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2438 Next_Elmt
(Iface_Op_Elmt
);
2442 Next_Elmt
(Iface_Elmt
);
2446 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2447 -- this subprogram and this is not a primitive declared between two
2448 -- views then force the generation of a wrapper. As an optimization,
2449 -- previous versions of the frontend avoid generating the wrapper;
2450 -- however, the wrapper facilitates locating and reporting an error
2451 -- when a duplicate declaration is found later. See example in
2455 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2458 (Corresponding_Concurrent_Type
(Obj_Typ
))
2461 Make_Parameter_Specification
(Loc
,
2462 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
2464 Out_Present
=> False,
2465 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2467 -- For entries and procedures of protected types the mode of
2468 -- the controlling argument must be in-out.
2472 Make_Parameter_Specification
(Loc
,
2473 Defining_Identifier
=>
2474 Make_Defining_Identifier
(Loc
,
2477 Out_Present
=> (Ekind
(Subp_Id
) /= E_Function
),
2478 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2483 Wrapper_Id
: constant Entity_Id
:=
2484 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2485 New_Formals
: List_Id
;
2486 Obj_Param
: Node_Id
;
2487 Obj_Param_Typ
: Entity_Id
;
2490 -- Minimum decoration is needed to catch the entity in
2491 -- Sem_Ch6.Override_Dispatching_Operation.
2493 if Ekind
(Subp_Id
) = E_Function
then
2494 Set_Ekind
(Wrapper_Id
, E_Function
);
2496 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2499 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2500 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2501 Set_Is_Private_Primitive
(Wrapper_Id
,
2502 Is_Private_Primitive_Subprogram
(Subp_Id
));
2504 -- Process the formals
2506 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2508 -- A function with a controlling result and no first controlling
2509 -- formal needs no additional parameter.
2511 if Has_Controlling_Result
(Subp_Id
)
2513 (No
(First_Formal
(Subp_Id
))
2514 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2518 -- Routine Subp_Id has been found to override an interface primitive.
2519 -- If the interface operation has an access parameter, create a copy
2520 -- of it, with the same null exclusion indicator if present.
2522 elsif Present
(First_Param
) then
2523 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2525 Make_Access_Definition
(Loc
,
2527 New_Reference_To
(Obj_Typ
, Loc
));
2528 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2529 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2532 Obj_Param_Typ
:= New_Reference_To
(Obj_Typ
, Loc
);
2536 Make_Parameter_Specification
(Loc
,
2537 Defining_Identifier
=>
2538 Make_Defining_Identifier
(Loc
,
2540 In_Present
=> In_Present
(First_Param
),
2541 Out_Present
=> Out_Present
(First_Param
),
2542 Parameter_Type
=> Obj_Param_Typ
);
2544 Prepend_To
(New_Formals
, Obj_Param
);
2546 -- If we are dealing with a primitive declared between two views,
2547 -- implemented by a synchronized operation, we need to create
2548 -- a default parameter. The mode of the parameter must match that
2549 -- of the primitive operation.
2552 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2554 Make_Parameter_Specification
(Loc
,
2555 Defining_Identifier
=>
2556 Make_Defining_Identifier
(Loc
, Name_uO
),
2557 In_Present
=> In_Present
(Parent
(First_Entity
(Subp_Id
))),
2558 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2559 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2560 Prepend_To
(New_Formals
, Obj_Param
);
2563 -- Build the final spec. If it is a function with a controlling
2564 -- result, it is a primitive operation of the corresponding
2565 -- record type, so mark the spec accordingly.
2567 if Ekind
(Subp_Id
) = E_Function
then
2572 if Has_Controlling_Result
(Subp_Id
) then
2575 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2577 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2581 Make_Function_Specification
(Loc
,
2582 Defining_Unit_Name
=> Wrapper_Id
,
2583 Parameter_Specifications
=> New_Formals
,
2584 Result_Definition
=> Res_Def
);
2588 Make_Procedure_Specification
(Loc
,
2589 Defining_Unit_Name
=> Wrapper_Id
,
2590 Parameter_Specifications
=> New_Formals
);
2593 end Build_Wrapper_Spec
;
2595 -------------------------
2596 -- Build_Wrapper_Specs --
2597 -------------------------
2599 procedure Build_Wrapper_Specs
2605 Rec_Typ
: Entity_Id
;
2606 procedure Scan_Declarations
(L
: List_Id
);
2607 -- Common processing for visible and private declarations
2608 -- of a protected type.
2610 procedure Scan_Declarations
(L
: List_Id
) is
2612 Wrap_Decl
: Node_Id
;
2613 Wrap_Spec
: Node_Id
;
2621 while Present
(Decl
) loop
2624 if Nkind
(Decl
) = N_Entry_Declaration
2625 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2629 (Subp_Id
=> Defining_Identifier
(Decl
),
2631 Formals
=> Parameter_Specifications
(Decl
));
2633 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2636 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2639 Parameter_Specifications
(Specification
(Decl
)));
2642 if Present
(Wrap_Spec
) then
2644 Make_Subprogram_Declaration
(Loc
,
2645 Specification
=> Wrap_Spec
);
2647 Insert_After
(N
, Wrap_Decl
);
2650 Analyze
(Wrap_Decl
);
2655 end Scan_Declarations
;
2657 -- start of processing for Build_Wrapper_Specs
2660 if Is_Protected_Type
(Typ
) then
2661 Def
:= Protected_Definition
(Parent
(Typ
));
2662 else pragma Assert
(Is_Task_Type
(Typ
));
2663 Def
:= Task_Definition
(Parent
(Typ
));
2666 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2668 -- Generate wrapper specs for a concurrent type which implements an
2669 -- interface. Operations in both the visible and private parts may
2670 -- implement progenitor operations.
2672 if Present
(Interfaces
(Rec_Typ
))
2673 and then Present
(Def
)
2675 Scan_Declarations
(Visible_Declarations
(Def
));
2676 Scan_Declarations
(Private_Declarations
(Def
));
2678 end Build_Wrapper_Specs
;
2680 ---------------------------
2681 -- Build_Find_Body_Index --
2682 ---------------------------
2684 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2685 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2688 Has_F
: Boolean := False;
2690 If_St
: Node_Id
:= Empty
;
2693 Decls
: List_Id
:= New_List
;
2696 Siz
: Node_Id
:= Empty
;
2698 procedure Add_If_Clause
(Expr
: Node_Id
);
2699 -- Add test for range of current entry
2701 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2702 -- If a bound of an entry is given by a discriminant, retrieve the
2703 -- actual value of the discriminant from the enclosing object.
2709 procedure Add_If_Clause
(Expr
: Node_Id
) is
2711 Stats
: constant List_Id
:=
2713 Make_Simple_Return_Statement
(Loc
,
2714 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2717 -- Index for current entry body
2721 -- Compute total length of entry queues so far
2729 Right_Opnd
=> Expr
);
2734 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2737 -- Map entry queue indexes in the range of the current family
2738 -- into the current index, that designates the entry body.
2742 Make_Implicit_If_Statement
(Typ
,
2744 Then_Statements
=> Stats
,
2745 Elsif_Parts
=> New_List
);
2749 Append_To
(Elsif_Parts
(If_St
),
2750 Make_Elsif_Part
(Loc
,
2752 Then_Statements
=> Stats
));
2756 ------------------------------
2757 -- Convert_Discriminant_Ref --
2758 ------------------------------
2760 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2764 if Is_Entity_Name
(Bound
)
2765 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2768 Make_Selected_Component
(Loc
,
2770 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2771 Make_Explicit_Dereference
(Loc
,
2772 Make_Identifier
(Loc
, Name_uObject
))),
2773 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2774 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2776 B
:= New_Copy_Tree
(Bound
);
2780 end Convert_Discriminant_Ref
;
2782 -- Start of processing for Build_Find_Body_Index
2785 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2787 Ent
:= First_Entity
(Typ
);
2788 while Present
(Ent
) loop
2789 if Ekind
(Ent
) = E_Entry_Family
then
2799 -- If the protected type has no entry families, there is a one-one
2800 -- correspondence between entry queue and entry body.
2803 Make_Simple_Return_Statement
(Loc
,
2804 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2807 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2810 -- if E <= l1 then return 1;
2811 -- elsif E <= l1 + l2 then return 2;
2816 Ent
:= First_Entity
(Typ
);
2818 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2820 while Present
(Ent
) loop
2821 if Ekind
(Ent
) = E_Entry
then
2822 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2824 elsif Ekind
(Ent
) = E_Entry_Family
then
2825 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2826 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2827 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2828 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2837 Make_Simple_Return_Statement
(Loc
,
2838 Expression
=> Make_Integer_Literal
(Loc
, 1));
2840 elsif Nkind
(Ret
) = N_If_Statement
then
2842 -- Ranges are in increasing order, so last one doesn't need guard
2845 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2848 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2854 Make_Subprogram_Body
(Loc
,
2855 Specification
=> Spec
,
2856 Declarations
=> Decls
,
2857 Handled_Statement_Sequence
=>
2858 Make_Handled_Sequence_Of_Statements
(Loc
,
2859 Statements
=> New_List
(Ret
)));
2860 end Build_Find_Body_Index
;
2862 --------------------------------
2863 -- Build_Find_Body_Index_Spec --
2864 --------------------------------
2866 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2867 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2868 Id
: constant Entity_Id
:=
2869 Make_Defining_Identifier
(Loc
,
2870 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2871 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2872 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2876 Make_Function_Specification
(Loc
,
2877 Defining_Unit_Name
=> Id
,
2878 Parameter_Specifications
=> New_List
(
2879 Make_Parameter_Specification
(Loc
,
2880 Defining_Identifier
=> Parm1
,
2882 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2884 Make_Parameter_Specification
(Loc
,
2885 Defining_Identifier
=> Parm2
,
2887 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2889 Result_Definition
=> New_Occurrence_Of
(
2890 RTE
(RE_Protected_Entry_Index
), Loc
));
2891 end Build_Find_Body_Index_Spec
;
2893 -----------------------------------------------
2894 -- Build_Lock_Free_Protected_Subprogram_Body --
2895 -----------------------------------------------
2897 function Build_Lock_Free_Protected_Subprogram_Body
2900 Unprot_Spec
: Node_Id
) return Node_Id
2902 Actuals
: constant List_Id
:= New_List
;
2903 Loc
: constant Source_Ptr
:= Sloc
(N
);
2904 Spec
: constant Node_Id
:= Specification
(N
);
2905 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
2907 Prot_Spec
: Node_Id
;
2911 -- Create the protected version of the body
2914 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
2916 -- Build the actual parameters which appear in the call to the
2917 -- unprotected version of the body.
2919 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
2920 while Present
(Formal
) loop
2922 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
2927 -- Function case, generate:
2928 -- return <Unprot_Func_Call>;
2930 if Nkind
(Spec
) = N_Function_Specification
then
2932 Make_Simple_Return_Statement
(Loc
,
2934 Make_Function_Call
(Loc
,
2936 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2937 Parameter_Associations
=> Actuals
));
2939 -- Procedure case, call the unprotected version
2943 Make_Procedure_Call_Statement
(Loc
,
2945 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2946 Parameter_Associations
=> Actuals
);
2950 Make_Subprogram_Body
(Loc
,
2951 Declarations
=> Empty_List
,
2952 Specification
=> Prot_Spec
,
2953 Handled_Statement_Sequence
=>
2954 Make_Handled_Sequence_Of_Statements
(Loc
,
2955 Statements
=> New_List
(Stmt
)));
2956 end Build_Lock_Free_Protected_Subprogram_Body
;
2958 -------------------------------------------------
2959 -- Build_Lock_Free_Unprotected_Subprogram_Body --
2960 -------------------------------------------------
2962 -- Procedures which meet the lock-free implementation requirements and
2963 -- reference a unique scalar component Comp are expanded in the following
2966 -- procedure P (...) is
2967 -- <original declarations>
2971 -- Saved_Comp : constant ... :=
2972 -- Atomic_Load (Comp'Address, Relaxed);
2973 -- Current_Comp : ... := Saved_Comp;
2975 -- <original statements>
2976 -- exit when Atomic_Compare (Comp, Saved_Comp, Current_Comp);
2982 -- References to Comp which appear in the original statements are replaced
2983 -- with references to Current_Comp. Each return and raise statement of P is
2984 -- transformed into an atomic status check:
2986 -- if Atomic_Compare (Comp, Saved_Comp, Current_Comp) then
2987 -- <original statement>
2992 -- Functions which meet the lock-free implementation requirements and
2993 -- reference a unique scalar component Comp are expanded in the following
2996 -- function F (...) return ... is
2997 -- <original declarations>
2998 -- Saved_Comp : constant ... := Atomic_Load (Comp'Address);
3000 -- <original statements>
3003 -- References to Comp which appear in the original statements are replaced
3004 -- with references to Saved_Comp.
3006 function Build_Lock_Free_Unprotected_Subprogram_Body
3008 Prot_Typ
: Node_Id
) return Node_Id
3010 Is_Procedure
: constant Boolean :=
3011 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
3012 Loc
: constant Source_Ptr
:= Sloc
(N
);
3013 Label_Id
: Entity_Id
:= Empty
;
3015 procedure Process_Stmts
3017 Compare
: Entity_Id
;
3018 Unsigned
: Entity_Id
;
3020 Saved_Comp
: Entity_Id
;
3021 Current_Comp
: Entity_Id
);
3022 -- Given a statement sequence Stmts, wrap any return or raise statements
3023 -- in the following manner:
3025 -- if System.Atomic_Primitives.Atomic_Compare_Exchange
3027 -- Interfaces.Unsigned (Saved_Comp),
3028 -- Interfaces.Unsigned (Current_Comp))
3035 -- Replace all references to Comp with a reference to Current_Comp.
3037 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
3038 -- Subprograms which meet the lock-free implementation criteria are
3039 -- allowed to reference only one unique component. Return the prival
3040 -- of the said component.
3046 procedure Process_Stmts
3048 Compare
: Entity_Id
;
3049 Unsigned
: Entity_Id
;
3051 Saved_Comp
: Entity_Id
;
3052 Current_Comp
: Entity_Id
)
3054 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
3055 -- Transform a single node if it is a return statement, a raise
3056 -- statement or a reference to Comp.
3062 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3064 procedure Wrap_Statement
(Stmt
: Node_Id
);
3065 -- Wrap an arbitrary statement inside an if statement where the
3066 -- condition does an atomic check on the state of the object.
3068 --------------------
3069 -- Wrap_Statement --
3070 --------------------
3072 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3074 -- The first time through, create the declaration of a label
3075 -- which is used to skip the remainder of source statements if
3076 -- the state of the object has changed.
3078 if No
(Label_Id
) then
3080 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3081 Set_Entity
(Label_Id
,
3082 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3087 -- if System.Atomic_Primitives.Atomic_Compare_Exchange
3089 -- Interfaces.Unsigned (Saved_Comp),
3090 -- Interfaces.Unsigned (Current_Comp))
3098 Make_If_Statement
(Loc
,
3100 Make_Function_Call
(Loc
,
3102 New_Reference_To
(Compare
, Loc
),
3103 Parameter_Associations
=> New_List
(
3104 Make_Attribute_Reference
(Loc
,
3105 Prefix
=> New_Reference_To
(Comp
, Loc
),
3106 Attribute_Name
=> Name_Address
),
3108 Unchecked_Convert_To
(Unsigned
,
3109 New_Reference_To
(Saved_Comp
, Loc
)),
3111 Unchecked_Convert_To
(Unsigned
,
3112 New_Reference_To
(Current_Comp
, Loc
)))),
3114 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3116 Else_Statements
=> New_List
(
3117 Make_Goto_Statement
(Loc
,
3118 Name
=> New_Reference_To
(Entity
(Label_Id
), Loc
)))));
3121 -- Start of processing for Process_Node
3124 -- Wrap each return and raise statement that appear inside a
3125 -- procedure. Skip the last return statement which is added by
3126 -- default since it is transformed into an exit statement.
3129 and then Nkind_In
(N
, N_Simple_Return_Statement
,
3130 N_Extended_Return_Statement
,
3132 and then Nkind
(Last
(Stmts
)) /= N_Simple_Return_Statement
3137 -- Replace all references to the original component by a reference
3138 -- to the current state of the component.
3140 elsif Nkind
(N
) = N_Identifier
3141 and then Present
(Entity
(N
))
3142 and then Entity
(N
) = Comp
3144 Rewrite
(N
, Make_Identifier
(Loc
, Chars
(Current_Comp
)));
3150 Set_Analyzed
(N
, False);
3155 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3161 -- Start of processing for Process_Stmts
3164 Stmt
:= First
(Stmts
);
3165 while Present
(Stmt
) loop
3166 Process_Nodes
(Stmt
);
3171 --------------------------
3172 -- Referenced_Component --
3173 --------------------------
3175 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
3178 Source_Comp
: Entity_Id
:= Empty
;
3181 -- Find the unique source component which N references in its
3184 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
3186 Element
: Lock_Free_Subprogram
renames
3187 Lock_Free_Subprogram_Table
.Table
(Index
);
3189 if Element
.Sub_Body
= N
then
3190 Source_Comp
:= Element
.Comp_Id
;
3196 if No
(Source_Comp
) then
3200 -- Find the prival which corresponds to the source component within
3201 -- the declarations of N.
3203 Decl
:= First
(Declarations
(N
));
3204 while Present
(Decl
) loop
3206 -- Privals appear as object renamings
3208 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
3209 Comp
:= Defining_Identifier
(Decl
);
3211 if Present
(Prival_Link
(Comp
))
3212 and then Prival_Link
(Comp
) = Source_Comp
3222 end Referenced_Component
;
3226 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
3227 Decls
: constant List_Id
:= Declarations
(N
);
3230 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3233 Stmts
:= New_Copy_List
(Statements
(Handled_Statement_Sequence
(N
)));
3235 -- Perform the lock-free expansion when the subprogram references a
3236 -- protected component.
3238 if Present
(Comp
) then
3240 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
3241 Block_Decls
: List_Id
;
3242 Compare
: Entity_Id
;
3243 Current_Comp
: Entity_Id
;
3247 Load_Params
: List_Id
;
3248 Saved_Comp
: Entity_Id
;
3251 Unsigned
: Entity_Id
;
3254 -- Get the type size
3256 -- Surely this should be Known_Static_Esize if you are about
3257 -- to assume you can do UI_To_Int on it! ???
3259 if Known_Esize
(Comp_Type
) then
3260 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3262 -- If the Esize (Object_Size) is unknown at compile-time, look at
3263 -- the RM_Size (Value_Size) since it may have been set by an
3264 -- explicit representation clause.
3266 -- And how do we know this is statically known???
3269 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3272 -- Retrieve all relevant atomic routines and types
3276 Compare
:= RTE
(RE_Atomic_Compare_Exchange_8
);
3277 Load
:= RTE
(RE_Atomic_Load_8
);
3278 Unsigned
:= RTE
(RE_Uint8
);
3281 Compare
:= RTE
(RE_Atomic_Compare_Exchange_16
);
3282 Load
:= RTE
(RE_Atomic_Load_16
);
3283 Unsigned
:= RTE
(RE_Uint16
);
3286 Compare
:= RTE
(RE_Atomic_Compare_Exchange_32
);
3287 Load
:= RTE
(RE_Atomic_Load_32
);
3288 Unsigned
:= RTE
(RE_Uint32
);
3291 Compare
:= RTE
(RE_Atomic_Compare_Exchange_64
);
3292 Load
:= RTE
(RE_Atomic_Load_64
);
3293 Unsigned
:= RTE
(RE_Uint64
);
3296 raise Program_Error
;
3302 -- Saved_Comp : constant Comp_Type :=
3303 -- Comp_Type (Atomic_Load (Comp'Address));
3307 -- Saved_Comp : constant Comp_Type :=
3308 -- Comp_Type (Atomic_Load (Comp'Address),
3312 Make_Defining_Identifier
(Loc
,
3313 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3315 Load_Params
:= New_List
(
3316 Make_Attribute_Reference
(Loc
,
3317 Prefix
=> New_Reference_To
(Comp
, Loc
),
3318 Attribute_Name
=> Name_Address
));
3320 -- For protected procedures, set the memory model to be relaxed
3322 if Is_Procedure
then
3323 Append_To
(Load_Params
,
3324 New_Reference_To
(RTE
(RE_Relaxed
), Loc
));
3328 Make_Object_Declaration
(Loc
,
3329 Defining_Identifier
=> Saved_Comp
,
3330 Constant_Present
=> True,
3331 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3333 Unchecked_Convert_To
(Comp_Type
,
3334 Make_Function_Call
(Loc
,
3335 Name
=> New_Reference_To
(Load
, Loc
),
3336 Parameter_Associations
=> Load_Params
)));
3338 -- Protected procedures
3340 if Is_Procedure
then
3341 Block_Decls
:= New_List
(Decl
);
3344 -- Current_Comp : Comp_Type := Saved_Comp;
3347 Make_Defining_Identifier
(Loc
,
3348 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3350 Append_To
(Block_Decls
,
3351 Make_Object_Declaration
(Loc
,
3352 Defining_Identifier
=> Current_Comp
,
3353 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3354 Expression
=> New_Reference_To
(Saved_Comp
, Loc
)));
3356 -- Protected function
3359 Append_To
(Decls
, Decl
);
3360 Current_Comp
:= Saved_Comp
;
3364 (Stmts
, Compare
, Unsigned
, Comp
, Saved_Comp
, Current_Comp
);
3368 -- exit when System.Atomic_Primitives.Atomic_Compare_Exchange
3370 -- Interfaces.Unsigned (Saved_Comp),
3371 -- Interfaces.Unsigned (Current_Comp))
3373 if Is_Procedure
then
3375 Make_Exit_Statement
(Loc
,
3377 Make_Function_Call
(Loc
,
3379 New_Reference_To
(Compare
, Loc
),
3380 Parameter_Associations
=> New_List
(
3381 Make_Attribute_Reference
(Loc
,
3382 Prefix
=> New_Reference_To
(Comp
, Loc
),
3383 Attribute_Name
=> Name_Address
),
3385 Unchecked_Convert_To
(Unsigned
,
3386 New_Reference_To
(Saved_Comp
, Loc
)),
3388 Unchecked_Convert_To
(Unsigned
,
3389 New_Reference_To
(Current_Comp
, Loc
)))));
3391 -- Small optimization: transform the default return statement
3392 -- of a procedure into the atomic exit statement.
3394 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3395 Rewrite
(Last
(Stmts
), Stmt
);
3397 Append_To
(Stmts
, Stmt
);
3401 -- Create the declaration of the label used to skip the rest of
3402 -- the source statements when the object state changes.
3404 if Present
(Label_Id
) then
3405 Label
:= Make_Label
(Loc
, Label_Id
);
3407 Make_Implicit_Label_Declaration
(Loc
,
3408 Defining_Identifier
=> Entity
(Label_Id
),
3409 Label_Construct
=> Label
));
3410 Append_To
(Stmts
, Label
);
3423 if Is_Procedure
then
3425 Make_Procedure_Call_Statement
(Loc
,
3427 New_Reference_To
(RTE
(RE_Atomic_Synchronize
), Loc
)),
3428 Make_Loop_Statement
(Loc
,
3429 Statements
=> New_List
(
3430 Make_Block_Statement
(Loc
,
3431 Declarations
=> Block_Decls
,
3432 Handled_Statement_Sequence
=>
3433 Make_Handled_Sequence_Of_Statements
(Loc
,
3434 Statements
=> Stmts
))),
3435 End_Label
=> Empty
));
3440 -- Add renamings for the protection object, discriminals, privals and
3441 -- the entry index constant for use by debugger.
3443 Debug_Private_Data_Declarations
(Decls
);
3445 -- Make an unprotected version of the subprogram for use within the same
3446 -- object, with new name and extra parameter representing the object.
3449 Make_Subprogram_Body
(Loc
,
3451 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3452 Declarations
=> Decls
,
3453 Handled_Statement_Sequence
=>
3454 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
3455 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3457 -------------------------
3458 -- Build_Master_Entity --
3459 -------------------------
3461 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3462 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3464 Context_Id
: Entity_Id
;
3470 if Is_Itype
(Obj_Or_Typ
) then
3471 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3473 Par
:= Parent
(Obj_Or_Typ
);
3476 -- When creating a master for a record component which is either a task
3477 -- or access-to-task, the enclosing record is the master scope and the
3478 -- proper insertion point is the component list.
3480 if Is_Record_Type
(Current_Scope
) then
3482 Context_Id
:= Current_Scope
;
3483 Decls
:= List_Containing
(Context
);
3485 -- Default case for object declarations and access types. Note that the
3486 -- context is updated to the nearest enclosing body, block, package or
3487 -- return statement.
3490 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3493 -- Do not create a master if one already exists or there is no task
3496 if Has_Master_Entity
(Context_Id
)
3497 or else Restriction_Active
(No_Task_Hierarchy
)
3502 -- Create a master, generate:
3503 -- _Master : constant Master_Id := Current_Master.all;
3506 Make_Object_Declaration
(Loc
,
3507 Defining_Identifier
=>
3508 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3509 Constant_Present
=> True,
3510 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3512 Make_Explicit_Dereference
(Loc
,
3513 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
3515 -- The master is inserted at the start of the declarative list of the
3518 Prepend_To
(Decls
, Decl
);
3520 -- In certain cases where transient scopes are involved, the immediate
3521 -- scope is not always the proper master scope. Ensure that the master
3522 -- declaration and entity appear in the same context.
3524 if Context_Id
/= Current_Scope
then
3525 Push_Scope
(Context_Id
);
3532 -- Mark the enclosing scope and its associated construct as being task
3535 Set_Has_Master_Entity
(Context_Id
);
3537 while Present
(Context
)
3538 and then Nkind
(Context
) /= N_Compilation_Unit
3540 if Nkind_In
(Context
, N_Block_Statement
,
3544 Set_Is_Task_Master
(Context
);
3547 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3548 Context
:= Corresponding_Stub
(Parent
(Context
));
3551 Context
:= Parent
(Context
);
3553 end Build_Master_Entity
;
3555 ---------------------------
3556 -- Build_Master_Renaming --
3557 ---------------------------
3559 procedure Build_Master_Renaming
3560 (Ptr_Typ
: Entity_Id
;
3561 Ins_Nod
: Node_Id
:= Empty
)
3563 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3565 Master_Decl
: Node_Id
;
3566 Master_Id
: Entity_Id
;
3569 -- Nothing to do if there is no task hierarchy
3571 if Restriction_Active
(No_Task_Hierarchy
) then
3575 -- Determine the proper context to insert the master renaming
3577 if Present
(Ins_Nod
) then
3579 elsif Is_Itype
(Ptr_Typ
) then
3580 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3582 Context
:= Parent
(Ptr_Typ
);
3586 -- <Ptr_Typ>M : Master_Id renames _Master;
3589 Make_Defining_Identifier
(Loc
,
3590 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3593 Make_Object_Renaming_Declaration
(Loc
,
3594 Defining_Identifier
=> Master_Id
,
3595 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3596 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3598 Insert_Action
(Context
, Master_Decl
);
3600 -- The renamed master now services the access type
3602 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3603 end Build_Master_Renaming
;
3605 -----------------------------------------
3606 -- Build_Private_Protected_Declaration --
3607 -----------------------------------------
3609 function Build_Private_Protected_Declaration
3610 (N
: Node_Id
) return Entity_Id
3612 Loc
: constant Source_Ptr
:= Sloc
(N
);
3613 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3618 Spec_Id
: Entity_Id
;
3621 Formal
:= First_Formal
(Body_Id
);
3623 -- The protected operation always has at least one formal, namely the
3624 -- object itself, but it is only placed in the parameter list if
3625 -- expansion is enabled.
3627 if Present
(Formal
) or else Expander_Active
then
3628 Plist
:= Copy_Parameter_List
(Body_Id
);
3633 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3635 Make_Procedure_Specification
(Loc
,
3636 Defining_Unit_Name
=>
3637 Make_Defining_Identifier
(Sloc
(Body_Id
),
3638 Chars
=> Chars
(Body_Id
)),
3639 Parameter_Specifications
=>
3643 Make_Function_Specification
(Loc
,
3644 Defining_Unit_Name
=>
3645 Make_Defining_Identifier
(Sloc
(Body_Id
),
3646 Chars
=> Chars
(Body_Id
)),
3647 Parameter_Specifications
=> Plist
,
3648 Result_Definition
=>
3649 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3652 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3653 Insert_Before
(N
, Decl
);
3654 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3656 -- Indicate that the entity comes from source, to ensure that cross-
3657 -- reference information is properly generated. The body itself is
3658 -- rewritten during expansion, and the body entity will not appear in
3659 -- calls to the operation.
3661 Set_Comes_From_Source
(Spec_Id
, True);
3663 Set_Has_Completion
(Spec_Id
);
3664 Set_Convention
(Spec_Id
, Convention_Protected
);
3666 end Build_Private_Protected_Declaration
;
3668 ---------------------------
3669 -- Build_Protected_Entry --
3670 ---------------------------
3672 function Build_Protected_Entry
3675 Pid
: Node_Id
) return Node_Id
3677 Loc
: constant Source_Ptr
:= Sloc
(N
);
3679 Decls
: constant List_Id
:= Declarations
(N
);
3680 End_Lab
: constant Node_Id
:=
3681 End_Label
(Handled_Statement_Sequence
(N
));
3682 End_Loc
: constant Source_Ptr
:=
3683 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3684 -- Used for the generated call to Complete_Entry_Body
3686 Han_Loc
: Source_Ptr
;
3687 -- Used for the exception handler, inserted at end of the body
3689 Op_Decls
: constant List_Id
:= New_List
;
3697 -- Set the source location on the exception handler only when debugging
3698 -- the expanded code (see Make_Implicit_Exception_Handler).
3700 if Debug_Generated_Code
then
3703 -- Otherwise the inserted code should not be visible to the debugger
3706 Han_Loc
:= No_Location
;
3710 Make_Defining_Identifier
(Loc
,
3711 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3713 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
3715 -- Add the following declarations:
3716 -- type poVP is access poV;
3717 -- _object : poVP := poVP (_O);
3719 -- where _O is the formal parameter associated with the concurrent
3720 -- object. These declarations are needed for Complete_Entry_Body.
3722 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
3724 -- Add renamings for all formals, the Protection object, discriminals,
3725 -- privals and the entry index constant for use by debugger.
3727 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
3728 Debug_Private_Data_Declarations
(Decls
);
3730 case Corresponding_Runtime_Package
(Pid
) is
3731 when System_Tasking_Protected_Objects_Entries
=>
3733 New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
);
3735 when System_Tasking_Protected_Objects_Single_Entry
=>
3737 New_Reference_To
(RTE
(RE_Complete_Single_Entry_Body
), Loc
);
3740 raise Program_Error
;
3743 Op_Stats
:= New_List
(
3744 Make_Block_Statement
(Loc
,
3745 Declarations
=> Decls
,
3746 Handled_Statement_Sequence
=>
3747 Handled_Statement_Sequence
(N
)),
3749 Make_Procedure_Call_Statement
(End_Loc
,
3751 Parameter_Associations
=> New_List
(
3752 Make_Attribute_Reference
(End_Loc
,
3754 Make_Selected_Component
(End_Loc
,
3755 Prefix
=> Make_Identifier
(End_Loc
, Name_uObject
),
3756 Selector_Name
=> Make_Identifier
(End_Loc
, Name_uObject
)),
3757 Attribute_Name
=> Name_Unchecked_Access
))));
3759 -- When exceptions can not be propagated, we never need to call
3760 -- Exception_Complete_Entry_Body
3762 if No_Exception_Handlers_Set
then
3764 Make_Subprogram_Body
(Loc
,
3765 Specification
=> Espec
,
3766 Declarations
=> Op_Decls
,
3767 Handled_Statement_Sequence
=>
3768 Make_Handled_Sequence_Of_Statements
(Loc
,
3769 Statements
=> Op_Stats
,
3770 End_Label
=> End_Lab
));
3773 Ohandle
:= Make_Others_Choice
(Loc
);
3774 Set_All_Others
(Ohandle
);
3776 case Corresponding_Runtime_Package
(Pid
) is
3777 when System_Tasking_Protected_Objects_Entries
=>
3780 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3782 when System_Tasking_Protected_Objects_Single_Entry
=>
3785 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3788 raise Program_Error
;
3791 -- Establish link between subprogram body entity and source entry
3793 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
3795 -- Create body of entry procedure. The renaming declarations are
3796 -- placed ahead of the block that contains the actual entry body.
3799 Make_Subprogram_Body
(Loc
,
3800 Specification
=> Espec
,
3801 Declarations
=> Op_Decls
,
3802 Handled_Statement_Sequence
=>
3803 Make_Handled_Sequence_Of_Statements
(Loc
,
3804 Statements
=> Op_Stats
,
3805 End_Label
=> End_Lab
,
3806 Exception_Handlers
=> New_List
(
3807 Make_Implicit_Exception_Handler
(Han_Loc
,
3808 Exception_Choices
=> New_List
(Ohandle
),
3810 Statements
=> New_List
(
3811 Make_Procedure_Call_Statement
(Han_Loc
,
3813 Parameter_Associations
=> New_List
(
3814 Make_Attribute_Reference
(Han_Loc
,
3816 Make_Selected_Component
(Han_Loc
,
3818 Make_Identifier
(Han_Loc
, Name_uObject
),
3820 Make_Identifier
(Han_Loc
, Name_uObject
)),
3821 Attribute_Name
=> Name_Unchecked_Access
),
3823 Make_Function_Call
(Han_Loc
,
3824 Name
=> New_Reference_To
(
3825 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3827 end Build_Protected_Entry
;
3829 -----------------------------------------
3830 -- Build_Protected_Entry_Specification --
3831 -----------------------------------------
3833 function Build_Protected_Entry_Specification
3836 Ent_Id
: Entity_Id
) return Node_Id
3838 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3841 Set_Debug_Info_Needed
(Def_Id
);
3843 if Present
(Ent_Id
) then
3844 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3848 Make_Procedure_Specification
(Loc
,
3849 Defining_Unit_Name
=> Def_Id
,
3850 Parameter_Specifications
=> New_List
(
3851 Make_Parameter_Specification
(Loc
,
3852 Defining_Identifier
=>
3853 Make_Defining_Identifier
(Loc
, Name_uO
),
3855 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3857 Make_Parameter_Specification
(Loc
,
3858 Defining_Identifier
=> P
,
3860 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3862 Make_Parameter_Specification
(Loc
,
3863 Defining_Identifier
=>
3864 Make_Defining_Identifier
(Loc
, Name_uE
),
3866 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
3867 end Build_Protected_Entry_Specification
;
3869 --------------------------
3870 -- Build_Protected_Spec --
3871 --------------------------
3873 function Build_Protected_Spec
3875 Obj_Type
: Entity_Id
;
3877 Unprotected
: Boolean := False) return List_Id
3879 Loc
: constant Source_Ptr
:= Sloc
(N
);
3882 New_Plist
: List_Id
;
3883 New_Param
: Node_Id
;
3886 New_Plist
:= New_List
;
3888 Formal
:= First_Formal
(Ident
);
3889 while Present
(Formal
) loop
3891 Make_Parameter_Specification
(Loc
,
3892 Defining_Identifier
=>
3893 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
3894 In_Present
=> In_Present
(Parent
(Formal
)),
3895 Out_Present
=> Out_Present
(Parent
(Formal
)),
3896 Parameter_Type
=> New_Reference_To
(Etype
(Formal
), Loc
));
3899 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
3902 Append
(New_Param
, New_Plist
);
3903 Next_Formal
(Formal
);
3906 -- If the subprogram is a procedure and the context is not an access
3907 -- to protected subprogram, the parameter is in-out. Otherwise it is
3911 Make_Parameter_Specification
(Loc
,
3912 Defining_Identifier
=>
3913 Make_Defining_Identifier
(Loc
, Name_uObject
),
3916 (Etype
(Ident
) = Standard_Void_Type
3917 and then not Is_RTE
(Obj_Type
, RE_Address
)),
3919 New_Reference_To
(Obj_Type
, Loc
));
3920 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
3921 Prepend_To
(New_Plist
, Decl
);
3924 end Build_Protected_Spec
;
3926 ---------------------------------------
3927 -- Build_Protected_Sub_Specification --
3928 ---------------------------------------
3930 function Build_Protected_Sub_Specification
3932 Prot_Typ
: Entity_Id
;
3933 Mode
: Subprogram_Protection_Mode
) return Node_Id
3935 Loc
: constant Source_Ptr
:= Sloc
(N
);
3939 New_Plist
: List_Id
;
3942 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
3943 (Dispatching_Mode
=> ' ',
3944 Protected_Mode
=> 'P',
3945 Unprotected_Mode
=> 'N');
3948 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
3951 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
3956 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
3959 Build_Protected_Spec
3960 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
3961 Mode
= Unprotected_Mode
);
3963 Make_Defining_Identifier
(Loc
,
3964 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
3966 -- The unprotected operation carries the user code, and debugging
3967 -- information must be generated for it, even though this spec does
3968 -- not come from source. It is also convenient to allow gdb to step
3969 -- into the protected operation, even though it only contains lock/
3972 Set_Debug_Info_Needed
(New_Id
);
3974 -- If a pragma Eliminate applies to the source entity, the internal
3975 -- subprograms will be eliminated as well.
3977 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
3979 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
3981 Make_Procedure_Specification
(Loc
,
3982 Defining_Unit_Name
=> New_Id
,
3983 Parameter_Specifications
=> New_Plist
);
3985 -- Create a new specification for the anonymous subprogram type
3989 Make_Function_Specification
(Loc
,
3990 Defining_Unit_Name
=> New_Id
,
3991 Parameter_Specifications
=> New_Plist
,
3992 Result_Definition
=>
3993 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
3995 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
3999 end Build_Protected_Sub_Specification
;
4001 -------------------------------------
4002 -- Build_Protected_Subprogram_Body --
4003 -------------------------------------
4005 function Build_Protected_Subprogram_Body
4008 N_Op_Spec
: Node_Id
) return Node_Id
4010 Loc
: constant Source_Ptr
:= Sloc
(N
);
4012 P_Op_Spec
: Node_Id
;
4015 Unprot_Call
: Node_Id
;
4017 Lock_Name
: Node_Id
;
4018 Lock_Stmt
: Node_Id
;
4019 Service_Name
: Node_Id
;
4021 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
4022 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
4024 Object_Parm
: Node_Id
;
4029 Op_Spec
:= Specification
(N
);
4030 Exc_Safe
:= Is_Exception_Safe
(N
);
4033 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
4035 -- Build a list of the formal parameters of the protected version of
4036 -- the subprogram to use as the actual parameters of the unprotected
4039 Uactuals
:= New_List
;
4040 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
4041 while Present
(Pformal
) loop
4042 Append_To
(Uactuals
,
4043 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
4047 -- Make a call to the unprotected version of the subprogram built above
4048 -- for use by the protected version built below.
4050 if Nkind
(Op_Spec
) = N_Function_Specification
then
4052 R
:= Make_Temporary
(Loc
, 'R');
4054 Make_Object_Declaration
(Loc
,
4055 Defining_Identifier
=> R
,
4056 Constant_Present
=> True,
4057 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
4059 Make_Function_Call
(Loc
,
4060 Name
=> Make_Identifier
(Loc
,
4061 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4062 Parameter_Associations
=> Uactuals
));
4065 Make_Simple_Return_Statement
(Loc
,
4066 Expression
=> New_Reference_To
(R
, Loc
));
4069 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
4070 Expression
=> Make_Function_Call
(Loc
,
4072 Make_Identifier
(Loc
,
4073 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4074 Parameter_Associations
=> Uactuals
));
4077 Lock_Kind
:= RE_Lock_Read_Only
;
4081 Make_Procedure_Call_Statement
(Loc
,
4083 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4084 Parameter_Associations
=> Uactuals
);
4086 Lock_Kind
:= RE_Lock
;
4089 -- Wrap call in block that will be covered by an at_end handler
4091 if not Exc_Safe
then
4092 Unprot_Call
:= Make_Block_Statement
(Loc
,
4093 Handled_Statement_Sequence
=>
4094 Make_Handled_Sequence_Of_Statements
(Loc
,
4095 Statements
=> New_List
(Unprot_Call
)));
4098 -- Make the protected subprogram body. This locks the protected
4099 -- object and calls the unprotected version of the subprogram.
4101 case Corresponding_Runtime_Package
(Pid
) is
4102 when System_Tasking_Protected_Objects_Entries
=>
4103 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
4104 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
4106 when System_Tasking_Protected_Objects_Single_Entry
=>
4107 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
4108 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
4110 when System_Tasking_Protected_Objects
=>
4111 Lock_Name
:= New_Reference_To
(RTE
(Lock_Kind
), Loc
);
4112 Service_Name
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
4115 raise Program_Error
;
4119 Make_Attribute_Reference
(Loc
,
4121 Make_Selected_Component
(Loc
,
4122 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4123 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4124 Attribute_Name
=> Name_Unchecked_Access
);
4126 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
4128 Parameter_Associations
=> New_List
(Object_Parm
));
4130 if Abort_Allowed
then
4132 Make_Procedure_Call_Statement
(Loc
,
4133 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
4134 Parameter_Associations
=> Empty_List
),
4138 Stmts
:= New_List
(Lock_Stmt
);
4141 if not Exc_Safe
then
4142 Append
(Unprot_Call
, Stmts
);
4144 if Nkind
(Op_Spec
) = N_Function_Specification
then
4146 Stmts
:= Empty_List
;
4148 Append
(Unprot_Call
, Stmts
);
4152 Make_Procedure_Call_Statement
(Loc
,
4153 Name
=> Service_Name
,
4154 Parameter_Associations
=>
4155 New_List
(New_Copy_Tree
(Object_Parm
))),
4158 if Abort_Allowed
then
4160 Make_Procedure_Call_Statement
(Loc
,
4161 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
4162 Parameter_Associations
=> Empty_List
),
4166 if Nkind
(Op_Spec
) = N_Function_Specification
then
4167 Append
(Return_Stmt
, Stmts
);
4168 Append
(Make_Block_Statement
(Loc
,
4169 Declarations
=> New_List
(Unprot_Call
),
4170 Handled_Statement_Sequence
=>
4171 Make_Handled_Sequence_Of_Statements
(Loc
,
4172 Statements
=> Stmts
)), Pre_Stmts
);
4178 Make_Subprogram_Body
(Loc
,
4179 Declarations
=> Empty_List
,
4180 Specification
=> P_Op_Spec
,
4181 Handled_Statement_Sequence
=>
4182 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4184 if not Exc_Safe
then
4185 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4189 end Build_Protected_Subprogram_Body
;
4191 -------------------------------------
4192 -- Build_Protected_Subprogram_Call --
4193 -------------------------------------
4195 procedure Build_Protected_Subprogram_Call
4199 External
: Boolean := True)
4201 Loc
: constant Source_Ptr
:= Sloc
(N
);
4202 Sub
: constant Entity_Id
:= Entity
(Name
);
4208 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4211 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4214 if Present
(Parameter_Associations
(N
)) then
4215 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4220 -- If the type is an untagged derived type, convert to the root type,
4221 -- which is the one on which the operations are defined.
4223 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4224 and then not Is_Tagged_Type
(Etype
(Rec
))
4225 and then Is_Derived_Type
(Etype
(Rec
))
4227 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4228 Set_Subtype_Mark
(Rec
,
4229 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4232 Prepend
(Rec
, Params
);
4234 if Ekind
(Sub
) = E_Procedure
then
4236 Make_Procedure_Call_Statement
(Loc
,
4238 Parameter_Associations
=> Params
));
4241 pragma Assert
(Ekind
(Sub
) = E_Function
);
4243 Make_Function_Call
(Loc
,
4245 Parameter_Associations
=> Params
));
4249 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4250 and then Is_Entity_Name
(Expression
(Rec
))
4251 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4253 Add_Shared_Var_Lock_Procs
(N
);
4255 end Build_Protected_Subprogram_Call
;
4257 -------------------------
4258 -- Build_Selected_Name --
4259 -------------------------
4261 function Build_Selected_Name
4262 (Prefix
: Entity_Id
;
4263 Selector
: Entity_Id
;
4264 Append_Char
: Character := ' ') return Name_Id
4266 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4267 Select_Len
: Natural;
4270 Get_Name_String
(Chars
(Selector
));
4271 Select_Len
:= Name_Len
;
4272 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4273 Get_Name_String
(Chars
(Prefix
));
4275 -- If scope is anonymous type, discard suffix to recover name of
4276 -- single protected object. Otherwise use protected type name.
4278 if Name_Buffer
(Name_Len
) = 'T' then
4279 Name_Len
:= Name_Len
- 1;
4282 Add_Str_To_Name_Buffer
("__");
4283 for J
in 1 .. Select_Len
loop
4284 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4287 -- Now add the Append_Char if specified. The encoding to follow
4288 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4289 -- then the entity is associated to a protected type subprogram.
4290 -- Otherwise, it is a protected type entry. For each case, the
4291 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4293 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4295 if Append_Char
/= ' ' then
4296 if Append_Char
= 'P' or Append_Char
= 'N' then
4297 Add_Char_To_Name_Buffer
(Append_Char
);
4300 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4301 return New_External_Name
(Name_Find
, ' ', -1);
4306 end Build_Selected_Name
;
4308 -----------------------------
4309 -- Build_Simple_Entry_Call --
4310 -----------------------------
4312 -- A task entry call is converted to a call to Call_Simple
4315 -- P : parms := (parm, parm, parm);
4317 -- Call_Simple (acceptor-task, entry-index, P'Address);
4323 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4324 -- the parameters, and the constructed aggregate value contains either the
4325 -- parameters or, in the case of non-elementary types, references to these
4326 -- parameters. Then the address of this aggregate is passed to the runtime
4327 -- routine, along with the task id value and the task entry index value.
4328 -- Pnn is only required if parameters are present.
4330 -- The assignments after the call are present only in the case of in-out
4331 -- or out parameters for elementary types, and are used to assign back the
4332 -- resulting values of such parameters.
4334 -- Note: the reason that we insert a block here is that in the context
4335 -- of selects, conditional entry calls etc. the entry call statement
4336 -- appears on its own, not as an element of a list.
4338 -- A protected entry call is converted to a Protected_Entry_Call:
4341 -- P : E1_Params := (param, param, param);
4343 -- Bnn : Communications_Block;
4346 -- P : E1_Params := (param, param, param);
4347 -- Bnn : Communications_Block;
4350 -- Protected_Entry_Call (
4351 -- Object => po._object'Access,
4352 -- E => <entry index>;
4353 -- Uninterpreted_Data => P'Address;
4354 -- Mode => Simple_Call;
4361 procedure Build_Simple_Entry_Call
4370 -- If call has been inlined, nothing left to do
4372 if Nkind
(N
) = N_Block_Statement
then
4376 -- Convert entry call to Call_Simple call
4379 Loc
: constant Source_Ptr
:= Sloc
(N
);
4380 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4381 Stats
: constant List_Id
:= New_List
;
4384 Comm_Name
: Entity_Id
;
4388 Ent_Acc
: Entity_Id
;
4390 Iface_Tag
: Entity_Id
;
4391 Iface_Typ
: Entity_Id
;
4404 -- Simple entry and entry family cases merge here
4406 Ent
:= Entity
(Ename
);
4407 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4408 Conctyp
:= Etype
(Concval
);
4410 -- If prefix is an access type, dereference to obtain the task type
4412 if Is_Access_Type
(Conctyp
) then
4413 Conctyp
:= Designated_Type
(Conctyp
);
4416 -- Special case for protected subprogram calls
4418 if Is_Protected_Type
(Conctyp
)
4419 and then Is_Subprogram
(Entity
(Ename
))
4421 if not Is_Eliminated
(Entity
(Ename
)) then
4422 Build_Protected_Subprogram_Call
4423 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4430 -- First parameter is the Task_Id value from the task value or the
4431 -- Object from the protected object value, obtained by selecting
4432 -- the _Task_Id or _Object from the result of doing an unchecked
4433 -- conversion to convert the value to the corresponding record type.
4435 if Nkind
(Concval
) = N_Function_Call
4436 and then Is_Task_Type
(Conctyp
)
4437 and then Ada_Version
>= Ada_2005
4440 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4441 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4446 Make_Object_Declaration
(Loc
,
4447 Defining_Identifier
=> Obj
,
4448 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4449 Expression
=> ExpR
);
4450 Set_Etype
(Obj
, Conctyp
);
4451 Decls
:= New_List
(Decl
);
4452 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4459 Parm1
:= Concurrent_Ref
(Concval
);
4461 -- Second parameter is the entry index, computed by the routine
4462 -- provided for this purpose. The value of this expression is
4463 -- assigned to an intermediate variable to assure that any entry
4464 -- family index expressions are evaluated before the entry
4468 or else Restriction_Active
(No_Entry_Queue
) = False
4469 or else not Is_Protected_Type
(Conctyp
)
4470 or else Number_Entries
(Conctyp
) > 1
4471 or else (Has_Attach_Handler
(Conctyp
)
4472 and then not Restricted_Profile
)
4474 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4477 Make_Object_Declaration
(Loc
,
4478 Defining_Identifier
=> X
,
4479 Object_Definition
=>
4480 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
4481 Expression
=> Actual_Index_Expression
(
4482 Loc
, Entity
(Ename
), Index
, Concval
));
4484 Append_To
(Decls
, Xdecl
);
4485 Parm2
:= New_Reference_To
(X
, Loc
);
4492 -- The third parameter is the packaged parameters. If there are
4493 -- none, then it is just the null address, since nothing is passed.
4496 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
4499 -- Case of parameters present, where third argument is the address
4500 -- of a packaged record containing the required parameter values.
4503 -- First build a list of parameter values, which are references to
4504 -- objects of the parameter types.
4508 Actual
:= First_Actual
(N
);
4509 Formal
:= First_Formal
(Ent
);
4511 while Present
(Actual
) loop
4513 -- If it is a by_copy_type, copy it to a new variable. The
4514 -- packaged record has a field that points to this variable.
4516 if Is_By_Copy_Type
(Etype
(Actual
)) then
4518 Make_Object_Declaration
(Loc
,
4519 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4520 Aliased_Present
=> True,
4521 Object_Definition
=>
4522 New_Reference_To
(Etype
(Formal
), Loc
));
4524 -- Mark the object as not needing initialization since the
4525 -- initialization is performed separately, avoiding errors
4526 -- on cases such as formals of null-excluding access types.
4528 Set_No_Initialization
(N_Node
);
4530 -- We must make an assignment statement separate for the
4531 -- case of limited type. We cannot assign it unless the
4532 -- Assignment_OK flag is set first. An out formal of an
4533 -- access type must also be initialized from the actual,
4534 -- as stated in RM 6.4.1 (13).
4536 if Ekind
(Formal
) /= E_Out_Parameter
4537 or else Is_Access_Type
(Etype
(Formal
))
4540 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
4541 Set_Assignment_OK
(N_Var
);
4543 Make_Assignment_Statement
(Loc
,
4545 Expression
=> Relocate_Node
(Actual
)));
4548 Append
(N_Node
, Decls
);
4551 Make_Attribute_Reference
(Loc
,
4552 Attribute_Name
=> Name_Unchecked_Access
,
4554 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4556 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4558 elsif Is_VM_By_Copy_Actual
(Actual
) then
4560 Make_Object_Declaration
(Loc
,
4561 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4562 Aliased_Present
=> True,
4563 Object_Definition
=>
4564 New_Reference_To
(Etype
(Formal
), Loc
),
4565 Expression
=> New_Copy_Tree
(Actual
));
4566 Set_Assignment_OK
(N_Node
);
4568 Append
(N_Node
, Decls
);
4571 Make_Attribute_Reference
(Loc
,
4572 Attribute_Name
=> Name_Unchecked_Access
,
4574 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4577 -- Interface class-wide formal
4579 if Ada_Version
>= Ada_2005
4580 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4581 and then Is_Interface
(Etype
(Formal
))
4583 Iface_Typ
:= Etype
(Etype
(Formal
));
4586 -- formal_iface_type! (actual.iface_tag)'reference
4589 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4590 pragma Assert
(Present
(Iface_Tag
));
4593 Make_Reference
(Loc
,
4594 Unchecked_Convert_To
(Iface_Typ
,
4595 Make_Selected_Component
(Loc
,
4597 Relocate_Node
(Actual
),
4599 New_Reference_To
(Iface_Tag
, Loc
)))));
4605 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4609 Next_Actual
(Actual
);
4610 Next_Formal_With_Extras
(Formal
);
4613 -- Now build the declaration of parameters initialized with the
4614 -- aggregate containing this constructed parameter list.
4616 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4619 Make_Object_Declaration
(Loc
,
4620 Defining_Identifier
=> P
,
4621 Object_Definition
=>
4622 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
4624 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4627 Make_Attribute_Reference
(Loc
,
4628 Prefix
=> New_Reference_To
(P
, Loc
),
4629 Attribute_Name
=> Name_Address
);
4631 Append
(Pdecl
, Decls
);
4634 -- Now we can create the call, case of protected type
4636 if Is_Protected_Type
(Conctyp
) then
4637 case Corresponding_Runtime_Package
(Conctyp
) is
4638 when System_Tasking_Protected_Objects_Entries
=>
4640 -- Change the type of the index declaration
4642 Set_Object_Definition
(Xdecl
,
4643 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
4645 -- Some additional declarations for protected entry calls
4651 -- Bnn : Communications_Block;
4653 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4656 Make_Object_Declaration
(Loc
,
4657 Defining_Identifier
=> Comm_Name
,
4658 Object_Definition
=>
4659 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
4661 -- Some additional statements for protected entry calls
4663 -- Protected_Entry_Call (
4664 -- Object => po._object'Access,
4665 -- E => <entry index>;
4666 -- Uninterpreted_Data => P'Address;
4667 -- Mode => Simple_Call;
4671 Make_Procedure_Call_Statement
(Loc
,
4673 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
4675 Parameter_Associations
=> New_List
(
4676 Make_Attribute_Reference
(Loc
,
4677 Attribute_Name
=> Name_Unchecked_Access
,
4681 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
4682 New_Occurrence_Of
(Comm_Name
, Loc
)));
4684 when System_Tasking_Protected_Objects_Single_Entry
=>
4685 -- Protected_Single_Entry_Call (
4686 -- Object => po._object'Access,
4687 -- Uninterpreted_Data => P'Address;
4688 -- Mode => Simple_Call);
4691 Make_Procedure_Call_Statement
(Loc
,
4692 Name
=> New_Reference_To
(
4693 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4695 Parameter_Associations
=> New_List
(
4696 Make_Attribute_Reference
(Loc
,
4697 Attribute_Name
=> Name_Unchecked_Access
,
4700 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
4703 raise Program_Error
;
4706 -- Case of task type
4710 Make_Procedure_Call_Statement
(Loc
,
4711 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
4712 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4716 Append_To
(Stats
, Call
);
4718 -- If there are out or in/out parameters by copy add assignment
4719 -- statements for the result values.
4721 if Present
(Parms
) then
4722 Actual
:= First_Actual
(N
);
4723 Formal
:= First_Formal
(Ent
);
4725 Set_Assignment_OK
(Actual
);
4726 while Present
(Actual
) loop
4727 if (Is_By_Copy_Type
(Etype
(Actual
))
4728 or else Is_VM_By_Copy_Actual
(Actual
))
4729 and then Ekind
(Formal
) /= E_In_Parameter
4732 Make_Assignment_Statement
(Loc
,
4733 Name
=> New_Copy
(Actual
),
4735 Make_Explicit_Dereference
(Loc
,
4736 Make_Selected_Component
(Loc
,
4737 Prefix
=> New_Reference_To
(P
, Loc
),
4739 Make_Identifier
(Loc
, Chars
(Formal
)))));
4741 -- In all cases (including limited private types) we want
4742 -- the assignment to be valid.
4744 Set_Assignment_OK
(Name
(N_Node
));
4746 -- If the call is the triggering alternative in an
4747 -- asynchronous select, or the entry_call alternative of a
4748 -- conditional entry call, the assignments for in-out
4749 -- parameters are incorporated into the statement list that
4750 -- follows, so that there are executed only if the entry
4753 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4754 and then N
= Triggering_Statement
(Parent
(N
)))
4756 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4757 and then N
= Entry_Call_Statement
(Parent
(N
)))
4759 if No
(Statements
(Parent
(N
))) then
4760 Set_Statements
(Parent
(N
), New_List
);
4763 Prepend
(N_Node
, Statements
(Parent
(N
)));
4766 Insert_After
(Call
, N_Node
);
4770 Next_Actual
(Actual
);
4771 Next_Formal_With_Extras
(Formal
);
4775 -- Finally, create block and analyze it
4778 Make_Block_Statement
(Loc
,
4779 Declarations
=> Decls
,
4780 Handled_Statement_Sequence
=>
4781 Make_Handled_Sequence_Of_Statements
(Loc
,
4782 Statements
=> Stats
)));
4786 end Build_Simple_Entry_Call
;
4788 --------------------------------
4789 -- Build_Task_Activation_Call --
4790 --------------------------------
4792 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4793 Loc
: constant Source_Ptr
:= Sloc
(N
);
4800 -- Get the activation chain entity. Except in the case of a package
4801 -- body, this is in the node that was passed. For a package body, we
4802 -- have to find the corresponding package declaration node.
4804 if Nkind
(N
) = N_Package_Body
then
4805 P
:= Corresponding_Spec
(N
);
4808 exit when Nkind
(P
) = N_Package_Declaration
;
4811 Chain
:= Activation_Chain_Entity
(P
);
4814 Chain
:= Activation_Chain_Entity
(N
);
4817 if Present
(Chain
) then
4818 if Restricted_Profile
then
4819 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4821 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
4825 Make_Procedure_Call_Statement
(Loc
,
4827 Parameter_Associations
=>
4828 New_List
(Make_Attribute_Reference
(Loc
,
4829 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4830 Attribute_Name
=> Name_Unchecked_Access
)));
4832 if Nkind
(N
) = N_Package_Declaration
then
4833 if Present
(Corresponding_Body
(N
)) then
4836 elsif Present
(Private_Declarations
(Specification
(N
))) then
4837 Append
(Call
, Private_Declarations
(Specification
(N
)));
4840 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4844 if Present
(Handled_Statement_Sequence
(N
)) then
4846 -- The call goes at the start of the statement sequence
4847 -- after the start of exception range label if one is present.
4853 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4855 -- A special case, skip exception range label if one is
4856 -- present (from front end zcx processing).
4858 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
4862 -- Another special case, if the first statement is a block
4863 -- from optimization of a local raise to a goto, then the
4864 -- call goes inside this block.
4866 if Nkind
(Stm
) = N_Block_Statement
4867 and then Exception_Junk
(Stm
)
4870 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
4873 -- Insertion point is after any exception label pushes,
4874 -- since we want it covered by any local handlers.
4876 while Nkind
(Stm
) in N_Push_xxx_Label
loop
4880 -- Now we have the proper insertion point
4882 Insert_Before
(Stm
, Call
);
4886 Set_Handled_Statement_Sequence
(N
,
4887 Make_Handled_Sequence_Of_Statements
(Loc
,
4888 Statements
=> New_List
(Call
)));
4893 Check_Task_Activation
(N
);
4895 end Build_Task_Activation_Call
;
4897 -------------------------------
4898 -- Build_Task_Allocate_Block --
4899 -------------------------------
4901 procedure Build_Task_Allocate_Block
4906 T
: constant Entity_Id
:= Entity
(Expression
(N
));
4907 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
4908 Loc
: constant Source_Ptr
:= Sloc
(N
);
4909 Chain
: constant Entity_Id
:=
4910 Make_Defining_Identifier
(Loc
, Name_uChain
);
4911 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4916 Make_Block_Statement
(Loc
,
4917 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4918 Declarations
=> New_List
(
4920 -- _Chain : Activation_Chain;
4922 Make_Object_Declaration
(Loc
,
4923 Defining_Identifier
=> Chain
,
4924 Aliased_Present
=> True,
4925 Object_Definition
=>
4926 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
4928 Handled_Statement_Sequence
=>
4929 Make_Handled_Sequence_Of_Statements
(Loc
,
4931 Statements
=> New_List
(
4935 Make_Procedure_Call_Statement
(Loc
,
4936 Name
=> New_Reference_To
(Init
, Loc
),
4937 Parameter_Associations
=> Args
),
4939 -- Activate_Tasks (_Chain);
4941 Make_Procedure_Call_Statement
(Loc
,
4942 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
4943 Parameter_Associations
=> New_List
(
4944 Make_Attribute_Reference
(Loc
,
4945 Prefix
=> New_Reference_To
(Chain
, Loc
),
4946 Attribute_Name
=> Name_Unchecked_Access
))))),
4948 Has_Created_Identifier
=> True,
4949 Is_Task_Allocation_Block
=> True);
4952 Make_Implicit_Label_Declaration
(Loc
,
4953 Defining_Identifier
=> Blkent
,
4954 Label_Construct
=> Block
));
4956 Append_To
(Actions
, Block
);
4958 Set_Activation_Chain_Entity
(Block
, Chain
);
4959 end Build_Task_Allocate_Block
;
4961 -----------------------------------------------
4962 -- Build_Task_Allocate_Block_With_Init_Stmts --
4963 -----------------------------------------------
4965 procedure Build_Task_Allocate_Block_With_Init_Stmts
4968 Init_Stmts
: List_Id
)
4970 Loc
: constant Source_Ptr
:= Sloc
(N
);
4971 Chain
: constant Entity_Id
:=
4972 Make_Defining_Identifier
(Loc
, Name_uChain
);
4973 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4977 Append_To
(Init_Stmts
,
4978 Make_Procedure_Call_Statement
(Loc
,
4979 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
4980 Parameter_Associations
=> New_List
(
4981 Make_Attribute_Reference
(Loc
,
4982 Prefix
=> New_Reference_To
(Chain
, Loc
),
4983 Attribute_Name
=> Name_Unchecked_Access
))));
4986 Make_Block_Statement
(Loc
,
4987 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4988 Declarations
=> New_List
(
4990 -- _Chain : Activation_Chain;
4992 Make_Object_Declaration
(Loc
,
4993 Defining_Identifier
=> Chain
,
4994 Aliased_Present
=> True,
4995 Object_Definition
=>
4996 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
4998 Handled_Statement_Sequence
=>
4999 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5001 Has_Created_Identifier
=> True,
5002 Is_Task_Allocation_Block
=> True);
5005 Make_Implicit_Label_Declaration
(Loc
,
5006 Defining_Identifier
=> Blkent
,
5007 Label_Construct
=> Block
));
5009 Append_To
(Actions
, Block
);
5011 Set_Activation_Chain_Entity
(Block
, Chain
);
5012 end Build_Task_Allocate_Block_With_Init_Stmts
;
5014 -----------------------------------
5015 -- Build_Task_Proc_Specification --
5016 -----------------------------------
5018 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5019 Loc
: constant Source_Ptr
:= Sloc
(T
);
5020 Spec_Id
: Entity_Id
;
5023 -- Case of explicit task type, suffix TB
5025 if Comes_From_Source
(T
) then
5027 Make_Defining_Identifier
(Loc
,
5028 Chars
=> New_External_Name
(Chars
(T
), "TB"));
5030 -- Case of anonymous task type, suffix B
5034 Make_Defining_Identifier
(Loc
,
5035 Chars
=> New_External_Name
(Chars
(T
), 'B'));
5038 Set_Is_Internal
(Spec_Id
);
5040 -- Associate the procedure with the task, if this is the declaration
5041 -- (and not the body) of the procedure.
5043 if No
(Task_Body_Procedure
(T
)) then
5044 Set_Task_Body_Procedure
(T
, Spec_Id
);
5048 Make_Procedure_Specification
(Loc
,
5049 Defining_Unit_Name
=> Spec_Id
,
5050 Parameter_Specifications
=> New_List
(
5051 Make_Parameter_Specification
(Loc
,
5052 Defining_Identifier
=>
5053 Make_Defining_Identifier
(Loc
, Name_uTask
),
5055 Make_Access_Definition
(Loc
,
5057 New_Reference_To
(Corresponding_Record_Type
(T
), Loc
)))));
5058 end Build_Task_Proc_Specification
;
5060 ---------------------------------------
5061 -- Build_Unprotected_Subprogram_Body --
5062 ---------------------------------------
5064 function Build_Unprotected_Subprogram_Body
5066 Pid
: Node_Id
) return Node_Id
5068 Decls
: constant List_Id
:= Declarations
(N
);
5071 -- Add renamings for the Protection object, discriminals, privals and
5072 -- the entry index constant for use by debugger.
5074 Debug_Private_Data_Declarations
(Decls
);
5076 -- Make an unprotected version of the subprogram for use within the same
5077 -- object, with a new name and an additional parameter representing the
5081 Make_Subprogram_Body
(Sloc
(N
),
5083 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5084 Declarations
=> Decls
,
5085 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5086 end Build_Unprotected_Subprogram_Body
;
5088 ----------------------------
5089 -- Collect_Entry_Families --
5090 ----------------------------
5092 procedure Collect_Entry_Families
5095 Current_Node
: in out Node_Id
;
5096 Conctyp
: Entity_Id
)
5099 Efam_Decl
: Node_Id
;
5100 Efam_Type
: Entity_Id
;
5103 Efam
:= First_Entity
(Conctyp
);
5104 while Present
(Efam
) loop
5105 if Ekind
(Efam
) = E_Entry_Family
then
5106 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5111 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5113 Bas_Decl
: Node_Id
:= Empty
;
5118 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5120 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5121 Bas
:= Make_Temporary
(Loc
, 'B');
5124 Make_Subtype_Declaration
(Loc
,
5125 Defining_Identifier
=> Bas
,
5126 Subtype_Indication
=>
5127 Make_Subtype_Indication
(Loc
,
5129 New_Occurrence_Of
(Standard_Integer
, Loc
),
5131 Make_Range_Constraint
(Loc
,
5132 Range_Expression
=> Make_Range
(Loc
,
5133 Make_Integer_Literal
5134 (Loc
, -Entry_Family_Bound
),
5135 Make_Integer_Literal
5136 (Loc
, Entry_Family_Bound
- 1)))));
5138 Insert_After
(Current_Node
, Bas_Decl
);
5139 Current_Node
:= Bas_Decl
;
5144 Make_Full_Type_Declaration
(Loc
,
5145 Defining_Identifier
=> Efam_Type
,
5147 Make_Unconstrained_Array_Definition
(Loc
,
5149 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5151 Component_Definition
=>
5152 Make_Component_Definition
(Loc
,
5153 Aliased_Present
=> False,
5154 Subtype_Indication
=>
5155 New_Reference_To
(Standard_Character
, Loc
))));
5158 Insert_After
(Current_Node
, Efam_Decl
);
5159 Current_Node
:= Efam_Decl
;
5160 Analyze
(Efam_Decl
);
5163 Make_Component_Declaration
(Loc
,
5164 Defining_Identifier
=>
5165 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5167 Component_Definition
=>
5168 Make_Component_Definition
(Loc
,
5169 Aliased_Present
=> False,
5170 Subtype_Indication
=>
5171 Make_Subtype_Indication
(Loc
,
5173 New_Occurrence_Of
(Efam_Type
, Loc
),
5176 Make_Index_Or_Discriminant_Constraint
(Loc
,
5177 Constraints
=> New_List
(
5179 (Etype
(Discrete_Subtype_Definition
5180 (Parent
(Efam
))), Loc
)))))));
5186 end Collect_Entry_Families
;
5188 -----------------------
5189 -- Concurrent_Object --
5190 -----------------------
5192 function Concurrent_Object
5193 (Spec_Id
: Entity_Id
;
5194 Conc_Typ
: Entity_Id
) return Entity_Id
5197 -- Parameter _O or _object
5199 if Is_Protected_Type
(Conc_Typ
) then
5200 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5205 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5206 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5208 end Concurrent_Object
;
5210 ----------------------
5211 -- Copy_Result_Type --
5212 ----------------------
5214 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5215 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5220 -- If the result type is an access_to_subprogram, we must create
5221 -- new entities for its spec.
5223 if Nkind
(New_Res
) = N_Access_Definition
5224 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5226 -- Provide new entities for the formals
5228 Par_Spec
:= First
(Parameter_Specifications
5229 (Access_To_Subprogram_Definition
(New_Res
)));
5230 while Present
(Par_Spec
) loop
5231 Formal
:= Defining_Identifier
(Par_Spec
);
5232 Set_Defining_Identifier
(Par_Spec
,
5233 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5239 end Copy_Result_Type
;
5241 --------------------
5242 -- Concurrent_Ref --
5243 --------------------
5245 -- The expression returned for a reference to a concurrent object has the
5248 -- taskV!(name)._Task_Id
5252 -- objectV!(name)._Object
5254 -- for a protected object. For the case of an access to a concurrent
5255 -- object, there is an extra explicit dereference:
5257 -- taskV!(name.all)._Task_Id
5258 -- objectV!(name.all)._Object
5260 -- here taskV and objectV are the types for the associated records, which
5261 -- contain the required _Task_Id and _Object fields for tasks and protected
5262 -- objects, respectively.
5264 -- For the case of a task type name, the expression is
5268 -- i.e. a call to the Self function which returns precisely this Task_Id
5270 -- For the case of a protected type name, the expression is
5274 -- which is a renaming of the _object field of the current object
5275 -- record, passed into protected operations as a parameter.
5277 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5278 Loc
: constant Source_Ptr
:= Sloc
(N
);
5279 Ntyp
: constant Entity_Id
:= Etype
(N
);
5283 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5284 -- Check whether the reference is to the immediately enclosing task
5285 -- type, or to an outer one (rare but legal).
5287 ---------------------
5288 -- Is_Current_Task --
5289 ---------------------
5291 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5295 Scop
:= Current_Scope
;
5296 while Present
(Scop
)
5297 and then Scop
/= Standard_Standard
5303 elsif Is_Task_Type
(Scop
) then
5306 -- If this is a procedure nested within the task type, we must
5307 -- assume that it can be called from an inner task, and therefore
5308 -- cannot treat it as a local reference.
5310 elsif Is_Overloadable
(Scop
)
5311 and then In_Open_Scopes
(T
)
5316 Scop
:= Scope
(Scop
);
5320 -- We know that we are within the task body, so should have found it
5323 raise Program_Error
;
5324 end Is_Current_Task
;
5326 -- Start of processing for Concurrent_Ref
5329 if Is_Access_Type
(Ntyp
) then
5330 Dtyp
:= Designated_Type
(Ntyp
);
5332 if Is_Protected_Type
(Dtyp
) then
5333 Sel
:= Name_uObject
;
5335 Sel
:= Name_uTask_Id
;
5339 Make_Selected_Component
(Loc
,
5341 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5342 Make_Explicit_Dereference
(Loc
, N
)),
5343 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5345 elsif Is_Entity_Name
(N
)
5346 and then Is_Concurrent_Type
(Entity
(N
))
5348 if Is_Task_Type
(Entity
(N
)) then
5350 if Is_Current_Task
(Entity
(N
)) then
5352 Make_Function_Call
(Loc
,
5353 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
5358 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5359 T_Body
: constant Node_Id
:=
5360 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5364 Make_Object_Declaration
(Loc
,
5365 Defining_Identifier
=> T_Self
,
5366 Object_Definition
=>
5367 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5369 Make_Function_Call
(Loc
,
5370 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
5371 Prepend
(Decl
, Declarations
(T_Body
));
5373 Set_Scope
(T_Self
, Entity
(N
));
5374 return New_Occurrence_Of
(T_Self
, Loc
);
5379 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5382 New_Reference_To
(Find_Protection_Object
(Current_Scope
), Loc
);
5386 if Is_Protected_Type
(Ntyp
) then
5387 Sel
:= Name_uObject
;
5389 elsif Is_Task_Type
(Ntyp
) then
5390 Sel
:= Name_uTask_Id
;
5393 raise Program_Error
;
5397 Make_Selected_Component
(Loc
,
5399 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5401 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5405 ------------------------
5406 -- Convert_Concurrent --
5407 ------------------------
5409 function Convert_Concurrent
5411 Typ
: Entity_Id
) return Node_Id
5414 if not Is_Concurrent_Type
(Typ
) then
5418 Unchecked_Convert_To
5419 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5421 end Convert_Concurrent
;
5423 -------------------------------------
5424 -- Debug_Private_Data_Declarations --
5425 -------------------------------------
5427 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5428 Debug_Nod
: Node_Id
;
5432 Decl
:= First
(Decls
);
5433 while Present
(Decl
)
5434 and then not Comes_From_Source
(Decl
)
5436 -- Declaration for concurrent entity _object and its access type,
5437 -- along with the entry index subtype:
5438 -- type prot_typVP is access prot_typV;
5439 -- _object : prot_typVP := prot_typV (_O);
5440 -- subtype Jnn is <Type of Index> range Low .. High;
5442 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5443 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5445 -- Declaration for the Protection object, discriminals, privals and
5446 -- entry index constant:
5447 -- conc_typR : protection_typ renames _object._object;
5448 -- discr_nameD : discr_typ renames _object.discr_name;
5449 -- discr_nameD : discr_typ renames _task.discr_name;
5450 -- prival_name : comp_typ renames _object.comp_name;
5451 -- J : constant Jnn :=
5452 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5454 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5455 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5456 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5458 if Present
(Debug_Nod
) then
5459 Insert_After
(Decl
, Debug_Nod
);
5465 end Debug_Private_Data_Declarations
;
5467 ----------------------------
5468 -- Entry_Index_Expression --
5469 ----------------------------
5471 function Entry_Index_Expression
5475 Ttyp
: Entity_Id
) return Node_Id
5485 -- The queues of entries and entry families appear in textual order in
5486 -- the associated record. The entry index is computed as the sum of the
5487 -- number of queues for all entries that precede the designated one, to
5488 -- which is added the index expression, if this expression denotes a
5489 -- member of a family.
5491 -- The following is a place holder for the count of simple entries
5493 Num
:= Make_Integer_Literal
(Sloc
, 1);
5495 -- We construct an expression which is a series of addition operations.
5496 -- The first operand is the number of single entries that precede this
5497 -- one, the second operand is the index value relative to the start of
5498 -- the referenced family, and the remaining operands are the lengths of
5499 -- the entry families that precede this entry, i.e. the constructed
5502 -- number_simple_entries +
5503 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5504 -- family'length + ...
5506 -- where index-value is the given index value, and s is the index
5507 -- subtype (we have to use pos because the subtype might be an
5508 -- enumeration type preventing direct subtraction). Note that the task
5509 -- entry array is one-indexed.
5511 -- The upper bound of the entry family may be a discriminant, so we
5512 -- retrieve the lower bound explicitly to compute offset, rather than
5513 -- using the index subtype which may mention a discriminant.
5515 if Present
(Index
) then
5516 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5525 Make_Attribute_Reference
(Sloc
,
5526 Attribute_Name
=> Name_Pos
,
5527 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
5528 Expressions
=> New_List
(Relocate_Node
(Index
))),
5536 -- Now add lengths of preceding entries and entry families
5538 Prev
:= First_Entity
(Ttyp
);
5540 while Chars
(Prev
) /= Chars
(Ent
)
5541 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5542 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5544 if Ekind
(Prev
) = E_Entry
then
5545 Set_Intval
(Num
, Intval
(Num
) + 1);
5547 elsif Ekind
(Prev
) = E_Entry_Family
then
5549 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5550 Lo
:= Type_Low_Bound
(S
);
5551 Hi
:= Type_High_Bound
(S
);
5556 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5558 -- Other components are anonymous types to be ignored
5568 end Entry_Index_Expression
;
5570 ---------------------------
5571 -- Establish_Task_Master --
5572 ---------------------------
5574 procedure Establish_Task_Master
(N
: Node_Id
) is
5578 if Restriction_Active
(No_Task_Hierarchy
) = False then
5579 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5581 -- The block may have no declarations, and nevertheless be a task
5582 -- master, if it contains a call that may return an object that
5585 if No
(Declarations
(N
)) then
5586 Set_Declarations
(N
, New_List
(Call
));
5588 Prepend_To
(Declarations
(N
), Call
);
5593 end Establish_Task_Master
;
5595 --------------------------------
5596 -- Expand_Accept_Declarations --
5597 --------------------------------
5599 -- Part of the expansion of an accept statement involves the creation of
5600 -- a declaration that can be referenced from the statement sequence of
5605 -- This declaration is inserted immediately before the accept statement
5606 -- and it is important that it be inserted before the statements of the
5607 -- statement sequence are analyzed. Thus it would be too late to create
5608 -- this declaration in the Expand_N_Accept_Statement routine, which is
5609 -- why there is a separate procedure to be called directly from Sem_Ch9.
5611 -- Ann is used to hold the address of the record containing the parameters
5612 -- (see Expand_N_Entry_Call for more details on how this record is built).
5613 -- References to the parameters do an unchecked conversion of this address
5614 -- to a pointer to the required record type, and then access the field that
5615 -- holds the value of the required parameter. The entity for the address
5616 -- variable is held as the top stack element (i.e. the last element) of the
5617 -- Accept_Address stack in the corresponding entry entity, and this element
5618 -- must be set in place before the statements are processed.
5620 -- The above description applies to the case of a stand alone accept
5621 -- statement, i.e. one not appearing as part of a select alternative.
5623 -- For the case of an accept that appears as part of a select alternative
5624 -- of a selective accept, we must still create the declaration right away,
5625 -- since Ann is needed immediately, but there is an important difference:
5627 -- The declaration is inserted before the selective accept, not before
5628 -- the accept statement (which is not part of a list anyway, and so would
5629 -- not accommodate inserted declarations)
5631 -- We only need one address variable for the entire selective accept. So
5632 -- the Ann declaration is created only for the first accept alternative,
5633 -- and subsequent accept alternatives reference the same Ann variable.
5635 -- We can distinguish the two cases by seeing whether the accept statement
5636 -- is part of a list. If not, then it must be in an accept alternative.
5638 -- To expand the requeue statement, a label is provided at the end of the
5639 -- accept statement or alternative of which it is a part, so that the
5640 -- statement can be skipped after the requeue is complete. This label is
5641 -- created here rather than during the expansion of the accept statement,
5642 -- because it will be needed by any requeue statements within the accept,
5643 -- which are expanded before the accept.
5645 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5646 Loc
: constant Source_Ptr
:= Sloc
(N
);
5647 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5648 Ann
: Entity_Id
:= Empty
;
5656 if Full_Expander_Active
then
5658 -- If we have no handled statement sequence, we may need to build
5659 -- a dummy sequence consisting of a null statement. This can be
5660 -- skipped if the trivial accept optimization is permitted.
5662 if not Trivial_Accept_OK
5664 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5666 Set_Handled_Statement_Sequence
(N
,
5667 Make_Handled_Sequence_Of_Statements
(Loc
,
5668 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5671 -- Create and declare two labels to be placed at the end of the
5672 -- accept statement. The first label is used to allow requeues to
5673 -- skip the remainder of entry processing. The second label is used
5674 -- to skip the remainder of entry processing if the rendezvous
5675 -- completes in the middle of the accept body.
5677 if Present
(Handled_Statement_Sequence
(N
)) then
5682 Ent
:= Make_Temporary
(Loc
, 'L');
5683 Lab_Id
:= New_Reference_To
(Ent
, Loc
);
5684 Lab
:= Make_Label
(Loc
, Lab_Id
);
5686 Make_Implicit_Label_Declaration
(Loc
,
5687 Defining_Identifier
=> Ent
,
5688 Label_Construct
=> Lab
);
5689 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5691 Ent
:= Make_Temporary
(Loc
, 'L');
5692 Lab_Id
:= New_Reference_To
(Ent
, Loc
);
5693 Lab
:= Make_Label
(Loc
, Lab_Id
);
5695 Make_Implicit_Label_Declaration
(Loc
,
5696 Defining_Identifier
=> Ent
,
5697 Label_Construct
=> Lab
);
5698 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5706 -- Case of stand alone accept statement
5708 if Is_List_Member
(N
) then
5710 if Present
(Handled_Statement_Sequence
(N
)) then
5711 Ann
:= Make_Temporary
(Loc
, 'A');
5714 Make_Object_Declaration
(Loc
,
5715 Defining_Identifier
=> Ann
,
5716 Object_Definition
=>
5717 New_Reference_To
(RTE
(RE_Address
), Loc
));
5719 Insert_Before
(N
, Adecl
);
5722 Insert_Before
(N
, Ldecl
);
5725 Insert_Before
(N
, Ldecl2
);
5729 -- Case of accept statement which is in an accept alternative
5733 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5734 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5738 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5739 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5741 -- ??? Consider a single label for select statements
5743 if Present
(Handled_Statement_Sequence
(N
)) then
5745 Statements
(Handled_Statement_Sequence
(N
)));
5749 Statements
(Handled_Statement_Sequence
(N
)));
5753 -- Find first accept alternative of the selective accept. A
5754 -- valid selective accept must have at least one accept in it.
5756 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5758 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5762 -- If we are the first accept statement, then we have to create
5763 -- the Ann variable, as for the stand alone case, except that
5764 -- it is inserted before the selective accept. Similarly, a
5765 -- label for requeue expansion must be declared.
5767 if N
= Accept_Statement
(Alt
) then
5768 Ann
:= Make_Temporary
(Loc
, 'A');
5770 Make_Object_Declaration
(Loc
,
5771 Defining_Identifier
=> Ann
,
5772 Object_Definition
=>
5773 New_Reference_To
(RTE
(RE_Address
), Loc
));
5775 Insert_Before
(Sel_Acc
, Adecl
);
5778 -- If we are not the first accept statement, then find the Ann
5779 -- variable allocated by the first accept and use it.
5783 Node
(Last_Elmt
(Accept_Address
5784 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5789 -- Merge here with Ann either created or referenced, and Adecl
5790 -- pointing to the corresponding declaration. Remaining processing
5791 -- is the same for the two cases.
5793 if Present
(Ann
) then
5794 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5795 Set_Debug_Info_Needed
(Ann
);
5798 -- Create renaming declarations for the entry formals. Each reference
5799 -- to a formal becomes a dereference of a component of the parameter
5800 -- block, whose address is held in Ann. These declarations are
5801 -- eventually inserted into the accept block, and analyzed there so
5802 -- that they have the proper scope for gdb and do not conflict with
5803 -- other declarations.
5805 if Present
(Parameter_Specifications
(N
))
5806 and then Present
(Handled_Statement_Sequence
(N
))
5813 Renamed_Formal
: Node_Id
;
5817 Formal
:= First_Formal
(Ent
);
5819 while Present
(Formal
) loop
5820 Comp
:= Entry_Component
(Formal
);
5822 Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5824 Set_Etype
(New_F
, Etype
(Formal
));
5825 Set_Scope
(New_F
, Ent
);
5827 -- Now we set debug info needed on New_F even though it does
5828 -- not come from source, so that the debugger will get the
5829 -- right information for these generated names.
5831 Set_Debug_Info_Needed
(New_F
);
5833 if Ekind
(Formal
) = E_In_Parameter
then
5834 Set_Ekind
(New_F
, E_Constant
);
5836 Set_Ekind
(New_F
, E_Variable
);
5837 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5840 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5843 Make_Selected_Component
(Loc
,
5845 Unchecked_Convert_To
(
5846 Entry_Parameters_Type
(Ent
),
5847 New_Reference_To
(Ann
, Loc
)),
5849 New_Reference_To
(Comp
, Loc
));
5852 Build_Renamed_Formal_Declaration
5853 (New_F
, Formal
, Comp
, Renamed_Formal
);
5855 if No
(Declarations
(N
)) then
5856 Set_Declarations
(N
, New_List
);
5859 Append
(Decl
, Declarations
(N
));
5860 Set_Renamed_Object
(Formal
, New_F
);
5861 Next_Formal
(Formal
);
5868 end Expand_Accept_Declarations
;
5870 ---------------------------------------------
5871 -- Expand_Access_Protected_Subprogram_Type --
5872 ---------------------------------------------
5874 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5875 Loc
: constant Source_Ptr
:= Sloc
(N
);
5877 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5878 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5879 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5880 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5881 P_List
: constant List_Id
:= Build_Protected_Spec
5882 (N
, RTE
(RE_Address
), D_T
, False);
5888 -- Create access to subprogram with full signature
5890 if Etype
(D_T
) /= Standard_Void_Type
then
5892 Make_Access_Function_Definition
(Loc
,
5893 Parameter_Specifications
=> P_List
,
5894 Result_Definition
=>
5895 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5899 Make_Access_Procedure_Definition
(Loc
,
5900 Parameter_Specifications
=> P_List
);
5904 Make_Full_Type_Declaration
(Loc
,
5905 Defining_Identifier
=> D_T2
,
5906 Type_Definition
=> Def1
);
5908 Insert_After
(N
, Decl1
);
5911 -- Associate the access to subprogram with its original access to
5912 -- protected subprogram type. Needed by the backend to know that this
5913 -- type corresponds with an access to protected subprogram type.
5915 Set_Original_Access_Type
(D_T2
, T
);
5917 -- Create Equivalent_Type, a record with two components for an access to
5918 -- object and an access to subprogram.
5921 Make_Component_Declaration
(Loc
,
5922 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5923 Component_Definition
=>
5924 Make_Component_Definition
(Loc
,
5925 Aliased_Present
=> False,
5926 Subtype_Indication
=>
5927 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5929 Make_Component_Declaration
(Loc
,
5930 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5931 Component_Definition
=>
5932 Make_Component_Definition
(Loc
,
5933 Aliased_Present
=> False,
5934 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5937 Make_Full_Type_Declaration
(Loc
,
5938 Defining_Identifier
=> E_T
,
5940 Make_Record_Definition
(Loc
,
5942 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
5944 Insert_After
(Decl1
, Decl2
);
5946 Set_Equivalent_Type
(T
, E_T
);
5947 end Expand_Access_Protected_Subprogram_Type
;
5949 --------------------------
5950 -- Expand_Entry_Barrier --
5951 --------------------------
5953 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5954 Cond
: constant Node_Id
:=
5955 Condition
(Entry_Body_Formal_Part
(N
));
5956 Prot
: constant Entity_Id
:= Scope
(Ent
);
5957 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5960 Body_Decl
: Node_Id
;
5963 if No_Run_Time_Mode
then
5964 Error_Msg_CRT
("entry barrier", N
);
5968 -- The body of the entry barrier must be analyzed in the context of the
5969 -- protected object, but its scope is external to it, just as any other
5970 -- unprotected version of a protected operation. The specification has
5971 -- been produced when the protected type declaration was elaborated. We
5972 -- build the body, insert it in the enclosing scope, but analyze it in
5973 -- the current context. A more uniform approach would be to treat the
5974 -- barrier just as a protected function, and discard the protected
5975 -- version of it because it is never called.
5977 if Full_Expander_Active
then
5978 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
5979 Func
:= Barrier_Function
(Ent
);
5980 Set_Corresponding_Spec
(B_F
, Func
);
5982 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
5984 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
5985 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
5988 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
5990 Set_Discriminals
(Spec_Decl
);
5991 Set_Scope
(Func
, Scope
(Prot
));
5994 Analyze_And_Resolve
(Cond
, Any_Boolean
);
5997 -- The Ravenscar profile restricts barriers to simple variables declared
5998 -- within the protected object. We also allow Boolean constants, since
5999 -- these appear in several published examples and are also allowed by
6000 -- the Aonix compiler.
6002 -- Note that after analysis variables in this context will be replaced
6003 -- by the corresponding prival, that is to say a renaming of a selected
6004 -- component of the form _Object.Var. If expansion is disabled, as
6005 -- within a generic, we check that the entity appears in the current
6008 if Is_Entity_Name
(Cond
) then
6010 -- A small optimization of useless renamings. If the scope of the
6011 -- entity of the condition is not the barrier function, then the
6012 -- condition does not reference any of the generated renamings
6013 -- within the function.
6015 if Full_Expander_Active
6016 and then Scope
(Entity
(Cond
)) /= Func
6018 Set_Declarations
(B_F
, Empty_List
);
6021 if Entity
(Cond
) = Standard_False
6023 Entity
(Cond
) = Standard_True
6027 elsif not Expander_Active
6028 and then Scope
(Entity
(Cond
)) = Current_Scope
6032 -- Check for case of _object.all.field (note that the explicit
6033 -- dereference gets inserted by analyze/expand of _object.field)
6035 elsif Present
(Renamed_Object
(Entity
(Cond
)))
6037 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
6041 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
6047 -- It is not a boolean variable or literal, so check the restriction
6049 Check_Restriction
(Simple_Barriers
, Cond
);
6050 end Expand_Entry_Barrier
;
6052 ------------------------------
6053 -- Expand_N_Abort_Statement --
6054 ------------------------------
6056 -- Expand abort T1, T2, .. Tn; into:
6057 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6059 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6060 Loc
: constant Source_Ptr
:= Sloc
(N
);
6061 Tlist
: constant List_Id
:= Names
(N
);
6067 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6070 Tasknm
:= First
(Tlist
);
6072 while Present
(Tasknm
) loop
6075 -- A task interface class-wide type object is being aborted.
6076 -- Retrieve its _task_id by calling a dispatching routine.
6078 if Ada_Version
>= Ada_2005
6079 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6080 and then Is_Interface
(Etype
(Tasknm
))
6081 and then Is_Task_Interface
(Etype
(Tasknm
))
6083 Append_To
(Component_Associations
(Aggr
),
6084 Make_Component_Association
(Loc
,
6085 Choices
=> New_List
(
6086 Make_Integer_Literal
(Loc
, Count
)),
6089 -- Task_Id (Tasknm._disp_get_task_id)
6091 Make_Unchecked_Type_Conversion
(Loc
,
6093 New_Reference_To
(RTE
(RO_ST_Task_Id
), Loc
),
6095 Make_Selected_Component
(Loc
,
6096 Prefix
=> New_Copy_Tree
(Tasknm
),
6098 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6101 Append_To
(Component_Associations
(Aggr
),
6102 Make_Component_Association
(Loc
,
6103 Choices
=> New_List
(
6104 Make_Integer_Literal
(Loc
, Count
)),
6105 Expression
=> Concurrent_Ref
(Tasknm
)));
6112 Make_Procedure_Call_Statement
(Loc
,
6113 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
6114 Parameter_Associations
=> New_List
(
6115 Make_Qualified_Expression
(Loc
,
6116 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
6117 Expression
=> Aggr
))));
6120 end Expand_N_Abort_Statement
;
6122 -------------------------------
6123 -- Expand_N_Accept_Statement --
6124 -------------------------------
6126 -- This procedure handles expansion of accept statements that stand
6127 -- alone, i.e. they are not part of an accept alternative. The expansion
6128 -- of accept statement in accept alternatives is handled by the routines
6129 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6130 -- following description applies only to stand alone accept statements.
6132 -- If there is no handled statement sequence, or only null statements,
6133 -- then this is called a trivial accept, and the expansion is:
6135 -- Accept_Trivial (entry-index)
6137 -- If there is a handled statement sequence, then the expansion is:
6144 -- Accept_Call (entry-index, Ann);
6145 -- Renaming_Declarations for formals
6146 -- <statement sequence from N_Accept_Statement node>
6147 -- Complete_Rendezvous;
6152 -- <exception handler from N_Accept_Statement node>
6153 -- Complete_Rendezvous;
6155 -- <exception handler from N_Accept_Statement node>
6156 -- Complete_Rendezvous;
6161 -- when all others =>
6162 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6165 -- The first three declarations were already inserted ahead of the accept
6166 -- statement by the Expand_Accept_Declarations procedure, which was called
6167 -- directly from the semantics during analysis of the accept statement,
6168 -- before analyzing its contained statements.
6170 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6171 -- from possible expansion activity (the original source of course does
6172 -- not have any declarations associated with the accept statement, since
6173 -- an accept statement has no declarative part). In particular, if the
6174 -- expander is active, the first such declaration is the declaration of
6175 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6177 -- The two blocks are merged into a single block if the inner block has
6178 -- no exception handlers, but otherwise two blocks are required, since
6179 -- exceptions might be raised in the exception handlers of the inner
6180 -- block, and Exceptional_Complete_Rendezvous must be called.
6182 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6183 Loc
: constant Source_Ptr
:= Sloc
(N
);
6184 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6185 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6186 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6187 Eent
: constant Entity_Id
:= Entity
(Ename
);
6188 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6189 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6190 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6195 -- Start of processing for Expand_N_Accept_Statement
6198 -- If accept statement is not part of a list, then its parent must be
6199 -- an accept alternative, and, as described above, we do not do any
6200 -- expansion for such accept statements at this level.
6202 if not Is_List_Member
(N
) then
6203 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6206 -- Trivial accept case (no statement sequence, or null statements).
6207 -- If the accept statement has declarations, then just insert them
6208 -- before the procedure call.
6210 elsif Trivial_Accept_OK
6211 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6213 -- Remove declarations for renamings, because the parameter block
6214 -- will not be assigned.
6221 D
:= First
(Declarations
(N
));
6223 while Present
(D
) loop
6225 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6233 if Present
(Declarations
(N
)) then
6234 Insert_Actions
(N
, Declarations
(N
));
6238 Make_Procedure_Call_Statement
(Loc
,
6239 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
6240 Parameter_Associations
=> New_List
(
6241 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6245 -- Discard Entry_Address that was created for it, so it will not be
6246 -- emitted if this accept statement is in the statement part of a
6247 -- delay alternative.
6249 if Present
(Stats
) then
6250 Remove_Last_Elmt
(Acstack
);
6253 -- Case of statement sequence present
6256 -- Construct the block, using the declarations from the accept
6257 -- statement if any to initialize the declarations of the block.
6259 Blkent
:= Make_Temporary
(Loc
, 'A');
6260 Set_Ekind
(Blkent
, E_Block
);
6261 Set_Etype
(Blkent
, Standard_Void_Type
);
6262 Set_Scope
(Blkent
, Current_Scope
);
6265 Make_Block_Statement
(Loc
,
6266 Identifier
=> New_Reference_To
(Blkent
, Loc
),
6267 Declarations
=> Declarations
(N
),
6268 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6270 -- For the analysis of the generated declarations, the parent node
6271 -- must be properly set.
6273 Set_Parent
(Block
, Parent
(N
));
6275 -- Prepend call to Accept_Call to main statement sequence If the
6276 -- accept has exception handlers, the statement sequence is wrapped
6277 -- in a block. Insert call and renaming declarations in the
6278 -- declarations of the block, so they are elaborated before the
6282 Make_Procedure_Call_Statement
(Loc
,
6283 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
6284 Parameter_Associations
=> New_List
(
6285 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6286 New_Reference_To
(Ann
, Loc
)));
6288 if Parent
(Stats
) = N
then
6289 Prepend
(Call
, Statements
(Stats
));
6298 Push_Scope
(Blkent
);
6306 D
:= First
(Declarations
(N
));
6307 while Present
(D
) loop
6310 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6312 -- The renaming declarations for the formals were created
6313 -- during analysis of the accept statement, and attached to
6314 -- the list of declarations. Place them now in the context
6315 -- of the accept block or subprogram.
6318 Typ
:= Entity
(Subtype_Mark
(D
));
6319 Insert_After
(Call
, D
);
6322 -- If the formal is class_wide, it does not have an actual
6323 -- subtype. The analysis of the renaming declaration creates
6324 -- one, but we need to retain the class-wide nature of the
6327 if Is_Class_Wide_Type
(Typ
) then
6328 Set_Etype
(Defining_Identifier
(D
), Typ
);
6339 -- Replace the accept statement by the new block
6344 -- Last step is to unstack the Accept_Address value
6346 Remove_Last_Elmt
(Acstack
);
6348 end Expand_N_Accept_Statement
;
6350 ----------------------------------
6351 -- Expand_N_Asynchronous_Select --
6352 ----------------------------------
6354 -- This procedure assumes that the trigger statement is an entry call or
6355 -- a dispatching procedure call. A delay alternative should already have
6356 -- been expanded into an entry call to the appropriate delay object Wait
6359 -- If the trigger is a task entry call, the select is implemented with
6360 -- a Task_Entry_Call:
6365 -- P : parms := (parm, parm, parm);
6367 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6369 -- procedure _clean is
6372 -- Cancel_Task_Entry_Call (C);
6379 -- (<acceptor-task>, -- Acceptor
6380 -- <entry-index>, -- E
6381 -- P'Address, -- Uninterpreted_Data
6382 -- Asynchronous_Call, -- Mode
6383 -- B); -- Rendezvous_Successful
6390 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6393 -- when Abort_Signal => Abort_Undefer;
6400 -- <triggered-statements>
6404 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6405 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6409 -- P : parms := (parm, parm, parm);
6411 -- Call_Simple (acceptor-task, entry-index, P'Address);
6417 -- so the task at hand is to convert the latter expansion into the former
6419 -- If the trigger is a protected entry call, the select is implemented
6420 -- with Protected_Entry_Call:
6423 -- P : E1_Params := (param, param, param);
6424 -- Bnn : Communications_Block;
6429 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6431 -- procedure _clean is
6434 -- if Enqueued (Bnn) then
6435 -- Cancel_Protected_Entry_Call (Bnn);
6442 -- Protected_Entry_Call
6443 -- (po._object'Access, -- Object
6444 -- <entry index>, -- E
6445 -- P'Address, -- Uninterpreted_Data
6446 -- Asynchronous_Call, -- Mode
6449 -- if Enqueued (Bnn) then
6453 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6456 -- when Abort_Signal => Abort_Undefer;
6459 -- if not Cancelled (Bnn) then
6460 -- <triggered-statements>
6464 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6468 -- P : E1_Params := (param, param, param);
6469 -- Bnn : Communications_Block;
6472 -- Protected_Entry_Call
6473 -- (po._object'Access, -- Object
6474 -- <entry index>, -- E
6475 -- P'Address, -- Uninterpreted_Data
6476 -- Simple_Call, -- Mode
6483 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6487 -- B : Boolean := False;
6488 -- Bnn : Communication_Block;
6489 -- C : Ada.Tags.Prim_Op_Kind;
6490 -- D : System.Storage_Elements.Dummy_Communication_Block;
6491 -- K : Ada.Tags.Tagged_Kind :=
6492 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6493 -- P : Parameters := (Param1 .. ParamN);
6498 -- if K = Ada.Tags.TK_Limited_Tagged then
6499 -- <dispatching-call>;
6500 -- <triggering-statements>;
6504 -- Ada.Tags.Get_Offset_Index
6505 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6507 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6509 -- if C = POK_Protected_Entry then
6511 -- procedure _clean is
6513 -- if Enqueued (Bnn) then
6514 -- Cancel_Protected_Entry_Call (Bnn);
6520 -- _Disp_Asynchronous_Select
6521 -- (<object>, S, P'Address, D, B);
6522 -- Bnn := Communication_Block (D);
6524 -- Param1 := P.Param1;
6526 -- ParamN := P.ParamN;
6528 -- if Enqueued (Bnn) then
6529 -- <abortable-statements>
6532 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6535 -- when Abort_Signal => Abort_Undefer;
6538 -- if not Cancelled (Bnn) then
6539 -- <triggering-statements>
6542 -- elsif C = POK_Task_Entry then
6544 -- procedure _clean is
6546 -- Cancel_Task_Entry_Call (U);
6552 -- _Disp_Asynchronous_Select
6553 -- (<object>, S, P'Address, D, B);
6554 -- Bnn := Communication_Bloc (D);
6556 -- Param1 := P.Param1;
6558 -- ParamN := P.ParamN;
6563 -- <abortable-statements>
6565 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6568 -- when Abort_Signal => Abort_Undefer;
6572 -- <triggering-statements>
6577 -- <dispatching-call>;
6578 -- <triggering-statements>
6583 -- The job is to convert this to the asynchronous form
6585 -- If the trigger is a delay statement, it will have been expanded into a
6586 -- call to one of the GNARL delay procedures. This routine will convert
6587 -- this into a protected entry call on a delay object and then continue
6588 -- processing as for a protected entry call trigger. This requires
6589 -- declaring a Delay_Block object and adding a pointer to this object to
6590 -- the parameter list of the delay procedure to form the parameter list of
6591 -- the entry call. This object is used by the runtime to queue the delay
6594 -- For a description of the use of P and the assignments after the call,
6595 -- see Expand_N_Entry_Call_Statement.
6597 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6598 Loc
: constant Source_Ptr
:= Sloc
(N
);
6599 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6600 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6602 Abort_Block_Ent
: Entity_Id
;
6603 Abortable_Block
: Node_Id
;
6606 Blk_Ent
: Entity_Id
;
6607 Blk_Typ
: Entity_Id
;
6609 Call_Ent
: Entity_Id
;
6610 Cancel_Param
: Entity_Id
;
6611 Cleanup_Block
: Node_Id
;
6612 Cleanup_Block_Ent
: Entity_Id
;
6613 Cleanup_Stmts
: List_Id
;
6614 Conc_Typ_Stmts
: List_Id
;
6616 Dblock_Ent
: Entity_Id
;
6621 Enqueue_Call
: Node_Id
;
6624 Handler_Stmt
: Node_Id
;
6626 Lim_Typ_Stmts
: List_Id
;
6632 ProtE_Stmts
: List_Id
;
6633 ProtP_Stmts
: List_Id
;
6636 TaskE_Stmts
: List_Id
;
6639 B
: Entity_Id
; -- Call status flag
6640 Bnn
: Entity_Id
; -- Communication block
6641 C
: Entity_Id
; -- Call kind
6642 K
: Entity_Id
; -- Tagged kind
6643 P
: Entity_Id
; -- Parameter block
6644 S
: Entity_Id
; -- Primitive operation slot
6645 T
: Entity_Id
; -- Additional status flag
6648 Process_Statements_For_Controlled_Objects
(Trig
);
6649 Process_Statements_For_Controlled_Objects
(Abrt
);
6651 -- Retrieve Astats and Tstats now because the finalization machinery may
6652 -- wrap them in blocks.
6654 Astats
:= Statements
(Abrt
);
6655 Tstats
:= Statements
(Trig
);
6657 Blk_Ent
:= Make_Temporary
(Loc
, 'A');
6658 Ecall
:= Triggering_Statement
(Trig
);
6660 -- The arguments in the call may require dynamic allocation, and the
6661 -- call statement may have been transformed into a block. The block
6662 -- may contain additional declarations for internal entities, and the
6663 -- original call is found by sequential search.
6665 if Nkind
(Ecall
) = N_Block_Statement
then
6666 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6667 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6668 N_Entry_Call_Statement
)
6674 -- This is either a dispatching call or a delay statement used as a
6675 -- trigger which was expanded into a procedure call.
6677 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6678 if Ada_Version
>= Ada_2005
6680 (No
(Original_Node
(Ecall
))
6681 or else not Nkind_In
(Original_Node
(Ecall
),
6682 N_Delay_Relative_Statement
,
6683 N_Delay_Until_Statement
))
6685 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6690 -- Call status flag processing, generate:
6691 -- B : Boolean := False;
6693 B
:= Build_B
(Loc
, Decls
);
6695 -- Communication block processing, generate:
6696 -- Bnn : Communication_Block;
6698 Bnn
:= Make_Temporary
(Loc
, 'B');
6700 Make_Object_Declaration
(Loc
,
6701 Defining_Identifier
=> Bnn
,
6702 Object_Definition
=>
6703 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
6705 -- Call kind processing, generate:
6706 -- C : Ada.Tags.Prim_Op_Kind;
6708 C
:= Build_C
(Loc
, Decls
);
6710 -- Tagged kind processing, generate:
6711 -- K : Ada.Tags.Tagged_Kind :=
6712 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6714 -- Dummy communication block, generate:
6715 -- D : Dummy_Communication_Block;
6718 Make_Object_Declaration
(Loc
,
6719 Defining_Identifier
=>
6720 Make_Defining_Identifier
(Loc
, Name_uD
),
6721 Object_Definition
=>
6723 RTE
(RE_Dummy_Communication_Block
), Loc
)));
6725 K
:= Build_K
(Loc
, Decls
, Obj
);
6727 -- Parameter block processing
6729 Blk_Typ
:= Build_Parameter_Block
6730 (Loc
, Actuals
, Formals
, Decls
);
6731 P
:= Parameter_Block_Pack
6732 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6734 -- Dispatch table slot processing, generate:
6737 S
:= Build_S
(Loc
, Decls
);
6739 -- Additional status flag processing, generate:
6742 T
:= Make_Temporary
(Loc
, 'T');
6744 Make_Object_Declaration
(Loc
,
6745 Defining_Identifier
=> T
,
6746 Object_Definition
=>
6747 New_Reference_To
(Standard_Boolean
, Loc
)));
6749 ------------------------------
6750 -- Protected entry handling --
6751 ------------------------------
6754 -- Param1 := P.Param1;
6756 -- ParamN := P.ParamN;
6758 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6761 -- Bnn := Communication_Block (D);
6763 Prepend_To
(Cleanup_Stmts
,
6764 Make_Assignment_Statement
(Loc
,
6766 New_Reference_To
(Bnn
, Loc
),
6768 Make_Unchecked_Type_Conversion
(Loc
,
6770 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
6771 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
6774 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6776 Prepend_To
(Cleanup_Stmts
,
6777 Make_Procedure_Call_Statement
(Loc
,
6780 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6781 Name_uDisp_Asynchronous_Select
),
6783 Parameter_Associations
=>
6785 New_Copy_Tree
(Obj
), -- <object>
6786 New_Reference_To
(S
, Loc
), -- S
6787 Make_Attribute_Reference
(Loc
, -- P'Address
6789 New_Reference_To
(P
, Loc
),
6792 Make_Identifier
(Loc
, Name_uD
), -- D
6793 New_Reference_To
(B
, Loc
)))); -- B
6796 -- if Enqueued (Bnn) then
6797 -- <abortable-statements>
6800 Append_To
(Cleanup_Stmts
,
6801 Make_If_Statement
(Loc
,
6803 Make_Function_Call
(Loc
,
6805 New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
6806 Parameter_Associations
=>
6808 New_Reference_To
(Bnn
, Loc
))),
6811 New_Copy_List_Tree
(Astats
)));
6813 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6814 -- will then generate a _clean for the communication block Bnn.
6818 -- procedure _clean is
6820 -- if Enqueued (Bnn) then
6821 -- Cancel_Protected_Entry_Call (Bnn);
6830 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
6832 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
6834 -- Wrap the cleanup block in an exception handling block
6840 -- when Abort_Signal => Abort_Undefer;
6843 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
6846 Make_Implicit_Label_Declaration
(Loc
,
6847 Defining_Identifier
=>
6851 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
6854 -- if not Cancelled (Bnn) then
6855 -- <triggering-statements>
6858 Append_To
(ProtE_Stmts
,
6859 Make_If_Statement
(Loc
,
6863 Make_Function_Call
(Loc
,
6865 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
6866 Parameter_Associations
=>
6868 New_Reference_To
(Bnn
, Loc
)))),
6871 New_Copy_List_Tree
(Tstats
)));
6873 -------------------------
6874 -- Task entry handling --
6875 -------------------------
6878 -- Param1 := P.Param1;
6880 -- ParamN := P.ParamN;
6882 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6885 -- Bnn := Communication_Block (D);
6887 Append_To
(TaskE_Stmts
,
6888 Make_Assignment_Statement
(Loc
,
6890 New_Reference_To
(Bnn
, Loc
),
6892 Make_Unchecked_Type_Conversion
(Loc
,
6894 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
6895 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
6898 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6900 Prepend_To
(TaskE_Stmts
,
6901 Make_Procedure_Call_Statement
(Loc
,
6904 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6905 Name_uDisp_Asynchronous_Select
),
6907 Parameter_Associations
=>
6909 New_Copy_Tree
(Obj
), -- <object>
6910 New_Reference_To
(S
, Loc
), -- S
6911 Make_Attribute_Reference
(Loc
, -- P'Address
6913 New_Reference_To
(P
, Loc
),
6916 Make_Identifier
(Loc
, Name_uD
), -- D
6917 New_Reference_To
(B
, Loc
)))); -- B
6922 Prepend_To
(TaskE_Stmts
,
6923 Make_Procedure_Call_Statement
(Loc
,
6925 New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
6926 Parameter_Associations
=>
6931 -- <abortable-statements>
6933 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
6935 Prepend_To
(Cleanup_Stmts
,
6936 Make_Procedure_Call_Statement
(Loc
,
6938 New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
6939 Parameter_Associations
=>
6942 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6943 -- will generate a _clean for the additional status flag.
6947 -- procedure _clean is
6949 -- Cancel_Task_Entry_Call (U);
6957 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
6959 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
6961 -- Wrap the cleanup block in an exception handling block
6967 -- when Abort_Signal => Abort_Undefer;
6970 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
6972 Append_To
(TaskE_Stmts
,
6973 Make_Implicit_Label_Declaration
(Loc
,
6974 Defining_Identifier
=> Abort_Block_Ent
));
6976 Append_To
(TaskE_Stmts
,
6978 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
6982 -- <triggering-statements>
6985 Append_To
(TaskE_Stmts
,
6986 Make_If_Statement
(Loc
,
6990 New_Reference_To
(T
, Loc
)),
6993 New_Copy_List_Tree
(Tstats
)));
6995 ----------------------------------
6996 -- Protected procedure handling --
6997 ----------------------------------
7000 -- <dispatching-call>;
7001 -- <triggering-statements>
7003 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7004 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7007 -- S := Ada.Tags.Get_Offset_Index
7008 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7011 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7014 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7016 Append_To
(Conc_Typ_Stmts
,
7017 Make_Procedure_Call_Statement
(Loc
,
7020 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7021 Name_uDisp_Get_Prim_Op_Kind
),
7023 Parameter_Associations
=>
7025 New_Copy_Tree
(Obj
),
7026 New_Reference_To
(S
, Loc
),
7027 New_Reference_To
(C
, Loc
))));
7030 -- if C = POK_Procedure_Entry then
7032 -- elsif C = POK_Task_Entry then
7038 Append_To
(Conc_Typ_Stmts
,
7039 Make_If_Statement
(Loc
,
7043 New_Reference_To
(C
, Loc
),
7045 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7052 Make_Elsif_Part
(Loc
,
7056 New_Reference_To
(C
, Loc
),
7058 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
)),
7067 -- <dispatching-call>;
7068 -- <triggering-statements>
7070 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7071 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7074 -- if K = Ada.Tags.TK_Limited_Tagged then
7081 Make_If_Statement
(Loc
,
7085 New_Reference_To
(K
, Loc
),
7087 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
7096 Make_Block_Statement
(Loc
,
7099 Handled_Statement_Sequence
=>
7100 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7105 -- Delay triggering statement processing
7108 -- Add a Delay_Block object to the parameter list of the delay
7109 -- procedure to form the parameter list of the Wait entry call.
7111 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7113 Pdef
:= Entity
(Name
(Ecall
));
7115 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7117 New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
7119 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7121 New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
7123 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7124 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
7127 Append_To
(Parameter_Associations
(Ecall
),
7128 Make_Attribute_Reference
(Loc
,
7129 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7130 Attribute_Name
=> Name_Unchecked_Access
));
7132 -- Create the inner block to protect the abortable part
7134 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7137 Make_Procedure_Call_Statement
(Loc
,
7138 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7141 Make_Block_Statement
(Loc
,
7142 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7143 Handled_Statement_Sequence
=>
7144 Make_Handled_Sequence_Of_Statements
(Loc
,
7145 Statements
=> Astats
),
7146 Has_Created_Identifier
=> True,
7147 Is_Asynchronous_Call_Block
=> True);
7149 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7152 Make_Implicit_If_Statement
(N
,
7153 Condition
=> Make_Function_Call
(Loc
,
7154 Name
=> Enqueue_Call
,
7155 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7157 New_List
(Make_Block_Statement
(Loc
,
7158 Handled_Statement_Sequence
=>
7159 Make_Handled_Sequence_Of_Statements
(Loc
,
7160 Statements
=> New_List
(
7161 Make_Implicit_Label_Declaration
(Loc
,
7162 Defining_Identifier
=> Blk_Ent
,
7163 Label_Construct
=> Abortable_Block
),
7165 Exception_Handlers
=> Hdle
)))));
7167 Stmts
:= New_List
(Ecall
);
7169 -- Construct statement sequence for new block
7172 Make_Implicit_If_Statement
(N
,
7173 Condition
=> Make_Function_Call
(Loc
,
7174 Name
=> New_Reference_To
(
7175 RTE
(RE_Timed_Out
), Loc
),
7176 Parameter_Associations
=> New_List
(
7177 Make_Attribute_Reference
(Loc
,
7178 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7179 Attribute_Name
=> Name_Unchecked_Access
))),
7180 Then_Statements
=> Tstats
));
7182 -- The result is the new block
7184 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7187 Make_Block_Statement
(Loc
,
7188 Declarations
=> New_List
(
7189 Make_Object_Declaration
(Loc
,
7190 Defining_Identifier
=> Dblock_Ent
,
7191 Aliased_Present
=> True,
7192 Object_Definition
=> New_Reference_To
(
7193 RTE
(RE_Delay_Block
), Loc
))),
7195 Handled_Statement_Sequence
=>
7196 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7206 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7207 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7209 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7210 Decls
:= Declarations
(Ecall
);
7212 if Is_Protected_Type
(Etype
(Concval
)) then
7214 -- Get the declarations of the block expanded from the entry call
7216 Decl
:= First
(Decls
);
7217 while Present
(Decl
)
7219 (Nkind
(Decl
) /= N_Object_Declaration
7220 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7221 RE_Communication_Block
))
7226 pragma Assert
(Present
(Decl
));
7227 Cancel_Param
:= Defining_Identifier
(Decl
);
7229 -- Change the mode of the Protected_Entry_Call call
7231 -- Protected_Entry_Call (
7232 -- Object => po._object'Access,
7233 -- E => <entry index>;
7234 -- Uninterpreted_Data => P'Address;
7235 -- Mode => Asynchronous_Call;
7238 Stmt
:= First
(Stmts
);
7240 -- Skip assignments to temporaries created for in-out parameters
7242 -- This makes unwarranted assumptions about the shape of the expanded
7243 -- tree for the call, and should be cleaned up ???
7245 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7251 Param
:= First
(Parameter_Associations
(Call
));
7252 while Present
(Param
)
7253 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7258 pragma Assert
(Present
(Param
));
7259 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7262 -- Append an if statement to execute the abortable part
7265 -- if Enqueued (Bnn) then
7268 Make_Implicit_If_Statement
(N
,
7269 Condition
=> Make_Function_Call
(Loc
,
7270 Name
=> New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
7271 Parameter_Associations
=> New_List
(
7272 New_Reference_To
(Cancel_Param
, Loc
))),
7273 Then_Statements
=> Astats
));
7276 Make_Block_Statement
(Loc
,
7277 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7278 Handled_Statement_Sequence
=>
7279 Make_Handled_Sequence_Of_Statements
(Loc
,
7280 Statements
=> Stmts
),
7281 Has_Created_Identifier
=> True,
7282 Is_Asynchronous_Call_Block
=> True);
7284 -- For the VM call Update_Exception instead of Abort_Undefer.
7285 -- See 4jexcept.ads for an explanation.
7287 if VM_Target
= No_VM
then
7288 if Exception_Mechanism
= Back_End_Exceptions
then
7290 -- Aborts are not deferred at beginning of exception handlers
7293 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7296 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7297 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7298 Parameter_Associations
=> No_List
);
7301 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7302 Name
=> New_Reference_To
(RTE
(RE_Update_Exception
), Loc
),
7303 Parameter_Associations
=> New_List
(
7304 Make_Function_Call
(Loc
,
7305 Name
=> New_Occurrence_Of
7306 (RTE
(RE_Current_Target_Exception
), Loc
))));
7310 Make_Block_Statement
(Loc
,
7311 Handled_Statement_Sequence
=>
7312 Make_Handled_Sequence_Of_Statements
(Loc
,
7313 Statements
=> New_List
(
7314 Make_Implicit_Label_Declaration
(Loc
,
7315 Defining_Identifier
=> Blk_Ent
,
7316 Label_Construct
=> Abortable_Block
),
7321 Exception_Handlers
=> New_List
(
7322 Make_Implicit_Exception_Handler
(Loc
,
7324 -- when Abort_Signal =>
7325 -- Abort_Undefer.all;
7327 Exception_Choices
=>
7328 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
7329 Statements
=> New_List
(Handler_Stmt
))))),
7331 -- if not Cancelled (Bnn) then
7332 -- triggered statements
7335 Make_Implicit_If_Statement
(N
,
7336 Condition
=> Make_Op_Not
(Loc
,
7338 Make_Function_Call
(Loc
,
7339 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7340 Parameter_Associations
=> New_List
(
7341 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7342 Then_Statements
=> Tstats
));
7344 -- Asynchronous task entry call
7351 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7353 -- Insert declaration of B in declarations of existing block
7356 Make_Object_Declaration
(Loc
,
7357 Defining_Identifier
=> B
,
7358 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7360 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7362 -- Insert declaration of C in declarations of existing block
7365 Make_Object_Declaration
(Loc
,
7366 Defining_Identifier
=> Cancel_Param
,
7367 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7369 -- Remove and save the call to Call_Simple
7371 Stmt
:= First
(Stmts
);
7373 -- Skip assignments to temporaries created for in-out parameters.
7374 -- This makes unwarranted assumptions about the shape of the expanded
7375 -- tree for the call, and should be cleaned up ???
7377 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7383 -- Create the inner block to protect the abortable part
7385 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7388 Make_Procedure_Call_Statement
(Loc
,
7389 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7392 Make_Block_Statement
(Loc
,
7393 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7394 Handled_Statement_Sequence
=>
7395 Make_Handled_Sequence_Of_Statements
(Loc
,
7396 Statements
=> Astats
),
7397 Has_Created_Identifier
=> True,
7398 Is_Asynchronous_Call_Block
=> True);
7401 Make_Block_Statement
(Loc
,
7402 Handled_Statement_Sequence
=>
7403 Make_Handled_Sequence_Of_Statements
(Loc
,
7404 Statements
=> New_List
(
7405 Make_Implicit_Label_Declaration
(Loc
,
7406 Defining_Identifier
=>
7411 Exception_Handlers
=> Hdle
)));
7413 -- Create new call statement
7415 Params
:= Parameter_Associations
(Call
);
7418 New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7420 New_Reference_To
(B
, Loc
));
7423 Make_Procedure_Call_Statement
(Loc
,
7425 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7426 Parameter_Associations
=> Params
));
7428 -- Construct statement sequence for new block
7431 Make_Implicit_If_Statement
(N
,
7434 New_Reference_To
(Cancel_Param
, Loc
)),
7435 Then_Statements
=> Tstats
));
7437 -- Protected the call against abort
7440 Make_Procedure_Call_Statement
(Loc
,
7441 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7442 Parameter_Associations
=> Empty_List
));
7445 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7447 -- The result is the new block
7450 Make_Block_Statement
(Loc
,
7451 Declarations
=> Decls
,
7452 Handled_Statement_Sequence
=>
7453 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7456 end Expand_N_Asynchronous_Select
;
7458 -------------------------------------
7459 -- Expand_N_Conditional_Entry_Call --
7460 -------------------------------------
7462 -- The conditional task entry call is converted to a call to
7467 -- P : parms := (parm, parm, parm);
7471 -- (<acceptor-task>, -- Acceptor
7472 -- <entry-index>, -- E
7473 -- P'Address, -- Uninterpreted_Data
7474 -- Conditional_Call, -- Mode
7475 -- B); -- Rendezvous_Successful
7480 -- normal-statements
7486 -- For a description of the use of P and the assignments after the call,
7487 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7488 -- conditional entry call has already been expanded (by the Expand_N_Entry
7489 -- _Call_Statement procedure) as follows:
7492 -- P : parms := (parm, parm, parm);
7494 -- ... info for in-out parameters
7495 -- Call_Simple (acceptor-task, entry-index, P'Address);
7501 -- so the task at hand is to convert the latter expansion into the former
7503 -- The conditional protected entry call is converted to a call to
7504 -- Protected_Entry_Call:
7507 -- P : parms := (parm, parm, parm);
7508 -- Bnn : Communications_Block;
7511 -- Protected_Entry_Call
7512 -- (po._object'Access, -- Object
7513 -- <entry index>, -- E
7514 -- P'Address, -- Uninterpreted_Data
7515 -- Conditional_Call, -- Mode
7520 -- if Cancelled (Bnn) then
7523 -- normal-statements
7527 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7531 -- B : Boolean := False;
7532 -- C : Ada.Tags.Prim_Op_Kind;
7533 -- K : Ada.Tags.Tagged_Kind :=
7534 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7535 -- P : Parameters := (Param1 .. ParamN);
7539 -- if K = Ada.Tags.TK_Limited_Tagged then
7540 -- <dispatching-call>;
7541 -- <triggering-statements>
7545 -- Ada.Tags.Get_Offset_Index
7546 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7548 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7550 -- if C = POK_Protected_Entry
7551 -- or else C = POK_Task_Entry
7553 -- Param1 := P.Param1;
7555 -- ParamN := P.ParamN;
7559 -- if C = POK_Procedure
7560 -- or else C = POK_Protected_Procedure
7561 -- or else C = POK_Task_Procedure
7563 -- <dispatching-call>;
7566 -- <triggering-statements>
7568 -- <else-statements>
7573 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7574 Loc
: constant Source_Ptr
:= Sloc
(N
);
7575 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7576 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7579 Blk_Typ
: Entity_Id
;
7581 Call_Ent
: Entity_Id
;
7582 Conc_Typ_Stmts
: List_Id
;
7586 Lim_Typ_Stmts
: List_Id
;
7593 Transient_Blk
: Node_Id
;
7596 B
: Entity_Id
; -- Call status flag
7597 C
: Entity_Id
; -- Call kind
7598 K
: Entity_Id
; -- Tagged kind
7599 P
: Entity_Id
; -- Parameter block
7600 S
: Entity_Id
; -- Primitive operation slot
7603 Process_Statements_For_Controlled_Objects
(N
);
7605 if Ada_Version
>= Ada_2005
7606 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7608 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7613 -- Call status flag processing, generate:
7614 -- B : Boolean := False;
7616 B
:= Build_B
(Loc
, Decls
);
7618 -- Call kind processing, generate:
7619 -- C : Ada.Tags.Prim_Op_Kind;
7621 C
:= Build_C
(Loc
, Decls
);
7623 -- Tagged kind processing, generate:
7624 -- K : Ada.Tags.Tagged_Kind :=
7625 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7627 K
:= Build_K
(Loc
, Decls
, Obj
);
7629 -- Parameter block processing
7631 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7632 P
:= Parameter_Block_Pack
7633 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7635 -- Dispatch table slot processing, generate:
7638 S
:= Build_S
(Loc
, Decls
);
7641 -- S := Ada.Tags.Get_Offset_Index
7642 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7645 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7648 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7650 Append_To
(Conc_Typ_Stmts
,
7651 Make_Procedure_Call_Statement
(Loc
,
7654 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7655 Name_uDisp_Conditional_Select
),
7657 Parameter_Associations
=>
7659 New_Copy_Tree
(Obj
), -- <object>
7660 New_Reference_To
(S
, Loc
), -- S
7661 Make_Attribute_Reference
(Loc
, -- P'Address
7663 New_Reference_To
(P
, Loc
),
7666 New_Reference_To
(C
, Loc
), -- C
7667 New_Reference_To
(B
, Loc
)))); -- B
7670 -- if C = POK_Protected_Entry
7671 -- or else C = POK_Task_Entry
7673 -- Param1 := P.Param1;
7675 -- ParamN := P.ParamN;
7678 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7680 -- Generate the if statement only when the packed parameters need
7681 -- explicit assignments to their corresponding actuals.
7683 if Present
(Unpack
) then
7684 Append_To
(Conc_Typ_Stmts
,
7685 Make_If_Statement
(Loc
,
7692 New_Reference_To
(C
, Loc
),
7694 New_Reference_To
(RTE
(
7695 RE_POK_Protected_Entry
), Loc
)),
7699 New_Reference_To
(C
, Loc
),
7701 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
7709 -- if C = POK_Procedure
7710 -- or else C = POK_Protected_Procedure
7711 -- or else C = POK_Task_Procedure
7713 -- <dispatching-call>
7715 -- <normal-statements>
7717 -- <else-statements>
7720 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7722 Prepend_To
(N_Stats
,
7723 Make_If_Statement
(Loc
,
7729 New_Reference_To
(C
, Loc
),
7731 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
7738 New_Reference_To
(C
, Loc
),
7740 New_Reference_To
(RTE
(
7741 RE_POK_Protected_Procedure
), Loc
)),
7746 New_Reference_To
(C
, Loc
),
7748 New_Reference_To
(RTE
(
7749 RE_POK_Task_Procedure
), Loc
)))),
7754 Append_To
(Conc_Typ_Stmts
,
7755 Make_If_Statement
(Loc
,
7756 Condition
=> New_Reference_To
(B
, Loc
),
7757 Then_Statements
=> N_Stats
,
7758 Else_Statements
=> Else_Statements
(N
)));
7761 -- <dispatching-call>;
7762 -- <triggering-statements>
7764 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
7765 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
7768 -- if K = Ada.Tags.TK_Limited_Tagged then
7775 Make_If_Statement
(Loc
,
7779 New_Reference_To
(K
, Loc
),
7781 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
7790 Make_Block_Statement
(Loc
,
7793 Handled_Statement_Sequence
=>
7794 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7796 -- As described above, The entry alternative is transformed into a
7797 -- block that contains the gnulli call, and possibly assignment
7798 -- statements for in-out parameters. The gnulli call may itself be
7799 -- rewritten into a transient block if some unconstrained parameters
7800 -- require it. We need to retrieve the call to complete its parameter
7805 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
7807 if Present
(Transient_Blk
)
7808 and then Nkind
(Transient_Blk
) = N_Block_Statement
7810 Blk
:= Transient_Blk
;
7813 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
7814 Stmt
:= First
(Stmts
);
7815 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7820 Params
:= Parameter_Associations
(Call
);
7822 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
7824 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7826 Param
:= First
(Params
);
7827 while Present
(Param
)
7828 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7833 pragma Assert
(Present
(Param
));
7834 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7838 -- Find the Communication_Block parameter for the call to the
7839 -- Cancelled function.
7841 Decl
:= First
(Declarations
(Blk
));
7842 while Present
(Decl
)
7843 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7844 RE_Communication_Block
)
7849 -- Add an if statement to execute the else part if the call
7850 -- does not succeed (as indicated by the Cancelled predicate).
7853 Make_Implicit_If_Statement
(N
,
7854 Condition
=> Make_Function_Call
(Loc
,
7855 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
7856 Parameter_Associations
=> New_List
(
7857 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
7858 Then_Statements
=> Else_Statements
(N
),
7859 Else_Statements
=> Statements
(Alt
)));
7862 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7864 -- Insert declaration of B in declarations of existing block
7866 if No
(Declarations
(Blk
)) then
7867 Set_Declarations
(Blk
, New_List
);
7870 Prepend_To
(Declarations
(Blk
),
7871 Make_Object_Declaration
(Loc
,
7872 Defining_Identifier
=> B
,
7873 Object_Definition
=>
7874 New_Reference_To
(Standard_Boolean
, Loc
)));
7876 -- Create new call statement
7879 New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7880 Append_To
(Params
, New_Reference_To
(B
, Loc
));
7883 Make_Procedure_Call_Statement
(Loc
,
7884 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7885 Parameter_Associations
=> Params
));
7887 -- Construct statement sequence for new block
7890 Make_Implicit_If_Statement
(N
,
7891 Condition
=> New_Reference_To
(B
, Loc
),
7892 Then_Statements
=> Statements
(Alt
),
7893 Else_Statements
=> Else_Statements
(N
)));
7896 -- The result is the new block
7899 Make_Block_Statement
(Loc
,
7900 Declarations
=> Declarations
(Blk
),
7901 Handled_Statement_Sequence
=>
7902 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7906 end Expand_N_Conditional_Entry_Call
;
7908 ---------------------------------------
7909 -- Expand_N_Delay_Relative_Statement --
7910 ---------------------------------------
7912 -- Delay statement is implemented as a procedure call to Delay_For
7913 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7914 -- simple delays imposed by the use of Protected Objects.
7916 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
7917 Loc
: constant Source_Ptr
:= Sloc
(N
);
7920 Make_Procedure_Call_Statement
(Loc
,
7921 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
7922 Parameter_Associations
=> New_List
(Expression
(N
))));
7924 end Expand_N_Delay_Relative_Statement
;
7926 ------------------------------------
7927 -- Expand_N_Delay_Until_Statement --
7928 ------------------------------------
7930 -- Delay Until statement is implemented as a procedure call to
7931 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7933 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
7934 Loc
: constant Source_Ptr
:= Sloc
(N
);
7938 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
7939 Typ
:= RTE
(RO_CA_Delay_Until
);
7941 Typ
:= RTE
(RO_RT_Delay_Until
);
7945 Make_Procedure_Call_Statement
(Loc
,
7946 Name
=> New_Reference_To
(Typ
, Loc
),
7947 Parameter_Associations
=> New_List
(Expression
(N
))));
7950 end Expand_N_Delay_Until_Statement
;
7952 -------------------------
7953 -- Expand_N_Entry_Body --
7954 -------------------------
7956 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
7958 -- Associate discriminals with the next protected operation body to be
7961 if Present
(Next_Protected_Operation
(N
)) then
7962 Set_Discriminals
(Parent
(Current_Scope
));
7964 end Expand_N_Entry_Body
;
7966 -----------------------------------
7967 -- Expand_N_Entry_Call_Statement --
7968 -----------------------------------
7970 -- An entry call is expanded into GNARLI calls to implement a simple entry
7971 -- call (see Build_Simple_Entry_Call).
7973 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
7979 if No_Run_Time_Mode
then
7980 Error_Msg_CRT
("entry call", N
);
7984 -- If this entry call is part of an asynchronous select, don't expand it
7985 -- here; it will be expanded with the select statement. Don't expand
7986 -- timed entry calls either, as they are translated into asynchronous
7989 -- ??? This whole approach is questionable; it may be better to go back
7990 -- to allowing the expansion to take place and then attempting to fix it
7991 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7992 -- whether the expanded call is on a task or protected entry.
7994 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
7995 or else N
/= Triggering_Statement
(Parent
(N
)))
7996 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
7997 or else N
/= Entry_Call_Statement
(Parent
(N
))
7998 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8000 Extract_Entry
(N
, Concval
, Ename
, Index
);
8001 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8003 end Expand_N_Entry_Call_Statement
;
8005 --------------------------------
8006 -- Expand_N_Entry_Declaration --
8007 --------------------------------
8009 -- If there are parameters, then first, each of the formals is marked by
8010 -- setting Is_Entry_Formal. Next a record type is built which is used to
8011 -- hold the parameter values. The name of this record type is entryP where
8012 -- entry is the name of the entry, with an additional corresponding access
8013 -- type called entryPA. The record type has matching components for each
8014 -- formal (the component names are the same as the formal names). For
8015 -- elementary types, the component type matches the formal type. For
8016 -- composite types, an access type is declared (with the name formalA)
8017 -- which designates the formal type, and the type of the component is this
8018 -- access type. Finally the Entry_Component of each formal is set to
8019 -- reference the corresponding record component.
8021 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8022 Loc
: constant Source_Ptr
:= Sloc
(N
);
8023 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8024 Components
: List_Id
;
8027 Last_Decl
: Node_Id
;
8028 Component
: Entity_Id
;
8031 Rec_Ent
: Entity_Id
;
8032 Acc_Ent
: Entity_Id
;
8035 Formal
:= First_Formal
(Entry_Ent
);
8038 -- Most processing is done only if parameters are present
8040 if Present
(Formal
) then
8041 Components
:= New_List
;
8043 -- Loop through formals
8045 while Present
(Formal
) loop
8046 Set_Is_Entry_Formal
(Formal
);
8048 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8049 Set_Entry_Component
(Formal
, Component
);
8050 Set_Entry_Formal
(Component
, Formal
);
8051 Ftype
:= Etype
(Formal
);
8053 -- Declare new access type and then append
8055 Ctype
:= Make_Temporary
(Loc
, 'A');
8058 Make_Full_Type_Declaration
(Loc
,
8059 Defining_Identifier
=> Ctype
,
8061 Make_Access_To_Object_Definition
(Loc
,
8062 All_Present
=> True,
8063 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8064 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
8066 Insert_After
(Last_Decl
, Decl
);
8069 Append_To
(Components
,
8070 Make_Component_Declaration
(Loc
,
8071 Defining_Identifier
=> Component
,
8072 Component_Definition
=>
8073 Make_Component_Definition
(Loc
,
8074 Aliased_Present
=> False,
8075 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
8077 Next_Formal_With_Extras
(Formal
);
8080 -- Create the Entry_Parameter_Record declaration
8082 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8085 Make_Full_Type_Declaration
(Loc
,
8086 Defining_Identifier
=> Rec_Ent
,
8088 Make_Record_Definition
(Loc
,
8090 Make_Component_List
(Loc
,
8091 Component_Items
=> Components
)));
8093 Insert_After
(Last_Decl
, Decl
);
8096 -- Construct and link in the corresponding access type
8098 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8100 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8103 Make_Full_Type_Declaration
(Loc
,
8104 Defining_Identifier
=> Acc_Ent
,
8106 Make_Access_To_Object_Definition
(Loc
,
8107 All_Present
=> True,
8108 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
8110 Insert_After
(Last_Decl
, Decl
);
8112 end Expand_N_Entry_Declaration
;
8114 -----------------------------
8115 -- Expand_N_Protected_Body --
8116 -----------------------------
8118 -- Protected bodies are expanded to the completion of the subprograms
8119 -- created for the corresponding protected type. These are a protected and
8120 -- unprotected version of each protected subprogram in the object, a
8121 -- function to calculate each entry barrier, and a procedure to execute the
8122 -- sequence of statements of each protected entry body. For example, for
8123 -- protected type ptype:
8126 -- (O : System.Address;
8127 -- E : Protected_Entry_Index)
8130 -- <discriminant renamings>
8131 -- <private object renamings>
8133 -- return <barrier expression>;
8136 -- procedure pprocN (_object : in out poV;...) is
8137 -- <discriminant renamings>
8138 -- <private object renamings>
8140 -- <sequence of statements>
8143 -- procedure pprocP (_object : in out poV;...) is
8144 -- procedure _clean is
8147 -- ptypeS (_object, Pn);
8148 -- Unlock (_object._object'Access);
8149 -- Abort_Undefer.all;
8154 -- Lock (_object._object'Access);
8155 -- pprocN (_object;...);
8160 -- function pfuncN (_object : poV;...) return Return_Type is
8161 -- <discriminant renamings>
8162 -- <private object renamings>
8164 -- <sequence of statements>
8167 -- function pfuncP (_object : poV) return Return_Type is
8168 -- procedure _clean is
8170 -- Unlock (_object._object'Access);
8171 -- Abort_Undefer.all;
8176 -- Lock (_object._object'Access);
8177 -- return pfuncN (_object);
8184 -- (O : System.Address;
8185 -- P : System.Address;
8186 -- E : Protected_Entry_Index)
8188 -- <discriminant renamings>
8189 -- <private object renamings>
8190 -- type poVP is access poV;
8191 -- _Object : ptVP := ptVP!(O);
8195 -- <statement sequence>
8196 -- Complete_Entry_Body (_Object._Object);
8198 -- when all others =>
8199 -- Exceptional_Complete_Entry_Body (
8200 -- _Object._Object, Get_GNAT_Exception);
8204 -- The type poV is the record created for the protected type to hold
8205 -- the state of the protected object.
8207 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8208 Loc
: constant Source_Ptr
:= Sloc
(N
);
8209 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8211 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8212 -- This flag indicates whether the lock free implementation is active
8214 Current_Node
: Node_Id
;
8215 Disp_Op_Body
: Node_Id
;
8216 New_Op_Body
: Node_Id
;
8217 Num_Entries
: Natural := 0;
8221 function Build_Dispatching_Subprogram_Body
8224 Prot_Bod
: Node_Id
) return Node_Id
;
8225 -- Build a dispatching version of the protected subprogram body. The
8226 -- newly generated subprogram contains a call to the original protected
8227 -- body. The following code is generated:
8229 -- function <protected-function-name> (Param1 .. ParamN) return
8232 -- return <protected-function-name>P (Param1 .. ParamN);
8233 -- end <protected-function-name>;
8237 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8239 -- <protected-procedure-name>P (Param1 .. ParamN);
8240 -- end <protected-procedure-name>
8242 ---------------------------------------
8243 -- Build_Dispatching_Subprogram_Body --
8244 ---------------------------------------
8246 function Build_Dispatching_Subprogram_Body
8249 Prot_Bod
: Node_Id
) return Node_Id
8251 Loc
: constant Source_Ptr
:= Sloc
(N
);
8258 -- Generate a specification without a letter suffix in order to
8259 -- override an interface function or procedure.
8261 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8263 -- The formal parameters become the actuals of the protected function
8264 -- or procedure call.
8266 Actuals
:= New_List
;
8267 Formal
:= First
(Parameter_Specifications
(Spec
));
8268 while Present
(Formal
) loop
8270 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8274 if Nkind
(Spec
) = N_Procedure_Specification
then
8277 Make_Procedure_Call_Statement
(Loc
,
8279 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8280 Parameter_Associations
=> Actuals
));
8283 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8287 Make_Simple_Return_Statement
(Loc
,
8289 Make_Function_Call
(Loc
,
8291 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8292 Parameter_Associations
=> Actuals
)));
8296 Make_Subprogram_Body
(Loc
,
8297 Declarations
=> Empty_List
,
8298 Specification
=> Spec
,
8299 Handled_Statement_Sequence
=>
8300 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8301 end Build_Dispatching_Subprogram_Body
;
8303 -- Start of processing for Expand_N_Protected_Body
8306 if No_Run_Time_Mode
then
8307 Error_Msg_CRT
("protected body", N
);
8311 -- This is the proper body corresponding to a stub. The declarations
8312 -- must be inserted at the point of the stub, which in turn is in the
8313 -- declarative part of the parent unit.
8315 if Nkind
(Parent
(N
)) = N_Subunit
then
8316 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8321 Op_Body
:= First
(Declarations
(N
));
8323 -- The protected body is replaced with the bodies of its
8324 -- protected operations, and the declarations for internal objects
8325 -- that may have been created for entry family bounds.
8327 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8330 while Present
(Op_Body
) loop
8331 case Nkind
(Op_Body
) is
8332 when N_Subprogram_Declaration
=>
8335 when N_Subprogram_Body
=>
8337 -- Do not create bodies for eliminated operations
8339 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8340 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8342 if Lock_Free_Active
then
8344 Build_Lock_Free_Unprotected_Subprogram_Body
8348 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8351 Insert_After
(Current_Node
, New_Op_Body
);
8352 Current_Node
:= New_Op_Body
;
8353 Analyze
(New_Op_Body
);
8355 -- Build the corresponding protected operation. It may
8356 -- appear that this is needed only if this is a visible
8357 -- operation of the type, or if it is an interrupt handler,
8358 -- and this was the strategy used previously in GNAT.
8360 -- However, the operation may be exported through a 'Access
8361 -- to an external caller. This is the common idiom in code
8362 -- that uses the Ada 2005 Timing_Events package. As a result
8363 -- we need to produce the protected body for both visible
8364 -- and private operations, as well as operations that only
8365 -- have a body in the source, and for which we create a
8366 -- declaration in the protected body itself.
8368 if Present
(Corresponding_Spec
(Op_Body
)) then
8369 if Lock_Free_Active
then
8371 Build_Lock_Free_Protected_Subprogram_Body
8372 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8375 Build_Protected_Subprogram_Body
8376 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8379 Insert_After
(Current_Node
, New_Op_Body
);
8380 Analyze
(New_Op_Body
);
8382 Current_Node
:= New_Op_Body
;
8384 -- Generate an overriding primitive operation body for
8385 -- this subprogram if the protected type implements an
8388 if Ada_Version
>= Ada_2005
8390 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8393 Build_Dispatching_Subprogram_Body
8394 (Op_Body
, Pid
, New_Op_Body
);
8396 Insert_After
(Current_Node
, Disp_Op_Body
);
8397 Analyze
(Disp_Op_Body
);
8399 Current_Node
:= Disp_Op_Body
;
8404 when N_Entry_Body
=>
8405 Op_Id
:= Defining_Identifier
(Op_Body
);
8406 Num_Entries
:= Num_Entries
+ 1;
8408 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8410 Insert_After
(Current_Node
, New_Op_Body
);
8411 Current_Node
:= New_Op_Body
;
8412 Analyze
(New_Op_Body
);
8414 when N_Implicit_Label_Declaration
=>
8417 when N_Itype_Reference
=>
8418 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8420 when N_Freeze_Entity
=>
8421 New_Op_Body
:= New_Copy
(Op_Body
);
8423 if Present
(Entity
(Op_Body
))
8424 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8426 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8429 Insert_After
(Current_Node
, New_Op_Body
);
8430 Current_Node
:= New_Op_Body
;
8431 Analyze
(New_Op_Body
);
8434 New_Op_Body
:= New_Copy
(Op_Body
);
8435 Insert_After
(Current_Node
, New_Op_Body
);
8436 Current_Node
:= New_Op_Body
;
8437 Analyze
(New_Op_Body
);
8439 when N_Object_Declaration
=>
8440 pragma Assert
(not Comes_From_Source
(Op_Body
));
8441 New_Op_Body
:= New_Copy
(Op_Body
);
8442 Insert_After
(Current_Node
, New_Op_Body
);
8443 Current_Node
:= New_Op_Body
;
8444 Analyze
(New_Op_Body
);
8447 raise Program_Error
;
8454 -- Finally, create the body of the function that maps an entry index
8455 -- into the corresponding body index, except when there is no entry, or
8456 -- in a Ravenscar-like profile.
8458 if Corresponding_Runtime_Package
(Pid
) =
8459 System_Tasking_Protected_Objects_Entries
8461 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8462 Insert_After
(Current_Node
, New_Op_Body
);
8463 Current_Node
:= New_Op_Body
;
8464 Analyze
(New_Op_Body
);
8467 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8468 -- protected body. At this point all wrapper specs have been created,
8469 -- frozen and included in the dispatch table for the protected type.
8471 if Ada_Version
>= Ada_2005
then
8472 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8474 end Expand_N_Protected_Body
;
8476 -----------------------------------------
8477 -- Expand_N_Protected_Type_Declaration --
8478 -----------------------------------------
8480 -- First we create a corresponding record type declaration used to
8481 -- represent values of this protected type.
8482 -- The general form of this type declaration is
8484 -- type poV (discriminants) is record
8485 -- _Object : aliased <kind>Protection
8486 -- [(<entry count> [, <handler count>])];
8487 -- [entry_family : array (bounds) of Void;]
8488 -- <private data fields>
8491 -- The discriminants are present only if the corresponding protected type
8492 -- has discriminants, and they exactly mirror the protected type
8493 -- discriminants. The private data fields similarly mirror the private
8494 -- declarations of the protected type.
8496 -- The Object field is always present. It contains RTS specific data used
8497 -- to control the protected object. It is declared as Aliased so that it
8498 -- can be passed as a pointer to the RTS. This allows the protected record
8499 -- to be referenced within RTS data structures. An appropriate Protection
8500 -- type and discriminant are generated.
8502 -- The Service field is present for protected objects with entries. It
8503 -- contains sufficient information to allow the entry service procedure for
8504 -- this object to be called when the object is not known till runtime.
8506 -- One entry_family component is present for each entry family in the
8507 -- task definition (see Expand_N_Task_Type_Declaration).
8509 -- When a protected object is declared, an instance of the protected type
8510 -- value record is created. The elaboration of this declaration creates the
8511 -- correct bounds for the entry families, and also evaluates the priority
8512 -- expression if needed. The initialization routine for the protected type
8513 -- itself then calls Initialize_Protection with appropriate parameters to
8514 -- initialize the value of the Task_Id field. Install_Handlers may be also
8515 -- called if a pragma Attach_Handler applies.
8517 -- Note: this record is passed to the subprograms created by the expansion
8518 -- of protected subprograms and entries. It is an in parameter to protected
8519 -- functions and an in out parameter to procedures and entry bodies. The
8520 -- Entity_Id for this created record type is placed in the
8521 -- Corresponding_Record_Type field of the associated protected type entity.
8523 -- Next we create a procedure specifications for protected subprograms and
8524 -- entry bodies. For each protected subprograms two subprograms are
8525 -- created, an unprotected and a protected version. The unprotected version
8526 -- is called from within other operations of the same protected object.
8528 -- We also build the call to register the procedure if a pragma
8529 -- Interrupt_Handler applies.
8531 -- A single subprogram is created to service all entry bodies; it has an
8532 -- additional boolean out parameter indicating that the previous entry call
8533 -- made by the current task was serviced immediately, i.e. not by proxy.
8534 -- The O parameter contains a pointer to a record object of the type
8535 -- described above. An untyped interface is used here to allow this
8536 -- procedure to be called in places where the type of the object to be
8537 -- serviced is not known. This must be done, for example, when a call that
8538 -- may have been requeued is cancelled; the corresponding object must be
8539 -- serviced, but which object that is not known till runtime.
8542 -- (O : System.Address; P : out Boolean);
8543 -- procedure pprocN (_object : in out poV);
8544 -- procedure pproc (_object : in out poV);
8545 -- function pfuncN (_object : poV);
8546 -- function pfunc (_object : poV);
8549 -- Note that this must come after the record type declaration, since
8550 -- the specs refer to this type.
8552 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8553 Loc
: constant Source_Ptr
:= Sloc
(N
);
8554 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8556 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8557 -- This flag indicates whether the lock free implementation is active
8559 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8560 -- This contains two lists; one for visible and one for private decls
8564 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8568 Comp_Id
: Entity_Id
;
8570 Current_Node
: Node_Id
:= N
;
8571 Bdef
: Entity_Id
:= Empty
; -- avoid uninit warning
8572 Edef
: Entity_Id
:= Empty
; -- avoid uninit warning
8573 Entries_Aggr
: Node_Id
;
8574 Body_Id
: Entity_Id
;
8577 Object_Comp
: Node_Id
;
8579 procedure Check_Inlining
(Subp
: Entity_Id
);
8580 -- If the original operation has a pragma Inline, propagate the flag
8581 -- to the internal body, for possible inlining later on. The source
8582 -- operation is invisible to the back-end and is never actually called.
8584 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8585 -- When compiling under the Ravenscar profile, private components must
8586 -- have a static size, or else a protected object will require heap
8587 -- allocation, violating the corresponding restriction. It is preferable
8588 -- to make this check here, because it provides a better error message
8589 -- than the back-end, which refers to the object as a whole.
8591 procedure Register_Handler
;
8592 -- For a protected operation that is an interrupt handler, add the
8593 -- freeze action that will register it as such.
8595 --------------------
8596 -- Check_Inlining --
8597 --------------------
8599 procedure Check_Inlining
(Subp
: Entity_Id
) is
8601 if Is_Inlined
(Subp
) then
8602 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8603 Set_Is_Inlined
(Subp
, False);
8607 ---------------------------------
8608 -- Check_Static_Component_Size --
8609 ---------------------------------
8611 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8612 Typ
: constant Entity_Id
:= Etype
(Comp
);
8616 if Is_Scalar_Type
(Typ
) then
8619 elsif Is_Array_Type
(Typ
) then
8620 return Compile_Time_Known_Bounds
(Typ
);
8622 elsif Is_Record_Type
(Typ
) then
8623 C
:= First_Component
(Typ
);
8624 while Present
(C
) loop
8625 if not Static_Component_Size
(C
) then
8634 -- Any other type will be checked by the back-end
8639 end Static_Component_Size
;
8641 ----------------------
8642 -- Register_Handler --
8643 ----------------------
8645 procedure Register_Handler
is
8647 -- All semantic checks already done in Sem_Prag
8649 Prot_Proc
: constant Entity_Id
:=
8650 Defining_Unit_Name
(Specification
(Current_Node
));
8652 Proc_Address
: constant Node_Id
:=
8653 Make_Attribute_Reference
(Loc
,
8655 New_Reference_To
(Prot_Proc
, Loc
),
8656 Attribute_Name
=> Name_Address
);
8658 RTS_Call
: constant Entity_Id
:=
8659 Make_Procedure_Call_Statement
(Loc
,
8662 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8663 Parameter_Associations
=> New_List
(Proc_Address
));
8665 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8666 end Register_Handler
;
8668 -- Start of processing for Expand_N_Protected_Type_Declaration
8671 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8674 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8677 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8679 Qualify_Entity_Names
(N
);
8681 -- If the type has discriminants, their occurrences in the declaration
8682 -- have been replaced by the corresponding discriminals. For components
8683 -- that are constrained by discriminants, their homologues in the
8684 -- corresponding record type must refer to the discriminants of that
8685 -- record, so we must apply a new renaming to subtypes_indications:
8687 -- protected discriminant => discriminal => record discriminant
8689 -- This replacement is not applied to default expressions, for which
8690 -- the discriminal is correct.
8692 if Has_Discriminants
(Prot_Typ
) then
8698 Disc
:= First_Discriminant
(Prot_Typ
);
8699 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
8700 while Present
(Disc
) loop
8701 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
8702 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
8703 Next_Discriminant
(Disc
);
8709 -- Fill in the component declarations
8711 -- Add components for entry families. For each entry family, create an
8712 -- anonymous type declaration with the same size, and analyze the type.
8714 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
8716 pragma Assert
(Present
(Pdef
));
8718 -- Add private field components
8720 if Present
(Private_Declarations
(Pdef
)) then
8721 Priv
:= First
(Private_Declarations
(Pdef
));
8723 while Present
(Priv
) loop
8725 if Nkind
(Priv
) = N_Component_Declaration
then
8726 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
8728 -- When compiling for a restricted profile, the private
8729 -- components must have a static size. If not, this is an
8730 -- error for a single protected declaration, and rates a
8731 -- warning on a protected type declaration.
8733 if not Comes_From_Source
(Prot_Typ
) then
8734 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
8736 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
8737 Error_Msg_N
("component has non-static size?", Priv
);
8739 ("\creation of protected object of type& will violate"
8740 & " restriction No_Implicit_Heap_Allocations?",
8745 -- The component definition consists of a subtype indication,
8746 -- or (in Ada 2005) an access definition. Make a copy of the
8747 -- proper definition.
8750 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
8751 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
8753 Nent
: constant Entity_Id
:=
8754 Make_Defining_Identifier
(Sloc
(Oent
),
8755 Chars
=> Chars
(Oent
));
8758 if Present
(Subtype_Indication
(Old_Comp
)) then
8760 Make_Component_Definition
(Sloc
(Oent
),
8761 Aliased_Present
=> False,
8762 Subtype_Indication
=>
8763 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
8767 Make_Component_Definition
(Sloc
(Oent
),
8768 Aliased_Present
=> False,
8769 Access_Definition
=>
8770 New_Copy_Tree
(Access_Definition
(Old_Comp
),
8775 Make_Component_Declaration
(Loc
,
8776 Defining_Identifier
=> Nent
,
8777 Component_Definition
=> New_Comp
,
8778 Expression
=> Expression
(Priv
));
8780 Set_Has_Per_Object_Constraint
(Nent
,
8781 Has_Per_Object_Constraint
(Oent
));
8783 Append_To
(Cdecls
, New_Priv
);
8786 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
8788 -- Make the unprotected version of the subprogram available
8789 -- for expansion of intra object calls. There is need for
8790 -- a protected version only if the subprogram is an interrupt
8791 -- handler, otherwise this operation can only be called from
8795 Make_Subprogram_Declaration
(Loc
,
8797 Build_Protected_Sub_Specification
8798 (Priv
, Prot_Typ
, Unprotected_Mode
));
8800 Insert_After
(Current_Node
, Sub
);
8803 Set_Protected_Body_Subprogram
8804 (Defining_Unit_Name
(Specification
(Priv
)),
8805 Defining_Unit_Name
(Specification
(Sub
)));
8806 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
8807 Current_Node
:= Sub
;
8810 Make_Subprogram_Declaration
(Loc
,
8812 Build_Protected_Sub_Specification
8813 (Priv
, Prot_Typ
, Protected_Mode
));
8815 Insert_After
(Current_Node
, Sub
);
8817 Current_Node
:= Sub
;
8819 if Is_Interrupt_Handler
8820 (Defining_Unit_Name
(Specification
(Priv
)))
8822 if not Restricted_Profile
then
8832 -- Except for the lock-free implementation, prepend the _Object field
8833 -- with the right type to the component list. We need to compute the
8834 -- number of entries, and in some cases the number of Attach_Handler
8837 if not Lock_Free_Active
then
8840 Num_Attach_Handler
: Int
:= 0;
8841 Protection_Subtype
: Node_Id
;
8842 Entry_Count_Expr
: constant Node_Id
:=
8843 Build_Entry_Count_Expression
8844 (Prot_Typ
, Cdecls
, Loc
);
8847 -- Could this be simplified using Corresponding_Runtime_Package???
8849 if Has_Attach_Handler
(Prot_Typ
) then
8850 Ritem
:= First_Rep_Item
(Prot_Typ
);
8851 while Present
(Ritem
) loop
8852 if Nkind
(Ritem
) = N_Pragma
8853 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
8855 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
8858 Next_Rep_Item
(Ritem
);
8861 if Restricted_Profile
then
8862 if Has_Entries
(Prot_Typ
) then
8863 Protection_Subtype
:=
8864 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
8866 Protection_Subtype
:=
8867 New_Reference_To
(RTE
(RE_Protection
), Loc
);
8871 Protection_Subtype
:=
8872 Make_Subtype_Indication
(Loc
,
8875 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
8877 Make_Index_Or_Discriminant_Constraint
(Loc
,
8878 Constraints
=> New_List
(
8880 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
8883 elsif Has_Interrupt_Handler
(Prot_Typ
)
8884 and then not Restriction_Active
(No_Dynamic_Attachment
)
8886 Protection_Subtype
:=
8887 Make_Subtype_Indication
(Loc
,
8890 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
8892 Make_Index_Or_Discriminant_Constraint
(Loc
,
8893 Constraints
=> New_List
(Entry_Count_Expr
)));
8895 -- Type has explicit entries or generated primitive entry wrappers
8897 elsif Has_Entries
(Prot_Typ
)
8898 or else (Ada_Version
>= Ada_2005
8899 and then Present
(Interface_List
(N
)))
8901 case Corresponding_Runtime_Package
(Prot_Typ
) is
8902 when System_Tasking_Protected_Objects_Entries
=>
8903 Protection_Subtype
:=
8904 Make_Subtype_Indication
(Loc
,
8907 (RTE
(RE_Protection_Entries
), Loc
),
8909 Make_Index_Or_Discriminant_Constraint
(Loc
,
8910 Constraints
=> New_List
(Entry_Count_Expr
)));
8912 when System_Tasking_Protected_Objects_Single_Entry
=>
8913 Protection_Subtype
:=
8914 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
8917 raise Program_Error
;
8921 Protection_Subtype
:=
8922 New_Reference_To
(RTE
(RE_Protection
), Loc
);
8926 Make_Component_Declaration
(Loc
,
8927 Defining_Identifier
=>
8928 Make_Defining_Identifier
(Loc
, Name_uObject
),
8929 Component_Definition
=>
8930 Make_Component_Definition
(Loc
,
8931 Aliased_Present
=> True,
8932 Subtype_Indication
=> Protection_Subtype
));
8935 -- Put the _Object component after the private component so that it
8936 -- be finalized early as required by 9.4 (20)
8938 Append_To
(Cdecls
, Object_Comp
);
8941 Insert_After
(Current_Node
, Rec_Decl
);
8942 Current_Node
:= Rec_Decl
;
8944 -- Analyze the record declaration immediately after construction,
8945 -- because the initialization procedure is needed for single object
8946 -- declarations before the next entity is analyzed (the freeze call
8947 -- that generates this initialization procedure is found below).
8949 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
8951 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8952 -- the corresponding record is frozen. If any wrappers are generated,
8953 -- Current_Node is updated accordingly.
8955 if Ada_Version
>= Ada_2005
then
8956 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
8959 -- Collect pointers to entry bodies and their barriers, to be placed
8960 -- in the Entry_Bodies_Array for the type. For each entry/family we
8961 -- add an expression to the aggregate which is the initial value of
8962 -- this array. The array is declared after all protected subprograms.
8964 if Has_Entries
(Prot_Typ
) then
8965 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
8967 Entries_Aggr
:= Empty
;
8970 -- Build two new procedure specifications for each protected subprogram;
8971 -- one to call from outside the object and one to call from inside.
8972 -- Build a barrier function and an entry body action procedure
8973 -- specification for each protected entry. Initialize the entry body
8974 -- array. If subprogram is flagged as eliminated, do not generate any
8975 -- internal operations.
8978 Comp
:= First
(Visible_Declarations
(Pdef
));
8979 while Present
(Comp
) loop
8980 if Nkind
(Comp
) = N_Subprogram_Declaration
then
8982 Make_Subprogram_Declaration
(Loc
,
8984 Build_Protected_Sub_Specification
8985 (Comp
, Prot_Typ
, Unprotected_Mode
));
8987 Insert_After
(Current_Node
, Sub
);
8990 Set_Protected_Body_Subprogram
8991 (Defining_Unit_Name
(Specification
(Comp
)),
8992 Defining_Unit_Name
(Specification
(Sub
)));
8993 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
8995 -- Make the protected version of the subprogram available for
8996 -- expansion of external calls.
8998 Current_Node
:= Sub
;
9001 Make_Subprogram_Declaration
(Loc
,
9003 Build_Protected_Sub_Specification
9004 (Comp
, Prot_Typ
, Protected_Mode
));
9006 Insert_After
(Current_Node
, Sub
);
9009 Current_Node
:= Sub
;
9011 -- Generate an overriding primitive operation specification for
9012 -- this subprogram if the protected type implements an interface.
9014 if Ada_Version
>= Ada_2005
9016 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9019 Make_Subprogram_Declaration
(Loc
,
9021 Build_Protected_Sub_Specification
9022 (Comp
, Prot_Typ
, Dispatching_Mode
));
9024 Insert_After
(Current_Node
, Sub
);
9027 Current_Node
:= Sub
;
9030 -- If a pragma Interrupt_Handler applies, build and add a call to
9031 -- Register_Interrupt_Handler to the freezing actions of the
9032 -- protected version (Current_Node) of the subprogram:
9034 -- system.interrupts.register_interrupt_handler
9035 -- (prot_procP'address);
9037 if not Restricted_Profile
9038 and then Is_Interrupt_Handler
9039 (Defining_Unit_Name
(Specification
(Comp
)))
9044 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9045 E_Count
:= E_Count
+ 1;
9046 Comp_Id
:= Defining_Identifier
(Comp
);
9049 Make_Defining_Identifier
(Loc
,
9050 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9052 Make_Subprogram_Declaration
(Loc
,
9054 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9056 Insert_After
(Current_Node
, Sub
);
9059 -- Build wrapper procedure for pre/postconditions
9061 Build_PPC_Wrapper
(Comp_Id
, N
);
9063 Set_Protected_Body_Subprogram
9064 (Defining_Identifier
(Comp
),
9065 Defining_Unit_Name
(Specification
(Sub
)));
9067 Current_Node
:= Sub
;
9070 Make_Defining_Identifier
(Loc
,
9071 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
9073 Make_Subprogram_Declaration
(Loc
,
9075 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9077 Insert_After
(Current_Node
, Sub
);
9079 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9080 Set_Barrier_Function
(Comp_Id
, Bdef
);
9081 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9082 Current_Node
:= Sub
;
9084 -- Collect pointers to the protected subprogram and the barrier
9085 -- of the current entry, for insertion into Entry_Bodies_Array.
9087 Append_To
(Expressions
(Entries_Aggr
),
9088 Make_Aggregate
(Loc
,
9089 Expressions
=> New_List
(
9090 Make_Attribute_Reference
(Loc
,
9091 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9092 Attribute_Name
=> Name_Unrestricted_Access
),
9093 Make_Attribute_Reference
(Loc
,
9094 Prefix
=> New_Reference_To
(Edef
, Loc
),
9095 Attribute_Name
=> Name_Unrestricted_Access
))));
9101 -- If there are some private entry declarations, expand it as if they
9102 -- were visible entries.
9104 if Present
(Private_Declarations
(Pdef
)) then
9105 Comp
:= First
(Private_Declarations
(Pdef
));
9106 while Present
(Comp
) loop
9107 if Nkind
(Comp
) = N_Entry_Declaration
then
9108 E_Count
:= E_Count
+ 1;
9109 Comp_Id
:= Defining_Identifier
(Comp
);
9112 Make_Defining_Identifier
(Loc
,
9113 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9115 Make_Subprogram_Declaration
(Loc
,
9117 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9119 Insert_After
(Current_Node
, Sub
);
9122 Set_Protected_Body_Subprogram
9123 (Defining_Identifier
(Comp
),
9124 Defining_Unit_Name
(Specification
(Sub
)));
9126 Current_Node
:= Sub
;
9129 Make_Defining_Identifier
(Loc
,
9130 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9133 Make_Subprogram_Declaration
(Loc
,
9135 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9137 Insert_After
(Current_Node
, Sub
);
9139 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9140 Set_Barrier_Function
(Comp_Id
, Bdef
);
9141 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9142 Current_Node
:= Sub
;
9144 -- Collect pointers to the protected subprogram and the barrier
9145 -- of the current entry, for insertion into Entry_Bodies_Array.
9147 Append_To
(Expressions
(Entries_Aggr
),
9148 Make_Aggregate
(Loc
,
9149 Expressions
=> New_List
(
9150 Make_Attribute_Reference
(Loc
,
9151 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9152 Attribute_Name
=> Name_Unrestricted_Access
),
9153 Make_Attribute_Reference
(Loc
,
9154 Prefix
=> New_Reference_To
(Edef
, Loc
),
9155 Attribute_Name
=> Name_Unrestricted_Access
))));
9162 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9163 -- all protected subprograms have been collected.
9165 if Has_Entries
(Prot_Typ
) then
9167 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9168 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9170 case Corresponding_Runtime_Package
(Prot_Typ
) is
9171 when System_Tasking_Protected_Objects_Entries
=>
9172 Body_Arr
:= Make_Object_Declaration
(Loc
,
9173 Defining_Identifier
=> Body_Id
,
9174 Aliased_Present
=> True,
9175 Object_Definition
=>
9176 Make_Subtype_Indication
(Loc
,
9177 Subtype_Mark
=> New_Reference_To
(
9178 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9180 Make_Index_Or_Discriminant_Constraint
(Loc
,
9181 Constraints
=> New_List
(
9183 Make_Integer_Literal
(Loc
, 1),
9184 Make_Integer_Literal
(Loc
, E_Count
))))),
9185 Expression
=> Entries_Aggr
);
9187 when System_Tasking_Protected_Objects_Single_Entry
=>
9188 Body_Arr
:= Make_Object_Declaration
(Loc
,
9189 Defining_Identifier
=> Body_Id
,
9190 Aliased_Present
=> True,
9191 Object_Definition
=> New_Reference_To
9192 (RTE
(RE_Entry_Body
), Loc
),
9194 Make_Aggregate
(Loc
,
9195 Expressions
=> New_List
(
9196 Make_Attribute_Reference
(Loc
,
9197 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9198 Attribute_Name
=> Name_Unrestricted_Access
),
9199 Make_Attribute_Reference
(Loc
,
9200 Prefix
=> New_Reference_To
(Edef
, Loc
),
9201 Attribute_Name
=> Name_Unrestricted_Access
))));
9204 raise Program_Error
;
9207 -- A pointer to this array will be placed in the corresponding record
9208 -- by its initialization procedure so this needs to be analyzed here.
9210 Insert_After
(Current_Node
, Body_Arr
);
9211 Current_Node
:= Body_Arr
;
9214 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9216 -- Finally, build the function that maps an entry index into the
9217 -- corresponding body. A pointer to this function is placed in each
9218 -- object of the type. Except for a ravenscar-like profile (no abort,
9219 -- no entry queue, 1 entry)
9221 if Corresponding_Runtime_Package
(Prot_Typ
) =
9222 System_Tasking_Protected_Objects_Entries
9225 Make_Subprogram_Declaration
(Loc
,
9226 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9227 Insert_After
(Current_Node
, Sub
);
9231 end Expand_N_Protected_Type_Declaration
;
9233 --------------------------------
9234 -- Expand_N_Requeue_Statement --
9235 --------------------------------
9237 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9238 -- operations, depending on the source and destination (task or protected
9239 -- object). A dispatching requeue statement is expanded into a call to the
9240 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9241 -- jump around the remainder of processing for the original entry and, if
9242 -- the destination is (different) protected object, to attempt to service
9243 -- it. The following illustrates the various cases:
9246 -- (O : System.Address;
9247 -- P : System.Address;
9248 -- E : Protected_Entry_Index)
9250 -- <discriminant renamings>
9251 -- <private object renamings>
9252 -- type poVP is access poV;
9253 -- _object : ptVP := ptVP!(O);
9257 -- <start of statement sequence for entry>
9259 -- -- Requeue from one protected entry body to another protected
9262 -- Requeue_Protected_Entry (
9263 -- _object._object'Access,
9264 -- new._object'Access,
9269 -- <some more of the statement sequence for entry>
9271 -- -- Requeue from an entry body to a task entry
9273 -- Requeue_Protected_To_Task_Entry (
9279 -- <rest of statement sequence for entry>
9280 -- Complete_Entry_Body (_object._object);
9283 -- when all others =>
9284 -- Exceptional_Complete_Entry_Body (
9285 -- _object._object, Get_GNAT_Exception);
9289 -- Requeue of a task entry call to a task entry
9291 -- Accept_Call (E, Ann);
9292 -- <start of statement sequence for accept statement>
9293 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9295 -- <rest of statement sequence for accept statement>
9297 -- Complete_Rendezvous;
9300 -- when all others =>
9301 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9303 -- Requeue of a task entry call to a protected entry
9305 -- Accept_Call (E, Ann);
9306 -- <start of statement sequence for accept statement>
9307 -- Requeue_Task_To_Protected_Entry (
9308 -- new._object'Access,
9313 -- <rest of statement sequence for accept statement>
9315 -- Complete_Rendezvous;
9318 -- when all others =>
9319 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9321 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9322 -- marked by pragma Implemented (XXX, By_Entry).
9324 -- The requeue is inside a protected entry:
9327 -- (O : System.Address;
9328 -- P : System.Address;
9329 -- E : Protected_Entry_Index)
9331 -- <discriminant renamings>
9332 -- <private object renamings>
9333 -- type poVP is access poV;
9334 -- _object : ptVP := ptVP!(O);
9338 -- <start of statement sequence for entry>
9341 -- (<interface class-wide object>,
9344 -- Ada.Tags.Get_Offset_Index
9346 -- <interface dispatch table index of target entry>),
9350 -- <rest of statement sequence for entry>
9351 -- Complete_Entry_Body (_object._object);
9354 -- when all others =>
9355 -- Exceptional_Complete_Entry_Body (
9356 -- _object._object, Get_GNAT_Exception);
9360 -- The requeue is inside a task entry:
9362 -- Accept_Call (E, Ann);
9363 -- <start of statement sequence for accept statement>
9365 -- (<interface class-wide object>,
9368 -- Ada.Tags.Get_Offset_Index
9370 -- <interface dispatch table index of target entrt>),
9374 -- <rest of statement sequence for accept statement>
9376 -- Complete_Rendezvous;
9379 -- when all others =>
9380 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9382 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9383 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9384 -- statement is replaced by a dispatching call with actual parameters taken
9385 -- from the inner-most accept statement or entry body.
9387 -- Target.Primitive (Param1, ..., ParamN);
9389 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9390 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9394 -- S : constant Offset_Index :=
9395 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9396 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9399 -- if C = POK_Protected_Entry
9400 -- or else C = POK_Task_Entry
9402 -- <statements for dispatching requeue>
9404 -- elsif C = POK_Protected_Procedure then
9405 -- <dispatching call equivalent>
9408 -- raise Program_Error;
9412 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9413 Loc
: constant Source_Ptr
:= Sloc
(N
);
9414 Conc_Typ
: Entity_Id
;
9418 Old_Typ
: Entity_Id
;
9420 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9421 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9422 -- the form Concval.Ename. It is statically known that Ename is allowed
9423 -- to be implemented by a protected procedure. Create a dispatching call
9424 -- equivalent of Concval.Ename taking the actual parameters from the
9425 -- inner-most accept statement or entry body.
9427 function Build_Dispatching_Requeue
return Node_Id
;
9428 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9429 -- the form Concval.Ename. It is statically known that Ename is allowed
9430 -- to be implemented by a protected or a task entry. Create a call to
9431 -- primitive _Disp_Requeue which handles the low-level actions.
9433 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9434 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9435 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9436 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9437 -- determines at runtime whether Ename denotes an entry or a procedure
9438 -- and perform the appropriate kind of dispatching select.
9440 function Build_Normal_Requeue
return Node_Id
;
9441 -- N denotes a non-dispatching requeue statement to either a task or a
9442 -- protected entry. Build the appropriate runtime call to perform the
9445 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9446 -- For a protected entry, create a return statement to skip the rest of
9447 -- the entry body. Otherwise, create a goto statement to skip the rest
9448 -- of a task accept statement. The lookup for the enclosing entry body
9449 -- or accept statement starts from Search.
9451 ---------------------------------------
9452 -- Build_Dispatching_Call_Equivalent --
9453 ---------------------------------------
9455 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9456 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9457 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9464 -- Climb the parent chain looking for the inner-most entry body or
9465 -- accept statement.
9468 while Present
(Acc_Ent
)
9469 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9472 Acc_Ent
:= Parent
(Acc_Ent
);
9475 -- A requeue statement should be housed inside an entry body or an
9476 -- accept statement at some level. If this is not the case, then the
9477 -- tree is malformed.
9479 pragma Assert
(Present
(Acc_Ent
));
9481 -- Recover the list of formal parameters
9483 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9484 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9487 Formals
:= Parameter_Specifications
(Acc_Ent
);
9489 -- Create the actual parameters for the dispatching call. These are
9490 -- simply copies of the entry body or accept statement formals in the
9491 -- same order as they appear.
9495 if Present
(Formals
) then
9496 Actuals
:= New_List
;
9497 Formal
:= First
(Formals
);
9498 while Present
(Formal
) loop
9500 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9506 -- Obj.Call_Ent (Actuals);
9509 Make_Procedure_Call_Statement
(Loc
,
9511 Make_Selected_Component
(Loc
,
9512 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9513 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9515 Parameter_Associations
=> Actuals
);
9516 end Build_Dispatching_Call_Equivalent
;
9518 -------------------------------
9519 -- Build_Dispatching_Requeue --
9520 -------------------------------
9522 function Build_Dispatching_Requeue
return Node_Id
is
9523 Params
: constant List_Id
:= New_List
;
9526 -- Process the "with abort" parameter
9529 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9531 -- Process the entry wrapper's position in the primary dispatch
9532 -- table parameter. Generate:
9534 -- Ada.Tags.Get_Entry_Index
9535 -- (T => To_Tag_Ptr (Obj'Address).all,
9537 -- Ada.Tags.Get_Offset_Index
9538 -- (Ada.Tags.Tag (Concval),
9539 -- <interface dispatch table position of Ename>));
9541 -- Note that Obj'Address is recursively expanded into a call to
9542 -- Base_Address (Obj).
9544 if Tagged_Type_Expansion
then
9546 Make_Function_Call
(Loc
,
9547 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9548 Parameter_Associations
=> New_List
(
9550 Make_Explicit_Dereference
(Loc
,
9551 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9552 Make_Attribute_Reference
(Loc
,
9553 Prefix
=> New_Copy_Tree
(Concval
),
9554 Attribute_Name
=> Name_Address
))),
9556 Make_Function_Call
(Loc
,
9557 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9558 Parameter_Associations
=> New_List
(
9559 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9560 Make_Integer_Literal
(Loc
,
9561 DT_Position
(Entity
(Ename
))))))));
9567 Make_Function_Call
(Loc
,
9568 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9569 Parameter_Associations
=> New_List
(
9571 Make_Attribute_Reference
(Loc
,
9573 Attribute_Name
=> Name_Tag
),
9575 Make_Function_Call
(Loc
,
9576 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9578 Parameter_Associations
=> New_List
(
9582 Make_Attribute_Reference
(Loc
,
9584 Attribute_Name
=> Name_Tag
),
9588 Make_Attribute_Reference
(Loc
,
9589 Prefix
=> New_Reference_To
(Etype
(Concval
), Loc
),
9590 Attribute_Name
=> Name_Tag
),
9594 Make_Integer_Literal
(Loc
,
9595 DT_Position
(Entity
(Ename
))))))));
9598 -- Specific actuals for protected to XXX requeue
9600 if Is_Protected_Type
(Old_Typ
) then
9602 Make_Attribute_Reference
(Loc
, -- _object'Address
9604 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9605 Attribute_Name
=> Name_Address
));
9607 Prepend_To
(Params
, -- True
9608 New_Reference_To
(Standard_True
, Loc
));
9610 -- Specific actuals for task to XXX requeue
9613 pragma Assert
(Is_Task_Type
(Old_Typ
));
9615 Prepend_To
(Params
, -- null
9616 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
9618 Prepend_To
(Params
, -- False
9619 New_Reference_To
(Standard_False
, Loc
));
9622 -- Add the object parameter
9624 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9627 -- _Disp_Requeue (<Params>);
9629 -- Find entity for Disp_Requeue operation, which belongs to
9630 -- the type and may not be directly visible.
9637 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9638 while Present
(Elmt
) loop
9640 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9645 Make_Procedure_Call_Statement
(Loc
,
9646 Name
=> New_Occurrence_Of
(Op
, Loc
),
9647 Parameter_Associations
=> Params
);
9649 end Build_Dispatching_Requeue
;
9651 --------------------------------------
9652 -- Build_Dispatching_Requeue_To_Any --
9653 --------------------------------------
9655 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9656 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9657 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9658 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
9668 -- Dispatch table slot processing, generate:
9671 S
:= Build_S
(Loc
, Decls
);
9673 -- Call kind processing, generate:
9674 -- C : Ada.Tags.Prim_Op_Kind;
9676 C
:= Build_C
(Loc
, Decls
);
9679 -- S := Ada.Tags.Get_Offset_Index
9680 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9682 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
9685 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9688 Make_Procedure_Call_Statement
(Loc
,
9691 Find_Prim_Op
(Etype
(Etype
(Obj
)),
9692 Name_uDisp_Get_Prim_Op_Kind
),
9694 Parameter_Associations
=> New_List
(
9695 New_Copy_Tree
(Obj
),
9696 New_Reference_To
(S
, Loc
),
9697 New_Reference_To
(C
, Loc
))));
9701 -- if C = POK_Protected_Entry
9702 -- or else C = POK_Task_Entry
9705 Make_If_Statement
(Loc
,
9711 New_Reference_To
(C
, Loc
),
9713 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
9718 New_Reference_To
(C
, Loc
),
9720 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
9722 -- Dispatching requeue equivalent
9724 Then_Statements
=> New_List
(
9725 Build_Dispatching_Requeue
,
9728 -- elsif C = POK_Protected_Procedure then
9730 Elsif_Parts
=> New_List
(
9731 Make_Elsif_Part
(Loc
,
9735 New_Reference_To
(C
, Loc
),
9738 RTE
(RE_POK_Protected_Procedure
), Loc
)),
9740 -- Dispatching call equivalent
9742 Then_Statements
=> New_List
(
9743 Build_Dispatching_Call_Equivalent
))),
9746 -- raise Program_Error;
9749 Else_Statements
=> New_List
(
9750 Make_Raise_Program_Error
(Loc
,
9751 Reason
=> PE_Explicit_Raise
))));
9753 -- Wrap everything into a block
9756 Make_Block_Statement
(Loc
,
9757 Declarations
=> Decls
,
9758 Handled_Statement_Sequence
=>
9759 Make_Handled_Sequence_Of_Statements
(Loc
,
9760 Statements
=> Stmts
));
9761 end Build_Dispatching_Requeue_To_Any
;
9763 --------------------------
9764 -- Build_Normal_Requeue --
9765 --------------------------
9767 function Build_Normal_Requeue
return Node_Id
is
9768 Params
: constant List_Id
:= New_List
;
9773 -- Process the "with abort" parameter
9776 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9778 -- Add the index expression to the parameters. It is common among all
9782 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
9784 if Is_Protected_Type
(Old_Typ
) then
9786 Self_Param
: Node_Id
;
9790 Make_Attribute_Reference
(Loc
,
9792 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9794 Name_Unchecked_Access
);
9796 -- Protected to protected requeue
9798 if Is_Protected_Type
(Conc_Typ
) then
9801 RTE
(RE_Requeue_Protected_Entry
), Loc
);
9804 Make_Attribute_Reference
(Loc
,
9806 Concurrent_Ref
(Concval
),
9808 Name_Unchecked_Access
);
9810 -- Protected to task requeue
9812 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9815 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
9817 Param
:= Concurrent_Ref
(Concval
);
9820 Prepend_To
(Params
, Param
);
9821 Prepend_To
(Params
, Self_Param
);
9824 else pragma Assert
(Is_Task_Type
(Old_Typ
));
9826 -- Task to protected requeue
9828 if Is_Protected_Type
(Conc_Typ
) then
9831 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
9834 Make_Attribute_Reference
(Loc
,
9836 Concurrent_Ref
(Concval
),
9838 Name_Unchecked_Access
);
9840 -- Task to task requeue
9842 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9844 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
);
9846 Param
:= Concurrent_Ref
(Concval
);
9849 Prepend_To
(Params
, Param
);
9853 Make_Procedure_Call_Statement
(Loc
,
9855 Parameter_Associations
=> Params
);
9856 end Build_Normal_Requeue
;
9858 --------------------------
9859 -- Build_Skip_Statement --
9860 --------------------------
9862 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
9863 Skip_Stmt
: Node_Id
;
9866 -- Build a return statement to skip the rest of the entire body
9868 if Is_Protected_Type
(Old_Typ
) then
9869 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
9871 -- If the requeue is within a task, find the end label of the
9872 -- enclosing accept statement and create a goto statement to it.
9880 -- Climb the parent chain looking for the enclosing accept
9883 Acc
:= Parent
(Search
);
9885 and then Nkind
(Acc
) /= N_Accept_Statement
9887 Acc
:= Parent
(Acc
);
9890 -- The last statement is the second label used for completing
9891 -- the rendezvous the usual way. The label we are looking for
9892 -- is right before it.
9895 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
9897 pragma Assert
(Nkind
(Label
) = N_Label
);
9899 -- Generate a goto statement to skip the rest of the accept
9902 Make_Goto_Statement
(Loc
,
9904 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
9908 Set_Analyzed
(Skip_Stmt
);
9911 end Build_Skip_Statement
;
9913 -- Start of processing for Expand_N_Requeue_Statement
9916 -- Extract the components of the entry call
9918 Extract_Entry
(N
, Concval
, Ename
, Index
);
9919 Conc_Typ
:= Etype
(Concval
);
9921 -- If the prefix is an access to class-wide type, dereference to get
9922 -- object and entry type.
9924 if Is_Access_Type
(Conc_Typ
) then
9925 Conc_Typ
:= Designated_Type
(Conc_Typ
);
9927 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
9928 Analyze_And_Resolve
(Concval
, Conc_Typ
);
9931 -- Examine the scope stack in order to find nearest enclosing protected
9932 -- or task type. This will constitute our invocation source.
9934 Old_Typ
:= Current_Scope
;
9935 while Present
(Old_Typ
)
9936 and then not Is_Protected_Type
(Old_Typ
)
9937 and then not Is_Task_Type
(Old_Typ
)
9939 Old_Typ
:= Scope
(Old_Typ
);
9942 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9943 -- Concval.Ename where the type of Concval is class-wide concurrent
9946 if Ada_Version
>= Ada_2012
9947 and then Present
(Concval
)
9948 and then Is_Class_Wide_Type
(Conc_Typ
)
9949 and then Is_Concurrent_Interface
(Conc_Typ
)
9952 Has_Impl
: Boolean := False;
9953 Impl_Kind
: Name_Id
:= No_Name
;
9956 -- Check whether the Ename is flagged by pragma Implemented
9958 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
9960 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
9963 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9964 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9967 and then Impl_Kind
= Name_By_Entry
9969 Rewrite
(N
, Build_Dispatching_Requeue
);
9971 Insert_After
(N
, Build_Skip_Statement
(N
));
9973 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9974 -- a protected procedure. In this case the requeue is transformed
9975 -- into a dispatching call.
9978 and then Impl_Kind
= Name_By_Protected_Procedure
9980 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
9983 -- The procedure_or_entry_NAME's implementation kind is either
9984 -- By_Any, Optional, or pragma Implemented was not applied at all.
9985 -- In this case a runtime test determines whether Ename denotes an
9986 -- entry or a protected procedure and performs the appropriate
9990 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
9995 -- Processing for regular (non-dispatching) requeues
9998 Rewrite
(N
, Build_Normal_Requeue
);
10000 Insert_After
(N
, Build_Skip_Statement
(N
));
10002 end Expand_N_Requeue_Statement
;
10004 -------------------------------
10005 -- Expand_N_Selective_Accept --
10006 -------------------------------
10008 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10009 Loc
: constant Source_Ptr
:= Sloc
(N
);
10010 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10012 -- Note: in the below declarations a lot of new lists are allocated
10013 -- unconditionally which may well not end up being used. That's
10014 -- not a good idea since it wastes space gratuitously ???
10016 Accept_Case
: List_Id
;
10017 Accept_List
: constant List_Id
:= New_List
;
10020 Alt_List
: constant List_Id
:= New_List
;
10021 Alt_Stats
: List_Id
;
10022 Ann
: Entity_Id
:= Empty
;
10025 Check_Guard
: Boolean := True;
10027 Decls
: constant List_Id
:= New_List
;
10028 Stats
: constant List_Id
:= New_List
;
10029 Body_List
: constant List_Id
:= New_List
;
10030 Trailing_List
: constant List_Id
:= New_List
;
10033 Else_Present
: Boolean := False;
10034 Terminate_Alt
: Node_Id
:= Empty
;
10035 Select_Mode
: Node_Id
;
10037 Delay_Case
: List_Id
;
10038 Delay_Count
: Integer := 0;
10039 Delay_Val
: Entity_Id
;
10040 Delay_Index
: Entity_Id
;
10041 Delay_Min
: Entity_Id
;
10042 Delay_Num
: Int
:= 1;
10043 Delay_Alt_List
: List_Id
:= New_List
;
10044 Delay_List
: constant List_Id
:= New_List
;
10048 First_Delay
: Boolean := True;
10049 Guard_Open
: Entity_Id
;
10055 Num_Accept
: Nat
:= 0;
10058 Time_Type
: Entity_Id
;
10060 Select_Call
: Node_Id
;
10062 Qnam
: constant Entity_Id
:=
10063 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10065 Xnam
: constant Entity_Id
:=
10066 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10068 -----------------------
10069 -- Local subprograms --
10070 -----------------------
10072 function Accept_Or_Raise
return List_Id
;
10073 -- For the rare case where delay alternatives all have guards, and
10074 -- all of them are closed, it is still possible that there were open
10075 -- accept alternatives with no callers. We must reexamine the
10076 -- Accept_List, and execute a selective wait with no else if some
10077 -- accept is open. If none, we raise program_error.
10079 procedure Add_Accept
(Alt
: Node_Id
);
10080 -- Process a single accept statement in a select alternative. Build
10081 -- procedure for body of accept, and add entry to dispatch table with
10082 -- expression for guard, in preparation for call to run time select.
10084 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10085 -- Manufacture a label using Num as a serial number and declare it.
10086 -- The declaration is appended to Decls. The label marks the trailing
10087 -- statements of an accept or delay alternative.
10089 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10090 -- Build call to Selective_Wait runtime routine
10092 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10093 -- Add code to compare value of delay with previous values, and
10094 -- generate case entry for trailing statements.
10096 procedure Process_Accept_Alternative
10100 -- Add code to call corresponding procedure, and branch to
10101 -- trailing statements, if any.
10103 ---------------------
10104 -- Accept_Or_Raise --
10105 ---------------------
10107 function Accept_Or_Raise
return List_Id
is
10110 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10113 -- We generate the following:
10115 -- for J in q'range loop
10116 -- if q(J).S /=null_task_entry then
10117 -- selective_wait (simple_mode,...);
10123 -- if no rendez_vous then
10124 -- raise program_error;
10127 -- Note that the code needs to know that the selector name
10128 -- in an Accept_Alternative is named S.
10130 Cond
:= Make_Op_Ne
(Loc
,
10132 Make_Selected_Component
(Loc
,
10134 Make_Indexed_Component
(Loc
,
10135 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10136 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
10137 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10139 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
10141 Stats
:= New_List
(
10142 Make_Implicit_Loop_Statement
(N
,
10143 Identifier
=> Empty
,
10144 Iteration_Scheme
=>
10145 Make_Iteration_Scheme
(Loc
,
10146 Loop_Parameter_Specification
=>
10147 Make_Loop_Parameter_Specification
(Loc
,
10148 Defining_Identifier
=> J
,
10149 Discrete_Subtype_Definition
=>
10150 Make_Attribute_Reference
(Loc
,
10151 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10152 Attribute_Name
=> Name_Range
,
10153 Expressions
=> New_List
(
10154 Make_Integer_Literal
(Loc
, 1))))),
10156 Statements
=> New_List
(
10157 Make_Implicit_If_Statement
(N
,
10159 Then_Statements
=> New_List
(
10161 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
10162 Make_Exit_Statement
(Loc
))))));
10165 Make_Raise_Program_Error
(Loc
,
10166 Condition
=> Make_Op_Eq
(Loc
,
10167 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
10169 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
10170 Reason
=> PE_All_Guards_Closed
));
10173 end Accept_Or_Raise
;
10179 procedure Add_Accept
(Alt
: Node_Id
) is
10180 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10181 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10182 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10183 Eent
: constant Entity_Id
:= Entity
(Ename
);
10184 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10185 Null_Body
: Node_Id
;
10186 Proc_Body
: Node_Id
;
10187 PB_Ent
: Entity_Id
;
10193 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10196 if Present
(Condition
(Alt
)) then
10198 Make_Conditional_Expression
(Eloc
, New_List
(
10200 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10201 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10204 Entry_Index_Expression
10205 (Eloc
, Eent
, Index
, Scope
(Eent
));
10208 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10209 Null_Body
:= New_Reference_To
(Standard_False
, Eloc
);
10211 if Abort_Allowed
then
10212 Call
:= Make_Procedure_Call_Statement
(Eloc
,
10213 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Eloc
));
10214 Insert_Before
(First
(Statements
(Handled_Statement_Sequence
(
10215 Accept_Statement
(Alt
)))), Call
);
10220 Make_Defining_Identifier
(Eloc
,
10221 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10223 if Comes_From_Source
(Alt
) then
10224 Set_Debug_Info_Needed
(PB_Ent
);
10228 Make_Subprogram_Body
(Eloc
,
10230 Make_Procedure_Specification
(Eloc
,
10231 Defining_Unit_Name
=> PB_Ent
),
10232 Declarations
=> Declarations
(Acc_Stm
),
10233 Handled_Statement_Sequence
=>
10234 Build_Accept_Body
(Accept_Statement
(Alt
)));
10236 -- During the analysis of the body of the accept statement, any
10237 -- zero cost exception handler records were collected in the
10238 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10239 -- This is where we move them to where they belong, namely the
10240 -- newly created procedure.
10242 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10243 Append
(Proc_Body
, Body_List
);
10246 Null_Body
:= New_Reference_To
(Standard_True
, Eloc
);
10248 -- if accept statement has declarations, insert above, given that
10249 -- we are not creating a body for the accept.
10251 if Present
(Declarations
(Acc_Stm
)) then
10252 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10256 Append_To
(Accept_List
,
10257 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10259 Num_Accept
:= Num_Accept
+ 1;
10262 ----------------------------
10263 -- Make_And_Declare_Label --
10264 ----------------------------
10266 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10270 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10272 Make_Label
(Loc
, Lab_Id
);
10275 Make_Implicit_Label_Declaration
(Loc
,
10276 Defining_Identifier
=>
10277 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10278 Label_Construct
=> Lab
));
10281 end Make_And_Declare_Label
;
10283 ----------------------
10284 -- Make_Select_Call --
10285 ----------------------
10287 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10288 Params
: constant List_Id
:= New_List
;
10292 Make_Attribute_Reference
(Loc
,
10293 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10294 Attribute_Name
=> Name_Unchecked_Access
),
10296 Append
(Select_Mode
, Params
);
10297 Append
(New_Reference_To
(Ann
, Loc
), Params
);
10298 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
10301 Make_Procedure_Call_Statement
(Loc
,
10302 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
10303 Parameter_Associations
=> Params
);
10304 end Make_Select_Call
;
10306 --------------------------------
10307 -- Process_Accept_Alternative --
10308 --------------------------------
10310 procedure Process_Accept_Alternative
10315 Choices
: List_Id
:= No_List
;
10316 Alt_Stats
: List_Id
;
10319 Adjust_Condition
(Condition
(Alt
));
10320 Alt_Stats
:= No_List
;
10322 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10323 Choices
:= New_List
(
10324 Make_Integer_Literal
(Loc
, Index
));
10326 Alt_Stats
:= New_List
(
10327 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10328 Name
=> New_Reference_To
(
10329 Defining_Unit_Name
(Specification
(Proc
)), Sloc
(Proc
))));
10332 if Statements
(Alt
) /= Empty_List
then
10334 if No
(Alt_Stats
) then
10336 -- Accept with no body, followed by trailing statements
10338 Choices
:= New_List
(
10339 Make_Integer_Literal
(Loc
, Index
));
10341 Alt_Stats
:= New_List
;
10344 -- After the call, if any, branch to trailing statements. We
10345 -- create a label for each, as well as the corresponding label
10348 Lab
:= Make_And_Declare_Label
(Index
);
10349 Append_To
(Alt_Stats
,
10350 Make_Goto_Statement
(Loc
,
10351 Name
=> New_Copy
(Identifier
(Lab
))));
10353 Append
(Lab
, Trailing_List
);
10354 Append_List
(Statements
(Alt
), Trailing_List
);
10355 Append_To
(Trailing_List
,
10356 Make_Goto_Statement
(Loc
,
10357 Name
=> New_Copy
(Identifier
(End_Lab
))));
10360 if Present
(Alt_Stats
) then
10362 -- Procedure call. and/or trailing statements
10364 Append_To
(Alt_List
,
10365 Make_Case_Statement_Alternative
(Loc
,
10366 Discrete_Choices
=> Choices
,
10367 Statements
=> Alt_Stats
));
10369 end Process_Accept_Alternative
;
10371 -------------------------------
10372 -- Process_Delay_Alternative --
10373 -------------------------------
10375 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10378 Delay_Alt
: List_Id
;
10381 -- Deal with C/Fortran boolean as delay condition
10383 Adjust_Condition
(Condition
(Alt
));
10385 -- Determine the smallest specified delay
10387 -- for each delay alternative generate:
10389 -- if guard-expression then
10390 -- Delay_Val := delay-expression;
10391 -- Guard_Open := True;
10392 -- if Delay_Val < Delay_Min then
10393 -- Delay_Min := Delay_Val;
10394 -- Delay_Index := Index;
10398 -- The enclosing if-statement is omitted if there is no guard
10401 or else First_Delay
10403 First_Delay
:= False;
10405 Delay_Alt
:= New_List
(
10406 Make_Assignment_Statement
(Loc
,
10407 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10408 Expression
=> Expression
(Delay_Statement
(Alt
))));
10410 if Delay_Count
> 1 then
10411 Append_To
(Delay_Alt
,
10412 Make_Assignment_Statement
(Loc
,
10413 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10414 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10418 Delay_Alt
:= New_List
(
10419 Make_Assignment_Statement
(Loc
,
10420 Name
=> New_Reference_To
(Delay_Val
, Loc
),
10421 Expression
=> Expression
(Delay_Statement
(Alt
))));
10423 if Time_Type
= Standard_Duration
then
10426 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
10427 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
10430 -- The scope of the time type must define a comparison
10431 -- operator. The scope itself may not be visible, so we
10432 -- construct a node with entity information to insure that
10433 -- semantic analysis can find the proper operator.
10436 Make_Function_Call
(Loc
,
10437 Name
=> Make_Selected_Component
(Loc
,
10438 Prefix
=> New_Reference_To
(Scope
(Time_Type
), Loc
),
10440 Make_Operator_Symbol
(Loc
,
10441 Chars
=> Name_Op_Lt
,
10442 Strval
=> No_String
)),
10443 Parameter_Associations
=>
10445 New_Reference_To
(Delay_Val
, Loc
),
10446 New_Reference_To
(Delay_Min
, Loc
)));
10448 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10451 Append_To
(Delay_Alt
,
10452 Make_Implicit_If_Statement
(N
,
10454 Then_Statements
=> New_List
(
10455 Make_Assignment_Statement
(Loc
,
10456 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10457 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
10459 Make_Assignment_Statement
(Loc
,
10460 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10461 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10464 if Check_Guard
then
10465 Append_To
(Delay_Alt
,
10466 Make_Assignment_Statement
(Loc
,
10467 Name
=> New_Reference_To
(Guard_Open
, Loc
),
10468 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
10471 if Present
(Condition
(Alt
)) then
10472 Delay_Alt
:= New_List
(
10473 Make_Implicit_If_Statement
(N
,
10474 Condition
=> Condition
(Alt
),
10475 Then_Statements
=> Delay_Alt
));
10478 Append_List
(Delay_Alt
, Delay_List
);
10480 -- If the delay alternative has a statement part, add choice to the
10481 -- case statements for delays.
10483 if Present
(Statements
(Alt
)) then
10485 if Delay_Count
= 1 then
10486 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10489 Choices
:= New_List
(
10490 Make_Integer_Literal
(Loc
, Index
));
10492 Append_To
(Delay_Alt_List
,
10493 Make_Case_Statement_Alternative
(Loc
,
10494 Discrete_Choices
=> Choices
,
10495 Statements
=> Statements
(Alt
)));
10498 elsif Delay_Count
= 1 then
10500 -- If the single delay has no trailing statements, add a branch
10501 -- to the exit label to the selective wait.
10503 Delay_Alt_List
:= New_List
(
10504 Make_Goto_Statement
(Loc
,
10505 Name
=> New_Copy
(Identifier
(End_Lab
))));
10508 end Process_Delay_Alternative
;
10510 -- Start of processing for Expand_N_Selective_Accept
10513 Process_Statements_For_Controlled_Objects
(N
);
10515 -- First insert some declarations before the select. The first is:
10519 -- This variable holds the parameters passed to the accept body. This
10520 -- declaration has already been inserted by the time we get here by
10521 -- a call to Expand_Accept_Declarations made from the semantics when
10522 -- processing the first accept statement contained in the select. We
10523 -- can find this entity as Accept_Address (E), where E is any of the
10524 -- entries references by contained accept statements.
10526 -- The first step is to scan the list of Selective_Accept_Statements
10527 -- to find this entity, and also count the number of accepts, and
10528 -- determine if terminated, delay or else is present:
10532 Alt
:= First
(Alts
);
10533 while Present
(Alt
) loop
10534 Process_Statements_For_Controlled_Objects
(Alt
);
10536 if Nkind
(Alt
) = N_Accept_Alternative
then
10539 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10540 Delay_Count
:= Delay_Count
+ 1;
10542 -- If the delays are relative delays, the delay expressions have
10543 -- type Standard_Duration. Otherwise they must have some time type
10544 -- recognized by GNAT.
10546 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10547 Time_Type
:= Standard_Duration
;
10549 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10551 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10552 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10557 "& is not a time type (RM 9.6(6))",
10558 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10559 Time_Type
:= Standard_Duration
;
10560 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10564 if No
(Condition
(Alt
)) then
10566 -- This guard will always be open
10568 Check_Guard
:= False;
10571 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10572 Adjust_Condition
(Condition
(Alt
));
10573 Terminate_Alt
:= Alt
;
10576 Num_Alts
:= Num_Alts
+ 1;
10580 Else_Present
:= Present
(Else_Statements
(N
));
10582 -- At the same time (see procedure Add_Accept) we build the accept list:
10584 -- Qnn : Accept_List (1 .. num-select) := (
10585 -- (null-body, entry-index),
10586 -- (null-body, entry-index),
10588 -- (null_body, entry-index));
10590 -- In the above declaration, null-body is True if the corresponding
10591 -- accept has no body, and false otherwise. The entry is either the
10592 -- entry index expression if there is no guard, or if a guard is
10593 -- present, then a conditional expression of the form:
10595 -- (if guard then entry-index else Null_Task_Entry)
10597 -- If a guard is statically known to be false, the entry can simply
10598 -- be omitted from the accept list.
10601 Make_Object_Declaration
(Loc
,
10602 Defining_Identifier
=> Qnam
,
10603 Object_Definition
=>
10604 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10605 Aliased_Present
=> True,
10608 Make_Qualified_Expression
(Loc
,
10610 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10612 Make_Aggregate
(Loc
, Expressions
=> Accept_List
)));
10616 -- Then we declare the variable that holds the index for the accept
10617 -- that will be selected for service:
10619 -- Xnn : Select_Index;
10622 Make_Object_Declaration
(Loc
,
10623 Defining_Identifier
=> Xnam
,
10624 Object_Definition
=>
10625 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
10627 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
10631 -- After this follow procedure declarations for each accept body
10633 -- procedure Pnn is
10638 -- where the ... are statements from the corresponding procedure body.
10639 -- No parameters are involved, since the parameters are passed via Ann
10640 -- and the parameter references have already been expanded to be direct
10641 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10642 -- any embedded tasking statements (which would normally be illegal in
10643 -- procedures), have been converted to calls to the tasking runtime so
10644 -- there is no problem in putting them into procedures.
10646 -- The original accept statement has been expanded into a block in
10647 -- the same fashion as for simple accepts (see Build_Accept_Body).
10649 -- Note: we don't really need to build these procedures for the case
10650 -- where no delay statement is present, but it is just as easy to
10651 -- build them unconditionally, and not significantly inefficient,
10652 -- since if they are short they will be inlined anyway.
10654 -- The procedure declarations have been assembled in Body_List
10656 -- If delays are present, we must compute the required delay.
10657 -- We first generate the declarations:
10659 -- Delay_Index : Boolean := 0;
10660 -- Delay_Min : Some_Time_Type.Time;
10661 -- Delay_Val : Some_Time_Type.Time;
10663 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10664 -- active delay that is actually chosen as the basis for the possible
10665 -- delay if an immediate rendez-vous is not possible.
10667 -- In the most common case there is a single delay statement, and this
10668 -- is handled specially.
10670 if Delay_Count
> 0 then
10672 -- Generate the required declarations
10675 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
10677 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
10679 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
10682 Make_Object_Declaration
(Loc
,
10683 Defining_Identifier
=> Delay_Val
,
10684 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
10687 Make_Object_Declaration
(Loc
,
10688 Defining_Identifier
=> Delay_Index
,
10689 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
10690 Expression
=> Make_Integer_Literal
(Loc
, 0)));
10693 Make_Object_Declaration
(Loc
,
10694 Defining_Identifier
=> Delay_Min
,
10695 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
10697 Unchecked_Convert_To
(Time_Type
,
10698 Make_Attribute_Reference
(Loc
,
10700 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
10701 Attribute_Name
=> Name_Last
))));
10703 -- Create Duration and Delay_Mode objects used for passing a delay
10706 D
:= Make_Temporary
(Loc
, 'D');
10707 M
:= Make_Temporary
(Loc
, 'M');
10713 -- Note that these values are defined in s-osprim.ads and must
10714 -- be kept in sync:
10716 -- Relative : constant := 0;
10717 -- Absolute_Calendar : constant := 1;
10718 -- Absolute_RT : constant := 2;
10720 if Time_Type
= Standard_Duration
then
10721 Discr
:= Make_Integer_Literal
(Loc
, 0);
10723 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10724 Discr
:= Make_Integer_Literal
(Loc
, 1);
10728 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
10729 Discr
:= Make_Integer_Literal
(Loc
, 2);
10733 Make_Object_Declaration
(Loc
,
10734 Defining_Identifier
=> D
,
10735 Object_Definition
=>
10736 New_Reference_To
(Standard_Duration
, Loc
)));
10739 Make_Object_Declaration
(Loc
,
10740 Defining_Identifier
=> M
,
10741 Object_Definition
=>
10742 New_Reference_To
(Standard_Integer
, Loc
),
10743 Expression
=> Discr
));
10746 if Check_Guard
then
10748 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
10751 Make_Object_Declaration
(Loc
,
10752 Defining_Identifier
=> Guard_Open
,
10753 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
10754 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
10757 -- Delay_Count is zero, don't need M and D set (suppress warning)
10764 if Present
(Terminate_Alt
) then
10766 -- If the terminate alternative guard is False, use
10767 -- Simple_Mode; otherwise use Terminate_Mode.
10769 if Present
(Condition
(Terminate_Alt
)) then
10770 Select_Mode
:= Make_Conditional_Expression
(Loc
,
10771 New_List
(Condition
(Terminate_Alt
),
10772 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
10773 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
10775 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
10778 elsif Else_Present
or Delay_Count
> 0 then
10779 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
10782 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
10785 Select_Call
:= Make_Select_Call
(Select_Mode
);
10786 Append
(Select_Call
, Stats
);
10788 -- Now generate code to act on the result. There is an entry
10789 -- in this case for each accept statement with a non-null body,
10790 -- followed by a branch to the statements that follow the Accept.
10791 -- In the absence of delay alternatives, we generate:
10794 -- when No_Rendezvous => -- omitted if simple mode
10809 -- Lab0: Else_Statements;
10812 -- Lab1: Trailing_Statements1;
10815 -- Lab2: Trailing_Statements2;
10820 -- Generate label for common exit
10822 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
10824 -- First entry is the default case, when no rendezvous is possible
10826 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
10828 if Else_Present
then
10830 -- If no rendezvous is possible, the else part is executed
10832 Lab
:= Make_And_Declare_Label
(0);
10833 Alt_Stats
:= New_List
(
10834 Make_Goto_Statement
(Loc
,
10835 Name
=> New_Copy
(Identifier
(Lab
))));
10837 Append
(Lab
, Trailing_List
);
10838 Append_List
(Else_Statements
(N
), Trailing_List
);
10839 Append_To
(Trailing_List
,
10840 Make_Goto_Statement
(Loc
,
10841 Name
=> New_Copy
(Identifier
(End_Lab
))));
10843 Alt_Stats
:= New_List
(
10844 Make_Goto_Statement
(Loc
,
10845 Name
=> New_Copy
(Identifier
(End_Lab
))));
10848 Append_To
(Alt_List
,
10849 Make_Case_Statement_Alternative
(Loc
,
10850 Discrete_Choices
=> Choices
,
10851 Statements
=> Alt_Stats
));
10853 -- We make use of the fact that Accept_Index is an integer type, and
10854 -- generate successive literals for entries for each accept. Only those
10855 -- for which there is a body or trailing statements get a case entry.
10857 Alt
:= First
(Select_Alternatives
(N
));
10858 Proc
:= First
(Body_List
);
10859 while Present
(Alt
) loop
10861 if Nkind
(Alt
) = N_Accept_Alternative
then
10862 Process_Accept_Alternative
(Alt
, Index
, Proc
);
10863 Index
:= Index
+ 1;
10866 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
10871 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10872 Process_Delay_Alternative
(Alt
, Delay_Num
);
10873 Delay_Num
:= Delay_Num
+ 1;
10879 -- An others choice is always added to the main case, as well
10880 -- as the delay case (to satisfy the compiler).
10882 Append_To
(Alt_List
,
10883 Make_Case_Statement_Alternative
(Loc
,
10884 Discrete_Choices
=>
10885 New_List
(Make_Others_Choice
(Loc
)),
10887 New_List
(Make_Goto_Statement
(Loc
,
10888 Name
=> New_Copy
(Identifier
(End_Lab
))))));
10890 Accept_Case
:= New_List
(
10891 Make_Case_Statement
(Loc
,
10892 Expression
=> New_Reference_To
(Xnam
, Loc
),
10893 Alternatives
=> Alt_List
));
10895 Append_List
(Trailing_List
, Accept_Case
);
10896 Append
(End_Lab
, Accept_Case
);
10897 Append_List
(Body_List
, Decls
);
10899 -- Construct case statement for trailing statements of delay
10900 -- alternatives, if there are several of them.
10902 if Delay_Count
> 1 then
10903 Append_To
(Delay_Alt_List
,
10904 Make_Case_Statement_Alternative
(Loc
,
10905 Discrete_Choices
=>
10906 New_List
(Make_Others_Choice
(Loc
)),
10908 New_List
(Make_Null_Statement
(Loc
))));
10910 Delay_Case
:= New_List
(
10911 Make_Case_Statement
(Loc
,
10912 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
10913 Alternatives
=> Delay_Alt_List
));
10915 Delay_Case
:= Delay_Alt_List
;
10918 -- If there are no delay alternatives, we append the case statement
10919 -- to the statement list.
10921 if Delay_Count
= 0 then
10922 Append_List
(Accept_Case
, Stats
);
10924 -- Delay alternatives present
10927 -- If delay alternatives are present we generate:
10929 -- find minimum delay.
10930 -- DX := minimum delay;
10931 -- M := <delay mode>;
10932 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10935 -- if X = No_Rendezvous then
10936 -- case statement for delay statements.
10938 -- case statement for accept alternatives.
10949 -- The type of the delay expression is known to be legal
10951 if Time_Type
= Standard_Duration
then
10952 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
10954 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10955 Conv
:= Make_Function_Call
(Loc
,
10956 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
10957 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
10961 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
10963 Conv
:= Make_Function_Call
(Loc
,
10964 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
10965 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
10968 Stmt
:= Make_Assignment_Statement
(Loc
,
10969 Name
=> New_Reference_To
(D
, Loc
),
10970 Expression
=> Conv
);
10972 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10974 Parms
:= Parameter_Associations
(Select_Call
);
10975 Parm
:= First
(Parms
);
10977 while Present
(Parm
)
10978 and then Parm
/= Select_Mode
10983 pragma Assert
(Present
(Parm
));
10984 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
10987 -- Prepare two new parameters of Duration and Delay_Mode type
10988 -- which represent the value and the mode of the minimum delay.
10991 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
10992 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
10994 -- Create a call to RTS
10996 Rewrite
(Select_Call
,
10997 Make_Procedure_Call_Statement
(Loc
,
10998 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
10999 Parameter_Associations
=> Parms
));
11001 -- This new call should follow the calculation of the minimum
11004 Insert_List_Before
(Select_Call
, Delay_List
);
11006 if Check_Guard
then
11008 Make_Implicit_If_Statement
(N
,
11009 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
11011 New_List
(New_Copy_Tree
(Stmt
),
11012 New_Copy_Tree
(Select_Call
)),
11013 Else_Statements
=> Accept_Or_Raise
);
11014 Rewrite
(Select_Call
, Stmt
);
11016 Insert_Before
(Select_Call
, Stmt
);
11020 Make_Implicit_If_Statement
(N
,
11021 Condition
=> Make_Op_Eq
(Loc
,
11022 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
11024 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
11026 Then_Statements
=> Delay_Case
,
11027 Else_Statements
=> Accept_Case
);
11029 Append
(Cases
, Stats
);
11033 -- Replace accept statement with appropriate block
11036 Make_Block_Statement
(Loc
,
11037 Declarations
=> Decls
,
11038 Handled_Statement_Sequence
=>
11039 Make_Handled_Sequence_Of_Statements
(Loc
,
11040 Statements
=> Stats
));
11042 Rewrite
(N
, Block
);
11045 -- Note: have to worry more about abort deferral in above code ???
11047 -- Final step is to unstack the Accept_Address entries for all accept
11048 -- statements appearing in accept alternatives in the select statement
11050 Alt
:= First
(Alts
);
11051 while Present
(Alt
) loop
11052 if Nkind
(Alt
) = N_Accept_Alternative
then
11053 Remove_Last_Elmt
(Accept_Address
11054 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11059 end Expand_N_Selective_Accept
;
11061 --------------------------------------
11062 -- Expand_N_Single_Task_Declaration --
11063 --------------------------------------
11065 -- Single task declarations should never be present after semantic
11066 -- analysis, since we expect them to be replaced by a declaration of an
11067 -- anonymous task type, followed by a declaration of the task object. We
11068 -- include this routine to make sure that is happening!
11070 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11072 raise Program_Error
;
11073 end Expand_N_Single_Task_Declaration
;
11075 ------------------------
11076 -- Expand_N_Task_Body --
11077 ------------------------
11079 -- Given a task body
11081 -- task body tname is
11087 -- This expansion routine converts it into a procedure and sets the
11088 -- elaboration flag for the procedure to true, to represent the fact
11089 -- that the task body is now elaborated:
11091 -- procedure tnameB (_Task : access tnameV) is
11092 -- discriminal : dtype renames _Task.discriminant;
11094 -- procedure _clean is
11096 -- Abort_Defer.all;
11098 -- Abort_Undefer.all;
11103 -- Abort_Undefer.all;
11105 -- System.Task_Stages.Complete_Activation;
11113 -- In addition, if the task body is an activator, then a call to activate
11114 -- tasks is added at the start of the statements, before the call to
11115 -- Complete_Activation, and if in addition the task is a master then it
11116 -- must be established as a master. These calls are inserted and analyzed
11117 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11120 -- There is one discriminal declaration line generated for each
11121 -- discriminant that is present to provide an easy reference point for
11122 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11124 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11125 -- task body procedures have a profile (Arg : System.Address). That is
11126 -- needed because GNARLI has to use the same access-to-subprogram type
11127 -- for all task types. We depend here on knowing that in GNAT, passing
11128 -- an address argument by value is identical to passing a record value
11129 -- by access (in either case a single pointer is passed), so even though
11130 -- this procedure has the wrong profile. In fact it's all OK, since the
11131 -- callings sequence is identical.
11133 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11134 Loc
: constant Source_Ptr
:= Sloc
(N
);
11135 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11139 Insert_Nod
: Node_Id
;
11140 -- Used to determine the proper location of wrapper body insertions
11143 -- Add renaming declarations for discriminals and a declaration for the
11144 -- entry family index (if applicable).
11146 Install_Private_Data_Declarations
11147 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11149 -- Add a call to Abort_Undefer at the very beginning of the task
11150 -- body since this body is called with abort still deferred.
11152 if Abort_Allowed
then
11153 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11155 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11159 -- The statement part has already been protected with an at_end and
11160 -- cleanup actions. The call to Complete_Activation must be placed
11161 -- at the head of the sequence of statements of that block. The
11162 -- declarations have been merged in this sequence of statements but
11163 -- the first real statement is accessible from the First_Real_Statement
11164 -- field (which was set for exactly this purpose).
11166 if Restricted_Profile
then
11167 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11169 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11173 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11177 Make_Subprogram_Body
(Loc
,
11178 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11179 Declarations
=> Declarations
(N
),
11180 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11182 -- If the task contains generic instantiations, cleanup actions are
11183 -- delayed until after instantiation. Transfer the activation chain to
11184 -- the subprogram, to insure that the activation call is properly
11185 -- generated. It the task body contains inner tasks, indicate that the
11186 -- subprogram is a task master.
11188 if Delay_Cleanups
(Ttyp
) then
11189 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11190 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11193 Rewrite
(N
, New_N
);
11196 -- Set elaboration flag immediately after task body. If the body is a
11197 -- subunit, the flag is set in the declarative part containing the stub.
11199 if Nkind
(Parent
(N
)) /= N_Subunit
then
11201 Make_Assignment_Statement
(Loc
,
11203 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11204 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
11207 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11208 -- the task body. At this point all wrapper specs have been created,
11209 -- frozen and included in the dispatch table for the task type.
11211 if Ada_Version
>= Ada_2005
then
11212 if Nkind
(Parent
(N
)) = N_Subunit
then
11213 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11218 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11220 end Expand_N_Task_Body
;
11222 ------------------------------------
11223 -- Expand_N_Task_Type_Declaration --
11224 ------------------------------------
11226 -- We have several things to do. First we must create a Boolean flag used
11227 -- to mark if the body is elaborated yet. This variable gets set to True
11228 -- when the body of the task is elaborated (we can't rely on the normal
11229 -- ABE mechanism for the task body, since we need to pass an access to
11230 -- this elaboration boolean to the runtime routines).
11232 -- taskE : aliased Boolean := False;
11234 -- Next a variable is declared to hold the task stack size (either the
11235 -- default : Unspecified_Size, or a value that is set by a pragma
11236 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11237 -- the variable is initialized with this value:
11239 -- taskZ : Size_Type := Unspecified_Size;
11241 -- taskZ : Size_Type := Size_Type (size_expression);
11243 -- Note: No variable is needed to hold the task relative deadline since
11244 -- its value would never be static because the parameter is of a private
11245 -- type (Ada.Real_Time.Time_Span).
11247 -- Next we create a corresponding record type declaration used to represent
11248 -- values of this task. The general form of this type declaration is
11250 -- type taskV (discriminants) is record
11251 -- _Task_Id : Task_Id;
11252 -- entry_family : array (bounds) of Void;
11253 -- _Priority : Integer := priority_expression;
11254 -- _Size : Size_Type := size_expression;
11255 -- _Task_Info : Task_Info_Type := task_info_expression;
11256 -- _CPU : Integer := cpu_range_expression;
11257 -- _Relative_Deadline : Time_Span := time_span_expression;
11258 -- _Domain : Dispatching_Domain := dd_expression;
11261 -- The discriminants are present only if the corresponding task type has
11262 -- discriminants, and they exactly mirror the task type discriminants.
11264 -- The Id field is always present. It contains the Task_Id value, as set by
11265 -- the call to Create_Task. Note that although the task is limited, the
11266 -- task value record type is not limited, so there is no problem in passing
11267 -- this field as an out parameter to Create_Task.
11269 -- One entry_family component is present for each entry family in the task
11270 -- definition. The bounds correspond to the bounds of the entry family
11271 -- (which may depend on discriminants). The element type is void, since we
11272 -- only need the bounds information for determining the entry index. Note
11273 -- that the use of an anonymous array would normally be illegal in this
11274 -- context, but this is a parser check, and the semantics is quite prepared
11275 -- to handle such a case.
11277 -- The _Size field is present only if a Storage_Size pragma appears in the
11278 -- task definition. The expression captures the argument that was present
11279 -- in the pragma, and is used to override the task stack size otherwise
11280 -- associated with the task type.
11282 -- The _Priority field is present only if a Priority or Interrupt_Priority
11283 -- pragma appears in the task definition. The expression captures the
11284 -- argument that was present in the pragma, and is used to provide the Size
11285 -- parameter to the call to Create_Task.
11287 -- The _Task_Info field is present only if a Task_Info pragma appears in
11288 -- the task definition. The expression captures the argument that was
11289 -- present in the pragma, and is used to provide the Task_Image parameter
11290 -- to the call to Create_Task.
11292 -- The _CPU field is present only if a CPU pragma appears in the task
11293 -- definition. The expression captures the argument that was present in
11294 -- the pragma, and is used to provide the CPU parameter to the call to
11297 -- The _Relative_Deadline field is present only if a Relative_Deadline
11298 -- pragma appears in the task definition. The expression captures the
11299 -- argument that was present in the pragma, and is used to provide the
11300 -- Relative_Deadline parameter to the call to Create_Task.
11302 -- The _Domain field is present only if a Dispatching_Domain pragma or
11303 -- aspect appears in the task definition. The expression captures the
11304 -- argument that was present in the pragma or aspect, and is used to
11305 -- provide the Dispatching_Domain parameter to the call to Create_Task.
11307 -- When a task is declared, an instance of the task value record is
11308 -- created. The elaboration of this declaration creates the correct bounds
11309 -- for the entry families, and also evaluates the size, priority, and
11310 -- task_Info expressions if needed. The initialization routine for the task
11311 -- type itself then calls Create_Task with appropriate parameters to
11312 -- initialize the value of the Task_Id field.
11314 -- Note: the address of this record is passed as the "Discriminants"
11315 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11316 -- body procedure, it does not matter that it does not quite match the
11317 -- GNARLI model of what is being passed (the record contains more than just
11318 -- the discriminants, but the discriminants can be found from the record
11321 -- The Entity_Id for this created record type is placed in the
11322 -- Corresponding_Record_Type field of the associated task type entity.
11324 -- Next we create a procedure specification for the task body procedure:
11326 -- procedure taskB (_Task : access taskV);
11328 -- Note that this must come after the record type declaration, since
11329 -- the spec refers to this type. It turns out that the initialization
11330 -- procedure for the value type references the task body spec, but that's
11331 -- fine, since it won't be generated till the freeze point for the type,
11332 -- which is certainly after the task body spec declaration.
11334 -- Finally, we set the task index value field of the entry attribute in
11335 -- the case of a simple entry.
11337 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11338 Loc
: constant Source_Ptr
:= Sloc
(N
);
11339 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11340 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11341 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11343 Proc_Spec
: Node_Id
;
11344 Rec_Decl
: Node_Id
;
11345 Rec_Ent
: Entity_Id
;
11347 Elab_Decl
: Node_Id
;
11348 Size_Decl
: Node_Id
;
11349 Body_Decl
: Node_Id
;
11350 Task_Size
: Node_Id
;
11351 Ent_Stack
: Entity_Id
;
11352 Decl_Stack
: Node_Id
;
11355 -- If already expanded, nothing to do
11357 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11361 -- Here we will do the expansion
11363 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11365 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11366 Cdecls
:= Component_Items
(Component_List
11367 (Type_Definition
(Rec_Decl
)));
11369 Qualify_Entity_Names
(N
);
11371 -- First create the elaboration variable
11374 Make_Object_Declaration
(Loc
,
11375 Defining_Identifier
=>
11376 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11377 Chars
=> New_External_Name
(Tasknm
, 'E')),
11378 Aliased_Present
=> True,
11379 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
11380 Expression
=> New_Reference_To
(Standard_False
, Loc
));
11381 Insert_After
(N
, Elab_Decl
);
11383 -- Next create the declaration of the size variable (tasknmZ)
11385 Set_Storage_Size_Variable
(Tasktyp
,
11386 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11387 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11389 if Present
(Taskdef
)
11390 and then Has_Storage_Size_Pragma
(Taskdef
)
11392 Is_Static_Expression
11394 (First
(Pragma_Argument_Associations
11395 (Find_Task_Or_Protected_Pragma
11396 (Taskdef
, Name_Storage_Size
)))))
11399 Make_Object_Declaration
(Loc
,
11400 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11401 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11403 Convert_To
(RTE
(RE_Size_Type
),
11405 (Expression
(First
(Pragma_Argument_Associations
11406 (Find_Task_Or_Protected_Pragma
11407 (Taskdef
, Name_Storage_Size
)))))));
11411 Make_Object_Declaration
(Loc
,
11412 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11413 Object_Definition
=>
11414 New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11416 New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
11419 Insert_After
(Elab_Decl
, Size_Decl
);
11421 -- Next build the rest of the corresponding record declaration. This is
11422 -- done last, since the corresponding record initialization procedure
11423 -- will reference the previously created entities.
11425 -- Fill in the component declarations -- first the _Task_Id field
11428 Make_Component_Declaration
(Loc
,
11429 Defining_Identifier
=>
11430 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11431 Component_Definition
=>
11432 Make_Component_Definition
(Loc
,
11433 Aliased_Present
=> False,
11434 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
11437 -- Declare static ATCB (that is, created by the expander) if we are
11438 -- using the Restricted run time.
11440 if Restricted_Profile
then
11442 Make_Component_Declaration
(Loc
,
11443 Defining_Identifier
=>
11444 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11446 Component_Definition
=>
11447 Make_Component_Definition
(Loc
,
11448 Aliased_Present
=> True,
11449 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11451 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11454 Make_Index_Or_Discriminant_Constraint
(Loc
,
11456 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11460 -- Declare static stack (that is, created by the expander) if we are
11461 -- using the Restricted run time on a bare board configuration.
11463 if Restricted_Profile
11464 and then Preallocated_Stacks_On_Target
11466 -- First we need to extract the appropriate stack size
11468 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11470 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11472 Expr_N
: constant Node_Id
:=
11473 Expression
(First
(
11474 Pragma_Argument_Associations
(
11475 Find_Task_Or_Protected_Pragma
11476 (Taskdef
, Name_Storage_Size
))));
11477 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11478 P
: constant Node_Id
:= Parent
(Expr_N
);
11481 -- The stack is defined inside the corresponding record.
11482 -- Therefore if the size of the stack is set by means of
11483 -- a discriminant, we must reference the discriminant of the
11484 -- corresponding record type.
11486 if Nkind
(Expr_N
) in N_Has_Entity
11487 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11491 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11493 Set_Parent
(Task_Size
, P
);
11494 Set_Etype
(Task_Size
, Etyp
);
11495 Set_Analyzed
(Task_Size
);
11498 Task_Size
:= Relocate_Node
(Expr_N
);
11504 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
11507 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11508 Defining_Identifier
=> Ent_Stack
,
11510 Component_Definition
=>
11511 Make_Component_Definition
(Loc
,
11512 Aliased_Present
=> True,
11513 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11515 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11518 Make_Index_Or_Discriminant_Constraint
(Loc
,
11519 Constraints
=> New_List
(Make_Range
(Loc
,
11520 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11521 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11524 Append_To
(Cdecls
, Decl_Stack
);
11526 -- The appropriate alignment for the stack is ensured by the run-time
11527 -- code in charge of task creation.
11531 -- Add components for entry families
11533 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11535 -- Add the _Priority component if a Priority pragma is present
11537 if Present
(Taskdef
) and then Has_Pragma_Priority
(Taskdef
) then
11539 Prag
: constant Node_Id
:=
11540 Find_Task_Or_Protected_Pragma
(Taskdef
, Name_Priority
);
11544 Expr
:= First
(Pragma_Argument_Associations
(Prag
));
11546 if Nkind
(Expr
) = N_Pragma_Argument_Association
then
11547 Expr
:= Expression
(Expr
);
11550 Expr
:= New_Copy_Tree
(Expr
);
11552 -- Add conversion to proper type to do range check if required
11553 -- Note that for runtime units, we allow out of range interrupt
11554 -- priority values to be used in a priority pragma. This is for
11555 -- the benefit of some versions of System.Interrupts which use
11556 -- a special server task with maximum interrupt priority.
11558 if Pragma_Name
(Prag
) = Name_Priority
11559 and then not GNAT_Mode
11561 Rewrite
(Expr
, Convert_To
(RTE
(RE_Priority
), Expr
));
11563 Rewrite
(Expr
, Convert_To
(RTE
(RE_Any_Priority
), Expr
));
11567 Make_Component_Declaration
(Loc
,
11568 Defining_Identifier
=>
11569 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11570 Component_Definition
=>
11571 Make_Component_Definition
(Loc
,
11572 Aliased_Present
=> False,
11573 Subtype_Indication
=> New_Reference_To
(Standard_Integer
,
11575 Expression
=> Expr
));
11579 -- Add the _Task_Size component if a Storage_Size pragma is present
11581 if Present
(Taskdef
)
11582 and then Has_Storage_Size_Pragma
(Taskdef
)
11585 Make_Component_Declaration
(Loc
,
11586 Defining_Identifier
=>
11587 Make_Defining_Identifier
(Loc
, Name_uSize
),
11589 Component_Definition
=>
11590 Make_Component_Definition
(Loc
,
11591 Aliased_Present
=> False,
11592 Subtype_Indication
=> New_Reference_To
(RTE
(RE_Size_Type
),
11596 Convert_To
(RTE
(RE_Size_Type
),
11598 Expression
(First
(
11599 Pragma_Argument_Associations
(
11600 Find_Task_Or_Protected_Pragma
11601 (Taskdef
, Name_Storage_Size
))))))));
11604 -- Add the _Task_Info component if a Task_Info pragma is present
11606 if Present
(Taskdef
) and then Has_Task_Info_Pragma
(Taskdef
) then
11608 Make_Component_Declaration
(Loc
,
11609 Defining_Identifier
=>
11610 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11612 Component_Definition
=>
11613 Make_Component_Definition
(Loc
,
11614 Aliased_Present
=> False,
11615 Subtype_Indication
=>
11616 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
11618 Expression
=> New_Copy
(
11619 Expression
(First
(
11620 Pragma_Argument_Associations
(
11621 Find_Task_Or_Protected_Pragma
11622 (Taskdef
, Name_Task_Info
)))))));
11625 -- Add the _CPU component if a CPU pragma is present
11627 if Present
(Taskdef
) and then Has_Pragma_CPU
(Taskdef
) then
11629 Make_Component_Declaration
(Loc
,
11630 Defining_Identifier
=>
11631 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11633 Component_Definition
=>
11634 Make_Component_Definition
(Loc
,
11635 Aliased_Present
=> False,
11636 Subtype_Indication
=>
11637 New_Reference_To
(RTE
(RE_CPU_Range
), Loc
)),
11639 Expression
=> New_Copy
(
11640 Expression
(First
(
11641 Pragma_Argument_Associations
(
11642 Find_Task_Or_Protected_Pragma
11643 (Taskdef
, Name_CPU
)))))));
11646 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11647 -- present. If we are using a restricted run time this component will
11648 -- not be added (deadlines are not allowed by the Ravenscar profile).
11650 if not Restricted_Profile
11651 and then Present
(Taskdef
)
11652 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11655 Make_Component_Declaration
(Loc
,
11656 Defining_Identifier
=>
11657 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11659 Component_Definition
=>
11660 Make_Component_Definition
(Loc
,
11661 Aliased_Present
=> False,
11662 Subtype_Indication
=>
11663 New_Reference_To
(RTE
(RE_Time_Span
), Loc
)),
11666 Convert_To
(RTE
(RE_Time_Span
),
11668 Expression
(First
(
11669 Pragma_Argument_Associations
(
11670 Find_Task_Or_Protected_Pragma
11671 (Taskdef
, Name_Relative_Deadline
))))))));
11674 -- Add the _Dispatching_Domain component if a Dispatching_Domain pragma
11675 -- or aspect is present. If we are using a restricted run time this
11676 -- component will not be added (dispatching domains are not allowed by
11677 -- the Ravenscar profile).
11679 if not Restricted_Profile
11680 and then Present
(Taskdef
)
11681 and then Has_Pragma_Dispatching_Domain
(Taskdef
)
11684 Make_Component_Declaration
(Loc
,
11685 Defining_Identifier
=>
11686 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
11688 Component_Definition
=>
11689 Make_Component_Definition
(Loc
,
11690 Aliased_Present
=> False,
11691 Subtype_Indication
=>
11693 (RTE
(RE_Dispatching_Domain_Access
), Loc
)),
11696 Unchecked_Convert_To
(RTE
(RE_Dispatching_Domain_Access
),
11700 (Pragma_Argument_Associations
11701 (Find_Task_Or_Protected_Pragma
11702 (Taskdef
, Name_Dispatching_Domain
))))))));
11705 Insert_After
(Size_Decl
, Rec_Decl
);
11707 -- Analyze the record declaration immediately after construction,
11708 -- because the initialization procedure is needed for single task
11709 -- declarations before the next entity is analyzed.
11711 Analyze
(Rec_Decl
);
11713 -- Create the declaration of the task body procedure
11715 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
11717 Make_Subprogram_Declaration
(Loc
,
11718 Specification
=> Proc_Spec
);
11720 Insert_After
(Rec_Decl
, Body_Decl
);
11722 -- The subprogram does not comes from source, so we have to indicate the
11723 -- need for debugging information explicitly.
11725 if Comes_From_Source
(Original_Node
(N
)) then
11726 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
11729 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11730 -- the corresponding record has been frozen.
11732 if Ada_Version
>= Ada_2005
then
11733 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
11736 -- Ada 2005 (AI-345): We must defer freezing to allow further
11737 -- declaration of primitive subprograms covering task interfaces
11739 if Ada_Version
<= Ada_95
then
11741 -- Now we can freeze the corresponding record. This needs manually
11742 -- freezing, since it is really part of the task type, and the task
11743 -- type is frozen at this stage. We of course need the initialization
11744 -- procedure for this corresponding record type and we won't get it
11745 -- in time if we don't freeze now.
11748 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
11750 if Is_Non_Empty_List
(L
) then
11751 Insert_List_After
(Body_Decl
, L
);
11756 -- Complete the expansion of access types to the current task type, if
11757 -- any were declared.
11759 Expand_Previous_Access_Type
(Tasktyp
);
11761 -- Create wrappers for entries that have pre/postconditions
11767 Ent
:= First_Entity
(Tasktyp
);
11768 while Present
(Ent
) loop
11769 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
11770 and then Present
(Spec_PPC_List
(Contract
(Ent
)))
11772 Build_PPC_Wrapper
(Ent
, N
);
11778 end Expand_N_Task_Type_Declaration
;
11780 -------------------------------
11781 -- Expand_N_Timed_Entry_Call --
11782 -------------------------------
11784 -- A timed entry call in normal case is not implemented using ATC mechanism
11785 -- anymore for efficiency reason.
11795 -- is expanded as follow:
11797 -- 1) When T.E is a task entry_call;
11801 -- X : Task_Entry_Index := <entry index>;
11802 -- DX : Duration := To_Duration (D);
11803 -- M : Delay_Mode := <discriminant>;
11804 -- P : parms := (parm, parm, parm);
11807 -- Timed_Protected_Entry_Call
11808 -- (<acceptor-task>, X, P'Address, DX, M, B);
11816 -- 2) When T.E is a protected entry_call;
11820 -- X : Protected_Entry_Index := <entry index>;
11821 -- DX : Duration := To_Duration (D);
11822 -- M : Delay_Mode := <discriminant>;
11823 -- P : parms := (parm, parm, parm);
11826 -- Timed_Protected_Entry_Call
11827 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
11835 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
11838 -- B : Boolean := False;
11839 -- C : Ada.Tags.Prim_Op_Kind;
11840 -- DX : Duration := To_Duration (D)
11841 -- K : Ada.Tags.Tagged_Kind :=
11842 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
11843 -- M : Integer :=...;
11844 -- P : Parameters := (Param1 .. ParamN);
11848 -- if K = Ada.Tags.TK_Limited_Tagged then
11849 -- <dispatching-call>;
11850 -- <triggering-statements>
11854 -- Ada.Tags.Get_Offset_Index
11855 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
11857 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
11859 -- if C = POK_Protected_Entry
11860 -- or else C = POK_Task_Entry
11862 -- Param1 := P.Param1;
11864 -- ParamN := P.ParamN;
11868 -- if C = POK_Procedure
11869 -- or else C = POK_Protected_Procedure
11870 -- or else C = POK_Task_Procedure
11872 -- <dispatching-call>;
11875 -- <triggering-statements>
11877 -- <timed-statements>
11882 -- The triggering statement and the sequence of timed statements have not
11883 -- been analyzed yet (see Analyzed_Timed_Entry_Call). They may contain
11884 -- local declarations, and therefore the copies that are made during
11885 -- expansion must be disjoint, as for any other inlining.
11887 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
11888 Loc
: constant Source_Ptr
:= Sloc
(N
);
11891 Blk_Typ
: Entity_Id
;
11893 Call_Ent
: Entity_Id
;
11894 Conc_Typ_Stmts
: List_Id
;
11900 D_Type
: Entity_Id
;
11908 Is_Disp_Select
: Boolean;
11909 Lim_Typ_Stmts
: List_Id
;
11918 B
: Entity_Id
; -- Call status flag
11919 C
: Entity_Id
; -- Call kind
11920 D
: Entity_Id
; -- Delay
11921 K
: Entity_Id
; -- Tagged kind
11922 M
: Entity_Id
; -- Delay mode
11923 P
: Entity_Id
; -- Parameter block
11924 S
: Entity_Id
; -- Primitive operation slot
11927 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11928 -- was already reported on spec, so do not attempt to expand the call.
11930 if Restriction_Active
(No_Select_Statements
) then
11934 E_Call
:= Entry_Call_Statement
(Entry_Call_Alternative
(N
));
11935 D_Stat
:= Delay_Statement
(Delay_Alternative
(N
));
11937 Process_Statements_For_Controlled_Objects
(Entry_Call_Alternative
(N
));
11938 Process_Statements_For_Controlled_Objects
(Delay_Alternative
(N
));
11940 -- Retrieve E_Stats and D_Stats now because the finalization machinery
11941 -- may wrap them in blocks.
11943 E_Stats
:= Statements
(Entry_Call_Alternative
(N
));
11944 D_Stats
:= Statements
(Delay_Alternative
(N
));
11946 -- The arguments in the call may require dynamic allocation, and the
11947 -- call statement may have been transformed into a block. The block
11948 -- may contain additional declarations for internal entities, and the
11949 -- original call is found by sequential search.
11951 if Nkind
(E_Call
) = N_Block_Statement
then
11952 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
11953 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
11954 N_Entry_Call_Statement
)
11961 Ada_Version
>= Ada_2005
11962 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
11964 if Is_Disp_Select
then
11965 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
11971 -- B : Boolean := False;
11973 B
:= Build_B
(Loc
, Decls
);
11976 -- C : Ada.Tags.Prim_Op_Kind;
11978 C
:= Build_C
(Loc
, Decls
);
11980 -- Because the analysis of all statements was disabled, manually
11981 -- analyze the delay statement.
11984 D_Stat
:= Original_Node
(D_Stat
);
11987 -- Build an entry call using Simple_Entry_Call
11989 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
11990 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
11992 Decls
:= Declarations
(E_Call
);
11993 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12002 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12005 Make_Object_Declaration
(Loc
,
12006 Defining_Identifier
=> B
,
12007 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
12010 -- Duration and mode processing
12012 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12014 -- Use the type of the delay expression (Calendar or Real_Time) to
12015 -- generate the appropriate conversion.
12017 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12018 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12019 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12021 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12022 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12024 Make_Function_Call
(Loc
,
12025 Name
=> New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
12026 Parameter_Associations
=>
12027 New_List
(New_Copy
(Expression
(D_Stat
))));
12029 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12030 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12032 Make_Function_Call
(Loc
,
12033 Name
=> New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
12034 Parameter_Associations
=>
12035 New_List
(New_Copy
(Expression
(D_Stat
))));
12038 D
:= Make_Temporary
(Loc
, 'D');
12044 Make_Object_Declaration
(Loc
,
12045 Defining_Identifier
=> D
,
12046 Object_Definition
=> New_Reference_To
(Standard_Duration
, Loc
)));
12048 M
:= Make_Temporary
(Loc
, 'M');
12051 -- M : Integer := (0 | 1 | 2);
12054 Make_Object_Declaration
(Loc
,
12055 Defining_Identifier
=> M
,
12056 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
12057 Expression
=> D_Disc
));
12059 -- Do the assignment at this stage only because the evaluation of the
12060 -- expression must not occur before (see ACVC C97302A).
12063 Make_Assignment_Statement
(Loc
,
12064 Name
=> New_Reference_To
(D
, Loc
),
12065 Expression
=> D_Conv
));
12067 -- Parameter block processing
12069 -- Manually create the parameter block for dispatching calls. In the
12070 -- case of entries, the block has already been created during the call
12071 -- to Build_Simple_Entry_Call.
12073 if Is_Disp_Select
then
12075 -- Tagged kind processing, generate:
12076 -- K : Ada.Tags.Tagged_Kind :=
12077 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12079 K
:= Build_K
(Loc
, Decls
, Obj
);
12081 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12083 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12085 -- Dispatch table slot processing, generate:
12088 S
:= Build_S
(Loc
, Decls
);
12091 -- S := Ada.Tags.Get_Offset_Index
12092 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12095 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12098 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12100 -- where Obj is the controlling formal parameter, S is the dispatch
12101 -- table slot number of the dispatching operation, P is the wrapped
12102 -- parameter block, D is the duration, M is the duration mode, C is
12103 -- the call kind and B is the call status.
12105 Params
:= New_List
;
12107 Append_To
(Params
, New_Copy_Tree
(Obj
));
12108 Append_To
(Params
, New_Reference_To
(S
, Loc
));
12110 Make_Attribute_Reference
(Loc
,
12111 Prefix
=> New_Reference_To
(P
, Loc
),
12112 Attribute_Name
=> Name_Address
));
12113 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12114 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12115 Append_To
(Params
, New_Reference_To
(C
, Loc
));
12116 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12118 Append_To
(Conc_Typ_Stmts
,
12119 Make_Procedure_Call_Statement
(Loc
,
12123 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12124 Parameter_Associations
=> Params
));
12127 -- if C = POK_Protected_Entry
12128 -- or else C = POK_Task_Entry
12130 -- Param1 := P.Param1;
12132 -- ParamN := P.ParamN;
12135 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12137 -- Generate the if statement only when the packed parameters need
12138 -- explicit assignments to their corresponding actuals.
12140 if Present
(Unpack
) then
12141 Append_To
(Conc_Typ_Stmts
,
12142 Make_If_Statement
(Loc
,
12148 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12151 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12155 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12157 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
12159 Then_Statements
=> Unpack
));
12165 -- if C = POK_Procedure
12166 -- or else C = POK_Protected_Procedure
12167 -- or else C = POK_Task_Procedure
12169 -- <dispatching-call>
12171 -- <triggering-statements>
12173 -- <timed-statements>
12176 N_Stats
:= Copy_Separate_List
(E_Stats
);
12178 Prepend_To
(N_Stats
,
12179 Make_If_Statement
(Loc
,
12185 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12187 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
12193 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12195 New_Reference_To
(RTE
(
12196 RE_POK_Protected_Procedure
), Loc
)),
12199 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12202 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12204 Then_Statements
=> New_List
(E_Call
)));
12206 Append_To
(Conc_Typ_Stmts
,
12207 Make_If_Statement
(Loc
,
12208 Condition
=> New_Reference_To
(B
, Loc
),
12209 Then_Statements
=> N_Stats
,
12210 Else_Statements
=> D_Stats
));
12213 -- <dispatching-call>;
12214 -- <triggering-statements>
12216 Lim_Typ_Stmts
:= Copy_Separate_List
(E_Stats
);
12217 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(E_Call
));
12220 -- if K = Ada.Tags.TK_Limited_Tagged then
12227 Make_If_Statement
(Loc
,
12230 Left_Opnd
=> New_Reference_To
(K
, Loc
),
12232 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
12233 Then_Statements
=> Lim_Typ_Stmts
,
12234 Else_Statements
=> Conc_Typ_Stmts
));
12237 -- Skip assignments to temporaries created for in-out parameters.
12238 -- This makes unwarranted assumptions about the shape of the expanded
12239 -- tree for the call, and should be cleaned up ???
12241 Stmt
:= First
(Stmts
);
12242 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12246 -- Do the assignment at this stage only because the evaluation
12247 -- of the expression must not occur before (see ACVC C97302A).
12249 Insert_Before
(Stmt
,
12250 Make_Assignment_Statement
(Loc
,
12251 Name
=> New_Reference_To
(D
, Loc
),
12252 Expression
=> D_Conv
));
12255 Params
:= Parameter_Associations
(Call
);
12257 -- For a protected type, we build a Timed_Protected_Entry_Call
12259 if Is_Protected_Type
(Etype
(Concval
)) then
12261 -- Create a new call statement
12263 Param
:= First
(Params
);
12264 while Present
(Param
)
12265 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12270 Dummy
:= Remove_Next
(Next
(Param
));
12272 -- Remove garbage is following the Cancel_Param if present
12274 Dummy
:= Next
(Param
);
12276 -- Remove the mode of the Protected_Entry_Call call, then remove
12277 -- the Communication_Block of the Protected_Entry_Call call, and
12278 -- finally add Duration and a Delay_Mode parameter
12280 pragma Assert
(Present
(Param
));
12281 Rewrite
(Param
, New_Reference_To
(D
, Loc
));
12283 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
12285 -- Add a Boolean flag for successful entry call
12287 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12289 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12290 when System_Tasking_Protected_Objects_Entries
=>
12292 Make_Procedure_Call_Statement
(Loc
,
12295 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12296 Parameter_Associations
=> Params
));
12298 when System_Tasking_Protected_Objects_Single_Entry
=>
12299 Param
:= First
(Params
);
12300 while Present
(Param
)
12302 Is_RTE
(Etype
(Param
), RE_Protected_Entry_Index
)
12310 Make_Procedure_Call_Statement
(Loc
,
12313 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
12314 Parameter_Associations
=> Params
));
12317 raise Program_Error
;
12320 -- For the task case, build a Timed_Task_Entry_Call
12323 -- Create a new call statement
12325 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12326 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12327 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12330 Make_Procedure_Call_Statement
(Loc
,
12332 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12333 Parameter_Associations
=> Params
));
12337 Make_Implicit_If_Statement
(N
,
12338 Condition
=> New_Reference_To
(B
, Loc
),
12339 Then_Statements
=> E_Stats
,
12340 Else_Statements
=> D_Stats
));
12344 Make_Block_Statement
(Loc
,
12345 Declarations
=> Decls
,
12346 Handled_Statement_Sequence
=>
12347 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12350 end Expand_N_Timed_Entry_Call
;
12352 ----------------------------------------
12353 -- Expand_Protected_Body_Declarations --
12354 ----------------------------------------
12356 procedure Expand_Protected_Body_Declarations
12358 Spec_Id
: Entity_Id
)
12361 if No_Run_Time_Mode
then
12362 Error_Msg_CRT
("protected body", N
);
12365 elsif Full_Expander_Active
then
12367 -- Associate discriminals with the first subprogram or entry body to
12370 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12371 Set_Discriminals
(Parent
(Spec_Id
));
12374 end Expand_Protected_Body_Declarations
;
12376 -------------------------
12377 -- External_Subprogram --
12378 -------------------------
12380 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12381 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12384 -- The internal and external subprograms follow each other on the entity
12385 -- chain. Note that previously private operations had no separate
12386 -- external subprogram. We now create one in all cases, because a
12387 -- private operation may actually appear in an external call, through
12388 -- a 'Access reference used for a callback.
12390 -- If the operation is a function that returns an anonymous access type,
12391 -- the corresponding itype appears before the operation, and must be
12394 -- This mechanism is fragile, there should be a real link between the
12395 -- two versions of the operation, but there is no place to put it ???
12397 if Is_Access_Type
(Next_Entity
(Subp
)) then
12398 return Next_Entity
(Next_Entity
(Subp
));
12400 return Next_Entity
(Subp
);
12402 end External_Subprogram
;
12404 ------------------------------
12405 -- Extract_Dispatching_Call --
12406 ------------------------------
12408 procedure Extract_Dispatching_Call
12410 Call_Ent
: out Entity_Id
;
12411 Object
: out Entity_Id
;
12412 Actuals
: out List_Id
;
12413 Formals
: out List_Id
)
12415 Call_Nam
: Node_Id
;
12418 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12420 if Present
(Original_Node
(N
)) then
12421 Call_Nam
:= Name
(Original_Node
(N
));
12423 Call_Nam
:= Name
(N
);
12426 -- Retrieve the name of the dispatching procedure. It contains the
12427 -- dispatch table slot number.
12430 case Nkind
(Call_Nam
) is
12431 when N_Identifier
=>
12434 when N_Selected_Component
=>
12435 Call_Nam
:= Selector_Name
(Call_Nam
);
12438 raise Program_Error
;
12443 Actuals
:= Parameter_Associations
(N
);
12444 Call_Ent
:= Entity
(Call_Nam
);
12445 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12446 Object
:= First
(Actuals
);
12448 if Present
(Original_Node
(Object
)) then
12449 Object
:= Original_Node
(Object
);
12452 -- If the type of the dispatching object is an access type then return
12453 -- an explicit dereference.
12455 if Is_Access_Type
(Etype
(Object
)) then
12456 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12459 end Extract_Dispatching_Call
;
12461 -------------------
12462 -- Extract_Entry --
12463 -------------------
12465 procedure Extract_Entry
12467 Concval
: out Node_Id
;
12468 Ename
: out Node_Id
;
12469 Index
: out Node_Id
)
12471 Nam
: constant Node_Id
:= Name
(N
);
12474 -- For a simple entry, the name is a selected component, with the
12475 -- prefix being the task value, and the selector being the entry.
12477 if Nkind
(Nam
) = N_Selected_Component
then
12478 Concval
:= Prefix
(Nam
);
12479 Ename
:= Selector_Name
(Nam
);
12482 -- For a member of an entry family, the name is an indexed component
12483 -- where the prefix is a selected component, whose prefix in turn is
12484 -- the task value, and whose selector is the entry family. The single
12485 -- expression in the expressions list of the indexed component is the
12486 -- subscript for the family.
12488 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12489 Concval
:= Prefix
(Prefix
(Nam
));
12490 Ename
:= Selector_Name
(Prefix
(Nam
));
12491 Index
:= First
(Expressions
(Nam
));
12495 -------------------
12496 -- Family_Offset --
12497 -------------------
12499 function Family_Offset
12504 Cap
: Boolean) return Node_Id
12510 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12511 -- If one of the bounds is a reference to a discriminant, replace with
12512 -- corresponding discriminal of type. Within the body of a task retrieve
12513 -- the renamed discriminant by simple visibility, using its generated
12514 -- name. Within a protected object, find the original discriminant and
12515 -- replace it with the discriminal of the current protected operation.
12517 ------------------------------
12518 -- Convert_Discriminant_Ref --
12519 ------------------------------
12521 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12522 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12527 if Is_Entity_Name
(Bound
)
12528 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12530 if Is_Task_Type
(Ttyp
)
12531 and then Has_Completion
(Ttyp
)
12533 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12534 Find_Direct_Name
(B
);
12536 elsif Is_Protected_Type
(Ttyp
) then
12537 D
:= First_Discriminant
(Ttyp
);
12538 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12539 Next_Discriminant
(D
);
12542 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
12545 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
12548 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12552 B
:= New_Copy_Tree
(Bound
);
12556 Make_Attribute_Reference
(Loc
,
12557 Attribute_Name
=> Name_Pos
,
12558 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12559 Expressions
=> New_List
(B
));
12560 end Convert_Discriminant_Ref
;
12562 -- Start of processing for Family_Offset
12565 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12566 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12569 if Is_Task_Type
(Ttyp
) then
12570 Ityp
:= RTE
(RE_Task_Entry_Index
);
12572 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12576 Make_Attribute_Reference
(Loc
,
12577 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12578 Attribute_Name
=> Name_Min
,
12579 Expressions
=> New_List
(
12581 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12584 Make_Attribute_Reference
(Loc
,
12585 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12586 Attribute_Name
=> Name_Max
,
12587 Expressions
=> New_List
(
12589 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12592 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12599 function Family_Size
12604 Cap
: Boolean) return Node_Id
12609 if Is_Task_Type
(Ttyp
) then
12610 Ityp
:= RTE
(RE_Task_Entry_Index
);
12612 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12616 Make_Attribute_Reference
(Loc
,
12617 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12618 Attribute_Name
=> Name_Max
,
12619 Expressions
=> New_List
(
12622 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12624 Make_Integer_Literal
(Loc
, 1)),
12625 Make_Integer_Literal
(Loc
, 0)));
12628 ----------------------------
12629 -- Find_Enclosing_Context --
12630 ----------------------------
12632 procedure Find_Enclosing_Context
12634 Context
: out Node_Id
;
12635 Context_Id
: out Entity_Id
;
12636 Context_Decls
: out List_Id
)
12639 -- Traverse the parent chain looking for an enclosing body, block,
12640 -- package or return statement.
12642 Context
:= Parent
(N
);
12643 while not Nkind_In
(Context
, N_Block_Statement
,
12645 N_Extended_Return_Statement
,
12647 N_Package_Declaration
,
12651 Context
:= Parent
(Context
);
12654 -- Extract the constituents of the context
12656 if Nkind
(Context
) = N_Extended_Return_Statement
then
12657 Context_Decls
:= Return_Object_Declarations
(Context
);
12658 Context_Id
:= Return_Statement_Entity
(Context
);
12660 -- Package declarations and bodies use a common library-level activation
12661 -- chain or task master, therefore return the package declaration as the
12662 -- proper carrier for the appropriate flag.
12664 elsif Nkind
(Context
) = N_Package_Body
then
12665 Context_Decls
:= Declarations
(Context
);
12666 Context_Id
:= Corresponding_Spec
(Context
);
12667 Context
:= Parent
(Context_Id
);
12669 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
12670 Context
:= Parent
(Parent
(Context
));
12672 Context
:= Parent
(Context
);
12675 elsif Nkind
(Context
) = N_Package_Declaration
then
12676 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
12677 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12679 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12680 Context_Id
:= Defining_Identifier
(Context_Id
);
12684 Context_Decls
:= Declarations
(Context
);
12686 if Nkind
(Context
) = N_Block_Statement
then
12687 Context_Id
:= Entity
(Identifier
(Context
));
12689 elsif Nkind
(Context
) = N_Entry_Body
then
12690 Context_Id
:= Defining_Identifier
(Context
);
12692 elsif Nkind
(Context
) = N_Subprogram_Body
then
12693 if Present
(Corresponding_Spec
(Context
)) then
12694 Context_Id
:= Corresponding_Spec
(Context
);
12696 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12698 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12699 Context_Id
:= Defining_Identifier
(Context_Id
);
12703 elsif Nkind
(Context
) = N_Task_Body
then
12704 Context_Id
:= Corresponding_Spec
(Context
);
12707 raise Program_Error
;
12711 pragma Assert
(Present
(Context
));
12712 pragma Assert
(Present
(Context_Id
));
12713 pragma Assert
(Present
(Context_Decls
));
12714 end Find_Enclosing_Context
;
12716 -----------------------
12717 -- Find_Master_Scope --
12718 -----------------------
12720 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
12724 -- In Ada 2005, the master is the innermost enclosing scope that is not
12725 -- transient. If the enclosing block is the rewriting of a call or the
12726 -- scope is an extended return statement this is valid master. The
12727 -- master in an extended return is only used within the return, and is
12728 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12729 -- now before that overwriting occurs.
12733 if Ada_Version
>= Ada_2005
then
12734 while Is_Internal
(S
) loop
12735 if Nkind
(Parent
(S
)) = N_Block_Statement
12737 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
12741 elsif Ekind
(S
) = E_Return_Statement
then
12751 end Find_Master_Scope
;
12753 -----------------------------------
12754 -- Find_Task_Or_Protected_Pragma --
12755 -----------------------------------
12757 function Find_Task_Or_Protected_Pragma
12759 P
: Name_Id
) return Node_Id
12764 N
:= First
(Visible_Declarations
(T
));
12765 while Present
(N
) loop
12766 if Nkind
(N
) = N_Pragma
then
12767 if Pragma_Name
(N
) = P
then
12770 elsif P
= Name_Priority
12771 and then Pragma_Name
(N
) = Name_Interrupt_Priority
12784 N
:= First
(Private_Declarations
(T
));
12785 while Present
(N
) loop
12786 if Nkind
(N
) = N_Pragma
then
12787 if Pragma_Name
(N
) = P
then
12790 elsif P
= Name_Priority
12791 and then Pragma_Name
(N
) = Name_Interrupt_Priority
12804 raise Program_Error
;
12805 end Find_Task_Or_Protected_Pragma
;
12807 -------------------------------
12808 -- First_Protected_Operation --
12809 -------------------------------
12811 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
12812 First_Op
: Node_Id
;
12815 First_Op
:= First
(D
);
12816 while Present
(First_Op
)
12817 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
12823 end First_Protected_Operation
;
12825 ---------------------------------------
12826 -- Install_Private_Data_Declarations --
12827 ---------------------------------------
12829 procedure Install_Private_Data_Declarations
12831 Spec_Id
: Entity_Id
;
12832 Conc_Typ
: Entity_Id
;
12833 Body_Nod
: Node_Id
;
12835 Barrier
: Boolean := False;
12836 Family
: Boolean := False)
12838 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
12841 Insert_Node
: Node_Id
:= Empty
;
12842 Obj_Ent
: Entity_Id
;
12844 procedure Add
(Decl
: Node_Id
);
12845 -- Add a single declaration after Insert_Node. If this is the first
12846 -- addition, Decl is added to the front of Decls and it becomes the
12849 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
12850 -- The bounds of an entry index may depend on discriminants, create a
12851 -- reference to the corresponding prival. Otherwise return a duplicate
12852 -- of the original bound.
12858 procedure Add
(Decl
: Node_Id
) is
12860 if No
(Insert_Node
) then
12861 Prepend_To
(Decls
, Decl
);
12863 Insert_After
(Insert_Node
, Decl
);
12866 Insert_Node
:= Decl
;
12869 --------------------------
12870 -- Replace_Discriminant --
12871 --------------------------
12873 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
12875 if Nkind
(Bound
) = N_Identifier
12876 and then Is_Discriminal
(Entity
(Bound
))
12878 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12880 return Duplicate_Subexpr
(Bound
);
12884 -- Start of processing for Install_Private_Data_Declarations
12887 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
12888 -- formal parameter _O, _object or _task depending on the context.
12890 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
12892 -- Special processing of _O for barrier functions, protected entries
12899 (Ekind
(Spec_Id
) = E_Entry
12900 or else Ekind
(Spec_Id
) = E_Entry_Family
))
12903 Conc_Rec
: constant Entity_Id
:=
12904 Corresponding_Record_Type
(Conc_Typ
);
12905 Typ_Id
: constant Entity_Id
:=
12906 Make_Defining_Identifier
(Loc
,
12907 New_External_Name
(Chars
(Conc_Rec
), 'P'));
12910 -- type prot_typVP is access prot_typV;
12913 Make_Full_Type_Declaration
(Loc
,
12914 Defining_Identifier
=> Typ_Id
,
12916 Make_Access_To_Object_Definition
(Loc
,
12917 Subtype_Indication
=>
12918 New_Reference_To
(Conc_Rec
, Loc
)));
12922 -- _object : prot_typVP := prot_typV (_O);
12925 Make_Object_Declaration
(Loc
,
12926 Defining_Identifier
=>
12927 Make_Defining_Identifier
(Loc
, Name_uObject
),
12928 Object_Definition
=> New_Reference_To
(Typ_Id
, Loc
),
12930 Unchecked_Convert_To
(Typ_Id
,
12931 New_Reference_To
(Obj_Ent
, Loc
)));
12934 -- Set the reference to the concurrent object
12936 Obj_Ent
:= Defining_Identifier
(Decl
);
12940 -- Step 2: Create the Protection object and build its declaration for
12941 -- any protected entry (family) of subprogram. Note for the lock-free
12942 -- implementation, the Protection object is not needed anymore.
12944 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
12946 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
12950 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
12952 -- Determine the proper protection type
12954 if Has_Attach_Handler
(Conc_Typ
)
12955 and then not Restricted_Profile
12956 and then not Restriction_Active
(No_Dynamic_Attachment
)
12958 Prot_Typ
:= RE_Static_Interrupt_Protection
;
12960 elsif Has_Interrupt_Handler
(Conc_Typ
)
12961 and then not Restriction_Active
(No_Dynamic_Attachment
)
12963 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
12965 -- The type has explicit entries or generated primitive entry
12968 elsif Has_Entries
(Conc_Typ
)
12970 (Ada_Version
>= Ada_2005
12971 and then Present
(Interface_List
(Parent
(Conc_Typ
))))
12973 case Corresponding_Runtime_Package
(Conc_Typ
) is
12974 when System_Tasking_Protected_Objects_Entries
=>
12975 Prot_Typ
:= RE_Protection_Entries
;
12977 when System_Tasking_Protected_Objects_Single_Entry
=>
12978 Prot_Typ
:= RE_Protection_Entry
;
12981 raise Program_Error
;
12985 Prot_Typ
:= RE_Protection
;
12989 -- conc_typR : protection_typ renames _object._object;
12992 Make_Object_Renaming_Declaration
(Loc
,
12993 Defining_Identifier
=> Prot_Ent
,
12995 New_Reference_To
(RTE
(Prot_Typ
), Loc
),
12997 Make_Selected_Component
(Loc
,
12998 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
12999 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13004 -- Step 3: Add discriminant renamings (if any)
13006 if Has_Discriminants
(Conc_Typ
) then
13011 D
:= First_Discriminant
(Conc_Typ
);
13012 while Present
(D
) loop
13014 -- Adjust the source location
13016 Set_Sloc
(Discriminal
(D
), Loc
);
13019 -- discr_name : discr_typ renames _object.discr_name;
13021 -- discr_name : discr_typ renames _task.discr_name;
13024 Make_Object_Renaming_Declaration
(Loc
,
13025 Defining_Identifier
=> Discriminal
(D
),
13026 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
13028 Make_Selected_Component
(Loc
,
13029 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13030 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13033 Next_Discriminant
(D
);
13038 -- Step 4: Add private component renamings (if any)
13040 if Is_Protected
then
13041 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13043 if Present
(Private_Declarations
(Def
)) then
13046 Comp_Id
: Entity_Id
;
13047 Decl_Id
: Entity_Id
;
13050 Comp
:= First
(Private_Declarations
(Def
));
13051 while Present
(Comp
) loop
13052 if Nkind
(Comp
) = N_Component_Declaration
then
13053 Comp_Id
:= Defining_Identifier
(Comp
);
13055 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13057 -- Minimal decoration
13059 if Ekind
(Spec_Id
) = E_Function
then
13060 Set_Ekind
(Decl_Id
, E_Constant
);
13062 Set_Ekind
(Decl_Id
, E_Variable
);
13065 Set_Prival
(Comp_Id
, Decl_Id
);
13066 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13067 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13070 -- comp_name : comp_typ renames _object.comp_name;
13073 Make_Object_Renaming_Declaration
(Loc
,
13074 Defining_Identifier
=> Decl_Id
,
13076 New_Reference_To
(Etype
(Comp_Id
), Loc
),
13078 Make_Selected_Component
(Loc
,
13080 New_Reference_To
(Obj_Ent
, Loc
),
13082 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13092 -- Step 5: Add the declaration of the entry index and the associated
13093 -- type for barrier functions and entry families.
13095 if (Barrier
and then Family
)
13096 or else Ekind
(Spec_Id
) = E_Entry_Family
13099 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13100 Index
: constant Entity_Id
:=
13101 Defining_Identifier
(
13102 Entry_Index_Specification
(
13103 Entry_Body_Formal_Part
(Body_Nod
)));
13104 Index_Con
: constant Entity_Id
:=
13105 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13107 Index_Typ
: Entity_Id
;
13111 -- Minimal decoration
13113 Set_Ekind
(Index_Con
, E_Constant
);
13114 Set_Entry_Index_Constant
(Index
, Index_Con
);
13115 Set_Discriminal_Link
(Index_Con
, Index
);
13117 -- Retrieve the bounds of the entry family
13119 High
:= Type_High_Bound
(Etype
(Index
));
13120 Low
:= Type_Low_Bound
(Etype
(Index
));
13122 -- In the simple case the entry family is given by a subtype
13123 -- mark and the index constant has the same type.
13125 if Is_Entity_Name
(Original_Node
(
13126 Discrete_Subtype_Definition
(Parent
(Index
))))
13128 Index_Typ
:= Etype
(Index
);
13130 -- Otherwise a new subtype declaration is required
13133 High
:= Replace_Bound
(High
);
13134 Low
:= Replace_Bound
(Low
);
13136 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13139 -- subtype Jnn is <Etype of Index> range Low .. High;
13142 Make_Subtype_Declaration
(Loc
,
13143 Defining_Identifier
=> Index_Typ
,
13144 Subtype_Indication
=>
13145 Make_Subtype_Indication
(Loc
,
13147 New_Reference_To
(Base_Type
(Etype
(Index
)), Loc
),
13149 Make_Range_Constraint
(Loc
,
13150 Range_Expression
=>
13151 Make_Range
(Loc
, Low
, High
))));
13155 Set_Etype
(Index_Con
, Index_Typ
);
13157 -- Create the object which designates the index:
13158 -- J : constant Jnn :=
13159 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13161 -- where Jnn is the subtype created above or the original type of
13162 -- the index, _E is a formal of the protected body subprogram and
13163 -- <index expr> is the index of the first family member.
13166 Make_Object_Declaration
(Loc
,
13167 Defining_Identifier
=> Index_Con
,
13168 Constant_Present
=> True,
13169 Object_Definition
=>
13170 New_Reference_To
(Index_Typ
, Loc
),
13173 Make_Attribute_Reference
(Loc
,
13175 New_Reference_To
(Index_Typ
, Loc
),
13176 Attribute_Name
=> Name_Val
,
13178 Expressions
=> New_List
(
13182 Make_Op_Subtract
(Loc
,
13184 New_Reference_To
(E
, Loc
),
13186 Entry_Index_Expression
(Loc
,
13187 Defining_Identifier
(Body_Nod
),
13191 Make_Attribute_Reference
(Loc
,
13193 New_Reference_To
(Index_Typ
, Loc
),
13194 Attribute_Name
=> Name_Pos
,
13195 Expressions
=> New_List
(
13196 Make_Attribute_Reference
(Loc
,
13198 New_Reference_To
(Index_Typ
, Loc
),
13199 Attribute_Name
=> Name_First
)))))));
13203 end Install_Private_Data_Declarations
;
13205 -----------------------
13206 -- Is_Exception_Safe --
13207 -----------------------
13209 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
13211 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
13212 -- Return True whenever encountering a subprogram call or raise
13213 -- statement of any kind in the sequence of statements
13215 ---------------------
13216 -- Has_Side_Effect --
13217 ---------------------
13219 -- What is this doing buried two levels down in exp_ch9. It seems like a
13220 -- generally useful function, and indeed there may be code duplication
13221 -- going on here ???
13223 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
13227 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
13228 -- Indicate whether N is a subprogram call or a raise statement
13230 ----------------------
13231 -- Is_Call_Or_Raise --
13232 ----------------------
13234 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
13236 return Nkind_In
(N
, N_Procedure_Call_Statement
,
13239 N_Raise_Constraint_Error
,
13240 N_Raise_Program_Error
,
13241 N_Raise_Storage_Error
);
13242 end Is_Call_Or_Raise
;
13244 -- Start of processing for Has_Side_Effect
13248 while Present
(Stmt
) loop
13249 if Is_Call_Or_Raise
(Stmt
) then
13253 -- An object declaration can also contain a function call or a
13254 -- raise statement.
13256 if Nkind
(Stmt
) = N_Object_Declaration
then
13257 Expr
:= Expression
(Stmt
);
13259 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
13268 end Has_Side_Effect
;
13270 -- Start of processing for Is_Exception_Safe
13273 -- If the checks handled by the back end are not disabled, we cannot
13274 -- ensure that no exception will be raised.
13276 if not Access_Checks_Suppressed
(Empty
)
13277 or else not Discriminant_Checks_Suppressed
(Empty
)
13278 or else not Range_Checks_Suppressed
(Empty
)
13279 or else not Index_Checks_Suppressed
(Empty
)
13280 or else Opt
.Stack_Checking_Enabled
13285 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
13288 (First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
13294 end Is_Exception_Safe
;
13296 ---------------------------------
13297 -- Is_Potentially_Large_Family --
13298 ---------------------------------
13300 function Is_Potentially_Large_Family
13301 (Base_Index
: Entity_Id
;
13302 Conctyp
: Entity_Id
;
13304 Hi
: Node_Id
) return Boolean
13307 return Scope
(Base_Index
) = Standard_Standard
13308 and then Base_Index
= Base_Type
(Standard_Integer
)
13309 and then Has_Discriminants
(Conctyp
)
13311 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13313 (Denotes_Discriminant
(Lo
, True)
13315 Denotes_Discriminant
(Hi
, True));
13316 end Is_Potentially_Large_Family
;
13318 -------------------------------------
13319 -- Is_Private_Primitive_Subprogram --
13320 -------------------------------------
13322 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13325 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13326 and then Is_Private_Primitive
(Id
);
13327 end Is_Private_Primitive_Subprogram
;
13333 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13334 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13335 Formal
: Entity_Id
;
13338 Formal
:= First_Formal
(Bod_Subp
);
13339 while Present
(Formal
) loop
13341 -- Look for formal parameter _E
13343 if Chars
(Formal
) = Name_uE
then
13347 Next_Formal
(Formal
);
13350 -- A protected body subprogram should always have the parameter in
13353 raise Program_Error
;
13356 --------------------------------
13357 -- Make_Initialize_Protection --
13358 --------------------------------
13360 function Make_Initialize_Protection
13361 (Protect_Rec
: Entity_Id
) return List_Id
13363 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13367 Ptyp
: constant Node_Id
:=
13368 Corresponding_Concurrent_Type
(Protect_Rec
);
13370 L
: constant List_Id
:= New_List
;
13371 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13372 Restricted
: constant Boolean := Restricted_Profile
;
13375 -- We may need two calls to properly initialize the object, one to
13376 -- Initialize_Protection, and possibly one to Install_Handlers if we
13377 -- have a pragma Attach_Handler.
13379 -- Get protected declaration. In the case of a task type declaration,
13380 -- this is simply the parent of the protected type entity. In the single
13381 -- protected object declaration, this parent will be the implicit type,
13382 -- and we can find the corresponding single protected object declaration
13383 -- by searching forward in the declaration list in the tree.
13385 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13386 -- of this type should have been removed during semantic analysis.
13388 Pdec
:= Parent
(Ptyp
);
13389 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13390 N_Single_Protected_Declaration
)
13395 -- Now we can find the object definition from this declaration
13397 Pdef
:= Protected_Definition
(Pdec
);
13399 -- Build the parameter list for the call. Note that _Init is the name
13400 -- of the formal for the object to be initialized, which is the task
13401 -- value record itself.
13405 -- For lock-free implementation, skip initializations of the Protection
13408 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13409 -- Object parameter. This is a pointer to the object of type
13410 -- Protection used by the GNARL to control the protected object.
13413 Make_Attribute_Reference
(Loc
,
13415 Make_Selected_Component
(Loc
,
13416 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13417 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13418 Attribute_Name
=> Name_Unchecked_Access
));
13420 -- Priority parameter. Set to Unspecified_Priority unless there is a
13421 -- priority pragma, in which case we take the value from the pragma,
13422 -- or there is an interrupt pragma and no priority pragma, and we
13423 -- set the ceiling to Interrupt_Priority'Last, an implementation-
13424 -- defined value, see D.3(10).
13427 and then Has_Pragma_Priority
(Pdef
)
13430 Prio
: constant Node_Id
:=
13433 (Pragma_Argument_Associations
13434 (Find_Task_Or_Protected_Pragma
13435 (Pdef
, Name_Priority
))));
13439 -- If priority is a static expression, then we can duplicate it
13440 -- with no problem and simply append it to the argument list.
13442 if Is_Static_Expression
(Prio
) then
13444 Duplicate_Subexpr_No_Checks
(Prio
));
13446 -- Otherwise, the priority may be a per-object expression, if
13447 -- it depends on a discriminant of the type. In this case,
13448 -- create local variable to capture the expression. Note that
13449 -- it is really necessary to create this variable explicitly.
13450 -- It might be thought that removing side effects would the
13451 -- appropriate approach, but that could generate declarations
13452 -- improperly placed in the enclosing scope.
13454 -- Note: Use System.Any_Priority as the expected type for the
13455 -- non-static priority expression, in case the expression has
13456 -- not been analyzed yet (as occurs for example with pragma
13457 -- Interrupt_Priority).
13460 Temp
:= Make_Temporary
(Loc
, 'R', Prio
);
13462 Make_Object_Declaration
(Loc
,
13463 Defining_Identifier
=> Temp
,
13464 Object_Definition
=>
13465 New_Occurrence_Of
(RTE
(RE_Any_Priority
), Loc
),
13466 Expression
=> Relocate_Node
(Prio
)));
13468 Append_To
(Args
, New_Occurrence_Of
(Temp
, Loc
));
13472 -- When no priority is specified but an xx_Handler pragma is, we
13473 -- default to System.Interrupts.Default_Interrupt_Priority, see
13476 elsif Has_Attach_Handler
(Ptyp
)
13477 or else Has_Interrupt_Handler
(Ptyp
)
13480 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13482 -- Normal case, no priority or xx_Handler specified, default priority
13486 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13489 -- Test for Compiler_Info parameter. This parameter allows entry body
13490 -- procedures and barrier functions to be called from the runtime. It
13491 -- is a pointer to the record generated by the compiler to represent
13492 -- the protected object.
13494 -- A protected type without entries that covers an interface and
13495 -- overrides the abstract routines with protected procedures is
13496 -- considered equivalent to a protected type with entries in the
13497 -- context of dispatching select statements.
13500 or else Has_Interfaces
(Protect_Rec
)
13502 ((Has_Attach_Handler
(Ptyp
) or else Has_Interrupt_Handler
(Ptyp
))
13503 and then not Restriction_Active
(No_Dynamic_Attachment
))
13506 Pkg_Id
: constant RTU_Id
:=
13507 Corresponding_Runtime_Package
(Ptyp
);
13509 Called_Subp
: RE_Id
;
13513 when System_Tasking_Protected_Objects_Entries
=>
13514 Called_Subp
:= RE_Initialize_Protection_Entries
;
13516 when System_Tasking_Protected_Objects
=>
13517 Called_Subp
:= RE_Initialize_Protection
;
13519 when System_Tasking_Protected_Objects_Single_Entry
=>
13520 Called_Subp
:= RE_Initialize_Protection_Entry
;
13523 raise Program_Error
;
13527 or else not Restricted
13528 or else Has_Interfaces
(Protect_Rec
)
13531 Make_Attribute_Reference
(Loc
,
13532 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13533 Attribute_Name
=> Name_Address
));
13536 -- Entry_Bodies parameter. This is a pointer to an array of
13537 -- pointers to the entry body procedures and barrier functions
13538 -- of the object. If the protected type has no entries this
13539 -- object will not exist, in this case, pass a null.
13542 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13545 Make_Attribute_Reference
(Loc
,
13546 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13547 Attribute_Name
=> Name_Unrestricted_Access
));
13549 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13551 -- Find index mapping function (clumsy but ok for now)
13553 while Ekind
(P_Arr
) /= E_Function
loop
13554 Next_Entity
(P_Arr
);
13558 Make_Attribute_Reference
(Loc
,
13559 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13560 Attribute_Name
=> Name_Unrestricted_Access
));
13562 -- Build_Entry_Names generation flag. When set to true,
13563 -- the runtime will allocate an array to hold the string
13564 -- names of protected entries.
13566 if not Restricted_Profile
then
13567 if Entry_Names_OK
then
13569 New_Reference_To
(Standard_True
, Loc
));
13572 New_Reference_To
(Standard_False
, Loc
));
13578 System_Tasking_Protected_Objects_Single_Entry
13580 Append_To
(Args
, Make_Null
(Loc
));
13582 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13583 Append_To
(Args
, Make_Null
(Loc
));
13584 Append_To
(Args
, Make_Null
(Loc
));
13585 Append_To
(Args
, New_Reference_To
(Standard_False
, Loc
));
13589 Make_Procedure_Call_Statement
(Loc
,
13590 Name
=> New_Reference_To
(RTE
(Called_Subp
), Loc
),
13591 Parameter_Associations
=> Args
));
13595 Make_Procedure_Call_Statement
(Loc
,
13596 Name
=> New_Reference_To
(RTE
(RE_Initialize_Protection
), Loc
),
13597 Parameter_Associations
=> Args
));
13601 if Has_Attach_Handler
(Ptyp
) then
13603 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13604 -- make the following call:
13606 -- Install_Handlers (_object,
13607 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13609 -- or, in the case of Ravenscar:
13611 -- Install_Restricted_Handlers
13612 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13615 Args
: constant List_Id
:= New_List
;
13616 Table
: constant List_Id
:= New_List
;
13617 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13620 -- Build the Attach_Handler table argument
13622 while Present
(Ritem
) loop
13623 if Nkind
(Ritem
) = N_Pragma
13624 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13627 Handler
: constant Node_Id
:=
13628 First
(Pragma_Argument_Associations
(Ritem
));
13630 Interrupt
: constant Node_Id
:= Next
(Handler
);
13631 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13635 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13636 Unchecked_Convert_To
13637 (RTE
(RE_System_Interrupt_Id
), Expr
),
13638 Make_Attribute_Reference
(Loc
,
13639 Prefix
=> Make_Selected_Component
(Loc
,
13640 Make_Identifier
(Loc
, Name_uInit
),
13641 Duplicate_Subexpr_No_Checks
13642 (Expression
(Handler
))),
13643 Attribute_Name
=> Name_Access
))));
13647 Next_Rep_Item
(Ritem
);
13650 -- Append the table argument we just built
13652 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13654 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13655 -- call to the statements.
13658 -- Call a simplified version of Install_Handlers to be used
13659 -- when the Ravenscar restrictions are in effect
13660 -- (Install_Restricted_Handlers).
13663 Make_Procedure_Call_Statement
(Loc
,
13666 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13667 Parameter_Associations
=> Args
));
13670 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13671 -- First, prepends the _object argument
13674 Make_Attribute_Reference
(Loc
,
13676 Make_Selected_Component
(Loc
,
13677 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13679 Make_Identifier
(Loc
, Name_uObject
)),
13680 Attribute_Name
=> Name_Unchecked_Access
));
13683 -- Then, insert call to Install_Handlers
13686 Make_Procedure_Call_Statement
(Loc
,
13687 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
13688 Parameter_Associations
=> Args
));
13694 end Make_Initialize_Protection
;
13696 ---------------------------
13697 -- Make_Task_Create_Call --
13698 ---------------------------
13700 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
13701 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
13711 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
13712 Tnam
:= Chars
(Ttyp
);
13714 -- Get task declaration. In the case of a task type declaration, this is
13715 -- simply the parent of the task type entity. In the single task
13716 -- declaration, this parent will be the implicit type, and we can find
13717 -- the corresponding single task declaration by searching forward in the
13718 -- declaration list in the tree.
13720 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13721 -- this type should have been removed during semantic analysis.
13723 Tdec
:= Parent
(Ttyp
);
13724 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
13725 N_Single_Task_Declaration
)
13730 -- Now we can find the task definition from this declaration
13732 Tdef
:= Task_Definition
(Tdec
);
13734 -- Build the parameter list for the call. Note that _Init is the name
13735 -- of the formal for the object to be initialized, which is the task
13736 -- value record itself.
13740 -- Priority parameter. Set to Unspecified_Priority unless there is a
13741 -- priority pragma, in which case we take the value from the pragma.
13743 if Present
(Tdef
) and then Has_Pragma_Priority
(Tdef
) then
13745 Make_Selected_Component
(Loc
,
13746 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13747 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
13750 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13753 -- Optional Stack parameter
13755 if Restricted_Profile
then
13757 -- If the stack has been preallocated by the expander then
13758 -- pass its address. Otherwise, pass a null address.
13760 if Preallocated_Stacks_On_Target
then
13762 Make_Attribute_Reference
(Loc
,
13764 Make_Selected_Component
(Loc
,
13765 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13766 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
13767 Attribute_Name
=> Name_Address
));
13771 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
13775 -- Size parameter. If no Storage_Size pragma is present, then
13776 -- the size is taken from the taskZ variable for the type, which
13777 -- is either Unspecified_Size, or has been reset by the use of
13778 -- a Storage_Size attribute definition clause. If a pragma is
13779 -- present, then the size is taken from the _Size field of the
13780 -- task value record, which was set from the pragma value.
13783 and then Has_Storage_Size_Pragma
(Tdef
)
13786 Make_Selected_Component
(Loc
,
13787 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13788 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
13792 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
13795 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
13796 -- Task_Info pragma, in which case we take the value from the pragma.
13799 and then Has_Task_Info_Pragma
(Tdef
)
13802 Make_Selected_Component
(Loc
,
13803 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13804 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
13808 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
13811 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
13812 -- in which case we take the value from the pragma. The parameter is
13813 -- passed as an Integer because in the case of unspecified CPU the
13814 -- value is not in the range of CPU_Range.
13816 if Present
(Tdef
) and then Has_Pragma_CPU
(Tdef
) then
13818 Convert_To
(Standard_Integer
,
13819 Make_Selected_Component
(Loc
,
13820 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13821 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
13825 New_Reference_To
(RTE
(RE_Unspecified_CPU
), Loc
));
13828 if not Restricted_Profile
then
13830 -- Deadline parameter. If no Relative_Deadline pragma is present,
13831 -- then the deadline is Time_Span_Zero. If a pragma is present, then
13832 -- the deadline is taken from the _Relative_Deadline field of the
13833 -- task value record, which was set from the pragma value. Note that
13834 -- this parameter must not be generated for the restricted profiles
13835 -- since Ravenscar does not allow deadlines.
13837 -- Case where pragma Relative_Deadline applies: use given value
13839 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
13841 Make_Selected_Component
(Loc
,
13843 Make_Identifier
(Loc
, Name_uInit
),
13845 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
13847 -- No pragma Relative_Deadline apply to the task
13851 New_Reference_To
(RTE
(RE_Time_Span_Zero
), Loc
));
13854 -- Dispatching_Domain parameter. If no Dispatching_Domain pragma or
13855 -- aspect is present, then the dispatching domain is null. If a
13856 -- pragma or aspect is present, then the dispatching domain is taken
13857 -- from the _Dispatching_Domain field of the task value record,
13858 -- which was set from the pragma value. Note that this parameter
13859 -- must not be generated for the restricted profiles since Ravenscar
13860 -- does not allow dispatching domains.
13862 -- Case where pragma or aspect Dispatching_Domain applies: use given
13865 if Present
(Tdef
) and then Has_Pragma_Dispatching_Domain
(Tdef
) then
13867 Make_Selected_Component
(Loc
,
13869 Make_Identifier
(Loc
, Name_uInit
),
13871 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
13873 -- No pragma or aspect Dispatching_Domain apply to the task
13876 Append_To
(Args
, Make_Null
(Loc
));
13879 -- Number of entries. This is an expression of the form:
13881 -- n + _Init.a'Length + _Init.a'B'Length + ...
13883 -- where a,b... are the entry family names for the task definition
13886 Build_Entry_Count_Expression
13891 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
13893 Append_To
(Args
, Ecount
);
13895 -- Master parameter. This is a reference to the _Master parameter of
13896 -- the initialization procedure, except in the case of the pragma
13897 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
13898 -- System.Tasking.Library_Task_Level.
13900 if Restriction_Active
(No_Task_Hierarchy
) = False then
13901 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
13904 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
13908 -- State parameter. This is a pointer to the task body procedure. The
13909 -- required value is obtained by taking 'Unrestricted_Access of the task
13910 -- body procedure and converting it (with an unchecked conversion) to
13911 -- the type required by the task kernel. For further details, see the
13912 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
13913 -- than 'Address in order to avoid creating trampolines.
13916 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
13917 Subp_Ptr_Typ
: constant Node_Id
:=
13918 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
13919 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
13922 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
13923 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
13925 -- Be sure to freeze a reference to the access-to-subprogram type,
13926 -- otherwise gigi will complain that it's in the wrong scope, because
13927 -- it's actually inside the init procedure for the record type that
13928 -- corresponds to the task type.
13930 -- This processing is causing a crash in the .NET/JVM back ends that
13931 -- is not yet understood, so skip it in these cases ???
13933 if VM_Target
= No_VM
then
13934 Set_Itype
(Ref
, Subp_Ptr_Typ
);
13935 Append_Freeze_Action
(Task_Rec
, Ref
);
13938 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
13939 Make_Qualified_Expression
(Loc
,
13940 Subtype_Mark
=> New_Reference_To
(Subp_Ptr_Typ
, Loc
),
13942 Make_Attribute_Reference
(Loc
,
13944 New_Occurrence_Of
(Body_Proc
, Loc
),
13945 Attribute_Name
=> Name_Unrestricted_Access
))));
13947 -- For the .NET/JVM cases revert to the original code below ???
13951 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
13952 Make_Attribute_Reference
(Loc
,
13954 New_Occurrence_Of
(Body_Proc
, Loc
),
13955 Attribute_Name
=> Name_Address
)));
13959 -- Discriminants parameter. This is just the address of the task
13960 -- value record itself (which contains the discriminant values
13963 Make_Attribute_Reference
(Loc
,
13964 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13965 Attribute_Name
=> Name_Address
));
13967 -- Elaborated parameter. This is an access to the elaboration Boolean
13970 Make_Attribute_Reference
(Loc
,
13971 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
13972 Attribute_Name
=> Name_Unchecked_Access
));
13974 -- Chain parameter. This is a reference to the _Chain parameter of
13975 -- the initialization procedure.
13977 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
13979 -- Task name parameter. Take this from the _Task_Id parameter to the
13980 -- init call unless there is a Task_Name pragma, in which case we take
13981 -- the value from the pragma.
13984 and then Has_Task_Name_Pragma
(Tdef
)
13986 -- Copy expression in full, because it may be dynamic and have
13992 (Pragma_Argument_Associations
13993 (Find_Task_Or_Protected_Pragma
13994 (Tdef
, Name_Task_Name
))))));
13997 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14000 -- Created_Task parameter. This is the _Task_Id field of the task
14004 Make_Selected_Component
(Loc
,
14005 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14006 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14008 -- Build_Entry_Names generation flag. When set to true, the runtime
14009 -- will allocate an array to hold the string names of task entries.
14011 if not Restricted_Profile
then
14012 if Has_Entries
(Ttyp
)
14013 and then Entry_Names_OK
14015 Append_To
(Args
, New_Reference_To
(Standard_True
, Loc
));
14017 Append_To
(Args
, New_Reference_To
(Standard_False
, Loc
));
14021 if Restricted_Profile
then
14022 Name
:= New_Reference_To
(RTE
(RE_Create_Restricted_Task
), Loc
);
14024 Name
:= New_Reference_To
(RTE
(RE_Create_Task
), Loc
);
14028 Make_Procedure_Call_Statement
(Loc
,
14030 Parameter_Associations
=> Args
);
14031 end Make_Task_Create_Call
;
14033 ------------------------------
14034 -- Next_Protected_Operation --
14035 ------------------------------
14037 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14041 Next_Op
:= Next
(N
);
14042 while Present
(Next_Op
)
14043 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
14049 end Next_Protected_Operation
;
14051 ---------------------
14052 -- Null_Statements --
14053 ---------------------
14055 function Null_Statements
(Stats
: List_Id
) return Boolean is
14059 Stmt
:= First
(Stats
);
14060 while Nkind
(Stmt
) /= N_Empty
14061 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14063 (Nkind
(Stmt
) = N_Pragma
14064 and then (Pragma_Name
(Stmt
) = Name_Unreferenced
14066 Pragma_Name
(Stmt
) = Name_Unmodified
14068 Pragma_Name
(Stmt
) = Name_Warnings
)))
14073 return Nkind
(Stmt
) = N_Empty
;
14074 end Null_Statements
;
14076 --------------------------
14077 -- Parameter_Block_Pack --
14078 --------------------------
14080 function Parameter_Block_Pack
14082 Blk_Typ
: Entity_Id
;
14086 Stmts
: List_Id
) return Node_Id
14088 Actual
: Entity_Id
;
14089 Expr
: Node_Id
:= Empty
;
14090 Formal
: Entity_Id
;
14091 Has_Param
: Boolean := False;
14094 Temp_Asn
: Node_Id
;
14095 Temp_Nam
: Node_Id
;
14098 Actual
:= First
(Actuals
);
14099 Formal
:= Defining_Identifier
(First
(Formals
));
14100 Params
:= New_List
;
14102 while Present
(Actual
) loop
14103 if Is_By_Copy_Type
(Etype
(Actual
)) then
14105 -- Jnn : aliased <formal-type>
14107 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14110 Make_Object_Declaration
(Loc
,
14113 Defining_Identifier
=>
14115 Object_Definition
=>
14116 New_Reference_To
(Etype
(Formal
), Loc
)));
14118 if Ekind
(Formal
) /= E_Out_Parameter
then
14124 New_Reference_To
(Temp_Nam
, Loc
);
14126 Set_Assignment_OK
(Temp_Asn
);
14129 Make_Assignment_Statement
(Loc
,
14133 New_Copy_Tree
(Actual
)));
14137 -- Jnn'unchecked_access
14140 Make_Attribute_Reference
(Loc
,
14142 Name_Unchecked_Access
,
14144 New_Reference_To
(Temp_Nam
, Loc
)));
14148 -- The controlling parameter is omitted
14151 if not Is_Controlling_Actual
(Actual
) then
14153 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14159 Next_Actual
(Actual
);
14160 Next_Formal_With_Extras
(Formal
);
14164 Expr
:= Make_Aggregate
(Loc
, Params
);
14169 -- J1'unchecked_access;
14170 -- <actual2>'reference;
14173 P
:= Make_Temporary
(Loc
, 'P');
14176 Make_Object_Declaration
(Loc
,
14177 Defining_Identifier
=>
14179 Object_Definition
=>
14180 New_Reference_To
(Blk_Typ
, Loc
),
14185 end Parameter_Block_Pack
;
14187 ----------------------------
14188 -- Parameter_Block_Unpack --
14189 ----------------------------
14191 function Parameter_Block_Unpack
14195 Formals
: List_Id
) return List_Id
14197 Actual
: Entity_Id
;
14199 Formal
: Entity_Id
;
14200 Has_Asnmt
: Boolean := False;
14201 Result
: constant List_Id
:= New_List
;
14204 Actual
:= First
(Actuals
);
14205 Formal
:= Defining_Identifier
(First
(Formals
));
14206 while Present
(Actual
) loop
14207 if Is_By_Copy_Type
(Etype
(Actual
))
14208 and then Ekind
(Formal
) /= E_In_Parameter
14211 -- <actual> := P.<formal>;
14214 Make_Assignment_Statement
(Loc
,
14218 Make_Explicit_Dereference
(Loc
,
14219 Make_Selected_Component
(Loc
,
14221 New_Reference_To
(P
, Loc
),
14223 Make_Identifier
(Loc
, Chars
(Formal
)))));
14225 Set_Assignment_OK
(Name
(Asnmt
));
14226 Append_To
(Result
, Asnmt
);
14231 Next_Actual
(Actual
);
14232 Next_Formal_With_Extras
(Formal
);
14238 return New_List
(Make_Null_Statement
(Loc
));
14240 end Parameter_Block_Unpack
;
14242 ----------------------
14243 -- Set_Discriminals --
14244 ----------------------
14246 procedure Set_Discriminals
(Dec
: Node_Id
) is
14249 D_Minal
: Entity_Id
;
14252 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14253 Pdef
:= Defining_Identifier
(Dec
);
14255 if Has_Discriminants
(Pdef
) then
14256 D
:= First_Discriminant
(Pdef
);
14257 while Present
(D
) loop
14259 Make_Defining_Identifier
(Sloc
(D
),
14260 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14262 Set_Ekind
(D_Minal
, E_Constant
);
14263 Set_Etype
(D_Minal
, Etype
(D
));
14264 Set_Scope
(D_Minal
, Pdef
);
14265 Set_Discriminal
(D
, D_Minal
);
14266 Set_Discriminal_Link
(D_Minal
, D
);
14268 Next_Discriminant
(D
);
14271 end Set_Discriminals
;
14273 -----------------------
14274 -- Trivial_Accept_OK --
14275 -----------------------
14277 function Trivial_Accept_OK
return Boolean is
14279 case Opt
.Task_Dispatching_Policy
is
14281 -- If we have the default task dispatching policy in effect, we can
14282 -- definitely do the optimization (one way of looking at this is to
14283 -- think of the formal definition of the default policy being allowed
14284 -- to run any task it likes after a rendezvous, so even if notionally
14285 -- a full rescheduling occurs, we can say that our dispatching policy
14286 -- (i.e. the default dispatching policy) reorders the queue to be the
14287 -- same as just before the call.
14292 -- FIFO_Within_Priorities certainly does not permit this
14293 -- optimization since the Rendezvous is a scheduling action that may
14294 -- require some other task to be run.
14299 -- For now, disallow the optimization for all other policies. This
14300 -- may be over-conservative, but it is certainly not incorrect.
14306 end Trivial_Accept_OK
;