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_Eval
; use Sem_Eval
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Util
; use Sem_Util
;
58 with Sinfo
; use Sinfo
;
59 with Snames
; use Snames
;
60 with Stand
; use Stand
;
61 with Targparm
; use Targparm
;
62 with Tbuild
; use Tbuild
;
63 with Uintp
; use Uintp
;
64 with Validsw
; use Validsw
;
66 package body Exp_Ch9
is
68 -- The following constant establishes the upper bound for the index of
69 -- an entry family. It is used to limit the allocated size of protected
70 -- types with defaulted discriminant of an integer type, when the bound
71 -- of some entry family depends on a discriminant. The limitation to entry
72 -- families of 128K should be reasonable in all cases, and is a documented
73 -- implementation restriction.
75 Entry_Family_Bound
: constant Pos
:= 2**16;
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 function Actual_Index_Expression
85 Tsk
: Entity_Id
) return Node_Id
;
86 -- Compute the index position for an entry call. Tsk is the target task. If
87 -- the bounds of some entry family depend on discriminants, the expression
88 -- computed by this function uses the discriminants of the target task.
90 procedure Add_Object_Pointer
94 -- Prepend an object pointer declaration to the declaration list Decls.
95 -- This object pointer is initialized to a type conversion of the System.
96 -- Address pointer passed to entry barrier functions and entry body
99 procedure Add_Formal_Renamings
104 -- Create renaming declarations for the formals, inside the procedure that
105 -- implements an entry body. The renamings make the original names of the
106 -- formals accessible to gdb, and serve no other purpose.
107 -- Spec is the specification of the procedure being built.
108 -- Decls is the list of declarations to be enhanced.
109 -- Ent is the entity for the original entry body.
111 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
112 -- Transform accept statement into a block with added exception handler.
113 -- Used both for simple accept statements and for accept alternatives in
114 -- select statements. Astat is the accept statement.
116 function Build_Barrier_Function
119 Pid
: Node_Id
) return Node_Id
;
120 -- Build the function body returning the value of the barrier expression
121 -- for the specified entry body.
123 function Build_Barrier_Function_Specification
125 Def_Id
: Entity_Id
) return Node_Id
;
126 -- Build a specification for a function implementing the protected entry
127 -- barrier of the specified entry body.
129 procedure Build_Contract_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
130 -- Build the body of a wrapper procedure for an entry or entry family that
131 -- has contract cases, preconditions, or postconditions. The body gathers
132 -- the executable contract items and expands them in the usual way, and
133 -- performs the entry call itself. This way preconditions are evaluated
134 -- before the call is queued. E is the entry in question, and Decl is the
135 -- enclosing synchronized type declaration at whose freeze point the
136 -- generated body is analyzed.
138 function Build_Corresponding_Record
141 Loc
: Source_Ptr
) return Node_Id
;
142 -- Common to tasks and protected types. Copy discriminant specifications,
143 -- build record declaration. N is the type declaration, Ctyp is the
144 -- concurrent entity (task type or protected type).
146 function Build_Dispatching_Tag_Check
148 N
: Node_Id
) return Node_Id
;
149 -- Utility to create the tree to check whether the dispatching call in
150 -- a timed entry call, a conditional entry call, or an asynchronous
151 -- transfer of control is a call to a primitive of a non-synchronized type.
152 -- K is the temporary that holds the tagged kind of the target object, and
153 -- N is the enclosing construct.
155 function Build_Entry_Count_Expression
156 (Concurrent_Type
: Node_Id
;
157 Component_List
: List_Id
;
158 Loc
: Source_Ptr
) return Node_Id
;
159 -- Compute number of entries for concurrent object. This is a count of
160 -- simple entries, followed by an expression that computes the length
161 -- of the range of each entry family. A single array with that size is
162 -- allocated for each concurrent object of the type.
164 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
165 -- Build the function that translates the entry index in the call
166 -- (which depends on the size of entry families) into an index into the
167 -- Entry_Bodies_Array, to determine the body and barrier function used
168 -- in a protected entry call. A pointer to this function appears in every
171 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
172 -- Build subprogram declaration for previous one
174 function Build_Lock_Free_Protected_Subprogram_Body
177 Unprot_Spec
: Node_Id
) return Node_Id
;
178 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
179 -- the subprogram specification of the unprotected version of N. Transform
180 -- N such that it invokes the unprotected version of the body.
182 function Build_Lock_Free_Unprotected_Subprogram_Body
184 Prot_Typ
: Node_Id
) return Node_Id
;
185 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
186 -- of N where the original statements of N are synchronized through atomic
187 -- actions such as compare and exchange. Prior to invoking this routine, it
188 -- has been established that N can be implemented in a lock-free fashion.
190 function Build_Parameter_Block
194 Decls
: List_Id
) return Entity_Id
;
195 -- Generate an access type for each actual parameter in the list Actuals.
196 -- Create an encapsulating record that contains all the actuals and return
197 -- its type. Generate:
198 -- type Ann1 is access all <actual1-type>
200 -- type AnnN is access all <actualN-type>
201 -- type Pnn is record
207 function Build_Protected_Entry
210 Pid
: Node_Id
) return Node_Id
;
211 -- Build the procedure implementing the statement sequence of the specified
214 function Build_Protected_Entry_Specification
217 Ent_Id
: Entity_Id
) return Node_Id
;
218 -- Build a specification for the procedure implementing the statements of
219 -- the specified entry body. Add attributes associating it with the entry
220 -- defining identifier Ent_Id.
222 function Build_Protected_Spec
224 Obj_Type
: Entity_Id
;
226 Unprotected
: Boolean := False) return List_Id
;
227 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
228 -- Subprogram_Type. Builds signature of protected subprogram, adding the
229 -- formal that corresponds to the object itself. For an access to protected
230 -- subprogram, there is no object type to specify, so the parameter has
231 -- type Address and mode In. An indirect call through such a pointer will
232 -- convert the address to a reference to the actual object. The object is
233 -- a limited record and therefore a by_reference type.
235 function Build_Protected_Subprogram_Body
238 N_Op_Spec
: Node_Id
) return Node_Id
;
239 -- This function is used to construct the protected version of a protected
240 -- subprogram. Its statement sequence first defers abort, then locks the
241 -- associated protected object, and then enters a block that contains a
242 -- call to the unprotected version of the subprogram (for details, see
243 -- Build_Unprotected_Subprogram_Body). This block statement requires a
244 -- cleanup handler that unlocks the object in all cases. For details,
245 -- see Exp_Ch7.Expand_Cleanup_Actions.
247 function Build_Renamed_Formal_Declaration
251 Renamed_Formal
: Node_Id
) return Node_Id
;
252 -- Create a renaming declaration for a formal, within a protected entry
253 -- body or an accept body. The renamed object is a component of the
254 -- parameter block that is a parameter in the entry call.
256 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
257 -- does not dereference the corresponding component to prevent an illegal
258 -- use of the incomplete type (AI05-0151).
260 function Build_Selected_Name
262 Selector
: Entity_Id
;
263 Append_Char
: Character := ' ') return Name_Id
;
264 -- Build a name in the form of Prefix__Selector, with an optional character
265 -- appended. This is used for internal subprograms generated for operations
266 -- of protected types, including barrier functions. For the subprograms
267 -- generated for entry bodies and entry barriers, the generated name
268 -- includes a sequence number that makes names unique in the presence of
269 -- entry overloading. This is necessary because entry body procedures and
270 -- barrier functions all have the same signature.
272 procedure Build_Simple_Entry_Call
277 -- Some comments here would be useful ???
279 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
280 -- This routine constructs a specification for the procedure that we will
281 -- build for the task body for task type T. The spec has the form:
283 -- procedure tnameB (_Task : access tnameV);
285 -- where name is the character name taken from the task type entity that
286 -- is passed as the argument to the procedure, and tnameV is the task
287 -- value type that is associated with the task type.
289 function Build_Unprotected_Subprogram_Body
291 Pid
: Node_Id
) return Node_Id
;
292 -- This routine constructs the unprotected version of a protected
293 -- subprogram body, which is contains all of the code in the original,
294 -- unexpanded body. This is the version of the protected subprogram that is
295 -- called from all protected operations on the same object, including the
296 -- protected version of the same subprogram.
298 procedure Build_Wrapper_Bodies
302 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
303 -- record of a concurrent type. N is the insertion node where all bodies
304 -- will be placed. This routine builds the bodies of the subprograms which
305 -- serve as an indirection mechanism to overriding primitives of concurrent
306 -- types, entries and protected procedures. Any new body is analyzed.
308 procedure Build_Wrapper_Specs
312 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
313 -- record of a concurrent type. N is the insertion node where all specs
314 -- will be placed. This routine builds the specs of the subprograms which
315 -- serve as an indirection mechanism to overriding primitives of concurrent
316 -- types, entries and protected procedures. Any new spec is analyzed.
318 procedure Collect_Entry_Families
321 Current_Node
: in out Node_Id
;
322 Conctyp
: Entity_Id
);
323 -- For each entry family in a concurrent type, create an anonymous array
324 -- type of the right size, and add a component to the corresponding_record.
326 function Concurrent_Object
327 (Spec_Id
: Entity_Id
;
328 Conc_Typ
: Entity_Id
) return Entity_Id
;
329 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
330 -- the entity associated with the concurrent object in the Protected_Body_
331 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
332 -- denotes formal parameter _O, _object or _task.
334 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
335 -- Copy the result type of a function specification, when building the
336 -- internal operation corresponding to a protected function, or when
337 -- expanding an access to protected function. If the result is an anonymous
338 -- access to subprogram itself, we need to create a new signature with the
339 -- same parameter names and the same resolved types, but with new entities
342 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean;
343 -- Return whether a secondary stack for the task T should be created by the
344 -- expander. The secondary stack for a task will be created by the expander
345 -- if the size of the stack has been specified by the Secondary_Stack_Size
346 -- representation aspect and either the No_Implicit_Heap_Allocations or
347 -- No_Implicit_Task_Allocations restrictions are in effect and the
348 -- No_Secondary_Stack restriction is not.
350 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
351 -- Decls is a list which may contain the declarations created by Install_
352 -- Private_Data_Declarations. All generated entities are marked as needing
353 -- debug info and debug nodes are manually generation where necessary. This
354 -- step of the expansion must to be done after private data has been moved
355 -- to its final resting scope to ensure proper visibility of debug objects.
357 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
358 -- If control flow optimizations are suppressed, and Alt is an accept,
359 -- delay, or entry call alternative with no trailing statements, insert
360 -- a null trailing statement with the given Loc (which is the sloc of
361 -- the accept, delay, or entry call statement). There might not be any
362 -- generated code for the accept, delay, or entry call itself (the effect
363 -- of these statements is part of the general processsing done for the
364 -- enclosing selective accept, timed entry call, or asynchronous select),
365 -- and the null statement is there to carry the sloc of that statement to
366 -- the back-end for trace-based coverage analysis purposes.
368 procedure Extract_Dispatching_Call
370 Call_Ent
: out Entity_Id
;
371 Object
: out Entity_Id
;
372 Actuals
: out List_Id
;
373 Formals
: out List_Id
);
374 -- Given a dispatching call, extract the entity of the name of the call,
375 -- its actual dispatching object, its actual parameters and the formal
376 -- parameters of the overridden interface-level version. If the type of
377 -- the dispatching object is an access type then an explicit dereference
378 -- is returned in Object.
380 procedure Extract_Entry
382 Concval
: out Node_Id
;
384 Index
: out Node_Id
);
385 -- Given an entry call, returns the associated concurrent object, the entry
386 -- name, and the entry family index.
388 function Family_Offset
393 Cap
: Boolean) return Node_Id
;
394 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
395 -- accept statement, or the upper bound in the discrete subtype of an entry
396 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
397 -- type of the entry. If Cap is true, the result is capped according to
398 -- Entry_Family_Bound.
405 Cap
: Boolean) return Node_Id
;
406 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
407 -- family, and handle properly the superflat case. This is equivalent to
408 -- the use of 'Length on the index type, but must use Family_Offset to
409 -- handle properly the case of bounds that depend on discriminants. If
410 -- Cap is true, the result is capped according to Entry_Family_Bound.
412 procedure Find_Enclosing_Context
414 Context
: out Node_Id
;
415 Context_Id
: out Entity_Id
;
416 Context_Decls
: out List_Id
);
417 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
418 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
419 -- nearest enclosing body, block, package, or return statement and return
420 -- its constituents. Context is the enclosing construct, Context_Id is
421 -- the scope of Context_Id and Context_Decls is the declarative list of
424 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
425 -- Given a subprogram identifier, return the entity which is associated
426 -- with the protection entry index in the Protected_Body_Subprogram or
427 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
430 function Is_Potentially_Large_Family
431 (Base_Index
: Entity_Id
;
434 Hi
: Node_Id
) return Boolean;
436 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
437 -- Determine whether Id is a function or a procedure and is marked as a
438 -- private primitive.
440 function Null_Statements
(Stats
: List_Id
) return Boolean;
441 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
442 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
443 -- to still count as null. Returns True for a null sequence. The argument
444 -- is the list of statements from the DO-END sequence.
446 function Parameter_Block_Pack
452 Stmts
: List_Id
) return Entity_Id
;
453 -- Set the components of the generated parameter block with the values
454 -- of the actual parameters. Generate aliased temporaries to capture the
455 -- values for types that are passed by copy. Otherwise generate a reference
456 -- to the actual's value. Return the address of the aggregate block.
458 -- Jnn1 : alias <formal-type1>;
459 -- Jnn1 := <actual1>;
462 -- Jnn1'unchecked_access;
463 -- <actual2>'reference;
466 function Parameter_Block_Unpack
470 Formals
: List_Id
) return List_Id
;
471 -- Retrieve the values of the components from the parameter block and
472 -- assign then to the original actual parameters. Generate:
473 -- <actual1> := P.<formal1>;
475 -- <actualN> := P.<formalN>;
477 function Trivial_Accept_OK
return Boolean;
478 -- If there is no DO-END block for an accept, or if the DO-END block has
479 -- only null statements, then it is possible to do the Rendezvous with much
480 -- less overhead using the Accept_Trivial routine in the run-time library.
481 -- However, this is not always a valid optimization. Whether it is valid or
482 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
483 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
484 -- a rescheduling is required, so this optimization is not allowed. This
485 -- function returns True if the optimization is permitted.
487 -----------------------------
488 -- Actual_Index_Expression --
489 -----------------------------
491 function Actual_Index_Expression
495 Tsk
: Entity_Id
) return Node_Id
497 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
505 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
506 -- Compute difference between bounds of entry family
508 --------------------------
509 -- Actual_Family_Offset --
510 --------------------------
512 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
514 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
515 -- Replace a reference to a discriminant with a selected component
516 -- denoting the discriminant of the target task.
518 -----------------------------
519 -- Actual_Discriminant_Ref --
520 -----------------------------
522 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
523 Typ
: constant Entity_Id
:= Etype
(Bound
);
527 if not Is_Entity_Name
(Bound
)
528 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
530 if Nkind
(Bound
) = N_Attribute_Reference
then
533 B
:= New_Copy_Tree
(Bound
);
538 Make_Selected_Component
(Sloc
,
539 Prefix
=> New_Copy_Tree
(Tsk
),
540 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
542 Analyze_And_Resolve
(B
, Typ
);
546 Make_Attribute_Reference
(Sloc
,
547 Attribute_Name
=> Name_Pos
,
548 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
549 Expressions
=> New_List
(B
));
550 end Actual_Discriminant_Ref
;
552 -- Start of processing for Actual_Family_Offset
556 Make_Op_Subtract
(Sloc
,
557 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
558 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
559 end Actual_Family_Offset
;
561 -- Start of processing for Actual_Index_Expression
564 -- The queues of entries and entry families appear in textual order in
565 -- the associated record. The entry index is computed as the sum of the
566 -- number of queues for all entries that precede the designated one, to
567 -- which is added the index expression, if this expression denotes a
568 -- member of a family.
570 -- The following is a place holder for the count of simple entries
572 Num
:= Make_Integer_Literal
(Sloc
, 1);
574 -- We construct an expression which is a series of addition operations.
575 -- See comments in Entry_Index_Expression, which is identical in
578 if Present
(Index
) then
579 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
585 Actual_Family_Offset
(
586 Make_Attribute_Reference
(Sloc
,
587 Attribute_Name
=> Name_Pos
,
588 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
589 Expressions
=> New_List
(Relocate_Node
(Index
))),
590 Type_Low_Bound
(S
)));
595 -- Now add lengths of preceding entries and entry families
597 Prev
:= First_Entity
(Ttyp
);
598 while Chars
(Prev
) /= Chars
(Ent
)
599 or else (Ekind
(Prev
) /= Ekind
(Ent
))
600 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
602 if Ekind
(Prev
) = E_Entry
then
603 Set_Intval
(Num
, Intval
(Num
) + 1);
605 elsif Ekind
(Prev
) = E_Entry_Family
then
607 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
609 -- The need for the following full view retrieval stems from this
610 -- complex case of nested generics and tasking:
613 -- type Formal_Index is range <>;
616 -- type Index is private;
623 -- type Index is new Formal_Index range 1 .. 10;
626 -- package body Outer is
628 -- entry Fam (Index); -- (2)
631 -- package body Inner is -- (3)
639 -- We are currently building the index expression for the entry
640 -- call "T.E" (1). Part of the expansion must mention the range
641 -- of the discrete type "Index" (2) of entry family "Fam".
643 -- However only the private view of type "Index" is available to
644 -- the inner generic (3) because there was no prior mention of
645 -- the type inside "Inner". This visibility requirement is
646 -- implicit and cannot be detected during the construction of
647 -- the generic trees and needs special handling.
650 and then Is_Private_Type
(S
)
651 and then Present
(Full_View
(S
))
656 Lo
:= Type_Low_Bound
(S
);
657 Hi
:= Type_High_Bound
(S
);
664 Left_Opnd
=> Actual_Family_Offset
(Hi
, Lo
),
665 Right_Opnd
=> Make_Integer_Literal
(Sloc
, 1)));
667 -- Other components are anonymous types to be ignored
677 end Actual_Index_Expression
;
679 --------------------------
680 -- Add_Formal_Renamings --
681 --------------------------
683 procedure Add_Formal_Renamings
689 Ptr
: constant Entity_Id
:=
691 (Next
(First
(Parameter_Specifications
(Spec
))));
692 -- The name of the formal that holds the address of the parameter block
699 Renamed_Formal
: Node_Id
;
702 Formal
:= First_Formal
(Ent
);
703 while Present
(Formal
) loop
704 Comp
:= Entry_Component
(Formal
);
706 Make_Defining_Identifier
(Sloc
(Formal
),
707 Chars
=> Chars
(Formal
));
708 Set_Etype
(New_F
, Etype
(Formal
));
709 Set_Scope
(New_F
, Ent
);
711 -- Now we set debug info needed on New_F even though it does not come
712 -- from source, so that the debugger will get the right information
713 -- for these generated names.
715 Set_Debug_Info_Needed
(New_F
);
717 if Ekind
(Formal
) = E_In_Parameter
then
718 Set_Ekind
(New_F
, E_Constant
);
720 Set_Ekind
(New_F
, E_Variable
);
721 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
724 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
727 Make_Selected_Component
(Loc
,
729 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
730 Make_Identifier
(Loc
, Chars
(Ptr
))),
731 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
734 Build_Renamed_Formal_Declaration
735 (New_F
, Formal
, Comp
, Renamed_Formal
);
737 Append
(Decl
, Decls
);
738 Set_Renamed_Object
(Formal
, New_F
);
739 Next_Formal
(Formal
);
741 end Add_Formal_Renamings
;
743 ------------------------
744 -- Add_Object_Pointer --
745 ------------------------
747 procedure Add_Object_Pointer
749 Conc_Typ
: Entity_Id
;
752 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
757 -- Create the renaming declaration for the Protection object of a
758 -- protected type. _Object is used by Complete_Entry_Body.
759 -- ??? An attempt to make this a renaming was unsuccessful.
761 -- Build the entity for the access type
764 Make_Defining_Identifier
(Loc
,
765 New_External_Name
(Chars
(Rec_Typ
), 'P'));
768 -- _object : poVP := poVP!O;
771 Make_Object_Declaration
(Loc
,
772 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uObject
),
773 Object_Definition
=> New_Occurrence_Of
(Obj_Ptr
, Loc
),
775 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
776 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
777 Prepend_To
(Decls
, Decl
);
780 -- type poVP is access poV;
783 Make_Full_Type_Declaration
(Loc
,
784 Defining_Identifier
=>
787 Make_Access_To_Object_Definition
(Loc
,
788 Subtype_Indication
=>
789 New_Occurrence_Of
(Rec_Typ
, Loc
)));
790 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
791 Prepend_To
(Decls
, Decl
);
792 end Add_Object_Pointer
;
794 -----------------------
795 -- Build_Accept_Body --
796 -----------------------
798 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
799 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
800 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
807 -- At the end of the statement sequence, Complete_Rendezvous is called.
808 -- A label skipping the Complete_Rendezvous, and all other accept
809 -- processing, has already been added for the expansion of requeue
810 -- statements. The Sloc is copied from the last statement since it
811 -- is really part of this last statement.
815 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
816 Insert_Before
(Last
(Statements
(Stats
)), Call
);
819 -- If exception handlers are present, then append Complete_Rendezvous
820 -- calls to the handlers, and construct the required outer block. As
821 -- above, the Sloc is copied from the last statement in the sequence.
823 if Present
(Exception_Handlers
(Stats
)) then
824 Hand
:= First
(Exception_Handlers
(Stats
));
825 while Present
(Hand
) loop
828 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
829 Append
(Call
, Statements
(Hand
));
835 Make_Handled_Sequence_Of_Statements
(Loc
,
836 Statements
=> New_List
(
837 Make_Block_Statement
(Loc
,
838 Handled_Statement_Sequence
=> Stats
)));
844 -- At this stage we know that the new statement sequence does
845 -- not have an exception handler part, so we supply one to call
846 -- Exceptional_Complete_Rendezvous. This handler is
848 -- when all others =>
849 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
851 -- We handle Abort_Signal to make sure that we properly catch the abort
852 -- case and wake up the caller.
854 Ohandle
:= Make_Others_Choice
(Loc
);
855 Set_All_Others
(Ohandle
);
857 Set_Exception_Handlers
(New_S
,
859 Make_Implicit_Exception_Handler
(Loc
,
860 Exception_Choices
=> New_List
(Ohandle
),
862 Statements
=> New_List
(
863 Make_Procedure_Call_Statement
(Sloc
(Stats
),
864 Name
=> New_Occurrence_Of
(
865 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
866 Parameter_Associations
=> New_List
(
867 Make_Function_Call
(Sloc
(Stats
),
870 (RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
872 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
873 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
874 Expand_Exception_Handlers
(New_S
);
876 -- Exceptional_Complete_Rendezvous must be called with abort still
877 -- deferred, which is the case for a "when all others" handler.
880 end Build_Accept_Body
;
882 -----------------------------------
883 -- Build_Activation_Chain_Entity --
884 -----------------------------------
886 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
887 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
888 -- Determine whether an extended return statement has activation chain
890 --------------------------
891 -- Has_Activation_Chain --
892 --------------------------
894 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
898 Decl
:= First
(Return_Object_Declarations
(Stmt
));
899 while Present
(Decl
) loop
900 if Nkind
(Decl
) = N_Object_Declaration
901 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
910 end Has_Activation_Chain
;
915 Context_Id
: Entity_Id
;
918 -- Start of processing for Build_Activation_Chain_Entity
921 -- Activation chain is never used for sequential elaboration policy, see
922 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
924 if Partition_Elaboration_Policy
= 'S' then
928 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
930 -- If activation chain entity has not been declared already, create one
932 if Nkind
(Context
) = N_Extended_Return_Statement
933 or else No
(Activation_Chain_Entity
(Context
))
935 -- Since extended return statements do not store the entity of the
936 -- chain, examine the return object declarations to avoid creating
939 if Nkind
(Context
) = N_Extended_Return_Statement
940 and then Has_Activation_Chain
(Context
)
946 Loc
: constant Source_Ptr
:= Sloc
(Context
);
951 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
953 -- Note: An extended return statement is not really a task
954 -- activator, but it does have an activation chain on which to
955 -- store the tasks temporarily. On successful return, the tasks
956 -- on this chain are moved to the chain passed in by the caller.
957 -- We do not build an Activation_Chain_Entity for an extended
958 -- return statement, because we do not want to build a call to
959 -- Activate_Tasks. Task activation is the responsibility of the
962 if Nkind
(Context
) /= N_Extended_Return_Statement
then
963 Set_Activation_Chain_Entity
(Context
, Chain
);
967 Make_Object_Declaration
(Loc
,
968 Defining_Identifier
=> Chain
,
969 Aliased_Present
=> True,
971 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
));
973 Prepend_To
(Decls
, Decl
);
975 -- Ensure that _chain appears in the proper scope of the context
977 if Context_Id
/= Current_Scope
then
978 Push_Scope
(Context_Id
);
986 end Build_Activation_Chain_Entity
;
988 ----------------------------
989 -- Build_Barrier_Function --
990 ----------------------------
992 function Build_Barrier_Function
995 Pid
: Node_Id
) return Node_Id
997 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
998 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
999 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
1000 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
1001 Op_Decls
: constant List_Id
:= New_List
;
1003 Func_Body
: Node_Id
;
1006 -- Add a declaration for the Protection object, renaming declarations
1007 -- for the discriminals and privals and finally a declaration for the
1008 -- entry family index (if applicable).
1010 Install_Private_Data_Declarations
(Sloc
(N
),
1016 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1018 -- If compiling with -fpreserve-control-flow, make sure we insert an
1019 -- IF statement so that the back-end knows to generate a conditional
1020 -- branch instruction, even if the condition is just the name of a
1021 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1022 -- such redundant IF statements under -fpreserve-control-flow
1023 -- (whether coming from this routine, or directly from source).
1025 if Opt
.Suppress_Control_Flow_Optimizations
then
1027 Make_Implicit_If_Statement
(Cond
,
1029 Then_Statements
=> New_List
(
1030 Make_Simple_Return_Statement
(Loc
,
1031 New_Occurrence_Of
(Standard_True
, Loc
))),
1033 Else_Statements
=> New_List
(
1034 Make_Simple_Return_Statement
(Loc
,
1035 New_Occurrence_Of
(Standard_False
, Loc
))));
1038 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1041 -- Note: the condition in the barrier function needs to be properly
1042 -- processed for the C/Fortran boolean possibility, but this happens
1043 -- automatically since the return statement does this normalization.
1046 Make_Subprogram_Body
(Loc
,
1048 Build_Barrier_Function_Specification
(Loc
,
1049 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1050 Declarations
=> Op_Decls
,
1051 Handled_Statement_Sequence
=>
1052 Make_Handled_Sequence_Of_Statements
(Loc
,
1053 Statements
=> New_List
(Stmt
)));
1054 Set_Is_Entry_Barrier_Function
(Func_Body
);
1057 end Build_Barrier_Function
;
1059 ------------------------------------------
1060 -- Build_Barrier_Function_Specification --
1061 ------------------------------------------
1063 function Build_Barrier_Function_Specification
1065 Def_Id
: Entity_Id
) return Node_Id
1068 Set_Debug_Info_Needed
(Def_Id
);
1071 Make_Function_Specification
(Loc
,
1072 Defining_Unit_Name
=> Def_Id
,
1073 Parameter_Specifications
=> New_List
(
1074 Make_Parameter_Specification
(Loc
,
1075 Defining_Identifier
=>
1076 Make_Defining_Identifier
(Loc
, Name_uO
),
1078 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
1080 Make_Parameter_Specification
(Loc
,
1081 Defining_Identifier
=>
1082 Make_Defining_Identifier
(Loc
, Name_uE
),
1084 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1086 Result_Definition
=>
1087 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1088 end Build_Barrier_Function_Specification
;
1090 --------------------------
1091 -- Build_Call_With_Task --
1092 --------------------------
1094 function Build_Call_With_Task
1096 E
: Entity_Id
) return Node_Id
1098 Loc
: constant Source_Ptr
:= Sloc
(N
);
1101 Make_Function_Call
(Loc
,
1102 Name
=> New_Occurrence_Of
(E
, Loc
),
1103 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1104 end Build_Call_With_Task
;
1106 -----------------------------
1107 -- Build_Class_Wide_Master --
1108 -----------------------------
1110 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1111 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1112 Master_Decl
: Node_Id
;
1113 Master_Id
: Entity_Id
;
1114 Master_Scope
: Entity_Id
;
1116 Related_Node
: Node_Id
;
1120 -- Nothing to do if there is no task hierarchy
1122 if Restriction_Active
(No_Task_Hierarchy
) then
1126 -- Find the declaration that created the access type, which is either a
1127 -- type declaration, or an object declaration with an access definition,
1128 -- in which case the type is anonymous.
1130 if Is_Itype
(Typ
) then
1131 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1133 Related_Node
:= Parent
(Typ
);
1136 Master_Scope
:= Find_Master_Scope
(Typ
);
1138 -- Nothing to do if the master scope already contains a _master entity.
1139 -- The only exception to this is the following scenario:
1142 -- Transient_Scope_1
1145 -- Transient_Scope_2
1148 -- In this case the source scope is marked as having the master entity
1149 -- even though the actual declaration appears inside an inner scope. If
1150 -- the second transient scope requires a _master, it cannot use the one
1151 -- already declared because the entity is not visible.
1153 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1154 Master_Decl
:= Empty
;
1156 if not Has_Master_Entity
(Master_Scope
)
1157 or else No
(Current_Entity_In_Scope
(Name_Id
))
1160 Set_Has_Master_Entity
(Master_Scope
);
1163 -- _master : constant Integer := Current_Master.all;
1166 Make_Object_Declaration
(Loc
,
1167 Defining_Identifier
=>
1168 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1169 Constant_Present
=> True,
1170 Object_Definition
=>
1171 New_Occurrence_Of
(Standard_Integer
, Loc
),
1173 Make_Explicit_Dereference
(Loc
,
1174 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
1176 Insert_Action
(Find_Hook_Context
(Related_Node
), Master_Decl
);
1177 Analyze
(Master_Decl
);
1179 -- Mark the containing scope as a task master. Masters associated
1180 -- with return statements are already marked at this stage (see
1181 -- Analyze_Subprogram_Body).
1183 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1185 Par
: Node_Id
:= Related_Node
;
1188 while Nkind
(Par
) /= N_Compilation_Unit
loop
1189 Par
:= Parent
(Par
);
1191 -- If we fall off the top, we are at the outer level,
1192 -- and the environment task is our effective master,
1193 -- so nothing to mark.
1195 if Nkind_In
(Par
, N_Block_Statement
,
1199 Set_Is_Task_Master
(Par
);
1209 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(Typ
), 'M'));
1212 -- typeMnn renames _master;
1215 Make_Object_Renaming_Declaration
(Loc
,
1216 Defining_Identifier
=> Master_Id
,
1217 Subtype_Mark
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1220 -- If the master is declared locally, add the renaming declaration
1221 -- immediately after it, to prevent access-before-elaboration in the
1224 if Present
(Master_Decl
) then
1225 Insert_After
(Master_Decl
, Ren_Decl
);
1229 Insert_Action
(Related_Node
, Ren_Decl
);
1232 Set_Master_Id
(Typ
, Master_Id
);
1233 end Build_Class_Wide_Master
;
1235 ----------------------------
1236 -- Build_Contract_Wrapper --
1237 ----------------------------
1239 procedure Build_Contract_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1240 Conc_Typ
: constant Entity_Id
:= Scope
(E
);
1241 Loc
: constant Source_Ptr
:= Sloc
(E
);
1243 procedure Add_Discriminant_Renamings
1244 (Obj_Id
: Entity_Id
;
1246 -- Add renaming declarations for all discriminants of concurrent type
1247 -- Conc_Typ. Obj_Id is the entity of the wrapper formal parameter which
1248 -- represents the concurrent object.
1250 procedure Add_Matching_Formals
1252 Actuals
: in out List_Id
);
1253 -- Add formal parameters that match those of entry E to list Formals.
1254 -- The routine also adds matching actuals for the new formals to list
1257 procedure Transfer_Pragma
(Prag
: Node_Id
; To
: in out List_Id
);
1258 -- Relocate pragma Prag to list To. The routine creates a new list if
1259 -- To does not exist.
1261 --------------------------------
1262 -- Add_Discriminant_Renamings --
1263 --------------------------------
1265 procedure Add_Discriminant_Renamings
1266 (Obj_Id
: Entity_Id
;
1272 -- Inspect the discriminants of the concurrent type and generate a
1273 -- renaming for each one.
1275 if Has_Discriminants
(Conc_Typ
) then
1276 Discr
:= First_Discriminant
(Conc_Typ
);
1277 while Present
(Discr
) loop
1279 Make_Object_Renaming_Declaration
(Loc
,
1280 Defining_Identifier
=>
1281 Make_Defining_Identifier
(Loc
, Chars
(Discr
)),
1283 New_Occurrence_Of
(Etype
(Discr
), Loc
),
1285 Make_Selected_Component
(Loc
,
1286 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
1288 Make_Identifier
(Loc
, Chars
(Discr
)))));
1290 Next_Discriminant
(Discr
);
1293 end Add_Discriminant_Renamings
;
1295 --------------------------
1296 -- Add_Matching_Formals --
1297 --------------------------
1299 procedure Add_Matching_Formals
1301 Actuals
: in out List_Id
)
1304 New_Formal
: Entity_Id
;
1307 -- Inspect the formal parameters of the entry and generate a new
1308 -- matching formal with the same name for the wrapper. A reference
1309 -- to the new formal becomes an actual in the entry call.
1311 Formal
:= First_Formal
(E
);
1312 while Present
(Formal
) loop
1313 New_Formal
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
1315 Make_Parameter_Specification
(Loc
,
1316 Defining_Identifier
=> New_Formal
,
1317 In_Present
=> In_Present
(Parent
(Formal
)),
1318 Out_Present
=> Out_Present
(Parent
(Formal
)),
1320 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
1322 if No
(Actuals
) then
1323 Actuals
:= New_List
;
1326 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1327 Next_Formal
(Formal
);
1329 end Add_Matching_Formals
;
1331 ---------------------
1332 -- Transfer_Pragma --
1333 ---------------------
1335 procedure Transfer_Pragma
(Prag
: Node_Id
; To
: in out List_Id
) is
1343 New_Prag
:= Relocate_Node
(Prag
);
1345 Set_Analyzed
(New_Prag
, False);
1346 Append
(New_Prag
, To
);
1347 end Transfer_Pragma
;
1351 Items
: constant Node_Id
:= Contract
(E
);
1352 Actuals
: List_Id
:= No_List
;
1355 Decls
: List_Id
:= No_List
;
1357 Has_Pragma
: Boolean := False;
1358 Index_Id
: Entity_Id
;
1361 Wrapper_Id
: Entity_Id
;
1363 -- Start of processing for Build_Contract_Wrapper
1366 -- This routine generates a specialized wrapper for a protected or task
1367 -- entry [family] which implements precondition/postcondition semantics.
1368 -- Preconditions and case guards of contract cases are checked before
1369 -- the protected action or rendezvous takes place. Postconditions and
1370 -- consequences of contract cases are checked after the protected action
1371 -- or rendezvous takes place. The structure of the generated wrapper is
1374 -- procedure Wrapper
1375 -- (Obj_Id : Conc_Typ; -- concurrent object
1376 -- [Index : Index_Typ;] -- index of entry family
1377 -- [Formal_1 : ...; -- parameters of original entry
1380 -- [Discr_1 : ... renames Obj_Id.Discr_1; -- discriminant
1381 -- Discr_N : ... renames Obj_Id.Discr_N;] -- renamings
1383 -- <precondition checks>
1384 -- <case guard checks>
1386 -- procedure _Postconditions is
1388 -- <postcondition checks>
1389 -- <consequence checks>
1390 -- end _Postconditions;
1393 -- Entry_Call (Obj_Id, [Index,] [Formal_1, Formal_N]);
1397 -- Create the wrapper only when the entry has at least one executable
1398 -- contract item such as contract cases, precondition or postcondition.
1400 if Present
(Items
) then
1402 -- Inspect the list of pre/postconditions and transfer all available
1403 -- pragmas to the declarative list of the wrapper.
1405 Prag
:= Pre_Post_Conditions
(Items
);
1406 while Present
(Prag
) loop
1407 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
1408 Name_Postcondition
, Name_Precondition
)
1409 and then Is_Checked
(Prag
)
1412 Transfer_Pragma
(Prag
, To
=> Decls
);
1415 Prag
:= Next_Pragma
(Prag
);
1418 -- Inspect the list of test/contract cases and transfer only contract
1419 -- cases pragmas to the declarative part of the wrapper.
1421 Prag
:= Contract_Test_Cases
(Items
);
1422 while Present
(Prag
) loop
1423 if Pragma_Name
(Prag
) = Name_Contract_Cases
1424 and then Is_Checked
(Prag
)
1427 Transfer_Pragma
(Prag
, To
=> Decls
);
1430 Prag
:= Next_Pragma
(Prag
);
1434 -- The entry lacks executable contract items and a wrapper is not needed
1436 if not Has_Pragma
then
1440 -- Create the profile of the wrapper. The first formal parameter is the
1441 -- concurrent object.
1444 Make_Defining_Identifier
(Loc
,
1445 Chars
=> New_External_Name
(Chars
(Conc_Typ
), 'A'));
1447 Formals
:= New_List
(
1448 Make_Parameter_Specification
(Loc
,
1449 Defining_Identifier
=> Obj_Id
,
1450 Out_Present
=> True,
1452 Parameter_Type
=> New_Occurrence_Of
(Conc_Typ
, Loc
)));
1454 -- Construct the call to the original entry. The call will be gradually
1455 -- augmented with an optional entry index and extra parameters.
1458 Make_Selected_Component
(Loc
,
1459 Prefix
=> New_Occurrence_Of
(Obj_Id
, Loc
),
1460 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1462 -- When creating a wrapper for an entry family, the second formal is the
1465 if Ekind
(E
) = E_Entry_Family
then
1466 Index_Id
:= Make_Defining_Identifier
(Loc
, Name_I
);
1469 Make_Parameter_Specification
(Loc
,
1470 Defining_Identifier
=> Index_Id
,
1472 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
1474 -- The call to the original entry becomes an indexed component to
1475 -- accommodate the entry index.
1478 Make_Indexed_Component
(Loc
,
1480 Expressions
=> New_List
(New_Occurrence_Of
(Index_Id
, Loc
)));
1483 -- Add formal parameters to match those of the entry and build actuals
1484 -- for the entry call.
1486 Add_Matching_Formals
(Formals
, Actuals
);
1489 Make_Procedure_Call_Statement
(Loc
,
1491 Parameter_Associations
=> Actuals
);
1493 -- Add renaming declarations for the discriminants of the enclosing type
1494 -- as the various contract items may reference them.
1496 Add_Discriminant_Renamings
(Obj_Id
, Decls
);
1499 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(E
), 'E'));
1500 Set_Contract_Wrapper
(E
, Wrapper_Id
);
1501 Set_Is_Entry_Wrapper
(Wrapper_Id
);
1503 -- The wrapper body is analyzed when the enclosing type is frozen
1505 Append_Freeze_Action
(Defining_Entity
(Decl
),
1506 Make_Subprogram_Body
(Loc
,
1508 Make_Procedure_Specification
(Loc
,
1509 Defining_Unit_Name
=> Wrapper_Id
,
1510 Parameter_Specifications
=> Formals
),
1511 Declarations
=> Decls
,
1512 Handled_Statement_Sequence
=>
1513 Make_Handled_Sequence_Of_Statements
(Loc
,
1514 Statements
=> New_List
(Call
))));
1515 end Build_Contract_Wrapper
;
1517 --------------------------------
1518 -- Build_Corresponding_Record --
1519 --------------------------------
1521 function Build_Corresponding_Record
1524 Loc
: Source_Ptr
) return Node_Id
1526 Rec_Ent
: constant Entity_Id
:=
1527 Make_Defining_Identifier
1528 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1531 New_Disc
: Entity_Id
;
1535 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1536 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1537 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1538 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1539 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1540 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1543 -- Use discriminals to create list of discriminants for record, and
1544 -- create new discriminals for use in default expressions, etc. It is
1545 -- worth noting that a task discriminant gives rise to 5 entities;
1547 -- a) The original discriminant.
1548 -- b) The discriminal for use in the task.
1549 -- c) The discriminant of the corresponding record.
1550 -- d) The discriminal for the init proc of the corresponding record.
1551 -- e) The local variable that renames the discriminant in the procedure
1552 -- for the task body.
1554 -- In fact the discriminals b) are used in the renaming declarations
1555 -- for e). See details in einfo (Handling of Discriminants).
1557 if Present
(Discriminant_Specifications
(N
)) then
1559 Disc
:= First_Discriminant
(Ctyp
);
1561 while Present
(Disc
) loop
1562 New_Disc
:= CR_Discriminant
(Disc
);
1565 Make_Discriminant_Specification
(Loc
,
1566 Defining_Identifier
=> New_Disc
,
1567 Discriminant_Type
=>
1568 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1570 New_Copy
(Discriminant_Default_Value
(Disc
))));
1572 Next_Discriminant
(Disc
);
1579 -- Now we can construct the record type declaration. Note that this
1580 -- record is "limited tagged". It is "limited" to reflect the underlying
1581 -- limitedness of the task or protected object that it represents, and
1582 -- ensuring for example that it is properly passed by reference. It is
1583 -- "tagged" to give support to dispatching calls through interfaces. We
1584 -- propagate here the list of interfaces covered by the concurrent type
1585 -- (Ada 2005: AI-345).
1588 Make_Full_Type_Declaration
(Loc
,
1589 Defining_Identifier
=> Rec_Ent
,
1590 Discriminant_Specifications
=> Dlist
,
1592 Make_Record_Definition
(Loc
,
1594 Make_Component_List
(Loc
, Component_Items
=> Cdecls
),
1596 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1597 Interface_List
=> Interface_List
(N
),
1598 Limited_Present
=> True));
1599 end Build_Corresponding_Record
;
1601 ---------------------------------
1602 -- Build_Dispatching_Tag_Check --
1603 ---------------------------------
1605 function Build_Dispatching_Tag_Check
1607 N
: Node_Id
) return Node_Id
1609 Loc
: constant Source_Ptr
:= Sloc
(N
);
1616 New_Occurrence_Of
(K
, Loc
),
1618 New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1622 New_Occurrence_Of
(K
, Loc
),
1624 New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
)));
1625 end Build_Dispatching_Tag_Check
;
1627 ----------------------------------
1628 -- Build_Entry_Count_Expression --
1629 ----------------------------------
1631 function Build_Entry_Count_Expression
1632 (Concurrent_Type
: Node_Id
;
1633 Component_List
: List_Id
;
1634 Loc
: Source_Ptr
) return Node_Id
1646 -- Count number of non-family entries
1649 Ent
:= First_Entity
(Concurrent_Type
);
1650 while Present
(Ent
) loop
1651 if Ekind
(Ent
) = E_Entry
then
1658 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1660 -- Loop through entry families building the addition nodes
1662 Ent
:= First_Entity
(Concurrent_Type
);
1663 Comp
:= First
(Component_List
);
1664 while Present
(Ent
) loop
1665 if Ekind
(Ent
) = E_Entry_Family
then
1666 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1670 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1671 Hi
:= Type_High_Bound
(Typ
);
1672 Lo
:= Type_Low_Bound
(Typ
);
1673 Large
:= Is_Potentially_Large_Family
1674 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1677 Left_Opnd
=> Ecount
,
1679 Family_Size
(Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1686 end Build_Entry_Count_Expression
;
1688 ---------------------------
1689 -- Build_Parameter_Block --
1690 ---------------------------
1692 function Build_Parameter_Block
1696 Decls
: List_Id
) return Entity_Id
1702 Has_Comp
: Boolean := False;
1706 Actual
:= First
(Actuals
);
1708 Formal
:= Defining_Identifier
(First
(Formals
));
1710 while Present
(Actual
) loop
1711 if not Is_Controlling_Actual
(Actual
) then
1714 -- type Ann is access all <actual-type>
1716 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1717 Set_Is_Param_Block_Component_Type
(Comp_Nam
);
1720 Make_Full_Type_Declaration
(Loc
,
1721 Defining_Identifier
=> Comp_Nam
,
1723 Make_Access_To_Object_Definition
(Loc
,
1724 All_Present
=> True,
1725 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1726 Subtype_Indication
=>
1727 New_Occurrence_Of
(Etype
(Actual
), Loc
))));
1733 Make_Component_Declaration
(Loc
,
1734 Defining_Identifier
=>
1735 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1736 Component_Definition
=>
1737 Make_Component_Definition
(Loc
,
1740 Subtype_Indication
=>
1741 New_Occurrence_Of
(Comp_Nam
, Loc
))));
1746 Next_Actual
(Actual
);
1747 Next_Formal_With_Extras
(Formal
);
1750 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1755 -- type Pnn is record
1760 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1761 -- the original parameter names and Ann1 .. AnnN are the access to
1765 Make_Full_Type_Declaration
(Loc
,
1766 Defining_Identifier
=>
1769 Make_Record_Definition
(Loc
,
1771 Make_Component_List
(Loc
, Comps
))));
1774 -- type Pnn is null record;
1777 Make_Full_Type_Declaration
(Loc
,
1778 Defining_Identifier
=>
1781 Make_Record_Definition
(Loc
,
1782 Null_Present
=> True,
1783 Component_List
=> Empty
)));
1787 end Build_Parameter_Block
;
1789 --------------------------------------
1790 -- Build_Renamed_Formal_Declaration --
1791 --------------------------------------
1793 function Build_Renamed_Formal_Declaration
1797 Renamed_Formal
: Node_Id
) return Node_Id
1799 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1803 -- If the formal is a tagged incomplete type, it is already passed
1804 -- by reference, so it is sufficient to rename the pointer component
1805 -- that corresponds to the actual. Otherwise we need to dereference
1806 -- the pointer component to obtain the actual.
1808 if Is_Incomplete_Type
(Etype
(Formal
))
1809 and then Is_Tagged_Type
(Etype
(Formal
))
1812 Make_Object_Renaming_Declaration
(Loc
,
1813 Defining_Identifier
=> New_F
,
1814 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Comp
), Loc
),
1815 Name
=> Renamed_Formal
);
1819 Make_Object_Renaming_Declaration
(Loc
,
1820 Defining_Identifier
=> New_F
,
1821 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Formal
), Loc
),
1823 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1827 end Build_Renamed_Formal_Declaration
;
1829 --------------------------
1830 -- Build_Wrapper_Bodies --
1831 --------------------------
1833 procedure Build_Wrapper_Bodies
1838 Rec_Typ
: Entity_Id
;
1840 function Build_Wrapper_Body
1842 Subp_Id
: Entity_Id
;
1843 Obj_Typ
: Entity_Id
;
1844 Formals
: List_Id
) return Node_Id
;
1845 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1846 -- associated with a protected or task type. Subp_Id is the subprogram
1847 -- name which will be wrapped. Obj_Typ is the type of the new formal
1848 -- parameter which handles dispatching and object notation. Formals are
1849 -- the original formals of Subp_Id which will be explicitly replicated.
1851 ------------------------
1852 -- Build_Wrapper_Body --
1853 ------------------------
1855 function Build_Wrapper_Body
1857 Subp_Id
: Entity_Id
;
1858 Obj_Typ
: Entity_Id
;
1859 Formals
: List_Id
) return Node_Id
1861 Body_Spec
: Node_Id
;
1864 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
1866 -- The subprogram is not overriding or is not a primitive declared
1867 -- between two views.
1869 if No
(Body_Spec
) then
1874 Actuals
: List_Id
:= No_List
;
1876 First_Form
: Node_Id
;
1881 -- Map formals to actuals. Use the list built for the wrapper
1882 -- spec, skipping the object notation parameter.
1884 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
1886 Formal
:= First_Form
;
1889 if Present
(Formal
) then
1890 Actuals
:= New_List
;
1891 while Present
(Formal
) loop
1893 Make_Identifier
(Loc
,
1894 Chars
=> Chars
(Defining_Identifier
(Formal
))));
1899 -- Special processing for primitives declared between a private
1900 -- type and its completion: the wrapper needs a properly typed
1901 -- parameter if the wrapped operation has a controlling first
1902 -- parameter. Note that this might not be the case for a function
1903 -- with a controlling result.
1905 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
1906 if No
(Actuals
) then
1907 Actuals
:= New_List
;
1910 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
1911 Prepend_To
(Actuals
,
1912 Unchecked_Convert_To
1913 (Corresponding_Concurrent_Type
(Obj_Typ
),
1914 Make_Identifier
(Loc
, Name_uO
)));
1917 Prepend_To
(Actuals
,
1918 Make_Identifier
(Loc
,
1919 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
1922 Nam
:= New_Occurrence_Of
(Subp_Id
, Loc
);
1924 -- An access-to-variable object parameter requires an explicit
1925 -- dereference in the unchecked conversion. This case occurs
1926 -- when a protected entry wrapper must override an interface
1927 -- level procedure with interface access as first parameter.
1929 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1931 if Nkind
(Parameter_Type
(First_Form
)) =
1935 Make_Explicit_Dereference
(Loc
,
1936 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
1938 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
1942 Make_Selected_Component
(Loc
,
1944 Unchecked_Convert_To
1945 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
1946 Selector_Name
=> New_Occurrence_Of
(Subp_Id
, Loc
));
1949 -- Create the subprogram body. For a function, the call to the
1950 -- actual subprogram has to be converted to the corresponding
1951 -- record if it is a controlling result.
1953 if Ekind
(Subp_Id
) = E_Function
then
1959 Make_Function_Call
(Loc
,
1961 Parameter_Associations
=> Actuals
);
1963 if Has_Controlling_Result
(Subp_Id
) then
1965 Unchecked_Convert_To
1966 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
1970 Make_Subprogram_Body
(Loc
,
1971 Specification
=> Body_Spec
,
1972 Declarations
=> Empty_List
,
1973 Handled_Statement_Sequence
=>
1974 Make_Handled_Sequence_Of_Statements
(Loc
,
1975 Statements
=> New_List
(
1976 Make_Simple_Return_Statement
(Loc
, Res
))));
1981 Make_Subprogram_Body
(Loc
,
1982 Specification
=> Body_Spec
,
1983 Declarations
=> Empty_List
,
1984 Handled_Statement_Sequence
=>
1985 Make_Handled_Sequence_Of_Statements
(Loc
,
1986 Statements
=> New_List
(
1987 Make_Procedure_Call_Statement
(Loc
,
1989 Parameter_Associations
=> Actuals
))));
1992 end Build_Wrapper_Body
;
1994 -- Start of processing for Build_Wrapper_Bodies
1997 if Is_Concurrent_Type
(Typ
) then
1998 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2003 -- Generate wrapper bodies for a concurrent type which implements an
2006 if Present
(Interfaces
(Rec_Typ
)) then
2008 Insert_Nod
: Node_Id
;
2010 Prim_Elmt
: Elmt_Id
;
2011 Prim_Decl
: Node_Id
;
2013 Wrap_Body
: Node_Id
;
2014 Wrap_Id
: Entity_Id
;
2019 -- Examine all primitive operations of the corresponding record
2020 -- type, looking for wrapper specs. Generate bodies in order to
2023 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2024 while Present
(Prim_Elmt
) loop
2025 Prim
:= Node
(Prim_Elmt
);
2027 if (Ekind
(Prim
) = E_Function
2028 or else Ekind
(Prim
) = E_Procedure
)
2029 and then Is_Primitive_Wrapper
(Prim
)
2031 Subp
:= Wrapped_Entity
(Prim
);
2032 Prim_Decl
:= Parent
(Parent
(Prim
));
2035 Build_Wrapper_Body
(Loc
,
2038 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2039 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2041 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2042 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2044 Insert_After
(Insert_Nod
, Wrap_Body
);
2045 Insert_Nod
:= Wrap_Body
;
2047 Analyze
(Wrap_Body
);
2050 Next_Elmt
(Prim_Elmt
);
2054 end Build_Wrapper_Bodies
;
2056 ------------------------
2057 -- Build_Wrapper_Spec --
2058 ------------------------
2060 function Build_Wrapper_Spec
2061 (Subp_Id
: Entity_Id
;
2062 Obj_Typ
: Entity_Id
;
2063 Formals
: List_Id
) return Node_Id
2065 function Overriding_Possible
2066 (Iface_Op
: Entity_Id
;
2067 Wrapper
: Entity_Id
) return Boolean;
2068 -- Determine whether a primitive operation can be overridden by Wrapper.
2069 -- Iface_Op is the candidate primitive operation of an interface type,
2070 -- Wrapper is the generated entry wrapper.
2072 function Replicate_Formals
2074 Formals
: List_Id
) return List_Id
;
2075 -- An explicit parameter replication is required due to the Is_Entry_
2076 -- Formal flag being set for all the formals of an entry. The explicit
2077 -- replication removes the flag that would otherwise cause a different
2078 -- path of analysis.
2080 -------------------------
2081 -- Overriding_Possible --
2082 -------------------------
2084 function Overriding_Possible
2085 (Iface_Op
: Entity_Id
;
2086 Wrapper
: Entity_Id
) return Boolean
2088 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2089 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2091 function Type_Conformant_Parameters
2092 (Iface_Op_Params
: List_Id
;
2093 Wrapper_Params
: List_Id
) return Boolean;
2094 -- Determine whether the parameters of the generated entry wrapper
2095 -- and those of a primitive operation are type conformant. During
2096 -- this check, the first parameter of the primitive operation is
2097 -- skipped if it is a controlling argument: protected functions
2098 -- may have a controlling result.
2100 --------------------------------
2101 -- Type_Conformant_Parameters --
2102 --------------------------------
2104 function Type_Conformant_Parameters
2105 (Iface_Op_Params
: List_Id
;
2106 Wrapper_Params
: List_Id
) return Boolean
2108 Iface_Op_Param
: Node_Id
;
2109 Iface_Op_Typ
: Entity_Id
;
2110 Wrapper_Param
: Node_Id
;
2111 Wrapper_Typ
: Entity_Id
;
2114 -- Skip the first (controlling) parameter of primitive operation
2116 Iface_Op_Param
:= First
(Iface_Op_Params
);
2118 if Present
(First_Formal
(Iface_Op
))
2119 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2121 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2124 Wrapper_Param
:= First
(Wrapper_Params
);
2125 while Present
(Iface_Op_Param
)
2126 and then Present
(Wrapper_Param
)
2128 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2129 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2131 -- The two parameters must be mode conformant
2133 if not Conforming_Types
2134 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2139 Next
(Iface_Op_Param
);
2140 Next
(Wrapper_Param
);
2143 -- One of the lists is longer than the other
2145 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2150 end Type_Conformant_Parameters
;
2152 -- Start of processing for Overriding_Possible
2155 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2159 -- If an inherited subprogram is implemented by a protected procedure
2160 -- or an entry, then the first parameter of the inherited subprogram
2161 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2163 if Ekind
(Iface_Op
) = E_Procedure
2164 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2167 Obj_Param
: constant Node_Id
:=
2168 First
(Parameter_Specifications
(Iface_Op_Spec
));
2170 if not Out_Present
(Obj_Param
)
2171 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2180 Type_Conformant_Parameters
2181 (Parameter_Specifications
(Iface_Op_Spec
),
2182 Parameter_Specifications
(Wrapper_Spec
));
2183 end Overriding_Possible
;
2185 -----------------------
2186 -- Replicate_Formals --
2187 -----------------------
2189 function Replicate_Formals
2191 Formals
: List_Id
) return List_Id
2193 New_Formals
: constant List_Id
:= New_List
;
2195 Param_Type
: Node_Id
;
2198 Formal
:= First
(Formals
);
2200 -- Skip the object parameter when dealing with primitives declared
2201 -- between two views.
2203 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2204 and then not Has_Controlling_Result
(Subp_Id
)
2206 Formal
:= Next
(Formal
);
2209 while Present
(Formal
) loop
2211 -- Create an explicit copy of the entry parameter
2213 -- When creating the wrapper subprogram for a primitive operation
2214 -- of a protected interface we must construct an equivalent
2215 -- signature to that of the overriding operation. For regular
2216 -- parameters we can just use the type of the formal, but for
2217 -- access to subprogram parameters we need to reanalyze the
2218 -- parameter type to create local entities for the signature of
2219 -- the subprogram type. Using the entities of the overriding
2220 -- subprogram will result in out-of-scope errors in the back-end.
2222 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2223 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2226 New_Occurrence_Of
(Etype
(Parameter_Type
(Formal
)), Loc
);
2229 Append_To
(New_Formals
,
2230 Make_Parameter_Specification
(Loc
,
2231 Defining_Identifier
=>
2232 Make_Defining_Identifier
(Loc
,
2233 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2234 In_Present
=> In_Present
(Formal
),
2235 Out_Present
=> Out_Present
(Formal
),
2236 Null_Exclusion_Present
=> Null_Exclusion_Present
(Formal
),
2237 Parameter_Type
=> Param_Type
));
2243 end Replicate_Formals
;
2247 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2248 First_Param
: Node_Id
:= Empty
;
2250 Iface_Elmt
: Elmt_Id
;
2251 Iface_Op
: Entity_Id
;
2252 Iface_Op_Elmt
: Elmt_Id
;
2253 Overridden_Subp
: Entity_Id
;
2255 -- Start of processing for Build_Wrapper_Spec
2258 -- No point in building wrappers for untagged concurrent types
2260 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2262 -- Check if this subprogram has a profile that matches some interface
2265 Check_Synchronized_Overriding
(Subp_Id
, Overridden_Subp
);
2267 if Present
(Overridden_Subp
) then
2269 First
(Parameter_Specifications
(Parent
(Overridden_Subp
)));
2271 -- An entry or a protected procedure can override a routine where the
2272 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2273 -- type. Since the wrapper must have the exact same signature as that of
2274 -- the overridden subprogram, we try to find the overriding candidate
2275 -- and use its controlling formal.
2277 -- Check every implemented interface
2279 elsif Present
(Interfaces
(Obj_Typ
)) then
2280 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2281 Search
: while Present
(Iface_Elmt
) loop
2282 Iface
:= Node
(Iface_Elmt
);
2284 -- Check every interface primitive
2286 if Present
(Primitive_Operations
(Iface
)) then
2287 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2288 while Present
(Iface_Op_Elmt
) loop
2289 Iface_Op
:= Node
(Iface_Op_Elmt
);
2291 -- Ignore predefined primitives
2293 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2294 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2296 -- The current primitive operation can be overridden by
2297 -- the generated entry wrapper.
2299 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2301 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2307 Next_Elmt
(Iface_Op_Elmt
);
2311 Next_Elmt
(Iface_Elmt
);
2315 -- Do not generate the wrapper if no interface primitive is covered by
2316 -- the subprogram and it is not a primitive declared between two views
2317 -- (see Process_Full_View).
2320 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2326 Wrapper_Id
: constant Entity_Id
:=
2327 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2328 New_Formals
: List_Id
;
2329 Obj_Param
: Node_Id
;
2330 Obj_Param_Typ
: Entity_Id
;
2333 -- Minimum decoration is needed to catch the entity in
2334 -- Sem_Ch6.Override_Dispatching_Operation.
2336 if Ekind
(Subp_Id
) = E_Function
then
2337 Set_Ekind
(Wrapper_Id
, E_Function
);
2339 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2342 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2343 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2344 Set_Is_Private_Primitive
(Wrapper_Id
,
2345 Is_Private_Primitive_Subprogram
(Subp_Id
));
2347 -- Process the formals
2349 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2351 -- A function with a controlling result and no first controlling
2352 -- formal needs no additional parameter.
2354 if Has_Controlling_Result
(Subp_Id
)
2356 (No
(First_Formal
(Subp_Id
))
2357 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2361 -- Routine Subp_Id has been found to override an interface primitive.
2362 -- If the interface operation has an access parameter, create a copy
2363 -- of it, with the same null exclusion indicator if present.
2365 elsif Present
(First_Param
) then
2366 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2368 Make_Access_Definition
(Loc
,
2370 New_Occurrence_Of
(Obj_Typ
, Loc
),
2371 Null_Exclusion_Present
=>
2372 Null_Exclusion_Present
(Parameter_Type
(First_Param
)),
2374 Constant_Present
(Parameter_Type
(First_Param
)));
2376 Obj_Param_Typ
:= New_Occurrence_Of
(Obj_Typ
, Loc
);
2380 Make_Parameter_Specification
(Loc
,
2381 Defining_Identifier
=>
2382 Make_Defining_Identifier
(Loc
,
2384 In_Present
=> In_Present
(First_Param
),
2385 Out_Present
=> Out_Present
(First_Param
),
2386 Parameter_Type
=> Obj_Param_Typ
);
2388 Prepend_To
(New_Formals
, Obj_Param
);
2390 -- If we are dealing with a primitive declared between two views,
2391 -- implemented by a synchronized operation, we need to create
2392 -- a default parameter. The mode of the parameter must match that
2393 -- of the primitive operation.
2396 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2399 Make_Parameter_Specification
(Loc
,
2400 Defining_Identifier
=>
2401 Make_Defining_Identifier
(Loc
, Name_uO
),
2403 In_Present
(Parent
(First_Entity
(Subp_Id
))),
2404 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2405 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2407 Prepend_To
(New_Formals
, Obj_Param
);
2410 -- Build the final spec. If it is a function with a controlling
2411 -- result, it is a primitive operation of the corresponding
2412 -- record type, so mark the spec accordingly.
2414 if Ekind
(Subp_Id
) = E_Function
then
2419 if Has_Controlling_Result
(Subp_Id
) then
2422 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2424 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2428 Make_Function_Specification
(Loc
,
2429 Defining_Unit_Name
=> Wrapper_Id
,
2430 Parameter_Specifications
=> New_Formals
,
2431 Result_Definition
=> Res_Def
);
2435 Make_Procedure_Specification
(Loc
,
2436 Defining_Unit_Name
=> Wrapper_Id
,
2437 Parameter_Specifications
=> New_Formals
);
2440 end Build_Wrapper_Spec
;
2442 -------------------------
2443 -- Build_Wrapper_Specs --
2444 -------------------------
2446 procedure Build_Wrapper_Specs
2452 Rec_Typ
: Entity_Id
;
2453 procedure Scan_Declarations
(L
: List_Id
);
2454 -- Common processing for visible and private declarations
2455 -- of a protected type.
2457 procedure Scan_Declarations
(L
: List_Id
) is
2459 Wrap_Decl
: Node_Id
;
2460 Wrap_Spec
: Node_Id
;
2468 while Present
(Decl
) loop
2471 if Nkind
(Decl
) = N_Entry_Declaration
2472 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2476 (Subp_Id
=> Defining_Identifier
(Decl
),
2478 Formals
=> Parameter_Specifications
(Decl
));
2480 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2483 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2486 Parameter_Specifications
(Specification
(Decl
)));
2489 if Present
(Wrap_Spec
) then
2491 Make_Subprogram_Declaration
(Loc
,
2492 Specification
=> Wrap_Spec
);
2494 Insert_After
(N
, Wrap_Decl
);
2497 Analyze
(Wrap_Decl
);
2502 end Scan_Declarations
;
2504 -- start of processing for Build_Wrapper_Specs
2507 if Is_Protected_Type
(Typ
) then
2508 Def
:= Protected_Definition
(Parent
(Typ
));
2509 else pragma Assert
(Is_Task_Type
(Typ
));
2510 Def
:= Task_Definition
(Parent
(Typ
));
2513 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2515 -- Generate wrapper specs for a concurrent type which implements an
2516 -- interface. Operations in both the visible and private parts may
2517 -- implement progenitor operations.
2519 if Present
(Interfaces
(Rec_Typ
)) and then Present
(Def
) then
2520 Scan_Declarations
(Visible_Declarations
(Def
));
2521 Scan_Declarations
(Private_Declarations
(Def
));
2523 end Build_Wrapper_Specs
;
2525 ---------------------------
2526 -- Build_Find_Body_Index --
2527 ---------------------------
2529 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2530 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2533 Has_F
: Boolean := False;
2535 If_St
: Node_Id
:= Empty
;
2538 Decls
: List_Id
:= New_List
;
2541 Siz
: Node_Id
:= Empty
;
2543 procedure Add_If_Clause
(Expr
: Node_Id
);
2544 -- Add test for range of current entry
2546 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2547 -- If a bound of an entry is given by a discriminant, retrieve the
2548 -- actual value of the discriminant from the enclosing object.
2554 procedure Add_If_Clause
(Expr
: Node_Id
) is
2556 Stats
: constant List_Id
:=
2558 Make_Simple_Return_Statement
(Loc
,
2559 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2562 -- Index for current entry body
2566 -- Compute total length of entry queues so far
2574 Right_Opnd
=> Expr
);
2579 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2582 -- Map entry queue indexes in the range of the current family
2583 -- into the current index, that designates the entry body.
2587 Make_Implicit_If_Statement
(Typ
,
2589 Then_Statements
=> Stats
,
2590 Elsif_Parts
=> New_List
);
2594 Append_To
(Elsif_Parts
(If_St
),
2595 Make_Elsif_Part
(Loc
,
2597 Then_Statements
=> Stats
));
2601 ------------------------------
2602 -- Convert_Discriminant_Ref --
2603 ------------------------------
2605 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2609 if Is_Entity_Name
(Bound
)
2610 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2613 Make_Selected_Component
(Loc
,
2615 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2616 Make_Explicit_Dereference
(Loc
,
2617 Make_Identifier
(Loc
, Name_uObject
))),
2618 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2619 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2621 B
:= New_Copy_Tree
(Bound
);
2625 end Convert_Discriminant_Ref
;
2627 -- Start of processing for Build_Find_Body_Index
2630 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2632 Ent
:= First_Entity
(Typ
);
2633 while Present
(Ent
) loop
2634 if Ekind
(Ent
) = E_Entry_Family
then
2644 -- If the protected type has no entry families, there is a one-one
2645 -- correspondence between entry queue and entry body.
2648 Make_Simple_Return_Statement
(Loc
,
2649 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2652 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2655 -- if E <= l1 then return 1;
2656 -- elsif E <= l1 + l2 then return 2;
2661 Ent
:= First_Entity
(Typ
);
2663 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2665 while Present
(Ent
) loop
2666 if Ekind
(Ent
) = E_Entry
then
2667 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2669 elsif Ekind
(Ent
) = E_Entry_Family
then
2670 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2671 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2672 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2673 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2682 Make_Simple_Return_Statement
(Loc
,
2683 Expression
=> Make_Integer_Literal
(Loc
, 1));
2685 elsif Nkind
(Ret
) = N_If_Statement
then
2687 -- Ranges are in increasing order, so last one doesn't need guard
2690 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2693 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2699 Make_Subprogram_Body
(Loc
,
2700 Specification
=> Spec
,
2701 Declarations
=> Decls
,
2702 Handled_Statement_Sequence
=>
2703 Make_Handled_Sequence_Of_Statements
(Loc
,
2704 Statements
=> New_List
(Ret
)));
2705 end Build_Find_Body_Index
;
2707 --------------------------------
2708 -- Build_Find_Body_Index_Spec --
2709 --------------------------------
2711 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2712 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2713 Id
: constant Entity_Id
:=
2714 Make_Defining_Identifier
(Loc
,
2715 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2716 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2717 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2721 Make_Function_Specification
(Loc
,
2722 Defining_Unit_Name
=> Id
,
2723 Parameter_Specifications
=> New_List
(
2724 Make_Parameter_Specification
(Loc
,
2725 Defining_Identifier
=> Parm1
,
2727 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2729 Make_Parameter_Specification
(Loc
,
2730 Defining_Identifier
=> Parm2
,
2732 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2734 Result_Definition
=> New_Occurrence_Of
(
2735 RTE
(RE_Protected_Entry_Index
), Loc
));
2736 end Build_Find_Body_Index_Spec
;
2738 -----------------------------------------------
2739 -- Build_Lock_Free_Protected_Subprogram_Body --
2740 -----------------------------------------------
2742 function Build_Lock_Free_Protected_Subprogram_Body
2745 Unprot_Spec
: Node_Id
) return Node_Id
2747 Actuals
: constant List_Id
:= New_List
;
2748 Loc
: constant Source_Ptr
:= Sloc
(N
);
2749 Spec
: constant Node_Id
:= Specification
(N
);
2750 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
2752 Prot_Spec
: Node_Id
;
2756 -- Create the protected version of the body
2759 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
2761 -- Build the actual parameters which appear in the call to the
2762 -- unprotected version of the body.
2764 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
2765 while Present
(Formal
) loop
2767 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
2772 -- Function case, generate:
2773 -- return <Unprot_Func_Call>;
2775 if Nkind
(Spec
) = N_Function_Specification
then
2777 Make_Simple_Return_Statement
(Loc
,
2779 Make_Function_Call
(Loc
,
2781 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2782 Parameter_Associations
=> Actuals
));
2784 -- Procedure case, call the unprotected version
2788 Make_Procedure_Call_Statement
(Loc
,
2790 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2791 Parameter_Associations
=> Actuals
);
2795 Make_Subprogram_Body
(Loc
,
2796 Declarations
=> Empty_List
,
2797 Specification
=> Prot_Spec
,
2798 Handled_Statement_Sequence
=>
2799 Make_Handled_Sequence_Of_Statements
(Loc
,
2800 Statements
=> New_List
(Stmt
)));
2801 end Build_Lock_Free_Protected_Subprogram_Body
;
2803 -------------------------------------------------
2804 -- Build_Lock_Free_Unprotected_Subprogram_Body --
2805 -------------------------------------------------
2807 -- Procedures which meet the lock-free implementation requirements and
2808 -- reference a unique scalar component Comp are expanded in the following
2811 -- procedure P (...) is
2812 -- Expected_Comp : constant Comp_Type :=
2814 -- (System.Atomic_Primitives.Lock_Free_Read_N
2815 -- (_Object.Comp'Address));
2819 -- <original declarations before the object renaming declaration
2822 -- Desired_Comp : Comp_Type := Expected_Comp;
2823 -- Comp : Comp_Type renames Desired_Comp;
2825 -- <original delarations after the object renaming declaration
2829 -- <original statements>
2830 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
2831 -- (_Object.Comp'Address,
2832 -- Interfaces.Unsigned_N (Expected_Comp),
2833 -- Interfaces.Unsigned_N (Desired_Comp));
2838 -- Each return and raise statement of P is transformed into an atomic
2841 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2842 -- (_Object.Comp'Address,
2843 -- Interfaces.Unsigned_N (Expected_Comp),
2844 -- Interfaces.Unsigned_N (Desired_Comp));
2846 -- <original statement>
2851 -- Functions which meet the lock-free implementation requirements and
2852 -- reference a unique scalar component Comp are expanded in the following
2855 -- function F (...) return ... is
2856 -- <original declarations before the object renaming declaration
2859 -- Expected_Comp : constant Comp_Type :=
2861 -- (System.Atomic_Primitives.Lock_Free_Read_N
2862 -- (_Object.Comp'Address));
2863 -- Comp : Comp_Type renames Expected_Comp;
2865 -- <original delarations after the object renaming declaration of
2869 -- <original statements>
2872 function Build_Lock_Free_Unprotected_Subprogram_Body
2874 Prot_Typ
: Node_Id
) return Node_Id
2876 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
2877 -- Subprograms which meet the lock-free implementation criteria are
2878 -- allowed to reference only one unique component. Return the prival
2879 -- of the said component.
2881 --------------------------
2882 -- Referenced_Component --
2883 --------------------------
2885 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
2888 Source_Comp
: Entity_Id
:= Empty
;
2891 -- Find the unique source component which N references in its
2894 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
2896 Element
: Lock_Free_Subprogram
renames
2897 Lock_Free_Subprogram_Table
.Table
(Index
);
2899 if Element
.Sub_Body
= N
then
2900 Source_Comp
:= Element
.Comp_Id
;
2906 if No
(Source_Comp
) then
2910 -- Find the prival which corresponds to the source component within
2911 -- the declarations of N.
2913 Decl
:= First
(Declarations
(N
));
2914 while Present
(Decl
) loop
2916 -- Privals appear as object renamings
2918 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
2919 Comp
:= Defining_Identifier
(Decl
);
2921 if Present
(Prival_Link
(Comp
))
2922 and then Prival_Link
(Comp
) = Source_Comp
2932 end Referenced_Component
;
2936 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
2937 Loc
: constant Source_Ptr
:= Sloc
(N
);
2938 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
2939 Decls
: List_Id
:= Declarations
(N
);
2941 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
2944 -- Add renamings for the protection object, discriminals, privals, and
2945 -- the entry index constant for use by debugger.
2947 Debug_Private_Data_Declarations
(Decls
);
2949 -- Perform the lock-free expansion when the subprogram references a
2950 -- protected component.
2952 if Present
(Comp
) then
2953 Protected_Component_Ref
: declare
2954 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
2955 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
2956 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
2958 Is_Procedure
: constant Boolean :=
2959 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
2960 -- Indicates if N is a protected procedure body
2962 Block_Decls
: List_Id
:= No_List
;
2963 Try_Write
: Entity_Id
;
2964 Desired_Comp
: Entity_Id
;
2967 Label_Id
: Entity_Id
:= Empty
;
2969 Expected_Comp
: Entity_Id
;
2972 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
2974 Unsigned
: Entity_Id
;
2976 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
2977 -- Transform a single node if it is a return statement, a raise
2978 -- statement or a reference to Comp.
2980 procedure Process_Stmts
(Stmts
: List_Id
);
2981 -- Given a statement sequence Stmts, wrap any return or raise
2982 -- statements in the following manner:
2984 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2985 -- (_Object.Comp'Address,
2986 -- Interfaces.Unsigned_N (Expected_Comp),
2987 -- Interfaces.Unsigned_N (Desired_Comp))
2998 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3000 procedure Wrap_Statement
(Stmt
: Node_Id
);
3001 -- Wrap an arbitrary statement inside an if statement where the
3002 -- condition does an atomic check on the state of the object.
3004 --------------------
3005 -- Wrap_Statement --
3006 --------------------
3008 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3010 -- The first time through, create the declaration of a label
3011 -- which is used to skip the remainder of source statements
3012 -- if the state of the object has changed.
3014 if No
(Label_Id
) then
3016 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3017 Set_Entity
(Label_Id
,
3018 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3022 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3023 -- (_Object.Comp'Address,
3024 -- Interfaces.Unsigned_N (Expected_Comp),
3025 -- Interfaces.Unsigned_N (Desired_Comp))
3033 Make_Implicit_If_Statement
(N
,
3035 Make_Function_Call
(Loc
,
3037 New_Occurrence_Of
(Try_Write
, Loc
),
3038 Parameter_Associations
=> New_List
(
3039 Make_Attribute_Reference
(Loc
,
3040 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3041 Attribute_Name
=> Name_Address
),
3043 Unchecked_Convert_To
(Unsigned
,
3044 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3046 Unchecked_Convert_To
(Unsigned
,
3047 New_Occurrence_Of
(Desired_Comp
, Loc
)))),
3049 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3051 Else_Statements
=> New_List
(
3052 Make_Goto_Statement
(Loc
,
3054 New_Occurrence_Of
(Entity
(Label_Id
), Loc
)))));
3057 -- Start of processing for Process_Node
3060 -- Wrap each return and raise statement that appear inside a
3061 -- procedure. Skip the last return statement which is added by
3062 -- default since it is transformed into an exit statement.
3065 and then ((Nkind
(N
) = N_Simple_Return_Statement
3066 and then N
/= Last
(Stmts
))
3067 or else Nkind
(N
) = N_Extended_Return_Statement
3068 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3069 N_Raise_Program_Error
,
3071 N_Raise_Storage_Error
)
3072 and then Comes_From_Source
(N
)))
3080 Set_Analyzed
(N
, False);
3085 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3091 procedure Process_Stmts
(Stmts
: List_Id
) is
3094 Stmt
:= First
(Stmts
);
3095 while Present
(Stmt
) loop
3096 Process_Nodes
(Stmt
);
3101 -- Start of processing for Protected_Component_Ref
3104 -- Get the type size
3106 if Known_Static_Esize
(Comp_Type
) then
3107 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3109 -- If the Esize (Object_Size) is unknown at compile time, look at
3110 -- the RM_Size (Value_Size) since it may have been set by an
3111 -- explicit representation clause.
3113 elsif Known_Static_RM_Size
(Comp_Type
) then
3114 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3116 -- Should not happen since this has already been checked in
3117 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3120 raise Program_Error
;
3123 -- Retrieve all relevant atomic routines and types
3127 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3128 Read
:= RTE
(RE_Lock_Free_Read_8
);
3129 Unsigned
:= RTE
(RE_Uint8
);
3132 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3133 Read
:= RTE
(RE_Lock_Free_Read_16
);
3134 Unsigned
:= RTE
(RE_Uint16
);
3137 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3138 Read
:= RTE
(RE_Lock_Free_Read_32
);
3139 Unsigned
:= RTE
(RE_Uint32
);
3142 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3143 Read
:= RTE
(RE_Lock_Free_Read_64
);
3144 Unsigned
:= RTE
(RE_Uint64
);
3147 raise Program_Error
;
3151 -- Expected_Comp : constant Comp_Type :=
3153 -- (System.Atomic_Primitives.Lock_Free_Read_N
3154 -- (_Object.Comp'Address));
3157 Make_Defining_Identifier
(Loc
,
3158 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3161 Make_Object_Declaration
(Loc
,
3162 Defining_Identifier
=> Expected_Comp
,
3163 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3164 Constant_Present
=> True,
3166 Unchecked_Convert_To
(Comp_Type
,
3167 Make_Function_Call
(Loc
,
3168 Name
=> New_Occurrence_Of
(Read
, Loc
),
3169 Parameter_Associations
=> New_List
(
3170 Make_Attribute_Reference
(Loc
,
3171 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3172 Attribute_Name
=> Name_Address
)))));
3174 -- Protected procedures
3176 if Is_Procedure
then
3177 -- Move the original declarations inside the generated block
3179 Block_Decls
:= Decls
;
3181 -- Reset the declarations list of the protected procedure to
3182 -- contain only Decl.
3184 Decls
:= New_List
(Decl
);
3187 -- Desired_Comp : Comp_Type := Expected_Comp;
3190 Make_Defining_Identifier
(Loc
,
3191 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3193 -- Insert the declarations of Expected_Comp and Desired_Comp in
3194 -- the block declarations right before the renaming of the
3195 -- protected component.
3197 Insert_Before
(Comp_Decl
,
3198 Make_Object_Declaration
(Loc
,
3199 Defining_Identifier
=> Desired_Comp
,
3200 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3202 New_Occurrence_Of
(Expected_Comp
, Loc
)));
3204 -- Protected function
3207 Desired_Comp
:= Expected_Comp
;
3209 -- Insert the declaration of Expected_Comp in the function
3210 -- declarations right before the renaming of the protected
3213 Insert_Before
(Comp_Decl
, Decl
);
3216 -- Rewrite the protected component renaming declaration to be a
3217 -- renaming of Desired_Comp.
3220 -- Comp : Comp_Type renames Desired_Comp;
3223 Make_Object_Renaming_Declaration
(Loc
,
3224 Defining_Identifier
=>
3225 Defining_Identifier
(Comp_Decl
),
3227 New_Occurrence_Of
(Comp_Type
, Loc
),
3229 New_Occurrence_Of
(Desired_Comp
, Loc
)));
3231 -- Wrap any return or raise statements in Stmts in same the manner
3232 -- described in Process_Stmts.
3234 Process_Stmts
(Stmts
);
3237 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3238 -- (_Object.Comp'Address,
3239 -- Interfaces.Unsigned_N (Expected_Comp),
3240 -- Interfaces.Unsigned_N (Desired_Comp))
3242 if Is_Procedure
then
3244 Make_Exit_Statement
(Loc
,
3246 Make_Function_Call
(Loc
,
3248 New_Occurrence_Of
(Try_Write
, Loc
),
3249 Parameter_Associations
=> New_List
(
3250 Make_Attribute_Reference
(Loc
,
3251 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3252 Attribute_Name
=> Name_Address
),
3254 Unchecked_Convert_To
(Unsigned
,
3255 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3257 Unchecked_Convert_To
(Unsigned
,
3258 New_Occurrence_Of
(Desired_Comp
, Loc
)))));
3260 -- Small optimization: transform the default return statement
3261 -- of a procedure into the atomic exit statement.
3263 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3264 Rewrite
(Last
(Stmts
), Stmt
);
3266 Append_To
(Stmts
, Stmt
);
3270 -- Create the declaration of the label used to skip the rest of
3271 -- the source statements when the object state changes.
3273 if Present
(Label_Id
) then
3274 Label
:= Make_Label
(Loc
, Label_Id
);
3276 Make_Implicit_Label_Declaration
(Loc
,
3277 Defining_Identifier
=> Entity
(Label_Id
),
3278 Label_Construct
=> Label
));
3279 Append_To
(Stmts
, Label
);
3291 if Is_Procedure
then
3294 Make_Loop_Statement
(Loc
,
3295 Statements
=> New_List
(
3296 Make_Block_Statement
(Loc
,
3297 Declarations
=> Block_Decls
,
3298 Handled_Statement_Sequence
=>
3299 Make_Handled_Sequence_Of_Statements
(Loc
,
3300 Statements
=> Stmts
))),
3301 End_Label
=> Empty
));
3305 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3306 end Protected_Component_Ref
;
3309 -- Make an unprotected version of the subprogram for use within the same
3310 -- object, with new name and extra parameter representing the object.
3313 Make_Subprogram_Body
(Loc
,
3315 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3316 Declarations
=> Decls
,
3317 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3318 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3320 -------------------------
3321 -- Build_Master_Entity --
3322 -------------------------
3324 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3325 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3327 Context_Id
: Entity_Id
;
3333 if Is_Itype
(Obj_Or_Typ
) then
3334 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3336 Par
:= Parent
(Obj_Or_Typ
);
3339 -- When creating a master for a record component which is either a task
3340 -- or access-to-task, the enclosing record is the master scope and the
3341 -- proper insertion point is the component list.
3343 if Is_Record_Type
(Current_Scope
) then
3345 Context_Id
:= Current_Scope
;
3346 Decls
:= List_Containing
(Context
);
3348 -- Default case for object declarations and access types. Note that the
3349 -- context is updated to the nearest enclosing body, block, package, or
3350 -- return statement.
3353 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3356 -- Nothing to do if the context already has a master
3358 if Has_Master_Entity
(Context_Id
) then
3361 -- Nothing to do if tasks or tasking hierarchies are prohibited
3363 elsif Restriction_Active
(No_Tasking
)
3364 or else Restriction_Active
(No_Task_Hierarchy
)
3369 -- Create a master, generate:
3370 -- _Master : constant Master_Id := Current_Master.all;
3373 Make_Object_Declaration
(Loc
,
3374 Defining_Identifier
=>
3375 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3376 Constant_Present
=> True,
3377 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3379 Make_Explicit_Dereference
(Loc
,
3380 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
3382 -- The master is inserted at the start of the declarative list of the
3385 Prepend_To
(Decls
, Decl
);
3387 -- In certain cases where transient scopes are involved, the immediate
3388 -- scope is not always the proper master scope. Ensure that the master
3389 -- declaration and entity appear in the same context.
3391 if Context_Id
/= Current_Scope
then
3392 Push_Scope
(Context_Id
);
3399 -- Mark the enclosing scope and its associated construct as being task
3402 Set_Has_Master_Entity
(Context_Id
);
3404 while Present
(Context
)
3405 and then Nkind
(Context
) /= N_Compilation_Unit
3407 if Nkind_In
(Context
, N_Block_Statement
,
3411 Set_Is_Task_Master
(Context
);
3414 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3415 Context
:= Corresponding_Stub
(Parent
(Context
));
3418 Context
:= Parent
(Context
);
3420 end Build_Master_Entity
;
3422 ---------------------------
3423 -- Build_Master_Renaming --
3424 ---------------------------
3426 procedure Build_Master_Renaming
3427 (Ptr_Typ
: Entity_Id
;
3428 Ins_Nod
: Node_Id
:= Empty
)
3430 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3432 Master_Decl
: Node_Id
;
3433 Master_Id
: Entity_Id
;
3436 -- Nothing to do if tasks or tasking hierarchies are prohibited
3438 if Restriction_Active
(No_Tasking
)
3439 or else Restriction_Active
(No_Task_Hierarchy
)
3444 -- Determine the proper context to insert the master renaming
3446 if Present
(Ins_Nod
) then
3448 elsif Is_Itype
(Ptr_Typ
) then
3449 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3451 Context
:= Parent
(Ptr_Typ
);
3455 -- <Ptr_Typ>M : Master_Id renames _Master;
3458 Make_Defining_Identifier
(Loc
,
3459 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3462 Make_Object_Renaming_Declaration
(Loc
,
3463 Defining_Identifier
=> Master_Id
,
3464 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3465 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3467 Insert_Action
(Context
, Master_Decl
);
3469 -- The renamed master now services the access type
3471 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3472 end Build_Master_Renaming
;
3474 -----------------------------------------
3475 -- Build_Private_Protected_Declaration --
3476 -----------------------------------------
3478 function Build_Private_Protected_Declaration
3479 (N
: Node_Id
) return Entity_Id
3481 Loc
: constant Source_Ptr
:= Sloc
(N
);
3482 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3487 Spec_Id
: Entity_Id
;
3490 Formal
:= First_Formal
(Body_Id
);
3492 -- The protected operation always has at least one formal, namely the
3493 -- object itself, but it is only placed in the parameter list if
3494 -- expansion is enabled.
3496 if Present
(Formal
) or else Expander_Active
then
3497 Plist
:= Copy_Parameter_List
(Body_Id
);
3502 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3504 Make_Procedure_Specification
(Loc
,
3505 Defining_Unit_Name
=>
3506 Make_Defining_Identifier
(Sloc
(Body_Id
),
3507 Chars
=> Chars
(Body_Id
)),
3508 Parameter_Specifications
=>
3512 Make_Function_Specification
(Loc
,
3513 Defining_Unit_Name
=>
3514 Make_Defining_Identifier
(Sloc
(Body_Id
),
3515 Chars
=> Chars
(Body_Id
)),
3516 Parameter_Specifications
=> Plist
,
3517 Result_Definition
=>
3518 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3521 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3522 Insert_Before
(N
, Decl
);
3523 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3525 -- Indicate that the entity comes from source, to ensure that cross-
3526 -- reference information is properly generated. The body itself is
3527 -- rewritten during expansion, and the body entity will not appear in
3528 -- calls to the operation.
3530 Set_Comes_From_Source
(Spec_Id
, True);
3532 Set_Has_Completion
(Spec_Id
);
3533 Set_Convention
(Spec_Id
, Convention_Protected
);
3535 end Build_Private_Protected_Declaration
;
3537 ---------------------------
3538 -- Build_Protected_Entry --
3539 ---------------------------
3541 function Build_Protected_Entry
3544 Pid
: Node_Id
) return Node_Id
3546 Bod_Decls
: constant List_Id
:= New_List
;
3547 Decls
: constant List_Id
:= Declarations
(N
);
3548 End_Lab
: constant Node_Id
:=
3549 End_Label
(Handled_Statement_Sequence
(N
));
3550 End_Loc
: constant Source_Ptr
:=
3551 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3552 -- Used for the generated call to Complete_Entry_Body
3554 Loc
: constant Source_Ptr
:= Sloc
(N
);
3558 Bod_Stmts
: List_Id
;
3562 EH_Loc
: Source_Ptr
;
3563 -- Used for the exception handler, inserted at end of the body
3566 -- Set the source location on the exception handler only when debugging
3567 -- the expanded code (see Make_Implicit_Exception_Handler).
3569 if Debug_Generated_Code
then
3572 -- Otherwise the inserted code should not be visible to the debugger
3575 EH_Loc
:= No_Location
;
3579 Make_Defining_Identifier
(Loc
,
3580 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3581 Bod_Spec
:= Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Empty
);
3583 -- Add the following declarations:
3585 -- type poVP is access poV;
3586 -- _object : poVP := poVP (_O);
3588 -- where _O is the formal parameter associated with the concurrent
3589 -- object. These declarations are needed for Complete_Entry_Body.
3591 Add_Object_Pointer
(Loc
, Pid
, Bod_Decls
);
3593 -- Add renamings for all formals, the Protection object, discriminals,
3594 -- privals and the entry index constant for use by debugger.
3596 Add_Formal_Renamings
(Bod_Spec
, Bod_Decls
, Ent
, Loc
);
3597 Debug_Private_Data_Declarations
(Decls
);
3599 -- Put the declarations and the statements from the entry
3603 Make_Block_Statement
(Loc
,
3604 Declarations
=> Decls
,
3605 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
)));
3607 case Corresponding_Runtime_Package
(Pid
) is
3608 when System_Tasking_Protected_Objects_Entries
=>
3609 Append_To
(Bod_Stmts
,
3610 Make_Procedure_Call_Statement
(End_Loc
,
3612 New_Occurrence_Of
(RTE
(RE_Complete_Entry_Body
), Loc
),
3613 Parameter_Associations
=> New_List
(
3614 Make_Attribute_Reference
(End_Loc
,
3616 Make_Selected_Component
(End_Loc
,
3618 Make_Identifier
(End_Loc
, Name_uObject
),
3620 Make_Identifier
(End_Loc
, Name_uObject
)),
3621 Attribute_Name
=> Name_Unchecked_Access
))));
3623 when System_Tasking_Protected_Objects_Single_Entry
=>
3625 -- Historically, a call to Complete_Single_Entry_Body was
3626 -- inserted, but it was a null procedure.
3631 raise Program_Error
;
3634 -- When exceptions can not be propagated, we never need to call
3635 -- Exception_Complete_Entry_Body.
3637 if No_Exception_Handlers_Set
then
3639 Make_Subprogram_Body
(Loc
,
3640 Specification
=> Bod_Spec
,
3641 Declarations
=> Bod_Decls
,
3642 Handled_Statement_Sequence
=>
3643 Make_Handled_Sequence_Of_Statements
(Loc
,
3644 Statements
=> Bod_Stmts
,
3645 End_Label
=> End_Lab
));
3648 Ohandle
:= Make_Others_Choice
(Loc
);
3649 Set_All_Others
(Ohandle
);
3651 case Corresponding_Runtime_Package
(Pid
) is
3652 when System_Tasking_Protected_Objects_Entries
=>
3655 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3657 when System_Tasking_Protected_Objects_Single_Entry
=>
3660 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3663 raise Program_Error
;
3666 -- Establish link between subprogram body entity and source entry
3668 Set_Corresponding_Protected_Entry
(Bod_Id
, Ent
);
3670 -- Create body of entry procedure. The renaming declarations are
3671 -- placed ahead of the block that contains the actual entry body.
3674 Make_Subprogram_Body
(Loc
,
3675 Specification
=> Bod_Spec
,
3676 Declarations
=> Bod_Decls
,
3677 Handled_Statement_Sequence
=>
3678 Make_Handled_Sequence_Of_Statements
(Loc
,
3679 Statements
=> Bod_Stmts
,
3680 End_Label
=> End_Lab
,
3681 Exception_Handlers
=> New_List
(
3682 Make_Implicit_Exception_Handler
(EH_Loc
,
3683 Exception_Choices
=> New_List
(Ohandle
),
3685 Statements
=> New_List
(
3686 Make_Procedure_Call_Statement
(EH_Loc
,
3688 Parameter_Associations
=> New_List
(
3689 Make_Attribute_Reference
(EH_Loc
,
3691 Make_Selected_Component
(EH_Loc
,
3693 Make_Identifier
(EH_Loc
, Name_uObject
),
3695 Make_Identifier
(EH_Loc
, Name_uObject
)),
3696 Attribute_Name
=> Name_Unchecked_Access
),
3698 Make_Function_Call
(EH_Loc
,
3701 (RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3703 end Build_Protected_Entry
;
3705 -----------------------------------------
3706 -- Build_Protected_Entry_Specification --
3707 -----------------------------------------
3709 function Build_Protected_Entry_Specification
3712 Ent_Id
: Entity_Id
) return Node_Id
3714 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3717 Set_Debug_Info_Needed
(Def_Id
);
3719 if Present
(Ent_Id
) then
3720 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3724 Make_Procedure_Specification
(Loc
,
3725 Defining_Unit_Name
=> Def_Id
,
3726 Parameter_Specifications
=> New_List
(
3727 Make_Parameter_Specification
(Loc
,
3728 Defining_Identifier
=>
3729 Make_Defining_Identifier
(Loc
, Name_uO
),
3731 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3733 Make_Parameter_Specification
(Loc
,
3734 Defining_Identifier
=> P
,
3736 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3738 Make_Parameter_Specification
(Loc
,
3739 Defining_Identifier
=>
3740 Make_Defining_Identifier
(Loc
, Name_uE
),
3742 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))));
3743 end Build_Protected_Entry_Specification
;
3745 --------------------------
3746 -- Build_Protected_Spec --
3747 --------------------------
3749 function Build_Protected_Spec
3751 Obj_Type
: Entity_Id
;
3753 Unprotected
: Boolean := False) return List_Id
3755 Loc
: constant Source_Ptr
:= Sloc
(N
);
3758 New_Plist
: List_Id
;
3759 New_Param
: Node_Id
;
3762 New_Plist
:= New_List
;
3764 Formal
:= First_Formal
(Ident
);
3765 while Present
(Formal
) loop
3767 Make_Parameter_Specification
(Loc
,
3768 Defining_Identifier
=>
3769 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
3770 Aliased_Present
=> Aliased_Present
(Parent
(Formal
)),
3771 In_Present
=> In_Present
(Parent
(Formal
)),
3772 Out_Present
=> Out_Present
(Parent
(Formal
)),
3773 Parameter_Type
=> New_Occurrence_Of
(Etype
(Formal
), Loc
));
3776 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
3779 Append
(New_Param
, New_Plist
);
3780 Next_Formal
(Formal
);
3783 -- If the subprogram is a procedure and the context is not an access
3784 -- to protected subprogram, the parameter is in-out. Otherwise it is
3788 Make_Parameter_Specification
(Loc
,
3789 Defining_Identifier
=>
3790 Make_Defining_Identifier
(Loc
, Name_uObject
),
3793 (Etype
(Ident
) = Standard_Void_Type
3794 and then not Is_RTE
(Obj_Type
, RE_Address
)),
3796 New_Occurrence_Of
(Obj_Type
, Loc
));
3797 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
3798 Prepend_To
(New_Plist
, Decl
);
3801 end Build_Protected_Spec
;
3803 ---------------------------------------
3804 -- Build_Protected_Sub_Specification --
3805 ---------------------------------------
3807 function Build_Protected_Sub_Specification
3809 Prot_Typ
: Entity_Id
;
3810 Mode
: Subprogram_Protection_Mode
) return Node_Id
3812 Loc
: constant Source_Ptr
:= Sloc
(N
);
3816 New_Plist
: List_Id
;
3819 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
3820 (Dispatching_Mode
=> ' ',
3821 Protected_Mode
=> 'P',
3822 Unprotected_Mode
=> 'N');
3825 if Ekind
(Defining_Unit_Name
(Specification
(N
))) = E_Subprogram_Body
3827 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
3832 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
3835 Build_Protected_Spec
3836 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
3837 Mode
= Unprotected_Mode
);
3839 Make_Defining_Identifier
(Loc
,
3840 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
3842 -- Reference the original nondispatching subprogram since the analysis
3843 -- of the object.operation notation may need its original name (see
3844 -- Sem_Ch4.Names_Match).
3846 if Mode
= Dispatching_Mode
then
3847 Set_Ekind
(New_Id
, Ekind
(Def_Id
));
3848 Set_Original_Protected_Subprogram
(New_Id
, Def_Id
);
3851 -- Link the protected or unprotected version to the original subprogram
3854 Set_Ekind
(New_Id
, Ekind
(Def_Id
));
3855 Set_Protected_Subprogram
(New_Id
, Def_Id
);
3857 -- The unprotected operation carries the user code, and debugging
3858 -- information must be generated for it, even though this spec does
3859 -- not come from source. It is also convenient to allow gdb to step
3860 -- into the protected operation, even though it only contains lock/
3863 Set_Debug_Info_Needed
(New_Id
);
3865 -- If a pragma Eliminate applies to the source entity, the internal
3866 -- subprograms will be eliminated as well.
3868 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
3870 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
3872 Make_Procedure_Specification
(Loc
,
3873 Defining_Unit_Name
=> New_Id
,
3874 Parameter_Specifications
=> New_Plist
);
3876 -- Create a new specification for the anonymous subprogram type
3880 Make_Function_Specification
(Loc
,
3881 Defining_Unit_Name
=> New_Id
,
3882 Parameter_Specifications
=> New_Plist
,
3883 Result_Definition
=>
3884 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
3886 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
3890 end Build_Protected_Sub_Specification
;
3892 -------------------------------------
3893 -- Build_Protected_Subprogram_Body --
3894 -------------------------------------
3896 function Build_Protected_Subprogram_Body
3899 N_Op_Spec
: Node_Id
) return Node_Id
3901 Exc_Safe
: constant Boolean := not Might_Raise
(N
);
3902 -- True if N cannot raise an exception
3904 Loc
: constant Source_Ptr
:= Sloc
(N
);
3905 Op_Spec
: constant Node_Id
:= Specification
(N
);
3906 P_Op_Spec
: constant Node_Id
:=
3907 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
3910 Lock_Name
: Node_Id
;
3911 Lock_Stmt
: Node_Id
;
3912 Object_Parm
: Node_Id
;
3915 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
3916 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
3920 Unprot_Call
: Node_Id
;
3923 -- Build a list of the formal parameters of the protected version of
3924 -- the subprogram to use as the actual parameters of the unprotected
3927 Uactuals
:= New_List
;
3928 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
3929 while Present
(Pformal
) loop
3930 Append_To
(Uactuals
,
3931 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
3935 -- Make a call to the unprotected version of the subprogram built above
3936 -- for use by the protected version built below.
3938 if Nkind
(Op_Spec
) = N_Function_Specification
then
3940 R
:= Make_Temporary
(Loc
, 'R');
3943 Make_Object_Declaration
(Loc
,
3944 Defining_Identifier
=> R
,
3945 Constant_Present
=> True,
3946 Object_Definition
=>
3947 New_Copy
(Result_Definition
(N_Op_Spec
)),
3949 Make_Function_Call
(Loc
,
3951 Make_Identifier
(Loc
,
3952 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3953 Parameter_Associations
=> Uactuals
));
3956 Make_Simple_Return_Statement
(Loc
,
3957 Expression
=> New_Occurrence_Of
(R
, Loc
));
3961 Make_Simple_Return_Statement
(Loc
,
3963 Make_Function_Call
(Loc
,
3965 Make_Identifier
(Loc
,
3966 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3967 Parameter_Associations
=> Uactuals
));
3970 Lock_Kind
:= RE_Lock_Read_Only
;
3974 Make_Procedure_Call_Statement
(Loc
,
3976 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3977 Parameter_Associations
=> Uactuals
);
3979 Lock_Kind
:= RE_Lock
;
3982 -- Wrap call in block that will be covered by an at_end handler
3984 if not Exc_Safe
then
3986 Make_Block_Statement
(Loc
,
3987 Handled_Statement_Sequence
=>
3988 Make_Handled_Sequence_Of_Statements
(Loc
,
3989 Statements
=> New_List
(Unprot_Call
)));
3992 -- Make the protected subprogram body. This locks the protected
3993 -- object and calls the unprotected version of the subprogram.
3995 case Corresponding_Runtime_Package
(Pid
) is
3996 when System_Tasking_Protected_Objects_Entries
=>
3997 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entries
), Loc
);
3999 when System_Tasking_Protected_Objects_Single_Entry
=>
4000 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entry
), Loc
);
4002 when System_Tasking_Protected_Objects
=>
4003 Lock_Name
:= New_Occurrence_Of
(RTE
(Lock_Kind
), Loc
);
4006 raise Program_Error
;
4010 Make_Attribute_Reference
(Loc
,
4012 Make_Selected_Component
(Loc
,
4013 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4014 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4015 Attribute_Name
=> Name_Unchecked_Access
);
4018 Make_Procedure_Call_Statement
(Loc
,
4020 Parameter_Associations
=> New_List
(Object_Parm
));
4022 if Abort_Allowed
then
4024 Build_Runtime_Call
(Loc
, RE_Abort_Defer
),
4028 Stmts
:= New_List
(Lock_Stmt
);
4031 if not Exc_Safe
then
4032 Append
(Unprot_Call
, Stmts
);
4034 if Nkind
(Op_Spec
) = N_Function_Specification
then
4036 Stmts
:= Empty_List
;
4038 Append
(Unprot_Call
, Stmts
);
4041 -- Historical note: Previously, call to the cleanup was inserted
4042 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4043 -- which is also shared by the 'not Exc_Safe' path.
4045 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
4047 if Nkind
(Op_Spec
) = N_Function_Specification
then
4048 Append_To
(Stmts
, Return_Stmt
);
4049 Append_To
(Pre_Stmts
,
4050 Make_Block_Statement
(Loc
,
4051 Declarations
=> New_List
(Unprot_Call
),
4052 Handled_Statement_Sequence
=>
4053 Make_Handled_Sequence_Of_Statements
(Loc
,
4054 Statements
=> Stmts
)));
4060 Make_Subprogram_Body
(Loc
,
4061 Declarations
=> Empty_List
,
4062 Specification
=> P_Op_Spec
,
4063 Handled_Statement_Sequence
=>
4064 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4066 -- Mark this subprogram as a protected subprogram body so that the
4067 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4068 -- path as otherwise the cleanup has already been inserted.
4070 if not Exc_Safe
then
4071 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4075 end Build_Protected_Subprogram_Body
;
4077 -------------------------------------
4078 -- Build_Protected_Subprogram_Call --
4079 -------------------------------------
4081 procedure Build_Protected_Subprogram_Call
4085 External
: Boolean := True)
4087 Loc
: constant Source_Ptr
:= Sloc
(N
);
4088 Sub
: constant Entity_Id
:= Entity
(Name
);
4094 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4097 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4100 if Present
(Parameter_Associations
(N
)) then
4101 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4106 -- If the type is an untagged derived type, convert to the root type,
4107 -- which is the one on which the operations are defined.
4109 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4110 and then not Is_Tagged_Type
(Etype
(Rec
))
4111 and then Is_Derived_Type
(Etype
(Rec
))
4113 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4114 Set_Subtype_Mark
(Rec
,
4115 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4118 Prepend
(Rec
, Params
);
4120 if Ekind
(Sub
) = E_Procedure
then
4122 Make_Procedure_Call_Statement
(Loc
,
4124 Parameter_Associations
=> Params
));
4127 pragma Assert
(Ekind
(Sub
) = E_Function
);
4129 Make_Function_Call
(Loc
,
4131 Parameter_Associations
=> Params
));
4133 -- Preserve type of call for subsequent processing (required for
4134 -- call to Wrap_Transient_Expression in the case of a shared passive
4137 Set_Etype
(N
, Etype
(New_Sub
));
4141 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4142 and then Is_Entity_Name
(Expression
(Rec
))
4143 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4145 Add_Shared_Var_Lock_Procs
(N
);
4147 end Build_Protected_Subprogram_Call
;
4149 ---------------------------------------------
4150 -- Build_Protected_Subprogram_Call_Cleanup --
4151 ---------------------------------------------
4153 procedure Build_Protected_Subprogram_Call_Cleanup
4162 -- If the associated protected object has entries, a protected
4163 -- procedure has to service entry queues. In this case generate:
4165 -- Service_Entries (_object._object'Access);
4167 if Nkind
(Op_Spec
) = N_Procedure_Specification
4168 and then Has_Entries
(Conc_Typ
)
4170 case Corresponding_Runtime_Package
(Conc_Typ
) is
4171 when System_Tasking_Protected_Objects_Entries
=>
4172 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entries
), Loc
);
4174 when System_Tasking_Protected_Objects_Single_Entry
=>
4175 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entry
), Loc
);
4178 raise Program_Error
;
4182 Make_Procedure_Call_Statement
(Loc
,
4184 Parameter_Associations
=> New_List
(
4185 Make_Attribute_Reference
(Loc
,
4187 Make_Selected_Component
(Loc
,
4188 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4189 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4190 Attribute_Name
=> Name_Unchecked_Access
))));
4194 -- Unlock (_object._object'Access);
4196 case Corresponding_Runtime_Package
(Conc_Typ
) is
4197 when System_Tasking_Protected_Objects_Entries
=>
4198 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entries
), Loc
);
4200 when System_Tasking_Protected_Objects_Single_Entry
=>
4201 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entry
), Loc
);
4203 when System_Tasking_Protected_Objects
=>
4204 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock
), Loc
);
4207 raise Program_Error
;
4211 Make_Procedure_Call_Statement
(Loc
,
4213 Parameter_Associations
=> New_List
(
4214 Make_Attribute_Reference
(Loc
,
4216 Make_Selected_Component
(Loc
,
4217 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4218 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4219 Attribute_Name
=> Name_Unchecked_Access
))));
4225 if Abort_Allowed
then
4226 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4228 end Build_Protected_Subprogram_Call_Cleanup
;
4230 -------------------------
4231 -- Build_Selected_Name --
4232 -------------------------
4234 function Build_Selected_Name
4235 (Prefix
: Entity_Id
;
4236 Selector
: Entity_Id
;
4237 Append_Char
: Character := ' ') return Name_Id
4239 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4240 Select_Len
: Natural;
4243 Get_Name_String
(Chars
(Selector
));
4244 Select_Len
:= Name_Len
;
4245 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4246 Get_Name_String
(Chars
(Prefix
));
4248 -- If scope is anonymous type, discard suffix to recover name of
4249 -- single protected object. Otherwise use protected type name.
4251 if Name_Buffer
(Name_Len
) = 'T' then
4252 Name_Len
:= Name_Len
- 1;
4255 Add_Str_To_Name_Buffer
("__");
4256 for J
in 1 .. Select_Len
loop
4257 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4260 -- Now add the Append_Char if specified. The encoding to follow
4261 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4262 -- then the entity is associated to a protected type subprogram.
4263 -- Otherwise, it is a protected type entry. For each case, the
4264 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4266 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4268 if Append_Char
/= ' ' then
4269 if Append_Char
= 'P' or Append_Char
= 'N' then
4270 Add_Char_To_Name_Buffer
(Append_Char
);
4273 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4274 return New_External_Name
(Name_Find
, ' ', -1);
4279 end Build_Selected_Name
;
4281 -----------------------------
4282 -- Build_Simple_Entry_Call --
4283 -----------------------------
4285 -- A task entry call is converted to a call to Call_Simple
4288 -- P : parms := (parm, parm, parm);
4290 -- Call_Simple (acceptor-task, entry-index, P'Address);
4296 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4297 -- the parameters, and the constructed aggregate value contains either the
4298 -- parameters or, in the case of non-elementary types, references to these
4299 -- parameters. Then the address of this aggregate is passed to the runtime
4300 -- routine, along with the task id value and the task entry index value.
4301 -- Pnn is only required if parameters are present.
4303 -- The assignments after the call are present only in the case of in-out
4304 -- or out parameters for elementary types, and are used to assign back the
4305 -- resulting values of such parameters.
4307 -- Note: the reason that we insert a block here is that in the context
4308 -- of selects, conditional entry calls etc. the entry call statement
4309 -- appears on its own, not as an element of a list.
4311 -- A protected entry call is converted to a Protected_Entry_Call:
4314 -- P : E1_Params := (param, param, param);
4316 -- Bnn : Communications_Block;
4319 -- P : E1_Params := (param, param, param);
4320 -- Bnn : Communications_Block;
4323 -- Protected_Entry_Call (
4324 -- Object => po._object'Access,
4325 -- E => <entry index>;
4326 -- Uninterpreted_Data => P'Address;
4327 -- Mode => Simple_Call;
4334 procedure Build_Simple_Entry_Call
4343 -- If call has been inlined, nothing left to do
4345 if Nkind
(N
) = N_Block_Statement
then
4349 -- Convert entry call to Call_Simple call
4352 Loc
: constant Source_Ptr
:= Sloc
(N
);
4353 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4354 Stats
: constant List_Id
:= New_List
;
4357 Comm_Name
: Entity_Id
;
4361 Ent_Acc
: Entity_Id
;
4363 Iface_Tag
: Entity_Id
;
4364 Iface_Typ
: Entity_Id
;
4377 -- Simple entry and entry family cases merge here
4379 Ent
:= Entity
(Ename
);
4380 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4381 Conctyp
:= Etype
(Concval
);
4383 -- If prefix is an access type, dereference to obtain the task type
4385 if Is_Access_Type
(Conctyp
) then
4386 Conctyp
:= Designated_Type
(Conctyp
);
4389 -- Special case for protected subprogram calls
4391 if Is_Protected_Type
(Conctyp
)
4392 and then Is_Subprogram
(Entity
(Ename
))
4394 if not Is_Eliminated
(Entity
(Ename
)) then
4395 Build_Protected_Subprogram_Call
4396 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4403 -- First parameter is the Task_Id value from the task value or the
4404 -- Object from the protected object value, obtained by selecting
4405 -- the _Task_Id or _Object from the result of doing an unchecked
4406 -- conversion to convert the value to the corresponding record type.
4408 if Nkind
(Concval
) = N_Function_Call
4409 and then Is_Task_Type
(Conctyp
)
4410 and then Ada_Version
>= Ada_2005
4413 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4414 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4419 Make_Object_Declaration
(Loc
,
4420 Defining_Identifier
=> Obj
,
4421 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4422 Expression
=> ExpR
);
4423 Set_Etype
(Obj
, Conctyp
);
4424 Decls
:= New_List
(Decl
);
4425 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4432 Parm1
:= Concurrent_Ref
(Concval
);
4434 -- Second parameter is the entry index, computed by the routine
4435 -- provided for this purpose. The value of this expression is
4436 -- assigned to an intermediate variable to assure that any entry
4437 -- family index expressions are evaluated before the entry
4440 if not Is_Protected_Type
(Conctyp
)
4442 Corresponding_Runtime_Package
(Conctyp
) =
4443 System_Tasking_Protected_Objects_Entries
4445 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4448 Make_Object_Declaration
(Loc
,
4449 Defining_Identifier
=> X
,
4450 Object_Definition
=>
4451 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
4452 Expression
=> Actual_Index_Expression
(
4453 Loc
, Entity
(Ename
), Index
, Concval
));
4455 Append_To
(Decls
, Xdecl
);
4456 Parm2
:= New_Occurrence_Of
(X
, Loc
);
4463 -- The third parameter is the packaged parameters. If there are
4464 -- none, then it is just the null address, since nothing is passed.
4467 Parm3
:= New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
);
4470 -- Case of parameters present, where third argument is the address
4471 -- of a packaged record containing the required parameter values.
4474 -- First build a list of parameter values, which are references to
4475 -- objects of the parameter types.
4479 Actual
:= First_Actual
(N
);
4480 Formal
:= First_Formal
(Ent
);
4481 while Present
(Actual
) loop
4483 -- If it is a by-copy type, copy it to a new variable. The
4484 -- packaged record has a field that points to this variable.
4486 if Is_By_Copy_Type
(Etype
(Actual
)) then
4488 Make_Object_Declaration
(Loc
,
4489 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4490 Aliased_Present
=> True,
4491 Object_Definition
=>
4492 New_Occurrence_Of
(Etype
(Formal
), Loc
));
4494 -- Mark the object as not needing initialization since the
4495 -- initialization is performed separately, avoiding errors
4496 -- on cases such as formals of null-excluding access types.
4498 Set_No_Initialization
(N_Node
);
4500 -- We must make a separate assignment statement for the
4501 -- case of limited types. We cannot assign it unless the
4502 -- Assignment_OK flag is set first. An out formal of an
4503 -- access type or whose type has a Default_Value must also
4504 -- be initialized from the actual (see RM 6.4.1 (13-13.1)),
4505 -- but no constraint, predicate, or null-exclusion check is
4506 -- applied before the call.
4508 if Ekind
(Formal
) /= E_Out_Parameter
4509 or else Is_Access_Type
(Etype
(Formal
))
4511 (Is_Scalar_Type
(Etype
(Formal
))
4513 Present
(Default_Aspect_Value
(Etype
(Formal
))))
4516 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
);
4517 Set_Assignment_OK
(N_Var
);
4519 Make_Assignment_Statement
(Loc
,
4521 Expression
=> Relocate_Node
(Actual
)));
4523 -- Mark the object as internal, so we don't later reset
4524 -- No_Initialization flag in Default_Initialize_Object,
4525 -- which would lead to needless default initialization.
4526 -- We don't set this outside the if statement, because
4527 -- out scalar parameters without Default_Value do require
4528 -- default initialization if Initialize_Scalars applies.
4530 Set_Is_Internal
(Defining_Identifier
(N_Node
));
4532 -- If actual is an out parameter of a null-excluding
4533 -- access type, there is access check on entry, so set
4534 -- Suppress_Assignment_Checks on the generated statement
4535 -- that assigns the actual to the parameter block.
4537 Set_Suppress_Assignment_Checks
(Last
(Stats
));
4540 Append
(N_Node
, Decls
);
4543 Make_Attribute_Reference
(Loc
,
4544 Attribute_Name
=> Name_Unchecked_Access
,
4547 (Defining_Identifier
(N_Node
), Loc
)));
4550 -- Interface class-wide formal
4552 if Ada_Version
>= Ada_2005
4553 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4554 and then Is_Interface
(Etype
(Formal
))
4556 Iface_Typ
:= Etype
(Etype
(Formal
));
4559 -- formal_iface_type! (actual.iface_tag)'reference
4562 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4563 pragma Assert
(Present
(Iface_Tag
));
4566 Make_Reference
(Loc
,
4567 Unchecked_Convert_To
(Iface_Typ
,
4568 Make_Selected_Component
(Loc
,
4570 Relocate_Node
(Actual
),
4572 New_Occurrence_Of
(Iface_Tag
, Loc
)))));
4578 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4582 Next_Actual
(Actual
);
4583 Next_Formal_With_Extras
(Formal
);
4586 -- Now build the declaration of parameters initialized with the
4587 -- aggregate containing this constructed parameter list.
4589 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4592 Make_Object_Declaration
(Loc
,
4593 Defining_Identifier
=> P
,
4594 Object_Definition
=>
4595 New_Occurrence_Of
(Designated_Type
(Ent_Acc
), Loc
),
4597 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4600 Make_Attribute_Reference
(Loc
,
4601 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4602 Attribute_Name
=> Name_Address
);
4604 Append
(Pdecl
, Decls
);
4607 -- Now we can create the call, case of protected type
4609 if Is_Protected_Type
(Conctyp
) then
4610 case Corresponding_Runtime_Package
(Conctyp
) is
4611 when System_Tasking_Protected_Objects_Entries
=>
4613 -- Change the type of the index declaration
4615 Set_Object_Definition
(Xdecl
,
4616 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
));
4618 -- Some additional declarations for protected entry calls
4624 -- Bnn : Communications_Block;
4626 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4629 Make_Object_Declaration
(Loc
,
4630 Defining_Identifier
=> Comm_Name
,
4631 Object_Definition
=>
4633 (RTE
(RE_Communication_Block
), Loc
)));
4635 -- Some additional statements for protected entry calls
4637 -- Protected_Entry_Call
4638 -- (Object => po._object'Access,
4639 -- E => <entry index>;
4640 -- Uninterpreted_Data => P'Address;
4641 -- Mode => Simple_Call;
4645 Make_Procedure_Call_Statement
(Loc
,
4647 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
4649 Parameter_Associations
=> New_List
(
4650 Make_Attribute_Reference
(Loc
,
4651 Attribute_Name
=> Name_Unchecked_Access
,
4655 New_Occurrence_Of
(RTE
(RE_Simple_Call
), Loc
),
4656 New_Occurrence_Of
(Comm_Name
, Loc
)));
4658 when System_Tasking_Protected_Objects_Single_Entry
=>
4660 -- Protected_Single_Entry_Call
4661 -- (Object => po._object'Access,
4662 -- Uninterpreted_Data => P'Address);
4665 Make_Procedure_Call_Statement
(Loc
,
4668 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4670 Parameter_Associations
=> New_List
(
4671 Make_Attribute_Reference
(Loc
,
4672 Attribute_Name
=> Name_Unchecked_Access
,
4677 raise Program_Error
;
4680 -- Case of task type
4684 Make_Procedure_Call_Statement
(Loc
,
4686 New_Occurrence_Of
(RTE
(RE_Call_Simple
), Loc
),
4687 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4691 Append_To
(Stats
, Call
);
4693 -- If there are out or in/out parameters by copy add assignment
4694 -- statements for the result values.
4696 if Present
(Parms
) then
4697 Actual
:= First_Actual
(N
);
4698 Formal
:= First_Formal
(Ent
);
4700 Set_Assignment_OK
(Actual
);
4701 while Present
(Actual
) loop
4702 if Is_By_Copy_Type
(Etype
(Actual
))
4703 and then Ekind
(Formal
) /= E_In_Parameter
4706 Make_Assignment_Statement
(Loc
,
4707 Name
=> New_Copy
(Actual
),
4709 Make_Explicit_Dereference
(Loc
,
4710 Make_Selected_Component
(Loc
,
4711 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4713 Make_Identifier
(Loc
, Chars
(Formal
)))));
4715 -- In all cases (including limited private types) we want
4716 -- the assignment to be valid.
4718 Set_Assignment_OK
(Name
(N_Node
));
4720 -- If the call is the triggering alternative in an
4721 -- asynchronous select, or the entry_call alternative of a
4722 -- conditional entry call, the assignments for in-out
4723 -- parameters are incorporated into the statement list that
4724 -- follows, so that there are executed only if the entry
4727 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4728 and then N
= Triggering_Statement
(Parent
(N
)))
4730 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4731 and then N
= Entry_Call_Statement
(Parent
(N
)))
4733 if No
(Statements
(Parent
(N
))) then
4734 Set_Statements
(Parent
(N
), New_List
);
4737 Prepend
(N_Node
, Statements
(Parent
(N
)));
4740 Insert_After
(Call
, N_Node
);
4744 Next_Actual
(Actual
);
4745 Next_Formal_With_Extras
(Formal
);
4749 -- Finally, create block and analyze it
4752 Make_Block_Statement
(Loc
,
4753 Declarations
=> Decls
,
4754 Handled_Statement_Sequence
=>
4755 Make_Handled_Sequence_Of_Statements
(Loc
,
4756 Statements
=> Stats
)));
4760 end Build_Simple_Entry_Call
;
4762 --------------------------------
4763 -- Build_Task_Activation_Call --
4764 --------------------------------
4766 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4767 function Activation_Call_Loc
return Source_Ptr
;
4768 -- Find a suitable source location for the activation call
4770 -------------------------
4771 -- Activation_Call_Loc --
4772 -------------------------
4774 function Activation_Call_Loc
return Source_Ptr
is
4776 -- The activation call must carry the location of the "end" keyword
4777 -- when the context is a package declaration.
4779 if Nkind
(N
) = N_Package_Declaration
then
4780 return End_Keyword_Location
(N
);
4782 -- Otherwise the activation call must carry the location of the
4786 return Begin_Keyword_Location
(N
);
4788 end Activation_Call_Loc
;
4799 -- Start of processing for Build_Task_Activation_Call
4802 -- For sequential elaboration policy, all the tasks will be activated at
4803 -- the end of the elaboration.
4805 if Partition_Elaboration_Policy
= 'S' then
4808 -- Do not create an activation call for a package spec if the package
4809 -- has a completing body. The activation call will be inserted after
4810 -- the "begin" of the body.
4812 elsif Nkind
(N
) = N_Package_Declaration
4813 and then Present
(Corresponding_Body
(N
))
4818 -- Obtain the activation chain entity. Block statements, entry bodies,
4819 -- subprogram bodies, and task bodies keep the entity in their nodes.
4820 -- Package bodies on the other hand store it in the declaration of the
4821 -- corresponding package spec.
4825 if Nkind
(Owner
) = N_Package_Body
then
4826 Owner
:= Unit_Declaration_Node
(Corresponding_Spec
(Owner
));
4829 Chain
:= Activation_Chain_Entity
(Owner
);
4831 -- Nothing to do when there are no tasks to activate. This is indicated
4832 -- by a missing activation chain entity.
4838 -- The location of the activation call must be as close as possible to
4839 -- the intended semantic location of the activation because the ABE
4840 -- mechanism relies heavily on accurate locations.
4842 Loc
:= Activation_Call_Loc
;
4844 if Restricted_Profile
then
4845 Name
:= New_Occurrence_Of
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4847 Name
:= New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
);
4851 Make_Procedure_Call_Statement
(Loc
,
4853 Parameter_Associations
=>
4854 New_List
(Make_Attribute_Reference
(Loc
,
4855 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4856 Attribute_Name
=> Name_Unchecked_Access
)));
4858 if Nkind
(N
) = N_Package_Declaration
then
4859 if Present
(Private_Declarations
(Specification
(N
))) then
4860 Append
(Call
, Private_Declarations
(Specification
(N
)));
4862 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4866 -- The call goes at the start of the statement sequence after the
4867 -- start of exception range label if one is present.
4869 if Present
(Handled_Statement_Sequence
(N
)) then
4870 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4872 -- A special case, skip exception range label if one is present
4873 -- (from front end zcx processing).
4875 if Nkind
(Stmt
) = N_Label
and then Exception_Junk
(Stmt
) then
4879 -- Another special case, if the first statement is a block from
4880 -- optimization of a local raise to a goto, then the call goes
4881 -- inside this block.
4883 if Nkind
(Stmt
) = N_Block_Statement
4884 and then Exception_Junk
(Stmt
)
4886 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
4889 -- Insertion point is after any exception label pushes, since we
4890 -- want it covered by any local handlers.
4892 while Nkind
(Stmt
) in N_Push_xxx_Label
loop
4896 -- Now we have the proper insertion point
4898 Insert_Before
(Stmt
, Call
);
4901 Set_Handled_Statement_Sequence
(N
,
4902 Make_Handled_Sequence_Of_Statements
(Loc
,
4903 Statements
=> New_List
(Call
)));
4908 end Build_Task_Activation_Call
;
4910 -------------------------------
4911 -- Build_Task_Allocate_Block --
4912 -------------------------------
4914 procedure Build_Task_Allocate_Block
4919 T
: constant Entity_Id
:= Entity
(Expression
(N
));
4920 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
4921 Loc
: constant Source_Ptr
:= Sloc
(N
);
4922 Chain
: constant Entity_Id
:=
4923 Make_Defining_Identifier
(Loc
, Name_uChain
);
4924 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4929 Make_Block_Statement
(Loc
,
4930 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4931 Declarations
=> New_List
(
4933 -- _Chain : Activation_Chain;
4935 Make_Object_Declaration
(Loc
,
4936 Defining_Identifier
=> Chain
,
4937 Aliased_Present
=> True,
4938 Object_Definition
=>
4939 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4941 Handled_Statement_Sequence
=>
4942 Make_Handled_Sequence_Of_Statements
(Loc
,
4944 Statements
=> New_List
(
4948 Make_Procedure_Call_Statement
(Loc
,
4949 Name
=> New_Occurrence_Of
(Init
, Loc
),
4950 Parameter_Associations
=> Args
),
4952 -- Activate_Tasks (_Chain);
4954 Make_Procedure_Call_Statement
(Loc
,
4955 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4956 Parameter_Associations
=> New_List
(
4957 Make_Attribute_Reference
(Loc
,
4958 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4959 Attribute_Name
=> Name_Unchecked_Access
))))),
4961 Has_Created_Identifier
=> True,
4962 Is_Task_Allocation_Block
=> True);
4965 Make_Implicit_Label_Declaration
(Loc
,
4966 Defining_Identifier
=> Blkent
,
4967 Label_Construct
=> Block
));
4969 Append_To
(Actions
, Block
);
4971 Set_Activation_Chain_Entity
(Block
, Chain
);
4972 end Build_Task_Allocate_Block
;
4974 -----------------------------------------------
4975 -- Build_Task_Allocate_Block_With_Init_Stmts --
4976 -----------------------------------------------
4978 procedure Build_Task_Allocate_Block_With_Init_Stmts
4981 Init_Stmts
: List_Id
)
4983 Loc
: constant Source_Ptr
:= Sloc
(N
);
4984 Chain
: constant Entity_Id
:=
4985 Make_Defining_Identifier
(Loc
, Name_uChain
);
4986 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4990 Append_To
(Init_Stmts
,
4991 Make_Procedure_Call_Statement
(Loc
,
4992 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4993 Parameter_Associations
=> New_List
(
4994 Make_Attribute_Reference
(Loc
,
4995 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4996 Attribute_Name
=> Name_Unchecked_Access
))));
4999 Make_Block_Statement
(Loc
,
5000 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
5001 Declarations
=> New_List
(
5003 -- _Chain : Activation_Chain;
5005 Make_Object_Declaration
(Loc
,
5006 Defining_Identifier
=> Chain
,
5007 Aliased_Present
=> True,
5008 Object_Definition
=>
5009 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
5011 Handled_Statement_Sequence
=>
5012 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5014 Has_Created_Identifier
=> True,
5015 Is_Task_Allocation_Block
=> True);
5018 Make_Implicit_Label_Declaration
(Loc
,
5019 Defining_Identifier
=> Blkent
,
5020 Label_Construct
=> Block
));
5022 Append_To
(Actions
, Block
);
5024 Set_Activation_Chain_Entity
(Block
, Chain
);
5025 end Build_Task_Allocate_Block_With_Init_Stmts
;
5027 -----------------------------------
5028 -- Build_Task_Proc_Specification --
5029 -----------------------------------
5031 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5032 Loc
: constant Source_Ptr
:= Sloc
(T
);
5033 Spec_Id
: Entity_Id
;
5036 -- Case of explicit task type, suffix TB
5038 if Comes_From_Source
(T
) then
5040 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
5042 -- Case of anonymous task type, suffix B
5046 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
5049 Set_Is_Internal
(Spec_Id
);
5051 -- Associate the procedure with the task, if this is the declaration
5052 -- (and not the body) of the procedure.
5054 if No
(Task_Body_Procedure
(T
)) then
5055 Set_Task_Body_Procedure
(T
, Spec_Id
);
5059 Make_Procedure_Specification
(Loc
,
5060 Defining_Unit_Name
=> Spec_Id
,
5061 Parameter_Specifications
=> New_List
(
5062 Make_Parameter_Specification
(Loc
,
5063 Defining_Identifier
=>
5064 Make_Defining_Identifier
(Loc
, Name_uTask
),
5066 Make_Access_Definition
(Loc
,
5068 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
5069 end Build_Task_Proc_Specification
;
5071 ---------------------------------------
5072 -- Build_Unprotected_Subprogram_Body --
5073 ---------------------------------------
5075 function Build_Unprotected_Subprogram_Body
5077 Pid
: Node_Id
) return Node_Id
5079 Decls
: constant List_Id
:= Declarations
(N
);
5082 -- Add renamings for the Protection object, discriminals, privals, and
5083 -- the entry index constant for use by debugger.
5085 Debug_Private_Data_Declarations
(Decls
);
5087 -- Make an unprotected version of the subprogram for use within the same
5088 -- object, with a new name and an additional parameter representing the
5092 Make_Subprogram_Body
(Sloc
(N
),
5094 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5095 Declarations
=> Decls
,
5096 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5097 end Build_Unprotected_Subprogram_Body
;
5099 ----------------------------
5100 -- Collect_Entry_Families --
5101 ----------------------------
5103 procedure Collect_Entry_Families
5106 Current_Node
: in out Node_Id
;
5107 Conctyp
: Entity_Id
)
5110 Efam_Decl
: Node_Id
;
5111 Efam_Type
: Entity_Id
;
5114 Efam
:= First_Entity
(Conctyp
);
5115 while Present
(Efam
) loop
5116 if Ekind
(Efam
) = E_Entry_Family
then
5117 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5122 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5124 Bas_Decl
: Node_Id
:= Empty
;
5129 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5131 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5132 Bas
:= Make_Temporary
(Loc
, 'B');
5135 Make_Subtype_Declaration
(Loc
,
5136 Defining_Identifier
=> Bas
,
5137 Subtype_Indication
=>
5138 Make_Subtype_Indication
(Loc
,
5140 New_Occurrence_Of
(Standard_Integer
, Loc
),
5142 Make_Range_Constraint
(Loc
,
5143 Range_Expression
=> Make_Range
(Loc
,
5144 Make_Integer_Literal
5145 (Loc
, -Entry_Family_Bound
),
5146 Make_Integer_Literal
5147 (Loc
, Entry_Family_Bound
- 1)))));
5149 Insert_After
(Current_Node
, Bas_Decl
);
5150 Current_Node
:= Bas_Decl
;
5155 Make_Full_Type_Declaration
(Loc
,
5156 Defining_Identifier
=> Efam_Type
,
5158 Make_Unconstrained_Array_Definition
(Loc
,
5160 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5162 Component_Definition
=>
5163 Make_Component_Definition
(Loc
,
5164 Aliased_Present
=> False,
5165 Subtype_Indication
=>
5166 New_Occurrence_Of
(Standard_Character
, Loc
))));
5169 Insert_After
(Current_Node
, Efam_Decl
);
5170 Current_Node
:= Efam_Decl
;
5171 Analyze
(Efam_Decl
);
5174 Make_Component_Declaration
(Loc
,
5175 Defining_Identifier
=>
5176 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5178 Component_Definition
=>
5179 Make_Component_Definition
(Loc
,
5180 Aliased_Present
=> False,
5181 Subtype_Indication
=>
5182 Make_Subtype_Indication
(Loc
,
5184 New_Occurrence_Of
(Efam_Type
, Loc
),
5187 Make_Index_Or_Discriminant_Constraint
(Loc
,
5188 Constraints
=> New_List
(
5190 (Etype
(Discrete_Subtype_Definition
5191 (Parent
(Efam
))), Loc
)))))));
5197 end Collect_Entry_Families
;
5199 -----------------------
5200 -- Concurrent_Object --
5201 -----------------------
5203 function Concurrent_Object
5204 (Spec_Id
: Entity_Id
;
5205 Conc_Typ
: Entity_Id
) return Entity_Id
5208 -- Parameter _O or _object
5210 if Is_Protected_Type
(Conc_Typ
) then
5211 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5216 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5217 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5219 end Concurrent_Object
;
5221 ----------------------
5222 -- Copy_Result_Type --
5223 ----------------------
5225 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5226 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5231 -- If the result type is an access_to_subprogram, we must create new
5232 -- entities for its spec.
5234 if Nkind
(New_Res
) = N_Access_Definition
5235 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5237 -- Provide new entities for the formals
5239 Par_Spec
:= First
(Parameter_Specifications
5240 (Access_To_Subprogram_Definition
(New_Res
)));
5241 while Present
(Par_Spec
) loop
5242 Formal
:= Defining_Identifier
(Par_Spec
);
5243 Set_Defining_Identifier
(Par_Spec
,
5244 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5250 end Copy_Result_Type
;
5252 --------------------
5253 -- Concurrent_Ref --
5254 --------------------
5256 -- The expression returned for a reference to a concurrent object has the
5259 -- taskV!(name)._Task_Id
5263 -- objectV!(name)._Object
5265 -- for a protected object. For the case of an access to a concurrent
5266 -- object, there is an extra explicit dereference:
5268 -- taskV!(name.all)._Task_Id
5269 -- objectV!(name.all)._Object
5271 -- here taskV and objectV are the types for the associated records, which
5272 -- contain the required _Task_Id and _Object fields for tasks and protected
5273 -- objects, respectively.
5275 -- For the case of a task type name, the expression is
5279 -- i.e. a call to the Self function which returns precisely this Task_Id
5281 -- For the case of a protected type name, the expression is
5285 -- which is a renaming of the _object field of the current object
5286 -- record, passed into protected operations as a parameter.
5288 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5289 Loc
: constant Source_Ptr
:= Sloc
(N
);
5290 Ntyp
: constant Entity_Id
:= Etype
(N
);
5294 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5295 -- Check whether the reference is to the immediately enclosing task
5296 -- type, or to an outer one (rare but legal).
5298 ---------------------
5299 -- Is_Current_Task --
5300 ---------------------
5302 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5306 Scop
:= Current_Scope
;
5307 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
5311 elsif Is_Task_Type
(Scop
) then
5314 -- If this is a procedure nested within the task type, we must
5315 -- assume that it can be called from an inner task, and therefore
5316 -- cannot treat it as a local reference.
5318 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5322 Scop
:= Scope
(Scop
);
5326 -- We know that we are within the task body, so should have found it
5329 raise Program_Error
;
5330 end Is_Current_Task
;
5332 -- Start of processing for Concurrent_Ref
5335 if Is_Access_Type
(Ntyp
) then
5336 Dtyp
:= Designated_Type
(Ntyp
);
5338 if Is_Protected_Type
(Dtyp
) then
5339 Sel
:= Name_uObject
;
5341 Sel
:= Name_uTask_Id
;
5345 Make_Selected_Component
(Loc
,
5347 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5348 Make_Explicit_Dereference
(Loc
, N
)),
5349 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5351 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5352 if Is_Task_Type
(Entity
(N
)) then
5354 if Is_Current_Task
(Entity
(N
)) then
5356 Make_Function_Call
(Loc
,
5357 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5362 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5363 T_Body
: constant Node_Id
:=
5364 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5368 Make_Object_Declaration
(Loc
,
5369 Defining_Identifier
=> T_Self
,
5370 Object_Definition
=>
5371 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5373 Make_Function_Call
(Loc
,
5374 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5375 Prepend
(Decl
, Declarations
(T_Body
));
5377 Set_Scope
(T_Self
, Entity
(N
));
5378 return New_Occurrence_Of
(T_Self
, Loc
);
5383 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5386 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5390 if Is_Protected_Type
(Ntyp
) then
5391 Sel
:= Name_uObject
;
5392 elsif Is_Task_Type
(Ntyp
) then
5393 Sel
:= Name_uTask_Id
;
5395 raise Program_Error
;
5399 Make_Selected_Component
(Loc
,
5401 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5403 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5407 ------------------------
5408 -- Convert_Concurrent --
5409 ------------------------
5411 function Convert_Concurrent
5413 Typ
: Entity_Id
) return Node_Id
5416 if not Is_Concurrent_Type
(Typ
) then
5420 Unchecked_Convert_To
5421 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5423 end Convert_Concurrent
;
5425 -------------------------------------
5426 -- Create_Secondary_Stack_For_Task --
5427 -------------------------------------
5429 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean is
5432 (Restriction_Active
(No_Implicit_Heap_Allocations
)
5433 or else Restriction_Active
(No_Implicit_Task_Allocations
))
5434 and then not Restriction_Active
(No_Secondary_Stack
)
5435 and then Has_Rep_Item
5436 (T
, Name_Secondary_Stack_Size
, Check_Parents
=> False);
5437 end Create_Secondary_Stack_For_Task
;
5439 -------------------------------------
5440 -- Debug_Private_Data_Declarations --
5441 -------------------------------------
5443 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5444 Debug_Nod
: Node_Id
;
5448 Decl
:= First
(Decls
);
5449 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5451 -- Declaration for concurrent entity _object and its access type,
5452 -- along with the entry index subtype:
5453 -- type prot_typVP is access prot_typV;
5454 -- _object : prot_typVP := prot_typV (_O);
5455 -- subtype Jnn is <Type of Index> range Low .. High;
5457 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5458 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5460 -- Declaration for the Protection object, discriminals, privals, and
5461 -- entry index constant:
5462 -- conc_typR : protection_typ renames _object._object;
5463 -- discr_nameD : discr_typ renames _object.discr_name;
5464 -- discr_nameD : discr_typ renames _task.discr_name;
5465 -- prival_name : comp_typ renames _object.comp_name;
5466 -- J : constant Jnn :=
5467 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5469 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5470 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5471 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5473 if Present
(Debug_Nod
) then
5474 Insert_After
(Decl
, Debug_Nod
);
5480 end Debug_Private_Data_Declarations
;
5482 ------------------------------
5483 -- Ensure_Statement_Present --
5484 ------------------------------
5486 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5490 if Opt
.Suppress_Control_Flow_Optimizations
5491 and then Is_Empty_List
(Statements
(Alt
))
5493 Stmt
:= Make_Null_Statement
(Loc
);
5495 -- Mark NULL statement as coming from source so that it is not
5496 -- eliminated by GIGI.
5498 -- Another covert channel. If this is a requirement, it must be
5499 -- documented in sinfo/einfo ???
5501 Set_Comes_From_Source
(Stmt
, True);
5503 Set_Statements
(Alt
, New_List
(Stmt
));
5505 end Ensure_Statement_Present
;
5507 ----------------------------
5508 -- Entry_Index_Expression --
5509 ----------------------------
5511 function Entry_Index_Expression
5515 Ttyp
: Entity_Id
) return Node_Id
5525 -- The queues of entries and entry families appear in textual order in
5526 -- the associated record. The entry index is computed as the sum of the
5527 -- number of queues for all entries that precede the designated one, to
5528 -- which is added the index expression, if this expression denotes a
5529 -- member of a family.
5531 -- The following is a place holder for the count of simple entries
5533 Num
:= Make_Integer_Literal
(Sloc
, 1);
5535 -- We construct an expression which is a series of addition operations.
5536 -- The first operand is the number of single entries that precede this
5537 -- one, the second operand is the index value relative to the start of
5538 -- the referenced family, and the remaining operands are the lengths of
5539 -- the entry families that precede this entry, i.e. the constructed
5542 -- number_simple_entries +
5543 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5544 -- family'length + ...
5546 -- where index-value is the given index value, and s is the index
5547 -- subtype (we have to use pos because the subtype might be an
5548 -- enumeration type preventing direct subtraction). Note that the task
5549 -- entry array is one-indexed.
5551 -- The upper bound of the entry family may be a discriminant, so we
5552 -- retrieve the lower bound explicitly to compute offset, rather than
5553 -- using the index subtype which may mention a discriminant.
5555 if Present
(Index
) then
5556 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5564 Make_Attribute_Reference
(Sloc
,
5565 Attribute_Name
=> Name_Pos
,
5566 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5567 Expressions
=> New_List
(Relocate_Node
(Index
))),
5575 -- Now add lengths of preceding entries and entry families
5577 Prev
:= First_Entity
(Ttyp
);
5578 while Chars
(Prev
) /= Chars
(Ent
)
5579 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5580 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5582 if Ekind
(Prev
) = E_Entry
then
5583 Set_Intval
(Num
, Intval
(Num
) + 1);
5585 elsif Ekind
(Prev
) = E_Entry_Family
then
5586 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5587 Lo
:= Type_Low_Bound
(S
);
5588 Hi
:= Type_High_Bound
(S
);
5593 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5595 -- Other components are anonymous types to be ignored
5605 end Entry_Index_Expression
;
5607 ---------------------------
5608 -- Establish_Task_Master --
5609 ---------------------------
5611 procedure Establish_Task_Master
(N
: Node_Id
) is
5615 if Restriction_Active
(No_Task_Hierarchy
) = False then
5616 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5618 -- The block may have no declarations (and nevertheless be a task
5619 -- master) if it contains a call that may return an object that
5622 if No
(Declarations
(N
)) then
5623 Set_Declarations
(N
, New_List
(Call
));
5625 Prepend_To
(Declarations
(N
), Call
);
5630 end Establish_Task_Master
;
5632 --------------------------------
5633 -- Expand_Accept_Declarations --
5634 --------------------------------
5636 -- Part of the expansion of an accept statement involves the creation of
5637 -- a declaration that can be referenced from the statement sequence of
5642 -- This declaration is inserted immediately before the accept statement
5643 -- and it is important that it be inserted before the statements of the
5644 -- statement sequence are analyzed. Thus it would be too late to create
5645 -- this declaration in the Expand_N_Accept_Statement routine, which is
5646 -- why there is a separate procedure to be called directly from Sem_Ch9.
5648 -- Ann is used to hold the address of the record containing the parameters
5649 -- (see Expand_N_Entry_Call for more details on how this record is built).
5650 -- References to the parameters do an unchecked conversion of this address
5651 -- to a pointer to the required record type, and then access the field that
5652 -- holds the value of the required parameter. The entity for the address
5653 -- variable is held as the top stack element (i.e. the last element) of the
5654 -- Accept_Address stack in the corresponding entry entity, and this element
5655 -- must be set in place before the statements are processed.
5657 -- The above description applies to the case of a stand alone accept
5658 -- statement, i.e. one not appearing as part of a select alternative.
5660 -- For the case of an accept that appears as part of a select alternative
5661 -- of a selective accept, we must still create the declaration right away,
5662 -- since Ann is needed immediately, but there is an important difference:
5664 -- The declaration is inserted before the selective accept, not before
5665 -- the accept statement (which is not part of a list anyway, and so would
5666 -- not accommodate inserted declarations)
5668 -- We only need one address variable for the entire selective accept. So
5669 -- the Ann declaration is created only for the first accept alternative,
5670 -- and subsequent accept alternatives reference the same Ann variable.
5672 -- We can distinguish the two cases by seeing whether the accept statement
5673 -- is part of a list. If not, then it must be in an accept alternative.
5675 -- To expand the requeue statement, a label is provided at the end of the
5676 -- accept statement or alternative of which it is a part, so that the
5677 -- statement can be skipped after the requeue is complete. This label is
5678 -- created here rather than during the expansion of the accept statement,
5679 -- because it will be needed by any requeue statements within the accept,
5680 -- which are expanded before the accept.
5682 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5683 Loc
: constant Source_Ptr
:= Sloc
(N
);
5684 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5685 Ann
: Entity_Id
:= Empty
;
5692 if Expander_Active
then
5694 -- If we have no handled statement sequence, we may need to build
5695 -- a dummy sequence consisting of a null statement. This can be
5696 -- skipped if the trivial accept optimization is permitted.
5698 if not Trivial_Accept_OK
5699 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5701 Set_Handled_Statement_Sequence
(N
,
5702 Make_Handled_Sequence_Of_Statements
(Loc
,
5703 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5706 -- Create and declare two labels to be placed at the end of the
5707 -- accept statement. The first label is used to allow requeues to
5708 -- skip the remainder of entry processing. The second label is used
5709 -- to skip the remainder of entry processing if the rendezvous
5710 -- completes in the middle of the accept body.
5712 if Present
(Handled_Statement_Sequence
(N
)) then
5717 Ent
:= Make_Temporary
(Loc
, 'L');
5718 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5720 Make_Implicit_Label_Declaration
(Loc
,
5721 Defining_Identifier
=> Ent
,
5722 Label_Construct
=> Lab
);
5723 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5725 Ent
:= Make_Temporary
(Loc
, 'L');
5726 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5728 Make_Implicit_Label_Declaration
(Loc
,
5729 Defining_Identifier
=> Ent
,
5730 Label_Construct
=> Lab
);
5731 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5739 -- Case of stand alone accept statement
5741 if Is_List_Member
(N
) then
5743 if Present
(Handled_Statement_Sequence
(N
)) then
5744 Ann
:= Make_Temporary
(Loc
, 'A');
5747 Make_Object_Declaration
(Loc
,
5748 Defining_Identifier
=> Ann
,
5749 Object_Definition
=>
5750 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5752 Insert_Before_And_Analyze
(N
, Adecl
);
5753 Insert_Before_And_Analyze
(N
, Ldecl
);
5754 Insert_Before_And_Analyze
(N
, Ldecl2
);
5757 -- Case of accept statement which is in an accept alternative
5761 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5762 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5766 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5767 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5769 -- ??? Consider a single label for select statements
5771 if Present
(Handled_Statement_Sequence
(N
)) then
5773 Statements
(Handled_Statement_Sequence
(N
)));
5777 Statements
(Handled_Statement_Sequence
(N
)));
5781 -- Find first accept alternative of the selective accept. A
5782 -- valid selective accept must have at least one accept in it.
5784 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5786 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5790 -- If this is the first accept statement, then we have to
5791 -- create the Ann variable, as for the stand alone case, except
5792 -- that it is inserted before the selective accept. Similarly,
5793 -- a label for requeue expansion must be declared.
5795 if N
= Accept_Statement
(Alt
) then
5796 Ann
:= Make_Temporary
(Loc
, 'A');
5798 Make_Object_Declaration
(Loc
,
5799 Defining_Identifier
=> Ann
,
5800 Object_Definition
=>
5801 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5803 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5805 -- If this is not the first accept statement, then find the Ann
5806 -- variable allocated by the first accept and use it.
5810 Node
(Last_Elmt
(Accept_Address
5811 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5816 -- Merge here with Ann either created or referenced, and Adecl
5817 -- pointing to the corresponding declaration. Remaining processing
5818 -- is the same for the two cases.
5820 if Present
(Ann
) then
5821 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5822 Set_Debug_Info_Needed
(Ann
);
5825 -- Create renaming declarations for the entry formals. Each reference
5826 -- to a formal becomes a dereference of a component of the parameter
5827 -- block, whose address is held in Ann. These declarations are
5828 -- eventually inserted into the accept block, and analyzed there so
5829 -- that they have the proper scope for gdb and do not conflict with
5830 -- other declarations.
5832 if Present
(Parameter_Specifications
(N
))
5833 and then Present
(Handled_Statement_Sequence
(N
))
5840 Renamed_Formal
: Node_Id
;
5844 Formal
:= First_Formal
(Ent
);
5846 while Present
(Formal
) loop
5847 Comp
:= Entry_Component
(Formal
);
5848 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5850 Set_Etype
(New_F
, Etype
(Formal
));
5851 Set_Scope
(New_F
, Ent
);
5853 -- Now we set debug info needed on New_F even though it does
5854 -- not come from source, so that the debugger will get the
5855 -- right information for these generated names.
5857 Set_Debug_Info_Needed
(New_F
);
5859 if Ekind
(Formal
) = E_In_Parameter
then
5860 Set_Ekind
(New_F
, E_Constant
);
5862 Set_Ekind
(New_F
, E_Variable
);
5863 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5866 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5869 Make_Selected_Component
(Loc
,
5871 Unchecked_Convert_To
(
5872 Entry_Parameters_Type
(Ent
),
5873 New_Occurrence_Of
(Ann
, Loc
)),
5875 New_Occurrence_Of
(Comp
, Loc
));
5878 Build_Renamed_Formal_Declaration
5879 (New_F
, Formal
, Comp
, Renamed_Formal
);
5881 if No
(Declarations
(N
)) then
5882 Set_Declarations
(N
, New_List
);
5885 Append
(Decl
, Declarations
(N
));
5886 Set_Renamed_Object
(Formal
, New_F
);
5887 Next_Formal
(Formal
);
5894 end Expand_Accept_Declarations
;
5896 ---------------------------------------------
5897 -- Expand_Access_Protected_Subprogram_Type --
5898 ---------------------------------------------
5900 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5901 Loc
: constant Source_Ptr
:= Sloc
(N
);
5902 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5903 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5904 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5905 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5906 P_List
: constant List_Id
:=
5907 Build_Protected_Spec
(N
, RTE
(RE_Address
), D_T
, False);
5915 -- Create access to subprogram with full signature
5917 if Etype
(D_T
) /= Standard_Void_Type
then
5919 Make_Access_Function_Definition
(Loc
,
5920 Parameter_Specifications
=> P_List
,
5921 Result_Definition
=>
5922 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5926 Make_Access_Procedure_Definition
(Loc
,
5927 Parameter_Specifications
=> P_List
);
5931 Make_Full_Type_Declaration
(Loc
,
5932 Defining_Identifier
=> D_T2
,
5933 Type_Definition
=> Def1
);
5935 -- Declare the new types before the original one since the latter will
5936 -- refer to them through the Equivalent_Type slot.
5938 Insert_Before_And_Analyze
(N
, Decl1
);
5940 -- Associate the access to subprogram with its original access to
5941 -- protected subprogram type. Needed by the backend to know that this
5942 -- type corresponds with an access to protected subprogram type.
5944 Set_Original_Access_Type
(D_T2
, T
);
5946 -- Create Equivalent_Type, a record with two components for an access to
5947 -- object and an access to subprogram.
5950 Make_Component_Declaration
(Loc
,
5951 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5952 Component_Definition
=>
5953 Make_Component_Definition
(Loc
,
5954 Aliased_Present
=> False,
5955 Subtype_Indication
=>
5956 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5958 Make_Component_Declaration
(Loc
,
5959 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5960 Component_Definition
=>
5961 Make_Component_Definition
(Loc
,
5962 Aliased_Present
=> False,
5963 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5966 Make_Full_Type_Declaration
(Loc
,
5967 Defining_Identifier
=> E_T
,
5969 Make_Record_Definition
(Loc
,
5971 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
5973 Insert_Before_And_Analyze
(N
, Decl2
);
5974 Set_Equivalent_Type
(T
, E_T
);
5975 end Expand_Access_Protected_Subprogram_Type
;
5977 --------------------------
5978 -- Expand_Entry_Barrier --
5979 --------------------------
5981 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5982 Cond
: constant Node_Id
:= Condition
(Entry_Body_Formal_Part
(N
));
5983 Prot
: constant Entity_Id
:= Scope
(Ent
);
5984 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5986 Func_Id
: Entity_Id
:= Empty
;
5987 -- The entity of the barrier function
5989 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
5990 -- Check whether entity in Barrier is external to protected type.
5991 -- If so, barrier may not be properly synchronized.
5993 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
;
5994 -- Check whether N follows the Pure_Barriers restriction. Return OK if
5997 function Is_Simple_Barrier_Name
(N
: Node_Id
) return Boolean;
5998 -- Check whether entity name N denotes a component of the protected
5999 -- object. This is used to check the Simple_Barrier restriction.
6001 ----------------------
6002 -- Is_Global_Entity --
6003 ----------------------
6005 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
6010 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
6014 if Ekind
(E
) = E_Variable
then
6016 -- If the variable is local to the barrier function generated
6017 -- during expansion, it is ok. If expansion is not performed,
6018 -- then Func is Empty so this test cannot succeed.
6020 if Scope
(E
) = Func_Id
then
6023 -- A protected call from a barrier to another object is ok
6025 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
6028 -- If the variable is within the package body we consider
6029 -- this safe. This is a common (if dubious) idiom.
6031 elsif S
= Scope
(Prot
)
6032 and then Ekind_In
(S
, E_Package
, E_Generic_Package
)
6033 and then Nkind
(Parent
(E
)) = N_Object_Declaration
6034 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
6039 Error_Msg_N
("potentially unsynchronized barrier??", N
);
6040 Error_Msg_N
("\& should be private component of type??", N
);
6046 end Is_Global_Entity
;
6048 procedure Check_Unprotected_Barrier
is
6049 new Traverse_Proc
(Is_Global_Entity
);
6051 ----------------------------
6052 -- Is_Simple_Barrier_Name --
6053 ----------------------------
6055 function Is_Simple_Barrier_Name
(N
: Node_Id
) return Boolean is
6059 -- Check if the name is a component of the protected object. If
6060 -- the expander is active, the component has been transformed into a
6061 -- renaming of _object.all.component. Original_Node is needed in case
6062 -- validity checking is enabled, in which case the simple object
6063 -- reference will have been rewritten.
6065 if Expander_Active
then
6067 -- The expanded name may have been constant folded in which case
6068 -- the original node is not necessarily an entity name (e.g. an
6069 -- indexed component).
6071 if not Is_Entity_Name
(Original_Node
(N
)) then
6075 Renamed
:= Renamed_Object
(Entity
(Original_Node
(N
)));
6079 and then Nkind
(Renamed
) = N_Selected_Component
6080 and then Chars
(Prefix
(Prefix
(Renamed
))) = Name_uObject
;
6082 return Is_Protected_Component
(Entity
(N
));
6084 end Is_Simple_Barrier_Name
;
6086 ---------------------
6087 -- Is_Pure_Barrier --
6088 ---------------------
6090 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
is
6093 when N_Expanded_Name
6096 if No
(Entity
(N
)) then
6099 elsif Is_Universal_Numeric_Type
(Entity
(N
)) then
6103 case Ekind
(Entity
(N
)) is
6106 | E_Enumeration_Literal
6116 if Is_Simple_Barrier_Name
(N
) then
6122 -- The count attribute has been transformed into run-time
6125 if Is_RTE
(Entity
(N
), RE_Protected_Count
)
6126 or else Is_RTE
(Entity
(N
), RE_Protected_Count_Entry
)
6135 when N_Function_Call
=>
6137 -- Function call checks are carried out as part of the analysis
6138 -- of the function call name.
6142 when N_Character_Literal
6151 if Ekind
(Entity
(N
)) = E_Operator
then
6155 when N_Short_Circuit
=>
6158 when N_Indexed_Component
6159 | N_Selected_Component
6161 if not Is_Access_Type
(Etype
(Prefix
(N
))) then
6165 when N_Type_Conversion
=>
6167 -- Conversions to Universal_Integer will not raise constraint
6170 if Cannot_Raise_Constraint_Error
(N
)
6171 or else Etype
(N
) = Universal_Integer
6176 when N_Unchecked_Type_Conversion
=>
6184 end Is_Pure_Barrier
;
6186 function Check_Pure_Barriers
is new Traverse_Func
(Is_Pure_Barrier
);
6190 Cond_Id
: Entity_Id
;
6191 Entry_Body
: Node_Id
;
6192 Func_Body
: Node_Id
:= Empty
;
6194 -- Start of processing for Expand_Entry_Barrier
6197 if No_Run_Time_Mode
then
6198 Error_Msg_CRT
("entry barrier", N
);
6202 -- The body of the entry barrier must be analyzed in the context of the
6203 -- protected object, but its scope is external to it, just as any other
6204 -- unprotected version of a protected operation. The specification has
6205 -- been produced when the protected type declaration was elaborated. We
6206 -- build the body, insert it in the enclosing scope, but analyze it in
6207 -- the current context. A more uniform approach would be to treat the
6208 -- barrier just as a protected function, and discard the protected
6209 -- version of it because it is never called.
6211 if Expander_Active
then
6212 Func_Body
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6213 Func_Id
:= Barrier_Function
(Ent
);
6214 Set_Corresponding_Spec
(Func_Body
, Func_Id
);
6216 Entry_Body
:= Parent
(Corresponding_Body
(Spec_Decl
));
6218 if Nkind
(Parent
(Entry_Body
)) = N_Subunit
then
6219 Entry_Body
:= Corresponding_Stub
(Parent
(Entry_Body
));
6222 Insert_Before_And_Analyze
(Entry_Body
, Func_Body
);
6224 Set_Discriminals
(Spec_Decl
);
6225 Set_Scope
(Func_Id
, Scope
(Prot
));
6228 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6231 -- Check Pure_Barriers restriction
6233 if Check_Pure_Barriers
(Cond
) = Abandon
then
6234 Check_Restriction
(Pure_Barriers
, Cond
);
6237 -- The Ravenscar profile restricts barriers to simple variables declared
6238 -- within the protected object. We also allow Boolean constants, since
6239 -- these appear in several published examples and are also allowed by
6242 -- Note that after analysis variables in this context will be replaced
6243 -- by the corresponding prival, that is to say a renaming of a selected
6244 -- component of the form _Object.Var. If expansion is disabled, as
6245 -- within a generic, we check that the entity appears in the current
6248 if Is_Entity_Name
(Cond
) then
6249 Cond_Id
:= Entity
(Cond
);
6251 -- Perform a small optimization of simple barrier functions. If the
6252 -- scope of the condition's entity is not the barrier function, then
6253 -- the condition does not depend on any of the generated renamings.
6254 -- If this is the case, eliminate the renamings as they are useless.
6255 -- This optimization is not performed when the condition was folded
6256 -- and validity checks are in effect because the original condition
6257 -- may have produced at least one check that depends on the generated
6261 and then Scope
(Cond_Id
) /= Func_Id
6262 and then not Validity_Check_Operands
6264 Set_Declarations
(Func_Body
, Empty_List
);
6267 if Cond_Id
= Standard_False
or else Cond_Id
= Standard_True
then
6270 elsif Is_Simple_Barrier_Name
(Cond
) then
6275 -- It is not a boolean variable or literal, so check the restriction.
6276 -- Note that it is safe to be calling Check_Restriction from here, even
6277 -- though this is part of the expander, since Expand_Entry_Barrier is
6278 -- called from Sem_Ch9 even in -gnatc mode.
6280 Check_Restriction
(Simple_Barriers
, Cond
);
6282 -- Emit warning if barrier contains global entities and is thus
6283 -- potentially unsynchronized.
6285 Check_Unprotected_Barrier
(Cond
);
6286 end Expand_Entry_Barrier
;
6288 ------------------------------
6289 -- Expand_N_Abort_Statement --
6290 ------------------------------
6292 -- Expand abort T1, T2, .. Tn; into:
6293 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6295 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6296 Loc
: constant Source_Ptr
:= Sloc
(N
);
6297 Tlist
: constant List_Id
:= Names
(N
);
6303 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6306 Tasknm
:= First
(Tlist
);
6308 while Present
(Tasknm
) loop
6311 -- A task interface class-wide type object is being aborted. Retrieve
6312 -- its _task_id by calling a dispatching routine.
6314 if Ada_Version
>= Ada_2005
6315 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6316 and then Is_Interface
(Etype
(Tasknm
))
6317 and then Is_Task_Interface
(Etype
(Tasknm
))
6319 Append_To
(Component_Associations
(Aggr
),
6320 Make_Component_Association
(Loc
,
6321 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6324 -- Task_Id (Tasknm._disp_get_task_id)
6326 Make_Unchecked_Type_Conversion
(Loc
,
6328 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
6330 Make_Selected_Component
(Loc
,
6331 Prefix
=> New_Copy_Tree
(Tasknm
),
6333 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6336 Append_To
(Component_Associations
(Aggr
),
6337 Make_Component_Association
(Loc
,
6338 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6339 Expression
=> Concurrent_Ref
(Tasknm
)));
6346 Make_Procedure_Call_Statement
(Loc
,
6347 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6348 Parameter_Associations
=> New_List
(
6349 Make_Qualified_Expression
(Loc
,
6350 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6351 Expression
=> Aggr
))));
6354 end Expand_N_Abort_Statement
;
6356 -------------------------------
6357 -- Expand_N_Accept_Statement --
6358 -------------------------------
6360 -- This procedure handles expansion of accept statements that stand alone,
6361 -- i.e. they are not part of an accept alternative. The expansion of
6362 -- accept statement in accept alternatives is handled by the routines
6363 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6364 -- following description applies only to stand alone accept statements.
6366 -- If there is no handled statement sequence, or only null statements, then
6367 -- this is called a trivial accept, and the expansion is:
6369 -- Accept_Trivial (entry-index)
6371 -- If there is a handled statement sequence, then the expansion is:
6378 -- Accept_Call (entry-index, Ann);
6379 -- Renaming_Declarations for formals
6380 -- <statement sequence from N_Accept_Statement node>
6381 -- Complete_Rendezvous;
6386 -- <exception handler from N_Accept_Statement node>
6387 -- Complete_Rendezvous;
6389 -- <exception handler from N_Accept_Statement node>
6390 -- Complete_Rendezvous;
6395 -- when all others =>
6396 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6399 -- The first three declarations were already inserted ahead of the accept
6400 -- statement by the Expand_Accept_Declarations procedure, which was called
6401 -- directly from the semantics during analysis of the accept statement,
6402 -- before analyzing its contained statements.
6404 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6405 -- from possible expansion activity (the original source of course does
6406 -- not have any declarations associated with the accept statement, since
6407 -- an accept statement has no declarative part). In particular, if the
6408 -- expander is active, the first such declaration is the declaration of
6409 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6411 -- The two blocks are merged into a single block if the inner block has
6412 -- no exception handlers, but otherwise two blocks are required, since
6413 -- exceptions might be raised in the exception handlers of the inner
6414 -- block, and Exceptional_Complete_Rendezvous must be called.
6416 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6417 Loc
: constant Source_Ptr
:= Sloc
(N
);
6418 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6419 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6420 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6421 Eent
: constant Entity_Id
:= Entity
(Ename
);
6422 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6423 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6424 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6430 -- If the accept statement is not part of a list, then its parent must
6431 -- be an accept alternative, and, as described above, we do not do any
6432 -- expansion for such accept statements at this level.
6434 if not Is_List_Member
(N
) then
6435 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6438 -- Trivial accept case (no statement sequence, or null statements).
6439 -- If the accept statement has declarations, then just insert them
6440 -- before the procedure call.
6442 elsif Trivial_Accept_OK
6443 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6445 -- Remove declarations for renamings, because the parameter block
6446 -- will not be assigned.
6453 D
:= First
(Declarations
(N
));
6454 while Present
(D
) loop
6456 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6464 if Present
(Declarations
(N
)) then
6465 Insert_Actions
(N
, Declarations
(N
));
6469 Make_Procedure_Call_Statement
(Loc
,
6470 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6471 Parameter_Associations
=> New_List
(
6472 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6476 -- Discard Entry_Address that was created for it, so it will not be
6477 -- emitted if this accept statement is in the statement part of a
6478 -- delay alternative.
6480 if Present
(Stats
) then
6481 Remove_Last_Elmt
(Acstack
);
6484 -- Case of statement sequence present
6487 -- Construct the block, using the declarations from the accept
6488 -- statement if any to initialize the declarations of the block.
6490 Blkent
:= Make_Temporary
(Loc
, 'A');
6491 Set_Ekind
(Blkent
, E_Block
);
6492 Set_Etype
(Blkent
, Standard_Void_Type
);
6493 Set_Scope
(Blkent
, Current_Scope
);
6496 Make_Block_Statement
(Loc
,
6497 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6498 Declarations
=> Declarations
(N
),
6499 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6501 -- For the analysis of the generated declarations, the parent node
6502 -- must be properly set.
6504 Set_Parent
(Block
, Parent
(N
));
6506 -- Prepend call to Accept_Call to main statement sequence If the
6507 -- accept has exception handlers, the statement sequence is wrapped
6508 -- in a block. Insert call and renaming declarations in the
6509 -- declarations of the block, so they are elaborated before the
6513 Make_Procedure_Call_Statement
(Loc
,
6514 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6515 Parameter_Associations
=> New_List
(
6516 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6517 New_Occurrence_Of
(Ann
, Loc
)));
6519 if Parent
(Stats
) = N
then
6520 Prepend
(Call
, Statements
(Stats
));
6522 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6527 Push_Scope
(Blkent
);
6535 D
:= First
(Declarations
(N
));
6536 while Present
(D
) loop
6539 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6541 -- The renaming declarations for the formals were created
6542 -- during analysis of the accept statement, and attached to
6543 -- the list of declarations. Place them now in the context
6544 -- of the accept block or subprogram.
6547 Typ
:= Entity
(Subtype_Mark
(D
));
6548 Insert_After
(Call
, D
);
6551 -- If the formal is class_wide, it does not have an actual
6552 -- subtype. The analysis of the renaming declaration creates
6553 -- one, but we need to retain the class-wide nature of the
6556 if Is_Class_Wide_Type
(Typ
) then
6557 Set_Etype
(Defining_Identifier
(D
), Typ
);
6568 -- Replace the accept statement by the new block
6573 -- Last step is to unstack the Accept_Address value
6575 Remove_Last_Elmt
(Acstack
);
6577 end Expand_N_Accept_Statement
;
6579 ----------------------------------
6580 -- Expand_N_Asynchronous_Select --
6581 ----------------------------------
6583 -- This procedure assumes that the trigger statement is an entry call or
6584 -- a dispatching procedure call. A delay alternative should already have
6585 -- been expanded into an entry call to the appropriate delay object Wait
6588 -- If the trigger is a task entry call, the select is implemented with
6589 -- a Task_Entry_Call:
6594 -- P : parms := (parm, parm, parm);
6596 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6598 -- procedure _clean is
6601 -- Cancel_Task_Entry_Call (C);
6608 -- (<acceptor-task>, -- Acceptor
6609 -- <entry-index>, -- E
6610 -- P'Address, -- Uninterpreted_Data
6611 -- Asynchronous_Call, -- Mode
6612 -- B); -- Rendezvous_Successful
6619 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6622 -- when Abort_Signal => Abort_Undefer;
6629 -- <triggered-statements>
6633 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6634 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6638 -- P : parms := (parm, parm, parm);
6640 -- Call_Simple (acceptor-task, entry-index, P'Address);
6646 -- so the task at hand is to convert the latter expansion into the former
6648 -- If the trigger is a protected entry call, the select is implemented
6649 -- with Protected_Entry_Call:
6652 -- P : E1_Params := (param, param, param);
6653 -- Bnn : Communications_Block;
6658 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6660 -- procedure _clean is
6663 -- if Enqueued (Bnn) then
6664 -- Cancel_Protected_Entry_Call (Bnn);
6671 -- Protected_Entry_Call
6672 -- (po._object'Access, -- Object
6673 -- <entry index>, -- E
6674 -- P'Address, -- Uninterpreted_Data
6675 -- Asynchronous_Call, -- Mode
6678 -- if Enqueued (Bnn) then
6682 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6685 -- when Abort_Signal => Abort_Undefer;
6688 -- if not Cancelled (Bnn) then
6689 -- <triggered-statements>
6693 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6697 -- P : E1_Params := (param, param, param);
6698 -- Bnn : Communications_Block;
6701 -- Protected_Entry_Call
6702 -- (po._object'Access, -- Object
6703 -- <entry index>, -- E
6704 -- P'Address, -- Uninterpreted_Data
6705 -- Simple_Call, -- Mode
6712 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6716 -- B : Boolean := False;
6717 -- Bnn : Communication_Block;
6718 -- C : Ada.Tags.Prim_Op_Kind;
6719 -- D : System.Storage_Elements.Dummy_Communication_Block;
6720 -- K : Ada.Tags.Tagged_Kind :=
6721 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6722 -- P : Parameters := (Param1 .. ParamN);
6727 -- if K = Ada.Tags.TK_Limited_Tagged
6728 -- or else K = Ada.Tags.TK_Tagged
6730 -- <dispatching-call>;
6731 -- <triggering-statements>;
6735 -- Ada.Tags.Get_Offset_Index
6736 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6738 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6740 -- if C = POK_Protected_Entry then
6742 -- procedure _clean is
6744 -- if Enqueued (Bnn) then
6745 -- Cancel_Protected_Entry_Call (Bnn);
6751 -- _Disp_Asynchronous_Select
6752 -- (<object>, S, P'Address, D, B);
6753 -- Bnn := Communication_Block (D);
6755 -- Param1 := P.Param1;
6757 -- ParamN := P.ParamN;
6759 -- if Enqueued (Bnn) then
6760 -- <abortable-statements>
6763 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6766 -- when Abort_Signal => Abort_Undefer;
6769 -- if not Cancelled (Bnn) then
6770 -- <triggering-statements>
6773 -- elsif C = POK_Task_Entry then
6775 -- procedure _clean is
6777 -- Cancel_Task_Entry_Call (U);
6783 -- _Disp_Asynchronous_Select
6784 -- (<object>, S, P'Address, D, B);
6785 -- Bnn := Communication_Bloc (D);
6787 -- Param1 := P.Param1;
6789 -- ParamN := P.ParamN;
6794 -- <abortable-statements>
6796 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6799 -- when Abort_Signal => Abort_Undefer;
6803 -- <triggering-statements>
6808 -- <dispatching-call>;
6809 -- <triggering-statements>
6814 -- The job is to convert this to the asynchronous form
6816 -- If the trigger is a delay statement, it will have been expanded into
6817 -- a call to one of the GNARL delay procedures. This routine will convert
6818 -- this into a protected entry call on a delay object and then continue
6819 -- processing as for a protected entry call trigger. This requires
6820 -- declaring a Delay_Block object and adding a pointer to this object to
6821 -- the parameter list of the delay procedure to form the parameter list of
6822 -- the entry call. This object is used by the runtime to queue the delay
6825 -- For a description of the use of P and the assignments after the call,
6826 -- see Expand_N_Entry_Call_Statement.
6828 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6829 Loc
: constant Source_Ptr
:= Sloc
(N
);
6830 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6831 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6833 Abort_Block_Ent
: Entity_Id
;
6834 Abortable_Block
: Node_Id
;
6837 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6838 Blk_Typ
: Entity_Id
;
6840 Call_Ent
: Entity_Id
;
6841 Cancel_Param
: Entity_Id
;
6842 Cleanup_Block
: Node_Id
;
6843 Cleanup_Block_Ent
: Entity_Id
;
6844 Cleanup_Stmts
: List_Id
;
6845 Conc_Typ_Stmts
: List_Id
;
6847 Dblock_Ent
: Entity_Id
;
6852 Enqueue_Call
: Node_Id
;
6855 Handler_Stmt
: Node_Id
;
6857 Lim_Typ_Stmts
: List_Id
;
6863 ProtE_Stmts
: List_Id
;
6864 ProtP_Stmts
: List_Id
;
6867 TaskE_Stmts
: List_Id
;
6870 B
: Entity_Id
; -- Call status flag
6871 Bnn
: Entity_Id
; -- Communication block
6872 C
: Entity_Id
; -- Call kind
6873 K
: Entity_Id
; -- Tagged kind
6874 P
: Entity_Id
; -- Parameter block
6875 S
: Entity_Id
; -- Primitive operation slot
6876 T
: Entity_Id
; -- Additional status flag
6878 procedure Rewrite_Abortable_Part
;
6879 -- If the trigger is a dispatching call, the expansion inserts multiple
6880 -- copies of the abortable part. This is both inefficient, and may lead
6881 -- to duplicate definitions that the back-end will reject, when the
6882 -- abortable part includes loops. This procedure rewrites the abortable
6883 -- part into a call to a generated procedure.
6885 ----------------------------
6886 -- Rewrite_Abortable_Part --
6887 ----------------------------
6889 procedure Rewrite_Abortable_Part
is
6890 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6895 Make_Subprogram_Body
(Loc
,
6897 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6898 Declarations
=> New_List
,
6899 Handled_Statement_Sequence
=>
6900 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6901 Insert_Before
(N
, Decl
);
6904 -- Rewrite abortable part into a call to this procedure
6908 Make_Procedure_Call_Statement
(Loc
,
6909 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6910 end Rewrite_Abortable_Part
;
6912 -- Start of processing for Expand_N_Asynchronous_Select
6915 -- Asynchronous select is not supported on restricted runtimes. Don't
6918 if Restricted_Profile
then
6922 Process_Statements_For_Controlled_Objects
(Trig
);
6923 Process_Statements_For_Controlled_Objects
(Abrt
);
6925 Ecall
:= Triggering_Statement
(Trig
);
6927 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6929 -- Retrieve Astats and Tstats now because the finalization machinery may
6930 -- wrap them in blocks.
6932 Astats
:= Statements
(Abrt
);
6933 Tstats
:= Statements
(Trig
);
6935 -- The arguments in the call may require dynamic allocation, and the
6936 -- call statement may have been transformed into a block. The block
6937 -- may contain additional declarations for internal entities, and the
6938 -- original call is found by sequential search.
6940 if Nkind
(Ecall
) = N_Block_Statement
then
6941 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6942 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6943 N_Entry_Call_Statement
)
6949 -- This is either a dispatching call or a delay statement used as a
6950 -- trigger which was expanded into a procedure call.
6952 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6953 if Ada_Version
>= Ada_2005
6955 (No
(Original_Node
(Ecall
))
6956 or else not Nkind_In
(Original_Node
(Ecall
),
6957 N_Delay_Relative_Statement
,
6958 N_Delay_Until_Statement
))
6960 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6962 Rewrite_Abortable_Part
;
6966 -- Call status flag processing, generate:
6967 -- B : Boolean := False;
6969 B
:= Build_B
(Loc
, Decls
);
6971 -- Communication block processing, generate:
6972 -- Bnn : Communication_Block;
6974 Bnn
:= Make_Temporary
(Loc
, 'B');
6976 Make_Object_Declaration
(Loc
,
6977 Defining_Identifier
=> Bnn
,
6978 Object_Definition
=>
6979 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
6981 -- Call kind processing, generate:
6982 -- C : Ada.Tags.Prim_Op_Kind;
6984 C
:= Build_C
(Loc
, Decls
);
6986 -- Tagged kind processing, generate:
6987 -- K : Ada.Tags.Tagged_Kind :=
6988 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6990 -- Dummy communication block, generate:
6991 -- D : Dummy_Communication_Block;
6994 Make_Object_Declaration
(Loc
,
6995 Defining_Identifier
=>
6996 Make_Defining_Identifier
(Loc
, Name_uD
),
6997 Object_Definition
=>
6999 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
7001 K
:= Build_K
(Loc
, Decls
, Obj
);
7003 -- Parameter block processing
7005 Blk_Typ
:= Build_Parameter_Block
7006 (Loc
, Actuals
, Formals
, Decls
);
7007 P
:= Parameter_Block_Pack
7008 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7010 -- Dispatch table slot processing, generate:
7013 S
:= Build_S
(Loc
, Decls
);
7015 -- Additional status flag processing, generate:
7018 T
:= Make_Temporary
(Loc
, 'T');
7020 Make_Object_Declaration
(Loc
,
7021 Defining_Identifier
=> T
,
7022 Object_Definition
=>
7023 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7025 ------------------------------
7026 -- Protected entry handling --
7027 ------------------------------
7030 -- Param1 := P.Param1;
7032 -- ParamN := P.ParamN;
7034 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7037 -- Bnn := Communication_Block (D);
7039 Prepend_To
(Cleanup_Stmts
,
7040 Make_Assignment_Statement
(Loc
,
7041 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
7043 Make_Unchecked_Type_Conversion
(Loc
,
7045 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7046 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7049 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7051 Prepend_To
(Cleanup_Stmts
,
7052 Make_Procedure_Call_Statement
(Loc
,
7056 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
7058 Parameter_Associations
=>
7060 New_Copy_Tree
(Obj
), -- <object>
7061 New_Occurrence_Of
(S
, Loc
), -- S
7062 Make_Attribute_Reference
(Loc
, -- P'Address
7063 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7064 Attribute_Name
=> Name_Address
),
7065 Make_Identifier
(Loc
, Name_uD
), -- D
7066 New_Occurrence_Of
(B
, Loc
)))); -- B
7069 -- if Enqueued (Bnn) then
7070 -- <abortable-statements>
7073 Append_To
(Cleanup_Stmts
,
7074 Make_Implicit_If_Statement
(N
,
7076 Make_Function_Call
(Loc
,
7078 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7079 Parameter_Associations
=>
7080 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
7083 New_Copy_List_Tree
(Astats
)));
7085 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7086 -- will then generate a _clean for the communication block Bnn.
7090 -- procedure _clean is
7092 -- if Enqueued (Bnn) then
7093 -- Cancel_Protected_Entry_Call (Bnn);
7102 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7104 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7106 -- Wrap the cleanup block in an exception handling block
7112 -- when Abort_Signal => Abort_Undefer;
7115 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7118 Make_Implicit_Label_Declaration
(Loc
,
7119 Defining_Identifier
=> Abort_Block_Ent
),
7122 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7125 -- if not Cancelled (Bnn) then
7126 -- <triggering-statements>
7129 Append_To
(ProtE_Stmts
,
7130 Make_Implicit_If_Statement
(N
,
7134 Make_Function_Call
(Loc
,
7136 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7137 Parameter_Associations
=>
7138 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7141 New_Copy_List_Tree
(Tstats
)));
7143 -------------------------
7144 -- Task entry handling --
7145 -------------------------
7148 -- Param1 := P.Param1;
7150 -- ParamN := P.ParamN;
7152 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7155 -- Bnn := Communication_Block (D);
7157 Append_To
(TaskE_Stmts
,
7158 Make_Assignment_Statement
(Loc
,
7160 New_Occurrence_Of
(Bnn
, Loc
),
7162 Make_Unchecked_Type_Conversion
(Loc
,
7164 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7165 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7168 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7170 Prepend_To
(TaskE_Stmts
,
7171 Make_Procedure_Call_Statement
(Loc
,
7174 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7175 Name_uDisp_Asynchronous_Select
),
7178 Parameter_Associations
=> New_List
(
7179 New_Copy_Tree
(Obj
), -- <object>
7180 New_Occurrence_Of
(S
, Loc
), -- S
7181 Make_Attribute_Reference
(Loc
, -- P'Address
7182 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7183 Attribute_Name
=> Name_Address
),
7184 Make_Identifier
(Loc
, Name_uD
), -- D
7185 New_Occurrence_Of
(B
, Loc
)))); -- B
7190 Prepend_To
(TaskE_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7194 -- <abortable-statements>
7196 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7199 (Cleanup_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7201 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7202 -- will generate a _clean for the additional status flag.
7206 -- procedure _clean is
7208 -- Cancel_Task_Entry_Call (U);
7216 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7218 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7220 -- Wrap the cleanup block in an exception handling block
7226 -- when Abort_Signal => Abort_Undefer;
7229 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7231 Append_To
(TaskE_Stmts
,
7232 Make_Implicit_Label_Declaration
(Loc
,
7233 Defining_Identifier
=> Abort_Block_Ent
));
7235 Append_To
(TaskE_Stmts
,
7237 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7241 -- <triggering-statements>
7244 Append_To
(TaskE_Stmts
,
7245 Make_Implicit_If_Statement
(N
,
7247 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7250 New_Copy_List_Tree
(Tstats
)));
7252 ----------------------------------
7253 -- Protected procedure handling --
7254 ----------------------------------
7257 -- <dispatching-call>;
7258 -- <triggering-statements>
7260 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7261 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7264 -- S := Ada.Tags.Get_Offset_Index
7265 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7268 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7271 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7273 Append_To
(Conc_Typ_Stmts
,
7274 Make_Procedure_Call_Statement
(Loc
,
7277 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7278 Name_uDisp_Get_Prim_Op_Kind
),
7280 Parameter_Associations
=>
7282 New_Copy_Tree
(Obj
),
7283 New_Occurrence_Of
(S
, Loc
),
7284 New_Occurrence_Of
(C
, Loc
))));
7287 -- if C = POK_Procedure_Entry then
7289 -- elsif C = POK_Task_Entry then
7295 Append_To
(Conc_Typ_Stmts
,
7296 Make_Implicit_If_Statement
(N
,
7300 New_Occurrence_Of
(C
, Loc
),
7302 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7309 Make_Elsif_Part
(Loc
,
7313 New_Occurrence_Of
(C
, Loc
),
7315 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7324 -- <dispatching-call>;
7325 -- <triggering-statements>
7327 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7328 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7331 -- if K = Ada.Tags.TK_Limited_Tagged
7332 -- or else K = Ada.Tags.TK_Tagged
7340 Make_Implicit_If_Statement
(N
,
7341 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7342 Then_Statements
=> Lim_Typ_Stmts
,
7343 Else_Statements
=> Conc_Typ_Stmts
));
7346 Make_Block_Statement
(Loc
,
7349 Handled_Statement_Sequence
=>
7350 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7355 -- Delay triggering statement processing
7358 -- Add a Delay_Block object to the parameter list of the delay
7359 -- procedure to form the parameter list of the Wait entry call.
7361 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7363 Pdef
:= Entity
(Name
(Ecall
));
7365 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7367 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7369 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7371 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7373 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7374 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7377 Append_To
(Parameter_Associations
(Ecall
),
7378 Make_Attribute_Reference
(Loc
,
7379 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7380 Attribute_Name
=> Name_Unchecked_Access
));
7382 -- Create the inner block to protect the abortable part
7384 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7386 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7389 Make_Block_Statement
(Loc
,
7390 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7391 Handled_Statement_Sequence
=>
7392 Make_Handled_Sequence_Of_Statements
(Loc
,
7393 Statements
=> Astats
),
7394 Has_Created_Identifier
=> True,
7395 Is_Asynchronous_Call_Block
=> True);
7397 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7400 Make_Implicit_If_Statement
(N
,
7402 Make_Function_Call
(Loc
,
7403 Name
=> Enqueue_Call
,
7404 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7406 New_List
(Make_Block_Statement
(Loc
,
7407 Handled_Statement_Sequence
=>
7408 Make_Handled_Sequence_Of_Statements
(Loc
,
7409 Statements
=> New_List
(
7410 Make_Implicit_Label_Declaration
(Loc
,
7411 Defining_Identifier
=> Blk_Ent
,
7412 Label_Construct
=> Abortable_Block
),
7414 Exception_Handlers
=> Hdle
)))));
7416 Stmts
:= New_List
(Ecall
);
7418 -- Construct statement sequence for new block
7421 Make_Implicit_If_Statement
(N
,
7423 Make_Function_Call
(Loc
,
7424 Name
=> New_Occurrence_Of
(
7425 RTE
(RE_Timed_Out
), Loc
),
7426 Parameter_Associations
=> New_List
(
7427 Make_Attribute_Reference
(Loc
,
7428 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7429 Attribute_Name
=> Name_Unchecked_Access
))),
7430 Then_Statements
=> Tstats
));
7432 -- The result is the new block
7434 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7437 Make_Block_Statement
(Loc
,
7438 Declarations
=> New_List
(
7439 Make_Object_Declaration
(Loc
,
7440 Defining_Identifier
=> Dblock_Ent
,
7441 Aliased_Present
=> True,
7442 Object_Definition
=>
7443 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7445 Handled_Statement_Sequence
=>
7446 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7456 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7457 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7459 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7460 Decls
:= Declarations
(Ecall
);
7462 if Is_Protected_Type
(Etype
(Concval
)) then
7464 -- Get the declarations of the block expanded from the entry call
7466 Decl
:= First
(Decls
);
7467 while Present
(Decl
)
7468 and then (Nkind
(Decl
) /= N_Object_Declaration
7469 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7470 RE_Communication_Block
))
7475 pragma Assert
(Present
(Decl
));
7476 Cancel_Param
:= Defining_Identifier
(Decl
);
7478 -- Change the mode of the Protected_Entry_Call call
7480 -- Protected_Entry_Call (
7481 -- Object => po._object'Access,
7482 -- E => <entry index>;
7483 -- Uninterpreted_Data => P'Address;
7484 -- Mode => Asynchronous_Call;
7487 -- Skip assignments to temporaries created for in-out parameters
7489 -- This makes unwarranted assumptions about the shape of the expanded
7490 -- tree for the call, and should be cleaned up ???
7492 Stmt
:= First
(Stmts
);
7493 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7499 Param
:= First
(Parameter_Associations
(Call
));
7500 while Present
(Param
)
7501 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7506 pragma Assert
(Present
(Param
));
7507 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7510 -- Append an if statement to execute the abortable part
7513 -- if Enqueued (Bnn) then
7516 Make_Implicit_If_Statement
(N
,
7518 Make_Function_Call
(Loc
,
7519 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7520 Parameter_Associations
=> New_List
(
7521 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7522 Then_Statements
=> Astats
));
7525 Make_Block_Statement
(Loc
,
7526 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7527 Handled_Statement_Sequence
=>
7528 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7529 Has_Created_Identifier
=> True,
7530 Is_Asynchronous_Call_Block
=> True);
7532 -- Aborts are not deferred at beginning of exception handlers in
7535 if ZCX_Exceptions
then
7536 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7539 Handler_Stmt
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
7543 Make_Block_Statement
(Loc
,
7544 Handled_Statement_Sequence
=>
7545 Make_Handled_Sequence_Of_Statements
(Loc
,
7546 Statements
=> New_List
(
7547 Make_Implicit_Label_Declaration
(Loc
,
7548 Defining_Identifier
=> Blk_Ent
,
7549 Label_Construct
=> Abortable_Block
),
7554 Exception_Handlers
=> New_List
(
7555 Make_Implicit_Exception_Handler
(Loc
,
7557 -- when Abort_Signal =>
7558 -- Abort_Undefer.all;
7560 Exception_Choices
=>
7561 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7562 Statements
=> New_List
(Handler_Stmt
))))),
7564 -- if not Cancelled (Bnn) then
7565 -- triggered statements
7568 Make_Implicit_If_Statement
(N
,
7569 Condition
=> Make_Op_Not
(Loc
,
7571 Make_Function_Call
(Loc
,
7572 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7573 Parameter_Associations
=> New_List
(
7574 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7575 Then_Statements
=> Tstats
));
7577 -- Asynchronous task entry call
7584 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7586 -- Insert declaration of B in declarations of existing block
7589 Make_Object_Declaration
(Loc
,
7590 Defining_Identifier
=> B
,
7591 Object_Definition
=>
7592 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7594 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7596 -- Insert the declaration of C in the declarations of the existing
7597 -- block. The variable is initialized to something (True or False,
7598 -- does not matter) to prevent CodePeer from complaining about a
7599 -- possible read of an uninitialized variable.
7602 Make_Object_Declaration
(Loc
,
7603 Defining_Identifier
=> Cancel_Param
,
7604 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
7605 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
),
7606 Has_Init_Expression
=> True));
7608 -- Remove and save the call to Call_Simple
7610 Stmt
:= First
(Stmts
);
7612 -- Skip assignments to temporaries created for in-out parameters.
7613 -- This makes unwarranted assumptions about the shape of the expanded
7614 -- tree for the call, and should be cleaned up ???
7616 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7622 -- Create the inner block to protect the abortable part
7624 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7626 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7629 Make_Block_Statement
(Loc
,
7630 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7631 Handled_Statement_Sequence
=>
7632 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7633 Has_Created_Identifier
=> True,
7634 Is_Asynchronous_Call_Block
=> True);
7637 Make_Block_Statement
(Loc
,
7638 Handled_Statement_Sequence
=>
7639 Make_Handled_Sequence_Of_Statements
(Loc
,
7640 Statements
=> New_List
(
7641 Make_Implicit_Label_Declaration
(Loc
,
7642 Defining_Identifier
=> Blk_Ent
,
7643 Label_Construct
=> Abortable_Block
),
7645 Exception_Handlers
=> Hdle
)));
7647 -- Create new call statement
7649 Params
:= Parameter_Associations
(Call
);
7652 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7653 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7656 Make_Procedure_Call_Statement
(Loc
,
7657 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7658 Parameter_Associations
=> Params
));
7660 -- Construct statement sequence for new block
7663 Make_Implicit_If_Statement
(N
,
7665 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7666 Then_Statements
=> Tstats
));
7668 -- Protected the call against abort
7670 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7673 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7675 -- The result is the new block
7678 Make_Block_Statement
(Loc
,
7679 Declarations
=> Decls
,
7680 Handled_Statement_Sequence
=>
7681 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7684 end Expand_N_Asynchronous_Select
;
7686 -------------------------------------
7687 -- Expand_N_Conditional_Entry_Call --
7688 -------------------------------------
7690 -- The conditional task entry call is converted to a call to
7695 -- P : parms := (parm, parm, parm);
7699 -- (<acceptor-task>, -- Acceptor
7700 -- <entry-index>, -- E
7701 -- P'Address, -- Uninterpreted_Data
7702 -- Conditional_Call, -- Mode
7703 -- B); -- Rendezvous_Successful
7708 -- normal-statements
7714 -- For a description of the use of P and the assignments after the call,
7715 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7716 -- conditional entry call has already been expanded (by the Expand_N_Entry
7717 -- _Call_Statement procedure) as follows:
7720 -- P : parms := (parm, parm, parm);
7722 -- ... info for in-out parameters
7723 -- Call_Simple (acceptor-task, entry-index, P'Address);
7729 -- so the task at hand is to convert the latter expansion into the former
7731 -- The conditional protected entry call is converted to a call to
7732 -- Protected_Entry_Call:
7735 -- P : parms := (parm, parm, parm);
7736 -- Bnn : Communications_Block;
7739 -- Protected_Entry_Call
7740 -- (po._object'Access, -- Object
7741 -- <entry index>, -- E
7742 -- P'Address, -- Uninterpreted_Data
7743 -- Conditional_Call, -- Mode
7748 -- if Cancelled (Bnn) then
7751 -- normal-statements
7755 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7759 -- B : Boolean := False;
7760 -- C : Ada.Tags.Prim_Op_Kind;
7761 -- K : Ada.Tags.Tagged_Kind :=
7762 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7763 -- P : Parameters := (Param1 .. ParamN);
7767 -- if K = Ada.Tags.TK_Limited_Tagged
7768 -- or else K = Ada.Tags.TK_Tagged
7770 -- <dispatching-call>;
7771 -- <triggering-statements>
7775 -- Ada.Tags.Get_Offset_Index
7776 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7778 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7780 -- if C = POK_Protected_Entry
7781 -- or else C = POK_Task_Entry
7783 -- Param1 := P.Param1;
7785 -- ParamN := P.ParamN;
7789 -- if C = POK_Procedure
7790 -- or else C = POK_Protected_Procedure
7791 -- or else C = POK_Task_Procedure
7793 -- <dispatching-call>;
7796 -- <triggering-statements>
7798 -- <else-statements>
7803 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7804 Loc
: constant Source_Ptr
:= Sloc
(N
);
7805 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7806 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7809 Blk_Typ
: Entity_Id
;
7811 Call_Ent
: Entity_Id
;
7812 Conc_Typ_Stmts
: List_Id
;
7816 Lim_Typ_Stmts
: List_Id
;
7823 Transient_Blk
: Node_Id
;
7826 B
: Entity_Id
; -- Call status flag
7827 C
: Entity_Id
; -- Call kind
7828 K
: Entity_Id
; -- Tagged kind
7829 P
: Entity_Id
; -- Parameter block
7830 S
: Entity_Id
; -- Primitive operation slot
7833 Process_Statements_For_Controlled_Objects
(N
);
7835 if Ada_Version
>= Ada_2005
7836 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7838 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7843 -- Call status flag processing, generate:
7844 -- B : Boolean := False;
7846 B
:= Build_B
(Loc
, Decls
);
7848 -- Call kind processing, generate:
7849 -- C : Ada.Tags.Prim_Op_Kind;
7851 C
:= Build_C
(Loc
, Decls
);
7853 -- Tagged kind processing, generate:
7854 -- K : Ada.Tags.Tagged_Kind :=
7855 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7857 K
:= Build_K
(Loc
, Decls
, Obj
);
7859 -- Parameter block processing
7861 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7862 P
:= Parameter_Block_Pack
7863 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7865 -- Dispatch table slot processing, generate:
7868 S
:= Build_S
(Loc
, Decls
);
7871 -- S := Ada.Tags.Get_Offset_Index
7872 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7875 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7878 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7880 Append_To
(Conc_Typ_Stmts
,
7881 Make_Procedure_Call_Statement
(Loc
,
7884 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7885 Name_uDisp_Conditional_Select
),
7887 Parameter_Associations
=>
7889 New_Copy_Tree
(Obj
), -- <object>
7890 New_Occurrence_Of
(S
, Loc
), -- S
7891 Make_Attribute_Reference
(Loc
, -- P'Address
7892 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7893 Attribute_Name
=> Name_Address
),
7894 New_Occurrence_Of
(C
, Loc
), -- C
7895 New_Occurrence_Of
(B
, Loc
)))); -- B
7898 -- if C = POK_Protected_Entry
7899 -- or else C = POK_Task_Entry
7901 -- Param1 := P.Param1;
7903 -- ParamN := P.ParamN;
7906 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7908 -- Generate the if statement only when the packed parameters need
7909 -- explicit assignments to their corresponding actuals.
7911 if Present
(Unpack
) then
7912 Append_To
(Conc_Typ_Stmts
,
7913 Make_Implicit_If_Statement
(N
,
7919 New_Occurrence_Of
(C
, Loc
),
7921 New_Occurrence_Of
(RTE
(
7922 RE_POK_Protected_Entry
), Loc
)),
7927 New_Occurrence_Of
(C
, Loc
),
7929 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
7931 Then_Statements
=> Unpack
));
7936 -- if C = POK_Procedure
7937 -- or else C = POK_Protected_Procedure
7938 -- or else C = POK_Task_Procedure
7940 -- <dispatching-call>
7942 -- <normal-statements>
7944 -- <else-statements>
7947 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7949 Prepend_To
(N_Stats
,
7950 Make_Implicit_If_Statement
(N
,
7956 New_Occurrence_Of
(C
, Loc
),
7958 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
7965 New_Occurrence_Of
(C
, Loc
),
7967 New_Occurrence_Of
(RTE
(
7968 RE_POK_Protected_Procedure
), Loc
)),
7973 New_Occurrence_Of
(C
, Loc
),
7975 New_Occurrence_Of
(RTE
(
7976 RE_POK_Task_Procedure
), Loc
)))),
7981 Append_To
(Conc_Typ_Stmts
,
7982 Make_Implicit_If_Statement
(N
,
7983 Condition
=> New_Occurrence_Of
(B
, Loc
),
7984 Then_Statements
=> N_Stats
,
7985 Else_Statements
=> Else_Statements
(N
)));
7988 -- <dispatching-call>;
7989 -- <triggering-statements>
7991 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
7992 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
7995 -- if K = Ada.Tags.TK_Limited_Tagged
7996 -- or else K = Ada.Tags.TK_Tagged
8004 Make_Implicit_If_Statement
(N
,
8005 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
8006 Then_Statements
=> Lim_Typ_Stmts
,
8007 Else_Statements
=> Conc_Typ_Stmts
));
8010 Make_Block_Statement
(Loc
,
8013 Handled_Statement_Sequence
=>
8014 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8016 -- As described above, the entry alternative is transformed into a
8017 -- block that contains the gnulli call, and possibly assignment
8018 -- statements for in-out parameters. The gnulli call may itself be
8019 -- rewritten into a transient block if some unconstrained parameters
8020 -- require it. We need to retrieve the call to complete its parameter
8025 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
8027 if Present
(Transient_Blk
)
8028 and then Nkind
(Transient_Blk
) = N_Block_Statement
8030 Blk
:= Transient_Blk
;
8033 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
8034 Stmt
:= First
(Stmts
);
8035 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
8040 Params
:= Parameter_Associations
(Call
);
8042 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
8044 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8046 Param
:= First
(Params
);
8047 while Present
(Param
)
8048 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
8053 pragma Assert
(Present
(Param
));
8055 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8059 -- Find the Communication_Block parameter for the call to the
8060 -- Cancelled function.
8062 Decl
:= First
(Declarations
(Blk
));
8063 while Present
(Decl
)
8064 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
8065 RE_Communication_Block
)
8070 -- Add an if statement to execute the else part if the call
8071 -- does not succeed (as indicated by the Cancelled predicate).
8074 Make_Implicit_If_Statement
(N
,
8075 Condition
=> Make_Function_Call
(Loc
,
8076 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
8077 Parameter_Associations
=> New_List
(
8078 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
8079 Then_Statements
=> Else_Statements
(N
),
8080 Else_Statements
=> Statements
(Alt
)));
8083 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8085 -- Insert declaration of B in declarations of existing block
8087 if No
(Declarations
(Blk
)) then
8088 Set_Declarations
(Blk
, New_List
);
8091 Prepend_To
(Declarations
(Blk
),
8092 Make_Object_Declaration
(Loc
,
8093 Defining_Identifier
=> B
,
8094 Object_Definition
=>
8095 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8097 -- Create new call statement
8100 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8101 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
8104 Make_Procedure_Call_Statement
(Loc
,
8105 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
8106 Parameter_Associations
=> Params
));
8108 -- Construct statement sequence for new block
8111 Make_Implicit_If_Statement
(N
,
8112 Condition
=> New_Occurrence_Of
(B
, Loc
),
8113 Then_Statements
=> Statements
(Alt
),
8114 Else_Statements
=> Else_Statements
(N
)));
8117 -- The result is the new block
8120 Make_Block_Statement
(Loc
,
8121 Declarations
=> Declarations
(Blk
),
8122 Handled_Statement_Sequence
=>
8123 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8127 end Expand_N_Conditional_Entry_Call
;
8129 ---------------------------------------
8130 -- Expand_N_Delay_Relative_Statement --
8131 ---------------------------------------
8133 -- Delay statement is implemented as a procedure call to Delay_For
8134 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8135 -- simple delays imposed by the use of Protected Objects.
8137 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8138 Loc
: constant Source_Ptr
:= Sloc
(N
);
8142 -- Try to use System.Relative_Delays.Delay_For only if available. This
8143 -- is the implementation used on restricted platforms when Ada.Calendar
8144 -- is not available.
8146 if RTE_Available
(RO_RD_Delay_For
) then
8147 Proc
:= RTE
(RO_RD_Delay_For
);
8149 -- Otherwise, use Ada.Calendar.Delays.Delay_For and emit an error
8150 -- message if not available.
8153 Proc
:= RTE
(RO_CA_Delay_For
);
8157 Make_Procedure_Call_Statement
(Loc
,
8158 Name
=> New_Occurrence_Of
(Proc
, Loc
),
8159 Parameter_Associations
=> New_List
(Expression
(N
))));
8161 end Expand_N_Delay_Relative_Statement
;
8163 ------------------------------------
8164 -- Expand_N_Delay_Until_Statement --
8165 ------------------------------------
8167 -- Delay Until statement is implemented as a procedure call to
8168 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8170 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8171 Loc
: constant Source_Ptr
:= Sloc
(N
);
8175 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8176 Typ
:= RTE
(RO_CA_Delay_Until
);
8178 Typ
:= RTE
(RO_RT_Delay_Until
);
8182 Make_Procedure_Call_Statement
(Loc
,
8183 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8184 Parameter_Associations
=> New_List
(Expression
(N
))));
8187 end Expand_N_Delay_Until_Statement
;
8189 -------------------------
8190 -- Expand_N_Entry_Body --
8191 -------------------------
8193 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8195 -- Associate discriminals with the next protected operation body to be
8198 if Present
(Next_Protected_Operation
(N
)) then
8199 Set_Discriminals
(Parent
(Current_Scope
));
8201 end Expand_N_Entry_Body
;
8203 -----------------------------------
8204 -- Expand_N_Entry_Call_Statement --
8205 -----------------------------------
8207 -- An entry call is expanded into GNARLI calls to implement a simple entry
8208 -- call (see Build_Simple_Entry_Call).
8210 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8216 if No_Run_Time_Mode
then
8217 Error_Msg_CRT
("entry call", N
);
8221 -- If this entry call is part of an asynchronous select, don't expand it
8222 -- here; it will be expanded with the select statement. Don't expand
8223 -- timed entry calls either, as they are translated into asynchronous
8226 -- ??? This whole approach is questionable; it may be better to go back
8227 -- to allowing the expansion to take place and then attempting to fix it
8228 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8229 -- whether the expanded call is on a task or protected entry.
8231 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8232 or else N
/= Triggering_Statement
(Parent
(N
)))
8233 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8234 or else N
/= Entry_Call_Statement
(Parent
(N
))
8235 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8237 Extract_Entry
(N
, Concval
, Ename
, Index
);
8238 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8240 end Expand_N_Entry_Call_Statement
;
8242 --------------------------------
8243 -- Expand_N_Entry_Declaration --
8244 --------------------------------
8246 -- If there are parameters, then first, each of the formals is marked by
8247 -- setting Is_Entry_Formal. Next a record type is built which is used to
8248 -- hold the parameter values. The name of this record type is entryP where
8249 -- entry is the name of the entry, with an additional corresponding access
8250 -- type called entryPA. The record type has matching components for each
8251 -- formal (the component names are the same as the formal names). For
8252 -- elementary types, the component type matches the formal type. For
8253 -- composite types, an access type is declared (with the name formalA)
8254 -- which designates the formal type, and the type of the component is this
8255 -- access type. Finally the Entry_Component of each formal is set to
8256 -- reference the corresponding record component.
8258 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8259 Loc
: constant Source_Ptr
:= Sloc
(N
);
8260 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8261 Components
: List_Id
;
8264 Last_Decl
: Node_Id
;
8265 Component
: Entity_Id
;
8268 Rec_Ent
: Entity_Id
;
8269 Acc_Ent
: Entity_Id
;
8272 Formal
:= First_Formal
(Entry_Ent
);
8275 -- Most processing is done only if parameters are present
8277 if Present
(Formal
) then
8278 Components
:= New_List
;
8280 -- Loop through formals
8282 while Present
(Formal
) loop
8283 Set_Is_Entry_Formal
(Formal
);
8285 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8286 Set_Entry_Component
(Formal
, Component
);
8287 Set_Entry_Formal
(Component
, Formal
);
8288 Ftype
:= Etype
(Formal
);
8290 -- Declare new access type and then append
8292 Ctype
:= Make_Temporary
(Loc
, 'A');
8293 Set_Is_Param_Block_Component_Type
(Ctype
);
8296 Make_Full_Type_Declaration
(Loc
,
8297 Defining_Identifier
=> Ctype
,
8299 Make_Access_To_Object_Definition
(Loc
,
8300 All_Present
=> True,
8301 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8302 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8304 Insert_After
(Last_Decl
, Decl
);
8307 Append_To
(Components
,
8308 Make_Component_Declaration
(Loc
,
8309 Defining_Identifier
=> Component
,
8310 Component_Definition
=>
8311 Make_Component_Definition
(Loc
,
8312 Aliased_Present
=> False,
8313 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8315 Next_Formal_With_Extras
(Formal
);
8318 -- Create the Entry_Parameter_Record declaration
8320 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8323 Make_Full_Type_Declaration
(Loc
,
8324 Defining_Identifier
=> Rec_Ent
,
8326 Make_Record_Definition
(Loc
,
8328 Make_Component_List
(Loc
,
8329 Component_Items
=> Components
)));
8331 Insert_After
(Last_Decl
, Decl
);
8334 -- Construct and link in the corresponding access type
8336 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8338 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8341 Make_Full_Type_Declaration
(Loc
,
8342 Defining_Identifier
=> Acc_Ent
,
8344 Make_Access_To_Object_Definition
(Loc
,
8345 All_Present
=> True,
8346 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8348 Insert_After
(Last_Decl
, Decl
);
8350 end Expand_N_Entry_Declaration
;
8352 -----------------------------
8353 -- Expand_N_Protected_Body --
8354 -----------------------------
8356 -- Protected bodies are expanded to the completion of the subprograms
8357 -- created for the corresponding protected type. These are a protected and
8358 -- unprotected version of each protected subprogram in the object, a
8359 -- function to calculate each entry barrier, and a procedure to execute the
8360 -- sequence of statements of each protected entry body. For example, for
8361 -- protected type ptype:
8364 -- (O : System.Address;
8365 -- E : Protected_Entry_Index)
8368 -- <discriminant renamings>
8369 -- <private object renamings>
8371 -- return <barrier expression>;
8374 -- procedure pprocN (_object : in out poV;...) is
8375 -- <discriminant renamings>
8376 -- <private object renamings>
8378 -- <sequence of statements>
8381 -- procedure pprocP (_object : in out poV;...) is
8382 -- procedure _clean is
8385 -- ptypeS (_object, Pn);
8386 -- Unlock (_object._object'Access);
8387 -- Abort_Undefer.all;
8392 -- Lock (_object._object'Access);
8393 -- pprocN (_object;...);
8398 -- function pfuncN (_object : poV;...) return Return_Type is
8399 -- <discriminant renamings>
8400 -- <private object renamings>
8402 -- <sequence of statements>
8405 -- function pfuncP (_object : poV) return Return_Type is
8406 -- procedure _clean is
8408 -- Unlock (_object._object'Access);
8409 -- Abort_Undefer.all;
8414 -- Lock (_object._object'Access);
8415 -- return pfuncN (_object);
8422 -- (O : System.Address;
8423 -- P : System.Address;
8424 -- E : Protected_Entry_Index)
8426 -- <discriminant renamings>
8427 -- <private object renamings>
8428 -- type poVP is access poV;
8429 -- _Object : ptVP := ptVP!(O);
8433 -- <statement sequence>
8434 -- Complete_Entry_Body (_Object._Object);
8436 -- when all others =>
8437 -- Exceptional_Complete_Entry_Body (
8438 -- _Object._Object, Get_GNAT_Exception);
8442 -- The type poV is the record created for the protected type to hold
8443 -- the state of the protected object.
8445 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8446 Loc
: constant Source_Ptr
:= Sloc
(N
);
8447 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8449 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8450 -- This flag indicates whether the lock free implementation is active
8452 Current_Node
: Node_Id
;
8453 Disp_Op_Body
: Node_Id
;
8454 New_Op_Body
: Node_Id
;
8458 function Build_Dispatching_Subprogram_Body
8461 Prot_Bod
: Node_Id
) return Node_Id
;
8462 -- Build a dispatching version of the protected subprogram body. The
8463 -- newly generated subprogram contains a call to the original protected
8464 -- body. The following code is generated:
8466 -- function <protected-function-name> (Param1 .. ParamN) return
8469 -- return <protected-function-name>P (Param1 .. ParamN);
8470 -- end <protected-function-name>;
8474 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8476 -- <protected-procedure-name>P (Param1 .. ParamN);
8477 -- end <protected-procedure-name>
8479 ---------------------------------------
8480 -- Build_Dispatching_Subprogram_Body --
8481 ---------------------------------------
8483 function Build_Dispatching_Subprogram_Body
8486 Prot_Bod
: Node_Id
) return Node_Id
8488 Loc
: constant Source_Ptr
:= Sloc
(N
);
8495 -- Generate a specification without a letter suffix in order to
8496 -- override an interface function or procedure.
8498 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8500 -- The formal parameters become the actuals of the protected function
8501 -- or procedure call.
8503 Actuals
:= New_List
;
8504 Formal
:= First
(Parameter_Specifications
(Spec
));
8505 while Present
(Formal
) loop
8507 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8511 if Nkind
(Spec
) = N_Procedure_Specification
then
8514 Make_Procedure_Call_Statement
(Loc
,
8516 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8517 Parameter_Associations
=> Actuals
));
8520 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8524 Make_Simple_Return_Statement
(Loc
,
8526 Make_Function_Call
(Loc
,
8528 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8529 Parameter_Associations
=> Actuals
)));
8533 Make_Subprogram_Body
(Loc
,
8534 Declarations
=> Empty_List
,
8535 Specification
=> Spec
,
8536 Handled_Statement_Sequence
=>
8537 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8538 end Build_Dispatching_Subprogram_Body
;
8540 -- Start of processing for Expand_N_Protected_Body
8543 if No_Run_Time_Mode
then
8544 Error_Msg_CRT
("protected body", N
);
8548 -- This is the proper body corresponding to a stub. The declarations
8549 -- must be inserted at the point of the stub, which in turn is in the
8550 -- declarative part of the parent unit.
8552 if Nkind
(Parent
(N
)) = N_Subunit
then
8553 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8558 Op_Body
:= First
(Declarations
(N
));
8560 -- The protected body is replaced with the bodies of its protected
8561 -- operations, and the declarations for internal objects that may
8562 -- have been created for entry family bounds.
8564 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8567 while Present
(Op_Body
) loop
8568 case Nkind
(Op_Body
) is
8569 when N_Subprogram_Declaration
=>
8572 when N_Subprogram_Body
=>
8574 -- Do not create bodies for eliminated operations
8576 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8577 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8579 if Lock_Free_Active
then
8581 Build_Lock_Free_Unprotected_Subprogram_Body
8585 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8588 Insert_After
(Current_Node
, New_Op_Body
);
8589 Current_Node
:= New_Op_Body
;
8590 Analyze
(New_Op_Body
);
8592 -- Build the corresponding protected operation. It may
8593 -- appear that this is needed only if this is a visible
8594 -- operation of the type, or if it is an interrupt handler,
8595 -- and this was the strategy used previously in GNAT.
8597 -- However, the operation may be exported through a 'Access
8598 -- to an external caller. This is the common idiom in code
8599 -- that uses the Ada 2005 Timing_Events package. As a result
8600 -- we need to produce the protected body for both visible
8601 -- and private operations, as well as operations that only
8602 -- have a body in the source, and for which we create a
8603 -- declaration in the protected body itself.
8605 if Present
(Corresponding_Spec
(Op_Body
)) then
8606 if Lock_Free_Active
then
8608 Build_Lock_Free_Protected_Subprogram_Body
8609 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8612 Build_Protected_Subprogram_Body
8613 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8616 Insert_After
(Current_Node
, New_Op_Body
);
8617 Analyze
(New_Op_Body
);
8619 Current_Node
:= New_Op_Body
;
8621 -- Generate an overriding primitive operation body for
8622 -- this subprogram if the protected type implements an
8625 if Ada_Version
>= Ada_2005
8627 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8630 Build_Dispatching_Subprogram_Body
8631 (Op_Body
, Pid
, New_Op_Body
);
8633 Insert_After
(Current_Node
, Disp_Op_Body
);
8634 Analyze
(Disp_Op_Body
);
8636 Current_Node
:= Disp_Op_Body
;
8641 when N_Entry_Body
=>
8642 Op_Id
:= Defining_Identifier
(Op_Body
);
8643 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8645 Insert_After
(Current_Node
, New_Op_Body
);
8646 Current_Node
:= New_Op_Body
;
8647 Analyze
(New_Op_Body
);
8649 when N_Implicit_Label_Declaration
=>
8652 when N_Itype_Reference
=>
8653 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8655 when N_Freeze_Entity
=>
8656 New_Op_Body
:= New_Copy
(Op_Body
);
8658 if Present
(Entity
(Op_Body
))
8659 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8661 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8664 Insert_After
(Current_Node
, New_Op_Body
);
8665 Current_Node
:= New_Op_Body
;
8666 Analyze
(New_Op_Body
);
8669 New_Op_Body
:= New_Copy
(Op_Body
);
8670 Insert_After
(Current_Node
, New_Op_Body
);
8671 Current_Node
:= New_Op_Body
;
8672 Analyze
(New_Op_Body
);
8674 when N_Object_Declaration
=>
8675 pragma Assert
(not Comes_From_Source
(Op_Body
));
8676 New_Op_Body
:= New_Copy
(Op_Body
);
8677 Insert_After
(Current_Node
, New_Op_Body
);
8678 Current_Node
:= New_Op_Body
;
8679 Analyze
(New_Op_Body
);
8682 raise Program_Error
;
8688 -- Finally, create the body of the function that maps an entry index
8689 -- into the corresponding body index, except when there is no entry, or
8690 -- in a Ravenscar-like profile.
8692 if Corresponding_Runtime_Package
(Pid
) =
8693 System_Tasking_Protected_Objects_Entries
8695 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8696 Insert_After
(Current_Node
, New_Op_Body
);
8697 Current_Node
:= New_Op_Body
;
8698 Analyze
(New_Op_Body
);
8701 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8702 -- protected body. At this point all wrapper specs have been created,
8703 -- frozen and included in the dispatch table for the protected type.
8705 if Ada_Version
>= Ada_2005
then
8706 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8708 end Expand_N_Protected_Body
;
8710 -----------------------------------------
8711 -- Expand_N_Protected_Type_Declaration --
8712 -----------------------------------------
8714 -- First we create a corresponding record type declaration used to
8715 -- represent values of this protected type.
8716 -- The general form of this type declaration is
8718 -- type poV (discriminants) is record
8719 -- _Object : aliased <kind>Protection
8720 -- [(<entry count> [, <handler count>])];
8721 -- [entry_family : array (bounds) of Void;]
8722 -- <private data fields>
8725 -- The discriminants are present only if the corresponding protected type
8726 -- has discriminants, and they exactly mirror the protected type
8727 -- discriminants. The private data fields similarly mirror the private
8728 -- declarations of the protected type.
8730 -- The Object field is always present. It contains RTS specific data used
8731 -- to control the protected object. It is declared as Aliased so that it
8732 -- can be passed as a pointer to the RTS. This allows the protected record
8733 -- to be referenced within RTS data structures. An appropriate Protection
8734 -- type and discriminant are generated.
8736 -- The Service field is present for protected objects with entries. It
8737 -- contains sufficient information to allow the entry service procedure for
8738 -- this object to be called when the object is not known till runtime.
8740 -- One entry_family component is present for each entry family in the
8741 -- task definition (see Expand_N_Task_Type_Declaration).
8743 -- When a protected object is declared, an instance of the protected type
8744 -- value record is created. The elaboration of this declaration creates the
8745 -- correct bounds for the entry families, and also evaluates the priority
8746 -- expression if needed. The initialization routine for the protected type
8747 -- itself then calls Initialize_Protection with appropriate parameters to
8748 -- initialize the value of the Task_Id field. Install_Handlers may be also
8749 -- called if a pragma Attach_Handler applies.
8751 -- Note: this record is passed to the subprograms created by the expansion
8752 -- of protected subprograms and entries. It is an in parameter to protected
8753 -- functions and an in out parameter to procedures and entry bodies. The
8754 -- Entity_Id for this created record type is placed in the
8755 -- Corresponding_Record_Type field of the associated protected type entity.
8757 -- Next we create a procedure specifications for protected subprograms and
8758 -- entry bodies. For each protected subprograms two subprograms are
8759 -- created, an unprotected and a protected version. The unprotected version
8760 -- is called from within other operations of the same protected object.
8762 -- We also build the call to register the procedure if a pragma
8763 -- Interrupt_Handler applies.
8765 -- A single subprogram is created to service all entry bodies; it has an
8766 -- additional boolean out parameter indicating that the previous entry call
8767 -- made by the current task was serviced immediately, i.e. not by proxy.
8768 -- The O parameter contains a pointer to a record object of the type
8769 -- described above. An untyped interface is used here to allow this
8770 -- procedure to be called in places where the type of the object to be
8771 -- serviced is not known. This must be done, for example, when a call that
8772 -- may have been requeued is cancelled; the corresponding object must be
8773 -- serviced, but which object that is not known till runtime.
8776 -- (O : System.Address; P : out Boolean);
8777 -- procedure pprocN (_object : in out poV);
8778 -- procedure pproc (_object : in out poV);
8779 -- function pfuncN (_object : poV);
8780 -- function pfunc (_object : poV);
8783 -- Note that this must come after the record type declaration, since
8784 -- the specs refer to this type.
8786 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8787 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8788 Loc
: constant Source_Ptr
:= Sloc
(N
);
8789 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8791 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8792 -- This flag indicates whether the lock free implementation is active
8794 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8795 -- This contains two lists; one for visible and one for private decls
8797 Current_Node
: Node_Id
:= N
;
8799 Entries_Aggr
: Node_Id
;
8801 procedure Check_Inlining
(Subp
: Entity_Id
);
8802 -- If the original operation has a pragma Inline, propagate the flag
8803 -- to the internal body, for possible inlining later on. The source
8804 -- operation is invisible to the back-end and is never actually called.
8806 procedure Expand_Entry_Declaration
(Decl
: Node_Id
);
8807 -- Create the entry barrier and the procedure body for entry declaration
8808 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8810 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8811 -- When compiling under the Ravenscar profile, private components must
8812 -- have a static size, or else a protected object will require heap
8813 -- allocation, violating the corresponding restriction. It is preferable
8814 -- to make this check here, because it provides a better error message
8815 -- than the back-end, which refers to the object as a whole.
8817 procedure Register_Handler
;
8818 -- For a protected operation that is an interrupt handler, add the
8819 -- freeze action that will register it as such.
8821 --------------------
8822 -- Check_Inlining --
8823 --------------------
8825 procedure Check_Inlining
(Subp
: Entity_Id
) is
8827 if Is_Inlined
(Subp
) then
8828 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8829 Set_Is_Inlined
(Subp
, False);
8833 ---------------------------
8834 -- Static_Component_Size --
8835 ---------------------------
8837 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8838 Typ
: constant Entity_Id
:= Etype
(Comp
);
8842 if Is_Scalar_Type
(Typ
) then
8845 elsif Is_Array_Type
(Typ
) then
8846 return Compile_Time_Known_Bounds
(Typ
);
8848 elsif Is_Record_Type
(Typ
) then
8849 C
:= First_Component
(Typ
);
8850 while Present
(C
) loop
8851 if not Static_Component_Size
(C
) then
8860 -- Any other type will be checked by the back-end
8865 end Static_Component_Size
;
8867 ------------------------------
8868 -- Expand_Entry_Declaration --
8869 ------------------------------
8871 procedure Expand_Entry_Declaration
(Decl
: Node_Id
) is
8872 Ent_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
8878 E_Count
:= E_Count
+ 1;
8880 -- Create the protected body subprogram
8883 Make_Defining_Identifier
(Loc
,
8884 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'E'));
8885 Set_Protected_Body_Subprogram
(Ent_Id
, Bod_Id
);
8888 Make_Subprogram_Declaration
(Loc
,
8890 Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Ent_Id
));
8892 Insert_After
(Current_Node
, Subp
);
8893 Current_Node
:= Subp
;
8897 -- Build a wrapper procedure to handle contract cases, preconditions,
8898 -- and postconditions.
8900 Build_Contract_Wrapper
(Ent_Id
, N
);
8902 -- Create the barrier function
8905 Make_Defining_Identifier
(Loc
,
8906 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'B'));
8907 Set_Barrier_Function
(Ent_Id
, Bar_Id
);
8910 Make_Subprogram_Declaration
(Loc
,
8912 Build_Barrier_Function_Specification
(Loc
, Bar_Id
));
8913 Set_Is_Entry_Barrier_Function
(Subp
);
8915 Insert_After
(Current_Node
, Subp
);
8916 Current_Node
:= Subp
;
8920 Set_Protected_Body_Subprogram
(Bar_Id
, Bar_Id
);
8921 Set_Scope
(Bar_Id
, Scope
(Ent_Id
));
8923 -- Collect pointers to the protected subprogram and the barrier
8924 -- of the current entry, for insertion into Entry_Bodies_Array.
8926 Append_To
(Expressions
(Entries_Aggr
),
8927 Make_Aggregate
(Loc
,
8928 Expressions
=> New_List
(
8929 Make_Attribute_Reference
(Loc
,
8930 Prefix
=> New_Occurrence_Of
(Bar_Id
, Loc
),
8931 Attribute_Name
=> Name_Unrestricted_Access
),
8932 Make_Attribute_Reference
(Loc
,
8933 Prefix
=> New_Occurrence_Of
(Bod_Id
, Loc
),
8934 Attribute_Name
=> Name_Unrestricted_Access
))));
8935 end Expand_Entry_Declaration
;
8937 ----------------------
8938 -- Register_Handler --
8939 ----------------------
8941 procedure Register_Handler
is
8943 -- All semantic checks already done in Sem_Prag
8945 Prot_Proc
: constant Entity_Id
:=
8946 Defining_Unit_Name
(Specification
(Current_Node
));
8948 Proc_Address
: constant Node_Id
:=
8949 Make_Attribute_Reference
(Loc
,
8951 New_Occurrence_Of
(Prot_Proc
, Loc
),
8952 Attribute_Name
=> Name_Address
);
8954 RTS_Call
: constant Entity_Id
:=
8955 Make_Procedure_Call_Statement
(Loc
,
8958 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8959 Parameter_Associations
=> New_List
(Proc_Address
));
8961 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8962 end Register_Handler
;
8967 Body_Id
: Entity_Id
;
8973 Object_Comp
: Node_Id
;
8978 -- Start of processing for Expand_N_Protected_Type_Declaration
8981 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8984 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8987 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8989 Qualify_Entity_Names
(N
);
8991 -- If the type has discriminants, their occurrences in the declaration
8992 -- have been replaced by the corresponding discriminals. For components
8993 -- that are constrained by discriminants, their homologues in the
8994 -- corresponding record type must refer to the discriminants of that
8995 -- record, so we must apply a new renaming to subtypes_indications:
8997 -- protected discriminant => discriminal => record discriminant
8999 -- This replacement is not applied to default expressions, for which
9000 -- the discriminal is correct.
9002 if Has_Discriminants
(Prot_Typ
) then
9008 Disc
:= First_Discriminant
(Prot_Typ
);
9009 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
9010 while Present
(Disc
) loop
9011 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
9012 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
9013 Next_Discriminant
(Disc
);
9019 -- Fill in the component declarations
9021 -- Add components for entry families. For each entry family, create an
9022 -- anonymous type declaration with the same size, and analyze the type.
9024 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9026 pragma Assert
(Present
(Pdef
));
9028 Insert_After
(Current_Node
, Rec_Decl
);
9029 Current_Node
:= Rec_Decl
;
9031 -- Add private field components
9033 if Present
(Private_Declarations
(Pdef
)) then
9034 Priv
:= First
(Private_Declarations
(Pdef
));
9035 while Present
(Priv
) loop
9036 if Nkind
(Priv
) = N_Component_Declaration
then
9037 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9039 -- When compiling for a restricted profile, the private
9040 -- components must have a static size. If not, this is an
9041 -- error for a single protected declaration, and rates a
9042 -- warning on a protected type declaration.
9044 if not Comes_From_Source
(Prot_Typ
) then
9046 -- It's ok to be checking this restriction at expansion
9047 -- time, because this is only for the restricted profile,
9048 -- which is not subject to strict RM conformance, so it
9049 -- is OK to miss this check in -gnatc mode.
9051 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9053 (No_Implicit_Protected_Object_Allocations
, Priv
);
9055 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9056 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9058 -- Any object of the type will be non-static
9060 Error_Msg_N
("component has non-static size??", Priv
);
9062 ("\creation of protected object of type& will "
9063 & "violate restriction "
9064 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9066 -- Object will be non-static if discriminants are
9069 ("creation of protected object of type& with "
9070 & "non-static discriminants will violate "
9071 & "restriction No_Implicit_Heap_Allocations??",
9075 -- Likewise for No_Implicit_Protected_Object_Allocations
9077 elsif Restriction_Active
9078 (No_Implicit_Protected_Object_Allocations
)
9080 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9082 -- Any object of the type will be non-static
9084 Error_Msg_N
("component has non-static size??", Priv
);
9086 ("\creation of protected object of type& will "
9087 & "violate restriction "
9088 & "No_Implicit_Protected_Object_Allocations??",
9091 -- Object will be non-static if discriminants are
9094 ("creation of protected object of type& with "
9095 & "non-static discriminants will violate "
9097 & "No_Implicit_Protected_Object_Allocations??",
9103 -- The component definition consists of a subtype indication,
9104 -- or (in Ada 2005) an access definition. Make a copy of the
9105 -- proper definition.
9108 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9109 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9110 Nent
: constant Entity_Id
:=
9111 Make_Defining_Identifier
(Sloc
(Oent
),
9112 Chars
=> Chars
(Oent
));
9116 if Present
(Subtype_Indication
(Old_Comp
)) then
9118 Make_Component_Definition
(Sloc
(Oent
),
9119 Aliased_Present
=> False,
9120 Subtype_Indication
=>
9122 (Subtype_Indication
(Old_Comp
), Discr_Map
));
9125 Make_Component_Definition
(Sloc
(Oent
),
9126 Aliased_Present
=> False,
9127 Access_Definition
=>
9129 (Access_Definition
(Old_Comp
), Discr_Map
));
9133 Make_Component_Declaration
(Loc
,
9134 Defining_Identifier
=> Nent
,
9135 Component_Definition
=> New_Comp
,
9136 Expression
=> Expression
(Priv
));
9138 Set_Has_Per_Object_Constraint
(Nent
,
9139 Has_Per_Object_Constraint
(Oent
));
9141 Append_To
(Cdecls
, New_Priv
);
9144 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9146 -- Make the unprotected version of the subprogram available
9147 -- for expansion of intra object calls. There is need for
9148 -- a protected version only if the subprogram is an interrupt
9149 -- handler, otherwise this operation can only be called from
9153 Make_Subprogram_Declaration
(Loc
,
9155 Build_Protected_Sub_Specification
9156 (Priv
, Prot_Typ
, Unprotected_Mode
));
9158 Insert_After
(Current_Node
, Sub
);
9161 Set_Protected_Body_Subprogram
9162 (Defining_Unit_Name
(Specification
(Priv
)),
9163 Defining_Unit_Name
(Specification
(Sub
)));
9164 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9165 Current_Node
:= Sub
;
9168 Make_Subprogram_Declaration
(Loc
,
9170 Build_Protected_Sub_Specification
9171 (Priv
, Prot_Typ
, Protected_Mode
));
9173 Insert_After
(Current_Node
, Sub
);
9175 Current_Node
:= Sub
;
9177 if Is_Interrupt_Handler
9178 (Defining_Unit_Name
(Specification
(Priv
)))
9180 if not Restricted_Profile
then
9190 -- Except for the lock-free implementation, append the _Object field
9191 -- with the right type to the component list. We need to compute the
9192 -- number of entries, and in some cases the number of Attach_Handler
9195 if not Lock_Free_Active
then
9197 Entry_Count_Expr
: constant Node_Id
:=
9198 Build_Entry_Count_Expression
9199 (Prot_Typ
, Cdecls
, Loc
);
9200 Num_Attach_Handler
: Nat
:= 0;
9201 Protection_Subtype
: Node_Id
;
9205 if Has_Attach_Handler
(Prot_Typ
) then
9206 Ritem
:= First_Rep_Item
(Prot_Typ
);
9207 while Present
(Ritem
) loop
9208 if Nkind
(Ritem
) = N_Pragma
9209 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9211 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9214 Next_Rep_Item
(Ritem
);
9218 -- Determine the proper protection type. There are two special
9219 -- cases: 1) when the protected type has dynamic interrupt
9220 -- handlers, and 2) when it has static handlers and we use a
9221 -- restricted profile.
9223 if Has_Attach_Handler
(Prot_Typ
)
9224 and then not Restricted_Profile
9226 Protection_Subtype
:=
9227 Make_Subtype_Indication
(Loc
,
9230 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9232 Make_Index_Or_Discriminant_Constraint
(Loc
,
9233 Constraints
=> New_List
(
9235 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9237 elsif Has_Interrupt_Handler
(Prot_Typ
)
9238 and then not Restriction_Active
(No_Dynamic_Attachment
)
9240 Protection_Subtype
:=
9241 Make_Subtype_Indication
(Loc
,
9244 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9246 Make_Index_Or_Discriminant_Constraint
(Loc
,
9247 Constraints
=> New_List
(Entry_Count_Expr
)));
9250 case Corresponding_Runtime_Package
(Prot_Typ
) is
9251 when System_Tasking_Protected_Objects_Entries
=>
9252 Protection_Subtype
:=
9253 Make_Subtype_Indication
(Loc
,
9256 (RTE
(RE_Protection_Entries
), Loc
),
9258 Make_Index_Or_Discriminant_Constraint
(Loc
,
9259 Constraints
=> New_List
(Entry_Count_Expr
)));
9261 when System_Tasking_Protected_Objects_Single_Entry
=>
9262 Protection_Subtype
:=
9263 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9265 when System_Tasking_Protected_Objects
=>
9266 Protection_Subtype
:=
9267 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9270 raise Program_Error
;
9275 Make_Component_Declaration
(Loc
,
9276 Defining_Identifier
=>
9277 Make_Defining_Identifier
(Loc
, Name_uObject
),
9278 Component_Definition
=>
9279 Make_Component_Definition
(Loc
,
9280 Aliased_Present
=> True,
9281 Subtype_Indication
=> Protection_Subtype
));
9284 -- Put the _Object component after the private component so that it
9285 -- be finalized early as required by 9.4 (20)
9287 Append_To
(Cdecls
, Object_Comp
);
9290 -- Analyze the record declaration immediately after construction,
9291 -- because the initialization procedure is needed for single object
9292 -- declarations before the next entity is analyzed (the freeze call
9293 -- that generates this initialization procedure is found below).
9295 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9297 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9298 -- the corresponding record is frozen. If any wrappers are generated,
9299 -- Current_Node is updated accordingly.
9301 if Ada_Version
>= Ada_2005
then
9302 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9305 -- Collect pointers to entry bodies and their barriers, to be placed
9306 -- in the Entry_Bodies_Array for the type. For each entry/family we
9307 -- add an expression to the aggregate which is the initial value of
9308 -- this array. The array is declared after all protected subprograms.
9310 if Has_Entries
(Prot_Typ
) then
9311 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9313 Entries_Aggr
:= Empty
;
9316 -- Build two new procedure specifications for each protected subprogram;
9317 -- one to call from outside the object and one to call from inside.
9318 -- Build a barrier function and an entry body action procedure
9319 -- specification for each protected entry. Initialize the entry body
9320 -- array. If subprogram is flagged as eliminated, do not generate any
9321 -- internal operations.
9324 Comp
:= First
(Visible_Declarations
(Pdef
));
9325 while Present
(Comp
) loop
9326 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9328 Make_Subprogram_Declaration
(Loc
,
9330 Build_Protected_Sub_Specification
9331 (Comp
, Prot_Typ
, Unprotected_Mode
));
9333 Insert_After
(Current_Node
, Sub
);
9336 Set_Protected_Body_Subprogram
9337 (Defining_Unit_Name
(Specification
(Comp
)),
9338 Defining_Unit_Name
(Specification
(Sub
)));
9339 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9341 -- Make the protected version of the subprogram available for
9342 -- expansion of external calls.
9344 Current_Node
:= Sub
;
9347 Make_Subprogram_Declaration
(Loc
,
9349 Build_Protected_Sub_Specification
9350 (Comp
, Prot_Typ
, Protected_Mode
));
9352 Insert_After
(Current_Node
, Sub
);
9355 Current_Node
:= Sub
;
9357 -- Generate an overriding primitive operation specification for
9358 -- this subprogram if the protected type implements an interface
9359 -- and Build_Wrapper_Spec did not generate its wrapper.
9361 if Ada_Version
>= Ada_2005
9363 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9366 Found
: Boolean := False;
9367 Prim_Elmt
: Elmt_Id
;
9373 (Primitive_Operations
9374 (Corresponding_Record_Type
(Prot_Typ
)));
9376 while Present
(Prim_Elmt
) loop
9377 Prim_Op
:= Node
(Prim_Elmt
);
9379 if Is_Primitive_Wrapper
(Prim_Op
)
9380 and then Wrapped_Entity
(Prim_Op
) =
9381 Defining_Entity
(Specification
(Comp
))
9387 Next_Elmt
(Prim_Elmt
);
9392 Make_Subprogram_Declaration
(Loc
,
9394 Build_Protected_Sub_Specification
9395 (Comp
, Prot_Typ
, Dispatching_Mode
));
9397 Insert_After
(Current_Node
, Sub
);
9400 Current_Node
:= Sub
;
9405 -- If a pragma Interrupt_Handler applies, build and add a call to
9406 -- Register_Interrupt_Handler to the freezing actions of the
9407 -- protected version (Current_Node) of the subprogram:
9409 -- system.interrupts.register_interrupt_handler
9410 -- (prot_procP'address);
9412 if not Restricted_Profile
9413 and then Is_Interrupt_Handler
9414 (Defining_Unit_Name
(Specification
(Comp
)))
9419 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9420 Expand_Entry_Declaration
(Comp
);
9426 -- If there are some private entry declarations, expand it as if they
9427 -- were visible entries.
9429 if Present
(Private_Declarations
(Pdef
)) then
9430 Comp
:= First
(Private_Declarations
(Pdef
));
9431 while Present
(Comp
) loop
9432 if Nkind
(Comp
) = N_Entry_Declaration
then
9433 Expand_Entry_Declaration
(Comp
);
9440 -- Create the declaration of an array object which contains the values
9441 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9442 -- type. This object is later passed to the appropriate protected object
9443 -- initialization routine.
9445 if Has_Entries
(Prot_Typ
)
9446 and then Corresponding_Runtime_Package
(Prot_Typ
) =
9447 System_Tasking_Protected_Objects_Entries
9454 Maxes_Id
: Entity_Id
;
9455 Need_Array
: Boolean := False;
9458 -- First check if there is any Max_Queue_Length pragma
9460 Item
:= First_Entity
(Prot_Typ
);
9461 while Present
(Item
) loop
9462 if Is_Entry
(Item
) and then Has_Max_Queue_Length
(Item
) then
9470 -- Gather the Max_Queue_Length values of all entries in a list. A
9471 -- value of zero indicates that the entry has no limitation on its
9476 Item
:= First_Entity
(Prot_Typ
);
9478 while Present
(Item
) loop
9479 if Is_Entry
(Item
) then
9482 Make_Integer_Literal
9483 (Loc
, Get_Max_Queue_Length
(Item
)));
9489 -- Create the declaration of the array object. Generate:
9491 -- Maxes_Id : aliased constant
9492 -- Protected_Entry_Queue_Max_Array
9493 -- (1 .. Count) := (..., ...);
9496 Make_Defining_Identifier
(Loc
,
9497 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'B'));
9500 Make_Object_Declaration
(Loc
,
9501 Defining_Identifier
=> Maxes_Id
,
9502 Aliased_Present
=> True,
9503 Constant_Present
=> True,
9504 Object_Definition
=>
9505 Make_Subtype_Indication
(Loc
,
9508 (RTE
(RE_Protected_Entry_Queue_Max_Array
), Loc
),
9510 Make_Index_Or_Discriminant_Constraint
(Loc
,
9511 Constraints
=> New_List
(
9513 Make_Integer_Literal
(Loc
, 1),
9514 Make_Integer_Literal
(Loc
, Count
))))),
9515 Expression
=> Make_Aggregate
(Loc
, Maxes
));
9517 -- A pointer to this array will be placed in the corresponding
9518 -- record by its initialization procedure so this needs to be
9521 Insert_After
(Current_Node
, Max_Vals
);
9522 Current_Node
:= Max_Vals
;
9525 Set_Entry_Max_Queue_Lengths_Array
(Prot_Typ
, Maxes_Id
);
9530 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9531 -- all protected subprograms have been collected.
9533 if Has_Entries
(Prot_Typ
) then
9535 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9536 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9538 case Corresponding_Runtime_Package
(Prot_Typ
) is
9539 when System_Tasking_Protected_Objects_Entries
=>
9540 Expr
:= Entries_Aggr
;
9542 Make_Subtype_Indication
(Loc
,
9545 (RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9547 Make_Index_Or_Discriminant_Constraint
(Loc
,
9548 Constraints
=> New_List
(
9550 Make_Integer_Literal
(Loc
, 1),
9551 Make_Integer_Literal
(Loc
, E_Count
)))));
9553 when System_Tasking_Protected_Objects_Single_Entry
=>
9554 Expr
:= Remove_Head
(Expressions
(Entries_Aggr
));
9555 Obj_Def
:= New_Occurrence_Of
(RTE
(RE_Entry_Body
), Loc
);
9558 raise Program_Error
;
9562 Make_Object_Declaration
(Loc
,
9563 Defining_Identifier
=> Body_Id
,
9564 Aliased_Present
=> True,
9565 Constant_Present
=> True,
9566 Object_Definition
=> Obj_Def
,
9567 Expression
=> Expr
);
9569 -- A pointer to this array will be placed in the corresponding record
9570 -- by its initialization procedure so this needs to be analyzed here.
9572 Insert_After
(Current_Node
, Body_Arr
);
9573 Current_Node
:= Body_Arr
;
9576 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9578 -- Finally, build the function that maps an entry index into the
9579 -- corresponding body. A pointer to this function is placed in each
9580 -- object of the type. Except for a ravenscar-like profile (no abort,
9581 -- no entry queue, 1 entry)
9583 if Corresponding_Runtime_Package
(Prot_Typ
) =
9584 System_Tasking_Protected_Objects_Entries
9587 Make_Subprogram_Declaration
(Loc
,
9588 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9590 Insert_After
(Current_Node
, Sub
);
9594 end Expand_N_Protected_Type_Declaration
;
9596 --------------------------------
9597 -- Expand_N_Requeue_Statement --
9598 --------------------------------
9600 -- A nondispatching requeue statement is expanded into one of four GNARLI
9601 -- operations, depending on the source and destination (task or protected
9602 -- object). A dispatching requeue statement is expanded into a call to the
9603 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9604 -- jump around the remainder of processing for the original entry and, if
9605 -- the destination is (different) protected object, to attempt to service
9606 -- it. The following illustrates the various cases:
9609 -- (O : System.Address;
9610 -- P : System.Address;
9611 -- E : Protected_Entry_Index)
9613 -- <discriminant renamings>
9614 -- <private object renamings>
9615 -- type poVP is access poV;
9616 -- _object : ptVP := ptVP!(O);
9620 -- <start of statement sequence for entry>
9622 -- -- Requeue from one protected entry body to another protected
9625 -- Requeue_Protected_Entry (
9626 -- _object._object'Access,
9627 -- new._object'Access,
9632 -- <some more of the statement sequence for entry>
9634 -- -- Requeue from an entry body to a task entry
9636 -- Requeue_Protected_To_Task_Entry (
9642 -- <rest of statement sequence for entry>
9643 -- Complete_Entry_Body (_object._object);
9646 -- when all others =>
9647 -- Exceptional_Complete_Entry_Body (
9648 -- _object._object, Get_GNAT_Exception);
9652 -- Requeue of a task entry call to a task entry
9654 -- Accept_Call (E, Ann);
9655 -- <start of statement sequence for accept statement>
9656 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9658 -- <rest of statement sequence for accept statement>
9660 -- Complete_Rendezvous;
9663 -- when all others =>
9664 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9666 -- Requeue of a task entry call to a protected entry
9668 -- Accept_Call (E, Ann);
9669 -- <start of statement sequence for accept statement>
9670 -- Requeue_Task_To_Protected_Entry (
9671 -- new._object'Access,
9676 -- <rest of statement sequence for accept statement>
9678 -- Complete_Rendezvous;
9681 -- when all others =>
9682 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9684 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9685 -- marked by pragma Implemented (XXX, By_Entry).
9687 -- The requeue is inside a protected entry:
9690 -- (O : System.Address;
9691 -- P : System.Address;
9692 -- E : Protected_Entry_Index)
9694 -- <discriminant renamings>
9695 -- <private object renamings>
9696 -- type poVP is access poV;
9697 -- _object : ptVP := ptVP!(O);
9701 -- <start of statement sequence for entry>
9704 -- (<interface class-wide object>,
9707 -- Ada.Tags.Get_Offset_Index
9709 -- <interface dispatch table index of target entry>),
9713 -- <rest of statement sequence for entry>
9714 -- Complete_Entry_Body (_object._object);
9717 -- when all others =>
9718 -- Exceptional_Complete_Entry_Body (
9719 -- _object._object, Get_GNAT_Exception);
9723 -- The requeue is inside a task entry:
9725 -- Accept_Call (E, Ann);
9726 -- <start of statement sequence for accept statement>
9728 -- (<interface class-wide object>,
9731 -- Ada.Tags.Get_Offset_Index
9733 -- <interface dispatch table index of target entrt>),
9737 -- <rest of statement sequence for accept statement>
9739 -- Complete_Rendezvous;
9742 -- when all others =>
9743 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9745 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9746 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9747 -- statement is replaced by a dispatching call with actual parameters taken
9748 -- from the inner-most accept statement or entry body.
9750 -- Target.Primitive (Param1, ..., ParamN);
9752 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9753 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9757 -- S : constant Offset_Index :=
9758 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9759 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9762 -- if C = POK_Protected_Entry
9763 -- or else C = POK_Task_Entry
9765 -- <statements for dispatching requeue>
9767 -- elsif C = POK_Protected_Procedure then
9768 -- <dispatching call equivalent>
9771 -- raise Program_Error;
9775 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9776 Loc
: constant Source_Ptr
:= Sloc
(N
);
9777 Conc_Typ
: Entity_Id
;
9781 Old_Typ
: Entity_Id
;
9783 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9784 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9785 -- the form Concval.Ename. It is statically known that Ename is allowed
9786 -- to be implemented by a protected procedure. Create a dispatching call
9787 -- equivalent of Concval.Ename taking the actual parameters from the
9788 -- inner-most accept statement or entry body.
9790 function Build_Dispatching_Requeue
return Node_Id
;
9791 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9792 -- the form Concval.Ename. It is statically known that Ename is allowed
9793 -- to be implemented by a protected or a task entry. Create a call to
9794 -- primitive _Disp_Requeue which handles the low-level actions.
9796 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9797 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9798 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9799 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9800 -- determines at runtime whether Ename denotes an entry or a procedure
9801 -- and perform the appropriate kind of dispatching select.
9803 function Build_Normal_Requeue
return Node_Id
;
9804 -- N denotes a nondispatching requeue statement to either a task or a
9805 -- protected entry. Build the appropriate runtime call to perform the
9808 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9809 -- For a protected entry, create a return statement to skip the rest of
9810 -- the entry body. Otherwise, create a goto statement to skip the rest
9811 -- of a task accept statement. The lookup for the enclosing entry body
9812 -- or accept statement starts from Search.
9814 ---------------------------------------
9815 -- Build_Dispatching_Call_Equivalent --
9816 ---------------------------------------
9818 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9819 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9820 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9827 -- Climb the parent chain looking for the inner-most entry body or
9828 -- accept statement.
9831 while Present
(Acc_Ent
)
9832 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9835 Acc_Ent
:= Parent
(Acc_Ent
);
9838 -- A requeue statement should be housed inside an entry body or an
9839 -- accept statement at some level. If this is not the case, then the
9840 -- tree is malformed.
9842 pragma Assert
(Present
(Acc_Ent
));
9844 -- Recover the list of formal parameters
9846 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9847 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9850 Formals
:= Parameter_Specifications
(Acc_Ent
);
9852 -- Create the actual parameters for the dispatching call. These are
9853 -- simply copies of the entry body or accept statement formals in the
9854 -- same order as they appear.
9858 if Present
(Formals
) then
9859 Actuals
:= New_List
;
9860 Formal
:= First
(Formals
);
9861 while Present
(Formal
) loop
9863 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9869 -- Obj.Call_Ent (Actuals);
9872 Make_Procedure_Call_Statement
(Loc
,
9874 Make_Selected_Component
(Loc
,
9875 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9876 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9878 Parameter_Associations
=> Actuals
);
9879 end Build_Dispatching_Call_Equivalent
;
9881 -------------------------------
9882 -- Build_Dispatching_Requeue --
9883 -------------------------------
9885 function Build_Dispatching_Requeue
return Node_Id
is
9886 Params
: constant List_Id
:= New_List
;
9889 -- Process the "with abort" parameter
9892 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9894 -- Process the entry wrapper's position in the primary dispatch
9895 -- table parameter. Generate:
9897 -- Ada.Tags.Get_Entry_Index
9898 -- (T => To_Tag_Ptr (Obj'Address).all,
9900 -- Ada.Tags.Get_Offset_Index
9901 -- (Ada.Tags.Tag (Concval),
9902 -- <interface dispatch table position of Ename>));
9904 -- Note that Obj'Address is recursively expanded into a call to
9905 -- Base_Address (Obj).
9907 if Tagged_Type_Expansion
then
9909 Make_Function_Call
(Loc
,
9910 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9911 Parameter_Associations
=> New_List
(
9913 Make_Explicit_Dereference
(Loc
,
9914 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9915 Make_Attribute_Reference
(Loc
,
9916 Prefix
=> New_Copy_Tree
(Concval
),
9917 Attribute_Name
=> Name_Address
))),
9919 Make_Function_Call
(Loc
,
9920 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9921 Parameter_Associations
=> New_List
(
9922 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9923 Make_Integer_Literal
(Loc
,
9924 DT_Position
(Entity
(Ename
))))))));
9930 Make_Function_Call
(Loc
,
9931 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9932 Parameter_Associations
=> New_List
(
9934 Make_Attribute_Reference
(Loc
,
9936 Attribute_Name
=> Name_Tag
),
9938 Make_Function_Call
(Loc
,
9939 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9941 Parameter_Associations
=> New_List
(
9945 Make_Attribute_Reference
(Loc
,
9947 Attribute_Name
=> Name_Tag
),
9951 Make_Attribute_Reference
(Loc
,
9952 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9953 Attribute_Name
=> Name_Tag
),
9957 Make_Integer_Literal
(Loc
,
9958 DT_Position
(Entity
(Ename
))))))));
9961 -- Specific actuals for protected to XXX requeue
9963 if Is_Protected_Type
(Old_Typ
) then
9965 Make_Attribute_Reference
(Loc
, -- _object'Address
9967 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9968 Attribute_Name
=> Name_Address
));
9970 Prepend_To
(Params
, -- True
9971 New_Occurrence_Of
(Standard_True
, Loc
));
9973 -- Specific actuals for task to XXX requeue
9976 pragma Assert
(Is_Task_Type
(Old_Typ
));
9978 Prepend_To
(Params
, -- null
9979 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9981 Prepend_To
(Params
, -- False
9982 New_Occurrence_Of
(Standard_False
, Loc
));
9985 -- Add the object parameter
9987 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9990 -- _Disp_Requeue (<Params>);
9992 -- Find entity for Disp_Requeue operation, which belongs to
9993 -- the type and may not be directly visible.
9998 pragma Warnings
(Off
, Op
);
10001 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
10002 while Present
(Elmt
) loop
10004 exit when Chars
(Op
) = Name_uDisp_Requeue
;
10009 Make_Procedure_Call_Statement
(Loc
,
10010 Name
=> New_Occurrence_Of
(Op
, Loc
),
10011 Parameter_Associations
=> Params
);
10013 end Build_Dispatching_Requeue
;
10015 --------------------------------------
10016 -- Build_Dispatching_Requeue_To_Any --
10017 --------------------------------------
10019 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
10020 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
10021 Obj
: constant Node_Id
:= Original_Node
(Concval
);
10022 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
10032 -- Dispatch table slot processing, generate:
10035 S
:= Build_S
(Loc
, Decls
);
10037 -- Call kind processing, generate:
10038 -- C : Ada.Tags.Prim_Op_Kind;
10040 C
:= Build_C
(Loc
, Decls
);
10043 -- S := Ada.Tags.Get_Offset_Index
10044 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10046 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10049 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10052 Make_Procedure_Call_Statement
(Loc
,
10054 New_Occurrence_Of
(
10055 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10056 Name_uDisp_Get_Prim_Op_Kind
),
10058 Parameter_Associations
=> New_List
(
10059 New_Copy_Tree
(Obj
),
10060 New_Occurrence_Of
(S
, Loc
),
10061 New_Occurrence_Of
(C
, Loc
))));
10065 -- if C = POK_Protected_Entry
10066 -- or else C = POK_Task_Entry
10069 Make_Implicit_If_Statement
(N
,
10075 New_Occurrence_Of
(C
, Loc
),
10077 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10082 New_Occurrence_Of
(C
, Loc
),
10084 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10086 -- Dispatching requeue equivalent
10088 Then_Statements
=> New_List
(
10089 Build_Dispatching_Requeue
,
10092 -- elsif C = POK_Protected_Procedure then
10094 Elsif_Parts
=> New_List
(
10095 Make_Elsif_Part
(Loc
,
10099 New_Occurrence_Of
(C
, Loc
),
10101 New_Occurrence_Of
(
10102 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10104 -- Dispatching call equivalent
10106 Then_Statements
=> New_List
(
10107 Build_Dispatching_Call_Equivalent
))),
10110 -- raise Program_Error;
10113 Else_Statements
=> New_List
(
10114 Make_Raise_Program_Error
(Loc
,
10115 Reason
=> PE_Explicit_Raise
))));
10117 -- Wrap everything into a block
10120 Make_Block_Statement
(Loc
,
10121 Declarations
=> Decls
,
10122 Handled_Statement_Sequence
=>
10123 Make_Handled_Sequence_Of_Statements
(Loc
,
10124 Statements
=> Stmts
));
10125 end Build_Dispatching_Requeue_To_Any
;
10127 --------------------------
10128 -- Build_Normal_Requeue --
10129 --------------------------
10131 function Build_Normal_Requeue
return Node_Id
is
10132 Params
: constant List_Id
:= New_List
;
10137 -- Process the "with abort" parameter
10139 Prepend_To
(Params
,
10140 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10142 -- Add the index expression to the parameters. It is common among all
10145 Prepend_To
(Params
,
10146 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10148 if Is_Protected_Type
(Old_Typ
) then
10150 Self_Param
: Node_Id
;
10154 Make_Attribute_Reference
(Loc
,
10156 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10158 Name_Unchecked_Access
);
10160 -- Protected to protected requeue
10162 if Is_Protected_Type
(Conc_Typ
) then
10164 New_Occurrence_Of
(
10165 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10168 Make_Attribute_Reference
(Loc
,
10170 Concurrent_Ref
(Concval
),
10172 Name_Unchecked_Access
);
10174 -- Protected to task requeue
10176 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10178 New_Occurrence_Of
(
10179 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10181 Param
:= Concurrent_Ref
(Concval
);
10184 Prepend_To
(Params
, Param
);
10185 Prepend_To
(Params
, Self_Param
);
10188 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10190 -- Task to protected requeue
10192 if Is_Protected_Type
(Conc_Typ
) then
10194 New_Occurrence_Of
(
10195 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10198 Make_Attribute_Reference
(Loc
,
10200 Concurrent_Ref
(Concval
),
10202 Name_Unchecked_Access
);
10204 -- Task to task requeue
10206 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10208 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10210 Param
:= Concurrent_Ref
(Concval
);
10213 Prepend_To
(Params
, Param
);
10217 Make_Procedure_Call_Statement
(Loc
,
10219 Parameter_Associations
=> Params
);
10220 end Build_Normal_Requeue
;
10222 --------------------------
10223 -- Build_Skip_Statement --
10224 --------------------------
10226 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10227 Skip_Stmt
: Node_Id
;
10230 -- Build a return statement to skip the rest of the entire body
10232 if Is_Protected_Type
(Old_Typ
) then
10233 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10235 -- If the requeue is within a task, find the end label of the
10236 -- enclosing accept statement and create a goto statement to it.
10244 -- Climb the parent chain looking for the enclosing accept
10247 Acc
:= Parent
(Search
);
10248 while Present
(Acc
)
10249 and then Nkind
(Acc
) /= N_Accept_Statement
10251 Acc
:= Parent
(Acc
);
10254 -- The last statement is the second label used for completing
10255 -- the rendezvous the usual way. The label we are looking for
10256 -- is right before it.
10259 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10261 pragma Assert
(Nkind
(Label
) = N_Label
);
10263 -- Generate a goto statement to skip the rest of the accept
10266 Make_Goto_Statement
(Loc
,
10268 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10272 Set_Analyzed
(Skip_Stmt
);
10275 end Build_Skip_Statement
;
10277 -- Start of processing for Expand_N_Requeue_Statement
10280 -- Extract the components of the entry call
10282 Extract_Entry
(N
, Concval
, Ename
, Index
);
10283 Conc_Typ
:= Etype
(Concval
);
10285 -- If the prefix is an access to class-wide type, dereference to get
10286 -- object and entry type.
10288 if Is_Access_Type
(Conc_Typ
) then
10289 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10291 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10292 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10295 -- Examine the scope stack in order to find nearest enclosing protected
10296 -- or task type. This will constitute our invocation source.
10298 Old_Typ
:= Current_Scope
;
10299 while Present
(Old_Typ
)
10300 and then not Is_Protected_Type
(Old_Typ
)
10301 and then not Is_Task_Type
(Old_Typ
)
10303 Old_Typ
:= Scope
(Old_Typ
);
10306 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10307 -- Concval.Ename where the type of Concval is class-wide concurrent
10310 if Ada_Version
>= Ada_2012
10311 and then Present
(Concval
)
10312 and then Is_Class_Wide_Type
(Conc_Typ
)
10313 and then Is_Concurrent_Interface
(Conc_Typ
)
10316 Has_Impl
: Boolean := False;
10317 Impl_Kind
: Name_Id
:= No_Name
;
10320 -- Check whether the Ename is flagged by pragma Implemented
10322 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10324 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10327 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10328 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10330 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10331 Rewrite
(N
, Build_Dispatching_Requeue
);
10333 Insert_After
(N
, Build_Skip_Statement
(N
));
10335 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10336 -- a protected procedure. In this case the requeue is transformed
10337 -- into a dispatching call.
10340 and then Impl_Kind
= Name_By_Protected_Procedure
10342 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10345 -- The procedure_or_entry_NAME's implementation kind is either
10346 -- By_Any, Optional, or pragma Implemented was not applied at all.
10347 -- In this case a runtime test determines whether Ename denotes an
10348 -- entry or a protected procedure and performs the appropriate
10352 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10357 -- Processing for regular (nondispatching) requeues
10360 Rewrite
(N
, Build_Normal_Requeue
);
10362 Insert_After
(N
, Build_Skip_Statement
(N
));
10364 end Expand_N_Requeue_Statement
;
10366 -------------------------------
10367 -- Expand_N_Selective_Accept --
10368 -------------------------------
10370 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10371 Loc
: constant Source_Ptr
:= Sloc
(N
);
10372 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10374 -- Note: in the below declarations a lot of new lists are allocated
10375 -- unconditionally which may well not end up being used. That's not
10376 -- a good idea since it wastes space gratuitously ???
10378 Accept_Case
: List_Id
;
10379 Accept_List
: constant List_Id
:= New_List
;
10382 Alt_List
: constant List_Id
:= New_List
;
10383 Alt_Stats
: List_Id
;
10384 Ann
: Entity_Id
:= Empty
;
10386 Check_Guard
: Boolean := True;
10388 Decls
: constant List_Id
:= New_List
;
10389 Stats
: constant List_Id
:= New_List
;
10390 Body_List
: constant List_Id
:= New_List
;
10391 Trailing_List
: constant List_Id
:= New_List
;
10394 Else_Present
: Boolean := False;
10395 Terminate_Alt
: Node_Id
:= Empty
;
10396 Select_Mode
: Node_Id
;
10398 Delay_Case
: List_Id
;
10399 Delay_Count
: Integer := 0;
10400 Delay_Val
: Entity_Id
;
10401 Delay_Index
: Entity_Id
;
10402 Delay_Min
: Entity_Id
;
10403 Delay_Num
: Pos
:= 1;
10404 Delay_Alt_List
: List_Id
:= New_List
;
10405 Delay_List
: constant List_Id
:= New_List
;
10409 First_Delay
: Boolean := True;
10410 Guard_Open
: Entity_Id
;
10416 Num_Accept
: Nat
:= 0;
10418 Time_Type
: Entity_Id
;
10419 Select_Call
: Node_Id
;
10421 Qnam
: constant Entity_Id
:=
10422 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10424 Xnam
: constant Entity_Id
:=
10425 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10427 -----------------------
10428 -- Local subprograms --
10429 -----------------------
10431 function Accept_Or_Raise
return List_Id
;
10432 -- For the rare case where delay alternatives all have guards, and
10433 -- all of them are closed, it is still possible that there were open
10434 -- accept alternatives with no callers. We must reexamine the
10435 -- Accept_List, and execute a selective wait with no else if some
10436 -- accept is open. If none, we raise program_error.
10438 procedure Add_Accept
(Alt
: Node_Id
);
10439 -- Process a single accept statement in a select alternative. Build
10440 -- procedure for body of accept, and add entry to dispatch table with
10441 -- expression for guard, in preparation for call to run time select.
10443 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10444 -- Manufacture a label using Num as a serial number and declare it.
10445 -- The declaration is appended to Decls. The label marks the trailing
10446 -- statements of an accept or delay alternative.
10448 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10449 -- Build call to Selective_Wait runtime routine
10451 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10452 -- Add code to compare value of delay with previous values, and
10453 -- generate case entry for trailing statements.
10455 procedure Process_Accept_Alternative
10459 -- Add code to call corresponding procedure, and branch to
10460 -- trailing statements, if any.
10462 ---------------------
10463 -- Accept_Or_Raise --
10464 ---------------------
10466 function Accept_Or_Raise
return List_Id
is
10469 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10472 -- We generate the following:
10474 -- for J in q'range loop
10475 -- if q(J).S /=null_task_entry then
10476 -- selective_wait (simple_mode,...);
10482 -- if no rendez_vous then
10483 -- raise program_error;
10486 -- Note that the code needs to know that the selector name
10487 -- in an Accept_Alternative is named S.
10489 Cond
:= Make_Op_Ne
(Loc
,
10491 Make_Selected_Component
(Loc
,
10493 Make_Indexed_Component
(Loc
,
10494 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10495 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10496 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10498 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10500 Stats
:= New_List
(
10501 Make_Implicit_Loop_Statement
(N
,
10502 Iteration_Scheme
=>
10503 Make_Iteration_Scheme
(Loc
,
10504 Loop_Parameter_Specification
=>
10505 Make_Loop_Parameter_Specification
(Loc
,
10506 Defining_Identifier
=> J
,
10507 Discrete_Subtype_Definition
=>
10508 Make_Attribute_Reference
(Loc
,
10509 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10510 Attribute_Name
=> Name_Range
,
10511 Expressions
=> New_List
(
10512 Make_Integer_Literal
(Loc
, 1))))),
10514 Statements
=> New_List
(
10515 Make_Implicit_If_Statement
(N
,
10517 Then_Statements
=> New_List
(
10519 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10520 Make_Exit_Statement
(Loc
))))));
10523 Make_Raise_Program_Error
(Loc
,
10524 Condition
=> Make_Op_Eq
(Loc
,
10525 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10527 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10528 Reason
=> PE_All_Guards_Closed
));
10531 end Accept_Or_Raise
;
10537 procedure Add_Accept
(Alt
: Node_Id
) is
10538 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10539 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10540 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10541 Eent
: constant Entity_Id
:= Entity
(Ename
);
10542 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10543 Null_Body
: Node_Id
;
10544 Proc_Body
: Node_Id
;
10545 PB_Ent
: Entity_Id
;
10551 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10554 if Present
(Condition
(Alt
)) then
10556 Make_If_Expression
(Eloc
, New_List
(
10558 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10559 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10562 Entry_Index_Expression
10563 (Eloc
, Eent
, Index
, Scope
(Eent
));
10566 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10567 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10569 -- Always add call to Abort_Undefer when generating code, since
10570 -- this is what the runtime expects (abort deferred in
10571 -- Selective_Wait). In CodePeer mode this only confuses the
10572 -- analysis with unknown calls, so don't do it.
10574 if not CodePeer_Mode
then
10575 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10577 (First
(Statements
(Handled_Statement_Sequence
10578 (Accept_Statement
(Alt
)))),
10584 Make_Defining_Identifier
(Eloc
,
10585 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10587 -- Link the acceptor to the original receiving entry
10589 Set_Ekind
(PB_Ent
, E_Procedure
);
10590 Set_Receiving_Entry
(PB_Ent
, Eent
);
10592 if Comes_From_Source
(Alt
) then
10593 Set_Debug_Info_Needed
(PB_Ent
);
10597 Make_Subprogram_Body
(Eloc
,
10599 Make_Procedure_Specification
(Eloc
,
10600 Defining_Unit_Name
=> PB_Ent
),
10601 Declarations
=> Declarations
(Acc_Stm
),
10602 Handled_Statement_Sequence
=>
10603 Build_Accept_Body
(Accept_Statement
(Alt
)));
10605 -- During the analysis of the body of the accept statement, any
10606 -- zero cost exception handler records were collected in the
10607 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10608 -- This is where we move them to where they belong, namely the
10609 -- newly created procedure.
10611 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10612 Append
(Proc_Body
, Body_List
);
10615 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10617 -- if accept statement has declarations, insert above, given that
10618 -- we are not creating a body for the accept.
10620 if Present
(Declarations
(Acc_Stm
)) then
10621 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10625 Append_To
(Accept_List
,
10626 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10628 Num_Accept
:= Num_Accept
+ 1;
10631 ----------------------------
10632 -- Make_And_Declare_Label --
10633 ----------------------------
10635 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10639 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10641 Make_Label
(Loc
, Lab_Id
);
10644 Make_Implicit_Label_Declaration
(Loc
,
10645 Defining_Identifier
=>
10646 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10647 Label_Construct
=> Lab
));
10650 end Make_And_Declare_Label
;
10652 ----------------------
10653 -- Make_Select_Call --
10654 ----------------------
10656 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10657 Params
: constant List_Id
:= New_List
;
10661 Make_Attribute_Reference
(Loc
,
10662 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10663 Attribute_Name
=> Name_Unchecked_Access
));
10664 Append_To
(Params
, Select_Mode
);
10665 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10666 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10669 Make_Procedure_Call_Statement
(Loc
,
10670 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10671 Parameter_Associations
=> Params
);
10672 end Make_Select_Call
;
10674 --------------------------------
10675 -- Process_Accept_Alternative --
10676 --------------------------------
10678 procedure Process_Accept_Alternative
10683 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10684 Alt_Stats
: List_Id
;
10687 Adjust_Condition
(Condition
(Alt
));
10689 -- Accept with body
10691 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10694 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10697 (Defining_Unit_Name
(Specification
(Proc
)),
10700 -- Accept with no body (followed by trailing statements)
10703 Alt_Stats
:= Empty_List
;
10706 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10708 -- After the call, if any, branch to trailing statements, if any.
10709 -- We create a label for each, as well as the corresponding label
10712 if not Is_Empty_List
(Statements
(Alt
)) then
10713 Lab
:= Make_And_Declare_Label
(Index
);
10714 Append
(Lab
, Trailing_List
);
10715 Append_List
(Statements
(Alt
), Trailing_List
);
10716 Append_To
(Trailing_List
,
10717 Make_Goto_Statement
(Loc
,
10718 Name
=> New_Copy
(Identifier
(End_Lab
))));
10724 Append_To
(Alt_Stats
,
10725 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10727 Append_To
(Alt_List
,
10728 Make_Case_Statement_Alternative
(Loc
,
10729 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10730 Statements
=> Alt_Stats
));
10731 end Process_Accept_Alternative
;
10733 -------------------------------
10734 -- Process_Delay_Alternative --
10735 -------------------------------
10737 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10738 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10740 Delay_Alt
: List_Id
;
10743 -- Deal with C/Fortran boolean as delay condition
10745 Adjust_Condition
(Condition
(Alt
));
10747 -- Determine the smallest specified delay
10749 -- for each delay alternative generate:
10751 -- if guard-expression then
10752 -- Delay_Val := delay-expression;
10753 -- Guard_Open := True;
10754 -- if Delay_Val < Delay_Min then
10755 -- Delay_Min := Delay_Val;
10756 -- Delay_Index := Index;
10760 -- The enclosing if-statement is omitted if there is no guard
10762 if Delay_Count
= 1 or else First_Delay
then
10763 First_Delay
:= False;
10765 Delay_Alt
:= New_List
(
10766 Make_Assignment_Statement
(Loc
,
10767 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10768 Expression
=> Expression
(Delay_Statement
(Alt
))));
10770 if Delay_Count
> 1 then
10771 Append_To
(Delay_Alt
,
10772 Make_Assignment_Statement
(Loc
,
10773 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10774 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10778 Delay_Alt
:= New_List
(
10779 Make_Assignment_Statement
(Loc
,
10780 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10781 Expression
=> Expression
(Delay_Statement
(Alt
))));
10783 if Time_Type
= Standard_Duration
then
10786 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10787 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10790 -- The scope of the time type must define a comparison
10791 -- operator. The scope itself may not be visible, so we
10792 -- construct a node with entity information to insure that
10793 -- semantic analysis can find the proper operator.
10796 Make_Function_Call
(Loc
,
10797 Name
=> Make_Selected_Component
(Loc
,
10799 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10801 Make_Operator_Symbol
(Loc
,
10802 Chars
=> Name_Op_Lt
,
10803 Strval
=> No_String
)),
10804 Parameter_Associations
=>
10806 New_Occurrence_Of
(Delay_Val
, Loc
),
10807 New_Occurrence_Of
(Delay_Min
, Loc
)));
10809 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10812 Append_To
(Delay_Alt
,
10813 Make_Implicit_If_Statement
(N
,
10815 Then_Statements
=> New_List
(
10816 Make_Assignment_Statement
(Loc
,
10817 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10818 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10820 Make_Assignment_Statement
(Loc
,
10821 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10822 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10825 if Check_Guard
then
10826 Append_To
(Delay_Alt
,
10827 Make_Assignment_Statement
(Loc
,
10828 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10829 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10832 if Present
(Condition
(Alt
)) then
10833 Delay_Alt
:= New_List
(
10834 Make_Implicit_If_Statement
(N
,
10835 Condition
=> Condition
(Alt
),
10836 Then_Statements
=> Delay_Alt
));
10839 Append_List
(Delay_Alt
, Delay_List
);
10841 Ensure_Statement_Present
(Dloc
, Alt
);
10843 -- If the delay alternative has a statement part, add choice to the
10844 -- case statements for delays.
10846 if not Is_Empty_List
(Statements
(Alt
)) then
10848 if Delay_Count
= 1 then
10849 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10852 Append_To
(Delay_Alt_List
,
10853 Make_Case_Statement_Alternative
(Loc
,
10854 Discrete_Choices
=> New_List
(
10855 Make_Integer_Literal
(Loc
, Index
)),
10856 Statements
=> Statements
(Alt
)));
10859 elsif Delay_Count
= 1 then
10861 -- If the single delay has no trailing statements, add a branch
10862 -- to the exit label to the selective wait.
10864 Delay_Alt_List
:= New_List
(
10865 Make_Goto_Statement
(Loc
,
10866 Name
=> New_Copy
(Identifier
(End_Lab
))));
10869 end Process_Delay_Alternative
;
10871 -- Start of processing for Expand_N_Selective_Accept
10874 Process_Statements_For_Controlled_Objects
(N
);
10876 -- First insert some declarations before the select. The first is:
10880 -- This variable holds the parameters passed to the accept body. This
10881 -- declaration has already been inserted by the time we get here by
10882 -- a call to Expand_Accept_Declarations made from the semantics when
10883 -- processing the first accept statement contained in the select. We
10884 -- can find this entity as Accept_Address (E), where E is any of the
10885 -- entries references by contained accept statements.
10887 -- The first step is to scan the list of Selective_Accept_Statements
10888 -- to find this entity, and also count the number of accepts, and
10889 -- determine if terminated, delay or else is present:
10893 Alt
:= First
(Alts
);
10894 while Present
(Alt
) loop
10895 Process_Statements_For_Controlled_Objects
(Alt
);
10897 if Nkind
(Alt
) = N_Accept_Alternative
then
10900 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10901 Delay_Count
:= Delay_Count
+ 1;
10903 -- If the delays are relative delays, the delay expressions have
10904 -- type Standard_Duration. Otherwise they must have some time type
10905 -- recognized by GNAT.
10907 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10908 Time_Type
:= Standard_Duration
;
10910 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10912 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10913 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10918 "& is not a time type (RM 9.6(6))",
10919 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10920 Time_Type
:= Standard_Duration
;
10921 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10925 if No
(Condition
(Alt
)) then
10927 -- This guard will always be open
10929 Check_Guard
:= False;
10932 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10933 Adjust_Condition
(Condition
(Alt
));
10934 Terminate_Alt
:= Alt
;
10937 Num_Alts
:= Num_Alts
+ 1;
10941 Else_Present
:= Present
(Else_Statements
(N
));
10943 -- At the same time (see procedure Add_Accept) we build the accept list:
10945 -- Qnn : Accept_List (1 .. num-select) := (
10946 -- (null-body, entry-index),
10947 -- (null-body, entry-index),
10949 -- (null_body, entry-index));
10951 -- In the above declaration, null-body is True if the corresponding
10952 -- accept has no body, and false otherwise. The entry is either the
10953 -- entry index expression if there is no guard, or if a guard is
10954 -- present, then an if expression of the form:
10956 -- (if guard then entry-index else Null_Task_Entry)
10958 -- If a guard is statically known to be false, the entry can simply
10959 -- be omitted from the accept list.
10962 Make_Object_Declaration
(Loc
,
10963 Defining_Identifier
=> Qnam
,
10964 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10965 Aliased_Present
=> True,
10967 Make_Qualified_Expression
(Loc
,
10969 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10971 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10973 -- Then we declare the variable that holds the index for the accept
10974 -- that will be selected for service:
10976 -- Xnn : Select_Index;
10979 Make_Object_Declaration
(Loc
,
10980 Defining_Identifier
=> Xnam
,
10981 Object_Definition
=>
10982 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10984 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10986 -- After this follow procedure declarations for each accept body
10988 -- procedure Pnn is
10993 -- where the ... are statements from the corresponding procedure body.
10994 -- No parameters are involved, since the parameters are passed via Ann
10995 -- and the parameter references have already been expanded to be direct
10996 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10997 -- any embedded tasking statements (which would normally be illegal in
10998 -- procedures), have been converted to calls to the tasking runtime so
10999 -- there is no problem in putting them into procedures.
11001 -- The original accept statement has been expanded into a block in
11002 -- the same fashion as for simple accepts (see Build_Accept_Body).
11004 -- Note: we don't really need to build these procedures for the case
11005 -- where no delay statement is present, but it is just as easy to
11006 -- build them unconditionally, and not significantly inefficient,
11007 -- since if they are short they will be inlined anyway.
11009 -- The procedure declarations have been assembled in Body_List
11011 -- If delays are present, we must compute the required delay.
11012 -- We first generate the declarations:
11014 -- Delay_Index : Boolean := 0;
11015 -- Delay_Min : Some_Time_Type.Time;
11016 -- Delay_Val : Some_Time_Type.Time;
11018 -- Delay_Index will be set to the index of the minimum delay, i.e. the
11019 -- active delay that is actually chosen as the basis for the possible
11020 -- delay if an immediate rendez-vous is not possible.
11022 -- In the most common case there is a single delay statement, and this
11023 -- is handled specially.
11025 if Delay_Count
> 0 then
11027 -- Generate the required declarations
11030 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
11032 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
11034 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
11037 Make_Object_Declaration
(Loc
,
11038 Defining_Identifier
=> Delay_Val
,
11039 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
11042 Make_Object_Declaration
(Loc
,
11043 Defining_Identifier
=> Delay_Index
,
11044 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11045 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11048 Make_Object_Declaration
(Loc
,
11049 Defining_Identifier
=> Delay_Min
,
11050 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11052 Unchecked_Convert_To
(Time_Type
,
11053 Make_Attribute_Reference
(Loc
,
11055 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11056 Attribute_Name
=> Name_Last
))));
11058 -- Create Duration and Delay_Mode objects used for passing a delay
11061 D
:= Make_Temporary
(Loc
, 'D');
11062 M
:= Make_Temporary
(Loc
, 'M');
11068 -- Note that these values are defined in s-osprim.ads and must
11069 -- be kept in sync:
11071 -- Relative : constant := 0;
11072 -- Absolute_Calendar : constant := 1;
11073 -- Absolute_RT : constant := 2;
11075 if Time_Type
= Standard_Duration
then
11076 Discr
:= Make_Integer_Literal
(Loc
, 0);
11078 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11079 Discr
:= Make_Integer_Literal
(Loc
, 1);
11083 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11084 Discr
:= Make_Integer_Literal
(Loc
, 2);
11088 Make_Object_Declaration
(Loc
,
11089 Defining_Identifier
=> D
,
11090 Object_Definition
=>
11091 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11094 Make_Object_Declaration
(Loc
,
11095 Defining_Identifier
=> M
,
11096 Object_Definition
=>
11097 New_Occurrence_Of
(Standard_Integer
, Loc
),
11098 Expression
=> Discr
));
11101 if Check_Guard
then
11103 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11106 Make_Object_Declaration
(Loc
,
11107 Defining_Identifier
=> Guard_Open
,
11108 Object_Definition
=>
11109 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11111 New_Occurrence_Of
(Standard_False
, Loc
)));
11114 -- Delay_Count is zero, don't need M and D set (suppress warning)
11121 if Present
(Terminate_Alt
) then
11123 -- If the terminate alternative guard is False, use
11124 -- Simple_Mode; otherwise use Terminate_Mode.
11126 if Present
(Condition
(Terminate_Alt
)) then
11127 Select_Mode
:= Make_If_Expression
(Loc
,
11128 New_List
(Condition
(Terminate_Alt
),
11129 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11130 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11132 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11135 elsif Else_Present
or Delay_Count
> 0 then
11136 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11139 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11142 Select_Call
:= Make_Select_Call
(Select_Mode
);
11143 Append
(Select_Call
, Stats
);
11145 -- Now generate code to act on the result. There is an entry
11146 -- in this case for each accept statement with a non-null body,
11147 -- followed by a branch to the statements that follow the Accept.
11148 -- In the absence of delay alternatives, we generate:
11151 -- when No_Rendezvous => -- omitted if simple mode
11166 -- Lab0: Else_Statements;
11169 -- Lab1: Trailing_Statements1;
11172 -- Lab2: Trailing_Statements2;
11177 -- Generate label for common exit
11179 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11181 -- First entry is the default case, when no rendezvous is possible
11183 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11185 if Else_Present
then
11187 -- If no rendezvous is possible, the else part is executed
11189 Lab
:= Make_And_Declare_Label
(0);
11190 Alt_Stats
:= New_List
(
11191 Make_Goto_Statement
(Loc
,
11192 Name
=> New_Copy
(Identifier
(Lab
))));
11194 Append
(Lab
, Trailing_List
);
11195 Append_List
(Else_Statements
(N
), Trailing_List
);
11196 Append_To
(Trailing_List
,
11197 Make_Goto_Statement
(Loc
,
11198 Name
=> New_Copy
(Identifier
(End_Lab
))));
11200 Alt_Stats
:= New_List
(
11201 Make_Goto_Statement
(Loc
,
11202 Name
=> New_Copy
(Identifier
(End_Lab
))));
11205 Append_To
(Alt_List
,
11206 Make_Case_Statement_Alternative
(Loc
,
11207 Discrete_Choices
=> Choices
,
11208 Statements
=> Alt_Stats
));
11210 -- We make use of the fact that Accept_Index is an integer type, and
11211 -- generate successive literals for entries for each accept. Only those
11212 -- for which there is a body or trailing statements get a case entry.
11214 Alt
:= First
(Select_Alternatives
(N
));
11215 Proc
:= First
(Body_List
);
11216 while Present
(Alt
) loop
11218 if Nkind
(Alt
) = N_Accept_Alternative
then
11219 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11220 Index
:= Index
+ 1;
11223 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11228 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11229 Process_Delay_Alternative
(Alt
, Delay_Num
);
11230 Delay_Num
:= Delay_Num
+ 1;
11236 -- An others choice is always added to the main case, as well
11237 -- as the delay case (to satisfy the compiler).
11239 Append_To
(Alt_List
,
11240 Make_Case_Statement_Alternative
(Loc
,
11241 Discrete_Choices
=>
11242 New_List
(Make_Others_Choice
(Loc
)),
11244 New_List
(Make_Goto_Statement
(Loc
,
11245 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11247 Accept_Case
:= New_List
(
11248 Make_Case_Statement
(Loc
,
11249 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11250 Alternatives
=> Alt_List
));
11252 Append_List
(Trailing_List
, Accept_Case
);
11253 Append_List
(Body_List
, Decls
);
11255 -- Construct case statement for trailing statements of delay
11256 -- alternatives, if there are several of them.
11258 if Delay_Count
> 1 then
11259 Append_To
(Delay_Alt_List
,
11260 Make_Case_Statement_Alternative
(Loc
,
11261 Discrete_Choices
=>
11262 New_List
(Make_Others_Choice
(Loc
)),
11264 New_List
(Make_Null_Statement
(Loc
))));
11266 Delay_Case
:= New_List
(
11267 Make_Case_Statement
(Loc
,
11268 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11269 Alternatives
=> Delay_Alt_List
));
11271 Delay_Case
:= Delay_Alt_List
;
11274 -- If there are no delay alternatives, we append the case statement
11275 -- to the statement list.
11277 if Delay_Count
= 0 then
11278 Append_List
(Accept_Case
, Stats
);
11280 -- Delay alternatives present
11283 -- If delay alternatives are present we generate:
11285 -- find minimum delay.
11286 -- DX := minimum delay;
11287 -- M := <delay mode>;
11288 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11291 -- if X = No_Rendezvous then
11292 -- case statement for delay statements.
11294 -- case statement for accept alternatives.
11305 -- The type of the delay expression is known to be legal
11307 if Time_Type
= Standard_Duration
then
11308 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11310 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11311 Conv
:= Make_Function_Call
(Loc
,
11312 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11313 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11317 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11319 Conv
:= Make_Function_Call
(Loc
,
11320 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11321 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11324 Stmt
:= Make_Assignment_Statement
(Loc
,
11325 Name
=> New_Occurrence_Of
(D
, Loc
),
11326 Expression
=> Conv
);
11328 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11330 Parms
:= Parameter_Associations
(Select_Call
);
11332 Parm
:= First
(Parms
);
11333 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11337 pragma Assert
(Present
(Parm
));
11338 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11341 -- Prepare two new parameters of Duration and Delay_Mode type
11342 -- which represent the value and the mode of the minimum delay.
11345 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11346 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11348 -- Create a call to RTS
11350 Rewrite
(Select_Call
,
11351 Make_Procedure_Call_Statement
(Loc
,
11352 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11353 Parameter_Associations
=> Parms
));
11355 -- This new call should follow the calculation of the minimum
11358 Insert_List_Before
(Select_Call
, Delay_List
);
11360 if Check_Guard
then
11362 Make_Implicit_If_Statement
(N
,
11363 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11364 Then_Statements
=> New_List
(
11365 New_Copy_Tree
(Stmt
),
11366 New_Copy_Tree
(Select_Call
)),
11367 Else_Statements
=> Accept_Or_Raise
);
11368 Rewrite
(Select_Call
, Stmt
);
11370 Insert_Before
(Select_Call
, Stmt
);
11374 Make_Implicit_If_Statement
(N
,
11375 Condition
=> Make_Op_Eq
(Loc
,
11376 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11378 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11380 Then_Statements
=> Delay_Case
,
11381 Else_Statements
=> Accept_Case
);
11383 Append
(Cases
, Stats
);
11387 Append
(End_Lab
, Stats
);
11389 -- Replace accept statement with appropriate block
11392 Make_Block_Statement
(Loc
,
11393 Declarations
=> Decls
,
11394 Handled_Statement_Sequence
=>
11395 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11398 -- Note: have to worry more about abort deferral in above code ???
11400 -- Final step is to unstack the Accept_Address entries for all accept
11401 -- statements appearing in accept alternatives in the select statement
11403 Alt
:= First
(Alts
);
11404 while Present
(Alt
) loop
11405 if Nkind
(Alt
) = N_Accept_Alternative
then
11406 Remove_Last_Elmt
(Accept_Address
11407 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11412 end Expand_N_Selective_Accept
;
11414 -------------------------------------------
11415 -- Expand_N_Single_Protected_Declaration --
11416 -------------------------------------------
11418 -- A single protected declaration should never be present after semantic
11419 -- analysis because it is transformed into a protected type declaration
11420 -- and an accompanying anonymous object. This routine ensures that the
11421 -- transformation takes place.
11423 procedure Expand_N_Single_Protected_Declaration
(N
: Node_Id
) is
11425 raise Program_Error
;
11426 end Expand_N_Single_Protected_Declaration
;
11428 --------------------------------------
11429 -- Expand_N_Single_Task_Declaration --
11430 --------------------------------------
11432 -- A single task declaration should never be present after semantic
11433 -- analysis because it is transformed into a task type declaration and
11434 -- an accompanying anonymous object. This routine ensures that the
11435 -- transformation takes place.
11437 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11439 raise Program_Error
;
11440 end Expand_N_Single_Task_Declaration
;
11442 ------------------------
11443 -- Expand_N_Task_Body --
11444 ------------------------
11446 -- Given a task body
11448 -- task body tname is
11454 -- This expansion routine converts it into a procedure and sets the
11455 -- elaboration flag for the procedure to true, to represent the fact
11456 -- that the task body is now elaborated:
11458 -- procedure tnameB (_Task : access tnameV) is
11459 -- discriminal : dtype renames _Task.discriminant;
11461 -- procedure _clean is
11463 -- Abort_Defer.all;
11465 -- Abort_Undefer.all;
11470 -- Abort_Undefer.all;
11472 -- System.Task_Stages.Complete_Activation;
11480 -- In addition, if the task body is an activator, then a call to activate
11481 -- tasks is added at the start of the statements, before the call to
11482 -- Complete_Activation, and if in addition the task is a master then it
11483 -- must be established as a master. These calls are inserted and analyzed
11484 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11487 -- There is one discriminal declaration line generated for each
11488 -- discriminant that is present to provide an easy reference point for
11489 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11491 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11492 -- task body procedures have a profile (Arg : System.Address). That is
11493 -- needed because GNARLI has to use the same access-to-subprogram type
11494 -- for all task types. We depend here on knowing that in GNAT, passing
11495 -- an address argument by value is identical to passing a record value
11496 -- by access (in either case a single pointer is passed), so even though
11497 -- this procedure has the wrong profile. In fact it's all OK, since the
11498 -- callings sequence is identical.
11500 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11501 Loc
: constant Source_Ptr
:= Sloc
(N
);
11502 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11506 Insert_Nod
: Node_Id
;
11507 -- Used to determine the proper location of wrapper body insertions
11510 -- if no task body procedure, means we had an error in configurable
11511 -- run-time mode, and there is no point in proceeding further.
11513 if No
(Task_Body_Procedure
(Ttyp
)) then
11517 -- Add renaming declarations for discriminals and a declaration for the
11518 -- entry family index (if applicable).
11520 Install_Private_Data_Declarations
11521 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11523 -- Add a call to Abort_Undefer at the very beginning of the task
11524 -- body since this body is called with abort still deferred.
11526 if Abort_Allowed
then
11527 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11529 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11533 -- The statement part has already been protected with an at_end and
11534 -- cleanup actions. The call to Complete_Activation must be placed
11535 -- at the head of the sequence of statements of that block. The
11536 -- declarations have been merged in this sequence of statements but
11537 -- the first real statement is accessible from the First_Real_Statement
11538 -- field (which was set for exactly this purpose).
11540 if Restricted_Profile
then
11541 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11543 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11547 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11551 Make_Subprogram_Body
(Loc
,
11552 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11553 Declarations
=> Declarations
(N
),
11554 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11555 Set_Is_Task_Body_Procedure
(New_N
);
11557 -- If the task contains generic instantiations, cleanup actions are
11558 -- delayed until after instantiation. Transfer the activation chain to
11559 -- the subprogram, to insure that the activation call is properly
11560 -- generated. It the task body contains inner tasks, indicate that the
11561 -- subprogram is a task master.
11563 if Delay_Cleanups
(Ttyp
) then
11564 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11565 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11568 Rewrite
(N
, New_N
);
11571 -- Set elaboration flag immediately after task body. If the body is a
11572 -- subunit, the flag is set in the declarative part containing the stub.
11574 if Nkind
(Parent
(N
)) /= N_Subunit
then
11576 Make_Assignment_Statement
(Loc
,
11578 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11579 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11582 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11583 -- the task body. At this point all wrapper specs have been created,
11584 -- frozen and included in the dispatch table for the task type.
11586 if Ada_Version
>= Ada_2005
then
11587 if Nkind
(Parent
(N
)) = N_Subunit
then
11588 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11593 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11595 end Expand_N_Task_Body
;
11597 ------------------------------------
11598 -- Expand_N_Task_Type_Declaration --
11599 ------------------------------------
11601 -- We have several things to do. First we must create a Boolean flag used
11602 -- to mark if the body is elaborated yet. This variable gets set to True
11603 -- when the body of the task is elaborated (we can't rely on the normal
11604 -- ABE mechanism for the task body, since we need to pass an access to
11605 -- this elaboration boolean to the runtime routines).
11607 -- taskE : aliased Boolean := False;
11609 -- Next a variable is declared to hold the task stack size (either the
11610 -- default : Unspecified_Size, or a value that is set by a pragma
11611 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11612 -- the variable is initialized with this value:
11614 -- taskZ : Size_Type := Unspecified_Size;
11616 -- taskZ : Size_Type := Size_Type (size_expression);
11618 -- Note: No variable is needed to hold the task relative deadline since
11619 -- its value would never be static because the parameter is of a private
11620 -- type (Ada.Real_Time.Time_Span).
11622 -- Next we create a corresponding record type declaration used to represent
11623 -- values of this task. The general form of this type declaration is
11625 -- type taskV (discriminants) is record
11626 -- _Task_Id : Task_Id;
11627 -- entry_family : array (bounds) of Void;
11628 -- _Priority : Integer := priority_expression;
11629 -- _Size : Size_Type := size_expression;
11630 -- _Secondary_Stack_Size : Size_Type := size_expression;
11631 -- _Task_Info : Task_Info_Type := task_info_expression;
11632 -- _CPU : Integer := cpu_range_expression;
11633 -- _Relative_Deadline : Time_Span := time_span_expression;
11634 -- _Domain : Dispatching_Domain := dd_expression;
11637 -- The discriminants are present only if the corresponding task type has
11638 -- discriminants, and they exactly mirror the task type discriminants.
11640 -- The Id field is always present. It contains the Task_Id value, as set by
11641 -- the call to Create_Task. Note that although the task is limited, the
11642 -- task value record type is not limited, so there is no problem in passing
11643 -- this field as an out parameter to Create_Task.
11645 -- One entry_family component is present for each entry family in the task
11646 -- definition. The bounds correspond to the bounds of the entry family
11647 -- (which may depend on discriminants). The element type is void, since we
11648 -- only need the bounds information for determining the entry index. Note
11649 -- that the use of an anonymous array would normally be illegal in this
11650 -- context, but this is a parser check, and the semantics is quite prepared
11651 -- to handle such a case.
11653 -- The _Size field is present only if a Storage_Size pragma appears in the
11654 -- task definition. The expression captures the argument that was present
11655 -- in the pragma, and is used to override the task stack size otherwise
11656 -- associated with the task type.
11658 -- The _Secondary_Stack_Size field is present only the task entity has a
11659 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11660 -- when the record init proc is built, to capture the expression of the
11661 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11662 -- be filled here since aspect evaluations are delayed till the freeze
11665 -- The _Priority field is present only if the task entity has a Priority or
11666 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11667 -- definition clause). It will be filled at the freeze point, when the
11668 -- record init proc is built, to capture the expression of the rep item
11669 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11670 -- here since aspect evaluations are delayed till the freeze point.
11672 -- The _Task_Info field is present only if a Task_Info pragma appears in
11673 -- the task definition. The expression captures the argument that was
11674 -- present in the pragma, and is used to provide the Task_Image parameter
11675 -- to the call to Create_Task.
11677 -- The _CPU field is present only if the task entity has a CPU rep item
11678 -- (pragma, aspect specification or attribute definition clause). It will
11679 -- be filled at the freeze point, when the record init proc is built, to
11680 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11681 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11682 -- are delayed till the freeze point.
11684 -- The _Relative_Deadline field is present only if a Relative_Deadline
11685 -- pragma appears in the task definition. The expression captures the
11686 -- argument that was present in the pragma, and is used to provide the
11687 -- Relative_Deadline parameter to the call to Create_Task.
11689 -- The _Domain field is present only if the task entity has a
11690 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11691 -- definition clause). It will be filled at the freeze point, when the
11692 -- record init proc is built, to capture the expression of the rep item
11693 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11694 -- here since aspect evaluations are delayed till the freeze point.
11696 -- When a task is declared, an instance of the task value record is
11697 -- created. The elaboration of this declaration creates the correct bounds
11698 -- for the entry families, and also evaluates the size, priority, and
11699 -- task_Info expressions if needed. The initialization routine for the task
11700 -- type itself then calls Create_Task with appropriate parameters to
11701 -- initialize the value of the Task_Id field.
11703 -- Note: the address of this record is passed as the "Discriminants"
11704 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11705 -- body procedure, it does not matter that it does not quite match the
11706 -- GNARLI model of what is being passed (the record contains more than just
11707 -- the discriminants, but the discriminants can be found from the record
11710 -- The Entity_Id for this created record type is placed in the
11711 -- Corresponding_Record_Type field of the associated task type entity.
11713 -- Next we create a procedure specification for the task body procedure:
11715 -- procedure taskB (_Task : access taskV);
11717 -- Note that this must come after the record type declaration, since
11718 -- the spec refers to this type. It turns out that the initialization
11719 -- procedure for the value type references the task body spec, but that's
11720 -- fine, since it won't be generated till the freeze point for the type,
11721 -- which is certainly after the task body spec declaration.
11723 -- Finally, we set the task index value field of the entry attribute in
11724 -- the case of a simple entry.
11726 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11727 Loc
: constant Source_Ptr
:= Sloc
(N
);
11728 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11729 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11730 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11731 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11733 Body_Decl
: Node_Id
;
11735 Decl_Stack
: Node_Id
;
11737 Elab_Decl
: Node_Id
;
11738 Ent_Stack
: Entity_Id
;
11739 Proc_Spec
: Node_Id
;
11740 Rec_Decl
: Node_Id
;
11741 Rec_Ent
: Entity_Id
;
11742 Size_Decl
: Entity_Id
;
11743 Task_Size
: Node_Id
;
11745 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11746 -- Searches the task definition T for the first occurrence of the pragma
11747 -- Relative Deadline. The caller has ensured that the pragma is present
11748 -- in the task definition. Note that this routine cannot be implemented
11749 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11750 -- not chained because their expansion into a procedure call statement
11751 -- would cause a break in the chain.
11753 ----------------------------------
11754 -- Get_Relative_Deadline_Pragma --
11755 ----------------------------------
11757 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11761 N
:= First
(Visible_Declarations
(T
));
11762 while Present
(N
) loop
11763 if Nkind
(N
) = N_Pragma
11764 and then Pragma_Name
(N
) = Name_Relative_Deadline
11772 N
:= First
(Private_Declarations
(T
));
11773 while Present
(N
) loop
11774 if Nkind
(N
) = N_Pragma
11775 and then Pragma_Name
(N
) = Name_Relative_Deadline
11783 raise Program_Error
;
11784 end Get_Relative_Deadline_Pragma
;
11786 -- Start of processing for Expand_N_Task_Type_Declaration
11789 -- If already expanded, nothing to do
11791 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11795 -- Here we will do the expansion
11797 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11799 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11800 Cdecls
:= Component_Items
(Component_List
11801 (Type_Definition
(Rec_Decl
)));
11803 Qualify_Entity_Names
(N
);
11805 -- First create the elaboration variable
11808 Make_Object_Declaration
(Loc
,
11809 Defining_Identifier
=>
11810 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11811 Chars
=> New_External_Name
(Tasknm
, 'E')),
11812 Aliased_Present
=> True,
11813 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11814 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11816 Insert_After
(N
, Elab_Decl
);
11818 -- Next create the declaration of the size variable (tasknmZ)
11820 Set_Storage_Size_Variable
(Tasktyp
,
11821 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11822 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11824 if Present
(Taskdef
)
11825 and then Has_Storage_Size_Pragma
(Taskdef
)
11827 Is_OK_Static_Expression
11829 (First
(Pragma_Argument_Associations
11830 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11833 Make_Object_Declaration
(Loc
,
11834 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11835 Object_Definition
=>
11836 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11838 Convert_To
(RTE
(RE_Size_Type
),
11840 (Expression
(First
(Pragma_Argument_Associations
11842 (TaskId
, Name_Storage_Size
)))))));
11846 Make_Object_Declaration
(Loc
,
11847 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11848 Object_Definition
=>
11849 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11851 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11854 Insert_After
(Elab_Decl
, Size_Decl
);
11856 -- Next build the rest of the corresponding record declaration. This is
11857 -- done last, since the corresponding record initialization procedure
11858 -- will reference the previously created entities.
11860 -- Fill in the component declarations -- first the _Task_Id field
11863 Make_Component_Declaration
(Loc
,
11864 Defining_Identifier
=>
11865 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11866 Component_Definition
=>
11867 Make_Component_Definition
(Loc
,
11868 Aliased_Present
=> False,
11869 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11872 -- Declare static ATCB (that is, created by the expander) if we are
11873 -- using the Restricted run time.
11875 if Restricted_Profile
then
11877 Make_Component_Declaration
(Loc
,
11878 Defining_Identifier
=>
11879 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11881 Component_Definition
=>
11882 Make_Component_Definition
(Loc
,
11883 Aliased_Present
=> True,
11884 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11886 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11889 Make_Index_Or_Discriminant_Constraint
(Loc
,
11891 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11895 -- Declare static stack (that is, created by the expander) if we are
11896 -- using the Restricted run time on a bare board configuration.
11898 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11900 -- First we need to extract the appropriate stack size
11902 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11904 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11906 Expr_N
: constant Node_Id
:=
11907 Expression
(First
(
11908 Pragma_Argument_Associations
(
11909 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11910 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11911 P
: constant Node_Id
:= Parent
(Expr_N
);
11914 -- The stack is defined inside the corresponding record.
11915 -- Therefore if the size of the stack is set by means of
11916 -- a discriminant, we must reference the discriminant of the
11917 -- corresponding record type.
11919 if Nkind
(Expr_N
) in N_Has_Entity
11920 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11924 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11926 Set_Parent
(Task_Size
, P
);
11927 Set_Etype
(Task_Size
, Etyp
);
11928 Set_Analyzed
(Task_Size
);
11931 Task_Size
:= Relocate_Node
(Expr_N
);
11937 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11940 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11941 Defining_Identifier
=> Ent_Stack
,
11943 Component_Definition
=>
11944 Make_Component_Definition
(Loc
,
11945 Aliased_Present
=> True,
11946 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11948 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11951 Make_Index_Or_Discriminant_Constraint
(Loc
,
11952 Constraints
=> New_List
(Make_Range
(Loc
,
11953 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11954 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11957 Append_To
(Cdecls
, Decl_Stack
);
11959 -- The appropriate alignment for the stack is ensured by the run-time
11960 -- code in charge of task creation.
11964 -- Declare a static secondary stack if the conditions for a statically
11965 -- generated stack are met.
11967 if Create_Secondary_Stack_For_Task
(TaskId
) then
11970 Size_Expr
: Node_Id
;
11973 -- First extract the secondary stack size from the task type's
11974 -- representation aspect.
11978 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False);
11980 -- Get Secondary_Stack_Size expression. Can be a pragma or aspect.
11982 if Nkind
(Ritem
) = N_Pragma
then
11985 (First
(Pragma_Argument_Associations
(Ritem
)));
11987 Size_Expr
:= Expression
(Ritem
);
11990 pragma Assert
(Compile_Time_Known_Value
(Size_Expr
));
11992 -- Create the secondary stack for the task
11995 Make_Component_Declaration
(Loc
,
11996 Defining_Identifier
=>
11997 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack
),
11998 Component_Definition
=>
11999 Make_Component_Definition
(Loc
,
12000 Aliased_Present
=> True,
12001 Subtype_Indication
=>
12002 Make_Subtype_Indication
(Loc
,
12004 New_Occurrence_Of
(RTE
(RE_SS_Stack
), Loc
),
12006 Make_Index_Or_Discriminant_Constraint
(Loc
,
12007 Constraints
=> New_List
(
12008 Make_Integer_Literal
(Loc
,
12009 Expr_Value
(Size_Expr
)))))));
12011 Append_To
(Cdecls
, Decl_SS
);
12015 -- Add components for entry families
12017 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
12019 -- Add the _Priority component if a Interrupt_Priority or Priority rep
12020 -- item is present.
12022 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
12024 Make_Component_Declaration
(Loc
,
12025 Defining_Identifier
=>
12026 Make_Defining_Identifier
(Loc
, Name_uPriority
),
12027 Component_Definition
=>
12028 Make_Component_Definition
(Loc
,
12029 Aliased_Present
=> False,
12030 Subtype_Indication
=>
12031 New_Occurrence_Of
(Standard_Integer
, Loc
))));
12034 -- Add the _Size component if a Storage_Size pragma is present
12036 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
12038 Make_Component_Declaration
(Loc
,
12039 Defining_Identifier
=>
12040 Make_Defining_Identifier
(Loc
, Name_uSize
),
12042 Component_Definition
=>
12043 Make_Component_Definition
(Loc
,
12044 Aliased_Present
=> False,
12045 Subtype_Indication
=>
12046 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
12049 Convert_To
(RTE
(RE_Size_Type
),
12051 Expression
(First
(
12052 Pragma_Argument_Associations
(
12053 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
12056 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
12057 -- rep item is present.
12060 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
12063 Make_Component_Declaration
(Loc
,
12064 Defining_Identifier
=>
12065 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack_Size
),
12067 Component_Definition
=>
12068 Make_Component_Definition
(Loc
,
12069 Aliased_Present
=> False,
12070 Subtype_Indication
=>
12071 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
))));
12074 -- Add the _Task_Info component if a Task_Info pragma is present
12076 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
12078 Make_Component_Declaration
(Loc
,
12079 Defining_Identifier
=>
12080 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
12082 Component_Definition
=>
12083 Make_Component_Definition
(Loc
,
12084 Aliased_Present
=> False,
12085 Subtype_Indication
=>
12086 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
12088 Expression
=> New_Copy
(
12089 Expression
(First
(
12090 Pragma_Argument_Associations
(
12092 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
12095 -- Add the _CPU component if a CPU rep item is present
12097 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
12099 Make_Component_Declaration
(Loc
,
12100 Defining_Identifier
=>
12101 Make_Defining_Identifier
(Loc
, Name_uCPU
),
12103 Component_Definition
=>
12104 Make_Component_Definition
(Loc
,
12105 Aliased_Present
=> False,
12106 Subtype_Indication
=>
12107 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
12110 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
12111 -- present. If we are using a restricted run time this component will
12112 -- not be added (deadlines are not allowed by the Ravenscar profile),
12113 -- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
12116 if (not Restricted_Profile
or else Task_Dispatching_Policy
= 'E')
12117 and then Present
(Taskdef
)
12118 and then Has_Relative_Deadline_Pragma
(Taskdef
)
12121 Make_Component_Declaration
(Loc
,
12122 Defining_Identifier
=>
12123 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
12125 Component_Definition
=>
12126 Make_Component_Definition
(Loc
,
12127 Aliased_Present
=> False,
12128 Subtype_Indication
=>
12129 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
12132 Convert_To
(RTE
(RE_Time_Span
),
12134 Expression
(First
(
12135 Pragma_Argument_Associations
(
12136 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12139 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12140 -- item is present. If we are using a restricted run time this component
12141 -- will not be added (dispatching domains are not allowed by the
12142 -- Ravenscar profile).
12144 if not Restricted_Profile
12147 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12150 Make_Component_Declaration
(Loc
,
12151 Defining_Identifier
=>
12152 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12154 Component_Definition
=>
12155 Make_Component_Definition
(Loc
,
12156 Aliased_Present
=> False,
12157 Subtype_Indication
=>
12159 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12162 Insert_After
(Size_Decl
, Rec_Decl
);
12164 -- Analyze the record declaration immediately after construction,
12165 -- because the initialization procedure is needed for single task
12166 -- declarations before the next entity is analyzed.
12168 Analyze
(Rec_Decl
);
12170 -- Create the declaration of the task body procedure
12172 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12174 Make_Subprogram_Declaration
(Loc
,
12175 Specification
=> Proc_Spec
);
12176 Set_Is_Task_Body_Procedure
(Body_Decl
);
12178 Insert_After
(Rec_Decl
, Body_Decl
);
12180 -- The subprogram does not comes from source, so we have to indicate the
12181 -- need for debugging information explicitly.
12183 if Comes_From_Source
(Original_Node
(N
)) then
12184 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12187 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12188 -- the corresponding record has been frozen.
12190 if Ada_Version
>= Ada_2005
then
12191 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12194 -- Ada 2005 (AI-345): We must defer freezing to allow further
12195 -- declaration of primitive subprograms covering task interfaces
12197 if Ada_Version
<= Ada_95
then
12199 -- Now we can freeze the corresponding record. This needs manually
12200 -- freezing, since it is really part of the task type, and the task
12201 -- type is frozen at this stage. We of course need the initialization
12202 -- procedure for this corresponding record type and we won't get it
12203 -- in time if we don't freeze now.
12206 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
12208 if Is_Non_Empty_List
(L
) then
12209 Insert_List_After
(Body_Decl
, L
);
12214 -- Complete the expansion of access types to the current task type, if
12215 -- any were declared.
12217 Expand_Previous_Access_Type
(Tasktyp
);
12219 -- Create wrappers for entries that have contract cases, preconditions
12220 -- and postconditions.
12226 Ent
:= First_Entity
(Tasktyp
);
12227 while Present
(Ent
) loop
12228 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
) then
12229 Build_Contract_Wrapper
(Ent
, N
);
12235 end Expand_N_Task_Type_Declaration
;
12237 -------------------------------
12238 -- Expand_N_Timed_Entry_Call --
12239 -------------------------------
12241 -- A timed entry call in normal case is not implemented using ATC mechanism
12242 -- anymore for efficiency reason.
12252 -- is expanded as follows:
12254 -- 1) When T.E is a task entry_call;
12258 -- X : Task_Entry_Index := <entry index>;
12259 -- DX : Duration := To_Duration (D);
12260 -- M : Delay_Mode := <discriminant>;
12261 -- P : parms := (parm, parm, parm);
12264 -- Timed_Protected_Entry_Call
12265 -- (<acceptor-task>, X, P'Address, DX, M, B);
12273 -- 2) When T.E is a protected entry_call;
12277 -- X : Protected_Entry_Index := <entry index>;
12278 -- DX : Duration := To_Duration (D);
12279 -- M : Delay_Mode := <discriminant>;
12280 -- P : parms := (parm, parm, parm);
12283 -- Timed_Protected_Entry_Call
12284 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12292 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12293 -- is no delay and the triggering statements are executed. We first
12294 -- determine the kind of the triggering call and then execute a
12295 -- synchronized operation or a direct call.
12298 -- B : Boolean := False;
12299 -- C : Ada.Tags.Prim_Op_Kind;
12300 -- DX : Duration := To_Duration (D)
12301 -- K : Ada.Tags.Tagged_Kind :=
12302 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12303 -- M : Integer :=...;
12304 -- P : Parameters := (Param1 .. ParamN);
12308 -- if K = Ada.Tags.TK_Limited_Tagged
12309 -- or else K = Ada.Tags.TK_Tagged
12311 -- <dispatching-call>;
12316 -- Ada.Tags.Get_Offset_Index
12317 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12319 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12321 -- if C = POK_Protected_Entry
12322 -- or else C = POK_Task_Entry
12324 -- Param1 := P.Param1;
12326 -- ParamN := P.ParamN;
12330 -- if C = POK_Procedure
12331 -- or else C = POK_Protected_Procedure
12332 -- or else C = POK_Task_Procedure
12334 -- <dispatching-call>;
12340 -- <triggering-statements>
12342 -- <timed-statements>
12346 -- The triggering statement and the sequence of timed statements have not
12347 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12348 -- global references if within an instantiation.
12350 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12351 Loc
: constant Source_Ptr
:= Sloc
(N
);
12354 Blk_Typ
: Entity_Id
;
12356 Call_Ent
: Entity_Id
;
12357 Conc_Typ_Stmts
: List_Id
;
12358 Concval
: Node_Id
:= Empty
; -- init to avoid warning
12359 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12362 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12364 D_Type
: Entity_Id
;
12367 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12368 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12373 Is_Disp_Select
: Boolean;
12374 Lim_Typ_Stmts
: List_Id
;
12383 B
: Entity_Id
; -- Call status flag
12384 C
: Entity_Id
; -- Call kind
12385 D
: Entity_Id
; -- Delay
12386 K
: Entity_Id
; -- Tagged kind
12387 M
: Entity_Id
; -- Delay mode
12388 P
: Entity_Id
; -- Parameter block
12389 S
: Entity_Id
; -- Primitive operation slot
12391 -- Start of processing for Expand_N_Timed_Entry_Call
12394 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12395 -- was already reported on spec, so do not attempt to expand the call.
12397 if Restriction_Active
(No_Select_Statements
) then
12401 Process_Statements_For_Controlled_Objects
(E_Alt
);
12402 Process_Statements_For_Controlled_Objects
(D_Alt
);
12404 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12406 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12407 -- may wrap them in blocks.
12409 E_Stats
:= Statements
(E_Alt
);
12410 D_Stats
:= Statements
(D_Alt
);
12412 -- The arguments in the call may require dynamic allocation, and the
12413 -- call statement may have been transformed into a block. The block
12414 -- may contain additional declarations for internal entities, and the
12415 -- original call is found by sequential search.
12417 if Nkind
(E_Call
) = N_Block_Statement
then
12418 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12419 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12420 N_Entry_Call_Statement
)
12427 Ada_Version
>= Ada_2005
12428 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12430 if Is_Disp_Select
then
12431 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12437 -- B : Boolean := False;
12439 B
:= Build_B
(Loc
, Decls
);
12442 -- C : Ada.Tags.Prim_Op_Kind;
12444 C
:= Build_C
(Loc
, Decls
);
12446 -- Because the analysis of all statements was disabled, manually
12447 -- analyze the delay statement.
12450 D_Stat
:= Original_Node
(D_Stat
);
12453 -- Build an entry call using Simple_Entry_Call
12455 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12456 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12458 Decls
:= Declarations
(E_Call
);
12459 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12468 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12471 Make_Object_Declaration
(Loc
,
12472 Defining_Identifier
=> B
,
12473 Object_Definition
=>
12474 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12477 -- Duration and mode processing
12479 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12481 -- Use the type of the delay expression (Calendar or Real_Time) to
12482 -- generate the appropriate conversion.
12484 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12485 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12486 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12488 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12489 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12491 Make_Function_Call
(Loc
,
12492 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12493 Parameter_Associations
=>
12494 New_List
(New_Copy
(Expression
(D_Stat
))));
12496 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12497 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12499 Make_Function_Call
(Loc
,
12500 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12501 Parameter_Associations
=>
12502 New_List
(New_Copy
(Expression
(D_Stat
))));
12505 D
:= Make_Temporary
(Loc
, 'D');
12511 Make_Object_Declaration
(Loc
,
12512 Defining_Identifier
=> D
,
12513 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12515 M
:= Make_Temporary
(Loc
, 'M');
12518 -- M : Integer := (0 | 1 | 2);
12521 Make_Object_Declaration
(Loc
,
12522 Defining_Identifier
=> M
,
12523 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12524 Expression
=> D_Disc
));
12526 -- Do the assignment at this stage only because the evaluation of the
12527 -- expression must not occur before (see ACVC C97302A).
12530 Make_Assignment_Statement
(Loc
,
12531 Name
=> New_Occurrence_Of
(D
, Loc
),
12532 Expression
=> D_Conv
));
12534 -- Parameter block processing
12536 -- Manually create the parameter block for dispatching calls. In the
12537 -- case of entries, the block has already been created during the call
12538 -- to Build_Simple_Entry_Call.
12540 if Is_Disp_Select
then
12542 -- Tagged kind processing, generate:
12543 -- K : Ada.Tags.Tagged_Kind :=
12544 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12546 K
:= Build_K
(Loc
, Decls
, Obj
);
12548 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12550 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12552 -- Dispatch table slot processing, generate:
12555 S
:= Build_S
(Loc
, Decls
);
12558 -- S := Ada.Tags.Get_Offset_Index
12559 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12562 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12565 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12567 -- where Obj is the controlling formal parameter, S is the dispatch
12568 -- table slot number of the dispatching operation, P is the wrapped
12569 -- parameter block, D is the duration, M is the duration mode, C is
12570 -- the call kind and B is the call status.
12572 Params
:= New_List
;
12574 Append_To
(Params
, New_Copy_Tree
(Obj
));
12575 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12577 Make_Attribute_Reference
(Loc
,
12578 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12579 Attribute_Name
=> Name_Address
));
12580 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12581 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12582 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12583 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12585 Append_To
(Conc_Typ_Stmts
,
12586 Make_Procedure_Call_Statement
(Loc
,
12590 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12591 Parameter_Associations
=> Params
));
12594 -- if C = POK_Protected_Entry
12595 -- or else C = POK_Task_Entry
12597 -- Param1 := P.Param1;
12599 -- ParamN := P.ParamN;
12602 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12604 -- Generate the if statement only when the packed parameters need
12605 -- explicit assignments to their corresponding actuals.
12607 if Present
(Unpack
) then
12608 Append_To
(Conc_Typ_Stmts
,
12609 Make_Implicit_If_Statement
(N
,
12615 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12618 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12622 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12624 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12626 Then_Statements
=> Unpack
));
12632 -- if C = POK_Procedure
12633 -- or else C = POK_Protected_Procedure
12634 -- or else C = POK_Task_Procedure
12636 -- <dispatching-call>
12640 N_Stats
:= New_List
(
12641 Make_Implicit_If_Statement
(N
,
12646 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12648 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12654 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12656 New_Occurrence_Of
(RTE
(
12657 RE_POK_Protected_Procedure
), Loc
)),
12660 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12663 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12665 Then_Statements
=> New_List
(E_Call
)));
12667 Append_To
(Conc_Typ_Stmts
,
12668 Make_Implicit_If_Statement
(N
,
12669 Condition
=> New_Occurrence_Of
(B
, Loc
),
12670 Then_Statements
=> N_Stats
));
12673 -- <dispatching-call>;
12677 New_List
(New_Copy_Tree
(E_Call
),
12678 Make_Assignment_Statement
(Loc
,
12679 Name
=> New_Occurrence_Of
(B
, Loc
),
12680 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12683 -- if K = Ada.Tags.TK_Limited_Tagged
12684 -- or else K = Ada.Tags.TK_Tagged
12692 Make_Implicit_If_Statement
(N
,
12693 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12694 Then_Statements
=> Lim_Typ_Stmts
,
12695 Else_Statements
=> Conc_Typ_Stmts
));
12700 -- <triggering-statements>
12702 -- <timed-statements>
12706 Make_Implicit_If_Statement
(N
,
12707 Condition
=> New_Occurrence_Of
(B
, Loc
),
12708 Then_Statements
=> E_Stats
,
12709 Else_Statements
=> D_Stats
));
12712 -- Simple case of a nondispatching trigger. Skip assignments to
12713 -- temporaries created for in-out parameters.
12715 -- This makes unwarranted assumptions about the shape of the expanded
12716 -- tree for the call, and should be cleaned up ???
12718 Stmt
:= First
(Stmts
);
12719 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12723 -- Do the assignment at this stage only because the evaluation
12724 -- of the expression must not occur before (see ACVC C97302A).
12726 Insert_Before
(Stmt
,
12727 Make_Assignment_Statement
(Loc
,
12728 Name
=> New_Occurrence_Of
(D
, Loc
),
12729 Expression
=> D_Conv
));
12732 Params
:= Parameter_Associations
(Call
);
12734 -- For a protected type, we build a Timed_Protected_Entry_Call
12736 if Is_Protected_Type
(Etype
(Concval
)) then
12738 -- Create a new call statement
12740 Param
:= First
(Params
);
12741 while Present
(Param
)
12742 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12747 Dummy
:= Remove_Next
(Next
(Param
));
12749 -- Remove garbage is following the Cancel_Param if present
12751 Dummy
:= Next
(Param
);
12753 -- Remove the mode of the Protected_Entry_Call call, then remove
12754 -- the Communication_Block of the Protected_Entry_Call call, and
12755 -- finally add Duration and a Delay_Mode parameter
12757 pragma Assert
(Present
(Param
));
12758 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12760 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12762 -- Add a Boolean flag for successful entry call
12764 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12766 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12767 when System_Tasking_Protected_Objects_Entries
=>
12769 Make_Procedure_Call_Statement
(Loc
,
12772 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12773 Parameter_Associations
=> Params
));
12776 raise Program_Error
;
12779 -- For the task case, build a Timed_Task_Entry_Call
12782 -- Create a new call statement
12784 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12785 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12786 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12789 Make_Procedure_Call_Statement
(Loc
,
12791 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12792 Parameter_Associations
=> Params
));
12796 Make_Implicit_If_Statement
(N
,
12797 Condition
=> New_Occurrence_Of
(B
, Loc
),
12798 Then_Statements
=> E_Stats
,
12799 Else_Statements
=> D_Stats
));
12803 Make_Block_Statement
(Loc
,
12804 Declarations
=> Decls
,
12805 Handled_Statement_Sequence
=>
12806 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12809 end Expand_N_Timed_Entry_Call
;
12811 ----------------------------------------
12812 -- Expand_Protected_Body_Declarations --
12813 ----------------------------------------
12815 procedure Expand_Protected_Body_Declarations
12817 Spec_Id
: Entity_Id
)
12820 if No_Run_Time_Mode
then
12821 Error_Msg_CRT
("protected body", N
);
12824 elsif Expander_Active
then
12826 -- Associate discriminals with the first subprogram or entry body to
12829 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12830 Set_Discriminals
(Parent
(Spec_Id
));
12833 end Expand_Protected_Body_Declarations
;
12835 -------------------------
12836 -- External_Subprogram --
12837 -------------------------
12839 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12840 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12843 -- The internal and external subprograms follow each other on the entity
12844 -- chain. Note that previously private operations had no separate
12845 -- external subprogram. We now create one in all cases, because a
12846 -- private operation may actually appear in an external call, through
12847 -- a 'Access reference used for a callback.
12849 -- If the operation is a function that returns an anonymous access type,
12850 -- the corresponding itype appears before the operation, and must be
12853 -- This mechanism is fragile, there should be a real link between the
12854 -- two versions of the operation, but there is no place to put it ???
12856 if Is_Access_Type
(Next_Entity
(Subp
)) then
12857 return Next_Entity
(Next_Entity
(Subp
));
12859 return Next_Entity
(Subp
);
12861 end External_Subprogram
;
12863 ------------------------------
12864 -- Extract_Dispatching_Call --
12865 ------------------------------
12867 procedure Extract_Dispatching_Call
12869 Call_Ent
: out Entity_Id
;
12870 Object
: out Entity_Id
;
12871 Actuals
: out List_Id
;
12872 Formals
: out List_Id
)
12874 Call_Nam
: Node_Id
;
12877 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12879 if Present
(Original_Node
(N
)) then
12880 Call_Nam
:= Name
(Original_Node
(N
));
12882 Call_Nam
:= Name
(N
);
12885 -- Retrieve the name of the dispatching procedure. It contains the
12886 -- dispatch table slot number.
12889 case Nkind
(Call_Nam
) is
12890 when N_Identifier
=>
12893 when N_Selected_Component
=>
12894 Call_Nam
:= Selector_Name
(Call_Nam
);
12897 raise Program_Error
;
12901 Actuals
:= Parameter_Associations
(N
);
12902 Call_Ent
:= Entity
(Call_Nam
);
12903 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12904 Object
:= First
(Actuals
);
12906 if Present
(Original_Node
(Object
)) then
12907 Object
:= Original_Node
(Object
);
12910 -- If the type of the dispatching object is an access type then return
12911 -- an explicit dereference of a copy of the object, and note that this
12912 -- is the controlling actual of the call.
12914 if Is_Access_Type
(Etype
(Object
)) then
12916 Make_Explicit_Dereference
(Sloc
(N
), New_Copy_Tree
(Object
));
12918 Set_Is_Controlling_Actual
(Object
);
12920 end Extract_Dispatching_Call
;
12922 -------------------
12923 -- Extract_Entry --
12924 -------------------
12926 procedure Extract_Entry
12928 Concval
: out Node_Id
;
12929 Ename
: out Node_Id
;
12930 Index
: out Node_Id
)
12932 Nam
: constant Node_Id
:= Name
(N
);
12935 -- For a simple entry, the name is a selected component, with the
12936 -- prefix being the task value, and the selector being the entry.
12938 if Nkind
(Nam
) = N_Selected_Component
then
12939 Concval
:= Prefix
(Nam
);
12940 Ename
:= Selector_Name
(Nam
);
12943 -- For a member of an entry family, the name is an indexed component
12944 -- where the prefix is a selected component, whose prefix in turn is
12945 -- the task value, and whose selector is the entry family. The single
12946 -- expression in the expressions list of the indexed component is the
12947 -- subscript for the family.
12949 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12950 Concval
:= Prefix
(Prefix
(Nam
));
12951 Ename
:= Selector_Name
(Prefix
(Nam
));
12952 Index
:= First
(Expressions
(Nam
));
12955 -- Through indirection, the type may actually be a limited view of a
12956 -- concurrent type. When compiling a call, the non-limited view of the
12957 -- type is visible.
12959 if From_Limited_With
(Etype
(Concval
)) then
12960 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12964 -------------------
12965 -- Family_Offset --
12966 -------------------
12968 function Family_Offset
12973 Cap
: Boolean) return Node_Id
12979 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12980 -- If one of the bounds is a reference to a discriminant, replace with
12981 -- corresponding discriminal of type. Within the body of a task retrieve
12982 -- the renamed discriminant by simple visibility, using its generated
12983 -- name. Within a protected object, find the original discriminant and
12984 -- replace it with the discriminal of the current protected operation.
12986 ------------------------------
12987 -- Convert_Discriminant_Ref --
12988 ------------------------------
12990 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12991 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12996 if Is_Entity_Name
(Bound
)
12997 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12999 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
13000 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13001 Find_Direct_Name
(B
);
13003 elsif Is_Protected_Type
(Ttyp
) then
13004 D
:= First_Discriminant
(Ttyp
);
13005 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
13006 Next_Discriminant
(D
);
13009 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
13012 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
13015 elsif Nkind
(Bound
) = N_Attribute_Reference
then
13019 B
:= New_Copy_Tree
(Bound
);
13023 Make_Attribute_Reference
(Loc
,
13024 Attribute_Name
=> Name_Pos
,
13025 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
13026 Expressions
=> New_List
(B
));
13027 end Convert_Discriminant_Ref
;
13029 -- Start of processing for Family_Offset
13032 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
13033 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
13036 if Is_Task_Type
(Ttyp
) then
13037 Ityp
:= RTE
(RE_Task_Entry_Index
);
13039 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13043 Make_Attribute_Reference
(Loc
,
13044 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13045 Attribute_Name
=> Name_Min
,
13046 Expressions
=> New_List
(
13048 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
13051 Make_Attribute_Reference
(Loc
,
13052 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13053 Attribute_Name
=> Name_Max
,
13054 Expressions
=> New_List
(
13056 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
13059 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
13066 function Family_Size
13071 Cap
: Boolean) return Node_Id
13076 if Is_Task_Type
(Ttyp
) then
13077 Ityp
:= RTE
(RE_Task_Entry_Index
);
13079 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13083 Make_Attribute_Reference
(Loc
,
13084 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13085 Attribute_Name
=> Name_Max
,
13086 Expressions
=> New_List
(
13088 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
13089 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
13090 Make_Integer_Literal
(Loc
, 0)));
13093 ----------------------------
13094 -- Find_Enclosing_Context --
13095 ----------------------------
13097 procedure Find_Enclosing_Context
13099 Context
: out Node_Id
;
13100 Context_Id
: out Entity_Id
;
13101 Context_Decls
: out List_Id
)
13104 -- Traverse the parent chain looking for an enclosing body, block,
13105 -- package or return statement.
13107 Context
:= Parent
(N
);
13108 while Present
(Context
) loop
13109 if Nkind_In
(Context
, N_Entry_Body
,
13110 N_Extended_Return_Statement
,
13112 N_Package_Declaration
,
13118 -- Do not consider block created to protect a list of statements with
13119 -- an Abort_Defer / Abort_Undefer_Direct pair.
13121 elsif Nkind
(Context
) = N_Block_Statement
13122 and then not Is_Abort_Block
(Context
)
13127 Context
:= Parent
(Context
);
13130 pragma Assert
(Present
(Context
));
13132 -- Extract the constituents of the context
13134 if Nkind
(Context
) = N_Extended_Return_Statement
then
13135 Context_Decls
:= Return_Object_Declarations
(Context
);
13136 Context_Id
:= Return_Statement_Entity
(Context
);
13138 -- Package declarations and bodies use a common library-level activation
13139 -- chain or task master, therefore return the package declaration as the
13140 -- proper carrier for the appropriate flag.
13142 elsif Nkind
(Context
) = N_Package_Body
then
13143 Context_Decls
:= Declarations
(Context
);
13144 Context_Id
:= Corresponding_Spec
(Context
);
13145 Context
:= Parent
(Context_Id
);
13147 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13148 Context
:= Parent
(Parent
(Context
));
13150 Context
:= Parent
(Context
);
13153 elsif Nkind
(Context
) = N_Package_Declaration
then
13154 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13155 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13157 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13158 Context_Id
:= Defining_Identifier
(Context_Id
);
13162 if Nkind
(Context
) = N_Block_Statement
then
13163 Context_Id
:= Entity
(Identifier
(Context
));
13165 elsif Nkind
(Context
) = N_Entry_Body
then
13166 Context_Id
:= Defining_Identifier
(Context
);
13168 elsif Nkind
(Context
) = N_Subprogram_Body
then
13169 if Present
(Corresponding_Spec
(Context
)) then
13170 Context_Id
:= Corresponding_Spec
(Context
);
13172 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13174 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13175 Context_Id
:= Defining_Identifier
(Context_Id
);
13179 elsif Nkind
(Context
) = N_Task_Body
then
13180 Context_Id
:= Corresponding_Spec
(Context
);
13183 raise Program_Error
;
13186 Context_Decls
:= Declarations
(Context
);
13189 pragma Assert
(Present
(Context_Id
));
13190 pragma Assert
(Present
(Context_Decls
));
13191 end Find_Enclosing_Context
;
13193 -----------------------
13194 -- Find_Master_Scope --
13195 -----------------------
13197 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13201 -- In Ada 2005, the master is the innermost enclosing scope that is not
13202 -- transient. If the enclosing block is the rewriting of a call or the
13203 -- scope is an extended return statement this is valid master. The
13204 -- master in an extended return is only used within the return, and is
13205 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13206 -- now before that overwriting occurs.
13210 if Ada_Version
>= Ada_2005
then
13211 while Is_Internal
(S
) loop
13212 if Nkind
(Parent
(S
)) = N_Block_Statement
13214 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
13218 elsif Ekind
(S
) = E_Return_Statement
then
13228 end Find_Master_Scope
;
13230 -------------------------------
13231 -- First_Protected_Operation --
13232 -------------------------------
13234 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13235 First_Op
: Node_Id
;
13238 First_Op
:= First
(D
);
13239 while Present
(First_Op
)
13240 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
13246 end First_Protected_Operation
;
13248 ---------------------------------------
13249 -- Install_Private_Data_Declarations --
13250 ---------------------------------------
13252 procedure Install_Private_Data_Declarations
13254 Spec_Id
: Entity_Id
;
13255 Conc_Typ
: Entity_Id
;
13256 Body_Nod
: Node_Id
;
13258 Barrier
: Boolean := False;
13259 Family
: Boolean := False)
13261 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13264 Insert_Node
: Node_Id
:= Empty
;
13265 Obj_Ent
: Entity_Id
;
13267 procedure Add
(Decl
: Node_Id
);
13268 -- Add a single declaration after Insert_Node. If this is the first
13269 -- addition, Decl is added to the front of Decls and it becomes the
13272 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13273 -- The bounds of an entry index may depend on discriminants, create a
13274 -- reference to the corresponding prival. Otherwise return a duplicate
13275 -- of the original bound.
13281 procedure Add
(Decl
: Node_Id
) is
13283 if No
(Insert_Node
) then
13284 Prepend_To
(Decls
, Decl
);
13286 Insert_After
(Insert_Node
, Decl
);
13289 Insert_Node
:= Decl
;
13292 --------------------------
13293 -- Replace_Discriminant --
13294 --------------------------
13296 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13298 if Nkind
(Bound
) = N_Identifier
13299 and then Is_Discriminal
(Entity
(Bound
))
13301 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13303 return Duplicate_Subexpr
(Bound
);
13307 -- Start of processing for Install_Private_Data_Declarations
13310 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13311 -- formal parameter _O, _object or _task depending on the context.
13313 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13315 -- Special processing of _O for barrier functions, protected entries
13322 (Ekind
(Spec_Id
) = E_Entry
13323 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13326 Conc_Rec
: constant Entity_Id
:=
13327 Corresponding_Record_Type
(Conc_Typ
);
13328 Typ_Id
: constant Entity_Id
:=
13329 Make_Defining_Identifier
(Loc
,
13330 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13333 -- type prot_typVP is access prot_typV;
13336 Make_Full_Type_Declaration
(Loc
,
13337 Defining_Identifier
=> Typ_Id
,
13339 Make_Access_To_Object_Definition
(Loc
,
13340 Subtype_Indication
=>
13341 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13345 -- _object : prot_typVP := prot_typV (_O);
13348 Make_Object_Declaration
(Loc
,
13349 Defining_Identifier
=>
13350 Make_Defining_Identifier
(Loc
, Name_uObject
),
13351 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13353 Unchecked_Convert_To
(Typ_Id
,
13354 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13357 -- Set the reference to the concurrent object
13359 Obj_Ent
:= Defining_Identifier
(Decl
);
13363 -- Step 2: Create the Protection object and build its declaration for
13364 -- any protected entry (family) of subprogram. Note for the lock-free
13365 -- implementation, the Protection object is not needed anymore.
13367 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13369 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13373 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13375 -- Determine the proper protection type
13377 if Has_Attach_Handler
(Conc_Typ
)
13378 and then not Restricted_Profile
13380 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13382 elsif Has_Interrupt_Handler
(Conc_Typ
)
13383 and then not Restriction_Active
(No_Dynamic_Attachment
)
13385 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13388 case Corresponding_Runtime_Package
(Conc_Typ
) is
13389 when System_Tasking_Protected_Objects_Entries
=>
13390 Prot_Typ
:= RE_Protection_Entries
;
13392 when System_Tasking_Protected_Objects_Single_Entry
=>
13393 Prot_Typ
:= RE_Protection_Entry
;
13395 when System_Tasking_Protected_Objects
=>
13396 Prot_Typ
:= RE_Protection
;
13399 raise Program_Error
;
13404 -- conc_typR : protection_typ renames _object._object;
13407 Make_Object_Renaming_Declaration
(Loc
,
13408 Defining_Identifier
=> Prot_Ent
,
13410 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13412 Make_Selected_Component
(Loc
,
13413 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13414 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13419 -- Step 3: Add discriminant renamings (if any)
13421 if Has_Discriminants
(Conc_Typ
) then
13426 D
:= First_Discriminant
(Conc_Typ
);
13427 while Present
(D
) loop
13429 -- Adjust the source location
13431 Set_Sloc
(Discriminal
(D
), Loc
);
13434 -- discr_name : discr_typ renames _object.discr_name;
13436 -- discr_name : discr_typ renames _task.discr_name;
13439 Make_Object_Renaming_Declaration
(Loc
,
13440 Defining_Identifier
=> Discriminal
(D
),
13441 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13443 Make_Selected_Component
(Loc
,
13444 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13445 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13448 Next_Discriminant
(D
);
13453 -- Step 4: Add private component renamings (if any)
13455 if Is_Protected
then
13456 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13458 if Present
(Private_Declarations
(Def
)) then
13461 Comp_Id
: Entity_Id
;
13462 Decl_Id
: Entity_Id
;
13465 Comp
:= First
(Private_Declarations
(Def
));
13466 while Present
(Comp
) loop
13467 if Nkind
(Comp
) = N_Component_Declaration
then
13468 Comp_Id
:= Defining_Identifier
(Comp
);
13470 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13472 -- Minimal decoration
13474 if Ekind
(Spec_Id
) = E_Function
then
13475 Set_Ekind
(Decl_Id
, E_Constant
);
13477 Set_Ekind
(Decl_Id
, E_Variable
);
13480 Set_Prival
(Comp_Id
, Decl_Id
);
13481 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13482 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13485 -- comp_name : comp_typ renames _object.comp_name;
13488 Make_Object_Renaming_Declaration
(Loc
,
13489 Defining_Identifier
=> Decl_Id
,
13491 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13493 Make_Selected_Component
(Loc
,
13495 New_Occurrence_Of
(Obj_Ent
, Loc
),
13497 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13507 -- Step 5: Add the declaration of the entry index and the associated
13508 -- type for barrier functions and entry families.
13510 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13512 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13513 Index
: constant Entity_Id
:=
13514 Defining_Identifier
13515 (Entry_Index_Specification
13516 (Entry_Body_Formal_Part
(Body_Nod
)));
13517 Index_Con
: constant Entity_Id
:=
13518 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13520 Index_Typ
: Entity_Id
;
13524 -- Minimal decoration
13526 Set_Ekind
(Index_Con
, E_Constant
);
13527 Set_Entry_Index_Constant
(Index
, Index_Con
);
13528 Set_Discriminal_Link
(Index_Con
, Index
);
13530 -- Retrieve the bounds of the entry family
13532 High
:= Type_High_Bound
(Etype
(Index
));
13533 Low
:= Type_Low_Bound
(Etype
(Index
));
13535 -- In the simple case the entry family is given by a subtype mark
13536 -- and the index constant has the same type.
13538 if Is_Entity_Name
(Original_Node
(
13539 Discrete_Subtype_Definition
(Parent
(Index
))))
13541 Index_Typ
:= Etype
(Index
);
13543 -- Otherwise a new subtype declaration is required
13546 High
:= Replace_Bound
(High
);
13547 Low
:= Replace_Bound
(Low
);
13549 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13552 -- subtype Jnn is <Etype of Index> range Low .. High;
13555 Make_Subtype_Declaration
(Loc
,
13556 Defining_Identifier
=> Index_Typ
,
13557 Subtype_Indication
=>
13558 Make_Subtype_Indication
(Loc
,
13560 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13562 Make_Range_Constraint
(Loc
,
13563 Range_Expression
=>
13564 Make_Range
(Loc
, Low
, High
))));
13568 Set_Etype
(Index_Con
, Index_Typ
);
13570 -- Create the object which designates the index:
13571 -- J : constant Jnn :=
13572 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13574 -- where Jnn is the subtype created above or the original type of
13575 -- the index, _E is a formal of the protected body subprogram and
13576 -- <index expr> is the index of the first family member.
13579 Make_Object_Declaration
(Loc
,
13580 Defining_Identifier
=> Index_Con
,
13581 Constant_Present
=> True,
13582 Object_Definition
=>
13583 New_Occurrence_Of
(Index_Typ
, Loc
),
13586 Make_Attribute_Reference
(Loc
,
13588 New_Occurrence_Of
(Index_Typ
, Loc
),
13589 Attribute_Name
=> Name_Val
,
13591 Expressions
=> New_List
(
13595 Make_Op_Subtract
(Loc
,
13596 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13598 Entry_Index_Expression
(Loc
,
13599 Defining_Identifier
(Body_Nod
),
13603 Make_Attribute_Reference
(Loc
,
13605 New_Occurrence_Of
(Index_Typ
, Loc
),
13606 Attribute_Name
=> Name_Pos
,
13607 Expressions
=> New_List
(
13608 Make_Attribute_Reference
(Loc
,
13610 New_Occurrence_Of
(Index_Typ
, Loc
),
13611 Attribute_Name
=> Name_First
)))))));
13615 end Install_Private_Data_Declarations
;
13617 ---------------------------------
13618 -- Is_Potentially_Large_Family --
13619 ---------------------------------
13621 function Is_Potentially_Large_Family
13622 (Base_Index
: Entity_Id
;
13623 Conctyp
: Entity_Id
;
13625 Hi
: Node_Id
) return Boolean
13628 return Scope
(Base_Index
) = Standard_Standard
13629 and then Base_Index
= Base_Type
(Standard_Integer
)
13630 and then Has_Discriminants
(Conctyp
)
13632 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13634 (Denotes_Discriminant
(Lo
, True)
13636 Denotes_Discriminant
(Hi
, True));
13637 end Is_Potentially_Large_Family
;
13639 -------------------------------------
13640 -- Is_Private_Primitive_Subprogram --
13641 -------------------------------------
13643 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13646 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13647 and then Is_Private_Primitive
(Id
);
13648 end Is_Private_Primitive_Subprogram
;
13654 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13655 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13656 Formal
: Entity_Id
;
13659 Formal
:= First_Formal
(Bod_Subp
);
13660 while Present
(Formal
) loop
13662 -- Look for formal parameter _E
13664 if Chars
(Formal
) = Name_uE
then
13668 Next_Formal
(Formal
);
13671 -- A protected body subprogram should always have the parameter in
13674 raise Program_Error
;
13677 --------------------------------
13678 -- Make_Initialize_Protection --
13679 --------------------------------
13681 function Make_Initialize_Protection
13682 (Protect_Rec
: Entity_Id
) return List_Id
13684 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13687 Ptyp
: constant Node_Id
:=
13688 Corresponding_Concurrent_Type
(Protect_Rec
);
13690 L
: constant List_Id
:= New_List
;
13691 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13692 Prio_Type
: Entity_Id
;
13693 Prio_Var
: Entity_Id
:= Empty
;
13694 Restricted
: constant Boolean := Restricted_Profile
;
13697 -- We may need two calls to properly initialize the object, one to
13698 -- Initialize_Protection, and possibly one to Install_Handlers if we
13699 -- have a pragma Attach_Handler.
13701 -- Get protected declaration. In the case of a task type declaration,
13702 -- this is simply the parent of the protected type entity. In the single
13703 -- protected object declaration, this parent will be the implicit type,
13704 -- and we can find the corresponding single protected object declaration
13705 -- by searching forward in the declaration list in the tree.
13707 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13708 -- of this type should have been removed during semantic analysis.
13710 Pdec
:= Parent
(Ptyp
);
13711 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13712 N_Single_Protected_Declaration
)
13717 -- Build the parameter list for the call. Note that _Init is the name
13718 -- of the formal for the object to be initialized, which is the task
13719 -- value record itself.
13723 -- For lock-free implementation, skip initializations of the Protection
13726 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13728 -- Object parameter. This is a pointer to the object of type
13729 -- Protection used by the GNARL to control the protected object.
13732 Make_Attribute_Reference
(Loc
,
13734 Make_Selected_Component
(Loc
,
13735 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13736 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13737 Attribute_Name
=> Name_Unchecked_Access
));
13739 -- Priority parameter. Set to Unspecified_Priority unless there is a
13740 -- Priority rep item, in which case we take the value from the pragma
13741 -- or attribute definition clause, or there is an Interrupt_Priority
13742 -- rep item and no Priority rep item, and we set the ceiling to
13743 -- Interrupt_Priority'Last, an implementation-defined value, see
13746 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13748 Prio_Clause
: constant Node_Id
:=
13750 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13757 if Nkind
(Prio_Clause
) = N_Pragma
then
13760 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13762 -- Get_Rep_Item returns either priority pragma
13764 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13765 Prio_Type
:= RTE
(RE_Any_Priority
);
13767 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13770 -- Attribute definition clause Priority
13773 if Chars
(Prio_Clause
) = Name_Priority
then
13774 Prio_Type
:= RTE
(RE_Any_Priority
);
13776 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13779 Prio
:= Expression
(Prio_Clause
);
13782 -- Always create a locale variable to capture the priority.
13783 -- The priority is also passed to Install_Restriced_Handlers.
13784 -- Note that it is really necessary to create this variable
13785 -- explicitly. It might be thought that removing side effects
13786 -- would the appropriate approach, but that could generate
13787 -- declarations improperly placed in the enclosing scope.
13789 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13791 Make_Object_Declaration
(Loc
,
13792 Defining_Identifier
=> Prio_Var
,
13793 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13794 Expression
=> Relocate_Node
(Prio
)));
13796 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13799 -- When no priority is specified but an xx_Handler pragma is, we
13800 -- default to System.Interrupts.Default_Interrupt_Priority, see
13803 elsif Has_Attach_Handler
(Ptyp
)
13804 or else Has_Interrupt_Handler
(Ptyp
)
13807 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13809 -- Normal case, no priority or xx_Handler specified, default priority
13813 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13816 -- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
13818 if Restricted_Profile
and Task_Dispatching_Policy
= 'E' then
13819 Deadline_Floor
: declare
13820 Item
: constant Node_Id
:=
13822 (Ptyp
, Name_Deadline_Floor
, Check_Parents
=> False);
13824 Deadline
: Node_Id
;
13827 if Present
(Item
) then
13829 -- Pragma Deadline_Floor
13831 if Nkind
(Item
) = N_Pragma
then
13834 (First
(Pragma_Argument_Associations
(Item
)));
13836 -- Attribute definition clause Deadline_Floor
13840 (Nkind
(Item
) = N_Attribute_Definition_Clause
);
13842 Deadline
:= Expression
(Item
);
13845 Append_To
(Args
, Deadline
);
13847 -- Unusual case: default deadline
13851 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
13853 end Deadline_Floor
;
13856 -- Test for Compiler_Info parameter. This parameter allows entry body
13857 -- procedures and barrier functions to be called from the runtime. It
13858 -- is a pointer to the record generated by the compiler to represent
13859 -- the protected object.
13861 -- A protected type without entries that covers an interface and
13862 -- overrides the abstract routines with protected procedures is
13863 -- considered equivalent to a protected type with entries in the
13864 -- context of dispatching select statements.
13866 -- Protected types with interrupt handlers (when not using a
13867 -- restricted profile) are also considered equivalent to protected
13868 -- types with entries.
13870 -- The types which are used (Static_Interrupt_Protection and
13871 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13874 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13876 Called_Subp
: RE_Id
;
13880 when System_Tasking_Protected_Objects_Entries
=>
13881 Called_Subp
:= RE_Initialize_Protection_Entries
;
13883 -- Argument Compiler_Info
13886 Make_Attribute_Reference
(Loc
,
13887 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13888 Attribute_Name
=> Name_Address
));
13890 when System_Tasking_Protected_Objects_Single_Entry
=>
13891 Called_Subp
:= RE_Initialize_Protection_Entry
;
13893 -- Argument Compiler_Info
13896 Make_Attribute_Reference
(Loc
,
13897 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13898 Attribute_Name
=> Name_Address
));
13900 when System_Tasking_Protected_Objects
=>
13901 Called_Subp
:= RE_Initialize_Protection
;
13904 raise Program_Error
;
13907 -- Entry_Queue_Maxes parameter. This is an access to an array of
13908 -- naturals representing the entry queue maximums for each entry
13909 -- in the protected type. Zero represents no max. The access is
13910 -- null if there is no limit for all entries (usual case).
13913 and then Pkg_Id
= System_Tasking_Protected_Objects_Entries
13915 if Present
(Entry_Max_Queue_Lengths_Array
(Ptyp
)) then
13917 Make_Attribute_Reference
(Loc
,
13920 (Entry_Max_Queue_Lengths_Array
(Ptyp
), Loc
),
13921 Attribute_Name
=> Name_Unrestricted_Access
));
13923 Append_To
(Args
, Make_Null
(Loc
));
13926 -- Edge cases exist where entry initialization functions are
13927 -- called, but no entries exist, so null is appended.
13929 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13930 Append_To
(Args
, Make_Null
(Loc
));
13933 -- Entry_Bodies parameter. This is a pointer to an array of
13934 -- pointers to the entry body procedures and barrier functions of
13935 -- the object. If the protected type has no entries this object
13936 -- will not exist, in this case, pass a null (it can happen when
13937 -- there are protected interrupt handlers or interfaces).
13940 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13942 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13943 -- multiple entries).
13946 Make_Attribute_Reference
(Loc
,
13947 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13948 Attribute_Name
=> Name_Unrestricted_Access
));
13950 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13952 -- Find index mapping function (clumsy but ok for now)
13954 while Ekind
(P_Arr
) /= E_Function
loop
13955 Next_Entity
(P_Arr
);
13959 Make_Attribute_Reference
(Loc
,
13960 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13961 Attribute_Name
=> Name_Unrestricted_Access
));
13964 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13966 -- This is the case where we have a protected object with
13967 -- interfaces and no entries, and the single entry restriction
13968 -- is in effect. We pass a null pointer for the entry
13969 -- parameter because there is no actual entry.
13971 Append_To
(Args
, Make_Null
(Loc
));
13973 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13975 -- This is the case where we have a protected object with no
13977 -- - either interrupt handlers with non restricted profile,
13979 -- Note that the types which are used for interrupt handlers
13980 -- (Static/Dynamic_Interrupt_Protection) are derived from
13981 -- Protection_Entries. We pass two null pointers because there
13982 -- is no actual entry, and the initialization procedure needs
13983 -- both Entry_Bodies and Find_Body_Index.
13985 Append_To
(Args
, Make_Null
(Loc
));
13986 Append_To
(Args
, Make_Null
(Loc
));
13990 Make_Procedure_Call_Statement
(Loc
,
13992 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
13993 Parameter_Associations
=> Args
));
13997 if Has_Attach_Handler
(Ptyp
) then
13999 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
14000 -- make the following call:
14002 -- Install_Handlers (_object,
14003 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
14005 -- or, in the case of Ravenscar:
14007 -- Install_Restricted_Handlers
14008 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
14011 Args
: constant List_Id
:= New_List
;
14012 Table
: constant List_Id
:= New_List
;
14013 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
14016 -- Build the Priority parameter (only for ravenscar)
14020 -- Priority comes from a pragma
14022 if Present
(Prio_Var
) then
14023 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
14025 -- Priority is the default one
14030 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
14034 -- Build the Attach_Handler table argument
14036 while Present
(Ritem
) loop
14037 if Nkind
(Ritem
) = N_Pragma
14038 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
14041 Handler
: constant Node_Id
:=
14042 First
(Pragma_Argument_Associations
(Ritem
));
14044 Interrupt
: constant Node_Id
:= Next
(Handler
);
14045 Expr
: constant Node_Id
:= Expression
(Interrupt
);
14049 Make_Aggregate
(Loc
, Expressions
=> New_List
(
14050 Unchecked_Convert_To
14051 (RTE
(RE_System_Interrupt_Id
), Expr
),
14052 Make_Attribute_Reference
(Loc
,
14054 Make_Selected_Component
(Loc
,
14056 Make_Identifier
(Loc
, Name_uInit
),
14058 Duplicate_Subexpr_No_Checks
14059 (Expression
(Handler
))),
14060 Attribute_Name
=> Name_Access
))));
14064 Next_Rep_Item
(Ritem
);
14067 -- Append the table argument we just built
14069 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
14071 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14072 -- call to the statements.
14075 -- Call a simplified version of Install_Handlers to be used
14076 -- when the Ravenscar restrictions are in effect
14077 -- (Install_Restricted_Handlers).
14080 Make_Procedure_Call_Statement
(Loc
,
14083 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
14084 Parameter_Associations
=> Args
));
14087 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
14089 -- First, prepends the _object argument
14092 Make_Attribute_Reference
(Loc
,
14094 Make_Selected_Component
(Loc
,
14095 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14097 Make_Identifier
(Loc
, Name_uObject
)),
14098 Attribute_Name
=> Name_Unchecked_Access
));
14101 -- Then, insert call to Install_Handlers
14104 Make_Procedure_Call_Statement
(Loc
,
14106 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
14107 Parameter_Associations
=> Args
));
14113 end Make_Initialize_Protection
;
14115 ---------------------------
14116 -- Make_Task_Create_Call --
14117 ---------------------------
14119 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
14120 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14130 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14131 Tnam
:= Chars
(Ttyp
);
14133 -- Get task declaration. In the case of a task type declaration, this is
14134 -- simply the parent of the task type entity. In the single task
14135 -- declaration, this parent will be the implicit type, and we can find
14136 -- the corresponding single task declaration by searching forward in the
14137 -- declaration list in the tree.
14139 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14140 -- this type should have been removed during semantic analysis.
14142 Tdec
:= Parent
(Ttyp
);
14143 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
14144 N_Single_Task_Declaration
)
14149 -- Now we can find the task definition from this declaration
14151 Tdef
:= Task_Definition
(Tdec
);
14153 -- Build the parameter list for the call. Note that _Init is the name
14154 -- of the formal for the object to be initialized, which is the task
14155 -- value record itself.
14159 -- Priority parameter. Set to Unspecified_Priority unless there is a
14160 -- Priority rep item, in which case we take the value from the rep item.
14161 -- Not used on Ravenscar_EDF profile.
14163 if not (Restricted_Profile
and then Task_Dispatching_Policy
= 'E') then
14164 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14166 Make_Selected_Component
(Loc
,
14167 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14168 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14171 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14175 -- Optional Stack parameter
14177 if Restricted_Profile
then
14179 -- If the stack has been preallocated by the expander then
14180 -- pass its address. Otherwise, pass a null address.
14182 if Preallocated_Stacks_On_Target
then
14184 Make_Attribute_Reference
(Loc
,
14186 Make_Selected_Component
(Loc
,
14187 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14188 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14189 Attribute_Name
=> Name_Address
));
14193 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14197 -- Size parameter. If no Storage_Size pragma is present, then
14198 -- the size is taken from the taskZ variable for the type, which
14199 -- is either Unspecified_Size, or has been reset by the use of
14200 -- a Storage_Size attribute definition clause. If a pragma is
14201 -- present, then the size is taken from the _Size field of the
14202 -- task value record, which was set from the pragma value.
14204 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14206 Make_Selected_Component
(Loc
,
14207 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14208 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14212 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14215 -- Secondary_Stack parameter used for restricted profiles
14217 if Restricted_Profile
then
14219 -- If the secondary stack has been allocated by the expander then
14220 -- pass its access pointer. Otherwise, pass null.
14222 if Create_Secondary_Stack_For_Task
(Ttyp
) then
14224 Make_Attribute_Reference
(Loc
,
14226 Make_Selected_Component
(Loc
,
14227 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14229 Make_Identifier
(Loc
, Name_uSecondary_Stack
)),
14230 Attribute_Name
=> Name_Unrestricted_Access
));
14233 Append_To
(Args
, Make_Null
(Loc
));
14237 -- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there
14238 -- is a Secondary_Stack_Size rep item, in which case take the value from
14239 -- the rep item. If the restriction No_Secondary_Stack is active then a
14240 -- size of 0 is passed regardless to prevent the allocation of the
14243 if Restriction_Active
(No_Secondary_Stack
) then
14244 Append_To
(Args
, Make_Integer_Literal
(Loc
, 0));
14247 (Ttyp
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
14250 Make_Selected_Component
(Loc
,
14251 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14253 Make_Identifier
(Loc
, Name_uSecondary_Stack_Size
)));
14257 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
14260 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14261 -- Task_Info pragma, in which case we take the value from the pragma.
14263 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14265 Make_Selected_Component
(Loc
,
14266 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14267 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14271 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14274 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14275 -- in which case we take the value from the rep item. The parameter is
14276 -- passed as an Integer because in the case of unspecified CPU the
14277 -- value is not in the range of CPU_Range.
14279 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14281 Convert_To
(Standard_Integer
,
14282 Make_Selected_Component
(Loc
,
14283 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14284 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14287 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14290 if not Restricted_Profile
or else Task_Dispatching_Policy
= 'E' then
14292 -- Deadline parameter. If no Relative_Deadline pragma is present,
14293 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14294 -- the deadline is taken from the _Relative_Deadline field of the
14295 -- task value record, which was set from the pragma value. Note that
14296 -- this parameter must not be generated for the restricted profiles
14297 -- since Ravenscar does not allow deadlines.
14299 -- Case where pragma Relative_Deadline applies: use given value
14301 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14303 Make_Selected_Component
(Loc
,
14304 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14306 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14308 -- No pragma Relative_Deadline apply to the task
14312 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14316 if not Restricted_Profile
then
14318 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14319 -- present, then the dispatching domain is null. If a rep item is
14320 -- present, then the dispatching domain is taken from the
14321 -- _Dispatching_Domain field of the task value record, which was set
14322 -- from the rep item value.
14324 -- Case where Dispatching_Domain rep item applies: use given value
14327 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14330 Make_Selected_Component
(Loc
,
14332 Make_Identifier
(Loc
, Name_uInit
),
14334 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14336 -- No pragma or aspect Dispatching_Domain applies to the task
14339 Append_To
(Args
, Make_Null
(Loc
));
14342 -- Number of entries. This is an expression of the form:
14344 -- n + _Init.a'Length + _Init.a'B'Length + ...
14346 -- where a,b... are the entry family names for the task definition
14349 Build_Entry_Count_Expression
14354 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14356 Append_To
(Args
, Ecount
);
14358 -- Master parameter. This is a reference to the _Master parameter of
14359 -- the initialization procedure, except in the case of the pragma
14360 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14361 -- System.Tasking.Library_Task_Level.
14363 if Restriction_Active
(No_Task_Hierarchy
) = False then
14364 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14367 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14371 -- State parameter. This is a pointer to the task body procedure. The
14372 -- required value is obtained by taking 'Unrestricted_Access of the task
14373 -- body procedure and converting it (with an unchecked conversion) to
14374 -- the type required by the task kernel. For further details, see the
14375 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14376 -- than 'Address in order to avoid creating trampolines.
14379 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14380 Subp_Ptr_Typ
: constant Node_Id
:=
14381 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14382 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14385 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14386 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14388 -- Be sure to freeze a reference to the access-to-subprogram type,
14389 -- otherwise gigi will complain that it's in the wrong scope, because
14390 -- it's actually inside the init procedure for the record type that
14391 -- corresponds to the task type.
14393 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14394 Append_Freeze_Action
(Task_Rec
, Ref
);
14397 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14398 Make_Qualified_Expression
(Loc
,
14399 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14401 Make_Attribute_Reference
(Loc
,
14402 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14403 Attribute_Name
=> Name_Unrestricted_Access
))));
14406 -- Discriminants parameter. This is just the address of the task
14407 -- value record itself (which contains the discriminant values
14410 Make_Attribute_Reference
(Loc
,
14411 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14412 Attribute_Name
=> Name_Address
));
14414 -- Elaborated parameter. This is an access to the elaboration Boolean
14417 Make_Attribute_Reference
(Loc
,
14418 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14419 Attribute_Name
=> Name_Unchecked_Access
));
14421 -- Add Chain parameter (not done for sequential elaboration policy, see
14422 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14424 if Partition_Elaboration_Policy
/= 'S' then
14425 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14428 -- Task name parameter. Take this from the _Task_Id parameter to the
14429 -- init call unless there is a Task_Name pragma, in which case we take
14430 -- the value from the pragma.
14432 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14433 -- Copy expression in full, because it may be dynamic and have
14440 (Pragma_Argument_Associations
14442 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14445 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14448 -- Created_Task parameter. This is the _Task_Id field of the task
14452 Make_Selected_Component
(Loc
,
14453 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14454 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14460 if Restricted_Profile
then
14461 if Partition_Elaboration_Policy
= 'S' then
14462 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14464 Create_RE
:= RE_Create_Restricted_Task
;
14467 Create_RE
:= RE_Create_Task
;
14470 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14474 Make_Procedure_Call_Statement
(Loc
,
14476 Parameter_Associations
=> Args
);
14477 end Make_Task_Create_Call
;
14479 ------------------------------
14480 -- Next_Protected_Operation --
14481 ------------------------------
14483 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14487 -- Check whether there is a subsequent body for a protected operation
14488 -- in the current protected body. In Ada2012 that includes expression
14489 -- functions that are completions.
14491 Next_Op
:= Next
(N
);
14492 while Present
(Next_Op
)
14493 and then not Nkind_In
(Next_Op
,
14494 N_Subprogram_Body
, N_Entry_Body
, N_Expression_Function
)
14500 end Next_Protected_Operation
;
14502 ---------------------
14503 -- Null_Statements --
14504 ---------------------
14506 function Null_Statements
(Stats
: List_Id
) return Boolean is
14510 Stmt
:= First
(Stats
);
14511 while Nkind
(Stmt
) /= N_Empty
14512 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14514 (Nkind
(Stmt
) = N_Pragma
14516 Nam_In
(Pragma_Name_Unmapped
(Stmt
),
14524 return Nkind
(Stmt
) = N_Empty
;
14525 end Null_Statements
;
14527 --------------------------
14528 -- Parameter_Block_Pack --
14529 --------------------------
14531 function Parameter_Block_Pack
14533 Blk_Typ
: Entity_Id
;
14537 Stmts
: List_Id
) return Node_Id
14539 Actual
: Entity_Id
;
14540 Expr
: Node_Id
:= Empty
;
14541 Formal
: Entity_Id
;
14542 Has_Param
: Boolean := False;
14545 Temp_Asn
: Node_Id
;
14546 Temp_Nam
: Node_Id
;
14549 Actual
:= First
(Actuals
);
14550 Formal
:= Defining_Identifier
(First
(Formals
));
14551 Params
:= New_List
;
14552 while Present
(Actual
) loop
14553 if Is_By_Copy_Type
(Etype
(Actual
)) then
14555 -- Jnn : aliased <formal-type>
14557 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14560 Make_Object_Declaration
(Loc
,
14561 Aliased_Present
=> True,
14562 Defining_Identifier
=> Temp_Nam
,
14563 Object_Definition
=>
14564 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14566 -- The object is initialized with an explicit assignment
14567 -- later. Indicate that it does not need an initialization
14568 -- to prevent spurious warnings if the type excludes null.
14570 Set_No_Initialization
(Last
(Decls
));
14572 if Ekind
(Formal
) /= E_Out_Parameter
then
14578 New_Occurrence_Of
(Temp_Nam
, Loc
);
14580 Set_Assignment_OK
(Temp_Asn
);
14583 Make_Assignment_Statement
(Loc
,
14585 Expression
=> New_Copy_Tree
(Actual
)));
14588 -- If the actual is not controlling, generate:
14590 -- Jnn'unchecked_access
14592 -- and add it to aggegate for access to formals. Note that the
14593 -- actual may be by-copy but still be a controlling actual if it
14594 -- is an access to class-wide interface.
14596 if not Is_Controlling_Actual
(Actual
) then
14598 Make_Attribute_Reference
(Loc
,
14599 Attribute_Name
=> Name_Unchecked_Access
,
14600 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14605 -- The controlling parameter is omitted
14608 if not Is_Controlling_Actual
(Actual
) then
14610 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14616 Next_Actual
(Actual
);
14617 Next_Formal_With_Extras
(Formal
);
14621 Expr
:= Make_Aggregate
(Loc
, Params
);
14626 -- J1'unchecked_access;
14627 -- <actual2>'reference;
14630 P
:= Make_Temporary
(Loc
, 'P');
14633 Make_Object_Declaration
(Loc
,
14634 Defining_Identifier
=> P
,
14635 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14636 Expression
=> Expr
));
14639 end Parameter_Block_Pack
;
14641 ----------------------------
14642 -- Parameter_Block_Unpack --
14643 ----------------------------
14645 function Parameter_Block_Unpack
14649 Formals
: List_Id
) return List_Id
14651 Actual
: Entity_Id
;
14653 Formal
: Entity_Id
;
14654 Has_Asnmt
: Boolean := False;
14655 Result
: constant List_Id
:= New_List
;
14658 Actual
:= First
(Actuals
);
14659 Formal
:= Defining_Identifier
(First
(Formals
));
14660 while Present
(Actual
) loop
14661 if Is_By_Copy_Type
(Etype
(Actual
))
14662 and then Ekind
(Formal
) /= E_In_Parameter
14665 -- <actual> := P.<formal>;
14668 Make_Assignment_Statement
(Loc
,
14672 Make_Explicit_Dereference
(Loc
,
14673 Make_Selected_Component
(Loc
,
14675 New_Occurrence_Of
(P
, Loc
),
14677 Make_Identifier
(Loc
, Chars
(Formal
)))));
14679 Set_Assignment_OK
(Name
(Asnmt
));
14680 Append_To
(Result
, Asnmt
);
14685 Next_Actual
(Actual
);
14686 Next_Formal_With_Extras
(Formal
);
14692 return New_List
(Make_Null_Statement
(Loc
));
14694 end Parameter_Block_Unpack
;
14696 ----------------------
14697 -- Set_Discriminals --
14698 ----------------------
14700 procedure Set_Discriminals
(Dec
: Node_Id
) is
14703 D_Minal
: Entity_Id
;
14706 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14707 Pdef
:= Defining_Identifier
(Dec
);
14709 if Has_Discriminants
(Pdef
) then
14710 D
:= First_Discriminant
(Pdef
);
14711 while Present
(D
) loop
14713 Make_Defining_Identifier
(Sloc
(D
),
14714 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14716 Set_Ekind
(D_Minal
, E_Constant
);
14717 Set_Etype
(D_Minal
, Etype
(D
));
14718 Set_Scope
(D_Minal
, Pdef
);
14719 Set_Discriminal
(D
, D_Minal
);
14720 Set_Discriminal_Link
(D_Minal
, D
);
14722 Next_Discriminant
(D
);
14725 end Set_Discriminals
;
14727 -----------------------
14728 -- Trivial_Accept_OK --
14729 -----------------------
14731 function Trivial_Accept_OK
return Boolean is
14733 case Opt
.Task_Dispatching_Policy
is
14735 -- If we have the default task dispatching policy in effect, we can
14736 -- definitely do the optimization (one way of looking at this is to
14737 -- think of the formal definition of the default policy being allowed
14738 -- to run any task it likes after a rendezvous, so even if notionally
14739 -- a full rescheduling occurs, we can say that our dispatching policy
14740 -- (i.e. the default dispatching policy) reorders the queue to be the
14741 -- same as just before the call.
14746 -- FIFO_Within_Priorities certainly does not permit this
14747 -- optimization since the Rendezvous is a scheduling action that may
14748 -- require some other task to be run.
14753 -- For now, disallow the optimization for all other policies. This
14754 -- may be over-conservative, but it is certainly not incorrect.
14759 end Trivial_Accept_OK
;