1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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_Ch6
; use Exp_Ch6
;
33 with Exp_Ch11
; use Exp_Ch11
;
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_Aux
; use Sem_Aux
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Ch11
; use Sem_Ch11
;
55 with Sem_Elab
; use Sem_Elab
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Util
; use Sem_Util
;
59 with Sinfo
; use Sinfo
;
60 with Snames
; use Snames
;
61 with Stand
; use Stand
;
62 with Stringt
; use Stringt
;
63 with Targparm
; use Targparm
;
64 with Tbuild
; use Tbuild
;
65 with Uintp
; use Uintp
;
67 package body Exp_Ch9
is
69 -- The following constant establishes the upper bound for the index of
70 -- an entry family. It is used to limit the allocated size of protected
71 -- types with defaulted discriminant of an integer type, when the bound
72 -- of some entry family depends on a discriminant. The limitation to
73 -- entry families of 128K should be reasonable in all cases, and is a
74 -- documented implementation restriction. It will be lifted when protected
75 -- entry families are re-implemented as a single ordered queue.
77 Entry_Family_Bound
: constant Int
:= 2**16;
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 function Actual_Index_Expression
87 Tsk
: Entity_Id
) return Node_Id
;
88 -- Compute the index position for an entry call. Tsk is the target task. If
89 -- the bounds of some entry family depend on discriminants, the expression
90 -- computed by this function uses the discriminants of the target task.
92 procedure Add_Object_Pointer
96 -- Prepend an object pointer declaration to the declaration list Decls.
97 -- This object pointer is initialized to a type conversion of the System.
98 -- Address pointer passed to entry barrier functions and entry body
101 procedure Add_Formal_Renamings
106 -- Create renaming declarations for the formals, inside the procedure that
107 -- implements an entry body. The renamings make the original names of the
108 -- formals accessible to gdb, and serve no other purpose.
109 -- Spec is the specification of the procedure being built.
110 -- Decls is the list of declarations to be enhanced.
111 -- Ent is the entity for the original entry body.
113 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
114 -- Transform accept statement into a block with added exception handler.
115 -- Used both for simple accept statements and for accept alternatives in
116 -- select statements. Astat is the accept statement.
118 function Build_Barrier_Function
121 Pid
: Node_Id
) return Node_Id
;
122 -- Build the function body returning the value of the barrier expression
123 -- for the specified entry body.
125 function Build_Barrier_Function_Specification
127 Def_Id
: Entity_Id
) return Node_Id
;
128 -- Build a specification for a function implementing the protected entry
129 -- barrier of the specified entry body.
131 function Build_Corresponding_Record
134 Loc
: Source_Ptr
) return Node_Id
;
135 -- Common to tasks and protected types. Copy discriminant specifications,
136 -- build record declaration. N is the type declaration, Ctyp is the
137 -- concurrent entity (task type or protected type).
139 function Build_Entry_Count_Expression
140 (Concurrent_Type
: Node_Id
;
141 Component_List
: List_Id
;
142 Loc
: Source_Ptr
) return Node_Id
;
143 -- Compute number of entries for concurrent object. This is a count of
144 -- simple entries, followed by an expression that computes the length
145 -- of the range of each entry family. A single array with that size is
146 -- allocated for each concurrent object of the type.
148 function Build_Parameter_Block
152 Decls
: List_Id
) return Entity_Id
;
153 -- Generate an access type for each actual parameter in the list Actuals.
154 -- Create an encapsulating record that contains all the actuals and return
155 -- its type. Generate:
156 -- type Ann1 is access all <actual1-type>
158 -- type AnnN is access all <actualN-type>
159 -- type Pnn is record
165 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
166 -- Build body of wrapper procedure for an entry or entry family that has
167 -- pre/postconditions. The body gathers the PPC's and expands them in the
168 -- usual way, and performs the entry call itself. This way preconditions
169 -- are evaluated before the call is queued. E is the entry in question,
170 -- and Decl is the enclosing synchronized type declaration at whose
171 -- freeze point the generated body is analyzed.
173 procedure Build_Wrapper_Bodies
177 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
178 -- record of a concurrent type. N is the insertion node where all bodies
179 -- will be placed. This routine builds the bodies of the subprograms which
180 -- serve as an indirection mechanism to overriding primitives of concurrent
181 -- types, entries and protected procedures. Any new body is analyzed.
183 procedure Build_Wrapper_Specs
187 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
188 -- record of a concurrent type. N is the insertion node where all specs
189 -- will be placed. This routine builds the specs of the subprograms which
190 -- serve as an indirection mechanism to overriding primitives of concurrent
191 -- types, entries and protected procedures. Any new spec is analyzed.
193 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
194 -- Build the function that translates the entry index in the call
195 -- (which depends on the size of entry families) into an index into the
196 -- Entry_Bodies_Array, to determine the body and barrier function used
197 -- in a protected entry call. A pointer to this function appears in every
200 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
201 -- Build subprogram declaration for previous one
203 function Build_Protected_Entry
206 Pid
: Node_Id
) return Node_Id
;
207 -- Build the procedure implementing the statement sequence of the specified
210 function Build_Protected_Entry_Specification
213 Ent_Id
: Entity_Id
) return Node_Id
;
214 -- Build a specification for the procedure implementing the statements of
215 -- the specified entry body. Add attributes associating it with the entry
216 -- defining identifier Ent_Id.
218 function Build_Protected_Spec
220 Obj_Type
: Entity_Id
;
222 Unprotected
: Boolean := False) return List_Id
;
223 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
224 -- Subprogram_Type. Builds signature of protected subprogram, adding the
225 -- formal that corresponds to the object itself. For an access to protected
226 -- subprogram, there is no object type to specify, so the parameter has
227 -- type Address and mode In. An indirect call through such a pointer will
228 -- convert the address to a reference to the actual object. The object is
229 -- a limited record and therefore a by_reference type.
231 function Build_Protected_Subprogram_Body
234 N_Op_Spec
: Node_Id
) return Node_Id
;
235 -- This function is used to construct the protected version of a protected
236 -- subprogram. Its statement sequence first defers abort, then locks
237 -- the associated protected object, and then enters a block that contains
238 -- a call to the unprotected version of the subprogram (for details, see
239 -- Build_Unprotected_Subprogram_Body). This block statement requires
240 -- a cleanup handler that unlocks the object in all cases.
241 -- (see Exp_Ch7.Expand_Cleanup_Actions).
243 function Build_Selected_Name
245 Selector
: Entity_Id
;
246 Append_Char
: Character := ' ') return Name_Id
;
247 -- Build a name in the form of Prefix__Selector, with an optional
248 -- character appended. This is used for internal subprograms generated
249 -- for operations of protected types, including barrier functions.
250 -- For the subprograms generated for entry bodies and entry barriers,
251 -- the generated name includes a sequence number that makes names
252 -- unique in the presence of entry overloading. This is necessary
253 -- because entry body procedures and barrier functions all have the
256 procedure Build_Simple_Entry_Call
261 -- Some comments here would be useful ???
263 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
264 -- This routine constructs a specification for the procedure that we will
265 -- build for the task body for task type T. The spec has the form:
267 -- procedure tnameB (_Task : access tnameV);
269 -- where name is the character name taken from the task type entity that
270 -- is passed as the argument to the procedure, and tnameV is the task
271 -- value type that is associated with the task type.
273 function Build_Unprotected_Subprogram_Body
275 Pid
: Node_Id
) return Node_Id
;
276 -- This routine constructs the unprotected version of a protected
277 -- subprogram body, which is contains all of the code in the
278 -- original, unexpanded body. This is the version of the protected
279 -- subprogram that is called from all protected operations on the same
280 -- object, including the protected version of the same subprogram.
282 procedure Collect_Entry_Families
285 Current_Node
: in out Node_Id
;
286 Conctyp
: Entity_Id
);
287 -- For each entry family in a concurrent type, create an anonymous array
288 -- type of the right size, and add a component to the corresponding_record.
290 function Concurrent_Object
291 (Spec_Id
: Entity_Id
;
292 Conc_Typ
: Entity_Id
) return Entity_Id
;
293 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
294 -- the entity associated with the concurrent object in the Protected_Body_
295 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
296 -- denotes formal parameter _O, _object or _task.
298 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
299 -- Copy the result type of a function specification, when building the
300 -- internal operation corresponding to a protected function, or when
301 -- expanding an access to protected function. If the result is an anonymous
302 -- access to subprogram itself, we need to create a new signature with the
303 -- same parameter names and the same resolved types, but with new entities
306 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
307 -- Decls is a list which may contain the declarations created by Install_
308 -- Private_Data_Declarations. All generated entities are marked as needing
309 -- debug info and debug nodes are manually generation where necessary. This
310 -- step of the expansion must to be done after private data has been moved
311 -- to its final resting scope to ensure proper visibility of debug objects.
313 function Family_Offset
318 Cap
: Boolean) return Node_Id
;
319 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
320 -- an accept statement, or the upper bound in the discrete subtype of
321 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
322 -- the concurrent type of the entry. If Cap is true, the result is
323 -- capped according to Entry_Family_Bound.
330 Cap
: Boolean) return Node_Id
;
331 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
332 -- a family, and handle properly the superflat case. This is equivalent
333 -- to the use of 'Length on the index type, but must use Family_Offset
334 -- to handle properly the case of bounds that depend on discriminants.
335 -- If Cap is true, the result is capped according to Entry_Family_Bound.
337 procedure Extract_Dispatching_Call
339 Call_Ent
: out Entity_Id
;
340 Object
: out Entity_Id
;
341 Actuals
: out List_Id
;
342 Formals
: out List_Id
);
343 -- Given a dispatching call, extract the entity of the name of the call,
344 -- its object parameter, its actual parameters and the formal parameters
345 -- of the overridden interface-level version.
347 procedure Extract_Entry
349 Concval
: out Node_Id
;
351 Index
: out Node_Id
);
352 -- Given an entry call, returns the associated concurrent object,
353 -- the entry name, and the entry family index.
355 function Find_Task_Or_Protected_Pragma
357 P
: Name_Id
) return Node_Id
;
358 -- Searches the task or protected definition T for the first occurrence
359 -- of the pragma whose name is given by P. The caller has ensured that
360 -- the pragma is present in the task definition. A special case is that
361 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
362 -- ??? Should be implemented with the rep item chain mechanism.
364 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
365 -- Given a subprogram identifier, return the entity which is associated
366 -- with the protection entry index in the Protected_Body_Subprogram or the
367 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
370 function Is_Potentially_Large_Family
371 (Base_Index
: Entity_Id
;
374 Hi
: Node_Id
) return Boolean;
376 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
377 -- Determine whether Id is a function or a procedure and is marked as a
378 -- private primitive.
380 function Null_Statements
(Stats
: List_Id
) return Boolean;
381 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
382 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
383 -- well to still count as null. Returns True for a null sequence. The
384 -- argument is the list of statements from the DO-END sequence.
386 function Parameter_Block_Pack
392 Stmts
: List_Id
) return Entity_Id
;
393 -- Set the components of the generated parameter block with the values of
394 -- the actual parameters. Generate aliased temporaries to capture the
395 -- values for types that are passed by copy. Otherwise generate a reference
396 -- to the actual's value. Return the address of the aggregate block.
398 -- Jnn1 : alias <formal-type1>;
399 -- Jnn1 := <actual1>;
402 -- Jnn1'unchecked_access;
403 -- <actual2>'reference;
406 function Parameter_Block_Unpack
410 Formals
: List_Id
) return List_Id
;
411 -- Retrieve the values of the components from the parameter block and
412 -- assign then to the original actual parameters. Generate:
413 -- <actual1> := P.<formal1>;
415 -- <actualN> := P.<formalN>;
417 function Trivial_Accept_OK
return Boolean;
418 -- If there is no DO-END block for an accept, or if the DO-END block has
419 -- only null statements, then it is possible to do the Rendezvous with much
420 -- less overhead using the Accept_Trivial routine in the run-time library.
421 -- However, this is not always a valid optimization. Whether it is valid or
422 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
423 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
424 -- a rescheduling is required, so this optimization is not allowed. This
425 -- function returns True if the optimization is permitted.
427 -----------------------------
428 -- Actual_Index_Expression --
429 -----------------------------
431 function Actual_Index_Expression
435 Tsk
: Entity_Id
) return Node_Id
437 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
445 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
446 -- Compute difference between bounds of entry family
448 --------------------------
449 -- Actual_Family_Offset --
450 --------------------------
452 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
454 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
455 -- Replace a reference to a discriminant with a selected component
456 -- denoting the discriminant of the target task.
458 -----------------------------
459 -- Actual_Discriminant_Ref --
460 -----------------------------
462 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
463 Typ
: constant Entity_Id
:= Etype
(Bound
);
467 if not Is_Entity_Name
(Bound
)
468 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
470 if Nkind
(Bound
) = N_Attribute_Reference
then
473 B
:= New_Copy_Tree
(Bound
);
478 Make_Selected_Component
(Sloc
,
479 Prefix
=> New_Copy_Tree
(Tsk
),
480 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
482 Analyze_And_Resolve
(B
, Typ
);
486 Make_Attribute_Reference
(Sloc
,
487 Attribute_Name
=> Name_Pos
,
488 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
489 Expressions
=> New_List
(B
));
490 end Actual_Discriminant_Ref
;
492 -- Start of processing for Actual_Family_Offset
496 Make_Op_Subtract
(Sloc
,
497 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
498 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
499 end Actual_Family_Offset
;
501 -- Start of processing for Actual_Index_Expression
504 -- The queues of entries and entry families appear in textual order in
505 -- the associated record. The entry index is computed as the sum of the
506 -- number of queues for all entries that precede the designated one, to
507 -- which is added the index expression, if this expression denotes a
508 -- member of a family.
510 -- The following is a place holder for the count of simple entries
512 Num
:= Make_Integer_Literal
(Sloc
, 1);
514 -- We construct an expression which is a series of addition operations.
515 -- See comments in Entry_Index_Expression, which is identical in
518 if Present
(Index
) then
519 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
526 Actual_Family_Offset
(
527 Make_Attribute_Reference
(Sloc
,
528 Attribute_Name
=> Name_Pos
,
529 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
530 Expressions
=> New_List
(Relocate_Node
(Index
))),
531 Type_Low_Bound
(S
)));
536 -- Now add lengths of preceding entries and entry families
538 Prev
:= First_Entity
(Ttyp
);
540 while Chars
(Prev
) /= Chars
(Ent
)
541 or else (Ekind
(Prev
) /= Ekind
(Ent
))
542 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
544 if Ekind
(Prev
) = E_Entry
then
545 Set_Intval
(Num
, Intval
(Num
) + 1);
547 elsif Ekind
(Prev
) = E_Entry_Family
then
549 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
551 -- The need for the following full view retrieval stems from
552 -- this complex case of nested generics and tasking:
555 -- type Formal_Index is range <>;
558 -- type Index is private;
565 -- type Index is new Formal_Index range 1 .. 10;
568 -- package body Outer is
570 -- entry Fam (Index); -- (2)
573 -- package body Inner is -- (3)
581 -- We are currently building the index expression for the entry
582 -- call "T.E" (1). Part of the expansion must mention the range
583 -- of the discrete type "Index" (2) of entry family "Fam".
584 -- However only the private view of type "Index" is available to
585 -- the inner generic (3) because there was no prior mention of
586 -- the type inside "Inner". This visibility requirement is
587 -- implicit and cannot be detected during the construction of
588 -- the generic trees and needs special handling.
591 and then Is_Private_Type
(S
)
592 and then Present
(Full_View
(S
))
597 Lo
:= Type_Low_Bound
(S
);
598 Hi
:= Type_High_Bound
(S
);
606 Actual_Family_Offset
(Hi
, Lo
),
608 Make_Integer_Literal
(Sloc
, 1)));
610 -- Other components are anonymous types to be ignored
620 end Actual_Index_Expression
;
622 --------------------------
623 -- Add_Formal_Renamings --
624 --------------------------
626 procedure Add_Formal_Renamings
632 Ptr
: constant Entity_Id
:=
634 (Next
(First
(Parameter_Specifications
(Spec
))));
635 -- The name of the formal that holds the address of the parameter block
644 Formal
:= First_Formal
(Ent
);
645 while Present
(Formal
) loop
646 Comp
:= Entry_Component
(Formal
);
648 Make_Defining_Identifier
(Sloc
(Formal
),
649 Chars
=> Chars
(Formal
));
650 Set_Etype
(New_F
, Etype
(Formal
));
651 Set_Scope
(New_F
, Ent
);
653 -- Now we set debug info needed on New_F even though it does not
654 -- come from source, so that the debugger will get the right
655 -- information for these generated names.
657 Set_Debug_Info_Needed
(New_F
);
659 if Ekind
(Formal
) = E_In_Parameter
then
660 Set_Ekind
(New_F
, E_Constant
);
662 Set_Ekind
(New_F
, E_Variable
);
663 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
666 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
669 Make_Object_Renaming_Declaration
(Loc
,
670 Defining_Identifier
=> New_F
,
672 New_Reference_To
(Etype
(Formal
), Loc
),
674 Make_Explicit_Dereference
(Loc
,
675 Make_Selected_Component
(Loc
,
677 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
678 Make_Identifier
(Loc
, Chars
(Ptr
))),
680 New_Reference_To
(Comp
, Loc
))));
682 Append
(Decl
, Decls
);
683 Set_Renamed_Object
(Formal
, New_F
);
684 Next_Formal
(Formal
);
686 end Add_Formal_Renamings
;
688 ------------------------
689 -- Add_Object_Pointer --
690 ------------------------
692 procedure Add_Object_Pointer
694 Conc_Typ
: Entity_Id
;
697 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
702 -- Create the renaming declaration for the Protection object of a
703 -- protected type. _Object is used by Complete_Entry_Body.
704 -- ??? An attempt to make this a renaming was unsuccessful.
706 -- Build the entity for the access type
709 Make_Defining_Identifier
(Loc
,
710 New_External_Name
(Chars
(Rec_Typ
), 'P'));
713 -- _object : poVP := poVP!O;
716 Make_Object_Declaration
(Loc
,
717 Defining_Identifier
=>
718 Make_Defining_Identifier
(Loc
, Name_uObject
),
720 New_Reference_To
(Obj_Ptr
, Loc
),
722 Unchecked_Convert_To
(Obj_Ptr
,
723 Make_Identifier
(Loc
, Name_uO
)));
724 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
725 Prepend_To
(Decls
, Decl
);
728 -- type poVP is access poV;
731 Make_Full_Type_Declaration
(Loc
,
732 Defining_Identifier
=>
735 Make_Access_To_Object_Definition
(Loc
,
736 Subtype_Indication
=>
737 New_Reference_To
(Rec_Typ
, Loc
)));
738 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
739 Prepend_To
(Decls
, Decl
);
740 end Add_Object_Pointer
;
742 -----------------------
743 -- Build_Accept_Body --
744 -----------------------
746 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
747 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
748 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
755 -- At the end of the statement sequence, Complete_Rendezvous is called.
756 -- A label skipping the Complete_Rendezvous, and all other accept
757 -- processing, has already been added for the expansion of requeue
758 -- statements. The Sloc is copied from the last statement since it
759 -- is really part of this last statement.
763 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
764 Insert_Before
(Last
(Statements
(Stats
)), Call
);
767 -- If exception handlers are present, then append Complete_Rendezvous
768 -- calls to the handlers, and construct the required outer block. As
769 -- above, the Sloc is copied from the last statement in the sequence.
771 if Present
(Exception_Handlers
(Stats
)) then
772 Hand
:= First
(Exception_Handlers
(Stats
));
773 while Present
(Hand
) loop
776 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
777 Append
(Call
, Statements
(Hand
));
783 Make_Handled_Sequence_Of_Statements
(Loc
,
784 Statements
=> New_List
(
785 Make_Block_Statement
(Loc
,
786 Handled_Statement_Sequence
=> Stats
)));
792 -- At this stage we know that the new statement sequence does not
793 -- have an exception handler part, so we supply one to call
794 -- Exceptional_Complete_Rendezvous. This handler is
796 -- when all others =>
797 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
799 -- We handle Abort_Signal to make sure that we properly catch the abort
800 -- case and wake up the caller.
802 Ohandle
:= Make_Others_Choice
(Loc
);
803 Set_All_Others
(Ohandle
);
805 Set_Exception_Handlers
(New_S
,
807 Make_Implicit_Exception_Handler
(Loc
,
808 Exception_Choices
=> New_List
(Ohandle
),
810 Statements
=> New_List
(
811 Make_Procedure_Call_Statement
(Sloc
(Stats
),
812 Name
=> New_Reference_To
(
813 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
814 Parameter_Associations
=> New_List
(
815 Make_Function_Call
(Sloc
(Stats
),
816 Name
=> New_Reference_To
(
817 RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
819 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
820 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
821 Expand_Exception_Handlers
(New_S
);
823 -- Exceptional_Complete_Rendezvous must be called with abort
824 -- still deferred, which is the case for a "when all others" handler.
827 end Build_Accept_Body
;
829 -----------------------------------
830 -- Build_Activation_Chain_Entity --
831 -----------------------------------
833 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
839 -- Loop to find enclosing construct containing activation chain variable
840 -- The construct is a body, a block, or an extended return.
844 while not Nkind_In
(P
, N_Subprogram_Body
,
846 N_Package_Declaration
,
850 N_Extended_Return_Statement
)
855 -- If we are in a package body, the activation chain variable is
856 -- declared in the body, but the Activation_Chain_Entity is attached
859 if Nkind
(P
) = N_Package_Body
then
860 Decls
:= Declarations
(P
);
861 P
:= Unit_Declaration_Node
(Corresponding_Spec
(P
));
863 elsif Nkind
(P
) = N_Package_Declaration
then
864 Decls
:= Visible_Declarations
(Specification
(P
));
866 elsif Nkind
(P
) = N_Extended_Return_Statement
then
867 Decls
:= Return_Object_Declarations
(P
);
870 Decls
:= Declarations
(P
);
873 -- If activation chain entity not already declared, declare it
875 if Nkind
(P
) = N_Extended_Return_Statement
876 or else No
(Activation_Chain_Entity
(P
))
878 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
880 -- Note: An extended return statement is not really a task activator,
881 -- but it does have an activation chain on which to store the tasks
882 -- temporarily. On successful return, the tasks on this chain are
883 -- moved to the chain passed in by the caller. We do not build an
884 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
885 -- because we do not want to build a call to Activate_Tasks. Task
886 -- activation is the responsibility of the caller.
888 if Nkind
(P
) /= N_Extended_Return_Statement
then
889 Set_Activation_Chain_Entity
(P
, Chain
);
893 Make_Object_Declaration
(Sloc
(P
),
894 Defining_Identifier
=> Chain
,
895 Aliased_Present
=> True,
897 New_Reference_To
(RTE
(RE_Activation_Chain
), Sloc
(P
))));
899 Analyze
(First
(Decls
));
901 end Build_Activation_Chain_Entity
;
903 ----------------------------
904 -- Build_Barrier_Function --
905 ----------------------------
907 function Build_Barrier_Function
910 Pid
: Node_Id
) return Node_Id
912 Loc
: constant Source_Ptr
:= Sloc
(N
);
913 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
914 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
915 Op_Decls
: constant List_Id
:= New_List
;
919 -- Add a declaration for the Protection object, renaming declarations
920 -- for the discriminals and privals and finally a declaration for the
921 -- entry family index (if applicable).
923 Install_Private_Data_Declarations
924 (Loc
, Func_Id
, Pid
, N
, Op_Decls
, True, Ekind
(Ent
) = E_Entry_Family
);
926 -- Note: the condition in the barrier function needs to be properly
927 -- processed for the C/Fortran boolean possibility, but this happens
928 -- automatically since the return statement does this normalization.
931 Make_Subprogram_Body
(Loc
,
933 Build_Barrier_Function_Specification
(Loc
,
934 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
935 Declarations
=> Op_Decls
,
936 Handled_Statement_Sequence
=>
937 Make_Handled_Sequence_Of_Statements
(Loc
,
938 Statements
=> New_List
(
939 Make_Simple_Return_Statement
(Loc
,
940 Expression
=> Condition
(Ent_Formals
)))));
941 Set_Is_Entry_Barrier_Function
(Func_Body
);
944 end Build_Barrier_Function
;
946 ------------------------------------------
947 -- Build_Barrier_Function_Specification --
948 ------------------------------------------
950 function Build_Barrier_Function_Specification
952 Def_Id
: Entity_Id
) return Node_Id
955 Set_Debug_Info_Needed
(Def_Id
);
957 return Make_Function_Specification
(Loc
,
958 Defining_Unit_Name
=> Def_Id
,
959 Parameter_Specifications
=> New_List
(
960 Make_Parameter_Specification
(Loc
,
961 Defining_Identifier
=>
962 Make_Defining_Identifier
(Loc
, Name_uO
),
964 New_Reference_To
(RTE
(RE_Address
), Loc
)),
966 Make_Parameter_Specification
(Loc
,
967 Defining_Identifier
=>
968 Make_Defining_Identifier
(Loc
, Name_uE
),
970 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
973 New_Reference_To
(Standard_Boolean
, Loc
));
974 end Build_Barrier_Function_Specification
;
976 --------------------------
977 -- Build_Call_With_Task --
978 --------------------------
980 function Build_Call_With_Task
982 E
: Entity_Id
) return Node_Id
984 Loc
: constant Source_Ptr
:= Sloc
(N
);
987 Make_Function_Call
(Loc
,
988 Name
=> New_Reference_To
(E
, Loc
),
989 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
990 end Build_Call_With_Task
;
992 --------------------------------
993 -- Build_Corresponding_Record --
994 --------------------------------
996 function Build_Corresponding_Record
999 Loc
: Source_Ptr
) return Node_Id
1001 Rec_Ent
: constant Entity_Id
:=
1002 Make_Defining_Identifier
1003 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1006 New_Disc
: Entity_Id
;
1010 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1011 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1012 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1013 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1014 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1015 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1018 -- Use discriminals to create list of discriminants for record, and
1019 -- create new discriminals for use in default expressions, etc. It is
1020 -- worth noting that a task discriminant gives rise to 5 entities;
1022 -- a) The original discriminant.
1023 -- b) The discriminal for use in the task.
1024 -- c) The discriminant of the corresponding record.
1025 -- d) The discriminal for the init proc of the corresponding record.
1026 -- e) The local variable that renames the discriminant in the procedure
1027 -- for the task body.
1029 -- In fact the discriminals b) are used in the renaming declarations
1030 -- for e). See details in einfo (Handling of Discriminants).
1032 if Present
(Discriminant_Specifications
(N
)) then
1034 Disc
:= First_Discriminant
(Ctyp
);
1036 while Present
(Disc
) loop
1037 New_Disc
:= CR_Discriminant
(Disc
);
1040 Make_Discriminant_Specification
(Loc
,
1041 Defining_Identifier
=> New_Disc
,
1042 Discriminant_Type
=>
1043 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1045 New_Copy
(Discriminant_Default_Value
(Disc
))));
1047 Next_Discriminant
(Disc
);
1054 -- Now we can construct the record type declaration. Note that this
1055 -- record is "limited tagged". It is "limited" to reflect the underlying
1056 -- limitedness of the task or protected object that it represents, and
1057 -- ensuring for example that it is properly passed by reference. It is
1058 -- "tagged" to give support to dispatching calls through interfaces. We
1059 -- propagate here the list of interfaces covered by the concurrent type
1060 -- (Ada 2005: AI-345).
1063 Make_Full_Type_Declaration
(Loc
,
1064 Defining_Identifier
=> Rec_Ent
,
1065 Discriminant_Specifications
=> Dlist
,
1067 Make_Record_Definition
(Loc
,
1069 Make_Component_List
(Loc
,
1070 Component_Items
=> Cdecls
),
1072 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1073 Interface_List
=> Interface_List
(N
),
1074 Limited_Present
=> True));
1075 end Build_Corresponding_Record
;
1077 ----------------------------------
1078 -- Build_Entry_Count_Expression --
1079 ----------------------------------
1081 function Build_Entry_Count_Expression
1082 (Concurrent_Type
: Node_Id
;
1083 Component_List
: List_Id
;
1084 Loc
: Source_Ptr
) return Node_Id
1096 -- Count number of non-family entries
1099 Ent
:= First_Entity
(Concurrent_Type
);
1100 while Present
(Ent
) loop
1101 if Ekind
(Ent
) = E_Entry
then
1108 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1110 -- Loop through entry families building the addition nodes
1112 Ent
:= First_Entity
(Concurrent_Type
);
1113 Comp
:= First
(Component_List
);
1114 while Present
(Ent
) loop
1115 if Ekind
(Ent
) = E_Entry_Family
then
1116 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1120 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1121 Hi
:= Type_High_Bound
(Typ
);
1122 Lo
:= Type_Low_Bound
(Typ
);
1123 Large
:= Is_Potentially_Large_Family
1124 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1127 Left_Opnd
=> Ecount
,
1128 Right_Opnd
=> Family_Size
1129 (Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1136 end Build_Entry_Count_Expression
;
1138 -----------------------
1139 -- Build_Entry_Names --
1140 -----------------------
1142 function Build_Entry_Names
(Conc_Typ
: Entity_Id
) return Node_Id
is
1143 Loc
: constant Source_Ptr
:= Sloc
(Conc_Typ
);
1149 Typ
: Entity_Id
:= Conc_Typ
;
1151 procedure Build_Entry_Family_Name
(Id
: Entity_Id
);
1153 -- for Lnn in Family_Low .. Family_High loop
1156 -- (_init._object <or> _init._task_id,
1158 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1160 -- Note that the bounds of the range may reference discriminants. The
1161 -- above construct is added directly to the statements of the block.
1163 procedure Build_Entry_Name
(Id
: Entity_Id
);
1167 -- (_init._object <or>_init._task_id,
1169 -- new String ("<Entry name>");
1170 -- The above construct is added directly to the statements of the block.
1172 function Build_Set_Entry_Name_Call
(Arg3
: Node_Id
) return Node_Id
;
1173 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1174 -- _init._task_id or _init._object, Inn and Arg3.
1176 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
;
1177 -- Given a protected type or its corresponding record, find the type of
1180 procedure Increment_Index
(Stmts
: List_Id
);
1181 -- Generate the following and add it to Stmts
1184 -----------------------------
1185 -- Build_Entry_Family_Name --
1186 -----------------------------
1188 procedure Build_Entry_Family_Name
(Id
: Entity_Id
) is
1189 Def
: constant Node_Id
:=
1190 Discrete_Subtype_Definition
(Parent
(Id
));
1191 L_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'L');
1192 L_Stmts
: constant List_Id
:= New_List
;
1195 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1196 -- Given a discrete subtype definition of an entry family, generate a
1197 -- range node which covers the range of Def's type.
1203 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1204 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1205 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1208 -- If a bound references a discriminant, generate an identifier
1209 -- with the same name. Resolution will map it to the formals of
1212 if Is_Entity_Name
(Low
)
1213 and then Ekind
(Entity
(Low
)) = E_Discriminant
1215 Low
:= Make_Identifier
(Loc
, Chars
(Low
));
1217 Low
:= New_Copy_Tree
(Low
);
1220 if Is_Entity_Name
(High
)
1221 and then Ekind
(Entity
(High
)) = E_Discriminant
1223 High
:= Make_Identifier
(Loc
, Chars
(High
));
1225 High
:= New_Copy_Tree
(High
);
1231 High_Bound
=> High
);
1234 -- Start of processing for Build_Entry_Family_Name
1237 Get_Name_String
(Chars
(Id
));
1239 -- Add a leading '('
1241 Add_Char_To_Name_Buffer
('(');
1244 -- new String'("<Entry name>(" & Lnn'Img & ")");
1246 -- This is an implicit heap allocation, and Comes_From_Source is
1247 -- False, which ensures that it will get flagged as a violation of
1248 -- No_Implicit_Heap_Allocations when that restriction applies.
1251 Make_Allocator
(Loc
,
1252 Make_Qualified_Expression
(Loc
,
1254 New_Reference_To
(Standard_String
, Loc
),
1256 Make_Op_Concat
(Loc
,
1258 Make_Op_Concat
(Loc
,
1260 Make_String_Literal
(Loc
,
1261 Strval
=> String_From_Name_Buffer
),
1263 Make_Attribute_Reference
(Loc
,
1265 New_Reference_To
(L_Id
, Loc
),
1266 Attribute_Name
=> Name_Img
)),
1268 Make_String_Literal
(Loc
,
1271 Increment_Index
(L_Stmts
);
1272 Append_To
(L_Stmts
, Build_Set_Entry_Name_Call
(Val
));
1275 -- for Lnn in Family_Low .. Family_High loop
1278 -- (_init._object <or> _init._task_id, Inn, <Val>);
1282 Make_Loop_Statement
(Loc
,
1284 Make_Iteration_Scheme
(Loc
,
1285 Loop_Parameter_Specification
=>
1286 Make_Loop_Parameter_Specification
(Loc
,
1287 Defining_Identifier
=> L_Id
,
1288 Discrete_Subtype_Definition
=> Build_Range
(Def
))),
1289 Statements
=> L_Stmts
,
1290 End_Label
=> Empty
));
1291 end Build_Entry_Family_Name
;
1293 ----------------------
1294 -- Build_Entry_Name --
1295 ----------------------
1297 procedure Build_Entry_Name
(Id
: Entity_Id
) is
1301 Get_Name_String
(Chars
(Id
));
1303 -- This is an implicit heap allocation, and Comes_From_Source is
1304 -- False, which ensures that it will get flagged as a violation of
1305 -- No_Implicit_Heap_Allocations when that restriction applies.
1308 Make_Allocator
(Loc
,
1309 Make_Qualified_Expression
(Loc
,
1311 New_Reference_To
(Standard_String
, Loc
),
1313 Make_String_Literal
(Loc
,
1314 String_From_Name_Buffer
)));
1316 Increment_Index
(B_Stmts
);
1317 Append_To
(B_Stmts
, Build_Set_Entry_Name_Call
(Val
));
1318 end Build_Entry_Name
;
1320 -------------------------------
1321 -- Build_Set_Entry_Name_Call --
1322 -------------------------------
1324 function Build_Set_Entry_Name_Call
(Arg3
: Node_Id
) return Node_Id
is
1329 -- Determine the proper name for the first argument and the RTS
1332 if Is_Protected_Type
(Typ
) then
1333 Arg1
:= Name_uObject
;
1334 Proc
:= RO_PE_Set_Entry_Name
;
1336 else pragma Assert
(Is_Task_Type
(Typ
));
1337 Arg1
:= Name_uTask_Id
;
1338 Proc
:= RO_TS_Set_Entry_Name
;
1342 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1345 Make_Procedure_Call_Statement
(Loc
,
1347 New_Reference_To
(RTE
(Proc
), Loc
),
1348 Parameter_Associations
=> New_List
(
1349 Make_Selected_Component
(Loc
, -- _init._object
1350 Prefix
=> -- _init._task_id
1351 Make_Identifier
(Loc
, Name_uInit
),
1353 Make_Identifier
(Loc
, Arg1
)),
1354 New_Reference_To
(Index
, Loc
), -- Inn
1356 end Build_Set_Entry_Name_Call
;
1358 --------------------------
1359 -- Find_Protection_Type --
1360 --------------------------
1362 function Find_Protection_Type
(Conc_Typ
: Entity_Id
) return Entity_Id
is
1364 Typ
: Entity_Id
:= Conc_Typ
;
1367 if Is_Concurrent_Type
(Typ
) then
1368 Typ
:= Corresponding_Record_Type
(Typ
);
1371 Comp
:= First_Component
(Typ
);
1372 while Present
(Comp
) loop
1373 if Chars
(Comp
) = Name_uObject
then
1374 return Base_Type
(Etype
(Comp
));
1377 Next_Component
(Comp
);
1380 -- The corresponding record of a protected type should always have an
1383 raise Program_Error
;
1384 end Find_Protection_Type
;
1386 ---------------------
1387 -- Increment_Index --
1388 ---------------------
1390 procedure Increment_Index
(Stmts
: List_Id
) is
1396 Make_Assignment_Statement
(Loc
,
1398 New_Reference_To
(Index
, Loc
),
1402 New_Reference_To
(Index
, Loc
),
1404 Make_Integer_Literal
(Loc
, 1))));
1405 end Increment_Index
;
1407 -- Start of processing for Build_Entry_Names
1410 -- Retrieve the original concurrent type
1412 if Is_Concurrent_Record_Type
(Typ
) then
1413 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1416 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
1418 -- Nothing to do if the type has no entries
1420 if not Has_Entries
(Typ
) then
1424 -- Avoid generating entry names for a protected type with only one entry
1426 if Is_Protected_Type
(Typ
)
1427 and then Find_Protection_Type
(Typ
) /= RTE
(RE_Protection_Entries
)
1432 Index
:= Make_Temporary
(Loc
, 'I');
1434 -- Step 1: Generate the declaration of the index variable:
1435 -- Inn : Protected_Entry_Index := 0;
1437 -- Inn : Task_Entry_Index := 0;
1439 if Is_Protected_Type
(Typ
) then
1440 Index_Typ
:= RE_Protected_Entry_Index
;
1442 Index_Typ
:= RE_Task_Entry_Index
;
1445 B_Decls
:= New_List
;
1447 Make_Object_Declaration
(Loc
,
1448 Defining_Identifier
=> Index
,
1449 Object_Definition
=> New_Reference_To
(RTE
(Index_Typ
), Loc
),
1450 Expression
=> Make_Integer_Literal
(Loc
, 0)));
1452 B_Stmts
:= New_List
;
1454 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1457 Comp
:= First_Entity
(Typ
);
1458 while Present
(Comp
) loop
1459 if Ekind
(Comp
) = E_Entry
then
1460 Build_Entry_Name
(Comp
);
1462 elsif Ekind
(Comp
) = E_Entry_Family
then
1463 Build_Entry_Family_Name
(Comp
);
1469 -- Step 3: Wrap the statements in a block
1472 Make_Block_Statement
(Loc
,
1473 Declarations
=> B_Decls
,
1474 Handled_Statement_Sequence
=>
1475 Make_Handled_Sequence_Of_Statements
(Loc
,
1476 Statements
=> B_Stmts
));
1477 end Build_Entry_Names
;
1479 ---------------------------
1480 -- Build_Parameter_Block --
1481 ---------------------------
1483 function Build_Parameter_Block
1487 Decls
: List_Id
) return Entity_Id
1493 Has_Comp
: Boolean := False;
1497 Actual
:= First
(Actuals
);
1499 Formal
:= Defining_Identifier
(First
(Formals
));
1501 while Present
(Actual
) loop
1502 if not Is_Controlling_Actual
(Actual
) then
1505 -- type Ann is access all <actual-type>
1507 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1510 Make_Full_Type_Declaration
(Loc
,
1511 Defining_Identifier
=> Comp_Nam
,
1513 Make_Access_To_Object_Definition
(Loc
,
1514 All_Present
=> True,
1515 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1516 Subtype_Indication
=>
1517 New_Reference_To
(Etype
(Actual
), Loc
))));
1523 Make_Component_Declaration
(Loc
,
1524 Defining_Identifier
=>
1525 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1526 Component_Definition
=>
1527 Make_Component_Definition
(Loc
,
1530 Subtype_Indication
=>
1531 New_Reference_To
(Comp_Nam
, Loc
))));
1536 Next_Actual
(Actual
);
1537 Next_Formal_With_Extras
(Formal
);
1540 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1545 -- type Pnn is record
1550 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1551 -- the original parameter names and Ann1 .. AnnN are the access to
1555 Make_Full_Type_Declaration
(Loc
,
1556 Defining_Identifier
=>
1559 Make_Record_Definition
(Loc
,
1561 Make_Component_List
(Loc
, Comps
))));
1564 -- type Pnn is null record;
1567 Make_Full_Type_Declaration
(Loc
,
1568 Defining_Identifier
=>
1571 Make_Record_Definition
(Loc
,
1572 Null_Present
=> True,
1573 Component_List
=> Empty
)));
1577 end Build_Parameter_Block
;
1579 -----------------------
1580 -- Build_PPC_Wrapper --
1581 -----------------------
1583 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1584 Loc
: constant Source_Ptr
:= Sloc
(E
);
1585 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1587 Wrapper_Id
: constant Entity_Id
:=
1588 Make_Defining_Identifier
(Loc
,
1589 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1590 -- the wrapper procedure name
1592 Wrapper_Body
: Node_Id
;
1594 Synch_Id
: constant Entity_Id
:=
1595 Make_Defining_Identifier
(Loc
,
1596 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1597 -- The parameter that designates the synchronized object in the call
1599 Actuals
: constant List_Id
:= New_List
;
1600 -- the actuals in the entry call.
1602 Decls
: constant List_Id
:= New_List
;
1604 Entry_Call
: Node_Id
;
1605 Entry_Name
: Node_Id
;
1608 -- The specification of the wrapper procedure
1612 -- Only build the wrapper if entry has pre/postconditions.
1613 -- Should this be done unconditionally instead ???
1619 P
:= Spec_PPC_List
(E
);
1624 -- Transfer ppc pragmas to the declarations of the wrapper
1626 while Present
(P
) loop
1627 if Pragma_Name
(P
) = Name_Precondition
1628 or else Pragma_Name
(P
) = Name_Postcondition
1630 Append
(Relocate_Node
(P
), Decls
);
1631 Set_Analyzed
(Last
(Decls
), False);
1634 P
:= Next_Pragma
(P
);
1638 -- First formal is synchronized object
1641 Make_Parameter_Specification
(Loc
,
1642 Defining_Identifier
=> Synch_Id
,
1643 Out_Present
=> True,
1645 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1648 Make_Selected_Component
(Loc
,
1649 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1650 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1652 -- If entity is entry family, second formal is the corresponding index,
1653 -- and entry name is an indexed component.
1655 if Ekind
(E
) = E_Entry_Family
then
1657 Index
: constant Entity_Id
:=
1658 Make_Defining_Identifier
(Loc
, Name_I
);
1661 Make_Parameter_Specification
(Loc
,
1662 Defining_Identifier
=> Index
,
1664 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
1667 Make_Indexed_Component
(Loc
,
1668 Prefix
=> Entry_Name
,
1669 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
1674 Make_Procedure_Call_Statement
(Loc
,
1676 Parameter_Associations
=> Actuals
);
1678 -- Now add formals that match those of the entry, and build actuals for
1679 -- the nested entry call.
1683 New_Form
: Entity_Id
;
1684 Parm_Spec
: Node_Id
;
1687 Form
:= First_Formal
(E
);
1688 while Present
(Form
) loop
1689 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
1691 Make_Parameter_Specification
(Loc
,
1692 Defining_Identifier
=> New_Form
,
1693 Out_Present
=> Out_Present
(Parent
(Form
)),
1694 In_Present
=> In_Present
(Parent
(Form
)),
1695 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
1697 Append
(Parm_Spec
, Specs
);
1698 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
1703 -- Add renaming declarations for the discriminants of the enclosing
1704 -- type, which may be visible in the preconditions.
1706 if Has_Discriminants
(Synch_Type
) then
1712 D
:= First_Discriminant
(Synch_Type
);
1713 while Present
(D
) loop
1715 Make_Object_Renaming_Declaration
(Loc
,
1716 Defining_Identifier
=>
1717 Make_Defining_Identifier
(Loc
, Chars
(D
)),
1718 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
1720 Make_Selected_Component
(Loc
,
1721 Prefix
=> New_Reference_To
(Synch_Id
, Loc
),
1722 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
1723 Prepend
(Decl
, Decls
);
1724 Next_Discriminant
(D
);
1729 Set_PPC_Wrapper
(E
, Wrapper_Id
);
1731 Make_Subprogram_Body
(Loc
,
1733 Make_Procedure_Specification
(Loc
,
1734 Defining_Unit_Name
=> Wrapper_Id
,
1735 Parameter_Specifications
=> Specs
),
1736 Declarations
=> Decls
,
1737 Handled_Statement_Sequence
=>
1738 Make_Handled_Sequence_Of_Statements
(Loc
,
1739 Statements
=> New_List
(Entry_Call
)));
1741 -- The wrapper body is analyzed when the enclosing type is frozen
1743 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
1744 end Build_PPC_Wrapper
;
1746 --------------------------
1747 -- Build_Wrapper_Bodies --
1748 --------------------------
1750 procedure Build_Wrapper_Bodies
1755 Rec_Typ
: Entity_Id
;
1757 function Build_Wrapper_Body
1759 Subp_Id
: Entity_Id
;
1760 Obj_Typ
: Entity_Id
;
1761 Formals
: List_Id
) return Node_Id
;
1762 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1763 -- associated with a protected or task type. Subp_Id is the subprogram
1764 -- name which will be wrapped. Obj_Typ is the type of the new formal
1765 -- parameter which handles dispatching and object notation. Formals are
1766 -- the original formals of Subp_Id which will be explicitly replicated.
1768 ------------------------
1769 -- Build_Wrapper_Body --
1770 ------------------------
1772 function Build_Wrapper_Body
1774 Subp_Id
: Entity_Id
;
1775 Obj_Typ
: Entity_Id
;
1776 Formals
: List_Id
) return Node_Id
1778 Body_Spec
: Node_Id
;
1781 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
1783 -- The subprogram is not overriding or is not a primitive declared
1784 -- between two views.
1786 if No
(Body_Spec
) then
1791 Actuals
: List_Id
:= No_List
;
1793 First_Form
: Node_Id
;
1798 -- Map formals to actuals. Use the list built for the wrapper
1799 -- spec, skipping the object notation parameter.
1801 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
1803 Formal
:= First_Form
;
1806 if Present
(Formal
) then
1807 Actuals
:= New_List
;
1808 while Present
(Formal
) loop
1810 Make_Identifier
(Loc
, Chars
=>
1811 Chars
(Defining_Identifier
(Formal
))));
1817 -- Special processing for primitives declared between a private
1818 -- type and its completion: the wrapper needs a properly typed
1819 -- parameter if the wrapped operation has a controlling first
1820 -- parameter. Note that this might not be the case for a function
1821 -- with a controlling result.
1823 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
1824 if No
(Actuals
) then
1825 Actuals
:= New_List
;
1828 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
1829 Prepend_To
(Actuals
,
1830 Unchecked_Convert_To
1831 (Corresponding_Concurrent_Type
(Obj_Typ
),
1832 Make_Identifier
(Loc
, Name_uO
)));
1835 Prepend_To
(Actuals
,
1836 Make_Identifier
(Loc
, Chars
=>
1837 Chars
(Defining_Identifier
(First_Form
))));
1840 Nam
:= New_Reference_To
(Subp_Id
, Loc
);
1842 -- An access-to-variable object parameter requires an explicit
1843 -- dereference in the unchecked conversion. This case occurs
1844 -- when a protected entry wrapper must override an interface
1845 -- level procedure with interface access as first parameter.
1847 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1849 if Nkind
(Parameter_Type
(First_Form
)) =
1853 Make_Explicit_Dereference
(Loc
,
1854 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
1856 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
1860 Make_Selected_Component
(Loc
,
1862 Unchecked_Convert_To
1863 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
1864 Selector_Name
=> New_Reference_To
(Subp_Id
, Loc
));
1867 -- Create the subprogram body. For a function, the call to the
1868 -- actual subprogram has to be converted to the corresponding
1869 -- record if it is a controlling result.
1871 if Ekind
(Subp_Id
) = E_Function
then
1877 Make_Function_Call
(Loc
,
1879 Parameter_Associations
=> Actuals
);
1881 if Has_Controlling_Result
(Subp_Id
) then
1883 Unchecked_Convert_To
1884 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
1888 Make_Subprogram_Body
(Loc
,
1889 Specification
=> Body_Spec
,
1890 Declarations
=> Empty_List
,
1891 Handled_Statement_Sequence
=>
1892 Make_Handled_Sequence_Of_Statements
(Loc
,
1893 Statements
=> New_List
(
1894 Make_Simple_Return_Statement
(Loc
, Res
))));
1899 Make_Subprogram_Body
(Loc
,
1900 Specification
=> Body_Spec
,
1901 Declarations
=> Empty_List
,
1902 Handled_Statement_Sequence
=>
1903 Make_Handled_Sequence_Of_Statements
(Loc
,
1904 Statements
=> New_List
(
1905 Make_Procedure_Call_Statement
(Loc
,
1907 Parameter_Associations
=> Actuals
))));
1910 end Build_Wrapper_Body
;
1912 -- Start of processing for Build_Wrapper_Bodies
1915 if Is_Concurrent_Type
(Typ
) then
1916 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
1921 -- Generate wrapper bodies for a concurrent type which implements an
1924 if Present
(Interfaces
(Rec_Typ
)) then
1926 Insert_Nod
: Node_Id
;
1928 Prim_Elmt
: Elmt_Id
;
1929 Prim_Decl
: Node_Id
;
1931 Wrap_Body
: Node_Id
;
1932 Wrap_Id
: Entity_Id
;
1937 -- Examine all primitive operations of the corresponding record
1938 -- type, looking for wrapper specs. Generate bodies in order to
1941 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
1942 while Present
(Prim_Elmt
) loop
1943 Prim
:= Node
(Prim_Elmt
);
1945 if (Ekind
(Prim
) = E_Function
1946 or else Ekind
(Prim
) = E_Procedure
)
1947 and then Is_Primitive_Wrapper
(Prim
)
1949 Subp
:= Wrapped_Entity
(Prim
);
1950 Prim_Decl
:= Parent
(Parent
(Prim
));
1953 Build_Wrapper_Body
(Loc
,
1956 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
1957 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
1959 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
1960 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
1962 Insert_After
(Insert_Nod
, Wrap_Body
);
1963 Insert_Nod
:= Wrap_Body
;
1965 Analyze
(Wrap_Body
);
1968 Next_Elmt
(Prim_Elmt
);
1972 end Build_Wrapper_Bodies
;
1974 ------------------------
1975 -- Build_Wrapper_Spec --
1976 ------------------------
1978 function Build_Wrapper_Spec
1979 (Subp_Id
: Entity_Id
;
1980 Obj_Typ
: Entity_Id
;
1981 Formals
: List_Id
) return Node_Id
1983 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
1984 First_Param
: Node_Id
;
1986 Iface_Elmt
: Elmt_Id
;
1987 Iface_Op
: Entity_Id
;
1988 Iface_Op_Elmt
: Elmt_Id
;
1990 function Overriding_Possible
1991 (Iface_Op
: Entity_Id
;
1992 Wrapper
: Entity_Id
) return Boolean;
1993 -- Determine whether a primitive operation can be overridden by Wrapper.
1994 -- Iface_Op is the candidate primitive operation of an interface type,
1995 -- Wrapper is the generated entry wrapper.
1997 function Replicate_Formals
1999 Formals
: List_Id
) return List_Id
;
2000 -- An explicit parameter replication is required due to the Is_Entry_
2001 -- Formal flag being set for all the formals of an entry. The explicit
2002 -- replication removes the flag that would otherwise cause a different
2003 -- path of analysis.
2005 -------------------------
2006 -- Overriding_Possible --
2007 -------------------------
2009 function Overriding_Possible
2010 (Iface_Op
: Entity_Id
;
2011 Wrapper
: Entity_Id
) return Boolean
2013 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2014 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2016 function Type_Conformant_Parameters
2017 (Iface_Op_Params
: List_Id
;
2018 Wrapper_Params
: List_Id
) return Boolean;
2019 -- Determine whether the parameters of the generated entry wrapper
2020 -- and those of a primitive operation are type conformant. During
2021 -- this check, the first parameter of the primitive operation is
2022 -- skipped if it is a controlling argument: protected functions
2023 -- may have a controlling result.
2025 --------------------------------
2026 -- Type_Conformant_Parameters --
2027 --------------------------------
2029 function Type_Conformant_Parameters
2030 (Iface_Op_Params
: List_Id
;
2031 Wrapper_Params
: List_Id
) return Boolean
2033 Iface_Op_Param
: Node_Id
;
2034 Iface_Op_Typ
: Entity_Id
;
2035 Wrapper_Param
: Node_Id
;
2036 Wrapper_Typ
: Entity_Id
;
2039 -- Skip the first (controlling) parameter of primitive operation
2041 Iface_Op_Param
:= First
(Iface_Op_Params
);
2043 if Present
(First_Formal
(Iface_Op
))
2044 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2046 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2049 Wrapper_Param
:= First
(Wrapper_Params
);
2050 while Present
(Iface_Op_Param
)
2051 and then Present
(Wrapper_Param
)
2053 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2054 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2056 -- The two parameters must be mode conformant
2058 if not Conforming_Types
2059 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2064 Next
(Iface_Op_Param
);
2065 Next
(Wrapper_Param
);
2068 -- One of the lists is longer than the other
2070 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2075 end Type_Conformant_Parameters
;
2077 -- Start of processing for Overriding_Possible
2080 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2084 -- If an inherited subprogram is implemented by a protected procedure
2085 -- or an entry, then the first parameter of the inherited subprogram
2086 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2088 if Ekind
(Iface_Op
) = E_Procedure
2089 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2092 Obj_Param
: constant Node_Id
:=
2093 First
(Parameter_Specifications
(Iface_Op_Spec
));
2095 if not Out_Present
(Obj_Param
)
2096 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2105 Type_Conformant_Parameters
(
2106 Parameter_Specifications
(Iface_Op_Spec
),
2107 Parameter_Specifications
(Wrapper_Spec
));
2108 end Overriding_Possible
;
2110 -----------------------
2111 -- Replicate_Formals --
2112 -----------------------
2114 function Replicate_Formals
2116 Formals
: List_Id
) return List_Id
2118 New_Formals
: constant List_Id
:= New_List
;
2120 Param_Type
: Node_Id
;
2123 Formal
:= First
(Formals
);
2125 -- Skip the object parameter when dealing with primitives declared
2126 -- between two views.
2128 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2129 and then not Has_Controlling_Result
(Subp_Id
)
2131 Formal
:= Next
(Formal
);
2134 while Present
(Formal
) loop
2136 -- Create an explicit copy of the entry parameter
2138 -- When creating the wrapper subprogram for a primitive operation
2139 -- of a protected interface we must construct an equivalent
2140 -- signature to that of the overriding operation. For regular
2141 -- parameters we can just use the type of the formal, but for
2142 -- access to subprogram parameters we need to reanalyze the
2143 -- parameter type to create local entities for the signature of
2144 -- the subprogram type. Using the entities of the overriding
2145 -- subprogram will result in out-of-scope errors in the back-end.
2147 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2148 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2151 New_Reference_To
(Etype
(Parameter_Type
(Formal
)), Loc
);
2154 Append_To
(New_Formals
,
2155 Make_Parameter_Specification
(Loc
,
2156 Defining_Identifier
=>
2157 Make_Defining_Identifier
(Loc
,
2158 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2159 In_Present
=> In_Present
(Formal
),
2160 Out_Present
=> Out_Present
(Formal
),
2161 Parameter_Type
=> Param_Type
));
2167 end Replicate_Formals
;
2169 -- Start of processing for Build_Wrapper_Spec
2172 -- There is no point in building wrappers for non-tagged concurrent
2175 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2177 -- An entry or a protected procedure can override a routine where the
2178 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2179 -- type. Since the wrapper must have the exact same signature as that of
2180 -- the overridden subprogram, we try to find the overriding candidate
2181 -- and use its controlling formal.
2183 First_Param
:= Empty
;
2185 -- Check every implemented interface
2187 if Present
(Interfaces
(Obj_Typ
)) then
2188 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2189 Search
: while Present
(Iface_Elmt
) loop
2190 Iface
:= Node
(Iface_Elmt
);
2192 -- Check every interface primitive
2194 if Present
(Primitive_Operations
(Iface
)) then
2195 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2196 while Present
(Iface_Op_Elmt
) loop
2197 Iface_Op
:= Node
(Iface_Op_Elmt
);
2199 -- Ignore predefined primitives
2201 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2202 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2204 -- The current primitive operation can be overridden by
2205 -- the generated entry wrapper.
2207 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2209 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2215 Next_Elmt
(Iface_Op_Elmt
);
2219 Next_Elmt
(Iface_Elmt
);
2223 -- If the subprogram to be wrapped is not overriding anything or is not
2224 -- a primitive declared between two views, do not produce anything. This
2225 -- avoids spurious errors involving overriding.
2228 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2234 Wrapper_Id
: constant Entity_Id
:=
2235 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2236 New_Formals
: List_Id
;
2237 Obj_Param
: Node_Id
;
2238 Obj_Param_Typ
: Entity_Id
;
2241 -- Minimum decoration is needed to catch the entity in
2242 -- Sem_Ch6.Override_Dispatching_Operation.
2244 if Ekind
(Subp_Id
) = E_Function
then
2245 Set_Ekind
(Wrapper_Id
, E_Function
);
2247 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2250 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2251 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2252 Set_Is_Private_Primitive
(Wrapper_Id
,
2253 Is_Private_Primitive_Subprogram
(Subp_Id
));
2255 -- Process the formals
2257 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2259 -- A function with a controlling result and no first controlling
2260 -- formal needs no additional parameter.
2262 if Has_Controlling_Result
(Subp_Id
)
2264 (No
(First_Formal
(Subp_Id
))
2265 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2269 -- Routine Subp_Id has been found to override an interface primitive.
2270 -- If the interface operation has an access parameter, create a copy
2271 -- of it, with the same null exclusion indicator if present.
2273 elsif Present
(First_Param
) then
2274 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2276 Make_Access_Definition
(Loc
,
2278 New_Reference_To
(Obj_Typ
, Loc
));
2279 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2280 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2283 Obj_Param_Typ
:= New_Reference_To
(Obj_Typ
, Loc
);
2287 Make_Parameter_Specification
(Loc
,
2288 Defining_Identifier
=>
2289 Make_Defining_Identifier
(Loc
,
2291 In_Present
=> In_Present
(First_Param
),
2292 Out_Present
=> Out_Present
(First_Param
),
2293 Parameter_Type
=> Obj_Param_Typ
);
2295 Prepend_To
(New_Formals
, Obj_Param
);
2297 -- If we are dealing with a primitive declared between two views,
2298 -- implemented by a synchronized operation, we need to create
2299 -- a default parameter. The mode of the parameter must match that
2300 -- of the primitive operation.
2303 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2305 Make_Parameter_Specification
(Loc
,
2306 Defining_Identifier
=>
2307 Make_Defining_Identifier
(Loc
, Name_uO
),
2308 In_Present
=> In_Present
(Parent
(First_Entity
(Subp_Id
))),
2309 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2310 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2311 Prepend_To
(New_Formals
, Obj_Param
);
2314 -- Build the final spec. If it is a function with a controlling
2315 -- result, it is a primitive operation of the corresponding
2316 -- record type, so mark the spec accordingly.
2318 if Ekind
(Subp_Id
) = E_Function
then
2323 if Has_Controlling_Result
(Subp_Id
) then
2326 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2328 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2332 Make_Function_Specification
(Loc
,
2333 Defining_Unit_Name
=> Wrapper_Id
,
2334 Parameter_Specifications
=> New_Formals
,
2335 Result_Definition
=> Res_Def
);
2339 Make_Procedure_Specification
(Loc
,
2340 Defining_Unit_Name
=> Wrapper_Id
,
2341 Parameter_Specifications
=> New_Formals
);
2344 end Build_Wrapper_Spec
;
2346 -------------------------
2347 -- Build_Wrapper_Specs --
2348 -------------------------
2350 procedure Build_Wrapper_Specs
2356 Rec_Typ
: Entity_Id
;
2357 procedure Scan_Declarations
(L
: List_Id
);
2358 -- Common processing for visible and private declarations
2359 -- of a protected type.
2361 procedure Scan_Declarations
(L
: List_Id
) is
2363 Wrap_Decl
: Node_Id
;
2364 Wrap_Spec
: Node_Id
;
2372 while Present
(Decl
) loop
2375 if Nkind
(Decl
) = N_Entry_Declaration
2376 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2380 (Subp_Id
=> Defining_Identifier
(Decl
),
2382 Formals
=> Parameter_Specifications
(Decl
));
2384 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2387 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2390 Parameter_Specifications
(Specification
(Decl
)));
2393 if Present
(Wrap_Spec
) then
2395 Make_Subprogram_Declaration
(Loc
,
2396 Specification
=> Wrap_Spec
);
2398 Insert_After
(N
, Wrap_Decl
);
2401 Analyze
(Wrap_Decl
);
2406 end Scan_Declarations
;
2408 -- start of processing for Build_Wrapper_Specs
2411 if Is_Protected_Type
(Typ
) then
2412 Def
:= Protected_Definition
(Parent
(Typ
));
2413 else pragma Assert
(Is_Task_Type
(Typ
));
2414 Def
:= Task_Definition
(Parent
(Typ
));
2417 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2419 -- Generate wrapper specs for a concurrent type which implements an
2420 -- interface. Operations in both the visible and private parts may
2421 -- implement progenitor operations.
2423 if Present
(Interfaces
(Rec_Typ
))
2424 and then Present
(Def
)
2426 Scan_Declarations
(Visible_Declarations
(Def
));
2427 Scan_Declarations
(Private_Declarations
(Def
));
2429 end Build_Wrapper_Specs
;
2431 ---------------------------
2432 -- Build_Find_Body_Index --
2433 ---------------------------
2435 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2436 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2439 Has_F
: Boolean := False;
2441 If_St
: Node_Id
:= Empty
;
2444 Decls
: List_Id
:= New_List
;
2447 Siz
: Node_Id
:= Empty
;
2449 procedure Add_If_Clause
(Expr
: Node_Id
);
2450 -- Add test for range of current entry
2452 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2453 -- If a bound of an entry is given by a discriminant, retrieve the
2454 -- actual value of the discriminant from the enclosing object.
2460 procedure Add_If_Clause
(Expr
: Node_Id
) is
2462 Stats
: constant List_Id
:=
2464 Make_Simple_Return_Statement
(Loc
,
2465 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2468 -- Index for current entry body
2472 -- Compute total length of entry queues so far
2480 Right_Opnd
=> Expr
);
2485 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2488 -- Map entry queue indices in the range of the current family
2489 -- into the current index, that designates the entry body.
2493 Make_Implicit_If_Statement
(Typ
,
2495 Then_Statements
=> Stats
,
2496 Elsif_Parts
=> New_List
);
2502 Make_Elsif_Part
(Loc
,
2504 Then_Statements
=> Stats
),
2505 Elsif_Parts
(If_St
));
2509 ------------------------------
2510 -- Convert_Discriminant_Ref --
2511 ------------------------------
2513 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2517 if Is_Entity_Name
(Bound
)
2518 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2521 Make_Selected_Component
(Loc
,
2523 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2524 Make_Explicit_Dereference
(Loc
,
2525 Make_Identifier
(Loc
, Name_uObject
))),
2526 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2527 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2529 B
:= New_Copy_Tree
(Bound
);
2533 end Convert_Discriminant_Ref
;
2535 -- Start of processing for Build_Find_Body_Index
2538 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2540 Ent
:= First_Entity
(Typ
);
2541 while Present
(Ent
) loop
2542 if Ekind
(Ent
) = E_Entry_Family
then
2552 -- If the protected type has no entry families, there is a one-one
2553 -- correspondence between entry queue and entry body.
2556 Make_Simple_Return_Statement
(Loc
,
2557 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2560 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2563 -- if E <= l1 then return 1;
2564 -- elsif E <= l1 + l2 then return 2;
2569 Ent
:= First_Entity
(Typ
);
2571 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2573 while Present
(Ent
) loop
2574 if Ekind
(Ent
) = E_Entry
then
2575 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2577 elsif Ekind
(Ent
) = E_Entry_Family
then
2578 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2579 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2580 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2581 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2590 Make_Simple_Return_Statement
(Loc
,
2591 Expression
=> Make_Integer_Literal
(Loc
, 1));
2593 elsif Nkind
(Ret
) = N_If_Statement
then
2595 -- Ranges are in increasing order, so last one doesn't need guard
2598 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2601 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2607 Make_Subprogram_Body
(Loc
,
2608 Specification
=> Spec
,
2609 Declarations
=> Decls
,
2610 Handled_Statement_Sequence
=>
2611 Make_Handled_Sequence_Of_Statements
(Loc
,
2612 Statements
=> New_List
(Ret
)));
2613 end Build_Find_Body_Index
;
2615 --------------------------------
2616 -- Build_Find_Body_Index_Spec --
2617 --------------------------------
2619 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2620 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2621 Id
: constant Entity_Id
:=
2622 Make_Defining_Identifier
(Loc
,
2623 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2624 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2625 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2629 Make_Function_Specification
(Loc
,
2630 Defining_Unit_Name
=> Id
,
2631 Parameter_Specifications
=> New_List
(
2632 Make_Parameter_Specification
(Loc
,
2633 Defining_Identifier
=> Parm1
,
2635 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2637 Make_Parameter_Specification
(Loc
,
2638 Defining_Identifier
=> Parm2
,
2640 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2641 Result_Definition
=> New_Occurrence_Of
(
2642 RTE
(RE_Protected_Entry_Index
), Loc
));
2643 end Build_Find_Body_Index_Spec
;
2645 -------------------------
2646 -- Build_Master_Entity --
2647 -------------------------
2649 procedure Build_Master_Entity
(E
: Entity_Id
) is
2650 Loc
: constant Source_Ptr
:= Sloc
(E
);
2656 S
:= Find_Master_Scope
(E
);
2658 -- Nothing to do if we already built a master entity for this scope
2659 -- or if there is no task hierarchy.
2661 if Has_Master_Entity
(S
)
2662 or else Restriction_Active
(No_Task_Hierarchy
)
2667 -- Otherwise first build the master entity
2668 -- _Master : constant Master_Id := Current_Master.all;
2669 -- and insert it just before the current declaration
2672 Make_Object_Declaration
(Loc
,
2673 Defining_Identifier
=>
2674 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2675 Constant_Present
=> True,
2676 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
2678 Make_Explicit_Dereference
(Loc
,
2679 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
2682 Insert_Before
(P
, Decl
);
2685 Set_Has_Master_Entity
(S
);
2687 -- Now mark the containing scope as a task master
2689 while Nkind
(P
) /= N_Compilation_Unit
loop
2692 -- If we fall off the top, we are at the outer level, and the
2693 -- environment task is our effective master, so nothing to mark.
2696 (P
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2698 Set_Is_Task_Master
(P
, True);
2701 elsif Nkind
(Parent
(P
)) = N_Subunit
then
2702 P
:= Corresponding_Stub
(Parent
(P
));
2705 end Build_Master_Entity
;
2707 -----------------------------------------
2708 -- Build_Private_Protected_Declaration --
2709 -----------------------------------------
2711 function Build_Private_Protected_Declaration
2712 (N
: Node_Id
) return Entity_Id
2714 Loc
: constant Source_Ptr
:= Sloc
(N
);
2715 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
2720 Spec_Id
: Entity_Id
;
2723 Formal
:= First_Formal
(Body_Id
);
2725 -- The protected operation always has at least one formal, namely the
2726 -- object itself, but it is only placed in the parameter list if
2727 -- expansion is enabled.
2729 if Present
(Formal
) or else Expander_Active
then
2730 Plist
:= Copy_Parameter_List
(Body_Id
);
2735 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
2737 Make_Procedure_Specification
(Loc
,
2738 Defining_Unit_Name
=>
2739 Make_Defining_Identifier
(Sloc
(Body_Id
),
2740 Chars
=> Chars
(Body_Id
)),
2741 Parameter_Specifications
=>
2745 Make_Function_Specification
(Loc
,
2746 Defining_Unit_Name
=>
2747 Make_Defining_Identifier
(Sloc
(Body_Id
),
2748 Chars
=> Chars
(Body_Id
)),
2749 Parameter_Specifications
=> Plist
,
2750 Result_Definition
=>
2751 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
2754 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
2755 Insert_Before
(N
, Decl
);
2756 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
2758 -- Indicate that the entity comes from source, to ensure that cross-
2759 -- reference information is properly generated. The body itself is
2760 -- rewritten during expansion, and the body entity will not appear in
2761 -- calls to the operation.
2763 Set_Comes_From_Source
(Spec_Id
, True);
2765 Set_Has_Completion
(Spec_Id
);
2766 Set_Convention
(Spec_Id
, Convention_Protected
);
2768 end Build_Private_Protected_Declaration
;
2770 ---------------------------
2771 -- Build_Protected_Entry --
2772 ---------------------------
2774 function Build_Protected_Entry
2777 Pid
: Node_Id
) return Node_Id
2779 Loc
: constant Source_Ptr
:= Sloc
(N
);
2781 Decls
: constant List_Id
:= Declarations
(N
);
2782 End_Lab
: constant Node_Id
:=
2783 End_Label
(Handled_Statement_Sequence
(N
));
2784 End_Loc
: constant Source_Ptr
:=
2785 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
2786 -- Used for the generated call to Complete_Entry_Body
2788 Han_Loc
: Source_Ptr
;
2789 -- Used for the exception handler, inserted at end of the body
2791 Op_Decls
: constant List_Id
:= New_List
;
2799 -- Set the source location on the exception handler only when debugging
2800 -- the expanded code (see Make_Implicit_Exception_Handler).
2802 if Debug_Generated_Code
then
2805 -- Otherwise the inserted code should not be visible to the debugger
2808 Han_Loc
:= No_Location
;
2812 Make_Defining_Identifier
(Loc
,
2813 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
2815 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
2817 -- Add the following declarations:
2818 -- type poVP is access poV;
2819 -- _object : poVP := poVP (_O);
2821 -- where _O is the formal parameter associated with the concurrent
2822 -- object. These declarations are needed for Complete_Entry_Body.
2824 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
2826 -- Add renamings for all formals, the Protection object, discriminals,
2827 -- privals and the entry index constant for use by debugger.
2829 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
2830 Debug_Private_Data_Declarations
(Decls
);
2832 case Corresponding_Runtime_Package
(Pid
) is
2833 when System_Tasking_Protected_Objects_Entries
=>
2835 New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
);
2837 when System_Tasking_Protected_Objects_Single_Entry
=>
2839 New_Reference_To
(RTE
(RE_Complete_Single_Entry_Body
), Loc
);
2842 raise Program_Error
;
2845 Op_Stats
:= New_List
(
2846 Make_Block_Statement
(Loc
,
2847 Declarations
=> Decls
,
2848 Handled_Statement_Sequence
=>
2849 Handled_Statement_Sequence
(N
)),
2851 Make_Procedure_Call_Statement
(End_Loc
,
2853 Parameter_Associations
=> New_List
(
2854 Make_Attribute_Reference
(End_Loc
,
2856 Make_Selected_Component
(End_Loc
,
2858 Make_Identifier
(End_Loc
, Name_uObject
),
2860 Make_Identifier
(End_Loc
, Name_uObject
)),
2861 Attribute_Name
=> Name_Unchecked_Access
))));
2863 -- When exceptions can not be propagated, we never need to call
2864 -- Exception_Complete_Entry_Body
2866 if No_Exception_Handlers_Set
then
2868 Make_Subprogram_Body
(Loc
,
2869 Specification
=> Espec
,
2870 Declarations
=> Op_Decls
,
2871 Handled_Statement_Sequence
=>
2872 Make_Handled_Sequence_Of_Statements
(Loc
,
2873 Statements
=> Op_Stats
,
2874 End_Label
=> End_Lab
));
2877 Ohandle
:= Make_Others_Choice
(Loc
);
2878 Set_All_Others
(Ohandle
);
2880 case Corresponding_Runtime_Package
(Pid
) is
2881 when System_Tasking_Protected_Objects_Entries
=>
2884 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
2886 when System_Tasking_Protected_Objects_Single_Entry
=>
2889 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
2892 raise Program_Error
;
2895 -- Establish link between subprogram body entity and source entry.
2897 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
2899 -- Create body of entry procedure. The renaming declarations are
2900 -- placed ahead of the block that contains the actual entry body.
2903 Make_Subprogram_Body
(Loc
,
2904 Specification
=> Espec
,
2905 Declarations
=> Op_Decls
,
2906 Handled_Statement_Sequence
=>
2907 Make_Handled_Sequence_Of_Statements
(Loc
,
2908 Statements
=> Op_Stats
,
2909 End_Label
=> End_Lab
,
2910 Exception_Handlers
=> New_List
(
2911 Make_Implicit_Exception_Handler
(Han_Loc
,
2912 Exception_Choices
=> New_List
(Ohandle
),
2914 Statements
=> New_List
(
2915 Make_Procedure_Call_Statement
(Han_Loc
,
2917 Parameter_Associations
=> New_List
(
2918 Make_Attribute_Reference
(Han_Loc
,
2920 Make_Selected_Component
(Han_Loc
,
2922 Make_Identifier
(Han_Loc
, Name_uObject
),
2924 Make_Identifier
(Han_Loc
, Name_uObject
)),
2925 Attribute_Name
=> Name_Unchecked_Access
),
2927 Make_Function_Call
(Han_Loc
,
2928 Name
=> New_Reference_To
(
2929 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
2931 end Build_Protected_Entry
;
2933 -----------------------------------------
2934 -- Build_Protected_Entry_Specification --
2935 -----------------------------------------
2937 function Build_Protected_Entry_Specification
2940 Ent_Id
: Entity_Id
) return Node_Id
2942 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
2945 Set_Debug_Info_Needed
(Def_Id
);
2947 if Present
(Ent_Id
) then
2948 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
2952 Make_Procedure_Specification
(Loc
,
2953 Defining_Unit_Name
=> Def_Id
,
2954 Parameter_Specifications
=> New_List
(
2955 Make_Parameter_Specification
(Loc
,
2956 Defining_Identifier
=>
2957 Make_Defining_Identifier
(Loc
, Name_uO
),
2959 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2961 Make_Parameter_Specification
(Loc
,
2962 Defining_Identifier
=> P
,
2964 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2966 Make_Parameter_Specification
(Loc
,
2967 Defining_Identifier
=>
2968 Make_Defining_Identifier
(Loc
, Name_uE
),
2970 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
2971 end Build_Protected_Entry_Specification
;
2973 --------------------------
2974 -- Build_Protected_Spec --
2975 --------------------------
2977 function Build_Protected_Spec
2979 Obj_Type
: Entity_Id
;
2981 Unprotected
: Boolean := False) return List_Id
2983 Loc
: constant Source_Ptr
:= Sloc
(N
);
2986 New_Plist
: List_Id
;
2987 New_Param
: Node_Id
;
2990 New_Plist
:= New_List
;
2992 Formal
:= First_Formal
(Ident
);
2993 while Present
(Formal
) loop
2995 Make_Parameter_Specification
(Loc
,
2996 Defining_Identifier
=>
2997 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
2998 In_Present
=> In_Present
(Parent
(Formal
)),
2999 Out_Present
=> Out_Present
(Parent
(Formal
)),
3000 Parameter_Type
=> New_Reference_To
(Etype
(Formal
), Loc
));
3003 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
3006 Append
(New_Param
, New_Plist
);
3007 Next_Formal
(Formal
);
3010 -- If the subprogram is a procedure and the context is not an access
3011 -- to protected subprogram, the parameter is in-out. Otherwise it is
3015 Make_Parameter_Specification
(Loc
,
3016 Defining_Identifier
=>
3017 Make_Defining_Identifier
(Loc
, Name_uObject
),
3020 (Etype
(Ident
) = Standard_Void_Type
3021 and then not Is_RTE
(Obj_Type
, RE_Address
)),
3023 New_Reference_To
(Obj_Type
, Loc
));
3024 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
3025 Prepend_To
(New_Plist
, Decl
);
3028 end Build_Protected_Spec
;
3030 ---------------------------------------
3031 -- Build_Protected_Sub_Specification --
3032 ---------------------------------------
3034 function Build_Protected_Sub_Specification
3036 Prot_Typ
: Entity_Id
;
3037 Mode
: Subprogram_Protection_Mode
) return Node_Id
3039 Loc
: constant Source_Ptr
:= Sloc
(N
);
3043 New_Plist
: List_Id
;
3046 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
3047 (Dispatching_Mode
=> ' ',
3048 Protected_Mode
=> 'P',
3049 Unprotected_Mode
=> 'N');
3052 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
3055 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
3060 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
3063 Build_Protected_Spec
3064 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
3065 Mode
= Unprotected_Mode
);
3067 Make_Defining_Identifier
(Loc
,
3068 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
3070 -- The unprotected operation carries the user code, and debugging
3071 -- information must be generated for it, even though this spec does
3072 -- not come from source. It is also convenient to allow gdb to step
3073 -- into the protected operation, even though it only contains lock/
3076 Set_Debug_Info_Needed
(New_Id
);
3078 -- If a pragma Eliminate applies to the source entity, the internal
3079 -- subprograms will be eliminated as well.
3081 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
3083 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
3085 Make_Procedure_Specification
(Loc
,
3086 Defining_Unit_Name
=> New_Id
,
3087 Parameter_Specifications
=> New_Plist
);
3089 -- Create a new specification for the anonymous subprogram type
3093 Make_Function_Specification
(Loc
,
3094 Defining_Unit_Name
=> New_Id
,
3095 Parameter_Specifications
=> New_Plist
,
3096 Result_Definition
=>
3097 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
3099 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
3103 end Build_Protected_Sub_Specification
;
3105 -------------------------------------
3106 -- Build_Protected_Subprogram_Body --
3107 -------------------------------------
3109 function Build_Protected_Subprogram_Body
3112 N_Op_Spec
: Node_Id
) return Node_Id
3114 Loc
: constant Source_Ptr
:= Sloc
(N
);
3116 P_Op_Spec
: Node_Id
;
3119 Unprot_Call
: Node_Id
;
3121 Lock_Name
: Node_Id
;
3122 Lock_Stmt
: Node_Id
;
3123 Service_Name
: Node_Id
;
3125 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
3126 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
3128 Object_Parm
: Node_Id
;
3131 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
3132 -- Tell whether a given subprogram cannot raise an exception
3134 -----------------------
3135 -- Is_Exception_Safe --
3136 -----------------------
3138 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
3140 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
3141 -- Return True whenever encountering a subprogram call or raise
3142 -- statement of any kind in the sequence of statements
3144 ---------------------
3145 -- Has_Side_Effect --
3146 ---------------------
3148 -- What is this doing buried two levels down in exp_ch9. It seems
3149 -- like a generally useful function, and indeed there may be code
3150 -- duplication going on here ???
3152 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
3156 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
3157 -- Indicate whether N is a subprogram call or a raise statement
3159 ----------------------
3160 -- Is_Call_Or_Raise --
3161 ----------------------
3163 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
3165 return Nkind_In
(N
, N_Procedure_Call_Statement
,
3168 N_Raise_Constraint_Error
,
3169 N_Raise_Program_Error
,
3170 N_Raise_Storage_Error
);
3171 end Is_Call_Or_Raise
;
3173 -- Start of processing for Has_Side_Effect
3177 while Present
(Stmt
) loop
3178 if Is_Call_Or_Raise
(Stmt
) then
3182 -- An object declaration can also contain a function call
3183 -- or a raise statement
3185 if Nkind
(Stmt
) = N_Object_Declaration
then
3186 Expr
:= Expression
(Stmt
);
3188 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
3197 end Has_Side_Effect
;
3199 -- Start of processing for Is_Exception_Safe
3202 -- If the checks handled by the back end are not disabled, we cannot
3203 -- ensure that no exception will be raised.
3205 if not Access_Checks_Suppressed
(Empty
)
3206 or else not Discriminant_Checks_Suppressed
(Empty
)
3207 or else not Range_Checks_Suppressed
(Empty
)
3208 or else not Index_Checks_Suppressed
(Empty
)
3209 or else Opt
.Stack_Checking_Enabled
3214 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
3217 First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
3223 end Is_Exception_Safe
;
3225 -- Start of processing for Build_Protected_Subprogram_Body
3228 Op_Spec
:= Specification
(N
);
3229 Exc_Safe
:= Is_Exception_Safe
(N
);
3232 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
3234 -- Build a list of the formal parameters of the protected version of
3235 -- the subprogram to use as the actual parameters of the unprotected
3238 Uactuals
:= New_List
;
3239 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
3240 while Present
(Pformal
) loop
3242 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))),
3247 -- Make a call to the unprotected version of the subprogram built above
3248 -- for use by the protected version built below.
3250 if Nkind
(Op_Spec
) = N_Function_Specification
then
3252 R
:= Make_Temporary
(Loc
, 'R');
3254 Make_Object_Declaration
(Loc
,
3255 Defining_Identifier
=> R
,
3256 Constant_Present
=> True,
3257 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
3259 Make_Function_Call
(Loc
,
3260 Name
=> Make_Identifier
(Loc
,
3261 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3262 Parameter_Associations
=> Uactuals
));
3265 Make_Simple_Return_Statement
(Loc
,
3266 Expression
=> New_Reference_To
(R
, Loc
));
3269 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
3270 Expression
=> Make_Function_Call
(Loc
,
3272 Make_Identifier
(Loc
,
3273 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3274 Parameter_Associations
=> Uactuals
));
3279 Make_Procedure_Call_Statement
(Loc
,
3281 Make_Identifier
(Loc
,
3282 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3283 Parameter_Associations
=> Uactuals
);
3286 -- Wrap call in block that will be covered by an at_end handler
3288 if not Exc_Safe
then
3289 Unprot_Call
:= Make_Block_Statement
(Loc
,
3290 Handled_Statement_Sequence
=>
3291 Make_Handled_Sequence_Of_Statements
(Loc
,
3292 Statements
=> New_List
(Unprot_Call
)));
3295 -- Make the protected subprogram body. This locks the protected
3296 -- object and calls the unprotected version of the subprogram.
3298 case Corresponding_Runtime_Package
(Pid
) is
3299 when System_Tasking_Protected_Objects_Entries
=>
3300 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
3301 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
3303 when System_Tasking_Protected_Objects_Single_Entry
=>
3304 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
3305 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
3307 when System_Tasking_Protected_Objects
=>
3308 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock
), Loc
);
3309 Service_Name
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
3312 raise Program_Error
;
3316 Make_Attribute_Reference
(Loc
,
3318 Make_Selected_Component
(Loc
,
3320 Make_Identifier
(Loc
, Name_uObject
),
3322 Make_Identifier
(Loc
, Name_uObject
)),
3323 Attribute_Name
=> Name_Unchecked_Access
);
3325 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
3327 Parameter_Associations
=> New_List
(Object_Parm
));
3329 if Abort_Allowed
then
3331 Make_Procedure_Call_Statement
(Loc
,
3332 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
3333 Parameter_Associations
=> Empty_List
),
3337 Stmts
:= New_List
(Lock_Stmt
);
3340 if not Exc_Safe
then
3341 Append
(Unprot_Call
, Stmts
);
3343 if Nkind
(Op_Spec
) = N_Function_Specification
then
3345 Stmts
:= Empty_List
;
3347 Append
(Unprot_Call
, Stmts
);
3351 Make_Procedure_Call_Statement
(Loc
,
3352 Name
=> Service_Name
,
3353 Parameter_Associations
=>
3354 New_List
(New_Copy_Tree
(Object_Parm
))),
3357 if Abort_Allowed
then
3359 Make_Procedure_Call_Statement
(Loc
,
3360 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
3361 Parameter_Associations
=> Empty_List
),
3365 if Nkind
(Op_Spec
) = N_Function_Specification
then
3366 Append
(Return_Stmt
, Stmts
);
3367 Append
(Make_Block_Statement
(Loc
,
3368 Declarations
=> New_List
(Unprot_Call
),
3369 Handled_Statement_Sequence
=>
3370 Make_Handled_Sequence_Of_Statements
(Loc
,
3371 Statements
=> Stmts
)), Pre_Stmts
);
3377 Make_Subprogram_Body
(Loc
,
3378 Declarations
=> Empty_List
,
3379 Specification
=> P_Op_Spec
,
3380 Handled_Statement_Sequence
=>
3381 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
3383 if not Exc_Safe
then
3384 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
3388 end Build_Protected_Subprogram_Body
;
3390 -------------------------------------
3391 -- Build_Protected_Subprogram_Call --
3392 -------------------------------------
3394 procedure Build_Protected_Subprogram_Call
3398 External
: Boolean := True)
3400 Loc
: constant Source_Ptr
:= Sloc
(N
);
3401 Sub
: constant Entity_Id
:= Entity
(Name
);
3407 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
3410 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
3413 if Present
(Parameter_Associations
(N
)) then
3414 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
3419 -- If the type is an untagged derived type, convert to the root type,
3420 -- which is the one on which the operations are defined.
3422 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
3423 and then not Is_Tagged_Type
(Etype
(Rec
))
3424 and then Is_Derived_Type
(Etype
(Rec
))
3426 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
3427 Set_Subtype_Mark
(Rec
,
3428 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
3431 Prepend
(Rec
, Params
);
3433 if Ekind
(Sub
) = E_Procedure
then
3435 Make_Procedure_Call_Statement
(Loc
,
3437 Parameter_Associations
=> Params
));
3440 pragma Assert
(Ekind
(Sub
) = E_Function
);
3442 Make_Function_Call
(Loc
,
3444 Parameter_Associations
=> Params
));
3448 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
3449 and then Is_Entity_Name
(Expression
(Rec
))
3450 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
3452 Add_Shared_Var_Lock_Procs
(N
);
3454 end Build_Protected_Subprogram_Call
;
3456 -------------------------
3457 -- Build_Selected_Name --
3458 -------------------------
3460 function Build_Selected_Name
3461 (Prefix
: Entity_Id
;
3462 Selector
: Entity_Id
;
3463 Append_Char
: Character := ' ') return Name_Id
3465 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
3466 Select_Len
: Natural;
3469 Get_Name_String
(Chars
(Selector
));
3470 Select_Len
:= Name_Len
;
3471 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
3472 Get_Name_String
(Chars
(Prefix
));
3474 -- If scope is anonymous type, discard suffix to recover name of
3475 -- single protected object. Otherwise use protected type name.
3477 if Name_Buffer
(Name_Len
) = 'T' then
3478 Name_Len
:= Name_Len
- 1;
3481 Add_Str_To_Name_Buffer
("__");
3482 for J
in 1 .. Select_Len
loop
3483 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
3486 -- Now add the Append_Char if specified. The encoding to follow
3487 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3488 -- then the entity is associated to a protected type subprogram.
3489 -- Otherwise, it is a protected type entry. For each case, the
3490 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3492 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3494 if Append_Char
/= ' ' then
3495 if Append_Char
= 'P' or Append_Char
= 'N' then
3496 Add_Char_To_Name_Buffer
(Append_Char
);
3499 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
3500 return New_External_Name
(Name_Find
, ' ', -1);
3505 end Build_Selected_Name
;
3507 -----------------------------
3508 -- Build_Simple_Entry_Call --
3509 -----------------------------
3511 -- A task entry call is converted to a call to Call_Simple
3514 -- P : parms := (parm, parm, parm);
3516 -- Call_Simple (acceptor-task, entry-index, P'Address);
3522 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3523 -- the parameters, and the constructed aggregate value contains either the
3524 -- parameters or, in the case of non-elementary types, references to these
3525 -- parameters. Then the address of this aggregate is passed to the runtime
3526 -- routine, along with the task id value and the task entry index value.
3527 -- Pnn is only required if parameters are present.
3529 -- The assignments after the call are present only in the case of in-out
3530 -- or out parameters for elementary types, and are used to assign back the
3531 -- resulting values of such parameters.
3533 -- Note: the reason that we insert a block here is that in the context
3534 -- of selects, conditional entry calls etc. the entry call statement
3535 -- appears on its own, not as an element of a list.
3537 -- A protected entry call is converted to a Protected_Entry_Call:
3540 -- P : E1_Params := (param, param, param);
3542 -- Bnn : Communications_Block;
3545 -- P : E1_Params := (param, param, param);
3546 -- Bnn : Communications_Block;
3549 -- Protected_Entry_Call (
3550 -- Object => po._object'Access,
3551 -- E => <entry index>;
3552 -- Uninterpreted_Data => P'Address;
3553 -- Mode => Simple_Call;
3560 procedure Build_Simple_Entry_Call
3569 -- If call has been inlined, nothing left to do
3571 if Nkind
(N
) = N_Block_Statement
then
3575 -- Convert entry call to Call_Simple call
3578 Loc
: constant Source_Ptr
:= Sloc
(N
);
3579 Parms
: constant List_Id
:= Parameter_Associations
(N
);
3580 Stats
: constant List_Id
:= New_List
;
3583 Comm_Name
: Entity_Id
;
3587 Ent_Acc
: Entity_Id
;
3589 Iface_Tag
: Entity_Id
;
3590 Iface_Typ
: Entity_Id
;
3603 -- Simple entry and entry family cases merge here
3605 Ent
:= Entity
(Ename
);
3606 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
3607 Conctyp
:= Etype
(Concval
);
3609 -- If prefix is an access type, dereference to obtain the task type
3611 if Is_Access_Type
(Conctyp
) then
3612 Conctyp
:= Designated_Type
(Conctyp
);
3615 -- Special case for protected subprogram calls
3617 if Is_Protected_Type
(Conctyp
)
3618 and then Is_Subprogram
(Entity
(Ename
))
3620 if not Is_Eliminated
(Entity
(Ename
)) then
3621 Build_Protected_Subprogram_Call
3622 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
3629 -- First parameter is the Task_Id value from the task value or the
3630 -- Object from the protected object value, obtained by selecting
3631 -- the _Task_Id or _Object from the result of doing an unchecked
3632 -- conversion to convert the value to the corresponding record type.
3634 if Nkind
(Concval
) = N_Function_Call
3635 and then Is_Task_Type
(Conctyp
)
3636 and then Ada_Version
>= Ada_2005
3639 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
3640 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
3645 Make_Object_Declaration
(Loc
,
3646 Defining_Identifier
=> Obj
,
3647 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
3648 Expression
=> ExpR
);
3649 Set_Etype
(Obj
, Conctyp
);
3650 Decls
:= New_List
(Decl
);
3651 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
3658 Parm1
:= Concurrent_Ref
(Concval
);
3660 -- Second parameter is the entry index, computed by the routine
3661 -- provided for this purpose. The value of this expression is
3662 -- assigned to an intermediate variable to assure that any entry
3663 -- family index expressions are evaluated before the entry
3667 or else Restriction_Active
(No_Entry_Queue
) = False
3668 or else not Is_Protected_Type
(Conctyp
)
3669 or else Number_Entries
(Conctyp
) > 1
3670 or else (Has_Attach_Handler
(Conctyp
)
3671 and then not Restricted_Profile
)
3673 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
3676 Make_Object_Declaration
(Loc
,
3677 Defining_Identifier
=> X
,
3678 Object_Definition
=>
3679 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3680 Expression
=> Actual_Index_Expression
(
3681 Loc
, Entity
(Ename
), Index
, Concval
));
3683 Append_To
(Decls
, Xdecl
);
3684 Parm2
:= New_Reference_To
(X
, Loc
);
3691 -- The third parameter is the packaged parameters. If there are
3692 -- none, then it is just the null address, since nothing is passed.
3695 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
3698 -- Case of parameters present, where third argument is the address
3699 -- of a packaged record containing the required parameter values.
3702 -- First build a list of parameter values, which are references to
3703 -- objects of the parameter types.
3707 Actual
:= First_Actual
(N
);
3708 Formal
:= First_Formal
(Ent
);
3710 while Present
(Actual
) loop
3712 -- If it is a by_copy_type, copy it to a new variable. The
3713 -- packaged record has a field that points to this variable.
3715 if Is_By_Copy_Type
(Etype
(Actual
)) then
3717 Make_Object_Declaration
(Loc
,
3718 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
3719 Aliased_Present
=> True,
3720 Object_Definition
=>
3721 New_Reference_To
(Etype
(Formal
), Loc
));
3723 -- Mark the object as not needing initialization since the
3724 -- initialization is performed separately, avoiding errors
3725 -- on cases such as formals of null-excluding access types.
3727 Set_No_Initialization
(N_Node
);
3729 -- We must make an assignment statement separate for the
3730 -- case of limited type. We cannot assign it unless the
3731 -- Assignment_OK flag is set first. An out formal of an
3732 -- access type must also be initialized from the actual,
3733 -- as stated in RM 6.4.1 (13).
3735 if Ekind
(Formal
) /= E_Out_Parameter
3736 or else Is_Access_Type
(Etype
(Formal
))
3739 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
3740 Set_Assignment_OK
(N_Var
);
3742 Make_Assignment_Statement
(Loc
,
3744 Expression
=> Relocate_Node
(Actual
)));
3747 Append
(N_Node
, Decls
);
3750 Make_Attribute_Reference
(Loc
,
3751 Attribute_Name
=> Name_Unchecked_Access
,
3753 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
3755 -- Interface class-wide formal
3757 if Ada_Version
>= Ada_2005
3758 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
3759 and then Is_Interface
(Etype
(Formal
))
3761 Iface_Typ
:= Etype
(Etype
(Formal
));
3764 -- formal_iface_type! (actual.iface_tag)'reference
3767 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
3768 pragma Assert
(Present
(Iface_Tag
));
3771 Make_Reference
(Loc
,
3772 Unchecked_Convert_To
(Iface_Typ
,
3773 Make_Selected_Component
(Loc
,
3775 Relocate_Node
(Actual
),
3777 New_Reference_To
(Iface_Tag
, Loc
)))));
3783 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
3787 Next_Actual
(Actual
);
3788 Next_Formal_With_Extras
(Formal
);
3791 -- Now build the declaration of parameters initialized with the
3792 -- aggregate containing this constructed parameter list.
3794 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3797 Make_Object_Declaration
(Loc
,
3798 Defining_Identifier
=> P
,
3799 Object_Definition
=>
3800 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
3802 Make_Aggregate
(Loc
, Expressions
=> Plist
));
3805 Make_Attribute_Reference
(Loc
,
3806 Prefix
=> New_Reference_To
(P
, Loc
),
3807 Attribute_Name
=> Name_Address
);
3809 Append
(Pdecl
, Decls
);
3812 -- Now we can create the call, case of protected type
3814 if Is_Protected_Type
(Conctyp
) then
3815 case Corresponding_Runtime_Package
(Conctyp
) is
3816 when System_Tasking_Protected_Objects_Entries
=>
3818 -- Change the type of the index declaration
3820 Set_Object_Definition
(Xdecl
,
3821 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
3823 -- Some additional declarations for protected entry calls
3829 -- Bnn : Communications_Block;
3831 Comm_Name
:= Make_Temporary
(Loc
, 'B');
3834 Make_Object_Declaration
(Loc
,
3835 Defining_Identifier
=> Comm_Name
,
3836 Object_Definition
=>
3837 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
3839 -- Some additional statements for protected entry calls
3841 -- Protected_Entry_Call (
3842 -- Object => po._object'Access,
3843 -- E => <entry index>;
3844 -- Uninterpreted_Data => P'Address;
3845 -- Mode => Simple_Call;
3849 Make_Procedure_Call_Statement
(Loc
,
3851 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
3853 Parameter_Associations
=> New_List
(
3854 Make_Attribute_Reference
(Loc
,
3855 Attribute_Name
=> Name_Unchecked_Access
,
3859 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
3860 New_Occurrence_Of
(Comm_Name
, Loc
)));
3862 when System_Tasking_Protected_Objects_Single_Entry
=>
3863 -- Protected_Single_Entry_Call (
3864 -- Object => po._object'Access,
3865 -- Uninterpreted_Data => P'Address;
3866 -- Mode => Simple_Call);
3869 Make_Procedure_Call_Statement
(Loc
,
3870 Name
=> New_Reference_To
(
3871 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
3873 Parameter_Associations
=> New_List
(
3874 Make_Attribute_Reference
(Loc
,
3875 Attribute_Name
=> Name_Unchecked_Access
,
3878 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
3881 raise Program_Error
;
3884 -- Case of task type
3888 Make_Procedure_Call_Statement
(Loc
,
3889 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
3890 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
3894 Append_To
(Stats
, Call
);
3896 -- If there are out or in/out parameters by copy add assignment
3897 -- statements for the result values.
3899 if Present
(Parms
) then
3900 Actual
:= First_Actual
(N
);
3901 Formal
:= First_Formal
(Ent
);
3903 Set_Assignment_OK
(Actual
);
3904 while Present
(Actual
) loop
3905 if Is_By_Copy_Type
(Etype
(Actual
))
3906 and then Ekind
(Formal
) /= E_In_Parameter
3909 Make_Assignment_Statement
(Loc
,
3910 Name
=> New_Copy
(Actual
),
3912 Make_Explicit_Dereference
(Loc
,
3913 Make_Selected_Component
(Loc
,
3914 Prefix
=> New_Reference_To
(P
, Loc
),
3916 Make_Identifier
(Loc
, Chars
(Formal
)))));
3918 -- In all cases (including limited private types) we want
3919 -- the assignment to be valid.
3921 Set_Assignment_OK
(Name
(N_Node
));
3923 -- If the call is the triggering alternative in an
3924 -- asynchronous select, or the entry_call alternative of a
3925 -- conditional entry call, the assignments for in-out
3926 -- parameters are incorporated into the statement list that
3927 -- follows, so that there are executed only if the entry
3930 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
3931 and then N
= Triggering_Statement
(Parent
(N
)))
3933 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
3934 and then N
= Entry_Call_Statement
(Parent
(N
)))
3936 if No
(Statements
(Parent
(N
))) then
3937 Set_Statements
(Parent
(N
), New_List
);
3940 Prepend
(N_Node
, Statements
(Parent
(N
)));
3943 Insert_After
(Call
, N_Node
);
3947 Next_Actual
(Actual
);
3948 Next_Formal_With_Extras
(Formal
);
3952 -- Finally, create block and analyze it
3955 Make_Block_Statement
(Loc
,
3956 Declarations
=> Decls
,
3957 Handled_Statement_Sequence
=>
3958 Make_Handled_Sequence_Of_Statements
(Loc
,
3959 Statements
=> Stats
)));
3963 end Build_Simple_Entry_Call
;
3965 --------------------------------
3966 -- Build_Task_Activation_Call --
3967 --------------------------------
3969 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
3970 Loc
: constant Source_Ptr
:= Sloc
(N
);
3977 -- Get the activation chain entity. Except in the case of a package
3978 -- body, this is in the node that was passed. For a package body, we
3979 -- have to find the corresponding package declaration node.
3981 if Nkind
(N
) = N_Package_Body
then
3982 P
:= Corresponding_Spec
(N
);
3985 exit when Nkind
(P
) = N_Package_Declaration
;
3988 Chain
:= Activation_Chain_Entity
(P
);
3991 Chain
:= Activation_Chain_Entity
(N
);
3994 if Present
(Chain
) then
3995 if Restricted_Profile
then
3996 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
3998 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
4002 Make_Procedure_Call_Statement
(Loc
,
4004 Parameter_Associations
=>
4005 New_List
(Make_Attribute_Reference
(Loc
,
4006 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4007 Attribute_Name
=> Name_Unchecked_Access
)));
4009 if Nkind
(N
) = N_Package_Declaration
then
4010 if Present
(Corresponding_Body
(N
)) then
4013 elsif Present
(Private_Declarations
(Specification
(N
))) then
4014 Append
(Call
, Private_Declarations
(Specification
(N
)));
4017 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4021 if Present
(Handled_Statement_Sequence
(N
)) then
4023 -- The call goes at the start of the statement sequence
4024 -- after the start of exception range label if one is present.
4030 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4032 -- A special case, skip exception range label if one is
4033 -- present (from front end zcx processing).
4035 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
4039 -- Another special case, if the first statement is a block
4040 -- from optimization of a local raise to a goto, then the
4041 -- call goes inside this block.
4043 if Nkind
(Stm
) = N_Block_Statement
4044 and then Exception_Junk
(Stm
)
4047 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
4050 -- Insertion point is after any exception label pushes,
4051 -- since we want it covered by any local handlers.
4053 while Nkind
(Stm
) in N_Push_xxx_Label
loop
4057 -- Now we have the proper insertion point
4059 Insert_Before
(Stm
, Call
);
4063 Set_Handled_Statement_Sequence
(N
,
4064 Make_Handled_Sequence_Of_Statements
(Loc
,
4065 Statements
=> New_List
(Call
)));
4070 Check_Task_Activation
(N
);
4072 end Build_Task_Activation_Call
;
4074 -------------------------------
4075 -- Build_Task_Allocate_Block --
4076 -------------------------------
4078 procedure Build_Task_Allocate_Block
4083 T
: constant Entity_Id
:= Entity
(Expression
(N
));
4084 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
4085 Loc
: constant Source_Ptr
:= Sloc
(N
);
4086 Chain
: constant Entity_Id
:=
4087 Make_Defining_Identifier
(Loc
, Name_uChain
);
4088 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4093 Make_Block_Statement
(Loc
,
4094 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4095 Declarations
=> New_List
(
4097 -- _Chain : Activation_Chain;
4099 Make_Object_Declaration
(Loc
,
4100 Defining_Identifier
=> Chain
,
4101 Aliased_Present
=> True,
4102 Object_Definition
=>
4103 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
4105 Handled_Statement_Sequence
=>
4106 Make_Handled_Sequence_Of_Statements
(Loc
,
4108 Statements
=> New_List
(
4112 Make_Procedure_Call_Statement
(Loc
,
4113 Name
=> New_Reference_To
(Init
, Loc
),
4114 Parameter_Associations
=> Args
),
4116 -- Activate_Tasks (_Chain);
4118 Make_Procedure_Call_Statement
(Loc
,
4119 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
4120 Parameter_Associations
=> New_List
(
4121 Make_Attribute_Reference
(Loc
,
4122 Prefix
=> New_Reference_To
(Chain
, Loc
),
4123 Attribute_Name
=> Name_Unchecked_Access
))))),
4125 Has_Created_Identifier
=> True,
4126 Is_Task_Allocation_Block
=> True);
4129 Make_Implicit_Label_Declaration
(Loc
,
4130 Defining_Identifier
=> Blkent
,
4131 Label_Construct
=> Block
));
4133 Append_To
(Actions
, Block
);
4135 Set_Activation_Chain_Entity
(Block
, Chain
);
4136 end Build_Task_Allocate_Block
;
4138 -----------------------------------------------
4139 -- Build_Task_Allocate_Block_With_Init_Stmts --
4140 -----------------------------------------------
4142 procedure Build_Task_Allocate_Block_With_Init_Stmts
4145 Init_Stmts
: List_Id
)
4147 Loc
: constant Source_Ptr
:= Sloc
(N
);
4148 Chain
: constant Entity_Id
:=
4149 Make_Defining_Identifier
(Loc
, Name_uChain
);
4150 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4154 Append_To
(Init_Stmts
,
4155 Make_Procedure_Call_Statement
(Loc
,
4156 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
4157 Parameter_Associations
=> New_List
(
4158 Make_Attribute_Reference
(Loc
,
4159 Prefix
=> New_Reference_To
(Chain
, Loc
),
4160 Attribute_Name
=> Name_Unchecked_Access
))));
4163 Make_Block_Statement
(Loc
,
4164 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4165 Declarations
=> New_List
(
4167 -- _Chain : Activation_Chain;
4169 Make_Object_Declaration
(Loc
,
4170 Defining_Identifier
=> Chain
,
4171 Aliased_Present
=> True,
4172 Object_Definition
=>
4173 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
4175 Handled_Statement_Sequence
=>
4176 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
4178 Has_Created_Identifier
=> True,
4179 Is_Task_Allocation_Block
=> True);
4182 Make_Implicit_Label_Declaration
(Loc
,
4183 Defining_Identifier
=> Blkent
,
4184 Label_Construct
=> Block
));
4186 Append_To
(Actions
, Block
);
4188 Set_Activation_Chain_Entity
(Block
, Chain
);
4189 end Build_Task_Allocate_Block_With_Init_Stmts
;
4191 -----------------------------------
4192 -- Build_Task_Proc_Specification --
4193 -----------------------------------
4195 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
4196 Loc
: constant Source_Ptr
:= Sloc
(T
);
4197 Spec_Id
: Entity_Id
;
4200 -- Case of explicit task type, suffix TB
4202 if Comes_From_Source
(T
) then
4204 Make_Defining_Identifier
(Loc
,
4205 Chars
=> New_External_Name
(Chars
(T
), "TB"));
4207 -- Case of anonymous task type, suffix B
4211 Make_Defining_Identifier
(Loc
,
4212 Chars
=> New_External_Name
(Chars
(T
), 'B'));
4215 Set_Is_Internal
(Spec_Id
);
4217 -- Associate the procedure with the task, if this is the declaration
4218 -- (and not the body) of the procedure.
4220 if No
(Task_Body_Procedure
(T
)) then
4221 Set_Task_Body_Procedure
(T
, Spec_Id
);
4225 Make_Procedure_Specification
(Loc
,
4226 Defining_Unit_Name
=> Spec_Id
,
4227 Parameter_Specifications
=> New_List
(
4228 Make_Parameter_Specification
(Loc
,
4229 Defining_Identifier
=>
4230 Make_Defining_Identifier
(Loc
, Name_uTask
),
4232 Make_Access_Definition
(Loc
,
4234 New_Reference_To
(Corresponding_Record_Type
(T
), Loc
)))));
4235 end Build_Task_Proc_Specification
;
4237 ---------------------------------------
4238 -- Build_Unprotected_Subprogram_Body --
4239 ---------------------------------------
4241 function Build_Unprotected_Subprogram_Body
4243 Pid
: Node_Id
) return Node_Id
4245 Decls
: constant List_Id
:= Declarations
(N
);
4248 -- Add renamings for the Protection object, discriminals, privals and
4249 -- the entry index constant for use by debugger.
4251 Debug_Private_Data_Declarations
(Decls
);
4253 -- Make an unprotected version of the subprogram for use within the same
4254 -- object, with a new name and an additional parameter representing the
4258 Make_Subprogram_Body
(Sloc
(N
),
4260 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
4261 Declarations
=> Decls
,
4262 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
4263 end Build_Unprotected_Subprogram_Body
;
4265 ----------------------------
4266 -- Collect_Entry_Families --
4267 ----------------------------
4269 procedure Collect_Entry_Families
4272 Current_Node
: in out Node_Id
;
4273 Conctyp
: Entity_Id
)
4276 Efam_Decl
: Node_Id
;
4277 Efam_Type
: Entity_Id
;
4280 Efam
:= First_Entity
(Conctyp
);
4281 while Present
(Efam
) loop
4282 if Ekind
(Efam
) = E_Entry_Family
then
4283 Efam_Type
:= Make_Temporary
(Loc
, 'F');
4288 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
4290 Bas_Decl
: Node_Id
:= Empty
;
4295 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
4297 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
4298 Bas
:= Make_Temporary
(Loc
, 'B');
4301 Make_Subtype_Declaration
(Loc
,
4302 Defining_Identifier
=> Bas
,
4303 Subtype_Indication
=>
4304 Make_Subtype_Indication
(Loc
,
4306 New_Occurrence_Of
(Standard_Integer
, Loc
),
4308 Make_Range_Constraint
(Loc
,
4309 Range_Expression
=> Make_Range
(Loc
,
4310 Make_Integer_Literal
4311 (Loc
, -Entry_Family_Bound
),
4312 Make_Integer_Literal
4313 (Loc
, Entry_Family_Bound
- 1)))));
4315 Insert_After
(Current_Node
, Bas_Decl
);
4316 Current_Node
:= Bas_Decl
;
4321 Make_Full_Type_Declaration
(Loc
,
4322 Defining_Identifier
=> Efam_Type
,
4324 Make_Unconstrained_Array_Definition
(Loc
,
4326 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
4328 Component_Definition
=>
4329 Make_Component_Definition
(Loc
,
4330 Aliased_Present
=> False,
4331 Subtype_Indication
=>
4332 New_Reference_To
(Standard_Character
, Loc
))));
4335 Insert_After
(Current_Node
, Efam_Decl
);
4336 Current_Node
:= Efam_Decl
;
4337 Analyze
(Efam_Decl
);
4340 Make_Component_Declaration
(Loc
,
4341 Defining_Identifier
=>
4342 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
4344 Component_Definition
=>
4345 Make_Component_Definition
(Loc
,
4346 Aliased_Present
=> False,
4347 Subtype_Indication
=>
4348 Make_Subtype_Indication
(Loc
,
4350 New_Occurrence_Of
(Efam_Type
, Loc
),
4353 Make_Index_Or_Discriminant_Constraint
(Loc
,
4354 Constraints
=> New_List
(
4356 (Etype
(Discrete_Subtype_Definition
4357 (Parent
(Efam
))), Loc
)))))));
4363 end Collect_Entry_Families
;
4365 -----------------------
4366 -- Concurrent_Object --
4367 -----------------------
4369 function Concurrent_Object
4370 (Spec_Id
: Entity_Id
;
4371 Conc_Typ
: Entity_Id
) return Entity_Id
4374 -- Parameter _O or _object
4376 if Is_Protected_Type
(Conc_Typ
) then
4377 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
4382 pragma Assert
(Is_Task_Type
(Conc_Typ
));
4383 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
4385 end Concurrent_Object
;
4387 ----------------------
4388 -- Copy_Result_Type --
4389 ----------------------
4391 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
4392 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
4397 -- If the result type is an access_to_subprogram, we must create
4398 -- new entities for its spec.
4400 if Nkind
(New_Res
) = N_Access_Definition
4401 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
4403 -- Provide new entities for the formals
4405 Par_Spec
:= First
(Parameter_Specifications
4406 (Access_To_Subprogram_Definition
(New_Res
)));
4407 while Present
(Par_Spec
) loop
4408 Formal
:= Defining_Identifier
(Par_Spec
);
4409 Set_Defining_Identifier
(Par_Spec
,
4410 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
4416 end Copy_Result_Type
;
4418 --------------------
4419 -- Concurrent_Ref --
4420 --------------------
4422 -- The expression returned for a reference to a concurrent object has the
4425 -- taskV!(name)._Task_Id
4429 -- objectV!(name)._Object
4431 -- for a protected object. For the case of an access to a concurrent
4432 -- object, there is an extra explicit dereference:
4434 -- taskV!(name.all)._Task_Id
4435 -- objectV!(name.all)._Object
4437 -- here taskV and objectV are the types for the associated records, which
4438 -- contain the required _Task_Id and _Object fields for tasks and protected
4439 -- objects, respectively.
4441 -- For the case of a task type name, the expression is
4445 -- i.e. a call to the Self function which returns precisely this Task_Id
4447 -- For the case of a protected type name, the expression is
4451 -- which is a renaming of the _object field of the current object
4452 -- record, passed into protected operations as a parameter.
4454 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
4455 Loc
: constant Source_Ptr
:= Sloc
(N
);
4456 Ntyp
: constant Entity_Id
:= Etype
(N
);
4460 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
4461 -- Check whether the reference is to the immediately enclosing task
4462 -- type, or to an outer one (rare but legal).
4464 ---------------------
4465 -- Is_Current_Task --
4466 ---------------------
4468 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
4472 Scop
:= Current_Scope
;
4473 while Present
(Scop
)
4474 and then Scop
/= Standard_Standard
4480 elsif Is_Task_Type
(Scop
) then
4483 -- If this is a procedure nested within the task type, we must
4484 -- assume that it can be called from an inner task, and therefore
4485 -- cannot treat it as a local reference.
4487 elsif Is_Overloadable
(Scop
)
4488 and then In_Open_Scopes
(T
)
4493 Scop
:= Scope
(Scop
);
4497 -- We know that we are within the task body, so should have found it
4500 raise Program_Error
;
4501 end Is_Current_Task
;
4503 -- Start of processing for Concurrent_Ref
4506 if Is_Access_Type
(Ntyp
) then
4507 Dtyp
:= Designated_Type
(Ntyp
);
4509 if Is_Protected_Type
(Dtyp
) then
4510 Sel
:= Name_uObject
;
4512 Sel
:= Name_uTask_Id
;
4516 Make_Selected_Component
(Loc
,
4518 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
4519 Make_Explicit_Dereference
(Loc
, N
)),
4520 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
4522 elsif Is_Entity_Name
(N
)
4523 and then Is_Concurrent_Type
(Entity
(N
))
4525 if Is_Task_Type
(Entity
(N
)) then
4527 if Is_Current_Task
(Entity
(N
)) then
4529 Make_Function_Call
(Loc
,
4530 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
4535 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
4536 T_Body
: constant Node_Id
:=
4537 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
4541 Make_Object_Declaration
(Loc
,
4542 Defining_Identifier
=> T_Self
,
4543 Object_Definition
=>
4544 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
4546 Make_Function_Call
(Loc
,
4547 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
4548 Prepend
(Decl
, Declarations
(T_Body
));
4550 Set_Scope
(T_Self
, Entity
(N
));
4551 return New_Occurrence_Of
(T_Self
, Loc
);
4556 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
4559 New_Reference_To
(Find_Protection_Object
(Current_Scope
), Loc
);
4563 if Is_Protected_Type
(Ntyp
) then
4564 Sel
:= Name_uObject
;
4566 elsif Is_Task_Type
(Ntyp
) then
4567 Sel
:= Name_uTask_Id
;
4570 raise Program_Error
;
4574 Make_Selected_Component
(Loc
,
4576 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
4578 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
4582 ------------------------
4583 -- Convert_Concurrent --
4584 ------------------------
4586 function Convert_Concurrent
4588 Typ
: Entity_Id
) return Node_Id
4591 if not Is_Concurrent_Type
(Typ
) then
4595 Unchecked_Convert_To
4596 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
4598 end Convert_Concurrent
;
4600 -------------------------------------
4601 -- Debug_Private_Data_Declarations --
4602 -------------------------------------
4604 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
4605 Debug_Nod
: Node_Id
;
4609 Decl
:= First
(Decls
);
4610 while Present
(Decl
)
4611 and then not Comes_From_Source
(Decl
)
4613 -- Declaration for concurrent entity _object and its access type,
4614 -- along with the entry index subtype:
4615 -- type prot_typVP is access prot_typV;
4616 -- _object : prot_typVP := prot_typV (_O);
4617 -- subtype Jnn is <Type of Index> range Low .. High;
4619 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
4620 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4622 -- Declaration for the Protection object, discriminals, privals and
4623 -- entry index constant:
4624 -- conc_typR : protection_typ renames _object._object;
4625 -- discr_nameD : discr_typ renames _object.discr_name;
4626 -- discr_nameD : discr_typ renames _task.discr_name;
4627 -- prival_name : comp_typ renames _object.comp_name;
4628 -- J : constant Jnn :=
4629 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4631 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
4632 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4633 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
4635 if Present
(Debug_Nod
) then
4636 Insert_After
(Decl
, Debug_Nod
);
4642 end Debug_Private_Data_Declarations
;
4644 ----------------------------
4645 -- Entry_Index_Expression --
4646 ----------------------------
4648 function Entry_Index_Expression
4652 Ttyp
: Entity_Id
) return Node_Id
4662 -- The queues of entries and entry families appear in textual order in
4663 -- the associated record. The entry index is computed as the sum of the
4664 -- number of queues for all entries that precede the designated one, to
4665 -- which is added the index expression, if this expression denotes a
4666 -- member of a family.
4668 -- The following is a place holder for the count of simple entries
4670 Num
:= Make_Integer_Literal
(Sloc
, 1);
4672 -- We construct an expression which is a series of addition operations.
4673 -- The first operand is the number of single entries that precede this
4674 -- one, the second operand is the index value relative to the start of
4675 -- the referenced family, and the remaining operands are the lengths of
4676 -- the entry families that precede this entry, i.e. the constructed
4679 -- number_simple_entries +
4680 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4681 -- family'length + ...
4683 -- where index-value is the given index value, and s is the index
4684 -- subtype (we have to use pos because the subtype might be an
4685 -- enumeration type preventing direct subtraction). Note that the task
4686 -- entry array is one-indexed.
4688 -- The upper bound of the entry family may be a discriminant, so we
4689 -- retrieve the lower bound explicitly to compute offset, rather than
4690 -- using the index subtype which may mention a discriminant.
4692 if Present
(Index
) then
4693 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
4702 Make_Attribute_Reference
(Sloc
,
4703 Attribute_Name
=> Name_Pos
,
4704 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
4705 Expressions
=> New_List
(Relocate_Node
(Index
))),
4713 -- Now add lengths of preceding entries and entry families
4715 Prev
:= First_Entity
(Ttyp
);
4717 while Chars
(Prev
) /= Chars
(Ent
)
4718 or else (Ekind
(Prev
) /= Ekind
(Ent
))
4719 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
4721 if Ekind
(Prev
) = E_Entry
then
4722 Set_Intval
(Num
, Intval
(Num
) + 1);
4724 elsif Ekind
(Prev
) = E_Entry_Family
then
4726 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
4727 Lo
:= Type_Low_Bound
(S
);
4728 Hi
:= Type_High_Bound
(S
);
4733 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
4735 -- Other components are anonymous types to be ignored
4745 end Entry_Index_Expression
;
4747 ---------------------------
4748 -- Establish_Task_Master --
4749 ---------------------------
4751 procedure Establish_Task_Master
(N
: Node_Id
) is
4754 if Restriction_Active
(No_Task_Hierarchy
) = False then
4755 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
4756 Prepend_To
(Declarations
(N
), Call
);
4759 end Establish_Task_Master
;
4761 --------------------------------
4762 -- Expand_Accept_Declarations --
4763 --------------------------------
4765 -- Part of the expansion of an accept statement involves the creation of
4766 -- a declaration that can be referenced from the statement sequence of
4771 -- This declaration is inserted immediately before the accept statement
4772 -- and it is important that it be inserted before the statements of the
4773 -- statement sequence are analyzed. Thus it would be too late to create
4774 -- this declaration in the Expand_N_Accept_Statement routine, which is
4775 -- why there is a separate procedure to be called directly from Sem_Ch9.
4777 -- Ann is used to hold the address of the record containing the parameters
4778 -- (see Expand_N_Entry_Call for more details on how this record is built).
4779 -- References to the parameters do an unchecked conversion of this address
4780 -- to a pointer to the required record type, and then access the field that
4781 -- holds the value of the required parameter. The entity for the address
4782 -- variable is held as the top stack element (i.e. the last element) of the
4783 -- Accept_Address stack in the corresponding entry entity, and this element
4784 -- must be set in place before the statements are processed.
4786 -- The above description applies to the case of a stand alone accept
4787 -- statement, i.e. one not appearing as part of a select alternative.
4789 -- For the case of an accept that appears as part of a select alternative
4790 -- of a selective accept, we must still create the declaration right away,
4791 -- since Ann is needed immediately, but there is an important difference:
4793 -- The declaration is inserted before the selective accept, not before
4794 -- the accept statement (which is not part of a list anyway, and so would
4795 -- not accommodate inserted declarations)
4797 -- We only need one address variable for the entire selective accept. So
4798 -- the Ann declaration is created only for the first accept alternative,
4799 -- and subsequent accept alternatives reference the same Ann variable.
4801 -- We can distinguish the two cases by seeing whether the accept statement
4802 -- is part of a list. If not, then it must be in an accept alternative.
4804 -- To expand the requeue statement, a label is provided at the end of the
4805 -- accept statement or alternative of which it is a part, so that the
4806 -- statement can be skipped after the requeue is complete. This label is
4807 -- created here rather than during the expansion of the accept statement,
4808 -- because it will be needed by any requeue statements within the accept,
4809 -- which are expanded before the accept.
4811 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
4812 Loc
: constant Source_Ptr
:= Sloc
(N
);
4813 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
4814 Ann
: Entity_Id
:= Empty
;
4822 if Expander_Active
then
4824 -- If we have no handled statement sequence, we may need to build
4825 -- a dummy sequence consisting of a null statement. This can be
4826 -- skipped if the trivial accept optimization is permitted.
4828 if not Trivial_Accept_OK
4830 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
4832 Set_Handled_Statement_Sequence
(N
,
4833 Make_Handled_Sequence_Of_Statements
(Loc
,
4834 New_List
(Make_Null_Statement
(Loc
))));
4837 -- Create and declare two labels to be placed at the end of the
4838 -- accept statement. The first label is used to allow requeues to
4839 -- skip the remainder of entry processing. The second label is used
4840 -- to skip the remainder of entry processing if the rendezvous
4841 -- completes in the middle of the accept body.
4843 if Present
(Handled_Statement_Sequence
(N
)) then
4848 Ent
:= Make_Temporary
(Loc
, 'L');
4849 Lab_Id
:= New_Reference_To
(Ent
, Loc
);
4850 Lab
:= Make_Label
(Loc
, Lab_Id
);
4852 Make_Implicit_Label_Declaration
(Loc
,
4853 Defining_Identifier
=> Ent
,
4854 Label_Construct
=> Lab
);
4855 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
4857 Ent
:= Make_Temporary
(Loc
, 'L');
4858 Lab_Id
:= New_Reference_To
(Ent
, Loc
);
4859 Lab
:= Make_Label
(Loc
, Lab_Id
);
4861 Make_Implicit_Label_Declaration
(Loc
,
4862 Defining_Identifier
=> Ent
,
4863 Label_Construct
=> Lab
);
4864 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
4872 -- Case of stand alone accept statement
4874 if Is_List_Member
(N
) then
4876 if Present
(Handled_Statement_Sequence
(N
)) then
4877 Ann
:= Make_Temporary
(Loc
, 'A');
4880 Make_Object_Declaration
(Loc
,
4881 Defining_Identifier
=> Ann
,
4882 Object_Definition
=>
4883 New_Reference_To
(RTE
(RE_Address
), Loc
));
4885 Insert_Before
(N
, Adecl
);
4888 Insert_Before
(N
, Ldecl
);
4891 Insert_Before
(N
, Ldecl2
);
4895 -- Case of accept statement which is in an accept alternative
4899 Acc_Alt
: constant Node_Id
:= Parent
(N
);
4900 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
4904 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
4905 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
4907 -- ??? Consider a single label for select statements
4909 if Present
(Handled_Statement_Sequence
(N
)) then
4911 Statements
(Handled_Statement_Sequence
(N
)));
4915 Statements
(Handled_Statement_Sequence
(N
)));
4919 -- Find first accept alternative of the selective accept. A
4920 -- valid selective accept must have at least one accept in it.
4922 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
4924 while Nkind
(Alt
) /= N_Accept_Alternative
loop
4928 -- If we are the first accept statement, then we have to create
4929 -- the Ann variable, as for the stand alone case, except that
4930 -- it is inserted before the selective accept. Similarly, a
4931 -- label for requeue expansion must be declared.
4933 if N
= Accept_Statement
(Alt
) then
4934 Ann
:= Make_Temporary
(Loc
, 'A');
4936 Make_Object_Declaration
(Loc
,
4937 Defining_Identifier
=> Ann
,
4938 Object_Definition
=>
4939 New_Reference_To
(RTE
(RE_Address
), Loc
));
4941 Insert_Before
(Sel_Acc
, Adecl
);
4944 -- If we are not the first accept statement, then find the Ann
4945 -- variable allocated by the first accept and use it.
4949 Node
(Last_Elmt
(Accept_Address
4950 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
4955 -- Merge here with Ann either created or referenced, and Adecl
4956 -- pointing to the corresponding declaration. Remaining processing
4957 -- is the same for the two cases.
4959 if Present
(Ann
) then
4960 Append_Elmt
(Ann
, Accept_Address
(Ent
));
4961 Set_Debug_Info_Needed
(Ann
);
4964 -- Create renaming declarations for the entry formals. Each reference
4965 -- to a formal becomes a dereference of a component of the parameter
4966 -- block, whose address is held in Ann. These declarations are
4967 -- eventually inserted into the accept block, and analyzed there so
4968 -- that they have the proper scope for gdb and do not conflict with
4969 -- other declarations.
4971 if Present
(Parameter_Specifications
(N
))
4972 and then Present
(Handled_Statement_Sequence
(N
))
4982 Formal
:= First_Formal
(Ent
);
4984 while Present
(Formal
) loop
4985 Comp
:= Entry_Component
(Formal
);
4987 Make_Defining_Identifier
(Loc
, Chars
(Formal
));
4989 Set_Etype
(New_F
, Etype
(Formal
));
4990 Set_Scope
(New_F
, Ent
);
4992 -- Now we set debug info needed on New_F even though it does
4993 -- not come from source, so that the debugger will get the
4994 -- right information for these generated names.
4996 Set_Debug_Info_Needed
(New_F
);
4998 if Ekind
(Formal
) = E_In_Parameter
then
4999 Set_Ekind
(New_F
, E_Constant
);
5001 Set_Ekind
(New_F
, E_Variable
);
5002 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5005 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5008 Make_Object_Renaming_Declaration
(Loc
,
5009 Defining_Identifier
=>
5012 New_Reference_To
(Etype
(Formal
), Loc
),
5014 Make_Explicit_Dereference
(Loc
,
5015 Make_Selected_Component
(Loc
,
5017 Unchecked_Convert_To
(
5018 Entry_Parameters_Type
(Ent
),
5019 New_Reference_To
(Ann
, Loc
)),
5021 New_Reference_To
(Comp
, Loc
))));
5023 if No
(Declarations
(N
)) then
5024 Set_Declarations
(N
, New_List
);
5027 Append
(Decl
, Declarations
(N
));
5028 Set_Renamed_Object
(Formal
, New_F
);
5029 Next_Formal
(Formal
);
5036 end Expand_Accept_Declarations
;
5038 ---------------------------------------------
5039 -- Expand_Access_Protected_Subprogram_Type --
5040 ---------------------------------------------
5042 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5043 Loc
: constant Source_Ptr
:= Sloc
(N
);
5045 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5046 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5047 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5048 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5049 P_List
: constant List_Id
:= Build_Protected_Spec
5050 (N
, RTE
(RE_Address
), D_T
, False);
5056 -- Create access to subprogram with full signature
5058 if Etype
(D_T
) /= Standard_Void_Type
then
5060 Make_Access_Function_Definition
(Loc
,
5061 Parameter_Specifications
=> P_List
,
5062 Result_Definition
=>
5063 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5067 Make_Access_Procedure_Definition
(Loc
,
5068 Parameter_Specifications
=> P_List
);
5072 Make_Full_Type_Declaration
(Loc
,
5073 Defining_Identifier
=> D_T2
,
5074 Type_Definition
=> Def1
);
5076 Insert_After
(N
, Decl1
);
5079 -- Create Equivalent_Type, a record with two components for an access to
5080 -- object and an access to subprogram.
5083 Make_Component_Declaration
(Loc
,
5084 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5085 Component_Definition
=>
5086 Make_Component_Definition
(Loc
,
5087 Aliased_Present
=> False,
5088 Subtype_Indication
=>
5089 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5091 Make_Component_Declaration
(Loc
,
5092 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5093 Component_Definition
=>
5094 Make_Component_Definition
(Loc
,
5095 Aliased_Present
=> False,
5096 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5099 Make_Full_Type_Declaration
(Loc
,
5100 Defining_Identifier
=> E_T
,
5102 Make_Record_Definition
(Loc
,
5104 Make_Component_List
(Loc
,
5105 Component_Items
=> Comps
)));
5107 Insert_After
(Decl1
, Decl2
);
5109 Set_Equivalent_Type
(T
, E_T
);
5110 end Expand_Access_Protected_Subprogram_Type
;
5112 --------------------------
5113 -- Expand_Entry_Barrier --
5114 --------------------------
5116 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5117 Cond
: constant Node_Id
:=
5118 Condition
(Entry_Body_Formal_Part
(N
));
5119 Prot
: constant Entity_Id
:= Scope
(Ent
);
5120 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5123 Body_Decl
: Node_Id
;
5126 if No_Run_Time_Mode
then
5127 Error_Msg_CRT
("entry barrier", N
);
5131 -- The body of the entry barrier must be analyzed in the context of the
5132 -- protected object, but its scope is external to it, just as any other
5133 -- unprotected version of a protected operation. The specification has
5134 -- been produced when the protected type declaration was elaborated. We
5135 -- build the body, insert it in the enclosing scope, but analyze it in
5136 -- the current context. A more uniform approach would be to treat the
5137 -- barrier just as a protected function, and discard the protected
5138 -- version of it because it is never called.
5140 if Expander_Active
then
5141 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
5142 Func
:= Barrier_Function
(Ent
);
5143 Set_Corresponding_Spec
(B_F
, Func
);
5145 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
5147 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
5148 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
5151 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
5153 Set_Discriminals
(Spec_Decl
);
5154 Set_Scope
(Func
, Scope
(Prot
));
5157 Analyze_And_Resolve
(Cond
, Any_Boolean
);
5160 -- The Ravenscar profile restricts barriers to simple variables declared
5161 -- within the protected object. We also allow Boolean constants, since
5162 -- these appear in several published examples and are also allowed by
5163 -- the Aonix compiler.
5165 -- Note that after analysis variables in this context will be replaced
5166 -- by the corresponding prival, that is to say a renaming of a selected
5167 -- component of the form _Object.Var. If expansion is disabled, as
5168 -- within a generic, we check that the entity appears in the current
5171 if Is_Entity_Name
(Cond
) then
5173 -- A small optimization of useless renamings. If the scope of the
5174 -- entity of the condition is not the barrier function, then the
5175 -- condition does not reference any of the generated renamings
5176 -- within the function.
5179 and then Scope
(Entity
(Cond
)) /= Func
5181 Set_Declarations
(B_F
, Empty_List
);
5184 if Entity
(Cond
) = Standard_False
5186 Entity
(Cond
) = Standard_True
5190 elsif not Expander_Active
5191 and then Scope
(Entity
(Cond
)) = Current_Scope
5195 -- Check for case of _object.all.field (note that the explicit
5196 -- dereference gets inserted by analyze/expand of _object.field)
5198 elsif Present
(Renamed_Object
(Entity
(Cond
)))
5200 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
5204 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
5210 -- It is not a boolean variable or literal, so check the restriction
5212 Check_Restriction
(Simple_Barriers
, Cond
);
5213 end Expand_Entry_Barrier
;
5215 ------------------------------
5216 -- Expand_N_Abort_Statement --
5217 ------------------------------
5219 -- Expand abort T1, T2, .. Tn; into:
5220 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5222 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
5223 Loc
: constant Source_Ptr
:= Sloc
(N
);
5224 Tlist
: constant List_Id
:= Names
(N
);
5230 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
5233 Tasknm
:= First
(Tlist
);
5235 while Present
(Tasknm
) loop
5238 -- A task interface class-wide type object is being aborted.
5239 -- Retrieve its _task_id by calling a dispatching routine.
5241 if Ada_Version
>= Ada_2005
5242 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
5243 and then Is_Interface
(Etype
(Tasknm
))
5244 and then Is_Task_Interface
(Etype
(Tasknm
))
5246 Append_To
(Component_Associations
(Aggr
),
5247 Make_Component_Association
(Loc
,
5248 Choices
=> New_List
(
5249 Make_Integer_Literal
(Loc
, Count
)),
5252 -- Task_Id (Tasknm._disp_get_task_id)
5254 Make_Unchecked_Type_Conversion
(Loc
,
5256 New_Reference_To
(RTE
(RO_ST_Task_Id
), Loc
),
5258 Make_Selected_Component
(Loc
,
5260 New_Copy_Tree
(Tasknm
),
5262 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
5265 Append_To
(Component_Associations
(Aggr
),
5266 Make_Component_Association
(Loc
,
5267 Choices
=> New_List
(
5268 Make_Integer_Literal
(Loc
, Count
)),
5269 Expression
=> Concurrent_Ref
(Tasknm
)));
5276 Make_Procedure_Call_Statement
(Loc
,
5277 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
5278 Parameter_Associations
=> New_List
(
5279 Make_Qualified_Expression
(Loc
,
5280 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
5281 Expression
=> Aggr
))));
5284 end Expand_N_Abort_Statement
;
5286 -------------------------------
5287 -- Expand_N_Accept_Statement --
5288 -------------------------------
5290 -- This procedure handles expansion of accept statements that stand
5291 -- alone, i.e. they are not part of an accept alternative. The expansion
5292 -- of accept statement in accept alternatives is handled by the routines
5293 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5294 -- following description applies only to stand alone accept statements.
5296 -- If there is no handled statement sequence, or only null statements,
5297 -- then this is called a trivial accept, and the expansion is:
5299 -- Accept_Trivial (entry-index)
5301 -- If there is a handled statement sequence, then the expansion is:
5308 -- Accept_Call (entry-index, Ann);
5309 -- Renaming_Declarations for formals
5310 -- <statement sequence from N_Accept_Statement node>
5311 -- Complete_Rendezvous;
5316 -- <exception handler from N_Accept_Statement node>
5317 -- Complete_Rendezvous;
5319 -- <exception handler from N_Accept_Statement node>
5320 -- Complete_Rendezvous;
5325 -- when all others =>
5326 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5329 -- The first three declarations were already inserted ahead of the accept
5330 -- statement by the Expand_Accept_Declarations procedure, which was called
5331 -- directly from the semantics during analysis of the accept statement,
5332 -- before analyzing its contained statements.
5334 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5335 -- from possible expansion activity (the original source of course does
5336 -- not have any declarations associated with the accept statement, since
5337 -- an accept statement has no declarative part). In particular, if the
5338 -- expander is active, the first such declaration is the declaration of
5339 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5341 -- The two blocks are merged into a single block if the inner block has
5342 -- no exception handlers, but otherwise two blocks are required, since
5343 -- exceptions might be raised in the exception handlers of the inner
5344 -- block, and Exceptional_Complete_Rendezvous must be called.
5346 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
5347 Loc
: constant Source_Ptr
:= Sloc
(N
);
5348 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5349 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
5350 Eindx
: constant Node_Id
:= Entry_Index
(N
);
5351 Eent
: constant Entity_Id
:= Entity
(Ename
);
5352 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
5353 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
5354 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
5359 -- Start of processing for Expand_N_Accept_Statement
5362 -- If accept statement is not part of a list, then its parent must be
5363 -- an accept alternative, and, as described above, we do not do any
5364 -- expansion for such accept statements at this level.
5366 if not Is_List_Member
(N
) then
5367 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
5370 -- Trivial accept case (no statement sequence, or null statements).
5371 -- If the accept statement has declarations, then just insert them
5372 -- before the procedure call.
5374 elsif Trivial_Accept_OK
5375 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5377 -- Remove declarations for renamings, because the parameter block
5378 -- will not be assigned.
5385 D
:= First
(Declarations
(N
));
5387 while Present
(D
) loop
5389 if Nkind
(D
) = N_Object_Renaming_Declaration
then
5397 if Present
(Declarations
(N
)) then
5398 Insert_Actions
(N
, Declarations
(N
));
5402 Make_Procedure_Call_Statement
(Loc
,
5403 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
5404 Parameter_Associations
=> New_List
(
5405 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
5409 -- Discard Entry_Address that was created for it, so it will not be
5410 -- emitted if this accept statement is in the statement part of a
5411 -- delay alternative.
5413 if Present
(Stats
) then
5414 Remove_Last_Elmt
(Acstack
);
5417 -- Case of statement sequence present
5420 -- Construct the block, using the declarations from the accept
5421 -- statement if any to initialize the declarations of the block.
5423 Blkent
:= Make_Temporary
(Loc
, 'A');
5424 Set_Ekind
(Blkent
, E_Block
);
5425 Set_Etype
(Blkent
, Standard_Void_Type
);
5426 Set_Scope
(Blkent
, Current_Scope
);
5429 Make_Block_Statement
(Loc
,
5430 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5431 Declarations
=> Declarations
(N
),
5432 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
5434 -- For the analysis of the generated declarations, the parent node
5435 -- must be properly set.
5437 Set_Parent
(Block
, Parent
(N
));
5439 -- Prepend call to Accept_Call to main statement sequence If the
5440 -- accept has exception handlers, the statement sequence is wrapped
5441 -- in a block. Insert call and renaming declarations in the
5442 -- declarations of the block, so they are elaborated before the
5446 Make_Procedure_Call_Statement
(Loc
,
5447 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
5448 Parameter_Associations
=> New_List
(
5449 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
5450 New_Reference_To
(Ann
, Loc
)));
5452 if Parent
(Stats
) = N
then
5453 Prepend
(Call
, Statements
(Stats
));
5462 Push_Scope
(Blkent
);
5470 D
:= First
(Declarations
(N
));
5471 while Present
(D
) loop
5474 if Nkind
(D
) = N_Object_Renaming_Declaration
then
5476 -- The renaming declarations for the formals were created
5477 -- during analysis of the accept statement, and attached to
5478 -- the list of declarations. Place them now in the context
5479 -- of the accept block or subprogram.
5482 Typ
:= Entity
(Subtype_Mark
(D
));
5483 Insert_After
(Call
, D
);
5486 -- If the formal is class_wide, it does not have an actual
5487 -- subtype. The analysis of the renaming declaration creates
5488 -- one, but we need to retain the class-wide nature of the
5491 if Is_Class_Wide_Type
(Typ
) then
5492 Set_Etype
(Defining_Identifier
(D
), Typ
);
5503 -- Replace the accept statement by the new block
5508 -- Last step is to unstack the Accept_Address value
5510 Remove_Last_Elmt
(Acstack
);
5512 end Expand_N_Accept_Statement
;
5514 ----------------------------------
5515 -- Expand_N_Asynchronous_Select --
5516 ----------------------------------
5518 -- This procedure assumes that the trigger statement is an entry call or
5519 -- a dispatching procedure call. A delay alternative should already have
5520 -- been expanded into an entry call to the appropriate delay object Wait
5523 -- If the trigger is a task entry call, the select is implemented with
5524 -- a Task_Entry_Call:
5529 -- P : parms := (parm, parm, parm);
5531 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5533 -- procedure _clean is
5536 -- Cancel_Task_Entry_Call (C);
5543 -- (<acceptor-task>, -- Acceptor
5544 -- <entry-index>, -- E
5545 -- P'Address, -- Uninterpreted_Data
5546 -- Asynchronous_Call, -- Mode
5547 -- B); -- Rendezvous_Successful
5554 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5557 -- when Abort_Signal => Abort_Undefer;
5564 -- <triggered-statements>
5568 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5569 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5573 -- P : parms := (parm, parm, parm);
5575 -- Call_Simple (acceptor-task, entry-index, P'Address);
5581 -- so the task at hand is to convert the latter expansion into the former
5583 -- If the trigger is a protected entry call, the select is implemented
5584 -- with Protected_Entry_Call:
5587 -- P : E1_Params := (param, param, param);
5588 -- Bnn : Communications_Block;
5593 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5595 -- procedure _clean is
5598 -- if Enqueued (Bnn) then
5599 -- Cancel_Protected_Entry_Call (Bnn);
5606 -- Protected_Entry_Call
5607 -- (po._object'Access, -- Object
5608 -- <entry index>, -- E
5609 -- P'Address, -- Uninterpreted_Data
5610 -- Asynchronous_Call, -- Mode
5613 -- if Enqueued (Bnn) then
5617 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5620 -- when Abort_Signal => Abort_Undefer;
5623 -- if not Cancelled (Bnn) then
5624 -- <triggered-statements>
5628 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5632 -- P : E1_Params := (param, param, param);
5633 -- Bnn : Communications_Block;
5636 -- Protected_Entry_Call
5637 -- (po._object'Access, -- Object
5638 -- <entry index>, -- E
5639 -- P'Address, -- Uninterpreted_Data
5640 -- Simple_Call, -- Mode
5647 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5651 -- B : Boolean := False;
5652 -- Bnn : Communication_Block;
5653 -- C : Ada.Tags.Prim_Op_Kind;
5654 -- D : System.Storage_Elements.Dummy_Communication_Block;
5655 -- K : Ada.Tags.Tagged_Kind :=
5656 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5657 -- P : Parameters := (Param1 .. ParamN);
5662 -- if K = Ada.Tags.TK_Limited_Tagged then
5663 -- <dispatching-call>;
5664 -- <triggering-statements>;
5668 -- Ada.Tags.Get_Offset_Index
5669 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5671 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5673 -- if C = POK_Protected_Entry then
5675 -- procedure _clean is
5677 -- if Enqueued (Bnn) then
5678 -- Cancel_Protected_Entry_Call (Bnn);
5684 -- _Disp_Asynchronous_Select
5685 -- (<object>, S, P'Address, D, B);
5686 -- Bnn := Communication_Block (D);
5688 -- Param1 := P.Param1;
5690 -- ParamN := P.ParamN;
5692 -- if Enqueued (Bnn) then
5693 -- <abortable-statements>
5696 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5699 -- when Abort_Signal => Abort_Undefer;
5702 -- if not Cancelled (Bnn) then
5703 -- <triggering-statements>
5706 -- elsif C = POK_Task_Entry then
5708 -- procedure _clean is
5710 -- Cancel_Task_Entry_Call (U);
5716 -- _Disp_Asynchronous_Select
5717 -- (<object>, S, P'Address, D, B);
5718 -- Bnn := Communication_Bloc (D);
5720 -- Param1 := P.Param1;
5722 -- ParamN := P.ParamN;
5727 -- <abortable-statements>
5729 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5732 -- when Abort_Signal => Abort_Undefer;
5736 -- <triggering-statements>
5741 -- <dispatching-call>;
5742 -- <triggering-statements>
5747 -- The job is to convert this to the asynchronous form
5749 -- If the trigger is a delay statement, it will have been expanded into a
5750 -- call to one of the GNARL delay procedures. This routine will convert
5751 -- this into a protected entry call on a delay object and then continue
5752 -- processing as for a protected entry call trigger. This requires
5753 -- declaring a Delay_Block object and adding a pointer to this object to
5754 -- the parameter list of the delay procedure to form the parameter list of
5755 -- the entry call. This object is used by the runtime to queue the delay
5758 -- For a description of the use of P and the assignments after the call,
5759 -- see Expand_N_Entry_Call_Statement.
5761 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
5762 Loc
: constant Source_Ptr
:= Sloc
(N
);
5763 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
5764 Astats
: constant List_Id
:= Statements
(Abrt
);
5765 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
5766 Tstats
: constant List_Id
:= Statements
(Trig
);
5768 Abort_Block_Ent
: Entity_Id
;
5769 Abortable_Block
: Node_Id
;
5771 Blk_Ent
: Entity_Id
;
5772 Blk_Typ
: Entity_Id
;
5774 Call_Ent
: Entity_Id
;
5775 Cancel_Param
: Entity_Id
;
5776 Cleanup_Block
: Node_Id
;
5777 Cleanup_Block_Ent
: Entity_Id
;
5778 Cleanup_Stmts
: List_Id
;
5779 Conc_Typ_Stmts
: List_Id
;
5781 Dblock_Ent
: Entity_Id
;
5786 Enqueue_Call
: Node_Id
;
5790 Lim_Typ_Stmts
: List_Id
;
5796 ProtE_Stmts
: List_Id
;
5797 ProtP_Stmts
: List_Id
;
5800 Target_Undefer
: RE_Id
;
5801 TaskE_Stmts
: List_Id
;
5802 Undefer_Args
: List_Id
:= No_List
;
5804 B
: Entity_Id
; -- Call status flag
5805 Bnn
: Entity_Id
; -- Communication block
5806 C
: Entity_Id
; -- Call kind
5807 K
: Entity_Id
; -- Tagged kind
5808 P
: Entity_Id
; -- Parameter block
5809 S
: Entity_Id
; -- Primitive operation slot
5810 T
: Entity_Id
; -- Additional status flag
5813 Blk_Ent
:= Make_Temporary
(Loc
, 'A');
5814 Ecall
:= Triggering_Statement
(Trig
);
5816 -- The arguments in the call may require dynamic allocation, and the
5817 -- call statement may have been transformed into a block. The block
5818 -- may contain additional declarations for internal entities, and the
5819 -- original call is found by sequential search.
5821 if Nkind
(Ecall
) = N_Block_Statement
then
5822 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
5823 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
5824 N_Entry_Call_Statement
)
5830 -- This is either a dispatching call or a delay statement used as a
5831 -- trigger which was expanded into a procedure call.
5833 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
5834 if Ada_Version
>= Ada_2005
5836 (No
(Original_Node
(Ecall
))
5837 or else not Nkind_In
(Original_Node
(Ecall
),
5838 N_Delay_Relative_Statement
,
5839 N_Delay_Until_Statement
))
5841 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
5846 -- Call status flag processing, generate:
5847 -- B : Boolean := False;
5849 B
:= Build_B
(Loc
, Decls
);
5851 -- Communication block processing, generate:
5852 -- Bnn : Communication_Block;
5854 Bnn
:= Make_Temporary
(Loc
, 'B');
5856 Make_Object_Declaration
(Loc
,
5857 Defining_Identifier
=> Bnn
,
5858 Object_Definition
=>
5859 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
5861 -- Call kind processing, generate:
5862 -- C : Ada.Tags.Prim_Op_Kind;
5864 C
:= Build_C
(Loc
, Decls
);
5866 -- Tagged kind processing, generate:
5867 -- K : Ada.Tags.Tagged_Kind :=
5868 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5870 -- Dummy communication block, generate:
5871 -- D : Dummy_Communication_Block;
5874 Make_Object_Declaration
(Loc
,
5875 Defining_Identifier
=>
5876 Make_Defining_Identifier
(Loc
, Name_uD
),
5877 Object_Definition
=>
5879 RTE
(RE_Dummy_Communication_Block
), Loc
)));
5881 K
:= Build_K
(Loc
, Decls
, Obj
);
5883 -- Parameter block processing
5885 Blk_Typ
:= Build_Parameter_Block
5886 (Loc
, Actuals
, Formals
, Decls
);
5887 P
:= Parameter_Block_Pack
5888 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
5890 -- Dispatch table slot processing, generate:
5893 S
:= Build_S
(Loc
, Decls
);
5895 -- Additional status flag processing, generate:
5898 T
:= Make_Temporary
(Loc
, 'T');
5900 Make_Object_Declaration
(Loc
,
5901 Defining_Identifier
=> T
,
5902 Object_Definition
=>
5903 New_Reference_To
(Standard_Boolean
, Loc
)));
5905 ------------------------------
5906 -- Protected entry handling --
5907 ------------------------------
5910 -- Param1 := P.Param1;
5912 -- ParamN := P.ParamN;
5914 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
5917 -- Bnn := Communication_Block (D);
5919 Prepend_To
(Cleanup_Stmts
,
5920 Make_Assignment_Statement
(Loc
,
5922 New_Reference_To
(Bnn
, Loc
),
5924 Make_Unchecked_Type_Conversion
(Loc
,
5926 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
5928 Make_Identifier
(Loc
, Name_uD
))));
5931 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5933 Prepend_To
(Cleanup_Stmts
,
5934 Make_Procedure_Call_Statement
(Loc
,
5937 Find_Prim_Op
(Etype
(Etype
(Obj
)),
5938 Name_uDisp_Asynchronous_Select
),
5940 Parameter_Associations
=>
5942 New_Copy_Tree
(Obj
), -- <object>
5943 New_Reference_To
(S
, Loc
), -- S
5944 Make_Attribute_Reference
(Loc
, -- P'Address
5946 New_Reference_To
(P
, Loc
),
5949 Make_Identifier
(Loc
, Name_uD
), -- D
5950 New_Reference_To
(B
, Loc
)))); -- B
5953 -- if Enqueued (Bnn) then
5954 -- <abortable-statements>
5957 Append_To
(Cleanup_Stmts
,
5958 Make_If_Statement
(Loc
,
5960 Make_Function_Call
(Loc
,
5962 New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
5963 Parameter_Associations
=>
5965 New_Reference_To
(Bnn
, Loc
))),
5968 New_Copy_List_Tree
(Astats
)));
5970 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5971 -- will then generate a _clean for the communication block Bnn.
5975 -- procedure _clean is
5977 -- if Enqueued (Bnn) then
5978 -- Cancel_Protected_Entry_Call (Bnn);
5987 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
5989 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
5991 -- Wrap the cleanup block in an exception handling block
5997 -- when Abort_Signal => Abort_Undefer;
6000 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
6003 Make_Implicit_Label_Declaration
(Loc
,
6004 Defining_Identifier
=>
6008 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
6011 -- if not Cancelled (Bnn) then
6012 -- <triggering-statements>
6015 Append_To
(ProtE_Stmts
,
6016 Make_If_Statement
(Loc
,
6020 Make_Function_Call
(Loc
,
6022 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
6023 Parameter_Associations
=>
6025 New_Reference_To
(Bnn
, Loc
)))),
6028 New_Copy_List_Tree
(Tstats
)));
6030 -------------------------
6031 -- Task entry handling --
6032 -------------------------
6035 -- Param1 := P.Param1;
6037 -- ParamN := P.ParamN;
6039 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6042 -- Bnn := Communication_Block (D);
6044 Append_To
(TaskE_Stmts
,
6045 Make_Assignment_Statement
(Loc
,
6047 New_Reference_To
(Bnn
, Loc
),
6049 Make_Unchecked_Type_Conversion
(Loc
,
6051 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
6053 Make_Identifier
(Loc
, Name_uD
))));
6056 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6058 Prepend_To
(TaskE_Stmts
,
6059 Make_Procedure_Call_Statement
(Loc
,
6062 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6063 Name_uDisp_Asynchronous_Select
),
6065 Parameter_Associations
=>
6067 New_Copy_Tree
(Obj
), -- <object>
6068 New_Reference_To
(S
, Loc
), -- S
6069 Make_Attribute_Reference
(Loc
, -- P'Address
6071 New_Reference_To
(P
, Loc
),
6074 Make_Identifier
(Loc
, Name_uD
), -- D
6075 New_Reference_To
(B
, Loc
)))); -- B
6080 Prepend_To
(TaskE_Stmts
,
6081 Make_Procedure_Call_Statement
(Loc
,
6083 New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
6084 Parameter_Associations
=>
6089 -- <abortable-statements>
6091 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
6093 Prepend_To
(Cleanup_Stmts
,
6094 Make_Procedure_Call_Statement
(Loc
,
6096 New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
6097 Parameter_Associations
=>
6100 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6101 -- will generate a _clean for the additional status flag.
6105 -- procedure _clean is
6107 -- Cancel_Task_Entry_Call (U);
6115 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
6117 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
6119 -- Wrap the cleanup block in an exception handling block
6125 -- when Abort_Signal => Abort_Undefer;
6128 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
6130 Append_To
(TaskE_Stmts
,
6131 Make_Implicit_Label_Declaration
(Loc
,
6132 Defining_Identifier
=> Abort_Block_Ent
));
6134 Append_To
(TaskE_Stmts
,
6136 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
6140 -- <triggering-statements>
6143 Append_To
(TaskE_Stmts
,
6144 Make_If_Statement
(Loc
,
6148 New_Reference_To
(T
, Loc
)),
6151 New_Copy_List_Tree
(Tstats
)));
6153 ----------------------------------
6154 -- Protected procedure handling --
6155 ----------------------------------
6158 -- <dispatching-call>;
6159 -- <triggering-statements>
6161 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
6162 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
6165 -- S := Ada.Tags.Get_Offset_Index
6166 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6169 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
6172 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6174 Append_To
(Conc_Typ_Stmts
,
6175 Make_Procedure_Call_Statement
(Loc
,
6178 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6179 Name_uDisp_Get_Prim_Op_Kind
),
6181 Parameter_Associations
=>
6183 New_Copy_Tree
(Obj
),
6184 New_Reference_To
(S
, Loc
),
6185 New_Reference_To
(C
, Loc
))));
6188 -- if C = POK_Procedure_Entry then
6190 -- elsif C = POK_Task_Entry then
6196 Append_To
(Conc_Typ_Stmts
,
6197 Make_If_Statement
(Loc
,
6201 New_Reference_To
(C
, Loc
),
6203 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
6210 Make_Elsif_Part
(Loc
,
6214 New_Reference_To
(C
, Loc
),
6216 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
)),
6225 -- <dispatching-call>;
6226 -- <triggering-statements>
6228 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
6229 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
6232 -- if K = Ada.Tags.TK_Limited_Tagged then
6239 Make_If_Statement
(Loc
,
6243 New_Reference_To
(K
, Loc
),
6245 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
6254 Make_Block_Statement
(Loc
,
6257 Handled_Statement_Sequence
=>
6258 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6263 -- Delay triggering statement processing
6266 -- Add a Delay_Block object to the parameter list of the delay
6267 -- procedure to form the parameter list of the Wait entry call.
6269 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
6271 Pdef
:= Entity
(Name
(Ecall
));
6273 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
6275 New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
6277 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
6279 New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
6281 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
6282 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
6285 Append_To
(Parameter_Associations
(Ecall
),
6286 Make_Attribute_Reference
(Loc
,
6287 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
6288 Attribute_Name
=> Name_Unchecked_Access
));
6290 -- Create the inner block to protect the abortable part
6293 Make_Implicit_Exception_Handler
(Loc
,
6294 Exception_Choices
=>
6295 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
6296 Statements
=> New_List
(
6297 Make_Procedure_Call_Statement
(Loc
,
6298 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)))));
6301 Make_Procedure_Call_Statement
(Loc
,
6302 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
6305 Make_Block_Statement
(Loc
,
6306 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
6307 Handled_Statement_Sequence
=>
6308 Make_Handled_Sequence_Of_Statements
(Loc
,
6309 Statements
=> Astats
),
6310 Has_Created_Identifier
=> True,
6311 Is_Asynchronous_Call_Block
=> True);
6313 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6316 Make_Implicit_If_Statement
(N
,
6317 Condition
=> Make_Function_Call
(Loc
,
6318 Name
=> Enqueue_Call
,
6319 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
6321 New_List
(Make_Block_Statement
(Loc
,
6322 Handled_Statement_Sequence
=>
6323 Make_Handled_Sequence_Of_Statements
(Loc
,
6324 Statements
=> New_List
(
6325 Make_Implicit_Label_Declaration
(Loc
,
6326 Defining_Identifier
=> Blk_Ent
,
6327 Label_Construct
=> Abortable_Block
),
6329 Exception_Handlers
=> Hdle
)))));
6331 Stmts
:= New_List
(Ecall
);
6333 -- Construct statement sequence for new block
6336 Make_Implicit_If_Statement
(N
,
6337 Condition
=> Make_Function_Call
(Loc
,
6338 Name
=> New_Reference_To
(
6339 RTE
(RE_Timed_Out
), Loc
),
6340 Parameter_Associations
=> New_List
(
6341 Make_Attribute_Reference
(Loc
,
6342 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
6343 Attribute_Name
=> Name_Unchecked_Access
))),
6344 Then_Statements
=> Tstats
));
6346 -- The result is the new block
6348 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
6351 Make_Block_Statement
(Loc
,
6352 Declarations
=> New_List
(
6353 Make_Object_Declaration
(Loc
,
6354 Defining_Identifier
=> Dblock_Ent
,
6355 Aliased_Present
=> True,
6356 Object_Definition
=> New_Reference_To
(
6357 RTE
(RE_Delay_Block
), Loc
))),
6359 Handled_Statement_Sequence
=>
6360 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6370 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
6371 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
6373 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
6374 Decls
:= Declarations
(Ecall
);
6376 if Is_Protected_Type
(Etype
(Concval
)) then
6378 -- Get the declarations of the block expanded from the entry call
6380 Decl
:= First
(Decls
);
6381 while Present
(Decl
)
6383 (Nkind
(Decl
) /= N_Object_Declaration
6384 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
6385 RE_Communication_Block
))
6390 pragma Assert
(Present
(Decl
));
6391 Cancel_Param
:= Defining_Identifier
(Decl
);
6393 -- Change the mode of the Protected_Entry_Call call
6395 -- Protected_Entry_Call (
6396 -- Object => po._object'Access,
6397 -- E => <entry index>;
6398 -- Uninterpreted_Data => P'Address;
6399 -- Mode => Asynchronous_Call;
6402 Stmt
:= First
(Stmts
);
6404 -- Skip assignments to temporaries created for in-out parameters
6406 -- This makes unwarranted assumptions about the shape of the expanded
6407 -- tree for the call, and should be cleaned up ???
6409 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
6415 Param
:= First
(Parameter_Associations
(Call
));
6416 while Present
(Param
)
6417 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
6422 pragma Assert
(Present
(Param
));
6423 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
6426 -- Append an if statement to execute the abortable part
6429 -- if Enqueued (Bnn) then
6432 Make_Implicit_If_Statement
(N
,
6433 Condition
=> Make_Function_Call
(Loc
,
6434 Name
=> New_Reference_To
(
6435 RTE
(RE_Enqueued
), Loc
),
6436 Parameter_Associations
=> New_List
(
6437 New_Reference_To
(Cancel_Param
, Loc
))),
6438 Then_Statements
=> Astats
));
6441 Make_Block_Statement
(Loc
,
6442 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
6443 Handled_Statement_Sequence
=>
6444 Make_Handled_Sequence_Of_Statements
(Loc
,
6445 Statements
=> Stmts
),
6446 Has_Created_Identifier
=> True,
6447 Is_Asynchronous_Call_Block
=> True);
6449 -- For the VM call Update_Exception instead of Abort_Undefer.
6450 -- See 4jexcept.ads for an explanation.
6452 if VM_Target
= No_VM
then
6453 Target_Undefer
:= RE_Abort_Undefer
;
6455 Target_Undefer
:= RE_Update_Exception
;
6457 New_List
(Make_Function_Call
(Loc
,
6458 Name
=> New_Occurrence_Of
6459 (RTE
(RE_Current_Target_Exception
), Loc
)));
6463 Make_Block_Statement
(Loc
,
6464 Handled_Statement_Sequence
=>
6465 Make_Handled_Sequence_Of_Statements
(Loc
,
6466 Statements
=> New_List
(
6467 Make_Implicit_Label_Declaration
(Loc
,
6468 Defining_Identifier
=> Blk_Ent
,
6469 Label_Construct
=> Abortable_Block
),
6474 Exception_Handlers
=> New_List
(
6475 Make_Implicit_Exception_Handler
(Loc
,
6477 -- when Abort_Signal =>
6478 -- Abort_Undefer.all;
6480 Exception_Choices
=>
6481 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
6482 Statements
=> New_List
(
6483 Make_Procedure_Call_Statement
(Loc
,
6484 Name
=> New_Reference_To
(
6485 RTE
(Target_Undefer
), Loc
),
6486 Parameter_Associations
=> Undefer_Args
)))))),
6488 -- if not Cancelled (Bnn) then
6489 -- triggered statements
6492 Make_Implicit_If_Statement
(N
,
6493 Condition
=> Make_Op_Not
(Loc
,
6495 Make_Function_Call
(Loc
,
6496 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
6497 Parameter_Associations
=> New_List
(
6498 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
6499 Then_Statements
=> Tstats
));
6501 -- Asynchronous task entry call
6508 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
6510 -- Insert declaration of B in declarations of existing block
6513 Make_Object_Declaration
(Loc
,
6514 Defining_Identifier
=> B
,
6515 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
6517 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
6519 -- Insert declaration of C in declarations of existing block
6522 Make_Object_Declaration
(Loc
,
6523 Defining_Identifier
=> Cancel_Param
,
6524 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
6526 -- Remove and save the call to Call_Simple
6528 Stmt
:= First
(Stmts
);
6530 -- Skip assignments to temporaries created for in-out parameters.
6531 -- This makes unwarranted assumptions about the shape of the expanded
6532 -- tree for the call, and should be cleaned up ???
6534 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
6540 -- Create the inner block to protect the abortable part
6543 Make_Implicit_Exception_Handler
(Loc
,
6544 Exception_Choices
=>
6545 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
6548 Make_Procedure_Call_Statement
(Loc
,
6549 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)))));
6552 Make_Procedure_Call_Statement
(Loc
,
6553 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
6556 Make_Block_Statement
(Loc
,
6557 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
6558 Handled_Statement_Sequence
=>
6559 Make_Handled_Sequence_Of_Statements
(Loc
,
6560 Statements
=> Astats
),
6561 Has_Created_Identifier
=> True,
6562 Is_Asynchronous_Call_Block
=> True);
6565 Make_Block_Statement
(Loc
,
6566 Handled_Statement_Sequence
=>
6567 Make_Handled_Sequence_Of_Statements
(Loc
,
6568 Statements
=> New_List
(
6569 Make_Implicit_Label_Declaration
(Loc
,
6570 Defining_Identifier
=>
6575 Exception_Handlers
=> Hdle
)));
6577 -- Create new call statement
6579 Params
:= Parameter_Associations
(Call
);
6582 New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
6584 New_Reference_To
(B
, Loc
));
6587 Make_Procedure_Call_Statement
(Loc
,
6589 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
6590 Parameter_Associations
=> Params
));
6592 -- Construct statement sequence for new block
6595 Make_Implicit_If_Statement
(N
,
6598 New_Reference_To
(Cancel_Param
, Loc
)),
6599 Then_Statements
=> Tstats
));
6601 -- Protected the call against abort
6604 Make_Procedure_Call_Statement
(Loc
,
6605 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
6606 Parameter_Associations
=> Empty_List
));
6609 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
6611 -- The result is the new block
6614 Make_Block_Statement
(Loc
,
6615 Declarations
=> Decls
,
6616 Handled_Statement_Sequence
=>
6617 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6620 end Expand_N_Asynchronous_Select
;
6622 -------------------------------------
6623 -- Expand_N_Conditional_Entry_Call --
6624 -------------------------------------
6626 -- The conditional task entry call is converted to a call to
6631 -- P : parms := (parm, parm, parm);
6635 -- (<acceptor-task>, -- Acceptor
6636 -- <entry-index>, -- E
6637 -- P'Address, -- Uninterpreted_Data
6638 -- Conditional_Call, -- Mode
6639 -- B); -- Rendezvous_Successful
6644 -- normal-statements
6650 -- For a description of the use of P and the assignments after the call,
6651 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6652 -- conditional entry call has already been expanded (by the Expand_N_Entry
6653 -- _Call_Statement procedure) as follows:
6656 -- P : parms := (parm, parm, parm);
6658 -- ... info for in-out parameters
6659 -- Call_Simple (acceptor-task, entry-index, P'Address);
6665 -- so the task at hand is to convert the latter expansion into the former
6667 -- The conditional protected entry call is converted to a call to
6668 -- Protected_Entry_Call:
6671 -- P : parms := (parm, parm, parm);
6672 -- Bnn : Communications_Block;
6675 -- Protected_Entry_Call
6676 -- (po._object'Access, -- Object
6677 -- <entry index>, -- E
6678 -- P'Address, -- Uninterpreted_Data
6679 -- Conditional_Call, -- Mode
6684 -- if Cancelled (Bnn) then
6687 -- normal-statements
6691 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6695 -- B : Boolean := False;
6696 -- C : Ada.Tags.Prim_Op_Kind;
6697 -- K : Ada.Tags.Tagged_Kind :=
6698 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6699 -- P : Parameters := (Param1 .. ParamN);
6703 -- if K = Ada.Tags.TK_Limited_Tagged then
6704 -- <dispatching-call>;
6705 -- <triggering-statements>
6709 -- Ada.Tags.Get_Offset_Index
6710 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6712 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6714 -- if C = POK_Protected_Entry
6715 -- or else C = POK_Task_Entry
6717 -- Param1 := P.Param1;
6719 -- ParamN := P.ParamN;
6723 -- if C = POK_Procedure
6724 -- or else C = POK_Protected_Procedure
6725 -- or else C = POK_Task_Procedure
6727 -- <dispatching-call>;
6730 -- <triggering-statements>
6732 -- <else-statements>
6737 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
6738 Loc
: constant Source_Ptr
:= Sloc
(N
);
6739 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
6740 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
6743 Blk_Typ
: Entity_Id
;
6745 Call_Ent
: Entity_Id
;
6746 Conc_Typ_Stmts
: List_Id
;
6750 Lim_Typ_Stmts
: List_Id
;
6757 Transient_Blk
: Node_Id
;
6760 B
: Entity_Id
; -- Call status flag
6761 C
: Entity_Id
; -- Call kind
6762 K
: Entity_Id
; -- Tagged kind
6763 P
: Entity_Id
; -- Parameter block
6764 S
: Entity_Id
; -- Primitive operation slot
6767 if Ada_Version
>= Ada_2005
6768 and then Nkind
(Blk
) = N_Procedure_Call_Statement
6770 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
6775 -- Call status flag processing, generate:
6776 -- B : Boolean := False;
6778 B
:= Build_B
(Loc
, Decls
);
6780 -- Call kind processing, generate:
6781 -- C : Ada.Tags.Prim_Op_Kind;
6783 C
:= Build_C
(Loc
, Decls
);
6785 -- Tagged kind processing, generate:
6786 -- K : Ada.Tags.Tagged_Kind :=
6787 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6789 K
:= Build_K
(Loc
, Decls
, Obj
);
6791 -- Parameter block processing
6793 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
6794 P
:= Parameter_Block_Pack
6795 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6797 -- Dispatch table slot processing, generate:
6800 S
:= Build_S
(Loc
, Decls
);
6803 -- S := Ada.Tags.Get_Offset_Index
6804 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6807 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
6810 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6812 Append_To
(Conc_Typ_Stmts
,
6813 Make_Procedure_Call_Statement
(Loc
,
6816 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6817 Name_uDisp_Conditional_Select
),
6819 Parameter_Associations
=>
6821 New_Copy_Tree
(Obj
), -- <object>
6822 New_Reference_To
(S
, Loc
), -- S
6823 Make_Attribute_Reference
(Loc
, -- P'Address
6825 New_Reference_To
(P
, Loc
),
6828 New_Reference_To
(C
, Loc
), -- C
6829 New_Reference_To
(B
, Loc
)))); -- B
6832 -- if C = POK_Protected_Entry
6833 -- or else C = POK_Task_Entry
6835 -- Param1 := P.Param1;
6837 -- ParamN := P.ParamN;
6840 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6842 -- Generate the if statement only when the packed parameters need
6843 -- explicit assignments to their corresponding actuals.
6845 if Present
(Unpack
) then
6846 Append_To
(Conc_Typ_Stmts
,
6847 Make_If_Statement
(Loc
,
6854 New_Reference_To
(C
, Loc
),
6856 New_Reference_To
(RTE
(
6857 RE_POK_Protected_Entry
), Loc
)),
6861 New_Reference_To
(C
, Loc
),
6863 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
6871 -- if C = POK_Procedure
6872 -- or else C = POK_Protected_Procedure
6873 -- or else C = POK_Task_Procedure
6875 -- <dispatching-call>
6877 -- <normal-statements>
6879 -- <else-statements>
6882 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
6884 Prepend_To
(N_Stats
,
6885 Make_If_Statement
(Loc
,
6891 New_Reference_To
(C
, Loc
),
6893 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
6900 New_Reference_To
(C
, Loc
),
6902 New_Reference_To
(RTE
(
6903 RE_POK_Protected_Procedure
), Loc
)),
6908 New_Reference_To
(C
, Loc
),
6910 New_Reference_To
(RTE
(
6911 RE_POK_Task_Procedure
), Loc
)))),
6916 Append_To
(Conc_Typ_Stmts
,
6917 Make_If_Statement
(Loc
,
6918 Condition
=> New_Reference_To
(B
, Loc
),
6919 Then_Statements
=> N_Stats
,
6920 Else_Statements
=> Else_Statements
(N
)));
6923 -- <dispatching-call>;
6924 -- <triggering-statements>
6926 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
6927 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
6930 -- if K = Ada.Tags.TK_Limited_Tagged then
6937 Make_If_Statement
(Loc
,
6941 New_Reference_To
(K
, Loc
),
6943 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
6952 Make_Block_Statement
(Loc
,
6955 Handled_Statement_Sequence
=>
6956 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
6958 -- As described above, The entry alternative is transformed into a
6959 -- block that contains the gnulli call, and possibly assignment
6960 -- statements for in-out parameters. The gnulli call may itself be
6961 -- rewritten into a transient block if some unconstrained parameters
6962 -- require it. We need to retrieve the call to complete its parameter
6967 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
6969 if Present
(Transient_Blk
)
6970 and then Nkind
(Transient_Blk
) = N_Block_Statement
6972 Blk
:= Transient_Blk
;
6975 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
6976 Stmt
:= First
(Stmts
);
6977 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
6982 Params
:= Parameter_Associations
(Call
);
6984 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
6986 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6988 Param
:= First
(Params
);
6989 while Present
(Param
)
6990 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
6995 pragma Assert
(Present
(Param
));
6996 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7000 -- Find the Communication_Block parameter for the call to the
7001 -- Cancelled function.
7003 Decl
:= First
(Declarations
(Blk
));
7004 while Present
(Decl
)
7005 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7006 RE_Communication_Block
)
7011 -- Add an if statement to execute the else part if the call
7012 -- does not succeed (as indicated by the Cancelled predicate).
7015 Make_Implicit_If_Statement
(N
,
7016 Condition
=> Make_Function_Call
(Loc
,
7017 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
7018 Parameter_Associations
=> New_List
(
7019 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
7020 Then_Statements
=> Else_Statements
(N
),
7021 Else_Statements
=> Statements
(Alt
)));
7024 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7026 -- Insert declaration of B in declarations of existing block
7028 if No
(Declarations
(Blk
)) then
7029 Set_Declarations
(Blk
, New_List
);
7032 Prepend_To
(Declarations
(Blk
),
7033 Make_Object_Declaration
(Loc
,
7034 Defining_Identifier
=> B
,
7035 Object_Definition
=>
7036 New_Reference_To
(Standard_Boolean
, Loc
)));
7038 -- Create new call statement
7041 New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7042 Append_To
(Params
, New_Reference_To
(B
, Loc
));
7045 Make_Procedure_Call_Statement
(Loc
,
7046 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7047 Parameter_Associations
=> Params
));
7049 -- Construct statement sequence for new block
7052 Make_Implicit_If_Statement
(N
,
7053 Condition
=> New_Reference_To
(B
, Loc
),
7054 Then_Statements
=> Statements
(Alt
),
7055 Else_Statements
=> Else_Statements
(N
)));
7058 -- The result is the new block
7061 Make_Block_Statement
(Loc
,
7062 Declarations
=> Declarations
(Blk
),
7063 Handled_Statement_Sequence
=>
7064 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7068 end Expand_N_Conditional_Entry_Call
;
7070 ---------------------------------------
7071 -- Expand_N_Delay_Relative_Statement --
7072 ---------------------------------------
7074 -- Delay statement is implemented as a procedure call to Delay_For
7075 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7076 -- simple delays imposed by the use of Protected Objects.
7078 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
7079 Loc
: constant Source_Ptr
:= Sloc
(N
);
7082 Make_Procedure_Call_Statement
(Loc
,
7083 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
7084 Parameter_Associations
=> New_List
(Expression
(N
))));
7086 end Expand_N_Delay_Relative_Statement
;
7088 ------------------------------------
7089 -- Expand_N_Delay_Until_Statement --
7090 ------------------------------------
7092 -- Delay Until statement is implemented as a procedure call to
7093 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7095 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
7096 Loc
: constant Source_Ptr
:= Sloc
(N
);
7100 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
7101 Typ
:= RTE
(RO_CA_Delay_Until
);
7103 Typ
:= RTE
(RO_RT_Delay_Until
);
7107 Make_Procedure_Call_Statement
(Loc
,
7108 Name
=> New_Reference_To
(Typ
, Loc
),
7109 Parameter_Associations
=> New_List
(Expression
(N
))));
7112 end Expand_N_Delay_Until_Statement
;
7114 -------------------------
7115 -- Expand_N_Entry_Body --
7116 -------------------------
7118 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
7120 -- Associate discriminals with the next protected operation body to be
7123 if Present
(Next_Protected_Operation
(N
)) then
7124 Set_Discriminals
(Parent
(Current_Scope
));
7126 end Expand_N_Entry_Body
;
7128 -----------------------------------
7129 -- Expand_N_Entry_Call_Statement --
7130 -----------------------------------
7132 -- An entry call is expanded into GNARLI calls to implement a simple entry
7133 -- call (see Build_Simple_Entry_Call).
7135 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
7141 if No_Run_Time_Mode
then
7142 Error_Msg_CRT
("entry call", N
);
7146 -- If this entry call is part of an asynchronous select, don't expand it
7147 -- here; it will be expanded with the select statement. Don't expand
7148 -- timed entry calls either, as they are translated into asynchronous
7151 -- ??? This whole approach is questionable; it may be better to go back
7152 -- to allowing the expansion to take place and then attempting to fix it
7153 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7154 -- whether the expanded call is on a task or protected entry.
7156 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
7157 or else N
/= Triggering_Statement
(Parent
(N
)))
7158 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
7159 or else N
/= Entry_Call_Statement
(Parent
(N
))
7160 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
7162 Extract_Entry
(N
, Concval
, Ename
, Index
);
7163 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
7165 end Expand_N_Entry_Call_Statement
;
7167 --------------------------------
7168 -- Expand_N_Entry_Declaration --
7169 --------------------------------
7171 -- If there are parameters, then first, each of the formals is marked by
7172 -- setting Is_Entry_Formal. Next a record type is built which is used to
7173 -- hold the parameter values. The name of this record type is entryP where
7174 -- entry is the name of the entry, with an additional corresponding access
7175 -- type called entryPA. The record type has matching components for each
7176 -- formal (the component names are the same as the formal names). For
7177 -- elementary types, the component type matches the formal type. For
7178 -- composite types, an access type is declared (with the name formalA)
7179 -- which designates the formal type, and the type of the component is this
7180 -- access type. Finally the Entry_Component of each formal is set to
7181 -- reference the corresponding record component.
7183 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
7184 Loc
: constant Source_Ptr
:= Sloc
(N
);
7185 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
7186 Components
: List_Id
;
7189 Last_Decl
: Node_Id
;
7190 Component
: Entity_Id
;
7193 Rec_Ent
: Entity_Id
;
7194 Acc_Ent
: Entity_Id
;
7197 Formal
:= First_Formal
(Entry_Ent
);
7200 -- Most processing is done only if parameters are present
7202 if Present
(Formal
) then
7203 Components
:= New_List
;
7205 -- Loop through formals
7207 while Present
(Formal
) loop
7208 Set_Is_Entry_Formal
(Formal
);
7210 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
7211 Set_Entry_Component
(Formal
, Component
);
7212 Set_Entry_Formal
(Component
, Formal
);
7213 Ftype
:= Etype
(Formal
);
7215 -- Declare new access type and then append
7217 Ctype
:= Make_Temporary
(Loc
, 'A');
7220 Make_Full_Type_Declaration
(Loc
,
7221 Defining_Identifier
=> Ctype
,
7223 Make_Access_To_Object_Definition
(Loc
,
7224 All_Present
=> True,
7225 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
7226 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
7228 Insert_After
(Last_Decl
, Decl
);
7231 Append_To
(Components
,
7232 Make_Component_Declaration
(Loc
,
7233 Defining_Identifier
=> Component
,
7234 Component_Definition
=>
7235 Make_Component_Definition
(Loc
,
7236 Aliased_Present
=> False,
7237 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
7239 Next_Formal_With_Extras
(Formal
);
7242 -- Create the Entry_Parameter_Record declaration
7244 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
7247 Make_Full_Type_Declaration
(Loc
,
7248 Defining_Identifier
=> Rec_Ent
,
7250 Make_Record_Definition
(Loc
,
7252 Make_Component_List
(Loc
,
7253 Component_Items
=> Components
)));
7255 Insert_After
(Last_Decl
, Decl
);
7258 -- Construct and link in the corresponding access type
7260 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
7262 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
7265 Make_Full_Type_Declaration
(Loc
,
7266 Defining_Identifier
=> Acc_Ent
,
7268 Make_Access_To_Object_Definition
(Loc
,
7269 All_Present
=> True,
7270 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
7272 Insert_After
(Last_Decl
, Decl
);
7275 end Expand_N_Entry_Declaration
;
7277 -----------------------------
7278 -- Expand_N_Protected_Body --
7279 -----------------------------
7281 -- Protected bodies are expanded to the completion of the subprograms
7282 -- created for the corresponding protected type. These are a protected and
7283 -- unprotected version of each protected subprogram in the object, a
7284 -- function to calculate each entry barrier, and a procedure to execute the
7285 -- sequence of statements of each protected entry body. For example, for
7286 -- protected type ptype:
7289 -- (O : System.Address;
7290 -- E : Protected_Entry_Index)
7293 -- <discriminant renamings>
7294 -- <private object renamings>
7296 -- return <barrier expression>;
7299 -- procedure pprocN (_object : in out poV;...) is
7300 -- <discriminant renamings>
7301 -- <private object renamings>
7303 -- <sequence of statements>
7306 -- procedure pprocP (_object : in out poV;...) is
7307 -- procedure _clean is
7310 -- ptypeS (_object, Pn);
7311 -- Unlock (_object._object'Access);
7312 -- Abort_Undefer.all;
7317 -- Lock (_object._object'Access);
7318 -- pprocN (_object;...);
7323 -- function pfuncN (_object : poV;...) return Return_Type is
7324 -- <discriminant renamings>
7325 -- <private object renamings>
7327 -- <sequence of statements>
7330 -- function pfuncP (_object : poV) return Return_Type is
7331 -- procedure _clean is
7333 -- Unlock (_object._object'Access);
7334 -- Abort_Undefer.all;
7339 -- Lock (_object._object'Access);
7340 -- return pfuncN (_object);
7347 -- (O : System.Address;
7348 -- P : System.Address;
7349 -- E : Protected_Entry_Index)
7351 -- <discriminant renamings>
7352 -- <private object renamings>
7353 -- type poVP is access poV;
7354 -- _Object : ptVP := ptVP!(O);
7358 -- <statement sequence>
7359 -- Complete_Entry_Body (_Object._Object);
7361 -- when all others =>
7362 -- Exceptional_Complete_Entry_Body (
7363 -- _Object._Object, Get_GNAT_Exception);
7367 -- The type poV is the record created for the protected type to hold
7368 -- the state of the protected object.
7370 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
7371 Loc
: constant Source_Ptr
:= Sloc
(N
);
7372 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
7374 Current_Node
: Node_Id
;
7375 Disp_Op_Body
: Node_Id
;
7376 New_Op_Body
: Node_Id
;
7377 Num_Entries
: Natural := 0;
7381 Chain
: Entity_Id
:= Empty
;
7382 -- Finalization chain that may be attached to new body
7384 function Build_Dispatching_Subprogram_Body
7387 Prot_Bod
: Node_Id
) return Node_Id
;
7388 -- Build a dispatching version of the protected subprogram body. The
7389 -- newly generated subprogram contains a call to the original protected
7390 -- body. The following code is generated:
7392 -- function <protected-function-name> (Param1 .. ParamN) return
7395 -- return <protected-function-name>P (Param1 .. ParamN);
7396 -- end <protected-function-name>;
7400 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7402 -- <protected-procedure-name>P (Param1 .. ParamN);
7403 -- end <protected-procedure-name>
7405 ---------------------------------------
7406 -- Build_Dispatching_Subprogram_Body --
7407 ---------------------------------------
7409 function Build_Dispatching_Subprogram_Body
7412 Prot_Bod
: Node_Id
) return Node_Id
7414 Loc
: constant Source_Ptr
:= Sloc
(N
);
7421 -- Generate a specification without a letter suffix in order to
7422 -- override an interface function or procedure.
7424 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
7426 -- The formal parameters become the actuals of the protected function
7427 -- or procedure call.
7429 Actuals
:= New_List
;
7430 Formal
:= First
(Parameter_Specifications
(Spec
));
7431 while Present
(Formal
) loop
7433 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
7438 if Nkind
(Spec
) = N_Procedure_Specification
then
7441 Make_Procedure_Call_Statement
(Loc
,
7443 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
7444 Parameter_Associations
=> Actuals
));
7446 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
7450 Make_Simple_Return_Statement
(Loc
,
7452 Make_Function_Call
(Loc
,
7454 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
7455 Parameter_Associations
=> Actuals
)));
7459 Make_Subprogram_Body
(Loc
,
7460 Declarations
=> Empty_List
,
7461 Specification
=> Spec
,
7462 Handled_Statement_Sequence
=>
7463 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
7464 end Build_Dispatching_Subprogram_Body
;
7466 -- Start of processing for Expand_N_Protected_Body
7469 if No_Run_Time_Mode
then
7470 Error_Msg_CRT
("protected body", N
);
7474 -- This is the proper body corresponding to a stub. The declarations
7475 -- must be inserted at the point of the stub, which in turn is in the
7476 -- declarative part of the parent unit.
7478 if Nkind
(Parent
(N
)) = N_Subunit
then
7479 Current_Node
:= Corresponding_Stub
(Parent
(N
));
7484 Op_Body
:= First
(Declarations
(N
));
7486 -- The protected body is replaced with the bodies of its
7487 -- protected operations, and the declarations for internal objects
7488 -- that may have been created for entry family bounds.
7490 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
7493 while Present
(Op_Body
) loop
7494 case Nkind
(Op_Body
) is
7495 when N_Subprogram_Declaration
=>
7498 when N_Subprogram_Body
=>
7500 -- Do not create bodies for eliminated operations
7502 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
7503 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
7506 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
7508 -- Propagate the finalization chain to the new body. In the
7509 -- unlikely event that the subprogram contains a declaration
7510 -- or allocator for an object that requires finalization,
7511 -- the corresponding chain is created when analyzing the
7512 -- body, and attached to its entity. This entity is not
7513 -- further elaborated, and so the chain properly belongs to
7514 -- the newly created subprogram body.
7517 Finalization_Chain_Entity
(Defining_Entity
(Op_Body
));
7519 if Present
(Chain
) then
7520 Set_Finalization_Chain_Entity
7521 (Protected_Body_Subprogram
7522 (Corresponding_Spec
(Op_Body
)), Chain
);
7524 (Handled_Statement_Sequence
(New_Op_Body
), False);
7527 Insert_After
(Current_Node
, New_Op_Body
);
7528 Current_Node
:= New_Op_Body
;
7529 Analyze
(New_Op_Body
);
7531 -- Build the corresponding protected operation. It may
7532 -- appear that this is needed only if this is a visible
7533 -- operation of the type, or if it is an interrupt handler,
7534 -- and this was the strategy used previously in GNAT.
7535 -- However, the operation may be exported through a 'Access
7536 -- to an external caller. This is the common idiom in code
7537 -- that uses the Ada 2005 Timing_Events package. As a result
7538 -- we need to produce the protected body for both visible
7539 -- and private operations, as well as operations that only
7540 -- have a body in the source, and for which we create a
7541 -- declaration in the protected body itself.
7543 if Present
(Corresponding_Spec
(Op_Body
)) then
7545 Build_Protected_Subprogram_Body
(
7546 Op_Body
, Pid
, Specification
(New_Op_Body
));
7548 Insert_After
(Current_Node
, New_Op_Body
);
7549 Analyze
(New_Op_Body
);
7551 Current_Node
:= New_Op_Body
;
7553 -- Generate an overriding primitive operation body for
7554 -- this subprogram if the protected type implements an
7557 if Ada_Version
>= Ada_2005
7559 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
7562 Build_Dispatching_Subprogram_Body
7563 (Op_Body
, Pid
, New_Op_Body
);
7565 Insert_After
(Current_Node
, Disp_Op_Body
);
7566 Analyze
(Disp_Op_Body
);
7568 Current_Node
:= Disp_Op_Body
;
7573 when N_Entry_Body
=>
7574 Op_Id
:= Defining_Identifier
(Op_Body
);
7575 Num_Entries
:= Num_Entries
+ 1;
7577 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
7579 Insert_After
(Current_Node
, New_Op_Body
);
7580 Current_Node
:= New_Op_Body
;
7581 Analyze
(New_Op_Body
);
7583 when N_Implicit_Label_Declaration
=>
7586 when N_Itype_Reference
=>
7587 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
7589 when N_Freeze_Entity
=>
7590 New_Op_Body
:= New_Copy
(Op_Body
);
7592 if Present
(Entity
(Op_Body
))
7593 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
7595 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
7598 Insert_After
(Current_Node
, New_Op_Body
);
7599 Current_Node
:= New_Op_Body
;
7600 Analyze
(New_Op_Body
);
7603 New_Op_Body
:= New_Copy
(Op_Body
);
7604 Insert_After
(Current_Node
, New_Op_Body
);
7605 Current_Node
:= New_Op_Body
;
7606 Analyze
(New_Op_Body
);
7608 when N_Object_Declaration
=>
7609 pragma Assert
(not Comes_From_Source
(Op_Body
));
7610 New_Op_Body
:= New_Copy
(Op_Body
);
7611 Insert_After
(Current_Node
, New_Op_Body
);
7612 Current_Node
:= New_Op_Body
;
7613 Analyze
(New_Op_Body
);
7616 raise Program_Error
;
7623 -- Finally, create the body of the function that maps an entry index
7624 -- into the corresponding body index, except when there is no entry, or
7625 -- in a Ravenscar-like profile.
7627 if Corresponding_Runtime_Package
(Pid
) =
7628 System_Tasking_Protected_Objects_Entries
7630 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
7631 Insert_After
(Current_Node
, New_Op_Body
);
7632 Current_Node
:= New_Op_Body
;
7633 Analyze
(New_Op_Body
);
7636 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7637 -- protected body. At this point all wrapper specs have been created,
7638 -- frozen and included in the dispatch table for the protected type.
7640 if Ada_Version
>= Ada_2005
then
7641 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
7643 end Expand_N_Protected_Body
;
7645 -----------------------------------------
7646 -- Expand_N_Protected_Type_Declaration --
7647 -----------------------------------------
7649 -- First we create a corresponding record type declaration used to
7650 -- represent values of this protected type.
7651 -- The general form of this type declaration is
7653 -- type poV (discriminants) is record
7654 -- _Object : aliased <kind>Protection
7655 -- [(<entry count> [, <handler count>])];
7656 -- [entry_family : array (bounds) of Void;]
7657 -- <private data fields>
7660 -- The discriminants are present only if the corresponding protected type
7661 -- has discriminants, and they exactly mirror the protected type
7662 -- discriminants. The private data fields similarly mirror the private
7663 -- declarations of the protected type.
7665 -- The Object field is always present. It contains RTS specific data used
7666 -- to control the protected object. It is declared as Aliased so that it
7667 -- can be passed as a pointer to the RTS. This allows the protected record
7668 -- to be referenced within RTS data structures. An appropriate Protection
7669 -- type and discriminant are generated.
7671 -- The Service field is present for protected objects with entries. It
7672 -- contains sufficient information to allow the entry service procedure for
7673 -- this object to be called when the object is not known till runtime.
7675 -- One entry_family component is present for each entry family in the
7676 -- task definition (see Expand_N_Task_Type_Declaration).
7678 -- When a protected object is declared, an instance of the protected type
7679 -- value record is created. The elaboration of this declaration creates the
7680 -- correct bounds for the entry families, and also evaluates the priority
7681 -- expression if needed. The initialization routine for the protected type
7682 -- itself then calls Initialize_Protection with appropriate parameters to
7683 -- initialize the value of the Task_Id field. Install_Handlers may be also
7684 -- called if a pragma Attach_Handler applies.
7686 -- Note: this record is passed to the subprograms created by the expansion
7687 -- of protected subprograms and entries. It is an in parameter to protected
7688 -- functions and an in out parameter to procedures and entry bodies. The
7689 -- Entity_Id for this created record type is placed in the
7690 -- Corresponding_Record_Type field of the associated protected type entity.
7692 -- Next we create a procedure specifications for protected subprograms and
7693 -- entry bodies. For each protected subprograms two subprograms are
7694 -- created, an unprotected and a protected version. The unprotected version
7695 -- is called from within other operations of the same protected object.
7697 -- We also build the call to register the procedure if a pragma
7698 -- Interrupt_Handler applies.
7700 -- A single subprogram is created to service all entry bodies; it has an
7701 -- additional boolean out parameter indicating that the previous entry call
7702 -- made by the current task was serviced immediately, i.e. not by proxy.
7703 -- The O parameter contains a pointer to a record object of the type
7704 -- described above. An untyped interface is used here to allow this
7705 -- procedure to be called in places where the type of the object to be
7706 -- serviced is not known. This must be done, for example, when a call that
7707 -- may have been requeued is cancelled; the corresponding object must be
7708 -- serviced, but which object that is not known till runtime.
7711 -- (O : System.Address; P : out Boolean);
7712 -- procedure pprocN (_object : in out poV);
7713 -- procedure pproc (_object : in out poV);
7714 -- function pfuncN (_object : poV);
7715 -- function pfunc (_object : poV);
7718 -- Note that this must come after the record type declaration, since
7719 -- the specs refer to this type.
7721 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
7722 Loc
: constant Source_Ptr
:= Sloc
(N
);
7723 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
7725 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
7726 -- This contains two lists; one for visible and one for private decls
7730 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
7734 Comp_Id
: Entity_Id
;
7736 Current_Node
: Node_Id
:= N
;
7737 Bdef
: Entity_Id
:= Empty
; -- avoid uninit warning
7738 Edef
: Entity_Id
:= Empty
; -- avoid uninit warning
7739 Entries_Aggr
: Node_Id
;
7740 Body_Id
: Entity_Id
;
7743 Object_Comp
: Node_Id
;
7745 procedure Check_Inlining
(Subp
: Entity_Id
);
7746 -- If the original operation has a pragma Inline, propagate the flag
7747 -- to the internal body, for possible inlining later on. The source
7748 -- operation is invisible to the back-end and is never actually called.
7750 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
7751 -- When compiling under the Ravenscar profile, private components must
7752 -- have a static size, or else a protected object will require heap
7753 -- allocation, violating the corresponding restriction. It is preferable
7754 -- to make this check here, because it provides a better error message
7755 -- than the back-end, which refers to the object as a whole.
7757 procedure Register_Handler
;
7758 -- For a protected operation that is an interrupt handler, add the
7759 -- freeze action that will register it as such.
7761 --------------------
7762 -- Check_Inlining --
7763 --------------------
7765 procedure Check_Inlining
(Subp
: Entity_Id
) is
7767 if Is_Inlined
(Subp
) then
7768 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
7769 Set_Is_Inlined
(Subp
, False);
7773 ---------------------------------
7774 -- Check_Static_Component_Size --
7775 ---------------------------------
7777 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
7778 Typ
: constant Entity_Id
:= Etype
(Comp
);
7782 if Is_Scalar_Type
(Typ
) then
7785 elsif Is_Array_Type
(Typ
) then
7786 return Compile_Time_Known_Bounds
(Typ
);
7788 elsif Is_Record_Type
(Typ
) then
7789 C
:= First_Component
(Typ
);
7790 while Present
(C
) loop
7791 if not Static_Component_Size
(C
) then
7800 -- Any other types will be checked by the back-end
7805 end Static_Component_Size
;
7807 ----------------------
7808 -- Register_Handler --
7809 ----------------------
7811 procedure Register_Handler
is
7813 -- All semantic checks already done in Sem_Prag
7815 Prot_Proc
: constant Entity_Id
:=
7817 (Specification
(Current_Node
));
7819 Proc_Address
: constant Node_Id
:=
7820 Make_Attribute_Reference
(Loc
,
7821 Prefix
=> New_Reference_To
(Prot_Proc
, Loc
),
7822 Attribute_Name
=> Name_Address
);
7824 RTS_Call
: constant Entity_Id
:=
7825 Make_Procedure_Call_Statement
(Loc
,
7828 RTE
(RE_Register_Interrupt_Handler
), Loc
),
7829 Parameter_Associations
=>
7830 New_List
(Proc_Address
));
7832 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
7833 end Register_Handler
;
7835 -- Start of processing for Expand_N_Protected_Type_Declaration
7838 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
7841 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
7844 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
7846 Qualify_Entity_Names
(N
);
7848 -- If the type has discriminants, their occurrences in the declaration
7849 -- have been replaced by the corresponding discriminals. For components
7850 -- that are constrained by discriminants, their homologues in the
7851 -- corresponding record type must refer to the discriminants of that
7852 -- record, so we must apply a new renaming to subtypes_indications:
7854 -- protected discriminant => discriminal => record discriminant
7856 -- This replacement is not applied to default expressions, for which
7857 -- the discriminal is correct.
7859 if Has_Discriminants
(Prot_Typ
) then
7865 Disc
:= First_Discriminant
(Prot_Typ
);
7866 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
7867 while Present
(Disc
) loop
7868 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
7869 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
7870 Next_Discriminant
(Disc
);
7876 -- Fill in the component declarations
7878 -- Add components for entry families. For each entry family, create an
7879 -- anonymous type declaration with the same size, and analyze the type.
7881 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
7883 -- Prepend the _Object field with the right type to the component list.
7884 -- We need to compute the number of entries, and in some cases the
7885 -- number of Attach_Handler pragmas.
7889 Num_Attach_Handler
: Int
:= 0;
7890 Protection_Subtype
: Node_Id
;
7891 Entry_Count_Expr
: constant Node_Id
:=
7892 Build_Entry_Count_Expression
7893 (Prot_Typ
, Cdecls
, Loc
);
7896 -- Could this be simplified using Corresponding_Runtime_Package???
7898 if Has_Attach_Handler
(Prot_Typ
) then
7899 Ritem
:= First_Rep_Item
(Prot_Typ
);
7900 while Present
(Ritem
) loop
7901 if Nkind
(Ritem
) = N_Pragma
7902 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
7904 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
7907 Next_Rep_Item
(Ritem
);
7910 if Restricted_Profile
then
7911 if Has_Entries
(Prot_Typ
) then
7912 Protection_Subtype
:=
7913 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
7915 Protection_Subtype
:=
7916 New_Reference_To
(RTE
(RE_Protection
), Loc
);
7919 Protection_Subtype
:=
7920 Make_Subtype_Indication
7924 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
7926 Make_Index_Or_Discriminant_Constraint
(
7928 Constraints
=> New_List
(
7930 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
7933 elsif Has_Interrupt_Handler
(Prot_Typ
) then
7934 Protection_Subtype
:=
7935 Make_Subtype_Indication
(
7937 Subtype_Mark
=> New_Reference_To
7938 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
7940 Make_Index_Or_Discriminant_Constraint
(
7942 Constraints
=> New_List
(Entry_Count_Expr
)));
7944 -- Type has explicit entries or generated primitive entry wrappers
7946 elsif Has_Entries
(Prot_Typ
)
7947 or else (Ada_Version
>= Ada_2005
7948 and then Present
(Interface_List
(N
)))
7950 case Corresponding_Runtime_Package
(Prot_Typ
) is
7951 when System_Tasking_Protected_Objects_Entries
=>
7952 Protection_Subtype
:=
7953 Make_Subtype_Indication
(Loc
,
7955 New_Reference_To
(RTE
(RE_Protection_Entries
), Loc
),
7957 Make_Index_Or_Discriminant_Constraint
(
7959 Constraints
=> New_List
(Entry_Count_Expr
)));
7961 when System_Tasking_Protected_Objects_Single_Entry
=>
7962 Protection_Subtype
:=
7963 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
7966 raise Program_Error
;
7970 Protection_Subtype
:= New_Reference_To
(RTE
(RE_Protection
), Loc
);
7974 Make_Component_Declaration
(Loc
,
7975 Defining_Identifier
=>
7976 Make_Defining_Identifier
(Loc
, Name_uObject
),
7977 Component_Definition
=>
7978 Make_Component_Definition
(Loc
,
7979 Aliased_Present
=> True,
7980 Subtype_Indication
=> Protection_Subtype
));
7983 pragma Assert
(Present
(Pdef
));
7985 -- Add private field components
7987 if Present
(Private_Declarations
(Pdef
)) then
7988 Priv
:= First
(Private_Declarations
(Pdef
));
7990 while Present
(Priv
) loop
7992 if Nkind
(Priv
) = N_Component_Declaration
then
7993 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
7995 -- When compiling for a restricted profile, the private
7996 -- components must have a static size. If not, this is an
7997 -- error for a single protected declaration, and rates a
7998 -- warning on a protected type declaration.
8000 if not Comes_From_Source
(Prot_Typ
) then
8001 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
8003 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
8004 Error_Msg_N
("component has non-static size?", Priv
);
8006 ("\creation of protected object of type& will violate"
8007 & " restriction No_Implicit_Heap_Allocations?",
8012 -- The component definition consists of a subtype indication,
8013 -- or (in Ada 2005) an access definition. Make a copy of the
8014 -- proper definition.
8017 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
8018 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
8020 Nent
: constant Entity_Id
:=
8021 Make_Defining_Identifier
(Sloc
(Oent
),
8022 Chars
=> Chars
(Oent
));
8025 if Present
(Subtype_Indication
(Old_Comp
)) then
8027 Make_Component_Definition
(Sloc
(Oent
),
8028 Aliased_Present
=> False,
8029 Subtype_Indication
=>
8030 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
8034 Make_Component_Definition
(Sloc
(Oent
),
8035 Aliased_Present
=> False,
8036 Access_Definition
=>
8037 New_Copy_Tree
(Access_Definition
(Old_Comp
),
8042 Make_Component_Declaration
(Loc
,
8043 Defining_Identifier
=> Nent
,
8044 Component_Definition
=> New_Comp
,
8045 Expression
=> Expression
(Priv
));
8047 Set_Has_Per_Object_Constraint
(Nent
,
8048 Has_Per_Object_Constraint
(Oent
));
8050 Append_To
(Cdecls
, New_Priv
);
8053 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
8055 -- Make the unprotected version of the subprogram available
8056 -- for expansion of intra object calls. There is need for
8057 -- a protected version only if the subprogram is an interrupt
8058 -- handler, otherwise this operation can only be called from
8062 Make_Subprogram_Declaration
(Loc
,
8064 Build_Protected_Sub_Specification
8065 (Priv
, Prot_Typ
, Unprotected_Mode
));
8067 Insert_After
(Current_Node
, Sub
);
8070 Set_Protected_Body_Subprogram
8071 (Defining_Unit_Name
(Specification
(Priv
)),
8072 Defining_Unit_Name
(Specification
(Sub
)));
8073 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
8074 Current_Node
:= Sub
;
8077 Make_Subprogram_Declaration
(Loc
,
8079 Build_Protected_Sub_Specification
8080 (Priv
, Prot_Typ
, Protected_Mode
));
8082 Insert_After
(Current_Node
, Sub
);
8084 Current_Node
:= Sub
;
8086 if Is_Interrupt_Handler
8087 (Defining_Unit_Name
(Specification
(Priv
)))
8089 if not Restricted_Profile
then
8099 -- Put the _Object component after the private component so that it
8100 -- be finalized early as required by 9.4 (20)
8102 Append_To
(Cdecls
, Object_Comp
);
8104 Insert_After
(Current_Node
, Rec_Decl
);
8105 Current_Node
:= Rec_Decl
;
8107 -- Analyze the record declaration immediately after construction,
8108 -- because the initialization procedure is needed for single object
8109 -- declarations before the next entity is analyzed (the freeze call
8110 -- that generates this initialization procedure is found below).
8112 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
8114 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8115 -- the corresponding record is frozen. If any wrappers are generated,
8116 -- Current_Node is updated accordingly.
8118 if Ada_Version
>= Ada_2005
then
8119 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
8122 -- Collect pointers to entry bodies and their barriers, to be placed
8123 -- in the Entry_Bodies_Array for the type. For each entry/family we
8124 -- add an expression to the aggregate which is the initial value of
8125 -- this array. The array is declared after all protected subprograms.
8127 if Has_Entries
(Prot_Typ
) then
8128 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
8130 Entries_Aggr
:= Empty
;
8133 -- Build two new procedure specifications for each protected subprogram;
8134 -- one to call from outside the object and one to call from inside.
8135 -- Build a barrier function and an entry body action procedure
8136 -- specification for each protected entry. Initialize the entry body
8137 -- array. If subprogram is flagged as eliminated, do not generate any
8138 -- internal operations.
8142 Comp
:= First
(Visible_Declarations
(Pdef
));
8144 while Present
(Comp
) loop
8145 if Nkind
(Comp
) = N_Subprogram_Declaration
then
8147 Make_Subprogram_Declaration
(Loc
,
8149 Build_Protected_Sub_Specification
8150 (Comp
, Prot_Typ
, Unprotected_Mode
));
8152 Insert_After
(Current_Node
, Sub
);
8155 Set_Protected_Body_Subprogram
8156 (Defining_Unit_Name
(Specification
(Comp
)),
8157 Defining_Unit_Name
(Specification
(Sub
)));
8158 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
8160 -- Make the protected version of the subprogram available for
8161 -- expansion of external calls.
8163 Current_Node
:= Sub
;
8166 Make_Subprogram_Declaration
(Loc
,
8168 Build_Protected_Sub_Specification
8169 (Comp
, Prot_Typ
, Protected_Mode
));
8171 Insert_After
(Current_Node
, Sub
);
8174 Current_Node
:= Sub
;
8176 -- Generate an overriding primitive operation specification for
8177 -- this subprogram if the protected type implements an interface.
8179 if Ada_Version
>= Ada_2005
8181 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
8184 Make_Subprogram_Declaration
(Loc
,
8186 Build_Protected_Sub_Specification
8187 (Comp
, Prot_Typ
, Dispatching_Mode
));
8189 Insert_After
(Current_Node
, Sub
);
8192 Current_Node
:= Sub
;
8195 -- If a pragma Interrupt_Handler applies, build and add a call to
8196 -- Register_Interrupt_Handler to the freezing actions of the
8197 -- protected version (Current_Node) of the subprogram:
8199 -- system.interrupts.register_interrupt_handler
8200 -- (prot_procP'address);
8202 if not Restricted_Profile
8203 and then Is_Interrupt_Handler
8204 (Defining_Unit_Name
(Specification
(Comp
)))
8209 elsif Nkind
(Comp
) = N_Entry_Declaration
then
8210 E_Count
:= E_Count
+ 1;
8211 Comp_Id
:= Defining_Identifier
(Comp
);
8214 Make_Defining_Identifier
(Loc
,
8215 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
8217 Make_Subprogram_Declaration
(Loc
,
8219 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
8221 Insert_After
(Current_Node
, Sub
);
8224 -- build wrapper procedure for pre/postconditions.
8226 Build_PPC_Wrapper
(Comp_Id
, N
);
8228 Set_Protected_Body_Subprogram
8229 (Defining_Identifier
(Comp
),
8230 Defining_Unit_Name
(Specification
(Sub
)));
8232 Current_Node
:= Sub
;
8235 Make_Defining_Identifier
(Loc
,
8236 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
8238 Make_Subprogram_Declaration
(Loc
,
8240 Build_Barrier_Function_Specification
(Loc
, Bdef
));
8242 Insert_After
(Current_Node
, Sub
);
8244 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
8245 Set_Barrier_Function
(Comp_Id
, Bdef
);
8246 Set_Scope
(Bdef
, Scope
(Comp_Id
));
8247 Current_Node
:= Sub
;
8249 -- Collect pointers to the protected subprogram and the barrier
8250 -- of the current entry, for insertion into Entry_Bodies_Array.
8253 Make_Aggregate
(Loc
,
8254 Expressions
=> New_List
(
8255 Make_Attribute_Reference
(Loc
,
8256 Prefix
=> New_Reference_To
(Bdef
, Loc
),
8257 Attribute_Name
=> Name_Unrestricted_Access
),
8258 Make_Attribute_Reference
(Loc
,
8259 Prefix
=> New_Reference_To
(Edef
, Loc
),
8260 Attribute_Name
=> Name_Unrestricted_Access
))),
8261 Expressions
(Entries_Aggr
));
8268 -- If there are some private entry declarations, expand it as if they
8269 -- were visible entries.
8271 if Present
(Private_Declarations
(Pdef
)) then
8272 Comp
:= First
(Private_Declarations
(Pdef
));
8273 while Present
(Comp
) loop
8274 if Nkind
(Comp
) = N_Entry_Declaration
then
8275 E_Count
:= E_Count
+ 1;
8276 Comp_Id
:= Defining_Identifier
(Comp
);
8279 Make_Defining_Identifier
(Loc
,
8280 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
8282 Make_Subprogram_Declaration
(Loc
,
8284 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
8286 Insert_After
(Current_Node
, Sub
);
8289 Set_Protected_Body_Subprogram
8290 (Defining_Identifier
(Comp
),
8291 Defining_Unit_Name
(Specification
(Sub
)));
8293 Current_Node
:= Sub
;
8296 Make_Defining_Identifier
(Loc
,
8297 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
8300 Make_Subprogram_Declaration
(Loc
,
8302 Build_Barrier_Function_Specification
(Loc
, Bdef
));
8304 Insert_After
(Current_Node
, Sub
);
8306 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
8307 Set_Barrier_Function
(Comp_Id
, Bdef
);
8308 Set_Scope
(Bdef
, Scope
(Comp_Id
));
8309 Current_Node
:= Sub
;
8311 -- Collect pointers to the protected subprogram and the barrier
8312 -- of the current entry, for insertion into Entry_Bodies_Array.
8314 Append_To
(Expressions
(Entries_Aggr
),
8315 Make_Aggregate
(Loc
,
8316 Expressions
=> New_List
(
8317 Make_Attribute_Reference
(Loc
,
8318 Prefix
=> New_Reference_To
(Bdef
, Loc
),
8319 Attribute_Name
=> Name_Unrestricted_Access
),
8320 Make_Attribute_Reference
(Loc
,
8321 Prefix
=> New_Reference_To
(Edef
, Loc
),
8322 Attribute_Name
=> Name_Unrestricted_Access
))));
8329 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8330 -- all protected subprograms have been collected.
8332 if Has_Entries
(Prot_Typ
) then
8334 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
8335 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
8337 case Corresponding_Runtime_Package
(Prot_Typ
) is
8338 when System_Tasking_Protected_Objects_Entries
=>
8339 Body_Arr
:= Make_Object_Declaration
(Loc
,
8340 Defining_Identifier
=> Body_Id
,
8341 Aliased_Present
=> True,
8342 Object_Definition
=>
8343 Make_Subtype_Indication
(Loc
,
8344 Subtype_Mark
=> New_Reference_To
(
8345 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
8347 Make_Index_Or_Discriminant_Constraint
(Loc
,
8348 Constraints
=> New_List
(
8350 Make_Integer_Literal
(Loc
, 1),
8351 Make_Integer_Literal
(Loc
, E_Count
))))),
8352 Expression
=> Entries_Aggr
);
8354 when System_Tasking_Protected_Objects_Single_Entry
=>
8355 Body_Arr
:= Make_Object_Declaration
(Loc
,
8356 Defining_Identifier
=> Body_Id
,
8357 Aliased_Present
=> True,
8358 Object_Definition
=> New_Reference_To
8359 (RTE
(RE_Entry_Body
), Loc
),
8361 Make_Aggregate
(Loc
,
8362 Expressions
=> New_List
(
8363 Make_Attribute_Reference
(Loc
,
8364 Prefix
=> New_Reference_To
(Bdef
, Loc
),
8365 Attribute_Name
=> Name_Unrestricted_Access
),
8366 Make_Attribute_Reference
(Loc
,
8367 Prefix
=> New_Reference_To
(Edef
, Loc
),
8368 Attribute_Name
=> Name_Unrestricted_Access
))));
8371 raise Program_Error
;
8374 -- A pointer to this array will be placed in the corresponding record
8375 -- by its initialization procedure so this needs to be analyzed here.
8377 Insert_After
(Current_Node
, Body_Arr
);
8378 Current_Node
:= Body_Arr
;
8381 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
8383 -- Finally, build the function that maps an entry index into the
8384 -- corresponding body. A pointer to this function is placed in each
8385 -- object of the type. Except for a ravenscar-like profile (no abort,
8386 -- no entry queue, 1 entry)
8388 if Corresponding_Runtime_Package
(Prot_Typ
) =
8389 System_Tasking_Protected_Objects_Entries
8392 Make_Subprogram_Declaration
(Loc
,
8393 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
8394 Insert_After
(Current_Node
, Sub
);
8398 end Expand_N_Protected_Type_Declaration
;
8400 --------------------------------
8401 -- Expand_N_Requeue_Statement --
8402 --------------------------------
8404 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8405 -- operations, depending on the source and destination (task or protected
8406 -- object). A dispatching requeue statement is expanded into a call to the
8407 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8408 -- jump around the remainder of processing for the original entry and, if
8409 -- the destination is (different) protected object, to attempt to service
8410 -- it. The following illustrates the various cases:
8413 -- (O : System.Address;
8414 -- P : System.Address;
8415 -- E : Protected_Entry_Index)
8417 -- <discriminant renamings>
8418 -- <private object renamings>
8419 -- type poVP is access poV;
8420 -- _object : ptVP := ptVP!(O);
8424 -- <start of statement sequence for entry>
8426 -- -- Requeue from one protected entry body to another protected
8429 -- Requeue_Protected_Entry (
8430 -- _object._object'Access,
8431 -- new._object'Access,
8436 -- <some more of the statement sequence for entry>
8438 -- -- Requeue from an entry body to a task entry
8440 -- Requeue_Protected_To_Task_Entry (
8446 -- <rest of statement sequence for entry>
8447 -- Complete_Entry_Body (_object._object);
8450 -- when all others =>
8451 -- Exceptional_Complete_Entry_Body (
8452 -- _object._object, Get_GNAT_Exception);
8456 -- Requeue of a task entry call to a task entry
8458 -- Accept_Call (E, Ann);
8459 -- <start of statement sequence for accept statement>
8460 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8462 -- <rest of statement sequence for accept statement>
8464 -- Complete_Rendezvous;
8467 -- when all others =>
8468 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8470 -- Requeue of a task entry call to a protected entry
8472 -- Accept_Call (E, Ann);
8473 -- <start of statement sequence for accept statement>
8474 -- Requeue_Task_To_Protected_Entry (
8475 -- new._object'Access,
8480 -- <rest of statement sequence for accept statement>
8482 -- Complete_Rendezvous;
8485 -- when all others =>
8486 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8488 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8489 -- marked by pragma Implemented (XXX, By_Entry).
8491 -- The requeue is inside a protected entry:
8494 -- (O : System.Address;
8495 -- P : System.Address;
8496 -- E : Protected_Entry_Index)
8498 -- <discriminant renamings>
8499 -- <private object renamings>
8500 -- type poVP is access poV;
8501 -- _object : ptVP := ptVP!(O);
8505 -- <start of statement sequence for entry>
8508 -- (<interface class-wide object>,
8511 -- Ada.Tags.Get_Offset_Index
8513 -- <interface dispatch table index of target entry>),
8517 -- <rest of statement sequence for entry>
8518 -- Complete_Entry_Body (_object._object);
8521 -- when all others =>
8522 -- Exceptional_Complete_Entry_Body (
8523 -- _object._object, Get_GNAT_Exception);
8527 -- The requeue is inside a task entry:
8529 -- Accept_Call (E, Ann);
8530 -- <start of statement sequence for accept statement>
8532 -- (<interface class-wide object>,
8535 -- Ada.Tags.Get_Offset_Index
8537 -- <interface dispatch table index of target entrt>),
8541 -- <rest of statement sequence for accept statement>
8543 -- Complete_Rendezvous;
8546 -- when all others =>
8547 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8549 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8550 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8551 -- statement is replaced by a dispatching call with actual parameters taken
8552 -- from the inner-most accept statement or entry body.
8554 -- Target.Primitive (Param1, ..., ParamN);
8556 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8557 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8560 -- S : constant Offset_Index :=
8561 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8562 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8565 -- if C = POK_Protected_Entry
8566 -- or else C = POK_Task_Entry
8568 -- <statements for dispatching requeue>
8570 -- elsif C = POK_Protected_Procedure then
8571 -- <dispatching call equivalent>
8574 -- raise Program_Error;
8578 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
8579 Loc
: constant Source_Ptr
:= Sloc
(N
);
8580 Conc_Typ
: Entity_Id
;
8584 Old_Typ
: Entity_Id
;
8586 function Build_Dispatching_Call_Equivalent
return Node_Id
;
8587 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8588 -- the form Concval.Ename. It is statically known that Ename is allowed
8589 -- to be implemented by a protected procedure. Create a dispatching call
8590 -- equivalent of Concval.Ename taking the actual parameters from the
8591 -- inner-most accept statement or entry body.
8593 function Build_Dispatching_Requeue
return Node_Id
;
8594 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8595 -- the form Concval.Ename. It is statically known that Ename is allowed
8596 -- to be implemented by a protected or a task entry. Create a call to
8597 -- primitive _Disp_Requeue which handles the low-level actions.
8599 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
8600 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8601 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8602 -- (XXX, By_Any) or not marked at all. Create a block which determines
8603 -- at runtime whether Ename denotes an entry or a procedure and perform
8604 -- the appropriate kind of dispatching select.
8606 function Build_Normal_Requeue
return Node_Id
;
8607 -- N denotes a non-dispatching requeue statement to either a task or a
8608 -- protected entry. Build the appropriate runtime call to perform the
8611 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
8612 -- For a protected entry, create a return statement to skip the rest of
8613 -- the entry body. Otherwise, create a goto statement to skip the rest
8614 -- of a task accept statement. The lookup for the enclosing entry body
8615 -- or accept statement starts from Search.
8617 ---------------------------------------
8618 -- Build_Dispatching_Call_Equivalent --
8619 ---------------------------------------
8621 function Build_Dispatching_Call_Equivalent
return Node_Id
is
8622 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
8623 Obj
: constant Node_Id
:= Original_Node
(Concval
);
8630 -- Climb the parent chain looking for the inner-most entry body or
8631 -- accept statement.
8634 while Present
(Acc_Ent
)
8635 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
8638 Acc_Ent
:= Parent
(Acc_Ent
);
8641 -- A requeue statement should be housed inside an entry body or an
8642 -- accept statement at some level. If this is not the case, then the
8643 -- tree is malformed.
8645 pragma Assert
(Present
(Acc_Ent
));
8647 -- Recover the list of formal parameters
8649 if Nkind
(Acc_Ent
) = N_Entry_Body
then
8650 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
8653 Formals
:= Parameter_Specifications
(Acc_Ent
);
8655 -- Create the actual parameters for the dispatching call. These are
8656 -- simply copies of the entry body or accept statement formals in the
8657 -- same order as they appear.
8661 if Present
(Formals
) then
8662 Actuals
:= New_List
;
8663 Formal
:= First
(Formals
);
8664 while Present
(Formal
) loop
8666 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8672 -- Obj.Call_Ent (Actuals);
8675 Make_Procedure_Call_Statement
(Loc
,
8677 Make_Selected_Component
(Loc
,
8679 Make_Identifier
(Loc
, Chars
(Obj
)),
8681 Make_Identifier
(Loc
, Chars
(Call_Ent
))),
8683 Parameter_Associations
=> Actuals
);
8684 end Build_Dispatching_Call_Equivalent
;
8686 -------------------------------
8687 -- Build_Dispatching_Requeue --
8688 -------------------------------
8690 function Build_Dispatching_Requeue
return Node_Id
is
8691 Params
: constant List_Id
:= New_List
;
8694 -- Process the "with abort" parameter
8697 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
8699 -- Process the entry wrapper's position in the primary dispatch
8700 -- table parameter. Generate:
8702 -- Ada.Tags.Get_Offset_Index
8703 -- (Ada.Tags.Tag (Concval),
8704 -- <interface dispatch table position of Ename>)
8707 Make_Function_Call
(Loc
,
8709 New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
8711 Parameter_Associations
=> New_List
(
8712 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
8713 Make_Integer_Literal
(Loc
, DT_Position
(Entity
(Ename
))))));
8715 -- Specific actuals for protected to XXX requeue
8717 if Is_Protected_Type
(Old_Typ
) then
8719 Make_Attribute_Reference
(Loc
, -- _object'Address
8721 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
8722 Attribute_Name
=> Name_Address
));
8724 Prepend_To
(Params
, -- True
8725 New_Reference_To
(Standard_True
, Loc
));
8727 -- Specific actuals for task to XXX requeue
8730 pragma Assert
(Is_Task_Type
(Old_Typ
));
8732 Prepend_To
(Params
, -- null
8733 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
8735 Prepend_To
(Params
, -- False
8736 New_Reference_To
(Standard_False
, Loc
));
8739 -- Add the object parameter
8741 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
8744 -- _Disp_Requeue (<Params>);
8747 Make_Procedure_Call_Statement
(Loc
,
8749 Make_Identifier
(Loc
, Name_uDisp_Requeue
),
8750 Parameter_Associations
=> Params
);
8751 end Build_Dispatching_Requeue
;
8753 --------------------------------------
8754 -- Build_Dispatching_Requeue_To_Any --
8755 --------------------------------------
8757 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
8758 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
8759 Obj
: constant Node_Id
:= Original_Node
(Concval
);
8760 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
8770 -- Dispatch table slot processing, generate:
8773 S
:= Build_S
(Loc
, Decls
);
8775 -- Call kind processing, generate:
8776 -- C : Ada.Tags.Prim_Op_Kind;
8778 C
:= Build_C
(Loc
, Decls
);
8781 -- S := Ada.Tags.Get_Offset_Index
8782 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8784 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
8787 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8790 Make_Procedure_Call_Statement
(Loc
,
8793 Find_Prim_Op
(Etype
(Etype
(Obj
)),
8794 Name_uDisp_Get_Prim_Op_Kind
),
8796 Parameter_Associations
=> New_List
(
8797 New_Copy_Tree
(Obj
),
8798 New_Reference_To
(S
, Loc
),
8799 New_Reference_To
(C
, Loc
))));
8803 -- if C = POK_Protected_Entry
8804 -- or else C = POK_Task_Entry
8807 Make_If_Statement
(Loc
,
8813 New_Reference_To
(C
, Loc
),
8815 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
8820 New_Reference_To
(C
, Loc
),
8822 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
8824 -- Dispatching requeue equivalent
8826 Then_Statements
=> New_List
(
8827 Build_Dispatching_Requeue
,
8830 -- elsif C = POK_Protected_Procedure then
8832 Elsif_Parts
=> New_List
(
8833 Make_Elsif_Part
(Loc
,
8837 New_Reference_To
(C
, Loc
),
8840 RTE
(RE_POK_Protected_Procedure
), Loc
)),
8842 -- Dispatching call equivalent
8844 Then_Statements
=> New_List
(
8845 Build_Dispatching_Call_Equivalent
))),
8848 -- raise Program_Error;
8851 Else_Statements
=> New_List
(
8852 Make_Raise_Program_Error
(Loc
,
8853 Reason
=> PE_Explicit_Raise
))));
8855 -- Wrap everything into a block
8858 Make_Block_Statement
(Loc
,
8859 Declarations
=> Decls
,
8860 Handled_Statement_Sequence
=>
8861 Make_Handled_Sequence_Of_Statements
(Loc
,
8862 Statements
=> Stmts
));
8863 end Build_Dispatching_Requeue_To_Any
;
8865 --------------------------
8866 -- Build_Normal_Requeue --
8867 --------------------------
8869 function Build_Normal_Requeue
return Node_Id
is
8870 Params
: constant List_Id
:= New_List
;
8875 -- Process the "with abort" parameter
8878 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
8880 -- Add the index expression to the parameters. It is common among all
8884 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
8886 if Is_Protected_Type
(Old_Typ
) then
8888 Self_Param
: Node_Id
;
8892 Make_Attribute_Reference
(Loc
,
8894 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
8896 Name_Unchecked_Access
);
8898 -- Protected to protected requeue
8900 if Is_Protected_Type
(Conc_Typ
) then
8903 RTE
(RE_Requeue_Protected_Entry
), Loc
);
8906 Make_Attribute_Reference
(Loc
,
8908 Concurrent_Ref
(Concval
),
8910 Name_Unchecked_Access
);
8912 -- Protected to task requeue
8914 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
8917 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
8919 Param
:= Concurrent_Ref
(Concval
);
8922 Prepend_To
(Params
, Param
);
8923 Prepend_To
(Params
, Self_Param
);
8926 else pragma Assert
(Is_Task_Type
(Old_Typ
));
8928 -- Task to protected requeue
8930 if Is_Protected_Type
(Conc_Typ
) then
8933 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
8936 Make_Attribute_Reference
(Loc
,
8938 Concurrent_Ref
(Concval
),
8940 Name_Unchecked_Access
);
8942 -- Task to task requeue
8944 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
8946 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
);
8948 Param
:= Concurrent_Ref
(Concval
);
8951 Prepend_To
(Params
, Param
);
8955 Make_Procedure_Call_Statement
(Loc
,
8957 Parameter_Associations
=> Params
);
8958 end Build_Normal_Requeue
;
8960 --------------------------
8961 -- Build_Skip_Statement --
8962 --------------------------
8964 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
8965 Skip_Stmt
: Node_Id
;
8968 -- Build a return statement to skip the rest of the entire body
8970 if Is_Protected_Type
(Old_Typ
) then
8971 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
8973 -- If the requeue is within a task, find the end label of the
8974 -- enclosing accept statement and create a goto statement to it.
8982 -- Climb the parent chain looking for the enclosing accept
8985 Acc
:= Parent
(Search
);
8987 and then Nkind
(Acc
) /= N_Accept_Statement
8989 Acc
:= Parent
(Acc
);
8992 -- The last statement is the second label used for completing
8993 -- the rendezvous the usual way. The label we are looking for
8994 -- is right before it.
8997 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
8999 pragma Assert
(Nkind
(Label
) = N_Label
);
9001 -- Generate a goto statement to skip the rest of the accept
9004 Make_Goto_Statement
(Loc
,
9006 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
9010 Set_Analyzed
(Skip_Stmt
);
9013 end Build_Skip_Statement
;
9015 -- Start of processing for Expand_N_Requeue_Statement
9018 -- Extract the components of the entry call
9020 Extract_Entry
(N
, Concval
, Ename
, Index
);
9021 Conc_Typ
:= Etype
(Concval
);
9023 -- Examine the scope stack in order to find nearest enclosing protected
9024 -- or task type. This will constitute our invocation source.
9026 Old_Typ
:= Current_Scope
;
9027 while Present
(Old_Typ
)
9028 and then not Is_Protected_Type
(Old_Typ
)
9029 and then not Is_Task_Type
(Old_Typ
)
9031 Old_Typ
:= Scope
(Old_Typ
);
9034 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9035 -- Concval.Ename where the type of Concval is class-wide concurrent
9038 if Ada_Version
>= Ada_2012
9039 and then Present
(Concval
)
9040 and then Is_Class_Wide_Type
(Conc_Typ
)
9041 and then Is_Concurrent_Interface
(Conc_Typ
)
9044 Has_Impl
: Boolean := False;
9045 Impl_Kind
: Name_Id
:= No_Name
;
9048 -- Check whether the Ename is flagged by pragma Implemented
9050 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
9052 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
9055 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9056 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9059 and then Impl_Kind
= Name_By_Entry
9061 Rewrite
(N
, Build_Dispatching_Requeue
);
9063 Insert_After
(N
, Build_Skip_Statement
(N
));
9065 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9066 -- a protected procedure. In this case the requeue is transformed
9067 -- into a dispatching call.
9070 and then Impl_Kind
= Name_By_Protected_Procedure
9072 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
9075 -- The procedure_or_entry_NAME's implementation kind is either
9076 -- By_Any or pragma Implemented was not applied at all. In this
9077 -- case a runtime test determines whether Ename denotes an entry
9078 -- or a protected procedure and performs the appropriate call.
9081 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
9086 -- Processing for regular (non-dispatching) requeues
9089 Rewrite
(N
, Build_Normal_Requeue
);
9091 Insert_After
(N
, Build_Skip_Statement
(N
));
9093 end Expand_N_Requeue_Statement
;
9095 -------------------------------
9096 -- Expand_N_Selective_Accept --
9097 -------------------------------
9099 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
9100 Loc
: constant Source_Ptr
:= Sloc
(N
);
9101 Alts
: constant List_Id
:= Select_Alternatives
(N
);
9103 -- Note: in the below declarations a lot of new lists are allocated
9104 -- unconditionally which may well not end up being used. That's
9105 -- not a good idea since it wastes space gratuitously ???
9107 Accept_Case
: List_Id
;
9108 Accept_List
: constant List_Id
:= New_List
;
9111 Alt_List
: constant List_Id
:= New_List
;
9112 Alt_Stats
: List_Id
;
9113 Ann
: Entity_Id
:= Empty
;
9116 Check_Guard
: Boolean := True;
9118 Decls
: constant List_Id
:= New_List
;
9119 Stats
: constant List_Id
:= New_List
;
9120 Body_List
: constant List_Id
:= New_List
;
9121 Trailing_List
: constant List_Id
:= New_List
;
9124 Else_Present
: Boolean := False;
9125 Terminate_Alt
: Node_Id
:= Empty
;
9126 Select_Mode
: Node_Id
;
9128 Delay_Case
: List_Id
;
9129 Delay_Count
: Integer := 0;
9130 Delay_Val
: Entity_Id
;
9131 Delay_Index
: Entity_Id
;
9132 Delay_Min
: Entity_Id
;
9133 Delay_Num
: Int
:= 1;
9134 Delay_Alt_List
: List_Id
:= New_List
;
9135 Delay_List
: constant List_Id
:= New_List
;
9139 First_Delay
: Boolean := True;
9140 Guard_Open
: Entity_Id
;
9146 Num_Accept
: Nat
:= 0;
9149 Time_Type
: Entity_Id
;
9151 Select_Call
: Node_Id
;
9153 Qnam
: constant Entity_Id
:=
9154 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
9156 Xnam
: constant Entity_Id
:=
9157 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
9159 -----------------------
9160 -- Local subprograms --
9161 -----------------------
9163 function Accept_Or_Raise
return List_Id
;
9164 -- For the rare case where delay alternatives all have guards, and
9165 -- all of them are closed, it is still possible that there were open
9166 -- accept alternatives with no callers. We must reexamine the
9167 -- Accept_List, and execute a selective wait with no else if some
9168 -- accept is open. If none, we raise program_error.
9170 procedure Add_Accept
(Alt
: Node_Id
);
9171 -- Process a single accept statement in a select alternative. Build
9172 -- procedure for body of accept, and add entry to dispatch table with
9173 -- expression for guard, in preparation for call to run time select.
9175 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
9176 -- Manufacture a label using Num as a serial number and declare it.
9177 -- The declaration is appended to Decls. The label marks the trailing
9178 -- statements of an accept or delay alternative.
9180 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
9181 -- Build call to Selective_Wait runtime routine
9183 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
9184 -- Add code to compare value of delay with previous values, and
9185 -- generate case entry for trailing statements.
9187 procedure Process_Accept_Alternative
9191 -- Add code to call corresponding procedure, and branch to
9192 -- trailing statements, if any.
9194 ---------------------
9195 -- Accept_Or_Raise --
9196 ---------------------
9198 function Accept_Or_Raise
return List_Id
is
9201 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
9204 -- We generate the following:
9206 -- for J in q'range loop
9207 -- if q(J).S /=null_task_entry then
9208 -- selective_wait (simple_mode,...);
9214 -- if no rendez_vous then
9215 -- raise program_error;
9218 -- Note that the code needs to know that the selector name
9219 -- in an Accept_Alternative is named S.
9221 Cond
:= Make_Op_Ne
(Loc
,
9223 Make_Selected_Component
(Loc
,
9224 Prefix
=> Make_Indexed_Component
(Loc
,
9225 Prefix
=> New_Reference_To
(Qnam
, Loc
),
9226 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
9227 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
9229 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
9232 Make_Implicit_Loop_Statement
(N
,
9233 Identifier
=> Empty
,
9235 Make_Iteration_Scheme
(Loc
,
9236 Loop_Parameter_Specification
=>
9237 Make_Loop_Parameter_Specification
(Loc
,
9238 Defining_Identifier
=> J
,
9239 Discrete_Subtype_Definition
=>
9240 Make_Attribute_Reference
(Loc
,
9241 Prefix
=> New_Reference_To
(Qnam
, Loc
),
9242 Attribute_Name
=> Name_Range
,
9243 Expressions
=> New_List
(
9244 Make_Integer_Literal
(Loc
, 1))))),
9246 Statements
=> New_List
(
9247 Make_Implicit_If_Statement
(N
,
9249 Then_Statements
=> New_List
(
9251 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
9252 Make_Exit_Statement
(Loc
))))));
9255 Make_Raise_Program_Error
(Loc
,
9256 Condition
=> Make_Op_Eq
(Loc
,
9257 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
9259 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
9260 Reason
=> PE_All_Guards_Closed
));
9263 end Accept_Or_Raise
;
9269 procedure Add_Accept
(Alt
: Node_Id
) is
9270 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
9271 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
9272 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
9273 Eent
: constant Entity_Id
:= Entity
(Ename
);
9274 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
9275 Null_Body
: Node_Id
;
9276 Proc_Body
: Node_Id
;
9283 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
9286 if Present
(Condition
(Alt
)) then
9288 Make_Conditional_Expression
(Eloc
, New_List
(
9290 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
9291 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Eloc
)));
9294 Entry_Index_Expression
9295 (Eloc
, Eent
, Index
, Scope
(Eent
));
9298 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
9299 Null_Body
:= New_Reference_To
(Standard_False
, Eloc
);
9301 if Abort_Allowed
then
9302 Call
:= Make_Procedure_Call_Statement
(Eloc
,
9303 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Eloc
));
9304 Insert_Before
(First
(Statements
(Handled_Statement_Sequence
(
9305 Accept_Statement
(Alt
)))), Call
);
9310 Make_Defining_Identifier
(Eloc
,
9311 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
9313 if Comes_From_Source
(Alt
) then
9314 Set_Debug_Info_Needed
(PB_Ent
);
9318 Make_Subprogram_Body
(Eloc
,
9320 Make_Procedure_Specification
(Eloc
,
9321 Defining_Unit_Name
=> PB_Ent
),
9322 Declarations
=> Declarations
(Acc_Stm
),
9323 Handled_Statement_Sequence
=>
9324 Build_Accept_Body
(Accept_Statement
(Alt
)));
9326 -- During the analysis of the body of the accept statement, any
9327 -- zero cost exception handler records were collected in the
9328 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9329 -- This is where we move them to where they belong, namely the
9330 -- newly created procedure.
9332 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
9333 Append
(Proc_Body
, Body_List
);
9336 Null_Body
:= New_Reference_To
(Standard_True
, Eloc
);
9338 -- if accept statement has declarations, insert above, given that
9339 -- we are not creating a body for the accept.
9341 if Present
(Declarations
(Acc_Stm
)) then
9342 Insert_Actions
(N
, Declarations
(Acc_Stm
));
9346 Append_To
(Accept_List
,
9347 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
9349 Num_Accept
:= Num_Accept
+ 1;
9352 ----------------------------
9353 -- Make_And_Declare_Label --
9354 ----------------------------
9356 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
9360 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
9362 Make_Label
(Loc
, Lab_Id
);
9365 Make_Implicit_Label_Declaration
(Loc
,
9366 Defining_Identifier
=>
9367 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
9368 Label_Construct
=> Lab
));
9371 end Make_And_Declare_Label
;
9373 ----------------------
9374 -- Make_Select_Call --
9375 ----------------------
9377 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
9378 Params
: constant List_Id
:= New_List
;
9382 Make_Attribute_Reference
(Loc
,
9383 Prefix
=> New_Reference_To
(Qnam
, Loc
),
9384 Attribute_Name
=> Name_Unchecked_Access
),
9386 Append
(Select_Mode
, Params
);
9387 Append
(New_Reference_To
(Ann
, Loc
), Params
);
9388 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
9391 Make_Procedure_Call_Statement
(Loc
,
9392 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
9393 Parameter_Associations
=> Params
);
9394 end Make_Select_Call
;
9396 --------------------------------
9397 -- Process_Accept_Alternative --
9398 --------------------------------
9400 procedure Process_Accept_Alternative
9405 Choices
: List_Id
:= No_List
;
9406 Alt_Stats
: List_Id
;
9409 Adjust_Condition
(Condition
(Alt
));
9410 Alt_Stats
:= No_List
;
9412 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
9413 Choices
:= New_List
(
9414 Make_Integer_Literal
(Loc
, Index
));
9416 Alt_Stats
:= New_List
(
9417 Make_Procedure_Call_Statement
(Sloc
(Proc
),
9418 Name
=> New_Reference_To
(
9419 Defining_Unit_Name
(Specification
(Proc
)), Sloc
(Proc
))));
9422 if Statements
(Alt
) /= Empty_List
then
9424 if No
(Alt_Stats
) then
9426 -- Accept with no body, followed by trailing statements
9428 Choices
:= New_List
(
9429 Make_Integer_Literal
(Loc
, Index
));
9431 Alt_Stats
:= New_List
;
9434 -- After the call, if any, branch to trailing statements. We
9435 -- create a label for each, as well as the corresponding label
9438 Lab
:= Make_And_Declare_Label
(Index
);
9439 Append_To
(Alt_Stats
,
9440 Make_Goto_Statement
(Loc
,
9441 Name
=> New_Copy
(Identifier
(Lab
))));
9443 Append
(Lab
, Trailing_List
);
9444 Append_List
(Statements
(Alt
), Trailing_List
);
9445 Append_To
(Trailing_List
,
9446 Make_Goto_Statement
(Loc
,
9447 Name
=> New_Copy
(Identifier
(End_Lab
))));
9450 if Present
(Alt_Stats
) then
9452 -- Procedure call. and/or trailing statements
9454 Append_To
(Alt_List
,
9455 Make_Case_Statement_Alternative
(Loc
,
9456 Discrete_Choices
=> Choices
,
9457 Statements
=> Alt_Stats
));
9459 end Process_Accept_Alternative
;
9461 -------------------------------
9462 -- Process_Delay_Alternative --
9463 -------------------------------
9465 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
9468 Delay_Alt
: List_Id
;
9471 -- Deal with C/Fortran boolean as delay condition
9473 Adjust_Condition
(Condition
(Alt
));
9475 -- Determine the smallest specified delay
9477 -- for each delay alternative generate:
9479 -- if guard-expression then
9480 -- Delay_Val := delay-expression;
9481 -- Guard_Open := True;
9482 -- if Delay_Val < Delay_Min then
9483 -- Delay_Min := Delay_Val;
9484 -- Delay_Index := Index;
9488 -- The enclosing if-statement is omitted if there is no guard
9493 First_Delay
:= False;
9495 Delay_Alt
:= New_List
(
9496 Make_Assignment_Statement
(Loc
,
9497 Name
=> New_Reference_To
(Delay_Min
, Loc
),
9498 Expression
=> Expression
(Delay_Statement
(Alt
))));
9500 if Delay_Count
> 1 then
9501 Append_To
(Delay_Alt
,
9502 Make_Assignment_Statement
(Loc
,
9503 Name
=> New_Reference_To
(Delay_Index
, Loc
),
9504 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
9508 Delay_Alt
:= New_List
(
9509 Make_Assignment_Statement
(Loc
,
9510 Name
=> New_Reference_To
(Delay_Val
, Loc
),
9511 Expression
=> Expression
(Delay_Statement
(Alt
))));
9513 if Time_Type
= Standard_Duration
then
9516 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
9517 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
9520 -- The scope of the time type must define a comparison
9521 -- operator. The scope itself may not be visible, so we
9522 -- construct a node with entity information to insure that
9523 -- semantic analysis can find the proper operator.
9526 Make_Function_Call
(Loc
,
9527 Name
=> Make_Selected_Component
(Loc
,
9528 Prefix
=> New_Reference_To
(Scope
(Time_Type
), Loc
),
9530 Make_Operator_Symbol
(Loc
,
9531 Chars
=> Name_Op_Lt
,
9532 Strval
=> No_String
)),
9533 Parameter_Associations
=>
9535 New_Reference_To
(Delay_Val
, Loc
),
9536 New_Reference_To
(Delay_Min
, Loc
)));
9538 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
9541 Append_To
(Delay_Alt
,
9542 Make_Implicit_If_Statement
(N
,
9544 Then_Statements
=> New_List
(
9545 Make_Assignment_Statement
(Loc
,
9546 Name
=> New_Reference_To
(Delay_Min
, Loc
),
9547 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
9549 Make_Assignment_Statement
(Loc
,
9550 Name
=> New_Reference_To
(Delay_Index
, Loc
),
9551 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
9555 Append_To
(Delay_Alt
,
9556 Make_Assignment_Statement
(Loc
,
9557 Name
=> New_Reference_To
(Guard_Open
, Loc
),
9558 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
9561 if Present
(Condition
(Alt
)) then
9562 Delay_Alt
:= New_List
(
9563 Make_Implicit_If_Statement
(N
,
9564 Condition
=> Condition
(Alt
),
9565 Then_Statements
=> Delay_Alt
));
9568 Append_List
(Delay_Alt
, Delay_List
);
9570 -- If the delay alternative has a statement part, add choice to the
9571 -- case statements for delays.
9573 if Present
(Statements
(Alt
)) then
9575 if Delay_Count
= 1 then
9576 Append_List
(Statements
(Alt
), Delay_Alt_List
);
9579 Choices
:= New_List
(
9580 Make_Integer_Literal
(Loc
, Index
));
9582 Append_To
(Delay_Alt_List
,
9583 Make_Case_Statement_Alternative
(Loc
,
9584 Discrete_Choices
=> Choices
,
9585 Statements
=> Statements
(Alt
)));
9588 elsif Delay_Count
= 1 then
9590 -- If the single delay has no trailing statements, add a branch
9591 -- to the exit label to the selective wait.
9593 Delay_Alt_List
:= New_List
(
9594 Make_Goto_Statement
(Loc
,
9595 Name
=> New_Copy
(Identifier
(End_Lab
))));
9598 end Process_Delay_Alternative
;
9600 -- Start of processing for Expand_N_Selective_Accept
9603 -- First insert some declarations before the select. The first is:
9607 -- This variable holds the parameters passed to the accept body. This
9608 -- declaration has already been inserted by the time we get here by
9609 -- a call to Expand_Accept_Declarations made from the semantics when
9610 -- processing the first accept statement contained in the select. We
9611 -- can find this entity as Accept_Address (E), where E is any of the
9612 -- entries references by contained accept statements.
9614 -- The first step is to scan the list of Selective_Accept_Statements
9615 -- to find this entity, and also count the number of accepts, and
9616 -- determine if terminated, delay or else is present:
9620 Alt
:= First
(Alts
);
9621 while Present
(Alt
) loop
9623 if Nkind
(Alt
) = N_Accept_Alternative
then
9626 elsif Nkind
(Alt
) = N_Delay_Alternative
then
9627 Delay_Count
:= Delay_Count
+ 1;
9629 -- If the delays are relative delays, the delay expressions have
9630 -- type Standard_Duration. Otherwise they must have some time type
9631 -- recognized by GNAT.
9633 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
9634 Time_Type
:= Standard_Duration
;
9636 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
9638 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
9639 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
9644 "& is not a time type (RM 9.6(6))",
9645 Expression
(Delay_Statement
(Alt
)), Time_Type
);
9646 Time_Type
:= Standard_Duration
;
9647 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
9651 if No
(Condition
(Alt
)) then
9653 -- This guard will always be open
9655 Check_Guard
:= False;
9658 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
9659 Adjust_Condition
(Condition
(Alt
));
9660 Terminate_Alt
:= Alt
;
9663 Num_Alts
:= Num_Alts
+ 1;
9667 Else_Present
:= Present
(Else_Statements
(N
));
9669 -- At the same time (see procedure Add_Accept) we build the accept list:
9671 -- Qnn : Accept_List (1 .. num-select) := (
9672 -- (null-body, entry-index),
9673 -- (null-body, entry-index),
9675 -- (null_body, entry-index));
9677 -- In the above declaration, null-body is True if the corresponding
9678 -- accept has no body, and false otherwise. The entry is either the
9679 -- entry index expression if there is no guard, or if a guard is
9680 -- present, then a conditional expression of the form:
9682 -- (if guard then entry-index else Null_Task_Entry)
9684 -- If a guard is statically known to be false, the entry can simply
9685 -- be omitted from the accept list.
9688 Make_Object_Declaration
(Loc
,
9689 Defining_Identifier
=> Qnam
,
9690 Object_Definition
=>
9691 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
9692 Aliased_Present
=> True,
9695 Make_Qualified_Expression
(Loc
,
9697 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
9699 Make_Aggregate
(Loc
, Expressions
=> Accept_List
)));
9703 -- Then we declare the variable that holds the index for the accept
9704 -- that will be selected for service:
9706 -- Xnn : Select_Index;
9709 Make_Object_Declaration
(Loc
,
9710 Defining_Identifier
=> Xnam
,
9711 Object_Definition
=>
9712 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
9714 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
9718 -- After this follow procedure declarations for each accept body
9725 -- where the ... are statements from the corresponding procedure body.
9726 -- No parameters are involved, since the parameters are passed via Ann
9727 -- and the parameter references have already been expanded to be direct
9728 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9729 -- any embedded tasking statements (which would normally be illegal in
9730 -- procedures), have been converted to calls to the tasking runtime so
9731 -- there is no problem in putting them into procedures.
9733 -- The original accept statement has been expanded into a block in
9734 -- the same fashion as for simple accepts (see Build_Accept_Body).
9736 -- Note: we don't really need to build these procedures for the case
9737 -- where no delay statement is present, but it is just as easy to
9738 -- build them unconditionally, and not significantly inefficient,
9739 -- since if they are short they will be inlined anyway.
9741 -- The procedure declarations have been assembled in Body_List
9743 -- If delays are present, we must compute the required delay.
9744 -- We first generate the declarations:
9746 -- Delay_Index : Boolean := 0;
9747 -- Delay_Min : Some_Time_Type.Time;
9748 -- Delay_Val : Some_Time_Type.Time;
9750 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9751 -- active delay that is actually chosen as the basis for the possible
9752 -- delay if an immediate rendez-vous is not possible.
9754 -- In the most common case there is a single delay statement, and this
9755 -- is handled specially.
9757 if Delay_Count
> 0 then
9759 -- Generate the required declarations
9762 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
9764 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
9766 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
9769 Make_Object_Declaration
(Loc
,
9770 Defining_Identifier
=> Delay_Val
,
9771 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
9774 Make_Object_Declaration
(Loc
,
9775 Defining_Identifier
=> Delay_Index
,
9776 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
9777 Expression
=> Make_Integer_Literal
(Loc
, 0)));
9780 Make_Object_Declaration
(Loc
,
9781 Defining_Identifier
=> Delay_Min
,
9782 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
9784 Unchecked_Convert_To
(Time_Type
,
9785 Make_Attribute_Reference
(Loc
,
9787 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
9788 Attribute_Name
=> Name_Last
))));
9790 -- Create Duration and Delay_Mode objects used for passing a delay
9793 D
:= Make_Temporary
(Loc
, 'D');
9794 M
:= Make_Temporary
(Loc
, 'M');
9800 -- Note that these values are defined in s-osprim.ads and must
9803 -- Relative : constant := 0;
9804 -- Absolute_Calendar : constant := 1;
9805 -- Absolute_RT : constant := 2;
9807 if Time_Type
= Standard_Duration
then
9808 Discr
:= Make_Integer_Literal
(Loc
, 0);
9810 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
9811 Discr
:= Make_Integer_Literal
(Loc
, 1);
9815 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
9816 Discr
:= Make_Integer_Literal
(Loc
, 2);
9820 Make_Object_Declaration
(Loc
,
9821 Defining_Identifier
=> D
,
9822 Object_Definition
=>
9823 New_Reference_To
(Standard_Duration
, Loc
)));
9826 Make_Object_Declaration
(Loc
,
9827 Defining_Identifier
=> M
,
9828 Object_Definition
=>
9829 New_Reference_To
(Standard_Integer
, Loc
),
9830 Expression
=> Discr
));
9835 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
9838 Make_Object_Declaration
(Loc
,
9839 Defining_Identifier
=> Guard_Open
,
9840 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
9841 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
9844 -- Delay_Count is zero, don't need M and D set (suppress warning)
9851 if Present
(Terminate_Alt
) then
9853 -- If the terminate alternative guard is False, use
9854 -- Simple_Mode; otherwise use Terminate_Mode.
9856 if Present
(Condition
(Terminate_Alt
)) then
9857 Select_Mode
:= Make_Conditional_Expression
(Loc
,
9858 New_List
(Condition
(Terminate_Alt
),
9859 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
9860 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
9862 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
9865 elsif Else_Present
or Delay_Count
> 0 then
9866 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
9869 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
9872 Select_Call
:= Make_Select_Call
(Select_Mode
);
9873 Append
(Select_Call
, Stats
);
9875 -- Now generate code to act on the result. There is an entry
9876 -- in this case for each accept statement with a non-null body,
9877 -- followed by a branch to the statements that follow the Accept.
9878 -- In the absence of delay alternatives, we generate:
9881 -- when No_Rendezvous => -- omitted if simple mode
9896 -- Lab0: Else_Statements;
9899 -- Lab1: Trailing_Statements1;
9902 -- Lab2: Trailing_Statements2;
9907 -- Generate label for common exit
9909 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
9911 -- First entry is the default case, when no rendezvous is possible
9913 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
9915 if Else_Present
then
9917 -- If no rendezvous is possible, the else part is executed
9919 Lab
:= Make_And_Declare_Label
(0);
9920 Alt_Stats
:= New_List
(
9921 Make_Goto_Statement
(Loc
,
9922 Name
=> New_Copy
(Identifier
(Lab
))));
9924 Append
(Lab
, Trailing_List
);
9925 Append_List
(Else_Statements
(N
), Trailing_List
);
9926 Append_To
(Trailing_List
,
9927 Make_Goto_Statement
(Loc
,
9928 Name
=> New_Copy
(Identifier
(End_Lab
))));
9930 Alt_Stats
:= New_List
(
9931 Make_Goto_Statement
(Loc
,
9932 Name
=> New_Copy
(Identifier
(End_Lab
))));
9935 Append_To
(Alt_List
,
9936 Make_Case_Statement_Alternative
(Loc
,
9937 Discrete_Choices
=> Choices
,
9938 Statements
=> Alt_Stats
));
9940 -- We make use of the fact that Accept_Index is an integer type, and
9941 -- generate successive literals for entries for each accept. Only those
9942 -- for which there is a body or trailing statements get a case entry.
9944 Alt
:= First
(Select_Alternatives
(N
));
9945 Proc
:= First
(Body_List
);
9946 while Present
(Alt
) loop
9948 if Nkind
(Alt
) = N_Accept_Alternative
then
9949 Process_Accept_Alternative
(Alt
, Index
, Proc
);
9953 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
9958 elsif Nkind
(Alt
) = N_Delay_Alternative
then
9959 Process_Delay_Alternative
(Alt
, Delay_Num
);
9960 Delay_Num
:= Delay_Num
+ 1;
9966 -- An others choice is always added to the main case, as well
9967 -- as the delay case (to satisfy the compiler).
9969 Append_To
(Alt_List
,
9970 Make_Case_Statement_Alternative
(Loc
,
9972 New_List
(Make_Others_Choice
(Loc
)),
9974 New_List
(Make_Goto_Statement
(Loc
,
9975 Name
=> New_Copy
(Identifier
(End_Lab
))))));
9977 Accept_Case
:= New_List
(
9978 Make_Case_Statement
(Loc
,
9979 Expression
=> New_Reference_To
(Xnam
, Loc
),
9980 Alternatives
=> Alt_List
));
9982 Append_List
(Trailing_List
, Accept_Case
);
9983 Append
(End_Lab
, Accept_Case
);
9984 Append_List
(Body_List
, Decls
);
9986 -- Construct case statement for trailing statements of delay
9987 -- alternatives, if there are several of them.
9989 if Delay_Count
> 1 then
9990 Append_To
(Delay_Alt_List
,
9991 Make_Case_Statement_Alternative
(Loc
,
9993 New_List
(Make_Others_Choice
(Loc
)),
9995 New_List
(Make_Null_Statement
(Loc
))));
9997 Delay_Case
:= New_List
(
9998 Make_Case_Statement
(Loc
,
9999 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
10000 Alternatives
=> Delay_Alt_List
));
10002 Delay_Case
:= Delay_Alt_List
;
10005 -- If there are no delay alternatives, we append the case statement
10006 -- to the statement list.
10008 if Delay_Count
= 0 then
10009 Append_List
(Accept_Case
, Stats
);
10011 -- Delay alternatives present
10014 -- If delay alternatives are present we generate:
10016 -- find minimum delay.
10017 -- DX := minimum delay;
10018 -- M := <delay mode>;
10019 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10022 -- if X = No_Rendezvous then
10023 -- case statement for delay statements.
10025 -- case statement for accept alternatives.
10036 -- The type of the delay expression is known to be legal
10038 if Time_Type
= Standard_Duration
then
10039 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
10041 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10042 Conv
:= Make_Function_Call
(Loc
,
10043 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
10044 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
10048 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
10050 Conv
:= Make_Function_Call
(Loc
,
10051 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
10052 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
10055 Stmt
:= Make_Assignment_Statement
(Loc
,
10056 Name
=> New_Reference_To
(D
, Loc
),
10057 Expression
=> Conv
);
10059 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10061 Parms
:= Parameter_Associations
(Select_Call
);
10062 Parm
:= First
(Parms
);
10064 while Present
(Parm
)
10065 and then Parm
/= Select_Mode
10070 pragma Assert
(Present
(Parm
));
10071 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
10074 -- Prepare two new parameters of Duration and Delay_Mode type
10075 -- which represent the value and the mode of the minimum delay.
10078 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
10079 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
10081 -- Create a call to RTS
10083 Rewrite
(Select_Call
,
10084 Make_Procedure_Call_Statement
(Loc
,
10085 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
10086 Parameter_Associations
=> Parms
));
10088 -- This new call should follow the calculation of the minimum
10091 Insert_List_Before
(Select_Call
, Delay_List
);
10093 if Check_Guard
then
10095 Make_Implicit_If_Statement
(N
,
10096 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
10098 New_List
(New_Copy_Tree
(Stmt
),
10099 New_Copy_Tree
(Select_Call
)),
10100 Else_Statements
=> Accept_Or_Raise
);
10101 Rewrite
(Select_Call
, Stmt
);
10103 Insert_Before
(Select_Call
, Stmt
);
10107 Make_Implicit_If_Statement
(N
,
10108 Condition
=> Make_Op_Eq
(Loc
,
10109 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
10111 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
10113 Then_Statements
=> Delay_Case
,
10114 Else_Statements
=> Accept_Case
);
10116 Append
(Cases
, Stats
);
10120 -- Replace accept statement with appropriate block
10123 Make_Block_Statement
(Loc
,
10124 Declarations
=> Decls
,
10125 Handled_Statement_Sequence
=>
10126 Make_Handled_Sequence_Of_Statements
(Loc
,
10127 Statements
=> Stats
));
10129 Rewrite
(N
, Block
);
10132 -- Note: have to worry more about abort deferral in above code ???
10134 -- Final step is to unstack the Accept_Address entries for all accept
10135 -- statements appearing in accept alternatives in the select statement
10137 Alt
:= First
(Alts
);
10138 while Present
(Alt
) loop
10139 if Nkind
(Alt
) = N_Accept_Alternative
then
10140 Remove_Last_Elmt
(Accept_Address
10141 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
10146 end Expand_N_Selective_Accept
;
10148 --------------------------------------
10149 -- Expand_N_Single_Task_Declaration --
10150 --------------------------------------
10152 -- Single task declarations should never be present after semantic
10153 -- analysis, since we expect them to be replaced by a declaration of an
10154 -- anonymous task type, followed by a declaration of the task object. We
10155 -- include this routine to make sure that is happening!
10157 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
10159 raise Program_Error
;
10160 end Expand_N_Single_Task_Declaration
;
10162 ------------------------
10163 -- Expand_N_Task_Body --
10164 ------------------------
10166 -- Given a task body
10168 -- task body tname is
10174 -- This expansion routine converts it into a procedure and sets the
10175 -- elaboration flag for the procedure to true, to represent the fact
10176 -- that the task body is now elaborated:
10178 -- procedure tnameB (_Task : access tnameV) is
10179 -- discriminal : dtype renames _Task.discriminant;
10181 -- procedure _clean is
10183 -- Abort_Defer.all;
10185 -- Abort_Undefer.all;
10190 -- Abort_Undefer.all;
10192 -- System.Task_Stages.Complete_Activation;
10200 -- In addition, if the task body is an activator, then a call to activate
10201 -- tasks is added at the start of the statements, before the call to
10202 -- Complete_Activation, and if in addition the task is a master then it
10203 -- must be established as a master. These calls are inserted and analyzed
10204 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10207 -- There is one discriminal declaration line generated for each
10208 -- discriminant that is present to provide an easy reference point for
10209 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10211 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10212 -- task body procedures have a profile (Arg : System.Address). That is
10213 -- needed because GNARLI has to use the same access-to-subprogram type
10214 -- for all task types. We depend here on knowing that in GNAT, passing
10215 -- an address argument by value is identical to passing a record value
10216 -- by access (in either case a single pointer is passed), so even though
10217 -- this procedure has the wrong profile. In fact it's all OK, since the
10218 -- callings sequence is identical.
10220 procedure Expand_N_Task_Body
(N
: Node_Id
) is
10221 Loc
: constant Source_Ptr
:= Sloc
(N
);
10222 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
10226 Insert_Nod
: Node_Id
;
10227 -- Used to determine the proper location of wrapper body insertions
10230 -- Add renaming declarations for discriminals and a declaration for the
10231 -- entry family index (if applicable).
10233 Install_Private_Data_Declarations
10234 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
10236 -- Add a call to Abort_Undefer at the very beginning of the task
10237 -- body since this body is called with abort still deferred.
10239 if Abort_Allowed
then
10240 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10242 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
10246 -- The statement part has already been protected with an at_end and
10247 -- cleanup actions. The call to Complete_Activation must be placed
10248 -- at the head of the sequence of statements of that block. The
10249 -- declarations have been merged in this sequence of statements but
10250 -- the first real statement is accessible from the First_Real_Statement
10251 -- field (which was set for exactly this purpose).
10253 if Restricted_Profile
then
10254 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
10256 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
10260 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
10264 Make_Subprogram_Body
(Loc
,
10265 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
10266 Declarations
=> Declarations
(N
),
10267 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
10269 -- If the task contains generic instantiations, cleanup actions are
10270 -- delayed until after instantiation. Transfer the activation chain to
10271 -- the subprogram, to insure that the activation call is properly
10272 -- generated. It the task body contains inner tasks, indicate that the
10273 -- subprogram is a task master.
10275 if Delay_Cleanups
(Ttyp
) then
10276 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
10277 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
10280 Rewrite
(N
, New_N
);
10283 -- Set elaboration flag immediately after task body. If the body is a
10284 -- subunit, the flag is set in the declarative part containing the stub.
10286 if Nkind
(Parent
(N
)) /= N_Subunit
then
10288 Make_Assignment_Statement
(Loc
,
10290 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
10291 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
10294 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10295 -- the task body. At this point all wrapper specs have been created,
10296 -- frozen and included in the dispatch table for the task type.
10298 if Ada_Version
>= Ada_2005
then
10299 if Nkind
(Parent
(N
)) = N_Subunit
then
10300 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
10305 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
10307 end Expand_N_Task_Body
;
10309 ------------------------------------
10310 -- Expand_N_Task_Type_Declaration --
10311 ------------------------------------
10313 -- We have several things to do. First we must create a Boolean flag used
10314 -- to mark if the body is elaborated yet. This variable gets set to True
10315 -- when the body of the task is elaborated (we can't rely on the normal
10316 -- ABE mechanism for the task body, since we need to pass an access to
10317 -- this elaboration boolean to the runtime routines).
10319 -- taskE : aliased Boolean := False;
10321 -- Next a variable is declared to hold the task stack size (either the
10322 -- default : Unspecified_Size, or a value that is set by a pragma
10323 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10324 -- the variable is initialized with this value:
10326 -- taskZ : Size_Type := Unspecified_Size;
10328 -- taskZ : Size_Type := Size_Type (size_expression);
10330 -- Note: No variable is needed to hold the task relative deadline since
10331 -- its value would never be static because the parameter is of a private
10332 -- type (Ada.Real_Time.Time_Span).
10334 -- Next we create a corresponding record type declaration used to represent
10335 -- values of this task. The general form of this type declaration is
10337 -- type taskV (discriminants) is record
10338 -- _Task_Id : Task_Id;
10339 -- entry_family : array (bounds) of Void;
10340 -- _Priority : Integer := priority_expression;
10341 -- _Size : Size_Type := Size_Type (size_expression);
10342 -- _Task_Info : Task_Info_Type := task_info_expression;
10343 -- _CPU : Integer := cpu_range_expression;
10346 -- The discriminants are present only if the corresponding task type has
10347 -- discriminants, and they exactly mirror the task type discriminants.
10349 -- The Id field is always present. It contains the Task_Id value, as set by
10350 -- the call to Create_Task. Note that although the task is limited, the
10351 -- task value record type is not limited, so there is no problem in passing
10352 -- this field as an out parameter to Create_Task.
10354 -- One entry_family component is present for each entry family in the task
10355 -- definition. The bounds correspond to the bounds of the entry family
10356 -- (which may depend on discriminants). The element type is void, since we
10357 -- only need the bounds information for determining the entry index. Note
10358 -- that the use of an anonymous array would normally be illegal in this
10359 -- context, but this is a parser check, and the semantics is quite prepared
10360 -- to handle such a case.
10362 -- The _Size field is present only if a Storage_Size pragma appears in the
10363 -- task definition. The expression captures the argument that was present
10364 -- in the pragma, and is used to override the task stack size otherwise
10365 -- associated with the task type.
10367 -- The _Priority field is present only if a Priority or Interrupt_Priority
10368 -- pragma appears in the task definition. The expression captures the
10369 -- argument that was present in the pragma, and is used to provide the Size
10370 -- parameter to the call to Create_Task.
10372 -- The _Task_Info field is present only if a Task_Info pragma appears in
10373 -- the task definition. The expression captures the argument that was
10374 -- present in the pragma, and is used to provide the Task_Image parameter
10375 -- to the call to Create_Task.
10377 -- The _CPU field is present only if a CPU pragma appears in the task
10378 -- definition. The expression captures the argument that was present in
10379 -- the pragma, and is used to provide the CPU parameter to the call to
10382 -- The _Relative_Deadline field is present only if a Relative_Deadline
10383 -- pragma appears in the task definition. The expression captures the
10384 -- argument that was present in the pragma, and is used to provide the
10385 -- Relative_Deadline parameter to the call to Create_Task.
10387 -- When a task is declared, an instance of the task value record is
10388 -- created. The elaboration of this declaration creates the correct bounds
10389 -- for the entry families, and also evaluates the size, priority, and
10390 -- task_Info expressions if needed. The initialization routine for the task
10391 -- type itself then calls Create_Task with appropriate parameters to
10392 -- initialize the value of the Task_Id field.
10394 -- Note: the address of this record is passed as the "Discriminants"
10395 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10396 -- body procedure, it does not matter that it does not quite match the
10397 -- GNARLI model of what is being passed (the record contains more than just
10398 -- the discriminants, but the discriminants can be found from the record
10401 -- The Entity_Id for this created record type is placed in the
10402 -- Corresponding_Record_Type field of the associated task type entity.
10404 -- Next we create a procedure specification for the task body procedure:
10406 -- procedure taskB (_Task : access taskV);
10408 -- Note that this must come after the record type declaration, since
10409 -- the spec refers to this type. It turns out that the initialization
10410 -- procedure for the value type references the task body spec, but that's
10411 -- fine, since it won't be generated till the freeze point for the type,
10412 -- which is certainly after the task body spec declaration.
10414 -- Finally, we set the task index value field of the entry attribute in
10415 -- the case of a simple entry.
10417 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
10418 Loc
: constant Source_Ptr
:= Sloc
(N
);
10419 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
10420 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
10421 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
10423 Proc_Spec
: Node_Id
;
10424 Rec_Decl
: Node_Id
;
10425 Rec_Ent
: Entity_Id
;
10427 Elab_Decl
: Node_Id
;
10428 Size_Decl
: Node_Id
;
10429 Body_Decl
: Node_Id
;
10430 Task_Size
: Node_Id
;
10431 Ent_Stack
: Entity_Id
;
10432 Decl_Stack
: Node_Id
;
10435 -- If already expanded, nothing to do
10437 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
10441 -- Here we will do the expansion
10443 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
10445 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
10446 Cdecls
:= Component_Items
(Component_List
10447 (Type_Definition
(Rec_Decl
)));
10449 Qualify_Entity_Names
(N
);
10451 -- First create the elaboration variable
10454 Make_Object_Declaration
(Loc
,
10455 Defining_Identifier
=>
10456 Make_Defining_Identifier
(Sloc
(Tasktyp
),
10457 Chars
=> New_External_Name
(Tasknm
, 'E')),
10458 Aliased_Present
=> True,
10459 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
10460 Expression
=> New_Reference_To
(Standard_False
, Loc
));
10461 Insert_After
(N
, Elab_Decl
);
10463 -- Next create the declaration of the size variable (tasknmZ)
10465 Set_Storage_Size_Variable
(Tasktyp
,
10466 Make_Defining_Identifier
(Sloc
(Tasktyp
),
10467 Chars
=> New_External_Name
(Tasknm
, 'Z')));
10469 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) and then
10470 Is_Static_Expression
(Expression
(First
(
10471 Pragma_Argument_Associations
(Find_Task_Or_Protected_Pragma
(
10472 Taskdef
, Name_Storage_Size
)))))
10475 Make_Object_Declaration
(Loc
,
10476 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
10477 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
10479 Convert_To
(RTE
(RE_Size_Type
),
10481 Expression
(First
(
10482 Pragma_Argument_Associations
(
10483 Find_Task_Or_Protected_Pragma
10484 (Taskdef
, Name_Storage_Size
)))))));
10488 Make_Object_Declaration
(Loc
,
10489 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
10490 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
10491 Expression
=> New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
10494 Insert_After
(Elab_Decl
, Size_Decl
);
10496 -- Next build the rest of the corresponding record declaration. This is
10497 -- done last, since the corresponding record initialization procedure
10498 -- will reference the previously created entities.
10500 -- Fill in the component declarations -- first the _Task_Id field
10503 Make_Component_Declaration
(Loc
,
10504 Defining_Identifier
=>
10505 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
10506 Component_Definition
=>
10507 Make_Component_Definition
(Loc
,
10508 Aliased_Present
=> False,
10509 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
10512 -- Declare static ATCB (that is, created by the expander) if we are
10513 -- using the Restricted run time.
10515 if Restricted_Profile
then
10517 Make_Component_Declaration
(Loc
,
10518 Defining_Identifier
=>
10519 Make_Defining_Identifier
(Loc
, Name_uATCB
),
10521 Component_Definition
=>
10522 Make_Component_Definition
(Loc
,
10523 Aliased_Present
=> True,
10524 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
10525 Subtype_Mark
=> New_Occurrence_Of
10526 (RTE
(RE_Ada_Task_Control_Block
), Loc
),
10529 Make_Index_Or_Discriminant_Constraint
(Loc
,
10531 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
10535 -- Declare static stack (that is, created by the expander) if we are
10536 -- using the Restricted run time on a bare board configuration.
10538 if Restricted_Profile
10539 and then Preallocated_Stacks_On_Target
10541 -- First we need to extract the appropriate stack size
10543 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
10545 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
10547 Expr_N
: constant Node_Id
:=
10548 Expression
(First
(
10549 Pragma_Argument_Associations
(
10550 Find_Task_Or_Protected_Pragma
10551 (Taskdef
, Name_Storage_Size
))));
10552 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
10553 P
: constant Node_Id
:= Parent
(Expr_N
);
10556 -- The stack is defined inside the corresponding record.
10557 -- Therefore if the size of the stack is set by means of
10558 -- a discriminant, we must reference the discriminant of the
10559 -- corresponding record type.
10561 if Nkind
(Expr_N
) in N_Has_Entity
10562 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
10566 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
10568 Set_Parent
(Task_Size
, P
);
10569 Set_Etype
(Task_Size
, Etyp
);
10570 Set_Analyzed
(Task_Size
);
10573 Task_Size
:= Relocate_Node
(Expr_N
);
10579 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
10582 Decl_Stack
:= Make_Component_Declaration
(Loc
,
10583 Defining_Identifier
=> Ent_Stack
,
10585 Component_Definition
=>
10586 Make_Component_Definition
(Loc
,
10587 Aliased_Present
=> True,
10588 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
10590 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
10593 Make_Index_Or_Discriminant_Constraint
(Loc
,
10594 Constraints
=> New_List
(Make_Range
(Loc
,
10595 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
10596 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
10599 Append_To
(Cdecls
, Decl_Stack
);
10601 -- The appropriate alignment for the stack is ensured by the run-time
10602 -- code in charge of task creation.
10606 -- Add components for entry families
10608 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
10610 -- Add the _Priority component if a Priority pragma is present
10612 if Present
(Taskdef
) and then Has_Pragma_Priority
(Taskdef
) then
10614 Prag
: constant Node_Id
:=
10615 Find_Task_Or_Protected_Pragma
(Taskdef
, Name_Priority
);
10619 Expr
:= First
(Pragma_Argument_Associations
(Prag
));
10621 if Nkind
(Expr
) = N_Pragma_Argument_Association
then
10622 Expr
:= Expression
(Expr
);
10625 Expr
:= New_Copy_Tree
(Expr
);
10627 -- Add conversion to proper type to do range check if required
10628 -- Note that for runtime units, we allow out of range interrupt
10629 -- priority values to be used in a priority pragma. This is for
10630 -- the benefit of some versions of System.Interrupts which use
10631 -- a special server task with maximum interrupt priority.
10633 if Pragma_Name
(Prag
) = Name_Priority
10634 and then not GNAT_Mode
10636 Rewrite
(Expr
, Convert_To
(RTE
(RE_Priority
), Expr
));
10638 Rewrite
(Expr
, Convert_To
(RTE
(RE_Any_Priority
), Expr
));
10642 Make_Component_Declaration
(Loc
,
10643 Defining_Identifier
=>
10644 Make_Defining_Identifier
(Loc
, Name_uPriority
),
10645 Component_Definition
=>
10646 Make_Component_Definition
(Loc
,
10647 Aliased_Present
=> False,
10648 Subtype_Indication
=> New_Reference_To
(Standard_Integer
,
10650 Expression
=> Expr
));
10654 -- Add the _Task_Size component if a Storage_Size pragma is present
10656 if Present
(Taskdef
)
10657 and then Has_Storage_Size_Pragma
(Taskdef
)
10660 Make_Component_Declaration
(Loc
,
10661 Defining_Identifier
=>
10662 Make_Defining_Identifier
(Loc
, Name_uSize
),
10664 Component_Definition
=>
10665 Make_Component_Definition
(Loc
,
10666 Aliased_Present
=> False,
10667 Subtype_Indication
=> New_Reference_To
(RTE
(RE_Size_Type
),
10671 Convert_To
(RTE
(RE_Size_Type
),
10673 Expression
(First
(
10674 Pragma_Argument_Associations
(
10675 Find_Task_Or_Protected_Pragma
10676 (Taskdef
, Name_Storage_Size
))))))));
10679 -- Add the _Task_Info component if a Task_Info pragma is present
10681 if Present
(Taskdef
) and then Has_Task_Info_Pragma
(Taskdef
) then
10683 Make_Component_Declaration
(Loc
,
10684 Defining_Identifier
=>
10685 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
10687 Component_Definition
=>
10688 Make_Component_Definition
(Loc
,
10689 Aliased_Present
=> False,
10690 Subtype_Indication
=>
10691 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
10693 Expression
=> New_Copy
(
10694 Expression
(First
(
10695 Pragma_Argument_Associations
(
10696 Find_Task_Or_Protected_Pragma
10697 (Taskdef
, Name_Task_Info
)))))));
10700 -- Add the _CPU component if a CPU pragma is present
10702 if Present
(Taskdef
) and then Has_Pragma_CPU
(Taskdef
) then
10704 Make_Component_Declaration
(Loc
,
10705 Defining_Identifier
=>
10706 Make_Defining_Identifier
(Loc
, Name_uCPU
),
10708 Component_Definition
=>
10709 Make_Component_Definition
(Loc
,
10710 Aliased_Present
=> False,
10711 Subtype_Indication
=>
10712 New_Reference_To
(RTE
(RE_CPU_Range
), Loc
)),
10714 Expression
=> New_Copy
(
10715 Expression
(First
(
10716 Pragma_Argument_Associations
(
10717 Find_Task_Or_Protected_Pragma
10718 (Taskdef
, Name_CPU
)))))));
10721 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10722 -- present. If we are using a restricted run time this component will
10723 -- not be added (deadlines are not allowed by the Ravenscar profile).
10725 if not Restricted_Profile
10726 and then Present
(Taskdef
)
10727 and then Has_Relative_Deadline_Pragma
(Taskdef
)
10730 Make_Component_Declaration
(Loc
,
10731 Defining_Identifier
=>
10732 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
10734 Component_Definition
=>
10735 Make_Component_Definition
(Loc
,
10736 Aliased_Present
=> False,
10737 Subtype_Indication
=>
10738 New_Reference_To
(RTE
(RE_Time_Span
), Loc
)),
10741 Convert_To
(RTE
(RE_Time_Span
),
10743 Expression
(First
(
10744 Pragma_Argument_Associations
(
10745 Find_Task_Or_Protected_Pragma
10746 (Taskdef
, Name_Relative_Deadline
))))))));
10749 Insert_After
(Size_Decl
, Rec_Decl
);
10751 -- Analyze the record declaration immediately after construction,
10752 -- because the initialization procedure is needed for single task
10753 -- declarations before the next entity is analyzed.
10755 Analyze
(Rec_Decl
);
10757 -- Create the declaration of the task body procedure
10759 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
10761 Make_Subprogram_Declaration
(Loc
,
10762 Specification
=> Proc_Spec
);
10764 Insert_After
(Rec_Decl
, Body_Decl
);
10766 -- The subprogram does not comes from source, so we have to indicate the
10767 -- need for debugging information explicitly.
10769 if Comes_From_Source
(Original_Node
(N
)) then
10770 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
10773 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10774 -- the corresponding record has been frozen.
10776 if Ada_Version
>= Ada_2005
then
10777 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
10780 -- Ada 2005 (AI-345): We must defer freezing to allow further
10781 -- declaration of primitive subprograms covering task interfaces
10783 if Ada_Version
<= Ada_95
then
10785 -- Now we can freeze the corresponding record. This needs manually
10786 -- freezing, since it is really part of the task type, and the task
10787 -- type is frozen at this stage. We of course need the initialization
10788 -- procedure for this corresponding record type and we won't get it
10789 -- in time if we don't freeze now.
10792 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
10794 if Is_Non_Empty_List
(L
) then
10795 Insert_List_After
(Body_Decl
, L
);
10800 -- Complete the expansion of access types to the current task type, if
10801 -- any were declared.
10803 Expand_Previous_Access_Type
(Tasktyp
);
10805 -- Create wrappers for entries that have pre/postconditions
10811 Ent
:= First_Entity
(Tasktyp
);
10812 while Present
(Ent
) loop
10813 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
10814 and then Present
(Spec_PPC_List
(Ent
))
10816 Build_PPC_Wrapper
(Ent
, N
);
10822 end Expand_N_Task_Type_Declaration
;
10824 -------------------------------
10825 -- Expand_N_Timed_Entry_Call --
10826 -------------------------------
10828 -- A timed entry call in normal case is not implemented using ATC mechanism
10829 -- anymore for efficiency reason.
10839 -- is expanded as follow:
10841 -- 1) When T.E is a task entry_call;
10845 -- X : Task_Entry_Index := <entry index>;
10846 -- DX : Duration := To_Duration (D);
10847 -- M : Delay_Mode := <discriminant>;
10848 -- P : parms := (parm, parm, parm);
10851 -- Timed_Protected_Entry_Call
10852 -- (<acceptor-task>, X, P'Address, DX, M, B);
10860 -- 2) When T.E is a protected entry_call;
10864 -- X : Protected_Entry_Index := <entry index>;
10865 -- DX : Duration := To_Duration (D);
10866 -- M : Delay_Mode := <discriminant>;
10867 -- P : parms := (parm, parm, parm);
10870 -- Timed_Protected_Entry_Call
10871 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10879 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10882 -- B : Boolean := False;
10883 -- C : Ada.Tags.Prim_Op_Kind;
10884 -- DX : Duration := To_Duration (D)
10885 -- K : Ada.Tags.Tagged_Kind :=
10886 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10887 -- M : Integer :=...;
10888 -- P : Parameters := (Param1 .. ParamN);
10892 -- if K = Ada.Tags.TK_Limited_Tagged then
10893 -- <dispatching-call>;
10894 -- <triggering-statements>
10898 -- Ada.Tags.Get_Offset_Index
10899 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10901 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10903 -- if C = POK_Protected_Entry
10904 -- or else C = POK_Task_Entry
10906 -- Param1 := P.Param1;
10908 -- ParamN := P.ParamN;
10912 -- if C = POK_Procedure
10913 -- or else C = POK_Protected_Procedure
10914 -- or else C = POK_Task_Procedure
10916 -- <dispatching-call>;
10919 -- <triggering-statements>
10921 -- <timed-statements>
10926 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
10927 Loc
: constant Source_Ptr
:= Sloc
(N
);
10929 E_Call
: Node_Id
:=
10930 Entry_Call_Statement
(Entry_Call_Alternative
(N
));
10931 E_Stats
: constant List_Id
:=
10932 Statements
(Entry_Call_Alternative
(N
));
10933 D_Stat
: Node_Id
:=
10934 Delay_Statement
(Delay_Alternative
(N
));
10935 D_Stats
: constant List_Id
:=
10936 Statements
(Delay_Alternative
(N
));
10939 Blk_Typ
: Entity_Id
;
10941 Call_Ent
: Entity_Id
;
10942 Conc_Typ_Stmts
: List_Id
;
10946 D_Type
: Entity_Id
;
10952 Is_Disp_Select
: Boolean;
10953 Lim_Typ_Stmts
: List_Id
;
10962 B
: Entity_Id
; -- Call status flag
10963 C
: Entity_Id
; -- Call kind
10964 D
: Entity_Id
; -- Delay
10965 K
: Entity_Id
; -- Tagged kind
10966 M
: Entity_Id
; -- Delay mode
10967 P
: Entity_Id
; -- Parameter block
10968 S
: Entity_Id
; -- Primitive operation slot
10971 -- Under the Ravenscar profile, timed entry calls are excluded. An error
10972 -- was already reported on spec, so do not attempt to expand the call.
10974 if Restriction_Active
(No_Select_Statements
) then
10978 -- The arguments in the call may require dynamic allocation, and the
10979 -- call statement may have been transformed into a block. The block
10980 -- may contain additional declarations for internal entities, and the
10981 -- original call is found by sequential search.
10983 if Nkind
(E_Call
) = N_Block_Statement
then
10984 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
10985 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
10986 N_Entry_Call_Statement
)
10993 Ada_Version
>= Ada_2005
10994 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
10996 if Is_Disp_Select
then
10997 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
11003 -- B : Boolean := False;
11005 B
:= Build_B
(Loc
, Decls
);
11008 -- C : Ada.Tags.Prim_Op_Kind;
11010 C
:= Build_C
(Loc
, Decls
);
11012 -- Because the analysis of all statements was disabled, manually
11013 -- analyze the delay statement.
11016 D_Stat
:= Original_Node
(D_Stat
);
11019 -- Build an entry call using Simple_Entry_Call
11021 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
11022 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
11024 Decls
:= Declarations
(E_Call
);
11025 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
11034 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
11037 Make_Object_Declaration
(Loc
,
11038 Defining_Identifier
=>
11040 Object_Definition
=>
11041 New_Reference_To
(Standard_Boolean
, Loc
)));
11044 -- Duration and mode processing
11046 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
11048 -- Use the type of the delay expression (Calendar or Real_Time) to
11049 -- generate the appropriate conversion.
11051 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
11052 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
11053 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
11055 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
11056 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
11057 D_Conv
:= Make_Function_Call
(Loc
,
11058 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
11059 New_List
(New_Copy
(Expression
(D_Stat
))));
11061 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
11062 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
11063 D_Conv
:= Make_Function_Call
(Loc
,
11064 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
11065 New_List
(New_Copy
(Expression
(D_Stat
))));
11068 D
:= Make_Temporary
(Loc
, 'D');
11074 Make_Object_Declaration
(Loc
,
11075 Defining_Identifier
=>
11077 Object_Definition
=>
11078 New_Reference_To
(Standard_Duration
, Loc
)));
11080 M
:= Make_Temporary
(Loc
, 'M');
11083 -- M : Integer := (0 | 1 | 2);
11086 Make_Object_Declaration
(Loc
,
11087 Defining_Identifier
=>
11089 Object_Definition
=>
11090 New_Reference_To
(Standard_Integer
, Loc
),
11094 -- Do the assignment at this stage only because the evaluation of the
11095 -- expression must not occur before (see ACVC C97302A).
11098 Make_Assignment_Statement
(Loc
,
11100 New_Reference_To
(D
, Loc
),
11104 -- Parameter block processing
11106 -- Manually create the parameter block for dispatching calls. In the
11107 -- case of entries, the block has already been created during the call
11108 -- to Build_Simple_Entry_Call.
11110 if Is_Disp_Select
then
11112 -- Tagged kind processing, generate:
11113 -- K : Ada.Tags.Tagged_Kind :=
11114 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11116 K
:= Build_K
(Loc
, Decls
, Obj
);
11118 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
11119 P
:= Parameter_Block_Pack
11120 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
11122 -- Dispatch table slot processing, generate:
11125 S
:= Build_S
(Loc
, Decls
);
11128 -- S := Ada.Tags.Get_Offset_Index
11129 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11132 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
11135 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11137 -- where Obj is the controlling formal parameter, S is the dispatch
11138 -- table slot number of the dispatching operation, P is the wrapped
11139 -- parameter block, D is the duration, M is the duration mode, C is
11140 -- the call kind and B is the call status.
11142 Params
:= New_List
;
11144 Append_To
(Params
, New_Copy_Tree
(Obj
));
11145 Append_To
(Params
, New_Reference_To
(S
, Loc
));
11146 Append_To
(Params
, Make_Attribute_Reference
(Loc
,
11147 Prefix
=> New_Reference_To
(P
, Loc
),
11148 Attribute_Name
=> Name_Address
));
11149 Append_To
(Params
, New_Reference_To
(D
, Loc
));
11150 Append_To
(Params
, New_Reference_To
(M
, Loc
));
11151 Append_To
(Params
, New_Reference_To
(C
, Loc
));
11152 Append_To
(Params
, New_Reference_To
(B
, Loc
));
11154 Append_To
(Conc_Typ_Stmts
,
11155 Make_Procedure_Call_Statement
(Loc
,
11158 Find_Prim_Op
(Etype
(Etype
(Obj
)),
11159 Name_uDisp_Timed_Select
),
11161 Parameter_Associations
=>
11165 -- if C = POK_Protected_Entry
11166 -- or else C = POK_Task_Entry
11168 -- Param1 := P.Param1;
11170 -- ParamN := P.ParamN;
11173 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
11175 -- Generate the if statement only when the packed parameters need
11176 -- explicit assignments to their corresponding actuals.
11178 if Present
(Unpack
) then
11179 Append_To
(Conc_Typ_Stmts
,
11180 Make_If_Statement
(Loc
,
11187 New_Reference_To
(C
, Loc
),
11189 New_Reference_To
(RTE
(
11190 RE_POK_Protected_Entry
), Loc
)),
11194 New_Reference_To
(C
, Loc
),
11196 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
11205 -- if C = POK_Procedure
11206 -- or else C = POK_Protected_Procedure
11207 -- or else C = POK_Task_Procedure
11209 -- <dispatching-call>
11211 -- <triggering-statements>
11213 -- <timed-statements>
11216 N_Stats
:= New_Copy_List_Tree
(E_Stats
);
11218 Prepend_To
(N_Stats
,
11219 Make_If_Statement
(Loc
,
11226 New_Reference_To
(C
, Loc
),
11228 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
11234 New_Reference_To
(C
, Loc
),
11236 New_Reference_To
(RTE
(
11237 RE_POK_Protected_Procedure
), Loc
)),
11241 New_Reference_To
(C
, Loc
),
11243 New_Reference_To
(RTE
(
11244 RE_POK_Task_Procedure
), Loc
)))),
11247 New_List
(E_Call
)));
11249 Append_To
(Conc_Typ_Stmts
,
11250 Make_If_Statement
(Loc
,
11251 Condition
=> New_Reference_To
(B
, Loc
),
11252 Then_Statements
=> N_Stats
,
11253 Else_Statements
=> D_Stats
));
11256 -- <dispatching-call>;
11257 -- <triggering-statements>
11259 Lim_Typ_Stmts
:= New_Copy_List_Tree
(E_Stats
);
11260 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(E_Call
));
11263 -- if K = Ada.Tags.TK_Limited_Tagged then
11270 Make_If_Statement
(Loc
,
11274 New_Reference_To
(K
, Loc
),
11276 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
11285 -- Skip assignments to temporaries created for in-out parameters.
11286 -- This makes unwarranted assumptions about the shape of the expanded
11287 -- tree for the call, and should be cleaned up ???
11289 Stmt
:= First
(Stmts
);
11290 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
11294 -- Do the assignment at this stage only because the evaluation
11295 -- of the expression must not occur before (see ACVC C97302A).
11297 Insert_Before
(Stmt
,
11298 Make_Assignment_Statement
(Loc
,
11299 Name
=> New_Reference_To
(D
, Loc
),
11300 Expression
=> D_Conv
));
11303 Params
:= Parameter_Associations
(Call
);
11305 -- For a protected type, we build a Timed_Protected_Entry_Call
11307 if Is_Protected_Type
(Etype
(Concval
)) then
11309 -- Create a new call statement
11311 Param
:= First
(Params
);
11312 while Present
(Param
)
11313 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
11318 Dummy
:= Remove_Next
(Next
(Param
));
11320 -- Remove garbage is following the Cancel_Param if present
11322 Dummy
:= Next
(Param
);
11324 -- Remove the mode of the Protected_Entry_Call call, then remove
11325 -- the Communication_Block of the Protected_Entry_Call call, and
11326 -- finally add Duration and a Delay_Mode parameter
11328 pragma Assert
(Present
(Param
));
11329 Rewrite
(Param
, New_Reference_To
(D
, Loc
));
11331 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
11333 -- Add a Boolean flag for successful entry call
11335 Append_To
(Params
, New_Reference_To
(B
, Loc
));
11337 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
11338 when System_Tasking_Protected_Objects_Entries
=>
11340 Make_Procedure_Call_Statement
(Loc
,
11343 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
11344 Parameter_Associations
=> Params
));
11346 when System_Tasking_Protected_Objects_Single_Entry
=>
11347 Param
:= First
(Params
);
11348 while Present
(Param
)
11350 Is_RTE
(Etype
(Param
), RE_Protected_Entry_Index
)
11358 Make_Procedure_Call_Statement
(Loc
,
11359 Name
=> New_Reference_To
(
11360 RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
11361 Parameter_Associations
=> Params
));
11364 raise Program_Error
;
11367 -- For the task case, build a Timed_Task_Entry_Call
11370 -- Create a new call statement
11372 Append_To
(Params
, New_Reference_To
(D
, Loc
));
11373 Append_To
(Params
, New_Reference_To
(M
, Loc
));
11374 Append_To
(Params
, New_Reference_To
(B
, Loc
));
11377 Make_Procedure_Call_Statement
(Loc
,
11379 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
11380 Parameter_Associations
=> Params
));
11384 Make_Implicit_If_Statement
(N
,
11385 Condition
=> New_Reference_To
(B
, Loc
),
11386 Then_Statements
=> E_Stats
,
11387 Else_Statements
=> D_Stats
));
11391 Make_Block_Statement
(Loc
,
11392 Declarations
=> Decls
,
11393 Handled_Statement_Sequence
=>
11394 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
11397 end Expand_N_Timed_Entry_Call
;
11399 ----------------------------------------
11400 -- Expand_Protected_Body_Declarations --
11401 ----------------------------------------
11403 procedure Expand_Protected_Body_Declarations
11405 Spec_Id
: Entity_Id
)
11408 if No_Run_Time_Mode
then
11409 Error_Msg_CRT
("protected body", N
);
11412 elsif Expander_Active
then
11414 -- Associate discriminals with the first subprogram or entry body to
11417 if Present
(First_Protected_Operation
(Declarations
(N
))) then
11418 Set_Discriminals
(Parent
(Spec_Id
));
11421 end Expand_Protected_Body_Declarations
;
11423 -------------------------
11424 -- External_Subprogram --
11425 -------------------------
11427 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
11428 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
11431 -- The internal and external subprograms follow each other on the entity
11432 -- chain. Note that previously private operations had no separate
11433 -- external subprogram. We now create one in all cases, because a
11434 -- private operation may actually appear in an external call, through
11435 -- a 'Access reference used for a callback.
11437 -- If the operation is a function that returns an anonymous access type,
11438 -- the corresponding itype appears before the operation, and must be
11441 -- This mechanism is fragile, there should be a real link between the
11442 -- two versions of the operation, but there is no place to put it ???
11444 if Is_Access_Type
(Next_Entity
(Subp
)) then
11445 return Next_Entity
(Next_Entity
(Subp
));
11447 return Next_Entity
(Subp
);
11449 end External_Subprogram
;
11451 ------------------------------
11452 -- Extract_Dispatching_Call --
11453 ------------------------------
11455 procedure Extract_Dispatching_Call
11457 Call_Ent
: out Entity_Id
;
11458 Object
: out Entity_Id
;
11459 Actuals
: out List_Id
;
11460 Formals
: out List_Id
)
11462 Call_Nam
: Node_Id
;
11465 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
11467 if Present
(Original_Node
(N
)) then
11468 Call_Nam
:= Name
(Original_Node
(N
));
11470 Call_Nam
:= Name
(N
);
11473 -- Retrieve the name of the dispatching procedure. It contains the
11474 -- dispatch table slot number.
11477 case Nkind
(Call_Nam
) is
11478 when N_Identifier
=>
11481 when N_Selected_Component
=>
11482 Call_Nam
:= Selector_Name
(Call_Nam
);
11485 raise Program_Error
;
11490 Actuals
:= Parameter_Associations
(N
);
11491 Call_Ent
:= Entity
(Call_Nam
);
11492 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
11493 Object
:= First
(Actuals
);
11495 if Present
(Original_Node
(Object
)) then
11496 Object
:= Original_Node
(Object
);
11498 end Extract_Dispatching_Call
;
11500 -------------------
11501 -- Extract_Entry --
11502 -------------------
11504 procedure Extract_Entry
11506 Concval
: out Node_Id
;
11507 Ename
: out Node_Id
;
11508 Index
: out Node_Id
)
11510 Nam
: constant Node_Id
:= Name
(N
);
11513 -- For a simple entry, the name is a selected component, with the
11514 -- prefix being the task value, and the selector being the entry.
11516 if Nkind
(Nam
) = N_Selected_Component
then
11517 Concval
:= Prefix
(Nam
);
11518 Ename
:= Selector_Name
(Nam
);
11521 -- For a member of an entry family, the name is an indexed component
11522 -- where the prefix is a selected component, whose prefix in turn is
11523 -- the task value, and whose selector is the entry family. The single
11524 -- expression in the expressions list of the indexed component is the
11525 -- subscript for the family.
11527 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
11528 Concval
:= Prefix
(Prefix
(Nam
));
11529 Ename
:= Selector_Name
(Prefix
(Nam
));
11530 Index
:= First
(Expressions
(Nam
));
11534 -------------------
11535 -- Family_Offset --
11536 -------------------
11538 function Family_Offset
11543 Cap
: Boolean) return Node_Id
11549 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
11550 -- If one of the bounds is a reference to a discriminant, replace with
11551 -- corresponding discriminal of type. Within the body of a task retrieve
11552 -- the renamed discriminant by simple visibility, using its generated
11553 -- name. Within a protected object, find the original discriminant and
11554 -- replace it with the discriminal of the current protected operation.
11556 ------------------------------
11557 -- Convert_Discriminant_Ref --
11558 ------------------------------
11560 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
11561 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
11566 if Is_Entity_Name
(Bound
)
11567 and then Ekind
(Entity
(Bound
)) = E_Discriminant
11569 if Is_Task_Type
(Ttyp
)
11570 and then Has_Completion
(Ttyp
)
11572 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
11573 Find_Direct_Name
(B
);
11575 elsif Is_Protected_Type
(Ttyp
) then
11576 D
:= First_Discriminant
(Ttyp
);
11577 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
11578 Next_Discriminant
(D
);
11581 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
11584 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
11587 elsif Nkind
(Bound
) = N_Attribute_Reference
then
11591 B
:= New_Copy_Tree
(Bound
);
11595 Make_Attribute_Reference
(Loc
,
11596 Attribute_Name
=> Name_Pos
,
11597 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
11598 Expressions
=> New_List
(B
));
11599 end Convert_Discriminant_Ref
;
11601 -- Start of processing for Family_Offset
11604 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
11605 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
11608 if Is_Task_Type
(Ttyp
) then
11609 Ityp
:= RTE
(RE_Task_Entry_Index
);
11611 Ityp
:= RTE
(RE_Protected_Entry_Index
);
11615 Make_Attribute_Reference
(Loc
,
11616 Prefix
=> New_Reference_To
(Ityp
, Loc
),
11617 Attribute_Name
=> Name_Min
,
11618 Expressions
=> New_List
(
11620 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
11623 Make_Attribute_Reference
(Loc
,
11624 Prefix
=> New_Reference_To
(Ityp
, Loc
),
11625 Attribute_Name
=> Name_Max
,
11626 Expressions
=> New_List
(
11628 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
11631 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
11638 function Family_Size
11643 Cap
: Boolean) return Node_Id
11648 if Is_Task_Type
(Ttyp
) then
11649 Ityp
:= RTE
(RE_Task_Entry_Index
);
11651 Ityp
:= RTE
(RE_Protected_Entry_Index
);
11655 Make_Attribute_Reference
(Loc
,
11656 Prefix
=> New_Reference_To
(Ityp
, Loc
),
11657 Attribute_Name
=> Name_Max
,
11658 Expressions
=> New_List
(
11661 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
11663 Make_Integer_Literal
(Loc
, 1)),
11664 Make_Integer_Literal
(Loc
, 0)));
11667 -----------------------
11668 -- Find_Master_Scope --
11669 -----------------------
11671 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
11675 -- In Ada2005, the master is the innermost enclosing scope that is not
11676 -- transient. If the enclosing block is the rewriting of a call or the
11677 -- scope is an extended return statement this is valid master. The
11678 -- master in an extended return is only used within the return, and is
11679 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11680 -- now before that overwriting occurs.
11684 if Ada_Version
>= Ada_2005
then
11685 while Is_Internal
(S
) loop
11686 if Nkind
(Parent
(S
)) = N_Block_Statement
11688 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
11692 elsif Ekind
(S
) = E_Return_Statement
then
11702 end Find_Master_Scope
;
11704 -----------------------------------
11705 -- Find_Task_Or_Protected_Pragma --
11706 -----------------------------------
11708 function Find_Task_Or_Protected_Pragma
11710 P
: Name_Id
) return Node_Id
11715 N
:= First
(Visible_Declarations
(T
));
11716 while Present
(N
) loop
11717 if Nkind
(N
) = N_Pragma
then
11718 if Pragma_Name
(N
) = P
then
11721 elsif P
= Name_Priority
11722 and then Pragma_Name
(N
) = Name_Interrupt_Priority
11735 N
:= First
(Private_Declarations
(T
));
11736 while Present
(N
) loop
11737 if Nkind
(N
) = N_Pragma
then
11738 if Pragma_Name
(N
) = P
then
11741 elsif P
= Name_Priority
11742 and then Pragma_Name
(N
) = Name_Interrupt_Priority
11755 raise Program_Error
;
11756 end Find_Task_Or_Protected_Pragma
;
11758 -------------------------------
11759 -- First_Protected_Operation --
11760 -------------------------------
11762 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
11763 First_Op
: Node_Id
;
11766 First_Op
:= First
(D
);
11767 while Present
(First_Op
)
11768 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
11774 end First_Protected_Operation
;
11776 ---------------------------------------
11777 -- Install_Private_Data_Declarations --
11778 ---------------------------------------
11780 procedure Install_Private_Data_Declarations
11782 Spec_Id
: Entity_Id
;
11783 Conc_Typ
: Entity_Id
;
11784 Body_Nod
: Node_Id
;
11786 Barrier
: Boolean := False;
11787 Family
: Boolean := False)
11789 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
11792 Insert_Node
: Node_Id
:= Empty
;
11793 Obj_Ent
: Entity_Id
;
11795 procedure Add
(Decl
: Node_Id
);
11796 -- Add a single declaration after Insert_Node. If this is the first
11797 -- addition, Decl is added to the front of Decls and it becomes the
11800 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
11801 -- The bounds of an entry index may depend on discriminants, create a
11802 -- reference to the corresponding prival. Otherwise return a duplicate
11803 -- of the original bound.
11809 procedure Add
(Decl
: Node_Id
) is
11811 if No
(Insert_Node
) then
11812 Prepend_To
(Decls
, Decl
);
11814 Insert_After
(Insert_Node
, Decl
);
11817 Insert_Node
:= Decl
;
11820 --------------------------
11821 -- Replace_Discriminant --
11822 --------------------------
11824 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
11826 if Nkind
(Bound
) = N_Identifier
11827 and then Is_Discriminal
(Entity
(Bound
))
11829 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
11831 return Duplicate_Subexpr
(Bound
);
11835 -- Start of processing for Install_Private_Data_Declarations
11838 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11839 -- formal parameter _O, _object or _task depending on the context.
11841 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
11843 -- Special processing of _O for barrier functions, protected entries
11850 (Ekind
(Spec_Id
) = E_Entry
11851 or else Ekind
(Spec_Id
) = E_Entry_Family
))
11854 Conc_Rec
: constant Entity_Id
:=
11855 Corresponding_Record_Type
(Conc_Typ
);
11856 Typ_Id
: constant Entity_Id
:=
11857 Make_Defining_Identifier
(Loc
,
11858 New_External_Name
(Chars
(Conc_Rec
), 'P'));
11861 -- type prot_typVP is access prot_typV;
11864 Make_Full_Type_Declaration
(Loc
,
11865 Defining_Identifier
=> Typ_Id
,
11867 Make_Access_To_Object_Definition
(Loc
,
11868 Subtype_Indication
=>
11869 New_Reference_To
(Conc_Rec
, Loc
)));
11873 -- _object : prot_typVP := prot_typV (_O);
11876 Make_Object_Declaration
(Loc
,
11877 Defining_Identifier
=>
11878 Make_Defining_Identifier
(Loc
, Name_uObject
),
11879 Object_Definition
=> New_Reference_To
(Typ_Id
, Loc
),
11881 Unchecked_Convert_To
(Typ_Id
,
11882 New_Reference_To
(Obj_Ent
, Loc
)));
11885 -- Set the reference to the concurrent object
11887 Obj_Ent
:= Defining_Identifier
(Decl
);
11891 -- Step 2: Create the Protection object and build its declaration for
11892 -- any protected entry (family) of subprogram.
11894 if Is_Protected
then
11896 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
11900 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
11902 -- Determine the proper protection type
11904 if Has_Attach_Handler
(Conc_Typ
)
11905 and then not Restricted_Profile
11907 Prot_Typ
:= RE_Static_Interrupt_Protection
;
11909 elsif Has_Interrupt_Handler
(Conc_Typ
) then
11910 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
11912 -- The type has explicit entries or generated primitive entry
11915 elsif Has_Entries
(Conc_Typ
)
11917 (Ada_Version
>= Ada_2005
11918 and then Present
(Interface_List
(Parent
(Conc_Typ
))))
11920 case Corresponding_Runtime_Package
(Conc_Typ
) is
11921 when System_Tasking_Protected_Objects_Entries
=>
11922 Prot_Typ
:= RE_Protection_Entries
;
11924 when System_Tasking_Protected_Objects_Single_Entry
=>
11925 Prot_Typ
:= RE_Protection_Entry
;
11928 raise Program_Error
;
11932 Prot_Typ
:= RE_Protection
;
11936 -- conc_typR : protection_typ renames _object._object;
11939 Make_Object_Renaming_Declaration
(Loc
,
11940 Defining_Identifier
=> Prot_Ent
,
11942 New_Reference_To
(RTE
(Prot_Typ
), Loc
),
11944 Make_Selected_Component
(Loc
,
11946 New_Reference_To
(Obj_Ent
, Loc
),
11948 Make_Identifier
(Loc
, Name_uObject
)));
11953 -- Step 3: Add discriminant renamings (if any)
11955 if Has_Discriminants
(Conc_Typ
) then
11960 D
:= First_Discriminant
(Conc_Typ
);
11961 while Present
(D
) loop
11963 -- Adjust the source location
11965 Set_Sloc
(Discriminal
(D
), Loc
);
11968 -- discr_name : discr_typ renames _object.discr_name;
11970 -- discr_name : discr_typ renames _task.discr_name;
11973 Make_Object_Renaming_Declaration
(Loc
,
11974 Defining_Identifier
=> Discriminal
(D
),
11975 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
11977 Make_Selected_Component
(Loc
,
11978 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
11979 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
11982 Next_Discriminant
(D
);
11987 -- Step 4: Add private component renamings (if any)
11989 if Is_Protected
then
11990 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
11992 if Present
(Private_Declarations
(Def
)) then
11995 Comp_Id
: Entity_Id
;
11996 Decl_Id
: Entity_Id
;
11999 Comp
:= First
(Private_Declarations
(Def
));
12000 while Present
(Comp
) loop
12001 if Nkind
(Comp
) = N_Component_Declaration
then
12002 Comp_Id
:= Defining_Identifier
(Comp
);
12004 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
12006 -- Minimal decoration
12008 if Ekind
(Spec_Id
) = E_Function
then
12009 Set_Ekind
(Decl_Id
, E_Constant
);
12011 Set_Ekind
(Decl_Id
, E_Variable
);
12014 Set_Prival
(Comp_Id
, Decl_Id
);
12015 Set_Prival_Link
(Decl_Id
, Comp_Id
);
12016 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
12019 -- comp_name : comp_typ renames _object.comp_name;
12022 Make_Object_Renaming_Declaration
(Loc
,
12023 Defining_Identifier
=> Decl_Id
,
12025 New_Reference_To
(Etype
(Comp_Id
), Loc
),
12027 Make_Selected_Component
(Loc
,
12029 New_Reference_To
(Obj_Ent
, Loc
),
12031 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
12041 -- Step 5: Add the declaration of the entry index and the associated
12042 -- type for barrier functions and entry families.
12044 if (Barrier
and then Family
)
12045 or else Ekind
(Spec_Id
) = E_Entry_Family
12048 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
12049 Index
: constant Entity_Id
:=
12050 Defining_Identifier
(
12051 Entry_Index_Specification
(
12052 Entry_Body_Formal_Part
(Body_Nod
)));
12053 Index_Con
: constant Entity_Id
:=
12054 Make_Defining_Identifier
(Loc
, Chars
(Index
));
12056 Index_Typ
: Entity_Id
;
12060 -- Minimal decoration
12062 Set_Ekind
(Index_Con
, E_Constant
);
12063 Set_Entry_Index_Constant
(Index
, Index_Con
);
12064 Set_Discriminal_Link
(Index_Con
, Index
);
12066 -- Retrieve the bounds of the entry family
12068 High
:= Type_High_Bound
(Etype
(Index
));
12069 Low
:= Type_Low_Bound
(Etype
(Index
));
12071 -- In the simple case the entry family is given by a subtype
12072 -- mark and the index constant has the same type.
12074 if Is_Entity_Name
(Original_Node
(
12075 Discrete_Subtype_Definition
(Parent
(Index
))))
12077 Index_Typ
:= Etype
(Index
);
12079 -- Otherwise a new subtype declaration is required
12082 High
:= Replace_Bound
(High
);
12083 Low
:= Replace_Bound
(Low
);
12085 Index_Typ
:= Make_Temporary
(Loc
, 'J');
12088 -- subtype Jnn is <Etype of Index> range Low .. High;
12091 Make_Subtype_Declaration
(Loc
,
12092 Defining_Identifier
=> Index_Typ
,
12093 Subtype_Indication
=>
12094 Make_Subtype_Indication
(Loc
,
12096 New_Reference_To
(Base_Type
(Etype
(Index
)), Loc
),
12098 Make_Range_Constraint
(Loc
,
12099 Range_Expression
=>
12100 Make_Range
(Loc
, Low
, High
))));
12104 Set_Etype
(Index_Con
, Index_Typ
);
12106 -- Create the object which designates the index:
12107 -- J : constant Jnn :=
12108 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12110 -- where Jnn is the subtype created above or the original type of
12111 -- the index, _E is a formal of the protected body subprogram and
12112 -- <index expr> is the index of the first family member.
12115 Make_Object_Declaration
(Loc
,
12116 Defining_Identifier
=> Index_Con
,
12117 Constant_Present
=> True,
12118 Object_Definition
=>
12119 New_Reference_To
(Index_Typ
, Loc
),
12122 Make_Attribute_Reference
(Loc
,
12124 New_Reference_To
(Index_Typ
, Loc
),
12125 Attribute_Name
=> Name_Val
,
12127 Expressions
=> New_List
(
12131 Make_Op_Subtract
(Loc
,
12133 New_Reference_To
(E
, Loc
),
12135 Entry_Index_Expression
(Loc
,
12136 Defining_Identifier
(Body_Nod
),
12140 Make_Attribute_Reference
(Loc
,
12142 New_Reference_To
(Index_Typ
, Loc
),
12143 Attribute_Name
=> Name_Pos
,
12144 Expressions
=> New_List
(
12145 Make_Attribute_Reference
(Loc
,
12147 New_Reference_To
(Index_Typ
, Loc
),
12148 Attribute_Name
=> Name_First
)))))));
12152 end Install_Private_Data_Declarations
;
12154 ---------------------------------
12155 -- Is_Potentially_Large_Family --
12156 ---------------------------------
12158 function Is_Potentially_Large_Family
12159 (Base_Index
: Entity_Id
;
12160 Conctyp
: Entity_Id
;
12162 Hi
: Node_Id
) return Boolean
12165 return Scope
(Base_Index
) = Standard_Standard
12166 and then Base_Index
= Base_Type
(Standard_Integer
)
12167 and then Has_Discriminants
(Conctyp
)
12169 (Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
12171 (Denotes_Discriminant
(Lo
, True)
12172 or else Denotes_Discriminant
(Hi
, True));
12173 end Is_Potentially_Large_Family
;
12175 -------------------------------------
12176 -- Is_Private_Primitive_Subprogram --
12177 -------------------------------------
12179 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
12182 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
12183 and then Is_Private_Primitive
(Id
);
12184 end Is_Private_Primitive_Subprogram
;
12190 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
12191 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
12192 Formal
: Entity_Id
;
12195 Formal
:= First_Formal
(Bod_Subp
);
12196 while Present
(Formal
) loop
12198 -- Look for formal parameter _E
12200 if Chars
(Formal
) = Name_uE
then
12204 Next_Formal
(Formal
);
12207 -- A protected body subprogram should always have the parameter in
12210 raise Program_Error
;
12213 --------------------------------
12214 -- Make_Initialize_Protection --
12215 --------------------------------
12217 function Make_Initialize_Protection
12218 (Protect_Rec
: Entity_Id
) return List_Id
12220 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
12224 Ptyp
: constant Node_Id
:=
12225 Corresponding_Concurrent_Type
(Protect_Rec
);
12227 L
: constant List_Id
:= New_List
;
12228 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
12229 Restricted
: constant Boolean := Restricted_Profile
;
12232 -- We may need two calls to properly initialize the object, one to
12233 -- Initialize_Protection, and possibly one to Install_Handlers if we
12234 -- have a pragma Attach_Handler.
12236 -- Get protected declaration. In the case of a task type declaration,
12237 -- this is simply the parent of the protected type entity. In the single
12238 -- protected object declaration, this parent will be the implicit type,
12239 -- and we can find the corresponding single protected object declaration
12240 -- by searching forward in the declaration list in the tree.
12242 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12243 -- of this type should have been removed during semantic analysis.
12245 Pdec
:= Parent
(Ptyp
);
12246 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
12247 N_Single_Protected_Declaration
)
12252 -- Now we can find the object definition from this declaration
12254 Pdef
:= Protected_Definition
(Pdec
);
12256 -- Build the parameter list for the call. Note that _Init is the name
12257 -- of the formal for the object to be initialized, which is the task
12258 -- value record itself.
12262 -- Object parameter. This is a pointer to the object of type
12263 -- Protection used by the GNARL to control the protected object.
12266 Make_Attribute_Reference
(Loc
,
12268 Make_Selected_Component
(Loc
,
12269 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12270 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
12271 Attribute_Name
=> Name_Unchecked_Access
));
12273 -- Priority parameter. Set to Unspecified_Priority unless there is a
12274 -- priority pragma, in which case we take the value from the pragma,
12275 -- or there is an interrupt pragma and no priority pragma, and we
12276 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12277 -- defined value, see D.3(10).
12280 and then Has_Pragma_Priority
(Pdef
)
12283 Prio
: constant Node_Id
:=
12286 (Pragma_Argument_Associations
12287 (Find_Task_Or_Protected_Pragma
12288 (Pdef
, Name_Priority
))));
12292 -- If priority is a static expression, then we can duplicate it
12293 -- with no problem and simply append it to the argument list.
12295 if Is_Static_Expression
(Prio
) then
12297 Duplicate_Subexpr_No_Checks
(Prio
));
12299 -- Otherwise, the priority may be a per-object expression, if it
12300 -- depends on a discriminant of the type. In this case, create
12301 -- local variable to capture the expression. Note that it is
12302 -- really necessary to create this variable explicitly. It might
12303 -- be thought that removing side effects would the appropriate
12304 -- approach, but that could generate declarations improperly
12305 -- placed in the enclosing scope.
12307 -- Note: Use System.Any_Priority as the expected type for the
12308 -- non-static priority expression, in case the expression has not
12309 -- been analyzed yet (as occurs for example with pragma
12310 -- Interrupt_Priority).
12313 Temp
:= Make_Temporary
(Loc
, 'R', Prio
);
12315 Make_Object_Declaration
(Loc
,
12316 Defining_Identifier
=> Temp
,
12317 Object_Definition
=>
12318 New_Occurrence_Of
(RTE
(RE_Any_Priority
), Loc
),
12319 Expression
=> Relocate_Node
(Prio
)));
12321 Append_To
(Args
, New_Occurrence_Of
(Temp
, Loc
));
12325 -- When no priority is specified but an xx_Handler pragma is, we default
12326 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12328 elsif Has_Interrupt_Handler
(Ptyp
)
12329 or else Has_Attach_Handler
(Ptyp
)
12332 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
12334 -- Normal case, no priority or xx_Handler specified, default priority
12338 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
12341 -- Test for Compiler_Info parameter. This parameter allows entry body
12342 -- procedures and barrier functions to be called from the runtime. It
12343 -- is a pointer to the record generated by the compiler to represent
12344 -- the protected object.
12347 or else Has_Interrupt_Handler
(Ptyp
)
12348 or else Has_Attach_Handler
(Ptyp
)
12349 or else Has_Interfaces
(Protect_Rec
)
12352 Pkg_Id
: constant RTU_Id
:=
12353 Corresponding_Runtime_Package
(Ptyp
);
12354 Called_Subp
: RE_Id
;
12358 when System_Tasking_Protected_Objects_Entries
=>
12359 Called_Subp
:= RE_Initialize_Protection_Entries
;
12361 when System_Tasking_Protected_Objects
=>
12362 Called_Subp
:= RE_Initialize_Protection
;
12364 when System_Tasking_Protected_Objects_Single_Entry
=>
12365 Called_Subp
:= RE_Initialize_Protection_Entry
;
12368 raise Program_Error
;
12371 if Has_Entry
or else not Restricted
then
12373 Make_Attribute_Reference
(Loc
,
12374 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12375 Attribute_Name
=> Name_Address
));
12378 -- Entry_Bodies parameter. This is a pointer to an array of
12379 -- pointers to the entry body procedures and barrier functions of
12380 -- the object. If the protected type has no entries this object
12381 -- will not exist, in this case, pass a null.
12384 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
12387 Make_Attribute_Reference
(Loc
,
12388 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
12389 Attribute_Name
=> Name_Unrestricted_Access
));
12391 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
12393 -- Find index mapping function (clumsy but ok for now)
12395 while Ekind
(P_Arr
) /= E_Function
loop
12396 Next_Entity
(P_Arr
);
12400 Make_Attribute_Reference
(Loc
,
12402 New_Reference_To
(P_Arr
, Loc
),
12403 Attribute_Name
=> Name_Unrestricted_Access
));
12405 -- Build_Entry_Names generation flag. When set to true, the
12406 -- runtime will allocate an array to hold the string names
12407 -- of protected entries.
12409 if not Restricted_Profile
then
12410 if Entry_Names_OK
then
12412 New_Reference_To
(Standard_True
, Loc
));
12415 New_Reference_To
(Standard_False
, Loc
));
12420 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
12421 Append_To
(Args
, Make_Null
(Loc
));
12423 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
12424 Append_To
(Args
, Make_Null
(Loc
));
12425 Append_To
(Args
, Make_Null
(Loc
));
12426 Append_To
(Args
, New_Reference_To
(Standard_False
, Loc
));
12430 Make_Procedure_Call_Statement
(Loc
,
12431 Name
=> New_Reference_To
(RTE
(Called_Subp
), Loc
),
12432 Parameter_Associations
=> Args
));
12436 Make_Procedure_Call_Statement
(Loc
,
12437 Name
=> New_Reference_To
(RTE
(RE_Initialize_Protection
), Loc
),
12438 Parameter_Associations
=> Args
));
12441 if Has_Attach_Handler
(Ptyp
) then
12443 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12444 -- make the following call:
12446 -- Install_Handlers (_object,
12447 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12449 -- or, in the case of Ravenscar:
12451 -- Install_Restricted_Handlers
12452 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12455 Args
: constant List_Id
:= New_List
;
12456 Table
: constant List_Id
:= New_List
;
12457 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
12460 -- Build the Attach_Handler table argument
12462 while Present
(Ritem
) loop
12463 if Nkind
(Ritem
) = N_Pragma
12464 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
12467 Handler
: constant Node_Id
:=
12468 First
(Pragma_Argument_Associations
(Ritem
));
12470 Interrupt
: constant Node_Id
:= Next
(Handler
);
12471 Expr
: constant Node_Id
:= Expression
(Interrupt
);
12475 Make_Aggregate
(Loc
, Expressions
=> New_List
(
12476 Unchecked_Convert_To
12477 (RTE
(RE_System_Interrupt_Id
), Expr
),
12478 Make_Attribute_Reference
(Loc
,
12479 Prefix
=> Make_Selected_Component
(Loc
,
12480 Make_Identifier
(Loc
, Name_uInit
),
12481 Duplicate_Subexpr_No_Checks
12482 (Expression
(Handler
))),
12483 Attribute_Name
=> Name_Access
))));
12487 Next_Rep_Item
(Ritem
);
12490 -- Append the table argument we just built
12492 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
12494 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12495 -- call to the statements.
12498 -- Call a simplified version of Install_Handlers to be used
12499 -- when the Ravenscar restrictions are in effect
12500 -- (Install_Restricted_Handlers).
12503 Make_Procedure_Call_Statement
(Loc
,
12506 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
12507 Parameter_Associations
=> Args
));
12510 -- First, prepends the _object argument
12513 Make_Attribute_Reference
(Loc
,
12515 Make_Selected_Component
(Loc
,
12516 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12517 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
12518 Attribute_Name
=> Name_Unchecked_Access
));
12520 -- Then, insert call to Install_Handlers
12523 Make_Procedure_Call_Statement
(Loc
,
12524 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
12525 Parameter_Associations
=> Args
));
12531 end Make_Initialize_Protection
;
12533 ---------------------------
12534 -- Make_Task_Create_Call --
12535 ---------------------------
12537 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
12538 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
12548 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
12549 Tnam
:= Chars
(Ttyp
);
12551 -- Get task declaration. In the case of a task type declaration, this is
12552 -- simply the parent of the task type entity. In the single task
12553 -- declaration, this parent will be the implicit type, and we can find
12554 -- the corresponding single task declaration by searching forward in the
12555 -- declaration list in the tree.
12557 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12558 -- this type should have been removed during semantic analysis.
12560 Tdec
:= Parent
(Ttyp
);
12561 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
12562 N_Single_Task_Declaration
)
12567 -- Now we can find the task definition from this declaration
12569 Tdef
:= Task_Definition
(Tdec
);
12571 -- Build the parameter list for the call. Note that _Init is the name
12572 -- of the formal for the object to be initialized, which is the task
12573 -- value record itself.
12577 -- Priority parameter. Set to Unspecified_Priority unless there is a
12578 -- priority pragma, in which case we take the value from the pragma.
12580 if Present
(Tdef
) and then Has_Pragma_Priority
(Tdef
) then
12582 Make_Selected_Component
(Loc
,
12583 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12584 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
12587 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
12590 -- Optional Stack parameter
12592 if Restricted_Profile
then
12594 -- If the stack has been preallocated by the expander then
12595 -- pass its address. Otherwise, pass a null address.
12597 if Preallocated_Stacks_On_Target
then
12599 Make_Attribute_Reference
(Loc
,
12600 Prefix
=> Make_Selected_Component
(Loc
,
12601 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12603 Make_Identifier
(Loc
, Name_uStack
)),
12604 Attribute_Name
=> Name_Address
));
12608 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
12612 -- Size parameter. If no Storage_Size pragma is present, then
12613 -- the size is taken from the taskZ variable for the type, which
12614 -- is either Unspecified_Size, or has been reset by the use of
12615 -- a Storage_Size attribute definition clause. If a pragma is
12616 -- present, then the size is taken from the _Size field of the
12617 -- task value record, which was set from the pragma value.
12620 and then Has_Storage_Size_Pragma
(Tdef
)
12623 Make_Selected_Component
(Loc
,
12624 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12625 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
12629 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
12632 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12633 -- Task_Info pragma, in which case we take the value from the pragma.
12636 and then Has_Task_Info_Pragma
(Tdef
)
12639 Make_Selected_Component
(Loc
,
12640 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12641 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
12645 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
12648 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12649 -- in which case we take the value from the pragma. The parameter is
12650 -- passed as an Integer because in the case of unspecified CPU the
12651 -- value is not in the range of CPU_Range.
12653 if Present
(Tdef
) and then Has_Pragma_CPU
(Tdef
) then
12655 Convert_To
(Standard_Integer
,
12656 Make_Selected_Component
(Loc
,
12657 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12658 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
12662 New_Reference_To
(RTE
(RE_Unspecified_CPU
), Loc
));
12665 if not Restricted_Profile
then
12667 -- Deadline parameter. If no Relative_Deadline pragma is present,
12668 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12669 -- the deadline is taken from the _Relative_Deadline field of the
12670 -- task value record, which was set from the pragma value. Note that
12671 -- this parameter must not be generated for the restricted profiles
12672 -- since Ravenscar does not allow deadlines.
12674 -- Case where pragma Relative_Deadline applies: use given value
12676 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
12678 Make_Selected_Component
(Loc
,
12679 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12681 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
12683 -- No pragma Relative_Deadline apply to the task
12687 New_Reference_To
(RTE
(RE_Time_Span_Zero
), Loc
));
12690 -- Number of entries. This is an expression of the form:
12692 -- n + _Init.a'Length + _Init.a'B'Length + ...
12694 -- where a,b... are the entry family names for the task definition
12697 Build_Entry_Count_Expression
12702 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
12704 Append_To
(Args
, Ecount
);
12706 -- Master parameter. This is a reference to the _Master parameter of
12707 -- the initialization procedure, except in the case of the pragma
12708 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12709 -- System.Tasking.Library_Task_Level.
12711 if Restriction_Active
(No_Task_Hierarchy
) = False then
12712 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
12715 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
12719 -- State parameter. This is a pointer to the task body procedure. The
12720 -- required value is obtained by taking 'Unrestricted_Access of the task
12721 -- body procedure and converting it (with an unchecked conversion) to
12722 -- the type required by the task kernel. For further details, see the
12723 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12724 -- than 'Address in order to avoid creating trampolines.
12727 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
12728 Subp_Ptr_Typ
: constant Node_Id
:=
12729 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
12730 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
12733 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
12734 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
12736 -- Be sure to freeze a reference to the access-to-subprogram type,
12737 -- otherwise gigi will complain that it's in the wrong scope, because
12738 -- it's actually inside the init procedure for the record type that
12739 -- corresponds to the task type.
12741 -- This processing is causing a crash in the .NET/JVM back ends that
12742 -- is not yet understood, so skip it in these cases ???
12744 if VM_Target
= No_VM
then
12745 Set_Itype
(Ref
, Subp_Ptr_Typ
);
12746 Append_Freeze_Action
(Task_Rec
, Ref
);
12749 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
12750 Make_Qualified_Expression
(Loc
,
12751 Subtype_Mark
=> New_Reference_To
(Subp_Ptr_Typ
, Loc
),
12753 Make_Attribute_Reference
(Loc
,
12755 New_Occurrence_Of
(Body_Proc
, Loc
),
12756 Attribute_Name
=> Name_Unrestricted_Access
))));
12758 -- For the .NET/JVM cases revert to the original code below ???
12762 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
12763 Make_Attribute_Reference
(Loc
,
12765 New_Occurrence_Of
(Body_Proc
, Loc
),
12766 Attribute_Name
=> Name_Address
)));
12770 -- Discriminants parameter. This is just the address of the task
12771 -- value record itself (which contains the discriminant values
12774 Make_Attribute_Reference
(Loc
,
12775 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12776 Attribute_Name
=> Name_Address
));
12778 -- Elaborated parameter. This is an access to the elaboration Boolean
12781 Make_Attribute_Reference
(Loc
,
12782 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
12783 Attribute_Name
=> Name_Unchecked_Access
));
12785 -- Chain parameter. This is a reference to the _Chain parameter of
12786 -- the initialization procedure.
12788 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
12790 -- Task name parameter. Take this from the _Task_Id parameter to the
12791 -- init call unless there is a Task_Name pragma, in which case we take
12792 -- the value from the pragma.
12795 and then Has_Task_Name_Pragma
(Tdef
)
12797 -- Copy expression in full, because it may be dynamic and have
12803 (Pragma_Argument_Associations
12804 (Find_Task_Or_Protected_Pragma
12805 (Tdef
, Name_Task_Name
))))));
12808 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
12811 -- Created_Task parameter. This is the _Task_Id field of the task
12815 Make_Selected_Component
(Loc
,
12816 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
12817 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
12819 -- Build_Entry_Names generation flag. When set to true, the runtime
12820 -- will allocate an array to hold the string names of task entries.
12822 if not Restricted_Profile
then
12823 if Has_Entries
(Ttyp
)
12824 and then Entry_Names_OK
12826 Append_To
(Args
, New_Reference_To
(Standard_True
, Loc
));
12828 Append_To
(Args
, New_Reference_To
(Standard_False
, Loc
));
12832 if Restricted_Profile
then
12833 Name
:= New_Reference_To
(RTE
(RE_Create_Restricted_Task
), Loc
);
12835 Name
:= New_Reference_To
(RTE
(RE_Create_Task
), Loc
);
12839 Make_Procedure_Call_Statement
(Loc
,
12841 Parameter_Associations
=> Args
);
12842 end Make_Task_Create_Call
;
12844 ------------------------------
12845 -- Next_Protected_Operation --
12846 ------------------------------
12848 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
12852 Next_Op
:= Next
(N
);
12853 while Present
(Next_Op
)
12854 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
12860 end Next_Protected_Operation
;
12862 ---------------------
12863 -- Null_Statements --
12864 ---------------------
12866 function Null_Statements
(Stats
: List_Id
) return Boolean is
12870 Stmt
:= First
(Stats
);
12871 while Nkind
(Stmt
) /= N_Empty
12872 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
12874 (Nkind
(Stmt
) = N_Pragma
12875 and then (Pragma_Name
(Stmt
) = Name_Unreferenced
12877 Pragma_Name
(Stmt
) = Name_Unmodified
12879 Pragma_Name
(Stmt
) = Name_Warnings
)))
12884 return Nkind
(Stmt
) = N_Empty
;
12885 end Null_Statements
;
12887 --------------------------
12888 -- Parameter_Block_Pack --
12889 --------------------------
12891 function Parameter_Block_Pack
12893 Blk_Typ
: Entity_Id
;
12897 Stmts
: List_Id
) return Node_Id
12899 Actual
: Entity_Id
;
12900 Expr
: Node_Id
:= Empty
;
12901 Formal
: Entity_Id
;
12902 Has_Param
: Boolean := False;
12905 Temp_Asn
: Node_Id
;
12906 Temp_Nam
: Node_Id
;
12909 Actual
:= First
(Actuals
);
12910 Formal
:= Defining_Identifier
(First
(Formals
));
12911 Params
:= New_List
;
12913 while Present
(Actual
) loop
12914 if Is_By_Copy_Type
(Etype
(Actual
)) then
12916 -- Jnn : aliased <formal-type>
12918 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
12921 Make_Object_Declaration
(Loc
,
12924 Defining_Identifier
=>
12926 Object_Definition
=>
12927 New_Reference_To
(Etype
(Formal
), Loc
)));
12929 if Ekind
(Formal
) /= E_Out_Parameter
then
12935 New_Reference_To
(Temp_Nam
, Loc
);
12937 Set_Assignment_OK
(Temp_Asn
);
12940 Make_Assignment_Statement
(Loc
,
12944 New_Copy_Tree
(Actual
)));
12948 -- Jnn'unchecked_access
12951 Make_Attribute_Reference
(Loc
,
12953 Name_Unchecked_Access
,
12955 New_Reference_To
(Temp_Nam
, Loc
)));
12959 -- The controlling parameter is omitted
12962 if not Is_Controlling_Actual
(Actual
) then
12964 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
12970 Next_Actual
(Actual
);
12971 Next_Formal_With_Extras
(Formal
);
12975 Expr
:= Make_Aggregate
(Loc
, Params
);
12980 -- J1'unchecked_access;
12981 -- <actual2>'reference;
12984 P
:= Make_Temporary
(Loc
, 'P');
12987 Make_Object_Declaration
(Loc
,
12988 Defining_Identifier
=>
12990 Object_Definition
=>
12991 New_Reference_To
(Blk_Typ
, Loc
),
12996 end Parameter_Block_Pack
;
12998 ----------------------------
12999 -- Parameter_Block_Unpack --
13000 ----------------------------
13002 function Parameter_Block_Unpack
13006 Formals
: List_Id
) return List_Id
13008 Actual
: Entity_Id
;
13010 Formal
: Entity_Id
;
13011 Has_Asnmt
: Boolean := False;
13012 Result
: constant List_Id
:= New_List
;
13015 Actual
:= First
(Actuals
);
13016 Formal
:= Defining_Identifier
(First
(Formals
));
13017 while Present
(Actual
) loop
13018 if Is_By_Copy_Type
(Etype
(Actual
))
13019 and then Ekind
(Formal
) /= E_In_Parameter
13022 -- <actual> := P.<formal>;
13025 Make_Assignment_Statement
(Loc
,
13029 Make_Explicit_Dereference
(Loc
,
13030 Make_Selected_Component
(Loc
,
13032 New_Reference_To
(P
, Loc
),
13034 Make_Identifier
(Loc
, Chars
(Formal
)))));
13036 Set_Assignment_OK
(Name
(Asnmt
));
13037 Append_To
(Result
, Asnmt
);
13042 Next_Actual
(Actual
);
13043 Next_Formal_With_Extras
(Formal
);
13049 return New_List
(Make_Null_Statement
(Loc
));
13051 end Parameter_Block_Unpack
;
13053 ----------------------
13054 -- Set_Discriminals --
13055 ----------------------
13057 procedure Set_Discriminals
(Dec
: Node_Id
) is
13060 D_Minal
: Entity_Id
;
13063 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
13064 Pdef
:= Defining_Identifier
(Dec
);
13066 if Has_Discriminants
(Pdef
) then
13067 D
:= First_Discriminant
(Pdef
);
13068 while Present
(D
) loop
13070 Make_Defining_Identifier
(Sloc
(D
),
13071 Chars
=> New_External_Name
(Chars
(D
), 'D'));
13073 Set_Ekind
(D_Minal
, E_Constant
);
13074 Set_Etype
(D_Minal
, Etype
(D
));
13075 Set_Scope
(D_Minal
, Pdef
);
13076 Set_Discriminal
(D
, D_Minal
);
13077 Set_Discriminal_Link
(D_Minal
, D
);
13079 Next_Discriminant
(D
);
13082 end Set_Discriminals
;
13084 -----------------------
13085 -- Trivial_Accept_OK --
13086 -----------------------
13088 function Trivial_Accept_OK
return Boolean is
13090 case Opt
.Task_Dispatching_Policy
is
13092 -- If we have the default task dispatching policy in effect, we can
13093 -- definitely do the optimization (one way of looking at this is to
13094 -- think of the formal definition of the default policy being allowed
13095 -- to run any task it likes after a rendezvous, so even if notionally
13096 -- a full rescheduling occurs, we can say that our dispatching policy
13097 -- (i.e. the default dispatching policy) reorders the queue to be the
13098 -- same as just before the call.
13103 -- FIFO_Within_Priorities certainly does not permit this
13104 -- optimization since the Rendezvous is a scheduling action that may
13105 -- require some other task to be run.
13110 -- For now, disallow the optimization for all other policies. This
13111 -- may be over-conservative, but it is certainly not incorrect.
13117 end Trivial_Accept_OK
;