1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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
295 -- original, unexpanded body. This is the version of the protected
296 -- subprogram that is called from all protected operations on the same
297 -- object, including the 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
)));
582 Actual_Family_Offset
(
583 Make_Attribute_Reference
(Sloc
,
584 Attribute_Name
=> Name_Pos
,
585 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
586 Expressions
=> New_List
(Relocate_Node
(Index
))),
587 Type_Low_Bound
(S
)));
592 -- Now add lengths of preceding entries and entry families
594 Prev
:= First_Entity
(Ttyp
);
596 while Chars
(Prev
) /= Chars
(Ent
)
597 or else (Ekind
(Prev
) /= Ekind
(Ent
))
598 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
600 if Ekind
(Prev
) = E_Entry
then
601 Set_Intval
(Num
, Intval
(Num
) + 1);
603 elsif Ekind
(Prev
) = E_Entry_Family
then
605 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
607 -- The need for the following full view retrieval stems from this
608 -- complex case of nested generics and tasking:
611 -- type Formal_Index is range <>;
614 -- type Index is private;
621 -- type Index is new Formal_Index range 1 .. 10;
624 -- package body Outer is
626 -- entry Fam (Index); -- (2)
629 -- package body Inner is -- (3)
637 -- We are currently building the index expression for the entry
638 -- call "T.E" (1). Part of the expansion must mention the range
639 -- of the discrete type "Index" (2) of entry family "Fam".
641 -- However only the private view of type "Index" is available to
642 -- the inner generic (3) because there was no prior mention of
643 -- the type inside "Inner". This visibility requirement is
644 -- implicit and cannot be detected during the construction of
645 -- the generic trees and needs special handling.
648 and then Is_Private_Type
(S
)
649 and then Present
(Full_View
(S
))
654 Lo
:= Type_Low_Bound
(S
);
655 Hi
:= Type_High_Bound
(S
);
663 Actual_Family_Offset
(Hi
, Lo
),
665 Make_Integer_Literal
(Sloc
, 1)));
667 -- Other components are anonymous types to be ignored
677 end Actual_Index_Expression
;
679 --------------------------
680 -- Add_Formal_Renamings --
681 --------------------------
683 procedure Add_Formal_Renamings
689 Ptr
: constant Entity_Id
:=
691 (Next
(First
(Parameter_Specifications
(Spec
))));
692 -- The name of the formal that holds the address of the parameter block
699 Renamed_Formal
: Node_Id
;
702 Formal
:= First_Formal
(Ent
);
703 while Present
(Formal
) loop
704 Comp
:= Entry_Component
(Formal
);
706 Make_Defining_Identifier
(Sloc
(Formal
),
707 Chars
=> Chars
(Formal
));
708 Set_Etype
(New_F
, Etype
(Formal
));
709 Set_Scope
(New_F
, Ent
);
711 -- Now we set debug info needed on New_F even though it does not come
712 -- from source, so that the debugger will get the right information
713 -- for these generated names.
715 Set_Debug_Info_Needed
(New_F
);
717 if Ekind
(Formal
) = E_In_Parameter
then
718 Set_Ekind
(New_F
, E_Constant
);
720 Set_Ekind
(New_F
, E_Variable
);
721 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
724 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
727 Make_Selected_Component
(Loc
,
729 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
730 Make_Identifier
(Loc
, Chars
(Ptr
))),
731 Selector_Name
=> New_Reference_To
(Comp
, Loc
));
734 Build_Renamed_Formal_Declaration
735 (New_F
, Formal
, Comp
, Renamed_Formal
);
737 Append
(Decl
, Decls
);
738 Set_Renamed_Object
(Formal
, New_F
);
739 Next_Formal
(Formal
);
741 end Add_Formal_Renamings
;
743 ------------------------
744 -- Add_Object_Pointer --
745 ------------------------
747 procedure Add_Object_Pointer
749 Conc_Typ
: Entity_Id
;
752 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
757 -- Create the renaming declaration for the Protection object of a
758 -- protected type. _Object is used by Complete_Entry_Body.
759 -- ??? An attempt to make this a renaming was unsuccessful.
761 -- Build the entity for the access type
764 Make_Defining_Identifier
(Loc
,
765 New_External_Name
(Chars
(Rec_Typ
), 'P'));
768 -- _object : poVP := poVP!O;
771 Make_Object_Declaration
(Loc
,
772 Defining_Identifier
=>
773 Make_Defining_Identifier
(Loc
, Name_uObject
),
775 New_Reference_To
(Obj_Ptr
, Loc
),
777 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
778 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
779 Prepend_To
(Decls
, Decl
);
782 -- type poVP is access poV;
785 Make_Full_Type_Declaration
(Loc
,
786 Defining_Identifier
=>
789 Make_Access_To_Object_Definition
(Loc
,
790 Subtype_Indication
=>
791 New_Reference_To
(Rec_Typ
, Loc
)));
792 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
793 Prepend_To
(Decls
, Decl
);
794 end Add_Object_Pointer
;
796 -----------------------
797 -- Build_Accept_Body --
798 -----------------------
800 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
801 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
802 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
809 -- At the end of the statement sequence, Complete_Rendezvous is called.
810 -- A label skipping the Complete_Rendezvous, and all other accept
811 -- processing, has already been added for the expansion of requeue
812 -- statements. The Sloc is copied from the last statement since it
813 -- is really part of this last statement.
817 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
818 Insert_Before
(Last
(Statements
(Stats
)), Call
);
821 -- If exception handlers are present, then append Complete_Rendezvous
822 -- calls to the handlers, and construct the required outer block. As
823 -- above, the Sloc is copied from the last statement in the sequence.
825 if Present
(Exception_Handlers
(Stats
)) then
826 Hand
:= First
(Exception_Handlers
(Stats
));
827 while Present
(Hand
) loop
830 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
831 Append
(Call
, Statements
(Hand
));
837 Make_Handled_Sequence_Of_Statements
(Loc
,
838 Statements
=> New_List
(
839 Make_Block_Statement
(Loc
,
840 Handled_Statement_Sequence
=> Stats
)));
846 -- At this stage we know that the new statement sequence does
847 -- not have an exception handler part, so we supply one to call
848 -- Exceptional_Complete_Rendezvous. This handler is
850 -- when all others =>
851 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
853 -- We handle Abort_Signal to make sure that we properly catch the abort
854 -- case and wake up the caller.
856 Ohandle
:= Make_Others_Choice
(Loc
);
857 Set_All_Others
(Ohandle
);
859 Set_Exception_Handlers
(New_S
,
861 Make_Implicit_Exception_Handler
(Loc
,
862 Exception_Choices
=> New_List
(Ohandle
),
864 Statements
=> New_List
(
865 Make_Procedure_Call_Statement
(Sloc
(Stats
),
866 Name
=> New_Reference_To
(
867 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
868 Parameter_Associations
=> New_List
(
869 Make_Function_Call
(Sloc
(Stats
),
870 Name
=> New_Reference_To
(
871 RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
873 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
874 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
875 Expand_Exception_Handlers
(New_S
);
877 -- Exceptional_Complete_Rendezvous must be called with abort
878 -- still deferred, which is the case for a "when all others" handler.
881 end Build_Accept_Body
;
883 -----------------------------------
884 -- Build_Activation_Chain_Entity --
885 -----------------------------------
887 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
888 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
889 -- Determine whether an extended return statement has an activation
892 --------------------------
893 -- Has_Activation_Chain --
894 --------------------------
896 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
900 Decl
:= First
(Return_Object_Declarations
(Stmt
));
901 while Present
(Decl
) loop
902 if Nkind
(Decl
) = N_Object_Declaration
903 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
912 end Has_Activation_Chain
;
917 Context_Id
: Entity_Id
;
920 -- Start of processing for Build_Activation_Chain_Entity
923 -- Activation chain is never used for sequential elaboration policy, see
924 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
926 if Partition_Elaboration_Policy
= 'S' then
930 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
932 -- If activation chain entity has not been declared already, create one
934 if Nkind
(Context
) = N_Extended_Return_Statement
935 or else No
(Activation_Chain_Entity
(Context
))
937 -- Since extended return statements do not store the entity of the
938 -- chain, examine the return object declarations to avoid creating
941 if Nkind
(Context
) = N_Extended_Return_Statement
942 and then Has_Activation_Chain
(Context
)
948 Loc
: constant Source_Ptr
:= Sloc
(Context
);
953 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
955 -- Note: An extended return statement is not really a task
956 -- activator, but it does have an activation chain on which to
957 -- store the tasks temporarily. On successful return, the tasks
958 -- on this chain are moved to the chain passed in by the caller.
959 -- We do not build an Activation_Chain_Entity for an extended
960 -- return statement, because we do not want to build a call to
961 -- Activate_Tasks. Task activation is the responsibility of the
964 if Nkind
(Context
) /= N_Extended_Return_Statement
then
965 Set_Activation_Chain_Entity
(Context
, Chain
);
969 Make_Object_Declaration
(Loc
,
970 Defining_Identifier
=> Chain
,
971 Aliased_Present
=> True,
973 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
));
975 Prepend_To
(Decls
, Decl
);
977 -- Ensure that _chain appears in the proper scope of the context
979 if Context_Id
/= Current_Scope
then
980 Push_Scope
(Context_Id
);
988 end Build_Activation_Chain_Entity
;
990 ----------------------------
991 -- Build_Barrier_Function --
992 ----------------------------
994 function Build_Barrier_Function
997 Pid
: Node_Id
) return Node_Id
999 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
1000 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
1001 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
1002 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
1003 Op_Decls
: constant List_Id
:= New_List
;
1005 Func_Body
: Node_Id
;
1008 -- Add a declaration for the Protection object, renaming declarations
1009 -- for the discriminals and privals and finally a declaration for the
1010 -- entry family index (if applicable).
1012 Install_Private_Data_Declarations
(Sloc
(N
),
1018 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1020 -- If compiling with -fpreserve-control-flow, make sure we insert an
1021 -- IF statement so that the back-end knows to generate a conditional
1022 -- branch instruction, even if the condition is just the name of a
1023 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1024 -- such redundant IF statements under -fpreserve-control-flow
1025 -- (whether coming from this routine, or directly from source).
1027 if Opt
.Suppress_Control_Flow_Optimizations
then
1028 Stmt
:= Make_Implicit_If_Statement
(Cond
,
1030 Then_Statements
=> New_List
(
1031 Make_Simple_Return_Statement
(Loc
,
1032 New_Occurrence_Of
(Standard_True
, Loc
))),
1033 Else_Statements
=> New_List
(
1034 Make_Simple_Return_Statement
(Loc
,
1035 New_Occurrence_Of
(Standard_False
, Loc
))));
1038 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1041 -- Note: the condition in the barrier function needs to be properly
1042 -- processed for the C/Fortran boolean possibility, but this happens
1043 -- automatically since the return statement does this normalization.
1046 Make_Subprogram_Body
(Loc
,
1048 Build_Barrier_Function_Specification
(Loc
,
1049 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1050 Declarations
=> Op_Decls
,
1051 Handled_Statement_Sequence
=>
1052 Make_Handled_Sequence_Of_Statements
(Loc
,
1053 Statements
=> New_List
(Stmt
)));
1054 Set_Is_Entry_Barrier_Function
(Func_Body
);
1057 end Build_Barrier_Function
;
1059 ------------------------------------------
1060 -- Build_Barrier_Function_Specification --
1061 ------------------------------------------
1063 function Build_Barrier_Function_Specification
1065 Def_Id
: Entity_Id
) return Node_Id
1068 Set_Debug_Info_Needed
(Def_Id
);
1070 return Make_Function_Specification
(Loc
,
1071 Defining_Unit_Name
=> Def_Id
,
1072 Parameter_Specifications
=> New_List
(
1073 Make_Parameter_Specification
(Loc
,
1074 Defining_Identifier
=>
1075 Make_Defining_Identifier
(Loc
, Name_uO
),
1077 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1079 Make_Parameter_Specification
(Loc
,
1080 Defining_Identifier
=>
1081 Make_Defining_Identifier
(Loc
, Name_uE
),
1083 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1085 Result_Definition
=>
1086 New_Reference_To
(Standard_Boolean
, Loc
));
1087 end Build_Barrier_Function_Specification
;
1089 --------------------------
1090 -- Build_Call_With_Task --
1091 --------------------------
1093 function Build_Call_With_Task
1095 E
: Entity_Id
) return Node_Id
1097 Loc
: constant Source_Ptr
:= Sloc
(N
);
1100 Make_Function_Call
(Loc
,
1101 Name
=> New_Reference_To
(E
, Loc
),
1102 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1103 end Build_Call_With_Task
;
1105 -----------------------------
1106 -- Build_Class_Wide_Master --
1107 -----------------------------
1109 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1110 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1111 Master_Id
: Entity_Id
;
1112 Master_Scope
: Entity_Id
;
1114 Related_Node
: Node_Id
;
1118 -- Nothing to do if there is no task hierarchy
1120 if Restriction_Active
(No_Task_Hierarchy
) then
1124 -- Find the declaration that created the access type. It is either a
1125 -- type declaration, or an object declaration with an access definition,
1126 -- in which case the type is anonymous.
1128 if Is_Itype
(Typ
) then
1129 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1131 Related_Node
:= Parent
(Typ
);
1134 Master_Scope
:= Find_Master_Scope
(Typ
);
1136 -- Nothing to do if the master scope already contains a _master entity.
1137 -- The only exception to this is the following scenario:
1140 -- Transient_Scope_1
1143 -- Transient_Scope_2
1146 -- In this case the source scope is marked as having the master entity
1147 -- even though the actual declaration appears inside an inner scope. If
1148 -- the second transient scope requires a _master, it cannot use the one
1149 -- already declared because the entity is not visible.
1151 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1153 if not Has_Master_Entity
(Master_Scope
)
1154 or else No
(Current_Entity_In_Scope
(Name_Id
))
1157 Master_Decl
: Node_Id
;
1160 Set_Has_Master_Entity
(Master_Scope
);
1163 -- _master : constant Integer := Current_Master.all;
1166 Make_Object_Declaration
(Loc
,
1167 Defining_Identifier
=>
1168 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1169 Constant_Present
=> True,
1170 Object_Definition
=>
1171 New_Reference_To
(Standard_Integer
, Loc
),
1173 Make_Explicit_Dereference
(Loc
,
1174 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
1176 Insert_Action
(Related_Node
, Master_Decl
);
1177 Analyze
(Master_Decl
);
1179 -- Mark the containing scope as a task master. Masters associated
1180 -- with return statements are already marked at this stage (see
1181 -- Analyze_Subprogram_Body).
1183 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1185 Par
: Node_Id
:= Related_Node
;
1188 while Nkind
(Par
) /= N_Compilation_Unit
loop
1189 Par
:= Parent
(Par
);
1191 -- If we fall off the top, we are at the outer level,
1192 -- and the environment task is our effective master,
1193 -- so nothing to mark.
1195 if Nkind_In
(Par
, N_Block_Statement
,
1199 Set_Is_Task_Master
(Par
);
1209 Make_Defining_Identifier
(Loc
,
1210 New_External_Name
(Chars
(Typ
), 'M'));
1213 -- Mnn renames _master;
1216 Make_Object_Renaming_Declaration
(Loc
,
1217 Defining_Identifier
=> Master_Id
,
1218 Subtype_Mark
=> New_Reference_To
(Standard_Integer
, Loc
),
1221 Insert_Action
(Related_Node
, Ren_Decl
);
1223 Set_Master_Id
(Typ
, Master_Id
);
1224 end Build_Class_Wide_Master
;
1226 --------------------------------
1227 -- Build_Corresponding_Record --
1228 --------------------------------
1230 function Build_Corresponding_Record
1233 Loc
: Source_Ptr
) return Node_Id
1235 Rec_Ent
: constant Entity_Id
:=
1236 Make_Defining_Identifier
1237 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1240 New_Disc
: Entity_Id
;
1244 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1245 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1246 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1247 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1248 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1249 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1252 -- Use discriminals to create list of discriminants for record, and
1253 -- create new discriminals for use in default expressions, etc. It is
1254 -- worth noting that a task discriminant gives rise to 5 entities;
1256 -- a) The original discriminant.
1257 -- b) The discriminal for use in the task.
1258 -- c) The discriminant of the corresponding record.
1259 -- d) The discriminal for the init proc of the corresponding record.
1260 -- e) The local variable that renames the discriminant in the procedure
1261 -- for the task body.
1263 -- In fact the discriminals b) are used in the renaming declarations
1264 -- for e). See details in einfo (Handling of Discriminants).
1266 if Present
(Discriminant_Specifications
(N
)) then
1268 Disc
:= First_Discriminant
(Ctyp
);
1270 while Present
(Disc
) loop
1271 New_Disc
:= CR_Discriminant
(Disc
);
1274 Make_Discriminant_Specification
(Loc
,
1275 Defining_Identifier
=> New_Disc
,
1276 Discriminant_Type
=>
1277 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1279 New_Copy
(Discriminant_Default_Value
(Disc
))));
1281 Next_Discriminant
(Disc
);
1288 -- Now we can construct the record type declaration. Note that this
1289 -- record is "limited tagged". It is "limited" to reflect the underlying
1290 -- limitedness of the task or protected object that it represents, and
1291 -- ensuring for example that it is properly passed by reference. It is
1292 -- "tagged" to give support to dispatching calls through interfaces. We
1293 -- propagate here the list of interfaces covered by the concurrent type
1294 -- (Ada 2005: AI-345).
1297 Make_Full_Type_Declaration
(Loc
,
1298 Defining_Identifier
=> Rec_Ent
,
1299 Discriminant_Specifications
=> Dlist
,
1301 Make_Record_Definition
(Loc
,
1303 Make_Component_List
(Loc
,
1304 Component_Items
=> Cdecls
),
1306 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1307 Interface_List
=> Interface_List
(N
),
1308 Limited_Present
=> True));
1309 end Build_Corresponding_Record
;
1311 ---------------------------------
1312 -- Build_Dispatching_Tag_Check --
1313 ---------------------------------
1315 function Build_Dispatching_Tag_Check
1317 N
: Node_Id
) return Node_Id
1319 Loc
: constant Source_Ptr
:= Sloc
(N
);
1324 Left_Opnd
=> New_Reference_To
(K
, Loc
),
1325 Right_Opnd
=> New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1327 Left_Opnd
=> New_Reference_To
(K
, Loc
),
1328 Right_Opnd
=> New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
)));
1329 end Build_Dispatching_Tag_Check
;
1331 ----------------------------------
1332 -- Build_Entry_Count_Expression --
1333 ----------------------------------
1335 function Build_Entry_Count_Expression
1336 (Concurrent_Type
: Node_Id
;
1337 Component_List
: List_Id
;
1338 Loc
: Source_Ptr
) return Node_Id
1350 -- Count number of non-family entries
1353 Ent
:= First_Entity
(Concurrent_Type
);
1354 while Present
(Ent
) loop
1355 if Ekind
(Ent
) = E_Entry
then
1362 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1364 -- Loop through entry families building the addition nodes
1366 Ent
:= First_Entity
(Concurrent_Type
);
1367 Comp
:= First
(Component_List
);
1368 while Present
(Ent
) loop
1369 if Ekind
(Ent
) = E_Entry_Family
then
1370 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1374 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1375 Hi
:= Type_High_Bound
(Typ
);
1376 Lo
:= Type_Low_Bound
(Typ
);
1377 Large
:= Is_Potentially_Large_Family
1378 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1381 Left_Opnd
=> Ecount
,
1382 Right_Opnd
=> Family_Size
1383 (Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1390 end Build_Entry_Count_Expression
;
1392 -----------------------
1393 -- Build_Entry_Names --
1394 -----------------------
1396 procedure Build_Entry_Names
1398 Obj_Typ
: Entity_Id
;
1401 Loc
: constant Source_Ptr
:= Sloc
(Obj_Ref
);
1402 Data
: Entity_Id
:= Empty
;
1403 Index
: Entity_Id
:= Empty
;
1404 Typ
: Entity_Id
:= Obj_Typ
;
1406 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
);
1407 -- Given an entry [family], create a static string which denotes the
1408 -- name of Comp_Id and assign it to the underlying data structure which
1409 -- contains the entry names of a concurrent object.
1411 function Object_Reference
return Node_Id
;
1412 -- Return a reference to field _object or _task_id depending on the
1413 -- concurrent object being processed.
1415 ----------------------
1416 -- Build_Entry_Name --
1417 ----------------------
1419 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
) is
1420 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1421 -- Given a discrete subtype definition of an entry family, generate a
1422 -- range node which covers the range of Def's type.
1424 procedure Create_Index_And_Data
;
1425 -- Generate the declarations of variables Index and Data. Subsequent
1426 -- calls do nothing.
1428 function Increment_Index
return Node_Id
;
1429 -- Increment the index used in the assignment of string names to the
1432 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
;
1433 -- Given the name of a temporary variable, create the following
1434 -- declaration for it:
1436 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1438 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
;
1439 -- Given the name of a temporary variable, place it in the array of
1440 -- string names. Generate:
1442 -- Data (Index) := Def_Id'Unchecked_Access;
1448 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1449 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1450 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1453 -- If a bound references a discriminant, generate an identifier
1454 -- with the same name. Resolution will map it to the formals of
1457 if Is_Entity_Name
(Low
)
1458 and then Ekind
(Entity
(Low
)) = E_Discriminant
1461 Make_Selected_Component
(Loc
,
1462 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1463 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Low
)));
1465 Low
:= New_Copy_Tree
(Low
);
1468 if Is_Entity_Name
(High
)
1469 and then Ekind
(Entity
(High
)) = E_Discriminant
1472 Make_Selected_Component
(Loc
,
1473 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1474 Selector_Name
=> Make_Identifier
(Loc
, Chars
(High
)));
1476 High
:= New_Copy_Tree
(High
);
1482 High_Bound
=> High
);
1485 ---------------------------
1486 -- Create_Index_And_Data --
1487 ---------------------------
1489 procedure Create_Index_And_Data
is
1491 if No
(Index
) and then No
(Data
) then
1498 if Is_Protected_Type
(Typ
) then
1499 Count
:= RO_PE_Number_Of_Entries
;
1500 Data_Typ
:= RE_Protected_Entry_Names_Array
;
1502 Count
:= RO_ST_Number_Of_Entries
;
1503 Data_Typ
:= RE_Task_Entry_Names_Array
;
1506 -- Step 1: Generate the declaration of the index variable:
1508 -- Index : Entry_Index := 1;
1510 Index
:= Make_Temporary
(Loc
, 'I');
1513 Make_Object_Declaration
(Loc
,
1514 Defining_Identifier
=> Index
,
1515 Object_Definition
=>
1516 New_Reference_To
(RTE
(RE_Entry_Index
), Loc
),
1517 Expression
=> Make_Integer_Literal
(Loc
, 1)));
1519 -- Step 2: Generate the declaration of an array to house all
1522 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1523 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1525 Size
:= Make_Temporary
(Loc
, 'S');
1528 Make_Object_Declaration
(Loc
,
1529 Defining_Identifier
=> Size
,
1530 Constant_Present
=> True,
1531 Object_Definition
=>
1532 New_Reference_To
(RTE
(RE_Entry_Index
), Loc
),
1534 Make_Function_Call
(Loc
,
1536 New_Reference_To
(RTE
(Count
), Loc
),
1537 Parameter_Associations
=>
1538 New_List
(Object_Reference
))));
1540 Data
:= Make_Temporary
(Loc
, 'A');
1543 Make_Object_Declaration
(Loc
,
1544 Defining_Identifier
=> Data
,
1545 Aliased_Present
=> True,
1546 Object_Definition
=>
1547 New_Reference_To
(RTE
(Data_Typ
), Loc
),
1549 Make_Aggregate
(Loc
,
1550 Component_Associations
=> New_List
(
1551 Make_Component_Association
(Loc
,
1552 Choices
=> New_List
(
1554 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1555 High_Bound
=> New_Reference_To
(Size
, Loc
))),
1556 Expression
=> Make_Null
(Loc
))))));
1559 end Create_Index_And_Data
;
1561 ---------------------
1562 -- Increment_Index --
1563 ---------------------
1565 function Increment_Index
return Node_Id
is
1568 Make_Assignment_Statement
(Loc
,
1569 Name
=> New_Reference_To
(Index
, Loc
),
1572 Left_Opnd
=> New_Reference_To
(Index
, Loc
),
1573 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
1574 end Increment_Index
;
1576 ----------------------
1577 -- Name_Declaration --
1578 ----------------------
1580 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
is
1583 Make_Object_Declaration
(Loc
,
1584 Defining_Identifier
=> Def_Id
,
1585 Aliased_Present
=> True,
1586 Constant_Present
=> True,
1587 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
1589 Make_String_Literal
(Loc
, String_From_Name_Buffer
));
1590 end Name_Declaration
;
1592 --------------------
1593 -- Set_Entry_Name --
1594 --------------------
1596 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
is
1599 Make_Assignment_Statement
(Loc
,
1601 Make_Indexed_Component
(Loc
,
1602 Prefix
=> New_Reference_To
(Data
, Loc
),
1603 Expressions
=> New_List
(New_Reference_To
(Index
, Loc
))),
1606 Make_Attribute_Reference
(Loc
,
1607 Prefix
=> New_Reference_To
(Def_Id
, Loc
),
1608 Attribute_Name
=> Name_Unchecked_Access
));
1613 Temp_Id
: Entity_Id
;
1616 -- Start of processing for Build_Entry_Name
1619 if Ekind
(Comp_Id
) = E_Entry_Family
then
1620 Subt_Def
:= Discrete_Subtype_Definition
(Parent
(Comp_Id
));
1622 Create_Index_And_Data
;
1624 -- Step 1: Create the string name of the entry family.
1626 -- Temp : aliased constant String := "name ()";
1628 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1629 Get_Name_String
(Chars
(Comp_Id
));
1630 Add_Char_To_Name_Buffer
(' ');
1631 Add_Char_To_Name_Buffer
('(');
1632 Add_Char_To_Name_Buffer
(')');
1634 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1637 -- for Member in Family_Low .. Family_High loop
1638 -- Set_Entry_Name (...);
1639 -- Index := Index + 1;
1643 Make_Loop_Statement
(Loc
,
1645 Make_Iteration_Scheme
(Loc
,
1646 Loop_Parameter_Specification
=>
1647 Make_Loop_Parameter_Specification
(Loc
,
1648 Defining_Identifier
=>
1649 Make_Temporary
(Loc
, 'L'),
1650 Discrete_Subtype_Definition
=>
1651 Build_Range
(Subt_Def
))),
1653 Statements
=> New_List
(
1654 Set_Entry_Name
(Temp_Id
),
1656 End_Label
=> Empty
));
1661 Create_Index_And_Data
;
1663 -- Step 1: Create the string name of the entry. Generate:
1664 -- Temp : aliased constant String := "name";
1666 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1667 Get_Name_String
(Chars
(Comp_Id
));
1669 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1671 -- Step 2: Associate the string name with the underlying data
1674 Append_To
(Stmts
, Set_Entry_Name
(Temp_Id
));
1675 Append_To
(Stmts
, Increment_Index
);
1677 end Build_Entry_Name
;
1679 ----------------------
1680 -- Object_Reference --
1681 ----------------------
1683 function Object_Reference
return Node_Id
is
1684 Conc_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Typ
);
1689 if Is_Protected_Type
(Typ
) then
1690 Field
:= Name_uObject
;
1692 Field
:= Name_uTask_Id
;
1696 Make_Selected_Component
(Loc
,
1698 Unchecked_Convert_To
(Conc_Typ
, New_Copy_Tree
(Obj_Ref
)),
1699 Selector_Name
=> Make_Identifier
(Loc
, Field
));
1701 if Is_Protected_Type
(Typ
) then
1703 Make_Attribute_Reference
(Loc
,
1705 Attribute_Name
=> Name_Unchecked_Access
);
1709 end Object_Reference
;
1716 -- Start of processing for Build_Entry_Names
1719 -- Retrieve the original concurrent type
1721 if Is_Concurrent_Record_Type
(Typ
) then
1722 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1725 pragma Assert
(Is_Concurrent_Type
(Typ
));
1727 -- Nothing to do if the type has no entries
1729 if not Has_Entries
(Typ
) then
1733 -- Avoid generating entry names for a protected type with only one entry
1735 if Is_Protected_Type
(Typ
)
1736 and then Find_Protection_Type
(Base_Type
(Typ
)) /=
1737 RTE
(RE_Protection_Entries
)
1742 -- Step 1: Populate the array with statically generated strings denoting
1743 -- entries and entry family names.
1745 Comp
:= First_Entity
(Typ
);
1746 while Present
(Comp
) loop
1747 if Comes_From_Source
(Comp
)
1748 and then Ekind_In
(Comp
, E_Entry
, E_Entry_Family
)
1750 Build_Entry_Name
(Comp
);
1756 -- Step 2: Associate the array with the related concurrent object:
1758 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1760 if Present
(Data
) then
1761 if Is_Protected_Type
(Typ
) then
1762 Proc
:= RO_PE_Set_Entry_Names
;
1764 Proc
:= RO_ST_Set_Entry_Names
;
1768 Make_Procedure_Call_Statement
(Loc
,
1769 Name
=> New_Reference_To
(RTE
(Proc
), Loc
),
1770 Parameter_Associations
=> New_List
(
1772 Make_Attribute_Reference
(Loc
,
1773 Prefix
=> New_Reference_To
(Data
, Loc
),
1774 Attribute_Name
=> Name_Unchecked_Access
))));
1776 end Build_Entry_Names
;
1778 ---------------------------
1779 -- Build_Parameter_Block --
1780 ---------------------------
1782 function Build_Parameter_Block
1786 Decls
: List_Id
) return Entity_Id
1792 Has_Comp
: Boolean := False;
1796 Actual
:= First
(Actuals
);
1798 Formal
:= Defining_Identifier
(First
(Formals
));
1800 while Present
(Actual
) loop
1801 if not Is_Controlling_Actual
(Actual
) then
1804 -- type Ann is access all <actual-type>
1806 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1809 Make_Full_Type_Declaration
(Loc
,
1810 Defining_Identifier
=> Comp_Nam
,
1812 Make_Access_To_Object_Definition
(Loc
,
1813 All_Present
=> True,
1814 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1815 Subtype_Indication
=>
1816 New_Reference_To
(Etype
(Actual
), Loc
))));
1822 Make_Component_Declaration
(Loc
,
1823 Defining_Identifier
=>
1824 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1825 Component_Definition
=>
1826 Make_Component_Definition
(Loc
,
1829 Subtype_Indication
=>
1830 New_Reference_To
(Comp_Nam
, Loc
))));
1835 Next_Actual
(Actual
);
1836 Next_Formal_With_Extras
(Formal
);
1839 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1844 -- type Pnn is record
1849 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1850 -- the original parameter names and Ann1 .. AnnN are the access to
1854 Make_Full_Type_Declaration
(Loc
,
1855 Defining_Identifier
=>
1858 Make_Record_Definition
(Loc
,
1860 Make_Component_List
(Loc
, Comps
))));
1863 -- type Pnn is null record;
1866 Make_Full_Type_Declaration
(Loc
,
1867 Defining_Identifier
=>
1870 Make_Record_Definition
(Loc
,
1871 Null_Present
=> True,
1872 Component_List
=> Empty
)));
1876 end Build_Parameter_Block
;
1878 --------------------------------------
1879 -- Build_Renamed_Formal_Declaration --
1880 --------------------------------------
1882 function Build_Renamed_Formal_Declaration
1886 Renamed_Formal
: Node_Id
) return Node_Id
1888 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1892 -- If the formal is a tagged incomplete type, it is already passed
1893 -- by reference, so it is sufficient to rename the pointer component
1894 -- that corresponds to the actual. Otherwise we need to dereference
1895 -- the pointer component to obtain the actual.
1897 if Is_Incomplete_Type
(Etype
(Formal
))
1898 and then Is_Tagged_Type
(Etype
(Formal
))
1901 Make_Object_Renaming_Declaration
(Loc
,
1902 Defining_Identifier
=> New_F
,
1903 Subtype_Mark
=> New_Reference_To
(Etype
(Comp
), Loc
),
1904 Name
=> Renamed_Formal
);
1908 Make_Object_Renaming_Declaration
(Loc
,
1909 Defining_Identifier
=> New_F
,
1910 Subtype_Mark
=> New_Reference_To
(Etype
(Formal
), Loc
),
1912 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1916 end Build_Renamed_Formal_Declaration
;
1918 -----------------------
1919 -- Build_PPC_Wrapper --
1920 -----------------------
1922 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1923 Loc
: constant Source_Ptr
:= Sloc
(E
);
1924 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1926 Wrapper_Id
: constant Entity_Id
:=
1927 Make_Defining_Identifier
(Loc
,
1928 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1929 -- the wrapper procedure name
1931 Wrapper_Body
: Node_Id
;
1933 Synch_Id
: constant Entity_Id
:=
1934 Make_Defining_Identifier
(Loc
,
1935 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1936 -- The parameter that designates the synchronized object in the call
1938 Actuals
: constant List_Id
:= New_List
;
1939 -- The actuals in the entry call
1941 Decls
: constant List_Id
:= New_List
;
1943 Entry_Call
: Node_Id
;
1944 Entry_Name
: Node_Id
;
1947 -- The specification of the wrapper procedure
1951 -- Only build the wrapper if entry has pre/postconditions.
1952 -- Should this be done unconditionally instead ???
1958 P
:= Pre_Post_Conditions
(Contract
(E
));
1964 -- Transfer ppc pragmas to the declarations of the wrapper
1966 while Present
(P
) loop
1967 if Nam_In
(Pragma_Name
(P
), Name_Precondition
,
1970 Append
(Relocate_Node
(P
), Decls
);
1971 Set_Analyzed
(Last
(Decls
), False);
1974 P
:= Next_Pragma
(P
);
1978 -- First formal is synchronized object
1981 Make_Parameter_Specification
(Loc
,
1982 Defining_Identifier
=> Synch_Id
,
1983 Out_Present
=> True,
1985 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1988 Make_Selected_Component
(Loc
,
1989 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1990 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1992 -- If entity is entry family, second formal is the corresponding index,
1993 -- and entry name is an indexed component.
1995 if Ekind
(E
) = E_Entry_Family
then
1997 Index
: constant Entity_Id
:=
1998 Make_Defining_Identifier
(Loc
, Name_I
);
2001 Make_Parameter_Specification
(Loc
,
2002 Defining_Identifier
=> Index
,
2004 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
2007 Make_Indexed_Component
(Loc
,
2008 Prefix
=> Entry_Name
,
2009 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
2014 Make_Procedure_Call_Statement
(Loc
,
2016 Parameter_Associations
=> Actuals
);
2018 -- Now add formals that match those of the entry, and build actuals for
2019 -- the nested entry call.
2023 New_Form
: Entity_Id
;
2024 Parm_Spec
: Node_Id
;
2027 Form
:= First_Formal
(E
);
2028 while Present
(Form
) loop
2029 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
2031 Make_Parameter_Specification
(Loc
,
2032 Defining_Identifier
=> New_Form
,
2033 Out_Present
=> Out_Present
(Parent
(Form
)),
2034 In_Present
=> In_Present
(Parent
(Form
)),
2035 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
2037 Append
(Parm_Spec
, Specs
);
2038 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
2043 -- Add renaming declarations for the discriminants of the enclosing
2044 -- type, which may be visible in the preconditions.
2046 if Has_Discriminants
(Synch_Type
) then
2052 D
:= First_Discriminant
(Synch_Type
);
2053 while Present
(D
) loop
2055 Make_Object_Renaming_Declaration
(Loc
,
2056 Defining_Identifier
=>
2057 Make_Defining_Identifier
(Loc
, Chars
(D
)),
2058 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
2060 Make_Selected_Component
(Loc
,
2061 Prefix
=> New_Reference_To
(Synch_Id
, Loc
),
2062 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
2063 Prepend
(Decl
, Decls
);
2064 Next_Discriminant
(D
);
2069 Set_PPC_Wrapper
(E
, Wrapper_Id
);
2071 Make_Subprogram_Body
(Loc
,
2073 Make_Procedure_Specification
(Loc
,
2074 Defining_Unit_Name
=> Wrapper_Id
,
2075 Parameter_Specifications
=> Specs
),
2076 Declarations
=> Decls
,
2077 Handled_Statement_Sequence
=>
2078 Make_Handled_Sequence_Of_Statements
(Loc
,
2079 Statements
=> New_List
(Entry_Call
)));
2081 -- The wrapper body is analyzed when the enclosing type is frozen
2083 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
2084 end Build_PPC_Wrapper
;
2086 --------------------------
2087 -- Build_Wrapper_Bodies --
2088 --------------------------
2090 procedure Build_Wrapper_Bodies
2095 Rec_Typ
: Entity_Id
;
2097 function Build_Wrapper_Body
2099 Subp_Id
: Entity_Id
;
2100 Obj_Typ
: Entity_Id
;
2101 Formals
: List_Id
) return Node_Id
;
2102 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2103 -- associated with a protected or task type. Subp_Id is the subprogram
2104 -- name which will be wrapped. Obj_Typ is the type of the new formal
2105 -- parameter which handles dispatching and object notation. Formals are
2106 -- the original formals of Subp_Id which will be explicitly replicated.
2108 ------------------------
2109 -- Build_Wrapper_Body --
2110 ------------------------
2112 function Build_Wrapper_Body
2114 Subp_Id
: Entity_Id
;
2115 Obj_Typ
: Entity_Id
;
2116 Formals
: List_Id
) return Node_Id
2118 Body_Spec
: Node_Id
;
2121 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
2123 -- The subprogram is not overriding or is not a primitive declared
2124 -- between two views.
2126 if No
(Body_Spec
) then
2131 Actuals
: List_Id
:= No_List
;
2133 First_Form
: Node_Id
;
2138 -- Map formals to actuals. Use the list built for the wrapper
2139 -- spec, skipping the object notation parameter.
2141 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
2143 Formal
:= First_Form
;
2146 if Present
(Formal
) then
2147 Actuals
:= New_List
;
2148 while Present
(Formal
) loop
2150 Make_Identifier
(Loc
,
2151 Chars
=> Chars
(Defining_Identifier
(Formal
))));
2156 -- Special processing for primitives declared between a private
2157 -- type and its completion: the wrapper needs a properly typed
2158 -- parameter if the wrapped operation has a controlling first
2159 -- parameter. Note that this might not be the case for a function
2160 -- with a controlling result.
2162 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
2163 if No
(Actuals
) then
2164 Actuals
:= New_List
;
2167 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
2168 Prepend_To
(Actuals
,
2169 Unchecked_Convert_To
2170 (Corresponding_Concurrent_Type
(Obj_Typ
),
2171 Make_Identifier
(Loc
, Name_uO
)));
2174 Prepend_To
(Actuals
,
2175 Make_Identifier
(Loc
,
2176 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
2179 Nam
:= New_Reference_To
(Subp_Id
, Loc
);
2181 -- An access-to-variable object parameter requires an explicit
2182 -- dereference in the unchecked conversion. This case occurs
2183 -- when a protected entry wrapper must override an interface
2184 -- level procedure with interface access as first parameter.
2186 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2188 if Nkind
(Parameter_Type
(First_Form
)) =
2192 Make_Explicit_Dereference
(Loc
,
2193 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
2195 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
2199 Make_Selected_Component
(Loc
,
2201 Unchecked_Convert_To
2202 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
2203 Selector_Name
=> New_Reference_To
(Subp_Id
, Loc
));
2206 -- Create the subprogram body. For a function, the call to the
2207 -- actual subprogram has to be converted to the corresponding
2208 -- record if it is a controlling result.
2210 if Ekind
(Subp_Id
) = E_Function
then
2216 Make_Function_Call
(Loc
,
2218 Parameter_Associations
=> Actuals
);
2220 if Has_Controlling_Result
(Subp_Id
) then
2222 Unchecked_Convert_To
2223 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
2227 Make_Subprogram_Body
(Loc
,
2228 Specification
=> Body_Spec
,
2229 Declarations
=> Empty_List
,
2230 Handled_Statement_Sequence
=>
2231 Make_Handled_Sequence_Of_Statements
(Loc
,
2232 Statements
=> New_List
(
2233 Make_Simple_Return_Statement
(Loc
, Res
))));
2238 Make_Subprogram_Body
(Loc
,
2239 Specification
=> Body_Spec
,
2240 Declarations
=> Empty_List
,
2241 Handled_Statement_Sequence
=>
2242 Make_Handled_Sequence_Of_Statements
(Loc
,
2243 Statements
=> New_List
(
2244 Make_Procedure_Call_Statement
(Loc
,
2246 Parameter_Associations
=> Actuals
))));
2249 end Build_Wrapper_Body
;
2251 -- Start of processing for Build_Wrapper_Bodies
2254 if Is_Concurrent_Type
(Typ
) then
2255 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2260 -- Generate wrapper bodies for a concurrent type which implements an
2263 if Present
(Interfaces
(Rec_Typ
)) then
2265 Insert_Nod
: Node_Id
;
2267 Prim_Elmt
: Elmt_Id
;
2268 Prim_Decl
: Node_Id
;
2270 Wrap_Body
: Node_Id
;
2271 Wrap_Id
: Entity_Id
;
2276 -- Examine all primitive operations of the corresponding record
2277 -- type, looking for wrapper specs. Generate bodies in order to
2280 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2281 while Present
(Prim_Elmt
) loop
2282 Prim
:= Node
(Prim_Elmt
);
2284 if (Ekind
(Prim
) = E_Function
2285 or else Ekind
(Prim
) = E_Procedure
)
2286 and then Is_Primitive_Wrapper
(Prim
)
2288 Subp
:= Wrapped_Entity
(Prim
);
2289 Prim_Decl
:= Parent
(Parent
(Prim
));
2292 Build_Wrapper_Body
(Loc
,
2295 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2296 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2298 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2299 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2301 Insert_After
(Insert_Nod
, Wrap_Body
);
2302 Insert_Nod
:= Wrap_Body
;
2304 Analyze
(Wrap_Body
);
2307 Next_Elmt
(Prim_Elmt
);
2311 end Build_Wrapper_Bodies
;
2313 ------------------------
2314 -- Build_Wrapper_Spec --
2315 ------------------------
2317 function Build_Wrapper_Spec
2318 (Subp_Id
: Entity_Id
;
2319 Obj_Typ
: Entity_Id
;
2320 Formals
: List_Id
) return Node_Id
2322 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2323 First_Param
: Node_Id
;
2325 Iface_Elmt
: Elmt_Id
;
2326 Iface_Op
: Entity_Id
;
2327 Iface_Op_Elmt
: Elmt_Id
;
2329 function Overriding_Possible
2330 (Iface_Op
: Entity_Id
;
2331 Wrapper
: Entity_Id
) return Boolean;
2332 -- Determine whether a primitive operation can be overridden by Wrapper.
2333 -- Iface_Op is the candidate primitive operation of an interface type,
2334 -- Wrapper is the generated entry wrapper.
2336 function Replicate_Formals
2338 Formals
: List_Id
) return List_Id
;
2339 -- An explicit parameter replication is required due to the Is_Entry_
2340 -- Formal flag being set for all the formals of an entry. The explicit
2341 -- replication removes the flag that would otherwise cause a different
2342 -- path of analysis.
2344 -------------------------
2345 -- Overriding_Possible --
2346 -------------------------
2348 function Overriding_Possible
2349 (Iface_Op
: Entity_Id
;
2350 Wrapper
: Entity_Id
) return Boolean
2352 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2353 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2355 function Type_Conformant_Parameters
2356 (Iface_Op_Params
: List_Id
;
2357 Wrapper_Params
: List_Id
) return Boolean;
2358 -- Determine whether the parameters of the generated entry wrapper
2359 -- and those of a primitive operation are type conformant. During
2360 -- this check, the first parameter of the primitive operation is
2361 -- skipped if it is a controlling argument: protected functions
2362 -- may have a controlling result.
2364 --------------------------------
2365 -- Type_Conformant_Parameters --
2366 --------------------------------
2368 function Type_Conformant_Parameters
2369 (Iface_Op_Params
: List_Id
;
2370 Wrapper_Params
: List_Id
) return Boolean
2372 Iface_Op_Param
: Node_Id
;
2373 Iface_Op_Typ
: Entity_Id
;
2374 Wrapper_Param
: Node_Id
;
2375 Wrapper_Typ
: Entity_Id
;
2378 -- Skip the first (controlling) parameter of primitive operation
2380 Iface_Op_Param
:= First
(Iface_Op_Params
);
2382 if Present
(First_Formal
(Iface_Op
))
2383 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2385 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2388 Wrapper_Param
:= First
(Wrapper_Params
);
2389 while Present
(Iface_Op_Param
)
2390 and then Present
(Wrapper_Param
)
2392 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2393 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2395 -- The two parameters must be mode conformant
2397 if not Conforming_Types
2398 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2403 Next
(Iface_Op_Param
);
2404 Next
(Wrapper_Param
);
2407 -- One of the lists is longer than the other
2409 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2414 end Type_Conformant_Parameters
;
2416 -- Start of processing for Overriding_Possible
2419 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2423 -- If an inherited subprogram is implemented by a protected procedure
2424 -- or an entry, then the first parameter of the inherited subprogram
2425 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2427 if Ekind
(Iface_Op
) = E_Procedure
2428 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2431 Obj_Param
: constant Node_Id
:=
2432 First
(Parameter_Specifications
(Iface_Op_Spec
));
2434 if not Out_Present
(Obj_Param
)
2435 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2444 Type_Conformant_Parameters
(
2445 Parameter_Specifications
(Iface_Op_Spec
),
2446 Parameter_Specifications
(Wrapper_Spec
));
2447 end Overriding_Possible
;
2449 -----------------------
2450 -- Replicate_Formals --
2451 -----------------------
2453 function Replicate_Formals
2455 Formals
: List_Id
) return List_Id
2457 New_Formals
: constant List_Id
:= New_List
;
2459 Param_Type
: Node_Id
;
2462 Formal
:= First
(Formals
);
2464 -- Skip the object parameter when dealing with primitives declared
2465 -- between two views.
2467 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2468 and then not Has_Controlling_Result
(Subp_Id
)
2470 Formal
:= Next
(Formal
);
2473 while Present
(Formal
) loop
2475 -- Create an explicit copy of the entry parameter
2477 -- When creating the wrapper subprogram for a primitive operation
2478 -- of a protected interface we must construct an equivalent
2479 -- signature to that of the overriding operation. For regular
2480 -- parameters we can just use the type of the formal, but for
2481 -- access to subprogram parameters we need to reanalyze the
2482 -- parameter type to create local entities for the signature of
2483 -- the subprogram type. Using the entities of the overriding
2484 -- subprogram will result in out-of-scope errors in the back-end.
2486 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2487 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2490 New_Reference_To
(Etype
(Parameter_Type
(Formal
)), Loc
);
2493 Append_To
(New_Formals
,
2494 Make_Parameter_Specification
(Loc
,
2495 Defining_Identifier
=>
2496 Make_Defining_Identifier
(Loc
,
2497 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2498 In_Present
=> In_Present
(Formal
),
2499 Out_Present
=> Out_Present
(Formal
),
2500 Parameter_Type
=> Param_Type
));
2506 end Replicate_Formals
;
2508 -- Start of processing for Build_Wrapper_Spec
2511 -- There is no point in building wrappers for non-tagged concurrent
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_Reference_To
(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_Reference_To
(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_Reference_To
(Obj_Typ
, Loc
));
2644 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2645 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2648 Obj_Param_Typ
:= New_Reference_To
(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_Reference_To
(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
))
2789 and then Present
(Def
)
2791 Scan_Declarations
(Visible_Declarations
(Def
));
2792 Scan_Declarations
(Private_Declarations
(Def
));
2794 end Build_Wrapper_Specs
;
2796 ---------------------------
2797 -- Build_Find_Body_Index --
2798 ---------------------------
2800 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2801 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2804 Has_F
: Boolean := False;
2806 If_St
: Node_Id
:= Empty
;
2809 Decls
: List_Id
:= New_List
;
2812 Siz
: Node_Id
:= Empty
;
2814 procedure Add_If_Clause
(Expr
: Node_Id
);
2815 -- Add test for range of current entry
2817 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2818 -- If a bound of an entry is given by a discriminant, retrieve the
2819 -- actual value of the discriminant from the enclosing object.
2825 procedure Add_If_Clause
(Expr
: Node_Id
) is
2827 Stats
: constant List_Id
:=
2829 Make_Simple_Return_Statement
(Loc
,
2830 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2833 -- Index for current entry body
2837 -- Compute total length of entry queues so far
2845 Right_Opnd
=> Expr
);
2850 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2853 -- Map entry queue indexes in the range of the current family
2854 -- into the current index, that designates the entry body.
2858 Make_Implicit_If_Statement
(Typ
,
2860 Then_Statements
=> Stats
,
2861 Elsif_Parts
=> New_List
);
2865 Append_To
(Elsif_Parts
(If_St
),
2866 Make_Elsif_Part
(Loc
,
2868 Then_Statements
=> Stats
));
2872 ------------------------------
2873 -- Convert_Discriminant_Ref --
2874 ------------------------------
2876 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2880 if Is_Entity_Name
(Bound
)
2881 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2884 Make_Selected_Component
(Loc
,
2886 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2887 Make_Explicit_Dereference
(Loc
,
2888 Make_Identifier
(Loc
, Name_uObject
))),
2889 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2890 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2892 B
:= New_Copy_Tree
(Bound
);
2896 end Convert_Discriminant_Ref
;
2898 -- Start of processing for Build_Find_Body_Index
2901 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2903 Ent
:= First_Entity
(Typ
);
2904 while Present
(Ent
) loop
2905 if Ekind
(Ent
) = E_Entry_Family
then
2915 -- If the protected type has no entry families, there is a one-one
2916 -- correspondence between entry queue and entry body.
2919 Make_Simple_Return_Statement
(Loc
,
2920 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2923 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2926 -- if E <= l1 then return 1;
2927 -- elsif E <= l1 + l2 then return 2;
2932 Ent
:= First_Entity
(Typ
);
2934 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2936 while Present
(Ent
) loop
2937 if Ekind
(Ent
) = E_Entry
then
2938 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2940 elsif Ekind
(Ent
) = E_Entry_Family
then
2941 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2942 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2943 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2944 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2953 Make_Simple_Return_Statement
(Loc
,
2954 Expression
=> Make_Integer_Literal
(Loc
, 1));
2956 elsif Nkind
(Ret
) = N_If_Statement
then
2958 -- Ranges are in increasing order, so last one doesn't need guard
2961 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2964 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2970 Make_Subprogram_Body
(Loc
,
2971 Specification
=> Spec
,
2972 Declarations
=> Decls
,
2973 Handled_Statement_Sequence
=>
2974 Make_Handled_Sequence_Of_Statements
(Loc
,
2975 Statements
=> New_List
(Ret
)));
2976 end Build_Find_Body_Index
;
2978 --------------------------------
2979 -- Build_Find_Body_Index_Spec --
2980 --------------------------------
2982 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2983 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2984 Id
: constant Entity_Id
:=
2985 Make_Defining_Identifier
(Loc
,
2986 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2987 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2988 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2992 Make_Function_Specification
(Loc
,
2993 Defining_Unit_Name
=> Id
,
2994 Parameter_Specifications
=> New_List
(
2995 Make_Parameter_Specification
(Loc
,
2996 Defining_Identifier
=> Parm1
,
2998 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3000 Make_Parameter_Specification
(Loc
,
3001 Defining_Identifier
=> Parm2
,
3003 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
3005 Result_Definition
=> New_Occurrence_Of
(
3006 RTE
(RE_Protected_Entry_Index
), Loc
));
3007 end Build_Find_Body_Index_Spec
;
3009 -----------------------------------------------
3010 -- Build_Lock_Free_Protected_Subprogram_Body --
3011 -----------------------------------------------
3013 function Build_Lock_Free_Protected_Subprogram_Body
3016 Unprot_Spec
: Node_Id
) return Node_Id
3018 Actuals
: constant List_Id
:= New_List
;
3019 Loc
: constant Source_Ptr
:= Sloc
(N
);
3020 Spec
: constant Node_Id
:= Specification
(N
);
3021 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
3023 Prot_Spec
: Node_Id
;
3027 -- Create the protected version of the body
3030 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
3032 -- Build the actual parameters which appear in the call to the
3033 -- unprotected version of the body.
3035 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
3036 while Present
(Formal
) loop
3038 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
3043 -- Function case, generate:
3044 -- return <Unprot_Func_Call>;
3046 if Nkind
(Spec
) = N_Function_Specification
then
3048 Make_Simple_Return_Statement
(Loc
,
3050 Make_Function_Call
(Loc
,
3052 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3053 Parameter_Associations
=> Actuals
));
3055 -- Procedure case, call the unprotected version
3059 Make_Procedure_Call_Statement
(Loc
,
3061 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3062 Parameter_Associations
=> Actuals
);
3066 Make_Subprogram_Body
(Loc
,
3067 Declarations
=> Empty_List
,
3068 Specification
=> Prot_Spec
,
3069 Handled_Statement_Sequence
=>
3070 Make_Handled_Sequence_Of_Statements
(Loc
,
3071 Statements
=> New_List
(Stmt
)));
3072 end Build_Lock_Free_Protected_Subprogram_Body
;
3074 -------------------------------------------------
3075 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3076 -------------------------------------------------
3078 -- Procedures which meet the lock-free implementation requirements and
3079 -- reference a unique scalar component Comp are expanded in the following
3082 -- procedure P (...) is
3083 -- Expected_Comp : constant Comp_Type :=
3085 -- (System.Atomic_Primitives.Lock_Free_Read_N
3086 -- (_Object.Comp'Address));
3090 -- <original declarations before the object renaming declaration
3093 -- Desired_Comp : Comp_Type := Expected_Comp;
3094 -- Comp : Comp_Type renames Desired_Comp;
3096 -- <original delarations after the object renaming declaration
3100 -- <original statements>
3101 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3102 -- (_Object.Comp'Address,
3103 -- Interfaces.Unsigned_N (Expected_Comp),
3104 -- Interfaces.Unsigned_N (Desired_Comp));
3109 -- Each return and raise statement of P is transformed into an atomic
3112 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3113 -- (_Object.Comp'Address,
3114 -- Interfaces.Unsigned_N (Expected_Comp),
3115 -- Interfaces.Unsigned_N (Desired_Comp));
3117 -- <original statement>
3122 -- Functions which meet the lock-free implementation requirements and
3123 -- reference a unique scalar component Comp are expanded in the following
3126 -- function F (...) return ... is
3127 -- <original declarations before the object renaming declaration
3130 -- Expected_Comp : constant Comp_Type :=
3132 -- (System.Atomic_Primitives.Lock_Free_Read_N
3133 -- (_Object.Comp'Address));
3134 -- Comp : Comp_Type renames Expected_Comp;
3136 -- <original delarations after the object renaming declaration of
3140 -- <original statements>
3143 function Build_Lock_Free_Unprotected_Subprogram_Body
3145 Prot_Typ
: Node_Id
) return Node_Id
3147 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
3148 -- Subprograms which meet the lock-free implementation criteria are
3149 -- allowed to reference only one unique component. Return the prival
3150 -- of the said component.
3152 --------------------------
3153 -- Referenced_Component --
3154 --------------------------
3156 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
3159 Source_Comp
: Entity_Id
:= Empty
;
3162 -- Find the unique source component which N references in its
3165 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
3167 Element
: Lock_Free_Subprogram
renames
3168 Lock_Free_Subprogram_Table
.Table
(Index
);
3170 if Element
.Sub_Body
= N
then
3171 Source_Comp
:= Element
.Comp_Id
;
3177 if No
(Source_Comp
) then
3181 -- Find the prival which corresponds to the source component within
3182 -- the declarations of N.
3184 Decl
:= First
(Declarations
(N
));
3185 while Present
(Decl
) loop
3187 -- Privals appear as object renamings
3189 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
3190 Comp
:= Defining_Identifier
(Decl
);
3192 if Present
(Prival_Link
(Comp
))
3193 and then Prival_Link
(Comp
) = Source_Comp
3203 end Referenced_Component
;
3207 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
3208 Loc
: constant Source_Ptr
:= Sloc
(N
);
3209 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
3210 Decls
: List_Id
:= Declarations
(N
);
3212 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3215 -- Add renamings for the protection object, discriminals, privals and
3216 -- the entry index constant for use by debugger.
3218 Debug_Private_Data_Declarations
(Decls
);
3220 -- Perform the lock-free expansion when the subprogram references a
3221 -- protected component.
3223 if Present
(Comp
) then
3224 Protected_Component_Ref
: declare
3225 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
3226 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
3227 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
3229 Is_Procedure
: constant Boolean :=
3230 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
3231 -- Indicates if N is a protected procedure body
3233 Block_Decls
: List_Id
;
3234 Try_Write
: Entity_Id
;
3235 Desired_Comp
: Entity_Id
;
3238 Label_Id
: Entity_Id
:= Empty
;
3240 Expected_Comp
: Entity_Id
;
3243 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
3245 Unsigned
: Entity_Id
;
3247 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
3248 -- Transform a single node if it is a return statement, a raise
3249 -- statement or a reference to Comp.
3251 procedure Process_Stmts
(Stmts
: List_Id
);
3252 -- Given a statement sequence Stmts, wrap any return or raise
3253 -- statements in the following manner:
3255 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3256 -- (_Object.Comp'Address,
3257 -- Interfaces.Unsigned_N (Expected_Comp),
3258 -- Interfaces.Unsigned_N (Desired_Comp))
3269 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3271 procedure Wrap_Statement
(Stmt
: Node_Id
);
3272 -- Wrap an arbitrary statement inside an if statement where the
3273 -- condition does an atomic check on the state of the object.
3275 --------------------
3276 -- Wrap_Statement --
3277 --------------------
3279 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3281 -- The first time through, create the declaration of a label
3282 -- which is used to skip the remainder of source statements
3283 -- if the state of the object has changed.
3285 if No
(Label_Id
) then
3287 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3288 Set_Entity
(Label_Id
,
3289 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3293 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3294 -- (_Object.Comp'Address,
3295 -- Interfaces.Unsigned_N (Expected_Comp),
3296 -- Interfaces.Unsigned_N (Desired_Comp))
3304 Make_Implicit_If_Statement
(N
,
3306 Make_Function_Call
(Loc
,
3308 New_Reference_To
(Try_Write
, Loc
),
3309 Parameter_Associations
=> New_List
(
3310 Make_Attribute_Reference
(Loc
,
3311 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3312 Attribute_Name
=> Name_Address
),
3314 Unchecked_Convert_To
(Unsigned
,
3315 New_Reference_To
(Expected_Comp
, Loc
)),
3317 Unchecked_Convert_To
(Unsigned
,
3318 New_Reference_To
(Desired_Comp
, Loc
)))),
3320 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3322 Else_Statements
=> New_List
(
3323 Make_Goto_Statement
(Loc
,
3325 New_Reference_To
(Entity
(Label_Id
), Loc
)))));
3328 -- Start of processing for Process_Node
3331 -- Wrap each return and raise statement that appear inside a
3332 -- procedure. Skip the last return statement which is added by
3333 -- default since it is transformed into an exit statement.
3336 and then ((Nkind
(N
) = N_Simple_Return_Statement
3337 and then N
/= Last
(Stmts
))
3338 or else Nkind
(N
) = N_Extended_Return_Statement
3339 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3340 N_Raise_Program_Error
,
3342 N_Raise_Storage_Error
)
3343 and then Comes_From_Source
(N
)))
3351 Set_Analyzed
(N
, False);
3356 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3362 procedure Process_Stmts
(Stmts
: List_Id
) is
3365 Stmt
:= First
(Stmts
);
3366 while Present
(Stmt
) loop
3367 Process_Nodes
(Stmt
);
3372 -- Start of processing for Protected_Component_Ref
3375 -- Get the type size
3377 if Known_Static_Esize
(Comp_Type
) then
3378 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3380 -- If the Esize (Object_Size) is unknown at compile time, look at
3381 -- the RM_Size (Value_Size) since it may have been set by an
3382 -- explicit representation clause.
3384 elsif Known_Static_RM_Size
(Comp_Type
) then
3385 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3387 -- Should not happen since this has already been checked in
3388 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3391 raise Program_Error
;
3394 -- Retrieve all relevant atomic routines and types
3398 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3399 Read
:= RTE
(RE_Lock_Free_Read_8
);
3400 Unsigned
:= RTE
(RE_Uint8
);
3403 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3404 Read
:= RTE
(RE_Lock_Free_Read_16
);
3405 Unsigned
:= RTE
(RE_Uint16
);
3408 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3409 Read
:= RTE
(RE_Lock_Free_Read_32
);
3410 Unsigned
:= RTE
(RE_Uint32
);
3413 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3414 Read
:= RTE
(RE_Lock_Free_Read_64
);
3415 Unsigned
:= RTE
(RE_Uint64
);
3418 raise Program_Error
;
3422 -- Expected_Comp : constant Comp_Type :=
3424 -- (System.Atomic_Primitives.Lock_Free_Read_N
3425 -- (_Object.Comp'Address));
3428 Make_Defining_Identifier
(Loc
,
3429 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3432 Make_Object_Declaration
(Loc
,
3433 Defining_Identifier
=> Expected_Comp
,
3434 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3435 Constant_Present
=> True,
3437 Unchecked_Convert_To
(Comp_Type
,
3438 Make_Function_Call
(Loc
,
3439 Name
=> New_Reference_To
(Read
, Loc
),
3440 Parameter_Associations
=> New_List
(
3441 Make_Attribute_Reference
(Loc
,
3442 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3443 Attribute_Name
=> Name_Address
)))));
3445 -- Protected procedures
3447 if Is_Procedure
then
3448 -- Move the original declarations inside the generated block
3450 Block_Decls
:= Decls
;
3452 -- Reset the declarations list of the protected procedure to
3453 -- contain only Decl.
3455 Decls
:= New_List
(Decl
);
3458 -- Desired_Comp : Comp_Type := Expected_Comp;
3461 Make_Defining_Identifier
(Loc
,
3462 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3464 -- Insert the declarations of Expected_Comp and Desired_Comp in
3465 -- the block declarations right before the renaming of the
3466 -- protected component.
3468 Insert_Before
(Comp_Decl
,
3469 Make_Object_Declaration
(Loc
,
3470 Defining_Identifier
=> Desired_Comp
,
3471 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3473 New_Reference_To
(Expected_Comp
, Loc
)));
3475 -- Protected function
3478 Desired_Comp
:= Expected_Comp
;
3480 -- Insert the declaration of Expected_Comp in the function
3481 -- declarations right before the renaming of the protected
3484 Insert_Before
(Comp_Decl
, Decl
);
3487 -- Rewrite the protected component renaming declaration to be a
3488 -- renaming of Desired_Comp.
3491 -- Comp : Comp_Type renames Desired_Comp;
3494 Make_Object_Renaming_Declaration
(Loc
,
3495 Defining_Identifier
=>
3496 Defining_Identifier
(Comp_Decl
),
3498 New_Occurrence_Of
(Comp_Type
, Loc
),
3500 New_Reference_To
(Desired_Comp
, Loc
)));
3502 -- Wrap any return or raise statements in Stmts in same the manner
3503 -- described in Process_Stmts.
3505 Process_Stmts
(Stmts
);
3508 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3509 -- (_Object.Comp'Address,
3510 -- Interfaces.Unsigned_N (Expected_Comp),
3511 -- Interfaces.Unsigned_N (Desired_Comp))
3513 if Is_Procedure
then
3515 Make_Exit_Statement
(Loc
,
3517 Make_Function_Call
(Loc
,
3519 New_Reference_To
(Try_Write
, Loc
),
3520 Parameter_Associations
=> New_List
(
3521 Make_Attribute_Reference
(Loc
,
3522 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3523 Attribute_Name
=> Name_Address
),
3525 Unchecked_Convert_To
(Unsigned
,
3526 New_Reference_To
(Expected_Comp
, Loc
)),
3528 Unchecked_Convert_To
(Unsigned
,
3529 New_Reference_To
(Desired_Comp
, Loc
)))));
3531 -- Small optimization: transform the default return statement
3532 -- of a procedure into the atomic exit statement.
3534 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3535 Rewrite
(Last
(Stmts
), Stmt
);
3537 Append_To
(Stmts
, Stmt
);
3541 -- Create the declaration of the label used to skip the rest of
3542 -- the source statements when the object state changes.
3544 if Present
(Label_Id
) then
3545 Label
:= Make_Label
(Loc
, Label_Id
);
3547 Make_Implicit_Label_Declaration
(Loc
,
3548 Defining_Identifier
=> Entity
(Label_Id
),
3549 Label_Construct
=> Label
));
3550 Append_To
(Stmts
, Label
);
3562 if Is_Procedure
then
3565 Make_Loop_Statement
(Loc
,
3566 Statements
=> New_List
(
3567 Make_Block_Statement
(Loc
,
3568 Declarations
=> Block_Decls
,
3569 Handled_Statement_Sequence
=>
3570 Make_Handled_Sequence_Of_Statements
(Loc
,
3571 Statements
=> Stmts
))),
3572 End_Label
=> Empty
));
3576 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3577 end Protected_Component_Ref
;
3580 -- Make an unprotected version of the subprogram for use within the same
3581 -- object, with new name and extra parameter representing the object.
3584 Make_Subprogram_Body
(Loc
,
3586 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3587 Declarations
=> Decls
,
3588 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3589 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3591 -------------------------
3592 -- Build_Master_Entity --
3593 -------------------------
3595 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3596 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3598 Context_Id
: Entity_Id
;
3604 if Is_Itype
(Obj_Or_Typ
) then
3605 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3607 Par
:= Parent
(Obj_Or_Typ
);
3610 -- When creating a master for a record component which is either a task
3611 -- or access-to-task, the enclosing record is the master scope and the
3612 -- proper insertion point is the component list.
3614 if Is_Record_Type
(Current_Scope
) then
3616 Context_Id
:= Current_Scope
;
3617 Decls
:= List_Containing
(Context
);
3619 -- Default case for object declarations and access types. Note that the
3620 -- context is updated to the nearest enclosing body, block, package or
3621 -- return statement.
3624 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3627 -- Do not create a master if one already exists or there is no task
3630 if Has_Master_Entity
(Context_Id
)
3631 or else Restriction_Active
(No_Task_Hierarchy
)
3636 -- Create a master, generate:
3637 -- _Master : constant Master_Id := Current_Master.all;
3640 Make_Object_Declaration
(Loc
,
3641 Defining_Identifier
=>
3642 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3643 Constant_Present
=> True,
3644 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3646 Make_Explicit_Dereference
(Loc
,
3647 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
3649 -- The master is inserted at the start of the declarative list of the
3652 Prepend_To
(Decls
, Decl
);
3654 -- In certain cases where transient scopes are involved, the immediate
3655 -- scope is not always the proper master scope. Ensure that the master
3656 -- declaration and entity appear in the same context.
3658 if Context_Id
/= Current_Scope
then
3659 Push_Scope
(Context_Id
);
3666 -- Mark the enclosing scope and its associated construct as being task
3669 Set_Has_Master_Entity
(Context_Id
);
3671 while Present
(Context
)
3672 and then Nkind
(Context
) /= N_Compilation_Unit
3674 if Nkind_In
(Context
, N_Block_Statement
,
3678 Set_Is_Task_Master
(Context
);
3681 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3682 Context
:= Corresponding_Stub
(Parent
(Context
));
3685 Context
:= Parent
(Context
);
3687 end Build_Master_Entity
;
3689 ---------------------------
3690 -- Build_Master_Renaming --
3691 ---------------------------
3693 procedure Build_Master_Renaming
3694 (Ptr_Typ
: Entity_Id
;
3695 Ins_Nod
: Node_Id
:= Empty
)
3697 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3699 Master_Decl
: Node_Id
;
3700 Master_Id
: Entity_Id
;
3703 -- Nothing to do if there is no task hierarchy
3705 if Restriction_Active
(No_Task_Hierarchy
) then
3709 -- Determine the proper context to insert the master renaming
3711 if Present
(Ins_Nod
) then
3713 elsif Is_Itype
(Ptr_Typ
) then
3714 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3716 Context
:= Parent
(Ptr_Typ
);
3720 -- <Ptr_Typ>M : Master_Id renames _Master;
3723 Make_Defining_Identifier
(Loc
,
3724 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3727 Make_Object_Renaming_Declaration
(Loc
,
3728 Defining_Identifier
=> Master_Id
,
3729 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3730 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3732 Insert_Action
(Context
, Master_Decl
);
3734 -- The renamed master now services the access type
3736 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3737 end Build_Master_Renaming
;
3739 -----------------------------------------
3740 -- Build_Private_Protected_Declaration --
3741 -----------------------------------------
3743 function Build_Private_Protected_Declaration
3744 (N
: Node_Id
) return Entity_Id
3746 Loc
: constant Source_Ptr
:= Sloc
(N
);
3747 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3752 Spec_Id
: Entity_Id
;
3755 Formal
:= First_Formal
(Body_Id
);
3757 -- The protected operation always has at least one formal, namely the
3758 -- object itself, but it is only placed in the parameter list if
3759 -- expansion is enabled.
3761 if Present
(Formal
) or else Expander_Active
then
3762 Plist
:= Copy_Parameter_List
(Body_Id
);
3767 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3769 Make_Procedure_Specification
(Loc
,
3770 Defining_Unit_Name
=>
3771 Make_Defining_Identifier
(Sloc
(Body_Id
),
3772 Chars
=> Chars
(Body_Id
)),
3773 Parameter_Specifications
=>
3777 Make_Function_Specification
(Loc
,
3778 Defining_Unit_Name
=>
3779 Make_Defining_Identifier
(Sloc
(Body_Id
),
3780 Chars
=> Chars
(Body_Id
)),
3781 Parameter_Specifications
=> Plist
,
3782 Result_Definition
=>
3783 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3786 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3787 Insert_Before
(N
, Decl
);
3788 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3790 -- Indicate that the entity comes from source, to ensure that cross-
3791 -- reference information is properly generated. The body itself is
3792 -- rewritten during expansion, and the body entity will not appear in
3793 -- calls to the operation.
3795 Set_Comes_From_Source
(Spec_Id
, True);
3797 Set_Has_Completion
(Spec_Id
);
3798 Set_Convention
(Spec_Id
, Convention_Protected
);
3800 end Build_Private_Protected_Declaration
;
3802 ---------------------------
3803 -- Build_Protected_Entry --
3804 ---------------------------
3806 function Build_Protected_Entry
3809 Pid
: Node_Id
) return Node_Id
3811 Loc
: constant Source_Ptr
:= Sloc
(N
);
3813 Decls
: constant List_Id
:= Declarations
(N
);
3814 End_Lab
: constant Node_Id
:=
3815 End_Label
(Handled_Statement_Sequence
(N
));
3816 End_Loc
: constant Source_Ptr
:=
3817 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3818 -- Used for the generated call to Complete_Entry_Body
3820 Han_Loc
: Source_Ptr
;
3821 -- Used for the exception handler, inserted at end of the body
3823 Op_Decls
: constant List_Id
:= New_List
;
3831 -- Set the source location on the exception handler only when debugging
3832 -- the expanded code (see Make_Implicit_Exception_Handler).
3834 if Debug_Generated_Code
then
3837 -- Otherwise the inserted code should not be visible to the debugger
3840 Han_Loc
:= No_Location
;
3844 Make_Defining_Identifier
(Loc
,
3845 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3847 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
3849 -- Add the following declarations:
3851 -- type poVP is access poV;
3852 -- _object : poVP := poVP (_O);
3854 -- where _O is the formal parameter associated with the concurrent
3855 -- object. These declarations are needed for Complete_Entry_Body.
3857 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
3859 -- Add renamings for all formals, the Protection object, discriminals,
3860 -- privals and the entry index constant for use by debugger.
3862 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
3863 Debug_Private_Data_Declarations
(Decls
);
3865 -- Put the declarations and the statements from the entry
3869 Make_Block_Statement
(Loc
,
3870 Declarations
=> Decls
,
3871 Handled_Statement_Sequence
=>
3872 Handled_Statement_Sequence
(N
)));
3874 case Corresponding_Runtime_Package
(Pid
) is
3875 when System_Tasking_Protected_Objects_Entries
=>
3876 Append_To
(Op_Stats
,
3877 Make_Procedure_Call_Statement
(End_Loc
,
3879 New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
),
3880 Parameter_Associations
=> New_List
(
3881 Make_Attribute_Reference
(End_Loc
,
3883 Make_Selected_Component
(End_Loc
,
3885 Make_Identifier
(End_Loc
, Name_uObject
),
3887 Make_Identifier
(End_Loc
, Name_uObject
)),
3888 Attribute_Name
=> Name_Unchecked_Access
))));
3890 when System_Tasking_Protected_Objects_Single_Entry
=>
3892 -- Historically, a call to Complete_Single_Entry_Body was
3893 -- inserted, but it was a null procedure.
3898 raise Program_Error
;
3901 -- When exceptions can not be propagated, we never need to call
3902 -- Exception_Complete_Entry_Body
3904 if No_Exception_Handlers_Set
then
3906 Make_Subprogram_Body
(Loc
,
3907 Specification
=> Espec
,
3908 Declarations
=> Op_Decls
,
3909 Handled_Statement_Sequence
=>
3910 Make_Handled_Sequence_Of_Statements
(Loc
,
3911 Statements
=> Op_Stats
,
3912 End_Label
=> End_Lab
));
3915 Ohandle
:= Make_Others_Choice
(Loc
);
3916 Set_All_Others
(Ohandle
);
3918 case Corresponding_Runtime_Package
(Pid
) is
3919 when System_Tasking_Protected_Objects_Entries
=>
3922 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3924 when System_Tasking_Protected_Objects_Single_Entry
=>
3927 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3930 raise Program_Error
;
3933 -- Establish link between subprogram body entity and source entry
3935 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
3937 -- Create body of entry procedure. The renaming declarations are
3938 -- placed ahead of the block that contains the actual entry body.
3941 Make_Subprogram_Body
(Loc
,
3942 Specification
=> Espec
,
3943 Declarations
=> Op_Decls
,
3944 Handled_Statement_Sequence
=>
3945 Make_Handled_Sequence_Of_Statements
(Loc
,
3946 Statements
=> Op_Stats
,
3947 End_Label
=> End_Lab
,
3948 Exception_Handlers
=> New_List
(
3949 Make_Implicit_Exception_Handler
(Han_Loc
,
3950 Exception_Choices
=> New_List
(Ohandle
),
3952 Statements
=> New_List
(
3953 Make_Procedure_Call_Statement
(Han_Loc
,
3955 Parameter_Associations
=> New_List
(
3956 Make_Attribute_Reference
(Han_Loc
,
3958 Make_Selected_Component
(Han_Loc
,
3960 Make_Identifier
(Han_Loc
, Name_uObject
),
3962 Make_Identifier
(Han_Loc
, Name_uObject
)),
3963 Attribute_Name
=> Name_Unchecked_Access
),
3965 Make_Function_Call
(Han_Loc
,
3966 Name
=> New_Reference_To
(
3967 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3969 end Build_Protected_Entry
;
3971 -----------------------------------------
3972 -- Build_Protected_Entry_Specification --
3973 -----------------------------------------
3975 function Build_Protected_Entry_Specification
3978 Ent_Id
: Entity_Id
) return Node_Id
3980 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3983 Set_Debug_Info_Needed
(Def_Id
);
3985 if Present
(Ent_Id
) then
3986 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3990 Make_Procedure_Specification
(Loc
,
3991 Defining_Unit_Name
=> Def_Id
,
3992 Parameter_Specifications
=> New_List
(
3993 Make_Parameter_Specification
(Loc
,
3994 Defining_Identifier
=>
3995 Make_Defining_Identifier
(Loc
, Name_uO
),
3997 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3999 Make_Parameter_Specification
(Loc
,
4000 Defining_Identifier
=> P
,
4002 New_Reference_To
(RTE
(RE_Address
), Loc
)),
4004 Make_Parameter_Specification
(Loc
,
4005 Defining_Identifier
=>
4006 Make_Defining_Identifier
(Loc
, Name_uE
),
4008 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
4009 end Build_Protected_Entry_Specification
;
4011 --------------------------
4012 -- Build_Protected_Spec --
4013 --------------------------
4015 function Build_Protected_Spec
4017 Obj_Type
: Entity_Id
;
4019 Unprotected
: Boolean := False) return List_Id
4021 Loc
: constant Source_Ptr
:= Sloc
(N
);
4024 New_Plist
: List_Id
;
4025 New_Param
: Node_Id
;
4028 New_Plist
:= New_List
;
4030 Formal
:= First_Formal
(Ident
);
4031 while Present
(Formal
) loop
4033 Make_Parameter_Specification
(Loc
,
4034 Defining_Identifier
=>
4035 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
4036 In_Present
=> In_Present
(Parent
(Formal
)),
4037 Out_Present
=> Out_Present
(Parent
(Formal
)),
4038 Parameter_Type
=> New_Reference_To
(Etype
(Formal
), Loc
));
4041 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
4044 Append
(New_Param
, New_Plist
);
4045 Next_Formal
(Formal
);
4048 -- If the subprogram is a procedure and the context is not an access
4049 -- to protected subprogram, the parameter is in-out. Otherwise it is
4053 Make_Parameter_Specification
(Loc
,
4054 Defining_Identifier
=>
4055 Make_Defining_Identifier
(Loc
, Name_uObject
),
4058 (Etype
(Ident
) = Standard_Void_Type
4059 and then not Is_RTE
(Obj_Type
, RE_Address
)),
4061 New_Reference_To
(Obj_Type
, Loc
));
4062 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4063 Prepend_To
(New_Plist
, Decl
);
4066 end Build_Protected_Spec
;
4068 ---------------------------------------
4069 -- Build_Protected_Sub_Specification --
4070 ---------------------------------------
4072 function Build_Protected_Sub_Specification
4074 Prot_Typ
: Entity_Id
;
4075 Mode
: Subprogram_Protection_Mode
) return Node_Id
4077 Loc
: constant Source_Ptr
:= Sloc
(N
);
4081 New_Plist
: List_Id
;
4084 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
4085 (Dispatching_Mode
=> ' ',
4086 Protected_Mode
=> 'P',
4087 Unprotected_Mode
=> 'N');
4090 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
4093 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
4098 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
4101 Build_Protected_Spec
4102 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
4103 Mode
= Unprotected_Mode
);
4105 Make_Defining_Identifier
(Loc
,
4106 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
4108 -- The unprotected operation carries the user code, and debugging
4109 -- information must be generated for it, even though this spec does
4110 -- not come from source. It is also convenient to allow gdb to step
4111 -- into the protected operation, even though it only contains lock/
4114 Set_Debug_Info_Needed
(New_Id
);
4116 -- If a pragma Eliminate applies to the source entity, the internal
4117 -- subprograms will be eliminated as well.
4119 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
4121 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
4123 Make_Procedure_Specification
(Loc
,
4124 Defining_Unit_Name
=> New_Id
,
4125 Parameter_Specifications
=> New_Plist
);
4127 -- Create a new specification for the anonymous subprogram type
4131 Make_Function_Specification
(Loc
,
4132 Defining_Unit_Name
=> New_Id
,
4133 Parameter_Specifications
=> New_Plist
,
4134 Result_Definition
=>
4135 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
4137 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
4141 end Build_Protected_Sub_Specification
;
4143 -------------------------------------
4144 -- Build_Protected_Subprogram_Body --
4145 -------------------------------------
4147 function Build_Protected_Subprogram_Body
4150 N_Op_Spec
: Node_Id
) return Node_Id
4152 Loc
: constant Source_Ptr
:= Sloc
(N
);
4154 P_Op_Spec
: Node_Id
;
4157 Unprot_Call
: Node_Id
;
4159 Lock_Name
: Node_Id
;
4160 Lock_Stmt
: Node_Id
;
4162 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
4163 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
4165 Object_Parm
: Node_Id
;
4170 Op_Spec
:= Specification
(N
);
4171 Exc_Safe
:= Is_Exception_Safe
(N
);
4174 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
4176 -- Build a list of the formal parameters of the protected version of
4177 -- the subprogram to use as the actual parameters of the unprotected
4180 Uactuals
:= New_List
;
4181 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
4182 while Present
(Pformal
) loop
4183 Append_To
(Uactuals
,
4184 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
4188 -- Make a call to the unprotected version of the subprogram built above
4189 -- for use by the protected version built below.
4191 if Nkind
(Op_Spec
) = N_Function_Specification
then
4193 R
:= Make_Temporary
(Loc
, 'R');
4195 Make_Object_Declaration
(Loc
,
4196 Defining_Identifier
=> R
,
4197 Constant_Present
=> True,
4198 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
4200 Make_Function_Call
(Loc
,
4201 Name
=> Make_Identifier
(Loc
,
4202 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4203 Parameter_Associations
=> Uactuals
));
4206 Make_Simple_Return_Statement
(Loc
,
4207 Expression
=> New_Reference_To
(R
, Loc
));
4210 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
4211 Expression
=> Make_Function_Call
(Loc
,
4213 Make_Identifier
(Loc
,
4214 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4215 Parameter_Associations
=> Uactuals
));
4218 Lock_Kind
:= RE_Lock_Read_Only
;
4222 Make_Procedure_Call_Statement
(Loc
,
4224 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4225 Parameter_Associations
=> Uactuals
);
4227 Lock_Kind
:= RE_Lock
;
4230 -- Wrap call in block that will be covered by an at_end handler
4232 if not Exc_Safe
then
4233 Unprot_Call
:= Make_Block_Statement
(Loc
,
4234 Handled_Statement_Sequence
=>
4235 Make_Handled_Sequence_Of_Statements
(Loc
,
4236 Statements
=> New_List
(Unprot_Call
)));
4239 -- Make the protected subprogram body. This locks the protected
4240 -- object and calls the unprotected version of the subprogram.
4242 case Corresponding_Runtime_Package
(Pid
) is
4243 when System_Tasking_Protected_Objects_Entries
=>
4244 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
4246 when System_Tasking_Protected_Objects_Single_Entry
=>
4247 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
4249 when System_Tasking_Protected_Objects
=>
4250 Lock_Name
:= New_Reference_To
(RTE
(Lock_Kind
), Loc
);
4253 raise Program_Error
;
4257 Make_Attribute_Reference
(Loc
,
4259 Make_Selected_Component
(Loc
,
4260 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4261 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4262 Attribute_Name
=> Name_Unchecked_Access
);
4264 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
4266 Parameter_Associations
=> New_List
(Object_Parm
));
4268 if Abort_Allowed
then
4270 Make_Procedure_Call_Statement
(Loc
,
4271 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
4272 Parameter_Associations
=> Empty_List
),
4276 Stmts
:= New_List
(Lock_Stmt
);
4279 if not Exc_Safe
then
4280 Append
(Unprot_Call
, Stmts
);
4282 if Nkind
(Op_Spec
) = N_Function_Specification
then
4284 Stmts
:= Empty_List
;
4286 Append
(Unprot_Call
, Stmts
);
4289 -- Historical note: Previously, call the the cleanup was inserted
4290 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4291 -- which is also shared by the 'not Exc_Safe' path.
4293 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
4295 if Nkind
(Op_Spec
) = N_Function_Specification
then
4296 Append
(Return_Stmt
, Stmts
);
4297 Append
(Make_Block_Statement
(Loc
,
4298 Declarations
=> New_List
(Unprot_Call
),
4299 Handled_Statement_Sequence
=>
4300 Make_Handled_Sequence_Of_Statements
(Loc
,
4301 Statements
=> Stmts
)), Pre_Stmts
);
4307 Make_Subprogram_Body
(Loc
,
4308 Declarations
=> Empty_List
,
4309 Specification
=> P_Op_Spec
,
4310 Handled_Statement_Sequence
=>
4311 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4313 -- Mark this subprogram as a protected subprogram body so that the
4314 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4315 -- path as otherwise the cleanup has already been inserted.
4317 if not Exc_Safe
then
4318 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4322 end Build_Protected_Subprogram_Body
;
4324 -------------------------------------
4325 -- Build_Protected_Subprogram_Call --
4326 -------------------------------------
4328 procedure Build_Protected_Subprogram_Call
4332 External
: Boolean := True)
4334 Loc
: constant Source_Ptr
:= Sloc
(N
);
4335 Sub
: constant Entity_Id
:= Entity
(Name
);
4341 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4344 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4347 if Present
(Parameter_Associations
(N
)) then
4348 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4353 -- If the type is an untagged derived type, convert to the root type,
4354 -- which is the one on which the operations are defined.
4356 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4357 and then not Is_Tagged_Type
(Etype
(Rec
))
4358 and then Is_Derived_Type
(Etype
(Rec
))
4360 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4361 Set_Subtype_Mark
(Rec
,
4362 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4365 Prepend
(Rec
, Params
);
4367 if Ekind
(Sub
) = E_Procedure
then
4369 Make_Procedure_Call_Statement
(Loc
,
4371 Parameter_Associations
=> Params
));
4374 pragma Assert
(Ekind
(Sub
) = E_Function
);
4376 Make_Function_Call
(Loc
,
4378 Parameter_Associations
=> Params
));
4382 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4383 and then Is_Entity_Name
(Expression
(Rec
))
4384 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4386 Add_Shared_Var_Lock_Procs
(N
);
4388 end Build_Protected_Subprogram_Call
;
4390 ---------------------------------------------
4391 -- Build_Protected_Subprogram_Call_Cleanup --
4392 ---------------------------------------------
4394 procedure Build_Protected_Subprogram_Call_Cleanup
4403 -- If the associated protected object has entries, a protected
4404 -- procedure has to service entry queues. In this case generate:
4406 -- Service_Entries (_object._object'Access);
4408 if Nkind
(Op_Spec
) = N_Procedure_Specification
4409 and then Has_Entries
(Conc_Typ
)
4411 case Corresponding_Runtime_Package
(Conc_Typ
) is
4412 when System_Tasking_Protected_Objects_Entries
=>
4413 Nam
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
4415 when System_Tasking_Protected_Objects_Single_Entry
=>
4416 Nam
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
4419 raise Program_Error
;
4423 Make_Procedure_Call_Statement
(Loc
,
4425 Parameter_Associations
=> New_List
(
4426 Make_Attribute_Reference
(Loc
,
4428 Make_Selected_Component
(Loc
,
4429 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4430 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4431 Attribute_Name
=> Name_Unchecked_Access
))));
4435 -- Unlock (_object._object'Access);
4437 case Corresponding_Runtime_Package
(Conc_Typ
) is
4438 when System_Tasking_Protected_Objects_Entries
=>
4439 Nam
:= New_Reference_To
(RTE
(RE_Unlock_Entries
), Loc
);
4441 when System_Tasking_Protected_Objects_Single_Entry
=>
4442 Nam
:= New_Reference_To
(RTE
(RE_Unlock_Entry
), Loc
);
4444 when System_Tasking_Protected_Objects
=>
4445 Nam
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
4448 raise Program_Error
;
4452 Make_Procedure_Call_Statement
(Loc
,
4454 Parameter_Associations
=> New_List
(
4455 Make_Attribute_Reference
(Loc
,
4457 Make_Selected_Component
(Loc
,
4458 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4459 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4460 Attribute_Name
=> Name_Unchecked_Access
))));
4466 if Abort_Allowed
then
4468 Make_Procedure_Call_Statement
(Loc
,
4470 New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
4471 Parameter_Associations
=> Empty_List
));
4473 end Build_Protected_Subprogram_Call_Cleanup
;
4475 -------------------------
4476 -- Build_Selected_Name --
4477 -------------------------
4479 function Build_Selected_Name
4480 (Prefix
: Entity_Id
;
4481 Selector
: Entity_Id
;
4482 Append_Char
: Character := ' ') return Name_Id
4484 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4485 Select_Len
: Natural;
4488 Get_Name_String
(Chars
(Selector
));
4489 Select_Len
:= Name_Len
;
4490 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4491 Get_Name_String
(Chars
(Prefix
));
4493 -- If scope is anonymous type, discard suffix to recover name of
4494 -- single protected object. Otherwise use protected type name.
4496 if Name_Buffer
(Name_Len
) = 'T' then
4497 Name_Len
:= Name_Len
- 1;
4500 Add_Str_To_Name_Buffer
("__");
4501 for J
in 1 .. Select_Len
loop
4502 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4505 -- Now add the Append_Char if specified. The encoding to follow
4506 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4507 -- then the entity is associated to a protected type subprogram.
4508 -- Otherwise, it is a protected type entry. For each case, the
4509 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4511 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4513 if Append_Char
/= ' ' then
4514 if Append_Char
= 'P' or Append_Char
= 'N' then
4515 Add_Char_To_Name_Buffer
(Append_Char
);
4518 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4519 return New_External_Name
(Name_Find
, ' ', -1);
4524 end Build_Selected_Name
;
4526 -----------------------------
4527 -- Build_Simple_Entry_Call --
4528 -----------------------------
4530 -- A task entry call is converted to a call to Call_Simple
4533 -- P : parms := (parm, parm, parm);
4535 -- Call_Simple (acceptor-task, entry-index, P'Address);
4541 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4542 -- the parameters, and the constructed aggregate value contains either the
4543 -- parameters or, in the case of non-elementary types, references to these
4544 -- parameters. Then the address of this aggregate is passed to the runtime
4545 -- routine, along with the task id value and the task entry index value.
4546 -- Pnn is only required if parameters are present.
4548 -- The assignments after the call are present only in the case of in-out
4549 -- or out parameters for elementary types, and are used to assign back the
4550 -- resulting values of such parameters.
4552 -- Note: the reason that we insert a block here is that in the context
4553 -- of selects, conditional entry calls etc. the entry call statement
4554 -- appears on its own, not as an element of a list.
4556 -- A protected entry call is converted to a Protected_Entry_Call:
4559 -- P : E1_Params := (param, param, param);
4561 -- Bnn : Communications_Block;
4564 -- P : E1_Params := (param, param, param);
4565 -- Bnn : Communications_Block;
4568 -- Protected_Entry_Call (
4569 -- Object => po._object'Access,
4570 -- E => <entry index>;
4571 -- Uninterpreted_Data => P'Address;
4572 -- Mode => Simple_Call;
4579 procedure Build_Simple_Entry_Call
4588 -- If call has been inlined, nothing left to do
4590 if Nkind
(N
) = N_Block_Statement
then
4594 -- Convert entry call to Call_Simple call
4597 Loc
: constant Source_Ptr
:= Sloc
(N
);
4598 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4599 Stats
: constant List_Id
:= New_List
;
4602 Comm_Name
: Entity_Id
;
4606 Ent_Acc
: Entity_Id
;
4608 Iface_Tag
: Entity_Id
;
4609 Iface_Typ
: Entity_Id
;
4622 -- Simple entry and entry family cases merge here
4624 Ent
:= Entity
(Ename
);
4625 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4626 Conctyp
:= Etype
(Concval
);
4628 -- If prefix is an access type, dereference to obtain the task type
4630 if Is_Access_Type
(Conctyp
) then
4631 Conctyp
:= Designated_Type
(Conctyp
);
4634 -- Special case for protected subprogram calls
4636 if Is_Protected_Type
(Conctyp
)
4637 and then Is_Subprogram
(Entity
(Ename
))
4639 if not Is_Eliminated
(Entity
(Ename
)) then
4640 Build_Protected_Subprogram_Call
4641 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4648 -- First parameter is the Task_Id value from the task value or the
4649 -- Object from the protected object value, obtained by selecting
4650 -- the _Task_Id or _Object from the result of doing an unchecked
4651 -- conversion to convert the value to the corresponding record type.
4653 if Nkind
(Concval
) = N_Function_Call
4654 and then Is_Task_Type
(Conctyp
)
4655 and then Ada_Version
>= Ada_2005
4658 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4659 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4664 Make_Object_Declaration
(Loc
,
4665 Defining_Identifier
=> Obj
,
4666 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4667 Expression
=> ExpR
);
4668 Set_Etype
(Obj
, Conctyp
);
4669 Decls
:= New_List
(Decl
);
4670 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4677 Parm1
:= Concurrent_Ref
(Concval
);
4679 -- Second parameter is the entry index, computed by the routine
4680 -- provided for this purpose. The value of this expression is
4681 -- assigned to an intermediate variable to assure that any entry
4682 -- family index expressions are evaluated before the entry
4686 or else Restriction_Active
(No_Entry_Queue
) = False
4687 or else not Is_Protected_Type
(Conctyp
)
4688 or else Number_Entries
(Conctyp
) > 1
4689 or else (Has_Attach_Handler
(Conctyp
)
4690 and then not Restricted_Profile
)
4692 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4695 Make_Object_Declaration
(Loc
,
4696 Defining_Identifier
=> X
,
4697 Object_Definition
=>
4698 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
4699 Expression
=> Actual_Index_Expression
(
4700 Loc
, Entity
(Ename
), Index
, Concval
));
4702 Append_To
(Decls
, Xdecl
);
4703 Parm2
:= New_Reference_To
(X
, Loc
);
4710 -- The third parameter is the packaged parameters. If there are
4711 -- none, then it is just the null address, since nothing is passed.
4714 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
4717 -- Case of parameters present, where third argument is the address
4718 -- of a packaged record containing the required parameter values.
4721 -- First build a list of parameter values, which are references to
4722 -- objects of the parameter types.
4726 Actual
:= First_Actual
(N
);
4727 Formal
:= First_Formal
(Ent
);
4729 while Present
(Actual
) loop
4731 -- If it is a by_copy_type, copy it to a new variable. The
4732 -- packaged record has a field that points to this variable.
4734 if Is_By_Copy_Type
(Etype
(Actual
)) then
4736 Make_Object_Declaration
(Loc
,
4737 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4738 Aliased_Present
=> True,
4739 Object_Definition
=>
4740 New_Reference_To
(Etype
(Formal
), Loc
));
4742 -- Mark the object as not needing initialization since the
4743 -- initialization is performed separately, avoiding errors
4744 -- on cases such as formals of null-excluding access types.
4746 Set_No_Initialization
(N_Node
);
4748 -- We must make an assignment statement separate for the
4749 -- case of limited type. We cannot assign it unless the
4750 -- Assignment_OK flag is set first. An out formal of an
4751 -- access type must also be initialized from the actual,
4752 -- as stated in RM 6.4.1 (13).
4754 if Ekind
(Formal
) /= E_Out_Parameter
4755 or else Is_Access_Type
(Etype
(Formal
))
4758 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
4759 Set_Assignment_OK
(N_Var
);
4761 Make_Assignment_Statement
(Loc
,
4763 Expression
=> Relocate_Node
(Actual
)));
4766 Append
(N_Node
, Decls
);
4769 Make_Attribute_Reference
(Loc
,
4770 Attribute_Name
=> Name_Unchecked_Access
,
4772 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4774 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4776 elsif Is_VM_By_Copy_Actual
(Actual
) then
4778 Make_Object_Declaration
(Loc
,
4779 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4780 Aliased_Present
=> True,
4781 Object_Definition
=>
4782 New_Reference_To
(Etype
(Formal
), Loc
),
4783 Expression
=> New_Copy_Tree
(Actual
));
4784 Set_Assignment_OK
(N_Node
);
4786 Append
(N_Node
, Decls
);
4789 Make_Attribute_Reference
(Loc
,
4790 Attribute_Name
=> Name_Unchecked_Access
,
4792 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4795 -- Interface class-wide formal
4797 if Ada_Version
>= Ada_2005
4798 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4799 and then Is_Interface
(Etype
(Formal
))
4801 Iface_Typ
:= Etype
(Etype
(Formal
));
4804 -- formal_iface_type! (actual.iface_tag)'reference
4807 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4808 pragma Assert
(Present
(Iface_Tag
));
4811 Make_Reference
(Loc
,
4812 Unchecked_Convert_To
(Iface_Typ
,
4813 Make_Selected_Component
(Loc
,
4815 Relocate_Node
(Actual
),
4817 New_Reference_To
(Iface_Tag
, Loc
)))));
4823 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4827 Next_Actual
(Actual
);
4828 Next_Formal_With_Extras
(Formal
);
4831 -- Now build the declaration of parameters initialized with the
4832 -- aggregate containing this constructed parameter list.
4834 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4837 Make_Object_Declaration
(Loc
,
4838 Defining_Identifier
=> P
,
4839 Object_Definition
=>
4840 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
4842 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4845 Make_Attribute_Reference
(Loc
,
4846 Prefix
=> New_Reference_To
(P
, Loc
),
4847 Attribute_Name
=> Name_Address
);
4849 Append
(Pdecl
, Decls
);
4852 -- Now we can create the call, case of protected type
4854 if Is_Protected_Type
(Conctyp
) then
4855 case Corresponding_Runtime_Package
(Conctyp
) is
4856 when System_Tasking_Protected_Objects_Entries
=>
4858 -- Change the type of the index declaration
4860 Set_Object_Definition
(Xdecl
,
4861 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
4863 -- Some additional declarations for protected entry calls
4869 -- Bnn : Communications_Block;
4871 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4874 Make_Object_Declaration
(Loc
,
4875 Defining_Identifier
=> Comm_Name
,
4876 Object_Definition
=>
4877 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
4879 -- Some additional statements for protected entry calls
4881 -- Protected_Entry_Call (
4882 -- Object => po._object'Access,
4883 -- E => <entry index>;
4884 -- Uninterpreted_Data => P'Address;
4885 -- Mode => Simple_Call;
4889 Make_Procedure_Call_Statement
(Loc
,
4891 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
4893 Parameter_Associations
=> New_List
(
4894 Make_Attribute_Reference
(Loc
,
4895 Attribute_Name
=> Name_Unchecked_Access
,
4899 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
4900 New_Occurrence_Of
(Comm_Name
, Loc
)));
4902 when System_Tasking_Protected_Objects_Single_Entry
=>
4903 -- Protected_Single_Entry_Call (
4904 -- Object => po._object'Access,
4905 -- Uninterpreted_Data => P'Address;
4906 -- Mode => Simple_Call);
4909 Make_Procedure_Call_Statement
(Loc
,
4910 Name
=> New_Reference_To
(
4911 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4913 Parameter_Associations
=> New_List
(
4914 Make_Attribute_Reference
(Loc
,
4915 Attribute_Name
=> Name_Unchecked_Access
,
4918 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
4921 raise Program_Error
;
4924 -- Case of task type
4928 Make_Procedure_Call_Statement
(Loc
,
4929 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
4930 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4934 Append_To
(Stats
, Call
);
4936 -- If there are out or in/out parameters by copy add assignment
4937 -- statements for the result values.
4939 if Present
(Parms
) then
4940 Actual
:= First_Actual
(N
);
4941 Formal
:= First_Formal
(Ent
);
4943 Set_Assignment_OK
(Actual
);
4944 while Present
(Actual
) loop
4945 if (Is_By_Copy_Type
(Etype
(Actual
))
4946 or else Is_VM_By_Copy_Actual
(Actual
))
4947 and then Ekind
(Formal
) /= E_In_Parameter
4950 Make_Assignment_Statement
(Loc
,
4951 Name
=> New_Copy
(Actual
),
4953 Make_Explicit_Dereference
(Loc
,
4954 Make_Selected_Component
(Loc
,
4955 Prefix
=> New_Reference_To
(P
, Loc
),
4957 Make_Identifier
(Loc
, Chars
(Formal
)))));
4959 -- In all cases (including limited private types) we want
4960 -- the assignment to be valid.
4962 Set_Assignment_OK
(Name
(N_Node
));
4964 -- If the call is the triggering alternative in an
4965 -- asynchronous select, or the entry_call alternative of a
4966 -- conditional entry call, the assignments for in-out
4967 -- parameters are incorporated into the statement list that
4968 -- follows, so that there are executed only if the entry
4971 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4972 and then N
= Triggering_Statement
(Parent
(N
)))
4974 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4975 and then N
= Entry_Call_Statement
(Parent
(N
)))
4977 if No
(Statements
(Parent
(N
))) then
4978 Set_Statements
(Parent
(N
), New_List
);
4981 Prepend
(N_Node
, Statements
(Parent
(N
)));
4984 Insert_After
(Call
, N_Node
);
4988 Next_Actual
(Actual
);
4989 Next_Formal_With_Extras
(Formal
);
4993 -- Finally, create block and analyze it
4996 Make_Block_Statement
(Loc
,
4997 Declarations
=> Decls
,
4998 Handled_Statement_Sequence
=>
4999 Make_Handled_Sequence_Of_Statements
(Loc
,
5000 Statements
=> Stats
)));
5004 end Build_Simple_Entry_Call
;
5006 --------------------------------
5007 -- Build_Task_Activation_Call --
5008 --------------------------------
5010 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
5011 Loc
: constant Source_Ptr
:= Sloc
(N
);
5018 -- For sequential elaboration policy, all the tasks will be activated at
5019 -- the end of the elaboration.
5021 if Partition_Elaboration_Policy
= 'S' then
5025 -- Get the activation chain entity. Except in the case of a package
5026 -- body, this is in the node that was passed. For a package body, we
5027 -- have to find the corresponding package declaration node.
5029 if Nkind
(N
) = N_Package_Body
then
5030 P
:= Corresponding_Spec
(N
);
5033 exit when Nkind
(P
) = N_Package_Declaration
;
5036 Chain
:= Activation_Chain_Entity
(P
);
5039 Chain
:= Activation_Chain_Entity
(N
);
5042 if Present
(Chain
) then
5043 if Restricted_Profile
then
5044 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
5046 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
5050 Make_Procedure_Call_Statement
(Loc
,
5052 Parameter_Associations
=>
5053 New_List
(Make_Attribute_Reference
(Loc
,
5054 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5055 Attribute_Name
=> Name_Unchecked_Access
)));
5057 if Nkind
(N
) = N_Package_Declaration
then
5058 if Present
(Corresponding_Body
(N
)) then
5061 elsif Present
(Private_Declarations
(Specification
(N
))) then
5062 Append
(Call
, Private_Declarations
(Specification
(N
)));
5065 Append
(Call
, Visible_Declarations
(Specification
(N
)));
5069 if Present
(Handled_Statement_Sequence
(N
)) then
5071 -- The call goes at the start of the statement sequence
5072 -- after the start of exception range label if one is present.
5078 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
5080 -- A special case, skip exception range label if one is
5081 -- present (from front end zcx processing).
5083 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
5087 -- Another special case, if the first statement is a block
5088 -- from optimization of a local raise to a goto, then the
5089 -- call goes inside this block.
5091 if Nkind
(Stm
) = N_Block_Statement
5092 and then Exception_Junk
(Stm
)
5095 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
5098 -- Insertion point is after any exception label pushes,
5099 -- since we want it covered by any local handlers.
5101 while Nkind
(Stm
) in N_Push_xxx_Label
loop
5105 -- Now we have the proper insertion point
5107 Insert_Before
(Stm
, Call
);
5111 Set_Handled_Statement_Sequence
(N
,
5112 Make_Handled_Sequence_Of_Statements
(Loc
,
5113 Statements
=> New_List
(Call
)));
5118 Check_Task_Activation
(N
);
5120 end Build_Task_Activation_Call
;
5122 -------------------------------
5123 -- Build_Task_Allocate_Block --
5124 -------------------------------
5126 procedure Build_Task_Allocate_Block
5131 T
: constant Entity_Id
:= Entity
(Expression
(N
));
5132 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
5133 Loc
: constant Source_Ptr
:= Sloc
(N
);
5134 Chain
: constant Entity_Id
:=
5135 Make_Defining_Identifier
(Loc
, Name_uChain
);
5136 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5141 Make_Block_Statement
(Loc
,
5142 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5143 Declarations
=> New_List
(
5145 -- _Chain : Activation_Chain;
5147 Make_Object_Declaration
(Loc
,
5148 Defining_Identifier
=> Chain
,
5149 Aliased_Present
=> True,
5150 Object_Definition
=>
5151 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
5153 Handled_Statement_Sequence
=>
5154 Make_Handled_Sequence_Of_Statements
(Loc
,
5156 Statements
=> New_List
(
5160 Make_Procedure_Call_Statement
(Loc
,
5161 Name
=> New_Reference_To
(Init
, Loc
),
5162 Parameter_Associations
=> Args
),
5164 -- Activate_Tasks (_Chain);
5166 Make_Procedure_Call_Statement
(Loc
,
5167 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
5168 Parameter_Associations
=> New_List
(
5169 Make_Attribute_Reference
(Loc
,
5170 Prefix
=> New_Reference_To
(Chain
, Loc
),
5171 Attribute_Name
=> Name_Unchecked_Access
))))),
5173 Has_Created_Identifier
=> True,
5174 Is_Task_Allocation_Block
=> True);
5177 Make_Implicit_Label_Declaration
(Loc
,
5178 Defining_Identifier
=> Blkent
,
5179 Label_Construct
=> Block
));
5181 Append_To
(Actions
, Block
);
5183 Set_Activation_Chain_Entity
(Block
, Chain
);
5184 end Build_Task_Allocate_Block
;
5186 -----------------------------------------------
5187 -- Build_Task_Allocate_Block_With_Init_Stmts --
5188 -----------------------------------------------
5190 procedure Build_Task_Allocate_Block_With_Init_Stmts
5193 Init_Stmts
: List_Id
)
5195 Loc
: constant Source_Ptr
:= Sloc
(N
);
5196 Chain
: constant Entity_Id
:=
5197 Make_Defining_Identifier
(Loc
, Name_uChain
);
5198 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5202 Append_To
(Init_Stmts
,
5203 Make_Procedure_Call_Statement
(Loc
,
5204 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
5205 Parameter_Associations
=> New_List
(
5206 Make_Attribute_Reference
(Loc
,
5207 Prefix
=> New_Reference_To
(Chain
, Loc
),
5208 Attribute_Name
=> Name_Unchecked_Access
))));
5211 Make_Block_Statement
(Loc
,
5212 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5213 Declarations
=> New_List
(
5215 -- _Chain : Activation_Chain;
5217 Make_Object_Declaration
(Loc
,
5218 Defining_Identifier
=> Chain
,
5219 Aliased_Present
=> True,
5220 Object_Definition
=>
5221 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
5223 Handled_Statement_Sequence
=>
5224 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5226 Has_Created_Identifier
=> True,
5227 Is_Task_Allocation_Block
=> True);
5230 Make_Implicit_Label_Declaration
(Loc
,
5231 Defining_Identifier
=> Blkent
,
5232 Label_Construct
=> Block
));
5234 Append_To
(Actions
, Block
);
5236 Set_Activation_Chain_Entity
(Block
, Chain
);
5237 end Build_Task_Allocate_Block_With_Init_Stmts
;
5239 -----------------------------------
5240 -- Build_Task_Proc_Specification --
5241 -----------------------------------
5243 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5244 Loc
: constant Source_Ptr
:= Sloc
(T
);
5245 Spec_Id
: Entity_Id
;
5248 -- Case of explicit task type, suffix TB
5250 if Comes_From_Source
(T
) then
5252 Make_Defining_Identifier
(Loc
,
5253 Chars
=> New_External_Name
(Chars
(T
), "TB"));
5255 -- Case of anonymous task type, suffix B
5259 Make_Defining_Identifier
(Loc
,
5260 Chars
=> New_External_Name
(Chars
(T
), 'B'));
5263 Set_Is_Internal
(Spec_Id
);
5265 -- Associate the procedure with the task, if this is the declaration
5266 -- (and not the body) of the procedure.
5268 if No
(Task_Body_Procedure
(T
)) then
5269 Set_Task_Body_Procedure
(T
, Spec_Id
);
5273 Make_Procedure_Specification
(Loc
,
5274 Defining_Unit_Name
=> Spec_Id
,
5275 Parameter_Specifications
=> New_List
(
5276 Make_Parameter_Specification
(Loc
,
5277 Defining_Identifier
=>
5278 Make_Defining_Identifier
(Loc
, Name_uTask
),
5280 Make_Access_Definition
(Loc
,
5282 New_Reference_To
(Corresponding_Record_Type
(T
), Loc
)))));
5283 end Build_Task_Proc_Specification
;
5285 ---------------------------------------
5286 -- Build_Unprotected_Subprogram_Body --
5287 ---------------------------------------
5289 function Build_Unprotected_Subprogram_Body
5291 Pid
: Node_Id
) return Node_Id
5293 Decls
: constant List_Id
:= Declarations
(N
);
5296 -- Add renamings for the Protection object, discriminals, privals and
5297 -- the entry index constant for use by debugger.
5299 Debug_Private_Data_Declarations
(Decls
);
5301 -- Make an unprotected version of the subprogram for use within the same
5302 -- object, with a new name and an additional parameter representing the
5306 Make_Subprogram_Body
(Sloc
(N
),
5308 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5309 Declarations
=> Decls
,
5310 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5311 end Build_Unprotected_Subprogram_Body
;
5313 ----------------------------
5314 -- Collect_Entry_Families --
5315 ----------------------------
5317 procedure Collect_Entry_Families
5320 Current_Node
: in out Node_Id
;
5321 Conctyp
: Entity_Id
)
5324 Efam_Decl
: Node_Id
;
5325 Efam_Type
: Entity_Id
;
5328 Efam
:= First_Entity
(Conctyp
);
5329 while Present
(Efam
) loop
5330 if Ekind
(Efam
) = E_Entry_Family
then
5331 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5336 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5338 Bas_Decl
: Node_Id
:= Empty
;
5343 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5345 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5346 Bas
:= Make_Temporary
(Loc
, 'B');
5349 Make_Subtype_Declaration
(Loc
,
5350 Defining_Identifier
=> Bas
,
5351 Subtype_Indication
=>
5352 Make_Subtype_Indication
(Loc
,
5354 New_Occurrence_Of
(Standard_Integer
, Loc
),
5356 Make_Range_Constraint
(Loc
,
5357 Range_Expression
=> Make_Range
(Loc
,
5358 Make_Integer_Literal
5359 (Loc
, -Entry_Family_Bound
),
5360 Make_Integer_Literal
5361 (Loc
, Entry_Family_Bound
- 1)))));
5363 Insert_After
(Current_Node
, Bas_Decl
);
5364 Current_Node
:= Bas_Decl
;
5369 Make_Full_Type_Declaration
(Loc
,
5370 Defining_Identifier
=> Efam_Type
,
5372 Make_Unconstrained_Array_Definition
(Loc
,
5374 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5376 Component_Definition
=>
5377 Make_Component_Definition
(Loc
,
5378 Aliased_Present
=> False,
5379 Subtype_Indication
=>
5380 New_Reference_To
(Standard_Character
, Loc
))));
5383 Insert_After
(Current_Node
, Efam_Decl
);
5384 Current_Node
:= Efam_Decl
;
5385 Analyze
(Efam_Decl
);
5388 Make_Component_Declaration
(Loc
,
5389 Defining_Identifier
=>
5390 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5392 Component_Definition
=>
5393 Make_Component_Definition
(Loc
,
5394 Aliased_Present
=> False,
5395 Subtype_Indication
=>
5396 Make_Subtype_Indication
(Loc
,
5398 New_Occurrence_Of
(Efam_Type
, Loc
),
5401 Make_Index_Or_Discriminant_Constraint
(Loc
,
5402 Constraints
=> New_List
(
5404 (Etype
(Discrete_Subtype_Definition
5405 (Parent
(Efam
))), Loc
)))))));
5411 end Collect_Entry_Families
;
5413 -----------------------
5414 -- Concurrent_Object --
5415 -----------------------
5417 function Concurrent_Object
5418 (Spec_Id
: Entity_Id
;
5419 Conc_Typ
: Entity_Id
) return Entity_Id
5422 -- Parameter _O or _object
5424 if Is_Protected_Type
(Conc_Typ
) then
5425 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5430 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5431 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5433 end Concurrent_Object
;
5435 ----------------------
5436 -- Copy_Result_Type --
5437 ----------------------
5439 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5440 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5445 -- If the result type is an access_to_subprogram, we must create new
5446 -- entities for its spec.
5448 if Nkind
(New_Res
) = N_Access_Definition
5449 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5451 -- Provide new entities for the formals
5453 Par_Spec
:= First
(Parameter_Specifications
5454 (Access_To_Subprogram_Definition
(New_Res
)));
5455 while Present
(Par_Spec
) loop
5456 Formal
:= Defining_Identifier
(Par_Spec
);
5457 Set_Defining_Identifier
(Par_Spec
,
5458 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5464 end Copy_Result_Type
;
5466 --------------------
5467 -- Concurrent_Ref --
5468 --------------------
5470 -- The expression returned for a reference to a concurrent object has the
5473 -- taskV!(name)._Task_Id
5477 -- objectV!(name)._Object
5479 -- for a protected object. For the case of an access to a concurrent
5480 -- object, there is an extra explicit dereference:
5482 -- taskV!(name.all)._Task_Id
5483 -- objectV!(name.all)._Object
5485 -- here taskV and objectV are the types for the associated records, which
5486 -- contain the required _Task_Id and _Object fields for tasks and protected
5487 -- objects, respectively.
5489 -- For the case of a task type name, the expression is
5493 -- i.e. a call to the Self function which returns precisely this Task_Id
5495 -- For the case of a protected type name, the expression is
5499 -- which is a renaming of the _object field of the current object
5500 -- record, passed into protected operations as a parameter.
5502 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5503 Loc
: constant Source_Ptr
:= Sloc
(N
);
5504 Ntyp
: constant Entity_Id
:= Etype
(N
);
5508 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5509 -- Check whether the reference is to the immediately enclosing task
5510 -- type, or to an outer one (rare but legal).
5512 ---------------------
5513 -- Is_Current_Task --
5514 ---------------------
5516 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5520 Scop
:= Current_Scope
;
5521 while Present
(Scop
)
5522 and then Scop
/= Standard_Standard
5528 elsif Is_Task_Type
(Scop
) then
5531 -- If this is a procedure nested within the task type, we must
5532 -- assume that it can be called from an inner task, and therefore
5533 -- cannot treat it as a local reference.
5535 elsif Is_Overloadable
(Scop
)
5536 and then In_Open_Scopes
(T
)
5541 Scop
:= Scope
(Scop
);
5545 -- We know that we are within the task body, so should have found it
5548 raise Program_Error
;
5549 end Is_Current_Task
;
5551 -- Start of processing for Concurrent_Ref
5554 if Is_Access_Type
(Ntyp
) then
5555 Dtyp
:= Designated_Type
(Ntyp
);
5557 if Is_Protected_Type
(Dtyp
) then
5558 Sel
:= Name_uObject
;
5560 Sel
:= Name_uTask_Id
;
5564 Make_Selected_Component
(Loc
,
5566 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5567 Make_Explicit_Dereference
(Loc
, N
)),
5568 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5570 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5571 if Is_Task_Type
(Entity
(N
)) then
5573 if Is_Current_Task
(Entity
(N
)) then
5575 Make_Function_Call
(Loc
,
5576 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
5581 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5582 T_Body
: constant Node_Id
:=
5583 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5587 Make_Object_Declaration
(Loc
,
5588 Defining_Identifier
=> T_Self
,
5589 Object_Definition
=>
5590 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5592 Make_Function_Call
(Loc
,
5593 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
5594 Prepend
(Decl
, Declarations
(T_Body
));
5596 Set_Scope
(T_Self
, Entity
(N
));
5597 return New_Occurrence_Of
(T_Self
, Loc
);
5602 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5605 New_Reference_To
(Find_Protection_Object
(Current_Scope
), Loc
);
5609 if Is_Protected_Type
(Ntyp
) then
5610 Sel
:= Name_uObject
;
5612 elsif Is_Task_Type
(Ntyp
) then
5613 Sel
:= Name_uTask_Id
;
5616 raise Program_Error
;
5620 Make_Selected_Component
(Loc
,
5622 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5624 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5628 ------------------------
5629 -- Convert_Concurrent --
5630 ------------------------
5632 function Convert_Concurrent
5634 Typ
: Entity_Id
) return Node_Id
5637 if not Is_Concurrent_Type
(Typ
) then
5641 Unchecked_Convert_To
5642 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5644 end Convert_Concurrent
;
5646 -------------------------------------
5647 -- Debug_Private_Data_Declarations --
5648 -------------------------------------
5650 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5651 Debug_Nod
: Node_Id
;
5655 Decl
:= First
(Decls
);
5656 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5657 -- Declaration for concurrent entity _object and its access type,
5658 -- along with the entry index subtype:
5659 -- type prot_typVP is access prot_typV;
5660 -- _object : prot_typVP := prot_typV (_O);
5661 -- subtype Jnn is <Type of Index> range Low .. High;
5663 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5664 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5666 -- Declaration for the Protection object, discriminals, privals and
5667 -- entry index constant:
5668 -- conc_typR : protection_typ renames _object._object;
5669 -- discr_nameD : discr_typ renames _object.discr_name;
5670 -- discr_nameD : discr_typ renames _task.discr_name;
5671 -- prival_name : comp_typ renames _object.comp_name;
5672 -- J : constant Jnn :=
5673 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5675 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5676 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5677 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5679 if Present
(Debug_Nod
) then
5680 Insert_After
(Decl
, Debug_Nod
);
5686 end Debug_Private_Data_Declarations
;
5688 ------------------------------
5689 -- Ensure_Statement_Present --
5690 ------------------------------
5692 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5696 if Opt
.Suppress_Control_Flow_Optimizations
5697 and then Is_Empty_List
(Statements
(Alt
))
5699 Stmt
:= Make_Null_Statement
(Loc
);
5701 -- Mark NULL statement as coming from source so that it is not
5702 -- eliminated by GIGI.
5704 -- Another covert channel. If this is a requirement, it must be
5705 -- documented in sinfo/einfo ???
5707 Set_Comes_From_Source
(Stmt
, True);
5709 Set_Statements
(Alt
, New_List
(Stmt
));
5711 end Ensure_Statement_Present
;
5713 ----------------------------
5714 -- Entry_Index_Expression --
5715 ----------------------------
5717 function Entry_Index_Expression
5721 Ttyp
: Entity_Id
) return Node_Id
5731 -- The queues of entries and entry families appear in textual order in
5732 -- the associated record. The entry index is computed as the sum of the
5733 -- number of queues for all entries that precede the designated one, to
5734 -- which is added the index expression, if this expression denotes a
5735 -- member of a family.
5737 -- The following is a place holder for the count of simple entries
5739 Num
:= Make_Integer_Literal
(Sloc
, 1);
5741 -- We construct an expression which is a series of addition operations.
5742 -- The first operand is the number of single entries that precede this
5743 -- one, the second operand is the index value relative to the start of
5744 -- the referenced family, and the remaining operands are the lengths of
5745 -- the entry families that precede this entry, i.e. the constructed
5748 -- number_simple_entries +
5749 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5750 -- family'length + ...
5752 -- where index-value is the given index value, and s is the index
5753 -- subtype (we have to use pos because the subtype might be an
5754 -- enumeration type preventing direct subtraction). Note that the task
5755 -- entry array is one-indexed.
5757 -- The upper bound of the entry family may be a discriminant, so we
5758 -- retrieve the lower bound explicitly to compute offset, rather than
5759 -- using the index subtype which may mention a discriminant.
5761 if Present
(Index
) then
5762 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5771 Make_Attribute_Reference
(Sloc
,
5772 Attribute_Name
=> Name_Pos
,
5773 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
5774 Expressions
=> New_List
(Relocate_Node
(Index
))),
5782 -- Now add lengths of preceding entries and entry families
5784 Prev
:= First_Entity
(Ttyp
);
5786 while Chars
(Prev
) /= Chars
(Ent
)
5787 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5788 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5790 if Ekind
(Prev
) = E_Entry
then
5791 Set_Intval
(Num
, Intval
(Num
) + 1);
5793 elsif Ekind
(Prev
) = E_Entry_Family
then
5795 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5796 Lo
:= Type_Low_Bound
(S
);
5797 Hi
:= Type_High_Bound
(S
);
5802 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5804 -- Other components are anonymous types to be ignored
5814 end Entry_Index_Expression
;
5816 ---------------------------
5817 -- Establish_Task_Master --
5818 ---------------------------
5820 procedure Establish_Task_Master
(N
: Node_Id
) is
5824 if Restriction_Active
(No_Task_Hierarchy
) = False then
5825 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5827 -- The block may have no declarations, and nevertheless be a task
5828 -- master, if it contains a call that may return an object that
5831 if No
(Declarations
(N
)) then
5832 Set_Declarations
(N
, New_List
(Call
));
5834 Prepend_To
(Declarations
(N
), Call
);
5839 end Establish_Task_Master
;
5841 --------------------------------
5842 -- Expand_Accept_Declarations --
5843 --------------------------------
5845 -- Part of the expansion of an accept statement involves the creation of
5846 -- a declaration that can be referenced from the statement sequence of
5851 -- This declaration is inserted immediately before the accept statement
5852 -- and it is important that it be inserted before the statements of the
5853 -- statement sequence are analyzed. Thus it would be too late to create
5854 -- this declaration in the Expand_N_Accept_Statement routine, which is
5855 -- why there is a separate procedure to be called directly from Sem_Ch9.
5857 -- Ann is used to hold the address of the record containing the parameters
5858 -- (see Expand_N_Entry_Call for more details on how this record is built).
5859 -- References to the parameters do an unchecked conversion of this address
5860 -- to a pointer to the required record type, and then access the field that
5861 -- holds the value of the required parameter. The entity for the address
5862 -- variable is held as the top stack element (i.e. the last element) of the
5863 -- Accept_Address stack in the corresponding entry entity, and this element
5864 -- must be set in place before the statements are processed.
5866 -- The above description applies to the case of a stand alone accept
5867 -- statement, i.e. one not appearing as part of a select alternative.
5869 -- For the case of an accept that appears as part of a select alternative
5870 -- of a selective accept, we must still create the declaration right away,
5871 -- since Ann is needed immediately, but there is an important difference:
5873 -- The declaration is inserted before the selective accept, not before
5874 -- the accept statement (which is not part of a list anyway, and so would
5875 -- not accommodate inserted declarations)
5877 -- We only need one address variable for the entire selective accept. So
5878 -- the Ann declaration is created only for the first accept alternative,
5879 -- and subsequent accept alternatives reference the same Ann variable.
5881 -- We can distinguish the two cases by seeing whether the accept statement
5882 -- is part of a list. If not, then it must be in an accept alternative.
5884 -- To expand the requeue statement, a label is provided at the end of the
5885 -- accept statement or alternative of which it is a part, so that the
5886 -- statement can be skipped after the requeue is complete. This label is
5887 -- created here rather than during the expansion of the accept statement,
5888 -- because it will be needed by any requeue statements within the accept,
5889 -- which are expanded before the accept.
5891 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5892 Loc
: constant Source_Ptr
:= Sloc
(N
);
5893 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5894 Ann
: Entity_Id
:= Empty
;
5901 if Expander_Active
then
5903 -- If we have no handled statement sequence, we may need to build
5904 -- a dummy sequence consisting of a null statement. This can be
5905 -- skipped if the trivial accept optimization is permitted.
5907 if not Trivial_Accept_OK
5909 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5911 Set_Handled_Statement_Sequence
(N
,
5912 Make_Handled_Sequence_Of_Statements
(Loc
,
5913 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5916 -- Create and declare two labels to be placed at the end of the
5917 -- accept statement. The first label is used to allow requeues to
5918 -- skip the remainder of entry processing. The second label is used
5919 -- to skip the remainder of entry processing if the rendezvous
5920 -- completes in the middle of the accept body.
5922 if Present
(Handled_Statement_Sequence
(N
)) then
5927 Ent
:= Make_Temporary
(Loc
, 'L');
5928 Lab
:= Make_Label
(Loc
, New_Reference_To
(Ent
, Loc
));
5930 Make_Implicit_Label_Declaration
(Loc
,
5931 Defining_Identifier
=> Ent
,
5932 Label_Construct
=> Lab
);
5933 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5935 Ent
:= Make_Temporary
(Loc
, 'L');
5936 Lab
:= Make_Label
(Loc
, New_Reference_To
(Ent
, Loc
));
5938 Make_Implicit_Label_Declaration
(Loc
,
5939 Defining_Identifier
=> Ent
,
5940 Label_Construct
=> Lab
);
5941 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5949 -- Case of stand alone accept statement
5951 if Is_List_Member
(N
) then
5953 if Present
(Handled_Statement_Sequence
(N
)) then
5954 Ann
:= Make_Temporary
(Loc
, 'A');
5957 Make_Object_Declaration
(Loc
,
5958 Defining_Identifier
=> Ann
,
5959 Object_Definition
=>
5960 New_Reference_To
(RTE
(RE_Address
), Loc
));
5962 Insert_Before_And_Analyze
(N
, Adecl
);
5963 Insert_Before_And_Analyze
(N
, Ldecl
);
5964 Insert_Before_And_Analyze
(N
, Ldecl2
);
5967 -- Case of accept statement which is in an accept alternative
5971 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5972 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5976 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5977 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5979 -- ??? Consider a single label for select statements
5981 if Present
(Handled_Statement_Sequence
(N
)) then
5983 Statements
(Handled_Statement_Sequence
(N
)));
5987 Statements
(Handled_Statement_Sequence
(N
)));
5991 -- Find first accept alternative of the selective accept. A
5992 -- valid selective accept must have at least one accept in it.
5994 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5996 while Nkind
(Alt
) /= N_Accept_Alternative
loop
6000 -- If we are the first accept statement, then we have to create
6001 -- the Ann variable, as for the stand alone case, except that
6002 -- it is inserted before the selective accept. Similarly, a
6003 -- label for requeue expansion must be declared.
6005 if N
= Accept_Statement
(Alt
) then
6006 Ann
:= Make_Temporary
(Loc
, 'A');
6008 Make_Object_Declaration
(Loc
,
6009 Defining_Identifier
=> Ann
,
6010 Object_Definition
=>
6011 New_Reference_To
(RTE
(RE_Address
), Loc
));
6013 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
6015 -- If we are not the first accept statement, then find the Ann
6016 -- variable allocated by the first accept and use it.
6020 Node
(Last_Elmt
(Accept_Address
6021 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
6026 -- Merge here with Ann either created or referenced, and Adecl
6027 -- pointing to the corresponding declaration. Remaining processing
6028 -- is the same for the two cases.
6030 if Present
(Ann
) then
6031 Append_Elmt
(Ann
, Accept_Address
(Ent
));
6032 Set_Debug_Info_Needed
(Ann
);
6035 -- Create renaming declarations for the entry formals. Each reference
6036 -- to a formal becomes a dereference of a component of the parameter
6037 -- block, whose address is held in Ann. These declarations are
6038 -- eventually inserted into the accept block, and analyzed there so
6039 -- that they have the proper scope for gdb and do not conflict with
6040 -- other declarations.
6042 if Present
(Parameter_Specifications
(N
))
6043 and then Present
(Handled_Statement_Sequence
(N
))
6050 Renamed_Formal
: Node_Id
;
6054 Formal
:= First_Formal
(Ent
);
6056 while Present
(Formal
) loop
6057 Comp
:= Entry_Component
(Formal
);
6058 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
6060 Set_Etype
(New_F
, Etype
(Formal
));
6061 Set_Scope
(New_F
, Ent
);
6063 -- Now we set debug info needed on New_F even though it does
6064 -- not come from source, so that the debugger will get the
6065 -- right information for these generated names.
6067 Set_Debug_Info_Needed
(New_F
);
6069 if Ekind
(Formal
) = E_In_Parameter
then
6070 Set_Ekind
(New_F
, E_Constant
);
6072 Set_Ekind
(New_F
, E_Variable
);
6073 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
6076 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
6079 Make_Selected_Component
(Loc
,
6081 Unchecked_Convert_To
(
6082 Entry_Parameters_Type
(Ent
),
6083 New_Reference_To
(Ann
, Loc
)),
6085 New_Reference_To
(Comp
, Loc
));
6088 Build_Renamed_Formal_Declaration
6089 (New_F
, Formal
, Comp
, Renamed_Formal
);
6091 if No
(Declarations
(N
)) then
6092 Set_Declarations
(N
, New_List
);
6095 Append
(Decl
, Declarations
(N
));
6096 Set_Renamed_Object
(Formal
, New_F
);
6097 Next_Formal
(Formal
);
6104 end Expand_Accept_Declarations
;
6106 ---------------------------------------------
6107 -- Expand_Access_Protected_Subprogram_Type --
6108 ---------------------------------------------
6110 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
6111 Loc
: constant Source_Ptr
:= Sloc
(N
);
6113 T
: constant Entity_Id
:= Defining_Identifier
(N
);
6114 D_T
: constant Entity_Id
:= Designated_Type
(T
);
6115 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
6116 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
6117 P_List
: constant List_Id
:= Build_Protected_Spec
6118 (N
, RTE
(RE_Address
), D_T
, False);
6124 -- Create access to subprogram with full signature
6126 if Etype
(D_T
) /= Standard_Void_Type
then
6128 Make_Access_Function_Definition
(Loc
,
6129 Parameter_Specifications
=> P_List
,
6130 Result_Definition
=>
6131 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
6135 Make_Access_Procedure_Definition
(Loc
,
6136 Parameter_Specifications
=> P_List
);
6140 Make_Full_Type_Declaration
(Loc
,
6141 Defining_Identifier
=> D_T2
,
6142 Type_Definition
=> Def1
);
6144 Insert_After_And_Analyze
(N
, Decl1
);
6146 -- Associate the access to subprogram with its original access to
6147 -- protected subprogram type. Needed by the backend to know that this
6148 -- type corresponds with an access to protected subprogram type.
6150 Set_Original_Access_Type
(D_T2
, T
);
6152 -- Create Equivalent_Type, a record with two components for an access to
6153 -- object and an access to subprogram.
6156 Make_Component_Declaration
(Loc
,
6157 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6158 Component_Definition
=>
6159 Make_Component_Definition
(Loc
,
6160 Aliased_Present
=> False,
6161 Subtype_Indication
=>
6162 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
6164 Make_Component_Declaration
(Loc
,
6165 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
6166 Component_Definition
=>
6167 Make_Component_Definition
(Loc
,
6168 Aliased_Present
=> False,
6169 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
6172 Make_Full_Type_Declaration
(Loc
,
6173 Defining_Identifier
=> E_T
,
6175 Make_Record_Definition
(Loc
,
6177 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
6179 Insert_After_And_Analyze
(Decl1
, Decl2
);
6180 Set_Equivalent_Type
(T
, E_T
);
6181 end Expand_Access_Protected_Subprogram_Type
;
6183 --------------------------
6184 -- Expand_Entry_Barrier --
6185 --------------------------
6187 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
6188 Cond
: constant Node_Id
:=
6189 Condition
(Entry_Body_Formal_Part
(N
));
6190 Prot
: constant Entity_Id
:= Scope
(Ent
);
6191 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
6194 Body_Decl
: Node_Id
;
6197 if No_Run_Time_Mode
then
6198 Error_Msg_CRT
("entry barrier", N
);
6202 -- The body of the entry barrier must be analyzed in the context of the
6203 -- protected object, but its scope is external to it, just as any other
6204 -- unprotected version of a protected operation. The specification has
6205 -- been produced when the protected type declaration was elaborated. We
6206 -- build the body, insert it in the enclosing scope, but analyze it in
6207 -- the current context. A more uniform approach would be to treat the
6208 -- barrier just as a protected function, and discard the protected
6209 -- version of it because it is never called.
6211 if Expander_Active
then
6212 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6213 Func
:= Barrier_Function
(Ent
);
6214 Set_Corresponding_Spec
(B_F
, Func
);
6216 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
6218 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
6219 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
6222 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
6224 Set_Discriminals
(Spec_Decl
);
6225 Set_Scope
(Func
, Scope
(Prot
));
6228 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6231 -- The Ravenscar profile restricts barriers to simple variables declared
6232 -- within the protected object. We also allow Boolean constants, since
6233 -- these appear in several published examples and are also allowed by
6234 -- the Aonix compiler.
6236 -- Note that after analysis variables in this context will be replaced
6237 -- by the corresponding prival, that is to say a renaming of a selected
6238 -- component of the form _Object.Var. If expansion is disabled, as
6239 -- within a generic, we check that the entity appears in the current
6242 if Is_Entity_Name
(Cond
) then
6244 -- A small optimization of useless renamings. If the scope of the
6245 -- entity of the condition is not the barrier function, then the
6246 -- condition does not reference any of the generated renamings
6247 -- within the function.
6249 if Expander_Active
and then Scope
(Entity
(Cond
)) /= Func
then
6250 Set_Declarations
(B_F
, Empty_List
);
6253 if Entity
(Cond
) = Standard_False
6255 Entity
(Cond
) = Standard_True
6259 elsif not Expander_Active
6260 and then Scope
(Entity
(Cond
)) = Current_Scope
6264 -- Check for case of _object.all.field (note that the explicit
6265 -- dereference gets inserted by analyze/expand of _object.field)
6267 elsif Present
(Renamed_Object
(Entity
(Cond
)))
6269 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
6273 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
6279 -- It is not a boolean variable or literal, so check the restriction
6281 Check_Restriction
(Simple_Barriers
, Cond
);
6282 end Expand_Entry_Barrier
;
6284 ------------------------------
6285 -- Expand_N_Abort_Statement --
6286 ------------------------------
6288 -- Expand abort T1, T2, .. Tn; into:
6289 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6291 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6292 Loc
: constant Source_Ptr
:= Sloc
(N
);
6293 Tlist
: constant List_Id
:= Names
(N
);
6299 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6302 Tasknm
:= First
(Tlist
);
6304 while Present
(Tasknm
) loop
6307 -- A task interface class-wide type object is being aborted.
6308 -- Retrieve its _task_id by calling a dispatching routine.
6310 if Ada_Version
>= Ada_2005
6311 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6312 and then Is_Interface
(Etype
(Tasknm
))
6313 and then Is_Task_Interface
(Etype
(Tasknm
))
6315 Append_To
(Component_Associations
(Aggr
),
6316 Make_Component_Association
(Loc
,
6317 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6320 -- Task_Id (Tasknm._disp_get_task_id)
6322 Make_Unchecked_Type_Conversion
(Loc
,
6324 New_Reference_To
(RTE
(RO_ST_Task_Id
), Loc
),
6326 Make_Selected_Component
(Loc
,
6327 Prefix
=> New_Copy_Tree
(Tasknm
),
6329 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6332 Append_To
(Component_Associations
(Aggr
),
6333 Make_Component_Association
(Loc
,
6334 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6335 Expression
=> Concurrent_Ref
(Tasknm
)));
6342 Make_Procedure_Call_Statement
(Loc
,
6343 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
6344 Parameter_Associations
=> New_List
(
6345 Make_Qualified_Expression
(Loc
,
6346 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
6347 Expression
=> Aggr
))));
6350 end Expand_N_Abort_Statement
;
6352 -------------------------------
6353 -- Expand_N_Accept_Statement --
6354 -------------------------------
6356 -- This procedure handles expansion of accept statements that stand
6357 -- alone, i.e. they are not part of an accept alternative. The expansion
6358 -- of accept statement in accept alternatives is handled by the routines
6359 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6360 -- following description applies only to stand alone accept statements.
6362 -- If there is no handled statement sequence, or only null statements,
6363 -- then this is called a trivial accept, and the expansion is:
6365 -- Accept_Trivial (entry-index)
6367 -- If there is a handled statement sequence, then the expansion is:
6374 -- Accept_Call (entry-index, Ann);
6375 -- Renaming_Declarations for formals
6376 -- <statement sequence from N_Accept_Statement node>
6377 -- Complete_Rendezvous;
6382 -- <exception handler from N_Accept_Statement node>
6383 -- Complete_Rendezvous;
6385 -- <exception handler from N_Accept_Statement node>
6386 -- Complete_Rendezvous;
6391 -- when all others =>
6392 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6395 -- The first three declarations were already inserted ahead of the accept
6396 -- statement by the Expand_Accept_Declarations procedure, which was called
6397 -- directly from the semantics during analysis of the accept statement,
6398 -- before analyzing its contained statements.
6400 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6401 -- from possible expansion activity (the original source of course does
6402 -- not have any declarations associated with the accept statement, since
6403 -- an accept statement has no declarative part). In particular, if the
6404 -- expander is active, the first such declaration is the declaration of
6405 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6407 -- The two blocks are merged into a single block if the inner block has
6408 -- no exception handlers, but otherwise two blocks are required, since
6409 -- exceptions might be raised in the exception handlers of the inner
6410 -- block, and Exceptional_Complete_Rendezvous must be called.
6412 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6413 Loc
: constant Source_Ptr
:= Sloc
(N
);
6414 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6415 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6416 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6417 Eent
: constant Entity_Id
:= Entity
(Ename
);
6418 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6419 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6420 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6426 -- If the accept statement is not part of a list, then its parent must
6427 -- be an accept alternative, and, as described above, we do not do any
6428 -- expansion for such accept statements at this level.
6430 if not Is_List_Member
(N
) then
6431 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6434 -- Trivial accept case (no statement sequence, or null statements).
6435 -- If the accept statement has declarations, then just insert them
6436 -- before the procedure call.
6438 elsif Trivial_Accept_OK
6439 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6441 -- Remove declarations for renamings, because the parameter block
6442 -- will not be assigned.
6449 D
:= First
(Declarations
(N
));
6451 while Present
(D
) loop
6453 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6461 if Present
(Declarations
(N
)) then
6462 Insert_Actions
(N
, Declarations
(N
));
6466 Make_Procedure_Call_Statement
(Loc
,
6467 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
6468 Parameter_Associations
=> New_List
(
6469 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6473 -- Discard Entry_Address that was created for it, so it will not be
6474 -- emitted if this accept statement is in the statement part of a
6475 -- delay alternative.
6477 if Present
(Stats
) then
6478 Remove_Last_Elmt
(Acstack
);
6481 -- Case of statement sequence present
6484 -- Construct the block, using the declarations from the accept
6485 -- statement if any to initialize the declarations of the block.
6487 Blkent
:= Make_Temporary
(Loc
, 'A');
6488 Set_Ekind
(Blkent
, E_Block
);
6489 Set_Etype
(Blkent
, Standard_Void_Type
);
6490 Set_Scope
(Blkent
, Current_Scope
);
6493 Make_Block_Statement
(Loc
,
6494 Identifier
=> New_Reference_To
(Blkent
, Loc
),
6495 Declarations
=> Declarations
(N
),
6496 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6498 -- For the analysis of the generated declarations, the parent node
6499 -- must be properly set.
6501 Set_Parent
(Block
, Parent
(N
));
6503 -- Prepend call to Accept_Call to main statement sequence If the
6504 -- accept has exception handlers, the statement sequence is wrapped
6505 -- in a block. Insert call and renaming declarations in the
6506 -- declarations of the block, so they are elaborated before the
6510 Make_Procedure_Call_Statement
(Loc
,
6511 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
6512 Parameter_Associations
=> New_List
(
6513 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6514 New_Reference_To
(Ann
, Loc
)));
6516 if Parent
(Stats
) = N
then
6517 Prepend
(Call
, Statements
(Stats
));
6519 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6524 Push_Scope
(Blkent
);
6532 D
:= First
(Declarations
(N
));
6533 while Present
(D
) loop
6536 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6538 -- The renaming declarations for the formals were created
6539 -- during analysis of the accept statement, and attached to
6540 -- the list of declarations. Place them now in the context
6541 -- of the accept block or subprogram.
6544 Typ
:= Entity
(Subtype_Mark
(D
));
6545 Insert_After
(Call
, D
);
6548 -- If the formal is class_wide, it does not have an actual
6549 -- subtype. The analysis of the renaming declaration creates
6550 -- one, but we need to retain the class-wide nature of the
6553 if Is_Class_Wide_Type
(Typ
) then
6554 Set_Etype
(Defining_Identifier
(D
), Typ
);
6565 -- Replace the accept statement by the new block
6570 -- Last step is to unstack the Accept_Address value
6572 Remove_Last_Elmt
(Acstack
);
6574 end Expand_N_Accept_Statement
;
6576 ----------------------------------
6577 -- Expand_N_Asynchronous_Select --
6578 ----------------------------------
6580 -- This procedure assumes that the trigger statement is an entry call or
6581 -- a dispatching procedure call. A delay alternative should already have
6582 -- been expanded into an entry call to the appropriate delay object Wait
6585 -- If the trigger is a task entry call, the select is implemented with
6586 -- a Task_Entry_Call:
6591 -- P : parms := (parm, parm, parm);
6593 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6595 -- procedure _clean is
6598 -- Cancel_Task_Entry_Call (C);
6605 -- (<acceptor-task>, -- Acceptor
6606 -- <entry-index>, -- E
6607 -- P'Address, -- Uninterpreted_Data
6608 -- Asynchronous_Call, -- Mode
6609 -- B); -- Rendezvous_Successful
6616 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6619 -- when Abort_Signal => Abort_Undefer;
6626 -- <triggered-statements>
6630 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6631 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6635 -- P : parms := (parm, parm, parm);
6637 -- Call_Simple (acceptor-task, entry-index, P'Address);
6643 -- so the task at hand is to convert the latter expansion into the former
6645 -- If the trigger is a protected entry call, the select is implemented
6646 -- with Protected_Entry_Call:
6649 -- P : E1_Params := (param, param, param);
6650 -- Bnn : Communications_Block;
6655 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6657 -- procedure _clean is
6660 -- if Enqueued (Bnn) then
6661 -- Cancel_Protected_Entry_Call (Bnn);
6668 -- Protected_Entry_Call
6669 -- (po._object'Access, -- Object
6670 -- <entry index>, -- E
6671 -- P'Address, -- Uninterpreted_Data
6672 -- Asynchronous_Call, -- Mode
6675 -- if Enqueued (Bnn) then
6679 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6682 -- when Abort_Signal => Abort_Undefer;
6685 -- if not Cancelled (Bnn) then
6686 -- <triggered-statements>
6690 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6694 -- P : E1_Params := (param, param, param);
6695 -- Bnn : Communications_Block;
6698 -- Protected_Entry_Call
6699 -- (po._object'Access, -- Object
6700 -- <entry index>, -- E
6701 -- P'Address, -- Uninterpreted_Data
6702 -- Simple_Call, -- Mode
6709 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6713 -- B : Boolean := False;
6714 -- Bnn : Communication_Block;
6715 -- C : Ada.Tags.Prim_Op_Kind;
6716 -- D : System.Storage_Elements.Dummy_Communication_Block;
6717 -- K : Ada.Tags.Tagged_Kind :=
6718 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6719 -- P : Parameters := (Param1 .. ParamN);
6724 -- if K = Ada.Tags.TK_Limited_Tagged
6725 -- or else K = Ada.Tags.TK_Tagged
6727 -- <dispatching-call>;
6728 -- <triggering-statements>;
6732 -- Ada.Tags.Get_Offset_Index
6733 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6735 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6737 -- if C = POK_Protected_Entry then
6739 -- procedure _clean is
6741 -- if Enqueued (Bnn) then
6742 -- Cancel_Protected_Entry_Call (Bnn);
6748 -- _Disp_Asynchronous_Select
6749 -- (<object>, S, P'Address, D, B);
6750 -- Bnn := Communication_Block (D);
6752 -- Param1 := P.Param1;
6754 -- ParamN := P.ParamN;
6756 -- if Enqueued (Bnn) then
6757 -- <abortable-statements>
6760 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6763 -- when Abort_Signal => Abort_Undefer;
6766 -- if not Cancelled (Bnn) then
6767 -- <triggering-statements>
6770 -- elsif C = POK_Task_Entry then
6772 -- procedure _clean is
6774 -- Cancel_Task_Entry_Call (U);
6780 -- _Disp_Asynchronous_Select
6781 -- (<object>, S, P'Address, D, B);
6782 -- Bnn := Communication_Bloc (D);
6784 -- Param1 := P.Param1;
6786 -- ParamN := P.ParamN;
6791 -- <abortable-statements>
6793 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6796 -- when Abort_Signal => Abort_Undefer;
6800 -- <triggering-statements>
6805 -- <dispatching-call>;
6806 -- <triggering-statements>
6811 -- The job is to convert this to the asynchronous form
6813 -- If the trigger is a delay statement, it will have been expanded into a
6814 -- call to one of the GNARL delay procedures. This routine will convert
6815 -- this into a protected entry call on a delay object and then continue
6816 -- processing as for a protected entry call trigger. This requires
6817 -- declaring a Delay_Block object and adding a pointer to this object to
6818 -- the parameter list of the delay procedure to form the parameter list of
6819 -- the entry call. This object is used by the runtime to queue the delay
6822 -- For a description of the use of P and the assignments after the call,
6823 -- see Expand_N_Entry_Call_Statement.
6825 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6826 Loc
: constant Source_Ptr
:= Sloc
(N
);
6827 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6828 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6830 Abort_Block_Ent
: Entity_Id
;
6831 Abortable_Block
: Node_Id
;
6834 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6835 Blk_Typ
: Entity_Id
;
6837 Call_Ent
: Entity_Id
;
6838 Cancel_Param
: Entity_Id
;
6839 Cleanup_Block
: Node_Id
;
6840 Cleanup_Block_Ent
: Entity_Id
;
6841 Cleanup_Stmts
: List_Id
;
6842 Conc_Typ_Stmts
: List_Id
;
6844 Dblock_Ent
: Entity_Id
;
6849 Enqueue_Call
: Node_Id
;
6852 Handler_Stmt
: Node_Id
;
6854 Lim_Typ_Stmts
: List_Id
;
6860 ProtE_Stmts
: List_Id
;
6861 ProtP_Stmts
: List_Id
;
6864 TaskE_Stmts
: List_Id
;
6867 B
: Entity_Id
; -- Call status flag
6868 Bnn
: Entity_Id
; -- Communication block
6869 C
: Entity_Id
; -- Call kind
6870 K
: Entity_Id
; -- Tagged kind
6871 P
: Entity_Id
; -- Parameter block
6872 S
: Entity_Id
; -- Primitive operation slot
6873 T
: Entity_Id
; -- Additional status flag
6875 procedure Rewrite_Abortable_Part
;
6876 -- If the trigger is a dispatching call, the expansion inserts multiple
6877 -- copies of the abortable part. This is both inefficient, and may lead
6878 -- to duplicate definitions that the back-end will reject, when the
6879 -- abortable part includes loops. This procedure rewrites the abortable
6880 -- part into a call to a generated procedure.
6882 ----------------------------
6883 -- Rewrite_Abortable_Part --
6884 ----------------------------
6886 procedure Rewrite_Abortable_Part
is
6887 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6892 Make_Subprogram_Body
(Loc
,
6894 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6895 Declarations
=> New_List
,
6896 Handled_Statement_Sequence
=>
6897 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6898 Insert_Before
(N
, Decl
);
6901 -- Rewrite abortable part into a call to this procedure.
6905 Make_Procedure_Call_Statement
(Loc
,
6906 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6907 end Rewrite_Abortable_Part
;
6910 Process_Statements_For_Controlled_Objects
(Trig
);
6911 Process_Statements_For_Controlled_Objects
(Abrt
);
6913 Ecall
:= Triggering_Statement
(Trig
);
6915 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6917 -- Retrieve Astats and Tstats now because the finalization machinery may
6918 -- wrap them in blocks.
6920 Astats
:= Statements
(Abrt
);
6921 Tstats
:= Statements
(Trig
);
6923 -- The arguments in the call may require dynamic allocation, and the
6924 -- call statement may have been transformed into a block. The block
6925 -- may contain additional declarations for internal entities, and the
6926 -- original call is found by sequential search.
6928 if Nkind
(Ecall
) = N_Block_Statement
then
6929 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6930 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6931 N_Entry_Call_Statement
)
6937 -- This is either a dispatching call or a delay statement used as a
6938 -- trigger which was expanded into a procedure call.
6940 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6941 if Ada_Version
>= Ada_2005
6943 (No
(Original_Node
(Ecall
))
6944 or else not Nkind_In
(Original_Node
(Ecall
),
6945 N_Delay_Relative_Statement
,
6946 N_Delay_Until_Statement
))
6948 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6950 Rewrite_Abortable_Part
;
6954 -- Call status flag processing, generate:
6955 -- B : Boolean := False;
6957 B
:= Build_B
(Loc
, Decls
);
6959 -- Communication block processing, generate:
6960 -- Bnn : Communication_Block;
6962 Bnn
:= Make_Temporary
(Loc
, 'B');
6964 Make_Object_Declaration
(Loc
,
6965 Defining_Identifier
=> Bnn
,
6966 Object_Definition
=>
6967 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
6969 -- Call kind processing, generate:
6970 -- C : Ada.Tags.Prim_Op_Kind;
6972 C
:= Build_C
(Loc
, Decls
);
6974 -- Tagged kind processing, generate:
6975 -- K : Ada.Tags.Tagged_Kind :=
6976 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6978 -- Dummy communication block, generate:
6979 -- D : Dummy_Communication_Block;
6982 Make_Object_Declaration
(Loc
,
6983 Defining_Identifier
=>
6984 Make_Defining_Identifier
(Loc
, Name_uD
),
6985 Object_Definition
=>
6987 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
6989 K
:= Build_K
(Loc
, Decls
, Obj
);
6991 -- Parameter block processing
6993 Blk_Typ
:= Build_Parameter_Block
6994 (Loc
, Actuals
, Formals
, Decls
);
6995 P
:= Parameter_Block_Pack
6996 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6998 -- Dispatch table slot processing, generate:
7001 S
:= Build_S
(Loc
, Decls
);
7003 -- Additional status flag processing, generate:
7006 T
:= Make_Temporary
(Loc
, 'T');
7008 Make_Object_Declaration
(Loc
,
7009 Defining_Identifier
=> T
,
7010 Object_Definition
=>
7011 New_Reference_To
(Standard_Boolean
, Loc
)));
7013 ------------------------------
7014 -- Protected entry handling --
7015 ------------------------------
7018 -- Param1 := P.Param1;
7020 -- ParamN := P.ParamN;
7022 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7025 -- Bnn := Communication_Block (D);
7027 Prepend_To
(Cleanup_Stmts
,
7028 Make_Assignment_Statement
(Loc
,
7029 Name
=> New_Reference_To
(Bnn
, Loc
),
7031 Make_Unchecked_Type_Conversion
(Loc
,
7033 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
7034 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7037 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7039 Prepend_To
(Cleanup_Stmts
,
7040 Make_Procedure_Call_Statement
(Loc
,
7044 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
7046 Parameter_Associations
=>
7048 New_Copy_Tree
(Obj
), -- <object>
7049 New_Reference_To
(S
, Loc
), -- S
7050 Make_Attribute_Reference
(Loc
, -- P'Address
7051 Prefix
=> New_Reference_To
(P
, Loc
),
7052 Attribute_Name
=> Name_Address
),
7053 Make_Identifier
(Loc
, Name_uD
), -- D
7054 New_Reference_To
(B
, Loc
)))); -- B
7057 -- if Enqueued (Bnn) then
7058 -- <abortable-statements>
7061 Append_To
(Cleanup_Stmts
,
7062 Make_Implicit_If_Statement
(N
,
7064 Make_Function_Call
(Loc
,
7066 New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
7067 Parameter_Associations
=>
7068 New_List
(New_Reference_To
(Bnn
, Loc
))),
7071 New_Copy_List_Tree
(Astats
)));
7073 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7074 -- will then generate a _clean for the communication block Bnn.
7078 -- procedure _clean is
7080 -- if Enqueued (Bnn) then
7081 -- Cancel_Protected_Entry_Call (Bnn);
7090 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7092 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7094 -- Wrap the cleanup block in an exception handling block
7100 -- when Abort_Signal => Abort_Undefer;
7103 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7106 Make_Implicit_Label_Declaration
(Loc
,
7107 Defining_Identifier
=> Abort_Block_Ent
),
7110 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7113 -- if not Cancelled (Bnn) then
7114 -- <triggering-statements>
7117 Append_To
(ProtE_Stmts
,
7118 Make_Implicit_If_Statement
(N
,
7122 Make_Function_Call
(Loc
,
7124 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
7125 Parameter_Associations
=>
7126 New_List
(New_Reference_To
(Bnn
, Loc
)))),
7129 New_Copy_List_Tree
(Tstats
)));
7131 -------------------------
7132 -- Task entry handling --
7133 -------------------------
7136 -- Param1 := P.Param1;
7138 -- ParamN := P.ParamN;
7140 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7143 -- Bnn := Communication_Block (D);
7145 Append_To
(TaskE_Stmts
,
7146 Make_Assignment_Statement
(Loc
,
7148 New_Reference_To
(Bnn
, Loc
),
7150 Make_Unchecked_Type_Conversion
(Loc
,
7152 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
7153 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7156 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7158 Prepend_To
(TaskE_Stmts
,
7159 Make_Procedure_Call_Statement
(Loc
,
7162 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7163 Name_uDisp_Asynchronous_Select
),
7166 Parameter_Associations
=>
7168 New_Copy_Tree
(Obj
), -- <object>
7169 New_Reference_To
(S
, Loc
), -- S
7170 Make_Attribute_Reference
(Loc
, -- P'Address
7171 Prefix
=> New_Reference_To
(P
, Loc
),
7172 Attribute_Name
=> Name_Address
),
7173 Make_Identifier
(Loc
, Name_uD
), -- D
7174 New_Reference_To
(B
, Loc
)))); -- B
7179 Prepend_To
(TaskE_Stmts
,
7180 Make_Procedure_Call_Statement
(Loc
,
7181 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7182 Parameter_Associations
=> No_List
));
7186 -- <abortable-statements>
7188 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7190 Prepend_To
(Cleanup_Stmts
,
7191 Make_Procedure_Call_Statement
(Loc
,
7192 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7193 Parameter_Associations
=> No_List
));
7195 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7196 -- will generate a _clean for the additional status flag.
7200 -- procedure _clean is
7202 -- Cancel_Task_Entry_Call (U);
7210 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7212 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7214 -- Wrap the cleanup block in an exception handling block
7220 -- when Abort_Signal => Abort_Undefer;
7223 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7225 Append_To
(TaskE_Stmts
,
7226 Make_Implicit_Label_Declaration
(Loc
,
7227 Defining_Identifier
=> Abort_Block_Ent
));
7229 Append_To
(TaskE_Stmts
,
7231 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7235 -- <triggering-statements>
7238 Append_To
(TaskE_Stmts
,
7239 Make_Implicit_If_Statement
(N
,
7241 Make_Op_Not
(Loc
, Right_Opnd
=> New_Reference_To
(T
, Loc
)),
7244 New_Copy_List_Tree
(Tstats
)));
7246 ----------------------------------
7247 -- Protected procedure handling --
7248 ----------------------------------
7251 -- <dispatching-call>;
7252 -- <triggering-statements>
7254 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7255 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7258 -- S := Ada.Tags.Get_Offset_Index
7259 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7262 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7265 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7267 Append_To
(Conc_Typ_Stmts
,
7268 Make_Procedure_Call_Statement
(Loc
,
7271 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7272 Name_uDisp_Get_Prim_Op_Kind
),
7274 Parameter_Associations
=>
7276 New_Copy_Tree
(Obj
),
7277 New_Reference_To
(S
, Loc
),
7278 New_Reference_To
(C
, Loc
))));
7281 -- if C = POK_Procedure_Entry then
7283 -- elsif C = POK_Task_Entry then
7289 Append_To
(Conc_Typ_Stmts
,
7290 Make_Implicit_If_Statement
(N
,
7294 New_Reference_To
(C
, Loc
),
7296 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7303 Make_Elsif_Part
(Loc
,
7307 New_Reference_To
(C
, Loc
),
7309 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
)),
7318 -- <dispatching-call>;
7319 -- <triggering-statements>
7321 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7322 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7325 -- if K = Ada.Tags.TK_Limited_Tagged
7326 -- or else K = Ada.Tags.TK_Tagged
7334 Make_Implicit_If_Statement
(N
,
7335 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7336 Then_Statements
=> Lim_Typ_Stmts
,
7337 Else_Statements
=> Conc_Typ_Stmts
));
7340 Make_Block_Statement
(Loc
,
7343 Handled_Statement_Sequence
=>
7344 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7349 -- Delay triggering statement processing
7352 -- Add a Delay_Block object to the parameter list of the delay
7353 -- procedure to form the parameter list of the Wait entry call.
7355 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7357 Pdef
:= Entity
(Name
(Ecall
));
7359 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7361 New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
7363 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7365 New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
7367 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7368 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
7371 Append_To
(Parameter_Associations
(Ecall
),
7372 Make_Attribute_Reference
(Loc
,
7373 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7374 Attribute_Name
=> Name_Unchecked_Access
));
7376 -- Create the inner block to protect the abortable part
7378 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7381 Make_Procedure_Call_Statement
(Loc
,
7382 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7385 Make_Block_Statement
(Loc
,
7386 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7387 Handled_Statement_Sequence
=>
7388 Make_Handled_Sequence_Of_Statements
(Loc
,
7389 Statements
=> Astats
),
7390 Has_Created_Identifier
=> True,
7391 Is_Asynchronous_Call_Block
=> True);
7393 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7396 Make_Implicit_If_Statement
(N
,
7398 Make_Function_Call
(Loc
,
7399 Name
=> Enqueue_Call
,
7400 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7402 New_List
(Make_Block_Statement
(Loc
,
7403 Handled_Statement_Sequence
=>
7404 Make_Handled_Sequence_Of_Statements
(Loc
,
7405 Statements
=> New_List
(
7406 Make_Implicit_Label_Declaration
(Loc
,
7407 Defining_Identifier
=> Blk_Ent
,
7408 Label_Construct
=> Abortable_Block
),
7410 Exception_Handlers
=> Hdle
)))));
7412 Stmts
:= New_List
(Ecall
);
7414 -- Construct statement sequence for new block
7417 Make_Implicit_If_Statement
(N
,
7419 Make_Function_Call
(Loc
,
7420 Name
=> New_Reference_To
(
7421 RTE
(RE_Timed_Out
), Loc
),
7422 Parameter_Associations
=> New_List
(
7423 Make_Attribute_Reference
(Loc
,
7424 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7425 Attribute_Name
=> Name_Unchecked_Access
))),
7426 Then_Statements
=> Tstats
));
7428 -- The result is the new block
7430 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7433 Make_Block_Statement
(Loc
,
7434 Declarations
=> New_List
(
7435 Make_Object_Declaration
(Loc
,
7436 Defining_Identifier
=> Dblock_Ent
,
7437 Aliased_Present
=> True,
7438 Object_Definition
=>
7439 New_Reference_To
(RTE
(RE_Delay_Block
), Loc
))),
7441 Handled_Statement_Sequence
=>
7442 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7452 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7453 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7455 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7456 Decls
:= Declarations
(Ecall
);
7458 if Is_Protected_Type
(Etype
(Concval
)) then
7460 -- Get the declarations of the block expanded from the entry call
7462 Decl
:= First
(Decls
);
7463 while Present
(Decl
)
7464 and then (Nkind
(Decl
) /= N_Object_Declaration
7465 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7466 RE_Communication_Block
))
7471 pragma Assert
(Present
(Decl
));
7472 Cancel_Param
:= Defining_Identifier
(Decl
);
7474 -- Change the mode of the Protected_Entry_Call call
7476 -- Protected_Entry_Call (
7477 -- Object => po._object'Access,
7478 -- E => <entry index>;
7479 -- Uninterpreted_Data => P'Address;
7480 -- Mode => Asynchronous_Call;
7483 -- Skip assignments to temporaries created for in-out parameters
7485 -- This makes unwarranted assumptions about the shape of the expanded
7486 -- tree for the call, and should be cleaned up ???
7488 Stmt
:= First
(Stmts
);
7489 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7495 Param
:= First
(Parameter_Associations
(Call
));
7496 while Present
(Param
)
7497 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7502 pragma Assert
(Present
(Param
));
7503 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7506 -- Append an if statement to execute the abortable part
7509 -- if Enqueued (Bnn) then
7512 Make_Implicit_If_Statement
(N
,
7514 Make_Function_Call
(Loc
,
7515 Name
=> New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
7516 Parameter_Associations
=> New_List
(
7517 New_Reference_To
(Cancel_Param
, Loc
))),
7518 Then_Statements
=> Astats
));
7521 Make_Block_Statement
(Loc
,
7522 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7523 Handled_Statement_Sequence
=>
7524 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7525 Has_Created_Identifier
=> True,
7526 Is_Asynchronous_Call_Block
=> True);
7528 -- For the VM call Update_Exception instead of Abort_Undefer.
7529 -- See 4jexcept.ads for an explanation.
7531 if VM_Target
= No_VM
then
7532 if Exception_Mechanism
= Back_End_Exceptions
then
7534 -- Aborts are not deferred at beginning of exception handlers
7537 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7540 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7541 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7542 Parameter_Associations
=> No_List
);
7545 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7546 Name
=> New_Reference_To
(RTE
(RE_Update_Exception
), Loc
),
7547 Parameter_Associations
=> New_List
(
7548 Make_Function_Call
(Loc
,
7549 Name
=> New_Occurrence_Of
7550 (RTE
(RE_Current_Target_Exception
), Loc
))));
7554 Make_Block_Statement
(Loc
,
7555 Handled_Statement_Sequence
=>
7556 Make_Handled_Sequence_Of_Statements
(Loc
,
7557 Statements
=> New_List
(
7558 Make_Implicit_Label_Declaration
(Loc
,
7559 Defining_Identifier
=> Blk_Ent
,
7560 Label_Construct
=> Abortable_Block
),
7565 Exception_Handlers
=> New_List
(
7566 Make_Implicit_Exception_Handler
(Loc
,
7568 -- when Abort_Signal =>
7569 -- Abort_Undefer.all;
7571 Exception_Choices
=>
7572 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
7573 Statements
=> New_List
(Handler_Stmt
))))),
7575 -- if not Cancelled (Bnn) then
7576 -- triggered statements
7579 Make_Implicit_If_Statement
(N
,
7580 Condition
=> Make_Op_Not
(Loc
,
7582 Make_Function_Call
(Loc
,
7583 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7584 Parameter_Associations
=> New_List
(
7585 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7586 Then_Statements
=> Tstats
));
7588 -- Asynchronous task entry call
7595 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7597 -- Insert declaration of B in declarations of existing block
7600 Make_Object_Declaration
(Loc
,
7601 Defining_Identifier
=> B
,
7602 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7604 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7606 -- Insert declaration of C in declarations of existing block
7609 Make_Object_Declaration
(Loc
,
7610 Defining_Identifier
=> Cancel_Param
,
7611 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7613 -- Remove and save the call to Call_Simple
7615 Stmt
:= First
(Stmts
);
7617 -- Skip assignments to temporaries created for in-out parameters.
7618 -- This makes unwarranted assumptions about the shape of the expanded
7619 -- tree for the call, and should be cleaned up ???
7621 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7627 -- Create the inner block to protect the abortable part
7629 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7632 Make_Procedure_Call_Statement
(Loc
,
7633 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7636 Make_Block_Statement
(Loc
,
7637 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7638 Handled_Statement_Sequence
=>
7639 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7640 Has_Created_Identifier
=> True,
7641 Is_Asynchronous_Call_Block
=> True);
7644 Make_Block_Statement
(Loc
,
7645 Handled_Statement_Sequence
=>
7646 Make_Handled_Sequence_Of_Statements
(Loc
,
7647 Statements
=> New_List
(
7648 Make_Implicit_Label_Declaration
(Loc
,
7649 Defining_Identifier
=> Blk_Ent
,
7650 Label_Construct
=> Abortable_Block
),
7652 Exception_Handlers
=> Hdle
)));
7654 -- Create new call statement
7656 Params
:= Parameter_Associations
(Call
);
7659 New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7660 Append_To
(Params
, New_Reference_To
(B
, Loc
));
7663 Make_Procedure_Call_Statement
(Loc
,
7664 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7665 Parameter_Associations
=> Params
));
7667 -- Construct statement sequence for new block
7670 Make_Implicit_If_Statement
(N
,
7672 Make_Op_Not
(Loc
, New_Reference_To
(Cancel_Param
, Loc
)),
7673 Then_Statements
=> Tstats
));
7675 -- Protected the call against abort
7678 Make_Procedure_Call_Statement
(Loc
,
7679 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7680 Parameter_Associations
=> Empty_List
));
7683 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7685 -- The result is the new block
7688 Make_Block_Statement
(Loc
,
7689 Declarations
=> Decls
,
7690 Handled_Statement_Sequence
=>
7691 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7694 end Expand_N_Asynchronous_Select
;
7696 -------------------------------------
7697 -- Expand_N_Conditional_Entry_Call --
7698 -------------------------------------
7700 -- The conditional task entry call is converted to a call to
7705 -- P : parms := (parm, parm, parm);
7709 -- (<acceptor-task>, -- Acceptor
7710 -- <entry-index>, -- E
7711 -- P'Address, -- Uninterpreted_Data
7712 -- Conditional_Call, -- Mode
7713 -- B); -- Rendezvous_Successful
7718 -- normal-statements
7724 -- For a description of the use of P and the assignments after the call,
7725 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7726 -- conditional entry call has already been expanded (by the Expand_N_Entry
7727 -- _Call_Statement procedure) as follows:
7730 -- P : parms := (parm, parm, parm);
7732 -- ... info for in-out parameters
7733 -- Call_Simple (acceptor-task, entry-index, P'Address);
7739 -- so the task at hand is to convert the latter expansion into the former
7741 -- The conditional protected entry call is converted to a call to
7742 -- Protected_Entry_Call:
7745 -- P : parms := (parm, parm, parm);
7746 -- Bnn : Communications_Block;
7749 -- Protected_Entry_Call
7750 -- (po._object'Access, -- Object
7751 -- <entry index>, -- E
7752 -- P'Address, -- Uninterpreted_Data
7753 -- Conditional_Call, -- Mode
7758 -- if Cancelled (Bnn) then
7761 -- normal-statements
7765 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7769 -- B : Boolean := False;
7770 -- C : Ada.Tags.Prim_Op_Kind;
7771 -- K : Ada.Tags.Tagged_Kind :=
7772 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7773 -- P : Parameters := (Param1 .. ParamN);
7777 -- if K = Ada.Tags.TK_Limited_Tagged
7778 -- or else K = Ada.Tags.TK_Tagged
7780 -- <dispatching-call>;
7781 -- <triggering-statements>
7785 -- Ada.Tags.Get_Offset_Index
7786 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7788 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7790 -- if C = POK_Protected_Entry
7791 -- or else C = POK_Task_Entry
7793 -- Param1 := P.Param1;
7795 -- ParamN := P.ParamN;
7799 -- if C = POK_Procedure
7800 -- or else C = POK_Protected_Procedure
7801 -- or else C = POK_Task_Procedure
7803 -- <dispatching-call>;
7806 -- <triggering-statements>
7808 -- <else-statements>
7813 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7814 Loc
: constant Source_Ptr
:= Sloc
(N
);
7815 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7816 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7819 Blk_Typ
: Entity_Id
;
7821 Call_Ent
: Entity_Id
;
7822 Conc_Typ_Stmts
: List_Id
;
7826 Lim_Typ_Stmts
: List_Id
;
7833 Transient_Blk
: Node_Id
;
7836 B
: Entity_Id
; -- Call status flag
7837 C
: Entity_Id
; -- Call kind
7838 K
: Entity_Id
; -- Tagged kind
7839 P
: Entity_Id
; -- Parameter block
7840 S
: Entity_Id
; -- Primitive operation slot
7843 Process_Statements_For_Controlled_Objects
(N
);
7845 if Ada_Version
>= Ada_2005
7846 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7848 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7853 -- Call status flag processing, generate:
7854 -- B : Boolean := False;
7856 B
:= Build_B
(Loc
, Decls
);
7858 -- Call kind processing, generate:
7859 -- C : Ada.Tags.Prim_Op_Kind;
7861 C
:= Build_C
(Loc
, Decls
);
7863 -- Tagged kind processing, generate:
7864 -- K : Ada.Tags.Tagged_Kind :=
7865 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7867 K
:= Build_K
(Loc
, Decls
, Obj
);
7869 -- Parameter block processing
7871 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7872 P
:= Parameter_Block_Pack
7873 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7875 -- Dispatch table slot processing, generate:
7878 S
:= Build_S
(Loc
, Decls
);
7881 -- S := Ada.Tags.Get_Offset_Index
7882 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7885 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7888 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7890 Append_To
(Conc_Typ_Stmts
,
7891 Make_Procedure_Call_Statement
(Loc
,
7894 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7895 Name_uDisp_Conditional_Select
),
7897 Parameter_Associations
=>
7899 New_Copy_Tree
(Obj
), -- <object>
7900 New_Reference_To
(S
, Loc
), -- S
7901 Make_Attribute_Reference
(Loc
, -- P'Address
7902 Prefix
=> New_Reference_To
(P
, Loc
),
7903 Attribute_Name
=> Name_Address
),
7904 New_Reference_To
(C
, Loc
), -- C
7905 New_Reference_To
(B
, Loc
)))); -- B
7908 -- if C = POK_Protected_Entry
7909 -- or else C = POK_Task_Entry
7911 -- Param1 := P.Param1;
7913 -- ParamN := P.ParamN;
7916 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7918 -- Generate the if statement only when the packed parameters need
7919 -- explicit assignments to their corresponding actuals.
7921 if Present
(Unpack
) then
7922 Append_To
(Conc_Typ_Stmts
,
7923 Make_Implicit_If_Statement
(N
,
7929 New_Reference_To
(C
, Loc
),
7931 New_Reference_To
(RTE
(
7932 RE_POK_Protected_Entry
), Loc
)),
7937 New_Reference_To
(C
, Loc
),
7939 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
7941 Then_Statements
=> Unpack
));
7946 -- if C = POK_Procedure
7947 -- or else C = POK_Protected_Procedure
7948 -- or else C = POK_Task_Procedure
7950 -- <dispatching-call>
7952 -- <normal-statements>
7954 -- <else-statements>
7957 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7959 Prepend_To
(N_Stats
,
7960 Make_Implicit_If_Statement
(N
,
7966 New_Reference_To
(C
, Loc
),
7968 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
7975 New_Reference_To
(C
, Loc
),
7977 New_Reference_To
(RTE
(
7978 RE_POK_Protected_Procedure
), Loc
)),
7983 New_Reference_To
(C
, Loc
),
7985 New_Reference_To
(RTE
(
7986 RE_POK_Task_Procedure
), Loc
)))),
7991 Append_To
(Conc_Typ_Stmts
,
7992 Make_Implicit_If_Statement
(N
,
7993 Condition
=> New_Reference_To
(B
, Loc
),
7994 Then_Statements
=> N_Stats
,
7995 Else_Statements
=> Else_Statements
(N
)));
7998 -- <dispatching-call>;
7999 -- <triggering-statements>
8001 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
8002 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
8005 -- if K = Ada.Tags.TK_Limited_Tagged
8006 -- or else K = Ada.Tags.TK_Tagged
8014 Make_Implicit_If_Statement
(N
,
8015 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
8016 Then_Statements
=> Lim_Typ_Stmts
,
8017 Else_Statements
=> Conc_Typ_Stmts
));
8020 Make_Block_Statement
(Loc
,
8023 Handled_Statement_Sequence
=>
8024 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8026 -- As described above, the entry alternative is transformed into a
8027 -- block that contains the gnulli call, and possibly assignment
8028 -- statements for in-out parameters. The gnulli call may itself be
8029 -- rewritten into a transient block if some unconstrained parameters
8030 -- require it. We need to retrieve the call to complete its parameter
8035 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
8037 if Present
(Transient_Blk
)
8038 and then Nkind
(Transient_Blk
) = N_Block_Statement
8040 Blk
:= Transient_Blk
;
8043 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
8044 Stmt
:= First
(Stmts
);
8045 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
8050 Params
:= Parameter_Associations
(Call
);
8052 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
8054 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8056 Param
:= First
(Params
);
8057 while Present
(Param
)
8058 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
8063 pragma Assert
(Present
(Param
));
8064 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
8068 -- Find the Communication_Block parameter for the call to the
8069 -- Cancelled function.
8071 Decl
:= First
(Declarations
(Blk
));
8072 while Present
(Decl
)
8073 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
8074 RE_Communication_Block
)
8079 -- Add an if statement to execute the else part if the call
8080 -- does not succeed (as indicated by the Cancelled predicate).
8083 Make_Implicit_If_Statement
(N
,
8084 Condition
=> Make_Function_Call
(Loc
,
8085 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
8086 Parameter_Associations
=> New_List
(
8087 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
8088 Then_Statements
=> Else_Statements
(N
),
8089 Else_Statements
=> Statements
(Alt
)));
8092 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8094 -- Insert declaration of B in declarations of existing block
8096 if No
(Declarations
(Blk
)) then
8097 Set_Declarations
(Blk
, New_List
);
8100 Prepend_To
(Declarations
(Blk
),
8101 Make_Object_Declaration
(Loc
,
8102 Defining_Identifier
=> B
,
8103 Object_Definition
=>
8104 New_Reference_To
(Standard_Boolean
, Loc
)));
8106 -- Create new call statement
8109 New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
8110 Append_To
(Params
, New_Reference_To
(B
, Loc
));
8113 Make_Procedure_Call_Statement
(Loc
,
8114 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
8115 Parameter_Associations
=> Params
));
8117 -- Construct statement sequence for new block
8120 Make_Implicit_If_Statement
(N
,
8121 Condition
=> New_Reference_To
(B
, Loc
),
8122 Then_Statements
=> Statements
(Alt
),
8123 Else_Statements
=> Else_Statements
(N
)));
8126 -- The result is the new block
8129 Make_Block_Statement
(Loc
,
8130 Declarations
=> Declarations
(Blk
),
8131 Handled_Statement_Sequence
=>
8132 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8136 end Expand_N_Conditional_Entry_Call
;
8138 ---------------------------------------
8139 -- Expand_N_Delay_Relative_Statement --
8140 ---------------------------------------
8142 -- Delay statement is implemented as a procedure call to Delay_For
8143 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8144 -- simple delays imposed by the use of Protected Objects.
8146 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8147 Loc
: constant Source_Ptr
:= Sloc
(N
);
8150 Make_Procedure_Call_Statement
(Loc
,
8151 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
8152 Parameter_Associations
=> New_List
(Expression
(N
))));
8154 end Expand_N_Delay_Relative_Statement
;
8156 ------------------------------------
8157 -- Expand_N_Delay_Until_Statement --
8158 ------------------------------------
8160 -- Delay Until statement is implemented as a procedure call to
8161 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8163 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8164 Loc
: constant Source_Ptr
:= Sloc
(N
);
8168 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8169 Typ
:= RTE
(RO_CA_Delay_Until
);
8171 Typ
:= RTE
(RO_RT_Delay_Until
);
8175 Make_Procedure_Call_Statement
(Loc
,
8176 Name
=> New_Reference_To
(Typ
, Loc
),
8177 Parameter_Associations
=> New_List
(Expression
(N
))));
8180 end Expand_N_Delay_Until_Statement
;
8182 -------------------------
8183 -- Expand_N_Entry_Body --
8184 -------------------------
8186 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8188 -- Associate discriminals with the next protected operation body to be
8191 if Present
(Next_Protected_Operation
(N
)) then
8192 Set_Discriminals
(Parent
(Current_Scope
));
8194 end Expand_N_Entry_Body
;
8196 -----------------------------------
8197 -- Expand_N_Entry_Call_Statement --
8198 -----------------------------------
8200 -- An entry call is expanded into GNARLI calls to implement a simple entry
8201 -- call (see Build_Simple_Entry_Call).
8203 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8209 if No_Run_Time_Mode
then
8210 Error_Msg_CRT
("entry call", N
);
8214 -- If this entry call is part of an asynchronous select, don't expand it
8215 -- here; it will be expanded with the select statement. Don't expand
8216 -- timed entry calls either, as they are translated into asynchronous
8219 -- ??? This whole approach is questionable; it may be better to go back
8220 -- to allowing the expansion to take place and then attempting to fix it
8221 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8222 -- whether the expanded call is on a task or protected entry.
8224 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8225 or else N
/= Triggering_Statement
(Parent
(N
)))
8226 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8227 or else N
/= Entry_Call_Statement
(Parent
(N
))
8228 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8230 Extract_Entry
(N
, Concval
, Ename
, Index
);
8231 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8233 end Expand_N_Entry_Call_Statement
;
8235 --------------------------------
8236 -- Expand_N_Entry_Declaration --
8237 --------------------------------
8239 -- If there are parameters, then first, each of the formals is marked by
8240 -- setting Is_Entry_Formal. Next a record type is built which is used to
8241 -- hold the parameter values. The name of this record type is entryP where
8242 -- entry is the name of the entry, with an additional corresponding access
8243 -- type called entryPA. The record type has matching components for each
8244 -- formal (the component names are the same as the formal names). For
8245 -- elementary types, the component type matches the formal type. For
8246 -- composite types, an access type is declared (with the name formalA)
8247 -- which designates the formal type, and the type of the component is this
8248 -- access type. Finally the Entry_Component of each formal is set to
8249 -- reference the corresponding record component.
8251 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8252 Loc
: constant Source_Ptr
:= Sloc
(N
);
8253 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8254 Components
: List_Id
;
8257 Last_Decl
: Node_Id
;
8258 Component
: Entity_Id
;
8261 Rec_Ent
: Entity_Id
;
8262 Acc_Ent
: Entity_Id
;
8265 Formal
:= First_Formal
(Entry_Ent
);
8268 -- Most processing is done only if parameters are present
8270 if Present
(Formal
) then
8271 Components
:= New_List
;
8273 -- Loop through formals
8275 while Present
(Formal
) loop
8276 Set_Is_Entry_Formal
(Formal
);
8278 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8279 Set_Entry_Component
(Formal
, Component
);
8280 Set_Entry_Formal
(Component
, Formal
);
8281 Ftype
:= Etype
(Formal
);
8283 -- Declare new access type and then append
8285 Ctype
:= Make_Temporary
(Loc
, 'A');
8288 Make_Full_Type_Declaration
(Loc
,
8289 Defining_Identifier
=> Ctype
,
8291 Make_Access_To_Object_Definition
(Loc
,
8292 All_Present
=> True,
8293 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8294 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
8296 Insert_After
(Last_Decl
, Decl
);
8299 Append_To
(Components
,
8300 Make_Component_Declaration
(Loc
,
8301 Defining_Identifier
=> Component
,
8302 Component_Definition
=>
8303 Make_Component_Definition
(Loc
,
8304 Aliased_Present
=> False,
8305 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
8307 Next_Formal_With_Extras
(Formal
);
8310 -- Create the Entry_Parameter_Record declaration
8312 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8315 Make_Full_Type_Declaration
(Loc
,
8316 Defining_Identifier
=> Rec_Ent
,
8318 Make_Record_Definition
(Loc
,
8320 Make_Component_List
(Loc
,
8321 Component_Items
=> Components
)));
8323 Insert_After
(Last_Decl
, Decl
);
8326 -- Construct and link in the corresponding access type
8328 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8330 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8333 Make_Full_Type_Declaration
(Loc
,
8334 Defining_Identifier
=> Acc_Ent
,
8336 Make_Access_To_Object_Definition
(Loc
,
8337 All_Present
=> True,
8338 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
8340 Insert_After
(Last_Decl
, Decl
);
8342 end Expand_N_Entry_Declaration
;
8344 -----------------------------
8345 -- Expand_N_Protected_Body --
8346 -----------------------------
8348 -- Protected bodies are expanded to the completion of the subprograms
8349 -- created for the corresponding protected type. These are a protected and
8350 -- unprotected version of each protected subprogram in the object, a
8351 -- function to calculate each entry barrier, and a procedure to execute the
8352 -- sequence of statements of each protected entry body. For example, for
8353 -- protected type ptype:
8356 -- (O : System.Address;
8357 -- E : Protected_Entry_Index)
8360 -- <discriminant renamings>
8361 -- <private object renamings>
8363 -- return <barrier expression>;
8366 -- procedure pprocN (_object : in out poV;...) is
8367 -- <discriminant renamings>
8368 -- <private object renamings>
8370 -- <sequence of statements>
8373 -- procedure pprocP (_object : in out poV;...) is
8374 -- procedure _clean is
8377 -- ptypeS (_object, Pn);
8378 -- Unlock (_object._object'Access);
8379 -- Abort_Undefer.all;
8384 -- Lock (_object._object'Access);
8385 -- pprocN (_object;...);
8390 -- function pfuncN (_object : poV;...) return Return_Type is
8391 -- <discriminant renamings>
8392 -- <private object renamings>
8394 -- <sequence of statements>
8397 -- function pfuncP (_object : poV) return Return_Type is
8398 -- procedure _clean is
8400 -- Unlock (_object._object'Access);
8401 -- Abort_Undefer.all;
8406 -- Lock (_object._object'Access);
8407 -- return pfuncN (_object);
8414 -- (O : System.Address;
8415 -- P : System.Address;
8416 -- E : Protected_Entry_Index)
8418 -- <discriminant renamings>
8419 -- <private object renamings>
8420 -- type poVP is access poV;
8421 -- _Object : ptVP := ptVP!(O);
8425 -- <statement sequence>
8426 -- Complete_Entry_Body (_Object._Object);
8428 -- when all others =>
8429 -- Exceptional_Complete_Entry_Body (
8430 -- _Object._Object, Get_GNAT_Exception);
8434 -- The type poV is the record created for the protected type to hold
8435 -- the state of the protected object.
8437 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8438 Loc
: constant Source_Ptr
:= Sloc
(N
);
8439 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8441 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8442 -- This flag indicates whether the lock free implementation is active
8444 Current_Node
: Node_Id
;
8445 Disp_Op_Body
: Node_Id
;
8446 New_Op_Body
: Node_Id
;
8450 function Build_Dispatching_Subprogram_Body
8453 Prot_Bod
: Node_Id
) return Node_Id
;
8454 -- Build a dispatching version of the protected subprogram body. The
8455 -- newly generated subprogram contains a call to the original protected
8456 -- body. The following code is generated:
8458 -- function <protected-function-name> (Param1 .. ParamN) return
8461 -- return <protected-function-name>P (Param1 .. ParamN);
8462 -- end <protected-function-name>;
8466 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8468 -- <protected-procedure-name>P (Param1 .. ParamN);
8469 -- end <protected-procedure-name>
8471 ---------------------------------------
8472 -- Build_Dispatching_Subprogram_Body --
8473 ---------------------------------------
8475 function Build_Dispatching_Subprogram_Body
8478 Prot_Bod
: Node_Id
) return Node_Id
8480 Loc
: constant Source_Ptr
:= Sloc
(N
);
8487 -- Generate a specification without a letter suffix in order to
8488 -- override an interface function or procedure.
8490 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8492 -- The formal parameters become the actuals of the protected function
8493 -- or procedure call.
8495 Actuals
:= New_List
;
8496 Formal
:= First
(Parameter_Specifications
(Spec
));
8497 while Present
(Formal
) loop
8499 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8503 if Nkind
(Spec
) = N_Procedure_Specification
then
8506 Make_Procedure_Call_Statement
(Loc
,
8508 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8509 Parameter_Associations
=> Actuals
));
8512 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8516 Make_Simple_Return_Statement
(Loc
,
8518 Make_Function_Call
(Loc
,
8520 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8521 Parameter_Associations
=> Actuals
)));
8525 Make_Subprogram_Body
(Loc
,
8526 Declarations
=> Empty_List
,
8527 Specification
=> Spec
,
8528 Handled_Statement_Sequence
=>
8529 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8530 end Build_Dispatching_Subprogram_Body
;
8532 -- Start of processing for Expand_N_Protected_Body
8535 if No_Run_Time_Mode
then
8536 Error_Msg_CRT
("protected body", N
);
8540 -- This is the proper body corresponding to a stub. The declarations
8541 -- must be inserted at the point of the stub, which in turn is in the
8542 -- declarative part of the parent unit.
8544 if Nkind
(Parent
(N
)) = N_Subunit
then
8545 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8550 Op_Body
:= First
(Declarations
(N
));
8552 -- The protected body is replaced with the bodies of its
8553 -- protected operations, and the declarations for internal objects
8554 -- that may have been created for entry family bounds.
8556 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8559 while Present
(Op_Body
) loop
8560 case Nkind
(Op_Body
) is
8561 when N_Subprogram_Declaration
=>
8564 when N_Subprogram_Body
=>
8566 -- Do not create bodies for eliminated operations
8568 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8569 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8571 if Lock_Free_Active
then
8573 Build_Lock_Free_Unprotected_Subprogram_Body
8577 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8580 Insert_After
(Current_Node
, New_Op_Body
);
8581 Current_Node
:= New_Op_Body
;
8582 Analyze
(New_Op_Body
);
8584 -- Build the corresponding protected operation. It may
8585 -- appear that this is needed only if this is a visible
8586 -- operation of the type, or if it is an interrupt handler,
8587 -- and this was the strategy used previously in GNAT.
8589 -- However, the operation may be exported through a 'Access
8590 -- to an external caller. This is the common idiom in code
8591 -- that uses the Ada 2005 Timing_Events package. As a result
8592 -- we need to produce the protected body for both visible
8593 -- and private operations, as well as operations that only
8594 -- have a body in the source, and for which we create a
8595 -- declaration in the protected body itself.
8597 if Present
(Corresponding_Spec
(Op_Body
)) then
8598 if Lock_Free_Active
then
8600 Build_Lock_Free_Protected_Subprogram_Body
8601 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8604 Build_Protected_Subprogram_Body
8605 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8608 Insert_After
(Current_Node
, New_Op_Body
);
8609 Analyze
(New_Op_Body
);
8611 Current_Node
:= New_Op_Body
;
8613 -- Generate an overriding primitive operation body for
8614 -- this subprogram if the protected type implements an
8617 if Ada_Version
>= Ada_2005
8619 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8622 Build_Dispatching_Subprogram_Body
8623 (Op_Body
, Pid
, New_Op_Body
);
8625 Insert_After
(Current_Node
, Disp_Op_Body
);
8626 Analyze
(Disp_Op_Body
);
8628 Current_Node
:= Disp_Op_Body
;
8633 when N_Entry_Body
=>
8634 Op_Id
:= Defining_Identifier
(Op_Body
);
8635 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8637 Insert_After
(Current_Node
, New_Op_Body
);
8638 Current_Node
:= New_Op_Body
;
8639 Analyze
(New_Op_Body
);
8641 when N_Implicit_Label_Declaration
=>
8644 when N_Itype_Reference
=>
8645 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8647 when N_Freeze_Entity
=>
8648 New_Op_Body
:= New_Copy
(Op_Body
);
8650 if Present
(Entity
(Op_Body
))
8651 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8653 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8656 Insert_After
(Current_Node
, New_Op_Body
);
8657 Current_Node
:= New_Op_Body
;
8658 Analyze
(New_Op_Body
);
8661 New_Op_Body
:= New_Copy
(Op_Body
);
8662 Insert_After
(Current_Node
, New_Op_Body
);
8663 Current_Node
:= New_Op_Body
;
8664 Analyze
(New_Op_Body
);
8666 when N_Object_Declaration
=>
8667 pragma Assert
(not Comes_From_Source
(Op_Body
));
8668 New_Op_Body
:= New_Copy
(Op_Body
);
8669 Insert_After
(Current_Node
, New_Op_Body
);
8670 Current_Node
:= New_Op_Body
;
8671 Analyze
(New_Op_Body
);
8674 raise Program_Error
;
8681 -- Finally, create the body of the function that maps an entry index
8682 -- into the corresponding body index, except when there is no entry, or
8683 -- in a Ravenscar-like profile.
8685 if Corresponding_Runtime_Package
(Pid
) =
8686 System_Tasking_Protected_Objects_Entries
8688 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8689 Insert_After
(Current_Node
, New_Op_Body
);
8690 Current_Node
:= New_Op_Body
;
8691 Analyze
(New_Op_Body
);
8694 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8695 -- protected body. At this point all wrapper specs have been created,
8696 -- frozen and included in the dispatch table for the protected type.
8698 if Ada_Version
>= Ada_2005
then
8699 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8701 end Expand_N_Protected_Body
;
8703 -----------------------------------------
8704 -- Expand_N_Protected_Type_Declaration --
8705 -----------------------------------------
8707 -- First we create a corresponding record type declaration used to
8708 -- represent values of this protected type.
8709 -- The general form of this type declaration is
8711 -- type poV (discriminants) is record
8712 -- _Object : aliased <kind>Protection
8713 -- [(<entry count> [, <handler count>])];
8714 -- [entry_family : array (bounds) of Void;]
8715 -- <private data fields>
8718 -- The discriminants are present only if the corresponding protected type
8719 -- has discriminants, and they exactly mirror the protected type
8720 -- discriminants. The private data fields similarly mirror the private
8721 -- declarations of the protected type.
8723 -- The Object field is always present. It contains RTS specific data used
8724 -- to control the protected object. It is declared as Aliased so that it
8725 -- can be passed as a pointer to the RTS. This allows the protected record
8726 -- to be referenced within RTS data structures. An appropriate Protection
8727 -- type and discriminant are generated.
8729 -- The Service field is present for protected objects with entries. It
8730 -- contains sufficient information to allow the entry service procedure for
8731 -- this object to be called when the object is not known till runtime.
8733 -- One entry_family component is present for each entry family in the
8734 -- task definition (see Expand_N_Task_Type_Declaration).
8736 -- When a protected object is declared, an instance of the protected type
8737 -- value record is created. The elaboration of this declaration creates the
8738 -- correct bounds for the entry families, and also evaluates the priority
8739 -- expression if needed. The initialization routine for the protected type
8740 -- itself then calls Initialize_Protection with appropriate parameters to
8741 -- initialize the value of the Task_Id field. Install_Handlers may be also
8742 -- called if a pragma Attach_Handler applies.
8744 -- Note: this record is passed to the subprograms created by the expansion
8745 -- of protected subprograms and entries. It is an in parameter to protected
8746 -- functions and an in out parameter to procedures and entry bodies. The
8747 -- Entity_Id for this created record type is placed in the
8748 -- Corresponding_Record_Type field of the associated protected type entity.
8750 -- Next we create a procedure specifications for protected subprograms and
8751 -- entry bodies. For each protected subprograms two subprograms are
8752 -- created, an unprotected and a protected version. The unprotected version
8753 -- is called from within other operations of the same protected object.
8755 -- We also build the call to register the procedure if a pragma
8756 -- Interrupt_Handler applies.
8758 -- A single subprogram is created to service all entry bodies; it has an
8759 -- additional boolean out parameter indicating that the previous entry call
8760 -- made by the current task was serviced immediately, i.e. not by proxy.
8761 -- The O parameter contains a pointer to a record object of the type
8762 -- described above. An untyped interface is used here to allow this
8763 -- procedure to be called in places where the type of the object to be
8764 -- serviced is not known. This must be done, for example, when a call that
8765 -- may have been requeued is cancelled; the corresponding object must be
8766 -- serviced, but which object that is not known till runtime.
8769 -- (O : System.Address; P : out Boolean);
8770 -- procedure pprocN (_object : in out poV);
8771 -- procedure pproc (_object : in out poV);
8772 -- function pfuncN (_object : poV);
8773 -- function pfunc (_object : poV);
8776 -- Note that this must come after the record type declaration, since
8777 -- the specs refer to this type.
8779 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8780 Loc
: constant Source_Ptr
:= Sloc
(N
);
8781 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8783 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8784 -- This flag indicates whether the lock free implementation is active
8786 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8787 -- This contains two lists; one for visible and one for private decls
8791 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8795 Comp_Id
: Entity_Id
;
8797 Current_Node
: Node_Id
:= N
;
8798 Entries_Aggr
: Node_Id
;
8799 Body_Id
: Entity_Id
;
8802 Object_Comp
: Node_Id
;
8804 procedure Check_Inlining
(Subp
: Entity_Id
);
8805 -- If the original operation has a pragma Inline, propagate the flag
8806 -- to the internal body, for possible inlining later on. The source
8807 -- operation is invisible to the back-end and is never actually called.
8809 procedure Expand_Entry_Declaration
(Comp
: Entity_Id
);
8810 -- Create the subprograms for the barrier and for the body, and append
8811 -- then to Entry_Bodies_Array.
8813 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8814 -- When compiling under the Ravenscar profile, private components must
8815 -- have a static size, or else a protected object will require heap
8816 -- allocation, violating the corresponding restriction. It is preferable
8817 -- to make this check here, because it provides a better error message
8818 -- than the back-end, which refers to the object as a whole.
8820 procedure Register_Handler
;
8821 -- For a protected operation that is an interrupt handler, add the
8822 -- freeze action that will register it as such.
8824 --------------------
8825 -- Check_Inlining --
8826 --------------------
8828 procedure Check_Inlining
(Subp
: Entity_Id
) is
8830 if Is_Inlined
(Subp
) then
8831 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8832 Set_Is_Inlined
(Subp
, False);
8836 ---------------------------------
8837 -- Check_Static_Component_Size --
8838 ---------------------------------
8840 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8841 Typ
: constant Entity_Id
:= Etype
(Comp
);
8845 if Is_Scalar_Type
(Typ
) then
8848 elsif Is_Array_Type
(Typ
) then
8849 return Compile_Time_Known_Bounds
(Typ
);
8851 elsif Is_Record_Type
(Typ
) then
8852 C
:= First_Component
(Typ
);
8853 while Present
(C
) loop
8854 if not Static_Component_Size
(C
) then
8863 -- Any other type will be checked by the back-end
8868 end Static_Component_Size
;
8870 ------------------------------
8871 -- Expand_Entry_Declaration --
8872 ------------------------------
8874 procedure Expand_Entry_Declaration
(Comp
: Entity_Id
) is
8879 E_Count
:= E_Count
+ 1;
8880 Comp_Id
:= Defining_Identifier
(Comp
);
8883 Make_Defining_Identifier
(Loc
,
8884 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
8886 Make_Subprogram_Declaration
(Loc
,
8888 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
8890 Insert_After
(Current_Node
, Sub
);
8893 -- Build wrapper procedure for pre/postconditions
8895 Build_PPC_Wrapper
(Comp_Id
, N
);
8897 Set_Protected_Body_Subprogram
8898 (Defining_Identifier
(Comp
),
8899 Defining_Unit_Name
(Specification
(Sub
)));
8901 Current_Node
:= Sub
;
8904 Make_Defining_Identifier
(Loc
,
8905 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
8907 Make_Subprogram_Declaration
(Loc
,
8909 Build_Barrier_Function_Specification
(Loc
, Bdef
));
8911 Insert_After
(Current_Node
, Sub
);
8913 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
8914 Set_Barrier_Function
(Comp_Id
, Bdef
);
8915 Set_Scope
(Bdef
, Scope
(Comp_Id
));
8916 Current_Node
:= Sub
;
8918 -- Collect pointers to the protected subprogram and the barrier
8919 -- of the current entry, for insertion into Entry_Bodies_Array.
8921 Append_To
(Expressions
(Entries_Aggr
),
8922 Make_Aggregate
(Loc
,
8923 Expressions
=> New_List
(
8924 Make_Attribute_Reference
(Loc
,
8925 Prefix
=> New_Reference_To
(Bdef
, Loc
),
8926 Attribute_Name
=> Name_Unrestricted_Access
),
8927 Make_Attribute_Reference
(Loc
,
8928 Prefix
=> New_Reference_To
(Edef
, Loc
),
8929 Attribute_Name
=> Name_Unrestricted_Access
))));
8930 end Expand_Entry_Declaration
;
8932 ----------------------
8933 -- Register_Handler --
8934 ----------------------
8936 procedure Register_Handler
is
8938 -- All semantic checks already done in Sem_Prag
8940 Prot_Proc
: constant Entity_Id
:=
8941 Defining_Unit_Name
(Specification
(Current_Node
));
8943 Proc_Address
: constant Node_Id
:=
8944 Make_Attribute_Reference
(Loc
,
8946 New_Reference_To
(Prot_Proc
, Loc
),
8947 Attribute_Name
=> Name_Address
);
8949 RTS_Call
: constant Entity_Id
:=
8950 Make_Procedure_Call_Statement
(Loc
,
8953 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8954 Parameter_Associations
=> New_List
(Proc_Address
));
8956 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8957 end Register_Handler
;
8959 -- Start of processing for Expand_N_Protected_Type_Declaration
8962 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8965 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8968 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8970 Qualify_Entity_Names
(N
);
8972 -- If the type has discriminants, their occurrences in the declaration
8973 -- have been replaced by the corresponding discriminals. For components
8974 -- that are constrained by discriminants, their homologues in the
8975 -- corresponding record type must refer to the discriminants of that
8976 -- record, so we must apply a new renaming to subtypes_indications:
8978 -- protected discriminant => discriminal => record discriminant
8980 -- This replacement is not applied to default expressions, for which
8981 -- the discriminal is correct.
8983 if Has_Discriminants
(Prot_Typ
) then
8989 Disc
:= First_Discriminant
(Prot_Typ
);
8990 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
8991 while Present
(Disc
) loop
8992 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
8993 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
8994 Next_Discriminant
(Disc
);
9000 -- Fill in the component declarations
9002 -- Add components for entry families. For each entry family, create an
9003 -- anonymous type declaration with the same size, and analyze the type.
9005 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9007 pragma Assert
(Present
(Pdef
));
9009 -- Add private field components
9011 if Present
(Private_Declarations
(Pdef
)) then
9012 Priv
:= First
(Private_Declarations
(Pdef
));
9013 while Present
(Priv
) loop
9014 if Nkind
(Priv
) = N_Component_Declaration
then
9015 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9017 -- When compiling for a restricted profile, the private
9018 -- components must have a static size. If not, this is an
9019 -- error for a single protected declaration, and rates a
9020 -- warning on a protected type declaration.
9022 if not Comes_From_Source
(Prot_Typ
) then
9023 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9025 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9026 Error_Msg_N
("component has non-static size??", Priv
);
9028 ("\creation of protected object of type& will violate"
9029 & " restriction No_Implicit_Heap_Allocations??",
9034 -- The component definition consists of a subtype indication,
9035 -- or (in Ada 2005) an access definition. Make a copy of the
9036 -- proper definition.
9039 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9040 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9042 Nent
: constant Entity_Id
:=
9043 Make_Defining_Identifier
(Sloc
(Oent
),
9044 Chars
=> Chars
(Oent
));
9047 if Present
(Subtype_Indication
(Old_Comp
)) then
9049 Make_Component_Definition
(Sloc
(Oent
),
9050 Aliased_Present
=> False,
9051 Subtype_Indication
=>
9052 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
9056 Make_Component_Definition
(Sloc
(Oent
),
9057 Aliased_Present
=> False,
9058 Access_Definition
=>
9059 New_Copy_Tree
(Access_Definition
(Old_Comp
),
9064 Make_Component_Declaration
(Loc
,
9065 Defining_Identifier
=> Nent
,
9066 Component_Definition
=> New_Comp
,
9067 Expression
=> Expression
(Priv
));
9069 Set_Has_Per_Object_Constraint
(Nent
,
9070 Has_Per_Object_Constraint
(Oent
));
9072 Append_To
(Cdecls
, New_Priv
);
9075 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9077 -- Make the unprotected version of the subprogram available
9078 -- for expansion of intra object calls. There is need for
9079 -- a protected version only if the subprogram is an interrupt
9080 -- handler, otherwise this operation can only be called from
9084 Make_Subprogram_Declaration
(Loc
,
9086 Build_Protected_Sub_Specification
9087 (Priv
, Prot_Typ
, Unprotected_Mode
));
9089 Insert_After
(Current_Node
, Sub
);
9092 Set_Protected_Body_Subprogram
9093 (Defining_Unit_Name
(Specification
(Priv
)),
9094 Defining_Unit_Name
(Specification
(Sub
)));
9095 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9096 Current_Node
:= Sub
;
9099 Make_Subprogram_Declaration
(Loc
,
9101 Build_Protected_Sub_Specification
9102 (Priv
, Prot_Typ
, Protected_Mode
));
9104 Insert_After
(Current_Node
, Sub
);
9106 Current_Node
:= Sub
;
9108 if Is_Interrupt_Handler
9109 (Defining_Unit_Name
(Specification
(Priv
)))
9111 if not Restricted_Profile
then
9121 -- Except for the lock-free implementation, append the _Object field
9122 -- with the right type to the component list. We need to compute the
9123 -- number of entries, and in some cases the number of Attach_Handler
9126 if not Lock_Free_Active
then
9129 Num_Attach_Handler
: Int
:= 0;
9130 Protection_Subtype
: Node_Id
;
9131 Entry_Count_Expr
: constant Node_Id
:=
9132 Build_Entry_Count_Expression
9133 (Prot_Typ
, Cdecls
, Loc
);
9136 if Has_Attach_Handler
(Prot_Typ
) then
9137 Ritem
:= First_Rep_Item
(Prot_Typ
);
9138 while Present
(Ritem
) loop
9139 if Nkind
(Ritem
) = N_Pragma
9140 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9142 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9145 Next_Rep_Item
(Ritem
);
9149 -- Determine the proper protection type. There are two special
9150 -- cases: 1) when the protected type has dynamic interrupt
9151 -- handlers, and 2) when it has static handlers and we use a
9152 -- restricted profile.
9154 if Has_Attach_Handler
(Prot_Typ
)
9155 and then not Restricted_Profile
9157 Protection_Subtype
:=
9158 Make_Subtype_Indication
(Loc
,
9161 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9163 Make_Index_Or_Discriminant_Constraint
(Loc
,
9164 Constraints
=> New_List
(
9166 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9168 elsif Has_Interrupt_Handler
(Prot_Typ
)
9169 and then not Restriction_Active
(No_Dynamic_Attachment
)
9171 Protection_Subtype
:=
9172 Make_Subtype_Indication
(Loc
,
9175 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9177 Make_Index_Or_Discriminant_Constraint
(Loc
,
9178 Constraints
=> New_List
(Entry_Count_Expr
)));
9181 case Corresponding_Runtime_Package
(Prot_Typ
) is
9182 when System_Tasking_Protected_Objects_Entries
=>
9183 Protection_Subtype
:=
9184 Make_Subtype_Indication
(Loc
,
9187 (RTE
(RE_Protection_Entries
), Loc
),
9189 Make_Index_Or_Discriminant_Constraint
(Loc
,
9190 Constraints
=> New_List
(Entry_Count_Expr
)));
9192 when System_Tasking_Protected_Objects_Single_Entry
=>
9193 Protection_Subtype
:=
9194 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
9196 when System_Tasking_Protected_Objects
=>
9197 Protection_Subtype
:=
9198 New_Reference_To
(RTE
(RE_Protection
), Loc
);
9201 raise Program_Error
;
9206 Make_Component_Declaration
(Loc
,
9207 Defining_Identifier
=>
9208 Make_Defining_Identifier
(Loc
, Name_uObject
),
9209 Component_Definition
=>
9210 Make_Component_Definition
(Loc
,
9211 Aliased_Present
=> True,
9212 Subtype_Indication
=> Protection_Subtype
));
9215 -- Put the _Object component after the private component so that it
9216 -- be finalized early as required by 9.4 (20)
9218 Append_To
(Cdecls
, Object_Comp
);
9221 Insert_After
(Current_Node
, Rec_Decl
);
9222 Current_Node
:= Rec_Decl
;
9224 -- Analyze the record declaration immediately after construction,
9225 -- because the initialization procedure is needed for single object
9226 -- declarations before the next entity is analyzed (the freeze call
9227 -- that generates this initialization procedure is found below).
9229 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9231 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9232 -- the corresponding record is frozen. If any wrappers are generated,
9233 -- Current_Node is updated accordingly.
9235 if Ada_Version
>= Ada_2005
then
9236 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9239 -- Collect pointers to entry bodies and their barriers, to be placed
9240 -- in the Entry_Bodies_Array for the type. For each entry/family we
9241 -- add an expression to the aggregate which is the initial value of
9242 -- this array. The array is declared after all protected subprograms.
9244 if Has_Entries
(Prot_Typ
) then
9245 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9247 Entries_Aggr
:= Empty
;
9250 -- Build two new procedure specifications for each protected subprogram;
9251 -- one to call from outside the object and one to call from inside.
9252 -- Build a barrier function and an entry body action procedure
9253 -- specification for each protected entry. Initialize the entry body
9254 -- array. If subprogram is flagged as eliminated, do not generate any
9255 -- internal operations.
9258 Comp
:= First
(Visible_Declarations
(Pdef
));
9259 while Present
(Comp
) loop
9260 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9262 Make_Subprogram_Declaration
(Loc
,
9264 Build_Protected_Sub_Specification
9265 (Comp
, Prot_Typ
, Unprotected_Mode
));
9267 Insert_After
(Current_Node
, Sub
);
9270 Set_Protected_Body_Subprogram
9271 (Defining_Unit_Name
(Specification
(Comp
)),
9272 Defining_Unit_Name
(Specification
(Sub
)));
9273 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9275 -- Make the protected version of the subprogram available for
9276 -- expansion of external calls.
9278 Current_Node
:= Sub
;
9281 Make_Subprogram_Declaration
(Loc
,
9283 Build_Protected_Sub_Specification
9284 (Comp
, Prot_Typ
, Protected_Mode
));
9286 Insert_After
(Current_Node
, Sub
);
9289 Current_Node
:= Sub
;
9291 -- Generate an overriding primitive operation specification for
9292 -- this subprogram if the protected type implements an interface.
9294 if Ada_Version
>= Ada_2005
9296 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9299 Make_Subprogram_Declaration
(Loc
,
9301 Build_Protected_Sub_Specification
9302 (Comp
, Prot_Typ
, Dispatching_Mode
));
9304 Insert_After
(Current_Node
, Sub
);
9307 Current_Node
:= Sub
;
9310 -- If a pragma Interrupt_Handler applies, build and add a call to
9311 -- Register_Interrupt_Handler to the freezing actions of the
9312 -- protected version (Current_Node) of the subprogram:
9314 -- system.interrupts.register_interrupt_handler
9315 -- (prot_procP'address);
9317 if not Restricted_Profile
9318 and then Is_Interrupt_Handler
9319 (Defining_Unit_Name
(Specification
(Comp
)))
9324 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9326 Expand_Entry_Declaration
(Comp
);
9333 -- If there are some private entry declarations, expand it as if they
9334 -- were visible entries.
9336 if Present
(Private_Declarations
(Pdef
)) then
9337 Comp
:= First
(Private_Declarations
(Pdef
));
9338 while Present
(Comp
) loop
9339 if Nkind
(Comp
) = N_Entry_Declaration
then
9340 Expand_Entry_Declaration
(Comp
);
9347 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9348 -- all protected subprograms have been collected.
9350 if Has_Entries
(Prot_Typ
) then
9352 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9353 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9355 case Corresponding_Runtime_Package
(Prot_Typ
) is
9356 when System_Tasking_Protected_Objects_Entries
=>
9357 Body_Arr
:= Make_Object_Declaration
(Loc
,
9358 Defining_Identifier
=> Body_Id
,
9359 Aliased_Present
=> True,
9360 Object_Definition
=>
9361 Make_Subtype_Indication
(Loc
,
9362 Subtype_Mark
=> New_Reference_To
(
9363 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9365 Make_Index_Or_Discriminant_Constraint
(Loc
,
9366 Constraints
=> New_List
(
9368 Make_Integer_Literal
(Loc
, 1),
9369 Make_Integer_Literal
(Loc
, E_Count
))))),
9370 Expression
=> Entries_Aggr
);
9372 when System_Tasking_Protected_Objects_Single_Entry
=>
9373 Body_Arr
:= Make_Object_Declaration
(Loc
,
9374 Defining_Identifier
=> Body_Id
,
9375 Aliased_Present
=> True,
9376 Object_Definition
=> New_Reference_To
9377 (RTE
(RE_Entry_Body
), Loc
),
9378 Expression
=> Remove_Head
(Expressions
(Entries_Aggr
)));
9381 raise Program_Error
;
9384 -- A pointer to this array will be placed in the corresponding record
9385 -- by its initialization procedure so this needs to be analyzed here.
9387 Insert_After
(Current_Node
, Body_Arr
);
9388 Current_Node
:= Body_Arr
;
9391 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9393 -- Finally, build the function that maps an entry index into the
9394 -- corresponding body. A pointer to this function is placed in each
9395 -- object of the type. Except for a ravenscar-like profile (no abort,
9396 -- no entry queue, 1 entry)
9398 if Corresponding_Runtime_Package
(Prot_Typ
) =
9399 System_Tasking_Protected_Objects_Entries
9402 Make_Subprogram_Declaration
(Loc
,
9403 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9404 Insert_After
(Current_Node
, Sub
);
9408 end Expand_N_Protected_Type_Declaration
;
9410 --------------------------------
9411 -- Expand_N_Requeue_Statement --
9412 --------------------------------
9414 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9415 -- operations, depending on the source and destination (task or protected
9416 -- object). A dispatching requeue statement is expanded into a call to the
9417 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9418 -- jump around the remainder of processing for the original entry and, if
9419 -- the destination is (different) protected object, to attempt to service
9420 -- it. The following illustrates the various cases:
9423 -- (O : System.Address;
9424 -- P : System.Address;
9425 -- E : Protected_Entry_Index)
9427 -- <discriminant renamings>
9428 -- <private object renamings>
9429 -- type poVP is access poV;
9430 -- _object : ptVP := ptVP!(O);
9434 -- <start of statement sequence for entry>
9436 -- -- Requeue from one protected entry body to another protected
9439 -- Requeue_Protected_Entry (
9440 -- _object._object'Access,
9441 -- new._object'Access,
9446 -- <some more of the statement sequence for entry>
9448 -- -- Requeue from an entry body to a task entry
9450 -- Requeue_Protected_To_Task_Entry (
9456 -- <rest of statement sequence for entry>
9457 -- Complete_Entry_Body (_object._object);
9460 -- when all others =>
9461 -- Exceptional_Complete_Entry_Body (
9462 -- _object._object, Get_GNAT_Exception);
9466 -- Requeue of a task entry call to a task entry
9468 -- Accept_Call (E, Ann);
9469 -- <start of statement sequence for accept statement>
9470 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9472 -- <rest of statement sequence for accept statement>
9474 -- Complete_Rendezvous;
9477 -- when all others =>
9478 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9480 -- Requeue of a task entry call to a protected entry
9482 -- Accept_Call (E, Ann);
9483 -- <start of statement sequence for accept statement>
9484 -- Requeue_Task_To_Protected_Entry (
9485 -- new._object'Access,
9490 -- <rest of statement sequence for accept statement>
9492 -- Complete_Rendezvous;
9495 -- when all others =>
9496 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9498 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9499 -- marked by pragma Implemented (XXX, By_Entry).
9501 -- The requeue is inside a protected entry:
9504 -- (O : System.Address;
9505 -- P : System.Address;
9506 -- E : Protected_Entry_Index)
9508 -- <discriminant renamings>
9509 -- <private object renamings>
9510 -- type poVP is access poV;
9511 -- _object : ptVP := ptVP!(O);
9515 -- <start of statement sequence for entry>
9518 -- (<interface class-wide object>,
9521 -- Ada.Tags.Get_Offset_Index
9523 -- <interface dispatch table index of target entry>),
9527 -- <rest of statement sequence for entry>
9528 -- Complete_Entry_Body (_object._object);
9531 -- when all others =>
9532 -- Exceptional_Complete_Entry_Body (
9533 -- _object._object, Get_GNAT_Exception);
9537 -- The requeue is inside a task entry:
9539 -- Accept_Call (E, Ann);
9540 -- <start of statement sequence for accept statement>
9542 -- (<interface class-wide object>,
9545 -- Ada.Tags.Get_Offset_Index
9547 -- <interface dispatch table index of target entrt>),
9551 -- <rest of statement sequence for accept statement>
9553 -- Complete_Rendezvous;
9556 -- when all others =>
9557 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9559 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9560 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9561 -- statement is replaced by a dispatching call with actual parameters taken
9562 -- from the inner-most accept statement or entry body.
9564 -- Target.Primitive (Param1, ..., ParamN);
9566 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9567 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9571 -- S : constant Offset_Index :=
9572 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9573 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9576 -- if C = POK_Protected_Entry
9577 -- or else C = POK_Task_Entry
9579 -- <statements for dispatching requeue>
9581 -- elsif C = POK_Protected_Procedure then
9582 -- <dispatching call equivalent>
9585 -- raise Program_Error;
9589 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9590 Loc
: constant Source_Ptr
:= Sloc
(N
);
9591 Conc_Typ
: Entity_Id
;
9595 Old_Typ
: Entity_Id
;
9597 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9598 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9599 -- the form Concval.Ename. It is statically known that Ename is allowed
9600 -- to be implemented by a protected procedure. Create a dispatching call
9601 -- equivalent of Concval.Ename taking the actual parameters from the
9602 -- inner-most accept statement or entry body.
9604 function Build_Dispatching_Requeue
return Node_Id
;
9605 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9606 -- the form Concval.Ename. It is statically known that Ename is allowed
9607 -- to be implemented by a protected or a task entry. Create a call to
9608 -- primitive _Disp_Requeue which handles the low-level actions.
9610 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9611 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9612 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9613 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9614 -- determines at runtime whether Ename denotes an entry or a procedure
9615 -- and perform the appropriate kind of dispatching select.
9617 function Build_Normal_Requeue
return Node_Id
;
9618 -- N denotes a non-dispatching requeue statement to either a task or a
9619 -- protected entry. Build the appropriate runtime call to perform the
9622 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9623 -- For a protected entry, create a return statement to skip the rest of
9624 -- the entry body. Otherwise, create a goto statement to skip the rest
9625 -- of a task accept statement. The lookup for the enclosing entry body
9626 -- or accept statement starts from Search.
9628 ---------------------------------------
9629 -- Build_Dispatching_Call_Equivalent --
9630 ---------------------------------------
9632 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9633 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9634 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9641 -- Climb the parent chain looking for the inner-most entry body or
9642 -- accept statement.
9645 while Present
(Acc_Ent
)
9646 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9649 Acc_Ent
:= Parent
(Acc_Ent
);
9652 -- A requeue statement should be housed inside an entry body or an
9653 -- accept statement at some level. If this is not the case, then the
9654 -- tree is malformed.
9656 pragma Assert
(Present
(Acc_Ent
));
9658 -- Recover the list of formal parameters
9660 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9661 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9664 Formals
:= Parameter_Specifications
(Acc_Ent
);
9666 -- Create the actual parameters for the dispatching call. These are
9667 -- simply copies of the entry body or accept statement formals in the
9668 -- same order as they appear.
9672 if Present
(Formals
) then
9673 Actuals
:= New_List
;
9674 Formal
:= First
(Formals
);
9675 while Present
(Formal
) loop
9677 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9683 -- Obj.Call_Ent (Actuals);
9686 Make_Procedure_Call_Statement
(Loc
,
9688 Make_Selected_Component
(Loc
,
9689 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9690 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9692 Parameter_Associations
=> Actuals
);
9693 end Build_Dispatching_Call_Equivalent
;
9695 -------------------------------
9696 -- Build_Dispatching_Requeue --
9697 -------------------------------
9699 function Build_Dispatching_Requeue
return Node_Id
is
9700 Params
: constant List_Id
:= New_List
;
9703 -- Process the "with abort" parameter
9706 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9708 -- Process the entry wrapper's position in the primary dispatch
9709 -- table parameter. Generate:
9711 -- Ada.Tags.Get_Entry_Index
9712 -- (T => To_Tag_Ptr (Obj'Address).all,
9714 -- Ada.Tags.Get_Offset_Index
9715 -- (Ada.Tags.Tag (Concval),
9716 -- <interface dispatch table position of Ename>));
9718 -- Note that Obj'Address is recursively expanded into a call to
9719 -- Base_Address (Obj).
9721 if Tagged_Type_Expansion
then
9723 Make_Function_Call
(Loc
,
9724 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9725 Parameter_Associations
=> New_List
(
9727 Make_Explicit_Dereference
(Loc
,
9728 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9729 Make_Attribute_Reference
(Loc
,
9730 Prefix
=> New_Copy_Tree
(Concval
),
9731 Attribute_Name
=> Name_Address
))),
9733 Make_Function_Call
(Loc
,
9734 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9735 Parameter_Associations
=> New_List
(
9736 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9737 Make_Integer_Literal
(Loc
,
9738 DT_Position
(Entity
(Ename
))))))));
9744 Make_Function_Call
(Loc
,
9745 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9746 Parameter_Associations
=> New_List
(
9748 Make_Attribute_Reference
(Loc
,
9750 Attribute_Name
=> Name_Tag
),
9752 Make_Function_Call
(Loc
,
9753 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9755 Parameter_Associations
=> New_List
(
9759 Make_Attribute_Reference
(Loc
,
9761 Attribute_Name
=> Name_Tag
),
9765 Make_Attribute_Reference
(Loc
,
9766 Prefix
=> New_Reference_To
(Etype
(Concval
), Loc
),
9767 Attribute_Name
=> Name_Tag
),
9771 Make_Integer_Literal
(Loc
,
9772 DT_Position
(Entity
(Ename
))))))));
9775 -- Specific actuals for protected to XXX requeue
9777 if Is_Protected_Type
(Old_Typ
) then
9779 Make_Attribute_Reference
(Loc
, -- _object'Address
9781 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9782 Attribute_Name
=> Name_Address
));
9784 Prepend_To
(Params
, -- True
9785 New_Reference_To
(Standard_True
, Loc
));
9787 -- Specific actuals for task to XXX requeue
9790 pragma Assert
(Is_Task_Type
(Old_Typ
));
9792 Prepend_To
(Params
, -- null
9793 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
9795 Prepend_To
(Params
, -- False
9796 New_Reference_To
(Standard_False
, Loc
));
9799 -- Add the object parameter
9801 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9804 -- _Disp_Requeue (<Params>);
9806 -- Find entity for Disp_Requeue operation, which belongs to
9807 -- the type and may not be directly visible.
9814 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9815 while Present
(Elmt
) loop
9817 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9822 Make_Procedure_Call_Statement
(Loc
,
9823 Name
=> New_Occurrence_Of
(Op
, Loc
),
9824 Parameter_Associations
=> Params
);
9826 end Build_Dispatching_Requeue
;
9828 --------------------------------------
9829 -- Build_Dispatching_Requeue_To_Any --
9830 --------------------------------------
9832 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9833 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9834 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9835 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
9845 -- Dispatch table slot processing, generate:
9848 S
:= Build_S
(Loc
, Decls
);
9850 -- Call kind processing, generate:
9851 -- C : Ada.Tags.Prim_Op_Kind;
9853 C
:= Build_C
(Loc
, Decls
);
9856 -- S := Ada.Tags.Get_Offset_Index
9857 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9859 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
9862 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9865 Make_Procedure_Call_Statement
(Loc
,
9868 Find_Prim_Op
(Etype
(Etype
(Obj
)),
9869 Name_uDisp_Get_Prim_Op_Kind
),
9871 Parameter_Associations
=> New_List
(
9872 New_Copy_Tree
(Obj
),
9873 New_Reference_To
(S
, Loc
),
9874 New_Reference_To
(C
, Loc
))));
9878 -- if C = POK_Protected_Entry
9879 -- or else C = POK_Task_Entry
9882 Make_Implicit_If_Statement
(N
,
9888 New_Reference_To
(C
, Loc
),
9890 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
9895 New_Reference_To
(C
, Loc
),
9897 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
9899 -- Dispatching requeue equivalent
9901 Then_Statements
=> New_List
(
9902 Build_Dispatching_Requeue
,
9905 -- elsif C = POK_Protected_Procedure then
9907 Elsif_Parts
=> New_List
(
9908 Make_Elsif_Part
(Loc
,
9912 New_Reference_To
(C
, Loc
),
9915 RTE
(RE_POK_Protected_Procedure
), Loc
)),
9917 -- Dispatching call equivalent
9919 Then_Statements
=> New_List
(
9920 Build_Dispatching_Call_Equivalent
))),
9923 -- raise Program_Error;
9926 Else_Statements
=> New_List
(
9927 Make_Raise_Program_Error
(Loc
,
9928 Reason
=> PE_Explicit_Raise
))));
9930 -- Wrap everything into a block
9933 Make_Block_Statement
(Loc
,
9934 Declarations
=> Decls
,
9935 Handled_Statement_Sequence
=>
9936 Make_Handled_Sequence_Of_Statements
(Loc
,
9937 Statements
=> Stmts
));
9938 end Build_Dispatching_Requeue_To_Any
;
9940 --------------------------
9941 -- Build_Normal_Requeue --
9942 --------------------------
9944 function Build_Normal_Requeue
return Node_Id
is
9945 Params
: constant List_Id
:= New_List
;
9950 -- Process the "with abort" parameter
9953 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9955 -- Add the index expression to the parameters. It is common among all
9959 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
9961 if Is_Protected_Type
(Old_Typ
) then
9963 Self_Param
: Node_Id
;
9967 Make_Attribute_Reference
(Loc
,
9969 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9971 Name_Unchecked_Access
);
9973 -- Protected to protected requeue
9975 if Is_Protected_Type
(Conc_Typ
) then
9978 RTE
(RE_Requeue_Protected_Entry
), Loc
);
9981 Make_Attribute_Reference
(Loc
,
9983 Concurrent_Ref
(Concval
),
9985 Name_Unchecked_Access
);
9987 -- Protected to task requeue
9989 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9992 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
9994 Param
:= Concurrent_Ref
(Concval
);
9997 Prepend_To
(Params
, Param
);
9998 Prepend_To
(Params
, Self_Param
);
10001 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10003 -- Task to protected requeue
10005 if Is_Protected_Type
(Conc_Typ
) then
10008 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10011 Make_Attribute_Reference
(Loc
,
10013 Concurrent_Ref
(Concval
),
10015 Name_Unchecked_Access
);
10017 -- Task to task requeue
10019 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10021 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10023 Param
:= Concurrent_Ref
(Concval
);
10026 Prepend_To
(Params
, Param
);
10030 Make_Procedure_Call_Statement
(Loc
,
10032 Parameter_Associations
=> Params
);
10033 end Build_Normal_Requeue
;
10035 --------------------------
10036 -- Build_Skip_Statement --
10037 --------------------------
10039 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10040 Skip_Stmt
: Node_Id
;
10043 -- Build a return statement to skip the rest of the entire body
10045 if Is_Protected_Type
(Old_Typ
) then
10046 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10048 -- If the requeue is within a task, find the end label of the
10049 -- enclosing accept statement and create a goto statement to it.
10057 -- Climb the parent chain looking for the enclosing accept
10060 Acc
:= Parent
(Search
);
10061 while Present
(Acc
)
10062 and then Nkind
(Acc
) /= N_Accept_Statement
10064 Acc
:= Parent
(Acc
);
10067 -- The last statement is the second label used for completing
10068 -- the rendezvous the usual way. The label we are looking for
10069 -- is right before it.
10072 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10074 pragma Assert
(Nkind
(Label
) = N_Label
);
10076 -- Generate a goto statement to skip the rest of the accept
10079 Make_Goto_Statement
(Loc
,
10081 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10085 Set_Analyzed
(Skip_Stmt
);
10088 end Build_Skip_Statement
;
10090 -- Start of processing for Expand_N_Requeue_Statement
10093 -- Extract the components of the entry call
10095 Extract_Entry
(N
, Concval
, Ename
, Index
);
10096 Conc_Typ
:= Etype
(Concval
);
10098 -- If the prefix is an access to class-wide type, dereference to get
10099 -- object and entry type.
10101 if Is_Access_Type
(Conc_Typ
) then
10102 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10104 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10105 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10108 -- Examine the scope stack in order to find nearest enclosing protected
10109 -- or task type. This will constitute our invocation source.
10111 Old_Typ
:= Current_Scope
;
10112 while Present
(Old_Typ
)
10113 and then not Is_Protected_Type
(Old_Typ
)
10114 and then not Is_Task_Type
(Old_Typ
)
10116 Old_Typ
:= Scope
(Old_Typ
);
10119 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10120 -- Concval.Ename where the type of Concval is class-wide concurrent
10123 if Ada_Version
>= Ada_2012
10124 and then Present
(Concval
)
10125 and then Is_Class_Wide_Type
(Conc_Typ
)
10126 and then Is_Concurrent_Interface
(Conc_Typ
)
10129 Has_Impl
: Boolean := False;
10130 Impl_Kind
: Name_Id
:= No_Name
;
10133 -- Check whether the Ename is flagged by pragma Implemented
10135 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10137 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10140 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10141 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10144 and then Impl_Kind
= Name_By_Entry
10146 Rewrite
(N
, Build_Dispatching_Requeue
);
10148 Insert_After
(N
, Build_Skip_Statement
(N
));
10150 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10151 -- a protected procedure. In this case the requeue is transformed
10152 -- into a dispatching call.
10155 and then Impl_Kind
= Name_By_Protected_Procedure
10157 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10160 -- The procedure_or_entry_NAME's implementation kind is either
10161 -- By_Any, Optional, or pragma Implemented was not applied at all.
10162 -- In this case a runtime test determines whether Ename denotes an
10163 -- entry or a protected procedure and performs the appropriate
10167 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10172 -- Processing for regular (non-dispatching) requeues
10175 Rewrite
(N
, Build_Normal_Requeue
);
10177 Insert_After
(N
, Build_Skip_Statement
(N
));
10179 end Expand_N_Requeue_Statement
;
10181 -------------------------------
10182 -- Expand_N_Selective_Accept --
10183 -------------------------------
10185 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10186 Loc
: constant Source_Ptr
:= Sloc
(N
);
10187 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10189 -- Note: in the below declarations a lot of new lists are allocated
10190 -- unconditionally which may well not end up being used. That's not
10191 -- a good idea since it wastes space gratuitously ???
10193 Accept_Case
: List_Id
;
10194 Accept_List
: constant List_Id
:= New_List
;
10197 Alt_List
: constant List_Id
:= New_List
;
10198 Alt_Stats
: List_Id
;
10199 Ann
: Entity_Id
:= Empty
;
10201 Check_Guard
: Boolean := True;
10203 Decls
: constant List_Id
:= New_List
;
10204 Stats
: constant List_Id
:= New_List
;
10205 Body_List
: constant List_Id
:= New_List
;
10206 Trailing_List
: constant List_Id
:= New_List
;
10209 Else_Present
: Boolean := False;
10210 Terminate_Alt
: Node_Id
:= Empty
;
10211 Select_Mode
: Node_Id
;
10213 Delay_Case
: List_Id
;
10214 Delay_Count
: Integer := 0;
10215 Delay_Val
: Entity_Id
;
10216 Delay_Index
: Entity_Id
;
10217 Delay_Min
: Entity_Id
;
10218 Delay_Num
: Int
:= 1;
10219 Delay_Alt_List
: List_Id
:= New_List
;
10220 Delay_List
: constant List_Id
:= New_List
;
10224 First_Delay
: Boolean := True;
10225 Guard_Open
: Entity_Id
;
10231 Num_Accept
: Nat
:= 0;
10233 Time_Type
: Entity_Id
;
10234 Select_Call
: Node_Id
;
10236 Qnam
: constant Entity_Id
:=
10237 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10239 Xnam
: constant Entity_Id
:=
10240 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10242 -----------------------
10243 -- Local subprograms --
10244 -----------------------
10246 function Accept_Or_Raise
return List_Id
;
10247 -- For the rare case where delay alternatives all have guards, and
10248 -- all of them are closed, it is still possible that there were open
10249 -- accept alternatives with no callers. We must reexamine the
10250 -- Accept_List, and execute a selective wait with no else if some
10251 -- accept is open. If none, we raise program_error.
10253 procedure Add_Accept
(Alt
: Node_Id
);
10254 -- Process a single accept statement in a select alternative. Build
10255 -- procedure for body of accept, and add entry to dispatch table with
10256 -- expression for guard, in preparation for call to run time select.
10258 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10259 -- Manufacture a label using Num as a serial number and declare it.
10260 -- The declaration is appended to Decls. The label marks the trailing
10261 -- statements of an accept or delay alternative.
10263 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10264 -- Build call to Selective_Wait runtime routine
10266 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10267 -- Add code to compare value of delay with previous values, and
10268 -- generate case entry for trailing statements.
10270 procedure Process_Accept_Alternative
10274 -- Add code to call corresponding procedure, and branch to
10275 -- trailing statements, if any.
10277 ---------------------
10278 -- Accept_Or_Raise --
10279 ---------------------
10281 function Accept_Or_Raise
return List_Id
is
10284 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10287 -- We generate the following:
10289 -- for J in q'range loop
10290 -- if q(J).S /=null_task_entry then
10291 -- selective_wait (simple_mode,...);
10297 -- if no rendez_vous then
10298 -- raise program_error;
10301 -- Note that the code needs to know that the selector name
10302 -- in an Accept_Alternative is named S.
10304 Cond
:= Make_Op_Ne
(Loc
,
10306 Make_Selected_Component
(Loc
,
10308 Make_Indexed_Component
(Loc
,
10309 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10310 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
10311 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10313 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
10315 Stats
:= New_List
(
10316 Make_Implicit_Loop_Statement
(N
,
10317 Iteration_Scheme
=>
10318 Make_Iteration_Scheme
(Loc
,
10319 Loop_Parameter_Specification
=>
10320 Make_Loop_Parameter_Specification
(Loc
,
10321 Defining_Identifier
=> J
,
10322 Discrete_Subtype_Definition
=>
10323 Make_Attribute_Reference
(Loc
,
10324 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10325 Attribute_Name
=> Name_Range
,
10326 Expressions
=> New_List
(
10327 Make_Integer_Literal
(Loc
, 1))))),
10329 Statements
=> New_List
(
10330 Make_Implicit_If_Statement
(N
,
10332 Then_Statements
=> New_List
(
10334 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
10335 Make_Exit_Statement
(Loc
))))));
10338 Make_Raise_Program_Error
(Loc
,
10339 Condition
=> Make_Op_Eq
(Loc
,
10340 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
10342 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
10343 Reason
=> PE_All_Guards_Closed
));
10346 end Accept_Or_Raise
;
10352 procedure Add_Accept
(Alt
: Node_Id
) is
10353 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10354 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10355 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10356 Eent
: constant Entity_Id
:= Entity
(Ename
);
10357 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10358 Null_Body
: Node_Id
;
10359 Proc_Body
: Node_Id
;
10360 PB_Ent
: Entity_Id
;
10366 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10369 if Present
(Condition
(Alt
)) then
10371 Make_If_Expression
(Eloc
, New_List
(
10373 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10374 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10377 Entry_Index_Expression
10378 (Eloc
, Eent
, Index
, Scope
(Eent
));
10381 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10382 Null_Body
:= New_Reference_To
(Standard_False
, Eloc
);
10384 -- Always add call to Abort_Undefer when generating code, since
10385 -- this is what the runtime expects (abort deferred in
10386 -- Selective_Wait). In CodePeer mode this only confuses the
10387 -- analysis with unknown calls, so don't do it.
10389 if not CodePeer_Mode
then
10391 Make_Procedure_Call_Statement
(Eloc
,
10392 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Eloc
));
10394 (First
(Statements
(Handled_Statement_Sequence
10395 (Accept_Statement
(Alt
)))),
10401 Make_Defining_Identifier
(Eloc
,
10402 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10404 if Comes_From_Source
(Alt
) then
10405 Set_Debug_Info_Needed
(PB_Ent
);
10409 Make_Subprogram_Body
(Eloc
,
10411 Make_Procedure_Specification
(Eloc
,
10412 Defining_Unit_Name
=> PB_Ent
),
10413 Declarations
=> Declarations
(Acc_Stm
),
10414 Handled_Statement_Sequence
=>
10415 Build_Accept_Body
(Accept_Statement
(Alt
)));
10417 -- During the analysis of the body of the accept statement, any
10418 -- zero cost exception handler records were collected in the
10419 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10420 -- This is where we move them to where they belong, namely the
10421 -- newly created procedure.
10423 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10424 Append
(Proc_Body
, Body_List
);
10427 Null_Body
:= New_Reference_To
(Standard_True
, Eloc
);
10429 -- if accept statement has declarations, insert above, given that
10430 -- we are not creating a body for the accept.
10432 if Present
(Declarations
(Acc_Stm
)) then
10433 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10437 Append_To
(Accept_List
,
10438 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10440 Num_Accept
:= Num_Accept
+ 1;
10443 ----------------------------
10444 -- Make_And_Declare_Label --
10445 ----------------------------
10447 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10451 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10453 Make_Label
(Loc
, Lab_Id
);
10456 Make_Implicit_Label_Declaration
(Loc
,
10457 Defining_Identifier
=>
10458 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10459 Label_Construct
=> Lab
));
10462 end Make_And_Declare_Label
;
10464 ----------------------
10465 -- Make_Select_Call --
10466 ----------------------
10468 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10469 Params
: constant List_Id
:= New_List
;
10473 Make_Attribute_Reference
(Loc
,
10474 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10475 Attribute_Name
=> Name_Unchecked_Access
),
10477 Append
(Select_Mode
, Params
);
10478 Append
(New_Reference_To
(Ann
, Loc
), Params
);
10479 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
10482 Make_Procedure_Call_Statement
(Loc
,
10483 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
10484 Parameter_Associations
=> Params
);
10485 end Make_Select_Call
;
10487 --------------------------------
10488 -- Process_Accept_Alternative --
10489 --------------------------------
10491 procedure Process_Accept_Alternative
10496 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10497 Alt_Stats
: List_Id
;
10500 Adjust_Condition
(Condition
(Alt
));
10502 -- Accept with body
10504 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10507 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10510 (Defining_Unit_Name
(Specification
(Proc
)),
10513 -- Accept with no body (followed by trailing statements)
10516 Alt_Stats
:= Empty_List
;
10519 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10521 -- After the call, if any, branch to trailing statements, if any.
10522 -- We create a label for each, as well as the corresponding label
10525 if not Is_Empty_List
(Statements
(Alt
)) then
10526 Lab
:= Make_And_Declare_Label
(Index
);
10527 Append
(Lab
, Trailing_List
);
10528 Append_List
(Statements
(Alt
), Trailing_List
);
10529 Append_To
(Trailing_List
,
10530 Make_Goto_Statement
(Loc
,
10531 Name
=> New_Copy
(Identifier
(End_Lab
))));
10537 Append_To
(Alt_Stats
,
10538 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10540 Append_To
(Alt_List
,
10541 Make_Case_Statement_Alternative
(Loc
,
10542 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10543 Statements
=> Alt_Stats
));
10544 end Process_Accept_Alternative
;
10546 -------------------------------
10547 -- Process_Delay_Alternative --
10548 -------------------------------
10550 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10551 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10553 Delay_Alt
: List_Id
;
10556 -- Deal with C/Fortran boolean as delay condition
10558 Adjust_Condition
(Condition
(Alt
));
10560 -- Determine the smallest specified delay
10562 -- for each delay alternative generate:
10564 -- if guard-expression then
10565 -- Delay_Val := delay-expression;
10566 -- Guard_Open := True;
10567 -- if Delay_Val < Delay_Min then
10568 -- Delay_Min := Delay_Val;
10569 -- Delay_Index := Index;
10573 -- The enclosing if-statement is omitted if there is no guard
10575 if Delay_Count
= 1 or else First_Delay
then
10576 First_Delay
:= False;
10578 Delay_Alt
:= New_List
(
10579 Make_Assignment_Statement
(Loc
,
10580 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10581 Expression
=> Expression
(Delay_Statement
(Alt
))));
10583 if Delay_Count
> 1 then
10584 Append_To
(Delay_Alt
,
10585 Make_Assignment_Statement
(Loc
,
10586 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10587 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10591 Delay_Alt
:= New_List
(
10592 Make_Assignment_Statement
(Loc
,
10593 Name
=> New_Reference_To
(Delay_Val
, Loc
),
10594 Expression
=> Expression
(Delay_Statement
(Alt
))));
10596 if Time_Type
= Standard_Duration
then
10599 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
10600 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
10603 -- The scope of the time type must define a comparison
10604 -- operator. The scope itself may not be visible, so we
10605 -- construct a node with entity information to insure that
10606 -- semantic analysis can find the proper operator.
10609 Make_Function_Call
(Loc
,
10610 Name
=> Make_Selected_Component
(Loc
,
10612 New_Reference_To
(Scope
(Time_Type
), Loc
),
10614 Make_Operator_Symbol
(Loc
,
10615 Chars
=> Name_Op_Lt
,
10616 Strval
=> No_String
)),
10617 Parameter_Associations
=>
10619 New_Reference_To
(Delay_Val
, Loc
),
10620 New_Reference_To
(Delay_Min
, Loc
)));
10622 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10625 Append_To
(Delay_Alt
,
10626 Make_Implicit_If_Statement
(N
,
10628 Then_Statements
=> New_List
(
10629 Make_Assignment_Statement
(Loc
,
10630 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10631 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
10633 Make_Assignment_Statement
(Loc
,
10634 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10635 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10638 if Check_Guard
then
10639 Append_To
(Delay_Alt
,
10640 Make_Assignment_Statement
(Loc
,
10641 Name
=> New_Reference_To
(Guard_Open
, Loc
),
10642 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
10645 if Present
(Condition
(Alt
)) then
10646 Delay_Alt
:= New_List
(
10647 Make_Implicit_If_Statement
(N
,
10648 Condition
=> Condition
(Alt
),
10649 Then_Statements
=> Delay_Alt
));
10652 Append_List
(Delay_Alt
, Delay_List
);
10654 Ensure_Statement_Present
(Dloc
, Alt
);
10656 -- If the delay alternative has a statement part, add choice to the
10657 -- case statements for delays.
10659 if not Is_Empty_List
(Statements
(Alt
)) then
10661 if Delay_Count
= 1 then
10662 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10665 Append_To
(Delay_Alt_List
,
10666 Make_Case_Statement_Alternative
(Loc
,
10667 Discrete_Choices
=> New_List
(
10668 Make_Integer_Literal
(Loc
, Index
)),
10669 Statements
=> Statements
(Alt
)));
10672 elsif Delay_Count
= 1 then
10674 -- If the single delay has no trailing statements, add a branch
10675 -- to the exit label to the selective wait.
10677 Delay_Alt_List
:= New_List
(
10678 Make_Goto_Statement
(Loc
,
10679 Name
=> New_Copy
(Identifier
(End_Lab
))));
10682 end Process_Delay_Alternative
;
10684 -- Start of processing for Expand_N_Selective_Accept
10687 Process_Statements_For_Controlled_Objects
(N
);
10689 -- First insert some declarations before the select. The first is:
10693 -- This variable holds the parameters passed to the accept body. This
10694 -- declaration has already been inserted by the time we get here by
10695 -- a call to Expand_Accept_Declarations made from the semantics when
10696 -- processing the first accept statement contained in the select. We
10697 -- can find this entity as Accept_Address (E), where E is any of the
10698 -- entries references by contained accept statements.
10700 -- The first step is to scan the list of Selective_Accept_Statements
10701 -- to find this entity, and also count the number of accepts, and
10702 -- determine if terminated, delay or else is present:
10706 Alt
:= First
(Alts
);
10707 while Present
(Alt
) loop
10708 Process_Statements_For_Controlled_Objects
(Alt
);
10710 if Nkind
(Alt
) = N_Accept_Alternative
then
10713 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10714 Delay_Count
:= Delay_Count
+ 1;
10716 -- If the delays are relative delays, the delay expressions have
10717 -- type Standard_Duration. Otherwise they must have some time type
10718 -- recognized by GNAT.
10720 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10721 Time_Type
:= Standard_Duration
;
10723 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10725 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10726 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10731 "& is not a time type (RM 9.6(6))",
10732 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10733 Time_Type
:= Standard_Duration
;
10734 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10738 if No
(Condition
(Alt
)) then
10740 -- This guard will always be open
10742 Check_Guard
:= False;
10745 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10746 Adjust_Condition
(Condition
(Alt
));
10747 Terminate_Alt
:= Alt
;
10750 Num_Alts
:= Num_Alts
+ 1;
10754 Else_Present
:= Present
(Else_Statements
(N
));
10756 -- At the same time (see procedure Add_Accept) we build the accept list:
10758 -- Qnn : Accept_List (1 .. num-select) := (
10759 -- (null-body, entry-index),
10760 -- (null-body, entry-index),
10762 -- (null_body, entry-index));
10764 -- In the above declaration, null-body is True if the corresponding
10765 -- accept has no body, and false otherwise. The entry is either the
10766 -- entry index expression if there is no guard, or if a guard is
10767 -- present, then an if expression of the form:
10769 -- (if guard then entry-index else Null_Task_Entry)
10771 -- If a guard is statically known to be false, the entry can simply
10772 -- be omitted from the accept list.
10775 Make_Object_Declaration
(Loc
,
10776 Defining_Identifier
=> Qnam
,
10777 Object_Definition
=> New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10778 Aliased_Present
=> True,
10780 Make_Qualified_Expression
(Loc
,
10782 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10784 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10786 -- Then we declare the variable that holds the index for the accept
10787 -- that will be selected for service:
10789 -- Xnn : Select_Index;
10792 Make_Object_Declaration
(Loc
,
10793 Defining_Identifier
=> Xnam
,
10794 Object_Definition
=>
10795 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
10797 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)));
10799 -- After this follow procedure declarations for each accept body
10801 -- procedure Pnn is
10806 -- where the ... are statements from the corresponding procedure body.
10807 -- No parameters are involved, since the parameters are passed via Ann
10808 -- and the parameter references have already been expanded to be direct
10809 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10810 -- any embedded tasking statements (which would normally be illegal in
10811 -- procedures), have been converted to calls to the tasking runtime so
10812 -- there is no problem in putting them into procedures.
10814 -- The original accept statement has been expanded into a block in
10815 -- the same fashion as for simple accepts (see Build_Accept_Body).
10817 -- Note: we don't really need to build these procedures for the case
10818 -- where no delay statement is present, but it is just as easy to
10819 -- build them unconditionally, and not significantly inefficient,
10820 -- since if they are short they will be inlined anyway.
10822 -- The procedure declarations have been assembled in Body_List
10824 -- If delays are present, we must compute the required delay.
10825 -- We first generate the declarations:
10827 -- Delay_Index : Boolean := 0;
10828 -- Delay_Min : Some_Time_Type.Time;
10829 -- Delay_Val : Some_Time_Type.Time;
10831 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10832 -- active delay that is actually chosen as the basis for the possible
10833 -- delay if an immediate rendez-vous is not possible.
10835 -- In the most common case there is a single delay statement, and this
10836 -- is handled specially.
10838 if Delay_Count
> 0 then
10840 -- Generate the required declarations
10843 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
10845 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
10847 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
10850 Make_Object_Declaration
(Loc
,
10851 Defining_Identifier
=> Delay_Val
,
10852 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
10855 Make_Object_Declaration
(Loc
,
10856 Defining_Identifier
=> Delay_Index
,
10857 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
10858 Expression
=> Make_Integer_Literal
(Loc
, 0)));
10861 Make_Object_Declaration
(Loc
,
10862 Defining_Identifier
=> Delay_Min
,
10863 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
10865 Unchecked_Convert_To
(Time_Type
,
10866 Make_Attribute_Reference
(Loc
,
10868 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
10869 Attribute_Name
=> Name_Last
))));
10871 -- Create Duration and Delay_Mode objects used for passing a delay
10874 D
:= Make_Temporary
(Loc
, 'D');
10875 M
:= Make_Temporary
(Loc
, 'M');
10881 -- Note that these values are defined in s-osprim.ads and must
10882 -- be kept in sync:
10884 -- Relative : constant := 0;
10885 -- Absolute_Calendar : constant := 1;
10886 -- Absolute_RT : constant := 2;
10888 if Time_Type
= Standard_Duration
then
10889 Discr
:= Make_Integer_Literal
(Loc
, 0);
10891 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10892 Discr
:= Make_Integer_Literal
(Loc
, 1);
10896 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
10897 Discr
:= Make_Integer_Literal
(Loc
, 2);
10901 Make_Object_Declaration
(Loc
,
10902 Defining_Identifier
=> D
,
10903 Object_Definition
=>
10904 New_Reference_To
(Standard_Duration
, Loc
)));
10907 Make_Object_Declaration
(Loc
,
10908 Defining_Identifier
=> M
,
10909 Object_Definition
=>
10910 New_Reference_To
(Standard_Integer
, Loc
),
10911 Expression
=> Discr
));
10914 if Check_Guard
then
10916 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
10919 Make_Object_Declaration
(Loc
,
10920 Defining_Identifier
=> Guard_Open
,
10921 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
10922 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
10925 -- Delay_Count is zero, don't need M and D set (suppress warning)
10932 if Present
(Terminate_Alt
) then
10934 -- If the terminate alternative guard is False, use
10935 -- Simple_Mode; otherwise use Terminate_Mode.
10937 if Present
(Condition
(Terminate_Alt
)) then
10938 Select_Mode
:= Make_If_Expression
(Loc
,
10939 New_List
(Condition
(Terminate_Alt
),
10940 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
10941 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
10943 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
10946 elsif Else_Present
or Delay_Count
> 0 then
10947 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
10950 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
10953 Select_Call
:= Make_Select_Call
(Select_Mode
);
10954 Append
(Select_Call
, Stats
);
10956 -- Now generate code to act on the result. There is an entry
10957 -- in this case for each accept statement with a non-null body,
10958 -- followed by a branch to the statements that follow the Accept.
10959 -- In the absence of delay alternatives, we generate:
10962 -- when No_Rendezvous => -- omitted if simple mode
10977 -- Lab0: Else_Statements;
10980 -- Lab1: Trailing_Statements1;
10983 -- Lab2: Trailing_Statements2;
10988 -- Generate label for common exit
10990 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
10992 -- First entry is the default case, when no rendezvous is possible
10994 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
10996 if Else_Present
then
10998 -- If no rendezvous is possible, the else part is executed
11000 Lab
:= Make_And_Declare_Label
(0);
11001 Alt_Stats
:= New_List
(
11002 Make_Goto_Statement
(Loc
,
11003 Name
=> New_Copy
(Identifier
(Lab
))));
11005 Append
(Lab
, Trailing_List
);
11006 Append_List
(Else_Statements
(N
), Trailing_List
);
11007 Append_To
(Trailing_List
,
11008 Make_Goto_Statement
(Loc
,
11009 Name
=> New_Copy
(Identifier
(End_Lab
))));
11011 Alt_Stats
:= New_List
(
11012 Make_Goto_Statement
(Loc
,
11013 Name
=> New_Copy
(Identifier
(End_Lab
))));
11016 Append_To
(Alt_List
,
11017 Make_Case_Statement_Alternative
(Loc
,
11018 Discrete_Choices
=> Choices
,
11019 Statements
=> Alt_Stats
));
11021 -- We make use of the fact that Accept_Index is an integer type, and
11022 -- generate successive literals for entries for each accept. Only those
11023 -- for which there is a body or trailing statements get a case entry.
11025 Alt
:= First
(Select_Alternatives
(N
));
11026 Proc
:= First
(Body_List
);
11027 while Present
(Alt
) loop
11029 if Nkind
(Alt
) = N_Accept_Alternative
then
11030 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11031 Index
:= Index
+ 1;
11034 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11039 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11040 Process_Delay_Alternative
(Alt
, Delay_Num
);
11041 Delay_Num
:= Delay_Num
+ 1;
11047 -- An others choice is always added to the main case, as well
11048 -- as the delay case (to satisfy the compiler).
11050 Append_To
(Alt_List
,
11051 Make_Case_Statement_Alternative
(Loc
,
11052 Discrete_Choices
=>
11053 New_List
(Make_Others_Choice
(Loc
)),
11055 New_List
(Make_Goto_Statement
(Loc
,
11056 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11058 Accept_Case
:= New_List
(
11059 Make_Case_Statement
(Loc
,
11060 Expression
=> New_Reference_To
(Xnam
, Loc
),
11061 Alternatives
=> Alt_List
));
11063 Append_List
(Trailing_List
, Accept_Case
);
11064 Append_List
(Body_List
, Decls
);
11066 -- Construct case statement for trailing statements of delay
11067 -- alternatives, if there are several of them.
11069 if Delay_Count
> 1 then
11070 Append_To
(Delay_Alt_List
,
11071 Make_Case_Statement_Alternative
(Loc
,
11072 Discrete_Choices
=>
11073 New_List
(Make_Others_Choice
(Loc
)),
11075 New_List
(Make_Null_Statement
(Loc
))));
11077 Delay_Case
:= New_List
(
11078 Make_Case_Statement
(Loc
,
11079 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
11080 Alternatives
=> Delay_Alt_List
));
11082 Delay_Case
:= Delay_Alt_List
;
11085 -- If there are no delay alternatives, we append the case statement
11086 -- to the statement list.
11088 if Delay_Count
= 0 then
11089 Append_List
(Accept_Case
, Stats
);
11091 -- Delay alternatives present
11094 -- If delay alternatives are present we generate:
11096 -- find minimum delay.
11097 -- DX := minimum delay;
11098 -- M := <delay mode>;
11099 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11102 -- if X = No_Rendezvous then
11103 -- case statement for delay statements.
11105 -- case statement for accept alternatives.
11116 -- The type of the delay expression is known to be legal
11118 if Time_Type
= Standard_Duration
then
11119 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
11121 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11122 Conv
:= Make_Function_Call
(Loc
,
11123 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
11124 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
11128 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11130 Conv
:= Make_Function_Call
(Loc
,
11131 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
11132 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
11135 Stmt
:= Make_Assignment_Statement
(Loc
,
11136 Name
=> New_Reference_To
(D
, Loc
),
11137 Expression
=> Conv
);
11139 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11141 Parms
:= Parameter_Associations
(Select_Call
);
11142 Parm
:= First
(Parms
);
11144 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11148 pragma Assert
(Present
(Parm
));
11149 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
11152 -- Prepare two new parameters of Duration and Delay_Mode type
11153 -- which represent the value and the mode of the minimum delay.
11156 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
11157 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
11159 -- Create a call to RTS
11161 Rewrite
(Select_Call
,
11162 Make_Procedure_Call_Statement
(Loc
,
11163 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11164 Parameter_Associations
=> Parms
));
11166 -- This new call should follow the calculation of the minimum
11169 Insert_List_Before
(Select_Call
, Delay_List
);
11171 if Check_Guard
then
11173 Make_Implicit_If_Statement
(N
,
11174 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
11175 Then_Statements
=> New_List
(
11176 New_Copy_Tree
(Stmt
),
11177 New_Copy_Tree
(Select_Call
)),
11178 Else_Statements
=> Accept_Or_Raise
);
11179 Rewrite
(Select_Call
, Stmt
);
11181 Insert_Before
(Select_Call
, Stmt
);
11185 Make_Implicit_If_Statement
(N
,
11186 Condition
=> Make_Op_Eq
(Loc
,
11187 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
11189 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
11191 Then_Statements
=> Delay_Case
,
11192 Else_Statements
=> Accept_Case
);
11194 Append
(Cases
, Stats
);
11197 Append
(End_Lab
, Stats
);
11199 -- Replace accept statement with appropriate block
11202 Make_Block_Statement
(Loc
,
11203 Declarations
=> Decls
,
11204 Handled_Statement_Sequence
=>
11205 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11208 -- Note: have to worry more about abort deferral in above code ???
11210 -- Final step is to unstack the Accept_Address entries for all accept
11211 -- statements appearing in accept alternatives in the select statement
11213 Alt
:= First
(Alts
);
11214 while Present
(Alt
) loop
11215 if Nkind
(Alt
) = N_Accept_Alternative
then
11216 Remove_Last_Elmt
(Accept_Address
11217 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11222 end Expand_N_Selective_Accept
;
11224 --------------------------------------
11225 -- Expand_N_Single_Task_Declaration --
11226 --------------------------------------
11228 -- Single task declarations should never be present after semantic
11229 -- analysis, since we expect them to be replaced by a declaration of an
11230 -- anonymous task type, followed by a declaration of the task object. We
11231 -- include this routine to make sure that is happening.
11233 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11235 raise Program_Error
;
11236 end Expand_N_Single_Task_Declaration
;
11238 ------------------------
11239 -- Expand_N_Task_Body --
11240 ------------------------
11242 -- Given a task body
11244 -- task body tname is
11250 -- This expansion routine converts it into a procedure and sets the
11251 -- elaboration flag for the procedure to true, to represent the fact
11252 -- that the task body is now elaborated:
11254 -- procedure tnameB (_Task : access tnameV) is
11255 -- discriminal : dtype renames _Task.discriminant;
11257 -- procedure _clean is
11259 -- Abort_Defer.all;
11261 -- Abort_Undefer.all;
11266 -- Abort_Undefer.all;
11268 -- System.Task_Stages.Complete_Activation;
11276 -- In addition, if the task body is an activator, then a call to activate
11277 -- tasks is added at the start of the statements, before the call to
11278 -- Complete_Activation, and if in addition the task is a master then it
11279 -- must be established as a master. These calls are inserted and analyzed
11280 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11283 -- There is one discriminal declaration line generated for each
11284 -- discriminant that is present to provide an easy reference point for
11285 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11287 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11288 -- task body procedures have a profile (Arg : System.Address). That is
11289 -- needed because GNARLI has to use the same access-to-subprogram type
11290 -- for all task types. We depend here on knowing that in GNAT, passing
11291 -- an address argument by value is identical to passing a record value
11292 -- by access (in either case a single pointer is passed), so even though
11293 -- this procedure has the wrong profile. In fact it's all OK, since the
11294 -- callings sequence is identical.
11296 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11297 Loc
: constant Source_Ptr
:= Sloc
(N
);
11298 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11302 Insert_Nod
: Node_Id
;
11303 -- Used to determine the proper location of wrapper body insertions
11306 -- Add renaming declarations for discriminals and a declaration for the
11307 -- entry family index (if applicable).
11309 Install_Private_Data_Declarations
11310 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11312 -- Add a call to Abort_Undefer at the very beginning of the task
11313 -- body since this body is called with abort still deferred.
11315 if Abort_Allowed
then
11316 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11318 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11322 -- The statement part has already been protected with an at_end and
11323 -- cleanup actions. The call to Complete_Activation must be placed
11324 -- at the head of the sequence of statements of that block. The
11325 -- declarations have been merged in this sequence of statements but
11326 -- the first real statement is accessible from the First_Real_Statement
11327 -- field (which was set for exactly this purpose).
11329 if Restricted_Profile
then
11330 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11332 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11336 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11340 Make_Subprogram_Body
(Loc
,
11341 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11342 Declarations
=> Declarations
(N
),
11343 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11345 -- If the task contains generic instantiations, cleanup actions are
11346 -- delayed until after instantiation. Transfer the activation chain to
11347 -- the subprogram, to insure that the activation call is properly
11348 -- generated. It the task body contains inner tasks, indicate that the
11349 -- subprogram is a task master.
11351 if Delay_Cleanups
(Ttyp
) then
11352 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11353 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11356 Rewrite
(N
, New_N
);
11359 -- Set elaboration flag immediately after task body. If the body is a
11360 -- subunit, the flag is set in the declarative part containing the stub.
11362 if Nkind
(Parent
(N
)) /= N_Subunit
then
11364 Make_Assignment_Statement
(Loc
,
11366 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11367 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
11370 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11371 -- the task body. At this point all wrapper specs have been created,
11372 -- frozen and included in the dispatch table for the task type.
11374 if Ada_Version
>= Ada_2005
then
11375 if Nkind
(Parent
(N
)) = N_Subunit
then
11376 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11381 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11383 end Expand_N_Task_Body
;
11385 ------------------------------------
11386 -- Expand_N_Task_Type_Declaration --
11387 ------------------------------------
11389 -- We have several things to do. First we must create a Boolean flag used
11390 -- to mark if the body is elaborated yet. This variable gets set to True
11391 -- when the body of the task is elaborated (we can't rely on the normal
11392 -- ABE mechanism for the task body, since we need to pass an access to
11393 -- this elaboration boolean to the runtime routines).
11395 -- taskE : aliased Boolean := False;
11397 -- Next a variable is declared to hold the task stack size (either the
11398 -- default : Unspecified_Size, or a value that is set by a pragma
11399 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11400 -- the variable is initialized with this value:
11402 -- taskZ : Size_Type := Unspecified_Size;
11404 -- taskZ : Size_Type := Size_Type (size_expression);
11406 -- Note: No variable is needed to hold the task relative deadline since
11407 -- its value would never be static because the parameter is of a private
11408 -- type (Ada.Real_Time.Time_Span).
11410 -- Next we create a corresponding record type declaration used to represent
11411 -- values of this task. The general form of this type declaration is
11413 -- type taskV (discriminants) is record
11414 -- _Task_Id : Task_Id;
11415 -- entry_family : array (bounds) of Void;
11416 -- _Priority : Integer := priority_expression;
11417 -- _Size : Size_Type := size_expression;
11418 -- _Task_Info : Task_Info_Type := task_info_expression;
11419 -- _CPU : Integer := cpu_range_expression;
11420 -- _Relative_Deadline : Time_Span := time_span_expression;
11421 -- _Domain : Dispatching_Domain := dd_expression;
11424 -- The discriminants are present only if the corresponding task type has
11425 -- discriminants, and they exactly mirror the task type discriminants.
11427 -- The Id field is always present. It contains the Task_Id value, as set by
11428 -- the call to Create_Task. Note that although the task is limited, the
11429 -- task value record type is not limited, so there is no problem in passing
11430 -- this field as an out parameter to Create_Task.
11432 -- One entry_family component is present for each entry family in the task
11433 -- definition. The bounds correspond to the bounds of the entry family
11434 -- (which may depend on discriminants). The element type is void, since we
11435 -- only need the bounds information for determining the entry index. Note
11436 -- that the use of an anonymous array would normally be illegal in this
11437 -- context, but this is a parser check, and the semantics is quite prepared
11438 -- to handle such a case.
11440 -- The _Size field is present only if a Storage_Size pragma appears in the
11441 -- task definition. The expression captures the argument that was present
11442 -- in the pragma, and is used to override the task stack size otherwise
11443 -- associated with the task type.
11445 -- The _Priority field is present only if the task entity has a Priority or
11446 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11447 -- definition clause). It will be filled at the freeze point, when the
11448 -- record init proc is built, to capture the expression of the rep item
11449 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11450 -- here since aspect evaluations are delayed till the freeze point.
11452 -- The _Task_Info field is present only if a Task_Info pragma appears in
11453 -- the task definition. The expression captures the argument that was
11454 -- present in the pragma, and is used to provide the Task_Image parameter
11455 -- to the call to Create_Task.
11457 -- The _CPU field is present only if the task entity has a CPU rep item
11458 -- (pragma, aspect specification or attribute definition clause). It will
11459 -- be filled at the freeze point, when the record init proc is built, to
11460 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11461 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11462 -- are delayed till the freeze point.
11464 -- The _Relative_Deadline field is present only if a Relative_Deadline
11465 -- pragma appears in the task definition. The expression captures the
11466 -- argument that was present in the pragma, and is used to provide the
11467 -- Relative_Deadline parameter to the call to Create_Task.
11469 -- The _Domain field is present only if the task entity has a
11470 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11471 -- definition clause). It will be filled at the freeze point, when the
11472 -- record init proc is built, to capture the expression of the rep item
11473 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11474 -- here since aspect evaluations are delayed till the freeze point.
11476 -- When a task is declared, an instance of the task value record is
11477 -- created. The elaboration of this declaration creates the correct bounds
11478 -- for the entry families, and also evaluates the size, priority, and
11479 -- task_Info expressions if needed. The initialization routine for the task
11480 -- type itself then calls Create_Task with appropriate parameters to
11481 -- initialize the value of the Task_Id field.
11483 -- Note: the address of this record is passed as the "Discriminants"
11484 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11485 -- body procedure, it does not matter that it does not quite match the
11486 -- GNARLI model of what is being passed (the record contains more than just
11487 -- the discriminants, but the discriminants can be found from the record
11490 -- The Entity_Id for this created record type is placed in the
11491 -- Corresponding_Record_Type field of the associated task type entity.
11493 -- Next we create a procedure specification for the task body procedure:
11495 -- procedure taskB (_Task : access taskV);
11497 -- Note that this must come after the record type declaration, since
11498 -- the spec refers to this type. It turns out that the initialization
11499 -- procedure for the value type references the task body spec, but that's
11500 -- fine, since it won't be generated till the freeze point for the type,
11501 -- which is certainly after the task body spec declaration.
11503 -- Finally, we set the task index value field of the entry attribute in
11504 -- the case of a simple entry.
11506 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11507 Loc
: constant Source_Ptr
:= Sloc
(N
);
11508 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11509 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11510 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11511 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11513 Body_Decl
: Node_Id
;
11515 Decl_Stack
: Node_Id
;
11516 Elab_Decl
: Node_Id
;
11517 Ent_Stack
: Entity_Id
;
11518 Proc_Spec
: Node_Id
;
11519 Rec_Decl
: Node_Id
;
11520 Rec_Ent
: Entity_Id
;
11521 Size_Decl
: Entity_Id
;
11522 Task_Size
: Node_Id
;
11524 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11525 -- Searches the task definition T for the first occurrence of the pragma
11526 -- Relative Deadline. The caller has ensured that the pragma is present
11527 -- in the task definition. Note that this routine cannot be implemented
11528 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11529 -- not chained because their expansion into a procedure call statement
11530 -- would cause a break in the chain.
11532 ----------------------------------
11533 -- Get_Relative_Deadline_Pragma --
11534 ----------------------------------
11536 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11540 N
:= First
(Visible_Declarations
(T
));
11541 while Present
(N
) loop
11542 if Nkind
(N
) = N_Pragma
11543 and then Pragma_Name
(N
) = Name_Relative_Deadline
11551 N
:= First
(Private_Declarations
(T
));
11552 while Present
(N
) loop
11553 if Nkind
(N
) = N_Pragma
11554 and then Pragma_Name
(N
) = Name_Relative_Deadline
11562 raise Program_Error
;
11563 end Get_Relative_Deadline_Pragma
;
11565 -- Start of processing for Expand_N_Task_Type_Declaration
11568 -- If already expanded, nothing to do
11570 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11574 -- Here we will do the expansion
11576 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11578 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11579 Cdecls
:= Component_Items
(Component_List
11580 (Type_Definition
(Rec_Decl
)));
11582 Qualify_Entity_Names
(N
);
11584 -- First create the elaboration variable
11587 Make_Object_Declaration
(Loc
,
11588 Defining_Identifier
=>
11589 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11590 Chars
=> New_External_Name
(Tasknm
, 'E')),
11591 Aliased_Present
=> True,
11592 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
11593 Expression
=> New_Reference_To
(Standard_False
, Loc
));
11595 Insert_After
(N
, Elab_Decl
);
11597 -- Next create the declaration of the size variable (tasknmZ)
11599 Set_Storage_Size_Variable
(Tasktyp
,
11600 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11601 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11603 if Present
(Taskdef
)
11604 and then Has_Storage_Size_Pragma
(Taskdef
)
11606 Is_Static_Expression
11608 (First
(Pragma_Argument_Associations
11609 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11612 Make_Object_Declaration
(Loc
,
11613 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11614 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11616 Convert_To
(RTE
(RE_Size_Type
),
11618 (Expression
(First
(Pragma_Argument_Associations
11620 (TaskId
, Name_Storage_Size
)))))));
11624 Make_Object_Declaration
(Loc
,
11625 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11626 Object_Definition
=>
11627 New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11629 New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
11632 Insert_After
(Elab_Decl
, Size_Decl
);
11634 -- Next build the rest of the corresponding record declaration. This is
11635 -- done last, since the corresponding record initialization procedure
11636 -- will reference the previously created entities.
11638 -- Fill in the component declarations -- first the _Task_Id field
11641 Make_Component_Declaration
(Loc
,
11642 Defining_Identifier
=>
11643 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11644 Component_Definition
=>
11645 Make_Component_Definition
(Loc
,
11646 Aliased_Present
=> False,
11647 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
11650 -- Declare static ATCB (that is, created by the expander) if we are
11651 -- using the Restricted run time.
11653 if Restricted_Profile
then
11655 Make_Component_Declaration
(Loc
,
11656 Defining_Identifier
=>
11657 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11659 Component_Definition
=>
11660 Make_Component_Definition
(Loc
,
11661 Aliased_Present
=> True,
11662 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11664 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11667 Make_Index_Or_Discriminant_Constraint
(Loc
,
11669 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11673 -- Declare static stack (that is, created by the expander) if we are
11674 -- using the Restricted run time on a bare board configuration.
11676 if Restricted_Profile
11677 and then Preallocated_Stacks_On_Target
11679 -- First we need to extract the appropriate stack size
11681 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11683 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11685 Expr_N
: constant Node_Id
:=
11686 Expression
(First
(
11687 Pragma_Argument_Associations
(
11688 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11689 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11690 P
: constant Node_Id
:= Parent
(Expr_N
);
11693 -- The stack is defined inside the corresponding record.
11694 -- Therefore if the size of the stack is set by means of
11695 -- a discriminant, we must reference the discriminant of the
11696 -- corresponding record type.
11698 if Nkind
(Expr_N
) in N_Has_Entity
11699 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11703 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11705 Set_Parent
(Task_Size
, P
);
11706 Set_Etype
(Task_Size
, Etyp
);
11707 Set_Analyzed
(Task_Size
);
11710 Task_Size
:= Relocate_Node
(Expr_N
);
11716 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
11719 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11720 Defining_Identifier
=> Ent_Stack
,
11722 Component_Definition
=>
11723 Make_Component_Definition
(Loc
,
11724 Aliased_Present
=> True,
11725 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11727 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11730 Make_Index_Or_Discriminant_Constraint
(Loc
,
11731 Constraints
=> New_List
(Make_Range
(Loc
,
11732 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11733 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11736 Append_To
(Cdecls
, Decl_Stack
);
11738 -- The appropriate alignment for the stack is ensured by the run-time
11739 -- code in charge of task creation.
11743 -- Add components for entry families
11745 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11747 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11748 -- item is present.
11750 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
11752 Make_Component_Declaration
(Loc
,
11753 Defining_Identifier
=>
11754 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11755 Component_Definition
=>
11756 Make_Component_Definition
(Loc
,
11757 Aliased_Present
=> False,
11758 Subtype_Indication
=>
11759 New_Reference_To
(Standard_Integer
, Loc
))));
11762 -- Add the _Size component if a Storage_Size pragma is present
11764 if Present
(Taskdef
)
11765 and then Has_Storage_Size_Pragma
(Taskdef
)
11768 Make_Component_Declaration
(Loc
,
11769 Defining_Identifier
=>
11770 Make_Defining_Identifier
(Loc
, Name_uSize
),
11772 Component_Definition
=>
11773 Make_Component_Definition
(Loc
,
11774 Aliased_Present
=> False,
11775 Subtype_Indication
=>
11776 New_Reference_To
(RTE
(RE_Size_Type
), Loc
)),
11779 Convert_To
(RTE
(RE_Size_Type
),
11781 Expression
(First
(
11782 Pragma_Argument_Associations
(
11783 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
11786 -- Add the _Task_Info component if a Task_Info pragma is present
11788 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
11790 Make_Component_Declaration
(Loc
,
11791 Defining_Identifier
=>
11792 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11794 Component_Definition
=>
11795 Make_Component_Definition
(Loc
,
11796 Aliased_Present
=> False,
11797 Subtype_Indication
=>
11798 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
11800 Expression
=> New_Copy
(
11801 Expression
(First
(
11802 Pragma_Argument_Associations
(
11804 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
11807 -- Add the _CPU component if a CPU rep item is present
11809 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
11811 Make_Component_Declaration
(Loc
,
11812 Defining_Identifier
=>
11813 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11815 Component_Definition
=>
11816 Make_Component_Definition
(Loc
,
11817 Aliased_Present
=> False,
11818 Subtype_Indication
=>
11819 New_Reference_To
(RTE
(RE_CPU_Range
), Loc
))));
11822 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11823 -- present. If we are using a restricted run time this component will
11824 -- not be added (deadlines are not allowed by the Ravenscar profile).
11826 if not Restricted_Profile
11827 and then Present
(Taskdef
)
11828 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11831 Make_Component_Declaration
(Loc
,
11832 Defining_Identifier
=>
11833 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11835 Component_Definition
=>
11836 Make_Component_Definition
(Loc
,
11837 Aliased_Present
=> False,
11838 Subtype_Indication
=>
11839 New_Reference_To
(RTE
(RE_Time_Span
), Loc
)),
11842 Convert_To
(RTE
(RE_Time_Span
),
11844 Expression
(First
(
11845 Pragma_Argument_Associations
(
11846 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
11849 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
11850 -- item is present. If we are using a restricted run time this component
11851 -- will not be added (dispatching domains are not allowed by the
11852 -- Ravenscar profile).
11854 if not Restricted_Profile
11857 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
11860 Make_Component_Declaration
(Loc
,
11861 Defining_Identifier
=>
11862 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
11864 Component_Definition
=>
11865 Make_Component_Definition
(Loc
,
11866 Aliased_Present
=> False,
11867 Subtype_Indication
=>
11869 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
11872 Insert_After
(Size_Decl
, Rec_Decl
);
11874 -- Analyze the record declaration immediately after construction,
11875 -- because the initialization procedure is needed for single task
11876 -- declarations before the next entity is analyzed.
11878 Analyze
(Rec_Decl
);
11880 -- Create the declaration of the task body procedure
11882 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
11884 Make_Subprogram_Declaration
(Loc
,
11885 Specification
=> Proc_Spec
);
11887 Insert_After
(Rec_Decl
, Body_Decl
);
11889 -- The subprogram does not comes from source, so we have to indicate the
11890 -- need for debugging information explicitly.
11892 if Comes_From_Source
(Original_Node
(N
)) then
11893 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
11896 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11897 -- the corresponding record has been frozen.
11899 if Ada_Version
>= Ada_2005
then
11900 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
11903 -- Ada 2005 (AI-345): We must defer freezing to allow further
11904 -- declaration of primitive subprograms covering task interfaces
11906 if Ada_Version
<= Ada_95
then
11908 -- Now we can freeze the corresponding record. This needs manually
11909 -- freezing, since it is really part of the task type, and the task
11910 -- type is frozen at this stage. We of course need the initialization
11911 -- procedure for this corresponding record type and we won't get it
11912 -- in time if we don't freeze now.
11915 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
11917 if Is_Non_Empty_List
(L
) then
11918 Insert_List_After
(Body_Decl
, L
);
11923 -- Complete the expansion of access types to the current task type, if
11924 -- any were declared.
11926 Expand_Previous_Access_Type
(Tasktyp
);
11928 -- Create wrappers for entries that have pre/postconditions
11934 Ent
:= First_Entity
(Tasktyp
);
11935 while Present
(Ent
) loop
11936 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
11937 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
11939 Build_PPC_Wrapper
(Ent
, N
);
11945 end Expand_N_Task_Type_Declaration
;
11947 -------------------------------
11948 -- Expand_N_Timed_Entry_Call --
11949 -------------------------------
11951 -- A timed entry call in normal case is not implemented using ATC mechanism
11952 -- anymore for efficiency reason.
11962 -- is expanded as follows:
11964 -- 1) When T.E is a task entry_call;
11968 -- X : Task_Entry_Index := <entry index>;
11969 -- DX : Duration := To_Duration (D);
11970 -- M : Delay_Mode := <discriminant>;
11971 -- P : parms := (parm, parm, parm);
11974 -- Timed_Protected_Entry_Call
11975 -- (<acceptor-task>, X, P'Address, DX, M, B);
11983 -- 2) When T.E is a protected entry_call;
11987 -- X : Protected_Entry_Index := <entry index>;
11988 -- DX : Duration := To_Duration (D);
11989 -- M : Delay_Mode := <discriminant>;
11990 -- P : parms := (parm, parm, parm);
11993 -- Timed_Protected_Entry_Call
11994 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12002 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12003 -- is no delay and the triggering statements are executed. We first
12004 -- determine the kind of of the triggering call and then execute a
12005 -- synchronized operation or a direct call.
12008 -- B : Boolean := False;
12009 -- C : Ada.Tags.Prim_Op_Kind;
12010 -- DX : Duration := To_Duration (D)
12011 -- K : Ada.Tags.Tagged_Kind :=
12012 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12013 -- M : Integer :=...;
12014 -- P : Parameters := (Param1 .. ParamN);
12018 -- if K = Ada.Tags.TK_Limited_Tagged
12019 -- or else K = Ada.Tags.TK_Tagged
12021 -- <dispatching-call>;
12026 -- Ada.Tags.Get_Offset_Index
12027 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12029 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12031 -- if C = POK_Protected_Entry
12032 -- or else C = POK_Task_Entry
12034 -- Param1 := P.Param1;
12036 -- ParamN := P.ParamN;
12040 -- if C = POK_Procedure
12041 -- or else C = POK_Protected_Procedure
12042 -- or else C = POK_Task_Procedure
12044 -- <dispatching-call>;
12050 -- <triggering-statements>
12052 -- <timed-statements>
12056 -- The triggering statement and the sequence of timed statements have not
12057 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12058 -- global references if within an instantiation.
12060 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12061 Loc
: constant Source_Ptr
:= Sloc
(N
);
12064 Blk_Typ
: Entity_Id
;
12066 Call_Ent
: Entity_Id
;
12067 Conc_Typ_Stmts
: List_Id
;
12069 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12072 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12074 D_Type
: Entity_Id
;
12077 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12078 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12083 Is_Disp_Select
: Boolean;
12084 Lim_Typ_Stmts
: List_Id
;
12093 B
: Entity_Id
; -- Call status flag
12094 C
: Entity_Id
; -- Call kind
12095 D
: Entity_Id
; -- Delay
12096 K
: Entity_Id
; -- Tagged kind
12097 M
: Entity_Id
; -- Delay mode
12098 P
: Entity_Id
; -- Parameter block
12099 S
: Entity_Id
; -- Primitive operation slot
12101 -- Start of processing for Expand_N_Timed_Entry_Call
12104 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12105 -- was already reported on spec, so do not attempt to expand the call.
12107 if Restriction_Active
(No_Select_Statements
) then
12111 Process_Statements_For_Controlled_Objects
(E_Alt
);
12112 Process_Statements_For_Controlled_Objects
(D_Alt
);
12114 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12116 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12117 -- may wrap them in blocks.
12119 E_Stats
:= Statements
(E_Alt
);
12120 D_Stats
:= Statements
(D_Alt
);
12122 -- The arguments in the call may require dynamic allocation, and the
12123 -- call statement may have been transformed into a block. The block
12124 -- may contain additional declarations for internal entities, and the
12125 -- original call is found by sequential search.
12127 if Nkind
(E_Call
) = N_Block_Statement
then
12128 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12129 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12130 N_Entry_Call_Statement
)
12137 Ada_Version
>= Ada_2005
12138 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12140 if Is_Disp_Select
then
12141 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12147 -- B : Boolean := False;
12149 B
:= Build_B
(Loc
, Decls
);
12152 -- C : Ada.Tags.Prim_Op_Kind;
12154 C
:= Build_C
(Loc
, Decls
);
12156 -- Because the analysis of all statements was disabled, manually
12157 -- analyze the delay statement.
12160 D_Stat
:= Original_Node
(D_Stat
);
12163 -- Build an entry call using Simple_Entry_Call
12165 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12166 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12168 Decls
:= Declarations
(E_Call
);
12169 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12178 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12181 Make_Object_Declaration
(Loc
,
12182 Defining_Identifier
=> B
,
12183 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
12186 -- Duration and mode processing
12188 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12190 -- Use the type of the delay expression (Calendar or Real_Time) to
12191 -- generate the appropriate conversion.
12193 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12194 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12195 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12197 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12198 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12200 Make_Function_Call
(Loc
,
12201 Name
=> New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
12202 Parameter_Associations
=>
12203 New_List
(New_Copy
(Expression
(D_Stat
))));
12205 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12206 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12208 Make_Function_Call
(Loc
,
12209 Name
=> New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
12210 Parameter_Associations
=>
12211 New_List
(New_Copy
(Expression
(D_Stat
))));
12214 D
:= Make_Temporary
(Loc
, 'D');
12220 Make_Object_Declaration
(Loc
,
12221 Defining_Identifier
=> D
,
12222 Object_Definition
=> New_Reference_To
(Standard_Duration
, Loc
)));
12224 M
:= Make_Temporary
(Loc
, 'M');
12227 -- M : Integer := (0 | 1 | 2);
12230 Make_Object_Declaration
(Loc
,
12231 Defining_Identifier
=> M
,
12232 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
12233 Expression
=> D_Disc
));
12235 -- Do the assignment at this stage only because the evaluation of the
12236 -- expression must not occur before (see ACVC C97302A).
12239 Make_Assignment_Statement
(Loc
,
12240 Name
=> New_Reference_To
(D
, Loc
),
12241 Expression
=> D_Conv
));
12243 -- Parameter block processing
12245 -- Manually create the parameter block for dispatching calls. In the
12246 -- case of entries, the block has already been created during the call
12247 -- to Build_Simple_Entry_Call.
12249 if Is_Disp_Select
then
12251 -- Tagged kind processing, generate:
12252 -- K : Ada.Tags.Tagged_Kind :=
12253 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12255 K
:= Build_K
(Loc
, Decls
, Obj
);
12257 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12259 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12261 -- Dispatch table slot processing, generate:
12264 S
:= Build_S
(Loc
, Decls
);
12267 -- S := Ada.Tags.Get_Offset_Index
12268 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12271 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12274 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12276 -- where Obj is the controlling formal parameter, S is the dispatch
12277 -- table slot number of the dispatching operation, P is the wrapped
12278 -- parameter block, D is the duration, M is the duration mode, C is
12279 -- the call kind and B is the call status.
12281 Params
:= New_List
;
12283 Append_To
(Params
, New_Copy_Tree
(Obj
));
12284 Append_To
(Params
, New_Reference_To
(S
, Loc
));
12286 Make_Attribute_Reference
(Loc
,
12287 Prefix
=> New_Reference_To
(P
, Loc
),
12288 Attribute_Name
=> Name_Address
));
12289 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12290 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12291 Append_To
(Params
, New_Reference_To
(C
, Loc
));
12292 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12294 Append_To
(Conc_Typ_Stmts
,
12295 Make_Procedure_Call_Statement
(Loc
,
12299 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12300 Parameter_Associations
=> Params
));
12303 -- if C = POK_Protected_Entry
12304 -- or else C = POK_Task_Entry
12306 -- Param1 := P.Param1;
12308 -- ParamN := P.ParamN;
12311 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12313 -- Generate the if statement only when the packed parameters need
12314 -- explicit assignments to their corresponding actuals.
12316 if Present
(Unpack
) then
12317 Append_To
(Conc_Typ_Stmts
,
12318 Make_Implicit_If_Statement
(N
,
12324 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12327 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12331 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12333 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
12335 Then_Statements
=> Unpack
));
12341 -- if C = POK_Procedure
12342 -- or else C = POK_Protected_Procedure
12343 -- or else C = POK_Task_Procedure
12345 -- <dispatching-call>
12349 N_Stats
:= New_List
(
12350 Make_Implicit_If_Statement
(N
,
12355 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12357 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
12363 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12365 New_Reference_To
(RTE
(
12366 RE_POK_Protected_Procedure
), Loc
)),
12369 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12372 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12374 Then_Statements
=> New_List
(E_Call
)));
12376 Append_To
(Conc_Typ_Stmts
,
12377 Make_Implicit_If_Statement
(N
,
12378 Condition
=> New_Reference_To
(B
, Loc
),
12379 Then_Statements
=> N_Stats
));
12382 -- <dispatching-call>;
12386 New_List
(New_Copy_Tree
(E_Call
),
12387 Make_Assignment_Statement
(Loc
,
12388 Name
=> New_Occurrence_Of
(B
, Loc
),
12389 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12392 -- if K = Ada.Tags.TK_Limited_Tagged
12393 -- or else K = Ada.Tags.TK_Tagged
12401 Make_Implicit_If_Statement
(N
,
12402 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12403 Then_Statements
=> Lim_Typ_Stmts
,
12404 Else_Statements
=> Conc_Typ_Stmts
));
12409 -- <triggering-statements>
12411 -- <timed-statements>
12415 Make_Implicit_If_Statement
(N
,
12416 Condition
=> New_Occurrence_Of
(B
, Loc
),
12417 Then_Statements
=> E_Stats
,
12418 Else_Statements
=> D_Stats
));
12421 -- Simple case of a non-dispatching trigger. Skip assignments to
12422 -- temporaries created for in-out parameters.
12424 -- This makes unwarranted assumptions about the shape of the expanded
12425 -- tree for the call, and should be cleaned up ???
12427 Stmt
:= First
(Stmts
);
12428 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12432 -- Do the assignment at this stage only because the evaluation
12433 -- of the expression must not occur before (see ACVC C97302A).
12435 Insert_Before
(Stmt
,
12436 Make_Assignment_Statement
(Loc
,
12437 Name
=> New_Reference_To
(D
, Loc
),
12438 Expression
=> D_Conv
));
12441 Params
:= Parameter_Associations
(Call
);
12443 -- For a protected type, we build a Timed_Protected_Entry_Call
12445 if Is_Protected_Type
(Etype
(Concval
)) then
12447 -- Create a new call statement
12449 Param
:= First
(Params
);
12450 while Present
(Param
)
12451 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12456 Dummy
:= Remove_Next
(Next
(Param
));
12458 -- Remove garbage is following the Cancel_Param if present
12460 Dummy
:= Next
(Param
);
12462 -- Remove the mode of the Protected_Entry_Call call, then remove
12463 -- the Communication_Block of the Protected_Entry_Call call, and
12464 -- finally add Duration and a Delay_Mode parameter
12466 pragma Assert
(Present
(Param
));
12467 Rewrite
(Param
, New_Reference_To
(D
, Loc
));
12469 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
12471 -- Add a Boolean flag for successful entry call
12473 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12475 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12476 when System_Tasking_Protected_Objects_Entries
=>
12478 Make_Procedure_Call_Statement
(Loc
,
12481 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12482 Parameter_Associations
=> Params
));
12484 when System_Tasking_Protected_Objects_Single_Entry
=>
12485 Param
:= First
(Params
);
12486 while Present
(Param
)
12488 Is_RTE
(Etype
(Param
), RE_Protected_Entry_Index
)
12496 Make_Procedure_Call_Statement
(Loc
,
12499 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
12500 Parameter_Associations
=> Params
));
12503 raise Program_Error
;
12506 -- For the task case, build a Timed_Task_Entry_Call
12509 -- Create a new call statement
12511 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12512 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12513 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12516 Make_Procedure_Call_Statement
(Loc
,
12518 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12519 Parameter_Associations
=> Params
));
12523 Make_Implicit_If_Statement
(N
,
12524 Condition
=> New_Reference_To
(B
, Loc
),
12525 Then_Statements
=> E_Stats
,
12526 Else_Statements
=> D_Stats
));
12530 Make_Block_Statement
(Loc
,
12531 Declarations
=> Decls
,
12532 Handled_Statement_Sequence
=>
12533 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12536 end Expand_N_Timed_Entry_Call
;
12538 ----------------------------------------
12539 -- Expand_Protected_Body_Declarations --
12540 ----------------------------------------
12542 procedure Expand_Protected_Body_Declarations
12544 Spec_Id
: Entity_Id
)
12547 if No_Run_Time_Mode
then
12548 Error_Msg_CRT
("protected body", N
);
12551 elsif Expander_Active
then
12553 -- Associate discriminals with the first subprogram or entry body to
12556 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12557 Set_Discriminals
(Parent
(Spec_Id
));
12560 end Expand_Protected_Body_Declarations
;
12562 -------------------------
12563 -- External_Subprogram --
12564 -------------------------
12566 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12567 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12570 -- The internal and external subprograms follow each other on the entity
12571 -- chain. Note that previously private operations had no separate
12572 -- external subprogram. We now create one in all cases, because a
12573 -- private operation may actually appear in an external call, through
12574 -- a 'Access reference used for a callback.
12576 -- If the operation is a function that returns an anonymous access type,
12577 -- the corresponding itype appears before the operation, and must be
12580 -- This mechanism is fragile, there should be a real link between the
12581 -- two versions of the operation, but there is no place to put it ???
12583 if Is_Access_Type
(Next_Entity
(Subp
)) then
12584 return Next_Entity
(Next_Entity
(Subp
));
12586 return Next_Entity
(Subp
);
12588 end External_Subprogram
;
12590 ------------------------------
12591 -- Extract_Dispatching_Call --
12592 ------------------------------
12594 procedure Extract_Dispatching_Call
12596 Call_Ent
: out Entity_Id
;
12597 Object
: out Entity_Id
;
12598 Actuals
: out List_Id
;
12599 Formals
: out List_Id
)
12601 Call_Nam
: Node_Id
;
12604 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12606 if Present
(Original_Node
(N
)) then
12607 Call_Nam
:= Name
(Original_Node
(N
));
12609 Call_Nam
:= Name
(N
);
12612 -- Retrieve the name of the dispatching procedure. It contains the
12613 -- dispatch table slot number.
12616 case Nkind
(Call_Nam
) is
12617 when N_Identifier
=>
12620 when N_Selected_Component
=>
12621 Call_Nam
:= Selector_Name
(Call_Nam
);
12624 raise Program_Error
;
12629 Actuals
:= Parameter_Associations
(N
);
12630 Call_Ent
:= Entity
(Call_Nam
);
12631 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12632 Object
:= First
(Actuals
);
12634 if Present
(Original_Node
(Object
)) then
12635 Object
:= Original_Node
(Object
);
12638 -- If the type of the dispatching object is an access type then return
12639 -- an explicit dereference.
12641 if Is_Access_Type
(Etype
(Object
)) then
12642 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12645 end Extract_Dispatching_Call
;
12647 -------------------
12648 -- Extract_Entry --
12649 -------------------
12651 procedure Extract_Entry
12653 Concval
: out Node_Id
;
12654 Ename
: out Node_Id
;
12655 Index
: out Node_Id
)
12657 Nam
: constant Node_Id
:= Name
(N
);
12660 -- For a simple entry, the name is a selected component, with the
12661 -- prefix being the task value, and the selector being the entry.
12663 if Nkind
(Nam
) = N_Selected_Component
then
12664 Concval
:= Prefix
(Nam
);
12665 Ename
:= Selector_Name
(Nam
);
12668 -- For a member of an entry family, the name is an indexed component
12669 -- where the prefix is a selected component, whose prefix in turn is
12670 -- the task value, and whose selector is the entry family. The single
12671 -- expression in the expressions list of the indexed component is the
12672 -- subscript for the family.
12674 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12675 Concval
:= Prefix
(Prefix
(Nam
));
12676 Ename
:= Selector_Name
(Prefix
(Nam
));
12677 Index
:= First
(Expressions
(Nam
));
12681 -------------------
12682 -- Family_Offset --
12683 -------------------
12685 function Family_Offset
12690 Cap
: Boolean) return Node_Id
12696 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12697 -- If one of the bounds is a reference to a discriminant, replace with
12698 -- corresponding discriminal of type. Within the body of a task retrieve
12699 -- the renamed discriminant by simple visibility, using its generated
12700 -- name. Within a protected object, find the original discriminant and
12701 -- replace it with the discriminal of the current protected operation.
12703 ------------------------------
12704 -- Convert_Discriminant_Ref --
12705 ------------------------------
12707 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12708 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12713 if Is_Entity_Name
(Bound
)
12714 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12716 if Is_Task_Type
(Ttyp
)
12717 and then Has_Completion
(Ttyp
)
12719 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12720 Find_Direct_Name
(B
);
12722 elsif Is_Protected_Type
(Ttyp
) then
12723 D
:= First_Discriminant
(Ttyp
);
12724 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12725 Next_Discriminant
(D
);
12728 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
12731 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
12734 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12738 B
:= New_Copy_Tree
(Bound
);
12742 Make_Attribute_Reference
(Loc
,
12743 Attribute_Name
=> Name_Pos
,
12744 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12745 Expressions
=> New_List
(B
));
12746 end Convert_Discriminant_Ref
;
12748 -- Start of processing for Family_Offset
12751 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12752 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12755 if Is_Task_Type
(Ttyp
) then
12756 Ityp
:= RTE
(RE_Task_Entry_Index
);
12758 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12762 Make_Attribute_Reference
(Loc
,
12763 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12764 Attribute_Name
=> Name_Min
,
12765 Expressions
=> New_List
(
12767 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12770 Make_Attribute_Reference
(Loc
,
12771 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12772 Attribute_Name
=> Name_Max
,
12773 Expressions
=> New_List
(
12775 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12778 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12785 function Family_Size
12790 Cap
: Boolean) return Node_Id
12795 if Is_Task_Type
(Ttyp
) then
12796 Ityp
:= RTE
(RE_Task_Entry_Index
);
12798 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12802 Make_Attribute_Reference
(Loc
,
12803 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12804 Attribute_Name
=> Name_Max
,
12805 Expressions
=> New_List
(
12808 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12810 Make_Integer_Literal
(Loc
, 1)),
12811 Make_Integer_Literal
(Loc
, 0)));
12814 ----------------------------
12815 -- Find_Enclosing_Context --
12816 ----------------------------
12818 procedure Find_Enclosing_Context
12820 Context
: out Node_Id
;
12821 Context_Id
: out Entity_Id
;
12822 Context_Decls
: out List_Id
)
12825 -- Traverse the parent chain looking for an enclosing body, block,
12826 -- package or return statement.
12828 Context
:= Parent
(N
);
12829 while not Nkind_In
(Context
, N_Block_Statement
,
12831 N_Extended_Return_Statement
,
12833 N_Package_Declaration
,
12837 Context
:= Parent
(Context
);
12840 -- Extract the constituents of the context
12842 if Nkind
(Context
) = N_Extended_Return_Statement
then
12843 Context_Decls
:= Return_Object_Declarations
(Context
);
12844 Context_Id
:= Return_Statement_Entity
(Context
);
12846 -- Package declarations and bodies use a common library-level activation
12847 -- chain or task master, therefore return the package declaration as the
12848 -- proper carrier for the appropriate flag.
12850 elsif Nkind
(Context
) = N_Package_Body
then
12851 Context_Decls
:= Declarations
(Context
);
12852 Context_Id
:= Corresponding_Spec
(Context
);
12853 Context
:= Parent
(Context_Id
);
12855 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
12856 Context
:= Parent
(Parent
(Context
));
12858 Context
:= Parent
(Context
);
12861 elsif Nkind
(Context
) = N_Package_Declaration
then
12862 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
12863 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12865 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12866 Context_Id
:= Defining_Identifier
(Context_Id
);
12870 Context_Decls
:= Declarations
(Context
);
12872 if Nkind
(Context
) = N_Block_Statement
then
12873 Context_Id
:= Entity
(Identifier
(Context
));
12875 elsif Nkind
(Context
) = N_Entry_Body
then
12876 Context_Id
:= Defining_Identifier
(Context
);
12878 elsif Nkind
(Context
) = N_Subprogram_Body
then
12879 if Present
(Corresponding_Spec
(Context
)) then
12880 Context_Id
:= Corresponding_Spec
(Context
);
12882 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12884 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12885 Context_Id
:= Defining_Identifier
(Context_Id
);
12889 elsif Nkind
(Context
) = N_Task_Body
then
12890 Context_Id
:= Corresponding_Spec
(Context
);
12893 raise Program_Error
;
12897 pragma Assert
(Present
(Context
));
12898 pragma Assert
(Present
(Context_Id
));
12899 pragma Assert
(Present
(Context_Decls
));
12900 end Find_Enclosing_Context
;
12902 -----------------------
12903 -- Find_Master_Scope --
12904 -----------------------
12906 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
12910 -- In Ada 2005, the master is the innermost enclosing scope that is not
12911 -- transient. If the enclosing block is the rewriting of a call or the
12912 -- scope is an extended return statement this is valid master. The
12913 -- master in an extended return is only used within the return, and is
12914 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12915 -- now before that overwriting occurs.
12919 if Ada_Version
>= Ada_2005
then
12920 while Is_Internal
(S
) loop
12921 if Nkind
(Parent
(S
)) = N_Block_Statement
12923 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
12927 elsif Ekind
(S
) = E_Return_Statement
then
12937 end Find_Master_Scope
;
12939 -------------------------------
12940 -- First_Protected_Operation --
12941 -------------------------------
12943 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
12944 First_Op
: Node_Id
;
12947 First_Op
:= First
(D
);
12948 while Present
(First_Op
)
12949 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
12955 end First_Protected_Operation
;
12957 ---------------------------------------
12958 -- Install_Private_Data_Declarations --
12959 ---------------------------------------
12961 procedure Install_Private_Data_Declarations
12963 Spec_Id
: Entity_Id
;
12964 Conc_Typ
: Entity_Id
;
12965 Body_Nod
: Node_Id
;
12967 Barrier
: Boolean := False;
12968 Family
: Boolean := False)
12970 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
12973 Insert_Node
: Node_Id
:= Empty
;
12974 Obj_Ent
: Entity_Id
;
12976 procedure Add
(Decl
: Node_Id
);
12977 -- Add a single declaration after Insert_Node. If this is the first
12978 -- addition, Decl is added to the front of Decls and it becomes the
12981 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
12982 -- The bounds of an entry index may depend on discriminants, create a
12983 -- reference to the corresponding prival. Otherwise return a duplicate
12984 -- of the original bound.
12990 procedure Add
(Decl
: Node_Id
) is
12992 if No
(Insert_Node
) then
12993 Prepend_To
(Decls
, Decl
);
12995 Insert_After
(Insert_Node
, Decl
);
12998 Insert_Node
:= Decl
;
13001 --------------------------
13002 -- Replace_Discriminant --
13003 --------------------------
13005 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13007 if Nkind
(Bound
) = N_Identifier
13008 and then Is_Discriminal
(Entity
(Bound
))
13010 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13012 return Duplicate_Subexpr
(Bound
);
13016 -- Start of processing for Install_Private_Data_Declarations
13019 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13020 -- formal parameter _O, _object or _task depending on the context.
13022 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13024 -- Special processing of _O for barrier functions, protected entries
13031 (Ekind
(Spec_Id
) = E_Entry
13032 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13035 Conc_Rec
: constant Entity_Id
:=
13036 Corresponding_Record_Type
(Conc_Typ
);
13037 Typ_Id
: constant Entity_Id
:=
13038 Make_Defining_Identifier
(Loc
,
13039 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13042 -- type prot_typVP is access prot_typV;
13045 Make_Full_Type_Declaration
(Loc
,
13046 Defining_Identifier
=> Typ_Id
,
13048 Make_Access_To_Object_Definition
(Loc
,
13049 Subtype_Indication
=>
13050 New_Reference_To
(Conc_Rec
, Loc
)));
13054 -- _object : prot_typVP := prot_typV (_O);
13057 Make_Object_Declaration
(Loc
,
13058 Defining_Identifier
=>
13059 Make_Defining_Identifier
(Loc
, Name_uObject
),
13060 Object_Definition
=> New_Reference_To
(Typ_Id
, Loc
),
13062 Unchecked_Convert_To
(Typ_Id
,
13063 New_Reference_To
(Obj_Ent
, Loc
)));
13066 -- Set the reference to the concurrent object
13068 Obj_Ent
:= Defining_Identifier
(Decl
);
13072 -- Step 2: Create the Protection object and build its declaration for
13073 -- any protected entry (family) of subprogram. Note for the lock-free
13074 -- implementation, the Protection object is not needed anymore.
13076 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13078 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13082 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13084 -- Determine the proper protection type
13086 if Has_Attach_Handler
(Conc_Typ
)
13087 and then not Restricted_Profile
13089 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13091 elsif Has_Interrupt_Handler
(Conc_Typ
)
13092 and then not Restriction_Active
(No_Dynamic_Attachment
)
13094 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13097 case Corresponding_Runtime_Package
(Conc_Typ
) is
13098 when System_Tasking_Protected_Objects_Entries
=>
13099 Prot_Typ
:= RE_Protection_Entries
;
13101 when System_Tasking_Protected_Objects_Single_Entry
=>
13102 Prot_Typ
:= RE_Protection_Entry
;
13104 when System_Tasking_Protected_Objects
=>
13105 Prot_Typ
:= RE_Protection
;
13108 raise Program_Error
;
13113 -- conc_typR : protection_typ renames _object._object;
13116 Make_Object_Renaming_Declaration
(Loc
,
13117 Defining_Identifier
=> Prot_Ent
,
13119 New_Reference_To
(RTE
(Prot_Typ
), Loc
),
13121 Make_Selected_Component
(Loc
,
13122 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13123 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13128 -- Step 3: Add discriminant renamings (if any)
13130 if Has_Discriminants
(Conc_Typ
) then
13135 D
:= First_Discriminant
(Conc_Typ
);
13136 while Present
(D
) loop
13138 -- Adjust the source location
13140 Set_Sloc
(Discriminal
(D
), Loc
);
13143 -- discr_name : discr_typ renames _object.discr_name;
13145 -- discr_name : discr_typ renames _task.discr_name;
13148 Make_Object_Renaming_Declaration
(Loc
,
13149 Defining_Identifier
=> Discriminal
(D
),
13150 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
13152 Make_Selected_Component
(Loc
,
13153 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13154 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13157 Next_Discriminant
(D
);
13162 -- Step 4: Add private component renamings (if any)
13164 if Is_Protected
then
13165 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13167 if Present
(Private_Declarations
(Def
)) then
13170 Comp_Id
: Entity_Id
;
13171 Decl_Id
: Entity_Id
;
13174 Comp
:= First
(Private_Declarations
(Def
));
13175 while Present
(Comp
) loop
13176 if Nkind
(Comp
) = N_Component_Declaration
then
13177 Comp_Id
:= Defining_Identifier
(Comp
);
13179 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13181 -- Minimal decoration
13183 if Ekind
(Spec_Id
) = E_Function
then
13184 Set_Ekind
(Decl_Id
, E_Constant
);
13186 Set_Ekind
(Decl_Id
, E_Variable
);
13189 Set_Prival
(Comp_Id
, Decl_Id
);
13190 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13191 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13194 -- comp_name : comp_typ renames _object.comp_name;
13197 Make_Object_Renaming_Declaration
(Loc
,
13198 Defining_Identifier
=> Decl_Id
,
13200 New_Reference_To
(Etype
(Comp_Id
), Loc
),
13202 Make_Selected_Component
(Loc
,
13204 New_Reference_To
(Obj_Ent
, Loc
),
13206 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13216 -- Step 5: Add the declaration of the entry index and the associated
13217 -- type for barrier functions and entry families.
13219 if (Barrier
and then Family
)
13220 or else Ekind
(Spec_Id
) = E_Entry_Family
13223 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13224 Index
: constant Entity_Id
:=
13225 Defining_Identifier
(
13226 Entry_Index_Specification
(
13227 Entry_Body_Formal_Part
(Body_Nod
)));
13228 Index_Con
: constant Entity_Id
:=
13229 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13231 Index_Typ
: Entity_Id
;
13235 -- Minimal decoration
13237 Set_Ekind
(Index_Con
, E_Constant
);
13238 Set_Entry_Index_Constant
(Index
, Index_Con
);
13239 Set_Discriminal_Link
(Index_Con
, Index
);
13241 -- Retrieve the bounds of the entry family
13243 High
:= Type_High_Bound
(Etype
(Index
));
13244 Low
:= Type_Low_Bound
(Etype
(Index
));
13246 -- In the simple case the entry family is given by a subtype
13247 -- mark and the index constant has the same type.
13249 if Is_Entity_Name
(Original_Node
(
13250 Discrete_Subtype_Definition
(Parent
(Index
))))
13252 Index_Typ
:= Etype
(Index
);
13254 -- Otherwise a new subtype declaration is required
13257 High
:= Replace_Bound
(High
);
13258 Low
:= Replace_Bound
(Low
);
13260 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13263 -- subtype Jnn is <Etype of Index> range Low .. High;
13266 Make_Subtype_Declaration
(Loc
,
13267 Defining_Identifier
=> Index_Typ
,
13268 Subtype_Indication
=>
13269 Make_Subtype_Indication
(Loc
,
13271 New_Reference_To
(Base_Type
(Etype
(Index
)), Loc
),
13273 Make_Range_Constraint
(Loc
,
13274 Range_Expression
=>
13275 Make_Range
(Loc
, Low
, High
))));
13279 Set_Etype
(Index_Con
, Index_Typ
);
13281 -- Create the object which designates the index:
13282 -- J : constant Jnn :=
13283 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13285 -- where Jnn is the subtype created above or the original type of
13286 -- the index, _E is a formal of the protected body subprogram and
13287 -- <index expr> is the index of the first family member.
13290 Make_Object_Declaration
(Loc
,
13291 Defining_Identifier
=> Index_Con
,
13292 Constant_Present
=> True,
13293 Object_Definition
=>
13294 New_Reference_To
(Index_Typ
, Loc
),
13297 Make_Attribute_Reference
(Loc
,
13299 New_Reference_To
(Index_Typ
, Loc
),
13300 Attribute_Name
=> Name_Val
,
13302 Expressions
=> New_List
(
13306 Make_Op_Subtract
(Loc
,
13308 New_Reference_To
(E
, Loc
),
13310 Entry_Index_Expression
(Loc
,
13311 Defining_Identifier
(Body_Nod
),
13315 Make_Attribute_Reference
(Loc
,
13317 New_Reference_To
(Index_Typ
, Loc
),
13318 Attribute_Name
=> Name_Pos
,
13319 Expressions
=> New_List
(
13320 Make_Attribute_Reference
(Loc
,
13322 New_Reference_To
(Index_Typ
, Loc
),
13323 Attribute_Name
=> Name_First
)))))));
13327 end Install_Private_Data_Declarations
;
13329 -----------------------
13330 -- Is_Exception_Safe --
13331 -----------------------
13333 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
13335 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
13336 -- Return True whenever encountering a subprogram call or raise
13337 -- statement of any kind in the sequence of statements
13339 ---------------------
13340 -- Has_Side_Effect --
13341 ---------------------
13343 -- What is this doing buried two levels down in exp_ch9. It seems like a
13344 -- generally useful function, and indeed there may be code duplication
13345 -- going on here ???
13347 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
13351 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
13352 -- Indicate whether N is a subprogram call or a raise statement
13354 ----------------------
13355 -- Is_Call_Or_Raise --
13356 ----------------------
13358 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
13360 return Nkind_In
(N
, N_Procedure_Call_Statement
,
13363 N_Raise_Constraint_Error
,
13364 N_Raise_Program_Error
,
13365 N_Raise_Storage_Error
);
13366 end Is_Call_Or_Raise
;
13368 -- Start of processing for Has_Side_Effect
13372 while Present
(Stmt
) loop
13373 if Is_Call_Or_Raise
(Stmt
) then
13377 -- An object declaration can also contain a function call or a
13378 -- raise statement.
13380 if Nkind
(Stmt
) = N_Object_Declaration
then
13381 Expr
:= Expression
(Stmt
);
13383 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
13392 end Has_Side_Effect
;
13394 -- Start of processing for Is_Exception_Safe
13397 -- When exceptions can't be propagated, the subprogram returns normally
13399 if No_Exception_Handlers_Set
then
13403 -- If the checks handled by the back end are not disabled, we cannot
13404 -- ensure that no exception will be raised.
13406 if not Access_Checks_Suppressed
(Empty
)
13407 or else not Discriminant_Checks_Suppressed
(Empty
)
13408 or else not Range_Checks_Suppressed
(Empty
)
13409 or else not Index_Checks_Suppressed
(Empty
)
13410 or else Opt
.Stack_Checking_Enabled
13415 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
13418 (First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
13424 end Is_Exception_Safe
;
13426 ---------------------------------
13427 -- Is_Potentially_Large_Family --
13428 ---------------------------------
13430 function Is_Potentially_Large_Family
13431 (Base_Index
: Entity_Id
;
13432 Conctyp
: Entity_Id
;
13434 Hi
: Node_Id
) return Boolean
13437 return Scope
(Base_Index
) = Standard_Standard
13438 and then Base_Index
= Base_Type
(Standard_Integer
)
13439 and then Has_Discriminants
(Conctyp
)
13441 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13443 (Denotes_Discriminant
(Lo
, True)
13445 Denotes_Discriminant
(Hi
, True));
13446 end Is_Potentially_Large_Family
;
13448 -------------------------------------
13449 -- Is_Private_Primitive_Subprogram --
13450 -------------------------------------
13452 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13455 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13456 and then Is_Private_Primitive
(Id
);
13457 end Is_Private_Primitive_Subprogram
;
13463 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13464 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13465 Formal
: Entity_Id
;
13468 Formal
:= First_Formal
(Bod_Subp
);
13469 while Present
(Formal
) loop
13471 -- Look for formal parameter _E
13473 if Chars
(Formal
) = Name_uE
then
13477 Next_Formal
(Formal
);
13480 -- A protected body subprogram should always have the parameter in
13483 raise Program_Error
;
13486 --------------------------------
13487 -- Make_Initialize_Protection --
13488 --------------------------------
13490 function Make_Initialize_Protection
13491 (Protect_Rec
: Entity_Id
) return List_Id
13493 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13496 Ptyp
: constant Node_Id
:=
13497 Corresponding_Concurrent_Type
(Protect_Rec
);
13499 L
: constant List_Id
:= New_List
;
13500 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13501 Prio_Type
: Entity_Id
;
13502 Prio_Var
: Entity_Id
:= Empty
;
13503 Restricted
: constant Boolean := Restricted_Profile
;
13506 -- We may need two calls to properly initialize the object, one to
13507 -- Initialize_Protection, and possibly one to Install_Handlers if we
13508 -- have a pragma Attach_Handler.
13510 -- Get protected declaration. In the case of a task type declaration,
13511 -- this is simply the parent of the protected type entity. In the single
13512 -- protected object declaration, this parent will be the implicit type,
13513 -- and we can find the corresponding single protected object declaration
13514 -- by searching forward in the declaration list in the tree.
13516 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13517 -- of this type should have been removed during semantic analysis.
13519 Pdec
:= Parent
(Ptyp
);
13520 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13521 N_Single_Protected_Declaration
)
13526 -- Build the parameter list for the call. Note that _Init is the name
13527 -- of the formal for the object to be initialized, which is the task
13528 -- value record itself.
13532 -- For lock-free implementation, skip initializations of the Protection
13535 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13536 -- Object parameter. This is a pointer to the object of type
13537 -- Protection used by the GNARL to control the protected object.
13540 Make_Attribute_Reference
(Loc
,
13542 Make_Selected_Component
(Loc
,
13543 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13544 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13545 Attribute_Name
=> Name_Unchecked_Access
));
13547 -- Priority parameter. Set to Unspecified_Priority unless there is a
13548 -- Priority rep item, in which case we take the value from the pragma
13549 -- or attribute definition clause, or there is an Interrupt_Priority
13550 -- rep item and no Priority rep item, and we set the ceiling to
13551 -- Interrupt_Priority'Last, an implementation-defined value, see
13554 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13556 Prio_Clause
: constant Node_Id
:=
13558 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13565 if Nkind
(Prio_Clause
) = N_Pragma
then
13568 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13570 -- Get_Rep_Item returns either priority pragma.
13572 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13573 Prio_Type
:= RTE
(RE_Any_Priority
);
13575 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13578 -- Attribute definition clause Priority
13581 if Chars
(Prio_Clause
) = Name_Priority
then
13582 Prio_Type
:= RTE
(RE_Any_Priority
);
13584 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13587 Prio
:= Expression
(Prio_Clause
);
13590 -- Always create a locale variable to capture the priority.
13591 -- The priority is also passed to Install_Restriced_Handlers.
13592 -- Note that it is really necessary to create this variable
13593 -- explicitly. It might be thought that removing side effects
13594 -- would the appropriate approach, but that could generate
13595 -- declarations improperly placed in the enclosing scope.
13597 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13599 Make_Object_Declaration
(Loc
,
13600 Defining_Identifier
=> Prio_Var
,
13601 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13602 Expression
=> Relocate_Node
(Prio
)));
13604 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13607 -- When no priority is specified but an xx_Handler pragma is, we
13608 -- default to System.Interrupts.Default_Interrupt_Priority, see
13611 elsif Has_Attach_Handler
(Ptyp
)
13612 or else Has_Interrupt_Handler
(Ptyp
)
13615 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13617 -- Normal case, no priority or xx_Handler specified, default priority
13621 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13624 -- Test for Compiler_Info parameter. This parameter allows entry body
13625 -- procedures and barrier functions to be called from the runtime. It
13626 -- is a pointer to the record generated by the compiler to represent
13627 -- the protected object.
13629 -- A protected type without entries that covers an interface and
13630 -- overrides the abstract routines with protected procedures is
13631 -- considered equivalent to a protected type with entries in the
13632 -- context of dispatching select statements.
13634 -- Protected types with interrupt handlers (when not using a
13635 -- restricted profile) are also considered equivalent to protected
13636 -- types with entries.
13638 -- The types which are used (Static_Interrupt_Protection and
13639 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13642 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13644 Called_Subp
: RE_Id
;
13648 when System_Tasking_Protected_Objects_Entries
=>
13649 Called_Subp
:= RE_Initialize_Protection_Entries
;
13651 -- Argument Compiler_Info
13654 Make_Attribute_Reference
(Loc
,
13655 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13656 Attribute_Name
=> Name_Address
));
13658 when System_Tasking_Protected_Objects_Single_Entry
=>
13659 Called_Subp
:= RE_Initialize_Protection_Entry
;
13661 -- Argument Compiler_Info
13664 Make_Attribute_Reference
(Loc
,
13665 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13666 Attribute_Name
=> Name_Address
));
13668 when System_Tasking_Protected_Objects
=>
13669 Called_Subp
:= RE_Initialize_Protection
;
13672 raise Program_Error
;
13675 -- Entry_Bodies parameter. This is a pointer to an array of
13676 -- pointers to the entry body procedures and barrier functions of
13677 -- the object. If the protected type has no entries this object
13678 -- will not exist, in this case, pass a null (it can happen when
13679 -- there are protected interrupt handlers or interfaces).
13682 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13684 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13685 -- multiple entries).
13688 Make_Attribute_Reference
(Loc
,
13689 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13690 Attribute_Name
=> Name_Unrestricted_Access
));
13692 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13694 -- Find index mapping function (clumsy but ok for now)
13696 while Ekind
(P_Arr
) /= E_Function
loop
13697 Next_Entity
(P_Arr
);
13701 Make_Attribute_Reference
(Loc
,
13702 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13703 Attribute_Name
=> Name_Unrestricted_Access
));
13706 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13708 -- This is the case where we have a protected object with
13709 -- interfaces and no entries, and the single entry restriction
13710 -- is in effect. We pass a null pointer for the entry
13711 -- parameter because there is no actual entry.
13713 Append_To
(Args
, Make_Null
(Loc
));
13715 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13717 -- This is the case where we have a protected object with no
13719 -- - either interrupt handlers with non restricted profile,
13721 -- Note that the types which are used for interrupt handlers
13722 -- (Static/Dynamic_Interrupt_Protection) are derived from
13723 -- Protection_Entries. We pass two null pointers because there
13724 -- is no actual entry, and the initialization procedure needs
13725 -- both Entry_Bodies and Find_Body_Index.
13727 Append_To
(Args
, Make_Null
(Loc
));
13728 Append_To
(Args
, Make_Null
(Loc
));
13732 Make_Procedure_Call_Statement
(Loc
,
13733 Name
=> New_Reference_To
(RTE
(Called_Subp
), Loc
),
13734 Parameter_Associations
=> Args
));
13738 if Has_Attach_Handler
(Ptyp
) then
13740 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13741 -- make the following call:
13743 -- Install_Handlers (_object,
13744 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13746 -- or, in the case of Ravenscar:
13748 -- Install_Restricted_Handlers
13749 -- (Prio, (Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13752 Args
: constant List_Id
:= New_List
;
13753 Table
: constant List_Id
:= New_List
;
13754 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13757 -- Build the Priority parameter (only for ravenscar)
13761 -- Priority comes from a pragma
13763 if Present
(Prio_Var
) then
13764 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13766 -- Priority is the default one
13771 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
13775 -- Build the Attach_Handler table argument
13777 while Present
(Ritem
) loop
13778 if Nkind
(Ritem
) = N_Pragma
13779 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13782 Handler
: constant Node_Id
:=
13783 First
(Pragma_Argument_Associations
(Ritem
));
13785 Interrupt
: constant Node_Id
:= Next
(Handler
);
13786 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13790 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13791 Unchecked_Convert_To
13792 (RTE
(RE_System_Interrupt_Id
), Expr
),
13793 Make_Attribute_Reference
(Loc
,
13794 Prefix
=> Make_Selected_Component
(Loc
,
13795 Make_Identifier
(Loc
, Name_uInit
),
13796 Duplicate_Subexpr_No_Checks
13797 (Expression
(Handler
))),
13798 Attribute_Name
=> Name_Access
))));
13802 Next_Rep_Item
(Ritem
);
13805 -- Append the table argument we just built
13807 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13809 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13810 -- call to the statements.
13813 -- Call a simplified version of Install_Handlers to be used
13814 -- when the Ravenscar restrictions are in effect
13815 -- (Install_Restricted_Handlers).
13818 Make_Procedure_Call_Statement
(Loc
,
13821 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13822 Parameter_Associations
=> Args
));
13825 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13826 -- First, prepends the _object argument
13829 Make_Attribute_Reference
(Loc
,
13831 Make_Selected_Component
(Loc
,
13832 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13834 Make_Identifier
(Loc
, Name_uObject
)),
13835 Attribute_Name
=> Name_Unchecked_Access
));
13838 -- Then, insert call to Install_Handlers
13841 Make_Procedure_Call_Statement
(Loc
,
13842 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
13843 Parameter_Associations
=> Args
));
13849 end Make_Initialize_Protection
;
13851 ---------------------------
13852 -- Make_Task_Create_Call --
13853 ---------------------------
13855 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
13856 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
13866 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
13867 Tnam
:= Chars
(Ttyp
);
13869 -- Get task declaration. In the case of a task type declaration, this is
13870 -- simply the parent of the task type entity. In the single task
13871 -- declaration, this parent will be the implicit type, and we can find
13872 -- the corresponding single task declaration by searching forward in the
13873 -- declaration list in the tree.
13875 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13876 -- this type should have been removed during semantic analysis.
13878 Tdec
:= Parent
(Ttyp
);
13879 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
13880 N_Single_Task_Declaration
)
13885 -- Now we can find the task definition from this declaration
13887 Tdef
:= Task_Definition
(Tdec
);
13889 -- Build the parameter list for the call. Note that _Init is the name
13890 -- of the formal for the object to be initialized, which is the task
13891 -- value record itself.
13895 -- Priority parameter. Set to Unspecified_Priority unless there is a
13896 -- Priority rep item, in which case we take the value from the rep item.
13898 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
13900 Make_Selected_Component
(Loc
,
13901 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13902 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
13905 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13908 -- Optional Stack parameter
13910 if Restricted_Profile
then
13912 -- If the stack has been preallocated by the expander then
13913 -- pass its address. Otherwise, pass a null address.
13915 if Preallocated_Stacks_On_Target
then
13917 Make_Attribute_Reference
(Loc
,
13919 Make_Selected_Component
(Loc
,
13920 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13921 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
13922 Attribute_Name
=> Name_Address
));
13926 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
13930 -- Size parameter. If no Storage_Size pragma is present, then
13931 -- the size is taken from the taskZ variable for the type, which
13932 -- is either Unspecified_Size, or has been reset by the use of
13933 -- a Storage_Size attribute definition clause. If a pragma is
13934 -- present, then the size is taken from the _Size field of the
13935 -- task value record, which was set from the pragma value.
13938 and then Has_Storage_Size_Pragma
(Tdef
)
13941 Make_Selected_Component
(Loc
,
13942 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13943 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
13947 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
13950 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
13951 -- Task_Info pragma, in which case we take the value from the pragma.
13953 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
13955 Make_Selected_Component
(Loc
,
13956 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13957 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
13961 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
13964 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
13965 -- in which case we take the value from the rep item. The parameter is
13966 -- passed as an Integer because in the case of unspecified CPU the
13967 -- value is not in the range of CPU_Range.
13969 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
13971 Convert_To
(Standard_Integer
,
13972 Make_Selected_Component
(Loc
,
13973 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13974 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
13977 New_Reference_To
(RTE
(RE_Unspecified_CPU
), Loc
));
13980 if not Restricted_Profile
then
13982 -- Deadline parameter. If no Relative_Deadline pragma is present,
13983 -- then the deadline is Time_Span_Zero. If a pragma is present, then
13984 -- the deadline is taken from the _Relative_Deadline field of the
13985 -- task value record, which was set from the pragma value. Note that
13986 -- this parameter must not be generated for the restricted profiles
13987 -- since Ravenscar does not allow deadlines.
13989 -- Case where pragma Relative_Deadline applies: use given value
13992 and then Has_Relative_Deadline_Pragma
(Tdef
)
13995 Make_Selected_Component
(Loc
,
13997 Make_Identifier
(Loc
, Name_uInit
),
13999 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14001 -- No pragma Relative_Deadline apply to the task
14005 New_Reference_To
(RTE
(RE_Time_Span_Zero
), Loc
));
14008 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14009 -- present, then the dispatching domain is null. If a rep item is
14010 -- present, then the dispatching domain is taken from the
14011 -- _Dispatching_Domain field of the task value record, which was set
14012 -- from the rep item value. Note that this parameter must not be
14013 -- generated for the restricted profiles since Ravenscar does not
14014 -- allow dispatching domains.
14016 -- Case where Dispatching_Domain rep item applies: use given value
14019 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14022 Make_Selected_Component
(Loc
,
14024 Make_Identifier
(Loc
, Name_uInit
),
14026 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14028 -- No pragma or aspect Dispatching_Domain apply to the task
14031 Append_To
(Args
, Make_Null
(Loc
));
14034 -- Number of entries. This is an expression of the form:
14036 -- n + _Init.a'Length + _Init.a'B'Length + ...
14038 -- where a,b... are the entry family names for the task definition
14041 Build_Entry_Count_Expression
14046 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14048 Append_To
(Args
, Ecount
);
14050 -- Master parameter. This is a reference to the _Master parameter of
14051 -- the initialization procedure, except in the case of the pragma
14052 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14053 -- System.Tasking.Library_Task_Level.
14055 if Restriction_Active
(No_Task_Hierarchy
) = False then
14056 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14059 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14063 -- State parameter. This is a pointer to the task body procedure. The
14064 -- required value is obtained by taking 'Unrestricted_Access of the task
14065 -- body procedure and converting it (with an unchecked conversion) to
14066 -- the type required by the task kernel. For further details, see the
14067 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14068 -- than 'Address in order to avoid creating trampolines.
14071 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14072 Subp_Ptr_Typ
: constant Node_Id
:=
14073 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14074 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14077 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14078 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14080 -- Be sure to freeze a reference to the access-to-subprogram type,
14081 -- otherwise gigi will complain that it's in the wrong scope, because
14082 -- it's actually inside the init procedure for the record type that
14083 -- corresponds to the task type.
14085 -- This processing is causing a crash in the .NET/JVM back ends that
14086 -- is not yet understood, so skip it in these cases ???
14088 if VM_Target
= No_VM
then
14089 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14090 Append_Freeze_Action
(Task_Rec
, Ref
);
14093 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14094 Make_Qualified_Expression
(Loc
,
14095 Subtype_Mark
=> New_Reference_To
(Subp_Ptr_Typ
, Loc
),
14097 Make_Attribute_Reference
(Loc
,
14099 New_Occurrence_Of
(Body_Proc
, Loc
),
14100 Attribute_Name
=> Name_Unrestricted_Access
))));
14102 -- For the .NET/JVM cases revert to the original code below ???
14106 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14107 Make_Attribute_Reference
(Loc
,
14109 New_Occurrence_Of
(Body_Proc
, Loc
),
14110 Attribute_Name
=> Name_Address
)));
14114 -- Discriminants parameter. This is just the address of the task
14115 -- value record itself (which contains the discriminant values
14118 Make_Attribute_Reference
(Loc
,
14119 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14120 Attribute_Name
=> Name_Address
));
14122 -- Elaborated parameter. This is an access to the elaboration Boolean
14125 Make_Attribute_Reference
(Loc
,
14126 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14127 Attribute_Name
=> Name_Unchecked_Access
));
14129 -- Add Chain parameter (not done for sequential elaboration policy, see
14130 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14132 if Partition_Elaboration_Policy
/= 'S' then
14133 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14136 -- Task name parameter. Take this from the _Task_Id parameter to the
14137 -- init call unless there is a Task_Name pragma, in which case we take
14138 -- the value from the pragma.
14140 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14141 -- Copy expression in full, because it may be dynamic and have
14148 (Pragma_Argument_Associations
14150 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14153 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14156 -- Created_Task parameter. This is the _Task_Id field of the task
14160 Make_Selected_Component
(Loc
,
14161 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14162 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14168 if Restricted_Profile
then
14169 if Partition_Elaboration_Policy
= 'S' then
14170 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14172 Create_RE
:= RE_Create_Restricted_Task
;
14175 Create_RE
:= RE_Create_Task
;
14178 Name
:= New_Reference_To
(RTE
(Create_RE
), Loc
);
14182 Make_Procedure_Call_Statement
(Loc
,
14184 Parameter_Associations
=> Args
);
14185 end Make_Task_Create_Call
;
14187 ------------------------------
14188 -- Next_Protected_Operation --
14189 ------------------------------
14191 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14195 Next_Op
:= Next
(N
);
14196 while Present
(Next_Op
)
14197 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
14203 end Next_Protected_Operation
;
14205 ---------------------
14206 -- Null_Statements --
14207 ---------------------
14209 function Null_Statements
(Stats
: List_Id
) return Boolean is
14213 Stmt
:= First
(Stats
);
14214 while Nkind
(Stmt
) /= N_Empty
14215 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14217 (Nkind
(Stmt
) = N_Pragma
14219 Nam_In
(Pragma_Name
(Stmt
), Name_Unreferenced
,
14226 return Nkind
(Stmt
) = N_Empty
;
14227 end Null_Statements
;
14229 --------------------------
14230 -- Parameter_Block_Pack --
14231 --------------------------
14233 function Parameter_Block_Pack
14235 Blk_Typ
: Entity_Id
;
14239 Stmts
: List_Id
) return Node_Id
14241 Actual
: Entity_Id
;
14242 Expr
: Node_Id
:= Empty
;
14243 Formal
: Entity_Id
;
14244 Has_Param
: Boolean := False;
14247 Temp_Asn
: Node_Id
;
14248 Temp_Nam
: Node_Id
;
14251 Actual
:= First
(Actuals
);
14252 Formal
:= Defining_Identifier
(First
(Formals
));
14253 Params
:= New_List
;
14255 while Present
(Actual
) loop
14256 if Is_By_Copy_Type
(Etype
(Actual
)) then
14258 -- Jnn : aliased <formal-type>
14260 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14263 Make_Object_Declaration
(Loc
,
14266 Defining_Identifier
=>
14268 Object_Definition
=>
14269 New_Reference_To
(Etype
(Formal
), Loc
)));
14271 if Ekind
(Formal
) /= E_Out_Parameter
then
14277 New_Reference_To
(Temp_Nam
, Loc
);
14279 Set_Assignment_OK
(Temp_Asn
);
14282 Make_Assignment_Statement
(Loc
,
14286 New_Copy_Tree
(Actual
)));
14290 -- Jnn'unchecked_access
14293 Make_Attribute_Reference
(Loc
,
14295 Name_Unchecked_Access
,
14297 New_Reference_To
(Temp_Nam
, Loc
)));
14301 -- The controlling parameter is omitted
14304 if not Is_Controlling_Actual
(Actual
) then
14306 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14312 Next_Actual
(Actual
);
14313 Next_Formal_With_Extras
(Formal
);
14317 Expr
:= Make_Aggregate
(Loc
, Params
);
14322 -- J1'unchecked_access;
14323 -- <actual2>'reference;
14326 P
:= Make_Temporary
(Loc
, 'P');
14329 Make_Object_Declaration
(Loc
,
14330 Defining_Identifier
=>
14332 Object_Definition
=>
14333 New_Reference_To
(Blk_Typ
, Loc
),
14338 end Parameter_Block_Pack
;
14340 ----------------------------
14341 -- Parameter_Block_Unpack --
14342 ----------------------------
14344 function Parameter_Block_Unpack
14348 Formals
: List_Id
) return List_Id
14350 Actual
: Entity_Id
;
14352 Formal
: Entity_Id
;
14353 Has_Asnmt
: Boolean := False;
14354 Result
: constant List_Id
:= New_List
;
14357 Actual
:= First
(Actuals
);
14358 Formal
:= Defining_Identifier
(First
(Formals
));
14359 while Present
(Actual
) loop
14360 if Is_By_Copy_Type
(Etype
(Actual
))
14361 and then Ekind
(Formal
) /= E_In_Parameter
14364 -- <actual> := P.<formal>;
14367 Make_Assignment_Statement
(Loc
,
14371 Make_Explicit_Dereference
(Loc
,
14372 Make_Selected_Component
(Loc
,
14374 New_Reference_To
(P
, Loc
),
14376 Make_Identifier
(Loc
, Chars
(Formal
)))));
14378 Set_Assignment_OK
(Name
(Asnmt
));
14379 Append_To
(Result
, Asnmt
);
14384 Next_Actual
(Actual
);
14385 Next_Formal_With_Extras
(Formal
);
14391 return New_List
(Make_Null_Statement
(Loc
));
14393 end Parameter_Block_Unpack
;
14395 ----------------------
14396 -- Set_Discriminals --
14397 ----------------------
14399 procedure Set_Discriminals
(Dec
: Node_Id
) is
14402 D_Minal
: Entity_Id
;
14405 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14406 Pdef
:= Defining_Identifier
(Dec
);
14408 if Has_Discriminants
(Pdef
) then
14409 D
:= First_Discriminant
(Pdef
);
14410 while Present
(D
) loop
14412 Make_Defining_Identifier
(Sloc
(D
),
14413 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14415 Set_Ekind
(D_Minal
, E_Constant
);
14416 Set_Etype
(D_Minal
, Etype
(D
));
14417 Set_Scope
(D_Minal
, Pdef
);
14418 Set_Discriminal
(D
, D_Minal
);
14419 Set_Discriminal_Link
(D_Minal
, D
);
14421 Next_Discriminant
(D
);
14424 end Set_Discriminals
;
14426 -----------------------
14427 -- Trivial_Accept_OK --
14428 -----------------------
14430 function Trivial_Accept_OK
return Boolean is
14432 case Opt
.Task_Dispatching_Policy
is
14434 -- If we have the default task dispatching policy in effect, we can
14435 -- definitely do the optimization (one way of looking at this is to
14436 -- think of the formal definition of the default policy being allowed
14437 -- to run any task it likes after a rendezvous, so even if notionally
14438 -- a full rescheduling occurs, we can say that our dispatching policy
14439 -- (i.e. the default dispatching policy) reorders the queue to be the
14440 -- same as just before the call.
14445 -- FIFO_Within_Priorities certainly does not permit this
14446 -- optimization since the Rendezvous is a scheduling action that may
14447 -- require some other task to be run.
14452 -- For now, disallow the optimization for all other policies. This
14453 -- may be over-conservative, but it is certainly not incorrect.
14459 end Trivial_Accept_OK
;