1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 Checks
; use Checks
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Exp_Ch3
; use Exp_Ch3
;
32 with Exp_Ch11
; use Exp_Ch11
;
33 with Exp_Ch6
; use Exp_Ch6
;
34 with Exp_Dbug
; use Exp_Dbug
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Sel
; use Exp_Sel
;
37 with Exp_Smem
; use Exp_Smem
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Exp_Util
; use Exp_Util
;
40 with Freeze
; use Freeze
;
42 with Itypes
; use Itypes
;
43 with Namet
; use Namet
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch11
; use Sem_Ch11
;
54 with Sem_Elab
; use Sem_Elab
;
55 with Sem_Res
; use Sem_Res
;
56 with Sem_Util
; use Sem_Util
;
57 with Sinfo
; use Sinfo
;
58 with Snames
; use Snames
;
59 with Stand
; use Stand
;
60 with Stringt
; use Stringt
;
61 with Targparm
; use Targparm
;
62 with Tbuild
; use Tbuild
;
63 with Uintp
; use Uintp
;
65 package body Exp_Ch9
is
67 -- The following constant establishes the upper bound for the index of
68 -- an entry family. It is used to limit the allocated size of protected
69 -- types with defaulted discriminant of an integer type, when the bound
70 -- of some entry family depends on a discriminant. The limitation to
71 -- entry families of 128K should be reasonable in all cases, and is a
72 -- documented implementation restriction. It will be lifted when protected
73 -- entry families are re-implemented as a single ordered queue.
75 Entry_Family_Bound
: constant Int
:= 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 function Build_Entry_Count_Expression
130 (Concurrent_Type
: Node_Id
;
131 Component_List
: List_Id
;
132 Loc
: Source_Ptr
) return Node_Id
;
133 -- Compute number of entries for concurrent object. This is a count of
134 -- simple entries, followed by an expression that computes the length
135 -- of the range of each entry family. A single array with that size is
136 -- allocated for each concurrent object of the type.
138 function Build_Parameter_Block
142 Decls
: List_Id
) return Entity_Id
;
143 -- Generate an access type for each actual parameter in the list Actuals.
144 -- Create an encapsulating record that contains all the actuals and return
145 -- its type. Generate:
146 -- type Ann1 is access all <actual1-type>
148 -- type AnnN is access all <actualN-type>
149 -- type Pnn is record
155 function Build_Wrapper_Body
157 Proc_Nam
: Entity_Id
;
159 Formals
: List_Id
) return Node_Id
;
160 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
161 -- associated with a protected or task type. This is required to implement
162 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
163 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
164 -- handle object notation, Formals are the original entry formals that will
165 -- be explicitly replicated.
167 function Build_Wrapper_Spec
169 Proc_Nam
: Entity_Id
;
171 Formals
: List_Id
) return Node_Id
;
172 -- Ada 2005 (AI-345): Build the specification of a primitive operation
173 -- associated with a protected or task type. This is required implement
174 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
175 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
176 -- handle object notation, Formals are the original entry formals that will
177 -- be explicitly replicated.
179 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
180 -- Build the function that translates the entry index in the call
181 -- (which depends on the size of entry families) into an index into the
182 -- Entry_Bodies_Array, to determine the body and barrier function used
183 -- in a protected entry call. A pointer to this function appears in every
186 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
187 -- Build subprogram declaration for previous one
189 function Build_Protected_Entry
192 Pid
: Node_Id
) return Node_Id
;
193 -- Build the procedure implementing the statement sequence of the specified
196 function Build_Protected_Entry_Specification
199 Ent_Id
: Entity_Id
) return Node_Id
;
200 -- Build a specification for the procedure implementing the statements of
201 -- the specified entry body. Add attributes associating it with the entry
202 -- defining identifier Ent_Id.
204 function Build_Protected_Spec
206 Obj_Type
: Entity_Id
;
208 Unprotected
: Boolean := False) return List_Id
;
209 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
210 -- Subprogram_Type. Builds signature of protected subprogram, adding the
211 -- formal that corresponds to the object itself. For an access to protected
212 -- subprogram, there is no object type to specify, so the parameter has
213 -- type Address and mode In. An indirect call through such a pointer will
214 -- convert the address to a reference to the actual object. The object is
215 -- a limited record and therefore a by_reference type.
217 function Build_Protected_Subprogram_Body
220 N_Op_Spec
: Node_Id
) return Node_Id
;
221 -- This function is used to construct the protected version of a protected
222 -- subprogram. Its statement sequence first defers abort, then locks
223 -- the associated protected object, and then enters a block that contains
224 -- a call to the unprotected version of the subprogram (for details, see
225 -- Build_Unprotected_Subprogram_Body). This block statement requires
226 -- a cleanup handler that unlocks the object in all cases.
227 -- (see Exp_Ch7.Expand_Cleanup_Actions).
229 function Build_Selected_Name
231 Selector
: Entity_Id
;
232 Append_Char
: Character := ' ') return Name_Id
;
233 -- Build a name in the form of Prefix__Selector, with an optional
234 -- character appended. This is used for internal subprograms generated
235 -- for operations of protected types, including barrier functions.
236 -- For the subprograms generated for entry bodies and entry barriers,
237 -- the generated name includes a sequence number that makes names
238 -- unique in the presence of entry overloading. This is necessary
239 -- because entry body procedures and barrier functions all have the
242 procedure Build_Simple_Entry_Call
247 -- Some comments here would be useful ???
249 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
250 -- This routine constructs a specification for the procedure that we will
251 -- build for the task body for task type T. The spec has the form:
253 -- procedure tnameB (_Task : access tnameV);
255 -- where name is the character name taken from the task type entity that
256 -- is passed as the argument to the procedure, and tnameV is the task
257 -- value type that is associated with the task type.
259 function Build_Unprotected_Subprogram_Body
261 Pid
: Node_Id
) return Node_Id
;
262 -- This routine constructs the unprotected version of a protected
263 -- subprogram body, which is contains all of the code in the
264 -- original, unexpanded body. This is the version of the protected
265 -- subprogram that is called from all protected operations on the same
266 -- object, including the protected version of the same subprogram.
268 procedure Collect_Entry_Families
271 Current_Node
: in out Node_Id
;
272 Conctyp
: Entity_Id
);
273 -- For each entry family in a concurrent type, create an anonymous array
274 -- type of the right size, and add a component to the corresponding_record.
276 function Concurrent_Object
277 (Spec_Id
: Entity_Id
;
278 Conc_Typ
: Entity_Id
) return Entity_Id
;
279 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
280 -- the entity associated with the concurrent object in the Protected_Body_
281 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
282 -- denotes formal parameter _O, _object or _task.
284 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
285 -- Copy the result type of a function specification, when building the
286 -- internal operation corresponding to a protected function, or when
287 -- expanding an access to protected function. If the result is an anonymous
288 -- access to subprogram itself, we need to create a new signature with the
289 -- same parameter names and the same resolved types, but with new entities
292 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
293 -- Decls is a list which may contain the declarations created by Install_
294 -- Private_Data_Declarations. All generated entities are marked as needing
295 -- debug info and debug nodes are manually generation where necessary. This
296 -- step of the expansion must to be done after private data has been moved
297 -- to its final resting scope to ensure proper visibility of debug objects.
299 function Family_Offset
304 Cap
: Boolean) return Node_Id
;
305 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
306 -- an accept statement, or the upper bound in the discrete subtype of
307 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
308 -- the concurrent type of the entry. If Cap is true, the result is
309 -- capped according to Entry_Family_Bound.
316 Cap
: Boolean) return Node_Id
;
317 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
318 -- a family, and handle properly the superflat case. This is equivalent
319 -- to the use of 'Length on the index type, but must use Family_Offset
320 -- to handle properly the case of bounds that depend on discriminants.
321 -- If Cap is true, the result is capped according to Entry_Family_Bound.
323 procedure Extract_Dispatching_Call
325 Call_Ent
: out Entity_Id
;
326 Object
: out Entity_Id
;
327 Actuals
: out List_Id
;
328 Formals
: out List_Id
);
329 -- Given a dispatching call, extract the entity of the name of the call,
330 -- its object parameter, its actual parameters and the formal parameters
331 -- of the overridden interface-level version.
333 procedure Extract_Entry
335 Concval
: out Node_Id
;
337 Index
: out Node_Id
);
338 -- Given an entry call, returns the associated concurrent object,
339 -- the entry name, and the entry family index.
341 function Find_Task_Or_Protected_Pragma
343 P
: Name_Id
) return Node_Id
;
344 -- Searches the task or protected definition T for the first occurrence
345 -- of the pragma whose name is given by P. The caller has ensured that
346 -- the pragma is present in the task definition. A special case is that
347 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
348 -- ??? Should be implemented with the rep item chain mechanism.
350 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
351 -- Given a subprogram identifier, return the entity which is associated
352 -- with the protection entry index in the Protected_Body_Subprogram or the
353 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
356 function Is_Potentially_Large_Family
357 (Base_Index
: Entity_Id
;
360 Hi
: Node_Id
) return Boolean;
362 function Null_Statements
(Stats
: List_Id
) return Boolean;
363 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
364 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
365 -- well to still count as null. Returns True for a null sequence. The
366 -- argument is the list of statements from the DO-END sequence.
368 function Parameter_Block_Pack
374 Stmts
: List_Id
) return Entity_Id
;
375 -- Set the components of the generated parameter block with the values of
376 -- the actual parameters. Generate aliased temporaries to capture the
377 -- values for types that are passed by copy. Otherwise generate a reference
378 -- to the actual's value. Return the address of the aggregate block.
380 -- Jnn1 : alias <formal-type1>;
381 -- Jnn1 := <actual1>;
384 -- Jnn1'unchecked_access;
385 -- <actual2>'reference;
388 function Parameter_Block_Unpack
392 Formals
: List_Id
) return List_Id
;
393 -- Retrieve the values of the components from the parameter block and
394 -- assign then to the original actual parameters. Generate:
395 -- <actual1> := P.<formal1>;
397 -- <actualN> := P.<formalN>;
399 function Trivial_Accept_OK
return Boolean;
400 -- If there is no DO-END block for an accept, or if the DO-END block has
401 -- only null statements, then it is possible to do the Rendezvous with much
402 -- less overhead using the Accept_Trivial routine in the run-time library.
403 -- However, this is not always a valid optimization. Whether it is valid or
404 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
405 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
406 -- a rescheduling is required, so this optimization is not allowed. This
407 -- function returns True if the optimization is permitted.
409 -----------------------------
410 -- Actual_Index_Expression --
411 -----------------------------
413 function Actual_Index_Expression
417 Tsk
: Entity_Id
) return Node_Id
419 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
427 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
428 -- Compute difference between bounds of entry family
430 --------------------------
431 -- Actual_Family_Offset --
432 --------------------------
434 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
436 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
437 -- Replace a reference to a discriminant with a selected component
438 -- denoting the discriminant of the target task.
440 -----------------------------
441 -- Actual_Discriminant_Ref --
442 -----------------------------
444 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
445 Typ
: constant Entity_Id
:= Etype
(Bound
);
449 if not Is_Entity_Name
(Bound
)
450 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
452 if Nkind
(Bound
) = N_Attribute_Reference
then
455 B
:= New_Copy_Tree
(Bound
);
460 Make_Selected_Component
(Sloc
,
461 Prefix
=> New_Copy_Tree
(Tsk
),
462 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
464 Analyze_And_Resolve
(B
, Typ
);
468 Make_Attribute_Reference
(Sloc
,
469 Attribute_Name
=> Name_Pos
,
470 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
471 Expressions
=> New_List
(B
));
472 end Actual_Discriminant_Ref
;
474 -- Start of processing for Actual_Family_Offset
478 Make_Op_Subtract
(Sloc
,
479 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
480 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
481 end Actual_Family_Offset
;
483 -- Start of processing for Actual_Index_Expression
486 -- The queues of entries and entry families appear in textual order in
487 -- the associated record. The entry index is computed as the sum of the
488 -- number of queues for all entries that precede the designated one, to
489 -- which is added the index expression, if this expression denotes a
490 -- member of a family.
492 -- The following is a place holder for the count of simple entries
494 Num
:= Make_Integer_Literal
(Sloc
, 1);
496 -- We construct an expression which is a series of addition operations.
497 -- See comments in Entry_Index_Expression, which is identical in
500 if Present
(Index
) then
501 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
508 Actual_Family_Offset
(
509 Make_Attribute_Reference
(Sloc
,
510 Attribute_Name
=> Name_Pos
,
511 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
512 Expressions
=> New_List
(Relocate_Node
(Index
))),
513 Type_Low_Bound
(S
)));
518 -- Now add lengths of preceding entries and entry families
520 Prev
:= First_Entity
(Ttyp
);
522 while Chars
(Prev
) /= Chars
(Ent
)
523 or else (Ekind
(Prev
) /= Ekind
(Ent
))
524 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
526 if Ekind
(Prev
) = E_Entry
then
527 Set_Intval
(Num
, Intval
(Num
) + 1);
529 elsif Ekind
(Prev
) = E_Entry_Family
then
531 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
533 -- The need for the following full view retrieval stems from
534 -- this complex case of nested generics and tasking:
537 -- type Formal_Index is range <>;
540 -- type Index is private;
547 -- type Index is new Formal_Index range 1 .. 10;
550 -- package body Outer is
552 -- entry Fam (Index); -- (2)
555 -- package body Inner is -- (3)
563 -- We are currently building the index expression for the entry
564 -- call "T.E" (1). Part of the expansion must mention the range
565 -- of the discrete type "Index" (2) of entry family "Fam".
566 -- However only the private view of type "Index" is available to
567 -- the inner generic (3) because there was no prior mention of
568 -- the type inside "Inner". This visibility requirement is
569 -- implicit and cannot be detected during the construction of
570 -- the generic trees and needs special handling.
573 and then Is_Private_Type
(S
)
574 and then Present
(Full_View
(S
))
579 Lo
:= Type_Low_Bound
(S
);
580 Hi
:= Type_High_Bound
(S
);
588 Actual_Family_Offset
(Hi
, Lo
),
590 Make_Integer_Literal
(Sloc
, 1)));
592 -- Other components are anonymous types to be ignored
602 end Actual_Index_Expression
;
604 --------------------------
605 -- Add_Formal_Renamings --
606 --------------------------
608 procedure Add_Formal_Renamings
614 Ptr
: constant Entity_Id
:=
616 (Next
(First
(Parameter_Specifications
(Spec
))));
617 -- The name of the formal that holds the address of the parameter block
626 Formal
:= First_Formal
(Ent
);
627 while Present
(Formal
) loop
628 Comp
:= Entry_Component
(Formal
);
630 Make_Defining_Identifier
(Sloc
(Formal
),
631 Chars
=> Chars
(Formal
));
632 Set_Etype
(New_F
, Etype
(Formal
));
633 Set_Scope
(New_F
, Ent
);
635 -- Now we set debug info needed on New_F even though it does not
636 -- come from source, so that the debugger will get the right
637 -- information for these generated names.
639 Set_Debug_Info_Needed
(New_F
);
641 if Ekind
(Formal
) = E_In_Parameter
then
642 Set_Ekind
(New_F
, E_Constant
);
644 Set_Ekind
(New_F
, E_Variable
);
645 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
648 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
651 Make_Object_Renaming_Declaration
(Loc
,
652 Defining_Identifier
=> New_F
,
654 New_Reference_To
(Etype
(Formal
), Loc
),
656 Make_Explicit_Dereference
(Loc
,
657 Make_Selected_Component
(Loc
,
659 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
660 Make_Identifier
(Loc
, Chars
(Ptr
))),
662 New_Reference_To
(Comp
, Loc
))));
664 Append
(Decl
, Decls
);
665 Set_Renamed_Object
(Formal
, New_F
);
666 Next_Formal
(Formal
);
668 end Add_Formal_Renamings
;
670 ------------------------
671 -- Add_Object_Pointer --
672 ------------------------
674 procedure Add_Object_Pointer
676 Conc_Typ
: Entity_Id
;
679 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
684 -- Create the renaming declaration for the Protection object of a
685 -- protected type. _Object is used by Complete_Entry_Body.
686 -- ??? An attempt to make this a renaming was unsuccessful.
688 -- Build the entity for the access type
691 Make_Defining_Identifier
(Loc
,
692 New_External_Name
(Chars
(Rec_Typ
), 'P'));
695 -- _object : poVP := poVP!O;
698 Make_Object_Declaration
(Loc
,
699 Defining_Identifier
=>
700 Make_Defining_Identifier
(Loc
, Name_uObject
),
702 New_Reference_To
(Obj_Ptr
, Loc
),
704 Unchecked_Convert_To
(Obj_Ptr
,
705 Make_Identifier
(Loc
, Name_uO
)));
706 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
707 Prepend_To
(Decls
, Decl
);
710 -- type poVP is access poV;
713 Make_Full_Type_Declaration
(Loc
,
714 Defining_Identifier
=>
717 Make_Access_To_Object_Definition
(Loc
,
718 Subtype_Indication
=>
719 New_Reference_To
(Rec_Typ
, Loc
)));
720 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
721 Prepend_To
(Decls
, Decl
);
722 end Add_Object_Pointer
;
724 -----------------------
725 -- Build_Accept_Body --
726 -----------------------
728 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
729 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
730 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
737 -- At the end of the statement sequence, Complete_Rendezvous is called.
738 -- A label skipping the Complete_Rendezvous, and all other accept
739 -- processing, has already been added for the expansion of requeue
742 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Rendezvous
);
743 Insert_Before
(Last
(Statements
(Stats
)), Call
);
746 -- If exception handlers are present, then append Complete_Rendezvous
747 -- calls to the handlers, and construct the required outer block.
749 if Present
(Exception_Handlers
(Stats
)) then
750 Hand
:= First
(Exception_Handlers
(Stats
));
752 while Present
(Hand
) loop
753 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Rendezvous
);
754 Append
(Call
, Statements
(Hand
));
760 Make_Handled_Sequence_Of_Statements
(Loc
,
761 Statements
=> New_List
(
762 Make_Block_Statement
(Loc
,
763 Handled_Statement_Sequence
=> Stats
)));
769 -- At this stage we know that the new statement sequence does not
770 -- have an exception handler part, so we supply one to call
771 -- Exceptional_Complete_Rendezvous. This handler is
773 -- when all others =>
774 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
776 -- We handle Abort_Signal to make sure that we properly catch the abort
777 -- case and wake up the caller.
779 Ohandle
:= Make_Others_Choice
(Loc
);
780 Set_All_Others
(Ohandle
);
782 Set_Exception_Handlers
(New_S
,
784 Make_Implicit_Exception_Handler
(Loc
,
785 Exception_Choices
=> New_List
(Ohandle
),
787 Statements
=> New_List
(
788 Make_Procedure_Call_Statement
(Loc
,
789 Name
=> New_Reference_To
(
790 RTE
(RE_Exceptional_Complete_Rendezvous
), Loc
),
791 Parameter_Associations
=> New_List
(
792 Make_Function_Call
(Loc
,
793 Name
=> New_Reference_To
(
794 RTE
(RE_Get_GNAT_Exception
), Loc
))))))));
796 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
797 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
798 Expand_Exception_Handlers
(New_S
);
800 -- Exceptional_Complete_Rendezvous must be called with abort
801 -- still deferred, which is the case for a "when all others" handler.
804 end Build_Accept_Body
;
806 -----------------------------------
807 -- Build_Activation_Chain_Entity --
808 -----------------------------------
810 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
816 -- Loop to find enclosing construct containing activation chain variable
820 while not Nkind_In
(P
, N_Subprogram_Body
,
821 N_Package_Declaration
,
825 N_Extended_Return_Statement
)
830 -- If we are in a package body, the activation chain variable is
831 -- declared in the body, but the Activation_Chain_Entity is attached to
834 if Nkind
(P
) = N_Package_Body
then
835 Decls
:= Declarations
(P
);
836 P
:= Unit_Declaration_Node
(Corresponding_Spec
(P
));
838 elsif Nkind
(P
) = N_Package_Declaration
then
839 Decls
:= Visible_Declarations
(Specification
(P
));
841 elsif Nkind
(P
) = N_Extended_Return_Statement
then
842 Decls
:= Return_Object_Declarations
(P
);
845 Decls
:= Declarations
(P
);
848 -- If activation chain entity not already declared, declare it
850 if Nkind
(P
) = N_Extended_Return_Statement
851 or else No
(Activation_Chain_Entity
(P
))
853 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
855 -- Note: An extended return statement is not really a task activator,
856 -- but it does have an activation chain on which to store the tasks
857 -- temporarily. On successful return, the tasks on this chain are
858 -- moved to the chain passed in by the caller. We do not build an
859 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
860 -- because we do not want to build a call to Activate_Tasks. Task
861 -- activation is the responsibility of the caller.
863 if Nkind
(P
) /= N_Extended_Return_Statement
then
864 Set_Activation_Chain_Entity
(P
, Chain
);
868 Make_Object_Declaration
(Sloc
(P
),
869 Defining_Identifier
=> Chain
,
870 Aliased_Present
=> True,
872 New_Reference_To
(RTE
(RE_Activation_Chain
), Sloc
(P
))));
874 Analyze
(First
(Decls
));
876 end Build_Activation_Chain_Entity
;
878 ----------------------------
879 -- Build_Barrier_Function --
880 ----------------------------
882 function Build_Barrier_Function
885 Pid
: Node_Id
) return Node_Id
887 Loc
: constant Source_Ptr
:= Sloc
(N
);
888 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
889 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
890 Op_Decls
: constant List_Id
:= New_List
;
894 -- Add a declaration for the Protection object, renaming declarations
895 -- for the discriminals and privals and finally a declaration for the
896 -- entry family index (if applicable).
898 Install_Private_Data_Declarations
899 (Loc
, Func_Id
, Pid
, N
, Op_Decls
, True, Ekind
(Ent
) = E_Entry_Family
);
901 -- Note: the condition in the barrier function needs to be properly
902 -- processed for the C/Fortran boolean possibility, but this happens
903 -- automatically since the return statement does this normalization.
906 Make_Subprogram_Body
(Loc
,
908 Build_Barrier_Function_Specification
(Loc
,
909 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
910 Declarations
=> Op_Decls
,
911 Handled_Statement_Sequence
=>
912 Make_Handled_Sequence_Of_Statements
(Loc
,
913 Statements
=> New_List
(
914 Make_Simple_Return_Statement
(Loc
,
915 Expression
=> Condition
(Ent_Formals
)))));
916 Set_Is_Entry_Barrier_Function
(Func_Body
);
919 end Build_Barrier_Function
;
921 ------------------------------------------
922 -- Build_Barrier_Function_Specification --
923 ------------------------------------------
925 function Build_Barrier_Function_Specification
927 Def_Id
: Entity_Id
) return Node_Id
930 Set_Debug_Info_Needed
(Def_Id
);
932 return Make_Function_Specification
(Loc
,
933 Defining_Unit_Name
=> Def_Id
,
934 Parameter_Specifications
=> New_List
(
935 Make_Parameter_Specification
(Loc
,
936 Defining_Identifier
=>
937 Make_Defining_Identifier
(Loc
, Name_uO
),
939 New_Reference_To
(RTE
(RE_Address
), Loc
)),
941 Make_Parameter_Specification
(Loc
,
942 Defining_Identifier
=>
943 Make_Defining_Identifier
(Loc
, Name_uE
),
945 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
948 New_Reference_To
(Standard_Boolean
, Loc
));
949 end Build_Barrier_Function_Specification
;
951 --------------------------
952 -- Build_Call_With_Task --
953 --------------------------
955 function Build_Call_With_Task
957 E
: Entity_Id
) return Node_Id
959 Loc
: constant Source_Ptr
:= Sloc
(N
);
962 Make_Function_Call
(Loc
,
963 Name
=> New_Reference_To
(E
, Loc
),
964 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
965 end Build_Call_With_Task
;
967 --------------------------------
968 -- Build_Corresponding_Record --
969 --------------------------------
971 function Build_Corresponding_Record
974 Loc
: Source_Ptr
) return Node_Id
976 Rec_Ent
: constant Entity_Id
:=
977 Make_Defining_Identifier
978 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
981 New_Disc
: Entity_Id
;
985 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
986 Set_Ekind
(Rec_Ent
, E_Record_Type
);
987 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
988 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
989 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
990 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
993 -- Use discriminals to create list of discriminants for record, and
994 -- create new discriminals for use in default expressions, etc. It is
995 -- worth noting that a task discriminant gives rise to 5 entities;
997 -- a) The original discriminant.
998 -- b) The discriminal for use in the task.
999 -- c) The discriminant of the corresponding record.
1000 -- d) The discriminal for the init proc of the corresponding record.
1001 -- e) The local variable that renames the discriminant in the procedure
1002 -- for the task body.
1004 -- In fact the discriminals b) are used in the renaming declarations
1005 -- for e). See details in einfo (Handling of Discriminants).
1007 if Present
(Discriminant_Specifications
(N
)) then
1009 Disc
:= First_Discriminant
(Ctyp
);
1011 while Present
(Disc
) loop
1012 New_Disc
:= CR_Discriminant
(Disc
);
1015 Make_Discriminant_Specification
(Loc
,
1016 Defining_Identifier
=> New_Disc
,
1017 Discriminant_Type
=>
1018 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1020 New_Copy
(Discriminant_Default_Value
(Disc
))));
1022 Next_Discriminant
(Disc
);
1029 -- Now we can construct the record type declaration. Note that this
1030 -- record is "limited tagged". It is "limited" to reflect the underlying
1031 -- limitedness of the task or protected object that it represents, and
1032 -- ensuring for example that it is properly passed by reference. It is
1033 -- "tagged" to give support to dispatching calls through interfaces (Ada
1037 Make_Full_Type_Declaration
(Loc
,
1038 Defining_Identifier
=> Rec_Ent
,
1039 Discriminant_Specifications
=> Dlist
,
1041 Make_Record_Definition
(Loc
,
1043 Make_Component_List
(Loc
,
1044 Component_Items
=> Cdecls
),
1046 Ada_Version
>= Ada_05
and then Is_Tagged_Type
(Ctyp
),
1047 Limited_Present
=> True));
1048 end Build_Corresponding_Record
;
1050 ----------------------------------
1051 -- Build_Entry_Count_Expression --
1052 ----------------------------------
1054 function Build_Entry_Count_Expression
1055 (Concurrent_Type
: Node_Id
;
1056 Component_List
: List_Id
;
1057 Loc
: Source_Ptr
) return Node_Id
1069 -- Count number of non-family entries
1072 Ent
:= First_Entity
(Concurrent_Type
);
1073 while Present
(Ent
) loop
1074 if Ekind
(Ent
) = E_Entry
then
1081 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1083 -- Loop through entry families building the addition nodes
1085 Ent
:= First_Entity
(Concurrent_Type
);
1086 Comp
:= First
(Component_List
);
1087 while Present
(Ent
) loop
1088 if Ekind
(Ent
) = E_Entry_Family
then
1089 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1093 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1094 Hi
:= Type_High_Bound
(Typ
);
1095 Lo
:= Type_Low_Bound
(Typ
);
1096 Large
:= Is_Potentially_Large_Family
1097 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1100 Left_Opnd
=> Ecount
,
1101 Right_Opnd
=> Family_Size
1102 (Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1109 end Build_Entry_Count_Expression
;
1111 -----------------------
1112 -- Build_Entry_Names --
1113 -----------------------
1115 function Build_Entry_Names
(Conc_Typ
: Entity_Id
) return Node_Id
is
1116 Loc
: constant Source_Ptr
:= Sloc
(Conc_Typ
);
1122 Typ
: Entity_Id
:= Conc_Typ
;
1124 procedure Build_Entry_Family_Name
(Id
: Entity_Id
);
1126 -- for Lnn in Family_Low .. Family_High loop
1129 -- (_init._object, Inn, new String ("<Entry name> " & Lnn'Img));
1132 -- Note that the bounds of the range may reference discriminants. The
1133 -- above construct is added directly to the statements of the block.
1135 procedure Build_Entry_Name
(Id
: Entity_Id
);
1138 -- Set_Entry_Name (_init._task_id, Inn, new String ("<Entry name>");
1140 -- The above construct is added directly to the statements of the block.
1142 function Build_Set_Entry_Name_Call
(Arg3
: Node_Id
) return Node_Id
;
1143 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1144 -- _init._task_id or _init._object, Inn and Arg3.
1146 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
;
1147 -- Given a protected type or its corresponding record, find the type of
1150 procedure Increment_Index
(Stmts
: List_Id
);
1151 -- Generate the following and add it to Stmts
1154 -----------------------------
1155 -- Build_Entry_Family_Name --
1156 -----------------------------
1158 procedure Build_Entry_Family_Name
(Id
: Entity_Id
) is
1159 Def
: constant Node_Id
:=
1160 Discrete_Subtype_Definition
(Parent
(Id
));
1161 L_Id
: constant Entity_Id
:=
1162 Make_Defining_Identifier
(Loc
, New_Internal_Name
('L'));
1163 L_Stmts
: constant List_Id
:= New_List
;
1166 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1167 -- Given a discrete subtype definition of an entry family, generate a
1168 -- range node which covers the range of Def's type.
1174 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1175 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1176 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1179 -- If a bound references a discriminant, generate an identifier
1180 -- with the same name. Resolution will map it to the formals of
1183 if Is_Entity_Name
(Low
)
1184 and then Ekind
(Entity
(Low
)) = E_Discriminant
1186 Low
:= Make_Identifier
(Loc
, Chars
(Low
));
1188 Low
:= New_Copy_Tree
(Low
);
1191 if Is_Entity_Name
(High
)
1192 and then Ekind
(Entity
(High
)) = E_Discriminant
1194 High
:= Make_Identifier
(Loc
, Chars
(High
));
1196 High
:= New_Copy_Tree
(High
);
1202 High_Bound
=> High
);
1205 -- Start of processing for Build_Entry_Family_Name
1208 Get_Name_String
(Chars
(Id
));
1210 if Is_Enumeration_Type
(Etype
(Def
)) then
1211 Name_Len
:= Name_Len
+ 1;
1212 Name_Buffer
(Name_Len
) := ' ';
1216 -- new String'("<Entry name>" & Lnn'Img);
1219 Make_Allocator
(Loc
,
1220 Make_Qualified_Expression
(Loc
,
1222 New_Reference_To
(Standard_String
, Loc
),
1224 Make_Op_Concat
(Loc
,
1226 Make_String_Literal
(Loc
,
1227 String_From_Name_Buffer
),
1229 Make_Attribute_Reference
(Loc
,
1231 New_Reference_To
(L_Id
, Loc
),
1232 Attribute_Name
=> Name_Img
))));
1234 Increment_Index
(L_Stmts
);
1235 Append_To
(L_Stmts
, Build_Set_Entry_Name_Call
(Val
));
1238 -- for Lnn in Family_Low .. Family_High loop
1240 -- Set_Entry_Name (_init._task_id, Inn, <Val>);
1244 Make_Loop_Statement
(Loc
,
1246 Make_Iteration_Scheme
(Loc
,
1247 Loop_Parameter_Specification
=>
1248 Make_Loop_Parameter_Specification
(Loc
,
1249 Defining_Identifier
=> L_Id
,
1250 Discrete_Subtype_Definition
=>
1251 Build_Range
(Def
))),
1252 Statements
=> L_Stmts
,
1253 End_Label
=> Empty
));
1254 end Build_Entry_Family_Name
;
1256 ----------------------
1257 -- Build_Entry_Name --
1258 ----------------------
1260 procedure Build_Entry_Name
(Id
: Entity_Id
) is
1264 Get_Name_String
(Chars
(Id
));
1266 Make_Allocator
(Loc
,
1267 Make_Qualified_Expression
(Loc
,
1269 New_Reference_To
(Standard_String
, Loc
),
1271 Make_String_Literal
(Loc
,
1272 String_From_Name_Buffer
)));
1274 Increment_Index
(B_Stmts
);
1275 Append_To
(B_Stmts
, Build_Set_Entry_Name_Call
(Val
));
1276 end Build_Entry_Name
;
1278 -------------------------------
1279 -- Build_Set_Entry_Name_Call --
1280 -------------------------------
1282 function Build_Set_Entry_Name_Call
(Arg3
: Node_Id
) return Node_Id
is
1287 -- Determine the proper name for the first argument and the RTS
1290 if Is_Protected_Type
(Typ
) then
1291 Arg1
:= Name_uObject
;
1292 Proc
:= RO_PE_Set_Entry_Name
;
1294 else pragma Assert
(Is_Task_Type
(Typ
));
1295 Arg1
:= Name_uTask_Id
;
1296 Proc
:= RO_TS_Set_Entry_Name
;
1300 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1303 Make_Procedure_Call_Statement
(Loc
,
1305 New_Reference_To
(RTE
(Proc
), Loc
),
1306 Parameter_Associations
=> New_List
(
1307 Make_Selected_Component
(Loc
, -- _init._object
1308 Prefix
=> -- _init._task_id
1309 Make_Identifier
(Loc
, Name_uInit
),
1311 Make_Identifier
(Loc
, Arg1
)),
1312 New_Reference_To
(Index
, Loc
), -- Inn
1314 end Build_Set_Entry_Name_Call
;
1316 --------------------------
1317 -- Find_Protection_Type --
1318 --------------------------
1320 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
is
1322 Typ
: Entity_Id
:= Conc_Typ
;
1325 if Is_Concurrent_Type
(Typ
) then
1326 Typ
:= Corresponding_Record_Type
(Typ
);
1329 Comp
:= First_Component
(Typ
);
1330 while Present
(Comp
) loop
1331 if Chars
(Comp
) = Name_uObject
then
1332 return Base_Type
(Etype
(Comp
));
1335 Next_Component
(Comp
);
1338 -- The corresponding record of a protected type should always have an
1341 raise Program_Error
;
1342 end Find_Protection_Type
;
1344 ---------------------
1345 -- Increment_Index --
1346 ---------------------
1348 procedure Increment_Index
(Stmts
: List_Id
) is
1354 Make_Assignment_Statement
(Loc
,
1356 New_Reference_To
(Index
, Loc
),
1360 New_Reference_To
(Index
, Loc
),
1362 Make_Integer_Literal
(Loc
, 1))));
1363 end Increment_Index
;
1365 -- Start of processing for Build_Entry_Names
1368 -- Retrieve the original concurrent type
1370 if Is_Concurrent_Record_Type
(Typ
) then
1371 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1374 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
1376 -- Nothing to do if the type has no entries
1378 if not Has_Entries
(Typ
) then
1382 -- Avoid generating entry names for a protected type with only one entry
1384 if Is_Protected_Type
(Typ
)
1385 and then Find_Protection_Type
(Typ
) /= RTE
(RE_Protection_Entries
)
1390 Index
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
1392 -- Step 1: Generate the declaration of the index variable:
1393 -- Inn : Protected_Entry_Index := 0;
1395 -- Inn : Task_Entry_Index := 0;
1397 if Is_Protected_Type
(Typ
) then
1398 Index_Typ
:= RE_Protected_Entry_Index
;
1400 Index_Typ
:= RE_Task_Entry_Index
;
1403 B_Decls
:= New_List
;
1405 Make_Object_Declaration
(Loc
,
1406 Defining_Identifier
=> Index
,
1407 Object_Definition
=>
1408 New_Reference_To
(RTE
(Index_Typ
), Loc
),
1410 Make_Integer_Literal
(Loc
, 0)));
1412 B_Stmts
:= New_List
;
1414 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1417 Comp
:= First_Entity
(Typ
);
1418 while Present
(Comp
) loop
1419 if Ekind
(Comp
) = E_Entry
then
1420 Build_Entry_Name
(Comp
);
1422 elsif Ekind
(Comp
) = E_Entry_Family
then
1423 Build_Entry_Family_Name
(Comp
);
1429 -- Step 3: Wrap the statements in a block
1432 Make_Block_Statement
(Loc
,
1433 Declarations
=> B_Decls
,
1434 Handled_Statement_Sequence
=>
1435 Make_Handled_Sequence_Of_Statements
(Loc
,
1436 Statements
=> B_Stmts
));
1437 end Build_Entry_Names
;
1439 ---------------------------
1440 -- Build_Parameter_Block --
1441 ---------------------------
1443 function Build_Parameter_Block
1447 Decls
: List_Id
) return Entity_Id
1453 Has_Comp
: Boolean := False;
1457 Actual
:= First
(Actuals
);
1459 Formal
:= Defining_Identifier
(First
(Formals
));
1461 while Present
(Actual
) loop
1462 if not Is_Controlling_Actual
(Actual
) then
1465 -- type Ann is access all <actual-type>
1468 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
1471 Make_Full_Type_Declaration
(Loc
,
1472 Defining_Identifier
=>
1475 Make_Access_To_Object_Definition
(Loc
,
1479 Ekind
(Formal
) = E_In_Parameter
,
1480 Subtype_Indication
=>
1481 New_Reference_To
(Etype
(Actual
), Loc
))));
1487 Make_Component_Declaration
(Loc
,
1488 Defining_Identifier
=>
1489 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1490 Component_Definition
=>
1491 Make_Component_Definition
(Loc
,
1494 Subtype_Indication
=>
1495 New_Reference_To
(Comp_Nam
, Loc
))));
1500 Next_Actual
(Actual
);
1501 Next_Formal_With_Extras
(Formal
);
1505 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
1510 -- type Pnn is record
1515 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1516 -- the original parameter names and Ann1 .. AnnN are the access to
1520 Make_Full_Type_Declaration
(Loc
,
1521 Defining_Identifier
=>
1524 Make_Record_Definition
(Loc
,
1526 Make_Component_List
(Loc
, Comps
))));
1529 -- type Pnn is null record;
1532 Make_Full_Type_Declaration
(Loc
,
1533 Defining_Identifier
=>
1536 Make_Record_Definition
(Loc
,
1537 Null_Present
=> True,
1538 Component_List
=> Empty
)));
1542 end Build_Parameter_Block
;
1544 ------------------------
1545 -- Build_Wrapper_Body --
1546 ------------------------
1548 function Build_Wrapper_Body
1550 Proc_Nam
: Entity_Id
;
1551 Obj_Typ
: Entity_Id
;
1552 Formals
: List_Id
) return Node_Id
1554 Actuals
: List_Id
:= No_List
;
1555 Body_Spec
: Node_Id
;
1557 First_Formal
: Node_Id
;
1561 Body_Spec
:= Build_Wrapper_Spec
(Loc
, Proc_Nam
, Obj_Typ
, Formals
);
1563 -- If we did not generate the specification do have nothing else to do
1565 if Body_Spec
= Empty
then
1569 -- Map formals to actuals. Use the list built for the wrapper spec,
1570 -- skipping the object notation parameter.
1572 First_Formal
:= First
(Parameter_Specifications
(Body_Spec
));
1574 Formal
:= First_Formal
;
1577 if Present
(Formal
) then
1578 Actuals
:= New_List
;
1580 while Present
(Formal
) loop
1582 Make_Identifier
(Loc
, Chars
=>
1583 Chars
(Defining_Identifier
(Formal
))));
1589 -- An access-to-variable first parameter will require an explicit
1590 -- dereference in the unchecked conversion. This case occurs when
1591 -- a protected entry wrapper must override an interface-level
1592 -- procedure with interface access as first parameter.
1594 -- SubprgName (O.all).Proc_Nam (Formal_1 .. Formal_N)
1596 if Nkind
(Parameter_Type
(First_Formal
)) = N_Access_Definition
then
1598 Make_Explicit_Dereference
(Loc
,
1600 Make_Identifier
(Loc
, Chars
=> Name_uO
));
1603 Make_Identifier
(Loc
, Chars
=> Name_uO
);
1606 if Ekind
(Proc_Nam
) = E_Function
then
1608 Make_Subprogram_Body
(Loc
,
1609 Specification
=> Body_Spec
,
1610 Declarations
=> Empty_List
,
1611 Handled_Statement_Sequence
=>
1612 Make_Handled_Sequence_Of_Statements
(Loc
,
1615 Make_Simple_Return_Statement
(Loc
,
1616 Make_Function_Call
(Loc
,
1618 Make_Selected_Component
(Loc
,
1620 Unchecked_Convert_To
(
1621 Corresponding_Concurrent_Type
(Obj_Typ
),
1624 New_Reference_To
(Proc_Nam
, Loc
)),
1625 Parameter_Associations
=> Actuals
)))));
1628 Make_Subprogram_Body
(Loc
,
1629 Specification
=> Body_Spec
,
1630 Declarations
=> Empty_List
,
1631 Handled_Statement_Sequence
=>
1632 Make_Handled_Sequence_Of_Statements
(Loc
,
1635 Make_Procedure_Call_Statement
(Loc
,
1637 Make_Selected_Component
(Loc
,
1639 Unchecked_Convert_To
(
1640 Corresponding_Concurrent_Type
(Obj_Typ
),
1643 New_Reference_To
(Proc_Nam
, Loc
)),
1644 Parameter_Associations
=> Actuals
))));
1646 end Build_Wrapper_Body
;
1648 ------------------------
1649 -- Build_Wrapper_Spec --
1650 ------------------------
1652 function Build_Wrapper_Spec
1654 Proc_Nam
: Entity_Id
;
1655 Obj_Typ
: Entity_Id
;
1656 Formals
: List_Id
) return Node_Id
1658 New_Name_Id
: constant Entity_Id
:=
1659 Make_Defining_Identifier
(Loc
, Chars
(Proc_Nam
));
1661 First_Param
: Node_Id
:= Empty
;
1663 Iface_Elmt
: Elmt_Id
:= No_Elmt
;
1664 New_Formals
: List_Id
;
1665 Obj_Param
: Node_Id
;
1666 Obj_Param_Typ
: Node_Id
;
1667 Iface_Prim_Op
: Entity_Id
;
1668 Iface_Prim_Op_Elmt
: Elmt_Id
;
1670 function Overriding_Possible
1671 (Iface_Prim_Op
: Entity_Id
;
1672 Proc_Nam
: Entity_Id
) return Boolean;
1673 -- Determine whether a primitive operation can be overridden by the
1674 -- wrapper. Iface_Prim_Op is the candidate primitive operation of an
1675 -- abstract interface type, Proc_Nam is the generated entry wrapper.
1677 function Replicate_Entry_Formals
1679 Formals
: List_Id
) return List_Id
;
1680 -- An explicit parameter replication is required due to the
1681 -- Is_Entry_Formal flag being set for all the formals. The explicit
1682 -- replication removes the flag that would otherwise cause a different
1683 -- path of analysis.
1685 -------------------------
1686 -- Overriding_Possible --
1687 -------------------------
1689 function Overriding_Possible
1690 (Iface_Prim_Op
: Entity_Id
;
1691 Proc_Nam
: Entity_Id
) return Boolean
1693 Prim_Op_Spec
: constant Node_Id
:= Parent
(Iface_Prim_Op
);
1694 Proc_Spec
: constant Node_Id
:= Parent
(Proc_Nam
);
1696 Is_Access_To_Variable
: Boolean;
1697 Is_Out_Present
: Boolean;
1699 function Type_Conformant_Parameters
1700 (Prim_Op_Param_Specs
: List_Id
;
1701 Proc_Param_Specs
: List_Id
) return Boolean;
1702 -- Determine whether the parameters of the generated entry wrapper
1703 -- and those of a primitive operation are type conformant. During
1704 -- this check, the first parameter of the primitive operation is
1707 --------------------------------
1708 -- Type_Conformant_Parameters --
1709 --------------------------------
1711 function Type_Conformant_Parameters
1712 (Prim_Op_Param_Specs
: List_Id
;
1713 Proc_Param_Specs
: List_Id
) return Boolean
1715 Prim_Op_Param
: Node_Id
;
1716 Prim_Op_Typ
: Entity_Id
;
1717 Proc_Param
: Node_Id
;
1718 Proc_Typ
: Entity_Id
;
1721 -- Skip the first parameter of the primitive operation
1723 Prim_Op_Param
:= Next
(First
(Prim_Op_Param_Specs
));
1724 Proc_Param
:= First
(Proc_Param_Specs
);
1725 while Present
(Prim_Op_Param
)
1726 and then Present
(Proc_Param
)
1728 Prim_Op_Typ
:= Find_Parameter_Type
(Prim_Op_Param
);
1729 Proc_Typ
:= Find_Parameter_Type
(Proc_Param
);
1731 -- The two parameters must be mode conformant
1733 if not Conforming_Types
1734 (Prim_Op_Typ
, Proc_Typ
, Mode_Conformant
)
1739 Next
(Prim_Op_Param
);
1743 -- One of the lists is longer than the other
1745 if Present
(Prim_Op_Param
) or else Present
(Proc_Param
) then
1750 end Type_Conformant_Parameters
;
1752 -- Start of processing for Overriding_Possible
1755 if Chars
(Iface_Prim_Op
) /= Chars
(Proc_Nam
) then
1759 -- Special check for protected procedures: If an inherited subprogram
1760 -- is implemented by a protected procedure or an entry, then the
1761 -- first parameter of the inherited subprogram shall be of mode OUT
1762 -- or IN OUT, or an access-to-variable parameter.
1764 if Ekind
(Iface_Prim_Op
) = E_Procedure
then
1767 Present
(Parameter_Specifications
(Prim_Op_Spec
))
1769 Out_Present
(First
(Parameter_Specifications
(Prim_Op_Spec
)));
1771 Is_Access_To_Variable
:=
1772 Present
(Parameter_Specifications
(Prim_Op_Spec
))
1774 Nkind
(Parameter_Type
1776 (Parameter_Specifications
(Prim_Op_Spec
)))) =
1777 N_Access_Definition
;
1779 if not Is_Out_Present
1780 and then not Is_Access_To_Variable
1786 return Type_Conformant_Parameters
(
1787 Parameter_Specifications
(Prim_Op_Spec
),
1788 Parameter_Specifications
(Proc_Spec
));
1789 end Overriding_Possible
;
1791 -----------------------------
1792 -- Replicate_Entry_Formals --
1793 -----------------------------
1795 function Replicate_Entry_Formals
1797 Formals
: List_Id
) return List_Id
1799 New_Formals
: constant List_Id
:= New_List
;
1801 Param_Type
: Node_Id
;
1804 Formal
:= First
(Formals
);
1805 while Present
(Formal
) loop
1807 -- Create an explicit copy of the entry parameter
1809 -- When creating the wrapper subprogram for a primitive operation
1810 -- of a protected interface we must construct an equivalent
1811 -- signature to that of the overriding operation. For regular
1812 -- parameters we can just use the type of the formal, but for
1813 -- access to subprogram parameters we need to reanalyze the
1814 -- parameter type to create local entities for the signature of
1815 -- the subprogram type. Using the entities of the overriding
1816 -- subprogram will result in out-of-scope errors in the back-end.
1818 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
1819 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
1822 New_Reference_To
(Etype
(Parameter_Type
(Formal
)), Loc
);
1825 Append_To
(New_Formals
,
1826 Make_Parameter_Specification
(Loc
,
1827 Defining_Identifier
=>
1828 Make_Defining_Identifier
(Loc
,
1829 Chars
=> Chars
(Defining_Identifier
(Formal
))),
1830 In_Present
=> In_Present
(Formal
),
1831 Out_Present
=> Out_Present
(Formal
),
1832 Parameter_Type
=> Param_Type
));
1838 end Replicate_Entry_Formals
;
1840 -- Start of processing for Build_Wrapper_Spec
1843 -- The mode is determined by the first parameter of the interface-level
1844 -- procedure that the current entry is trying to override.
1846 pragma Assert
(Is_Non_Empty_List
(Abstract_Interface_List
(Obj_Typ
)));
1848 -- We must examine all the protected operations of the implemented
1849 -- interfaces in order to discover a possible overriding candidate.
1851 Iface
:= Etype
(First
(Abstract_Interface_List
(Obj_Typ
)));
1853 Examine_Parents
: loop
1854 if Present
(Primitive_Operations
(Iface
)) then
1855 Iface_Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1856 while Present
(Iface_Prim_Op_Elmt
) loop
1857 Iface_Prim_Op
:= Node
(Iface_Prim_Op_Elmt
);
1859 if not Is_Predefined_Dispatching_Operation
(Iface_Prim_Op
) then
1860 while Present
(Alias
(Iface_Prim_Op
)) loop
1861 Iface_Prim_Op
:= Alias
(Iface_Prim_Op
);
1864 -- The current primitive operation can be overridden by the
1865 -- generated entry wrapper.
1867 if Overriding_Possible
(Iface_Prim_Op
, Proc_Nam
) then
1868 First_Param
:= First
(Parameter_Specifications
1869 (Parent
(Iface_Prim_Op
)));
1875 Next_Elmt
(Iface_Prim_Op_Elmt
);
1879 exit Examine_Parents
when Etype
(Iface
) = Iface
;
1881 Iface
:= Etype
(Iface
);
1882 end loop Examine_Parents
;
1884 if Present
(Interfaces
1885 (Corresponding_Record_Type
(Scope
(Proc_Nam
))))
1887 Iface_Elmt
:= First_Elmt
1889 (Corresponding_Record_Type
(Scope
(Proc_Nam
))));
1890 Examine_Interfaces
: while Present
(Iface_Elmt
) loop
1891 Iface
:= Node
(Iface_Elmt
);
1893 if Present
(Primitive_Operations
(Iface
)) then
1894 Iface_Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1895 while Present
(Iface_Prim_Op_Elmt
) loop
1896 Iface_Prim_Op
:= Node
(Iface_Prim_Op_Elmt
);
1898 if not Is_Predefined_Dispatching_Operation
1901 while Present
(Alias
(Iface_Prim_Op
)) loop
1902 Iface_Prim_Op
:= Alias
(Iface_Prim_Op
);
1905 -- The current primitive operation can be overridden by
1906 -- the generated entry wrapper.
1908 if Overriding_Possible
(Iface_Prim_Op
, Proc_Nam
) then
1909 First_Param
:= First
(Parameter_Specifications
1910 (Parent
(Iface_Prim_Op
)));
1916 Next_Elmt
(Iface_Prim_Op_Elmt
);
1920 Next_Elmt
(Iface_Elmt
);
1921 end loop Examine_Interfaces
;
1924 -- Return if no interface primitive can be overridden
1930 New_Formals
:= Replicate_Entry_Formals
(Loc
, Formals
);
1932 -- ??? Certain source packages contain protected or task types that do
1933 -- not implement any interfaces and are compiled with the -gnat05
1934 -- switch. In this case, a default first parameter is created.
1936 -- If the interface operation has an access parameter, create a copy
1937 -- of it, with the same null exclusion indicator if present.
1939 if Present
(First_Param
) then
1940 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
1942 Make_Access_Definition
(Loc
,
1944 New_Reference_To
(Obj_Typ
, Loc
));
1945 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
1946 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
1949 Obj_Param_Typ
:= New_Reference_To
(Obj_Typ
, Loc
);
1953 Make_Parameter_Specification
(Loc
,
1954 Defining_Identifier
=>
1955 Make_Defining_Identifier
(Loc
, Name_uO
),
1956 In_Present
=> In_Present
(First_Param
),
1957 Out_Present
=> Out_Present
(First_Param
),
1958 Parameter_Type
=> Obj_Param_Typ
);
1962 Make_Parameter_Specification
(Loc
,
1963 Defining_Identifier
=>
1964 Make_Defining_Identifier
(Loc
, Name_uO
),
1966 Out_Present
=> True,
1967 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
1970 Prepend_To
(New_Formals
, Obj_Param
);
1972 -- Minimum decoration needed to catch the entity in
1973 -- Sem_Ch6.Override_Dispatching_Operation
1975 if Ekind
(Proc_Nam
) = E_Procedure
1976 or else Ekind
(Proc_Nam
) = E_Entry
1978 Set_Ekind
(New_Name_Id
, E_Procedure
);
1979 Set_Is_Primitive_Wrapper
(New_Name_Id
);
1980 Set_Wrapped_Entity
(New_Name_Id
, Proc_Nam
);
1983 Make_Procedure_Specification
(Loc
,
1984 Defining_Unit_Name
=> New_Name_Id
,
1985 Parameter_Specifications
=> New_Formals
);
1987 else pragma Assert
(Ekind
(Proc_Nam
) = E_Function
);
1988 Set_Ekind
(New_Name_Id
, E_Function
);
1991 Make_Function_Specification
(Loc
,
1992 Defining_Unit_Name
=> New_Name_Id
,
1993 Parameter_Specifications
=> New_Formals
,
1994 Result_Definition
=>
1995 New_Copy
(Result_Definition
(Parent
(Proc_Nam
))));
1997 end Build_Wrapper_Spec
;
1999 ---------------------------
2000 -- Build_Find_Body_Index --
2001 ---------------------------
2003 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2004 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2007 Has_F
: Boolean := False;
2009 If_St
: Node_Id
:= Empty
;
2012 Decls
: List_Id
:= New_List
;
2015 Siz
: Node_Id
:= Empty
;
2017 procedure Add_If_Clause
(Expr
: Node_Id
);
2018 -- Add test for range of current entry
2020 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2021 -- If a bound of an entry is given by a discriminant, retrieve the
2022 -- actual value of the discriminant from the enclosing object.
2028 procedure Add_If_Clause
(Expr
: Node_Id
) is
2030 Stats
: constant List_Id
:=
2032 Make_Simple_Return_Statement
(Loc
,
2033 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2036 -- Index for current entry body
2040 -- Compute total length of entry queues so far
2048 Right_Opnd
=> Expr
);
2053 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2056 -- Map entry queue indices in the range of the current family
2057 -- into the current index, that designates the entry body.
2061 Make_Implicit_If_Statement
(Typ
,
2063 Then_Statements
=> Stats
,
2064 Elsif_Parts
=> New_List
);
2070 Make_Elsif_Part
(Loc
,
2072 Then_Statements
=> Stats
),
2073 Elsif_Parts
(If_St
));
2077 ------------------------------
2078 -- Convert_Discriminant_Ref --
2079 ------------------------------
2081 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2085 if Is_Entity_Name
(Bound
)
2086 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2089 Make_Selected_Component
(Loc
,
2091 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2092 Make_Explicit_Dereference
(Loc
,
2093 Make_Identifier
(Loc
, Name_uObject
))),
2094 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2095 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2097 B
:= New_Copy_Tree
(Bound
);
2101 end Convert_Discriminant_Ref
;
2103 -- Start of processing for Build_Find_Body_Index
2106 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2108 Ent
:= First_Entity
(Typ
);
2109 while Present
(Ent
) loop
2110 if Ekind
(Ent
) = E_Entry_Family
then
2120 -- If the protected type has no entry families, there is a one-one
2121 -- correspondence between entry queue and entry body.
2124 Make_Simple_Return_Statement
(Loc
,
2125 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2128 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2131 -- if E <= l1 then return 1;
2132 -- elsif E <= l1 + l2 then return 2;
2137 Ent
:= First_Entity
(Typ
);
2139 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2141 while Present
(Ent
) loop
2143 if Ekind
(Ent
) = E_Entry
then
2144 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2146 elsif Ekind
(Ent
) = E_Entry_Family
then
2148 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2149 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2150 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2151 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2160 Make_Simple_Return_Statement
(Loc
,
2161 Expression
=> Make_Integer_Literal
(Loc
, 1));
2163 elsif Nkind
(Ret
) = N_If_Statement
then
2165 -- Ranges are in increasing order, so last one doesn't need guard
2168 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2171 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2177 Make_Subprogram_Body
(Loc
,
2178 Specification
=> Spec
,
2179 Declarations
=> Decls
,
2180 Handled_Statement_Sequence
=>
2181 Make_Handled_Sequence_Of_Statements
(Loc
,
2182 Statements
=> New_List
(Ret
)));
2183 end Build_Find_Body_Index
;
2185 --------------------------------
2186 -- Build_Find_Body_Index_Spec --
2187 --------------------------------
2189 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2190 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2191 Id
: constant Entity_Id
:=
2192 Make_Defining_Identifier
(Loc
,
2193 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2194 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2195 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2199 Make_Function_Specification
(Loc
,
2200 Defining_Unit_Name
=> Id
,
2201 Parameter_Specifications
=> New_List
(
2202 Make_Parameter_Specification
(Loc
,
2203 Defining_Identifier
=> Parm1
,
2205 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2207 Make_Parameter_Specification
(Loc
,
2208 Defining_Identifier
=> Parm2
,
2210 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2211 Result_Definition
=> New_Occurrence_Of
(
2212 RTE
(RE_Protected_Entry_Index
), Loc
));
2213 end Build_Find_Body_Index_Spec
;
2215 -------------------------
2216 -- Build_Master_Entity --
2217 -------------------------
2219 procedure Build_Master_Entity
(E
: Entity_Id
) is
2220 Loc
: constant Source_Ptr
:= Sloc
(E
);
2228 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2229 -- in internal scopes, unless present already.. Required for nested
2230 -- limited aggregates, where the expansion of task components may
2231 -- generate inner blocks. If the block is the rewriting of a call
2232 -- this is valid master.
2234 if Ada_Version
>= Ada_05
then
2235 while Is_Internal
(S
) loop
2236 if Nkind
(Parent
(S
)) = N_Block_Statement
2238 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
2247 -- Nothing to do if we already built a master entity for this scope
2248 -- or if there is no task hierarchy.
2250 if Has_Master_Entity
(S
)
2251 or else Restriction_Active
(No_Task_Hierarchy
)
2256 -- Otherwise first build the master entity
2257 -- _Master : constant Master_Id := Current_Master.all;
2258 -- and insert it just before the current declaration
2261 Make_Object_Declaration
(Loc
,
2262 Defining_Identifier
=>
2263 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2264 Constant_Present
=> True,
2265 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
2267 Make_Explicit_Dereference
(Loc
,
2268 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
2271 Insert_Before
(P
, Decl
);
2274 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2275 -- non-internal scope selected above.
2277 if Ada_Version
>= Ada_05
then
2278 Set_Has_Master_Entity
(S
);
2280 Set_Has_Master_Entity
(Scope
(E
));
2283 -- Now mark the containing scope as a task master
2285 while Nkind
(P
) /= N_Compilation_Unit
loop
2288 -- If we fall off the top, we are at the outer level, and the
2289 -- environment task is our effective master, so nothing to mark.
2292 (P
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2294 Set_Is_Task_Master
(P
, True);
2297 elsif Nkind
(Parent
(P
)) = N_Subunit
then
2298 P
:= Corresponding_Stub
(Parent
(P
));
2301 end Build_Master_Entity
;
2303 ---------------------------
2304 -- Build_Protected_Entry --
2305 ---------------------------
2307 function Build_Protected_Entry
2310 Pid
: Node_Id
) return Node_Id
2312 Loc
: constant Source_Ptr
:= Sloc
(N
);
2314 Decls
: constant List_Id
:= Declarations
(N
);
2315 End_Lab
: constant Node_Id
:=
2316 End_Label
(Handled_Statement_Sequence
(N
));
2317 End_Loc
: constant Source_Ptr
:=
2318 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
2319 -- Used for the generated call to Complete_Entry_Body
2321 Han_Loc
: Source_Ptr
;
2322 -- Used for the exception handler, inserted at end of the body
2324 Op_Decls
: constant List_Id
:= New_List
;
2332 -- Set the source location on the exception handler only when debugging
2333 -- the expanded code (see Make_Implicit_Exception_Handler).
2335 if Debug_Generated_Code
then
2338 -- Otherwise the inserted code should not be visible to the debugger
2341 Han_Loc
:= No_Location
;
2345 Make_Defining_Identifier
(Loc
,
2346 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
2348 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
2350 -- Add the following declarations:
2351 -- type poVP is access poV;
2352 -- _object : poVP := poVP (_O);
2354 -- where _O is the formal parameter associated with the concurrent
2355 -- object. These declarations are needed for Complete_Entry_Body.
2357 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
2359 -- Add renamings for all formals, the Protection object, discriminals,
2360 -- privals and the entry index constant for use by debugger.
2362 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
2363 Debug_Private_Data_Declarations
(Decls
);
2365 case Corresponding_Runtime_Package
(Pid
) is
2366 when System_Tasking_Protected_Objects_Entries
=>
2368 New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
);
2370 when System_Tasking_Protected_Objects_Single_Entry
=>
2372 New_Reference_To
(RTE
(RE_Complete_Single_Entry_Body
), Loc
);
2375 raise Program_Error
;
2378 Op_Stats
:= New_List
(
2379 Make_Block_Statement
(Loc
,
2380 Declarations
=> Decls
,
2381 Handled_Statement_Sequence
=>
2382 Handled_Statement_Sequence
(N
)),
2384 Make_Procedure_Call_Statement
(End_Loc
,
2386 Parameter_Associations
=> New_List
(
2387 Make_Attribute_Reference
(End_Loc
,
2389 Make_Selected_Component
(End_Loc
,
2391 Make_Identifier
(End_Loc
, Name_uObject
),
2393 Make_Identifier
(End_Loc
, Name_uObject
)),
2394 Attribute_Name
=> Name_Unchecked_Access
))));
2396 -- When exceptions can not be propagated, we never need to call
2397 -- Exception_Complete_Entry_Body
2399 if No_Exception_Handlers_Set
then
2401 Make_Subprogram_Body
(Loc
,
2402 Specification
=> Espec
,
2403 Declarations
=> Op_Decls
,
2404 Handled_Statement_Sequence
=>
2405 Make_Handled_Sequence_Of_Statements
(Loc
,
2406 Statements
=> Op_Stats
,
2407 End_Label
=> End_Lab
));
2410 Ohandle
:= Make_Others_Choice
(Loc
);
2411 Set_All_Others
(Ohandle
);
2413 case Corresponding_Runtime_Package
(Pid
) is
2414 when System_Tasking_Protected_Objects_Entries
=>
2417 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
2419 when System_Tasking_Protected_Objects_Single_Entry
=>
2422 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
2425 raise Program_Error
;
2428 -- Create body of entry procedure. The renaming declarations are
2429 -- placed ahead of the block that contains the actual entry body.
2432 Make_Subprogram_Body
(Loc
,
2433 Specification
=> Espec
,
2434 Declarations
=> Op_Decls
,
2435 Handled_Statement_Sequence
=>
2436 Make_Handled_Sequence_Of_Statements
(Loc
,
2437 Statements
=> Op_Stats
,
2438 End_Label
=> End_Lab
,
2439 Exception_Handlers
=> New_List
(
2440 Make_Implicit_Exception_Handler
(Han_Loc
,
2441 Exception_Choices
=> New_List
(Ohandle
),
2443 Statements
=> New_List
(
2444 Make_Procedure_Call_Statement
(Han_Loc
,
2446 Parameter_Associations
=> New_List
(
2447 Make_Attribute_Reference
(Han_Loc
,
2449 Make_Selected_Component
(Han_Loc
,
2451 Make_Identifier
(Han_Loc
, Name_uObject
),
2453 Make_Identifier
(Han_Loc
, Name_uObject
)),
2454 Attribute_Name
=> Name_Unchecked_Access
),
2456 Make_Function_Call
(Han_Loc
,
2457 Name
=> New_Reference_To
(
2458 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
2460 end Build_Protected_Entry
;
2462 -----------------------------------------
2463 -- Build_Protected_Entry_Specification --
2464 -----------------------------------------
2466 function Build_Protected_Entry_Specification
2469 Ent_Id
: Entity_Id
) return Node_Id
2471 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
2474 Set_Debug_Info_Needed
(Def_Id
);
2476 if Present
(Ent_Id
) then
2477 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
2481 Make_Procedure_Specification
(Loc
,
2482 Defining_Unit_Name
=> Def_Id
,
2483 Parameter_Specifications
=> New_List
(
2484 Make_Parameter_Specification
(Loc
,
2485 Defining_Identifier
=>
2486 Make_Defining_Identifier
(Loc
, Name_uO
),
2488 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2490 Make_Parameter_Specification
(Loc
,
2491 Defining_Identifier
=> P
,
2493 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2495 Make_Parameter_Specification
(Loc
,
2496 Defining_Identifier
=>
2497 Make_Defining_Identifier
(Loc
, Name_uE
),
2499 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
2500 end Build_Protected_Entry_Specification
;
2502 --------------------------
2503 -- Build_Protected_Spec --
2504 --------------------------
2506 function Build_Protected_Spec
2508 Obj_Type
: Entity_Id
;
2510 Unprotected
: Boolean := False) return List_Id
2512 Loc
: constant Source_Ptr
:= Sloc
(N
);
2515 New_Plist
: List_Id
;
2516 New_Param
: Node_Id
;
2519 New_Plist
:= New_List
;
2521 Formal
:= First_Formal
(Ident
);
2522 while Present
(Formal
) loop
2524 Make_Parameter_Specification
(Loc
,
2525 Defining_Identifier
=>
2526 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
2527 In_Present
=> In_Present
(Parent
(Formal
)),
2528 Out_Present
=> Out_Present
(Parent
(Formal
)),
2529 Parameter_Type
=> New_Reference_To
(Etype
(Formal
), Loc
));
2532 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
2535 Append
(New_Param
, New_Plist
);
2536 Next_Formal
(Formal
);
2539 -- If the subprogram is a procedure and the context is not an access
2540 -- to protected subprogram, the parameter is in-out. Otherwise it is
2544 Make_Parameter_Specification
(Loc
,
2545 Defining_Identifier
=>
2546 Make_Defining_Identifier
(Loc
, Name_uObject
),
2549 (Etype
(Ident
) = Standard_Void_Type
2550 and then not Is_RTE
(Obj_Type
, RE_Address
)),
2552 New_Reference_To
(Obj_Type
, Loc
));
2553 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
2554 Prepend_To
(New_Plist
, Decl
);
2557 end Build_Protected_Spec
;
2559 ---------------------------------------
2560 -- Build_Protected_Sub_Specification --
2561 ---------------------------------------
2563 function Build_Protected_Sub_Specification
2565 Prot_Typ
: Entity_Id
;
2566 Mode
: Subprogram_Protection_Mode
) return Node_Id
2568 Loc
: constant Source_Ptr
:= Sloc
(N
);
2572 New_Plist
: List_Id
;
2575 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
2576 (Dispatching_Mode
=> ' ',
2577 Protected_Mode
=> 'P',
2578 Unprotected_Mode
=> 'N');
2581 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
2584 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
2589 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
2592 Build_Protected_Spec
2593 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
2594 Mode
= Unprotected_Mode
);
2596 Make_Defining_Identifier
(Loc
,
2597 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
2599 -- The unprotected operation carries the user code, and debugging
2600 -- information must be generated for it, even though this spec does
2601 -- not come from source. It is also convenient to allow gdb to step
2602 -- into the protected operation, even though it only contains lock/
2605 Set_Debug_Info_Needed
(New_Id
);
2607 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
2609 Make_Procedure_Specification
(Loc
,
2610 Defining_Unit_Name
=> New_Id
,
2611 Parameter_Specifications
=> New_Plist
);
2613 -- Create a new specification for the anonymous subprogram type
2617 Make_Function_Specification
(Loc
,
2618 Defining_Unit_Name
=> New_Id
,
2619 Parameter_Specifications
=> New_Plist
,
2620 Result_Definition
=>
2621 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
2623 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
2627 end Build_Protected_Sub_Specification
;
2629 -------------------------------------
2630 -- Build_Protected_Subprogram_Body --
2631 -------------------------------------
2633 function Build_Protected_Subprogram_Body
2636 N_Op_Spec
: Node_Id
) return Node_Id
2638 Loc
: constant Source_Ptr
:= Sloc
(N
);
2640 P_Op_Spec
: Node_Id
;
2643 Unprot_Call
: Node_Id
;
2645 Lock_Name
: Node_Id
;
2646 Lock_Stmt
: Node_Id
;
2647 Service_Name
: Node_Id
;
2649 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
2650 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
2652 Object_Parm
: Node_Id
;
2655 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
2656 -- Tell whether a given subprogram cannot raise an exception
2658 -----------------------
2659 -- Is_Exception_Safe --
2660 -----------------------
2662 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
2664 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
2665 -- Return True whenever encountering a subprogram call or raise
2666 -- statement of any kind in the sequence of statements
2668 ---------------------
2669 -- Has_Side_Effect --
2670 ---------------------
2672 -- What is this doing buried two levels down in exp_ch9. It seems
2673 -- like a generally useful function, and indeed there may be code
2674 -- duplication going on here ???
2676 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
2680 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
2681 -- Indicate whether N is a subprogram call or a raise statement
2683 ----------------------
2684 -- Is_Call_Or_Raise --
2685 ----------------------
2687 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
2689 return Nkind_In
(N
, N_Procedure_Call_Statement
,
2692 N_Raise_Constraint_Error
,
2693 N_Raise_Program_Error
,
2694 N_Raise_Storage_Error
);
2695 end Is_Call_Or_Raise
;
2697 -- Start of processing for Has_Side_Effect
2701 while Present
(Stmt
) loop
2702 if Is_Call_Or_Raise
(Stmt
) then
2706 -- An object declaration can also contain a function call
2707 -- or a raise statement
2709 if Nkind
(Stmt
) = N_Object_Declaration
then
2710 Expr
:= Expression
(Stmt
);
2712 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
2721 end Has_Side_Effect
;
2723 -- Start of processing for Is_Exception_Safe
2726 -- If the checks handled by the back end are not disabled, we cannot
2727 -- ensure that no exception will be raised.
2729 if not Access_Checks_Suppressed
(Empty
)
2730 or else not Discriminant_Checks_Suppressed
(Empty
)
2731 or else not Range_Checks_Suppressed
(Empty
)
2732 or else not Index_Checks_Suppressed
(Empty
)
2733 or else Opt
.Stack_Checking_Enabled
2738 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
2741 First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
2747 end Is_Exception_Safe
;
2749 -- Start of processing for Build_Protected_Subprogram_Body
2752 Op_Spec
:= Specification
(N
);
2753 Exc_Safe
:= Is_Exception_Safe
(N
);
2756 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
2758 -- Build a list of the formal parameters of the protected version of
2759 -- the subprogram to use as the actual parameters of the unprotected
2762 Uactuals
:= New_List
;
2763 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
2764 while Present
(Pformal
) loop
2766 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))),
2771 -- Make a call to the unprotected version of the subprogram built above
2772 -- for use by the protected version built below.
2774 if Nkind
(Op_Spec
) = N_Function_Specification
then
2776 R
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
2778 Make_Object_Declaration
(Loc
,
2779 Defining_Identifier
=> R
,
2780 Constant_Present
=> True,
2781 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
2783 Make_Function_Call
(Loc
,
2784 Name
=> Make_Identifier
(Loc
,
2785 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
2786 Parameter_Associations
=> Uactuals
));
2787 Return_Stmt
:= Make_Simple_Return_Statement
(Loc
,
2788 Expression
=> New_Reference_To
(R
, Loc
));
2791 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
2792 Expression
=> Make_Function_Call
(Loc
,
2794 Make_Identifier
(Loc
,
2795 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
2796 Parameter_Associations
=> Uactuals
));
2801 Make_Procedure_Call_Statement
(Loc
,
2803 Make_Identifier
(Loc
,
2804 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
2805 Parameter_Associations
=> Uactuals
);
2808 -- Wrap call in block that will be covered by an at_end handler
2810 if not Exc_Safe
then
2811 Unprot_Call
:= Make_Block_Statement
(Loc
,
2812 Handled_Statement_Sequence
=>
2813 Make_Handled_Sequence_Of_Statements
(Loc
,
2814 Statements
=> New_List
(Unprot_Call
)));
2817 -- Make the protected subprogram body. This locks the protected
2818 -- object and calls the unprotected version of the subprogram.
2820 case Corresponding_Runtime_Package
(Pid
) is
2821 when System_Tasking_Protected_Objects_Entries
=>
2822 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
2823 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
2825 when System_Tasking_Protected_Objects_Single_Entry
=>
2826 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
2827 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
2829 when System_Tasking_Protected_Objects
=>
2830 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock
), Loc
);
2831 Service_Name
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
2834 raise Program_Error
;
2838 Make_Attribute_Reference
(Loc
,
2840 Make_Selected_Component
(Loc
,
2842 Make_Identifier
(Loc
, Name_uObject
),
2844 Make_Identifier
(Loc
, Name_uObject
)),
2845 Attribute_Name
=> Name_Unchecked_Access
);
2847 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
2849 Parameter_Associations
=> New_List
(Object_Parm
));
2851 if Abort_Allowed
then
2853 Make_Procedure_Call_Statement
(Loc
,
2854 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
2855 Parameter_Associations
=> Empty_List
),
2859 Stmts
:= New_List
(Lock_Stmt
);
2862 if not Exc_Safe
then
2863 Append
(Unprot_Call
, Stmts
);
2865 if Nkind
(Op_Spec
) = N_Function_Specification
then
2867 Stmts
:= Empty_List
;
2869 Append
(Unprot_Call
, Stmts
);
2873 Make_Procedure_Call_Statement
(Loc
,
2874 Name
=> Service_Name
,
2875 Parameter_Associations
=>
2876 New_List
(New_Copy_Tree
(Object_Parm
))),
2879 if Abort_Allowed
then
2881 Make_Procedure_Call_Statement
(Loc
,
2882 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
2883 Parameter_Associations
=> Empty_List
),
2887 if Nkind
(Op_Spec
) = N_Function_Specification
then
2888 Append
(Return_Stmt
, Stmts
);
2889 Append
(Make_Block_Statement
(Loc
,
2890 Declarations
=> New_List
(Unprot_Call
),
2891 Handled_Statement_Sequence
=>
2892 Make_Handled_Sequence_Of_Statements
(Loc
,
2893 Statements
=> Stmts
)), Pre_Stmts
);
2899 Make_Subprogram_Body
(Loc
,
2900 Declarations
=> Empty_List
,
2901 Specification
=> P_Op_Spec
,
2902 Handled_Statement_Sequence
=>
2903 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
2905 if not Exc_Safe
then
2906 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
2910 end Build_Protected_Subprogram_Body
;
2912 -------------------------------------
2913 -- Build_Protected_Subprogram_Call --
2914 -------------------------------------
2916 procedure Build_Protected_Subprogram_Call
2920 External
: Boolean := True)
2922 Loc
: constant Source_Ptr
:= Sloc
(N
);
2923 Sub
: constant Entity_Id
:= Entity
(Name
);
2929 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
2932 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
2935 if Present
(Parameter_Associations
(N
)) then
2936 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
2941 Prepend
(Rec
, Params
);
2943 if Ekind
(Sub
) = E_Procedure
then
2945 Make_Procedure_Call_Statement
(Loc
,
2947 Parameter_Associations
=> Params
));
2950 pragma Assert
(Ekind
(Sub
) = E_Function
);
2952 Make_Function_Call
(Loc
,
2954 Parameter_Associations
=> Params
));
2958 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
2959 and then Is_Entity_Name
(Expression
(Rec
))
2960 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
2962 Add_Shared_Var_Lock_Procs
(N
);
2964 end Build_Protected_Subprogram_Call
;
2966 -------------------------
2967 -- Build_Selected_Name --
2968 -------------------------
2970 function Build_Selected_Name
2971 (Prefix
: Entity_Id
;
2972 Selector
: Entity_Id
;
2973 Append_Char
: Character := ' ') return Name_Id
2975 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
2976 Select_Len
: Natural;
2979 Get_Name_String
(Chars
(Selector
));
2980 Select_Len
:= Name_Len
;
2981 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
2982 Get_Name_String
(Chars
(Prefix
));
2984 -- If scope is anonymous type, discard suffix to recover name of
2985 -- single protected object. Otherwise use protected type name.
2987 if Name_Buffer
(Name_Len
) = 'T' then
2988 Name_Len
:= Name_Len
- 1;
2991 Name_Buffer
(Name_Len
+ 1) := '_';
2992 Name_Buffer
(Name_Len
+ 2) := '_';
2994 Name_Len
:= Name_Len
+ 2;
2995 for J
in 1 .. Select_Len
loop
2996 Name_Len
:= Name_Len
+ 1;
2997 Name_Buffer
(Name_Len
) := Select_Buffer
(J
);
3000 -- Now add the Append_Char if specified. The encoding to follow
3001 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3002 -- then the entity is associated to a protected type subprogram.
3003 -- Otherwise, it is a protected type entry. For each case, the
3004 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3006 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3008 if Append_Char
/= ' ' then
3009 if Append_Char
= 'P' or Append_Char
= 'N' then
3010 Name_Len
:= Name_Len
+ 1;
3011 Name_Buffer
(Name_Len
) := Append_Char
;
3014 Name_Buffer
(Name_Len
+ 1) := '_';
3015 Name_Buffer
(Name_Len
+ 2) := Append_Char
;
3016 Name_Len
:= Name_Len
+ 2;
3017 return New_External_Name
(Name_Find
, ' ', -1);
3022 end Build_Selected_Name
;
3024 -----------------------------
3025 -- Build_Simple_Entry_Call --
3026 -----------------------------
3028 -- A task entry call is converted to a call to Call_Simple
3031 -- P : parms := (parm, parm, parm);
3033 -- Call_Simple (acceptor-task, entry-index, P'Address);
3039 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3040 -- the parameters, and the constructed aggregate value contains either the
3041 -- parameters or, in the case of non-elementary types, references to these
3042 -- parameters. Then the address of this aggregate is passed to the runtime
3043 -- routine, along with the task id value and the task entry index value.
3044 -- Pnn is only required if parameters are present.
3046 -- The assignments after the call are present only in the case of in-out
3047 -- or out parameters for elementary types, and are used to assign back the
3048 -- resulting values of such parameters.
3050 -- Note: the reason that we insert a block here is that in the context
3051 -- of selects, conditional entry calls etc. the entry call statement
3052 -- appears on its own, not as an element of a list.
3054 -- A protected entry call is converted to a Protected_Entry_Call:
3057 -- P : E1_Params := (param, param, param);
3059 -- Bnn : Communications_Block;
3062 -- P : E1_Params := (param, param, param);
3063 -- Bnn : Communications_Block;
3066 -- Protected_Entry_Call (
3067 -- Object => po._object'Access,
3068 -- E => <entry index>;
3069 -- Uninterpreted_Data => P'Address;
3070 -- Mode => Simple_Call;
3077 procedure Build_Simple_Entry_Call
3086 -- If call has been inlined, nothing left to do
3088 if Nkind
(N
) = N_Block_Statement
then
3092 -- Convert entry call to Call_Simple call
3095 Loc
: constant Source_Ptr
:= Sloc
(N
);
3096 Parms
: constant List_Id
:= Parameter_Associations
(N
);
3097 Stats
: constant List_Id
:= New_List
;
3100 Comm_Name
: Entity_Id
;
3104 Ent_Acc
: Entity_Id
;
3106 Iface_Tag
: Entity_Id
;
3107 Iface_Typ
: Entity_Id
;
3120 -- Simple entry and entry family cases merge here
3122 Ent
:= Entity
(Ename
);
3123 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
3124 Conctyp
:= Etype
(Concval
);
3126 -- If prefix is an access type, dereference to obtain the task type
3128 if Is_Access_Type
(Conctyp
) then
3129 Conctyp
:= Designated_Type
(Conctyp
);
3132 -- Special case for protected subprogram calls
3134 if Is_Protected_Type
(Conctyp
)
3135 and then Is_Subprogram
(Entity
(Ename
))
3137 if not Is_Eliminated
(Entity
(Ename
)) then
3138 Build_Protected_Subprogram_Call
3139 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
3146 -- First parameter is the Task_Id value from the task value or the
3147 -- Object from the protected object value, obtained by selecting
3148 -- the _Task_Id or _Object from the result of doing an unchecked
3149 -- conversion to convert the value to the corresponding record type.
3151 if Nkind
(Concval
) = N_Function_Call
3152 and then Is_Task_Type
(Conctyp
)
3153 and then Ada_Version
>= Ada_05
3156 Obj
: constant Entity_Id
:=
3157 Make_Defining_Identifier
(Loc
, New_Internal_Name
('F'));
3162 Make_Object_Declaration
(Loc
,
3163 Defining_Identifier
=> Obj
,
3164 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
3165 Expression
=> Relocate_Node
(Concval
));
3166 Set_Etype
(Obj
, Conctyp
);
3167 Decls
:= New_List
(Decl
);
3168 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
3175 Parm1
:= Concurrent_Ref
(Concval
);
3177 -- Second parameter is the entry index, computed by the routine
3178 -- provided for this purpose. The value of this expression is
3179 -- assigned to an intermediate variable to assure that any entry
3180 -- family index expressions are evaluated before the entry
3184 or else Restriction_Active
(No_Entry_Queue
) = False
3185 or else not Is_Protected_Type
(Conctyp
)
3186 or else Number_Entries
(Conctyp
) > 1
3187 or else (Has_Attach_Handler
(Conctyp
)
3188 and then not Restricted_Profile
)
3190 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
3193 Make_Object_Declaration
(Loc
,
3194 Defining_Identifier
=> X
,
3195 Object_Definition
=>
3196 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3197 Expression
=> Actual_Index_Expression
(
3198 Loc
, Entity
(Ename
), Index
, Concval
));
3200 Append_To
(Decls
, Xdecl
);
3201 Parm2
:= New_Reference_To
(X
, Loc
);
3208 -- The third parameter is the packaged parameters. If there are
3209 -- none, then it is just the null address, since nothing is passed.
3212 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
3215 -- Case of parameters present, where third argument is the address
3216 -- of a packaged record containing the required parameter values.
3219 -- First build a list of parameter values, which are references to
3220 -- objects of the parameter types.
3224 Actual
:= First_Actual
(N
);
3225 Formal
:= First_Formal
(Ent
);
3227 while Present
(Actual
) loop
3229 -- If it is a by_copy_type, copy it to a new variable. The
3230 -- packaged record has a field that points to this variable.
3232 if Is_By_Copy_Type
(Etype
(Actual
)) then
3234 Make_Object_Declaration
(Loc
,
3235 Defining_Identifier
=>
3236 Make_Defining_Identifier
(Loc
,
3237 Chars
=> New_Internal_Name
('J')),
3238 Aliased_Present
=> True,
3239 Object_Definition
=>
3240 New_Reference_To
(Etype
(Formal
), Loc
));
3242 -- Mark the object as not needing initialization since the
3243 -- initialization is performed separately, avoiding errors
3244 -- on cases such as formals of null-excluding access types.
3246 Set_No_Initialization
(N_Node
);
3248 -- We must make an assignment statement separate for the
3249 -- case of limited type. We cannot assign it unless the
3250 -- Assignment_OK flag is set first. An out formal of an
3251 -- access type must also be initialized from the actual,
3252 -- as stated in RM 6.4.1 (13).
3254 if Ekind
(Formal
) /= E_Out_Parameter
3255 or else Is_Access_Type
(Etype
(Formal
))
3258 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
3259 Set_Assignment_OK
(N_Var
);
3261 Make_Assignment_Statement
(Loc
,
3263 Expression
=> Relocate_Node
(Actual
)));
3266 Append
(N_Node
, Decls
);
3269 Make_Attribute_Reference
(Loc
,
3270 Attribute_Name
=> Name_Unchecked_Access
,
3272 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
3274 -- Interface class-wide formal
3276 if Ada_Version
>= Ada_05
3277 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
3278 and then Is_Interface
(Etype
(Formal
))
3280 Iface_Typ
:= Etype
(Etype
(Formal
));
3283 -- formal_iface_type! (actual.iface_tag)'reference
3286 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
3287 pragma Assert
(Present
(Iface_Tag
));
3290 Make_Reference
(Loc
,
3291 Unchecked_Convert_To
(Iface_Typ
,
3292 Make_Selected_Component
(Loc
,
3294 Relocate_Node
(Actual
),
3296 New_Reference_To
(Iface_Tag
, Loc
)))));
3302 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
3306 Next_Actual
(Actual
);
3307 Next_Formal_With_Extras
(Formal
);
3310 -- Now build the declaration of parameters initialized with the
3311 -- aggregate containing this constructed parameter list.
3313 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3316 Make_Object_Declaration
(Loc
,
3317 Defining_Identifier
=> P
,
3318 Object_Definition
=>
3319 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
3321 Make_Aggregate
(Loc
, Expressions
=> Plist
));
3324 Make_Attribute_Reference
(Loc
,
3325 Prefix
=> New_Reference_To
(P
, Loc
),
3326 Attribute_Name
=> Name_Address
);
3328 Append
(Pdecl
, Decls
);
3331 -- Now we can create the call, case of protected type
3333 if Is_Protected_Type
(Conctyp
) then
3334 case Corresponding_Runtime_Package
(Conctyp
) is
3335 when System_Tasking_Protected_Objects_Entries
=>
3337 -- Change the type of the index declaration
3339 Set_Object_Definition
(Xdecl
,
3340 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
3342 -- Some additional declarations for protected entry calls
3348 -- Bnn : Communications_Block;
3351 Make_Defining_Identifier
(Loc
, New_Internal_Name
('B'));
3354 Make_Object_Declaration
(Loc
,
3355 Defining_Identifier
=> Comm_Name
,
3356 Object_Definition
=>
3357 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
3359 -- Some additional statements for protected entry calls
3361 -- Protected_Entry_Call (
3362 -- Object => po._object'Access,
3363 -- E => <entry index>;
3364 -- Uninterpreted_Data => P'Address;
3365 -- Mode => Simple_Call;
3369 Make_Procedure_Call_Statement
(Loc
,
3371 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
3373 Parameter_Associations
=> New_List
(
3374 Make_Attribute_Reference
(Loc
,
3375 Attribute_Name
=> Name_Unchecked_Access
,
3379 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
3380 New_Occurrence_Of
(Comm_Name
, Loc
)));
3382 when System_Tasking_Protected_Objects_Single_Entry
=>
3383 -- Protected_Single_Entry_Call (
3384 -- Object => po._object'Access,
3385 -- Uninterpreted_Data => P'Address;
3386 -- Mode => Simple_Call);
3389 Make_Procedure_Call_Statement
(Loc
,
3390 Name
=> New_Reference_To
(
3391 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
3393 Parameter_Associations
=> New_List
(
3394 Make_Attribute_Reference
(Loc
,
3395 Attribute_Name
=> Name_Unchecked_Access
,
3398 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
3401 raise Program_Error
;
3404 -- Case of task type
3408 Make_Procedure_Call_Statement
(Loc
,
3409 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
3410 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
3414 Append_To
(Stats
, Call
);
3416 -- If there are out or in/out parameters by copy add assignment
3417 -- statements for the result values.
3419 if Present
(Parms
) then
3420 Actual
:= First_Actual
(N
);
3421 Formal
:= First_Formal
(Ent
);
3423 Set_Assignment_OK
(Actual
);
3424 while Present
(Actual
) loop
3425 if Is_By_Copy_Type
(Etype
(Actual
))
3426 and then Ekind
(Formal
) /= E_In_Parameter
3429 Make_Assignment_Statement
(Loc
,
3430 Name
=> New_Copy
(Actual
),
3432 Make_Explicit_Dereference
(Loc
,
3433 Make_Selected_Component
(Loc
,
3434 Prefix
=> New_Reference_To
(P
, Loc
),
3436 Make_Identifier
(Loc
, Chars
(Formal
)))));
3438 -- In all cases (including limited private types) we want
3439 -- the assignment to be valid.
3441 Set_Assignment_OK
(Name
(N_Node
));
3443 -- If the call is the triggering alternative in an
3444 -- asynchronous select, or the entry_call alternative of a
3445 -- conditional entry call, the assignments for in-out
3446 -- parameters are incorporated into the statement list that
3447 -- follows, so that there are executed only if the entry
3450 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
3451 and then N
= Triggering_Statement
(Parent
(N
)))
3453 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
3454 and then N
= Entry_Call_Statement
(Parent
(N
)))
3456 if No
(Statements
(Parent
(N
))) then
3457 Set_Statements
(Parent
(N
), New_List
);
3460 Prepend
(N_Node
, Statements
(Parent
(N
)));
3463 Insert_After
(Call
, N_Node
);
3467 Next_Actual
(Actual
);
3468 Next_Formal_With_Extras
(Formal
);
3472 -- Finally, create block and analyze it
3475 Make_Block_Statement
(Loc
,
3476 Declarations
=> Decls
,
3477 Handled_Statement_Sequence
=>
3478 Make_Handled_Sequence_Of_Statements
(Loc
,
3479 Statements
=> Stats
)));
3483 end Build_Simple_Entry_Call
;
3485 --------------------------------
3486 -- Build_Task_Activation_Call --
3487 --------------------------------
3489 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
3490 Loc
: constant Source_Ptr
:= Sloc
(N
);
3497 -- Get the activation chain entity. Except in the case of a package
3498 -- body, this is in the node that was passed. For a package body, we
3499 -- have to find the corresponding package declaration node.
3501 if Nkind
(N
) = N_Package_Body
then
3502 P
:= Corresponding_Spec
(N
);
3505 exit when Nkind
(P
) = N_Package_Declaration
;
3508 Chain
:= Activation_Chain_Entity
(P
);
3511 Chain
:= Activation_Chain_Entity
(N
);
3514 if Present
(Chain
) then
3515 if Restricted_Profile
then
3516 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
3518 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
3522 Make_Procedure_Call_Statement
(Loc
,
3524 Parameter_Associations
=>
3525 New_List
(Make_Attribute_Reference
(Loc
,
3526 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
3527 Attribute_Name
=> Name_Unchecked_Access
)));
3529 if Nkind
(N
) = N_Package_Declaration
then
3530 if Present
(Corresponding_Body
(N
)) then
3533 elsif Present
(Private_Declarations
(Specification
(N
))) then
3534 Append
(Call
, Private_Declarations
(Specification
(N
)));
3537 Append
(Call
, Visible_Declarations
(Specification
(N
)));
3541 if Present
(Handled_Statement_Sequence
(N
)) then
3543 -- The call goes at the start of the statement sequence
3544 -- after the start of exception range label if one is present.
3550 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
3552 -- A special case, skip exception range label if one is
3553 -- present (from front end zcx processing).
3555 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
3559 -- Another special case, if the first statement is a block
3560 -- from optimization of a local raise to a goto, then the
3561 -- call goes inside this block.
3563 if Nkind
(Stm
) = N_Block_Statement
3564 and then Exception_Junk
(Stm
)
3567 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
3570 -- Insertion point is after any exception label pushes,
3571 -- since we want it covered by any local handlers.
3573 while Nkind
(Stm
) in N_Push_xxx_Label
loop
3577 -- Now we have the proper insertion point
3579 Insert_Before
(Stm
, Call
);
3583 Set_Handled_Statement_Sequence
(N
,
3584 Make_Handled_Sequence_Of_Statements
(Loc
,
3585 Statements
=> New_List
(Call
)));
3590 Check_Task_Activation
(N
);
3592 end Build_Task_Activation_Call
;
3594 -------------------------------
3595 -- Build_Task_Allocate_Block --
3596 -------------------------------
3598 procedure Build_Task_Allocate_Block
3603 T
: constant Entity_Id
:= Entity
(Expression
(N
));
3604 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
3605 Loc
: constant Source_Ptr
:= Sloc
(N
);
3606 Chain
: constant Entity_Id
:=
3607 Make_Defining_Identifier
(Loc
, Name_uChain
);
3613 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3616 Make_Block_Statement
(Loc
,
3617 Identifier
=> New_Reference_To
(Blkent
, Loc
),
3618 Declarations
=> New_List
(
3620 -- _Chain : Activation_Chain;
3622 Make_Object_Declaration
(Loc
,
3623 Defining_Identifier
=> Chain
,
3624 Aliased_Present
=> True,
3625 Object_Definition
=>
3626 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
3628 Handled_Statement_Sequence
=>
3629 Make_Handled_Sequence_Of_Statements
(Loc
,
3631 Statements
=> New_List
(
3635 Make_Procedure_Call_Statement
(Loc
,
3636 Name
=> New_Reference_To
(Init
, Loc
),
3637 Parameter_Associations
=> Args
),
3639 -- Activate_Tasks (_Chain);
3641 Make_Procedure_Call_Statement
(Loc
,
3642 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
3643 Parameter_Associations
=> New_List
(
3644 Make_Attribute_Reference
(Loc
,
3645 Prefix
=> New_Reference_To
(Chain
, Loc
),
3646 Attribute_Name
=> Name_Unchecked_Access
))))),
3648 Has_Created_Identifier
=> True,
3649 Is_Task_Allocation_Block
=> True);
3652 Make_Implicit_Label_Declaration
(Loc
,
3653 Defining_Identifier
=> Blkent
,
3654 Label_Construct
=> Block
));
3656 Append_To
(Actions
, Block
);
3658 Set_Activation_Chain_Entity
(Block
, Chain
);
3659 end Build_Task_Allocate_Block
;
3661 -----------------------------------------------
3662 -- Build_Task_Allocate_Block_With_Init_Stmts --
3663 -----------------------------------------------
3665 procedure Build_Task_Allocate_Block_With_Init_Stmts
3668 Init_Stmts
: List_Id
)
3670 Loc
: constant Source_Ptr
:= Sloc
(N
);
3671 Chain
: constant Entity_Id
:=
3672 Make_Defining_Identifier
(Loc
, Name_uChain
);
3677 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3679 Append_To
(Init_Stmts
,
3680 Make_Procedure_Call_Statement
(Loc
,
3681 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
3682 Parameter_Associations
=> New_List
(
3683 Make_Attribute_Reference
(Loc
,
3684 Prefix
=> New_Reference_To
(Chain
, Loc
),
3685 Attribute_Name
=> Name_Unchecked_Access
))));
3688 Make_Block_Statement
(Loc
,
3689 Identifier
=> New_Reference_To
(Blkent
, Loc
),
3690 Declarations
=> New_List
(
3692 -- _Chain : Activation_Chain;
3694 Make_Object_Declaration
(Loc
,
3695 Defining_Identifier
=> Chain
,
3696 Aliased_Present
=> True,
3697 Object_Definition
=>
3698 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
3700 Handled_Statement_Sequence
=>
3701 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
3703 Has_Created_Identifier
=> True,
3704 Is_Task_Allocation_Block
=> True);
3707 Make_Implicit_Label_Declaration
(Loc
,
3708 Defining_Identifier
=> Blkent
,
3709 Label_Construct
=> Block
));
3711 Append_To
(Actions
, Block
);
3713 Set_Activation_Chain_Entity
(Block
, Chain
);
3714 end Build_Task_Allocate_Block_With_Init_Stmts
;
3716 -----------------------------------
3717 -- Build_Task_Proc_Specification --
3718 -----------------------------------
3720 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
3721 Loc
: constant Source_Ptr
:= Sloc
(T
);
3722 Spec_Id
: Entity_Id
;
3726 Make_Defining_Identifier
(Loc
,
3727 Chars
=> New_External_Name
(Chars
(T
), 'B'));
3728 Set_Is_Internal
(Spec_Id
);
3730 -- Associate the procedure with the task, if this is the declaration
3731 -- (and not the body) of the procedure.
3733 if No
(Task_Body_Procedure
(T
)) then
3734 Set_Task_Body_Procedure
(T
, Spec_Id
);
3738 Make_Procedure_Specification
(Loc
,
3739 Defining_Unit_Name
=> Spec_Id
,
3740 Parameter_Specifications
=> New_List
(
3741 Make_Parameter_Specification
(Loc
,
3742 Defining_Identifier
=>
3743 Make_Defining_Identifier
(Loc
, Name_uTask
),
3745 Make_Access_Definition
(Loc
,
3747 New_Reference_To
(Corresponding_Record_Type
(T
), Loc
)))));
3748 end Build_Task_Proc_Specification
;
3750 ---------------------------------------
3751 -- Build_Unprotected_Subprogram_Body --
3752 ---------------------------------------
3754 function Build_Unprotected_Subprogram_Body
3756 Pid
: Node_Id
) return Node_Id
3758 Decls
: constant List_Id
:= Declarations
(N
);
3761 -- Add renamings for the Protection object, discriminals, privals and
3762 -- the entry index constant for use by debugger.
3764 Debug_Private_Data_Declarations
(Decls
);
3766 -- Make an unprotected version of the subprogram for use within the same
3767 -- object, with a new name and an additional parameter representing the
3771 Make_Subprogram_Body
(Sloc
(N
),
3773 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
3774 Declarations
=> Decls
,
3775 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
3776 end Build_Unprotected_Subprogram_Body
;
3778 ----------------------------
3779 -- Collect_Entry_Families --
3780 ----------------------------
3782 procedure Collect_Entry_Families
3785 Current_Node
: in out Node_Id
;
3786 Conctyp
: Entity_Id
)
3789 Efam_Decl
: Node_Id
;
3790 Efam_Type
: Entity_Id
;
3793 Efam
:= First_Entity
(Conctyp
);
3794 while Present
(Efam
) loop
3795 if Ekind
(Efam
) = E_Entry_Family
then
3797 Make_Defining_Identifier
(Loc
,
3798 Chars
=> New_Internal_Name
('F'));
3803 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
3805 Bas_Decl
: Node_Id
:= Empty
;
3810 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
3812 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
3814 Make_Defining_Identifier
(Loc
,
3815 Chars
=> New_Internal_Name
('B'));
3818 Make_Subtype_Declaration
(Loc
,
3819 Defining_Identifier
=> Bas
,
3820 Subtype_Indication
=>
3821 Make_Subtype_Indication
(Loc
,
3823 New_Occurrence_Of
(Standard_Integer
, Loc
),
3825 Make_Range_Constraint
(Loc
,
3826 Range_Expression
=> Make_Range
(Loc
,
3827 Make_Integer_Literal
3828 (Loc
, -Entry_Family_Bound
),
3829 Make_Integer_Literal
3830 (Loc
, Entry_Family_Bound
- 1)))));
3832 Insert_After
(Current_Node
, Bas_Decl
);
3833 Current_Node
:= Bas_Decl
;
3838 Make_Full_Type_Declaration
(Loc
,
3839 Defining_Identifier
=> Efam_Type
,
3841 Make_Unconstrained_Array_Definition
(Loc
,
3843 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
3845 Component_Definition
=>
3846 Make_Component_Definition
(Loc
,
3847 Aliased_Present
=> False,
3848 Subtype_Indication
=>
3849 New_Reference_To
(Standard_Character
, Loc
))));
3852 Insert_After
(Current_Node
, Efam_Decl
);
3853 Current_Node
:= Efam_Decl
;
3854 Analyze
(Efam_Decl
);
3857 Make_Component_Declaration
(Loc
,
3858 Defining_Identifier
=>
3859 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
3861 Component_Definition
=>
3862 Make_Component_Definition
(Loc
,
3863 Aliased_Present
=> False,
3864 Subtype_Indication
=>
3865 Make_Subtype_Indication
(Loc
,
3867 New_Occurrence_Of
(Efam_Type
, Loc
),
3870 Make_Index_Or_Discriminant_Constraint
(Loc
,
3871 Constraints
=> New_List
(
3873 (Etype
(Discrete_Subtype_Definition
3874 (Parent
(Efam
))), Loc
)))))));
3880 end Collect_Entry_Families
;
3882 -----------------------
3883 -- Concurrent_Object --
3884 -----------------------
3886 function Concurrent_Object
3887 (Spec_Id
: Entity_Id
;
3888 Conc_Typ
: Entity_Id
) return Entity_Id
3891 -- Parameter _O or _object
3893 if Is_Protected_Type
(Conc_Typ
) then
3894 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
3899 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3900 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
3902 end Concurrent_Object
;
3904 ----------------------
3905 -- Copy_Result_Type --
3906 ----------------------
3908 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
3909 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
3914 -- If the result type is an access_to_subprogram, we must create
3915 -- new entities for its spec.
3917 if Nkind
(New_Res
) = N_Access_Definition
3918 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
3920 -- Provide new entities for the formals
3922 Par_Spec
:= First
(Parameter_Specifications
3923 (Access_To_Subprogram_Definition
(New_Res
)));
3924 while Present
(Par_Spec
) loop
3925 Formal
:= Defining_Identifier
(Par_Spec
);
3926 Set_Defining_Identifier
(Par_Spec
,
3927 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
3933 end Copy_Result_Type
;
3935 --------------------
3936 -- Concurrent_Ref --
3937 --------------------
3939 -- The expression returned for a reference to a concurrent object has the
3942 -- taskV!(name)._Task_Id
3946 -- objectV!(name)._Object
3948 -- for a protected object. For the case of an access to a concurrent
3949 -- object, there is an extra explicit dereference:
3951 -- taskV!(name.all)._Task_Id
3952 -- objectV!(name.all)._Object
3954 -- here taskV and objectV are the types for the associated records, which
3955 -- contain the required _Task_Id and _Object fields for tasks and protected
3956 -- objects, respectively.
3958 -- For the case of a task type name, the expression is
3962 -- i.e. a call to the Self function which returns precisely this Task_Id
3964 -- For the case of a protected type name, the expression is
3968 -- which is a renaming of the _object field of the current object object
3969 -- record, passed into protected operations as a parameter.
3971 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
3972 Loc
: constant Source_Ptr
:= Sloc
(N
);
3973 Ntyp
: constant Entity_Id
:= Etype
(N
);
3977 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
3978 -- Check whether the reference is to the immediately enclosing task
3979 -- type, or to an outer one (rare but legal).
3981 ---------------------
3982 -- Is_Current_Task --
3983 ---------------------
3985 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
3989 Scop
:= Current_Scope
;
3990 while Present
(Scop
)
3991 and then Scop
/= Standard_Standard
3997 elsif Is_Task_Type
(Scop
) then
4000 -- If this is a procedure nested within the task type, we must
4001 -- assume that it can be called from an inner task, and therefore
4002 -- cannot treat it as a local reference.
4004 elsif Is_Overloadable
(Scop
)
4005 and then In_Open_Scopes
(T
)
4010 Scop
:= Scope
(Scop
);
4014 -- We know that we are within the task body, so should have found it
4017 raise Program_Error
;
4018 end Is_Current_Task
;
4020 -- Start of processing for Concurrent_Ref
4023 if Is_Access_Type
(Ntyp
) then
4024 Dtyp
:= Designated_Type
(Ntyp
);
4026 if Is_Protected_Type
(Dtyp
) then
4027 Sel
:= Name_uObject
;
4029 Sel
:= Name_uTask_Id
;
4033 Make_Selected_Component
(Loc
,
4035 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
4036 Make_Explicit_Dereference
(Loc
, N
)),
4037 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
4039 elsif Is_Entity_Name
(N
)
4040 and then Is_Concurrent_Type
(Entity
(N
))
4042 if Is_Task_Type
(Entity
(N
)) then
4044 if Is_Current_Task
(Entity
(N
)) then
4046 Make_Function_Call
(Loc
,
4047 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
4052 T_Self
: constant Entity_Id
:=
4053 Make_Defining_Identifier
(Loc
,
4054 Chars
=> New_Internal_Name
('T'));
4055 T_Body
: constant Node_Id
:=
4056 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
4059 Decl
:= Make_Object_Declaration
(Loc
,
4060 Defining_Identifier
=> T_Self
,
4061 Object_Definition
=>
4062 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
4064 Make_Function_Call
(Loc
,
4065 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
4066 Prepend
(Decl
, Declarations
(T_Body
));
4068 Set_Scope
(T_Self
, Entity
(N
));
4069 return New_Occurrence_Of
(T_Self
, Loc
);
4074 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
4077 New_Reference_To
(Find_Protection_Object
(Current_Scope
), Loc
);
4081 if Is_Protected_Type
(Ntyp
) then
4082 Sel
:= Name_uObject
;
4084 elsif Is_Task_Type
(Ntyp
) then
4085 Sel
:= Name_uTask_Id
;
4088 raise Program_Error
;
4092 Make_Selected_Component
(Loc
,
4094 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
4096 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
4100 ------------------------
4101 -- Convert_Concurrent --
4102 ------------------------
4104 function Convert_Concurrent
4106 Typ
: Entity_Id
) return Node_Id
4109 if not Is_Concurrent_Type
(Typ
) then
4113 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
4116 end Convert_Concurrent
;
4118 -------------------------------------
4119 -- Debug_Private_Data_Declarations --
4120 -------------------------------------
4122 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
4123 Debug_Nod
: Node_Id
;
4127 Decl
:= First
(Decls
);
4128 while Present
(Decl
)
4129 and then not Comes_From_Source
(Decl
)
4131 -- Declaration for concurrent entity _object and its access type,
4132 -- along with the entry index subtype:
4133 -- type prot_typVP is access prot_typV;
4134 -- _object : prot_typVP := prot_typV (_O);
4135 -- subtype Jnn is <Type of Index> range Low .. High;
4137 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
4138 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4140 -- Declaration for the Protection object, discriminals, privals and
4141 -- entry index constant:
4142 -- conc_typR : protection_typ renames _object._object;
4143 -- discr_nameD : discr_typ renames _object.discr_name;
4144 -- discr_nameD : discr_typ renames _task.discr_name;
4145 -- prival_name : comp_typ renames _object.comp_name;
4146 -- J : constant Jnn :=
4147 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4149 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
4150 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4151 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
4153 if Present
(Debug_Nod
) then
4154 Insert_After
(Decl
, Debug_Nod
);
4160 end Debug_Private_Data_Declarations
;
4162 ----------------------------
4163 -- Entry_Index_Expression --
4164 ----------------------------
4166 function Entry_Index_Expression
4170 Ttyp
: Entity_Id
) return Node_Id
4180 -- The queues of entries and entry families appear in textual order in
4181 -- the associated record. The entry index is computed as the sum of the
4182 -- number of queues for all entries that precede the designated one, to
4183 -- which is added the index expression, if this expression denotes a
4184 -- member of a family.
4186 -- The following is a place holder for the count of simple entries
4188 Num
:= Make_Integer_Literal
(Sloc
, 1);
4190 -- We construct an expression which is a series of addition operations.
4191 -- The first operand is the number of single entries that precede this
4192 -- one, the second operand is the index value relative to the start of
4193 -- the referenced family, and the remaining operands are the lengths of
4194 -- the entry families that precede this entry, i.e. the constructed
4197 -- number_simple_entries +
4198 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4199 -- family'length + ...
4201 -- where index-value is the given index value, and s is the index
4202 -- subtype (we have to use pos because the subtype might be an
4203 -- enumeration type preventing direct subtraction). Note that the task
4204 -- entry array is one-indexed.
4206 -- The upper bound of the entry family may be a discriminant, so we
4207 -- retrieve the lower bound explicitly to compute offset, rather than
4208 -- using the index subtype which may mention a discriminant.
4210 if Present
(Index
) then
4211 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
4220 Make_Attribute_Reference
(Sloc
,
4221 Attribute_Name
=> Name_Pos
,
4222 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
4223 Expressions
=> New_List
(Relocate_Node
(Index
))),
4231 -- Now add lengths of preceding entries and entry families
4233 Prev
:= First_Entity
(Ttyp
);
4235 while Chars
(Prev
) /= Chars
(Ent
)
4236 or else (Ekind
(Prev
) /= Ekind
(Ent
))
4237 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
4239 if Ekind
(Prev
) = E_Entry
then
4240 Set_Intval
(Num
, Intval
(Num
) + 1);
4242 elsif Ekind
(Prev
) = E_Entry_Family
then
4244 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
4245 Lo
:= Type_Low_Bound
(S
);
4246 Hi
:= Type_High_Bound
(S
);
4251 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
4253 -- Other components are anonymous types to be ignored
4263 end Entry_Index_Expression
;
4265 ---------------------------
4266 -- Establish_Task_Master --
4267 ---------------------------
4269 procedure Establish_Task_Master
(N
: Node_Id
) is
4272 if Restriction_Active
(No_Task_Hierarchy
) = False then
4273 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
4274 Prepend_To
(Declarations
(N
), Call
);
4277 end Establish_Task_Master
;
4279 --------------------------------
4280 -- Expand_Accept_Declarations --
4281 --------------------------------
4283 -- Part of the expansion of an accept statement involves the creation of
4284 -- a declaration that can be referenced from the statement sequence of
4289 -- This declaration is inserted immediately before the accept statement
4290 -- and it is important that it be inserted before the statements of the
4291 -- statement sequence are analyzed. Thus it would be too late to create
4292 -- this declaration in the Expand_N_Accept_Statement routine, which is
4293 -- why there is a separate procedure to be called directly from Sem_Ch9.
4295 -- Ann is used to hold the address of the record containing the parameters
4296 -- (see Expand_N_Entry_Call for more details on how this record is built).
4297 -- References to the parameters do an unchecked conversion of this address
4298 -- to a pointer to the required record type, and then access the field that
4299 -- holds the value of the required parameter. The entity for the address
4300 -- variable is held as the top stack element (i.e. the last element) of the
4301 -- Accept_Address stack in the corresponding entry entity, and this element
4302 -- must be set in place before the statements are processed.
4304 -- The above description applies to the case of a stand alone accept
4305 -- statement, i.e. one not appearing as part of a select alternative.
4307 -- For the case of an accept that appears as part of a select alternative
4308 -- of a selective accept, we must still create the declaration right away,
4309 -- since Ann is needed immediately, but there is an important difference:
4311 -- The declaration is inserted before the selective accept, not before
4312 -- the accept statement (which is not part of a list anyway, and so would
4313 -- not accommodate inserted declarations)
4315 -- We only need one address variable for the entire selective accept. So
4316 -- the Ann declaration is created only for the first accept alternative,
4317 -- and subsequent accept alternatives reference the same Ann variable.
4319 -- We can distinguish the two cases by seeing whether the accept statement
4320 -- is part of a list. If not, then it must be in an accept alternative.
4322 -- To expand the requeue statement, a label is provided at the end of the
4323 -- accept statement or alternative of which it is a part, so that the
4324 -- statement can be skipped after the requeue is complete. This label is
4325 -- created here rather than during the expansion of the accept statement,
4326 -- because it will be needed by any requeue statements within the accept,
4327 -- which are expanded before the accept.
4329 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
4330 Loc
: constant Source_Ptr
:= Sloc
(N
);
4331 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
4332 Ann
: Entity_Id
:= Empty
;
4340 if Expander_Active
then
4342 -- If we have no handled statement sequence, we may need to build
4343 -- a dummy sequence consisting of a null statement. This can be
4344 -- skipped if the trivial accept optimization is permitted.
4346 if not Trivial_Accept_OK
4348 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
4350 Set_Handled_Statement_Sequence
(N
,
4351 Make_Handled_Sequence_Of_Statements
(Loc
,
4352 New_List
(Make_Null_Statement
(Loc
))));
4355 -- Create and declare two labels to be placed at the end of the
4356 -- accept statement. The first label is used to allow requeues to
4357 -- skip the remainder of entry processing. The second label is used
4358 -- to skip the remainder of entry processing if the rendezvous
4359 -- completes in the middle of the accept body.
4361 if Present
(Handled_Statement_Sequence
(N
)) then
4362 Lab_Id
:= Make_Identifier
(Loc
, New_Internal_Name
('L'));
4364 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)));
4365 Lab
:= Make_Label
(Loc
, Lab_Id
);
4367 Make_Implicit_Label_Declaration
(Loc
,
4368 Defining_Identifier
=> Entity
(Lab_Id
),
4369 Label_Construct
=> Lab
);
4370 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
4372 Lab_Id
:= Make_Identifier
(Loc
, New_Internal_Name
('L'));
4374 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)));
4375 Lab
:= Make_Label
(Loc
, Lab_Id
);
4377 Make_Implicit_Label_Declaration
(Loc
,
4378 Defining_Identifier
=> Entity
(Lab_Id
),
4379 Label_Construct
=> Lab
);
4380 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
4387 -- Case of stand alone accept statement
4389 if Is_List_Member
(N
) then
4391 if Present
(Handled_Statement_Sequence
(N
)) then
4393 Make_Defining_Identifier
(Loc
,
4394 Chars
=> New_Internal_Name
('A'));
4397 Make_Object_Declaration
(Loc
,
4398 Defining_Identifier
=> Ann
,
4399 Object_Definition
=>
4400 New_Reference_To
(RTE
(RE_Address
), Loc
));
4402 Insert_Before
(N
, Adecl
);
4405 Insert_Before
(N
, Ldecl
);
4408 Insert_Before
(N
, Ldecl2
);
4412 -- Case of accept statement which is in an accept alternative
4416 Acc_Alt
: constant Node_Id
:= Parent
(N
);
4417 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
4421 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
4422 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
4424 -- ??? Consider a single label for select statements
4426 if Present
(Handled_Statement_Sequence
(N
)) then
4428 Statements
(Handled_Statement_Sequence
(N
)));
4432 Statements
(Handled_Statement_Sequence
(N
)));
4436 -- Find first accept alternative of the selective accept. A
4437 -- valid selective accept must have at least one accept in it.
4439 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
4441 while Nkind
(Alt
) /= N_Accept_Alternative
loop
4445 -- If we are the first accept statement, then we have to create
4446 -- the Ann variable, as for the stand alone case, except that
4447 -- it is inserted before the selective accept. Similarly, a
4448 -- label for requeue expansion must be declared.
4450 if N
= Accept_Statement
(Alt
) then
4452 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
4455 Make_Object_Declaration
(Loc
,
4456 Defining_Identifier
=> Ann
,
4457 Object_Definition
=>
4458 New_Reference_To
(RTE
(RE_Address
), Loc
));
4460 Insert_Before
(Sel_Acc
, Adecl
);
4463 -- If we are not the first accept statement, then find the Ann
4464 -- variable allocated by the first accept and use it.
4468 Node
(Last_Elmt
(Accept_Address
4469 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
4474 -- Merge here with Ann either created or referenced, and Adecl
4475 -- pointing to the corresponding declaration. Remaining processing
4476 -- is the same for the two cases.
4478 if Present
(Ann
) then
4479 Append_Elmt
(Ann
, Accept_Address
(Ent
));
4480 Set_Debug_Info_Needed
(Ann
);
4483 -- Create renaming declarations for the entry formals. Each reference
4484 -- to a formal becomes a dereference of a component of the parameter
4485 -- block, whose address is held in Ann. These declarations are
4486 -- eventually inserted into the accept block, and analyzed there so
4487 -- that they have the proper scope for gdb and do not conflict with
4488 -- other declarations.
4490 if Present
(Parameter_Specifications
(N
))
4491 and then Present
(Handled_Statement_Sequence
(N
))
4501 Formal
:= First_Formal
(Ent
);
4503 while Present
(Formal
) loop
4504 Comp
:= Entry_Component
(Formal
);
4506 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
4508 Set_Etype
(New_F
, Etype
(Formal
));
4509 Set_Scope
(New_F
, Ent
);
4511 -- Now we set debug info needed on New_F even though it does
4512 -- not come from source, so that the debugger will get the
4513 -- right information for these generated names.
4515 Set_Debug_Info_Needed
(New_F
);
4517 if Ekind
(Formal
) = E_In_Parameter
then
4518 Set_Ekind
(New_F
, E_Constant
);
4520 Set_Ekind
(New_F
, E_Variable
);
4521 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
4524 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
4527 Make_Object_Renaming_Declaration
(Loc
,
4528 Defining_Identifier
=>
4531 New_Reference_To
(Etype
(Formal
), Loc
),
4533 Make_Explicit_Dereference
(Loc
,
4534 Make_Selected_Component
(Loc
,
4536 Unchecked_Convert_To
(
4537 Entry_Parameters_Type
(Ent
),
4538 New_Reference_To
(Ann
, Loc
)),
4540 New_Reference_To
(Comp
, Loc
))));
4542 if No
(Declarations
(N
)) then
4543 Set_Declarations
(N
, New_List
);
4546 Append
(Decl
, Declarations
(N
));
4547 Set_Renamed_Object
(Formal
, New_F
);
4548 Next_Formal
(Formal
);
4555 end Expand_Accept_Declarations
;
4557 ---------------------------------------------
4558 -- Expand_Access_Protected_Subprogram_Type --
4559 ---------------------------------------------
4561 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
4562 Loc
: constant Source_Ptr
:= Sloc
(N
);
4564 T
: constant Entity_Id
:= Defining_Identifier
(N
);
4565 D_T
: constant Entity_Id
:= Designated_Type
(T
);
4566 D_T2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
,
4567 Chars
=> New_Internal_Name
('D'));
4568 E_T
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
,
4569 Chars
=> New_Internal_Name
('E'));
4570 P_List
: constant List_Id
:= Build_Protected_Spec
4571 (N
, RTE
(RE_Address
), D_T
, False);
4577 -- Create access to protected subprogram with full signature
4579 if Nkind
(Type_Definition
(N
)) = N_Access_Function_Definition
then
4581 Make_Access_Function_Definition
(Loc
,
4582 Parameter_Specifications
=> P_List
,
4583 Result_Definition
=>
4584 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
4588 Make_Access_Procedure_Definition
(Loc
,
4589 Parameter_Specifications
=> P_List
);
4593 Make_Full_Type_Declaration
(Loc
,
4594 Defining_Identifier
=> D_T2
,
4595 Type_Definition
=> Def1
);
4598 Insert_After
(N
, Decl1
);
4600 -- Create Equivalent_Type, a record with two components for an access to
4601 -- object and an access to subprogram.
4604 Make_Component_Declaration
(Loc
,
4605 Defining_Identifier
=>
4606 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P')),
4607 Component_Definition
=>
4608 Make_Component_Definition
(Loc
,
4609 Aliased_Present
=> False,
4610 Subtype_Indication
=>
4611 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
4613 Make_Component_Declaration
(Loc
,
4614 Defining_Identifier
=>
4615 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S')),
4616 Component_Definition
=>
4617 Make_Component_Definition
(Loc
,
4618 Aliased_Present
=> False,
4619 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
4622 Make_Full_Type_Declaration
(Loc
,
4623 Defining_Identifier
=> E_T
,
4625 Make_Record_Definition
(Loc
,
4627 Make_Component_List
(Loc
,
4628 Component_Items
=> Comps
)));
4631 Insert_After
(Decl1
, Decl2
);
4632 Set_Equivalent_Type
(T
, E_T
);
4633 end Expand_Access_Protected_Subprogram_Type
;
4635 --------------------------
4636 -- Expand_Entry_Barrier --
4637 --------------------------
4639 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
4640 Cond
: constant Node_Id
:=
4641 Condition
(Entry_Body_Formal_Part
(N
));
4642 Prot
: constant Entity_Id
:= Scope
(Ent
);
4643 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
4646 Body_Decl
: Node_Id
;
4649 if No_Run_Time_Mode
then
4650 Error_Msg_CRT
("entry barrier", N
);
4654 -- The body of the entry barrier must be analyzed in the context of the
4655 -- protected object, but its scope is external to it, just as any other
4656 -- unprotected version of a protected operation. The specification has
4657 -- been produced when the protected type declaration was elaborated. We
4658 -- build the body, insert it in the enclosing scope, but analyze it in
4659 -- the current context. A more uniform approach would be to treat the
4660 -- barrier just as a protected function, and discard the protected
4661 -- version of it because it is never called.
4663 if Expander_Active
then
4664 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
4665 Func
:= Barrier_Function
(Ent
);
4666 Set_Corresponding_Spec
(B_F
, Func
);
4668 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
4670 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
4671 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
4674 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
4676 Set_Discriminals
(Spec_Decl
);
4677 Set_Scope
(Func
, Scope
(Prot
));
4680 Analyze_And_Resolve
(Cond
, Any_Boolean
);
4683 -- The Ravenscar profile restricts barriers to simple variables declared
4684 -- within the protected object. We also allow Boolean constants, since
4685 -- these appear in several published examples and are also allowed by
4686 -- the Aonix compiler.
4688 -- Note that after analysis variables in this context will be replaced
4689 -- by the corresponding prival, that is to say a renaming of a selected
4690 -- component of the form _Object.Var. If expansion is disabled, as
4691 -- within a generic, we check that the entity appears in the current
4694 if Is_Entity_Name
(Cond
) then
4696 -- A small optimization of useless renamings. If the scope of the
4697 -- entity of the condition is not the barrier function, then the
4698 -- condition does not reference any of the generated renamings
4699 -- within the function.
4702 and then Scope
(Entity
(Cond
)) /= Func
4704 Set_Declarations
(B_F
, Empty_List
);
4707 if Entity
(Cond
) = Standard_False
4709 Entity
(Cond
) = Standard_True
4713 elsif not Expander_Active
4714 and then Scope
(Entity
(Cond
)) = Current_Scope
4718 -- Check for case of _object.all.field (note that the explicit
4719 -- dereference gets inserted by analyze/expand of _object.field)
4721 elsif Present
(Renamed_Object
(Entity
(Cond
)))
4723 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
4727 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
4733 -- It is not a boolean variable or literal, so check the restriction
4735 Check_Restriction
(Simple_Barriers
, Cond
);
4736 end Expand_Entry_Barrier
;
4738 ------------------------------
4739 -- Expand_N_Abort_Statement --
4740 ------------------------------
4742 -- Expand abort T1, T2, .. Tn; into:
4743 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
4745 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
4746 Loc
: constant Source_Ptr
:= Sloc
(N
);
4747 Tlist
: constant List_Id
:= Names
(N
);
4753 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
4756 Tasknm
:= First
(Tlist
);
4758 while Present
(Tasknm
) loop
4761 -- A task interface class-wide type object is being aborted.
4762 -- Retrieve its _task_id by calling a dispatching routine.
4764 if Ada_Version
>= Ada_05
4765 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
4766 and then Is_Interface
(Etype
(Tasknm
))
4767 and then Is_Task_Interface
(Etype
(Tasknm
))
4769 Append_To
(Component_Associations
(Aggr
),
4770 Make_Component_Association
(Loc
,
4771 Choices
=> New_List
(
4772 Make_Integer_Literal
(Loc
, Count
)),
4775 -- Task_Id (Tasknm._disp_get_task_id)
4777 Make_Unchecked_Type_Conversion
(Loc
,
4779 New_Reference_To
(RTE
(RO_ST_Task_Id
), Loc
),
4781 Make_Selected_Component
(Loc
,
4783 New_Copy_Tree
(Tasknm
),
4785 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
4788 Append_To
(Component_Associations
(Aggr
),
4789 Make_Component_Association
(Loc
,
4790 Choices
=> New_List
(
4791 Make_Integer_Literal
(Loc
, Count
)),
4792 Expression
=> Concurrent_Ref
(Tasknm
)));
4799 Make_Procedure_Call_Statement
(Loc
,
4800 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
4801 Parameter_Associations
=> New_List
(
4802 Make_Qualified_Expression
(Loc
,
4803 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
4804 Expression
=> Aggr
))));
4807 end Expand_N_Abort_Statement
;
4809 -------------------------------
4810 -- Expand_N_Accept_Statement --
4811 -------------------------------
4813 -- This procedure handles expansion of accept statements that stand
4814 -- alone, i.e. they are not part of an accept alternative. The expansion
4815 -- of accept statement in accept alternatives is handled by the routines
4816 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
4817 -- following description applies only to stand alone accept statements.
4819 -- If there is no handled statement sequence, or only null statements,
4820 -- then this is called a trivial accept, and the expansion is:
4822 -- Accept_Trivial (entry-index)
4824 -- If there is a handled statement sequence, then the expansion is:
4831 -- Accept_Call (entry-index, Ann);
4832 -- Renaming_Declarations for formals
4833 -- <statement sequence from N_Accept_Statement node>
4834 -- Complete_Rendezvous;
4839 -- <exception handler from N_Accept_Statement node>
4840 -- Complete_Rendezvous;
4842 -- <exception handler from N_Accept_Statement node>
4843 -- Complete_Rendezvous;
4848 -- when all others =>
4849 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
4852 -- The first three declarations were already inserted ahead of the accept
4853 -- statement by the Expand_Accept_Declarations procedure, which was called
4854 -- directly from the semantics during analysis of the accept statement,
4855 -- before analyzing its contained statements.
4857 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
4858 -- from possible expansion activity (the original source of course does
4859 -- not have any declarations associated with the accept statement, since
4860 -- an accept statement has no declarative part). In particular, if the
4861 -- expander is active, the first such declaration is the declaration of
4862 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
4864 -- The two blocks are merged into a single block if the inner block has
4865 -- no exception handlers, but otherwise two blocks are required, since
4866 -- exceptions might be raised in the exception handlers of the inner
4867 -- block, and Exceptional_Complete_Rendezvous must be called.
4869 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
4870 Loc
: constant Source_Ptr
:= Sloc
(N
);
4871 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
4872 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
4873 Eindx
: constant Node_Id
:= Entry_Index
(N
);
4874 Eent
: constant Entity_Id
:= Entity
(Ename
);
4875 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
4876 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
4877 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
4882 -- Start of processing for Expand_N_Accept_Statement
4885 -- If accept statement is not part of a list, then its parent must be
4886 -- an accept alternative, and, as described above, we do not do any
4887 -- expansion for such accept statements at this level.
4889 if not Is_List_Member
(N
) then
4890 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
4893 -- Trivial accept case (no statement sequence, or null statements).
4894 -- If the accept statement has declarations, then just insert them
4895 -- before the procedure call.
4897 elsif Trivial_Accept_OK
4898 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
4900 -- Remove declarations for renamings, because the parameter block
4901 -- will not be assigned.
4908 D
:= First
(Declarations
(N
));
4910 while Present
(D
) loop
4912 if Nkind
(D
) = N_Object_Renaming_Declaration
then
4920 if Present
(Declarations
(N
)) then
4921 Insert_Actions
(N
, Declarations
(N
));
4925 Make_Procedure_Call_Statement
(Loc
,
4926 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
4927 Parameter_Associations
=> New_List
(
4928 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
4932 -- Discard Entry_Address that was created for it, so it will not be
4933 -- emitted if this accept statement is in the statement part of a
4934 -- delay alternative.
4936 if Present
(Stats
) then
4937 Remove_Last_Elmt
(Acstack
);
4940 -- Case of statement sequence present
4943 -- Construct the block, using the declarations from the accept
4944 -- statement if any to initialize the declarations of the block.
4946 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
4947 Set_Ekind
(Blkent
, E_Block
);
4948 Set_Etype
(Blkent
, Standard_Void_Type
);
4949 Set_Scope
(Blkent
, Current_Scope
);
4952 Make_Block_Statement
(Loc
,
4953 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4954 Declarations
=> Declarations
(N
),
4955 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
4957 -- Prepend call to Accept_Call to main statement sequence If the
4958 -- accept has exception handlers, the statement sequence is wrapped
4959 -- in a block. Insert call and renaming declarations in the
4960 -- declarations of the block, so they are elaborated before the
4964 Make_Procedure_Call_Statement
(Loc
,
4965 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
4966 Parameter_Associations
=> New_List
(
4967 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
4968 New_Reference_To
(Ann
, Loc
)));
4970 if Parent
(Stats
) = N
then
4971 Prepend
(Call
, Statements
(Stats
));
4980 Push_Scope
(Blkent
);
4988 D
:= First
(Declarations
(N
));
4989 while Present
(D
) loop
4992 if Nkind
(D
) = N_Object_Renaming_Declaration
then
4994 -- The renaming declarations for the formals were created
4995 -- during analysis of the accept statement, and attached to
4996 -- the list of declarations. Place them now in the context
4997 -- of the accept block or subprogram.
5000 Typ
:= Entity
(Subtype_Mark
(D
));
5001 Insert_After
(Call
, D
);
5004 -- If the formal is class_wide, it does not have an actual
5005 -- subtype. The analysis of the renaming declaration creates
5006 -- one, but we need to retain the class-wide nature of the
5009 if Is_Class_Wide_Type
(Typ
) then
5010 Set_Etype
(Defining_Identifier
(D
), Typ
);
5021 -- Replace the accept statement by the new block
5026 -- Last step is to unstack the Accept_Address value
5028 Remove_Last_Elmt
(Acstack
);
5030 end Expand_N_Accept_Statement
;
5032 ----------------------------------
5033 -- Expand_N_Asynchronous_Select --
5034 ----------------------------------
5036 -- This procedure assumes that the trigger statement is an entry call or
5037 -- a dispatching procedure call. A delay alternative should already have
5038 -- been expanded into an entry call to the appropriate delay object Wait
5041 -- If the trigger is a task entry call, the select is implemented with
5042 -- a Task_Entry_Call:
5047 -- P : parms := (parm, parm, parm);
5049 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5051 -- procedure _clean is
5054 -- Cancel_Task_Entry_Call (C);
5061 -- (<acceptor-task>, -- Acceptor
5062 -- <entry-index>, -- E
5063 -- P'Address, -- Uninterpreted_Data
5064 -- Asynchronous_Call, -- Mode
5065 -- B); -- Rendezvous_Successful
5072 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5075 -- when Abort_Signal => Abort_Undefer;
5082 -- <triggered-statements>
5086 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5087 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5091 -- P : parms := (parm, parm, parm);
5093 -- Call_Simple (acceptor-task, entry-index, P'Address);
5099 -- so the task at hand is to convert the latter expansion into the former
5101 -- If the trigger is a protected entry call, the select is implemented
5102 -- with Protected_Entry_Call:
5105 -- P : E1_Params := (param, param, param);
5106 -- Bnn : Communications_Block;
5111 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5113 -- procedure _clean is
5116 -- if Enqueued (Bnn) then
5117 -- Cancel_Protected_Entry_Call (Bnn);
5124 -- Protected_Entry_Call
5125 -- (po._object'Access, -- Object
5126 -- <entry index>, -- E
5127 -- P'Address, -- Uninterpreted_Data
5128 -- Asynchronous_Call, -- Mode
5131 -- if Enqueued (Bnn) then
5135 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5138 -- when Abort_Signal => Abort_Undefer;
5141 -- if not Cancelled (Bnn) then
5142 -- <triggered-statements>
5146 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5150 -- P : E1_Params := (param, param, param);
5151 -- Bnn : Communications_Block;
5154 -- Protected_Entry_Call
5155 -- (po._object'Access, -- Object
5156 -- <entry index>, -- E
5157 -- P'Address, -- Uninterpreted_Data
5158 -- Simple_Call, -- Mode
5165 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5169 -- B : Boolean := False;
5170 -- Bnn : Communication_Block;
5171 -- C : Ada.Tags.Prim_Op_Kind;
5172 -- D : System.Storage_Elements.Dummy_Communication_Block;
5173 -- K : Ada.Tags.Tagged_Kind :=
5174 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5175 -- P : Parameters := (Param1 .. ParamN);
5180 -- if K = Ada.Tags.TK_Limited_Tagged then
5181 -- <dispatching-call>;
5182 -- <triggering-statements>;
5186 -- Ada.Tags.Get_Offset_Index
5187 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5189 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5191 -- if C = POK_Protected_Entry then
5193 -- procedure _clean is
5195 -- if Enqueued (Bnn) then
5196 -- Cancel_Protected_Entry_Call (Bnn);
5202 -- _Disp_Asynchronous_Select
5203 -- (<object>, S, P'Address, D, B);
5204 -- Bnn := Communication_Block (D);
5206 -- Param1 := P.Param1;
5208 -- ParamN := P.ParamN;
5210 -- if Enqueued (Bnn) then
5211 -- <abortable-statements>
5214 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5217 -- when Abort_Signal => Abort_Undefer;
5220 -- if not Cancelled (Bnn) then
5221 -- <triggering-statements>
5224 -- elsif C = POK_Task_Entry then
5226 -- procedure _clean is
5228 -- Cancel_Task_Entry_Call (U);
5234 -- _Disp_Asynchronous_Select
5235 -- (<object>, S, P'Address, D, B);
5236 -- Bnn := Communication_Bloc (D);
5238 -- Param1 := P.Param1;
5240 -- ParamN := P.ParamN;
5245 -- <abortable-statements>
5247 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5250 -- when Abort_Signal => Abort_Undefer;
5254 -- <triggering-statements>
5259 -- <dispatching-call>;
5260 -- <triggering-statements>
5265 -- The job is to convert this to the asynchronous form
5267 -- If the trigger is a delay statement, it will have been expanded into a
5268 -- call to one of the GNARL delay procedures. This routine will convert
5269 -- this into a protected entry call on a delay object and then continue
5270 -- processing as for a protected entry call trigger. This requires
5271 -- declaring a Delay_Block object and adding a pointer to this object to
5272 -- the parameter list of the delay procedure to form the parameter list of
5273 -- the entry call. This object is used by the runtime to queue the delay
5276 -- For a description of the use of P and the assignments after the call,
5277 -- see Expand_N_Entry_Call_Statement.
5279 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
5280 Loc
: constant Source_Ptr
:= Sloc
(N
);
5281 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
5282 Astats
: constant List_Id
:= Statements
(Abrt
);
5283 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
5284 Tstats
: constant List_Id
:= Statements
(Trig
);
5286 Abort_Block_Ent
: Entity_Id
;
5287 Abortable_Block
: Node_Id
;
5289 Blk_Ent
: Entity_Id
;
5290 Blk_Typ
: Entity_Id
;
5292 Call_Ent
: Entity_Id
;
5293 Cancel_Param
: Entity_Id
;
5294 Cleanup_Block
: Node_Id
;
5295 Cleanup_Block_Ent
: Entity_Id
;
5296 Cleanup_Stmts
: List_Id
;
5297 Conc_Typ_Stmts
: List_Id
;
5299 Dblock_Ent
: Entity_Id
;
5304 Enqueue_Call
: Node_Id
;
5308 Lim_Typ_Stmts
: List_Id
;
5314 ProtE_Stmts
: List_Id
;
5315 ProtP_Stmts
: List_Id
;
5318 Target_Undefer
: RE_Id
;
5319 TaskE_Stmts
: List_Id
;
5320 Undefer_Args
: List_Id
:= No_List
;
5322 B
: Entity_Id
; -- Call status flag
5323 Bnn
: Entity_Id
; -- Communication block
5324 C
: Entity_Id
; -- Call kind
5325 K
: Entity_Id
; -- Tagged kind
5326 P
: Entity_Id
; -- Parameter block
5327 S
: Entity_Id
; -- Primitive operation slot
5328 T
: Entity_Id
; -- Additional status flag
5331 Blk_Ent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
5332 Ecall
:= Triggering_Statement
(Trig
);
5334 -- The arguments in the call may require dynamic allocation, and the
5335 -- call statement may have been transformed into a block. The block
5336 -- may contain additional declarations for internal entities, and the
5337 -- original call is found by sequential search.
5339 if Nkind
(Ecall
) = N_Block_Statement
then
5340 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
5341 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
5342 N_Entry_Call_Statement
)
5348 -- This is either a dispatching call or a delay statement used as a
5349 -- trigger which was expanded into a procedure call.
5351 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
5352 if Ada_Version
>= Ada_05
5354 (No
(Original_Node
(Ecall
))
5355 or else not Nkind_In
(Original_Node
(Ecall
),
5356 N_Delay_Relative_Statement
,
5357 N_Delay_Until_Statement
))
5359 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
5364 -- Call status flag processing, generate:
5365 -- B : Boolean := False;
5367 B
:= Build_B
(Loc
, Decls
);
5369 -- Communication block processing, generate:
5370 -- Bnn : Communication_Block;
5372 Bnn
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('B'));
5375 Make_Object_Declaration
(Loc
,
5376 Defining_Identifier
=>
5378 Object_Definition
=>
5379 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
5381 -- Call kind processing, generate:
5382 -- C : Ada.Tags.Prim_Op_Kind;
5384 C
:= Build_C
(Loc
, Decls
);
5386 -- Tagged kind processing, generate:
5387 -- K : Ada.Tags.Tagged_Kind :=
5388 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5390 -- Dummy communication block, generate:
5391 -- D : Dummy_Communication_Block;
5394 Make_Object_Declaration
(Loc
,
5395 Defining_Identifier
=>
5396 Make_Defining_Identifier
(Loc
, Name_uD
),
5397 Object_Definition
=>
5399 RTE
(RE_Dummy_Communication_Block
), Loc
)));
5401 K
:= Build_K
(Loc
, Decls
, Obj
);
5403 -- Parameter block processing
5405 Blk_Typ
:= Build_Parameter_Block
5406 (Loc
, Actuals
, Formals
, Decls
);
5407 P
:= Parameter_Block_Pack
5408 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
5410 -- Dispatch table slot processing, generate:
5413 S
:= Build_S
(Loc
, Decls
);
5415 -- Additional status flag processing, generate:
5417 T
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
5420 Make_Object_Declaration
(Loc
,
5421 Defining_Identifier
=>
5423 Object_Definition
=>
5424 New_Reference_To
(Standard_Boolean
, Loc
)));
5426 ------------------------------
5427 -- Protected entry handling --
5428 ------------------------------
5431 -- Param1 := P.Param1;
5433 -- ParamN := P.ParamN;
5435 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
5438 -- Bnn := Communication_Block (D);
5440 Prepend_To
(Cleanup_Stmts
,
5441 Make_Assignment_Statement
(Loc
,
5443 New_Reference_To
(Bnn
, Loc
),
5445 Make_Unchecked_Type_Conversion
(Loc
,
5447 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
5449 Make_Identifier
(Loc
, Name_uD
))));
5452 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5454 Prepend_To
(Cleanup_Stmts
,
5455 Make_Procedure_Call_Statement
(Loc
,
5458 Find_Prim_Op
(Etype
(Etype
(Obj
)),
5459 Name_uDisp_Asynchronous_Select
),
5461 Parameter_Associations
=>
5463 New_Copy_Tree
(Obj
), -- <object>
5464 New_Reference_To
(S
, Loc
), -- S
5465 Make_Attribute_Reference
(Loc
, -- P'Address
5467 New_Reference_To
(P
, Loc
),
5470 Make_Identifier
(Loc
, Name_uD
), -- D
5471 New_Reference_To
(B
, Loc
)))); -- B
5474 -- if Enqueued (Bnn) then
5475 -- <abortable-statements>
5478 Append_To
(Cleanup_Stmts
,
5479 Make_If_Statement
(Loc
,
5481 Make_Function_Call
(Loc
,
5483 New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
5484 Parameter_Associations
=>
5486 New_Reference_To
(Bnn
, Loc
))),
5489 New_Copy_List_Tree
(Astats
)));
5491 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5492 -- will then generate a _clean for the communication block Bnn.
5496 -- procedure _clean is
5498 -- if Enqueued (Bnn) then
5499 -- Cancel_Protected_Entry_Call (Bnn);
5508 Cleanup_Block_Ent
:=
5509 Make_Defining_Identifier
(Loc
, New_Internal_Name
('C'));
5512 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
5514 -- Wrap the cleanup block in an exception handling block
5520 -- when Abort_Signal => Abort_Undefer;
5524 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
5528 Make_Implicit_Label_Declaration
(Loc
,
5529 Defining_Identifier
=>
5533 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
5536 -- if not Cancelled (Bnn) then
5537 -- <triggering-statements>
5540 Append_To
(ProtE_Stmts
,
5541 Make_If_Statement
(Loc
,
5545 Make_Function_Call
(Loc
,
5547 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
5548 Parameter_Associations
=>
5550 New_Reference_To
(Bnn
, Loc
)))),
5553 New_Copy_List_Tree
(Tstats
)));
5555 -------------------------
5556 -- Task entry handling --
5557 -------------------------
5560 -- Param1 := P.Param1;
5562 -- ParamN := P.ParamN;
5564 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
5567 -- Bnn := Communication_Block (D);
5569 Append_To
(TaskE_Stmts
,
5570 Make_Assignment_Statement
(Loc
,
5572 New_Reference_To
(Bnn
, Loc
),
5574 Make_Unchecked_Type_Conversion
(Loc
,
5576 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
5578 Make_Identifier
(Loc
, Name_uD
))));
5581 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5583 Prepend_To
(TaskE_Stmts
,
5584 Make_Procedure_Call_Statement
(Loc
,
5587 Find_Prim_Op
(Etype
(Etype
(Obj
)),
5588 Name_uDisp_Asynchronous_Select
),
5590 Parameter_Associations
=>
5592 New_Copy_Tree
(Obj
), -- <object>
5593 New_Reference_To
(S
, Loc
), -- S
5594 Make_Attribute_Reference
(Loc
, -- P'Address
5596 New_Reference_To
(P
, Loc
),
5599 Make_Identifier
(Loc
, Name_uD
), -- D
5600 New_Reference_To
(B
, Loc
)))); -- B
5605 Prepend_To
(TaskE_Stmts
,
5606 Make_Procedure_Call_Statement
(Loc
,
5608 New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
5609 Parameter_Associations
=>
5614 -- <abortable-statements>
5616 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
5618 Prepend_To
(Cleanup_Stmts
,
5619 Make_Procedure_Call_Statement
(Loc
,
5621 New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
5622 Parameter_Associations
=>
5625 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5626 -- will generate a _clean for the additional status flag.
5630 -- procedure _clean is
5632 -- Cancel_Task_Entry_Call (U);
5640 Cleanup_Block_Ent
:=
5641 Make_Defining_Identifier
(Loc
, New_Internal_Name
('C'));
5644 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
5646 -- Wrap the cleanup block in an exception handling block
5652 -- when Abort_Signal => Abort_Undefer;
5656 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
5658 Append_To
(TaskE_Stmts
,
5659 Make_Implicit_Label_Declaration
(Loc
,
5660 Defining_Identifier
=>
5663 Append_To
(TaskE_Stmts
,
5665 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
5669 -- <triggering-statements>
5672 Append_To
(TaskE_Stmts
,
5673 Make_If_Statement
(Loc
,
5677 New_Reference_To
(T
, Loc
)),
5680 New_Copy_List_Tree
(Tstats
)));
5682 ----------------------------------
5683 -- Protected procedure handling --
5684 ----------------------------------
5687 -- <dispatching-call>;
5688 -- <triggering-statements>
5690 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
5691 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
5694 -- S := Ada.Tags.Get_Offset_Index
5695 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
5698 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
5701 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5703 Append_To
(Conc_Typ_Stmts
,
5704 Make_Procedure_Call_Statement
(Loc
,
5707 Find_Prim_Op
(Etype
(Etype
(Obj
)),
5708 Name_uDisp_Get_Prim_Op_Kind
),
5710 Parameter_Associations
=>
5712 New_Copy_Tree
(Obj
),
5713 New_Reference_To
(S
, Loc
),
5714 New_Reference_To
(C
, Loc
))));
5717 -- if C = POK_Procedure_Entry then
5719 -- elsif C = POK_Task_Entry then
5725 Append_To
(Conc_Typ_Stmts
,
5726 Make_If_Statement
(Loc
,
5730 New_Reference_To
(C
, Loc
),
5732 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
5739 Make_Elsif_Part
(Loc
,
5743 New_Reference_To
(C
, Loc
),
5745 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
)),
5754 -- <dispatching-call>;
5755 -- <triggering-statements>
5757 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
5758 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
5761 -- if K = Ada.Tags.TK_Limited_Tagged then
5768 Make_If_Statement
(Loc
,
5772 New_Reference_To
(K
, Loc
),
5774 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
5783 Make_Block_Statement
(Loc
,
5786 Handled_Statement_Sequence
=>
5787 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
5792 -- Delay triggering statement processing
5795 -- Add a Delay_Block object to the parameter list of the delay
5796 -- procedure to form the parameter list of the Wait entry call.
5799 Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
5801 Pdef
:= Entity
(Name
(Ecall
));
5803 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
5805 New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
5807 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
5809 New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
5811 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
5812 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
5815 Append_To
(Parameter_Associations
(Ecall
),
5816 Make_Attribute_Reference
(Loc
,
5817 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
5818 Attribute_Name
=> Name_Unchecked_Access
));
5820 -- Create the inner block to protect the abortable part
5823 Make_Implicit_Exception_Handler
(Loc
,
5824 Exception_Choices
=>
5825 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
5826 Statements
=> New_List
(
5827 Make_Procedure_Call_Statement
(Loc
,
5828 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)))));
5831 Make_Procedure_Call_Statement
(Loc
,
5832 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
5835 Make_Block_Statement
(Loc
,
5836 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
5837 Handled_Statement_Sequence
=>
5838 Make_Handled_Sequence_Of_Statements
(Loc
,
5839 Statements
=> Astats
),
5840 Has_Created_Identifier
=> True,
5841 Is_Asynchronous_Call_Block
=> True);
5843 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
5846 Make_Implicit_If_Statement
(N
,
5847 Condition
=> Make_Function_Call
(Loc
,
5848 Name
=> Enqueue_Call
,
5849 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
5851 New_List
(Make_Block_Statement
(Loc
,
5852 Handled_Statement_Sequence
=>
5853 Make_Handled_Sequence_Of_Statements
(Loc
,
5854 Statements
=> New_List
(
5855 Make_Implicit_Label_Declaration
(Loc
,
5856 Defining_Identifier
=> Blk_Ent
,
5857 Label_Construct
=> Abortable_Block
),
5859 Exception_Handlers
=> Hdle
)))));
5861 Stmts
:= New_List
(Ecall
);
5863 -- Construct statement sequence for new block
5866 Make_Implicit_If_Statement
(N
,
5867 Condition
=> Make_Function_Call
(Loc
,
5868 Name
=> New_Reference_To
(
5869 RTE
(RE_Timed_Out
), Loc
),
5870 Parameter_Associations
=> New_List
(
5871 Make_Attribute_Reference
(Loc
,
5872 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
5873 Attribute_Name
=> Name_Unchecked_Access
))),
5874 Then_Statements
=> Tstats
));
5876 -- The result is the new block
5878 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
5881 Make_Block_Statement
(Loc
,
5882 Declarations
=> New_List
(
5883 Make_Object_Declaration
(Loc
,
5884 Defining_Identifier
=> Dblock_Ent
,
5885 Aliased_Present
=> True,
5886 Object_Definition
=> New_Reference_To
(
5887 RTE
(RE_Delay_Block
), Loc
))),
5889 Handled_Statement_Sequence
=>
5890 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
5900 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
5901 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
5903 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
5904 Decls
:= Declarations
(Ecall
);
5906 if Is_Protected_Type
(Etype
(Concval
)) then
5908 -- Get the declarations of the block expanded from the entry call
5910 Decl
:= First
(Decls
);
5911 while Present
(Decl
)
5913 (Nkind
(Decl
) /= N_Object_Declaration
5914 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
5915 RE_Communication_Block
))
5920 pragma Assert
(Present
(Decl
));
5921 Cancel_Param
:= Defining_Identifier
(Decl
);
5923 -- Change the mode of the Protected_Entry_Call call
5925 -- Protected_Entry_Call (
5926 -- Object => po._object'Access,
5927 -- E => <entry index>;
5928 -- Uninterpreted_Data => P'Address;
5929 -- Mode => Asynchronous_Call;
5932 Stmt
:= First
(Stmts
);
5934 -- Skip assignments to temporaries created for in-out parameters
5936 -- This makes unwarranted assumptions about the shape of the expanded
5937 -- tree for the call, and should be cleaned up ???
5939 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
5945 Param
:= First
(Parameter_Associations
(Call
));
5946 while Present
(Param
)
5947 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
5952 pragma Assert
(Present
(Param
));
5953 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
5956 -- Append an if statement to execute the abortable part
5959 -- if Enqueued (Bnn) then
5962 Make_Implicit_If_Statement
(N
,
5963 Condition
=> Make_Function_Call
(Loc
,
5964 Name
=> New_Reference_To
(
5965 RTE
(RE_Enqueued
), Loc
),
5966 Parameter_Associations
=> New_List
(
5967 New_Reference_To
(Cancel_Param
, Loc
))),
5968 Then_Statements
=> Astats
));
5971 Make_Block_Statement
(Loc
,
5972 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
5973 Handled_Statement_Sequence
=>
5974 Make_Handled_Sequence_Of_Statements
(Loc
,
5975 Statements
=> Stmts
),
5976 Has_Created_Identifier
=> True,
5977 Is_Asynchronous_Call_Block
=> True);
5979 -- For the VM call Update_Exception instead of Abort_Undefer.
5980 -- See 4jexcept.ads for an explanation.
5982 if VM_Target
= No_VM
then
5983 Target_Undefer
:= RE_Abort_Undefer
;
5985 Target_Undefer
:= RE_Update_Exception
;
5987 New_List
(Make_Function_Call
(Loc
,
5988 Name
=> New_Occurrence_Of
5989 (RTE
(RE_Current_Target_Exception
), Loc
)));
5993 Make_Block_Statement
(Loc
,
5994 Handled_Statement_Sequence
=>
5995 Make_Handled_Sequence_Of_Statements
(Loc
,
5996 Statements
=> New_List
(
5997 Make_Implicit_Label_Declaration
(Loc
,
5998 Defining_Identifier
=> Blk_Ent
,
5999 Label_Construct
=> Abortable_Block
),
6004 Exception_Handlers
=> New_List
(
6005 Make_Implicit_Exception_Handler
(Loc
,
6007 -- when Abort_Signal =>
6008 -- Abort_Undefer.all;
6010 Exception_Choices
=>
6011 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
6012 Statements
=> New_List
(
6013 Make_Procedure_Call_Statement
(Loc
,
6014 Name
=> New_Reference_To
(
6015 RTE
(Target_Undefer
), Loc
),
6016 Parameter_Associations
=> Undefer_Args
)))))),
6018 -- if not Cancelled (Bnn) then
6019 -- triggered statements
6022 Make_Implicit_If_Statement
(N
,
6023 Condition
=> Make_Op_Not
(Loc
,
6025 Make_Function_Call
(Loc
,
6026 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
6027 Parameter_Associations
=> New_List
(
6028 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
6029 Then_Statements
=> Tstats
));
6031 -- Asynchronous task entry call
6038 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
6040 -- Insert declaration of B in declarations of existing block
6043 Make_Object_Declaration
(Loc
,
6044 Defining_Identifier
=> B
,
6045 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
6047 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
6049 -- Insert declaration of C in declarations of existing block
6052 Make_Object_Declaration
(Loc
,
6053 Defining_Identifier
=> Cancel_Param
,
6054 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
6056 -- Remove and save the call to Call_Simple
6058 Stmt
:= First
(Stmts
);
6060 -- Skip assignments to temporaries created for in-out parameters.
6061 -- This makes unwarranted assumptions about the shape of the expanded
6062 -- tree for the call, and should be cleaned up ???
6064 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
6070 -- Create the inner block to protect the abortable part
6073 Make_Implicit_Exception_Handler
(Loc
,
6074 Exception_Choices
=>
6075 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
6078 Make_Procedure_Call_Statement
(Loc
,
6079 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)))));
6082 Make_Procedure_Call_Statement
(Loc
,
6083 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
6086 Make_Block_Statement
(Loc
,
6087 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
6088 Handled_Statement_Sequence
=>
6089 Make_Handled_Sequence_Of_Statements
(Loc
,
6090 Statements
=> Astats
),
6091 Has_Created_Identifier
=> True,
6092 Is_Asynchronous_Call_Block
=> True);
6095 Make_Block_Statement
(Loc
,
6096 Handled_Statement_Sequence
=>
6097 Make_Handled_Sequence_Of_Statements
(Loc
,
6098 Statements
=> New_List
(
6099 Make_Implicit_Label_Declaration
(Loc
,
6100 Defining_Identifier
=>
6105 Exception_Handlers
=> Hdle
)));
6107 -- Create new call statement
6109 Params
:= Parameter_Associations
(Call
);
6112 New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
6114 New_Reference_To
(B
, Loc
));
6117 Make_Procedure_Call_Statement
(Loc
,
6119 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
6120 Parameter_Associations
=> Params
));
6122 -- Construct statement sequence for new block
6125 Make_Implicit_If_Statement
(N
,
6128 New_Reference_To
(Cancel_Param
, Loc
)),
6129 Then_Statements
=> Tstats
));
6131 -- Protected the call against abort
6134 Make_Procedure_Call_Statement
(Loc
,
6135 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
6136 Parameter_Associations
=> Empty_List
));
6139 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
6141 -- The result is the new block
6144 Make_Block_Statement
(Loc
,
6145 Declarations
=> Decls
,
6146 Handled_Statement_Sequence
=>
6147 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6150 end Expand_N_Asynchronous_Select
;
6152 -------------------------------------
6153 -- Expand_N_Conditional_Entry_Call --
6154 -------------------------------------
6156 -- The conditional task entry call is converted to a call to
6161 -- P : parms := (parm, parm, parm);
6165 -- (<acceptor-task>, -- Acceptor
6166 -- <entry-index>, -- E
6167 -- P'Address, -- Uninterpreted_Data
6168 -- Conditional_Call, -- Mode
6169 -- B); -- Rendezvous_Successful
6174 -- normal-statements
6180 -- For a description of the use of P and the assignments after the call,
6181 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6182 -- conditional entry call has already been expanded (by the Expand_N_Entry
6183 -- _Call_Statement procedure) as follows:
6186 -- P : parms := (parm, parm, parm);
6188 -- ... info for in-out parameters
6189 -- Call_Simple (acceptor-task, entry-index, P'Address);
6195 -- so the task at hand is to convert the latter expansion into the former
6197 -- The conditional protected entry call is converted to a call to
6198 -- Protected_Entry_Call:
6201 -- P : parms := (parm, parm, parm);
6202 -- Bnn : Communications_Block;
6205 -- Protected_Entry_Call
6206 -- (po._object'Access, -- Object
6207 -- <entry index>, -- E
6208 -- P'Address, -- Uninterpreted_Data
6209 -- Conditional_Call, -- Mode
6214 -- if Cancelled (Bnn) then
6217 -- normal-statements
6221 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6225 -- B : Boolean := False;
6226 -- C : Ada.Tags.Prim_Op_Kind;
6227 -- K : Ada.Tags.Tagged_Kind :=
6228 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6229 -- P : Parameters := (Param1 .. ParamN);
6233 -- if K = Ada.Tags.TK_Limited_Tagged then
6234 -- <dispatching-call>;
6235 -- <triggering-statements>
6239 -- Ada.Tags.Get_Offset_Index
6240 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6242 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6244 -- if C = POK_Protected_Entry
6245 -- or else C = POK_Task_Entry
6247 -- Param1 := P.Param1;
6249 -- ParamN := P.ParamN;
6253 -- if C = POK_Procedure
6254 -- or else C = POK_Protected_Procedure
6255 -- or else C = POK_Task_Procedure
6257 -- <dispatching-call>;
6260 -- <triggering-statements>
6262 -- <else-statements>
6267 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
6268 Loc
: constant Source_Ptr
:= Sloc
(N
);
6269 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
6270 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
6273 Blk_Typ
: Entity_Id
;
6275 Call_Ent
: Entity_Id
;
6276 Conc_Typ_Stmts
: List_Id
;
6280 Lim_Typ_Stmts
: List_Id
;
6287 Transient_Blk
: Node_Id
;
6290 B
: Entity_Id
; -- Call status flag
6291 C
: Entity_Id
; -- Call kind
6292 K
: Entity_Id
; -- Tagged kind
6293 P
: Entity_Id
; -- Parameter block
6294 S
: Entity_Id
; -- Primitive operation slot
6297 if Ada_Version
>= Ada_05
6298 and then Nkind
(Blk
) = N_Procedure_Call_Statement
6300 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
6305 -- Call status flag processing, generate:
6306 -- B : Boolean := False;
6308 B
:= Build_B
(Loc
, Decls
);
6310 -- Call kind processing, generate:
6311 -- C : Ada.Tags.Prim_Op_Kind;
6313 C
:= Build_C
(Loc
, Decls
);
6315 -- Tagged kind processing, generate:
6316 -- K : Ada.Tags.Tagged_Kind :=
6317 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6319 K
:= Build_K
(Loc
, Decls
, Obj
);
6321 -- Parameter block processing
6323 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
6324 P
:= Parameter_Block_Pack
6325 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6327 -- Dispatch table slot processing, generate:
6330 S
:= Build_S
(Loc
, Decls
);
6333 -- S := Ada.Tags.Get_Offset_Index
6334 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6337 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
6340 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6342 Append_To
(Conc_Typ_Stmts
,
6343 Make_Procedure_Call_Statement
(Loc
,
6346 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6347 Name_uDisp_Conditional_Select
),
6349 Parameter_Associations
=>
6351 New_Copy_Tree
(Obj
), -- <object>
6352 New_Reference_To
(S
, Loc
), -- S
6353 Make_Attribute_Reference
(Loc
, -- P'Address
6355 New_Reference_To
(P
, Loc
),
6358 New_Reference_To
(C
, Loc
), -- C
6359 New_Reference_To
(B
, Loc
)))); -- B
6362 -- if C = POK_Protected_Entry
6363 -- or else C = POK_Task_Entry
6365 -- Param1 := P.Param1;
6367 -- ParamN := P.ParamN;
6370 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6372 -- Generate the if statement only when the packed parameters need
6373 -- explicit assignments to their corresponding actuals.
6375 if Present
(Unpack
) then
6376 Append_To
(Conc_Typ_Stmts
,
6377 Make_If_Statement
(Loc
,
6384 New_Reference_To
(C
, Loc
),
6386 New_Reference_To
(RTE
(
6387 RE_POK_Protected_Entry
), Loc
)),
6391 New_Reference_To
(C
, Loc
),
6393 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
6401 -- if C = POK_Procedure
6402 -- or else C = POK_Protected_Procedure
6403 -- or else C = POK_Task_Procedure
6405 -- <dispatching-call>
6407 -- <normal-statements>
6409 -- <else-statements>
6412 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
6414 Prepend_To
(N_Stats
,
6415 Make_If_Statement
(Loc
,
6421 New_Reference_To
(C
, Loc
),
6423 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
6430 New_Reference_To
(C
, Loc
),
6432 New_Reference_To
(RTE
(
6433 RE_POK_Protected_Procedure
), Loc
)),
6438 New_Reference_To
(C
, Loc
),
6440 New_Reference_To
(RTE
(
6441 RE_POK_Task_Procedure
), Loc
)))),
6446 Append_To
(Conc_Typ_Stmts
,
6447 Make_If_Statement
(Loc
,
6448 Condition
=> New_Reference_To
(B
, Loc
),
6449 Then_Statements
=> N_Stats
,
6450 Else_Statements
=> Else_Statements
(N
)));
6453 -- <dispatching-call>;
6454 -- <triggering-statements>
6456 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
6457 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
6460 -- if K = Ada.Tags.TK_Limited_Tagged then
6467 Make_If_Statement
(Loc
,
6471 New_Reference_To
(K
, Loc
),
6473 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
6482 Make_Block_Statement
(Loc
,
6485 Handled_Statement_Sequence
=>
6486 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6488 -- As described above, The entry alternative is transformed into a
6489 -- block that contains the gnulli call, and possibly assignment
6490 -- statements for in-out parameters. The gnulli call may itself be
6491 -- rewritten into a transient block if some unconstrained parameters
6492 -- require it. We need to retrieve the call to complete its parameter
6497 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
6499 if Present
(Transient_Blk
)
6500 and then Nkind
(Transient_Blk
) = N_Block_Statement
6502 Blk
:= Transient_Blk
;
6505 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
6506 Stmt
:= First
(Stmts
);
6507 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
6512 Params
:= Parameter_Associations
(Call
);
6514 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
6516 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6518 Param
:= First
(Params
);
6519 while Present
(Param
)
6520 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
6525 pragma Assert
(Present
(Param
));
6526 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
6530 -- Find the Communication_Block parameter for the call to the
6531 -- Cancelled function.
6533 Decl
:= First
(Declarations
(Blk
));
6534 while Present
(Decl
)
6535 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
6536 RE_Communication_Block
)
6541 -- Add an if statement to execute the else part if the call
6542 -- does not succeed (as indicated by the Cancelled predicate).
6545 Make_Implicit_If_Statement
(N
,
6546 Condition
=> Make_Function_Call
(Loc
,
6547 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
6548 Parameter_Associations
=> New_List
(
6549 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
6550 Then_Statements
=> Else_Statements
(N
),
6551 Else_Statements
=> Statements
(Alt
)));
6554 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
6556 -- Insert declaration of B in declarations of existing block
6558 if No
(Declarations
(Blk
)) then
6559 Set_Declarations
(Blk
, New_List
);
6562 Prepend_To
(Declarations
(Blk
),
6563 Make_Object_Declaration
(Loc
,
6564 Defining_Identifier
=> B
,
6565 Object_Definition
=>
6566 New_Reference_To
(Standard_Boolean
, Loc
)));
6568 -- Create new call statement
6571 New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
6572 Append_To
(Params
, New_Reference_To
(B
, Loc
));
6575 Make_Procedure_Call_Statement
(Loc
,
6576 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
6577 Parameter_Associations
=> Params
));
6579 -- Construct statement sequence for new block
6582 Make_Implicit_If_Statement
(N
,
6583 Condition
=> New_Reference_To
(B
, Loc
),
6584 Then_Statements
=> Statements
(Alt
),
6585 Else_Statements
=> Else_Statements
(N
)));
6588 -- The result is the new block
6591 Make_Block_Statement
(Loc
,
6592 Declarations
=> Declarations
(Blk
),
6593 Handled_Statement_Sequence
=>
6594 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6598 end Expand_N_Conditional_Entry_Call
;
6600 ---------------------------------------
6601 -- Expand_N_Delay_Relative_Statement --
6602 ---------------------------------------
6604 -- Delay statement is implemented as a procedure call to Delay_For
6605 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6606 -- simple delays imposed by the use of Protected Objects.
6608 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
6609 Loc
: constant Source_Ptr
:= Sloc
(N
);
6612 Make_Procedure_Call_Statement
(Loc
,
6613 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
6614 Parameter_Associations
=> New_List
(Expression
(N
))));
6616 end Expand_N_Delay_Relative_Statement
;
6618 ------------------------------------
6619 -- Expand_N_Delay_Until_Statement --
6620 ------------------------------------
6622 -- Delay Until statement is implemented as a procedure call to
6623 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6625 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
6626 Loc
: constant Source_Ptr
:= Sloc
(N
);
6630 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
6631 Typ
:= RTE
(RO_CA_Delay_Until
);
6633 Typ
:= RTE
(RO_RT_Delay_Until
);
6637 Make_Procedure_Call_Statement
(Loc
,
6638 Name
=> New_Reference_To
(Typ
, Loc
),
6639 Parameter_Associations
=> New_List
(Expression
(N
))));
6642 end Expand_N_Delay_Until_Statement
;
6644 -------------------------
6645 -- Expand_N_Entry_Body --
6646 -------------------------
6648 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
6650 -- Associate discriminals with the next protected operation body to be
6653 if Present
(Next_Protected_Operation
(N
)) then
6654 Set_Discriminals
(Parent
(Current_Scope
));
6656 end Expand_N_Entry_Body
;
6658 -----------------------------------
6659 -- Expand_N_Entry_Call_Statement --
6660 -----------------------------------
6662 -- An entry call is expanded into GNARLI calls to implement a simple entry
6663 -- call (see Build_Simple_Entry_Call).
6665 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
6671 if No_Run_Time_Mode
then
6672 Error_Msg_CRT
("entry call", N
);
6676 -- If this entry call is part of an asynchronous select, don't expand it
6677 -- here; it will be expanded with the select statement. Don't expand
6678 -- timed entry calls either, as they are translated into asynchronous
6681 -- ??? This whole approach is questionable; it may be better to go back
6682 -- to allowing the expansion to take place and then attempting to fix it
6683 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6684 -- whether the expanded call is on a task or protected entry.
6686 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
6687 or else N
/= Triggering_Statement
(Parent
(N
)))
6688 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
6689 or else N
/= Entry_Call_Statement
(Parent
(N
))
6690 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
6692 Extract_Entry
(N
, Concval
, Ename
, Index
);
6693 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
6695 end Expand_N_Entry_Call_Statement
;
6697 --------------------------------
6698 -- Expand_N_Entry_Declaration --
6699 --------------------------------
6701 -- If there are parameters, then first, each of the formals is marked by
6702 -- setting Is_Entry_Formal. Next a record type is built which is used to
6703 -- hold the parameter values. The name of this record type is entryP where
6704 -- entry is the name of the entry, with an additional corresponding access
6705 -- type called entryPA. The record type has matching components for each
6706 -- formal (the component names are the same as the formal names). For
6707 -- elementary types, the component type matches the formal type. For
6708 -- composite types, an access type is declared (with the name formalA)
6709 -- which designates the formal type, and the type of the component is this
6710 -- access type. Finally the Entry_Component of each formal is set to
6711 -- reference the corresponding record component.
6713 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
6714 Loc
: constant Source_Ptr
:= Sloc
(N
);
6715 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
6716 Components
: List_Id
;
6719 Last_Decl
: Node_Id
;
6720 Component
: Entity_Id
;
6723 Rec_Ent
: Entity_Id
;
6724 Acc_Ent
: Entity_Id
;
6727 Formal
:= First_Formal
(Entry_Ent
);
6730 -- Most processing is done only if parameters are present
6732 if Present
(Formal
) then
6733 Components
:= New_List
;
6735 -- Loop through formals
6737 while Present
(Formal
) loop
6738 Set_Is_Entry_Formal
(Formal
);
6740 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
6741 Set_Entry_Component
(Formal
, Component
);
6742 Set_Entry_Formal
(Component
, Formal
);
6743 Ftype
:= Etype
(Formal
);
6745 -- Declare new access type and then append
6748 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
6751 Make_Full_Type_Declaration
(Loc
,
6752 Defining_Identifier
=> Ctype
,
6754 Make_Access_To_Object_Definition
(Loc
,
6755 All_Present
=> True,
6756 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
6757 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
6759 Insert_After
(Last_Decl
, Decl
);
6762 Append_To
(Components
,
6763 Make_Component_Declaration
(Loc
,
6764 Defining_Identifier
=> Component
,
6765 Component_Definition
=>
6766 Make_Component_Definition
(Loc
,
6767 Aliased_Present
=> False,
6768 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
6770 Next_Formal_With_Extras
(Formal
);
6773 -- Create the Entry_Parameter_Record declaration
6776 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
6779 Make_Full_Type_Declaration
(Loc
,
6780 Defining_Identifier
=> Rec_Ent
,
6782 Make_Record_Definition
(Loc
,
6784 Make_Component_List
(Loc
,
6785 Component_Items
=> Components
)));
6787 Insert_After
(Last_Decl
, Decl
);
6790 -- Construct and link in the corresponding access type
6793 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
6795 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
6798 Make_Full_Type_Declaration
(Loc
,
6799 Defining_Identifier
=> Acc_Ent
,
6801 Make_Access_To_Object_Definition
(Loc
,
6802 All_Present
=> True,
6803 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
6805 Insert_After
(Last_Decl
, Decl
);
6808 end Expand_N_Entry_Declaration
;
6810 -----------------------------
6811 -- Expand_N_Protected_Body --
6812 -----------------------------
6814 -- Protected bodies are expanded to the completion of the subprograms
6815 -- created for the corresponding protected type. These are a protected and
6816 -- unprotected version of each protected subprogram in the object, a
6817 -- function to calculate each entry barrier, and a procedure to execute the
6818 -- sequence of statements of each protected entry body. For example, for
6819 -- protected type ptype:
6822 -- (O : System.Address;
6823 -- E : Protected_Entry_Index)
6826 -- <discriminant renamings>
6827 -- <private object renamings>
6829 -- return <barrier expression>;
6832 -- procedure pprocN (_object : in out poV;...) is
6833 -- <discriminant renamings>
6834 -- <private object renamings>
6836 -- <sequence of statements>
6839 -- procedure pprocP (_object : in out poV;...) is
6840 -- procedure _clean is
6843 -- ptypeS (_object, Pn);
6844 -- Unlock (_object._object'Access);
6845 -- Abort_Undefer.all;
6850 -- Lock (_object._object'Access);
6851 -- pprocN (_object;...);
6856 -- function pfuncN (_object : poV;...) return Return_Type is
6857 -- <discriminant renamings>
6858 -- <private object renamings>
6860 -- <sequence of statements>
6863 -- function pfuncP (_object : poV) return Return_Type is
6864 -- procedure _clean is
6866 -- Unlock (_object._object'Access);
6867 -- Abort_Undefer.all;
6872 -- Lock (_object._object'Access);
6873 -- return pfuncN (_object);
6880 -- (O : System.Address;
6881 -- P : System.Address;
6882 -- E : Protected_Entry_Index)
6884 -- <discriminant renamings>
6885 -- <private object renamings>
6886 -- type poVP is access poV;
6887 -- _Object : ptVP := ptVP!(O);
6891 -- <statement sequence>
6892 -- Complete_Entry_Body (_Object._Object);
6894 -- when all others =>
6895 -- Exceptional_Complete_Entry_Body (
6896 -- _Object._Object, Get_GNAT_Exception);
6900 -- The type poV is the record created for the protected type to hold
6901 -- the state of the protected object.
6903 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
6904 Loc
: constant Source_Ptr
:= Sloc
(N
);
6905 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
6909 Disp_Op_Body
: Node_Id
;
6910 New_Op_Body
: Node_Id
;
6911 Current_Node
: Node_Id
;
6912 Num_Entries
: Natural := 0;
6914 function Build_Dispatching_Subprogram_Body
6917 Prot_Bod
: Node_Id
) return Node_Id
;
6918 -- Build a dispatching version of the protected subprogram body. The
6919 -- newly generated subprogram contains a call to the original protected
6920 -- body. The following code is generated:
6922 -- function <protected-function-name> (Param1 .. ParamN) return
6925 -- return <protected-function-name>P (Param1 .. ParamN);
6926 -- end <protected-function-name>;
6930 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
6932 -- <protected-procedure-name>P (Param1 .. ParamN);
6933 -- end <protected-procedure-name>
6935 ---------------------------------------
6936 -- Build_Dispatching_Subprogram_Body --
6937 ---------------------------------------
6939 function Build_Dispatching_Subprogram_Body
6942 Prot_Bod
: Node_Id
) return Node_Id
6944 Loc
: constant Source_Ptr
:= Sloc
(N
);
6951 -- Generate a specification without a letter suffix in order to
6952 -- override an interface function or procedure.
6955 Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
6957 -- The formal parameters become the actuals of the protected
6958 -- function or procedure call.
6960 Actuals
:= New_List
;
6961 Formal
:= First
(Parameter_Specifications
(Spec
));
6962 while Present
(Formal
) loop
6964 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
6969 if Nkind
(Spec
) = N_Procedure_Specification
then
6972 Make_Procedure_Call_Statement
(Loc
,
6974 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
6975 Parameter_Associations
=> Actuals
));
6977 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
6981 Make_Simple_Return_Statement
(Loc
,
6983 Make_Function_Call
(Loc
,
6985 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
6986 Parameter_Associations
=> Actuals
)));
6990 Make_Subprogram_Body
(Loc
,
6991 Declarations
=> Empty_List
,
6992 Specification
=> Spec
,
6993 Handled_Statement_Sequence
=>
6994 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
6995 end Build_Dispatching_Subprogram_Body
;
6997 -- Start of processing for Expand_N_Protected_Body
7000 if No_Run_Time_Mode
then
7001 Error_Msg_CRT
("protected body", N
);
7005 if Nkind
(Parent
(N
)) = N_Subunit
then
7007 -- This is the proper body corresponding to a stub. The declarations
7008 -- must be inserted at the point of the stub, which is in the decla-
7009 -- rative part of the parent unit.
7011 Current_Node
:= Corresponding_Stub
(Parent
(N
));
7017 Op_Body
:= First
(Declarations
(N
));
7019 -- The protected body is replaced with the bodies of its
7020 -- protected operations, and the declarations for internal objects
7021 -- that may have been created for entry family bounds.
7023 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
7026 while Present
(Op_Body
) loop
7027 case Nkind
(Op_Body
) is
7028 when N_Subprogram_Declaration
=>
7031 when N_Subprogram_Body
=>
7033 -- Exclude functions created to analyze defaults
7035 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
7036 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
7039 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
7041 -- Propagate the finalization chain to the new body.
7042 -- In the unlikely event that the subprogram contains a
7043 -- declaration or allocator for an object that requires
7044 -- finalization, the corresponding chain is created when
7045 -- analyzing the body, and attached to its entity. This
7046 -- entity is not further elaborated, and so the chain
7047 -- properly belongs to the newly created subprogram body.
7050 (Finalization_Chain_Entity
(Defining_Entity
(Op_Body
)))
7052 Set_Finalization_Chain_Entity
7053 (Protected_Body_Subprogram
7054 (Corresponding_Spec
(Op_Body
)),
7055 Finalization_Chain_Entity
(Defining_Entity
(Op_Body
)));
7057 (Handled_Statement_Sequence
(New_Op_Body
), False);
7060 Insert_After
(Current_Node
, New_Op_Body
);
7061 Current_Node
:= New_Op_Body
;
7062 Analyze
(New_Op_Body
);
7064 -- Build the corresponding protected operation. It may
7065 -- appear that this is needed only if this is a visible
7066 -- operation of the type, or if it is an interrupt handler,
7067 -- and this was the strategy used previously in GNAT.
7068 -- However, the operation may be exported through a
7069 -- 'Access to an external caller. This is the common idiom
7070 -- in code that uses the Ada 2005 Timing_Events package
7071 -- As a result we need to produce the protected body for
7072 -- both visible and private operations.
7074 if Present
(Corresponding_Spec
(Op_Body
)) then
7076 Unit_Declaration_Node
(Corresponding_Spec
(Op_Body
));
7078 if Nkind
(Parent
(Op_Decl
)) =
7079 N_Protected_Definition
7082 Build_Protected_Subprogram_Body
(
7083 Op_Body
, Pid
, Specification
(New_Op_Body
));
7085 Insert_After
(Current_Node
, New_Op_Body
);
7086 Analyze
(New_Op_Body
);
7088 Current_Node
:= New_Op_Body
;
7090 -- Generate an overriding primitive operation body for
7091 -- this subprogram if the protected type implements
7094 if Ada_Version
>= Ada_05
7095 and then Present
(Interfaces
(
7096 Corresponding_Record_Type
(Pid
)))
7099 Build_Dispatching_Subprogram_Body
(
7100 Op_Body
, Pid
, New_Op_Body
);
7102 Insert_After
(Current_Node
, Disp_Op_Body
);
7103 Analyze
(Disp_Op_Body
);
7105 Current_Node
:= Disp_Op_Body
;
7111 when N_Entry_Body
=>
7112 Op_Id
:= Defining_Identifier
(Op_Body
);
7113 Num_Entries
:= Num_Entries
+ 1;
7115 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
7117 Insert_After
(Current_Node
, New_Op_Body
);
7118 Current_Node
:= New_Op_Body
;
7119 Analyze
(New_Op_Body
);
7121 when N_Implicit_Label_Declaration
=>
7124 when N_Itype_Reference
=>
7125 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
7127 when N_Freeze_Entity
=>
7128 New_Op_Body
:= New_Copy
(Op_Body
);
7130 if Present
(Entity
(Op_Body
))
7131 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
7133 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
7136 Insert_After
(Current_Node
, New_Op_Body
);
7137 Current_Node
:= New_Op_Body
;
7138 Analyze
(New_Op_Body
);
7141 New_Op_Body
:= New_Copy
(Op_Body
);
7142 Insert_After
(Current_Node
, New_Op_Body
);
7143 Current_Node
:= New_Op_Body
;
7144 Analyze
(New_Op_Body
);
7146 when N_Object_Declaration
=>
7147 pragma Assert
(not Comes_From_Source
(Op_Body
));
7148 New_Op_Body
:= New_Copy
(Op_Body
);
7149 Insert_After
(Current_Node
, New_Op_Body
);
7150 Current_Node
:= New_Op_Body
;
7151 Analyze
(New_Op_Body
);
7154 raise Program_Error
;
7161 -- Finally, create the body of the function that maps an entry index
7162 -- into the corresponding body index, except when there is no entry,
7163 -- or in a ravenscar-like profile.
7165 if Corresponding_Runtime_Package
(Pid
) =
7166 System_Tasking_Protected_Objects_Entries
7168 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
7169 Insert_After
(Current_Node
, New_Op_Body
);
7170 Current_Node
:= New_Op_Body
;
7171 Analyze
(New_Op_Body
);
7174 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
7175 -- the protected body. At this point the entry specs have been created,
7176 -- frozen and included in the dispatch table for the protected type.
7178 pragma Assert
(Present
(Corresponding_Record_Type
(Pid
)));
7180 if Ada_Version
>= Ada_05
7181 and then Present
(Protected_Definition
(Parent
(Pid
)))
7182 and then Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
7185 Vis_Decl
: Node_Id
:=
7186 First
(Visible_Declarations
7187 (Protected_Definition
(Parent
(Pid
))));
7188 Wrap_Body
: Node_Id
;
7191 -- Examine the visible declarations of the protected type, looking
7192 -- for an entry declaration. We do not consider entry families
7193 -- since they cannot have dispatching operations, thus they do not
7194 -- need entry wrappers.
7196 while Present
(Vis_Decl
) loop
7197 if Nkind
(Vis_Decl
) = N_Entry_Declaration
then
7199 Build_Wrapper_Body
(Loc
,
7200 Proc_Nam
=> Defining_Identifier
(Vis_Decl
),
7201 Obj_Typ
=> Corresponding_Record_Type
(Pid
),
7202 Formals
=> Parameter_Specifications
(Vis_Decl
));
7204 if Wrap_Body
/= Empty
then
7205 Insert_After
(Current_Node
, Wrap_Body
);
7206 Current_Node
:= Wrap_Body
;
7208 Analyze
(Wrap_Body
);
7211 elsif Nkind
(Vis_Decl
) = N_Subprogram_Declaration
then
7213 Build_Wrapper_Body
(Loc
,
7214 Proc_Nam
=> Defining_Unit_Name
7215 (Specification
(Vis_Decl
)),
7216 Obj_Typ
=> Corresponding_Record_Type
(Pid
),
7217 Formals
=> Parameter_Specifications
7218 (Specification
(Vis_Decl
)));
7220 if Wrap_Body
/= Empty
then
7221 Insert_After
(Current_Node
, Wrap_Body
);
7222 Current_Node
:= Wrap_Body
;
7224 Analyze
(Wrap_Body
);
7232 end Expand_N_Protected_Body
;
7234 -----------------------------------------
7235 -- Expand_N_Protected_Type_Declaration --
7236 -----------------------------------------
7238 -- First we create a corresponding record type declaration used to
7239 -- represent values of this protected type.
7240 -- The general form of this type declaration is
7242 -- type poV (discriminants) is record
7243 -- _Object : aliased <kind>Protection
7244 -- [(<entry count> [, <handler count>])];
7245 -- [entry_family : array (bounds) of Void;]
7246 -- <private data fields>
7249 -- The discriminants are present only if the corresponding protected type
7250 -- has discriminants, and they exactly mirror the protected type
7251 -- discriminants. The private data fields similarly mirror the private
7252 -- declarations of the protected type.
7254 -- The Object field is always present. It contains RTS specific data used
7255 -- to control the protected object. It is declared as Aliased so that it
7256 -- can be passed as a pointer to the RTS. This allows the protected record
7257 -- to be referenced within RTS data structures. An appropriate Protection
7258 -- type and discriminant are generated.
7260 -- The Service field is present for protected objects with entries. It
7261 -- contains sufficient information to allow the entry service procedure for
7262 -- this object to be called when the object is not known till runtime.
7264 -- One entry_family component is present for each entry family in the
7265 -- task definition (see Expand_N_Task_Type_Declaration).
7267 -- When a protected object is declared, an instance of the protected type
7268 -- value record is created. The elaboration of this declaration creates the
7269 -- correct bounds for the entry families, and also evaluates the priority
7270 -- expression if needed. The initialization routine for the protected type
7271 -- itself then calls Initialize_Protection with appropriate parameters to
7272 -- initialize the value of the Task_Id field. Install_Handlers may be also
7273 -- called if a pragma Attach_Handler applies.
7275 -- Note: this record is passed to the subprograms created by the expansion
7276 -- of protected subprograms and entries. It is an in parameter to protected
7277 -- functions and an in out parameter to procedures and entry bodies. The
7278 -- Entity_Id for this created record type is placed in the
7279 -- Corresponding_Record_Type field of the associated protected type entity.
7281 -- Next we create a procedure specifications for protected subprograms and
7282 -- entry bodies. For each protected subprograms two subprograms are
7283 -- created, an unprotected and a protected version. The unprotected version
7284 -- is called from within other operations of the same protected object.
7286 -- We also build the call to register the procedure if a pragma
7287 -- Interrupt_Handler applies.
7289 -- A single subprogram is created to service all entry bodies; it has an
7290 -- additional boolean out parameter indicating that the previous entry call
7291 -- made by the current task was serviced immediately, i.e. not by proxy.
7292 -- The O parameter contains a pointer to a record object of the type
7293 -- described above. An untyped interface is used here to allow this
7294 -- procedure to be called in places where the type of the object to be
7295 -- serviced is not known. This must be done, for example, when a call that
7296 -- may have been requeued is cancelled; the corresponding object must be
7297 -- serviced, but which object that is not known till runtime.
7300 -- (O : System.Address; P : out Boolean);
7301 -- procedure pprocN (_object : in out poV);
7302 -- procedure pproc (_object : in out poV);
7303 -- function pfuncN (_object : poV);
7304 -- function pfunc (_object : poV);
7307 -- Note that this must come after the record type declaration, since
7308 -- the specs refer to this type.
7310 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
7311 Loc
: constant Source_Ptr
:= Sloc
(N
);
7312 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
7314 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
7315 -- This contains two lists; one for visible and one for private decls
7319 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
7323 Comp_Id
: Entity_Id
;
7325 Current_Node
: Node_Id
:= N
;
7326 Bdef
: Entity_Id
:= Empty
; -- avoid uninit warning
7327 Edef
: Entity_Id
:= Empty
; -- avoid uninit warning
7328 Entries_Aggr
: Node_Id
;
7329 Body_Id
: Entity_Id
;
7332 Object_Comp
: Node_Id
;
7334 procedure Register_Handler
;
7335 -- For a protected operation that is an interrupt handler, add the
7336 -- freeze action that will register it as such.
7338 ----------------------
7339 -- Register_Handler --
7340 ----------------------
7342 procedure Register_Handler
is
7344 -- All semantic checks already done in Sem_Prag
7346 Prot_Proc
: constant Entity_Id
:=
7348 (Specification
(Current_Node
));
7350 Proc_Address
: constant Node_Id
:=
7351 Make_Attribute_Reference
(Loc
,
7352 Prefix
=> New_Reference_To
(Prot_Proc
, Loc
),
7353 Attribute_Name
=> Name_Address
);
7355 RTS_Call
: constant Entity_Id
:=
7356 Make_Procedure_Call_Statement
(Loc
,
7359 RTE
(RE_Register_Interrupt_Handler
), Loc
),
7360 Parameter_Associations
=>
7361 New_List
(Proc_Address
));
7363 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
7364 end Register_Handler
;
7366 -- Start of processing for Expand_N_Protected_Type_Declaration
7369 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
7372 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
7375 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
7377 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7378 -- of implemented interfaces.
7380 Set_Interface_List
(Type_Definition
(Rec_Decl
), Interface_List
(N
));
7382 Qualify_Entity_Names
(N
);
7384 -- If the type has discriminants, their occurrences in the declaration
7385 -- have been replaced by the corresponding discriminals. For components
7386 -- that are constrained by discriminants, their homologues in the
7387 -- corresponding record type must refer to the discriminants of that
7388 -- record, so we must apply a new renaming to subtypes_indications:
7390 -- protected discriminant => discriminal => record discriminant
7392 -- This replacement is not applied to default expressions, for which
7393 -- the discriminal is correct.
7395 if Has_Discriminants
(Prot_Typ
) then
7401 Disc
:= First_Discriminant
(Prot_Typ
);
7402 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
7403 while Present
(Disc
) loop
7404 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
7405 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
7406 Next_Discriminant
(Disc
);
7412 -- Fill in the component declarations
7414 -- Add components for entry families. For each entry family, create an
7415 -- anonymous type declaration with the same size, and analyze the type.
7417 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
7419 -- Prepend the _Object field with the right type to the component list.
7420 -- We need to compute the number of entries, and in some cases the
7421 -- number of Attach_Handler pragmas.
7425 Num_Attach_Handler
: Int
:= 0;
7426 Protection_Subtype
: Node_Id
;
7427 Entry_Count_Expr
: constant Node_Id
:=
7428 Build_Entry_Count_Expression
7429 (Prot_Typ
, Cdecls
, Loc
);
7432 -- Could this be simplified using Corresponding_Runtime_Package???
7434 if Has_Attach_Handler
(Prot_Typ
) then
7435 Ritem
:= First_Rep_Item
(Prot_Typ
);
7436 while Present
(Ritem
) loop
7437 if Nkind
(Ritem
) = N_Pragma
7438 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
7440 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
7443 Next_Rep_Item
(Ritem
);
7446 if Restricted_Profile
then
7447 if Has_Entries
(Prot_Typ
) then
7448 Protection_Subtype
:=
7449 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
7451 Protection_Subtype
:=
7452 New_Reference_To
(RTE
(RE_Protection
), Loc
);
7455 Protection_Subtype
:=
7456 Make_Subtype_Indication
7460 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
7462 Make_Index_Or_Discriminant_Constraint
(
7464 Constraints
=> New_List
(
7466 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
7469 elsif Has_Interrupt_Handler
(Prot_Typ
) then
7470 Protection_Subtype
:=
7471 Make_Subtype_Indication
(
7473 Subtype_Mark
=> New_Reference_To
7474 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
7476 Make_Index_Or_Discriminant_Constraint
(
7478 Constraints
=> New_List
(Entry_Count_Expr
)));
7480 -- Type has explicit entries or generated primitive entry wrappers
7482 elsif Has_Entries
(Prot_Typ
)
7483 or else (Ada_Version
>= Ada_05
7484 and then Present
(Interface_List
(N
)))
7486 case Corresponding_Runtime_Package
(Prot_Typ
) is
7487 when System_Tasking_Protected_Objects_Entries
=>
7488 Protection_Subtype
:=
7489 Make_Subtype_Indication
(Loc
,
7491 New_Reference_To
(RTE
(RE_Protection_Entries
), Loc
),
7493 Make_Index_Or_Discriminant_Constraint
(
7495 Constraints
=> New_List
(Entry_Count_Expr
)));
7497 when System_Tasking_Protected_Objects_Single_Entry
=>
7498 Protection_Subtype
:=
7499 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
7502 raise Program_Error
;
7506 Protection_Subtype
:= New_Reference_To
(RTE
(RE_Protection
), Loc
);
7510 Make_Component_Declaration
(Loc
,
7511 Defining_Identifier
=>
7512 Make_Defining_Identifier
(Loc
, Name_uObject
),
7513 Component_Definition
=>
7514 Make_Component_Definition
(Loc
,
7515 Aliased_Present
=> True,
7516 Subtype_Indication
=> Protection_Subtype
));
7519 pragma Assert
(Present
(Pdef
));
7521 -- Add private field components
7523 if Present
(Private_Declarations
(Pdef
)) then
7524 Priv
:= First
(Private_Declarations
(Pdef
));
7526 while Present
(Priv
) loop
7528 if Nkind
(Priv
) = N_Component_Declaration
then
7530 -- The component definition consists of a subtype indication,
7531 -- or (in Ada 2005) an access definition. Make a copy of the
7532 -- proper definition.
7535 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
7536 Pent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
7540 if Present
(Subtype_Indication
(Old_Comp
)) then
7542 Make_Component_Definition
(Sloc
(Pent
),
7543 Aliased_Present
=> False,
7544 Subtype_Indication
=>
7545 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
7549 Make_Component_Definition
(Sloc
(Pent
),
7550 Aliased_Present
=> False,
7551 Access_Definition
=>
7552 New_Copy_Tree
(Access_Definition
(Old_Comp
),
7557 Make_Component_Declaration
(Loc
,
7558 Defining_Identifier
=>
7559 Make_Defining_Identifier
(Sloc
(Pent
), Chars
(Pent
)),
7560 Component_Definition
=> New_Comp
,
7561 Expression
=> Expression
(Priv
));
7563 Append_To
(Cdecls
, New_Priv
);
7566 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
7568 -- Make the unprotected version of the subprogram available
7569 -- for expansion of intra object calls. There is need for
7570 -- a protected version only if the subprogram is an interrupt
7571 -- handler, otherwise this operation can only be called from
7575 Make_Subprogram_Declaration
(Loc
,
7577 Build_Protected_Sub_Specification
7578 (Priv
, Prot_Typ
, Unprotected_Mode
));
7580 Insert_After
(Current_Node
, Sub
);
7583 Set_Protected_Body_Subprogram
7584 (Defining_Unit_Name
(Specification
(Priv
)),
7585 Defining_Unit_Name
(Specification
(Sub
)));
7587 Current_Node
:= Sub
;
7590 Make_Subprogram_Declaration
(Loc
,
7592 Build_Protected_Sub_Specification
7593 (Priv
, Prot_Typ
, Protected_Mode
));
7595 Insert_After
(Current_Node
, Sub
);
7597 Current_Node
:= Sub
;
7599 if Is_Interrupt_Handler
7600 (Defining_Unit_Name
(Specification
(Priv
)))
7602 if not Restricted_Profile
then
7612 -- Put the _Object component after the private component so that it
7613 -- be finalized early as required by 9.4 (20)
7615 Append_To
(Cdecls
, Object_Comp
);
7617 Insert_After
(Current_Node
, Rec_Decl
);
7618 Current_Node
:= Rec_Decl
;
7620 -- Analyze the record declaration immediately after construction,
7621 -- because the initialization procedure is needed for single object
7622 -- declarations before the next entity is analyzed (the freeze call
7623 -- that generates this initialization procedure is found below).
7625 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
7627 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7628 -- the corresponding record is frozen
7630 if Ada_Version
>= Ada_05
7631 and then Present
(Visible_Declarations
(Pdef
))
7632 and then Present
(Corresponding_Record_Type
7633 (Defining_Identifier
(Parent
(Pdef
))))
7634 and then Present
(Interfaces
7635 (Corresponding_Record_Type
7636 (Defining_Identifier
(Parent
(Pdef
)))))
7639 Current_Node
: Node_Id
:= Rec_Decl
;
7641 Wrap_Spec
: Node_Id
;
7645 -- Examine the visible declarations of the protected type, looking
7646 -- for declarations of entries, and subprograms. We do not
7647 -- consider entry families since they cannot have dispatching
7648 -- operations, thus they do not need entry wrappers.
7650 Vis_Decl
:= First
(Visible_Declarations
(Pdef
));
7652 while Present
(Vis_Decl
) loop
7656 if Nkind
(Vis_Decl
) = N_Entry_Declaration
7657 and then No
(Discrete_Subtype_Definition
(Vis_Decl
))
7660 Build_Wrapper_Spec
(Loc
,
7661 Proc_Nam
=> Defining_Identifier
(Vis_Decl
),
7662 Obj_Typ
=> Defining_Identifier
(Rec_Decl
),
7663 Formals
=> Parameter_Specifications
(Vis_Decl
));
7665 elsif Nkind
(Vis_Decl
) = N_Subprogram_Declaration
then
7667 Build_Wrapper_Spec
(Loc
,
7668 Proc_Nam
=> Defining_Unit_Name
7669 (Specification
(Vis_Decl
)),
7670 Obj_Typ
=> Defining_Identifier
(Rec_Decl
),
7671 Formals
=> Parameter_Specifications
7672 (Specification
(Vis_Decl
)));
7676 if Wrap_Spec
/= Empty
then
7677 New_N
:= Make_Subprogram_Declaration
(Loc
,
7678 Specification
=> Wrap_Spec
);
7680 Insert_After
(Current_Node
, New_N
);
7681 Current_Node
:= New_N
;
7691 -- Collect pointers to entry bodies and their barriers, to be placed
7692 -- in the Entry_Bodies_Array for the type. For each entry/family we
7693 -- add an expression to the aggregate which is the initial value of
7694 -- this array. The array is declared after all protected subprograms.
7696 if Has_Entries
(Prot_Typ
) then
7698 Make_Aggregate
(Loc
, Expressions
=> New_List
);
7701 Entries_Aggr
:= Empty
;
7704 -- Build two new procedure specifications for each protected subprogram;
7705 -- one to call from outside the object and one to call from inside.
7706 -- Build a barrier function and an entry body action procedure
7707 -- specification for each protected entry. Initialize the entry body
7708 -- array. If subprogram is flagged as eliminated, do not generate any
7709 -- internal operations.
7713 Comp
:= First
(Visible_Declarations
(Pdef
));
7715 while Present
(Comp
) loop
7716 if Nkind
(Comp
) = N_Subprogram_Declaration
7717 and then not Is_Eliminated
(Defining_Entity
(Comp
))
7720 Make_Subprogram_Declaration
(Loc
,
7722 Build_Protected_Sub_Specification
7723 (Comp
, Prot_Typ
, Unprotected_Mode
));
7725 Insert_After
(Current_Node
, Sub
);
7728 Set_Protected_Body_Subprogram
7729 (Defining_Unit_Name
(Specification
(Comp
)),
7730 Defining_Unit_Name
(Specification
(Sub
)));
7732 -- Make the protected version of the subprogram available for
7733 -- expansion of external calls.
7735 Current_Node
:= Sub
;
7738 Make_Subprogram_Declaration
(Loc
,
7740 Build_Protected_Sub_Specification
7741 (Comp
, Prot_Typ
, Protected_Mode
));
7743 Insert_After
(Current_Node
, Sub
);
7746 Current_Node
:= Sub
;
7748 -- Generate an overriding primitive operation specification for
7749 -- this subprogram if the protected type implements an interface.
7751 if Ada_Version
>= Ada_05
7753 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
7756 Make_Subprogram_Declaration
(Loc
,
7758 Build_Protected_Sub_Specification
7759 (Comp
, Prot_Typ
, Dispatching_Mode
));
7761 Insert_After
(Current_Node
, Sub
);
7764 Current_Node
:= Sub
;
7767 -- If a pragma Interrupt_Handler applies, build and add a call to
7768 -- Register_Interrupt_Handler to the freezing actions of the
7769 -- protected version (Current_Node) of the subprogram:
7771 -- system.interrupts.register_interrupt_handler
7772 -- (prot_procP'address);
7774 if not Restricted_Profile
7775 and then Is_Interrupt_Handler
7776 (Defining_Unit_Name
(Specification
(Comp
)))
7781 elsif Nkind
(Comp
) = N_Entry_Declaration
then
7782 E_Count
:= E_Count
+ 1;
7783 Comp_Id
:= Defining_Identifier
(Comp
);
7786 Make_Defining_Identifier
(Loc
,
7787 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
7789 Make_Subprogram_Declaration
(Loc
,
7791 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
7793 Insert_After
(Current_Node
, Sub
);
7796 Set_Protected_Body_Subprogram
7797 (Defining_Identifier
(Comp
),
7798 Defining_Unit_Name
(Specification
(Sub
)));
7800 Current_Node
:= Sub
;
7803 Make_Defining_Identifier
(Loc
,
7804 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
7806 Make_Subprogram_Declaration
(Loc
,
7808 Build_Barrier_Function_Specification
(Loc
, Bdef
));
7810 Insert_After
(Current_Node
, Sub
);
7812 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
7813 Set_Barrier_Function
(Comp_Id
, Bdef
);
7814 Set_Scope
(Bdef
, Scope
(Comp_Id
));
7815 Current_Node
:= Sub
;
7817 -- Collect pointers to the protected subprogram and the barrier
7818 -- of the current entry, for insertion into Entry_Bodies_Array.
7821 Make_Aggregate
(Loc
,
7822 Expressions
=> New_List
(
7823 Make_Attribute_Reference
(Loc
,
7824 Prefix
=> New_Reference_To
(Bdef
, Loc
),
7825 Attribute_Name
=> Name_Unrestricted_Access
),
7826 Make_Attribute_Reference
(Loc
,
7827 Prefix
=> New_Reference_To
(Edef
, Loc
),
7828 Attribute_Name
=> Name_Unrestricted_Access
))),
7829 Expressions
(Entries_Aggr
));
7836 -- If there are some private entry declarations, expand it as if they
7837 -- were visible entries.
7839 if Present
(Private_Declarations
(Pdef
)) then
7840 Comp
:= First
(Private_Declarations
(Pdef
));
7841 while Present
(Comp
) loop
7842 if Nkind
(Comp
) = N_Entry_Declaration
then
7843 E_Count
:= E_Count
+ 1;
7844 Comp_Id
:= Defining_Identifier
(Comp
);
7847 Make_Defining_Identifier
(Loc
,
7848 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
7850 Make_Subprogram_Declaration
(Loc
,
7852 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
7854 Insert_After
(Current_Node
, Sub
);
7857 Set_Protected_Body_Subprogram
7858 (Defining_Identifier
(Comp
),
7859 Defining_Unit_Name
(Specification
(Sub
)));
7861 Current_Node
:= Sub
;
7864 Make_Defining_Identifier
(Loc
,
7865 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
7868 Make_Subprogram_Declaration
(Loc
,
7870 Build_Barrier_Function_Specification
(Loc
, Bdef
));
7872 Insert_After
(Current_Node
, Sub
);
7874 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
7875 Set_Barrier_Function
(Comp_Id
, Bdef
);
7876 Set_Scope
(Bdef
, Scope
(Comp_Id
));
7877 Current_Node
:= Sub
;
7879 -- Collect pointers to the protected subprogram and the barrier
7880 -- of the current entry, for insertion into Entry_Bodies_Array.
7882 Append_To
(Expressions
(Entries_Aggr
),
7883 Make_Aggregate
(Loc
,
7884 Expressions
=> New_List
(
7885 Make_Attribute_Reference
(Loc
,
7886 Prefix
=> New_Reference_To
(Bdef
, Loc
),
7887 Attribute_Name
=> Name_Unrestricted_Access
),
7888 Make_Attribute_Reference
(Loc
,
7889 Prefix
=> New_Reference_To
(Edef
, Loc
),
7890 Attribute_Name
=> Name_Unrestricted_Access
))));
7897 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
7898 -- all protected subprograms have been collected.
7900 if Has_Entries
(Prot_Typ
) then
7902 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
7903 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
7905 case Corresponding_Runtime_Package
(Prot_Typ
) is
7906 when System_Tasking_Protected_Objects_Entries
=>
7907 Body_Arr
:= Make_Object_Declaration
(Loc
,
7908 Defining_Identifier
=> Body_Id
,
7909 Aliased_Present
=> True,
7910 Object_Definition
=>
7911 Make_Subtype_Indication
(Loc
,
7912 Subtype_Mark
=> New_Reference_To
(
7913 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
7915 Make_Index_Or_Discriminant_Constraint
(Loc
,
7916 Constraints
=> New_List
(
7918 Make_Integer_Literal
(Loc
, 1),
7919 Make_Integer_Literal
(Loc
, E_Count
))))),
7920 Expression
=> Entries_Aggr
);
7922 when System_Tasking_Protected_Objects_Single_Entry
=>
7923 Body_Arr
:= Make_Object_Declaration
(Loc
,
7924 Defining_Identifier
=> Body_Id
,
7925 Aliased_Present
=> True,
7926 Object_Definition
=> New_Reference_To
7927 (RTE
(RE_Entry_Body
), Loc
),
7929 Make_Aggregate
(Loc
,
7930 Expressions
=> New_List
(
7931 Make_Attribute_Reference
(Loc
,
7932 Prefix
=> New_Reference_To
(Bdef
, Loc
),
7933 Attribute_Name
=> Name_Unrestricted_Access
),
7934 Make_Attribute_Reference
(Loc
,
7935 Prefix
=> New_Reference_To
(Edef
, Loc
),
7936 Attribute_Name
=> Name_Unrestricted_Access
))));
7939 raise Program_Error
;
7942 -- A pointer to this array will be placed in the corresponding record
7943 -- by its initialization procedure so this needs to be analyzed here.
7945 Insert_After
(Current_Node
, Body_Arr
);
7946 Current_Node
:= Body_Arr
;
7949 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
7951 -- Finally, build the function that maps an entry index into the
7952 -- corresponding body. A pointer to this function is placed in each
7953 -- object of the type. Except for a ravenscar-like profile (no abort,
7954 -- no entry queue, 1 entry)
7956 if Corresponding_Runtime_Package
(Prot_Typ
) =
7957 System_Tasking_Protected_Objects_Entries
7960 Make_Subprogram_Declaration
(Loc
,
7961 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
7962 Insert_After
(Current_Node
, Sub
);
7966 end Expand_N_Protected_Type_Declaration
;
7968 --------------------------------
7969 -- Expand_N_Requeue_Statement --
7970 --------------------------------
7972 -- A non-dispatching requeue statement is expanded into one of four GNARLI
7973 -- operations, depending on the source and destination (task or protected
7974 -- object). A dispatching requeue statement is expanded into a call to the
7975 -- predefined primitive _Disp_Requeue. In addition, code is generated to
7976 -- jump around the remainder of processing for the original entry and, if
7977 -- the destination is (different) protected object, to attempt to service
7978 -- it. The following illustrates the various cases:
7981 -- (O : System.Address;
7982 -- P : System.Address;
7983 -- E : Protected_Entry_Index)
7985 -- <discriminant renamings>
7986 -- <private object renamings>
7987 -- type poVP is access poV;
7988 -- _object : ptVP := ptVP!(O);
7992 -- <start of statement sequence for entry>
7994 -- -- Requeue from one protected entry body to another protected
7997 -- Requeue_Protected_Entry (
7998 -- _object._object'Access,
7999 -- new._object'Access,
8004 -- <some more of the statement sequence for entry>
8006 -- -- Requeue from an entry body to a task entry
8008 -- Requeue_Protected_To_Task_Entry (
8014 -- <rest of statement sequence for entry>
8015 -- Complete_Entry_Body (_object._object);
8018 -- when all others =>
8019 -- Exceptional_Complete_Entry_Body (
8020 -- _object._object, Get_GNAT_Exception);
8024 -- Requeue of a task entry call to a task entry
8026 -- Accept_Call (E, Ann);
8027 -- <start of statement sequence for accept statement>
8028 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8030 -- <rest of statement sequence for accept statement>
8032 -- Complete_Rendezvous;
8035 -- when all others =>
8036 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8038 -- Requeue of a task entry call to a protected entry
8040 -- Accept_Call (E, Ann);
8041 -- <start of statement sequence for accept statement>
8042 -- Requeue_Task_To_Protected_Entry (
8043 -- new._object'Access,
8048 -- <rest of statement sequence for accept statement>
8050 -- Complete_Rendezvous;
8053 -- when all others =>
8054 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8056 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
8060 -- (O : System.Address;
8061 -- P : System.Address;
8062 -- E : Protected_Entry_Index)
8064 -- <discriminant renamings>
8065 -- <private object renamings>
8066 -- type poVP is access poV;
8067 -- _object : ptVP := ptVP!(O);
8071 -- <start of statement sequence for entry>
8074 -- (<interface class-wide object>,
8077 -- Ada.Tags.Get_Offset_Index
8079 -- <interface dispatch table index of target entry>),
8083 -- <rest of statement sequence for entry>
8084 -- Complete_Entry_Body (_object._object);
8087 -- when all others =>
8088 -- Exceptional_Complete_Entry_Body (
8089 -- _object._object, Get_GNAT_Exception);
8093 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
8096 -- Accept_Call (E, Ann);
8097 -- <start of statement sequence for accept statement>
8099 -- (<interface class-wide object>,
8102 -- Ada.Tags.Get_Offset_Index
8104 -- <interface dispatch table index of target entrt>),
8108 -- <rest of statement sequence for accept statement>
8110 -- Complete_Rendezvous;
8113 -- when all others =>
8114 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8116 -- Further details on these expansions can be found in Expand_N_Protected_
8117 -- Body and Expand_N_Accept_Statement.
8119 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
8120 Loc
: constant Source_Ptr
:= Sloc
(N
);
8121 Abortable
: Node_Id
;
8123 Conc_Typ
: Entity_Id
;
8128 New_Param
: Node_Id
;
8129 Old_Typ
: Entity_Id
;
8132 RTS_Call
: Entity_Id
;
8133 Self_Param
: Node_Id
;
8134 Skip_Stat
: Node_Id
;
8138 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
);
8140 -- Extract the components of the entry call
8142 Extract_Entry
(N
, Concval
, Ename
, Index
);
8143 Conc_Typ
:= Etype
(Concval
);
8145 -- Examine the scope stack in order to find nearest enclosing protected
8146 -- or task type. This will constitute our invocation source.
8148 Old_Typ
:= Current_Scope
;
8149 while Present
(Old_Typ
)
8150 and then not Is_Protected_Type
(Old_Typ
)
8151 and then not Is_Task_Type
(Old_Typ
)
8153 Old_Typ
:= Scope
(Old_Typ
);
8156 -- Generate the parameter list for all cases. The abortable flag is
8157 -- common among dispatching and regular requeue.
8159 Params
:= New_List
(Abortable
);
8161 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
8162 -- Concval.Ename where the type of Concval is class-wide concurrent
8165 if Ada_Version
>= Ada_05
8166 and then Present
(Concval
)
8167 and then Is_Class_Wide_Type
(Conc_Typ
)
8168 and then Is_Concurrent_Interface
(Conc_Typ
)
8170 RTS_Call
:= Make_Identifier
(Loc
, Name_uDisp_Requeue
);
8173 -- Ada.Tags.Get_Offset_Index
8174 -- (Ada.Tags.Tag (Concval),
8175 -- <interface dispatch table position of Ename>)
8178 Make_Function_Call
(Loc
,
8180 New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
8181 Parameter_Associations
=>
8183 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
8184 Make_Integer_Literal
(Loc
, DT_Position
(Entity
(Ename
))))));
8186 -- Specific actuals for protected to interface class-wide type
8189 if Is_Protected_Type
(Old_Typ
) then
8191 Make_Attribute_Reference
(Loc
, -- _object'Address
8193 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
8196 Prepend_To
(Params
, -- True
8197 New_Reference_To
(Standard_True
, Loc
));
8199 -- Specific actuals for task to interface class-wide type requeue
8202 pragma Assert
(Is_Task_Type
(Old_Typ
));
8204 Prepend_To
(Params
, -- null
8205 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
8206 Prepend_To
(Params
, -- False
8207 New_Reference_To
(Standard_False
, Loc
));
8210 -- Finally, add the common object parameter
8212 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
8214 -- Regular requeue processing
8217 New_Param
:= Concurrent_Ref
(Concval
);
8219 -- The index expression is common among all four cases
8222 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
8224 if Is_Protected_Type
(Old_Typ
) then
8226 Make_Attribute_Reference
(Loc
,
8228 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
8230 Name_Unchecked_Access
);
8232 -- Protected to protected requeue
8234 if Is_Protected_Type
(Conc_Typ
) then
8236 New_Reference_To
(RTE
(RE_Requeue_Protected_Entry
), Loc
);
8239 Make_Attribute_Reference
(Loc
,
8243 Name_Unchecked_Access
);
8245 -- Protected to task requeue
8248 pragma Assert
(Is_Task_Type
(Conc_Typ
));
8251 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
8254 Prepend
(New_Param
, Params
);
8255 Prepend
(Self_Param
, Params
);
8258 pragma Assert
(Is_Task_Type
(Old_Typ
));
8260 -- Task to protected requeue
8262 if Is_Protected_Type
(Conc_Typ
) then
8265 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
8268 Make_Attribute_Reference
(Loc
,
8272 Name_Unchecked_Access
);
8274 -- Task to task requeue
8277 pragma Assert
(Is_Task_Type
(Conc_Typ
));
8279 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
);
8282 Prepend
(New_Param
, Params
);
8286 -- Create the GNARLI or predefined primitive call
8289 Make_Procedure_Call_Statement
(Loc
,
8291 Parameter_Associations
=> Params
);
8296 if Is_Protected_Type
(Old_Typ
) then
8298 -- Build the return statement to skip the rest of the entry body
8300 Skip_Stat
:= Make_Simple_Return_Statement
(Loc
);
8303 -- If the requeue is within a task, find the end label of the
8304 -- enclosing accept statement.
8306 Acc_Stat
:= Parent
(N
);
8307 while Nkind
(Acc_Stat
) /= N_Accept_Statement
loop
8308 Acc_Stat
:= Parent
(Acc_Stat
);
8311 -- The last statement is the second label, used for completing the
8312 -- rendezvous the usual way. The label we are looking for is right
8316 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc_Stat
))));
8318 pragma Assert
(Nkind
(Lab_Node
) = N_Label
);
8320 -- Build the goto statement to skip the rest of the accept
8324 Make_Goto_Statement
(Loc
,
8325 Name
=> New_Occurrence_Of
(Entity
(Identifier
(Lab_Node
)), Loc
));
8328 Set_Analyzed
(Skip_Stat
);
8330 Insert_After
(N
, Skip_Stat
);
8331 end Expand_N_Requeue_Statement
;
8333 -------------------------------
8334 -- Expand_N_Selective_Accept --
8335 -------------------------------
8337 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
8338 Loc
: constant Source_Ptr
:= Sloc
(N
);
8339 Alts
: constant List_Id
:= Select_Alternatives
(N
);
8341 -- Note: in the below declarations a lot of new lists are allocated
8342 -- unconditionally which may well not end up being used. That's
8343 -- not a good idea since it wastes space gratuitously ???
8345 Accept_Case
: List_Id
;
8346 Accept_List
: constant List_Id
:= New_List
;
8349 Alt_List
: constant List_Id
:= New_List
;
8350 Alt_Stats
: List_Id
;
8351 Ann
: Entity_Id
:= Empty
;
8354 Check_Guard
: Boolean := True;
8356 Decls
: constant List_Id
:= New_List
;
8357 Stats
: constant List_Id
:= New_List
;
8358 Body_List
: constant List_Id
:= New_List
;
8359 Trailing_List
: constant List_Id
:= New_List
;
8362 Else_Present
: Boolean := False;
8363 Terminate_Alt
: Node_Id
:= Empty
;
8364 Select_Mode
: Node_Id
;
8366 Delay_Case
: List_Id
;
8367 Delay_Count
: Integer := 0;
8368 Delay_Val
: Entity_Id
;
8369 Delay_Index
: Entity_Id
;
8370 Delay_Min
: Entity_Id
;
8371 Delay_Num
: Int
:= 1;
8372 Delay_Alt_List
: List_Id
:= New_List
;
8373 Delay_List
: constant List_Id
:= New_List
;
8377 First_Delay
: Boolean := True;
8378 Guard_Open
: Entity_Id
;
8384 Num_Accept
: Nat
:= 0;
8387 Time_Type
: Entity_Id
;
8389 Select_Call
: Node_Id
;
8391 Qnam
: constant Entity_Id
:=
8392 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
8394 Xnam
: constant Entity_Id
:=
8395 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
8397 -----------------------
8398 -- Local subprograms --
8399 -----------------------
8401 function Accept_Or_Raise
return List_Id
;
8402 -- For the rare case where delay alternatives all have guards, and
8403 -- all of them are closed, it is still possible that there were open
8404 -- accept alternatives with no callers. We must reexamine the
8405 -- Accept_List, and execute a selective wait with no else if some
8406 -- accept is open. If none, we raise program_error.
8408 procedure Add_Accept
(Alt
: Node_Id
);
8409 -- Process a single accept statement in a select alternative. Build
8410 -- procedure for body of accept, and add entry to dispatch table with
8411 -- expression for guard, in preparation for call to run time select.
8413 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
8414 -- Manufacture a label using Num as a serial number and declare it.
8415 -- The declaration is appended to Decls. The label marks the trailing
8416 -- statements of an accept or delay alternative.
8418 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
8419 -- Build call to Selective_Wait runtime routine
8421 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
8422 -- Add code to compare value of delay with previous values, and
8423 -- generate case entry for trailing statements.
8425 procedure Process_Accept_Alternative
8429 -- Add code to call corresponding procedure, and branch to
8430 -- trailing statements, if any.
8432 ---------------------
8433 -- Accept_Or_Raise --
8434 ---------------------
8436 function Accept_Or_Raise
return List_Id
is
8439 J
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
,
8440 New_Internal_Name
('J'));
8443 -- We generate the following:
8445 -- for J in q'range loop
8446 -- if q(J).S /=null_task_entry then
8447 -- selective_wait (simple_mode,...);
8453 -- if no rendez_vous then
8454 -- raise program_error;
8457 -- Note that the code needs to know that the selector name
8458 -- in an Accept_Alternative is named S.
8460 Cond
:= Make_Op_Ne
(Loc
,
8462 Make_Selected_Component
(Loc
,
8463 Prefix
=> Make_Indexed_Component
(Loc
,
8464 Prefix
=> New_Reference_To
(Qnam
, Loc
),
8465 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
8466 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
8468 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
8471 Make_Implicit_Loop_Statement
(N
,
8472 Identifier
=> Empty
,
8474 Make_Iteration_Scheme
(Loc
,
8475 Loop_Parameter_Specification
=>
8476 Make_Loop_Parameter_Specification
(Loc
,
8477 Defining_Identifier
=> J
,
8478 Discrete_Subtype_Definition
=>
8479 Make_Attribute_Reference
(Loc
,
8480 Prefix
=> New_Reference_To
(Qnam
, Loc
),
8481 Attribute_Name
=> Name_Range
,
8482 Expressions
=> New_List
(
8483 Make_Integer_Literal
(Loc
, 1))))),
8485 Statements
=> New_List
(
8486 Make_Implicit_If_Statement
(N
,
8488 Then_Statements
=> New_List
(
8490 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
8491 Make_Exit_Statement
(Loc
))))));
8494 Make_Raise_Program_Error
(Loc
,
8495 Condition
=> Make_Op_Eq
(Loc
,
8496 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
8498 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
8499 Reason
=> PE_All_Guards_Closed
));
8502 end Accept_Or_Raise
;
8508 procedure Add_Accept
(Alt
: Node_Id
) is
8509 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
8510 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
8511 Eent
: constant Entity_Id
:= Entity
(Ename
);
8512 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
8513 Null_Body
: Node_Id
;
8514 Proc_Body
: Node_Id
;
8521 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
8524 if Present
(Condition
(Alt
)) then
8526 Make_Conditional_Expression
(Loc
, New_List
(
8528 Entry_Index_Expression
(Loc
, Eent
, Index
, Scope
(Eent
)),
8529 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
)));
8532 Entry_Index_Expression
8533 (Loc
, Eent
, Index
, Scope
(Eent
));
8536 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
8537 Null_Body
:= New_Reference_To
(Standard_False
, Loc
);
8539 if Abort_Allowed
then
8540 Call
:= Make_Procedure_Call_Statement
(Loc
,
8541 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
));
8542 Insert_Before
(First
(Statements
(Handled_Statement_Sequence
(
8543 Accept_Statement
(Alt
)))), Call
);
8548 Make_Defining_Identifier
(Sloc
(Ename
),
8549 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
8551 if Comes_From_Source
(Alt
) then
8552 Set_Debug_Info_Needed
(PB_Ent
);
8556 Make_Subprogram_Body
(Loc
,
8558 Make_Procedure_Specification
(Loc
,
8559 Defining_Unit_Name
=> PB_Ent
),
8560 Declarations
=> Declarations
(Acc_Stm
),
8561 Handled_Statement_Sequence
=>
8562 Build_Accept_Body
(Accept_Statement
(Alt
)));
8564 -- During the analysis of the body of the accept statement, any
8565 -- zero cost exception handler records were collected in the
8566 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8567 -- This is where we move them to where they belong, namely the
8568 -- newly created procedure.
8570 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
8571 Append
(Proc_Body
, Body_List
);
8574 Null_Body
:= New_Reference_To
(Standard_True
, Loc
);
8576 -- if accept statement has declarations, insert above, given that
8577 -- we are not creating a body for the accept.
8579 if Present
(Declarations
(Acc_Stm
)) then
8580 Insert_Actions
(N
, Declarations
(Acc_Stm
));
8584 Append_To
(Accept_List
,
8585 Make_Aggregate
(Loc
, Expressions
=> New_List
(Null_Body
, Expr
)));
8587 Num_Accept
:= Num_Accept
+ 1;
8590 ----------------------------
8591 -- Make_And_Declare_Label --
8592 ----------------------------
8594 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
8598 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
8600 Make_Label
(Loc
, Lab_Id
);
8603 Make_Implicit_Label_Declaration
(Loc
,
8604 Defining_Identifier
=>
8605 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
8606 Label_Construct
=> Lab
));
8609 end Make_And_Declare_Label
;
8611 ----------------------
8612 -- Make_Select_Call --
8613 ----------------------
8615 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
8616 Params
: constant List_Id
:= New_List
;
8620 Make_Attribute_Reference
(Loc
,
8621 Prefix
=> New_Reference_To
(Qnam
, Loc
),
8622 Attribute_Name
=> Name_Unchecked_Access
),
8624 Append
(Select_Mode
, Params
);
8625 Append
(New_Reference_To
(Ann
, Loc
), Params
);
8626 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
8629 Make_Procedure_Call_Statement
(Loc
,
8630 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
8631 Parameter_Associations
=> Params
);
8632 end Make_Select_Call
;
8634 --------------------------------
8635 -- Process_Accept_Alternative --
8636 --------------------------------
8638 procedure Process_Accept_Alternative
8643 Choices
: List_Id
:= No_List
;
8644 Alt_Stats
: List_Id
;
8647 Adjust_Condition
(Condition
(Alt
));
8648 Alt_Stats
:= No_List
;
8650 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
8651 Choices
:= New_List
(
8652 Make_Integer_Literal
(Loc
, Index
));
8654 Alt_Stats
:= New_List
(
8655 Make_Procedure_Call_Statement
(Loc
,
8656 Name
=> New_Reference_To
(
8657 Defining_Unit_Name
(Specification
(Proc
)), Loc
)));
8660 if Statements
(Alt
) /= Empty_List
then
8662 if No
(Alt_Stats
) then
8664 -- Accept with no body, followed by trailing statements
8666 Choices
:= New_List
(
8667 Make_Integer_Literal
(Loc
, Index
));
8669 Alt_Stats
:= New_List
;
8672 -- After the call, if any, branch to to trailing statements. We
8673 -- create a label for each, as well as the corresponding label
8676 Lab
:= Make_And_Declare_Label
(Index
);
8677 Append_To
(Alt_Stats
,
8678 Make_Goto_Statement
(Loc
,
8679 Name
=> New_Copy
(Identifier
(Lab
))));
8681 Append
(Lab
, Trailing_List
);
8682 Append_List
(Statements
(Alt
), Trailing_List
);
8683 Append_To
(Trailing_List
,
8684 Make_Goto_Statement
(Loc
,
8685 Name
=> New_Copy
(Identifier
(End_Lab
))));
8688 if Present
(Alt_Stats
) then
8690 -- Procedure call. and/or trailing statements
8692 Append_To
(Alt_List
,
8693 Make_Case_Statement_Alternative
(Loc
,
8694 Discrete_Choices
=> Choices
,
8695 Statements
=> Alt_Stats
));
8697 end Process_Accept_Alternative
;
8699 -------------------------------
8700 -- Process_Delay_Alternative --
8701 -------------------------------
8703 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
8706 Delay_Alt
: List_Id
;
8709 -- Deal with C/Fortran boolean as delay condition
8711 Adjust_Condition
(Condition
(Alt
));
8713 -- Determine the smallest specified delay
8715 -- for each delay alternative generate:
8717 -- if guard-expression then
8718 -- Delay_Val := delay-expression;
8719 -- Guard_Open := True;
8720 -- if Delay_Val < Delay_Min then
8721 -- Delay_Min := Delay_Val;
8722 -- Delay_Index := Index;
8726 -- The enclosing if-statement is omitted if there is no guard
8731 First_Delay
:= False;
8733 Delay_Alt
:= New_List
(
8734 Make_Assignment_Statement
(Loc
,
8735 Name
=> New_Reference_To
(Delay_Min
, Loc
),
8736 Expression
=> Expression
(Delay_Statement
(Alt
))));
8738 if Delay_Count
> 1 then
8739 Append_To
(Delay_Alt
,
8740 Make_Assignment_Statement
(Loc
,
8741 Name
=> New_Reference_To
(Delay_Index
, Loc
),
8742 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
8746 Delay_Alt
:= New_List
(
8747 Make_Assignment_Statement
(Loc
,
8748 Name
=> New_Reference_To
(Delay_Val
, Loc
),
8749 Expression
=> Expression
(Delay_Statement
(Alt
))));
8751 if Time_Type
= Standard_Duration
then
8754 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
8755 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
8758 -- The scope of the time type must define a comparison
8759 -- operator. The scope itself may not be visible, so we
8760 -- construct a node with entity information to insure that
8761 -- semantic analysis can find the proper operator.
8764 Make_Function_Call
(Loc
,
8765 Name
=> Make_Selected_Component
(Loc
,
8766 Prefix
=> New_Reference_To
(Scope
(Time_Type
), Loc
),
8768 Make_Operator_Symbol
(Loc
,
8769 Chars
=> Name_Op_Lt
,
8770 Strval
=> No_String
)),
8771 Parameter_Associations
=>
8773 New_Reference_To
(Delay_Val
, Loc
),
8774 New_Reference_To
(Delay_Min
, Loc
)));
8776 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
8779 Append_To
(Delay_Alt
,
8780 Make_Implicit_If_Statement
(N
,
8782 Then_Statements
=> New_List
(
8783 Make_Assignment_Statement
(Loc
,
8784 Name
=> New_Reference_To
(Delay_Min
, Loc
),
8785 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
8787 Make_Assignment_Statement
(Loc
,
8788 Name
=> New_Reference_To
(Delay_Index
, Loc
),
8789 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
8793 Append_To
(Delay_Alt
,
8794 Make_Assignment_Statement
(Loc
,
8795 Name
=> New_Reference_To
(Guard_Open
, Loc
),
8796 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
8799 if Present
(Condition
(Alt
)) then
8800 Delay_Alt
:= New_List
(
8801 Make_Implicit_If_Statement
(N
,
8802 Condition
=> Condition
(Alt
),
8803 Then_Statements
=> Delay_Alt
));
8806 Append_List
(Delay_Alt
, Delay_List
);
8808 -- If the delay alternative has a statement part, add choice to the
8809 -- case statements for delays.
8811 if Present
(Statements
(Alt
)) then
8813 if Delay_Count
= 1 then
8814 Append_List
(Statements
(Alt
), Delay_Alt_List
);
8817 Choices
:= New_List
(
8818 Make_Integer_Literal
(Loc
, Index
));
8820 Append_To
(Delay_Alt_List
,
8821 Make_Case_Statement_Alternative
(Loc
,
8822 Discrete_Choices
=> Choices
,
8823 Statements
=> Statements
(Alt
)));
8826 elsif Delay_Count
= 1 then
8828 -- If the single delay has no trailing statements, add a branch
8829 -- to the exit label to the selective wait.
8831 Delay_Alt_List
:= New_List
(
8832 Make_Goto_Statement
(Loc
,
8833 Name
=> New_Copy
(Identifier
(End_Lab
))));
8836 end Process_Delay_Alternative
;
8838 -- Start of processing for Expand_N_Selective_Accept
8841 -- First insert some declarations before the select. The first is:
8845 -- This variable holds the parameters passed to the accept body. This
8846 -- declaration has already been inserted by the time we get here by
8847 -- a call to Expand_Accept_Declarations made from the semantics when
8848 -- processing the first accept statement contained in the select. We
8849 -- can find this entity as Accept_Address (E), where E is any of the
8850 -- entries references by contained accept statements.
8852 -- The first step is to scan the list of Selective_Accept_Statements
8853 -- to find this entity, and also count the number of accepts, and
8854 -- determine if terminated, delay or else is present:
8858 Alt
:= First
(Alts
);
8859 while Present
(Alt
) loop
8861 if Nkind
(Alt
) = N_Accept_Alternative
then
8864 elsif Nkind
(Alt
) = N_Delay_Alternative
then
8865 Delay_Count
:= Delay_Count
+ 1;
8867 -- If the delays are relative delays, the delay expressions have
8868 -- type Standard_Duration. Otherwise they must have some time type
8869 -- recognized by GNAT.
8871 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
8872 Time_Type
:= Standard_Duration
;
8874 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
8876 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
8877 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
8882 "& is not a time type (RM 9.6(6))",
8883 Expression
(Delay_Statement
(Alt
)), Time_Type
);
8884 Time_Type
:= Standard_Duration
;
8885 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
8889 if No
(Condition
(Alt
)) then
8891 -- This guard will always be open
8893 Check_Guard
:= False;
8896 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
8897 Adjust_Condition
(Condition
(Alt
));
8898 Terminate_Alt
:= Alt
;
8901 Num_Alts
:= Num_Alts
+ 1;
8905 Else_Present
:= Present
(Else_Statements
(N
));
8907 -- At the same time (see procedure Add_Accept) we build the accept list:
8909 -- Qnn : Accept_List (1 .. num-select) := (
8910 -- (null-body, entry-index),
8911 -- (null-body, entry-index),
8913 -- (null_body, entry-index));
8915 -- In the above declaration, null-body is True if the corresponding
8916 -- accept has no body, and false otherwise. The entry is either the
8917 -- entry index expression if there is no guard, or if a guard is
8918 -- present, then a conditional expression of the form:
8920 -- (if guard then entry-index else Null_Task_Entry)
8922 -- If a guard is statically known to be false, the entry can simply
8923 -- be omitted from the accept list.
8926 Make_Object_Declaration
(Loc
,
8927 Defining_Identifier
=> Qnam
,
8928 Object_Definition
=>
8929 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
8930 Aliased_Present
=> True,
8933 Make_Qualified_Expression
(Loc
,
8935 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
8937 Make_Aggregate
(Loc
, Expressions
=> Accept_List
)));
8941 -- Then we declare the variable that holds the index for the accept
8942 -- that will be selected for service:
8944 -- Xnn : Select_Index;
8947 Make_Object_Declaration
(Loc
,
8948 Defining_Identifier
=> Xnam
,
8949 Object_Definition
=>
8950 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
8952 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
8956 -- After this follow procedure declarations for each accept body
8963 -- where the ... are statements from the corresponding procedure body.
8964 -- No parameters are involved, since the parameters are passed via Ann
8965 -- and the parameter references have already been expanded to be direct
8966 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
8967 -- any embedded tasking statements (which would normally be illegal in
8968 -- procedures), have been converted to calls to the tasking runtime so
8969 -- there is no problem in putting them into procedures.
8971 -- The original accept statement has been expanded into a block in
8972 -- the same fashion as for simple accepts (see Build_Accept_Body).
8974 -- Note: we don't really need to build these procedures for the case
8975 -- where no delay statement is present, but it is just as easy to
8976 -- build them unconditionally, and not significantly inefficient,
8977 -- since if they are short they will be inlined anyway.
8979 -- The procedure declarations have been assembled in Body_List
8981 -- If delays are present, we must compute the required delay.
8982 -- We first generate the declarations:
8984 -- Delay_Index : Boolean := 0;
8985 -- Delay_Min : Some_Time_Type.Time;
8986 -- Delay_Val : Some_Time_Type.Time;
8988 -- Delay_Index will be set to the index of the minimum delay, i.e. the
8989 -- active delay that is actually chosen as the basis for the possible
8990 -- delay if an immediate rendez-vous is not possible.
8992 -- In the most common case there is a single delay statement, and this
8993 -- is handled specially.
8995 if Delay_Count
> 0 then
8997 -- Generate the required declarations
9000 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
9002 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
9004 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
9007 Make_Object_Declaration
(Loc
,
9008 Defining_Identifier
=> Delay_Val
,
9009 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
9012 Make_Object_Declaration
(Loc
,
9013 Defining_Identifier
=> Delay_Index
,
9014 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
9015 Expression
=> Make_Integer_Literal
(Loc
, 0)));
9018 Make_Object_Declaration
(Loc
,
9019 Defining_Identifier
=> Delay_Min
,
9020 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
9022 Unchecked_Convert_To
(Time_Type
,
9023 Make_Attribute_Reference
(Loc
,
9025 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
9026 Attribute_Name
=> Name_Last
))));
9028 -- Create Duration and Delay_Mode objects used for passing a delay
9031 D
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
9032 M
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('M'));
9038 -- Note that these values are defined in s-osprim.ads and must
9041 -- Relative : constant := 0;
9042 -- Absolute_Calendar : constant := 1;
9043 -- Absolute_RT : constant := 2;
9045 if Time_Type
= Standard_Duration
then
9046 Discr
:= Make_Integer_Literal
(Loc
, 0);
9048 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
9049 Discr
:= Make_Integer_Literal
(Loc
, 1);
9053 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
9054 Discr
:= Make_Integer_Literal
(Loc
, 2);
9058 Make_Object_Declaration
(Loc
,
9059 Defining_Identifier
=> D
,
9060 Object_Definition
=>
9061 New_Reference_To
(Standard_Duration
, Loc
)));
9064 Make_Object_Declaration
(Loc
,
9065 Defining_Identifier
=> M
,
9066 Object_Definition
=>
9067 New_Reference_To
(Standard_Integer
, Loc
),
9068 Expression
=> Discr
));
9073 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
9076 Make_Object_Declaration
(Loc
,
9077 Defining_Identifier
=> Guard_Open
,
9078 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
9079 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
9082 -- Delay_Count is zero, don't need M and D set (suppress warning)
9089 if Present
(Terminate_Alt
) then
9091 -- If the terminate alternative guard is False, use
9092 -- Simple_Mode; otherwise use Terminate_Mode.
9094 if Present
(Condition
(Terminate_Alt
)) then
9095 Select_Mode
:= Make_Conditional_Expression
(Loc
,
9096 New_List
(Condition
(Terminate_Alt
),
9097 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
9098 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
9100 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
9103 elsif Else_Present
or Delay_Count
> 0 then
9104 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
9107 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
9110 Select_Call
:= Make_Select_Call
(Select_Mode
);
9111 Append
(Select_Call
, Stats
);
9113 -- Now generate code to act on the result. There is an entry
9114 -- in this case for each accept statement with a non-null body,
9115 -- followed by a branch to the statements that follow the Accept.
9116 -- In the absence of delay alternatives, we generate:
9119 -- when No_Rendezvous => -- omitted if simple mode
9134 -- Lab0: Else_Statements;
9137 -- Lab1: Trailing_Statements1;
9140 -- Lab2: Trailing_Statements2;
9145 -- Generate label for common exit
9147 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
9149 -- First entry is the default case, when no rendezvous is possible
9151 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
9153 if Else_Present
then
9155 -- If no rendezvous is possible, the else part is executed
9157 Lab
:= Make_And_Declare_Label
(0);
9158 Alt_Stats
:= New_List
(
9159 Make_Goto_Statement
(Loc
,
9160 Name
=> New_Copy
(Identifier
(Lab
))));
9162 Append
(Lab
, Trailing_List
);
9163 Append_List
(Else_Statements
(N
), Trailing_List
);
9164 Append_To
(Trailing_List
,
9165 Make_Goto_Statement
(Loc
,
9166 Name
=> New_Copy
(Identifier
(End_Lab
))));
9168 Alt_Stats
:= New_List
(
9169 Make_Goto_Statement
(Loc
,
9170 Name
=> New_Copy
(Identifier
(End_Lab
))));
9173 Append_To
(Alt_List
,
9174 Make_Case_Statement_Alternative
(Loc
,
9175 Discrete_Choices
=> Choices
,
9176 Statements
=> Alt_Stats
));
9178 -- We make use of the fact that Accept_Index is an integer type, and
9179 -- generate successive literals for entries for each accept. Only those
9180 -- for which there is a body or trailing statements get a case entry.
9182 Alt
:= First
(Select_Alternatives
(N
));
9183 Proc
:= First
(Body_List
);
9184 while Present
(Alt
) loop
9186 if Nkind
(Alt
) = N_Accept_Alternative
then
9187 Process_Accept_Alternative
(Alt
, Index
, Proc
);
9191 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
9196 elsif Nkind
(Alt
) = N_Delay_Alternative
then
9197 Process_Delay_Alternative
(Alt
, Delay_Num
);
9198 Delay_Num
:= Delay_Num
+ 1;
9204 -- An others choice is always added to the main case, as well
9205 -- as the delay case (to satisfy the compiler).
9207 Append_To
(Alt_List
,
9208 Make_Case_Statement_Alternative
(Loc
,
9210 New_List
(Make_Others_Choice
(Loc
)),
9212 New_List
(Make_Goto_Statement
(Loc
,
9213 Name
=> New_Copy
(Identifier
(End_Lab
))))));
9215 Accept_Case
:= New_List
(
9216 Make_Case_Statement
(Loc
,
9217 Expression
=> New_Reference_To
(Xnam
, Loc
),
9218 Alternatives
=> Alt_List
));
9220 Append_List
(Trailing_List
, Accept_Case
);
9221 Append
(End_Lab
, Accept_Case
);
9222 Append_List
(Body_List
, Decls
);
9224 -- Construct case statement for trailing statements of delay
9225 -- alternatives, if there are several of them.
9227 if Delay_Count
> 1 then
9228 Append_To
(Delay_Alt_List
,
9229 Make_Case_Statement_Alternative
(Loc
,
9231 New_List
(Make_Others_Choice
(Loc
)),
9233 New_List
(Make_Null_Statement
(Loc
))));
9235 Delay_Case
:= New_List
(
9236 Make_Case_Statement
(Loc
,
9237 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
9238 Alternatives
=> Delay_Alt_List
));
9240 Delay_Case
:= Delay_Alt_List
;
9243 -- If there are no delay alternatives, we append the case statement
9244 -- to the statement list.
9246 if Delay_Count
= 0 then
9247 Append_List
(Accept_Case
, Stats
);
9249 -- Delay alternatives present
9252 -- If delay alternatives are present we generate:
9254 -- find minimum delay.
9255 -- DX := minimum delay;
9256 -- M := <delay mode>;
9257 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9260 -- if X = No_Rendezvous then
9261 -- case statement for delay statements.
9263 -- case statement for accept alternatives.
9274 -- The type of the delay expression is known to be legal
9276 if Time_Type
= Standard_Duration
then
9277 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
9279 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
9280 Conv
:= Make_Function_Call
(Loc
,
9281 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
9282 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
9286 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
9288 Conv
:= Make_Function_Call
(Loc
,
9289 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
9290 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
9293 Stmt
:= Make_Assignment_Statement
(Loc
,
9294 Name
=> New_Reference_To
(D
, Loc
),
9295 Expression
=> Conv
);
9297 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9299 Parms
:= Parameter_Associations
(Select_Call
);
9300 Parm
:= First
(Parms
);
9302 while Present
(Parm
)
9303 and then Parm
/= Select_Mode
9308 pragma Assert
(Present
(Parm
));
9309 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
9312 -- Prepare two new parameters of Duration and Delay_Mode type
9313 -- which represent the value and the mode of the minimum delay.
9316 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
9317 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
9319 -- Create a call to RTS
9321 Rewrite
(Select_Call
,
9322 Make_Procedure_Call_Statement
(Loc
,
9323 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
9324 Parameter_Associations
=> Parms
));
9326 -- This new call should follow the calculation of the minimum
9329 Insert_List_Before
(Select_Call
, Delay_List
);
9333 Make_Implicit_If_Statement
(N
,
9334 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
9336 New_List
(New_Copy_Tree
(Stmt
),
9337 New_Copy_Tree
(Select_Call
)),
9338 Else_Statements
=> Accept_Or_Raise
);
9339 Rewrite
(Select_Call
, Stmt
);
9341 Insert_Before
(Select_Call
, Stmt
);
9345 Make_Implicit_If_Statement
(N
,
9346 Condition
=> Make_Op_Eq
(Loc
,
9347 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
9349 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
9351 Then_Statements
=> Delay_Case
,
9352 Else_Statements
=> Accept_Case
);
9354 Append
(Cases
, Stats
);
9358 -- Replace accept statement with appropriate block
9361 Make_Block_Statement
(Loc
,
9362 Declarations
=> Decls
,
9363 Handled_Statement_Sequence
=>
9364 Make_Handled_Sequence_Of_Statements
(Loc
,
9365 Statements
=> Stats
));
9370 -- Note: have to worry more about abort deferral in above code ???
9372 -- Final step is to unstack the Accept_Address entries for all accept
9373 -- statements appearing in accept alternatives in the select statement
9375 Alt
:= First
(Alts
);
9376 while Present
(Alt
) loop
9377 if Nkind
(Alt
) = N_Accept_Alternative
then
9378 Remove_Last_Elmt
(Accept_Address
9379 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
9384 end Expand_N_Selective_Accept
;
9386 --------------------------------------
9387 -- Expand_N_Single_Task_Declaration --
9388 --------------------------------------
9390 -- Single task declarations should never be present after semantic
9391 -- analysis, since we expect them to be replaced by a declaration of an
9392 -- anonymous task type, followed by a declaration of the task object. We
9393 -- include this routine to make sure that is happening!
9395 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
9397 raise Program_Error
;
9398 end Expand_N_Single_Task_Declaration
;
9400 ------------------------
9401 -- Expand_N_Task_Body --
9402 ------------------------
9404 -- Given a task body
9406 -- task body tname is
9412 -- This expansion routine converts it into a procedure and sets the
9413 -- elaboration flag for the procedure to true, to represent the fact
9414 -- that the task body is now elaborated:
9416 -- procedure tnameB (_Task : access tnameV) is
9417 -- discriminal : dtype renames _Task.discriminant;
9419 -- procedure _clean is
9423 -- Abort_Undefer.all;
9428 -- Abort_Undefer.all;
9430 -- System.Task_Stages.Complete_Activation;
9438 -- In addition, if the task body is an activator, then a call to activate
9439 -- tasks is added at the start of the statements, before the call to
9440 -- Complete_Activation, and if in addition the task is a master then it
9441 -- must be established as a master. These calls are inserted and analyzed
9442 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9445 -- There is one discriminal declaration line generated for each
9446 -- discriminant that is present to provide an easy reference point for
9447 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9449 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9450 -- task body procedures have a profile (Arg : System.Address). That is
9451 -- needed because GNARLI has to use the same access-to-subprogram type
9452 -- for all task types. We depend here on knowing that in GNAT, passing
9453 -- an address argument by value is identical to passing a record value
9454 -- by access (in either case a single pointer is passed), so even though
9455 -- this procedure has the wrong profile. In fact it's all OK, since the
9456 -- callings sequence is identical.
9458 procedure Expand_N_Task_Body
(N
: Node_Id
) is
9459 Loc
: constant Source_Ptr
:= Sloc
(N
);
9460 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
9465 -- Add renaming declarations for discriminals and a declaration for the
9466 -- entry family index (if applicable).
9468 Install_Private_Data_Declarations
9469 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
9471 -- Add a call to Abort_Undefer at the very beginning of the task
9472 -- body since this body is called with abort still deferred.
9474 if Abort_Allowed
then
9475 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
9477 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
9481 -- The statement part has already been protected with an at_end and
9482 -- cleanup actions. The call to Complete_Activation must be placed
9483 -- at the head of the sequence of statements of that block. The
9484 -- declarations have been merged in this sequence of statements but
9485 -- the first real statement is accessible from the First_Real_Statement
9486 -- field (which was set for exactly this purpose).
9488 if Restricted_Profile
then
9489 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
9491 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
9495 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
9499 Make_Subprogram_Body
(Loc
,
9500 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
9501 Declarations
=> Declarations
(N
),
9502 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
9504 -- If the task contains generic instantiations, cleanup actions are
9505 -- delayed until after instantiation. Transfer the activation chain to
9506 -- the subprogram, to insure that the activation call is properly
9507 -- generated. It the task body contains inner tasks, indicate that the
9508 -- subprogram is a task master.
9510 if Delay_Cleanups
(Ttyp
) then
9511 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
9512 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
9518 -- Set elaboration flag immediately after task body. If the body is a
9519 -- subunit, the flag is set in the declarative part containing the stub.
9521 if Nkind
(Parent
(N
)) /= N_Subunit
then
9523 Make_Assignment_Statement
(Loc
,
9525 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
9526 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
9529 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9530 -- the task body. At this point the entry specs have been created,
9531 -- frozen and included in the dispatch table for the task type.
9533 pragma Assert
(Present
(Corresponding_Record_Type
(Ttyp
)));
9535 if Ada_Version
>= Ada_05
9536 and then Present
(Task_Definition
(Parent
(Ttyp
)))
9537 and then Present
(Interfaces
(Corresponding_Record_Type
(Ttyp
)))
9540 Current_Node
: Node_Id
;
9541 Vis_Decl
: Node_Id
:=
9542 First
(Visible_Declarations
(Task_Definition
(Parent
(Ttyp
))));
9543 Wrap_Body
: Node_Id
;
9546 if Nkind
(Parent
(N
)) = N_Subunit
then
9547 Current_Node
:= Corresponding_Stub
(Parent
(N
));
9552 -- Examine the visible declarations of the task type, looking for
9553 -- an entry declaration. We do not consider entry families since
9554 -- they cannot have dispatching operations, thus they do not need
9557 while Present
(Vis_Decl
) loop
9558 if Nkind
(Vis_Decl
) = N_Entry_Declaration
9559 and then Ekind
(Defining_Identifier
(Vis_Decl
)) = E_Entry
9561 -- Create the specification of the wrapper
9564 Build_Wrapper_Body
(Loc
,
9565 Proc_Nam
=> Defining_Identifier
(Vis_Decl
),
9566 Obj_Typ
=> Corresponding_Record_Type
(Ttyp
),
9567 Formals
=> Parameter_Specifications
(Vis_Decl
));
9569 if Wrap_Body
/= Empty
then
9570 Insert_After
(Current_Node
, Wrap_Body
);
9571 Current_Node
:= Wrap_Body
;
9573 Analyze
(Wrap_Body
);
9581 end Expand_N_Task_Body
;
9583 ------------------------------------
9584 -- Expand_N_Task_Type_Declaration --
9585 ------------------------------------
9587 -- We have several things to do. First we must create a Boolean flag used
9588 -- to mark if the body is elaborated yet. This variable gets set to True
9589 -- when the body of the task is elaborated (we can't rely on the normal
9590 -- ABE mechanism for the task body, since we need to pass an access to
9591 -- this elaboration boolean to the runtime routines).
9593 -- taskE : aliased Boolean := False;
9595 -- Next a variable is declared to hold the task stack size (either the
9596 -- default : Unspecified_Size, or a value that is set by a pragma
9597 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9598 -- the variable is initialized with this value:
9600 -- taskZ : Size_Type := Unspecified_Size;
9602 -- taskZ : Size_Type := Size_Type (size_expression);
9604 -- Note: No variable is needed to hold the task relative deadline since
9605 -- its value would never be static because the parameter is of a private
9606 -- type (Ada.Real_Time.Time_Span).
9608 -- Next we create a corresponding record type declaration used to represent
9609 -- values of this task. The general form of this type declaration is
9611 -- type taskV (discriminants) is record
9612 -- _Task_Id : Task_Id;
9613 -- entry_family : array (bounds) of Void;
9614 -- _Priority : Integer := priority_expression;
9615 -- _Size : Size_Type := Size_Type (size_expression);
9616 -- _Task_Info : Task_Info_Type := task_info_expression;
9619 -- The discriminants are present only if the corresponding task type has
9620 -- discriminants, and they exactly mirror the task type discriminants.
9622 -- The Id field is always present. It contains the Task_Id value, as set by
9623 -- the call to Create_Task. Note that although the task is limited, the
9624 -- task value record type is not limited, so there is no problem in passing
9625 -- this field as an out parameter to Create_Task.
9627 -- One entry_family component is present for each entry family in the task
9628 -- definition. The bounds correspond to the bounds of the entry family
9629 -- (which may depend on discriminants). The element type is void, since we
9630 -- only need the bounds information for determining the entry index. Note
9631 -- that the use of an anonymous array would normally be illegal in this
9632 -- context, but this is a parser check, and the semantics is quite prepared
9633 -- to handle such a case.
9635 -- The _Size field is present only if a Storage_Size pragma appears in the
9636 -- task definition. The expression captures the argument that was present
9637 -- in the pragma, and is used to override the task stack size otherwise
9638 -- associated with the task type.
9640 -- The _Priority field is present only if a Priority or Interrupt_Priority
9641 -- pragma appears in the task definition. The expression captures the
9642 -- argument that was present in the pragma, and is used to provide the Size
9643 -- parameter to the call to Create_Task.
9645 -- The _Task_Info field is present only if a Task_Info pragma appears in
9646 -- the task definition. The expression captures the argument that was
9647 -- present in the pragma, and is used to provide the Task_Image parameter
9648 -- to the call to Create_Task.
9650 -- The _Relative_Deadline field is present only if a Relative_Deadline
9651 -- pragma appears in the task definition. The expression captures the
9652 -- argument that was present in the pragma, and is used to provide the
9653 -- Relative_Deadline parameter to the call to Create_Task.
9655 -- When a task is declared, an instance of the task value record is
9656 -- created. The elaboration of this declaration creates the correct bounds
9657 -- for the entry families, and also evaluates the size, priority, and
9658 -- task_Info expressions if needed. The initialization routine for the task
9659 -- type itself then calls Create_Task with appropriate parameters to
9660 -- initialize the value of the Task_Id field.
9662 -- Note: the address of this record is passed as the "Discriminants"
9663 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9664 -- body procedure, it does not matter that it does not quite match the
9665 -- GNARLI model of what is being passed (the record contains more than just
9666 -- the discriminants, but the discriminants can be found from the record
9669 -- The Entity_Id for this created record type is placed in the
9670 -- Corresponding_Record_Type field of the associated task type entity.
9672 -- Next we create a procedure specification for the task body procedure:
9674 -- procedure taskB (_Task : access taskV);
9676 -- Note that this must come after the record type declaration, since
9677 -- the spec refers to this type. It turns out that the initialization
9678 -- procedure for the value type references the task body spec, but that's
9679 -- fine, since it won't be generated till the freeze point for the type,
9680 -- which is certainly after the task body spec declaration.
9682 -- Finally, we set the task index value field of the entry attribute in
9683 -- the case of a simple entry.
9685 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
9686 Loc
: constant Source_Ptr
:= Sloc
(N
);
9687 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
9688 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
9689 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
9691 Proc_Spec
: Node_Id
;
9693 Rec_Ent
: Entity_Id
;
9695 Elab_Decl
: Node_Id
;
9696 Size_Decl
: Node_Id
;
9697 Body_Decl
: Node_Id
;
9698 Task_Size
: Node_Id
;
9699 Ent_Stack
: Entity_Id
;
9700 Decl_Stack
: Node_Id
;
9703 -- If already expanded, nothing to do
9705 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
9709 -- Here we will do the expansion
9711 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
9713 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9714 -- of implemented interfaces.
9716 Set_Interface_List
(Type_Definition
(Rec_Decl
), Interface_List
(N
));
9718 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
9719 Cdecls
:= Component_Items
(Component_List
9720 (Type_Definition
(Rec_Decl
)));
9722 Qualify_Entity_Names
(N
);
9724 -- First create the elaboration variable
9727 Make_Object_Declaration
(Loc
,
9728 Defining_Identifier
=>
9729 Make_Defining_Identifier
(Sloc
(Tasktyp
),
9730 Chars
=> New_External_Name
(Tasknm
, 'E')),
9731 Aliased_Present
=> True,
9732 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
9733 Expression
=> New_Reference_To
(Standard_False
, Loc
));
9734 Insert_After
(N
, Elab_Decl
);
9736 -- Next create the declaration of the size variable (tasknmZ)
9738 Set_Storage_Size_Variable
(Tasktyp
,
9739 Make_Defining_Identifier
(Sloc
(Tasktyp
),
9740 Chars
=> New_External_Name
(Tasknm
, 'Z')));
9742 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) and then
9743 Is_Static_Expression
(Expression
(First
(
9744 Pragma_Argument_Associations
(Find_Task_Or_Protected_Pragma
(
9745 Taskdef
, Name_Storage_Size
)))))
9748 Make_Object_Declaration
(Loc
,
9749 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
9750 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
9752 Convert_To
(RTE
(RE_Size_Type
),
9755 Pragma_Argument_Associations
(
9756 Find_Task_Or_Protected_Pragma
9757 (Taskdef
, Name_Storage_Size
)))))));
9761 Make_Object_Declaration
(Loc
,
9762 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
9763 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
9764 Expression
=> New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
9767 Insert_After
(Elab_Decl
, Size_Decl
);
9769 -- Next build the rest of the corresponding record declaration. This is
9770 -- done last, since the corresponding record initialization procedure
9771 -- will reference the previously created entities.
9773 -- Fill in the component declarations -- first the _Task_Id field
9776 Make_Component_Declaration
(Loc
,
9777 Defining_Identifier
=>
9778 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
9779 Component_Definition
=>
9780 Make_Component_Definition
(Loc
,
9781 Aliased_Present
=> False,
9782 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
9785 -- Declare static ATCB (that is, created by the expander) if we are
9786 -- using the Restricted run time.
9788 if Restricted_Profile
then
9790 Make_Component_Declaration
(Loc
,
9791 Defining_Identifier
=>
9792 Make_Defining_Identifier
(Loc
, Name_uATCB
),
9794 Component_Definition
=>
9795 Make_Component_Definition
(Loc
,
9796 Aliased_Present
=> True,
9797 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
9798 Subtype_Mark
=> New_Occurrence_Of
9799 (RTE
(RE_Ada_Task_Control_Block
), Loc
),
9802 Make_Index_Or_Discriminant_Constraint
(Loc
,
9804 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
9808 -- Declare static stack (that is, created by the expander) if we are
9809 -- using the Restricted run time on a bare board configuration.
9811 if Restricted_Profile
9812 and then Preallocated_Stacks_On_Target
9814 -- First we need to extract the appropriate stack size
9816 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
9818 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
9820 Expr_N
: constant Node_Id
:=
9822 Pragma_Argument_Associations
(
9823 Find_Task_Or_Protected_Pragma
9824 (Taskdef
, Name_Storage_Size
))));
9825 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
9826 P
: constant Node_Id
:= Parent
(Expr_N
);
9829 -- The stack is defined inside the corresponding record.
9830 -- Therefore if the size of the stack is set by means of
9831 -- a discriminant, we must reference the discriminant of the
9832 -- corresponding record type.
9834 if Nkind
(Expr_N
) in N_Has_Entity
9835 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
9839 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
9841 Set_Parent
(Task_Size
, P
);
9842 Set_Etype
(Task_Size
, Etyp
);
9843 Set_Analyzed
(Task_Size
);
9846 Task_Size
:= Relocate_Node
(Expr_N
);
9852 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
9855 Decl_Stack
:= Make_Component_Declaration
(Loc
,
9856 Defining_Identifier
=> Ent_Stack
,
9858 Component_Definition
=>
9859 Make_Component_Definition
(Loc
,
9860 Aliased_Present
=> True,
9861 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
9863 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
9866 Make_Index_Or_Discriminant_Constraint
(Loc
,
9867 Constraints
=> New_List
(Make_Range
(Loc
,
9868 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
9869 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
9872 Append_To
(Cdecls
, Decl_Stack
);
9874 -- The appropriate alignment for the stack is ensured by the run-time
9875 -- code in charge of task creation.
9879 -- Add components for entry families
9881 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
9883 -- Add the _Priority component if a Priority pragma is present
9885 if Present
(Taskdef
) and then Has_Priority_Pragma
(Taskdef
) then
9887 Prag
: constant Node_Id
:=
9888 Find_Task_Or_Protected_Pragma
(Taskdef
, Name_Priority
);
9892 Expr
:= First
(Pragma_Argument_Associations
(Prag
));
9894 if Nkind
(Expr
) = N_Pragma_Argument_Association
then
9895 Expr
:= Expression
(Expr
);
9898 Expr
:= New_Copy_Tree
(Expr
);
9900 -- Add conversion to proper type to do range check if required
9901 -- Note that for runtime units, we allow out of range interrupt
9902 -- priority values to be used in a priority pragma. This is for
9903 -- the benefit of some versions of System.Interrupts which use
9904 -- a special server task with maximum interrupt priority.
9906 if Pragma_Name
(Prag
) = Name_Priority
9907 and then not GNAT_Mode
9909 Rewrite
(Expr
, Convert_To
(RTE
(RE_Priority
), Expr
));
9911 Rewrite
(Expr
, Convert_To
(RTE
(RE_Any_Priority
), Expr
));
9915 Make_Component_Declaration
(Loc
,
9916 Defining_Identifier
=>
9917 Make_Defining_Identifier
(Loc
, Name_uPriority
),
9918 Component_Definition
=>
9919 Make_Component_Definition
(Loc
,
9920 Aliased_Present
=> False,
9921 Subtype_Indication
=> New_Reference_To
(Standard_Integer
,
9923 Expression
=> Expr
));
9927 -- Add the _Task_Size component if a Storage_Size pragma is present
9929 if Present
(Taskdef
)
9930 and then Has_Storage_Size_Pragma
(Taskdef
)
9933 Make_Component_Declaration
(Loc
,
9934 Defining_Identifier
=>
9935 Make_Defining_Identifier
(Loc
, Name_uSize
),
9937 Component_Definition
=>
9938 Make_Component_Definition
(Loc
,
9939 Aliased_Present
=> False,
9940 Subtype_Indication
=> New_Reference_To
(RTE
(RE_Size_Type
),
9944 Convert_To
(RTE
(RE_Size_Type
),
9947 Pragma_Argument_Associations
(
9948 Find_Task_Or_Protected_Pragma
9949 (Taskdef
, Name_Storage_Size
))))))));
9952 -- Add the _Task_Info component if a Task_Info pragma is present
9954 if Present
(Taskdef
) and then Has_Task_Info_Pragma
(Taskdef
) then
9956 Make_Component_Declaration
(Loc
,
9957 Defining_Identifier
=>
9958 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
9960 Component_Definition
=>
9961 Make_Component_Definition
(Loc
,
9962 Aliased_Present
=> False,
9963 Subtype_Indication
=>
9964 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
9966 Expression
=> New_Copy
(
9968 Pragma_Argument_Associations
(
9969 Find_Task_Or_Protected_Pragma
9970 (Taskdef
, Name_Task_Info
)))))));
9973 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
9974 -- present. If we are using a restricted run time this component will
9975 -- not be added (deadlines are not allowed by the Ravenscar profile).
9977 if not Restricted_Profile
9978 and then Present
(Taskdef
)
9979 and then Has_Relative_Deadline_Pragma
(Taskdef
)
9982 Make_Component_Declaration
(Loc
,
9983 Defining_Identifier
=>
9984 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
9986 Component_Definition
=>
9987 Make_Component_Definition
(Loc
,
9988 Aliased_Present
=> False,
9989 Subtype_Indication
=>
9990 New_Reference_To
(RTE
(RE_Time_Span
), Loc
)),
9993 Convert_To
(RTE
(RE_Time_Span
),
9996 Pragma_Argument_Associations
(
9997 Find_Task_Or_Protected_Pragma
9998 (Taskdef
, Name_Relative_Deadline
))))))));
10001 Insert_After
(Size_Decl
, Rec_Decl
);
10003 -- Analyze the record declaration immediately after construction,
10004 -- because the initialization procedure is needed for single task
10005 -- declarations before the next entity is analyzed.
10007 Analyze
(Rec_Decl
);
10009 -- Create the declaration of the task body procedure
10011 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
10013 Make_Subprogram_Declaration
(Loc
,
10014 Specification
=> Proc_Spec
);
10016 Insert_After
(Rec_Decl
, Body_Decl
);
10018 -- The subprogram does not comes from source, so we have to indicate the
10019 -- need for debugging information explicitly.
10021 if Comes_From_Source
(Original_Node
(N
)) then
10022 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
10025 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10026 -- the corresponding record has been frozen.
10028 if Ada_Version
>= Ada_05
10029 and then Present
(Taskdef
)
10030 and then Present
(Corresponding_Record_Type
10031 (Defining_Identifier
(Parent
(Taskdef
))))
10032 and then Present
(Interfaces
10033 (Corresponding_Record_Type
10034 (Defining_Identifier
(Parent
(Taskdef
)))))
10037 Current_Node
: Node_Id
:= Rec_Decl
;
10038 Vis_Decl
: Node_Id
:= First
(Visible_Declarations
(Taskdef
));
10039 Wrap_Spec
: Node_Id
;
10043 -- Examine the visible declarations of the task type, looking for
10044 -- an entry declaration. We do not consider entry families since
10045 -- they cannot have dispatching operations, thus they do not need
10048 while Present
(Vis_Decl
) loop
10049 if Nkind
(Vis_Decl
) = N_Entry_Declaration
10050 and then Ekind
(Defining_Identifier
(Vis_Decl
)) = E_Entry
10053 Build_Wrapper_Spec
(Loc
,
10054 Proc_Nam
=> Defining_Identifier
(Vis_Decl
),
10055 Obj_Typ
=> Etype
(Rec_Ent
),
10056 Formals
=> Parameter_Specifications
(Vis_Decl
));
10058 if Wrap_Spec
/= Empty
then
10060 Make_Subprogram_Declaration
(Loc
,
10061 Specification
=> Wrap_Spec
);
10063 Insert_After
(Current_Node
, New_N
);
10064 Current_Node
:= New_N
;
10075 -- Ada 2005 (AI-345): We must defer freezing to allow further
10076 -- declaration of primitive subprograms covering task interfaces
10078 if Ada_Version
<= Ada_95
then
10080 -- Now we can freeze the corresponding record. This needs manually
10081 -- freezing, since it is really part of the task type, and the task
10082 -- type is frozen at this stage. We of course need the initialization
10083 -- procedure for this corresponding record type and we won't get it
10084 -- in time if we don't freeze now.
10087 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, Loc
);
10089 if Is_Non_Empty_List
(L
) then
10090 Insert_List_After
(Body_Decl
, L
);
10095 -- Complete the expansion of access types to the current task type, if
10096 -- any were declared.
10098 Expand_Previous_Access_Type
(Tasktyp
);
10099 end Expand_N_Task_Type_Declaration
;
10101 -------------------------------
10102 -- Expand_N_Timed_Entry_Call --
10103 -------------------------------
10105 -- A timed entry call in normal case is not implemented using ATC mechanism
10106 -- anymore for efficiency reason.
10116 -- is expanded as follow:
10118 -- 1) When T.E is a task entry_call;
10122 -- X : Task_Entry_Index := <entry index>;
10123 -- DX : Duration := To_Duration (D);
10124 -- M : Delay_Mode := <discriminant>;
10125 -- P : parms := (parm, parm, parm);
10128 -- Timed_Protected_Entry_Call
10129 -- (<acceptor-task>, X, P'Address, DX, M, B);
10137 -- 2) When T.E is a protected entry_call;
10141 -- X : Protected_Entry_Index := <entry index>;
10142 -- DX : Duration := To_Duration (D);
10143 -- M : Delay_Mode := <discriminant>;
10144 -- P : parms := (parm, parm, parm);
10147 -- Timed_Protected_Entry_Call
10148 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10156 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10159 -- B : Boolean := False;
10160 -- C : Ada.Tags.Prim_Op_Kind;
10161 -- DX : Duration := To_Duration (D)
10162 -- K : Ada.Tags.Tagged_Kind :=
10163 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10164 -- M : Integer :=...;
10165 -- P : Parameters := (Param1 .. ParamN);
10169 -- if K = Ada.Tags.TK_Limited_Tagged then
10170 -- <dispatching-call>;
10171 -- <triggering-statements>
10175 -- Ada.Tags.Get_Offset_Index
10176 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10178 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10180 -- if C = POK_Protected_Entry
10181 -- or else C = POK_Task_Entry
10183 -- Param1 := P.Param1;
10185 -- ParamN := P.ParamN;
10189 -- if C = POK_Procedure
10190 -- or else C = POK_Protected_Procedure
10191 -- or else C = POK_Task_Procedure
10193 -- <dispatching-call>;
10196 -- <triggering-statements>
10198 -- <timed-statements>
10203 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
10204 Loc
: constant Source_Ptr
:= Sloc
(N
);
10206 E_Call
: Node_Id
:=
10207 Entry_Call_Statement
(Entry_Call_Alternative
(N
));
10208 E_Stats
: constant List_Id
:=
10209 Statements
(Entry_Call_Alternative
(N
));
10210 D_Stat
: Node_Id
:=
10211 Delay_Statement
(Delay_Alternative
(N
));
10212 D_Stats
: constant List_Id
:=
10213 Statements
(Delay_Alternative
(N
));
10216 Blk_Typ
: Entity_Id
;
10218 Call_Ent
: Entity_Id
;
10219 Conc_Typ_Stmts
: List_Id
;
10223 D_Type
: Entity_Id
;
10229 Is_Disp_Select
: Boolean;
10230 Lim_Typ_Stmts
: List_Id
;
10239 B
: Entity_Id
; -- Call status flag
10240 C
: Entity_Id
; -- Call kind
10241 D
: Entity_Id
; -- Delay
10242 K
: Entity_Id
; -- Tagged kind
10243 M
: Entity_Id
; -- Delay mode
10244 P
: Entity_Id
; -- Parameter block
10245 S
: Entity_Id
; -- Primitive operation slot
10248 -- The arguments in the call may require dynamic allocation, and the
10249 -- call statement may have been transformed into a block. The block
10250 -- may contain additional declarations for internal entities, and the
10251 -- original call is found by sequential search.
10253 if Nkind
(E_Call
) = N_Block_Statement
then
10254 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
10255 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
10256 N_Entry_Call_Statement
)
10263 Ada_Version
>= Ada_05
10264 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
10266 if Is_Disp_Select
then
10267 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
10273 -- B : Boolean := False;
10275 B
:= Build_B
(Loc
, Decls
);
10278 -- C : Ada.Tags.Prim_Op_Kind;
10280 C
:= Build_C
(Loc
, Decls
);
10282 -- Because the analysis of all statements was disabled, manually
10283 -- analyze the delay statement.
10286 D_Stat
:= Original_Node
(D_Stat
);
10289 -- Build an entry call using Simple_Entry_Call
10291 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
10292 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
10294 Decls
:= Declarations
(E_Call
);
10295 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
10304 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
10307 Make_Object_Declaration
(Loc
,
10308 Defining_Identifier
=>
10310 Object_Definition
=>
10311 New_Reference_To
(Standard_Boolean
, Loc
)));
10314 -- Duration and mode processing
10316 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
10318 -- Use the type of the delay expression (Calendar or Real_Time) to
10319 -- generate the appropriate conversion.
10321 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
10322 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
10323 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
10325 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
10326 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
10327 D_Conv
:= Make_Function_Call
(Loc
,
10328 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
10329 New_List
(New_Copy
(Expression
(D_Stat
))));
10331 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
10332 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
10333 D_Conv
:= Make_Function_Call
(Loc
,
10334 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
10335 New_List
(New_Copy
(Expression
(D_Stat
))));
10338 D
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
10344 Make_Object_Declaration
(Loc
,
10345 Defining_Identifier
=>
10347 Object_Definition
=>
10348 New_Reference_To
(Standard_Duration
, Loc
)));
10350 M
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('M'));
10353 -- M : Integer := (0 | 1 | 2);
10356 Make_Object_Declaration
(Loc
,
10357 Defining_Identifier
=>
10359 Object_Definition
=>
10360 New_Reference_To
(Standard_Integer
, Loc
),
10364 -- Do the assignment at this stage only because the evaluation of the
10365 -- expression must not occur before (see ACVC C97302A).
10368 Make_Assignment_Statement
(Loc
,
10370 New_Reference_To
(D
, Loc
),
10374 -- Parameter block processing
10376 -- Manually create the parameter block for dispatching calls. In the
10377 -- case of entries, the block has already been created during the call
10378 -- to Build_Simple_Entry_Call.
10380 if Is_Disp_Select
then
10382 -- Tagged kind processing, generate:
10383 -- K : Ada.Tags.Tagged_Kind :=
10384 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10386 K
:= Build_K
(Loc
, Decls
, Obj
);
10388 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
10389 P
:= Parameter_Block_Pack
10390 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
10392 -- Dispatch table slot processing, generate:
10395 S
:= Build_S
(Loc
, Decls
);
10398 -- S := Ada.Tags.Get_Offset_Index
10399 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10402 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10405 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10407 -- where Obj is the controlling formal parameter, S is the dispatch
10408 -- table slot number of the dispatching operation, P is the wrapped
10409 -- parameter block, D is the duration, M is the duration mode, C is
10410 -- the call kind and B is the call status.
10412 Params
:= New_List
;
10414 Append_To
(Params
, New_Copy_Tree
(Obj
));
10415 Append_To
(Params
, New_Reference_To
(S
, Loc
));
10416 Append_To
(Params
, Make_Attribute_Reference
(Loc
,
10417 Prefix
=> New_Reference_To
(P
, Loc
),
10418 Attribute_Name
=> Name_Address
));
10419 Append_To
(Params
, New_Reference_To
(D
, Loc
));
10420 Append_To
(Params
, New_Reference_To
(M
, Loc
));
10421 Append_To
(Params
, New_Reference_To
(C
, Loc
));
10422 Append_To
(Params
, New_Reference_To
(B
, Loc
));
10424 Append_To
(Conc_Typ_Stmts
,
10425 Make_Procedure_Call_Statement
(Loc
,
10428 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10429 Name_uDisp_Timed_Select
),
10431 Parameter_Associations
=>
10435 -- if C = POK_Protected_Entry
10436 -- or else C = POK_Task_Entry
10438 -- Param1 := P.Param1;
10440 -- ParamN := P.ParamN;
10443 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
10445 -- Generate the if statement only when the packed parameters need
10446 -- explicit assignments to their corresponding actuals.
10448 if Present
(Unpack
) then
10449 Append_To
(Conc_Typ_Stmts
,
10450 Make_If_Statement
(Loc
,
10457 New_Reference_To
(C
, Loc
),
10459 New_Reference_To
(RTE
(
10460 RE_POK_Protected_Entry
), Loc
)),
10464 New_Reference_To
(C
, Loc
),
10466 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
10475 -- if C = POK_Procedure
10476 -- or else C = POK_Protected_Procedure
10477 -- or else C = POK_Task_Procedure
10479 -- <dispatching-call>
10481 -- <triggering-statements>
10483 -- <timed-statements>
10486 N_Stats
:= New_Copy_List_Tree
(E_Stats
);
10488 Prepend_To
(N_Stats
,
10489 Make_If_Statement
(Loc
,
10496 New_Reference_To
(C
, Loc
),
10498 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
10504 New_Reference_To
(C
, Loc
),
10506 New_Reference_To
(RTE
(
10507 RE_POK_Protected_Procedure
), Loc
)),
10511 New_Reference_To
(C
, Loc
),
10513 New_Reference_To
(RTE
(
10514 RE_POK_Task_Procedure
), Loc
)))),
10517 New_List
(E_Call
)));
10519 Append_To
(Conc_Typ_Stmts
,
10520 Make_If_Statement
(Loc
,
10521 Condition
=> New_Reference_To
(B
, Loc
),
10522 Then_Statements
=> N_Stats
,
10523 Else_Statements
=> D_Stats
));
10526 -- <dispatching-call>;
10527 -- <triggering-statements>
10529 Lim_Typ_Stmts
:= New_Copy_List_Tree
(E_Stats
);
10530 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(E_Call
));
10533 -- if K = Ada.Tags.TK_Limited_Tagged then
10540 Make_If_Statement
(Loc
,
10544 New_Reference_To
(K
, Loc
),
10546 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
10555 -- Skip assignments to temporaries created for in-out parameters.
10556 -- This makes unwarranted assumptions about the shape of the expanded
10557 -- tree for the call, and should be cleaned up ???
10559 Stmt
:= First
(Stmts
);
10560 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
10564 -- Do the assignment at this stage only because the evaluation
10565 -- of the expression must not occur before (see ACVC C97302A).
10567 Insert_Before
(Stmt
,
10568 Make_Assignment_Statement
(Loc
,
10569 Name
=> New_Reference_To
(D
, Loc
),
10570 Expression
=> D_Conv
));
10573 Params
:= Parameter_Associations
(Call
);
10575 -- For a protected type, we build a Timed_Protected_Entry_Call
10577 if Is_Protected_Type
(Etype
(Concval
)) then
10579 -- Create a new call statement
10581 Param
:= First
(Params
);
10582 while Present
(Param
)
10583 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
10588 Dummy
:= Remove_Next
(Next
(Param
));
10590 -- Remove garbage is following the Cancel_Param if present
10592 Dummy
:= Next
(Param
);
10594 -- Remove the mode of the Protected_Entry_Call call, then remove
10595 -- the Communication_Block of the Protected_Entry_Call call, and
10596 -- finally add Duration and a Delay_Mode parameter
10598 pragma Assert
(Present
(Param
));
10599 Rewrite
(Param
, New_Reference_To
(D
, Loc
));
10601 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
10603 -- Add a Boolean flag for successful entry call
10605 Append_To
(Params
, New_Reference_To
(B
, Loc
));
10607 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
10608 when System_Tasking_Protected_Objects_Entries
=>
10610 Make_Procedure_Call_Statement
(Loc
,
10613 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
10614 Parameter_Associations
=> Params
));
10616 when System_Tasking_Protected_Objects_Single_Entry
=>
10617 Param
:= First
(Params
);
10618 while Present
(Param
)
10620 Is_RTE
(Etype
(Param
), RE_Protected_Entry_Index
)
10628 Make_Procedure_Call_Statement
(Loc
,
10629 Name
=> New_Reference_To
(
10630 RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
10631 Parameter_Associations
=> Params
));
10634 raise Program_Error
;
10637 -- For the task case, build a Timed_Task_Entry_Call
10640 -- Create a new call statement
10642 Append_To
(Params
, New_Reference_To
(D
, Loc
));
10643 Append_To
(Params
, New_Reference_To
(M
, Loc
));
10644 Append_To
(Params
, New_Reference_To
(B
, Loc
));
10647 Make_Procedure_Call_Statement
(Loc
,
10649 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
10650 Parameter_Associations
=> Params
));
10654 Make_Implicit_If_Statement
(N
,
10655 Condition
=> New_Reference_To
(B
, Loc
),
10656 Then_Statements
=> E_Stats
,
10657 Else_Statements
=> D_Stats
));
10661 Make_Block_Statement
(Loc
,
10662 Declarations
=> Decls
,
10663 Handled_Statement_Sequence
=>
10664 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
10667 end Expand_N_Timed_Entry_Call
;
10669 ----------------------------------------
10670 -- Expand_Protected_Body_Declarations --
10671 ----------------------------------------
10673 procedure Expand_Protected_Body_Declarations
10675 Spec_Id
: Entity_Id
)
10678 if No_Run_Time_Mode
then
10679 Error_Msg_CRT
("protected body", N
);
10682 elsif Expander_Active
then
10684 -- Associate discriminals with the first subprogram or entry body to
10687 if Present
(First_Protected_Operation
(Declarations
(N
))) then
10688 Set_Discriminals
(Parent
(Spec_Id
));
10691 end Expand_Protected_Body_Declarations
;
10693 -------------------------
10694 -- External_Subprogram --
10695 -------------------------
10697 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
10698 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
10701 -- The internal and external subprograms follow each other on the entity
10702 -- chain. Note that previously private operations had no separate
10703 -- external subprogram. We now create one in all cases, because a
10704 -- private operation may actually appear in an external call, through
10705 -- a 'Access reference used for a callback.
10707 -- If the operation is a function that returns an anonymous access type,
10708 -- the corresponding itype appears before the operation, and must be
10711 -- This mechanism is fragile, there should be a real link between the
10712 -- two versions of the operation, but there is no place to put it ???
10714 if Is_Access_Type
(Next_Entity
(Subp
)) then
10715 return Next_Entity
(Next_Entity
(Subp
));
10717 return Next_Entity
(Subp
);
10719 end External_Subprogram
;
10721 ------------------------------
10722 -- Extract_Dispatching_Call --
10723 ------------------------------
10725 procedure Extract_Dispatching_Call
10727 Call_Ent
: out Entity_Id
;
10728 Object
: out Entity_Id
;
10729 Actuals
: out List_Id
;
10730 Formals
: out List_Id
)
10732 Call_Nam
: Node_Id
;
10735 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
10737 if Present
(Original_Node
(N
)) then
10738 Call_Nam
:= Name
(Original_Node
(N
));
10740 Call_Nam
:= Name
(N
);
10743 -- Retrieve the name of the dispatching procedure. It contains the
10744 -- dispatch table slot number.
10747 case Nkind
(Call_Nam
) is
10748 when N_Identifier
=>
10751 when N_Selected_Component
=>
10752 Call_Nam
:= Selector_Name
(Call_Nam
);
10755 raise Program_Error
;
10760 Actuals
:= Parameter_Associations
(N
);
10761 Call_Ent
:= Entity
(Call_Nam
);
10762 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
10763 Object
:= First
(Actuals
);
10765 if Present
(Original_Node
(Object
)) then
10766 Object
:= Original_Node
(Object
);
10768 end Extract_Dispatching_Call
;
10770 -------------------
10771 -- Extract_Entry --
10772 -------------------
10774 procedure Extract_Entry
10776 Concval
: out Node_Id
;
10777 Ename
: out Node_Id
;
10778 Index
: out Node_Id
)
10780 Nam
: constant Node_Id
:= Name
(N
);
10783 -- For a simple entry, the name is a selected component, with the
10784 -- prefix being the task value, and the selector being the entry.
10786 if Nkind
(Nam
) = N_Selected_Component
then
10787 Concval
:= Prefix
(Nam
);
10788 Ename
:= Selector_Name
(Nam
);
10791 -- For a member of an entry family, the name is an indexed component
10792 -- where the prefix is a selected component, whose prefix in turn is
10793 -- the task value, and whose selector is the entry family. The single
10794 -- expression in the expressions list of the indexed component is the
10795 -- subscript for the family.
10797 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
10798 Concval
:= Prefix
(Prefix
(Nam
));
10799 Ename
:= Selector_Name
(Prefix
(Nam
));
10800 Index
:= First
(Expressions
(Nam
));
10804 -------------------
10805 -- Family_Offset --
10806 -------------------
10808 function Family_Offset
10813 Cap
: Boolean) return Node_Id
10819 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
10820 -- If one of the bounds is a reference to a discriminant, replace with
10821 -- corresponding discriminal of type. Within the body of a task retrieve
10822 -- the renamed discriminant by simple visibility, using its generated
10823 -- name. Within a protected object, find the original discriminant and
10824 -- replace it with the discriminal of the current protected operation.
10826 ------------------------------
10827 -- Convert_Discriminant_Ref --
10828 ------------------------------
10830 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
10831 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
10836 if Is_Entity_Name
(Bound
)
10837 and then Ekind
(Entity
(Bound
)) = E_Discriminant
10839 if Is_Task_Type
(Ttyp
)
10840 and then Has_Completion
(Ttyp
)
10842 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
10843 Find_Direct_Name
(B
);
10845 elsif Is_Protected_Type
(Ttyp
) then
10846 D
:= First_Discriminant
(Ttyp
);
10847 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
10848 Next_Discriminant
(D
);
10851 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
10854 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
10857 elsif Nkind
(Bound
) = N_Attribute_Reference
then
10861 B
:= New_Copy_Tree
(Bound
);
10865 Make_Attribute_Reference
(Loc
,
10866 Attribute_Name
=> Name_Pos
,
10867 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
10868 Expressions
=> New_List
(B
));
10869 end Convert_Discriminant_Ref
;
10871 -- Start of processing for Family_Offset
10874 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
10875 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
10878 if Is_Task_Type
(Ttyp
) then
10879 Ityp
:= RTE
(RE_Task_Entry_Index
);
10881 Ityp
:= RTE
(RE_Protected_Entry_Index
);
10885 Make_Attribute_Reference
(Loc
,
10886 Prefix
=> New_Reference_To
(Ityp
, Loc
),
10887 Attribute_Name
=> Name_Min
,
10888 Expressions
=> New_List
(
10890 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
10893 Make_Attribute_Reference
(Loc
,
10894 Prefix
=> New_Reference_To
(Ityp
, Loc
),
10895 Attribute_Name
=> Name_Max
,
10896 Expressions
=> New_List
(
10898 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
10901 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
10908 function Family_Size
10913 Cap
: Boolean) return Node_Id
10918 if Is_Task_Type
(Ttyp
) then
10919 Ityp
:= RTE
(RE_Task_Entry_Index
);
10921 Ityp
:= RTE
(RE_Protected_Entry_Index
);
10925 Make_Attribute_Reference
(Loc
,
10926 Prefix
=> New_Reference_To
(Ityp
, Loc
),
10927 Attribute_Name
=> Name_Max
,
10928 Expressions
=> New_List
(
10931 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
10933 Make_Integer_Literal
(Loc
, 1)),
10934 Make_Integer_Literal
(Loc
, 0)));
10937 -----------------------------------
10938 -- Find_Task_Or_Protected_Pragma --
10939 -----------------------------------
10941 function Find_Task_Or_Protected_Pragma
10943 P
: Name_Id
) return Node_Id
10948 N
:= First
(Visible_Declarations
(T
));
10949 while Present
(N
) loop
10950 if Nkind
(N
) = N_Pragma
then
10951 if Pragma_Name
(N
) = P
then
10954 elsif P
= Name_Priority
10955 and then Pragma_Name
(N
) = Name_Interrupt_Priority
10968 N
:= First
(Private_Declarations
(T
));
10969 while Present
(N
) loop
10970 if Nkind
(N
) = N_Pragma
then
10971 if Pragma_Name
(N
) = P
then
10974 elsif P
= Name_Priority
10975 and then Pragma_Name
(N
) = Name_Interrupt_Priority
10988 raise Program_Error
;
10989 end Find_Task_Or_Protected_Pragma
;
10991 -------------------------------
10992 -- First_Protected_Operation --
10993 -------------------------------
10995 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
10996 First_Op
: Node_Id
;
10999 First_Op
:= First
(D
);
11000 while Present
(First_Op
)
11001 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
11007 end First_Protected_Operation
;
11009 ---------------------------------------
11010 -- Install_Private_Data_Declarations --
11011 ---------------------------------------
11013 procedure Install_Private_Data_Declarations
11015 Spec_Id
: Entity_Id
;
11016 Conc_Typ
: Entity_Id
;
11017 Body_Nod
: Node_Id
;
11019 Barrier
: Boolean := False;
11020 Family
: Boolean := False)
11022 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
11025 Insert_Node
: Node_Id
:= Empty
;
11026 Obj_Ent
: Entity_Id
;
11028 procedure Add
(Decl
: Node_Id
);
11029 -- Add a single declaration after Insert_Node. If this is the first
11030 -- addition, Decl is added to the front of Decls and it becomes the
11033 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
11034 -- The bounds of an entry index may depend on discriminants, create a
11035 -- reference to the corresponding prival. Otherwise return a duplicate
11036 -- of the original bound.
11042 procedure Add
(Decl
: Node_Id
) is
11044 if No
(Insert_Node
) then
11045 Prepend_To
(Decls
, Decl
);
11047 Insert_After
(Insert_Node
, Decl
);
11050 Insert_Node
:= Decl
;
11053 --------------------------
11054 -- Replace_Discriminant --
11055 --------------------------
11057 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
11059 if Nkind
(Bound
) = N_Identifier
11060 and then Is_Discriminal
(Entity
(Bound
))
11062 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
11064 return Duplicate_Subexpr
(Bound
);
11068 -- Start of processing for Install_Private_Data_Declarations
11071 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11072 -- formal parameter _O, _object or _task depending on the context.
11074 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
11076 -- Special processing of _O for barrier functions, protected entries
11083 (Ekind
(Spec_Id
) = E_Entry
11084 or else Ekind
(Spec_Id
) = E_Entry_Family
))
11087 Conc_Rec
: constant Entity_Id
:=
11088 Corresponding_Record_Type
(Conc_Typ
);
11089 Typ_Id
: constant Entity_Id
:=
11090 Make_Defining_Identifier
(Loc
,
11091 New_External_Name
(Chars
(Conc_Rec
), 'P'));
11094 -- type prot_typVP is access prot_typV;
11097 Make_Full_Type_Declaration
(Loc
,
11098 Defining_Identifier
=> Typ_Id
,
11100 Make_Access_To_Object_Definition
(Loc
,
11101 Subtype_Indication
=>
11102 New_Reference_To
(Conc_Rec
, Loc
)));
11106 -- _object : prot_typVP := prot_typV (_O);
11109 Make_Object_Declaration
(Loc
,
11110 Defining_Identifier
=>
11111 Make_Defining_Identifier
(Loc
, Name_uObject
),
11112 Object_Definition
=> New_Reference_To
(Typ_Id
, Loc
),
11114 Unchecked_Convert_To
(Typ_Id
,
11115 New_Reference_To
(Obj_Ent
, Loc
)));
11118 -- Set the reference to the concurrent object
11120 Obj_Ent
:= Defining_Identifier
(Decl
);
11124 -- Step 2: Create the Protection object and build its declaration for
11125 -- any protected entry (family) of subprogram.
11127 if Is_Protected
then
11129 Prot_Ent
: constant Entity_Id
:=
11130 Make_Defining_Identifier
(Loc
,
11131 New_Internal_Name
('R'));
11135 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
11137 -- Determine the proper protection type
11139 if Has_Attach_Handler
(Conc_Typ
)
11140 and then not Restricted_Profile
11142 Prot_Typ
:= RE_Static_Interrupt_Protection
;
11144 elsif Has_Interrupt_Handler
(Conc_Typ
) then
11145 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
11147 -- The type has explicit entries or generated primitive entry
11150 elsif Has_Entries
(Conc_Typ
)
11152 (Ada_Version
>= Ada_05
11153 and then Present
(Interface_List
(Parent
(Conc_Typ
))))
11155 case Corresponding_Runtime_Package
(Conc_Typ
) is
11156 when System_Tasking_Protected_Objects_Entries
=>
11157 Prot_Typ
:= RE_Protection_Entries
;
11159 when System_Tasking_Protected_Objects_Single_Entry
=>
11160 Prot_Typ
:= RE_Protection_Entry
;
11163 raise Program_Error
;
11167 Prot_Typ
:= RE_Protection
;
11171 -- conc_typR : protection_typ renames _object._object;
11174 Make_Object_Renaming_Declaration
(Loc
,
11175 Defining_Identifier
=> Prot_Ent
,
11177 New_Reference_To
(RTE
(Prot_Typ
), Loc
),
11179 Make_Selected_Component
(Loc
,
11181 New_Reference_To
(Obj_Ent
, Loc
),
11183 Make_Identifier
(Loc
, Name_uObject
)));
11188 -- Step 3: Add discriminant renamings (if any)
11190 if Has_Discriminants
(Conc_Typ
) then
11195 D
:= First_Discriminant
(Conc_Typ
);
11196 while Present
(D
) loop
11198 -- Adjust the source location
11200 Set_Sloc
(Discriminal
(D
), Loc
);
11203 -- discr_name : discr_typ renames _object.discr_name;
11205 -- discr_name : discr_typ renames _task.discr_name;
11208 Make_Object_Renaming_Declaration
(Loc
,
11209 Defining_Identifier
=> Discriminal
(D
),
11210 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
11212 Make_Selected_Component
(Loc
,
11213 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
11214 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
11217 Next_Discriminant
(D
);
11222 -- Step 4: Add private component renamings (if any)
11224 if Is_Protected
then
11225 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
11227 if Present
(Private_Declarations
(Def
)) then
11230 Comp_Id
: Entity_Id
;
11231 Decl_Id
: Entity_Id
;
11234 Comp
:= First
(Private_Declarations
(Def
));
11235 while Present
(Comp
) loop
11236 if Nkind
(Comp
) = N_Component_Declaration
then
11237 Comp_Id
:= Defining_Identifier
(Comp
);
11239 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
11241 -- Minimal decoration
11243 if Ekind
(Spec_Id
) = E_Function
then
11244 Set_Ekind
(Decl_Id
, E_Constant
);
11246 Set_Ekind
(Decl_Id
, E_Variable
);
11249 Set_Prival
(Comp_Id
, Decl_Id
);
11250 Set_Prival_Link
(Decl_Id
, Comp_Id
);
11251 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
11254 -- comp_name : comp_typ renames _object.comp_name;
11257 Make_Object_Renaming_Declaration
(Loc
,
11258 Defining_Identifier
=> Decl_Id
,
11260 New_Reference_To
(Etype
(Comp_Id
), Loc
),
11262 Make_Selected_Component
(Loc
,
11264 New_Reference_To
(Obj_Ent
, Loc
),
11266 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
11276 -- Step 5: Add the declaration of the entry index and the associated
11277 -- type for barrier functions and entry families.
11279 if (Barrier
and then Family
)
11280 or else Ekind
(Spec_Id
) = E_Entry_Family
11283 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
11284 Index
: constant Entity_Id
:=
11285 Defining_Identifier
(
11286 Entry_Index_Specification
(
11287 Entry_Body_Formal_Part
(Body_Nod
)));
11288 Index_Con
: constant Entity_Id
:=
11289 Make_Defining_Identifier
(Loc
, Chars
(Index
));
11291 Index_Typ
: Entity_Id
;
11295 -- Minimal decoration
11297 Set_Ekind
(Index_Con
, E_Constant
);
11298 Set_Entry_Index_Constant
(Index
, Index_Con
);
11299 Set_Discriminal_Link
(Index_Con
, Index
);
11301 -- Retrieve the bounds of the entry family
11303 High
:= Type_High_Bound
(Etype
(Index
));
11304 Low
:= Type_Low_Bound
(Etype
(Index
));
11306 -- In the simple case the entry family is given by a subtype
11307 -- mark and the index constant has the same type.
11309 if Is_Entity_Name
(Original_Node
(
11310 Discrete_Subtype_Definition
(Parent
(Index
))))
11312 Index_Typ
:= Etype
(Index
);
11314 -- Otherwise a new subtype declaration is required
11317 High
:= Replace_Bound
(High
);
11318 Low
:= Replace_Bound
(Low
);
11321 Make_Defining_Identifier
(Loc
, New_Internal_Name
('J'));
11324 -- subtype Jnn is <Etype of Index> range Low .. High;
11327 Make_Subtype_Declaration
(Loc
,
11328 Defining_Identifier
=> Index_Typ
,
11329 Subtype_Indication
=>
11330 Make_Subtype_Indication
(Loc
,
11332 New_Reference_To
(Base_Type
(Etype
(Index
)), Loc
),
11334 Make_Range_Constraint
(Loc
,
11335 Range_Expression
=>
11336 Make_Range
(Loc
, Low
, High
))));
11340 Set_Etype
(Index_Con
, Index_Typ
);
11342 -- Create the object which designates the index:
11343 -- J : constant Jnn :=
11344 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
11346 -- where Jnn is the subtype created above or the original type of
11347 -- the index, _E is a formal of the protected body subprogram and
11348 -- <index expr> is the index of the first family member.
11351 Make_Object_Declaration
(Loc
,
11352 Defining_Identifier
=> Index_Con
,
11353 Constant_Present
=> True,
11354 Object_Definition
=>
11355 New_Reference_To
(Index_Typ
, Loc
),
11358 Make_Attribute_Reference
(Loc
,
11360 New_Reference_To
(Index_Typ
, Loc
),
11361 Attribute_Name
=> Name_Val
,
11363 Expressions
=> New_List
(
11367 Make_Op_Subtract
(Loc
,
11369 New_Reference_To
(E
, Loc
),
11371 Entry_Index_Expression
(Loc
,
11372 Defining_Identifier
(Body_Nod
),
11376 Make_Attribute_Reference
(Loc
,
11378 New_Reference_To
(Index_Typ
, Loc
),
11379 Attribute_Name
=> Name_Pos
,
11380 Expressions
=> New_List
(
11381 Make_Attribute_Reference
(Loc
,
11383 New_Reference_To
(Index_Typ
, Loc
),
11384 Attribute_Name
=> Name_First
)))))));
11388 end Install_Private_Data_Declarations
;
11390 ---------------------------------
11391 -- Is_Potentially_Large_Family --
11392 ---------------------------------
11394 function Is_Potentially_Large_Family
11395 (Base_Index
: Entity_Id
;
11396 Conctyp
: Entity_Id
;
11398 Hi
: Node_Id
) return Boolean
11401 return Scope
(Base_Index
) = Standard_Standard
11402 and then Base_Index
= Base_Type
(Standard_Integer
)
11403 and then Has_Discriminants
(Conctyp
)
11405 (Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
11407 (Denotes_Discriminant
(Lo
, True)
11408 or else Denotes_Discriminant
(Hi
, True));
11409 end Is_Potentially_Large_Family
;
11415 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
11416 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
11417 Formal
: Entity_Id
;
11420 Formal
:= First_Formal
(Bod_Subp
);
11421 while Present
(Formal
) loop
11423 -- Look for formal parameter _E
11425 if Chars
(Formal
) = Name_uE
then
11429 Next_Formal
(Formal
);
11432 -- A protected body subprogram should always have the parameter in
11435 raise Program_Error
;
11438 --------------------------------
11439 -- Make_Initialize_Protection --
11440 --------------------------------
11442 function Make_Initialize_Protection
11443 (Protect_Rec
: Entity_Id
) return List_Id
11445 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
11449 Ptyp
: constant Node_Id
:=
11450 Corresponding_Concurrent_Type
(Protect_Rec
);
11452 L
: constant List_Id
:= New_List
;
11453 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
11454 Restricted
: constant Boolean := Restricted_Profile
;
11457 -- We may need two calls to properly initialize the object, one to
11458 -- Initialize_Protection, and possibly one to Install_Handlers if we
11459 -- have a pragma Attach_Handler.
11461 -- Get protected declaration. In the case of a task type declaration,
11462 -- this is simply the parent of the protected type entity. In the single
11463 -- protected object declaration, this parent will be the implicit type,
11464 -- and we can find the corresponding single protected object declaration
11465 -- by searching forward in the declaration list in the tree.
11467 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
11468 -- of this type should have been removed during semantic analysis.
11470 Pdec
:= Parent
(Ptyp
);
11471 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
11472 N_Single_Protected_Declaration
)
11477 -- Now we can find the object definition from this declaration
11479 Pdef
:= Protected_Definition
(Pdec
);
11481 -- Build the parameter list for the call. Note that _Init is the name
11482 -- of the formal for the object to be initialized, which is the task
11483 -- value record itself.
11487 -- Object parameter. This is a pointer to the object of type
11488 -- Protection used by the GNARL to control the protected object.
11491 Make_Attribute_Reference
(Loc
,
11493 Make_Selected_Component
(Loc
,
11494 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11495 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
11496 Attribute_Name
=> Name_Unchecked_Access
));
11498 -- Priority parameter. Set to Unspecified_Priority unless there is a
11499 -- priority pragma, in which case we take the value from the pragma,
11500 -- or there is an interrupt pragma and no priority pragma, and we
11501 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11502 -- defined value, see D.3(10).
11505 and then Has_Priority_Pragma
(Pdef
)
11508 Prio
: constant Node_Id
:=
11511 (Pragma_Argument_Associations
11512 (Find_Task_Or_Protected_Pragma
11513 (Pdef
, Name_Priority
))));
11517 -- If priority is a static expression, then we can duplicate it
11518 -- with no problem and simply append it to the argument list.
11520 if Is_Static_Expression
(Prio
) then
11522 Duplicate_Subexpr_No_Checks
(Prio
));
11524 -- Otherwise, the priority may be a per-object expression, if it
11525 -- depends on a discriminant of the type. In this case, create
11526 -- local variable to capture the expression. Note that it is
11527 -- really necessary to create this variable explicitly. It might
11528 -- be thought that removing side effects would the appropriate
11529 -- approach, but that could generate declarations improperly
11530 -- placed in the enclosing scope.
11532 -- Note: Use System.Any_Priority as the expected type for the
11533 -- non-static priority expression, in case the expression has not
11534 -- been analyzed yet (as occurs for example with pragma
11535 -- Interrupt_Priority).
11539 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
11542 Make_Object_Declaration
(Loc
,
11543 Defining_Identifier
=> Temp
,
11544 Object_Definition
=>
11545 New_Occurrence_Of
(RTE
(RE_Any_Priority
), Loc
),
11546 Expression
=> Relocate_Node
(Prio
)));
11548 Append_To
(Args
, New_Occurrence_Of
(Temp
, Loc
));
11552 -- When no priority is specified but an xx_Handler pragma is, we default
11553 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11555 elsif Has_Interrupt_Handler
(Ptyp
)
11556 or else Has_Attach_Handler
(Ptyp
)
11559 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
11561 -- Normal case, no priority or xx_Handler specified, default priority
11565 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
11568 -- Test for Compiler_Info parameter. This parameter allows entry body
11569 -- procedures and barrier functions to be called from the runtime. It
11570 -- is a pointer to the record generated by the compiler to represent
11571 -- the protected object.
11574 or else Has_Interrupt_Handler
(Ptyp
)
11575 or else Has_Attach_Handler
(Ptyp
)
11576 or else Has_Interfaces
(Protect_Rec
)
11579 Pkg_Id
: constant RTU_Id
:=
11580 Corresponding_Runtime_Package
(Ptyp
);
11581 Called_Subp
: RE_Id
;
11585 when System_Tasking_Protected_Objects_Entries
=>
11586 Called_Subp
:= RE_Initialize_Protection_Entries
;
11588 when System_Tasking_Protected_Objects
=>
11589 Called_Subp
:= RE_Initialize_Protection
;
11591 when System_Tasking_Protected_Objects_Single_Entry
=>
11592 Called_Subp
:= RE_Initialize_Protection_Entry
;
11595 raise Program_Error
;
11598 if Has_Entry
or else not Restricted
then
11600 Make_Attribute_Reference
(Loc
,
11601 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11602 Attribute_Name
=> Name_Address
));
11605 -- Entry_Bodies parameter. This is a pointer to an array of
11606 -- pointers to the entry body procedures and barrier functions of
11607 -- the object. If the protected type has no entries this object
11608 -- will not exist, in this case, pass a null.
11611 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
11614 Make_Attribute_Reference
(Loc
,
11615 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
11616 Attribute_Name
=> Name_Unrestricted_Access
));
11618 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
11620 -- Find index mapping function (clumsy but ok for now)
11622 while Ekind
(P_Arr
) /= E_Function
loop
11623 Next_Entity
(P_Arr
);
11627 Make_Attribute_Reference
(Loc
,
11629 New_Reference_To
(P_Arr
, Loc
),
11630 Attribute_Name
=> Name_Unrestricted_Access
));
11632 -- Build_Entry_Names generation flag. When set to true, the
11633 -- runtime will allocate an array to hold the string names
11634 -- of protected entries.
11636 if not Restricted_Profile
then
11637 if Entry_Names_OK
then
11639 New_Reference_To
(Standard_True
, Loc
));
11642 New_Reference_To
(Standard_False
, Loc
));
11647 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
11648 Append_To
(Args
, Make_Null
(Loc
));
11650 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
11651 Append_To
(Args
, Make_Null
(Loc
));
11652 Append_To
(Args
, Make_Null
(Loc
));
11653 Append_To
(Args
, New_Reference_To
(Standard_False
, Loc
));
11657 Make_Procedure_Call_Statement
(Loc
,
11658 Name
=> New_Reference_To
(RTE
(Called_Subp
), Loc
),
11659 Parameter_Associations
=> Args
));
11663 Make_Procedure_Call_Statement
(Loc
,
11664 Name
=> New_Reference_To
(RTE
(RE_Initialize_Protection
), Loc
),
11665 Parameter_Associations
=> Args
));
11668 if Has_Attach_Handler
(Ptyp
) then
11670 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11671 -- make the following call:
11673 -- Install_Handlers (_object,
11674 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11676 -- or, in the case of Ravenscar:
11678 -- Install_Restricted_Handlers
11679 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11682 Args
: constant List_Id
:= New_List
;
11683 Table
: constant List_Id
:= New_List
;
11684 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
11687 -- Build the Attach_Handler table argument
11689 while Present
(Ritem
) loop
11690 if Nkind
(Ritem
) = N_Pragma
11691 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
11694 Handler
: constant Node_Id
:=
11695 First
(Pragma_Argument_Associations
(Ritem
));
11697 Interrupt
: constant Node_Id
:= Next
(Handler
);
11698 Expr
: constant Node_Id
:= Expression
(Interrupt
);
11702 Make_Aggregate
(Loc
, Expressions
=> New_List
(
11703 Unchecked_Convert_To
11704 (RTE
(RE_System_Interrupt_Id
), Expr
),
11705 Make_Attribute_Reference
(Loc
,
11706 Prefix
=> Make_Selected_Component
(Loc
,
11707 Make_Identifier
(Loc
, Name_uInit
),
11708 Duplicate_Subexpr_No_Checks
11709 (Expression
(Handler
))),
11710 Attribute_Name
=> Name_Access
))));
11714 Next_Rep_Item
(Ritem
);
11717 -- Append the table argument we just built
11719 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
11721 -- Append the Install_Handlers (or Install_Restricted_Handlers)
11722 -- call to the statements.
11725 -- Call a simplified version of Install_Handlers to be used
11726 -- when the Ravenscar restrictions are in effect
11727 -- (Install_Restricted_Handlers).
11730 Make_Procedure_Call_Statement
(Loc
,
11733 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
11734 Parameter_Associations
=> Args
));
11737 -- First, prepends the _object argument
11740 Make_Attribute_Reference
(Loc
,
11742 Make_Selected_Component
(Loc
,
11743 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11744 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
11745 Attribute_Name
=> Name_Unchecked_Access
));
11747 -- Then, insert call to Install_Handlers
11750 Make_Procedure_Call_Statement
(Loc
,
11751 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
11752 Parameter_Associations
=> Args
));
11758 end Make_Initialize_Protection
;
11760 ---------------------------
11761 -- Make_Task_Create_Call --
11762 ---------------------------
11764 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
11765 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
11775 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
11776 Tnam
:= Chars
(Ttyp
);
11778 -- Get task declaration. In the case of a task type declaration, this is
11779 -- simply the parent of the task type entity. In the single task
11780 -- declaration, this parent will be the implicit type, and we can find
11781 -- the corresponding single task declaration by searching forward in the
11782 -- declaration list in the tree.
11784 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11785 -- this type should have been removed during semantic analysis.
11787 Tdec
:= Parent
(Ttyp
);
11788 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
11789 N_Single_Task_Declaration
)
11794 -- Now we can find the task definition from this declaration
11796 Tdef
:= Task_Definition
(Tdec
);
11798 -- Build the parameter list for the call. Note that _Init is the name
11799 -- of the formal for the object to be initialized, which is the task
11800 -- value record itself.
11804 -- Priority parameter. Set to Unspecified_Priority unless there is a
11805 -- priority pragma, in which case we take the value from the pragma.
11807 if Present
(Tdef
) and then Has_Priority_Pragma
(Tdef
) then
11809 Make_Selected_Component
(Loc
,
11810 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11811 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
11814 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
11817 -- Optional Stack parameter
11819 if Restricted_Profile
then
11821 -- If the stack has been preallocated by the expander then
11822 -- pass its address. Otherwise, pass a null address.
11824 if Preallocated_Stacks_On_Target
then
11826 Make_Attribute_Reference
(Loc
,
11827 Prefix
=> Make_Selected_Component
(Loc
,
11828 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11830 Make_Identifier
(Loc
, Name_uStack
)),
11831 Attribute_Name
=> Name_Address
));
11835 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
11839 -- Size parameter. If no Storage_Size pragma is present, then
11840 -- the size is taken from the taskZ variable for the type, which
11841 -- is either Unspecified_Size, or has been reset by the use of
11842 -- a Storage_Size attribute definition clause. If a pragma is
11843 -- present, then the size is taken from the _Size field of the
11844 -- task value record, which was set from the pragma value.
11847 and then Has_Storage_Size_Pragma
(Tdef
)
11850 Make_Selected_Component
(Loc
,
11851 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11852 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
11856 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
11859 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
11860 -- Task_Info pragma, in which case we take the value from the pragma.
11863 and then Has_Task_Info_Pragma
(Tdef
)
11866 Make_Selected_Component
(Loc
,
11867 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11868 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
11872 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
11875 if not Restricted_Profile
then
11877 -- Deadline parameter. If no Relative_Deadline pragma is present,
11878 -- then the deadline is Time_Span_Zero. If a pragma is present, then
11879 -- the deadline is taken from the _Relative_Deadline field of the
11880 -- task value record, which was set from the pragma value. Note that
11881 -- this parameter must not be generated for the restricted profiles
11882 -- since Ravenscar does not allow deadlines.
11884 -- Case where pragma Relative_Deadline applies: use given value
11886 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
11888 Make_Selected_Component
(Loc
,
11889 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11891 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
11893 -- No pragma Relative_Deadline apply to the task
11897 New_Reference_To
(RTE
(RE_Time_Span_Zero
), Loc
));
11900 -- Number of entries. This is an expression of the form:
11902 -- n + _Init.a'Length + _Init.a'B'Length + ...
11904 -- where a,b... are the entry family names for the task definition
11907 Build_Entry_Count_Expression
11912 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
11914 Append_To
(Args
, Ecount
);
11916 -- Master parameter. This is a reference to the _Master parameter of
11917 -- the initialization procedure, except in the case of the pragma
11918 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
11919 -- See comments in System.Tasking.Initialization.Init_RTS for the
11922 if Restriction_Active
(No_Task_Hierarchy
) = False then
11923 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
11925 Append_To
(Args
, Make_Integer_Literal
(Loc
, 3));
11929 -- State parameter. This is a pointer to the task body procedure. The
11930 -- required value is obtained by taking 'Unrestricted_Access of the task
11931 -- body procedure and converting it (with an unchecked conversion) to
11932 -- the type required by the task kernel. For further details, see the
11933 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
11934 -- than 'Address in order to avoid creating trampolines.
11937 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
11938 Subp_Ptr_Typ
: constant Node_Id
:=
11939 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
11940 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
11943 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
11944 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
11946 -- Be sure to freeze a reference to the access-to-subprogram type,
11947 -- otherwise gigi will complain that it's in the wrong scope, because
11948 -- it's actually inside the init procedure for the record type that
11949 -- corresponds to the task type.
11951 -- This processing is causing a crash in the .NET/JVM back ends that
11952 -- is not yet understood, so skip it in these cases ???
11954 if VM_Target
= No_VM
then
11955 Set_Itype
(Ref
, Subp_Ptr_Typ
);
11956 Append_Freeze_Action
(Task_Rec
, Ref
);
11959 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
11960 Make_Qualified_Expression
(Loc
,
11961 Subtype_Mark
=> New_Reference_To
(Subp_Ptr_Typ
, Loc
),
11963 Make_Attribute_Reference
(Loc
,
11965 New_Occurrence_Of
(Body_Proc
, Loc
),
11966 Attribute_Name
=> Name_Unrestricted_Access
))));
11968 -- For the .NET/JVM cases revert to the original code below ???
11972 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
11973 Make_Attribute_Reference
(Loc
,
11975 New_Occurrence_Of
(Body_Proc
, Loc
),
11976 Attribute_Name
=> Name_Address
)));
11980 -- Discriminants parameter. This is just the address of the task
11981 -- value record itself (which contains the discriminant values
11984 Make_Attribute_Reference
(Loc
,
11985 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
11986 Attribute_Name
=> Name_Address
));
11988 -- Elaborated parameter. This is an access to the elaboration Boolean
11991 Make_Attribute_Reference
(Loc
,
11992 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
11993 Attribute_Name
=> Name_Unchecked_Access
));
11995 -- Chain parameter. This is a reference to the _Chain parameter of
11996 -- the initialization procedure.
11998 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
12000 -- Task name parameter. Take this from the _Task_Id parameter to the
12001 -- init call unless there is a Task_Name pragma, in which case we take
12002 -- the value from the pragma.
12005 and then Has_Task_Name_Pragma
(Tdef
)
12009 Expression
(First
(
12010 Pragma_Argument_Associations
(
12011 Find_Task_Or_Protected_Pragma
12012 (Tdef
, Name_Task_Name
))))));
12015 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
12018 -- Created_Task parameter. This is the _Task_Id field of the task
12022 Make_Selected_Component
(Loc
,
12023 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12024 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
12026 -- Build_Entry_Names generation flag. When set to true, the runtime
12027 -- will allocate an array to hold the string names of task entries.
12029 if not Restricted_Profile
then
12030 if Has_Entries
(Ttyp
)
12031 and then Entry_Names_OK
12033 Append_To
(Args
, New_Reference_To
(Standard_True
, Loc
));
12035 Append_To
(Args
, New_Reference_To
(Standard_False
, Loc
));
12039 if Restricted_Profile
then
12040 Name
:= New_Reference_To
(RTE
(RE_Create_Restricted_Task
), Loc
);
12042 Name
:= New_Reference_To
(RTE
(RE_Create_Task
), Loc
);
12046 Make_Procedure_Call_Statement
(Loc
,
12048 Parameter_Associations
=> Args
);
12049 end Make_Task_Create_Call
;
12051 ------------------------------
12052 -- Next_Protected_Operation --
12053 ------------------------------
12055 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
12059 Next_Op
:= Next
(N
);
12060 while Present
(Next_Op
)
12061 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
12067 end Next_Protected_Operation
;
12069 ---------------------
12070 -- Null_Statements --
12071 ---------------------
12073 function Null_Statements
(Stats
: List_Id
) return Boolean is
12077 Stmt
:= First
(Stats
);
12078 while Nkind
(Stmt
) /= N_Empty
12079 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
12081 (Nkind
(Stmt
) = N_Pragma
12082 and then (Pragma_Name
(Stmt
) = Name_Unreferenced
12084 Pragma_Name
(Stmt
) = Name_Unmodified
12086 Pragma_Name
(Stmt
) = Name_Warnings
)))
12091 return Nkind
(Stmt
) = N_Empty
;
12092 end Null_Statements
;
12094 --------------------------
12095 -- Parameter_Block_Pack --
12096 --------------------------
12098 function Parameter_Block_Pack
12100 Blk_Typ
: Entity_Id
;
12104 Stmts
: List_Id
) return Node_Id
12106 Actual
: Entity_Id
;
12107 Expr
: Node_Id
:= Empty
;
12108 Formal
: Entity_Id
;
12109 Has_Param
: Boolean := False;
12112 Temp_Asn
: Node_Id
;
12113 Temp_Nam
: Node_Id
;
12116 Actual
:= First
(Actuals
);
12117 Formal
:= Defining_Identifier
(First
(Formals
));
12118 Params
:= New_List
;
12120 while Present
(Actual
) loop
12121 if Is_By_Copy_Type
(Etype
(Actual
)) then
12123 -- Jnn : aliased <formal-type>
12126 Make_Defining_Identifier
(Loc
, New_Internal_Name
('J'));
12129 Make_Object_Declaration
(Loc
,
12132 Defining_Identifier
=>
12134 Object_Definition
=>
12135 New_Reference_To
(Etype
(Formal
), Loc
)));
12137 if Ekind
(Formal
) /= E_Out_Parameter
then
12143 New_Reference_To
(Temp_Nam
, Loc
);
12145 Set_Assignment_OK
(Temp_Asn
);
12148 Make_Assignment_Statement
(Loc
,
12152 New_Copy_Tree
(Actual
)));
12156 -- Jnn'unchecked_access
12159 Make_Attribute_Reference
(Loc
,
12161 Name_Unchecked_Access
,
12163 New_Reference_To
(Temp_Nam
, Loc
)));
12167 -- The controlling parameter is omitted
12170 if not Is_Controlling_Actual
(Actual
) then
12172 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
12178 Next_Actual
(Actual
);
12179 Next_Formal_With_Extras
(Formal
);
12183 Expr
:= Make_Aggregate
(Loc
, Params
);
12188 -- J1'unchecked_access;
12189 -- <actual2>'reference;
12192 P
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
12195 Make_Object_Declaration
(Loc
,
12196 Defining_Identifier
=>
12198 Object_Definition
=>
12199 New_Reference_To
(Blk_Typ
, Loc
),
12204 end Parameter_Block_Pack
;
12206 ----------------------------
12207 -- Parameter_Block_Unpack --
12208 ----------------------------
12210 function Parameter_Block_Unpack
12214 Formals
: List_Id
) return List_Id
12216 Actual
: Entity_Id
;
12218 Formal
: Entity_Id
;
12219 Has_Asnmt
: Boolean := False;
12220 Result
: constant List_Id
:= New_List
;
12223 Actual
:= First
(Actuals
);
12224 Formal
:= Defining_Identifier
(First
(Formals
));
12225 while Present
(Actual
) loop
12226 if Is_By_Copy_Type
(Etype
(Actual
))
12227 and then Ekind
(Formal
) /= E_In_Parameter
12230 -- <actual> := P.<formal>;
12233 Make_Assignment_Statement
(Loc
,
12237 Make_Explicit_Dereference
(Loc
,
12238 Make_Selected_Component
(Loc
,
12240 New_Reference_To
(P
, Loc
),
12242 Make_Identifier
(Loc
, Chars
(Formal
)))));
12244 Set_Assignment_OK
(Name
(Asnmt
));
12245 Append_To
(Result
, Asnmt
);
12250 Next_Actual
(Actual
);
12251 Next_Formal_With_Extras
(Formal
);
12257 return New_List
(Make_Null_Statement
(Loc
));
12259 end Parameter_Block_Unpack
;
12261 ----------------------
12262 -- Set_Discriminals --
12263 ----------------------
12265 procedure Set_Discriminals
(Dec
: Node_Id
) is
12268 D_Minal
: Entity_Id
;
12271 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
12272 Pdef
:= Defining_Identifier
(Dec
);
12274 if Has_Discriminants
(Pdef
) then
12275 D
:= First_Discriminant
(Pdef
);
12276 while Present
(D
) loop
12278 Make_Defining_Identifier
(Sloc
(D
),
12279 Chars
=> New_External_Name
(Chars
(D
), 'D'));
12281 Set_Ekind
(D_Minal
, E_Constant
);
12282 Set_Etype
(D_Minal
, Etype
(D
));
12283 Set_Scope
(D_Minal
, Pdef
);
12284 Set_Discriminal
(D
, D_Minal
);
12285 Set_Discriminal_Link
(D_Minal
, D
);
12287 Next_Discriminant
(D
);
12290 end Set_Discriminals
;
12292 -----------------------
12293 -- Trivial_Accept_OK --
12294 -----------------------
12296 function Trivial_Accept_OK
return Boolean is
12298 case Opt
.Task_Dispatching_Policy
is
12300 -- If we have the default task dispatching policy in effect, we can
12301 -- definitely do the optimization (one way of looking at this is to
12302 -- think of the formal definition of the default policy being allowed
12303 -- to run any task it likes after a rendezvous, so even if notionally
12304 -- a full rescheduling occurs, we can say that our dispatching policy
12305 -- (i.e. the default dispatching policy) reorders the queue to be the
12306 -- same as just before the call.
12311 -- FIFO_Within_Priorities certainly certainly does not permit this
12312 -- optimization since the Rendezvous is a scheduling action that may
12313 -- require some other task to be run.
12318 -- For now, disallow the optimization for all other policies. This
12319 -- may be over-conservative, but it is certainly not incorrect.
12325 end Trivial_Accept_OK
;