1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, 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 Accessibility
; use Accessibility
;
27 with Atree
; use Atree
;
28 with Aspects
; use Aspects
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Einfo
; use Einfo
;
32 with Einfo
.Entities
; use Einfo
.Entities
;
33 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Elists
; use Elists
;
35 with Errout
; use Errout
;
36 with Exp_Ch3
; use Exp_Ch3
;
37 with Exp_Ch6
; use Exp_Ch6
;
38 with Exp_Ch11
; use Exp_Ch11
;
39 with Exp_Dbug
; use Exp_Dbug
;
40 with Exp_Sel
; use Exp_Sel
;
41 with Exp_Smem
; use Exp_Smem
;
42 with Exp_Util
; use Exp_Util
;
43 with Freeze
; use Freeze
;
45 with Itypes
; use Itypes
;
46 with Namet
; use Namet
;
47 with Nlists
; use Nlists
;
48 with Nmake
; use Nmake
;
50 with Restrict
; use Restrict
;
51 with Rident
; use Rident
;
52 with Rtsfind
; use Rtsfind
;
54 with Sem_Aux
; use Sem_Aux
;
55 with Sem_Ch5
; use Sem_Ch5
;
56 with Sem_Ch6
; use Sem_Ch6
;
57 with Sem_Ch8
; use Sem_Ch8
;
58 with Sem_Ch9
; use Sem_Ch9
;
59 with Sem_Ch11
; use Sem_Ch11
;
60 with Sem_Ch13
; use Sem_Ch13
;
61 with Sem_Elab
; use Sem_Elab
;
62 with Sem_Eval
; use Sem_Eval
;
63 with Sem_Res
; use Sem_Res
;
64 with Sem_Util
; use Sem_Util
;
65 with Sinfo
; use Sinfo
;
66 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
67 with Sinfo
.Utils
; use Sinfo
.Utils
;
68 with Snames
; use Snames
;
69 with Stand
; use Stand
;
70 with Targparm
; use Targparm
;
71 with Tbuild
; use Tbuild
;
72 with Uintp
; use Uintp
;
73 with Validsw
; use Validsw
;
75 package body Exp_Ch9
is
77 -- The following constant establishes the upper bound for the index of
78 -- an entry family. It is used to limit the allocated size of protected
79 -- types with defaulted discriminant of an integer type, when the bound
80 -- of some entry family depends on a discriminant. The limitation to entry
81 -- families of 128K should be reasonable in all cases, and is a documented
82 -- implementation restriction.
84 Entry_Family_Bound
: constant Pos
:= 2**16;
86 -----------------------
87 -- Local Subprograms --
88 -----------------------
90 function Actual_Index_Expression
94 Tsk
: Entity_Id
) return Node_Id
;
95 -- Compute the index position for an entry call. Tsk is the target task. If
96 -- the bounds of some entry family depend on discriminants, the expression
97 -- computed by this function uses the discriminants of the target task.
99 procedure Add_Object_Pointer
101 Conc_Typ
: Entity_Id
;
103 -- Prepend an object pointer declaration to the declaration list Decls.
104 -- This object pointer is initialized to a type conversion of the System.
105 -- Address pointer passed to entry barrier functions and entry body
108 procedure Add_Formal_Renamings
113 -- Create renaming declarations for the formals, inside the procedure that
114 -- implements an entry body. The renamings make the original names of the
115 -- formals accessible to gdb, and serve no other purpose.
116 -- Spec is the specification of the procedure being built.
117 -- Decls is the list of declarations to be enhanced.
118 -- Ent is the entity for the original entry body.
120 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
121 -- Transform accept statement into a block with added exception handler.
122 -- Used both for simple accept statements and for accept alternatives in
123 -- select statements. Astat is the accept statement.
125 function Build_Barrier_Function
128 Pid
: Entity_Id
) return Node_Id
;
129 -- Build the function body returning the value of the barrier expression
130 -- for the specified entry body.
132 function Build_Barrier_Function_Specification
134 Def_Id
: Entity_Id
) return Node_Id
;
135 -- Build a specification for a function implementing the protected entry
136 -- barrier of the specified entry body.
138 function Build_Corresponding_Record
141 Loc
: Source_Ptr
) return Node_Id
;
142 -- Common to tasks and protected types. Copy discriminant specifications,
143 -- build record declaration. N is the type declaration, Ctyp is the
144 -- concurrent entity (task type or protected type).
146 function Build_Dispatching_Tag_Check
148 N
: Node_Id
) return Node_Id
;
149 -- Utility to create the tree to check whether the dispatching call in
150 -- a timed entry call, a conditional entry call, or an asynchronous
151 -- transfer of control is a call to a primitive of a non-synchronized type.
152 -- K is the temporary that holds the tagged kind of the target object, and
153 -- N is the enclosing construct.
155 function Build_Entry_Count_Expression
156 (Concurrent_Type
: Entity_Id
;
157 Loc
: Source_Ptr
) return Node_Id
;
158 -- Compute number of entries for concurrent object. This is a count of
159 -- simple entries, followed by an expression that computes the length
160 -- of the range of each entry family. A single array with that size is
161 -- allocated for each concurrent object of the type.
163 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
164 -- Build the function that translates the entry index in the call
165 -- (which depends on the size of entry families) into an index into the
166 -- Entry_Bodies_Array, to determine the body and barrier function used
167 -- in a protected entry call. A pointer to this function appears in every
170 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
171 -- Build subprogram declaration for previous one
173 function Build_Lock_Free_Protected_Subprogram_Body
176 Unprot_Spec
: Node_Id
) return Node_Id
;
177 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
178 -- the subprogram specification of the unprotected version of N. Transform
179 -- N such that it invokes the unprotected version of the body.
181 function Build_Lock_Free_Unprotected_Subprogram_Body
183 Prot_Typ
: Node_Id
) return Node_Id
;
184 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
185 -- of N where the original statements of N are synchronized through atomic
186 -- actions such as compare and exchange. Prior to invoking this routine, it
187 -- has been established that N can be implemented in a lock-free fashion.
189 function Build_Parameter_Block
193 Decls
: List_Id
) return Entity_Id
;
194 -- Generate an access type for each actual parameter in the list Actuals.
195 -- Create an encapsulating record that contains all the actuals and return
196 -- its type. Generate:
197 -- type Ann1 is access all <actual1-type>
199 -- type AnnN is access all <actualN-type>
200 -- type Pnn is record
206 function Build_Protected_Entry
209 Pid
: Node_Id
) return Node_Id
;
210 -- Build the procedure implementing the statement sequence of the specified
213 function Build_Protected_Entry_Specification
216 Ent_Id
: Entity_Id
) return Node_Id
;
217 -- Build a specification for the procedure implementing the statements of
218 -- the specified entry body. Add attributes associating it with the entry
219 -- defining identifier Ent_Id.
221 function Build_Protected_Spec
223 Obj_Type
: Entity_Id
;
225 Unprotected
: Boolean := False) return List_Id
;
226 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
227 -- Subprogram_Type. Builds signature of protected subprogram, adding the
228 -- formal that corresponds to the object itself. For an access to protected
229 -- subprogram, there is no object type to specify, so the parameter has
230 -- type Address and mode In. An indirect call through such a pointer will
231 -- convert the address to a reference to the actual object. The object is
232 -- a limited record and therefore a by_reference type.
234 function Build_Protected_Subprogram_Body
237 N_Op_Spec
: Node_Id
) return Node_Id
;
238 -- This function is used to construct the protected version of a protected
239 -- subprogram. Its statement sequence first defers abort, then locks the
240 -- associated protected object, and then enters a block that contains a
241 -- call to the unprotected version of the subprogram (for details, see
242 -- Build_Unprotected_Subprogram_Body). This block statement requires a
243 -- cleanup handler that unlocks the object in all cases. For details,
244 -- see Exp_Ch7.Expand_Cleanup_Actions.
246 function Build_Renamed_Formal_Declaration
250 Renamed_Formal
: Node_Id
) return Node_Id
;
251 -- Create a renaming declaration for a formal, within a protected entry
252 -- body or an accept body. The renamed object is a component of the
253 -- parameter block that is a parameter in the entry call.
255 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
256 -- does not dereference the corresponding component to prevent an illegal
257 -- use of the incomplete type (AI05-0151).
259 function Build_Selected_Name
261 Selector
: Entity_Id
;
262 Append_Char
: Character := ' ') return Name_Id
;
263 -- Build a name in the form of Prefix__Selector, with an optional character
264 -- appended. This is used for internal subprograms generated for operations
265 -- of protected types, including barrier functions. For the subprograms
266 -- generated for entry bodies and entry barriers, the generated name
267 -- includes a sequence number that makes names unique in the presence of
268 -- entry overloading. This is necessary because entry body procedures and
269 -- barrier functions all have the same signature.
271 procedure Build_Simple_Entry_Call
276 -- Build the call corresponding to the task entry call. N is the task entry
277 -- call, Concval is the concurrent object, Ename is the entry name and
278 -- Index is the entry family index.
279 -- Note that N might be expanded into an N_Block_Statement if it gets
282 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
283 -- This routine constructs a specification for the procedure that we will
284 -- build for the task body for task type T. The spec has the form:
286 -- procedure tnameB (_Task : access tnameV);
288 -- where name is the character name taken from the task type entity that
289 -- is passed as the argument to the procedure, and tnameV is the task
290 -- value type that is associated with the task type.
292 function Build_Unprotected_Subprogram_Body
294 Pid
: Node_Id
) return Node_Id
;
295 -- This routine constructs the unprotected version of a protected
296 -- subprogram body, which contains all of the code in the original,
297 -- unexpanded body. This is the version of the protected subprogram that is
298 -- called from all protected operations on the same object, including the
299 -- protected version of the same subprogram.
301 procedure Build_Wrapper_Bodies
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 bodies
307 -- will be placed. This routine builds the bodies of the subprograms which
308 -- serve as an indirection mechanism to overriding primitives of concurrent
309 -- types, entries and protected procedures. Any new body is analyzed.
311 procedure Build_Wrapper_Specs
315 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
316 -- record of a concurrent type. N is the insertion node where all specs
317 -- will be placed. This routine builds the specs of the subprograms which
318 -- serve as an indirection mechanism to overriding primitives of concurrent
319 -- types, entries and protected procedures. Any new spec is analyzed.
321 procedure Collect_Entry_Families
324 Current_Node
: in out Node_Id
;
325 Conctyp
: Entity_Id
);
326 -- For each entry family in a concurrent type, create an anonymous array
327 -- type of the right size, and add a component to the corresponding_record.
329 function Concurrent_Object
330 (Spec_Id
: Entity_Id
;
331 Conc_Typ
: Entity_Id
) return Entity_Id
;
332 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
333 -- the entity associated with the concurrent object in the Protected_Body_
334 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
335 -- denotes formal parameter _O, _object or _task.
337 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
338 -- Copy the result type of a function specification, when building the
339 -- internal operation corresponding to a protected function, or when
340 -- expanding an access to protected function. If the result is an anonymous
341 -- access to subprogram itself, we need to create a new signature with the
342 -- same parameter names and the same resolved types, but with new entities
345 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean;
346 -- Return whether a secondary stack for the task T should be created by the
347 -- expander. The secondary stack for a task will be created by the expander
348 -- if the size of the stack has been specified by the Secondary_Stack_Size
349 -- representation aspect and either the No_Implicit_Heap_Allocations or
350 -- No_Implicit_Task_Allocations restrictions are in effect and the
351 -- No_Secondary_Stack restriction is not.
353 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
354 -- Decls is a list which may contain the declarations created by Install_
355 -- Private_Data_Declarations. All generated entities are marked as needing
356 -- debug info and debug nodes are manually generation where necessary. This
357 -- step of the expansion must to be done after private data has been moved
358 -- to its final resting scope to ensure proper visibility of debug objects.
360 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
361 -- If control flow optimizations are suppressed, and Alt is an accept,
362 -- delay, or entry call alternative with no trailing statements, insert
363 -- a null trailing statement with the given Loc (which is the sloc of
364 -- the accept, delay, or entry call statement). There might not be any
365 -- generated code for the accept, delay, or entry call itself (the effect
366 -- of these statements is part of the general processing done for the
367 -- enclosing selective accept, timed entry call, or asynchronous select),
368 -- and the null statement is there to carry the sloc of that statement to
369 -- the back-end for trace-based coverage analysis purposes.
371 procedure Extract_Dispatching_Call
373 Call_Ent
: out Entity_Id
;
374 Object
: out Entity_Id
;
375 Actuals
: out List_Id
;
376 Formals
: out List_Id
);
377 -- Given a dispatching call, extract the entity of the name of the call,
378 -- its actual dispatching object, its actual parameters and the formal
379 -- parameters of the overridden interface-level version. If the type of
380 -- the dispatching object is an access type then an explicit dereference
381 -- is returned in Object.
383 procedure Extract_Entry
385 Concval
: out Node_Id
;
387 Index
: out Node_Id
);
388 -- Given an entry call, returns the associated concurrent object, the entry
389 -- name, and the entry family index.
391 function Family_Offset
396 Cap
: Boolean) return Node_Id
;
397 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
398 -- accept statement, or the upper bound in the discrete subtype of an entry
399 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
400 -- type of the entry. If Cap is true, the result is capped according to
401 -- Entry_Family_Bound.
408 Cap
: Boolean) return Node_Id
;
409 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
410 -- family, and handle properly the superflat case. This is equivalent to
411 -- the use of 'Length on the index type, but must use Family_Offset to
412 -- handle properly the case of bounds that depend on discriminants. If
413 -- Cap is true, the result is capped according to Entry_Family_Bound.
415 procedure Find_Enclosing_Context
417 Context
: out Node_Id
;
418 Context_Id
: out Entity_Id
;
419 Context_Decls
: out List_Id
);
420 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
421 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
422 -- nearest enclosing body, block, package, or return statement and return
423 -- its constituents. Context is the enclosing construct, Context_Id is
424 -- the scope of Context_Id and Context_Decls is the declarative list of
427 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
428 -- Given a subprogram identifier, return the entity which is associated
429 -- with the protection entry index in the Protected_Body_Subprogram or
430 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
433 function Is_Potentially_Large_Family
434 (Base_Index
: Entity_Id
;
437 Hi
: Node_Id
) return Boolean;
438 -- Determine whether an entry family is potentially large because one of
439 -- its bounds denotes a discrminant.
441 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
442 -- Determine whether Id is a function or a procedure and is marked as a
443 -- private primitive.
445 function Null_Statements
(Stats
: List_Id
) return Boolean;
446 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
447 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
448 -- to still count as null. Returns True for a null sequence. The argument
449 -- is the list of statements from the DO-END sequence.
451 function Parameter_Block_Pack
457 Stmts
: List_Id
) return Entity_Id
;
458 -- Set the components of the generated parameter block with the values
459 -- of the actual parameters. Generate aliased temporaries to capture the
460 -- values for types that are passed by copy. Otherwise generate a reference
461 -- to the actual's value. Return the address of the aggregate block.
463 -- Jnn1 : alias <formal-type1>;
464 -- Jnn1 := <actual1>;
467 -- Jnn1'unchecked_access;
468 -- <actual2>'reference;
471 function Parameter_Block_Unpack
475 Formals
: List_Id
) return List_Id
;
476 -- Retrieve the values of the components from the parameter block and
477 -- assign then to the original actual parameters. Generate:
478 -- <actual1> := P.<formal1>;
480 -- <actualN> := P.<formalN>;
482 procedure Reset_Scopes_To
(Bod
: Node_Id
; E
: Entity_Id
);
483 -- Reset the scope of declarations and blocks at the top level of Bod to
484 -- be E. Bod is either a block or a subprogram body. Used after expanding
485 -- various kinds of entry bodies into their corresponding constructs. This
486 -- is needed during unnesting to determine whether a body generated for an
487 -- entry or an accept alternative includes uplevel references.
489 function Trivial_Accept_OK
return Boolean;
490 -- If there is no DO-END block for an accept, or if the DO-END block has
491 -- only null statements, then it is possible to do the Rendezvous with much
492 -- less overhead using the Accept_Trivial routine in the run-time library.
493 -- However, this is not always a valid optimization. Whether it is valid or
494 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
495 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
496 -- a rescheduling is required, so this optimization is not allowed. This
497 -- function returns True if the optimization is permitted.
499 -----------------------------
500 -- Actual_Index_Expression --
501 -----------------------------
503 function Actual_Index_Expression
507 Tsk
: Entity_Id
) return Node_Id
509 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
517 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
518 -- Compute difference between bounds of entry family
520 --------------------------
521 -- Actual_Family_Offset --
522 --------------------------
524 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
526 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
527 -- Replace a reference to a discriminant with a selected component
528 -- denoting the discriminant of the target task.
530 -----------------------------
531 -- Actual_Discriminant_Ref --
532 -----------------------------
534 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
535 Typ
: constant Entity_Id
:= Etype
(Bound
);
539 if not Is_Entity_Name
(Bound
)
540 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
542 if Nkind
(Bound
) = N_Attribute_Reference
then
545 B
:= New_Copy_Tree
(Bound
);
550 Make_Selected_Component
(Sloc
,
551 Prefix
=> New_Copy_Tree
(Tsk
),
552 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
554 Analyze_And_Resolve
(B
, Typ
);
558 Make_Attribute_Reference
(Sloc
,
559 Attribute_Name
=> Name_Pos
,
560 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
561 Expressions
=> New_List
(B
));
562 end Actual_Discriminant_Ref
;
564 -- Start of processing for Actual_Family_Offset
568 Make_Op_Subtract
(Sloc
,
569 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
570 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
571 end Actual_Family_Offset
;
573 -- Start of processing for Actual_Index_Expression
576 -- The queues of entries and entry families appear in textual order in
577 -- the associated record. The entry index is computed as the sum of the
578 -- number of queues for all entries that precede the designated one, to
579 -- which is added the index expression, if this expression denotes a
580 -- member of a family.
582 -- The following is a place holder for the count of simple entries
584 Num
:= Make_Integer_Literal
(Sloc
, 1);
586 -- We construct an expression which is a series of addition operations.
587 -- See comments in Entry_Index_Expression, which is identical in
590 if Present
(Index
) then
591 S
:= Entry_Index_Type
(Ent
);
593 -- First make sure the index is in range if requested. The index type
594 -- has been directly set on the prefix, see Resolve_Entry.
596 if Do_Range_Check
(Index
) then
598 (Index
, Etype
(Prefix
(Parent
(Index
))), CE_Range_Check_Failed
);
605 Actual_Family_Offset
(
606 Make_Attribute_Reference
(Sloc
,
607 Attribute_Name
=> Name_Pos
,
608 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
609 Expressions
=> New_List
(Relocate_Node
(Index
))),
610 Type_Low_Bound
(S
)));
615 -- Now add lengths of preceding entries and entry families
617 Prev
:= First_Entity
(Ttyp
);
618 while Chars
(Prev
) /= Chars
(Ent
)
619 or else Ekind
(Prev
) /= Ekind
(Ent
)
620 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
622 if Ekind
(Prev
) = E_Entry
then
623 Set_Intval
(Num
, Intval
(Num
) + 1);
625 elsif Ekind
(Prev
) = E_Entry_Family
then
626 S
:= Entry_Index_Type
(Prev
);
628 -- The need for the following full view retrieval stems from this
629 -- complex case of nested generics and tasking:
632 -- type Formal_Index is range <>;
635 -- type Index is private;
642 -- type Index is new Formal_Index range 1 .. 10;
645 -- package body Outer is
647 -- entry Fam (Index); -- (2)
650 -- package body Inner is -- (3)
658 -- We are currently building the index expression for the entry
659 -- call "T.E" (1). Part of the expansion must mention the range
660 -- of the discrete type "Index" (2) of entry family "Fam".
662 -- However only the private view of type "Index" is available to
663 -- the inner generic (3) because there was no prior mention of
664 -- the type inside "Inner". This visibility requirement is
665 -- implicit and cannot be detected during the construction of
666 -- the generic trees and needs special handling.
669 and then Is_Private_Type
(S
)
670 and then Present
(Full_View
(S
))
675 Lo
:= Type_Low_Bound
(S
);
676 Hi
:= Type_High_Bound
(S
);
683 Left_Opnd
=> Actual_Family_Offset
(Hi
, Lo
),
684 Right_Opnd
=> Make_Integer_Literal
(Sloc
, 1)));
686 -- Other components are anonymous types to be ignored
696 end Actual_Index_Expression
;
698 --------------------------
699 -- Add_Formal_Renamings --
700 --------------------------
702 procedure Add_Formal_Renamings
708 Ptr
: constant Entity_Id
:=
710 (Next
(First
(Parameter_Specifications
(Spec
))));
711 -- The name of the formal that holds the address of the parameter block
718 Renamed_Formal
: Node_Id
;
721 Formal
:= First_Formal
(Ent
);
722 while Present
(Formal
) loop
723 Comp
:= Entry_Component
(Formal
);
725 Make_Defining_Identifier
(Sloc
(Formal
),
726 Chars
=> Chars
(Formal
));
727 Set_Etype
(New_F
, Etype
(Formal
));
728 Set_Scope
(New_F
, Ent
);
730 -- Now we set debug info needed on New_F even though it does not come
731 -- from source, so that the debugger will get the right information
732 -- for these generated names.
734 Set_Debug_Info_Needed
(New_F
);
736 if Ekind
(Formal
) = E_In_Parameter
then
737 Mutate_Ekind
(New_F
, E_Constant
);
739 Mutate_Ekind
(New_F
, E_Variable
);
740 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
743 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
746 Make_Selected_Component
(Loc
,
748 Make_Explicit_Dereference
(Loc
,
749 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
750 Make_Identifier
(Loc
, Chars
(Ptr
)))),
751 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
754 Build_Renamed_Formal_Declaration
755 (New_F
, Formal
, Comp
, Renamed_Formal
);
757 Append
(Decl
, Decls
);
758 Set_Renamed_Object
(Formal
, New_F
);
759 Next_Formal
(Formal
);
761 end Add_Formal_Renamings
;
763 ------------------------
764 -- Add_Object_Pointer --
765 ------------------------
767 procedure Add_Object_Pointer
769 Conc_Typ
: Entity_Id
;
772 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
777 -- Create the renaming declaration for the Protection object of a
778 -- protected type. _Object is used by Complete_Entry_Body.
779 -- ??? An attempt to make this a renaming was unsuccessful.
781 -- Build the entity for the access type
784 Make_Defining_Identifier
(Loc
,
785 New_External_Name
(Chars
(Rec_Typ
), 'P'));
788 -- _object : poVP := poVP!O;
791 Make_Object_Declaration
(Loc
,
792 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uObject
),
793 Object_Definition
=> New_Occurrence_Of
(Obj_Ptr
, Loc
),
795 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
796 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
797 Prepend_To
(Decls
, Decl
);
800 -- type poVP is access poV;
803 Make_Full_Type_Declaration
(Loc
,
804 Defining_Identifier
=>
807 Make_Access_To_Object_Definition
(Loc
,
808 Subtype_Indication
=>
809 New_Occurrence_Of
(Rec_Typ
, Loc
)));
810 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
811 Prepend_To
(Decls
, Decl
);
812 end Add_Object_Pointer
;
814 -----------------------
815 -- Build_Accept_Body --
816 -----------------------
818 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
819 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
820 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
827 -- At the end of the statement sequence, Complete_Rendezvous is called.
828 -- A label skipping the Complete_Rendezvous, and all other accept
829 -- processing, has already been added for the expansion of requeue
830 -- statements. The Sloc is copied from the last statement since it
831 -- is really part of this last statement.
835 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
836 Insert_Before
(Last
(Statements
(Stats
)), Call
);
839 -- Ada 2022 (AI12-0279)
841 if Has_Yield_Aspect
(Entity
(Entry_Direct_Name
(Astat
)))
842 and then RTE_Available
(RE_Yield
)
844 Insert_Action_After
(Call
,
845 Make_Procedure_Call_Statement
(Loc
,
846 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
849 -- If exception handlers are present, then append Complete_Rendezvous
850 -- calls to the handlers, and construct the required outer block. As
851 -- above, the Sloc is copied from the last statement in the sequence.
853 if Present
(Exception_Handlers
(Stats
)) then
854 Hand
:= First
(Exception_Handlers
(Stats
));
855 while Present
(Hand
) loop
858 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
859 Append
(Call
, Statements
(Hand
));
862 -- Ada 2022 (AI12-0279)
864 if Has_Yield_Aspect
(Entity
(Entry_Direct_Name
(Astat
)))
865 and then RTE_Available
(RE_Yield
)
867 Insert_Action_After
(Call
,
868 Make_Procedure_Call_Statement
(Loc
,
869 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
876 Make_Handled_Sequence_Of_Statements
(Loc
,
877 Statements
=> New_List
(
878 Make_Block_Statement
(Loc
,
879 Handled_Statement_Sequence
=> Stats
)));
885 -- At this stage we know that the new statement sequence does
886 -- not have an exception handler part, so we supply one to call
887 -- Exceptional_Complete_Rendezvous. This handler is
889 -- when all others =>
890 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
892 -- We handle Abort_Signal to make sure that we properly catch the abort
893 -- case and wake up the caller.
896 Make_Procedure_Call_Statement
(Sloc
(Stats
),
897 Name
=> New_Occurrence_Of
(
898 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
899 Parameter_Associations
=> New_List
(
900 Make_Function_Call
(Sloc
(Stats
),
903 (RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))));
905 Ohandle
:= Make_Others_Choice
(Loc
);
906 Set_All_Others
(Ohandle
);
908 Set_Exception_Handlers
(New_S
,
910 Make_Implicit_Exception_Handler
(Loc
,
911 Exception_Choices
=> New_List
(Ohandle
),
913 Statements
=> New_List
(Call
))));
915 -- Ada 2022 (AI12-0279)
917 if Has_Yield_Aspect
(Entity
(Entry_Direct_Name
(Astat
)))
918 and then RTE_Available
(RE_Yield
)
920 Insert_Action_After
(Call
,
921 Make_Procedure_Call_Statement
(Loc
,
922 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
925 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
926 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
927 Expand_Exception_Handlers
(New_S
);
929 -- Exceptional_Complete_Rendezvous must be called with abort still
930 -- deferred, which is the case for a "when all others" handler.
933 end Build_Accept_Body
;
935 -----------------------------------
936 -- Build_Activation_Chain_Entity --
937 -----------------------------------
939 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
940 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
941 -- Determine whether an extended return statement has activation chain
943 --------------------------
944 -- Has_Activation_Chain --
945 --------------------------
947 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
951 Decl
:= First
(Return_Object_Declarations
(Stmt
));
952 while Present
(Decl
) loop
953 if Nkind
(Decl
) = N_Object_Declaration
954 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
963 end Has_Activation_Chain
;
968 Context_Id
: Entity_Id
;
971 -- Start of processing for Build_Activation_Chain_Entity
974 -- No action needed if the run-time has no tasking support
976 if Global_No_Tasking
then
980 -- Activation chain is never used for sequential elaboration policy, see
981 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
983 if Partition_Elaboration_Policy
= 'S' then
987 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
989 -- If activation chain entity has not been declared already, create one
991 if Nkind
(Context
) = N_Extended_Return_Statement
992 or else No
(Activation_Chain_Entity
(Context
))
994 -- Since extended return statements do not store the entity of the
995 -- chain, examine the return object declarations to avoid creating
998 if Nkind
(Context
) = N_Extended_Return_Statement
999 and then Has_Activation_Chain
(Context
)
1005 Loc
: constant Source_Ptr
:= Sloc
(Context
);
1010 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
1012 -- Note: An extended return statement is not really a task
1013 -- activator, but it does have an activation chain on which to
1014 -- store the tasks temporarily. On successful return, the tasks
1015 -- on this chain are moved to the chain passed in by the caller.
1016 -- We do not build an Activation_Chain_Entity for an extended
1017 -- return statement, because we do not want to build a call to
1018 -- Activate_Tasks. Task activation is the responsibility of the
1021 if Nkind
(Context
) /= N_Extended_Return_Statement
then
1022 Set_Activation_Chain_Entity
(Context
, Chain
);
1026 Make_Object_Declaration
(Loc
,
1027 Defining_Identifier
=> Chain
,
1028 Aliased_Present
=> True,
1029 Object_Definition
=>
1030 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
));
1032 Prepend_To
(Decls
, Decl
);
1034 -- Ensure that _chain appears in the proper scope of the context
1036 if Context_Id
/= Current_Scope
then
1037 Push_Scope
(Context_Id
);
1045 end Build_Activation_Chain_Entity
;
1047 ----------------------------
1048 -- Build_Barrier_Function --
1049 ----------------------------
1051 function Build_Barrier_Function
1054 Pid
: Entity_Id
) return Node_Id
1056 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
1057 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
1058 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
1059 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
1060 Op_Decls
: constant List_Id
:= New_List
;
1062 Func_Body
: Node_Id
;
1065 -- Add a declaration for the Protection object, renaming declarations
1066 -- for the discriminals and privals and finally a declaration for the
1067 -- entry family index (if applicable).
1069 Install_Private_Data_Declarations
(Sloc
(N
),
1075 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1077 -- If compiling with -fpreserve-control-flow, make sure we insert an
1078 -- IF statement so that the back-end knows to generate a conditional
1079 -- branch instruction, even if the condition is just the name of a
1080 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1081 -- such redundant IF statements under -fpreserve-control-flow
1082 -- (whether coming from this routine, or directly from source).
1084 if Opt
.Suppress_Control_Flow_Optimizations
then
1086 Make_Implicit_If_Statement
(Cond
,
1088 Then_Statements
=> New_List
(
1089 Make_Simple_Return_Statement
(Loc
,
1090 New_Occurrence_Of
(Standard_True
, Loc
))),
1092 Else_Statements
=> New_List
(
1093 Make_Simple_Return_Statement
(Loc
,
1094 New_Occurrence_Of
(Standard_False
, Loc
))));
1097 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1100 -- Note: the condition in the barrier function needs to be properly
1101 -- processed for the C/Fortran boolean possibility, but this happens
1102 -- automatically since the return statement does this normalization.
1105 Make_Subprogram_Body
(Loc
,
1107 Build_Barrier_Function_Specification
(Loc
,
1108 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1109 Declarations
=> Op_Decls
,
1110 Handled_Statement_Sequence
=>
1111 Make_Handled_Sequence_Of_Statements
(Loc
,
1112 Statements
=> New_List
(Stmt
)));
1113 Set_Is_Entry_Barrier_Function
(Func_Body
);
1116 end Build_Barrier_Function
;
1118 ------------------------------------------
1119 -- Build_Barrier_Function_Specification --
1120 ------------------------------------------
1122 function Build_Barrier_Function_Specification
1124 Def_Id
: Entity_Id
) return Node_Id
1127 Set_Debug_Info_Needed
(Def_Id
);
1130 Make_Function_Specification
(Loc
,
1131 Defining_Unit_Name
=> Def_Id
,
1132 Parameter_Specifications
=> New_List
(
1133 Make_Parameter_Specification
(Loc
,
1134 Defining_Identifier
=>
1135 Make_Defining_Identifier
(Loc
, Name_uO
),
1137 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
1139 Make_Parameter_Specification
(Loc
,
1140 Defining_Identifier
=>
1141 Make_Defining_Identifier
(Loc
, Name_uE
),
1143 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1145 Result_Definition
=>
1146 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1147 end Build_Barrier_Function_Specification
;
1149 --------------------------
1150 -- Build_Call_With_Task --
1151 --------------------------
1153 function Build_Call_With_Task
1155 E
: Entity_Id
) return Node_Id
1157 Loc
: constant Source_Ptr
:= Sloc
(N
);
1160 Make_Function_Call
(Loc
,
1161 Name
=> New_Occurrence_Of
(E
, Loc
),
1162 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1163 end Build_Call_With_Task
;
1165 -----------------------------
1166 -- Build_Class_Wide_Master --
1167 -----------------------------
1169 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1170 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1171 Master_Decl
: Node_Id
;
1172 Master_Id
: Entity_Id
;
1173 Master_Scope
: Entity_Id
;
1175 Related_Node
: Node_Id
;
1179 -- No action needed if the run-time has no tasking support
1181 if Global_No_Tasking
then
1185 -- Find the declaration that created the access type, which is either a
1186 -- type declaration, or an object declaration with an access definition,
1187 -- in which case the type is anonymous.
1189 if Is_Itype
(Typ
) then
1190 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1192 Related_Node
:= Parent
(Typ
);
1195 Master_Scope
:= Find_Master_Scope
(Typ
);
1197 -- Nothing to do if the master scope already contains a _master entity.
1198 -- The only exception to this is the following scenario:
1201 -- Transient_Scope_1
1204 -- Transient_Scope_2
1207 -- In this case the source scope is marked as having the master entity
1208 -- even though the actual declaration appears inside an inner scope. If
1209 -- the second transient scope requires a _master, it cannot use the one
1210 -- already declared because the entity is not visible.
1212 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1213 Master_Decl
:= Empty
;
1215 if not Has_Master_Entity
(Master_Scope
)
1216 or else No
(Current_Entity_In_Scope
(Name_Id
))
1223 Master_Decl
:= Build_Master_Declaration
(Loc
);
1225 -- Ensure that the master declaration is placed before its use
1227 Ins_Nod
:= Find_Hook_Context
(Related_Node
);
1228 while not Is_List_Member
(Ins_Nod
) loop
1229 Ins_Nod
:= Parent
(Ins_Nod
);
1232 Par_Nod
:= Parent
(List_Containing
(Ins_Nod
));
1234 -- For internal blocks created by Wrap_Loop_Statement, Wrap_
1235 -- Statements_In_Block, and Build_Abort_Undefer_Block, remember
1236 -- that they have a task master entity declaration; required by
1237 -- Build_Master_Entity to avoid creating another master entity,
1238 -- and also ensures that subsequent calls to Find_Master_Scope
1239 -- return this scope as the master scope of Typ.
1241 if Is_Internal_Block
(Par_Nod
) then
1242 Set_Has_Master_Entity
(Entity
(Identifier
(Par_Nod
)));
1244 elsif Nkind
(Par_Nod
) = N_Handled_Sequence_Of_Statements
1245 and then Is_Internal_Block
(Parent
(Par_Nod
))
1247 Set_Has_Master_Entity
(Entity
(Identifier
(Parent
(Par_Nod
))));
1249 -- Otherwise remember that this scope has an associated task
1250 -- master entity declaration.
1253 Set_Has_Master_Entity
(Master_Scope
);
1256 Insert_Before
(First
(List_Containing
(Ins_Nod
)), Master_Decl
);
1257 Analyze
(Master_Decl
);
1259 -- Mark the containing scope as a task master. Masters associated
1260 -- with return statements are already marked at this stage (see
1261 -- Analyze_Subprogram_Body).
1263 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1265 Par
: Node_Id
:= Related_Node
;
1268 while Nkind
(Par
) /= N_Compilation_Unit
loop
1269 Par
:= Parent
(Par
);
1271 -- If we fall off the top, we are at the outer level,
1272 -- and the environment task is our effective master,
1273 -- so nothing to mark.
1276 N_Block_Statement | N_Subprogram_Body | N_Task_Body
1278 Set_Is_Task_Master
(Par
);
1288 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(Typ
), 'M'));
1291 -- typeMnn renames _master;
1294 Make_Object_Renaming_Declaration
(Loc
,
1295 Defining_Identifier
=> Master_Id
,
1296 Subtype_Mark
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1299 -- If the master is declared locally, add the renaming declaration
1300 -- immediately after it, to prevent access-before-elaboration in the
1303 if Present
(Master_Decl
) then
1304 Insert_After
(Master_Decl
, Ren_Decl
);
1308 Insert_Action
(Related_Node
, Ren_Decl
);
1311 Set_Master_Id
(Typ
, Master_Id
);
1312 end Build_Class_Wide_Master
;
1314 --------------------------------
1315 -- Build_Corresponding_Record --
1316 --------------------------------
1318 function Build_Corresponding_Record
1321 Loc
: Source_Ptr
) return Node_Id
1323 Rec_Ent
: constant Entity_Id
:=
1324 Make_Defining_Identifier
1325 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1328 New_Disc
: Entity_Id
;
1332 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1333 Mutate_Ekind
(Rec_Ent
, E_Record_Type
);
1334 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1335 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1336 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1337 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1340 -- Use discriminals to create list of discriminants for record, and
1341 -- create new discriminals for use in default expressions, etc. It is
1342 -- worth noting that a task discriminant gives rise to 5 entities;
1344 -- a) The original discriminant.
1345 -- b) The discriminal for use in the task.
1346 -- c) The discriminant of the corresponding record.
1347 -- d) The discriminal for the init proc of the corresponding record.
1348 -- e) The local variable that renames the discriminant in the procedure
1349 -- for the task body.
1351 -- In fact the discriminals b) are used in the renaming declarations
1352 -- for e). See details in einfo (Handling of Discriminants).
1354 if Present
(Discriminant_Specifications
(N
)) then
1356 Disc
:= First_Discriminant
(Ctyp
);
1358 while Present
(Disc
) loop
1359 New_Disc
:= CR_Discriminant
(Disc
);
1362 Make_Discriminant_Specification
(Loc
,
1363 Defining_Identifier
=> New_Disc
,
1364 Discriminant_Type
=>
1365 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1367 New_Copy
(Discriminant_Default_Value
(Disc
))));
1369 Next_Discriminant
(Disc
);
1376 -- Now we can construct the record type declaration. Note that this
1377 -- record is "limited tagged". It is "limited" to reflect the underlying
1378 -- limitedness of the task or protected object that it represents, and
1379 -- ensuring for example that it is properly passed by reference. It is
1380 -- "tagged" to give support to dispatching calls through interfaces. We
1381 -- propagate here the list of interfaces covered by the concurrent type
1382 -- (Ada 2005: AI-345).
1385 Make_Full_Type_Declaration
(Loc
,
1386 Defining_Identifier
=> Rec_Ent
,
1387 Discriminant_Specifications
=> Dlist
,
1389 Make_Record_Definition
(Loc
,
1391 Make_Component_List
(Loc
, Component_Items
=> Cdecls
),
1393 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1394 Interface_List
=> Interface_List
(N
),
1395 Limited_Present
=> True));
1396 end Build_Corresponding_Record
;
1398 ---------------------------------
1399 -- Build_Dispatching_Tag_Check --
1400 ---------------------------------
1402 function Build_Dispatching_Tag_Check
1404 N
: Node_Id
) return Node_Id
1406 Loc
: constant Source_Ptr
:= Sloc
(N
);
1413 New_Occurrence_Of
(K
, Loc
),
1415 New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1419 New_Occurrence_Of
(K
, Loc
),
1421 New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
)));
1422 end Build_Dispatching_Tag_Check
;
1424 ----------------------------------
1425 -- Build_Entry_Count_Expression --
1426 ----------------------------------
1428 function Build_Entry_Count_Expression
1429 (Concurrent_Type
: Entity_Id
;
1430 Loc
: Source_Ptr
) return Node_Id
1441 -- Count number of non-family entries
1444 Ent
:= First_Entity
(Concurrent_Type
);
1445 while Present
(Ent
) loop
1446 if Ekind
(Ent
) = E_Entry
then
1453 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1455 -- Loop through entry families building the addition nodes
1457 Ent
:= First_Entity
(Concurrent_Type
);
1458 while Present
(Ent
) loop
1459 if Ekind
(Ent
) = E_Entry_Family
then
1460 Typ
:= Entry_Index_Type
(Ent
);
1461 Hi
:= Type_High_Bound
(Typ
);
1462 Lo
:= Type_Low_Bound
(Typ
);
1463 Large
:= Is_Potentially_Large_Family
1464 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1467 Left_Opnd
=> Ecount
,
1469 Family_Size
(Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1476 end Build_Entry_Count_Expression
;
1478 ------------------------------
1479 -- Build_Master_Declaration --
1480 ------------------------------
1482 function Build_Master_Declaration
(Loc
: Source_Ptr
) return Node_Id
is
1483 Master_Decl
: Node_Id
;
1486 -- Generate a dummy master if tasks or tasking hierarchies are
1489 -- _Master : constant Integer := Library_Task_Level;
1491 if not Tasking_Allowed
1492 or else Restrictions
.Set
(No_Task_Hierarchy
)
1493 or else not RTE_Available
(RE_Current_Master
)
1496 Make_Object_Declaration
(Loc
,
1497 Defining_Identifier
=>
1498 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1499 Constant_Present
=> True,
1500 Object_Definition
=>
1501 New_Occurrence_Of
(Standard_Integer
, Loc
),
1503 Make_Integer_Literal
(Loc
, Library_Task_Level
));
1506 -- _master : constant Integer := Current_Master.all;
1510 Make_Object_Declaration
(Loc
,
1511 Defining_Identifier
=>
1512 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1513 Constant_Present
=> True,
1514 Object_Definition
=>
1515 New_Occurrence_Of
(Standard_Integer
, Loc
),
1517 Make_Explicit_Dereference
(Loc
,
1518 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
1522 end Build_Master_Declaration
;
1524 ---------------------------
1525 -- Build_Parameter_Block --
1526 ---------------------------
1528 function Build_Parameter_Block
1532 Decls
: List_Id
) return Entity_Id
1538 Has_Comp
: Boolean := False;
1542 Actual
:= First
(Actuals
);
1544 Formal
:= Defining_Identifier
(First
(Formals
));
1546 while Present
(Actual
) loop
1547 if not Is_Controlling_Actual
(Actual
) then
1550 -- type Ann is access all <actual-type>
1552 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1553 Set_Is_Param_Block_Component_Type
(Comp_Nam
);
1556 Make_Full_Type_Declaration
(Loc
,
1557 Defining_Identifier
=> Comp_Nam
,
1559 Make_Access_To_Object_Definition
(Loc
,
1560 All_Present
=> True,
1561 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1562 Subtype_Indication
=>
1563 New_Occurrence_Of
(Etype
(Actual
), Loc
))));
1569 Make_Component_Declaration
(Loc
,
1570 Defining_Identifier
=>
1571 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1572 Component_Definition
=>
1573 Make_Component_Definition
(Loc
,
1576 Subtype_Indication
=>
1577 New_Occurrence_Of
(Comp_Nam
, Loc
))));
1582 Next_Actual
(Actual
);
1583 Next_Formal_With_Extras
(Formal
);
1586 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1591 -- type Pnn is record
1596 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1597 -- the original parameter names and Ann1 .. AnnN are the access to
1601 Make_Full_Type_Declaration
(Loc
,
1602 Defining_Identifier
=>
1605 Make_Record_Definition
(Loc
,
1607 Make_Component_List
(Loc
, Comps
))));
1610 -- type Pnn is null record;
1613 Make_Full_Type_Declaration
(Loc
,
1614 Defining_Identifier
=>
1617 Make_Record_Definition
(Loc
,
1618 Null_Present
=> True,
1619 Component_List
=> Empty
)));
1623 end Build_Parameter_Block
;
1625 --------------------------------------
1626 -- Build_Renamed_Formal_Declaration --
1627 --------------------------------------
1629 function Build_Renamed_Formal_Declaration
1633 Renamed_Formal
: Node_Id
) return Node_Id
1635 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1639 -- If the formal is a tagged incomplete type, it is already passed
1640 -- by reference, so it is sufficient to rename the pointer component
1641 -- that corresponds to the actual. Otherwise we need to dereference
1642 -- the pointer component to obtain the actual.
1644 if Is_Incomplete_Type
(Etype
(Formal
))
1645 and then Is_Tagged_Type
(Etype
(Formal
))
1648 Make_Object_Renaming_Declaration
(Loc
,
1649 Defining_Identifier
=> New_F
,
1650 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Comp
), Loc
),
1651 Name
=> Renamed_Formal
);
1655 Make_Object_Renaming_Declaration
(Loc
,
1656 Defining_Identifier
=> New_F
,
1657 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Formal
), Loc
),
1659 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1663 end Build_Renamed_Formal_Declaration
;
1665 --------------------------
1666 -- Build_Wrapper_Bodies --
1667 --------------------------
1669 procedure Build_Wrapper_Bodies
1674 Rec_Typ
: Entity_Id
;
1676 function Build_Wrapper_Body
1678 Subp_Id
: Entity_Id
;
1679 Obj_Typ
: Entity_Id
;
1680 Formals
: List_Id
) return Node_Id
;
1681 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1682 -- associated with a protected or task type. Subp_Id is the subprogram
1683 -- name which will be wrapped. Obj_Typ is the type of the new formal
1684 -- parameter which handles dispatching and object notation. Formals are
1685 -- the original formals of Subp_Id which will be explicitly replicated.
1687 ------------------------
1688 -- Build_Wrapper_Body --
1689 ------------------------
1691 function Build_Wrapper_Body
1693 Subp_Id
: Entity_Id
;
1694 Obj_Typ
: Entity_Id
;
1695 Formals
: List_Id
) return Node_Id
1697 Body_Spec
: Node_Id
;
1700 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
1702 -- The subprogram is not overriding or is not a primitive declared
1703 -- between two views.
1705 if No
(Body_Spec
) then
1710 Actuals
: List_Id
:= No_List
;
1712 First_Form
: Node_Id
;
1717 -- Map formals to actuals. Use the list built for the wrapper
1718 -- spec, skipping the object notation parameter.
1720 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
1722 Formal
:= First_Form
;
1725 if Present
(Formal
) then
1726 Actuals
:= New_List
;
1727 while Present
(Formal
) loop
1729 Make_Identifier
(Loc
,
1730 Chars
=> Chars
(Defining_Identifier
(Formal
))));
1735 -- Special processing for primitives declared between a private
1736 -- type and its completion: the wrapper needs a properly typed
1737 -- parameter if the wrapped operation has a controlling first
1738 -- parameter. Note that this might not be the case for a function
1739 -- with a controlling result.
1741 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
1742 if No
(Actuals
) then
1743 Actuals
:= New_List
;
1746 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
1747 Prepend_To
(Actuals
,
1748 Unchecked_Convert_To
1749 (Corresponding_Concurrent_Type
(Obj_Typ
),
1750 Make_Identifier
(Loc
, Name_uO
)));
1753 Prepend_To
(Actuals
,
1754 Make_Identifier
(Loc
,
1755 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
1758 Nam
:= New_Occurrence_Of
(Subp_Id
, Loc
);
1760 -- An access-to-variable object parameter requires an explicit
1761 -- dereference in the unchecked conversion. This case occurs
1762 -- when a protected entry wrapper must override an interface
1763 -- level procedure with interface access as first parameter.
1765 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1767 if Nkind
(Parameter_Type
(First_Form
)) =
1771 Make_Explicit_Dereference
(Loc
,
1772 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
1774 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
1778 Make_Selected_Component
(Loc
,
1780 Unchecked_Convert_To
1781 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
1782 Selector_Name
=> New_Occurrence_Of
(Subp_Id
, Loc
));
1785 -- Create the subprogram body. For a function, the call to the
1786 -- actual subprogram has to be converted to the corresponding
1787 -- record if it is a controlling result.
1789 if Ekind
(Subp_Id
) = E_Function
then
1795 Make_Function_Call
(Loc
,
1797 Parameter_Associations
=> Actuals
);
1799 if Has_Controlling_Result
(Subp_Id
) then
1801 Unchecked_Convert_To
1802 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
1806 Make_Subprogram_Body
(Loc
,
1807 Specification
=> Body_Spec
,
1808 Declarations
=> Empty_List
,
1809 Handled_Statement_Sequence
=>
1810 Make_Handled_Sequence_Of_Statements
(Loc
,
1811 Statements
=> New_List
(
1812 Make_Simple_Return_Statement
(Loc
, Res
))));
1817 Make_Subprogram_Body
(Loc
,
1818 Specification
=> Body_Spec
,
1819 Declarations
=> Empty_List
,
1820 Handled_Statement_Sequence
=>
1821 Make_Handled_Sequence_Of_Statements
(Loc
,
1822 Statements
=> New_List
(
1823 Make_Procedure_Call_Statement
(Loc
,
1825 Parameter_Associations
=> Actuals
))));
1828 end Build_Wrapper_Body
;
1830 -- Start of processing for Build_Wrapper_Bodies
1833 if Is_Concurrent_Type
(Typ
) then
1834 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
1839 -- Generate wrapper bodies for a concurrent type which implements an
1842 if Present
(Interfaces
(Rec_Typ
)) then
1844 Insert_Nod
: Node_Id
;
1846 Prim_Elmt
: Elmt_Id
;
1847 Prim_Decl
: Node_Id
;
1849 Wrap_Body
: Node_Id
;
1850 Wrap_Id
: Entity_Id
;
1855 -- Examine all primitive operations of the corresponding record
1856 -- type, looking for wrapper specs. Generate bodies in order to
1859 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
1860 while Present
(Prim_Elmt
) loop
1861 Prim
:= Node
(Prim_Elmt
);
1863 if (Ekind
(Prim
) = E_Function
1864 or else Ekind
(Prim
) = E_Procedure
)
1865 and then Is_Primitive_Wrapper
(Prim
)
1867 Subp
:= Wrapped_Entity
(Prim
);
1868 Prim_Decl
:= Parent
(Parent
(Prim
));
1871 Build_Wrapper_Body
(Loc
,
1874 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
1875 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
1877 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
1878 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
1880 Insert_After
(Insert_Nod
, Wrap_Body
);
1881 Insert_Nod
:= Wrap_Body
;
1883 Analyze
(Wrap_Body
);
1886 Next_Elmt
(Prim_Elmt
);
1890 end Build_Wrapper_Bodies
;
1892 ------------------------
1893 -- Build_Wrapper_Spec --
1894 ------------------------
1896 function Build_Wrapper_Spec
1897 (Subp_Id
: Entity_Id
;
1898 Obj_Typ
: Entity_Id
;
1899 Formals
: List_Id
) return Node_Id
1901 function Overriding_Possible
1902 (Iface_Op
: Entity_Id
;
1903 Wrapper
: Entity_Id
) return Boolean;
1904 -- Determine whether a primitive operation can be overridden by Wrapper.
1905 -- Iface_Op is the candidate primitive operation of an interface type,
1906 -- Wrapper is the generated entry wrapper.
1908 function Replicate_Formals
1910 Formals
: List_Id
) return List_Id
;
1911 -- An explicit parameter replication is required due to the Is_Entry_
1912 -- Formal flag being set for all the formals of an entry. The explicit
1913 -- replication removes the flag that would otherwise cause a different
1914 -- path of analysis.
1916 -------------------------
1917 -- Overriding_Possible --
1918 -------------------------
1920 function Overriding_Possible
1921 (Iface_Op
: Entity_Id
;
1922 Wrapper
: Entity_Id
) return Boolean
1924 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
1925 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
1927 function Type_Conformant_Parameters
1928 (Iface_Op_Params
: List_Id
;
1929 Wrapper_Params
: List_Id
) return Boolean;
1930 -- Determine whether the parameters of the generated entry wrapper
1931 -- and those of a primitive operation are type conformant. During
1932 -- this check, the first parameter of the primitive operation is
1933 -- skipped if it is a controlling argument: protected functions
1934 -- may have a controlling result.
1936 --------------------------------
1937 -- Type_Conformant_Parameters --
1938 --------------------------------
1940 function Type_Conformant_Parameters
1941 (Iface_Op_Params
: List_Id
;
1942 Wrapper_Params
: List_Id
) return Boolean
1944 Iface_Op_Param
: Node_Id
;
1945 Iface_Op_Typ
: Entity_Id
;
1946 Wrapper_Param
: Node_Id
;
1947 Wrapper_Typ
: Entity_Id
;
1950 -- Skip the first (controlling) parameter of primitive operation
1952 Iface_Op_Param
:= First
(Iface_Op_Params
);
1954 if Present
(First_Formal
(Iface_Op
))
1955 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
1957 Next
(Iface_Op_Param
);
1960 Wrapper_Param
:= First
(Wrapper_Params
);
1961 while Present
(Iface_Op_Param
)
1962 and then Present
(Wrapper_Param
)
1964 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
1965 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
1967 -- The two parameters must be mode conformant
1969 if not Conforming_Types
1970 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
1975 Next
(Iface_Op_Param
);
1976 Next
(Wrapper_Param
);
1979 -- One of the lists is longer than the other
1981 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
1986 end Type_Conformant_Parameters
;
1988 -- Start of processing for Overriding_Possible
1991 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
1995 -- If an inherited subprogram is implemented by a protected procedure
1996 -- or an entry, then the first parameter of the inherited subprogram
1997 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
1999 if Ekind
(Iface_Op
) = E_Procedure
2000 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2003 Obj_Param
: constant Node_Id
:=
2004 First
(Parameter_Specifications
(Iface_Op_Spec
));
2006 if not Out_Present
(Obj_Param
)
2007 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2016 Type_Conformant_Parameters
2017 (Parameter_Specifications
(Iface_Op_Spec
),
2018 Parameter_Specifications
(Wrapper_Spec
));
2019 end Overriding_Possible
;
2021 -----------------------
2022 -- Replicate_Formals --
2023 -----------------------
2025 function Replicate_Formals
2027 Formals
: List_Id
) return List_Id
2029 New_Formals
: constant List_Id
:= New_List
;
2031 Param_Type
: Node_Id
;
2034 Formal
:= First
(Formals
);
2036 -- Skip the object parameter when dealing with primitives declared
2037 -- between two views.
2039 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2040 and then not Has_Controlling_Result
(Subp_Id
)
2045 while Present
(Formal
) loop
2047 -- Create an explicit copy of the entry parameter
2049 -- When creating the wrapper subprogram for a primitive operation
2050 -- of a protected interface we must construct an equivalent
2051 -- signature to that of the overriding operation. For regular
2052 -- parameters we can just use the type of the formal, but for
2053 -- access to subprogram parameters we need to reanalyze the
2054 -- parameter type to create local entities for the signature of
2055 -- the subprogram type. Using the entities of the overriding
2056 -- subprogram will result in out-of-scope errors in the back-end.
2058 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2059 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2062 New_Occurrence_Of
(Etype
(Parameter_Type
(Formal
)), Loc
);
2065 Append_To
(New_Formals
,
2066 Make_Parameter_Specification
(Loc
,
2067 Defining_Identifier
=>
2068 Make_Defining_Identifier
(Loc
,
2069 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2070 In_Present
=> In_Present
(Formal
),
2071 Out_Present
=> Out_Present
(Formal
),
2072 Null_Exclusion_Present
=> Null_Exclusion_Present
(Formal
),
2073 Parameter_Type
=> Param_Type
));
2079 end Replicate_Formals
;
2083 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2084 First_Param
: Node_Id
:= Empty
;
2086 Iface_Elmt
: Elmt_Id
;
2087 Iface_Op
: Entity_Id
;
2088 Iface_Op_Elmt
: Elmt_Id
;
2089 Overridden_Subp
: Entity_Id
;
2091 -- Start of processing for Build_Wrapper_Spec
2094 -- No point in building wrappers for untagged concurrent types
2096 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2098 -- Check if this subprogram has a profile that matches some interface
2101 Check_Synchronized_Overriding
(Subp_Id
, Overridden_Subp
);
2103 if Present
(Overridden_Subp
) then
2105 First
(Parameter_Specifications
(Parent
(Overridden_Subp
)));
2107 -- An entry or a protected procedure can override a routine where the
2108 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2109 -- type. Since the wrapper must have the exact same signature as that of
2110 -- the overridden subprogram, we try to find the overriding candidate
2111 -- and use its controlling formal.
2113 -- Check every implemented interface
2115 elsif Present
(Interfaces
(Obj_Typ
)) then
2116 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2117 Search
: while Present
(Iface_Elmt
) loop
2118 Iface
:= Node
(Iface_Elmt
);
2120 -- Check every interface primitive
2122 if Present
(Primitive_Operations
(Iface
)) then
2123 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2124 while Present
(Iface_Op_Elmt
) loop
2125 Iface_Op
:= Node
(Iface_Op_Elmt
);
2127 -- Ignore predefined primitives
2129 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2130 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2132 -- The current primitive operation can be overridden by
2133 -- the generated entry wrapper.
2135 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2137 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2143 Next_Elmt
(Iface_Op_Elmt
);
2147 Next_Elmt
(Iface_Elmt
);
2151 -- Do not generate the wrapper if no interface primitive is covered by
2152 -- the subprogram and it is not a primitive declared between two views
2153 -- (see Process_Full_View).
2156 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2162 Wrapper_Id
: constant Entity_Id
:=
2163 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2164 New_Formals
: List_Id
;
2165 Obj_Param
: Node_Id
;
2166 Obj_Param_Typ
: Entity_Id
;
2169 -- Minimum decoration is needed to catch the entity in
2170 -- Sem_Ch6.Override_Dispatching_Operation.
2172 if Ekind
(Subp_Id
) = E_Function
then
2173 Mutate_Ekind
(Wrapper_Id
, E_Function
);
2175 Mutate_Ekind
(Wrapper_Id
, E_Procedure
);
2178 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2179 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2180 Set_Is_Private_Primitive
(Wrapper_Id
,
2181 Is_Private_Primitive_Subprogram
(Subp_Id
));
2183 -- Process the formals
2185 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2187 -- A function with a controlling result and no first controlling
2188 -- formal needs no additional parameter.
2190 if Has_Controlling_Result
(Subp_Id
)
2192 (No
(First_Formal
(Subp_Id
))
2193 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2197 -- Routine Subp_Id has been found to override an interface primitive.
2198 -- If the interface operation has an access parameter, create a copy
2199 -- of it, with the same null exclusion indicator if present.
2201 elsif Present
(First_Param
) then
2202 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2204 Make_Access_Definition
(Loc
,
2206 New_Occurrence_Of
(Obj_Typ
, Loc
),
2207 Null_Exclusion_Present
=>
2208 Null_Exclusion_Present
(Parameter_Type
(First_Param
)),
2210 Constant_Present
(Parameter_Type
(First_Param
)));
2212 Obj_Param_Typ
:= New_Occurrence_Of
(Obj_Typ
, Loc
);
2216 Make_Parameter_Specification
(Loc
,
2217 Defining_Identifier
=>
2218 Make_Defining_Identifier
(Loc
,
2220 In_Present
=> In_Present
(First_Param
),
2221 Out_Present
=> Out_Present
(First_Param
),
2222 Parameter_Type
=> Obj_Param_Typ
);
2224 Prepend_To
(New_Formals
, Obj_Param
);
2226 -- If we are dealing with a primitive declared between two views,
2227 -- implemented by a synchronized operation, we need to create
2228 -- a default parameter. The mode of the parameter must match that
2229 -- of the primitive operation.
2232 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2235 Make_Parameter_Specification
(Loc
,
2236 Defining_Identifier
=>
2237 Make_Defining_Identifier
(Loc
, Name_uO
),
2239 In_Present
(Parent
(First_Entity
(Subp_Id
))),
2240 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2241 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2243 Prepend_To
(New_Formals
, Obj_Param
);
2246 -- Build the final spec. If it is a function with a controlling
2247 -- result, it is a primitive operation of the corresponding
2248 -- record type, so mark the spec accordingly.
2250 if Ekind
(Subp_Id
) = E_Function
then
2255 if Has_Controlling_Result
(Subp_Id
) then
2258 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2260 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2264 Make_Function_Specification
(Loc
,
2265 Defining_Unit_Name
=> Wrapper_Id
,
2266 Parameter_Specifications
=> New_Formals
,
2267 Result_Definition
=> Res_Def
);
2271 Make_Procedure_Specification
(Loc
,
2272 Defining_Unit_Name
=> Wrapper_Id
,
2273 Parameter_Specifications
=> New_Formals
);
2276 end Build_Wrapper_Spec
;
2278 -------------------------
2279 -- Build_Wrapper_Specs --
2280 -------------------------
2282 procedure Build_Wrapper_Specs
2288 Rec_Typ
: Entity_Id
;
2289 procedure Scan_Declarations
(L
: List_Id
);
2290 -- Common processing for visible and private declarations
2291 -- of a protected type.
2293 procedure Scan_Declarations
(L
: List_Id
) is
2295 Wrap_Decl
: Node_Id
;
2296 Wrap_Spec
: Node_Id
;
2304 while Present
(Decl
) loop
2307 if Nkind
(Decl
) = N_Entry_Declaration
2308 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2312 (Subp_Id
=> Defining_Identifier
(Decl
),
2314 Formals
=> Parameter_Specifications
(Decl
));
2316 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2319 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2322 Parameter_Specifications
(Specification
(Decl
)));
2325 if Present
(Wrap_Spec
) then
2327 Make_Subprogram_Declaration
(Loc
,
2328 Specification
=> Wrap_Spec
);
2330 Insert_After
(N
, Wrap_Decl
);
2333 Analyze
(Wrap_Decl
);
2338 end Scan_Declarations
;
2340 -- start of processing for Build_Wrapper_Specs
2343 if Is_Protected_Type
(Typ
) then
2344 Def
:= Protected_Definition
(Parent
(Typ
));
2345 else pragma Assert
(Is_Task_Type
(Typ
));
2346 Def
:= Task_Definition
(Parent
(Typ
));
2349 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2351 -- Generate wrapper specs for a concurrent type which implements an
2352 -- interface. Operations in both the visible and private parts may
2353 -- implement progenitor operations.
2355 if Present
(Interfaces
(Rec_Typ
)) and then Present
(Def
) then
2356 Scan_Declarations
(Visible_Declarations
(Def
));
2357 Scan_Declarations
(Private_Declarations
(Def
));
2359 end Build_Wrapper_Specs
;
2361 ---------------------------
2362 -- Build_Find_Body_Index --
2363 ---------------------------
2365 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2366 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2369 Has_F
: Boolean := False;
2371 If_St
: Node_Id
:= Empty
;
2374 Decls
: List_Id
:= New_List
;
2375 Ret
: Node_Id
:= Empty
;
2377 Siz
: Node_Id
:= Empty
;
2379 procedure Add_If_Clause
(Expr
: Node_Id
);
2380 -- Add test for range of current entry
2382 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2383 -- If a bound of an entry is given by a discriminant, retrieve the
2384 -- actual value of the discriminant from the enclosing object.
2390 procedure Add_If_Clause
(Expr
: Node_Id
) is
2392 Stats
: constant List_Id
:=
2394 Make_Simple_Return_Statement
(Loc
,
2395 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2398 -- Index for current entry body
2402 -- Compute total length of entry queues so far
2410 Right_Opnd
=> Expr
);
2415 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2418 -- Map entry queue indexes in the range of the current family
2419 -- into the current index, that designates the entry body.
2423 Make_Implicit_If_Statement
(Typ
,
2425 Then_Statements
=> Stats
,
2426 Elsif_Parts
=> New_List
);
2430 Append_To
(Elsif_Parts
(If_St
),
2431 Make_Elsif_Part
(Loc
,
2433 Then_Statements
=> Stats
));
2437 ------------------------------
2438 -- Convert_Discriminant_Ref --
2439 ------------------------------
2441 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2445 if Is_Entity_Name
(Bound
)
2446 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2449 Make_Selected_Component
(Loc
,
2451 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2452 Make_Explicit_Dereference
(Loc
,
2453 Make_Identifier
(Loc
, Name_uObject
))),
2454 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2455 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2457 B
:= New_Copy_Tree
(Bound
);
2461 end Convert_Discriminant_Ref
;
2463 -- Start of processing for Build_Find_Body_Index
2466 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2468 Ent
:= First_Entity
(Typ
);
2469 while Present
(Ent
) loop
2470 if Ekind
(Ent
) = E_Entry_Family
then
2480 -- If the protected type has no entry families, there is a one-one
2481 -- correspondence between entry queue and entry body.
2484 Make_Simple_Return_Statement
(Loc
,
2485 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2488 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2491 -- if E <= l1 then return 1;
2492 -- elsif E <= l1 + l2 then return 2;
2497 Ent
:= First_Entity
(Typ
);
2499 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2501 while Present
(Ent
) loop
2502 if Ekind
(Ent
) = E_Entry
then
2503 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2505 elsif Ekind
(Ent
) = E_Entry_Family
then
2506 E_Typ
:= Entry_Index_Type
(Ent
);
2507 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2508 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2509 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2518 Make_Simple_Return_Statement
(Loc
,
2519 Expression
=> Make_Integer_Literal
(Loc
, 1));
2522 -- Ranges are in increasing order, so last one doesn't need guard
2525 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2528 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2530 -- If Elsif_Parts becomes empty then remove it entirely, as
2531 -- otherwise we would violate the invariant of If_Statement
2532 -- node described in Sinfo.
2534 if Is_Empty_List
(Elsif_Parts
(Ret
)) then
2535 pragma Assert
(Elsif_Parts
(Ret
) /= No_List
);
2536 Set_Elsif_Parts
(Ret
, No_List
);
2543 Make_Subprogram_Body
(Loc
,
2544 Specification
=> Spec
,
2545 Declarations
=> Decls
,
2546 Handled_Statement_Sequence
=>
2547 Make_Handled_Sequence_Of_Statements
(Loc
,
2548 Statements
=> New_List
(Ret
)));
2549 end Build_Find_Body_Index
;
2551 --------------------------------
2552 -- Build_Find_Body_Index_Spec --
2553 --------------------------------
2555 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2556 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2557 Id
: constant Entity_Id
:=
2558 Make_Defining_Identifier
(Loc
,
2559 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2560 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2561 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2565 Make_Function_Specification
(Loc
,
2566 Defining_Unit_Name
=> Id
,
2567 Parameter_Specifications
=> New_List
(
2568 Make_Parameter_Specification
(Loc
,
2569 Defining_Identifier
=> Parm1
,
2571 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2573 Make_Parameter_Specification
(Loc
,
2574 Defining_Identifier
=> Parm2
,
2576 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2578 Result_Definition
=> New_Occurrence_Of
(
2579 RTE
(RE_Protected_Entry_Index
), Loc
));
2580 end Build_Find_Body_Index_Spec
;
2582 -----------------------------------------------
2583 -- Build_Lock_Free_Protected_Subprogram_Body --
2584 -----------------------------------------------
2586 function Build_Lock_Free_Protected_Subprogram_Body
2589 Unprot_Spec
: Node_Id
) return Node_Id
2591 Actuals
: constant List_Id
:= New_List
;
2592 Loc
: constant Source_Ptr
:= Sloc
(N
);
2593 Spec
: constant Node_Id
:= Specification
(N
);
2594 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
2596 Prot_Spec
: Node_Id
;
2600 -- Create the protected version of the body
2603 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
2605 -- Build the actual parameters which appear in the call to the
2606 -- unprotected version of the body.
2608 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
2609 while Present
(Formal
) loop
2611 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
2616 -- Function case, generate:
2617 -- return <Unprot_Func_Call>;
2619 if Nkind
(Spec
) = N_Function_Specification
then
2621 Make_Simple_Return_Statement
(Loc
,
2623 Make_Function_Call
(Loc
,
2625 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2626 Parameter_Associations
=> Actuals
));
2628 -- Procedure case, call the unprotected version
2632 Make_Procedure_Call_Statement
(Loc
,
2634 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2635 Parameter_Associations
=> Actuals
);
2639 Make_Subprogram_Body
(Loc
,
2640 Declarations
=> Empty_List
,
2641 Specification
=> Prot_Spec
,
2642 Handled_Statement_Sequence
=>
2643 Make_Handled_Sequence_Of_Statements
(Loc
,
2644 Statements
=> New_List
(Stmt
)));
2645 end Build_Lock_Free_Protected_Subprogram_Body
;
2647 -------------------------------------------------
2648 -- Build_Lock_Free_Unprotected_Subprogram_Body --
2649 -------------------------------------------------
2651 -- Procedures which meet the lock-free implementation requirements and
2652 -- reference a unique scalar component Comp are expanded in the following
2655 -- procedure P (...) is
2656 -- Expected_Comp : constant Comp_Type :=
2658 -- (System.Atomic_Primitives.Lock_Free_Read_N
2659 -- (_Object.Comp'Address));
2663 -- <original declarations before the object renaming declaration
2666 -- Desired_Comp : Comp_Type := Expected_Comp;
2667 -- Comp : Comp_Type renames Desired_Comp;
2669 -- <original declarations after the object renaming declaration
2673 -- <original statements>
2674 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
2675 -- (_Object.Comp'Address,
2676 -- Interfaces.Unsigned_N (Expected_Comp),
2677 -- Interfaces.Unsigned_N (Desired_Comp));
2682 -- Each return and raise statement of P is transformed into an atomic
2685 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2686 -- (_Object.Comp'Address,
2687 -- Interfaces.Unsigned_N (Expected_Comp),
2688 -- Interfaces.Unsigned_N (Desired_Comp));
2690 -- <original statement>
2695 -- Functions which meet the lock-free implementation requirements and
2696 -- reference a unique scalar component Comp are expanded in the following
2699 -- function F (...) return ... is
2700 -- <original declarations before the object renaming declaration
2703 -- Expected_Comp : constant Comp_Type :=
2705 -- (System.Atomic_Primitives.Lock_Free_Read_N
2706 -- (_Object.Comp'Address));
2707 -- Comp : Comp_Type renames Expected_Comp;
2709 -- <original declarations after the object renaming declaration of
2713 -- <original statements>
2716 function Build_Lock_Free_Unprotected_Subprogram_Body
2718 Prot_Typ
: Node_Id
) return Node_Id
2720 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
2721 -- Subprograms which meet the lock-free implementation criteria are
2722 -- allowed to reference only one unique component. Return the prival
2723 -- of the said component.
2725 --------------------------
2726 -- Referenced_Component --
2727 --------------------------
2729 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
2732 Source_Comp
: Entity_Id
:= Empty
;
2735 -- Find the unique source component which N references in its
2738 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
2740 Element
: Lock_Free_Subprogram
renames
2741 Lock_Free_Subprogram_Table
.Table
(Index
);
2743 if Element
.Sub_Body
= N
then
2744 Source_Comp
:= Element
.Comp_Id
;
2750 if No
(Source_Comp
) then
2754 -- Find the prival which corresponds to the source component within
2755 -- the declarations of N.
2757 Decl
:= First
(Declarations
(N
));
2758 while Present
(Decl
) loop
2760 -- Privals appear as object renamings
2762 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
2763 Comp
:= Defining_Identifier
(Decl
);
2765 if Present
(Prival_Link
(Comp
))
2766 and then Prival_Link
(Comp
) = Source_Comp
2776 end Referenced_Component
;
2780 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
2781 Loc
: constant Source_Ptr
:= Sloc
(N
);
2782 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
2783 Decls
: List_Id
:= Declarations
(N
);
2785 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
2788 -- Add renamings for the protection object, discriminals, privals, and
2789 -- the entry index constant for use by debugger.
2791 Debug_Private_Data_Declarations
(Decls
);
2793 -- Perform the lock-free expansion when the subprogram references a
2794 -- protected component.
2796 if Present
(Comp
) then
2797 Protected_Component_Ref
: declare
2798 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
2799 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
2800 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
2802 Is_Procedure
: constant Boolean :=
2803 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
2804 -- Indicates if N is a protected procedure body
2806 Block_Decls
: List_Id
:= No_List
;
2807 Try_Write
: Entity_Id
;
2808 Desired_Comp
: Entity_Id
;
2811 Label_Id
: Entity_Id
:= Empty
;
2813 Expected_Comp
: Entity_Id
;
2816 New_Copy_List_Tree
(Statements
(Hand_Stmt_Seq
));
2818 Unsigned
: Entity_Id
;
2820 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
2821 -- Transform a single node if it is a return statement, a raise
2822 -- statement or a reference to Comp.
2824 procedure Process_Stmts
(Stmts
: List_Id
);
2825 -- Given a statement sequence Stmts, wrap any return or raise
2826 -- statements in the following manner:
2828 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2829 -- (_Object.Comp'Address,
2830 -- Interfaces.Unsigned_N (Expected_Comp),
2831 -- Interfaces.Unsigned_N (Desired_Comp))
2842 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
2844 procedure Wrap_Statement
(Stmt
: Node_Id
);
2845 -- Wrap an arbitrary statement inside an if statement where the
2846 -- condition does an atomic check on the state of the object.
2848 --------------------
2849 -- Wrap_Statement --
2850 --------------------
2852 procedure Wrap_Statement
(Stmt
: Node_Id
) is
2854 -- The first time through, create the declaration of a label
2855 -- which is used to skip the remainder of source statements
2856 -- if the state of the object has changed.
2858 if No
(Label_Id
) then
2860 Make_Identifier
(Loc
, New_External_Name
('L', 0));
2861 Set_Entity
(Label_Id
,
2862 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
2866 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2867 -- (_Object.Comp'Address,
2868 -- Interfaces.Unsigned_N (Expected_Comp),
2869 -- Interfaces.Unsigned_N (Desired_Comp))
2877 Make_Implicit_If_Statement
(N
,
2879 Make_Function_Call
(Loc
,
2881 New_Occurrence_Of
(Try_Write
, Loc
),
2882 Parameter_Associations
=> New_List
(
2883 Make_Attribute_Reference
(Loc
,
2884 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
2885 Attribute_Name
=> Name_Address
),
2887 Unchecked_Convert_To
(Unsigned
,
2888 New_Occurrence_Of
(Expected_Comp
, Loc
)),
2890 Unchecked_Convert_To
(Unsigned
,
2891 New_Occurrence_Of
(Desired_Comp
, Loc
)))),
2893 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
2895 Else_Statements
=> New_List
(
2896 Make_Goto_Statement
(Loc
,
2898 New_Occurrence_Of
(Entity
(Label_Id
), Loc
)))));
2901 -- Start of processing for Process_Node
2904 -- Wrap each return and raise statement that appear inside a
2905 -- procedure. Skip the last return statement which is added by
2906 -- default since it is transformed into an exit statement.
2909 and then ((Nkind
(N
) = N_Simple_Return_Statement
2910 and then N
/= Last
(Stmts
))
2911 or else Nkind
(N
) = N_Extended_Return_Statement
2912 or else (Nkind
(N
) in
2913 N_Raise_xxx_Error | N_Raise_Statement
2914 and then Comes_From_Source
(N
)))
2922 Set_Analyzed
(N
, False);
2927 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
2933 procedure Process_Stmts
(Stmts
: List_Id
) is
2936 Stmt
:= First
(Stmts
);
2937 while Present
(Stmt
) loop
2938 Process_Nodes
(Stmt
);
2943 -- Start of processing for Protected_Component_Ref
2946 -- Get the type size
2948 if Known_Static_Esize
(Comp_Type
) then
2949 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
2951 -- If the Esize (Object_Size) is unknown at compile time, look at
2952 -- the RM_Size (Value_Size) since it may have been set by an
2953 -- explicit representation clause.
2955 elsif Known_Static_RM_Size
(Comp_Type
) then
2956 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
2958 -- Should not happen since this has already been checked in
2959 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
2962 raise Program_Error
;
2965 -- Retrieve all relevant atomic routines and types
2969 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
2970 Read
:= RTE
(RE_Lock_Free_Read_8
);
2971 Unsigned
:= RTE
(RE_Uint8
);
2974 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
2975 Read
:= RTE
(RE_Lock_Free_Read_16
);
2976 Unsigned
:= RTE
(RE_Uint16
);
2979 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
2980 Read
:= RTE
(RE_Lock_Free_Read_32
);
2981 Unsigned
:= RTE
(RE_Uint32
);
2984 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
2985 Read
:= RTE
(RE_Lock_Free_Read_64
);
2986 Unsigned
:= RTE
(RE_Uint64
);
2989 raise Program_Error
;
2993 -- Expected_Comp : constant Comp_Type :=
2995 -- (System.Atomic_Primitives.Lock_Free_Read_N
2996 -- (_Object.Comp'Address));
2999 Make_Defining_Identifier
(Loc
,
3000 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3003 Make_Object_Declaration
(Loc
,
3004 Defining_Identifier
=> Expected_Comp
,
3005 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3006 Constant_Present
=> True,
3008 Unchecked_Convert_To
(Comp_Type
,
3009 Make_Function_Call
(Loc
,
3010 Name
=> New_Occurrence_Of
(Read
, Loc
),
3011 Parameter_Associations
=> New_List
(
3012 Make_Attribute_Reference
(Loc
,
3013 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3014 Attribute_Name
=> Name_Address
)))));
3016 -- Protected procedures
3018 if Is_Procedure
then
3019 -- Move the original declarations inside the generated block
3021 Block_Decls
:= Decls
;
3023 -- Reset the declarations list of the protected procedure to
3024 -- contain only Decl.
3026 Decls
:= New_List
(Decl
);
3029 -- Desired_Comp : Comp_Type := Expected_Comp;
3032 Make_Defining_Identifier
(Loc
,
3033 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3035 -- Insert the declarations of Expected_Comp and Desired_Comp in
3036 -- the block declarations right before the renaming of the
3037 -- protected component.
3039 Insert_Before
(Comp_Decl
,
3040 Make_Object_Declaration
(Loc
,
3041 Defining_Identifier
=> Desired_Comp
,
3042 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3044 New_Occurrence_Of
(Expected_Comp
, Loc
)));
3046 -- Protected function
3049 Desired_Comp
:= Expected_Comp
;
3051 -- Insert the declaration of Expected_Comp in the function
3052 -- declarations right before the renaming of the protected
3055 Insert_Before
(Comp_Decl
, Decl
);
3058 -- Rewrite the protected component renaming declaration to be a
3059 -- renaming of Desired_Comp.
3062 -- Comp : Comp_Type renames Desired_Comp;
3065 Make_Object_Renaming_Declaration
(Loc
,
3066 Defining_Identifier
=>
3067 Defining_Identifier
(Comp_Decl
),
3069 New_Occurrence_Of
(Comp_Type
, Loc
),
3071 New_Occurrence_Of
(Desired_Comp
, Loc
)));
3073 -- Wrap any return or raise statements in Stmts in same the manner
3074 -- described in Process_Stmts.
3076 Process_Stmts
(Stmts
);
3079 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3080 -- (_Object.Comp'Address,
3081 -- Interfaces.Unsigned_N (Expected_Comp),
3082 -- Interfaces.Unsigned_N (Desired_Comp))
3084 if Is_Procedure
then
3086 Make_Exit_Statement
(Loc
,
3088 Make_Function_Call
(Loc
,
3090 New_Occurrence_Of
(Try_Write
, Loc
),
3091 Parameter_Associations
=> New_List
(
3092 Make_Attribute_Reference
(Loc
,
3093 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3094 Attribute_Name
=> Name_Address
),
3096 Unchecked_Convert_To
(Unsigned
,
3097 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3099 Unchecked_Convert_To
(Unsigned
,
3100 New_Occurrence_Of
(Desired_Comp
, Loc
)))));
3102 -- Small optimization: transform the default return statement
3103 -- of a procedure into the atomic exit statement.
3105 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3106 Rewrite
(Last
(Stmts
), Stmt
);
3108 Append_To
(Stmts
, Stmt
);
3112 -- Create the declaration of the label used to skip the rest of
3113 -- the source statements when the object state changes.
3115 if Present
(Label_Id
) then
3116 Label
:= Make_Label
(Loc
, Label_Id
);
3118 Make_Implicit_Label_Declaration
(Loc
,
3119 Defining_Identifier
=> Entity
(Label_Id
),
3120 Label_Construct
=> Label
));
3121 Append_To
(Stmts
, Label
);
3133 if Is_Procedure
then
3136 Make_Loop_Statement
(Loc
,
3137 Statements
=> New_List
(
3138 Make_Block_Statement
(Loc
,
3139 Declarations
=> Block_Decls
,
3140 Handled_Statement_Sequence
=>
3141 Make_Handled_Sequence_Of_Statements
(Loc
,
3142 Statements
=> Stmts
))),
3143 End_Label
=> Empty
));
3147 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3148 end Protected_Component_Ref
;
3151 -- Make an unprotected version of the subprogram for use within the same
3152 -- object, with new name and extra parameter representing the object.
3155 Make_Subprogram_Body
(Loc
,
3157 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3158 Declarations
=> Decls
,
3159 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3160 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3162 -------------------------
3163 -- Build_Master_Entity --
3164 -------------------------
3166 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3167 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3169 Context_Id
: Entity_Id
;
3175 -- No action needed if the run-time has no tasking support
3177 if Global_No_Tasking
then
3181 if Is_Itype
(Obj_Or_Typ
) then
3182 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3184 Par
:= Parent
(Obj_Or_Typ
);
3187 -- When creating a master for a record component which is either a task
3188 -- or access-to-task, the enclosing record is the master scope and the
3189 -- proper insertion point is the component list.
3191 if Is_Record_Type
(Current_Scope
) then
3193 Context_Id
:= Current_Scope
;
3194 Decls
:= List_Containing
(Context
);
3196 -- Default case for object declarations and access types. Note that the
3197 -- context is updated to the nearest enclosing body, block, package, or
3198 -- return statement.
3201 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3204 -- When the enclosing context is a BIP function whose result type has
3205 -- tasks, the function has an extra formal that is the master of the
3206 -- tasks to be created by its returned object (that is, when its
3207 -- enclosing context is a return statement). However, if the body of
3208 -- the function creates tasks before its return statements, such tasks
3209 -- need their own master.
3211 if Has_Master_Entity
(Context_Id
)
3212 and then Ekind
(Context_Id
) = E_Function
3213 and then Is_Build_In_Place_Function
(Context_Id
)
3214 and then Needs_BIP_Task_Actuals
(Context_Id
)
3216 -- No need to add it again if previously added
3219 Master_Present
: Boolean;
3222 -- Handle transient scopes
3224 if Context_Id
/= Current_Scope
then
3225 Push_Scope
(Context_Id
);
3227 Present
(Current_Entity_In_Scope
(Name_uMaster
));
3231 Present
(Current_Entity_In_Scope
(Name_uMaster
));
3234 if Master_Present
then
3239 -- Nothing to do if the context already has a master; internally built
3240 -- finalizers don't need a master.
3242 elsif Has_Master_Entity
(Context_Id
)
3243 or else Is_Finalizer
(Context_Id
)
3248 Decl
:= Build_Master_Declaration
(Loc
);
3250 -- The master is inserted at the start of the declarative list of the
3253 Prepend_To
(Decls
, Decl
);
3255 -- In certain cases where transient scopes are involved, the immediate
3256 -- scope is not always the proper master scope. Ensure that the master
3257 -- declaration and entity appear in the same context.
3259 if Context_Id
/= Current_Scope
then
3260 Push_Scope
(Context_Id
);
3267 -- Mark the enclosing scope and its associated construct as being task
3270 Set_Has_Master_Entity
(Context_Id
);
3272 while Present
(Context
)
3273 and then Nkind
(Context
) /= N_Compilation_Unit
3275 if Nkind
(Context
) in
3276 N_Block_Statement | N_Subprogram_Body | N_Task_Body
3278 Set_Is_Task_Master
(Context
);
3281 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3282 Context
:= Corresponding_Stub
(Parent
(Context
));
3285 Context
:= Parent
(Context
);
3287 end Build_Master_Entity
;
3289 ---------------------------
3290 -- Build_Master_Renaming --
3291 ---------------------------
3293 procedure Build_Master_Renaming
3294 (Ptr_Typ
: Entity_Id
;
3295 Ins_Nod
: Node_Id
:= Empty
)
3297 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3299 Master_Decl
: Node_Id
;
3300 Master_Id
: Entity_Id
;
3303 -- No action needed if the run-time has no tasking support
3305 if Global_No_Tasking
then
3309 -- Determine the proper context to insert the master renaming
3311 if Present
(Ins_Nod
) then
3314 elsif Is_Itype
(Ptr_Typ
) then
3315 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3317 -- When the context references a discriminant or a component of a
3318 -- private type and we are processing declarations in the private
3319 -- part of the enclosing package, we must insert the master renaming
3320 -- before the full declaration of the private type; otherwise the
3321 -- master renaming would be inserted in the public part of the
3322 -- package (and hence before the declaration of _master).
3324 if In_Private_Part
(Current_Scope
) then
3326 Ctx
: Node_Id
:= Context
;
3329 if Nkind
(Context
) = N_Discriminant_Specification
then
3330 Ctx
:= Parent
(Ctx
);
3332 while Nkind
(Ctx
) in
3333 N_Component_Declaration | N_Component_List
3335 Ctx
:= Parent
(Ctx
);
3339 if Nkind
(Ctx
) in N_Private_Type_Declaration
3340 | N_Private_Extension_Declaration
3342 Context
:= Parent
(Full_View
(Defining_Identifier
(Ctx
)));
3348 Context
:= Parent
(Ptr_Typ
);
3352 -- <Ptr_Typ>M : Master_Id renames _Master;
3353 -- and add a numeric suffix to the name to ensure that it is
3354 -- unique in case other access types in nested constructs
3355 -- are homonyms of this one.
3358 Make_Defining_Identifier
(Loc
,
3359 New_External_Name
(Chars
(Ptr_Typ
), 'M', -1));
3362 Make_Object_Renaming_Declaration
(Loc
,
3363 Defining_Identifier
=> Master_Id
,
3365 New_Occurrence_Of
(Standard_Integer
, Loc
),
3366 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3368 Insert_Action
(Context
, Master_Decl
);
3370 -- The renamed master now services the access type
3372 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3373 end Build_Master_Renaming
;
3375 ---------------------------
3376 -- Build_Protected_Entry --
3377 ---------------------------
3379 function Build_Protected_Entry
3382 Pid
: Node_Id
) return Node_Id
3384 Bod_Decls
: constant List_Id
:= New_List
;
3385 Decls
: constant List_Id
:= Declarations
(N
);
3386 End_Lab
: constant Node_Id
:=
3387 End_Label
(Handled_Statement_Sequence
(N
));
3388 End_Loc
: constant Source_Ptr
:=
3389 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3390 -- Used for the generated call to Complete_Entry_Body
3392 Loc
: constant Source_Ptr
:= Sloc
(N
);
3394 Block_Id
: Entity_Id
;
3397 Bod_Stmts
: List_Id
;
3400 Proc_Body
: Node_Id
;
3402 EH_Loc
: Source_Ptr
;
3403 -- Used for the exception handler, inserted at end of the body
3406 -- Set the source location on the exception handler only when debugging
3407 -- the expanded code (see Make_Implicit_Exception_Handler).
3409 if Debug_Generated_Code
then
3412 -- Otherwise the inserted code should not be visible to the debugger
3415 EH_Loc
:= No_Location
;
3419 Make_Defining_Identifier
(Loc
,
3420 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3421 Bod_Spec
:= Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Empty
);
3423 -- Add the following declarations:
3425 -- type poVP is access poV;
3426 -- _object : poVP := poVP (_O);
3428 -- where _O is the formal parameter associated with the concurrent
3429 -- object. These declarations are needed for Complete_Entry_Body.
3431 Add_Object_Pointer
(Loc
, Pid
, Bod_Decls
);
3433 -- Add renamings for all formals, the Protection object, discriminals,
3434 -- privals and the entry index constant for use by debugger.
3436 Add_Formal_Renamings
(Bod_Spec
, Bod_Decls
, Ent
, Loc
);
3437 Debug_Private_Data_Declarations
(Decls
);
3439 -- Put the declarations and the statements from the entry
3443 Make_Block_Statement
(Loc
,
3444 Declarations
=> Decls
,
3445 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
)));
3447 -- Analyze now and reset scopes for declarations so that Scope fields
3448 -- currently denoting the entry will now denote the block scope, and
3449 -- the block's scope will be set to the new procedure entity.
3451 Analyze_Statements
(Bod_Stmts
);
3453 Block_Id
:= Entity
(Identifier
(First
(Bod_Stmts
)));
3455 Set_Scope
(Block_Id
, Protected_Body_Subprogram
(Ent
));
3456 Set_Uses_Sec_Stack
(Block_Id
, Uses_Sec_Stack
(Corresponding_Spec
(N
)));
3458 Reset_Scopes_To
(First
(Bod_Stmts
), Block_Id
);
3459 Set_At_End_Proc
(First
(Bod_Stmts
), At_End_Proc
(N
));
3461 case Corresponding_Runtime_Package
(Pid
) is
3462 when System_Tasking_Protected_Objects_Entries
=>
3463 Append_To
(Bod_Stmts
,
3464 Make_Procedure_Call_Statement
(End_Loc
,
3466 New_Occurrence_Of
(RTE
(RE_Complete_Entry_Body
), Loc
),
3467 Parameter_Associations
=> New_List
(
3468 Make_Attribute_Reference
(End_Loc
,
3470 Make_Selected_Component
(End_Loc
,
3472 Make_Identifier
(End_Loc
, Name_uObject
),
3474 Make_Identifier
(End_Loc
, Name_uObject
)),
3475 Attribute_Name
=> Name_Unchecked_Access
))));
3477 when System_Tasking_Protected_Objects_Single_Entry
=>
3479 -- Historically, a call to Complete_Single_Entry_Body was
3480 -- inserted, but it was a null procedure.
3485 raise Program_Error
;
3488 -- When exceptions cannot be propagated, we never need to call
3489 -- Exception_Complete_Entry_Body.
3491 if No_Exception_Handlers_Set
then
3493 Make_Subprogram_Body
(Loc
,
3494 Specification
=> Bod_Spec
,
3495 Declarations
=> Bod_Decls
,
3496 Handled_Statement_Sequence
=>
3497 Make_Handled_Sequence_Of_Statements
(Loc
,
3498 Statements
=> Bod_Stmts
,
3499 End_Label
=> End_Lab
));
3502 Ohandle
:= Make_Others_Choice
(Loc
);
3503 Set_All_Others
(Ohandle
);
3505 case Corresponding_Runtime_Package
(Pid
) is
3506 when System_Tasking_Protected_Objects_Entries
=>
3509 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3511 when System_Tasking_Protected_Objects_Single_Entry
=>
3514 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3517 raise Program_Error
;
3520 -- Create body of entry procedure. The renaming declarations are
3521 -- placed ahead of the block that contains the actual entry body.
3524 Make_Subprogram_Body
(Loc
,
3525 Specification
=> Bod_Spec
,
3526 Declarations
=> Bod_Decls
,
3527 Handled_Statement_Sequence
=>
3528 Make_Handled_Sequence_Of_Statements
(Loc
,
3529 Statements
=> Bod_Stmts
,
3530 End_Label
=> End_Lab
,
3531 Exception_Handlers
=> New_List
(
3532 Make_Implicit_Exception_Handler
(EH_Loc
,
3533 Exception_Choices
=> New_List
(Ohandle
),
3535 Statements
=> New_List
(
3536 Make_Procedure_Call_Statement
(EH_Loc
,
3538 Parameter_Associations
=> New_List
(
3539 Make_Attribute_Reference
(EH_Loc
,
3541 Make_Selected_Component
(EH_Loc
,
3543 Make_Identifier
(EH_Loc
, Name_uObject
),
3545 Make_Identifier
(EH_Loc
, Name_uObject
)),
3546 Attribute_Name
=> Name_Unchecked_Access
),
3548 Make_Function_Call
(EH_Loc
,
3551 (RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3553 -- Establish link between subprogram body and source entry body
3555 Set_Corresponding_Entry_Body
(Proc_Body
, N
);
3557 Reset_Scopes_To
(Proc_Body
, Protected_Body_Subprogram
(Ent
));
3560 end Build_Protected_Entry
;
3562 -----------------------------------------
3563 -- Build_Protected_Entry_Specification --
3564 -----------------------------------------
3566 function Build_Protected_Entry_Specification
3569 Ent_Id
: Entity_Id
) return Node_Id
3571 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3574 Set_Debug_Info_Needed
(Def_Id
);
3576 if Present
(Ent_Id
) then
3577 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3581 Make_Procedure_Specification
(Loc
,
3582 Defining_Unit_Name
=> Def_Id
,
3583 Parameter_Specifications
=> New_List
(
3584 Make_Parameter_Specification
(Loc
,
3585 Defining_Identifier
=>
3586 Make_Defining_Identifier
(Loc
, Name_uO
),
3588 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3590 Make_Parameter_Specification
(Loc
,
3591 Defining_Identifier
=> P
,
3593 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3595 Make_Parameter_Specification
(Loc
,
3596 Defining_Identifier
=>
3597 Make_Defining_Identifier
(Loc
, Name_uE
),
3599 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))));
3600 end Build_Protected_Entry_Specification
;
3602 --------------------------
3603 -- Build_Protected_Spec --
3604 --------------------------
3606 function Build_Protected_Spec
3608 Obj_Type
: Entity_Id
;
3610 Unprotected
: Boolean := False) return List_Id
3612 Loc
: constant Source_Ptr
:= Sloc
(N
);
3616 New_Formal
: Entity_Id
;
3617 New_Plist
: List_Id
;
3620 New_Plist
:= New_List
;
3622 Formal
:= First_Formal
(Ident
);
3623 while Present
(Formal
) loop
3625 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
3626 Set_Comes_From_Source
(New_Formal
, Comes_From_Source
(Formal
));
3629 Mutate_Ekind
(New_Formal
, Ekind
(Formal
));
3630 Set_Protected_Formal
(Formal
, New_Formal
);
3633 Append_To
(New_Plist
,
3634 Make_Parameter_Specification
(Loc
,
3635 Defining_Identifier
=> New_Formal
,
3636 Aliased_Present
=> Aliased_Present
(Parent
(Formal
)),
3637 In_Present
=> In_Present
(Parent
(Formal
)),
3638 Out_Present
=> Out_Present
(Parent
(Formal
)),
3639 Parameter_Type
=> New_Occurrence_Of
(Etype
(Formal
), Loc
)));
3641 Next_Formal
(Formal
);
3644 -- If the subprogram is a procedure and the context is not an access
3645 -- to protected subprogram, the parameter is in-out. Otherwise it is
3649 Make_Parameter_Specification
(Loc
,
3650 Defining_Identifier
=>
3651 Make_Defining_Identifier
(Loc
, Name_uObject
),
3654 (Etype
(Ident
) = Standard_Void_Type
3655 and then not Is_RTE
(Obj_Type
, RE_Address
)),
3657 New_Occurrence_Of
(Obj_Type
, Loc
));
3658 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
3659 Prepend_To
(New_Plist
, Decl
);
3662 end Build_Protected_Spec
;
3664 ---------------------------------------
3665 -- Build_Protected_Sub_Specification --
3666 ---------------------------------------
3668 function Build_Protected_Sub_Specification
3670 Prot_Typ
: Entity_Id
;
3671 Mode
: Subprogram_Protection_Mode
) return Node_Id
3673 Loc
: constant Source_Ptr
:= Sloc
(N
);
3677 New_Plist
: List_Id
;
3680 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
3681 (Dispatching_Mode
=> ' ',
3682 Protected_Mode
=> 'P',
3683 Unprotected_Mode
=> 'N');
3686 if Ekind
(Defining_Unit_Name
(Specification
(N
))) = E_Subprogram_Body
3688 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
3693 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
3696 Build_Protected_Spec
3697 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
3698 Mode
= Unprotected_Mode
);
3700 Make_Defining_Identifier
(Loc
,
3701 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
3703 -- Reference the original nondispatching subprogram since the analysis
3704 -- of the object.operation notation may need its original name (see
3705 -- Sem_Ch4.Names_Match).
3707 if Mode
= Dispatching_Mode
then
3708 Mutate_Ekind
(New_Id
, Ekind
(Def_Id
));
3709 Set_Original_Protected_Subprogram
(New_Id
, Def_Id
);
3712 -- Link the protected or unprotected version to the original subprogram
3715 Mutate_Ekind
(New_Id
, Ekind
(Def_Id
));
3716 Set_Protected_Subprogram
(New_Id
, Def_Id
);
3718 -- The unprotected operation carries the user code, and debugging
3719 -- information must be generated for it, even though this spec does
3720 -- not come from source. It is also convenient to allow gdb to step
3721 -- into the protected operation, even though it only contains lock/
3724 Set_Debug_Info_Needed
(New_Id
);
3726 -- If a pragma Eliminate applies to the source entity, the internal
3727 -- subprograms will be eliminated as well.
3729 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
3731 -- It seems we should set Has_Nested_Subprogram here, but instead we
3732 -- currently set it in Expand_N_Protected_Body, because the entity
3733 -- created here isn't the one that Corresponding_Spec of the body
3734 -- will later be set to, and that's the entity where it's needed. ???
3736 Set_Has_Nested_Subprogram
(New_Id
, Has_Nested_Subprogram
(Def_Id
));
3738 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
3740 Make_Procedure_Specification
(Loc
,
3741 Defining_Unit_Name
=> New_Id
,
3742 Parameter_Specifications
=> New_Plist
);
3744 -- Create a new specification for the anonymous subprogram type
3748 Make_Function_Specification
(Loc
,
3749 Defining_Unit_Name
=> New_Id
,
3750 Parameter_Specifications
=> New_Plist
,
3751 Result_Definition
=>
3752 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
3754 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
3758 end Build_Protected_Sub_Specification
;
3760 -------------------------------------
3761 -- Build_Protected_Subprogram_Body --
3762 -------------------------------------
3764 function Build_Protected_Subprogram_Body
3767 N_Op_Spec
: Node_Id
) return Node_Id
3769 Might_Raise
: constant Boolean := Sem_Util
.Might_Raise
(N
);
3771 Loc
: constant Source_Ptr
:= Sloc
(N
);
3772 Op_Spec
: constant Node_Id
:= Specification
(N
);
3773 P_Op_Spec
: constant Node_Id
:=
3774 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
3777 Lock_Name
: Node_Id
;
3778 Lock_Stmt
: Node_Id
;
3779 Object_Parm
: Node_Id
;
3782 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
3783 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
3787 Unprot_Call
: Node_Id
;
3790 -- Build a list of the formal parameters of the protected version of
3791 -- the subprogram to use as the actual parameters of the unprotected
3794 Uactuals
:= New_List
;
3795 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
3796 while Present
(Pformal
) loop
3797 Append_To
(Uactuals
,
3798 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
3802 -- Make a call to the unprotected version of the subprogram built above
3803 -- for use by the protected version built below.
3805 if Nkind
(Op_Spec
) = N_Function_Specification
then
3808 Make_Simple_Return_Statement
(Loc
,
3810 Make_Function_Call
(Loc
,
3812 Make_Identifier
(Loc
,
3813 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3814 Parameter_Associations
=> Uactuals
));
3817 R
:= Make_Temporary
(Loc
, 'R');
3820 Make_Object_Declaration
(Loc
,
3821 Defining_Identifier
=> R
,
3822 Constant_Present
=> True,
3823 Object_Definition
=>
3824 New_Copy
(Result_Definition
(N_Op_Spec
)),
3826 Make_Function_Call
(Loc
,
3828 Make_Identifier
(Loc
,
3829 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3830 Parameter_Associations
=> Uactuals
));
3833 Make_Simple_Return_Statement
(Loc
,
3834 Expression
=> New_Occurrence_Of
(R
, Loc
));
3837 if Has_Enabled_Aspect
(Pid
, Aspect_Exclusive_Functions
) then
3838 Lock_Kind
:= RE_Lock
;
3840 Lock_Kind
:= RE_Lock_Read_Only
;
3844 Make_Procedure_Call_Statement
(Loc
,
3846 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3847 Parameter_Associations
=> Uactuals
);
3849 Lock_Kind
:= RE_Lock
;
3852 -- Wrap call in block that will be covered by an at_end handler
3856 Make_Block_Statement
(Loc
,
3857 Handled_Statement_Sequence
=>
3858 Make_Handled_Sequence_Of_Statements
(Loc
,
3859 Statements
=> New_List
(Unprot_Call
)));
3862 -- Make the protected subprogram body. This locks the protected
3863 -- object and calls the unprotected version of the subprogram.
3865 case Corresponding_Runtime_Package
(Pid
) is
3866 when System_Tasking_Protected_Objects_Entries
=>
3867 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entries
), Loc
);
3869 when System_Tasking_Protected_Objects_Single_Entry
=>
3870 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entry
), Loc
);
3872 when System_Tasking_Protected_Objects
=>
3873 Lock_Name
:= New_Occurrence_Of
(RTE
(Lock_Kind
), Loc
);
3876 raise Program_Error
;
3880 Make_Attribute_Reference
(Loc
,
3882 Make_Selected_Component
(Loc
,
3883 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
3884 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
3885 Attribute_Name
=> Name_Unchecked_Access
);
3888 Make_Procedure_Call_Statement
(Loc
,
3890 Parameter_Associations
=> New_List
(Object_Parm
));
3892 if Abort_Allowed
then
3894 Build_Runtime_Call
(Loc
, RE_Abort_Defer
),
3898 Stmts
:= New_List
(Lock_Stmt
);
3902 Append
(Unprot_Call
, Stmts
);
3904 if Nkind
(Op_Spec
) = N_Function_Specification
then
3906 Stmts
:= Empty_List
;
3908 Append
(Unprot_Call
, Stmts
);
3911 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
3913 if Nkind
(Op_Spec
) = N_Function_Specification
then
3914 Append_To
(Stmts
, Return_Stmt
);
3915 Append_To
(Pre_Stmts
,
3916 Make_Block_Statement
(Loc
,
3917 Declarations
=> New_List
(Unprot_Call
),
3918 Handled_Statement_Sequence
=>
3919 Make_Handled_Sequence_Of_Statements
(Loc
,
3920 Statements
=> Stmts
)));
3926 Make_Subprogram_Body
(Loc
,
3927 Declarations
=> Empty_List
,
3928 Specification
=> P_Op_Spec
,
3929 Handled_Statement_Sequence
=>
3930 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
3932 -- Mark this subprogram as a protected subprogram body so that the
3933 -- cleanup will be inserted. This is done only in the Might_Raise
3934 -- case because otherwise the cleanup has already been inserted.
3937 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
3941 end Build_Protected_Subprogram_Body
;
3943 -------------------------------------
3944 -- Build_Protected_Subprogram_Call --
3945 -------------------------------------
3947 procedure Build_Protected_Subprogram_Call
3951 External
: Boolean := True)
3953 Loc
: constant Source_Ptr
:= Sloc
(N
);
3954 Sub
: constant Entity_Id
:= Entity
(Name
);
3960 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
3963 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
3966 if Present
(Parameter_Associations
(N
)) then
3967 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
3972 -- If the type is an untagged derived type, convert to the root type,
3973 -- which is the one on which the operations are defined.
3975 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
3976 and then not Is_Tagged_Type
(Etype
(Rec
))
3977 and then Is_Derived_Type
(Etype
(Rec
))
3979 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
3980 Set_Subtype_Mark
(Rec
,
3981 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
3984 Prepend
(Rec
, Params
);
3986 if Ekind
(Sub
) = E_Procedure
then
3988 Make_Procedure_Call_Statement
(Loc
,
3990 Parameter_Associations
=> Params
));
3993 pragma Assert
(Ekind
(Sub
) = E_Function
);
3995 Make_Function_Call
(Loc
,
3997 Parameter_Associations
=> Params
));
3999 -- Preserve type of call for subsequent processing (required for
4000 -- call to Wrap_Transient_Expression in the case of a shared passive
4003 Set_Etype
(N
, Etype
(New_Sub
));
4007 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4008 and then Is_Entity_Name
(Expression
(Rec
))
4009 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4011 Add_Shared_Var_Lock_Procs
(N
);
4013 end Build_Protected_Subprogram_Call
;
4015 ---------------------------------------------
4016 -- Build_Protected_Subprogram_Call_Cleanup --
4017 ---------------------------------------------
4019 procedure Build_Protected_Subprogram_Call_Cleanup
4028 -- If the associated protected object has entries, the expanded
4029 -- exclusive protected operation has to service entry queues. In
4030 -- this case generate:
4032 -- Service_Entries (_object._object'Access);
4034 if (Nkind
(Op_Spec
) = N_Procedure_Specification
4036 (Nkind
(Op_Spec
) = N_Function_Specification
4039 (Conc_Typ
, Aspect_Exclusive_Functions
)))
4040 and then Has_Entries
(Conc_Typ
)
4042 case Corresponding_Runtime_Package
(Conc_Typ
) is
4043 when System_Tasking_Protected_Objects_Entries
=>
4044 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entries
), Loc
);
4046 when System_Tasking_Protected_Objects_Single_Entry
=>
4047 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entry
), Loc
);
4050 raise Program_Error
;
4054 Make_Procedure_Call_Statement
(Loc
,
4056 Parameter_Associations
=> New_List
(
4057 Make_Attribute_Reference
(Loc
,
4059 Make_Selected_Component
(Loc
,
4060 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4061 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4062 Attribute_Name
=> Name_Unchecked_Access
))));
4066 -- Unlock (_object._object'Access);
4068 case Corresponding_Runtime_Package
(Conc_Typ
) is
4069 when System_Tasking_Protected_Objects_Entries
=>
4070 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entries
), Loc
);
4072 when System_Tasking_Protected_Objects_Single_Entry
=>
4073 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entry
), Loc
);
4075 when System_Tasking_Protected_Objects
=>
4076 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock
), Loc
);
4079 raise Program_Error
;
4083 Make_Procedure_Call_Statement
(Loc
,
4085 Parameter_Associations
=> New_List
(
4086 Make_Attribute_Reference
(Loc
,
4088 Make_Selected_Component
(Loc
,
4089 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4090 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4091 Attribute_Name
=> Name_Unchecked_Access
))));
4097 if Abort_Allowed
then
4098 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4100 end Build_Protected_Subprogram_Call_Cleanup
;
4102 -------------------------
4103 -- Build_Selected_Name --
4104 -------------------------
4106 function Build_Selected_Name
4107 (Prefix
: Entity_Id
;
4108 Selector
: Entity_Id
;
4109 Append_Char
: Character := ' ') return Name_Id
4111 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4112 Select_Len
: Natural;
4115 Get_Name_String
(Chars
(Selector
));
4116 Select_Len
:= Name_Len
;
4117 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4118 Get_Name_String
(Chars
(Prefix
));
4120 -- If scope is anonymous type, discard suffix to recover name of
4121 -- single protected object. Otherwise use protected type name.
4123 if Name_Buffer
(Name_Len
) = 'T' then
4124 Name_Len
:= Name_Len
- 1;
4127 Add_Str_To_Name_Buffer
("__");
4128 for J
in 1 .. Select_Len
loop
4129 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4132 -- Now add the Append_Char if specified. The encoding to follow
4133 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4134 -- then the entity is associated to a protected type subprogram.
4135 -- Otherwise, it is a protected type entry. For each case, the
4136 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4138 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4140 if Append_Char
/= ' ' then
4141 if Append_Char
in 'P' |
'N' then
4142 Add_Char_To_Name_Buffer
(Append_Char
);
4145 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4146 return New_External_Name
(Name_Find
, ' ', -1);
4151 end Build_Selected_Name
;
4153 -----------------------------
4154 -- Build_Simple_Entry_Call --
4155 -----------------------------
4157 -- A task entry call is converted to a call to Call_Simple
4160 -- P : parms := (parm, parm, parm);
4162 -- Call_Simple (acceptor-task, entry-index, P'Address);
4168 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4169 -- the parameters, and the constructed aggregate value contains either the
4170 -- parameters or, in the case of non-elementary types, references to these
4171 -- parameters. Then the address of this aggregate is passed to the runtime
4172 -- routine, along with the task id value and the task entry index value.
4173 -- Pnn is only required if parameters are present.
4175 -- The assignments after the call are present only in the case of in-out
4176 -- or out parameters for elementary types, and are used to assign back the
4177 -- resulting values of such parameters.
4179 -- Note: the reason that we insert a block here is that in the context
4180 -- of selects, conditional entry calls etc. the entry call statement
4181 -- appears on its own, not as an element of a list.
4183 -- A protected entry call is converted to a Protected_Entry_Call:
4186 -- P : E1_Params := (param, param, param);
4188 -- Bnn : Communications_Block;
4191 -- P : E1_Params := (param, param, param);
4192 -- Bnn : Communications_Block;
4195 -- Protected_Entry_Call (
4196 -- Object => po._object'Access,
4197 -- E => <entry index>;
4198 -- Uninterpreted_Data => P'Address;
4199 -- Mode => Simple_Call;
4206 procedure Build_Simple_Entry_Call
4215 -- If call has been inlined, nothing left to do
4217 if Nkind
(N
) = N_Block_Statement
then
4221 -- Convert entry call to Call_Simple call
4224 Loc
: constant Source_Ptr
:= Sloc
(N
);
4225 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4226 Stats
: constant List_Id
:= New_List
;
4229 Comm_Name
: Entity_Id
;
4233 Ent_Acc
: Entity_Id
;
4235 Iface_Tag
: Entity_Id
;
4236 Iface_Typ
: Entity_Id
;
4249 -- Simple entry and entry family cases merge here
4251 Ent
:= Entity
(Ename
);
4252 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4253 Conctyp
:= Etype
(Concval
);
4255 -- Special case for protected subprogram calls
4257 if Is_Protected_Type
(Conctyp
)
4258 and then Is_Subprogram
(Entity
(Ename
))
4260 if not Is_Eliminated
(Entity
(Ename
)) then
4261 Build_Protected_Subprogram_Call
4262 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4269 -- First parameter is the Task_Id value from the task value or the
4270 -- Object from the protected object value, obtained by selecting
4271 -- the _Task_Id or _Object from the result of doing an unchecked
4272 -- conversion to convert the value to the corresponding record type.
4274 if Nkind
(Concval
) = N_Function_Call
4275 and then Is_Task_Type
(Conctyp
)
4276 and then Ada_Version
>= Ada_2005
4279 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4280 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4285 Make_Object_Declaration
(Loc
,
4286 Defining_Identifier
=> Obj
,
4287 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4288 Expression
=> ExpR
);
4289 Set_Etype
(Obj
, Conctyp
);
4290 Decls
:= New_List
(Decl
);
4291 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4298 Parm1
:= Concurrent_Ref
(Concval
);
4300 -- Second parameter is the entry index, computed by the routine
4301 -- provided for this purpose. The value of this expression is
4302 -- assigned to an intermediate variable to assure that any entry
4303 -- family index expressions are evaluated before the entry
4306 if not Is_Protected_Type
(Conctyp
)
4308 Corresponding_Runtime_Package
(Conctyp
) =
4309 System_Tasking_Protected_Objects_Entries
4311 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4314 Make_Object_Declaration
(Loc
,
4315 Defining_Identifier
=> X
,
4316 Object_Definition
=>
4317 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
4318 Expression
=> Actual_Index_Expression
(
4319 Loc
, Entity
(Ename
), Index
, Concval
));
4321 Append_To
(Decls
, Xdecl
);
4322 Parm2
:= New_Occurrence_Of
(X
, Loc
);
4329 -- The third parameter is the packaged parameters. If there are
4330 -- none, then it is just the null address, since nothing is passed.
4333 Parm3
:= New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
);
4336 -- Case of parameters present, where third argument is the address
4337 -- of a packaged record containing the required parameter values.
4340 -- First build a list of parameter values, which are references to
4341 -- objects of the parameter types.
4345 Actual
:= First_Actual
(N
);
4346 Formal
:= First_Formal
(Ent
);
4347 while Present
(Actual
) loop
4349 -- If it is a by-copy type, copy it to a new variable. The
4350 -- packaged record has a field that points to this variable.
4352 if Is_By_Copy_Type
(Etype
(Actual
)) then
4354 Make_Object_Declaration
(Loc
,
4355 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4356 Aliased_Present
=> True,
4357 Object_Definition
=>
4358 New_Occurrence_Of
(Etype
(Formal
), Loc
));
4360 -- Mark the object as not needing initialization since the
4361 -- initialization is performed separately, avoiding errors
4362 -- on cases such as formals of null-excluding access types.
4364 Set_No_Initialization
(N_Node
);
4366 -- We must make a separate assignment statement for the
4367 -- case of limited types. We cannot assign it unless the
4368 -- Assignment_OK flag is set first. An out formal of an
4369 -- access type or whose type has a Default_Value must also
4370 -- be initialized from the actual (see RM 6.4.1 (13-13.1)),
4371 -- but no constraint, predicate, or null-exclusion check is
4372 -- applied before the call.
4374 if Ekind
(Formal
) /= E_Out_Parameter
4375 or else Is_Access_Type
(Etype
(Formal
))
4377 (Is_Scalar_Type
(Etype
(Formal
))
4379 Present
(Default_Aspect_Value
(Etype
(Formal
))))
4382 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
);
4383 Set_Assignment_OK
(N_Var
);
4385 Make_Assignment_Statement
(Loc
,
4387 Expression
=> Relocate_Node
(Actual
)));
4389 -- Mark the object as internal, so we don't later reset
4390 -- No_Initialization flag in Default_Initialize_Object,
4391 -- which would lead to needless default initialization.
4392 -- We don't set this outside the if statement, because
4393 -- out scalar parameters without Default_Value do require
4394 -- default initialization if Initialize_Scalars applies.
4396 Set_Is_Internal
(Defining_Identifier
(N_Node
));
4398 -- If actual is an out parameter of a null-excluding
4399 -- access type, there is access check on entry, so set
4400 -- Suppress_Assignment_Checks on the generated statement
4401 -- that assigns the actual to the parameter block.
4403 Set_Suppress_Assignment_Checks
(Last
(Stats
));
4406 Append
(N_Node
, Decls
);
4409 Make_Attribute_Reference
(Loc
,
4410 Attribute_Name
=> Name_Unchecked_Access
,
4413 (Defining_Identifier
(N_Node
), Loc
)));
4416 -- Interface class-wide formal
4418 if Ada_Version
>= Ada_2005
4419 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4420 and then Is_Interface
(Etype
(Formal
))
4422 Iface_Typ
:= Etype
(Etype
(Formal
));
4425 -- formal_iface_type! (actual.iface_tag)'reference
4428 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4429 pragma Assert
(Present
(Iface_Tag
));
4432 Make_Reference
(Loc
,
4433 Unchecked_Convert_To
(Iface_Typ
,
4434 Make_Selected_Component
(Loc
,
4436 Relocate_Node
(Actual
),
4438 New_Occurrence_Of
(Iface_Tag
, Loc
)))));
4444 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4448 Next_Actual
(Actual
);
4449 Next_Formal_With_Extras
(Formal
);
4452 -- Now build the declaration of parameters initialized with the
4453 -- aggregate containing this constructed parameter list.
4455 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4458 Make_Object_Declaration
(Loc
,
4459 Defining_Identifier
=> P
,
4460 Object_Definition
=>
4461 New_Occurrence_Of
(Designated_Type
(Ent_Acc
), Loc
),
4463 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4466 Make_Attribute_Reference
(Loc
,
4467 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4468 Attribute_Name
=> Name_Address
);
4470 Append
(Pdecl
, Decls
);
4473 -- Now we can create the call, case of protected type
4475 if Is_Protected_Type
(Conctyp
) then
4476 case Corresponding_Runtime_Package
(Conctyp
) is
4477 when System_Tasking_Protected_Objects_Entries
=>
4479 -- Change the type of the index declaration
4481 Set_Object_Definition
(Xdecl
,
4482 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
));
4484 -- Some additional declarations for protected entry calls
4490 -- Bnn : Communications_Block;
4492 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4495 Make_Object_Declaration
(Loc
,
4496 Defining_Identifier
=> Comm_Name
,
4497 Object_Definition
=>
4499 (RTE
(RE_Communication_Block
), Loc
)));
4501 -- Some additional statements for protected entry calls
4503 -- Protected_Entry_Call
4504 -- (Object => po._object'Access,
4505 -- E => <entry index>;
4506 -- Uninterpreted_Data => P'Address;
4507 -- Mode => Simple_Call;
4511 Make_Procedure_Call_Statement
(Loc
,
4513 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
4515 Parameter_Associations
=> New_List
(
4516 Make_Attribute_Reference
(Loc
,
4517 Attribute_Name
=> Name_Unchecked_Access
,
4521 New_Occurrence_Of
(RTE
(RE_Simple_Call
), Loc
),
4522 New_Occurrence_Of
(Comm_Name
, Loc
)));
4524 when System_Tasking_Protected_Objects_Single_Entry
=>
4526 -- Protected_Single_Entry_Call
4527 -- (Object => po._object'Access,
4528 -- Uninterpreted_Data => P'Address);
4531 Make_Procedure_Call_Statement
(Loc
,
4534 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4536 Parameter_Associations
=> New_List
(
4537 Make_Attribute_Reference
(Loc
,
4538 Attribute_Name
=> Name_Unchecked_Access
,
4543 raise Program_Error
;
4546 -- Case of task type
4550 Make_Procedure_Call_Statement
(Loc
,
4552 New_Occurrence_Of
(RTE
(RE_Call_Simple
), Loc
),
4553 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4557 Append_To
(Stats
, Call
);
4559 -- If there are out or in/out parameters by copy add assignment
4560 -- statements for the result values.
4562 if Present
(Parms
) then
4563 Actual
:= First_Actual
(N
);
4564 Formal
:= First_Formal
(Ent
);
4566 Set_Assignment_OK
(Actual
);
4567 while Present
(Actual
) loop
4568 if Is_By_Copy_Type
(Etype
(Actual
))
4569 and then Ekind
(Formal
) /= E_In_Parameter
4572 Make_Assignment_Statement
(Loc
,
4573 Name
=> New_Copy
(Actual
),
4575 Make_Explicit_Dereference
(Loc
,
4576 Make_Selected_Component
(Loc
,
4577 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4579 Make_Identifier
(Loc
, Chars
(Formal
)))));
4581 -- In all cases (including limited private types) we want
4582 -- the assignment to be valid.
4584 Set_Assignment_OK
(Name
(N_Node
));
4586 -- If the call is the triggering alternative in an
4587 -- asynchronous select, or the entry_call alternative of a
4588 -- conditional entry call, the assignments for in-out
4589 -- parameters are incorporated into the statement list that
4590 -- follows, so that there are executed only if the entry
4593 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4594 and then N
= Triggering_Statement
(Parent
(N
)))
4596 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4597 and then N
= Entry_Call_Statement
(Parent
(N
)))
4599 if No
(Statements
(Parent
(N
))) then
4600 Set_Statements
(Parent
(N
), New_List
);
4603 Prepend
(N_Node
, Statements
(Parent
(N
)));
4606 Insert_After
(Call
, N_Node
);
4610 Next_Actual
(Actual
);
4611 Next_Formal_With_Extras
(Formal
);
4615 -- Finally, create block and analyze it
4618 Make_Block_Statement
(Loc
,
4619 Declarations
=> Decls
,
4620 Handled_Statement_Sequence
=>
4621 Make_Handled_Sequence_Of_Statements
(Loc
,
4622 Statements
=> Stats
)));
4626 end Build_Simple_Entry_Call
;
4628 --------------------------------
4629 -- Build_Task_Activation_Call --
4630 --------------------------------
4632 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4633 function Activation_Call_Loc
return Source_Ptr
;
4634 -- Find a suitable source location for the activation call
4636 -------------------------
4637 -- Activation_Call_Loc --
4638 -------------------------
4640 function Activation_Call_Loc
return Source_Ptr
is
4642 -- The activation call must carry the location of the "end" keyword
4643 -- when the context is a package declaration.
4645 if Nkind
(N
) = N_Package_Declaration
then
4646 return End_Keyword_Location
(N
);
4648 -- Otherwise the activation call must carry the location of the
4652 return Begin_Keyword_Location
(N
);
4654 end Activation_Call_Loc
;
4665 -- Start of processing for Build_Task_Activation_Call
4668 -- For sequential elaboration policy, all the tasks will be activated at
4669 -- the end of the elaboration.
4671 if Partition_Elaboration_Policy
= 'S' then
4674 -- Do not create an activation call for a package spec if the package
4675 -- has a completing body. The activation call will be inserted after
4676 -- the "begin" of the body.
4678 elsif Nkind
(N
) = N_Package_Declaration
4679 and then Present
(Corresponding_Body
(N
))
4684 -- Obtain the activation chain entity. Block statements, entry bodies,
4685 -- subprogram bodies, and task bodies keep the entity in their nodes.
4686 -- Package bodies on the other hand store it in the declaration of the
4687 -- corresponding package spec.
4691 if Nkind
(Owner
) = N_Package_Body
then
4692 Owner
:= Unit_Declaration_Node
(Corresponding_Spec
(Owner
));
4695 Chain
:= Activation_Chain_Entity
(Owner
);
4697 -- Nothing to do when there are no tasks to activate. This is indicated
4698 -- by a missing activation chain entity; also skip generating it when
4699 -- it is a ghost entity.
4701 if No
(Chain
) or else Is_Ignored_Ghost_Entity
(Chain
) then
4704 -- The availability of the activation chain entity does not ensure
4705 -- that we have tasks to activate because it may have been declared
4706 -- by the frontend to pass a required extra formal to a build-in-place
4707 -- subprogram call. If we are within the scope of a protected type and
4708 -- pragma Detect_Blocking is active we can assume that no tasks will be
4709 -- activated; if tasks are created in a protected object and this pragma
4710 -- is active then the frontend emits a warning and Program_Error is
4711 -- raised at runtime.
4713 elsif Detect_Blocking
and then Within_Protected_Type
(Current_Scope
) then
4717 -- The location of the activation call must be as close as possible to
4718 -- the intended semantic location of the activation because the ABE
4719 -- mechanism relies heavily on accurate locations.
4721 Loc
:= Activation_Call_Loc
;
4723 if Restricted_Profile
then
4724 Name
:= New_Occurrence_Of
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4726 Name
:= New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
);
4730 Make_Procedure_Call_Statement
(Loc
,
4732 Parameter_Associations
=>
4733 New_List
(Make_Attribute_Reference
(Loc
,
4734 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4735 Attribute_Name
=> Name_Unchecked_Access
)));
4737 if Nkind
(N
) = N_Package_Declaration
then
4738 if Present
(Private_Declarations
(Specification
(N
))) then
4739 Append
(Call
, Private_Declarations
(Specification
(N
)));
4741 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4745 -- The call goes at the start of the statement sequence after the
4746 -- start of exception range label if one is present.
4748 if Present
(Handled_Statement_Sequence
(N
)) then
4749 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4751 -- A special case, skip exception range label if one is present
4752 -- (from front end zcx processing).
4754 if Nkind
(Stmt
) = N_Label
and then Exception_Junk
(Stmt
) then
4758 -- Another special case, if the first statement is a block from
4759 -- optimization of a local raise to a goto, then the call goes
4760 -- inside this block.
4762 if Nkind
(Stmt
) = N_Block_Statement
4763 and then Exception_Junk
(Stmt
)
4765 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
4768 -- Insertion point is after any exception label pushes, since we
4769 -- want it covered by any local handlers.
4771 while Nkind
(Stmt
) in N_Push_xxx_Label
loop
4775 -- Now we have the proper insertion point
4777 Insert_Before
(Stmt
, Call
);
4780 Set_Handled_Statement_Sequence
(N
,
4781 Make_Handled_Sequence_Of_Statements
(Loc
,
4782 Statements
=> New_List
(Call
)));
4788 if Legacy_Elaboration_Checks
then
4789 Check_Task_Activation
(N
);
4791 end Build_Task_Activation_Call
;
4793 -------------------------------
4794 -- Build_Task_Allocate_Block --
4795 -------------------------------
4797 procedure Build_Task_Allocate_Block
4800 Init_Stmts
: List_Id
)
4802 Loc
: constant Source_Ptr
:= Sloc
(N
);
4803 Chain
: constant Entity_Id
:=
4804 Make_Defining_Identifier
(Loc
, Name_uChain
);
4805 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4809 Append_To
(Init_Stmts
,
4810 Make_Procedure_Call_Statement
(Loc
,
4811 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4812 Parameter_Associations
=> New_List
(
4813 Make_Attribute_Reference
(Loc
,
4814 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4815 Attribute_Name
=> Name_Unchecked_Access
))));
4818 Make_Block_Statement
(Loc
,
4819 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4820 Declarations
=> New_List
(
4822 -- _Chain : Activation_Chain;
4824 Make_Object_Declaration
(Loc
,
4825 Defining_Identifier
=> Chain
,
4826 Aliased_Present
=> True,
4827 Object_Definition
=>
4828 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4830 Handled_Statement_Sequence
=>
4831 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
4833 Has_Created_Identifier
=> True,
4834 Is_Task_Allocation_Block
=> True);
4837 Make_Implicit_Label_Declaration
(Loc
,
4838 Defining_Identifier
=> Blkent
,
4839 Label_Construct
=> Block
));
4841 Append_To
(Actions
, Block
);
4843 Set_Activation_Chain_Entity
(Block
, Chain
);
4844 end Build_Task_Allocate_Block
;
4846 -----------------------------------
4847 -- Build_Task_Proc_Specification --
4848 -----------------------------------
4850 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
4851 Loc
: constant Source_Ptr
:= Sloc
(T
);
4852 Spec_Id
: Entity_Id
;
4855 -- Case of explicit task type, suffix TB
4857 if Comes_From_Source
(T
) then
4859 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
4861 -- Case of anonymous task type, suffix B
4865 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
4868 Set_Is_Internal
(Spec_Id
);
4870 -- Associate the procedure with the task, if this is the declaration
4871 -- (and not the body) of the procedure.
4873 if No
(Task_Body_Procedure
(T
)) then
4874 Set_Task_Body_Procedure
(T
, Spec_Id
);
4878 Make_Procedure_Specification
(Loc
,
4879 Defining_Unit_Name
=> Spec_Id
,
4880 Parameter_Specifications
=> New_List
(
4881 Make_Parameter_Specification
(Loc
,
4882 Defining_Identifier
=>
4883 Make_Defining_Identifier
(Loc
, Name_uTask
),
4885 Make_Access_Definition
(Loc
,
4887 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
4888 end Build_Task_Proc_Specification
;
4890 ---------------------------------------
4891 -- Build_Unprotected_Subprogram_Body --
4892 ---------------------------------------
4894 function Build_Unprotected_Subprogram_Body
4896 Pid
: Node_Id
) return Node_Id
4898 Decls
: constant List_Id
:= Declarations
(N
);
4901 -- Add renamings for the Protection object, discriminals, privals, and
4902 -- the entry index constant for use by debugger.
4904 Debug_Private_Data_Declarations
(Decls
);
4906 -- Make an unprotected version of the subprogram for use within the same
4907 -- object, with a new name and an additional parameter representing the
4911 Make_Subprogram_Body
(Sloc
(N
),
4913 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
4914 Declarations
=> Decls
,
4915 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
),
4916 At_End_Proc
=> At_End_Proc
(N
));
4917 end Build_Unprotected_Subprogram_Body
;
4919 ----------------------------
4920 -- Collect_Entry_Families --
4921 ----------------------------
4923 procedure Collect_Entry_Families
4926 Current_Node
: in out Node_Id
;
4927 Conctyp
: Entity_Id
)
4930 Efam_Decl
: Node_Id
;
4931 Efam_Type
: Entity_Id
;
4934 Efam
:= First_Entity
(Conctyp
);
4935 while Present
(Efam
) loop
4936 if Ekind
(Efam
) = E_Entry_Family
then
4937 Efam_Type
:= Make_Temporary
(Loc
, 'F');
4940 Eityp
: constant Entity_Id
:= Entry_Index_Type
(Efam
);
4941 Lo
: constant Node_Id
:= Type_Low_Bound
(Eityp
);
4942 Hi
: constant Node_Id
:= Type_High_Bound
(Eityp
);
4947 Bityp
:= Base_Type
(Eityp
);
4949 if Is_Potentially_Large_Family
(Bityp
, Conctyp
, Lo
, Hi
) then
4950 Bityp
:= Make_Temporary
(Loc
, 'B');
4953 Make_Subtype_Declaration
(Loc
,
4954 Defining_Identifier
=> Bityp
,
4955 Subtype_Indication
=>
4956 Make_Subtype_Indication
(Loc
,
4958 New_Occurrence_Of
(Standard_Integer
, Loc
),
4960 Make_Range_Constraint
(Loc
,
4961 Range_Expression
=> Make_Range
(Loc
,
4962 Make_Integer_Literal
4963 (Loc
, -Entry_Family_Bound
),
4964 Make_Integer_Literal
4965 (Loc
, Entry_Family_Bound
- 1)))));
4967 Insert_After
(Current_Node
, Bdecl
);
4968 Current_Node
:= Bdecl
;
4973 Make_Full_Type_Declaration
(Loc
,
4974 Defining_Identifier
=> Efam_Type
,
4976 Make_Unconstrained_Array_Definition
(Loc
,
4978 (New_List
(New_Occurrence_Of
(Bityp
, Loc
))),
4980 Component_Definition
=>
4981 Make_Component_Definition
(Loc
,
4982 Aliased_Present
=> False,
4983 Subtype_Indication
=>
4984 New_Occurrence_Of
(Standard_Character
, Loc
))));
4987 Insert_After
(Current_Node
, Efam_Decl
);
4988 Current_Node
:= Efam_Decl
;
4989 Analyze
(Efam_Decl
);
4992 Make_Component_Declaration
(Loc
,
4993 Defining_Identifier
=>
4994 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
4996 Component_Definition
=>
4997 Make_Component_Definition
(Loc
,
4998 Aliased_Present
=> False,
4999 Subtype_Indication
=>
5000 Make_Subtype_Indication
(Loc
,
5002 New_Occurrence_Of
(Efam_Type
, Loc
),
5005 Make_Index_Or_Discriminant_Constraint
(Loc
,
5006 Constraints
=> New_List
(
5007 New_Occurrence_Of
(Entry_Index_Type
(Efam
),
5013 end Collect_Entry_Families
;
5015 -----------------------
5016 -- Concurrent_Object --
5017 -----------------------
5019 function Concurrent_Object
5020 (Spec_Id
: Entity_Id
;
5021 Conc_Typ
: Entity_Id
) return Entity_Id
5024 -- Parameter _O or _object
5026 if Is_Protected_Type
(Conc_Typ
) then
5027 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5032 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5033 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5035 end Concurrent_Object
;
5037 ----------------------
5038 -- Copy_Result_Type --
5039 ----------------------
5041 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5042 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5047 -- If the result type is an access_to_subprogram, we must create new
5048 -- entities for its spec.
5050 if Nkind
(New_Res
) = N_Access_Definition
5051 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5053 -- Provide new entities for the formals
5055 Par_Spec
:= First
(Parameter_Specifications
5056 (Access_To_Subprogram_Definition
(New_Res
)));
5057 while Present
(Par_Spec
) loop
5058 Formal
:= Defining_Identifier
(Par_Spec
);
5059 Set_Defining_Identifier
(Par_Spec
,
5060 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5066 end Copy_Result_Type
;
5068 --------------------
5069 -- Concurrent_Ref --
5070 --------------------
5072 -- The expression returned for a reference to a concurrent object has the
5075 -- taskV!(name)._Task_Id
5079 -- objectV!(name)._Object
5081 -- for a protected object. For the case of an access to a concurrent
5082 -- object, there is an extra explicit dereference:
5084 -- taskV!(name.all)._Task_Id
5085 -- objectV!(name.all)._Object
5087 -- here taskV and objectV are the types for the associated records, which
5088 -- contain the required _Task_Id and _Object fields for tasks and protected
5089 -- objects, respectively.
5091 -- For the case of a task type name, the expression is
5095 -- i.e. a call to the Self function which returns precisely this Task_Id
5097 -- For the case of a protected type name, the expression is
5101 -- which is a renaming of the _object field of the current object
5102 -- record, passed into protected operations as a parameter.
5104 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5105 Loc
: constant Source_Ptr
:= Sloc
(N
);
5106 Ntyp
: constant Entity_Id
:= Etype
(N
);
5110 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5111 -- Check whether the reference is to the immediately enclosing task
5112 -- type, or to an outer one (rare but legal).
5114 ---------------------
5115 -- Is_Current_Task --
5116 ---------------------
5118 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5122 Scop
:= Current_Scope
;
5123 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
5127 elsif Is_Task_Type
(Scop
) then
5130 -- If this is a procedure nested within the task type, we must
5131 -- assume that it can be called from an inner task, and therefore
5132 -- cannot treat it as a local reference.
5134 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5138 Scop
:= Scope
(Scop
);
5142 -- We know that we are within the task body, so should have found it
5145 raise Program_Error
;
5146 end Is_Current_Task
;
5148 -- Start of processing for Concurrent_Ref
5151 if Is_Access_Type
(Ntyp
) then
5152 Dtyp
:= Designated_Type
(Ntyp
);
5154 if Is_Protected_Type
(Dtyp
) then
5155 Sel
:= Name_uObject
;
5157 Sel
:= Name_uTask_Id
;
5161 Make_Selected_Component
(Loc
,
5163 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5164 Make_Explicit_Dereference
(Loc
, N
)),
5165 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5167 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5168 if Is_Task_Type
(Entity
(N
)) then
5170 if Is_Current_Task
(Entity
(N
)) then
5172 Make_Function_Call
(Loc
,
5173 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5178 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5179 T_Body
: constant Node_Id
:=
5180 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5184 Make_Object_Declaration
(Loc
,
5185 Defining_Identifier
=> T_Self
,
5186 Object_Definition
=>
5187 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5189 Make_Function_Call
(Loc
,
5190 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5191 Prepend
(Decl
, Declarations
(T_Body
));
5193 Set_Scope
(T_Self
, Entity
(N
));
5194 return New_Occurrence_Of
(T_Self
, Loc
);
5199 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5202 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5206 if Is_Protected_Type
(Ntyp
) then
5207 Sel
:= Name_uObject
;
5208 elsif Is_Task_Type
(Ntyp
) then
5209 Sel
:= Name_uTask_Id
;
5211 raise Program_Error
;
5215 Make_Selected_Component
(Loc
,
5217 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5219 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5223 ------------------------
5224 -- Convert_Concurrent --
5225 ------------------------
5227 function Convert_Concurrent
5229 Typ
: Entity_Id
) return Node_Id
5232 if not Is_Concurrent_Type
(Typ
) then
5236 Unchecked_Convert_To
5237 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5239 end Convert_Concurrent
;
5241 -------------------------------------
5242 -- Create_Secondary_Stack_For_Task --
5243 -------------------------------------
5245 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean is
5248 (Restriction_Active
(No_Implicit_Heap_Allocations
)
5249 or else Restriction_Active
(No_Implicit_Task_Allocations
))
5250 and then not Restriction_Active
(No_Secondary_Stack
)
5251 and then Has_Rep_Pragma
5252 (T
, Name_Secondary_Stack_Size
, Check_Parents
=> False);
5253 end Create_Secondary_Stack_For_Task
;
5255 -------------------------------------
5256 -- Debug_Private_Data_Declarations --
5257 -------------------------------------
5259 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5260 Debug_Nod
: Node_Id
;
5264 Decl
:= First
(Decls
);
5265 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5267 -- Declaration for concurrent entity _object and its access type,
5268 -- along with the entry index subtype:
5269 -- type prot_typVP is access prot_typV;
5270 -- _object : prot_typVP := prot_typV (_O);
5271 -- subtype Jnn is <Type of Index> range Low .. High;
5273 if Nkind
(Decl
) in N_Full_Type_Declaration | N_Object_Declaration
then
5274 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5276 -- Declaration for the Protection object, discriminals, privals, and
5277 -- entry index constant:
5278 -- conc_typR : protection_typ renames _object._object;
5279 -- discr_nameD : discr_typ renames _object.discr_name;
5280 -- discr_nameD : discr_typ renames _task.discr_name;
5281 -- prival_name : comp_typ renames _object.comp_name;
5282 -- J : constant Jnn :=
5283 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5285 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5286 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5287 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5289 if Present
(Debug_Nod
) then
5290 Insert_After
(Decl
, Debug_Nod
);
5296 end Debug_Private_Data_Declarations
;
5298 ------------------------------
5299 -- Ensure_Statement_Present --
5300 ------------------------------
5302 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5306 if Opt
.Suppress_Control_Flow_Optimizations
5307 and then Is_Empty_List
(Statements
(Alt
))
5309 Stmt
:= Make_Null_Statement
(Loc
);
5311 -- Mark NULL statement as coming from source so that it is not
5312 -- eliminated by GIGI.
5314 -- Another covert channel. If this is a requirement, it must be
5315 -- documented in sinfo/einfo ???
5317 Set_Comes_From_Source
(Stmt
, True);
5319 Set_Statements
(Alt
, New_List
(Stmt
));
5321 end Ensure_Statement_Present
;
5323 ----------------------------
5324 -- Entry_Index_Expression --
5325 ----------------------------
5327 function Entry_Index_Expression
5331 Ttyp
: Entity_Id
) return Node_Id
5341 -- The queues of entries and entry families appear in textual order in
5342 -- the associated record. The entry index is computed as the sum of the
5343 -- number of queues for all entries that precede the designated one, to
5344 -- which is added the index expression, if this expression denotes a
5345 -- member of a family.
5347 -- The following is a place holder for the count of simple entries
5349 Num
:= Make_Integer_Literal
(Sloc
, 1);
5351 -- We construct an expression which is a series of addition operations.
5352 -- The first operand is the number of single entries that precede this
5353 -- one, the second operand is the index value relative to the start of
5354 -- the referenced family, and the remaining operands are the lengths of
5355 -- the entry families that precede this entry, i.e. the constructed
5358 -- number_simple_entries +
5359 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5360 -- family'length + ...
5362 -- where index-value is the given index value, and s is the index
5363 -- subtype (we have to use pos because the subtype might be an
5364 -- enumeration type preventing direct subtraction). Note that the task
5365 -- entry array is one-indexed.
5367 -- The upper bound of the entry family may be a discriminant, so we
5368 -- retrieve the lower bound explicitly to compute offset, rather than
5369 -- using the index subtype which may mention a discriminant.
5371 if Present
(Index
) then
5372 S
:= Entry_Index_Type
(Ent
);
5374 -- First make sure the index is in range if requested. The index type
5375 -- is the pristine Entry_Index_Type of the entry.
5377 if Do_Range_Check
(Index
) then
5378 Generate_Range_Check
(Index
, S
, CE_Range_Check_Failed
);
5387 Make_Attribute_Reference
(Sloc
,
5388 Attribute_Name
=> Name_Pos
,
5389 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5390 Expressions
=> New_List
(Relocate_Node
(Index
))),
5398 -- Now add lengths of preceding entries and entry families
5400 Prev
:= First_Entity
(Ttyp
);
5401 while Chars
(Prev
) /= Chars
(Ent
)
5402 or else Ekind
(Prev
) /= Ekind
(Ent
)
5403 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5405 if Ekind
(Prev
) = E_Entry
then
5406 Set_Intval
(Num
, Intval
(Num
) + 1);
5408 elsif Ekind
(Prev
) = E_Entry_Family
then
5409 S
:= Entry_Index_Type
(Prev
);
5410 Lo
:= Type_Low_Bound
(S
);
5411 Hi
:= Type_High_Bound
(S
);
5416 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5418 -- Other components are anonymous types to be ignored
5428 end Entry_Index_Expression
;
5430 ---------------------------
5431 -- Establish_Task_Master --
5432 ---------------------------
5434 procedure Establish_Task_Master
(N
: Node_Id
) is
5438 if Restriction_Active
(No_Task_Hierarchy
) = False then
5439 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5441 -- The block may have no declarations (and nevertheless be a task
5442 -- master) if it contains a call that may return an object that
5445 if No
(Declarations
(N
)) then
5446 Set_Declarations
(N
, New_List
(Call
));
5448 Prepend_To
(Declarations
(N
), Call
);
5453 end Establish_Task_Master
;
5455 --------------------------------
5456 -- Expand_Accept_Declarations --
5457 --------------------------------
5459 -- Part of the expansion of an accept statement involves the creation of
5460 -- a declaration that can be referenced from the statement sequence of
5465 -- This declaration is inserted immediately before the accept statement
5466 -- and it is important that it be inserted before the statements of the
5467 -- statement sequence are analyzed. Thus it would be too late to create
5468 -- this declaration in the Expand_N_Accept_Statement routine, which is
5469 -- why there is a separate procedure to be called directly from Sem_Ch9.
5471 -- Ann is used to hold the address of the record containing the parameters
5472 -- (see Expand_N_Entry_Call for more details on how this record is built).
5473 -- References to the parameters do an unchecked conversion of this address
5474 -- to a pointer to the required record type, and then access the field that
5475 -- holds the value of the required parameter. The entity for the address
5476 -- variable is held as the top stack element (i.e. the last element) of the
5477 -- Accept_Address stack in the corresponding entry entity, and this element
5478 -- must be set in place before the statements are processed.
5480 -- The above description applies to the case of a stand alone accept
5481 -- statement, i.e. one not appearing as part of a select alternative.
5483 -- For the case of an accept that appears as part of a select alternative
5484 -- of a selective accept, we must still create the declaration right away,
5485 -- since Ann is needed immediately, but there is an important difference:
5487 -- The declaration is inserted before the selective accept, not before
5488 -- the accept statement (which is not part of a list anyway, and so would
5489 -- not accommodate inserted declarations)
5491 -- We only need one address variable for the entire selective accept. So
5492 -- the Ann declaration is created only for the first accept alternative,
5493 -- and subsequent accept alternatives reference the same Ann variable.
5495 -- We can distinguish the two cases by seeing whether the accept statement
5496 -- is part of a list. If not, then it must be in an accept alternative.
5498 -- To expand the requeue statement, a label is provided at the end of the
5499 -- accept statement or alternative of which it is a part, so that the
5500 -- statement can be skipped after the requeue is complete. This label is
5501 -- created here rather than during the expansion of the accept statement,
5502 -- because it will be needed by any requeue statements within the accept,
5503 -- which are expanded before the accept.
5505 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5506 Loc
: constant Source_Ptr
:= Sloc
(N
);
5507 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5508 Ann
: Entity_Id
:= Empty
;
5515 if Expander_Active
then
5517 -- If we have no handled statement sequence, we may need to build
5518 -- a dummy sequence consisting of a null statement. This can be
5519 -- skipped if the trivial accept optimization is permitted.
5521 if not Trivial_Accept_OK
5522 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5524 Set_Handled_Statement_Sequence
(N
,
5525 Make_Handled_Sequence_Of_Statements
(Loc
,
5526 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5529 -- Create and declare two labels to be placed at the end of the
5530 -- accept statement. The first label is used to allow requeues to
5531 -- skip the remainder of entry processing. The second label is used
5532 -- to skip the remainder of entry processing if the rendezvous
5533 -- completes in the middle of the accept body.
5535 if Present
(Handled_Statement_Sequence
(N
)) then
5540 Ent
:= Make_Temporary
(Loc
, 'L');
5541 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5543 Make_Implicit_Label_Declaration
(Loc
,
5544 Defining_Identifier
=> Ent
,
5545 Label_Construct
=> Lab
);
5546 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5548 Ent
:= Make_Temporary
(Loc
, 'L');
5549 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5551 Make_Implicit_Label_Declaration
(Loc
,
5552 Defining_Identifier
=> Ent
,
5553 Label_Construct
=> Lab
);
5554 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5562 -- Case of stand alone accept statement
5564 if Is_List_Member
(N
) then
5566 if Present
(Handled_Statement_Sequence
(N
)) then
5567 Ann
:= Make_Temporary
(Loc
, 'A');
5570 Make_Object_Declaration
(Loc
,
5571 Defining_Identifier
=> Ann
,
5572 Object_Definition
=>
5573 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5575 Insert_Before_And_Analyze
(N
, Adecl
);
5576 Insert_Before_And_Analyze
(N
, Ldecl
);
5577 Insert_Before_And_Analyze
(N
, Ldecl2
);
5580 -- Case of accept statement which is in an accept alternative
5584 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5585 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5589 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5590 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5592 -- ??? Consider a single label for select statements
5594 if Present
(Handled_Statement_Sequence
(N
)) then
5596 Statements
(Handled_Statement_Sequence
(N
)));
5600 Statements
(Handled_Statement_Sequence
(N
)));
5604 -- Find first accept alternative of the selective accept. A
5605 -- valid selective accept must have at least one accept in it.
5607 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5609 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5613 -- If this is the first accept statement, then we have to
5614 -- create the Ann variable, as for the stand alone case, except
5615 -- that it is inserted before the selective accept. Similarly,
5616 -- a label for requeue expansion must be declared.
5618 if N
= Accept_Statement
(Alt
) then
5619 Ann
:= Make_Temporary
(Loc
, 'A');
5621 Make_Object_Declaration
(Loc
,
5622 Defining_Identifier
=> Ann
,
5623 Object_Definition
=>
5624 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5626 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5628 -- If this is not the first accept statement, then find the Ann
5629 -- variable allocated by the first accept and use it.
5633 Node
(Last_Elmt
(Accept_Address
5634 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5639 -- Merge here with Ann either created or referenced, and Adecl
5640 -- pointing to the corresponding declaration. Remaining processing
5641 -- is the same for the two cases.
5643 if Present
(Ann
) then
5644 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5645 Set_Debug_Info_Needed
(Ann
);
5648 -- Create renaming declarations for the entry formals. Each reference
5649 -- to a formal becomes a dereference of a component of the parameter
5650 -- block, whose address is held in Ann. These declarations are
5651 -- eventually inserted into the accept block, and analyzed there so
5652 -- that they have the proper scope for gdb and do not conflict with
5653 -- other declarations.
5655 if Present
(Parameter_Specifications
(N
))
5656 and then Present
(Handled_Statement_Sequence
(N
))
5663 Renamed_Formal
: Node_Id
;
5667 Formal
:= First_Formal
(Ent
);
5669 while Present
(Formal
) loop
5670 Comp
:= Entry_Component
(Formal
);
5671 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5673 Set_Etype
(New_F
, Etype
(Formal
));
5674 Set_Scope
(New_F
, Ent
);
5676 -- Now we set debug info needed on New_F even though it does
5677 -- not come from source, so that the debugger will get the
5678 -- right information for these generated names.
5680 Set_Debug_Info_Needed
(New_F
);
5682 if Ekind
(Formal
) = E_In_Parameter
then
5683 Mutate_Ekind
(New_F
, E_Constant
);
5685 Mutate_Ekind
(New_F
, E_Variable
);
5686 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5689 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5692 Make_Selected_Component
(Loc
,
5694 Make_Explicit_Dereference
(Loc
,
5695 Unchecked_Convert_To
(
5696 Entry_Parameters_Type
(Ent
),
5697 New_Occurrence_Of
(Ann
, Loc
))),
5699 New_Occurrence_Of
(Comp
, Loc
));
5702 Build_Renamed_Formal_Declaration
5703 (New_F
, Formal
, Comp
, Renamed_Formal
);
5705 if No
(Declarations
(N
)) then
5706 Set_Declarations
(N
, New_List
);
5709 Append
(Decl
, Declarations
(N
));
5710 Set_Renamed_Object
(Formal
, New_F
);
5711 Next_Formal
(Formal
);
5718 end Expand_Accept_Declarations
;
5720 ---------------------------------------------
5721 -- Expand_Access_Protected_Subprogram_Type --
5722 ---------------------------------------------
5724 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5725 Loc
: constant Source_Ptr
:= Sloc
(N
);
5726 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5727 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5728 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5729 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5730 P_List
: constant List_Id
:=
5731 Build_Protected_Spec
(N
, RTE
(RE_Address
), D_T
, False);
5739 -- Create access to subprogram with full signature
5741 if Etype
(D_T
) /= Standard_Void_Type
then
5743 Make_Access_Function_Definition
(Loc
,
5744 Parameter_Specifications
=> P_List
,
5745 Result_Definition
=>
5746 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5750 Make_Access_Procedure_Definition
(Loc
,
5751 Parameter_Specifications
=> P_List
);
5755 Make_Full_Type_Declaration
(Loc
,
5756 Defining_Identifier
=> D_T2
,
5757 Type_Definition
=> Def1
);
5759 -- Declare the new types before the original one since the latter will
5760 -- refer to them through the Equivalent_Type slot.
5762 Insert_Before_And_Analyze
(N
, Decl1
);
5764 -- Associate the access to subprogram with its original access to
5765 -- protected subprogram type. Needed by the backend to know that this
5766 -- type corresponds with an access to protected subprogram type.
5768 Set_Original_Access_Type
(D_T2
, T
);
5770 -- Create Equivalent_Type, a record with two components for an access to
5771 -- object and an access to subprogram.
5774 Make_Component_Declaration
(Loc
,
5775 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5776 Component_Definition
=>
5777 Make_Component_Definition
(Loc
,
5778 Aliased_Present
=> False,
5779 Subtype_Indication
=>
5780 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5782 Make_Component_Declaration
(Loc
,
5783 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5784 Component_Definition
=>
5785 Make_Component_Definition
(Loc
,
5786 Aliased_Present
=> False,
5787 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5790 Make_Full_Type_Declaration
(Loc
,
5791 Defining_Identifier
=> E_T
,
5793 Make_Record_Definition
(Loc
,
5795 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
5797 Insert_Before_And_Analyze
(N
, Decl2
);
5798 Set_Equivalent_Type
(T
, E_T
);
5799 end Expand_Access_Protected_Subprogram_Type
;
5801 --------------------------
5802 -- Expand_Entry_Barrier --
5803 --------------------------
5805 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5806 Cond
: constant Node_Id
:= Condition
(Entry_Body_Formal_Part
(N
));
5807 Prot
: constant Entity_Id
:= Scope
(Ent
);
5808 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5810 Func_Id
: Entity_Id
:= Empty
;
5811 -- The entity of the barrier function
5813 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
5814 -- Check whether entity in Barrier is external to protected type.
5815 -- If so, barrier may not be properly synchronized.
5817 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
;
5818 -- Check whether N meets the Pure_Barriers restriction. Return OK if
5821 function Is_Simple_Barrier
(N
: Node_Id
) return Boolean;
5822 -- Check whether N meets the Simple_Barriers restriction. Return OK if
5825 ----------------------
5826 -- Is_Global_Entity --
5827 ----------------------
5829 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
5834 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5838 if Ekind
(E
) = E_Variable
then
5840 -- If the variable is local to the barrier function generated
5841 -- during expansion, it is ok. If expansion is not performed,
5842 -- then Func is Empty so this test cannot succeed.
5844 if Scope
(E
) = Func_Id
then
5847 -- A protected call from a barrier to another object is ok
5849 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
5852 -- If the variable is within the package body we consider
5853 -- this safe. This is a common (if dubious) idiom.
5855 elsif S
= Scope
(Prot
)
5856 and then Is_Package_Or_Generic_Package
(S
)
5857 and then Nkind
(Parent
(E
)) = N_Object_Declaration
5858 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
5863 Error_Msg_N
("potentially unsynchronized barrier??", N
);
5864 Error_Msg_N
("\& should be private component of type??", N
);
5870 end Is_Global_Entity
;
5872 procedure Check_Unprotected_Barrier
is
5873 new Traverse_Proc
(Is_Global_Entity
);
5875 -----------------------
5876 -- Is_Simple_Barrier --
5877 -----------------------
5879 function Is_Simple_Barrier
(N
: Node_Id
) return Boolean is
5883 if Is_Static_Expression
(N
) then
5885 elsif Ada_Version
>= Ada_2022
5886 and then Nkind
(N
) in N_Selected_Component | N_Indexed_Component
5887 and then Statically_Names_Object
(N
)
5889 -- Restriction relaxed in Ada 2022 to allow statically named
5891 return Is_Simple_Barrier
(Prefix
(N
));
5894 -- Check if the name is a component of the protected object. If
5895 -- the expander is active, the component has been transformed into a
5896 -- renaming of _object.all.component. Original_Node is needed in case
5897 -- validity checking is enabled, in which case the simple object
5898 -- reference will have been rewritten.
5900 if Expander_Active
then
5902 -- The expanded name may have been constant folded in which case
5903 -- the original node is not necessarily an entity name (e.g. an
5904 -- indexed component).
5906 if not Is_Entity_Name
(Original_Node
(N
)) then
5910 Renamed
:= Renamed_Object
(Entity
(Original_Node
(N
)));
5914 and then Nkind
(Renamed
) = N_Selected_Component
5915 and then Chars
(Prefix
(Prefix
(Renamed
))) = Name_uObject
;
5916 elsif not Is_Entity_Name
(N
) then
5919 return Is_Protected_Component
(Entity
(N
));
5921 end Is_Simple_Barrier
;
5923 ---------------------
5924 -- Is_Pure_Barrier --
5925 ---------------------
5927 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
is
5930 when N_Expanded_Name
5934 -- Because of N_Expanded_Name case, return Skip instead of OK.
5936 if No
(Entity
(N
)) then
5939 elsif Is_Numeric_Type
(Entity
(N
)) then
5943 case Ekind
(Entity
(N
)) is
5949 when E_Enumeration_Literal
5953 if not Is_OK_Static_Expression
(N
) then
5962 if Is_Simple_Barrier
(N
) then
5968 -- The count attribute has been transformed into run-time
5971 if Is_RTE
(Entity
(N
), RE_Protected_Count
)
5972 or else Is_RTE
(Entity
(N
), RE_Protected_Count_Entry
)
5981 when N_Function_Call
=>
5983 -- Function call checks are carried out as part of the analysis
5984 -- of the function call name.
5988 when N_Character_Literal
5997 if Ekind
(Entity
(N
)) = E_Operator
then
6001 when N_Short_Circuit
6007 when N_Indexed_Component | N_Selected_Component
=>
6008 if Statically_Names_Object
(N
) then
6009 return Is_Pure_Barrier
(Prefix
(N
));
6014 when N_Case_Expression_Alternative
=>
6015 -- do not traverse Discrete_Choices subtree
6016 if Is_Pure_Barrier
(Expression
(N
)) /= Abandon
then
6020 when N_Expression_With_Actions
=>
6021 -- this may occur in the case of a Count attribute reference
6022 if Is_Rewrite_Substitution
(N
)
6023 and then Is_Pure_Barrier
(Original_Node
(N
)) /= Abandon
6028 when N_Membership_Test
=>
6029 if Is_Pure_Barrier
(Left_Opnd
(N
)) /= Abandon
6030 and then All_Membership_Choices_Static
(N
)
6035 when N_Type_Conversion
=>
6037 -- Conversions to Universal_Integer do not raise constraint
6038 -- errors. Likewise if the expression's type is statically
6039 -- compatible with the target's type.
6041 if Etype
(N
) = Universal_Integer
6042 or else Subtypes_Statically_Compatible
6043 (Etype
(Expression
(N
)), Etype
(N
))
6048 when N_Unchecked_Type_Conversion
=>
6056 end Is_Pure_Barrier
;
6058 function Check_Pure_Barriers
is new Traverse_Func
(Is_Pure_Barrier
);
6062 Entry_Body
: Node_Id
;
6063 Func_Body
: Node_Id
:= Empty
;
6065 -- Start of processing for Expand_Entry_Barrier
6068 if No_Run_Time_Mode
then
6069 Error_Msg_CRT
("entry barrier", N
);
6073 -- Prevent cascaded errors
6075 if Nkind
(Cond
) = N_Error
then
6079 -- The body of the entry barrier must be analyzed in the context of the
6080 -- protected object, but its scope is external to it, just as any other
6081 -- unprotected version of a protected operation. The specification has
6082 -- been produced when the protected type declaration was elaborated. We
6083 -- build the body, insert it in the enclosing scope, but analyze it in
6084 -- the current context. A more uniform approach would be to treat the
6085 -- barrier just as a protected function, and discard the protected
6086 -- version of it because it is never called.
6088 if Expander_Active
then
6089 Func_Body
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6090 Func_Id
:= Barrier_Function
(Ent
);
6091 Set_Corresponding_Spec
(Func_Body
, Func_Id
);
6093 Entry_Body
:= Parent
(Corresponding_Body
(Spec_Decl
));
6095 if Nkind
(Parent
(Entry_Body
)) = N_Subunit
then
6096 Entry_Body
:= Corresponding_Stub
(Parent
(Entry_Body
));
6099 Insert_Before_And_Analyze
(Entry_Body
, Func_Body
);
6101 Set_Discriminals
(Spec_Decl
);
6102 Set_Scope
(Func_Id
, Scope
(Prot
));
6105 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6108 -- Check Simple_Barriers and Pure_Barriers restrictions.
6109 -- Note that it is safe to be calling Check_Restriction from here, even
6110 -- though this is part of the expander, since Expand_Entry_Barrier is
6111 -- called from Sem_Ch9 even in -gnatc mode.
6113 if not Is_Simple_Barrier
(Cond
) then
6114 -- flag restriction violation
6115 Check_Restriction
(Simple_Barriers
, Cond
);
6118 if Check_Pure_Barriers
(Cond
) = Abandon
then
6119 -- flag restriction violation
6120 Check_Restriction
(Pure_Barriers
, Cond
);
6122 -- Emit warning if barrier contains global entities and is thus
6123 -- potentially unsynchronized (if Pure_Barriers restrictions
6124 -- are met then no need to check for this).
6125 Check_Unprotected_Barrier
(Cond
);
6128 -- Perform a small optimization of simple barrier functions. If the
6129 -- scope of the condition's entity is not the barrier function, then
6130 -- the condition does not depend on any of the generated renamings.
6131 -- If this is the case, eliminate the renamings as they are useless.
6132 -- This optimization is not performed when the condition was folded
6133 -- and validity checks are in effect because the original condition
6134 -- may have produced at least one check that depends on the generated
6138 and then Is_Entity_Name
(Cond
)
6139 and then Scope
(Entity
(Cond
)) /= Func_Id
6140 and then not Validity_Check_Operands
6142 Set_Declarations
(Func_Body
, Empty_List
);
6144 end Expand_Entry_Barrier
;
6146 ------------------------------
6147 -- Expand_N_Abort_Statement --
6148 ------------------------------
6150 -- Expand abort T1, T2, .. Tn; into:
6151 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6153 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6154 Loc
: constant Source_Ptr
:= Sloc
(N
);
6155 Tlist
: constant List_Id
:= Names
(N
);
6161 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6164 Tasknm
:= First
(Tlist
);
6166 while Present
(Tasknm
) loop
6169 -- A task interface class-wide type object is being aborted. Retrieve
6170 -- its _task_id by calling a dispatching routine.
6172 if Ada_Version
>= Ada_2005
6173 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6174 and then Is_Interface
(Etype
(Tasknm
))
6175 and then Is_Task_Interface
(Etype
(Tasknm
))
6177 Append_To
(Component_Associations
(Aggr
),
6178 Make_Component_Association
(Loc
,
6179 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6182 -- Task_Id (Tasknm._disp_get_task_id)
6184 Unchecked_Convert_To
6185 (RTE
(RO_ST_Task_Id
),
6186 Make_Selected_Component
(Loc
,
6187 Prefix
=> New_Copy_Tree
(Tasknm
),
6189 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6192 Append_To
(Component_Associations
(Aggr
),
6193 Make_Component_Association
(Loc
,
6194 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6195 Expression
=> Concurrent_Ref
(Tasknm
)));
6202 Make_Procedure_Call_Statement
(Loc
,
6203 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6204 Parameter_Associations
=> New_List
(
6205 Make_Qualified_Expression
(Loc
,
6206 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6207 Expression
=> Aggr
))));
6210 end Expand_N_Abort_Statement
;
6212 -------------------------------
6213 -- Expand_N_Accept_Statement --
6214 -------------------------------
6216 -- This procedure handles expansion of accept statements that stand alone,
6217 -- i.e. they are not part of an accept alternative. The expansion of
6218 -- accept statement in accept alternatives is handled by the routines
6219 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6220 -- following description applies only to stand alone accept statements.
6222 -- If there is no handled statement sequence, or only null statements, then
6223 -- this is called a trivial accept, and the expansion is:
6225 -- Accept_Trivial (entry-index)
6227 -- If there is a handled statement sequence, then the expansion is:
6234 -- Accept_Call (entry-index, Ann);
6235 -- Renaming_Declarations for formals
6236 -- <statement sequence from N_Accept_Statement node>
6237 -- Complete_Rendezvous;
6242 -- <exception handler from N_Accept_Statement node>
6243 -- Complete_Rendezvous;
6245 -- <exception handler from N_Accept_Statement node>
6246 -- Complete_Rendezvous;
6251 -- when all others =>
6252 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6255 -- The first three declarations were already inserted ahead of the accept
6256 -- statement by the Expand_Accept_Declarations procedure, which was called
6257 -- directly from the semantics during analysis of the accept statement,
6258 -- before analyzing its contained statements.
6260 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6261 -- from possible expansion activity (the original source of course does
6262 -- not have any declarations associated with the accept statement, since
6263 -- an accept statement has no declarative part). In particular, if the
6264 -- expander is active, the first such declaration is the declaration of
6265 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6267 -- The two blocks are merged into a single block if the inner block has
6268 -- no exception handlers, but otherwise two blocks are required, since
6269 -- exceptions might be raised in the exception handlers of the inner
6270 -- block, and Exceptional_Complete_Rendezvous must be called.
6272 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6273 Loc
: constant Source_Ptr
:= Sloc
(N
);
6274 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6275 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6276 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6277 Eent
: constant Entity_Id
:= Entity
(Ename
);
6278 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6279 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6280 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6286 -- If the accept statement is not part of a list, then its parent must
6287 -- be an accept alternative, and, as described above, we do not do any
6288 -- expansion for such accept statements at this level.
6290 if not Is_List_Member
(N
) then
6291 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6294 -- Trivial accept case (no statement sequence, or null statements).
6295 -- If the accept statement has declarations, then just insert them
6296 -- before the procedure call.
6298 elsif Trivial_Accept_OK
6299 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6301 -- Remove declarations for renamings, because the parameter block
6302 -- will not be assigned.
6309 D
:= First
(Declarations
(N
));
6310 while Present
(D
) loop
6312 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6320 if Present
(Declarations
(N
)) then
6321 Insert_Actions
(N
, Declarations
(N
));
6325 Make_Procedure_Call_Statement
(Loc
,
6326 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6327 Parameter_Associations
=> New_List
(
6328 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6332 -- Ada 2022 (AI12-0279)
6334 if Has_Yield_Aspect
(Eent
)
6335 and then RTE_Available
(RE_Yield
)
6337 Insert_Action_After
(N
,
6338 Make_Procedure_Call_Statement
(Loc
,
6339 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
6342 -- Discard Entry_Address that was created for it, so it will not be
6343 -- emitted if this accept statement is in the statement part of a
6344 -- delay alternative.
6346 if Present
(Stats
) then
6347 Remove_Last_Elmt
(Acstack
);
6350 -- Case of statement sequence present
6353 -- Construct the block, using the declarations from the accept
6354 -- statement if any to initialize the declarations of the block.
6356 Blkent
:= Make_Temporary
(Loc
, 'A');
6357 Mutate_Ekind
(Blkent
, E_Block
);
6358 Set_Etype
(Blkent
, Standard_Void_Type
);
6359 Set_Scope
(Blkent
, Current_Scope
);
6362 Make_Block_Statement
(Loc
,
6363 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6364 Declarations
=> Declarations
(N
),
6365 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6367 -- Reset the Scope of local entities associated with the accept
6368 -- statement (that currently reference the entry scope) to the
6369 -- block scope, to avoid having references to the locals treated
6370 -- as up-level references.
6372 Reset_Scopes_To
(Block
, Blkent
);
6374 -- For the analysis of the generated declarations, the parent node
6375 -- must be properly set.
6377 Set_Parent
(Block
, Parent
(N
));
6378 Set_Parent
(Blkent
, Block
);
6380 -- Prepend call to Accept_Call to main statement sequence If the
6381 -- accept has exception handlers, the statement sequence is wrapped
6382 -- in a block. Insert call and renaming declarations in the
6383 -- declarations of the block, so they are elaborated before the
6387 Make_Procedure_Call_Statement
(Loc
,
6388 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6389 Parameter_Associations
=> New_List
(
6390 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6391 New_Occurrence_Of
(Ann
, Loc
)));
6393 if Parent
(Stats
) = N
then
6394 Prepend
(Call
, Statements
(Stats
));
6396 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6401 Push_Scope
(Blkent
);
6409 D
:= First
(Declarations
(N
));
6410 while Present
(D
) loop
6413 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6415 -- The renaming declarations for the formals were created
6416 -- during analysis of the accept statement, and attached to
6417 -- the list of declarations. Place them now in the context
6418 -- of the accept block or subprogram.
6421 Typ
:= Entity
(Subtype_Mark
(D
));
6422 Insert_After
(Call
, D
);
6425 -- If the formal is class_wide, it does not have an actual
6426 -- subtype. The analysis of the renaming declaration creates
6427 -- one, but we need to retain the class-wide nature of the
6430 if Is_Class_Wide_Type
(Typ
) then
6431 Set_Etype
(Defining_Identifier
(D
), Typ
);
6442 -- Replace the accept statement by the new block
6447 -- Last step is to unstack the Accept_Address value
6449 Remove_Last_Elmt
(Acstack
);
6451 end Expand_N_Accept_Statement
;
6453 ----------------------------------
6454 -- Expand_N_Asynchronous_Select --
6455 ----------------------------------
6457 -- This procedure assumes that the trigger statement is an entry call or
6458 -- a dispatching procedure call. A delay alternative should already have
6459 -- been expanded into an entry call to the appropriate delay object Wait
6462 -- If the trigger is a task entry call, the select is implemented with
6463 -- a Task_Entry_Call:
6468 -- P : parms := (parm, parm, parm);
6470 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6472 -- procedure _clean is
6475 -- Cancel_Task_Entry_Call (C);
6482 -- (<acceptor-task>, -- Acceptor
6483 -- <entry-index>, -- E
6484 -- P'Address, -- Uninterpreted_Data
6485 -- Asynchronous_Call, -- Mode
6486 -- B); -- Rendezvous_Successful
6493 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6496 -- when Abort_Signal => Abort_Undefer;
6503 -- <triggered-statements>
6507 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6508 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6512 -- P : parms := (parm, parm, parm);
6514 -- Call_Simple (acceptor-task, entry-index, P'Address);
6520 -- so the task at hand is to convert the latter expansion into the former
6522 -- If the trigger is a protected entry call, the select is implemented
6523 -- with Protected_Entry_Call:
6526 -- P : E1_Params := (param, param, param);
6527 -- Bnn : Communications_Block;
6532 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6534 -- procedure _clean is
6537 -- if Enqueued (Bnn) then
6538 -- Cancel_Protected_Entry_Call (Bnn);
6545 -- Protected_Entry_Call
6546 -- (po._object'Access, -- Object
6547 -- <entry index>, -- E
6548 -- P'Address, -- Uninterpreted_Data
6549 -- Asynchronous_Call, -- Mode
6552 -- if Enqueued (Bnn) then
6556 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6559 -- when Abort_Signal => Abort_Undefer;
6562 -- if not Cancelled (Bnn) then
6563 -- <triggered-statements>
6567 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6571 -- P : E1_Params := (param, param, param);
6572 -- Bnn : Communications_Block;
6575 -- Protected_Entry_Call
6576 -- (po._object'Access, -- Object
6577 -- <entry index>, -- E
6578 -- P'Address, -- Uninterpreted_Data
6579 -- Simple_Call, -- Mode
6586 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6590 -- B : Boolean := False;
6591 -- Bnn : Communication_Block;
6592 -- C : Ada.Tags.Prim_Op_Kind;
6593 -- D : System.Storage_Elements.Dummy_Communication_Block;
6594 -- K : Ada.Tags.Tagged_Kind :=
6595 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6596 -- P : Parameters := (Param1 .. ParamN);
6601 -- if K = Ada.Tags.TK_Limited_Tagged
6602 -- or else K = Ada.Tags.TK_Tagged
6604 -- <dispatching-call>;
6605 -- <triggering-statements>;
6609 -- Ada.Tags.Get_Offset_Index
6610 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6612 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6614 -- if C = POK_Protected_Entry then
6616 -- procedure _clean is
6618 -- if Enqueued (Bnn) then
6619 -- Cancel_Protected_Entry_Call (Bnn);
6625 -- _Disp_Asynchronous_Select
6626 -- (<object>, S, P'Address, D, B);
6627 -- Bnn := Communication_Block (D);
6629 -- Param1 := P.Param1;
6631 -- ParamN := P.ParamN;
6633 -- if Enqueued (Bnn) then
6634 -- <abortable-statements>
6637 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6640 -- when Abort_Signal => Abort_Undefer;
6643 -- if not Cancelled (Bnn) then
6644 -- <triggering-statements>
6647 -- elsif C = POK_Task_Entry then
6649 -- procedure _clean is
6651 -- Cancel_Task_Entry_Call (U);
6657 -- _Disp_Asynchronous_Select
6658 -- (<object>, S, P'Address, D, B);
6659 -- Bnn := Communication_Bloc (D);
6661 -- Param1 := P.Param1;
6663 -- ParamN := P.ParamN;
6668 -- <abortable-statements>
6670 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6673 -- when Abort_Signal => Abort_Undefer;
6677 -- <triggering-statements>
6682 -- <dispatching-call>;
6683 -- <triggering-statements>
6688 -- The job is to convert this to the asynchronous form
6690 -- If the trigger is a delay statement, it will have been expanded into
6691 -- a call to one of the GNARL delay procedures. This routine will convert
6692 -- this into a protected entry call on a delay object and then continue
6693 -- processing as for a protected entry call trigger. This requires
6694 -- declaring a Delay_Block object and adding a pointer to this object to
6695 -- the parameter list of the delay procedure to form the parameter list of
6696 -- the entry call. This object is used by the runtime to queue the delay
6699 -- For a description of the use of P and the assignments after the call,
6700 -- see Expand_N_Entry_Call_Statement.
6702 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6703 Loc
: constant Source_Ptr
:= Sloc
(N
);
6704 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6705 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6707 Abort_Block_Ent
: Entity_Id
;
6708 Abortable_Block
: Node_Id
;
6711 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6712 Blk_Typ
: Entity_Id
;
6714 Call_Ent
: Entity_Id
;
6715 Cancel_Param
: Entity_Id
;
6716 Cleanup_Block
: Node_Id
;
6717 Cleanup_Block_Ent
: Entity_Id
;
6718 Cleanup_Stmts
: List_Id
;
6719 Conc_Typ_Stmts
: List_Id
;
6721 Dblock_Ent
: Entity_Id
;
6726 Enqueue_Call
: Node_Id
;
6730 Lim_Typ_Stmts
: List_Id
;
6736 ProtE_Stmts
: List_Id
;
6737 ProtP_Stmts
: List_Id
;
6740 TaskE_Stmts
: List_Id
;
6743 B
: Entity_Id
; -- Call status flag
6744 Bnn
: Entity_Id
; -- Communication block
6745 C
: Entity_Id
; -- Call kind
6746 K
: Entity_Id
; -- Tagged kind
6747 P
: Entity_Id
; -- Parameter block
6748 S
: Entity_Id
; -- Primitive operation slot
6749 T
: Entity_Id
; -- Additional status flag
6751 procedure Rewrite_Abortable_Part
;
6752 -- If the trigger is a dispatching call, the expansion inserts multiple
6753 -- copies of the abortable part. This is both inefficient, and may lead
6754 -- to duplicate definitions that the back-end will reject, when the
6755 -- abortable part includes loops. This procedure rewrites the abortable
6756 -- part into a call to a generated procedure.
6758 ----------------------------
6759 -- Rewrite_Abortable_Part --
6760 ----------------------------
6762 procedure Rewrite_Abortable_Part
is
6763 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6768 Make_Subprogram_Body
(Loc
,
6770 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6771 Declarations
=> New_List
,
6772 Handled_Statement_Sequence
=>
6773 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6774 Insert_Before
(N
, Decl
);
6777 -- Rewrite abortable part into a call to this procedure
6781 Make_Procedure_Call_Statement
(Loc
,
6782 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6783 end Rewrite_Abortable_Part
;
6785 -- Start of processing for Expand_N_Asynchronous_Select
6788 -- Asynchronous select is not supported on restricted runtimes. Don't
6791 if Restricted_Profile
then
6795 Process_Statements_For_Controlled_Objects
(Trig
);
6796 Process_Statements_For_Controlled_Objects
(Abrt
);
6798 Ecall
:= Triggering_Statement
(Trig
);
6800 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6802 -- Retrieve Astats and Tstats now because the finalization machinery may
6803 -- wrap them in blocks.
6805 Astats
:= Statements
(Abrt
);
6806 Tstats
:= Statements
(Trig
);
6808 -- The arguments in the call may require dynamic allocation, and the
6809 -- call statement may have been transformed into a block. The block
6810 -- may contain additional declarations for internal entities, and the
6811 -- original call is found by sequential search.
6813 if Nkind
(Ecall
) = N_Block_Statement
then
6814 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6815 while Nkind
(Ecall
) not in
6816 N_Procedure_Call_Statement | N_Entry_Call_Statement
6822 -- This is either a dispatching call or a delay statement used as a
6823 -- trigger which was expanded into a procedure call.
6825 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6826 if Ada_Version
>= Ada_2005
6828 (No
(Original_Node
(Ecall
))
6829 or else Nkind
(Original_Node
(Ecall
)) not in N_Delay_Statement
)
6831 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6833 Rewrite_Abortable_Part
;
6837 -- Call status flag processing, generate:
6838 -- B : Boolean := False;
6840 B
:= Build_B
(Loc
, Decls
);
6842 -- Communication block processing, generate:
6843 -- Bnn : Communication_Block;
6845 Bnn
:= Make_Temporary
(Loc
, 'B');
6847 Make_Object_Declaration
(Loc
,
6848 Defining_Identifier
=> Bnn
,
6849 Object_Definition
=>
6850 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
6852 -- Call kind processing, generate:
6853 -- C : Ada.Tags.Prim_Op_Kind;
6855 C
:= Build_C
(Loc
, Decls
);
6857 -- Tagged kind processing, generate:
6858 -- K : Ada.Tags.Tagged_Kind :=
6859 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6861 -- Dummy communication block, generate:
6862 -- D : Dummy_Communication_Block;
6865 Make_Object_Declaration
(Loc
,
6866 Defining_Identifier
=>
6867 Make_Defining_Identifier
(Loc
, Name_uD
),
6868 Object_Definition
=>
6870 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
6872 K
:= Build_K
(Loc
, Decls
, Obj
);
6874 -- Parameter block processing
6876 Blk_Typ
:= Build_Parameter_Block
6877 (Loc
, Actuals
, Formals
, Decls
);
6878 P
:= Parameter_Block_Pack
6879 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6881 -- Dispatch table slot processing, generate:
6884 S
:= Build_S
(Loc
, Decls
);
6886 -- Additional status flag processing, generate:
6889 T
:= Make_Temporary
(Loc
, 'T');
6891 Make_Object_Declaration
(Loc
,
6892 Defining_Identifier
=> T
,
6893 Object_Definition
=>
6894 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
6896 ------------------------------
6897 -- Protected entry handling --
6898 ------------------------------
6901 -- Param1 := P.Param1;
6903 -- ParamN := P.ParamN;
6905 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6908 -- Bnn := Communication_Block (D);
6910 Prepend_To
(Cleanup_Stmts
,
6911 Make_Assignment_Statement
(Loc
,
6912 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
6914 Unchecked_Convert_To
6915 (RTE
(RE_Communication_Block
),
6916 Make_Identifier
(Loc
, Name_uD
))));
6919 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6921 Prepend_To
(Cleanup_Stmts
,
6922 Make_Procedure_Call_Statement
(Loc
,
6926 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
6928 Parameter_Associations
=>
6930 New_Copy_Tree
(Obj
), -- <object>
6931 New_Occurrence_Of
(S
, Loc
), -- S
6932 Make_Attribute_Reference
(Loc
, -- P'Address
6933 Prefix
=> New_Occurrence_Of
(P
, Loc
),
6934 Attribute_Name
=> Name_Address
),
6935 Make_Identifier
(Loc
, Name_uD
), -- D
6936 New_Occurrence_Of
(B
, Loc
)))); -- B
6939 -- if Enqueued (Bnn) then
6940 -- <abortable-statements>
6943 Append_To
(Cleanup_Stmts
,
6944 Make_Implicit_If_Statement
(N
,
6946 Make_Function_Call
(Loc
,
6948 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
6949 Parameter_Associations
=>
6950 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
6953 New_Copy_List_Tree
(Astats
)));
6955 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6956 -- will then generate a _clean for the communication block Bnn.
6960 -- procedure _clean is
6962 -- if Enqueued (Bnn) then
6963 -- Cancel_Protected_Entry_Call (Bnn);
6972 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
6974 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
6976 -- Wrap the cleanup block in an exception handling block
6982 -- when Abort_Signal => Abort_Undefer;
6985 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
6988 Make_Implicit_Label_Declaration
(Loc
,
6989 Defining_Identifier
=> Abort_Block_Ent
),
6992 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
6995 -- if not Cancelled (Bnn) then
6996 -- <triggering-statements>
6999 Append_To
(ProtE_Stmts
,
7000 Make_Implicit_If_Statement
(N
,
7004 Make_Function_Call
(Loc
,
7006 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7007 Parameter_Associations
=>
7008 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7011 New_Copy_List_Tree
(Tstats
)));
7013 -------------------------
7014 -- Task entry handling --
7015 -------------------------
7018 -- Param1 := P.Param1;
7020 -- ParamN := P.ParamN;
7022 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7025 -- Bnn := Communication_Block (D);
7027 Append_To
(TaskE_Stmts
,
7028 Make_Assignment_Statement
(Loc
,
7030 New_Occurrence_Of
(Bnn
, Loc
),
7032 Unchecked_Convert_To
7033 (RTE
(RE_Communication_Block
),
7034 Make_Identifier
(Loc
, Name_uD
))));
7037 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7039 Prepend_To
(TaskE_Stmts
,
7040 Make_Procedure_Call_Statement
(Loc
,
7043 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7044 Name_uDisp_Asynchronous_Select
),
7047 Parameter_Associations
=> New_List
(
7048 New_Copy_Tree
(Obj
), -- <object>
7049 New_Occurrence_Of
(S
, Loc
), -- S
7050 Make_Attribute_Reference
(Loc
, -- P'Address
7051 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7052 Attribute_Name
=> Name_Address
),
7053 Make_Identifier
(Loc
, Name_uD
), -- D
7054 New_Occurrence_Of
(B
, Loc
)))); -- B
7059 Prepend_To
(TaskE_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7063 -- <abortable-statements>
7065 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7068 (Cleanup_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7070 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7071 -- will generate a _clean for the additional status flag.
7075 -- procedure _clean is
7077 -- Cancel_Task_Entry_Call (U);
7085 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7087 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7089 -- Wrap the cleanup block in an exception handling block
7095 -- when Abort_Signal => Abort_Undefer;
7098 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7100 Append_To
(TaskE_Stmts
,
7101 Make_Implicit_Label_Declaration
(Loc
,
7102 Defining_Identifier
=> Abort_Block_Ent
));
7104 Append_To
(TaskE_Stmts
,
7106 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7110 -- <triggering-statements>
7113 Append_To
(TaskE_Stmts
,
7114 Make_Implicit_If_Statement
(N
,
7116 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7119 New_Copy_List_Tree
(Tstats
)));
7121 ----------------------------------
7122 -- Protected procedure handling --
7123 ----------------------------------
7126 -- <dispatching-call>;
7127 -- <triggering-statements>
7129 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7130 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7133 -- S := Ada.Tags.Get_Offset_Index
7134 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7137 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7140 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7142 Append_To
(Conc_Typ_Stmts
,
7143 Make_Procedure_Call_Statement
(Loc
,
7146 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7147 Name_uDisp_Get_Prim_Op_Kind
),
7149 Parameter_Associations
=>
7151 New_Copy_Tree
(Obj
),
7152 New_Occurrence_Of
(S
, Loc
),
7153 New_Occurrence_Of
(C
, Loc
))));
7156 -- if C = POK_Procedure_Entry then
7158 -- elsif C = POK_Task_Entry then
7164 Append_To
(Conc_Typ_Stmts
,
7165 Make_Implicit_If_Statement
(N
,
7169 New_Occurrence_Of
(C
, Loc
),
7171 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7178 Make_Elsif_Part
(Loc
,
7182 New_Occurrence_Of
(C
, Loc
),
7184 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7193 -- <dispatching-call>;
7194 -- <triggering-statements>
7196 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7197 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7200 -- if K = Ada.Tags.TK_Limited_Tagged
7201 -- or else K = Ada.Tags.TK_Tagged
7209 Make_Implicit_If_Statement
(N
,
7210 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7211 Then_Statements
=> Lim_Typ_Stmts
,
7212 Else_Statements
=> Conc_Typ_Stmts
));
7215 Make_Block_Statement
(Loc
,
7218 Handled_Statement_Sequence
=>
7219 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7224 -- Delay triggering statement processing
7227 -- Add a Delay_Block object to the parameter list of the delay
7228 -- procedure to form the parameter list of the Wait entry call.
7230 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7232 Pdef
:= Entity
(Name
(Ecall
));
7234 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7236 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7238 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7240 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7242 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7243 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7246 Append_To
(Parameter_Associations
(Ecall
),
7247 Make_Attribute_Reference
(Loc
,
7248 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7249 Attribute_Name
=> Name_Unchecked_Access
));
7251 -- Create the inner block to protect the abortable part
7253 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7255 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7258 Make_Block_Statement
(Loc
,
7259 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7260 Handled_Statement_Sequence
=>
7261 Make_Handled_Sequence_Of_Statements
(Loc
,
7262 Statements
=> Astats
),
7263 Has_Created_Identifier
=> True,
7264 Is_Asynchronous_Call_Block
=> True);
7266 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7269 Make_Implicit_If_Statement
(N
,
7271 Make_Function_Call
(Loc
,
7272 Name
=> Enqueue_Call
,
7273 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7275 New_List
(Make_Block_Statement
(Loc
,
7276 Handled_Statement_Sequence
=>
7277 Make_Handled_Sequence_Of_Statements
(Loc
,
7278 Statements
=> New_List
(
7279 Make_Implicit_Label_Declaration
(Loc
,
7280 Defining_Identifier
=> Blk_Ent
,
7281 Label_Construct
=> Abortable_Block
),
7283 Exception_Handlers
=> Hdle
)))));
7285 Stmts
:= New_List
(Ecall
);
7287 -- Construct statement sequence for new block
7290 Make_Implicit_If_Statement
(N
,
7292 Make_Function_Call
(Loc
,
7293 Name
=> New_Occurrence_Of
(
7294 RTE
(RE_Timed_Out
), Loc
),
7295 Parameter_Associations
=> New_List
(
7296 Make_Attribute_Reference
(Loc
,
7297 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7298 Attribute_Name
=> Name_Unchecked_Access
))),
7299 Then_Statements
=> Tstats
));
7301 -- The result is the new block
7303 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7306 Make_Block_Statement
(Loc
,
7307 Declarations
=> New_List
(
7308 Make_Object_Declaration
(Loc
,
7309 Defining_Identifier
=> Dblock_Ent
,
7310 Aliased_Present
=> True,
7311 Object_Definition
=>
7312 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7314 Handled_Statement_Sequence
=>
7315 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7325 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7326 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7328 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7329 Decls
:= Declarations
(Ecall
);
7331 if Is_Protected_Type
(Etype
(Concval
)) then
7333 -- Get the declarations of the block expanded from the entry call
7335 Decl
:= First
(Decls
);
7336 while Present
(Decl
)
7337 and then (Nkind
(Decl
) /= N_Object_Declaration
7338 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7339 RE_Communication_Block
))
7344 pragma Assert
(Present
(Decl
));
7345 Cancel_Param
:= Defining_Identifier
(Decl
);
7347 -- Change the mode of the Protected_Entry_Call call
7349 -- Protected_Entry_Call (
7350 -- Object => po._object'Access,
7351 -- E => <entry index>;
7352 -- Uninterpreted_Data => P'Address;
7353 -- Mode => Asynchronous_Call;
7356 -- Skip assignments to temporaries created for in-out parameters
7358 -- This makes unwarranted assumptions about the shape of the expanded
7359 -- tree for the call, and should be cleaned up ???
7361 Stmt
:= First
(Stmts
);
7362 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7368 Param
:= First
(Parameter_Associations
(Call
));
7369 while Present
(Param
)
7370 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7375 pragma Assert
(Present
(Param
));
7376 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7379 -- Append an if statement to execute the abortable part
7382 -- if Enqueued (Bnn) then
7385 Make_Implicit_If_Statement
(N
,
7387 Make_Function_Call
(Loc
,
7388 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7389 Parameter_Associations
=> New_List
(
7390 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7391 Then_Statements
=> Astats
));
7394 Make_Block_Statement
(Loc
,
7395 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7396 Handled_Statement_Sequence
=>
7397 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7398 Has_Created_Identifier
=> True,
7399 Is_Asynchronous_Call_Block
=> True);
7402 Make_Block_Statement
(Loc
,
7403 Handled_Statement_Sequence
=>
7404 Make_Handled_Sequence_Of_Statements
(Loc
,
7405 Statements
=> New_List
(
7406 Make_Implicit_Label_Declaration
(Loc
,
7407 Defining_Identifier
=> Blk_Ent
,
7408 Label_Construct
=> Abortable_Block
),
7413 Exception_Handlers
=> New_List
(
7414 Make_Implicit_Exception_Handler
(Loc
,
7416 -- when Abort_Signal =>
7419 Exception_Choices
=>
7420 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7421 Statements
=> New_List
(Make_Null_Statement
(Loc
)))))),
7423 -- if not Cancelled (Bnn) then
7424 -- triggered statements
7427 Make_Implicit_If_Statement
(N
,
7428 Condition
=> Make_Op_Not
(Loc
,
7430 Make_Function_Call
(Loc
,
7431 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7432 Parameter_Associations
=> New_List
(
7433 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7434 Then_Statements
=> Tstats
));
7436 -- Asynchronous task entry call
7443 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7445 -- Insert declaration of B in declarations of existing block
7448 Make_Object_Declaration
(Loc
,
7449 Defining_Identifier
=> B
,
7450 Object_Definition
=>
7451 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7453 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7455 -- Insert the declaration of C in the declarations of the existing
7456 -- block. The variable is initialized to something (True or False,
7457 -- does not matter) to prevent CodePeer from complaining about a
7458 -- possible read of an uninitialized variable.
7461 Make_Object_Declaration
(Loc
,
7462 Defining_Identifier
=> Cancel_Param
,
7463 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
7464 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
),
7465 Has_Init_Expression
=> True));
7467 -- Remove and save the call to Call_Simple
7469 Stmt
:= First
(Stmts
);
7471 -- Skip assignments to temporaries created for in-out parameters.
7472 -- This makes unwarranted assumptions about the shape of the expanded
7473 -- tree for the call, and should be cleaned up ???
7475 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7481 -- Create the inner block to protect the abortable part
7483 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7485 if Abort_Allowed
then
7486 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7490 Make_Block_Statement
(Loc
,
7491 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7492 Handled_Statement_Sequence
=>
7493 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7494 Has_Created_Identifier
=> True,
7495 Is_Asynchronous_Call_Block
=> True);
7498 Make_Block_Statement
(Loc
,
7499 Handled_Statement_Sequence
=>
7500 Make_Handled_Sequence_Of_Statements
(Loc
,
7501 Statements
=> New_List
(
7502 Make_Implicit_Label_Declaration
(Loc
,
7503 Defining_Identifier
=> Blk_Ent
,
7504 Label_Construct
=> Abortable_Block
),
7506 Exception_Handlers
=> Hdle
)));
7508 -- Create new call statement
7510 Params
:= Parameter_Associations
(Call
);
7513 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7514 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7517 Make_Procedure_Call_Statement
(Loc
,
7518 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7519 Parameter_Associations
=> Params
));
7521 -- Construct statement sequence for new block
7524 Make_Implicit_If_Statement
(N
,
7526 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7527 Then_Statements
=> Tstats
));
7529 -- Protected the call against abort
7531 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7534 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7536 -- The result is the new block
7539 Make_Block_Statement
(Loc
,
7540 Declarations
=> Decls
,
7541 Handled_Statement_Sequence
=>
7542 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7545 end Expand_N_Asynchronous_Select
;
7547 -------------------------------------
7548 -- Expand_N_Conditional_Entry_Call --
7549 -------------------------------------
7551 -- The conditional task entry call is converted to a call to
7556 -- P : parms := (parm, parm, parm);
7560 -- (<acceptor-task>, -- Acceptor
7561 -- <entry-index>, -- E
7562 -- P'Address, -- Uninterpreted_Data
7563 -- Conditional_Call, -- Mode
7564 -- B); -- Rendezvous_Successful
7569 -- normal-statements
7575 -- For a description of the use of P and the assignments after the call,
7576 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7577 -- conditional entry call has already been expanded (by the Expand_N_Entry
7578 -- _Call_Statement procedure) as follows:
7581 -- P : parms := (parm, parm, parm);
7583 -- ... info for in-out parameters
7584 -- Call_Simple (acceptor-task, entry-index, P'Address);
7590 -- so the task at hand is to convert the latter expansion into the former
7592 -- The conditional protected entry call is converted to a call to
7593 -- Protected_Entry_Call:
7596 -- P : parms := (parm, parm, parm);
7597 -- Bnn : Communications_Block;
7600 -- Protected_Entry_Call
7601 -- (po._object'Access, -- Object
7602 -- <entry index>, -- E
7603 -- P'Address, -- Uninterpreted_Data
7604 -- Conditional_Call, -- Mode
7609 -- if Cancelled (Bnn) then
7612 -- normal-statements
7616 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7620 -- B : Boolean := False;
7621 -- C : Ada.Tags.Prim_Op_Kind;
7622 -- K : Ada.Tags.Tagged_Kind :=
7623 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7624 -- P : Parameters := (Param1 .. ParamN);
7628 -- if K = Ada.Tags.TK_Limited_Tagged
7629 -- or else K = Ada.Tags.TK_Tagged
7631 -- <dispatching-call>;
7632 -- -- <triggering-statements> (code factorized after if-stmt)
7636 -- Ada.Tags.Get_Offset_Index
7637 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7639 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7641 -- if C = POK_Protected_Entry
7642 -- or else C = POK_Task_Entry
7644 -- Param1 := P.Param1;
7646 -- ParamN := P.ParamN;
7650 -- if C = POK_Procedure
7651 -- or else C = POK_Protected_Procedure
7652 -- or else C = POK_Task_Procedure
7654 -- <dispatching-call>;
7657 -- -- <triggering-statements> (code factorized after if-stmt)
7659 -- <else-statements>
7660 -- goto L0; -- skip triggering statements
7663 -- <triggering-statements>
7667 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7668 Loc
: constant Source_Ptr
:= Sloc
(N
);
7669 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7670 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7673 Blk_Typ
: Entity_Id
;
7675 Call_Ent
: Entity_Id
;
7676 Conc_Typ_Stmts
: List_Id
;
7681 Label_Id
: Entity_Id
:= Empty
;
7682 Lim_Typ_Stmts
: List_Id
;
7689 Transient_Blk
: Node_Id
;
7692 B
: Entity_Id
; -- Call status flag
7693 C
: Entity_Id
; -- Call kind
7694 K
: Entity_Id
; -- Tagged kind
7695 P
: Entity_Id
; -- Parameter block
7696 S
: Entity_Id
; -- Primitive operation slot
7699 Process_Statements_For_Controlled_Objects
(N
);
7701 if Ada_Version
>= Ada_2005
7702 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7704 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7709 -- Call status flag processing, generate:
7710 -- B : Boolean := False;
7712 B
:= Build_B
(Loc
, Decls
);
7714 -- Call kind processing, generate:
7715 -- C : Ada.Tags.Prim_Op_Kind;
7717 C
:= Build_C
(Loc
, Decls
);
7719 -- Tagged kind processing, generate:
7720 -- K : Ada.Tags.Tagged_Kind :=
7721 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7723 K
:= Build_K
(Loc
, Decls
, Obj
);
7725 -- Parameter block processing
7727 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7728 P
:= Parameter_Block_Pack
7729 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7731 -- Dispatch table slot processing, generate:
7734 S
:= Build_S
(Loc
, Decls
);
7737 -- S := Ada.Tags.Get_Offset_Index
7738 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7741 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7744 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7746 Append_To
(Conc_Typ_Stmts
,
7747 Make_Procedure_Call_Statement
(Loc
,
7750 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7751 Name_uDisp_Conditional_Select
),
7753 Parameter_Associations
=>
7755 New_Copy_Tree
(Obj
), -- <object>
7756 New_Occurrence_Of
(S
, Loc
), -- S
7757 Make_Attribute_Reference
(Loc
, -- P'Address
7758 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7759 Attribute_Name
=> Name_Address
),
7760 New_Occurrence_Of
(C
, Loc
), -- C
7761 New_Occurrence_Of
(B
, Loc
)))); -- B
7764 -- if C = POK_Protected_Entry
7765 -- or else C = POK_Task_Entry
7767 -- Param1 := P.Param1;
7769 -- ParamN := P.ParamN;
7772 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7774 -- Generate the if statement only when the packed parameters need
7775 -- explicit assignments to their corresponding actuals.
7777 if Present
(Unpack
) then
7778 Append_To
(Conc_Typ_Stmts
,
7779 Make_Implicit_If_Statement
(N
,
7785 New_Occurrence_Of
(C
, Loc
),
7787 New_Occurrence_Of
(RTE
(
7788 RE_POK_Protected_Entry
), Loc
)),
7793 New_Occurrence_Of
(C
, Loc
),
7795 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
7797 Then_Statements
=> Unpack
));
7802 -- if C = POK_Procedure
7803 -- or else C = POK_Protected_Procedure
7804 -- or else C = POK_Task_Procedure
7806 -- <dispatching-call>
7808 -- -- <triggering-stataments> (code factorized after if-stmt)
7810 -- <else-statements>
7811 -- goto L0; -- skip triggering statements
7814 N_Stats
:= New_List
;
7816 Prepend_To
(N_Stats
,
7817 Make_Implicit_If_Statement
(N
,
7823 New_Occurrence_Of
(C
, Loc
),
7825 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
7832 New_Occurrence_Of
(C
, Loc
),
7834 New_Occurrence_Of
(RTE
(
7835 RE_POK_Protected_Procedure
), Loc
)),
7840 New_Occurrence_Of
(C
, Loc
),
7842 New_Occurrence_Of
(RTE
(
7843 RE_POK_Task_Procedure
), Loc
)))),
7848 Label_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', 0));
7849 Set_Entity
(Label_Id
,
7850 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
7852 Append_To
(Else_Statements
(N
),
7853 Make_Goto_Statement
(Loc
,
7854 Name
=> New_Occurrence_Of
(Entity
(Label_Id
), Loc
)));
7856 Append_To
(Conc_Typ_Stmts
,
7857 Make_Implicit_If_Statement
(N
,
7858 Condition
=> New_Occurrence_Of
(B
, Loc
),
7859 Then_Statements
=> N_Stats
,
7860 Else_Statements
=> Else_Statements
(N
)));
7863 -- <dispatching-call>;
7864 -- -- <triggering-statements> (code factorized after if-stmt)
7866 Lim_Typ_Stmts
:= New_List
(New_Copy_Tree
(Blk
));
7869 -- if K = Ada.Tags.TK_Limited_Tagged
7870 -- or else K = Ada.Tags.TK_Tagged
7878 Make_Implicit_If_Statement
(N
,
7879 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7880 Then_Statements
=> Lim_Typ_Stmts
,
7881 Else_Statements
=> Conc_Typ_Stmts
));
7883 Label
:= Make_Label
(Loc
, Label_Id
);
7885 Make_Implicit_Label_Declaration
(Loc
,
7886 Defining_Identifier
=> Entity
(Label_Id
),
7887 Label_Construct
=> Label
));
7889 Append_List_To
(Stmts
, Statements
(Alt
)); -- triggering-statements
7890 Append_To
(Stmts
, Label
);
7893 Make_Block_Statement
(Loc
,
7896 Handled_Statement_Sequence
=>
7897 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7899 -- As described above, the entry alternative is transformed into a
7900 -- block that contains the gnulli call, and possibly assignment
7901 -- statements for in-out parameters. The gnulli call may itself be
7902 -- rewritten into a transient block if some unconstrained parameters
7903 -- require it. We need to retrieve the call to complete its parameter
7908 First
(Statements
(Handled_Statement_Sequence
(Blk
)));
7910 if Present
(Transient_Blk
)
7911 and then Nkind
(Transient_Blk
) = N_Block_Statement
7913 Blk
:= Transient_Blk
;
7916 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
7917 Stmt
:= First
(Stmts
);
7918 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7923 Params
:= Parameter_Associations
(Call
);
7925 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
7927 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7929 Param
:= First
(Params
);
7930 while Present
(Param
)
7931 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7936 pragma Assert
(Present
(Param
));
7938 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
7942 -- Find the Communication_Block parameter for the call to the
7943 -- Cancelled function.
7945 Decl
:= First
(Declarations
(Blk
));
7946 while Present
(Decl
)
7947 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7948 RE_Communication_Block
)
7953 -- Add an if statement to execute the else part if the call
7954 -- does not succeed (as indicated by the Cancelled predicate).
7957 Make_Implicit_If_Statement
(N
,
7958 Condition
=> Make_Function_Call
(Loc
,
7959 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7960 Parameter_Associations
=> New_List
(
7961 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
7962 Then_Statements
=> Else_Statements
(N
),
7963 Else_Statements
=> Statements
(Alt
)));
7966 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7968 -- Insert declaration of B in declarations of existing block
7970 if No
(Declarations
(Blk
)) then
7971 Set_Declarations
(Blk
, New_List
);
7974 Prepend_To
(Declarations
(Blk
),
7975 Make_Object_Declaration
(Loc
,
7976 Defining_Identifier
=> B
,
7977 Object_Definition
=>
7978 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7980 -- Create new call statement
7983 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
7984 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7987 Make_Procedure_Call_Statement
(Loc
,
7988 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7989 Parameter_Associations
=> Params
));
7991 -- Construct statement sequence for new block
7994 Make_Implicit_If_Statement
(N
,
7995 Condition
=> New_Occurrence_Of
(B
, Loc
),
7996 Then_Statements
=> Statements
(Alt
),
7997 Else_Statements
=> Else_Statements
(N
)));
8000 -- The result is the new block
8003 Make_Block_Statement
(Loc
,
8004 Declarations
=> Declarations
(Blk
),
8005 Handled_Statement_Sequence
=>
8006 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8011 Reset_Scopes_To
(N
, Entity
(Identifier
(N
)));
8012 end Expand_N_Conditional_Entry_Call
;
8014 ---------------------------------------
8015 -- Expand_N_Delay_Relative_Statement --
8016 ---------------------------------------
8018 -- Delay statement is implemented as a procedure call to Delay_For
8019 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8020 -- simple delays imposed by the use of Protected Objects.
8022 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8023 Loc
: constant Source_Ptr
:= Sloc
(N
);
8027 -- Try to use Ada.Calendar.Delays.Delay_For if available.
8029 if RTE_Available
(RO_CA_Delay_For
) then
8030 Proc
:= RTE
(RO_CA_Delay_For
);
8032 -- Otherwise, use System.Relative_Delays.Delay_For and emit an error
8033 -- message if not available. This is the implementation used on
8034 -- restricted platforms when Ada.Calendar is not available.
8037 Proc
:= RTE
(RO_RD_Delay_For
);
8041 Make_Procedure_Call_Statement
(Loc
,
8042 Name
=> New_Occurrence_Of
(Proc
, Loc
),
8043 Parameter_Associations
=> New_List
(Expression
(N
))));
8045 end Expand_N_Delay_Relative_Statement
;
8047 ------------------------------------
8048 -- Expand_N_Delay_Until_Statement --
8049 ------------------------------------
8051 -- Delay Until statement is implemented as a procedure call to
8052 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8054 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8055 Loc
: constant Source_Ptr
:= Sloc
(N
);
8059 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8060 Typ
:= RTE
(RO_CA_Delay_Until
);
8062 Typ
:= RTE
(RO_RT_Delay_Until
);
8066 Make_Procedure_Call_Statement
(Loc
,
8067 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8068 Parameter_Associations
=> New_List
(Expression
(N
))));
8071 end Expand_N_Delay_Until_Statement
;
8073 -------------------------
8074 -- Expand_N_Entry_Body --
8075 -------------------------
8077 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8079 -- Associate discriminals with the next protected operation body to be
8082 if Present
(Next_Protected_Operation
(N
)) then
8083 Set_Discriminals
(Parent
(Current_Scope
));
8085 end Expand_N_Entry_Body
;
8087 -----------------------------------
8088 -- Expand_N_Entry_Call_Statement --
8089 -----------------------------------
8091 -- An entry call is expanded into GNARLI calls to implement a simple entry
8092 -- call (see Build_Simple_Entry_Call).
8094 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8100 if No_Run_Time_Mode
then
8101 Error_Msg_CRT
("entry call", N
);
8105 -- If this entry call is part of an asynchronous select, don't expand it
8106 -- here; it will be expanded with the select statement. Don't expand
8107 -- timed entry calls either, as they are translated into asynchronous
8110 -- ??? This whole approach is questionable; it may be better to go back
8111 -- to allowing the expansion to take place and then attempting to fix it
8112 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8113 -- whether the expanded call is on a task or protected entry.
8115 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8116 or else N
/= Triggering_Statement
(Parent
(N
)))
8117 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8118 or else N
/= Entry_Call_Statement
(Parent
(N
))
8119 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8121 Extract_Entry
(N
, Concval
, Ename
, Index
);
8122 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8124 end Expand_N_Entry_Call_Statement
;
8126 --------------------------------
8127 -- Expand_N_Entry_Declaration --
8128 --------------------------------
8130 -- If there are parameters, then first, each of the formals is marked by
8131 -- setting Is_Entry_Formal. Next a record type is built which is used to
8132 -- hold the parameter values. The name of this record type is entryP where
8133 -- entry is the name of the entry, with an additional corresponding access
8134 -- type called entryPA. The record type has matching components for each
8135 -- formal (the component names are the same as the formal names). For
8136 -- elementary types, the component type matches the formal type. For
8137 -- composite types, an access type is declared (with the name formalA)
8138 -- which designates the formal type, and the type of the component is this
8139 -- access type. Finally the Entry_Component of each formal is set to
8140 -- reference the corresponding record component.
8142 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8143 Loc
: constant Source_Ptr
:= Sloc
(N
);
8144 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8145 Components
: List_Id
;
8148 Last_Decl
: Node_Id
;
8149 Component
: Entity_Id
;
8152 Rec_Ent
: Entity_Id
;
8153 Acc_Ent
: Entity_Id
;
8156 Formal
:= First_Formal
(Entry_Ent
);
8159 -- Most processing is done only if parameters are present
8161 if Present
(Formal
) then
8162 Components
:= New_List
;
8164 -- Loop through formals
8166 while Present
(Formal
) loop
8167 Set_Is_Entry_Formal
(Formal
);
8169 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8170 Set_Entry_Component
(Formal
, Component
);
8171 Set_Entry_Formal
(Component
, Formal
);
8172 Ftype
:= Etype
(Formal
);
8174 -- Declare new access type and then append
8176 Ctype
:= Make_Temporary
(Loc
, 'A');
8177 Set_Is_Param_Block_Component_Type
(Ctype
);
8180 Make_Full_Type_Declaration
(Loc
,
8181 Defining_Identifier
=> Ctype
,
8183 Make_Access_To_Object_Definition
(Loc
,
8184 All_Present
=> True,
8185 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8186 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8188 Insert_After
(Last_Decl
, Decl
);
8191 Append_To
(Components
,
8192 Make_Component_Declaration
(Loc
,
8193 Defining_Identifier
=> Component
,
8194 Component_Definition
=>
8195 Make_Component_Definition
(Loc
,
8196 Aliased_Present
=> False,
8197 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8199 Next_Formal_With_Extras
(Formal
);
8202 -- Create the Entry_Parameter_Record declaration
8204 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8207 Make_Full_Type_Declaration
(Loc
,
8208 Defining_Identifier
=> Rec_Ent
,
8210 Make_Record_Definition
(Loc
,
8212 Make_Component_List
(Loc
,
8213 Component_Items
=> Components
)));
8215 Insert_After
(Last_Decl
, Decl
);
8218 -- Construct and link in the corresponding access type
8220 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8222 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8225 Make_Full_Type_Declaration
(Loc
,
8226 Defining_Identifier
=> Acc_Ent
,
8228 Make_Access_To_Object_Definition
(Loc
,
8229 All_Present
=> True,
8230 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8232 Insert_After
(Last_Decl
, Decl
);
8234 end Expand_N_Entry_Declaration
;
8236 -----------------------------
8237 -- Expand_N_Protected_Body --
8238 -----------------------------
8240 -- Protected bodies are expanded to the completion of the subprograms
8241 -- created for the corresponding protected type. These are a protected and
8242 -- unprotected version of each protected subprogram in the object, a
8243 -- function to calculate each entry barrier, and a procedure to execute the
8244 -- sequence of statements of each protected entry body. For example, for
8245 -- protected type ptype:
8248 -- (O : System.Address;
8249 -- E : Protected_Entry_Index)
8252 -- <discriminant renamings>
8253 -- <private object renamings>
8255 -- return <barrier expression>;
8258 -- procedure pprocN (_object : in out poV;...) is
8259 -- <discriminant renamings>
8260 -- <private object renamings>
8262 -- <sequence of statements>
8265 -- procedure pprocP (_object : in out poV;...) is
8266 -- procedure _clean is
8269 -- ptypeS (_object, Pn);
8270 -- Unlock (_object._object'Access);
8271 -- Abort_Undefer.all;
8276 -- Lock (_object._object'Access);
8277 -- pprocN (_object;...);
8282 -- function pfuncN (_object : poV;...) return Return_Type is
8283 -- <discriminant renamings>
8284 -- <private object renamings>
8286 -- <sequence of statements>
8289 -- function pfuncP (_object : poV) return Return_Type is
8290 -- procedure _clean is
8292 -- Unlock (_object._object'Access);
8293 -- Abort_Undefer.all;
8298 -- Lock (_object._object'Access);
8299 -- return pfuncN (_object);
8306 -- (O : System.Address;
8307 -- P : System.Address;
8308 -- E : Protected_Entry_Index)
8310 -- <discriminant renamings>
8311 -- <private object renamings>
8312 -- type poVP is access poV;
8313 -- _Object : ptVP := ptVP!(O);
8317 -- <statement sequence>
8318 -- Complete_Entry_Body (_Object._Object);
8320 -- when all others =>
8321 -- Exceptional_Complete_Entry_Body (
8322 -- _Object._Object, Get_GNAT_Exception);
8326 -- The type poV is the record created for the protected type to hold
8327 -- the state of the protected object.
8329 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8330 Loc
: constant Source_Ptr
:= Sloc
(N
);
8331 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8333 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8334 -- This flag indicates whether the lock free implementation is active
8336 Current_Node
: Node_Id
;
8337 Disp_Op_Body
: Node_Id
;
8338 New_Op_Body
: Node_Id
;
8339 New_Op_Spec
: Node_Id
;
8343 Op_Spec
: Entity_Id
;
8345 function Build_Dispatching_Subprogram_Body
8348 Prot_Bod
: Node_Id
) return Node_Id
;
8349 -- Build a dispatching version of the protected subprogram body. The
8350 -- newly generated subprogram contains a call to the original protected
8351 -- body. The following code is generated:
8353 -- function <protected-function-name> (Param1 .. ParamN) return
8356 -- return <protected-function-name>P (Param1 .. ParamN);
8357 -- end <protected-function-name>;
8361 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8363 -- <protected-procedure-name>P (Param1 .. ParamN);
8364 -- end <protected-procedure-name>
8366 ---------------------------------------
8367 -- Build_Dispatching_Subprogram_Body --
8368 ---------------------------------------
8370 function Build_Dispatching_Subprogram_Body
8373 Prot_Bod
: Node_Id
) return Node_Id
8375 Loc
: constant Source_Ptr
:= Sloc
(N
);
8382 -- Generate a specification without a letter suffix in order to
8383 -- override an interface function or procedure.
8385 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8387 -- The formal parameters become the actuals of the protected function
8388 -- or procedure call.
8390 Actuals
:= New_List
;
8391 Formal
:= First
(Parameter_Specifications
(Spec
));
8392 while Present
(Formal
) loop
8394 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8398 if Nkind
(Spec
) = N_Procedure_Specification
then
8401 Make_Procedure_Call_Statement
(Loc
,
8403 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8404 Parameter_Associations
=> Actuals
));
8407 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8411 Make_Simple_Return_Statement
(Loc
,
8413 Make_Function_Call
(Loc
,
8415 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8416 Parameter_Associations
=> Actuals
)));
8420 Make_Subprogram_Body
(Loc
,
8421 Declarations
=> Empty_List
,
8422 Specification
=> Spec
,
8423 Handled_Statement_Sequence
=>
8424 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8425 end Build_Dispatching_Subprogram_Body
;
8427 -- Start of processing for Expand_N_Protected_Body
8430 if No_Run_Time_Mode
then
8431 Error_Msg_CRT
("protected body", N
);
8435 -- This is the proper body corresponding to a stub. The declarations
8436 -- must be inserted at the point of the stub, which in turn is in the
8437 -- declarative part of the parent unit.
8439 if Nkind
(Parent
(N
)) = N_Subunit
then
8440 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8445 Op_Body
:= First
(Declarations
(N
));
8447 -- The protected body is replaced with the bodies of its protected
8448 -- operations, and the declarations for internal objects that may
8449 -- have been created for entry family bounds.
8451 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8454 while Present
(Op_Body
) loop
8455 case Nkind
(Op_Body
) is
8456 when N_Subprogram_Declaration
=>
8459 when N_Subprogram_Body
=>
8460 Op_Spec
:= Corresponding_Spec
(Op_Body
);
8462 -- Do not create bodies for eliminated operations
8464 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8465 and then not Is_Eliminated
(Op_Spec
)
8467 if Lock_Free_Active
then
8469 Build_Lock_Free_Unprotected_Subprogram_Body
8473 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8476 Insert_After
(Current_Node
, New_Op_Body
);
8477 Current_Node
:= New_Op_Body
;
8478 Analyze
(New_Op_Body
);
8480 New_Op_Spec
:= Corresponding_Spec
(New_Op_Body
);
8482 -- When the original subprogram body has nested subprograms,
8483 -- the new body also has them, so set the flag accordingly.
8485 Set_Has_Nested_Subprogram
8486 (New_Op_Spec
, Has_Nested_Subprogram
(New_Op_Spec
));
8488 -- Similarly, when the original subprogram body uses the
8489 -- secondary stack, the new body also does. This is needed
8490 -- when the cleanup actions of the subprogram are delayed
8491 -- because it contains a package instance with a body.
8493 Set_Uses_Sec_Stack
(New_Op_Spec
, Uses_Sec_Stack
(Op_Spec
));
8495 -- Now reset the scopes of the top-level nested subprograms
8496 -- and other declaration entities so that they now refer to
8497 -- the new body's entity (it would preferable to do this
8498 -- within Build_Protected_Sub_Specification, which is called
8499 -- from Build_Unprotected_Subprogram_Body, but the needed
8500 -- subprogram entity isn't available via Corresponding_Spec
8501 -- until after the above Analyze call).
8503 Reset_Scopes_To
(New_Op_Body
, New_Op_Spec
);
8505 -- Build the corresponding protected operation. This is
8506 -- needed only if this is a public or private operation of
8509 Op_Decl
:= Unit_Declaration_Node
(Op_Spec
);
8511 if Nkind
(Parent
(Op_Decl
)) = N_Protected_Definition
then
8512 if Lock_Free_Active
then
8514 Build_Lock_Free_Protected_Subprogram_Body
8515 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8518 Build_Protected_Subprogram_Body
8519 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8522 Insert_After
(Current_Node
, New_Op_Body
);
8523 Current_Node
:= New_Op_Body
;
8524 Analyze
(New_Op_Body
);
8526 -- Generate an overriding primitive operation body for
8527 -- this subprogram if the protected type implements
8530 if Ada_Version
>= Ada_2005
8532 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8535 Build_Dispatching_Subprogram_Body
(
8536 Op_Body
, Pid
, New_Op_Body
);
8538 Insert_After
(Current_Node
, Disp_Op_Body
);
8539 Current_Node
:= Disp_Op_Body
;
8540 Analyze
(Disp_Op_Body
);
8545 when N_Entry_Body
=>
8546 Op_Id
:= Defining_Identifier
(Op_Body
);
8547 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8549 Insert_After
(Current_Node
, New_Op_Body
);
8550 Current_Node
:= New_Op_Body
;
8551 Analyze
(New_Op_Body
);
8553 when N_Implicit_Label_Declaration
=>
8559 New_Op_Body
:= New_Copy
(Op_Body
);
8560 Insert_After
(Current_Node
, New_Op_Body
);
8561 Current_Node
:= New_Op_Body
;
8563 when N_Freeze_Entity
=>
8564 New_Op_Body
:= New_Copy
(Op_Body
);
8566 if Present
(Entity
(Op_Body
))
8567 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8569 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8572 Insert_After
(Current_Node
, New_Op_Body
);
8573 Current_Node
:= New_Op_Body
;
8574 Analyze
(New_Op_Body
);
8577 New_Op_Body
:= New_Copy
(Op_Body
);
8578 Insert_After
(Current_Node
, New_Op_Body
);
8579 Current_Node
:= New_Op_Body
;
8580 Analyze
(New_Op_Body
);
8582 when N_Object_Declaration
=>
8583 pragma Assert
(not Comes_From_Source
(Op_Body
));
8584 New_Op_Body
:= New_Copy
(Op_Body
);
8585 Insert_After
(Current_Node
, New_Op_Body
);
8586 Current_Node
:= New_Op_Body
;
8587 Analyze
(New_Op_Body
);
8590 raise Program_Error
;
8596 -- Finally, create the body of the function that maps an entry index
8597 -- into the corresponding body index, except when there is no entry, or
8598 -- in a Ravenscar-like profile.
8600 if Corresponding_Runtime_Package
(Pid
) =
8601 System_Tasking_Protected_Objects_Entries
8603 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8604 Insert_After
(Current_Node
, New_Op_Body
);
8605 Current_Node
:= New_Op_Body
;
8606 Analyze
(New_Op_Body
);
8609 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8610 -- protected body. At this point all wrapper specs have been created,
8611 -- frozen and included in the dispatch table for the protected type.
8613 if Ada_Version
>= Ada_2005
then
8614 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8616 end Expand_N_Protected_Body
;
8618 -----------------------------------------
8619 -- Expand_N_Protected_Type_Declaration --
8620 -----------------------------------------
8622 -- First we create a corresponding record type declaration used to
8623 -- represent values of this protected type.
8624 -- The general form of this type declaration is
8626 -- type poV (discriminants) is record
8627 -- _Object : aliased <kind>Protection
8628 -- [(<entry count> [, <handler count>])];
8629 -- [entry_family : array (bounds) of Void;]
8630 -- <private data fields>
8633 -- The discriminants are present only if the corresponding protected type
8634 -- has discriminants, and they exactly mirror the protected type
8635 -- discriminants. The private data fields similarly mirror the private
8636 -- declarations of the protected type.
8638 -- The Object field is always present. It contains RTS specific data used
8639 -- to control the protected object. It is declared as Aliased so that it
8640 -- can be passed as a pointer to the RTS. This allows the protected record
8641 -- to be referenced within RTS data structures. An appropriate Protection
8642 -- type and discriminant are generated.
8644 -- The Service field is present for protected objects with entries. It
8645 -- contains sufficient information to allow the entry service procedure for
8646 -- this object to be called when the object is not known till runtime.
8648 -- One entry_family component is present for each entry family in the
8649 -- task definition (see Expand_N_Task_Type_Declaration).
8651 -- When a protected object is declared, an instance of the protected type
8652 -- value record is created. The elaboration of this declaration creates the
8653 -- correct bounds for the entry families, and also evaluates the priority
8654 -- expression if needed. The initialization routine for the protected type
8655 -- itself then calls Initialize_Protection with appropriate parameters to
8656 -- initialize the value of the Task_Id field. Install_Handlers may be also
8657 -- called if a pragma Attach_Handler applies.
8659 -- Note: this record is passed to the subprograms created by the expansion
8660 -- of protected subprograms and entries. It is an in parameter to protected
8661 -- functions and an in out parameter to procedures and entry bodies. The
8662 -- Entity_Id for this created record type is placed in the
8663 -- Corresponding_Record_Type field of the associated protected type entity.
8665 -- Next we create a procedure specifications for protected subprograms and
8666 -- entry bodies. For each protected subprograms two subprograms are
8667 -- created, an unprotected and a protected version. The unprotected version
8668 -- is called from within other operations of the same protected object.
8670 -- We also build the call to register the procedure if a pragma
8671 -- Interrupt_Handler applies.
8673 -- A single subprogram is created to service all entry bodies; it has an
8674 -- additional boolean out parameter indicating that the previous entry call
8675 -- made by the current task was serviced immediately, i.e. not by proxy.
8676 -- The O parameter contains a pointer to a record object of the type
8677 -- described above. An untyped interface is used here to allow this
8678 -- procedure to be called in places where the type of the object to be
8679 -- serviced is not known. This must be done, for example, when a call that
8680 -- may have been requeued is cancelled; the corresponding object must be
8681 -- serviced, but which object that is not known till runtime.
8684 -- (O : System.Address; P : out Boolean);
8685 -- procedure pprocN (_object : in out poV);
8686 -- procedure pproc (_object : in out poV);
8687 -- function pfuncN (_object : poV);
8688 -- function pfunc (_object : poV);
8691 -- Note that this must come after the record type declaration, since
8692 -- the specs refer to this type.
8694 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8695 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8696 Loc
: constant Source_Ptr
:= Sloc
(N
);
8697 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8699 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8700 -- This flag indicates whether the lock free implementation is active
8702 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8703 -- This contains two lists; one for visible and one for private decls
8705 Current_Node
: Node_Id
:= N
;
8707 Entries_Aggr
: Node_Id
;
8711 procedure Check_Inlining
(Subp
: Entity_Id
);
8712 -- If the original operation has a pragma Inline, propagate the flag
8713 -- to the internal body, for possible inlining later on. The source
8714 -- operation is invisible to the back-end and is never actually called.
8716 procedure Expand_Entry_Declaration
(Decl
: Node_Id
);
8717 -- Create the entry barrier and the procedure body for entry declaration
8718 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8720 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8721 -- When compiling under the Ravenscar profile, private components must
8722 -- have a static size, or else a protected object will require heap
8723 -- allocation, violating the corresponding restriction. It is preferable
8724 -- to make this check here, because it provides a better error message
8725 -- than the back-end, which refers to the object as a whole.
8727 procedure Register_Handler
;
8728 -- For a protected operation that is an interrupt handler, add the
8729 -- freeze action that will register it as such.
8731 procedure Replace_Access_Definition
(Comp
: Node_Id
);
8732 -- If a private component of the type is an access to itself, this
8733 -- is not a reference to the current instance, but an access type out
8734 -- of which one might construct a list. If such a component exists, we
8735 -- create an incomplete type for the equivalent record type, and
8736 -- a named access type for it, that replaces the access definition
8737 -- of the original component. This is similar to what is done for
8738 -- records in Check_Anonymous_Access_Components, but simpler, because
8739 -- the corresponding record type has no previous declaration.
8740 -- This needs to be done only once, even if there are several such
8741 -- access components. The following entity stores the constructed
8744 Acc_T
: Entity_Id
:= Empty
;
8746 --------------------
8747 -- Check_Inlining --
8748 --------------------
8750 procedure Check_Inlining
(Subp
: Entity_Id
) is
8752 if Is_Inlined
(Subp
) then
8753 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8754 Set_Is_Inlined
(Subp
, False);
8757 if Has_Pragma_No_Inline
(Subp
) then
8758 Set_Has_Pragma_No_Inline
(Protected_Body_Subprogram
(Subp
));
8762 ---------------------------
8763 -- Static_Component_Size --
8764 ---------------------------
8766 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8767 Typ
: constant Entity_Id
:= Etype
(Comp
);
8771 if Is_Scalar_Type
(Typ
) then
8774 elsif Is_Array_Type
(Typ
) then
8775 return Compile_Time_Known_Bounds
(Typ
);
8777 elsif Is_Record_Type
(Typ
) then
8778 C
:= First_Component
(Typ
);
8779 while Present
(C
) loop
8780 if not Static_Component_Size
(C
) then
8789 -- Any other type will be checked by the back-end
8794 end Static_Component_Size
;
8796 ------------------------------
8797 -- Expand_Entry_Declaration --
8798 ------------------------------
8800 procedure Expand_Entry_Declaration
(Decl
: Node_Id
) is
8801 Ent_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
8807 E_Count
:= E_Count
+ 1;
8809 -- Create the protected body subprogram
8812 Make_Defining_Identifier
(Loc
,
8813 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'E'));
8814 Set_Protected_Body_Subprogram
(Ent_Id
, Bod_Id
);
8817 Make_Subprogram_Declaration
(Loc
,
8819 Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Ent_Id
));
8821 Insert_After
(Current_Node
, Subp
);
8822 Current_Node
:= Subp
;
8826 -- Build a wrapper procedure to handle contract cases, preconditions,
8827 -- and postconditions.
8829 Build_Entry_Contract_Wrapper
(Ent_Id
, N
);
8831 -- Create the barrier function
8834 Make_Defining_Identifier
(Loc
,
8835 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'B'));
8836 Set_Barrier_Function
(Ent_Id
, Bar_Id
);
8839 Make_Subprogram_Declaration
(Loc
,
8841 Build_Barrier_Function_Specification
(Loc
, Bar_Id
));
8842 Set_Is_Entry_Barrier_Function
(Subp
);
8844 Insert_After
(Current_Node
, Subp
);
8845 Current_Node
:= Subp
;
8849 Set_Protected_Body_Subprogram
(Bar_Id
, Bar_Id
);
8850 Set_Scope
(Bar_Id
, Scope
(Ent_Id
));
8852 -- Collect pointers to the protected subprogram and the barrier
8853 -- of the current entry, for insertion into Entry_Bodies_Array.
8855 Append_To
(Expressions
(Entries_Aggr
),
8856 Make_Aggregate
(Loc
,
8857 Expressions
=> New_List
(
8858 Make_Attribute_Reference
(Loc
,
8859 Prefix
=> New_Occurrence_Of
(Bar_Id
, Loc
),
8860 Attribute_Name
=> Name_Unrestricted_Access
),
8861 Make_Attribute_Reference
(Loc
,
8862 Prefix
=> New_Occurrence_Of
(Bod_Id
, Loc
),
8863 Attribute_Name
=> Name_Unrestricted_Access
))));
8864 end Expand_Entry_Declaration
;
8866 ----------------------
8867 -- Register_Handler --
8868 ----------------------
8870 procedure Register_Handler
is
8872 -- All semantic checks already done in Sem_Prag
8874 Prot_Proc
: constant Entity_Id
:=
8875 Defining_Unit_Name
(Specification
(Current_Node
));
8877 Proc_Address
: constant Node_Id
:=
8878 Make_Attribute_Reference
(Loc
,
8880 New_Occurrence_Of
(Prot_Proc
, Loc
),
8881 Attribute_Name
=> Name_Address
);
8883 RTS_Call
: constant Entity_Id
:=
8884 Make_Procedure_Call_Statement
(Loc
,
8887 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8888 Parameter_Associations
=> New_List
(Proc_Address
));
8890 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8891 end Register_Handler
;
8893 -------------------------------
8894 -- Replace_Access_Definition --
8895 -------------------------------
8897 procedure Replace_Access_Definition
(Comp
: Node_Id
) is
8898 Loc
: constant Source_Ptr
:= Sloc
(Comp
);
8906 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Rec_Id
));
8907 Inc_D
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
8908 Acc_T
:= Make_Temporary
(Loc
, 'S');
8910 Make_Access_To_Object_Definition
(Loc
,
8911 Subtype_Indication
=> New_Occurrence_Of
(Inc_T
, Loc
));
8913 Make_Full_Type_Declaration
(Loc
,
8914 Defining_Identifier
=> Acc_T
,
8915 Type_Definition
=> Acc_Def
);
8917 Insert_Before
(Rec_Decl
, Inc_D
);
8920 Insert_Before
(Rec_Decl
, Acc_D
);
8924 Set_Access_Definition
(Comp
, Empty
);
8925 Set_Subtype_Indication
(Comp
, New_Occurrence_Of
(Acc_T
, Loc
));
8926 end Replace_Access_Definition
;
8931 Body_Id
: Entity_Id
;
8937 Object_Comp
: Node_Id
;
8941 -- Start of processing for Expand_N_Protected_Type_Declaration
8944 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8947 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8948 Rec_Id
:= Defining_Identifier
(Rec_Decl
);
8951 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8953 Qualify_Entity_Names
(N
);
8955 -- If the type has discriminants, their occurrences in the declaration
8956 -- have been replaced by the corresponding discriminals. For components
8957 -- that are constrained by discriminants, their homologues in the
8958 -- corresponding record type must refer to the discriminants of that
8959 -- record, so we must apply a new renaming to subtypes_indications:
8961 -- protected discriminant => discriminal => record discriminant
8963 -- This replacement is not applied to default expressions, for which
8964 -- the discriminal is correct.
8966 if Has_Discriminants
(Prot_Typ
) then
8972 Disc
:= First_Discriminant
(Prot_Typ
);
8973 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
8974 while Present
(Disc
) loop
8975 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
8976 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
8977 Next_Discriminant
(Disc
);
8983 -- Fill in the component declarations
8985 -- Add components for entry families. For each entry family, create an
8986 -- anonymous type declaration with the same size, and analyze the type.
8988 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
8990 pragma Assert
(Present
(Pdef
));
8992 Insert_After
(Current_Node
, Rec_Decl
);
8993 Current_Node
:= Rec_Decl
;
8995 -- Add private field components
8997 Priv
:= First
(Private_Declarations
(Pdef
));
8998 while Present
(Priv
) loop
8999 if Nkind
(Priv
) = N_Component_Declaration
then
9000 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9002 -- When compiling for a restricted profile, the private
9003 -- components must have a static size. If not, this is an error
9004 -- for a single protected declaration, and rates a warning on a
9005 -- protected type declaration.
9007 if not Comes_From_Source
(Prot_Typ
) then
9009 -- It's ok to be checking this restriction at expansion
9010 -- time, because this is only for the restricted profile,
9011 -- which is not subject to strict RM conformance, so it
9012 -- is OK to miss this check in -gnatc mode.
9014 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9016 (No_Implicit_Protected_Object_Allocations
, Priv
);
9018 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9019 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9021 -- Any object of the type will be non-static
9023 Error_Msg_N
("component has non-static size??", Priv
);
9025 ("\creation of protected object of type& will "
9026 & "violate restriction "
9027 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9029 -- Object will be non-static if discriminants are
9032 ("creation of protected object of type& with "
9033 & "non-static discriminants will violate "
9034 & "restriction No_Implicit_Heap_Allocations??",
9038 -- Likewise for No_Implicit_Protected_Object_Allocations
9040 elsif Restriction_Active
9041 (No_Implicit_Protected_Object_Allocations
)
9043 if not Discriminated_Size
(Defining_Identifier
(Priv
)) then
9044 -- Any object of the type will be non-static
9046 Error_Msg_N
("component has non-static size??", Priv
);
9048 ("\creation of protected object of type& will violate "
9050 & "No_Implicit_Protected_Object_Allocations??",
9053 -- Object will be non-static if discriminants are
9056 ("creation of protected object of type& with "
9057 & "non-static discriminants will violate restriction "
9058 & "No_Implicit_Protected_Object_Allocations??",
9064 -- The component definition consists of a subtype indication, or
9065 -- (in Ada 2005) an access definition. Make a copy of the proper
9069 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9070 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9071 Nent
: constant Entity_Id
:=
9072 Make_Defining_Identifier
(Sloc
(Oent
),
9073 Chars
=> Chars
(Oent
));
9077 if Present
(Subtype_Indication
(Old_Comp
)) then
9079 Make_Component_Definition
(Sloc
(Oent
),
9080 Aliased_Present
=> False,
9081 Subtype_Indication
=>
9083 (Subtype_Indication
(Old_Comp
), Discr_Map
));
9086 Make_Component_Definition
(Sloc
(Oent
),
9087 Aliased_Present
=> False,
9088 Access_Definition
=>
9090 (Access_Definition
(Old_Comp
), Discr_Map
));
9092 -- A self-reference in the private part becomes a
9093 -- self-reference to the corresponding record.
9095 if Entity
(Subtype_Mark
(Access_Definition
(New_Comp
)))
9098 Replace_Access_Definition
(New_Comp
);
9103 Make_Component_Declaration
(Loc
,
9104 Defining_Identifier
=> Nent
,
9105 Component_Definition
=> New_Comp
,
9106 Expression
=> Expression
(Priv
));
9108 Set_Has_Per_Object_Constraint
(Nent
,
9109 Has_Per_Object_Constraint
(Oent
));
9111 Append_To
(Cdecls
, New_Priv
);
9114 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9116 -- Make the unprotected version of the subprogram available for
9117 -- expansion of intra object calls. There is need for a protected
9118 -- version only if the subprogram is an interrupt handler,
9119 -- otherwise this operation can only be called from within the
9123 Make_Subprogram_Declaration
(Loc
,
9125 Build_Protected_Sub_Specification
9126 (Priv
, Prot_Typ
, Unprotected_Mode
));
9128 Insert_After
(Current_Node
, Sub
);
9131 Set_Protected_Body_Subprogram
9132 (Defining_Unit_Name
(Specification
(Priv
)),
9133 Defining_Unit_Name
(Specification
(Sub
)));
9134 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9135 Current_Node
:= Sub
;
9138 Make_Subprogram_Declaration
(Loc
,
9140 Build_Protected_Sub_Specification
9141 (Priv
, Prot_Typ
, Protected_Mode
));
9143 Insert_After
(Current_Node
, Sub
);
9145 Current_Node
:= Sub
;
9147 if Is_Interrupt_Handler
9148 (Defining_Unit_Name
(Specification
(Priv
)))
9150 if not Restricted_Profile
then
9159 -- Except for the lock-free implementation, append the _Object field
9160 -- with the right type to the component list. We need to compute the
9161 -- number of entries, and in some cases the number of Attach_Handler
9164 if not Lock_Free_Active
then
9166 Entry_Count_Expr
: constant Node_Id
:=
9167 Build_Entry_Count_Expression
9169 Num_Attach_Handler
: Nat
:= 0;
9170 Protection_Subtype
: Node_Id
;
9174 if Has_Attach_Handler
(Prot_Typ
) then
9175 Ritem
:= First_Rep_Item
(Prot_Typ
);
9176 while Present
(Ritem
) loop
9177 if Nkind
(Ritem
) = N_Pragma
9178 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9180 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9183 Next_Rep_Item
(Ritem
);
9187 -- Determine the proper protection type. There are two special
9188 -- cases: 1) when the protected type has dynamic interrupt
9189 -- handlers, and 2) when it has static handlers and we use a
9190 -- restricted profile.
9192 if Has_Attach_Handler
(Prot_Typ
)
9193 and then not Restricted_Profile
9195 Protection_Subtype
:=
9196 Make_Subtype_Indication
(Loc
,
9199 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9201 Make_Index_Or_Discriminant_Constraint
(Loc
,
9202 Constraints
=> New_List
(
9204 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9206 elsif Has_Interrupt_Handler
(Prot_Typ
)
9207 and then not Restriction_Active
(No_Dynamic_Attachment
)
9209 Protection_Subtype
:=
9210 Make_Subtype_Indication
(Loc
,
9213 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9215 Make_Index_Or_Discriminant_Constraint
(Loc
,
9216 Constraints
=> New_List
(Entry_Count_Expr
)));
9219 case Corresponding_Runtime_Package
(Prot_Typ
) is
9220 when System_Tasking_Protected_Objects_Entries
=>
9221 Protection_Subtype
:=
9222 Make_Subtype_Indication
(Loc
,
9225 (RTE
(RE_Protection_Entries
), Loc
),
9227 Make_Index_Or_Discriminant_Constraint
(Loc
,
9228 Constraints
=> New_List
(Entry_Count_Expr
)));
9230 when System_Tasking_Protected_Objects_Single_Entry
=>
9231 Protection_Subtype
:=
9232 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9234 when System_Tasking_Protected_Objects
=>
9235 Protection_Subtype
:=
9236 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9239 raise Program_Error
;
9244 Make_Component_Declaration
(Loc
,
9245 Defining_Identifier
=>
9246 Make_Defining_Identifier
(Loc
, Name_uObject
),
9247 Component_Definition
=>
9248 Make_Component_Definition
(Loc
,
9249 Aliased_Present
=> True,
9250 Subtype_Indication
=> Protection_Subtype
));
9253 -- Put the _Object component after the private component so that it
9254 -- be finalized early as required by 9.4 (20)
9256 Append_To
(Cdecls
, Object_Comp
);
9259 -- Analyze the record declaration immediately after construction,
9260 -- because the initialization procedure is needed for single object
9261 -- declarations before the next entity is analyzed (the freeze call
9262 -- that generates this initialization procedure is found below).
9264 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9266 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9267 -- the corresponding record is frozen. If any wrappers are generated,
9268 -- Current_Node is updated accordingly.
9270 if Ada_Version
>= Ada_2005
then
9271 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9274 -- Collect pointers to entry bodies and their barriers, to be placed
9275 -- in the Entry_Bodies_Array for the type. For each entry/family we
9276 -- add an expression to the aggregate which is the initial value of
9277 -- this array. The array is declared after all protected subprograms.
9279 if Has_Entries
(Prot_Typ
) then
9280 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9282 Entries_Aggr
:= Empty
;
9285 -- Build two new procedure specifications for each protected subprogram;
9286 -- one to call from outside the object and one to call from inside.
9287 -- Build a barrier function and an entry body action procedure
9288 -- specification for each protected entry. Initialize the entry body
9289 -- array. If subprogram is flagged as eliminated, do not generate any
9290 -- internal operations.
9293 Comp
:= First
(Visible_Declarations
(Pdef
));
9294 while Present
(Comp
) loop
9295 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9297 Make_Subprogram_Declaration
(Loc
,
9299 Build_Protected_Sub_Specification
9300 (Comp
, Prot_Typ
, Unprotected_Mode
));
9302 Insert_After
(Current_Node
, Sub
);
9305 Set_Protected_Body_Subprogram
9306 (Defining_Unit_Name
(Specification
(Comp
)),
9307 Defining_Unit_Name
(Specification
(Sub
)));
9308 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9310 -- Make the protected version of the subprogram available for
9311 -- expansion of external calls.
9313 Current_Node
:= Sub
;
9316 Make_Subprogram_Declaration
(Loc
,
9318 Build_Protected_Sub_Specification
9319 (Comp
, Prot_Typ
, Protected_Mode
));
9321 Insert_After
(Current_Node
, Sub
);
9324 Current_Node
:= Sub
;
9326 -- Generate an overriding primitive operation specification for
9327 -- this subprogram if the protected type implements an interface
9328 -- and Build_Wrapper_Spec did not generate its wrapper.
9330 if Ada_Version
>= Ada_2005
9332 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9335 Found
: Boolean := False;
9336 Prim_Elmt
: Elmt_Id
;
9342 (Primitive_Operations
9343 (Corresponding_Record_Type
(Prot_Typ
)));
9345 while Present
(Prim_Elmt
) loop
9346 Prim_Op
:= Node
(Prim_Elmt
);
9348 if Is_Primitive_Wrapper
(Prim_Op
)
9349 and then Wrapped_Entity
(Prim_Op
) =
9350 Defining_Entity
(Specification
(Comp
))
9356 Next_Elmt
(Prim_Elmt
);
9361 Make_Subprogram_Declaration
(Loc
,
9363 Build_Protected_Sub_Specification
9364 (Comp
, Prot_Typ
, Dispatching_Mode
));
9366 Insert_After
(Current_Node
, Sub
);
9369 Current_Node
:= Sub
;
9374 -- If a pragma Interrupt_Handler applies, build and add a call to
9375 -- Register_Interrupt_Handler to the freezing actions of the
9376 -- protected version (Current_Node) of the subprogram:
9378 -- system.interrupts.register_interrupt_handler
9379 -- (prot_procP'address);
9381 if not Restricted_Profile
9382 and then Is_Interrupt_Handler
9383 (Defining_Unit_Name
(Specification
(Comp
)))
9388 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9389 Expand_Entry_Declaration
(Comp
);
9395 -- If there are some private entry declarations, expand it as if they
9396 -- were visible entries.
9398 Comp
:= First
(Private_Declarations
(Pdef
));
9399 while Present
(Comp
) loop
9400 if Nkind
(Comp
) = N_Entry_Declaration
then
9401 Expand_Entry_Declaration
(Comp
);
9407 -- Create the declaration of an array object which contains the values
9408 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9409 -- type. This object is later passed to the appropriate protected object
9410 -- initialization routine.
9412 if Has_Entries
(Prot_Typ
)
9413 and then Corresponding_Runtime_Package
(Prot_Typ
) =
9414 System_Tasking_Protected_Objects_Entries
9421 Maxes_Id
: Entity_Id
;
9422 Need_Array
: Boolean := False;
9425 -- First check if there is any Max_Queue_Length pragma
9427 Item
:= First_Entity
(Prot_Typ
);
9428 while Present
(Item
) loop
9429 if Is_Entry
(Item
) and then Has_Max_Queue_Length
(Item
) then
9437 -- Gather the Max_Queue_Length values of all entries in a list. A
9438 -- value of zero indicates that the entry has no limitation on its
9443 Item
:= First_Entity
(Prot_Typ
);
9445 while Present
(Item
) loop
9446 if Is_Entry
(Item
) then
9449 Make_Integer_Literal
9450 (Loc
, Get_Max_Queue_Length
(Item
)));
9456 -- Create the declaration of the array object. Generate:
9458 -- Maxes_Id : aliased constant
9459 -- Protected_Entry_Queue_Max_Array
9460 -- (1 .. Count) := (..., ...);
9463 Make_Defining_Identifier
(Loc
,
9464 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'B'));
9467 Make_Object_Declaration
(Loc
,
9468 Defining_Identifier
=> Maxes_Id
,
9469 Aliased_Present
=> True,
9470 Constant_Present
=> True,
9471 Object_Definition
=>
9472 Make_Subtype_Indication
(Loc
,
9475 (RTE
(RE_Protected_Entry_Queue_Max_Array
), Loc
),
9477 Make_Index_Or_Discriminant_Constraint
(Loc
,
9478 Constraints
=> New_List
(
9480 Make_Integer_Literal
(Loc
, 1),
9481 Make_Integer_Literal
(Loc
, Count
))))),
9482 Expression
=> Make_Aggregate
(Loc
, Maxes
));
9484 -- A pointer to this array will be placed in the corresponding
9485 -- record by its initialization procedure so this needs to be
9488 Insert_After
(Current_Node
, Max_Vals
);
9489 Current_Node
:= Max_Vals
;
9492 Set_Entry_Max_Queue_Lengths_Array
(Prot_Typ
, Maxes_Id
);
9497 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9498 -- all protected subprograms have been collected.
9500 if Has_Entries
(Prot_Typ
) then
9502 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9503 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9505 case Corresponding_Runtime_Package
(Prot_Typ
) is
9506 when System_Tasking_Protected_Objects_Entries
=>
9507 Expr
:= Entries_Aggr
;
9509 Make_Subtype_Indication
(Loc
,
9512 (RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9514 Make_Index_Or_Discriminant_Constraint
(Loc
,
9515 Constraints
=> New_List
(
9517 Make_Integer_Literal
(Loc
, 1),
9518 Make_Integer_Literal
(Loc
, E_Count
)))));
9520 when System_Tasking_Protected_Objects_Single_Entry
=>
9521 Expr
:= Remove_Head
(Expressions
(Entries_Aggr
));
9522 Obj_Def
:= New_Occurrence_Of
(RTE
(RE_Entry_Body
), Loc
);
9525 raise Program_Error
;
9529 Make_Object_Declaration
(Loc
,
9530 Defining_Identifier
=> Body_Id
,
9531 Aliased_Present
=> True,
9532 Constant_Present
=> True,
9533 Object_Definition
=> Obj_Def
,
9534 Expression
=> Expr
);
9536 -- A pointer to this array will be placed in the corresponding record
9537 -- by its initialization procedure so this needs to be analyzed here.
9539 Insert_After
(Current_Node
, Body_Arr
);
9540 Current_Node
:= Body_Arr
;
9543 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9545 -- Finally, build the function that maps an entry index into the
9546 -- corresponding body. A pointer to this function is placed in each
9547 -- object of the type. Except for a ravenscar-like profile (no abort,
9548 -- no entry queue, 1 entry)
9550 if Corresponding_Runtime_Package
(Prot_Typ
) =
9551 System_Tasking_Protected_Objects_Entries
9554 Make_Subprogram_Declaration
(Loc
,
9555 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9557 Insert_After
(Current_Node
, Sub
);
9561 end Expand_N_Protected_Type_Declaration
;
9563 --------------------------------
9564 -- Expand_N_Requeue_Statement --
9565 --------------------------------
9567 -- A nondispatching requeue statement is expanded into one of four GNARLI
9568 -- operations, depending on the source and destination (task or protected
9569 -- object). A dispatching requeue statement is expanded into a call to the
9570 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9571 -- jump around the remainder of processing for the original entry and, if
9572 -- the destination is (different) protected object, to attempt to service
9573 -- it. The following illustrates the various cases:
9576 -- (O : System.Address;
9577 -- P : System.Address;
9578 -- E : Protected_Entry_Index)
9580 -- <discriminant renamings>
9581 -- <private object renamings>
9582 -- type poVP is access poV;
9583 -- _object : ptVP := ptVP!(O);
9587 -- <start of statement sequence for entry>
9589 -- -- Requeue from one protected entry body to another protected
9592 -- Requeue_Protected_Entry (
9593 -- _object._object'Access,
9594 -- new._object'Access,
9599 -- <some more of the statement sequence for entry>
9601 -- -- Requeue from an entry body to a task entry
9603 -- Requeue_Protected_To_Task_Entry (
9609 -- <rest of statement sequence for entry>
9610 -- Complete_Entry_Body (_object._object);
9613 -- when all others =>
9614 -- Exceptional_Complete_Entry_Body (
9615 -- _object._object, Get_GNAT_Exception);
9619 -- Requeue of a task entry call to a task entry
9621 -- Accept_Call (E, Ann);
9622 -- <start of statement sequence for accept statement>
9623 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9625 -- <rest of statement sequence for accept statement>
9627 -- Complete_Rendezvous;
9630 -- when all others =>
9631 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9633 -- Requeue of a task entry call to a protected entry
9635 -- Accept_Call (E, Ann);
9636 -- <start of statement sequence for accept statement>
9637 -- Requeue_Task_To_Protected_Entry (
9638 -- new._object'Access,
9643 -- <rest of statement sequence for accept statement>
9645 -- Complete_Rendezvous;
9648 -- when all others =>
9649 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9651 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9652 -- marked by pragma Implemented (XXX, By_Entry).
9654 -- The requeue is inside a protected entry:
9657 -- (O : System.Address;
9658 -- P : System.Address;
9659 -- E : Protected_Entry_Index)
9661 -- <discriminant renamings>
9662 -- <private object renamings>
9663 -- type poVP is access poV;
9664 -- _object : ptVP := ptVP!(O);
9668 -- <start of statement sequence for entry>
9671 -- (<interface class-wide object>,
9674 -- Ada.Tags.Get_Offset_Index
9676 -- <interface dispatch table index of target entry>),
9680 -- <rest of statement sequence for entry>
9681 -- Complete_Entry_Body (_object._object);
9684 -- when all others =>
9685 -- Exceptional_Complete_Entry_Body (
9686 -- _object._object, Get_GNAT_Exception);
9690 -- The requeue is inside a task entry:
9692 -- Accept_Call (E, Ann);
9693 -- <start of statement sequence for accept statement>
9695 -- (<interface class-wide object>,
9698 -- Ada.Tags.Get_Offset_Index
9700 -- <interface dispatch table index of target entrt>),
9704 -- <rest of statement sequence for accept statement>
9706 -- Complete_Rendezvous;
9709 -- when all others =>
9710 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9712 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9713 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9714 -- statement is replaced by a dispatching call with actual parameters taken
9715 -- from the inner-most accept statement or entry body.
9717 -- Target.Primitive (Param1, ..., ParamN);
9719 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9720 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9724 -- S : constant Offset_Index :=
9725 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9726 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9729 -- if C = POK_Protected_Entry
9730 -- or else C = POK_Task_Entry
9732 -- <statements for dispatching requeue>
9734 -- elsif C = POK_Protected_Procedure then
9735 -- <dispatching call equivalent>
9738 -- raise Program_Error;
9742 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9743 Loc
: constant Source_Ptr
:= Sloc
(N
);
9744 Conc_Typ
: Entity_Id
;
9747 Enc_Subp
: Entity_Id
;
9749 Old_Typ
: Entity_Id
;
9751 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9752 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9753 -- the form Concval.Ename. It is statically known that Ename is allowed
9754 -- to be implemented by a protected procedure. Create a dispatching call
9755 -- equivalent of Concval.Ename taking the actual parameters from the
9756 -- inner-most accept statement or entry body.
9758 function Build_Dispatching_Requeue
return Node_Id
;
9759 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9760 -- the form Concval.Ename. It is statically known that Ename is allowed
9761 -- to be implemented by a protected or a task entry. Create a call to
9762 -- primitive _Disp_Requeue which handles the low-level actions.
9764 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9765 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9766 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9767 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9768 -- determines at runtime whether Ename denotes an entry or a procedure
9769 -- and perform the appropriate kind of dispatching select.
9771 function Build_Normal_Requeue
return Node_Id
;
9772 -- N denotes a nondispatching requeue statement to either a task or a
9773 -- protected entry. Build the appropriate runtime call to perform the
9776 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9777 -- For a protected entry, create a return statement to skip the rest of
9778 -- the entry body. Otherwise, create a goto statement to skip the rest
9779 -- of a task accept statement. The lookup for the enclosing entry body
9780 -- or accept statement starts from Search.
9782 ---------------------------------------
9783 -- Build_Dispatching_Call_Equivalent --
9784 ---------------------------------------
9786 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9787 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9788 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9795 -- Climb the parent chain looking for the inner-most entry body or
9796 -- accept statement.
9799 while Present
(Acc_Ent
)
9800 and then Nkind
(Acc_Ent
) not in N_Accept_Statement | N_Entry_Body
9802 Acc_Ent
:= Parent
(Acc_Ent
);
9805 -- A requeue statement should be housed inside an entry body or an
9806 -- accept statement at some level. If this is not the case, then the
9807 -- tree is malformed.
9809 pragma Assert
(Present
(Acc_Ent
));
9811 -- Recover the list of formal parameters
9813 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9814 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9817 Formals
:= Parameter_Specifications
(Acc_Ent
);
9819 -- Create the actual parameters for the dispatching call. These are
9820 -- simply copies of the entry body or accept statement formals in the
9821 -- same order as they appear.
9825 if Present
(Formals
) then
9826 Actuals
:= New_List
;
9827 Formal
:= First
(Formals
);
9828 while Present
(Formal
) loop
9830 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9836 -- Obj.Call_Ent (Actuals);
9839 Make_Procedure_Call_Statement
(Loc
,
9841 Make_Selected_Component
(Loc
,
9842 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9843 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9845 Parameter_Associations
=> Actuals
);
9846 end Build_Dispatching_Call_Equivalent
;
9848 -------------------------------
9849 -- Build_Dispatching_Requeue --
9850 -------------------------------
9852 function Build_Dispatching_Requeue
return Node_Id
is
9853 Params
: constant List_Id
:= New_List
;
9856 -- Process the "with abort" parameter
9859 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9861 -- Process the entry wrapper's position in the primary dispatch
9862 -- table parameter. Generate:
9864 -- Ada.Tags.Get_Entry_Index
9865 -- (T => To_Tag_Ptr (Obj'Address).all,
9867 -- Ada.Tags.Get_Offset_Index
9868 -- (Ada.Tags.Tag (Concval),
9869 -- <interface dispatch table position of Ename>));
9871 -- Note that Obj'Address is recursively expanded into a call to
9872 -- Base_Address (Obj).
9874 if Tagged_Type_Expansion
then
9876 Make_Function_Call
(Loc
,
9877 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9878 Parameter_Associations
=> New_List
(
9880 Make_Explicit_Dereference
(Loc
,
9881 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9882 Make_Attribute_Reference
(Loc
,
9883 Prefix
=> New_Copy_Tree
(Concval
),
9884 Attribute_Name
=> Name_Address
))),
9886 Make_Function_Call
(Loc
,
9887 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9888 Parameter_Associations
=> New_List
(
9889 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9890 Make_Integer_Literal
(Loc
,
9891 DT_Position
(Entity
(Ename
))))))));
9897 Make_Function_Call
(Loc
,
9898 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9899 Parameter_Associations
=> New_List
(
9901 Make_Attribute_Reference
(Loc
,
9903 Attribute_Name
=> Name_Tag
),
9905 Make_Function_Call
(Loc
,
9906 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9908 Parameter_Associations
=> New_List
(
9912 Make_Attribute_Reference
(Loc
,
9914 Attribute_Name
=> Name_Tag
),
9918 Make_Attribute_Reference
(Loc
,
9919 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9920 Attribute_Name
=> Name_Tag
),
9924 Make_Integer_Literal
(Loc
,
9925 DT_Position
(Entity
(Ename
))))))));
9928 -- Specific actuals for protected to XXX requeue
9930 if Is_Protected_Type
(Old_Typ
) then
9932 Make_Attribute_Reference
(Loc
, -- _object'Address
9934 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9935 Attribute_Name
=> Name_Address
));
9937 Prepend_To
(Params
, -- True
9938 New_Occurrence_Of
(Standard_True
, Loc
));
9940 -- Specific actuals for task to XXX requeue
9943 pragma Assert
(Is_Task_Type
(Old_Typ
));
9945 Prepend_To
(Params
, -- null
9946 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9948 Prepend_To
(Params
, -- False
9949 New_Occurrence_Of
(Standard_False
, Loc
));
9952 -- Add the object parameter
9954 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9957 -- _Disp_Requeue (<Params>);
9959 -- Find entity for Disp_Requeue operation, which belongs to
9960 -- the type and may not be directly visible.
9964 Op
: Entity_Id
:= Empty
;
9967 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9968 while Present
(Elmt
) loop
9970 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9974 pragma Assert
(Present
(Op
));
9977 Make_Procedure_Call_Statement
(Loc
,
9978 Name
=> New_Occurrence_Of
(Op
, Loc
),
9979 Parameter_Associations
=> Params
);
9981 end Build_Dispatching_Requeue
;
9983 --------------------------------------
9984 -- Build_Dispatching_Requeue_To_Any --
9985 --------------------------------------
9987 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9988 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9989 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9990 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
10000 -- Dispatch table slot processing, generate:
10003 S
:= Build_S
(Loc
, Decls
);
10005 -- Call kind processing, generate:
10006 -- C : Ada.Tags.Prim_Op_Kind;
10008 C
:= Build_C
(Loc
, Decls
);
10011 -- S := Ada.Tags.Get_Offset_Index
10012 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10014 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10017 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10020 Make_Procedure_Call_Statement
(Loc
,
10022 New_Occurrence_Of
(
10023 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10024 Name_uDisp_Get_Prim_Op_Kind
),
10026 Parameter_Associations
=> New_List
(
10027 New_Copy_Tree
(Obj
),
10028 New_Occurrence_Of
(S
, Loc
),
10029 New_Occurrence_Of
(C
, Loc
))));
10033 -- if C = POK_Protected_Entry
10034 -- or else C = POK_Task_Entry
10037 Make_Implicit_If_Statement
(N
,
10043 New_Occurrence_Of
(C
, Loc
),
10045 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10050 New_Occurrence_Of
(C
, Loc
),
10052 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10054 -- Dispatching requeue equivalent
10056 Then_Statements
=> New_List
(
10057 Build_Dispatching_Requeue
,
10060 -- elsif C = POK_Protected_Procedure then
10062 Elsif_Parts
=> New_List
(
10063 Make_Elsif_Part
(Loc
,
10067 New_Occurrence_Of
(C
, Loc
),
10069 New_Occurrence_Of
(
10070 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10072 -- Dispatching call equivalent
10074 Then_Statements
=> New_List
(
10075 Build_Dispatching_Call_Equivalent
))),
10078 -- raise Program_Error;
10081 Else_Statements
=> New_List
(
10082 Make_Raise_Program_Error
(Loc
,
10083 Reason
=> PE_Explicit_Raise
))));
10085 -- Wrap everything into a block
10088 Make_Block_Statement
(Loc
,
10089 Declarations
=> Decls
,
10090 Handled_Statement_Sequence
=>
10091 Make_Handled_Sequence_Of_Statements
(Loc
,
10092 Statements
=> Stmts
));
10093 end Build_Dispatching_Requeue_To_Any
;
10095 --------------------------
10096 -- Build_Normal_Requeue --
10097 --------------------------
10099 function Build_Normal_Requeue
return Node_Id
is
10100 Params
: constant List_Id
:= New_List
;
10105 -- Process the "with abort" parameter
10107 Prepend_To
(Params
,
10108 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10110 -- Add the index expression to the parameters. It is common among all
10113 Prepend_To
(Params
,
10114 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10116 if Is_Protected_Type
(Old_Typ
) then
10118 Self_Param
: Node_Id
;
10122 Make_Attribute_Reference
(Loc
,
10124 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10126 Name_Unchecked_Access
);
10128 -- Protected to protected requeue
10130 if Is_Protected_Type
(Conc_Typ
) then
10132 New_Occurrence_Of
(
10133 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10136 Make_Attribute_Reference
(Loc
,
10138 Concurrent_Ref
(Concval
),
10140 Name_Unchecked_Access
);
10142 -- Protected to task requeue
10144 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10146 New_Occurrence_Of
(
10147 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10149 Param
:= Concurrent_Ref
(Concval
);
10152 Prepend_To
(Params
, Param
);
10153 Prepend_To
(Params
, Self_Param
);
10156 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10158 -- Task to protected requeue
10160 if Is_Protected_Type
(Conc_Typ
) then
10162 New_Occurrence_Of
(
10163 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10166 Make_Attribute_Reference
(Loc
,
10168 Concurrent_Ref
(Concval
),
10170 Name_Unchecked_Access
);
10172 -- Task to task requeue
10174 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10176 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10178 Param
:= Concurrent_Ref
(Concval
);
10181 Prepend_To
(Params
, Param
);
10185 Make_Procedure_Call_Statement
(Loc
,
10187 Parameter_Associations
=> Params
);
10188 end Build_Normal_Requeue
;
10190 --------------------------
10191 -- Build_Skip_Statement --
10192 --------------------------
10194 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10195 Skip_Stmt
: Node_Id
;
10198 -- Build a return statement to skip the rest of the entire body
10200 if Is_Protected_Type
(Old_Typ
) then
10201 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10203 -- If the requeue is within a task, find the end label of the
10204 -- enclosing accept statement and create a goto statement to it.
10212 -- Climb the parent chain looking for the enclosing accept
10215 Acc
:= Parent
(Search
);
10216 while Present
(Acc
)
10217 and then Nkind
(Acc
) /= N_Accept_Statement
10219 Acc
:= Parent
(Acc
);
10222 -- The last statement is the second label used for completing
10223 -- the rendezvous the usual way. The label we are looking for
10224 -- is right before it.
10227 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10229 pragma Assert
(Nkind
(Label
) = N_Label
);
10231 -- Generate a goto statement to skip the rest of the accept
10234 Make_Goto_Statement
(Loc
,
10236 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10240 Set_Analyzed
(Skip_Stmt
);
10243 end Build_Skip_Statement
;
10245 -- Start of processing for Expand_N_Requeue_Statement
10248 -- Extract the components of the entry call
10250 Extract_Entry
(N
, Concval
, Ename
, Index
);
10251 Conc_Typ
:= Etype
(Concval
);
10253 -- Examine the scope stack in order to find nearest enclosing concurrent
10254 -- type. This will constitute our invocation source.
10256 Old_Typ
:= Current_Scope
;
10257 while Present
(Old_Typ
)
10258 and then not Is_Concurrent_Type
(Old_Typ
)
10260 Old_Typ
:= Scope
(Old_Typ
);
10263 -- Obtain the innermost enclosing callable construct for use in
10264 -- generating a dynamic accessibility check.
10266 Enc_Subp
:= Current_Scope
;
10268 if Ekind
(Enc_Subp
) not in Entry_Kind | Subprogram_Kind
then
10269 Enc_Subp
:= Enclosing_Subprogram
(Enc_Subp
);
10272 -- Generate a dynamic accessibility check on the target object
10274 Insert_Before_And_Analyze
(N
,
10275 Make_Raise_Program_Error
(Loc
,
10278 Left_Opnd
=> Accessibility_Level
(Name
(N
), Dynamic_Level
),
10279 Right_Opnd
=> Make_Integer_Literal
(Loc
,
10280 Scope_Depth
(Enc_Subp
))),
10281 Reason
=> PE_Accessibility_Check_Failed
));
10283 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10284 -- Concval.Ename where the type of Concval is class-wide concurrent
10287 if Ada_Version
>= Ada_2012
10288 and then Present
(Concval
)
10289 and then Is_Class_Wide_Type
(Conc_Typ
)
10290 and then Is_Concurrent_Interface
(Conc_Typ
)
10293 Has_Impl
: Boolean := False;
10294 Impl_Kind
: Name_Id
:= No_Name
;
10297 -- Check whether the Ename is flagged by pragma Implemented
10299 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10301 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10304 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10305 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10307 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10308 Rewrite
(N
, Build_Dispatching_Requeue
);
10310 Insert_After
(N
, Build_Skip_Statement
(N
));
10312 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10313 -- a protected procedure. In this case the requeue is transformed
10314 -- into a dispatching call.
10317 and then Impl_Kind
= Name_By_Protected_Procedure
10319 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10322 -- The procedure_or_entry_NAME's implementation kind is either
10323 -- By_Any, Optional, or pragma Implemented was not applied at all.
10324 -- In this case a runtime test determines whether Ename denotes an
10325 -- entry or a protected procedure and performs the appropriate
10329 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10334 -- Processing for regular (nondispatching) requeues
10337 Rewrite
(N
, Build_Normal_Requeue
);
10339 Insert_After
(N
, Build_Skip_Statement
(N
));
10341 end Expand_N_Requeue_Statement
;
10343 -------------------------------
10344 -- Expand_N_Selective_Accept --
10345 -------------------------------
10347 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10348 Loc
: constant Source_Ptr
:= Sloc
(N
);
10349 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10351 -- Note: in the below declarations a lot of new lists are allocated
10352 -- unconditionally which may well not end up being used. That's not
10353 -- a good idea since it wastes space gratuitously ???
10355 Accept_Case
: List_Id
;
10356 Accept_List
: constant List_Id
:= New_List
;
10359 Alt_List
: constant List_Id
:= New_List
;
10360 Alt_Stats
: List_Id
;
10361 Ann
: Entity_Id
:= Empty
;
10363 Check_Guard
: Boolean := True;
10365 Decls
: constant List_Id
:= New_List
;
10366 Stats
: constant List_Id
:= New_List
;
10367 Body_List
: constant List_Id
:= New_List
;
10368 Trailing_List
: constant List_Id
:= New_List
;
10371 Else_Present
: Boolean := False;
10372 Terminate_Alt
: Node_Id
:= Empty
;
10373 Select_Mode
: Node_Id
;
10375 Delay_Case
: List_Id
;
10376 Delay_Count
: Integer := 0;
10377 Delay_Val
: Entity_Id
;
10378 Delay_Index
: Entity_Id
;
10379 Delay_Min
: Entity_Id
;
10380 Delay_Num
: Pos
:= 1;
10381 Delay_Alt_List
: List_Id
:= New_List
;
10382 Delay_List
: constant List_Id
:= New_List
;
10386 First_Delay
: Boolean := True;
10387 Guard_Open
: Entity_Id
;
10393 Num_Accept
: Nat
:= 0;
10395 Time_Type
: Entity_Id
:= Empty
;
10396 Select_Call
: Node_Id
;
10398 Qnam
: constant Entity_Id
:=
10399 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10401 Xnam
: constant Entity_Id
:=
10402 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10404 -----------------------
10405 -- Local subprograms --
10406 -----------------------
10408 function Accept_Or_Raise
return List_Id
;
10409 -- For the rare case where delay alternatives all have guards, and
10410 -- all of them are closed, it is still possible that there were open
10411 -- accept alternatives with no callers. We must reexamine the
10412 -- Accept_List, and execute a selective wait with no else if some
10413 -- accept is open. If none, we raise program_error.
10415 procedure Add_Accept
(Alt
: Node_Id
);
10416 -- Process a single accept statement in a select alternative. Build
10417 -- procedure for body of accept, and add entry to dispatch table with
10418 -- expression for guard, in preparation for call to run time select.
10420 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10421 -- Manufacture a label using Num as a serial number and declare it.
10422 -- The declaration is appended to Decls. The label marks the trailing
10423 -- statements of an accept or delay alternative.
10425 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10426 -- Build call to Selective_Wait runtime routine
10428 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10429 -- Add code to compare value of delay with previous values, and
10430 -- generate case entry for trailing statements.
10432 procedure Process_Accept_Alternative
10436 -- Add code to call corresponding procedure, and branch to
10437 -- trailing statements, if any.
10439 ---------------------
10440 -- Accept_Or_Raise --
10441 ---------------------
10443 function Accept_Or_Raise
return List_Id
is
10446 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10449 -- We generate the following:
10451 -- for J in q'range loop
10452 -- if q(J).S /=null_task_entry then
10453 -- selective_wait (simple_mode,...);
10459 -- if no rendez_vous then
10460 -- raise program_error;
10463 -- Note that the code needs to know that the selector name
10464 -- in an Accept_Alternative is named S.
10466 Cond
:= Make_Op_Ne
(Loc
,
10468 Make_Selected_Component
(Loc
,
10470 Make_Indexed_Component
(Loc
,
10471 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10472 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10473 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10475 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10477 Stats
:= New_List
(
10478 Make_Implicit_Loop_Statement
(N
,
10479 Iteration_Scheme
=>
10480 Make_Iteration_Scheme
(Loc
,
10481 Loop_Parameter_Specification
=>
10482 Make_Loop_Parameter_Specification
(Loc
,
10483 Defining_Identifier
=> J
,
10484 Discrete_Subtype_Definition
=>
10485 Make_Attribute_Reference
(Loc
,
10486 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10487 Attribute_Name
=> Name_Range
,
10488 Expressions
=> New_List
(
10489 Make_Integer_Literal
(Loc
, 1))))),
10491 Statements
=> New_List
(
10492 Make_Implicit_If_Statement
(N
,
10494 Then_Statements
=> New_List
(
10496 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10497 Make_Exit_Statement
(Loc
))))));
10500 Make_Raise_Program_Error
(Loc
,
10501 Condition
=> Make_Op_Eq
(Loc
,
10502 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10504 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10505 Reason
=> PE_All_Guards_Closed
));
10508 end Accept_Or_Raise
;
10514 procedure Add_Accept
(Alt
: Node_Id
) is
10515 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10516 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10517 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10518 Eent
: constant Entity_Id
:= Entity
(Ename
);
10519 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10523 Null_Body
: Node_Id
;
10524 PB_Ent
: Entity_Id
;
10525 Proc_Body
: Node_Id
;
10527 -- Start of processing for Add_Accept
10531 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10534 if Present
(Condition
(Alt
)) then
10536 Make_If_Expression
(Eloc
, New_List
(
10538 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10539 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10541 Expr
:= Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
));
10544 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10545 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10547 -- Always add call to Abort_Undefer when generating code, since
10548 -- this is what the runtime expects (abort deferred in
10549 -- Selective_Wait). In CodePeer mode this only confuses the
10550 -- analysis with unknown calls, so don't do it.
10552 if not CodePeer_Mode
then
10553 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10555 (First
(Statements
(Handled_Statement_Sequence
10556 (Accept_Statement
(Alt
)))),
10562 Make_Defining_Identifier
(Eloc
,
10563 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10565 -- Link the acceptor to the original receiving entry
10567 Mutate_Ekind
(PB_Ent
, E_Procedure
);
10568 Set_Receiving_Entry
(PB_Ent
, Eent
);
10570 if Comes_From_Source
(Alt
) then
10571 Set_Debug_Info_Needed
(PB_Ent
);
10575 Make_Subprogram_Body
(Eloc
,
10577 Make_Procedure_Specification
(Eloc
,
10578 Defining_Unit_Name
=> PB_Ent
),
10579 Declarations
=> Declarations
(Acc_Stm
),
10580 Handled_Statement_Sequence
=>
10581 Build_Accept_Body
(Accept_Statement
(Alt
)));
10583 Reset_Scopes_To
(Proc_Body
, PB_Ent
);
10585 -- During the analysis of the body of the accept statement, any
10586 -- zero cost exception handler records were collected in the
10587 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10588 -- This is where we move them to where they belong, namely the
10589 -- newly created procedure.
10591 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10592 Append
(Proc_Body
, Body_List
);
10595 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10597 -- if accept statement has declarations, insert above, given that
10598 -- we are not creating a body for the accept.
10600 if Present
(Declarations
(Acc_Stm
)) then
10601 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10605 Append_To
(Accept_List
,
10606 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10608 Num_Accept
:= Num_Accept
+ 1;
10611 ----------------------------
10612 -- Make_And_Declare_Label --
10613 ----------------------------
10615 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10619 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10621 Make_Label
(Loc
, Lab_Id
);
10624 Make_Implicit_Label_Declaration
(Loc
,
10625 Defining_Identifier
=>
10626 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10627 Label_Construct
=> Lab
));
10630 end Make_And_Declare_Label
;
10632 ----------------------
10633 -- Make_Select_Call --
10634 ----------------------
10636 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10637 Params
: constant List_Id
:= New_List
;
10641 Make_Attribute_Reference
(Loc
,
10642 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10643 Attribute_Name
=> Name_Unchecked_Access
));
10644 Append_To
(Params
, Select_Mode
);
10645 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10646 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10649 Make_Procedure_Call_Statement
(Loc
,
10650 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10651 Parameter_Associations
=> Params
);
10652 end Make_Select_Call
;
10654 --------------------------------
10655 -- Process_Accept_Alternative --
10656 --------------------------------
10658 procedure Process_Accept_Alternative
10663 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10664 Alt_Stats
: List_Id
;
10667 Adjust_Condition
(Condition
(Alt
));
10669 -- Accept with body
10671 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10674 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10677 (Defining_Unit_Name
(Specification
(Proc
)),
10680 -- Accept with no body (followed by trailing statements)
10684 Entry_Id
: constant Entity_Id
:=
10685 Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)));
10687 -- Ada 2022 (AI12-0279)
10689 if Has_Yield_Aspect
(Entry_Id
)
10690 and then RTE_Available
(RE_Yield
)
10694 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10695 New_Occurrence_Of
(RTE
(RE_Yield
), Sloc
(Proc
))));
10697 Alt_Stats
:= Empty_List
;
10702 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10704 -- After the call, if any, branch to trailing statements, if any.
10705 -- We create a label for each, as well as the corresponding label
10708 if not Is_Empty_List
(Statements
(Alt
)) then
10709 Lab
:= Make_And_Declare_Label
(Index
);
10710 Append
(Lab
, Trailing_List
);
10711 Append_List
(Statements
(Alt
), Trailing_List
);
10712 Append_To
(Trailing_List
,
10713 Make_Goto_Statement
(Loc
,
10714 Name
=> New_Copy
(Identifier
(End_Lab
))));
10720 Append_To
(Alt_Stats
,
10721 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10723 Append_To
(Alt_List
,
10724 Make_Case_Statement_Alternative
(Loc
,
10725 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10726 Statements
=> Alt_Stats
));
10727 end Process_Accept_Alternative
;
10729 -------------------------------
10730 -- Process_Delay_Alternative --
10731 -------------------------------
10733 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10734 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10736 Delay_Alt
: List_Id
;
10739 -- Deal with C/Fortran boolean as delay condition
10741 Adjust_Condition
(Condition
(Alt
));
10743 -- Determine the smallest specified delay
10745 -- for each delay alternative generate:
10747 -- if guard-expression then
10748 -- Delay_Val := delay-expression;
10749 -- Guard_Open := True;
10750 -- if Delay_Val < Delay_Min then
10751 -- Delay_Min := Delay_Val;
10752 -- Delay_Index := Index;
10756 -- The enclosing if-statement is omitted if there is no guard
10758 if Delay_Count
= 1 or else First_Delay
then
10759 First_Delay
:= False;
10761 Delay_Alt
:= New_List
(
10762 Make_Assignment_Statement
(Loc
,
10763 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10764 Expression
=> Expression
(Delay_Statement
(Alt
))));
10766 if Delay_Count
> 1 then
10767 Append_To
(Delay_Alt
,
10768 Make_Assignment_Statement
(Loc
,
10769 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10770 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10774 Delay_Alt
:= New_List
(
10775 Make_Assignment_Statement
(Loc
,
10776 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10777 Expression
=> Expression
(Delay_Statement
(Alt
))));
10779 if Time_Type
= Standard_Duration
then
10782 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10783 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10786 -- The scope of the time type must define a comparison
10787 -- operator. The scope itself may not be visible, so we
10788 -- construct a node with entity information to insure that
10789 -- semantic analysis can find the proper operator.
10792 Make_Function_Call
(Loc
,
10793 Name
=> Make_Selected_Component
(Loc
,
10795 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10797 Make_Operator_Symbol
(Loc
,
10798 Chars
=> Name_Op_Lt
,
10799 Strval
=> No_String
)),
10800 Parameter_Associations
=>
10802 New_Occurrence_Of
(Delay_Val
, Loc
),
10803 New_Occurrence_Of
(Delay_Min
, Loc
)));
10805 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10808 Append_To
(Delay_Alt
,
10809 Make_Implicit_If_Statement
(N
,
10811 Then_Statements
=> New_List
(
10812 Make_Assignment_Statement
(Loc
,
10813 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10814 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10816 Make_Assignment_Statement
(Loc
,
10817 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10818 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10821 if Check_Guard
then
10822 Append_To
(Delay_Alt
,
10823 Make_Assignment_Statement
(Loc
,
10824 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10825 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10828 if Present
(Condition
(Alt
)) then
10829 Delay_Alt
:= New_List
(
10830 Make_Implicit_If_Statement
(N
,
10831 Condition
=> Condition
(Alt
),
10832 Then_Statements
=> Delay_Alt
));
10835 Append_List
(Delay_Alt
, Delay_List
);
10837 Ensure_Statement_Present
(Dloc
, Alt
);
10839 -- If the delay alternative has a statement part, add choice to the
10840 -- case statements for delays.
10842 if not Is_Empty_List
(Statements
(Alt
)) then
10844 if Delay_Count
= 1 then
10845 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10848 Append_To
(Delay_Alt_List
,
10849 Make_Case_Statement_Alternative
(Loc
,
10850 Discrete_Choices
=> New_List
(
10851 Make_Integer_Literal
(Loc
, Index
)),
10852 Statements
=> Statements
(Alt
)));
10855 elsif Delay_Count
= 1 then
10857 -- If the single delay has no trailing statements, add a branch
10858 -- to the exit label to the selective wait.
10860 Delay_Alt_List
:= New_List
(
10861 Make_Goto_Statement
(Loc
,
10862 Name
=> New_Copy
(Identifier
(End_Lab
))));
10865 end Process_Delay_Alternative
;
10867 -- Start of processing for Expand_N_Selective_Accept
10870 Process_Statements_For_Controlled_Objects
(N
);
10872 -- First insert some declarations before the select. The first is:
10876 -- This variable holds the parameters passed to the accept body. This
10877 -- declaration has already been inserted by the time we get here by
10878 -- a call to Expand_Accept_Declarations made from the semantics when
10879 -- processing the first accept statement contained in the select. We
10880 -- can find this entity as Accept_Address (E), where E is any of the
10881 -- entries references by contained accept statements.
10883 -- The first step is to scan the list of Selective_Accept_Statements
10884 -- to find this entity, and also count the number of accepts, and
10885 -- determine if terminated, delay or else is present:
10889 Alt
:= First
(Alts
);
10890 while Present
(Alt
) loop
10891 Process_Statements_For_Controlled_Objects
(Alt
);
10893 if Nkind
(Alt
) = N_Accept_Alternative
then
10896 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10897 Delay_Count
:= Delay_Count
+ 1;
10899 -- If the delays are relative delays, the delay expressions have
10900 -- type Standard_Duration. Otherwise they must have some time type
10901 -- recognized by GNAT.
10903 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10904 Time_Type
:= Standard_Duration
;
10906 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10908 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10909 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10913 -- Move this check to sem???
10915 "& is not a time type (RM 9.6(6))",
10916 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10917 Time_Type
:= Standard_Duration
;
10918 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10922 if No
(Condition
(Alt
)) then
10924 -- This guard will always be open
10926 Check_Guard
:= False;
10929 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10930 Adjust_Condition
(Condition
(Alt
));
10931 Terminate_Alt
:= Alt
;
10934 Num_Alts
:= Num_Alts
+ 1;
10938 Else_Present
:= Present
(Else_Statements
(N
));
10940 -- At the same time (see procedure Add_Accept) we build the accept list:
10942 -- Qnn : Accept_List (1 .. num-select) := (
10943 -- (null-body, entry-index),
10944 -- (null-body, entry-index),
10946 -- (null_body, entry-index));
10948 -- In the above declaration, null-body is True if the corresponding
10949 -- accept has no body, and false otherwise. The entry is either the
10950 -- entry index expression if there is no guard, or if a guard is
10951 -- present, then an if expression of the form:
10953 -- (if guard then entry-index else Null_Task_Entry)
10955 -- If a guard is statically known to be false, the entry can simply
10956 -- be omitted from the accept list.
10959 Make_Object_Declaration
(Loc
,
10960 Defining_Identifier
=> Qnam
,
10961 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10962 Aliased_Present
=> True,
10964 Make_Qualified_Expression
(Loc
,
10966 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10968 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10970 -- Then we declare the variable that holds the index for the accept
10971 -- that will be selected for service:
10973 -- Xnn : Select_Index;
10976 Make_Object_Declaration
(Loc
,
10977 Defining_Identifier
=> Xnam
,
10978 Object_Definition
=>
10979 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10981 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10983 -- After this follow procedure declarations for each accept body
10985 -- procedure Pnn is
10990 -- where the ... are statements from the corresponding procedure body.
10991 -- No parameters are involved, since the parameters are passed via Ann
10992 -- and the parameter references have already been expanded to be direct
10993 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10994 -- any embedded tasking statements (which would normally be illegal in
10995 -- procedures), have been converted to calls to the tasking runtime so
10996 -- there is no problem in putting them into procedures.
10998 -- The original accept statement has been expanded into a block in
10999 -- the same fashion as for simple accepts (see Build_Accept_Body).
11001 -- Note: we don't really need to build these procedures for the case
11002 -- where no delay statement is present, but it is just as easy to
11003 -- build them unconditionally, and not significantly inefficient,
11004 -- since if they are short they will be inlined anyway.
11006 -- The procedure declarations have been assembled in Body_List
11008 -- If delays are present, we must compute the required delay.
11009 -- We first generate the declarations:
11011 -- Delay_Index : Boolean := 0;
11012 -- Delay_Min : Some_Time_Type.Time;
11013 -- Delay_Val : Some_Time_Type.Time;
11015 -- Delay_Index will be set to the index of the minimum delay, i.e. the
11016 -- active delay that is actually chosen as the basis for the possible
11017 -- delay if an immediate rendez-vous is not possible.
11019 -- In the most common case there is a single delay statement, and this
11020 -- is handled specially.
11022 if Delay_Count
> 0 then
11024 -- Generate the required declarations
11027 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
11029 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
11031 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
11033 pragma Assert
(Present
(Time_Type
));
11036 Make_Object_Declaration
(Loc
,
11037 Defining_Identifier
=> Delay_Val
,
11038 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
11041 Make_Object_Declaration
(Loc
,
11042 Defining_Identifier
=> Delay_Index
,
11043 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11044 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11047 Make_Object_Declaration
(Loc
,
11048 Defining_Identifier
=> Delay_Min
,
11049 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11051 Unchecked_Convert_To
(Time_Type
,
11052 Make_Attribute_Reference
(Loc
,
11054 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11055 Attribute_Name
=> Name_Last
))));
11057 -- Create Duration and Delay_Mode objects used for passing a delay
11060 D
:= Make_Temporary
(Loc
, 'D');
11061 M
:= Make_Temporary
(Loc
, 'M');
11067 -- Note that these values are defined in s-osprim.ads and must
11068 -- be kept in sync:
11070 -- Relative : constant := 0;
11071 -- Absolute_Calendar : constant := 1;
11072 -- Absolute_RT : constant := 2;
11074 if Time_Type
= Standard_Duration
then
11075 Discr
:= Make_Integer_Literal
(Loc
, 0);
11077 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11078 Discr
:= Make_Integer_Literal
(Loc
, 1);
11082 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11083 Discr
:= Make_Integer_Literal
(Loc
, 2);
11087 Make_Object_Declaration
(Loc
,
11088 Defining_Identifier
=> D
,
11089 Object_Definition
=>
11090 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11093 Make_Object_Declaration
(Loc
,
11094 Defining_Identifier
=> M
,
11095 Object_Definition
=>
11096 New_Occurrence_Of
(Standard_Integer
, Loc
),
11097 Expression
=> Discr
));
11100 if Check_Guard
then
11102 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11105 Make_Object_Declaration
(Loc
,
11106 Defining_Identifier
=> Guard_Open
,
11107 Object_Definition
=>
11108 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11110 New_Occurrence_Of
(Standard_False
, Loc
)));
11113 -- Delay_Count is zero, don't need M and D set (suppress warning)
11120 if Present
(Terminate_Alt
) then
11122 -- If the terminate alternative guard is False, use
11123 -- Simple_Mode; otherwise use Terminate_Mode.
11125 if Present
(Condition
(Terminate_Alt
)) then
11126 Select_Mode
:= Make_If_Expression
(Loc
,
11127 New_List
(Condition
(Terminate_Alt
),
11128 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11129 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11131 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11134 elsif Else_Present
or Delay_Count
> 0 then
11135 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11138 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11141 Select_Call
:= Make_Select_Call
(Select_Mode
);
11142 Append
(Select_Call
, Stats
);
11144 -- Now generate code to act on the result. There is an entry
11145 -- in this case for each accept statement with a non-null body,
11146 -- followed by a branch to the statements that follow the Accept.
11147 -- In the absence of delay alternatives, we generate:
11150 -- when No_Rendezvous => -- omitted if simple mode
11165 -- Lab0: Else_Statements;
11168 -- Lab1: Trailing_Statements1;
11171 -- Lab2: Trailing_Statements2;
11176 -- Generate label for common exit
11178 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11180 -- First entry is the default case, when no rendezvous is possible
11182 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11184 if Else_Present
then
11186 -- If no rendezvous is possible, the else part is executed
11188 Lab
:= Make_And_Declare_Label
(0);
11189 Alt_Stats
:= New_List
(
11190 Make_Goto_Statement
(Loc
,
11191 Name
=> New_Copy
(Identifier
(Lab
))));
11193 Append
(Lab
, Trailing_List
);
11194 Append_List
(Else_Statements
(N
), Trailing_List
);
11195 Append_To
(Trailing_List
,
11196 Make_Goto_Statement
(Loc
,
11197 Name
=> New_Copy
(Identifier
(End_Lab
))));
11199 Alt_Stats
:= New_List
(
11200 Make_Goto_Statement
(Loc
,
11201 Name
=> New_Copy
(Identifier
(End_Lab
))));
11204 Append_To
(Alt_List
,
11205 Make_Case_Statement_Alternative
(Loc
,
11206 Discrete_Choices
=> Choices
,
11207 Statements
=> Alt_Stats
));
11209 -- We make use of the fact that Accept_Index is an integer type, and
11210 -- generate successive literals for entries for each accept. Only those
11211 -- for which there is a body or trailing statements get a case entry.
11213 Alt
:= First
(Select_Alternatives
(N
));
11214 Proc
:= First
(Body_List
);
11215 while Present
(Alt
) loop
11217 if Nkind
(Alt
) = N_Accept_Alternative
then
11218 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11219 Index
:= Index
+ 1;
11222 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11227 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11228 Process_Delay_Alternative
(Alt
, Delay_Num
);
11229 Delay_Num
:= Delay_Num
+ 1;
11235 -- An others choice is always added to the main case, as well
11236 -- as the delay case (to satisfy the compiler).
11238 Append_To
(Alt_List
,
11239 Make_Case_Statement_Alternative
(Loc
,
11240 Discrete_Choices
=>
11241 New_List
(Make_Others_Choice
(Loc
)),
11243 New_List
(Make_Goto_Statement
(Loc
,
11244 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11246 Accept_Case
:= New_List
(
11247 Make_Case_Statement
(Loc
,
11248 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11249 Alternatives
=> Alt_List
));
11251 Append_List
(Trailing_List
, Accept_Case
);
11252 Append_List
(Body_List
, Decls
);
11254 -- Construct case statement for trailing statements of delay
11255 -- alternatives, if there are several of them.
11257 if Delay_Count
> 1 then
11258 Append_To
(Delay_Alt_List
,
11259 Make_Case_Statement_Alternative
(Loc
,
11260 Discrete_Choices
=>
11261 New_List
(Make_Others_Choice
(Loc
)),
11263 New_List
(Make_Null_Statement
(Loc
))));
11265 Delay_Case
:= New_List
(
11266 Make_Case_Statement
(Loc
,
11267 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11268 Alternatives
=> Delay_Alt_List
));
11270 Delay_Case
:= Delay_Alt_List
;
11273 -- If there are no delay alternatives, we append the case statement
11274 -- to the statement list.
11276 if Delay_Count
= 0 then
11277 Append_List
(Accept_Case
, Stats
);
11279 -- Delay alternatives present
11282 -- If delay alternatives are present we generate:
11284 -- find minimum delay.
11285 -- DX := minimum delay;
11286 -- M := <delay mode>;
11287 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11290 -- if X = No_Rendezvous then
11291 -- case statement for delay statements.
11293 -- case statement for accept alternatives.
11304 -- The type of the delay expression is known to be legal
11306 if Time_Type
= Standard_Duration
then
11307 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11309 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11310 Conv
:= Make_Function_Call
(Loc
,
11311 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11312 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11316 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11318 Conv
:= Make_Function_Call
(Loc
,
11319 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11320 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11323 Stmt
:= Make_Assignment_Statement
(Loc
,
11324 Name
=> New_Occurrence_Of
(D
, Loc
),
11325 Expression
=> Conv
);
11327 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11329 Parms
:= Parameter_Associations
(Select_Call
);
11331 Parm
:= First
(Parms
);
11332 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11336 pragma Assert
(Present
(Parm
));
11337 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11340 -- Prepare two new parameters of Duration and Delay_Mode type
11341 -- which represent the value and the mode of the minimum delay.
11344 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11345 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11347 -- Create a call to RTS
11349 Rewrite
(Select_Call
,
11350 Make_Procedure_Call_Statement
(Loc
,
11351 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11352 Parameter_Associations
=> Parms
));
11354 -- This new call should follow the calculation of the minimum
11357 Insert_List_Before
(Select_Call
, Delay_List
);
11359 if Check_Guard
then
11361 Make_Implicit_If_Statement
(N
,
11362 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11363 Then_Statements
=> New_List
(
11364 New_Copy_Tree
(Stmt
),
11365 New_Copy_Tree
(Select_Call
)),
11366 Else_Statements
=> Accept_Or_Raise
);
11367 Rewrite
(Select_Call
, Stmt
);
11369 Insert_Before
(Select_Call
, Stmt
);
11373 Make_Implicit_If_Statement
(N
,
11374 Condition
=> Make_Op_Eq
(Loc
,
11375 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11377 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11379 Then_Statements
=> Delay_Case
,
11380 Else_Statements
=> Accept_Case
);
11382 Append
(Cases
, Stats
);
11386 Append
(End_Lab
, Stats
);
11388 -- Replace accept statement with appropriate block
11391 Make_Block_Statement
(Loc
,
11392 Declarations
=> Decls
,
11393 Handled_Statement_Sequence
=>
11394 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11397 -- Note: have to worry more about abort deferral in above code ???
11399 -- Final step is to unstack the Accept_Address entries for all accept
11400 -- statements appearing in accept alternatives in the select statement
11402 Alt
:= First
(Alts
);
11403 while Present
(Alt
) loop
11404 if Nkind
(Alt
) = N_Accept_Alternative
then
11405 Remove_Last_Elmt
(Accept_Address
11406 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11411 end Expand_N_Selective_Accept
;
11413 -------------------------------------------
11414 -- Expand_N_Single_Protected_Declaration --
11415 -------------------------------------------
11417 -- A single protected declaration should never be present after semantic
11418 -- analysis because it is transformed into a protected type declaration
11419 -- and an accompanying anonymous object. This routine ensures that the
11420 -- transformation takes place.
11422 procedure Expand_N_Single_Protected_Declaration
(N
: Node_Id
) is
11424 raise Program_Error
;
11425 end Expand_N_Single_Protected_Declaration
;
11427 --------------------------------------
11428 -- Expand_N_Single_Task_Declaration --
11429 --------------------------------------
11431 -- A single task declaration should never be present after semantic
11432 -- analysis because it is transformed into a task type declaration and
11433 -- an accompanying anonymous object. This routine ensures that the
11434 -- transformation takes place.
11436 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11438 raise Program_Error
;
11439 end Expand_N_Single_Task_Declaration
;
11441 ------------------------
11442 -- Expand_N_Task_Body --
11443 ------------------------
11445 -- Given a task body
11447 -- task body tname is
11453 -- This expansion routine converts it into a procedure and sets the
11454 -- elaboration flag for the procedure to true, to represent the fact
11455 -- that the task body is now elaborated:
11457 -- procedure tnameB (_Task : access tnameV) is
11458 -- discriminal : dtype renames _Task.discriminant;
11460 -- procedure _clean is
11462 -- Abort_Defer.all;
11464 -- Abort_Undefer.all;
11469 -- Abort_Undefer.all;
11471 -- System.Task_Stages.Complete_Activation;
11479 -- In addition, if the task body is an activator, then a call to activate
11480 -- tasks is added at the start of the statements, before the call to
11481 -- Complete_Activation, and if in addition the task is a master then it
11482 -- must be established as a master. These calls are inserted and analyzed
11483 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11486 -- There is one discriminal declaration line generated for each
11487 -- discriminant that is present to provide an easy reference point for
11488 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11490 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11491 -- task body procedures have a profile (Arg : System.Address). That is
11492 -- needed because GNARLI has to use the same access-to-subprogram type
11493 -- for all task types. We depend here on knowing that in GNAT, passing
11494 -- an address argument by value is identical to passing a record value
11495 -- by access (in either case a single pointer is passed), so even though
11496 -- this procedure has the wrong profile. In fact it's all OK, since the
11497 -- callings sequence is identical.
11499 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11500 Loc
: constant Source_Ptr
:= Sloc
(N
);
11501 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11505 Insert_Nod
: Node_Id
;
11506 -- Used to determine the proper location of wrapper body insertions
11509 -- if no task body procedure, means we had an error in configurable
11510 -- run-time mode, and there is no point in proceeding further.
11512 if No
(Task_Body_Procedure
(Ttyp
)) then
11516 -- Add renaming declarations for discriminals and a declaration for the
11517 -- entry family index (if applicable).
11519 Install_Private_Data_Declarations
11520 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11522 -- Add a call to Abort_Undefer at the very beginning of the task
11523 -- body since this body is called with abort still deferred.
11525 if Abort_Allowed
then
11526 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11527 Prepend
(Call
, Declarations
(N
));
11531 -- Place call to Complete_Activation at the head of the statement list.
11533 if Restricted_Profile
then
11534 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11536 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11540 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11544 Make_Subprogram_Body
(Loc
,
11545 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11546 Declarations
=> Declarations
(N
),
11547 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11548 Set_Is_Task_Body_Procedure
(New_N
);
11549 Set_At_End_Proc
(New_N
, At_End_Proc
(N
));
11551 -- If the task contains generic instantiations, cleanup actions are
11552 -- delayed until after instantiation. Transfer the activation chain to
11553 -- the subprogram, to insure that the activation call is properly
11554 -- generated. It the task body contains inner tasks, indicate that the
11555 -- subprogram is a task master.
11557 if Delay_Cleanups
(Ttyp
) then
11558 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11559 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11562 Rewrite
(N
, New_N
);
11565 -- Set elaboration flag immediately after task body. If the body is a
11566 -- subunit, the flag is set in the declarative part containing the stub.
11568 if Nkind
(Parent
(N
)) /= N_Subunit
then
11570 Make_Assignment_Statement
(Loc
,
11572 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11573 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11576 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11577 -- the task body. At this point all wrapper specs have been created,
11578 -- frozen and included in the dispatch table for the task type.
11580 if Ada_Version
>= Ada_2005
then
11581 if Nkind
(Parent
(N
)) = N_Subunit
then
11582 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11587 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11589 end Expand_N_Task_Body
;
11591 ------------------------------------
11592 -- Expand_N_Task_Type_Declaration --
11593 ------------------------------------
11595 -- We have several things to do. First we must create a Boolean flag used
11596 -- to mark if the body is elaborated yet. This variable gets set to True
11597 -- when the body of the task is elaborated (we can't rely on the normal
11598 -- ABE mechanism for the task body, since we need to pass an access to
11599 -- this elaboration boolean to the runtime routines).
11601 -- taskE : aliased Boolean := False;
11603 -- Next a variable is declared to hold the task stack size (either the
11604 -- default : Unspecified_Size, or a value that is set by a pragma
11605 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11606 -- the variable is initialized with this value:
11608 -- taskZ : Size_Type := Unspecified_Size;
11610 -- taskZ : Size_Type := Size_Type (size_expression);
11612 -- Note: No variable is needed to hold the task relative deadline since
11613 -- its value would never be static because the parameter is of a private
11614 -- type (Ada.Real_Time.Time_Span).
11616 -- Next we create a corresponding record type declaration used to represent
11617 -- values of this task. The general form of this type declaration is
11619 -- type taskV (discriminants) is record
11620 -- _Task_Id : Task_Id;
11621 -- entry_family : array (bounds) of Void;
11622 -- _Priority : Integer := priority_expression;
11623 -- _Size : Size_Type := size_expression;
11624 -- _Secondary_Stack_Size : Size_Type := size_expression;
11625 -- _Task_Info : Task_Info_Type := task_info_expression;
11626 -- _CPU : Integer := cpu_range_expression;
11627 -- _Relative_Deadline : Time_Span := time_span_expression;
11628 -- _Domain : Dispatching_Domain := dd_expression;
11631 -- The discriminants are present only if the corresponding task type has
11632 -- discriminants, and they exactly mirror the task type discriminants.
11634 -- The Id field is always present. It contains the Task_Id value, as set by
11635 -- the call to Create_Task. Note that although the task is limited, the
11636 -- task value record type is not limited, so there is no problem in passing
11637 -- this field as an out parameter to Create_Task.
11639 -- One entry_family component is present for each entry family in the task
11640 -- definition. The bounds correspond to the bounds of the entry family
11641 -- (which may depend on discriminants). The element type is void, since we
11642 -- only need the bounds information for determining the entry index. Note
11643 -- that the use of an anonymous array would normally be illegal in this
11644 -- context, but this is a parser check, and the semantics is quite prepared
11645 -- to handle such a case.
11647 -- The _Size field is present only if a Storage_Size pragma appears in the
11648 -- task definition. The expression captures the argument that was present
11649 -- in the pragma, and is used to override the task stack size otherwise
11650 -- associated with the task type.
11652 -- The _Secondary_Stack_Size field is present only the task entity has a
11653 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11654 -- when the record init proc is built, to capture the expression of the
11655 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11656 -- be filled here since aspect evaluations are delayed till the freeze
11659 -- The _Priority field is present only if the task entity has a Priority or
11660 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11661 -- definition clause). It will be filled at the freeze point, when the
11662 -- record init proc is built, to capture the expression of the rep item
11663 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11664 -- here since aspect evaluations are delayed till the freeze point.
11666 -- The _Task_Info field is present only if a Task_Info pragma appears in
11667 -- the task definition. The expression captures the argument that was
11668 -- present in the pragma, and is used to provide the Task_Image parameter
11669 -- to the call to Create_Task.
11671 -- The _CPU field is present only if the task entity has a CPU rep item
11672 -- (pragma, aspect specification or attribute definition clause). It will
11673 -- be filled at the freeze point, when the record init proc is built, to
11674 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11675 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11676 -- are delayed till the freeze point.
11678 -- The _Relative_Deadline field is present only if a Relative_Deadline
11679 -- pragma appears in the task definition. The expression captures the
11680 -- argument that was present in the pragma, and is used to provide the
11681 -- Relative_Deadline parameter to the call to Create_Task.
11683 -- The _Domain field is present only if the task entity has a
11684 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11685 -- definition clause). It will be filled at the freeze point, when the
11686 -- record init proc is built, to capture the expression of the rep item
11687 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11688 -- here since aspect evaluations are delayed till the freeze point.
11690 -- When a task is declared, an instance of the task value record is
11691 -- created. The elaboration of this declaration creates the correct bounds
11692 -- for the entry families, and also evaluates the size, priority, and
11693 -- task_Info expressions if needed. The initialization routine for the task
11694 -- type itself then calls Create_Task with appropriate parameters to
11695 -- initialize the value of the Task_Id field.
11697 -- Note: the address of this record is passed as the "Discriminants"
11698 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11699 -- body procedure, it does not matter that it does not quite match the
11700 -- GNARLI model of what is being passed (the record contains more than just
11701 -- the discriminants, but the discriminants can be found from the record
11704 -- The Entity_Id for this created record type is placed in the
11705 -- Corresponding_Record_Type field of the associated task type entity.
11707 -- Next we create a procedure specification for the task body procedure:
11709 -- procedure taskB (_Task : access taskV);
11711 -- Note that this must come after the record type declaration, since
11712 -- the spec refers to this type. It turns out that the initialization
11713 -- procedure for the value type references the task body spec, but that's
11714 -- fine, since it won't be generated till the freeze point for the type,
11715 -- which is certainly after the task body spec declaration.
11717 -- Finally, we set the task index value field of the entry attribute in
11718 -- the case of a simple entry.
11720 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11721 Loc
: constant Source_Ptr
:= Sloc
(N
);
11722 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11723 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11724 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11725 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11727 Body_Decl
: Node_Id
;
11729 Decl_Stack
: Node_Id
;
11731 Elab_Decl
: Node_Id
;
11732 Ent_Stack
: Entity_Id
;
11733 Proc_Spec
: Node_Id
;
11734 Rec_Decl
: Node_Id
;
11735 Rec_Ent
: Entity_Id
;
11736 Size_Decl
: Entity_Id
;
11737 Task_Size
: Node_Id
;
11739 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11740 -- Searches the task definition T for the first occurrence of the pragma
11741 -- Relative Deadline. The caller has ensured that the pragma is present
11742 -- in the task definition. Note that this routine cannot be implemented
11743 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11744 -- not chained because their expansion into a procedure call statement
11745 -- would cause a break in the chain.
11747 ----------------------------------
11748 -- Get_Relative_Deadline_Pragma --
11749 ----------------------------------
11751 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11755 N
:= First
(Visible_Declarations
(T
));
11756 while Present
(N
) loop
11757 if Nkind
(N
) = N_Pragma
11758 and then Pragma_Name
(N
) = Name_Relative_Deadline
11766 N
:= First
(Private_Declarations
(T
));
11767 while Present
(N
) loop
11768 if Nkind
(N
) = N_Pragma
11769 and then Pragma_Name
(N
) = Name_Relative_Deadline
11777 raise Program_Error
;
11778 end Get_Relative_Deadline_Pragma
;
11780 -- Start of processing for Expand_N_Task_Type_Declaration
11783 -- If already expanded, nothing to do
11785 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11789 -- Here we will do the expansion
11791 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11793 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11794 Cdecls
:= Component_Items
(Component_List
11795 (Type_Definition
(Rec_Decl
)));
11797 Qualify_Entity_Names
(N
);
11799 -- First create the elaboration variable
11802 Make_Object_Declaration
(Loc
,
11803 Defining_Identifier
=>
11804 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11805 Chars
=> New_External_Name
(Tasknm
, 'E')),
11806 Aliased_Present
=> True,
11807 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11808 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11810 Insert_After
(N
, Elab_Decl
);
11812 -- Next create the declaration of the size variable (tasknmZ)
11814 Set_Storage_Size_Variable
(Tasktyp
,
11815 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11816 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11818 if Present
(Taskdef
)
11819 and then Has_Storage_Size_Pragma
(Taskdef
)
11821 Is_OK_Static_Expression
11823 (First
(Pragma_Argument_Associations
11824 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11827 Make_Object_Declaration
(Loc
,
11828 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11829 Object_Definition
=>
11830 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11832 Convert_To
(RTE
(RE_Size_Type
),
11834 (Expression
(First
(Pragma_Argument_Associations
11836 (TaskId
, Name_Storage_Size
)))))));
11840 Make_Object_Declaration
(Loc
,
11841 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11842 Object_Definition
=>
11843 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11845 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11848 Insert_After
(Elab_Decl
, Size_Decl
);
11850 -- Next build the rest of the corresponding record declaration. This is
11851 -- done last, since the corresponding record initialization procedure
11852 -- will reference the previously created entities.
11854 -- Fill in the component declarations -- first the _Task_Id field
11857 Make_Component_Declaration
(Loc
,
11858 Defining_Identifier
=>
11859 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11860 Component_Definition
=>
11861 Make_Component_Definition
(Loc
,
11862 Aliased_Present
=> False,
11863 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11866 -- Declare static ATCB (that is, created by the expander) if we are
11867 -- using the Restricted run time.
11869 if Restricted_Profile
then
11871 Make_Component_Declaration
(Loc
,
11872 Defining_Identifier
=>
11873 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11875 Component_Definition
=>
11876 Make_Component_Definition
(Loc
,
11877 Aliased_Present
=> True,
11878 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11880 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11883 Make_Index_Or_Discriminant_Constraint
(Loc
,
11885 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11889 -- Declare static stack (that is, created by the expander) if we are
11890 -- using the Restricted run time on a bare board configuration.
11892 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11894 -- First we need to extract the appropriate stack size
11896 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11898 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11900 Expr_N
: constant Node_Id
:=
11901 Expression
(First
(
11902 Pragma_Argument_Associations
(
11903 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11904 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11905 P
: constant Node_Id
:= Parent
(Expr_N
);
11908 -- The stack is defined inside the corresponding record.
11909 -- Therefore if the size of the stack is set by means of
11910 -- a discriminant, we must reference the discriminant of the
11911 -- corresponding record type.
11913 if Nkind
(Expr_N
) in N_Has_Entity
11914 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11918 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11920 Set_Parent
(Task_Size
, P
);
11921 Set_Etype
(Task_Size
, Etyp
);
11922 Set_Analyzed
(Task_Size
);
11925 Task_Size
:= New_Copy_Tree
(Expr_N
);
11931 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11934 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11935 Defining_Identifier
=> Ent_Stack
,
11937 Component_Definition
=>
11938 Make_Component_Definition
(Loc
,
11939 Aliased_Present
=> True,
11940 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11942 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11945 Make_Index_Or_Discriminant_Constraint
(Loc
,
11946 Constraints
=> New_List
(Make_Range
(Loc
,
11947 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11948 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11951 Append_To
(Cdecls
, Decl_Stack
);
11953 -- The appropriate alignment for the stack is ensured by the run-time
11954 -- code in charge of task creation.
11958 -- Declare a static secondary stack if the conditions for a statically
11959 -- generated stack are met.
11961 if Create_Secondary_Stack_For_Task
(TaskId
) then
11963 Size_Expr
: constant Node_Id
:=
11964 Expression
(First
(
11965 Pragma_Argument_Associations
(
11966 Get_Rep_Pragma
(TaskId
,
11967 Name_Secondary_Stack_Size
))));
11969 Stack_Size
: Node_Id
;
11972 -- The secondary stack is defined inside the corresponding
11973 -- record. Therefore if the size of the stack is set by means
11974 -- of a discriminant, we must reference the discriminant of the
11975 -- corresponding record type.
11977 if Nkind
(Size_Expr
) in N_Has_Entity
11978 and then Present
(Discriminal_Link
(Entity
(Size_Expr
)))
11982 (CR_Discriminant
(Discriminal_Link
(Entity
(Size_Expr
))),
11984 Set_Parent
(Stack_Size
, Parent
(Size_Expr
));
11985 Set_Etype
(Stack_Size
, Etype
(Size_Expr
));
11986 Set_Analyzed
(Stack_Size
);
11989 Stack_Size
:= New_Copy_Tree
(Size_Expr
);
11992 -- Create the secondary stack for the task
11995 Make_Component_Declaration
(Loc
,
11996 Defining_Identifier
=>
11997 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack
),
11998 Component_Definition
=>
11999 Make_Component_Definition
(Loc
,
12000 Aliased_Present
=> True,
12001 Subtype_Indication
=>
12002 Make_Subtype_Indication
(Loc
,
12004 New_Occurrence_Of
(RTE
(RE_SS_Stack
), Loc
),
12006 Make_Index_Or_Discriminant_Constraint
(Loc
,
12007 Constraints
=> New_List
(
12008 Convert_To
(RTE
(RE_Size_Type
),
12011 Append_To
(Cdecls
, Decl_SS
);
12015 -- Add components for entry families
12017 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
12019 -- Add the _Priority component if a Interrupt_Priority or Priority rep
12020 -- item is present.
12022 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
12024 Make_Component_Declaration
(Loc
,
12025 Defining_Identifier
=>
12026 Make_Defining_Identifier
(Loc
, Name_uPriority
),
12027 Component_Definition
=>
12028 Make_Component_Definition
(Loc
,
12029 Aliased_Present
=> False,
12030 Subtype_Indication
=>
12031 New_Occurrence_Of
(Standard_Integer
, Loc
))));
12034 -- Add the _Size component if a Storage_Size pragma is present
12036 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
12038 Make_Component_Declaration
(Loc
,
12039 Defining_Identifier
=>
12040 Make_Defining_Identifier
(Loc
, Name_uSize
),
12042 Component_Definition
=>
12043 Make_Component_Definition
(Loc
,
12044 Aliased_Present
=> False,
12045 Subtype_Indication
=>
12046 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
12049 Convert_To
(RTE
(RE_Size_Type
),
12051 Expression
(First
(
12052 Pragma_Argument_Associations
(
12053 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
12056 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
12057 -- pragma is present.
12060 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
12063 Make_Component_Declaration
(Loc
,
12064 Defining_Identifier
=>
12065 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack_Size
),
12067 Component_Definition
=>
12068 Make_Component_Definition
(Loc
,
12069 Aliased_Present
=> False,
12070 Subtype_Indication
=>
12071 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
))));
12074 -- Add the _Task_Info component if a Task_Info pragma is present
12076 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
12078 Make_Component_Declaration
(Loc
,
12079 Defining_Identifier
=>
12080 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
12082 Component_Definition
=>
12083 Make_Component_Definition
(Loc
,
12084 Aliased_Present
=> False,
12085 Subtype_Indication
=>
12086 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
12088 Expression
=> New_Copy
(
12089 Expression
(First
(
12090 Pragma_Argument_Associations
(
12092 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
12095 -- Add the _CPU component if a CPU rep item is present
12097 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
12099 Make_Component_Declaration
(Loc
,
12100 Defining_Identifier
=>
12101 Make_Defining_Identifier
(Loc
, Name_uCPU
),
12103 Component_Definition
=>
12104 Make_Component_Definition
(Loc
,
12105 Aliased_Present
=> False,
12106 Subtype_Indication
=>
12107 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
12110 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
12111 -- present. If we are using a restricted run time this component will
12112 -- not be added (deadlines are not allowed by the Ravenscar profile),
12113 -- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
12116 if (not Restricted_Profile
or else Task_Dispatching_Policy
= 'E')
12117 and then Present
(Taskdef
)
12118 and then Has_Relative_Deadline_Pragma
(Taskdef
)
12121 Make_Component_Declaration
(Loc
,
12122 Defining_Identifier
=>
12123 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
12125 Component_Definition
=>
12126 Make_Component_Definition
(Loc
,
12127 Aliased_Present
=> False,
12128 Subtype_Indication
=>
12129 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
12132 Convert_To
(RTE
(RE_Time_Span
),
12134 Expression
(First
(
12135 Pragma_Argument_Associations
(
12136 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12139 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12140 -- item is present. If we are using a restricted run time this component
12141 -- will not be added (dispatching domains are not allowed by the
12142 -- Ravenscar profile).
12144 if not Restricted_Profile
12147 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12150 Make_Component_Declaration
(Loc
,
12151 Defining_Identifier
=>
12152 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12154 Component_Definition
=>
12155 Make_Component_Definition
(Loc
,
12156 Aliased_Present
=> False,
12157 Subtype_Indication
=>
12159 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12162 Insert_After
(Size_Decl
, Rec_Decl
);
12164 -- Analyze the record declaration immediately after construction,
12165 -- because the initialization procedure is needed for single task
12166 -- declarations before the next entity is analyzed.
12168 Analyze
(Rec_Decl
);
12170 -- Create the declaration of the task body procedure
12172 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12174 Make_Subprogram_Declaration
(Loc
,
12175 Specification
=> Proc_Spec
);
12176 Set_Is_Task_Body_Procedure
(Body_Decl
);
12178 Insert_After
(Rec_Decl
, Body_Decl
);
12180 -- The subprogram does not comes from source, so we have to indicate the
12181 -- need for debugging information explicitly.
12183 if Comes_From_Source
(Original_Node
(N
)) then
12184 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12187 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12188 -- the corresponding record has been frozen.
12190 if Ada_Version
>= Ada_2005
then
12191 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12194 -- Ada 2005 (AI-345): We must defer freezing to allow further
12195 -- declaration of primitive subprograms covering task interfaces
12197 if Ada_Version
<= Ada_95
then
12199 -- Now we can freeze the corresponding record. This needs manually
12200 -- freezing, since it is really part of the task type, and the task
12201 -- type is frozen at this stage. We of course need the initialization
12202 -- procedure for this corresponding record type and we won't get it
12203 -- in time if we don't freeze now.
12205 Insert_List_After
(Body_Decl
, List
=> Freeze_Entity
(Rec_Ent
, N
));
12208 -- Complete the expansion of access types to the current task type, if
12209 -- any were declared.
12211 Expand_Previous_Access_Type
(Tasktyp
);
12213 -- Create wrappers for entries that have contract cases, preconditions
12214 -- and postconditions.
12220 Ent
:= First_Entity
(Tasktyp
);
12221 while Present
(Ent
) loop
12222 if Ekind
(Ent
) in E_Entry | E_Entry_Family
then
12223 Build_Entry_Contract_Wrapper
(Ent
, N
);
12229 end Expand_N_Task_Type_Declaration
;
12231 -------------------------------
12232 -- Expand_N_Timed_Entry_Call --
12233 -------------------------------
12235 -- A timed entry call in normal case is not implemented using ATC mechanism
12236 -- anymore for efficiency reason.
12246 -- is expanded as follows:
12248 -- 1) When T.E is a task entry_call;
12252 -- X : Task_Entry_Index := <entry index>;
12253 -- DX : Duration := To_Duration (D);
12254 -- M : Delay_Mode := <discriminant>;
12255 -- P : parms := (parm, parm, parm);
12258 -- Timed_Protected_Entry_Call
12259 -- (<acceptor-task>, X, P'Address, DX, M, B);
12267 -- 2) When T.E is a protected entry_call;
12271 -- X : Protected_Entry_Index := <entry index>;
12272 -- DX : Duration := To_Duration (D);
12273 -- M : Delay_Mode := <discriminant>;
12274 -- P : parms := (parm, parm, parm);
12277 -- Timed_Protected_Entry_Call
12278 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12286 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12287 -- is no delay and the triggering statements are executed. We first
12288 -- determine the kind of the triggering call and then execute a
12289 -- synchronized operation or a direct call.
12292 -- B : Boolean := False;
12293 -- C : Ada.Tags.Prim_Op_Kind;
12294 -- DX : Duration := To_Duration (D)
12295 -- K : Ada.Tags.Tagged_Kind :=
12296 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12297 -- M : Integer :=...;
12298 -- P : Parameters := (Param1 .. ParamN);
12302 -- if K = Ada.Tags.TK_Limited_Tagged
12303 -- or else K = Ada.Tags.TK_Tagged
12305 -- <dispatching-call>;
12310 -- Ada.Tags.Get_Offset_Index
12311 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12313 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12315 -- if C = POK_Protected_Entry
12316 -- or else C = POK_Task_Entry
12318 -- Param1 := P.Param1;
12320 -- ParamN := P.ParamN;
12324 -- if C = POK_Procedure
12325 -- or else C = POK_Protected_Procedure
12326 -- or else C = POK_Task_Procedure
12328 -- <dispatching-call>;
12334 -- <triggering-statements>
12336 -- <timed-statements>
12340 -- The triggering statement and the sequence of timed statements have not
12341 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12342 -- global references if within an instantiation.
12344 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12346 Blk_Typ
: Entity_Id
;
12348 Call_Ent
: Entity_Id
;
12349 Conc_Typ_Stmts
: List_Id
;
12350 Concval
: Node_Id
:= Empty
; -- init to avoid warning
12351 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12354 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12356 D_Type
: Entity_Id
;
12359 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12360 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12365 Is_Disp_Select
: Boolean;
12366 Lim_Typ_Stmts
: List_Id
;
12367 Loc
: constant Source_Ptr
:= Sloc
(D_Stat
);
12376 B
: Entity_Id
; -- Call status flag
12377 C
: Entity_Id
; -- Call kind
12378 D
: Entity_Id
; -- Delay
12379 K
: Entity_Id
; -- Tagged kind
12380 M
: Entity_Id
; -- Delay mode
12381 P
: Entity_Id
; -- Parameter block
12382 S
: Entity_Id
; -- Primitive operation slot
12384 -- Start of processing for Expand_N_Timed_Entry_Call
12387 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12388 -- was already reported on spec, so do not attempt to expand the call.
12390 if Restriction_Active
(No_Select_Statements
) then
12394 Process_Statements_For_Controlled_Objects
(E_Alt
);
12395 Process_Statements_For_Controlled_Objects
(D_Alt
);
12397 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12399 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12400 -- may wrap them in blocks.
12402 E_Stats
:= Statements
(E_Alt
);
12403 D_Stats
:= Statements
(D_Alt
);
12405 -- The arguments in the call may require dynamic allocation, and the
12406 -- call statement may have been transformed into a block. The block
12407 -- may contain additional declarations for internal entities, and the
12408 -- original call is found by sequential search.
12410 if Nkind
(E_Call
) = N_Block_Statement
then
12411 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12412 while Nkind
(E_Call
) not in
12413 N_Procedure_Call_Statement | N_Entry_Call_Statement
12420 Ada_Version
>= Ada_2005
12421 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12423 if Is_Disp_Select
then
12424 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12430 -- B : Boolean := False;
12432 B
:= Build_B
(Loc
, Decls
);
12435 -- C : Ada.Tags.Prim_Op_Kind;
12437 C
:= Build_C
(Loc
, Decls
);
12439 -- Because the analysis of all statements was disabled, manually
12440 -- analyze the delay statement.
12443 D_Stat
:= Original_Node
(D_Stat
);
12446 -- Build an entry call using Simple_Entry_Call
12448 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12449 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12451 Decls
:= Declarations
(E_Call
);
12452 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12461 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12464 Make_Object_Declaration
(Loc
,
12465 Defining_Identifier
=> B
,
12466 Object_Definition
=>
12467 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12470 -- Duration and mode processing
12472 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12474 -- Use the type of the delay expression (Calendar or Real_Time) to
12475 -- generate the appropriate conversion.
12477 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12478 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12479 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12481 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12482 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12484 Make_Function_Call
(Loc
,
12485 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12486 Parameter_Associations
=>
12487 New_List
(New_Copy
(Expression
(D_Stat
))));
12489 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12490 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12492 Make_Function_Call
(Loc
,
12493 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12494 Parameter_Associations
=>
12495 New_List
(New_Copy
(Expression
(D_Stat
))));
12498 D
:= Make_Temporary
(Loc
, 'D');
12504 Make_Object_Declaration
(Loc
,
12505 Defining_Identifier
=> D
,
12506 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12508 M
:= Make_Temporary
(Loc
, 'M');
12511 -- M : Integer := (0 | 1 | 2);
12514 Make_Object_Declaration
(Loc
,
12515 Defining_Identifier
=> M
,
12516 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12517 Expression
=> D_Disc
));
12519 -- Parameter block processing
12521 -- Manually create the parameter block for dispatching calls. In the
12522 -- case of entries, the block has already been created during the call
12523 -- to Build_Simple_Entry_Call.
12525 if Is_Disp_Select
then
12527 -- Compute the delay at this stage because the evaluation of its
12528 -- expression must not occur earlier (see ACVC C97302A).
12531 Make_Assignment_Statement
(Loc
,
12532 Name
=> New_Occurrence_Of
(D
, Loc
),
12533 Expression
=> D_Conv
));
12535 -- Tagged kind processing, generate:
12536 -- K : Ada.Tags.Tagged_Kind :=
12537 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12539 K
:= Build_K
(Loc
, Decls
, Obj
);
12541 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12543 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12545 -- Dispatch table slot processing, generate:
12548 S
:= Build_S
(Loc
, Decls
);
12551 -- S := Ada.Tags.Get_Offset_Index
12552 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12555 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12558 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12560 -- where Obj is the controlling formal parameter, S is the dispatch
12561 -- table slot number of the dispatching operation, P is the wrapped
12562 -- parameter block, D is the duration, M is the duration mode, C is
12563 -- the call kind and B is the call status.
12565 Params
:= New_List
;
12567 Append_To
(Params
, New_Copy_Tree
(Obj
));
12568 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12570 Make_Attribute_Reference
(Loc
,
12571 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12572 Attribute_Name
=> Name_Address
));
12573 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12574 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12575 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12576 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12578 Append_To
(Conc_Typ_Stmts
,
12579 Make_Procedure_Call_Statement
(Loc
,
12583 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12584 Parameter_Associations
=> Params
));
12587 -- if C = POK_Protected_Entry
12588 -- or else C = POK_Task_Entry
12590 -- Param1 := P.Param1;
12592 -- ParamN := P.ParamN;
12595 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12597 -- Generate the if statement only when the packed parameters need
12598 -- explicit assignments to their corresponding actuals.
12600 if Present
(Unpack
) then
12601 Append_To
(Conc_Typ_Stmts
,
12602 Make_Implicit_If_Statement
(N
,
12608 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12611 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12615 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12617 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12619 Then_Statements
=> Unpack
));
12625 -- if C = POK_Procedure
12626 -- or else C = POK_Protected_Procedure
12627 -- or else C = POK_Task_Procedure
12629 -- <dispatching-call>
12633 N_Stats
:= New_List
(
12634 Make_Implicit_If_Statement
(N
,
12639 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12641 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12647 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12649 New_Occurrence_Of
(RTE
(
12650 RE_POK_Protected_Procedure
), Loc
)),
12653 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12656 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12658 Then_Statements
=> New_List
(E_Call
)));
12660 Append_To
(Conc_Typ_Stmts
,
12661 Make_Implicit_If_Statement
(N
,
12662 Condition
=> New_Occurrence_Of
(B
, Loc
),
12663 Then_Statements
=> N_Stats
));
12666 -- <dispatching-call>;
12670 New_List
(New_Copy_Tree
(E_Call
),
12671 Make_Assignment_Statement
(Loc
,
12672 Name
=> New_Occurrence_Of
(B
, Loc
),
12673 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12676 -- if K = Ada.Tags.TK_Limited_Tagged
12677 -- or else K = Ada.Tags.TK_Tagged
12685 Make_Implicit_If_Statement
(N
,
12686 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12687 Then_Statements
=> Lim_Typ_Stmts
,
12688 Else_Statements
=> Conc_Typ_Stmts
));
12693 -- <triggering-statements>
12695 -- <timed-statements>
12699 Make_Implicit_If_Statement
(N
,
12700 Condition
=> New_Occurrence_Of
(B
, Loc
),
12701 Then_Statements
=> E_Stats
,
12702 Else_Statements
=> D_Stats
));
12705 -- Simple case of a nondispatching trigger. Skip assignments to
12706 -- temporaries created for in-out parameters.
12708 -- This makes unwarranted assumptions about the shape of the expanded
12709 -- tree for the call, and should be cleaned up ???
12711 Stmt
:= First
(Stmts
);
12712 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12716 -- Compute the delay at this stage because the evaluation of
12717 -- its expression must not occur earlier (see ACVC C97302A).
12719 Insert_Before
(Stmt
,
12720 Make_Assignment_Statement
(Loc
,
12721 Name
=> New_Occurrence_Of
(D
, Loc
),
12722 Expression
=> D_Conv
));
12725 Params
:= Parameter_Associations
(Call
);
12727 -- For a protected type, we build a Timed_Protected_Entry_Call
12729 if Is_Protected_Type
(Etype
(Concval
)) then
12731 -- Create a new call statement
12733 Param
:= First
(Params
);
12734 while Present
(Param
)
12735 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12740 Dummy
:= Remove_Next
(Next
(Param
));
12742 -- Remove garbage is following the Cancel_Param if present
12744 Dummy
:= Next
(Param
);
12746 -- Remove the mode of the Protected_Entry_Call call, then remove
12747 -- the Communication_Block of the Protected_Entry_Call call, and
12748 -- finally add Duration and a Delay_Mode parameter
12750 pragma Assert
(Present
(Param
));
12751 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12753 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12755 -- Add a Boolean flag for successful entry call
12757 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12759 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12760 when System_Tasking_Protected_Objects_Entries
=>
12762 Make_Procedure_Call_Statement
(Loc
,
12765 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12766 Parameter_Associations
=> Params
));
12769 raise Program_Error
;
12772 -- For the task case, build a Timed_Task_Entry_Call
12775 -- Create a new call statement
12777 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12778 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12779 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12782 Make_Procedure_Call_Statement
(Loc
,
12784 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12785 Parameter_Associations
=> Params
));
12789 Make_Implicit_If_Statement
(N
,
12790 Condition
=> New_Occurrence_Of
(B
, Loc
),
12791 Then_Statements
=> E_Stats
,
12792 Else_Statements
=> D_Stats
));
12796 Make_Block_Statement
(Loc
,
12797 Declarations
=> Decls
,
12798 Handled_Statement_Sequence
=>
12799 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12803 -- Some items in Decls used to be in the N_Block in E_Call that is
12804 -- constructed in Expand_Entry_Call, and are now in the new Block
12805 -- into which N has been rewritten. Adjust their scopes to reflect that.
12807 if Nkind
(E_Call
) = N_Block_Statement
then
12808 Obj
:= First_Entity
(Entity
(Identifier
(E_Call
)));
12809 while Present
(Obj
) loop
12810 Set_Scope
(Obj
, Entity
(Identifier
(N
)));
12815 Reset_Scopes_To
(N
, Entity
(Identifier
(N
)));
12816 end Expand_N_Timed_Entry_Call
;
12818 ----------------------------------------
12819 -- Expand_Protected_Body_Declarations --
12820 ----------------------------------------
12822 procedure Expand_Protected_Body_Declarations
12824 Spec_Id
: Entity_Id
)
12827 if No_Run_Time_Mode
then
12828 Error_Msg_CRT
("protected body", N
);
12831 elsif Expander_Active
then
12833 -- Associate discriminals with the first subprogram or entry body to
12836 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12837 Set_Discriminals
(Parent
(Spec_Id
));
12840 end Expand_Protected_Body_Declarations
;
12842 -------------------------
12843 -- External_Subprogram --
12844 -------------------------
12846 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12847 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12850 -- The internal and external subprograms follow each other on the entity
12851 -- chain. Note that previously private operations had no separate
12852 -- external subprogram. We now create one in all cases, because a
12853 -- private operation may actually appear in an external call, through
12854 -- a 'Access reference used for a callback.
12856 -- If the operation is a function that returns an anonymous access type,
12857 -- the corresponding itype appears before the operation, and must be
12860 -- This mechanism is fragile, there should be a real link between the
12861 -- two versions of the operation, but there is no place to put it ???
12863 if Is_Access_Type
(Next_Entity
(Subp
)) then
12864 return Next_Entity
(Next_Entity
(Subp
));
12866 return Next_Entity
(Subp
);
12868 end External_Subprogram
;
12870 ------------------------------
12871 -- Extract_Dispatching_Call --
12872 ------------------------------
12874 procedure Extract_Dispatching_Call
12876 Call_Ent
: out Entity_Id
;
12877 Object
: out Entity_Id
;
12878 Actuals
: out List_Id
;
12879 Formals
: out List_Id
)
12881 Call_Nam
: Node_Id
;
12884 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12886 if Present
(Original_Node
(N
)) then
12887 Call_Nam
:= Name
(Original_Node
(N
));
12889 Call_Nam
:= Name
(N
);
12892 -- Retrieve the name of the dispatching procedure. It contains the
12893 -- dispatch table slot number.
12896 case Nkind
(Call_Nam
) is
12897 when N_Identifier
=>
12900 when N_Selected_Component
=>
12901 Call_Nam
:= Selector_Name
(Call_Nam
);
12904 raise Program_Error
;
12908 Actuals
:= Parameter_Associations
(N
);
12909 Call_Ent
:= Entity
(Call_Nam
);
12910 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12911 Object
:= First
(Actuals
);
12913 if Present
(Original_Node
(Object
)) then
12914 Object
:= Original_Node
(Object
);
12917 -- If the type of the dispatching object is an access type then return
12918 -- an explicit dereference of a copy of the object, and note that this
12919 -- is the controlling actual of the call.
12921 if Is_Access_Type
(Etype
(Object
)) then
12923 Make_Explicit_Dereference
(Sloc
(N
), New_Copy_Tree
(Object
));
12925 Set_Is_Controlling_Actual
(Object
);
12927 end Extract_Dispatching_Call
;
12929 -------------------
12930 -- Extract_Entry --
12931 -------------------
12933 procedure Extract_Entry
12935 Concval
: out Node_Id
;
12936 Ename
: out Node_Id
;
12937 Index
: out Node_Id
)
12939 Nam
: constant Node_Id
:= Name
(N
);
12942 -- For a simple entry, the name is a selected component, with the
12943 -- prefix being the task value, and the selector being the entry.
12945 if Nkind
(Nam
) = N_Selected_Component
then
12946 Concval
:= Prefix
(Nam
);
12947 Ename
:= Selector_Name
(Nam
);
12950 -- For a member of an entry family, the name is an indexed component
12951 -- where the prefix is a selected component, whose prefix in turn is
12952 -- the task value, and whose selector is the entry family. The single
12953 -- expression in the expressions list of the indexed component is the
12954 -- subscript for the family.
12956 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12957 Concval
:= Prefix
(Prefix
(Nam
));
12958 Ename
:= Selector_Name
(Prefix
(Nam
));
12959 Index
:= First
(Expressions
(Nam
));
12962 -- Through indirection, the type may actually be a limited view of a
12963 -- concurrent type. When compiling a call, the non-limited view of the
12964 -- type is visible.
12966 if From_Limited_With
(Etype
(Concval
)) then
12967 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12971 -------------------
12972 -- Family_Offset --
12973 -------------------
12975 function Family_Offset
12980 Cap
: Boolean) return Node_Id
12986 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12987 -- If one of the bounds is a reference to a discriminant, replace with
12988 -- corresponding discriminal of type. Within the body of a task retrieve
12989 -- the renamed discriminant by simple visibility, using its generated
12990 -- name. Within a protected object, find the original discriminant and
12991 -- replace it with the discriminal of the current protected operation.
12993 ------------------------------
12994 -- Convert_Discriminant_Ref --
12995 ------------------------------
12997 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12998 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
13003 if Is_Entity_Name
(Bound
)
13004 and then Ekind
(Entity
(Bound
)) = E_Discriminant
13006 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
13007 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13008 Find_Direct_Name
(B
);
13010 elsif Is_Protected_Type
(Ttyp
) then
13011 D
:= First_Discriminant
(Ttyp
);
13012 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
13013 Next_Discriminant
(D
);
13016 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
13019 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
13022 elsif Nkind
(Bound
) = N_Attribute_Reference
then
13026 B
:= New_Copy_Tree
(Bound
);
13030 Make_Attribute_Reference
(Loc
,
13031 Attribute_Name
=> Name_Pos
,
13032 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
13033 Expressions
=> New_List
(B
));
13034 end Convert_Discriminant_Ref
;
13036 -- Start of processing for Family_Offset
13039 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
13040 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
13043 if Is_Task_Type
(Ttyp
) then
13044 Ityp
:= RTE
(RE_Task_Entry_Index
);
13046 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13050 Make_Attribute_Reference
(Loc
,
13051 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13052 Attribute_Name
=> Name_Min
,
13053 Expressions
=> New_List
(
13055 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
13058 Make_Attribute_Reference
(Loc
,
13059 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13060 Attribute_Name
=> Name_Max
,
13061 Expressions
=> New_List
(
13063 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
13066 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
13073 function Family_Size
13078 Cap
: Boolean) return Node_Id
13083 if Is_Task_Type
(Ttyp
) then
13084 Ityp
:= RTE
(RE_Task_Entry_Index
);
13086 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13090 Make_Attribute_Reference
(Loc
,
13091 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13092 Attribute_Name
=> Name_Max
,
13093 Expressions
=> New_List
(
13095 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
13096 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
13097 Make_Integer_Literal
(Loc
, 0)));
13100 ----------------------------
13101 -- Find_Enclosing_Context --
13102 ----------------------------
13104 procedure Find_Enclosing_Context
13106 Context
: out Node_Id
;
13107 Context_Id
: out Entity_Id
;
13108 Context_Decls
: out List_Id
)
13111 -- Traverse the parent chain looking for an enclosing body, block,
13112 -- package or return statement.
13114 Context
:= Parent
(N
);
13115 while Present
(Context
) loop
13116 if Nkind
(Context
) in N_Entry_Body
13117 | N_Extended_Return_Statement
13119 | N_Package_Declaration
13120 | N_Subprogram_Body
13125 -- Do not consider block created to protect a list of statements with
13126 -- an Abort_Defer / Abort_Undefer_Direct pair.
13128 elsif Nkind
(Context
) = N_Block_Statement
13129 and then not Is_Abort_Block
(Context
)
13134 Context
:= Parent
(Context
);
13137 pragma Assert
(Present
(Context
));
13139 -- Extract the constituents of the context
13141 if Nkind
(Context
) = N_Extended_Return_Statement
then
13142 Context_Decls
:= Return_Object_Declarations
(Context
);
13143 Context_Id
:= Return_Statement_Entity
(Context
);
13145 -- Package declarations and bodies use a common library-level activation
13146 -- chain or task master, therefore return the package declaration as the
13147 -- proper carrier for the appropriate flag.
13149 elsif Nkind
(Context
) = N_Package_Body
then
13150 Context_Decls
:= Declarations
(Context
);
13151 Context_Id
:= Corresponding_Spec
(Context
);
13152 Context
:= Parent
(Context_Id
);
13154 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13155 Context
:= Parent
(Parent
(Context
));
13157 Context
:= Parent
(Context
);
13160 elsif Nkind
(Context
) = N_Package_Declaration
then
13161 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13162 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13164 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13165 Context_Id
:= Defining_Identifier
(Context_Id
);
13169 if Nkind
(Context
) = N_Block_Statement
then
13170 Context_Id
:= Entity
(Identifier
(Context
));
13172 if No
(Declarations
(Context
)) then
13173 Set_Declarations
(Context
, New_List
);
13176 elsif Nkind
(Context
) = N_Entry_Body
then
13177 Context_Id
:= Defining_Identifier
(Context
);
13179 elsif Nkind
(Context
) = N_Subprogram_Body
then
13180 if Present
(Corresponding_Spec
(Context
)) then
13181 Context_Id
:= Corresponding_Spec
(Context
);
13183 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13185 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13186 Context_Id
:= Defining_Identifier
(Context_Id
);
13190 elsif Nkind
(Context
) = N_Task_Body
then
13191 Context_Id
:= Corresponding_Spec
(Context
);
13194 raise Program_Error
;
13197 Context_Decls
:= Declarations
(Context
);
13200 pragma Assert
(Present
(Context_Id
));
13201 pragma Assert
(Present
(Context_Decls
));
13202 end Find_Enclosing_Context
;
13204 -----------------------
13205 -- Find_Master_Scope --
13206 -----------------------
13208 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13212 -- In Ada 2005, the master is the innermost enclosing scope that is not
13213 -- transient. If the enclosing block is the rewriting of a call or the
13214 -- scope is an extended return statement this is valid master. The
13215 -- master in an extended return is only used within the return, and is
13216 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13217 -- now before that overwriting occurs.
13221 if Ada_Version
>= Ada_2005
then
13222 while Is_Internal
(S
) loop
13223 if Nkind
(Parent
(S
)) = N_Block_Statement
13224 and then Has_Master_Entity
(S
)
13228 elsif Ekind
(S
) = E_Return_Statement
then
13238 end Find_Master_Scope
;
13240 -------------------------------
13241 -- First_Protected_Operation --
13242 -------------------------------
13244 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13245 First_Op
: Node_Id
;
13248 First_Op
:= First
(D
);
13249 while Present
(First_Op
)
13250 and then Nkind
(First_Op
) not in N_Subprogram_Body | N_Entry_Body
13256 end First_Protected_Operation
;
13258 ---------------------------------------
13259 -- Install_Private_Data_Declarations --
13260 ---------------------------------------
13262 procedure Install_Private_Data_Declarations
13264 Spec_Id
: Entity_Id
;
13265 Conc_Typ
: Entity_Id
;
13266 Body_Nod
: Node_Id
;
13268 Barrier
: Boolean := False;
13269 Family
: Boolean := False)
13271 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13274 Insert_Node
: Node_Id
:= Empty
;
13275 Obj_Ent
: Entity_Id
;
13277 procedure Add
(Decl
: Node_Id
);
13278 -- Add a single declaration after Insert_Node. If this is the first
13279 -- addition, Decl is added to the front of Decls and it becomes the
13282 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13283 -- The bounds of an entry index may depend on discriminants, create a
13284 -- reference to the corresponding prival. Otherwise return a duplicate
13285 -- of the original bound.
13291 procedure Add
(Decl
: Node_Id
) is
13293 if No
(Insert_Node
) then
13294 Prepend_To
(Decls
, Decl
);
13296 Insert_After
(Insert_Node
, Decl
);
13299 Insert_Node
:= Decl
;
13302 -------------------
13303 -- Replace_Bound --
13304 -------------------
13306 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13308 if Nkind
(Bound
) = N_Identifier
13309 and then Is_Discriminal
(Entity
(Bound
))
13311 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13313 return Duplicate_Subexpr
(Bound
);
13317 -- Start of processing for Install_Private_Data_Declarations
13320 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13321 -- formal parameter _O, _object or _task depending on the context.
13323 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13325 -- Special processing of _O for barrier functions, protected entries
13332 (Ekind
(Spec_Id
) = E_Entry
13333 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13336 Conc_Rec
: constant Entity_Id
:=
13337 Corresponding_Record_Type
(Conc_Typ
);
13338 Typ_Id
: constant Entity_Id
:=
13339 Make_Defining_Identifier
(Loc
,
13340 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13343 -- type prot_typVP is access prot_typV;
13346 Make_Full_Type_Declaration
(Loc
,
13347 Defining_Identifier
=> Typ_Id
,
13349 Make_Access_To_Object_Definition
(Loc
,
13350 Subtype_Indication
=>
13351 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13355 -- _object : prot_typVP := prot_typV (_O);
13358 Make_Object_Declaration
(Loc
,
13359 Defining_Identifier
=>
13360 Make_Defining_Identifier
(Loc
, Name_uObject
),
13361 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13363 Unchecked_Convert_To
(Typ_Id
,
13364 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13367 -- Set the reference to the concurrent object
13369 Obj_Ent
:= Defining_Identifier
(Decl
);
13373 -- Step 2: Create the Protection object and build its declaration for
13374 -- any protected entry (family) of subprogram. Note for the lock-free
13375 -- implementation, the Protection object is not needed anymore.
13377 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13379 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13383 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13385 -- Determine the proper protection type
13387 if Has_Attach_Handler
(Conc_Typ
)
13388 and then not Restricted_Profile
13390 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13392 elsif Has_Interrupt_Handler
(Conc_Typ
)
13393 and then not Restriction_Active
(No_Dynamic_Attachment
)
13395 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13398 case Corresponding_Runtime_Package
(Conc_Typ
) is
13399 when System_Tasking_Protected_Objects_Entries
=>
13400 Prot_Typ
:= RE_Protection_Entries
;
13402 when System_Tasking_Protected_Objects_Single_Entry
=>
13403 Prot_Typ
:= RE_Protection_Entry
;
13405 when System_Tasking_Protected_Objects
=>
13406 Prot_Typ
:= RE_Protection
;
13409 raise Program_Error
;
13414 -- conc_typR : protection_typ renames _object._object;
13417 Make_Object_Renaming_Declaration
(Loc
,
13418 Defining_Identifier
=> Prot_Ent
,
13420 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13422 Make_Selected_Component
(Loc
,
13423 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13424 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13430 -- Step 3: Add discriminant renamings (if any)
13432 if Has_Discriminants
(Conc_Typ
) then
13437 D
:= First_Discriminant
(Conc_Typ
);
13438 while Present
(D
) loop
13440 -- Adjust the source location
13442 Set_Sloc
(Discriminal
(D
), Loc
);
13445 -- discr_name : discr_typ renames _object.discr_name;
13447 -- discr_name : discr_typ renames _task.discr_name;
13450 Make_Object_Renaming_Declaration
(Loc
,
13451 Defining_Identifier
=> Discriminal
(D
),
13452 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13454 Make_Selected_Component
(Loc
,
13455 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13456 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13460 -- Set debug info needed on this renaming declaration even
13461 -- though it does not come from source, so that the debugger
13462 -- will get the right information for these generated names.
13464 Set_Debug_Info_Needed
(Discriminal
(D
));
13466 Next_Discriminant
(D
);
13471 -- Step 4: Add private component renamings (if any)
13473 if Is_Protected
then
13474 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13476 if Present
(Private_Declarations
(Def
)) then
13479 Comp_Id
: Entity_Id
;
13480 Decl_Id
: Entity_Id
;
13484 Comp
:= First
(Private_Declarations
(Def
));
13485 while Present
(Comp
) loop
13486 if Nkind
(Comp
) = N_Component_Declaration
then
13487 Comp_Id
:= Defining_Identifier
(Comp
);
13488 Nam
:= Chars
(Comp_Id
);
13489 Decl_Id
:= Make_Defining_Identifier
(Sloc
(Comp_Id
), Nam
);
13491 -- Minimal decoration
13493 if Ekind
(Spec_Id
) = E_Function
then
13494 Mutate_Ekind
(Decl_Id
, E_Constant
);
13496 Mutate_Ekind
(Decl_Id
, E_Variable
);
13499 Set_Prival
(Comp_Id
, Decl_Id
);
13500 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13501 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13502 Set_Is_Independent
(Decl_Id
, Is_Independent
(Comp_Id
));
13504 -- Copy the Comes_From_Source flag of the component, as
13505 -- the renaming may be the only entity directly seen by
13506 -- the user in the context, but do not warn for it.
13508 Set_Comes_From_Source
13509 (Decl_Id
, Comes_From_Source
(Comp_Id
));
13510 Set_Warnings_Off
(Decl_Id
);
13513 -- comp_name : comp_typ renames _object.comp_name;
13516 Make_Object_Renaming_Declaration
(Loc
,
13517 Defining_Identifier
=> Decl_Id
,
13519 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13521 Make_Selected_Component
(Loc
,
13522 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13523 Selector_Name
=> Make_Identifier
(Loc
, Nam
)));
13534 -- Step 5: Add the declaration of the entry index and the associated
13535 -- type for barrier functions and entry families.
13537 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13539 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13540 Index
: constant Entity_Id
:=
13541 Defining_Identifier
13542 (Entry_Index_Specification
13543 (Entry_Body_Formal_Part
(Body_Nod
)));
13544 Index_Con
: constant Entity_Id
:=
13545 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13547 Index_Typ
: Entity_Id
;
13551 -- Minimal decoration
13553 Mutate_Ekind
(Index_Con
, E_Constant
);
13554 Set_Entry_Index_Constant
(Index
, Index_Con
);
13555 Set_Discriminal_Link
(Index_Con
, Index
);
13557 -- Retrieve the bounds of the entry family
13559 High
:= Type_High_Bound
(Etype
(Index
));
13560 Low
:= Type_Low_Bound
(Etype
(Index
));
13562 -- In the simple case the entry family is given by a subtype mark
13563 -- and the index constant has the same type.
13565 if Is_Entity_Name
(Original_Node
(
13566 Discrete_Subtype_Definition
(Parent
(Index
))))
13568 Index_Typ
:= Etype
(Index
);
13570 -- Otherwise a new subtype declaration is required
13573 High
:= Replace_Bound
(High
);
13574 Low
:= Replace_Bound
(Low
);
13576 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13579 -- subtype Jnn is <Etype of Index> range Low .. High;
13582 Make_Subtype_Declaration
(Loc
,
13583 Defining_Identifier
=> Index_Typ
,
13584 Subtype_Indication
=>
13585 Make_Subtype_Indication
(Loc
,
13587 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13589 Make_Range_Constraint
(Loc
,
13590 Range_Expression
=>
13591 Make_Range
(Loc
, Low
, High
))));
13595 Set_Etype
(Index_Con
, Index_Typ
);
13597 -- Create the object which designates the index:
13598 -- J : constant Jnn :=
13599 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13601 -- where Jnn is the subtype created above or the original type of
13602 -- the index, _E is a formal of the protected body subprogram and
13603 -- <index expr> is the index of the first family member.
13606 Make_Object_Declaration
(Loc
,
13607 Defining_Identifier
=> Index_Con
,
13608 Constant_Present
=> True,
13609 Object_Definition
=>
13610 New_Occurrence_Of
(Index_Typ
, Loc
),
13613 Make_Attribute_Reference
(Loc
,
13615 New_Occurrence_Of
(Index_Typ
, Loc
),
13616 Attribute_Name
=> Name_Val
,
13618 Expressions
=> New_List
(
13622 Make_Op_Subtract
(Loc
,
13623 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13625 Entry_Index_Expression
(Loc
,
13626 Defining_Identifier
(Body_Nod
),
13630 Make_Attribute_Reference
(Loc
,
13632 New_Occurrence_Of
(Index_Typ
, Loc
),
13633 Attribute_Name
=> Name_Pos
,
13634 Expressions
=> New_List
(
13635 Make_Attribute_Reference
(Loc
,
13637 New_Occurrence_Of
(Index_Typ
, Loc
),
13638 Attribute_Name
=> Name_First
)))))));
13642 end Install_Private_Data_Declarations
;
13644 ---------------------------------
13645 -- Is_Potentially_Large_Family --
13646 ---------------------------------
13648 function Is_Potentially_Large_Family
13649 (Base_Index
: Entity_Id
;
13650 Conctyp
: Entity_Id
;
13652 Hi
: Node_Id
) return Boolean
13655 return Scope
(Base_Index
) = Standard_Standard
13656 and then Base_Index
= Base_Type
(Standard_Integer
)
13657 and then Has_Defaulted_Discriminants
(Conctyp
)
13659 (Denotes_Discriminant
(Lo
, True)
13661 Denotes_Discriminant
(Hi
, True));
13662 end Is_Potentially_Large_Family
;
13664 -------------------------------------
13665 -- Is_Private_Primitive_Subprogram --
13666 -------------------------------------
13668 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13671 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13672 and then Is_Private_Primitive
(Id
);
13673 end Is_Private_Primitive_Subprogram
;
13679 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13680 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13681 Formal
: Entity_Id
;
13684 Formal
:= First_Formal
(Bod_Subp
);
13685 while Present
(Formal
) loop
13687 -- Look for formal parameter _E
13689 if Chars
(Formal
) = Name_uE
then
13693 Next_Formal
(Formal
);
13696 -- A protected body subprogram should always have the parameter in
13699 raise Program_Error
;
13702 --------------------------------
13703 -- Make_Initialize_Protection --
13704 --------------------------------
13706 function Make_Initialize_Protection
13707 (Protect_Rec
: Entity_Id
) return List_Id
13709 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13712 Ptyp
: constant Node_Id
:=
13713 Corresponding_Concurrent_Type
(Protect_Rec
);
13715 L
: constant List_Id
:= New_List
;
13716 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13717 Prio_Type
: Entity_Id
;
13718 Prio_Var
: Entity_Id
:= Empty
;
13719 Restricted
: constant Boolean := Restricted_Profile
;
13722 -- We may need two calls to properly initialize the object, one to
13723 -- Initialize_Protection, and possibly one to Install_Handlers if we
13724 -- have a pragma Attach_Handler.
13726 -- Get protected declaration. In the case of a task type declaration,
13727 -- this is simply the parent of the protected type entity. In the single
13728 -- protected object declaration, this parent will be the implicit type,
13729 -- and we can find the corresponding single protected object declaration
13730 -- by searching forward in the declaration list in the tree.
13732 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13733 -- of this type should have been removed during semantic analysis.
13735 Pdec
:= Parent
(Ptyp
);
13736 while Nkind
(Pdec
) not in
13737 N_Protected_Type_Declaration | N_Single_Protected_Declaration
13742 -- Build the parameter list for the call. Note that _Init is the name
13743 -- of the formal for the object to be initialized, which is the task
13744 -- value record itself.
13748 -- For lock-free implementation, skip initializations of the Protection
13751 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13753 -- Object parameter. This is a pointer to the object of type
13754 -- Protection used by the GNARL to control the protected object.
13757 Make_Attribute_Reference
(Loc
,
13759 Make_Selected_Component
(Loc
,
13760 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13761 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13762 Attribute_Name
=> Name_Unchecked_Access
));
13764 -- Priority parameter. Set to Unspecified_Priority unless there is a
13765 -- Priority rep item, in which case we take the value from the pragma
13766 -- or attribute definition clause, or there is an Interrupt_Priority
13767 -- rep item and no Priority rep item, and we set the ceiling to
13768 -- Interrupt_Priority'Last, an implementation-defined value, see
13771 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13773 Prio_Clause
: constant Node_Id
:=
13775 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13782 if Nkind
(Prio_Clause
) = N_Pragma
then
13785 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13787 -- Get_Rep_Item returns either priority pragma
13789 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13790 Prio_Type
:= RTE
(RE_Any_Priority
);
13792 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13795 -- Attribute definition clause Priority
13798 if Chars
(Prio_Clause
) = Name_Priority
then
13799 Prio_Type
:= RTE
(RE_Any_Priority
);
13801 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13804 Prio
:= Expression
(Prio_Clause
);
13807 -- Always create a locale variable to capture the priority.
13808 -- The priority is also passed to Install_Restriced_Handlers.
13809 -- Note that it is really necessary to create this variable
13810 -- explicitly. It might be thought that removing side effects
13811 -- would the appropriate approach, but that could generate
13812 -- declarations improperly placed in the enclosing scope.
13814 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13816 Make_Object_Declaration
(Loc
,
13817 Defining_Identifier
=> Prio_Var
,
13818 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13819 Expression
=> Relocate_Node
(Prio
)));
13821 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13824 -- When no priority is specified but an xx_Handler pragma is, we
13825 -- default to System.Interrupts.Default_Interrupt_Priority, see
13828 elsif Has_Attach_Handler
(Ptyp
)
13829 or else Has_Interrupt_Handler
(Ptyp
)
13832 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13834 -- Normal case, no priority or xx_Handler specified, default priority
13838 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13841 -- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
13843 if Restricted_Profile
and Task_Dispatching_Policy
= 'E' then
13844 Deadline_Floor
: declare
13845 Item
: constant Node_Id
:=
13847 (Ptyp
, Name_Deadline_Floor
, Check_Parents
=> False);
13849 Deadline
: Node_Id
;
13852 if Present
(Item
) then
13854 -- Pragma Deadline_Floor
13856 if Nkind
(Item
) = N_Pragma
then
13859 (First
(Pragma_Argument_Associations
(Item
)));
13861 -- Attribute definition clause Deadline_Floor
13865 (Nkind
(Item
) = N_Attribute_Definition_Clause
);
13867 Deadline
:= Expression
(Item
);
13870 Append_To
(Args
, Deadline
);
13872 -- Unusual case: default deadline
13876 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
13878 end Deadline_Floor
;
13881 -- Test for Compiler_Info parameter. This parameter allows entry body
13882 -- procedures and barrier functions to be called from the runtime. It
13883 -- is a pointer to the record generated by the compiler to represent
13884 -- the protected object.
13886 -- A protected type without entries that covers an interface and
13887 -- overrides the abstract routines with protected procedures is
13888 -- considered equivalent to a protected type with entries in the
13889 -- context of dispatching select statements.
13891 -- Protected types with interrupt handlers (when not using a
13892 -- restricted profile) are also considered equivalent to protected
13893 -- types with entries.
13895 -- The types which are used (Static_Interrupt_Protection and
13896 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13899 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13901 Called_Subp
: RE_Id
;
13905 when System_Tasking_Protected_Objects_Entries
=>
13906 Called_Subp
:= RE_Initialize_Protection_Entries
;
13908 -- Argument Compiler_Info
13911 Make_Attribute_Reference
(Loc
,
13912 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13913 Attribute_Name
=> Name_Address
));
13915 when System_Tasking_Protected_Objects_Single_Entry
=>
13916 Called_Subp
:= RE_Initialize_Protection_Entry
;
13918 -- Argument Compiler_Info
13921 Make_Attribute_Reference
(Loc
,
13922 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13923 Attribute_Name
=> Name_Address
));
13925 when System_Tasking_Protected_Objects
=>
13926 Called_Subp
:= RE_Initialize_Protection
;
13929 raise Program_Error
;
13932 -- Entry_Queue_Maxes parameter. This is an access to an array of
13933 -- naturals representing the entry queue maximums for each entry
13934 -- in the protected type. Zero represents no max. The access is
13935 -- null if there is no limit for all entries (usual case).
13938 and then Pkg_Id
= System_Tasking_Protected_Objects_Entries
13940 if Present
(Entry_Max_Queue_Lengths_Array
(Ptyp
)) then
13942 Make_Attribute_Reference
(Loc
,
13945 (Entry_Max_Queue_Lengths_Array
(Ptyp
), Loc
),
13946 Attribute_Name
=> Name_Unrestricted_Access
));
13948 Append_To
(Args
, Make_Null
(Loc
));
13951 -- Edge cases exist where entry initialization functions are
13952 -- called, but no entries exist, so null is appended.
13954 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13955 Append_To
(Args
, Make_Null
(Loc
));
13958 -- Entry_Bodies parameter. This is a pointer to an array of
13959 -- pointers to the entry body procedures and barrier functions of
13960 -- the object. If the protected type has no entries this object
13961 -- will not exist, in this case, pass a null (it can happen when
13962 -- there are protected interrupt handlers or interfaces).
13965 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13967 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13968 -- multiple entries).
13971 Make_Attribute_Reference
(Loc
,
13972 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13973 Attribute_Name
=> Name_Unrestricted_Access
));
13975 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13977 -- Find index mapping function (clumsy but ok for now)
13979 while Ekind
(P_Arr
) /= E_Function
loop
13980 Next_Entity
(P_Arr
);
13984 Make_Attribute_Reference
(Loc
,
13985 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13986 Attribute_Name
=> Name_Unrestricted_Access
));
13989 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13991 -- This is the case where we have a protected object with
13992 -- interfaces and no entries, and the single entry restriction
13993 -- is in effect. We pass a null pointer for the entry
13994 -- parameter because there is no actual entry.
13996 Append_To
(Args
, Make_Null
(Loc
));
13998 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
14000 -- This is the case where we have a protected object with no
14002 -- - either interrupt handlers with non restricted profile,
14004 -- Note that the types which are used for interrupt handlers
14005 -- (Static/Dynamic_Interrupt_Protection) are derived from
14006 -- Protection_Entries. We pass two null pointers because there
14007 -- is no actual entry, and the initialization procedure needs
14008 -- both Entry_Bodies and Find_Body_Index.
14010 Append_To
(Args
, Make_Null
(Loc
));
14011 Append_To
(Args
, Make_Null
(Loc
));
14015 Make_Procedure_Call_Statement
(Loc
,
14017 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
14018 Parameter_Associations
=> Args
));
14022 if Has_Attach_Handler
(Ptyp
) then
14024 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
14025 -- make the following call:
14027 -- Install_Handlers (_object,
14028 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
14030 -- or, in the case of Ravenscar:
14032 -- Install_Restricted_Handlers
14033 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
14036 Args
: constant List_Id
:= New_List
;
14037 Table
: constant List_Id
:= New_List
;
14038 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
14041 -- Build the Priority parameter (only for ravenscar)
14045 -- Priority comes from a pragma
14047 if Present
(Prio_Var
) then
14048 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
14050 -- Priority is the default one
14055 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
14059 -- Build the Attach_Handler table argument
14061 while Present
(Ritem
) loop
14062 if Nkind
(Ritem
) = N_Pragma
14063 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
14066 Handler
: constant Node_Id
:=
14067 First
(Pragma_Argument_Associations
(Ritem
));
14069 Interrupt
: constant Node_Id
:= Next
(Handler
);
14070 Expr
: constant Node_Id
:= Expression
(Interrupt
);
14074 Make_Aggregate
(Loc
, Expressions
=> New_List
(
14075 Unchecked_Convert_To
14076 (RTE
(RE_System_Interrupt_Id
), Expr
),
14077 Make_Attribute_Reference
(Loc
,
14079 Make_Selected_Component
(Loc
,
14081 Make_Identifier
(Loc
, Name_uInit
),
14083 Duplicate_Subexpr_No_Checks
14084 (Expression
(Handler
))),
14085 Attribute_Name
=> Name_Access
))));
14089 Next_Rep_Item
(Ritem
);
14092 -- Append the table argument we just built
14094 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
14096 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14097 -- call to the statements.
14100 -- Call a simplified version of Install_Handlers to be used
14101 -- when the Ravenscar restrictions are in effect
14102 -- (Install_Restricted_Handlers).
14105 Make_Procedure_Call_Statement
(Loc
,
14108 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
14109 Parameter_Associations
=> Args
));
14112 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
14114 -- First, prepends the _object argument
14117 Make_Attribute_Reference
(Loc
,
14119 Make_Selected_Component
(Loc
,
14120 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14122 Make_Identifier
(Loc
, Name_uObject
)),
14123 Attribute_Name
=> Name_Unchecked_Access
));
14126 -- Then, insert call to Install_Handlers
14129 Make_Procedure_Call_Statement
(Loc
,
14131 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
14132 Parameter_Associations
=> Args
));
14138 end Make_Initialize_Protection
;
14140 ---------------------------
14141 -- Make_Task_Create_Call --
14142 ---------------------------
14144 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
14145 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14155 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14156 Tnam
:= Chars
(Ttyp
);
14158 -- Get task declaration. In the case of a task type declaration, this is
14159 -- simply the parent of the task type entity. In the single task
14160 -- declaration, this parent will be the implicit type, and we can find
14161 -- the corresponding single task declaration by searching forward in the
14162 -- declaration list in the tree.
14164 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14165 -- this type should have been removed during semantic analysis.
14167 Tdec
:= Parent
(Ttyp
);
14168 while Nkind
(Tdec
) not in
14169 N_Task_Type_Declaration | N_Single_Task_Declaration
14174 -- Now we can find the task definition from this declaration
14176 Tdef
:= Task_Definition
(Tdec
);
14178 -- Build the parameter list for the call. Note that _Init is the name
14179 -- of the formal for the object to be initialized, which is the task
14180 -- value record itself.
14184 -- Priority parameter. Set to Unspecified_Priority unless there is a
14185 -- Priority rep item, in which case we take the value from the rep item.
14186 -- Not used on Ravenscar_EDF profile.
14188 if not (Restricted_Profile
and then Task_Dispatching_Policy
= 'E') then
14189 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14191 Make_Selected_Component
(Loc
,
14192 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14193 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14196 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14200 -- Optional Stack parameter
14202 if Restricted_Profile
then
14204 -- If the stack has been preallocated by the expander then
14205 -- pass its address. Otherwise, pass a null address.
14207 if Preallocated_Stacks_On_Target
then
14209 Make_Attribute_Reference
(Loc
,
14211 Make_Selected_Component
(Loc
,
14212 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14213 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14214 Attribute_Name
=> Name_Address
));
14218 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14222 -- Size parameter. If no Storage_Size pragma is present, then
14223 -- the size is taken from the taskZ variable for the type, which
14224 -- is either Unspecified_Size, or has been reset by the use of
14225 -- a Storage_Size attribute definition clause. If a pragma is
14226 -- present, then the size is taken from the _Size field of the
14227 -- task value record, which was set from the pragma value.
14229 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14231 Make_Selected_Component
(Loc
,
14232 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14233 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14237 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14240 -- Secondary_Stack parameter used for restricted profiles
14242 if Restricted_Profile
then
14244 -- If the secondary stack has been allocated by the expander then
14245 -- pass its access pointer. Otherwise, pass null.
14247 if Create_Secondary_Stack_For_Task
(Ttyp
) then
14249 Make_Attribute_Reference
(Loc
,
14251 Make_Selected_Component
(Loc
,
14252 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14254 Make_Identifier
(Loc
, Name_uSecondary_Stack
)),
14255 Attribute_Name
=> Name_Unrestricted_Access
));
14258 Append_To
(Args
, Make_Null
(Loc
));
14262 -- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there
14263 -- is a Secondary_Stack_Size pragma, in which case take the value from
14264 -- the pragma. If the restriction No_Secondary_Stack is active then a
14265 -- size of 0 is passed regardless to prevent the allocation of the
14268 if Restriction_Active
(No_Secondary_Stack
) then
14269 Append_To
(Args
, Make_Integer_Literal
(Loc
, 0));
14271 elsif Has_Rep_Pragma
14272 (Ttyp
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
14275 Make_Selected_Component
(Loc
,
14276 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14278 Make_Identifier
(Loc
, Name_uSecondary_Stack_Size
)));
14282 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
14285 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14286 -- Task_Info pragma, in which case we take the value from the pragma.
14288 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14290 Make_Selected_Component
(Loc
,
14291 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14292 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14296 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14299 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14300 -- in which case we take the value from the rep item. The parameter is
14301 -- passed as an Integer because in the case of unspecified CPU the
14302 -- value is not in the range of CPU_Range.
14304 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14306 Convert_To
(Standard_Integer
,
14307 Make_Selected_Component
(Loc
,
14308 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14309 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14312 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14315 if not Restricted_Profile
or else Task_Dispatching_Policy
= 'E' then
14317 -- Deadline parameter. If no Relative_Deadline pragma is present,
14318 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14319 -- the deadline is taken from the _Relative_Deadline field of the
14320 -- task value record, which was set from the pragma value. Note that
14321 -- this parameter must not be generated for the restricted profiles
14322 -- since Ravenscar does not allow deadlines.
14324 -- Case where pragma Relative_Deadline applies: use given value
14326 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14328 Make_Selected_Component
(Loc
,
14329 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14331 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14333 -- No pragma Relative_Deadline apply to the task
14337 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14341 if not Restricted_Profile
then
14343 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14344 -- present, then the dispatching domain is null. If a rep item is
14345 -- present, then the dispatching domain is taken from the
14346 -- _Dispatching_Domain field of the task value record, which was set
14347 -- from the rep item value.
14349 -- Case where Dispatching_Domain rep item applies: use given value
14352 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14355 Make_Selected_Component
(Loc
,
14357 Make_Identifier
(Loc
, Name_uInit
),
14359 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14361 -- No pragma or aspect Dispatching_Domain applies to the task
14364 Append_To
(Args
, Make_Null
(Loc
));
14367 -- Number of entries. This is an expression of the form:
14369 -- n + _Init.a'Length + _Init.a'B'Length + ...
14371 -- where a,b... are the entry family names for the task definition
14373 Ecount
:= Build_Entry_Count_Expression
(Ttyp
, Loc
);
14374 Append_To
(Args
, Ecount
);
14376 -- Master parameter. This is a reference to the _Master parameter of
14377 -- the initialization procedure, except in the case of the pragma
14378 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14379 -- System.Tasking.Library_Task_Level.
14381 if Restriction_Active
(No_Task_Hierarchy
) = False then
14382 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14384 Append_To
(Args
, Make_Integer_Literal
(Loc
, Library_Task_Level
));
14388 -- State parameter. This is a pointer to the task body procedure. The
14389 -- required value is obtained by taking 'Unrestricted_Access of the task
14390 -- body procedure and converting it (with an unchecked conversion) to
14391 -- the type required by the task kernel. For further details, see the
14392 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14393 -- than 'Address in order to avoid creating trampolines.
14396 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14397 Subp_Ptr_Typ
: constant Node_Id
:=
14398 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14399 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14402 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14403 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14405 -- Be sure to freeze a reference to the access-to-subprogram type,
14406 -- otherwise gigi will complain that it's in the wrong scope, because
14407 -- it's actually inside the init procedure for the record type that
14408 -- corresponds to the task type.
14410 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14411 Append_Freeze_Action
(Task_Rec
, Ref
);
14414 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14415 Make_Qualified_Expression
(Loc
,
14416 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14418 Make_Attribute_Reference
(Loc
,
14419 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14420 Attribute_Name
=> Name_Unrestricted_Access
))));
14423 -- Discriminants parameter. This is just the address of the task
14424 -- value record itself (which contains the discriminant values
14427 Make_Attribute_Reference
(Loc
,
14428 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14429 Attribute_Name
=> Name_Address
));
14431 -- Elaborated parameter. This is an access to the elaboration Boolean
14434 Make_Attribute_Reference
(Loc
,
14435 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14436 Attribute_Name
=> Name_Unchecked_Access
));
14438 -- Add Chain parameter (not done for sequential elaboration policy, see
14439 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14441 if Partition_Elaboration_Policy
/= 'S' then
14442 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14445 -- Task name parameter. Take this from the _Task_Id parameter to the
14446 -- init call unless there is a Task_Name pragma, in which case we take
14447 -- the value from the pragma.
14449 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14450 -- Copy expression in full, because it may be dynamic and have
14457 (Pragma_Argument_Associations
14459 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14462 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14465 -- Created_Task parameter. This is the _Task_Id field of the task
14469 Make_Selected_Component
(Loc
,
14470 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14471 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14477 if Restricted_Profile
then
14478 if Partition_Elaboration_Policy
= 'S' then
14479 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14481 Create_RE
:= RE_Create_Restricted_Task
;
14484 Create_RE
:= RE_Create_Task
;
14487 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14491 Make_Procedure_Call_Statement
(Loc
,
14493 Parameter_Associations
=> Args
);
14494 end Make_Task_Create_Call
;
14496 ------------------------------
14497 -- Next_Protected_Operation --
14498 ------------------------------
14500 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14504 -- Check whether there is a subsequent body for a protected operation
14505 -- in the current protected body. In Ada2012 that includes expression
14506 -- functions that are completions.
14508 Next_Op
:= Next
(N
);
14509 while Present
(Next_Op
)
14510 and then Nkind
(Next_Op
) not in
14511 N_Subprogram_Body | N_Entry_Body | N_Expression_Function
14517 end Next_Protected_Operation
;
14519 ---------------------
14520 -- Null_Statements --
14521 ---------------------
14523 function Null_Statements
(Stats
: List_Id
) return Boolean is
14527 Stmt
:= First
(Stats
);
14528 while Nkind
(Stmt
) /= N_Empty
14529 and then (Nkind
(Stmt
) in N_Null_Statement | N_Label
14531 (Nkind
(Stmt
) = N_Pragma
14533 Pragma_Name_Unmapped
(Stmt
) in Name_Unreferenced
14540 return Nkind
(Stmt
) = N_Empty
;
14541 end Null_Statements
;
14543 --------------------------
14544 -- Parameter_Block_Pack --
14545 --------------------------
14547 function Parameter_Block_Pack
14549 Blk_Typ
: Entity_Id
;
14553 Stmts
: List_Id
) return Entity_Id
14555 Actual
: Entity_Id
;
14556 Expr
: Node_Id
:= Empty
;
14557 Formal
: Entity_Id
;
14558 Has_Param
: Boolean := False;
14561 Temp_Asn
: Node_Id
;
14562 Temp_Nam
: Node_Id
;
14565 Actual
:= First
(Actuals
);
14566 Formal
:= Defining_Identifier
(First
(Formals
));
14567 Params
:= New_List
;
14568 while Present
(Actual
) loop
14569 if Is_By_Copy_Type
(Etype
(Actual
)) then
14571 -- Jnn : aliased <formal-type>
14573 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14576 Make_Object_Declaration
(Loc
,
14577 Aliased_Present
=> True,
14578 Defining_Identifier
=> Temp_Nam
,
14579 Object_Definition
=>
14580 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14582 -- The object is initialized with an explicit assignment
14583 -- later. Indicate that it does not need an initialization
14584 -- to prevent spurious warnings if the type excludes null.
14586 Set_No_Initialization
(Last
(Decls
));
14588 if Ekind
(Formal
) /= E_Out_Parameter
then
14594 New_Occurrence_Of
(Temp_Nam
, Loc
);
14596 Set_Assignment_OK
(Temp_Asn
);
14599 Make_Assignment_Statement
(Loc
,
14601 Expression
=> New_Copy_Tree
(Actual
)));
14604 -- If the actual is not controlling, generate:
14606 -- Jnn'unchecked_access
14608 -- and add it to aggegate for access to formals. Note that the
14609 -- actual may be by-copy but still be a controlling actual if it
14610 -- is an access to class-wide interface.
14612 if not Is_Controlling_Actual
(Actual
) then
14614 Make_Attribute_Reference
(Loc
,
14615 Attribute_Name
=> Name_Unchecked_Access
,
14616 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14621 -- The controlling parameter is omitted
14624 if not Is_Controlling_Actual
(Actual
) then
14626 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14632 Next_Actual
(Actual
);
14633 Next_Formal_With_Extras
(Formal
);
14637 Expr
:= Make_Aggregate
(Loc
, Params
);
14642 -- J1'unchecked_access;
14643 -- <actual2>'reference;
14646 P
:= Make_Temporary
(Loc
, 'P');
14649 Make_Object_Declaration
(Loc
,
14650 Defining_Identifier
=> P
,
14651 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14652 Expression
=> Expr
));
14655 end Parameter_Block_Pack
;
14657 ----------------------------
14658 -- Parameter_Block_Unpack --
14659 ----------------------------
14661 function Parameter_Block_Unpack
14665 Formals
: List_Id
) return List_Id
14667 Actual
: Entity_Id
;
14669 Formal
: Entity_Id
;
14670 Has_Asnmt
: Boolean := False;
14671 Result
: constant List_Id
:= New_List
;
14674 Actual
:= First
(Actuals
);
14675 Formal
:= Defining_Identifier
(First
(Formals
));
14676 while Present
(Actual
) loop
14677 if Is_By_Copy_Type
(Etype
(Actual
))
14678 and then Ekind
(Formal
) /= E_In_Parameter
14681 -- <actual> := P.<formal>;
14684 Make_Assignment_Statement
(Loc
,
14688 Make_Explicit_Dereference
(Loc
,
14689 Make_Selected_Component
(Loc
,
14691 New_Occurrence_Of
(P
, Loc
),
14693 Make_Identifier
(Loc
, Chars
(Formal
)))));
14695 Set_Assignment_OK
(Name
(Asnmt
));
14696 Append_To
(Result
, Asnmt
);
14701 Next_Actual
(Actual
);
14702 Next_Formal_With_Extras
(Formal
);
14708 return New_List
(Make_Null_Statement
(Loc
));
14710 end Parameter_Block_Unpack
;
14712 ---------------------
14713 -- Reset_Scopes_To --
14714 ---------------------
14716 procedure Reset_Scopes_To
(Bod
: Node_Id
; E
: Entity_Id
) is
14717 function Reset_Scope
(N
: Node_Id
) return Traverse_Result
;
14718 -- Temporaries may have been declared during expansion of the procedure
14719 -- created for an entry body or an accept alternative. Indicate that
14720 -- their scope is the new body, to ensure proper generation of uplevel
14721 -- references where needed during unnesting.
14723 procedure Reset_Scopes
is new Traverse_Proc
(Reset_Scope
);
14729 function Reset_Scope
(N
: Node_Id
) return Traverse_Result
is
14733 -- If this is a block statement with an Identifier, it forms a scope,
14734 -- so we want to reset its scope but not look inside.
14737 and then Nkind
(N
) = N_Block_Statement
14738 and then Present
(Identifier
(N
))
14740 Set_Scope
(Entity
(Identifier
(N
)), E
);
14743 -- Ditto for a package declaration or a full type declaration, etc.
14745 elsif (Nkind
(N
) = N_Package_Declaration
14746 and then N
/= Specification
(N
))
14747 or else Nkind
(N
) in N_Declaration
14748 or else Nkind
(N
) in N_Renaming_Declaration
14750 Set_Scope
(Defining_Entity
(N
), E
);
14755 -- Scan declarations in new body. Declarations in the statement
14756 -- part will be handled during later traversal.
14758 Decl
:= First
(Declarations
(N
));
14759 while Present
(Decl
) loop
14760 Reset_Scopes
(Decl
);
14764 elsif Nkind
(N
) = N_Freeze_Entity
then
14766 -- Scan the actions associated with a freeze node, which may
14767 -- actually be declarations with entities that need to have
14768 -- their scopes reset.
14770 Decl
:= First
(Actions
(N
));
14771 while Present
(Decl
) loop
14772 Reset_Scopes
(Decl
);
14776 elsif N
/= Bod
and then Nkind
(N
) in N_Proper_Body
then
14778 -- A subprogram without a separate declaration may be encountered,
14779 -- and we need to reset the subprogram's entity's scope.
14781 if Nkind
(N
) = N_Subprogram_Body
then
14782 Set_Scope
(Defining_Entity
(Specification
(N
)), E
);
14791 -- Start of processing for Reset_Scopes_To
14794 Reset_Scopes
(Bod
);
14795 end Reset_Scopes_To
;
14797 ----------------------
14798 -- Set_Discriminals --
14799 ----------------------
14801 procedure Set_Discriminals
(Dec
: Node_Id
) is
14804 D_Minal
: Entity_Id
;
14807 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14808 Pdef
:= Defining_Identifier
(Dec
);
14810 if Has_Discriminants
(Pdef
) then
14811 D
:= First_Discriminant
(Pdef
);
14812 while Present
(D
) loop
14814 Make_Defining_Identifier
(Sloc
(D
),
14815 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14817 Mutate_Ekind
(D_Minal
, E_Constant
);
14818 Set_Etype
(D_Minal
, Etype
(D
));
14819 Set_Scope
(D_Minal
, Pdef
);
14820 Set_Discriminal
(D
, D_Minal
);
14821 Set_Discriminal_Link
(D_Minal
, D
);
14823 Next_Discriminant
(D
);
14826 end Set_Discriminals
;
14828 -----------------------
14829 -- Trivial_Accept_OK --
14830 -----------------------
14832 function Trivial_Accept_OK
return Boolean is
14834 case Opt
.Task_Dispatching_Policy
is
14836 -- If we have the default task dispatching policy in effect, we can
14837 -- definitely do the optimization (one way of looking at this is to
14838 -- think of the formal definition of the default policy being allowed
14839 -- to run any task it likes after a rendezvous, so even if notionally
14840 -- a full rescheduling occurs, we can say that our dispatching policy
14841 -- (i.e. the default dispatching policy) reorders the queue to be the
14842 -- same as just before the call.
14847 -- FIFO_Within_Priorities certainly does not permit this
14848 -- optimization since the Rendezvous is a scheduling action that may
14849 -- require some other task to be run.
14854 -- For now, disallow the optimization for all other policies. This
14855 -- may be over-conservative, but it is certainly not incorrect.
14860 end Trivial_Accept_OK
;