1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, 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_Sel
; use Exp_Sel
;
35 with Exp_Smem
; use Exp_Smem
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Freeze
; use Freeze
;
40 with Itypes
; use Itypes
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Ch9
; use Sem_Ch9
;
53 with Sem_Ch11
; use Sem_Ch11
;
54 with Sem_Elab
; use Sem_Elab
;
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
)));
4909 if Legacy_Elaboration_Checks
then
4910 Check_Task_Activation
(N
);
4912 end Build_Task_Activation_Call
;
4914 -------------------------------
4915 -- Build_Task_Allocate_Block --
4916 -------------------------------
4918 procedure Build_Task_Allocate_Block
4923 T
: constant Entity_Id
:= Entity
(Expression
(N
));
4924 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
4925 Loc
: constant Source_Ptr
:= Sloc
(N
);
4926 Chain
: constant Entity_Id
:=
4927 Make_Defining_Identifier
(Loc
, Name_uChain
);
4928 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4933 Make_Block_Statement
(Loc
,
4934 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4935 Declarations
=> New_List
(
4937 -- _Chain : Activation_Chain;
4939 Make_Object_Declaration
(Loc
,
4940 Defining_Identifier
=> Chain
,
4941 Aliased_Present
=> True,
4942 Object_Definition
=>
4943 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4945 Handled_Statement_Sequence
=>
4946 Make_Handled_Sequence_Of_Statements
(Loc
,
4948 Statements
=> New_List
(
4952 Make_Procedure_Call_Statement
(Loc
,
4953 Name
=> New_Occurrence_Of
(Init
, Loc
),
4954 Parameter_Associations
=> Args
),
4956 -- Activate_Tasks (_Chain);
4958 Make_Procedure_Call_Statement
(Loc
,
4959 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4960 Parameter_Associations
=> New_List
(
4961 Make_Attribute_Reference
(Loc
,
4962 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4963 Attribute_Name
=> Name_Unchecked_Access
))))),
4965 Has_Created_Identifier
=> True,
4966 Is_Task_Allocation_Block
=> True);
4969 Make_Implicit_Label_Declaration
(Loc
,
4970 Defining_Identifier
=> Blkent
,
4971 Label_Construct
=> Block
));
4973 Append_To
(Actions
, Block
);
4975 Set_Activation_Chain_Entity
(Block
, Chain
);
4976 end Build_Task_Allocate_Block
;
4978 -----------------------------------------------
4979 -- Build_Task_Allocate_Block_With_Init_Stmts --
4980 -----------------------------------------------
4982 procedure Build_Task_Allocate_Block_With_Init_Stmts
4985 Init_Stmts
: List_Id
)
4987 Loc
: constant Source_Ptr
:= Sloc
(N
);
4988 Chain
: constant Entity_Id
:=
4989 Make_Defining_Identifier
(Loc
, Name_uChain
);
4990 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4994 Append_To
(Init_Stmts
,
4995 Make_Procedure_Call_Statement
(Loc
,
4996 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4997 Parameter_Associations
=> New_List
(
4998 Make_Attribute_Reference
(Loc
,
4999 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5000 Attribute_Name
=> Name_Unchecked_Access
))));
5003 Make_Block_Statement
(Loc
,
5004 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
5005 Declarations
=> New_List
(
5007 -- _Chain : Activation_Chain;
5009 Make_Object_Declaration
(Loc
,
5010 Defining_Identifier
=> Chain
,
5011 Aliased_Present
=> True,
5012 Object_Definition
=>
5013 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
5015 Handled_Statement_Sequence
=>
5016 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5018 Has_Created_Identifier
=> True,
5019 Is_Task_Allocation_Block
=> True);
5022 Make_Implicit_Label_Declaration
(Loc
,
5023 Defining_Identifier
=> Blkent
,
5024 Label_Construct
=> Block
));
5026 Append_To
(Actions
, Block
);
5028 Set_Activation_Chain_Entity
(Block
, Chain
);
5029 end Build_Task_Allocate_Block_With_Init_Stmts
;
5031 -----------------------------------
5032 -- Build_Task_Proc_Specification --
5033 -----------------------------------
5035 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5036 Loc
: constant Source_Ptr
:= Sloc
(T
);
5037 Spec_Id
: Entity_Id
;
5040 -- Case of explicit task type, suffix TB
5042 if Comes_From_Source
(T
) then
5044 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
5046 -- Case of anonymous task type, suffix B
5050 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
5053 Set_Is_Internal
(Spec_Id
);
5055 -- Associate the procedure with the task, if this is the declaration
5056 -- (and not the body) of the procedure.
5058 if No
(Task_Body_Procedure
(T
)) then
5059 Set_Task_Body_Procedure
(T
, Spec_Id
);
5063 Make_Procedure_Specification
(Loc
,
5064 Defining_Unit_Name
=> Spec_Id
,
5065 Parameter_Specifications
=> New_List
(
5066 Make_Parameter_Specification
(Loc
,
5067 Defining_Identifier
=>
5068 Make_Defining_Identifier
(Loc
, Name_uTask
),
5070 Make_Access_Definition
(Loc
,
5072 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
5073 end Build_Task_Proc_Specification
;
5075 ---------------------------------------
5076 -- Build_Unprotected_Subprogram_Body --
5077 ---------------------------------------
5079 function Build_Unprotected_Subprogram_Body
5081 Pid
: Node_Id
) return Node_Id
5083 Decls
: constant List_Id
:= Declarations
(N
);
5086 -- Add renamings for the Protection object, discriminals, privals, and
5087 -- the entry index constant for use by debugger.
5089 Debug_Private_Data_Declarations
(Decls
);
5091 -- Make an unprotected version of the subprogram for use within the same
5092 -- object, with a new name and an additional parameter representing the
5096 Make_Subprogram_Body
(Sloc
(N
),
5098 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5099 Declarations
=> Decls
,
5100 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5101 end Build_Unprotected_Subprogram_Body
;
5103 ----------------------------
5104 -- Collect_Entry_Families --
5105 ----------------------------
5107 procedure Collect_Entry_Families
5110 Current_Node
: in out Node_Id
;
5111 Conctyp
: Entity_Id
)
5114 Efam_Decl
: Node_Id
;
5115 Efam_Type
: Entity_Id
;
5118 Efam
:= First_Entity
(Conctyp
);
5119 while Present
(Efam
) loop
5120 if Ekind
(Efam
) = E_Entry_Family
then
5121 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5126 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5128 Bas_Decl
: Node_Id
:= Empty
;
5133 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5135 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5136 Bas
:= Make_Temporary
(Loc
, 'B');
5139 Make_Subtype_Declaration
(Loc
,
5140 Defining_Identifier
=> Bas
,
5141 Subtype_Indication
=>
5142 Make_Subtype_Indication
(Loc
,
5144 New_Occurrence_Of
(Standard_Integer
, Loc
),
5146 Make_Range_Constraint
(Loc
,
5147 Range_Expression
=> Make_Range
(Loc
,
5148 Make_Integer_Literal
5149 (Loc
, -Entry_Family_Bound
),
5150 Make_Integer_Literal
5151 (Loc
, Entry_Family_Bound
- 1)))));
5153 Insert_After
(Current_Node
, Bas_Decl
);
5154 Current_Node
:= Bas_Decl
;
5159 Make_Full_Type_Declaration
(Loc
,
5160 Defining_Identifier
=> Efam_Type
,
5162 Make_Unconstrained_Array_Definition
(Loc
,
5164 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5166 Component_Definition
=>
5167 Make_Component_Definition
(Loc
,
5168 Aliased_Present
=> False,
5169 Subtype_Indication
=>
5170 New_Occurrence_Of
(Standard_Character
, Loc
))));
5173 Insert_After
(Current_Node
, Efam_Decl
);
5174 Current_Node
:= Efam_Decl
;
5175 Analyze
(Efam_Decl
);
5178 Make_Component_Declaration
(Loc
,
5179 Defining_Identifier
=>
5180 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5182 Component_Definition
=>
5183 Make_Component_Definition
(Loc
,
5184 Aliased_Present
=> False,
5185 Subtype_Indication
=>
5186 Make_Subtype_Indication
(Loc
,
5188 New_Occurrence_Of
(Efam_Type
, Loc
),
5191 Make_Index_Or_Discriminant_Constraint
(Loc
,
5192 Constraints
=> New_List
(
5194 (Etype
(Discrete_Subtype_Definition
5195 (Parent
(Efam
))), Loc
)))))));
5201 end Collect_Entry_Families
;
5203 -----------------------
5204 -- Concurrent_Object --
5205 -----------------------
5207 function Concurrent_Object
5208 (Spec_Id
: Entity_Id
;
5209 Conc_Typ
: Entity_Id
) return Entity_Id
5212 -- Parameter _O or _object
5214 if Is_Protected_Type
(Conc_Typ
) then
5215 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5220 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5221 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5223 end Concurrent_Object
;
5225 ----------------------
5226 -- Copy_Result_Type --
5227 ----------------------
5229 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5230 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5235 -- If the result type is an access_to_subprogram, we must create new
5236 -- entities for its spec.
5238 if Nkind
(New_Res
) = N_Access_Definition
5239 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5241 -- Provide new entities for the formals
5243 Par_Spec
:= First
(Parameter_Specifications
5244 (Access_To_Subprogram_Definition
(New_Res
)));
5245 while Present
(Par_Spec
) loop
5246 Formal
:= Defining_Identifier
(Par_Spec
);
5247 Set_Defining_Identifier
(Par_Spec
,
5248 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5254 end Copy_Result_Type
;
5256 --------------------
5257 -- Concurrent_Ref --
5258 --------------------
5260 -- The expression returned for a reference to a concurrent object has the
5263 -- taskV!(name)._Task_Id
5267 -- objectV!(name)._Object
5269 -- for a protected object. For the case of an access to a concurrent
5270 -- object, there is an extra explicit dereference:
5272 -- taskV!(name.all)._Task_Id
5273 -- objectV!(name.all)._Object
5275 -- here taskV and objectV are the types for the associated records, which
5276 -- contain the required _Task_Id and _Object fields for tasks and protected
5277 -- objects, respectively.
5279 -- For the case of a task type name, the expression is
5283 -- i.e. a call to the Self function which returns precisely this Task_Id
5285 -- For the case of a protected type name, the expression is
5289 -- which is a renaming of the _object field of the current object
5290 -- record, passed into protected operations as a parameter.
5292 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5293 Loc
: constant Source_Ptr
:= Sloc
(N
);
5294 Ntyp
: constant Entity_Id
:= Etype
(N
);
5298 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5299 -- Check whether the reference is to the immediately enclosing task
5300 -- type, or to an outer one (rare but legal).
5302 ---------------------
5303 -- Is_Current_Task --
5304 ---------------------
5306 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5310 Scop
:= Current_Scope
;
5311 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
5315 elsif Is_Task_Type
(Scop
) then
5318 -- If this is a procedure nested within the task type, we must
5319 -- assume that it can be called from an inner task, and therefore
5320 -- cannot treat it as a local reference.
5322 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5326 Scop
:= Scope
(Scop
);
5330 -- We know that we are within the task body, so should have found it
5333 raise Program_Error
;
5334 end Is_Current_Task
;
5336 -- Start of processing for Concurrent_Ref
5339 if Is_Access_Type
(Ntyp
) then
5340 Dtyp
:= Designated_Type
(Ntyp
);
5342 if Is_Protected_Type
(Dtyp
) then
5343 Sel
:= Name_uObject
;
5345 Sel
:= Name_uTask_Id
;
5349 Make_Selected_Component
(Loc
,
5351 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5352 Make_Explicit_Dereference
(Loc
, N
)),
5353 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5355 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5356 if Is_Task_Type
(Entity
(N
)) then
5358 if Is_Current_Task
(Entity
(N
)) then
5360 Make_Function_Call
(Loc
,
5361 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5366 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5367 T_Body
: constant Node_Id
:=
5368 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5372 Make_Object_Declaration
(Loc
,
5373 Defining_Identifier
=> T_Self
,
5374 Object_Definition
=>
5375 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5377 Make_Function_Call
(Loc
,
5378 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5379 Prepend
(Decl
, Declarations
(T_Body
));
5381 Set_Scope
(T_Self
, Entity
(N
));
5382 return New_Occurrence_Of
(T_Self
, Loc
);
5387 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5390 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5394 if Is_Protected_Type
(Ntyp
) then
5395 Sel
:= Name_uObject
;
5396 elsif Is_Task_Type
(Ntyp
) then
5397 Sel
:= Name_uTask_Id
;
5399 raise Program_Error
;
5403 Make_Selected_Component
(Loc
,
5405 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5407 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5411 ------------------------
5412 -- Convert_Concurrent --
5413 ------------------------
5415 function Convert_Concurrent
5417 Typ
: Entity_Id
) return Node_Id
5420 if not Is_Concurrent_Type
(Typ
) then
5424 Unchecked_Convert_To
5425 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5427 end Convert_Concurrent
;
5429 -------------------------------------
5430 -- Create_Secondary_Stack_For_Task --
5431 -------------------------------------
5433 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean is
5436 (Restriction_Active
(No_Implicit_Heap_Allocations
)
5437 or else Restriction_Active
(No_Implicit_Task_Allocations
))
5438 and then not Restriction_Active
(No_Secondary_Stack
)
5439 and then Has_Rep_Pragma
5440 (T
, Name_Secondary_Stack_Size
, Check_Parents
=> False);
5441 end Create_Secondary_Stack_For_Task
;
5443 -------------------------------------
5444 -- Debug_Private_Data_Declarations --
5445 -------------------------------------
5447 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5448 Debug_Nod
: Node_Id
;
5452 Decl
:= First
(Decls
);
5453 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5455 -- Declaration for concurrent entity _object and its access type,
5456 -- along with the entry index subtype:
5457 -- type prot_typVP is access prot_typV;
5458 -- _object : prot_typVP := prot_typV (_O);
5459 -- subtype Jnn is <Type of Index> range Low .. High;
5461 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5462 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5464 -- Declaration for the Protection object, discriminals, privals, and
5465 -- entry index constant:
5466 -- conc_typR : protection_typ renames _object._object;
5467 -- discr_nameD : discr_typ renames _object.discr_name;
5468 -- discr_nameD : discr_typ renames _task.discr_name;
5469 -- prival_name : comp_typ renames _object.comp_name;
5470 -- J : constant Jnn :=
5471 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5473 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5474 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5475 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5477 if Present
(Debug_Nod
) then
5478 Insert_After
(Decl
, Debug_Nod
);
5484 end Debug_Private_Data_Declarations
;
5486 ------------------------------
5487 -- Ensure_Statement_Present --
5488 ------------------------------
5490 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5494 if Opt
.Suppress_Control_Flow_Optimizations
5495 and then Is_Empty_List
(Statements
(Alt
))
5497 Stmt
:= Make_Null_Statement
(Loc
);
5499 -- Mark NULL statement as coming from source so that it is not
5500 -- eliminated by GIGI.
5502 -- Another covert channel. If this is a requirement, it must be
5503 -- documented in sinfo/einfo ???
5505 Set_Comes_From_Source
(Stmt
, True);
5507 Set_Statements
(Alt
, New_List
(Stmt
));
5509 end Ensure_Statement_Present
;
5511 ----------------------------
5512 -- Entry_Index_Expression --
5513 ----------------------------
5515 function Entry_Index_Expression
5519 Ttyp
: Entity_Id
) return Node_Id
5529 -- The queues of entries and entry families appear in textual order in
5530 -- the associated record. The entry index is computed as the sum of the
5531 -- number of queues for all entries that precede the designated one, to
5532 -- which is added the index expression, if this expression denotes a
5533 -- member of a family.
5535 -- The following is a place holder for the count of simple entries
5537 Num
:= Make_Integer_Literal
(Sloc
, 1);
5539 -- We construct an expression which is a series of addition operations.
5540 -- The first operand is the number of single entries that precede this
5541 -- one, the second operand is the index value relative to the start of
5542 -- the referenced family, and the remaining operands are the lengths of
5543 -- the entry families that precede this entry, i.e. the constructed
5546 -- number_simple_entries +
5547 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5548 -- family'length + ...
5550 -- where index-value is the given index value, and s is the index
5551 -- subtype (we have to use pos because the subtype might be an
5552 -- enumeration type preventing direct subtraction). Note that the task
5553 -- entry array is one-indexed.
5555 -- The upper bound of the entry family may be a discriminant, so we
5556 -- retrieve the lower bound explicitly to compute offset, rather than
5557 -- using the index subtype which may mention a discriminant.
5559 if Present
(Index
) then
5560 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5568 Make_Attribute_Reference
(Sloc
,
5569 Attribute_Name
=> Name_Pos
,
5570 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5571 Expressions
=> New_List
(Relocate_Node
(Index
))),
5579 -- Now add lengths of preceding entries and entry families
5581 Prev
:= First_Entity
(Ttyp
);
5582 while Chars
(Prev
) /= Chars
(Ent
)
5583 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5584 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5586 if Ekind
(Prev
) = E_Entry
then
5587 Set_Intval
(Num
, Intval
(Num
) + 1);
5589 elsif Ekind
(Prev
) = E_Entry_Family
then
5590 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5591 Lo
:= Type_Low_Bound
(S
);
5592 Hi
:= Type_High_Bound
(S
);
5597 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5599 -- Other components are anonymous types to be ignored
5609 end Entry_Index_Expression
;
5611 ---------------------------
5612 -- Establish_Task_Master --
5613 ---------------------------
5615 procedure Establish_Task_Master
(N
: Node_Id
) is
5619 if Restriction_Active
(No_Task_Hierarchy
) = False then
5620 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5622 -- The block may have no declarations (and nevertheless be a task
5623 -- master) if it contains a call that may return an object that
5626 if No
(Declarations
(N
)) then
5627 Set_Declarations
(N
, New_List
(Call
));
5629 Prepend_To
(Declarations
(N
), Call
);
5634 end Establish_Task_Master
;
5636 --------------------------------
5637 -- Expand_Accept_Declarations --
5638 --------------------------------
5640 -- Part of the expansion of an accept statement involves the creation of
5641 -- a declaration that can be referenced from the statement sequence of
5646 -- This declaration is inserted immediately before the accept statement
5647 -- and it is important that it be inserted before the statements of the
5648 -- statement sequence are analyzed. Thus it would be too late to create
5649 -- this declaration in the Expand_N_Accept_Statement routine, which is
5650 -- why there is a separate procedure to be called directly from Sem_Ch9.
5652 -- Ann is used to hold the address of the record containing the parameters
5653 -- (see Expand_N_Entry_Call for more details on how this record is built).
5654 -- References to the parameters do an unchecked conversion of this address
5655 -- to a pointer to the required record type, and then access the field that
5656 -- holds the value of the required parameter. The entity for the address
5657 -- variable is held as the top stack element (i.e. the last element) of the
5658 -- Accept_Address stack in the corresponding entry entity, and this element
5659 -- must be set in place before the statements are processed.
5661 -- The above description applies to the case of a stand alone accept
5662 -- statement, i.e. one not appearing as part of a select alternative.
5664 -- For the case of an accept that appears as part of a select alternative
5665 -- of a selective accept, we must still create the declaration right away,
5666 -- since Ann is needed immediately, but there is an important difference:
5668 -- The declaration is inserted before the selective accept, not before
5669 -- the accept statement (which is not part of a list anyway, and so would
5670 -- not accommodate inserted declarations)
5672 -- We only need one address variable for the entire selective accept. So
5673 -- the Ann declaration is created only for the first accept alternative,
5674 -- and subsequent accept alternatives reference the same Ann variable.
5676 -- We can distinguish the two cases by seeing whether the accept statement
5677 -- is part of a list. If not, then it must be in an accept alternative.
5679 -- To expand the requeue statement, a label is provided at the end of the
5680 -- accept statement or alternative of which it is a part, so that the
5681 -- statement can be skipped after the requeue is complete. This label is
5682 -- created here rather than during the expansion of the accept statement,
5683 -- because it will be needed by any requeue statements within the accept,
5684 -- which are expanded before the accept.
5686 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5687 Loc
: constant Source_Ptr
:= Sloc
(N
);
5688 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5689 Ann
: Entity_Id
:= Empty
;
5696 if Expander_Active
then
5698 -- If we have no handled statement sequence, we may need to build
5699 -- a dummy sequence consisting of a null statement. This can be
5700 -- skipped if the trivial accept optimization is permitted.
5702 if not Trivial_Accept_OK
5703 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5705 Set_Handled_Statement_Sequence
(N
,
5706 Make_Handled_Sequence_Of_Statements
(Loc
,
5707 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5710 -- Create and declare two labels to be placed at the end of the
5711 -- accept statement. The first label is used to allow requeues to
5712 -- skip the remainder of entry processing. The second label is used
5713 -- to skip the remainder of entry processing if the rendezvous
5714 -- completes in the middle of the accept body.
5716 if Present
(Handled_Statement_Sequence
(N
)) then
5721 Ent
:= Make_Temporary
(Loc
, 'L');
5722 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5724 Make_Implicit_Label_Declaration
(Loc
,
5725 Defining_Identifier
=> Ent
,
5726 Label_Construct
=> Lab
);
5727 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5729 Ent
:= Make_Temporary
(Loc
, 'L');
5730 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5732 Make_Implicit_Label_Declaration
(Loc
,
5733 Defining_Identifier
=> Ent
,
5734 Label_Construct
=> Lab
);
5735 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5743 -- Case of stand alone accept statement
5745 if Is_List_Member
(N
) then
5747 if Present
(Handled_Statement_Sequence
(N
)) then
5748 Ann
:= Make_Temporary
(Loc
, 'A');
5751 Make_Object_Declaration
(Loc
,
5752 Defining_Identifier
=> Ann
,
5753 Object_Definition
=>
5754 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5756 Insert_Before_And_Analyze
(N
, Adecl
);
5757 Insert_Before_And_Analyze
(N
, Ldecl
);
5758 Insert_Before_And_Analyze
(N
, Ldecl2
);
5761 -- Case of accept statement which is in an accept alternative
5765 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5766 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5770 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5771 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5773 -- ??? Consider a single label for select statements
5775 if Present
(Handled_Statement_Sequence
(N
)) then
5777 Statements
(Handled_Statement_Sequence
(N
)));
5781 Statements
(Handled_Statement_Sequence
(N
)));
5785 -- Find first accept alternative of the selective accept. A
5786 -- valid selective accept must have at least one accept in it.
5788 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5790 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5794 -- If this is the first accept statement, then we have to
5795 -- create the Ann variable, as for the stand alone case, except
5796 -- that it is inserted before the selective accept. Similarly,
5797 -- a label for requeue expansion must be declared.
5799 if N
= Accept_Statement
(Alt
) then
5800 Ann
:= Make_Temporary
(Loc
, 'A');
5802 Make_Object_Declaration
(Loc
,
5803 Defining_Identifier
=> Ann
,
5804 Object_Definition
=>
5805 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5807 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5809 -- If this is not the first accept statement, then find the Ann
5810 -- variable allocated by the first accept and use it.
5814 Node
(Last_Elmt
(Accept_Address
5815 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5820 -- Merge here with Ann either created or referenced, and Adecl
5821 -- pointing to the corresponding declaration. Remaining processing
5822 -- is the same for the two cases.
5824 if Present
(Ann
) then
5825 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5826 Set_Debug_Info_Needed
(Ann
);
5829 -- Create renaming declarations for the entry formals. Each reference
5830 -- to a formal becomes a dereference of a component of the parameter
5831 -- block, whose address is held in Ann. These declarations are
5832 -- eventually inserted into the accept block, and analyzed there so
5833 -- that they have the proper scope for gdb and do not conflict with
5834 -- other declarations.
5836 if Present
(Parameter_Specifications
(N
))
5837 and then Present
(Handled_Statement_Sequence
(N
))
5844 Renamed_Formal
: Node_Id
;
5848 Formal
:= First_Formal
(Ent
);
5850 while Present
(Formal
) loop
5851 Comp
:= Entry_Component
(Formal
);
5852 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5854 Set_Etype
(New_F
, Etype
(Formal
));
5855 Set_Scope
(New_F
, Ent
);
5857 -- Now we set debug info needed on New_F even though it does
5858 -- not come from source, so that the debugger will get the
5859 -- right information for these generated names.
5861 Set_Debug_Info_Needed
(New_F
);
5863 if Ekind
(Formal
) = E_In_Parameter
then
5864 Set_Ekind
(New_F
, E_Constant
);
5866 Set_Ekind
(New_F
, E_Variable
);
5867 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5870 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5873 Make_Selected_Component
(Loc
,
5875 Unchecked_Convert_To
(
5876 Entry_Parameters_Type
(Ent
),
5877 New_Occurrence_Of
(Ann
, Loc
)),
5879 New_Occurrence_Of
(Comp
, Loc
));
5882 Build_Renamed_Formal_Declaration
5883 (New_F
, Formal
, Comp
, Renamed_Formal
);
5885 if No
(Declarations
(N
)) then
5886 Set_Declarations
(N
, New_List
);
5889 Append
(Decl
, Declarations
(N
));
5890 Set_Renamed_Object
(Formal
, New_F
);
5891 Next_Formal
(Formal
);
5898 end Expand_Accept_Declarations
;
5900 ---------------------------------------------
5901 -- Expand_Access_Protected_Subprogram_Type --
5902 ---------------------------------------------
5904 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5905 Loc
: constant Source_Ptr
:= Sloc
(N
);
5906 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5907 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5908 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5909 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5910 P_List
: constant List_Id
:=
5911 Build_Protected_Spec
(N
, RTE
(RE_Address
), D_T
, False);
5919 -- Create access to subprogram with full signature
5921 if Etype
(D_T
) /= Standard_Void_Type
then
5923 Make_Access_Function_Definition
(Loc
,
5924 Parameter_Specifications
=> P_List
,
5925 Result_Definition
=>
5926 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5930 Make_Access_Procedure_Definition
(Loc
,
5931 Parameter_Specifications
=> P_List
);
5935 Make_Full_Type_Declaration
(Loc
,
5936 Defining_Identifier
=> D_T2
,
5937 Type_Definition
=> Def1
);
5939 -- Declare the new types before the original one since the latter will
5940 -- refer to them through the Equivalent_Type slot.
5942 Insert_Before_And_Analyze
(N
, Decl1
);
5944 -- Associate the access to subprogram with its original access to
5945 -- protected subprogram type. Needed by the backend to know that this
5946 -- type corresponds with an access to protected subprogram type.
5948 Set_Original_Access_Type
(D_T2
, T
);
5950 -- Create Equivalent_Type, a record with two components for an access to
5951 -- object and an access to subprogram.
5954 Make_Component_Declaration
(Loc
,
5955 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5956 Component_Definition
=>
5957 Make_Component_Definition
(Loc
,
5958 Aliased_Present
=> False,
5959 Subtype_Indication
=>
5960 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5962 Make_Component_Declaration
(Loc
,
5963 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5964 Component_Definition
=>
5965 Make_Component_Definition
(Loc
,
5966 Aliased_Present
=> False,
5967 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5970 Make_Full_Type_Declaration
(Loc
,
5971 Defining_Identifier
=> E_T
,
5973 Make_Record_Definition
(Loc
,
5975 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
5977 Insert_Before_And_Analyze
(N
, Decl2
);
5978 Set_Equivalent_Type
(T
, E_T
);
5979 end Expand_Access_Protected_Subprogram_Type
;
5981 --------------------------
5982 -- Expand_Entry_Barrier --
5983 --------------------------
5985 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5986 Cond
: constant Node_Id
:= Condition
(Entry_Body_Formal_Part
(N
));
5987 Prot
: constant Entity_Id
:= Scope
(Ent
);
5988 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5990 Func_Id
: Entity_Id
:= Empty
;
5991 -- The entity of the barrier function
5993 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
5994 -- Check whether entity in Barrier is external to protected type.
5995 -- If so, barrier may not be properly synchronized.
5997 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
;
5998 -- Check whether N follows the Pure_Barriers restriction. Return OK if
6001 function Is_Simple_Barrier_Name
(N
: Node_Id
) return Boolean;
6002 -- Check whether entity name N denotes a component of the protected
6003 -- object. This is used to check the Simple_Barrier restriction.
6005 ----------------------
6006 -- Is_Global_Entity --
6007 ----------------------
6009 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
6014 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
6018 if Ekind
(E
) = E_Variable
then
6020 -- If the variable is local to the barrier function generated
6021 -- during expansion, it is ok. If expansion is not performed,
6022 -- then Func is Empty so this test cannot succeed.
6024 if Scope
(E
) = Func_Id
then
6027 -- A protected call from a barrier to another object is ok
6029 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
6032 -- If the variable is within the package body we consider
6033 -- this safe. This is a common (if dubious) idiom.
6035 elsif S
= Scope
(Prot
)
6036 and then Ekind_In
(S
, E_Package
, E_Generic_Package
)
6037 and then Nkind
(Parent
(E
)) = N_Object_Declaration
6038 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
6043 Error_Msg_N
("potentially unsynchronized barrier??", N
);
6044 Error_Msg_N
("\& should be private component of type??", N
);
6050 end Is_Global_Entity
;
6052 procedure Check_Unprotected_Barrier
is
6053 new Traverse_Proc
(Is_Global_Entity
);
6055 ----------------------------
6056 -- Is_Simple_Barrier_Name --
6057 ----------------------------
6059 function Is_Simple_Barrier_Name
(N
: Node_Id
) return Boolean is
6063 -- Check if the name is a component of the protected object. If
6064 -- the expander is active, the component has been transformed into a
6065 -- renaming of _object.all.component. Original_Node is needed in case
6066 -- validity checking is enabled, in which case the simple object
6067 -- reference will have been rewritten.
6069 if Expander_Active
then
6071 -- The expanded name may have been constant folded in which case
6072 -- the original node is not necessarily an entity name (e.g. an
6073 -- indexed component).
6075 if not Is_Entity_Name
(Original_Node
(N
)) then
6079 Renamed
:= Renamed_Object
(Entity
(Original_Node
(N
)));
6083 and then Nkind
(Renamed
) = N_Selected_Component
6084 and then Chars
(Prefix
(Prefix
(Renamed
))) = Name_uObject
;
6086 return Is_Protected_Component
(Entity
(N
));
6088 end Is_Simple_Barrier_Name
;
6090 ---------------------
6091 -- Is_Pure_Barrier --
6092 ---------------------
6094 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
is
6097 when N_Expanded_Name
6100 if No
(Entity
(N
)) then
6103 elsif Is_Universal_Numeric_Type
(Entity
(N
)) then
6107 case Ekind
(Entity
(N
)) is
6110 | E_Enumeration_Literal
6120 if Is_Simple_Barrier_Name
(N
) then
6126 -- The count attribute has been transformed into run-time
6129 if Is_RTE
(Entity
(N
), RE_Protected_Count
)
6130 or else Is_RTE
(Entity
(N
), RE_Protected_Count_Entry
)
6139 when N_Function_Call
=>
6141 -- Function call checks are carried out as part of the analysis
6142 -- of the function call name.
6146 when N_Character_Literal
6155 if Ekind
(Entity
(N
)) = E_Operator
then
6159 when N_Short_Circuit
=>
6162 when N_Indexed_Component
6163 | N_Selected_Component
6165 if not Is_Access_Type
(Etype
(Prefix
(N
))) then
6169 when N_Type_Conversion
=>
6171 -- Conversions to Universal_Integer will not raise constraint
6174 if Cannot_Raise_Constraint_Error
(N
)
6175 or else Etype
(N
) = Universal_Integer
6180 when N_Unchecked_Type_Conversion
=>
6188 end Is_Pure_Barrier
;
6190 function Check_Pure_Barriers
is new Traverse_Func
(Is_Pure_Barrier
);
6194 Cond_Id
: Entity_Id
;
6195 Entry_Body
: Node_Id
;
6196 Func_Body
: Node_Id
:= Empty
;
6198 -- Start of processing for Expand_Entry_Barrier
6201 if No_Run_Time_Mode
then
6202 Error_Msg_CRT
("entry barrier", N
);
6206 -- The body of the entry barrier must be analyzed in the context of the
6207 -- protected object, but its scope is external to it, just as any other
6208 -- unprotected version of a protected operation. The specification has
6209 -- been produced when the protected type declaration was elaborated. We
6210 -- build the body, insert it in the enclosing scope, but analyze it in
6211 -- the current context. A more uniform approach would be to treat the
6212 -- barrier just as a protected function, and discard the protected
6213 -- version of it because it is never called.
6215 if Expander_Active
then
6216 Func_Body
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6217 Func_Id
:= Barrier_Function
(Ent
);
6218 Set_Corresponding_Spec
(Func_Body
, Func_Id
);
6220 Entry_Body
:= Parent
(Corresponding_Body
(Spec_Decl
));
6222 if Nkind
(Parent
(Entry_Body
)) = N_Subunit
then
6223 Entry_Body
:= Corresponding_Stub
(Parent
(Entry_Body
));
6226 Insert_Before_And_Analyze
(Entry_Body
, Func_Body
);
6228 Set_Discriminals
(Spec_Decl
);
6229 Set_Scope
(Func_Id
, Scope
(Prot
));
6232 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6235 -- Check Pure_Barriers restriction
6237 if Check_Pure_Barriers
(Cond
) = Abandon
then
6238 Check_Restriction
(Pure_Barriers
, Cond
);
6241 -- The Ravenscar profile restricts barriers to simple variables declared
6242 -- within the protected object. We also allow Boolean constants, since
6243 -- these appear in several published examples and are also allowed by
6246 -- Note that after analysis variables in this context will be replaced
6247 -- by the corresponding prival, that is to say a renaming of a selected
6248 -- component of the form _Object.Var. If expansion is disabled, as
6249 -- within a generic, we check that the entity appears in the current
6252 if Is_Entity_Name
(Cond
) then
6253 Cond_Id
:= Entity
(Cond
);
6255 -- Perform a small optimization of simple barrier functions. If the
6256 -- scope of the condition's entity is not the barrier function, then
6257 -- the condition does not depend on any of the generated renamings.
6258 -- If this is the case, eliminate the renamings as they are useless.
6259 -- This optimization is not performed when the condition was folded
6260 -- and validity checks are in effect because the original condition
6261 -- may have produced at least one check that depends on the generated
6265 and then Scope
(Cond_Id
) /= Func_Id
6266 and then not Validity_Check_Operands
6268 Set_Declarations
(Func_Body
, Empty_List
);
6271 if Cond_Id
= Standard_False
or else Cond_Id
= Standard_True
then
6274 elsif Is_Simple_Barrier_Name
(Cond
) then
6279 -- It is not a boolean variable or literal, so check the restriction.
6280 -- Note that it is safe to be calling Check_Restriction from here, even
6281 -- though this is part of the expander, since Expand_Entry_Barrier is
6282 -- called from Sem_Ch9 even in -gnatc mode.
6284 Check_Restriction
(Simple_Barriers
, Cond
);
6286 -- Emit warning if barrier contains global entities and is thus
6287 -- potentially unsynchronized.
6289 Check_Unprotected_Barrier
(Cond
);
6290 end Expand_Entry_Barrier
;
6292 ------------------------------
6293 -- Expand_N_Abort_Statement --
6294 ------------------------------
6296 -- Expand abort T1, T2, .. Tn; into:
6297 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6299 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6300 Loc
: constant Source_Ptr
:= Sloc
(N
);
6301 Tlist
: constant List_Id
:= Names
(N
);
6307 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6310 Tasknm
:= First
(Tlist
);
6312 while Present
(Tasknm
) loop
6315 -- A task interface class-wide type object is being aborted. Retrieve
6316 -- its _task_id by calling a dispatching routine.
6318 if Ada_Version
>= Ada_2005
6319 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6320 and then Is_Interface
(Etype
(Tasknm
))
6321 and then Is_Task_Interface
(Etype
(Tasknm
))
6323 Append_To
(Component_Associations
(Aggr
),
6324 Make_Component_Association
(Loc
,
6325 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6328 -- Task_Id (Tasknm._disp_get_task_id)
6330 Make_Unchecked_Type_Conversion
(Loc
,
6332 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
6334 Make_Selected_Component
(Loc
,
6335 Prefix
=> New_Copy_Tree
(Tasknm
),
6337 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6340 Append_To
(Component_Associations
(Aggr
),
6341 Make_Component_Association
(Loc
,
6342 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6343 Expression
=> Concurrent_Ref
(Tasknm
)));
6350 Make_Procedure_Call_Statement
(Loc
,
6351 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6352 Parameter_Associations
=> New_List
(
6353 Make_Qualified_Expression
(Loc
,
6354 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6355 Expression
=> Aggr
))));
6358 end Expand_N_Abort_Statement
;
6360 -------------------------------
6361 -- Expand_N_Accept_Statement --
6362 -------------------------------
6364 -- This procedure handles expansion of accept statements that stand alone,
6365 -- i.e. they are not part of an accept alternative. The expansion of
6366 -- accept statement in accept alternatives is handled by the routines
6367 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6368 -- following description applies only to stand alone accept statements.
6370 -- If there is no handled statement sequence, or only null statements, then
6371 -- this is called a trivial accept, and the expansion is:
6373 -- Accept_Trivial (entry-index)
6375 -- If there is a handled statement sequence, then the expansion is:
6382 -- Accept_Call (entry-index, Ann);
6383 -- Renaming_Declarations for formals
6384 -- <statement sequence from N_Accept_Statement node>
6385 -- Complete_Rendezvous;
6390 -- <exception handler from N_Accept_Statement node>
6391 -- Complete_Rendezvous;
6393 -- <exception handler from N_Accept_Statement node>
6394 -- Complete_Rendezvous;
6399 -- when all others =>
6400 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6403 -- The first three declarations were already inserted ahead of the accept
6404 -- statement by the Expand_Accept_Declarations procedure, which was called
6405 -- directly from the semantics during analysis of the accept statement,
6406 -- before analyzing its contained statements.
6408 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6409 -- from possible expansion activity (the original source of course does
6410 -- not have any declarations associated with the accept statement, since
6411 -- an accept statement has no declarative part). In particular, if the
6412 -- expander is active, the first such declaration is the declaration of
6413 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6415 -- The two blocks are merged into a single block if the inner block has
6416 -- no exception handlers, but otherwise two blocks are required, since
6417 -- exceptions might be raised in the exception handlers of the inner
6418 -- block, and Exceptional_Complete_Rendezvous must be called.
6420 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6421 Loc
: constant Source_Ptr
:= Sloc
(N
);
6422 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6423 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6424 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6425 Eent
: constant Entity_Id
:= Entity
(Ename
);
6426 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6427 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6428 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6434 -- If the accept statement is not part of a list, then its parent must
6435 -- be an accept alternative, and, as described above, we do not do any
6436 -- expansion for such accept statements at this level.
6438 if not Is_List_Member
(N
) then
6439 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6442 -- Trivial accept case (no statement sequence, or null statements).
6443 -- If the accept statement has declarations, then just insert them
6444 -- before the procedure call.
6446 elsif Trivial_Accept_OK
6447 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6449 -- Remove declarations for renamings, because the parameter block
6450 -- will not be assigned.
6457 D
:= First
(Declarations
(N
));
6458 while Present
(D
) loop
6460 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6468 if Present
(Declarations
(N
)) then
6469 Insert_Actions
(N
, Declarations
(N
));
6473 Make_Procedure_Call_Statement
(Loc
,
6474 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6475 Parameter_Associations
=> New_List
(
6476 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6480 -- Discard Entry_Address that was created for it, so it will not be
6481 -- emitted if this accept statement is in the statement part of a
6482 -- delay alternative.
6484 if Present
(Stats
) then
6485 Remove_Last_Elmt
(Acstack
);
6488 -- Case of statement sequence present
6491 -- Construct the block, using the declarations from the accept
6492 -- statement if any to initialize the declarations of the block.
6494 Blkent
:= Make_Temporary
(Loc
, 'A');
6495 Set_Ekind
(Blkent
, E_Block
);
6496 Set_Etype
(Blkent
, Standard_Void_Type
);
6497 Set_Scope
(Blkent
, Current_Scope
);
6500 Make_Block_Statement
(Loc
,
6501 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6502 Declarations
=> Declarations
(N
),
6503 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6505 -- For the analysis of the generated declarations, the parent node
6506 -- must be properly set.
6508 Set_Parent
(Block
, Parent
(N
));
6510 -- Prepend call to Accept_Call to main statement sequence If the
6511 -- accept has exception handlers, the statement sequence is wrapped
6512 -- in a block. Insert call and renaming declarations in the
6513 -- declarations of the block, so they are elaborated before the
6517 Make_Procedure_Call_Statement
(Loc
,
6518 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6519 Parameter_Associations
=> New_List
(
6520 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6521 New_Occurrence_Of
(Ann
, Loc
)));
6523 if Parent
(Stats
) = N
then
6524 Prepend
(Call
, Statements
(Stats
));
6526 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6531 Push_Scope
(Blkent
);
6539 D
:= First
(Declarations
(N
));
6540 while Present
(D
) loop
6543 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6545 -- The renaming declarations for the formals were created
6546 -- during analysis of the accept statement, and attached to
6547 -- the list of declarations. Place them now in the context
6548 -- of the accept block or subprogram.
6551 Typ
:= Entity
(Subtype_Mark
(D
));
6552 Insert_After
(Call
, D
);
6555 -- If the formal is class_wide, it does not have an actual
6556 -- subtype. The analysis of the renaming declaration creates
6557 -- one, but we need to retain the class-wide nature of the
6560 if Is_Class_Wide_Type
(Typ
) then
6561 Set_Etype
(Defining_Identifier
(D
), Typ
);
6572 -- Replace the accept statement by the new block
6577 -- Last step is to unstack the Accept_Address value
6579 Remove_Last_Elmt
(Acstack
);
6581 end Expand_N_Accept_Statement
;
6583 ----------------------------------
6584 -- Expand_N_Asynchronous_Select --
6585 ----------------------------------
6587 -- This procedure assumes that the trigger statement is an entry call or
6588 -- a dispatching procedure call. A delay alternative should already have
6589 -- been expanded into an entry call to the appropriate delay object Wait
6592 -- If the trigger is a task entry call, the select is implemented with
6593 -- a Task_Entry_Call:
6598 -- P : parms := (parm, parm, parm);
6600 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6602 -- procedure _clean is
6605 -- Cancel_Task_Entry_Call (C);
6612 -- (<acceptor-task>, -- Acceptor
6613 -- <entry-index>, -- E
6614 -- P'Address, -- Uninterpreted_Data
6615 -- Asynchronous_Call, -- Mode
6616 -- B); -- Rendezvous_Successful
6623 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6626 -- when Abort_Signal => Abort_Undefer;
6633 -- <triggered-statements>
6637 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6638 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6642 -- P : parms := (parm, parm, parm);
6644 -- Call_Simple (acceptor-task, entry-index, P'Address);
6650 -- so the task at hand is to convert the latter expansion into the former
6652 -- If the trigger is a protected entry call, the select is implemented
6653 -- with Protected_Entry_Call:
6656 -- P : E1_Params := (param, param, param);
6657 -- Bnn : Communications_Block;
6662 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6664 -- procedure _clean is
6667 -- if Enqueued (Bnn) then
6668 -- Cancel_Protected_Entry_Call (Bnn);
6675 -- Protected_Entry_Call
6676 -- (po._object'Access, -- Object
6677 -- <entry index>, -- E
6678 -- P'Address, -- Uninterpreted_Data
6679 -- Asynchronous_Call, -- Mode
6682 -- if Enqueued (Bnn) then
6686 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6689 -- when Abort_Signal => Abort_Undefer;
6692 -- if not Cancelled (Bnn) then
6693 -- <triggered-statements>
6697 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6701 -- P : E1_Params := (param, param, param);
6702 -- Bnn : Communications_Block;
6705 -- Protected_Entry_Call
6706 -- (po._object'Access, -- Object
6707 -- <entry index>, -- E
6708 -- P'Address, -- Uninterpreted_Data
6709 -- Simple_Call, -- Mode
6716 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6720 -- B : Boolean := False;
6721 -- Bnn : Communication_Block;
6722 -- C : Ada.Tags.Prim_Op_Kind;
6723 -- D : System.Storage_Elements.Dummy_Communication_Block;
6724 -- K : Ada.Tags.Tagged_Kind :=
6725 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6726 -- P : Parameters := (Param1 .. ParamN);
6731 -- if K = Ada.Tags.TK_Limited_Tagged
6732 -- or else K = Ada.Tags.TK_Tagged
6734 -- <dispatching-call>;
6735 -- <triggering-statements>;
6739 -- Ada.Tags.Get_Offset_Index
6740 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6742 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6744 -- if C = POK_Protected_Entry then
6746 -- procedure _clean is
6748 -- if Enqueued (Bnn) then
6749 -- Cancel_Protected_Entry_Call (Bnn);
6755 -- _Disp_Asynchronous_Select
6756 -- (<object>, S, P'Address, D, B);
6757 -- Bnn := Communication_Block (D);
6759 -- Param1 := P.Param1;
6761 -- ParamN := P.ParamN;
6763 -- if Enqueued (Bnn) then
6764 -- <abortable-statements>
6767 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6770 -- when Abort_Signal => Abort_Undefer;
6773 -- if not Cancelled (Bnn) then
6774 -- <triggering-statements>
6777 -- elsif C = POK_Task_Entry then
6779 -- procedure _clean is
6781 -- Cancel_Task_Entry_Call (U);
6787 -- _Disp_Asynchronous_Select
6788 -- (<object>, S, P'Address, D, B);
6789 -- Bnn := Communication_Bloc (D);
6791 -- Param1 := P.Param1;
6793 -- ParamN := P.ParamN;
6798 -- <abortable-statements>
6800 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6803 -- when Abort_Signal => Abort_Undefer;
6807 -- <triggering-statements>
6812 -- <dispatching-call>;
6813 -- <triggering-statements>
6818 -- The job is to convert this to the asynchronous form
6820 -- If the trigger is a delay statement, it will have been expanded into
6821 -- a call to one of the GNARL delay procedures. This routine will convert
6822 -- this into a protected entry call on a delay object and then continue
6823 -- processing as for a protected entry call trigger. This requires
6824 -- declaring a Delay_Block object and adding a pointer to this object to
6825 -- the parameter list of the delay procedure to form the parameter list of
6826 -- the entry call. This object is used by the runtime to queue the delay
6829 -- For a description of the use of P and the assignments after the call,
6830 -- see Expand_N_Entry_Call_Statement.
6832 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6833 Loc
: constant Source_Ptr
:= Sloc
(N
);
6834 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6835 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6837 Abort_Block_Ent
: Entity_Id
;
6838 Abortable_Block
: Node_Id
;
6841 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6842 Blk_Typ
: Entity_Id
;
6844 Call_Ent
: Entity_Id
;
6845 Cancel_Param
: Entity_Id
;
6846 Cleanup_Block
: Node_Id
;
6847 Cleanup_Block_Ent
: Entity_Id
;
6848 Cleanup_Stmts
: List_Id
;
6849 Conc_Typ_Stmts
: List_Id
;
6851 Dblock_Ent
: Entity_Id
;
6856 Enqueue_Call
: Node_Id
;
6859 Handler_Stmt
: Node_Id
;
6861 Lim_Typ_Stmts
: List_Id
;
6867 ProtE_Stmts
: List_Id
;
6868 ProtP_Stmts
: List_Id
;
6871 TaskE_Stmts
: List_Id
;
6874 B
: Entity_Id
; -- Call status flag
6875 Bnn
: Entity_Id
; -- Communication block
6876 C
: Entity_Id
; -- Call kind
6877 K
: Entity_Id
; -- Tagged kind
6878 P
: Entity_Id
; -- Parameter block
6879 S
: Entity_Id
; -- Primitive operation slot
6880 T
: Entity_Id
; -- Additional status flag
6882 procedure Rewrite_Abortable_Part
;
6883 -- If the trigger is a dispatching call, the expansion inserts multiple
6884 -- copies of the abortable part. This is both inefficient, and may lead
6885 -- to duplicate definitions that the back-end will reject, when the
6886 -- abortable part includes loops. This procedure rewrites the abortable
6887 -- part into a call to a generated procedure.
6889 ----------------------------
6890 -- Rewrite_Abortable_Part --
6891 ----------------------------
6893 procedure Rewrite_Abortable_Part
is
6894 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6899 Make_Subprogram_Body
(Loc
,
6901 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6902 Declarations
=> New_List
,
6903 Handled_Statement_Sequence
=>
6904 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6905 Insert_Before
(N
, Decl
);
6908 -- Rewrite abortable part into a call to this procedure
6912 Make_Procedure_Call_Statement
(Loc
,
6913 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6914 end Rewrite_Abortable_Part
;
6916 -- Start of processing for Expand_N_Asynchronous_Select
6919 -- Asynchronous select is not supported on restricted runtimes. Don't
6922 if Restricted_Profile
then
6926 Process_Statements_For_Controlled_Objects
(Trig
);
6927 Process_Statements_For_Controlled_Objects
(Abrt
);
6929 Ecall
:= Triggering_Statement
(Trig
);
6931 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6933 -- Retrieve Astats and Tstats now because the finalization machinery may
6934 -- wrap them in blocks.
6936 Astats
:= Statements
(Abrt
);
6937 Tstats
:= Statements
(Trig
);
6939 -- The arguments in the call may require dynamic allocation, and the
6940 -- call statement may have been transformed into a block. The block
6941 -- may contain additional declarations for internal entities, and the
6942 -- original call is found by sequential search.
6944 if Nkind
(Ecall
) = N_Block_Statement
then
6945 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6946 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6947 N_Entry_Call_Statement
)
6953 -- This is either a dispatching call or a delay statement used as a
6954 -- trigger which was expanded into a procedure call.
6956 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6957 if Ada_Version
>= Ada_2005
6959 (No
(Original_Node
(Ecall
))
6960 or else not Nkind_In
(Original_Node
(Ecall
),
6961 N_Delay_Relative_Statement
,
6962 N_Delay_Until_Statement
))
6964 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6966 Rewrite_Abortable_Part
;
6970 -- Call status flag processing, generate:
6971 -- B : Boolean := False;
6973 B
:= Build_B
(Loc
, Decls
);
6975 -- Communication block processing, generate:
6976 -- Bnn : Communication_Block;
6978 Bnn
:= Make_Temporary
(Loc
, 'B');
6980 Make_Object_Declaration
(Loc
,
6981 Defining_Identifier
=> Bnn
,
6982 Object_Definition
=>
6983 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
6985 -- Call kind processing, generate:
6986 -- C : Ada.Tags.Prim_Op_Kind;
6988 C
:= Build_C
(Loc
, Decls
);
6990 -- Tagged kind processing, generate:
6991 -- K : Ada.Tags.Tagged_Kind :=
6992 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6994 -- Dummy communication block, generate:
6995 -- D : Dummy_Communication_Block;
6998 Make_Object_Declaration
(Loc
,
6999 Defining_Identifier
=>
7000 Make_Defining_Identifier
(Loc
, Name_uD
),
7001 Object_Definition
=>
7003 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
7005 K
:= Build_K
(Loc
, Decls
, Obj
);
7007 -- Parameter block processing
7009 Blk_Typ
:= Build_Parameter_Block
7010 (Loc
, Actuals
, Formals
, Decls
);
7011 P
:= Parameter_Block_Pack
7012 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7014 -- Dispatch table slot processing, generate:
7017 S
:= Build_S
(Loc
, Decls
);
7019 -- Additional status flag processing, generate:
7022 T
:= Make_Temporary
(Loc
, 'T');
7024 Make_Object_Declaration
(Loc
,
7025 Defining_Identifier
=> T
,
7026 Object_Definition
=>
7027 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7029 ------------------------------
7030 -- Protected entry handling --
7031 ------------------------------
7034 -- Param1 := P.Param1;
7036 -- ParamN := P.ParamN;
7038 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7041 -- Bnn := Communication_Block (D);
7043 Prepend_To
(Cleanup_Stmts
,
7044 Make_Assignment_Statement
(Loc
,
7045 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
7047 Make_Unchecked_Type_Conversion
(Loc
,
7049 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7050 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7053 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7055 Prepend_To
(Cleanup_Stmts
,
7056 Make_Procedure_Call_Statement
(Loc
,
7060 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
7062 Parameter_Associations
=>
7064 New_Copy_Tree
(Obj
), -- <object>
7065 New_Occurrence_Of
(S
, Loc
), -- S
7066 Make_Attribute_Reference
(Loc
, -- P'Address
7067 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7068 Attribute_Name
=> Name_Address
),
7069 Make_Identifier
(Loc
, Name_uD
), -- D
7070 New_Occurrence_Of
(B
, Loc
)))); -- B
7073 -- if Enqueued (Bnn) then
7074 -- <abortable-statements>
7077 Append_To
(Cleanup_Stmts
,
7078 Make_Implicit_If_Statement
(N
,
7080 Make_Function_Call
(Loc
,
7082 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7083 Parameter_Associations
=>
7084 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
7087 New_Copy_List_Tree
(Astats
)));
7089 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7090 -- will then generate a _clean for the communication block Bnn.
7094 -- procedure _clean is
7096 -- if Enqueued (Bnn) then
7097 -- Cancel_Protected_Entry_Call (Bnn);
7106 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7108 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7110 -- Wrap the cleanup block in an exception handling block
7116 -- when Abort_Signal => Abort_Undefer;
7119 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7122 Make_Implicit_Label_Declaration
(Loc
,
7123 Defining_Identifier
=> Abort_Block_Ent
),
7126 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7129 -- if not Cancelled (Bnn) then
7130 -- <triggering-statements>
7133 Append_To
(ProtE_Stmts
,
7134 Make_Implicit_If_Statement
(N
,
7138 Make_Function_Call
(Loc
,
7140 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7141 Parameter_Associations
=>
7142 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7145 New_Copy_List_Tree
(Tstats
)));
7147 -------------------------
7148 -- Task entry handling --
7149 -------------------------
7152 -- Param1 := P.Param1;
7154 -- ParamN := P.ParamN;
7156 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7159 -- Bnn := Communication_Block (D);
7161 Append_To
(TaskE_Stmts
,
7162 Make_Assignment_Statement
(Loc
,
7164 New_Occurrence_Of
(Bnn
, Loc
),
7166 Make_Unchecked_Type_Conversion
(Loc
,
7168 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7169 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7172 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7174 Prepend_To
(TaskE_Stmts
,
7175 Make_Procedure_Call_Statement
(Loc
,
7178 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7179 Name_uDisp_Asynchronous_Select
),
7182 Parameter_Associations
=> New_List
(
7183 New_Copy_Tree
(Obj
), -- <object>
7184 New_Occurrence_Of
(S
, Loc
), -- S
7185 Make_Attribute_Reference
(Loc
, -- P'Address
7186 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7187 Attribute_Name
=> Name_Address
),
7188 Make_Identifier
(Loc
, Name_uD
), -- D
7189 New_Occurrence_Of
(B
, Loc
)))); -- B
7194 Prepend_To
(TaskE_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7198 -- <abortable-statements>
7200 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7203 (Cleanup_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7205 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7206 -- will generate a _clean for the additional status flag.
7210 -- procedure _clean is
7212 -- Cancel_Task_Entry_Call (U);
7220 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7222 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7224 -- Wrap the cleanup block in an exception handling block
7230 -- when Abort_Signal => Abort_Undefer;
7233 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7235 Append_To
(TaskE_Stmts
,
7236 Make_Implicit_Label_Declaration
(Loc
,
7237 Defining_Identifier
=> Abort_Block_Ent
));
7239 Append_To
(TaskE_Stmts
,
7241 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7245 -- <triggering-statements>
7248 Append_To
(TaskE_Stmts
,
7249 Make_Implicit_If_Statement
(N
,
7251 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7254 New_Copy_List_Tree
(Tstats
)));
7256 ----------------------------------
7257 -- Protected procedure handling --
7258 ----------------------------------
7261 -- <dispatching-call>;
7262 -- <triggering-statements>
7264 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7265 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7268 -- S := Ada.Tags.Get_Offset_Index
7269 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7272 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7275 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7277 Append_To
(Conc_Typ_Stmts
,
7278 Make_Procedure_Call_Statement
(Loc
,
7281 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7282 Name_uDisp_Get_Prim_Op_Kind
),
7284 Parameter_Associations
=>
7286 New_Copy_Tree
(Obj
),
7287 New_Occurrence_Of
(S
, Loc
),
7288 New_Occurrence_Of
(C
, Loc
))));
7291 -- if C = POK_Procedure_Entry then
7293 -- elsif C = POK_Task_Entry then
7299 Append_To
(Conc_Typ_Stmts
,
7300 Make_Implicit_If_Statement
(N
,
7304 New_Occurrence_Of
(C
, Loc
),
7306 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7313 Make_Elsif_Part
(Loc
,
7317 New_Occurrence_Of
(C
, Loc
),
7319 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7328 -- <dispatching-call>;
7329 -- <triggering-statements>
7331 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7332 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7335 -- if K = Ada.Tags.TK_Limited_Tagged
7336 -- or else K = Ada.Tags.TK_Tagged
7344 Make_Implicit_If_Statement
(N
,
7345 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7346 Then_Statements
=> Lim_Typ_Stmts
,
7347 Else_Statements
=> Conc_Typ_Stmts
));
7350 Make_Block_Statement
(Loc
,
7353 Handled_Statement_Sequence
=>
7354 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7359 -- Delay triggering statement processing
7362 -- Add a Delay_Block object to the parameter list of the delay
7363 -- procedure to form the parameter list of the Wait entry call.
7365 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7367 Pdef
:= Entity
(Name
(Ecall
));
7369 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7371 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7373 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7375 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7377 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7378 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7381 Append_To
(Parameter_Associations
(Ecall
),
7382 Make_Attribute_Reference
(Loc
,
7383 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7384 Attribute_Name
=> Name_Unchecked_Access
));
7386 -- Create the inner block to protect the abortable part
7388 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7390 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7393 Make_Block_Statement
(Loc
,
7394 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7395 Handled_Statement_Sequence
=>
7396 Make_Handled_Sequence_Of_Statements
(Loc
,
7397 Statements
=> Astats
),
7398 Has_Created_Identifier
=> True,
7399 Is_Asynchronous_Call_Block
=> True);
7401 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7404 Make_Implicit_If_Statement
(N
,
7406 Make_Function_Call
(Loc
,
7407 Name
=> Enqueue_Call
,
7408 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7410 New_List
(Make_Block_Statement
(Loc
,
7411 Handled_Statement_Sequence
=>
7412 Make_Handled_Sequence_Of_Statements
(Loc
,
7413 Statements
=> New_List
(
7414 Make_Implicit_Label_Declaration
(Loc
,
7415 Defining_Identifier
=> Blk_Ent
,
7416 Label_Construct
=> Abortable_Block
),
7418 Exception_Handlers
=> Hdle
)))));
7420 Stmts
:= New_List
(Ecall
);
7422 -- Construct statement sequence for new block
7425 Make_Implicit_If_Statement
(N
,
7427 Make_Function_Call
(Loc
,
7428 Name
=> New_Occurrence_Of
(
7429 RTE
(RE_Timed_Out
), Loc
),
7430 Parameter_Associations
=> New_List
(
7431 Make_Attribute_Reference
(Loc
,
7432 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7433 Attribute_Name
=> Name_Unchecked_Access
))),
7434 Then_Statements
=> Tstats
));
7436 -- The result is the new block
7438 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7441 Make_Block_Statement
(Loc
,
7442 Declarations
=> New_List
(
7443 Make_Object_Declaration
(Loc
,
7444 Defining_Identifier
=> Dblock_Ent
,
7445 Aliased_Present
=> True,
7446 Object_Definition
=>
7447 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7449 Handled_Statement_Sequence
=>
7450 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7460 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7461 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7463 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7464 Decls
:= Declarations
(Ecall
);
7466 if Is_Protected_Type
(Etype
(Concval
)) then
7468 -- Get the declarations of the block expanded from the entry call
7470 Decl
:= First
(Decls
);
7471 while Present
(Decl
)
7472 and then (Nkind
(Decl
) /= N_Object_Declaration
7473 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7474 RE_Communication_Block
))
7479 pragma Assert
(Present
(Decl
));
7480 Cancel_Param
:= Defining_Identifier
(Decl
);
7482 -- Change the mode of the Protected_Entry_Call call
7484 -- Protected_Entry_Call (
7485 -- Object => po._object'Access,
7486 -- E => <entry index>;
7487 -- Uninterpreted_Data => P'Address;
7488 -- Mode => Asynchronous_Call;
7491 -- Skip assignments to temporaries created for in-out parameters
7493 -- This makes unwarranted assumptions about the shape of the expanded
7494 -- tree for the call, and should be cleaned up ???
7496 Stmt
:= First
(Stmts
);
7497 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7503 Param
:= First
(Parameter_Associations
(Call
));
7504 while Present
(Param
)
7505 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7510 pragma Assert
(Present
(Param
));
7511 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7514 -- Append an if statement to execute the abortable part
7517 -- if Enqueued (Bnn) then
7520 Make_Implicit_If_Statement
(N
,
7522 Make_Function_Call
(Loc
,
7523 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7524 Parameter_Associations
=> New_List
(
7525 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7526 Then_Statements
=> Astats
));
7529 Make_Block_Statement
(Loc
,
7530 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7531 Handled_Statement_Sequence
=>
7532 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7533 Has_Created_Identifier
=> True,
7534 Is_Asynchronous_Call_Block
=> True);
7536 -- Aborts are not deferred at beginning of exception handlers in
7539 if ZCX_Exceptions
then
7540 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7543 Handler_Stmt
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
7547 Make_Block_Statement
(Loc
,
7548 Handled_Statement_Sequence
=>
7549 Make_Handled_Sequence_Of_Statements
(Loc
,
7550 Statements
=> New_List
(
7551 Make_Implicit_Label_Declaration
(Loc
,
7552 Defining_Identifier
=> Blk_Ent
,
7553 Label_Construct
=> Abortable_Block
),
7558 Exception_Handlers
=> New_List
(
7559 Make_Implicit_Exception_Handler
(Loc
,
7561 -- when Abort_Signal =>
7562 -- Abort_Undefer.all;
7564 Exception_Choices
=>
7565 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7566 Statements
=> New_List
(Handler_Stmt
))))),
7568 -- if not Cancelled (Bnn) then
7569 -- triggered statements
7572 Make_Implicit_If_Statement
(N
,
7573 Condition
=> Make_Op_Not
(Loc
,
7575 Make_Function_Call
(Loc
,
7576 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7577 Parameter_Associations
=> New_List
(
7578 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7579 Then_Statements
=> Tstats
));
7581 -- Asynchronous task entry call
7588 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7590 -- Insert declaration of B in declarations of existing block
7593 Make_Object_Declaration
(Loc
,
7594 Defining_Identifier
=> B
,
7595 Object_Definition
=>
7596 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7598 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7600 -- Insert the declaration of C in the declarations of the existing
7601 -- block. The variable is initialized to something (True or False,
7602 -- does not matter) to prevent CodePeer from complaining about a
7603 -- possible read of an uninitialized variable.
7606 Make_Object_Declaration
(Loc
,
7607 Defining_Identifier
=> Cancel_Param
,
7608 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
7609 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
),
7610 Has_Init_Expression
=> True));
7612 -- Remove and save the call to Call_Simple
7614 Stmt
:= First
(Stmts
);
7616 -- Skip assignments to temporaries created for in-out parameters.
7617 -- This makes unwarranted assumptions about the shape of the expanded
7618 -- tree for the call, and should be cleaned up ???
7620 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7626 -- Create the inner block to protect the abortable part
7628 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7630 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7633 Make_Block_Statement
(Loc
,
7634 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7635 Handled_Statement_Sequence
=>
7636 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7637 Has_Created_Identifier
=> True,
7638 Is_Asynchronous_Call_Block
=> True);
7641 Make_Block_Statement
(Loc
,
7642 Handled_Statement_Sequence
=>
7643 Make_Handled_Sequence_Of_Statements
(Loc
,
7644 Statements
=> New_List
(
7645 Make_Implicit_Label_Declaration
(Loc
,
7646 Defining_Identifier
=> Blk_Ent
,
7647 Label_Construct
=> Abortable_Block
),
7649 Exception_Handlers
=> Hdle
)));
7651 -- Create new call statement
7653 Params
:= Parameter_Associations
(Call
);
7656 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7657 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7660 Make_Procedure_Call_Statement
(Loc
,
7661 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7662 Parameter_Associations
=> Params
));
7664 -- Construct statement sequence for new block
7667 Make_Implicit_If_Statement
(N
,
7669 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7670 Then_Statements
=> Tstats
));
7672 -- Protected the call against abort
7674 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7677 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7679 -- The result is the new block
7682 Make_Block_Statement
(Loc
,
7683 Declarations
=> Decls
,
7684 Handled_Statement_Sequence
=>
7685 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7688 end Expand_N_Asynchronous_Select
;
7690 -------------------------------------
7691 -- Expand_N_Conditional_Entry_Call --
7692 -------------------------------------
7694 -- The conditional task entry call is converted to a call to
7699 -- P : parms := (parm, parm, parm);
7703 -- (<acceptor-task>, -- Acceptor
7704 -- <entry-index>, -- E
7705 -- P'Address, -- Uninterpreted_Data
7706 -- Conditional_Call, -- Mode
7707 -- B); -- Rendezvous_Successful
7712 -- normal-statements
7718 -- For a description of the use of P and the assignments after the call,
7719 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7720 -- conditional entry call has already been expanded (by the Expand_N_Entry
7721 -- _Call_Statement procedure) as follows:
7724 -- P : parms := (parm, parm, parm);
7726 -- ... info for in-out parameters
7727 -- Call_Simple (acceptor-task, entry-index, P'Address);
7733 -- so the task at hand is to convert the latter expansion into the former
7735 -- The conditional protected entry call is converted to a call to
7736 -- Protected_Entry_Call:
7739 -- P : parms := (parm, parm, parm);
7740 -- Bnn : Communications_Block;
7743 -- Protected_Entry_Call
7744 -- (po._object'Access, -- Object
7745 -- <entry index>, -- E
7746 -- P'Address, -- Uninterpreted_Data
7747 -- Conditional_Call, -- Mode
7752 -- if Cancelled (Bnn) then
7755 -- normal-statements
7759 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7763 -- B : Boolean := False;
7764 -- C : Ada.Tags.Prim_Op_Kind;
7765 -- K : Ada.Tags.Tagged_Kind :=
7766 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7767 -- P : Parameters := (Param1 .. ParamN);
7771 -- if K = Ada.Tags.TK_Limited_Tagged
7772 -- or else K = Ada.Tags.TK_Tagged
7774 -- <dispatching-call>;
7775 -- <triggering-statements>
7779 -- Ada.Tags.Get_Offset_Index
7780 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7782 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7784 -- if C = POK_Protected_Entry
7785 -- or else C = POK_Task_Entry
7787 -- Param1 := P.Param1;
7789 -- ParamN := P.ParamN;
7793 -- if C = POK_Procedure
7794 -- or else C = POK_Protected_Procedure
7795 -- or else C = POK_Task_Procedure
7797 -- <dispatching-call>;
7800 -- <triggering-statements>
7802 -- <else-statements>
7807 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7808 Loc
: constant Source_Ptr
:= Sloc
(N
);
7809 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7810 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7813 Blk_Typ
: Entity_Id
;
7815 Call_Ent
: Entity_Id
;
7816 Conc_Typ_Stmts
: List_Id
;
7820 Lim_Typ_Stmts
: List_Id
;
7827 Transient_Blk
: Node_Id
;
7830 B
: Entity_Id
; -- Call status flag
7831 C
: Entity_Id
; -- Call kind
7832 K
: Entity_Id
; -- Tagged kind
7833 P
: Entity_Id
; -- Parameter block
7834 S
: Entity_Id
; -- Primitive operation slot
7837 Process_Statements_For_Controlled_Objects
(N
);
7839 if Ada_Version
>= Ada_2005
7840 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7842 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7847 -- Call status flag processing, generate:
7848 -- B : Boolean := False;
7850 B
:= Build_B
(Loc
, Decls
);
7852 -- Call kind processing, generate:
7853 -- C : Ada.Tags.Prim_Op_Kind;
7855 C
:= Build_C
(Loc
, Decls
);
7857 -- Tagged kind processing, generate:
7858 -- K : Ada.Tags.Tagged_Kind :=
7859 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7861 K
:= Build_K
(Loc
, Decls
, Obj
);
7863 -- Parameter block processing
7865 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7866 P
:= Parameter_Block_Pack
7867 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7869 -- Dispatch table slot processing, generate:
7872 S
:= Build_S
(Loc
, Decls
);
7875 -- S := Ada.Tags.Get_Offset_Index
7876 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7879 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7882 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7884 Append_To
(Conc_Typ_Stmts
,
7885 Make_Procedure_Call_Statement
(Loc
,
7888 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7889 Name_uDisp_Conditional_Select
),
7891 Parameter_Associations
=>
7893 New_Copy_Tree
(Obj
), -- <object>
7894 New_Occurrence_Of
(S
, Loc
), -- S
7895 Make_Attribute_Reference
(Loc
, -- P'Address
7896 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7897 Attribute_Name
=> Name_Address
),
7898 New_Occurrence_Of
(C
, Loc
), -- C
7899 New_Occurrence_Of
(B
, Loc
)))); -- B
7902 -- if C = POK_Protected_Entry
7903 -- or else C = POK_Task_Entry
7905 -- Param1 := P.Param1;
7907 -- ParamN := P.ParamN;
7910 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7912 -- Generate the if statement only when the packed parameters need
7913 -- explicit assignments to their corresponding actuals.
7915 if Present
(Unpack
) then
7916 Append_To
(Conc_Typ_Stmts
,
7917 Make_Implicit_If_Statement
(N
,
7923 New_Occurrence_Of
(C
, Loc
),
7925 New_Occurrence_Of
(RTE
(
7926 RE_POK_Protected_Entry
), Loc
)),
7931 New_Occurrence_Of
(C
, Loc
),
7933 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
7935 Then_Statements
=> Unpack
));
7940 -- if C = POK_Procedure
7941 -- or else C = POK_Protected_Procedure
7942 -- or else C = POK_Task_Procedure
7944 -- <dispatching-call>
7946 -- <normal-statements>
7948 -- <else-statements>
7951 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7953 Prepend_To
(N_Stats
,
7954 Make_Implicit_If_Statement
(N
,
7960 New_Occurrence_Of
(C
, Loc
),
7962 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
7969 New_Occurrence_Of
(C
, Loc
),
7971 New_Occurrence_Of
(RTE
(
7972 RE_POK_Protected_Procedure
), Loc
)),
7977 New_Occurrence_Of
(C
, Loc
),
7979 New_Occurrence_Of
(RTE
(
7980 RE_POK_Task_Procedure
), Loc
)))),
7985 Append_To
(Conc_Typ_Stmts
,
7986 Make_Implicit_If_Statement
(N
,
7987 Condition
=> New_Occurrence_Of
(B
, Loc
),
7988 Then_Statements
=> N_Stats
,
7989 Else_Statements
=> Else_Statements
(N
)));
7992 -- <dispatching-call>;
7993 -- <triggering-statements>
7995 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
7996 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
7999 -- if K = Ada.Tags.TK_Limited_Tagged
8000 -- or else K = Ada.Tags.TK_Tagged
8008 Make_Implicit_If_Statement
(N
,
8009 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
8010 Then_Statements
=> Lim_Typ_Stmts
,
8011 Else_Statements
=> Conc_Typ_Stmts
));
8014 Make_Block_Statement
(Loc
,
8017 Handled_Statement_Sequence
=>
8018 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8020 -- As described above, the entry alternative is transformed into a
8021 -- block that contains the gnulli call, and possibly assignment
8022 -- statements for in-out parameters. The gnulli call may itself be
8023 -- rewritten into a transient block if some unconstrained parameters
8024 -- require it. We need to retrieve the call to complete its parameter
8029 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
8031 if Present
(Transient_Blk
)
8032 and then Nkind
(Transient_Blk
) = N_Block_Statement
8034 Blk
:= Transient_Blk
;
8037 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
8038 Stmt
:= First
(Stmts
);
8039 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
8044 Params
:= Parameter_Associations
(Call
);
8046 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
8048 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8050 Param
:= First
(Params
);
8051 while Present
(Param
)
8052 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
8057 pragma Assert
(Present
(Param
));
8059 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8063 -- Find the Communication_Block parameter for the call to the
8064 -- Cancelled function.
8066 Decl
:= First
(Declarations
(Blk
));
8067 while Present
(Decl
)
8068 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
8069 RE_Communication_Block
)
8074 -- Add an if statement to execute the else part if the call
8075 -- does not succeed (as indicated by the Cancelled predicate).
8078 Make_Implicit_If_Statement
(N
,
8079 Condition
=> Make_Function_Call
(Loc
,
8080 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
8081 Parameter_Associations
=> New_List
(
8082 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
8083 Then_Statements
=> Else_Statements
(N
),
8084 Else_Statements
=> Statements
(Alt
)));
8087 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8089 -- Insert declaration of B in declarations of existing block
8091 if No
(Declarations
(Blk
)) then
8092 Set_Declarations
(Blk
, New_List
);
8095 Prepend_To
(Declarations
(Blk
),
8096 Make_Object_Declaration
(Loc
,
8097 Defining_Identifier
=> B
,
8098 Object_Definition
=>
8099 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8101 -- Create new call statement
8104 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8105 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
8108 Make_Procedure_Call_Statement
(Loc
,
8109 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
8110 Parameter_Associations
=> Params
));
8112 -- Construct statement sequence for new block
8115 Make_Implicit_If_Statement
(N
,
8116 Condition
=> New_Occurrence_Of
(B
, Loc
),
8117 Then_Statements
=> Statements
(Alt
),
8118 Else_Statements
=> Else_Statements
(N
)));
8121 -- The result is the new block
8124 Make_Block_Statement
(Loc
,
8125 Declarations
=> Declarations
(Blk
),
8126 Handled_Statement_Sequence
=>
8127 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8131 end Expand_N_Conditional_Entry_Call
;
8133 ---------------------------------------
8134 -- Expand_N_Delay_Relative_Statement --
8135 ---------------------------------------
8137 -- Delay statement is implemented as a procedure call to Delay_For
8138 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8139 -- simple delays imposed by the use of Protected Objects.
8141 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8142 Loc
: constant Source_Ptr
:= Sloc
(N
);
8146 -- Try to use System.Relative_Delays.Delay_For only if available. This
8147 -- is the implementation used on restricted platforms when Ada.Calendar
8148 -- is not available.
8150 if RTE_Available
(RO_RD_Delay_For
) then
8151 Proc
:= RTE
(RO_RD_Delay_For
);
8153 -- Otherwise, use Ada.Calendar.Delays.Delay_For and emit an error
8154 -- message if not available.
8157 Proc
:= RTE
(RO_CA_Delay_For
);
8161 Make_Procedure_Call_Statement
(Loc
,
8162 Name
=> New_Occurrence_Of
(Proc
, Loc
),
8163 Parameter_Associations
=> New_List
(Expression
(N
))));
8165 end Expand_N_Delay_Relative_Statement
;
8167 ------------------------------------
8168 -- Expand_N_Delay_Until_Statement --
8169 ------------------------------------
8171 -- Delay Until statement is implemented as a procedure call to
8172 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8174 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8175 Loc
: constant Source_Ptr
:= Sloc
(N
);
8179 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8180 Typ
:= RTE
(RO_CA_Delay_Until
);
8182 Typ
:= RTE
(RO_RT_Delay_Until
);
8186 Make_Procedure_Call_Statement
(Loc
,
8187 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8188 Parameter_Associations
=> New_List
(Expression
(N
))));
8191 end Expand_N_Delay_Until_Statement
;
8193 -------------------------
8194 -- Expand_N_Entry_Body --
8195 -------------------------
8197 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8199 -- Associate discriminals with the next protected operation body to be
8202 if Present
(Next_Protected_Operation
(N
)) then
8203 Set_Discriminals
(Parent
(Current_Scope
));
8205 end Expand_N_Entry_Body
;
8207 -----------------------------------
8208 -- Expand_N_Entry_Call_Statement --
8209 -----------------------------------
8211 -- An entry call is expanded into GNARLI calls to implement a simple entry
8212 -- call (see Build_Simple_Entry_Call).
8214 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8220 if No_Run_Time_Mode
then
8221 Error_Msg_CRT
("entry call", N
);
8225 -- If this entry call is part of an asynchronous select, don't expand it
8226 -- here; it will be expanded with the select statement. Don't expand
8227 -- timed entry calls either, as they are translated into asynchronous
8230 -- ??? This whole approach is questionable; it may be better to go back
8231 -- to allowing the expansion to take place and then attempting to fix it
8232 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8233 -- whether the expanded call is on a task or protected entry.
8235 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8236 or else N
/= Triggering_Statement
(Parent
(N
)))
8237 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8238 or else N
/= Entry_Call_Statement
(Parent
(N
))
8239 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8241 Extract_Entry
(N
, Concval
, Ename
, Index
);
8242 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8244 end Expand_N_Entry_Call_Statement
;
8246 --------------------------------
8247 -- Expand_N_Entry_Declaration --
8248 --------------------------------
8250 -- If there are parameters, then first, each of the formals is marked by
8251 -- setting Is_Entry_Formal. Next a record type is built which is used to
8252 -- hold the parameter values. The name of this record type is entryP where
8253 -- entry is the name of the entry, with an additional corresponding access
8254 -- type called entryPA. The record type has matching components for each
8255 -- formal (the component names are the same as the formal names). For
8256 -- elementary types, the component type matches the formal type. For
8257 -- composite types, an access type is declared (with the name formalA)
8258 -- which designates the formal type, and the type of the component is this
8259 -- access type. Finally the Entry_Component of each formal is set to
8260 -- reference the corresponding record component.
8262 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8263 Loc
: constant Source_Ptr
:= Sloc
(N
);
8264 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8265 Components
: List_Id
;
8268 Last_Decl
: Node_Id
;
8269 Component
: Entity_Id
;
8272 Rec_Ent
: Entity_Id
;
8273 Acc_Ent
: Entity_Id
;
8276 Formal
:= First_Formal
(Entry_Ent
);
8279 -- Most processing is done only if parameters are present
8281 if Present
(Formal
) then
8282 Components
:= New_List
;
8284 -- Loop through formals
8286 while Present
(Formal
) loop
8287 Set_Is_Entry_Formal
(Formal
);
8289 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8290 Set_Entry_Component
(Formal
, Component
);
8291 Set_Entry_Formal
(Component
, Formal
);
8292 Ftype
:= Etype
(Formal
);
8294 -- Declare new access type and then append
8296 Ctype
:= Make_Temporary
(Loc
, 'A');
8297 Set_Is_Param_Block_Component_Type
(Ctype
);
8300 Make_Full_Type_Declaration
(Loc
,
8301 Defining_Identifier
=> Ctype
,
8303 Make_Access_To_Object_Definition
(Loc
,
8304 All_Present
=> True,
8305 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8306 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8308 Insert_After
(Last_Decl
, Decl
);
8311 Append_To
(Components
,
8312 Make_Component_Declaration
(Loc
,
8313 Defining_Identifier
=> Component
,
8314 Component_Definition
=>
8315 Make_Component_Definition
(Loc
,
8316 Aliased_Present
=> False,
8317 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8319 Next_Formal_With_Extras
(Formal
);
8322 -- Create the Entry_Parameter_Record declaration
8324 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8327 Make_Full_Type_Declaration
(Loc
,
8328 Defining_Identifier
=> Rec_Ent
,
8330 Make_Record_Definition
(Loc
,
8332 Make_Component_List
(Loc
,
8333 Component_Items
=> Components
)));
8335 Insert_After
(Last_Decl
, Decl
);
8338 -- Construct and link in the corresponding access type
8340 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8342 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8345 Make_Full_Type_Declaration
(Loc
,
8346 Defining_Identifier
=> Acc_Ent
,
8348 Make_Access_To_Object_Definition
(Loc
,
8349 All_Present
=> True,
8350 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8352 Insert_After
(Last_Decl
, Decl
);
8354 end Expand_N_Entry_Declaration
;
8356 -----------------------------
8357 -- Expand_N_Protected_Body --
8358 -----------------------------
8360 -- Protected bodies are expanded to the completion of the subprograms
8361 -- created for the corresponding protected type. These are a protected and
8362 -- unprotected version of each protected subprogram in the object, a
8363 -- function to calculate each entry barrier, and a procedure to execute the
8364 -- sequence of statements of each protected entry body. For example, for
8365 -- protected type ptype:
8368 -- (O : System.Address;
8369 -- E : Protected_Entry_Index)
8372 -- <discriminant renamings>
8373 -- <private object renamings>
8375 -- return <barrier expression>;
8378 -- procedure pprocN (_object : in out poV;...) is
8379 -- <discriminant renamings>
8380 -- <private object renamings>
8382 -- <sequence of statements>
8385 -- procedure pprocP (_object : in out poV;...) is
8386 -- procedure _clean is
8389 -- ptypeS (_object, Pn);
8390 -- Unlock (_object._object'Access);
8391 -- Abort_Undefer.all;
8396 -- Lock (_object._object'Access);
8397 -- pprocN (_object;...);
8402 -- function pfuncN (_object : poV;...) return Return_Type is
8403 -- <discriminant renamings>
8404 -- <private object renamings>
8406 -- <sequence of statements>
8409 -- function pfuncP (_object : poV) return Return_Type is
8410 -- procedure _clean is
8412 -- Unlock (_object._object'Access);
8413 -- Abort_Undefer.all;
8418 -- Lock (_object._object'Access);
8419 -- return pfuncN (_object);
8426 -- (O : System.Address;
8427 -- P : System.Address;
8428 -- E : Protected_Entry_Index)
8430 -- <discriminant renamings>
8431 -- <private object renamings>
8432 -- type poVP is access poV;
8433 -- _Object : ptVP := ptVP!(O);
8437 -- <statement sequence>
8438 -- Complete_Entry_Body (_Object._Object);
8440 -- when all others =>
8441 -- Exceptional_Complete_Entry_Body (
8442 -- _Object._Object, Get_GNAT_Exception);
8446 -- The type poV is the record created for the protected type to hold
8447 -- the state of the protected object.
8449 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8450 Loc
: constant Source_Ptr
:= Sloc
(N
);
8451 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8453 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8454 -- This flag indicates whether the lock free implementation is active
8456 Current_Node
: Node_Id
;
8457 Disp_Op_Body
: Node_Id
;
8458 New_Op_Body
: Node_Id
;
8462 function Build_Dispatching_Subprogram_Body
8465 Prot_Bod
: Node_Id
) return Node_Id
;
8466 -- Build a dispatching version of the protected subprogram body. The
8467 -- newly generated subprogram contains a call to the original protected
8468 -- body. The following code is generated:
8470 -- function <protected-function-name> (Param1 .. ParamN) return
8473 -- return <protected-function-name>P (Param1 .. ParamN);
8474 -- end <protected-function-name>;
8478 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8480 -- <protected-procedure-name>P (Param1 .. ParamN);
8481 -- end <protected-procedure-name>
8483 ---------------------------------------
8484 -- Build_Dispatching_Subprogram_Body --
8485 ---------------------------------------
8487 function Build_Dispatching_Subprogram_Body
8490 Prot_Bod
: Node_Id
) return Node_Id
8492 Loc
: constant Source_Ptr
:= Sloc
(N
);
8499 -- Generate a specification without a letter suffix in order to
8500 -- override an interface function or procedure.
8502 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8504 -- The formal parameters become the actuals of the protected function
8505 -- or procedure call.
8507 Actuals
:= New_List
;
8508 Formal
:= First
(Parameter_Specifications
(Spec
));
8509 while Present
(Formal
) loop
8511 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8515 if Nkind
(Spec
) = N_Procedure_Specification
then
8518 Make_Procedure_Call_Statement
(Loc
,
8520 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8521 Parameter_Associations
=> Actuals
));
8524 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8528 Make_Simple_Return_Statement
(Loc
,
8530 Make_Function_Call
(Loc
,
8532 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8533 Parameter_Associations
=> Actuals
)));
8537 Make_Subprogram_Body
(Loc
,
8538 Declarations
=> Empty_List
,
8539 Specification
=> Spec
,
8540 Handled_Statement_Sequence
=>
8541 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8542 end Build_Dispatching_Subprogram_Body
;
8544 -- Start of processing for Expand_N_Protected_Body
8547 if No_Run_Time_Mode
then
8548 Error_Msg_CRT
("protected body", N
);
8552 -- This is the proper body corresponding to a stub. The declarations
8553 -- must be inserted at the point of the stub, which in turn is in the
8554 -- declarative part of the parent unit.
8556 if Nkind
(Parent
(N
)) = N_Subunit
then
8557 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8562 Op_Body
:= First
(Declarations
(N
));
8564 -- The protected body is replaced with the bodies of its protected
8565 -- operations, and the declarations for internal objects that may
8566 -- have been created for entry family bounds.
8568 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8571 while Present
(Op_Body
) loop
8572 case Nkind
(Op_Body
) is
8573 when N_Subprogram_Declaration
=>
8576 when N_Subprogram_Body
=>
8578 -- Do not create bodies for eliminated operations
8580 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8581 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8583 if Lock_Free_Active
then
8585 Build_Lock_Free_Unprotected_Subprogram_Body
8589 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8592 Insert_After
(Current_Node
, New_Op_Body
);
8593 Current_Node
:= New_Op_Body
;
8594 Analyze
(New_Op_Body
);
8596 -- Build the corresponding protected operation. It may
8597 -- appear that this is needed only if this is a visible
8598 -- operation of the type, or if it is an interrupt handler,
8599 -- and this was the strategy used previously in GNAT.
8601 -- However, the operation may be exported through a 'Access
8602 -- to an external caller. This is the common idiom in code
8603 -- that uses the Ada 2005 Timing_Events package. As a result
8604 -- we need to produce the protected body for both visible
8605 -- and private operations, as well as operations that only
8606 -- have a body in the source, and for which we create a
8607 -- declaration in the protected body itself.
8609 if Present
(Corresponding_Spec
(Op_Body
)) then
8610 if Lock_Free_Active
then
8612 Build_Lock_Free_Protected_Subprogram_Body
8613 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8616 Build_Protected_Subprogram_Body
8617 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8620 Insert_After
(Current_Node
, New_Op_Body
);
8621 Analyze
(New_Op_Body
);
8623 Current_Node
:= New_Op_Body
;
8625 -- Generate an overriding primitive operation body for
8626 -- this subprogram if the protected type implements an
8629 if Ada_Version
>= Ada_2005
8631 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8634 Build_Dispatching_Subprogram_Body
8635 (Op_Body
, Pid
, New_Op_Body
);
8637 Insert_After
(Current_Node
, Disp_Op_Body
);
8638 Analyze
(Disp_Op_Body
);
8640 Current_Node
:= Disp_Op_Body
;
8645 when N_Entry_Body
=>
8646 Op_Id
:= Defining_Identifier
(Op_Body
);
8647 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8649 Insert_After
(Current_Node
, New_Op_Body
);
8650 Current_Node
:= New_Op_Body
;
8651 Analyze
(New_Op_Body
);
8653 when N_Implicit_Label_Declaration
=>
8656 when N_Itype_Reference
=>
8657 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8659 when N_Freeze_Entity
=>
8660 New_Op_Body
:= New_Copy
(Op_Body
);
8662 if Present
(Entity
(Op_Body
))
8663 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8665 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8668 Insert_After
(Current_Node
, New_Op_Body
);
8669 Current_Node
:= New_Op_Body
;
8670 Analyze
(New_Op_Body
);
8673 New_Op_Body
:= New_Copy
(Op_Body
);
8674 Insert_After
(Current_Node
, New_Op_Body
);
8675 Current_Node
:= New_Op_Body
;
8676 Analyze
(New_Op_Body
);
8678 when N_Object_Declaration
=>
8679 pragma Assert
(not Comes_From_Source
(Op_Body
));
8680 New_Op_Body
:= New_Copy
(Op_Body
);
8681 Insert_After
(Current_Node
, New_Op_Body
);
8682 Current_Node
:= New_Op_Body
;
8683 Analyze
(New_Op_Body
);
8686 raise Program_Error
;
8692 -- Finally, create the body of the function that maps an entry index
8693 -- into the corresponding body index, except when there is no entry, or
8694 -- in a Ravenscar-like profile.
8696 if Corresponding_Runtime_Package
(Pid
) =
8697 System_Tasking_Protected_Objects_Entries
8699 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8700 Insert_After
(Current_Node
, New_Op_Body
);
8701 Current_Node
:= New_Op_Body
;
8702 Analyze
(New_Op_Body
);
8705 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8706 -- protected body. At this point all wrapper specs have been created,
8707 -- frozen and included in the dispatch table for the protected type.
8709 if Ada_Version
>= Ada_2005
then
8710 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8712 end Expand_N_Protected_Body
;
8714 -----------------------------------------
8715 -- Expand_N_Protected_Type_Declaration --
8716 -----------------------------------------
8718 -- First we create a corresponding record type declaration used to
8719 -- represent values of this protected type.
8720 -- The general form of this type declaration is
8722 -- type poV (discriminants) is record
8723 -- _Object : aliased <kind>Protection
8724 -- [(<entry count> [, <handler count>])];
8725 -- [entry_family : array (bounds) of Void;]
8726 -- <private data fields>
8729 -- The discriminants are present only if the corresponding protected type
8730 -- has discriminants, and they exactly mirror the protected type
8731 -- discriminants. The private data fields similarly mirror the private
8732 -- declarations of the protected type.
8734 -- The Object field is always present. It contains RTS specific data used
8735 -- to control the protected object. It is declared as Aliased so that it
8736 -- can be passed as a pointer to the RTS. This allows the protected record
8737 -- to be referenced within RTS data structures. An appropriate Protection
8738 -- type and discriminant are generated.
8740 -- The Service field is present for protected objects with entries. It
8741 -- contains sufficient information to allow the entry service procedure for
8742 -- this object to be called when the object is not known till runtime.
8744 -- One entry_family component is present for each entry family in the
8745 -- task definition (see Expand_N_Task_Type_Declaration).
8747 -- When a protected object is declared, an instance of the protected type
8748 -- value record is created. The elaboration of this declaration creates the
8749 -- correct bounds for the entry families, and also evaluates the priority
8750 -- expression if needed. The initialization routine for the protected type
8751 -- itself then calls Initialize_Protection with appropriate parameters to
8752 -- initialize the value of the Task_Id field. Install_Handlers may be also
8753 -- called if a pragma Attach_Handler applies.
8755 -- Note: this record is passed to the subprograms created by the expansion
8756 -- of protected subprograms and entries. It is an in parameter to protected
8757 -- functions and an in out parameter to procedures and entry bodies. The
8758 -- Entity_Id for this created record type is placed in the
8759 -- Corresponding_Record_Type field of the associated protected type entity.
8761 -- Next we create a procedure specifications for protected subprograms and
8762 -- entry bodies. For each protected subprograms two subprograms are
8763 -- created, an unprotected and a protected version. The unprotected version
8764 -- is called from within other operations of the same protected object.
8766 -- We also build the call to register the procedure if a pragma
8767 -- Interrupt_Handler applies.
8769 -- A single subprogram is created to service all entry bodies; it has an
8770 -- additional boolean out parameter indicating that the previous entry call
8771 -- made by the current task was serviced immediately, i.e. not by proxy.
8772 -- The O parameter contains a pointer to a record object of the type
8773 -- described above. An untyped interface is used here to allow this
8774 -- procedure to be called in places where the type of the object to be
8775 -- serviced is not known. This must be done, for example, when a call that
8776 -- may have been requeued is cancelled; the corresponding object must be
8777 -- serviced, but which object that is not known till runtime.
8780 -- (O : System.Address; P : out Boolean);
8781 -- procedure pprocN (_object : in out poV);
8782 -- procedure pproc (_object : in out poV);
8783 -- function pfuncN (_object : poV);
8784 -- function pfunc (_object : poV);
8787 -- Note that this must come after the record type declaration, since
8788 -- the specs refer to this type.
8790 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8791 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8792 Loc
: constant Source_Ptr
:= Sloc
(N
);
8793 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8795 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8796 -- This flag indicates whether the lock free implementation is active
8798 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8799 -- This contains two lists; one for visible and one for private decls
8801 Current_Node
: Node_Id
:= N
;
8803 Entries_Aggr
: Node_Id
;
8805 procedure Check_Inlining
(Subp
: Entity_Id
);
8806 -- If the original operation has a pragma Inline, propagate the flag
8807 -- to the internal body, for possible inlining later on. The source
8808 -- operation is invisible to the back-end and is never actually called.
8810 procedure Expand_Entry_Declaration
(Decl
: Node_Id
);
8811 -- Create the entry barrier and the procedure body for entry declaration
8812 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8814 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8815 -- When compiling under the Ravenscar profile, private components must
8816 -- have a static size, or else a protected object will require heap
8817 -- allocation, violating the corresponding restriction. It is preferable
8818 -- to make this check here, because it provides a better error message
8819 -- than the back-end, which refers to the object as a whole.
8821 procedure Register_Handler
;
8822 -- For a protected operation that is an interrupt handler, add the
8823 -- freeze action that will register it as such.
8825 --------------------
8826 -- Check_Inlining --
8827 --------------------
8829 procedure Check_Inlining
(Subp
: Entity_Id
) is
8831 if Is_Inlined
(Subp
) then
8832 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8833 Set_Is_Inlined
(Subp
, False);
8837 ---------------------------
8838 -- Static_Component_Size --
8839 ---------------------------
8841 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8842 Typ
: constant Entity_Id
:= Etype
(Comp
);
8846 if Is_Scalar_Type
(Typ
) then
8849 elsif Is_Array_Type
(Typ
) then
8850 return Compile_Time_Known_Bounds
(Typ
);
8852 elsif Is_Record_Type
(Typ
) then
8853 C
:= First_Component
(Typ
);
8854 while Present
(C
) loop
8855 if not Static_Component_Size
(C
) then
8864 -- Any other type will be checked by the back-end
8869 end Static_Component_Size
;
8871 ------------------------------
8872 -- Expand_Entry_Declaration --
8873 ------------------------------
8875 procedure Expand_Entry_Declaration
(Decl
: Node_Id
) is
8876 Ent_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
8882 E_Count
:= E_Count
+ 1;
8884 -- Create the protected body subprogram
8887 Make_Defining_Identifier
(Loc
,
8888 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'E'));
8889 Set_Protected_Body_Subprogram
(Ent_Id
, Bod_Id
);
8892 Make_Subprogram_Declaration
(Loc
,
8894 Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Ent_Id
));
8896 Insert_After
(Current_Node
, Subp
);
8897 Current_Node
:= Subp
;
8901 -- Build a wrapper procedure to handle contract cases, preconditions,
8902 -- and postconditions.
8904 Build_Contract_Wrapper
(Ent_Id
, N
);
8906 -- Create the barrier function
8909 Make_Defining_Identifier
(Loc
,
8910 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'B'));
8911 Set_Barrier_Function
(Ent_Id
, Bar_Id
);
8914 Make_Subprogram_Declaration
(Loc
,
8916 Build_Barrier_Function_Specification
(Loc
, Bar_Id
));
8917 Set_Is_Entry_Barrier_Function
(Subp
);
8919 Insert_After
(Current_Node
, Subp
);
8920 Current_Node
:= Subp
;
8924 Set_Protected_Body_Subprogram
(Bar_Id
, Bar_Id
);
8925 Set_Scope
(Bar_Id
, Scope
(Ent_Id
));
8927 -- Collect pointers to the protected subprogram and the barrier
8928 -- of the current entry, for insertion into Entry_Bodies_Array.
8930 Append_To
(Expressions
(Entries_Aggr
),
8931 Make_Aggregate
(Loc
,
8932 Expressions
=> New_List
(
8933 Make_Attribute_Reference
(Loc
,
8934 Prefix
=> New_Occurrence_Of
(Bar_Id
, Loc
),
8935 Attribute_Name
=> Name_Unrestricted_Access
),
8936 Make_Attribute_Reference
(Loc
,
8937 Prefix
=> New_Occurrence_Of
(Bod_Id
, Loc
),
8938 Attribute_Name
=> Name_Unrestricted_Access
))));
8939 end Expand_Entry_Declaration
;
8941 ----------------------
8942 -- Register_Handler --
8943 ----------------------
8945 procedure Register_Handler
is
8947 -- All semantic checks already done in Sem_Prag
8949 Prot_Proc
: constant Entity_Id
:=
8950 Defining_Unit_Name
(Specification
(Current_Node
));
8952 Proc_Address
: constant Node_Id
:=
8953 Make_Attribute_Reference
(Loc
,
8955 New_Occurrence_Of
(Prot_Proc
, Loc
),
8956 Attribute_Name
=> Name_Address
);
8958 RTS_Call
: constant Entity_Id
:=
8959 Make_Procedure_Call_Statement
(Loc
,
8962 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8963 Parameter_Associations
=> New_List
(Proc_Address
));
8965 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8966 end Register_Handler
;
8971 Body_Id
: Entity_Id
;
8977 Object_Comp
: Node_Id
;
8982 -- Start of processing for Expand_N_Protected_Type_Declaration
8985 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8988 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8991 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8993 Qualify_Entity_Names
(N
);
8995 -- If the type has discriminants, their occurrences in the declaration
8996 -- have been replaced by the corresponding discriminals. For components
8997 -- that are constrained by discriminants, their homologues in the
8998 -- corresponding record type must refer to the discriminants of that
8999 -- record, so we must apply a new renaming to subtypes_indications:
9001 -- protected discriminant => discriminal => record discriminant
9003 -- This replacement is not applied to default expressions, for which
9004 -- the discriminal is correct.
9006 if Has_Discriminants
(Prot_Typ
) then
9012 Disc
:= First_Discriminant
(Prot_Typ
);
9013 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
9014 while Present
(Disc
) loop
9015 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
9016 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
9017 Next_Discriminant
(Disc
);
9023 -- Fill in the component declarations
9025 -- Add components for entry families. For each entry family, create an
9026 -- anonymous type declaration with the same size, and analyze the type.
9028 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9030 pragma Assert
(Present
(Pdef
));
9032 Insert_After
(Current_Node
, Rec_Decl
);
9033 Current_Node
:= Rec_Decl
;
9035 -- Add private field components
9037 if Present
(Private_Declarations
(Pdef
)) then
9038 Priv
:= First
(Private_Declarations
(Pdef
));
9039 while Present
(Priv
) loop
9040 if Nkind
(Priv
) = N_Component_Declaration
then
9041 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9043 -- When compiling for a restricted profile, the private
9044 -- components must have a static size. If not, this is an
9045 -- error for a single protected declaration, and rates a
9046 -- warning on a protected type declaration.
9048 if not Comes_From_Source
(Prot_Typ
) then
9050 -- It's ok to be checking this restriction at expansion
9051 -- time, because this is only for the restricted profile,
9052 -- which is not subject to strict RM conformance, so it
9053 -- is OK to miss this check in -gnatc mode.
9055 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9057 (No_Implicit_Protected_Object_Allocations
, Priv
);
9059 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9060 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9062 -- Any object of the type will be non-static
9064 Error_Msg_N
("component has non-static size??", Priv
);
9066 ("\creation of protected object of type& will "
9067 & "violate restriction "
9068 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9070 -- Object will be non-static if discriminants are
9073 ("creation of protected object of type& with "
9074 & "non-static discriminants will violate "
9075 & "restriction No_Implicit_Heap_Allocations??",
9079 -- Likewise for No_Implicit_Protected_Object_Allocations
9081 elsif Restriction_Active
9082 (No_Implicit_Protected_Object_Allocations
)
9084 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9086 -- Any object of the type will be non-static
9088 Error_Msg_N
("component has non-static size??", Priv
);
9090 ("\creation of protected object of type& will "
9091 & "violate restriction "
9092 & "No_Implicit_Protected_Object_Allocations??",
9095 -- Object will be non-static if discriminants are
9098 ("creation of protected object of type& with "
9099 & "non-static discriminants will violate "
9101 & "No_Implicit_Protected_Object_Allocations??",
9107 -- The component definition consists of a subtype indication,
9108 -- or (in Ada 2005) an access definition. Make a copy of the
9109 -- proper definition.
9112 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9113 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9114 Nent
: constant Entity_Id
:=
9115 Make_Defining_Identifier
(Sloc
(Oent
),
9116 Chars
=> Chars
(Oent
));
9120 if Present
(Subtype_Indication
(Old_Comp
)) then
9122 Make_Component_Definition
(Sloc
(Oent
),
9123 Aliased_Present
=> False,
9124 Subtype_Indication
=>
9126 (Subtype_Indication
(Old_Comp
), Discr_Map
));
9129 Make_Component_Definition
(Sloc
(Oent
),
9130 Aliased_Present
=> False,
9131 Access_Definition
=>
9133 (Access_Definition
(Old_Comp
), Discr_Map
));
9137 Make_Component_Declaration
(Loc
,
9138 Defining_Identifier
=> Nent
,
9139 Component_Definition
=> New_Comp
,
9140 Expression
=> Expression
(Priv
));
9142 Set_Has_Per_Object_Constraint
(Nent
,
9143 Has_Per_Object_Constraint
(Oent
));
9145 Append_To
(Cdecls
, New_Priv
);
9148 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9150 -- Make the unprotected version of the subprogram available
9151 -- for expansion of intra object calls. There is need for
9152 -- a protected version only if the subprogram is an interrupt
9153 -- handler, otherwise this operation can only be called from
9157 Make_Subprogram_Declaration
(Loc
,
9159 Build_Protected_Sub_Specification
9160 (Priv
, Prot_Typ
, Unprotected_Mode
));
9162 Insert_After
(Current_Node
, Sub
);
9165 Set_Protected_Body_Subprogram
9166 (Defining_Unit_Name
(Specification
(Priv
)),
9167 Defining_Unit_Name
(Specification
(Sub
)));
9168 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9169 Current_Node
:= Sub
;
9172 Make_Subprogram_Declaration
(Loc
,
9174 Build_Protected_Sub_Specification
9175 (Priv
, Prot_Typ
, Protected_Mode
));
9177 Insert_After
(Current_Node
, Sub
);
9179 Current_Node
:= Sub
;
9181 if Is_Interrupt_Handler
9182 (Defining_Unit_Name
(Specification
(Priv
)))
9184 if not Restricted_Profile
then
9194 -- Except for the lock-free implementation, append the _Object field
9195 -- with the right type to the component list. We need to compute the
9196 -- number of entries, and in some cases the number of Attach_Handler
9199 if not Lock_Free_Active
then
9201 Entry_Count_Expr
: constant Node_Id
:=
9202 Build_Entry_Count_Expression
9203 (Prot_Typ
, Cdecls
, Loc
);
9204 Num_Attach_Handler
: Nat
:= 0;
9205 Protection_Subtype
: Node_Id
;
9209 if Has_Attach_Handler
(Prot_Typ
) then
9210 Ritem
:= First_Rep_Item
(Prot_Typ
);
9211 while Present
(Ritem
) loop
9212 if Nkind
(Ritem
) = N_Pragma
9213 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9215 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9218 Next_Rep_Item
(Ritem
);
9222 -- Determine the proper protection type. There are two special
9223 -- cases: 1) when the protected type has dynamic interrupt
9224 -- handlers, and 2) when it has static handlers and we use a
9225 -- restricted profile.
9227 if Has_Attach_Handler
(Prot_Typ
)
9228 and then not Restricted_Profile
9230 Protection_Subtype
:=
9231 Make_Subtype_Indication
(Loc
,
9234 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9236 Make_Index_Or_Discriminant_Constraint
(Loc
,
9237 Constraints
=> New_List
(
9239 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9241 elsif Has_Interrupt_Handler
(Prot_Typ
)
9242 and then not Restriction_Active
(No_Dynamic_Attachment
)
9244 Protection_Subtype
:=
9245 Make_Subtype_Indication
(Loc
,
9248 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9250 Make_Index_Or_Discriminant_Constraint
(Loc
,
9251 Constraints
=> New_List
(Entry_Count_Expr
)));
9254 case Corresponding_Runtime_Package
(Prot_Typ
) is
9255 when System_Tasking_Protected_Objects_Entries
=>
9256 Protection_Subtype
:=
9257 Make_Subtype_Indication
(Loc
,
9260 (RTE
(RE_Protection_Entries
), Loc
),
9262 Make_Index_Or_Discriminant_Constraint
(Loc
,
9263 Constraints
=> New_List
(Entry_Count_Expr
)));
9265 when System_Tasking_Protected_Objects_Single_Entry
=>
9266 Protection_Subtype
:=
9267 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9269 when System_Tasking_Protected_Objects
=>
9270 Protection_Subtype
:=
9271 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9274 raise Program_Error
;
9279 Make_Component_Declaration
(Loc
,
9280 Defining_Identifier
=>
9281 Make_Defining_Identifier
(Loc
, Name_uObject
),
9282 Component_Definition
=>
9283 Make_Component_Definition
(Loc
,
9284 Aliased_Present
=> True,
9285 Subtype_Indication
=> Protection_Subtype
));
9288 -- Put the _Object component after the private component so that it
9289 -- be finalized early as required by 9.4 (20)
9291 Append_To
(Cdecls
, Object_Comp
);
9294 -- Analyze the record declaration immediately after construction,
9295 -- because the initialization procedure is needed for single object
9296 -- declarations before the next entity is analyzed (the freeze call
9297 -- that generates this initialization procedure is found below).
9299 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9301 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9302 -- the corresponding record is frozen. If any wrappers are generated,
9303 -- Current_Node is updated accordingly.
9305 if Ada_Version
>= Ada_2005
then
9306 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9309 -- Collect pointers to entry bodies and their barriers, to be placed
9310 -- in the Entry_Bodies_Array for the type. For each entry/family we
9311 -- add an expression to the aggregate which is the initial value of
9312 -- this array. The array is declared after all protected subprograms.
9314 if Has_Entries
(Prot_Typ
) then
9315 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9317 Entries_Aggr
:= Empty
;
9320 -- Build two new procedure specifications for each protected subprogram;
9321 -- one to call from outside the object and one to call from inside.
9322 -- Build a barrier function and an entry body action procedure
9323 -- specification for each protected entry. Initialize the entry body
9324 -- array. If subprogram is flagged as eliminated, do not generate any
9325 -- internal operations.
9328 Comp
:= First
(Visible_Declarations
(Pdef
));
9329 while Present
(Comp
) loop
9330 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9332 Make_Subprogram_Declaration
(Loc
,
9334 Build_Protected_Sub_Specification
9335 (Comp
, Prot_Typ
, Unprotected_Mode
));
9337 Insert_After
(Current_Node
, Sub
);
9340 Set_Protected_Body_Subprogram
9341 (Defining_Unit_Name
(Specification
(Comp
)),
9342 Defining_Unit_Name
(Specification
(Sub
)));
9343 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9345 -- Make the protected version of the subprogram available for
9346 -- expansion of external calls.
9348 Current_Node
:= Sub
;
9351 Make_Subprogram_Declaration
(Loc
,
9353 Build_Protected_Sub_Specification
9354 (Comp
, Prot_Typ
, Protected_Mode
));
9356 Insert_After
(Current_Node
, Sub
);
9359 Current_Node
:= Sub
;
9361 -- Generate an overriding primitive operation specification for
9362 -- this subprogram if the protected type implements an interface
9363 -- and Build_Wrapper_Spec did not generate its wrapper.
9365 if Ada_Version
>= Ada_2005
9367 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9370 Found
: Boolean := False;
9371 Prim_Elmt
: Elmt_Id
;
9377 (Primitive_Operations
9378 (Corresponding_Record_Type
(Prot_Typ
)));
9380 while Present
(Prim_Elmt
) loop
9381 Prim_Op
:= Node
(Prim_Elmt
);
9383 if Is_Primitive_Wrapper
(Prim_Op
)
9384 and then Wrapped_Entity
(Prim_Op
) =
9385 Defining_Entity
(Specification
(Comp
))
9391 Next_Elmt
(Prim_Elmt
);
9396 Make_Subprogram_Declaration
(Loc
,
9398 Build_Protected_Sub_Specification
9399 (Comp
, Prot_Typ
, Dispatching_Mode
));
9401 Insert_After
(Current_Node
, Sub
);
9404 Current_Node
:= Sub
;
9409 -- If a pragma Interrupt_Handler applies, build and add a call to
9410 -- Register_Interrupt_Handler to the freezing actions of the
9411 -- protected version (Current_Node) of the subprogram:
9413 -- system.interrupts.register_interrupt_handler
9414 -- (prot_procP'address);
9416 if not Restricted_Profile
9417 and then Is_Interrupt_Handler
9418 (Defining_Unit_Name
(Specification
(Comp
)))
9423 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9424 Expand_Entry_Declaration
(Comp
);
9430 -- If there are some private entry declarations, expand it as if they
9431 -- were visible entries.
9433 if Present
(Private_Declarations
(Pdef
)) then
9434 Comp
:= First
(Private_Declarations
(Pdef
));
9435 while Present
(Comp
) loop
9436 if Nkind
(Comp
) = N_Entry_Declaration
then
9437 Expand_Entry_Declaration
(Comp
);
9444 -- Create the declaration of an array object which contains the values
9445 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9446 -- type. This object is later passed to the appropriate protected object
9447 -- initialization routine.
9449 if Has_Entries
(Prot_Typ
)
9450 and then Corresponding_Runtime_Package
(Prot_Typ
) =
9451 System_Tasking_Protected_Objects_Entries
9458 Maxes_Id
: Entity_Id
;
9459 Need_Array
: Boolean := False;
9462 -- First check if there is any Max_Queue_Length pragma
9464 Item
:= First_Entity
(Prot_Typ
);
9465 while Present
(Item
) loop
9466 if Is_Entry
(Item
) and then Has_Max_Queue_Length
(Item
) then
9474 -- Gather the Max_Queue_Length values of all entries in a list. A
9475 -- value of zero indicates that the entry has no limitation on its
9480 Item
:= First_Entity
(Prot_Typ
);
9482 while Present
(Item
) loop
9483 if Is_Entry
(Item
) then
9486 Make_Integer_Literal
9487 (Loc
, Get_Max_Queue_Length
(Item
)));
9493 -- Create the declaration of the array object. Generate:
9495 -- Maxes_Id : aliased constant
9496 -- Protected_Entry_Queue_Max_Array
9497 -- (1 .. Count) := (..., ...);
9500 Make_Defining_Identifier
(Loc
,
9501 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'B'));
9504 Make_Object_Declaration
(Loc
,
9505 Defining_Identifier
=> Maxes_Id
,
9506 Aliased_Present
=> True,
9507 Constant_Present
=> True,
9508 Object_Definition
=>
9509 Make_Subtype_Indication
(Loc
,
9512 (RTE
(RE_Protected_Entry_Queue_Max_Array
), Loc
),
9514 Make_Index_Or_Discriminant_Constraint
(Loc
,
9515 Constraints
=> New_List
(
9517 Make_Integer_Literal
(Loc
, 1),
9518 Make_Integer_Literal
(Loc
, Count
))))),
9519 Expression
=> Make_Aggregate
(Loc
, Maxes
));
9521 -- A pointer to this array will be placed in the corresponding
9522 -- record by its initialization procedure so this needs to be
9525 Insert_After
(Current_Node
, Max_Vals
);
9526 Current_Node
:= Max_Vals
;
9529 Set_Entry_Max_Queue_Lengths_Array
(Prot_Typ
, Maxes_Id
);
9534 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9535 -- all protected subprograms have been collected.
9537 if Has_Entries
(Prot_Typ
) then
9539 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9540 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9542 case Corresponding_Runtime_Package
(Prot_Typ
) is
9543 when System_Tasking_Protected_Objects_Entries
=>
9544 Expr
:= Entries_Aggr
;
9546 Make_Subtype_Indication
(Loc
,
9549 (RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9551 Make_Index_Or_Discriminant_Constraint
(Loc
,
9552 Constraints
=> New_List
(
9554 Make_Integer_Literal
(Loc
, 1),
9555 Make_Integer_Literal
(Loc
, E_Count
)))));
9557 when System_Tasking_Protected_Objects_Single_Entry
=>
9558 Expr
:= Remove_Head
(Expressions
(Entries_Aggr
));
9559 Obj_Def
:= New_Occurrence_Of
(RTE
(RE_Entry_Body
), Loc
);
9562 raise Program_Error
;
9566 Make_Object_Declaration
(Loc
,
9567 Defining_Identifier
=> Body_Id
,
9568 Aliased_Present
=> True,
9569 Constant_Present
=> True,
9570 Object_Definition
=> Obj_Def
,
9571 Expression
=> Expr
);
9573 -- A pointer to this array will be placed in the corresponding record
9574 -- by its initialization procedure so this needs to be analyzed here.
9576 Insert_After
(Current_Node
, Body_Arr
);
9577 Current_Node
:= Body_Arr
;
9580 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9582 -- Finally, build the function that maps an entry index into the
9583 -- corresponding body. A pointer to this function is placed in each
9584 -- object of the type. Except for a ravenscar-like profile (no abort,
9585 -- no entry queue, 1 entry)
9587 if Corresponding_Runtime_Package
(Prot_Typ
) =
9588 System_Tasking_Protected_Objects_Entries
9591 Make_Subprogram_Declaration
(Loc
,
9592 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9594 Insert_After
(Current_Node
, Sub
);
9598 end Expand_N_Protected_Type_Declaration
;
9600 --------------------------------
9601 -- Expand_N_Requeue_Statement --
9602 --------------------------------
9604 -- A nondispatching requeue statement is expanded into one of four GNARLI
9605 -- operations, depending on the source and destination (task or protected
9606 -- object). A dispatching requeue statement is expanded into a call to the
9607 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9608 -- jump around the remainder of processing for the original entry and, if
9609 -- the destination is (different) protected object, to attempt to service
9610 -- it. The following illustrates the various cases:
9613 -- (O : System.Address;
9614 -- P : System.Address;
9615 -- E : Protected_Entry_Index)
9617 -- <discriminant renamings>
9618 -- <private object renamings>
9619 -- type poVP is access poV;
9620 -- _object : ptVP := ptVP!(O);
9624 -- <start of statement sequence for entry>
9626 -- -- Requeue from one protected entry body to another protected
9629 -- Requeue_Protected_Entry (
9630 -- _object._object'Access,
9631 -- new._object'Access,
9636 -- <some more of the statement sequence for entry>
9638 -- -- Requeue from an entry body to a task entry
9640 -- Requeue_Protected_To_Task_Entry (
9646 -- <rest of statement sequence for entry>
9647 -- Complete_Entry_Body (_object._object);
9650 -- when all others =>
9651 -- Exceptional_Complete_Entry_Body (
9652 -- _object._object, Get_GNAT_Exception);
9656 -- Requeue of a task entry call to a task entry
9658 -- Accept_Call (E, Ann);
9659 -- <start of statement sequence for accept statement>
9660 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9662 -- <rest of statement sequence for accept statement>
9664 -- Complete_Rendezvous;
9667 -- when all others =>
9668 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9670 -- Requeue of a task entry call to a protected entry
9672 -- Accept_Call (E, Ann);
9673 -- <start of statement sequence for accept statement>
9674 -- Requeue_Task_To_Protected_Entry (
9675 -- new._object'Access,
9680 -- <rest of statement sequence for accept statement>
9682 -- Complete_Rendezvous;
9685 -- when all others =>
9686 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9688 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9689 -- marked by pragma Implemented (XXX, By_Entry).
9691 -- The requeue is inside a protected entry:
9694 -- (O : System.Address;
9695 -- P : System.Address;
9696 -- E : Protected_Entry_Index)
9698 -- <discriminant renamings>
9699 -- <private object renamings>
9700 -- type poVP is access poV;
9701 -- _object : ptVP := ptVP!(O);
9705 -- <start of statement sequence for entry>
9708 -- (<interface class-wide object>,
9711 -- Ada.Tags.Get_Offset_Index
9713 -- <interface dispatch table index of target entry>),
9717 -- <rest of statement sequence for entry>
9718 -- Complete_Entry_Body (_object._object);
9721 -- when all others =>
9722 -- Exceptional_Complete_Entry_Body (
9723 -- _object._object, Get_GNAT_Exception);
9727 -- The requeue is inside a task entry:
9729 -- Accept_Call (E, Ann);
9730 -- <start of statement sequence for accept statement>
9732 -- (<interface class-wide object>,
9735 -- Ada.Tags.Get_Offset_Index
9737 -- <interface dispatch table index of target entrt>),
9741 -- <rest of statement sequence for accept statement>
9743 -- Complete_Rendezvous;
9746 -- when all others =>
9747 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9749 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9750 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9751 -- statement is replaced by a dispatching call with actual parameters taken
9752 -- from the inner-most accept statement or entry body.
9754 -- Target.Primitive (Param1, ..., ParamN);
9756 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9757 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9761 -- S : constant Offset_Index :=
9762 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9763 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9766 -- if C = POK_Protected_Entry
9767 -- or else C = POK_Task_Entry
9769 -- <statements for dispatching requeue>
9771 -- elsif C = POK_Protected_Procedure then
9772 -- <dispatching call equivalent>
9775 -- raise Program_Error;
9779 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9780 Loc
: constant Source_Ptr
:= Sloc
(N
);
9781 Conc_Typ
: Entity_Id
;
9785 Old_Typ
: Entity_Id
;
9787 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9788 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9789 -- the form Concval.Ename. It is statically known that Ename is allowed
9790 -- to be implemented by a protected procedure. Create a dispatching call
9791 -- equivalent of Concval.Ename taking the actual parameters from the
9792 -- inner-most accept statement or entry body.
9794 function Build_Dispatching_Requeue
return Node_Id
;
9795 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9796 -- the form Concval.Ename. It is statically known that Ename is allowed
9797 -- to be implemented by a protected or a task entry. Create a call to
9798 -- primitive _Disp_Requeue which handles the low-level actions.
9800 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9801 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9802 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9803 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9804 -- determines at runtime whether Ename denotes an entry or a procedure
9805 -- and perform the appropriate kind of dispatching select.
9807 function Build_Normal_Requeue
return Node_Id
;
9808 -- N denotes a nondispatching requeue statement to either a task or a
9809 -- protected entry. Build the appropriate runtime call to perform the
9812 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9813 -- For a protected entry, create a return statement to skip the rest of
9814 -- the entry body. Otherwise, create a goto statement to skip the rest
9815 -- of a task accept statement. The lookup for the enclosing entry body
9816 -- or accept statement starts from Search.
9818 ---------------------------------------
9819 -- Build_Dispatching_Call_Equivalent --
9820 ---------------------------------------
9822 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9823 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9824 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9831 -- Climb the parent chain looking for the inner-most entry body or
9832 -- accept statement.
9835 while Present
(Acc_Ent
)
9836 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9839 Acc_Ent
:= Parent
(Acc_Ent
);
9842 -- A requeue statement should be housed inside an entry body or an
9843 -- accept statement at some level. If this is not the case, then the
9844 -- tree is malformed.
9846 pragma Assert
(Present
(Acc_Ent
));
9848 -- Recover the list of formal parameters
9850 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9851 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9854 Formals
:= Parameter_Specifications
(Acc_Ent
);
9856 -- Create the actual parameters for the dispatching call. These are
9857 -- simply copies of the entry body or accept statement formals in the
9858 -- same order as they appear.
9862 if Present
(Formals
) then
9863 Actuals
:= New_List
;
9864 Formal
:= First
(Formals
);
9865 while Present
(Formal
) loop
9867 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9873 -- Obj.Call_Ent (Actuals);
9876 Make_Procedure_Call_Statement
(Loc
,
9878 Make_Selected_Component
(Loc
,
9879 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9880 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9882 Parameter_Associations
=> Actuals
);
9883 end Build_Dispatching_Call_Equivalent
;
9885 -------------------------------
9886 -- Build_Dispatching_Requeue --
9887 -------------------------------
9889 function Build_Dispatching_Requeue
return Node_Id
is
9890 Params
: constant List_Id
:= New_List
;
9893 -- Process the "with abort" parameter
9896 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9898 -- Process the entry wrapper's position in the primary dispatch
9899 -- table parameter. Generate:
9901 -- Ada.Tags.Get_Entry_Index
9902 -- (T => To_Tag_Ptr (Obj'Address).all,
9904 -- Ada.Tags.Get_Offset_Index
9905 -- (Ada.Tags.Tag (Concval),
9906 -- <interface dispatch table position of Ename>));
9908 -- Note that Obj'Address is recursively expanded into a call to
9909 -- Base_Address (Obj).
9911 if Tagged_Type_Expansion
then
9913 Make_Function_Call
(Loc
,
9914 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9915 Parameter_Associations
=> New_List
(
9917 Make_Explicit_Dereference
(Loc
,
9918 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9919 Make_Attribute_Reference
(Loc
,
9920 Prefix
=> New_Copy_Tree
(Concval
),
9921 Attribute_Name
=> Name_Address
))),
9923 Make_Function_Call
(Loc
,
9924 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9925 Parameter_Associations
=> New_List
(
9926 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9927 Make_Integer_Literal
(Loc
,
9928 DT_Position
(Entity
(Ename
))))))));
9934 Make_Function_Call
(Loc
,
9935 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9936 Parameter_Associations
=> New_List
(
9938 Make_Attribute_Reference
(Loc
,
9940 Attribute_Name
=> Name_Tag
),
9942 Make_Function_Call
(Loc
,
9943 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9945 Parameter_Associations
=> New_List
(
9949 Make_Attribute_Reference
(Loc
,
9951 Attribute_Name
=> Name_Tag
),
9955 Make_Attribute_Reference
(Loc
,
9956 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9957 Attribute_Name
=> Name_Tag
),
9961 Make_Integer_Literal
(Loc
,
9962 DT_Position
(Entity
(Ename
))))))));
9965 -- Specific actuals for protected to XXX requeue
9967 if Is_Protected_Type
(Old_Typ
) then
9969 Make_Attribute_Reference
(Loc
, -- _object'Address
9971 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9972 Attribute_Name
=> Name_Address
));
9974 Prepend_To
(Params
, -- True
9975 New_Occurrence_Of
(Standard_True
, Loc
));
9977 -- Specific actuals for task to XXX requeue
9980 pragma Assert
(Is_Task_Type
(Old_Typ
));
9982 Prepend_To
(Params
, -- null
9983 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9985 Prepend_To
(Params
, -- False
9986 New_Occurrence_Of
(Standard_False
, Loc
));
9989 -- Add the object parameter
9991 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9994 -- _Disp_Requeue (<Params>);
9996 -- Find entity for Disp_Requeue operation, which belongs to
9997 -- the type and may not be directly visible.
10002 pragma Warnings
(Off
, Op
);
10005 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
10006 while Present
(Elmt
) loop
10008 exit when Chars
(Op
) = Name_uDisp_Requeue
;
10013 Make_Procedure_Call_Statement
(Loc
,
10014 Name
=> New_Occurrence_Of
(Op
, Loc
),
10015 Parameter_Associations
=> Params
);
10017 end Build_Dispatching_Requeue
;
10019 --------------------------------------
10020 -- Build_Dispatching_Requeue_To_Any --
10021 --------------------------------------
10023 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
10024 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
10025 Obj
: constant Node_Id
:= Original_Node
(Concval
);
10026 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
10036 -- Dispatch table slot processing, generate:
10039 S
:= Build_S
(Loc
, Decls
);
10041 -- Call kind processing, generate:
10042 -- C : Ada.Tags.Prim_Op_Kind;
10044 C
:= Build_C
(Loc
, Decls
);
10047 -- S := Ada.Tags.Get_Offset_Index
10048 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10050 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10053 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10056 Make_Procedure_Call_Statement
(Loc
,
10058 New_Occurrence_Of
(
10059 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10060 Name_uDisp_Get_Prim_Op_Kind
),
10062 Parameter_Associations
=> New_List
(
10063 New_Copy_Tree
(Obj
),
10064 New_Occurrence_Of
(S
, Loc
),
10065 New_Occurrence_Of
(C
, Loc
))));
10069 -- if C = POK_Protected_Entry
10070 -- or else C = POK_Task_Entry
10073 Make_Implicit_If_Statement
(N
,
10079 New_Occurrence_Of
(C
, Loc
),
10081 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10086 New_Occurrence_Of
(C
, Loc
),
10088 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10090 -- Dispatching requeue equivalent
10092 Then_Statements
=> New_List
(
10093 Build_Dispatching_Requeue
,
10096 -- elsif C = POK_Protected_Procedure then
10098 Elsif_Parts
=> New_List
(
10099 Make_Elsif_Part
(Loc
,
10103 New_Occurrence_Of
(C
, Loc
),
10105 New_Occurrence_Of
(
10106 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10108 -- Dispatching call equivalent
10110 Then_Statements
=> New_List
(
10111 Build_Dispatching_Call_Equivalent
))),
10114 -- raise Program_Error;
10117 Else_Statements
=> New_List
(
10118 Make_Raise_Program_Error
(Loc
,
10119 Reason
=> PE_Explicit_Raise
))));
10121 -- Wrap everything into a block
10124 Make_Block_Statement
(Loc
,
10125 Declarations
=> Decls
,
10126 Handled_Statement_Sequence
=>
10127 Make_Handled_Sequence_Of_Statements
(Loc
,
10128 Statements
=> Stmts
));
10129 end Build_Dispatching_Requeue_To_Any
;
10131 --------------------------
10132 -- Build_Normal_Requeue --
10133 --------------------------
10135 function Build_Normal_Requeue
return Node_Id
is
10136 Params
: constant List_Id
:= New_List
;
10141 -- Process the "with abort" parameter
10143 Prepend_To
(Params
,
10144 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10146 -- Add the index expression to the parameters. It is common among all
10149 Prepend_To
(Params
,
10150 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10152 if Is_Protected_Type
(Old_Typ
) then
10154 Self_Param
: Node_Id
;
10158 Make_Attribute_Reference
(Loc
,
10160 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10162 Name_Unchecked_Access
);
10164 -- Protected to protected requeue
10166 if Is_Protected_Type
(Conc_Typ
) then
10168 New_Occurrence_Of
(
10169 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10172 Make_Attribute_Reference
(Loc
,
10174 Concurrent_Ref
(Concval
),
10176 Name_Unchecked_Access
);
10178 -- Protected to task requeue
10180 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10182 New_Occurrence_Of
(
10183 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10185 Param
:= Concurrent_Ref
(Concval
);
10188 Prepend_To
(Params
, Param
);
10189 Prepend_To
(Params
, Self_Param
);
10192 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10194 -- Task to protected requeue
10196 if Is_Protected_Type
(Conc_Typ
) then
10198 New_Occurrence_Of
(
10199 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10202 Make_Attribute_Reference
(Loc
,
10204 Concurrent_Ref
(Concval
),
10206 Name_Unchecked_Access
);
10208 -- Task to task requeue
10210 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10212 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10214 Param
:= Concurrent_Ref
(Concval
);
10217 Prepend_To
(Params
, Param
);
10221 Make_Procedure_Call_Statement
(Loc
,
10223 Parameter_Associations
=> Params
);
10224 end Build_Normal_Requeue
;
10226 --------------------------
10227 -- Build_Skip_Statement --
10228 --------------------------
10230 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10231 Skip_Stmt
: Node_Id
;
10234 -- Build a return statement to skip the rest of the entire body
10236 if Is_Protected_Type
(Old_Typ
) then
10237 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10239 -- If the requeue is within a task, find the end label of the
10240 -- enclosing accept statement and create a goto statement to it.
10248 -- Climb the parent chain looking for the enclosing accept
10251 Acc
:= Parent
(Search
);
10252 while Present
(Acc
)
10253 and then Nkind
(Acc
) /= N_Accept_Statement
10255 Acc
:= Parent
(Acc
);
10258 -- The last statement is the second label used for completing
10259 -- the rendezvous the usual way. The label we are looking for
10260 -- is right before it.
10263 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10265 pragma Assert
(Nkind
(Label
) = N_Label
);
10267 -- Generate a goto statement to skip the rest of the accept
10270 Make_Goto_Statement
(Loc
,
10272 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10276 Set_Analyzed
(Skip_Stmt
);
10279 end Build_Skip_Statement
;
10281 -- Start of processing for Expand_N_Requeue_Statement
10284 -- Extract the components of the entry call
10286 Extract_Entry
(N
, Concval
, Ename
, Index
);
10287 Conc_Typ
:= Etype
(Concval
);
10289 -- If the prefix is an access to class-wide type, dereference to get
10290 -- object and entry type.
10292 if Is_Access_Type
(Conc_Typ
) then
10293 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10295 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10296 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10299 -- Examine the scope stack in order to find nearest enclosing protected
10300 -- or task type. This will constitute our invocation source.
10302 Old_Typ
:= Current_Scope
;
10303 while Present
(Old_Typ
)
10304 and then not Is_Protected_Type
(Old_Typ
)
10305 and then not Is_Task_Type
(Old_Typ
)
10307 Old_Typ
:= Scope
(Old_Typ
);
10310 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10311 -- Concval.Ename where the type of Concval is class-wide concurrent
10314 if Ada_Version
>= Ada_2012
10315 and then Present
(Concval
)
10316 and then Is_Class_Wide_Type
(Conc_Typ
)
10317 and then Is_Concurrent_Interface
(Conc_Typ
)
10320 Has_Impl
: Boolean := False;
10321 Impl_Kind
: Name_Id
:= No_Name
;
10324 -- Check whether the Ename is flagged by pragma Implemented
10326 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10328 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10331 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10332 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10334 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10335 Rewrite
(N
, Build_Dispatching_Requeue
);
10337 Insert_After
(N
, Build_Skip_Statement
(N
));
10339 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10340 -- a protected procedure. In this case the requeue is transformed
10341 -- into a dispatching call.
10344 and then Impl_Kind
= Name_By_Protected_Procedure
10346 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10349 -- The procedure_or_entry_NAME's implementation kind is either
10350 -- By_Any, Optional, or pragma Implemented was not applied at all.
10351 -- In this case a runtime test determines whether Ename denotes an
10352 -- entry or a protected procedure and performs the appropriate
10356 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10361 -- Processing for regular (nondispatching) requeues
10364 Rewrite
(N
, Build_Normal_Requeue
);
10366 Insert_After
(N
, Build_Skip_Statement
(N
));
10368 end Expand_N_Requeue_Statement
;
10370 -------------------------------
10371 -- Expand_N_Selective_Accept --
10372 -------------------------------
10374 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10375 Loc
: constant Source_Ptr
:= Sloc
(N
);
10376 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10378 -- Note: in the below declarations a lot of new lists are allocated
10379 -- unconditionally which may well not end up being used. That's not
10380 -- a good idea since it wastes space gratuitously ???
10382 Accept_Case
: List_Id
;
10383 Accept_List
: constant List_Id
:= New_List
;
10386 Alt_List
: constant List_Id
:= New_List
;
10387 Alt_Stats
: List_Id
;
10388 Ann
: Entity_Id
:= Empty
;
10390 Check_Guard
: Boolean := True;
10392 Decls
: constant List_Id
:= New_List
;
10393 Stats
: constant List_Id
:= New_List
;
10394 Body_List
: constant List_Id
:= New_List
;
10395 Trailing_List
: constant List_Id
:= New_List
;
10398 Else_Present
: Boolean := False;
10399 Terminate_Alt
: Node_Id
:= Empty
;
10400 Select_Mode
: Node_Id
;
10402 Delay_Case
: List_Id
;
10403 Delay_Count
: Integer := 0;
10404 Delay_Val
: Entity_Id
;
10405 Delay_Index
: Entity_Id
;
10406 Delay_Min
: Entity_Id
;
10407 Delay_Num
: Pos
:= 1;
10408 Delay_Alt_List
: List_Id
:= New_List
;
10409 Delay_List
: constant List_Id
:= New_List
;
10413 First_Delay
: Boolean := True;
10414 Guard_Open
: Entity_Id
;
10420 Num_Accept
: Nat
:= 0;
10422 Time_Type
: Entity_Id
;
10423 Select_Call
: Node_Id
;
10425 Qnam
: constant Entity_Id
:=
10426 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10428 Xnam
: constant Entity_Id
:=
10429 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10431 -----------------------
10432 -- Local subprograms --
10433 -----------------------
10435 function Accept_Or_Raise
return List_Id
;
10436 -- For the rare case where delay alternatives all have guards, and
10437 -- all of them are closed, it is still possible that there were open
10438 -- accept alternatives with no callers. We must reexamine the
10439 -- Accept_List, and execute a selective wait with no else if some
10440 -- accept is open. If none, we raise program_error.
10442 procedure Add_Accept
(Alt
: Node_Id
);
10443 -- Process a single accept statement in a select alternative. Build
10444 -- procedure for body of accept, and add entry to dispatch table with
10445 -- expression for guard, in preparation for call to run time select.
10447 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10448 -- Manufacture a label using Num as a serial number and declare it.
10449 -- The declaration is appended to Decls. The label marks the trailing
10450 -- statements of an accept or delay alternative.
10452 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10453 -- Build call to Selective_Wait runtime routine
10455 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10456 -- Add code to compare value of delay with previous values, and
10457 -- generate case entry for trailing statements.
10459 procedure Process_Accept_Alternative
10463 -- Add code to call corresponding procedure, and branch to
10464 -- trailing statements, if any.
10466 ---------------------
10467 -- Accept_Or_Raise --
10468 ---------------------
10470 function Accept_Or_Raise
return List_Id
is
10473 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10476 -- We generate the following:
10478 -- for J in q'range loop
10479 -- if q(J).S /=null_task_entry then
10480 -- selective_wait (simple_mode,...);
10486 -- if no rendez_vous then
10487 -- raise program_error;
10490 -- Note that the code needs to know that the selector name
10491 -- in an Accept_Alternative is named S.
10493 Cond
:= Make_Op_Ne
(Loc
,
10495 Make_Selected_Component
(Loc
,
10497 Make_Indexed_Component
(Loc
,
10498 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10499 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10500 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10502 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10504 Stats
:= New_List
(
10505 Make_Implicit_Loop_Statement
(N
,
10506 Iteration_Scheme
=>
10507 Make_Iteration_Scheme
(Loc
,
10508 Loop_Parameter_Specification
=>
10509 Make_Loop_Parameter_Specification
(Loc
,
10510 Defining_Identifier
=> J
,
10511 Discrete_Subtype_Definition
=>
10512 Make_Attribute_Reference
(Loc
,
10513 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10514 Attribute_Name
=> Name_Range
,
10515 Expressions
=> New_List
(
10516 Make_Integer_Literal
(Loc
, 1))))),
10518 Statements
=> New_List
(
10519 Make_Implicit_If_Statement
(N
,
10521 Then_Statements
=> New_List
(
10523 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10524 Make_Exit_Statement
(Loc
))))));
10527 Make_Raise_Program_Error
(Loc
,
10528 Condition
=> Make_Op_Eq
(Loc
,
10529 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10531 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10532 Reason
=> PE_All_Guards_Closed
));
10535 end Accept_Or_Raise
;
10541 procedure Add_Accept
(Alt
: Node_Id
) is
10542 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10543 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10544 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10545 Eent
: constant Entity_Id
:= Entity
(Ename
);
10546 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10547 Null_Body
: Node_Id
;
10548 Proc_Body
: Node_Id
;
10549 PB_Ent
: Entity_Id
;
10555 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10558 if Present
(Condition
(Alt
)) then
10560 Make_If_Expression
(Eloc
, New_List
(
10562 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10563 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10566 Entry_Index_Expression
10567 (Eloc
, Eent
, Index
, Scope
(Eent
));
10570 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10571 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10573 -- Always add call to Abort_Undefer when generating code, since
10574 -- this is what the runtime expects (abort deferred in
10575 -- Selective_Wait). In CodePeer mode this only confuses the
10576 -- analysis with unknown calls, so don't do it.
10578 if not CodePeer_Mode
then
10579 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10581 (First
(Statements
(Handled_Statement_Sequence
10582 (Accept_Statement
(Alt
)))),
10588 Make_Defining_Identifier
(Eloc
,
10589 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10591 -- Link the acceptor to the original receiving entry
10593 Set_Ekind
(PB_Ent
, E_Procedure
);
10594 Set_Receiving_Entry
(PB_Ent
, Eent
);
10596 if Comes_From_Source
(Alt
) then
10597 Set_Debug_Info_Needed
(PB_Ent
);
10601 Make_Subprogram_Body
(Eloc
,
10603 Make_Procedure_Specification
(Eloc
,
10604 Defining_Unit_Name
=> PB_Ent
),
10605 Declarations
=> Declarations
(Acc_Stm
),
10606 Handled_Statement_Sequence
=>
10607 Build_Accept_Body
(Accept_Statement
(Alt
)));
10609 -- During the analysis of the body of the accept statement, any
10610 -- zero cost exception handler records were collected in the
10611 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10612 -- This is where we move them to where they belong, namely the
10613 -- newly created procedure.
10615 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10616 Append
(Proc_Body
, Body_List
);
10619 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10621 -- if accept statement has declarations, insert above, given that
10622 -- we are not creating a body for the accept.
10624 if Present
(Declarations
(Acc_Stm
)) then
10625 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10629 Append_To
(Accept_List
,
10630 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10632 Num_Accept
:= Num_Accept
+ 1;
10635 ----------------------------
10636 -- Make_And_Declare_Label --
10637 ----------------------------
10639 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10643 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10645 Make_Label
(Loc
, Lab_Id
);
10648 Make_Implicit_Label_Declaration
(Loc
,
10649 Defining_Identifier
=>
10650 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10651 Label_Construct
=> Lab
));
10654 end Make_And_Declare_Label
;
10656 ----------------------
10657 -- Make_Select_Call --
10658 ----------------------
10660 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10661 Params
: constant List_Id
:= New_List
;
10665 Make_Attribute_Reference
(Loc
,
10666 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10667 Attribute_Name
=> Name_Unchecked_Access
));
10668 Append_To
(Params
, Select_Mode
);
10669 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10670 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10673 Make_Procedure_Call_Statement
(Loc
,
10674 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10675 Parameter_Associations
=> Params
);
10676 end Make_Select_Call
;
10678 --------------------------------
10679 -- Process_Accept_Alternative --
10680 --------------------------------
10682 procedure Process_Accept_Alternative
10687 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10688 Alt_Stats
: List_Id
;
10691 Adjust_Condition
(Condition
(Alt
));
10693 -- Accept with body
10695 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10698 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10701 (Defining_Unit_Name
(Specification
(Proc
)),
10704 -- Accept with no body (followed by trailing statements)
10707 Alt_Stats
:= Empty_List
;
10710 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10712 -- After the call, if any, branch to trailing statements, if any.
10713 -- We create a label for each, as well as the corresponding label
10716 if not Is_Empty_List
(Statements
(Alt
)) then
10717 Lab
:= Make_And_Declare_Label
(Index
);
10718 Append
(Lab
, Trailing_List
);
10719 Append_List
(Statements
(Alt
), Trailing_List
);
10720 Append_To
(Trailing_List
,
10721 Make_Goto_Statement
(Loc
,
10722 Name
=> New_Copy
(Identifier
(End_Lab
))));
10728 Append_To
(Alt_Stats
,
10729 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10731 Append_To
(Alt_List
,
10732 Make_Case_Statement_Alternative
(Loc
,
10733 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10734 Statements
=> Alt_Stats
));
10735 end Process_Accept_Alternative
;
10737 -------------------------------
10738 -- Process_Delay_Alternative --
10739 -------------------------------
10741 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10742 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10744 Delay_Alt
: List_Id
;
10747 -- Deal with C/Fortran boolean as delay condition
10749 Adjust_Condition
(Condition
(Alt
));
10751 -- Determine the smallest specified delay
10753 -- for each delay alternative generate:
10755 -- if guard-expression then
10756 -- Delay_Val := delay-expression;
10757 -- Guard_Open := True;
10758 -- if Delay_Val < Delay_Min then
10759 -- Delay_Min := Delay_Val;
10760 -- Delay_Index := Index;
10764 -- The enclosing if-statement is omitted if there is no guard
10766 if Delay_Count
= 1 or else First_Delay
then
10767 First_Delay
:= False;
10769 Delay_Alt
:= New_List
(
10770 Make_Assignment_Statement
(Loc
,
10771 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10772 Expression
=> Expression
(Delay_Statement
(Alt
))));
10774 if Delay_Count
> 1 then
10775 Append_To
(Delay_Alt
,
10776 Make_Assignment_Statement
(Loc
,
10777 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10778 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10782 Delay_Alt
:= New_List
(
10783 Make_Assignment_Statement
(Loc
,
10784 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10785 Expression
=> Expression
(Delay_Statement
(Alt
))));
10787 if Time_Type
= Standard_Duration
then
10790 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10791 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10794 -- The scope of the time type must define a comparison
10795 -- operator. The scope itself may not be visible, so we
10796 -- construct a node with entity information to insure that
10797 -- semantic analysis can find the proper operator.
10800 Make_Function_Call
(Loc
,
10801 Name
=> Make_Selected_Component
(Loc
,
10803 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10805 Make_Operator_Symbol
(Loc
,
10806 Chars
=> Name_Op_Lt
,
10807 Strval
=> No_String
)),
10808 Parameter_Associations
=>
10810 New_Occurrence_Of
(Delay_Val
, Loc
),
10811 New_Occurrence_Of
(Delay_Min
, Loc
)));
10813 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10816 Append_To
(Delay_Alt
,
10817 Make_Implicit_If_Statement
(N
,
10819 Then_Statements
=> New_List
(
10820 Make_Assignment_Statement
(Loc
,
10821 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10822 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10824 Make_Assignment_Statement
(Loc
,
10825 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10826 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10829 if Check_Guard
then
10830 Append_To
(Delay_Alt
,
10831 Make_Assignment_Statement
(Loc
,
10832 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10833 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10836 if Present
(Condition
(Alt
)) then
10837 Delay_Alt
:= New_List
(
10838 Make_Implicit_If_Statement
(N
,
10839 Condition
=> Condition
(Alt
),
10840 Then_Statements
=> Delay_Alt
));
10843 Append_List
(Delay_Alt
, Delay_List
);
10845 Ensure_Statement_Present
(Dloc
, Alt
);
10847 -- If the delay alternative has a statement part, add choice to the
10848 -- case statements for delays.
10850 if not Is_Empty_List
(Statements
(Alt
)) then
10852 if Delay_Count
= 1 then
10853 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10856 Append_To
(Delay_Alt_List
,
10857 Make_Case_Statement_Alternative
(Loc
,
10858 Discrete_Choices
=> New_List
(
10859 Make_Integer_Literal
(Loc
, Index
)),
10860 Statements
=> Statements
(Alt
)));
10863 elsif Delay_Count
= 1 then
10865 -- If the single delay has no trailing statements, add a branch
10866 -- to the exit label to the selective wait.
10868 Delay_Alt_List
:= New_List
(
10869 Make_Goto_Statement
(Loc
,
10870 Name
=> New_Copy
(Identifier
(End_Lab
))));
10873 end Process_Delay_Alternative
;
10875 -- Start of processing for Expand_N_Selective_Accept
10878 Process_Statements_For_Controlled_Objects
(N
);
10880 -- First insert some declarations before the select. The first is:
10884 -- This variable holds the parameters passed to the accept body. This
10885 -- declaration has already been inserted by the time we get here by
10886 -- a call to Expand_Accept_Declarations made from the semantics when
10887 -- processing the first accept statement contained in the select. We
10888 -- can find this entity as Accept_Address (E), where E is any of the
10889 -- entries references by contained accept statements.
10891 -- The first step is to scan the list of Selective_Accept_Statements
10892 -- to find this entity, and also count the number of accepts, and
10893 -- determine if terminated, delay or else is present:
10897 Alt
:= First
(Alts
);
10898 while Present
(Alt
) loop
10899 Process_Statements_For_Controlled_Objects
(Alt
);
10901 if Nkind
(Alt
) = N_Accept_Alternative
then
10904 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10905 Delay_Count
:= Delay_Count
+ 1;
10907 -- If the delays are relative delays, the delay expressions have
10908 -- type Standard_Duration. Otherwise they must have some time type
10909 -- recognized by GNAT.
10911 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10912 Time_Type
:= Standard_Duration
;
10914 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10916 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10917 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10922 "& is not a time type (RM 9.6(6))",
10923 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10924 Time_Type
:= Standard_Duration
;
10925 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10929 if No
(Condition
(Alt
)) then
10931 -- This guard will always be open
10933 Check_Guard
:= False;
10936 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10937 Adjust_Condition
(Condition
(Alt
));
10938 Terminate_Alt
:= Alt
;
10941 Num_Alts
:= Num_Alts
+ 1;
10945 Else_Present
:= Present
(Else_Statements
(N
));
10947 -- At the same time (see procedure Add_Accept) we build the accept list:
10949 -- Qnn : Accept_List (1 .. num-select) := (
10950 -- (null-body, entry-index),
10951 -- (null-body, entry-index),
10953 -- (null_body, entry-index));
10955 -- In the above declaration, null-body is True if the corresponding
10956 -- accept has no body, and false otherwise. The entry is either the
10957 -- entry index expression if there is no guard, or if a guard is
10958 -- present, then an if expression of the form:
10960 -- (if guard then entry-index else Null_Task_Entry)
10962 -- If a guard is statically known to be false, the entry can simply
10963 -- be omitted from the accept list.
10966 Make_Object_Declaration
(Loc
,
10967 Defining_Identifier
=> Qnam
,
10968 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10969 Aliased_Present
=> True,
10971 Make_Qualified_Expression
(Loc
,
10973 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10975 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10977 -- Then we declare the variable that holds the index for the accept
10978 -- that will be selected for service:
10980 -- Xnn : Select_Index;
10983 Make_Object_Declaration
(Loc
,
10984 Defining_Identifier
=> Xnam
,
10985 Object_Definition
=>
10986 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10988 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10990 -- After this follow procedure declarations for each accept body
10992 -- procedure Pnn is
10997 -- where the ... are statements from the corresponding procedure body.
10998 -- No parameters are involved, since the parameters are passed via Ann
10999 -- and the parameter references have already been expanded to be direct
11000 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
11001 -- any embedded tasking statements (which would normally be illegal in
11002 -- procedures), have been converted to calls to the tasking runtime so
11003 -- there is no problem in putting them into procedures.
11005 -- The original accept statement has been expanded into a block in
11006 -- the same fashion as for simple accepts (see Build_Accept_Body).
11008 -- Note: we don't really need to build these procedures for the case
11009 -- where no delay statement is present, but it is just as easy to
11010 -- build them unconditionally, and not significantly inefficient,
11011 -- since if they are short they will be inlined anyway.
11013 -- The procedure declarations have been assembled in Body_List
11015 -- If delays are present, we must compute the required delay.
11016 -- We first generate the declarations:
11018 -- Delay_Index : Boolean := 0;
11019 -- Delay_Min : Some_Time_Type.Time;
11020 -- Delay_Val : Some_Time_Type.Time;
11022 -- Delay_Index will be set to the index of the minimum delay, i.e. the
11023 -- active delay that is actually chosen as the basis for the possible
11024 -- delay if an immediate rendez-vous is not possible.
11026 -- In the most common case there is a single delay statement, and this
11027 -- is handled specially.
11029 if Delay_Count
> 0 then
11031 -- Generate the required declarations
11034 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
11036 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
11038 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
11041 Make_Object_Declaration
(Loc
,
11042 Defining_Identifier
=> Delay_Val
,
11043 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
11046 Make_Object_Declaration
(Loc
,
11047 Defining_Identifier
=> Delay_Index
,
11048 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11049 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11052 Make_Object_Declaration
(Loc
,
11053 Defining_Identifier
=> Delay_Min
,
11054 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11056 Unchecked_Convert_To
(Time_Type
,
11057 Make_Attribute_Reference
(Loc
,
11059 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11060 Attribute_Name
=> Name_Last
))));
11062 -- Create Duration and Delay_Mode objects used for passing a delay
11065 D
:= Make_Temporary
(Loc
, 'D');
11066 M
:= Make_Temporary
(Loc
, 'M');
11072 -- Note that these values are defined in s-osprim.ads and must
11073 -- be kept in sync:
11075 -- Relative : constant := 0;
11076 -- Absolute_Calendar : constant := 1;
11077 -- Absolute_RT : constant := 2;
11079 if Time_Type
= Standard_Duration
then
11080 Discr
:= Make_Integer_Literal
(Loc
, 0);
11082 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11083 Discr
:= Make_Integer_Literal
(Loc
, 1);
11087 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11088 Discr
:= Make_Integer_Literal
(Loc
, 2);
11092 Make_Object_Declaration
(Loc
,
11093 Defining_Identifier
=> D
,
11094 Object_Definition
=>
11095 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11098 Make_Object_Declaration
(Loc
,
11099 Defining_Identifier
=> M
,
11100 Object_Definition
=>
11101 New_Occurrence_Of
(Standard_Integer
, Loc
),
11102 Expression
=> Discr
));
11105 if Check_Guard
then
11107 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11110 Make_Object_Declaration
(Loc
,
11111 Defining_Identifier
=> Guard_Open
,
11112 Object_Definition
=>
11113 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11115 New_Occurrence_Of
(Standard_False
, Loc
)));
11118 -- Delay_Count is zero, don't need M and D set (suppress warning)
11125 if Present
(Terminate_Alt
) then
11127 -- If the terminate alternative guard is False, use
11128 -- Simple_Mode; otherwise use Terminate_Mode.
11130 if Present
(Condition
(Terminate_Alt
)) then
11131 Select_Mode
:= Make_If_Expression
(Loc
,
11132 New_List
(Condition
(Terminate_Alt
),
11133 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11134 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11136 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11139 elsif Else_Present
or Delay_Count
> 0 then
11140 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11143 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11146 Select_Call
:= Make_Select_Call
(Select_Mode
);
11147 Append
(Select_Call
, Stats
);
11149 -- Now generate code to act on the result. There is an entry
11150 -- in this case for each accept statement with a non-null body,
11151 -- followed by a branch to the statements that follow the Accept.
11152 -- In the absence of delay alternatives, we generate:
11155 -- when No_Rendezvous => -- omitted if simple mode
11170 -- Lab0: Else_Statements;
11173 -- Lab1: Trailing_Statements1;
11176 -- Lab2: Trailing_Statements2;
11181 -- Generate label for common exit
11183 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11185 -- First entry is the default case, when no rendezvous is possible
11187 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11189 if Else_Present
then
11191 -- If no rendezvous is possible, the else part is executed
11193 Lab
:= Make_And_Declare_Label
(0);
11194 Alt_Stats
:= New_List
(
11195 Make_Goto_Statement
(Loc
,
11196 Name
=> New_Copy
(Identifier
(Lab
))));
11198 Append
(Lab
, Trailing_List
);
11199 Append_List
(Else_Statements
(N
), Trailing_List
);
11200 Append_To
(Trailing_List
,
11201 Make_Goto_Statement
(Loc
,
11202 Name
=> New_Copy
(Identifier
(End_Lab
))));
11204 Alt_Stats
:= New_List
(
11205 Make_Goto_Statement
(Loc
,
11206 Name
=> New_Copy
(Identifier
(End_Lab
))));
11209 Append_To
(Alt_List
,
11210 Make_Case_Statement_Alternative
(Loc
,
11211 Discrete_Choices
=> Choices
,
11212 Statements
=> Alt_Stats
));
11214 -- We make use of the fact that Accept_Index is an integer type, and
11215 -- generate successive literals for entries for each accept. Only those
11216 -- for which there is a body or trailing statements get a case entry.
11218 Alt
:= First
(Select_Alternatives
(N
));
11219 Proc
:= First
(Body_List
);
11220 while Present
(Alt
) loop
11222 if Nkind
(Alt
) = N_Accept_Alternative
then
11223 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11224 Index
:= Index
+ 1;
11227 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11232 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11233 Process_Delay_Alternative
(Alt
, Delay_Num
);
11234 Delay_Num
:= Delay_Num
+ 1;
11240 -- An others choice is always added to the main case, as well
11241 -- as the delay case (to satisfy the compiler).
11243 Append_To
(Alt_List
,
11244 Make_Case_Statement_Alternative
(Loc
,
11245 Discrete_Choices
=>
11246 New_List
(Make_Others_Choice
(Loc
)),
11248 New_List
(Make_Goto_Statement
(Loc
,
11249 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11251 Accept_Case
:= New_List
(
11252 Make_Case_Statement
(Loc
,
11253 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11254 Alternatives
=> Alt_List
));
11256 Append_List
(Trailing_List
, Accept_Case
);
11257 Append_List
(Body_List
, Decls
);
11259 -- Construct case statement for trailing statements of delay
11260 -- alternatives, if there are several of them.
11262 if Delay_Count
> 1 then
11263 Append_To
(Delay_Alt_List
,
11264 Make_Case_Statement_Alternative
(Loc
,
11265 Discrete_Choices
=>
11266 New_List
(Make_Others_Choice
(Loc
)),
11268 New_List
(Make_Null_Statement
(Loc
))));
11270 Delay_Case
:= New_List
(
11271 Make_Case_Statement
(Loc
,
11272 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11273 Alternatives
=> Delay_Alt_List
));
11275 Delay_Case
:= Delay_Alt_List
;
11278 -- If there are no delay alternatives, we append the case statement
11279 -- to the statement list.
11281 if Delay_Count
= 0 then
11282 Append_List
(Accept_Case
, Stats
);
11284 -- Delay alternatives present
11287 -- If delay alternatives are present we generate:
11289 -- find minimum delay.
11290 -- DX := minimum delay;
11291 -- M := <delay mode>;
11292 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11295 -- if X = No_Rendezvous then
11296 -- case statement for delay statements.
11298 -- case statement for accept alternatives.
11309 -- The type of the delay expression is known to be legal
11311 if Time_Type
= Standard_Duration
then
11312 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11314 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11315 Conv
:= Make_Function_Call
(Loc
,
11316 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11317 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11321 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11323 Conv
:= Make_Function_Call
(Loc
,
11324 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11325 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11328 Stmt
:= Make_Assignment_Statement
(Loc
,
11329 Name
=> New_Occurrence_Of
(D
, Loc
),
11330 Expression
=> Conv
);
11332 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11334 Parms
:= Parameter_Associations
(Select_Call
);
11336 Parm
:= First
(Parms
);
11337 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11341 pragma Assert
(Present
(Parm
));
11342 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11345 -- Prepare two new parameters of Duration and Delay_Mode type
11346 -- which represent the value and the mode of the minimum delay.
11349 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11350 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11352 -- Create a call to RTS
11354 Rewrite
(Select_Call
,
11355 Make_Procedure_Call_Statement
(Loc
,
11356 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11357 Parameter_Associations
=> Parms
));
11359 -- This new call should follow the calculation of the minimum
11362 Insert_List_Before
(Select_Call
, Delay_List
);
11364 if Check_Guard
then
11366 Make_Implicit_If_Statement
(N
,
11367 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11368 Then_Statements
=> New_List
(
11369 New_Copy_Tree
(Stmt
),
11370 New_Copy_Tree
(Select_Call
)),
11371 Else_Statements
=> Accept_Or_Raise
);
11372 Rewrite
(Select_Call
, Stmt
);
11374 Insert_Before
(Select_Call
, Stmt
);
11378 Make_Implicit_If_Statement
(N
,
11379 Condition
=> Make_Op_Eq
(Loc
,
11380 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11382 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11384 Then_Statements
=> Delay_Case
,
11385 Else_Statements
=> Accept_Case
);
11387 Append
(Cases
, Stats
);
11391 Append
(End_Lab
, Stats
);
11393 -- Replace accept statement with appropriate block
11396 Make_Block_Statement
(Loc
,
11397 Declarations
=> Decls
,
11398 Handled_Statement_Sequence
=>
11399 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11402 -- Note: have to worry more about abort deferral in above code ???
11404 -- Final step is to unstack the Accept_Address entries for all accept
11405 -- statements appearing in accept alternatives in the select statement
11407 Alt
:= First
(Alts
);
11408 while Present
(Alt
) loop
11409 if Nkind
(Alt
) = N_Accept_Alternative
then
11410 Remove_Last_Elmt
(Accept_Address
11411 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11416 end Expand_N_Selective_Accept
;
11418 -------------------------------------------
11419 -- Expand_N_Single_Protected_Declaration --
11420 -------------------------------------------
11422 -- A single protected declaration should never be present after semantic
11423 -- analysis because it is transformed into a protected type declaration
11424 -- and an accompanying anonymous object. This routine ensures that the
11425 -- transformation takes place.
11427 procedure Expand_N_Single_Protected_Declaration
(N
: Node_Id
) is
11429 raise Program_Error
;
11430 end Expand_N_Single_Protected_Declaration
;
11432 --------------------------------------
11433 -- Expand_N_Single_Task_Declaration --
11434 --------------------------------------
11436 -- A single task declaration should never be present after semantic
11437 -- analysis because it is transformed into a task type declaration and
11438 -- an accompanying anonymous object. This routine ensures that the
11439 -- transformation takes place.
11441 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11443 raise Program_Error
;
11444 end Expand_N_Single_Task_Declaration
;
11446 ------------------------
11447 -- Expand_N_Task_Body --
11448 ------------------------
11450 -- Given a task body
11452 -- task body tname is
11458 -- This expansion routine converts it into a procedure and sets the
11459 -- elaboration flag for the procedure to true, to represent the fact
11460 -- that the task body is now elaborated:
11462 -- procedure tnameB (_Task : access tnameV) is
11463 -- discriminal : dtype renames _Task.discriminant;
11465 -- procedure _clean is
11467 -- Abort_Defer.all;
11469 -- Abort_Undefer.all;
11474 -- Abort_Undefer.all;
11476 -- System.Task_Stages.Complete_Activation;
11484 -- In addition, if the task body is an activator, then a call to activate
11485 -- tasks is added at the start of the statements, before the call to
11486 -- Complete_Activation, and if in addition the task is a master then it
11487 -- must be established as a master. These calls are inserted and analyzed
11488 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11491 -- There is one discriminal declaration line generated for each
11492 -- discriminant that is present to provide an easy reference point for
11493 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11495 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11496 -- task body procedures have a profile (Arg : System.Address). That is
11497 -- needed because GNARLI has to use the same access-to-subprogram type
11498 -- for all task types. We depend here on knowing that in GNAT, passing
11499 -- an address argument by value is identical to passing a record value
11500 -- by access (in either case a single pointer is passed), so even though
11501 -- this procedure has the wrong profile. In fact it's all OK, since the
11502 -- callings sequence is identical.
11504 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11505 Loc
: constant Source_Ptr
:= Sloc
(N
);
11506 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11510 Insert_Nod
: Node_Id
;
11511 -- Used to determine the proper location of wrapper body insertions
11514 -- if no task body procedure, means we had an error in configurable
11515 -- run-time mode, and there is no point in proceeding further.
11517 if No
(Task_Body_Procedure
(Ttyp
)) then
11521 -- Add renaming declarations for discriminals and a declaration for the
11522 -- entry family index (if applicable).
11524 Install_Private_Data_Declarations
11525 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11527 -- Add a call to Abort_Undefer at the very beginning of the task
11528 -- body since this body is called with abort still deferred.
11530 if Abort_Allowed
then
11531 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11533 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11537 -- The statement part has already been protected with an at_end and
11538 -- cleanup actions. The call to Complete_Activation must be placed
11539 -- at the head of the sequence of statements of that block. The
11540 -- declarations have been merged in this sequence of statements but
11541 -- the first real statement is accessible from the First_Real_Statement
11542 -- field (which was set for exactly this purpose).
11544 if Restricted_Profile
then
11545 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11547 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11551 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11555 Make_Subprogram_Body
(Loc
,
11556 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11557 Declarations
=> Declarations
(N
),
11558 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11559 Set_Is_Task_Body_Procedure
(New_N
);
11561 -- If the task contains generic instantiations, cleanup actions are
11562 -- delayed until after instantiation. Transfer the activation chain to
11563 -- the subprogram, to insure that the activation call is properly
11564 -- generated. It the task body contains inner tasks, indicate that the
11565 -- subprogram is a task master.
11567 if Delay_Cleanups
(Ttyp
) then
11568 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11569 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11572 Rewrite
(N
, New_N
);
11575 -- Set elaboration flag immediately after task body. If the body is a
11576 -- subunit, the flag is set in the declarative part containing the stub.
11578 if Nkind
(Parent
(N
)) /= N_Subunit
then
11580 Make_Assignment_Statement
(Loc
,
11582 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11583 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11586 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11587 -- the task body. At this point all wrapper specs have been created,
11588 -- frozen and included in the dispatch table for the task type.
11590 if Ada_Version
>= Ada_2005
then
11591 if Nkind
(Parent
(N
)) = N_Subunit
then
11592 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11597 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11599 end Expand_N_Task_Body
;
11601 ------------------------------------
11602 -- Expand_N_Task_Type_Declaration --
11603 ------------------------------------
11605 -- We have several things to do. First we must create a Boolean flag used
11606 -- to mark if the body is elaborated yet. This variable gets set to True
11607 -- when the body of the task is elaborated (we can't rely on the normal
11608 -- ABE mechanism for the task body, since we need to pass an access to
11609 -- this elaboration boolean to the runtime routines).
11611 -- taskE : aliased Boolean := False;
11613 -- Next a variable is declared to hold the task stack size (either the
11614 -- default : Unspecified_Size, or a value that is set by a pragma
11615 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11616 -- the variable is initialized with this value:
11618 -- taskZ : Size_Type := Unspecified_Size;
11620 -- taskZ : Size_Type := Size_Type (size_expression);
11622 -- Note: No variable is needed to hold the task relative deadline since
11623 -- its value would never be static because the parameter is of a private
11624 -- type (Ada.Real_Time.Time_Span).
11626 -- Next we create a corresponding record type declaration used to represent
11627 -- values of this task. The general form of this type declaration is
11629 -- type taskV (discriminants) is record
11630 -- _Task_Id : Task_Id;
11631 -- entry_family : array (bounds) of Void;
11632 -- _Priority : Integer := priority_expression;
11633 -- _Size : Size_Type := size_expression;
11634 -- _Secondary_Stack_Size : Size_Type := size_expression;
11635 -- _Task_Info : Task_Info_Type := task_info_expression;
11636 -- _CPU : Integer := cpu_range_expression;
11637 -- _Relative_Deadline : Time_Span := time_span_expression;
11638 -- _Domain : Dispatching_Domain := dd_expression;
11641 -- The discriminants are present only if the corresponding task type has
11642 -- discriminants, and they exactly mirror the task type discriminants.
11644 -- The Id field is always present. It contains the Task_Id value, as set by
11645 -- the call to Create_Task. Note that although the task is limited, the
11646 -- task value record type is not limited, so there is no problem in passing
11647 -- this field as an out parameter to Create_Task.
11649 -- One entry_family component is present for each entry family in the task
11650 -- definition. The bounds correspond to the bounds of the entry family
11651 -- (which may depend on discriminants). The element type is void, since we
11652 -- only need the bounds information for determining the entry index. Note
11653 -- that the use of an anonymous array would normally be illegal in this
11654 -- context, but this is a parser check, and the semantics is quite prepared
11655 -- to handle such a case.
11657 -- The _Size field is present only if a Storage_Size pragma appears in the
11658 -- task definition. The expression captures the argument that was present
11659 -- in the pragma, and is used to override the task stack size otherwise
11660 -- associated with the task type.
11662 -- The _Secondary_Stack_Size field is present only the task entity has a
11663 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11664 -- when the record init proc is built, to capture the expression of the
11665 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11666 -- be filled here since aspect evaluations are delayed till the freeze
11669 -- The _Priority field is present only if the task entity has a Priority or
11670 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11671 -- definition clause). It will be filled at the freeze point, when the
11672 -- record init proc is built, to capture the expression of the rep item
11673 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11674 -- here since aspect evaluations are delayed till the freeze point.
11676 -- The _Task_Info field is present only if a Task_Info pragma appears in
11677 -- the task definition. The expression captures the argument that was
11678 -- present in the pragma, and is used to provide the Task_Image parameter
11679 -- to the call to Create_Task.
11681 -- The _CPU field is present only if the task entity has a CPU rep item
11682 -- (pragma, aspect specification or attribute definition clause). It will
11683 -- be filled at the freeze point, when the record init proc is built, to
11684 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11685 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11686 -- are delayed till the freeze point.
11688 -- The _Relative_Deadline field is present only if a Relative_Deadline
11689 -- pragma appears in the task definition. The expression captures the
11690 -- argument that was present in the pragma, and is used to provide the
11691 -- Relative_Deadline parameter to the call to Create_Task.
11693 -- The _Domain field is present only if the task entity has a
11694 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11695 -- definition clause). It will be filled at the freeze point, when the
11696 -- record init proc is built, to capture the expression of the rep item
11697 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11698 -- here since aspect evaluations are delayed till the freeze point.
11700 -- When a task is declared, an instance of the task value record is
11701 -- created. The elaboration of this declaration creates the correct bounds
11702 -- for the entry families, and also evaluates the size, priority, and
11703 -- task_Info expressions if needed. The initialization routine for the task
11704 -- type itself then calls Create_Task with appropriate parameters to
11705 -- initialize the value of the Task_Id field.
11707 -- Note: the address of this record is passed as the "Discriminants"
11708 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11709 -- body procedure, it does not matter that it does not quite match the
11710 -- GNARLI model of what is being passed (the record contains more than just
11711 -- the discriminants, but the discriminants can be found from the record
11714 -- The Entity_Id for this created record type is placed in the
11715 -- Corresponding_Record_Type field of the associated task type entity.
11717 -- Next we create a procedure specification for the task body procedure:
11719 -- procedure taskB (_Task : access taskV);
11721 -- Note that this must come after the record type declaration, since
11722 -- the spec refers to this type. It turns out that the initialization
11723 -- procedure for the value type references the task body spec, but that's
11724 -- fine, since it won't be generated till the freeze point for the type,
11725 -- which is certainly after the task body spec declaration.
11727 -- Finally, we set the task index value field of the entry attribute in
11728 -- the case of a simple entry.
11730 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11731 Loc
: constant Source_Ptr
:= Sloc
(N
);
11732 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11733 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11734 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11735 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11737 Body_Decl
: Node_Id
;
11739 Decl_Stack
: Node_Id
;
11741 Elab_Decl
: Node_Id
;
11742 Ent_Stack
: Entity_Id
;
11743 Proc_Spec
: Node_Id
;
11744 Rec_Decl
: Node_Id
;
11745 Rec_Ent
: Entity_Id
;
11746 Size_Decl
: Entity_Id
;
11747 Task_Size
: Node_Id
;
11749 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11750 -- Searches the task definition T for the first occurrence of the pragma
11751 -- Relative Deadline. The caller has ensured that the pragma is present
11752 -- in the task definition. Note that this routine cannot be implemented
11753 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11754 -- not chained because their expansion into a procedure call statement
11755 -- would cause a break in the chain.
11757 ----------------------------------
11758 -- Get_Relative_Deadline_Pragma --
11759 ----------------------------------
11761 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11765 N
:= First
(Visible_Declarations
(T
));
11766 while Present
(N
) loop
11767 if Nkind
(N
) = N_Pragma
11768 and then Pragma_Name
(N
) = Name_Relative_Deadline
11776 N
:= First
(Private_Declarations
(T
));
11777 while Present
(N
) loop
11778 if Nkind
(N
) = N_Pragma
11779 and then Pragma_Name
(N
) = Name_Relative_Deadline
11787 raise Program_Error
;
11788 end Get_Relative_Deadline_Pragma
;
11790 -- Start of processing for Expand_N_Task_Type_Declaration
11793 -- If already expanded, nothing to do
11795 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11799 -- Here we will do the expansion
11801 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11803 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11804 Cdecls
:= Component_Items
(Component_List
11805 (Type_Definition
(Rec_Decl
)));
11807 Qualify_Entity_Names
(N
);
11809 -- First create the elaboration variable
11812 Make_Object_Declaration
(Loc
,
11813 Defining_Identifier
=>
11814 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11815 Chars
=> New_External_Name
(Tasknm
, 'E')),
11816 Aliased_Present
=> True,
11817 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11818 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11820 Insert_After
(N
, Elab_Decl
);
11822 -- Next create the declaration of the size variable (tasknmZ)
11824 Set_Storage_Size_Variable
(Tasktyp
,
11825 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11826 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11828 if Present
(Taskdef
)
11829 and then Has_Storage_Size_Pragma
(Taskdef
)
11831 Is_OK_Static_Expression
11833 (First
(Pragma_Argument_Associations
11834 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11837 Make_Object_Declaration
(Loc
,
11838 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11839 Object_Definition
=>
11840 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11842 Convert_To
(RTE
(RE_Size_Type
),
11844 (Expression
(First
(Pragma_Argument_Associations
11846 (TaskId
, Name_Storage_Size
)))))));
11850 Make_Object_Declaration
(Loc
,
11851 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11852 Object_Definition
=>
11853 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11855 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11858 Insert_After
(Elab_Decl
, Size_Decl
);
11860 -- Next build the rest of the corresponding record declaration. This is
11861 -- done last, since the corresponding record initialization procedure
11862 -- will reference the previously created entities.
11864 -- Fill in the component declarations -- first the _Task_Id field
11867 Make_Component_Declaration
(Loc
,
11868 Defining_Identifier
=>
11869 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11870 Component_Definition
=>
11871 Make_Component_Definition
(Loc
,
11872 Aliased_Present
=> False,
11873 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11876 -- Declare static ATCB (that is, created by the expander) if we are
11877 -- using the Restricted run time.
11879 if Restricted_Profile
then
11881 Make_Component_Declaration
(Loc
,
11882 Defining_Identifier
=>
11883 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11885 Component_Definition
=>
11886 Make_Component_Definition
(Loc
,
11887 Aliased_Present
=> True,
11888 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11890 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11893 Make_Index_Or_Discriminant_Constraint
(Loc
,
11895 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11899 -- Declare static stack (that is, created by the expander) if we are
11900 -- using the Restricted run time on a bare board configuration.
11902 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11904 -- First we need to extract the appropriate stack size
11906 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11908 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11910 Expr_N
: constant Node_Id
:=
11911 Expression
(First
(
11912 Pragma_Argument_Associations
(
11913 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11914 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11915 P
: constant Node_Id
:= Parent
(Expr_N
);
11918 -- The stack is defined inside the corresponding record.
11919 -- Therefore if the size of the stack is set by means of
11920 -- a discriminant, we must reference the discriminant of the
11921 -- corresponding record type.
11923 if Nkind
(Expr_N
) in N_Has_Entity
11924 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11928 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11930 Set_Parent
(Task_Size
, P
);
11931 Set_Etype
(Task_Size
, Etyp
);
11932 Set_Analyzed
(Task_Size
);
11935 Task_Size
:= New_Copy_Tree
(Expr_N
);
11941 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11944 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11945 Defining_Identifier
=> Ent_Stack
,
11947 Component_Definition
=>
11948 Make_Component_Definition
(Loc
,
11949 Aliased_Present
=> True,
11950 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11952 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11955 Make_Index_Or_Discriminant_Constraint
(Loc
,
11956 Constraints
=> New_List
(Make_Range
(Loc
,
11957 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11958 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11961 Append_To
(Cdecls
, Decl_Stack
);
11963 -- The appropriate alignment for the stack is ensured by the run-time
11964 -- code in charge of task creation.
11968 -- Declare a static secondary stack if the conditions for a statically
11969 -- generated stack are met.
11971 if Create_Secondary_Stack_For_Task
(TaskId
) then
11973 Size_Expr
: constant Node_Id
:=
11974 Expression
(First
(
11975 Pragma_Argument_Associations
(
11976 Get_Rep_Pragma
(TaskId
,
11977 Name_Secondary_Stack_Size
))));
11979 Stack_Size
: Node_Id
;
11982 -- The secondary stack is defined inside the corresponding
11983 -- record. Therefore if the size of the stack is set by means
11984 -- of a discriminant, we must reference the discriminant of the
11985 -- corresponding record type.
11987 if Nkind
(Size_Expr
) in N_Has_Entity
11988 and then Present
(Discriminal_Link
(Entity
(Size_Expr
)))
11992 (CR_Discriminant
(Discriminal_Link
(Entity
(Size_Expr
))),
11994 Set_Parent
(Stack_Size
, Parent
(Size_Expr
));
11995 Set_Etype
(Stack_Size
, Etype
(Size_Expr
));
11996 Set_Analyzed
(Stack_Size
);
11999 Stack_Size
:= New_Copy_Tree
(Size_Expr
);
12002 -- Create the secondary stack for the task
12005 Make_Component_Declaration
(Loc
,
12006 Defining_Identifier
=>
12007 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack
),
12008 Component_Definition
=>
12009 Make_Component_Definition
(Loc
,
12010 Aliased_Present
=> True,
12011 Subtype_Indication
=>
12012 Make_Subtype_Indication
(Loc
,
12014 New_Occurrence_Of
(RTE
(RE_SS_Stack
), Loc
),
12016 Make_Index_Or_Discriminant_Constraint
(Loc
,
12017 Constraints
=> New_List
(
12018 Convert_To
(RTE
(RE_Size_Type
),
12021 Append_To
(Cdecls
, Decl_SS
);
12025 -- Add components for entry families
12027 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
12029 -- Add the _Priority component if a Interrupt_Priority or Priority rep
12030 -- item is present.
12032 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
12034 Make_Component_Declaration
(Loc
,
12035 Defining_Identifier
=>
12036 Make_Defining_Identifier
(Loc
, Name_uPriority
),
12037 Component_Definition
=>
12038 Make_Component_Definition
(Loc
,
12039 Aliased_Present
=> False,
12040 Subtype_Indication
=>
12041 New_Occurrence_Of
(Standard_Integer
, Loc
))));
12044 -- Add the _Size component if a Storage_Size pragma is present
12046 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
12048 Make_Component_Declaration
(Loc
,
12049 Defining_Identifier
=>
12050 Make_Defining_Identifier
(Loc
, Name_uSize
),
12052 Component_Definition
=>
12053 Make_Component_Definition
(Loc
,
12054 Aliased_Present
=> False,
12055 Subtype_Indication
=>
12056 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
12059 Convert_To
(RTE
(RE_Size_Type
),
12061 Expression
(First
(
12062 Pragma_Argument_Associations
(
12063 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
12066 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
12067 -- pragma is present.
12070 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
12073 Make_Component_Declaration
(Loc
,
12074 Defining_Identifier
=>
12075 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack_Size
),
12077 Component_Definition
=>
12078 Make_Component_Definition
(Loc
,
12079 Aliased_Present
=> False,
12080 Subtype_Indication
=>
12081 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
))));
12084 -- Add the _Task_Info component if a Task_Info pragma is present
12086 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
12088 Make_Component_Declaration
(Loc
,
12089 Defining_Identifier
=>
12090 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
12092 Component_Definition
=>
12093 Make_Component_Definition
(Loc
,
12094 Aliased_Present
=> False,
12095 Subtype_Indication
=>
12096 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
12098 Expression
=> New_Copy
(
12099 Expression
(First
(
12100 Pragma_Argument_Associations
(
12102 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
12105 -- Add the _CPU component if a CPU rep item is present
12107 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
12109 Make_Component_Declaration
(Loc
,
12110 Defining_Identifier
=>
12111 Make_Defining_Identifier
(Loc
, Name_uCPU
),
12113 Component_Definition
=>
12114 Make_Component_Definition
(Loc
,
12115 Aliased_Present
=> False,
12116 Subtype_Indication
=>
12117 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
12120 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
12121 -- present. If we are using a restricted run time this component will
12122 -- not be added (deadlines are not allowed by the Ravenscar profile),
12123 -- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
12126 if (not Restricted_Profile
or else Task_Dispatching_Policy
= 'E')
12127 and then Present
(Taskdef
)
12128 and then Has_Relative_Deadline_Pragma
(Taskdef
)
12131 Make_Component_Declaration
(Loc
,
12132 Defining_Identifier
=>
12133 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
12135 Component_Definition
=>
12136 Make_Component_Definition
(Loc
,
12137 Aliased_Present
=> False,
12138 Subtype_Indication
=>
12139 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
12142 Convert_To
(RTE
(RE_Time_Span
),
12144 Expression
(First
(
12145 Pragma_Argument_Associations
(
12146 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12149 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12150 -- item is present. If we are using a restricted run time this component
12151 -- will not be added (dispatching domains are not allowed by the
12152 -- Ravenscar profile).
12154 if not Restricted_Profile
12157 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12160 Make_Component_Declaration
(Loc
,
12161 Defining_Identifier
=>
12162 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12164 Component_Definition
=>
12165 Make_Component_Definition
(Loc
,
12166 Aliased_Present
=> False,
12167 Subtype_Indication
=>
12169 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12172 Insert_After
(Size_Decl
, Rec_Decl
);
12174 -- Analyze the record declaration immediately after construction,
12175 -- because the initialization procedure is needed for single task
12176 -- declarations before the next entity is analyzed.
12178 Analyze
(Rec_Decl
);
12180 -- Create the declaration of the task body procedure
12182 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12184 Make_Subprogram_Declaration
(Loc
,
12185 Specification
=> Proc_Spec
);
12186 Set_Is_Task_Body_Procedure
(Body_Decl
);
12188 Insert_After
(Rec_Decl
, Body_Decl
);
12190 -- The subprogram does not comes from source, so we have to indicate the
12191 -- need for debugging information explicitly.
12193 if Comes_From_Source
(Original_Node
(N
)) then
12194 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12197 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12198 -- the corresponding record has been frozen.
12200 if Ada_Version
>= Ada_2005
then
12201 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12204 -- Ada 2005 (AI-345): We must defer freezing to allow further
12205 -- declaration of primitive subprograms covering task interfaces
12207 if Ada_Version
<= Ada_95
then
12209 -- Now we can freeze the corresponding record. This needs manually
12210 -- freezing, since it is really part of the task type, and the task
12211 -- type is frozen at this stage. We of course need the initialization
12212 -- procedure for this corresponding record type and we won't get it
12213 -- in time if we don't freeze now.
12216 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
12218 if Is_Non_Empty_List
(L
) then
12219 Insert_List_After
(Body_Decl
, L
);
12224 -- Complete the expansion of access types to the current task type, if
12225 -- any were declared.
12227 Expand_Previous_Access_Type
(Tasktyp
);
12229 -- Create wrappers for entries that have contract cases, preconditions
12230 -- and postconditions.
12236 Ent
:= First_Entity
(Tasktyp
);
12237 while Present
(Ent
) loop
12238 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
) then
12239 Build_Contract_Wrapper
(Ent
, N
);
12245 end Expand_N_Task_Type_Declaration
;
12247 -------------------------------
12248 -- Expand_N_Timed_Entry_Call --
12249 -------------------------------
12251 -- A timed entry call in normal case is not implemented using ATC mechanism
12252 -- anymore for efficiency reason.
12262 -- is expanded as follows:
12264 -- 1) When T.E is a task entry_call;
12268 -- X : Task_Entry_Index := <entry index>;
12269 -- DX : Duration := To_Duration (D);
12270 -- M : Delay_Mode := <discriminant>;
12271 -- P : parms := (parm, parm, parm);
12274 -- Timed_Protected_Entry_Call
12275 -- (<acceptor-task>, X, P'Address, DX, M, B);
12283 -- 2) When T.E is a protected entry_call;
12287 -- X : Protected_Entry_Index := <entry index>;
12288 -- DX : Duration := To_Duration (D);
12289 -- M : Delay_Mode := <discriminant>;
12290 -- P : parms := (parm, parm, parm);
12293 -- Timed_Protected_Entry_Call
12294 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12302 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12303 -- is no delay and the triggering statements are executed. We first
12304 -- determine the kind of the triggering call and then execute a
12305 -- synchronized operation or a direct call.
12308 -- B : Boolean := False;
12309 -- C : Ada.Tags.Prim_Op_Kind;
12310 -- DX : Duration := To_Duration (D)
12311 -- K : Ada.Tags.Tagged_Kind :=
12312 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12313 -- M : Integer :=...;
12314 -- P : Parameters := (Param1 .. ParamN);
12318 -- if K = Ada.Tags.TK_Limited_Tagged
12319 -- or else K = Ada.Tags.TK_Tagged
12321 -- <dispatching-call>;
12326 -- Ada.Tags.Get_Offset_Index
12327 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12329 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12331 -- if C = POK_Protected_Entry
12332 -- or else C = POK_Task_Entry
12334 -- Param1 := P.Param1;
12336 -- ParamN := P.ParamN;
12340 -- if C = POK_Procedure
12341 -- or else C = POK_Protected_Procedure
12342 -- or else C = POK_Task_Procedure
12344 -- <dispatching-call>;
12350 -- <triggering-statements>
12352 -- <timed-statements>
12356 -- The triggering statement and the sequence of timed statements have not
12357 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12358 -- global references if within an instantiation.
12360 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12361 Loc
: constant Source_Ptr
:= Sloc
(N
);
12364 Blk_Typ
: Entity_Id
;
12366 Call_Ent
: Entity_Id
;
12367 Conc_Typ_Stmts
: List_Id
;
12368 Concval
: Node_Id
:= Empty
; -- init to avoid warning
12369 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12372 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12374 D_Type
: Entity_Id
;
12377 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12378 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12383 Is_Disp_Select
: Boolean;
12384 Lim_Typ_Stmts
: List_Id
;
12393 B
: Entity_Id
; -- Call status flag
12394 C
: Entity_Id
; -- Call kind
12395 D
: Entity_Id
; -- Delay
12396 K
: Entity_Id
; -- Tagged kind
12397 M
: Entity_Id
; -- Delay mode
12398 P
: Entity_Id
; -- Parameter block
12399 S
: Entity_Id
; -- Primitive operation slot
12401 -- Start of processing for Expand_N_Timed_Entry_Call
12404 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12405 -- was already reported on spec, so do not attempt to expand the call.
12407 if Restriction_Active
(No_Select_Statements
) then
12411 Process_Statements_For_Controlled_Objects
(E_Alt
);
12412 Process_Statements_For_Controlled_Objects
(D_Alt
);
12414 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12416 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12417 -- may wrap them in blocks.
12419 E_Stats
:= Statements
(E_Alt
);
12420 D_Stats
:= Statements
(D_Alt
);
12422 -- The arguments in the call may require dynamic allocation, and the
12423 -- call statement may have been transformed into a block. The block
12424 -- may contain additional declarations for internal entities, and the
12425 -- original call is found by sequential search.
12427 if Nkind
(E_Call
) = N_Block_Statement
then
12428 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12429 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12430 N_Entry_Call_Statement
)
12437 Ada_Version
>= Ada_2005
12438 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12440 if Is_Disp_Select
then
12441 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12447 -- B : Boolean := False;
12449 B
:= Build_B
(Loc
, Decls
);
12452 -- C : Ada.Tags.Prim_Op_Kind;
12454 C
:= Build_C
(Loc
, Decls
);
12456 -- Because the analysis of all statements was disabled, manually
12457 -- analyze the delay statement.
12460 D_Stat
:= Original_Node
(D_Stat
);
12463 -- Build an entry call using Simple_Entry_Call
12465 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12466 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12468 Decls
:= Declarations
(E_Call
);
12469 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12478 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12481 Make_Object_Declaration
(Loc
,
12482 Defining_Identifier
=> B
,
12483 Object_Definition
=>
12484 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12487 -- Duration and mode processing
12489 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12491 -- Use the type of the delay expression (Calendar or Real_Time) to
12492 -- generate the appropriate conversion.
12494 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12495 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12496 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12498 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12499 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12501 Make_Function_Call
(Loc
,
12502 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12503 Parameter_Associations
=>
12504 New_List
(New_Copy
(Expression
(D_Stat
))));
12506 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12507 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12509 Make_Function_Call
(Loc
,
12510 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12511 Parameter_Associations
=>
12512 New_List
(New_Copy
(Expression
(D_Stat
))));
12515 D
:= Make_Temporary
(Loc
, 'D');
12521 Make_Object_Declaration
(Loc
,
12522 Defining_Identifier
=> D
,
12523 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12525 M
:= Make_Temporary
(Loc
, 'M');
12528 -- M : Integer := (0 | 1 | 2);
12531 Make_Object_Declaration
(Loc
,
12532 Defining_Identifier
=> M
,
12533 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12534 Expression
=> D_Disc
));
12536 -- Do the assignment at this stage only because the evaluation of the
12537 -- expression must not occur before (see ACVC C97302A).
12540 Make_Assignment_Statement
(Loc
,
12541 Name
=> New_Occurrence_Of
(D
, Loc
),
12542 Expression
=> D_Conv
));
12544 -- Parameter block processing
12546 -- Manually create the parameter block for dispatching calls. In the
12547 -- case of entries, the block has already been created during the call
12548 -- to Build_Simple_Entry_Call.
12550 if Is_Disp_Select
then
12552 -- Tagged kind processing, generate:
12553 -- K : Ada.Tags.Tagged_Kind :=
12554 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12556 K
:= Build_K
(Loc
, Decls
, Obj
);
12558 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12560 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12562 -- Dispatch table slot processing, generate:
12565 S
:= Build_S
(Loc
, Decls
);
12568 -- S := Ada.Tags.Get_Offset_Index
12569 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12572 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12575 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12577 -- where Obj is the controlling formal parameter, S is the dispatch
12578 -- table slot number of the dispatching operation, P is the wrapped
12579 -- parameter block, D is the duration, M is the duration mode, C is
12580 -- the call kind and B is the call status.
12582 Params
:= New_List
;
12584 Append_To
(Params
, New_Copy_Tree
(Obj
));
12585 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12587 Make_Attribute_Reference
(Loc
,
12588 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12589 Attribute_Name
=> Name_Address
));
12590 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12591 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12592 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12593 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12595 Append_To
(Conc_Typ_Stmts
,
12596 Make_Procedure_Call_Statement
(Loc
,
12600 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12601 Parameter_Associations
=> Params
));
12604 -- if C = POK_Protected_Entry
12605 -- or else C = POK_Task_Entry
12607 -- Param1 := P.Param1;
12609 -- ParamN := P.ParamN;
12612 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12614 -- Generate the if statement only when the packed parameters need
12615 -- explicit assignments to their corresponding actuals.
12617 if Present
(Unpack
) then
12618 Append_To
(Conc_Typ_Stmts
,
12619 Make_Implicit_If_Statement
(N
,
12625 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12628 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12632 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12634 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12636 Then_Statements
=> Unpack
));
12642 -- if C = POK_Procedure
12643 -- or else C = POK_Protected_Procedure
12644 -- or else C = POK_Task_Procedure
12646 -- <dispatching-call>
12650 N_Stats
:= New_List
(
12651 Make_Implicit_If_Statement
(N
,
12656 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12658 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12664 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12666 New_Occurrence_Of
(RTE
(
12667 RE_POK_Protected_Procedure
), Loc
)),
12670 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12673 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12675 Then_Statements
=> New_List
(E_Call
)));
12677 Append_To
(Conc_Typ_Stmts
,
12678 Make_Implicit_If_Statement
(N
,
12679 Condition
=> New_Occurrence_Of
(B
, Loc
),
12680 Then_Statements
=> N_Stats
));
12683 -- <dispatching-call>;
12687 New_List
(New_Copy_Tree
(E_Call
),
12688 Make_Assignment_Statement
(Loc
,
12689 Name
=> New_Occurrence_Of
(B
, Loc
),
12690 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12693 -- if K = Ada.Tags.TK_Limited_Tagged
12694 -- or else K = Ada.Tags.TK_Tagged
12702 Make_Implicit_If_Statement
(N
,
12703 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12704 Then_Statements
=> Lim_Typ_Stmts
,
12705 Else_Statements
=> Conc_Typ_Stmts
));
12710 -- <triggering-statements>
12712 -- <timed-statements>
12716 Make_Implicit_If_Statement
(N
,
12717 Condition
=> New_Occurrence_Of
(B
, Loc
),
12718 Then_Statements
=> E_Stats
,
12719 Else_Statements
=> D_Stats
));
12722 -- Simple case of a nondispatching trigger. Skip assignments to
12723 -- temporaries created for in-out parameters.
12725 -- This makes unwarranted assumptions about the shape of the expanded
12726 -- tree for the call, and should be cleaned up ???
12728 Stmt
:= First
(Stmts
);
12729 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12733 -- Do the assignment at this stage only because the evaluation
12734 -- of the expression must not occur before (see ACVC C97302A).
12736 Insert_Before
(Stmt
,
12737 Make_Assignment_Statement
(Loc
,
12738 Name
=> New_Occurrence_Of
(D
, Loc
),
12739 Expression
=> D_Conv
));
12742 Params
:= Parameter_Associations
(Call
);
12744 -- For a protected type, we build a Timed_Protected_Entry_Call
12746 if Is_Protected_Type
(Etype
(Concval
)) then
12748 -- Create a new call statement
12750 Param
:= First
(Params
);
12751 while Present
(Param
)
12752 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12757 Dummy
:= Remove_Next
(Next
(Param
));
12759 -- Remove garbage is following the Cancel_Param if present
12761 Dummy
:= Next
(Param
);
12763 -- Remove the mode of the Protected_Entry_Call call, then remove
12764 -- the Communication_Block of the Protected_Entry_Call call, and
12765 -- finally add Duration and a Delay_Mode parameter
12767 pragma Assert
(Present
(Param
));
12768 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12770 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12772 -- Add a Boolean flag for successful entry call
12774 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12776 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12777 when System_Tasking_Protected_Objects_Entries
=>
12779 Make_Procedure_Call_Statement
(Loc
,
12782 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12783 Parameter_Associations
=> Params
));
12786 raise Program_Error
;
12789 -- For the task case, build a Timed_Task_Entry_Call
12792 -- Create a new call statement
12794 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12795 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12796 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12799 Make_Procedure_Call_Statement
(Loc
,
12801 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12802 Parameter_Associations
=> Params
));
12806 Make_Implicit_If_Statement
(N
,
12807 Condition
=> New_Occurrence_Of
(B
, Loc
),
12808 Then_Statements
=> E_Stats
,
12809 Else_Statements
=> D_Stats
));
12813 Make_Block_Statement
(Loc
,
12814 Declarations
=> Decls
,
12815 Handled_Statement_Sequence
=>
12816 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12819 end Expand_N_Timed_Entry_Call
;
12821 ----------------------------------------
12822 -- Expand_Protected_Body_Declarations --
12823 ----------------------------------------
12825 procedure Expand_Protected_Body_Declarations
12827 Spec_Id
: Entity_Id
)
12830 if No_Run_Time_Mode
then
12831 Error_Msg_CRT
("protected body", N
);
12834 elsif Expander_Active
then
12836 -- Associate discriminals with the first subprogram or entry body to
12839 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12840 Set_Discriminals
(Parent
(Spec_Id
));
12843 end Expand_Protected_Body_Declarations
;
12845 -------------------------
12846 -- External_Subprogram --
12847 -------------------------
12849 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12850 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12853 -- The internal and external subprograms follow each other on the entity
12854 -- chain. Note that previously private operations had no separate
12855 -- external subprogram. We now create one in all cases, because a
12856 -- private operation may actually appear in an external call, through
12857 -- a 'Access reference used for a callback.
12859 -- If the operation is a function that returns an anonymous access type,
12860 -- the corresponding itype appears before the operation, and must be
12863 -- This mechanism is fragile, there should be a real link between the
12864 -- two versions of the operation, but there is no place to put it ???
12866 if Is_Access_Type
(Next_Entity
(Subp
)) then
12867 return Next_Entity
(Next_Entity
(Subp
));
12869 return Next_Entity
(Subp
);
12871 end External_Subprogram
;
12873 ------------------------------
12874 -- Extract_Dispatching_Call --
12875 ------------------------------
12877 procedure Extract_Dispatching_Call
12879 Call_Ent
: out Entity_Id
;
12880 Object
: out Entity_Id
;
12881 Actuals
: out List_Id
;
12882 Formals
: out List_Id
)
12884 Call_Nam
: Node_Id
;
12887 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12889 if Present
(Original_Node
(N
)) then
12890 Call_Nam
:= Name
(Original_Node
(N
));
12892 Call_Nam
:= Name
(N
);
12895 -- Retrieve the name of the dispatching procedure. It contains the
12896 -- dispatch table slot number.
12899 case Nkind
(Call_Nam
) is
12900 when N_Identifier
=>
12903 when N_Selected_Component
=>
12904 Call_Nam
:= Selector_Name
(Call_Nam
);
12907 raise Program_Error
;
12911 Actuals
:= Parameter_Associations
(N
);
12912 Call_Ent
:= Entity
(Call_Nam
);
12913 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12914 Object
:= First
(Actuals
);
12916 if Present
(Original_Node
(Object
)) then
12917 Object
:= Original_Node
(Object
);
12920 -- If the type of the dispatching object is an access type then return
12921 -- an explicit dereference of a copy of the object, and note that this
12922 -- is the controlling actual of the call.
12924 if Is_Access_Type
(Etype
(Object
)) then
12926 Make_Explicit_Dereference
(Sloc
(N
), New_Copy_Tree
(Object
));
12928 Set_Is_Controlling_Actual
(Object
);
12930 end Extract_Dispatching_Call
;
12932 -------------------
12933 -- Extract_Entry --
12934 -------------------
12936 procedure Extract_Entry
12938 Concval
: out Node_Id
;
12939 Ename
: out Node_Id
;
12940 Index
: out Node_Id
)
12942 Nam
: constant Node_Id
:= Name
(N
);
12945 -- For a simple entry, the name is a selected component, with the
12946 -- prefix being the task value, and the selector being the entry.
12948 if Nkind
(Nam
) = N_Selected_Component
then
12949 Concval
:= Prefix
(Nam
);
12950 Ename
:= Selector_Name
(Nam
);
12953 -- For a member of an entry family, the name is an indexed component
12954 -- where the prefix is a selected component, whose prefix in turn is
12955 -- the task value, and whose selector is the entry family. The single
12956 -- expression in the expressions list of the indexed component is the
12957 -- subscript for the family.
12959 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12960 Concval
:= Prefix
(Prefix
(Nam
));
12961 Ename
:= Selector_Name
(Prefix
(Nam
));
12962 Index
:= First
(Expressions
(Nam
));
12965 -- Through indirection, the type may actually be a limited view of a
12966 -- concurrent type. When compiling a call, the non-limited view of the
12967 -- type is visible.
12969 if From_Limited_With
(Etype
(Concval
)) then
12970 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12974 -------------------
12975 -- Family_Offset --
12976 -------------------
12978 function Family_Offset
12983 Cap
: Boolean) return Node_Id
12989 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12990 -- If one of the bounds is a reference to a discriminant, replace with
12991 -- corresponding discriminal of type. Within the body of a task retrieve
12992 -- the renamed discriminant by simple visibility, using its generated
12993 -- name. Within a protected object, find the original discriminant and
12994 -- replace it with the discriminal of the current protected operation.
12996 ------------------------------
12997 -- Convert_Discriminant_Ref --
12998 ------------------------------
13000 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
13001 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
13006 if Is_Entity_Name
(Bound
)
13007 and then Ekind
(Entity
(Bound
)) = E_Discriminant
13009 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
13010 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13011 Find_Direct_Name
(B
);
13013 elsif Is_Protected_Type
(Ttyp
) then
13014 D
:= First_Discriminant
(Ttyp
);
13015 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
13016 Next_Discriminant
(D
);
13019 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
13022 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
13025 elsif Nkind
(Bound
) = N_Attribute_Reference
then
13029 B
:= New_Copy_Tree
(Bound
);
13033 Make_Attribute_Reference
(Loc
,
13034 Attribute_Name
=> Name_Pos
,
13035 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
13036 Expressions
=> New_List
(B
));
13037 end Convert_Discriminant_Ref
;
13039 -- Start of processing for Family_Offset
13042 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
13043 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
13046 if Is_Task_Type
(Ttyp
) then
13047 Ityp
:= RTE
(RE_Task_Entry_Index
);
13049 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13053 Make_Attribute_Reference
(Loc
,
13054 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13055 Attribute_Name
=> Name_Min
,
13056 Expressions
=> New_List
(
13058 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
13061 Make_Attribute_Reference
(Loc
,
13062 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13063 Attribute_Name
=> Name_Max
,
13064 Expressions
=> New_List
(
13066 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
13069 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
13076 function Family_Size
13081 Cap
: Boolean) return Node_Id
13086 if Is_Task_Type
(Ttyp
) then
13087 Ityp
:= RTE
(RE_Task_Entry_Index
);
13089 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13093 Make_Attribute_Reference
(Loc
,
13094 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13095 Attribute_Name
=> Name_Max
,
13096 Expressions
=> New_List
(
13098 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
13099 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
13100 Make_Integer_Literal
(Loc
, 0)));
13103 ----------------------------
13104 -- Find_Enclosing_Context --
13105 ----------------------------
13107 procedure Find_Enclosing_Context
13109 Context
: out Node_Id
;
13110 Context_Id
: out Entity_Id
;
13111 Context_Decls
: out List_Id
)
13114 -- Traverse the parent chain looking for an enclosing body, block,
13115 -- package or return statement.
13117 Context
:= Parent
(N
);
13118 while Present
(Context
) loop
13119 if Nkind_In
(Context
, N_Entry_Body
,
13120 N_Extended_Return_Statement
,
13122 N_Package_Declaration
,
13128 -- Do not consider block created to protect a list of statements with
13129 -- an Abort_Defer / Abort_Undefer_Direct pair.
13131 elsif Nkind
(Context
) = N_Block_Statement
13132 and then not Is_Abort_Block
(Context
)
13137 Context
:= Parent
(Context
);
13140 pragma Assert
(Present
(Context
));
13142 -- Extract the constituents of the context
13144 if Nkind
(Context
) = N_Extended_Return_Statement
then
13145 Context_Decls
:= Return_Object_Declarations
(Context
);
13146 Context_Id
:= Return_Statement_Entity
(Context
);
13148 -- Package declarations and bodies use a common library-level activation
13149 -- chain or task master, therefore return the package declaration as the
13150 -- proper carrier for the appropriate flag.
13152 elsif Nkind
(Context
) = N_Package_Body
then
13153 Context_Decls
:= Declarations
(Context
);
13154 Context_Id
:= Corresponding_Spec
(Context
);
13155 Context
:= Parent
(Context_Id
);
13157 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13158 Context
:= Parent
(Parent
(Context
));
13160 Context
:= Parent
(Context
);
13163 elsif Nkind
(Context
) = N_Package_Declaration
then
13164 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13165 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13167 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13168 Context_Id
:= Defining_Identifier
(Context_Id
);
13172 if Nkind
(Context
) = N_Block_Statement
then
13173 Context_Id
:= Entity
(Identifier
(Context
));
13175 elsif Nkind
(Context
) = N_Entry_Body
then
13176 Context_Id
:= Defining_Identifier
(Context
);
13178 elsif Nkind
(Context
) = N_Subprogram_Body
then
13179 if Present
(Corresponding_Spec
(Context
)) then
13180 Context_Id
:= Corresponding_Spec
(Context
);
13182 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13184 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13185 Context_Id
:= Defining_Identifier
(Context_Id
);
13189 elsif Nkind
(Context
) = N_Task_Body
then
13190 Context_Id
:= Corresponding_Spec
(Context
);
13193 raise Program_Error
;
13196 Context_Decls
:= Declarations
(Context
);
13199 pragma Assert
(Present
(Context_Id
));
13200 pragma Assert
(Present
(Context_Decls
));
13201 end Find_Enclosing_Context
;
13203 -----------------------
13204 -- Find_Master_Scope --
13205 -----------------------
13207 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13211 -- In Ada 2005, the master is the innermost enclosing scope that is not
13212 -- transient. If the enclosing block is the rewriting of a call or the
13213 -- scope is an extended return statement this is valid master. The
13214 -- master in an extended return is only used within the return, and is
13215 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13216 -- now before that overwriting occurs.
13220 if Ada_Version
>= Ada_2005
then
13221 while Is_Internal
(S
) loop
13222 if Nkind
(Parent
(S
)) = N_Block_Statement
13224 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
13228 elsif Ekind
(S
) = E_Return_Statement
then
13238 end Find_Master_Scope
;
13240 -------------------------------
13241 -- First_Protected_Operation --
13242 -------------------------------
13244 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13245 First_Op
: Node_Id
;
13248 First_Op
:= First
(D
);
13249 while Present
(First_Op
)
13250 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
13256 end First_Protected_Operation
;
13258 ---------------------------------------
13259 -- Install_Private_Data_Declarations --
13260 ---------------------------------------
13262 procedure Install_Private_Data_Declarations
13264 Spec_Id
: Entity_Id
;
13265 Conc_Typ
: Entity_Id
;
13266 Body_Nod
: Node_Id
;
13268 Barrier
: Boolean := False;
13269 Family
: Boolean := False)
13271 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13274 Insert_Node
: Node_Id
:= Empty
;
13275 Obj_Ent
: Entity_Id
;
13277 procedure Add
(Decl
: Node_Id
);
13278 -- Add a single declaration after Insert_Node. If this is the first
13279 -- addition, Decl is added to the front of Decls and it becomes the
13282 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13283 -- The bounds of an entry index may depend on discriminants, create a
13284 -- reference to the corresponding prival. Otherwise return a duplicate
13285 -- of the original bound.
13291 procedure Add
(Decl
: Node_Id
) is
13293 if No
(Insert_Node
) then
13294 Prepend_To
(Decls
, Decl
);
13296 Insert_After
(Insert_Node
, Decl
);
13299 Insert_Node
:= Decl
;
13302 -------------------
13303 -- Replace_Bound --
13304 -------------------
13306 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13308 if Nkind
(Bound
) = N_Identifier
13309 and then Is_Discriminal
(Entity
(Bound
))
13311 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13313 return Duplicate_Subexpr
(Bound
);
13317 -- Start of processing for Install_Private_Data_Declarations
13320 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13321 -- formal parameter _O, _object or _task depending on the context.
13323 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13325 -- Special processing of _O for barrier functions, protected entries
13332 (Ekind
(Spec_Id
) = E_Entry
13333 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13336 Conc_Rec
: constant Entity_Id
:=
13337 Corresponding_Record_Type
(Conc_Typ
);
13338 Typ_Id
: constant Entity_Id
:=
13339 Make_Defining_Identifier
(Loc
,
13340 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13343 -- type prot_typVP is access prot_typV;
13346 Make_Full_Type_Declaration
(Loc
,
13347 Defining_Identifier
=> Typ_Id
,
13349 Make_Access_To_Object_Definition
(Loc
,
13350 Subtype_Indication
=>
13351 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13355 -- _object : prot_typVP := prot_typV (_O);
13358 Make_Object_Declaration
(Loc
,
13359 Defining_Identifier
=>
13360 Make_Defining_Identifier
(Loc
, Name_uObject
),
13361 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13363 Unchecked_Convert_To
(Typ_Id
,
13364 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13367 -- Set the reference to the concurrent object
13369 Obj_Ent
:= Defining_Identifier
(Decl
);
13373 -- Step 2: Create the Protection object and build its declaration for
13374 -- any protected entry (family) of subprogram. Note for the lock-free
13375 -- implementation, the Protection object is not needed anymore.
13377 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13379 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13383 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13385 -- Determine the proper protection type
13387 if Has_Attach_Handler
(Conc_Typ
)
13388 and then not Restricted_Profile
13390 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13392 elsif Has_Interrupt_Handler
(Conc_Typ
)
13393 and then not Restriction_Active
(No_Dynamic_Attachment
)
13395 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13398 case Corresponding_Runtime_Package
(Conc_Typ
) is
13399 when System_Tasking_Protected_Objects_Entries
=>
13400 Prot_Typ
:= RE_Protection_Entries
;
13402 when System_Tasking_Protected_Objects_Single_Entry
=>
13403 Prot_Typ
:= RE_Protection_Entry
;
13405 when System_Tasking_Protected_Objects
=>
13406 Prot_Typ
:= RE_Protection
;
13409 raise Program_Error
;
13414 -- conc_typR : protection_typ renames _object._object;
13417 Make_Object_Renaming_Declaration
(Loc
,
13418 Defining_Identifier
=> Prot_Ent
,
13420 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13422 Make_Selected_Component
(Loc
,
13423 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13424 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13429 -- Step 3: Add discriminant renamings (if any)
13431 if Has_Discriminants
(Conc_Typ
) then
13436 D
:= First_Discriminant
(Conc_Typ
);
13437 while Present
(D
) loop
13439 -- Adjust the source location
13441 Set_Sloc
(Discriminal
(D
), Loc
);
13444 -- discr_name : discr_typ renames _object.discr_name;
13446 -- discr_name : discr_typ renames _task.discr_name;
13449 Make_Object_Renaming_Declaration
(Loc
,
13450 Defining_Identifier
=> Discriminal
(D
),
13451 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13453 Make_Selected_Component
(Loc
,
13454 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13455 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13458 -- Set debug info needed on this renaming declaration even
13459 -- though it does not come from source, so that the debugger
13460 -- will get the right information for these generated names.
13462 Set_Debug_Info_Needed
(Discriminal
(D
));
13464 Next_Discriminant
(D
);
13469 -- Step 4: Add private component renamings (if any)
13471 if Is_Protected
then
13472 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13474 if Present
(Private_Declarations
(Def
)) then
13477 Comp_Id
: Entity_Id
;
13478 Decl_Id
: Entity_Id
;
13481 Comp
:= First
(Private_Declarations
(Def
));
13482 while Present
(Comp
) loop
13483 if Nkind
(Comp
) = N_Component_Declaration
then
13484 Comp_Id
:= Defining_Identifier
(Comp
);
13486 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13488 -- Minimal decoration
13490 if Ekind
(Spec_Id
) = E_Function
then
13491 Set_Ekind
(Decl_Id
, E_Constant
);
13493 Set_Ekind
(Decl_Id
, E_Variable
);
13496 Set_Prival
(Comp_Id
, Decl_Id
);
13497 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13498 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13501 -- comp_name : comp_typ renames _object.comp_name;
13504 Make_Object_Renaming_Declaration
(Loc
,
13505 Defining_Identifier
=> Decl_Id
,
13507 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13509 Make_Selected_Component
(Loc
,
13511 New_Occurrence_Of
(Obj_Ent
, Loc
),
13513 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13523 -- Step 5: Add the declaration of the entry index and the associated
13524 -- type for barrier functions and entry families.
13526 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13528 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13529 Index
: constant Entity_Id
:=
13530 Defining_Identifier
13531 (Entry_Index_Specification
13532 (Entry_Body_Formal_Part
(Body_Nod
)));
13533 Index_Con
: constant Entity_Id
:=
13534 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13536 Index_Typ
: Entity_Id
;
13540 -- Minimal decoration
13542 Set_Ekind
(Index_Con
, E_Constant
);
13543 Set_Entry_Index_Constant
(Index
, Index_Con
);
13544 Set_Discriminal_Link
(Index_Con
, Index
);
13546 -- Retrieve the bounds of the entry family
13548 High
:= Type_High_Bound
(Etype
(Index
));
13549 Low
:= Type_Low_Bound
(Etype
(Index
));
13551 -- In the simple case the entry family is given by a subtype mark
13552 -- and the index constant has the same type.
13554 if Is_Entity_Name
(Original_Node
(
13555 Discrete_Subtype_Definition
(Parent
(Index
))))
13557 Index_Typ
:= Etype
(Index
);
13559 -- Otherwise a new subtype declaration is required
13562 High
:= Replace_Bound
(High
);
13563 Low
:= Replace_Bound
(Low
);
13565 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13568 -- subtype Jnn is <Etype of Index> range Low .. High;
13571 Make_Subtype_Declaration
(Loc
,
13572 Defining_Identifier
=> Index_Typ
,
13573 Subtype_Indication
=>
13574 Make_Subtype_Indication
(Loc
,
13576 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13578 Make_Range_Constraint
(Loc
,
13579 Range_Expression
=>
13580 Make_Range
(Loc
, Low
, High
))));
13584 Set_Etype
(Index_Con
, Index_Typ
);
13586 -- Create the object which designates the index:
13587 -- J : constant Jnn :=
13588 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13590 -- where Jnn is the subtype created above or the original type of
13591 -- the index, _E is a formal of the protected body subprogram and
13592 -- <index expr> is the index of the first family member.
13595 Make_Object_Declaration
(Loc
,
13596 Defining_Identifier
=> Index_Con
,
13597 Constant_Present
=> True,
13598 Object_Definition
=>
13599 New_Occurrence_Of
(Index_Typ
, Loc
),
13602 Make_Attribute_Reference
(Loc
,
13604 New_Occurrence_Of
(Index_Typ
, Loc
),
13605 Attribute_Name
=> Name_Val
,
13607 Expressions
=> New_List
(
13611 Make_Op_Subtract
(Loc
,
13612 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13614 Entry_Index_Expression
(Loc
,
13615 Defining_Identifier
(Body_Nod
),
13619 Make_Attribute_Reference
(Loc
,
13621 New_Occurrence_Of
(Index_Typ
, Loc
),
13622 Attribute_Name
=> Name_Pos
,
13623 Expressions
=> New_List
(
13624 Make_Attribute_Reference
(Loc
,
13626 New_Occurrence_Of
(Index_Typ
, Loc
),
13627 Attribute_Name
=> Name_First
)))))));
13631 end Install_Private_Data_Declarations
;
13633 ---------------------------------
13634 -- Is_Potentially_Large_Family --
13635 ---------------------------------
13637 function Is_Potentially_Large_Family
13638 (Base_Index
: Entity_Id
;
13639 Conctyp
: Entity_Id
;
13641 Hi
: Node_Id
) return Boolean
13644 return Scope
(Base_Index
) = Standard_Standard
13645 and then Base_Index
= Base_Type
(Standard_Integer
)
13646 and then Has_Discriminants
(Conctyp
)
13648 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13650 (Denotes_Discriminant
(Lo
, True)
13652 Denotes_Discriminant
(Hi
, True));
13653 end Is_Potentially_Large_Family
;
13655 -------------------------------------
13656 -- Is_Private_Primitive_Subprogram --
13657 -------------------------------------
13659 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13662 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13663 and then Is_Private_Primitive
(Id
);
13664 end Is_Private_Primitive_Subprogram
;
13670 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13671 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13672 Formal
: Entity_Id
;
13675 Formal
:= First_Formal
(Bod_Subp
);
13676 while Present
(Formal
) loop
13678 -- Look for formal parameter _E
13680 if Chars
(Formal
) = Name_uE
then
13684 Next_Formal
(Formal
);
13687 -- A protected body subprogram should always have the parameter in
13690 raise Program_Error
;
13693 --------------------------------
13694 -- Make_Initialize_Protection --
13695 --------------------------------
13697 function Make_Initialize_Protection
13698 (Protect_Rec
: Entity_Id
) return List_Id
13700 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13703 Ptyp
: constant Node_Id
:=
13704 Corresponding_Concurrent_Type
(Protect_Rec
);
13706 L
: constant List_Id
:= New_List
;
13707 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13708 Prio_Type
: Entity_Id
;
13709 Prio_Var
: Entity_Id
:= Empty
;
13710 Restricted
: constant Boolean := Restricted_Profile
;
13713 -- We may need two calls to properly initialize the object, one to
13714 -- Initialize_Protection, and possibly one to Install_Handlers if we
13715 -- have a pragma Attach_Handler.
13717 -- Get protected declaration. In the case of a task type declaration,
13718 -- this is simply the parent of the protected type entity. In the single
13719 -- protected object declaration, this parent will be the implicit type,
13720 -- and we can find the corresponding single protected object declaration
13721 -- by searching forward in the declaration list in the tree.
13723 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13724 -- of this type should have been removed during semantic analysis.
13726 Pdec
:= Parent
(Ptyp
);
13727 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13728 N_Single_Protected_Declaration
)
13733 -- Build the parameter list for the call. Note that _Init is the name
13734 -- of the formal for the object to be initialized, which is the task
13735 -- value record itself.
13739 -- For lock-free implementation, skip initializations of the Protection
13742 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13744 -- Object parameter. This is a pointer to the object of type
13745 -- Protection used by the GNARL to control the protected object.
13748 Make_Attribute_Reference
(Loc
,
13750 Make_Selected_Component
(Loc
,
13751 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13752 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13753 Attribute_Name
=> Name_Unchecked_Access
));
13755 -- Priority parameter. Set to Unspecified_Priority unless there is a
13756 -- Priority rep item, in which case we take the value from the pragma
13757 -- or attribute definition clause, or there is an Interrupt_Priority
13758 -- rep item and no Priority rep item, and we set the ceiling to
13759 -- Interrupt_Priority'Last, an implementation-defined value, see
13762 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13764 Prio_Clause
: constant Node_Id
:=
13766 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13773 if Nkind
(Prio_Clause
) = N_Pragma
then
13776 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13778 -- Get_Rep_Item returns either priority pragma
13780 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13781 Prio_Type
:= RTE
(RE_Any_Priority
);
13783 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13786 -- Attribute definition clause Priority
13789 if Chars
(Prio_Clause
) = Name_Priority
then
13790 Prio_Type
:= RTE
(RE_Any_Priority
);
13792 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13795 Prio
:= Expression
(Prio_Clause
);
13798 -- Always create a locale variable to capture the priority.
13799 -- The priority is also passed to Install_Restriced_Handlers.
13800 -- Note that it is really necessary to create this variable
13801 -- explicitly. It might be thought that removing side effects
13802 -- would the appropriate approach, but that could generate
13803 -- declarations improperly placed in the enclosing scope.
13805 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13807 Make_Object_Declaration
(Loc
,
13808 Defining_Identifier
=> Prio_Var
,
13809 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13810 Expression
=> Relocate_Node
(Prio
)));
13812 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13815 -- When no priority is specified but an xx_Handler pragma is, we
13816 -- default to System.Interrupts.Default_Interrupt_Priority, see
13819 elsif Has_Attach_Handler
(Ptyp
)
13820 or else Has_Interrupt_Handler
(Ptyp
)
13823 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13825 -- Normal case, no priority or xx_Handler specified, default priority
13829 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13832 -- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
13834 if Restricted_Profile
and Task_Dispatching_Policy
= 'E' then
13835 Deadline_Floor
: declare
13836 Item
: constant Node_Id
:=
13838 (Ptyp
, Name_Deadline_Floor
, Check_Parents
=> False);
13840 Deadline
: Node_Id
;
13843 if Present
(Item
) then
13845 -- Pragma Deadline_Floor
13847 if Nkind
(Item
) = N_Pragma
then
13850 (First
(Pragma_Argument_Associations
(Item
)));
13852 -- Attribute definition clause Deadline_Floor
13856 (Nkind
(Item
) = N_Attribute_Definition_Clause
);
13858 Deadline
:= Expression
(Item
);
13861 Append_To
(Args
, Deadline
);
13863 -- Unusual case: default deadline
13867 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
13869 end Deadline_Floor
;
13872 -- Test for Compiler_Info parameter. This parameter allows entry body
13873 -- procedures and barrier functions to be called from the runtime. It
13874 -- is a pointer to the record generated by the compiler to represent
13875 -- the protected object.
13877 -- A protected type without entries that covers an interface and
13878 -- overrides the abstract routines with protected procedures is
13879 -- considered equivalent to a protected type with entries in the
13880 -- context of dispatching select statements.
13882 -- Protected types with interrupt handlers (when not using a
13883 -- restricted profile) are also considered equivalent to protected
13884 -- types with entries.
13886 -- The types which are used (Static_Interrupt_Protection and
13887 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13890 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13892 Called_Subp
: RE_Id
;
13896 when System_Tasking_Protected_Objects_Entries
=>
13897 Called_Subp
:= RE_Initialize_Protection_Entries
;
13899 -- Argument Compiler_Info
13902 Make_Attribute_Reference
(Loc
,
13903 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13904 Attribute_Name
=> Name_Address
));
13906 when System_Tasking_Protected_Objects_Single_Entry
=>
13907 Called_Subp
:= RE_Initialize_Protection_Entry
;
13909 -- Argument Compiler_Info
13912 Make_Attribute_Reference
(Loc
,
13913 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13914 Attribute_Name
=> Name_Address
));
13916 when System_Tasking_Protected_Objects
=>
13917 Called_Subp
:= RE_Initialize_Protection
;
13920 raise Program_Error
;
13923 -- Entry_Queue_Maxes parameter. This is an access to an array of
13924 -- naturals representing the entry queue maximums for each entry
13925 -- in the protected type. Zero represents no max. The access is
13926 -- null if there is no limit for all entries (usual case).
13929 and then Pkg_Id
= System_Tasking_Protected_Objects_Entries
13931 if Present
(Entry_Max_Queue_Lengths_Array
(Ptyp
)) then
13933 Make_Attribute_Reference
(Loc
,
13936 (Entry_Max_Queue_Lengths_Array
(Ptyp
), Loc
),
13937 Attribute_Name
=> Name_Unrestricted_Access
));
13939 Append_To
(Args
, Make_Null
(Loc
));
13942 -- Edge cases exist where entry initialization functions are
13943 -- called, but no entries exist, so null is appended.
13945 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13946 Append_To
(Args
, Make_Null
(Loc
));
13949 -- Entry_Bodies parameter. This is a pointer to an array of
13950 -- pointers to the entry body procedures and barrier functions of
13951 -- the object. If the protected type has no entries this object
13952 -- will not exist, in this case, pass a null (it can happen when
13953 -- there are protected interrupt handlers or interfaces).
13956 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13958 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13959 -- multiple entries).
13962 Make_Attribute_Reference
(Loc
,
13963 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13964 Attribute_Name
=> Name_Unrestricted_Access
));
13966 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13968 -- Find index mapping function (clumsy but ok for now)
13970 while Ekind
(P_Arr
) /= E_Function
loop
13971 Next_Entity
(P_Arr
);
13975 Make_Attribute_Reference
(Loc
,
13976 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13977 Attribute_Name
=> Name_Unrestricted_Access
));
13980 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13982 -- This is the case where we have a protected object with
13983 -- interfaces and no entries, and the single entry restriction
13984 -- is in effect. We pass a null pointer for the entry
13985 -- parameter because there is no actual entry.
13987 Append_To
(Args
, Make_Null
(Loc
));
13989 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13991 -- This is the case where we have a protected object with no
13993 -- - either interrupt handlers with non restricted profile,
13995 -- Note that the types which are used for interrupt handlers
13996 -- (Static/Dynamic_Interrupt_Protection) are derived from
13997 -- Protection_Entries. We pass two null pointers because there
13998 -- is no actual entry, and the initialization procedure needs
13999 -- both Entry_Bodies and Find_Body_Index.
14001 Append_To
(Args
, Make_Null
(Loc
));
14002 Append_To
(Args
, Make_Null
(Loc
));
14006 Make_Procedure_Call_Statement
(Loc
,
14008 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
14009 Parameter_Associations
=> Args
));
14013 if Has_Attach_Handler
(Ptyp
) then
14015 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
14016 -- make the following call:
14018 -- Install_Handlers (_object,
14019 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
14021 -- or, in the case of Ravenscar:
14023 -- Install_Restricted_Handlers
14024 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
14027 Args
: constant List_Id
:= New_List
;
14028 Table
: constant List_Id
:= New_List
;
14029 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
14032 -- Build the Priority parameter (only for ravenscar)
14036 -- Priority comes from a pragma
14038 if Present
(Prio_Var
) then
14039 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
14041 -- Priority is the default one
14046 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
14050 -- Build the Attach_Handler table argument
14052 while Present
(Ritem
) loop
14053 if Nkind
(Ritem
) = N_Pragma
14054 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
14057 Handler
: constant Node_Id
:=
14058 First
(Pragma_Argument_Associations
(Ritem
));
14060 Interrupt
: constant Node_Id
:= Next
(Handler
);
14061 Expr
: constant Node_Id
:= Expression
(Interrupt
);
14065 Make_Aggregate
(Loc
, Expressions
=> New_List
(
14066 Unchecked_Convert_To
14067 (RTE
(RE_System_Interrupt_Id
), Expr
),
14068 Make_Attribute_Reference
(Loc
,
14070 Make_Selected_Component
(Loc
,
14072 Make_Identifier
(Loc
, Name_uInit
),
14074 Duplicate_Subexpr_No_Checks
14075 (Expression
(Handler
))),
14076 Attribute_Name
=> Name_Access
))));
14080 Next_Rep_Item
(Ritem
);
14083 -- Append the table argument we just built
14085 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
14087 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14088 -- call to the statements.
14091 -- Call a simplified version of Install_Handlers to be used
14092 -- when the Ravenscar restrictions are in effect
14093 -- (Install_Restricted_Handlers).
14096 Make_Procedure_Call_Statement
(Loc
,
14099 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
14100 Parameter_Associations
=> Args
));
14103 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
14105 -- First, prepends the _object argument
14108 Make_Attribute_Reference
(Loc
,
14110 Make_Selected_Component
(Loc
,
14111 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14113 Make_Identifier
(Loc
, Name_uObject
)),
14114 Attribute_Name
=> Name_Unchecked_Access
));
14117 -- Then, insert call to Install_Handlers
14120 Make_Procedure_Call_Statement
(Loc
,
14122 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
14123 Parameter_Associations
=> Args
));
14129 end Make_Initialize_Protection
;
14131 ---------------------------
14132 -- Make_Task_Create_Call --
14133 ---------------------------
14135 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
14136 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14146 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14147 Tnam
:= Chars
(Ttyp
);
14149 -- Get task declaration. In the case of a task type declaration, this is
14150 -- simply the parent of the task type entity. In the single task
14151 -- declaration, this parent will be the implicit type, and we can find
14152 -- the corresponding single task declaration by searching forward in the
14153 -- declaration list in the tree.
14155 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14156 -- this type should have been removed during semantic analysis.
14158 Tdec
:= Parent
(Ttyp
);
14159 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
14160 N_Single_Task_Declaration
)
14165 -- Now we can find the task definition from this declaration
14167 Tdef
:= Task_Definition
(Tdec
);
14169 -- Build the parameter list for the call. Note that _Init is the name
14170 -- of the formal for the object to be initialized, which is the task
14171 -- value record itself.
14175 -- Priority parameter. Set to Unspecified_Priority unless there is a
14176 -- Priority rep item, in which case we take the value from the rep item.
14177 -- Not used on Ravenscar_EDF profile.
14179 if not (Restricted_Profile
and then Task_Dispatching_Policy
= 'E') then
14180 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14182 Make_Selected_Component
(Loc
,
14183 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14184 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14187 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14191 -- Optional Stack parameter
14193 if Restricted_Profile
then
14195 -- If the stack has been preallocated by the expander then
14196 -- pass its address. Otherwise, pass a null address.
14198 if Preallocated_Stacks_On_Target
then
14200 Make_Attribute_Reference
(Loc
,
14202 Make_Selected_Component
(Loc
,
14203 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14204 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14205 Attribute_Name
=> Name_Address
));
14209 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14213 -- Size parameter. If no Storage_Size pragma is present, then
14214 -- the size is taken from the taskZ variable for the type, which
14215 -- is either Unspecified_Size, or has been reset by the use of
14216 -- a Storage_Size attribute definition clause. If a pragma is
14217 -- present, then the size is taken from the _Size field of the
14218 -- task value record, which was set from the pragma value.
14220 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14222 Make_Selected_Component
(Loc
,
14223 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14224 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14228 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14231 -- Secondary_Stack parameter used for restricted profiles
14233 if Restricted_Profile
then
14235 -- If the secondary stack has been allocated by the expander then
14236 -- pass its access pointer. Otherwise, pass null.
14238 if Create_Secondary_Stack_For_Task
(Ttyp
) then
14240 Make_Attribute_Reference
(Loc
,
14242 Make_Selected_Component
(Loc
,
14243 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14245 Make_Identifier
(Loc
, Name_uSecondary_Stack
)),
14246 Attribute_Name
=> Name_Unrestricted_Access
));
14249 Append_To
(Args
, Make_Null
(Loc
));
14253 -- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there
14254 -- is a Secondary_Stack_Size pragma, in which case take the value from
14255 -- the pragma. If the restriction No_Secondary_Stack is active then a
14256 -- size of 0 is passed regardless to prevent the allocation of the
14259 if Restriction_Active
(No_Secondary_Stack
) then
14260 Append_To
(Args
, Make_Integer_Literal
(Loc
, 0));
14262 elsif Has_Rep_Pragma
14263 (Ttyp
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
14266 Make_Selected_Component
(Loc
,
14267 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14269 Make_Identifier
(Loc
, Name_uSecondary_Stack_Size
)));
14273 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
14276 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14277 -- Task_Info pragma, in which case we take the value from the pragma.
14279 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14281 Make_Selected_Component
(Loc
,
14282 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14283 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14287 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14290 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14291 -- in which case we take the value from the rep item. The parameter is
14292 -- passed as an Integer because in the case of unspecified CPU the
14293 -- value is not in the range of CPU_Range.
14295 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14297 Convert_To
(Standard_Integer
,
14298 Make_Selected_Component
(Loc
,
14299 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14300 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14303 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14306 if not Restricted_Profile
or else Task_Dispatching_Policy
= 'E' then
14308 -- Deadline parameter. If no Relative_Deadline pragma is present,
14309 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14310 -- the deadline is taken from the _Relative_Deadline field of the
14311 -- task value record, which was set from the pragma value. Note that
14312 -- this parameter must not be generated for the restricted profiles
14313 -- since Ravenscar does not allow deadlines.
14315 -- Case where pragma Relative_Deadline applies: use given value
14317 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14319 Make_Selected_Component
(Loc
,
14320 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14322 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14324 -- No pragma Relative_Deadline apply to the task
14328 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14332 if not Restricted_Profile
then
14334 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14335 -- present, then the dispatching domain is null. If a rep item is
14336 -- present, then the dispatching domain is taken from the
14337 -- _Dispatching_Domain field of the task value record, which was set
14338 -- from the rep item value.
14340 -- Case where Dispatching_Domain rep item applies: use given value
14343 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14346 Make_Selected_Component
(Loc
,
14348 Make_Identifier
(Loc
, Name_uInit
),
14350 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14352 -- No pragma or aspect Dispatching_Domain applies to the task
14355 Append_To
(Args
, Make_Null
(Loc
));
14358 -- Number of entries. This is an expression of the form:
14360 -- n + _Init.a'Length + _Init.a'B'Length + ...
14362 -- where a,b... are the entry family names for the task definition
14365 Build_Entry_Count_Expression
14370 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14372 Append_To
(Args
, Ecount
);
14374 -- Master parameter. This is a reference to the _Master parameter of
14375 -- the initialization procedure, except in the case of the pragma
14376 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14377 -- System.Tasking.Library_Task_Level.
14379 if Restriction_Active
(No_Task_Hierarchy
) = False then
14380 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14383 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14387 -- State parameter. This is a pointer to the task body procedure. The
14388 -- required value is obtained by taking 'Unrestricted_Access of the task
14389 -- body procedure and converting it (with an unchecked conversion) to
14390 -- the type required by the task kernel. For further details, see the
14391 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14392 -- than 'Address in order to avoid creating trampolines.
14395 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14396 Subp_Ptr_Typ
: constant Node_Id
:=
14397 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14398 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14401 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14402 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14404 -- Be sure to freeze a reference to the access-to-subprogram type,
14405 -- otherwise gigi will complain that it's in the wrong scope, because
14406 -- it's actually inside the init procedure for the record type that
14407 -- corresponds to the task type.
14409 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14410 Append_Freeze_Action
(Task_Rec
, Ref
);
14413 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14414 Make_Qualified_Expression
(Loc
,
14415 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14417 Make_Attribute_Reference
(Loc
,
14418 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14419 Attribute_Name
=> Name_Unrestricted_Access
))));
14422 -- Discriminants parameter. This is just the address of the task
14423 -- value record itself (which contains the discriminant values
14426 Make_Attribute_Reference
(Loc
,
14427 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14428 Attribute_Name
=> Name_Address
));
14430 -- Elaborated parameter. This is an access to the elaboration Boolean
14433 Make_Attribute_Reference
(Loc
,
14434 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14435 Attribute_Name
=> Name_Unchecked_Access
));
14437 -- Add Chain parameter (not done for sequential elaboration policy, see
14438 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14440 if Partition_Elaboration_Policy
/= 'S' then
14441 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14444 -- Task name parameter. Take this from the _Task_Id parameter to the
14445 -- init call unless there is a Task_Name pragma, in which case we take
14446 -- the value from the pragma.
14448 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14449 -- Copy expression in full, because it may be dynamic and have
14456 (Pragma_Argument_Associations
14458 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14461 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14464 -- Created_Task parameter. This is the _Task_Id field of the task
14468 Make_Selected_Component
(Loc
,
14469 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14470 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14476 if Restricted_Profile
then
14477 if Partition_Elaboration_Policy
= 'S' then
14478 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14480 Create_RE
:= RE_Create_Restricted_Task
;
14483 Create_RE
:= RE_Create_Task
;
14486 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14490 Make_Procedure_Call_Statement
(Loc
,
14492 Parameter_Associations
=> Args
);
14493 end Make_Task_Create_Call
;
14495 ------------------------------
14496 -- Next_Protected_Operation --
14497 ------------------------------
14499 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14503 -- Check whether there is a subsequent body for a protected operation
14504 -- in the current protected body. In Ada2012 that includes expression
14505 -- functions that are completions.
14507 Next_Op
:= Next
(N
);
14508 while Present
(Next_Op
)
14509 and then not Nkind_In
(Next_Op
,
14510 N_Subprogram_Body
, N_Entry_Body
, N_Expression_Function
)
14516 end Next_Protected_Operation
;
14518 ---------------------
14519 -- Null_Statements --
14520 ---------------------
14522 function Null_Statements
(Stats
: List_Id
) return Boolean is
14526 Stmt
:= First
(Stats
);
14527 while Nkind
(Stmt
) /= N_Empty
14528 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14530 (Nkind
(Stmt
) = N_Pragma
14532 Nam_In
(Pragma_Name_Unmapped
(Stmt
),
14540 return Nkind
(Stmt
) = N_Empty
;
14541 end Null_Statements
;
14543 --------------------------
14544 -- Parameter_Block_Pack --
14545 --------------------------
14547 function Parameter_Block_Pack
14549 Blk_Typ
: Entity_Id
;
14553 Stmts
: List_Id
) return Node_Id
14555 Actual
: Entity_Id
;
14556 Expr
: Node_Id
:= Empty
;
14557 Formal
: Entity_Id
;
14558 Has_Param
: Boolean := False;
14561 Temp_Asn
: Node_Id
;
14562 Temp_Nam
: Node_Id
;
14565 Actual
:= First
(Actuals
);
14566 Formal
:= Defining_Identifier
(First
(Formals
));
14567 Params
:= New_List
;
14568 while Present
(Actual
) loop
14569 if Is_By_Copy_Type
(Etype
(Actual
)) then
14571 -- Jnn : aliased <formal-type>
14573 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14576 Make_Object_Declaration
(Loc
,
14577 Aliased_Present
=> True,
14578 Defining_Identifier
=> Temp_Nam
,
14579 Object_Definition
=>
14580 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14582 -- The object is initialized with an explicit assignment
14583 -- later. Indicate that it does not need an initialization
14584 -- to prevent spurious warnings if the type excludes null.
14586 Set_No_Initialization
(Last
(Decls
));
14588 if Ekind
(Formal
) /= E_Out_Parameter
then
14594 New_Occurrence_Of
(Temp_Nam
, Loc
);
14596 Set_Assignment_OK
(Temp_Asn
);
14599 Make_Assignment_Statement
(Loc
,
14601 Expression
=> New_Copy_Tree
(Actual
)));
14604 -- If the actual is not controlling, generate:
14606 -- Jnn'unchecked_access
14608 -- and add it to aggegate for access to formals. Note that the
14609 -- actual may be by-copy but still be a controlling actual if it
14610 -- is an access to class-wide interface.
14612 if not Is_Controlling_Actual
(Actual
) then
14614 Make_Attribute_Reference
(Loc
,
14615 Attribute_Name
=> Name_Unchecked_Access
,
14616 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14621 -- The controlling parameter is omitted
14624 if not Is_Controlling_Actual
(Actual
) then
14626 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14632 Next_Actual
(Actual
);
14633 Next_Formal_With_Extras
(Formal
);
14637 Expr
:= Make_Aggregate
(Loc
, Params
);
14642 -- J1'unchecked_access;
14643 -- <actual2>'reference;
14646 P
:= Make_Temporary
(Loc
, 'P');
14649 Make_Object_Declaration
(Loc
,
14650 Defining_Identifier
=> P
,
14651 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14652 Expression
=> Expr
));
14655 end Parameter_Block_Pack
;
14657 ----------------------------
14658 -- Parameter_Block_Unpack --
14659 ----------------------------
14661 function Parameter_Block_Unpack
14665 Formals
: List_Id
) return List_Id
14667 Actual
: Entity_Id
;
14669 Formal
: Entity_Id
;
14670 Has_Asnmt
: Boolean := False;
14671 Result
: constant List_Id
:= New_List
;
14674 Actual
:= First
(Actuals
);
14675 Formal
:= Defining_Identifier
(First
(Formals
));
14676 while Present
(Actual
) loop
14677 if Is_By_Copy_Type
(Etype
(Actual
))
14678 and then Ekind
(Formal
) /= E_In_Parameter
14681 -- <actual> := P.<formal>;
14684 Make_Assignment_Statement
(Loc
,
14688 Make_Explicit_Dereference
(Loc
,
14689 Make_Selected_Component
(Loc
,
14691 New_Occurrence_Of
(P
, Loc
),
14693 Make_Identifier
(Loc
, Chars
(Formal
)))));
14695 Set_Assignment_OK
(Name
(Asnmt
));
14696 Append_To
(Result
, Asnmt
);
14701 Next_Actual
(Actual
);
14702 Next_Formal_With_Extras
(Formal
);
14708 return New_List
(Make_Null_Statement
(Loc
));
14710 end Parameter_Block_Unpack
;
14712 ----------------------
14713 -- Set_Discriminals --
14714 ----------------------
14716 procedure Set_Discriminals
(Dec
: Node_Id
) is
14719 D_Minal
: Entity_Id
;
14722 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14723 Pdef
:= Defining_Identifier
(Dec
);
14725 if Has_Discriminants
(Pdef
) then
14726 D
:= First_Discriminant
(Pdef
);
14727 while Present
(D
) loop
14729 Make_Defining_Identifier
(Sloc
(D
),
14730 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14732 Set_Ekind
(D_Minal
, E_Constant
);
14733 Set_Etype
(D_Minal
, Etype
(D
));
14734 Set_Scope
(D_Minal
, Pdef
);
14735 Set_Discriminal
(D
, D_Minal
);
14736 Set_Discriminal_Link
(D_Minal
, D
);
14738 Next_Discriminant
(D
);
14741 end Set_Discriminals
;
14743 -----------------------
14744 -- Trivial_Accept_OK --
14745 -----------------------
14747 function Trivial_Accept_OK
return Boolean is
14749 case Opt
.Task_Dispatching_Policy
is
14751 -- If we have the default task dispatching policy in effect, we can
14752 -- definitely do the optimization (one way of looking at this is to
14753 -- think of the formal definition of the default policy being allowed
14754 -- to run any task it likes after a rendezvous, so even if notionally
14755 -- a full rescheduling occurs, we can say that our dispatching policy
14756 -- (i.e. the default dispatching policy) reorders the queue to be the
14757 -- same as just before the call.
14762 -- FIFO_Within_Priorities certainly does not permit this
14763 -- optimization since the Rendezvous is a scheduling action that may
14764 -- require some other task to be run.
14769 -- For now, disallow the optimization for all other policies. This
14770 -- may be over-conservative, but it is certainly not incorrect.
14775 end Trivial_Accept_OK
;