1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Einfo
; use Einfo
;
28 with Elists
; use Elists
;
29 with Errout
; use Errout
;
30 with Exp_Ch3
; use Exp_Ch3
;
31 with Exp_Ch6
; use Exp_Ch6
;
32 with Exp_Ch11
; use Exp_Ch11
;
33 with Exp_Dbug
; use Exp_Dbug
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Sel
; use Exp_Sel
;
36 with Exp_Smem
; use Exp_Smem
;
37 with Exp_Tss
; use Exp_Tss
;
38 with Exp_Util
; use Exp_Util
;
39 with Freeze
; use Freeze
;
41 with Itypes
; use Itypes
;
42 with Namet
; use Namet
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch9
; use Sem_Ch9
;
54 with Sem_Ch11
; use Sem_Ch11
;
55 with Sem_Elab
; use Sem_Elab
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Util
; use Sem_Util
;
59 with Sinfo
; use Sinfo
;
60 with Snames
; use Snames
;
61 with Stand
; use Stand
;
62 with Targparm
; use Targparm
;
63 with Tbuild
; use Tbuild
;
64 with Uintp
; use Uintp
;
65 with Validsw
; use Validsw
;
67 package body Exp_Ch9
is
69 -- The following constant establishes the upper bound for the index of
70 -- an entry family. It is used to limit the allocated size of protected
71 -- types with defaulted discriminant of an integer type, when the bound
72 -- of some entry family depends on a discriminant. The limitation to entry
73 -- families of 128K should be reasonable in all cases, and is a documented
74 -- implementation restriction.
76 Entry_Family_Bound
: constant Pos
:= 2**16;
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 function Actual_Index_Expression
86 Tsk
: Entity_Id
) return Node_Id
;
87 -- Compute the index position for an entry call. Tsk is the target task. If
88 -- the bounds of some entry family depend on discriminants, the expression
89 -- computed by this function uses the discriminants of the target task.
91 procedure Add_Object_Pointer
95 -- Prepend an object pointer declaration to the declaration list Decls.
96 -- This object pointer is initialized to a type conversion of the System.
97 -- Address pointer passed to entry barrier functions and entry body
100 procedure Add_Formal_Renamings
105 -- Create renaming declarations for the formals, inside the procedure that
106 -- implements an entry body. The renamings make the original names of the
107 -- formals accessible to gdb, and serve no other purpose.
108 -- Spec is the specification of the procedure being built.
109 -- Decls is the list of declarations to be enhanced.
110 -- Ent is the entity for the original entry body.
112 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
113 -- Transform accept statement into a block with added exception handler.
114 -- Used both for simple accept statements and for accept alternatives in
115 -- select statements. Astat is the accept statement.
117 function Build_Barrier_Function
120 Pid
: Node_Id
) return Node_Id
;
121 -- Build the function body returning the value of the barrier expression
122 -- for the specified entry body.
124 function Build_Barrier_Function_Specification
126 Def_Id
: Entity_Id
) return Node_Id
;
127 -- Build a specification for a function implementing the protected entry
128 -- barrier of the specified entry body.
130 procedure Build_Contract_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
131 -- Build the body of a wrapper procedure for an entry or entry family that
132 -- has contract cases, preconditions, or postconditions. The body gathers
133 -- the executable contract items and expands them in the usual way, and
134 -- performs the entry call itself. This way preconditions are evaluated
135 -- before the call is queued. E is the entry in question, and Decl is the
136 -- enclosing synchronized type declaration at whose freeze point the
137 -- generated body is analyzed.
139 function Build_Corresponding_Record
142 Loc
: Source_Ptr
) return Node_Id
;
143 -- Common to tasks and protected types. Copy discriminant specifications,
144 -- build record declaration. N is the type declaration, Ctyp is the
145 -- concurrent entity (task type or protected type).
147 function Build_Dispatching_Tag_Check
149 N
: Node_Id
) return Node_Id
;
150 -- Utility to create the tree to check whether the dispatching call in
151 -- a timed entry call, a conditional entry call, or an asynchronous
152 -- transfer of control is a call to a primitive of a non-synchronized type.
153 -- K is the temporary that holds the tagged kind of the target object, and
154 -- N is the enclosing construct.
156 function Build_Entry_Count_Expression
157 (Concurrent_Type
: Node_Id
;
158 Component_List
: List_Id
;
159 Loc
: Source_Ptr
) return Node_Id
;
160 -- Compute number of entries for concurrent object. This is a count of
161 -- simple entries, followed by an expression that computes the length
162 -- of the range of each entry family. A single array with that size is
163 -- allocated for each concurrent object of the type.
165 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
166 -- Build the function that translates the entry index in the call
167 -- (which depends on the size of entry families) into an index into the
168 -- Entry_Bodies_Array, to determine the body and barrier function used
169 -- in a protected entry call. A pointer to this function appears in every
172 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
173 -- Build subprogram declaration for previous one
175 function Build_Lock_Free_Protected_Subprogram_Body
178 Unprot_Spec
: Node_Id
) return Node_Id
;
179 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
180 -- the subprogram specification of the unprotected version of N. Transform
181 -- N such that it invokes the unprotected version of the body.
183 function Build_Lock_Free_Unprotected_Subprogram_Body
185 Prot_Typ
: Node_Id
) return Node_Id
;
186 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
187 -- of N where the original statements of N are synchronized through atomic
188 -- actions such as compare and exchange. Prior to invoking this routine, it
189 -- has been established that N can be implemented in a lock-free fashion.
191 function Build_Parameter_Block
195 Decls
: List_Id
) return Entity_Id
;
196 -- Generate an access type for each actual parameter in the list Actuals.
197 -- Create an encapsulating record that contains all the actuals and return
198 -- its type. Generate:
199 -- type Ann1 is access all <actual1-type>
201 -- type AnnN is access all <actualN-type>
202 -- type Pnn is record
208 function Build_Protected_Entry
211 Pid
: Node_Id
) return Node_Id
;
212 -- Build the procedure implementing the statement sequence of the specified
215 function Build_Protected_Entry_Specification
218 Ent_Id
: Entity_Id
) return Node_Id
;
219 -- Build a specification for the procedure implementing the statements of
220 -- the specified entry body. Add attributes associating it with the entry
221 -- defining identifier Ent_Id.
223 function Build_Protected_Spec
225 Obj_Type
: Entity_Id
;
227 Unprotected
: Boolean := False) return List_Id
;
228 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
229 -- Subprogram_Type. Builds signature of protected subprogram, adding the
230 -- formal that corresponds to the object itself. For an access to protected
231 -- subprogram, there is no object type to specify, so the parameter has
232 -- type Address and mode In. An indirect call through such a pointer will
233 -- convert the address to a reference to the actual object. The object is
234 -- a limited record and therefore a by_reference type.
236 function Build_Protected_Subprogram_Body
239 N_Op_Spec
: Node_Id
) return Node_Id
;
240 -- This function is used to construct the protected version of a protected
241 -- subprogram. Its statement sequence first defers abort, then locks the
242 -- associated protected object, and then enters a block that contains a
243 -- call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires a
245 -- cleanup handler that unlocks the object in all cases. For details,
246 -- see Exp_Ch7.Expand_Cleanup_Actions.
248 function Build_Renamed_Formal_Declaration
252 Renamed_Formal
: Node_Id
) return Node_Id
;
253 -- Create a renaming declaration for a formal, within a protected entry
254 -- body or an accept body. The renamed object is a component of the
255 -- parameter block that is a parameter in the entry call.
257 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
258 -- does not dereference the corresponding component to prevent an illegal
259 -- use of the incomplete type (AI05-0151).
261 function Build_Selected_Name
263 Selector
: Entity_Id
;
264 Append_Char
: Character := ' ') return Name_Id
;
265 -- Build a name in the form of Prefix__Selector, with an optional character
266 -- appended. This is used for internal subprograms generated for operations
267 -- of protected types, including barrier functions. For the subprograms
268 -- generated for entry bodies and entry barriers, the generated name
269 -- includes a sequence number that makes names unique in the presence of
270 -- entry overloading. This is necessary because entry body procedures and
271 -- barrier functions all have the same signature.
273 procedure Build_Simple_Entry_Call
278 -- Some comments here would be useful ???
280 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
281 -- This routine constructs a specification for the procedure that we will
282 -- build for the task body for task type T. The spec has the form:
284 -- procedure tnameB (_Task : access tnameV);
286 -- where name is the character name taken from the task type entity that
287 -- is passed as the argument to the procedure, and tnameV is the task
288 -- value type that is associated with the task type.
290 function Build_Unprotected_Subprogram_Body
292 Pid
: Node_Id
) return Node_Id
;
293 -- This routine constructs the unprotected version of a protected
294 -- subprogram body, which is contains all of the code in the original,
295 -- unexpanded body. This is the version of the protected subprogram that is
296 -- called from all protected operations on the same object, including the
297 -- protected version of the same subprogram.
299 procedure Build_Wrapper_Bodies
303 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
304 -- record of a concurrent type. N is the insertion node where all bodies
305 -- will be placed. This routine builds the bodies of the subprograms which
306 -- serve as an indirection mechanism to overriding primitives of concurrent
307 -- types, entries and protected procedures. Any new body is analyzed.
309 procedure Build_Wrapper_Specs
313 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
314 -- record of a concurrent type. N is the insertion node where all specs
315 -- will be placed. This routine builds the specs of the subprograms which
316 -- serve as an indirection mechanism to overriding primitives of concurrent
317 -- types, entries and protected procedures. Any new spec is analyzed.
319 procedure Collect_Entry_Families
322 Current_Node
: in out Node_Id
;
323 Conctyp
: Entity_Id
);
324 -- For each entry family in a concurrent type, create an anonymous array
325 -- type of the right size, and add a component to the corresponding_record.
327 function Concurrent_Object
328 (Spec_Id
: Entity_Id
;
329 Conc_Typ
: Entity_Id
) return Entity_Id
;
330 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
331 -- the entity associated with the concurrent object in the Protected_Body_
332 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
333 -- denotes formal parameter _O, _object or _task.
335 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
336 -- Copy the result type of a function specification, when building the
337 -- internal operation corresponding to a protected function, or when
338 -- expanding an access to protected function. If the result is an anonymous
339 -- access to subprogram itself, we need to create a new signature with the
340 -- same parameter names and the same resolved types, but with new entities
343 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
344 -- Decls is a list which may contain the declarations created by Install_
345 -- Private_Data_Declarations. All generated entities are marked as needing
346 -- debug info and debug nodes are manually generation where necessary. This
347 -- step of the expansion must to be done after private data has been moved
348 -- to its final resting scope to ensure proper visibility of debug objects.
350 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
351 -- If control flow optimizations are suppressed, and Alt is an accept,
352 -- delay, or entry call alternative with no trailing statements, insert
353 -- a null trailing statement with the given Loc (which is the sloc of
354 -- the accept, delay, or entry call statement). There might not be any
355 -- generated code for the accept, delay, or entry call itself (the effect
356 -- of these statements is part of the general processsing done for the
357 -- enclosing selective accept, timed entry call, or asynchronous select),
358 -- and the null statement is there to carry the sloc of that statement to
359 -- the back-end for trace-based coverage analysis purposes.
361 procedure Extract_Dispatching_Call
363 Call_Ent
: out Entity_Id
;
364 Object
: out Entity_Id
;
365 Actuals
: out List_Id
;
366 Formals
: out List_Id
);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval
: out Node_Id
;
377 Index
: out Node_Id
);
378 -- Given an entry call, returns the associated concurrent object, the entry
379 -- name, and the entry family index.
381 function Family_Offset
386 Cap
: Boolean) return Node_Id
;
387 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
388 -- accept statement, or the upper bound in the discrete subtype of an entry
389 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
390 -- type of the entry. If Cap is true, the result is capped according to
391 -- Entry_Family_Bound.
398 Cap
: Boolean) return Node_Id
;
399 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
400 -- family, and handle properly the superflat case. This is equivalent to
401 -- the use of 'Length on the index type, but must use Family_Offset to
402 -- handle properly the case of bounds that depend on discriminants. If
403 -- Cap is true, the result is capped according to Entry_Family_Bound.
405 procedure Find_Enclosing_Context
407 Context
: out Node_Id
;
408 Context_Id
: out Entity_Id
;
409 Context_Decls
: out List_Id
);
410 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
411 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
412 -- nearest enclosing body, block, package, or return statement and return
413 -- its constituents. Context is the enclosing construct, Context_Id is
414 -- the scope of Context_Id and Context_Decls is the declarative list of
417 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
418 -- Given a subprogram identifier, return the entity which is associated
419 -- with the protection entry index in the Protected_Body_Subprogram or
420 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
423 function Is_Potentially_Large_Family
424 (Base_Index
: Entity_Id
;
427 Hi
: Node_Id
) return Boolean;
429 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
430 -- Determine whether Id is a function or a procedure and is marked as a
431 -- private primitive.
433 function Null_Statements
(Stats
: List_Id
) return Boolean;
434 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
435 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
436 -- to still count as null. Returns True for a null sequence. The argument
437 -- is the list of statements from the DO-END sequence.
439 function Parameter_Block_Pack
445 Stmts
: List_Id
) return Entity_Id
;
446 -- Set the components of the generated parameter block with the values
447 -- of the actual parameters. Generate aliased temporaries to capture the
448 -- values for types that are passed by copy. Otherwise generate a reference
449 -- to the actual's value. Return the address of the aggregate block.
451 -- Jnn1 : alias <formal-type1>;
452 -- Jnn1 := <actual1>;
455 -- Jnn1'unchecked_access;
456 -- <actual2>'reference;
459 function Parameter_Block_Unpack
463 Formals
: List_Id
) return List_Id
;
464 -- Retrieve the values of the components from the parameter block and
465 -- assign then to the original actual parameters. Generate:
466 -- <actual1> := P.<formal1>;
468 -- <actualN> := P.<formalN>;
470 function Trivial_Accept_OK
return Boolean;
471 -- If there is no DO-END block for an accept, or if the DO-END block has
472 -- only null statements, then it is possible to do the Rendezvous with much
473 -- less overhead using the Accept_Trivial routine in the run-time library.
474 -- However, this is not always a valid optimization. Whether it is valid or
475 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
476 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
477 -- a rescheduling is required, so this optimization is not allowed. This
478 -- function returns True if the optimization is permitted.
480 -----------------------------
481 -- Actual_Index_Expression --
482 -----------------------------
484 function Actual_Index_Expression
488 Tsk
: Entity_Id
) return Node_Id
490 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
498 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
499 -- Compute difference between bounds of entry family
501 --------------------------
502 -- Actual_Family_Offset --
503 --------------------------
505 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
507 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
508 -- Replace a reference to a discriminant with a selected component
509 -- denoting the discriminant of the target task.
511 -----------------------------
512 -- Actual_Discriminant_Ref --
513 -----------------------------
515 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
516 Typ
: constant Entity_Id
:= Etype
(Bound
);
520 if not Is_Entity_Name
(Bound
)
521 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
523 if Nkind
(Bound
) = N_Attribute_Reference
then
526 B
:= New_Copy_Tree
(Bound
);
531 Make_Selected_Component
(Sloc
,
532 Prefix
=> New_Copy_Tree
(Tsk
),
533 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
535 Analyze_And_Resolve
(B
, Typ
);
539 Make_Attribute_Reference
(Sloc
,
540 Attribute_Name
=> Name_Pos
,
541 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
542 Expressions
=> New_List
(B
));
543 end Actual_Discriminant_Ref
;
545 -- Start of processing for Actual_Family_Offset
549 Make_Op_Subtract
(Sloc
,
550 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
551 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
552 end Actual_Family_Offset
;
554 -- Start of processing for Actual_Index_Expression
557 -- The queues of entries and entry families appear in textual order in
558 -- the associated record. The entry index is computed as the sum of the
559 -- number of queues for all entries that precede the designated one, to
560 -- which is added the index expression, if this expression denotes a
561 -- member of a family.
563 -- The following is a place holder for the count of simple entries
565 Num
:= Make_Integer_Literal
(Sloc
, 1);
567 -- We construct an expression which is a series of addition operations.
568 -- See comments in Entry_Index_Expression, which is identical in
571 if Present
(Index
) then
572 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
578 Actual_Family_Offset
(
579 Make_Attribute_Reference
(Sloc
,
580 Attribute_Name
=> Name_Pos
,
581 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
582 Expressions
=> New_List
(Relocate_Node
(Index
))),
583 Type_Low_Bound
(S
)));
588 -- Now add lengths of preceding entries and entry families
590 Prev
:= First_Entity
(Ttyp
);
591 while Chars
(Prev
) /= Chars
(Ent
)
592 or else (Ekind
(Prev
) /= Ekind
(Ent
))
593 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
595 if Ekind
(Prev
) = E_Entry
then
596 Set_Intval
(Num
, Intval
(Num
) + 1);
598 elsif Ekind
(Prev
) = E_Entry_Family
then
600 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
602 -- The need for the following full view retrieval stems from this
603 -- complex case of nested generics and tasking:
606 -- type Formal_Index is range <>;
609 -- type Index is private;
616 -- type Index is new Formal_Index range 1 .. 10;
619 -- package body Outer is
621 -- entry Fam (Index); -- (2)
624 -- package body Inner is -- (3)
632 -- We are currently building the index expression for the entry
633 -- call "T.E" (1). Part of the expansion must mention the range
634 -- of the discrete type "Index" (2) of entry family "Fam".
636 -- However only the private view of type "Index" is available to
637 -- the inner generic (3) because there was no prior mention of
638 -- the type inside "Inner". This visibility requirement is
639 -- implicit and cannot be detected during the construction of
640 -- the generic trees and needs special handling.
643 and then Is_Private_Type
(S
)
644 and then Present
(Full_View
(S
))
649 Lo
:= Type_Low_Bound
(S
);
650 Hi
:= Type_High_Bound
(S
);
657 Left_Opnd
=> Actual_Family_Offset
(Hi
, Lo
),
658 Right_Opnd
=> Make_Integer_Literal
(Sloc
, 1)));
660 -- Other components are anonymous types to be ignored
670 end Actual_Index_Expression
;
672 --------------------------
673 -- Add_Formal_Renamings --
674 --------------------------
676 procedure Add_Formal_Renamings
682 Ptr
: constant Entity_Id
:=
684 (Next
(First
(Parameter_Specifications
(Spec
))));
685 -- The name of the formal that holds the address of the parameter block
692 Renamed_Formal
: Node_Id
;
695 Formal
:= First_Formal
(Ent
);
696 while Present
(Formal
) loop
697 Comp
:= Entry_Component
(Formal
);
699 Make_Defining_Identifier
(Sloc
(Formal
),
700 Chars
=> Chars
(Formal
));
701 Set_Etype
(New_F
, Etype
(Formal
));
702 Set_Scope
(New_F
, Ent
);
704 -- Now we set debug info needed on New_F even though it does not come
705 -- from source, so that the debugger will get the right information
706 -- for these generated names.
708 Set_Debug_Info_Needed
(New_F
);
710 if Ekind
(Formal
) = E_In_Parameter
then
711 Set_Ekind
(New_F
, E_Constant
);
713 Set_Ekind
(New_F
, E_Variable
);
714 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
717 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
720 Make_Selected_Component
(Loc
,
722 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
723 Make_Identifier
(Loc
, Chars
(Ptr
))),
724 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
727 Build_Renamed_Formal_Declaration
728 (New_F
, Formal
, Comp
, Renamed_Formal
);
730 Append
(Decl
, Decls
);
731 Set_Renamed_Object
(Formal
, New_F
);
732 Next_Formal
(Formal
);
734 end Add_Formal_Renamings
;
736 ------------------------
737 -- Add_Object_Pointer --
738 ------------------------
740 procedure Add_Object_Pointer
742 Conc_Typ
: Entity_Id
;
745 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
750 -- Create the renaming declaration for the Protection object of a
751 -- protected type. _Object is used by Complete_Entry_Body.
752 -- ??? An attempt to make this a renaming was unsuccessful.
754 -- Build the entity for the access type
757 Make_Defining_Identifier
(Loc
,
758 New_External_Name
(Chars
(Rec_Typ
), 'P'));
761 -- _object : poVP := poVP!O;
764 Make_Object_Declaration
(Loc
,
765 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uObject
),
766 Object_Definition
=> New_Occurrence_Of
(Obj_Ptr
, Loc
),
768 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
769 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
770 Prepend_To
(Decls
, Decl
);
773 -- type poVP is access poV;
776 Make_Full_Type_Declaration
(Loc
,
777 Defining_Identifier
=>
780 Make_Access_To_Object_Definition
(Loc
,
781 Subtype_Indication
=>
782 New_Occurrence_Of
(Rec_Typ
, Loc
)));
783 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
784 Prepend_To
(Decls
, Decl
);
785 end Add_Object_Pointer
;
787 -----------------------
788 -- Build_Accept_Body --
789 -----------------------
791 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
792 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
793 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
800 -- At the end of the statement sequence, Complete_Rendezvous is called.
801 -- A label skipping the Complete_Rendezvous, and all other accept
802 -- processing, has already been added for the expansion of requeue
803 -- statements. The Sloc is copied from the last statement since it
804 -- is really part of this last statement.
808 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
809 Insert_Before
(Last
(Statements
(Stats
)), Call
);
812 -- If exception handlers are present, then append Complete_Rendezvous
813 -- calls to the handlers, and construct the required outer block. As
814 -- above, the Sloc is copied from the last statement in the sequence.
816 if Present
(Exception_Handlers
(Stats
)) then
817 Hand
:= First
(Exception_Handlers
(Stats
));
818 while Present
(Hand
) loop
821 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
822 Append
(Call
, Statements
(Hand
));
828 Make_Handled_Sequence_Of_Statements
(Loc
,
829 Statements
=> New_List
(
830 Make_Block_Statement
(Loc
,
831 Handled_Statement_Sequence
=> Stats
)));
837 -- At this stage we know that the new statement sequence does
838 -- not have an exception handler part, so we supply one to call
839 -- Exceptional_Complete_Rendezvous. This handler is
841 -- when all others =>
842 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
844 -- We handle Abort_Signal to make sure that we properly catch the abort
845 -- case and wake up the caller.
847 Ohandle
:= Make_Others_Choice
(Loc
);
848 Set_All_Others
(Ohandle
);
850 Set_Exception_Handlers
(New_S
,
852 Make_Implicit_Exception_Handler
(Loc
,
853 Exception_Choices
=> New_List
(Ohandle
),
855 Statements
=> New_List
(
856 Make_Procedure_Call_Statement
(Sloc
(Stats
),
857 Name
=> New_Occurrence_Of
(
858 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
859 Parameter_Associations
=> New_List
(
860 Make_Function_Call
(Sloc
(Stats
),
863 (RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
865 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
866 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
867 Expand_Exception_Handlers
(New_S
);
869 -- Exceptional_Complete_Rendezvous must be called with abort still
870 -- deferred, which is the case for a "when all others" handler.
873 end Build_Accept_Body
;
875 -----------------------------------
876 -- Build_Activation_Chain_Entity --
877 -----------------------------------
879 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
880 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
881 -- Determine whether an extended return statement has activation chain
883 --------------------------
884 -- Has_Activation_Chain --
885 --------------------------
887 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
891 Decl
:= First
(Return_Object_Declarations
(Stmt
));
892 while Present
(Decl
) loop
893 if Nkind
(Decl
) = N_Object_Declaration
894 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
903 end Has_Activation_Chain
;
908 Context_Id
: Entity_Id
;
911 -- Start of processing for Build_Activation_Chain_Entity
914 -- Activation chain is never used for sequential elaboration policy, see
915 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
917 if Partition_Elaboration_Policy
= 'S' then
921 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
923 -- If activation chain entity has not been declared already, create one
925 if Nkind
(Context
) = N_Extended_Return_Statement
926 or else No
(Activation_Chain_Entity
(Context
))
928 -- Since extended return statements do not store the entity of the
929 -- chain, examine the return object declarations to avoid creating
932 if Nkind
(Context
) = N_Extended_Return_Statement
933 and then Has_Activation_Chain
(Context
)
939 Loc
: constant Source_Ptr
:= Sloc
(Context
);
944 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
946 -- Note: An extended return statement is not really a task
947 -- activator, but it does have an activation chain on which to
948 -- store the tasks temporarily. On successful return, the tasks
949 -- on this chain are moved to the chain passed in by the caller.
950 -- We do not build an Activation_Chain_Entity for an extended
951 -- return statement, because we do not want to build a call to
952 -- Activate_Tasks. Task activation is the responsibility of the
955 if Nkind
(Context
) /= N_Extended_Return_Statement
then
956 Set_Activation_Chain_Entity
(Context
, Chain
);
960 Make_Object_Declaration
(Loc
,
961 Defining_Identifier
=> Chain
,
962 Aliased_Present
=> True,
964 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
));
966 Prepend_To
(Decls
, Decl
);
968 -- Ensure that _chain appears in the proper scope of the context
970 if Context_Id
/= Current_Scope
then
971 Push_Scope
(Context_Id
);
979 end Build_Activation_Chain_Entity
;
981 ----------------------------
982 -- Build_Barrier_Function --
983 ----------------------------
985 function Build_Barrier_Function
988 Pid
: Node_Id
) return Node_Id
990 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
991 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
992 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
993 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
994 Op_Decls
: constant List_Id
:= New_List
;
999 -- Add a declaration for the Protection object, renaming declarations
1000 -- for the discriminals and privals and finally a declaration for the
1001 -- entry family index (if applicable).
1003 Install_Private_Data_Declarations
(Sloc
(N
),
1009 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1011 -- If compiling with -fpreserve-control-flow, make sure we insert an
1012 -- IF statement so that the back-end knows to generate a conditional
1013 -- branch instruction, even if the condition is just the name of a
1014 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1015 -- such redundant IF statements under -fpreserve-control-flow
1016 -- (whether coming from this routine, or directly from source).
1018 if Opt
.Suppress_Control_Flow_Optimizations
then
1020 Make_Implicit_If_Statement
(Cond
,
1022 Then_Statements
=> New_List
(
1023 Make_Simple_Return_Statement
(Loc
,
1024 New_Occurrence_Of
(Standard_True
, Loc
))),
1026 Else_Statements
=> New_List
(
1027 Make_Simple_Return_Statement
(Loc
,
1028 New_Occurrence_Of
(Standard_False
, Loc
))));
1031 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1034 -- Note: the condition in the barrier function needs to be properly
1035 -- processed for the C/Fortran boolean possibility, but this happens
1036 -- automatically since the return statement does this normalization.
1039 Make_Subprogram_Body
(Loc
,
1041 Build_Barrier_Function_Specification
(Loc
,
1042 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1043 Declarations
=> Op_Decls
,
1044 Handled_Statement_Sequence
=>
1045 Make_Handled_Sequence_Of_Statements
(Loc
,
1046 Statements
=> New_List
(Stmt
)));
1047 Set_Is_Entry_Barrier_Function
(Func_Body
);
1050 end Build_Barrier_Function
;
1052 ------------------------------------------
1053 -- Build_Barrier_Function_Specification --
1054 ------------------------------------------
1056 function Build_Barrier_Function_Specification
1058 Def_Id
: Entity_Id
) return Node_Id
1061 Set_Debug_Info_Needed
(Def_Id
);
1064 Make_Function_Specification
(Loc
,
1065 Defining_Unit_Name
=> Def_Id
,
1066 Parameter_Specifications
=> New_List
(
1067 Make_Parameter_Specification
(Loc
,
1068 Defining_Identifier
=>
1069 Make_Defining_Identifier
(Loc
, Name_uO
),
1071 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
1073 Make_Parameter_Specification
(Loc
,
1074 Defining_Identifier
=>
1075 Make_Defining_Identifier
(Loc
, Name_uE
),
1077 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1079 Result_Definition
=>
1080 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1081 end Build_Barrier_Function_Specification
;
1083 --------------------------
1084 -- Build_Call_With_Task --
1085 --------------------------
1087 function Build_Call_With_Task
1089 E
: Entity_Id
) return Node_Id
1091 Loc
: constant Source_Ptr
:= Sloc
(N
);
1094 Make_Function_Call
(Loc
,
1095 Name
=> New_Occurrence_Of
(E
, Loc
),
1096 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1097 end Build_Call_With_Task
;
1099 -----------------------------
1100 -- Build_Class_Wide_Master --
1101 -----------------------------
1103 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1104 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1105 Master_Decl
: Node_Id
;
1106 Master_Id
: Entity_Id
;
1107 Master_Scope
: Entity_Id
;
1109 Related_Node
: Node_Id
;
1113 -- Nothing to do if there is no task hierarchy
1115 if Restriction_Active
(No_Task_Hierarchy
) then
1119 -- Find the declaration that created the access type, which is either a
1120 -- type declaration, or an object declaration with an access definition,
1121 -- in which case the type is anonymous.
1123 if Is_Itype
(Typ
) then
1124 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1126 Related_Node
:= Parent
(Typ
);
1129 Master_Scope
:= Find_Master_Scope
(Typ
);
1131 -- Nothing to do if the master scope already contains a _master entity.
1132 -- The only exception to this is the following scenario:
1135 -- Transient_Scope_1
1138 -- Transient_Scope_2
1141 -- In this case the source scope is marked as having the master entity
1142 -- even though the actual declaration appears inside an inner scope. If
1143 -- the second transient scope requires a _master, it cannot use the one
1144 -- already declared because the entity is not visible.
1146 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1147 Master_Decl
:= Empty
;
1149 if not Has_Master_Entity
(Master_Scope
)
1150 or else No
(Current_Entity_In_Scope
(Name_Id
))
1153 Set_Has_Master_Entity
(Master_Scope
);
1156 -- _master : constant Integer := Current_Master.all;
1159 Make_Object_Declaration
(Loc
,
1160 Defining_Identifier
=>
1161 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1162 Constant_Present
=> True,
1163 Object_Definition
=>
1164 New_Occurrence_Of
(Standard_Integer
, Loc
),
1166 Make_Explicit_Dereference
(Loc
,
1167 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
1169 Insert_Action
(Find_Hook_Context
(Related_Node
), Master_Decl
);
1170 Analyze
(Master_Decl
);
1172 -- Mark the containing scope as a task master. Masters associated
1173 -- with return statements are already marked at this stage (see
1174 -- Analyze_Subprogram_Body).
1176 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1178 Par
: Node_Id
:= Related_Node
;
1181 while Nkind
(Par
) /= N_Compilation_Unit
loop
1182 Par
:= Parent
(Par
);
1184 -- If we fall off the top, we are at the outer level,
1185 -- and the environment task is our effective master,
1186 -- so nothing to mark.
1188 if Nkind_In
(Par
, N_Block_Statement
,
1192 Set_Is_Task_Master
(Par
);
1202 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(Typ
), 'M'));
1205 -- typeMnn renames _master;
1208 Make_Object_Renaming_Declaration
(Loc
,
1209 Defining_Identifier
=> Master_Id
,
1210 Subtype_Mark
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1213 -- If the master is declared locally, add the renaming declaration
1214 -- immediately after it, to prevent access-before-elaboration in the
1217 if Present
(Master_Decl
) then
1218 Insert_After
(Master_Decl
, Ren_Decl
);
1222 Insert_Action
(Related_Node
, Ren_Decl
);
1225 Set_Master_Id
(Typ
, Master_Id
);
1226 end Build_Class_Wide_Master
;
1228 ----------------------------
1229 -- Build_Contract_Wrapper --
1230 ----------------------------
1232 procedure Build_Contract_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1233 Conc_Typ
: constant Entity_Id
:= Scope
(E
);
1234 Loc
: constant Source_Ptr
:= Sloc
(E
);
1236 procedure Add_Discriminant_Renamings
1237 (Obj_Id
: Entity_Id
;
1239 -- Add renaming declarations for all discriminants of concurrent type
1240 -- Conc_Typ. Obj_Id is the entity of the wrapper formal parameter which
1241 -- represents the concurrent object.
1243 procedure Add_Matching_Formals
1245 Actuals
: in out List_Id
);
1246 -- Add formal parameters that match those of entry E to list Formals.
1247 -- The routine also adds matching actuals for the new formals to list
1250 procedure Transfer_Pragma
(Prag
: Node_Id
; To
: in out List_Id
);
1251 -- Relocate pragma Prag to list To. The routine creates a new list if
1252 -- To does not exist.
1254 --------------------------------
1255 -- Add_Discriminant_Renamings --
1256 --------------------------------
1258 procedure Add_Discriminant_Renamings
1259 (Obj_Id
: Entity_Id
;
1265 -- Inspect the discriminants of the concurrent type and generate a
1266 -- renaming for each one.
1268 if Has_Discriminants
(Conc_Typ
) then
1269 Discr
:= First_Discriminant
(Conc_Typ
);
1270 while Present
(Discr
) loop
1272 Make_Object_Renaming_Declaration
(Loc
,
1273 Defining_Identifier
=>
1274 Make_Defining_Identifier
(Loc
, Chars
(Discr
)),
1276 New_Occurrence_Of
(Etype
(Discr
), Loc
),
1278 Make_Selected_Component
(Loc
,
1279 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
1281 Make_Identifier
(Loc
, Chars
(Discr
)))));
1283 Next_Discriminant
(Discr
);
1286 end Add_Discriminant_Renamings
;
1288 --------------------------
1289 -- Add_Matching_Formals --
1290 --------------------------
1292 procedure Add_Matching_Formals
1294 Actuals
: in out List_Id
)
1297 New_Formal
: Entity_Id
;
1300 -- Inspect the formal parameters of the entry and generate a new
1301 -- matching formal with the same name for the wrapper. A reference
1302 -- to the new formal becomes an actual in the entry call.
1304 Formal
:= First_Formal
(E
);
1305 while Present
(Formal
) loop
1306 New_Formal
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
1308 Make_Parameter_Specification
(Loc
,
1309 Defining_Identifier
=> New_Formal
,
1310 In_Present
=> In_Present
(Parent
(Formal
)),
1311 Out_Present
=> Out_Present
(Parent
(Formal
)),
1313 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
1315 if No
(Actuals
) then
1316 Actuals
:= New_List
;
1319 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1320 Next_Formal
(Formal
);
1322 end Add_Matching_Formals
;
1324 ---------------------
1325 -- Transfer_Pragma --
1326 ---------------------
1328 procedure Transfer_Pragma
(Prag
: Node_Id
; To
: in out List_Id
) is
1336 New_Prag
:= Relocate_Node
(Prag
);
1338 Set_Analyzed
(New_Prag
, False);
1339 Append
(New_Prag
, To
);
1340 end Transfer_Pragma
;
1344 Items
: constant Node_Id
:= Contract
(E
);
1345 Actuals
: List_Id
:= No_List
;
1348 Decls
: List_Id
:= No_List
;
1350 Has_Pragma
: Boolean := False;
1351 Index_Id
: Entity_Id
;
1354 Wrapper_Id
: Entity_Id
;
1356 -- Start of processing for Build_Contract_Wrapper
1359 -- This routine generates a specialized wrapper for a protected or task
1360 -- entry [family] which implements precondition/postcondition semantics.
1361 -- Preconditions and case guards of contract cases are checked before
1362 -- the protected action or rendezvous takes place. Postconditions and
1363 -- consequences of contract cases are checked after the protected action
1364 -- or rendezvous takes place. The structure of the generated wrapper is
1367 -- procedure Wrapper
1368 -- (Obj_Id : Conc_Typ; -- concurrent object
1369 -- [Index : Index_Typ;] -- index of entry family
1370 -- [Formal_1 : ...; -- parameters of original entry
1373 -- [Discr_1 : ... renames Obj_Id.Discr_1; -- discriminant
1374 -- Discr_N : ... renames Obj_Id.Discr_N;] -- renamings
1376 -- <precondition checks>
1377 -- <case guard checks>
1379 -- procedure _Postconditions is
1381 -- <postcondition checks>
1382 -- <consequence checks>
1383 -- end _Postconditions;
1386 -- Entry_Call (Obj_Id, [Index,] [Formal_1, Formal_N]);
1390 -- Create the wrapper only when the entry has at least one executable
1391 -- contract item such as contract cases, precondition or postcondition.
1393 if Present
(Items
) then
1395 -- Inspect the list of pre/postconditions and transfer all available
1396 -- pragmas to the declarative list of the wrapper.
1398 Prag
:= Pre_Post_Conditions
(Items
);
1399 while Present
(Prag
) loop
1400 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
1401 Name_Postcondition
, Name_Precondition
)
1402 and then Is_Checked
(Prag
)
1405 Transfer_Pragma
(Prag
, To
=> Decls
);
1408 Prag
:= Next_Pragma
(Prag
);
1411 -- Inspect the list of test/contract cases and transfer only contract
1412 -- cases pragmas to the declarative part of the wrapper.
1414 Prag
:= Contract_Test_Cases
(Items
);
1415 while Present
(Prag
) loop
1416 if Pragma_Name
(Prag
) = Name_Contract_Cases
1417 and then Is_Checked
(Prag
)
1420 Transfer_Pragma
(Prag
, To
=> Decls
);
1423 Prag
:= Next_Pragma
(Prag
);
1427 -- The entry lacks executable contract items and a wrapper is not needed
1429 if not Has_Pragma
then
1433 -- Create the profile of the wrapper. The first formal parameter is the
1434 -- concurrent object.
1437 Make_Defining_Identifier
(Loc
,
1438 Chars
=> New_External_Name
(Chars
(Conc_Typ
), 'A'));
1440 Formals
:= New_List
(
1441 Make_Parameter_Specification
(Loc
,
1442 Defining_Identifier
=> Obj_Id
,
1443 Out_Present
=> True,
1445 Parameter_Type
=> New_Occurrence_Of
(Conc_Typ
, Loc
)));
1447 -- Construct the call to the original entry. The call will be gradually
1448 -- augmented with an optional entry index and extra parameters.
1451 Make_Selected_Component
(Loc
,
1452 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
1453 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1455 -- When creating a wrapper for an entry family, the second formal is the
1458 if Ekind
(E
) = E_Entry_Family
then
1459 Index_Id
:= Make_Defining_Identifier
(Loc
, Name_I
);
1462 Make_Parameter_Specification
(Loc
,
1463 Defining_Identifier
=> Index_Id
,
1465 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
1467 -- The call to the original entry becomes an indexed component to
1468 -- accommodate the entry index.
1471 Make_Indexed_Component
(Loc
,
1473 Expressions
=> New_List
(New_Occurrence_Of
(Index_Id
, Loc
)));
1476 -- Add formal parameters to match those of the entry and build actuals
1477 -- for the entry call.
1479 Add_Matching_Formals
(Formals
, Actuals
);
1482 Make_Procedure_Call_Statement
(Loc
,
1484 Parameter_Associations
=> Actuals
);
1486 -- Add renaming declarations for the discriminants of the enclosing type
1487 -- as the various contract items may reference them.
1489 Add_Discriminant_Renamings
(Obj_Id
, Decls
);
1492 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(E
), 'E'));
1493 Set_Contract_Wrapper
(E
, Wrapper_Id
);
1494 Set_Is_Entry_Wrapper
(Wrapper_Id
);
1496 -- The wrapper body is analyzed when the enclosing type is frozen
1498 Append_Freeze_Action
(Defining_Entity
(Decl
),
1499 Make_Subprogram_Body
(Loc
,
1501 Make_Procedure_Specification
(Loc
,
1502 Defining_Unit_Name
=> Wrapper_Id
,
1503 Parameter_Specifications
=> Formals
),
1504 Declarations
=> Decls
,
1505 Handled_Statement_Sequence
=>
1506 Make_Handled_Sequence_Of_Statements
(Loc
,
1507 Statements
=> New_List
(Call
))));
1508 end Build_Contract_Wrapper
;
1510 --------------------------------
1511 -- Build_Corresponding_Record --
1512 --------------------------------
1514 function Build_Corresponding_Record
1517 Loc
: Source_Ptr
) return Node_Id
1519 Rec_Ent
: constant Entity_Id
:=
1520 Make_Defining_Identifier
1521 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1524 New_Disc
: Entity_Id
;
1528 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1529 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1530 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1531 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1532 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1533 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1536 -- Use discriminals to create list of discriminants for record, and
1537 -- create new discriminals for use in default expressions, etc. It is
1538 -- worth noting that a task discriminant gives rise to 5 entities;
1540 -- a) The original discriminant.
1541 -- b) The discriminal for use in the task.
1542 -- c) The discriminant of the corresponding record.
1543 -- d) The discriminal for the init proc of the corresponding record.
1544 -- e) The local variable that renames the discriminant in the procedure
1545 -- for the task body.
1547 -- In fact the discriminals b) are used in the renaming declarations
1548 -- for e). See details in einfo (Handling of Discriminants).
1550 if Present
(Discriminant_Specifications
(N
)) then
1552 Disc
:= First_Discriminant
(Ctyp
);
1554 while Present
(Disc
) loop
1555 New_Disc
:= CR_Discriminant
(Disc
);
1558 Make_Discriminant_Specification
(Loc
,
1559 Defining_Identifier
=> New_Disc
,
1560 Discriminant_Type
=>
1561 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1563 New_Copy
(Discriminant_Default_Value
(Disc
))));
1565 Next_Discriminant
(Disc
);
1572 -- Now we can construct the record type declaration. Note that this
1573 -- record is "limited tagged". It is "limited" to reflect the underlying
1574 -- limitedness of the task or protected object that it represents, and
1575 -- ensuring for example that it is properly passed by reference. It is
1576 -- "tagged" to give support to dispatching calls through interfaces. We
1577 -- propagate here the list of interfaces covered by the concurrent type
1578 -- (Ada 2005: AI-345).
1581 Make_Full_Type_Declaration
(Loc
,
1582 Defining_Identifier
=> Rec_Ent
,
1583 Discriminant_Specifications
=> Dlist
,
1585 Make_Record_Definition
(Loc
,
1587 Make_Component_List
(Loc
, Component_Items
=> Cdecls
),
1589 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1590 Interface_List
=> Interface_List
(N
),
1591 Limited_Present
=> True));
1592 end Build_Corresponding_Record
;
1594 ---------------------------------
1595 -- Build_Dispatching_Tag_Check --
1596 ---------------------------------
1598 function Build_Dispatching_Tag_Check
1600 N
: Node_Id
) return Node_Id
1602 Loc
: constant Source_Ptr
:= Sloc
(N
);
1609 New_Occurrence_Of
(K
, Loc
),
1611 New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1615 New_Occurrence_Of
(K
, Loc
),
1617 New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
)));
1618 end Build_Dispatching_Tag_Check
;
1620 ----------------------------------
1621 -- Build_Entry_Count_Expression --
1622 ----------------------------------
1624 function Build_Entry_Count_Expression
1625 (Concurrent_Type
: Node_Id
;
1626 Component_List
: List_Id
;
1627 Loc
: Source_Ptr
) return Node_Id
1639 -- Count number of non-family entries
1642 Ent
:= First_Entity
(Concurrent_Type
);
1643 while Present
(Ent
) loop
1644 if Ekind
(Ent
) = E_Entry
then
1651 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1653 -- Loop through entry families building the addition nodes
1655 Ent
:= First_Entity
(Concurrent_Type
);
1656 Comp
:= First
(Component_List
);
1657 while Present
(Ent
) loop
1658 if Ekind
(Ent
) = E_Entry_Family
then
1659 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1663 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1664 Hi
:= Type_High_Bound
(Typ
);
1665 Lo
:= Type_Low_Bound
(Typ
);
1666 Large
:= Is_Potentially_Large_Family
1667 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1670 Left_Opnd
=> Ecount
,
1672 Family_Size
(Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1679 end Build_Entry_Count_Expression
;
1681 ---------------------------
1682 -- Build_Parameter_Block --
1683 ---------------------------
1685 function Build_Parameter_Block
1689 Decls
: List_Id
) return Entity_Id
1695 Has_Comp
: Boolean := False;
1699 Actual
:= First
(Actuals
);
1701 Formal
:= Defining_Identifier
(First
(Formals
));
1703 while Present
(Actual
) loop
1704 if not Is_Controlling_Actual
(Actual
) then
1707 -- type Ann is access all <actual-type>
1709 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1710 Set_Is_Param_Block_Component_Type
(Comp_Nam
);
1713 Make_Full_Type_Declaration
(Loc
,
1714 Defining_Identifier
=> Comp_Nam
,
1716 Make_Access_To_Object_Definition
(Loc
,
1717 All_Present
=> True,
1718 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1719 Subtype_Indication
=>
1720 New_Occurrence_Of
(Etype
(Actual
), Loc
))));
1726 Make_Component_Declaration
(Loc
,
1727 Defining_Identifier
=>
1728 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1729 Component_Definition
=>
1730 Make_Component_Definition
(Loc
,
1733 Subtype_Indication
=>
1734 New_Occurrence_Of
(Comp_Nam
, Loc
))));
1739 Next_Actual
(Actual
);
1740 Next_Formal_With_Extras
(Formal
);
1743 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1748 -- type Pnn is record
1753 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1754 -- the original parameter names and Ann1 .. AnnN are the access to
1758 Make_Full_Type_Declaration
(Loc
,
1759 Defining_Identifier
=>
1762 Make_Record_Definition
(Loc
,
1764 Make_Component_List
(Loc
, Comps
))));
1767 -- type Pnn is null record;
1770 Make_Full_Type_Declaration
(Loc
,
1771 Defining_Identifier
=>
1774 Make_Record_Definition
(Loc
,
1775 Null_Present
=> True,
1776 Component_List
=> Empty
)));
1780 end Build_Parameter_Block
;
1782 --------------------------------------
1783 -- Build_Renamed_Formal_Declaration --
1784 --------------------------------------
1786 function Build_Renamed_Formal_Declaration
1790 Renamed_Formal
: Node_Id
) return Node_Id
1792 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1796 -- If the formal is a tagged incomplete type, it is already passed
1797 -- by reference, so it is sufficient to rename the pointer component
1798 -- that corresponds to the actual. Otherwise we need to dereference
1799 -- the pointer component to obtain the actual.
1801 if Is_Incomplete_Type
(Etype
(Formal
))
1802 and then Is_Tagged_Type
(Etype
(Formal
))
1805 Make_Object_Renaming_Declaration
(Loc
,
1806 Defining_Identifier
=> New_F
,
1807 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Comp
), Loc
),
1808 Name
=> Renamed_Formal
);
1812 Make_Object_Renaming_Declaration
(Loc
,
1813 Defining_Identifier
=> New_F
,
1814 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Formal
), Loc
),
1816 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1820 end Build_Renamed_Formal_Declaration
;
1822 --------------------------
1823 -- Build_Wrapper_Bodies --
1824 --------------------------
1826 procedure Build_Wrapper_Bodies
1831 Rec_Typ
: Entity_Id
;
1833 function Build_Wrapper_Body
1835 Subp_Id
: Entity_Id
;
1836 Obj_Typ
: Entity_Id
;
1837 Formals
: List_Id
) return Node_Id
;
1838 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1839 -- associated with a protected or task type. Subp_Id is the subprogram
1840 -- name which will be wrapped. Obj_Typ is the type of the new formal
1841 -- parameter which handles dispatching and object notation. Formals are
1842 -- the original formals of Subp_Id which will be explicitly replicated.
1844 ------------------------
1845 -- Build_Wrapper_Body --
1846 ------------------------
1848 function Build_Wrapper_Body
1850 Subp_Id
: Entity_Id
;
1851 Obj_Typ
: Entity_Id
;
1852 Formals
: List_Id
) return Node_Id
1854 Body_Spec
: Node_Id
;
1857 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
1859 -- The subprogram is not overriding or is not a primitive declared
1860 -- between two views.
1862 if No
(Body_Spec
) then
1867 Actuals
: List_Id
:= No_List
;
1869 First_Form
: Node_Id
;
1874 -- Map formals to actuals. Use the list built for the wrapper
1875 -- spec, skipping the object notation parameter.
1877 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
1879 Formal
:= First_Form
;
1882 if Present
(Formal
) then
1883 Actuals
:= New_List
;
1884 while Present
(Formal
) loop
1886 Make_Identifier
(Loc
,
1887 Chars
=> Chars
(Defining_Identifier
(Formal
))));
1892 -- Special processing for primitives declared between a private
1893 -- type and its completion: the wrapper needs a properly typed
1894 -- parameter if the wrapped operation has a controlling first
1895 -- parameter. Note that this might not be the case for a function
1896 -- with a controlling result.
1898 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
1899 if No
(Actuals
) then
1900 Actuals
:= New_List
;
1903 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
1904 Prepend_To
(Actuals
,
1905 Unchecked_Convert_To
1906 (Corresponding_Concurrent_Type
(Obj_Typ
),
1907 Make_Identifier
(Loc
, Name_uO
)));
1910 Prepend_To
(Actuals
,
1911 Make_Identifier
(Loc
,
1912 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
1915 Nam
:= New_Occurrence_Of
(Subp_Id
, Loc
);
1917 -- An access-to-variable object parameter requires an explicit
1918 -- dereference in the unchecked conversion. This case occurs
1919 -- when a protected entry wrapper must override an interface
1920 -- level procedure with interface access as first parameter.
1922 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1924 if Nkind
(Parameter_Type
(First_Form
)) =
1928 Make_Explicit_Dereference
(Loc
,
1929 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
1931 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
1935 Make_Selected_Component
(Loc
,
1937 Unchecked_Convert_To
1938 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
1939 Selector_Name
=> New_Occurrence_Of
(Subp_Id
, Loc
));
1942 -- Create the subprogram body. For a function, the call to the
1943 -- actual subprogram has to be converted to the corresponding
1944 -- record if it is a controlling result.
1946 if Ekind
(Subp_Id
) = E_Function
then
1952 Make_Function_Call
(Loc
,
1954 Parameter_Associations
=> Actuals
);
1956 if Has_Controlling_Result
(Subp_Id
) then
1958 Unchecked_Convert_To
1959 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
1963 Make_Subprogram_Body
(Loc
,
1964 Specification
=> Body_Spec
,
1965 Declarations
=> Empty_List
,
1966 Handled_Statement_Sequence
=>
1967 Make_Handled_Sequence_Of_Statements
(Loc
,
1968 Statements
=> New_List
(
1969 Make_Simple_Return_Statement
(Loc
, Res
))));
1974 Make_Subprogram_Body
(Loc
,
1975 Specification
=> Body_Spec
,
1976 Declarations
=> Empty_List
,
1977 Handled_Statement_Sequence
=>
1978 Make_Handled_Sequence_Of_Statements
(Loc
,
1979 Statements
=> New_List
(
1980 Make_Procedure_Call_Statement
(Loc
,
1982 Parameter_Associations
=> Actuals
))));
1985 end Build_Wrapper_Body
;
1987 -- Start of processing for Build_Wrapper_Bodies
1990 if Is_Concurrent_Type
(Typ
) then
1991 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
1996 -- Generate wrapper bodies for a concurrent type which implements an
1999 if Present
(Interfaces
(Rec_Typ
)) then
2001 Insert_Nod
: Node_Id
;
2003 Prim_Elmt
: Elmt_Id
;
2004 Prim_Decl
: Node_Id
;
2006 Wrap_Body
: Node_Id
;
2007 Wrap_Id
: Entity_Id
;
2012 -- Examine all primitive operations of the corresponding record
2013 -- type, looking for wrapper specs. Generate bodies in order to
2016 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2017 while Present
(Prim_Elmt
) loop
2018 Prim
:= Node
(Prim_Elmt
);
2020 if (Ekind
(Prim
) = E_Function
2021 or else Ekind
(Prim
) = E_Procedure
)
2022 and then Is_Primitive_Wrapper
(Prim
)
2024 Subp
:= Wrapped_Entity
(Prim
);
2025 Prim_Decl
:= Parent
(Parent
(Prim
));
2028 Build_Wrapper_Body
(Loc
,
2031 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2032 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2034 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2035 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2037 Insert_After
(Insert_Nod
, Wrap_Body
);
2038 Insert_Nod
:= Wrap_Body
;
2040 Analyze
(Wrap_Body
);
2043 Next_Elmt
(Prim_Elmt
);
2047 end Build_Wrapper_Bodies
;
2049 ------------------------
2050 -- Build_Wrapper_Spec --
2051 ------------------------
2053 function Build_Wrapper_Spec
2054 (Subp_Id
: Entity_Id
;
2055 Obj_Typ
: Entity_Id
;
2056 Formals
: List_Id
) return Node_Id
2058 function Overriding_Possible
2059 (Iface_Op
: Entity_Id
;
2060 Wrapper
: Entity_Id
) return Boolean;
2061 -- Determine whether a primitive operation can be overridden by Wrapper.
2062 -- Iface_Op is the candidate primitive operation of an interface type,
2063 -- Wrapper is the generated entry wrapper.
2065 function Replicate_Formals
2067 Formals
: List_Id
) return List_Id
;
2068 -- An explicit parameter replication is required due to the Is_Entry_
2069 -- Formal flag being set for all the formals of an entry. The explicit
2070 -- replication removes the flag that would otherwise cause a different
2071 -- path of analysis.
2073 -------------------------
2074 -- Overriding_Possible --
2075 -------------------------
2077 function Overriding_Possible
2078 (Iface_Op
: Entity_Id
;
2079 Wrapper
: Entity_Id
) return Boolean
2081 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2082 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2084 function Type_Conformant_Parameters
2085 (Iface_Op_Params
: List_Id
;
2086 Wrapper_Params
: List_Id
) return Boolean;
2087 -- Determine whether the parameters of the generated entry wrapper
2088 -- and those of a primitive operation are type conformant. During
2089 -- this check, the first parameter of the primitive operation is
2090 -- skipped if it is a controlling argument: protected functions
2091 -- may have a controlling result.
2093 --------------------------------
2094 -- Type_Conformant_Parameters --
2095 --------------------------------
2097 function Type_Conformant_Parameters
2098 (Iface_Op_Params
: List_Id
;
2099 Wrapper_Params
: List_Id
) return Boolean
2101 Iface_Op_Param
: Node_Id
;
2102 Iface_Op_Typ
: Entity_Id
;
2103 Wrapper_Param
: Node_Id
;
2104 Wrapper_Typ
: Entity_Id
;
2107 -- Skip the first (controlling) parameter of primitive operation
2109 Iface_Op_Param
:= First
(Iface_Op_Params
);
2111 if Present
(First_Formal
(Iface_Op
))
2112 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2114 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2117 Wrapper_Param
:= First
(Wrapper_Params
);
2118 while Present
(Iface_Op_Param
)
2119 and then Present
(Wrapper_Param
)
2121 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2122 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2124 -- The two parameters must be mode conformant
2126 if not Conforming_Types
2127 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2132 Next
(Iface_Op_Param
);
2133 Next
(Wrapper_Param
);
2136 -- One of the lists is longer than the other
2138 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2143 end Type_Conformant_Parameters
;
2145 -- Start of processing for Overriding_Possible
2148 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2152 -- If an inherited subprogram is implemented by a protected procedure
2153 -- or an entry, then the first parameter of the inherited subprogram
2154 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2156 if Ekind
(Iface_Op
) = E_Procedure
2157 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2160 Obj_Param
: constant Node_Id
:=
2161 First
(Parameter_Specifications
(Iface_Op_Spec
));
2163 if not Out_Present
(Obj_Param
)
2164 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2173 Type_Conformant_Parameters
2174 (Parameter_Specifications
(Iface_Op_Spec
),
2175 Parameter_Specifications
(Wrapper_Spec
));
2176 end Overriding_Possible
;
2178 -----------------------
2179 -- Replicate_Formals --
2180 -----------------------
2182 function Replicate_Formals
2184 Formals
: List_Id
) return List_Id
2186 New_Formals
: constant List_Id
:= New_List
;
2188 Param_Type
: Node_Id
;
2191 Formal
:= First
(Formals
);
2193 -- Skip the object parameter when dealing with primitives declared
2194 -- between two views.
2196 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2197 and then not Has_Controlling_Result
(Subp_Id
)
2199 Formal
:= Next
(Formal
);
2202 while Present
(Formal
) loop
2204 -- Create an explicit copy of the entry parameter
2206 -- When creating the wrapper subprogram for a primitive operation
2207 -- of a protected interface we must construct an equivalent
2208 -- signature to that of the overriding operation. For regular
2209 -- parameters we can just use the type of the formal, but for
2210 -- access to subprogram parameters we need to reanalyze the
2211 -- parameter type to create local entities for the signature of
2212 -- the subprogram type. Using the entities of the overriding
2213 -- subprogram will result in out-of-scope errors in the back-end.
2215 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2216 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2219 New_Occurrence_Of
(Etype
(Parameter_Type
(Formal
)), Loc
);
2222 Append_To
(New_Formals
,
2223 Make_Parameter_Specification
(Loc
,
2224 Defining_Identifier
=>
2225 Make_Defining_Identifier
(Loc
,
2226 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2227 In_Present
=> In_Present
(Formal
),
2228 Out_Present
=> Out_Present
(Formal
),
2229 Null_Exclusion_Present
=> Null_Exclusion_Present
(Formal
),
2230 Parameter_Type
=> Param_Type
));
2236 end Replicate_Formals
;
2240 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2241 First_Param
: Node_Id
:= Empty
;
2243 Iface_Elmt
: Elmt_Id
;
2244 Iface_Op
: Entity_Id
;
2245 Iface_Op_Elmt
: Elmt_Id
;
2246 Overridden_Subp
: Entity_Id
;
2248 -- Start of processing for Build_Wrapper_Spec
2251 -- No point in building wrappers for untagged concurrent types
2253 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2255 -- Check if this subprogram has a profile that matches some interface
2258 Check_Synchronized_Overriding
(Subp_Id
, Overridden_Subp
);
2260 if Present
(Overridden_Subp
) then
2262 First
(Parameter_Specifications
(Parent
(Overridden_Subp
)));
2264 -- An entry or a protected procedure can override a routine where the
2265 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2266 -- type. Since the wrapper must have the exact same signature as that of
2267 -- the overridden subprogram, we try to find the overriding candidate
2268 -- and use its controlling formal.
2270 -- Check every implemented interface
2272 elsif Present
(Interfaces
(Obj_Typ
)) then
2273 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2274 Search
: while Present
(Iface_Elmt
) loop
2275 Iface
:= Node
(Iface_Elmt
);
2277 -- Check every interface primitive
2279 if Present
(Primitive_Operations
(Iface
)) then
2280 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2281 while Present
(Iface_Op_Elmt
) loop
2282 Iface_Op
:= Node
(Iface_Op_Elmt
);
2284 -- Ignore predefined primitives
2286 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2287 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2289 -- The current primitive operation can be overridden by
2290 -- the generated entry wrapper.
2292 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2294 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2300 Next_Elmt
(Iface_Op_Elmt
);
2304 Next_Elmt
(Iface_Elmt
);
2308 -- Do not generate the wrapper if no interface primitive is covered by
2309 -- the subprogram and it is not a primitive declared between two views
2310 -- (see Process_Full_View).
2313 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2319 Wrapper_Id
: constant Entity_Id
:=
2320 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2321 New_Formals
: List_Id
;
2322 Obj_Param
: Node_Id
;
2323 Obj_Param_Typ
: Entity_Id
;
2326 -- Minimum decoration is needed to catch the entity in
2327 -- Sem_Ch6.Override_Dispatching_Operation.
2329 if Ekind
(Subp_Id
) = E_Function
then
2330 Set_Ekind
(Wrapper_Id
, E_Function
);
2332 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2335 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2336 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2337 Set_Is_Private_Primitive
(Wrapper_Id
,
2338 Is_Private_Primitive_Subprogram
(Subp_Id
));
2340 -- Process the formals
2342 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2344 -- A function with a controlling result and no first controlling
2345 -- formal needs no additional parameter.
2347 if Has_Controlling_Result
(Subp_Id
)
2349 (No
(First_Formal
(Subp_Id
))
2350 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2354 -- Routine Subp_Id has been found to override an interface primitive.
2355 -- If the interface operation has an access parameter, create a copy
2356 -- of it, with the same null exclusion indicator if present.
2358 elsif Present
(First_Param
) then
2359 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2361 Make_Access_Definition
(Loc
,
2363 New_Occurrence_Of
(Obj_Typ
, Loc
),
2364 Null_Exclusion_Present
=>
2365 Null_Exclusion_Present
(Parameter_Type
(First_Param
)),
2367 Constant_Present
(Parameter_Type
(First_Param
)));
2369 Obj_Param_Typ
:= New_Occurrence_Of
(Obj_Typ
, Loc
);
2373 Make_Parameter_Specification
(Loc
,
2374 Defining_Identifier
=>
2375 Make_Defining_Identifier
(Loc
,
2377 In_Present
=> In_Present
(First_Param
),
2378 Out_Present
=> Out_Present
(First_Param
),
2379 Parameter_Type
=> Obj_Param_Typ
);
2381 Prepend_To
(New_Formals
, Obj_Param
);
2383 -- If we are dealing with a primitive declared between two views,
2384 -- implemented by a synchronized operation, we need to create
2385 -- a default parameter. The mode of the parameter must match that
2386 -- of the primitive operation.
2389 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2392 Make_Parameter_Specification
(Loc
,
2393 Defining_Identifier
=>
2394 Make_Defining_Identifier
(Loc
, Name_uO
),
2396 In_Present
(Parent
(First_Entity
(Subp_Id
))),
2397 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2398 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2400 Prepend_To
(New_Formals
, Obj_Param
);
2403 -- Build the final spec. If it is a function with a controlling
2404 -- result, it is a primitive operation of the corresponding
2405 -- record type, so mark the spec accordingly.
2407 if Ekind
(Subp_Id
) = E_Function
then
2412 if Has_Controlling_Result
(Subp_Id
) then
2415 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2417 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2421 Make_Function_Specification
(Loc
,
2422 Defining_Unit_Name
=> Wrapper_Id
,
2423 Parameter_Specifications
=> New_Formals
,
2424 Result_Definition
=> Res_Def
);
2428 Make_Procedure_Specification
(Loc
,
2429 Defining_Unit_Name
=> Wrapper_Id
,
2430 Parameter_Specifications
=> New_Formals
);
2433 end Build_Wrapper_Spec
;
2435 -------------------------
2436 -- Build_Wrapper_Specs --
2437 -------------------------
2439 procedure Build_Wrapper_Specs
2445 Rec_Typ
: Entity_Id
;
2446 procedure Scan_Declarations
(L
: List_Id
);
2447 -- Common processing for visible and private declarations
2448 -- of a protected type.
2450 procedure Scan_Declarations
(L
: List_Id
) is
2452 Wrap_Decl
: Node_Id
;
2453 Wrap_Spec
: Node_Id
;
2461 while Present
(Decl
) loop
2464 if Nkind
(Decl
) = N_Entry_Declaration
2465 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2469 (Subp_Id
=> Defining_Identifier
(Decl
),
2471 Formals
=> Parameter_Specifications
(Decl
));
2473 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2476 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2479 Parameter_Specifications
(Specification
(Decl
)));
2482 if Present
(Wrap_Spec
) then
2484 Make_Subprogram_Declaration
(Loc
,
2485 Specification
=> Wrap_Spec
);
2487 Insert_After
(N
, Wrap_Decl
);
2490 Analyze
(Wrap_Decl
);
2495 end Scan_Declarations
;
2497 -- start of processing for Build_Wrapper_Specs
2500 if Is_Protected_Type
(Typ
) then
2501 Def
:= Protected_Definition
(Parent
(Typ
));
2502 else pragma Assert
(Is_Task_Type
(Typ
));
2503 Def
:= Task_Definition
(Parent
(Typ
));
2506 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2508 -- Generate wrapper specs for a concurrent type which implements an
2509 -- interface. Operations in both the visible and private parts may
2510 -- implement progenitor operations.
2512 if Present
(Interfaces
(Rec_Typ
)) and then Present
(Def
) then
2513 Scan_Declarations
(Visible_Declarations
(Def
));
2514 Scan_Declarations
(Private_Declarations
(Def
));
2516 end Build_Wrapper_Specs
;
2518 ---------------------------
2519 -- Build_Find_Body_Index --
2520 ---------------------------
2522 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2523 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2526 Has_F
: Boolean := False;
2528 If_St
: Node_Id
:= Empty
;
2531 Decls
: List_Id
:= New_List
;
2534 Siz
: Node_Id
:= Empty
;
2536 procedure Add_If_Clause
(Expr
: Node_Id
);
2537 -- Add test for range of current entry
2539 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2540 -- If a bound of an entry is given by a discriminant, retrieve the
2541 -- actual value of the discriminant from the enclosing object.
2547 procedure Add_If_Clause
(Expr
: Node_Id
) is
2549 Stats
: constant List_Id
:=
2551 Make_Simple_Return_Statement
(Loc
,
2552 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2555 -- Index for current entry body
2559 -- Compute total length of entry queues so far
2567 Right_Opnd
=> Expr
);
2572 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2575 -- Map entry queue indexes in the range of the current family
2576 -- into the current index, that designates the entry body.
2580 Make_Implicit_If_Statement
(Typ
,
2582 Then_Statements
=> Stats
,
2583 Elsif_Parts
=> New_List
);
2587 Append_To
(Elsif_Parts
(If_St
),
2588 Make_Elsif_Part
(Loc
,
2590 Then_Statements
=> Stats
));
2594 ------------------------------
2595 -- Convert_Discriminant_Ref --
2596 ------------------------------
2598 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2602 if Is_Entity_Name
(Bound
)
2603 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2606 Make_Selected_Component
(Loc
,
2608 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2609 Make_Explicit_Dereference
(Loc
,
2610 Make_Identifier
(Loc
, Name_uObject
))),
2611 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2612 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2614 B
:= New_Copy_Tree
(Bound
);
2618 end Convert_Discriminant_Ref
;
2620 -- Start of processing for Build_Find_Body_Index
2623 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2625 Ent
:= First_Entity
(Typ
);
2626 while Present
(Ent
) loop
2627 if Ekind
(Ent
) = E_Entry_Family
then
2637 -- If the protected type has no entry families, there is a one-one
2638 -- correspondence between entry queue and entry body.
2641 Make_Simple_Return_Statement
(Loc
,
2642 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2645 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2648 -- if E <= l1 then return 1;
2649 -- elsif E <= l1 + l2 then return 2;
2654 Ent
:= First_Entity
(Typ
);
2656 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2658 while Present
(Ent
) loop
2659 if Ekind
(Ent
) = E_Entry
then
2660 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2662 elsif Ekind
(Ent
) = E_Entry_Family
then
2663 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2664 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2665 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2666 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2675 Make_Simple_Return_Statement
(Loc
,
2676 Expression
=> Make_Integer_Literal
(Loc
, 1));
2678 elsif Nkind
(Ret
) = N_If_Statement
then
2680 -- Ranges are in increasing order, so last one doesn't need guard
2683 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2686 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2692 Make_Subprogram_Body
(Loc
,
2693 Specification
=> Spec
,
2694 Declarations
=> Decls
,
2695 Handled_Statement_Sequence
=>
2696 Make_Handled_Sequence_Of_Statements
(Loc
,
2697 Statements
=> New_List
(Ret
)));
2698 end Build_Find_Body_Index
;
2700 --------------------------------
2701 -- Build_Find_Body_Index_Spec --
2702 --------------------------------
2704 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2705 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2706 Id
: constant Entity_Id
:=
2707 Make_Defining_Identifier
(Loc
,
2708 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2709 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2710 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2714 Make_Function_Specification
(Loc
,
2715 Defining_Unit_Name
=> Id
,
2716 Parameter_Specifications
=> New_List
(
2717 Make_Parameter_Specification
(Loc
,
2718 Defining_Identifier
=> Parm1
,
2720 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2722 Make_Parameter_Specification
(Loc
,
2723 Defining_Identifier
=> Parm2
,
2725 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2727 Result_Definition
=> New_Occurrence_Of
(
2728 RTE
(RE_Protected_Entry_Index
), Loc
));
2729 end Build_Find_Body_Index_Spec
;
2731 -----------------------------------------------
2732 -- Build_Lock_Free_Protected_Subprogram_Body --
2733 -----------------------------------------------
2735 function Build_Lock_Free_Protected_Subprogram_Body
2738 Unprot_Spec
: Node_Id
) return Node_Id
2740 Actuals
: constant List_Id
:= New_List
;
2741 Loc
: constant Source_Ptr
:= Sloc
(N
);
2742 Spec
: constant Node_Id
:= Specification
(N
);
2743 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
2745 Prot_Spec
: Node_Id
;
2749 -- Create the protected version of the body
2752 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
2754 -- Build the actual parameters which appear in the call to the
2755 -- unprotected version of the body.
2757 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
2758 while Present
(Formal
) loop
2760 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
2765 -- Function case, generate:
2766 -- return <Unprot_Func_Call>;
2768 if Nkind
(Spec
) = N_Function_Specification
then
2770 Make_Simple_Return_Statement
(Loc
,
2772 Make_Function_Call
(Loc
,
2774 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2775 Parameter_Associations
=> Actuals
));
2777 -- Procedure case, call the unprotected version
2781 Make_Procedure_Call_Statement
(Loc
,
2783 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2784 Parameter_Associations
=> Actuals
);
2788 Make_Subprogram_Body
(Loc
,
2789 Declarations
=> Empty_List
,
2790 Specification
=> Prot_Spec
,
2791 Handled_Statement_Sequence
=>
2792 Make_Handled_Sequence_Of_Statements
(Loc
,
2793 Statements
=> New_List
(Stmt
)));
2794 end Build_Lock_Free_Protected_Subprogram_Body
;
2796 -------------------------------------------------
2797 -- Build_Lock_Free_Unprotected_Subprogram_Body --
2798 -------------------------------------------------
2800 -- Procedures which meet the lock-free implementation requirements and
2801 -- reference a unique scalar component Comp are expanded in the following
2804 -- procedure P (...) is
2805 -- Expected_Comp : constant Comp_Type :=
2807 -- (System.Atomic_Primitives.Lock_Free_Read_N
2808 -- (_Object.Comp'Address));
2812 -- <original declarations before the object renaming declaration
2815 -- Desired_Comp : Comp_Type := Expected_Comp;
2816 -- Comp : Comp_Type renames Desired_Comp;
2818 -- <original delarations after the object renaming declaration
2822 -- <original statements>
2823 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
2824 -- (_Object.Comp'Address,
2825 -- Interfaces.Unsigned_N (Expected_Comp),
2826 -- Interfaces.Unsigned_N (Desired_Comp));
2831 -- Each return and raise statement of P is transformed into an atomic
2834 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2835 -- (_Object.Comp'Address,
2836 -- Interfaces.Unsigned_N (Expected_Comp),
2837 -- Interfaces.Unsigned_N (Desired_Comp));
2839 -- <original statement>
2844 -- Functions which meet the lock-free implementation requirements and
2845 -- reference a unique scalar component Comp are expanded in the following
2848 -- function F (...) return ... is
2849 -- <original declarations before the object renaming declaration
2852 -- Expected_Comp : constant Comp_Type :=
2854 -- (System.Atomic_Primitives.Lock_Free_Read_N
2855 -- (_Object.Comp'Address));
2856 -- Comp : Comp_Type renames Expected_Comp;
2858 -- <original delarations after the object renaming declaration of
2862 -- <original statements>
2865 function Build_Lock_Free_Unprotected_Subprogram_Body
2867 Prot_Typ
: Node_Id
) return Node_Id
2869 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
2870 -- Subprograms which meet the lock-free implementation criteria are
2871 -- allowed to reference only one unique component. Return the prival
2872 -- of the said component.
2874 --------------------------
2875 -- Referenced_Component --
2876 --------------------------
2878 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
2881 Source_Comp
: Entity_Id
:= Empty
;
2884 -- Find the unique source component which N references in its
2887 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
2889 Element
: Lock_Free_Subprogram
renames
2890 Lock_Free_Subprogram_Table
.Table
(Index
);
2892 if Element
.Sub_Body
= N
then
2893 Source_Comp
:= Element
.Comp_Id
;
2899 if No
(Source_Comp
) then
2903 -- Find the prival which corresponds to the source component within
2904 -- the declarations of N.
2906 Decl
:= First
(Declarations
(N
));
2907 while Present
(Decl
) loop
2909 -- Privals appear as object renamings
2911 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
2912 Comp
:= Defining_Identifier
(Decl
);
2914 if Present
(Prival_Link
(Comp
))
2915 and then Prival_Link
(Comp
) = Source_Comp
2925 end Referenced_Component
;
2929 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
2930 Loc
: constant Source_Ptr
:= Sloc
(N
);
2931 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
2932 Decls
: List_Id
:= Declarations
(N
);
2934 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
2937 -- Add renamings for the protection object, discriminals, privals, and
2938 -- the entry index constant for use by debugger.
2940 Debug_Private_Data_Declarations
(Decls
);
2942 -- Perform the lock-free expansion when the subprogram references a
2943 -- protected component.
2945 if Present
(Comp
) then
2946 Protected_Component_Ref
: declare
2947 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
2948 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
2949 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
2951 Is_Procedure
: constant Boolean :=
2952 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
2953 -- Indicates if N is a protected procedure body
2955 Block_Decls
: List_Id
:= No_List
;
2956 Try_Write
: Entity_Id
;
2957 Desired_Comp
: Entity_Id
;
2960 Label_Id
: Entity_Id
:= Empty
;
2962 Expected_Comp
: Entity_Id
;
2965 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
2967 Unsigned
: Entity_Id
;
2969 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
2970 -- Transform a single node if it is a return statement, a raise
2971 -- statement or a reference to Comp.
2973 procedure Process_Stmts
(Stmts
: List_Id
);
2974 -- Given a statement sequence Stmts, wrap any return or raise
2975 -- statements in the following manner:
2977 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2978 -- (_Object.Comp'Address,
2979 -- Interfaces.Unsigned_N (Expected_Comp),
2980 -- Interfaces.Unsigned_N (Desired_Comp))
2991 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
2993 procedure Wrap_Statement
(Stmt
: Node_Id
);
2994 -- Wrap an arbitrary statement inside an if statement where the
2995 -- condition does an atomic check on the state of the object.
2997 --------------------
2998 -- Wrap_Statement --
2999 --------------------
3001 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3003 -- The first time through, create the declaration of a label
3004 -- which is used to skip the remainder of source statements
3005 -- if the state of the object has changed.
3007 if No
(Label_Id
) then
3009 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3010 Set_Entity
(Label_Id
,
3011 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3015 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3016 -- (_Object.Comp'Address,
3017 -- Interfaces.Unsigned_N (Expected_Comp),
3018 -- Interfaces.Unsigned_N (Desired_Comp))
3026 Make_Implicit_If_Statement
(N
,
3028 Make_Function_Call
(Loc
,
3030 New_Occurrence_Of
(Try_Write
, Loc
),
3031 Parameter_Associations
=> New_List
(
3032 Make_Attribute_Reference
(Loc
,
3033 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3034 Attribute_Name
=> Name_Address
),
3036 Unchecked_Convert_To
(Unsigned
,
3037 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3039 Unchecked_Convert_To
(Unsigned
,
3040 New_Occurrence_Of
(Desired_Comp
, Loc
)))),
3042 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3044 Else_Statements
=> New_List
(
3045 Make_Goto_Statement
(Loc
,
3047 New_Occurrence_Of
(Entity
(Label_Id
), Loc
)))));
3050 -- Start of processing for Process_Node
3053 -- Wrap each return and raise statement that appear inside a
3054 -- procedure. Skip the last return statement which is added by
3055 -- default since it is transformed into an exit statement.
3058 and then ((Nkind
(N
) = N_Simple_Return_Statement
3059 and then N
/= Last
(Stmts
))
3060 or else Nkind
(N
) = N_Extended_Return_Statement
3061 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3062 N_Raise_Program_Error
,
3064 N_Raise_Storage_Error
)
3065 and then Comes_From_Source
(N
)))
3073 Set_Analyzed
(N
, False);
3078 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3084 procedure Process_Stmts
(Stmts
: List_Id
) is
3087 Stmt
:= First
(Stmts
);
3088 while Present
(Stmt
) loop
3089 Process_Nodes
(Stmt
);
3094 -- Start of processing for Protected_Component_Ref
3097 -- Get the type size
3099 if Known_Static_Esize
(Comp_Type
) then
3100 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3102 -- If the Esize (Object_Size) is unknown at compile time, look at
3103 -- the RM_Size (Value_Size) since it may have been set by an
3104 -- explicit representation clause.
3106 elsif Known_Static_RM_Size
(Comp_Type
) then
3107 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3109 -- Should not happen since this has already been checked in
3110 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3113 raise Program_Error
;
3116 -- Retrieve all relevant atomic routines and types
3120 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3121 Read
:= RTE
(RE_Lock_Free_Read_8
);
3122 Unsigned
:= RTE
(RE_Uint8
);
3125 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3126 Read
:= RTE
(RE_Lock_Free_Read_16
);
3127 Unsigned
:= RTE
(RE_Uint16
);
3130 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3131 Read
:= RTE
(RE_Lock_Free_Read_32
);
3132 Unsigned
:= RTE
(RE_Uint32
);
3135 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3136 Read
:= RTE
(RE_Lock_Free_Read_64
);
3137 Unsigned
:= RTE
(RE_Uint64
);
3140 raise Program_Error
;
3144 -- Expected_Comp : constant Comp_Type :=
3146 -- (System.Atomic_Primitives.Lock_Free_Read_N
3147 -- (_Object.Comp'Address));
3150 Make_Defining_Identifier
(Loc
,
3151 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3154 Make_Object_Declaration
(Loc
,
3155 Defining_Identifier
=> Expected_Comp
,
3156 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3157 Constant_Present
=> True,
3159 Unchecked_Convert_To
(Comp_Type
,
3160 Make_Function_Call
(Loc
,
3161 Name
=> New_Occurrence_Of
(Read
, Loc
),
3162 Parameter_Associations
=> New_List
(
3163 Make_Attribute_Reference
(Loc
,
3164 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3165 Attribute_Name
=> Name_Address
)))));
3167 -- Protected procedures
3169 if Is_Procedure
then
3170 -- Move the original declarations inside the generated block
3172 Block_Decls
:= Decls
;
3174 -- Reset the declarations list of the protected procedure to
3175 -- contain only Decl.
3177 Decls
:= New_List
(Decl
);
3180 -- Desired_Comp : Comp_Type := Expected_Comp;
3183 Make_Defining_Identifier
(Loc
,
3184 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3186 -- Insert the declarations of Expected_Comp and Desired_Comp in
3187 -- the block declarations right before the renaming of the
3188 -- protected component.
3190 Insert_Before
(Comp_Decl
,
3191 Make_Object_Declaration
(Loc
,
3192 Defining_Identifier
=> Desired_Comp
,
3193 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3195 New_Occurrence_Of
(Expected_Comp
, Loc
)));
3197 -- Protected function
3200 Desired_Comp
:= Expected_Comp
;
3202 -- Insert the declaration of Expected_Comp in the function
3203 -- declarations right before the renaming of the protected
3206 Insert_Before
(Comp_Decl
, Decl
);
3209 -- Rewrite the protected component renaming declaration to be a
3210 -- renaming of Desired_Comp.
3213 -- Comp : Comp_Type renames Desired_Comp;
3216 Make_Object_Renaming_Declaration
(Loc
,
3217 Defining_Identifier
=>
3218 Defining_Identifier
(Comp_Decl
),
3220 New_Occurrence_Of
(Comp_Type
, Loc
),
3222 New_Occurrence_Of
(Desired_Comp
, Loc
)));
3224 -- Wrap any return or raise statements in Stmts in same the manner
3225 -- described in Process_Stmts.
3227 Process_Stmts
(Stmts
);
3230 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3231 -- (_Object.Comp'Address,
3232 -- Interfaces.Unsigned_N (Expected_Comp),
3233 -- Interfaces.Unsigned_N (Desired_Comp))
3235 if Is_Procedure
then
3237 Make_Exit_Statement
(Loc
,
3239 Make_Function_Call
(Loc
,
3241 New_Occurrence_Of
(Try_Write
, Loc
),
3242 Parameter_Associations
=> New_List
(
3243 Make_Attribute_Reference
(Loc
,
3244 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3245 Attribute_Name
=> Name_Address
),
3247 Unchecked_Convert_To
(Unsigned
,
3248 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3250 Unchecked_Convert_To
(Unsigned
,
3251 New_Occurrence_Of
(Desired_Comp
, Loc
)))));
3253 -- Small optimization: transform the default return statement
3254 -- of a procedure into the atomic exit statement.
3256 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3257 Rewrite
(Last
(Stmts
), Stmt
);
3259 Append_To
(Stmts
, Stmt
);
3263 -- Create the declaration of the label used to skip the rest of
3264 -- the source statements when the object state changes.
3266 if Present
(Label_Id
) then
3267 Label
:= Make_Label
(Loc
, Label_Id
);
3269 Make_Implicit_Label_Declaration
(Loc
,
3270 Defining_Identifier
=> Entity
(Label_Id
),
3271 Label_Construct
=> Label
));
3272 Append_To
(Stmts
, Label
);
3284 if Is_Procedure
then
3287 Make_Loop_Statement
(Loc
,
3288 Statements
=> New_List
(
3289 Make_Block_Statement
(Loc
,
3290 Declarations
=> Block_Decls
,
3291 Handled_Statement_Sequence
=>
3292 Make_Handled_Sequence_Of_Statements
(Loc
,
3293 Statements
=> Stmts
))),
3294 End_Label
=> Empty
));
3298 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3299 end Protected_Component_Ref
;
3302 -- Make an unprotected version of the subprogram for use within the same
3303 -- object, with new name and extra parameter representing the object.
3306 Make_Subprogram_Body
(Loc
,
3308 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3309 Declarations
=> Decls
,
3310 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3311 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3313 -------------------------
3314 -- Build_Master_Entity --
3315 -------------------------
3317 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3318 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3320 Context_Id
: Entity_Id
;
3326 if Is_Itype
(Obj_Or_Typ
) then
3327 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3329 Par
:= Parent
(Obj_Or_Typ
);
3332 -- When creating a master for a record component which is either a task
3333 -- or access-to-task, the enclosing record is the master scope and the
3334 -- proper insertion point is the component list.
3336 if Is_Record_Type
(Current_Scope
) then
3338 Context_Id
:= Current_Scope
;
3339 Decls
:= List_Containing
(Context
);
3341 -- Default case for object declarations and access types. Note that the
3342 -- context is updated to the nearest enclosing body, block, package, or
3343 -- return statement.
3346 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3349 -- Nothing to do if the context already has a master
3351 if Has_Master_Entity
(Context_Id
) then
3354 -- Nothing to do if tasks or tasking hierarchies are prohibited
3356 elsif Restriction_Active
(No_Tasking
)
3357 or else Restriction_Active
(No_Task_Hierarchy
)
3362 -- Create a master, generate:
3363 -- _Master : constant Master_Id := Current_Master.all;
3366 Make_Object_Declaration
(Loc
,
3367 Defining_Identifier
=>
3368 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3369 Constant_Present
=> True,
3370 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3372 Make_Explicit_Dereference
(Loc
,
3373 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
3375 -- The master is inserted at the start of the declarative list of the
3378 Prepend_To
(Decls
, Decl
);
3380 -- In certain cases where transient scopes are involved, the immediate
3381 -- scope is not always the proper master scope. Ensure that the master
3382 -- declaration and entity appear in the same context.
3384 if Context_Id
/= Current_Scope
then
3385 Push_Scope
(Context_Id
);
3392 -- Mark the enclosing scope and its associated construct as being task
3395 Set_Has_Master_Entity
(Context_Id
);
3397 while Present
(Context
)
3398 and then Nkind
(Context
) /= N_Compilation_Unit
3400 if Nkind_In
(Context
, N_Block_Statement
,
3404 Set_Is_Task_Master
(Context
);
3407 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3408 Context
:= Corresponding_Stub
(Parent
(Context
));
3411 Context
:= Parent
(Context
);
3413 end Build_Master_Entity
;
3415 ---------------------------
3416 -- Build_Master_Renaming --
3417 ---------------------------
3419 procedure Build_Master_Renaming
3420 (Ptr_Typ
: Entity_Id
;
3421 Ins_Nod
: Node_Id
:= Empty
)
3423 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3425 Master_Decl
: Node_Id
;
3426 Master_Id
: Entity_Id
;
3429 -- Nothing to do if tasks or tasking hierarchies are prohibited
3431 if Restriction_Active
(No_Tasking
)
3432 or else Restriction_Active
(No_Task_Hierarchy
)
3437 -- Determine the proper context to insert the master renaming
3439 if Present
(Ins_Nod
) then
3441 elsif Is_Itype
(Ptr_Typ
) then
3442 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3444 Context
:= Parent
(Ptr_Typ
);
3448 -- <Ptr_Typ>M : Master_Id renames _Master;
3451 Make_Defining_Identifier
(Loc
,
3452 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3455 Make_Object_Renaming_Declaration
(Loc
,
3456 Defining_Identifier
=> Master_Id
,
3457 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3458 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3460 Insert_Action
(Context
, Master_Decl
);
3462 -- The renamed master now services the access type
3464 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3465 end Build_Master_Renaming
;
3467 -----------------------------------------
3468 -- Build_Private_Protected_Declaration --
3469 -----------------------------------------
3471 function Build_Private_Protected_Declaration
3472 (N
: Node_Id
) return Entity_Id
3474 Loc
: constant Source_Ptr
:= Sloc
(N
);
3475 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3480 Spec_Id
: Entity_Id
;
3483 Formal
:= First_Formal
(Body_Id
);
3485 -- The protected operation always has at least one formal, namely the
3486 -- object itself, but it is only placed in the parameter list if
3487 -- expansion is enabled.
3489 if Present
(Formal
) or else Expander_Active
then
3490 Plist
:= Copy_Parameter_List
(Body_Id
);
3495 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3497 Make_Procedure_Specification
(Loc
,
3498 Defining_Unit_Name
=>
3499 Make_Defining_Identifier
(Sloc
(Body_Id
),
3500 Chars
=> Chars
(Body_Id
)),
3501 Parameter_Specifications
=>
3505 Make_Function_Specification
(Loc
,
3506 Defining_Unit_Name
=>
3507 Make_Defining_Identifier
(Sloc
(Body_Id
),
3508 Chars
=> Chars
(Body_Id
)),
3509 Parameter_Specifications
=> Plist
,
3510 Result_Definition
=>
3511 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3514 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3515 Insert_Before
(N
, Decl
);
3516 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3518 -- Indicate that the entity comes from source, to ensure that cross-
3519 -- reference information is properly generated. The body itself is
3520 -- rewritten during expansion, and the body entity will not appear in
3521 -- calls to the operation.
3523 Set_Comes_From_Source
(Spec_Id
, True);
3525 Set_Has_Completion
(Spec_Id
);
3526 Set_Convention
(Spec_Id
, Convention_Protected
);
3528 end Build_Private_Protected_Declaration
;
3530 ---------------------------
3531 -- Build_Protected_Entry --
3532 ---------------------------
3534 function Build_Protected_Entry
3537 Pid
: Node_Id
) return Node_Id
3539 Bod_Decls
: constant List_Id
:= New_List
;
3540 Decls
: constant List_Id
:= Declarations
(N
);
3541 End_Lab
: constant Node_Id
:=
3542 End_Label
(Handled_Statement_Sequence
(N
));
3543 End_Loc
: constant Source_Ptr
:=
3544 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3545 -- Used for the generated call to Complete_Entry_Body
3547 Loc
: constant Source_Ptr
:= Sloc
(N
);
3551 Bod_Stmts
: List_Id
;
3555 EH_Loc
: Source_Ptr
;
3556 -- Used for the exception handler, inserted at end of the body
3559 -- Set the source location on the exception handler only when debugging
3560 -- the expanded code (see Make_Implicit_Exception_Handler).
3562 if Debug_Generated_Code
then
3565 -- Otherwise the inserted code should not be visible to the debugger
3568 EH_Loc
:= No_Location
;
3572 Make_Defining_Identifier
(Loc
,
3573 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3574 Bod_Spec
:= Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Empty
);
3576 -- Add the following declarations:
3578 -- type poVP is access poV;
3579 -- _object : poVP := poVP (_O);
3581 -- where _O is the formal parameter associated with the concurrent
3582 -- object. These declarations are needed for Complete_Entry_Body.
3584 Add_Object_Pointer
(Loc
, Pid
, Bod_Decls
);
3586 -- Add renamings for all formals, the Protection object, discriminals,
3587 -- privals and the entry index constant for use by debugger.
3589 Add_Formal_Renamings
(Bod_Spec
, Bod_Decls
, Ent
, Loc
);
3590 Debug_Private_Data_Declarations
(Decls
);
3592 -- Put the declarations and the statements from the entry
3596 Make_Block_Statement
(Loc
,
3597 Declarations
=> Decls
,
3598 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
)));
3600 case Corresponding_Runtime_Package
(Pid
) is
3601 when System_Tasking_Protected_Objects_Entries
=>
3602 Append_To
(Bod_Stmts
,
3603 Make_Procedure_Call_Statement
(End_Loc
,
3605 New_Occurrence_Of
(RTE
(RE_Complete_Entry_Body
), Loc
),
3606 Parameter_Associations
=> New_List
(
3607 Make_Attribute_Reference
(End_Loc
,
3609 Make_Selected_Component
(End_Loc
,
3611 Make_Identifier
(End_Loc
, Name_uObject
),
3613 Make_Identifier
(End_Loc
, Name_uObject
)),
3614 Attribute_Name
=> Name_Unchecked_Access
))));
3616 when System_Tasking_Protected_Objects_Single_Entry
=>
3618 -- Historically, a call to Complete_Single_Entry_Body was
3619 -- inserted, but it was a null procedure.
3624 raise Program_Error
;
3627 -- When exceptions can not be propagated, we never need to call
3628 -- Exception_Complete_Entry_Body.
3630 if No_Exception_Handlers_Set
then
3632 Make_Subprogram_Body
(Loc
,
3633 Specification
=> Bod_Spec
,
3634 Declarations
=> Bod_Decls
,
3635 Handled_Statement_Sequence
=>
3636 Make_Handled_Sequence_Of_Statements
(Loc
,
3637 Statements
=> Bod_Stmts
,
3638 End_Label
=> End_Lab
));
3641 Ohandle
:= Make_Others_Choice
(Loc
);
3642 Set_All_Others
(Ohandle
);
3644 case Corresponding_Runtime_Package
(Pid
) is
3645 when System_Tasking_Protected_Objects_Entries
=>
3648 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3650 when System_Tasking_Protected_Objects_Single_Entry
=>
3653 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3656 raise Program_Error
;
3659 -- Establish link between subprogram body entity and source entry
3661 Set_Corresponding_Protected_Entry
(Bod_Id
, Ent
);
3663 -- Create body of entry procedure. The renaming declarations are
3664 -- placed ahead of the block that contains the actual entry body.
3667 Make_Subprogram_Body
(Loc
,
3668 Specification
=> Bod_Spec
,
3669 Declarations
=> Bod_Decls
,
3670 Handled_Statement_Sequence
=>
3671 Make_Handled_Sequence_Of_Statements
(Loc
,
3672 Statements
=> Bod_Stmts
,
3673 End_Label
=> End_Lab
,
3674 Exception_Handlers
=> New_List
(
3675 Make_Implicit_Exception_Handler
(EH_Loc
,
3676 Exception_Choices
=> New_List
(Ohandle
),
3678 Statements
=> New_List
(
3679 Make_Procedure_Call_Statement
(EH_Loc
,
3681 Parameter_Associations
=> New_List
(
3682 Make_Attribute_Reference
(EH_Loc
,
3684 Make_Selected_Component
(EH_Loc
,
3686 Make_Identifier
(EH_Loc
, Name_uObject
),
3688 Make_Identifier
(EH_Loc
, Name_uObject
)),
3689 Attribute_Name
=> Name_Unchecked_Access
),
3691 Make_Function_Call
(EH_Loc
,
3694 (RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3696 end Build_Protected_Entry
;
3698 -----------------------------------------
3699 -- Build_Protected_Entry_Specification --
3700 -----------------------------------------
3702 function Build_Protected_Entry_Specification
3705 Ent_Id
: Entity_Id
) return Node_Id
3707 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3710 Set_Debug_Info_Needed
(Def_Id
);
3712 if Present
(Ent_Id
) then
3713 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3717 Make_Procedure_Specification
(Loc
,
3718 Defining_Unit_Name
=> Def_Id
,
3719 Parameter_Specifications
=> New_List
(
3720 Make_Parameter_Specification
(Loc
,
3721 Defining_Identifier
=>
3722 Make_Defining_Identifier
(Loc
, Name_uO
),
3724 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3726 Make_Parameter_Specification
(Loc
,
3727 Defining_Identifier
=> P
,
3729 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3731 Make_Parameter_Specification
(Loc
,
3732 Defining_Identifier
=>
3733 Make_Defining_Identifier
(Loc
, Name_uE
),
3735 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))));
3736 end Build_Protected_Entry_Specification
;
3738 --------------------------
3739 -- Build_Protected_Spec --
3740 --------------------------
3742 function Build_Protected_Spec
3744 Obj_Type
: Entity_Id
;
3746 Unprotected
: Boolean := False) return List_Id
3748 Loc
: constant Source_Ptr
:= Sloc
(N
);
3751 New_Plist
: List_Id
;
3752 New_Param
: Node_Id
;
3755 New_Plist
:= New_List
;
3757 Formal
:= First_Formal
(Ident
);
3758 while Present
(Formal
) loop
3760 Make_Parameter_Specification
(Loc
,
3761 Defining_Identifier
=>
3762 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
3763 Aliased_Present
=> Aliased_Present
(Parent
(Formal
)),
3764 In_Present
=> In_Present
(Parent
(Formal
)),
3765 Out_Present
=> Out_Present
(Parent
(Formal
)),
3766 Parameter_Type
=> New_Occurrence_Of
(Etype
(Formal
), Loc
));
3769 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
3772 Append
(New_Param
, New_Plist
);
3773 Next_Formal
(Formal
);
3776 -- If the subprogram is a procedure and the context is not an access
3777 -- to protected subprogram, the parameter is in-out. Otherwise it is
3781 Make_Parameter_Specification
(Loc
,
3782 Defining_Identifier
=>
3783 Make_Defining_Identifier
(Loc
, Name_uObject
),
3786 (Etype
(Ident
) = Standard_Void_Type
3787 and then not Is_RTE
(Obj_Type
, RE_Address
)),
3789 New_Occurrence_Of
(Obj_Type
, Loc
));
3790 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
3791 Prepend_To
(New_Plist
, Decl
);
3794 end Build_Protected_Spec
;
3796 ---------------------------------------
3797 -- Build_Protected_Sub_Specification --
3798 ---------------------------------------
3800 function Build_Protected_Sub_Specification
3802 Prot_Typ
: Entity_Id
;
3803 Mode
: Subprogram_Protection_Mode
) return Node_Id
3805 Loc
: constant Source_Ptr
:= Sloc
(N
);
3809 New_Plist
: List_Id
;
3812 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
3813 (Dispatching_Mode
=> ' ',
3814 Protected_Mode
=> 'P',
3815 Unprotected_Mode
=> 'N');
3818 if Ekind
(Defining_Unit_Name
(Specification
(N
))) = E_Subprogram_Body
3820 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
3825 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
3828 Build_Protected_Spec
3829 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
3830 Mode
= Unprotected_Mode
);
3832 Make_Defining_Identifier
(Loc
,
3833 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
3835 -- Reference the original nondispatching subprogram since the analysis
3836 -- of the object.operation notation may need its original name (see
3837 -- Sem_Ch4.Names_Match).
3839 if Mode
= Dispatching_Mode
then
3840 Set_Ekind
(New_Id
, Ekind
(Def_Id
));
3841 Set_Original_Protected_Subprogram
(New_Id
, Def_Id
);
3844 -- The unprotected operation carries the user code, and debugging
3845 -- information must be generated for it, even though this spec does
3846 -- not come from source. It is also convenient to allow gdb to step
3847 -- into the protected operation, even though it only contains lock/
3850 Set_Debug_Info_Needed
(New_Id
);
3852 -- If a pragma Eliminate applies to the source entity, the internal
3853 -- subprograms will be eliminated as well.
3855 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
3857 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
3859 Make_Procedure_Specification
(Loc
,
3860 Defining_Unit_Name
=> New_Id
,
3861 Parameter_Specifications
=> New_Plist
);
3863 -- Create a new specification for the anonymous subprogram type
3867 Make_Function_Specification
(Loc
,
3868 Defining_Unit_Name
=> New_Id
,
3869 Parameter_Specifications
=> New_Plist
,
3870 Result_Definition
=>
3871 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
3873 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
3877 end Build_Protected_Sub_Specification
;
3879 -------------------------------------
3880 -- Build_Protected_Subprogram_Body --
3881 -------------------------------------
3883 function Build_Protected_Subprogram_Body
3886 N_Op_Spec
: Node_Id
) return Node_Id
3888 Exc_Safe
: constant Boolean := not Might_Raise
(N
);
3889 -- True if N cannot raise an exception
3891 Loc
: constant Source_Ptr
:= Sloc
(N
);
3892 Op_Spec
: constant Node_Id
:= Specification
(N
);
3893 P_Op_Spec
: constant Node_Id
:=
3894 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
3897 Lock_Name
: Node_Id
;
3898 Lock_Stmt
: Node_Id
;
3899 Object_Parm
: Node_Id
;
3902 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
3903 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
3907 Unprot_Call
: Node_Id
;
3910 -- Build a list of the formal parameters of the protected version of
3911 -- the subprogram to use as the actual parameters of the unprotected
3914 Uactuals
:= New_List
;
3915 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
3916 while Present
(Pformal
) loop
3917 Append_To
(Uactuals
,
3918 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
3922 -- Make a call to the unprotected version of the subprogram built above
3923 -- for use by the protected version built below.
3925 if Nkind
(Op_Spec
) = N_Function_Specification
then
3927 R
:= Make_Temporary
(Loc
, 'R');
3930 Make_Object_Declaration
(Loc
,
3931 Defining_Identifier
=> R
,
3932 Constant_Present
=> True,
3933 Object_Definition
=>
3934 New_Copy
(Result_Definition
(N_Op_Spec
)),
3936 Make_Function_Call
(Loc
,
3938 Make_Identifier
(Loc
,
3939 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3940 Parameter_Associations
=> Uactuals
));
3943 Make_Simple_Return_Statement
(Loc
,
3944 Expression
=> New_Occurrence_Of
(R
, Loc
));
3948 Make_Simple_Return_Statement
(Loc
,
3950 Make_Function_Call
(Loc
,
3952 Make_Identifier
(Loc
,
3953 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3954 Parameter_Associations
=> Uactuals
));
3957 Lock_Kind
:= RE_Lock_Read_Only
;
3961 Make_Procedure_Call_Statement
(Loc
,
3963 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3964 Parameter_Associations
=> Uactuals
);
3966 Lock_Kind
:= RE_Lock
;
3969 -- Wrap call in block that will be covered by an at_end handler
3971 if not Exc_Safe
then
3973 Make_Block_Statement
(Loc
,
3974 Handled_Statement_Sequence
=>
3975 Make_Handled_Sequence_Of_Statements
(Loc
,
3976 Statements
=> New_List
(Unprot_Call
)));
3979 -- Make the protected subprogram body. This locks the protected
3980 -- object and calls the unprotected version of the subprogram.
3982 case Corresponding_Runtime_Package
(Pid
) is
3983 when System_Tasking_Protected_Objects_Entries
=>
3984 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entries
), Loc
);
3986 when System_Tasking_Protected_Objects_Single_Entry
=>
3987 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entry
), Loc
);
3989 when System_Tasking_Protected_Objects
=>
3990 Lock_Name
:= New_Occurrence_Of
(RTE
(Lock_Kind
), Loc
);
3993 raise Program_Error
;
3997 Make_Attribute_Reference
(Loc
,
3999 Make_Selected_Component
(Loc
,
4000 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4001 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4002 Attribute_Name
=> Name_Unchecked_Access
);
4005 Make_Procedure_Call_Statement
(Loc
,
4007 Parameter_Associations
=> New_List
(Object_Parm
));
4009 if Abort_Allowed
then
4011 Build_Runtime_Call
(Loc
, RE_Abort_Defer
),
4015 Stmts
:= New_List
(Lock_Stmt
);
4018 if not Exc_Safe
then
4019 Append
(Unprot_Call
, Stmts
);
4021 if Nkind
(Op_Spec
) = N_Function_Specification
then
4023 Stmts
:= Empty_List
;
4025 Append
(Unprot_Call
, Stmts
);
4028 -- Historical note: Previously, call to the cleanup was inserted
4029 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4030 -- which is also shared by the 'not Exc_Safe' path.
4032 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
4034 if Nkind
(Op_Spec
) = N_Function_Specification
then
4035 Append_To
(Stmts
, Return_Stmt
);
4036 Append_To
(Pre_Stmts
,
4037 Make_Block_Statement
(Loc
,
4038 Declarations
=> New_List
(Unprot_Call
),
4039 Handled_Statement_Sequence
=>
4040 Make_Handled_Sequence_Of_Statements
(Loc
,
4041 Statements
=> Stmts
)));
4047 Make_Subprogram_Body
(Loc
,
4048 Declarations
=> Empty_List
,
4049 Specification
=> P_Op_Spec
,
4050 Handled_Statement_Sequence
=>
4051 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4053 -- Mark this subprogram as a protected subprogram body so that the
4054 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4055 -- path as otherwise the cleanup has already been inserted.
4057 if not Exc_Safe
then
4058 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4062 end Build_Protected_Subprogram_Body
;
4064 -------------------------------------
4065 -- Build_Protected_Subprogram_Call --
4066 -------------------------------------
4068 procedure Build_Protected_Subprogram_Call
4072 External
: Boolean := True)
4074 Loc
: constant Source_Ptr
:= Sloc
(N
);
4075 Sub
: constant Entity_Id
:= Entity
(Name
);
4081 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4084 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4087 if Present
(Parameter_Associations
(N
)) then
4088 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4093 -- If the type is an untagged derived type, convert to the root type,
4094 -- which is the one on which the operations are defined.
4096 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4097 and then not Is_Tagged_Type
(Etype
(Rec
))
4098 and then Is_Derived_Type
(Etype
(Rec
))
4100 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4101 Set_Subtype_Mark
(Rec
,
4102 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4105 Prepend
(Rec
, Params
);
4107 if Ekind
(Sub
) = E_Procedure
then
4109 Make_Procedure_Call_Statement
(Loc
,
4111 Parameter_Associations
=> Params
));
4114 pragma Assert
(Ekind
(Sub
) = E_Function
);
4116 Make_Function_Call
(Loc
,
4118 Parameter_Associations
=> Params
));
4120 -- Preserve type of call for subsequent processing (required for
4121 -- call to Wrap_Transient_Expression in the case of a shared passive
4124 Set_Etype
(N
, Etype
(New_Sub
));
4128 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4129 and then Is_Entity_Name
(Expression
(Rec
))
4130 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4132 Add_Shared_Var_Lock_Procs
(N
);
4134 end Build_Protected_Subprogram_Call
;
4136 ---------------------------------------------
4137 -- Build_Protected_Subprogram_Call_Cleanup --
4138 ---------------------------------------------
4140 procedure Build_Protected_Subprogram_Call_Cleanup
4149 -- If the associated protected object has entries, a protected
4150 -- procedure has to service entry queues. In this case generate:
4152 -- Service_Entries (_object._object'Access);
4154 if Nkind
(Op_Spec
) = N_Procedure_Specification
4155 and then Has_Entries
(Conc_Typ
)
4157 case Corresponding_Runtime_Package
(Conc_Typ
) is
4158 when System_Tasking_Protected_Objects_Entries
=>
4159 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entries
), Loc
);
4161 when System_Tasking_Protected_Objects_Single_Entry
=>
4162 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entry
), Loc
);
4165 raise Program_Error
;
4169 Make_Procedure_Call_Statement
(Loc
,
4171 Parameter_Associations
=> New_List
(
4172 Make_Attribute_Reference
(Loc
,
4174 Make_Selected_Component
(Loc
,
4175 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4176 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4177 Attribute_Name
=> Name_Unchecked_Access
))));
4181 -- Unlock (_object._object'Access);
4183 case Corresponding_Runtime_Package
(Conc_Typ
) is
4184 when System_Tasking_Protected_Objects_Entries
=>
4185 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entries
), Loc
);
4187 when System_Tasking_Protected_Objects_Single_Entry
=>
4188 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entry
), Loc
);
4190 when System_Tasking_Protected_Objects
=>
4191 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock
), Loc
);
4194 raise Program_Error
;
4198 Make_Procedure_Call_Statement
(Loc
,
4200 Parameter_Associations
=> New_List
(
4201 Make_Attribute_Reference
(Loc
,
4203 Make_Selected_Component
(Loc
,
4204 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4205 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4206 Attribute_Name
=> Name_Unchecked_Access
))));
4212 if Abort_Allowed
then
4213 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4215 end Build_Protected_Subprogram_Call_Cleanup
;
4217 -------------------------
4218 -- Build_Selected_Name --
4219 -------------------------
4221 function Build_Selected_Name
4222 (Prefix
: Entity_Id
;
4223 Selector
: Entity_Id
;
4224 Append_Char
: Character := ' ') return Name_Id
4226 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4227 Select_Len
: Natural;
4230 Get_Name_String
(Chars
(Selector
));
4231 Select_Len
:= Name_Len
;
4232 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4233 Get_Name_String
(Chars
(Prefix
));
4235 -- If scope is anonymous type, discard suffix to recover name of
4236 -- single protected object. Otherwise use protected type name.
4238 if Name_Buffer
(Name_Len
) = 'T' then
4239 Name_Len
:= Name_Len
- 1;
4242 Add_Str_To_Name_Buffer
("__");
4243 for J
in 1 .. Select_Len
loop
4244 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4247 -- Now add the Append_Char if specified. The encoding to follow
4248 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4249 -- then the entity is associated to a protected type subprogram.
4250 -- Otherwise, it is a protected type entry. For each case, the
4251 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4253 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4255 if Append_Char
/= ' ' then
4256 if Append_Char
= 'P' or Append_Char
= 'N' then
4257 Add_Char_To_Name_Buffer
(Append_Char
);
4260 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4261 return New_External_Name
(Name_Find
, ' ', -1);
4266 end Build_Selected_Name
;
4268 -----------------------------
4269 -- Build_Simple_Entry_Call --
4270 -----------------------------
4272 -- A task entry call is converted to a call to Call_Simple
4275 -- P : parms := (parm, parm, parm);
4277 -- Call_Simple (acceptor-task, entry-index, P'Address);
4283 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4284 -- the parameters, and the constructed aggregate value contains either the
4285 -- parameters or, in the case of non-elementary types, references to these
4286 -- parameters. Then the address of this aggregate is passed to the runtime
4287 -- routine, along with the task id value and the task entry index value.
4288 -- Pnn is only required if parameters are present.
4290 -- The assignments after the call are present only in the case of in-out
4291 -- or out parameters for elementary types, and are used to assign back the
4292 -- resulting values of such parameters.
4294 -- Note: the reason that we insert a block here is that in the context
4295 -- of selects, conditional entry calls etc. the entry call statement
4296 -- appears on its own, not as an element of a list.
4298 -- A protected entry call is converted to a Protected_Entry_Call:
4301 -- P : E1_Params := (param, param, param);
4303 -- Bnn : Communications_Block;
4306 -- P : E1_Params := (param, param, param);
4307 -- Bnn : Communications_Block;
4310 -- Protected_Entry_Call (
4311 -- Object => po._object'Access,
4312 -- E => <entry index>;
4313 -- Uninterpreted_Data => P'Address;
4314 -- Mode => Simple_Call;
4321 procedure Build_Simple_Entry_Call
4330 -- If call has been inlined, nothing left to do
4332 if Nkind
(N
) = N_Block_Statement
then
4336 -- Convert entry call to Call_Simple call
4339 Loc
: constant Source_Ptr
:= Sloc
(N
);
4340 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4341 Stats
: constant List_Id
:= New_List
;
4344 Comm_Name
: Entity_Id
;
4348 Ent_Acc
: Entity_Id
;
4350 Iface_Tag
: Entity_Id
;
4351 Iface_Typ
: Entity_Id
;
4364 -- Simple entry and entry family cases merge here
4366 Ent
:= Entity
(Ename
);
4367 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4368 Conctyp
:= Etype
(Concval
);
4370 -- If prefix is an access type, dereference to obtain the task type
4372 if Is_Access_Type
(Conctyp
) then
4373 Conctyp
:= Designated_Type
(Conctyp
);
4376 -- Special case for protected subprogram calls
4378 if Is_Protected_Type
(Conctyp
)
4379 and then Is_Subprogram
(Entity
(Ename
))
4381 if not Is_Eliminated
(Entity
(Ename
)) then
4382 Build_Protected_Subprogram_Call
4383 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4390 -- First parameter is the Task_Id value from the task value or the
4391 -- Object from the protected object value, obtained by selecting
4392 -- the _Task_Id or _Object from the result of doing an unchecked
4393 -- conversion to convert the value to the corresponding record type.
4395 if Nkind
(Concval
) = N_Function_Call
4396 and then Is_Task_Type
(Conctyp
)
4397 and then Ada_Version
>= Ada_2005
4400 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4401 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4406 Make_Object_Declaration
(Loc
,
4407 Defining_Identifier
=> Obj
,
4408 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4409 Expression
=> ExpR
);
4410 Set_Etype
(Obj
, Conctyp
);
4411 Decls
:= New_List
(Decl
);
4412 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4419 Parm1
:= Concurrent_Ref
(Concval
);
4421 -- Second parameter is the entry index, computed by the routine
4422 -- provided for this purpose. The value of this expression is
4423 -- assigned to an intermediate variable to assure that any entry
4424 -- family index expressions are evaluated before the entry
4427 if not Is_Protected_Type
(Conctyp
)
4429 Corresponding_Runtime_Package
(Conctyp
) =
4430 System_Tasking_Protected_Objects_Entries
4432 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4435 Make_Object_Declaration
(Loc
,
4436 Defining_Identifier
=> X
,
4437 Object_Definition
=>
4438 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
4439 Expression
=> Actual_Index_Expression
(
4440 Loc
, Entity
(Ename
), Index
, Concval
));
4442 Append_To
(Decls
, Xdecl
);
4443 Parm2
:= New_Occurrence_Of
(X
, Loc
);
4450 -- The third parameter is the packaged parameters. If there are
4451 -- none, then it is just the null address, since nothing is passed.
4454 Parm3
:= New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
);
4457 -- Case of parameters present, where third argument is the address
4458 -- of a packaged record containing the required parameter values.
4461 -- First build a list of parameter values, which are references to
4462 -- objects of the parameter types.
4466 Actual
:= First_Actual
(N
);
4467 Formal
:= First_Formal
(Ent
);
4468 while Present
(Actual
) loop
4470 -- If it is a by-copy type, copy it to a new variable. The
4471 -- packaged record has a field that points to this variable.
4473 if Is_By_Copy_Type
(Etype
(Actual
)) then
4475 Make_Object_Declaration
(Loc
,
4476 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4477 Aliased_Present
=> True,
4478 Object_Definition
=>
4479 New_Occurrence_Of
(Etype
(Formal
), Loc
));
4481 -- Mark the object as not needing initialization since the
4482 -- initialization is performed separately, avoiding errors
4483 -- on cases such as formals of null-excluding access types.
4485 Set_No_Initialization
(N_Node
);
4487 -- We must make a separate assignment statement for the
4488 -- case of limited types. We cannot assign it unless the
4489 -- Assignment_OK flag is set first. An out formal of an
4490 -- access type or whose type has a Default_Value must also
4491 -- be initialized from the actual (see RM 6.4.1 (13-13.1)),
4492 -- but no constraint, predicate, or null-exclusion check is
4493 -- applied before the call.
4495 if Ekind
(Formal
) /= E_Out_Parameter
4496 or else Is_Access_Type
(Etype
(Formal
))
4498 (Is_Scalar_Type
(Etype
(Formal
))
4500 Present
(Default_Aspect_Value
(Etype
(Formal
))))
4503 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
);
4504 Set_Assignment_OK
(N_Var
);
4506 Make_Assignment_Statement
(Loc
,
4508 Expression
=> Relocate_Node
(Actual
)));
4510 -- Mark the object as internal, so we don't later reset
4511 -- No_Initialization flag in Default_Initialize_Object,
4512 -- which would lead to needless default initialization.
4513 -- We don't set this outside the if statement, because
4514 -- out scalar parameters without Default_Value do require
4515 -- default initialization if Initialize_Scalars applies.
4517 Set_Is_Internal
(Defining_Identifier
(N_Node
));
4519 -- If actual is an out parameter of a null-excluding
4520 -- access type, there is access check on entry, so set
4521 -- Suppress_Assignment_Checks on the generated statement
4522 -- that assigns the actual to the parameter block.
4524 Set_Suppress_Assignment_Checks
(Last
(Stats
));
4527 Append
(N_Node
, Decls
);
4530 Make_Attribute_Reference
(Loc
,
4531 Attribute_Name
=> Name_Unchecked_Access
,
4534 (Defining_Identifier
(N_Node
), Loc
)));
4537 -- Interface class-wide formal
4539 if Ada_Version
>= Ada_2005
4540 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4541 and then Is_Interface
(Etype
(Formal
))
4543 Iface_Typ
:= Etype
(Etype
(Formal
));
4546 -- formal_iface_type! (actual.iface_tag)'reference
4549 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4550 pragma Assert
(Present
(Iface_Tag
));
4553 Make_Reference
(Loc
,
4554 Unchecked_Convert_To
(Iface_Typ
,
4555 Make_Selected_Component
(Loc
,
4557 Relocate_Node
(Actual
),
4559 New_Occurrence_Of
(Iface_Tag
, Loc
)))));
4565 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4569 Next_Actual
(Actual
);
4570 Next_Formal_With_Extras
(Formal
);
4573 -- Now build the declaration of parameters initialized with the
4574 -- aggregate containing this constructed parameter list.
4576 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4579 Make_Object_Declaration
(Loc
,
4580 Defining_Identifier
=> P
,
4581 Object_Definition
=>
4582 New_Occurrence_Of
(Designated_Type
(Ent_Acc
), Loc
),
4584 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4587 Make_Attribute_Reference
(Loc
,
4588 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4589 Attribute_Name
=> Name_Address
);
4591 Append
(Pdecl
, Decls
);
4594 -- Now we can create the call, case of protected type
4596 if Is_Protected_Type
(Conctyp
) then
4597 case Corresponding_Runtime_Package
(Conctyp
) is
4598 when System_Tasking_Protected_Objects_Entries
=>
4600 -- Change the type of the index declaration
4602 Set_Object_Definition
(Xdecl
,
4603 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
));
4605 -- Some additional declarations for protected entry calls
4611 -- Bnn : Communications_Block;
4613 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4616 Make_Object_Declaration
(Loc
,
4617 Defining_Identifier
=> Comm_Name
,
4618 Object_Definition
=>
4620 (RTE
(RE_Communication_Block
), Loc
)));
4622 -- Some additional statements for protected entry calls
4624 -- Protected_Entry_Call
4625 -- (Object => po._object'Access,
4626 -- E => <entry index>;
4627 -- Uninterpreted_Data => P'Address;
4628 -- Mode => Simple_Call;
4632 Make_Procedure_Call_Statement
(Loc
,
4634 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
4636 Parameter_Associations
=> New_List
(
4637 Make_Attribute_Reference
(Loc
,
4638 Attribute_Name
=> Name_Unchecked_Access
,
4642 New_Occurrence_Of
(RTE
(RE_Simple_Call
), Loc
),
4643 New_Occurrence_Of
(Comm_Name
, Loc
)));
4645 when System_Tasking_Protected_Objects_Single_Entry
=>
4647 -- Protected_Single_Entry_Call
4648 -- (Object => po._object'Access,
4649 -- Uninterpreted_Data => P'Address);
4652 Make_Procedure_Call_Statement
(Loc
,
4655 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4657 Parameter_Associations
=> New_List
(
4658 Make_Attribute_Reference
(Loc
,
4659 Attribute_Name
=> Name_Unchecked_Access
,
4664 raise Program_Error
;
4667 -- Case of task type
4671 Make_Procedure_Call_Statement
(Loc
,
4673 New_Occurrence_Of
(RTE
(RE_Call_Simple
), Loc
),
4674 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4678 Append_To
(Stats
, Call
);
4680 -- If there are out or in/out parameters by copy add assignment
4681 -- statements for the result values.
4683 if Present
(Parms
) then
4684 Actual
:= First_Actual
(N
);
4685 Formal
:= First_Formal
(Ent
);
4687 Set_Assignment_OK
(Actual
);
4688 while Present
(Actual
) loop
4689 if Is_By_Copy_Type
(Etype
(Actual
))
4690 and then Ekind
(Formal
) /= E_In_Parameter
4693 Make_Assignment_Statement
(Loc
,
4694 Name
=> New_Copy
(Actual
),
4696 Make_Explicit_Dereference
(Loc
,
4697 Make_Selected_Component
(Loc
,
4698 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4700 Make_Identifier
(Loc
, Chars
(Formal
)))));
4702 -- In all cases (including limited private types) we want
4703 -- the assignment to be valid.
4705 Set_Assignment_OK
(Name
(N_Node
));
4707 -- If the call is the triggering alternative in an
4708 -- asynchronous select, or the entry_call alternative of a
4709 -- conditional entry call, the assignments for in-out
4710 -- parameters are incorporated into the statement list that
4711 -- follows, so that there are executed only if the entry
4714 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4715 and then N
= Triggering_Statement
(Parent
(N
)))
4717 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4718 and then N
= Entry_Call_Statement
(Parent
(N
)))
4720 if No
(Statements
(Parent
(N
))) then
4721 Set_Statements
(Parent
(N
), New_List
);
4724 Prepend
(N_Node
, Statements
(Parent
(N
)));
4727 Insert_After
(Call
, N_Node
);
4731 Next_Actual
(Actual
);
4732 Next_Formal_With_Extras
(Formal
);
4736 -- Finally, create block and analyze it
4739 Make_Block_Statement
(Loc
,
4740 Declarations
=> Decls
,
4741 Handled_Statement_Sequence
=>
4742 Make_Handled_Sequence_Of_Statements
(Loc
,
4743 Statements
=> Stats
)));
4747 end Build_Simple_Entry_Call
;
4749 --------------------------------
4750 -- Build_Task_Activation_Call --
4751 --------------------------------
4753 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4754 Loc
: constant Source_Ptr
:= Sloc
(N
);
4761 -- For sequential elaboration policy, all the tasks will be activated at
4762 -- the end of the elaboration.
4764 if Partition_Elaboration_Policy
= 'S' then
4768 -- Get the activation chain entity. Except in the case of a package
4769 -- body, this is in the node that was passed. For a package body, we
4770 -- have to find the corresponding package declaration node.
4772 if Nkind
(N
) = N_Package_Body
then
4773 P
:= Corresponding_Spec
(N
);
4776 exit when Nkind
(P
) = N_Package_Declaration
;
4779 Chain
:= Activation_Chain_Entity
(P
);
4782 Chain
:= Activation_Chain_Entity
(N
);
4785 if Present
(Chain
) then
4786 if Restricted_Profile
then
4787 Name
:= New_Occurrence_Of
4788 (RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4790 Name
:= New_Occurrence_Of
4791 (RTE
(RE_Activate_Tasks
), Loc
);
4795 Make_Procedure_Call_Statement
(Loc
,
4797 Parameter_Associations
=>
4798 New_List
(Make_Attribute_Reference
(Loc
,
4799 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4800 Attribute_Name
=> Name_Unchecked_Access
)));
4802 if Nkind
(N
) = N_Package_Declaration
then
4803 if Present
(Corresponding_Body
(N
)) then
4806 elsif Present
(Private_Declarations
(Specification
(N
))) then
4807 Append
(Call
, Private_Declarations
(Specification
(N
)));
4810 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4814 if Present
(Handled_Statement_Sequence
(N
)) then
4816 -- The call goes at the start of the statement sequence after
4817 -- the start of exception range label if one is present.
4823 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4825 -- A special case, skip exception range label if one is
4826 -- present (from front end zcx processing).
4828 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
4832 -- Another special case, if the first statement is a block
4833 -- from optimization of a local raise to a goto, then the
4834 -- call goes inside this block.
4836 if Nkind
(Stm
) = N_Block_Statement
4837 and then Exception_Junk
(Stm
)
4840 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
4843 -- Insertion point is after any exception label pushes,
4844 -- since we want it covered by any local handlers.
4846 while Nkind
(Stm
) in N_Push_xxx_Label
loop
4850 -- Now we have the proper insertion point
4852 Insert_Before
(Stm
, Call
);
4856 Set_Handled_Statement_Sequence
(N
,
4857 Make_Handled_Sequence_Of_Statements
(Loc
,
4858 Statements
=> New_List
(Call
)));
4863 Check_Task_Activation
(N
);
4865 end Build_Task_Activation_Call
;
4867 -------------------------------
4868 -- Build_Task_Allocate_Block --
4869 -------------------------------
4871 procedure Build_Task_Allocate_Block
4876 T
: constant Entity_Id
:= Entity
(Expression
(N
));
4877 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
4878 Loc
: constant Source_Ptr
:= Sloc
(N
);
4879 Chain
: constant Entity_Id
:=
4880 Make_Defining_Identifier
(Loc
, Name_uChain
);
4881 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4886 Make_Block_Statement
(Loc
,
4887 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4888 Declarations
=> New_List
(
4890 -- _Chain : Activation_Chain;
4892 Make_Object_Declaration
(Loc
,
4893 Defining_Identifier
=> Chain
,
4894 Aliased_Present
=> True,
4895 Object_Definition
=>
4896 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4898 Handled_Statement_Sequence
=>
4899 Make_Handled_Sequence_Of_Statements
(Loc
,
4901 Statements
=> New_List
(
4905 Make_Procedure_Call_Statement
(Loc
,
4906 Name
=> New_Occurrence_Of
(Init
, Loc
),
4907 Parameter_Associations
=> Args
),
4909 -- Activate_Tasks (_Chain);
4911 Make_Procedure_Call_Statement
(Loc
,
4912 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4913 Parameter_Associations
=> New_List
(
4914 Make_Attribute_Reference
(Loc
,
4915 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4916 Attribute_Name
=> Name_Unchecked_Access
))))),
4918 Has_Created_Identifier
=> True,
4919 Is_Task_Allocation_Block
=> True);
4922 Make_Implicit_Label_Declaration
(Loc
,
4923 Defining_Identifier
=> Blkent
,
4924 Label_Construct
=> Block
));
4926 Append_To
(Actions
, Block
);
4928 Set_Activation_Chain_Entity
(Block
, Chain
);
4929 end Build_Task_Allocate_Block
;
4931 -----------------------------------------------
4932 -- Build_Task_Allocate_Block_With_Init_Stmts --
4933 -----------------------------------------------
4935 procedure Build_Task_Allocate_Block_With_Init_Stmts
4938 Init_Stmts
: List_Id
)
4940 Loc
: constant Source_Ptr
:= Sloc
(N
);
4941 Chain
: constant Entity_Id
:=
4942 Make_Defining_Identifier
(Loc
, Name_uChain
);
4943 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4947 Append_To
(Init_Stmts
,
4948 Make_Procedure_Call_Statement
(Loc
,
4949 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4950 Parameter_Associations
=> New_List
(
4951 Make_Attribute_Reference
(Loc
,
4952 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4953 Attribute_Name
=> Name_Unchecked_Access
))));
4956 Make_Block_Statement
(Loc
,
4957 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4958 Declarations
=> New_List
(
4960 -- _Chain : Activation_Chain;
4962 Make_Object_Declaration
(Loc
,
4963 Defining_Identifier
=> Chain
,
4964 Aliased_Present
=> True,
4965 Object_Definition
=>
4966 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4968 Handled_Statement_Sequence
=>
4969 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
4971 Has_Created_Identifier
=> True,
4972 Is_Task_Allocation_Block
=> True);
4975 Make_Implicit_Label_Declaration
(Loc
,
4976 Defining_Identifier
=> Blkent
,
4977 Label_Construct
=> Block
));
4979 Append_To
(Actions
, Block
);
4981 Set_Activation_Chain_Entity
(Block
, Chain
);
4982 end Build_Task_Allocate_Block_With_Init_Stmts
;
4984 -----------------------------------
4985 -- Build_Task_Proc_Specification --
4986 -----------------------------------
4988 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
4989 Loc
: constant Source_Ptr
:= Sloc
(T
);
4990 Spec_Id
: Entity_Id
;
4993 -- Case of explicit task type, suffix TB
4995 if Comes_From_Source
(T
) then
4997 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
4999 -- Case of anonymous task type, suffix B
5003 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
5006 Set_Is_Internal
(Spec_Id
);
5008 -- Associate the procedure with the task, if this is the declaration
5009 -- (and not the body) of the procedure.
5011 if No
(Task_Body_Procedure
(T
)) then
5012 Set_Task_Body_Procedure
(T
, Spec_Id
);
5016 Make_Procedure_Specification
(Loc
,
5017 Defining_Unit_Name
=> Spec_Id
,
5018 Parameter_Specifications
=> New_List
(
5019 Make_Parameter_Specification
(Loc
,
5020 Defining_Identifier
=>
5021 Make_Defining_Identifier
(Loc
, Name_uTask
),
5023 Make_Access_Definition
(Loc
,
5025 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
5026 end Build_Task_Proc_Specification
;
5028 ---------------------------------------
5029 -- Build_Unprotected_Subprogram_Body --
5030 ---------------------------------------
5032 function Build_Unprotected_Subprogram_Body
5034 Pid
: Node_Id
) return Node_Id
5036 Decls
: constant List_Id
:= Declarations
(N
);
5039 -- Add renamings for the Protection object, discriminals, privals, and
5040 -- the entry index constant for use by debugger.
5042 Debug_Private_Data_Declarations
(Decls
);
5044 -- Make an unprotected version of the subprogram for use within the same
5045 -- object, with a new name and an additional parameter representing the
5049 Make_Subprogram_Body
(Sloc
(N
),
5051 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5052 Declarations
=> Decls
,
5053 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5054 end Build_Unprotected_Subprogram_Body
;
5056 ----------------------------
5057 -- Collect_Entry_Families --
5058 ----------------------------
5060 procedure Collect_Entry_Families
5063 Current_Node
: in out Node_Id
;
5064 Conctyp
: Entity_Id
)
5067 Efam_Decl
: Node_Id
;
5068 Efam_Type
: Entity_Id
;
5071 Efam
:= First_Entity
(Conctyp
);
5072 while Present
(Efam
) loop
5073 if Ekind
(Efam
) = E_Entry_Family
then
5074 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5079 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5081 Bas_Decl
: Node_Id
:= Empty
;
5086 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5088 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5089 Bas
:= Make_Temporary
(Loc
, 'B');
5092 Make_Subtype_Declaration
(Loc
,
5093 Defining_Identifier
=> Bas
,
5094 Subtype_Indication
=>
5095 Make_Subtype_Indication
(Loc
,
5097 New_Occurrence_Of
(Standard_Integer
, Loc
),
5099 Make_Range_Constraint
(Loc
,
5100 Range_Expression
=> Make_Range
(Loc
,
5101 Make_Integer_Literal
5102 (Loc
, -Entry_Family_Bound
),
5103 Make_Integer_Literal
5104 (Loc
, Entry_Family_Bound
- 1)))));
5106 Insert_After
(Current_Node
, Bas_Decl
);
5107 Current_Node
:= Bas_Decl
;
5112 Make_Full_Type_Declaration
(Loc
,
5113 Defining_Identifier
=> Efam_Type
,
5115 Make_Unconstrained_Array_Definition
(Loc
,
5117 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5119 Component_Definition
=>
5120 Make_Component_Definition
(Loc
,
5121 Aliased_Present
=> False,
5122 Subtype_Indication
=>
5123 New_Occurrence_Of
(Standard_Character
, Loc
))));
5126 Insert_After
(Current_Node
, Efam_Decl
);
5127 Current_Node
:= Efam_Decl
;
5128 Analyze
(Efam_Decl
);
5131 Make_Component_Declaration
(Loc
,
5132 Defining_Identifier
=>
5133 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5135 Component_Definition
=>
5136 Make_Component_Definition
(Loc
,
5137 Aliased_Present
=> False,
5138 Subtype_Indication
=>
5139 Make_Subtype_Indication
(Loc
,
5141 New_Occurrence_Of
(Efam_Type
, Loc
),
5144 Make_Index_Or_Discriminant_Constraint
(Loc
,
5145 Constraints
=> New_List
(
5147 (Etype
(Discrete_Subtype_Definition
5148 (Parent
(Efam
))), Loc
)))))));
5154 end Collect_Entry_Families
;
5156 -----------------------
5157 -- Concurrent_Object --
5158 -----------------------
5160 function Concurrent_Object
5161 (Spec_Id
: Entity_Id
;
5162 Conc_Typ
: Entity_Id
) return Entity_Id
5165 -- Parameter _O or _object
5167 if Is_Protected_Type
(Conc_Typ
) then
5168 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5173 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5174 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5176 end Concurrent_Object
;
5178 ----------------------
5179 -- Copy_Result_Type --
5180 ----------------------
5182 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5183 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5188 -- If the result type is an access_to_subprogram, we must create new
5189 -- entities for its spec.
5191 if Nkind
(New_Res
) = N_Access_Definition
5192 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5194 -- Provide new entities for the formals
5196 Par_Spec
:= First
(Parameter_Specifications
5197 (Access_To_Subprogram_Definition
(New_Res
)));
5198 while Present
(Par_Spec
) loop
5199 Formal
:= Defining_Identifier
(Par_Spec
);
5200 Set_Defining_Identifier
(Par_Spec
,
5201 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5207 end Copy_Result_Type
;
5209 --------------------
5210 -- Concurrent_Ref --
5211 --------------------
5213 -- The expression returned for a reference to a concurrent object has the
5216 -- taskV!(name)._Task_Id
5220 -- objectV!(name)._Object
5222 -- for a protected object. For the case of an access to a concurrent
5223 -- object, there is an extra explicit dereference:
5225 -- taskV!(name.all)._Task_Id
5226 -- objectV!(name.all)._Object
5228 -- here taskV and objectV are the types for the associated records, which
5229 -- contain the required _Task_Id and _Object fields for tasks and protected
5230 -- objects, respectively.
5232 -- For the case of a task type name, the expression is
5236 -- i.e. a call to the Self function which returns precisely this Task_Id
5238 -- For the case of a protected type name, the expression is
5242 -- which is a renaming of the _object field of the current object
5243 -- record, passed into protected operations as a parameter.
5245 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5246 Loc
: constant Source_Ptr
:= Sloc
(N
);
5247 Ntyp
: constant Entity_Id
:= Etype
(N
);
5251 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5252 -- Check whether the reference is to the immediately enclosing task
5253 -- type, or to an outer one (rare but legal).
5255 ---------------------
5256 -- Is_Current_Task --
5257 ---------------------
5259 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5263 Scop
:= Current_Scope
;
5264 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
5268 elsif Is_Task_Type
(Scop
) then
5271 -- If this is a procedure nested within the task type, we must
5272 -- assume that it can be called from an inner task, and therefore
5273 -- cannot treat it as a local reference.
5275 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5279 Scop
:= Scope
(Scop
);
5283 -- We know that we are within the task body, so should have found it
5286 raise Program_Error
;
5287 end Is_Current_Task
;
5289 -- Start of processing for Concurrent_Ref
5292 if Is_Access_Type
(Ntyp
) then
5293 Dtyp
:= Designated_Type
(Ntyp
);
5295 if Is_Protected_Type
(Dtyp
) then
5296 Sel
:= Name_uObject
;
5298 Sel
:= Name_uTask_Id
;
5302 Make_Selected_Component
(Loc
,
5304 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5305 Make_Explicit_Dereference
(Loc
, N
)),
5306 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5308 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5309 if Is_Task_Type
(Entity
(N
)) then
5311 if Is_Current_Task
(Entity
(N
)) then
5313 Make_Function_Call
(Loc
,
5314 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5319 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5320 T_Body
: constant Node_Id
:=
5321 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5325 Make_Object_Declaration
(Loc
,
5326 Defining_Identifier
=> T_Self
,
5327 Object_Definition
=>
5328 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5330 Make_Function_Call
(Loc
,
5331 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5332 Prepend
(Decl
, Declarations
(T_Body
));
5334 Set_Scope
(T_Self
, Entity
(N
));
5335 return New_Occurrence_Of
(T_Self
, Loc
);
5340 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5343 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5347 if Is_Protected_Type
(Ntyp
) then
5348 Sel
:= Name_uObject
;
5349 elsif Is_Task_Type
(Ntyp
) then
5350 Sel
:= Name_uTask_Id
;
5352 raise Program_Error
;
5356 Make_Selected_Component
(Loc
,
5358 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5360 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5364 ------------------------
5365 -- Convert_Concurrent --
5366 ------------------------
5368 function Convert_Concurrent
5370 Typ
: Entity_Id
) return Node_Id
5373 if not Is_Concurrent_Type
(Typ
) then
5377 Unchecked_Convert_To
5378 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5380 end Convert_Concurrent
;
5382 -------------------------------------
5383 -- Debug_Private_Data_Declarations --
5384 -------------------------------------
5386 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5387 Debug_Nod
: Node_Id
;
5391 Decl
:= First
(Decls
);
5392 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5394 -- Declaration for concurrent entity _object and its access type,
5395 -- along with the entry index subtype:
5396 -- type prot_typVP is access prot_typV;
5397 -- _object : prot_typVP := prot_typV (_O);
5398 -- subtype Jnn is <Type of Index> range Low .. High;
5400 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5401 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5403 -- Declaration for the Protection object, discriminals, privals, and
5404 -- entry index constant:
5405 -- conc_typR : protection_typ renames _object._object;
5406 -- discr_nameD : discr_typ renames _object.discr_name;
5407 -- discr_nameD : discr_typ renames _task.discr_name;
5408 -- prival_name : comp_typ renames _object.comp_name;
5409 -- J : constant Jnn :=
5410 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5412 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5413 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5414 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5416 if Present
(Debug_Nod
) then
5417 Insert_After
(Decl
, Debug_Nod
);
5423 end Debug_Private_Data_Declarations
;
5425 ------------------------------
5426 -- Ensure_Statement_Present --
5427 ------------------------------
5429 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5433 if Opt
.Suppress_Control_Flow_Optimizations
5434 and then Is_Empty_List
(Statements
(Alt
))
5436 Stmt
:= Make_Null_Statement
(Loc
);
5438 -- Mark NULL statement as coming from source so that it is not
5439 -- eliminated by GIGI.
5441 -- Another covert channel. If this is a requirement, it must be
5442 -- documented in sinfo/einfo ???
5444 Set_Comes_From_Source
(Stmt
, True);
5446 Set_Statements
(Alt
, New_List
(Stmt
));
5448 end Ensure_Statement_Present
;
5450 ----------------------------
5451 -- Entry_Index_Expression --
5452 ----------------------------
5454 function Entry_Index_Expression
5458 Ttyp
: Entity_Id
) return Node_Id
5468 -- The queues of entries and entry families appear in textual order in
5469 -- the associated record. The entry index is computed as the sum of the
5470 -- number of queues for all entries that precede the designated one, to
5471 -- which is added the index expression, if this expression denotes a
5472 -- member of a family.
5474 -- The following is a place holder for the count of simple entries
5476 Num
:= Make_Integer_Literal
(Sloc
, 1);
5478 -- We construct an expression which is a series of addition operations.
5479 -- The first operand is the number of single entries that precede this
5480 -- one, the second operand is the index value relative to the start of
5481 -- the referenced family, and the remaining operands are the lengths of
5482 -- the entry families that precede this entry, i.e. the constructed
5485 -- number_simple_entries +
5486 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5487 -- family'length + ...
5489 -- where index-value is the given index value, and s is the index
5490 -- subtype (we have to use pos because the subtype might be an
5491 -- enumeration type preventing direct subtraction). Note that the task
5492 -- entry array is one-indexed.
5494 -- The upper bound of the entry family may be a discriminant, so we
5495 -- retrieve the lower bound explicitly to compute offset, rather than
5496 -- using the index subtype which may mention a discriminant.
5498 if Present
(Index
) then
5499 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5507 Make_Attribute_Reference
(Sloc
,
5508 Attribute_Name
=> Name_Pos
,
5509 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5510 Expressions
=> New_List
(Relocate_Node
(Index
))),
5518 -- Now add lengths of preceding entries and entry families
5520 Prev
:= First_Entity
(Ttyp
);
5521 while Chars
(Prev
) /= Chars
(Ent
)
5522 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5523 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5525 if Ekind
(Prev
) = E_Entry
then
5526 Set_Intval
(Num
, Intval
(Num
) + 1);
5528 elsif Ekind
(Prev
) = E_Entry_Family
then
5529 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5530 Lo
:= Type_Low_Bound
(S
);
5531 Hi
:= Type_High_Bound
(S
);
5536 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5538 -- Other components are anonymous types to be ignored
5548 end Entry_Index_Expression
;
5550 ---------------------------
5551 -- Establish_Task_Master --
5552 ---------------------------
5554 procedure Establish_Task_Master
(N
: Node_Id
) is
5558 if Restriction_Active
(No_Task_Hierarchy
) = False then
5559 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5561 -- The block may have no declarations (and nevertheless be a task
5562 -- master) if it contains a call that may return an object that
5565 if No
(Declarations
(N
)) then
5566 Set_Declarations
(N
, New_List
(Call
));
5568 Prepend_To
(Declarations
(N
), Call
);
5573 end Establish_Task_Master
;
5575 --------------------------------
5576 -- Expand_Accept_Declarations --
5577 --------------------------------
5579 -- Part of the expansion of an accept statement involves the creation of
5580 -- a declaration that can be referenced from the statement sequence of
5585 -- This declaration is inserted immediately before the accept statement
5586 -- and it is important that it be inserted before the statements of the
5587 -- statement sequence are analyzed. Thus it would be too late to create
5588 -- this declaration in the Expand_N_Accept_Statement routine, which is
5589 -- why there is a separate procedure to be called directly from Sem_Ch9.
5591 -- Ann is used to hold the address of the record containing the parameters
5592 -- (see Expand_N_Entry_Call for more details on how this record is built).
5593 -- References to the parameters do an unchecked conversion of this address
5594 -- to a pointer to the required record type, and then access the field that
5595 -- holds the value of the required parameter. The entity for the address
5596 -- variable is held as the top stack element (i.e. the last element) of the
5597 -- Accept_Address stack in the corresponding entry entity, and this element
5598 -- must be set in place before the statements are processed.
5600 -- The above description applies to the case of a stand alone accept
5601 -- statement, i.e. one not appearing as part of a select alternative.
5603 -- For the case of an accept that appears as part of a select alternative
5604 -- of a selective accept, we must still create the declaration right away,
5605 -- since Ann is needed immediately, but there is an important difference:
5607 -- The declaration is inserted before the selective accept, not before
5608 -- the accept statement (which is not part of a list anyway, and so would
5609 -- not accommodate inserted declarations)
5611 -- We only need one address variable for the entire selective accept. So
5612 -- the Ann declaration is created only for the first accept alternative,
5613 -- and subsequent accept alternatives reference the same Ann variable.
5615 -- We can distinguish the two cases by seeing whether the accept statement
5616 -- is part of a list. If not, then it must be in an accept alternative.
5618 -- To expand the requeue statement, a label is provided at the end of the
5619 -- accept statement or alternative of which it is a part, so that the
5620 -- statement can be skipped after the requeue is complete. This label is
5621 -- created here rather than during the expansion of the accept statement,
5622 -- because it will be needed by any requeue statements within the accept,
5623 -- which are expanded before the accept.
5625 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5626 Loc
: constant Source_Ptr
:= Sloc
(N
);
5627 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5628 Ann
: Entity_Id
:= Empty
;
5635 if Expander_Active
then
5637 -- If we have no handled statement sequence, we may need to build
5638 -- a dummy sequence consisting of a null statement. This can be
5639 -- skipped if the trivial accept optimization is permitted.
5641 if not Trivial_Accept_OK
5642 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5644 Set_Handled_Statement_Sequence
(N
,
5645 Make_Handled_Sequence_Of_Statements
(Loc
,
5646 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5649 -- Create and declare two labels to be placed at the end of the
5650 -- accept statement. The first label is used to allow requeues to
5651 -- skip the remainder of entry processing. The second label is used
5652 -- to skip the remainder of entry processing if the rendezvous
5653 -- completes in the middle of the accept body.
5655 if Present
(Handled_Statement_Sequence
(N
)) then
5660 Ent
:= Make_Temporary
(Loc
, 'L');
5661 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5663 Make_Implicit_Label_Declaration
(Loc
,
5664 Defining_Identifier
=> Ent
,
5665 Label_Construct
=> Lab
);
5666 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5668 Ent
:= Make_Temporary
(Loc
, 'L');
5669 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5671 Make_Implicit_Label_Declaration
(Loc
,
5672 Defining_Identifier
=> Ent
,
5673 Label_Construct
=> Lab
);
5674 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5682 -- Case of stand alone accept statement
5684 if Is_List_Member
(N
) then
5686 if Present
(Handled_Statement_Sequence
(N
)) then
5687 Ann
:= Make_Temporary
(Loc
, 'A');
5690 Make_Object_Declaration
(Loc
,
5691 Defining_Identifier
=> Ann
,
5692 Object_Definition
=>
5693 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5695 Insert_Before_And_Analyze
(N
, Adecl
);
5696 Insert_Before_And_Analyze
(N
, Ldecl
);
5697 Insert_Before_And_Analyze
(N
, Ldecl2
);
5700 -- Case of accept statement which is in an accept alternative
5704 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5705 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5709 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5710 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5712 -- ??? Consider a single label for select statements
5714 if Present
(Handled_Statement_Sequence
(N
)) then
5716 Statements
(Handled_Statement_Sequence
(N
)));
5720 Statements
(Handled_Statement_Sequence
(N
)));
5724 -- Find first accept alternative of the selective accept. A
5725 -- valid selective accept must have at least one accept in it.
5727 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5729 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5733 -- If this is the first accept statement, then we have to
5734 -- create the Ann variable, as for the stand alone case, except
5735 -- that it is inserted before the selective accept. Similarly,
5736 -- a label for requeue expansion must be declared.
5738 if N
= Accept_Statement
(Alt
) then
5739 Ann
:= Make_Temporary
(Loc
, 'A');
5741 Make_Object_Declaration
(Loc
,
5742 Defining_Identifier
=> Ann
,
5743 Object_Definition
=>
5744 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5746 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5748 -- If this is not the first accept statement, then find the Ann
5749 -- variable allocated by the first accept and use it.
5753 Node
(Last_Elmt
(Accept_Address
5754 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5759 -- Merge here with Ann either created or referenced, and Adecl
5760 -- pointing to the corresponding declaration. Remaining processing
5761 -- is the same for the two cases.
5763 if Present
(Ann
) then
5764 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5765 Set_Debug_Info_Needed
(Ann
);
5768 -- Create renaming declarations for the entry formals. Each reference
5769 -- to a formal becomes a dereference of a component of the parameter
5770 -- block, whose address is held in Ann. These declarations are
5771 -- eventually inserted into the accept block, and analyzed there so
5772 -- that they have the proper scope for gdb and do not conflict with
5773 -- other declarations.
5775 if Present
(Parameter_Specifications
(N
))
5776 and then Present
(Handled_Statement_Sequence
(N
))
5783 Renamed_Formal
: Node_Id
;
5787 Formal
:= First_Formal
(Ent
);
5789 while Present
(Formal
) loop
5790 Comp
:= Entry_Component
(Formal
);
5791 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5793 Set_Etype
(New_F
, Etype
(Formal
));
5794 Set_Scope
(New_F
, Ent
);
5796 -- Now we set debug info needed on New_F even though it does
5797 -- not come from source, so that the debugger will get the
5798 -- right information for these generated names.
5800 Set_Debug_Info_Needed
(New_F
);
5802 if Ekind
(Formal
) = E_In_Parameter
then
5803 Set_Ekind
(New_F
, E_Constant
);
5805 Set_Ekind
(New_F
, E_Variable
);
5806 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5809 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5812 Make_Selected_Component
(Loc
,
5814 Unchecked_Convert_To
(
5815 Entry_Parameters_Type
(Ent
),
5816 New_Occurrence_Of
(Ann
, Loc
)),
5818 New_Occurrence_Of
(Comp
, Loc
));
5821 Build_Renamed_Formal_Declaration
5822 (New_F
, Formal
, Comp
, Renamed_Formal
);
5824 if No
(Declarations
(N
)) then
5825 Set_Declarations
(N
, New_List
);
5828 Append
(Decl
, Declarations
(N
));
5829 Set_Renamed_Object
(Formal
, New_F
);
5830 Next_Formal
(Formal
);
5837 end Expand_Accept_Declarations
;
5839 ---------------------------------------------
5840 -- Expand_Access_Protected_Subprogram_Type --
5841 ---------------------------------------------
5843 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5844 Loc
: constant Source_Ptr
:= Sloc
(N
);
5845 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5846 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5847 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5848 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5849 P_List
: constant List_Id
:=
5850 Build_Protected_Spec
(N
, RTE
(RE_Address
), D_T
, False);
5858 -- Create access to subprogram with full signature
5860 if Etype
(D_T
) /= Standard_Void_Type
then
5862 Make_Access_Function_Definition
(Loc
,
5863 Parameter_Specifications
=> P_List
,
5864 Result_Definition
=>
5865 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5869 Make_Access_Procedure_Definition
(Loc
,
5870 Parameter_Specifications
=> P_List
);
5874 Make_Full_Type_Declaration
(Loc
,
5875 Defining_Identifier
=> D_T2
,
5876 Type_Definition
=> Def1
);
5878 -- Declare the new types before the original one since the latter will
5879 -- refer to them through the Equivalent_Type slot.
5881 Insert_Before_And_Analyze
(N
, Decl1
);
5883 -- Associate the access to subprogram with its original access to
5884 -- protected subprogram type. Needed by the backend to know that this
5885 -- type corresponds with an access to protected subprogram type.
5887 Set_Original_Access_Type
(D_T2
, T
);
5889 -- Create Equivalent_Type, a record with two components for an access to
5890 -- object and an access to subprogram.
5893 Make_Component_Declaration
(Loc
,
5894 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5895 Component_Definition
=>
5896 Make_Component_Definition
(Loc
,
5897 Aliased_Present
=> False,
5898 Subtype_Indication
=>
5899 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5901 Make_Component_Declaration
(Loc
,
5902 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5903 Component_Definition
=>
5904 Make_Component_Definition
(Loc
,
5905 Aliased_Present
=> False,
5906 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5909 Make_Full_Type_Declaration
(Loc
,
5910 Defining_Identifier
=> E_T
,
5912 Make_Record_Definition
(Loc
,
5914 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
5916 Insert_Before_And_Analyze
(N
, Decl2
);
5917 Set_Equivalent_Type
(T
, E_T
);
5918 end Expand_Access_Protected_Subprogram_Type
;
5920 --------------------------
5921 -- Expand_Entry_Barrier --
5922 --------------------------
5924 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5925 Cond
: constant Node_Id
:= Condition
(Entry_Body_Formal_Part
(N
));
5926 Prot
: constant Entity_Id
:= Scope
(Ent
);
5927 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5929 Func_Id
: Entity_Id
:= Empty
;
5930 -- The entity of the barrier function
5932 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
5933 -- Check whether entity in Barrier is external to protected type.
5934 -- If so, barrier may not be properly synchronized.
5936 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
;
5937 -- Check whether N follows the Pure_Barriers restriction. Return OK if
5940 function Is_Simple_Barrier_Name
(N
: Node_Id
) return Boolean;
5941 -- Check whether entity name N denotes a component of the protected
5942 -- object. This is used to check the Simple_Barrier restriction.
5944 ----------------------
5945 -- Is_Global_Entity --
5946 ----------------------
5948 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
5953 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5957 if Ekind
(E
) = E_Variable
then
5959 -- If the variable is local to the barrier function generated
5960 -- during expansion, it is ok. If expansion is not performed,
5961 -- then Func is Empty so this test cannot succeed.
5963 if Scope
(E
) = Func_Id
then
5966 -- A protected call from a barrier to another object is ok
5968 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
5971 -- If the variable is within the package body we consider
5972 -- this safe. This is a common (if dubious) idiom.
5974 elsif S
= Scope
(Prot
)
5975 and then Ekind_In
(S
, E_Package
, E_Generic_Package
)
5976 and then Nkind
(Parent
(E
)) = N_Object_Declaration
5977 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
5982 Error_Msg_N
("potentially unsynchronized barrier??", N
);
5983 Error_Msg_N
("\& should be private component of type??", N
);
5989 end Is_Global_Entity
;
5991 procedure Check_Unprotected_Barrier
is
5992 new Traverse_Proc
(Is_Global_Entity
);
5994 ----------------------------
5995 -- Is_Simple_Barrier_Name --
5996 ----------------------------
5998 function Is_Simple_Barrier_Name
(N
: Node_Id
) return Boolean is
6002 -- Check for case of _object.all.field (note that the explicit
6003 -- dereference gets inserted by analyze/expand of _object.field).
6005 if Expander_Active
then
6006 Renamed
:= Renamed_Object
(Entity
(N
));
6010 and then Nkind
(Renamed
) = N_Selected_Component
6011 and then Chars
(Prefix
(Prefix
(Renamed
))) = Name_uObject
;
6013 return Scope
(Entity
(N
)) = Current_Scope
;
6015 end Is_Simple_Barrier_Name
;
6017 ---------------------
6018 -- Is_Pure_Barrier --
6019 ---------------------
6021 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
is
6022 function Is_Count_Attribute
(N
: Node_Id
) return Boolean;
6023 -- Check whether N is part of an expansion of the Count attribute.
6024 -- Return True if N represents the expanded function call.
6026 ------------------------
6027 -- Is_Count_Attribute --
6028 ------------------------
6030 function Is_Count_Attribute
(N
: Node_Id
) return Boolean is
6033 Nkind
(N
) = N_Function_Call
6034 and then Present
(Original_Node
(N
))
6035 and then Nkind
(Original_Node
(N
)) = N_Attribute_Reference
6036 and then Attribute_Name
(Original_Node
(N
)) = Name_Count
;
6037 end Is_Count_Attribute
;
6039 -- Start of processing for Is_Pure_Barrier
6043 when N_Expanded_Name
6046 if No
(Entity
(N
)) then
6050 if Present
(Parent
(N
))
6051 and then Is_Count_Attribute
(Parent
(N
))
6056 case Ekind
(Entity
(N
)) is
6059 | E_Enumeration_Literal
6068 -- A variable in the protected type is expanded as a
6071 if Is_Simple_Barrier_Name
(N
) then
6079 when N_Function_Call
=>
6080 if Is_Count_Attribute
(N
) then
6084 when N_Character_Literal
6093 if Ekind
(Entity
(N
)) = E_Operator
then
6097 when N_Short_Circuit
=>
6105 end Is_Pure_Barrier
;
6107 function Check_Pure_Barriers
is new Traverse_Func
(Is_Pure_Barrier
);
6111 Cond_Id
: Entity_Id
;
6112 Entry_Body
: Node_Id
;
6113 Func_Body
: Node_Id
;
6114 pragma Warnings
(Off
, Func_Body
);
6116 -- Start of processing for Expand_Entry_Barrier
6119 if No_Run_Time_Mode
then
6120 Error_Msg_CRT
("entry barrier", N
);
6124 -- The body of the entry barrier must be analyzed in the context of the
6125 -- protected object, but its scope is external to it, just as any other
6126 -- unprotected version of a protected operation. The specification has
6127 -- been produced when the protected type declaration was elaborated. We
6128 -- build the body, insert it in the enclosing scope, but analyze it in
6129 -- the current context. A more uniform approach would be to treat the
6130 -- barrier just as a protected function, and discard the protected
6131 -- version of it because it is never called.
6133 if Expander_Active
then
6134 Func_Body
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6135 Func_Id
:= Barrier_Function
(Ent
);
6136 Set_Corresponding_Spec
(Func_Body
, Func_Id
);
6138 Entry_Body
:= Parent
(Corresponding_Body
(Spec_Decl
));
6140 if Nkind
(Parent
(Entry_Body
)) = N_Subunit
then
6141 Entry_Body
:= Corresponding_Stub
(Parent
(Entry_Body
));
6144 Insert_Before_And_Analyze
(Entry_Body
, Func_Body
);
6146 Set_Discriminals
(Spec_Decl
);
6147 Set_Scope
(Func_Id
, Scope
(Prot
));
6150 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6153 -- Check Pure_Barriers restriction
6155 if Check_Pure_Barriers
(Cond
) = Abandon
then
6156 Check_Restriction
(Pure_Barriers
, Cond
);
6159 -- The Ravenscar profile restricts barriers to simple variables declared
6160 -- within the protected object. We also allow Boolean constants, since
6161 -- these appear in several published examples and are also allowed by
6164 -- Note that after analysis variables in this context will be replaced
6165 -- by the corresponding prival, that is to say a renaming of a selected
6166 -- component of the form _Object.Var. If expansion is disabled, as
6167 -- within a generic, we check that the entity appears in the current
6170 if Is_Entity_Name
(Cond
) then
6171 Cond_Id
:= Entity
(Cond
);
6173 -- Perform a small optimization of simple barrier functions. If the
6174 -- scope of the condition's entity is not the barrier function, then
6175 -- the condition does not depend on any of the generated renamings.
6176 -- If this is the case, eliminate the renamings as they are useless.
6177 -- This optimization is not performed when the condition was folded
6178 -- and validity checks are in effect because the original condition
6179 -- may have produced at least one check that depends on the generated
6183 and then Scope
(Cond_Id
) /= Func_Id
6184 and then not Validity_Check_Operands
6186 Set_Declarations
(Func_Body
, Empty_List
);
6189 if Cond_Id
= Standard_False
or else Cond_Id
= Standard_True
then
6192 elsif Is_Simple_Barrier_Name
(Cond
) then
6197 -- It is not a boolean variable or literal, so check the restriction.
6198 -- Note that it is safe to be calling Check_Restriction from here, even
6199 -- though this is part of the expander, since Expand_Entry_Barrier is
6200 -- called from Sem_Ch9 even in -gnatc mode.
6202 Check_Restriction
(Simple_Barriers
, Cond
);
6204 -- Emit warning if barrier contains global entities and is thus
6205 -- potentially unsynchronized.
6207 Check_Unprotected_Barrier
(Cond
);
6208 end Expand_Entry_Barrier
;
6210 ------------------------------
6211 -- Expand_N_Abort_Statement --
6212 ------------------------------
6214 -- Expand abort T1, T2, .. Tn; into:
6215 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6217 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6218 Loc
: constant Source_Ptr
:= Sloc
(N
);
6219 Tlist
: constant List_Id
:= Names
(N
);
6225 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6228 Tasknm
:= First
(Tlist
);
6230 while Present
(Tasknm
) loop
6233 -- A task interface class-wide type object is being aborted. Retrieve
6234 -- its _task_id by calling a dispatching routine.
6236 if Ada_Version
>= Ada_2005
6237 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6238 and then Is_Interface
(Etype
(Tasknm
))
6239 and then Is_Task_Interface
(Etype
(Tasknm
))
6241 Append_To
(Component_Associations
(Aggr
),
6242 Make_Component_Association
(Loc
,
6243 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6246 -- Task_Id (Tasknm._disp_get_task_id)
6248 Make_Unchecked_Type_Conversion
(Loc
,
6250 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
6252 Make_Selected_Component
(Loc
,
6253 Prefix
=> New_Copy_Tree
(Tasknm
),
6255 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6258 Append_To
(Component_Associations
(Aggr
),
6259 Make_Component_Association
(Loc
,
6260 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6261 Expression
=> Concurrent_Ref
(Tasknm
)));
6268 Make_Procedure_Call_Statement
(Loc
,
6269 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6270 Parameter_Associations
=> New_List
(
6271 Make_Qualified_Expression
(Loc
,
6272 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6273 Expression
=> Aggr
))));
6276 end Expand_N_Abort_Statement
;
6278 -------------------------------
6279 -- Expand_N_Accept_Statement --
6280 -------------------------------
6282 -- This procedure handles expansion of accept statements that stand alone,
6283 -- i.e. they are not part of an accept alternative. The expansion of
6284 -- accept statement in accept alternatives is handled by the routines
6285 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6286 -- following description applies only to stand alone accept statements.
6288 -- If there is no handled statement sequence, or only null statements, then
6289 -- this is called a trivial accept, and the expansion is:
6291 -- Accept_Trivial (entry-index)
6293 -- If there is a handled statement sequence, then the expansion is:
6300 -- Accept_Call (entry-index, Ann);
6301 -- Renaming_Declarations for formals
6302 -- <statement sequence from N_Accept_Statement node>
6303 -- Complete_Rendezvous;
6308 -- <exception handler from N_Accept_Statement node>
6309 -- Complete_Rendezvous;
6311 -- <exception handler from N_Accept_Statement node>
6312 -- Complete_Rendezvous;
6317 -- when all others =>
6318 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6321 -- The first three declarations were already inserted ahead of the accept
6322 -- statement by the Expand_Accept_Declarations procedure, which was called
6323 -- directly from the semantics during analysis of the accept statement,
6324 -- before analyzing its contained statements.
6326 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6327 -- from possible expansion activity (the original source of course does
6328 -- not have any declarations associated with the accept statement, since
6329 -- an accept statement has no declarative part). In particular, if the
6330 -- expander is active, the first such declaration is the declaration of
6331 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6333 -- The two blocks are merged into a single block if the inner block has
6334 -- no exception handlers, but otherwise two blocks are required, since
6335 -- exceptions might be raised in the exception handlers of the inner
6336 -- block, and Exceptional_Complete_Rendezvous must be called.
6338 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6339 Loc
: constant Source_Ptr
:= Sloc
(N
);
6340 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6341 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6342 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6343 Eent
: constant Entity_Id
:= Entity
(Ename
);
6344 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6345 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6346 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6352 -- If the accept statement is not part of a list, then its parent must
6353 -- be an accept alternative, and, as described above, we do not do any
6354 -- expansion for such accept statements at this level.
6356 if not Is_List_Member
(N
) then
6357 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6360 -- Trivial accept case (no statement sequence, or null statements).
6361 -- If the accept statement has declarations, then just insert them
6362 -- before the procedure call.
6364 elsif Trivial_Accept_OK
6365 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6367 -- Remove declarations for renamings, because the parameter block
6368 -- will not be assigned.
6375 D
:= First
(Declarations
(N
));
6376 while Present
(D
) loop
6378 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6386 if Present
(Declarations
(N
)) then
6387 Insert_Actions
(N
, Declarations
(N
));
6391 Make_Procedure_Call_Statement
(Loc
,
6392 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6393 Parameter_Associations
=> New_List
(
6394 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6398 -- Discard Entry_Address that was created for it, so it will not be
6399 -- emitted if this accept statement is in the statement part of a
6400 -- delay alternative.
6402 if Present
(Stats
) then
6403 Remove_Last_Elmt
(Acstack
);
6406 -- Case of statement sequence present
6409 -- Construct the block, using the declarations from the accept
6410 -- statement if any to initialize the declarations of the block.
6412 Blkent
:= Make_Temporary
(Loc
, 'A');
6413 Set_Ekind
(Blkent
, E_Block
);
6414 Set_Etype
(Blkent
, Standard_Void_Type
);
6415 Set_Scope
(Blkent
, Current_Scope
);
6418 Make_Block_Statement
(Loc
,
6419 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6420 Declarations
=> Declarations
(N
),
6421 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6423 -- For the analysis of the generated declarations, the parent node
6424 -- must be properly set.
6426 Set_Parent
(Block
, Parent
(N
));
6428 -- Prepend call to Accept_Call to main statement sequence If the
6429 -- accept has exception handlers, the statement sequence is wrapped
6430 -- in a block. Insert call and renaming declarations in the
6431 -- declarations of the block, so they are elaborated before the
6435 Make_Procedure_Call_Statement
(Loc
,
6436 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6437 Parameter_Associations
=> New_List
(
6438 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6439 New_Occurrence_Of
(Ann
, Loc
)));
6441 if Parent
(Stats
) = N
then
6442 Prepend
(Call
, Statements
(Stats
));
6444 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6449 Push_Scope
(Blkent
);
6457 D
:= First
(Declarations
(N
));
6458 while Present
(D
) loop
6461 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6463 -- The renaming declarations for the formals were created
6464 -- during analysis of the accept statement, and attached to
6465 -- the list of declarations. Place them now in the context
6466 -- of the accept block or subprogram.
6469 Typ
:= Entity
(Subtype_Mark
(D
));
6470 Insert_After
(Call
, D
);
6473 -- If the formal is class_wide, it does not have an actual
6474 -- subtype. The analysis of the renaming declaration creates
6475 -- one, but we need to retain the class-wide nature of the
6478 if Is_Class_Wide_Type
(Typ
) then
6479 Set_Etype
(Defining_Identifier
(D
), Typ
);
6490 -- Replace the accept statement by the new block
6495 -- Last step is to unstack the Accept_Address value
6497 Remove_Last_Elmt
(Acstack
);
6499 end Expand_N_Accept_Statement
;
6501 ----------------------------------
6502 -- Expand_N_Asynchronous_Select --
6503 ----------------------------------
6505 -- This procedure assumes that the trigger statement is an entry call or
6506 -- a dispatching procedure call. A delay alternative should already have
6507 -- been expanded into an entry call to the appropriate delay object Wait
6510 -- If the trigger is a task entry call, the select is implemented with
6511 -- a Task_Entry_Call:
6516 -- P : parms := (parm, parm, parm);
6518 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6520 -- procedure _clean is
6523 -- Cancel_Task_Entry_Call (C);
6530 -- (<acceptor-task>, -- Acceptor
6531 -- <entry-index>, -- E
6532 -- P'Address, -- Uninterpreted_Data
6533 -- Asynchronous_Call, -- Mode
6534 -- B); -- Rendezvous_Successful
6541 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6544 -- when Abort_Signal => Abort_Undefer;
6551 -- <triggered-statements>
6555 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6556 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6560 -- P : parms := (parm, parm, parm);
6562 -- Call_Simple (acceptor-task, entry-index, P'Address);
6568 -- so the task at hand is to convert the latter expansion into the former
6570 -- If the trigger is a protected entry call, the select is implemented
6571 -- with Protected_Entry_Call:
6574 -- P : E1_Params := (param, param, param);
6575 -- Bnn : Communications_Block;
6580 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6582 -- procedure _clean is
6585 -- if Enqueued (Bnn) then
6586 -- Cancel_Protected_Entry_Call (Bnn);
6593 -- Protected_Entry_Call
6594 -- (po._object'Access, -- Object
6595 -- <entry index>, -- E
6596 -- P'Address, -- Uninterpreted_Data
6597 -- Asynchronous_Call, -- Mode
6600 -- if Enqueued (Bnn) then
6604 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6607 -- when Abort_Signal => Abort_Undefer;
6610 -- if not Cancelled (Bnn) then
6611 -- <triggered-statements>
6615 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6619 -- P : E1_Params := (param, param, param);
6620 -- Bnn : Communications_Block;
6623 -- Protected_Entry_Call
6624 -- (po._object'Access, -- Object
6625 -- <entry index>, -- E
6626 -- P'Address, -- Uninterpreted_Data
6627 -- Simple_Call, -- Mode
6634 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6638 -- B : Boolean := False;
6639 -- Bnn : Communication_Block;
6640 -- C : Ada.Tags.Prim_Op_Kind;
6641 -- D : System.Storage_Elements.Dummy_Communication_Block;
6642 -- K : Ada.Tags.Tagged_Kind :=
6643 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6644 -- P : Parameters := (Param1 .. ParamN);
6649 -- if K = Ada.Tags.TK_Limited_Tagged
6650 -- or else K = Ada.Tags.TK_Tagged
6652 -- <dispatching-call>;
6653 -- <triggering-statements>;
6657 -- Ada.Tags.Get_Offset_Index
6658 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6660 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6662 -- if C = POK_Protected_Entry then
6664 -- procedure _clean is
6666 -- if Enqueued (Bnn) then
6667 -- Cancel_Protected_Entry_Call (Bnn);
6673 -- _Disp_Asynchronous_Select
6674 -- (<object>, S, P'Address, D, B);
6675 -- Bnn := Communication_Block (D);
6677 -- Param1 := P.Param1;
6679 -- ParamN := P.ParamN;
6681 -- if Enqueued (Bnn) then
6682 -- <abortable-statements>
6685 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6688 -- when Abort_Signal => Abort_Undefer;
6691 -- if not Cancelled (Bnn) then
6692 -- <triggering-statements>
6695 -- elsif C = POK_Task_Entry then
6697 -- procedure _clean is
6699 -- Cancel_Task_Entry_Call (U);
6705 -- _Disp_Asynchronous_Select
6706 -- (<object>, S, P'Address, D, B);
6707 -- Bnn := Communication_Bloc (D);
6709 -- Param1 := P.Param1;
6711 -- ParamN := P.ParamN;
6716 -- <abortable-statements>
6718 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6721 -- when Abort_Signal => Abort_Undefer;
6725 -- <triggering-statements>
6730 -- <dispatching-call>;
6731 -- <triggering-statements>
6736 -- The job is to convert this to the asynchronous form
6738 -- If the trigger is a delay statement, it will have been expanded into
6739 -- a call to one of the GNARL delay procedures. This routine will convert
6740 -- this into a protected entry call on a delay object and then continue
6741 -- processing as for a protected entry call trigger. This requires
6742 -- declaring a Delay_Block object and adding a pointer to this object to
6743 -- the parameter list of the delay procedure to form the parameter list of
6744 -- the entry call. This object is used by the runtime to queue the delay
6747 -- For a description of the use of P and the assignments after the call,
6748 -- see Expand_N_Entry_Call_Statement.
6750 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6751 Loc
: constant Source_Ptr
:= Sloc
(N
);
6752 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6753 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6755 Abort_Block_Ent
: Entity_Id
;
6756 Abortable_Block
: Node_Id
;
6759 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6760 Blk_Typ
: Entity_Id
;
6762 Call_Ent
: Entity_Id
;
6763 Cancel_Param
: Entity_Id
;
6764 Cleanup_Block
: Node_Id
;
6765 Cleanup_Block_Ent
: Entity_Id
;
6766 Cleanup_Stmts
: List_Id
;
6767 Conc_Typ_Stmts
: List_Id
;
6769 Dblock_Ent
: Entity_Id
;
6774 Enqueue_Call
: Node_Id
;
6777 Handler_Stmt
: Node_Id
;
6779 Lim_Typ_Stmts
: List_Id
;
6785 ProtE_Stmts
: List_Id
;
6786 ProtP_Stmts
: List_Id
;
6789 TaskE_Stmts
: List_Id
;
6792 B
: Entity_Id
; -- Call status flag
6793 Bnn
: Entity_Id
; -- Communication block
6794 C
: Entity_Id
; -- Call kind
6795 K
: Entity_Id
; -- Tagged kind
6796 P
: Entity_Id
; -- Parameter block
6797 S
: Entity_Id
; -- Primitive operation slot
6798 T
: Entity_Id
; -- Additional status flag
6800 procedure Rewrite_Abortable_Part
;
6801 -- If the trigger is a dispatching call, the expansion inserts multiple
6802 -- copies of the abortable part. This is both inefficient, and may lead
6803 -- to duplicate definitions that the back-end will reject, when the
6804 -- abortable part includes loops. This procedure rewrites the abortable
6805 -- part into a call to a generated procedure.
6807 ----------------------------
6808 -- Rewrite_Abortable_Part --
6809 ----------------------------
6811 procedure Rewrite_Abortable_Part
is
6812 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6817 Make_Subprogram_Body
(Loc
,
6819 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6820 Declarations
=> New_List
,
6821 Handled_Statement_Sequence
=>
6822 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6823 Insert_Before
(N
, Decl
);
6826 -- Rewrite abortable part into a call to this procedure
6830 Make_Procedure_Call_Statement
(Loc
,
6831 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6832 end Rewrite_Abortable_Part
;
6834 -- Start of processing for Expand_N_Asynchronous_Select
6837 -- Asynchronous select is not supported on restricted runtimes. Don't
6840 if Restricted_Profile
then
6844 Process_Statements_For_Controlled_Objects
(Trig
);
6845 Process_Statements_For_Controlled_Objects
(Abrt
);
6847 Ecall
:= Triggering_Statement
(Trig
);
6849 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6851 -- Retrieve Astats and Tstats now because the finalization machinery may
6852 -- wrap them in blocks.
6854 Astats
:= Statements
(Abrt
);
6855 Tstats
:= Statements
(Trig
);
6857 -- The arguments in the call may require dynamic allocation, and the
6858 -- call statement may have been transformed into a block. The block
6859 -- may contain additional declarations for internal entities, and the
6860 -- original call is found by sequential search.
6862 if Nkind
(Ecall
) = N_Block_Statement
then
6863 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6864 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6865 N_Entry_Call_Statement
)
6871 -- This is either a dispatching call or a delay statement used as a
6872 -- trigger which was expanded into a procedure call.
6874 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6875 if Ada_Version
>= Ada_2005
6877 (No
(Original_Node
(Ecall
))
6878 or else not Nkind_In
(Original_Node
(Ecall
),
6879 N_Delay_Relative_Statement
,
6880 N_Delay_Until_Statement
))
6882 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6884 Rewrite_Abortable_Part
;
6888 -- Call status flag processing, generate:
6889 -- B : Boolean := False;
6891 B
:= Build_B
(Loc
, Decls
);
6893 -- Communication block processing, generate:
6894 -- Bnn : Communication_Block;
6896 Bnn
:= Make_Temporary
(Loc
, 'B');
6898 Make_Object_Declaration
(Loc
,
6899 Defining_Identifier
=> Bnn
,
6900 Object_Definition
=>
6901 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
6903 -- Call kind processing, generate:
6904 -- C : Ada.Tags.Prim_Op_Kind;
6906 C
:= Build_C
(Loc
, Decls
);
6908 -- Tagged kind processing, generate:
6909 -- K : Ada.Tags.Tagged_Kind :=
6910 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6912 -- Dummy communication block, generate:
6913 -- D : Dummy_Communication_Block;
6916 Make_Object_Declaration
(Loc
,
6917 Defining_Identifier
=>
6918 Make_Defining_Identifier
(Loc
, Name_uD
),
6919 Object_Definition
=>
6921 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
6923 K
:= Build_K
(Loc
, Decls
, Obj
);
6925 -- Parameter block processing
6927 Blk_Typ
:= Build_Parameter_Block
6928 (Loc
, Actuals
, Formals
, Decls
);
6929 P
:= Parameter_Block_Pack
6930 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6932 -- Dispatch table slot processing, generate:
6935 S
:= Build_S
(Loc
, Decls
);
6937 -- Additional status flag processing, generate:
6940 T
:= Make_Temporary
(Loc
, 'T');
6942 Make_Object_Declaration
(Loc
,
6943 Defining_Identifier
=> T
,
6944 Object_Definition
=>
6945 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
6947 ------------------------------
6948 -- Protected entry handling --
6949 ------------------------------
6952 -- Param1 := P.Param1;
6954 -- ParamN := P.ParamN;
6956 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6959 -- Bnn := Communication_Block (D);
6961 Prepend_To
(Cleanup_Stmts
,
6962 Make_Assignment_Statement
(Loc
,
6963 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
6965 Make_Unchecked_Type_Conversion
(Loc
,
6967 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
6968 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
6971 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6973 Prepend_To
(Cleanup_Stmts
,
6974 Make_Procedure_Call_Statement
(Loc
,
6978 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
6980 Parameter_Associations
=>
6982 New_Copy_Tree
(Obj
), -- <object>
6983 New_Occurrence_Of
(S
, Loc
), -- S
6984 Make_Attribute_Reference
(Loc
, -- P'Address
6985 Prefix
=> New_Occurrence_Of
(P
, Loc
),
6986 Attribute_Name
=> Name_Address
),
6987 Make_Identifier
(Loc
, Name_uD
), -- D
6988 New_Occurrence_Of
(B
, Loc
)))); -- B
6991 -- if Enqueued (Bnn) then
6992 -- <abortable-statements>
6995 Append_To
(Cleanup_Stmts
,
6996 Make_Implicit_If_Statement
(N
,
6998 Make_Function_Call
(Loc
,
7000 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7001 Parameter_Associations
=>
7002 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
7005 New_Copy_List_Tree
(Astats
)));
7007 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7008 -- will then generate a _clean for the communication block Bnn.
7012 -- procedure _clean is
7014 -- if Enqueued (Bnn) then
7015 -- Cancel_Protected_Entry_Call (Bnn);
7024 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7026 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7028 -- Wrap the cleanup block in an exception handling block
7034 -- when Abort_Signal => Abort_Undefer;
7037 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7040 Make_Implicit_Label_Declaration
(Loc
,
7041 Defining_Identifier
=> Abort_Block_Ent
),
7044 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7047 -- if not Cancelled (Bnn) then
7048 -- <triggering-statements>
7051 Append_To
(ProtE_Stmts
,
7052 Make_Implicit_If_Statement
(N
,
7056 Make_Function_Call
(Loc
,
7058 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7059 Parameter_Associations
=>
7060 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7063 New_Copy_List_Tree
(Tstats
)));
7065 -------------------------
7066 -- Task entry handling --
7067 -------------------------
7070 -- Param1 := P.Param1;
7072 -- ParamN := P.ParamN;
7074 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7077 -- Bnn := Communication_Block (D);
7079 Append_To
(TaskE_Stmts
,
7080 Make_Assignment_Statement
(Loc
,
7082 New_Occurrence_Of
(Bnn
, Loc
),
7084 Make_Unchecked_Type_Conversion
(Loc
,
7086 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7087 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7090 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7092 Prepend_To
(TaskE_Stmts
,
7093 Make_Procedure_Call_Statement
(Loc
,
7096 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7097 Name_uDisp_Asynchronous_Select
),
7100 Parameter_Associations
=> New_List
(
7101 New_Copy_Tree
(Obj
), -- <object>
7102 New_Occurrence_Of
(S
, Loc
), -- S
7103 Make_Attribute_Reference
(Loc
, -- P'Address
7104 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7105 Attribute_Name
=> Name_Address
),
7106 Make_Identifier
(Loc
, Name_uD
), -- D
7107 New_Occurrence_Of
(B
, Loc
)))); -- B
7112 Prepend_To
(TaskE_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7116 -- <abortable-statements>
7118 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7121 (Cleanup_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7123 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7124 -- will generate a _clean for the additional status flag.
7128 -- procedure _clean is
7130 -- Cancel_Task_Entry_Call (U);
7138 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7140 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7142 -- Wrap the cleanup block in an exception handling block
7148 -- when Abort_Signal => Abort_Undefer;
7151 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7153 Append_To
(TaskE_Stmts
,
7154 Make_Implicit_Label_Declaration
(Loc
,
7155 Defining_Identifier
=> Abort_Block_Ent
));
7157 Append_To
(TaskE_Stmts
,
7159 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7163 -- <triggering-statements>
7166 Append_To
(TaskE_Stmts
,
7167 Make_Implicit_If_Statement
(N
,
7169 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7172 New_Copy_List_Tree
(Tstats
)));
7174 ----------------------------------
7175 -- Protected procedure handling --
7176 ----------------------------------
7179 -- <dispatching-call>;
7180 -- <triggering-statements>
7182 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7183 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7186 -- S := Ada.Tags.Get_Offset_Index
7187 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7190 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7193 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7195 Append_To
(Conc_Typ_Stmts
,
7196 Make_Procedure_Call_Statement
(Loc
,
7199 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7200 Name_uDisp_Get_Prim_Op_Kind
),
7202 Parameter_Associations
=>
7204 New_Copy_Tree
(Obj
),
7205 New_Occurrence_Of
(S
, Loc
),
7206 New_Occurrence_Of
(C
, Loc
))));
7209 -- if C = POK_Procedure_Entry then
7211 -- elsif C = POK_Task_Entry then
7217 Append_To
(Conc_Typ_Stmts
,
7218 Make_Implicit_If_Statement
(N
,
7222 New_Occurrence_Of
(C
, Loc
),
7224 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7231 Make_Elsif_Part
(Loc
,
7235 New_Occurrence_Of
(C
, Loc
),
7237 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7246 -- <dispatching-call>;
7247 -- <triggering-statements>
7249 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7250 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7253 -- if K = Ada.Tags.TK_Limited_Tagged
7254 -- or else K = Ada.Tags.TK_Tagged
7262 Make_Implicit_If_Statement
(N
,
7263 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7264 Then_Statements
=> Lim_Typ_Stmts
,
7265 Else_Statements
=> Conc_Typ_Stmts
));
7268 Make_Block_Statement
(Loc
,
7271 Handled_Statement_Sequence
=>
7272 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7277 -- Delay triggering statement processing
7280 -- Add a Delay_Block object to the parameter list of the delay
7281 -- procedure to form the parameter list of the Wait entry call.
7283 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7285 Pdef
:= Entity
(Name
(Ecall
));
7287 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7289 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7291 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7293 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7295 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7296 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7299 Append_To
(Parameter_Associations
(Ecall
),
7300 Make_Attribute_Reference
(Loc
,
7301 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7302 Attribute_Name
=> Name_Unchecked_Access
));
7304 -- Create the inner block to protect the abortable part
7306 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7308 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7311 Make_Block_Statement
(Loc
,
7312 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7313 Handled_Statement_Sequence
=>
7314 Make_Handled_Sequence_Of_Statements
(Loc
,
7315 Statements
=> Astats
),
7316 Has_Created_Identifier
=> True,
7317 Is_Asynchronous_Call_Block
=> True);
7319 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7322 Make_Implicit_If_Statement
(N
,
7324 Make_Function_Call
(Loc
,
7325 Name
=> Enqueue_Call
,
7326 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7328 New_List
(Make_Block_Statement
(Loc
,
7329 Handled_Statement_Sequence
=>
7330 Make_Handled_Sequence_Of_Statements
(Loc
,
7331 Statements
=> New_List
(
7332 Make_Implicit_Label_Declaration
(Loc
,
7333 Defining_Identifier
=> Blk_Ent
,
7334 Label_Construct
=> Abortable_Block
),
7336 Exception_Handlers
=> Hdle
)))));
7338 Stmts
:= New_List
(Ecall
);
7340 -- Construct statement sequence for new block
7343 Make_Implicit_If_Statement
(N
,
7345 Make_Function_Call
(Loc
,
7346 Name
=> New_Occurrence_Of
(
7347 RTE
(RE_Timed_Out
), Loc
),
7348 Parameter_Associations
=> New_List
(
7349 Make_Attribute_Reference
(Loc
,
7350 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7351 Attribute_Name
=> Name_Unchecked_Access
))),
7352 Then_Statements
=> Tstats
));
7354 -- The result is the new block
7356 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7359 Make_Block_Statement
(Loc
,
7360 Declarations
=> New_List
(
7361 Make_Object_Declaration
(Loc
,
7362 Defining_Identifier
=> Dblock_Ent
,
7363 Aliased_Present
=> True,
7364 Object_Definition
=>
7365 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7367 Handled_Statement_Sequence
=>
7368 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7378 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7379 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7381 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7382 Decls
:= Declarations
(Ecall
);
7384 if Is_Protected_Type
(Etype
(Concval
)) then
7386 -- Get the declarations of the block expanded from the entry call
7388 Decl
:= First
(Decls
);
7389 while Present
(Decl
)
7390 and then (Nkind
(Decl
) /= N_Object_Declaration
7391 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7392 RE_Communication_Block
))
7397 pragma Assert
(Present
(Decl
));
7398 Cancel_Param
:= Defining_Identifier
(Decl
);
7400 -- Change the mode of the Protected_Entry_Call call
7402 -- Protected_Entry_Call (
7403 -- Object => po._object'Access,
7404 -- E => <entry index>;
7405 -- Uninterpreted_Data => P'Address;
7406 -- Mode => Asynchronous_Call;
7409 -- Skip assignments to temporaries created for in-out parameters
7411 -- This makes unwarranted assumptions about the shape of the expanded
7412 -- tree for the call, and should be cleaned up ???
7414 Stmt
:= First
(Stmts
);
7415 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7421 Param
:= First
(Parameter_Associations
(Call
));
7422 while Present
(Param
)
7423 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7428 pragma Assert
(Present
(Param
));
7429 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7432 -- Append an if statement to execute the abortable part
7435 -- if Enqueued (Bnn) then
7438 Make_Implicit_If_Statement
(N
,
7440 Make_Function_Call
(Loc
,
7441 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7442 Parameter_Associations
=> New_List
(
7443 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7444 Then_Statements
=> Astats
));
7447 Make_Block_Statement
(Loc
,
7448 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7449 Handled_Statement_Sequence
=>
7450 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7451 Has_Created_Identifier
=> True,
7452 Is_Asynchronous_Call_Block
=> True);
7454 -- Aborts are not deferred at beginning of exception handlers in
7457 if ZCX_Exceptions
then
7458 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7461 Handler_Stmt
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
7465 Make_Block_Statement
(Loc
,
7466 Handled_Statement_Sequence
=>
7467 Make_Handled_Sequence_Of_Statements
(Loc
,
7468 Statements
=> New_List
(
7469 Make_Implicit_Label_Declaration
(Loc
,
7470 Defining_Identifier
=> Blk_Ent
,
7471 Label_Construct
=> Abortable_Block
),
7476 Exception_Handlers
=> New_List
(
7477 Make_Implicit_Exception_Handler
(Loc
,
7479 -- when Abort_Signal =>
7480 -- Abort_Undefer.all;
7482 Exception_Choices
=>
7483 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7484 Statements
=> New_List
(Handler_Stmt
))))),
7486 -- if not Cancelled (Bnn) then
7487 -- triggered statements
7490 Make_Implicit_If_Statement
(N
,
7491 Condition
=> Make_Op_Not
(Loc
,
7493 Make_Function_Call
(Loc
,
7494 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7495 Parameter_Associations
=> New_List
(
7496 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7497 Then_Statements
=> Tstats
));
7499 -- Asynchronous task entry call
7506 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7508 -- Insert declaration of B in declarations of existing block
7511 Make_Object_Declaration
(Loc
,
7512 Defining_Identifier
=> B
,
7513 Object_Definition
=>
7514 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7516 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7518 -- Insert the declaration of C in the declarations of the existing
7519 -- block. The variable is initialized to something (True or False,
7520 -- does not matter) to prevent CodePeer from complaining about a
7521 -- possible read of an uninitialized variable.
7524 Make_Object_Declaration
(Loc
,
7525 Defining_Identifier
=> Cancel_Param
,
7526 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
7527 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
),
7528 Has_Init_Expression
=> True));
7530 -- Remove and save the call to Call_Simple
7532 Stmt
:= First
(Stmts
);
7534 -- Skip assignments to temporaries created for in-out parameters.
7535 -- This makes unwarranted assumptions about the shape of the expanded
7536 -- tree for the call, and should be cleaned up ???
7538 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7544 -- Create the inner block to protect the abortable part
7546 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7548 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7551 Make_Block_Statement
(Loc
,
7552 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7553 Handled_Statement_Sequence
=>
7554 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7555 Has_Created_Identifier
=> True,
7556 Is_Asynchronous_Call_Block
=> True);
7559 Make_Block_Statement
(Loc
,
7560 Handled_Statement_Sequence
=>
7561 Make_Handled_Sequence_Of_Statements
(Loc
,
7562 Statements
=> New_List
(
7563 Make_Implicit_Label_Declaration
(Loc
,
7564 Defining_Identifier
=> Blk_Ent
,
7565 Label_Construct
=> Abortable_Block
),
7567 Exception_Handlers
=> Hdle
)));
7569 -- Create new call statement
7571 Params
:= Parameter_Associations
(Call
);
7574 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7575 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7578 Make_Procedure_Call_Statement
(Loc
,
7579 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7580 Parameter_Associations
=> Params
));
7582 -- Construct statement sequence for new block
7585 Make_Implicit_If_Statement
(N
,
7587 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7588 Then_Statements
=> Tstats
));
7590 -- Protected the call against abort
7592 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7595 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7597 -- The result is the new block
7600 Make_Block_Statement
(Loc
,
7601 Declarations
=> Decls
,
7602 Handled_Statement_Sequence
=>
7603 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7606 end Expand_N_Asynchronous_Select
;
7608 -------------------------------------
7609 -- Expand_N_Conditional_Entry_Call --
7610 -------------------------------------
7612 -- The conditional task entry call is converted to a call to
7617 -- P : parms := (parm, parm, parm);
7621 -- (<acceptor-task>, -- Acceptor
7622 -- <entry-index>, -- E
7623 -- P'Address, -- Uninterpreted_Data
7624 -- Conditional_Call, -- Mode
7625 -- B); -- Rendezvous_Successful
7630 -- normal-statements
7636 -- For a description of the use of P and the assignments after the call,
7637 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7638 -- conditional entry call has already been expanded (by the Expand_N_Entry
7639 -- _Call_Statement procedure) as follows:
7642 -- P : parms := (parm, parm, parm);
7644 -- ... info for in-out parameters
7645 -- Call_Simple (acceptor-task, entry-index, P'Address);
7651 -- so the task at hand is to convert the latter expansion into the former
7653 -- The conditional protected entry call is converted to a call to
7654 -- Protected_Entry_Call:
7657 -- P : parms := (parm, parm, parm);
7658 -- Bnn : Communications_Block;
7661 -- Protected_Entry_Call
7662 -- (po._object'Access, -- Object
7663 -- <entry index>, -- E
7664 -- P'Address, -- Uninterpreted_Data
7665 -- Conditional_Call, -- Mode
7670 -- if Cancelled (Bnn) then
7673 -- normal-statements
7677 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7681 -- B : Boolean := False;
7682 -- C : Ada.Tags.Prim_Op_Kind;
7683 -- K : Ada.Tags.Tagged_Kind :=
7684 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7685 -- P : Parameters := (Param1 .. ParamN);
7689 -- if K = Ada.Tags.TK_Limited_Tagged
7690 -- or else K = Ada.Tags.TK_Tagged
7692 -- <dispatching-call>;
7693 -- <triggering-statements>
7697 -- Ada.Tags.Get_Offset_Index
7698 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7700 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7702 -- if C = POK_Protected_Entry
7703 -- or else C = POK_Task_Entry
7705 -- Param1 := P.Param1;
7707 -- ParamN := P.ParamN;
7711 -- if C = POK_Procedure
7712 -- or else C = POK_Protected_Procedure
7713 -- or else C = POK_Task_Procedure
7715 -- <dispatching-call>;
7718 -- <triggering-statements>
7720 -- <else-statements>
7725 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7726 Loc
: constant Source_Ptr
:= Sloc
(N
);
7727 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7728 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7731 Blk_Typ
: Entity_Id
;
7733 Call_Ent
: Entity_Id
;
7734 Conc_Typ_Stmts
: List_Id
;
7738 Lim_Typ_Stmts
: List_Id
;
7745 Transient_Blk
: Node_Id
;
7748 B
: Entity_Id
; -- Call status flag
7749 C
: Entity_Id
; -- Call kind
7750 K
: Entity_Id
; -- Tagged kind
7751 P
: Entity_Id
; -- Parameter block
7752 S
: Entity_Id
; -- Primitive operation slot
7755 Process_Statements_For_Controlled_Objects
(N
);
7757 if Ada_Version
>= Ada_2005
7758 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7760 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7765 -- Call status flag processing, generate:
7766 -- B : Boolean := False;
7768 B
:= Build_B
(Loc
, Decls
);
7770 -- Call kind processing, generate:
7771 -- C : Ada.Tags.Prim_Op_Kind;
7773 C
:= Build_C
(Loc
, Decls
);
7775 -- Tagged kind processing, generate:
7776 -- K : Ada.Tags.Tagged_Kind :=
7777 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7779 K
:= Build_K
(Loc
, Decls
, Obj
);
7781 -- Parameter block processing
7783 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7784 P
:= Parameter_Block_Pack
7785 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7787 -- Dispatch table slot processing, generate:
7790 S
:= Build_S
(Loc
, Decls
);
7793 -- S := Ada.Tags.Get_Offset_Index
7794 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7797 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7800 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7802 Append_To
(Conc_Typ_Stmts
,
7803 Make_Procedure_Call_Statement
(Loc
,
7806 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7807 Name_uDisp_Conditional_Select
),
7809 Parameter_Associations
=>
7811 New_Copy_Tree
(Obj
), -- <object>
7812 New_Occurrence_Of
(S
, Loc
), -- S
7813 Make_Attribute_Reference
(Loc
, -- P'Address
7814 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7815 Attribute_Name
=> Name_Address
),
7816 New_Occurrence_Of
(C
, Loc
), -- C
7817 New_Occurrence_Of
(B
, Loc
)))); -- B
7820 -- if C = POK_Protected_Entry
7821 -- or else C = POK_Task_Entry
7823 -- Param1 := P.Param1;
7825 -- ParamN := P.ParamN;
7828 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7830 -- Generate the if statement only when the packed parameters need
7831 -- explicit assignments to their corresponding actuals.
7833 if Present
(Unpack
) then
7834 Append_To
(Conc_Typ_Stmts
,
7835 Make_Implicit_If_Statement
(N
,
7841 New_Occurrence_Of
(C
, Loc
),
7843 New_Occurrence_Of
(RTE
(
7844 RE_POK_Protected_Entry
), Loc
)),
7849 New_Occurrence_Of
(C
, Loc
),
7851 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
7853 Then_Statements
=> Unpack
));
7858 -- if C = POK_Procedure
7859 -- or else C = POK_Protected_Procedure
7860 -- or else C = POK_Task_Procedure
7862 -- <dispatching-call>
7864 -- <normal-statements>
7866 -- <else-statements>
7869 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7871 Prepend_To
(N_Stats
,
7872 Make_Implicit_If_Statement
(N
,
7878 New_Occurrence_Of
(C
, Loc
),
7880 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
7887 New_Occurrence_Of
(C
, Loc
),
7889 New_Occurrence_Of
(RTE
(
7890 RE_POK_Protected_Procedure
), Loc
)),
7895 New_Occurrence_Of
(C
, Loc
),
7897 New_Occurrence_Of
(RTE
(
7898 RE_POK_Task_Procedure
), Loc
)))),
7903 Append_To
(Conc_Typ_Stmts
,
7904 Make_Implicit_If_Statement
(N
,
7905 Condition
=> New_Occurrence_Of
(B
, Loc
),
7906 Then_Statements
=> N_Stats
,
7907 Else_Statements
=> Else_Statements
(N
)));
7910 -- <dispatching-call>;
7911 -- <triggering-statements>
7913 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
7914 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
7917 -- if K = Ada.Tags.TK_Limited_Tagged
7918 -- or else K = Ada.Tags.TK_Tagged
7926 Make_Implicit_If_Statement
(N
,
7927 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7928 Then_Statements
=> Lim_Typ_Stmts
,
7929 Else_Statements
=> Conc_Typ_Stmts
));
7932 Make_Block_Statement
(Loc
,
7935 Handled_Statement_Sequence
=>
7936 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7938 -- As described above, the entry alternative is transformed into a
7939 -- block that contains the gnulli call, and possibly assignment
7940 -- statements for in-out parameters. The gnulli call may itself be
7941 -- rewritten into a transient block if some unconstrained parameters
7942 -- require it. We need to retrieve the call to complete its parameter
7947 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
7949 if Present
(Transient_Blk
)
7950 and then Nkind
(Transient_Blk
) = N_Block_Statement
7952 Blk
:= Transient_Blk
;
7955 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
7956 Stmt
:= First
(Stmts
);
7957 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7962 Params
:= Parameter_Associations
(Call
);
7964 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
7966 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7968 Param
:= First
(Params
);
7969 while Present
(Param
)
7970 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7975 pragma Assert
(Present
(Param
));
7977 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
7981 -- Find the Communication_Block parameter for the call to the
7982 -- Cancelled function.
7984 Decl
:= First
(Declarations
(Blk
));
7985 while Present
(Decl
)
7986 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7987 RE_Communication_Block
)
7992 -- Add an if statement to execute the else part if the call
7993 -- does not succeed (as indicated by the Cancelled predicate).
7996 Make_Implicit_If_Statement
(N
,
7997 Condition
=> Make_Function_Call
(Loc
,
7998 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7999 Parameter_Associations
=> New_List
(
8000 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
8001 Then_Statements
=> Else_Statements
(N
),
8002 Else_Statements
=> Statements
(Alt
)));
8005 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8007 -- Insert declaration of B in declarations of existing block
8009 if No
(Declarations
(Blk
)) then
8010 Set_Declarations
(Blk
, New_List
);
8013 Prepend_To
(Declarations
(Blk
),
8014 Make_Object_Declaration
(Loc
,
8015 Defining_Identifier
=> B
,
8016 Object_Definition
=>
8017 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8019 -- Create new call statement
8022 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8023 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
8026 Make_Procedure_Call_Statement
(Loc
,
8027 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
8028 Parameter_Associations
=> Params
));
8030 -- Construct statement sequence for new block
8033 Make_Implicit_If_Statement
(N
,
8034 Condition
=> New_Occurrence_Of
(B
, Loc
),
8035 Then_Statements
=> Statements
(Alt
),
8036 Else_Statements
=> Else_Statements
(N
)));
8039 -- The result is the new block
8042 Make_Block_Statement
(Loc
,
8043 Declarations
=> Declarations
(Blk
),
8044 Handled_Statement_Sequence
=>
8045 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8049 end Expand_N_Conditional_Entry_Call
;
8051 ---------------------------------------
8052 -- Expand_N_Delay_Relative_Statement --
8053 ---------------------------------------
8055 -- Delay statement is implemented as a procedure call to Delay_For
8056 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8057 -- simple delays imposed by the use of Protected Objects.
8059 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8060 Loc
: constant Source_Ptr
:= Sloc
(N
);
8064 -- Try to use System.Relative_Delays.Delay_For only if available. This
8065 -- is the implementation used on restricted platforms when Ada.Calendar
8066 -- is not available.
8068 if RTE_Available
(RO_RD_Delay_For
) then
8069 Proc
:= RTE
(RO_RD_Delay_For
);
8071 -- Otherwise, use Ada.Calendar.Delays.Delay_For and emit an error
8072 -- message if not available.
8075 Proc
:= RTE
(RO_CA_Delay_For
);
8079 Make_Procedure_Call_Statement
(Loc
,
8080 Name
=> New_Occurrence_Of
(Proc
, Loc
),
8081 Parameter_Associations
=> New_List
(Expression
(N
))));
8083 end Expand_N_Delay_Relative_Statement
;
8085 ------------------------------------
8086 -- Expand_N_Delay_Until_Statement --
8087 ------------------------------------
8089 -- Delay Until statement is implemented as a procedure call to
8090 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8092 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8093 Loc
: constant Source_Ptr
:= Sloc
(N
);
8097 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8098 Typ
:= RTE
(RO_CA_Delay_Until
);
8100 Typ
:= RTE
(RO_RT_Delay_Until
);
8104 Make_Procedure_Call_Statement
(Loc
,
8105 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8106 Parameter_Associations
=> New_List
(Expression
(N
))));
8109 end Expand_N_Delay_Until_Statement
;
8111 -------------------------
8112 -- Expand_N_Entry_Body --
8113 -------------------------
8115 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8117 -- Associate discriminals with the next protected operation body to be
8120 if Present
(Next_Protected_Operation
(N
)) then
8121 Set_Discriminals
(Parent
(Current_Scope
));
8123 end Expand_N_Entry_Body
;
8125 -----------------------------------
8126 -- Expand_N_Entry_Call_Statement --
8127 -----------------------------------
8129 -- An entry call is expanded into GNARLI calls to implement a simple entry
8130 -- call (see Build_Simple_Entry_Call).
8132 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8138 if No_Run_Time_Mode
then
8139 Error_Msg_CRT
("entry call", N
);
8143 -- If this entry call is part of an asynchronous select, don't expand it
8144 -- here; it will be expanded with the select statement. Don't expand
8145 -- timed entry calls either, as they are translated into asynchronous
8148 -- ??? This whole approach is questionable; it may be better to go back
8149 -- to allowing the expansion to take place and then attempting to fix it
8150 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8151 -- whether the expanded call is on a task or protected entry.
8153 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8154 or else N
/= Triggering_Statement
(Parent
(N
)))
8155 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8156 or else N
/= Entry_Call_Statement
(Parent
(N
))
8157 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8159 Extract_Entry
(N
, Concval
, Ename
, Index
);
8160 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8162 end Expand_N_Entry_Call_Statement
;
8164 --------------------------------
8165 -- Expand_N_Entry_Declaration --
8166 --------------------------------
8168 -- If there are parameters, then first, each of the formals is marked by
8169 -- setting Is_Entry_Formal. Next a record type is built which is used to
8170 -- hold the parameter values. The name of this record type is entryP where
8171 -- entry is the name of the entry, with an additional corresponding access
8172 -- type called entryPA. The record type has matching components for each
8173 -- formal (the component names are the same as the formal names). For
8174 -- elementary types, the component type matches the formal type. For
8175 -- composite types, an access type is declared (with the name formalA)
8176 -- which designates the formal type, and the type of the component is this
8177 -- access type. Finally the Entry_Component of each formal is set to
8178 -- reference the corresponding record component.
8180 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8181 Loc
: constant Source_Ptr
:= Sloc
(N
);
8182 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8183 Components
: List_Id
;
8186 Last_Decl
: Node_Id
;
8187 Component
: Entity_Id
;
8190 Rec_Ent
: Entity_Id
;
8191 Acc_Ent
: Entity_Id
;
8194 Formal
:= First_Formal
(Entry_Ent
);
8197 -- Most processing is done only if parameters are present
8199 if Present
(Formal
) then
8200 Components
:= New_List
;
8202 -- Loop through formals
8204 while Present
(Formal
) loop
8205 Set_Is_Entry_Formal
(Formal
);
8207 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8208 Set_Entry_Component
(Formal
, Component
);
8209 Set_Entry_Formal
(Component
, Formal
);
8210 Ftype
:= Etype
(Formal
);
8212 -- Declare new access type and then append
8214 Ctype
:= Make_Temporary
(Loc
, 'A');
8215 Set_Is_Param_Block_Component_Type
(Ctype
);
8218 Make_Full_Type_Declaration
(Loc
,
8219 Defining_Identifier
=> Ctype
,
8221 Make_Access_To_Object_Definition
(Loc
,
8222 All_Present
=> True,
8223 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8224 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8226 Insert_After
(Last_Decl
, Decl
);
8229 Append_To
(Components
,
8230 Make_Component_Declaration
(Loc
,
8231 Defining_Identifier
=> Component
,
8232 Component_Definition
=>
8233 Make_Component_Definition
(Loc
,
8234 Aliased_Present
=> False,
8235 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8237 Next_Formal_With_Extras
(Formal
);
8240 -- Create the Entry_Parameter_Record declaration
8242 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8245 Make_Full_Type_Declaration
(Loc
,
8246 Defining_Identifier
=> Rec_Ent
,
8248 Make_Record_Definition
(Loc
,
8250 Make_Component_List
(Loc
,
8251 Component_Items
=> Components
)));
8253 Insert_After
(Last_Decl
, Decl
);
8256 -- Construct and link in the corresponding access type
8258 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8260 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8263 Make_Full_Type_Declaration
(Loc
,
8264 Defining_Identifier
=> Acc_Ent
,
8266 Make_Access_To_Object_Definition
(Loc
,
8267 All_Present
=> True,
8268 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8270 Insert_After
(Last_Decl
, Decl
);
8272 end Expand_N_Entry_Declaration
;
8274 -----------------------------
8275 -- Expand_N_Protected_Body --
8276 -----------------------------
8278 -- Protected bodies are expanded to the completion of the subprograms
8279 -- created for the corresponding protected type. These are a protected and
8280 -- unprotected version of each protected subprogram in the object, a
8281 -- function to calculate each entry barrier, and a procedure to execute the
8282 -- sequence of statements of each protected entry body. For example, for
8283 -- protected type ptype:
8286 -- (O : System.Address;
8287 -- E : Protected_Entry_Index)
8290 -- <discriminant renamings>
8291 -- <private object renamings>
8293 -- return <barrier expression>;
8296 -- procedure pprocN (_object : in out poV;...) is
8297 -- <discriminant renamings>
8298 -- <private object renamings>
8300 -- <sequence of statements>
8303 -- procedure pprocP (_object : in out poV;...) is
8304 -- procedure _clean is
8307 -- ptypeS (_object, Pn);
8308 -- Unlock (_object._object'Access);
8309 -- Abort_Undefer.all;
8314 -- Lock (_object._object'Access);
8315 -- pprocN (_object;...);
8320 -- function pfuncN (_object : poV;...) return Return_Type is
8321 -- <discriminant renamings>
8322 -- <private object renamings>
8324 -- <sequence of statements>
8327 -- function pfuncP (_object : poV) return Return_Type is
8328 -- procedure _clean is
8330 -- Unlock (_object._object'Access);
8331 -- Abort_Undefer.all;
8336 -- Lock (_object._object'Access);
8337 -- return pfuncN (_object);
8344 -- (O : System.Address;
8345 -- P : System.Address;
8346 -- E : Protected_Entry_Index)
8348 -- <discriminant renamings>
8349 -- <private object renamings>
8350 -- type poVP is access poV;
8351 -- _Object : ptVP := ptVP!(O);
8355 -- <statement sequence>
8356 -- Complete_Entry_Body (_Object._Object);
8358 -- when all others =>
8359 -- Exceptional_Complete_Entry_Body (
8360 -- _Object._Object, Get_GNAT_Exception);
8364 -- The type poV is the record created for the protected type to hold
8365 -- the state of the protected object.
8367 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8368 Loc
: constant Source_Ptr
:= Sloc
(N
);
8369 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8371 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8372 -- This flag indicates whether the lock free implementation is active
8374 Current_Node
: Node_Id
;
8375 Disp_Op_Body
: Node_Id
;
8376 New_Op_Body
: Node_Id
;
8380 function Build_Dispatching_Subprogram_Body
8383 Prot_Bod
: Node_Id
) return Node_Id
;
8384 -- Build a dispatching version of the protected subprogram body. The
8385 -- newly generated subprogram contains a call to the original protected
8386 -- body. The following code is generated:
8388 -- function <protected-function-name> (Param1 .. ParamN) return
8391 -- return <protected-function-name>P (Param1 .. ParamN);
8392 -- end <protected-function-name>;
8396 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8398 -- <protected-procedure-name>P (Param1 .. ParamN);
8399 -- end <protected-procedure-name>
8401 ---------------------------------------
8402 -- Build_Dispatching_Subprogram_Body --
8403 ---------------------------------------
8405 function Build_Dispatching_Subprogram_Body
8408 Prot_Bod
: Node_Id
) return Node_Id
8410 Loc
: constant Source_Ptr
:= Sloc
(N
);
8417 -- Generate a specification without a letter suffix in order to
8418 -- override an interface function or procedure.
8420 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8422 -- The formal parameters become the actuals of the protected function
8423 -- or procedure call.
8425 Actuals
:= New_List
;
8426 Formal
:= First
(Parameter_Specifications
(Spec
));
8427 while Present
(Formal
) loop
8429 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8433 if Nkind
(Spec
) = N_Procedure_Specification
then
8436 Make_Procedure_Call_Statement
(Loc
,
8438 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8439 Parameter_Associations
=> Actuals
));
8442 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8446 Make_Simple_Return_Statement
(Loc
,
8448 Make_Function_Call
(Loc
,
8450 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8451 Parameter_Associations
=> Actuals
)));
8455 Make_Subprogram_Body
(Loc
,
8456 Declarations
=> Empty_List
,
8457 Specification
=> Spec
,
8458 Handled_Statement_Sequence
=>
8459 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8460 end Build_Dispatching_Subprogram_Body
;
8462 -- Start of processing for Expand_N_Protected_Body
8465 if No_Run_Time_Mode
then
8466 Error_Msg_CRT
("protected body", N
);
8470 -- This is the proper body corresponding to a stub. The declarations
8471 -- must be inserted at the point of the stub, which in turn is in the
8472 -- declarative part of the parent unit.
8474 if Nkind
(Parent
(N
)) = N_Subunit
then
8475 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8480 Op_Body
:= First
(Declarations
(N
));
8482 -- The protected body is replaced with the bodies of its protected
8483 -- operations, and the declarations for internal objects that may
8484 -- have been created for entry family bounds.
8486 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8489 while Present
(Op_Body
) loop
8490 case Nkind
(Op_Body
) is
8491 when N_Subprogram_Declaration
=>
8494 when N_Subprogram_Body
=>
8496 -- Do not create bodies for eliminated operations
8498 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8499 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8501 if Lock_Free_Active
then
8503 Build_Lock_Free_Unprotected_Subprogram_Body
8507 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8510 Insert_After
(Current_Node
, New_Op_Body
);
8511 Current_Node
:= New_Op_Body
;
8512 Analyze
(New_Op_Body
);
8514 -- Build the corresponding protected operation. It may
8515 -- appear that this is needed only if this is a visible
8516 -- operation of the type, or if it is an interrupt handler,
8517 -- and this was the strategy used previously in GNAT.
8519 -- However, the operation may be exported through a 'Access
8520 -- to an external caller. This is the common idiom in code
8521 -- that uses the Ada 2005 Timing_Events package. As a result
8522 -- we need to produce the protected body for both visible
8523 -- and private operations, as well as operations that only
8524 -- have a body in the source, and for which we create a
8525 -- declaration in the protected body itself.
8527 if Present
(Corresponding_Spec
(Op_Body
)) then
8528 if Lock_Free_Active
then
8530 Build_Lock_Free_Protected_Subprogram_Body
8531 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8534 Build_Protected_Subprogram_Body
8535 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8538 Insert_After
(Current_Node
, New_Op_Body
);
8539 Analyze
(New_Op_Body
);
8541 Current_Node
:= New_Op_Body
;
8543 -- Generate an overriding primitive operation body for
8544 -- this subprogram if the protected type implements an
8547 if Ada_Version
>= Ada_2005
8549 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8552 Build_Dispatching_Subprogram_Body
8553 (Op_Body
, Pid
, New_Op_Body
);
8555 Insert_After
(Current_Node
, Disp_Op_Body
);
8556 Analyze
(Disp_Op_Body
);
8558 Current_Node
:= Disp_Op_Body
;
8563 when N_Entry_Body
=>
8564 Op_Id
:= Defining_Identifier
(Op_Body
);
8565 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8567 Insert_After
(Current_Node
, New_Op_Body
);
8568 Current_Node
:= New_Op_Body
;
8569 Analyze
(New_Op_Body
);
8571 when N_Implicit_Label_Declaration
=>
8574 when N_Itype_Reference
=>
8575 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8577 when N_Freeze_Entity
=>
8578 New_Op_Body
:= New_Copy
(Op_Body
);
8580 if Present
(Entity
(Op_Body
))
8581 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8583 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8586 Insert_After
(Current_Node
, New_Op_Body
);
8587 Current_Node
:= New_Op_Body
;
8588 Analyze
(New_Op_Body
);
8591 New_Op_Body
:= New_Copy
(Op_Body
);
8592 Insert_After
(Current_Node
, New_Op_Body
);
8593 Current_Node
:= New_Op_Body
;
8594 Analyze
(New_Op_Body
);
8596 when N_Object_Declaration
=>
8597 pragma Assert
(not Comes_From_Source
(Op_Body
));
8598 New_Op_Body
:= New_Copy
(Op_Body
);
8599 Insert_After
(Current_Node
, New_Op_Body
);
8600 Current_Node
:= New_Op_Body
;
8601 Analyze
(New_Op_Body
);
8604 raise Program_Error
;
8610 -- Finally, create the body of the function that maps an entry index
8611 -- into the corresponding body index, except when there is no entry, or
8612 -- in a Ravenscar-like profile.
8614 if Corresponding_Runtime_Package
(Pid
) =
8615 System_Tasking_Protected_Objects_Entries
8617 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8618 Insert_After
(Current_Node
, New_Op_Body
);
8619 Current_Node
:= New_Op_Body
;
8620 Analyze
(New_Op_Body
);
8623 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8624 -- protected body. At this point all wrapper specs have been created,
8625 -- frozen and included in the dispatch table for the protected type.
8627 if Ada_Version
>= Ada_2005
then
8628 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8630 end Expand_N_Protected_Body
;
8632 -----------------------------------------
8633 -- Expand_N_Protected_Type_Declaration --
8634 -----------------------------------------
8636 -- First we create a corresponding record type declaration used to
8637 -- represent values of this protected type.
8638 -- The general form of this type declaration is
8640 -- type poV (discriminants) is record
8641 -- _Object : aliased <kind>Protection
8642 -- [(<entry count> [, <handler count>])];
8643 -- [entry_family : array (bounds) of Void;]
8644 -- <private data fields>
8647 -- The discriminants are present only if the corresponding protected type
8648 -- has discriminants, and they exactly mirror the protected type
8649 -- discriminants. The private data fields similarly mirror the private
8650 -- declarations of the protected type.
8652 -- The Object field is always present. It contains RTS specific data used
8653 -- to control the protected object. It is declared as Aliased so that it
8654 -- can be passed as a pointer to the RTS. This allows the protected record
8655 -- to be referenced within RTS data structures. An appropriate Protection
8656 -- type and discriminant are generated.
8658 -- The Service field is present for protected objects with entries. It
8659 -- contains sufficient information to allow the entry service procedure for
8660 -- this object to be called when the object is not known till runtime.
8662 -- One entry_family component is present for each entry family in the
8663 -- task definition (see Expand_N_Task_Type_Declaration).
8665 -- When a protected object is declared, an instance of the protected type
8666 -- value record is created. The elaboration of this declaration creates the
8667 -- correct bounds for the entry families, and also evaluates the priority
8668 -- expression if needed. The initialization routine for the protected type
8669 -- itself then calls Initialize_Protection with appropriate parameters to
8670 -- initialize the value of the Task_Id field. Install_Handlers may be also
8671 -- called if a pragma Attach_Handler applies.
8673 -- Note: this record is passed to the subprograms created by the expansion
8674 -- of protected subprograms and entries. It is an in parameter to protected
8675 -- functions and an in out parameter to procedures and entry bodies. The
8676 -- Entity_Id for this created record type is placed in the
8677 -- Corresponding_Record_Type field of the associated protected type entity.
8679 -- Next we create a procedure specifications for protected subprograms and
8680 -- entry bodies. For each protected subprograms two subprograms are
8681 -- created, an unprotected and a protected version. The unprotected version
8682 -- is called from within other operations of the same protected object.
8684 -- We also build the call to register the procedure if a pragma
8685 -- Interrupt_Handler applies.
8687 -- A single subprogram is created to service all entry bodies; it has an
8688 -- additional boolean out parameter indicating that the previous entry call
8689 -- made by the current task was serviced immediately, i.e. not by proxy.
8690 -- The O parameter contains a pointer to a record object of the type
8691 -- described above. An untyped interface is used here to allow this
8692 -- procedure to be called in places where the type of the object to be
8693 -- serviced is not known. This must be done, for example, when a call that
8694 -- may have been requeued is cancelled; the corresponding object must be
8695 -- serviced, but which object that is not known till runtime.
8698 -- (O : System.Address; P : out Boolean);
8699 -- procedure pprocN (_object : in out poV);
8700 -- procedure pproc (_object : in out poV);
8701 -- function pfuncN (_object : poV);
8702 -- function pfunc (_object : poV);
8705 -- Note that this must come after the record type declaration, since
8706 -- the specs refer to this type.
8708 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8709 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8710 Loc
: constant Source_Ptr
:= Sloc
(N
);
8711 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8713 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8714 -- This flag indicates whether the lock free implementation is active
8716 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8717 -- This contains two lists; one for visible and one for private decls
8719 Current_Node
: Node_Id
:= N
;
8721 Entries_Aggr
: Node_Id
;
8723 procedure Check_Inlining
(Subp
: Entity_Id
);
8724 -- If the original operation has a pragma Inline, propagate the flag
8725 -- to the internal body, for possible inlining later on. The source
8726 -- operation is invisible to the back-end and is never actually called.
8728 procedure Expand_Entry_Declaration
(Decl
: Node_Id
);
8729 -- Create the entry barrier and the procedure body for entry declaration
8730 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8732 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8733 -- When compiling under the Ravenscar profile, private components must
8734 -- have a static size, or else a protected object will require heap
8735 -- allocation, violating the corresponding restriction. It is preferable
8736 -- to make this check here, because it provides a better error message
8737 -- than the back-end, which refers to the object as a whole.
8739 procedure Register_Handler
;
8740 -- For a protected operation that is an interrupt handler, add the
8741 -- freeze action that will register it as such.
8743 --------------------
8744 -- Check_Inlining --
8745 --------------------
8747 procedure Check_Inlining
(Subp
: Entity_Id
) is
8749 if Is_Inlined
(Subp
) then
8750 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8751 Set_Is_Inlined
(Subp
, False);
8755 ---------------------------
8756 -- Static_Component_Size --
8757 ---------------------------
8759 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8760 Typ
: constant Entity_Id
:= Etype
(Comp
);
8764 if Is_Scalar_Type
(Typ
) then
8767 elsif Is_Array_Type
(Typ
) then
8768 return Compile_Time_Known_Bounds
(Typ
);
8770 elsif Is_Record_Type
(Typ
) then
8771 C
:= First_Component
(Typ
);
8772 while Present
(C
) loop
8773 if not Static_Component_Size
(C
) then
8782 -- Any other type will be checked by the back-end
8787 end Static_Component_Size
;
8789 ------------------------------
8790 -- Expand_Entry_Declaration --
8791 ------------------------------
8793 procedure Expand_Entry_Declaration
(Decl
: Node_Id
) is
8794 Ent_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
8800 E_Count
:= E_Count
+ 1;
8802 -- Create the protected body subprogram
8805 Make_Defining_Identifier
(Loc
,
8806 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'E'));
8807 Set_Protected_Body_Subprogram
(Ent_Id
, Bod_Id
);
8810 Make_Subprogram_Declaration
(Loc
,
8812 Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Ent_Id
));
8814 Insert_After
(Current_Node
, Subp
);
8815 Current_Node
:= Subp
;
8819 -- Build a wrapper procedure to handle contract cases, preconditions,
8820 -- and postconditions.
8822 Build_Contract_Wrapper
(Ent_Id
, N
);
8824 -- Create the barrier function
8827 Make_Defining_Identifier
(Loc
,
8828 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'B'));
8829 Set_Barrier_Function
(Ent_Id
, Bar_Id
);
8832 Make_Subprogram_Declaration
(Loc
,
8834 Build_Barrier_Function_Specification
(Loc
, Bar_Id
));
8835 Set_Is_Entry_Barrier_Function
(Subp
);
8837 Insert_After
(Current_Node
, Subp
);
8838 Current_Node
:= Subp
;
8842 Set_Protected_Body_Subprogram
(Bar_Id
, Bar_Id
);
8843 Set_Scope
(Bar_Id
, Scope
(Ent_Id
));
8845 -- Collect pointers to the protected subprogram and the barrier
8846 -- of the current entry, for insertion into Entry_Bodies_Array.
8848 Append_To
(Expressions
(Entries_Aggr
),
8849 Make_Aggregate
(Loc
,
8850 Expressions
=> New_List
(
8851 Make_Attribute_Reference
(Loc
,
8852 Prefix
=> New_Occurrence_Of
(Bar_Id
, Loc
),
8853 Attribute_Name
=> Name_Unrestricted_Access
),
8854 Make_Attribute_Reference
(Loc
,
8855 Prefix
=> New_Occurrence_Of
(Bod_Id
, Loc
),
8856 Attribute_Name
=> Name_Unrestricted_Access
))));
8857 end Expand_Entry_Declaration
;
8859 ----------------------
8860 -- Register_Handler --
8861 ----------------------
8863 procedure Register_Handler
is
8865 -- All semantic checks already done in Sem_Prag
8867 Prot_Proc
: constant Entity_Id
:=
8868 Defining_Unit_Name
(Specification
(Current_Node
));
8870 Proc_Address
: constant Node_Id
:=
8871 Make_Attribute_Reference
(Loc
,
8873 New_Occurrence_Of
(Prot_Proc
, Loc
),
8874 Attribute_Name
=> Name_Address
);
8876 RTS_Call
: constant Entity_Id
:=
8877 Make_Procedure_Call_Statement
(Loc
,
8880 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8881 Parameter_Associations
=> New_List
(Proc_Address
));
8883 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8884 end Register_Handler
;
8889 Body_Id
: Entity_Id
;
8895 Object_Comp
: Node_Id
;
8900 -- Start of processing for Expand_N_Protected_Type_Declaration
8903 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8906 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8909 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8911 Qualify_Entity_Names
(N
);
8913 -- If the type has discriminants, their occurrences in the declaration
8914 -- have been replaced by the corresponding discriminals. For components
8915 -- that are constrained by discriminants, their homologues in the
8916 -- corresponding record type must refer to the discriminants of that
8917 -- record, so we must apply a new renaming to subtypes_indications:
8919 -- protected discriminant => discriminal => record discriminant
8921 -- This replacement is not applied to default expressions, for which
8922 -- the discriminal is correct.
8924 if Has_Discriminants
(Prot_Typ
) then
8930 Disc
:= First_Discriminant
(Prot_Typ
);
8931 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
8932 while Present
(Disc
) loop
8933 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
8934 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
8935 Next_Discriminant
(Disc
);
8941 -- Fill in the component declarations
8943 -- Add components for entry families. For each entry family, create an
8944 -- anonymous type declaration with the same size, and analyze the type.
8946 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
8948 pragma Assert
(Present
(Pdef
));
8950 Insert_After
(Current_Node
, Rec_Decl
);
8951 Current_Node
:= Rec_Decl
;
8953 -- Add private field components
8955 if Present
(Private_Declarations
(Pdef
)) then
8956 Priv
:= First
(Private_Declarations
(Pdef
));
8957 while Present
(Priv
) loop
8958 if Nkind
(Priv
) = N_Component_Declaration
then
8959 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
8961 -- When compiling for a restricted profile, the private
8962 -- components must have a static size. If not, this is an
8963 -- error for a single protected declaration, and rates a
8964 -- warning on a protected type declaration.
8966 if not Comes_From_Source
(Prot_Typ
) then
8968 -- It's ok to be checking this restriction at expansion
8969 -- time, because this is only for the restricted profile,
8970 -- which is not subject to strict RM conformance, so it
8971 -- is OK to miss this check in -gnatc mode.
8973 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
8975 (No_Implicit_Protected_Object_Allocations
, Priv
);
8977 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
8978 if not Discriminated_Size
(Defining_Identifier
(Priv
))
8980 -- Any object of the type will be non-static
8982 Error_Msg_N
("component has non-static size??", Priv
);
8984 ("\creation of protected object of type& will "
8985 & "violate restriction "
8986 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
8988 -- Object will be non-static if discriminants are
8991 ("creation of protected object of type& with "
8992 & "non-static discriminants will violate "
8993 & "restriction No_Implicit_Heap_Allocations??",
8997 -- Likewise for No_Implicit_Protected_Object_Allocations
8999 elsif Restriction_Active
9000 (No_Implicit_Protected_Object_Allocations
)
9002 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9004 -- Any object of the type will be non-static
9006 Error_Msg_N
("component has non-static size??", Priv
);
9008 ("\creation of protected object of type& will "
9009 & "violate restriction "
9010 & "No_Implicit_Protected_Object_Allocations??",
9013 -- Object will be non-static if discriminants are
9016 ("creation of protected object of type& with "
9017 & "non-static discriminants will violate "
9019 & "No_Implicit_Protected_Object_Allocations??",
9025 -- The component definition consists of a subtype indication,
9026 -- or (in Ada 2005) an access definition. Make a copy of the
9027 -- proper definition.
9030 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9031 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9032 Nent
: constant Entity_Id
:=
9033 Make_Defining_Identifier
(Sloc
(Oent
),
9034 Chars
=> Chars
(Oent
));
9038 if Present
(Subtype_Indication
(Old_Comp
)) then
9040 Make_Component_Definition
(Sloc
(Oent
),
9041 Aliased_Present
=> False,
9042 Subtype_Indication
=>
9044 (Subtype_Indication
(Old_Comp
), Discr_Map
));
9047 Make_Component_Definition
(Sloc
(Oent
),
9048 Aliased_Present
=> False,
9049 Access_Definition
=>
9051 (Access_Definition
(Old_Comp
), Discr_Map
));
9055 Make_Component_Declaration
(Loc
,
9056 Defining_Identifier
=> Nent
,
9057 Component_Definition
=> New_Comp
,
9058 Expression
=> Expression
(Priv
));
9060 Set_Has_Per_Object_Constraint
(Nent
,
9061 Has_Per_Object_Constraint
(Oent
));
9063 Append_To
(Cdecls
, New_Priv
);
9066 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9068 -- Make the unprotected version of the subprogram available
9069 -- for expansion of intra object calls. There is need for
9070 -- a protected version only if the subprogram is an interrupt
9071 -- handler, otherwise this operation can only be called from
9075 Make_Subprogram_Declaration
(Loc
,
9077 Build_Protected_Sub_Specification
9078 (Priv
, Prot_Typ
, Unprotected_Mode
));
9080 Insert_After
(Current_Node
, Sub
);
9083 Set_Protected_Body_Subprogram
9084 (Defining_Unit_Name
(Specification
(Priv
)),
9085 Defining_Unit_Name
(Specification
(Sub
)));
9086 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9087 Current_Node
:= Sub
;
9090 Make_Subprogram_Declaration
(Loc
,
9092 Build_Protected_Sub_Specification
9093 (Priv
, Prot_Typ
, Protected_Mode
));
9095 Insert_After
(Current_Node
, Sub
);
9097 Current_Node
:= Sub
;
9099 if Is_Interrupt_Handler
9100 (Defining_Unit_Name
(Specification
(Priv
)))
9102 if not Restricted_Profile
then
9112 -- Except for the lock-free implementation, append the _Object field
9113 -- with the right type to the component list. We need to compute the
9114 -- number of entries, and in some cases the number of Attach_Handler
9117 if not Lock_Free_Active
then
9119 Entry_Count_Expr
: constant Node_Id
:=
9120 Build_Entry_Count_Expression
9121 (Prot_Typ
, Cdecls
, Loc
);
9122 Num_Attach_Handler
: Nat
:= 0;
9123 Protection_Subtype
: Node_Id
;
9127 if Has_Attach_Handler
(Prot_Typ
) then
9128 Ritem
:= First_Rep_Item
(Prot_Typ
);
9129 while Present
(Ritem
) loop
9130 if Nkind
(Ritem
) = N_Pragma
9131 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9133 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9136 Next_Rep_Item
(Ritem
);
9140 -- Determine the proper protection type. There are two special
9141 -- cases: 1) when the protected type has dynamic interrupt
9142 -- handlers, and 2) when it has static handlers and we use a
9143 -- restricted profile.
9145 if Has_Attach_Handler
(Prot_Typ
)
9146 and then not Restricted_Profile
9148 Protection_Subtype
:=
9149 Make_Subtype_Indication
(Loc
,
9152 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9154 Make_Index_Or_Discriminant_Constraint
(Loc
,
9155 Constraints
=> New_List
(
9157 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9159 elsif Has_Interrupt_Handler
(Prot_Typ
)
9160 and then not Restriction_Active
(No_Dynamic_Attachment
)
9162 Protection_Subtype
:=
9163 Make_Subtype_Indication
(Loc
,
9166 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9168 Make_Index_Or_Discriminant_Constraint
(Loc
,
9169 Constraints
=> New_List
(Entry_Count_Expr
)));
9172 case Corresponding_Runtime_Package
(Prot_Typ
) is
9173 when System_Tasking_Protected_Objects_Entries
=>
9174 Protection_Subtype
:=
9175 Make_Subtype_Indication
(Loc
,
9178 (RTE
(RE_Protection_Entries
), Loc
),
9180 Make_Index_Or_Discriminant_Constraint
(Loc
,
9181 Constraints
=> New_List
(Entry_Count_Expr
)));
9183 when System_Tasking_Protected_Objects_Single_Entry
=>
9184 Protection_Subtype
:=
9185 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9187 when System_Tasking_Protected_Objects
=>
9188 Protection_Subtype
:=
9189 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9192 raise Program_Error
;
9197 Make_Component_Declaration
(Loc
,
9198 Defining_Identifier
=>
9199 Make_Defining_Identifier
(Loc
, Name_uObject
),
9200 Component_Definition
=>
9201 Make_Component_Definition
(Loc
,
9202 Aliased_Present
=> True,
9203 Subtype_Indication
=> Protection_Subtype
));
9206 -- Put the _Object component after the private component so that it
9207 -- be finalized early as required by 9.4 (20)
9209 Append_To
(Cdecls
, Object_Comp
);
9212 -- Analyze the record declaration immediately after construction,
9213 -- because the initialization procedure is needed for single object
9214 -- declarations before the next entity is analyzed (the freeze call
9215 -- that generates this initialization procedure is found below).
9217 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9219 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9220 -- the corresponding record is frozen. If any wrappers are generated,
9221 -- Current_Node is updated accordingly.
9223 if Ada_Version
>= Ada_2005
then
9224 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9227 -- Collect pointers to entry bodies and their barriers, to be placed
9228 -- in the Entry_Bodies_Array for the type. For each entry/family we
9229 -- add an expression to the aggregate which is the initial value of
9230 -- this array. The array is declared after all protected subprograms.
9232 if Has_Entries
(Prot_Typ
) then
9233 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9235 Entries_Aggr
:= Empty
;
9238 -- Build two new procedure specifications for each protected subprogram;
9239 -- one to call from outside the object and one to call from inside.
9240 -- Build a barrier function and an entry body action procedure
9241 -- specification for each protected entry. Initialize the entry body
9242 -- array. If subprogram is flagged as eliminated, do not generate any
9243 -- internal operations.
9246 Comp
:= First
(Visible_Declarations
(Pdef
));
9247 while Present
(Comp
) loop
9248 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9250 Make_Subprogram_Declaration
(Loc
,
9252 Build_Protected_Sub_Specification
9253 (Comp
, Prot_Typ
, Unprotected_Mode
));
9255 Insert_After
(Current_Node
, Sub
);
9258 Set_Protected_Body_Subprogram
9259 (Defining_Unit_Name
(Specification
(Comp
)),
9260 Defining_Unit_Name
(Specification
(Sub
)));
9261 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9263 -- Make the protected version of the subprogram available for
9264 -- expansion of external calls.
9266 Current_Node
:= Sub
;
9269 Make_Subprogram_Declaration
(Loc
,
9271 Build_Protected_Sub_Specification
9272 (Comp
, Prot_Typ
, Protected_Mode
));
9274 Insert_After
(Current_Node
, Sub
);
9277 Current_Node
:= Sub
;
9279 -- Generate an overriding primitive operation specification for
9280 -- this subprogram if the protected type implements an interface
9281 -- and Build_Wrapper_Spec did not generate its wrapper.
9283 if Ada_Version
>= Ada_2005
9285 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9288 Found
: Boolean := False;
9289 Prim_Elmt
: Elmt_Id
;
9295 (Primitive_Operations
9296 (Corresponding_Record_Type
(Prot_Typ
)));
9298 while Present
(Prim_Elmt
) loop
9299 Prim_Op
:= Node
(Prim_Elmt
);
9301 if Is_Primitive_Wrapper
(Prim_Op
)
9302 and then Wrapped_Entity
(Prim_Op
) =
9303 Defining_Entity
(Specification
(Comp
))
9309 Next_Elmt
(Prim_Elmt
);
9314 Make_Subprogram_Declaration
(Loc
,
9316 Build_Protected_Sub_Specification
9317 (Comp
, Prot_Typ
, Dispatching_Mode
));
9319 Insert_After
(Current_Node
, Sub
);
9322 Current_Node
:= Sub
;
9327 -- If a pragma Interrupt_Handler applies, build and add a call to
9328 -- Register_Interrupt_Handler to the freezing actions of the
9329 -- protected version (Current_Node) of the subprogram:
9331 -- system.interrupts.register_interrupt_handler
9332 -- (prot_procP'address);
9334 if not Restricted_Profile
9335 and then Is_Interrupt_Handler
9336 (Defining_Unit_Name
(Specification
(Comp
)))
9341 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9342 Expand_Entry_Declaration
(Comp
);
9348 -- If there are some private entry declarations, expand it as if they
9349 -- were visible entries.
9351 if Present
(Private_Declarations
(Pdef
)) then
9352 Comp
:= First
(Private_Declarations
(Pdef
));
9353 while Present
(Comp
) loop
9354 if Nkind
(Comp
) = N_Entry_Declaration
then
9355 Expand_Entry_Declaration
(Comp
);
9362 -- Create the declaration of an array object which contains the values
9363 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9364 -- type. This object is later passed to the appropriate protected object
9365 -- initialization routine.
9367 if Has_Entries
(Prot_Typ
)
9368 and then Corresponding_Runtime_Package
(Prot_Typ
) =
9369 System_Tasking_Protected_Objects_Entries
9376 Maxes_Id
: Entity_Id
;
9377 Need_Array
: Boolean := False;
9380 -- First check if there is any Max_Queue_Length pragma
9382 Item
:= First_Entity
(Prot_Typ
);
9383 while Present
(Item
) loop
9384 if Is_Entry
(Item
) and then Has_Max_Queue_Length
(Item
) then
9392 -- Gather the Max_Queue_Length values of all entries in a list. A
9393 -- value of zero indicates that the entry has no limitation on its
9398 Item
:= First_Entity
(Prot_Typ
);
9400 while Present
(Item
) loop
9401 if Is_Entry
(Item
) then
9404 Make_Integer_Literal
9405 (Loc
, Get_Max_Queue_Length
(Item
)));
9411 -- Create the declaration of the array object. Generate:
9413 -- Maxes_Id : aliased constant
9414 -- Protected_Entry_Queue_Max_Array
9415 -- (1 .. Count) := (..., ...);
9418 Make_Defining_Identifier
(Loc
,
9419 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'B'));
9422 Make_Object_Declaration
(Loc
,
9423 Defining_Identifier
=> Maxes_Id
,
9424 Aliased_Present
=> True,
9425 Constant_Present
=> True,
9426 Object_Definition
=>
9427 Make_Subtype_Indication
(Loc
,
9430 (RTE
(RE_Protected_Entry_Queue_Max_Array
), Loc
),
9432 Make_Index_Or_Discriminant_Constraint
(Loc
,
9433 Constraints
=> New_List
(
9435 Make_Integer_Literal
(Loc
, 1),
9436 Make_Integer_Literal
(Loc
, Count
))))),
9437 Expression
=> Make_Aggregate
(Loc
, Maxes
));
9439 -- A pointer to this array will be placed in the corresponding
9440 -- record by its initialization procedure so this needs to be
9443 Insert_After
(Current_Node
, Max_Vals
);
9444 Current_Node
:= Max_Vals
;
9447 Set_Entry_Max_Queue_Lengths_Array
(Prot_Typ
, Maxes_Id
);
9452 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9453 -- all protected subprograms have been collected.
9455 if Has_Entries
(Prot_Typ
) then
9457 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9458 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9460 case Corresponding_Runtime_Package
(Prot_Typ
) is
9461 when System_Tasking_Protected_Objects_Entries
=>
9462 Expr
:= Entries_Aggr
;
9464 Make_Subtype_Indication
(Loc
,
9467 (RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9469 Make_Index_Or_Discriminant_Constraint
(Loc
,
9470 Constraints
=> New_List
(
9472 Make_Integer_Literal
(Loc
, 1),
9473 Make_Integer_Literal
(Loc
, E_Count
)))));
9475 when System_Tasking_Protected_Objects_Single_Entry
=>
9476 Expr
:= Remove_Head
(Expressions
(Entries_Aggr
));
9477 Obj_Def
:= New_Occurrence_Of
(RTE
(RE_Entry_Body
), Loc
);
9480 raise Program_Error
;
9484 Make_Object_Declaration
(Loc
,
9485 Defining_Identifier
=> Body_Id
,
9486 Aliased_Present
=> True,
9487 Constant_Present
=> True,
9488 Object_Definition
=> Obj_Def
,
9489 Expression
=> Expr
);
9491 -- A pointer to this array will be placed in the corresponding record
9492 -- by its initialization procedure so this needs to be analyzed here.
9494 Insert_After
(Current_Node
, Body_Arr
);
9495 Current_Node
:= Body_Arr
;
9498 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9500 -- Finally, build the function that maps an entry index into the
9501 -- corresponding body. A pointer to this function is placed in each
9502 -- object of the type. Except for a ravenscar-like profile (no abort,
9503 -- no entry queue, 1 entry)
9505 if Corresponding_Runtime_Package
(Prot_Typ
) =
9506 System_Tasking_Protected_Objects_Entries
9509 Make_Subprogram_Declaration
(Loc
,
9510 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9512 Insert_After
(Current_Node
, Sub
);
9516 end Expand_N_Protected_Type_Declaration
;
9518 --------------------------------
9519 -- Expand_N_Requeue_Statement --
9520 --------------------------------
9522 -- A nondispatching requeue statement is expanded into one of four GNARLI
9523 -- operations, depending on the source and destination (task or protected
9524 -- object). A dispatching requeue statement is expanded into a call to the
9525 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9526 -- jump around the remainder of processing for the original entry and, if
9527 -- the destination is (different) protected object, to attempt to service
9528 -- it. The following illustrates the various cases:
9531 -- (O : System.Address;
9532 -- P : System.Address;
9533 -- E : Protected_Entry_Index)
9535 -- <discriminant renamings>
9536 -- <private object renamings>
9537 -- type poVP is access poV;
9538 -- _object : ptVP := ptVP!(O);
9542 -- <start of statement sequence for entry>
9544 -- -- Requeue from one protected entry body to another protected
9547 -- Requeue_Protected_Entry (
9548 -- _object._object'Access,
9549 -- new._object'Access,
9554 -- <some more of the statement sequence for entry>
9556 -- -- Requeue from an entry body to a task entry
9558 -- Requeue_Protected_To_Task_Entry (
9564 -- <rest of statement sequence for entry>
9565 -- Complete_Entry_Body (_object._object);
9568 -- when all others =>
9569 -- Exceptional_Complete_Entry_Body (
9570 -- _object._object, Get_GNAT_Exception);
9574 -- Requeue of a task entry call to a task entry
9576 -- Accept_Call (E, Ann);
9577 -- <start of statement sequence for accept statement>
9578 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9580 -- <rest of statement sequence for accept statement>
9582 -- Complete_Rendezvous;
9585 -- when all others =>
9586 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9588 -- Requeue of a task entry call to a protected entry
9590 -- Accept_Call (E, Ann);
9591 -- <start of statement sequence for accept statement>
9592 -- Requeue_Task_To_Protected_Entry (
9593 -- new._object'Access,
9598 -- <rest of statement sequence for accept statement>
9600 -- Complete_Rendezvous;
9603 -- when all others =>
9604 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9606 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9607 -- marked by pragma Implemented (XXX, By_Entry).
9609 -- The requeue is inside a protected entry:
9612 -- (O : System.Address;
9613 -- P : System.Address;
9614 -- E : Protected_Entry_Index)
9616 -- <discriminant renamings>
9617 -- <private object renamings>
9618 -- type poVP is access poV;
9619 -- _object : ptVP := ptVP!(O);
9623 -- <start of statement sequence for entry>
9626 -- (<interface class-wide object>,
9629 -- Ada.Tags.Get_Offset_Index
9631 -- <interface dispatch table index of target entry>),
9635 -- <rest of statement sequence for entry>
9636 -- Complete_Entry_Body (_object._object);
9639 -- when all others =>
9640 -- Exceptional_Complete_Entry_Body (
9641 -- _object._object, Get_GNAT_Exception);
9645 -- The requeue is inside a task entry:
9647 -- Accept_Call (E, Ann);
9648 -- <start of statement sequence for accept statement>
9650 -- (<interface class-wide object>,
9653 -- Ada.Tags.Get_Offset_Index
9655 -- <interface dispatch table index of target entrt>),
9659 -- <rest of statement sequence for accept statement>
9661 -- Complete_Rendezvous;
9664 -- when all others =>
9665 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9667 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9668 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9669 -- statement is replaced by a dispatching call with actual parameters taken
9670 -- from the inner-most accept statement or entry body.
9672 -- Target.Primitive (Param1, ..., ParamN);
9674 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9675 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9679 -- S : constant Offset_Index :=
9680 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9681 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9684 -- if C = POK_Protected_Entry
9685 -- or else C = POK_Task_Entry
9687 -- <statements for dispatching requeue>
9689 -- elsif C = POK_Protected_Procedure then
9690 -- <dispatching call equivalent>
9693 -- raise Program_Error;
9697 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9698 Loc
: constant Source_Ptr
:= Sloc
(N
);
9699 Conc_Typ
: Entity_Id
;
9703 Old_Typ
: Entity_Id
;
9705 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9706 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9707 -- the form Concval.Ename. It is statically known that Ename is allowed
9708 -- to be implemented by a protected procedure. Create a dispatching call
9709 -- equivalent of Concval.Ename taking the actual parameters from the
9710 -- inner-most accept statement or entry body.
9712 function Build_Dispatching_Requeue
return Node_Id
;
9713 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9714 -- the form Concval.Ename. It is statically known that Ename is allowed
9715 -- to be implemented by a protected or a task entry. Create a call to
9716 -- primitive _Disp_Requeue which handles the low-level actions.
9718 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9719 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9720 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9721 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9722 -- determines at runtime whether Ename denotes an entry or a procedure
9723 -- and perform the appropriate kind of dispatching select.
9725 function Build_Normal_Requeue
return Node_Id
;
9726 -- N denotes a nondispatching requeue statement to either a task or a
9727 -- protected entry. Build the appropriate runtime call to perform the
9730 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9731 -- For a protected entry, create a return statement to skip the rest of
9732 -- the entry body. Otherwise, create a goto statement to skip the rest
9733 -- of a task accept statement. The lookup for the enclosing entry body
9734 -- or accept statement starts from Search.
9736 ---------------------------------------
9737 -- Build_Dispatching_Call_Equivalent --
9738 ---------------------------------------
9740 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9741 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9742 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9749 -- Climb the parent chain looking for the inner-most entry body or
9750 -- accept statement.
9753 while Present
(Acc_Ent
)
9754 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9757 Acc_Ent
:= Parent
(Acc_Ent
);
9760 -- A requeue statement should be housed inside an entry body or an
9761 -- accept statement at some level. If this is not the case, then the
9762 -- tree is malformed.
9764 pragma Assert
(Present
(Acc_Ent
));
9766 -- Recover the list of formal parameters
9768 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9769 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9772 Formals
:= Parameter_Specifications
(Acc_Ent
);
9774 -- Create the actual parameters for the dispatching call. These are
9775 -- simply copies of the entry body or accept statement formals in the
9776 -- same order as they appear.
9780 if Present
(Formals
) then
9781 Actuals
:= New_List
;
9782 Formal
:= First
(Formals
);
9783 while Present
(Formal
) loop
9785 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9791 -- Obj.Call_Ent (Actuals);
9794 Make_Procedure_Call_Statement
(Loc
,
9796 Make_Selected_Component
(Loc
,
9797 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9798 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9800 Parameter_Associations
=> Actuals
);
9801 end Build_Dispatching_Call_Equivalent
;
9803 -------------------------------
9804 -- Build_Dispatching_Requeue --
9805 -------------------------------
9807 function Build_Dispatching_Requeue
return Node_Id
is
9808 Params
: constant List_Id
:= New_List
;
9811 -- Process the "with abort" parameter
9814 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9816 -- Process the entry wrapper's position in the primary dispatch
9817 -- table parameter. Generate:
9819 -- Ada.Tags.Get_Entry_Index
9820 -- (T => To_Tag_Ptr (Obj'Address).all,
9822 -- Ada.Tags.Get_Offset_Index
9823 -- (Ada.Tags.Tag (Concval),
9824 -- <interface dispatch table position of Ename>));
9826 -- Note that Obj'Address is recursively expanded into a call to
9827 -- Base_Address (Obj).
9829 if Tagged_Type_Expansion
then
9831 Make_Function_Call
(Loc
,
9832 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9833 Parameter_Associations
=> New_List
(
9835 Make_Explicit_Dereference
(Loc
,
9836 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9837 Make_Attribute_Reference
(Loc
,
9838 Prefix
=> New_Copy_Tree
(Concval
),
9839 Attribute_Name
=> Name_Address
))),
9841 Make_Function_Call
(Loc
,
9842 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9843 Parameter_Associations
=> New_List
(
9844 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9845 Make_Integer_Literal
(Loc
,
9846 DT_Position
(Entity
(Ename
))))))));
9852 Make_Function_Call
(Loc
,
9853 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9854 Parameter_Associations
=> New_List
(
9856 Make_Attribute_Reference
(Loc
,
9858 Attribute_Name
=> Name_Tag
),
9860 Make_Function_Call
(Loc
,
9861 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9863 Parameter_Associations
=> New_List
(
9867 Make_Attribute_Reference
(Loc
,
9869 Attribute_Name
=> Name_Tag
),
9873 Make_Attribute_Reference
(Loc
,
9874 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9875 Attribute_Name
=> Name_Tag
),
9879 Make_Integer_Literal
(Loc
,
9880 DT_Position
(Entity
(Ename
))))))));
9883 -- Specific actuals for protected to XXX requeue
9885 if Is_Protected_Type
(Old_Typ
) then
9887 Make_Attribute_Reference
(Loc
, -- _object'Address
9889 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9890 Attribute_Name
=> Name_Address
));
9892 Prepend_To
(Params
, -- True
9893 New_Occurrence_Of
(Standard_True
, Loc
));
9895 -- Specific actuals for task to XXX requeue
9898 pragma Assert
(Is_Task_Type
(Old_Typ
));
9900 Prepend_To
(Params
, -- null
9901 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9903 Prepend_To
(Params
, -- False
9904 New_Occurrence_Of
(Standard_False
, Loc
));
9907 -- Add the object parameter
9909 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9912 -- _Disp_Requeue (<Params>);
9914 -- Find entity for Disp_Requeue operation, which belongs to
9915 -- the type and may not be directly visible.
9920 pragma Warnings
(Off
, Op
);
9923 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9924 while Present
(Elmt
) loop
9926 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9931 Make_Procedure_Call_Statement
(Loc
,
9932 Name
=> New_Occurrence_Of
(Op
, Loc
),
9933 Parameter_Associations
=> Params
);
9935 end Build_Dispatching_Requeue
;
9937 --------------------------------------
9938 -- Build_Dispatching_Requeue_To_Any --
9939 --------------------------------------
9941 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9942 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9943 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9944 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
9954 -- Dispatch table slot processing, generate:
9957 S
:= Build_S
(Loc
, Decls
);
9959 -- Call kind processing, generate:
9960 -- C : Ada.Tags.Prim_Op_Kind;
9962 C
:= Build_C
(Loc
, Decls
);
9965 -- S := Ada.Tags.Get_Offset_Index
9966 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9968 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
9971 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9974 Make_Procedure_Call_Statement
(Loc
,
9977 Find_Prim_Op
(Etype
(Etype
(Obj
)),
9978 Name_uDisp_Get_Prim_Op_Kind
),
9980 Parameter_Associations
=> New_List
(
9981 New_Copy_Tree
(Obj
),
9982 New_Occurrence_Of
(S
, Loc
),
9983 New_Occurrence_Of
(C
, Loc
))));
9987 -- if C = POK_Protected_Entry
9988 -- or else C = POK_Task_Entry
9991 Make_Implicit_If_Statement
(N
,
9997 New_Occurrence_Of
(C
, Loc
),
9999 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10004 New_Occurrence_Of
(C
, Loc
),
10006 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10008 -- Dispatching requeue equivalent
10010 Then_Statements
=> New_List
(
10011 Build_Dispatching_Requeue
,
10014 -- elsif C = POK_Protected_Procedure then
10016 Elsif_Parts
=> New_List
(
10017 Make_Elsif_Part
(Loc
,
10021 New_Occurrence_Of
(C
, Loc
),
10023 New_Occurrence_Of
(
10024 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10026 -- Dispatching call equivalent
10028 Then_Statements
=> New_List
(
10029 Build_Dispatching_Call_Equivalent
))),
10032 -- raise Program_Error;
10035 Else_Statements
=> New_List
(
10036 Make_Raise_Program_Error
(Loc
,
10037 Reason
=> PE_Explicit_Raise
))));
10039 -- Wrap everything into a block
10042 Make_Block_Statement
(Loc
,
10043 Declarations
=> Decls
,
10044 Handled_Statement_Sequence
=>
10045 Make_Handled_Sequence_Of_Statements
(Loc
,
10046 Statements
=> Stmts
));
10047 end Build_Dispatching_Requeue_To_Any
;
10049 --------------------------
10050 -- Build_Normal_Requeue --
10051 --------------------------
10053 function Build_Normal_Requeue
return Node_Id
is
10054 Params
: constant List_Id
:= New_List
;
10059 -- Process the "with abort" parameter
10061 Prepend_To
(Params
,
10062 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10064 -- Add the index expression to the parameters. It is common among all
10067 Prepend_To
(Params
,
10068 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10070 if Is_Protected_Type
(Old_Typ
) then
10072 Self_Param
: Node_Id
;
10076 Make_Attribute_Reference
(Loc
,
10078 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10080 Name_Unchecked_Access
);
10082 -- Protected to protected requeue
10084 if Is_Protected_Type
(Conc_Typ
) then
10086 New_Occurrence_Of
(
10087 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10090 Make_Attribute_Reference
(Loc
,
10092 Concurrent_Ref
(Concval
),
10094 Name_Unchecked_Access
);
10096 -- Protected to task requeue
10098 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10100 New_Occurrence_Of
(
10101 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10103 Param
:= Concurrent_Ref
(Concval
);
10106 Prepend_To
(Params
, Param
);
10107 Prepend_To
(Params
, Self_Param
);
10110 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10112 -- Task to protected requeue
10114 if Is_Protected_Type
(Conc_Typ
) then
10116 New_Occurrence_Of
(
10117 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10120 Make_Attribute_Reference
(Loc
,
10122 Concurrent_Ref
(Concval
),
10124 Name_Unchecked_Access
);
10126 -- Task to task requeue
10128 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10130 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10132 Param
:= Concurrent_Ref
(Concval
);
10135 Prepend_To
(Params
, Param
);
10139 Make_Procedure_Call_Statement
(Loc
,
10141 Parameter_Associations
=> Params
);
10142 end Build_Normal_Requeue
;
10144 --------------------------
10145 -- Build_Skip_Statement --
10146 --------------------------
10148 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10149 Skip_Stmt
: Node_Id
;
10152 -- Build a return statement to skip the rest of the entire body
10154 if Is_Protected_Type
(Old_Typ
) then
10155 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10157 -- If the requeue is within a task, find the end label of the
10158 -- enclosing accept statement and create a goto statement to it.
10166 -- Climb the parent chain looking for the enclosing accept
10169 Acc
:= Parent
(Search
);
10170 while Present
(Acc
)
10171 and then Nkind
(Acc
) /= N_Accept_Statement
10173 Acc
:= Parent
(Acc
);
10176 -- The last statement is the second label used for completing
10177 -- the rendezvous the usual way. The label we are looking for
10178 -- is right before it.
10181 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10183 pragma Assert
(Nkind
(Label
) = N_Label
);
10185 -- Generate a goto statement to skip the rest of the accept
10188 Make_Goto_Statement
(Loc
,
10190 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10194 Set_Analyzed
(Skip_Stmt
);
10197 end Build_Skip_Statement
;
10199 -- Start of processing for Expand_N_Requeue_Statement
10202 -- Extract the components of the entry call
10204 Extract_Entry
(N
, Concval
, Ename
, Index
);
10205 Conc_Typ
:= Etype
(Concval
);
10207 -- If the prefix is an access to class-wide type, dereference to get
10208 -- object and entry type.
10210 if Is_Access_Type
(Conc_Typ
) then
10211 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10213 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10214 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10217 -- Examine the scope stack in order to find nearest enclosing protected
10218 -- or task type. This will constitute our invocation source.
10220 Old_Typ
:= Current_Scope
;
10221 while Present
(Old_Typ
)
10222 and then not Is_Protected_Type
(Old_Typ
)
10223 and then not Is_Task_Type
(Old_Typ
)
10225 Old_Typ
:= Scope
(Old_Typ
);
10228 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10229 -- Concval.Ename where the type of Concval is class-wide concurrent
10232 if Ada_Version
>= Ada_2012
10233 and then Present
(Concval
)
10234 and then Is_Class_Wide_Type
(Conc_Typ
)
10235 and then Is_Concurrent_Interface
(Conc_Typ
)
10238 Has_Impl
: Boolean := False;
10239 Impl_Kind
: Name_Id
:= No_Name
;
10242 -- Check whether the Ename is flagged by pragma Implemented
10244 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10246 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10249 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10250 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10252 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10253 Rewrite
(N
, Build_Dispatching_Requeue
);
10255 Insert_After
(N
, Build_Skip_Statement
(N
));
10257 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10258 -- a protected procedure. In this case the requeue is transformed
10259 -- into a dispatching call.
10262 and then Impl_Kind
= Name_By_Protected_Procedure
10264 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10267 -- The procedure_or_entry_NAME's implementation kind is either
10268 -- By_Any, Optional, or pragma Implemented was not applied at all.
10269 -- In this case a runtime test determines whether Ename denotes an
10270 -- entry or a protected procedure and performs the appropriate
10274 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10279 -- Processing for regular (nondispatching) requeues
10282 Rewrite
(N
, Build_Normal_Requeue
);
10284 Insert_After
(N
, Build_Skip_Statement
(N
));
10286 end Expand_N_Requeue_Statement
;
10288 -------------------------------
10289 -- Expand_N_Selective_Accept --
10290 -------------------------------
10292 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10293 Loc
: constant Source_Ptr
:= Sloc
(N
);
10294 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10296 -- Note: in the below declarations a lot of new lists are allocated
10297 -- unconditionally which may well not end up being used. That's not
10298 -- a good idea since it wastes space gratuitously ???
10300 Accept_Case
: List_Id
;
10301 Accept_List
: constant List_Id
:= New_List
;
10304 Alt_List
: constant List_Id
:= New_List
;
10305 Alt_Stats
: List_Id
;
10306 Ann
: Entity_Id
:= Empty
;
10308 Check_Guard
: Boolean := True;
10310 Decls
: constant List_Id
:= New_List
;
10311 Stats
: constant List_Id
:= New_List
;
10312 Body_List
: constant List_Id
:= New_List
;
10313 Trailing_List
: constant List_Id
:= New_List
;
10316 Else_Present
: Boolean := False;
10317 Terminate_Alt
: Node_Id
:= Empty
;
10318 Select_Mode
: Node_Id
;
10320 Delay_Case
: List_Id
;
10321 Delay_Count
: Integer := 0;
10322 Delay_Val
: Entity_Id
;
10323 Delay_Index
: Entity_Id
;
10324 Delay_Min
: Entity_Id
;
10325 Delay_Num
: Pos
:= 1;
10326 Delay_Alt_List
: List_Id
:= New_List
;
10327 Delay_List
: constant List_Id
:= New_List
;
10331 First_Delay
: Boolean := True;
10332 Guard_Open
: Entity_Id
;
10338 Num_Accept
: Nat
:= 0;
10340 Time_Type
: Entity_Id
;
10341 Select_Call
: Node_Id
;
10343 Qnam
: constant Entity_Id
:=
10344 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10346 Xnam
: constant Entity_Id
:=
10347 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10349 -----------------------
10350 -- Local subprograms --
10351 -----------------------
10353 function Accept_Or_Raise
return List_Id
;
10354 -- For the rare case where delay alternatives all have guards, and
10355 -- all of them are closed, it is still possible that there were open
10356 -- accept alternatives with no callers. We must reexamine the
10357 -- Accept_List, and execute a selective wait with no else if some
10358 -- accept is open. If none, we raise program_error.
10360 procedure Add_Accept
(Alt
: Node_Id
);
10361 -- Process a single accept statement in a select alternative. Build
10362 -- procedure for body of accept, and add entry to dispatch table with
10363 -- expression for guard, in preparation for call to run time select.
10365 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10366 -- Manufacture a label using Num as a serial number and declare it.
10367 -- The declaration is appended to Decls. The label marks the trailing
10368 -- statements of an accept or delay alternative.
10370 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10371 -- Build call to Selective_Wait runtime routine
10373 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10374 -- Add code to compare value of delay with previous values, and
10375 -- generate case entry for trailing statements.
10377 procedure Process_Accept_Alternative
10381 -- Add code to call corresponding procedure, and branch to
10382 -- trailing statements, if any.
10384 ---------------------
10385 -- Accept_Or_Raise --
10386 ---------------------
10388 function Accept_Or_Raise
return List_Id
is
10391 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10394 -- We generate the following:
10396 -- for J in q'range loop
10397 -- if q(J).S /=null_task_entry then
10398 -- selective_wait (simple_mode,...);
10404 -- if no rendez_vous then
10405 -- raise program_error;
10408 -- Note that the code needs to know that the selector name
10409 -- in an Accept_Alternative is named S.
10411 Cond
:= Make_Op_Ne
(Loc
,
10413 Make_Selected_Component
(Loc
,
10415 Make_Indexed_Component
(Loc
,
10416 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10417 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10418 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10420 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10422 Stats
:= New_List
(
10423 Make_Implicit_Loop_Statement
(N
,
10424 Iteration_Scheme
=>
10425 Make_Iteration_Scheme
(Loc
,
10426 Loop_Parameter_Specification
=>
10427 Make_Loop_Parameter_Specification
(Loc
,
10428 Defining_Identifier
=> J
,
10429 Discrete_Subtype_Definition
=>
10430 Make_Attribute_Reference
(Loc
,
10431 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10432 Attribute_Name
=> Name_Range
,
10433 Expressions
=> New_List
(
10434 Make_Integer_Literal
(Loc
, 1))))),
10436 Statements
=> New_List
(
10437 Make_Implicit_If_Statement
(N
,
10439 Then_Statements
=> New_List
(
10441 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10442 Make_Exit_Statement
(Loc
))))));
10445 Make_Raise_Program_Error
(Loc
,
10446 Condition
=> Make_Op_Eq
(Loc
,
10447 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10449 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10450 Reason
=> PE_All_Guards_Closed
));
10453 end Accept_Or_Raise
;
10459 procedure Add_Accept
(Alt
: Node_Id
) is
10460 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10461 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10462 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10463 Eent
: constant Entity_Id
:= Entity
(Ename
);
10464 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10465 Null_Body
: Node_Id
;
10466 Proc_Body
: Node_Id
;
10467 PB_Ent
: Entity_Id
;
10473 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10476 if Present
(Condition
(Alt
)) then
10478 Make_If_Expression
(Eloc
, New_List
(
10480 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10481 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10484 Entry_Index_Expression
10485 (Eloc
, Eent
, Index
, Scope
(Eent
));
10488 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10489 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10491 -- Always add call to Abort_Undefer when generating code, since
10492 -- this is what the runtime expects (abort deferred in
10493 -- Selective_Wait). In CodePeer mode this only confuses the
10494 -- analysis with unknown calls, so don't do it.
10496 if not CodePeer_Mode
then
10497 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10499 (First
(Statements
(Handled_Statement_Sequence
10500 (Accept_Statement
(Alt
)))),
10506 Make_Defining_Identifier
(Eloc
,
10507 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10509 if Comes_From_Source
(Alt
) then
10510 Set_Debug_Info_Needed
(PB_Ent
);
10514 Make_Subprogram_Body
(Eloc
,
10516 Make_Procedure_Specification
(Eloc
,
10517 Defining_Unit_Name
=> PB_Ent
),
10518 Declarations
=> Declarations
(Acc_Stm
),
10519 Handled_Statement_Sequence
=>
10520 Build_Accept_Body
(Accept_Statement
(Alt
)));
10522 -- During the analysis of the body of the accept statement, any
10523 -- zero cost exception handler records were collected in the
10524 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10525 -- This is where we move them to where they belong, namely the
10526 -- newly created procedure.
10528 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10529 Append
(Proc_Body
, Body_List
);
10532 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10534 -- if accept statement has declarations, insert above, given that
10535 -- we are not creating a body for the accept.
10537 if Present
(Declarations
(Acc_Stm
)) then
10538 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10542 Append_To
(Accept_List
,
10543 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10545 Num_Accept
:= Num_Accept
+ 1;
10548 ----------------------------
10549 -- Make_And_Declare_Label --
10550 ----------------------------
10552 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10556 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10558 Make_Label
(Loc
, Lab_Id
);
10561 Make_Implicit_Label_Declaration
(Loc
,
10562 Defining_Identifier
=>
10563 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10564 Label_Construct
=> Lab
));
10567 end Make_And_Declare_Label
;
10569 ----------------------
10570 -- Make_Select_Call --
10571 ----------------------
10573 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10574 Params
: constant List_Id
:= New_List
;
10578 Make_Attribute_Reference
(Loc
,
10579 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10580 Attribute_Name
=> Name_Unchecked_Access
));
10581 Append_To
(Params
, Select_Mode
);
10582 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10583 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10586 Make_Procedure_Call_Statement
(Loc
,
10587 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10588 Parameter_Associations
=> Params
);
10589 end Make_Select_Call
;
10591 --------------------------------
10592 -- Process_Accept_Alternative --
10593 --------------------------------
10595 procedure Process_Accept_Alternative
10600 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10601 Alt_Stats
: List_Id
;
10604 Adjust_Condition
(Condition
(Alt
));
10606 -- Accept with body
10608 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10611 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10614 (Defining_Unit_Name
(Specification
(Proc
)),
10617 -- Accept with no body (followed by trailing statements)
10620 Alt_Stats
:= Empty_List
;
10623 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10625 -- After the call, if any, branch to trailing statements, if any.
10626 -- We create a label for each, as well as the corresponding label
10629 if not Is_Empty_List
(Statements
(Alt
)) then
10630 Lab
:= Make_And_Declare_Label
(Index
);
10631 Append
(Lab
, Trailing_List
);
10632 Append_List
(Statements
(Alt
), Trailing_List
);
10633 Append_To
(Trailing_List
,
10634 Make_Goto_Statement
(Loc
,
10635 Name
=> New_Copy
(Identifier
(End_Lab
))));
10641 Append_To
(Alt_Stats
,
10642 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10644 Append_To
(Alt_List
,
10645 Make_Case_Statement_Alternative
(Loc
,
10646 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10647 Statements
=> Alt_Stats
));
10648 end Process_Accept_Alternative
;
10650 -------------------------------
10651 -- Process_Delay_Alternative --
10652 -------------------------------
10654 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10655 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10657 Delay_Alt
: List_Id
;
10660 -- Deal with C/Fortran boolean as delay condition
10662 Adjust_Condition
(Condition
(Alt
));
10664 -- Determine the smallest specified delay
10666 -- for each delay alternative generate:
10668 -- if guard-expression then
10669 -- Delay_Val := delay-expression;
10670 -- Guard_Open := True;
10671 -- if Delay_Val < Delay_Min then
10672 -- Delay_Min := Delay_Val;
10673 -- Delay_Index := Index;
10677 -- The enclosing if-statement is omitted if there is no guard
10679 if Delay_Count
= 1 or else First_Delay
then
10680 First_Delay
:= False;
10682 Delay_Alt
:= New_List
(
10683 Make_Assignment_Statement
(Loc
,
10684 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10685 Expression
=> Expression
(Delay_Statement
(Alt
))));
10687 if Delay_Count
> 1 then
10688 Append_To
(Delay_Alt
,
10689 Make_Assignment_Statement
(Loc
,
10690 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10691 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10695 Delay_Alt
:= New_List
(
10696 Make_Assignment_Statement
(Loc
,
10697 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10698 Expression
=> Expression
(Delay_Statement
(Alt
))));
10700 if Time_Type
= Standard_Duration
then
10703 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10704 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10707 -- The scope of the time type must define a comparison
10708 -- operator. The scope itself may not be visible, so we
10709 -- construct a node with entity information to insure that
10710 -- semantic analysis can find the proper operator.
10713 Make_Function_Call
(Loc
,
10714 Name
=> Make_Selected_Component
(Loc
,
10716 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10718 Make_Operator_Symbol
(Loc
,
10719 Chars
=> Name_Op_Lt
,
10720 Strval
=> No_String
)),
10721 Parameter_Associations
=>
10723 New_Occurrence_Of
(Delay_Val
, Loc
),
10724 New_Occurrence_Of
(Delay_Min
, Loc
)));
10726 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10729 Append_To
(Delay_Alt
,
10730 Make_Implicit_If_Statement
(N
,
10732 Then_Statements
=> New_List
(
10733 Make_Assignment_Statement
(Loc
,
10734 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10735 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10737 Make_Assignment_Statement
(Loc
,
10738 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10739 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10742 if Check_Guard
then
10743 Append_To
(Delay_Alt
,
10744 Make_Assignment_Statement
(Loc
,
10745 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10746 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10749 if Present
(Condition
(Alt
)) then
10750 Delay_Alt
:= New_List
(
10751 Make_Implicit_If_Statement
(N
,
10752 Condition
=> Condition
(Alt
),
10753 Then_Statements
=> Delay_Alt
));
10756 Append_List
(Delay_Alt
, Delay_List
);
10758 Ensure_Statement_Present
(Dloc
, Alt
);
10760 -- If the delay alternative has a statement part, add choice to the
10761 -- case statements for delays.
10763 if not Is_Empty_List
(Statements
(Alt
)) then
10765 if Delay_Count
= 1 then
10766 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10769 Append_To
(Delay_Alt_List
,
10770 Make_Case_Statement_Alternative
(Loc
,
10771 Discrete_Choices
=> New_List
(
10772 Make_Integer_Literal
(Loc
, Index
)),
10773 Statements
=> Statements
(Alt
)));
10776 elsif Delay_Count
= 1 then
10778 -- If the single delay has no trailing statements, add a branch
10779 -- to the exit label to the selective wait.
10781 Delay_Alt_List
:= New_List
(
10782 Make_Goto_Statement
(Loc
,
10783 Name
=> New_Copy
(Identifier
(End_Lab
))));
10786 end Process_Delay_Alternative
;
10788 -- Start of processing for Expand_N_Selective_Accept
10791 Process_Statements_For_Controlled_Objects
(N
);
10793 -- First insert some declarations before the select. The first is:
10797 -- This variable holds the parameters passed to the accept body. This
10798 -- declaration has already been inserted by the time we get here by
10799 -- a call to Expand_Accept_Declarations made from the semantics when
10800 -- processing the first accept statement contained in the select. We
10801 -- can find this entity as Accept_Address (E), where E is any of the
10802 -- entries references by contained accept statements.
10804 -- The first step is to scan the list of Selective_Accept_Statements
10805 -- to find this entity, and also count the number of accepts, and
10806 -- determine if terminated, delay or else is present:
10810 Alt
:= First
(Alts
);
10811 while Present
(Alt
) loop
10812 Process_Statements_For_Controlled_Objects
(Alt
);
10814 if Nkind
(Alt
) = N_Accept_Alternative
then
10817 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10818 Delay_Count
:= Delay_Count
+ 1;
10820 -- If the delays are relative delays, the delay expressions have
10821 -- type Standard_Duration. Otherwise they must have some time type
10822 -- recognized by GNAT.
10824 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10825 Time_Type
:= Standard_Duration
;
10827 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10829 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10830 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10835 "& is not a time type (RM 9.6(6))",
10836 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10837 Time_Type
:= Standard_Duration
;
10838 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10842 if No
(Condition
(Alt
)) then
10844 -- This guard will always be open
10846 Check_Guard
:= False;
10849 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10850 Adjust_Condition
(Condition
(Alt
));
10851 Terminate_Alt
:= Alt
;
10854 Num_Alts
:= Num_Alts
+ 1;
10858 Else_Present
:= Present
(Else_Statements
(N
));
10860 -- At the same time (see procedure Add_Accept) we build the accept list:
10862 -- Qnn : Accept_List (1 .. num-select) := (
10863 -- (null-body, entry-index),
10864 -- (null-body, entry-index),
10866 -- (null_body, entry-index));
10868 -- In the above declaration, null-body is True if the corresponding
10869 -- accept has no body, and false otherwise. The entry is either the
10870 -- entry index expression if there is no guard, or if a guard is
10871 -- present, then an if expression of the form:
10873 -- (if guard then entry-index else Null_Task_Entry)
10875 -- If a guard is statically known to be false, the entry can simply
10876 -- be omitted from the accept list.
10879 Make_Object_Declaration
(Loc
,
10880 Defining_Identifier
=> Qnam
,
10881 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10882 Aliased_Present
=> True,
10884 Make_Qualified_Expression
(Loc
,
10886 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10888 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10890 -- Then we declare the variable that holds the index for the accept
10891 -- that will be selected for service:
10893 -- Xnn : Select_Index;
10896 Make_Object_Declaration
(Loc
,
10897 Defining_Identifier
=> Xnam
,
10898 Object_Definition
=>
10899 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10901 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10903 -- After this follow procedure declarations for each accept body
10905 -- procedure Pnn is
10910 -- where the ... are statements from the corresponding procedure body.
10911 -- No parameters are involved, since the parameters are passed via Ann
10912 -- and the parameter references have already been expanded to be direct
10913 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10914 -- any embedded tasking statements (which would normally be illegal in
10915 -- procedures), have been converted to calls to the tasking runtime so
10916 -- there is no problem in putting them into procedures.
10918 -- The original accept statement has been expanded into a block in
10919 -- the same fashion as for simple accepts (see Build_Accept_Body).
10921 -- Note: we don't really need to build these procedures for the case
10922 -- where no delay statement is present, but it is just as easy to
10923 -- build them unconditionally, and not significantly inefficient,
10924 -- since if they are short they will be inlined anyway.
10926 -- The procedure declarations have been assembled in Body_List
10928 -- If delays are present, we must compute the required delay.
10929 -- We first generate the declarations:
10931 -- Delay_Index : Boolean := 0;
10932 -- Delay_Min : Some_Time_Type.Time;
10933 -- Delay_Val : Some_Time_Type.Time;
10935 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10936 -- active delay that is actually chosen as the basis for the possible
10937 -- delay if an immediate rendez-vous is not possible.
10939 -- In the most common case there is a single delay statement, and this
10940 -- is handled specially.
10942 if Delay_Count
> 0 then
10944 -- Generate the required declarations
10947 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
10949 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
10951 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
10954 Make_Object_Declaration
(Loc
,
10955 Defining_Identifier
=> Delay_Val
,
10956 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
10959 Make_Object_Declaration
(Loc
,
10960 Defining_Identifier
=> Delay_Index
,
10961 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
10962 Expression
=> Make_Integer_Literal
(Loc
, 0)));
10965 Make_Object_Declaration
(Loc
,
10966 Defining_Identifier
=> Delay_Min
,
10967 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
10969 Unchecked_Convert_To
(Time_Type
,
10970 Make_Attribute_Reference
(Loc
,
10972 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
10973 Attribute_Name
=> Name_Last
))));
10975 -- Create Duration and Delay_Mode objects used for passing a delay
10978 D
:= Make_Temporary
(Loc
, 'D');
10979 M
:= Make_Temporary
(Loc
, 'M');
10985 -- Note that these values are defined in s-osprim.ads and must
10986 -- be kept in sync:
10988 -- Relative : constant := 0;
10989 -- Absolute_Calendar : constant := 1;
10990 -- Absolute_RT : constant := 2;
10992 if Time_Type
= Standard_Duration
then
10993 Discr
:= Make_Integer_Literal
(Loc
, 0);
10995 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10996 Discr
:= Make_Integer_Literal
(Loc
, 1);
11000 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11001 Discr
:= Make_Integer_Literal
(Loc
, 2);
11005 Make_Object_Declaration
(Loc
,
11006 Defining_Identifier
=> D
,
11007 Object_Definition
=>
11008 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11011 Make_Object_Declaration
(Loc
,
11012 Defining_Identifier
=> M
,
11013 Object_Definition
=>
11014 New_Occurrence_Of
(Standard_Integer
, Loc
),
11015 Expression
=> Discr
));
11018 if Check_Guard
then
11020 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11023 Make_Object_Declaration
(Loc
,
11024 Defining_Identifier
=> Guard_Open
,
11025 Object_Definition
=>
11026 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11028 New_Occurrence_Of
(Standard_False
, Loc
)));
11031 -- Delay_Count is zero, don't need M and D set (suppress warning)
11038 if Present
(Terminate_Alt
) then
11040 -- If the terminate alternative guard is False, use
11041 -- Simple_Mode; otherwise use Terminate_Mode.
11043 if Present
(Condition
(Terminate_Alt
)) then
11044 Select_Mode
:= Make_If_Expression
(Loc
,
11045 New_List
(Condition
(Terminate_Alt
),
11046 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11047 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11049 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11052 elsif Else_Present
or Delay_Count
> 0 then
11053 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11056 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11059 Select_Call
:= Make_Select_Call
(Select_Mode
);
11060 Append
(Select_Call
, Stats
);
11062 -- Now generate code to act on the result. There is an entry
11063 -- in this case for each accept statement with a non-null body,
11064 -- followed by a branch to the statements that follow the Accept.
11065 -- In the absence of delay alternatives, we generate:
11068 -- when No_Rendezvous => -- omitted if simple mode
11083 -- Lab0: Else_Statements;
11086 -- Lab1: Trailing_Statements1;
11089 -- Lab2: Trailing_Statements2;
11094 -- Generate label for common exit
11096 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11098 -- First entry is the default case, when no rendezvous is possible
11100 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11102 if Else_Present
then
11104 -- If no rendezvous is possible, the else part is executed
11106 Lab
:= Make_And_Declare_Label
(0);
11107 Alt_Stats
:= New_List
(
11108 Make_Goto_Statement
(Loc
,
11109 Name
=> New_Copy
(Identifier
(Lab
))));
11111 Append
(Lab
, Trailing_List
);
11112 Append_List
(Else_Statements
(N
), Trailing_List
);
11113 Append_To
(Trailing_List
,
11114 Make_Goto_Statement
(Loc
,
11115 Name
=> New_Copy
(Identifier
(End_Lab
))));
11117 Alt_Stats
:= New_List
(
11118 Make_Goto_Statement
(Loc
,
11119 Name
=> New_Copy
(Identifier
(End_Lab
))));
11122 Append_To
(Alt_List
,
11123 Make_Case_Statement_Alternative
(Loc
,
11124 Discrete_Choices
=> Choices
,
11125 Statements
=> Alt_Stats
));
11127 -- We make use of the fact that Accept_Index is an integer type, and
11128 -- generate successive literals for entries for each accept. Only those
11129 -- for which there is a body or trailing statements get a case entry.
11131 Alt
:= First
(Select_Alternatives
(N
));
11132 Proc
:= First
(Body_List
);
11133 while Present
(Alt
) loop
11135 if Nkind
(Alt
) = N_Accept_Alternative
then
11136 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11137 Index
:= Index
+ 1;
11140 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11145 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11146 Process_Delay_Alternative
(Alt
, Delay_Num
);
11147 Delay_Num
:= Delay_Num
+ 1;
11153 -- An others choice is always added to the main case, as well
11154 -- as the delay case (to satisfy the compiler).
11156 Append_To
(Alt_List
,
11157 Make_Case_Statement_Alternative
(Loc
,
11158 Discrete_Choices
=>
11159 New_List
(Make_Others_Choice
(Loc
)),
11161 New_List
(Make_Goto_Statement
(Loc
,
11162 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11164 Accept_Case
:= New_List
(
11165 Make_Case_Statement
(Loc
,
11166 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11167 Alternatives
=> Alt_List
));
11169 Append_List
(Trailing_List
, Accept_Case
);
11170 Append_List
(Body_List
, Decls
);
11172 -- Construct case statement for trailing statements of delay
11173 -- alternatives, if there are several of them.
11175 if Delay_Count
> 1 then
11176 Append_To
(Delay_Alt_List
,
11177 Make_Case_Statement_Alternative
(Loc
,
11178 Discrete_Choices
=>
11179 New_List
(Make_Others_Choice
(Loc
)),
11181 New_List
(Make_Null_Statement
(Loc
))));
11183 Delay_Case
:= New_List
(
11184 Make_Case_Statement
(Loc
,
11185 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11186 Alternatives
=> Delay_Alt_List
));
11188 Delay_Case
:= Delay_Alt_List
;
11191 -- If there are no delay alternatives, we append the case statement
11192 -- to the statement list.
11194 if Delay_Count
= 0 then
11195 Append_List
(Accept_Case
, Stats
);
11197 -- Delay alternatives present
11200 -- If delay alternatives are present we generate:
11202 -- find minimum delay.
11203 -- DX := minimum delay;
11204 -- M := <delay mode>;
11205 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11208 -- if X = No_Rendezvous then
11209 -- case statement for delay statements.
11211 -- case statement for accept alternatives.
11222 -- The type of the delay expression is known to be legal
11224 if Time_Type
= Standard_Duration
then
11225 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11227 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11228 Conv
:= Make_Function_Call
(Loc
,
11229 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11230 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11234 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11236 Conv
:= Make_Function_Call
(Loc
,
11237 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11238 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11241 Stmt
:= Make_Assignment_Statement
(Loc
,
11242 Name
=> New_Occurrence_Of
(D
, Loc
),
11243 Expression
=> Conv
);
11245 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11247 Parms
:= Parameter_Associations
(Select_Call
);
11249 Parm
:= First
(Parms
);
11250 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11254 pragma Assert
(Present
(Parm
));
11255 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11258 -- Prepare two new parameters of Duration and Delay_Mode type
11259 -- which represent the value and the mode of the minimum delay.
11262 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11263 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11265 -- Create a call to RTS
11267 Rewrite
(Select_Call
,
11268 Make_Procedure_Call_Statement
(Loc
,
11269 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11270 Parameter_Associations
=> Parms
));
11272 -- This new call should follow the calculation of the minimum
11275 Insert_List_Before
(Select_Call
, Delay_List
);
11277 if Check_Guard
then
11279 Make_Implicit_If_Statement
(N
,
11280 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11281 Then_Statements
=> New_List
(
11282 New_Copy_Tree
(Stmt
),
11283 New_Copy_Tree
(Select_Call
)),
11284 Else_Statements
=> Accept_Or_Raise
);
11285 Rewrite
(Select_Call
, Stmt
);
11287 Insert_Before
(Select_Call
, Stmt
);
11291 Make_Implicit_If_Statement
(N
,
11292 Condition
=> Make_Op_Eq
(Loc
,
11293 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11295 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11297 Then_Statements
=> Delay_Case
,
11298 Else_Statements
=> Accept_Case
);
11300 Append
(Cases
, Stats
);
11304 Append
(End_Lab
, Stats
);
11306 -- Replace accept statement with appropriate block
11309 Make_Block_Statement
(Loc
,
11310 Declarations
=> Decls
,
11311 Handled_Statement_Sequence
=>
11312 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11315 -- Note: have to worry more about abort deferral in above code ???
11317 -- Final step is to unstack the Accept_Address entries for all accept
11318 -- statements appearing in accept alternatives in the select statement
11320 Alt
:= First
(Alts
);
11321 while Present
(Alt
) loop
11322 if Nkind
(Alt
) = N_Accept_Alternative
then
11323 Remove_Last_Elmt
(Accept_Address
11324 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11329 end Expand_N_Selective_Accept
;
11331 -------------------------------------------
11332 -- Expand_N_Single_Protected_Declaration --
11333 -------------------------------------------
11335 -- A single protected declaration should never be present after semantic
11336 -- analysis because it is transformed into a protected type declaration
11337 -- and an accompanying anonymous object. This routine ensures that the
11338 -- transformation takes place.
11340 procedure Expand_N_Single_Protected_Declaration
(N
: Node_Id
) is
11342 raise Program_Error
;
11343 end Expand_N_Single_Protected_Declaration
;
11345 --------------------------------------
11346 -- Expand_N_Single_Task_Declaration --
11347 --------------------------------------
11349 -- A single task declaration should never be present after semantic
11350 -- analysis because it is transformed into a task type declaration and
11351 -- an accompanying anonymous object. This routine ensures that the
11352 -- transformation takes place.
11354 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11356 raise Program_Error
;
11357 end Expand_N_Single_Task_Declaration
;
11359 ------------------------
11360 -- Expand_N_Task_Body --
11361 ------------------------
11363 -- Given a task body
11365 -- task body tname is
11371 -- This expansion routine converts it into a procedure and sets the
11372 -- elaboration flag for the procedure to true, to represent the fact
11373 -- that the task body is now elaborated:
11375 -- procedure tnameB (_Task : access tnameV) is
11376 -- discriminal : dtype renames _Task.discriminant;
11378 -- procedure _clean is
11380 -- Abort_Defer.all;
11382 -- Abort_Undefer.all;
11387 -- Abort_Undefer.all;
11389 -- System.Task_Stages.Complete_Activation;
11397 -- In addition, if the task body is an activator, then a call to activate
11398 -- tasks is added at the start of the statements, before the call to
11399 -- Complete_Activation, and if in addition the task is a master then it
11400 -- must be established as a master. These calls are inserted and analyzed
11401 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11404 -- There is one discriminal declaration line generated for each
11405 -- discriminant that is present to provide an easy reference point for
11406 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11408 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11409 -- task body procedures have a profile (Arg : System.Address). That is
11410 -- needed because GNARLI has to use the same access-to-subprogram type
11411 -- for all task types. We depend here on knowing that in GNAT, passing
11412 -- an address argument by value is identical to passing a record value
11413 -- by access (in either case a single pointer is passed), so even though
11414 -- this procedure has the wrong profile. In fact it's all OK, since the
11415 -- callings sequence is identical.
11417 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11418 Loc
: constant Source_Ptr
:= Sloc
(N
);
11419 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11423 Insert_Nod
: Node_Id
;
11424 -- Used to determine the proper location of wrapper body insertions
11427 -- if no task body procedure, means we had an error in configurable
11428 -- run-time mode, and there is no point in proceeding further.
11430 if No
(Task_Body_Procedure
(Ttyp
)) then
11434 -- Add renaming declarations for discriminals and a declaration for the
11435 -- entry family index (if applicable).
11437 Install_Private_Data_Declarations
11438 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11440 -- Add a call to Abort_Undefer at the very beginning of the task
11441 -- body since this body is called with abort still deferred.
11443 if Abort_Allowed
then
11444 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11446 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11450 -- The statement part has already been protected with an at_end and
11451 -- cleanup actions. The call to Complete_Activation must be placed
11452 -- at the head of the sequence of statements of that block. The
11453 -- declarations have been merged in this sequence of statements but
11454 -- the first real statement is accessible from the First_Real_Statement
11455 -- field (which was set for exactly this purpose).
11457 if Restricted_Profile
then
11458 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11460 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11464 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11468 Make_Subprogram_Body
(Loc
,
11469 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11470 Declarations
=> Declarations
(N
),
11471 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11472 Set_Is_Task_Body_Procedure
(New_N
);
11474 -- If the task contains generic instantiations, cleanup actions are
11475 -- delayed until after instantiation. Transfer the activation chain to
11476 -- the subprogram, to insure that the activation call is properly
11477 -- generated. It the task body contains inner tasks, indicate that the
11478 -- subprogram is a task master.
11480 if Delay_Cleanups
(Ttyp
) then
11481 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11482 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11485 Rewrite
(N
, New_N
);
11488 -- Set elaboration flag immediately after task body. If the body is a
11489 -- subunit, the flag is set in the declarative part containing the stub.
11491 if Nkind
(Parent
(N
)) /= N_Subunit
then
11493 Make_Assignment_Statement
(Loc
,
11495 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11496 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11499 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11500 -- the task body. At this point all wrapper specs have been created,
11501 -- frozen and included in the dispatch table for the task type.
11503 if Ada_Version
>= Ada_2005
then
11504 if Nkind
(Parent
(N
)) = N_Subunit
then
11505 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11510 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11512 end Expand_N_Task_Body
;
11514 ------------------------------------
11515 -- Expand_N_Task_Type_Declaration --
11516 ------------------------------------
11518 -- We have several things to do. First we must create a Boolean flag used
11519 -- to mark if the body is elaborated yet. This variable gets set to True
11520 -- when the body of the task is elaborated (we can't rely on the normal
11521 -- ABE mechanism for the task body, since we need to pass an access to
11522 -- this elaboration boolean to the runtime routines).
11524 -- taskE : aliased Boolean := False;
11526 -- Next a variable is declared to hold the task stack size (either the
11527 -- default : Unspecified_Size, or a value that is set by a pragma
11528 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11529 -- the variable is initialized with this value:
11531 -- taskZ : Size_Type := Unspecified_Size;
11533 -- taskZ : Size_Type := Size_Type (size_expression);
11535 -- Note: No variable is needed to hold the task relative deadline since
11536 -- its value would never be static because the parameter is of a private
11537 -- type (Ada.Real_Time.Time_Span).
11539 -- Next we create a corresponding record type declaration used to represent
11540 -- values of this task. The general form of this type declaration is
11542 -- type taskV (discriminants) is record
11543 -- _Task_Id : Task_Id;
11544 -- entry_family : array (bounds) of Void;
11545 -- _Priority : Integer := priority_expression;
11546 -- _Size : Size_Type := size_expression;
11547 -- _Secondary_Stack_Size : Size_Type := size_expression;
11548 -- _Task_Info : Task_Info_Type := task_info_expression;
11549 -- _CPU : Integer := cpu_range_expression;
11550 -- _Relative_Deadline : Time_Span := time_span_expression;
11551 -- _Domain : Dispatching_Domain := dd_expression;
11554 -- The discriminants are present only if the corresponding task type has
11555 -- discriminants, and they exactly mirror the task type discriminants.
11557 -- The Id field is always present. It contains the Task_Id value, as set by
11558 -- the call to Create_Task. Note that although the task is limited, the
11559 -- task value record type is not limited, so there is no problem in passing
11560 -- this field as an out parameter to Create_Task.
11562 -- One entry_family component is present for each entry family in the task
11563 -- definition. The bounds correspond to the bounds of the entry family
11564 -- (which may depend on discriminants). The element type is void, since we
11565 -- only need the bounds information for determining the entry index. Note
11566 -- that the use of an anonymous array would normally be illegal in this
11567 -- context, but this is a parser check, and the semantics is quite prepared
11568 -- to handle such a case.
11570 -- The _Size field is present only if a Storage_Size pragma appears in the
11571 -- task definition. The expression captures the argument that was present
11572 -- in the pragma, and is used to override the task stack size otherwise
11573 -- associated with the task type.
11575 -- The _Secondary_Stack_Size field is present only the task entity has a
11576 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11577 -- when the record init proc is built, to capture the expression of the
11578 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11579 -- be filled here since aspect evaluations are delayed till the freeze
11582 -- The _Priority field is present only if the task entity has a Priority or
11583 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11584 -- definition clause). It will be filled at the freeze point, when the
11585 -- record init proc is built, to capture the expression of the rep item
11586 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11587 -- here since aspect evaluations are delayed till the freeze point.
11589 -- The _Task_Info field is present only if a Task_Info pragma appears in
11590 -- the task definition. The expression captures the argument that was
11591 -- present in the pragma, and is used to provide the Task_Image parameter
11592 -- to the call to Create_Task.
11594 -- The _CPU field is present only if the task entity has a CPU rep item
11595 -- (pragma, aspect specification or attribute definition clause). It will
11596 -- be filled at the freeze point, when the record init proc is built, to
11597 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11598 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11599 -- are delayed till the freeze point.
11601 -- The _Relative_Deadline field is present only if a Relative_Deadline
11602 -- pragma appears in the task definition. The expression captures the
11603 -- argument that was present in the pragma, and is used to provide the
11604 -- Relative_Deadline parameter to the call to Create_Task.
11606 -- The _Domain field is present only if the task entity has a
11607 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11608 -- definition clause). It will be filled at the freeze point, when the
11609 -- record init proc is built, to capture the expression of the rep item
11610 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11611 -- here since aspect evaluations are delayed till the freeze point.
11613 -- When a task is declared, an instance of the task value record is
11614 -- created. The elaboration of this declaration creates the correct bounds
11615 -- for the entry families, and also evaluates the size, priority, and
11616 -- task_Info expressions if needed. The initialization routine for the task
11617 -- type itself then calls Create_Task with appropriate parameters to
11618 -- initialize the value of the Task_Id field.
11620 -- Note: the address of this record is passed as the "Discriminants"
11621 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11622 -- body procedure, it does not matter that it does not quite match the
11623 -- GNARLI model of what is being passed (the record contains more than just
11624 -- the discriminants, but the discriminants can be found from the record
11627 -- The Entity_Id for this created record type is placed in the
11628 -- Corresponding_Record_Type field of the associated task type entity.
11630 -- Next we create a procedure specification for the task body procedure:
11632 -- procedure taskB (_Task : access taskV);
11634 -- Note that this must come after the record type declaration, since
11635 -- the spec refers to this type. It turns out that the initialization
11636 -- procedure for the value type references the task body spec, but that's
11637 -- fine, since it won't be generated till the freeze point for the type,
11638 -- which is certainly after the task body spec declaration.
11640 -- Finally, we set the task index value field of the entry attribute in
11641 -- the case of a simple entry.
11643 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11644 Loc
: constant Source_Ptr
:= Sloc
(N
);
11645 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11646 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11647 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11648 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11650 Body_Decl
: Node_Id
;
11652 Decl_Stack
: Node_Id
;
11653 Elab_Decl
: Node_Id
;
11654 Ent_Stack
: Entity_Id
;
11655 Proc_Spec
: Node_Id
;
11656 Rec_Decl
: Node_Id
;
11657 Rec_Ent
: Entity_Id
;
11658 Size_Decl
: Entity_Id
;
11659 Task_Size
: Node_Id
;
11661 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11662 -- Searches the task definition T for the first occurrence of the pragma
11663 -- Relative Deadline. The caller has ensured that the pragma is present
11664 -- in the task definition. Note that this routine cannot be implemented
11665 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11666 -- not chained because their expansion into a procedure call statement
11667 -- would cause a break in the chain.
11669 ----------------------------------
11670 -- Get_Relative_Deadline_Pragma --
11671 ----------------------------------
11673 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11677 N
:= First
(Visible_Declarations
(T
));
11678 while Present
(N
) loop
11679 if Nkind
(N
) = N_Pragma
11680 and then Pragma_Name
(N
) = Name_Relative_Deadline
11688 N
:= First
(Private_Declarations
(T
));
11689 while Present
(N
) loop
11690 if Nkind
(N
) = N_Pragma
11691 and then Pragma_Name
(N
) = Name_Relative_Deadline
11699 raise Program_Error
;
11700 end Get_Relative_Deadline_Pragma
;
11702 -- Start of processing for Expand_N_Task_Type_Declaration
11705 -- If already expanded, nothing to do
11707 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11711 -- Here we will do the expansion
11713 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11715 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11716 Cdecls
:= Component_Items
(Component_List
11717 (Type_Definition
(Rec_Decl
)));
11719 Qualify_Entity_Names
(N
);
11721 -- First create the elaboration variable
11724 Make_Object_Declaration
(Loc
,
11725 Defining_Identifier
=>
11726 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11727 Chars
=> New_External_Name
(Tasknm
, 'E')),
11728 Aliased_Present
=> True,
11729 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11730 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11732 Insert_After
(N
, Elab_Decl
);
11734 -- Next create the declaration of the size variable (tasknmZ)
11736 Set_Storage_Size_Variable
(Tasktyp
,
11737 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11738 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11740 if Present
(Taskdef
)
11741 and then Has_Storage_Size_Pragma
(Taskdef
)
11743 Is_OK_Static_Expression
11745 (First
(Pragma_Argument_Associations
11746 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11749 Make_Object_Declaration
(Loc
,
11750 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11751 Object_Definition
=>
11752 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11754 Convert_To
(RTE
(RE_Size_Type
),
11756 (Expression
(First
(Pragma_Argument_Associations
11758 (TaskId
, Name_Storage_Size
)))))));
11762 Make_Object_Declaration
(Loc
,
11763 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11764 Object_Definition
=>
11765 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11767 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11770 Insert_After
(Elab_Decl
, Size_Decl
);
11772 -- Next build the rest of the corresponding record declaration. This is
11773 -- done last, since the corresponding record initialization procedure
11774 -- will reference the previously created entities.
11776 -- Fill in the component declarations -- first the _Task_Id field
11779 Make_Component_Declaration
(Loc
,
11780 Defining_Identifier
=>
11781 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11782 Component_Definition
=>
11783 Make_Component_Definition
(Loc
,
11784 Aliased_Present
=> False,
11785 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11788 -- Declare static ATCB (that is, created by the expander) if we are
11789 -- using the Restricted run time.
11791 if Restricted_Profile
then
11793 Make_Component_Declaration
(Loc
,
11794 Defining_Identifier
=>
11795 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11797 Component_Definition
=>
11798 Make_Component_Definition
(Loc
,
11799 Aliased_Present
=> True,
11800 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11802 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11805 Make_Index_Or_Discriminant_Constraint
(Loc
,
11807 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11811 -- Declare static stack (that is, created by the expander) if we are
11812 -- using the Restricted run time on a bare board configuration.
11814 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11816 -- First we need to extract the appropriate stack size
11818 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11820 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11822 Expr_N
: constant Node_Id
:=
11823 Expression
(First
(
11824 Pragma_Argument_Associations
(
11825 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11826 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11827 P
: constant Node_Id
:= Parent
(Expr_N
);
11830 -- The stack is defined inside the corresponding record.
11831 -- Therefore if the size of the stack is set by means of
11832 -- a discriminant, we must reference the discriminant of the
11833 -- corresponding record type.
11835 if Nkind
(Expr_N
) in N_Has_Entity
11836 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11840 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11842 Set_Parent
(Task_Size
, P
);
11843 Set_Etype
(Task_Size
, Etyp
);
11844 Set_Analyzed
(Task_Size
);
11847 Task_Size
:= Relocate_Node
(Expr_N
);
11853 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11856 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11857 Defining_Identifier
=> Ent_Stack
,
11859 Component_Definition
=>
11860 Make_Component_Definition
(Loc
,
11861 Aliased_Present
=> True,
11862 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11864 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11867 Make_Index_Or_Discriminant_Constraint
(Loc
,
11868 Constraints
=> New_List
(Make_Range
(Loc
,
11869 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11870 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11873 Append_To
(Cdecls
, Decl_Stack
);
11875 -- The appropriate alignment for the stack is ensured by the run-time
11876 -- code in charge of task creation.
11880 -- Add components for entry families
11882 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11884 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11885 -- item is present.
11887 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
11889 Make_Component_Declaration
(Loc
,
11890 Defining_Identifier
=>
11891 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11892 Component_Definition
=>
11893 Make_Component_Definition
(Loc
,
11894 Aliased_Present
=> False,
11895 Subtype_Indication
=>
11896 New_Occurrence_Of
(Standard_Integer
, Loc
))));
11899 -- Add the _Size component if a Storage_Size pragma is present
11901 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11903 Make_Component_Declaration
(Loc
,
11904 Defining_Identifier
=>
11905 Make_Defining_Identifier
(Loc
, Name_uSize
),
11907 Component_Definition
=>
11908 Make_Component_Definition
(Loc
,
11909 Aliased_Present
=> False,
11910 Subtype_Indication
=>
11911 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
11914 Convert_To
(RTE
(RE_Size_Type
),
11916 Expression
(First
(
11917 Pragma_Argument_Associations
(
11918 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
11921 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
11922 -- rep item is present.
11925 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
11928 Make_Component_Declaration
(Loc
,
11929 Defining_Identifier
=>
11930 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack_Size
),
11932 Component_Definition
=>
11933 Make_Component_Definition
(Loc
,
11934 Aliased_Present
=> False,
11935 Subtype_Indication
=>
11936 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
))));
11939 -- Add the _Task_Info component if a Task_Info pragma is present
11941 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
11943 Make_Component_Declaration
(Loc
,
11944 Defining_Identifier
=>
11945 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11947 Component_Definition
=>
11948 Make_Component_Definition
(Loc
,
11949 Aliased_Present
=> False,
11950 Subtype_Indication
=>
11951 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
11953 Expression
=> New_Copy
(
11954 Expression
(First
(
11955 Pragma_Argument_Associations
(
11957 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
11960 -- Add the _CPU component if a CPU rep item is present
11962 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
11964 Make_Component_Declaration
(Loc
,
11965 Defining_Identifier
=>
11966 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11968 Component_Definition
=>
11969 Make_Component_Definition
(Loc
,
11970 Aliased_Present
=> False,
11971 Subtype_Indication
=>
11972 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
11975 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11976 -- present. If we are using a restricted run time this component will
11977 -- not be added (deadlines are not allowed by the Ravenscar profile),
11978 -- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
11981 if (not Restricted_Profile
or else Task_Dispatching_Policy
= 'E')
11982 and then Present
(Taskdef
)
11983 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11986 Make_Component_Declaration
(Loc
,
11987 Defining_Identifier
=>
11988 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11990 Component_Definition
=>
11991 Make_Component_Definition
(Loc
,
11992 Aliased_Present
=> False,
11993 Subtype_Indication
=>
11994 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
11997 Convert_To
(RTE
(RE_Time_Span
),
11999 Expression
(First
(
12000 Pragma_Argument_Associations
(
12001 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12004 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12005 -- item is present. If we are using a restricted run time this component
12006 -- will not be added (dispatching domains are not allowed by the
12007 -- Ravenscar profile).
12009 if not Restricted_Profile
12012 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12015 Make_Component_Declaration
(Loc
,
12016 Defining_Identifier
=>
12017 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12019 Component_Definition
=>
12020 Make_Component_Definition
(Loc
,
12021 Aliased_Present
=> False,
12022 Subtype_Indication
=>
12024 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12027 Insert_After
(Size_Decl
, Rec_Decl
);
12029 -- Analyze the record declaration immediately after construction,
12030 -- because the initialization procedure is needed for single task
12031 -- declarations before the next entity is analyzed.
12033 Analyze
(Rec_Decl
);
12035 -- Create the declaration of the task body procedure
12037 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12039 Make_Subprogram_Declaration
(Loc
,
12040 Specification
=> Proc_Spec
);
12041 Set_Is_Task_Body_Procedure
(Body_Decl
);
12043 Insert_After
(Rec_Decl
, Body_Decl
);
12045 -- The subprogram does not comes from source, so we have to indicate the
12046 -- need for debugging information explicitly.
12048 if Comes_From_Source
(Original_Node
(N
)) then
12049 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12052 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12053 -- the corresponding record has been frozen.
12055 if Ada_Version
>= Ada_2005
then
12056 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12059 -- Ada 2005 (AI-345): We must defer freezing to allow further
12060 -- declaration of primitive subprograms covering task interfaces
12062 if Ada_Version
<= Ada_95
then
12064 -- Now we can freeze the corresponding record. This needs manually
12065 -- freezing, since it is really part of the task type, and the task
12066 -- type is frozen at this stage. We of course need the initialization
12067 -- procedure for this corresponding record type and we won't get it
12068 -- in time if we don't freeze now.
12071 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
12073 if Is_Non_Empty_List
(L
) then
12074 Insert_List_After
(Body_Decl
, L
);
12079 -- Complete the expansion of access types to the current task type, if
12080 -- any were declared.
12082 Expand_Previous_Access_Type
(Tasktyp
);
12084 -- Create wrappers for entries that have contract cases, preconditions
12085 -- and postconditions.
12091 Ent
:= First_Entity
(Tasktyp
);
12092 while Present
(Ent
) loop
12093 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
) then
12094 Build_Contract_Wrapper
(Ent
, N
);
12100 end Expand_N_Task_Type_Declaration
;
12102 -------------------------------
12103 -- Expand_N_Timed_Entry_Call --
12104 -------------------------------
12106 -- A timed entry call in normal case is not implemented using ATC mechanism
12107 -- anymore for efficiency reason.
12117 -- is expanded as follows:
12119 -- 1) When T.E is a task entry_call;
12123 -- X : Task_Entry_Index := <entry index>;
12124 -- DX : Duration := To_Duration (D);
12125 -- M : Delay_Mode := <discriminant>;
12126 -- P : parms := (parm, parm, parm);
12129 -- Timed_Protected_Entry_Call
12130 -- (<acceptor-task>, X, P'Address, DX, M, B);
12138 -- 2) When T.E is a protected entry_call;
12142 -- X : Protected_Entry_Index := <entry index>;
12143 -- DX : Duration := To_Duration (D);
12144 -- M : Delay_Mode := <discriminant>;
12145 -- P : parms := (parm, parm, parm);
12148 -- Timed_Protected_Entry_Call
12149 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12157 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12158 -- is no delay and the triggering statements are executed. We first
12159 -- determine the kind of the triggering call and then execute a
12160 -- synchronized operation or a direct call.
12163 -- B : Boolean := False;
12164 -- C : Ada.Tags.Prim_Op_Kind;
12165 -- DX : Duration := To_Duration (D)
12166 -- K : Ada.Tags.Tagged_Kind :=
12167 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12168 -- M : Integer :=...;
12169 -- P : Parameters := (Param1 .. ParamN);
12173 -- if K = Ada.Tags.TK_Limited_Tagged
12174 -- or else K = Ada.Tags.TK_Tagged
12176 -- <dispatching-call>;
12181 -- Ada.Tags.Get_Offset_Index
12182 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12184 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12186 -- if C = POK_Protected_Entry
12187 -- or else C = POK_Task_Entry
12189 -- Param1 := P.Param1;
12191 -- ParamN := P.ParamN;
12195 -- if C = POK_Procedure
12196 -- or else C = POK_Protected_Procedure
12197 -- or else C = POK_Task_Procedure
12199 -- <dispatching-call>;
12205 -- <triggering-statements>
12207 -- <timed-statements>
12211 -- The triggering statement and the sequence of timed statements have not
12212 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12213 -- global references if within an instantiation.
12215 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12216 Loc
: constant Source_Ptr
:= Sloc
(N
);
12219 Blk_Typ
: Entity_Id
;
12221 Call_Ent
: Entity_Id
;
12222 Conc_Typ_Stmts
: List_Id
;
12224 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12227 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12229 D_Type
: Entity_Id
;
12232 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12233 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12238 Is_Disp_Select
: Boolean;
12239 Lim_Typ_Stmts
: List_Id
;
12248 B
: Entity_Id
; -- Call status flag
12249 C
: Entity_Id
; -- Call kind
12250 D
: Entity_Id
; -- Delay
12251 K
: Entity_Id
; -- Tagged kind
12252 M
: Entity_Id
; -- Delay mode
12253 P
: Entity_Id
; -- Parameter block
12254 S
: Entity_Id
; -- Primitive operation slot
12256 -- Start of processing for Expand_N_Timed_Entry_Call
12259 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12260 -- was already reported on spec, so do not attempt to expand the call.
12262 if Restriction_Active
(No_Select_Statements
) then
12266 Process_Statements_For_Controlled_Objects
(E_Alt
);
12267 Process_Statements_For_Controlled_Objects
(D_Alt
);
12269 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12271 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12272 -- may wrap them in blocks.
12274 E_Stats
:= Statements
(E_Alt
);
12275 D_Stats
:= Statements
(D_Alt
);
12277 -- The arguments in the call may require dynamic allocation, and the
12278 -- call statement may have been transformed into a block. The block
12279 -- may contain additional declarations for internal entities, and the
12280 -- original call is found by sequential search.
12282 if Nkind
(E_Call
) = N_Block_Statement
then
12283 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12284 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12285 N_Entry_Call_Statement
)
12292 Ada_Version
>= Ada_2005
12293 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12295 if Is_Disp_Select
then
12296 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12302 -- B : Boolean := False;
12304 B
:= Build_B
(Loc
, Decls
);
12307 -- C : Ada.Tags.Prim_Op_Kind;
12309 C
:= Build_C
(Loc
, Decls
);
12311 -- Because the analysis of all statements was disabled, manually
12312 -- analyze the delay statement.
12315 D_Stat
:= Original_Node
(D_Stat
);
12318 -- Build an entry call using Simple_Entry_Call
12320 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12321 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12323 Decls
:= Declarations
(E_Call
);
12324 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12333 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12336 Make_Object_Declaration
(Loc
,
12337 Defining_Identifier
=> B
,
12338 Object_Definition
=>
12339 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12342 -- Duration and mode processing
12344 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12346 -- Use the type of the delay expression (Calendar or Real_Time) to
12347 -- generate the appropriate conversion.
12349 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12350 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12351 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12353 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12354 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12356 Make_Function_Call
(Loc
,
12357 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12358 Parameter_Associations
=>
12359 New_List
(New_Copy
(Expression
(D_Stat
))));
12361 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12362 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12364 Make_Function_Call
(Loc
,
12365 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12366 Parameter_Associations
=>
12367 New_List
(New_Copy
(Expression
(D_Stat
))));
12370 D
:= Make_Temporary
(Loc
, 'D');
12376 Make_Object_Declaration
(Loc
,
12377 Defining_Identifier
=> D
,
12378 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12380 M
:= Make_Temporary
(Loc
, 'M');
12383 -- M : Integer := (0 | 1 | 2);
12386 Make_Object_Declaration
(Loc
,
12387 Defining_Identifier
=> M
,
12388 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12389 Expression
=> D_Disc
));
12391 -- Do the assignment at this stage only because the evaluation of the
12392 -- expression must not occur before (see ACVC C97302A).
12395 Make_Assignment_Statement
(Loc
,
12396 Name
=> New_Occurrence_Of
(D
, Loc
),
12397 Expression
=> D_Conv
));
12399 -- Parameter block processing
12401 -- Manually create the parameter block for dispatching calls. In the
12402 -- case of entries, the block has already been created during the call
12403 -- to Build_Simple_Entry_Call.
12405 if Is_Disp_Select
then
12407 -- Tagged kind processing, generate:
12408 -- K : Ada.Tags.Tagged_Kind :=
12409 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12411 K
:= Build_K
(Loc
, Decls
, Obj
);
12413 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12415 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12417 -- Dispatch table slot processing, generate:
12420 S
:= Build_S
(Loc
, Decls
);
12423 -- S := Ada.Tags.Get_Offset_Index
12424 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12427 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12430 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12432 -- where Obj is the controlling formal parameter, S is the dispatch
12433 -- table slot number of the dispatching operation, P is the wrapped
12434 -- parameter block, D is the duration, M is the duration mode, C is
12435 -- the call kind and B is the call status.
12437 Params
:= New_List
;
12439 Append_To
(Params
, New_Copy_Tree
(Obj
));
12440 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12442 Make_Attribute_Reference
(Loc
,
12443 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12444 Attribute_Name
=> Name_Address
));
12445 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12446 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12447 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12448 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12450 Append_To
(Conc_Typ_Stmts
,
12451 Make_Procedure_Call_Statement
(Loc
,
12455 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12456 Parameter_Associations
=> Params
));
12459 -- if C = POK_Protected_Entry
12460 -- or else C = POK_Task_Entry
12462 -- Param1 := P.Param1;
12464 -- ParamN := P.ParamN;
12467 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12469 -- Generate the if statement only when the packed parameters need
12470 -- explicit assignments to their corresponding actuals.
12472 if Present
(Unpack
) then
12473 Append_To
(Conc_Typ_Stmts
,
12474 Make_Implicit_If_Statement
(N
,
12480 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12483 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12487 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12489 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12491 Then_Statements
=> Unpack
));
12497 -- if C = POK_Procedure
12498 -- or else C = POK_Protected_Procedure
12499 -- or else C = POK_Task_Procedure
12501 -- <dispatching-call>
12505 N_Stats
:= New_List
(
12506 Make_Implicit_If_Statement
(N
,
12511 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12513 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12519 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12521 New_Occurrence_Of
(RTE
(
12522 RE_POK_Protected_Procedure
), Loc
)),
12525 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12528 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12530 Then_Statements
=> New_List
(E_Call
)));
12532 Append_To
(Conc_Typ_Stmts
,
12533 Make_Implicit_If_Statement
(N
,
12534 Condition
=> New_Occurrence_Of
(B
, Loc
),
12535 Then_Statements
=> N_Stats
));
12538 -- <dispatching-call>;
12542 New_List
(New_Copy_Tree
(E_Call
),
12543 Make_Assignment_Statement
(Loc
,
12544 Name
=> New_Occurrence_Of
(B
, Loc
),
12545 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12548 -- if K = Ada.Tags.TK_Limited_Tagged
12549 -- or else K = Ada.Tags.TK_Tagged
12557 Make_Implicit_If_Statement
(N
,
12558 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12559 Then_Statements
=> Lim_Typ_Stmts
,
12560 Else_Statements
=> Conc_Typ_Stmts
));
12565 -- <triggering-statements>
12567 -- <timed-statements>
12571 Make_Implicit_If_Statement
(N
,
12572 Condition
=> New_Occurrence_Of
(B
, Loc
),
12573 Then_Statements
=> E_Stats
,
12574 Else_Statements
=> D_Stats
));
12577 -- Simple case of a nondispatching trigger. Skip assignments to
12578 -- temporaries created for in-out parameters.
12580 -- This makes unwarranted assumptions about the shape of the expanded
12581 -- tree for the call, and should be cleaned up ???
12583 Stmt
:= First
(Stmts
);
12584 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12588 -- Do the assignment at this stage only because the evaluation
12589 -- of the expression must not occur before (see ACVC C97302A).
12591 Insert_Before
(Stmt
,
12592 Make_Assignment_Statement
(Loc
,
12593 Name
=> New_Occurrence_Of
(D
, Loc
),
12594 Expression
=> D_Conv
));
12597 Params
:= Parameter_Associations
(Call
);
12599 -- For a protected type, we build a Timed_Protected_Entry_Call
12601 if Is_Protected_Type
(Etype
(Concval
)) then
12603 -- Create a new call statement
12605 Param
:= First
(Params
);
12606 while Present
(Param
)
12607 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12612 Dummy
:= Remove_Next
(Next
(Param
));
12614 -- Remove garbage is following the Cancel_Param if present
12616 Dummy
:= Next
(Param
);
12618 -- Remove the mode of the Protected_Entry_Call call, then remove
12619 -- the Communication_Block of the Protected_Entry_Call call, and
12620 -- finally add Duration and a Delay_Mode parameter
12622 pragma Assert
(Present
(Param
));
12623 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12625 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12627 -- Add a Boolean flag for successful entry call
12629 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12631 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12632 when System_Tasking_Protected_Objects_Entries
=>
12634 Make_Procedure_Call_Statement
(Loc
,
12637 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12638 Parameter_Associations
=> Params
));
12641 raise Program_Error
;
12644 -- For the task case, build a Timed_Task_Entry_Call
12647 -- Create a new call statement
12649 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12650 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12651 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12654 Make_Procedure_Call_Statement
(Loc
,
12656 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12657 Parameter_Associations
=> Params
));
12661 Make_Implicit_If_Statement
(N
,
12662 Condition
=> New_Occurrence_Of
(B
, Loc
),
12663 Then_Statements
=> E_Stats
,
12664 Else_Statements
=> D_Stats
));
12668 Make_Block_Statement
(Loc
,
12669 Declarations
=> Decls
,
12670 Handled_Statement_Sequence
=>
12671 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12674 end Expand_N_Timed_Entry_Call
;
12676 ----------------------------------------
12677 -- Expand_Protected_Body_Declarations --
12678 ----------------------------------------
12680 procedure Expand_Protected_Body_Declarations
12682 Spec_Id
: Entity_Id
)
12685 if No_Run_Time_Mode
then
12686 Error_Msg_CRT
("protected body", N
);
12689 elsif Expander_Active
then
12691 -- Associate discriminals with the first subprogram or entry body to
12694 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12695 Set_Discriminals
(Parent
(Spec_Id
));
12698 end Expand_Protected_Body_Declarations
;
12700 -------------------------
12701 -- External_Subprogram --
12702 -------------------------
12704 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12705 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12708 -- The internal and external subprograms follow each other on the entity
12709 -- chain. Note that previously private operations had no separate
12710 -- external subprogram. We now create one in all cases, because a
12711 -- private operation may actually appear in an external call, through
12712 -- a 'Access reference used for a callback.
12714 -- If the operation is a function that returns an anonymous access type,
12715 -- the corresponding itype appears before the operation, and must be
12718 -- This mechanism is fragile, there should be a real link between the
12719 -- two versions of the operation, but there is no place to put it ???
12721 if Is_Access_Type
(Next_Entity
(Subp
)) then
12722 return Next_Entity
(Next_Entity
(Subp
));
12724 return Next_Entity
(Subp
);
12726 end External_Subprogram
;
12728 ------------------------------
12729 -- Extract_Dispatching_Call --
12730 ------------------------------
12732 procedure Extract_Dispatching_Call
12734 Call_Ent
: out Entity_Id
;
12735 Object
: out Entity_Id
;
12736 Actuals
: out List_Id
;
12737 Formals
: out List_Id
)
12739 Call_Nam
: Node_Id
;
12742 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12744 if Present
(Original_Node
(N
)) then
12745 Call_Nam
:= Name
(Original_Node
(N
));
12747 Call_Nam
:= Name
(N
);
12750 -- Retrieve the name of the dispatching procedure. It contains the
12751 -- dispatch table slot number.
12754 case Nkind
(Call_Nam
) is
12755 when N_Identifier
=>
12758 when N_Selected_Component
=>
12759 Call_Nam
:= Selector_Name
(Call_Nam
);
12762 raise Program_Error
;
12766 Actuals
:= Parameter_Associations
(N
);
12767 Call_Ent
:= Entity
(Call_Nam
);
12768 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12769 Object
:= First
(Actuals
);
12771 if Present
(Original_Node
(Object
)) then
12772 Object
:= Original_Node
(Object
);
12775 -- If the type of the dispatching object is an access type then return
12776 -- an explicit dereference.
12778 if Is_Access_Type
(Etype
(Object
)) then
12779 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12782 end Extract_Dispatching_Call
;
12784 -------------------
12785 -- Extract_Entry --
12786 -------------------
12788 procedure Extract_Entry
12790 Concval
: out Node_Id
;
12791 Ename
: out Node_Id
;
12792 Index
: out Node_Id
)
12794 Nam
: constant Node_Id
:= Name
(N
);
12797 -- For a simple entry, the name is a selected component, with the
12798 -- prefix being the task value, and the selector being the entry.
12800 if Nkind
(Nam
) = N_Selected_Component
then
12801 Concval
:= Prefix
(Nam
);
12802 Ename
:= Selector_Name
(Nam
);
12805 -- For a member of an entry family, the name is an indexed component
12806 -- where the prefix is a selected component, whose prefix in turn is
12807 -- the task value, and whose selector is the entry family. The single
12808 -- expression in the expressions list of the indexed component is the
12809 -- subscript for the family.
12811 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12812 Concval
:= Prefix
(Prefix
(Nam
));
12813 Ename
:= Selector_Name
(Prefix
(Nam
));
12814 Index
:= First
(Expressions
(Nam
));
12817 -- Through indirection, the type may actually be a limited view of a
12818 -- concurrent type. When compiling a call, the non-limited view of the
12819 -- type is visible.
12821 if From_Limited_With
(Etype
(Concval
)) then
12822 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12826 -------------------
12827 -- Family_Offset --
12828 -------------------
12830 function Family_Offset
12835 Cap
: Boolean) return Node_Id
12841 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12842 -- If one of the bounds is a reference to a discriminant, replace with
12843 -- corresponding discriminal of type. Within the body of a task retrieve
12844 -- the renamed discriminant by simple visibility, using its generated
12845 -- name. Within a protected object, find the original discriminant and
12846 -- replace it with the discriminal of the current protected operation.
12848 ------------------------------
12849 -- Convert_Discriminant_Ref --
12850 ------------------------------
12852 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12853 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12858 if Is_Entity_Name
(Bound
)
12859 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12861 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
12862 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12863 Find_Direct_Name
(B
);
12865 elsif Is_Protected_Type
(Ttyp
) then
12866 D
:= First_Discriminant
(Ttyp
);
12867 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12868 Next_Discriminant
(D
);
12871 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
12874 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
12877 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12881 B
:= New_Copy_Tree
(Bound
);
12885 Make_Attribute_Reference
(Loc
,
12886 Attribute_Name
=> Name_Pos
,
12887 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12888 Expressions
=> New_List
(B
));
12889 end Convert_Discriminant_Ref
;
12891 -- Start of processing for Family_Offset
12894 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12895 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12898 if Is_Task_Type
(Ttyp
) then
12899 Ityp
:= RTE
(RE_Task_Entry_Index
);
12901 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12905 Make_Attribute_Reference
(Loc
,
12906 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12907 Attribute_Name
=> Name_Min
,
12908 Expressions
=> New_List
(
12910 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12913 Make_Attribute_Reference
(Loc
,
12914 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12915 Attribute_Name
=> Name_Max
,
12916 Expressions
=> New_List
(
12918 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12921 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12928 function Family_Size
12933 Cap
: Boolean) return Node_Id
12938 if Is_Task_Type
(Ttyp
) then
12939 Ityp
:= RTE
(RE_Task_Entry_Index
);
12941 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12945 Make_Attribute_Reference
(Loc
,
12946 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12947 Attribute_Name
=> Name_Max
,
12948 Expressions
=> New_List
(
12950 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12951 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
12952 Make_Integer_Literal
(Loc
, 0)));
12955 ----------------------------
12956 -- Find_Enclosing_Context --
12957 ----------------------------
12959 procedure Find_Enclosing_Context
12961 Context
: out Node_Id
;
12962 Context_Id
: out Entity_Id
;
12963 Context_Decls
: out List_Id
)
12966 -- Traverse the parent chain looking for an enclosing body, block,
12967 -- package or return statement.
12969 Context
:= Parent
(N
);
12970 while Present
(Context
) loop
12971 if Nkind_In
(Context
, N_Entry_Body
,
12972 N_Extended_Return_Statement
,
12974 N_Package_Declaration
,
12980 -- Do not consider block created to protect a list of statements with
12981 -- an Abort_Defer / Abort_Undefer_Direct pair.
12983 elsif Nkind
(Context
) = N_Block_Statement
12984 and then not Is_Abort_Block
(Context
)
12989 Context
:= Parent
(Context
);
12992 pragma Assert
(Present
(Context
));
12994 -- Extract the constituents of the context
12996 if Nkind
(Context
) = N_Extended_Return_Statement
then
12997 Context_Decls
:= Return_Object_Declarations
(Context
);
12998 Context_Id
:= Return_Statement_Entity
(Context
);
13000 -- Package declarations and bodies use a common library-level activation
13001 -- chain or task master, therefore return the package declaration as the
13002 -- proper carrier for the appropriate flag.
13004 elsif Nkind
(Context
) = N_Package_Body
then
13005 Context_Decls
:= Declarations
(Context
);
13006 Context_Id
:= Corresponding_Spec
(Context
);
13007 Context
:= Parent
(Context_Id
);
13009 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13010 Context
:= Parent
(Parent
(Context
));
13012 Context
:= Parent
(Context
);
13015 elsif Nkind
(Context
) = N_Package_Declaration
then
13016 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13017 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13019 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13020 Context_Id
:= Defining_Identifier
(Context_Id
);
13024 if Nkind
(Context
) = N_Block_Statement
then
13025 Context_Id
:= Entity
(Identifier
(Context
));
13027 elsif Nkind
(Context
) = N_Entry_Body
then
13028 Context_Id
:= Defining_Identifier
(Context
);
13030 elsif Nkind
(Context
) = N_Subprogram_Body
then
13031 if Present
(Corresponding_Spec
(Context
)) then
13032 Context_Id
:= Corresponding_Spec
(Context
);
13034 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13036 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13037 Context_Id
:= Defining_Identifier
(Context_Id
);
13041 elsif Nkind
(Context
) = N_Task_Body
then
13042 Context_Id
:= Corresponding_Spec
(Context
);
13045 raise Program_Error
;
13048 Context_Decls
:= Declarations
(Context
);
13051 pragma Assert
(Present
(Context_Id
));
13052 pragma Assert
(Present
(Context_Decls
));
13053 end Find_Enclosing_Context
;
13055 -----------------------
13056 -- Find_Master_Scope --
13057 -----------------------
13059 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13063 -- In Ada 2005, the master is the innermost enclosing scope that is not
13064 -- transient. If the enclosing block is the rewriting of a call or the
13065 -- scope is an extended return statement this is valid master. The
13066 -- master in an extended return is only used within the return, and is
13067 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13068 -- now before that overwriting occurs.
13072 if Ada_Version
>= Ada_2005
then
13073 while Is_Internal
(S
) loop
13074 if Nkind
(Parent
(S
)) = N_Block_Statement
13076 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
13080 elsif Ekind
(S
) = E_Return_Statement
then
13090 end Find_Master_Scope
;
13092 -------------------------------
13093 -- First_Protected_Operation --
13094 -------------------------------
13096 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13097 First_Op
: Node_Id
;
13100 First_Op
:= First
(D
);
13101 while Present
(First_Op
)
13102 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
13108 end First_Protected_Operation
;
13110 ---------------------------------------
13111 -- Install_Private_Data_Declarations --
13112 ---------------------------------------
13114 procedure Install_Private_Data_Declarations
13116 Spec_Id
: Entity_Id
;
13117 Conc_Typ
: Entity_Id
;
13118 Body_Nod
: Node_Id
;
13120 Barrier
: Boolean := False;
13121 Family
: Boolean := False)
13123 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13126 Insert_Node
: Node_Id
:= Empty
;
13127 Obj_Ent
: Entity_Id
;
13129 procedure Add
(Decl
: Node_Id
);
13130 -- Add a single declaration after Insert_Node. If this is the first
13131 -- addition, Decl is added to the front of Decls and it becomes the
13134 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13135 -- The bounds of an entry index may depend on discriminants, create a
13136 -- reference to the corresponding prival. Otherwise return a duplicate
13137 -- of the original bound.
13143 procedure Add
(Decl
: Node_Id
) is
13145 if No
(Insert_Node
) then
13146 Prepend_To
(Decls
, Decl
);
13148 Insert_After
(Insert_Node
, Decl
);
13151 Insert_Node
:= Decl
;
13154 --------------------------
13155 -- Replace_Discriminant --
13156 --------------------------
13158 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13160 if Nkind
(Bound
) = N_Identifier
13161 and then Is_Discriminal
(Entity
(Bound
))
13163 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13165 return Duplicate_Subexpr
(Bound
);
13169 -- Start of processing for Install_Private_Data_Declarations
13172 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13173 -- formal parameter _O, _object or _task depending on the context.
13175 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13177 -- Special processing of _O for barrier functions, protected entries
13184 (Ekind
(Spec_Id
) = E_Entry
13185 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13188 Conc_Rec
: constant Entity_Id
:=
13189 Corresponding_Record_Type
(Conc_Typ
);
13190 Typ_Id
: constant Entity_Id
:=
13191 Make_Defining_Identifier
(Loc
,
13192 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13195 -- type prot_typVP is access prot_typV;
13198 Make_Full_Type_Declaration
(Loc
,
13199 Defining_Identifier
=> Typ_Id
,
13201 Make_Access_To_Object_Definition
(Loc
,
13202 Subtype_Indication
=>
13203 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13207 -- _object : prot_typVP := prot_typV (_O);
13210 Make_Object_Declaration
(Loc
,
13211 Defining_Identifier
=>
13212 Make_Defining_Identifier
(Loc
, Name_uObject
),
13213 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13215 Unchecked_Convert_To
(Typ_Id
,
13216 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13219 -- Set the reference to the concurrent object
13221 Obj_Ent
:= Defining_Identifier
(Decl
);
13225 -- Step 2: Create the Protection object and build its declaration for
13226 -- any protected entry (family) of subprogram. Note for the lock-free
13227 -- implementation, the Protection object is not needed anymore.
13229 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13231 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13235 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13237 -- Determine the proper protection type
13239 if Has_Attach_Handler
(Conc_Typ
)
13240 and then not Restricted_Profile
13242 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13244 elsif Has_Interrupt_Handler
(Conc_Typ
)
13245 and then not Restriction_Active
(No_Dynamic_Attachment
)
13247 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13250 case Corresponding_Runtime_Package
(Conc_Typ
) is
13251 when System_Tasking_Protected_Objects_Entries
=>
13252 Prot_Typ
:= RE_Protection_Entries
;
13254 when System_Tasking_Protected_Objects_Single_Entry
=>
13255 Prot_Typ
:= RE_Protection_Entry
;
13257 when System_Tasking_Protected_Objects
=>
13258 Prot_Typ
:= RE_Protection
;
13261 raise Program_Error
;
13266 -- conc_typR : protection_typ renames _object._object;
13269 Make_Object_Renaming_Declaration
(Loc
,
13270 Defining_Identifier
=> Prot_Ent
,
13272 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13274 Make_Selected_Component
(Loc
,
13275 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13276 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13281 -- Step 3: Add discriminant renamings (if any)
13283 if Has_Discriminants
(Conc_Typ
) then
13288 D
:= First_Discriminant
(Conc_Typ
);
13289 while Present
(D
) loop
13291 -- Adjust the source location
13293 Set_Sloc
(Discriminal
(D
), Loc
);
13296 -- discr_name : discr_typ renames _object.discr_name;
13298 -- discr_name : discr_typ renames _task.discr_name;
13301 Make_Object_Renaming_Declaration
(Loc
,
13302 Defining_Identifier
=> Discriminal
(D
),
13303 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13305 Make_Selected_Component
(Loc
,
13306 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13307 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13310 Next_Discriminant
(D
);
13315 -- Step 4: Add private component renamings (if any)
13317 if Is_Protected
then
13318 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13320 if Present
(Private_Declarations
(Def
)) then
13323 Comp_Id
: Entity_Id
;
13324 Decl_Id
: Entity_Id
;
13327 Comp
:= First
(Private_Declarations
(Def
));
13328 while Present
(Comp
) loop
13329 if Nkind
(Comp
) = N_Component_Declaration
then
13330 Comp_Id
:= Defining_Identifier
(Comp
);
13332 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13334 -- Minimal decoration
13336 if Ekind
(Spec_Id
) = E_Function
then
13337 Set_Ekind
(Decl_Id
, E_Constant
);
13339 Set_Ekind
(Decl_Id
, E_Variable
);
13342 Set_Prival
(Comp_Id
, Decl_Id
);
13343 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13344 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13347 -- comp_name : comp_typ renames _object.comp_name;
13350 Make_Object_Renaming_Declaration
(Loc
,
13351 Defining_Identifier
=> Decl_Id
,
13353 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13355 Make_Selected_Component
(Loc
,
13357 New_Occurrence_Of
(Obj_Ent
, Loc
),
13359 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13369 -- Step 5: Add the declaration of the entry index and the associated
13370 -- type for barrier functions and entry families.
13372 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13374 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13375 Index
: constant Entity_Id
:=
13376 Defining_Identifier
13377 (Entry_Index_Specification
13378 (Entry_Body_Formal_Part
(Body_Nod
)));
13379 Index_Con
: constant Entity_Id
:=
13380 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13382 Index_Typ
: Entity_Id
;
13386 -- Minimal decoration
13388 Set_Ekind
(Index_Con
, E_Constant
);
13389 Set_Entry_Index_Constant
(Index
, Index_Con
);
13390 Set_Discriminal_Link
(Index_Con
, Index
);
13392 -- Retrieve the bounds of the entry family
13394 High
:= Type_High_Bound
(Etype
(Index
));
13395 Low
:= Type_Low_Bound
(Etype
(Index
));
13397 -- In the simple case the entry family is given by a subtype mark
13398 -- and the index constant has the same type.
13400 if Is_Entity_Name
(Original_Node
(
13401 Discrete_Subtype_Definition
(Parent
(Index
))))
13403 Index_Typ
:= Etype
(Index
);
13405 -- Otherwise a new subtype declaration is required
13408 High
:= Replace_Bound
(High
);
13409 Low
:= Replace_Bound
(Low
);
13411 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13414 -- subtype Jnn is <Etype of Index> range Low .. High;
13417 Make_Subtype_Declaration
(Loc
,
13418 Defining_Identifier
=> Index_Typ
,
13419 Subtype_Indication
=>
13420 Make_Subtype_Indication
(Loc
,
13422 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13424 Make_Range_Constraint
(Loc
,
13425 Range_Expression
=>
13426 Make_Range
(Loc
, Low
, High
))));
13430 Set_Etype
(Index_Con
, Index_Typ
);
13432 -- Create the object which designates the index:
13433 -- J : constant Jnn :=
13434 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13436 -- where Jnn is the subtype created above or the original type of
13437 -- the index, _E is a formal of the protected body subprogram and
13438 -- <index expr> is the index of the first family member.
13441 Make_Object_Declaration
(Loc
,
13442 Defining_Identifier
=> Index_Con
,
13443 Constant_Present
=> True,
13444 Object_Definition
=>
13445 New_Occurrence_Of
(Index_Typ
, Loc
),
13448 Make_Attribute_Reference
(Loc
,
13450 New_Occurrence_Of
(Index_Typ
, Loc
),
13451 Attribute_Name
=> Name_Val
,
13453 Expressions
=> New_List
(
13457 Make_Op_Subtract
(Loc
,
13458 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13460 Entry_Index_Expression
(Loc
,
13461 Defining_Identifier
(Body_Nod
),
13465 Make_Attribute_Reference
(Loc
,
13467 New_Occurrence_Of
(Index_Typ
, Loc
),
13468 Attribute_Name
=> Name_Pos
,
13469 Expressions
=> New_List
(
13470 Make_Attribute_Reference
(Loc
,
13472 New_Occurrence_Of
(Index_Typ
, Loc
),
13473 Attribute_Name
=> Name_First
)))))));
13477 end Install_Private_Data_Declarations
;
13479 ---------------------------------
13480 -- Is_Potentially_Large_Family --
13481 ---------------------------------
13483 function Is_Potentially_Large_Family
13484 (Base_Index
: Entity_Id
;
13485 Conctyp
: Entity_Id
;
13487 Hi
: Node_Id
) return Boolean
13490 return Scope
(Base_Index
) = Standard_Standard
13491 and then Base_Index
= Base_Type
(Standard_Integer
)
13492 and then Has_Discriminants
(Conctyp
)
13494 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13496 (Denotes_Discriminant
(Lo
, True)
13498 Denotes_Discriminant
(Hi
, True));
13499 end Is_Potentially_Large_Family
;
13501 -------------------------------------
13502 -- Is_Private_Primitive_Subprogram --
13503 -------------------------------------
13505 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13508 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13509 and then Is_Private_Primitive
(Id
);
13510 end Is_Private_Primitive_Subprogram
;
13516 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13517 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13518 Formal
: Entity_Id
;
13521 Formal
:= First_Formal
(Bod_Subp
);
13522 while Present
(Formal
) loop
13524 -- Look for formal parameter _E
13526 if Chars
(Formal
) = Name_uE
then
13530 Next_Formal
(Formal
);
13533 -- A protected body subprogram should always have the parameter in
13536 raise Program_Error
;
13539 --------------------------------
13540 -- Make_Initialize_Protection --
13541 --------------------------------
13543 function Make_Initialize_Protection
13544 (Protect_Rec
: Entity_Id
) return List_Id
13546 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13549 Ptyp
: constant Node_Id
:=
13550 Corresponding_Concurrent_Type
(Protect_Rec
);
13552 L
: constant List_Id
:= New_List
;
13553 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13554 Prio_Type
: Entity_Id
;
13555 Prio_Var
: Entity_Id
:= Empty
;
13556 Restricted
: constant Boolean := Restricted_Profile
;
13559 -- We may need two calls to properly initialize the object, one to
13560 -- Initialize_Protection, and possibly one to Install_Handlers if we
13561 -- have a pragma Attach_Handler.
13563 -- Get protected declaration. In the case of a task type declaration,
13564 -- this is simply the parent of the protected type entity. In the single
13565 -- protected object declaration, this parent will be the implicit type,
13566 -- and we can find the corresponding single protected object declaration
13567 -- by searching forward in the declaration list in the tree.
13569 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13570 -- of this type should have been removed during semantic analysis.
13572 Pdec
:= Parent
(Ptyp
);
13573 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13574 N_Single_Protected_Declaration
)
13579 -- Build the parameter list for the call. Note that _Init is the name
13580 -- of the formal for the object to be initialized, which is the task
13581 -- value record itself.
13585 -- For lock-free implementation, skip initializations of the Protection
13588 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13590 -- Object parameter. This is a pointer to the object of type
13591 -- Protection used by the GNARL to control the protected object.
13594 Make_Attribute_Reference
(Loc
,
13596 Make_Selected_Component
(Loc
,
13597 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13598 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13599 Attribute_Name
=> Name_Unchecked_Access
));
13601 -- Priority parameter. Set to Unspecified_Priority unless there is a
13602 -- Priority rep item, in which case we take the value from the pragma
13603 -- or attribute definition clause, or there is an Interrupt_Priority
13604 -- rep item and no Priority rep item, and we set the ceiling to
13605 -- Interrupt_Priority'Last, an implementation-defined value, see
13608 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13610 Prio_Clause
: constant Node_Id
:=
13612 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13619 if Nkind
(Prio_Clause
) = N_Pragma
then
13622 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13624 -- Get_Rep_Item returns either priority pragma
13626 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13627 Prio_Type
:= RTE
(RE_Any_Priority
);
13629 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13632 -- Attribute definition clause Priority
13635 if Chars
(Prio_Clause
) = Name_Priority
then
13636 Prio_Type
:= RTE
(RE_Any_Priority
);
13638 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13641 Prio
:= Expression
(Prio_Clause
);
13644 -- Always create a locale variable to capture the priority.
13645 -- The priority is also passed to Install_Restriced_Handlers.
13646 -- Note that it is really necessary to create this variable
13647 -- explicitly. It might be thought that removing side effects
13648 -- would the appropriate approach, but that could generate
13649 -- declarations improperly placed in the enclosing scope.
13651 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13653 Make_Object_Declaration
(Loc
,
13654 Defining_Identifier
=> Prio_Var
,
13655 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13656 Expression
=> Relocate_Node
(Prio
)));
13658 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13661 -- When no priority is specified but an xx_Handler pragma is, we
13662 -- default to System.Interrupts.Default_Interrupt_Priority, see
13665 elsif Has_Attach_Handler
(Ptyp
)
13666 or else Has_Interrupt_Handler
(Ptyp
)
13669 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13671 -- Normal case, no priority or xx_Handler specified, default priority
13675 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13678 -- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
13680 if Restricted_Profile
and Task_Dispatching_Policy
= 'E' then
13681 Deadline_Floor
: declare
13682 Item
: constant Node_Id
:=
13684 (Ptyp
, Name_Deadline_Floor
, Check_Parents
=> False);
13686 Deadline
: Node_Id
;
13689 if Present
(Item
) then
13691 -- Pragma Deadline_Floor
13693 if Nkind
(Item
) = N_Pragma
then
13696 (First
(Pragma_Argument_Associations
(Item
)));
13698 -- Attribute definition clause Deadline_Floor
13702 (Nkind
(Item
) = N_Attribute_Definition_Clause
);
13704 Deadline
:= Expression
(Item
);
13707 Append_To
(Args
, Deadline
);
13709 -- Unusual case: default deadline
13713 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
13715 end Deadline_Floor
;
13718 -- Test for Compiler_Info parameter. This parameter allows entry body
13719 -- procedures and barrier functions to be called from the runtime. It
13720 -- is a pointer to the record generated by the compiler to represent
13721 -- the protected object.
13723 -- A protected type without entries that covers an interface and
13724 -- overrides the abstract routines with protected procedures is
13725 -- considered equivalent to a protected type with entries in the
13726 -- context of dispatching select statements.
13728 -- Protected types with interrupt handlers (when not using a
13729 -- restricted profile) are also considered equivalent to protected
13730 -- types with entries.
13732 -- The types which are used (Static_Interrupt_Protection and
13733 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13736 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13738 Called_Subp
: RE_Id
;
13742 when System_Tasking_Protected_Objects_Entries
=>
13743 Called_Subp
:= RE_Initialize_Protection_Entries
;
13745 -- Argument Compiler_Info
13748 Make_Attribute_Reference
(Loc
,
13749 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13750 Attribute_Name
=> Name_Address
));
13752 when System_Tasking_Protected_Objects_Single_Entry
=>
13753 Called_Subp
:= RE_Initialize_Protection_Entry
;
13755 -- Argument Compiler_Info
13758 Make_Attribute_Reference
(Loc
,
13759 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13760 Attribute_Name
=> Name_Address
));
13762 when System_Tasking_Protected_Objects
=>
13763 Called_Subp
:= RE_Initialize_Protection
;
13766 raise Program_Error
;
13769 -- Entry_Queue_Maxes parameter. This is an access to an array of
13770 -- naturals representing the entry queue maximums for each entry
13771 -- in the protected type. Zero represents no max. The access is
13772 -- null if there is no limit for all entries (usual case).
13775 and then Pkg_Id
= System_Tasking_Protected_Objects_Entries
13777 if Present
(Entry_Max_Queue_Lengths_Array
(Ptyp
)) then
13779 Make_Attribute_Reference
(Loc
,
13782 (Entry_Max_Queue_Lengths_Array
(Ptyp
), Loc
),
13783 Attribute_Name
=> Name_Unrestricted_Access
));
13785 Append_To
(Args
, Make_Null
(Loc
));
13788 -- Edge cases exist where entry initialization functions are
13789 -- called, but no entries exist, so null is appended.
13791 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13792 Append_To
(Args
, Make_Null
(Loc
));
13795 -- Entry_Bodies parameter. This is a pointer to an array of
13796 -- pointers to the entry body procedures and barrier functions of
13797 -- the object. If the protected type has no entries this object
13798 -- will not exist, in this case, pass a null (it can happen when
13799 -- there are protected interrupt handlers or interfaces).
13802 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13804 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13805 -- multiple entries).
13808 Make_Attribute_Reference
(Loc
,
13809 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13810 Attribute_Name
=> Name_Unrestricted_Access
));
13812 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13814 -- Find index mapping function (clumsy but ok for now)
13816 while Ekind
(P_Arr
) /= E_Function
loop
13817 Next_Entity
(P_Arr
);
13821 Make_Attribute_Reference
(Loc
,
13822 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13823 Attribute_Name
=> Name_Unrestricted_Access
));
13826 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13828 -- This is the case where we have a protected object with
13829 -- interfaces and no entries, and the single entry restriction
13830 -- is in effect. We pass a null pointer for the entry
13831 -- parameter because there is no actual entry.
13833 Append_To
(Args
, Make_Null
(Loc
));
13835 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13837 -- This is the case where we have a protected object with no
13839 -- - either interrupt handlers with non restricted profile,
13841 -- Note that the types which are used for interrupt handlers
13842 -- (Static/Dynamic_Interrupt_Protection) are derived from
13843 -- Protection_Entries. We pass two null pointers because there
13844 -- is no actual entry, and the initialization procedure needs
13845 -- both Entry_Bodies and Find_Body_Index.
13847 Append_To
(Args
, Make_Null
(Loc
));
13848 Append_To
(Args
, Make_Null
(Loc
));
13852 Make_Procedure_Call_Statement
(Loc
,
13854 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
13855 Parameter_Associations
=> Args
));
13859 if Has_Attach_Handler
(Ptyp
) then
13861 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13862 -- make the following call:
13864 -- Install_Handlers (_object,
13865 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13867 -- or, in the case of Ravenscar:
13869 -- Install_Restricted_Handlers
13870 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
13873 Args
: constant List_Id
:= New_List
;
13874 Table
: constant List_Id
:= New_List
;
13875 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13878 -- Build the Priority parameter (only for ravenscar)
13882 -- Priority comes from a pragma
13884 if Present
(Prio_Var
) then
13885 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13887 -- Priority is the default one
13892 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
13896 -- Build the Attach_Handler table argument
13898 while Present
(Ritem
) loop
13899 if Nkind
(Ritem
) = N_Pragma
13900 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13903 Handler
: constant Node_Id
:=
13904 First
(Pragma_Argument_Associations
(Ritem
));
13906 Interrupt
: constant Node_Id
:= Next
(Handler
);
13907 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13911 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13912 Unchecked_Convert_To
13913 (RTE
(RE_System_Interrupt_Id
), Expr
),
13914 Make_Attribute_Reference
(Loc
,
13916 Make_Selected_Component
(Loc
,
13918 Make_Identifier
(Loc
, Name_uInit
),
13920 Duplicate_Subexpr_No_Checks
13921 (Expression
(Handler
))),
13922 Attribute_Name
=> Name_Access
))));
13926 Next_Rep_Item
(Ritem
);
13929 -- Append the table argument we just built
13931 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13933 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13934 -- call to the statements.
13937 -- Call a simplified version of Install_Handlers to be used
13938 -- when the Ravenscar restrictions are in effect
13939 -- (Install_Restricted_Handlers).
13942 Make_Procedure_Call_Statement
(Loc
,
13945 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13946 Parameter_Associations
=> Args
));
13949 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13951 -- First, prepends the _object argument
13954 Make_Attribute_Reference
(Loc
,
13956 Make_Selected_Component
(Loc
,
13957 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13959 Make_Identifier
(Loc
, Name_uObject
)),
13960 Attribute_Name
=> Name_Unchecked_Access
));
13963 -- Then, insert call to Install_Handlers
13966 Make_Procedure_Call_Statement
(Loc
,
13968 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
13969 Parameter_Associations
=> Args
));
13975 end Make_Initialize_Protection
;
13977 ---------------------------
13978 -- Make_Task_Create_Call --
13979 ---------------------------
13981 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
13982 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
13992 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
13993 Tnam
:= Chars
(Ttyp
);
13995 -- Get task declaration. In the case of a task type declaration, this is
13996 -- simply the parent of the task type entity. In the single task
13997 -- declaration, this parent will be the implicit type, and we can find
13998 -- the corresponding single task declaration by searching forward in the
13999 -- declaration list in the tree.
14001 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14002 -- this type should have been removed during semantic analysis.
14004 Tdec
:= Parent
(Ttyp
);
14005 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
14006 N_Single_Task_Declaration
)
14011 -- Now we can find the task definition from this declaration
14013 Tdef
:= Task_Definition
(Tdec
);
14015 -- Build the parameter list for the call. Note that _Init is the name
14016 -- of the formal for the object to be initialized, which is the task
14017 -- value record itself.
14021 -- Priority parameter. Set to Unspecified_Priority unless there is a
14022 -- Priority rep item, in which case we take the value from the rep item.
14023 -- Not used on Ravenscar_EDF profile.
14025 if not (Restricted_Profile
and then Task_Dispatching_Policy
= 'E') then
14026 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14028 Make_Selected_Component
(Loc
,
14029 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14030 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14033 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14037 -- Optional Stack parameter
14039 if Restricted_Profile
then
14041 -- If the stack has been preallocated by the expander then
14042 -- pass its address. Otherwise, pass a null address.
14044 if Preallocated_Stacks_On_Target
then
14046 Make_Attribute_Reference
(Loc
,
14048 Make_Selected_Component
(Loc
,
14049 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14050 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14051 Attribute_Name
=> Name_Address
));
14055 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14059 -- Size parameter. If no Storage_Size pragma is present, then
14060 -- the size is taken from the taskZ variable for the type, which
14061 -- is either Unspecified_Size, or has been reset by the use of
14062 -- a Storage_Size attribute definition clause. If a pragma is
14063 -- present, then the size is taken from the _Size field of the
14064 -- task value record, which was set from the pragma value.
14066 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14068 Make_Selected_Component
(Loc
,
14069 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14070 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14074 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14077 -- Secondary_Stack_Size parameter. Set Default_Secondary_Stack_Size
14078 -- unless there is a Secondary_Stack_Size rep item, in which case we
14079 -- take the value from the rep item. If the restriction
14080 -- No_Secondary_Stack is active then a size of 0 is passed regardless
14081 -- to prevent the allocation of the unused stack.
14083 if Restriction_Active
(No_Secondary_Stack
) then
14084 Append_To
(Args
, Make_Integer_Literal
(Loc
, 0));
14087 (Ttyp
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
14090 Make_Selected_Component
(Loc
,
14091 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14093 Make_Identifier
(Loc
, Name_uSecondary_Stack_Size
)));
14097 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
14100 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14101 -- Task_Info pragma, in which case we take the value from the pragma.
14103 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14105 Make_Selected_Component
(Loc
,
14106 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14107 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14111 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14114 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14115 -- in which case we take the value from the rep item. The parameter is
14116 -- passed as an Integer because in the case of unspecified CPU the
14117 -- value is not in the range of CPU_Range.
14119 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14121 Convert_To
(Standard_Integer
,
14122 Make_Selected_Component
(Loc
,
14123 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14124 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14127 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14130 if not Restricted_Profile
or else Task_Dispatching_Policy
= 'E' then
14132 -- Deadline parameter. If no Relative_Deadline pragma is present,
14133 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14134 -- the deadline is taken from the _Relative_Deadline field of the
14135 -- task value record, which was set from the pragma value. Note that
14136 -- this parameter must not be generated for the restricted profiles
14137 -- since Ravenscar does not allow deadlines.
14139 -- Case where pragma Relative_Deadline applies: use given value
14141 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14143 Make_Selected_Component
(Loc
,
14144 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14146 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14148 -- No pragma Relative_Deadline apply to the task
14152 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14156 if not Restricted_Profile
then
14158 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14159 -- present, then the dispatching domain is null. If a rep item is
14160 -- present, then the dispatching domain is taken from the
14161 -- _Dispatching_Domain field of the task value record, which was set
14162 -- from the rep item value.
14164 -- Case where Dispatching_Domain rep item applies: use given value
14167 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14170 Make_Selected_Component
(Loc
,
14172 Make_Identifier
(Loc
, Name_uInit
),
14174 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14176 -- No pragma or aspect Dispatching_Domain applies to the task
14179 Append_To
(Args
, Make_Null
(Loc
));
14182 -- Number of entries. This is an expression of the form:
14184 -- n + _Init.a'Length + _Init.a'B'Length + ...
14186 -- where a,b... are the entry family names for the task definition
14189 Build_Entry_Count_Expression
14194 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14196 Append_To
(Args
, Ecount
);
14198 -- Master parameter. This is a reference to the _Master parameter of
14199 -- the initialization procedure, except in the case of the pragma
14200 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14201 -- System.Tasking.Library_Task_Level.
14203 if Restriction_Active
(No_Task_Hierarchy
) = False then
14204 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14207 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14211 -- State parameter. This is a pointer to the task body procedure. The
14212 -- required value is obtained by taking 'Unrestricted_Access of the task
14213 -- body procedure and converting it (with an unchecked conversion) to
14214 -- the type required by the task kernel. For further details, see the
14215 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14216 -- than 'Address in order to avoid creating trampolines.
14219 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14220 Subp_Ptr_Typ
: constant Node_Id
:=
14221 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14222 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14225 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14226 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14228 -- Be sure to freeze a reference to the access-to-subprogram type,
14229 -- otherwise gigi will complain that it's in the wrong scope, because
14230 -- it's actually inside the init procedure for the record type that
14231 -- corresponds to the task type.
14233 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14234 Append_Freeze_Action
(Task_Rec
, Ref
);
14237 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14238 Make_Qualified_Expression
(Loc
,
14239 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14241 Make_Attribute_Reference
(Loc
,
14242 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14243 Attribute_Name
=> Name_Unrestricted_Access
))));
14246 -- Discriminants parameter. This is just the address of the task
14247 -- value record itself (which contains the discriminant values
14250 Make_Attribute_Reference
(Loc
,
14251 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14252 Attribute_Name
=> Name_Address
));
14254 -- Elaborated parameter. This is an access to the elaboration Boolean
14257 Make_Attribute_Reference
(Loc
,
14258 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14259 Attribute_Name
=> Name_Unchecked_Access
));
14261 -- Add Chain parameter (not done for sequential elaboration policy, see
14262 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14264 if Partition_Elaboration_Policy
/= 'S' then
14265 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14268 -- Task name parameter. Take this from the _Task_Id parameter to the
14269 -- init call unless there is a Task_Name pragma, in which case we take
14270 -- the value from the pragma.
14272 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14273 -- Copy expression in full, because it may be dynamic and have
14280 (Pragma_Argument_Associations
14282 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14285 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14288 -- Created_Task parameter. This is the _Task_Id field of the task
14292 Make_Selected_Component
(Loc
,
14293 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14294 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14300 if Restricted_Profile
then
14301 if Partition_Elaboration_Policy
= 'S' then
14302 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14304 Create_RE
:= RE_Create_Restricted_Task
;
14307 Create_RE
:= RE_Create_Task
;
14310 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14314 Make_Procedure_Call_Statement
(Loc
,
14316 Parameter_Associations
=> Args
);
14317 end Make_Task_Create_Call
;
14319 ------------------------------
14320 -- Next_Protected_Operation --
14321 ------------------------------
14323 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14327 -- Check whether there is a subsequent body for a protected operation
14328 -- in the current protected body. In Ada2012 that includes expression
14329 -- functions that are completions.
14331 Next_Op
:= Next
(N
);
14332 while Present
(Next_Op
)
14333 and then not Nkind_In
(Next_Op
,
14334 N_Subprogram_Body
, N_Entry_Body
, N_Expression_Function
)
14340 end Next_Protected_Operation
;
14342 ---------------------
14343 -- Null_Statements --
14344 ---------------------
14346 function Null_Statements
(Stats
: List_Id
) return Boolean is
14350 Stmt
:= First
(Stats
);
14351 while Nkind
(Stmt
) /= N_Empty
14352 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14354 (Nkind
(Stmt
) = N_Pragma
14356 Nam_In
(Pragma_Name_Unmapped
(Stmt
),
14364 return Nkind
(Stmt
) = N_Empty
;
14365 end Null_Statements
;
14367 --------------------------
14368 -- Parameter_Block_Pack --
14369 --------------------------
14371 function Parameter_Block_Pack
14373 Blk_Typ
: Entity_Id
;
14377 Stmts
: List_Id
) return Node_Id
14379 Actual
: Entity_Id
;
14380 Expr
: Node_Id
:= Empty
;
14381 Formal
: Entity_Id
;
14382 Has_Param
: Boolean := False;
14385 Temp_Asn
: Node_Id
;
14386 Temp_Nam
: Node_Id
;
14389 Actual
:= First
(Actuals
);
14390 Formal
:= Defining_Identifier
(First
(Formals
));
14391 Params
:= New_List
;
14392 while Present
(Actual
) loop
14393 if Is_By_Copy_Type
(Etype
(Actual
)) then
14395 -- Jnn : aliased <formal-type>
14397 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14400 Make_Object_Declaration
(Loc
,
14401 Aliased_Present
=> True,
14402 Defining_Identifier
=> Temp_Nam
,
14403 Object_Definition
=>
14404 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14406 if Ekind
(Formal
) /= E_Out_Parameter
then
14412 New_Occurrence_Of
(Temp_Nam
, Loc
);
14414 Set_Assignment_OK
(Temp_Asn
);
14417 Make_Assignment_Statement
(Loc
,
14419 Expression
=> New_Copy_Tree
(Actual
)));
14423 -- Jnn'unchecked_access
14426 Make_Attribute_Reference
(Loc
,
14427 Attribute_Name
=> Name_Unchecked_Access
,
14428 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14432 -- The controlling parameter is omitted
14435 if not Is_Controlling_Actual
(Actual
) then
14437 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14443 Next_Actual
(Actual
);
14444 Next_Formal_With_Extras
(Formal
);
14448 Expr
:= Make_Aggregate
(Loc
, Params
);
14453 -- J1'unchecked_access;
14454 -- <actual2>'reference;
14457 P
:= Make_Temporary
(Loc
, 'P');
14460 Make_Object_Declaration
(Loc
,
14461 Defining_Identifier
=> P
,
14462 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14463 Expression
=> Expr
));
14466 end Parameter_Block_Pack
;
14468 ----------------------------
14469 -- Parameter_Block_Unpack --
14470 ----------------------------
14472 function Parameter_Block_Unpack
14476 Formals
: List_Id
) return List_Id
14478 Actual
: Entity_Id
;
14480 Formal
: Entity_Id
;
14481 Has_Asnmt
: Boolean := False;
14482 Result
: constant List_Id
:= New_List
;
14485 Actual
:= First
(Actuals
);
14486 Formal
:= Defining_Identifier
(First
(Formals
));
14487 while Present
(Actual
) loop
14488 if Is_By_Copy_Type
(Etype
(Actual
))
14489 and then Ekind
(Formal
) /= E_In_Parameter
14492 -- <actual> := P.<formal>;
14495 Make_Assignment_Statement
(Loc
,
14499 Make_Explicit_Dereference
(Loc
,
14500 Make_Selected_Component
(Loc
,
14502 New_Occurrence_Of
(P
, Loc
),
14504 Make_Identifier
(Loc
, Chars
(Formal
)))));
14506 Set_Assignment_OK
(Name
(Asnmt
));
14507 Append_To
(Result
, Asnmt
);
14512 Next_Actual
(Actual
);
14513 Next_Formal_With_Extras
(Formal
);
14519 return New_List
(Make_Null_Statement
(Loc
));
14521 end Parameter_Block_Unpack
;
14523 ----------------------
14524 -- Set_Discriminals --
14525 ----------------------
14527 procedure Set_Discriminals
(Dec
: Node_Id
) is
14530 D_Minal
: Entity_Id
;
14533 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14534 Pdef
:= Defining_Identifier
(Dec
);
14536 if Has_Discriminants
(Pdef
) then
14537 D
:= First_Discriminant
(Pdef
);
14538 while Present
(D
) loop
14540 Make_Defining_Identifier
(Sloc
(D
),
14541 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14543 Set_Ekind
(D_Minal
, E_Constant
);
14544 Set_Etype
(D_Minal
, Etype
(D
));
14545 Set_Scope
(D_Minal
, Pdef
);
14546 Set_Discriminal
(D
, D_Minal
);
14547 Set_Discriminal_Link
(D_Minal
, D
);
14549 Next_Discriminant
(D
);
14552 end Set_Discriminals
;
14554 -----------------------
14555 -- Trivial_Accept_OK --
14556 -----------------------
14558 function Trivial_Accept_OK
return Boolean is
14560 case Opt
.Task_Dispatching_Policy
is
14562 -- If we have the default task dispatching policy in effect, we can
14563 -- definitely do the optimization (one way of looking at this is to
14564 -- think of the formal definition of the default policy being allowed
14565 -- to run any task it likes after a rendezvous, so even if notionally
14566 -- a full rescheduling occurs, we can say that our dispatching policy
14567 -- (i.e. the default dispatching policy) reorders the queue to be the
14568 -- same as just before the call.
14573 -- FIFO_Within_Priorities certainly does not permit this
14574 -- optimization since the Rendezvous is a scheduling action that may
14575 -- require some other task to be run.
14580 -- For now, disallow the optimization for all other policies. This
14581 -- may be over-conservative, but it is certainly not incorrect.
14586 end Trivial_Accept_OK
;