1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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_Ch9
; use Sem_Ch9
;
55 with Sem_Ch11
; use Sem_Ch11
;
56 with Sem_Elab
; use Sem_Elab
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Util
; use Sem_Util
;
60 with Sinfo
; use Sinfo
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Stringt
; use Stringt
;
64 with Targparm
; use Targparm
;
65 with Tbuild
; use Tbuild
;
66 with Uintp
; use Uintp
;
68 package body Exp_Ch9
is
70 -- The following constant establishes the upper bound for the index of
71 -- an entry family. It is used to limit the allocated size of protected
72 -- types with defaulted discriminant of an integer type, when the bound
73 -- of some entry family depends on a discriminant. The limitation to entry
74 -- families of 128K should be reasonable in all cases, and is a documented
75 -- implementation restriction.
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_Dispatching_Tag_Check
141 N
: Node_Id
) return Node_Id
;
142 -- Utility to create the tree to check whether the dispatching call in
143 -- a timed entry call, a conditional entry call, or an asynchronous
144 -- transfer of control is a call to a primitive of a non-synchronized type.
145 -- K is the temporary that holds the tagged kind of the target object, and
146 -- N is the enclosing construct.
148 function Build_Entry_Count_Expression
149 (Concurrent_Type
: Node_Id
;
150 Component_List
: List_Id
;
151 Loc
: Source_Ptr
) return Node_Id
;
152 -- Compute number of entries for concurrent object. This is a count of
153 -- simple entries, followed by an expression that computes the length
154 -- of the range of each entry family. A single array with that size is
155 -- allocated for each concurrent object of the type.
157 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
158 -- Build the function that translates the entry index in the call
159 -- (which depends on the size of entry families) into an index into the
160 -- Entry_Bodies_Array, to determine the body and barrier function used
161 -- in a protected entry call. A pointer to this function appears in every
164 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
165 -- Build subprogram declaration for previous one
167 function Build_Lock_Free_Protected_Subprogram_Body
170 Unprot_Spec
: Node_Id
) return Node_Id
;
171 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
172 -- the subprogram specification of the unprotected version of N. Transform
173 -- N such that it invokes the unprotected version of the body.
175 function Build_Lock_Free_Unprotected_Subprogram_Body
177 Prot_Typ
: Node_Id
) return Node_Id
;
178 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
179 -- of N where the original statements of N are synchronized through atomic
180 -- actions such as compare and exchange. Prior to invoking this routine, it
181 -- has been established that N can be implemented in a lock-free fashion.
183 function Build_Parameter_Block
187 Decls
: List_Id
) return Entity_Id
;
188 -- Generate an access type for each actual parameter in the list Actuals.
189 -- Create an encapsulating record that contains all the actuals and return
190 -- its type. Generate:
191 -- type Ann1 is access all <actual1-type>
193 -- type AnnN is access all <actualN-type>
194 -- type Pnn is record
200 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
201 -- Build body of wrapper procedure for an entry or entry family that has
202 -- pre/postconditions. The body gathers the PPC's and expands them in the
203 -- usual way, and performs the entry call itself. This way preconditions
204 -- are evaluated before the call is queued. E is the entry in question,
205 -- and Decl is the enclosing synchronized type declaration at whose freeze
206 -- point the generated body is analyzed.
208 function Build_Protected_Entry
211 Pid
: Node_Id
) return Node_Id
;
212 -- Build the procedure implementing the statement sequence of the specified
215 function Build_Protected_Entry_Specification
218 Ent_Id
: Entity_Id
) return Node_Id
;
219 -- Build a specification for the procedure implementing the statements of
220 -- the specified entry body. Add attributes associating it with the entry
221 -- defining identifier Ent_Id.
223 function Build_Protected_Spec
225 Obj_Type
: Entity_Id
;
227 Unprotected
: Boolean := False) return List_Id
;
228 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
229 -- Subprogram_Type. Builds signature of protected subprogram, adding the
230 -- formal that corresponds to the object itself. For an access to protected
231 -- subprogram, there is no object type to specify, so the parameter has
232 -- type Address and mode In. An indirect call through such a pointer will
233 -- convert the address to a reference to the actual object. The object is
234 -- a limited record and therefore a by_reference type.
236 function Build_Protected_Subprogram_Body
239 N_Op_Spec
: Node_Id
) return Node_Id
;
240 -- This function is used to construct the protected version of a protected
241 -- subprogram. Its statement sequence first defers abort, then locks the
242 -- associated protected object, and then enters a block that contains a
243 -- call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires a
245 -- cleanup handler that unlocks the object in all cases. For details,
246 -- see Exp_Ch7.Expand_Cleanup_Actions.
248 function Build_Renamed_Formal_Declaration
252 Renamed_Formal
: Node_Id
) return Node_Id
;
253 -- Create a renaming declaration for a formal, within a protected entry
254 -- body or an accept body. The renamed object is a component of the
255 -- parameter block that is a parameter in the entry call.
257 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
258 -- does not dereference the corresponding component to prevent an illegal
259 -- use of the incomplete type (AI05-0151).
261 function Build_Selected_Name
263 Selector
: Entity_Id
;
264 Append_Char
: Character := ' ') return Name_Id
;
265 -- Build a name in the form of Prefix__Selector, with an optional character
266 -- appended. This is used for internal subprograms generated for operations
267 -- of protected types, including barrier functions. For the subprograms
268 -- generated for entry bodies and entry barriers, the generated name
269 -- includes a sequence number that makes names unique in the presence of
270 -- entry overloading. This is necessary because entry body procedures and
271 -- barrier functions all have the same signature.
273 procedure Build_Simple_Entry_Call
278 -- Some comments here would be useful ???
280 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
281 -- This routine constructs a specification for the procedure that we will
282 -- build for the task body for task type T. The spec has the form:
284 -- procedure tnameB (_Task : access tnameV);
286 -- where name is the character name taken from the task type entity that
287 -- is passed as the argument to the procedure, and tnameV is the task
288 -- value type that is associated with the task type.
290 function Build_Unprotected_Subprogram_Body
292 Pid
: Node_Id
) return Node_Id
;
293 -- This routine constructs the unprotected version of a protected
294 -- subprogram body, which is contains all of the code in the original,
295 -- unexpanded body. This is the version of the protected subprogram that is
296 -- called from all protected operations on the same object, including the
297 -- protected version of the same subprogram.
299 procedure Build_Wrapper_Bodies
303 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
304 -- record of a concurrent type. N is the insertion node where all bodies
305 -- will be placed. This routine builds the bodies of the subprograms which
306 -- serve as an indirection mechanism to overriding primitives of concurrent
307 -- types, entries and protected procedures. Any new body is analyzed.
309 procedure Build_Wrapper_Specs
313 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
314 -- record of a concurrent type. N is the insertion node where all specs
315 -- will be placed. This routine builds the specs of the subprograms which
316 -- serve as an indirection mechanism to overriding primitives of concurrent
317 -- types, entries and protected procedures. Any new spec is analyzed.
319 procedure Collect_Entry_Families
322 Current_Node
: in out Node_Id
;
323 Conctyp
: Entity_Id
);
324 -- For each entry family in a concurrent type, create an anonymous array
325 -- type of the right size, and add a component to the corresponding_record.
327 function Concurrent_Object
328 (Spec_Id
: Entity_Id
;
329 Conc_Typ
: Entity_Id
) return Entity_Id
;
330 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
331 -- the entity associated with the concurrent object in the Protected_Body_
332 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
333 -- denotes formal parameter _O, _object or _task.
335 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
336 -- Copy the result type of a function specification, when building the
337 -- internal operation corresponding to a protected function, or when
338 -- expanding an access to protected function. If the result is an anonymous
339 -- access to subprogram itself, we need to create a new signature with the
340 -- same parameter names and the same resolved types, but with new entities
343 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
344 -- Decls is a list which may contain the declarations created by Install_
345 -- Private_Data_Declarations. All generated entities are marked as needing
346 -- debug info and debug nodes are manually generation where necessary. This
347 -- step of the expansion must to be done after private data has been moved
348 -- to its final resting scope to ensure proper visibility of debug objects.
350 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
351 -- If control flow optimizations are suppressed, and Alt is an accept,
352 -- delay, or entry call alternative with no trailing statements, insert
353 -- a null trailing statement with the given Loc (which is the sloc of
354 -- the accept, delay, or entry call statement). There might not be any
355 -- generated code for the accept, delay, or entry call itself (the effect
356 -- of these statements is part of the general processsing done for the
357 -- enclosing selective accept, timed entry call, or asynchronous select),
358 -- and the null statement is there to carry the sloc of that statement to
359 -- the back-end for trace-based coverage analysis purposes.
361 procedure Extract_Dispatching_Call
363 Call_Ent
: out Entity_Id
;
364 Object
: out Entity_Id
;
365 Actuals
: out List_Id
;
366 Formals
: out List_Id
);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval
: out Node_Id
;
377 Index
: out Node_Id
);
378 -- Given an entry call, returns the associated concurrent object, the entry
379 -- name, and the entry family index.
381 function Family_Offset
386 Cap
: Boolean) return Node_Id
;
387 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
388 -- accept statement, or the upper bound in the discrete subtype of an entry
389 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
390 -- type of the entry. If Cap is true, the result is capped according to
391 -- Entry_Family_Bound.
398 Cap
: Boolean) return Node_Id
;
399 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
400 -- family, and handle properly the superflat case. This is equivalent to
401 -- the use of 'Length on the index type, but must use Family_Offset to
402 -- handle properly the case of bounds that depend on discriminants. If
403 -- Cap is true, the result is capped according to Entry_Family_Bound.
405 procedure Find_Enclosing_Context
407 Context
: out Node_Id
;
408 Context_Id
: out Entity_Id
;
409 Context_Decls
: out List_Id
);
410 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
411 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
412 -- nearest enclosing body, block, package or return statement and return
413 -- its constituents. Context is the enclosing construct, Context_Id is
414 -- the scope of Context_Id and Context_Decls is the declarative list of
417 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
418 -- Given a subprogram identifier, return the entity which is associated
419 -- with the protection entry index in the Protected_Body_Subprogram or
420 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
423 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
424 -- Tell whether a given subprogram cannot raise an exception
426 function Is_Potentially_Large_Family
427 (Base_Index
: Entity_Id
;
430 Hi
: Node_Id
) return Boolean;
432 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
433 -- Determine whether Id is a function or a procedure and is marked as a
434 -- private primitive.
436 function Null_Statements
(Stats
: List_Id
) return Boolean;
437 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
438 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
439 -- to still count as null. Returns True for a null sequence. The argument
440 -- is the list of statements from the DO-END sequence.
442 function Parameter_Block_Pack
448 Stmts
: List_Id
) return Entity_Id
;
449 -- Set the components of the generated parameter block with the values
450 -- of the actual parameters. Generate aliased temporaries to capture the
451 -- values for types that are passed by copy. Otherwise generate a reference
452 -- to the actual's value. Return the address of the aggregate block.
454 -- Jnn1 : alias <formal-type1>;
455 -- Jnn1 := <actual1>;
458 -- Jnn1'unchecked_access;
459 -- <actual2>'reference;
462 function Parameter_Block_Unpack
466 Formals
: List_Id
) return List_Id
;
467 -- Retrieve the values of the components from the parameter block and
468 -- assign then to the original actual parameters. Generate:
469 -- <actual1> := P.<formal1>;
471 -- <actualN> := P.<formalN>;
473 function Trivial_Accept_OK
return Boolean;
474 -- If there is no DO-END block for an accept, or if the DO-END block has
475 -- only null statements, then it is possible to do the Rendezvous with much
476 -- less overhead using the Accept_Trivial routine in the run-time library.
477 -- However, this is not always a valid optimization. Whether it is valid or
478 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
479 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
480 -- a rescheduling is required, so this optimization is not allowed. This
481 -- function returns True if the optimization is permitted.
483 -----------------------------
484 -- Actual_Index_Expression --
485 -----------------------------
487 function Actual_Index_Expression
491 Tsk
: Entity_Id
) return Node_Id
493 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
501 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
502 -- Compute difference between bounds of entry family
504 --------------------------
505 -- Actual_Family_Offset --
506 --------------------------
508 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
510 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
511 -- Replace a reference to a discriminant with a selected component
512 -- denoting the discriminant of the target task.
514 -----------------------------
515 -- Actual_Discriminant_Ref --
516 -----------------------------
518 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
519 Typ
: constant Entity_Id
:= Etype
(Bound
);
523 if not Is_Entity_Name
(Bound
)
524 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
526 if Nkind
(Bound
) = N_Attribute_Reference
then
529 B
:= New_Copy_Tree
(Bound
);
534 Make_Selected_Component
(Sloc
,
535 Prefix
=> New_Copy_Tree
(Tsk
),
536 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
538 Analyze_And_Resolve
(B
, Typ
);
542 Make_Attribute_Reference
(Sloc
,
543 Attribute_Name
=> Name_Pos
,
544 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
545 Expressions
=> New_List
(B
));
546 end Actual_Discriminant_Ref
;
548 -- Start of processing for Actual_Family_Offset
552 Make_Op_Subtract
(Sloc
,
553 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
554 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
555 end Actual_Family_Offset
;
557 -- Start of processing for Actual_Index_Expression
560 -- The queues of entries and entry families appear in textual order in
561 -- the associated record. The entry index is computed as the sum of the
562 -- number of queues for all entries that precede the designated one, to
563 -- which is added the index expression, if this expression denotes a
564 -- member of a family.
566 -- The following is a place holder for the count of simple entries
568 Num
:= Make_Integer_Literal
(Sloc
, 1);
570 -- We construct an expression which is a series of addition operations.
571 -- See comments in Entry_Index_Expression, which is identical in
574 if Present
(Index
) then
575 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
581 Actual_Family_Offset
(
582 Make_Attribute_Reference
(Sloc
,
583 Attribute_Name
=> Name_Pos
,
584 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
585 Expressions
=> New_List
(Relocate_Node
(Index
))),
586 Type_Low_Bound
(S
)));
591 -- Now add lengths of preceding entries and entry families
593 Prev
:= First_Entity
(Ttyp
);
594 while Chars
(Prev
) /= Chars
(Ent
)
595 or else (Ekind
(Prev
) /= Ekind
(Ent
))
596 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
598 if Ekind
(Prev
) = E_Entry
then
599 Set_Intval
(Num
, Intval
(Num
) + 1);
601 elsif Ekind
(Prev
) = E_Entry_Family
then
603 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
605 -- The need for the following full view retrieval stems from this
606 -- complex case of nested generics and tasking:
609 -- type Formal_Index is range <>;
612 -- type Index is private;
619 -- type Index is new Formal_Index range 1 .. 10;
622 -- package body Outer is
624 -- entry Fam (Index); -- (2)
627 -- package body Inner is -- (3)
635 -- We are currently building the index expression for the entry
636 -- call "T.E" (1). Part of the expansion must mention the range
637 -- of the discrete type "Index" (2) of entry family "Fam".
639 -- However only the private view of type "Index" is available to
640 -- the inner generic (3) because there was no prior mention of
641 -- the type inside "Inner". This visibility requirement is
642 -- implicit and cannot be detected during the construction of
643 -- the generic trees and needs special handling.
646 and then Is_Private_Type
(S
)
647 and then Present
(Full_View
(S
))
652 Lo
:= Type_Low_Bound
(S
);
653 Hi
:= Type_High_Bound
(S
);
660 Left_Opnd
=> Actual_Family_Offset
(Hi
, Lo
),
661 Right_Opnd
=> Make_Integer_Literal
(Sloc
, 1)));
663 -- Other components are anonymous types to be ignored
673 end Actual_Index_Expression
;
675 --------------------------
676 -- Add_Formal_Renamings --
677 --------------------------
679 procedure Add_Formal_Renamings
685 Ptr
: constant Entity_Id
:=
687 (Next
(First
(Parameter_Specifications
(Spec
))));
688 -- The name of the formal that holds the address of the parameter block
695 Renamed_Formal
: Node_Id
;
698 Formal
:= First_Formal
(Ent
);
699 while Present
(Formal
) loop
700 Comp
:= Entry_Component
(Formal
);
702 Make_Defining_Identifier
(Sloc
(Formal
),
703 Chars
=> Chars
(Formal
));
704 Set_Etype
(New_F
, Etype
(Formal
));
705 Set_Scope
(New_F
, Ent
);
707 -- Now we set debug info needed on New_F even though it does not come
708 -- from source, so that the debugger will get the right information
709 -- for these generated names.
711 Set_Debug_Info_Needed
(New_F
);
713 if Ekind
(Formal
) = E_In_Parameter
then
714 Set_Ekind
(New_F
, E_Constant
);
716 Set_Ekind
(New_F
, E_Variable
);
717 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
720 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
723 Make_Selected_Component
(Loc
,
725 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
726 Make_Identifier
(Loc
, Chars
(Ptr
))),
727 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
730 Build_Renamed_Formal_Declaration
731 (New_F
, Formal
, Comp
, Renamed_Formal
);
733 Append
(Decl
, Decls
);
734 Set_Renamed_Object
(Formal
, New_F
);
735 Next_Formal
(Formal
);
737 end Add_Formal_Renamings
;
739 ------------------------
740 -- Add_Object_Pointer --
741 ------------------------
743 procedure Add_Object_Pointer
745 Conc_Typ
: Entity_Id
;
748 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
753 -- Create the renaming declaration for the Protection object of a
754 -- protected type. _Object is used by Complete_Entry_Body.
755 -- ??? An attempt to make this a renaming was unsuccessful.
757 -- Build the entity for the access type
760 Make_Defining_Identifier
(Loc
,
761 New_External_Name
(Chars
(Rec_Typ
), 'P'));
764 -- _object : poVP := poVP!O;
767 Make_Object_Declaration
(Loc
,
768 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uObject
),
769 Object_Definition
=> New_Occurrence_Of
(Obj_Ptr
, Loc
),
771 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
772 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
773 Prepend_To
(Decls
, Decl
);
776 -- type poVP is access poV;
779 Make_Full_Type_Declaration
(Loc
,
780 Defining_Identifier
=>
783 Make_Access_To_Object_Definition
(Loc
,
784 Subtype_Indication
=>
785 New_Occurrence_Of
(Rec_Typ
, Loc
)));
786 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
787 Prepend_To
(Decls
, Decl
);
788 end Add_Object_Pointer
;
790 -----------------------
791 -- Build_Accept_Body --
792 -----------------------
794 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
795 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
796 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
803 -- At the end of the statement sequence, Complete_Rendezvous is called.
804 -- A label skipping the Complete_Rendezvous, and all other accept
805 -- processing, has already been added for the expansion of requeue
806 -- statements. The Sloc is copied from the last statement since it
807 -- is really part of this last statement.
811 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
812 Insert_Before
(Last
(Statements
(Stats
)), Call
);
815 -- If exception handlers are present, then append Complete_Rendezvous
816 -- calls to the handlers, and construct the required outer block. As
817 -- above, the Sloc is copied from the last statement in the sequence.
819 if Present
(Exception_Handlers
(Stats
)) then
820 Hand
:= First
(Exception_Handlers
(Stats
));
821 while Present
(Hand
) loop
824 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
825 Append
(Call
, Statements
(Hand
));
831 Make_Handled_Sequence_Of_Statements
(Loc
,
832 Statements
=> New_List
(
833 Make_Block_Statement
(Loc
,
834 Handled_Statement_Sequence
=> Stats
)));
840 -- At this stage we know that the new statement sequence does
841 -- not have an exception handler part, so we supply one to call
842 -- Exceptional_Complete_Rendezvous. This handler is
844 -- when all others =>
845 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
847 -- We handle Abort_Signal to make sure that we properly catch the abort
848 -- case and wake up the caller.
850 Ohandle
:= Make_Others_Choice
(Loc
);
851 Set_All_Others
(Ohandle
);
853 Set_Exception_Handlers
(New_S
,
855 Make_Implicit_Exception_Handler
(Loc
,
856 Exception_Choices
=> New_List
(Ohandle
),
858 Statements
=> New_List
(
859 Make_Procedure_Call_Statement
(Sloc
(Stats
),
860 Name
=> New_Occurrence_Of
(
861 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
862 Parameter_Associations
=> New_List
(
863 Make_Function_Call
(Sloc
(Stats
),
866 (RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
868 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
869 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
870 Expand_Exception_Handlers
(New_S
);
872 -- Exceptional_Complete_Rendezvous must be called with abort still
873 -- deferred, which is the case for a "when all others" handler.
876 end Build_Accept_Body
;
878 -----------------------------------
879 -- Build_Activation_Chain_Entity --
880 -----------------------------------
882 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
883 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
884 -- Determine whether an extended return statement has activation chain
886 --------------------------
887 -- Has_Activation_Chain --
888 --------------------------
890 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
894 Decl
:= First
(Return_Object_Declarations
(Stmt
));
895 while Present
(Decl
) loop
896 if Nkind
(Decl
) = N_Object_Declaration
897 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
906 end Has_Activation_Chain
;
911 Context_Id
: Entity_Id
;
914 -- Start of processing for Build_Activation_Chain_Entity
917 -- Activation chain is never used for sequential elaboration policy, see
918 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
920 if Partition_Elaboration_Policy
= 'S' then
924 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
926 -- If activation chain entity has not been declared already, create one
928 if Nkind
(Context
) = N_Extended_Return_Statement
929 or else No
(Activation_Chain_Entity
(Context
))
931 -- Since extended return statements do not store the entity of the
932 -- chain, examine the return object declarations to avoid creating
935 if Nkind
(Context
) = N_Extended_Return_Statement
936 and then Has_Activation_Chain
(Context
)
942 Loc
: constant Source_Ptr
:= Sloc
(Context
);
947 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
949 -- Note: An extended return statement is not really a task
950 -- activator, but it does have an activation chain on which to
951 -- store the tasks temporarily. On successful return, the tasks
952 -- on this chain are moved to the chain passed in by the caller.
953 -- We do not build an Activation_Chain_Entity for an extended
954 -- return statement, because we do not want to build a call to
955 -- Activate_Tasks. Task activation is the responsibility of the
958 if Nkind
(Context
) /= N_Extended_Return_Statement
then
959 Set_Activation_Chain_Entity
(Context
, Chain
);
963 Make_Object_Declaration
(Loc
,
964 Defining_Identifier
=> Chain
,
965 Aliased_Present
=> True,
967 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
));
969 Prepend_To
(Decls
, Decl
);
971 -- Ensure that _chain appears in the proper scope of the context
973 if Context_Id
/= Current_Scope
then
974 Push_Scope
(Context_Id
);
982 end Build_Activation_Chain_Entity
;
984 ----------------------------
985 -- Build_Barrier_Function --
986 ----------------------------
988 function Build_Barrier_Function
991 Pid
: Node_Id
) return Node_Id
993 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
994 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
995 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
996 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
997 Op_Decls
: constant List_Id
:= New_List
;
1002 -- Add a declaration for the Protection object, renaming declarations
1003 -- for the discriminals and privals and finally a declaration for the
1004 -- entry family index (if applicable).
1006 Install_Private_Data_Declarations
(Sloc
(N
),
1012 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1014 -- If compiling with -fpreserve-control-flow, make sure we insert an
1015 -- IF statement so that the back-end knows to generate a conditional
1016 -- branch instruction, even if the condition is just the name of a
1017 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1018 -- such redundant IF statements under -fpreserve-control-flow
1019 -- (whether coming from this routine, or directly from source).
1021 if Opt
.Suppress_Control_Flow_Optimizations
then
1022 Stmt
:= Make_Implicit_If_Statement
(Cond
,
1024 Then_Statements
=> New_List
(
1025 Make_Simple_Return_Statement
(Loc
,
1026 New_Occurrence_Of
(Standard_True
, Loc
))),
1027 Else_Statements
=> New_List
(
1028 Make_Simple_Return_Statement
(Loc
,
1029 New_Occurrence_Of
(Standard_False
, Loc
))));
1032 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1035 -- Note: the condition in the barrier function needs to be properly
1036 -- processed for the C/Fortran boolean possibility, but this happens
1037 -- automatically since the return statement does this normalization.
1040 Make_Subprogram_Body
(Loc
,
1042 Build_Barrier_Function_Specification
(Loc
,
1043 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1044 Declarations
=> Op_Decls
,
1045 Handled_Statement_Sequence
=>
1046 Make_Handled_Sequence_Of_Statements
(Loc
,
1047 Statements
=> New_List
(Stmt
)));
1048 Set_Is_Entry_Barrier_Function
(Func_Body
);
1051 end Build_Barrier_Function
;
1053 ------------------------------------------
1054 -- Build_Barrier_Function_Specification --
1055 ------------------------------------------
1057 function Build_Barrier_Function_Specification
1059 Def_Id
: Entity_Id
) return Node_Id
1062 Set_Debug_Info_Needed
(Def_Id
);
1064 return Make_Function_Specification
(Loc
,
1065 Defining_Unit_Name
=> Def_Id
,
1066 Parameter_Specifications
=> New_List
(
1067 Make_Parameter_Specification
(Loc
,
1068 Defining_Identifier
=>
1069 Make_Defining_Identifier
(Loc
, Name_uO
),
1071 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
1073 Make_Parameter_Specification
(Loc
,
1074 Defining_Identifier
=>
1075 Make_Defining_Identifier
(Loc
, Name_uE
),
1077 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1079 Result_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
1080 end Build_Barrier_Function_Specification
;
1082 --------------------------
1083 -- Build_Call_With_Task --
1084 --------------------------
1086 function Build_Call_With_Task
1088 E
: Entity_Id
) return Node_Id
1090 Loc
: constant Source_Ptr
:= Sloc
(N
);
1093 Make_Function_Call
(Loc
,
1094 Name
=> New_Occurrence_Of
(E
, Loc
),
1095 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1096 end Build_Call_With_Task
;
1098 -----------------------------
1099 -- Build_Class_Wide_Master --
1100 -----------------------------
1102 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1103 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1104 Master_Id
: Entity_Id
;
1105 Master_Scope
: Entity_Id
;
1107 Related_Node
: Node_Id
;
1111 -- Nothing to do if there is no task hierarchy
1113 if Restriction_Active
(No_Task_Hierarchy
) then
1117 -- Find the declaration that created the access type, which is either a
1118 -- type declaration, or an object declaration with an access definition,
1119 -- in which case the type is anonymous.
1121 if Is_Itype
(Typ
) then
1122 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1124 Related_Node
:= Parent
(Typ
);
1127 Master_Scope
:= Find_Master_Scope
(Typ
);
1129 -- Nothing to do if the master scope already contains a _master entity.
1130 -- The only exception to this is the following scenario:
1133 -- Transient_Scope_1
1136 -- Transient_Scope_2
1139 -- In this case the source scope is marked as having the master entity
1140 -- even though the actual declaration appears inside an inner scope. If
1141 -- the second transient scope requires a _master, it cannot use the one
1142 -- already declared because the entity is not visible.
1144 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1146 if not Has_Master_Entity
(Master_Scope
)
1147 or else No
(Current_Entity_In_Scope
(Name_Id
))
1150 Master_Decl
: Node_Id
;
1152 Set_Has_Master_Entity
(Master_Scope
);
1155 -- _master : constant Integer := Current_Master.all;
1158 Make_Object_Declaration
(Loc
,
1159 Defining_Identifier
=>
1160 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1161 Constant_Present
=> True,
1162 Object_Definition
=>
1163 New_Occurrence_Of
(Standard_Integer
, Loc
),
1165 Make_Explicit_Dereference
(Loc
,
1166 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
1168 Insert_Action
(Find_Hook_Context
(Related_Node
), Master_Decl
);
1169 Analyze
(Master_Decl
);
1171 -- Mark the containing scope as a task master. Masters associated
1172 -- with return statements are already marked at this stage (see
1173 -- Analyze_Subprogram_Body).
1175 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1177 Par
: Node_Id
:= Related_Node
;
1180 while Nkind
(Par
) /= N_Compilation_Unit
loop
1181 Par
:= Parent
(Par
);
1183 -- If we fall off the top, we are at the outer level,
1184 -- and the environment task is our effective master,
1185 -- so nothing to mark.
1187 if Nkind_In
(Par
, N_Block_Statement
,
1191 Set_Is_Task_Master
(Par
);
1201 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(Typ
), 'M'));
1204 -- typeMnn renames _master;
1207 Make_Object_Renaming_Declaration
(Loc
,
1208 Defining_Identifier
=> Master_Id
,
1209 Subtype_Mark
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1212 Insert_Action
(Related_Node
, Ren_Decl
);
1214 Set_Master_Id
(Typ
, Master_Id
);
1215 end Build_Class_Wide_Master
;
1217 --------------------------------
1218 -- Build_Corresponding_Record --
1219 --------------------------------
1221 function Build_Corresponding_Record
1224 Loc
: Source_Ptr
) return Node_Id
1226 Rec_Ent
: constant Entity_Id
:=
1227 Make_Defining_Identifier
1228 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1231 New_Disc
: Entity_Id
;
1235 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1236 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1237 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1238 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1239 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1240 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1243 -- Use discriminals to create list of discriminants for record, and
1244 -- create new discriminals for use in default expressions, etc. It is
1245 -- worth noting that a task discriminant gives rise to 5 entities;
1247 -- a) The original discriminant.
1248 -- b) The discriminal for use in the task.
1249 -- c) The discriminant of the corresponding record.
1250 -- d) The discriminal for the init proc of the corresponding record.
1251 -- e) The local variable that renames the discriminant in the procedure
1252 -- for the task body.
1254 -- In fact the discriminals b) are used in the renaming declarations
1255 -- for e). See details in einfo (Handling of Discriminants).
1257 if Present
(Discriminant_Specifications
(N
)) then
1259 Disc
:= First_Discriminant
(Ctyp
);
1261 while Present
(Disc
) loop
1262 New_Disc
:= CR_Discriminant
(Disc
);
1265 Make_Discriminant_Specification
(Loc
,
1266 Defining_Identifier
=> New_Disc
,
1267 Discriminant_Type
=>
1268 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1270 New_Copy
(Discriminant_Default_Value
(Disc
))));
1272 Next_Discriminant
(Disc
);
1279 -- Now we can construct the record type declaration. Note that this
1280 -- record is "limited tagged". It is "limited" to reflect the underlying
1281 -- limitedness of the task or protected object that it represents, and
1282 -- ensuring for example that it is properly passed by reference. It is
1283 -- "tagged" to give support to dispatching calls through interfaces. We
1284 -- propagate here the list of interfaces covered by the concurrent type
1285 -- (Ada 2005: AI-345).
1288 Make_Full_Type_Declaration
(Loc
,
1289 Defining_Identifier
=> Rec_Ent
,
1290 Discriminant_Specifications
=> Dlist
,
1292 Make_Record_Definition
(Loc
,
1294 Make_Component_List
(Loc
, Component_Items
=> Cdecls
),
1296 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1297 Interface_List
=> Interface_List
(N
),
1298 Limited_Present
=> True));
1299 end Build_Corresponding_Record
;
1301 ---------------------------------
1302 -- Build_Dispatching_Tag_Check --
1303 ---------------------------------
1305 function Build_Dispatching_Tag_Check
1307 N
: Node_Id
) return Node_Id
1309 Loc
: constant Source_Ptr
:= Sloc
(N
);
1316 New_Occurrence_Of
(K
, Loc
),
1318 New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1322 New_Occurrence_Of
(K
, Loc
),
1324 New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
)));
1325 end Build_Dispatching_Tag_Check
;
1327 ----------------------------------
1328 -- Build_Entry_Count_Expression --
1329 ----------------------------------
1331 function Build_Entry_Count_Expression
1332 (Concurrent_Type
: Node_Id
;
1333 Component_List
: List_Id
;
1334 Loc
: Source_Ptr
) return Node_Id
1346 -- Count number of non-family entries
1349 Ent
:= First_Entity
(Concurrent_Type
);
1350 while Present
(Ent
) loop
1351 if Ekind
(Ent
) = E_Entry
then
1358 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1360 -- Loop through entry families building the addition nodes
1362 Ent
:= First_Entity
(Concurrent_Type
);
1363 Comp
:= First
(Component_List
);
1364 while Present
(Ent
) loop
1365 if Ekind
(Ent
) = E_Entry_Family
then
1366 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1370 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1371 Hi
:= Type_High_Bound
(Typ
);
1372 Lo
:= Type_Low_Bound
(Typ
);
1373 Large
:= Is_Potentially_Large_Family
1374 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1377 Left_Opnd
=> Ecount
,
1379 Family_Size
(Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1386 end Build_Entry_Count_Expression
;
1388 -----------------------
1389 -- Build_Entry_Names --
1390 -----------------------
1392 procedure Build_Entry_Names
1394 Obj_Typ
: Entity_Id
;
1397 Loc
: constant Source_Ptr
:= Sloc
(Obj_Ref
);
1398 Data
: Entity_Id
:= Empty
;
1399 Index
: Entity_Id
:= Empty
;
1400 Typ
: Entity_Id
:= Obj_Typ
;
1402 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
);
1403 -- Given an entry [family], create a static string which denotes the
1404 -- name of Comp_Id and assign it to the underlying data structure which
1405 -- contains the entry names of a concurrent object.
1407 function Object_Reference
return Node_Id
;
1408 -- Return a reference to field _object or _task_id depending on the
1409 -- concurrent object being processed.
1411 ----------------------
1412 -- Build_Entry_Name --
1413 ----------------------
1415 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
) is
1416 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1417 -- Given a discrete subtype definition of an entry family, generate a
1418 -- range node which covers the range of Def's type.
1420 procedure Create_Index_And_Data
;
1421 -- Generate the declarations of variables Index and Data. Subsequent
1422 -- calls do nothing.
1424 function Increment_Index
return Node_Id
;
1425 -- Increment the index used in the assignment of string names to the
1428 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
;
1429 -- Given the name of a temporary variable, create the following
1430 -- declaration for it:
1432 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1434 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
;
1435 -- Given the name of a temporary variable, place it in the array of
1436 -- string names. Generate:
1438 -- Data (Index) := Def_Id'Unchecked_Access;
1444 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1445 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1446 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1449 -- If a bound references a discriminant, generate an identifier
1450 -- with the same name. Resolution will map it to the formals of
1453 if Is_Entity_Name
(Low
)
1454 and then Ekind
(Entity
(Low
)) = E_Discriminant
1457 Make_Selected_Component
(Loc
,
1458 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1459 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Low
)));
1461 Low
:= New_Copy_Tree
(Low
);
1464 if Is_Entity_Name
(High
)
1465 and then Ekind
(Entity
(High
)) = E_Discriminant
1468 Make_Selected_Component
(Loc
,
1469 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1470 Selector_Name
=> Make_Identifier
(Loc
, Chars
(High
)));
1472 High
:= New_Copy_Tree
(High
);
1478 High_Bound
=> High
);
1481 ---------------------------
1482 -- Create_Index_And_Data --
1483 ---------------------------
1485 procedure Create_Index_And_Data
is
1487 if No
(Index
) and then No
(Data
) then
1494 if Is_Protected_Type
(Typ
) then
1495 Count
:= RO_PE_Number_Of_Entries
;
1496 Data_Typ
:= RE_Protected_Entry_Names_Array
;
1498 Count
:= RO_ST_Number_Of_Entries
;
1499 Data_Typ
:= RE_Task_Entry_Names_Array
;
1502 -- Step 1: Generate the declaration of the index variable:
1504 -- Index : Entry_Index := 1;
1506 Index
:= Make_Temporary
(Loc
, 'I');
1509 Make_Object_Declaration
(Loc
,
1510 Defining_Identifier
=> Index
,
1511 Object_Definition
=>
1512 New_Occurrence_Of
(RTE
(RE_Entry_Index
), Loc
),
1513 Expression
=> Make_Integer_Literal
(Loc
, 1)));
1515 -- Step 2: Generate the declaration of an array to house all
1518 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1519 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1521 Size
:= Make_Temporary
(Loc
, 'S');
1524 Make_Object_Declaration
(Loc
,
1525 Defining_Identifier
=> Size
,
1526 Constant_Present
=> True,
1527 Object_Definition
=>
1528 New_Occurrence_Of
(RTE
(RE_Entry_Index
), Loc
),
1530 Make_Function_Call
(Loc
,
1532 New_Occurrence_Of
(RTE
(Count
), Loc
),
1533 Parameter_Associations
=>
1534 New_List
(Object_Reference
))));
1536 Data
:= Make_Temporary
(Loc
, 'A');
1539 Make_Object_Declaration
(Loc
,
1540 Defining_Identifier
=> Data
,
1541 Aliased_Present
=> True,
1542 Object_Definition
=>
1543 New_Occurrence_Of
(RTE
(Data_Typ
), Loc
),
1545 Make_Aggregate
(Loc
,
1546 Component_Associations
=> New_List
(
1547 Make_Component_Association
(Loc
,
1548 Choices
=> New_List
(
1551 Make_Integer_Literal
(Loc
, 1),
1553 New_Occurrence_Of
(Size
, Loc
))),
1554 Expression
=> Make_Null
(Loc
))))));
1557 end Create_Index_And_Data
;
1559 ---------------------
1560 -- Increment_Index --
1561 ---------------------
1563 function Increment_Index
return Node_Id
is
1566 Make_Assignment_Statement
(Loc
,
1567 Name
=> New_Occurrence_Of
(Index
, Loc
),
1570 Left_Opnd
=> New_Occurrence_Of
(Index
, Loc
),
1571 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
1572 end Increment_Index
;
1574 ----------------------
1575 -- Name_Declaration --
1576 ----------------------
1578 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
is
1581 Make_Object_Declaration
(Loc
,
1582 Defining_Identifier
=> Def_Id
,
1583 Aliased_Present
=> True,
1584 Constant_Present
=> True,
1585 Object_Definition
=>
1586 New_Occurrence_Of
(Standard_String
, Loc
),
1588 Make_String_Literal
(Loc
, String_From_Name_Buffer
));
1589 end Name_Declaration
;
1591 --------------------
1592 -- Set_Entry_Name --
1593 --------------------
1595 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
is
1598 Make_Assignment_Statement
(Loc
,
1600 Make_Indexed_Component
(Loc
,
1601 Prefix
=> New_Occurrence_Of
(Data
, Loc
),
1602 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
))),
1605 Make_Attribute_Reference
(Loc
,
1606 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
1607 Attribute_Name
=> Name_Unchecked_Access
));
1612 Temp_Id
: Entity_Id
;
1615 -- Start of processing for Build_Entry_Name
1618 if Ekind
(Comp_Id
) = E_Entry_Family
then
1619 Subt_Def
:= Discrete_Subtype_Definition
(Parent
(Comp_Id
));
1621 Create_Index_And_Data
;
1623 -- Step 1: Create the string name of the entry family.
1625 -- Temp : aliased constant String := "name ()";
1627 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1628 Get_Name_String
(Chars
(Comp_Id
));
1629 Add_Char_To_Name_Buffer
(' ');
1630 Add_Char_To_Name_Buffer
('(');
1631 Add_Char_To_Name_Buffer
(')');
1633 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1636 -- for Member in Family_Low .. Family_High loop
1637 -- Set_Entry_Name (...);
1638 -- Index := Index + 1;
1642 Make_Loop_Statement
(Loc
,
1644 Make_Iteration_Scheme
(Loc
,
1645 Loop_Parameter_Specification
=>
1646 Make_Loop_Parameter_Specification
(Loc
,
1647 Defining_Identifier
=>
1648 Make_Temporary
(Loc
, 'L'),
1649 Discrete_Subtype_Definition
=>
1650 Build_Range
(Subt_Def
))),
1652 Statements
=> New_List
(
1653 Set_Entry_Name
(Temp_Id
),
1655 End_Label
=> Empty
));
1660 Create_Index_And_Data
;
1662 -- Step 1: Create the string name of the entry. Generate:
1663 -- Temp : aliased constant String := "name";
1665 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1666 Get_Name_String
(Chars
(Comp_Id
));
1668 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1670 -- Step 2: Associate the string name with the underlying data
1673 Append_To
(Stmts
, Set_Entry_Name
(Temp_Id
));
1674 Append_To
(Stmts
, Increment_Index
);
1676 end Build_Entry_Name
;
1678 ----------------------
1679 -- Object_Reference --
1680 ----------------------
1682 function Object_Reference
return Node_Id
is
1683 Conc_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Typ
);
1688 if Is_Protected_Type
(Typ
) then
1689 Field
:= Name_uObject
;
1691 Field
:= Name_uTask_Id
;
1695 Make_Selected_Component
(Loc
,
1697 Unchecked_Convert_To
(Conc_Typ
, New_Copy_Tree
(Obj_Ref
)),
1698 Selector_Name
=> Make_Identifier
(Loc
, Field
));
1700 if Is_Protected_Type
(Typ
) then
1702 Make_Attribute_Reference
(Loc
,
1704 Attribute_Name
=> Name_Unchecked_Access
);
1708 end Object_Reference
;
1715 -- Start of processing for Build_Entry_Names
1718 -- Retrieve the original concurrent type
1720 if Is_Concurrent_Record_Type
(Typ
) then
1721 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1724 pragma Assert
(Is_Concurrent_Type
(Typ
));
1726 -- Nothing to do if the type has no entries
1728 if not Has_Entries
(Typ
) then
1732 -- Avoid generating entry names for a protected type with only one entry
1734 if Is_Protected_Type
(Typ
)
1735 and then Find_Protection_Type
(Base_Type
(Typ
)) /=
1736 RTE
(RE_Protection_Entries
)
1741 -- Step 1: Populate the array with statically generated strings denoting
1742 -- entries and entry family names.
1744 Comp
:= First_Entity
(Typ
);
1745 while Present
(Comp
) loop
1746 if Comes_From_Source
(Comp
)
1747 and then Ekind_In
(Comp
, E_Entry
, E_Entry_Family
)
1749 Build_Entry_Name
(Comp
);
1755 -- Step 2: Associate the array with the related concurrent object:
1757 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1759 if Present
(Data
) then
1760 if Is_Protected_Type
(Typ
) then
1761 Proc
:= RO_PE_Set_Entry_Names
;
1763 Proc
:= RO_ST_Set_Entry_Names
;
1767 Make_Procedure_Call_Statement
(Loc
,
1768 Name
=> New_Occurrence_Of
(RTE
(Proc
), Loc
),
1769 Parameter_Associations
=> New_List
(
1771 Make_Attribute_Reference
(Loc
,
1772 Prefix
=> New_Occurrence_Of
(Data
, Loc
),
1773 Attribute_Name
=> Name_Unchecked_Access
))));
1775 end Build_Entry_Names
;
1777 ---------------------------
1778 -- Build_Parameter_Block --
1779 ---------------------------
1781 function Build_Parameter_Block
1785 Decls
: List_Id
) return Entity_Id
1791 Has_Comp
: Boolean := False;
1795 Actual
:= First
(Actuals
);
1797 Formal
:= Defining_Identifier
(First
(Formals
));
1799 while Present
(Actual
) loop
1800 if not Is_Controlling_Actual
(Actual
) then
1803 -- type Ann is access all <actual-type>
1805 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1808 Make_Full_Type_Declaration
(Loc
,
1809 Defining_Identifier
=> Comp_Nam
,
1811 Make_Access_To_Object_Definition
(Loc
,
1812 All_Present
=> True,
1813 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1814 Subtype_Indication
=>
1815 New_Occurrence_Of
(Etype
(Actual
), Loc
))));
1821 Make_Component_Declaration
(Loc
,
1822 Defining_Identifier
=>
1823 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1824 Component_Definition
=>
1825 Make_Component_Definition
(Loc
,
1828 Subtype_Indication
=>
1829 New_Occurrence_Of
(Comp_Nam
, Loc
))));
1834 Next_Actual
(Actual
);
1835 Next_Formal_With_Extras
(Formal
);
1838 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1843 -- type Pnn is record
1848 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1849 -- the original parameter names and Ann1 .. AnnN are the access to
1853 Make_Full_Type_Declaration
(Loc
,
1854 Defining_Identifier
=>
1857 Make_Record_Definition
(Loc
,
1859 Make_Component_List
(Loc
, Comps
))));
1862 -- type Pnn is null record;
1865 Make_Full_Type_Declaration
(Loc
,
1866 Defining_Identifier
=>
1869 Make_Record_Definition
(Loc
,
1870 Null_Present
=> True,
1871 Component_List
=> Empty
)));
1875 end Build_Parameter_Block
;
1877 --------------------------------------
1878 -- Build_Renamed_Formal_Declaration --
1879 --------------------------------------
1881 function Build_Renamed_Formal_Declaration
1885 Renamed_Formal
: Node_Id
) return Node_Id
1887 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1891 -- If the formal is a tagged incomplete type, it is already passed
1892 -- by reference, so it is sufficient to rename the pointer component
1893 -- that corresponds to the actual. Otherwise we need to dereference
1894 -- the pointer component to obtain the actual.
1896 if Is_Incomplete_Type
(Etype
(Formal
))
1897 and then Is_Tagged_Type
(Etype
(Formal
))
1900 Make_Object_Renaming_Declaration
(Loc
,
1901 Defining_Identifier
=> New_F
,
1902 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Comp
), Loc
),
1903 Name
=> Renamed_Formal
);
1907 Make_Object_Renaming_Declaration
(Loc
,
1908 Defining_Identifier
=> New_F
,
1909 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Formal
), Loc
),
1911 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1915 end Build_Renamed_Formal_Declaration
;
1917 -----------------------
1918 -- Build_PPC_Wrapper --
1919 -----------------------
1921 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1922 Loc
: constant Source_Ptr
:= Sloc
(E
);
1923 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1925 Wrapper_Id
: constant Entity_Id
:=
1926 Make_Defining_Identifier
(Loc
,
1927 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1928 -- the wrapper procedure name
1930 Wrapper_Body
: Node_Id
;
1932 Synch_Id
: constant Entity_Id
:=
1933 Make_Defining_Identifier
(Loc
,
1934 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1935 -- The parameter that designates the synchronized object in the call
1937 Actuals
: constant List_Id
:= New_List
;
1938 -- The actuals in the entry call
1940 Decls
: constant List_Id
:= New_List
;
1942 Entry_Call
: Node_Id
;
1943 Entry_Name
: Node_Id
;
1946 -- The specification of the wrapper procedure
1950 -- Only build the wrapper if entry has pre/postconditions.
1951 -- Should this be done unconditionally instead ???
1957 P
:= Pre_Post_Conditions
(Contract
(E
));
1963 -- Transfer ppc pragmas to the declarations of the wrapper
1965 while Present
(P
) loop
1966 if Nam_In
(Pragma_Name
(P
), Name_Precondition
,
1969 Append
(Relocate_Node
(P
), Decls
);
1970 Set_Analyzed
(Last
(Decls
), False);
1973 P
:= Next_Pragma
(P
);
1977 -- First formal is synchronized object
1980 Make_Parameter_Specification
(Loc
,
1981 Defining_Identifier
=> Synch_Id
,
1982 Out_Present
=> True,
1984 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1987 Make_Selected_Component
(Loc
,
1988 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1989 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1991 -- If entity is entry family, second formal is the corresponding index,
1992 -- and entry name is an indexed component.
1994 if Ekind
(E
) = E_Entry_Family
then
1996 Index
: constant Entity_Id
:=
1997 Make_Defining_Identifier
(Loc
, Name_I
);
2000 Make_Parameter_Specification
(Loc
,
2001 Defining_Identifier
=> Index
,
2003 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
2006 Make_Indexed_Component
(Loc
,
2007 Prefix
=> Entry_Name
,
2008 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
2013 Make_Procedure_Call_Statement
(Loc
,
2015 Parameter_Associations
=> Actuals
);
2017 -- Now add formals that match those of the entry, and build actuals for
2018 -- the nested entry call.
2022 New_Form
: Entity_Id
;
2023 Parm_Spec
: Node_Id
;
2026 Form
:= First_Formal
(E
);
2027 while Present
(Form
) loop
2028 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
2030 Make_Parameter_Specification
(Loc
,
2031 Defining_Identifier
=> New_Form
,
2032 Out_Present
=> Out_Present
(Parent
(Form
)),
2033 In_Present
=> In_Present
(Parent
(Form
)),
2034 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
2036 Append
(Parm_Spec
, Specs
);
2037 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
2042 -- Add renaming declarations for the discriminants of the enclosing
2043 -- type, which may be visible in the preconditions.
2045 if Has_Discriminants
(Synch_Type
) then
2051 D
:= First_Discriminant
(Synch_Type
);
2052 while Present
(D
) loop
2054 Make_Object_Renaming_Declaration
(Loc
,
2055 Defining_Identifier
=>
2056 Make_Defining_Identifier
(Loc
, Chars
(D
)),
2057 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
2059 Make_Selected_Component
(Loc
,
2060 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
2061 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
2062 Prepend
(Decl
, Decls
);
2063 Next_Discriminant
(D
);
2068 Set_PPC_Wrapper
(E
, Wrapper_Id
);
2070 Make_Subprogram_Body
(Loc
,
2072 Make_Procedure_Specification
(Loc
,
2073 Defining_Unit_Name
=> Wrapper_Id
,
2074 Parameter_Specifications
=> Specs
),
2075 Declarations
=> Decls
,
2076 Handled_Statement_Sequence
=>
2077 Make_Handled_Sequence_Of_Statements
(Loc
,
2078 Statements
=> New_List
(Entry_Call
)));
2080 -- The wrapper body is analyzed when the enclosing type is frozen
2082 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
2083 end Build_PPC_Wrapper
;
2085 --------------------------
2086 -- Build_Wrapper_Bodies --
2087 --------------------------
2089 procedure Build_Wrapper_Bodies
2094 Rec_Typ
: Entity_Id
;
2096 function Build_Wrapper_Body
2098 Subp_Id
: Entity_Id
;
2099 Obj_Typ
: Entity_Id
;
2100 Formals
: List_Id
) return Node_Id
;
2101 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2102 -- associated with a protected or task type. Subp_Id is the subprogram
2103 -- name which will be wrapped. Obj_Typ is the type of the new formal
2104 -- parameter which handles dispatching and object notation. Formals are
2105 -- the original formals of Subp_Id which will be explicitly replicated.
2107 ------------------------
2108 -- Build_Wrapper_Body --
2109 ------------------------
2111 function Build_Wrapper_Body
2113 Subp_Id
: Entity_Id
;
2114 Obj_Typ
: Entity_Id
;
2115 Formals
: List_Id
) return Node_Id
2117 Body_Spec
: Node_Id
;
2120 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
2122 -- The subprogram is not overriding or is not a primitive declared
2123 -- between two views.
2125 if No
(Body_Spec
) then
2130 Actuals
: List_Id
:= No_List
;
2132 First_Form
: Node_Id
;
2137 -- Map formals to actuals. Use the list built for the wrapper
2138 -- spec, skipping the object notation parameter.
2140 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
2142 Formal
:= First_Form
;
2145 if Present
(Formal
) then
2146 Actuals
:= New_List
;
2147 while Present
(Formal
) loop
2149 Make_Identifier
(Loc
,
2150 Chars
=> Chars
(Defining_Identifier
(Formal
))));
2155 -- Special processing for primitives declared between a private
2156 -- type and its completion: the wrapper needs a properly typed
2157 -- parameter if the wrapped operation has a controlling first
2158 -- parameter. Note that this might not be the case for a function
2159 -- with a controlling result.
2161 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
2162 if No
(Actuals
) then
2163 Actuals
:= New_List
;
2166 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
2167 Prepend_To
(Actuals
,
2168 Unchecked_Convert_To
2169 (Corresponding_Concurrent_Type
(Obj_Typ
),
2170 Make_Identifier
(Loc
, Name_uO
)));
2173 Prepend_To
(Actuals
,
2174 Make_Identifier
(Loc
,
2175 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
2178 Nam
:= New_Occurrence_Of
(Subp_Id
, Loc
);
2180 -- An access-to-variable object parameter requires an explicit
2181 -- dereference in the unchecked conversion. This case occurs
2182 -- when a protected entry wrapper must override an interface
2183 -- level procedure with interface access as first parameter.
2185 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2187 if Nkind
(Parameter_Type
(First_Form
)) =
2191 Make_Explicit_Dereference
(Loc
,
2192 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
2194 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
2198 Make_Selected_Component
(Loc
,
2200 Unchecked_Convert_To
2201 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
2202 Selector_Name
=> New_Occurrence_Of
(Subp_Id
, Loc
));
2205 -- Create the subprogram body. For a function, the call to the
2206 -- actual subprogram has to be converted to the corresponding
2207 -- record if it is a controlling result.
2209 if Ekind
(Subp_Id
) = E_Function
then
2215 Make_Function_Call
(Loc
,
2217 Parameter_Associations
=> Actuals
);
2219 if Has_Controlling_Result
(Subp_Id
) then
2221 Unchecked_Convert_To
2222 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
2226 Make_Subprogram_Body
(Loc
,
2227 Specification
=> Body_Spec
,
2228 Declarations
=> Empty_List
,
2229 Handled_Statement_Sequence
=>
2230 Make_Handled_Sequence_Of_Statements
(Loc
,
2231 Statements
=> New_List
(
2232 Make_Simple_Return_Statement
(Loc
, Res
))));
2237 Make_Subprogram_Body
(Loc
,
2238 Specification
=> Body_Spec
,
2239 Declarations
=> Empty_List
,
2240 Handled_Statement_Sequence
=>
2241 Make_Handled_Sequence_Of_Statements
(Loc
,
2242 Statements
=> New_List
(
2243 Make_Procedure_Call_Statement
(Loc
,
2245 Parameter_Associations
=> Actuals
))));
2248 end Build_Wrapper_Body
;
2250 -- Start of processing for Build_Wrapper_Bodies
2253 if Is_Concurrent_Type
(Typ
) then
2254 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2259 -- Generate wrapper bodies for a concurrent type which implements an
2262 if Present
(Interfaces
(Rec_Typ
)) then
2264 Insert_Nod
: Node_Id
;
2266 Prim_Elmt
: Elmt_Id
;
2267 Prim_Decl
: Node_Id
;
2269 Wrap_Body
: Node_Id
;
2270 Wrap_Id
: Entity_Id
;
2275 -- Examine all primitive operations of the corresponding record
2276 -- type, looking for wrapper specs. Generate bodies in order to
2279 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2280 while Present
(Prim_Elmt
) loop
2281 Prim
:= Node
(Prim_Elmt
);
2283 if (Ekind
(Prim
) = E_Function
2284 or else Ekind
(Prim
) = E_Procedure
)
2285 and then Is_Primitive_Wrapper
(Prim
)
2287 Subp
:= Wrapped_Entity
(Prim
);
2288 Prim_Decl
:= Parent
(Parent
(Prim
));
2291 Build_Wrapper_Body
(Loc
,
2294 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2295 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2297 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2298 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2300 Insert_After
(Insert_Nod
, Wrap_Body
);
2301 Insert_Nod
:= Wrap_Body
;
2303 Analyze
(Wrap_Body
);
2306 Next_Elmt
(Prim_Elmt
);
2310 end Build_Wrapper_Bodies
;
2312 ------------------------
2313 -- Build_Wrapper_Spec --
2314 ------------------------
2316 function Build_Wrapper_Spec
2317 (Subp_Id
: Entity_Id
;
2318 Obj_Typ
: Entity_Id
;
2319 Formals
: List_Id
) return Node_Id
2321 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2322 First_Param
: Node_Id
;
2324 Iface_Elmt
: Elmt_Id
;
2325 Iface_Op
: Entity_Id
;
2326 Iface_Op_Elmt
: Elmt_Id
;
2328 function Overriding_Possible
2329 (Iface_Op
: Entity_Id
;
2330 Wrapper
: Entity_Id
) return Boolean;
2331 -- Determine whether a primitive operation can be overridden by Wrapper.
2332 -- Iface_Op is the candidate primitive operation of an interface type,
2333 -- Wrapper is the generated entry wrapper.
2335 function Replicate_Formals
2337 Formals
: List_Id
) return List_Id
;
2338 -- An explicit parameter replication is required due to the Is_Entry_
2339 -- Formal flag being set for all the formals of an entry. The explicit
2340 -- replication removes the flag that would otherwise cause a different
2341 -- path of analysis.
2343 -------------------------
2344 -- Overriding_Possible --
2345 -------------------------
2347 function Overriding_Possible
2348 (Iface_Op
: Entity_Id
;
2349 Wrapper
: Entity_Id
) return Boolean
2351 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2352 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2354 function Type_Conformant_Parameters
2355 (Iface_Op_Params
: List_Id
;
2356 Wrapper_Params
: List_Id
) return Boolean;
2357 -- Determine whether the parameters of the generated entry wrapper
2358 -- and those of a primitive operation are type conformant. During
2359 -- this check, the first parameter of the primitive operation is
2360 -- skipped if it is a controlling argument: protected functions
2361 -- may have a controlling result.
2363 --------------------------------
2364 -- Type_Conformant_Parameters --
2365 --------------------------------
2367 function Type_Conformant_Parameters
2368 (Iface_Op_Params
: List_Id
;
2369 Wrapper_Params
: List_Id
) return Boolean
2371 Iface_Op_Param
: Node_Id
;
2372 Iface_Op_Typ
: Entity_Id
;
2373 Wrapper_Param
: Node_Id
;
2374 Wrapper_Typ
: Entity_Id
;
2377 -- Skip the first (controlling) parameter of primitive operation
2379 Iface_Op_Param
:= First
(Iface_Op_Params
);
2381 if Present
(First_Formal
(Iface_Op
))
2382 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2384 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2387 Wrapper_Param
:= First
(Wrapper_Params
);
2388 while Present
(Iface_Op_Param
)
2389 and then Present
(Wrapper_Param
)
2391 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2392 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2394 -- The two parameters must be mode conformant
2396 if not Conforming_Types
2397 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2402 Next
(Iface_Op_Param
);
2403 Next
(Wrapper_Param
);
2406 -- One of the lists is longer than the other
2408 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2413 end Type_Conformant_Parameters
;
2415 -- Start of processing for Overriding_Possible
2418 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2422 -- If an inherited subprogram is implemented by a protected procedure
2423 -- or an entry, then the first parameter of the inherited subprogram
2424 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2426 if Ekind
(Iface_Op
) = E_Procedure
2427 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2430 Obj_Param
: constant Node_Id
:=
2431 First
(Parameter_Specifications
(Iface_Op_Spec
));
2433 if not Out_Present
(Obj_Param
)
2434 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2443 Type_Conformant_Parameters
(
2444 Parameter_Specifications
(Iface_Op_Spec
),
2445 Parameter_Specifications
(Wrapper_Spec
));
2446 end Overriding_Possible
;
2448 -----------------------
2449 -- Replicate_Formals --
2450 -----------------------
2452 function Replicate_Formals
2454 Formals
: List_Id
) return List_Id
2456 New_Formals
: constant List_Id
:= New_List
;
2458 Param_Type
: Node_Id
;
2461 Formal
:= First
(Formals
);
2463 -- Skip the object parameter when dealing with primitives declared
2464 -- between two views.
2466 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2467 and then not Has_Controlling_Result
(Subp_Id
)
2469 Formal
:= Next
(Formal
);
2472 while Present
(Formal
) loop
2474 -- Create an explicit copy of the entry parameter
2476 -- When creating the wrapper subprogram for a primitive operation
2477 -- of a protected interface we must construct an equivalent
2478 -- signature to that of the overriding operation. For regular
2479 -- parameters we can just use the type of the formal, but for
2480 -- access to subprogram parameters we need to reanalyze the
2481 -- parameter type to create local entities for the signature of
2482 -- the subprogram type. Using the entities of the overriding
2483 -- subprogram will result in out-of-scope errors in the back-end.
2485 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2486 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2489 New_Occurrence_Of
(Etype
(Parameter_Type
(Formal
)), Loc
);
2492 Append_To
(New_Formals
,
2493 Make_Parameter_Specification
(Loc
,
2494 Defining_Identifier
=>
2495 Make_Defining_Identifier
(Loc
,
2497 (Defining_Identifier
(Formal
))),
2498 In_Present
=> In_Present
(Formal
),
2499 Out_Present
=> Out_Present
(Formal
),
2500 Null_Exclusion_Present
=> Null_Exclusion_Present
(Formal
),
2501 Parameter_Type
=> Param_Type
));
2507 end Replicate_Formals
;
2509 -- Start of processing for Build_Wrapper_Spec
2512 -- No point in building wrappers for untagged concurrent types
2514 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2516 -- An entry or a protected procedure can override a routine where the
2517 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2518 -- type. Since the wrapper must have the exact same signature as that of
2519 -- the overridden subprogram, we try to find the overriding candidate
2520 -- and use its controlling formal.
2522 First_Param
:= Empty
;
2524 -- Check every implemented interface
2526 if Present
(Interfaces
(Obj_Typ
)) then
2527 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2528 Search
: while Present
(Iface_Elmt
) loop
2529 Iface
:= Node
(Iface_Elmt
);
2531 -- Check every interface primitive
2533 if Present
(Primitive_Operations
(Iface
)) then
2534 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2535 while Present
(Iface_Op_Elmt
) loop
2536 Iface_Op
:= Node
(Iface_Op_Elmt
);
2538 -- Ignore predefined primitives
2540 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2541 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2543 -- The current primitive operation can be overridden by
2544 -- the generated entry wrapper.
2546 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2548 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2554 Next_Elmt
(Iface_Op_Elmt
);
2558 Next_Elmt
(Iface_Elmt
);
2562 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2563 -- this subprogram and this is not a primitive declared between two
2564 -- views then force the generation of a wrapper. As an optimization,
2565 -- previous versions of the frontend avoid generating the wrapper;
2566 -- however, the wrapper facilitates locating and reporting an error
2567 -- when a duplicate declaration is found later. See example in
2571 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2574 (Corresponding_Concurrent_Type
(Obj_Typ
))
2577 Make_Parameter_Specification
(Loc
,
2578 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
2580 Out_Present
=> False,
2581 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2583 -- For entries and procedures of protected types the mode of
2584 -- the controlling argument must be in-out.
2588 Make_Parameter_Specification
(Loc
,
2589 Defining_Identifier
=>
2590 Make_Defining_Identifier
(Loc
,
2593 Out_Present
=> (Ekind
(Subp_Id
) /= E_Function
),
2594 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2599 Wrapper_Id
: constant Entity_Id
:=
2600 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2601 New_Formals
: List_Id
;
2602 Obj_Param
: Node_Id
;
2603 Obj_Param_Typ
: Entity_Id
;
2606 -- Minimum decoration is needed to catch the entity in
2607 -- Sem_Ch6.Override_Dispatching_Operation.
2609 if Ekind
(Subp_Id
) = E_Function
then
2610 Set_Ekind
(Wrapper_Id
, E_Function
);
2612 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2615 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2616 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2617 Set_Is_Private_Primitive
(Wrapper_Id
,
2618 Is_Private_Primitive_Subprogram
(Subp_Id
));
2620 -- Process the formals
2622 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2624 -- A function with a controlling result and no first controlling
2625 -- formal needs no additional parameter.
2627 if Has_Controlling_Result
(Subp_Id
)
2629 (No
(First_Formal
(Subp_Id
))
2630 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2634 -- Routine Subp_Id has been found to override an interface primitive.
2635 -- If the interface operation has an access parameter, create a copy
2636 -- of it, with the same null exclusion indicator if present.
2638 elsif Present
(First_Param
) then
2639 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2641 Make_Access_Definition
(Loc
,
2643 New_Occurrence_Of
(Obj_Typ
, Loc
));
2644 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2645 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2648 Obj_Param_Typ
:= New_Occurrence_Of
(Obj_Typ
, Loc
);
2652 Make_Parameter_Specification
(Loc
,
2653 Defining_Identifier
=>
2654 Make_Defining_Identifier
(Loc
,
2656 In_Present
=> In_Present
(First_Param
),
2657 Out_Present
=> Out_Present
(First_Param
),
2658 Parameter_Type
=> Obj_Param_Typ
);
2660 Prepend_To
(New_Formals
, Obj_Param
);
2662 -- If we are dealing with a primitive declared between two views,
2663 -- implemented by a synchronized operation, we need to create
2664 -- a default parameter. The mode of the parameter must match that
2665 -- of the primitive operation.
2668 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2670 Make_Parameter_Specification
(Loc
,
2671 Defining_Identifier
=>
2672 Make_Defining_Identifier
(Loc
, Name_uO
),
2673 In_Present
=> In_Present
(Parent
(First_Entity
(Subp_Id
))),
2674 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2675 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2676 Prepend_To
(New_Formals
, Obj_Param
);
2679 -- Build the final spec. If it is a function with a controlling
2680 -- result, it is a primitive operation of the corresponding
2681 -- record type, so mark the spec accordingly.
2683 if Ekind
(Subp_Id
) = E_Function
then
2688 if Has_Controlling_Result
(Subp_Id
) then
2691 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2693 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2697 Make_Function_Specification
(Loc
,
2698 Defining_Unit_Name
=> Wrapper_Id
,
2699 Parameter_Specifications
=> New_Formals
,
2700 Result_Definition
=> Res_Def
);
2704 Make_Procedure_Specification
(Loc
,
2705 Defining_Unit_Name
=> Wrapper_Id
,
2706 Parameter_Specifications
=> New_Formals
);
2709 end Build_Wrapper_Spec
;
2711 -------------------------
2712 -- Build_Wrapper_Specs --
2713 -------------------------
2715 procedure Build_Wrapper_Specs
2721 Rec_Typ
: Entity_Id
;
2722 procedure Scan_Declarations
(L
: List_Id
);
2723 -- Common processing for visible and private declarations
2724 -- of a protected type.
2726 procedure Scan_Declarations
(L
: List_Id
) is
2728 Wrap_Decl
: Node_Id
;
2729 Wrap_Spec
: Node_Id
;
2737 while Present
(Decl
) loop
2740 if Nkind
(Decl
) = N_Entry_Declaration
2741 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2745 (Subp_Id
=> Defining_Identifier
(Decl
),
2747 Formals
=> Parameter_Specifications
(Decl
));
2749 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2752 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2755 Parameter_Specifications
(Specification
(Decl
)));
2758 if Present
(Wrap_Spec
) then
2760 Make_Subprogram_Declaration
(Loc
,
2761 Specification
=> Wrap_Spec
);
2763 Insert_After
(N
, Wrap_Decl
);
2766 Analyze
(Wrap_Decl
);
2771 end Scan_Declarations
;
2773 -- start of processing for Build_Wrapper_Specs
2776 if Is_Protected_Type
(Typ
) then
2777 Def
:= Protected_Definition
(Parent
(Typ
));
2778 else pragma Assert
(Is_Task_Type
(Typ
));
2779 Def
:= Task_Definition
(Parent
(Typ
));
2782 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2784 -- Generate wrapper specs for a concurrent type which implements an
2785 -- interface. Operations in both the visible and private parts may
2786 -- implement progenitor operations.
2788 if Present
(Interfaces
(Rec_Typ
)) and then Present
(Def
) then
2789 Scan_Declarations
(Visible_Declarations
(Def
));
2790 Scan_Declarations
(Private_Declarations
(Def
));
2792 end Build_Wrapper_Specs
;
2794 ---------------------------
2795 -- Build_Find_Body_Index --
2796 ---------------------------
2798 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2799 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2802 Has_F
: Boolean := False;
2804 If_St
: Node_Id
:= Empty
;
2807 Decls
: List_Id
:= New_List
;
2810 Siz
: Node_Id
:= Empty
;
2812 procedure Add_If_Clause
(Expr
: Node_Id
);
2813 -- Add test for range of current entry
2815 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2816 -- If a bound of an entry is given by a discriminant, retrieve the
2817 -- actual value of the discriminant from the enclosing object.
2823 procedure Add_If_Clause
(Expr
: Node_Id
) is
2825 Stats
: constant List_Id
:=
2827 Make_Simple_Return_Statement
(Loc
,
2828 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2831 -- Index for current entry body
2835 -- Compute total length of entry queues so far
2843 Right_Opnd
=> Expr
);
2848 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2851 -- Map entry queue indexes in the range of the current family
2852 -- into the current index, that designates the entry body.
2856 Make_Implicit_If_Statement
(Typ
,
2858 Then_Statements
=> Stats
,
2859 Elsif_Parts
=> New_List
);
2863 Append_To
(Elsif_Parts
(If_St
),
2864 Make_Elsif_Part
(Loc
,
2866 Then_Statements
=> Stats
));
2870 ------------------------------
2871 -- Convert_Discriminant_Ref --
2872 ------------------------------
2874 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2878 if Is_Entity_Name
(Bound
)
2879 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2882 Make_Selected_Component
(Loc
,
2884 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2885 Make_Explicit_Dereference
(Loc
,
2886 Make_Identifier
(Loc
, Name_uObject
))),
2887 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2888 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2890 B
:= New_Copy_Tree
(Bound
);
2894 end Convert_Discriminant_Ref
;
2896 -- Start of processing for Build_Find_Body_Index
2899 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2901 Ent
:= First_Entity
(Typ
);
2902 while Present
(Ent
) loop
2903 if Ekind
(Ent
) = E_Entry_Family
then
2913 -- If the protected type has no entry families, there is a one-one
2914 -- correspondence between entry queue and entry body.
2917 Make_Simple_Return_Statement
(Loc
,
2918 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2921 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2924 -- if E <= l1 then return 1;
2925 -- elsif E <= l1 + l2 then return 2;
2930 Ent
:= First_Entity
(Typ
);
2932 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2934 while Present
(Ent
) loop
2935 if Ekind
(Ent
) = E_Entry
then
2936 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2938 elsif Ekind
(Ent
) = E_Entry_Family
then
2939 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2940 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2941 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2942 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2951 Make_Simple_Return_Statement
(Loc
,
2952 Expression
=> Make_Integer_Literal
(Loc
, 1));
2954 elsif Nkind
(Ret
) = N_If_Statement
then
2956 -- Ranges are in increasing order, so last one doesn't need guard
2959 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2962 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2968 Make_Subprogram_Body
(Loc
,
2969 Specification
=> Spec
,
2970 Declarations
=> Decls
,
2971 Handled_Statement_Sequence
=>
2972 Make_Handled_Sequence_Of_Statements
(Loc
,
2973 Statements
=> New_List
(Ret
)));
2974 end Build_Find_Body_Index
;
2976 --------------------------------
2977 -- Build_Find_Body_Index_Spec --
2978 --------------------------------
2980 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2981 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2982 Id
: constant Entity_Id
:=
2983 Make_Defining_Identifier
(Loc
,
2984 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2985 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2986 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2990 Make_Function_Specification
(Loc
,
2991 Defining_Unit_Name
=> Id
,
2992 Parameter_Specifications
=> New_List
(
2993 Make_Parameter_Specification
(Loc
,
2994 Defining_Identifier
=> Parm1
,
2996 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2998 Make_Parameter_Specification
(Loc
,
2999 Defining_Identifier
=> Parm2
,
3001 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
3003 Result_Definition
=> New_Occurrence_Of
(
3004 RTE
(RE_Protected_Entry_Index
), Loc
));
3005 end Build_Find_Body_Index_Spec
;
3007 -----------------------------------------------
3008 -- Build_Lock_Free_Protected_Subprogram_Body --
3009 -----------------------------------------------
3011 function Build_Lock_Free_Protected_Subprogram_Body
3014 Unprot_Spec
: Node_Id
) return Node_Id
3016 Actuals
: constant List_Id
:= New_List
;
3017 Loc
: constant Source_Ptr
:= Sloc
(N
);
3018 Spec
: constant Node_Id
:= Specification
(N
);
3019 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
3021 Prot_Spec
: Node_Id
;
3025 -- Create the protected version of the body
3028 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
3030 -- Build the actual parameters which appear in the call to the
3031 -- unprotected version of the body.
3033 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
3034 while Present
(Formal
) loop
3036 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
3041 -- Function case, generate:
3042 -- return <Unprot_Func_Call>;
3044 if Nkind
(Spec
) = N_Function_Specification
then
3046 Make_Simple_Return_Statement
(Loc
,
3048 Make_Function_Call
(Loc
,
3050 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3051 Parameter_Associations
=> Actuals
));
3053 -- Procedure case, call the unprotected version
3057 Make_Procedure_Call_Statement
(Loc
,
3059 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3060 Parameter_Associations
=> Actuals
);
3064 Make_Subprogram_Body
(Loc
,
3065 Declarations
=> Empty_List
,
3066 Specification
=> Prot_Spec
,
3067 Handled_Statement_Sequence
=>
3068 Make_Handled_Sequence_Of_Statements
(Loc
,
3069 Statements
=> New_List
(Stmt
)));
3070 end Build_Lock_Free_Protected_Subprogram_Body
;
3072 -------------------------------------------------
3073 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3074 -------------------------------------------------
3076 -- Procedures which meet the lock-free implementation requirements and
3077 -- reference a unique scalar component Comp are expanded in the following
3080 -- procedure P (...) is
3081 -- Expected_Comp : constant Comp_Type :=
3083 -- (System.Atomic_Primitives.Lock_Free_Read_N
3084 -- (_Object.Comp'Address));
3088 -- <original declarations before the object renaming declaration
3091 -- Desired_Comp : Comp_Type := Expected_Comp;
3092 -- Comp : Comp_Type renames Desired_Comp;
3094 -- <original delarations after the object renaming declaration
3098 -- <original statements>
3099 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3100 -- (_Object.Comp'Address,
3101 -- Interfaces.Unsigned_N (Expected_Comp),
3102 -- Interfaces.Unsigned_N (Desired_Comp));
3107 -- Each return and raise statement of P is transformed into an atomic
3110 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3111 -- (_Object.Comp'Address,
3112 -- Interfaces.Unsigned_N (Expected_Comp),
3113 -- Interfaces.Unsigned_N (Desired_Comp));
3115 -- <original statement>
3120 -- Functions which meet the lock-free implementation requirements and
3121 -- reference a unique scalar component Comp are expanded in the following
3124 -- function F (...) return ... is
3125 -- <original declarations before the object renaming declaration
3128 -- Expected_Comp : constant Comp_Type :=
3130 -- (System.Atomic_Primitives.Lock_Free_Read_N
3131 -- (_Object.Comp'Address));
3132 -- Comp : Comp_Type renames Expected_Comp;
3134 -- <original delarations after the object renaming declaration of
3138 -- <original statements>
3141 function Build_Lock_Free_Unprotected_Subprogram_Body
3143 Prot_Typ
: Node_Id
) return Node_Id
3145 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
3146 -- Subprograms which meet the lock-free implementation criteria are
3147 -- allowed to reference only one unique component. Return the prival
3148 -- of the said component.
3150 --------------------------
3151 -- Referenced_Component --
3152 --------------------------
3154 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
3157 Source_Comp
: Entity_Id
:= Empty
;
3160 -- Find the unique source component which N references in its
3163 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
3165 Element
: Lock_Free_Subprogram
renames
3166 Lock_Free_Subprogram_Table
.Table
(Index
);
3168 if Element
.Sub_Body
= N
then
3169 Source_Comp
:= Element
.Comp_Id
;
3175 if No
(Source_Comp
) then
3179 -- Find the prival which corresponds to the source component within
3180 -- the declarations of N.
3182 Decl
:= First
(Declarations
(N
));
3183 while Present
(Decl
) loop
3185 -- Privals appear as object renamings
3187 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
3188 Comp
:= Defining_Identifier
(Decl
);
3190 if Present
(Prival_Link
(Comp
))
3191 and then Prival_Link
(Comp
) = Source_Comp
3201 end Referenced_Component
;
3205 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
3206 Loc
: constant Source_Ptr
:= Sloc
(N
);
3207 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
3208 Decls
: List_Id
:= Declarations
(N
);
3210 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3213 -- Add renamings for the protection object, discriminals, privals and
3214 -- the entry index constant for use by debugger.
3216 Debug_Private_Data_Declarations
(Decls
);
3218 -- Perform the lock-free expansion when the subprogram references a
3219 -- protected component.
3221 if Present
(Comp
) then
3222 Protected_Component_Ref
: declare
3223 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
3224 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
3225 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
3227 Is_Procedure
: constant Boolean :=
3228 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
3229 -- Indicates if N is a protected procedure body
3231 Block_Decls
: List_Id
;
3232 Try_Write
: Entity_Id
;
3233 Desired_Comp
: Entity_Id
;
3236 Label_Id
: Entity_Id
:= Empty
;
3238 Expected_Comp
: Entity_Id
;
3241 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
3243 Unsigned
: Entity_Id
;
3245 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
3246 -- Transform a single node if it is a return statement, a raise
3247 -- statement or a reference to Comp.
3249 procedure Process_Stmts
(Stmts
: List_Id
);
3250 -- Given a statement sequence Stmts, wrap any return or raise
3251 -- statements in the following manner:
3253 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3254 -- (_Object.Comp'Address,
3255 -- Interfaces.Unsigned_N (Expected_Comp),
3256 -- Interfaces.Unsigned_N (Desired_Comp))
3267 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3269 procedure Wrap_Statement
(Stmt
: Node_Id
);
3270 -- Wrap an arbitrary statement inside an if statement where the
3271 -- condition does an atomic check on the state of the object.
3273 --------------------
3274 -- Wrap_Statement --
3275 --------------------
3277 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3279 -- The first time through, create the declaration of a label
3280 -- which is used to skip the remainder of source statements
3281 -- if the state of the object has changed.
3283 if No
(Label_Id
) then
3285 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3286 Set_Entity
(Label_Id
,
3287 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3291 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3292 -- (_Object.Comp'Address,
3293 -- Interfaces.Unsigned_N (Expected_Comp),
3294 -- Interfaces.Unsigned_N (Desired_Comp))
3302 Make_Implicit_If_Statement
(N
,
3304 Make_Function_Call
(Loc
,
3306 New_Occurrence_Of
(Try_Write
, Loc
),
3307 Parameter_Associations
=> New_List
(
3308 Make_Attribute_Reference
(Loc
,
3309 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3310 Attribute_Name
=> Name_Address
),
3312 Unchecked_Convert_To
(Unsigned
,
3313 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3315 Unchecked_Convert_To
(Unsigned
,
3316 New_Occurrence_Of
(Desired_Comp
, Loc
)))),
3318 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3320 Else_Statements
=> New_List
(
3321 Make_Goto_Statement
(Loc
,
3323 New_Occurrence_Of
(Entity
(Label_Id
), Loc
)))));
3326 -- Start of processing for Process_Node
3329 -- Wrap each return and raise statement that appear inside a
3330 -- procedure. Skip the last return statement which is added by
3331 -- default since it is transformed into an exit statement.
3334 and then ((Nkind
(N
) = N_Simple_Return_Statement
3335 and then N
/= Last
(Stmts
))
3336 or else Nkind
(N
) = N_Extended_Return_Statement
3337 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3338 N_Raise_Program_Error
,
3340 N_Raise_Storage_Error
)
3341 and then Comes_From_Source
(N
)))
3349 Set_Analyzed
(N
, False);
3354 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3360 procedure Process_Stmts
(Stmts
: List_Id
) is
3363 Stmt
:= First
(Stmts
);
3364 while Present
(Stmt
) loop
3365 Process_Nodes
(Stmt
);
3370 -- Start of processing for Protected_Component_Ref
3373 -- Get the type size
3375 if Known_Static_Esize
(Comp_Type
) then
3376 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3378 -- If the Esize (Object_Size) is unknown at compile time, look at
3379 -- the RM_Size (Value_Size) since it may have been set by an
3380 -- explicit representation clause.
3382 elsif Known_Static_RM_Size
(Comp_Type
) then
3383 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3385 -- Should not happen since this has already been checked in
3386 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3389 raise Program_Error
;
3392 -- Retrieve all relevant atomic routines and types
3396 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3397 Read
:= RTE
(RE_Lock_Free_Read_8
);
3398 Unsigned
:= RTE
(RE_Uint8
);
3401 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3402 Read
:= RTE
(RE_Lock_Free_Read_16
);
3403 Unsigned
:= RTE
(RE_Uint16
);
3406 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3407 Read
:= RTE
(RE_Lock_Free_Read_32
);
3408 Unsigned
:= RTE
(RE_Uint32
);
3411 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3412 Read
:= RTE
(RE_Lock_Free_Read_64
);
3413 Unsigned
:= RTE
(RE_Uint64
);
3416 raise Program_Error
;
3420 -- Expected_Comp : constant Comp_Type :=
3422 -- (System.Atomic_Primitives.Lock_Free_Read_N
3423 -- (_Object.Comp'Address));
3426 Make_Defining_Identifier
(Loc
,
3427 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3430 Make_Object_Declaration
(Loc
,
3431 Defining_Identifier
=> Expected_Comp
,
3432 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3433 Constant_Present
=> True,
3435 Unchecked_Convert_To
(Comp_Type
,
3436 Make_Function_Call
(Loc
,
3437 Name
=> New_Occurrence_Of
(Read
, Loc
),
3438 Parameter_Associations
=> New_List
(
3439 Make_Attribute_Reference
(Loc
,
3440 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3441 Attribute_Name
=> Name_Address
)))));
3443 -- Protected procedures
3445 if Is_Procedure
then
3446 -- Move the original declarations inside the generated block
3448 Block_Decls
:= Decls
;
3450 -- Reset the declarations list of the protected procedure to
3451 -- contain only Decl.
3453 Decls
:= New_List
(Decl
);
3456 -- Desired_Comp : Comp_Type := Expected_Comp;
3459 Make_Defining_Identifier
(Loc
,
3460 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3462 -- Insert the declarations of Expected_Comp and Desired_Comp in
3463 -- the block declarations right before the renaming of the
3464 -- protected component.
3466 Insert_Before
(Comp_Decl
,
3467 Make_Object_Declaration
(Loc
,
3468 Defining_Identifier
=> Desired_Comp
,
3469 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3471 New_Occurrence_Of
(Expected_Comp
, Loc
)));
3473 -- Protected function
3476 Desired_Comp
:= Expected_Comp
;
3478 -- Insert the declaration of Expected_Comp in the function
3479 -- declarations right before the renaming of the protected
3482 Insert_Before
(Comp_Decl
, Decl
);
3485 -- Rewrite the protected component renaming declaration to be a
3486 -- renaming of Desired_Comp.
3489 -- Comp : Comp_Type renames Desired_Comp;
3492 Make_Object_Renaming_Declaration
(Loc
,
3493 Defining_Identifier
=>
3494 Defining_Identifier
(Comp_Decl
),
3496 New_Occurrence_Of
(Comp_Type
, Loc
),
3498 New_Occurrence_Of
(Desired_Comp
, Loc
)));
3500 -- Wrap any return or raise statements in Stmts in same the manner
3501 -- described in Process_Stmts.
3503 Process_Stmts
(Stmts
);
3506 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3507 -- (_Object.Comp'Address,
3508 -- Interfaces.Unsigned_N (Expected_Comp),
3509 -- Interfaces.Unsigned_N (Desired_Comp))
3511 if Is_Procedure
then
3513 Make_Exit_Statement
(Loc
,
3515 Make_Function_Call
(Loc
,
3517 New_Occurrence_Of
(Try_Write
, Loc
),
3518 Parameter_Associations
=> New_List
(
3519 Make_Attribute_Reference
(Loc
,
3520 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3521 Attribute_Name
=> Name_Address
),
3523 Unchecked_Convert_To
(Unsigned
,
3524 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3526 Unchecked_Convert_To
(Unsigned
,
3527 New_Occurrence_Of
(Desired_Comp
, Loc
)))));
3529 -- Small optimization: transform the default return statement
3530 -- of a procedure into the atomic exit statement.
3532 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3533 Rewrite
(Last
(Stmts
), Stmt
);
3535 Append_To
(Stmts
, Stmt
);
3539 -- Create the declaration of the label used to skip the rest of
3540 -- the source statements when the object state changes.
3542 if Present
(Label_Id
) then
3543 Label
:= Make_Label
(Loc
, Label_Id
);
3545 Make_Implicit_Label_Declaration
(Loc
,
3546 Defining_Identifier
=> Entity
(Label_Id
),
3547 Label_Construct
=> Label
));
3548 Append_To
(Stmts
, Label
);
3560 if Is_Procedure
then
3563 Make_Loop_Statement
(Loc
,
3564 Statements
=> New_List
(
3565 Make_Block_Statement
(Loc
,
3566 Declarations
=> Block_Decls
,
3567 Handled_Statement_Sequence
=>
3568 Make_Handled_Sequence_Of_Statements
(Loc
,
3569 Statements
=> Stmts
))),
3570 End_Label
=> Empty
));
3574 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3575 end Protected_Component_Ref
;
3578 -- Make an unprotected version of the subprogram for use within the same
3579 -- object, with new name and extra parameter representing the object.
3582 Make_Subprogram_Body
(Loc
,
3584 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3585 Declarations
=> Decls
,
3586 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3587 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3589 -------------------------
3590 -- Build_Master_Entity --
3591 -------------------------
3593 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3594 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3596 Context_Id
: Entity_Id
;
3602 if Is_Itype
(Obj_Or_Typ
) then
3603 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3605 Par
:= Parent
(Obj_Or_Typ
);
3608 -- When creating a master for a record component which is either a task
3609 -- or access-to-task, the enclosing record is the master scope and the
3610 -- proper insertion point is the component list.
3612 if Is_Record_Type
(Current_Scope
) then
3614 Context_Id
:= Current_Scope
;
3615 Decls
:= List_Containing
(Context
);
3617 -- Default case for object declarations and access types. Note that the
3618 -- context is updated to the nearest enclosing body, block, package or
3619 -- return statement.
3622 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3625 -- Do not create a master if one already exists or there is no task
3628 if Has_Master_Entity
(Context_Id
)
3629 or else Restriction_Active
(No_Task_Hierarchy
)
3634 -- Create a master, generate:
3635 -- _Master : constant Master_Id := Current_Master.all;
3638 Make_Object_Declaration
(Loc
,
3639 Defining_Identifier
=>
3640 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3641 Constant_Present
=> True,
3642 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3644 Make_Explicit_Dereference
(Loc
,
3645 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
3647 -- The master is inserted at the start of the declarative list of the
3650 Prepend_To
(Decls
, Decl
);
3652 -- In certain cases where transient scopes are involved, the immediate
3653 -- scope is not always the proper master scope. Ensure that the master
3654 -- declaration and entity appear in the same context.
3656 if Context_Id
/= Current_Scope
then
3657 Push_Scope
(Context_Id
);
3664 -- Mark the enclosing scope and its associated construct as being task
3667 Set_Has_Master_Entity
(Context_Id
);
3669 while Present
(Context
)
3670 and then Nkind
(Context
) /= N_Compilation_Unit
3672 if Nkind_In
(Context
, N_Block_Statement
,
3676 Set_Is_Task_Master
(Context
);
3679 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3680 Context
:= Corresponding_Stub
(Parent
(Context
));
3683 Context
:= Parent
(Context
);
3685 end Build_Master_Entity
;
3687 ---------------------------
3688 -- Build_Master_Renaming --
3689 ---------------------------
3691 procedure Build_Master_Renaming
3692 (Ptr_Typ
: Entity_Id
;
3693 Ins_Nod
: Node_Id
:= Empty
)
3695 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3697 Master_Decl
: Node_Id
;
3698 Master_Id
: Entity_Id
;
3701 -- Nothing to do if there is no task hierarchy
3703 if Restriction_Active
(No_Task_Hierarchy
) then
3707 -- Determine the proper context to insert the master renaming
3709 if Present
(Ins_Nod
) then
3711 elsif Is_Itype
(Ptr_Typ
) then
3712 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3714 Context
:= Parent
(Ptr_Typ
);
3718 -- <Ptr_Typ>M : Master_Id renames _Master;
3721 Make_Defining_Identifier
(Loc
,
3722 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3725 Make_Object_Renaming_Declaration
(Loc
,
3726 Defining_Identifier
=> Master_Id
,
3727 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3728 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3730 Insert_Action
(Context
, Master_Decl
);
3732 -- The renamed master now services the access type
3734 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3735 end Build_Master_Renaming
;
3737 -----------------------------------------
3738 -- Build_Private_Protected_Declaration --
3739 -----------------------------------------
3741 function Build_Private_Protected_Declaration
3742 (N
: Node_Id
) return Entity_Id
3744 Loc
: constant Source_Ptr
:= Sloc
(N
);
3745 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3750 Spec_Id
: Entity_Id
;
3753 Formal
:= First_Formal
(Body_Id
);
3755 -- The protected operation always has at least one formal, namely the
3756 -- object itself, but it is only placed in the parameter list if
3757 -- expansion is enabled.
3759 if Present
(Formal
) or else Expander_Active
then
3760 Plist
:= Copy_Parameter_List
(Body_Id
);
3765 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3767 Make_Procedure_Specification
(Loc
,
3768 Defining_Unit_Name
=>
3769 Make_Defining_Identifier
(Sloc
(Body_Id
),
3770 Chars
=> Chars
(Body_Id
)),
3771 Parameter_Specifications
=>
3775 Make_Function_Specification
(Loc
,
3776 Defining_Unit_Name
=>
3777 Make_Defining_Identifier
(Sloc
(Body_Id
),
3778 Chars
=> Chars
(Body_Id
)),
3779 Parameter_Specifications
=> Plist
,
3780 Result_Definition
=>
3781 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3784 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3785 Insert_Before
(N
, Decl
);
3786 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3788 -- Indicate that the entity comes from source, to ensure that cross-
3789 -- reference information is properly generated. The body itself is
3790 -- rewritten during expansion, and the body entity will not appear in
3791 -- calls to the operation.
3793 Set_Comes_From_Source
(Spec_Id
, True);
3795 Set_Has_Completion
(Spec_Id
);
3796 Set_Convention
(Spec_Id
, Convention_Protected
);
3798 end Build_Private_Protected_Declaration
;
3800 ---------------------------
3801 -- Build_Protected_Entry --
3802 ---------------------------
3804 function Build_Protected_Entry
3807 Pid
: Node_Id
) return Node_Id
3809 Loc
: constant Source_Ptr
:= Sloc
(N
);
3811 Decls
: constant List_Id
:= Declarations
(N
);
3812 End_Lab
: constant Node_Id
:=
3813 End_Label
(Handled_Statement_Sequence
(N
));
3814 End_Loc
: constant Source_Ptr
:=
3815 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3816 -- Used for the generated call to Complete_Entry_Body
3818 Han_Loc
: Source_Ptr
;
3819 -- Used for the exception handler, inserted at end of the body
3821 Op_Decls
: constant List_Id
:= New_List
;
3829 -- Set the source location on the exception handler only when debugging
3830 -- the expanded code (see Make_Implicit_Exception_Handler).
3832 if Debug_Generated_Code
then
3835 -- Otherwise the inserted code should not be visible to the debugger
3838 Han_Loc
:= No_Location
;
3842 Make_Defining_Identifier
(Loc
,
3843 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3845 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
3847 -- Add the following declarations:
3849 -- type poVP is access poV;
3850 -- _object : poVP := poVP (_O);
3852 -- where _O is the formal parameter associated with the concurrent
3853 -- object. These declarations are needed for Complete_Entry_Body.
3855 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
3857 -- Add renamings for all formals, the Protection object, discriminals,
3858 -- privals and the entry index constant for use by debugger.
3860 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
3861 Debug_Private_Data_Declarations
(Decls
);
3863 -- Put the declarations and the statements from the entry
3867 Make_Block_Statement
(Loc
,
3868 Declarations
=> Decls
,
3869 Handled_Statement_Sequence
=>
3870 Handled_Statement_Sequence
(N
)));
3872 case Corresponding_Runtime_Package
(Pid
) is
3873 when System_Tasking_Protected_Objects_Entries
=>
3874 Append_To
(Op_Stats
,
3875 Make_Procedure_Call_Statement
(End_Loc
,
3877 New_Occurrence_Of
(RTE
(RE_Complete_Entry_Body
), Loc
),
3878 Parameter_Associations
=> New_List
(
3879 Make_Attribute_Reference
(End_Loc
,
3881 Make_Selected_Component
(End_Loc
,
3883 Make_Identifier
(End_Loc
, Name_uObject
),
3885 Make_Identifier
(End_Loc
, Name_uObject
)),
3886 Attribute_Name
=> Name_Unchecked_Access
))));
3888 when System_Tasking_Protected_Objects_Single_Entry
=>
3890 -- Historically, a call to Complete_Single_Entry_Body was
3891 -- inserted, but it was a null procedure.
3896 raise Program_Error
;
3899 -- When exceptions can not be propagated, we never need to call
3900 -- Exception_Complete_Entry_Body
3902 if No_Exception_Handlers_Set
then
3904 Make_Subprogram_Body
(Loc
,
3905 Specification
=> Espec
,
3906 Declarations
=> Op_Decls
,
3907 Handled_Statement_Sequence
=>
3908 Make_Handled_Sequence_Of_Statements
(Loc
,
3909 Statements
=> Op_Stats
,
3910 End_Label
=> End_Lab
));
3913 Ohandle
:= Make_Others_Choice
(Loc
);
3914 Set_All_Others
(Ohandle
);
3916 case Corresponding_Runtime_Package
(Pid
) is
3917 when System_Tasking_Protected_Objects_Entries
=>
3920 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3922 when System_Tasking_Protected_Objects_Single_Entry
=>
3925 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3928 raise Program_Error
;
3931 -- Establish link between subprogram body entity and source entry
3933 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
3935 -- Create body of entry procedure. The renaming declarations are
3936 -- placed ahead of the block that contains the actual entry body.
3939 Make_Subprogram_Body
(Loc
,
3940 Specification
=> Espec
,
3941 Declarations
=> Op_Decls
,
3942 Handled_Statement_Sequence
=>
3943 Make_Handled_Sequence_Of_Statements
(Loc
,
3944 Statements
=> Op_Stats
,
3945 End_Label
=> End_Lab
,
3946 Exception_Handlers
=> New_List
(
3947 Make_Implicit_Exception_Handler
(Han_Loc
,
3948 Exception_Choices
=> New_List
(Ohandle
),
3950 Statements
=> New_List
(
3951 Make_Procedure_Call_Statement
(Han_Loc
,
3953 Parameter_Associations
=> New_List
(
3954 Make_Attribute_Reference
(Han_Loc
,
3956 Make_Selected_Component
(Han_Loc
,
3958 Make_Identifier
(Han_Loc
, Name_uObject
),
3960 Make_Identifier
(Han_Loc
, Name_uObject
)),
3961 Attribute_Name
=> Name_Unchecked_Access
),
3963 Make_Function_Call
(Han_Loc
,
3964 Name
=> New_Occurrence_Of
(
3965 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3967 end Build_Protected_Entry
;
3969 -----------------------------------------
3970 -- Build_Protected_Entry_Specification --
3971 -----------------------------------------
3973 function Build_Protected_Entry_Specification
3976 Ent_Id
: Entity_Id
) return Node_Id
3978 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3981 Set_Debug_Info_Needed
(Def_Id
);
3983 if Present
(Ent_Id
) then
3984 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3988 Make_Procedure_Specification
(Loc
,
3989 Defining_Unit_Name
=> Def_Id
,
3990 Parameter_Specifications
=> New_List
(
3991 Make_Parameter_Specification
(Loc
,
3992 Defining_Identifier
=>
3993 Make_Defining_Identifier
(Loc
, Name_uO
),
3995 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3997 Make_Parameter_Specification
(Loc
,
3998 Defining_Identifier
=> P
,
4000 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
4002 Make_Parameter_Specification
(Loc
,
4003 Defining_Identifier
=>
4004 Make_Defining_Identifier
(Loc
, Name_uE
),
4006 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))));
4007 end Build_Protected_Entry_Specification
;
4009 --------------------------
4010 -- Build_Protected_Spec --
4011 --------------------------
4013 function Build_Protected_Spec
4015 Obj_Type
: Entity_Id
;
4017 Unprotected
: Boolean := False) return List_Id
4019 Loc
: constant Source_Ptr
:= Sloc
(N
);
4022 New_Plist
: List_Id
;
4023 New_Param
: Node_Id
;
4026 New_Plist
:= New_List
;
4028 Formal
:= First_Formal
(Ident
);
4029 while Present
(Formal
) loop
4031 Make_Parameter_Specification
(Loc
,
4032 Defining_Identifier
=>
4033 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
4034 In_Present
=> In_Present
(Parent
(Formal
)),
4035 Out_Present
=> Out_Present
(Parent
(Formal
)),
4036 Parameter_Type
=> New_Occurrence_Of
(Etype
(Formal
), Loc
));
4039 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
4042 Append
(New_Param
, New_Plist
);
4043 Next_Formal
(Formal
);
4046 -- If the subprogram is a procedure and the context is not an access
4047 -- to protected subprogram, the parameter is in-out. Otherwise it is
4051 Make_Parameter_Specification
(Loc
,
4052 Defining_Identifier
=>
4053 Make_Defining_Identifier
(Loc
, Name_uObject
),
4056 (Etype
(Ident
) = Standard_Void_Type
4057 and then not Is_RTE
(Obj_Type
, RE_Address
)),
4059 New_Occurrence_Of
(Obj_Type
, Loc
));
4060 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4061 Prepend_To
(New_Plist
, Decl
);
4064 end Build_Protected_Spec
;
4066 ---------------------------------------
4067 -- Build_Protected_Sub_Specification --
4068 ---------------------------------------
4070 function Build_Protected_Sub_Specification
4072 Prot_Typ
: Entity_Id
;
4073 Mode
: Subprogram_Protection_Mode
) return Node_Id
4075 Loc
: constant Source_Ptr
:= Sloc
(N
);
4079 New_Plist
: List_Id
;
4082 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
4083 (Dispatching_Mode
=> ' ',
4084 Protected_Mode
=> 'P',
4085 Unprotected_Mode
=> 'N');
4088 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
4091 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
4096 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
4099 Build_Protected_Spec
4100 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
4101 Mode
= Unprotected_Mode
);
4103 Make_Defining_Identifier
(Loc
,
4104 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
4106 -- The unprotected operation carries the user code, and debugging
4107 -- information must be generated for it, even though this spec does
4108 -- not come from source. It is also convenient to allow gdb to step
4109 -- into the protected operation, even though it only contains lock/
4112 Set_Debug_Info_Needed
(New_Id
);
4114 -- If a pragma Eliminate applies to the source entity, the internal
4115 -- subprograms will be eliminated as well.
4117 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
4119 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
4121 Make_Procedure_Specification
(Loc
,
4122 Defining_Unit_Name
=> New_Id
,
4123 Parameter_Specifications
=> New_Plist
);
4125 -- Create a new specification for the anonymous subprogram type
4129 Make_Function_Specification
(Loc
,
4130 Defining_Unit_Name
=> New_Id
,
4131 Parameter_Specifications
=> New_Plist
,
4132 Result_Definition
=>
4133 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
4135 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
4139 end Build_Protected_Sub_Specification
;
4141 -------------------------------------
4142 -- Build_Protected_Subprogram_Body --
4143 -------------------------------------
4145 function Build_Protected_Subprogram_Body
4148 N_Op_Spec
: Node_Id
) return Node_Id
4150 Loc
: constant Source_Ptr
:= Sloc
(N
);
4152 P_Op_Spec
: Node_Id
;
4155 Unprot_Call
: Node_Id
;
4157 Lock_Name
: Node_Id
;
4158 Lock_Stmt
: Node_Id
;
4160 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
4161 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
4163 Object_Parm
: Node_Id
;
4168 Op_Spec
:= Specification
(N
);
4169 Exc_Safe
:= Is_Exception_Safe
(N
);
4172 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
4174 -- Build a list of the formal parameters of the protected version of
4175 -- the subprogram to use as the actual parameters of the unprotected
4178 Uactuals
:= New_List
;
4179 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
4180 while Present
(Pformal
) loop
4181 Append_To
(Uactuals
,
4182 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
4186 -- Make a call to the unprotected version of the subprogram built above
4187 -- for use by the protected version built below.
4189 if Nkind
(Op_Spec
) = N_Function_Specification
then
4191 R
:= Make_Temporary
(Loc
, 'R');
4193 Make_Object_Declaration
(Loc
,
4194 Defining_Identifier
=> R
,
4195 Constant_Present
=> True,
4196 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
4198 Make_Function_Call
(Loc
,
4199 Name
=> Make_Identifier
(Loc
,
4200 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4201 Parameter_Associations
=> Uactuals
));
4204 Make_Simple_Return_Statement
(Loc
,
4205 Expression
=> New_Occurrence_Of
(R
, Loc
));
4208 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
4209 Expression
=> Make_Function_Call
(Loc
,
4211 Make_Identifier
(Loc
,
4212 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4213 Parameter_Associations
=> Uactuals
));
4216 Lock_Kind
:= RE_Lock_Read_Only
;
4220 Make_Procedure_Call_Statement
(Loc
,
4222 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4223 Parameter_Associations
=> Uactuals
);
4225 Lock_Kind
:= RE_Lock
;
4228 -- Wrap call in block that will be covered by an at_end handler
4230 if not Exc_Safe
then
4231 Unprot_Call
:= Make_Block_Statement
(Loc
,
4232 Handled_Statement_Sequence
=>
4233 Make_Handled_Sequence_Of_Statements
(Loc
,
4234 Statements
=> New_List
(Unprot_Call
)));
4237 -- Make the protected subprogram body. This locks the protected
4238 -- object and calls the unprotected version of the subprogram.
4240 case Corresponding_Runtime_Package
(Pid
) is
4241 when System_Tasking_Protected_Objects_Entries
=>
4242 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entries
), Loc
);
4244 when System_Tasking_Protected_Objects_Single_Entry
=>
4245 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entry
), Loc
);
4247 when System_Tasking_Protected_Objects
=>
4248 Lock_Name
:= New_Occurrence_Of
(RTE
(Lock_Kind
), Loc
);
4251 raise Program_Error
;
4255 Make_Attribute_Reference
(Loc
,
4257 Make_Selected_Component
(Loc
,
4258 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4259 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4260 Attribute_Name
=> Name_Unchecked_Access
);
4262 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
4264 Parameter_Associations
=> New_List
(Object_Parm
));
4266 if Abort_Allowed
then
4268 Make_Procedure_Call_Statement
(Loc
,
4269 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Defer
), Loc
),
4270 Parameter_Associations
=> Empty_List
),
4274 Stmts
:= New_List
(Lock_Stmt
);
4277 if not Exc_Safe
then
4278 Append
(Unprot_Call
, Stmts
);
4280 if Nkind
(Op_Spec
) = N_Function_Specification
then
4282 Stmts
:= Empty_List
;
4284 Append
(Unprot_Call
, Stmts
);
4287 -- Historical note: Previously, call the the cleanup was inserted
4288 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4289 -- which is also shared by the 'not Exc_Safe' path.
4291 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
4293 if Nkind
(Op_Spec
) = N_Function_Specification
then
4294 Append
(Return_Stmt
, Stmts
);
4295 Append
(Make_Block_Statement
(Loc
,
4296 Declarations
=> New_List
(Unprot_Call
),
4297 Handled_Statement_Sequence
=>
4298 Make_Handled_Sequence_Of_Statements
(Loc
,
4299 Statements
=> Stmts
)), Pre_Stmts
);
4305 Make_Subprogram_Body
(Loc
,
4306 Declarations
=> Empty_List
,
4307 Specification
=> P_Op_Spec
,
4308 Handled_Statement_Sequence
=>
4309 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4311 -- Mark this subprogram as a protected subprogram body so that the
4312 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4313 -- path as otherwise the cleanup has already been inserted.
4315 if not Exc_Safe
then
4316 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4320 end Build_Protected_Subprogram_Body
;
4322 -------------------------------------
4323 -- Build_Protected_Subprogram_Call --
4324 -------------------------------------
4326 procedure Build_Protected_Subprogram_Call
4330 External
: Boolean := True)
4332 Loc
: constant Source_Ptr
:= Sloc
(N
);
4333 Sub
: constant Entity_Id
:= Entity
(Name
);
4339 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4342 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4345 if Present
(Parameter_Associations
(N
)) then
4346 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4351 -- If the type is an untagged derived type, convert to the root type,
4352 -- which is the one on which the operations are defined.
4354 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4355 and then not Is_Tagged_Type
(Etype
(Rec
))
4356 and then Is_Derived_Type
(Etype
(Rec
))
4358 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4359 Set_Subtype_Mark
(Rec
,
4360 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4363 Prepend
(Rec
, Params
);
4365 if Ekind
(Sub
) = E_Procedure
then
4367 Make_Procedure_Call_Statement
(Loc
,
4369 Parameter_Associations
=> Params
));
4372 pragma Assert
(Ekind
(Sub
) = E_Function
);
4374 Make_Function_Call
(Loc
,
4376 Parameter_Associations
=> Params
));
4378 -- Preserve type of call for subsequent processing (required for
4379 -- call to Wrap_Transient_Expression in the case of a shared passive
4382 Set_Etype
(N
, Etype
(New_Sub
));
4386 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4387 and then Is_Entity_Name
(Expression
(Rec
))
4388 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4390 Add_Shared_Var_Lock_Procs
(N
);
4392 end Build_Protected_Subprogram_Call
;
4394 ---------------------------------------------
4395 -- Build_Protected_Subprogram_Call_Cleanup --
4396 ---------------------------------------------
4398 procedure Build_Protected_Subprogram_Call_Cleanup
4407 -- If the associated protected object has entries, a protected
4408 -- procedure has to service entry queues. In this case generate:
4410 -- Service_Entries (_object._object'Access);
4412 if Nkind
(Op_Spec
) = N_Procedure_Specification
4413 and then Has_Entries
(Conc_Typ
)
4415 case Corresponding_Runtime_Package
(Conc_Typ
) is
4416 when System_Tasking_Protected_Objects_Entries
=>
4417 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entries
), Loc
);
4419 when System_Tasking_Protected_Objects_Single_Entry
=>
4420 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entry
), Loc
);
4423 raise Program_Error
;
4427 Make_Procedure_Call_Statement
(Loc
,
4429 Parameter_Associations
=> New_List
(
4430 Make_Attribute_Reference
(Loc
,
4432 Make_Selected_Component
(Loc
,
4433 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4434 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4435 Attribute_Name
=> Name_Unchecked_Access
))));
4439 -- Unlock (_object._object'Access);
4441 case Corresponding_Runtime_Package
(Conc_Typ
) is
4442 when System_Tasking_Protected_Objects_Entries
=>
4443 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entries
), Loc
);
4445 when System_Tasking_Protected_Objects_Single_Entry
=>
4446 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entry
), Loc
);
4448 when System_Tasking_Protected_Objects
=>
4449 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock
), Loc
);
4452 raise Program_Error
;
4456 Make_Procedure_Call_Statement
(Loc
,
4458 Parameter_Associations
=> New_List
(
4459 Make_Attribute_Reference
(Loc
,
4461 Make_Selected_Component
(Loc
,
4462 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4463 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4464 Attribute_Name
=> Name_Unchecked_Access
))));
4470 if Abort_Allowed
then
4472 Make_Procedure_Call_Statement
(Loc
,
4474 New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
),
4475 Parameter_Associations
=> Empty_List
));
4477 end Build_Protected_Subprogram_Call_Cleanup
;
4479 -------------------------
4480 -- Build_Selected_Name --
4481 -------------------------
4483 function Build_Selected_Name
4484 (Prefix
: Entity_Id
;
4485 Selector
: Entity_Id
;
4486 Append_Char
: Character := ' ') return Name_Id
4488 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4489 Select_Len
: Natural;
4492 Get_Name_String
(Chars
(Selector
));
4493 Select_Len
:= Name_Len
;
4494 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4495 Get_Name_String
(Chars
(Prefix
));
4497 -- If scope is anonymous type, discard suffix to recover name of
4498 -- single protected object. Otherwise use protected type name.
4500 if Name_Buffer
(Name_Len
) = 'T' then
4501 Name_Len
:= Name_Len
- 1;
4504 Add_Str_To_Name_Buffer
("__");
4505 for J
in 1 .. Select_Len
loop
4506 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4509 -- Now add the Append_Char if specified. The encoding to follow
4510 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4511 -- then the entity is associated to a protected type subprogram.
4512 -- Otherwise, it is a protected type entry. For each case, the
4513 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4515 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4517 if Append_Char
/= ' ' then
4518 if Append_Char
= 'P' or Append_Char
= 'N' then
4519 Add_Char_To_Name_Buffer
(Append_Char
);
4522 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4523 return New_External_Name
(Name_Find
, ' ', -1);
4528 end Build_Selected_Name
;
4530 -----------------------------
4531 -- Build_Simple_Entry_Call --
4532 -----------------------------
4534 -- A task entry call is converted to a call to Call_Simple
4537 -- P : parms := (parm, parm, parm);
4539 -- Call_Simple (acceptor-task, entry-index, P'Address);
4545 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4546 -- the parameters, and the constructed aggregate value contains either the
4547 -- parameters or, in the case of non-elementary types, references to these
4548 -- parameters. Then the address of this aggregate is passed to the runtime
4549 -- routine, along with the task id value and the task entry index value.
4550 -- Pnn is only required if parameters are present.
4552 -- The assignments after the call are present only in the case of in-out
4553 -- or out parameters for elementary types, and are used to assign back the
4554 -- resulting values of such parameters.
4556 -- Note: the reason that we insert a block here is that in the context
4557 -- of selects, conditional entry calls etc. the entry call statement
4558 -- appears on its own, not as an element of a list.
4560 -- A protected entry call is converted to a Protected_Entry_Call:
4563 -- P : E1_Params := (param, param, param);
4565 -- Bnn : Communications_Block;
4568 -- P : E1_Params := (param, param, param);
4569 -- Bnn : Communications_Block;
4572 -- Protected_Entry_Call (
4573 -- Object => po._object'Access,
4574 -- E => <entry index>;
4575 -- Uninterpreted_Data => P'Address;
4576 -- Mode => Simple_Call;
4583 procedure Build_Simple_Entry_Call
4592 -- If call has been inlined, nothing left to do
4594 if Nkind
(N
) = N_Block_Statement
then
4598 -- Convert entry call to Call_Simple call
4601 Loc
: constant Source_Ptr
:= Sloc
(N
);
4602 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4603 Stats
: constant List_Id
:= New_List
;
4606 Comm_Name
: Entity_Id
;
4610 Ent_Acc
: Entity_Id
;
4612 Iface_Tag
: Entity_Id
;
4613 Iface_Typ
: Entity_Id
;
4626 -- Simple entry and entry family cases merge here
4628 Ent
:= Entity
(Ename
);
4629 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4630 Conctyp
:= Etype
(Concval
);
4632 -- If prefix is an access type, dereference to obtain the task type
4634 if Is_Access_Type
(Conctyp
) then
4635 Conctyp
:= Designated_Type
(Conctyp
);
4638 -- Special case for protected subprogram calls
4640 if Is_Protected_Type
(Conctyp
)
4641 and then Is_Subprogram
(Entity
(Ename
))
4643 if not Is_Eliminated
(Entity
(Ename
)) then
4644 Build_Protected_Subprogram_Call
4645 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4652 -- First parameter is the Task_Id value from the task value or the
4653 -- Object from the protected object value, obtained by selecting
4654 -- the _Task_Id or _Object from the result of doing an unchecked
4655 -- conversion to convert the value to the corresponding record type.
4657 if Nkind
(Concval
) = N_Function_Call
4658 and then Is_Task_Type
(Conctyp
)
4659 and then Ada_Version
>= Ada_2005
4662 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4663 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4668 Make_Object_Declaration
(Loc
,
4669 Defining_Identifier
=> Obj
,
4670 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4671 Expression
=> ExpR
);
4672 Set_Etype
(Obj
, Conctyp
);
4673 Decls
:= New_List
(Decl
);
4674 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4681 Parm1
:= Concurrent_Ref
(Concval
);
4683 -- Second parameter is the entry index, computed by the routine
4684 -- provided for this purpose. The value of this expression is
4685 -- assigned to an intermediate variable to assure that any entry
4686 -- family index expressions are evaluated before the entry
4689 if not Is_Protected_Type
(Conctyp
)
4691 Corresponding_Runtime_Package
(Conctyp
) =
4692 System_Tasking_Protected_Objects_Entries
4694 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4697 Make_Object_Declaration
(Loc
,
4698 Defining_Identifier
=> X
,
4699 Object_Definition
=>
4700 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
4701 Expression
=> Actual_Index_Expression
(
4702 Loc
, Entity
(Ename
), Index
, Concval
));
4704 Append_To
(Decls
, Xdecl
);
4705 Parm2
:= New_Occurrence_Of
(X
, Loc
);
4712 -- The third parameter is the packaged parameters. If there are
4713 -- none, then it is just the null address, since nothing is passed.
4716 Parm3
:= New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
);
4719 -- Case of parameters present, where third argument is the address
4720 -- of a packaged record containing the required parameter values.
4723 -- First build a list of parameter values, which are references to
4724 -- objects of the parameter types.
4728 Actual
:= First_Actual
(N
);
4729 Formal
:= First_Formal
(Ent
);
4730 while Present
(Actual
) loop
4732 -- If it is a by_copy_type, copy it to a new variable. The
4733 -- packaged record has a field that points to this variable.
4735 if Is_By_Copy_Type
(Etype
(Actual
)) then
4737 Make_Object_Declaration
(Loc
,
4738 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4739 Aliased_Present
=> True,
4740 Object_Definition
=>
4741 New_Occurrence_Of
(Etype
(Formal
), Loc
));
4743 -- Mark the object as not needing initialization since the
4744 -- initialization is performed separately, avoiding errors
4745 -- on cases such as formals of null-excluding access types.
4747 Set_No_Initialization
(N_Node
);
4749 -- We must make an assignment statement separate for the
4750 -- case of limited type. We cannot assign it unless the
4751 -- Assignment_OK flag is set first. An out formal of an
4752 -- access type must also be initialized from the actual,
4753 -- as stated in RM 6.4.1 (13), but no constraint is applied
4756 if Ekind
(Formal
) /= E_Out_Parameter
4757 or else Is_Access_Type
(Etype
(Formal
))
4760 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
);
4761 Set_Assignment_OK
(N_Var
);
4763 Make_Assignment_Statement
(Loc
,
4765 Expression
=> Relocate_Node
(Actual
)));
4767 -- If actual is an out parameter of a null-excluding
4768 -- access type, there is access check on entry, so set
4769 -- Suppress_Assignment_Checks on the generated statement
4770 -- that assigns the actual to the parameter block
4772 Set_Suppress_Assignment_Checks
(Last
(Stats
));
4775 Append
(N_Node
, Decls
);
4778 Make_Attribute_Reference
(Loc
,
4779 Attribute_Name
=> Name_Unchecked_Access
,
4781 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
)));
4783 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4785 elsif Is_VM_By_Copy_Actual
(Actual
) then
4787 Make_Object_Declaration
(Loc
,
4788 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4789 Aliased_Present
=> True,
4790 Object_Definition
=>
4791 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4792 Expression
=> New_Copy_Tree
(Actual
));
4793 Set_Assignment_OK
(N_Node
);
4795 Append
(N_Node
, Decls
);
4798 Make_Attribute_Reference
(Loc
,
4799 Attribute_Name
=> Name_Unchecked_Access
,
4801 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
)));
4804 -- Interface class-wide formal
4806 if Ada_Version
>= Ada_2005
4807 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4808 and then Is_Interface
(Etype
(Formal
))
4810 Iface_Typ
:= Etype
(Etype
(Formal
));
4813 -- formal_iface_type! (actual.iface_tag)'reference
4816 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4817 pragma Assert
(Present
(Iface_Tag
));
4820 Make_Reference
(Loc
,
4821 Unchecked_Convert_To
(Iface_Typ
,
4822 Make_Selected_Component
(Loc
,
4824 Relocate_Node
(Actual
),
4826 New_Occurrence_Of
(Iface_Tag
, Loc
)))));
4832 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4836 Next_Actual
(Actual
);
4837 Next_Formal_With_Extras
(Formal
);
4840 -- Now build the declaration of parameters initialized with the
4841 -- aggregate containing this constructed parameter list.
4843 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4846 Make_Object_Declaration
(Loc
,
4847 Defining_Identifier
=> P
,
4848 Object_Definition
=>
4849 New_Occurrence_Of
(Designated_Type
(Ent_Acc
), Loc
),
4851 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4854 Make_Attribute_Reference
(Loc
,
4855 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4856 Attribute_Name
=> Name_Address
);
4858 Append
(Pdecl
, Decls
);
4861 -- Now we can create the call, case of protected type
4863 if Is_Protected_Type
(Conctyp
) then
4864 case Corresponding_Runtime_Package
(Conctyp
) is
4865 when System_Tasking_Protected_Objects_Entries
=>
4867 -- Change the type of the index declaration
4869 Set_Object_Definition
(Xdecl
,
4870 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
));
4872 -- Some additional declarations for protected entry calls
4878 -- Bnn : Communications_Block;
4880 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4883 Make_Object_Declaration
(Loc
,
4884 Defining_Identifier
=> Comm_Name
,
4885 Object_Definition
=>
4887 (RTE
(RE_Communication_Block
), Loc
)));
4889 -- Some additional statements for protected entry calls
4891 -- Protected_Entry_Call (
4892 -- Object => po._object'Access,
4893 -- E => <entry index>;
4894 -- Uninterpreted_Data => P'Address;
4895 -- Mode => Simple_Call;
4899 Make_Procedure_Call_Statement
(Loc
,
4901 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
4903 Parameter_Associations
=> New_List
(
4904 Make_Attribute_Reference
(Loc
,
4905 Attribute_Name
=> Name_Unchecked_Access
,
4909 New_Occurrence_Of
(RTE
(RE_Simple_Call
), Loc
),
4910 New_Occurrence_Of
(Comm_Name
, Loc
)));
4912 when System_Tasking_Protected_Objects_Single_Entry
=>
4913 -- Protected_Single_Entry_Call (
4914 -- Object => po._object'Access,
4915 -- Uninterpreted_Data => P'Address);
4918 Make_Procedure_Call_Statement
(Loc
,
4919 Name
=> New_Occurrence_Of
(
4920 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4922 Parameter_Associations
=> New_List
(
4923 Make_Attribute_Reference
(Loc
,
4924 Attribute_Name
=> Name_Unchecked_Access
,
4929 raise Program_Error
;
4932 -- Case of task type
4936 Make_Procedure_Call_Statement
(Loc
,
4937 Name
=> New_Occurrence_Of
(RTE
(RE_Call_Simple
), Loc
),
4938 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4942 Append_To
(Stats
, Call
);
4944 -- If there are out or in/out parameters by copy add assignment
4945 -- statements for the result values.
4947 if Present
(Parms
) then
4948 Actual
:= First_Actual
(N
);
4949 Formal
:= First_Formal
(Ent
);
4951 Set_Assignment_OK
(Actual
);
4952 while Present
(Actual
) loop
4953 if (Is_By_Copy_Type
(Etype
(Actual
))
4954 or else Is_VM_By_Copy_Actual
(Actual
))
4955 and then Ekind
(Formal
) /= E_In_Parameter
4958 Make_Assignment_Statement
(Loc
,
4959 Name
=> New_Copy
(Actual
),
4961 Make_Explicit_Dereference
(Loc
,
4962 Make_Selected_Component
(Loc
,
4963 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4965 Make_Identifier
(Loc
, Chars
(Formal
)))));
4967 -- In all cases (including limited private types) we want
4968 -- the assignment to be valid.
4970 Set_Assignment_OK
(Name
(N_Node
));
4972 -- If the call is the triggering alternative in an
4973 -- asynchronous select, or the entry_call alternative of a
4974 -- conditional entry call, the assignments for in-out
4975 -- parameters are incorporated into the statement list that
4976 -- follows, so that there are executed only if the entry
4979 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4980 and then N
= Triggering_Statement
(Parent
(N
)))
4982 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4983 and then N
= Entry_Call_Statement
(Parent
(N
)))
4985 if No
(Statements
(Parent
(N
))) then
4986 Set_Statements
(Parent
(N
), New_List
);
4989 Prepend
(N_Node
, Statements
(Parent
(N
)));
4992 Insert_After
(Call
, N_Node
);
4996 Next_Actual
(Actual
);
4997 Next_Formal_With_Extras
(Formal
);
5001 -- Finally, create block and analyze it
5004 Make_Block_Statement
(Loc
,
5005 Declarations
=> Decls
,
5006 Handled_Statement_Sequence
=>
5007 Make_Handled_Sequence_Of_Statements
(Loc
,
5008 Statements
=> Stats
)));
5012 end Build_Simple_Entry_Call
;
5014 --------------------------------
5015 -- Build_Task_Activation_Call --
5016 --------------------------------
5018 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
5019 Loc
: constant Source_Ptr
:= Sloc
(N
);
5026 -- For sequential elaboration policy, all the tasks will be activated at
5027 -- the end of the elaboration.
5029 if Partition_Elaboration_Policy
= 'S' then
5033 -- Get the activation chain entity. Except in the case of a package
5034 -- body, this is in the node that was passed. For a package body, we
5035 -- have to find the corresponding package declaration node.
5037 if Nkind
(N
) = N_Package_Body
then
5038 P
:= Corresponding_Spec
(N
);
5041 exit when Nkind
(P
) = N_Package_Declaration
;
5044 Chain
:= Activation_Chain_Entity
(P
);
5047 Chain
:= Activation_Chain_Entity
(N
);
5050 if Present
(Chain
) then
5051 if Restricted_Profile
then
5052 Name
:= New_Occurrence_Of
5053 (RTE
(RE_Activate_Restricted_Tasks
), Loc
);
5055 Name
:= New_Occurrence_Of
5056 (RTE
(RE_Activate_Tasks
), Loc
);
5060 Make_Procedure_Call_Statement
(Loc
,
5062 Parameter_Associations
=>
5063 New_List
(Make_Attribute_Reference
(Loc
,
5064 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5065 Attribute_Name
=> Name_Unchecked_Access
)));
5067 if Nkind
(N
) = N_Package_Declaration
then
5068 if Present
(Corresponding_Body
(N
)) then
5071 elsif Present
(Private_Declarations
(Specification
(N
))) then
5072 Append
(Call
, Private_Declarations
(Specification
(N
)));
5075 Append
(Call
, Visible_Declarations
(Specification
(N
)));
5079 if Present
(Handled_Statement_Sequence
(N
)) then
5081 -- The call goes at the start of the statement sequence after
5082 -- the start of exception range label if one is present.
5088 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
5090 -- A special case, skip exception range label if one is
5091 -- present (from front end zcx processing).
5093 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
5097 -- Another special case, if the first statement is a block
5098 -- from optimization of a local raise to a goto, then the
5099 -- call goes inside this block.
5101 if Nkind
(Stm
) = N_Block_Statement
5102 and then Exception_Junk
(Stm
)
5105 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
5108 -- Insertion point is after any exception label pushes,
5109 -- since we want it covered by any local handlers.
5111 while Nkind
(Stm
) in N_Push_xxx_Label
loop
5115 -- Now we have the proper insertion point
5117 Insert_Before
(Stm
, Call
);
5121 Set_Handled_Statement_Sequence
(N
,
5122 Make_Handled_Sequence_Of_Statements
(Loc
,
5123 Statements
=> New_List
(Call
)));
5128 Check_Task_Activation
(N
);
5130 end Build_Task_Activation_Call
;
5132 -------------------------------
5133 -- Build_Task_Allocate_Block --
5134 -------------------------------
5136 procedure Build_Task_Allocate_Block
5141 T
: constant Entity_Id
:= Entity
(Expression
(N
));
5142 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
5143 Loc
: constant Source_Ptr
:= Sloc
(N
);
5144 Chain
: constant Entity_Id
:=
5145 Make_Defining_Identifier
(Loc
, Name_uChain
);
5146 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5151 Make_Block_Statement
(Loc
,
5152 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
5153 Declarations
=> New_List
(
5155 -- _Chain : Activation_Chain;
5157 Make_Object_Declaration
(Loc
,
5158 Defining_Identifier
=> Chain
,
5159 Aliased_Present
=> True,
5160 Object_Definition
=>
5161 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
5163 Handled_Statement_Sequence
=>
5164 Make_Handled_Sequence_Of_Statements
(Loc
,
5166 Statements
=> New_List
(
5170 Make_Procedure_Call_Statement
(Loc
,
5171 Name
=> New_Occurrence_Of
(Init
, Loc
),
5172 Parameter_Associations
=> Args
),
5174 -- Activate_Tasks (_Chain);
5176 Make_Procedure_Call_Statement
(Loc
,
5177 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
5178 Parameter_Associations
=> New_List
(
5179 Make_Attribute_Reference
(Loc
,
5180 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5181 Attribute_Name
=> Name_Unchecked_Access
))))),
5183 Has_Created_Identifier
=> True,
5184 Is_Task_Allocation_Block
=> True);
5187 Make_Implicit_Label_Declaration
(Loc
,
5188 Defining_Identifier
=> Blkent
,
5189 Label_Construct
=> Block
));
5191 Append_To
(Actions
, Block
);
5193 Set_Activation_Chain_Entity
(Block
, Chain
);
5194 end Build_Task_Allocate_Block
;
5196 -----------------------------------------------
5197 -- Build_Task_Allocate_Block_With_Init_Stmts --
5198 -----------------------------------------------
5200 procedure Build_Task_Allocate_Block_With_Init_Stmts
5203 Init_Stmts
: List_Id
)
5205 Loc
: constant Source_Ptr
:= Sloc
(N
);
5206 Chain
: constant Entity_Id
:=
5207 Make_Defining_Identifier
(Loc
, Name_uChain
);
5208 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5212 Append_To
(Init_Stmts
,
5213 Make_Procedure_Call_Statement
(Loc
,
5214 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
5215 Parameter_Associations
=> New_List
(
5216 Make_Attribute_Reference
(Loc
,
5217 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5218 Attribute_Name
=> Name_Unchecked_Access
))));
5221 Make_Block_Statement
(Loc
,
5222 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
5223 Declarations
=> New_List
(
5225 -- _Chain : Activation_Chain;
5227 Make_Object_Declaration
(Loc
,
5228 Defining_Identifier
=> Chain
,
5229 Aliased_Present
=> True,
5230 Object_Definition
=>
5231 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
5233 Handled_Statement_Sequence
=>
5234 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5236 Has_Created_Identifier
=> True,
5237 Is_Task_Allocation_Block
=> True);
5240 Make_Implicit_Label_Declaration
(Loc
,
5241 Defining_Identifier
=> Blkent
,
5242 Label_Construct
=> Block
));
5244 Append_To
(Actions
, Block
);
5246 Set_Activation_Chain_Entity
(Block
, Chain
);
5247 end Build_Task_Allocate_Block_With_Init_Stmts
;
5249 -----------------------------------
5250 -- Build_Task_Proc_Specification --
5251 -----------------------------------
5253 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5254 Loc
: constant Source_Ptr
:= Sloc
(T
);
5255 Spec_Id
: Entity_Id
;
5258 -- Case of explicit task type, suffix TB
5260 if Comes_From_Source
(T
) then
5262 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
5264 -- Case of anonymous task type, suffix B
5268 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
5271 Set_Is_Internal
(Spec_Id
);
5273 -- Associate the procedure with the task, if this is the declaration
5274 -- (and not the body) of the procedure.
5276 if No
(Task_Body_Procedure
(T
)) then
5277 Set_Task_Body_Procedure
(T
, Spec_Id
);
5281 Make_Procedure_Specification
(Loc
,
5282 Defining_Unit_Name
=> Spec_Id
,
5283 Parameter_Specifications
=> New_List
(
5284 Make_Parameter_Specification
(Loc
,
5285 Defining_Identifier
=>
5286 Make_Defining_Identifier
(Loc
, Name_uTask
),
5288 Make_Access_Definition
(Loc
,
5290 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
5291 end Build_Task_Proc_Specification
;
5293 ---------------------------------------
5294 -- Build_Unprotected_Subprogram_Body --
5295 ---------------------------------------
5297 function Build_Unprotected_Subprogram_Body
5299 Pid
: Node_Id
) return Node_Id
5301 Decls
: constant List_Id
:= Declarations
(N
);
5304 -- Add renamings for the Protection object, discriminals, privals and
5305 -- the entry index constant for use by debugger.
5307 Debug_Private_Data_Declarations
(Decls
);
5309 -- Make an unprotected version of the subprogram for use within the same
5310 -- object, with a new name and an additional parameter representing the
5314 Make_Subprogram_Body
(Sloc
(N
),
5316 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5317 Declarations
=> Decls
,
5318 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5319 end Build_Unprotected_Subprogram_Body
;
5321 ----------------------------
5322 -- Collect_Entry_Families --
5323 ----------------------------
5325 procedure Collect_Entry_Families
5328 Current_Node
: in out Node_Id
;
5329 Conctyp
: Entity_Id
)
5332 Efam_Decl
: Node_Id
;
5333 Efam_Type
: Entity_Id
;
5336 Efam
:= First_Entity
(Conctyp
);
5337 while Present
(Efam
) loop
5338 if Ekind
(Efam
) = E_Entry_Family
then
5339 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5344 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5346 Bas_Decl
: Node_Id
:= Empty
;
5351 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5353 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5354 Bas
:= Make_Temporary
(Loc
, 'B');
5357 Make_Subtype_Declaration
(Loc
,
5358 Defining_Identifier
=> Bas
,
5359 Subtype_Indication
=>
5360 Make_Subtype_Indication
(Loc
,
5362 New_Occurrence_Of
(Standard_Integer
, Loc
),
5364 Make_Range_Constraint
(Loc
,
5365 Range_Expression
=> Make_Range
(Loc
,
5366 Make_Integer_Literal
5367 (Loc
, -Entry_Family_Bound
),
5368 Make_Integer_Literal
5369 (Loc
, Entry_Family_Bound
- 1)))));
5371 Insert_After
(Current_Node
, Bas_Decl
);
5372 Current_Node
:= Bas_Decl
;
5377 Make_Full_Type_Declaration
(Loc
,
5378 Defining_Identifier
=> Efam_Type
,
5380 Make_Unconstrained_Array_Definition
(Loc
,
5382 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5384 Component_Definition
=>
5385 Make_Component_Definition
(Loc
,
5386 Aliased_Present
=> False,
5387 Subtype_Indication
=>
5388 New_Occurrence_Of
(Standard_Character
, Loc
))));
5391 Insert_After
(Current_Node
, Efam_Decl
);
5392 Current_Node
:= Efam_Decl
;
5393 Analyze
(Efam_Decl
);
5396 Make_Component_Declaration
(Loc
,
5397 Defining_Identifier
=>
5398 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5400 Component_Definition
=>
5401 Make_Component_Definition
(Loc
,
5402 Aliased_Present
=> False,
5403 Subtype_Indication
=>
5404 Make_Subtype_Indication
(Loc
,
5406 New_Occurrence_Of
(Efam_Type
, Loc
),
5409 Make_Index_Or_Discriminant_Constraint
(Loc
,
5410 Constraints
=> New_List
(
5412 (Etype
(Discrete_Subtype_Definition
5413 (Parent
(Efam
))), Loc
)))))));
5419 end Collect_Entry_Families
;
5421 -----------------------
5422 -- Concurrent_Object --
5423 -----------------------
5425 function Concurrent_Object
5426 (Spec_Id
: Entity_Id
;
5427 Conc_Typ
: Entity_Id
) return Entity_Id
5430 -- Parameter _O or _object
5432 if Is_Protected_Type
(Conc_Typ
) then
5433 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5438 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5439 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5441 end Concurrent_Object
;
5443 ----------------------
5444 -- Copy_Result_Type --
5445 ----------------------
5447 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5448 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5453 -- If the result type is an access_to_subprogram, we must create new
5454 -- entities for its spec.
5456 if Nkind
(New_Res
) = N_Access_Definition
5457 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5459 -- Provide new entities for the formals
5461 Par_Spec
:= First
(Parameter_Specifications
5462 (Access_To_Subprogram_Definition
(New_Res
)));
5463 while Present
(Par_Spec
) loop
5464 Formal
:= Defining_Identifier
(Par_Spec
);
5465 Set_Defining_Identifier
(Par_Spec
,
5466 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5472 end Copy_Result_Type
;
5474 --------------------
5475 -- Concurrent_Ref --
5476 --------------------
5478 -- The expression returned for a reference to a concurrent object has the
5481 -- taskV!(name)._Task_Id
5485 -- objectV!(name)._Object
5487 -- for a protected object. For the case of an access to a concurrent
5488 -- object, there is an extra explicit dereference:
5490 -- taskV!(name.all)._Task_Id
5491 -- objectV!(name.all)._Object
5493 -- here taskV and objectV are the types for the associated records, which
5494 -- contain the required _Task_Id and _Object fields for tasks and protected
5495 -- objects, respectively.
5497 -- For the case of a task type name, the expression is
5501 -- i.e. a call to the Self function which returns precisely this Task_Id
5503 -- For the case of a protected type name, the expression is
5507 -- which is a renaming of the _object field of the current object
5508 -- record, passed into protected operations as a parameter.
5510 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5511 Loc
: constant Source_Ptr
:= Sloc
(N
);
5512 Ntyp
: constant Entity_Id
:= Etype
(N
);
5516 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5517 -- Check whether the reference is to the immediately enclosing task
5518 -- type, or to an outer one (rare but legal).
5520 ---------------------
5521 -- Is_Current_Task --
5522 ---------------------
5524 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5528 Scop
:= Current_Scope
;
5529 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
5533 elsif Is_Task_Type
(Scop
) then
5536 -- If this is a procedure nested within the task type, we must
5537 -- assume that it can be called from an inner task, and therefore
5538 -- cannot treat it as a local reference.
5540 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5544 Scop
:= Scope
(Scop
);
5548 -- We know that we are within the task body, so should have found it
5551 raise Program_Error
;
5552 end Is_Current_Task
;
5554 -- Start of processing for Concurrent_Ref
5557 if Is_Access_Type
(Ntyp
) then
5558 Dtyp
:= Designated_Type
(Ntyp
);
5560 if Is_Protected_Type
(Dtyp
) then
5561 Sel
:= Name_uObject
;
5563 Sel
:= Name_uTask_Id
;
5567 Make_Selected_Component
(Loc
,
5569 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5570 Make_Explicit_Dereference
(Loc
, N
)),
5571 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5573 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5574 if Is_Task_Type
(Entity
(N
)) then
5576 if Is_Current_Task
(Entity
(N
)) then
5578 Make_Function_Call
(Loc
,
5579 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5584 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5585 T_Body
: constant Node_Id
:=
5586 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5590 Make_Object_Declaration
(Loc
,
5591 Defining_Identifier
=> T_Self
,
5592 Object_Definition
=>
5593 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5595 Make_Function_Call
(Loc
,
5596 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5597 Prepend
(Decl
, Declarations
(T_Body
));
5599 Set_Scope
(T_Self
, Entity
(N
));
5600 return New_Occurrence_Of
(T_Self
, Loc
);
5605 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5608 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5612 if Is_Protected_Type
(Ntyp
) then
5613 Sel
:= Name_uObject
;
5615 elsif Is_Task_Type
(Ntyp
) then
5616 Sel
:= Name_uTask_Id
;
5619 raise Program_Error
;
5623 Make_Selected_Component
(Loc
,
5625 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5627 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5631 ------------------------
5632 -- Convert_Concurrent --
5633 ------------------------
5635 function Convert_Concurrent
5637 Typ
: Entity_Id
) return Node_Id
5640 if not Is_Concurrent_Type
(Typ
) then
5644 Unchecked_Convert_To
5645 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5647 end Convert_Concurrent
;
5649 -------------------------------------
5650 -- Debug_Private_Data_Declarations --
5651 -------------------------------------
5653 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5654 Debug_Nod
: Node_Id
;
5658 Decl
:= First
(Decls
);
5659 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5661 -- Declaration for concurrent entity _object and its access type,
5662 -- along with the entry index subtype:
5663 -- type prot_typVP is access prot_typV;
5664 -- _object : prot_typVP := prot_typV (_O);
5665 -- subtype Jnn is <Type of Index> range Low .. High;
5667 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5668 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5670 -- Declaration for the Protection object, discriminals, privals and
5671 -- entry index constant:
5672 -- conc_typR : protection_typ renames _object._object;
5673 -- discr_nameD : discr_typ renames _object.discr_name;
5674 -- discr_nameD : discr_typ renames _task.discr_name;
5675 -- prival_name : comp_typ renames _object.comp_name;
5676 -- J : constant Jnn :=
5677 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5679 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5680 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5681 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5683 if Present
(Debug_Nod
) then
5684 Insert_After
(Decl
, Debug_Nod
);
5690 end Debug_Private_Data_Declarations
;
5692 ------------------------------
5693 -- Ensure_Statement_Present --
5694 ------------------------------
5696 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5700 if Opt
.Suppress_Control_Flow_Optimizations
5701 and then Is_Empty_List
(Statements
(Alt
))
5703 Stmt
:= Make_Null_Statement
(Loc
);
5705 -- Mark NULL statement as coming from source so that it is not
5706 -- eliminated by GIGI.
5708 -- Another covert channel. If this is a requirement, it must be
5709 -- documented in sinfo/einfo ???
5711 Set_Comes_From_Source
(Stmt
, True);
5713 Set_Statements
(Alt
, New_List
(Stmt
));
5715 end Ensure_Statement_Present
;
5717 ----------------------------
5718 -- Entry_Index_Expression --
5719 ----------------------------
5721 function Entry_Index_Expression
5725 Ttyp
: Entity_Id
) return Node_Id
5735 -- The queues of entries and entry families appear in textual order in
5736 -- the associated record. The entry index is computed as the sum of the
5737 -- number of queues for all entries that precede the designated one, to
5738 -- which is added the index expression, if this expression denotes a
5739 -- member of a family.
5741 -- The following is a place holder for the count of simple entries
5743 Num
:= Make_Integer_Literal
(Sloc
, 1);
5745 -- We construct an expression which is a series of addition operations.
5746 -- The first operand is the number of single entries that precede this
5747 -- one, the second operand is the index value relative to the start of
5748 -- the referenced family, and the remaining operands are the lengths of
5749 -- the entry families that precede this entry, i.e. the constructed
5752 -- number_simple_entries +
5753 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5754 -- family'length + ...
5756 -- where index-value is the given index value, and s is the index
5757 -- subtype (we have to use pos because the subtype might be an
5758 -- enumeration type preventing direct subtraction). Note that the task
5759 -- entry array is one-indexed.
5761 -- The upper bound of the entry family may be a discriminant, so we
5762 -- retrieve the lower bound explicitly to compute offset, rather than
5763 -- using the index subtype which may mention a discriminant.
5765 if Present
(Index
) then
5766 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5774 Make_Attribute_Reference
(Sloc
,
5775 Attribute_Name
=> Name_Pos
,
5776 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5777 Expressions
=> New_List
(Relocate_Node
(Index
))),
5785 -- Now add lengths of preceding entries and entry families
5787 Prev
:= First_Entity
(Ttyp
);
5789 while Chars
(Prev
) /= Chars
(Ent
)
5790 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5791 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5793 if Ekind
(Prev
) = E_Entry
then
5794 Set_Intval
(Num
, Intval
(Num
) + 1);
5796 elsif Ekind
(Prev
) = E_Entry_Family
then
5797 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5798 Lo
:= Type_Low_Bound
(S
);
5799 Hi
:= Type_High_Bound
(S
);
5804 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5806 -- Other components are anonymous types to be ignored
5816 end Entry_Index_Expression
;
5818 ---------------------------
5819 -- Establish_Task_Master --
5820 ---------------------------
5822 procedure Establish_Task_Master
(N
: Node_Id
) is
5826 if Restriction_Active
(No_Task_Hierarchy
) = False then
5827 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5829 -- The block may have no declarations (and nevertheless be a task
5830 -- master) if it contains a call that may return an object that
5833 if No
(Declarations
(N
)) then
5834 Set_Declarations
(N
, New_List
(Call
));
5836 Prepend_To
(Declarations
(N
), Call
);
5841 end Establish_Task_Master
;
5843 --------------------------------
5844 -- Expand_Accept_Declarations --
5845 --------------------------------
5847 -- Part of the expansion of an accept statement involves the creation of
5848 -- a declaration that can be referenced from the statement sequence of
5853 -- This declaration is inserted immediately before the accept statement
5854 -- and it is important that it be inserted before the statements of the
5855 -- statement sequence are analyzed. Thus it would be too late to create
5856 -- this declaration in the Expand_N_Accept_Statement routine, which is
5857 -- why there is a separate procedure to be called directly from Sem_Ch9.
5859 -- Ann is used to hold the address of the record containing the parameters
5860 -- (see Expand_N_Entry_Call for more details on how this record is built).
5861 -- References to the parameters do an unchecked conversion of this address
5862 -- to a pointer to the required record type, and then access the field that
5863 -- holds the value of the required parameter. The entity for the address
5864 -- variable is held as the top stack element (i.e. the last element) of the
5865 -- Accept_Address stack in the corresponding entry entity, and this element
5866 -- must be set in place before the statements are processed.
5868 -- The above description applies to the case of a stand alone accept
5869 -- statement, i.e. one not appearing as part of a select alternative.
5871 -- For the case of an accept that appears as part of a select alternative
5872 -- of a selective accept, we must still create the declaration right away,
5873 -- since Ann is needed immediately, but there is an important difference:
5875 -- The declaration is inserted before the selective accept, not before
5876 -- the accept statement (which is not part of a list anyway, and so would
5877 -- not accommodate inserted declarations)
5879 -- We only need one address variable for the entire selective accept. So
5880 -- the Ann declaration is created only for the first accept alternative,
5881 -- and subsequent accept alternatives reference the same Ann variable.
5883 -- We can distinguish the two cases by seeing whether the accept statement
5884 -- is part of a list. If not, then it must be in an accept alternative.
5886 -- To expand the requeue statement, a label is provided at the end of the
5887 -- accept statement or alternative of which it is a part, so that the
5888 -- statement can be skipped after the requeue is complete. This label is
5889 -- created here rather than during the expansion of the accept statement,
5890 -- because it will be needed by any requeue statements within the accept,
5891 -- which are expanded before the accept.
5893 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5894 Loc
: constant Source_Ptr
:= Sloc
(N
);
5895 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5896 Ann
: Entity_Id
:= Empty
;
5903 if Expander_Active
then
5905 -- If we have no handled statement sequence, we may need to build
5906 -- a dummy sequence consisting of a null statement. This can be
5907 -- skipped if the trivial accept optimization is permitted.
5909 if not Trivial_Accept_OK
5910 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5912 Set_Handled_Statement_Sequence
(N
,
5913 Make_Handled_Sequence_Of_Statements
(Loc
,
5914 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5917 -- Create and declare two labels to be placed at the end of the
5918 -- accept statement. The first label is used to allow requeues to
5919 -- skip the remainder of entry processing. The second label is used
5920 -- to skip the remainder of entry processing if the rendezvous
5921 -- completes in the middle of the accept body.
5923 if Present
(Handled_Statement_Sequence
(N
)) then
5928 Ent
:= Make_Temporary
(Loc
, 'L');
5929 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5931 Make_Implicit_Label_Declaration
(Loc
,
5932 Defining_Identifier
=> Ent
,
5933 Label_Construct
=> Lab
);
5934 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5936 Ent
:= Make_Temporary
(Loc
, 'L');
5937 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5939 Make_Implicit_Label_Declaration
(Loc
,
5940 Defining_Identifier
=> Ent
,
5941 Label_Construct
=> Lab
);
5942 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5950 -- Case of stand alone accept statement
5952 if Is_List_Member
(N
) then
5954 if Present
(Handled_Statement_Sequence
(N
)) then
5955 Ann
:= Make_Temporary
(Loc
, 'A');
5958 Make_Object_Declaration
(Loc
,
5959 Defining_Identifier
=> Ann
,
5960 Object_Definition
=>
5961 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5963 Insert_Before_And_Analyze
(N
, Adecl
);
5964 Insert_Before_And_Analyze
(N
, Ldecl
);
5965 Insert_Before_And_Analyze
(N
, Ldecl2
);
5968 -- Case of accept statement which is in an accept alternative
5972 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5973 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5977 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5978 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5980 -- ??? Consider a single label for select statements
5982 if Present
(Handled_Statement_Sequence
(N
)) then
5984 Statements
(Handled_Statement_Sequence
(N
)));
5988 Statements
(Handled_Statement_Sequence
(N
)));
5992 -- Find first accept alternative of the selective accept. A
5993 -- valid selective accept must have at least one accept in it.
5995 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5997 while Nkind
(Alt
) /= N_Accept_Alternative
loop
6001 -- If this is the first accept statement, then we have to
6002 -- create the Ann variable, as for the stand alone case, except
6003 -- that it is inserted before the selective accept. Similarly,
6004 -- a label for requeue expansion must be declared.
6006 if N
= Accept_Statement
(Alt
) then
6007 Ann
:= Make_Temporary
(Loc
, 'A');
6009 Make_Object_Declaration
(Loc
,
6010 Defining_Identifier
=> Ann
,
6011 Object_Definition
=>
6012 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
6014 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
6016 -- If this is not the first accept statement, then find the Ann
6017 -- variable allocated by the first accept and use it.
6021 Node
(Last_Elmt
(Accept_Address
6022 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
6027 -- Merge here with Ann either created or referenced, and Adecl
6028 -- pointing to the corresponding declaration. Remaining processing
6029 -- is the same for the two cases.
6031 if Present
(Ann
) then
6032 Append_Elmt
(Ann
, Accept_Address
(Ent
));
6033 Set_Debug_Info_Needed
(Ann
);
6036 -- Create renaming declarations for the entry formals. Each reference
6037 -- to a formal becomes a dereference of a component of the parameter
6038 -- block, whose address is held in Ann. These declarations are
6039 -- eventually inserted into the accept block, and analyzed there so
6040 -- that they have the proper scope for gdb and do not conflict with
6041 -- other declarations.
6043 if Present
(Parameter_Specifications
(N
))
6044 and then Present
(Handled_Statement_Sequence
(N
))
6051 Renamed_Formal
: Node_Id
;
6055 Formal
:= First_Formal
(Ent
);
6057 while Present
(Formal
) loop
6058 Comp
:= Entry_Component
(Formal
);
6059 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
6061 Set_Etype
(New_F
, Etype
(Formal
));
6062 Set_Scope
(New_F
, Ent
);
6064 -- Now we set debug info needed on New_F even though it does
6065 -- not come from source, so that the debugger will get the
6066 -- right information for these generated names.
6068 Set_Debug_Info_Needed
(New_F
);
6070 if Ekind
(Formal
) = E_In_Parameter
then
6071 Set_Ekind
(New_F
, E_Constant
);
6073 Set_Ekind
(New_F
, E_Variable
);
6074 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
6077 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
6080 Make_Selected_Component
(Loc
,
6082 Unchecked_Convert_To
(
6083 Entry_Parameters_Type
(Ent
),
6084 New_Occurrence_Of
(Ann
, Loc
)),
6086 New_Occurrence_Of
(Comp
, Loc
));
6089 Build_Renamed_Formal_Declaration
6090 (New_F
, Formal
, Comp
, Renamed_Formal
);
6092 if No
(Declarations
(N
)) then
6093 Set_Declarations
(N
, New_List
);
6096 Append
(Decl
, Declarations
(N
));
6097 Set_Renamed_Object
(Formal
, New_F
);
6098 Next_Formal
(Formal
);
6105 end Expand_Accept_Declarations
;
6107 ---------------------------------------------
6108 -- Expand_Access_Protected_Subprogram_Type --
6109 ---------------------------------------------
6111 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
6112 Loc
: constant Source_Ptr
:= Sloc
(N
);
6114 T
: constant Entity_Id
:= Defining_Identifier
(N
);
6115 D_T
: constant Entity_Id
:= Designated_Type
(T
);
6116 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
6117 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
6118 P_List
: constant List_Id
:= Build_Protected_Spec
6119 (N
, RTE
(RE_Address
), D_T
, False);
6125 -- Create access to subprogram with full signature
6127 if Etype
(D_T
) /= Standard_Void_Type
then
6129 Make_Access_Function_Definition
(Loc
,
6130 Parameter_Specifications
=> P_List
,
6131 Result_Definition
=>
6132 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
6136 Make_Access_Procedure_Definition
(Loc
,
6137 Parameter_Specifications
=> P_List
);
6141 Make_Full_Type_Declaration
(Loc
,
6142 Defining_Identifier
=> D_T2
,
6143 Type_Definition
=> Def1
);
6145 Insert_After_And_Analyze
(N
, Decl1
);
6147 -- Associate the access to subprogram with its original access to
6148 -- protected subprogram type. Needed by the backend to know that this
6149 -- type corresponds with an access to protected subprogram type.
6151 Set_Original_Access_Type
(D_T2
, T
);
6153 -- Create Equivalent_Type, a record with two components for an access to
6154 -- object and an access to subprogram.
6157 Make_Component_Declaration
(Loc
,
6158 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6159 Component_Definition
=>
6160 Make_Component_Definition
(Loc
,
6161 Aliased_Present
=> False,
6162 Subtype_Indication
=>
6163 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
6165 Make_Component_Declaration
(Loc
,
6166 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
6167 Component_Definition
=>
6168 Make_Component_Definition
(Loc
,
6169 Aliased_Present
=> False,
6170 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
6173 Make_Full_Type_Declaration
(Loc
,
6174 Defining_Identifier
=> E_T
,
6176 Make_Record_Definition
(Loc
,
6178 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
6180 Insert_After_And_Analyze
(Decl1
, Decl2
);
6181 Set_Equivalent_Type
(T
, E_T
);
6182 end Expand_Access_Protected_Subprogram_Type
;
6184 --------------------------
6185 -- Expand_Entry_Barrier --
6186 --------------------------
6188 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
6189 Cond
: constant Node_Id
:=
6190 Condition
(Entry_Body_Formal_Part
(N
));
6191 Prot
: constant Entity_Id
:= Scope
(Ent
);
6192 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
6195 Body_Decl
: Node_Id
;
6197 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
6198 -- Check whether entity in Barrier is external to protected type.
6199 -- If so, barrier may not be properly synchronized.
6201 ----------------------
6202 -- Is_Global_Entity --
6203 ----------------------
6205 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
6210 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
6214 if Ekind
(E
) = E_Variable
then
6215 if Scope
(E
) = Func
then
6218 -- A protected call from a barrier to another object is ok
6220 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
6223 -- If the variable is within the package body we consider
6224 -- this safe. This is a common (if dubious) idiom.
6226 elsif S
= Scope
(Prot
)
6227 and then Ekind_In
(S
, E_Package
, E_Generic_Package
)
6228 and then Nkind
(Parent
(E
)) = N_Object_Declaration
6229 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
6234 Error_Msg_N
("potentially unsynchronized barrier??", N
);
6235 Error_Msg_N
("\& should be private component of type??", N
);
6241 end Is_Global_Entity
;
6243 procedure Check_Unprotected_Barrier
is
6244 new Traverse_Proc
(Is_Global_Entity
);
6246 -- Start of processing for Expand_Entry_Barrier
6249 if No_Run_Time_Mode
then
6250 Error_Msg_CRT
("entry barrier", N
);
6254 -- The body of the entry barrier must be analyzed in the context of the
6255 -- protected object, but its scope is external to it, just as any other
6256 -- unprotected version of a protected operation. The specification has
6257 -- been produced when the protected type declaration was elaborated. We
6258 -- build the body, insert it in the enclosing scope, but analyze it in
6259 -- the current context. A more uniform approach would be to treat the
6260 -- barrier just as a protected function, and discard the protected
6261 -- version of it because it is never called.
6263 if Expander_Active
then
6264 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6265 Func
:= Barrier_Function
(Ent
);
6266 Set_Corresponding_Spec
(B_F
, Func
);
6268 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
6270 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
6271 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
6274 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
6276 Set_Discriminals
(Spec_Decl
);
6277 Set_Scope
(Func
, Scope
(Prot
));
6280 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6283 -- The Ravenscar profile restricts barriers to simple variables declared
6284 -- within the protected object. We also allow Boolean constants, since
6285 -- these appear in several published examples and are also allowed by
6288 -- Note that after analysis variables in this context will be replaced
6289 -- by the corresponding prival, that is to say a renaming of a selected
6290 -- component of the form _Object.Var. If expansion is disabled, as
6291 -- within a generic, we check that the entity appears in the current
6294 if Is_Entity_Name
(Cond
) then
6296 -- A small optimization of useless renamings. If the scope of the
6297 -- entity of the condition is not the barrier function, then the
6298 -- condition does not reference any of the generated renamings
6299 -- within the function.
6301 if Expander_Active
and then Scope
(Entity
(Cond
)) /= Func
then
6302 Set_Declarations
(B_F
, Empty_List
);
6305 if Entity
(Cond
) = Standard_False
6307 Entity
(Cond
) = Standard_True
6311 elsif not Expander_Active
6312 and then Scope
(Entity
(Cond
)) = Current_Scope
6316 -- Check for case of _object.all.field (note that the explicit
6317 -- dereference gets inserted by analyze/expand of _object.field)
6319 elsif Present
(Renamed_Object
(Entity
(Cond
)))
6321 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
6325 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
6331 -- It is not a boolean variable or literal, so check the restriction.
6332 -- Note that it is safe to be calling Check_Restriction from here, even
6333 -- though this is part of the expander, since Expand_Entry_Barrier is
6334 -- called from Sem_Ch9 even in -gnatc mode.
6336 Check_Restriction
(Simple_Barriers
, Cond
);
6338 -- Emit warning if barrier contains global entities and is thus
6339 -- potentially unsynchronized.
6341 Check_Unprotected_Barrier
(Cond
);
6342 end Expand_Entry_Barrier
;
6344 ------------------------------
6345 -- Expand_N_Abort_Statement --
6346 ------------------------------
6348 -- Expand abort T1, T2, .. Tn; into:
6349 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6351 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6352 Loc
: constant Source_Ptr
:= Sloc
(N
);
6353 Tlist
: constant List_Id
:= Names
(N
);
6359 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6362 Tasknm
:= First
(Tlist
);
6364 while Present
(Tasknm
) loop
6367 -- A task interface class-wide type object is being aborted. Retrieve
6368 -- its _task_id by calling a dispatching routine.
6370 if Ada_Version
>= Ada_2005
6371 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6372 and then Is_Interface
(Etype
(Tasknm
))
6373 and then Is_Task_Interface
(Etype
(Tasknm
))
6375 Append_To
(Component_Associations
(Aggr
),
6376 Make_Component_Association
(Loc
,
6377 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6380 -- Task_Id (Tasknm._disp_get_task_id)
6382 Make_Unchecked_Type_Conversion
(Loc
,
6384 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
6386 Make_Selected_Component
(Loc
,
6387 Prefix
=> New_Copy_Tree
(Tasknm
),
6389 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6392 Append_To
(Component_Associations
(Aggr
),
6393 Make_Component_Association
(Loc
,
6394 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6395 Expression
=> Concurrent_Ref
(Tasknm
)));
6402 Make_Procedure_Call_Statement
(Loc
,
6403 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6404 Parameter_Associations
=> New_List
(
6405 Make_Qualified_Expression
(Loc
,
6406 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6407 Expression
=> Aggr
))));
6410 end Expand_N_Abort_Statement
;
6412 -------------------------------
6413 -- Expand_N_Accept_Statement --
6414 -------------------------------
6416 -- This procedure handles expansion of accept statements that stand alone,
6417 -- i.e. they are not part of an accept alternative. The expansion of
6418 -- accept statement in accept alternatives is handled by the routines
6419 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6420 -- following description applies only to stand alone accept statements.
6422 -- If there is no handled statement sequence, or only null statements, then
6423 -- this is called a trivial accept, and the expansion is:
6425 -- Accept_Trivial (entry-index)
6427 -- If there is a handled statement sequence, then the expansion is:
6434 -- Accept_Call (entry-index, Ann);
6435 -- Renaming_Declarations for formals
6436 -- <statement sequence from N_Accept_Statement node>
6437 -- Complete_Rendezvous;
6442 -- <exception handler from N_Accept_Statement node>
6443 -- Complete_Rendezvous;
6445 -- <exception handler from N_Accept_Statement node>
6446 -- Complete_Rendezvous;
6451 -- when all others =>
6452 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6455 -- The first three declarations were already inserted ahead of the accept
6456 -- statement by the Expand_Accept_Declarations procedure, which was called
6457 -- directly from the semantics during analysis of the accept statement,
6458 -- before analyzing its contained statements.
6460 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6461 -- from possible expansion activity (the original source of course does
6462 -- not have any declarations associated with the accept statement, since
6463 -- an accept statement has no declarative part). In particular, if the
6464 -- expander is active, the first such declaration is the declaration of
6465 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6467 -- The two blocks are merged into a single block if the inner block has
6468 -- no exception handlers, but otherwise two blocks are required, since
6469 -- exceptions might be raised in the exception handlers of the inner
6470 -- block, and Exceptional_Complete_Rendezvous must be called.
6472 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6473 Loc
: constant Source_Ptr
:= Sloc
(N
);
6474 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6475 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6476 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6477 Eent
: constant Entity_Id
:= Entity
(Ename
);
6478 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6479 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6480 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6486 -- If the accept statement is not part of a list, then its parent must
6487 -- be an accept alternative, and, as described above, we do not do any
6488 -- expansion for such accept statements at this level.
6490 if not Is_List_Member
(N
) then
6491 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6494 -- Trivial accept case (no statement sequence, or null statements).
6495 -- If the accept statement has declarations, then just insert them
6496 -- before the procedure call.
6498 elsif Trivial_Accept_OK
6499 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6501 -- Remove declarations for renamings, because the parameter block
6502 -- will not be assigned.
6509 D
:= First
(Declarations
(N
));
6510 while Present
(D
) loop
6512 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6520 if Present
(Declarations
(N
)) then
6521 Insert_Actions
(N
, Declarations
(N
));
6525 Make_Procedure_Call_Statement
(Loc
,
6526 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6527 Parameter_Associations
=> New_List
(
6528 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6532 -- Discard Entry_Address that was created for it, so it will not be
6533 -- emitted if this accept statement is in the statement part of a
6534 -- delay alternative.
6536 if Present
(Stats
) then
6537 Remove_Last_Elmt
(Acstack
);
6540 -- Case of statement sequence present
6543 -- Construct the block, using the declarations from the accept
6544 -- statement if any to initialize the declarations of the block.
6546 Blkent
:= Make_Temporary
(Loc
, 'A');
6547 Set_Ekind
(Blkent
, E_Block
);
6548 Set_Etype
(Blkent
, Standard_Void_Type
);
6549 Set_Scope
(Blkent
, Current_Scope
);
6552 Make_Block_Statement
(Loc
,
6553 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6554 Declarations
=> Declarations
(N
),
6555 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6557 -- For the analysis of the generated declarations, the parent node
6558 -- must be properly set.
6560 Set_Parent
(Block
, Parent
(N
));
6562 -- Prepend call to Accept_Call to main statement sequence If the
6563 -- accept has exception handlers, the statement sequence is wrapped
6564 -- in a block. Insert call and renaming declarations in the
6565 -- declarations of the block, so they are elaborated before the
6569 Make_Procedure_Call_Statement
(Loc
,
6570 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6571 Parameter_Associations
=> New_List
(
6572 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6573 New_Occurrence_Of
(Ann
, Loc
)));
6575 if Parent
(Stats
) = N
then
6576 Prepend
(Call
, Statements
(Stats
));
6578 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6583 Push_Scope
(Blkent
);
6591 D
:= First
(Declarations
(N
));
6592 while Present
(D
) loop
6595 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6597 -- The renaming declarations for the formals were created
6598 -- during analysis of the accept statement, and attached to
6599 -- the list of declarations. Place them now in the context
6600 -- of the accept block or subprogram.
6603 Typ
:= Entity
(Subtype_Mark
(D
));
6604 Insert_After
(Call
, D
);
6607 -- If the formal is class_wide, it does not have an actual
6608 -- subtype. The analysis of the renaming declaration creates
6609 -- one, but we need to retain the class-wide nature of the
6612 if Is_Class_Wide_Type
(Typ
) then
6613 Set_Etype
(Defining_Identifier
(D
), Typ
);
6624 -- Replace the accept statement by the new block
6629 -- Last step is to unstack the Accept_Address value
6631 Remove_Last_Elmt
(Acstack
);
6633 end Expand_N_Accept_Statement
;
6635 ----------------------------------
6636 -- Expand_N_Asynchronous_Select --
6637 ----------------------------------
6639 -- This procedure assumes that the trigger statement is an entry call or
6640 -- a dispatching procedure call. A delay alternative should already have
6641 -- been expanded into an entry call to the appropriate delay object Wait
6644 -- If the trigger is a task entry call, the select is implemented with
6645 -- a Task_Entry_Call:
6650 -- P : parms := (parm, parm, parm);
6652 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6654 -- procedure _clean is
6657 -- Cancel_Task_Entry_Call (C);
6664 -- (<acceptor-task>, -- Acceptor
6665 -- <entry-index>, -- E
6666 -- P'Address, -- Uninterpreted_Data
6667 -- Asynchronous_Call, -- Mode
6668 -- B); -- Rendezvous_Successful
6675 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6678 -- when Abort_Signal => Abort_Undefer;
6685 -- <triggered-statements>
6689 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6690 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6694 -- P : parms := (parm, parm, parm);
6696 -- Call_Simple (acceptor-task, entry-index, P'Address);
6702 -- so the task at hand is to convert the latter expansion into the former
6704 -- If the trigger is a protected entry call, the select is implemented
6705 -- with Protected_Entry_Call:
6708 -- P : E1_Params := (param, param, param);
6709 -- Bnn : Communications_Block;
6714 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6716 -- procedure _clean is
6719 -- if Enqueued (Bnn) then
6720 -- Cancel_Protected_Entry_Call (Bnn);
6727 -- Protected_Entry_Call
6728 -- (po._object'Access, -- Object
6729 -- <entry index>, -- E
6730 -- P'Address, -- Uninterpreted_Data
6731 -- Asynchronous_Call, -- Mode
6734 -- if Enqueued (Bnn) then
6738 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6741 -- when Abort_Signal => Abort_Undefer;
6744 -- if not Cancelled (Bnn) then
6745 -- <triggered-statements>
6749 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6753 -- P : E1_Params := (param, param, param);
6754 -- Bnn : Communications_Block;
6757 -- Protected_Entry_Call
6758 -- (po._object'Access, -- Object
6759 -- <entry index>, -- E
6760 -- P'Address, -- Uninterpreted_Data
6761 -- Simple_Call, -- Mode
6768 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6772 -- B : Boolean := False;
6773 -- Bnn : Communication_Block;
6774 -- C : Ada.Tags.Prim_Op_Kind;
6775 -- D : System.Storage_Elements.Dummy_Communication_Block;
6776 -- K : Ada.Tags.Tagged_Kind :=
6777 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6778 -- P : Parameters := (Param1 .. ParamN);
6783 -- if K = Ada.Tags.TK_Limited_Tagged
6784 -- or else K = Ada.Tags.TK_Tagged
6786 -- <dispatching-call>;
6787 -- <triggering-statements>;
6791 -- Ada.Tags.Get_Offset_Index
6792 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6794 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6796 -- if C = POK_Protected_Entry then
6798 -- procedure _clean is
6800 -- if Enqueued (Bnn) then
6801 -- Cancel_Protected_Entry_Call (Bnn);
6807 -- _Disp_Asynchronous_Select
6808 -- (<object>, S, P'Address, D, B);
6809 -- Bnn := Communication_Block (D);
6811 -- Param1 := P.Param1;
6813 -- ParamN := P.ParamN;
6815 -- if Enqueued (Bnn) then
6816 -- <abortable-statements>
6819 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6822 -- when Abort_Signal => Abort_Undefer;
6825 -- if not Cancelled (Bnn) then
6826 -- <triggering-statements>
6829 -- elsif C = POK_Task_Entry then
6831 -- procedure _clean is
6833 -- Cancel_Task_Entry_Call (U);
6839 -- _Disp_Asynchronous_Select
6840 -- (<object>, S, P'Address, D, B);
6841 -- Bnn := Communication_Bloc (D);
6843 -- Param1 := P.Param1;
6845 -- ParamN := P.ParamN;
6850 -- <abortable-statements>
6852 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6855 -- when Abort_Signal => Abort_Undefer;
6859 -- <triggering-statements>
6864 -- <dispatching-call>;
6865 -- <triggering-statements>
6870 -- The job is to convert this to the asynchronous form
6872 -- If the trigger is a delay statement, it will have been expanded into
6873 -- a call to one of the GNARL delay procedures. This routine will convert
6874 -- this into a protected entry call on a delay object and then continue
6875 -- processing as for a protected entry call trigger. This requires
6876 -- declaring a Delay_Block object and adding a pointer to this object to
6877 -- the parameter list of the delay procedure to form the parameter list of
6878 -- the entry call. This object is used by the runtime to queue the delay
6881 -- For a description of the use of P and the assignments after the call,
6882 -- see Expand_N_Entry_Call_Statement.
6884 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6885 Loc
: constant Source_Ptr
:= Sloc
(N
);
6886 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6887 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6889 Abort_Block_Ent
: Entity_Id
;
6890 Abortable_Block
: Node_Id
;
6893 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6894 Blk_Typ
: Entity_Id
;
6896 Call_Ent
: Entity_Id
;
6897 Cancel_Param
: Entity_Id
;
6898 Cleanup_Block
: Node_Id
;
6899 Cleanup_Block_Ent
: Entity_Id
;
6900 Cleanup_Stmts
: List_Id
;
6901 Conc_Typ_Stmts
: List_Id
;
6903 Dblock_Ent
: Entity_Id
;
6908 Enqueue_Call
: Node_Id
;
6911 Handler_Stmt
: Node_Id
;
6913 Lim_Typ_Stmts
: List_Id
;
6919 ProtE_Stmts
: List_Id
;
6920 ProtP_Stmts
: List_Id
;
6923 TaskE_Stmts
: List_Id
;
6926 B
: Entity_Id
; -- Call status flag
6927 Bnn
: Entity_Id
; -- Communication block
6928 C
: Entity_Id
; -- Call kind
6929 K
: Entity_Id
; -- Tagged kind
6930 P
: Entity_Id
; -- Parameter block
6931 S
: Entity_Id
; -- Primitive operation slot
6932 T
: Entity_Id
; -- Additional status flag
6934 procedure Rewrite_Abortable_Part
;
6935 -- If the trigger is a dispatching call, the expansion inserts multiple
6936 -- copies of the abortable part. This is both inefficient, and may lead
6937 -- to duplicate definitions that the back-end will reject, when the
6938 -- abortable part includes loops. This procedure rewrites the abortable
6939 -- part into a call to a generated procedure.
6941 ----------------------------
6942 -- Rewrite_Abortable_Part --
6943 ----------------------------
6945 procedure Rewrite_Abortable_Part
is
6946 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6951 Make_Subprogram_Body
(Loc
,
6953 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6954 Declarations
=> New_List
,
6955 Handled_Statement_Sequence
=>
6956 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6957 Insert_Before
(N
, Decl
);
6960 -- Rewrite abortable part into a call to this procedure.
6964 Make_Procedure_Call_Statement
(Loc
,
6965 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6966 end Rewrite_Abortable_Part
;
6969 Process_Statements_For_Controlled_Objects
(Trig
);
6970 Process_Statements_For_Controlled_Objects
(Abrt
);
6972 Ecall
:= Triggering_Statement
(Trig
);
6974 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6976 -- Retrieve Astats and Tstats now because the finalization machinery may
6977 -- wrap them in blocks.
6979 Astats
:= Statements
(Abrt
);
6980 Tstats
:= Statements
(Trig
);
6982 -- The arguments in the call may require dynamic allocation, and the
6983 -- call statement may have been transformed into a block. The block
6984 -- may contain additional declarations for internal entities, and the
6985 -- original call is found by sequential search.
6987 if Nkind
(Ecall
) = N_Block_Statement
then
6988 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6989 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6990 N_Entry_Call_Statement
)
6996 -- This is either a dispatching call or a delay statement used as a
6997 -- trigger which was expanded into a procedure call.
6999 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
7000 if Ada_Version
>= Ada_2005
7002 (No
(Original_Node
(Ecall
))
7003 or else not Nkind_In
(Original_Node
(Ecall
),
7004 N_Delay_Relative_Statement
,
7005 N_Delay_Until_Statement
))
7007 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
7009 Rewrite_Abortable_Part
;
7013 -- Call status flag processing, generate:
7014 -- B : Boolean := False;
7016 B
:= Build_B
(Loc
, Decls
);
7018 -- Communication block processing, generate:
7019 -- Bnn : Communication_Block;
7021 Bnn
:= Make_Temporary
(Loc
, 'B');
7023 Make_Object_Declaration
(Loc
,
7024 Defining_Identifier
=> Bnn
,
7025 Object_Definition
=>
7026 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
7028 -- Call kind processing, generate:
7029 -- C : Ada.Tags.Prim_Op_Kind;
7031 C
:= Build_C
(Loc
, Decls
);
7033 -- Tagged kind processing, generate:
7034 -- K : Ada.Tags.Tagged_Kind :=
7035 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7037 -- Dummy communication block, generate:
7038 -- D : Dummy_Communication_Block;
7041 Make_Object_Declaration
(Loc
,
7042 Defining_Identifier
=>
7043 Make_Defining_Identifier
(Loc
, Name_uD
),
7044 Object_Definition
=>
7046 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
7048 K
:= Build_K
(Loc
, Decls
, Obj
);
7050 -- Parameter block processing
7052 Blk_Typ
:= Build_Parameter_Block
7053 (Loc
, Actuals
, Formals
, Decls
);
7054 P
:= Parameter_Block_Pack
7055 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7057 -- Dispatch table slot processing, generate:
7060 S
:= Build_S
(Loc
, Decls
);
7062 -- Additional status flag processing, generate:
7065 T
:= Make_Temporary
(Loc
, 'T');
7067 Make_Object_Declaration
(Loc
,
7068 Defining_Identifier
=> T
,
7069 Object_Definition
=>
7070 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7072 ------------------------------
7073 -- Protected entry handling --
7074 ------------------------------
7077 -- Param1 := P.Param1;
7079 -- ParamN := P.ParamN;
7081 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7084 -- Bnn := Communication_Block (D);
7086 Prepend_To
(Cleanup_Stmts
,
7087 Make_Assignment_Statement
(Loc
,
7088 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
7090 Make_Unchecked_Type_Conversion
(Loc
,
7092 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7093 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7096 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7098 Prepend_To
(Cleanup_Stmts
,
7099 Make_Procedure_Call_Statement
(Loc
,
7103 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
7105 Parameter_Associations
=>
7107 New_Copy_Tree
(Obj
), -- <object>
7108 New_Occurrence_Of
(S
, Loc
), -- S
7109 Make_Attribute_Reference
(Loc
, -- P'Address
7110 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7111 Attribute_Name
=> Name_Address
),
7112 Make_Identifier
(Loc
, Name_uD
), -- D
7113 New_Occurrence_Of
(B
, Loc
)))); -- B
7116 -- if Enqueued (Bnn) then
7117 -- <abortable-statements>
7120 Append_To
(Cleanup_Stmts
,
7121 Make_Implicit_If_Statement
(N
,
7123 Make_Function_Call
(Loc
,
7125 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7126 Parameter_Associations
=>
7127 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
7130 New_Copy_List_Tree
(Astats
)));
7132 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7133 -- will then generate a _clean for the communication block Bnn.
7137 -- procedure _clean is
7139 -- if Enqueued (Bnn) then
7140 -- Cancel_Protected_Entry_Call (Bnn);
7149 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7151 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7153 -- Wrap the cleanup block in an exception handling block
7159 -- when Abort_Signal => Abort_Undefer;
7162 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7165 Make_Implicit_Label_Declaration
(Loc
,
7166 Defining_Identifier
=> Abort_Block_Ent
),
7169 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7172 -- if not Cancelled (Bnn) then
7173 -- <triggering-statements>
7176 Append_To
(ProtE_Stmts
,
7177 Make_Implicit_If_Statement
(N
,
7181 Make_Function_Call
(Loc
,
7183 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7184 Parameter_Associations
=>
7185 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7188 New_Copy_List_Tree
(Tstats
)));
7190 -------------------------
7191 -- Task entry handling --
7192 -------------------------
7195 -- Param1 := P.Param1;
7197 -- ParamN := P.ParamN;
7199 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7202 -- Bnn := Communication_Block (D);
7204 Append_To
(TaskE_Stmts
,
7205 Make_Assignment_Statement
(Loc
,
7207 New_Occurrence_Of
(Bnn
, Loc
),
7209 Make_Unchecked_Type_Conversion
(Loc
,
7211 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7212 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7215 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7217 Prepend_To
(TaskE_Stmts
,
7218 Make_Procedure_Call_Statement
(Loc
,
7221 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7222 Name_uDisp_Asynchronous_Select
),
7225 Parameter_Associations
=>
7227 New_Copy_Tree
(Obj
), -- <object>
7228 New_Occurrence_Of
(S
, Loc
), -- S
7229 Make_Attribute_Reference
(Loc
, -- P'Address
7230 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7231 Attribute_Name
=> Name_Address
),
7232 Make_Identifier
(Loc
, Name_uD
), -- D
7233 New_Occurrence_Of
(B
, Loc
)))); -- B
7238 Prepend_To
(TaskE_Stmts
,
7239 Make_Procedure_Call_Statement
(Loc
,
7240 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Defer
), Loc
),
7241 Parameter_Associations
=> No_List
));
7245 -- <abortable-statements>
7247 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7249 Prepend_To
(Cleanup_Stmts
,
7250 Make_Procedure_Call_Statement
(Loc
,
7251 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
),
7252 Parameter_Associations
=> No_List
));
7254 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7255 -- will generate a _clean for the additional status flag.
7259 -- procedure _clean is
7261 -- Cancel_Task_Entry_Call (U);
7269 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7271 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7273 -- Wrap the cleanup block in an exception handling block
7279 -- when Abort_Signal => Abort_Undefer;
7282 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7284 Append_To
(TaskE_Stmts
,
7285 Make_Implicit_Label_Declaration
(Loc
,
7286 Defining_Identifier
=> Abort_Block_Ent
));
7288 Append_To
(TaskE_Stmts
,
7290 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7294 -- <triggering-statements>
7297 Append_To
(TaskE_Stmts
,
7298 Make_Implicit_If_Statement
(N
,
7300 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7303 New_Copy_List_Tree
(Tstats
)));
7305 ----------------------------------
7306 -- Protected procedure handling --
7307 ----------------------------------
7310 -- <dispatching-call>;
7311 -- <triggering-statements>
7313 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7314 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7317 -- S := Ada.Tags.Get_Offset_Index
7318 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7321 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7324 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7326 Append_To
(Conc_Typ_Stmts
,
7327 Make_Procedure_Call_Statement
(Loc
,
7330 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7331 Name_uDisp_Get_Prim_Op_Kind
),
7333 Parameter_Associations
=>
7335 New_Copy_Tree
(Obj
),
7336 New_Occurrence_Of
(S
, Loc
),
7337 New_Occurrence_Of
(C
, Loc
))));
7340 -- if C = POK_Procedure_Entry then
7342 -- elsif C = POK_Task_Entry then
7348 Append_To
(Conc_Typ_Stmts
,
7349 Make_Implicit_If_Statement
(N
,
7353 New_Occurrence_Of
(C
, Loc
),
7355 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7362 Make_Elsif_Part
(Loc
,
7366 New_Occurrence_Of
(C
, Loc
),
7368 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7377 -- <dispatching-call>;
7378 -- <triggering-statements>
7380 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7381 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7384 -- if K = Ada.Tags.TK_Limited_Tagged
7385 -- or else K = Ada.Tags.TK_Tagged
7393 Make_Implicit_If_Statement
(N
,
7394 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7395 Then_Statements
=> Lim_Typ_Stmts
,
7396 Else_Statements
=> Conc_Typ_Stmts
));
7399 Make_Block_Statement
(Loc
,
7402 Handled_Statement_Sequence
=>
7403 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7408 -- Delay triggering statement processing
7411 -- Add a Delay_Block object to the parameter list of the delay
7412 -- procedure to form the parameter list of the Wait entry call.
7414 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7416 Pdef
:= Entity
(Name
(Ecall
));
7418 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7420 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7422 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7424 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7426 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7427 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7430 Append_To
(Parameter_Associations
(Ecall
),
7431 Make_Attribute_Reference
(Loc
,
7432 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7433 Attribute_Name
=> Name_Unchecked_Access
));
7435 -- Create the inner block to protect the abortable part
7437 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7440 Make_Procedure_Call_Statement
(Loc
,
7441 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
)));
7444 Make_Block_Statement
(Loc
,
7445 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7446 Handled_Statement_Sequence
=>
7447 Make_Handled_Sequence_Of_Statements
(Loc
,
7448 Statements
=> Astats
),
7449 Has_Created_Identifier
=> True,
7450 Is_Asynchronous_Call_Block
=> True);
7452 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7455 Make_Implicit_If_Statement
(N
,
7457 Make_Function_Call
(Loc
,
7458 Name
=> Enqueue_Call
,
7459 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7461 New_List
(Make_Block_Statement
(Loc
,
7462 Handled_Statement_Sequence
=>
7463 Make_Handled_Sequence_Of_Statements
(Loc
,
7464 Statements
=> New_List
(
7465 Make_Implicit_Label_Declaration
(Loc
,
7466 Defining_Identifier
=> Blk_Ent
,
7467 Label_Construct
=> Abortable_Block
),
7469 Exception_Handlers
=> Hdle
)))));
7471 Stmts
:= New_List
(Ecall
);
7473 -- Construct statement sequence for new block
7476 Make_Implicit_If_Statement
(N
,
7478 Make_Function_Call
(Loc
,
7479 Name
=> New_Occurrence_Of
(
7480 RTE
(RE_Timed_Out
), Loc
),
7481 Parameter_Associations
=> New_List
(
7482 Make_Attribute_Reference
(Loc
,
7483 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7484 Attribute_Name
=> Name_Unchecked_Access
))),
7485 Then_Statements
=> Tstats
));
7487 -- The result is the new block
7489 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7492 Make_Block_Statement
(Loc
,
7493 Declarations
=> New_List
(
7494 Make_Object_Declaration
(Loc
,
7495 Defining_Identifier
=> Dblock_Ent
,
7496 Aliased_Present
=> True,
7497 Object_Definition
=>
7498 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7500 Handled_Statement_Sequence
=>
7501 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7511 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7512 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7514 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7515 Decls
:= Declarations
(Ecall
);
7517 if Is_Protected_Type
(Etype
(Concval
)) then
7519 -- Get the declarations of the block expanded from the entry call
7521 Decl
:= First
(Decls
);
7522 while Present
(Decl
)
7523 and then (Nkind
(Decl
) /= N_Object_Declaration
7524 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7525 RE_Communication_Block
))
7530 pragma Assert
(Present
(Decl
));
7531 Cancel_Param
:= Defining_Identifier
(Decl
);
7533 -- Change the mode of the Protected_Entry_Call call
7535 -- Protected_Entry_Call (
7536 -- Object => po._object'Access,
7537 -- E => <entry index>;
7538 -- Uninterpreted_Data => P'Address;
7539 -- Mode => Asynchronous_Call;
7542 -- Skip assignments to temporaries created for in-out parameters
7544 -- This makes unwarranted assumptions about the shape of the expanded
7545 -- tree for the call, and should be cleaned up ???
7547 Stmt
:= First
(Stmts
);
7548 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7554 Param
:= First
(Parameter_Associations
(Call
));
7555 while Present
(Param
)
7556 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7561 pragma Assert
(Present
(Param
));
7562 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7565 -- Append an if statement to execute the abortable part
7568 -- if Enqueued (Bnn) then
7571 Make_Implicit_If_Statement
(N
,
7573 Make_Function_Call
(Loc
,
7574 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7575 Parameter_Associations
=> New_List
(
7576 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7577 Then_Statements
=> Astats
));
7580 Make_Block_Statement
(Loc
,
7581 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7582 Handled_Statement_Sequence
=>
7583 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7584 Has_Created_Identifier
=> True,
7585 Is_Asynchronous_Call_Block
=> True);
7587 -- For the VM call Update_Exception instead of Abort_Undefer.
7588 -- See 4jexcept.ads for an explanation.
7590 if VM_Target
= No_VM
then
7591 if Exception_Mechanism
= Back_End_Exceptions
then
7593 -- Aborts are not deferred at beginning of exception handlers
7596 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7599 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7600 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
),
7601 Parameter_Associations
=> No_List
);
7604 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7605 Name
=> New_Occurrence_Of
(RTE
(RE_Update_Exception
), Loc
),
7606 Parameter_Associations
=> New_List
(
7607 Make_Function_Call
(Loc
,
7608 Name
=> New_Occurrence_Of
7609 (RTE
(RE_Current_Target_Exception
), Loc
))));
7613 Make_Block_Statement
(Loc
,
7614 Handled_Statement_Sequence
=>
7615 Make_Handled_Sequence_Of_Statements
(Loc
,
7616 Statements
=> New_List
(
7617 Make_Implicit_Label_Declaration
(Loc
,
7618 Defining_Identifier
=> Blk_Ent
,
7619 Label_Construct
=> Abortable_Block
),
7624 Exception_Handlers
=> New_List
(
7625 Make_Implicit_Exception_Handler
(Loc
,
7627 -- when Abort_Signal =>
7628 -- Abort_Undefer.all;
7630 Exception_Choices
=>
7631 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7632 Statements
=> New_List
(Handler_Stmt
))))),
7634 -- if not Cancelled (Bnn) then
7635 -- triggered statements
7638 Make_Implicit_If_Statement
(N
,
7639 Condition
=> Make_Op_Not
(Loc
,
7641 Make_Function_Call
(Loc
,
7642 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7643 Parameter_Associations
=> New_List
(
7644 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7645 Then_Statements
=> Tstats
));
7647 -- Asynchronous task entry call
7654 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7656 -- Insert declaration of B in declarations of existing block
7659 Make_Object_Declaration
(Loc
,
7660 Defining_Identifier
=> B
,
7661 Object_Definition
=>
7662 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7664 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7666 -- Insert declaration of C in declarations of existing block
7669 Make_Object_Declaration
(Loc
,
7670 Defining_Identifier
=> Cancel_Param
,
7671 Object_Definition
=>
7672 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7674 -- Remove and save the call to Call_Simple
7676 Stmt
:= First
(Stmts
);
7678 -- Skip assignments to temporaries created for in-out parameters.
7679 -- This makes unwarranted assumptions about the shape of the expanded
7680 -- tree for the call, and should be cleaned up ???
7682 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7688 -- Create the inner block to protect the abortable part
7690 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7693 Make_Procedure_Call_Statement
(Loc
,
7694 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
)));
7697 Make_Block_Statement
(Loc
,
7698 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7699 Handled_Statement_Sequence
=>
7700 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7701 Has_Created_Identifier
=> True,
7702 Is_Asynchronous_Call_Block
=> True);
7705 Make_Block_Statement
(Loc
,
7706 Handled_Statement_Sequence
=>
7707 Make_Handled_Sequence_Of_Statements
(Loc
,
7708 Statements
=> New_List
(
7709 Make_Implicit_Label_Declaration
(Loc
,
7710 Defining_Identifier
=> Blk_Ent
,
7711 Label_Construct
=> Abortable_Block
),
7713 Exception_Handlers
=> Hdle
)));
7715 -- Create new call statement
7717 Params
:= Parameter_Associations
(Call
);
7720 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7721 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7724 Make_Procedure_Call_Statement
(Loc
,
7725 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7726 Parameter_Associations
=> Params
));
7728 -- Construct statement sequence for new block
7731 Make_Implicit_If_Statement
(N
,
7733 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7734 Then_Statements
=> Tstats
));
7736 -- Protected the call against abort
7739 Make_Procedure_Call_Statement
(Loc
,
7740 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Defer
), Loc
),
7741 Parameter_Associations
=> Empty_List
));
7744 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7746 -- The result is the new block
7749 Make_Block_Statement
(Loc
,
7750 Declarations
=> Decls
,
7751 Handled_Statement_Sequence
=>
7752 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7755 end Expand_N_Asynchronous_Select
;
7757 -------------------------------------
7758 -- Expand_N_Conditional_Entry_Call --
7759 -------------------------------------
7761 -- The conditional task entry call is converted to a call to
7766 -- P : parms := (parm, parm, parm);
7770 -- (<acceptor-task>, -- Acceptor
7771 -- <entry-index>, -- E
7772 -- P'Address, -- Uninterpreted_Data
7773 -- Conditional_Call, -- Mode
7774 -- B); -- Rendezvous_Successful
7779 -- normal-statements
7785 -- For a description of the use of P and the assignments after the call,
7786 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7787 -- conditional entry call has already been expanded (by the Expand_N_Entry
7788 -- _Call_Statement procedure) as follows:
7791 -- P : parms := (parm, parm, parm);
7793 -- ... info for in-out parameters
7794 -- Call_Simple (acceptor-task, entry-index, P'Address);
7800 -- so the task at hand is to convert the latter expansion into the former
7802 -- The conditional protected entry call is converted to a call to
7803 -- Protected_Entry_Call:
7806 -- P : parms := (parm, parm, parm);
7807 -- Bnn : Communications_Block;
7810 -- Protected_Entry_Call
7811 -- (po._object'Access, -- Object
7812 -- <entry index>, -- E
7813 -- P'Address, -- Uninterpreted_Data
7814 -- Conditional_Call, -- Mode
7819 -- if Cancelled (Bnn) then
7822 -- normal-statements
7826 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7830 -- B : Boolean := False;
7831 -- C : Ada.Tags.Prim_Op_Kind;
7832 -- K : Ada.Tags.Tagged_Kind :=
7833 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7834 -- P : Parameters := (Param1 .. ParamN);
7838 -- if K = Ada.Tags.TK_Limited_Tagged
7839 -- or else K = Ada.Tags.TK_Tagged
7841 -- <dispatching-call>;
7842 -- <triggering-statements>
7846 -- Ada.Tags.Get_Offset_Index
7847 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7849 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7851 -- if C = POK_Protected_Entry
7852 -- or else C = POK_Task_Entry
7854 -- Param1 := P.Param1;
7856 -- ParamN := P.ParamN;
7860 -- if C = POK_Procedure
7861 -- or else C = POK_Protected_Procedure
7862 -- or else C = POK_Task_Procedure
7864 -- <dispatching-call>;
7867 -- <triggering-statements>
7869 -- <else-statements>
7874 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7875 Loc
: constant Source_Ptr
:= Sloc
(N
);
7876 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7877 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7880 Blk_Typ
: Entity_Id
;
7882 Call_Ent
: Entity_Id
;
7883 Conc_Typ_Stmts
: List_Id
;
7887 Lim_Typ_Stmts
: List_Id
;
7894 Transient_Blk
: Node_Id
;
7897 B
: Entity_Id
; -- Call status flag
7898 C
: Entity_Id
; -- Call kind
7899 K
: Entity_Id
; -- Tagged kind
7900 P
: Entity_Id
; -- Parameter block
7901 S
: Entity_Id
; -- Primitive operation slot
7904 Process_Statements_For_Controlled_Objects
(N
);
7906 if Ada_Version
>= Ada_2005
7907 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7909 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7914 -- Call status flag processing, generate:
7915 -- B : Boolean := False;
7917 B
:= Build_B
(Loc
, Decls
);
7919 -- Call kind processing, generate:
7920 -- C : Ada.Tags.Prim_Op_Kind;
7922 C
:= Build_C
(Loc
, Decls
);
7924 -- Tagged kind processing, generate:
7925 -- K : Ada.Tags.Tagged_Kind :=
7926 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7928 K
:= Build_K
(Loc
, Decls
, Obj
);
7930 -- Parameter block processing
7932 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7933 P
:= Parameter_Block_Pack
7934 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7936 -- Dispatch table slot processing, generate:
7939 S
:= Build_S
(Loc
, Decls
);
7942 -- S := Ada.Tags.Get_Offset_Index
7943 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7946 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7949 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7951 Append_To
(Conc_Typ_Stmts
,
7952 Make_Procedure_Call_Statement
(Loc
,
7955 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7956 Name_uDisp_Conditional_Select
),
7958 Parameter_Associations
=>
7960 New_Copy_Tree
(Obj
), -- <object>
7961 New_Occurrence_Of
(S
, Loc
), -- S
7962 Make_Attribute_Reference
(Loc
, -- P'Address
7963 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7964 Attribute_Name
=> Name_Address
),
7965 New_Occurrence_Of
(C
, Loc
), -- C
7966 New_Occurrence_Of
(B
, Loc
)))); -- B
7969 -- if C = POK_Protected_Entry
7970 -- or else C = POK_Task_Entry
7972 -- Param1 := P.Param1;
7974 -- ParamN := P.ParamN;
7977 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7979 -- Generate the if statement only when the packed parameters need
7980 -- explicit assignments to their corresponding actuals.
7982 if Present
(Unpack
) then
7983 Append_To
(Conc_Typ_Stmts
,
7984 Make_Implicit_If_Statement
(N
,
7990 New_Occurrence_Of
(C
, Loc
),
7992 New_Occurrence_Of
(RTE
(
7993 RE_POK_Protected_Entry
), Loc
)),
7998 New_Occurrence_Of
(C
, Loc
),
8000 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
8002 Then_Statements
=> Unpack
));
8007 -- if C = POK_Procedure
8008 -- or else C = POK_Protected_Procedure
8009 -- or else C = POK_Task_Procedure
8011 -- <dispatching-call>
8013 -- <normal-statements>
8015 -- <else-statements>
8018 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
8020 Prepend_To
(N_Stats
,
8021 Make_Implicit_If_Statement
(N
,
8027 New_Occurrence_Of
(C
, Loc
),
8029 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
8036 New_Occurrence_Of
(C
, Loc
),
8038 New_Occurrence_Of
(RTE
(
8039 RE_POK_Protected_Procedure
), Loc
)),
8044 New_Occurrence_Of
(C
, Loc
),
8046 New_Occurrence_Of
(RTE
(
8047 RE_POK_Task_Procedure
), Loc
)))),
8052 Append_To
(Conc_Typ_Stmts
,
8053 Make_Implicit_If_Statement
(N
,
8054 Condition
=> New_Occurrence_Of
(B
, Loc
),
8055 Then_Statements
=> N_Stats
,
8056 Else_Statements
=> Else_Statements
(N
)));
8059 -- <dispatching-call>;
8060 -- <triggering-statements>
8062 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
8063 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
8066 -- if K = Ada.Tags.TK_Limited_Tagged
8067 -- or else K = Ada.Tags.TK_Tagged
8075 Make_Implicit_If_Statement
(N
,
8076 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
8077 Then_Statements
=> Lim_Typ_Stmts
,
8078 Else_Statements
=> Conc_Typ_Stmts
));
8081 Make_Block_Statement
(Loc
,
8084 Handled_Statement_Sequence
=>
8085 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8087 -- As described above, the entry alternative is transformed into a
8088 -- block that contains the gnulli call, and possibly assignment
8089 -- statements for in-out parameters. The gnulli call may itself be
8090 -- rewritten into a transient block if some unconstrained parameters
8091 -- require it. We need to retrieve the call to complete its parameter
8096 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
8098 if Present
(Transient_Blk
)
8099 and then Nkind
(Transient_Blk
) = N_Block_Statement
8101 Blk
:= Transient_Blk
;
8104 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
8105 Stmt
:= First
(Stmts
);
8106 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
8111 Params
:= Parameter_Associations
(Call
);
8113 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
8115 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8117 Param
:= First
(Params
);
8118 while Present
(Param
)
8119 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
8124 pragma Assert
(Present
(Param
));
8126 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8130 -- Find the Communication_Block parameter for the call to the
8131 -- Cancelled function.
8133 Decl
:= First
(Declarations
(Blk
));
8134 while Present
(Decl
)
8135 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
8136 RE_Communication_Block
)
8141 -- Add an if statement to execute the else part if the call
8142 -- does not succeed (as indicated by the Cancelled predicate).
8145 Make_Implicit_If_Statement
(N
,
8146 Condition
=> Make_Function_Call
(Loc
,
8147 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
8148 Parameter_Associations
=> New_List
(
8149 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
8150 Then_Statements
=> Else_Statements
(N
),
8151 Else_Statements
=> Statements
(Alt
)));
8154 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8156 -- Insert declaration of B in declarations of existing block
8158 if No
(Declarations
(Blk
)) then
8159 Set_Declarations
(Blk
, New_List
);
8162 Prepend_To
(Declarations
(Blk
),
8163 Make_Object_Declaration
(Loc
,
8164 Defining_Identifier
=> B
,
8165 Object_Definition
=>
8166 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8168 -- Create new call statement
8171 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8172 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
8175 Make_Procedure_Call_Statement
(Loc
,
8176 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
8177 Parameter_Associations
=> Params
));
8179 -- Construct statement sequence for new block
8182 Make_Implicit_If_Statement
(N
,
8183 Condition
=> New_Occurrence_Of
(B
, Loc
),
8184 Then_Statements
=> Statements
(Alt
),
8185 Else_Statements
=> Else_Statements
(N
)));
8188 -- The result is the new block
8191 Make_Block_Statement
(Loc
,
8192 Declarations
=> Declarations
(Blk
),
8193 Handled_Statement_Sequence
=>
8194 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8198 end Expand_N_Conditional_Entry_Call
;
8200 ---------------------------------------
8201 -- Expand_N_Delay_Relative_Statement --
8202 ---------------------------------------
8204 -- Delay statement is implemented as a procedure call to Delay_For
8205 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8206 -- simple delays imposed by the use of Protected Objects.
8208 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8209 Loc
: constant Source_Ptr
:= Sloc
(N
);
8212 Make_Procedure_Call_Statement
(Loc
,
8213 Name
=> New_Occurrence_Of
(RTE
(RO_CA_Delay_For
), Loc
),
8214 Parameter_Associations
=> New_List
(Expression
(N
))));
8216 end Expand_N_Delay_Relative_Statement
;
8218 ------------------------------------
8219 -- Expand_N_Delay_Until_Statement --
8220 ------------------------------------
8222 -- Delay Until statement is implemented as a procedure call to
8223 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8225 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8226 Loc
: constant Source_Ptr
:= Sloc
(N
);
8230 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8231 Typ
:= RTE
(RO_CA_Delay_Until
);
8233 Typ
:= RTE
(RO_RT_Delay_Until
);
8237 Make_Procedure_Call_Statement
(Loc
,
8238 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8239 Parameter_Associations
=> New_List
(Expression
(N
))));
8242 end Expand_N_Delay_Until_Statement
;
8244 -------------------------
8245 -- Expand_N_Entry_Body --
8246 -------------------------
8248 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8250 -- Associate discriminals with the next protected operation body to be
8253 if Present
(Next_Protected_Operation
(N
)) then
8254 Set_Discriminals
(Parent
(Current_Scope
));
8256 end Expand_N_Entry_Body
;
8258 -----------------------------------
8259 -- Expand_N_Entry_Call_Statement --
8260 -----------------------------------
8262 -- An entry call is expanded into GNARLI calls to implement a simple entry
8263 -- call (see Build_Simple_Entry_Call).
8265 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8271 if No_Run_Time_Mode
then
8272 Error_Msg_CRT
("entry call", N
);
8276 -- If this entry call is part of an asynchronous select, don't expand it
8277 -- here; it will be expanded with the select statement. Don't expand
8278 -- timed entry calls either, as they are translated into asynchronous
8281 -- ??? This whole approach is questionable; it may be better to go back
8282 -- to allowing the expansion to take place and then attempting to fix it
8283 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8284 -- whether the expanded call is on a task or protected entry.
8286 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8287 or else N
/= Triggering_Statement
(Parent
(N
)))
8288 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8289 or else N
/= Entry_Call_Statement
(Parent
(N
))
8290 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8292 Extract_Entry
(N
, Concval
, Ename
, Index
);
8293 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8295 end Expand_N_Entry_Call_Statement
;
8297 --------------------------------
8298 -- Expand_N_Entry_Declaration --
8299 --------------------------------
8301 -- If there are parameters, then first, each of the formals is marked by
8302 -- setting Is_Entry_Formal. Next a record type is built which is used to
8303 -- hold the parameter values. The name of this record type is entryP where
8304 -- entry is the name of the entry, with an additional corresponding access
8305 -- type called entryPA. The record type has matching components for each
8306 -- formal (the component names are the same as the formal names). For
8307 -- elementary types, the component type matches the formal type. For
8308 -- composite types, an access type is declared (with the name formalA)
8309 -- which designates the formal type, and the type of the component is this
8310 -- access type. Finally the Entry_Component of each formal is set to
8311 -- reference the corresponding record component.
8313 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8314 Loc
: constant Source_Ptr
:= Sloc
(N
);
8315 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8316 Components
: List_Id
;
8319 Last_Decl
: Node_Id
;
8320 Component
: Entity_Id
;
8323 Rec_Ent
: Entity_Id
;
8324 Acc_Ent
: Entity_Id
;
8327 Formal
:= First_Formal
(Entry_Ent
);
8330 -- Most processing is done only if parameters are present
8332 if Present
(Formal
) then
8333 Components
:= New_List
;
8335 -- Loop through formals
8337 while Present
(Formal
) loop
8338 Set_Is_Entry_Formal
(Formal
);
8340 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8341 Set_Entry_Component
(Formal
, Component
);
8342 Set_Entry_Formal
(Component
, Formal
);
8343 Ftype
:= Etype
(Formal
);
8345 -- Declare new access type and then append
8347 Ctype
:= Make_Temporary
(Loc
, 'A');
8350 Make_Full_Type_Declaration
(Loc
,
8351 Defining_Identifier
=> Ctype
,
8353 Make_Access_To_Object_Definition
(Loc
,
8354 All_Present
=> True,
8355 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8356 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8358 Insert_After
(Last_Decl
, Decl
);
8361 Append_To
(Components
,
8362 Make_Component_Declaration
(Loc
,
8363 Defining_Identifier
=> Component
,
8364 Component_Definition
=>
8365 Make_Component_Definition
(Loc
,
8366 Aliased_Present
=> False,
8367 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8369 Next_Formal_With_Extras
(Formal
);
8372 -- Create the Entry_Parameter_Record declaration
8374 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8377 Make_Full_Type_Declaration
(Loc
,
8378 Defining_Identifier
=> Rec_Ent
,
8380 Make_Record_Definition
(Loc
,
8382 Make_Component_List
(Loc
,
8383 Component_Items
=> Components
)));
8385 Insert_After
(Last_Decl
, Decl
);
8388 -- Construct and link in the corresponding access type
8390 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8392 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8395 Make_Full_Type_Declaration
(Loc
,
8396 Defining_Identifier
=> Acc_Ent
,
8398 Make_Access_To_Object_Definition
(Loc
,
8399 All_Present
=> True,
8400 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8402 Insert_After
(Last_Decl
, Decl
);
8404 end Expand_N_Entry_Declaration
;
8406 -----------------------------
8407 -- Expand_N_Protected_Body --
8408 -----------------------------
8410 -- Protected bodies are expanded to the completion of the subprograms
8411 -- created for the corresponding protected type. These are a protected and
8412 -- unprotected version of each protected subprogram in the object, a
8413 -- function to calculate each entry barrier, and a procedure to execute the
8414 -- sequence of statements of each protected entry body. For example, for
8415 -- protected type ptype:
8418 -- (O : System.Address;
8419 -- E : Protected_Entry_Index)
8422 -- <discriminant renamings>
8423 -- <private object renamings>
8425 -- return <barrier expression>;
8428 -- procedure pprocN (_object : in out poV;...) is
8429 -- <discriminant renamings>
8430 -- <private object renamings>
8432 -- <sequence of statements>
8435 -- procedure pprocP (_object : in out poV;...) is
8436 -- procedure _clean is
8439 -- ptypeS (_object, Pn);
8440 -- Unlock (_object._object'Access);
8441 -- Abort_Undefer.all;
8446 -- Lock (_object._object'Access);
8447 -- pprocN (_object;...);
8452 -- function pfuncN (_object : poV;...) return Return_Type is
8453 -- <discriminant renamings>
8454 -- <private object renamings>
8456 -- <sequence of statements>
8459 -- function pfuncP (_object : poV) return Return_Type is
8460 -- procedure _clean is
8462 -- Unlock (_object._object'Access);
8463 -- Abort_Undefer.all;
8468 -- Lock (_object._object'Access);
8469 -- return pfuncN (_object);
8476 -- (O : System.Address;
8477 -- P : System.Address;
8478 -- E : Protected_Entry_Index)
8480 -- <discriminant renamings>
8481 -- <private object renamings>
8482 -- type poVP is access poV;
8483 -- _Object : ptVP := ptVP!(O);
8487 -- <statement sequence>
8488 -- Complete_Entry_Body (_Object._Object);
8490 -- when all others =>
8491 -- Exceptional_Complete_Entry_Body (
8492 -- _Object._Object, Get_GNAT_Exception);
8496 -- The type poV is the record created for the protected type to hold
8497 -- the state of the protected object.
8499 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8500 Loc
: constant Source_Ptr
:= Sloc
(N
);
8501 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8503 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8504 -- This flag indicates whether the lock free implementation is active
8506 Current_Node
: Node_Id
;
8507 Disp_Op_Body
: Node_Id
;
8508 New_Op_Body
: Node_Id
;
8512 function Build_Dispatching_Subprogram_Body
8515 Prot_Bod
: Node_Id
) return Node_Id
;
8516 -- Build a dispatching version of the protected subprogram body. The
8517 -- newly generated subprogram contains a call to the original protected
8518 -- body. The following code is generated:
8520 -- function <protected-function-name> (Param1 .. ParamN) return
8523 -- return <protected-function-name>P (Param1 .. ParamN);
8524 -- end <protected-function-name>;
8528 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8530 -- <protected-procedure-name>P (Param1 .. ParamN);
8531 -- end <protected-procedure-name>
8533 ---------------------------------------
8534 -- Build_Dispatching_Subprogram_Body --
8535 ---------------------------------------
8537 function Build_Dispatching_Subprogram_Body
8540 Prot_Bod
: Node_Id
) return Node_Id
8542 Loc
: constant Source_Ptr
:= Sloc
(N
);
8549 -- Generate a specification without a letter suffix in order to
8550 -- override an interface function or procedure.
8552 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8554 -- The formal parameters become the actuals of the protected function
8555 -- or procedure call.
8557 Actuals
:= New_List
;
8558 Formal
:= First
(Parameter_Specifications
(Spec
));
8559 while Present
(Formal
) loop
8561 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8565 if Nkind
(Spec
) = N_Procedure_Specification
then
8568 Make_Procedure_Call_Statement
(Loc
,
8570 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8571 Parameter_Associations
=> Actuals
));
8574 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8578 Make_Simple_Return_Statement
(Loc
,
8580 Make_Function_Call
(Loc
,
8582 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8583 Parameter_Associations
=> Actuals
)));
8587 Make_Subprogram_Body
(Loc
,
8588 Declarations
=> Empty_List
,
8589 Specification
=> Spec
,
8590 Handled_Statement_Sequence
=>
8591 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8592 end Build_Dispatching_Subprogram_Body
;
8594 -- Start of processing for Expand_N_Protected_Body
8597 if No_Run_Time_Mode
then
8598 Error_Msg_CRT
("protected body", N
);
8602 -- This is the proper body corresponding to a stub. The declarations
8603 -- must be inserted at the point of the stub, which in turn is in the
8604 -- declarative part of the parent unit.
8606 if Nkind
(Parent
(N
)) = N_Subunit
then
8607 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8612 Op_Body
:= First
(Declarations
(N
));
8614 -- The protected body is replaced with the bodies of its
8615 -- protected operations, and the declarations for internal objects
8616 -- that may have been created for entry family bounds.
8618 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8621 while Present
(Op_Body
) loop
8622 case Nkind
(Op_Body
) is
8623 when N_Subprogram_Declaration
=>
8626 when N_Subprogram_Body
=>
8628 -- Do not create bodies for eliminated operations
8630 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8631 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8633 if Lock_Free_Active
then
8635 Build_Lock_Free_Unprotected_Subprogram_Body
8639 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8642 Insert_After
(Current_Node
, New_Op_Body
);
8643 Current_Node
:= New_Op_Body
;
8644 Analyze
(New_Op_Body
);
8646 -- Build the corresponding protected operation. It may
8647 -- appear that this is needed only if this is a visible
8648 -- operation of the type, or if it is an interrupt handler,
8649 -- and this was the strategy used previously in GNAT.
8651 -- However, the operation may be exported through a 'Access
8652 -- to an external caller. This is the common idiom in code
8653 -- that uses the Ada 2005 Timing_Events package. As a result
8654 -- we need to produce the protected body for both visible
8655 -- and private operations, as well as operations that only
8656 -- have a body in the source, and for which we create a
8657 -- declaration in the protected body itself.
8659 if Present
(Corresponding_Spec
(Op_Body
)) then
8660 if Lock_Free_Active
then
8662 Build_Lock_Free_Protected_Subprogram_Body
8663 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8666 Build_Protected_Subprogram_Body
8667 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8670 Insert_After
(Current_Node
, New_Op_Body
);
8671 Analyze
(New_Op_Body
);
8673 Current_Node
:= New_Op_Body
;
8675 -- Generate an overriding primitive operation body for
8676 -- this subprogram if the protected type implements an
8679 if Ada_Version
>= Ada_2005
8681 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8684 Build_Dispatching_Subprogram_Body
8685 (Op_Body
, Pid
, New_Op_Body
);
8687 Insert_After
(Current_Node
, Disp_Op_Body
);
8688 Analyze
(Disp_Op_Body
);
8690 Current_Node
:= Disp_Op_Body
;
8695 when N_Entry_Body
=>
8696 Op_Id
:= Defining_Identifier
(Op_Body
);
8697 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8699 Insert_After
(Current_Node
, New_Op_Body
);
8700 Current_Node
:= New_Op_Body
;
8701 Analyze
(New_Op_Body
);
8703 when N_Implicit_Label_Declaration
=>
8706 when N_Itype_Reference
=>
8707 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8709 when N_Freeze_Entity
=>
8710 New_Op_Body
:= New_Copy
(Op_Body
);
8712 if Present
(Entity
(Op_Body
))
8713 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8715 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8718 Insert_After
(Current_Node
, New_Op_Body
);
8719 Current_Node
:= New_Op_Body
;
8720 Analyze
(New_Op_Body
);
8723 New_Op_Body
:= New_Copy
(Op_Body
);
8724 Insert_After
(Current_Node
, New_Op_Body
);
8725 Current_Node
:= New_Op_Body
;
8726 Analyze
(New_Op_Body
);
8728 when N_Object_Declaration
=>
8729 pragma Assert
(not Comes_From_Source
(Op_Body
));
8730 New_Op_Body
:= New_Copy
(Op_Body
);
8731 Insert_After
(Current_Node
, New_Op_Body
);
8732 Current_Node
:= New_Op_Body
;
8733 Analyze
(New_Op_Body
);
8736 raise Program_Error
;
8743 -- Finally, create the body of the function that maps an entry index
8744 -- into the corresponding body index, except when there is no entry, or
8745 -- in a Ravenscar-like profile.
8747 if Corresponding_Runtime_Package
(Pid
) =
8748 System_Tasking_Protected_Objects_Entries
8750 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8751 Insert_After
(Current_Node
, New_Op_Body
);
8752 Current_Node
:= New_Op_Body
;
8753 Analyze
(New_Op_Body
);
8756 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8757 -- protected body. At this point all wrapper specs have been created,
8758 -- frozen and included in the dispatch table for the protected type.
8760 if Ada_Version
>= Ada_2005
then
8761 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8763 end Expand_N_Protected_Body
;
8765 -----------------------------------------
8766 -- Expand_N_Protected_Type_Declaration --
8767 -----------------------------------------
8769 -- First we create a corresponding record type declaration used to
8770 -- represent values of this protected type.
8771 -- The general form of this type declaration is
8773 -- type poV (discriminants) is record
8774 -- _Object : aliased <kind>Protection
8775 -- [(<entry count> [, <handler count>])];
8776 -- [entry_family : array (bounds) of Void;]
8777 -- <private data fields>
8780 -- The discriminants are present only if the corresponding protected type
8781 -- has discriminants, and they exactly mirror the protected type
8782 -- discriminants. The private data fields similarly mirror the private
8783 -- declarations of the protected type.
8785 -- The Object field is always present. It contains RTS specific data used
8786 -- to control the protected object. It is declared as Aliased so that it
8787 -- can be passed as a pointer to the RTS. This allows the protected record
8788 -- to be referenced within RTS data structures. An appropriate Protection
8789 -- type and discriminant are generated.
8791 -- The Service field is present for protected objects with entries. It
8792 -- contains sufficient information to allow the entry service procedure for
8793 -- this object to be called when the object is not known till runtime.
8795 -- One entry_family component is present for each entry family in the
8796 -- task definition (see Expand_N_Task_Type_Declaration).
8798 -- When a protected object is declared, an instance of the protected type
8799 -- value record is created. The elaboration of this declaration creates the
8800 -- correct bounds for the entry families, and also evaluates the priority
8801 -- expression if needed. The initialization routine for the protected type
8802 -- itself then calls Initialize_Protection with appropriate parameters to
8803 -- initialize the value of the Task_Id field. Install_Handlers may be also
8804 -- called if a pragma Attach_Handler applies.
8806 -- Note: this record is passed to the subprograms created by the expansion
8807 -- of protected subprograms and entries. It is an in parameter to protected
8808 -- functions and an in out parameter to procedures and entry bodies. The
8809 -- Entity_Id for this created record type is placed in the
8810 -- Corresponding_Record_Type field of the associated protected type entity.
8812 -- Next we create a procedure specifications for protected subprograms and
8813 -- entry bodies. For each protected subprograms two subprograms are
8814 -- created, an unprotected and a protected version. The unprotected version
8815 -- is called from within other operations of the same protected object.
8817 -- We also build the call to register the procedure if a pragma
8818 -- Interrupt_Handler applies.
8820 -- A single subprogram is created to service all entry bodies; it has an
8821 -- additional boolean out parameter indicating that the previous entry call
8822 -- made by the current task was serviced immediately, i.e. not by proxy.
8823 -- The O parameter contains a pointer to a record object of the type
8824 -- described above. An untyped interface is used here to allow this
8825 -- procedure to be called in places where the type of the object to be
8826 -- serviced is not known. This must be done, for example, when a call that
8827 -- may have been requeued is cancelled; the corresponding object must be
8828 -- serviced, but which object that is not known till runtime.
8831 -- (O : System.Address; P : out Boolean);
8832 -- procedure pprocN (_object : in out poV);
8833 -- procedure pproc (_object : in out poV);
8834 -- function pfuncN (_object : poV);
8835 -- function pfunc (_object : poV);
8838 -- Note that this must come after the record type declaration, since
8839 -- the specs refer to this type.
8841 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8842 Loc
: constant Source_Ptr
:= Sloc
(N
);
8843 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8845 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8846 -- This flag indicates whether the lock free implementation is active
8848 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8849 -- This contains two lists; one for visible and one for private decls
8853 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8857 Comp_Id
: Entity_Id
;
8859 Current_Node
: Node_Id
:= N
;
8860 Entries_Aggr
: Node_Id
;
8861 Body_Id
: Entity_Id
;
8864 Object_Comp
: Node_Id
;
8866 procedure Check_Inlining
(Subp
: Entity_Id
);
8867 -- If the original operation has a pragma Inline, propagate the flag
8868 -- to the internal body, for possible inlining later on. The source
8869 -- operation is invisible to the back-end and is never actually called.
8871 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean;
8872 -- If a component size is not static then a warning will be emitted
8873 -- in Ravenscar or other restricted contexts. When a component is non-
8874 -- static because of a discriminant constraint we can specialize the
8875 -- warning by mentioning discriminants explicitly.
8877 procedure Expand_Entry_Declaration
(Comp
: Entity_Id
);
8878 -- Create the subprograms for the barrier and for the body, and append
8879 -- then to Entry_Bodies_Array.
8881 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8882 -- When compiling under the Ravenscar profile, private components must
8883 -- have a static size, or else a protected object will require heap
8884 -- allocation, violating the corresponding restriction. It is preferable
8885 -- to make this check here, because it provides a better error message
8886 -- than the back-end, which refers to the object as a whole.
8888 procedure Register_Handler
;
8889 -- For a protected operation that is an interrupt handler, add the
8890 -- freeze action that will register it as such.
8892 --------------------
8893 -- Check_Inlining --
8894 --------------------
8896 procedure Check_Inlining
(Subp
: Entity_Id
) is
8898 if Is_Inlined
(Subp
) then
8899 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8900 Set_Is_Inlined
(Subp
, False);
8904 ------------------------
8905 -- Discriminated_Size --
8906 ------------------------
8908 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean is
8909 Typ
: constant Entity_Id
:= Etype
(Comp
);
8912 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean;
8913 -- Check whether the bound of an index is non-static and does denote
8914 -- a discriminant, in which case any protected object of the type
8915 -- will have a non-static size.
8917 ----------------------
8918 -- Non_Static_Bound --
8919 ----------------------
8921 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean is
8923 if Is_OK_Static_Expression
(Bound
) then
8926 elsif Is_Entity_Name
(Bound
)
8927 and then Present
(Discriminal_Link
(Entity
(Bound
)))
8934 end Non_Static_Bound
;
8936 -- Start of processing for Discriminated_Size
8939 if not Is_Array_Type
(Typ
) then
8943 if Ekind
(Typ
) = E_Array_Subtype
then
8944 Index
:= First_Index
(Typ
);
8945 while Present
(Index
) loop
8946 if Non_Static_Bound
(Low_Bound
(Index
))
8947 or else Non_Static_Bound
(High_Bound
(Index
))
8959 end Discriminated_Size
;
8961 ---------------------------
8962 -- Static_Component_Size --
8963 ---------------------------
8965 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8966 Typ
: constant Entity_Id
:= Etype
(Comp
);
8970 if Is_Scalar_Type
(Typ
) then
8973 elsif Is_Array_Type
(Typ
) then
8974 return Compile_Time_Known_Bounds
(Typ
);
8976 elsif Is_Record_Type
(Typ
) then
8977 C
:= First_Component
(Typ
);
8978 while Present
(C
) loop
8979 if not Static_Component_Size
(C
) then
8988 -- Any other type will be checked by the back-end
8993 end Static_Component_Size
;
8995 ------------------------------
8996 -- Expand_Entry_Declaration --
8997 ------------------------------
8999 procedure Expand_Entry_Declaration
(Comp
: Entity_Id
) is
9004 E_Count
:= E_Count
+ 1;
9005 Comp_Id
:= Defining_Identifier
(Comp
);
9008 Make_Defining_Identifier
(Loc
,
9009 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9011 Make_Subprogram_Declaration
(Loc
,
9013 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9015 Insert_After
(Current_Node
, Sub
);
9018 -- Build wrapper procedure for pre/postconditions
9020 Build_PPC_Wrapper
(Comp_Id
, N
);
9022 Set_Protected_Body_Subprogram
9023 (Defining_Identifier
(Comp
),
9024 Defining_Unit_Name
(Specification
(Sub
)));
9026 Current_Node
:= Sub
;
9029 Make_Defining_Identifier
(Loc
,
9030 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
9032 Make_Subprogram_Declaration
(Loc
,
9034 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9036 Insert_After
(Current_Node
, Sub
);
9038 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9039 Set_Barrier_Function
(Comp_Id
, Bdef
);
9040 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9041 Current_Node
:= Sub
;
9043 -- Collect pointers to the protected subprogram and the barrier
9044 -- of the current entry, for insertion into Entry_Bodies_Array.
9046 Append_To
(Expressions
(Entries_Aggr
),
9047 Make_Aggregate
(Loc
,
9048 Expressions
=> New_List
(
9049 Make_Attribute_Reference
(Loc
,
9050 Prefix
=> New_Occurrence_Of
(Bdef
, Loc
),
9051 Attribute_Name
=> Name_Unrestricted_Access
),
9052 Make_Attribute_Reference
(Loc
,
9053 Prefix
=> New_Occurrence_Of
(Edef
, Loc
),
9054 Attribute_Name
=> Name_Unrestricted_Access
))));
9055 end Expand_Entry_Declaration
;
9057 ----------------------
9058 -- Register_Handler --
9059 ----------------------
9061 procedure Register_Handler
is
9063 -- All semantic checks already done in Sem_Prag
9065 Prot_Proc
: constant Entity_Id
:=
9066 Defining_Unit_Name
(Specification
(Current_Node
));
9068 Proc_Address
: constant Node_Id
:=
9069 Make_Attribute_Reference
(Loc
,
9071 New_Occurrence_Of
(Prot_Proc
, Loc
),
9072 Attribute_Name
=> Name_Address
);
9074 RTS_Call
: constant Entity_Id
:=
9075 Make_Procedure_Call_Statement
(Loc
,
9078 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
9079 Parameter_Associations
=> New_List
(Proc_Address
));
9081 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
9082 end Register_Handler
;
9084 -- Start of processing for Expand_N_Protected_Type_Declaration
9087 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
9090 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
9093 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
9095 Qualify_Entity_Names
(N
);
9097 -- If the type has discriminants, their occurrences in the declaration
9098 -- have been replaced by the corresponding discriminals. For components
9099 -- that are constrained by discriminants, their homologues in the
9100 -- corresponding record type must refer to the discriminants of that
9101 -- record, so we must apply a new renaming to subtypes_indications:
9103 -- protected discriminant => discriminal => record discriminant
9105 -- This replacement is not applied to default expressions, for which
9106 -- the discriminal is correct.
9108 if Has_Discriminants
(Prot_Typ
) then
9114 Disc
:= First_Discriminant
(Prot_Typ
);
9115 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
9116 while Present
(Disc
) loop
9117 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
9118 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
9119 Next_Discriminant
(Disc
);
9125 -- Fill in the component declarations
9127 -- Add components for entry families. For each entry family, create an
9128 -- anonymous type declaration with the same size, and analyze the type.
9130 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9132 pragma Assert
(Present
(Pdef
));
9134 -- Add private field components
9136 if Present
(Private_Declarations
(Pdef
)) then
9137 Priv
:= First
(Private_Declarations
(Pdef
));
9138 while Present
(Priv
) loop
9139 if Nkind
(Priv
) = N_Component_Declaration
then
9140 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9142 -- When compiling for a restricted profile, the private
9143 -- components must have a static size. If not, this is an
9144 -- error for a single protected declaration, and rates a
9145 -- warning on a protected type declaration.
9147 if not Comes_From_Source
(Prot_Typ
) then
9149 -- It's ok to be checking this restriction at expansion
9150 -- time, because this is only for the restricted profile,
9151 -- which is not subject to strict RM conformance, so it
9152 -- is OK to miss this check in -gnatc mode.
9154 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9156 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9157 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9160 -- Any object of the type will be non-static.
9162 Error_Msg_N
("component has non-static size??", Priv
);
9164 ("\creation of protected object of type& will"
9165 & " violate restriction "
9166 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9169 -- Object will be non-static if discriminants are.
9172 ("creation of protected object of type& with "
9173 & "non-static discriminants will violate"
9174 & " restriction No_Implicit_Heap_Allocations??",
9180 -- The component definition consists of a subtype indication,
9181 -- or (in Ada 2005) an access definition. Make a copy of the
9182 -- proper definition.
9185 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9186 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9188 Nent
: constant Entity_Id
:=
9189 Make_Defining_Identifier
(Sloc
(Oent
),
9190 Chars
=> Chars
(Oent
));
9193 if Present
(Subtype_Indication
(Old_Comp
)) then
9195 Make_Component_Definition
(Sloc
(Oent
),
9196 Aliased_Present
=> False,
9197 Subtype_Indication
=>
9198 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
9202 Make_Component_Definition
(Sloc
(Oent
),
9203 Aliased_Present
=> False,
9204 Access_Definition
=>
9205 New_Copy_Tree
(Access_Definition
(Old_Comp
),
9210 Make_Component_Declaration
(Loc
,
9211 Defining_Identifier
=> Nent
,
9212 Component_Definition
=> New_Comp
,
9213 Expression
=> Expression
(Priv
));
9215 Set_Has_Per_Object_Constraint
(Nent
,
9216 Has_Per_Object_Constraint
(Oent
));
9218 Append_To
(Cdecls
, New_Priv
);
9221 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9223 -- Make the unprotected version of the subprogram available
9224 -- for expansion of intra object calls. There is need for
9225 -- a protected version only if the subprogram is an interrupt
9226 -- handler, otherwise this operation can only be called from
9230 Make_Subprogram_Declaration
(Loc
,
9232 Build_Protected_Sub_Specification
9233 (Priv
, Prot_Typ
, Unprotected_Mode
));
9235 Insert_After
(Current_Node
, Sub
);
9238 Set_Protected_Body_Subprogram
9239 (Defining_Unit_Name
(Specification
(Priv
)),
9240 Defining_Unit_Name
(Specification
(Sub
)));
9241 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9242 Current_Node
:= Sub
;
9245 Make_Subprogram_Declaration
(Loc
,
9247 Build_Protected_Sub_Specification
9248 (Priv
, Prot_Typ
, Protected_Mode
));
9250 Insert_After
(Current_Node
, Sub
);
9252 Current_Node
:= Sub
;
9254 if Is_Interrupt_Handler
9255 (Defining_Unit_Name
(Specification
(Priv
)))
9257 if not Restricted_Profile
then
9267 -- Except for the lock-free implementation, append the _Object field
9268 -- with the right type to the component list. We need to compute the
9269 -- number of entries, and in some cases the number of Attach_Handler
9272 if not Lock_Free_Active
then
9275 Num_Attach_Handler
: Int
:= 0;
9276 Protection_Subtype
: Node_Id
;
9277 Entry_Count_Expr
: constant Node_Id
:=
9278 Build_Entry_Count_Expression
9279 (Prot_Typ
, Cdecls
, Loc
);
9282 if Has_Attach_Handler
(Prot_Typ
) then
9283 Ritem
:= First_Rep_Item
(Prot_Typ
);
9284 while Present
(Ritem
) loop
9285 if Nkind
(Ritem
) = N_Pragma
9286 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9288 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9291 Next_Rep_Item
(Ritem
);
9295 -- Determine the proper protection type. There are two special
9296 -- cases: 1) when the protected type has dynamic interrupt
9297 -- handlers, and 2) when it has static handlers and we use a
9298 -- restricted profile.
9300 if Has_Attach_Handler
(Prot_Typ
)
9301 and then not Restricted_Profile
9303 Protection_Subtype
:=
9304 Make_Subtype_Indication
(Loc
,
9307 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9309 Make_Index_Or_Discriminant_Constraint
(Loc
,
9310 Constraints
=> New_List
(
9312 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9314 elsif Has_Interrupt_Handler
(Prot_Typ
)
9315 and then not Restriction_Active
(No_Dynamic_Attachment
)
9317 Protection_Subtype
:=
9318 Make_Subtype_Indication
(Loc
,
9321 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9323 Make_Index_Or_Discriminant_Constraint
(Loc
,
9324 Constraints
=> New_List
(Entry_Count_Expr
)));
9327 case Corresponding_Runtime_Package
(Prot_Typ
) is
9328 when System_Tasking_Protected_Objects_Entries
=>
9329 Protection_Subtype
:=
9330 Make_Subtype_Indication
(Loc
,
9333 (RTE
(RE_Protection_Entries
), Loc
),
9335 Make_Index_Or_Discriminant_Constraint
(Loc
,
9336 Constraints
=> New_List
(Entry_Count_Expr
)));
9338 when System_Tasking_Protected_Objects_Single_Entry
=>
9339 Protection_Subtype
:=
9340 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9342 when System_Tasking_Protected_Objects
=>
9343 Protection_Subtype
:=
9344 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9347 raise Program_Error
;
9352 Make_Component_Declaration
(Loc
,
9353 Defining_Identifier
=>
9354 Make_Defining_Identifier
(Loc
, Name_uObject
),
9355 Component_Definition
=>
9356 Make_Component_Definition
(Loc
,
9357 Aliased_Present
=> True,
9358 Subtype_Indication
=> Protection_Subtype
));
9361 -- Put the _Object component after the private component so that it
9362 -- be finalized early as required by 9.4 (20)
9364 Append_To
(Cdecls
, Object_Comp
);
9367 Insert_After
(Current_Node
, Rec_Decl
);
9368 Current_Node
:= Rec_Decl
;
9370 -- Analyze the record declaration immediately after construction,
9371 -- because the initialization procedure is needed for single object
9372 -- declarations before the next entity is analyzed (the freeze call
9373 -- that generates this initialization procedure is found below).
9375 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9377 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9378 -- the corresponding record is frozen. If any wrappers are generated,
9379 -- Current_Node is updated accordingly.
9381 if Ada_Version
>= Ada_2005
then
9382 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9385 -- Collect pointers to entry bodies and their barriers, to be placed
9386 -- in the Entry_Bodies_Array for the type. For each entry/family we
9387 -- add an expression to the aggregate which is the initial value of
9388 -- this array. The array is declared after all protected subprograms.
9390 if Has_Entries
(Prot_Typ
) then
9391 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9393 Entries_Aggr
:= Empty
;
9396 -- Build two new procedure specifications for each protected subprogram;
9397 -- one to call from outside the object and one to call from inside.
9398 -- Build a barrier function and an entry body action procedure
9399 -- specification for each protected entry. Initialize the entry body
9400 -- array. If subprogram is flagged as eliminated, do not generate any
9401 -- internal operations.
9404 Comp
:= First
(Visible_Declarations
(Pdef
));
9405 while Present
(Comp
) loop
9406 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9408 Make_Subprogram_Declaration
(Loc
,
9410 Build_Protected_Sub_Specification
9411 (Comp
, Prot_Typ
, Unprotected_Mode
));
9413 Insert_After
(Current_Node
, Sub
);
9416 Set_Protected_Body_Subprogram
9417 (Defining_Unit_Name
(Specification
(Comp
)),
9418 Defining_Unit_Name
(Specification
(Sub
)));
9419 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9421 -- Make the protected version of the subprogram available for
9422 -- expansion of external calls.
9424 Current_Node
:= Sub
;
9427 Make_Subprogram_Declaration
(Loc
,
9429 Build_Protected_Sub_Specification
9430 (Comp
, Prot_Typ
, Protected_Mode
));
9432 Insert_After
(Current_Node
, Sub
);
9435 Current_Node
:= Sub
;
9437 -- Generate an overriding primitive operation specification for
9438 -- this subprogram if the protected type implements an interface.
9440 if Ada_Version
>= Ada_2005
9442 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9445 Make_Subprogram_Declaration
(Loc
,
9447 Build_Protected_Sub_Specification
9448 (Comp
, Prot_Typ
, Dispatching_Mode
));
9450 Insert_After
(Current_Node
, Sub
);
9453 Current_Node
:= Sub
;
9456 -- If a pragma Interrupt_Handler applies, build and add a call to
9457 -- Register_Interrupt_Handler to the freezing actions of the
9458 -- protected version (Current_Node) of the subprogram:
9460 -- system.interrupts.register_interrupt_handler
9461 -- (prot_procP'address);
9463 if not Restricted_Profile
9464 and then Is_Interrupt_Handler
9465 (Defining_Unit_Name
(Specification
(Comp
)))
9470 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9472 Expand_Entry_Declaration
(Comp
);
9479 -- If there are some private entry declarations, expand it as if they
9480 -- were visible entries.
9482 if Present
(Private_Declarations
(Pdef
)) then
9483 Comp
:= First
(Private_Declarations
(Pdef
));
9484 while Present
(Comp
) loop
9485 if Nkind
(Comp
) = N_Entry_Declaration
then
9486 Expand_Entry_Declaration
(Comp
);
9493 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9494 -- all protected subprograms have been collected.
9496 if Has_Entries
(Prot_Typ
) then
9498 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9499 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9501 case Corresponding_Runtime_Package
(Prot_Typ
) is
9502 when System_Tasking_Protected_Objects_Entries
=>
9503 Body_Arr
:= Make_Object_Declaration
(Loc
,
9504 Defining_Identifier
=> Body_Id
,
9505 Aliased_Present
=> True,
9506 Object_Definition
=>
9507 Make_Subtype_Indication
(Loc
,
9508 Subtype_Mark
=> New_Occurrence_Of
(
9509 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9511 Make_Index_Or_Discriminant_Constraint
(Loc
,
9512 Constraints
=> New_List
(
9514 Make_Integer_Literal
(Loc
, 1),
9515 Make_Integer_Literal
(Loc
, E_Count
))))),
9516 Expression
=> Entries_Aggr
);
9518 when System_Tasking_Protected_Objects_Single_Entry
=>
9519 Body_Arr
:= Make_Object_Declaration
(Loc
,
9520 Defining_Identifier
=> Body_Id
,
9521 Aliased_Present
=> True,
9522 Object_Definition
=> New_Occurrence_Of
9523 (RTE
(RE_Entry_Body
), Loc
),
9524 Expression
=> Remove_Head
(Expressions
(Entries_Aggr
)));
9527 raise Program_Error
;
9530 -- A pointer to this array will be placed in the corresponding record
9531 -- by its initialization procedure so this needs to be analyzed here.
9533 Insert_After
(Current_Node
, Body_Arr
);
9534 Current_Node
:= Body_Arr
;
9537 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9539 -- Finally, build the function that maps an entry index into the
9540 -- corresponding body. A pointer to this function is placed in each
9541 -- object of the type. Except for a ravenscar-like profile (no abort,
9542 -- no entry queue, 1 entry)
9544 if Corresponding_Runtime_Package
(Prot_Typ
) =
9545 System_Tasking_Protected_Objects_Entries
9548 Make_Subprogram_Declaration
(Loc
,
9549 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9550 Insert_After
(Current_Node
, Sub
);
9554 end Expand_N_Protected_Type_Declaration
;
9556 --------------------------------
9557 -- Expand_N_Requeue_Statement --
9558 --------------------------------
9560 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9561 -- operations, depending on the source and destination (task or protected
9562 -- object). A dispatching requeue statement is expanded into a call to the
9563 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9564 -- jump around the remainder of processing for the original entry and, if
9565 -- the destination is (different) protected object, to attempt to service
9566 -- it. The following illustrates the various cases:
9569 -- (O : System.Address;
9570 -- P : System.Address;
9571 -- E : Protected_Entry_Index)
9573 -- <discriminant renamings>
9574 -- <private object renamings>
9575 -- type poVP is access poV;
9576 -- _object : ptVP := ptVP!(O);
9580 -- <start of statement sequence for entry>
9582 -- -- Requeue from one protected entry body to another protected
9585 -- Requeue_Protected_Entry (
9586 -- _object._object'Access,
9587 -- new._object'Access,
9592 -- <some more of the statement sequence for entry>
9594 -- -- Requeue from an entry body to a task entry
9596 -- Requeue_Protected_To_Task_Entry (
9602 -- <rest of statement sequence for entry>
9603 -- Complete_Entry_Body (_object._object);
9606 -- when all others =>
9607 -- Exceptional_Complete_Entry_Body (
9608 -- _object._object, Get_GNAT_Exception);
9612 -- Requeue of a task entry call to a task entry
9614 -- Accept_Call (E, Ann);
9615 -- <start of statement sequence for accept statement>
9616 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9618 -- <rest of statement sequence for accept statement>
9620 -- Complete_Rendezvous;
9623 -- when all others =>
9624 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9626 -- Requeue of a task entry call to a protected entry
9628 -- Accept_Call (E, Ann);
9629 -- <start of statement sequence for accept statement>
9630 -- Requeue_Task_To_Protected_Entry (
9631 -- new._object'Access,
9636 -- <rest of statement sequence for accept statement>
9638 -- Complete_Rendezvous;
9641 -- when all others =>
9642 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9644 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9645 -- marked by pragma Implemented (XXX, By_Entry).
9647 -- The requeue is inside a protected entry:
9650 -- (O : System.Address;
9651 -- P : System.Address;
9652 -- E : Protected_Entry_Index)
9654 -- <discriminant renamings>
9655 -- <private object renamings>
9656 -- type poVP is access poV;
9657 -- _object : ptVP := ptVP!(O);
9661 -- <start of statement sequence for entry>
9664 -- (<interface class-wide object>,
9667 -- Ada.Tags.Get_Offset_Index
9669 -- <interface dispatch table index of target entry>),
9673 -- <rest of statement sequence for entry>
9674 -- Complete_Entry_Body (_object._object);
9677 -- when all others =>
9678 -- Exceptional_Complete_Entry_Body (
9679 -- _object._object, Get_GNAT_Exception);
9683 -- The requeue is inside a task entry:
9685 -- Accept_Call (E, Ann);
9686 -- <start of statement sequence for accept statement>
9688 -- (<interface class-wide object>,
9691 -- Ada.Tags.Get_Offset_Index
9693 -- <interface dispatch table index of target entrt>),
9697 -- <rest of statement sequence for accept statement>
9699 -- Complete_Rendezvous;
9702 -- when all others =>
9703 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9705 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9706 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9707 -- statement is replaced by a dispatching call with actual parameters taken
9708 -- from the inner-most accept statement or entry body.
9710 -- Target.Primitive (Param1, ..., ParamN);
9712 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9713 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9717 -- S : constant Offset_Index :=
9718 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9719 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9722 -- if C = POK_Protected_Entry
9723 -- or else C = POK_Task_Entry
9725 -- <statements for dispatching requeue>
9727 -- elsif C = POK_Protected_Procedure then
9728 -- <dispatching call equivalent>
9731 -- raise Program_Error;
9735 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9736 Loc
: constant Source_Ptr
:= Sloc
(N
);
9737 Conc_Typ
: Entity_Id
;
9741 Old_Typ
: Entity_Id
;
9743 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9744 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9745 -- the form Concval.Ename. It is statically known that Ename is allowed
9746 -- to be implemented by a protected procedure. Create a dispatching call
9747 -- equivalent of Concval.Ename taking the actual parameters from the
9748 -- inner-most accept statement or entry body.
9750 function Build_Dispatching_Requeue
return Node_Id
;
9751 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9752 -- the form Concval.Ename. It is statically known that Ename is allowed
9753 -- to be implemented by a protected or a task entry. Create a call to
9754 -- primitive _Disp_Requeue which handles the low-level actions.
9756 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9757 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9758 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9759 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9760 -- determines at runtime whether Ename denotes an entry or a procedure
9761 -- and perform the appropriate kind of dispatching select.
9763 function Build_Normal_Requeue
return Node_Id
;
9764 -- N denotes a non-dispatching requeue statement to either a task or a
9765 -- protected entry. Build the appropriate runtime call to perform the
9768 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9769 -- For a protected entry, create a return statement to skip the rest of
9770 -- the entry body. Otherwise, create a goto statement to skip the rest
9771 -- of a task accept statement. The lookup for the enclosing entry body
9772 -- or accept statement starts from Search.
9774 ---------------------------------------
9775 -- Build_Dispatching_Call_Equivalent --
9776 ---------------------------------------
9778 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9779 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9780 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9787 -- Climb the parent chain looking for the inner-most entry body or
9788 -- accept statement.
9791 while Present
(Acc_Ent
)
9792 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9795 Acc_Ent
:= Parent
(Acc_Ent
);
9798 -- A requeue statement should be housed inside an entry body or an
9799 -- accept statement at some level. If this is not the case, then the
9800 -- tree is malformed.
9802 pragma Assert
(Present
(Acc_Ent
));
9804 -- Recover the list of formal parameters
9806 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9807 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9810 Formals
:= Parameter_Specifications
(Acc_Ent
);
9812 -- Create the actual parameters for the dispatching call. These are
9813 -- simply copies of the entry body or accept statement formals in the
9814 -- same order as they appear.
9818 if Present
(Formals
) then
9819 Actuals
:= New_List
;
9820 Formal
:= First
(Formals
);
9821 while Present
(Formal
) loop
9823 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9829 -- Obj.Call_Ent (Actuals);
9832 Make_Procedure_Call_Statement
(Loc
,
9834 Make_Selected_Component
(Loc
,
9835 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9836 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9838 Parameter_Associations
=> Actuals
);
9839 end Build_Dispatching_Call_Equivalent
;
9841 -------------------------------
9842 -- Build_Dispatching_Requeue --
9843 -------------------------------
9845 function Build_Dispatching_Requeue
return Node_Id
is
9846 Params
: constant List_Id
:= New_List
;
9849 -- Process the "with abort" parameter
9852 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9854 -- Process the entry wrapper's position in the primary dispatch
9855 -- table parameter. Generate:
9857 -- Ada.Tags.Get_Entry_Index
9858 -- (T => To_Tag_Ptr (Obj'Address).all,
9860 -- Ada.Tags.Get_Offset_Index
9861 -- (Ada.Tags.Tag (Concval),
9862 -- <interface dispatch table position of Ename>));
9864 -- Note that Obj'Address is recursively expanded into a call to
9865 -- Base_Address (Obj).
9867 if Tagged_Type_Expansion
then
9869 Make_Function_Call
(Loc
,
9870 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9871 Parameter_Associations
=> New_List
(
9873 Make_Explicit_Dereference
(Loc
,
9874 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9875 Make_Attribute_Reference
(Loc
,
9876 Prefix
=> New_Copy_Tree
(Concval
),
9877 Attribute_Name
=> Name_Address
))),
9879 Make_Function_Call
(Loc
,
9880 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9881 Parameter_Associations
=> New_List
(
9882 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9883 Make_Integer_Literal
(Loc
,
9884 DT_Position
(Entity
(Ename
))))))));
9890 Make_Function_Call
(Loc
,
9891 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9892 Parameter_Associations
=> New_List
(
9894 Make_Attribute_Reference
(Loc
,
9896 Attribute_Name
=> Name_Tag
),
9898 Make_Function_Call
(Loc
,
9899 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9901 Parameter_Associations
=> New_List
(
9905 Make_Attribute_Reference
(Loc
,
9907 Attribute_Name
=> Name_Tag
),
9911 Make_Attribute_Reference
(Loc
,
9912 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9913 Attribute_Name
=> Name_Tag
),
9917 Make_Integer_Literal
(Loc
,
9918 DT_Position
(Entity
(Ename
))))))));
9921 -- Specific actuals for protected to XXX requeue
9923 if Is_Protected_Type
(Old_Typ
) then
9925 Make_Attribute_Reference
(Loc
, -- _object'Address
9927 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9928 Attribute_Name
=> Name_Address
));
9930 Prepend_To
(Params
, -- True
9931 New_Occurrence_Of
(Standard_True
, Loc
));
9933 -- Specific actuals for task to XXX requeue
9936 pragma Assert
(Is_Task_Type
(Old_Typ
));
9938 Prepend_To
(Params
, -- null
9939 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9941 Prepend_To
(Params
, -- False
9942 New_Occurrence_Of
(Standard_False
, Loc
));
9945 -- Add the object parameter
9947 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9950 -- _Disp_Requeue (<Params>);
9952 -- Find entity for Disp_Requeue operation, which belongs to
9953 -- the type and may not be directly visible.
9960 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9961 while Present
(Elmt
) loop
9963 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9968 Make_Procedure_Call_Statement
(Loc
,
9969 Name
=> New_Occurrence_Of
(Op
, Loc
),
9970 Parameter_Associations
=> Params
);
9972 end Build_Dispatching_Requeue
;
9974 --------------------------------------
9975 -- Build_Dispatching_Requeue_To_Any --
9976 --------------------------------------
9978 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9979 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9980 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9981 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
9991 -- Dispatch table slot processing, generate:
9994 S
:= Build_S
(Loc
, Decls
);
9996 -- Call kind processing, generate:
9997 -- C : Ada.Tags.Prim_Op_Kind;
9999 C
:= Build_C
(Loc
, Decls
);
10002 -- S := Ada.Tags.Get_Offset_Index
10003 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10005 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10008 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10011 Make_Procedure_Call_Statement
(Loc
,
10013 New_Occurrence_Of
(
10014 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10015 Name_uDisp_Get_Prim_Op_Kind
),
10017 Parameter_Associations
=> New_List
(
10018 New_Copy_Tree
(Obj
),
10019 New_Occurrence_Of
(S
, Loc
),
10020 New_Occurrence_Of
(C
, Loc
))));
10024 -- if C = POK_Protected_Entry
10025 -- or else C = POK_Task_Entry
10028 Make_Implicit_If_Statement
(N
,
10034 New_Occurrence_Of
(C
, Loc
),
10036 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10041 New_Occurrence_Of
(C
, Loc
),
10043 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10045 -- Dispatching requeue equivalent
10047 Then_Statements
=> New_List
(
10048 Build_Dispatching_Requeue
,
10051 -- elsif C = POK_Protected_Procedure then
10053 Elsif_Parts
=> New_List
(
10054 Make_Elsif_Part
(Loc
,
10058 New_Occurrence_Of
(C
, Loc
),
10060 New_Occurrence_Of
(
10061 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10063 -- Dispatching call equivalent
10065 Then_Statements
=> New_List
(
10066 Build_Dispatching_Call_Equivalent
))),
10069 -- raise Program_Error;
10072 Else_Statements
=> New_List
(
10073 Make_Raise_Program_Error
(Loc
,
10074 Reason
=> PE_Explicit_Raise
))));
10076 -- Wrap everything into a block
10079 Make_Block_Statement
(Loc
,
10080 Declarations
=> Decls
,
10081 Handled_Statement_Sequence
=>
10082 Make_Handled_Sequence_Of_Statements
(Loc
,
10083 Statements
=> Stmts
));
10084 end Build_Dispatching_Requeue_To_Any
;
10086 --------------------------
10087 -- Build_Normal_Requeue --
10088 --------------------------
10090 function Build_Normal_Requeue
return Node_Id
is
10091 Params
: constant List_Id
:= New_List
;
10096 -- Process the "with abort" parameter
10098 Prepend_To
(Params
,
10099 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10101 -- Add the index expression to the parameters. It is common among all
10104 Prepend_To
(Params
,
10105 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10107 if Is_Protected_Type
(Old_Typ
) then
10109 Self_Param
: Node_Id
;
10113 Make_Attribute_Reference
(Loc
,
10115 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10117 Name_Unchecked_Access
);
10119 -- Protected to protected requeue
10121 if Is_Protected_Type
(Conc_Typ
) then
10123 New_Occurrence_Of
(
10124 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10127 Make_Attribute_Reference
(Loc
,
10129 Concurrent_Ref
(Concval
),
10131 Name_Unchecked_Access
);
10133 -- Protected to task requeue
10135 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10137 New_Occurrence_Of
(
10138 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10140 Param
:= Concurrent_Ref
(Concval
);
10143 Prepend_To
(Params
, Param
);
10144 Prepend_To
(Params
, Self_Param
);
10147 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10149 -- Task to protected requeue
10151 if Is_Protected_Type
(Conc_Typ
) then
10153 New_Occurrence_Of
(
10154 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10157 Make_Attribute_Reference
(Loc
,
10159 Concurrent_Ref
(Concval
),
10161 Name_Unchecked_Access
);
10163 -- Task to task requeue
10165 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10167 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10169 Param
:= Concurrent_Ref
(Concval
);
10172 Prepend_To
(Params
, Param
);
10176 Make_Procedure_Call_Statement
(Loc
,
10178 Parameter_Associations
=> Params
);
10179 end Build_Normal_Requeue
;
10181 --------------------------
10182 -- Build_Skip_Statement --
10183 --------------------------
10185 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10186 Skip_Stmt
: Node_Id
;
10189 -- Build a return statement to skip the rest of the entire body
10191 if Is_Protected_Type
(Old_Typ
) then
10192 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10194 -- If the requeue is within a task, find the end label of the
10195 -- enclosing accept statement and create a goto statement to it.
10203 -- Climb the parent chain looking for the enclosing accept
10206 Acc
:= Parent
(Search
);
10207 while Present
(Acc
)
10208 and then Nkind
(Acc
) /= N_Accept_Statement
10210 Acc
:= Parent
(Acc
);
10213 -- The last statement is the second label used for completing
10214 -- the rendezvous the usual way. The label we are looking for
10215 -- is right before it.
10218 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10220 pragma Assert
(Nkind
(Label
) = N_Label
);
10222 -- Generate a goto statement to skip the rest of the accept
10225 Make_Goto_Statement
(Loc
,
10227 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10231 Set_Analyzed
(Skip_Stmt
);
10234 end Build_Skip_Statement
;
10236 -- Start of processing for Expand_N_Requeue_Statement
10239 -- Extract the components of the entry call
10241 Extract_Entry
(N
, Concval
, Ename
, Index
);
10242 Conc_Typ
:= Etype
(Concval
);
10244 -- If the prefix is an access to class-wide type, dereference to get
10245 -- object and entry type.
10247 if Is_Access_Type
(Conc_Typ
) then
10248 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10250 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10251 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10254 -- Examine the scope stack in order to find nearest enclosing protected
10255 -- or task type. This will constitute our invocation source.
10257 Old_Typ
:= Current_Scope
;
10258 while Present
(Old_Typ
)
10259 and then not Is_Protected_Type
(Old_Typ
)
10260 and then not Is_Task_Type
(Old_Typ
)
10262 Old_Typ
:= Scope
(Old_Typ
);
10265 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10266 -- Concval.Ename where the type of Concval is class-wide concurrent
10269 if Ada_Version
>= Ada_2012
10270 and then Present
(Concval
)
10271 and then Is_Class_Wide_Type
(Conc_Typ
)
10272 and then Is_Concurrent_Interface
(Conc_Typ
)
10275 Has_Impl
: Boolean := False;
10276 Impl_Kind
: Name_Id
:= No_Name
;
10279 -- Check whether the Ename is flagged by pragma Implemented
10281 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10283 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10286 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10287 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10289 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10290 Rewrite
(N
, Build_Dispatching_Requeue
);
10292 Insert_After
(N
, Build_Skip_Statement
(N
));
10294 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10295 -- a protected procedure. In this case the requeue is transformed
10296 -- into a dispatching call.
10299 and then Impl_Kind
= Name_By_Protected_Procedure
10301 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10304 -- The procedure_or_entry_NAME's implementation kind is either
10305 -- By_Any, Optional, or pragma Implemented was not applied at all.
10306 -- In this case a runtime test determines whether Ename denotes an
10307 -- entry or a protected procedure and performs the appropriate
10311 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10316 -- Processing for regular (non-dispatching) requeues
10319 Rewrite
(N
, Build_Normal_Requeue
);
10321 Insert_After
(N
, Build_Skip_Statement
(N
));
10323 end Expand_N_Requeue_Statement
;
10325 -------------------------------
10326 -- Expand_N_Selective_Accept --
10327 -------------------------------
10329 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10330 Loc
: constant Source_Ptr
:= Sloc
(N
);
10331 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10333 -- Note: in the below declarations a lot of new lists are allocated
10334 -- unconditionally which may well not end up being used. That's not
10335 -- a good idea since it wastes space gratuitously ???
10337 Accept_Case
: List_Id
;
10338 Accept_List
: constant List_Id
:= New_List
;
10341 Alt_List
: constant List_Id
:= New_List
;
10342 Alt_Stats
: List_Id
;
10343 Ann
: Entity_Id
:= Empty
;
10345 Check_Guard
: Boolean := True;
10347 Decls
: constant List_Id
:= New_List
;
10348 Stats
: constant List_Id
:= New_List
;
10349 Body_List
: constant List_Id
:= New_List
;
10350 Trailing_List
: constant List_Id
:= New_List
;
10353 Else_Present
: Boolean := False;
10354 Terminate_Alt
: Node_Id
:= Empty
;
10355 Select_Mode
: Node_Id
;
10357 Delay_Case
: List_Id
;
10358 Delay_Count
: Integer := 0;
10359 Delay_Val
: Entity_Id
;
10360 Delay_Index
: Entity_Id
;
10361 Delay_Min
: Entity_Id
;
10362 Delay_Num
: Int
:= 1;
10363 Delay_Alt_List
: List_Id
:= New_List
;
10364 Delay_List
: constant List_Id
:= New_List
;
10368 First_Delay
: Boolean := True;
10369 Guard_Open
: Entity_Id
;
10375 Num_Accept
: Nat
:= 0;
10377 Time_Type
: Entity_Id
;
10378 Select_Call
: Node_Id
;
10380 Qnam
: constant Entity_Id
:=
10381 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10383 Xnam
: constant Entity_Id
:=
10384 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10386 -----------------------
10387 -- Local subprograms --
10388 -----------------------
10390 function Accept_Or_Raise
return List_Id
;
10391 -- For the rare case where delay alternatives all have guards, and
10392 -- all of them are closed, it is still possible that there were open
10393 -- accept alternatives with no callers. We must reexamine the
10394 -- Accept_List, and execute a selective wait with no else if some
10395 -- accept is open. If none, we raise program_error.
10397 procedure Add_Accept
(Alt
: Node_Id
);
10398 -- Process a single accept statement in a select alternative. Build
10399 -- procedure for body of accept, and add entry to dispatch table with
10400 -- expression for guard, in preparation for call to run time select.
10402 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10403 -- Manufacture a label using Num as a serial number and declare it.
10404 -- The declaration is appended to Decls. The label marks the trailing
10405 -- statements of an accept or delay alternative.
10407 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10408 -- Build call to Selective_Wait runtime routine
10410 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10411 -- Add code to compare value of delay with previous values, and
10412 -- generate case entry for trailing statements.
10414 procedure Process_Accept_Alternative
10418 -- Add code to call corresponding procedure, and branch to
10419 -- trailing statements, if any.
10421 ---------------------
10422 -- Accept_Or_Raise --
10423 ---------------------
10425 function Accept_Or_Raise
return List_Id
is
10428 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10431 -- We generate the following:
10433 -- for J in q'range loop
10434 -- if q(J).S /=null_task_entry then
10435 -- selective_wait (simple_mode,...);
10441 -- if no rendez_vous then
10442 -- raise program_error;
10445 -- Note that the code needs to know that the selector name
10446 -- in an Accept_Alternative is named S.
10448 Cond
:= Make_Op_Ne
(Loc
,
10450 Make_Selected_Component
(Loc
,
10452 Make_Indexed_Component
(Loc
,
10453 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10454 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10455 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10457 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10459 Stats
:= New_List
(
10460 Make_Implicit_Loop_Statement
(N
,
10461 Iteration_Scheme
=>
10462 Make_Iteration_Scheme
(Loc
,
10463 Loop_Parameter_Specification
=>
10464 Make_Loop_Parameter_Specification
(Loc
,
10465 Defining_Identifier
=> J
,
10466 Discrete_Subtype_Definition
=>
10467 Make_Attribute_Reference
(Loc
,
10468 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10469 Attribute_Name
=> Name_Range
,
10470 Expressions
=> New_List
(
10471 Make_Integer_Literal
(Loc
, 1))))),
10473 Statements
=> New_List
(
10474 Make_Implicit_If_Statement
(N
,
10476 Then_Statements
=> New_List
(
10478 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10479 Make_Exit_Statement
(Loc
))))));
10482 Make_Raise_Program_Error
(Loc
,
10483 Condition
=> Make_Op_Eq
(Loc
,
10484 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10486 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10487 Reason
=> PE_All_Guards_Closed
));
10490 end Accept_Or_Raise
;
10496 procedure Add_Accept
(Alt
: Node_Id
) is
10497 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10498 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10499 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10500 Eent
: constant Entity_Id
:= Entity
(Ename
);
10501 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10502 Null_Body
: Node_Id
;
10503 Proc_Body
: Node_Id
;
10504 PB_Ent
: Entity_Id
;
10510 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10513 if Present
(Condition
(Alt
)) then
10515 Make_If_Expression
(Eloc
, New_List
(
10517 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10518 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10521 Entry_Index_Expression
10522 (Eloc
, Eent
, Index
, Scope
(Eent
));
10525 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10526 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10528 -- Always add call to Abort_Undefer when generating code, since
10529 -- this is what the runtime expects (abort deferred in
10530 -- Selective_Wait). In CodePeer mode this only confuses the
10531 -- analysis with unknown calls, so don't do it.
10533 if not CodePeer_Mode
then
10535 Make_Procedure_Call_Statement
(Eloc
,
10536 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Eloc
));
10538 (First
(Statements
(Handled_Statement_Sequence
10539 (Accept_Statement
(Alt
)))),
10545 Make_Defining_Identifier
(Eloc
,
10546 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10548 if Comes_From_Source
(Alt
) then
10549 Set_Debug_Info_Needed
(PB_Ent
);
10553 Make_Subprogram_Body
(Eloc
,
10555 Make_Procedure_Specification
(Eloc
,
10556 Defining_Unit_Name
=> PB_Ent
),
10557 Declarations
=> Declarations
(Acc_Stm
),
10558 Handled_Statement_Sequence
=>
10559 Build_Accept_Body
(Accept_Statement
(Alt
)));
10561 -- During the analysis of the body of the accept statement, any
10562 -- zero cost exception handler records were collected in the
10563 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10564 -- This is where we move them to where they belong, namely the
10565 -- newly created procedure.
10567 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10568 Append
(Proc_Body
, Body_List
);
10571 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10573 -- if accept statement has declarations, insert above, given that
10574 -- we are not creating a body for the accept.
10576 if Present
(Declarations
(Acc_Stm
)) then
10577 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10581 Append_To
(Accept_List
,
10582 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10584 Num_Accept
:= Num_Accept
+ 1;
10587 ----------------------------
10588 -- Make_And_Declare_Label --
10589 ----------------------------
10591 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10595 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10597 Make_Label
(Loc
, Lab_Id
);
10600 Make_Implicit_Label_Declaration
(Loc
,
10601 Defining_Identifier
=>
10602 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10603 Label_Construct
=> Lab
));
10606 end Make_And_Declare_Label
;
10608 ----------------------
10609 -- Make_Select_Call --
10610 ----------------------
10612 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10613 Params
: constant List_Id
:= New_List
;
10617 Make_Attribute_Reference
(Loc
,
10618 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10619 Attribute_Name
=> Name_Unchecked_Access
));
10620 Append_To
(Params
, Select_Mode
);
10621 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10622 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10625 Make_Procedure_Call_Statement
(Loc
,
10626 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10627 Parameter_Associations
=> Params
);
10628 end Make_Select_Call
;
10630 --------------------------------
10631 -- Process_Accept_Alternative --
10632 --------------------------------
10634 procedure Process_Accept_Alternative
10639 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10640 Alt_Stats
: List_Id
;
10643 Adjust_Condition
(Condition
(Alt
));
10645 -- Accept with body
10647 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10650 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10653 (Defining_Unit_Name
(Specification
(Proc
)),
10656 -- Accept with no body (followed by trailing statements)
10659 Alt_Stats
:= Empty_List
;
10662 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10664 -- After the call, if any, branch to trailing statements, if any.
10665 -- We create a label for each, as well as the corresponding label
10668 if not Is_Empty_List
(Statements
(Alt
)) then
10669 Lab
:= Make_And_Declare_Label
(Index
);
10670 Append
(Lab
, Trailing_List
);
10671 Append_List
(Statements
(Alt
), Trailing_List
);
10672 Append_To
(Trailing_List
,
10673 Make_Goto_Statement
(Loc
,
10674 Name
=> New_Copy
(Identifier
(End_Lab
))));
10680 Append_To
(Alt_Stats
,
10681 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10683 Append_To
(Alt_List
,
10684 Make_Case_Statement_Alternative
(Loc
,
10685 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10686 Statements
=> Alt_Stats
));
10687 end Process_Accept_Alternative
;
10689 -------------------------------
10690 -- Process_Delay_Alternative --
10691 -------------------------------
10693 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10694 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10696 Delay_Alt
: List_Id
;
10699 -- Deal with C/Fortran boolean as delay condition
10701 Adjust_Condition
(Condition
(Alt
));
10703 -- Determine the smallest specified delay
10705 -- for each delay alternative generate:
10707 -- if guard-expression then
10708 -- Delay_Val := delay-expression;
10709 -- Guard_Open := True;
10710 -- if Delay_Val < Delay_Min then
10711 -- Delay_Min := Delay_Val;
10712 -- Delay_Index := Index;
10716 -- The enclosing if-statement is omitted if there is no guard
10718 if Delay_Count
= 1 or else First_Delay
then
10719 First_Delay
:= False;
10721 Delay_Alt
:= New_List
(
10722 Make_Assignment_Statement
(Loc
,
10723 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10724 Expression
=> Expression
(Delay_Statement
(Alt
))));
10726 if Delay_Count
> 1 then
10727 Append_To
(Delay_Alt
,
10728 Make_Assignment_Statement
(Loc
,
10729 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10730 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10734 Delay_Alt
:= New_List
(
10735 Make_Assignment_Statement
(Loc
,
10736 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10737 Expression
=> Expression
(Delay_Statement
(Alt
))));
10739 if Time_Type
= Standard_Duration
then
10742 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10743 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10746 -- The scope of the time type must define a comparison
10747 -- operator. The scope itself may not be visible, so we
10748 -- construct a node with entity information to insure that
10749 -- semantic analysis can find the proper operator.
10752 Make_Function_Call
(Loc
,
10753 Name
=> Make_Selected_Component
(Loc
,
10755 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10757 Make_Operator_Symbol
(Loc
,
10758 Chars
=> Name_Op_Lt
,
10759 Strval
=> No_String
)),
10760 Parameter_Associations
=>
10762 New_Occurrence_Of
(Delay_Val
, Loc
),
10763 New_Occurrence_Of
(Delay_Min
, Loc
)));
10765 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10768 Append_To
(Delay_Alt
,
10769 Make_Implicit_If_Statement
(N
,
10771 Then_Statements
=> New_List
(
10772 Make_Assignment_Statement
(Loc
,
10773 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10774 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10776 Make_Assignment_Statement
(Loc
,
10777 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10778 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10781 if Check_Guard
then
10782 Append_To
(Delay_Alt
,
10783 Make_Assignment_Statement
(Loc
,
10784 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10785 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10788 if Present
(Condition
(Alt
)) then
10789 Delay_Alt
:= New_List
(
10790 Make_Implicit_If_Statement
(N
,
10791 Condition
=> Condition
(Alt
),
10792 Then_Statements
=> Delay_Alt
));
10795 Append_List
(Delay_Alt
, Delay_List
);
10797 Ensure_Statement_Present
(Dloc
, Alt
);
10799 -- If the delay alternative has a statement part, add choice to the
10800 -- case statements for delays.
10802 if not Is_Empty_List
(Statements
(Alt
)) then
10804 if Delay_Count
= 1 then
10805 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10808 Append_To
(Delay_Alt_List
,
10809 Make_Case_Statement_Alternative
(Loc
,
10810 Discrete_Choices
=> New_List
(
10811 Make_Integer_Literal
(Loc
, Index
)),
10812 Statements
=> Statements
(Alt
)));
10815 elsif Delay_Count
= 1 then
10817 -- If the single delay has no trailing statements, add a branch
10818 -- to the exit label to the selective wait.
10820 Delay_Alt_List
:= New_List
(
10821 Make_Goto_Statement
(Loc
,
10822 Name
=> New_Copy
(Identifier
(End_Lab
))));
10825 end Process_Delay_Alternative
;
10827 -- Start of processing for Expand_N_Selective_Accept
10830 Process_Statements_For_Controlled_Objects
(N
);
10832 -- First insert some declarations before the select. The first is:
10836 -- This variable holds the parameters passed to the accept body. This
10837 -- declaration has already been inserted by the time we get here by
10838 -- a call to Expand_Accept_Declarations made from the semantics when
10839 -- processing the first accept statement contained in the select. We
10840 -- can find this entity as Accept_Address (E), where E is any of the
10841 -- entries references by contained accept statements.
10843 -- The first step is to scan the list of Selective_Accept_Statements
10844 -- to find this entity, and also count the number of accepts, and
10845 -- determine if terminated, delay or else is present:
10849 Alt
:= First
(Alts
);
10850 while Present
(Alt
) loop
10851 Process_Statements_For_Controlled_Objects
(Alt
);
10853 if Nkind
(Alt
) = N_Accept_Alternative
then
10856 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10857 Delay_Count
:= Delay_Count
+ 1;
10859 -- If the delays are relative delays, the delay expressions have
10860 -- type Standard_Duration. Otherwise they must have some time type
10861 -- recognized by GNAT.
10863 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10864 Time_Type
:= Standard_Duration
;
10866 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10868 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10869 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10874 "& is not a time type (RM 9.6(6))",
10875 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10876 Time_Type
:= Standard_Duration
;
10877 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10881 if No
(Condition
(Alt
)) then
10883 -- This guard will always be open
10885 Check_Guard
:= False;
10888 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10889 Adjust_Condition
(Condition
(Alt
));
10890 Terminate_Alt
:= Alt
;
10893 Num_Alts
:= Num_Alts
+ 1;
10897 Else_Present
:= Present
(Else_Statements
(N
));
10899 -- At the same time (see procedure Add_Accept) we build the accept list:
10901 -- Qnn : Accept_List (1 .. num-select) := (
10902 -- (null-body, entry-index),
10903 -- (null-body, entry-index),
10905 -- (null_body, entry-index));
10907 -- In the above declaration, null-body is True if the corresponding
10908 -- accept has no body, and false otherwise. The entry is either the
10909 -- entry index expression if there is no guard, or if a guard is
10910 -- present, then an if expression of the form:
10912 -- (if guard then entry-index else Null_Task_Entry)
10914 -- If a guard is statically known to be false, the entry can simply
10915 -- be omitted from the accept list.
10918 Make_Object_Declaration
(Loc
,
10919 Defining_Identifier
=> Qnam
,
10920 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10921 Aliased_Present
=> True,
10923 Make_Qualified_Expression
(Loc
,
10925 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10927 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10929 -- Then we declare the variable that holds the index for the accept
10930 -- that will be selected for service:
10932 -- Xnn : Select_Index;
10935 Make_Object_Declaration
(Loc
,
10936 Defining_Identifier
=> Xnam
,
10937 Object_Definition
=>
10938 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10940 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10942 -- After this follow procedure declarations for each accept body
10944 -- procedure Pnn is
10949 -- where the ... are statements from the corresponding procedure body.
10950 -- No parameters are involved, since the parameters are passed via Ann
10951 -- and the parameter references have already been expanded to be direct
10952 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10953 -- any embedded tasking statements (which would normally be illegal in
10954 -- procedures), have been converted to calls to the tasking runtime so
10955 -- there is no problem in putting them into procedures.
10957 -- The original accept statement has been expanded into a block in
10958 -- the same fashion as for simple accepts (see Build_Accept_Body).
10960 -- Note: we don't really need to build these procedures for the case
10961 -- where no delay statement is present, but it is just as easy to
10962 -- build them unconditionally, and not significantly inefficient,
10963 -- since if they are short they will be inlined anyway.
10965 -- The procedure declarations have been assembled in Body_List
10967 -- If delays are present, we must compute the required delay.
10968 -- We first generate the declarations:
10970 -- Delay_Index : Boolean := 0;
10971 -- Delay_Min : Some_Time_Type.Time;
10972 -- Delay_Val : Some_Time_Type.Time;
10974 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10975 -- active delay that is actually chosen as the basis for the possible
10976 -- delay if an immediate rendez-vous is not possible.
10978 -- In the most common case there is a single delay statement, and this
10979 -- is handled specially.
10981 if Delay_Count
> 0 then
10983 -- Generate the required declarations
10986 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
10988 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
10990 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
10993 Make_Object_Declaration
(Loc
,
10994 Defining_Identifier
=> Delay_Val
,
10995 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
10998 Make_Object_Declaration
(Loc
,
10999 Defining_Identifier
=> Delay_Index
,
11000 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11001 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11004 Make_Object_Declaration
(Loc
,
11005 Defining_Identifier
=> Delay_Min
,
11006 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11008 Unchecked_Convert_To
(Time_Type
,
11009 Make_Attribute_Reference
(Loc
,
11011 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11012 Attribute_Name
=> Name_Last
))));
11014 -- Create Duration and Delay_Mode objects used for passing a delay
11017 D
:= Make_Temporary
(Loc
, 'D');
11018 M
:= Make_Temporary
(Loc
, 'M');
11024 -- Note that these values are defined in s-osprim.ads and must
11025 -- be kept in sync:
11027 -- Relative : constant := 0;
11028 -- Absolute_Calendar : constant := 1;
11029 -- Absolute_RT : constant := 2;
11031 if Time_Type
= Standard_Duration
then
11032 Discr
:= Make_Integer_Literal
(Loc
, 0);
11034 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11035 Discr
:= Make_Integer_Literal
(Loc
, 1);
11039 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11040 Discr
:= Make_Integer_Literal
(Loc
, 2);
11044 Make_Object_Declaration
(Loc
,
11045 Defining_Identifier
=> D
,
11046 Object_Definition
=>
11047 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11050 Make_Object_Declaration
(Loc
,
11051 Defining_Identifier
=> M
,
11052 Object_Definition
=>
11053 New_Occurrence_Of
(Standard_Integer
, Loc
),
11054 Expression
=> Discr
));
11057 if Check_Guard
then
11059 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11062 Make_Object_Declaration
(Loc
,
11063 Defining_Identifier
=> Guard_Open
,
11064 Object_Definition
=>
11065 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11067 New_Occurrence_Of
(Standard_False
, Loc
)));
11070 -- Delay_Count is zero, don't need M and D set (suppress warning)
11077 if Present
(Terminate_Alt
) then
11079 -- If the terminate alternative guard is False, use
11080 -- Simple_Mode; otherwise use Terminate_Mode.
11082 if Present
(Condition
(Terminate_Alt
)) then
11083 Select_Mode
:= Make_If_Expression
(Loc
,
11084 New_List
(Condition
(Terminate_Alt
),
11085 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11086 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11088 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11091 elsif Else_Present
or Delay_Count
> 0 then
11092 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11095 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11098 Select_Call
:= Make_Select_Call
(Select_Mode
);
11099 Append
(Select_Call
, Stats
);
11101 -- Now generate code to act on the result. There is an entry
11102 -- in this case for each accept statement with a non-null body,
11103 -- followed by a branch to the statements that follow the Accept.
11104 -- In the absence of delay alternatives, we generate:
11107 -- when No_Rendezvous => -- omitted if simple mode
11122 -- Lab0: Else_Statements;
11125 -- Lab1: Trailing_Statements1;
11128 -- Lab2: Trailing_Statements2;
11133 -- Generate label for common exit
11135 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11137 -- First entry is the default case, when no rendezvous is possible
11139 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11141 if Else_Present
then
11143 -- If no rendezvous is possible, the else part is executed
11145 Lab
:= Make_And_Declare_Label
(0);
11146 Alt_Stats
:= New_List
(
11147 Make_Goto_Statement
(Loc
,
11148 Name
=> New_Copy
(Identifier
(Lab
))));
11150 Append
(Lab
, Trailing_List
);
11151 Append_List
(Else_Statements
(N
), Trailing_List
);
11152 Append_To
(Trailing_List
,
11153 Make_Goto_Statement
(Loc
,
11154 Name
=> New_Copy
(Identifier
(End_Lab
))));
11156 Alt_Stats
:= New_List
(
11157 Make_Goto_Statement
(Loc
,
11158 Name
=> New_Copy
(Identifier
(End_Lab
))));
11161 Append_To
(Alt_List
,
11162 Make_Case_Statement_Alternative
(Loc
,
11163 Discrete_Choices
=> Choices
,
11164 Statements
=> Alt_Stats
));
11166 -- We make use of the fact that Accept_Index is an integer type, and
11167 -- generate successive literals for entries for each accept. Only those
11168 -- for which there is a body or trailing statements get a case entry.
11170 Alt
:= First
(Select_Alternatives
(N
));
11171 Proc
:= First
(Body_List
);
11172 while Present
(Alt
) loop
11174 if Nkind
(Alt
) = N_Accept_Alternative
then
11175 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11176 Index
:= Index
+ 1;
11179 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11184 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11185 Process_Delay_Alternative
(Alt
, Delay_Num
);
11186 Delay_Num
:= Delay_Num
+ 1;
11192 -- An others choice is always added to the main case, as well
11193 -- as the delay case (to satisfy the compiler).
11195 Append_To
(Alt_List
,
11196 Make_Case_Statement_Alternative
(Loc
,
11197 Discrete_Choices
=>
11198 New_List
(Make_Others_Choice
(Loc
)),
11200 New_List
(Make_Goto_Statement
(Loc
,
11201 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11203 Accept_Case
:= New_List
(
11204 Make_Case_Statement
(Loc
,
11205 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11206 Alternatives
=> Alt_List
));
11208 Append_List
(Trailing_List
, Accept_Case
);
11209 Append_List
(Body_List
, Decls
);
11211 -- Construct case statement for trailing statements of delay
11212 -- alternatives, if there are several of them.
11214 if Delay_Count
> 1 then
11215 Append_To
(Delay_Alt_List
,
11216 Make_Case_Statement_Alternative
(Loc
,
11217 Discrete_Choices
=>
11218 New_List
(Make_Others_Choice
(Loc
)),
11220 New_List
(Make_Null_Statement
(Loc
))));
11222 Delay_Case
:= New_List
(
11223 Make_Case_Statement
(Loc
,
11224 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11225 Alternatives
=> Delay_Alt_List
));
11227 Delay_Case
:= Delay_Alt_List
;
11230 -- If there are no delay alternatives, we append the case statement
11231 -- to the statement list.
11233 if Delay_Count
= 0 then
11234 Append_List
(Accept_Case
, Stats
);
11236 -- Delay alternatives present
11239 -- If delay alternatives are present we generate:
11241 -- find minimum delay.
11242 -- DX := minimum delay;
11243 -- M := <delay mode>;
11244 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11247 -- if X = No_Rendezvous then
11248 -- case statement for delay statements.
11250 -- case statement for accept alternatives.
11261 -- The type of the delay expression is known to be legal
11263 if Time_Type
= Standard_Duration
then
11264 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11266 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11267 Conv
:= Make_Function_Call
(Loc
,
11268 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11269 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11273 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11275 Conv
:= Make_Function_Call
(Loc
,
11276 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11277 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11280 Stmt
:= Make_Assignment_Statement
(Loc
,
11281 Name
=> New_Occurrence_Of
(D
, Loc
),
11282 Expression
=> Conv
);
11284 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11286 Parms
:= Parameter_Associations
(Select_Call
);
11288 Parm
:= First
(Parms
);
11289 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11293 pragma Assert
(Present
(Parm
));
11294 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11297 -- Prepare two new parameters of Duration and Delay_Mode type
11298 -- which represent the value and the mode of the minimum delay.
11301 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11302 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11304 -- Create a call to RTS
11306 Rewrite
(Select_Call
,
11307 Make_Procedure_Call_Statement
(Loc
,
11308 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11309 Parameter_Associations
=> Parms
));
11311 -- This new call should follow the calculation of the minimum
11314 Insert_List_Before
(Select_Call
, Delay_List
);
11316 if Check_Guard
then
11318 Make_Implicit_If_Statement
(N
,
11319 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11320 Then_Statements
=> New_List
(
11321 New_Copy_Tree
(Stmt
),
11322 New_Copy_Tree
(Select_Call
)),
11323 Else_Statements
=> Accept_Or_Raise
);
11324 Rewrite
(Select_Call
, Stmt
);
11326 Insert_Before
(Select_Call
, Stmt
);
11330 Make_Implicit_If_Statement
(N
,
11331 Condition
=> Make_Op_Eq
(Loc
,
11332 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11334 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11336 Then_Statements
=> Delay_Case
,
11337 Else_Statements
=> Accept_Case
);
11339 Append
(Cases
, Stats
);
11343 Append
(End_Lab
, Stats
);
11345 -- Replace accept statement with appropriate block
11348 Make_Block_Statement
(Loc
,
11349 Declarations
=> Decls
,
11350 Handled_Statement_Sequence
=>
11351 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11354 -- Note: have to worry more about abort deferral in above code ???
11356 -- Final step is to unstack the Accept_Address entries for all accept
11357 -- statements appearing in accept alternatives in the select statement
11359 Alt
:= First
(Alts
);
11360 while Present
(Alt
) loop
11361 if Nkind
(Alt
) = N_Accept_Alternative
then
11362 Remove_Last_Elmt
(Accept_Address
11363 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11368 end Expand_N_Selective_Accept
;
11370 --------------------------------------
11371 -- Expand_N_Single_Task_Declaration --
11372 --------------------------------------
11374 -- Single task declarations should never be present after semantic
11375 -- analysis, since we expect them to be replaced by a declaration of an
11376 -- anonymous task type, followed by a declaration of the task object. We
11377 -- include this routine to make sure that is happening.
11379 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11381 raise Program_Error
;
11382 end Expand_N_Single_Task_Declaration
;
11384 ------------------------
11385 -- Expand_N_Task_Body --
11386 ------------------------
11388 -- Given a task body
11390 -- task body tname is
11396 -- This expansion routine converts it into a procedure and sets the
11397 -- elaboration flag for the procedure to true, to represent the fact
11398 -- that the task body is now elaborated:
11400 -- procedure tnameB (_Task : access tnameV) is
11401 -- discriminal : dtype renames _Task.discriminant;
11403 -- procedure _clean is
11405 -- Abort_Defer.all;
11407 -- Abort_Undefer.all;
11412 -- Abort_Undefer.all;
11414 -- System.Task_Stages.Complete_Activation;
11422 -- In addition, if the task body is an activator, then a call to activate
11423 -- tasks is added at the start of the statements, before the call to
11424 -- Complete_Activation, and if in addition the task is a master then it
11425 -- must be established as a master. These calls are inserted and analyzed
11426 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11429 -- There is one discriminal declaration line generated for each
11430 -- discriminant that is present to provide an easy reference point for
11431 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11433 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11434 -- task body procedures have a profile (Arg : System.Address). That is
11435 -- needed because GNARLI has to use the same access-to-subprogram type
11436 -- for all task types. We depend here on knowing that in GNAT, passing
11437 -- an address argument by value is identical to passing a record value
11438 -- by access (in either case a single pointer is passed), so even though
11439 -- this procedure has the wrong profile. In fact it's all OK, since the
11440 -- callings sequence is identical.
11442 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11443 Loc
: constant Source_Ptr
:= Sloc
(N
);
11444 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11448 Insert_Nod
: Node_Id
;
11449 -- Used to determine the proper location of wrapper body insertions
11452 -- Add renaming declarations for discriminals and a declaration for the
11453 -- entry family index (if applicable).
11455 Install_Private_Data_Declarations
11456 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11458 -- Add a call to Abort_Undefer at the very beginning of the task
11459 -- body since this body is called with abort still deferred.
11461 if Abort_Allowed
then
11462 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11464 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11468 -- The statement part has already been protected with an at_end and
11469 -- cleanup actions. The call to Complete_Activation must be placed
11470 -- at the head of the sequence of statements of that block. The
11471 -- declarations have been merged in this sequence of statements but
11472 -- the first real statement is accessible from the First_Real_Statement
11473 -- field (which was set for exactly this purpose).
11475 if Restricted_Profile
then
11476 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11478 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11482 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11486 Make_Subprogram_Body
(Loc
,
11487 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11488 Declarations
=> Declarations
(N
),
11489 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11491 -- If the task contains generic instantiations, cleanup actions are
11492 -- delayed until after instantiation. Transfer the activation chain to
11493 -- the subprogram, to insure that the activation call is properly
11494 -- generated. It the task body contains inner tasks, indicate that the
11495 -- subprogram is a task master.
11497 if Delay_Cleanups
(Ttyp
) then
11498 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11499 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11502 Rewrite
(N
, New_N
);
11505 -- Set elaboration flag immediately after task body. If the body is a
11506 -- subunit, the flag is set in the declarative part containing the stub.
11508 if Nkind
(Parent
(N
)) /= N_Subunit
then
11510 Make_Assignment_Statement
(Loc
,
11512 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11513 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11516 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11517 -- the task body. At this point all wrapper specs have been created,
11518 -- frozen and included in the dispatch table for the task type.
11520 if Ada_Version
>= Ada_2005
then
11521 if Nkind
(Parent
(N
)) = N_Subunit
then
11522 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11527 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11529 end Expand_N_Task_Body
;
11531 ------------------------------------
11532 -- Expand_N_Task_Type_Declaration --
11533 ------------------------------------
11535 -- We have several things to do. First we must create a Boolean flag used
11536 -- to mark if the body is elaborated yet. This variable gets set to True
11537 -- when the body of the task is elaborated (we can't rely on the normal
11538 -- ABE mechanism for the task body, since we need to pass an access to
11539 -- this elaboration boolean to the runtime routines).
11541 -- taskE : aliased Boolean := False;
11543 -- Next a variable is declared to hold the task stack size (either the
11544 -- default : Unspecified_Size, or a value that is set by a pragma
11545 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11546 -- the variable is initialized with this value:
11548 -- taskZ : Size_Type := Unspecified_Size;
11550 -- taskZ : Size_Type := Size_Type (size_expression);
11552 -- Note: No variable is needed to hold the task relative deadline since
11553 -- its value would never be static because the parameter is of a private
11554 -- type (Ada.Real_Time.Time_Span).
11556 -- Next we create a corresponding record type declaration used to represent
11557 -- values of this task. The general form of this type declaration is
11559 -- type taskV (discriminants) is record
11560 -- _Task_Id : Task_Id;
11561 -- entry_family : array (bounds) of Void;
11562 -- _Priority : Integer := priority_expression;
11563 -- _Size : Size_Type := size_expression;
11564 -- _Task_Info : Task_Info_Type := task_info_expression;
11565 -- _CPU : Integer := cpu_range_expression;
11566 -- _Relative_Deadline : Time_Span := time_span_expression;
11567 -- _Domain : Dispatching_Domain := dd_expression;
11570 -- The discriminants are present only if the corresponding task type has
11571 -- discriminants, and they exactly mirror the task type discriminants.
11573 -- The Id field is always present. It contains the Task_Id value, as set by
11574 -- the call to Create_Task. Note that although the task is limited, the
11575 -- task value record type is not limited, so there is no problem in passing
11576 -- this field as an out parameter to Create_Task.
11578 -- One entry_family component is present for each entry family in the task
11579 -- definition. The bounds correspond to the bounds of the entry family
11580 -- (which may depend on discriminants). The element type is void, since we
11581 -- only need the bounds information for determining the entry index. Note
11582 -- that the use of an anonymous array would normally be illegal in this
11583 -- context, but this is a parser check, and the semantics is quite prepared
11584 -- to handle such a case.
11586 -- The _Size field is present only if a Storage_Size pragma appears in the
11587 -- task definition. The expression captures the argument that was present
11588 -- in the pragma, and is used to override the task stack size otherwise
11589 -- associated with the task type.
11591 -- The _Priority field is present only if the task entity has a Priority or
11592 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11593 -- definition clause). It will be filled at the freeze point, when the
11594 -- record init proc is built, to capture the expression of the rep item
11595 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11596 -- here since aspect evaluations are delayed till the freeze point.
11598 -- The _Task_Info field is present only if a Task_Info pragma appears in
11599 -- the task definition. The expression captures the argument that was
11600 -- present in the pragma, and is used to provide the Task_Image parameter
11601 -- to the call to Create_Task.
11603 -- The _CPU field is present only if the task entity has a CPU rep item
11604 -- (pragma, aspect specification or attribute definition clause). It will
11605 -- be filled at the freeze point, when the record init proc is built, to
11606 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11607 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11608 -- are delayed till the freeze point.
11610 -- The _Relative_Deadline field is present only if a Relative_Deadline
11611 -- pragma appears in the task definition. The expression captures the
11612 -- argument that was present in the pragma, and is used to provide the
11613 -- Relative_Deadline parameter to the call to Create_Task.
11615 -- The _Domain field is present only if the task entity has a
11616 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11617 -- definition clause). It will be filled at the freeze point, when the
11618 -- record init proc is built, to capture the expression of the rep item
11619 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11620 -- here since aspect evaluations are delayed till the freeze point.
11622 -- When a task is declared, an instance of the task value record is
11623 -- created. The elaboration of this declaration creates the correct bounds
11624 -- for the entry families, and also evaluates the size, priority, and
11625 -- task_Info expressions if needed. The initialization routine for the task
11626 -- type itself then calls Create_Task with appropriate parameters to
11627 -- initialize the value of the Task_Id field.
11629 -- Note: the address of this record is passed as the "Discriminants"
11630 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11631 -- body procedure, it does not matter that it does not quite match the
11632 -- GNARLI model of what is being passed (the record contains more than just
11633 -- the discriminants, but the discriminants can be found from the record
11636 -- The Entity_Id for this created record type is placed in the
11637 -- Corresponding_Record_Type field of the associated task type entity.
11639 -- Next we create a procedure specification for the task body procedure:
11641 -- procedure taskB (_Task : access taskV);
11643 -- Note that this must come after the record type declaration, since
11644 -- the spec refers to this type. It turns out that the initialization
11645 -- procedure for the value type references the task body spec, but that's
11646 -- fine, since it won't be generated till the freeze point for the type,
11647 -- which is certainly after the task body spec declaration.
11649 -- Finally, we set the task index value field of the entry attribute in
11650 -- the case of a simple entry.
11652 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11653 Loc
: constant Source_Ptr
:= Sloc
(N
);
11654 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11655 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11656 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11657 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11659 Body_Decl
: Node_Id
;
11661 Decl_Stack
: Node_Id
;
11662 Elab_Decl
: Node_Id
;
11663 Ent_Stack
: Entity_Id
;
11664 Proc_Spec
: Node_Id
;
11665 Rec_Decl
: Node_Id
;
11666 Rec_Ent
: Entity_Id
;
11667 Size_Decl
: Entity_Id
;
11668 Task_Size
: Node_Id
;
11670 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11671 -- Searches the task definition T for the first occurrence of the pragma
11672 -- Relative Deadline. The caller has ensured that the pragma is present
11673 -- in the task definition. Note that this routine cannot be implemented
11674 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11675 -- not chained because their expansion into a procedure call statement
11676 -- would cause a break in the chain.
11678 ----------------------------------
11679 -- Get_Relative_Deadline_Pragma --
11680 ----------------------------------
11682 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11686 N
:= First
(Visible_Declarations
(T
));
11687 while Present
(N
) loop
11688 if Nkind
(N
) = N_Pragma
11689 and then Pragma_Name
(N
) = Name_Relative_Deadline
11697 N
:= First
(Private_Declarations
(T
));
11698 while Present
(N
) loop
11699 if Nkind
(N
) = N_Pragma
11700 and then Pragma_Name
(N
) = Name_Relative_Deadline
11708 raise Program_Error
;
11709 end Get_Relative_Deadline_Pragma
;
11711 -- Start of processing for Expand_N_Task_Type_Declaration
11714 -- If already expanded, nothing to do
11716 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11720 -- Here we will do the expansion
11722 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11724 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11725 Cdecls
:= Component_Items
(Component_List
11726 (Type_Definition
(Rec_Decl
)));
11728 Qualify_Entity_Names
(N
);
11730 -- First create the elaboration variable
11733 Make_Object_Declaration
(Loc
,
11734 Defining_Identifier
=>
11735 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11736 Chars
=> New_External_Name
(Tasknm
, 'E')),
11737 Aliased_Present
=> True,
11738 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11739 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11741 Insert_After
(N
, Elab_Decl
);
11743 -- Next create the declaration of the size variable (tasknmZ)
11745 Set_Storage_Size_Variable
(Tasktyp
,
11746 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11747 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11749 if Present
(Taskdef
)
11750 and then Has_Storage_Size_Pragma
(Taskdef
)
11752 Is_OK_Static_Expression
11754 (First
(Pragma_Argument_Associations
11755 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11758 Make_Object_Declaration
(Loc
,
11759 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11760 Object_Definition
=>
11761 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11763 Convert_To
(RTE
(RE_Size_Type
),
11765 (Expression
(First
(Pragma_Argument_Associations
11767 (TaskId
, Name_Storage_Size
)))))));
11771 Make_Object_Declaration
(Loc
,
11772 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11773 Object_Definition
=>
11774 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11776 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11779 Insert_After
(Elab_Decl
, Size_Decl
);
11781 -- Next build the rest of the corresponding record declaration. This is
11782 -- done last, since the corresponding record initialization procedure
11783 -- will reference the previously created entities.
11785 -- Fill in the component declarations -- first the _Task_Id field
11788 Make_Component_Declaration
(Loc
,
11789 Defining_Identifier
=>
11790 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11791 Component_Definition
=>
11792 Make_Component_Definition
(Loc
,
11793 Aliased_Present
=> False,
11794 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11797 -- Declare static ATCB (that is, created by the expander) if we are
11798 -- using the Restricted run time.
11800 if Restricted_Profile
then
11802 Make_Component_Declaration
(Loc
,
11803 Defining_Identifier
=>
11804 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11806 Component_Definition
=>
11807 Make_Component_Definition
(Loc
,
11808 Aliased_Present
=> True,
11809 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11811 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11814 Make_Index_Or_Discriminant_Constraint
(Loc
,
11816 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11820 -- Declare static stack (that is, created by the expander) if we are
11821 -- using the Restricted run time on a bare board configuration.
11823 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11825 -- First we need to extract the appropriate stack size
11827 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11829 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11831 Expr_N
: constant Node_Id
:=
11832 Expression
(First
(
11833 Pragma_Argument_Associations
(
11834 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11835 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11836 P
: constant Node_Id
:= Parent
(Expr_N
);
11839 -- The stack is defined inside the corresponding record.
11840 -- Therefore if the size of the stack is set by means of
11841 -- a discriminant, we must reference the discriminant of the
11842 -- corresponding record type.
11844 if Nkind
(Expr_N
) in N_Has_Entity
11845 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11849 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11851 Set_Parent
(Task_Size
, P
);
11852 Set_Etype
(Task_Size
, Etyp
);
11853 Set_Analyzed
(Task_Size
);
11856 Task_Size
:= Relocate_Node
(Expr_N
);
11862 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11865 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11866 Defining_Identifier
=> Ent_Stack
,
11868 Component_Definition
=>
11869 Make_Component_Definition
(Loc
,
11870 Aliased_Present
=> True,
11871 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11873 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11876 Make_Index_Or_Discriminant_Constraint
(Loc
,
11877 Constraints
=> New_List
(Make_Range
(Loc
,
11878 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11879 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11882 Append_To
(Cdecls
, Decl_Stack
);
11884 -- The appropriate alignment for the stack is ensured by the run-time
11885 -- code in charge of task creation.
11889 -- Add components for entry families
11891 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11893 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11894 -- item is present.
11896 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
11898 Make_Component_Declaration
(Loc
,
11899 Defining_Identifier
=>
11900 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11901 Component_Definition
=>
11902 Make_Component_Definition
(Loc
,
11903 Aliased_Present
=> False,
11904 Subtype_Indication
=>
11905 New_Occurrence_Of
(Standard_Integer
, Loc
))));
11908 -- Add the _Size component if a Storage_Size pragma is present
11910 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11912 Make_Component_Declaration
(Loc
,
11913 Defining_Identifier
=>
11914 Make_Defining_Identifier
(Loc
, Name_uSize
),
11916 Component_Definition
=>
11917 Make_Component_Definition
(Loc
,
11918 Aliased_Present
=> False,
11919 Subtype_Indication
=>
11920 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
11923 Convert_To
(RTE
(RE_Size_Type
),
11925 Expression
(First
(
11926 Pragma_Argument_Associations
(
11927 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
11930 -- Add the _Task_Info component if a Task_Info pragma is present
11932 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
11934 Make_Component_Declaration
(Loc
,
11935 Defining_Identifier
=>
11936 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11938 Component_Definition
=>
11939 Make_Component_Definition
(Loc
,
11940 Aliased_Present
=> False,
11941 Subtype_Indication
=>
11942 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
11944 Expression
=> New_Copy
(
11945 Expression
(First
(
11946 Pragma_Argument_Associations
(
11948 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
11951 -- Add the _CPU component if a CPU rep item is present
11953 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
11955 Make_Component_Declaration
(Loc
,
11956 Defining_Identifier
=>
11957 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11959 Component_Definition
=>
11960 Make_Component_Definition
(Loc
,
11961 Aliased_Present
=> False,
11962 Subtype_Indication
=>
11963 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
11966 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11967 -- present. If we are using a restricted run time this component will
11968 -- not be added (deadlines are not allowed by the Ravenscar profile).
11970 if not Restricted_Profile
11971 and then Present
(Taskdef
)
11972 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11975 Make_Component_Declaration
(Loc
,
11976 Defining_Identifier
=>
11977 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11979 Component_Definition
=>
11980 Make_Component_Definition
(Loc
,
11981 Aliased_Present
=> False,
11982 Subtype_Indication
=>
11983 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
11986 Convert_To
(RTE
(RE_Time_Span
),
11988 Expression
(First
(
11989 Pragma_Argument_Associations
(
11990 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
11993 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
11994 -- item is present. If we are using a restricted run time this component
11995 -- will not be added (dispatching domains are not allowed by the
11996 -- Ravenscar profile).
11998 if not Restricted_Profile
12001 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12004 Make_Component_Declaration
(Loc
,
12005 Defining_Identifier
=>
12006 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12008 Component_Definition
=>
12009 Make_Component_Definition
(Loc
,
12010 Aliased_Present
=> False,
12011 Subtype_Indication
=>
12013 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12016 Insert_After
(Size_Decl
, Rec_Decl
);
12018 -- Analyze the record declaration immediately after construction,
12019 -- because the initialization procedure is needed for single task
12020 -- declarations before the next entity is analyzed.
12022 Analyze
(Rec_Decl
);
12024 -- Create the declaration of the task body procedure
12026 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12028 Make_Subprogram_Declaration
(Loc
,
12029 Specification
=> Proc_Spec
);
12031 Insert_After
(Rec_Decl
, Body_Decl
);
12033 -- The subprogram does not comes from source, so we have to indicate the
12034 -- need for debugging information explicitly.
12036 if Comes_From_Source
(Original_Node
(N
)) then
12037 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12040 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12041 -- the corresponding record has been frozen.
12043 if Ada_Version
>= Ada_2005
then
12044 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12047 -- Ada 2005 (AI-345): We must defer freezing to allow further
12048 -- declaration of primitive subprograms covering task interfaces
12050 if Ada_Version
<= Ada_95
then
12052 -- Now we can freeze the corresponding record. This needs manually
12053 -- freezing, since it is really part of the task type, and the task
12054 -- type is frozen at this stage. We of course need the initialization
12055 -- procedure for this corresponding record type and we won't get it
12056 -- in time if we don't freeze now.
12059 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
12061 if Is_Non_Empty_List
(L
) then
12062 Insert_List_After
(Body_Decl
, L
);
12067 -- Complete the expansion of access types to the current task type, if
12068 -- any were declared.
12070 Expand_Previous_Access_Type
(Tasktyp
);
12072 -- Create wrappers for entries that have pre/postconditions
12078 Ent
:= First_Entity
(Tasktyp
);
12079 while Present
(Ent
) loop
12080 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
12081 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
12083 Build_PPC_Wrapper
(Ent
, N
);
12089 end Expand_N_Task_Type_Declaration
;
12091 -------------------------------
12092 -- Expand_N_Timed_Entry_Call --
12093 -------------------------------
12095 -- A timed entry call in normal case is not implemented using ATC mechanism
12096 -- anymore for efficiency reason.
12106 -- is expanded as follows:
12108 -- 1) When T.E is a task entry_call;
12112 -- X : Task_Entry_Index := <entry index>;
12113 -- DX : Duration := To_Duration (D);
12114 -- M : Delay_Mode := <discriminant>;
12115 -- P : parms := (parm, parm, parm);
12118 -- Timed_Protected_Entry_Call
12119 -- (<acceptor-task>, X, P'Address, DX, M, B);
12127 -- 2) When T.E is a protected entry_call;
12131 -- X : Protected_Entry_Index := <entry index>;
12132 -- DX : Duration := To_Duration (D);
12133 -- M : Delay_Mode := <discriminant>;
12134 -- P : parms := (parm, parm, parm);
12137 -- Timed_Protected_Entry_Call
12138 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12146 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12147 -- is no delay and the triggering statements are executed. We first
12148 -- determine the kind of of the triggering call and then execute a
12149 -- synchronized operation or a direct call.
12152 -- B : Boolean := False;
12153 -- C : Ada.Tags.Prim_Op_Kind;
12154 -- DX : Duration := To_Duration (D)
12155 -- K : Ada.Tags.Tagged_Kind :=
12156 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12157 -- M : Integer :=...;
12158 -- P : Parameters := (Param1 .. ParamN);
12162 -- if K = Ada.Tags.TK_Limited_Tagged
12163 -- or else K = Ada.Tags.TK_Tagged
12165 -- <dispatching-call>;
12170 -- Ada.Tags.Get_Offset_Index
12171 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12173 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12175 -- if C = POK_Protected_Entry
12176 -- or else C = POK_Task_Entry
12178 -- Param1 := P.Param1;
12180 -- ParamN := P.ParamN;
12184 -- if C = POK_Procedure
12185 -- or else C = POK_Protected_Procedure
12186 -- or else C = POK_Task_Procedure
12188 -- <dispatching-call>;
12194 -- <triggering-statements>
12196 -- <timed-statements>
12200 -- The triggering statement and the sequence of timed statements have not
12201 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12202 -- global references if within an instantiation.
12204 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12205 Loc
: constant Source_Ptr
:= Sloc
(N
);
12208 Blk_Typ
: Entity_Id
;
12210 Call_Ent
: Entity_Id
;
12211 Conc_Typ_Stmts
: List_Id
;
12213 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12216 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12218 D_Type
: Entity_Id
;
12221 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12222 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12227 Is_Disp_Select
: Boolean;
12228 Lim_Typ_Stmts
: List_Id
;
12237 B
: Entity_Id
; -- Call status flag
12238 C
: Entity_Id
; -- Call kind
12239 D
: Entity_Id
; -- Delay
12240 K
: Entity_Id
; -- Tagged kind
12241 M
: Entity_Id
; -- Delay mode
12242 P
: Entity_Id
; -- Parameter block
12243 S
: Entity_Id
; -- Primitive operation slot
12245 -- Start of processing for Expand_N_Timed_Entry_Call
12248 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12249 -- was already reported on spec, so do not attempt to expand the call.
12251 if Restriction_Active
(No_Select_Statements
) then
12255 Process_Statements_For_Controlled_Objects
(E_Alt
);
12256 Process_Statements_For_Controlled_Objects
(D_Alt
);
12258 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12260 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12261 -- may wrap them in blocks.
12263 E_Stats
:= Statements
(E_Alt
);
12264 D_Stats
:= Statements
(D_Alt
);
12266 -- The arguments in the call may require dynamic allocation, and the
12267 -- call statement may have been transformed into a block. The block
12268 -- may contain additional declarations for internal entities, and the
12269 -- original call is found by sequential search.
12271 if Nkind
(E_Call
) = N_Block_Statement
then
12272 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12273 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12274 N_Entry_Call_Statement
)
12281 Ada_Version
>= Ada_2005
12282 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12284 if Is_Disp_Select
then
12285 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12291 -- B : Boolean := False;
12293 B
:= Build_B
(Loc
, Decls
);
12296 -- C : Ada.Tags.Prim_Op_Kind;
12298 C
:= Build_C
(Loc
, Decls
);
12300 -- Because the analysis of all statements was disabled, manually
12301 -- analyze the delay statement.
12304 D_Stat
:= Original_Node
(D_Stat
);
12307 -- Build an entry call using Simple_Entry_Call
12309 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12310 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12312 Decls
:= Declarations
(E_Call
);
12313 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12322 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12325 Make_Object_Declaration
(Loc
,
12326 Defining_Identifier
=> B
,
12327 Object_Definition
=>
12328 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12331 -- Duration and mode processing
12333 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12335 -- Use the type of the delay expression (Calendar or Real_Time) to
12336 -- generate the appropriate conversion.
12338 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12339 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12340 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12342 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12343 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12345 Make_Function_Call
(Loc
,
12346 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12347 Parameter_Associations
=>
12348 New_List
(New_Copy
(Expression
(D_Stat
))));
12350 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12351 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12353 Make_Function_Call
(Loc
,
12354 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12355 Parameter_Associations
=>
12356 New_List
(New_Copy
(Expression
(D_Stat
))));
12359 D
:= Make_Temporary
(Loc
, 'D');
12365 Make_Object_Declaration
(Loc
,
12366 Defining_Identifier
=> D
,
12367 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12369 M
:= Make_Temporary
(Loc
, 'M');
12372 -- M : Integer := (0 | 1 | 2);
12375 Make_Object_Declaration
(Loc
,
12376 Defining_Identifier
=> M
,
12377 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12378 Expression
=> D_Disc
));
12380 -- Do the assignment at this stage only because the evaluation of the
12381 -- expression must not occur before (see ACVC C97302A).
12384 Make_Assignment_Statement
(Loc
,
12385 Name
=> New_Occurrence_Of
(D
, Loc
),
12386 Expression
=> D_Conv
));
12388 -- Parameter block processing
12390 -- Manually create the parameter block for dispatching calls. In the
12391 -- case of entries, the block has already been created during the call
12392 -- to Build_Simple_Entry_Call.
12394 if Is_Disp_Select
then
12396 -- Tagged kind processing, generate:
12397 -- K : Ada.Tags.Tagged_Kind :=
12398 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12400 K
:= Build_K
(Loc
, Decls
, Obj
);
12402 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12404 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12406 -- Dispatch table slot processing, generate:
12409 S
:= Build_S
(Loc
, Decls
);
12412 -- S := Ada.Tags.Get_Offset_Index
12413 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12416 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12419 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12421 -- where Obj is the controlling formal parameter, S is the dispatch
12422 -- table slot number of the dispatching operation, P is the wrapped
12423 -- parameter block, D is the duration, M is the duration mode, C is
12424 -- the call kind and B is the call status.
12426 Params
:= New_List
;
12428 Append_To
(Params
, New_Copy_Tree
(Obj
));
12429 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12431 Make_Attribute_Reference
(Loc
,
12432 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12433 Attribute_Name
=> Name_Address
));
12434 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12435 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12436 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12437 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12439 Append_To
(Conc_Typ_Stmts
,
12440 Make_Procedure_Call_Statement
(Loc
,
12444 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12445 Parameter_Associations
=> Params
));
12448 -- if C = POK_Protected_Entry
12449 -- or else C = POK_Task_Entry
12451 -- Param1 := P.Param1;
12453 -- ParamN := P.ParamN;
12456 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12458 -- Generate the if statement only when the packed parameters need
12459 -- explicit assignments to their corresponding actuals.
12461 if Present
(Unpack
) then
12462 Append_To
(Conc_Typ_Stmts
,
12463 Make_Implicit_If_Statement
(N
,
12469 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12472 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12476 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12478 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12480 Then_Statements
=> Unpack
));
12486 -- if C = POK_Procedure
12487 -- or else C = POK_Protected_Procedure
12488 -- or else C = POK_Task_Procedure
12490 -- <dispatching-call>
12494 N_Stats
:= New_List
(
12495 Make_Implicit_If_Statement
(N
,
12500 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12502 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12508 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12510 New_Occurrence_Of
(RTE
(
12511 RE_POK_Protected_Procedure
), Loc
)),
12514 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12517 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12519 Then_Statements
=> New_List
(E_Call
)));
12521 Append_To
(Conc_Typ_Stmts
,
12522 Make_Implicit_If_Statement
(N
,
12523 Condition
=> New_Occurrence_Of
(B
, Loc
),
12524 Then_Statements
=> N_Stats
));
12527 -- <dispatching-call>;
12531 New_List
(New_Copy_Tree
(E_Call
),
12532 Make_Assignment_Statement
(Loc
,
12533 Name
=> New_Occurrence_Of
(B
, Loc
),
12534 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12537 -- if K = Ada.Tags.TK_Limited_Tagged
12538 -- or else K = Ada.Tags.TK_Tagged
12546 Make_Implicit_If_Statement
(N
,
12547 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12548 Then_Statements
=> Lim_Typ_Stmts
,
12549 Else_Statements
=> Conc_Typ_Stmts
));
12554 -- <triggering-statements>
12556 -- <timed-statements>
12560 Make_Implicit_If_Statement
(N
,
12561 Condition
=> New_Occurrence_Of
(B
, Loc
),
12562 Then_Statements
=> E_Stats
,
12563 Else_Statements
=> D_Stats
));
12566 -- Simple case of a non-dispatching trigger. Skip assignments to
12567 -- temporaries created for in-out parameters.
12569 -- This makes unwarranted assumptions about the shape of the expanded
12570 -- tree for the call, and should be cleaned up ???
12572 Stmt
:= First
(Stmts
);
12573 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12577 -- Do the assignment at this stage only because the evaluation
12578 -- of the expression must not occur before (see ACVC C97302A).
12580 Insert_Before
(Stmt
,
12581 Make_Assignment_Statement
(Loc
,
12582 Name
=> New_Occurrence_Of
(D
, Loc
),
12583 Expression
=> D_Conv
));
12586 Params
:= Parameter_Associations
(Call
);
12588 -- For a protected type, we build a Timed_Protected_Entry_Call
12590 if Is_Protected_Type
(Etype
(Concval
)) then
12592 -- Create a new call statement
12594 Param
:= First
(Params
);
12595 while Present
(Param
)
12596 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12601 Dummy
:= Remove_Next
(Next
(Param
));
12603 -- Remove garbage is following the Cancel_Param if present
12605 Dummy
:= Next
(Param
);
12607 -- Remove the mode of the Protected_Entry_Call call, then remove
12608 -- the Communication_Block of the Protected_Entry_Call call, and
12609 -- finally add Duration and a Delay_Mode parameter
12611 pragma Assert
(Present
(Param
));
12612 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12614 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12616 -- Add a Boolean flag for successful entry call
12618 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12620 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12621 when System_Tasking_Protected_Objects_Entries
=>
12623 Make_Procedure_Call_Statement
(Loc
,
12626 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12627 Parameter_Associations
=> Params
));
12630 raise Program_Error
;
12633 -- For the task case, build a Timed_Task_Entry_Call
12636 -- Create a new call statement
12638 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12639 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12640 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12643 Make_Procedure_Call_Statement
(Loc
,
12645 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12646 Parameter_Associations
=> Params
));
12650 Make_Implicit_If_Statement
(N
,
12651 Condition
=> New_Occurrence_Of
(B
, Loc
),
12652 Then_Statements
=> E_Stats
,
12653 Else_Statements
=> D_Stats
));
12657 Make_Block_Statement
(Loc
,
12658 Declarations
=> Decls
,
12659 Handled_Statement_Sequence
=>
12660 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12663 end Expand_N_Timed_Entry_Call
;
12665 ----------------------------------------
12666 -- Expand_Protected_Body_Declarations --
12667 ----------------------------------------
12669 procedure Expand_Protected_Body_Declarations
12671 Spec_Id
: Entity_Id
)
12674 if No_Run_Time_Mode
then
12675 Error_Msg_CRT
("protected body", N
);
12678 elsif Expander_Active
then
12680 -- Associate discriminals with the first subprogram or entry body to
12683 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12684 Set_Discriminals
(Parent
(Spec_Id
));
12687 end Expand_Protected_Body_Declarations
;
12689 -------------------------
12690 -- External_Subprogram --
12691 -------------------------
12693 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12694 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12697 -- The internal and external subprograms follow each other on the entity
12698 -- chain. Note that previously private operations had no separate
12699 -- external subprogram. We now create one in all cases, because a
12700 -- private operation may actually appear in an external call, through
12701 -- a 'Access reference used for a callback.
12703 -- If the operation is a function that returns an anonymous access type,
12704 -- the corresponding itype appears before the operation, and must be
12707 -- This mechanism is fragile, there should be a real link between the
12708 -- two versions of the operation, but there is no place to put it ???
12710 if Is_Access_Type
(Next_Entity
(Subp
)) then
12711 return Next_Entity
(Next_Entity
(Subp
));
12713 return Next_Entity
(Subp
);
12715 end External_Subprogram
;
12717 ------------------------------
12718 -- Extract_Dispatching_Call --
12719 ------------------------------
12721 procedure Extract_Dispatching_Call
12723 Call_Ent
: out Entity_Id
;
12724 Object
: out Entity_Id
;
12725 Actuals
: out List_Id
;
12726 Formals
: out List_Id
)
12728 Call_Nam
: Node_Id
;
12731 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12733 if Present
(Original_Node
(N
)) then
12734 Call_Nam
:= Name
(Original_Node
(N
));
12736 Call_Nam
:= Name
(N
);
12739 -- Retrieve the name of the dispatching procedure. It contains the
12740 -- dispatch table slot number.
12743 case Nkind
(Call_Nam
) is
12744 when N_Identifier
=>
12747 when N_Selected_Component
=>
12748 Call_Nam
:= Selector_Name
(Call_Nam
);
12751 raise Program_Error
;
12756 Actuals
:= Parameter_Associations
(N
);
12757 Call_Ent
:= Entity
(Call_Nam
);
12758 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12759 Object
:= First
(Actuals
);
12761 if Present
(Original_Node
(Object
)) then
12762 Object
:= Original_Node
(Object
);
12765 -- If the type of the dispatching object is an access type then return
12766 -- an explicit dereference.
12768 if Is_Access_Type
(Etype
(Object
)) then
12769 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12772 end Extract_Dispatching_Call
;
12774 -------------------
12775 -- Extract_Entry --
12776 -------------------
12778 procedure Extract_Entry
12780 Concval
: out Node_Id
;
12781 Ename
: out Node_Id
;
12782 Index
: out Node_Id
)
12784 Nam
: constant Node_Id
:= Name
(N
);
12787 -- For a simple entry, the name is a selected component, with the
12788 -- prefix being the task value, and the selector being the entry.
12790 if Nkind
(Nam
) = N_Selected_Component
then
12791 Concval
:= Prefix
(Nam
);
12792 Ename
:= Selector_Name
(Nam
);
12795 -- For a member of an entry family, the name is an indexed component
12796 -- where the prefix is a selected component, whose prefix in turn is
12797 -- the task value, and whose selector is the entry family. The single
12798 -- expression in the expressions list of the indexed component is the
12799 -- subscript for the family.
12801 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12802 Concval
:= Prefix
(Prefix
(Nam
));
12803 Ename
:= Selector_Name
(Prefix
(Nam
));
12804 Index
:= First
(Expressions
(Nam
));
12807 -- Through indirection, the type may actually be a limited view of a
12808 -- concurrent type. When compiling a call, the non-limited view of the
12809 -- type is visible.
12811 if From_Limited_With
(Etype
(Concval
)) then
12812 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12816 -------------------
12817 -- Family_Offset --
12818 -------------------
12820 function Family_Offset
12825 Cap
: Boolean) return Node_Id
12831 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12832 -- If one of the bounds is a reference to a discriminant, replace with
12833 -- corresponding discriminal of type. Within the body of a task retrieve
12834 -- the renamed discriminant by simple visibility, using its generated
12835 -- name. Within a protected object, find the original discriminant and
12836 -- replace it with the discriminal of the current protected operation.
12838 ------------------------------
12839 -- Convert_Discriminant_Ref --
12840 ------------------------------
12842 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12843 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12848 if Is_Entity_Name
(Bound
)
12849 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12851 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
12852 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12853 Find_Direct_Name
(B
);
12855 elsif Is_Protected_Type
(Ttyp
) then
12856 D
:= First_Discriminant
(Ttyp
);
12857 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12858 Next_Discriminant
(D
);
12861 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
12864 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
12867 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12871 B
:= New_Copy_Tree
(Bound
);
12875 Make_Attribute_Reference
(Loc
,
12876 Attribute_Name
=> Name_Pos
,
12877 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12878 Expressions
=> New_List
(B
));
12879 end Convert_Discriminant_Ref
;
12881 -- Start of processing for Family_Offset
12884 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12885 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12888 if Is_Task_Type
(Ttyp
) then
12889 Ityp
:= RTE
(RE_Task_Entry_Index
);
12891 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12895 Make_Attribute_Reference
(Loc
,
12896 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12897 Attribute_Name
=> Name_Min
,
12898 Expressions
=> New_List
(
12900 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12903 Make_Attribute_Reference
(Loc
,
12904 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12905 Attribute_Name
=> Name_Max
,
12906 Expressions
=> New_List
(
12908 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12911 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12918 function Family_Size
12923 Cap
: Boolean) return Node_Id
12928 if Is_Task_Type
(Ttyp
) then
12929 Ityp
:= RTE
(RE_Task_Entry_Index
);
12931 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12935 Make_Attribute_Reference
(Loc
,
12936 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12937 Attribute_Name
=> Name_Max
,
12938 Expressions
=> New_List
(
12940 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12941 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
12942 Make_Integer_Literal
(Loc
, 0)));
12945 ----------------------------
12946 -- Find_Enclosing_Context --
12947 ----------------------------
12949 procedure Find_Enclosing_Context
12951 Context
: out Node_Id
;
12952 Context_Id
: out Entity_Id
;
12953 Context_Decls
: out List_Id
)
12956 -- Traverse the parent chain looking for an enclosing body, block,
12957 -- package or return statement.
12959 Context
:= Parent
(N
);
12960 while not Nkind_In
(Context
, N_Block_Statement
,
12962 N_Extended_Return_Statement
,
12964 N_Package_Declaration
,
12968 Context
:= Parent
(Context
);
12971 -- Extract the constituents of the context
12973 if Nkind
(Context
) = N_Extended_Return_Statement
then
12974 Context_Decls
:= Return_Object_Declarations
(Context
);
12975 Context_Id
:= Return_Statement_Entity
(Context
);
12977 -- Package declarations and bodies use a common library-level activation
12978 -- chain or task master, therefore return the package declaration as the
12979 -- proper carrier for the appropriate flag.
12981 elsif Nkind
(Context
) = N_Package_Body
then
12982 Context_Decls
:= Declarations
(Context
);
12983 Context_Id
:= Corresponding_Spec
(Context
);
12984 Context
:= Parent
(Context_Id
);
12986 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
12987 Context
:= Parent
(Parent
(Context
));
12989 Context
:= Parent
(Context
);
12992 elsif Nkind
(Context
) = N_Package_Declaration
then
12993 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
12994 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12996 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12997 Context_Id
:= Defining_Identifier
(Context_Id
);
13001 Context_Decls
:= Declarations
(Context
);
13003 if Nkind
(Context
) = N_Block_Statement
then
13004 Context_Id
:= Entity
(Identifier
(Context
));
13006 elsif Nkind
(Context
) = N_Entry_Body
then
13007 Context_Id
:= Defining_Identifier
(Context
);
13009 elsif Nkind
(Context
) = N_Subprogram_Body
then
13010 if Present
(Corresponding_Spec
(Context
)) then
13011 Context_Id
:= Corresponding_Spec
(Context
);
13013 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13015 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13016 Context_Id
:= Defining_Identifier
(Context_Id
);
13020 elsif Nkind
(Context
) = N_Task_Body
then
13021 Context_Id
:= Corresponding_Spec
(Context
);
13024 raise Program_Error
;
13028 pragma Assert
(Present
(Context
));
13029 pragma Assert
(Present
(Context_Id
));
13030 pragma Assert
(Present
(Context_Decls
));
13031 end Find_Enclosing_Context
;
13033 -----------------------
13034 -- Find_Master_Scope --
13035 -----------------------
13037 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13041 -- In Ada 2005, the master is the innermost enclosing scope that is not
13042 -- transient. If the enclosing block is the rewriting of a call or the
13043 -- scope is an extended return statement this is valid master. The
13044 -- master in an extended return is only used within the return, and is
13045 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13046 -- now before that overwriting occurs.
13050 if Ada_Version
>= Ada_2005
then
13051 while Is_Internal
(S
) loop
13052 if Nkind
(Parent
(S
)) = N_Block_Statement
13054 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
13058 elsif Ekind
(S
) = E_Return_Statement
then
13068 end Find_Master_Scope
;
13070 -------------------------------
13071 -- First_Protected_Operation --
13072 -------------------------------
13074 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13075 First_Op
: Node_Id
;
13078 First_Op
:= First
(D
);
13079 while Present
(First_Op
)
13080 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
13086 end First_Protected_Operation
;
13088 ---------------------------------------
13089 -- Install_Private_Data_Declarations --
13090 ---------------------------------------
13092 procedure Install_Private_Data_Declarations
13094 Spec_Id
: Entity_Id
;
13095 Conc_Typ
: Entity_Id
;
13096 Body_Nod
: Node_Id
;
13098 Barrier
: Boolean := False;
13099 Family
: Boolean := False)
13101 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13104 Insert_Node
: Node_Id
:= Empty
;
13105 Obj_Ent
: Entity_Id
;
13107 procedure Add
(Decl
: Node_Id
);
13108 -- Add a single declaration after Insert_Node. If this is the first
13109 -- addition, Decl is added to the front of Decls and it becomes the
13112 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13113 -- The bounds of an entry index may depend on discriminants, create a
13114 -- reference to the corresponding prival. Otherwise return a duplicate
13115 -- of the original bound.
13121 procedure Add
(Decl
: Node_Id
) is
13123 if No
(Insert_Node
) then
13124 Prepend_To
(Decls
, Decl
);
13126 Insert_After
(Insert_Node
, Decl
);
13129 Insert_Node
:= Decl
;
13132 --------------------------
13133 -- Replace_Discriminant --
13134 --------------------------
13136 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13138 if Nkind
(Bound
) = N_Identifier
13139 and then Is_Discriminal
(Entity
(Bound
))
13141 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13143 return Duplicate_Subexpr
(Bound
);
13147 -- Start of processing for Install_Private_Data_Declarations
13150 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13151 -- formal parameter _O, _object or _task depending on the context.
13153 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13155 -- Special processing of _O for barrier functions, protected entries
13162 (Ekind
(Spec_Id
) = E_Entry
13163 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13166 Conc_Rec
: constant Entity_Id
:=
13167 Corresponding_Record_Type
(Conc_Typ
);
13168 Typ_Id
: constant Entity_Id
:=
13169 Make_Defining_Identifier
(Loc
,
13170 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13173 -- type prot_typVP is access prot_typV;
13176 Make_Full_Type_Declaration
(Loc
,
13177 Defining_Identifier
=> Typ_Id
,
13179 Make_Access_To_Object_Definition
(Loc
,
13180 Subtype_Indication
=>
13181 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13185 -- _object : prot_typVP := prot_typV (_O);
13188 Make_Object_Declaration
(Loc
,
13189 Defining_Identifier
=>
13190 Make_Defining_Identifier
(Loc
, Name_uObject
),
13191 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13193 Unchecked_Convert_To
(Typ_Id
,
13194 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13197 -- Set the reference to the concurrent object
13199 Obj_Ent
:= Defining_Identifier
(Decl
);
13203 -- Step 2: Create the Protection object and build its declaration for
13204 -- any protected entry (family) of subprogram. Note for the lock-free
13205 -- implementation, the Protection object is not needed anymore.
13207 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13209 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13213 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13215 -- Determine the proper protection type
13217 if Has_Attach_Handler
(Conc_Typ
)
13218 and then not Restricted_Profile
13220 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13222 elsif Has_Interrupt_Handler
(Conc_Typ
)
13223 and then not Restriction_Active
(No_Dynamic_Attachment
)
13225 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13228 case Corresponding_Runtime_Package
(Conc_Typ
) is
13229 when System_Tasking_Protected_Objects_Entries
=>
13230 Prot_Typ
:= RE_Protection_Entries
;
13232 when System_Tasking_Protected_Objects_Single_Entry
=>
13233 Prot_Typ
:= RE_Protection_Entry
;
13235 when System_Tasking_Protected_Objects
=>
13236 Prot_Typ
:= RE_Protection
;
13239 raise Program_Error
;
13244 -- conc_typR : protection_typ renames _object._object;
13247 Make_Object_Renaming_Declaration
(Loc
,
13248 Defining_Identifier
=> Prot_Ent
,
13250 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13252 Make_Selected_Component
(Loc
,
13253 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13254 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13259 -- Step 3: Add discriminant renamings (if any)
13261 if Has_Discriminants
(Conc_Typ
) then
13266 D
:= First_Discriminant
(Conc_Typ
);
13267 while Present
(D
) loop
13269 -- Adjust the source location
13271 Set_Sloc
(Discriminal
(D
), Loc
);
13274 -- discr_name : discr_typ renames _object.discr_name;
13276 -- discr_name : discr_typ renames _task.discr_name;
13279 Make_Object_Renaming_Declaration
(Loc
,
13280 Defining_Identifier
=> Discriminal
(D
),
13281 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13283 Make_Selected_Component
(Loc
,
13284 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13285 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13288 Next_Discriminant
(D
);
13293 -- Step 4: Add private component renamings (if any)
13295 if Is_Protected
then
13296 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13298 if Present
(Private_Declarations
(Def
)) then
13301 Comp_Id
: Entity_Id
;
13302 Decl_Id
: Entity_Id
;
13305 Comp
:= First
(Private_Declarations
(Def
));
13306 while Present
(Comp
) loop
13307 if Nkind
(Comp
) = N_Component_Declaration
then
13308 Comp_Id
:= Defining_Identifier
(Comp
);
13310 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13312 -- Minimal decoration
13314 if Ekind
(Spec_Id
) = E_Function
then
13315 Set_Ekind
(Decl_Id
, E_Constant
);
13317 Set_Ekind
(Decl_Id
, E_Variable
);
13320 Set_Prival
(Comp_Id
, Decl_Id
);
13321 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13322 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13325 -- comp_name : comp_typ renames _object.comp_name;
13328 Make_Object_Renaming_Declaration
(Loc
,
13329 Defining_Identifier
=> Decl_Id
,
13331 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13333 Make_Selected_Component
(Loc
,
13335 New_Occurrence_Of
(Obj_Ent
, Loc
),
13337 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13347 -- Step 5: Add the declaration of the entry index and the associated
13348 -- type for barrier functions and entry families.
13350 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13352 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13353 Index
: constant Entity_Id
:=
13354 Defining_Identifier
13355 (Entry_Index_Specification
13356 (Entry_Body_Formal_Part
(Body_Nod
)));
13357 Index_Con
: constant Entity_Id
:=
13358 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13360 Index_Typ
: Entity_Id
;
13364 -- Minimal decoration
13366 Set_Ekind
(Index_Con
, E_Constant
);
13367 Set_Entry_Index_Constant
(Index
, Index_Con
);
13368 Set_Discriminal_Link
(Index_Con
, Index
);
13370 -- Retrieve the bounds of the entry family
13372 High
:= Type_High_Bound
(Etype
(Index
));
13373 Low
:= Type_Low_Bound
(Etype
(Index
));
13375 -- In the simple case the entry family is given by a subtype
13376 -- mark and the index constant has the same type.
13378 if Is_Entity_Name
(Original_Node
(
13379 Discrete_Subtype_Definition
(Parent
(Index
))))
13381 Index_Typ
:= Etype
(Index
);
13383 -- Otherwise a new subtype declaration is required
13386 High
:= Replace_Bound
(High
);
13387 Low
:= Replace_Bound
(Low
);
13389 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13392 -- subtype Jnn is <Etype of Index> range Low .. High;
13395 Make_Subtype_Declaration
(Loc
,
13396 Defining_Identifier
=> Index_Typ
,
13397 Subtype_Indication
=>
13398 Make_Subtype_Indication
(Loc
,
13400 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13402 Make_Range_Constraint
(Loc
,
13403 Range_Expression
=>
13404 Make_Range
(Loc
, Low
, High
))));
13408 Set_Etype
(Index_Con
, Index_Typ
);
13410 -- Create the object which designates the index:
13411 -- J : constant Jnn :=
13412 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13414 -- where Jnn is the subtype created above or the original type of
13415 -- the index, _E is a formal of the protected body subprogram and
13416 -- <index expr> is the index of the first family member.
13419 Make_Object_Declaration
(Loc
,
13420 Defining_Identifier
=> Index_Con
,
13421 Constant_Present
=> True,
13422 Object_Definition
=>
13423 New_Occurrence_Of
(Index_Typ
, Loc
),
13426 Make_Attribute_Reference
(Loc
,
13428 New_Occurrence_Of
(Index_Typ
, Loc
),
13429 Attribute_Name
=> Name_Val
,
13431 Expressions
=> New_List
(
13435 Make_Op_Subtract
(Loc
,
13436 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13438 Entry_Index_Expression
(Loc
,
13439 Defining_Identifier
(Body_Nod
),
13443 Make_Attribute_Reference
(Loc
,
13445 New_Occurrence_Of
(Index_Typ
, Loc
),
13446 Attribute_Name
=> Name_Pos
,
13447 Expressions
=> New_List
(
13448 Make_Attribute_Reference
(Loc
,
13450 New_Occurrence_Of
(Index_Typ
, Loc
),
13451 Attribute_Name
=> Name_First
)))))));
13455 end Install_Private_Data_Declarations
;
13457 -----------------------
13458 -- Is_Exception_Safe --
13459 -----------------------
13461 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
13463 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
13464 -- Return True whenever encountering a subprogram call or raise
13465 -- statement of any kind in the sequence of statements
13467 ---------------------
13468 -- Has_Side_Effect --
13469 ---------------------
13471 -- What is this doing buried two levels down in exp_ch9. It seems like a
13472 -- generally useful function, and indeed there may be code duplication
13473 -- going on here ???
13475 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
13479 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
13480 -- Indicate whether N is a subprogram call or a raise statement
13482 ----------------------
13483 -- Is_Call_Or_Raise --
13484 ----------------------
13486 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
13488 return Nkind_In
(N
, N_Procedure_Call_Statement
,
13491 N_Raise_Constraint_Error
,
13492 N_Raise_Program_Error
,
13493 N_Raise_Storage_Error
);
13494 end Is_Call_Or_Raise
;
13496 -- Start of processing for Has_Side_Effect
13500 while Present
(Stmt
) loop
13501 if Is_Call_Or_Raise
(Stmt
) then
13505 -- An object declaration can also contain a function call or a
13506 -- raise statement.
13508 if Nkind
(Stmt
) = N_Object_Declaration
then
13509 Expr
:= Expression
(Stmt
);
13511 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
13520 end Has_Side_Effect
;
13522 -- Start of processing for Is_Exception_Safe
13525 -- When exceptions can't be propagated, the subprogram returns normally
13527 if No_Exception_Handlers_Set
then
13531 -- If the checks handled by the back end are not disabled, we cannot
13532 -- ensure that no exception will be raised.
13534 if not Access_Checks_Suppressed
(Empty
)
13535 or else not Discriminant_Checks_Suppressed
(Empty
)
13536 or else not Range_Checks_Suppressed
(Empty
)
13537 or else not Index_Checks_Suppressed
(Empty
)
13538 or else Opt
.Stack_Checking_Enabled
13543 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
13546 (First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
13552 end Is_Exception_Safe
;
13554 ---------------------------------
13555 -- Is_Potentially_Large_Family --
13556 ---------------------------------
13558 function Is_Potentially_Large_Family
13559 (Base_Index
: Entity_Id
;
13560 Conctyp
: Entity_Id
;
13562 Hi
: Node_Id
) return Boolean
13565 return Scope
(Base_Index
) = Standard_Standard
13566 and then Base_Index
= Base_Type
(Standard_Integer
)
13567 and then Has_Discriminants
(Conctyp
)
13569 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13571 (Denotes_Discriminant
(Lo
, True)
13573 Denotes_Discriminant
(Hi
, True));
13574 end Is_Potentially_Large_Family
;
13576 -------------------------------------
13577 -- Is_Private_Primitive_Subprogram --
13578 -------------------------------------
13580 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13583 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13584 and then Is_Private_Primitive
(Id
);
13585 end Is_Private_Primitive_Subprogram
;
13591 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13592 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13593 Formal
: Entity_Id
;
13596 Formal
:= First_Formal
(Bod_Subp
);
13597 while Present
(Formal
) loop
13599 -- Look for formal parameter _E
13601 if Chars
(Formal
) = Name_uE
then
13605 Next_Formal
(Formal
);
13608 -- A protected body subprogram should always have the parameter in
13611 raise Program_Error
;
13614 --------------------------------
13615 -- Make_Initialize_Protection --
13616 --------------------------------
13618 function Make_Initialize_Protection
13619 (Protect_Rec
: Entity_Id
) return List_Id
13621 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13624 Ptyp
: constant Node_Id
:=
13625 Corresponding_Concurrent_Type
(Protect_Rec
);
13627 L
: constant List_Id
:= New_List
;
13628 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13629 Prio_Type
: Entity_Id
;
13630 Prio_Var
: Entity_Id
:= Empty
;
13631 Restricted
: constant Boolean := Restricted_Profile
;
13634 -- We may need two calls to properly initialize the object, one to
13635 -- Initialize_Protection, and possibly one to Install_Handlers if we
13636 -- have a pragma Attach_Handler.
13638 -- Get protected declaration. In the case of a task type declaration,
13639 -- this is simply the parent of the protected type entity. In the single
13640 -- protected object declaration, this parent will be the implicit type,
13641 -- and we can find the corresponding single protected object declaration
13642 -- by searching forward in the declaration list in the tree.
13644 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13645 -- of this type should have been removed during semantic analysis.
13647 Pdec
:= Parent
(Ptyp
);
13648 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13649 N_Single_Protected_Declaration
)
13654 -- Build the parameter list for the call. Note that _Init is the name
13655 -- of the formal for the object to be initialized, which is the task
13656 -- value record itself.
13660 -- For lock-free implementation, skip initializations of the Protection
13663 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13665 -- Object parameter. This is a pointer to the object of type
13666 -- Protection used by the GNARL to control the protected object.
13669 Make_Attribute_Reference
(Loc
,
13671 Make_Selected_Component
(Loc
,
13672 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13673 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13674 Attribute_Name
=> Name_Unchecked_Access
));
13676 -- Priority parameter. Set to Unspecified_Priority unless there is a
13677 -- Priority rep item, in which case we take the value from the pragma
13678 -- or attribute definition clause, or there is an Interrupt_Priority
13679 -- rep item and no Priority rep item, and we set the ceiling to
13680 -- Interrupt_Priority'Last, an implementation-defined value, see
13683 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13685 Prio_Clause
: constant Node_Id
:=
13687 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13694 if Nkind
(Prio_Clause
) = N_Pragma
then
13697 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13699 -- Get_Rep_Item returns either priority pragma.
13701 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13702 Prio_Type
:= RTE
(RE_Any_Priority
);
13704 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13707 -- Attribute definition clause Priority
13710 if Chars
(Prio_Clause
) = Name_Priority
then
13711 Prio_Type
:= RTE
(RE_Any_Priority
);
13713 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13716 Prio
:= Expression
(Prio_Clause
);
13719 -- Always create a locale variable to capture the priority.
13720 -- The priority is also passed to Install_Restriced_Handlers.
13721 -- Note that it is really necessary to create this variable
13722 -- explicitly. It might be thought that removing side effects
13723 -- would the appropriate approach, but that could generate
13724 -- declarations improperly placed in the enclosing scope.
13726 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13728 Make_Object_Declaration
(Loc
,
13729 Defining_Identifier
=> Prio_Var
,
13730 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13731 Expression
=> Relocate_Node
(Prio
)));
13733 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13736 -- When no priority is specified but an xx_Handler pragma is, we
13737 -- default to System.Interrupts.Default_Interrupt_Priority, see
13740 elsif Has_Attach_Handler
(Ptyp
)
13741 or else Has_Interrupt_Handler
(Ptyp
)
13744 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13746 -- Normal case, no priority or xx_Handler specified, default priority
13750 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13753 -- Test for Compiler_Info parameter. This parameter allows entry body
13754 -- procedures and barrier functions to be called from the runtime. It
13755 -- is a pointer to the record generated by the compiler to represent
13756 -- the protected object.
13758 -- A protected type without entries that covers an interface and
13759 -- overrides the abstract routines with protected procedures is
13760 -- considered equivalent to a protected type with entries in the
13761 -- context of dispatching select statements.
13763 -- Protected types with interrupt handlers (when not using a
13764 -- restricted profile) are also considered equivalent to protected
13765 -- types with entries.
13767 -- The types which are used (Static_Interrupt_Protection and
13768 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13771 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13773 Called_Subp
: RE_Id
;
13777 when System_Tasking_Protected_Objects_Entries
=>
13778 Called_Subp
:= RE_Initialize_Protection_Entries
;
13780 -- Argument Compiler_Info
13783 Make_Attribute_Reference
(Loc
,
13784 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13785 Attribute_Name
=> Name_Address
));
13787 when System_Tasking_Protected_Objects_Single_Entry
=>
13788 Called_Subp
:= RE_Initialize_Protection_Entry
;
13790 -- Argument Compiler_Info
13793 Make_Attribute_Reference
(Loc
,
13794 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13795 Attribute_Name
=> Name_Address
));
13797 when System_Tasking_Protected_Objects
=>
13798 Called_Subp
:= RE_Initialize_Protection
;
13801 raise Program_Error
;
13804 -- Entry_Bodies parameter. This is a pointer to an array of
13805 -- pointers to the entry body procedures and barrier functions of
13806 -- the object. If the protected type has no entries this object
13807 -- will not exist, in this case, pass a null (it can happen when
13808 -- there are protected interrupt handlers or interfaces).
13811 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13813 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13814 -- multiple entries).
13817 Make_Attribute_Reference
(Loc
,
13818 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13819 Attribute_Name
=> Name_Unrestricted_Access
));
13821 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13823 -- Find index mapping function (clumsy but ok for now)
13825 while Ekind
(P_Arr
) /= E_Function
loop
13826 Next_Entity
(P_Arr
);
13830 Make_Attribute_Reference
(Loc
,
13831 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13832 Attribute_Name
=> Name_Unrestricted_Access
));
13835 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13837 -- This is the case where we have a protected object with
13838 -- interfaces and no entries, and the single entry restriction
13839 -- is in effect. We pass a null pointer for the entry
13840 -- parameter because there is no actual entry.
13842 Append_To
(Args
, Make_Null
(Loc
));
13844 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13846 -- This is the case where we have a protected object with no
13848 -- - either interrupt handlers with non restricted profile,
13850 -- Note that the types which are used for interrupt handlers
13851 -- (Static/Dynamic_Interrupt_Protection) are derived from
13852 -- Protection_Entries. We pass two null pointers because there
13853 -- is no actual entry, and the initialization procedure needs
13854 -- both Entry_Bodies and Find_Body_Index.
13856 Append_To
(Args
, Make_Null
(Loc
));
13857 Append_To
(Args
, Make_Null
(Loc
));
13861 Make_Procedure_Call_Statement
(Loc
,
13863 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
13864 Parameter_Associations
=> Args
));
13868 if Has_Attach_Handler
(Ptyp
) then
13870 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13871 -- make the following call:
13873 -- Install_Handlers (_object,
13874 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13876 -- or, in the case of Ravenscar:
13878 -- Install_Restricted_Handlers
13879 -- (Prio, (Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13882 Args
: constant List_Id
:= New_List
;
13883 Table
: constant List_Id
:= New_List
;
13884 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13887 -- Build the Priority parameter (only for ravenscar)
13891 -- Priority comes from a pragma
13893 if Present
(Prio_Var
) then
13894 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13896 -- Priority is the default one
13901 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
13905 -- Build the Attach_Handler table argument
13907 while Present
(Ritem
) loop
13908 if Nkind
(Ritem
) = N_Pragma
13909 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13912 Handler
: constant Node_Id
:=
13913 First
(Pragma_Argument_Associations
(Ritem
));
13915 Interrupt
: constant Node_Id
:= Next
(Handler
);
13916 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13920 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13921 Unchecked_Convert_To
13922 (RTE
(RE_System_Interrupt_Id
), Expr
),
13923 Make_Attribute_Reference
(Loc
,
13925 Make_Selected_Component
(Loc
,
13927 Make_Identifier
(Loc
, Name_uInit
),
13929 Duplicate_Subexpr_No_Checks
13930 (Expression
(Handler
))),
13931 Attribute_Name
=> Name_Access
))));
13935 Next_Rep_Item
(Ritem
);
13938 -- Append the table argument we just built
13940 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13942 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13943 -- call to the statements.
13946 -- Call a simplified version of Install_Handlers to be used
13947 -- when the Ravenscar restrictions are in effect
13948 -- (Install_Restricted_Handlers).
13951 Make_Procedure_Call_Statement
(Loc
,
13954 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13955 Parameter_Associations
=> Args
));
13958 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13960 -- First, prepends the _object argument
13963 Make_Attribute_Reference
(Loc
,
13965 Make_Selected_Component
(Loc
,
13966 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13968 Make_Identifier
(Loc
, Name_uObject
)),
13969 Attribute_Name
=> Name_Unchecked_Access
));
13972 -- Then, insert call to Install_Handlers
13975 Make_Procedure_Call_Statement
(Loc
,
13977 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
13978 Parameter_Associations
=> Args
));
13984 end Make_Initialize_Protection
;
13986 ---------------------------
13987 -- Make_Task_Create_Call --
13988 ---------------------------
13990 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
13991 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14001 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14002 Tnam
:= Chars
(Ttyp
);
14004 -- Get task declaration. In the case of a task type declaration, this is
14005 -- simply the parent of the task type entity. In the single task
14006 -- declaration, this parent will be the implicit type, and we can find
14007 -- the corresponding single task declaration by searching forward in the
14008 -- declaration list in the tree.
14010 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14011 -- this type should have been removed during semantic analysis.
14013 Tdec
:= Parent
(Ttyp
);
14014 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
14015 N_Single_Task_Declaration
)
14020 -- Now we can find the task definition from this declaration
14022 Tdef
:= Task_Definition
(Tdec
);
14024 -- Build the parameter list for the call. Note that _Init is the name
14025 -- of the formal for the object to be initialized, which is the task
14026 -- value record itself.
14030 -- Priority parameter. Set to Unspecified_Priority unless there is a
14031 -- Priority rep item, in which case we take the value from the rep item.
14033 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14035 Make_Selected_Component
(Loc
,
14036 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14037 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14040 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14043 -- Optional Stack parameter
14045 if Restricted_Profile
then
14047 -- If the stack has been preallocated by the expander then
14048 -- pass its address. Otherwise, pass a null address.
14050 if Preallocated_Stacks_On_Target
then
14052 Make_Attribute_Reference
(Loc
,
14054 Make_Selected_Component
(Loc
,
14055 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14056 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14057 Attribute_Name
=> Name_Address
));
14061 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14065 -- Size parameter. If no Storage_Size pragma is present, then
14066 -- the size is taken from the taskZ variable for the type, which
14067 -- is either Unspecified_Size, or has been reset by the use of
14068 -- a Storage_Size attribute definition clause. If a pragma is
14069 -- present, then the size is taken from the _Size field of the
14070 -- task value record, which was set from the pragma value.
14072 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14074 Make_Selected_Component
(Loc
,
14075 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14076 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14080 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14083 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14084 -- Task_Info pragma, in which case we take the value from the pragma.
14086 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14088 Make_Selected_Component
(Loc
,
14089 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14090 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14094 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14097 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14098 -- in which case we take the value from the rep item. The parameter is
14099 -- passed as an Integer because in the case of unspecified CPU the
14100 -- value is not in the range of CPU_Range.
14102 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14104 Convert_To
(Standard_Integer
,
14105 Make_Selected_Component
(Loc
,
14106 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14107 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14110 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14113 if not Restricted_Profile
then
14115 -- Deadline parameter. If no Relative_Deadline pragma is present,
14116 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14117 -- the deadline is taken from the _Relative_Deadline field of the
14118 -- task value record, which was set from the pragma value. Note that
14119 -- this parameter must not be generated for the restricted profiles
14120 -- since Ravenscar does not allow deadlines.
14122 -- Case where pragma Relative_Deadline applies: use given value
14124 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14126 Make_Selected_Component
(Loc
,
14127 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14129 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14131 -- No pragma Relative_Deadline apply to the task
14135 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14138 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14139 -- present, then the dispatching domain is null. If a rep item is
14140 -- present, then the dispatching domain is taken from the
14141 -- _Dispatching_Domain field of the task value record, which was set
14142 -- from the rep item value. Note that this parameter must not be
14143 -- generated for the restricted profiles since Ravenscar does not
14144 -- allow dispatching domains.
14146 -- Case where Dispatching_Domain rep item applies: use given value
14149 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14152 Make_Selected_Component
(Loc
,
14154 Make_Identifier
(Loc
, Name_uInit
),
14156 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14158 -- No pragma or aspect Dispatching_Domain apply to the task
14161 Append_To
(Args
, Make_Null
(Loc
));
14164 -- Number of entries. This is an expression of the form:
14166 -- n + _Init.a'Length + _Init.a'B'Length + ...
14168 -- where a,b... are the entry family names for the task definition
14171 Build_Entry_Count_Expression
14176 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14178 Append_To
(Args
, Ecount
);
14180 -- Master parameter. This is a reference to the _Master parameter of
14181 -- the initialization procedure, except in the case of the pragma
14182 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14183 -- System.Tasking.Library_Task_Level.
14185 if Restriction_Active
(No_Task_Hierarchy
) = False then
14186 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14189 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14193 -- State parameter. This is a pointer to the task body procedure. The
14194 -- required value is obtained by taking 'Unrestricted_Access of the task
14195 -- body procedure and converting it (with an unchecked conversion) to
14196 -- the type required by the task kernel. For further details, see the
14197 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14198 -- than 'Address in order to avoid creating trampolines.
14201 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14202 Subp_Ptr_Typ
: constant Node_Id
:=
14203 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14204 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14207 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14208 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14210 -- Be sure to freeze a reference to the access-to-subprogram type,
14211 -- otherwise gigi will complain that it's in the wrong scope, because
14212 -- it's actually inside the init procedure for the record type that
14213 -- corresponds to the task type.
14215 -- This processing is causing a crash in the .NET/JVM back ends that
14216 -- is not yet understood, so skip it in these cases ???
14218 if VM_Target
= No_VM
then
14219 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14220 Append_Freeze_Action
(Task_Rec
, Ref
);
14223 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14224 Make_Qualified_Expression
(Loc
,
14225 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14227 Make_Attribute_Reference
(Loc
,
14228 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14229 Attribute_Name
=> Name_Unrestricted_Access
))));
14231 -- For the .NET/JVM cases revert to the original code below ???
14235 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14236 Make_Attribute_Reference
(Loc
,
14237 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14238 Attribute_Name
=> Name_Address
)));
14242 -- Discriminants parameter. This is just the address of the task
14243 -- value record itself (which contains the discriminant values
14246 Make_Attribute_Reference
(Loc
,
14247 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14248 Attribute_Name
=> Name_Address
));
14250 -- Elaborated parameter. This is an access to the elaboration Boolean
14253 Make_Attribute_Reference
(Loc
,
14254 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14255 Attribute_Name
=> Name_Unchecked_Access
));
14257 -- Add Chain parameter (not done for sequential elaboration policy, see
14258 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14260 if Partition_Elaboration_Policy
/= 'S' then
14261 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14264 -- Task name parameter. Take this from the _Task_Id parameter to the
14265 -- init call unless there is a Task_Name pragma, in which case we take
14266 -- the value from the pragma.
14268 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14269 -- Copy expression in full, because it may be dynamic and have
14276 (Pragma_Argument_Associations
14278 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14281 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14284 -- Created_Task parameter. This is the _Task_Id field of the task
14288 Make_Selected_Component
(Loc
,
14289 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14290 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14296 if Restricted_Profile
then
14297 if Partition_Elaboration_Policy
= 'S' then
14298 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14300 Create_RE
:= RE_Create_Restricted_Task
;
14303 Create_RE
:= RE_Create_Task
;
14306 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14310 Make_Procedure_Call_Statement
(Loc
,
14312 Parameter_Associations
=> Args
);
14313 end Make_Task_Create_Call
;
14315 ------------------------------
14316 -- Next_Protected_Operation --
14317 ------------------------------
14319 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14323 Next_Op
:= Next
(N
);
14324 while Present
(Next_Op
)
14325 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
14331 end Next_Protected_Operation
;
14333 ---------------------
14334 -- Null_Statements --
14335 ---------------------
14337 function Null_Statements
(Stats
: List_Id
) return Boolean is
14341 Stmt
:= First
(Stats
);
14342 while Nkind
(Stmt
) /= N_Empty
14343 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14345 (Nkind
(Stmt
) = N_Pragma
14347 Nam_In
(Pragma_Name
(Stmt
), Name_Unreferenced
,
14354 return Nkind
(Stmt
) = N_Empty
;
14355 end Null_Statements
;
14357 --------------------------
14358 -- Parameter_Block_Pack --
14359 --------------------------
14361 function Parameter_Block_Pack
14363 Blk_Typ
: Entity_Id
;
14367 Stmts
: List_Id
) return Node_Id
14369 Actual
: Entity_Id
;
14370 Expr
: Node_Id
:= Empty
;
14371 Formal
: Entity_Id
;
14372 Has_Param
: Boolean := False;
14375 Temp_Asn
: Node_Id
;
14376 Temp_Nam
: Node_Id
;
14379 Actual
:= First
(Actuals
);
14380 Formal
:= Defining_Identifier
(First
(Formals
));
14381 Params
:= New_List
;
14382 while Present
(Actual
) loop
14383 if Is_By_Copy_Type
(Etype
(Actual
)) then
14385 -- Jnn : aliased <formal-type>
14387 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14390 Make_Object_Declaration
(Loc
,
14391 Aliased_Present
=> True,
14392 Defining_Identifier
=> Temp_Nam
,
14393 Object_Definition
=>
14394 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14396 if Ekind
(Formal
) /= E_Out_Parameter
then
14402 New_Occurrence_Of
(Temp_Nam
, Loc
);
14404 Set_Assignment_OK
(Temp_Asn
);
14407 Make_Assignment_Statement
(Loc
,
14409 Expression
=> New_Copy_Tree
(Actual
)));
14413 -- Jnn'unchecked_access
14416 Make_Attribute_Reference
(Loc
,
14417 Attribute_Name
=> Name_Unchecked_Access
,
14418 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14422 -- The controlling parameter is omitted
14425 if not Is_Controlling_Actual
(Actual
) then
14427 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14433 Next_Actual
(Actual
);
14434 Next_Formal_With_Extras
(Formal
);
14438 Expr
:= Make_Aggregate
(Loc
, Params
);
14443 -- J1'unchecked_access;
14444 -- <actual2>'reference;
14447 P
:= Make_Temporary
(Loc
, 'P');
14450 Make_Object_Declaration
(Loc
,
14451 Defining_Identifier
=> P
,
14452 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14453 Expression
=> Expr
));
14456 end Parameter_Block_Pack
;
14458 ----------------------------
14459 -- Parameter_Block_Unpack --
14460 ----------------------------
14462 function Parameter_Block_Unpack
14466 Formals
: List_Id
) return List_Id
14468 Actual
: Entity_Id
;
14470 Formal
: Entity_Id
;
14471 Has_Asnmt
: Boolean := False;
14472 Result
: constant List_Id
:= New_List
;
14475 Actual
:= First
(Actuals
);
14476 Formal
:= Defining_Identifier
(First
(Formals
));
14477 while Present
(Actual
) loop
14478 if Is_By_Copy_Type
(Etype
(Actual
))
14479 and then Ekind
(Formal
) /= E_In_Parameter
14482 -- <actual> := P.<formal>;
14485 Make_Assignment_Statement
(Loc
,
14489 Make_Explicit_Dereference
(Loc
,
14490 Make_Selected_Component
(Loc
,
14492 New_Occurrence_Of
(P
, Loc
),
14494 Make_Identifier
(Loc
, Chars
(Formal
)))));
14496 Set_Assignment_OK
(Name
(Asnmt
));
14497 Append_To
(Result
, Asnmt
);
14502 Next_Actual
(Actual
);
14503 Next_Formal_With_Extras
(Formal
);
14509 return New_List
(Make_Null_Statement
(Loc
));
14511 end Parameter_Block_Unpack
;
14513 ----------------------
14514 -- Set_Discriminals --
14515 ----------------------
14517 procedure Set_Discriminals
(Dec
: Node_Id
) is
14520 D_Minal
: Entity_Id
;
14523 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14524 Pdef
:= Defining_Identifier
(Dec
);
14526 if Has_Discriminants
(Pdef
) then
14527 D
:= First_Discriminant
(Pdef
);
14528 while Present
(D
) loop
14530 Make_Defining_Identifier
(Sloc
(D
),
14531 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14533 Set_Ekind
(D_Minal
, E_Constant
);
14534 Set_Etype
(D_Minal
, Etype
(D
));
14535 Set_Scope
(D_Minal
, Pdef
);
14536 Set_Discriminal
(D
, D_Minal
);
14537 Set_Discriminal_Link
(D_Minal
, D
);
14539 Next_Discriminant
(D
);
14542 end Set_Discriminals
;
14544 -----------------------
14545 -- Trivial_Accept_OK --
14546 -----------------------
14548 function Trivial_Accept_OK
return Boolean is
14550 case Opt
.Task_Dispatching_Policy
is
14552 -- If we have the default task dispatching policy in effect, we can
14553 -- definitely do the optimization (one way of looking at this is to
14554 -- think of the formal definition of the default policy being allowed
14555 -- to run any task it likes after a rendezvous, so even if notionally
14556 -- a full rescheduling occurs, we can say that our dispatching policy
14557 -- (i.e. the default dispatching policy) reorders the queue to be the
14558 -- same as just before the call.
14563 -- FIFO_Within_Priorities certainly does not permit this
14564 -- optimization since the Rendezvous is a scheduling action that may
14565 -- require some other task to be run.
14570 -- For now, disallow the optimization for all other policies. This
14571 -- may be over-conservative, but it is certainly not incorrect.
14577 end Trivial_Accept_OK
;