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
=>
8659 New_Op_Body
:= New_Copy
(Op_Body
);
8660 Insert_After
(Current_Node
, New_Op_Body
);
8661 Current_Node
:= New_Op_Body
;
8663 when N_Freeze_Entity
=>
8664 New_Op_Body
:= New_Copy
(Op_Body
);
8666 if Present
(Entity
(Op_Body
))
8667 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8669 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8672 Insert_After
(Current_Node
, New_Op_Body
);
8673 Current_Node
:= New_Op_Body
;
8674 Analyze
(New_Op_Body
);
8677 New_Op_Body
:= New_Copy
(Op_Body
);
8678 Insert_After
(Current_Node
, New_Op_Body
);
8679 Current_Node
:= New_Op_Body
;
8680 Analyze
(New_Op_Body
);
8682 when N_Object_Declaration
=>
8683 pragma Assert
(not Comes_From_Source
(Op_Body
));
8684 New_Op_Body
:= New_Copy
(Op_Body
);
8685 Insert_After
(Current_Node
, New_Op_Body
);
8686 Current_Node
:= New_Op_Body
;
8687 Analyze
(New_Op_Body
);
8690 raise Program_Error
;
8696 -- Finally, create the body of the function that maps an entry index
8697 -- into the corresponding body index, except when there is no entry, or
8698 -- in a Ravenscar-like profile.
8700 if Corresponding_Runtime_Package
(Pid
) =
8701 System_Tasking_Protected_Objects_Entries
8703 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8704 Insert_After
(Current_Node
, New_Op_Body
);
8705 Current_Node
:= New_Op_Body
;
8706 Analyze
(New_Op_Body
);
8709 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8710 -- protected body. At this point all wrapper specs have been created,
8711 -- frozen and included in the dispatch table for the protected type.
8713 if Ada_Version
>= Ada_2005
then
8714 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8716 end Expand_N_Protected_Body
;
8718 -----------------------------------------
8719 -- Expand_N_Protected_Type_Declaration --
8720 -----------------------------------------
8722 -- First we create a corresponding record type declaration used to
8723 -- represent values of this protected type.
8724 -- The general form of this type declaration is
8726 -- type poV (discriminants) is record
8727 -- _Object : aliased <kind>Protection
8728 -- [(<entry count> [, <handler count>])];
8729 -- [entry_family : array (bounds) of Void;]
8730 -- <private data fields>
8733 -- The discriminants are present only if the corresponding protected type
8734 -- has discriminants, and they exactly mirror the protected type
8735 -- discriminants. The private data fields similarly mirror the private
8736 -- declarations of the protected type.
8738 -- The Object field is always present. It contains RTS specific data used
8739 -- to control the protected object. It is declared as Aliased so that it
8740 -- can be passed as a pointer to the RTS. This allows the protected record
8741 -- to be referenced within RTS data structures. An appropriate Protection
8742 -- type and discriminant are generated.
8744 -- The Service field is present for protected objects with entries. It
8745 -- contains sufficient information to allow the entry service procedure for
8746 -- this object to be called when the object is not known till runtime.
8748 -- One entry_family component is present for each entry family in the
8749 -- task definition (see Expand_N_Task_Type_Declaration).
8751 -- When a protected object is declared, an instance of the protected type
8752 -- value record is created. The elaboration of this declaration creates the
8753 -- correct bounds for the entry families, and also evaluates the priority
8754 -- expression if needed. The initialization routine for the protected type
8755 -- itself then calls Initialize_Protection with appropriate parameters to
8756 -- initialize the value of the Task_Id field. Install_Handlers may be also
8757 -- called if a pragma Attach_Handler applies.
8759 -- Note: this record is passed to the subprograms created by the expansion
8760 -- of protected subprograms and entries. It is an in parameter to protected
8761 -- functions and an in out parameter to procedures and entry bodies. The
8762 -- Entity_Id for this created record type is placed in the
8763 -- Corresponding_Record_Type field of the associated protected type entity.
8765 -- Next we create a procedure specifications for protected subprograms and
8766 -- entry bodies. For each protected subprograms two subprograms are
8767 -- created, an unprotected and a protected version. The unprotected version
8768 -- is called from within other operations of the same protected object.
8770 -- We also build the call to register the procedure if a pragma
8771 -- Interrupt_Handler applies.
8773 -- A single subprogram is created to service all entry bodies; it has an
8774 -- additional boolean out parameter indicating that the previous entry call
8775 -- made by the current task was serviced immediately, i.e. not by proxy.
8776 -- The O parameter contains a pointer to a record object of the type
8777 -- described above. An untyped interface is used here to allow this
8778 -- procedure to be called in places where the type of the object to be
8779 -- serviced is not known. This must be done, for example, when a call that
8780 -- may have been requeued is cancelled; the corresponding object must be
8781 -- serviced, but which object that is not known till runtime.
8784 -- (O : System.Address; P : out Boolean);
8785 -- procedure pprocN (_object : in out poV);
8786 -- procedure pproc (_object : in out poV);
8787 -- function pfuncN (_object : poV);
8788 -- function pfunc (_object : poV);
8791 -- Note that this must come after the record type declaration, since
8792 -- the specs refer to this type.
8794 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8795 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8796 Loc
: constant Source_Ptr
:= Sloc
(N
);
8797 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8799 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8800 -- This flag indicates whether the lock free implementation is active
8802 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8803 -- This contains two lists; one for visible and one for private decls
8805 Current_Node
: Node_Id
:= N
;
8807 Entries_Aggr
: Node_Id
;
8809 procedure Check_Inlining
(Subp
: Entity_Id
);
8810 -- If the original operation has a pragma Inline, propagate the flag
8811 -- to the internal body, for possible inlining later on. The source
8812 -- operation is invisible to the back-end and is never actually called.
8814 procedure Expand_Entry_Declaration
(Decl
: Node_Id
);
8815 -- Create the entry barrier and the procedure body for entry declaration
8816 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8818 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8819 -- When compiling under the Ravenscar profile, private components must
8820 -- have a static size, or else a protected object will require heap
8821 -- allocation, violating the corresponding restriction. It is preferable
8822 -- to make this check here, because it provides a better error message
8823 -- than the back-end, which refers to the object as a whole.
8825 procedure Register_Handler
;
8826 -- For a protected operation that is an interrupt handler, add the
8827 -- freeze action that will register it as such.
8829 --------------------
8830 -- Check_Inlining --
8831 --------------------
8833 procedure Check_Inlining
(Subp
: Entity_Id
) is
8835 if Is_Inlined
(Subp
) then
8836 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8837 Set_Is_Inlined
(Subp
, False);
8841 ---------------------------
8842 -- Static_Component_Size --
8843 ---------------------------
8845 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8846 Typ
: constant Entity_Id
:= Etype
(Comp
);
8850 if Is_Scalar_Type
(Typ
) then
8853 elsif Is_Array_Type
(Typ
) then
8854 return Compile_Time_Known_Bounds
(Typ
);
8856 elsif Is_Record_Type
(Typ
) then
8857 C
:= First_Component
(Typ
);
8858 while Present
(C
) loop
8859 if not Static_Component_Size
(C
) then
8868 -- Any other type will be checked by the back-end
8873 end Static_Component_Size
;
8875 ------------------------------
8876 -- Expand_Entry_Declaration --
8877 ------------------------------
8879 procedure Expand_Entry_Declaration
(Decl
: Node_Id
) is
8880 Ent_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
8886 E_Count
:= E_Count
+ 1;
8888 -- Create the protected body subprogram
8891 Make_Defining_Identifier
(Loc
,
8892 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'E'));
8893 Set_Protected_Body_Subprogram
(Ent_Id
, Bod_Id
);
8896 Make_Subprogram_Declaration
(Loc
,
8898 Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Ent_Id
));
8900 Insert_After
(Current_Node
, Subp
);
8901 Current_Node
:= Subp
;
8905 -- Build a wrapper procedure to handle contract cases, preconditions,
8906 -- and postconditions.
8908 Build_Contract_Wrapper
(Ent_Id
, N
);
8910 -- Create the barrier function
8913 Make_Defining_Identifier
(Loc
,
8914 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'B'));
8915 Set_Barrier_Function
(Ent_Id
, Bar_Id
);
8918 Make_Subprogram_Declaration
(Loc
,
8920 Build_Barrier_Function_Specification
(Loc
, Bar_Id
));
8921 Set_Is_Entry_Barrier_Function
(Subp
);
8923 Insert_After
(Current_Node
, Subp
);
8924 Current_Node
:= Subp
;
8928 Set_Protected_Body_Subprogram
(Bar_Id
, Bar_Id
);
8929 Set_Scope
(Bar_Id
, Scope
(Ent_Id
));
8931 -- Collect pointers to the protected subprogram and the barrier
8932 -- of the current entry, for insertion into Entry_Bodies_Array.
8934 Append_To
(Expressions
(Entries_Aggr
),
8935 Make_Aggregate
(Loc
,
8936 Expressions
=> New_List
(
8937 Make_Attribute_Reference
(Loc
,
8938 Prefix
=> New_Occurrence_Of
(Bar_Id
, Loc
),
8939 Attribute_Name
=> Name_Unrestricted_Access
),
8940 Make_Attribute_Reference
(Loc
,
8941 Prefix
=> New_Occurrence_Of
(Bod_Id
, Loc
),
8942 Attribute_Name
=> Name_Unrestricted_Access
))));
8943 end Expand_Entry_Declaration
;
8945 ----------------------
8946 -- Register_Handler --
8947 ----------------------
8949 procedure Register_Handler
is
8951 -- All semantic checks already done in Sem_Prag
8953 Prot_Proc
: constant Entity_Id
:=
8954 Defining_Unit_Name
(Specification
(Current_Node
));
8956 Proc_Address
: constant Node_Id
:=
8957 Make_Attribute_Reference
(Loc
,
8959 New_Occurrence_Of
(Prot_Proc
, Loc
),
8960 Attribute_Name
=> Name_Address
);
8962 RTS_Call
: constant Entity_Id
:=
8963 Make_Procedure_Call_Statement
(Loc
,
8966 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8967 Parameter_Associations
=> New_List
(Proc_Address
));
8969 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8970 end Register_Handler
;
8975 Body_Id
: Entity_Id
;
8981 Object_Comp
: Node_Id
;
8986 -- Start of processing for Expand_N_Protected_Type_Declaration
8989 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8992 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8995 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8997 Qualify_Entity_Names
(N
);
8999 -- If the type has discriminants, their occurrences in the declaration
9000 -- have been replaced by the corresponding discriminals. For components
9001 -- that are constrained by discriminants, their homologues in the
9002 -- corresponding record type must refer to the discriminants of that
9003 -- record, so we must apply a new renaming to subtypes_indications:
9005 -- protected discriminant => discriminal => record discriminant
9007 -- This replacement is not applied to default expressions, for which
9008 -- the discriminal is correct.
9010 if Has_Discriminants
(Prot_Typ
) then
9016 Disc
:= First_Discriminant
(Prot_Typ
);
9017 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
9018 while Present
(Disc
) loop
9019 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
9020 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
9021 Next_Discriminant
(Disc
);
9027 -- Fill in the component declarations
9029 -- Add components for entry families. For each entry family, create an
9030 -- anonymous type declaration with the same size, and analyze the type.
9032 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9034 pragma Assert
(Present
(Pdef
));
9036 Insert_After
(Current_Node
, Rec_Decl
);
9037 Current_Node
:= Rec_Decl
;
9039 -- Add private field components
9041 if Present
(Private_Declarations
(Pdef
)) then
9042 Priv
:= First
(Private_Declarations
(Pdef
));
9043 while Present
(Priv
) loop
9044 if Nkind
(Priv
) = N_Component_Declaration
then
9045 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9047 -- When compiling for a restricted profile, the private
9048 -- components must have a static size. If not, this is an
9049 -- error for a single protected declaration, and rates a
9050 -- warning on a protected type declaration.
9052 if not Comes_From_Source
(Prot_Typ
) then
9054 -- It's ok to be checking this restriction at expansion
9055 -- time, because this is only for the restricted profile,
9056 -- which is not subject to strict RM conformance, so it
9057 -- is OK to miss this check in -gnatc mode.
9059 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9061 (No_Implicit_Protected_Object_Allocations
, Priv
);
9063 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9064 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9066 -- Any object of the type will be non-static
9068 Error_Msg_N
("component has non-static size??", Priv
);
9070 ("\creation of protected object of type& will "
9071 & "violate restriction "
9072 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9074 -- Object will be non-static if discriminants are
9077 ("creation of protected object of type& with "
9078 & "non-static discriminants will violate "
9079 & "restriction No_Implicit_Heap_Allocations??",
9083 -- Likewise for No_Implicit_Protected_Object_Allocations
9085 elsif Restriction_Active
9086 (No_Implicit_Protected_Object_Allocations
)
9088 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9090 -- Any object of the type will be non-static
9092 Error_Msg_N
("component has non-static size??", Priv
);
9094 ("\creation of protected object of type& will "
9095 & "violate restriction "
9096 & "No_Implicit_Protected_Object_Allocations??",
9099 -- Object will be non-static if discriminants are
9102 ("creation of protected object of type& with "
9103 & "non-static discriminants will violate "
9105 & "No_Implicit_Protected_Object_Allocations??",
9111 -- The component definition consists of a subtype indication,
9112 -- or (in Ada 2005) an access definition. Make a copy of the
9113 -- proper definition.
9116 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9117 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9118 Nent
: constant Entity_Id
:=
9119 Make_Defining_Identifier
(Sloc
(Oent
),
9120 Chars
=> Chars
(Oent
));
9124 if Present
(Subtype_Indication
(Old_Comp
)) then
9126 Make_Component_Definition
(Sloc
(Oent
),
9127 Aliased_Present
=> False,
9128 Subtype_Indication
=>
9130 (Subtype_Indication
(Old_Comp
), Discr_Map
));
9133 Make_Component_Definition
(Sloc
(Oent
),
9134 Aliased_Present
=> False,
9135 Access_Definition
=>
9137 (Access_Definition
(Old_Comp
), Discr_Map
));
9141 Make_Component_Declaration
(Loc
,
9142 Defining_Identifier
=> Nent
,
9143 Component_Definition
=> New_Comp
,
9144 Expression
=> Expression
(Priv
));
9146 Set_Has_Per_Object_Constraint
(Nent
,
9147 Has_Per_Object_Constraint
(Oent
));
9149 Append_To
(Cdecls
, New_Priv
);
9152 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9154 -- Make the unprotected version of the subprogram available
9155 -- for expansion of intra object calls. There is need for
9156 -- a protected version only if the subprogram is an interrupt
9157 -- handler, otherwise this operation can only be called from
9161 Make_Subprogram_Declaration
(Loc
,
9163 Build_Protected_Sub_Specification
9164 (Priv
, Prot_Typ
, Unprotected_Mode
));
9166 Insert_After
(Current_Node
, Sub
);
9169 Set_Protected_Body_Subprogram
9170 (Defining_Unit_Name
(Specification
(Priv
)),
9171 Defining_Unit_Name
(Specification
(Sub
)));
9172 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9173 Current_Node
:= Sub
;
9176 Make_Subprogram_Declaration
(Loc
,
9178 Build_Protected_Sub_Specification
9179 (Priv
, Prot_Typ
, Protected_Mode
));
9181 Insert_After
(Current_Node
, Sub
);
9183 Current_Node
:= Sub
;
9185 if Is_Interrupt_Handler
9186 (Defining_Unit_Name
(Specification
(Priv
)))
9188 if not Restricted_Profile
then
9198 -- Except for the lock-free implementation, append the _Object field
9199 -- with the right type to the component list. We need to compute the
9200 -- number of entries, and in some cases the number of Attach_Handler
9203 if not Lock_Free_Active
then
9205 Entry_Count_Expr
: constant Node_Id
:=
9206 Build_Entry_Count_Expression
9207 (Prot_Typ
, Cdecls
, Loc
);
9208 Num_Attach_Handler
: Nat
:= 0;
9209 Protection_Subtype
: Node_Id
;
9213 if Has_Attach_Handler
(Prot_Typ
) then
9214 Ritem
:= First_Rep_Item
(Prot_Typ
);
9215 while Present
(Ritem
) loop
9216 if Nkind
(Ritem
) = N_Pragma
9217 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9219 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9222 Next_Rep_Item
(Ritem
);
9226 -- Determine the proper protection type. There are two special
9227 -- cases: 1) when the protected type has dynamic interrupt
9228 -- handlers, and 2) when it has static handlers and we use a
9229 -- restricted profile.
9231 if Has_Attach_Handler
(Prot_Typ
)
9232 and then not Restricted_Profile
9234 Protection_Subtype
:=
9235 Make_Subtype_Indication
(Loc
,
9238 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9240 Make_Index_Or_Discriminant_Constraint
(Loc
,
9241 Constraints
=> New_List
(
9243 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9245 elsif Has_Interrupt_Handler
(Prot_Typ
)
9246 and then not Restriction_Active
(No_Dynamic_Attachment
)
9248 Protection_Subtype
:=
9249 Make_Subtype_Indication
(Loc
,
9252 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9254 Make_Index_Or_Discriminant_Constraint
(Loc
,
9255 Constraints
=> New_List
(Entry_Count_Expr
)));
9258 case Corresponding_Runtime_Package
(Prot_Typ
) is
9259 when System_Tasking_Protected_Objects_Entries
=>
9260 Protection_Subtype
:=
9261 Make_Subtype_Indication
(Loc
,
9264 (RTE
(RE_Protection_Entries
), Loc
),
9266 Make_Index_Or_Discriminant_Constraint
(Loc
,
9267 Constraints
=> New_List
(Entry_Count_Expr
)));
9269 when System_Tasking_Protected_Objects_Single_Entry
=>
9270 Protection_Subtype
:=
9271 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9273 when System_Tasking_Protected_Objects
=>
9274 Protection_Subtype
:=
9275 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9278 raise Program_Error
;
9283 Make_Component_Declaration
(Loc
,
9284 Defining_Identifier
=>
9285 Make_Defining_Identifier
(Loc
, Name_uObject
),
9286 Component_Definition
=>
9287 Make_Component_Definition
(Loc
,
9288 Aliased_Present
=> True,
9289 Subtype_Indication
=> Protection_Subtype
));
9292 -- Put the _Object component after the private component so that it
9293 -- be finalized early as required by 9.4 (20)
9295 Append_To
(Cdecls
, Object_Comp
);
9298 -- Analyze the record declaration immediately after construction,
9299 -- because the initialization procedure is needed for single object
9300 -- declarations before the next entity is analyzed (the freeze call
9301 -- that generates this initialization procedure is found below).
9303 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9305 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9306 -- the corresponding record is frozen. If any wrappers are generated,
9307 -- Current_Node is updated accordingly.
9309 if Ada_Version
>= Ada_2005
then
9310 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9313 -- Collect pointers to entry bodies and their barriers, to be placed
9314 -- in the Entry_Bodies_Array for the type. For each entry/family we
9315 -- add an expression to the aggregate which is the initial value of
9316 -- this array. The array is declared after all protected subprograms.
9318 if Has_Entries
(Prot_Typ
) then
9319 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9321 Entries_Aggr
:= Empty
;
9324 -- Build two new procedure specifications for each protected subprogram;
9325 -- one to call from outside the object and one to call from inside.
9326 -- Build a barrier function and an entry body action procedure
9327 -- specification for each protected entry. Initialize the entry body
9328 -- array. If subprogram is flagged as eliminated, do not generate any
9329 -- internal operations.
9332 Comp
:= First
(Visible_Declarations
(Pdef
));
9333 while Present
(Comp
) loop
9334 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9336 Make_Subprogram_Declaration
(Loc
,
9338 Build_Protected_Sub_Specification
9339 (Comp
, Prot_Typ
, Unprotected_Mode
));
9341 Insert_After
(Current_Node
, Sub
);
9344 Set_Protected_Body_Subprogram
9345 (Defining_Unit_Name
(Specification
(Comp
)),
9346 Defining_Unit_Name
(Specification
(Sub
)));
9347 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9349 -- Make the protected version of the subprogram available for
9350 -- expansion of external calls.
9352 Current_Node
:= Sub
;
9355 Make_Subprogram_Declaration
(Loc
,
9357 Build_Protected_Sub_Specification
9358 (Comp
, Prot_Typ
, Protected_Mode
));
9360 Insert_After
(Current_Node
, Sub
);
9363 Current_Node
:= Sub
;
9365 -- Generate an overriding primitive operation specification for
9366 -- this subprogram if the protected type implements an interface
9367 -- and Build_Wrapper_Spec did not generate its wrapper.
9369 if Ada_Version
>= Ada_2005
9371 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9374 Found
: Boolean := False;
9375 Prim_Elmt
: Elmt_Id
;
9381 (Primitive_Operations
9382 (Corresponding_Record_Type
(Prot_Typ
)));
9384 while Present
(Prim_Elmt
) loop
9385 Prim_Op
:= Node
(Prim_Elmt
);
9387 if Is_Primitive_Wrapper
(Prim_Op
)
9388 and then Wrapped_Entity
(Prim_Op
) =
9389 Defining_Entity
(Specification
(Comp
))
9395 Next_Elmt
(Prim_Elmt
);
9400 Make_Subprogram_Declaration
(Loc
,
9402 Build_Protected_Sub_Specification
9403 (Comp
, Prot_Typ
, Dispatching_Mode
));
9405 Insert_After
(Current_Node
, Sub
);
9408 Current_Node
:= Sub
;
9413 -- If a pragma Interrupt_Handler applies, build and add a call to
9414 -- Register_Interrupt_Handler to the freezing actions of the
9415 -- protected version (Current_Node) of the subprogram:
9417 -- system.interrupts.register_interrupt_handler
9418 -- (prot_procP'address);
9420 if not Restricted_Profile
9421 and then Is_Interrupt_Handler
9422 (Defining_Unit_Name
(Specification
(Comp
)))
9427 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9428 Expand_Entry_Declaration
(Comp
);
9434 -- If there are some private entry declarations, expand it as if they
9435 -- were visible entries.
9437 if Present
(Private_Declarations
(Pdef
)) then
9438 Comp
:= First
(Private_Declarations
(Pdef
));
9439 while Present
(Comp
) loop
9440 if Nkind
(Comp
) = N_Entry_Declaration
then
9441 Expand_Entry_Declaration
(Comp
);
9448 -- Create the declaration of an array object which contains the values
9449 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9450 -- type. This object is later passed to the appropriate protected object
9451 -- initialization routine.
9453 if Has_Entries
(Prot_Typ
)
9454 and then Corresponding_Runtime_Package
(Prot_Typ
) =
9455 System_Tasking_Protected_Objects_Entries
9462 Maxes_Id
: Entity_Id
;
9463 Need_Array
: Boolean := False;
9466 -- First check if there is any Max_Queue_Length pragma
9468 Item
:= First_Entity
(Prot_Typ
);
9469 while Present
(Item
) loop
9470 if Is_Entry
(Item
) and then Has_Max_Queue_Length
(Item
) then
9478 -- Gather the Max_Queue_Length values of all entries in a list. A
9479 -- value of zero indicates that the entry has no limitation on its
9484 Item
:= First_Entity
(Prot_Typ
);
9486 while Present
(Item
) loop
9487 if Is_Entry
(Item
) then
9490 Make_Integer_Literal
9491 (Loc
, Get_Max_Queue_Length
(Item
)));
9497 -- Create the declaration of the array object. Generate:
9499 -- Maxes_Id : aliased constant
9500 -- Protected_Entry_Queue_Max_Array
9501 -- (1 .. Count) := (..., ...);
9504 Make_Defining_Identifier
(Loc
,
9505 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'B'));
9508 Make_Object_Declaration
(Loc
,
9509 Defining_Identifier
=> Maxes_Id
,
9510 Aliased_Present
=> True,
9511 Constant_Present
=> True,
9512 Object_Definition
=>
9513 Make_Subtype_Indication
(Loc
,
9516 (RTE
(RE_Protected_Entry_Queue_Max_Array
), Loc
),
9518 Make_Index_Or_Discriminant_Constraint
(Loc
,
9519 Constraints
=> New_List
(
9521 Make_Integer_Literal
(Loc
, 1),
9522 Make_Integer_Literal
(Loc
, Count
))))),
9523 Expression
=> Make_Aggregate
(Loc
, Maxes
));
9525 -- A pointer to this array will be placed in the corresponding
9526 -- record by its initialization procedure so this needs to be
9529 Insert_After
(Current_Node
, Max_Vals
);
9530 Current_Node
:= Max_Vals
;
9533 Set_Entry_Max_Queue_Lengths_Array
(Prot_Typ
, Maxes_Id
);
9538 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9539 -- all protected subprograms have been collected.
9541 if Has_Entries
(Prot_Typ
) then
9543 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9544 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9546 case Corresponding_Runtime_Package
(Prot_Typ
) is
9547 when System_Tasking_Protected_Objects_Entries
=>
9548 Expr
:= Entries_Aggr
;
9550 Make_Subtype_Indication
(Loc
,
9553 (RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9555 Make_Index_Or_Discriminant_Constraint
(Loc
,
9556 Constraints
=> New_List
(
9558 Make_Integer_Literal
(Loc
, 1),
9559 Make_Integer_Literal
(Loc
, E_Count
)))));
9561 when System_Tasking_Protected_Objects_Single_Entry
=>
9562 Expr
:= Remove_Head
(Expressions
(Entries_Aggr
));
9563 Obj_Def
:= New_Occurrence_Of
(RTE
(RE_Entry_Body
), Loc
);
9566 raise Program_Error
;
9570 Make_Object_Declaration
(Loc
,
9571 Defining_Identifier
=> Body_Id
,
9572 Aliased_Present
=> True,
9573 Constant_Present
=> True,
9574 Object_Definition
=> Obj_Def
,
9575 Expression
=> Expr
);
9577 -- A pointer to this array will be placed in the corresponding record
9578 -- by its initialization procedure so this needs to be analyzed here.
9580 Insert_After
(Current_Node
, Body_Arr
);
9581 Current_Node
:= Body_Arr
;
9584 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9586 -- Finally, build the function that maps an entry index into the
9587 -- corresponding body. A pointer to this function is placed in each
9588 -- object of the type. Except for a ravenscar-like profile (no abort,
9589 -- no entry queue, 1 entry)
9591 if Corresponding_Runtime_Package
(Prot_Typ
) =
9592 System_Tasking_Protected_Objects_Entries
9595 Make_Subprogram_Declaration
(Loc
,
9596 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9598 Insert_After
(Current_Node
, Sub
);
9602 end Expand_N_Protected_Type_Declaration
;
9604 --------------------------------
9605 -- Expand_N_Requeue_Statement --
9606 --------------------------------
9608 -- A nondispatching requeue statement is expanded into one of four GNARLI
9609 -- operations, depending on the source and destination (task or protected
9610 -- object). A dispatching requeue statement is expanded into a call to the
9611 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9612 -- jump around the remainder of processing for the original entry and, if
9613 -- the destination is (different) protected object, to attempt to service
9614 -- it. The following illustrates the various cases:
9617 -- (O : System.Address;
9618 -- P : System.Address;
9619 -- E : Protected_Entry_Index)
9621 -- <discriminant renamings>
9622 -- <private object renamings>
9623 -- type poVP is access poV;
9624 -- _object : ptVP := ptVP!(O);
9628 -- <start of statement sequence for entry>
9630 -- -- Requeue from one protected entry body to another protected
9633 -- Requeue_Protected_Entry (
9634 -- _object._object'Access,
9635 -- new._object'Access,
9640 -- <some more of the statement sequence for entry>
9642 -- -- Requeue from an entry body to a task entry
9644 -- Requeue_Protected_To_Task_Entry (
9650 -- <rest of statement sequence for entry>
9651 -- Complete_Entry_Body (_object._object);
9654 -- when all others =>
9655 -- Exceptional_Complete_Entry_Body (
9656 -- _object._object, Get_GNAT_Exception);
9660 -- Requeue of a task entry call to a task entry
9662 -- Accept_Call (E, Ann);
9663 -- <start of statement sequence for accept statement>
9664 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9666 -- <rest of statement sequence for accept statement>
9668 -- Complete_Rendezvous;
9671 -- when all others =>
9672 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9674 -- Requeue of a task entry call to a protected entry
9676 -- Accept_Call (E, Ann);
9677 -- <start of statement sequence for accept statement>
9678 -- Requeue_Task_To_Protected_Entry (
9679 -- new._object'Access,
9684 -- <rest of statement sequence for accept statement>
9686 -- Complete_Rendezvous;
9689 -- when all others =>
9690 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9692 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9693 -- marked by pragma Implemented (XXX, By_Entry).
9695 -- The requeue is inside a protected entry:
9698 -- (O : System.Address;
9699 -- P : System.Address;
9700 -- E : Protected_Entry_Index)
9702 -- <discriminant renamings>
9703 -- <private object renamings>
9704 -- type poVP is access poV;
9705 -- _object : ptVP := ptVP!(O);
9709 -- <start of statement sequence for entry>
9712 -- (<interface class-wide object>,
9715 -- Ada.Tags.Get_Offset_Index
9717 -- <interface dispatch table index of target entry>),
9721 -- <rest of statement sequence for entry>
9722 -- Complete_Entry_Body (_object._object);
9725 -- when all others =>
9726 -- Exceptional_Complete_Entry_Body (
9727 -- _object._object, Get_GNAT_Exception);
9731 -- The requeue is inside a task entry:
9733 -- Accept_Call (E, Ann);
9734 -- <start of statement sequence for accept statement>
9736 -- (<interface class-wide object>,
9739 -- Ada.Tags.Get_Offset_Index
9741 -- <interface dispatch table index of target entrt>),
9745 -- <rest of statement sequence for accept statement>
9747 -- Complete_Rendezvous;
9750 -- when all others =>
9751 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9753 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9754 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9755 -- statement is replaced by a dispatching call with actual parameters taken
9756 -- from the inner-most accept statement or entry body.
9758 -- Target.Primitive (Param1, ..., ParamN);
9760 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9761 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9765 -- S : constant Offset_Index :=
9766 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9767 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9770 -- if C = POK_Protected_Entry
9771 -- or else C = POK_Task_Entry
9773 -- <statements for dispatching requeue>
9775 -- elsif C = POK_Protected_Procedure then
9776 -- <dispatching call equivalent>
9779 -- raise Program_Error;
9783 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9784 Loc
: constant Source_Ptr
:= Sloc
(N
);
9785 Conc_Typ
: Entity_Id
;
9789 Old_Typ
: Entity_Id
;
9791 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9792 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9793 -- the form Concval.Ename. It is statically known that Ename is allowed
9794 -- to be implemented by a protected procedure. Create a dispatching call
9795 -- equivalent of Concval.Ename taking the actual parameters from the
9796 -- inner-most accept statement or entry body.
9798 function Build_Dispatching_Requeue
return Node_Id
;
9799 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9800 -- the form Concval.Ename. It is statically known that Ename is allowed
9801 -- to be implemented by a protected or a task entry. Create a call to
9802 -- primitive _Disp_Requeue which handles the low-level actions.
9804 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9805 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9806 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9807 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9808 -- determines at runtime whether Ename denotes an entry or a procedure
9809 -- and perform the appropriate kind of dispatching select.
9811 function Build_Normal_Requeue
return Node_Id
;
9812 -- N denotes a nondispatching requeue statement to either a task or a
9813 -- protected entry. Build the appropriate runtime call to perform the
9816 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9817 -- For a protected entry, create a return statement to skip the rest of
9818 -- the entry body. Otherwise, create a goto statement to skip the rest
9819 -- of a task accept statement. The lookup for the enclosing entry body
9820 -- or accept statement starts from Search.
9822 ---------------------------------------
9823 -- Build_Dispatching_Call_Equivalent --
9824 ---------------------------------------
9826 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9827 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9828 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9835 -- Climb the parent chain looking for the inner-most entry body or
9836 -- accept statement.
9839 while Present
(Acc_Ent
)
9840 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9843 Acc_Ent
:= Parent
(Acc_Ent
);
9846 -- A requeue statement should be housed inside an entry body or an
9847 -- accept statement at some level. If this is not the case, then the
9848 -- tree is malformed.
9850 pragma Assert
(Present
(Acc_Ent
));
9852 -- Recover the list of formal parameters
9854 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9855 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9858 Formals
:= Parameter_Specifications
(Acc_Ent
);
9860 -- Create the actual parameters for the dispatching call. These are
9861 -- simply copies of the entry body or accept statement formals in the
9862 -- same order as they appear.
9866 if Present
(Formals
) then
9867 Actuals
:= New_List
;
9868 Formal
:= First
(Formals
);
9869 while Present
(Formal
) loop
9871 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9877 -- Obj.Call_Ent (Actuals);
9880 Make_Procedure_Call_Statement
(Loc
,
9882 Make_Selected_Component
(Loc
,
9883 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9884 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9886 Parameter_Associations
=> Actuals
);
9887 end Build_Dispatching_Call_Equivalent
;
9889 -------------------------------
9890 -- Build_Dispatching_Requeue --
9891 -------------------------------
9893 function Build_Dispatching_Requeue
return Node_Id
is
9894 Params
: constant List_Id
:= New_List
;
9897 -- Process the "with abort" parameter
9900 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9902 -- Process the entry wrapper's position in the primary dispatch
9903 -- table parameter. Generate:
9905 -- Ada.Tags.Get_Entry_Index
9906 -- (T => To_Tag_Ptr (Obj'Address).all,
9908 -- Ada.Tags.Get_Offset_Index
9909 -- (Ada.Tags.Tag (Concval),
9910 -- <interface dispatch table position of Ename>));
9912 -- Note that Obj'Address is recursively expanded into a call to
9913 -- Base_Address (Obj).
9915 if Tagged_Type_Expansion
then
9917 Make_Function_Call
(Loc
,
9918 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9919 Parameter_Associations
=> New_List
(
9921 Make_Explicit_Dereference
(Loc
,
9922 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9923 Make_Attribute_Reference
(Loc
,
9924 Prefix
=> New_Copy_Tree
(Concval
),
9925 Attribute_Name
=> Name_Address
))),
9927 Make_Function_Call
(Loc
,
9928 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9929 Parameter_Associations
=> New_List
(
9930 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9931 Make_Integer_Literal
(Loc
,
9932 DT_Position
(Entity
(Ename
))))))));
9938 Make_Function_Call
(Loc
,
9939 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9940 Parameter_Associations
=> New_List
(
9942 Make_Attribute_Reference
(Loc
,
9944 Attribute_Name
=> Name_Tag
),
9946 Make_Function_Call
(Loc
,
9947 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9949 Parameter_Associations
=> New_List
(
9953 Make_Attribute_Reference
(Loc
,
9955 Attribute_Name
=> Name_Tag
),
9959 Make_Attribute_Reference
(Loc
,
9960 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9961 Attribute_Name
=> Name_Tag
),
9965 Make_Integer_Literal
(Loc
,
9966 DT_Position
(Entity
(Ename
))))))));
9969 -- Specific actuals for protected to XXX requeue
9971 if Is_Protected_Type
(Old_Typ
) then
9973 Make_Attribute_Reference
(Loc
, -- _object'Address
9975 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9976 Attribute_Name
=> Name_Address
));
9978 Prepend_To
(Params
, -- True
9979 New_Occurrence_Of
(Standard_True
, Loc
));
9981 -- Specific actuals for task to XXX requeue
9984 pragma Assert
(Is_Task_Type
(Old_Typ
));
9986 Prepend_To
(Params
, -- null
9987 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9989 Prepend_To
(Params
, -- False
9990 New_Occurrence_Of
(Standard_False
, Loc
));
9993 -- Add the object parameter
9995 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9998 -- _Disp_Requeue (<Params>);
10000 -- Find entity for Disp_Requeue operation, which belongs to
10001 -- the type and may not be directly visible.
10006 pragma Warnings
(Off
, Op
);
10009 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
10010 while Present
(Elmt
) loop
10012 exit when Chars
(Op
) = Name_uDisp_Requeue
;
10017 Make_Procedure_Call_Statement
(Loc
,
10018 Name
=> New_Occurrence_Of
(Op
, Loc
),
10019 Parameter_Associations
=> Params
);
10021 end Build_Dispatching_Requeue
;
10023 --------------------------------------
10024 -- Build_Dispatching_Requeue_To_Any --
10025 --------------------------------------
10027 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
10028 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
10029 Obj
: constant Node_Id
:= Original_Node
(Concval
);
10030 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
10040 -- Dispatch table slot processing, generate:
10043 S
:= Build_S
(Loc
, Decls
);
10045 -- Call kind processing, generate:
10046 -- C : Ada.Tags.Prim_Op_Kind;
10048 C
:= Build_C
(Loc
, Decls
);
10051 -- S := Ada.Tags.Get_Offset_Index
10052 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10054 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10057 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10060 Make_Procedure_Call_Statement
(Loc
,
10062 New_Occurrence_Of
(
10063 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10064 Name_uDisp_Get_Prim_Op_Kind
),
10066 Parameter_Associations
=> New_List
(
10067 New_Copy_Tree
(Obj
),
10068 New_Occurrence_Of
(S
, Loc
),
10069 New_Occurrence_Of
(C
, Loc
))));
10073 -- if C = POK_Protected_Entry
10074 -- or else C = POK_Task_Entry
10077 Make_Implicit_If_Statement
(N
,
10083 New_Occurrence_Of
(C
, Loc
),
10085 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10090 New_Occurrence_Of
(C
, Loc
),
10092 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10094 -- Dispatching requeue equivalent
10096 Then_Statements
=> New_List
(
10097 Build_Dispatching_Requeue
,
10100 -- elsif C = POK_Protected_Procedure then
10102 Elsif_Parts
=> New_List
(
10103 Make_Elsif_Part
(Loc
,
10107 New_Occurrence_Of
(C
, Loc
),
10109 New_Occurrence_Of
(
10110 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10112 -- Dispatching call equivalent
10114 Then_Statements
=> New_List
(
10115 Build_Dispatching_Call_Equivalent
))),
10118 -- raise Program_Error;
10121 Else_Statements
=> New_List
(
10122 Make_Raise_Program_Error
(Loc
,
10123 Reason
=> PE_Explicit_Raise
))));
10125 -- Wrap everything into a block
10128 Make_Block_Statement
(Loc
,
10129 Declarations
=> Decls
,
10130 Handled_Statement_Sequence
=>
10131 Make_Handled_Sequence_Of_Statements
(Loc
,
10132 Statements
=> Stmts
));
10133 end Build_Dispatching_Requeue_To_Any
;
10135 --------------------------
10136 -- Build_Normal_Requeue --
10137 --------------------------
10139 function Build_Normal_Requeue
return Node_Id
is
10140 Params
: constant List_Id
:= New_List
;
10145 -- Process the "with abort" parameter
10147 Prepend_To
(Params
,
10148 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10150 -- Add the index expression to the parameters. It is common among all
10153 Prepend_To
(Params
,
10154 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10156 if Is_Protected_Type
(Old_Typ
) then
10158 Self_Param
: Node_Id
;
10162 Make_Attribute_Reference
(Loc
,
10164 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10166 Name_Unchecked_Access
);
10168 -- Protected to protected requeue
10170 if Is_Protected_Type
(Conc_Typ
) then
10172 New_Occurrence_Of
(
10173 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10176 Make_Attribute_Reference
(Loc
,
10178 Concurrent_Ref
(Concval
),
10180 Name_Unchecked_Access
);
10182 -- Protected to task requeue
10184 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10186 New_Occurrence_Of
(
10187 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10189 Param
:= Concurrent_Ref
(Concval
);
10192 Prepend_To
(Params
, Param
);
10193 Prepend_To
(Params
, Self_Param
);
10196 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10198 -- Task to protected requeue
10200 if Is_Protected_Type
(Conc_Typ
) then
10202 New_Occurrence_Of
(
10203 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10206 Make_Attribute_Reference
(Loc
,
10208 Concurrent_Ref
(Concval
),
10210 Name_Unchecked_Access
);
10212 -- Task to task requeue
10214 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10216 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10218 Param
:= Concurrent_Ref
(Concval
);
10221 Prepend_To
(Params
, Param
);
10225 Make_Procedure_Call_Statement
(Loc
,
10227 Parameter_Associations
=> Params
);
10228 end Build_Normal_Requeue
;
10230 --------------------------
10231 -- Build_Skip_Statement --
10232 --------------------------
10234 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10235 Skip_Stmt
: Node_Id
;
10238 -- Build a return statement to skip the rest of the entire body
10240 if Is_Protected_Type
(Old_Typ
) then
10241 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10243 -- If the requeue is within a task, find the end label of the
10244 -- enclosing accept statement and create a goto statement to it.
10252 -- Climb the parent chain looking for the enclosing accept
10255 Acc
:= Parent
(Search
);
10256 while Present
(Acc
)
10257 and then Nkind
(Acc
) /= N_Accept_Statement
10259 Acc
:= Parent
(Acc
);
10262 -- The last statement is the second label used for completing
10263 -- the rendezvous the usual way. The label we are looking for
10264 -- is right before it.
10267 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10269 pragma Assert
(Nkind
(Label
) = N_Label
);
10271 -- Generate a goto statement to skip the rest of the accept
10274 Make_Goto_Statement
(Loc
,
10276 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10280 Set_Analyzed
(Skip_Stmt
);
10283 end Build_Skip_Statement
;
10285 -- Start of processing for Expand_N_Requeue_Statement
10288 -- Extract the components of the entry call
10290 Extract_Entry
(N
, Concval
, Ename
, Index
);
10291 Conc_Typ
:= Etype
(Concval
);
10293 -- If the prefix is an access to class-wide type, dereference to get
10294 -- object and entry type.
10296 if Is_Access_Type
(Conc_Typ
) then
10297 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10299 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10300 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10303 -- Examine the scope stack in order to find nearest enclosing protected
10304 -- or task type. This will constitute our invocation source.
10306 Old_Typ
:= Current_Scope
;
10307 while Present
(Old_Typ
)
10308 and then not Is_Protected_Type
(Old_Typ
)
10309 and then not Is_Task_Type
(Old_Typ
)
10311 Old_Typ
:= Scope
(Old_Typ
);
10314 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10315 -- Concval.Ename where the type of Concval is class-wide concurrent
10318 if Ada_Version
>= Ada_2012
10319 and then Present
(Concval
)
10320 and then Is_Class_Wide_Type
(Conc_Typ
)
10321 and then Is_Concurrent_Interface
(Conc_Typ
)
10324 Has_Impl
: Boolean := False;
10325 Impl_Kind
: Name_Id
:= No_Name
;
10328 -- Check whether the Ename is flagged by pragma Implemented
10330 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10332 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10335 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10336 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10338 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10339 Rewrite
(N
, Build_Dispatching_Requeue
);
10341 Insert_After
(N
, Build_Skip_Statement
(N
));
10343 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10344 -- a protected procedure. In this case the requeue is transformed
10345 -- into a dispatching call.
10348 and then Impl_Kind
= Name_By_Protected_Procedure
10350 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10353 -- The procedure_or_entry_NAME's implementation kind is either
10354 -- By_Any, Optional, or pragma Implemented was not applied at all.
10355 -- In this case a runtime test determines whether Ename denotes an
10356 -- entry or a protected procedure and performs the appropriate
10360 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10365 -- Processing for regular (nondispatching) requeues
10368 Rewrite
(N
, Build_Normal_Requeue
);
10370 Insert_After
(N
, Build_Skip_Statement
(N
));
10372 end Expand_N_Requeue_Statement
;
10374 -------------------------------
10375 -- Expand_N_Selective_Accept --
10376 -------------------------------
10378 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10379 Loc
: constant Source_Ptr
:= Sloc
(N
);
10380 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10382 -- Note: in the below declarations a lot of new lists are allocated
10383 -- unconditionally which may well not end up being used. That's not
10384 -- a good idea since it wastes space gratuitously ???
10386 Accept_Case
: List_Id
;
10387 Accept_List
: constant List_Id
:= New_List
;
10390 Alt_List
: constant List_Id
:= New_List
;
10391 Alt_Stats
: List_Id
;
10392 Ann
: Entity_Id
:= Empty
;
10394 Check_Guard
: Boolean := True;
10396 Decls
: constant List_Id
:= New_List
;
10397 Stats
: constant List_Id
:= New_List
;
10398 Body_List
: constant List_Id
:= New_List
;
10399 Trailing_List
: constant List_Id
:= New_List
;
10402 Else_Present
: Boolean := False;
10403 Terminate_Alt
: Node_Id
:= Empty
;
10404 Select_Mode
: Node_Id
;
10406 Delay_Case
: List_Id
;
10407 Delay_Count
: Integer := 0;
10408 Delay_Val
: Entity_Id
;
10409 Delay_Index
: Entity_Id
;
10410 Delay_Min
: Entity_Id
;
10411 Delay_Num
: Pos
:= 1;
10412 Delay_Alt_List
: List_Id
:= New_List
;
10413 Delay_List
: constant List_Id
:= New_List
;
10417 First_Delay
: Boolean := True;
10418 Guard_Open
: Entity_Id
;
10424 Num_Accept
: Nat
:= 0;
10426 Time_Type
: Entity_Id
;
10427 Select_Call
: Node_Id
;
10429 Qnam
: constant Entity_Id
:=
10430 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10432 Xnam
: constant Entity_Id
:=
10433 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10435 -----------------------
10436 -- Local subprograms --
10437 -----------------------
10439 function Accept_Or_Raise
return List_Id
;
10440 -- For the rare case where delay alternatives all have guards, and
10441 -- all of them are closed, it is still possible that there were open
10442 -- accept alternatives with no callers. We must reexamine the
10443 -- Accept_List, and execute a selective wait with no else if some
10444 -- accept is open. If none, we raise program_error.
10446 procedure Add_Accept
(Alt
: Node_Id
);
10447 -- Process a single accept statement in a select alternative. Build
10448 -- procedure for body of accept, and add entry to dispatch table with
10449 -- expression for guard, in preparation for call to run time select.
10451 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10452 -- Manufacture a label using Num as a serial number and declare it.
10453 -- The declaration is appended to Decls. The label marks the trailing
10454 -- statements of an accept or delay alternative.
10456 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10457 -- Build call to Selective_Wait runtime routine
10459 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10460 -- Add code to compare value of delay with previous values, and
10461 -- generate case entry for trailing statements.
10463 procedure Process_Accept_Alternative
10467 -- Add code to call corresponding procedure, and branch to
10468 -- trailing statements, if any.
10470 ---------------------
10471 -- Accept_Or_Raise --
10472 ---------------------
10474 function Accept_Or_Raise
return List_Id
is
10477 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10480 -- We generate the following:
10482 -- for J in q'range loop
10483 -- if q(J).S /=null_task_entry then
10484 -- selective_wait (simple_mode,...);
10490 -- if no rendez_vous then
10491 -- raise program_error;
10494 -- Note that the code needs to know that the selector name
10495 -- in an Accept_Alternative is named S.
10497 Cond
:= Make_Op_Ne
(Loc
,
10499 Make_Selected_Component
(Loc
,
10501 Make_Indexed_Component
(Loc
,
10502 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10503 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10504 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10506 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10508 Stats
:= New_List
(
10509 Make_Implicit_Loop_Statement
(N
,
10510 Iteration_Scheme
=>
10511 Make_Iteration_Scheme
(Loc
,
10512 Loop_Parameter_Specification
=>
10513 Make_Loop_Parameter_Specification
(Loc
,
10514 Defining_Identifier
=> J
,
10515 Discrete_Subtype_Definition
=>
10516 Make_Attribute_Reference
(Loc
,
10517 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10518 Attribute_Name
=> Name_Range
,
10519 Expressions
=> New_List
(
10520 Make_Integer_Literal
(Loc
, 1))))),
10522 Statements
=> New_List
(
10523 Make_Implicit_If_Statement
(N
,
10525 Then_Statements
=> New_List
(
10527 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10528 Make_Exit_Statement
(Loc
))))));
10531 Make_Raise_Program_Error
(Loc
,
10532 Condition
=> Make_Op_Eq
(Loc
,
10533 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10535 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10536 Reason
=> PE_All_Guards_Closed
));
10539 end Accept_Or_Raise
;
10545 procedure Add_Accept
(Alt
: Node_Id
) is
10546 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10547 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10548 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10549 Eent
: constant Entity_Id
:= Entity
(Ename
);
10550 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10551 Null_Body
: Node_Id
;
10552 Proc_Body
: Node_Id
;
10553 PB_Ent
: Entity_Id
;
10559 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10562 if Present
(Condition
(Alt
)) then
10564 Make_If_Expression
(Eloc
, New_List
(
10566 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10567 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10570 Entry_Index_Expression
10571 (Eloc
, Eent
, Index
, Scope
(Eent
));
10574 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10575 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10577 -- Always add call to Abort_Undefer when generating code, since
10578 -- this is what the runtime expects (abort deferred in
10579 -- Selective_Wait). In CodePeer mode this only confuses the
10580 -- analysis with unknown calls, so don't do it.
10582 if not CodePeer_Mode
then
10583 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10585 (First
(Statements
(Handled_Statement_Sequence
10586 (Accept_Statement
(Alt
)))),
10592 Make_Defining_Identifier
(Eloc
,
10593 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10595 -- Link the acceptor to the original receiving entry
10597 Set_Ekind
(PB_Ent
, E_Procedure
);
10598 Set_Receiving_Entry
(PB_Ent
, Eent
);
10600 if Comes_From_Source
(Alt
) then
10601 Set_Debug_Info_Needed
(PB_Ent
);
10605 Make_Subprogram_Body
(Eloc
,
10607 Make_Procedure_Specification
(Eloc
,
10608 Defining_Unit_Name
=> PB_Ent
),
10609 Declarations
=> Declarations
(Acc_Stm
),
10610 Handled_Statement_Sequence
=>
10611 Build_Accept_Body
(Accept_Statement
(Alt
)));
10613 -- During the analysis of the body of the accept statement, any
10614 -- zero cost exception handler records were collected in the
10615 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10616 -- This is where we move them to where they belong, namely the
10617 -- newly created procedure.
10619 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10620 Append
(Proc_Body
, Body_List
);
10623 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10625 -- if accept statement has declarations, insert above, given that
10626 -- we are not creating a body for the accept.
10628 if Present
(Declarations
(Acc_Stm
)) then
10629 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10633 Append_To
(Accept_List
,
10634 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10636 Num_Accept
:= Num_Accept
+ 1;
10639 ----------------------------
10640 -- Make_And_Declare_Label --
10641 ----------------------------
10643 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10647 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10649 Make_Label
(Loc
, Lab_Id
);
10652 Make_Implicit_Label_Declaration
(Loc
,
10653 Defining_Identifier
=>
10654 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10655 Label_Construct
=> Lab
));
10658 end Make_And_Declare_Label
;
10660 ----------------------
10661 -- Make_Select_Call --
10662 ----------------------
10664 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10665 Params
: constant List_Id
:= New_List
;
10669 Make_Attribute_Reference
(Loc
,
10670 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10671 Attribute_Name
=> Name_Unchecked_Access
));
10672 Append_To
(Params
, Select_Mode
);
10673 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10674 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10677 Make_Procedure_Call_Statement
(Loc
,
10678 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10679 Parameter_Associations
=> Params
);
10680 end Make_Select_Call
;
10682 --------------------------------
10683 -- Process_Accept_Alternative --
10684 --------------------------------
10686 procedure Process_Accept_Alternative
10691 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10692 Alt_Stats
: List_Id
;
10695 Adjust_Condition
(Condition
(Alt
));
10697 -- Accept with body
10699 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10702 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10705 (Defining_Unit_Name
(Specification
(Proc
)),
10708 -- Accept with no body (followed by trailing statements)
10711 Alt_Stats
:= Empty_List
;
10714 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10716 -- After the call, if any, branch to trailing statements, if any.
10717 -- We create a label for each, as well as the corresponding label
10720 if not Is_Empty_List
(Statements
(Alt
)) then
10721 Lab
:= Make_And_Declare_Label
(Index
);
10722 Append
(Lab
, Trailing_List
);
10723 Append_List
(Statements
(Alt
), Trailing_List
);
10724 Append_To
(Trailing_List
,
10725 Make_Goto_Statement
(Loc
,
10726 Name
=> New_Copy
(Identifier
(End_Lab
))));
10732 Append_To
(Alt_Stats
,
10733 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10735 Append_To
(Alt_List
,
10736 Make_Case_Statement_Alternative
(Loc
,
10737 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10738 Statements
=> Alt_Stats
));
10739 end Process_Accept_Alternative
;
10741 -------------------------------
10742 -- Process_Delay_Alternative --
10743 -------------------------------
10745 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10746 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10748 Delay_Alt
: List_Id
;
10751 -- Deal with C/Fortran boolean as delay condition
10753 Adjust_Condition
(Condition
(Alt
));
10755 -- Determine the smallest specified delay
10757 -- for each delay alternative generate:
10759 -- if guard-expression then
10760 -- Delay_Val := delay-expression;
10761 -- Guard_Open := True;
10762 -- if Delay_Val < Delay_Min then
10763 -- Delay_Min := Delay_Val;
10764 -- Delay_Index := Index;
10768 -- The enclosing if-statement is omitted if there is no guard
10770 if Delay_Count
= 1 or else First_Delay
then
10771 First_Delay
:= False;
10773 Delay_Alt
:= New_List
(
10774 Make_Assignment_Statement
(Loc
,
10775 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10776 Expression
=> Expression
(Delay_Statement
(Alt
))));
10778 if Delay_Count
> 1 then
10779 Append_To
(Delay_Alt
,
10780 Make_Assignment_Statement
(Loc
,
10781 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10782 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10786 Delay_Alt
:= New_List
(
10787 Make_Assignment_Statement
(Loc
,
10788 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10789 Expression
=> Expression
(Delay_Statement
(Alt
))));
10791 if Time_Type
= Standard_Duration
then
10794 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10795 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10798 -- The scope of the time type must define a comparison
10799 -- operator. The scope itself may not be visible, so we
10800 -- construct a node with entity information to insure that
10801 -- semantic analysis can find the proper operator.
10804 Make_Function_Call
(Loc
,
10805 Name
=> Make_Selected_Component
(Loc
,
10807 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10809 Make_Operator_Symbol
(Loc
,
10810 Chars
=> Name_Op_Lt
,
10811 Strval
=> No_String
)),
10812 Parameter_Associations
=>
10814 New_Occurrence_Of
(Delay_Val
, Loc
),
10815 New_Occurrence_Of
(Delay_Min
, Loc
)));
10817 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10820 Append_To
(Delay_Alt
,
10821 Make_Implicit_If_Statement
(N
,
10823 Then_Statements
=> New_List
(
10824 Make_Assignment_Statement
(Loc
,
10825 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10826 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10828 Make_Assignment_Statement
(Loc
,
10829 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10830 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10833 if Check_Guard
then
10834 Append_To
(Delay_Alt
,
10835 Make_Assignment_Statement
(Loc
,
10836 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10837 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10840 if Present
(Condition
(Alt
)) then
10841 Delay_Alt
:= New_List
(
10842 Make_Implicit_If_Statement
(N
,
10843 Condition
=> Condition
(Alt
),
10844 Then_Statements
=> Delay_Alt
));
10847 Append_List
(Delay_Alt
, Delay_List
);
10849 Ensure_Statement_Present
(Dloc
, Alt
);
10851 -- If the delay alternative has a statement part, add choice to the
10852 -- case statements for delays.
10854 if not Is_Empty_List
(Statements
(Alt
)) then
10856 if Delay_Count
= 1 then
10857 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10860 Append_To
(Delay_Alt_List
,
10861 Make_Case_Statement_Alternative
(Loc
,
10862 Discrete_Choices
=> New_List
(
10863 Make_Integer_Literal
(Loc
, Index
)),
10864 Statements
=> Statements
(Alt
)));
10867 elsif Delay_Count
= 1 then
10869 -- If the single delay has no trailing statements, add a branch
10870 -- to the exit label to the selective wait.
10872 Delay_Alt_List
:= New_List
(
10873 Make_Goto_Statement
(Loc
,
10874 Name
=> New_Copy
(Identifier
(End_Lab
))));
10877 end Process_Delay_Alternative
;
10879 -- Start of processing for Expand_N_Selective_Accept
10882 Process_Statements_For_Controlled_Objects
(N
);
10884 -- First insert some declarations before the select. The first is:
10888 -- This variable holds the parameters passed to the accept body. This
10889 -- declaration has already been inserted by the time we get here by
10890 -- a call to Expand_Accept_Declarations made from the semantics when
10891 -- processing the first accept statement contained in the select. We
10892 -- can find this entity as Accept_Address (E), where E is any of the
10893 -- entries references by contained accept statements.
10895 -- The first step is to scan the list of Selective_Accept_Statements
10896 -- to find this entity, and also count the number of accepts, and
10897 -- determine if terminated, delay or else is present:
10901 Alt
:= First
(Alts
);
10902 while Present
(Alt
) loop
10903 Process_Statements_For_Controlled_Objects
(Alt
);
10905 if Nkind
(Alt
) = N_Accept_Alternative
then
10908 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10909 Delay_Count
:= Delay_Count
+ 1;
10911 -- If the delays are relative delays, the delay expressions have
10912 -- type Standard_Duration. Otherwise they must have some time type
10913 -- recognized by GNAT.
10915 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10916 Time_Type
:= Standard_Duration
;
10918 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10920 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10921 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10926 "& is not a time type (RM 9.6(6))",
10927 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10928 Time_Type
:= Standard_Duration
;
10929 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10933 if No
(Condition
(Alt
)) then
10935 -- This guard will always be open
10937 Check_Guard
:= False;
10940 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10941 Adjust_Condition
(Condition
(Alt
));
10942 Terminate_Alt
:= Alt
;
10945 Num_Alts
:= Num_Alts
+ 1;
10949 Else_Present
:= Present
(Else_Statements
(N
));
10951 -- At the same time (see procedure Add_Accept) we build the accept list:
10953 -- Qnn : Accept_List (1 .. num-select) := (
10954 -- (null-body, entry-index),
10955 -- (null-body, entry-index),
10957 -- (null_body, entry-index));
10959 -- In the above declaration, null-body is True if the corresponding
10960 -- accept has no body, and false otherwise. The entry is either the
10961 -- entry index expression if there is no guard, or if a guard is
10962 -- present, then an if expression of the form:
10964 -- (if guard then entry-index else Null_Task_Entry)
10966 -- If a guard is statically known to be false, the entry can simply
10967 -- be omitted from the accept list.
10970 Make_Object_Declaration
(Loc
,
10971 Defining_Identifier
=> Qnam
,
10972 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10973 Aliased_Present
=> True,
10975 Make_Qualified_Expression
(Loc
,
10977 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10979 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10981 -- Then we declare the variable that holds the index for the accept
10982 -- that will be selected for service:
10984 -- Xnn : Select_Index;
10987 Make_Object_Declaration
(Loc
,
10988 Defining_Identifier
=> Xnam
,
10989 Object_Definition
=>
10990 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10992 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10994 -- After this follow procedure declarations for each accept body
10996 -- procedure Pnn is
11001 -- where the ... are statements from the corresponding procedure body.
11002 -- No parameters are involved, since the parameters are passed via Ann
11003 -- and the parameter references have already been expanded to be direct
11004 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
11005 -- any embedded tasking statements (which would normally be illegal in
11006 -- procedures), have been converted to calls to the tasking runtime so
11007 -- there is no problem in putting them into procedures.
11009 -- The original accept statement has been expanded into a block in
11010 -- the same fashion as for simple accepts (see Build_Accept_Body).
11012 -- Note: we don't really need to build these procedures for the case
11013 -- where no delay statement is present, but it is just as easy to
11014 -- build them unconditionally, and not significantly inefficient,
11015 -- since if they are short they will be inlined anyway.
11017 -- The procedure declarations have been assembled in Body_List
11019 -- If delays are present, we must compute the required delay.
11020 -- We first generate the declarations:
11022 -- Delay_Index : Boolean := 0;
11023 -- Delay_Min : Some_Time_Type.Time;
11024 -- Delay_Val : Some_Time_Type.Time;
11026 -- Delay_Index will be set to the index of the minimum delay, i.e. the
11027 -- active delay that is actually chosen as the basis for the possible
11028 -- delay if an immediate rendez-vous is not possible.
11030 -- In the most common case there is a single delay statement, and this
11031 -- is handled specially.
11033 if Delay_Count
> 0 then
11035 -- Generate the required declarations
11038 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
11040 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
11042 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
11045 Make_Object_Declaration
(Loc
,
11046 Defining_Identifier
=> Delay_Val
,
11047 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
11050 Make_Object_Declaration
(Loc
,
11051 Defining_Identifier
=> Delay_Index
,
11052 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11053 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11056 Make_Object_Declaration
(Loc
,
11057 Defining_Identifier
=> Delay_Min
,
11058 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11060 Unchecked_Convert_To
(Time_Type
,
11061 Make_Attribute_Reference
(Loc
,
11063 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11064 Attribute_Name
=> Name_Last
))));
11066 -- Create Duration and Delay_Mode objects used for passing a delay
11069 D
:= Make_Temporary
(Loc
, 'D');
11070 M
:= Make_Temporary
(Loc
, 'M');
11076 -- Note that these values are defined in s-osprim.ads and must
11077 -- be kept in sync:
11079 -- Relative : constant := 0;
11080 -- Absolute_Calendar : constant := 1;
11081 -- Absolute_RT : constant := 2;
11083 if Time_Type
= Standard_Duration
then
11084 Discr
:= Make_Integer_Literal
(Loc
, 0);
11086 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11087 Discr
:= Make_Integer_Literal
(Loc
, 1);
11091 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11092 Discr
:= Make_Integer_Literal
(Loc
, 2);
11096 Make_Object_Declaration
(Loc
,
11097 Defining_Identifier
=> D
,
11098 Object_Definition
=>
11099 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11102 Make_Object_Declaration
(Loc
,
11103 Defining_Identifier
=> M
,
11104 Object_Definition
=>
11105 New_Occurrence_Of
(Standard_Integer
, Loc
),
11106 Expression
=> Discr
));
11109 if Check_Guard
then
11111 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11114 Make_Object_Declaration
(Loc
,
11115 Defining_Identifier
=> Guard_Open
,
11116 Object_Definition
=>
11117 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11119 New_Occurrence_Of
(Standard_False
, Loc
)));
11122 -- Delay_Count is zero, don't need M and D set (suppress warning)
11129 if Present
(Terminate_Alt
) then
11131 -- If the terminate alternative guard is False, use
11132 -- Simple_Mode; otherwise use Terminate_Mode.
11134 if Present
(Condition
(Terminate_Alt
)) then
11135 Select_Mode
:= Make_If_Expression
(Loc
,
11136 New_List
(Condition
(Terminate_Alt
),
11137 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11138 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11140 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11143 elsif Else_Present
or Delay_Count
> 0 then
11144 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11147 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11150 Select_Call
:= Make_Select_Call
(Select_Mode
);
11151 Append
(Select_Call
, Stats
);
11153 -- Now generate code to act on the result. There is an entry
11154 -- in this case for each accept statement with a non-null body,
11155 -- followed by a branch to the statements that follow the Accept.
11156 -- In the absence of delay alternatives, we generate:
11159 -- when No_Rendezvous => -- omitted if simple mode
11174 -- Lab0: Else_Statements;
11177 -- Lab1: Trailing_Statements1;
11180 -- Lab2: Trailing_Statements2;
11185 -- Generate label for common exit
11187 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11189 -- First entry is the default case, when no rendezvous is possible
11191 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11193 if Else_Present
then
11195 -- If no rendezvous is possible, the else part is executed
11197 Lab
:= Make_And_Declare_Label
(0);
11198 Alt_Stats
:= New_List
(
11199 Make_Goto_Statement
(Loc
,
11200 Name
=> New_Copy
(Identifier
(Lab
))));
11202 Append
(Lab
, Trailing_List
);
11203 Append_List
(Else_Statements
(N
), Trailing_List
);
11204 Append_To
(Trailing_List
,
11205 Make_Goto_Statement
(Loc
,
11206 Name
=> New_Copy
(Identifier
(End_Lab
))));
11208 Alt_Stats
:= New_List
(
11209 Make_Goto_Statement
(Loc
,
11210 Name
=> New_Copy
(Identifier
(End_Lab
))));
11213 Append_To
(Alt_List
,
11214 Make_Case_Statement_Alternative
(Loc
,
11215 Discrete_Choices
=> Choices
,
11216 Statements
=> Alt_Stats
));
11218 -- We make use of the fact that Accept_Index is an integer type, and
11219 -- generate successive literals for entries for each accept. Only those
11220 -- for which there is a body or trailing statements get a case entry.
11222 Alt
:= First
(Select_Alternatives
(N
));
11223 Proc
:= First
(Body_List
);
11224 while Present
(Alt
) loop
11226 if Nkind
(Alt
) = N_Accept_Alternative
then
11227 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11228 Index
:= Index
+ 1;
11231 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11236 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11237 Process_Delay_Alternative
(Alt
, Delay_Num
);
11238 Delay_Num
:= Delay_Num
+ 1;
11244 -- An others choice is always added to the main case, as well
11245 -- as the delay case (to satisfy the compiler).
11247 Append_To
(Alt_List
,
11248 Make_Case_Statement_Alternative
(Loc
,
11249 Discrete_Choices
=>
11250 New_List
(Make_Others_Choice
(Loc
)),
11252 New_List
(Make_Goto_Statement
(Loc
,
11253 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11255 Accept_Case
:= New_List
(
11256 Make_Case_Statement
(Loc
,
11257 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11258 Alternatives
=> Alt_List
));
11260 Append_List
(Trailing_List
, Accept_Case
);
11261 Append_List
(Body_List
, Decls
);
11263 -- Construct case statement for trailing statements of delay
11264 -- alternatives, if there are several of them.
11266 if Delay_Count
> 1 then
11267 Append_To
(Delay_Alt_List
,
11268 Make_Case_Statement_Alternative
(Loc
,
11269 Discrete_Choices
=>
11270 New_List
(Make_Others_Choice
(Loc
)),
11272 New_List
(Make_Null_Statement
(Loc
))));
11274 Delay_Case
:= New_List
(
11275 Make_Case_Statement
(Loc
,
11276 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11277 Alternatives
=> Delay_Alt_List
));
11279 Delay_Case
:= Delay_Alt_List
;
11282 -- If there are no delay alternatives, we append the case statement
11283 -- to the statement list.
11285 if Delay_Count
= 0 then
11286 Append_List
(Accept_Case
, Stats
);
11288 -- Delay alternatives present
11291 -- If delay alternatives are present we generate:
11293 -- find minimum delay.
11294 -- DX := minimum delay;
11295 -- M := <delay mode>;
11296 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11299 -- if X = No_Rendezvous then
11300 -- case statement for delay statements.
11302 -- case statement for accept alternatives.
11313 -- The type of the delay expression is known to be legal
11315 if Time_Type
= Standard_Duration
then
11316 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11318 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11319 Conv
:= Make_Function_Call
(Loc
,
11320 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11321 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11325 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11327 Conv
:= Make_Function_Call
(Loc
,
11328 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11329 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11332 Stmt
:= Make_Assignment_Statement
(Loc
,
11333 Name
=> New_Occurrence_Of
(D
, Loc
),
11334 Expression
=> Conv
);
11336 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11338 Parms
:= Parameter_Associations
(Select_Call
);
11340 Parm
:= First
(Parms
);
11341 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11345 pragma Assert
(Present
(Parm
));
11346 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11349 -- Prepare two new parameters of Duration and Delay_Mode type
11350 -- which represent the value and the mode of the minimum delay.
11353 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11354 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11356 -- Create a call to RTS
11358 Rewrite
(Select_Call
,
11359 Make_Procedure_Call_Statement
(Loc
,
11360 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11361 Parameter_Associations
=> Parms
));
11363 -- This new call should follow the calculation of the minimum
11366 Insert_List_Before
(Select_Call
, Delay_List
);
11368 if Check_Guard
then
11370 Make_Implicit_If_Statement
(N
,
11371 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11372 Then_Statements
=> New_List
(
11373 New_Copy_Tree
(Stmt
),
11374 New_Copy_Tree
(Select_Call
)),
11375 Else_Statements
=> Accept_Or_Raise
);
11376 Rewrite
(Select_Call
, Stmt
);
11378 Insert_Before
(Select_Call
, Stmt
);
11382 Make_Implicit_If_Statement
(N
,
11383 Condition
=> Make_Op_Eq
(Loc
,
11384 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11386 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11388 Then_Statements
=> Delay_Case
,
11389 Else_Statements
=> Accept_Case
);
11391 Append
(Cases
, Stats
);
11395 Append
(End_Lab
, Stats
);
11397 -- Replace accept statement with appropriate block
11400 Make_Block_Statement
(Loc
,
11401 Declarations
=> Decls
,
11402 Handled_Statement_Sequence
=>
11403 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11406 -- Note: have to worry more about abort deferral in above code ???
11408 -- Final step is to unstack the Accept_Address entries for all accept
11409 -- statements appearing in accept alternatives in the select statement
11411 Alt
:= First
(Alts
);
11412 while Present
(Alt
) loop
11413 if Nkind
(Alt
) = N_Accept_Alternative
then
11414 Remove_Last_Elmt
(Accept_Address
11415 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11420 end Expand_N_Selective_Accept
;
11422 -------------------------------------------
11423 -- Expand_N_Single_Protected_Declaration --
11424 -------------------------------------------
11426 -- A single protected declaration should never be present after semantic
11427 -- analysis because it is transformed into a protected type declaration
11428 -- and an accompanying anonymous object. This routine ensures that the
11429 -- transformation takes place.
11431 procedure Expand_N_Single_Protected_Declaration
(N
: Node_Id
) is
11433 raise Program_Error
;
11434 end Expand_N_Single_Protected_Declaration
;
11436 --------------------------------------
11437 -- Expand_N_Single_Task_Declaration --
11438 --------------------------------------
11440 -- A single task declaration should never be present after semantic
11441 -- analysis because it is transformed into a task type declaration and
11442 -- an accompanying anonymous object. This routine ensures that the
11443 -- transformation takes place.
11445 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11447 raise Program_Error
;
11448 end Expand_N_Single_Task_Declaration
;
11450 ------------------------
11451 -- Expand_N_Task_Body --
11452 ------------------------
11454 -- Given a task body
11456 -- task body tname is
11462 -- This expansion routine converts it into a procedure and sets the
11463 -- elaboration flag for the procedure to true, to represent the fact
11464 -- that the task body is now elaborated:
11466 -- procedure tnameB (_Task : access tnameV) is
11467 -- discriminal : dtype renames _Task.discriminant;
11469 -- procedure _clean is
11471 -- Abort_Defer.all;
11473 -- Abort_Undefer.all;
11478 -- Abort_Undefer.all;
11480 -- System.Task_Stages.Complete_Activation;
11488 -- In addition, if the task body is an activator, then a call to activate
11489 -- tasks is added at the start of the statements, before the call to
11490 -- Complete_Activation, and if in addition the task is a master then it
11491 -- must be established as a master. These calls are inserted and analyzed
11492 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11495 -- There is one discriminal declaration line generated for each
11496 -- discriminant that is present to provide an easy reference point for
11497 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11499 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11500 -- task body procedures have a profile (Arg : System.Address). That is
11501 -- needed because GNARLI has to use the same access-to-subprogram type
11502 -- for all task types. We depend here on knowing that in GNAT, passing
11503 -- an address argument by value is identical to passing a record value
11504 -- by access (in either case a single pointer is passed), so even though
11505 -- this procedure has the wrong profile. In fact it's all OK, since the
11506 -- callings sequence is identical.
11508 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11509 Loc
: constant Source_Ptr
:= Sloc
(N
);
11510 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11514 Insert_Nod
: Node_Id
;
11515 -- Used to determine the proper location of wrapper body insertions
11518 -- if no task body procedure, means we had an error in configurable
11519 -- run-time mode, and there is no point in proceeding further.
11521 if No
(Task_Body_Procedure
(Ttyp
)) then
11525 -- Add renaming declarations for discriminals and a declaration for the
11526 -- entry family index (if applicable).
11528 Install_Private_Data_Declarations
11529 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11531 -- Add a call to Abort_Undefer at the very beginning of the task
11532 -- body since this body is called with abort still deferred.
11534 if Abort_Allowed
then
11535 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11537 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11541 -- The statement part has already been protected with an at_end and
11542 -- cleanup actions. The call to Complete_Activation must be placed
11543 -- at the head of the sequence of statements of that block. The
11544 -- declarations have been merged in this sequence of statements but
11545 -- the first real statement is accessible from the First_Real_Statement
11546 -- field (which was set for exactly this purpose).
11548 if Restricted_Profile
then
11549 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11551 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11555 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11559 Make_Subprogram_Body
(Loc
,
11560 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11561 Declarations
=> Declarations
(N
),
11562 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11563 Set_Is_Task_Body_Procedure
(New_N
);
11565 -- If the task contains generic instantiations, cleanup actions are
11566 -- delayed until after instantiation. Transfer the activation chain to
11567 -- the subprogram, to insure that the activation call is properly
11568 -- generated. It the task body contains inner tasks, indicate that the
11569 -- subprogram is a task master.
11571 if Delay_Cleanups
(Ttyp
) then
11572 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11573 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11576 Rewrite
(N
, New_N
);
11579 -- Set elaboration flag immediately after task body. If the body is a
11580 -- subunit, the flag is set in the declarative part containing the stub.
11582 if Nkind
(Parent
(N
)) /= N_Subunit
then
11584 Make_Assignment_Statement
(Loc
,
11586 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11587 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11590 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11591 -- the task body. At this point all wrapper specs have been created,
11592 -- frozen and included in the dispatch table for the task type.
11594 if Ada_Version
>= Ada_2005
then
11595 if Nkind
(Parent
(N
)) = N_Subunit
then
11596 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11601 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11603 end Expand_N_Task_Body
;
11605 ------------------------------------
11606 -- Expand_N_Task_Type_Declaration --
11607 ------------------------------------
11609 -- We have several things to do. First we must create a Boolean flag used
11610 -- to mark if the body is elaborated yet. This variable gets set to True
11611 -- when the body of the task is elaborated (we can't rely on the normal
11612 -- ABE mechanism for the task body, since we need to pass an access to
11613 -- this elaboration boolean to the runtime routines).
11615 -- taskE : aliased Boolean := False;
11617 -- Next a variable is declared to hold the task stack size (either the
11618 -- default : Unspecified_Size, or a value that is set by a pragma
11619 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11620 -- the variable is initialized with this value:
11622 -- taskZ : Size_Type := Unspecified_Size;
11624 -- taskZ : Size_Type := Size_Type (size_expression);
11626 -- Note: No variable is needed to hold the task relative deadline since
11627 -- its value would never be static because the parameter is of a private
11628 -- type (Ada.Real_Time.Time_Span).
11630 -- Next we create a corresponding record type declaration used to represent
11631 -- values of this task. The general form of this type declaration is
11633 -- type taskV (discriminants) is record
11634 -- _Task_Id : Task_Id;
11635 -- entry_family : array (bounds) of Void;
11636 -- _Priority : Integer := priority_expression;
11637 -- _Size : Size_Type := size_expression;
11638 -- _Secondary_Stack_Size : Size_Type := size_expression;
11639 -- _Task_Info : Task_Info_Type := task_info_expression;
11640 -- _CPU : Integer := cpu_range_expression;
11641 -- _Relative_Deadline : Time_Span := time_span_expression;
11642 -- _Domain : Dispatching_Domain := dd_expression;
11645 -- The discriminants are present only if the corresponding task type has
11646 -- discriminants, and they exactly mirror the task type discriminants.
11648 -- The Id field is always present. It contains the Task_Id value, as set by
11649 -- the call to Create_Task. Note that although the task is limited, the
11650 -- task value record type is not limited, so there is no problem in passing
11651 -- this field as an out parameter to Create_Task.
11653 -- One entry_family component is present for each entry family in the task
11654 -- definition. The bounds correspond to the bounds of the entry family
11655 -- (which may depend on discriminants). The element type is void, since we
11656 -- only need the bounds information for determining the entry index. Note
11657 -- that the use of an anonymous array would normally be illegal in this
11658 -- context, but this is a parser check, and the semantics is quite prepared
11659 -- to handle such a case.
11661 -- The _Size field is present only if a Storage_Size pragma appears in the
11662 -- task definition. The expression captures the argument that was present
11663 -- in the pragma, and is used to override the task stack size otherwise
11664 -- associated with the task type.
11666 -- The _Secondary_Stack_Size field is present only the task entity has a
11667 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11668 -- when the record init proc is built, to capture the expression of the
11669 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11670 -- be filled here since aspect evaluations are delayed till the freeze
11673 -- The _Priority field is present only if the task entity has a Priority or
11674 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11675 -- definition clause). It will be filled at the freeze point, when the
11676 -- record init proc is built, to capture the expression of the rep item
11677 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11678 -- here since aspect evaluations are delayed till the freeze point.
11680 -- The _Task_Info field is present only if a Task_Info pragma appears in
11681 -- the task definition. The expression captures the argument that was
11682 -- present in the pragma, and is used to provide the Task_Image parameter
11683 -- to the call to Create_Task.
11685 -- The _CPU field is present only if the task entity has a CPU rep item
11686 -- (pragma, aspect specification or attribute definition clause). It will
11687 -- be filled at the freeze point, when the record init proc is built, to
11688 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11689 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11690 -- are delayed till the freeze point.
11692 -- The _Relative_Deadline field is present only if a Relative_Deadline
11693 -- pragma appears in the task definition. The expression captures the
11694 -- argument that was present in the pragma, and is used to provide the
11695 -- Relative_Deadline parameter to the call to Create_Task.
11697 -- The _Domain field is present only if the task entity has a
11698 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11699 -- definition clause). It will be filled at the freeze point, when the
11700 -- record init proc is built, to capture the expression of the rep item
11701 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11702 -- here since aspect evaluations are delayed till the freeze point.
11704 -- When a task is declared, an instance of the task value record is
11705 -- created. The elaboration of this declaration creates the correct bounds
11706 -- for the entry families, and also evaluates the size, priority, and
11707 -- task_Info expressions if needed. The initialization routine for the task
11708 -- type itself then calls Create_Task with appropriate parameters to
11709 -- initialize the value of the Task_Id field.
11711 -- Note: the address of this record is passed as the "Discriminants"
11712 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11713 -- body procedure, it does not matter that it does not quite match the
11714 -- GNARLI model of what is being passed (the record contains more than just
11715 -- the discriminants, but the discriminants can be found from the record
11718 -- The Entity_Id for this created record type is placed in the
11719 -- Corresponding_Record_Type field of the associated task type entity.
11721 -- Next we create a procedure specification for the task body procedure:
11723 -- procedure taskB (_Task : access taskV);
11725 -- Note that this must come after the record type declaration, since
11726 -- the spec refers to this type. It turns out that the initialization
11727 -- procedure for the value type references the task body spec, but that's
11728 -- fine, since it won't be generated till the freeze point for the type,
11729 -- which is certainly after the task body spec declaration.
11731 -- Finally, we set the task index value field of the entry attribute in
11732 -- the case of a simple entry.
11734 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11735 Loc
: constant Source_Ptr
:= Sloc
(N
);
11736 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11737 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11738 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11739 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11741 Body_Decl
: Node_Id
;
11743 Decl_Stack
: Node_Id
;
11745 Elab_Decl
: Node_Id
;
11746 Ent_Stack
: Entity_Id
;
11747 Proc_Spec
: Node_Id
;
11748 Rec_Decl
: Node_Id
;
11749 Rec_Ent
: Entity_Id
;
11750 Size_Decl
: Entity_Id
;
11751 Task_Size
: Node_Id
;
11753 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11754 -- Searches the task definition T for the first occurrence of the pragma
11755 -- Relative Deadline. The caller has ensured that the pragma is present
11756 -- in the task definition. Note that this routine cannot be implemented
11757 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11758 -- not chained because their expansion into a procedure call statement
11759 -- would cause a break in the chain.
11761 ----------------------------------
11762 -- Get_Relative_Deadline_Pragma --
11763 ----------------------------------
11765 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11769 N
:= First
(Visible_Declarations
(T
));
11770 while Present
(N
) loop
11771 if Nkind
(N
) = N_Pragma
11772 and then Pragma_Name
(N
) = Name_Relative_Deadline
11780 N
:= First
(Private_Declarations
(T
));
11781 while Present
(N
) loop
11782 if Nkind
(N
) = N_Pragma
11783 and then Pragma_Name
(N
) = Name_Relative_Deadline
11791 raise Program_Error
;
11792 end Get_Relative_Deadline_Pragma
;
11794 -- Start of processing for Expand_N_Task_Type_Declaration
11797 -- If already expanded, nothing to do
11799 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11803 -- Here we will do the expansion
11805 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11807 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11808 Cdecls
:= Component_Items
(Component_List
11809 (Type_Definition
(Rec_Decl
)));
11811 Qualify_Entity_Names
(N
);
11813 -- First create the elaboration variable
11816 Make_Object_Declaration
(Loc
,
11817 Defining_Identifier
=>
11818 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11819 Chars
=> New_External_Name
(Tasknm
, 'E')),
11820 Aliased_Present
=> True,
11821 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11822 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11824 Insert_After
(N
, Elab_Decl
);
11826 -- Next create the declaration of the size variable (tasknmZ)
11828 Set_Storage_Size_Variable
(Tasktyp
,
11829 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11830 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11832 if Present
(Taskdef
)
11833 and then Has_Storage_Size_Pragma
(Taskdef
)
11835 Is_OK_Static_Expression
11837 (First
(Pragma_Argument_Associations
11838 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11841 Make_Object_Declaration
(Loc
,
11842 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11843 Object_Definition
=>
11844 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11846 Convert_To
(RTE
(RE_Size_Type
),
11848 (Expression
(First
(Pragma_Argument_Associations
11850 (TaskId
, Name_Storage_Size
)))))));
11854 Make_Object_Declaration
(Loc
,
11855 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11856 Object_Definition
=>
11857 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11859 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11862 Insert_After
(Elab_Decl
, Size_Decl
);
11864 -- Next build the rest of the corresponding record declaration. This is
11865 -- done last, since the corresponding record initialization procedure
11866 -- will reference the previously created entities.
11868 -- Fill in the component declarations -- first the _Task_Id field
11871 Make_Component_Declaration
(Loc
,
11872 Defining_Identifier
=>
11873 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11874 Component_Definition
=>
11875 Make_Component_Definition
(Loc
,
11876 Aliased_Present
=> False,
11877 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11880 -- Declare static ATCB (that is, created by the expander) if we are
11881 -- using the Restricted run time.
11883 if Restricted_Profile
then
11885 Make_Component_Declaration
(Loc
,
11886 Defining_Identifier
=>
11887 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11889 Component_Definition
=>
11890 Make_Component_Definition
(Loc
,
11891 Aliased_Present
=> True,
11892 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11894 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11897 Make_Index_Or_Discriminant_Constraint
(Loc
,
11899 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11903 -- Declare static stack (that is, created by the expander) if we are
11904 -- using the Restricted run time on a bare board configuration.
11906 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11908 -- First we need to extract the appropriate stack size
11910 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11912 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11914 Expr_N
: constant Node_Id
:=
11915 Expression
(First
(
11916 Pragma_Argument_Associations
(
11917 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11918 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11919 P
: constant Node_Id
:= Parent
(Expr_N
);
11922 -- The stack is defined inside the corresponding record.
11923 -- Therefore if the size of the stack is set by means of
11924 -- a discriminant, we must reference the discriminant of the
11925 -- corresponding record type.
11927 if Nkind
(Expr_N
) in N_Has_Entity
11928 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11932 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11934 Set_Parent
(Task_Size
, P
);
11935 Set_Etype
(Task_Size
, Etyp
);
11936 Set_Analyzed
(Task_Size
);
11939 Task_Size
:= New_Copy_Tree
(Expr_N
);
11945 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11948 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11949 Defining_Identifier
=> Ent_Stack
,
11951 Component_Definition
=>
11952 Make_Component_Definition
(Loc
,
11953 Aliased_Present
=> True,
11954 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11956 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11959 Make_Index_Or_Discriminant_Constraint
(Loc
,
11960 Constraints
=> New_List
(Make_Range
(Loc
,
11961 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11962 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11965 Append_To
(Cdecls
, Decl_Stack
);
11967 -- The appropriate alignment for the stack is ensured by the run-time
11968 -- code in charge of task creation.
11972 -- Declare a static secondary stack if the conditions for a statically
11973 -- generated stack are met.
11975 if Create_Secondary_Stack_For_Task
(TaskId
) then
11977 Size_Expr
: constant Node_Id
:=
11978 Expression
(First
(
11979 Pragma_Argument_Associations
(
11980 Get_Rep_Pragma
(TaskId
,
11981 Name_Secondary_Stack_Size
))));
11983 Stack_Size
: Node_Id
;
11986 -- The secondary stack is defined inside the corresponding
11987 -- record. Therefore if the size of the stack is set by means
11988 -- of a discriminant, we must reference the discriminant of the
11989 -- corresponding record type.
11991 if Nkind
(Size_Expr
) in N_Has_Entity
11992 and then Present
(Discriminal_Link
(Entity
(Size_Expr
)))
11996 (CR_Discriminant
(Discriminal_Link
(Entity
(Size_Expr
))),
11998 Set_Parent
(Stack_Size
, Parent
(Size_Expr
));
11999 Set_Etype
(Stack_Size
, Etype
(Size_Expr
));
12000 Set_Analyzed
(Stack_Size
);
12003 Stack_Size
:= New_Copy_Tree
(Size_Expr
);
12006 -- Create the secondary stack for the task
12009 Make_Component_Declaration
(Loc
,
12010 Defining_Identifier
=>
12011 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack
),
12012 Component_Definition
=>
12013 Make_Component_Definition
(Loc
,
12014 Aliased_Present
=> True,
12015 Subtype_Indication
=>
12016 Make_Subtype_Indication
(Loc
,
12018 New_Occurrence_Of
(RTE
(RE_SS_Stack
), Loc
),
12020 Make_Index_Or_Discriminant_Constraint
(Loc
,
12021 Constraints
=> New_List
(
12022 Convert_To
(RTE
(RE_Size_Type
),
12025 Append_To
(Cdecls
, Decl_SS
);
12029 -- Add components for entry families
12031 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
12033 -- Add the _Priority component if a Interrupt_Priority or Priority rep
12034 -- item is present.
12036 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
12038 Make_Component_Declaration
(Loc
,
12039 Defining_Identifier
=>
12040 Make_Defining_Identifier
(Loc
, Name_uPriority
),
12041 Component_Definition
=>
12042 Make_Component_Definition
(Loc
,
12043 Aliased_Present
=> False,
12044 Subtype_Indication
=>
12045 New_Occurrence_Of
(Standard_Integer
, Loc
))));
12048 -- Add the _Size component if a Storage_Size pragma is present
12050 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
12052 Make_Component_Declaration
(Loc
,
12053 Defining_Identifier
=>
12054 Make_Defining_Identifier
(Loc
, Name_uSize
),
12056 Component_Definition
=>
12057 Make_Component_Definition
(Loc
,
12058 Aliased_Present
=> False,
12059 Subtype_Indication
=>
12060 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
12063 Convert_To
(RTE
(RE_Size_Type
),
12065 Expression
(First
(
12066 Pragma_Argument_Associations
(
12067 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
12070 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
12071 -- pragma is present.
12074 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
12077 Make_Component_Declaration
(Loc
,
12078 Defining_Identifier
=>
12079 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack_Size
),
12081 Component_Definition
=>
12082 Make_Component_Definition
(Loc
,
12083 Aliased_Present
=> False,
12084 Subtype_Indication
=>
12085 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
))));
12088 -- Add the _Task_Info component if a Task_Info pragma is present
12090 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
12092 Make_Component_Declaration
(Loc
,
12093 Defining_Identifier
=>
12094 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
12096 Component_Definition
=>
12097 Make_Component_Definition
(Loc
,
12098 Aliased_Present
=> False,
12099 Subtype_Indication
=>
12100 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
12102 Expression
=> New_Copy
(
12103 Expression
(First
(
12104 Pragma_Argument_Associations
(
12106 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
12109 -- Add the _CPU component if a CPU rep item is present
12111 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
12113 Make_Component_Declaration
(Loc
,
12114 Defining_Identifier
=>
12115 Make_Defining_Identifier
(Loc
, Name_uCPU
),
12117 Component_Definition
=>
12118 Make_Component_Definition
(Loc
,
12119 Aliased_Present
=> False,
12120 Subtype_Indication
=>
12121 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
12124 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
12125 -- present. If we are using a restricted run time this component will
12126 -- not be added (deadlines are not allowed by the Ravenscar profile),
12127 -- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
12130 if (not Restricted_Profile
or else Task_Dispatching_Policy
= 'E')
12131 and then Present
(Taskdef
)
12132 and then Has_Relative_Deadline_Pragma
(Taskdef
)
12135 Make_Component_Declaration
(Loc
,
12136 Defining_Identifier
=>
12137 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
12139 Component_Definition
=>
12140 Make_Component_Definition
(Loc
,
12141 Aliased_Present
=> False,
12142 Subtype_Indication
=>
12143 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
12146 Convert_To
(RTE
(RE_Time_Span
),
12148 Expression
(First
(
12149 Pragma_Argument_Associations
(
12150 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12153 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12154 -- item is present. If we are using a restricted run time this component
12155 -- will not be added (dispatching domains are not allowed by the
12156 -- Ravenscar profile).
12158 if not Restricted_Profile
12161 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12164 Make_Component_Declaration
(Loc
,
12165 Defining_Identifier
=>
12166 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12168 Component_Definition
=>
12169 Make_Component_Definition
(Loc
,
12170 Aliased_Present
=> False,
12171 Subtype_Indication
=>
12173 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12176 Insert_After
(Size_Decl
, Rec_Decl
);
12178 -- Analyze the record declaration immediately after construction,
12179 -- because the initialization procedure is needed for single task
12180 -- declarations before the next entity is analyzed.
12182 Analyze
(Rec_Decl
);
12184 -- Create the declaration of the task body procedure
12186 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12188 Make_Subprogram_Declaration
(Loc
,
12189 Specification
=> Proc_Spec
);
12190 Set_Is_Task_Body_Procedure
(Body_Decl
);
12192 Insert_After
(Rec_Decl
, Body_Decl
);
12194 -- The subprogram does not comes from source, so we have to indicate the
12195 -- need for debugging information explicitly.
12197 if Comes_From_Source
(Original_Node
(N
)) then
12198 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12201 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12202 -- the corresponding record has been frozen.
12204 if Ada_Version
>= Ada_2005
then
12205 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12208 -- Ada 2005 (AI-345): We must defer freezing to allow further
12209 -- declaration of primitive subprograms covering task interfaces
12211 if Ada_Version
<= Ada_95
then
12213 -- Now we can freeze the corresponding record. This needs manually
12214 -- freezing, since it is really part of the task type, and the task
12215 -- type is frozen at this stage. We of course need the initialization
12216 -- procedure for this corresponding record type and we won't get it
12217 -- in time if we don't freeze now.
12220 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
12222 if Is_Non_Empty_List
(L
) then
12223 Insert_List_After
(Body_Decl
, L
);
12228 -- Complete the expansion of access types to the current task type, if
12229 -- any were declared.
12231 Expand_Previous_Access_Type
(Tasktyp
);
12233 -- Create wrappers for entries that have contract cases, preconditions
12234 -- and postconditions.
12240 Ent
:= First_Entity
(Tasktyp
);
12241 while Present
(Ent
) loop
12242 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
) then
12243 Build_Contract_Wrapper
(Ent
, N
);
12249 end Expand_N_Task_Type_Declaration
;
12251 -------------------------------
12252 -- Expand_N_Timed_Entry_Call --
12253 -------------------------------
12255 -- A timed entry call in normal case is not implemented using ATC mechanism
12256 -- anymore for efficiency reason.
12266 -- is expanded as follows:
12268 -- 1) When T.E is a task entry_call;
12272 -- X : Task_Entry_Index := <entry index>;
12273 -- DX : Duration := To_Duration (D);
12274 -- M : Delay_Mode := <discriminant>;
12275 -- P : parms := (parm, parm, parm);
12278 -- Timed_Protected_Entry_Call
12279 -- (<acceptor-task>, X, P'Address, DX, M, B);
12287 -- 2) When T.E is a protected entry_call;
12291 -- X : Protected_Entry_Index := <entry index>;
12292 -- DX : Duration := To_Duration (D);
12293 -- M : Delay_Mode := <discriminant>;
12294 -- P : parms := (parm, parm, parm);
12297 -- Timed_Protected_Entry_Call
12298 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12306 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12307 -- is no delay and the triggering statements are executed. We first
12308 -- determine the kind of the triggering call and then execute a
12309 -- synchronized operation or a direct call.
12312 -- B : Boolean := False;
12313 -- C : Ada.Tags.Prim_Op_Kind;
12314 -- DX : Duration := To_Duration (D)
12315 -- K : Ada.Tags.Tagged_Kind :=
12316 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12317 -- M : Integer :=...;
12318 -- P : Parameters := (Param1 .. ParamN);
12322 -- if K = Ada.Tags.TK_Limited_Tagged
12323 -- or else K = Ada.Tags.TK_Tagged
12325 -- <dispatching-call>;
12330 -- Ada.Tags.Get_Offset_Index
12331 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12333 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12335 -- if C = POK_Protected_Entry
12336 -- or else C = POK_Task_Entry
12338 -- Param1 := P.Param1;
12340 -- ParamN := P.ParamN;
12344 -- if C = POK_Procedure
12345 -- or else C = POK_Protected_Procedure
12346 -- or else C = POK_Task_Procedure
12348 -- <dispatching-call>;
12354 -- <triggering-statements>
12356 -- <timed-statements>
12360 -- The triggering statement and the sequence of timed statements have not
12361 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12362 -- global references if within an instantiation.
12364 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12365 Loc
: constant Source_Ptr
:= Sloc
(N
);
12368 Blk_Typ
: Entity_Id
;
12370 Call_Ent
: Entity_Id
;
12371 Conc_Typ_Stmts
: List_Id
;
12372 Concval
: Node_Id
:= Empty
; -- init to avoid warning
12373 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12376 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12378 D_Type
: Entity_Id
;
12381 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12382 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12387 Is_Disp_Select
: Boolean;
12388 Lim_Typ_Stmts
: List_Id
;
12397 B
: Entity_Id
; -- Call status flag
12398 C
: Entity_Id
; -- Call kind
12399 D
: Entity_Id
; -- Delay
12400 K
: Entity_Id
; -- Tagged kind
12401 M
: Entity_Id
; -- Delay mode
12402 P
: Entity_Id
; -- Parameter block
12403 S
: Entity_Id
; -- Primitive operation slot
12405 -- Start of processing for Expand_N_Timed_Entry_Call
12408 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12409 -- was already reported on spec, so do not attempt to expand the call.
12411 if Restriction_Active
(No_Select_Statements
) then
12415 Process_Statements_For_Controlled_Objects
(E_Alt
);
12416 Process_Statements_For_Controlled_Objects
(D_Alt
);
12418 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12420 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12421 -- may wrap them in blocks.
12423 E_Stats
:= Statements
(E_Alt
);
12424 D_Stats
:= Statements
(D_Alt
);
12426 -- The arguments in the call may require dynamic allocation, and the
12427 -- call statement may have been transformed into a block. The block
12428 -- may contain additional declarations for internal entities, and the
12429 -- original call is found by sequential search.
12431 if Nkind
(E_Call
) = N_Block_Statement
then
12432 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12433 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12434 N_Entry_Call_Statement
)
12441 Ada_Version
>= Ada_2005
12442 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12444 if Is_Disp_Select
then
12445 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12451 -- B : Boolean := False;
12453 B
:= Build_B
(Loc
, Decls
);
12456 -- C : Ada.Tags.Prim_Op_Kind;
12458 C
:= Build_C
(Loc
, Decls
);
12460 -- Because the analysis of all statements was disabled, manually
12461 -- analyze the delay statement.
12464 D_Stat
:= Original_Node
(D_Stat
);
12467 -- Build an entry call using Simple_Entry_Call
12469 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12470 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12472 Decls
:= Declarations
(E_Call
);
12473 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12482 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12485 Make_Object_Declaration
(Loc
,
12486 Defining_Identifier
=> B
,
12487 Object_Definition
=>
12488 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12491 -- Duration and mode processing
12493 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12495 -- Use the type of the delay expression (Calendar or Real_Time) to
12496 -- generate the appropriate conversion.
12498 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12499 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12500 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12502 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12503 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12505 Make_Function_Call
(Loc
,
12506 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12507 Parameter_Associations
=>
12508 New_List
(New_Copy
(Expression
(D_Stat
))));
12510 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12511 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12513 Make_Function_Call
(Loc
,
12514 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12515 Parameter_Associations
=>
12516 New_List
(New_Copy
(Expression
(D_Stat
))));
12519 D
:= Make_Temporary
(Loc
, 'D');
12525 Make_Object_Declaration
(Loc
,
12526 Defining_Identifier
=> D
,
12527 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12529 M
:= Make_Temporary
(Loc
, 'M');
12532 -- M : Integer := (0 | 1 | 2);
12535 Make_Object_Declaration
(Loc
,
12536 Defining_Identifier
=> M
,
12537 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12538 Expression
=> D_Disc
));
12540 -- Do the assignment at this stage only because the evaluation of the
12541 -- expression must not occur before (see ACVC C97302A).
12544 Make_Assignment_Statement
(Loc
,
12545 Name
=> New_Occurrence_Of
(D
, Loc
),
12546 Expression
=> D_Conv
));
12548 -- Parameter block processing
12550 -- Manually create the parameter block for dispatching calls. In the
12551 -- case of entries, the block has already been created during the call
12552 -- to Build_Simple_Entry_Call.
12554 if Is_Disp_Select
then
12556 -- Tagged kind processing, generate:
12557 -- K : Ada.Tags.Tagged_Kind :=
12558 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12560 K
:= Build_K
(Loc
, Decls
, Obj
);
12562 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12564 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12566 -- Dispatch table slot processing, generate:
12569 S
:= Build_S
(Loc
, Decls
);
12572 -- S := Ada.Tags.Get_Offset_Index
12573 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12576 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12579 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12581 -- where Obj is the controlling formal parameter, S is the dispatch
12582 -- table slot number of the dispatching operation, P is the wrapped
12583 -- parameter block, D is the duration, M is the duration mode, C is
12584 -- the call kind and B is the call status.
12586 Params
:= New_List
;
12588 Append_To
(Params
, New_Copy_Tree
(Obj
));
12589 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12591 Make_Attribute_Reference
(Loc
,
12592 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12593 Attribute_Name
=> Name_Address
));
12594 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12595 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12596 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12597 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12599 Append_To
(Conc_Typ_Stmts
,
12600 Make_Procedure_Call_Statement
(Loc
,
12604 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12605 Parameter_Associations
=> Params
));
12608 -- if C = POK_Protected_Entry
12609 -- or else C = POK_Task_Entry
12611 -- Param1 := P.Param1;
12613 -- ParamN := P.ParamN;
12616 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12618 -- Generate the if statement only when the packed parameters need
12619 -- explicit assignments to their corresponding actuals.
12621 if Present
(Unpack
) then
12622 Append_To
(Conc_Typ_Stmts
,
12623 Make_Implicit_If_Statement
(N
,
12629 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12632 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12636 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12638 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12640 Then_Statements
=> Unpack
));
12646 -- if C = POK_Procedure
12647 -- or else C = POK_Protected_Procedure
12648 -- or else C = POK_Task_Procedure
12650 -- <dispatching-call>
12654 N_Stats
:= New_List
(
12655 Make_Implicit_If_Statement
(N
,
12660 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12662 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12668 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12670 New_Occurrence_Of
(RTE
(
12671 RE_POK_Protected_Procedure
), Loc
)),
12674 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12677 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12679 Then_Statements
=> New_List
(E_Call
)));
12681 Append_To
(Conc_Typ_Stmts
,
12682 Make_Implicit_If_Statement
(N
,
12683 Condition
=> New_Occurrence_Of
(B
, Loc
),
12684 Then_Statements
=> N_Stats
));
12687 -- <dispatching-call>;
12691 New_List
(New_Copy_Tree
(E_Call
),
12692 Make_Assignment_Statement
(Loc
,
12693 Name
=> New_Occurrence_Of
(B
, Loc
),
12694 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12697 -- if K = Ada.Tags.TK_Limited_Tagged
12698 -- or else K = Ada.Tags.TK_Tagged
12706 Make_Implicit_If_Statement
(N
,
12707 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12708 Then_Statements
=> Lim_Typ_Stmts
,
12709 Else_Statements
=> Conc_Typ_Stmts
));
12714 -- <triggering-statements>
12716 -- <timed-statements>
12720 Make_Implicit_If_Statement
(N
,
12721 Condition
=> New_Occurrence_Of
(B
, Loc
),
12722 Then_Statements
=> E_Stats
,
12723 Else_Statements
=> D_Stats
));
12726 -- Simple case of a nondispatching trigger. Skip assignments to
12727 -- temporaries created for in-out parameters.
12729 -- This makes unwarranted assumptions about the shape of the expanded
12730 -- tree for the call, and should be cleaned up ???
12732 Stmt
:= First
(Stmts
);
12733 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12737 -- Do the assignment at this stage only because the evaluation
12738 -- of the expression must not occur before (see ACVC C97302A).
12740 Insert_Before
(Stmt
,
12741 Make_Assignment_Statement
(Loc
,
12742 Name
=> New_Occurrence_Of
(D
, Loc
),
12743 Expression
=> D_Conv
));
12746 Params
:= Parameter_Associations
(Call
);
12748 -- For a protected type, we build a Timed_Protected_Entry_Call
12750 if Is_Protected_Type
(Etype
(Concval
)) then
12752 -- Create a new call statement
12754 Param
:= First
(Params
);
12755 while Present
(Param
)
12756 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12761 Dummy
:= Remove_Next
(Next
(Param
));
12763 -- Remove garbage is following the Cancel_Param if present
12765 Dummy
:= Next
(Param
);
12767 -- Remove the mode of the Protected_Entry_Call call, then remove
12768 -- the Communication_Block of the Protected_Entry_Call call, and
12769 -- finally add Duration and a Delay_Mode parameter
12771 pragma Assert
(Present
(Param
));
12772 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12774 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12776 -- Add a Boolean flag for successful entry call
12778 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12780 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12781 when System_Tasking_Protected_Objects_Entries
=>
12783 Make_Procedure_Call_Statement
(Loc
,
12786 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12787 Parameter_Associations
=> Params
));
12790 raise Program_Error
;
12793 -- For the task case, build a Timed_Task_Entry_Call
12796 -- Create a new call statement
12798 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12799 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12800 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12803 Make_Procedure_Call_Statement
(Loc
,
12805 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12806 Parameter_Associations
=> Params
));
12810 Make_Implicit_If_Statement
(N
,
12811 Condition
=> New_Occurrence_Of
(B
, Loc
),
12812 Then_Statements
=> E_Stats
,
12813 Else_Statements
=> D_Stats
));
12817 Make_Block_Statement
(Loc
,
12818 Declarations
=> Decls
,
12819 Handled_Statement_Sequence
=>
12820 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12823 end Expand_N_Timed_Entry_Call
;
12825 ----------------------------------------
12826 -- Expand_Protected_Body_Declarations --
12827 ----------------------------------------
12829 procedure Expand_Protected_Body_Declarations
12831 Spec_Id
: Entity_Id
)
12834 if No_Run_Time_Mode
then
12835 Error_Msg_CRT
("protected body", N
);
12838 elsif Expander_Active
then
12840 -- Associate discriminals with the first subprogram or entry body to
12843 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12844 Set_Discriminals
(Parent
(Spec_Id
));
12847 end Expand_Protected_Body_Declarations
;
12849 -------------------------
12850 -- External_Subprogram --
12851 -------------------------
12853 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12854 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12857 -- The internal and external subprograms follow each other on the entity
12858 -- chain. Note that previously private operations had no separate
12859 -- external subprogram. We now create one in all cases, because a
12860 -- private operation may actually appear in an external call, through
12861 -- a 'Access reference used for a callback.
12863 -- If the operation is a function that returns an anonymous access type,
12864 -- the corresponding itype appears before the operation, and must be
12867 -- This mechanism is fragile, there should be a real link between the
12868 -- two versions of the operation, but there is no place to put it ???
12870 if Is_Access_Type
(Next_Entity
(Subp
)) then
12871 return Next_Entity
(Next_Entity
(Subp
));
12873 return Next_Entity
(Subp
);
12875 end External_Subprogram
;
12877 ------------------------------
12878 -- Extract_Dispatching_Call --
12879 ------------------------------
12881 procedure Extract_Dispatching_Call
12883 Call_Ent
: out Entity_Id
;
12884 Object
: out Entity_Id
;
12885 Actuals
: out List_Id
;
12886 Formals
: out List_Id
)
12888 Call_Nam
: Node_Id
;
12891 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12893 if Present
(Original_Node
(N
)) then
12894 Call_Nam
:= Name
(Original_Node
(N
));
12896 Call_Nam
:= Name
(N
);
12899 -- Retrieve the name of the dispatching procedure. It contains the
12900 -- dispatch table slot number.
12903 case Nkind
(Call_Nam
) is
12904 when N_Identifier
=>
12907 when N_Selected_Component
=>
12908 Call_Nam
:= Selector_Name
(Call_Nam
);
12911 raise Program_Error
;
12915 Actuals
:= Parameter_Associations
(N
);
12916 Call_Ent
:= Entity
(Call_Nam
);
12917 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12918 Object
:= First
(Actuals
);
12920 if Present
(Original_Node
(Object
)) then
12921 Object
:= Original_Node
(Object
);
12924 -- If the type of the dispatching object is an access type then return
12925 -- an explicit dereference of a copy of the object, and note that this
12926 -- is the controlling actual of the call.
12928 if Is_Access_Type
(Etype
(Object
)) then
12930 Make_Explicit_Dereference
(Sloc
(N
), New_Copy_Tree
(Object
));
12932 Set_Is_Controlling_Actual
(Object
);
12934 end Extract_Dispatching_Call
;
12936 -------------------
12937 -- Extract_Entry --
12938 -------------------
12940 procedure Extract_Entry
12942 Concval
: out Node_Id
;
12943 Ename
: out Node_Id
;
12944 Index
: out Node_Id
)
12946 Nam
: constant Node_Id
:= Name
(N
);
12949 -- For a simple entry, the name is a selected component, with the
12950 -- prefix being the task value, and the selector being the entry.
12952 if Nkind
(Nam
) = N_Selected_Component
then
12953 Concval
:= Prefix
(Nam
);
12954 Ename
:= Selector_Name
(Nam
);
12957 -- For a member of an entry family, the name is an indexed component
12958 -- where the prefix is a selected component, whose prefix in turn is
12959 -- the task value, and whose selector is the entry family. The single
12960 -- expression in the expressions list of the indexed component is the
12961 -- subscript for the family.
12963 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12964 Concval
:= Prefix
(Prefix
(Nam
));
12965 Ename
:= Selector_Name
(Prefix
(Nam
));
12966 Index
:= First
(Expressions
(Nam
));
12969 -- Through indirection, the type may actually be a limited view of a
12970 -- concurrent type. When compiling a call, the non-limited view of the
12971 -- type is visible.
12973 if From_Limited_With
(Etype
(Concval
)) then
12974 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12978 -------------------
12979 -- Family_Offset --
12980 -------------------
12982 function Family_Offset
12987 Cap
: Boolean) return Node_Id
12993 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12994 -- If one of the bounds is a reference to a discriminant, replace with
12995 -- corresponding discriminal of type. Within the body of a task retrieve
12996 -- the renamed discriminant by simple visibility, using its generated
12997 -- name. Within a protected object, find the original discriminant and
12998 -- replace it with the discriminal of the current protected operation.
13000 ------------------------------
13001 -- Convert_Discriminant_Ref --
13002 ------------------------------
13004 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
13005 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
13010 if Is_Entity_Name
(Bound
)
13011 and then Ekind
(Entity
(Bound
)) = E_Discriminant
13013 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
13014 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13015 Find_Direct_Name
(B
);
13017 elsif Is_Protected_Type
(Ttyp
) then
13018 D
:= First_Discriminant
(Ttyp
);
13019 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
13020 Next_Discriminant
(D
);
13023 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
13026 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
13029 elsif Nkind
(Bound
) = N_Attribute_Reference
then
13033 B
:= New_Copy_Tree
(Bound
);
13037 Make_Attribute_Reference
(Loc
,
13038 Attribute_Name
=> Name_Pos
,
13039 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
13040 Expressions
=> New_List
(B
));
13041 end Convert_Discriminant_Ref
;
13043 -- Start of processing for Family_Offset
13046 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
13047 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
13050 if Is_Task_Type
(Ttyp
) then
13051 Ityp
:= RTE
(RE_Task_Entry_Index
);
13053 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13057 Make_Attribute_Reference
(Loc
,
13058 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13059 Attribute_Name
=> Name_Min
,
13060 Expressions
=> New_List
(
13062 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
13065 Make_Attribute_Reference
(Loc
,
13066 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13067 Attribute_Name
=> Name_Max
,
13068 Expressions
=> New_List
(
13070 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
13073 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
13080 function Family_Size
13085 Cap
: Boolean) return Node_Id
13090 if Is_Task_Type
(Ttyp
) then
13091 Ityp
:= RTE
(RE_Task_Entry_Index
);
13093 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13097 Make_Attribute_Reference
(Loc
,
13098 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13099 Attribute_Name
=> Name_Max
,
13100 Expressions
=> New_List
(
13102 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
13103 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
13104 Make_Integer_Literal
(Loc
, 0)));
13107 ----------------------------
13108 -- Find_Enclosing_Context --
13109 ----------------------------
13111 procedure Find_Enclosing_Context
13113 Context
: out Node_Id
;
13114 Context_Id
: out Entity_Id
;
13115 Context_Decls
: out List_Id
)
13118 -- Traverse the parent chain looking for an enclosing body, block,
13119 -- package or return statement.
13121 Context
:= Parent
(N
);
13122 while Present
(Context
) loop
13123 if Nkind_In
(Context
, N_Entry_Body
,
13124 N_Extended_Return_Statement
,
13126 N_Package_Declaration
,
13132 -- Do not consider block created to protect a list of statements with
13133 -- an Abort_Defer / Abort_Undefer_Direct pair.
13135 elsif Nkind
(Context
) = N_Block_Statement
13136 and then not Is_Abort_Block
(Context
)
13141 Context
:= Parent
(Context
);
13144 pragma Assert
(Present
(Context
));
13146 -- Extract the constituents of the context
13148 if Nkind
(Context
) = N_Extended_Return_Statement
then
13149 Context_Decls
:= Return_Object_Declarations
(Context
);
13150 Context_Id
:= Return_Statement_Entity
(Context
);
13152 -- Package declarations and bodies use a common library-level activation
13153 -- chain or task master, therefore return the package declaration as the
13154 -- proper carrier for the appropriate flag.
13156 elsif Nkind
(Context
) = N_Package_Body
then
13157 Context_Decls
:= Declarations
(Context
);
13158 Context_Id
:= Corresponding_Spec
(Context
);
13159 Context
:= Parent
(Context_Id
);
13161 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13162 Context
:= Parent
(Parent
(Context
));
13164 Context
:= Parent
(Context
);
13167 elsif Nkind
(Context
) = N_Package_Declaration
then
13168 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13169 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13171 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13172 Context_Id
:= Defining_Identifier
(Context_Id
);
13176 if Nkind
(Context
) = N_Block_Statement
then
13177 Context_Id
:= Entity
(Identifier
(Context
));
13179 elsif Nkind
(Context
) = N_Entry_Body
then
13180 Context_Id
:= Defining_Identifier
(Context
);
13182 elsif Nkind
(Context
) = N_Subprogram_Body
then
13183 if Present
(Corresponding_Spec
(Context
)) then
13184 Context_Id
:= Corresponding_Spec
(Context
);
13186 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13188 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13189 Context_Id
:= Defining_Identifier
(Context_Id
);
13193 elsif Nkind
(Context
) = N_Task_Body
then
13194 Context_Id
:= Corresponding_Spec
(Context
);
13197 raise Program_Error
;
13200 Context_Decls
:= Declarations
(Context
);
13203 pragma Assert
(Present
(Context_Id
));
13204 pragma Assert
(Present
(Context_Decls
));
13205 end Find_Enclosing_Context
;
13207 -----------------------
13208 -- Find_Master_Scope --
13209 -----------------------
13211 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13215 -- In Ada 2005, the master is the innermost enclosing scope that is not
13216 -- transient. If the enclosing block is the rewriting of a call or the
13217 -- scope is an extended return statement this is valid master. The
13218 -- master in an extended return is only used within the return, and is
13219 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13220 -- now before that overwriting occurs.
13224 if Ada_Version
>= Ada_2005
then
13225 while Is_Internal
(S
) loop
13226 if Nkind
(Parent
(S
)) = N_Block_Statement
13228 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
13232 elsif Ekind
(S
) = E_Return_Statement
then
13242 end Find_Master_Scope
;
13244 -------------------------------
13245 -- First_Protected_Operation --
13246 -------------------------------
13248 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13249 First_Op
: Node_Id
;
13252 First_Op
:= First
(D
);
13253 while Present
(First_Op
)
13254 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
13260 end First_Protected_Operation
;
13262 ---------------------------------------
13263 -- Install_Private_Data_Declarations --
13264 ---------------------------------------
13266 procedure Install_Private_Data_Declarations
13268 Spec_Id
: Entity_Id
;
13269 Conc_Typ
: Entity_Id
;
13270 Body_Nod
: Node_Id
;
13272 Barrier
: Boolean := False;
13273 Family
: Boolean := False)
13275 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13278 Insert_Node
: Node_Id
:= Empty
;
13279 Obj_Ent
: Entity_Id
;
13281 procedure Add
(Decl
: Node_Id
);
13282 -- Add a single declaration after Insert_Node. If this is the first
13283 -- addition, Decl is added to the front of Decls and it becomes the
13286 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13287 -- The bounds of an entry index may depend on discriminants, create a
13288 -- reference to the corresponding prival. Otherwise return a duplicate
13289 -- of the original bound.
13295 procedure Add
(Decl
: Node_Id
) is
13297 if No
(Insert_Node
) then
13298 Prepend_To
(Decls
, Decl
);
13300 Insert_After
(Insert_Node
, Decl
);
13303 Insert_Node
:= Decl
;
13306 -------------------
13307 -- Replace_Bound --
13308 -------------------
13310 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13312 if Nkind
(Bound
) = N_Identifier
13313 and then Is_Discriminal
(Entity
(Bound
))
13315 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13317 return Duplicate_Subexpr
(Bound
);
13321 -- Start of processing for Install_Private_Data_Declarations
13324 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13325 -- formal parameter _O, _object or _task depending on the context.
13327 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13329 -- Special processing of _O for barrier functions, protected entries
13336 (Ekind
(Spec_Id
) = E_Entry
13337 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13340 Conc_Rec
: constant Entity_Id
:=
13341 Corresponding_Record_Type
(Conc_Typ
);
13342 Typ_Id
: constant Entity_Id
:=
13343 Make_Defining_Identifier
(Loc
,
13344 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13347 -- type prot_typVP is access prot_typV;
13350 Make_Full_Type_Declaration
(Loc
,
13351 Defining_Identifier
=> Typ_Id
,
13353 Make_Access_To_Object_Definition
(Loc
,
13354 Subtype_Indication
=>
13355 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13359 -- _object : prot_typVP := prot_typV (_O);
13362 Make_Object_Declaration
(Loc
,
13363 Defining_Identifier
=>
13364 Make_Defining_Identifier
(Loc
, Name_uObject
),
13365 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13367 Unchecked_Convert_To
(Typ_Id
,
13368 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13371 -- Set the reference to the concurrent object
13373 Obj_Ent
:= Defining_Identifier
(Decl
);
13377 -- Step 2: Create the Protection object and build its declaration for
13378 -- any protected entry (family) of subprogram. Note for the lock-free
13379 -- implementation, the Protection object is not needed anymore.
13381 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13383 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13387 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13389 -- Determine the proper protection type
13391 if Has_Attach_Handler
(Conc_Typ
)
13392 and then not Restricted_Profile
13394 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13396 elsif Has_Interrupt_Handler
(Conc_Typ
)
13397 and then not Restriction_Active
(No_Dynamic_Attachment
)
13399 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13402 case Corresponding_Runtime_Package
(Conc_Typ
) is
13403 when System_Tasking_Protected_Objects_Entries
=>
13404 Prot_Typ
:= RE_Protection_Entries
;
13406 when System_Tasking_Protected_Objects_Single_Entry
=>
13407 Prot_Typ
:= RE_Protection_Entry
;
13409 when System_Tasking_Protected_Objects
=>
13410 Prot_Typ
:= RE_Protection
;
13413 raise Program_Error
;
13418 -- conc_typR : protection_typ renames _object._object;
13421 Make_Object_Renaming_Declaration
(Loc
,
13422 Defining_Identifier
=> Prot_Ent
,
13424 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13426 Make_Selected_Component
(Loc
,
13427 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13428 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13433 -- Step 3: Add discriminant renamings (if any)
13435 if Has_Discriminants
(Conc_Typ
) then
13440 D
:= First_Discriminant
(Conc_Typ
);
13441 while Present
(D
) loop
13443 -- Adjust the source location
13445 Set_Sloc
(Discriminal
(D
), Loc
);
13448 -- discr_name : discr_typ renames _object.discr_name;
13450 -- discr_name : discr_typ renames _task.discr_name;
13453 Make_Object_Renaming_Declaration
(Loc
,
13454 Defining_Identifier
=> Discriminal
(D
),
13455 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13457 Make_Selected_Component
(Loc
,
13458 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13459 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13462 -- Set debug info needed on this renaming declaration even
13463 -- though it does not come from source, so that the debugger
13464 -- will get the right information for these generated names.
13466 Set_Debug_Info_Needed
(Discriminal
(D
));
13468 Next_Discriminant
(D
);
13473 -- Step 4: Add private component renamings (if any)
13475 if Is_Protected
then
13476 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13478 if Present
(Private_Declarations
(Def
)) then
13481 Comp_Id
: Entity_Id
;
13482 Decl_Id
: Entity_Id
;
13485 Comp
:= First
(Private_Declarations
(Def
));
13486 while Present
(Comp
) loop
13487 if Nkind
(Comp
) = N_Component_Declaration
then
13488 Comp_Id
:= Defining_Identifier
(Comp
);
13490 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13492 -- Minimal decoration
13494 if Ekind
(Spec_Id
) = E_Function
then
13495 Set_Ekind
(Decl_Id
, E_Constant
);
13497 Set_Ekind
(Decl_Id
, E_Variable
);
13500 Set_Prival
(Comp_Id
, Decl_Id
);
13501 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13502 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13505 -- comp_name : comp_typ renames _object.comp_name;
13508 Make_Object_Renaming_Declaration
(Loc
,
13509 Defining_Identifier
=> Decl_Id
,
13511 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13513 Make_Selected_Component
(Loc
,
13515 New_Occurrence_Of
(Obj_Ent
, Loc
),
13517 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13527 -- Step 5: Add the declaration of the entry index and the associated
13528 -- type for barrier functions and entry families.
13530 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13532 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13533 Index
: constant Entity_Id
:=
13534 Defining_Identifier
13535 (Entry_Index_Specification
13536 (Entry_Body_Formal_Part
(Body_Nod
)));
13537 Index_Con
: constant Entity_Id
:=
13538 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13540 Index_Typ
: Entity_Id
;
13544 -- Minimal decoration
13546 Set_Ekind
(Index_Con
, E_Constant
);
13547 Set_Entry_Index_Constant
(Index
, Index_Con
);
13548 Set_Discriminal_Link
(Index_Con
, Index
);
13550 -- Retrieve the bounds of the entry family
13552 High
:= Type_High_Bound
(Etype
(Index
));
13553 Low
:= Type_Low_Bound
(Etype
(Index
));
13555 -- In the simple case the entry family is given by a subtype mark
13556 -- and the index constant has the same type.
13558 if Is_Entity_Name
(Original_Node
(
13559 Discrete_Subtype_Definition
(Parent
(Index
))))
13561 Index_Typ
:= Etype
(Index
);
13563 -- Otherwise a new subtype declaration is required
13566 High
:= Replace_Bound
(High
);
13567 Low
:= Replace_Bound
(Low
);
13569 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13572 -- subtype Jnn is <Etype of Index> range Low .. High;
13575 Make_Subtype_Declaration
(Loc
,
13576 Defining_Identifier
=> Index_Typ
,
13577 Subtype_Indication
=>
13578 Make_Subtype_Indication
(Loc
,
13580 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13582 Make_Range_Constraint
(Loc
,
13583 Range_Expression
=>
13584 Make_Range
(Loc
, Low
, High
))));
13588 Set_Etype
(Index_Con
, Index_Typ
);
13590 -- Create the object which designates the index:
13591 -- J : constant Jnn :=
13592 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13594 -- where Jnn is the subtype created above or the original type of
13595 -- the index, _E is a formal of the protected body subprogram and
13596 -- <index expr> is the index of the first family member.
13599 Make_Object_Declaration
(Loc
,
13600 Defining_Identifier
=> Index_Con
,
13601 Constant_Present
=> True,
13602 Object_Definition
=>
13603 New_Occurrence_Of
(Index_Typ
, Loc
),
13606 Make_Attribute_Reference
(Loc
,
13608 New_Occurrence_Of
(Index_Typ
, Loc
),
13609 Attribute_Name
=> Name_Val
,
13611 Expressions
=> New_List
(
13615 Make_Op_Subtract
(Loc
,
13616 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13618 Entry_Index_Expression
(Loc
,
13619 Defining_Identifier
(Body_Nod
),
13623 Make_Attribute_Reference
(Loc
,
13625 New_Occurrence_Of
(Index_Typ
, Loc
),
13626 Attribute_Name
=> Name_Pos
,
13627 Expressions
=> New_List
(
13628 Make_Attribute_Reference
(Loc
,
13630 New_Occurrence_Of
(Index_Typ
, Loc
),
13631 Attribute_Name
=> Name_First
)))))));
13635 end Install_Private_Data_Declarations
;
13637 ---------------------------------
13638 -- Is_Potentially_Large_Family --
13639 ---------------------------------
13641 function Is_Potentially_Large_Family
13642 (Base_Index
: Entity_Id
;
13643 Conctyp
: Entity_Id
;
13645 Hi
: Node_Id
) return Boolean
13648 return Scope
(Base_Index
) = Standard_Standard
13649 and then Base_Index
= Base_Type
(Standard_Integer
)
13650 and then Has_Discriminants
(Conctyp
)
13652 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13654 (Denotes_Discriminant
(Lo
, True)
13656 Denotes_Discriminant
(Hi
, True));
13657 end Is_Potentially_Large_Family
;
13659 -------------------------------------
13660 -- Is_Private_Primitive_Subprogram --
13661 -------------------------------------
13663 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13666 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13667 and then Is_Private_Primitive
(Id
);
13668 end Is_Private_Primitive_Subprogram
;
13674 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13675 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13676 Formal
: Entity_Id
;
13679 Formal
:= First_Formal
(Bod_Subp
);
13680 while Present
(Formal
) loop
13682 -- Look for formal parameter _E
13684 if Chars
(Formal
) = Name_uE
then
13688 Next_Formal
(Formal
);
13691 -- A protected body subprogram should always have the parameter in
13694 raise Program_Error
;
13697 --------------------------------
13698 -- Make_Initialize_Protection --
13699 --------------------------------
13701 function Make_Initialize_Protection
13702 (Protect_Rec
: Entity_Id
) return List_Id
13704 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13707 Ptyp
: constant Node_Id
:=
13708 Corresponding_Concurrent_Type
(Protect_Rec
);
13710 L
: constant List_Id
:= New_List
;
13711 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13712 Prio_Type
: Entity_Id
;
13713 Prio_Var
: Entity_Id
:= Empty
;
13714 Restricted
: constant Boolean := Restricted_Profile
;
13717 -- We may need two calls to properly initialize the object, one to
13718 -- Initialize_Protection, and possibly one to Install_Handlers if we
13719 -- have a pragma Attach_Handler.
13721 -- Get protected declaration. In the case of a task type declaration,
13722 -- this is simply the parent of the protected type entity. In the single
13723 -- protected object declaration, this parent will be the implicit type,
13724 -- and we can find the corresponding single protected object declaration
13725 -- by searching forward in the declaration list in the tree.
13727 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13728 -- of this type should have been removed during semantic analysis.
13730 Pdec
:= Parent
(Ptyp
);
13731 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13732 N_Single_Protected_Declaration
)
13737 -- Build the parameter list for the call. Note that _Init is the name
13738 -- of the formal for the object to be initialized, which is the task
13739 -- value record itself.
13743 -- For lock-free implementation, skip initializations of the Protection
13746 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13748 -- Object parameter. This is a pointer to the object of type
13749 -- Protection used by the GNARL to control the protected object.
13752 Make_Attribute_Reference
(Loc
,
13754 Make_Selected_Component
(Loc
,
13755 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13756 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13757 Attribute_Name
=> Name_Unchecked_Access
));
13759 -- Priority parameter. Set to Unspecified_Priority unless there is a
13760 -- Priority rep item, in which case we take the value from the pragma
13761 -- or attribute definition clause, or there is an Interrupt_Priority
13762 -- rep item and no Priority rep item, and we set the ceiling to
13763 -- Interrupt_Priority'Last, an implementation-defined value, see
13766 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13768 Prio_Clause
: constant Node_Id
:=
13770 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13777 if Nkind
(Prio_Clause
) = N_Pragma
then
13780 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13782 -- Get_Rep_Item returns either priority pragma
13784 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13785 Prio_Type
:= RTE
(RE_Any_Priority
);
13787 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13790 -- Attribute definition clause Priority
13793 if Chars
(Prio_Clause
) = Name_Priority
then
13794 Prio_Type
:= RTE
(RE_Any_Priority
);
13796 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13799 Prio
:= Expression
(Prio_Clause
);
13802 -- Always create a locale variable to capture the priority.
13803 -- The priority is also passed to Install_Restriced_Handlers.
13804 -- Note that it is really necessary to create this variable
13805 -- explicitly. It might be thought that removing side effects
13806 -- would the appropriate approach, but that could generate
13807 -- declarations improperly placed in the enclosing scope.
13809 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13811 Make_Object_Declaration
(Loc
,
13812 Defining_Identifier
=> Prio_Var
,
13813 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13814 Expression
=> Relocate_Node
(Prio
)));
13816 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13819 -- When no priority is specified but an xx_Handler pragma is, we
13820 -- default to System.Interrupts.Default_Interrupt_Priority, see
13823 elsif Has_Attach_Handler
(Ptyp
)
13824 or else Has_Interrupt_Handler
(Ptyp
)
13827 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13829 -- Normal case, no priority or xx_Handler specified, default priority
13833 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13836 -- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
13838 if Restricted_Profile
and Task_Dispatching_Policy
= 'E' then
13839 Deadline_Floor
: declare
13840 Item
: constant Node_Id
:=
13842 (Ptyp
, Name_Deadline_Floor
, Check_Parents
=> False);
13844 Deadline
: Node_Id
;
13847 if Present
(Item
) then
13849 -- Pragma Deadline_Floor
13851 if Nkind
(Item
) = N_Pragma
then
13854 (First
(Pragma_Argument_Associations
(Item
)));
13856 -- Attribute definition clause Deadline_Floor
13860 (Nkind
(Item
) = N_Attribute_Definition_Clause
);
13862 Deadline
:= Expression
(Item
);
13865 Append_To
(Args
, Deadline
);
13867 -- Unusual case: default deadline
13871 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
13873 end Deadline_Floor
;
13876 -- Test for Compiler_Info parameter. This parameter allows entry body
13877 -- procedures and barrier functions to be called from the runtime. It
13878 -- is a pointer to the record generated by the compiler to represent
13879 -- the protected object.
13881 -- A protected type without entries that covers an interface and
13882 -- overrides the abstract routines with protected procedures is
13883 -- considered equivalent to a protected type with entries in the
13884 -- context of dispatching select statements.
13886 -- Protected types with interrupt handlers (when not using a
13887 -- restricted profile) are also considered equivalent to protected
13888 -- types with entries.
13890 -- The types which are used (Static_Interrupt_Protection and
13891 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13894 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13896 Called_Subp
: RE_Id
;
13900 when System_Tasking_Protected_Objects_Entries
=>
13901 Called_Subp
:= RE_Initialize_Protection_Entries
;
13903 -- Argument Compiler_Info
13906 Make_Attribute_Reference
(Loc
,
13907 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13908 Attribute_Name
=> Name_Address
));
13910 when System_Tasking_Protected_Objects_Single_Entry
=>
13911 Called_Subp
:= RE_Initialize_Protection_Entry
;
13913 -- Argument Compiler_Info
13916 Make_Attribute_Reference
(Loc
,
13917 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13918 Attribute_Name
=> Name_Address
));
13920 when System_Tasking_Protected_Objects
=>
13921 Called_Subp
:= RE_Initialize_Protection
;
13924 raise Program_Error
;
13927 -- Entry_Queue_Maxes parameter. This is an access to an array of
13928 -- naturals representing the entry queue maximums for each entry
13929 -- in the protected type. Zero represents no max. The access is
13930 -- null if there is no limit for all entries (usual case).
13933 and then Pkg_Id
= System_Tasking_Protected_Objects_Entries
13935 if Present
(Entry_Max_Queue_Lengths_Array
(Ptyp
)) then
13937 Make_Attribute_Reference
(Loc
,
13940 (Entry_Max_Queue_Lengths_Array
(Ptyp
), Loc
),
13941 Attribute_Name
=> Name_Unrestricted_Access
));
13943 Append_To
(Args
, Make_Null
(Loc
));
13946 -- Edge cases exist where entry initialization functions are
13947 -- called, but no entries exist, so null is appended.
13949 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13950 Append_To
(Args
, Make_Null
(Loc
));
13953 -- Entry_Bodies parameter. This is a pointer to an array of
13954 -- pointers to the entry body procedures and barrier functions of
13955 -- the object. If the protected type has no entries this object
13956 -- will not exist, in this case, pass a null (it can happen when
13957 -- there are protected interrupt handlers or interfaces).
13960 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13962 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13963 -- multiple entries).
13966 Make_Attribute_Reference
(Loc
,
13967 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13968 Attribute_Name
=> Name_Unrestricted_Access
));
13970 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13972 -- Find index mapping function (clumsy but ok for now)
13974 while Ekind
(P_Arr
) /= E_Function
loop
13975 Next_Entity
(P_Arr
);
13979 Make_Attribute_Reference
(Loc
,
13980 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13981 Attribute_Name
=> Name_Unrestricted_Access
));
13984 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13986 -- This is the case where we have a protected object with
13987 -- interfaces and no entries, and the single entry restriction
13988 -- is in effect. We pass a null pointer for the entry
13989 -- parameter because there is no actual entry.
13991 Append_To
(Args
, Make_Null
(Loc
));
13993 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13995 -- This is the case where we have a protected object with no
13997 -- - either interrupt handlers with non restricted profile,
13999 -- Note that the types which are used for interrupt handlers
14000 -- (Static/Dynamic_Interrupt_Protection) are derived from
14001 -- Protection_Entries. We pass two null pointers because there
14002 -- is no actual entry, and the initialization procedure needs
14003 -- both Entry_Bodies and Find_Body_Index.
14005 Append_To
(Args
, Make_Null
(Loc
));
14006 Append_To
(Args
, Make_Null
(Loc
));
14010 Make_Procedure_Call_Statement
(Loc
,
14012 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
14013 Parameter_Associations
=> Args
));
14017 if Has_Attach_Handler
(Ptyp
) then
14019 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
14020 -- make the following call:
14022 -- Install_Handlers (_object,
14023 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
14025 -- or, in the case of Ravenscar:
14027 -- Install_Restricted_Handlers
14028 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
14031 Args
: constant List_Id
:= New_List
;
14032 Table
: constant List_Id
:= New_List
;
14033 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
14036 -- Build the Priority parameter (only for ravenscar)
14040 -- Priority comes from a pragma
14042 if Present
(Prio_Var
) then
14043 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
14045 -- Priority is the default one
14050 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
14054 -- Build the Attach_Handler table argument
14056 while Present
(Ritem
) loop
14057 if Nkind
(Ritem
) = N_Pragma
14058 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
14061 Handler
: constant Node_Id
:=
14062 First
(Pragma_Argument_Associations
(Ritem
));
14064 Interrupt
: constant Node_Id
:= Next
(Handler
);
14065 Expr
: constant Node_Id
:= Expression
(Interrupt
);
14069 Make_Aggregate
(Loc
, Expressions
=> New_List
(
14070 Unchecked_Convert_To
14071 (RTE
(RE_System_Interrupt_Id
), Expr
),
14072 Make_Attribute_Reference
(Loc
,
14074 Make_Selected_Component
(Loc
,
14076 Make_Identifier
(Loc
, Name_uInit
),
14078 Duplicate_Subexpr_No_Checks
14079 (Expression
(Handler
))),
14080 Attribute_Name
=> Name_Access
))));
14084 Next_Rep_Item
(Ritem
);
14087 -- Append the table argument we just built
14089 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
14091 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14092 -- call to the statements.
14095 -- Call a simplified version of Install_Handlers to be used
14096 -- when the Ravenscar restrictions are in effect
14097 -- (Install_Restricted_Handlers).
14100 Make_Procedure_Call_Statement
(Loc
,
14103 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
14104 Parameter_Associations
=> Args
));
14107 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
14109 -- First, prepends the _object argument
14112 Make_Attribute_Reference
(Loc
,
14114 Make_Selected_Component
(Loc
,
14115 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14117 Make_Identifier
(Loc
, Name_uObject
)),
14118 Attribute_Name
=> Name_Unchecked_Access
));
14121 -- Then, insert call to Install_Handlers
14124 Make_Procedure_Call_Statement
(Loc
,
14126 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
14127 Parameter_Associations
=> Args
));
14133 end Make_Initialize_Protection
;
14135 ---------------------------
14136 -- Make_Task_Create_Call --
14137 ---------------------------
14139 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
14140 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14150 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14151 Tnam
:= Chars
(Ttyp
);
14153 -- Get task declaration. In the case of a task type declaration, this is
14154 -- simply the parent of the task type entity. In the single task
14155 -- declaration, this parent will be the implicit type, and we can find
14156 -- the corresponding single task declaration by searching forward in the
14157 -- declaration list in the tree.
14159 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14160 -- this type should have been removed during semantic analysis.
14162 Tdec
:= Parent
(Ttyp
);
14163 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
14164 N_Single_Task_Declaration
)
14169 -- Now we can find the task definition from this declaration
14171 Tdef
:= Task_Definition
(Tdec
);
14173 -- Build the parameter list for the call. Note that _Init is the name
14174 -- of the formal for the object to be initialized, which is the task
14175 -- value record itself.
14179 -- Priority parameter. Set to Unspecified_Priority unless there is a
14180 -- Priority rep item, in which case we take the value from the rep item.
14181 -- Not used on Ravenscar_EDF profile.
14183 if not (Restricted_Profile
and then Task_Dispatching_Policy
= 'E') then
14184 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14186 Make_Selected_Component
(Loc
,
14187 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14188 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14191 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14195 -- Optional Stack parameter
14197 if Restricted_Profile
then
14199 -- If the stack has been preallocated by the expander then
14200 -- pass its address. Otherwise, pass a null address.
14202 if Preallocated_Stacks_On_Target
then
14204 Make_Attribute_Reference
(Loc
,
14206 Make_Selected_Component
(Loc
,
14207 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14208 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14209 Attribute_Name
=> Name_Address
));
14213 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14217 -- Size parameter. If no Storage_Size pragma is present, then
14218 -- the size is taken from the taskZ variable for the type, which
14219 -- is either Unspecified_Size, or has been reset by the use of
14220 -- a Storage_Size attribute definition clause. If a pragma is
14221 -- present, then the size is taken from the _Size field of the
14222 -- task value record, which was set from the pragma value.
14224 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14226 Make_Selected_Component
(Loc
,
14227 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14228 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14232 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14235 -- Secondary_Stack parameter used for restricted profiles
14237 if Restricted_Profile
then
14239 -- If the secondary stack has been allocated by the expander then
14240 -- pass its access pointer. Otherwise, pass null.
14242 if Create_Secondary_Stack_For_Task
(Ttyp
) then
14244 Make_Attribute_Reference
(Loc
,
14246 Make_Selected_Component
(Loc
,
14247 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14249 Make_Identifier
(Loc
, Name_uSecondary_Stack
)),
14250 Attribute_Name
=> Name_Unrestricted_Access
));
14253 Append_To
(Args
, Make_Null
(Loc
));
14257 -- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there
14258 -- is a Secondary_Stack_Size pragma, in which case take the value from
14259 -- the pragma. If the restriction No_Secondary_Stack is active then a
14260 -- size of 0 is passed regardless to prevent the allocation of the
14263 if Restriction_Active
(No_Secondary_Stack
) then
14264 Append_To
(Args
, Make_Integer_Literal
(Loc
, 0));
14266 elsif Has_Rep_Pragma
14267 (Ttyp
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
14270 Make_Selected_Component
(Loc
,
14271 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14273 Make_Identifier
(Loc
, Name_uSecondary_Stack_Size
)));
14277 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
14280 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14281 -- Task_Info pragma, in which case we take the value from the pragma.
14283 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14285 Make_Selected_Component
(Loc
,
14286 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14287 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14291 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14294 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14295 -- in which case we take the value from the rep item. The parameter is
14296 -- passed as an Integer because in the case of unspecified CPU the
14297 -- value is not in the range of CPU_Range.
14299 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14301 Convert_To
(Standard_Integer
,
14302 Make_Selected_Component
(Loc
,
14303 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14304 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14307 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14310 if not Restricted_Profile
or else Task_Dispatching_Policy
= 'E' then
14312 -- Deadline parameter. If no Relative_Deadline pragma is present,
14313 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14314 -- the deadline is taken from the _Relative_Deadline field of the
14315 -- task value record, which was set from the pragma value. Note that
14316 -- this parameter must not be generated for the restricted profiles
14317 -- since Ravenscar does not allow deadlines.
14319 -- Case where pragma Relative_Deadline applies: use given value
14321 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14323 Make_Selected_Component
(Loc
,
14324 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14326 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14328 -- No pragma Relative_Deadline apply to the task
14332 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14336 if not Restricted_Profile
then
14338 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14339 -- present, then the dispatching domain is null. If a rep item is
14340 -- present, then the dispatching domain is taken from the
14341 -- _Dispatching_Domain field of the task value record, which was set
14342 -- from the rep item value.
14344 -- Case where Dispatching_Domain rep item applies: use given value
14347 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14350 Make_Selected_Component
(Loc
,
14352 Make_Identifier
(Loc
, Name_uInit
),
14354 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14356 -- No pragma or aspect Dispatching_Domain applies to the task
14359 Append_To
(Args
, Make_Null
(Loc
));
14362 -- Number of entries. This is an expression of the form:
14364 -- n + _Init.a'Length + _Init.a'B'Length + ...
14366 -- where a,b... are the entry family names for the task definition
14369 Build_Entry_Count_Expression
14374 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14376 Append_To
(Args
, Ecount
);
14378 -- Master parameter. This is a reference to the _Master parameter of
14379 -- the initialization procedure, except in the case of the pragma
14380 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14381 -- System.Tasking.Library_Task_Level.
14383 if Restriction_Active
(No_Task_Hierarchy
) = False then
14384 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14387 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14391 -- State parameter. This is a pointer to the task body procedure. The
14392 -- required value is obtained by taking 'Unrestricted_Access of the task
14393 -- body procedure and converting it (with an unchecked conversion) to
14394 -- the type required by the task kernel. For further details, see the
14395 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14396 -- than 'Address in order to avoid creating trampolines.
14399 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14400 Subp_Ptr_Typ
: constant Node_Id
:=
14401 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14402 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14405 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14406 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14408 -- Be sure to freeze a reference to the access-to-subprogram type,
14409 -- otherwise gigi will complain that it's in the wrong scope, because
14410 -- it's actually inside the init procedure for the record type that
14411 -- corresponds to the task type.
14413 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14414 Append_Freeze_Action
(Task_Rec
, Ref
);
14417 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14418 Make_Qualified_Expression
(Loc
,
14419 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14421 Make_Attribute_Reference
(Loc
,
14422 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14423 Attribute_Name
=> Name_Unrestricted_Access
))));
14426 -- Discriminants parameter. This is just the address of the task
14427 -- value record itself (which contains the discriminant values
14430 Make_Attribute_Reference
(Loc
,
14431 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14432 Attribute_Name
=> Name_Address
));
14434 -- Elaborated parameter. This is an access to the elaboration Boolean
14437 Make_Attribute_Reference
(Loc
,
14438 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14439 Attribute_Name
=> Name_Unchecked_Access
));
14441 -- Add Chain parameter (not done for sequential elaboration policy, see
14442 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14444 if Partition_Elaboration_Policy
/= 'S' then
14445 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14448 -- Task name parameter. Take this from the _Task_Id parameter to the
14449 -- init call unless there is a Task_Name pragma, in which case we take
14450 -- the value from the pragma.
14452 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14453 -- Copy expression in full, because it may be dynamic and have
14460 (Pragma_Argument_Associations
14462 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14465 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14468 -- Created_Task parameter. This is the _Task_Id field of the task
14472 Make_Selected_Component
(Loc
,
14473 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14474 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14480 if Restricted_Profile
then
14481 if Partition_Elaboration_Policy
= 'S' then
14482 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14484 Create_RE
:= RE_Create_Restricted_Task
;
14487 Create_RE
:= RE_Create_Task
;
14490 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14494 Make_Procedure_Call_Statement
(Loc
,
14496 Parameter_Associations
=> Args
);
14497 end Make_Task_Create_Call
;
14499 ------------------------------
14500 -- Next_Protected_Operation --
14501 ------------------------------
14503 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14507 -- Check whether there is a subsequent body for a protected operation
14508 -- in the current protected body. In Ada2012 that includes expression
14509 -- functions that are completions.
14511 Next_Op
:= Next
(N
);
14512 while Present
(Next_Op
)
14513 and then not Nkind_In
(Next_Op
,
14514 N_Subprogram_Body
, N_Entry_Body
, N_Expression_Function
)
14520 end Next_Protected_Operation
;
14522 ---------------------
14523 -- Null_Statements --
14524 ---------------------
14526 function Null_Statements
(Stats
: List_Id
) return Boolean is
14530 Stmt
:= First
(Stats
);
14531 while Nkind
(Stmt
) /= N_Empty
14532 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14534 (Nkind
(Stmt
) = N_Pragma
14536 Nam_In
(Pragma_Name_Unmapped
(Stmt
),
14544 return Nkind
(Stmt
) = N_Empty
;
14545 end Null_Statements
;
14547 --------------------------
14548 -- Parameter_Block_Pack --
14549 --------------------------
14551 function Parameter_Block_Pack
14553 Blk_Typ
: Entity_Id
;
14557 Stmts
: List_Id
) return Node_Id
14559 Actual
: Entity_Id
;
14560 Expr
: Node_Id
:= Empty
;
14561 Formal
: Entity_Id
;
14562 Has_Param
: Boolean := False;
14565 Temp_Asn
: Node_Id
;
14566 Temp_Nam
: Node_Id
;
14569 Actual
:= First
(Actuals
);
14570 Formal
:= Defining_Identifier
(First
(Formals
));
14571 Params
:= New_List
;
14572 while Present
(Actual
) loop
14573 if Is_By_Copy_Type
(Etype
(Actual
)) then
14575 -- Jnn : aliased <formal-type>
14577 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14580 Make_Object_Declaration
(Loc
,
14581 Aliased_Present
=> True,
14582 Defining_Identifier
=> Temp_Nam
,
14583 Object_Definition
=>
14584 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14586 -- The object is initialized with an explicit assignment
14587 -- later. Indicate that it does not need an initialization
14588 -- to prevent spurious warnings if the type excludes null.
14590 Set_No_Initialization
(Last
(Decls
));
14592 if Ekind
(Formal
) /= E_Out_Parameter
then
14598 New_Occurrence_Of
(Temp_Nam
, Loc
);
14600 Set_Assignment_OK
(Temp_Asn
);
14603 Make_Assignment_Statement
(Loc
,
14605 Expression
=> New_Copy_Tree
(Actual
)));
14608 -- If the actual is not controlling, generate:
14610 -- Jnn'unchecked_access
14612 -- and add it to aggegate for access to formals. Note that the
14613 -- actual may be by-copy but still be a controlling actual if it
14614 -- is an access to class-wide interface.
14616 if not Is_Controlling_Actual
(Actual
) then
14618 Make_Attribute_Reference
(Loc
,
14619 Attribute_Name
=> Name_Unchecked_Access
,
14620 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14625 -- The controlling parameter is omitted
14628 if not Is_Controlling_Actual
(Actual
) then
14630 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14636 Next_Actual
(Actual
);
14637 Next_Formal_With_Extras
(Formal
);
14641 Expr
:= Make_Aggregate
(Loc
, Params
);
14646 -- J1'unchecked_access;
14647 -- <actual2>'reference;
14650 P
:= Make_Temporary
(Loc
, 'P');
14653 Make_Object_Declaration
(Loc
,
14654 Defining_Identifier
=> P
,
14655 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14656 Expression
=> Expr
));
14659 end Parameter_Block_Pack
;
14661 ----------------------------
14662 -- Parameter_Block_Unpack --
14663 ----------------------------
14665 function Parameter_Block_Unpack
14669 Formals
: List_Id
) return List_Id
14671 Actual
: Entity_Id
;
14673 Formal
: Entity_Id
;
14674 Has_Asnmt
: Boolean := False;
14675 Result
: constant List_Id
:= New_List
;
14678 Actual
:= First
(Actuals
);
14679 Formal
:= Defining_Identifier
(First
(Formals
));
14680 while Present
(Actual
) loop
14681 if Is_By_Copy_Type
(Etype
(Actual
))
14682 and then Ekind
(Formal
) /= E_In_Parameter
14685 -- <actual> := P.<formal>;
14688 Make_Assignment_Statement
(Loc
,
14692 Make_Explicit_Dereference
(Loc
,
14693 Make_Selected_Component
(Loc
,
14695 New_Occurrence_Of
(P
, Loc
),
14697 Make_Identifier
(Loc
, Chars
(Formal
)))));
14699 Set_Assignment_OK
(Name
(Asnmt
));
14700 Append_To
(Result
, Asnmt
);
14705 Next_Actual
(Actual
);
14706 Next_Formal_With_Extras
(Formal
);
14712 return New_List
(Make_Null_Statement
(Loc
));
14714 end Parameter_Block_Unpack
;
14716 ----------------------
14717 -- Set_Discriminals --
14718 ----------------------
14720 procedure Set_Discriminals
(Dec
: Node_Id
) is
14723 D_Minal
: Entity_Id
;
14726 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14727 Pdef
:= Defining_Identifier
(Dec
);
14729 if Has_Discriminants
(Pdef
) then
14730 D
:= First_Discriminant
(Pdef
);
14731 while Present
(D
) loop
14733 Make_Defining_Identifier
(Sloc
(D
),
14734 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14736 Set_Ekind
(D_Minal
, E_Constant
);
14737 Set_Etype
(D_Minal
, Etype
(D
));
14738 Set_Scope
(D_Minal
, Pdef
);
14739 Set_Discriminal
(D
, D_Minal
);
14740 Set_Discriminal_Link
(D_Minal
, D
);
14742 Next_Discriminant
(D
);
14745 end Set_Discriminals
;
14747 -----------------------
14748 -- Trivial_Accept_OK --
14749 -----------------------
14751 function Trivial_Accept_OK
return Boolean is
14753 case Opt
.Task_Dispatching_Policy
is
14755 -- If we have the default task dispatching policy in effect, we can
14756 -- definitely do the optimization (one way of looking at this is to
14757 -- think of the formal definition of the default policy being allowed
14758 -- to run any task it likes after a rendezvous, so even if notionally
14759 -- a full rescheduling occurs, we can say that our dispatching policy
14760 -- (i.e. the default dispatching policy) reorders the queue to be the
14761 -- same as just before the call.
14766 -- FIFO_Within_Priorities certainly does not permit this
14767 -- optimization since the Rendezvous is a scheduling action that may
14768 -- require some other task to be run.
14773 -- For now, disallow the optimization for all other policies. This
14774 -- may be over-conservative, but it is certainly not incorrect.
14779 end Trivial_Accept_OK
;