1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Exp_Ch3
; use Exp_Ch3
;
32 with Exp_Ch6
; use Exp_Ch6
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Dbug
; use Exp_Dbug
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Sel
; use Exp_Sel
;
37 with Exp_Smem
; use Exp_Smem
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Exp_Util
; use Exp_Util
;
40 with Freeze
; use Freeze
;
42 with Itypes
; use Itypes
;
43 with Namet
; use Namet
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Ch9
; use Sem_Ch9
;
55 with Sem_Ch11
; use Sem_Ch11
;
56 with Sem_Elab
; use Sem_Elab
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Util
; use Sem_Util
;
60 with Sinfo
; use Sinfo
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Stringt
; use Stringt
;
64 with Targparm
; use Targparm
;
65 with Tbuild
; use Tbuild
;
66 with Uintp
; use Uintp
;
68 package body Exp_Ch9
is
70 -- The following constant establishes the upper bound for the index of
71 -- an entry family. It is used to limit the allocated size of protected
72 -- types with defaulted discriminant of an integer type, when the bound
73 -- of some entry family depends on a discriminant. The limitation to entry
74 -- families of 128K should be reasonable in all cases, and is a documented
75 -- implementation restriction.
77 Entry_Family_Bound
: constant Int
:= 2**16;
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 function Actual_Index_Expression
87 Tsk
: Entity_Id
) return Node_Id
;
88 -- Compute the index position for an entry call. Tsk is the target task. If
89 -- the bounds of some entry family depend on discriminants, the expression
90 -- computed by this function uses the discriminants of the target task.
92 procedure Add_Object_Pointer
96 -- Prepend an object pointer declaration to the declaration list Decls.
97 -- This object pointer is initialized to a type conversion of the System.
98 -- Address pointer passed to entry barrier functions and entry body
101 procedure Add_Formal_Renamings
106 -- Create renaming declarations for the formals, inside the procedure that
107 -- implements an entry body. The renamings make the original names of the
108 -- formals accessible to gdb, and serve no other purpose.
109 -- Spec is the specification of the procedure being built.
110 -- Decls is the list of declarations to be enhanced.
111 -- Ent is the entity for the original entry body.
113 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
114 -- Transform accept statement into a block with added exception handler.
115 -- Used both for simple accept statements and for accept alternatives in
116 -- select statements. Astat is the accept statement.
118 function Build_Barrier_Function
121 Pid
: Node_Id
) return Node_Id
;
122 -- Build the function body returning the value of the barrier expression
123 -- for the specified entry body.
125 function Build_Barrier_Function_Specification
127 Def_Id
: Entity_Id
) return Node_Id
;
128 -- Build a specification for a function implementing the protected entry
129 -- barrier of the specified entry body.
131 function Build_Corresponding_Record
134 Loc
: Source_Ptr
) return Node_Id
;
135 -- Common to tasks and protected types. Copy discriminant specifications,
136 -- build record declaration. N is the type declaration, Ctyp is the
137 -- concurrent entity (task type or protected type).
139 function Build_Dispatching_Tag_Check
141 N
: Node_Id
) return Node_Id
;
142 -- Utility to create the tree to check whether the dispatching call in
143 -- a timed entry call, a conditional entry call, or an asynchronous
144 -- transfer of control is a call to a primitive of a non-synchronized type.
145 -- K is the temporary that holds the tagged kind of the target object, and
146 -- N is the enclosing construct.
148 function Build_Entry_Count_Expression
149 (Concurrent_Type
: Node_Id
;
150 Component_List
: List_Id
;
151 Loc
: Source_Ptr
) return Node_Id
;
152 -- Compute number of entries for concurrent object. This is a count of
153 -- simple entries, followed by an expression that computes the length
154 -- of the range of each entry family. A single array with that size is
155 -- allocated for each concurrent object of the type.
157 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
158 -- Build the function that translates the entry index in the call
159 -- (which depends on the size of entry families) into an index into the
160 -- Entry_Bodies_Array, to determine the body and barrier function used
161 -- in a protected entry call. A pointer to this function appears in every
164 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
165 -- Build subprogram declaration for previous one
167 function Build_Lock_Free_Protected_Subprogram_Body
170 Unprot_Spec
: Node_Id
) return Node_Id
;
171 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
172 -- the subprogram specification of the unprotected version of N. Transform
173 -- N such that it invokes the unprotected version of the body.
175 function Build_Lock_Free_Unprotected_Subprogram_Body
177 Prot_Typ
: Node_Id
) return Node_Id
;
178 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
179 -- of N where the original statements of N are synchronized through atomic
180 -- actions such as compare and exchange. Prior to invoking this routine, it
181 -- has been established that N can be implemented in a lock-free fashion.
183 function Build_Parameter_Block
187 Decls
: List_Id
) return Entity_Id
;
188 -- Generate an access type for each actual parameter in the list Actuals.
189 -- Create an encapsulating record that contains all the actuals and return
190 -- its type. Generate:
191 -- type Ann1 is access all <actual1-type>
193 -- type AnnN is access all <actualN-type>
194 -- type Pnn is record
200 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
201 -- Build body of wrapper procedure for an entry or entry family that has
202 -- pre/postconditions. The body gathers the PPC's and expands them in the
203 -- usual way, and performs the entry call itself. This way preconditions
204 -- are evaluated before the call is queued. E is the entry in question,
205 -- and Decl is the enclosing synchronized type declaration at whose freeze
206 -- point the generated body is analyzed.
208 function Build_Protected_Entry
211 Pid
: Node_Id
) return Node_Id
;
212 -- Build the procedure implementing the statement sequence of the specified
215 function Build_Protected_Entry_Specification
218 Ent_Id
: Entity_Id
) return Node_Id
;
219 -- Build a specification for the procedure implementing the statements of
220 -- the specified entry body. Add attributes associating it with the entry
221 -- defining identifier Ent_Id.
223 function Build_Protected_Spec
225 Obj_Type
: Entity_Id
;
227 Unprotected
: Boolean := False) return List_Id
;
228 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
229 -- Subprogram_Type. Builds signature of protected subprogram, adding the
230 -- formal that corresponds to the object itself. For an access to protected
231 -- subprogram, there is no object type to specify, so the parameter has
232 -- type Address and mode In. An indirect call through such a pointer will
233 -- convert the address to a reference to the actual object. The object is
234 -- a limited record and therefore a by_reference type.
236 function Build_Protected_Subprogram_Body
239 N_Op_Spec
: Node_Id
) return Node_Id
;
240 -- This function is used to construct the protected version of a protected
241 -- subprogram. Its statement sequence first defers abort, then locks the
242 -- associated protected object, and then enters a block that contains a
243 -- call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires a
245 -- cleanup handler that unlocks the object in all cases. For details,
246 -- see Exp_Ch7.Expand_Cleanup_Actions.
248 function Build_Renamed_Formal_Declaration
252 Renamed_Formal
: Node_Id
) return Node_Id
;
253 -- Create a renaming declaration for a formal, within a protected entry
254 -- body or an accept body. The renamed object is a component of the
255 -- parameter block that is a parameter in the entry call.
257 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
258 -- does not dereference the corresponding component to prevent an illegal
259 -- use of the incomplete type (AI05-0151).
261 function Build_Selected_Name
263 Selector
: Entity_Id
;
264 Append_Char
: Character := ' ') return Name_Id
;
265 -- Build a name in the form of Prefix__Selector, with an optional character
266 -- appended. This is used for internal subprograms generated for operations
267 -- of protected types, including barrier functions. For the subprograms
268 -- generated for entry bodies and entry barriers, the generated name
269 -- includes a sequence number that makes names unique in the presence of
270 -- entry overloading. This is necessary because entry body procedures and
271 -- barrier functions all have the same signature.
273 procedure Build_Simple_Entry_Call
278 -- Some comments here would be useful ???
280 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
281 -- This routine constructs a specification for the procedure that we will
282 -- build for the task body for task type T. The spec has the form:
284 -- procedure tnameB (_Task : access tnameV);
286 -- where name is the character name taken from the task type entity that
287 -- is passed as the argument to the procedure, and tnameV is the task
288 -- value type that is associated with the task type.
290 function Build_Unprotected_Subprogram_Body
292 Pid
: Node_Id
) return Node_Id
;
293 -- This routine constructs the unprotected version of a protected
294 -- subprogram body, which is contains all of the code in the original,
295 -- unexpanded body. This is the version of the protected subprogram that is
296 -- called from all protected operations on the same object, including the
297 -- protected version of the same subprogram.
299 procedure Build_Wrapper_Bodies
303 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
304 -- record of a concurrent type. N is the insertion node where all bodies
305 -- will be placed. This routine builds the bodies of the subprograms which
306 -- serve as an indirection mechanism to overriding primitives of concurrent
307 -- types, entries and protected procedures. Any new body is analyzed.
309 procedure Build_Wrapper_Specs
313 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
314 -- record of a concurrent type. N is the insertion node where all specs
315 -- will be placed. This routine builds the specs of the subprograms which
316 -- serve as an indirection mechanism to overriding primitives of concurrent
317 -- types, entries and protected procedures. Any new spec is analyzed.
319 procedure Collect_Entry_Families
322 Current_Node
: in out Node_Id
;
323 Conctyp
: Entity_Id
);
324 -- For each entry family in a concurrent type, create an anonymous array
325 -- type of the right size, and add a component to the corresponding_record.
327 function Concurrent_Object
328 (Spec_Id
: Entity_Id
;
329 Conc_Typ
: Entity_Id
) return Entity_Id
;
330 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
331 -- the entity associated with the concurrent object in the Protected_Body_
332 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
333 -- denotes formal parameter _O, _object or _task.
335 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
336 -- Copy the result type of a function specification, when building the
337 -- internal operation corresponding to a protected function, or when
338 -- expanding an access to protected function. If the result is an anonymous
339 -- access to subprogram itself, we need to create a new signature with the
340 -- same parameter names and the same resolved types, but with new entities
343 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
344 -- Decls is a list which may contain the declarations created by Install_
345 -- Private_Data_Declarations. All generated entities are marked as needing
346 -- debug info and debug nodes are manually generation where necessary. This
347 -- step of the expansion must to be done after private data has been moved
348 -- to its final resting scope to ensure proper visibility of debug objects.
350 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
351 -- If control flow optimizations are suppressed, and Alt is an accept,
352 -- delay, or entry call alternative with no trailing statements, insert
353 -- a null trailing statement with the given Loc (which is the sloc of
354 -- the accept, delay, or entry call statement). There might not be any
355 -- generated code for the accept, delay, or entry call itself (the effect
356 -- of these statements is part of the general processsing done for the
357 -- enclosing selective accept, timed entry call, or asynchronous select),
358 -- and the null statement is there to carry the sloc of that statement to
359 -- the back-end for trace-based coverage analysis purposes.
361 procedure Extract_Dispatching_Call
363 Call_Ent
: out Entity_Id
;
364 Object
: out Entity_Id
;
365 Actuals
: out List_Id
;
366 Formals
: out List_Id
);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval
: out Node_Id
;
377 Index
: out Node_Id
);
378 -- Given an entry call, returns the associated concurrent object, the entry
379 -- name, and the entry family index.
381 function Family_Offset
386 Cap
: Boolean) return Node_Id
;
387 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
388 -- accept statement, or the upper bound in the discrete subtype of an entry
389 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
390 -- type of the entry. If Cap is true, the result is capped according to
391 -- Entry_Family_Bound.
398 Cap
: Boolean) return Node_Id
;
399 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
400 -- family, and handle properly the superflat case. This is equivalent to
401 -- the use of 'Length on the index type, but must use Family_Offset to
402 -- handle properly the case of bounds that depend on discriminants. If
403 -- Cap is true, the result is capped according to Entry_Family_Bound.
405 procedure Find_Enclosing_Context
407 Context
: out Node_Id
;
408 Context_Id
: out Entity_Id
;
409 Context_Decls
: out List_Id
);
410 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
411 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
412 -- nearest enclosing body, block, package or return statement and return
413 -- its constituents. Context is the enclosing construct, Context_Id is
414 -- the scope of Context_Id and Context_Decls is the declarative list of
417 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
418 -- Given a subprogram identifier, return the entity which is associated
419 -- with the protection entry index in the Protected_Body_Subprogram or
420 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
423 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
424 -- Tell whether a given subprogram cannot raise an exception
426 function Is_Potentially_Large_Family
427 (Base_Index
: Entity_Id
;
430 Hi
: Node_Id
) return Boolean;
432 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
433 -- Determine whether Id is a function or a procedure and is marked as a
434 -- private primitive.
436 function Null_Statements
(Stats
: List_Id
) return Boolean;
437 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
438 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
439 -- to still count as null. Returns True for a null sequence. The argument
440 -- is the list of statements from the DO-END sequence.
442 function Parameter_Block_Pack
448 Stmts
: List_Id
) return Entity_Id
;
449 -- Set the components of the generated parameter block with the values
450 -- of the actual parameters. Generate aliased temporaries to capture the
451 -- values for types that are passed by copy. Otherwise generate a reference
452 -- to the actual's value. Return the address of the aggregate block.
454 -- Jnn1 : alias <formal-type1>;
455 -- Jnn1 := <actual1>;
458 -- Jnn1'unchecked_access;
459 -- <actual2>'reference;
462 function Parameter_Block_Unpack
466 Formals
: List_Id
) return List_Id
;
467 -- Retrieve the values of the components from the parameter block and
468 -- assign then to the original actual parameters. Generate:
469 -- <actual1> := P.<formal1>;
471 -- <actualN> := P.<formalN>;
473 function Trivial_Accept_OK
return Boolean;
474 -- If there is no DO-END block for an accept, or if the DO-END block has
475 -- only null statements, then it is possible to do the Rendezvous with much
476 -- less overhead using the Accept_Trivial routine in the run-time library.
477 -- However, this is not always a valid optimization. Whether it is valid or
478 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
479 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
480 -- a rescheduling is required, so this optimization is not allowed. This
481 -- function returns True if the optimization is permitted.
483 -----------------------------
484 -- Actual_Index_Expression --
485 -----------------------------
487 function Actual_Index_Expression
491 Tsk
: Entity_Id
) return Node_Id
493 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
501 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
502 -- Compute difference between bounds of entry family
504 --------------------------
505 -- Actual_Family_Offset --
506 --------------------------
508 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
510 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
511 -- Replace a reference to a discriminant with a selected component
512 -- denoting the discriminant of the target task.
514 -----------------------------
515 -- Actual_Discriminant_Ref --
516 -----------------------------
518 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
519 Typ
: constant Entity_Id
:= Etype
(Bound
);
523 if not Is_Entity_Name
(Bound
)
524 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
526 if Nkind
(Bound
) = N_Attribute_Reference
then
529 B
:= New_Copy_Tree
(Bound
);
534 Make_Selected_Component
(Sloc
,
535 Prefix
=> New_Copy_Tree
(Tsk
),
536 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
538 Analyze_And_Resolve
(B
, Typ
);
542 Make_Attribute_Reference
(Sloc
,
543 Attribute_Name
=> Name_Pos
,
544 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
545 Expressions
=> New_List
(B
));
546 end Actual_Discriminant_Ref
;
548 -- Start of processing for Actual_Family_Offset
552 Make_Op_Subtract
(Sloc
,
553 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
554 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
555 end Actual_Family_Offset
;
557 -- Start of processing for Actual_Index_Expression
560 -- The queues of entries and entry families appear in textual order in
561 -- the associated record. The entry index is computed as the sum of the
562 -- number of queues for all entries that precede the designated one, to
563 -- which is added the index expression, if this expression denotes a
564 -- member of a family.
566 -- The following is a place holder for the count of simple entries
568 Num
:= Make_Integer_Literal
(Sloc
, 1);
570 -- We construct an expression which is a series of addition operations.
571 -- See comments in Entry_Index_Expression, which is identical in
574 if Present
(Index
) then
575 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
582 Actual_Family_Offset
(
583 Make_Attribute_Reference
(Sloc
,
584 Attribute_Name
=> Name_Pos
,
585 Prefix
=> New_Occurrence_Of
(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
);
595 while Chars
(Prev
) /= Chars
(Ent
)
596 or else (Ekind
(Prev
) /= Ekind
(Ent
))
597 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
599 if Ekind
(Prev
) = E_Entry
then
600 Set_Intval
(Num
, Intval
(Num
) + 1);
602 elsif Ekind
(Prev
) = E_Entry_Family
then
604 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
606 -- The need for the following full view retrieval stems from this
607 -- complex case of nested generics and tasking:
610 -- type Formal_Index is range <>;
613 -- type Index is private;
620 -- type Index is new Formal_Index range 1 .. 10;
623 -- package body Outer is
625 -- entry Fam (Index); -- (2)
628 -- package body Inner is -- (3)
636 -- We are currently building the index expression for the entry
637 -- call "T.E" (1). Part of the expansion must mention the range
638 -- of the discrete type "Index" (2) of entry family "Fam".
640 -- However only the private view of type "Index" is available to
641 -- the inner generic (3) because there was no prior mention of
642 -- the type inside "Inner". This visibility requirement is
643 -- implicit and cannot be detected during the construction of
644 -- the generic trees and needs special handling.
647 and then Is_Private_Type
(S
)
648 and then Present
(Full_View
(S
))
653 Lo
:= Type_Low_Bound
(S
);
654 Hi
:= Type_High_Bound
(S
);
662 Actual_Family_Offset
(Hi
, Lo
),
664 Make_Integer_Literal
(Sloc
, 1)));
666 -- Other components are anonymous types to be ignored
676 end Actual_Index_Expression
;
678 --------------------------
679 -- Add_Formal_Renamings --
680 --------------------------
682 procedure Add_Formal_Renamings
688 Ptr
: constant Entity_Id
:=
690 (Next
(First
(Parameter_Specifications
(Spec
))));
691 -- The name of the formal that holds the address of the parameter block
698 Renamed_Formal
: Node_Id
;
701 Formal
:= First_Formal
(Ent
);
702 while Present
(Formal
) loop
703 Comp
:= Entry_Component
(Formal
);
705 Make_Defining_Identifier
(Sloc
(Formal
),
706 Chars
=> Chars
(Formal
));
707 Set_Etype
(New_F
, Etype
(Formal
));
708 Set_Scope
(New_F
, Ent
);
710 -- Now we set debug info needed on New_F even though it does not come
711 -- from source, so that the debugger will get the right information
712 -- for these generated names.
714 Set_Debug_Info_Needed
(New_F
);
716 if Ekind
(Formal
) = E_In_Parameter
then
717 Set_Ekind
(New_F
, E_Constant
);
719 Set_Ekind
(New_F
, E_Variable
);
720 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
723 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
726 Make_Selected_Component
(Loc
,
728 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
729 Make_Identifier
(Loc
, Chars
(Ptr
))),
730 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
733 Build_Renamed_Formal_Declaration
734 (New_F
, Formal
, Comp
, Renamed_Formal
);
736 Append
(Decl
, Decls
);
737 Set_Renamed_Object
(Formal
, New_F
);
738 Next_Formal
(Formal
);
740 end Add_Formal_Renamings
;
742 ------------------------
743 -- Add_Object_Pointer --
744 ------------------------
746 procedure Add_Object_Pointer
748 Conc_Typ
: Entity_Id
;
751 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
756 -- Create the renaming declaration for the Protection object of a
757 -- protected type. _Object is used by Complete_Entry_Body.
758 -- ??? An attempt to make this a renaming was unsuccessful.
760 -- Build the entity for the access type
763 Make_Defining_Identifier
(Loc
,
764 New_External_Name
(Chars
(Rec_Typ
), 'P'));
767 -- _object : poVP := poVP!O;
770 Make_Object_Declaration
(Loc
,
771 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uObject
),
772 Object_Definition
=> New_Occurrence_Of
(Obj_Ptr
, Loc
),
774 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
775 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
776 Prepend_To
(Decls
, Decl
);
779 -- type poVP is access poV;
782 Make_Full_Type_Declaration
(Loc
,
783 Defining_Identifier
=>
786 Make_Access_To_Object_Definition
(Loc
,
787 Subtype_Indication
=>
788 New_Occurrence_Of
(Rec_Typ
, Loc
)));
789 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
790 Prepend_To
(Decls
, Decl
);
791 end Add_Object_Pointer
;
793 -----------------------
794 -- Build_Accept_Body --
795 -----------------------
797 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
798 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
799 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
806 -- At the end of the statement sequence, Complete_Rendezvous is called.
807 -- A label skipping the Complete_Rendezvous, and all other accept
808 -- processing, has already been added for the expansion of requeue
809 -- statements. The Sloc is copied from the last statement since it
810 -- is really part of this last statement.
814 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
815 Insert_Before
(Last
(Statements
(Stats
)), Call
);
818 -- If exception handlers are present, then append Complete_Rendezvous
819 -- calls to the handlers, and construct the required outer block. As
820 -- above, the Sloc is copied from the last statement in the sequence.
822 if Present
(Exception_Handlers
(Stats
)) then
823 Hand
:= First
(Exception_Handlers
(Stats
));
824 while Present
(Hand
) loop
827 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
828 Append
(Call
, Statements
(Hand
));
834 Make_Handled_Sequence_Of_Statements
(Loc
,
835 Statements
=> New_List
(
836 Make_Block_Statement
(Loc
,
837 Handled_Statement_Sequence
=> Stats
)));
843 -- At this stage we know that the new statement sequence does
844 -- not have an exception handler part, so we supply one to call
845 -- Exceptional_Complete_Rendezvous. This handler is
847 -- when all others =>
848 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
850 -- We handle Abort_Signal to make sure that we properly catch the abort
851 -- case and wake up the caller.
853 Ohandle
:= Make_Others_Choice
(Loc
);
854 Set_All_Others
(Ohandle
);
856 Set_Exception_Handlers
(New_S
,
858 Make_Implicit_Exception_Handler
(Loc
,
859 Exception_Choices
=> New_List
(Ohandle
),
861 Statements
=> New_List
(
862 Make_Procedure_Call_Statement
(Sloc
(Stats
),
863 Name
=> New_Occurrence_Of
(
864 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
865 Parameter_Associations
=> New_List
(
866 Make_Function_Call
(Sloc
(Stats
),
869 (RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
871 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
872 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
873 Expand_Exception_Handlers
(New_S
);
875 -- Exceptional_Complete_Rendezvous must be called with abort still
876 -- deferred, which is the case for a "when all others" handler.
879 end Build_Accept_Body
;
881 -----------------------------------
882 -- Build_Activation_Chain_Entity --
883 -----------------------------------
885 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
886 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
887 -- Determine whether an extended return statement has activation chain
889 --------------------------
890 -- Has_Activation_Chain --
891 --------------------------
893 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
897 Decl
:= First
(Return_Object_Declarations
(Stmt
));
898 while Present
(Decl
) loop
899 if Nkind
(Decl
) = N_Object_Declaration
900 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
909 end Has_Activation_Chain
;
914 Context_Id
: Entity_Id
;
917 -- Start of processing for Build_Activation_Chain_Entity
920 -- Activation chain is never used for sequential elaboration policy, see
921 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
923 if Partition_Elaboration_Policy
= 'S' then
927 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
929 -- If activation chain entity has not been declared already, create one
931 if Nkind
(Context
) = N_Extended_Return_Statement
932 or else No
(Activation_Chain_Entity
(Context
))
934 -- Since extended return statements do not store the entity of the
935 -- chain, examine the return object declarations to avoid creating
938 if Nkind
(Context
) = N_Extended_Return_Statement
939 and then Has_Activation_Chain
(Context
)
945 Loc
: constant Source_Ptr
:= Sloc
(Context
);
950 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
952 -- Note: An extended return statement is not really a task
953 -- activator, but it does have an activation chain on which to
954 -- store the tasks temporarily. On successful return, the tasks
955 -- on this chain are moved to the chain passed in by the caller.
956 -- We do not build an Activation_Chain_Entity for an extended
957 -- return statement, because we do not want to build a call to
958 -- Activate_Tasks. Task activation is the responsibility of the
961 if Nkind
(Context
) /= N_Extended_Return_Statement
then
962 Set_Activation_Chain_Entity
(Context
, Chain
);
966 Make_Object_Declaration
(Loc
,
967 Defining_Identifier
=> Chain
,
968 Aliased_Present
=> True,
970 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
));
972 Prepend_To
(Decls
, Decl
);
974 -- Ensure that _chain appears in the proper scope of the context
976 if Context_Id
/= Current_Scope
then
977 Push_Scope
(Context_Id
);
985 end Build_Activation_Chain_Entity
;
987 ----------------------------
988 -- Build_Barrier_Function --
989 ----------------------------
991 function Build_Barrier_Function
994 Pid
: Node_Id
) return Node_Id
996 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
997 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
998 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
999 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
1000 Op_Decls
: constant List_Id
:= New_List
;
1002 Func_Body
: Node_Id
;
1005 -- Add a declaration for the Protection object, renaming declarations
1006 -- for the discriminals and privals and finally a declaration for the
1007 -- entry family index (if applicable).
1009 Install_Private_Data_Declarations
(Sloc
(N
),
1015 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1017 -- If compiling with -fpreserve-control-flow, make sure we insert an
1018 -- IF statement so that the back-end knows to generate a conditional
1019 -- branch instruction, even if the condition is just the name of a
1020 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1021 -- such redundant IF statements under -fpreserve-control-flow
1022 -- (whether coming from this routine, or directly from source).
1024 if Opt
.Suppress_Control_Flow_Optimizations
then
1025 Stmt
:= Make_Implicit_If_Statement
(Cond
,
1027 Then_Statements
=> New_List
(
1028 Make_Simple_Return_Statement
(Loc
,
1029 New_Occurrence_Of
(Standard_True
, Loc
))),
1030 Else_Statements
=> New_List
(
1031 Make_Simple_Return_Statement
(Loc
,
1032 New_Occurrence_Of
(Standard_False
, Loc
))));
1035 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1038 -- Note: the condition in the barrier function needs to be properly
1039 -- processed for the C/Fortran boolean possibility, but this happens
1040 -- automatically since the return statement does this normalization.
1043 Make_Subprogram_Body
(Loc
,
1045 Build_Barrier_Function_Specification
(Loc
,
1046 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1047 Declarations
=> Op_Decls
,
1048 Handled_Statement_Sequence
=>
1049 Make_Handled_Sequence_Of_Statements
(Loc
,
1050 Statements
=> New_List
(Stmt
)));
1051 Set_Is_Entry_Barrier_Function
(Func_Body
);
1054 end Build_Barrier_Function
;
1056 ------------------------------------------
1057 -- Build_Barrier_Function_Specification --
1058 ------------------------------------------
1060 function Build_Barrier_Function_Specification
1062 Def_Id
: Entity_Id
) return Node_Id
1065 Set_Debug_Info_Needed
(Def_Id
);
1067 return Make_Function_Specification
(Loc
,
1068 Defining_Unit_Name
=> Def_Id
,
1069 Parameter_Specifications
=> New_List
(
1070 Make_Parameter_Specification
(Loc
,
1071 Defining_Identifier
=>
1072 Make_Defining_Identifier
(Loc
, Name_uO
),
1074 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
1076 Make_Parameter_Specification
(Loc
,
1077 Defining_Identifier
=>
1078 Make_Defining_Identifier
(Loc
, Name_uE
),
1080 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1082 Result_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
1083 end Build_Barrier_Function_Specification
;
1085 --------------------------
1086 -- Build_Call_With_Task --
1087 --------------------------
1089 function Build_Call_With_Task
1091 E
: Entity_Id
) return Node_Id
1093 Loc
: constant Source_Ptr
:= Sloc
(N
);
1096 Make_Function_Call
(Loc
,
1097 Name
=> New_Occurrence_Of
(E
, Loc
),
1098 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1099 end Build_Call_With_Task
;
1101 -----------------------------
1102 -- Build_Class_Wide_Master --
1103 -----------------------------
1105 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1106 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1107 Master_Id
: Entity_Id
;
1108 Master_Scope
: Entity_Id
;
1110 Related_Node
: Node_Id
;
1114 -- Nothing to do if there is no task hierarchy
1116 if Restriction_Active
(No_Task_Hierarchy
) then
1120 -- Find the declaration that created the access type, which is either a
1121 -- type declaration, or an object declaration with an access definition,
1122 -- in which case the type is anonymous.
1124 if Is_Itype
(Typ
) then
1125 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1127 Related_Node
:= Parent
(Typ
);
1130 Master_Scope
:= Find_Master_Scope
(Typ
);
1132 -- Nothing to do if the master scope already contains a _master entity.
1133 -- The only exception to this is the following scenario:
1136 -- Transient_Scope_1
1139 -- Transient_Scope_2
1142 -- In this case the source scope is marked as having the master entity
1143 -- even though the actual declaration appears inside an inner scope. If
1144 -- the second transient scope requires a _master, it cannot use the one
1145 -- already declared because the entity is not visible.
1147 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1149 if not Has_Master_Entity
(Master_Scope
)
1150 or else No
(Current_Entity_In_Scope
(Name_Id
))
1153 Master_Decl
: Node_Id
;
1155 Set_Has_Master_Entity
(Master_Scope
);
1158 -- _master : constant Integer := Current_Master.all;
1161 Make_Object_Declaration
(Loc
,
1162 Defining_Identifier
=>
1163 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1164 Constant_Present
=> True,
1165 Object_Definition
=>
1166 New_Occurrence_Of
(Standard_Integer
, Loc
),
1168 Make_Explicit_Dereference
(Loc
,
1169 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
1171 Insert_Action
(Find_Hook_Context
(Related_Node
), Master_Decl
);
1172 Analyze
(Master_Decl
);
1174 -- Mark the containing scope as a task master. Masters associated
1175 -- with return statements are already marked at this stage (see
1176 -- Analyze_Subprogram_Body).
1178 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1180 Par
: Node_Id
:= Related_Node
;
1183 while Nkind
(Par
) /= N_Compilation_Unit
loop
1184 Par
:= Parent
(Par
);
1186 -- If we fall off the top, we are at the outer level,
1187 -- and the environment task is our effective master,
1188 -- so nothing to mark.
1190 if Nkind_In
(Par
, N_Block_Statement
,
1194 Set_Is_Task_Master
(Par
);
1204 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(Typ
), 'M'));
1207 -- typeMnn renames _master;
1210 Make_Object_Renaming_Declaration
(Loc
,
1211 Defining_Identifier
=> Master_Id
,
1212 Subtype_Mark
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1215 Insert_Action
(Related_Node
, Ren_Decl
);
1217 Set_Master_Id
(Typ
, Master_Id
);
1218 end Build_Class_Wide_Master
;
1220 --------------------------------
1221 -- Build_Corresponding_Record --
1222 --------------------------------
1224 function Build_Corresponding_Record
1227 Loc
: Source_Ptr
) return Node_Id
1229 Rec_Ent
: constant Entity_Id
:=
1230 Make_Defining_Identifier
1231 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1234 New_Disc
: Entity_Id
;
1238 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1239 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1240 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1241 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1242 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1243 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1246 -- Use discriminals to create list of discriminants for record, and
1247 -- create new discriminals for use in default expressions, etc. It is
1248 -- worth noting that a task discriminant gives rise to 5 entities;
1250 -- a) The original discriminant.
1251 -- b) The discriminal for use in the task.
1252 -- c) The discriminant of the corresponding record.
1253 -- d) The discriminal for the init proc of the corresponding record.
1254 -- e) The local variable that renames the discriminant in the procedure
1255 -- for the task body.
1257 -- In fact the discriminals b) are used in the renaming declarations
1258 -- for e). See details in einfo (Handling of Discriminants).
1260 if Present
(Discriminant_Specifications
(N
)) then
1262 Disc
:= First_Discriminant
(Ctyp
);
1264 while Present
(Disc
) loop
1265 New_Disc
:= CR_Discriminant
(Disc
);
1268 Make_Discriminant_Specification
(Loc
,
1269 Defining_Identifier
=> New_Disc
,
1270 Discriminant_Type
=>
1271 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1273 New_Copy
(Discriminant_Default_Value
(Disc
))));
1275 Next_Discriminant
(Disc
);
1282 -- Now we can construct the record type declaration. Note that this
1283 -- record is "limited tagged". It is "limited" to reflect the underlying
1284 -- limitedness of the task or protected object that it represents, and
1285 -- ensuring for example that it is properly passed by reference. It is
1286 -- "tagged" to give support to dispatching calls through interfaces. We
1287 -- propagate here the list of interfaces covered by the concurrent type
1288 -- (Ada 2005: AI-345).
1291 Make_Full_Type_Declaration
(Loc
,
1292 Defining_Identifier
=> Rec_Ent
,
1293 Discriminant_Specifications
=> Dlist
,
1295 Make_Record_Definition
(Loc
,
1297 Make_Component_List
(Loc
,
1298 Component_Items
=> Cdecls
),
1300 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1301 Interface_List
=> Interface_List
(N
),
1302 Limited_Present
=> True));
1303 end Build_Corresponding_Record
;
1305 ---------------------------------
1306 -- Build_Dispatching_Tag_Check --
1307 ---------------------------------
1309 function Build_Dispatching_Tag_Check
1311 N
: Node_Id
) return Node_Id
1313 Loc
: constant Source_Ptr
:= Sloc
(N
);
1320 New_Occurrence_Of
(K
, Loc
),
1322 New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1326 New_Occurrence_Of
(K
, Loc
),
1328 New_Occurrence_Of
(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_Occurrence_Of
(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_Occurrence_Of
(RTE
(RE_Entry_Index
), Loc
),
1534 Make_Function_Call
(Loc
,
1536 New_Occurrence_Of
(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_Occurrence_Of
(RTE
(Data_Typ
), Loc
),
1549 Make_Aggregate
(Loc
,
1550 Component_Associations
=> New_List
(
1551 Make_Component_Association
(Loc
,
1552 Choices
=> New_List
(
1555 Make_Integer_Literal
(Loc
, 1),
1557 New_Occurrence_Of
(Size
, Loc
))),
1558 Expression
=> Make_Null
(Loc
))))));
1561 end Create_Index_And_Data
;
1563 ---------------------
1564 -- Increment_Index --
1565 ---------------------
1567 function Increment_Index
return Node_Id
is
1570 Make_Assignment_Statement
(Loc
,
1571 Name
=> New_Occurrence_Of
(Index
, Loc
),
1574 Left_Opnd
=> New_Occurrence_Of
(Index
, Loc
),
1575 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
1576 end Increment_Index
;
1578 ----------------------
1579 -- Name_Declaration --
1580 ----------------------
1582 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
is
1585 Make_Object_Declaration
(Loc
,
1586 Defining_Identifier
=> Def_Id
,
1587 Aliased_Present
=> True,
1588 Constant_Present
=> True,
1589 Object_Definition
=>
1590 New_Occurrence_Of
(Standard_String
, Loc
),
1592 Make_String_Literal
(Loc
, String_From_Name_Buffer
));
1593 end Name_Declaration
;
1595 --------------------
1596 -- Set_Entry_Name --
1597 --------------------
1599 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
is
1602 Make_Assignment_Statement
(Loc
,
1604 Make_Indexed_Component
(Loc
,
1605 Prefix
=> New_Occurrence_Of
(Data
, Loc
),
1606 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
))),
1609 Make_Attribute_Reference
(Loc
,
1610 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
1611 Attribute_Name
=> Name_Unchecked_Access
));
1616 Temp_Id
: Entity_Id
;
1619 -- Start of processing for Build_Entry_Name
1622 if Ekind
(Comp_Id
) = E_Entry_Family
then
1623 Subt_Def
:= Discrete_Subtype_Definition
(Parent
(Comp_Id
));
1625 Create_Index_And_Data
;
1627 -- Step 1: Create the string name of the entry family.
1629 -- Temp : aliased constant String := "name ()";
1631 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1632 Get_Name_String
(Chars
(Comp_Id
));
1633 Add_Char_To_Name_Buffer
(' ');
1634 Add_Char_To_Name_Buffer
('(');
1635 Add_Char_To_Name_Buffer
(')');
1637 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1640 -- for Member in Family_Low .. Family_High loop
1641 -- Set_Entry_Name (...);
1642 -- Index := Index + 1;
1646 Make_Loop_Statement
(Loc
,
1648 Make_Iteration_Scheme
(Loc
,
1649 Loop_Parameter_Specification
=>
1650 Make_Loop_Parameter_Specification
(Loc
,
1651 Defining_Identifier
=>
1652 Make_Temporary
(Loc
, 'L'),
1653 Discrete_Subtype_Definition
=>
1654 Build_Range
(Subt_Def
))),
1656 Statements
=> New_List
(
1657 Set_Entry_Name
(Temp_Id
),
1659 End_Label
=> Empty
));
1664 Create_Index_And_Data
;
1666 -- Step 1: Create the string name of the entry. Generate:
1667 -- Temp : aliased constant String := "name";
1669 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1670 Get_Name_String
(Chars
(Comp_Id
));
1672 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1674 -- Step 2: Associate the string name with the underlying data
1677 Append_To
(Stmts
, Set_Entry_Name
(Temp_Id
));
1678 Append_To
(Stmts
, Increment_Index
);
1680 end Build_Entry_Name
;
1682 ----------------------
1683 -- Object_Reference --
1684 ----------------------
1686 function Object_Reference
return Node_Id
is
1687 Conc_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Typ
);
1692 if Is_Protected_Type
(Typ
) then
1693 Field
:= Name_uObject
;
1695 Field
:= Name_uTask_Id
;
1699 Make_Selected_Component
(Loc
,
1701 Unchecked_Convert_To
(Conc_Typ
, New_Copy_Tree
(Obj_Ref
)),
1702 Selector_Name
=> Make_Identifier
(Loc
, Field
));
1704 if Is_Protected_Type
(Typ
) then
1706 Make_Attribute_Reference
(Loc
,
1708 Attribute_Name
=> Name_Unchecked_Access
);
1712 end Object_Reference
;
1719 -- Start of processing for Build_Entry_Names
1722 -- Retrieve the original concurrent type
1724 if Is_Concurrent_Record_Type
(Typ
) then
1725 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1728 pragma Assert
(Is_Concurrent_Type
(Typ
));
1730 -- Nothing to do if the type has no entries
1732 if not Has_Entries
(Typ
) then
1736 -- Avoid generating entry names for a protected type with only one entry
1738 if Is_Protected_Type
(Typ
)
1739 and then Find_Protection_Type
(Base_Type
(Typ
)) /=
1740 RTE
(RE_Protection_Entries
)
1745 -- Step 1: Populate the array with statically generated strings denoting
1746 -- entries and entry family names.
1748 Comp
:= First_Entity
(Typ
);
1749 while Present
(Comp
) loop
1750 if Comes_From_Source
(Comp
)
1751 and then Ekind_In
(Comp
, E_Entry
, E_Entry_Family
)
1753 Build_Entry_Name
(Comp
);
1759 -- Step 2: Associate the array with the related concurrent object:
1761 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1763 if Present
(Data
) then
1764 if Is_Protected_Type
(Typ
) then
1765 Proc
:= RO_PE_Set_Entry_Names
;
1767 Proc
:= RO_ST_Set_Entry_Names
;
1771 Make_Procedure_Call_Statement
(Loc
,
1772 Name
=> New_Occurrence_Of
(RTE
(Proc
), Loc
),
1773 Parameter_Associations
=> New_List
(
1775 Make_Attribute_Reference
(Loc
,
1776 Prefix
=> New_Occurrence_Of
(Data
, Loc
),
1777 Attribute_Name
=> Name_Unchecked_Access
))));
1779 end Build_Entry_Names
;
1781 ---------------------------
1782 -- Build_Parameter_Block --
1783 ---------------------------
1785 function Build_Parameter_Block
1789 Decls
: List_Id
) return Entity_Id
1795 Has_Comp
: Boolean := False;
1799 Actual
:= First
(Actuals
);
1801 Formal
:= Defining_Identifier
(First
(Formals
));
1803 while Present
(Actual
) loop
1804 if not Is_Controlling_Actual
(Actual
) then
1807 -- type Ann is access all <actual-type>
1809 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1812 Make_Full_Type_Declaration
(Loc
,
1813 Defining_Identifier
=> Comp_Nam
,
1815 Make_Access_To_Object_Definition
(Loc
,
1816 All_Present
=> True,
1817 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1818 Subtype_Indication
=>
1819 New_Occurrence_Of
(Etype
(Actual
), Loc
))));
1825 Make_Component_Declaration
(Loc
,
1826 Defining_Identifier
=>
1827 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1828 Component_Definition
=>
1829 Make_Component_Definition
(Loc
,
1832 Subtype_Indication
=>
1833 New_Occurrence_Of
(Comp_Nam
, Loc
))));
1838 Next_Actual
(Actual
);
1839 Next_Formal_With_Extras
(Formal
);
1842 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1847 -- type Pnn is record
1852 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1853 -- the original parameter names and Ann1 .. AnnN are the access to
1857 Make_Full_Type_Declaration
(Loc
,
1858 Defining_Identifier
=>
1861 Make_Record_Definition
(Loc
,
1863 Make_Component_List
(Loc
, Comps
))));
1866 -- type Pnn is null record;
1869 Make_Full_Type_Declaration
(Loc
,
1870 Defining_Identifier
=>
1873 Make_Record_Definition
(Loc
,
1874 Null_Present
=> True,
1875 Component_List
=> Empty
)));
1879 end Build_Parameter_Block
;
1881 --------------------------------------
1882 -- Build_Renamed_Formal_Declaration --
1883 --------------------------------------
1885 function Build_Renamed_Formal_Declaration
1889 Renamed_Formal
: Node_Id
) return Node_Id
1891 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1895 -- If the formal is a tagged incomplete type, it is already passed
1896 -- by reference, so it is sufficient to rename the pointer component
1897 -- that corresponds to the actual. Otherwise we need to dereference
1898 -- the pointer component to obtain the actual.
1900 if Is_Incomplete_Type
(Etype
(Formal
))
1901 and then Is_Tagged_Type
(Etype
(Formal
))
1904 Make_Object_Renaming_Declaration
(Loc
,
1905 Defining_Identifier
=> New_F
,
1906 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Comp
), Loc
),
1907 Name
=> Renamed_Formal
);
1911 Make_Object_Renaming_Declaration
(Loc
,
1912 Defining_Identifier
=> New_F
,
1913 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Formal
), Loc
),
1915 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1919 end Build_Renamed_Formal_Declaration
;
1921 -----------------------
1922 -- Build_PPC_Wrapper --
1923 -----------------------
1925 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1926 Loc
: constant Source_Ptr
:= Sloc
(E
);
1927 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1929 Wrapper_Id
: constant Entity_Id
:=
1930 Make_Defining_Identifier
(Loc
,
1931 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1932 -- the wrapper procedure name
1934 Wrapper_Body
: Node_Id
;
1936 Synch_Id
: constant Entity_Id
:=
1937 Make_Defining_Identifier
(Loc
,
1938 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1939 -- The parameter that designates the synchronized object in the call
1941 Actuals
: constant List_Id
:= New_List
;
1942 -- The actuals in the entry call
1944 Decls
: constant List_Id
:= New_List
;
1946 Entry_Call
: Node_Id
;
1947 Entry_Name
: Node_Id
;
1950 -- The specification of the wrapper procedure
1954 -- Only build the wrapper if entry has pre/postconditions.
1955 -- Should this be done unconditionally instead ???
1961 P
:= Pre_Post_Conditions
(Contract
(E
));
1967 -- Transfer ppc pragmas to the declarations of the wrapper
1969 while Present
(P
) loop
1970 if Nam_In
(Pragma_Name
(P
), Name_Precondition
,
1973 Append
(Relocate_Node
(P
), Decls
);
1974 Set_Analyzed
(Last
(Decls
), False);
1977 P
:= Next_Pragma
(P
);
1981 -- First formal is synchronized object
1984 Make_Parameter_Specification
(Loc
,
1985 Defining_Identifier
=> Synch_Id
,
1986 Out_Present
=> True,
1988 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1991 Make_Selected_Component
(Loc
,
1992 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1993 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1995 -- If entity is entry family, second formal is the corresponding index,
1996 -- and entry name is an indexed component.
1998 if Ekind
(E
) = E_Entry_Family
then
2000 Index
: constant Entity_Id
:=
2001 Make_Defining_Identifier
(Loc
, Name_I
);
2004 Make_Parameter_Specification
(Loc
,
2005 Defining_Identifier
=> Index
,
2007 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
2010 Make_Indexed_Component
(Loc
,
2011 Prefix
=> Entry_Name
,
2012 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
2017 Make_Procedure_Call_Statement
(Loc
,
2019 Parameter_Associations
=> Actuals
);
2021 -- Now add formals that match those of the entry, and build actuals for
2022 -- the nested entry call.
2026 New_Form
: Entity_Id
;
2027 Parm_Spec
: Node_Id
;
2030 Form
:= First_Formal
(E
);
2031 while Present
(Form
) loop
2032 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
2034 Make_Parameter_Specification
(Loc
,
2035 Defining_Identifier
=> New_Form
,
2036 Out_Present
=> Out_Present
(Parent
(Form
)),
2037 In_Present
=> In_Present
(Parent
(Form
)),
2038 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
2040 Append
(Parm_Spec
, Specs
);
2041 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
2046 -- Add renaming declarations for the discriminants of the enclosing
2047 -- type, which may be visible in the preconditions.
2049 if Has_Discriminants
(Synch_Type
) then
2055 D
:= First_Discriminant
(Synch_Type
);
2056 while Present
(D
) loop
2058 Make_Object_Renaming_Declaration
(Loc
,
2059 Defining_Identifier
=>
2060 Make_Defining_Identifier
(Loc
, Chars
(D
)),
2061 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
2063 Make_Selected_Component
(Loc
,
2064 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
2065 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
2066 Prepend
(Decl
, Decls
);
2067 Next_Discriminant
(D
);
2072 Set_PPC_Wrapper
(E
, Wrapper_Id
);
2074 Make_Subprogram_Body
(Loc
,
2076 Make_Procedure_Specification
(Loc
,
2077 Defining_Unit_Name
=> Wrapper_Id
,
2078 Parameter_Specifications
=> Specs
),
2079 Declarations
=> Decls
,
2080 Handled_Statement_Sequence
=>
2081 Make_Handled_Sequence_Of_Statements
(Loc
,
2082 Statements
=> New_List
(Entry_Call
)));
2084 -- The wrapper body is analyzed when the enclosing type is frozen
2086 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
2087 end Build_PPC_Wrapper
;
2089 --------------------------
2090 -- Build_Wrapper_Bodies --
2091 --------------------------
2093 procedure Build_Wrapper_Bodies
2098 Rec_Typ
: Entity_Id
;
2100 function Build_Wrapper_Body
2102 Subp_Id
: Entity_Id
;
2103 Obj_Typ
: Entity_Id
;
2104 Formals
: List_Id
) return Node_Id
;
2105 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2106 -- associated with a protected or task type. Subp_Id is the subprogram
2107 -- name which will be wrapped. Obj_Typ is the type of the new formal
2108 -- parameter which handles dispatching and object notation. Formals are
2109 -- the original formals of Subp_Id which will be explicitly replicated.
2111 ------------------------
2112 -- Build_Wrapper_Body --
2113 ------------------------
2115 function Build_Wrapper_Body
2117 Subp_Id
: Entity_Id
;
2118 Obj_Typ
: Entity_Id
;
2119 Formals
: List_Id
) return Node_Id
2121 Body_Spec
: Node_Id
;
2124 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
2126 -- The subprogram is not overriding or is not a primitive declared
2127 -- between two views.
2129 if No
(Body_Spec
) then
2134 Actuals
: List_Id
:= No_List
;
2136 First_Form
: Node_Id
;
2141 -- Map formals to actuals. Use the list built for the wrapper
2142 -- spec, skipping the object notation parameter.
2144 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
2146 Formal
:= First_Form
;
2149 if Present
(Formal
) then
2150 Actuals
:= New_List
;
2151 while Present
(Formal
) loop
2153 Make_Identifier
(Loc
,
2154 Chars
=> Chars
(Defining_Identifier
(Formal
))));
2159 -- Special processing for primitives declared between a private
2160 -- type and its completion: the wrapper needs a properly typed
2161 -- parameter if the wrapped operation has a controlling first
2162 -- parameter. Note that this might not be the case for a function
2163 -- with a controlling result.
2165 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
2166 if No
(Actuals
) then
2167 Actuals
:= New_List
;
2170 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
2171 Prepend_To
(Actuals
,
2172 Unchecked_Convert_To
2173 (Corresponding_Concurrent_Type
(Obj_Typ
),
2174 Make_Identifier
(Loc
, Name_uO
)));
2177 Prepend_To
(Actuals
,
2178 Make_Identifier
(Loc
,
2179 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
2182 Nam
:= New_Occurrence_Of
(Subp_Id
, Loc
);
2184 -- An access-to-variable object parameter requires an explicit
2185 -- dereference in the unchecked conversion. This case occurs
2186 -- when a protected entry wrapper must override an interface
2187 -- level procedure with interface access as first parameter.
2189 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2191 if Nkind
(Parameter_Type
(First_Form
)) =
2195 Make_Explicit_Dereference
(Loc
,
2196 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
2198 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
2202 Make_Selected_Component
(Loc
,
2204 Unchecked_Convert_To
2205 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
2206 Selector_Name
=> New_Occurrence_Of
(Subp_Id
, Loc
));
2209 -- Create the subprogram body. For a function, the call to the
2210 -- actual subprogram has to be converted to the corresponding
2211 -- record if it is a controlling result.
2213 if Ekind
(Subp_Id
) = E_Function
then
2219 Make_Function_Call
(Loc
,
2221 Parameter_Associations
=> Actuals
);
2223 if Has_Controlling_Result
(Subp_Id
) then
2225 Unchecked_Convert_To
2226 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
2230 Make_Subprogram_Body
(Loc
,
2231 Specification
=> Body_Spec
,
2232 Declarations
=> Empty_List
,
2233 Handled_Statement_Sequence
=>
2234 Make_Handled_Sequence_Of_Statements
(Loc
,
2235 Statements
=> New_List
(
2236 Make_Simple_Return_Statement
(Loc
, Res
))));
2241 Make_Subprogram_Body
(Loc
,
2242 Specification
=> Body_Spec
,
2243 Declarations
=> Empty_List
,
2244 Handled_Statement_Sequence
=>
2245 Make_Handled_Sequence_Of_Statements
(Loc
,
2246 Statements
=> New_List
(
2247 Make_Procedure_Call_Statement
(Loc
,
2249 Parameter_Associations
=> Actuals
))));
2252 end Build_Wrapper_Body
;
2254 -- Start of processing for Build_Wrapper_Bodies
2257 if Is_Concurrent_Type
(Typ
) then
2258 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2263 -- Generate wrapper bodies for a concurrent type which implements an
2266 if Present
(Interfaces
(Rec_Typ
)) then
2268 Insert_Nod
: Node_Id
;
2270 Prim_Elmt
: Elmt_Id
;
2271 Prim_Decl
: Node_Id
;
2273 Wrap_Body
: Node_Id
;
2274 Wrap_Id
: Entity_Id
;
2279 -- Examine all primitive operations of the corresponding record
2280 -- type, looking for wrapper specs. Generate bodies in order to
2283 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2284 while Present
(Prim_Elmt
) loop
2285 Prim
:= Node
(Prim_Elmt
);
2287 if (Ekind
(Prim
) = E_Function
2288 or else Ekind
(Prim
) = E_Procedure
)
2289 and then Is_Primitive_Wrapper
(Prim
)
2291 Subp
:= Wrapped_Entity
(Prim
);
2292 Prim_Decl
:= Parent
(Parent
(Prim
));
2295 Build_Wrapper_Body
(Loc
,
2298 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2299 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2301 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2302 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2304 Insert_After
(Insert_Nod
, Wrap_Body
);
2305 Insert_Nod
:= Wrap_Body
;
2307 Analyze
(Wrap_Body
);
2310 Next_Elmt
(Prim_Elmt
);
2314 end Build_Wrapper_Bodies
;
2316 ------------------------
2317 -- Build_Wrapper_Spec --
2318 ------------------------
2320 function Build_Wrapper_Spec
2321 (Subp_Id
: Entity_Id
;
2322 Obj_Typ
: Entity_Id
;
2323 Formals
: List_Id
) return Node_Id
2325 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2326 First_Param
: Node_Id
;
2328 Iface_Elmt
: Elmt_Id
;
2329 Iface_Op
: Entity_Id
;
2330 Iface_Op_Elmt
: Elmt_Id
;
2332 function Overriding_Possible
2333 (Iface_Op
: Entity_Id
;
2334 Wrapper
: Entity_Id
) return Boolean;
2335 -- Determine whether a primitive operation can be overridden by Wrapper.
2336 -- Iface_Op is the candidate primitive operation of an interface type,
2337 -- Wrapper is the generated entry wrapper.
2339 function Replicate_Formals
2341 Formals
: List_Id
) return List_Id
;
2342 -- An explicit parameter replication is required due to the Is_Entry_
2343 -- Formal flag being set for all the formals of an entry. The explicit
2344 -- replication removes the flag that would otherwise cause a different
2345 -- path of analysis.
2347 -------------------------
2348 -- Overriding_Possible --
2349 -------------------------
2351 function Overriding_Possible
2352 (Iface_Op
: Entity_Id
;
2353 Wrapper
: Entity_Id
) return Boolean
2355 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2356 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2358 function Type_Conformant_Parameters
2359 (Iface_Op_Params
: List_Id
;
2360 Wrapper_Params
: List_Id
) return Boolean;
2361 -- Determine whether the parameters of the generated entry wrapper
2362 -- and those of a primitive operation are type conformant. During
2363 -- this check, the first parameter of the primitive operation is
2364 -- skipped if it is a controlling argument: protected functions
2365 -- may have a controlling result.
2367 --------------------------------
2368 -- Type_Conformant_Parameters --
2369 --------------------------------
2371 function Type_Conformant_Parameters
2372 (Iface_Op_Params
: List_Id
;
2373 Wrapper_Params
: List_Id
) return Boolean
2375 Iface_Op_Param
: Node_Id
;
2376 Iface_Op_Typ
: Entity_Id
;
2377 Wrapper_Param
: Node_Id
;
2378 Wrapper_Typ
: Entity_Id
;
2381 -- Skip the first (controlling) parameter of primitive operation
2383 Iface_Op_Param
:= First
(Iface_Op_Params
);
2385 if Present
(First_Formal
(Iface_Op
))
2386 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2388 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2391 Wrapper_Param
:= First
(Wrapper_Params
);
2392 while Present
(Iface_Op_Param
)
2393 and then Present
(Wrapper_Param
)
2395 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2396 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2398 -- The two parameters must be mode conformant
2400 if not Conforming_Types
2401 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2406 Next
(Iface_Op_Param
);
2407 Next
(Wrapper_Param
);
2410 -- One of the lists is longer than the other
2412 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2417 end Type_Conformant_Parameters
;
2419 -- Start of processing for Overriding_Possible
2422 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2426 -- If an inherited subprogram is implemented by a protected procedure
2427 -- or an entry, then the first parameter of the inherited subprogram
2428 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2430 if Ekind
(Iface_Op
) = E_Procedure
2431 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2434 Obj_Param
: constant Node_Id
:=
2435 First
(Parameter_Specifications
(Iface_Op_Spec
));
2437 if not Out_Present
(Obj_Param
)
2438 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2447 Type_Conformant_Parameters
(
2448 Parameter_Specifications
(Iface_Op_Spec
),
2449 Parameter_Specifications
(Wrapper_Spec
));
2450 end Overriding_Possible
;
2452 -----------------------
2453 -- Replicate_Formals --
2454 -----------------------
2456 function Replicate_Formals
2458 Formals
: List_Id
) return List_Id
2460 New_Formals
: constant List_Id
:= New_List
;
2462 Param_Type
: Node_Id
;
2465 Formal
:= First
(Formals
);
2467 -- Skip the object parameter when dealing with primitives declared
2468 -- between two views.
2470 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2471 and then not Has_Controlling_Result
(Subp_Id
)
2473 Formal
:= Next
(Formal
);
2476 while Present
(Formal
) loop
2478 -- Create an explicit copy of the entry parameter
2480 -- When creating the wrapper subprogram for a primitive operation
2481 -- of a protected interface we must construct an equivalent
2482 -- signature to that of the overriding operation. For regular
2483 -- parameters we can just use the type of the formal, but for
2484 -- access to subprogram parameters we need to reanalyze the
2485 -- parameter type to create local entities for the signature of
2486 -- the subprogram type. Using the entities of the overriding
2487 -- subprogram will result in out-of-scope errors in the back-end.
2489 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2490 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2493 New_Occurrence_Of
(Etype
(Parameter_Type
(Formal
)), Loc
);
2496 Append_To
(New_Formals
,
2497 Make_Parameter_Specification
(Loc
,
2498 Defining_Identifier
=>
2499 Make_Defining_Identifier
(Loc
,
2501 (Defining_Identifier
(Formal
))),
2502 In_Present
=> In_Present
(Formal
),
2503 Out_Present
=> Out_Present
(Formal
),
2504 Null_Exclusion_Present
=> Null_Exclusion_Present
(Formal
),
2505 Parameter_Type
=> Param_Type
));
2511 end Replicate_Formals
;
2513 -- Start of processing for Build_Wrapper_Spec
2516 -- No point in building wrappers for untagged concurrent types
2518 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2520 -- An entry or a protected procedure can override a routine where the
2521 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2522 -- type. Since the wrapper must have the exact same signature as that of
2523 -- the overridden subprogram, we try to find the overriding candidate
2524 -- and use its controlling formal.
2526 First_Param
:= Empty
;
2528 -- Check every implemented interface
2530 if Present
(Interfaces
(Obj_Typ
)) then
2531 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2532 Search
: while Present
(Iface_Elmt
) loop
2533 Iface
:= Node
(Iface_Elmt
);
2535 -- Check every interface primitive
2537 if Present
(Primitive_Operations
(Iface
)) then
2538 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2539 while Present
(Iface_Op_Elmt
) loop
2540 Iface_Op
:= Node
(Iface_Op_Elmt
);
2542 -- Ignore predefined primitives
2544 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2545 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2547 -- The current primitive operation can be overridden by
2548 -- the generated entry wrapper.
2550 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2552 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2558 Next_Elmt
(Iface_Op_Elmt
);
2562 Next_Elmt
(Iface_Elmt
);
2566 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2567 -- this subprogram and this is not a primitive declared between two
2568 -- views then force the generation of a wrapper. As an optimization,
2569 -- previous versions of the frontend avoid generating the wrapper;
2570 -- however, the wrapper facilitates locating and reporting an error
2571 -- when a duplicate declaration is found later. See example in
2575 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2578 (Corresponding_Concurrent_Type
(Obj_Typ
))
2581 Make_Parameter_Specification
(Loc
,
2582 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
2584 Out_Present
=> False,
2585 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2587 -- For entries and procedures of protected types the mode of
2588 -- the controlling argument must be in-out.
2592 Make_Parameter_Specification
(Loc
,
2593 Defining_Identifier
=>
2594 Make_Defining_Identifier
(Loc
,
2597 Out_Present
=> (Ekind
(Subp_Id
) /= E_Function
),
2598 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2603 Wrapper_Id
: constant Entity_Id
:=
2604 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2605 New_Formals
: List_Id
;
2606 Obj_Param
: Node_Id
;
2607 Obj_Param_Typ
: Entity_Id
;
2610 -- Minimum decoration is needed to catch the entity in
2611 -- Sem_Ch6.Override_Dispatching_Operation.
2613 if Ekind
(Subp_Id
) = E_Function
then
2614 Set_Ekind
(Wrapper_Id
, E_Function
);
2616 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2619 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2620 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2621 Set_Is_Private_Primitive
(Wrapper_Id
,
2622 Is_Private_Primitive_Subprogram
(Subp_Id
));
2624 -- Process the formals
2626 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2628 -- A function with a controlling result and no first controlling
2629 -- formal needs no additional parameter.
2631 if Has_Controlling_Result
(Subp_Id
)
2633 (No
(First_Formal
(Subp_Id
))
2634 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2638 -- Routine Subp_Id has been found to override an interface primitive.
2639 -- If the interface operation has an access parameter, create a copy
2640 -- of it, with the same null exclusion indicator if present.
2642 elsif Present
(First_Param
) then
2643 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2645 Make_Access_Definition
(Loc
,
2647 New_Occurrence_Of
(Obj_Typ
, Loc
));
2648 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2649 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2652 Obj_Param_Typ
:= New_Occurrence_Of
(Obj_Typ
, Loc
);
2656 Make_Parameter_Specification
(Loc
,
2657 Defining_Identifier
=>
2658 Make_Defining_Identifier
(Loc
,
2660 In_Present
=> In_Present
(First_Param
),
2661 Out_Present
=> Out_Present
(First_Param
),
2662 Parameter_Type
=> Obj_Param_Typ
);
2664 Prepend_To
(New_Formals
, Obj_Param
);
2666 -- If we are dealing with a primitive declared between two views,
2667 -- implemented by a synchronized operation, we need to create
2668 -- a default parameter. The mode of the parameter must match that
2669 -- of the primitive operation.
2672 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2674 Make_Parameter_Specification
(Loc
,
2675 Defining_Identifier
=>
2676 Make_Defining_Identifier
(Loc
, Name_uO
),
2677 In_Present
=> In_Present
(Parent
(First_Entity
(Subp_Id
))),
2678 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2679 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2680 Prepend_To
(New_Formals
, Obj_Param
);
2683 -- Build the final spec. If it is a function with a controlling
2684 -- result, it is a primitive operation of the corresponding
2685 -- record type, so mark the spec accordingly.
2687 if Ekind
(Subp_Id
) = E_Function
then
2692 if Has_Controlling_Result
(Subp_Id
) then
2695 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2697 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2701 Make_Function_Specification
(Loc
,
2702 Defining_Unit_Name
=> Wrapper_Id
,
2703 Parameter_Specifications
=> New_Formals
,
2704 Result_Definition
=> Res_Def
);
2708 Make_Procedure_Specification
(Loc
,
2709 Defining_Unit_Name
=> Wrapper_Id
,
2710 Parameter_Specifications
=> New_Formals
);
2713 end Build_Wrapper_Spec
;
2715 -------------------------
2716 -- Build_Wrapper_Specs --
2717 -------------------------
2719 procedure Build_Wrapper_Specs
2725 Rec_Typ
: Entity_Id
;
2726 procedure Scan_Declarations
(L
: List_Id
);
2727 -- Common processing for visible and private declarations
2728 -- of a protected type.
2730 procedure Scan_Declarations
(L
: List_Id
) is
2732 Wrap_Decl
: Node_Id
;
2733 Wrap_Spec
: Node_Id
;
2741 while Present
(Decl
) loop
2744 if Nkind
(Decl
) = N_Entry_Declaration
2745 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2749 (Subp_Id
=> Defining_Identifier
(Decl
),
2751 Formals
=> Parameter_Specifications
(Decl
));
2753 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2756 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2759 Parameter_Specifications
(Specification
(Decl
)));
2762 if Present
(Wrap_Spec
) then
2764 Make_Subprogram_Declaration
(Loc
,
2765 Specification
=> Wrap_Spec
);
2767 Insert_After
(N
, Wrap_Decl
);
2770 Analyze
(Wrap_Decl
);
2775 end Scan_Declarations
;
2777 -- start of processing for Build_Wrapper_Specs
2780 if Is_Protected_Type
(Typ
) then
2781 Def
:= Protected_Definition
(Parent
(Typ
));
2782 else pragma Assert
(Is_Task_Type
(Typ
));
2783 Def
:= Task_Definition
(Parent
(Typ
));
2786 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2788 -- Generate wrapper specs for a concurrent type which implements an
2789 -- interface. Operations in both the visible and private parts may
2790 -- implement progenitor operations.
2792 if Present
(Interfaces
(Rec_Typ
))
2793 and then Present
(Def
)
2795 Scan_Declarations
(Visible_Declarations
(Def
));
2796 Scan_Declarations
(Private_Declarations
(Def
));
2798 end Build_Wrapper_Specs
;
2800 ---------------------------
2801 -- Build_Find_Body_Index --
2802 ---------------------------
2804 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2805 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2808 Has_F
: Boolean := False;
2810 If_St
: Node_Id
:= Empty
;
2813 Decls
: List_Id
:= New_List
;
2816 Siz
: Node_Id
:= Empty
;
2818 procedure Add_If_Clause
(Expr
: Node_Id
);
2819 -- Add test for range of current entry
2821 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2822 -- If a bound of an entry is given by a discriminant, retrieve the
2823 -- actual value of the discriminant from the enclosing object.
2829 procedure Add_If_Clause
(Expr
: Node_Id
) is
2831 Stats
: constant List_Id
:=
2833 Make_Simple_Return_Statement
(Loc
,
2834 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2837 -- Index for current entry body
2841 -- Compute total length of entry queues so far
2849 Right_Opnd
=> Expr
);
2854 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2857 -- Map entry queue indexes in the range of the current family
2858 -- into the current index, that designates the entry body.
2862 Make_Implicit_If_Statement
(Typ
,
2864 Then_Statements
=> Stats
,
2865 Elsif_Parts
=> New_List
);
2869 Append_To
(Elsif_Parts
(If_St
),
2870 Make_Elsif_Part
(Loc
,
2872 Then_Statements
=> Stats
));
2876 ------------------------------
2877 -- Convert_Discriminant_Ref --
2878 ------------------------------
2880 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2884 if Is_Entity_Name
(Bound
)
2885 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2888 Make_Selected_Component
(Loc
,
2890 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2891 Make_Explicit_Dereference
(Loc
,
2892 Make_Identifier
(Loc
, Name_uObject
))),
2893 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2894 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2896 B
:= New_Copy_Tree
(Bound
);
2900 end Convert_Discriminant_Ref
;
2902 -- Start of processing for Build_Find_Body_Index
2905 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2907 Ent
:= First_Entity
(Typ
);
2908 while Present
(Ent
) loop
2909 if Ekind
(Ent
) = E_Entry_Family
then
2919 -- If the protected type has no entry families, there is a one-one
2920 -- correspondence between entry queue and entry body.
2923 Make_Simple_Return_Statement
(Loc
,
2924 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2927 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2930 -- if E <= l1 then return 1;
2931 -- elsif E <= l1 + l2 then return 2;
2936 Ent
:= First_Entity
(Typ
);
2938 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2940 while Present
(Ent
) loop
2941 if Ekind
(Ent
) = E_Entry
then
2942 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2944 elsif Ekind
(Ent
) = E_Entry_Family
then
2945 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2946 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2947 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2948 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2957 Make_Simple_Return_Statement
(Loc
,
2958 Expression
=> Make_Integer_Literal
(Loc
, 1));
2960 elsif Nkind
(Ret
) = N_If_Statement
then
2962 -- Ranges are in increasing order, so last one doesn't need guard
2965 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2968 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2974 Make_Subprogram_Body
(Loc
,
2975 Specification
=> Spec
,
2976 Declarations
=> Decls
,
2977 Handled_Statement_Sequence
=>
2978 Make_Handled_Sequence_Of_Statements
(Loc
,
2979 Statements
=> New_List
(Ret
)));
2980 end Build_Find_Body_Index
;
2982 --------------------------------
2983 -- Build_Find_Body_Index_Spec --
2984 --------------------------------
2986 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2987 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2988 Id
: constant Entity_Id
:=
2989 Make_Defining_Identifier
(Loc
,
2990 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2991 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2992 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2996 Make_Function_Specification
(Loc
,
2997 Defining_Unit_Name
=> Id
,
2998 Parameter_Specifications
=> New_List
(
2999 Make_Parameter_Specification
(Loc
,
3000 Defining_Identifier
=> Parm1
,
3002 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3004 Make_Parameter_Specification
(Loc
,
3005 Defining_Identifier
=> Parm2
,
3007 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
3009 Result_Definition
=> New_Occurrence_Of
(
3010 RTE
(RE_Protected_Entry_Index
), Loc
));
3011 end Build_Find_Body_Index_Spec
;
3013 -----------------------------------------------
3014 -- Build_Lock_Free_Protected_Subprogram_Body --
3015 -----------------------------------------------
3017 function Build_Lock_Free_Protected_Subprogram_Body
3020 Unprot_Spec
: Node_Id
) return Node_Id
3022 Actuals
: constant List_Id
:= New_List
;
3023 Loc
: constant Source_Ptr
:= Sloc
(N
);
3024 Spec
: constant Node_Id
:= Specification
(N
);
3025 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
3027 Prot_Spec
: Node_Id
;
3031 -- Create the protected version of the body
3034 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
3036 -- Build the actual parameters which appear in the call to the
3037 -- unprotected version of the body.
3039 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
3040 while Present
(Formal
) loop
3042 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
3047 -- Function case, generate:
3048 -- return <Unprot_Func_Call>;
3050 if Nkind
(Spec
) = N_Function_Specification
then
3052 Make_Simple_Return_Statement
(Loc
,
3054 Make_Function_Call
(Loc
,
3056 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3057 Parameter_Associations
=> Actuals
));
3059 -- Procedure case, call the unprotected version
3063 Make_Procedure_Call_Statement
(Loc
,
3065 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3066 Parameter_Associations
=> Actuals
);
3070 Make_Subprogram_Body
(Loc
,
3071 Declarations
=> Empty_List
,
3072 Specification
=> Prot_Spec
,
3073 Handled_Statement_Sequence
=>
3074 Make_Handled_Sequence_Of_Statements
(Loc
,
3075 Statements
=> New_List
(Stmt
)));
3076 end Build_Lock_Free_Protected_Subprogram_Body
;
3078 -------------------------------------------------
3079 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3080 -------------------------------------------------
3082 -- Procedures which meet the lock-free implementation requirements and
3083 -- reference a unique scalar component Comp are expanded in the following
3086 -- procedure P (...) is
3087 -- Expected_Comp : constant Comp_Type :=
3089 -- (System.Atomic_Primitives.Lock_Free_Read_N
3090 -- (_Object.Comp'Address));
3094 -- <original declarations before the object renaming declaration
3097 -- Desired_Comp : Comp_Type := Expected_Comp;
3098 -- Comp : Comp_Type renames Desired_Comp;
3100 -- <original delarations after the object renaming declaration
3104 -- <original statements>
3105 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3106 -- (_Object.Comp'Address,
3107 -- Interfaces.Unsigned_N (Expected_Comp),
3108 -- Interfaces.Unsigned_N (Desired_Comp));
3113 -- Each return and raise statement of P is transformed into an atomic
3116 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3117 -- (_Object.Comp'Address,
3118 -- Interfaces.Unsigned_N (Expected_Comp),
3119 -- Interfaces.Unsigned_N (Desired_Comp));
3121 -- <original statement>
3126 -- Functions which meet the lock-free implementation requirements and
3127 -- reference a unique scalar component Comp are expanded in the following
3130 -- function F (...) return ... is
3131 -- <original declarations before the object renaming declaration
3134 -- Expected_Comp : constant Comp_Type :=
3136 -- (System.Atomic_Primitives.Lock_Free_Read_N
3137 -- (_Object.Comp'Address));
3138 -- Comp : Comp_Type renames Expected_Comp;
3140 -- <original delarations after the object renaming declaration of
3144 -- <original statements>
3147 function Build_Lock_Free_Unprotected_Subprogram_Body
3149 Prot_Typ
: Node_Id
) return Node_Id
3151 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
3152 -- Subprograms which meet the lock-free implementation criteria are
3153 -- allowed to reference only one unique component. Return the prival
3154 -- of the said component.
3156 --------------------------
3157 -- Referenced_Component --
3158 --------------------------
3160 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
3163 Source_Comp
: Entity_Id
:= Empty
;
3166 -- Find the unique source component which N references in its
3169 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
3171 Element
: Lock_Free_Subprogram
renames
3172 Lock_Free_Subprogram_Table
.Table
(Index
);
3174 if Element
.Sub_Body
= N
then
3175 Source_Comp
:= Element
.Comp_Id
;
3181 if No
(Source_Comp
) then
3185 -- Find the prival which corresponds to the source component within
3186 -- the declarations of N.
3188 Decl
:= First
(Declarations
(N
));
3189 while Present
(Decl
) loop
3191 -- Privals appear as object renamings
3193 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
3194 Comp
:= Defining_Identifier
(Decl
);
3196 if Present
(Prival_Link
(Comp
))
3197 and then Prival_Link
(Comp
) = Source_Comp
3207 end Referenced_Component
;
3211 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
3212 Loc
: constant Source_Ptr
:= Sloc
(N
);
3213 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
3214 Decls
: List_Id
:= Declarations
(N
);
3216 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3219 -- Add renamings for the protection object, discriminals, privals and
3220 -- the entry index constant for use by debugger.
3222 Debug_Private_Data_Declarations
(Decls
);
3224 -- Perform the lock-free expansion when the subprogram references a
3225 -- protected component.
3227 if Present
(Comp
) then
3228 Protected_Component_Ref
: declare
3229 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
3230 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
3231 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
3233 Is_Procedure
: constant Boolean :=
3234 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
3235 -- Indicates if N is a protected procedure body
3237 Block_Decls
: List_Id
;
3238 Try_Write
: Entity_Id
;
3239 Desired_Comp
: Entity_Id
;
3242 Label_Id
: Entity_Id
:= Empty
;
3244 Expected_Comp
: Entity_Id
;
3247 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
3249 Unsigned
: Entity_Id
;
3251 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
3252 -- Transform a single node if it is a return statement, a raise
3253 -- statement or a reference to Comp.
3255 procedure Process_Stmts
(Stmts
: List_Id
);
3256 -- Given a statement sequence Stmts, wrap any return or raise
3257 -- statements in the following manner:
3259 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3260 -- (_Object.Comp'Address,
3261 -- Interfaces.Unsigned_N (Expected_Comp),
3262 -- Interfaces.Unsigned_N (Desired_Comp))
3273 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3275 procedure Wrap_Statement
(Stmt
: Node_Id
);
3276 -- Wrap an arbitrary statement inside an if statement where the
3277 -- condition does an atomic check on the state of the object.
3279 --------------------
3280 -- Wrap_Statement --
3281 --------------------
3283 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3285 -- The first time through, create the declaration of a label
3286 -- which is used to skip the remainder of source statements
3287 -- if the state of the object has changed.
3289 if No
(Label_Id
) then
3291 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3292 Set_Entity
(Label_Id
,
3293 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3297 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3298 -- (_Object.Comp'Address,
3299 -- Interfaces.Unsigned_N (Expected_Comp),
3300 -- Interfaces.Unsigned_N (Desired_Comp))
3308 Make_Implicit_If_Statement
(N
,
3310 Make_Function_Call
(Loc
,
3312 New_Occurrence_Of
(Try_Write
, Loc
),
3313 Parameter_Associations
=> New_List
(
3314 Make_Attribute_Reference
(Loc
,
3315 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3316 Attribute_Name
=> Name_Address
),
3318 Unchecked_Convert_To
(Unsigned
,
3319 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3321 Unchecked_Convert_To
(Unsigned
,
3322 New_Occurrence_Of
(Desired_Comp
, Loc
)))),
3324 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3326 Else_Statements
=> New_List
(
3327 Make_Goto_Statement
(Loc
,
3329 New_Occurrence_Of
(Entity
(Label_Id
), Loc
)))));
3332 -- Start of processing for Process_Node
3335 -- Wrap each return and raise statement that appear inside a
3336 -- procedure. Skip the last return statement which is added by
3337 -- default since it is transformed into an exit statement.
3340 and then ((Nkind
(N
) = N_Simple_Return_Statement
3341 and then N
/= Last
(Stmts
))
3342 or else Nkind
(N
) = N_Extended_Return_Statement
3343 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3344 N_Raise_Program_Error
,
3346 N_Raise_Storage_Error
)
3347 and then Comes_From_Source
(N
)))
3355 Set_Analyzed
(N
, False);
3360 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3366 procedure Process_Stmts
(Stmts
: List_Id
) is
3369 Stmt
:= First
(Stmts
);
3370 while Present
(Stmt
) loop
3371 Process_Nodes
(Stmt
);
3376 -- Start of processing for Protected_Component_Ref
3379 -- Get the type size
3381 if Known_Static_Esize
(Comp_Type
) then
3382 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3384 -- If the Esize (Object_Size) is unknown at compile time, look at
3385 -- the RM_Size (Value_Size) since it may have been set by an
3386 -- explicit representation clause.
3388 elsif Known_Static_RM_Size
(Comp_Type
) then
3389 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3391 -- Should not happen since this has already been checked in
3392 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3395 raise Program_Error
;
3398 -- Retrieve all relevant atomic routines and types
3402 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3403 Read
:= RTE
(RE_Lock_Free_Read_8
);
3404 Unsigned
:= RTE
(RE_Uint8
);
3407 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3408 Read
:= RTE
(RE_Lock_Free_Read_16
);
3409 Unsigned
:= RTE
(RE_Uint16
);
3412 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3413 Read
:= RTE
(RE_Lock_Free_Read_32
);
3414 Unsigned
:= RTE
(RE_Uint32
);
3417 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3418 Read
:= RTE
(RE_Lock_Free_Read_64
);
3419 Unsigned
:= RTE
(RE_Uint64
);
3422 raise Program_Error
;
3426 -- Expected_Comp : constant Comp_Type :=
3428 -- (System.Atomic_Primitives.Lock_Free_Read_N
3429 -- (_Object.Comp'Address));
3432 Make_Defining_Identifier
(Loc
,
3433 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3436 Make_Object_Declaration
(Loc
,
3437 Defining_Identifier
=> Expected_Comp
,
3438 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3439 Constant_Present
=> True,
3441 Unchecked_Convert_To
(Comp_Type
,
3442 Make_Function_Call
(Loc
,
3443 Name
=> New_Occurrence_Of
(Read
, Loc
),
3444 Parameter_Associations
=> New_List
(
3445 Make_Attribute_Reference
(Loc
,
3446 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3447 Attribute_Name
=> Name_Address
)))));
3449 -- Protected procedures
3451 if Is_Procedure
then
3452 -- Move the original declarations inside the generated block
3454 Block_Decls
:= Decls
;
3456 -- Reset the declarations list of the protected procedure to
3457 -- contain only Decl.
3459 Decls
:= New_List
(Decl
);
3462 -- Desired_Comp : Comp_Type := Expected_Comp;
3465 Make_Defining_Identifier
(Loc
,
3466 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3468 -- Insert the declarations of Expected_Comp and Desired_Comp in
3469 -- the block declarations right before the renaming of the
3470 -- protected component.
3472 Insert_Before
(Comp_Decl
,
3473 Make_Object_Declaration
(Loc
,
3474 Defining_Identifier
=> Desired_Comp
,
3475 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3477 New_Occurrence_Of
(Expected_Comp
, Loc
)));
3479 -- Protected function
3482 Desired_Comp
:= Expected_Comp
;
3484 -- Insert the declaration of Expected_Comp in the function
3485 -- declarations right before the renaming of the protected
3488 Insert_Before
(Comp_Decl
, Decl
);
3491 -- Rewrite the protected component renaming declaration to be a
3492 -- renaming of Desired_Comp.
3495 -- Comp : Comp_Type renames Desired_Comp;
3498 Make_Object_Renaming_Declaration
(Loc
,
3499 Defining_Identifier
=>
3500 Defining_Identifier
(Comp_Decl
),
3502 New_Occurrence_Of
(Comp_Type
, Loc
),
3504 New_Occurrence_Of
(Desired_Comp
, Loc
)));
3506 -- Wrap any return or raise statements in Stmts in same the manner
3507 -- described in Process_Stmts.
3509 Process_Stmts
(Stmts
);
3512 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3513 -- (_Object.Comp'Address,
3514 -- Interfaces.Unsigned_N (Expected_Comp),
3515 -- Interfaces.Unsigned_N (Desired_Comp))
3517 if Is_Procedure
then
3519 Make_Exit_Statement
(Loc
,
3521 Make_Function_Call
(Loc
,
3523 New_Occurrence_Of
(Try_Write
, Loc
),
3524 Parameter_Associations
=> New_List
(
3525 Make_Attribute_Reference
(Loc
,
3526 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3527 Attribute_Name
=> Name_Address
),
3529 Unchecked_Convert_To
(Unsigned
,
3530 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3532 Unchecked_Convert_To
(Unsigned
,
3533 New_Occurrence_Of
(Desired_Comp
, Loc
)))));
3535 -- Small optimization: transform the default return statement
3536 -- of a procedure into the atomic exit statement.
3538 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3539 Rewrite
(Last
(Stmts
), Stmt
);
3541 Append_To
(Stmts
, Stmt
);
3545 -- Create the declaration of the label used to skip the rest of
3546 -- the source statements when the object state changes.
3548 if Present
(Label_Id
) then
3549 Label
:= Make_Label
(Loc
, Label_Id
);
3551 Make_Implicit_Label_Declaration
(Loc
,
3552 Defining_Identifier
=> Entity
(Label_Id
),
3553 Label_Construct
=> Label
));
3554 Append_To
(Stmts
, Label
);
3566 if Is_Procedure
then
3569 Make_Loop_Statement
(Loc
,
3570 Statements
=> New_List
(
3571 Make_Block_Statement
(Loc
,
3572 Declarations
=> Block_Decls
,
3573 Handled_Statement_Sequence
=>
3574 Make_Handled_Sequence_Of_Statements
(Loc
,
3575 Statements
=> Stmts
))),
3576 End_Label
=> Empty
));
3580 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3581 end Protected_Component_Ref
;
3584 -- Make an unprotected version of the subprogram for use within the same
3585 -- object, with new name and extra parameter representing the object.
3588 Make_Subprogram_Body
(Loc
,
3590 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3591 Declarations
=> Decls
,
3592 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3593 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3595 -------------------------
3596 -- Build_Master_Entity --
3597 -------------------------
3599 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3600 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3602 Context_Id
: Entity_Id
;
3608 if Is_Itype
(Obj_Or_Typ
) then
3609 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3611 Par
:= Parent
(Obj_Or_Typ
);
3614 -- When creating a master for a record component which is either a task
3615 -- or access-to-task, the enclosing record is the master scope and the
3616 -- proper insertion point is the component list.
3618 if Is_Record_Type
(Current_Scope
) then
3620 Context_Id
:= Current_Scope
;
3621 Decls
:= List_Containing
(Context
);
3623 -- Default case for object declarations and access types. Note that the
3624 -- context is updated to the nearest enclosing body, block, package or
3625 -- return statement.
3628 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3631 -- Do not create a master if one already exists or there is no task
3634 if Has_Master_Entity
(Context_Id
)
3635 or else Restriction_Active
(No_Task_Hierarchy
)
3640 -- Create a master, generate:
3641 -- _Master : constant Master_Id := Current_Master.all;
3644 Make_Object_Declaration
(Loc
,
3645 Defining_Identifier
=>
3646 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3647 Constant_Present
=> True,
3648 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3650 Make_Explicit_Dereference
(Loc
,
3651 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
3653 -- The master is inserted at the start of the declarative list of the
3656 Prepend_To
(Decls
, Decl
);
3658 -- In certain cases where transient scopes are involved, the immediate
3659 -- scope is not always the proper master scope. Ensure that the master
3660 -- declaration and entity appear in the same context.
3662 if Context_Id
/= Current_Scope
then
3663 Push_Scope
(Context_Id
);
3670 -- Mark the enclosing scope and its associated construct as being task
3673 Set_Has_Master_Entity
(Context_Id
);
3675 while Present
(Context
)
3676 and then Nkind
(Context
) /= N_Compilation_Unit
3678 if Nkind_In
(Context
, N_Block_Statement
,
3682 Set_Is_Task_Master
(Context
);
3685 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3686 Context
:= Corresponding_Stub
(Parent
(Context
));
3689 Context
:= Parent
(Context
);
3691 end Build_Master_Entity
;
3693 ---------------------------
3694 -- Build_Master_Renaming --
3695 ---------------------------
3697 procedure Build_Master_Renaming
3698 (Ptr_Typ
: Entity_Id
;
3699 Ins_Nod
: Node_Id
:= Empty
)
3701 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3703 Master_Decl
: Node_Id
;
3704 Master_Id
: Entity_Id
;
3707 -- Nothing to do if there is no task hierarchy
3709 if Restriction_Active
(No_Task_Hierarchy
) then
3713 -- Determine the proper context to insert the master renaming
3715 if Present
(Ins_Nod
) then
3717 elsif Is_Itype
(Ptr_Typ
) then
3718 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3720 Context
:= Parent
(Ptr_Typ
);
3724 -- <Ptr_Typ>M : Master_Id renames _Master;
3727 Make_Defining_Identifier
(Loc
,
3728 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3731 Make_Object_Renaming_Declaration
(Loc
,
3732 Defining_Identifier
=> Master_Id
,
3733 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
3734 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3736 Insert_Action
(Context
, Master_Decl
);
3738 -- The renamed master now services the access type
3740 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3741 end Build_Master_Renaming
;
3743 -----------------------------------------
3744 -- Build_Private_Protected_Declaration --
3745 -----------------------------------------
3747 function Build_Private_Protected_Declaration
3748 (N
: Node_Id
) return Entity_Id
3750 Loc
: constant Source_Ptr
:= Sloc
(N
);
3751 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3756 Spec_Id
: Entity_Id
;
3759 Formal
:= First_Formal
(Body_Id
);
3761 -- The protected operation always has at least one formal, namely the
3762 -- object itself, but it is only placed in the parameter list if
3763 -- expansion is enabled.
3765 if Present
(Formal
) or else Expander_Active
then
3766 Plist
:= Copy_Parameter_List
(Body_Id
);
3771 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3773 Make_Procedure_Specification
(Loc
,
3774 Defining_Unit_Name
=>
3775 Make_Defining_Identifier
(Sloc
(Body_Id
),
3776 Chars
=> Chars
(Body_Id
)),
3777 Parameter_Specifications
=>
3781 Make_Function_Specification
(Loc
,
3782 Defining_Unit_Name
=>
3783 Make_Defining_Identifier
(Sloc
(Body_Id
),
3784 Chars
=> Chars
(Body_Id
)),
3785 Parameter_Specifications
=> Plist
,
3786 Result_Definition
=>
3787 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3790 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3791 Insert_Before
(N
, Decl
);
3792 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3794 -- Indicate that the entity comes from source, to ensure that cross-
3795 -- reference information is properly generated. The body itself is
3796 -- rewritten during expansion, and the body entity will not appear in
3797 -- calls to the operation.
3799 Set_Comes_From_Source
(Spec_Id
, True);
3801 Set_Has_Completion
(Spec_Id
);
3802 Set_Convention
(Spec_Id
, Convention_Protected
);
3804 end Build_Private_Protected_Declaration
;
3806 ---------------------------
3807 -- Build_Protected_Entry --
3808 ---------------------------
3810 function Build_Protected_Entry
3813 Pid
: Node_Id
) return Node_Id
3815 Loc
: constant Source_Ptr
:= Sloc
(N
);
3817 Decls
: constant List_Id
:= Declarations
(N
);
3818 End_Lab
: constant Node_Id
:=
3819 End_Label
(Handled_Statement_Sequence
(N
));
3820 End_Loc
: constant Source_Ptr
:=
3821 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3822 -- Used for the generated call to Complete_Entry_Body
3824 Han_Loc
: Source_Ptr
;
3825 -- Used for the exception handler, inserted at end of the body
3827 Op_Decls
: constant List_Id
:= New_List
;
3835 -- Set the source location on the exception handler only when debugging
3836 -- the expanded code (see Make_Implicit_Exception_Handler).
3838 if Debug_Generated_Code
then
3841 -- Otherwise the inserted code should not be visible to the debugger
3844 Han_Loc
:= No_Location
;
3848 Make_Defining_Identifier
(Loc
,
3849 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3851 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
3853 -- Add the following declarations:
3855 -- type poVP is access poV;
3856 -- _object : poVP := poVP (_O);
3858 -- where _O is the formal parameter associated with the concurrent
3859 -- object. These declarations are needed for Complete_Entry_Body.
3861 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
3863 -- Add renamings for all formals, the Protection object, discriminals,
3864 -- privals and the entry index constant for use by debugger.
3866 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
3867 Debug_Private_Data_Declarations
(Decls
);
3869 -- Put the declarations and the statements from the entry
3873 Make_Block_Statement
(Loc
,
3874 Declarations
=> Decls
,
3875 Handled_Statement_Sequence
=>
3876 Handled_Statement_Sequence
(N
)));
3878 case Corresponding_Runtime_Package
(Pid
) is
3879 when System_Tasking_Protected_Objects_Entries
=>
3880 Append_To
(Op_Stats
,
3881 Make_Procedure_Call_Statement
(End_Loc
,
3883 New_Occurrence_Of
(RTE
(RE_Complete_Entry_Body
), Loc
),
3884 Parameter_Associations
=> New_List
(
3885 Make_Attribute_Reference
(End_Loc
,
3887 Make_Selected_Component
(End_Loc
,
3889 Make_Identifier
(End_Loc
, Name_uObject
),
3891 Make_Identifier
(End_Loc
, Name_uObject
)),
3892 Attribute_Name
=> Name_Unchecked_Access
))));
3894 when System_Tasking_Protected_Objects_Single_Entry
=>
3896 -- Historically, a call to Complete_Single_Entry_Body was
3897 -- inserted, but it was a null procedure.
3902 raise Program_Error
;
3905 -- When exceptions can not be propagated, we never need to call
3906 -- Exception_Complete_Entry_Body
3908 if No_Exception_Handlers_Set
then
3910 Make_Subprogram_Body
(Loc
,
3911 Specification
=> Espec
,
3912 Declarations
=> Op_Decls
,
3913 Handled_Statement_Sequence
=>
3914 Make_Handled_Sequence_Of_Statements
(Loc
,
3915 Statements
=> Op_Stats
,
3916 End_Label
=> End_Lab
));
3919 Ohandle
:= Make_Others_Choice
(Loc
);
3920 Set_All_Others
(Ohandle
);
3922 case Corresponding_Runtime_Package
(Pid
) is
3923 when System_Tasking_Protected_Objects_Entries
=>
3926 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3928 when System_Tasking_Protected_Objects_Single_Entry
=>
3931 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3934 raise Program_Error
;
3937 -- Establish link between subprogram body entity and source entry
3939 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
3941 -- Create body of entry procedure. The renaming declarations are
3942 -- placed ahead of the block that contains the actual entry body.
3945 Make_Subprogram_Body
(Loc
,
3946 Specification
=> Espec
,
3947 Declarations
=> Op_Decls
,
3948 Handled_Statement_Sequence
=>
3949 Make_Handled_Sequence_Of_Statements
(Loc
,
3950 Statements
=> Op_Stats
,
3951 End_Label
=> End_Lab
,
3952 Exception_Handlers
=> New_List
(
3953 Make_Implicit_Exception_Handler
(Han_Loc
,
3954 Exception_Choices
=> New_List
(Ohandle
),
3956 Statements
=> New_List
(
3957 Make_Procedure_Call_Statement
(Han_Loc
,
3959 Parameter_Associations
=> New_List
(
3960 Make_Attribute_Reference
(Han_Loc
,
3962 Make_Selected_Component
(Han_Loc
,
3964 Make_Identifier
(Han_Loc
, Name_uObject
),
3966 Make_Identifier
(Han_Loc
, Name_uObject
)),
3967 Attribute_Name
=> Name_Unchecked_Access
),
3969 Make_Function_Call
(Han_Loc
,
3970 Name
=> New_Occurrence_Of
(
3971 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3973 end Build_Protected_Entry
;
3975 -----------------------------------------
3976 -- Build_Protected_Entry_Specification --
3977 -----------------------------------------
3979 function Build_Protected_Entry_Specification
3982 Ent_Id
: Entity_Id
) return Node_Id
3984 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3987 Set_Debug_Info_Needed
(Def_Id
);
3989 if Present
(Ent_Id
) then
3990 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3994 Make_Procedure_Specification
(Loc
,
3995 Defining_Unit_Name
=> Def_Id
,
3996 Parameter_Specifications
=> New_List
(
3997 Make_Parameter_Specification
(Loc
,
3998 Defining_Identifier
=>
3999 Make_Defining_Identifier
(Loc
, Name_uO
),
4001 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
4003 Make_Parameter_Specification
(Loc
,
4004 Defining_Identifier
=> P
,
4006 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
4008 Make_Parameter_Specification
(Loc
,
4009 Defining_Identifier
=>
4010 Make_Defining_Identifier
(Loc
, Name_uE
),
4012 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))));
4013 end Build_Protected_Entry_Specification
;
4015 --------------------------
4016 -- Build_Protected_Spec --
4017 --------------------------
4019 function Build_Protected_Spec
4021 Obj_Type
: Entity_Id
;
4023 Unprotected
: Boolean := False) return List_Id
4025 Loc
: constant Source_Ptr
:= Sloc
(N
);
4028 New_Plist
: List_Id
;
4029 New_Param
: Node_Id
;
4032 New_Plist
:= New_List
;
4034 Formal
:= First_Formal
(Ident
);
4035 while Present
(Formal
) loop
4037 Make_Parameter_Specification
(Loc
,
4038 Defining_Identifier
=>
4039 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
4040 In_Present
=> In_Present
(Parent
(Formal
)),
4041 Out_Present
=> Out_Present
(Parent
(Formal
)),
4042 Parameter_Type
=> New_Occurrence_Of
(Etype
(Formal
), Loc
));
4045 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
4048 Append
(New_Param
, New_Plist
);
4049 Next_Formal
(Formal
);
4052 -- If the subprogram is a procedure and the context is not an access
4053 -- to protected subprogram, the parameter is in-out. Otherwise it is
4057 Make_Parameter_Specification
(Loc
,
4058 Defining_Identifier
=>
4059 Make_Defining_Identifier
(Loc
, Name_uObject
),
4062 (Etype
(Ident
) = Standard_Void_Type
4063 and then not Is_RTE
(Obj_Type
, RE_Address
)),
4065 New_Occurrence_Of
(Obj_Type
, Loc
));
4066 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4067 Prepend_To
(New_Plist
, Decl
);
4070 end Build_Protected_Spec
;
4072 ---------------------------------------
4073 -- Build_Protected_Sub_Specification --
4074 ---------------------------------------
4076 function Build_Protected_Sub_Specification
4078 Prot_Typ
: Entity_Id
;
4079 Mode
: Subprogram_Protection_Mode
) return Node_Id
4081 Loc
: constant Source_Ptr
:= Sloc
(N
);
4085 New_Plist
: List_Id
;
4088 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
4089 (Dispatching_Mode
=> ' ',
4090 Protected_Mode
=> 'P',
4091 Unprotected_Mode
=> 'N');
4094 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
4097 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
4102 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
4105 Build_Protected_Spec
4106 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
4107 Mode
= Unprotected_Mode
);
4109 Make_Defining_Identifier
(Loc
,
4110 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
4112 -- The unprotected operation carries the user code, and debugging
4113 -- information must be generated for it, even though this spec does
4114 -- not come from source. It is also convenient to allow gdb to step
4115 -- into the protected operation, even though it only contains lock/
4118 Set_Debug_Info_Needed
(New_Id
);
4120 -- If a pragma Eliminate applies to the source entity, the internal
4121 -- subprograms will be eliminated as well.
4123 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
4125 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
4127 Make_Procedure_Specification
(Loc
,
4128 Defining_Unit_Name
=> New_Id
,
4129 Parameter_Specifications
=> New_Plist
);
4131 -- Create a new specification for the anonymous subprogram type
4135 Make_Function_Specification
(Loc
,
4136 Defining_Unit_Name
=> New_Id
,
4137 Parameter_Specifications
=> New_Plist
,
4138 Result_Definition
=>
4139 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
4141 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
4145 end Build_Protected_Sub_Specification
;
4147 -------------------------------------
4148 -- Build_Protected_Subprogram_Body --
4149 -------------------------------------
4151 function Build_Protected_Subprogram_Body
4154 N_Op_Spec
: Node_Id
) return Node_Id
4156 Loc
: constant Source_Ptr
:= Sloc
(N
);
4158 P_Op_Spec
: Node_Id
;
4161 Unprot_Call
: Node_Id
;
4163 Lock_Name
: Node_Id
;
4164 Lock_Stmt
: Node_Id
;
4166 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
4167 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
4169 Object_Parm
: Node_Id
;
4174 Op_Spec
:= Specification
(N
);
4175 Exc_Safe
:= Is_Exception_Safe
(N
);
4178 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
4180 -- Build a list of the formal parameters of the protected version of
4181 -- the subprogram to use as the actual parameters of the unprotected
4184 Uactuals
:= New_List
;
4185 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
4186 while Present
(Pformal
) loop
4187 Append_To
(Uactuals
,
4188 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
4192 -- Make a call to the unprotected version of the subprogram built above
4193 -- for use by the protected version built below.
4195 if Nkind
(Op_Spec
) = N_Function_Specification
then
4197 R
:= Make_Temporary
(Loc
, 'R');
4199 Make_Object_Declaration
(Loc
,
4200 Defining_Identifier
=> R
,
4201 Constant_Present
=> True,
4202 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
4204 Make_Function_Call
(Loc
,
4205 Name
=> Make_Identifier
(Loc
,
4206 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4207 Parameter_Associations
=> Uactuals
));
4210 Make_Simple_Return_Statement
(Loc
,
4211 Expression
=> New_Occurrence_Of
(R
, Loc
));
4214 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
4215 Expression
=> Make_Function_Call
(Loc
,
4217 Make_Identifier
(Loc
,
4218 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4219 Parameter_Associations
=> Uactuals
));
4222 Lock_Kind
:= RE_Lock_Read_Only
;
4226 Make_Procedure_Call_Statement
(Loc
,
4228 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4229 Parameter_Associations
=> Uactuals
);
4231 Lock_Kind
:= RE_Lock
;
4234 -- Wrap call in block that will be covered by an at_end handler
4236 if not Exc_Safe
then
4237 Unprot_Call
:= Make_Block_Statement
(Loc
,
4238 Handled_Statement_Sequence
=>
4239 Make_Handled_Sequence_Of_Statements
(Loc
,
4240 Statements
=> New_List
(Unprot_Call
)));
4243 -- Make the protected subprogram body. This locks the protected
4244 -- object and calls the unprotected version of the subprogram.
4246 case Corresponding_Runtime_Package
(Pid
) is
4247 when System_Tasking_Protected_Objects_Entries
=>
4248 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entries
), Loc
);
4250 when System_Tasking_Protected_Objects_Single_Entry
=>
4251 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entry
), Loc
);
4253 when System_Tasking_Protected_Objects
=>
4254 Lock_Name
:= New_Occurrence_Of
(RTE
(Lock_Kind
), Loc
);
4257 raise Program_Error
;
4261 Make_Attribute_Reference
(Loc
,
4263 Make_Selected_Component
(Loc
,
4264 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4265 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4266 Attribute_Name
=> Name_Unchecked_Access
);
4268 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
4270 Parameter_Associations
=> New_List
(Object_Parm
));
4272 if Abort_Allowed
then
4274 Make_Procedure_Call_Statement
(Loc
,
4275 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Defer
), Loc
),
4276 Parameter_Associations
=> Empty_List
),
4280 Stmts
:= New_List
(Lock_Stmt
);
4283 if not Exc_Safe
then
4284 Append
(Unprot_Call
, Stmts
);
4286 if Nkind
(Op_Spec
) = N_Function_Specification
then
4288 Stmts
:= Empty_List
;
4290 Append
(Unprot_Call
, Stmts
);
4293 -- Historical note: Previously, call the the cleanup was inserted
4294 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4295 -- which is also shared by the 'not Exc_Safe' path.
4297 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
4299 if Nkind
(Op_Spec
) = N_Function_Specification
then
4300 Append
(Return_Stmt
, Stmts
);
4301 Append
(Make_Block_Statement
(Loc
,
4302 Declarations
=> New_List
(Unprot_Call
),
4303 Handled_Statement_Sequence
=>
4304 Make_Handled_Sequence_Of_Statements
(Loc
,
4305 Statements
=> Stmts
)), Pre_Stmts
);
4311 Make_Subprogram_Body
(Loc
,
4312 Declarations
=> Empty_List
,
4313 Specification
=> P_Op_Spec
,
4314 Handled_Statement_Sequence
=>
4315 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4317 -- Mark this subprogram as a protected subprogram body so that the
4318 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4319 -- path as otherwise the cleanup has already been inserted.
4321 if not Exc_Safe
then
4322 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4326 end Build_Protected_Subprogram_Body
;
4328 -------------------------------------
4329 -- Build_Protected_Subprogram_Call --
4330 -------------------------------------
4332 procedure Build_Protected_Subprogram_Call
4336 External
: Boolean := True)
4338 Loc
: constant Source_Ptr
:= Sloc
(N
);
4339 Sub
: constant Entity_Id
:= Entity
(Name
);
4345 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4348 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4351 if Present
(Parameter_Associations
(N
)) then
4352 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4357 -- If the type is an untagged derived type, convert to the root type,
4358 -- which is the one on which the operations are defined.
4360 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4361 and then not Is_Tagged_Type
(Etype
(Rec
))
4362 and then Is_Derived_Type
(Etype
(Rec
))
4364 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4365 Set_Subtype_Mark
(Rec
,
4366 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4369 Prepend
(Rec
, Params
);
4371 if Ekind
(Sub
) = E_Procedure
then
4373 Make_Procedure_Call_Statement
(Loc
,
4375 Parameter_Associations
=> Params
));
4378 pragma Assert
(Ekind
(Sub
) = E_Function
);
4380 Make_Function_Call
(Loc
,
4382 Parameter_Associations
=> Params
));
4384 -- Preserve type of call for subsequent processing (required for
4385 -- call to Wrap_Transient_Expression in the case of a shared passive
4388 Set_Etype
(N
, Etype
(New_Sub
));
4392 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4393 and then Is_Entity_Name
(Expression
(Rec
))
4394 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4396 Add_Shared_Var_Lock_Procs
(N
);
4398 end Build_Protected_Subprogram_Call
;
4400 ---------------------------------------------
4401 -- Build_Protected_Subprogram_Call_Cleanup --
4402 ---------------------------------------------
4404 procedure Build_Protected_Subprogram_Call_Cleanup
4413 -- If the associated protected object has entries, a protected
4414 -- procedure has to service entry queues. In this case generate:
4416 -- Service_Entries (_object._object'Access);
4418 if Nkind
(Op_Spec
) = N_Procedure_Specification
4419 and then Has_Entries
(Conc_Typ
)
4421 case Corresponding_Runtime_Package
(Conc_Typ
) is
4422 when System_Tasking_Protected_Objects_Entries
=>
4423 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entries
), Loc
);
4425 when System_Tasking_Protected_Objects_Single_Entry
=>
4426 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entry
), Loc
);
4429 raise Program_Error
;
4433 Make_Procedure_Call_Statement
(Loc
,
4435 Parameter_Associations
=> New_List
(
4436 Make_Attribute_Reference
(Loc
,
4438 Make_Selected_Component
(Loc
,
4439 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4440 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4441 Attribute_Name
=> Name_Unchecked_Access
))));
4445 -- Unlock (_object._object'Access);
4447 case Corresponding_Runtime_Package
(Conc_Typ
) is
4448 when System_Tasking_Protected_Objects_Entries
=>
4449 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entries
), Loc
);
4451 when System_Tasking_Protected_Objects_Single_Entry
=>
4452 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entry
), Loc
);
4454 when System_Tasking_Protected_Objects
=>
4455 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock
), Loc
);
4458 raise Program_Error
;
4462 Make_Procedure_Call_Statement
(Loc
,
4464 Parameter_Associations
=> New_List
(
4465 Make_Attribute_Reference
(Loc
,
4467 Make_Selected_Component
(Loc
,
4468 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4469 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4470 Attribute_Name
=> Name_Unchecked_Access
))));
4476 if Abort_Allowed
then
4478 Make_Procedure_Call_Statement
(Loc
,
4480 New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
),
4481 Parameter_Associations
=> Empty_List
));
4483 end Build_Protected_Subprogram_Call_Cleanup
;
4485 -------------------------
4486 -- Build_Selected_Name --
4487 -------------------------
4489 function Build_Selected_Name
4490 (Prefix
: Entity_Id
;
4491 Selector
: Entity_Id
;
4492 Append_Char
: Character := ' ') return Name_Id
4494 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4495 Select_Len
: Natural;
4498 Get_Name_String
(Chars
(Selector
));
4499 Select_Len
:= Name_Len
;
4500 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4501 Get_Name_String
(Chars
(Prefix
));
4503 -- If scope is anonymous type, discard suffix to recover name of
4504 -- single protected object. Otherwise use protected type name.
4506 if Name_Buffer
(Name_Len
) = 'T' then
4507 Name_Len
:= Name_Len
- 1;
4510 Add_Str_To_Name_Buffer
("__");
4511 for J
in 1 .. Select_Len
loop
4512 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4515 -- Now add the Append_Char if specified. The encoding to follow
4516 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4517 -- then the entity is associated to a protected type subprogram.
4518 -- Otherwise, it is a protected type entry. For each case, the
4519 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4521 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4523 if Append_Char
/= ' ' then
4524 if Append_Char
= 'P' or Append_Char
= 'N' then
4525 Add_Char_To_Name_Buffer
(Append_Char
);
4528 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4529 return New_External_Name
(Name_Find
, ' ', -1);
4534 end Build_Selected_Name
;
4536 -----------------------------
4537 -- Build_Simple_Entry_Call --
4538 -----------------------------
4540 -- A task entry call is converted to a call to Call_Simple
4543 -- P : parms := (parm, parm, parm);
4545 -- Call_Simple (acceptor-task, entry-index, P'Address);
4551 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4552 -- the parameters, and the constructed aggregate value contains either the
4553 -- parameters or, in the case of non-elementary types, references to these
4554 -- parameters. Then the address of this aggregate is passed to the runtime
4555 -- routine, along with the task id value and the task entry index value.
4556 -- Pnn is only required if parameters are present.
4558 -- The assignments after the call are present only in the case of in-out
4559 -- or out parameters for elementary types, and are used to assign back the
4560 -- resulting values of such parameters.
4562 -- Note: the reason that we insert a block here is that in the context
4563 -- of selects, conditional entry calls etc. the entry call statement
4564 -- appears on its own, not as an element of a list.
4566 -- A protected entry call is converted to a Protected_Entry_Call:
4569 -- P : E1_Params := (param, param, param);
4571 -- Bnn : Communications_Block;
4574 -- P : E1_Params := (param, param, param);
4575 -- Bnn : Communications_Block;
4578 -- Protected_Entry_Call (
4579 -- Object => po._object'Access,
4580 -- E => <entry index>;
4581 -- Uninterpreted_Data => P'Address;
4582 -- Mode => Simple_Call;
4589 procedure Build_Simple_Entry_Call
4598 -- If call has been inlined, nothing left to do
4600 if Nkind
(N
) = N_Block_Statement
then
4604 -- Convert entry call to Call_Simple call
4607 Loc
: constant Source_Ptr
:= Sloc
(N
);
4608 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4609 Stats
: constant List_Id
:= New_List
;
4612 Comm_Name
: Entity_Id
;
4616 Ent_Acc
: Entity_Id
;
4618 Iface_Tag
: Entity_Id
;
4619 Iface_Typ
: Entity_Id
;
4632 -- Simple entry and entry family cases merge here
4634 Ent
:= Entity
(Ename
);
4635 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4636 Conctyp
:= Etype
(Concval
);
4638 -- If prefix is an access type, dereference to obtain the task type
4640 if Is_Access_Type
(Conctyp
) then
4641 Conctyp
:= Designated_Type
(Conctyp
);
4644 -- Special case for protected subprogram calls
4646 if Is_Protected_Type
(Conctyp
)
4647 and then Is_Subprogram
(Entity
(Ename
))
4649 if not Is_Eliminated
(Entity
(Ename
)) then
4650 Build_Protected_Subprogram_Call
4651 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4658 -- First parameter is the Task_Id value from the task value or the
4659 -- Object from the protected object value, obtained by selecting
4660 -- the _Task_Id or _Object from the result of doing an unchecked
4661 -- conversion to convert the value to the corresponding record type.
4663 if Nkind
(Concval
) = N_Function_Call
4664 and then Is_Task_Type
(Conctyp
)
4665 and then Ada_Version
>= Ada_2005
4668 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4669 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4674 Make_Object_Declaration
(Loc
,
4675 Defining_Identifier
=> Obj
,
4676 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4677 Expression
=> ExpR
);
4678 Set_Etype
(Obj
, Conctyp
);
4679 Decls
:= New_List
(Decl
);
4680 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4687 Parm1
:= Concurrent_Ref
(Concval
);
4689 -- Second parameter is the entry index, computed by the routine
4690 -- provided for this purpose. The value of this expression is
4691 -- assigned to an intermediate variable to assure that any entry
4692 -- family index expressions are evaluated before the entry
4695 if not Is_Protected_Type
(Conctyp
)
4697 Corresponding_Runtime_Package
(Conctyp
) =
4698 System_Tasking_Protected_Objects_Entries
4700 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4703 Make_Object_Declaration
(Loc
,
4704 Defining_Identifier
=> X
,
4705 Object_Definition
=>
4706 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
4707 Expression
=> Actual_Index_Expression
(
4708 Loc
, Entity
(Ename
), Index
, Concval
));
4710 Append_To
(Decls
, Xdecl
);
4711 Parm2
:= New_Occurrence_Of
(X
, Loc
);
4718 -- The third parameter is the packaged parameters. If there are
4719 -- none, then it is just the null address, since nothing is passed.
4722 Parm3
:= New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
);
4725 -- Case of parameters present, where third argument is the address
4726 -- of a packaged record containing the required parameter values.
4729 -- First build a list of parameter values, which are references to
4730 -- objects of the parameter types.
4734 Actual
:= First_Actual
(N
);
4735 Formal
:= First_Formal
(Ent
);
4736 while Present
(Actual
) loop
4738 -- If it is a by_copy_type, copy it to a new variable. The
4739 -- packaged record has a field that points to this variable.
4741 if Is_By_Copy_Type
(Etype
(Actual
)) then
4743 Make_Object_Declaration
(Loc
,
4744 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4745 Aliased_Present
=> True,
4746 Object_Definition
=>
4747 New_Occurrence_Of
(Etype
(Formal
), Loc
));
4749 -- Mark the object as not needing initialization since the
4750 -- initialization is performed separately, avoiding errors
4751 -- on cases such as formals of null-excluding access types.
4753 Set_No_Initialization
(N_Node
);
4755 -- We must make an assignment statement separate for the
4756 -- case of limited type. We cannot assign it unless the
4757 -- Assignment_OK flag is set first. An out formal of an
4758 -- access type must also be initialized from the actual,
4759 -- as stated in RM 6.4.1 (13), but no constraint is applied
4762 if Ekind
(Formal
) /= E_Out_Parameter
4763 or else Is_Access_Type
(Etype
(Formal
))
4766 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
);
4767 Set_Assignment_OK
(N_Var
);
4769 Make_Assignment_Statement
(Loc
,
4771 Expression
=> Relocate_Node
(Actual
)));
4773 -- If actual is an out parameter of a null-excluding
4774 -- access type, there is access check on entry, so set
4775 -- Suppress_Assignment_Checks on the generated statement
4776 -- that assigns the actual to the parameter block
4778 Set_Suppress_Assignment_Checks
(Last
(Stats
));
4781 Append
(N_Node
, Decls
);
4784 Make_Attribute_Reference
(Loc
,
4785 Attribute_Name
=> Name_Unchecked_Access
,
4787 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
)));
4789 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4791 elsif Is_VM_By_Copy_Actual
(Actual
) then
4793 Make_Object_Declaration
(Loc
,
4794 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4795 Aliased_Present
=> True,
4796 Object_Definition
=>
4797 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4798 Expression
=> New_Copy_Tree
(Actual
));
4799 Set_Assignment_OK
(N_Node
);
4801 Append
(N_Node
, Decls
);
4804 Make_Attribute_Reference
(Loc
,
4805 Attribute_Name
=> Name_Unchecked_Access
,
4807 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
)));
4810 -- Interface class-wide formal
4812 if Ada_Version
>= Ada_2005
4813 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4814 and then Is_Interface
(Etype
(Formal
))
4816 Iface_Typ
:= Etype
(Etype
(Formal
));
4819 -- formal_iface_type! (actual.iface_tag)'reference
4822 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4823 pragma Assert
(Present
(Iface_Tag
));
4826 Make_Reference
(Loc
,
4827 Unchecked_Convert_To
(Iface_Typ
,
4828 Make_Selected_Component
(Loc
,
4830 Relocate_Node
(Actual
),
4832 New_Occurrence_Of
(Iface_Tag
, Loc
)))));
4838 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4842 Next_Actual
(Actual
);
4843 Next_Formal_With_Extras
(Formal
);
4846 -- Now build the declaration of parameters initialized with the
4847 -- aggregate containing this constructed parameter list.
4849 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4852 Make_Object_Declaration
(Loc
,
4853 Defining_Identifier
=> P
,
4854 Object_Definition
=>
4855 New_Occurrence_Of
(Designated_Type
(Ent_Acc
), Loc
),
4857 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4860 Make_Attribute_Reference
(Loc
,
4861 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4862 Attribute_Name
=> Name_Address
);
4864 Append
(Pdecl
, Decls
);
4867 -- Now we can create the call, case of protected type
4869 if Is_Protected_Type
(Conctyp
) then
4870 case Corresponding_Runtime_Package
(Conctyp
) is
4871 when System_Tasking_Protected_Objects_Entries
=>
4873 -- Change the type of the index declaration
4875 Set_Object_Definition
(Xdecl
,
4876 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
));
4878 -- Some additional declarations for protected entry calls
4884 -- Bnn : Communications_Block;
4886 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4889 Make_Object_Declaration
(Loc
,
4890 Defining_Identifier
=> Comm_Name
,
4891 Object_Definition
=>
4893 (RTE
(RE_Communication_Block
), Loc
)));
4895 -- Some additional statements for protected entry calls
4897 -- Protected_Entry_Call (
4898 -- Object => po._object'Access,
4899 -- E => <entry index>;
4900 -- Uninterpreted_Data => P'Address;
4901 -- Mode => Simple_Call;
4905 Make_Procedure_Call_Statement
(Loc
,
4907 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
4909 Parameter_Associations
=> New_List
(
4910 Make_Attribute_Reference
(Loc
,
4911 Attribute_Name
=> Name_Unchecked_Access
,
4915 New_Occurrence_Of
(RTE
(RE_Simple_Call
), Loc
),
4916 New_Occurrence_Of
(Comm_Name
, Loc
)));
4918 when System_Tasking_Protected_Objects_Single_Entry
=>
4919 -- Protected_Single_Entry_Call (
4920 -- Object => po._object'Access,
4921 -- Uninterpreted_Data => P'Address);
4924 Make_Procedure_Call_Statement
(Loc
,
4925 Name
=> New_Occurrence_Of
(
4926 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4928 Parameter_Associations
=> New_List
(
4929 Make_Attribute_Reference
(Loc
,
4930 Attribute_Name
=> Name_Unchecked_Access
,
4935 raise Program_Error
;
4938 -- Case of task type
4942 Make_Procedure_Call_Statement
(Loc
,
4943 Name
=> New_Occurrence_Of
(RTE
(RE_Call_Simple
), Loc
),
4944 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4948 Append_To
(Stats
, Call
);
4950 -- If there are out or in/out parameters by copy add assignment
4951 -- statements for the result values.
4953 if Present
(Parms
) then
4954 Actual
:= First_Actual
(N
);
4955 Formal
:= First_Formal
(Ent
);
4957 Set_Assignment_OK
(Actual
);
4958 while Present
(Actual
) loop
4959 if (Is_By_Copy_Type
(Etype
(Actual
))
4960 or else Is_VM_By_Copy_Actual
(Actual
))
4961 and then Ekind
(Formal
) /= E_In_Parameter
4964 Make_Assignment_Statement
(Loc
,
4965 Name
=> New_Copy
(Actual
),
4967 Make_Explicit_Dereference
(Loc
,
4968 Make_Selected_Component
(Loc
,
4969 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4971 Make_Identifier
(Loc
, Chars
(Formal
)))));
4973 -- In all cases (including limited private types) we want
4974 -- the assignment to be valid.
4976 Set_Assignment_OK
(Name
(N_Node
));
4978 -- If the call is the triggering alternative in an
4979 -- asynchronous select, or the entry_call alternative of a
4980 -- conditional entry call, the assignments for in-out
4981 -- parameters are incorporated into the statement list that
4982 -- follows, so that there are executed only if the entry
4985 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4986 and then N
= Triggering_Statement
(Parent
(N
)))
4988 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4989 and then N
= Entry_Call_Statement
(Parent
(N
)))
4991 if No
(Statements
(Parent
(N
))) then
4992 Set_Statements
(Parent
(N
), New_List
);
4995 Prepend
(N_Node
, Statements
(Parent
(N
)));
4998 Insert_After
(Call
, N_Node
);
5002 Next_Actual
(Actual
);
5003 Next_Formal_With_Extras
(Formal
);
5007 -- Finally, create block and analyze it
5010 Make_Block_Statement
(Loc
,
5011 Declarations
=> Decls
,
5012 Handled_Statement_Sequence
=>
5013 Make_Handled_Sequence_Of_Statements
(Loc
,
5014 Statements
=> Stats
)));
5018 end Build_Simple_Entry_Call
;
5020 --------------------------------
5021 -- Build_Task_Activation_Call --
5022 --------------------------------
5024 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
5025 Loc
: constant Source_Ptr
:= Sloc
(N
);
5032 -- For sequential elaboration policy, all the tasks will be activated at
5033 -- the end of the elaboration.
5035 if Partition_Elaboration_Policy
= 'S' then
5039 -- Get the activation chain entity. Except in the case of a package
5040 -- body, this is in the node that was passed. For a package body, we
5041 -- have to find the corresponding package declaration node.
5043 if Nkind
(N
) = N_Package_Body
then
5044 P
:= Corresponding_Spec
(N
);
5047 exit when Nkind
(P
) = N_Package_Declaration
;
5050 Chain
:= Activation_Chain_Entity
(P
);
5053 Chain
:= Activation_Chain_Entity
(N
);
5056 if Present
(Chain
) then
5057 if Restricted_Profile
then
5058 Name
:= New_Occurrence_Of
5059 (RTE
(RE_Activate_Restricted_Tasks
), Loc
);
5061 Name
:= New_Occurrence_Of
5062 (RTE
(RE_Activate_Tasks
), Loc
);
5066 Make_Procedure_Call_Statement
(Loc
,
5068 Parameter_Associations
=>
5069 New_List
(Make_Attribute_Reference
(Loc
,
5070 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5071 Attribute_Name
=> Name_Unchecked_Access
)));
5073 if Nkind
(N
) = N_Package_Declaration
then
5074 if Present
(Corresponding_Body
(N
)) then
5077 elsif Present
(Private_Declarations
(Specification
(N
))) then
5078 Append
(Call
, Private_Declarations
(Specification
(N
)));
5081 Append
(Call
, Visible_Declarations
(Specification
(N
)));
5085 if Present
(Handled_Statement_Sequence
(N
)) then
5087 -- The call goes at the start of the statement sequence after
5088 -- the start of exception range label if one is present.
5094 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
5096 -- A special case, skip exception range label if one is
5097 -- present (from front end zcx processing).
5099 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
5103 -- Another special case, if the first statement is a block
5104 -- from optimization of a local raise to a goto, then the
5105 -- call goes inside this block.
5107 if Nkind
(Stm
) = N_Block_Statement
5108 and then Exception_Junk
(Stm
)
5111 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
5114 -- Insertion point is after any exception label pushes,
5115 -- since we want it covered by any local handlers.
5117 while Nkind
(Stm
) in N_Push_xxx_Label
loop
5121 -- Now we have the proper insertion point
5123 Insert_Before
(Stm
, Call
);
5127 Set_Handled_Statement_Sequence
(N
,
5128 Make_Handled_Sequence_Of_Statements
(Loc
,
5129 Statements
=> New_List
(Call
)));
5134 Check_Task_Activation
(N
);
5136 end Build_Task_Activation_Call
;
5138 -------------------------------
5139 -- Build_Task_Allocate_Block --
5140 -------------------------------
5142 procedure Build_Task_Allocate_Block
5147 T
: constant Entity_Id
:= Entity
(Expression
(N
));
5148 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
5149 Loc
: constant Source_Ptr
:= Sloc
(N
);
5150 Chain
: constant Entity_Id
:=
5151 Make_Defining_Identifier
(Loc
, Name_uChain
);
5152 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5157 Make_Block_Statement
(Loc
,
5158 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
5159 Declarations
=> New_List
(
5161 -- _Chain : Activation_Chain;
5163 Make_Object_Declaration
(Loc
,
5164 Defining_Identifier
=> Chain
,
5165 Aliased_Present
=> True,
5166 Object_Definition
=>
5167 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
5169 Handled_Statement_Sequence
=>
5170 Make_Handled_Sequence_Of_Statements
(Loc
,
5172 Statements
=> New_List
(
5176 Make_Procedure_Call_Statement
(Loc
,
5177 Name
=> New_Occurrence_Of
(Init
, Loc
),
5178 Parameter_Associations
=> Args
),
5180 -- Activate_Tasks (_Chain);
5182 Make_Procedure_Call_Statement
(Loc
,
5183 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
5184 Parameter_Associations
=> New_List
(
5185 Make_Attribute_Reference
(Loc
,
5186 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5187 Attribute_Name
=> Name_Unchecked_Access
))))),
5189 Has_Created_Identifier
=> True,
5190 Is_Task_Allocation_Block
=> True);
5193 Make_Implicit_Label_Declaration
(Loc
,
5194 Defining_Identifier
=> Blkent
,
5195 Label_Construct
=> Block
));
5197 Append_To
(Actions
, Block
);
5199 Set_Activation_Chain_Entity
(Block
, Chain
);
5200 end Build_Task_Allocate_Block
;
5202 -----------------------------------------------
5203 -- Build_Task_Allocate_Block_With_Init_Stmts --
5204 -----------------------------------------------
5206 procedure Build_Task_Allocate_Block_With_Init_Stmts
5209 Init_Stmts
: List_Id
)
5211 Loc
: constant Source_Ptr
:= Sloc
(N
);
5212 Chain
: constant Entity_Id
:=
5213 Make_Defining_Identifier
(Loc
, Name_uChain
);
5214 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5218 Append_To
(Init_Stmts
,
5219 Make_Procedure_Call_Statement
(Loc
,
5220 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
5221 Parameter_Associations
=> New_List
(
5222 Make_Attribute_Reference
(Loc
,
5223 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
5224 Attribute_Name
=> Name_Unchecked_Access
))));
5227 Make_Block_Statement
(Loc
,
5228 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
5229 Declarations
=> New_List
(
5231 -- _Chain : Activation_Chain;
5233 Make_Object_Declaration
(Loc
,
5234 Defining_Identifier
=> Chain
,
5235 Aliased_Present
=> True,
5236 Object_Definition
=>
5237 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
5239 Handled_Statement_Sequence
=>
5240 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5242 Has_Created_Identifier
=> True,
5243 Is_Task_Allocation_Block
=> True);
5246 Make_Implicit_Label_Declaration
(Loc
,
5247 Defining_Identifier
=> Blkent
,
5248 Label_Construct
=> Block
));
5250 Append_To
(Actions
, Block
);
5252 Set_Activation_Chain_Entity
(Block
, Chain
);
5253 end Build_Task_Allocate_Block_With_Init_Stmts
;
5255 -----------------------------------
5256 -- Build_Task_Proc_Specification --
5257 -----------------------------------
5259 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5260 Loc
: constant Source_Ptr
:= Sloc
(T
);
5261 Spec_Id
: Entity_Id
;
5264 -- Case of explicit task type, suffix TB
5266 if Comes_From_Source
(T
) then
5268 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
5270 -- Case of anonymous task type, suffix B
5274 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
5277 Set_Is_Internal
(Spec_Id
);
5279 -- Associate the procedure with the task, if this is the declaration
5280 -- (and not the body) of the procedure.
5282 if No
(Task_Body_Procedure
(T
)) then
5283 Set_Task_Body_Procedure
(T
, Spec_Id
);
5287 Make_Procedure_Specification
(Loc
,
5288 Defining_Unit_Name
=> Spec_Id
,
5289 Parameter_Specifications
=> New_List
(
5290 Make_Parameter_Specification
(Loc
,
5291 Defining_Identifier
=>
5292 Make_Defining_Identifier
(Loc
, Name_uTask
),
5294 Make_Access_Definition
(Loc
,
5296 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
5297 end Build_Task_Proc_Specification
;
5299 ---------------------------------------
5300 -- Build_Unprotected_Subprogram_Body --
5301 ---------------------------------------
5303 function Build_Unprotected_Subprogram_Body
5305 Pid
: Node_Id
) return Node_Id
5307 Decls
: constant List_Id
:= Declarations
(N
);
5310 -- Add renamings for the Protection object, discriminals, privals and
5311 -- the entry index constant for use by debugger.
5313 Debug_Private_Data_Declarations
(Decls
);
5315 -- Make an unprotected version of the subprogram for use within the same
5316 -- object, with a new name and an additional parameter representing the
5320 Make_Subprogram_Body
(Sloc
(N
),
5322 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5323 Declarations
=> Decls
,
5324 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5325 end Build_Unprotected_Subprogram_Body
;
5327 ----------------------------
5328 -- Collect_Entry_Families --
5329 ----------------------------
5331 procedure Collect_Entry_Families
5334 Current_Node
: in out Node_Id
;
5335 Conctyp
: Entity_Id
)
5338 Efam_Decl
: Node_Id
;
5339 Efam_Type
: Entity_Id
;
5342 Efam
:= First_Entity
(Conctyp
);
5343 while Present
(Efam
) loop
5344 if Ekind
(Efam
) = E_Entry_Family
then
5345 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5350 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5352 Bas_Decl
: Node_Id
:= Empty
;
5357 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5359 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5360 Bas
:= Make_Temporary
(Loc
, 'B');
5363 Make_Subtype_Declaration
(Loc
,
5364 Defining_Identifier
=> Bas
,
5365 Subtype_Indication
=>
5366 Make_Subtype_Indication
(Loc
,
5368 New_Occurrence_Of
(Standard_Integer
, Loc
),
5370 Make_Range_Constraint
(Loc
,
5371 Range_Expression
=> Make_Range
(Loc
,
5372 Make_Integer_Literal
5373 (Loc
, -Entry_Family_Bound
),
5374 Make_Integer_Literal
5375 (Loc
, Entry_Family_Bound
- 1)))));
5377 Insert_After
(Current_Node
, Bas_Decl
);
5378 Current_Node
:= Bas_Decl
;
5383 Make_Full_Type_Declaration
(Loc
,
5384 Defining_Identifier
=> Efam_Type
,
5386 Make_Unconstrained_Array_Definition
(Loc
,
5388 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5390 Component_Definition
=>
5391 Make_Component_Definition
(Loc
,
5392 Aliased_Present
=> False,
5393 Subtype_Indication
=>
5394 New_Occurrence_Of
(Standard_Character
, Loc
))));
5397 Insert_After
(Current_Node
, Efam_Decl
);
5398 Current_Node
:= Efam_Decl
;
5399 Analyze
(Efam_Decl
);
5402 Make_Component_Declaration
(Loc
,
5403 Defining_Identifier
=>
5404 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5406 Component_Definition
=>
5407 Make_Component_Definition
(Loc
,
5408 Aliased_Present
=> False,
5409 Subtype_Indication
=>
5410 Make_Subtype_Indication
(Loc
,
5412 New_Occurrence_Of
(Efam_Type
, Loc
),
5415 Make_Index_Or_Discriminant_Constraint
(Loc
,
5416 Constraints
=> New_List
(
5418 (Etype
(Discrete_Subtype_Definition
5419 (Parent
(Efam
))), Loc
)))))));
5425 end Collect_Entry_Families
;
5427 -----------------------
5428 -- Concurrent_Object --
5429 -----------------------
5431 function Concurrent_Object
5432 (Spec_Id
: Entity_Id
;
5433 Conc_Typ
: Entity_Id
) return Entity_Id
5436 -- Parameter _O or _object
5438 if Is_Protected_Type
(Conc_Typ
) then
5439 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5444 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5445 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5447 end Concurrent_Object
;
5449 ----------------------
5450 -- Copy_Result_Type --
5451 ----------------------
5453 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5454 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5459 -- If the result type is an access_to_subprogram, we must create new
5460 -- entities for its spec.
5462 if Nkind
(New_Res
) = N_Access_Definition
5463 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5465 -- Provide new entities for the formals
5467 Par_Spec
:= First
(Parameter_Specifications
5468 (Access_To_Subprogram_Definition
(New_Res
)));
5469 while Present
(Par_Spec
) loop
5470 Formal
:= Defining_Identifier
(Par_Spec
);
5471 Set_Defining_Identifier
(Par_Spec
,
5472 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5478 end Copy_Result_Type
;
5480 --------------------
5481 -- Concurrent_Ref --
5482 --------------------
5484 -- The expression returned for a reference to a concurrent object has the
5487 -- taskV!(name)._Task_Id
5491 -- objectV!(name)._Object
5493 -- for a protected object. For the case of an access to a concurrent
5494 -- object, there is an extra explicit dereference:
5496 -- taskV!(name.all)._Task_Id
5497 -- objectV!(name.all)._Object
5499 -- here taskV and objectV are the types for the associated records, which
5500 -- contain the required _Task_Id and _Object fields for tasks and protected
5501 -- objects, respectively.
5503 -- For the case of a task type name, the expression is
5507 -- i.e. a call to the Self function which returns precisely this Task_Id
5509 -- For the case of a protected type name, the expression is
5513 -- which is a renaming of the _object field of the current object
5514 -- record, passed into protected operations as a parameter.
5516 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5517 Loc
: constant Source_Ptr
:= Sloc
(N
);
5518 Ntyp
: constant Entity_Id
:= Etype
(N
);
5522 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5523 -- Check whether the reference is to the immediately enclosing task
5524 -- type, or to an outer one (rare but legal).
5526 ---------------------
5527 -- Is_Current_Task --
5528 ---------------------
5530 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5534 Scop
:= Current_Scope
;
5535 while Present
(Scop
)
5536 and then Scop
/= Standard_Standard
5542 elsif Is_Task_Type
(Scop
) then
5545 -- If this is a procedure nested within the task type, we must
5546 -- assume that it can be called from an inner task, and therefore
5547 -- cannot treat it as a local reference.
5549 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5553 Scop
:= Scope
(Scop
);
5557 -- We know that we are within the task body, so should have found it
5560 raise Program_Error
;
5561 end Is_Current_Task
;
5563 -- Start of processing for Concurrent_Ref
5566 if Is_Access_Type
(Ntyp
) then
5567 Dtyp
:= Designated_Type
(Ntyp
);
5569 if Is_Protected_Type
(Dtyp
) then
5570 Sel
:= Name_uObject
;
5572 Sel
:= Name_uTask_Id
;
5576 Make_Selected_Component
(Loc
,
5578 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5579 Make_Explicit_Dereference
(Loc
, N
)),
5580 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5582 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5583 if Is_Task_Type
(Entity
(N
)) then
5585 if Is_Current_Task
(Entity
(N
)) then
5587 Make_Function_Call
(Loc
,
5588 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5593 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5594 T_Body
: constant Node_Id
:=
5595 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5599 Make_Object_Declaration
(Loc
,
5600 Defining_Identifier
=> T_Self
,
5601 Object_Definition
=>
5602 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5604 Make_Function_Call
(Loc
,
5605 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5606 Prepend
(Decl
, Declarations
(T_Body
));
5608 Set_Scope
(T_Self
, Entity
(N
));
5609 return New_Occurrence_Of
(T_Self
, Loc
);
5614 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5617 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5621 if Is_Protected_Type
(Ntyp
) then
5622 Sel
:= Name_uObject
;
5624 elsif Is_Task_Type
(Ntyp
) then
5625 Sel
:= Name_uTask_Id
;
5628 raise Program_Error
;
5632 Make_Selected_Component
(Loc
,
5634 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5636 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5640 ------------------------
5641 -- Convert_Concurrent --
5642 ------------------------
5644 function Convert_Concurrent
5646 Typ
: Entity_Id
) return Node_Id
5649 if not Is_Concurrent_Type
(Typ
) then
5653 Unchecked_Convert_To
5654 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5656 end Convert_Concurrent
;
5658 -------------------------------------
5659 -- Debug_Private_Data_Declarations --
5660 -------------------------------------
5662 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5663 Debug_Nod
: Node_Id
;
5667 Decl
:= First
(Decls
);
5668 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5669 -- Declaration for concurrent entity _object and its access type,
5670 -- along with the entry index subtype:
5671 -- type prot_typVP is access prot_typV;
5672 -- _object : prot_typVP := prot_typV (_O);
5673 -- subtype Jnn is <Type of Index> range Low .. High;
5675 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5676 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5678 -- Declaration for the Protection object, discriminals, privals and
5679 -- entry index constant:
5680 -- conc_typR : protection_typ renames _object._object;
5681 -- discr_nameD : discr_typ renames _object.discr_name;
5682 -- discr_nameD : discr_typ renames _task.discr_name;
5683 -- prival_name : comp_typ renames _object.comp_name;
5684 -- J : constant Jnn :=
5685 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5687 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5688 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5689 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5691 if Present
(Debug_Nod
) then
5692 Insert_After
(Decl
, Debug_Nod
);
5698 end Debug_Private_Data_Declarations
;
5700 ------------------------------
5701 -- Ensure_Statement_Present --
5702 ------------------------------
5704 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5708 if Opt
.Suppress_Control_Flow_Optimizations
5709 and then Is_Empty_List
(Statements
(Alt
))
5711 Stmt
:= Make_Null_Statement
(Loc
);
5713 -- Mark NULL statement as coming from source so that it is not
5714 -- eliminated by GIGI.
5716 -- Another covert channel. If this is a requirement, it must be
5717 -- documented in sinfo/einfo ???
5719 Set_Comes_From_Source
(Stmt
, True);
5721 Set_Statements
(Alt
, New_List
(Stmt
));
5723 end Ensure_Statement_Present
;
5725 ----------------------------
5726 -- Entry_Index_Expression --
5727 ----------------------------
5729 function Entry_Index_Expression
5733 Ttyp
: Entity_Id
) return Node_Id
5743 -- The queues of entries and entry families appear in textual order in
5744 -- the associated record. The entry index is computed as the sum of the
5745 -- number of queues for all entries that precede the designated one, to
5746 -- which is added the index expression, if this expression denotes a
5747 -- member of a family.
5749 -- The following is a place holder for the count of simple entries
5751 Num
:= Make_Integer_Literal
(Sloc
, 1);
5753 -- We construct an expression which is a series of addition operations.
5754 -- The first operand is the number of single entries that precede this
5755 -- one, the second operand is the index value relative to the start of
5756 -- the referenced family, and the remaining operands are the lengths of
5757 -- the entry families that precede this entry, i.e. the constructed
5760 -- number_simple_entries +
5761 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5762 -- family'length + ...
5764 -- where index-value is the given index value, and s is the index
5765 -- subtype (we have to use pos because the subtype might be an
5766 -- enumeration type preventing direct subtraction). Note that the task
5767 -- entry array is one-indexed.
5769 -- The upper bound of the entry family may be a discriminant, so we
5770 -- retrieve the lower bound explicitly to compute offset, rather than
5771 -- using the index subtype which may mention a discriminant.
5773 if Present
(Index
) then
5774 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5783 Make_Attribute_Reference
(Sloc
,
5784 Attribute_Name
=> Name_Pos
,
5785 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5786 Expressions
=> New_List
(Relocate_Node
(Index
))),
5794 -- Now add lengths of preceding entries and entry families
5796 Prev
:= First_Entity
(Ttyp
);
5798 while Chars
(Prev
) /= Chars
(Ent
)
5799 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5800 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5802 if Ekind
(Prev
) = E_Entry
then
5803 Set_Intval
(Num
, Intval
(Num
) + 1);
5805 elsif Ekind
(Prev
) = E_Entry_Family
then
5807 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5808 Lo
:= Type_Low_Bound
(S
);
5809 Hi
:= Type_High_Bound
(S
);
5814 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5816 -- Other components are anonymous types to be ignored
5826 end Entry_Index_Expression
;
5828 ---------------------------
5829 -- Establish_Task_Master --
5830 ---------------------------
5832 procedure Establish_Task_Master
(N
: Node_Id
) is
5836 if Restriction_Active
(No_Task_Hierarchy
) = False then
5837 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5839 -- The block may have no declarations (and nevertheless be a task
5840 -- master) if it contains a call that may return an object that
5843 if No
(Declarations
(N
)) then
5844 Set_Declarations
(N
, New_List
(Call
));
5846 Prepend_To
(Declarations
(N
), Call
);
5851 end Establish_Task_Master
;
5853 --------------------------------
5854 -- Expand_Accept_Declarations --
5855 --------------------------------
5857 -- Part of the expansion of an accept statement involves the creation of
5858 -- a declaration that can be referenced from the statement sequence of
5863 -- This declaration is inserted immediately before the accept statement
5864 -- and it is important that it be inserted before the statements of the
5865 -- statement sequence are analyzed. Thus it would be too late to create
5866 -- this declaration in the Expand_N_Accept_Statement routine, which is
5867 -- why there is a separate procedure to be called directly from Sem_Ch9.
5869 -- Ann is used to hold the address of the record containing the parameters
5870 -- (see Expand_N_Entry_Call for more details on how this record is built).
5871 -- References to the parameters do an unchecked conversion of this address
5872 -- to a pointer to the required record type, and then access the field that
5873 -- holds the value of the required parameter. The entity for the address
5874 -- variable is held as the top stack element (i.e. the last element) of the
5875 -- Accept_Address stack in the corresponding entry entity, and this element
5876 -- must be set in place before the statements are processed.
5878 -- The above description applies to the case of a stand alone accept
5879 -- statement, i.e. one not appearing as part of a select alternative.
5881 -- For the case of an accept that appears as part of a select alternative
5882 -- of a selective accept, we must still create the declaration right away,
5883 -- since Ann is needed immediately, but there is an important difference:
5885 -- The declaration is inserted before the selective accept, not before
5886 -- the accept statement (which is not part of a list anyway, and so would
5887 -- not accommodate inserted declarations)
5889 -- We only need one address variable for the entire selective accept. So
5890 -- the Ann declaration is created only for the first accept alternative,
5891 -- and subsequent accept alternatives reference the same Ann variable.
5893 -- We can distinguish the two cases by seeing whether the accept statement
5894 -- is part of a list. If not, then it must be in an accept alternative.
5896 -- To expand the requeue statement, a label is provided at the end of the
5897 -- accept statement or alternative of which it is a part, so that the
5898 -- statement can be skipped after the requeue is complete. This label is
5899 -- created here rather than during the expansion of the accept statement,
5900 -- because it will be needed by any requeue statements within the accept,
5901 -- which are expanded before the accept.
5903 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5904 Loc
: constant Source_Ptr
:= Sloc
(N
);
5905 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5906 Ann
: Entity_Id
:= Empty
;
5913 if Expander_Active
then
5915 -- If we have no handled statement sequence, we may need to build
5916 -- a dummy sequence consisting of a null statement. This can be
5917 -- skipped if the trivial accept optimization is permitted.
5919 if not Trivial_Accept_OK
5921 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5923 Set_Handled_Statement_Sequence
(N
,
5924 Make_Handled_Sequence_Of_Statements
(Loc
,
5925 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5928 -- Create and declare two labels to be placed at the end of the
5929 -- accept statement. The first label is used to allow requeues to
5930 -- skip the remainder of entry processing. The second label is used
5931 -- to skip the remainder of entry processing if the rendezvous
5932 -- completes in the middle of the accept body.
5934 if Present
(Handled_Statement_Sequence
(N
)) then
5939 Ent
:= Make_Temporary
(Loc
, 'L');
5940 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5942 Make_Implicit_Label_Declaration
(Loc
,
5943 Defining_Identifier
=> Ent
,
5944 Label_Construct
=> Lab
);
5945 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5947 Ent
:= Make_Temporary
(Loc
, 'L');
5948 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5950 Make_Implicit_Label_Declaration
(Loc
,
5951 Defining_Identifier
=> Ent
,
5952 Label_Construct
=> Lab
);
5953 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5961 -- Case of stand alone accept statement
5963 if Is_List_Member
(N
) then
5965 if Present
(Handled_Statement_Sequence
(N
)) then
5966 Ann
:= Make_Temporary
(Loc
, 'A');
5969 Make_Object_Declaration
(Loc
,
5970 Defining_Identifier
=> Ann
,
5971 Object_Definition
=>
5972 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5974 Insert_Before_And_Analyze
(N
, Adecl
);
5975 Insert_Before_And_Analyze
(N
, Ldecl
);
5976 Insert_Before_And_Analyze
(N
, Ldecl2
);
5979 -- Case of accept statement which is in an accept alternative
5983 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5984 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5988 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5989 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5991 -- ??? Consider a single label for select statements
5993 if Present
(Handled_Statement_Sequence
(N
)) then
5995 Statements
(Handled_Statement_Sequence
(N
)));
5999 Statements
(Handled_Statement_Sequence
(N
)));
6003 -- Find first accept alternative of the selective accept. A
6004 -- valid selective accept must have at least one accept in it.
6006 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
6008 while Nkind
(Alt
) /= N_Accept_Alternative
loop
6012 -- If this is the first accept statement, then we have to
6013 -- create the Ann variable, as for the stand alone case, except
6014 -- that it is inserted before the selective accept. Similarly,
6015 -- a label for requeue expansion must be declared.
6017 if N
= Accept_Statement
(Alt
) then
6018 Ann
:= Make_Temporary
(Loc
, 'A');
6020 Make_Object_Declaration
(Loc
,
6021 Defining_Identifier
=> Ann
,
6022 Object_Definition
=>
6023 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
6025 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
6027 -- If this is not the first accept statement, then find the Ann
6028 -- variable allocated by the first accept and use it.
6032 Node
(Last_Elmt
(Accept_Address
6033 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
6038 -- Merge here with Ann either created or referenced, and Adecl
6039 -- pointing to the corresponding declaration. Remaining processing
6040 -- is the same for the two cases.
6042 if Present
(Ann
) then
6043 Append_Elmt
(Ann
, Accept_Address
(Ent
));
6044 Set_Debug_Info_Needed
(Ann
);
6047 -- Create renaming declarations for the entry formals. Each reference
6048 -- to a formal becomes a dereference of a component of the parameter
6049 -- block, whose address is held in Ann. These declarations are
6050 -- eventually inserted into the accept block, and analyzed there so
6051 -- that they have the proper scope for gdb and do not conflict with
6052 -- other declarations.
6054 if Present
(Parameter_Specifications
(N
))
6055 and then Present
(Handled_Statement_Sequence
(N
))
6062 Renamed_Formal
: Node_Id
;
6066 Formal
:= First_Formal
(Ent
);
6068 while Present
(Formal
) loop
6069 Comp
:= Entry_Component
(Formal
);
6070 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
6072 Set_Etype
(New_F
, Etype
(Formal
));
6073 Set_Scope
(New_F
, Ent
);
6075 -- Now we set debug info needed on New_F even though it does
6076 -- not come from source, so that the debugger will get the
6077 -- right information for these generated names.
6079 Set_Debug_Info_Needed
(New_F
);
6081 if Ekind
(Formal
) = E_In_Parameter
then
6082 Set_Ekind
(New_F
, E_Constant
);
6084 Set_Ekind
(New_F
, E_Variable
);
6085 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
6088 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
6091 Make_Selected_Component
(Loc
,
6093 Unchecked_Convert_To
(
6094 Entry_Parameters_Type
(Ent
),
6095 New_Occurrence_Of
(Ann
, Loc
)),
6097 New_Occurrence_Of
(Comp
, Loc
));
6100 Build_Renamed_Formal_Declaration
6101 (New_F
, Formal
, Comp
, Renamed_Formal
);
6103 if No
(Declarations
(N
)) then
6104 Set_Declarations
(N
, New_List
);
6107 Append
(Decl
, Declarations
(N
));
6108 Set_Renamed_Object
(Formal
, New_F
);
6109 Next_Formal
(Formal
);
6116 end Expand_Accept_Declarations
;
6118 ---------------------------------------------
6119 -- Expand_Access_Protected_Subprogram_Type --
6120 ---------------------------------------------
6122 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
6123 Loc
: constant Source_Ptr
:= Sloc
(N
);
6125 T
: constant Entity_Id
:= Defining_Identifier
(N
);
6126 D_T
: constant Entity_Id
:= Designated_Type
(T
);
6127 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
6128 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
6129 P_List
: constant List_Id
:= Build_Protected_Spec
6130 (N
, RTE
(RE_Address
), D_T
, False);
6136 -- Create access to subprogram with full signature
6138 if Etype
(D_T
) /= Standard_Void_Type
then
6140 Make_Access_Function_Definition
(Loc
,
6141 Parameter_Specifications
=> P_List
,
6142 Result_Definition
=>
6143 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
6147 Make_Access_Procedure_Definition
(Loc
,
6148 Parameter_Specifications
=> P_List
);
6152 Make_Full_Type_Declaration
(Loc
,
6153 Defining_Identifier
=> D_T2
,
6154 Type_Definition
=> Def1
);
6156 Insert_After_And_Analyze
(N
, Decl1
);
6158 -- Associate the access to subprogram with its original access to
6159 -- protected subprogram type. Needed by the backend to know that this
6160 -- type corresponds with an access to protected subprogram type.
6162 Set_Original_Access_Type
(D_T2
, T
);
6164 -- Create Equivalent_Type, a record with two components for an access to
6165 -- object and an access to subprogram.
6168 Make_Component_Declaration
(Loc
,
6169 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6170 Component_Definition
=>
6171 Make_Component_Definition
(Loc
,
6172 Aliased_Present
=> False,
6173 Subtype_Indication
=>
6174 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
6176 Make_Component_Declaration
(Loc
,
6177 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
6178 Component_Definition
=>
6179 Make_Component_Definition
(Loc
,
6180 Aliased_Present
=> False,
6181 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
6184 Make_Full_Type_Declaration
(Loc
,
6185 Defining_Identifier
=> E_T
,
6187 Make_Record_Definition
(Loc
,
6189 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
6191 Insert_After_And_Analyze
(Decl1
, Decl2
);
6192 Set_Equivalent_Type
(T
, E_T
);
6193 end Expand_Access_Protected_Subprogram_Type
;
6195 --------------------------
6196 -- Expand_Entry_Barrier --
6197 --------------------------
6199 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
6200 Cond
: constant Node_Id
:=
6201 Condition
(Entry_Body_Formal_Part
(N
));
6202 Prot
: constant Entity_Id
:= Scope
(Ent
);
6203 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
6206 Body_Decl
: Node_Id
;
6208 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
6209 -- Check whether entity in Barrier is external to protected type.
6210 -- If so, barrier may not be properly synchronized.
6212 ----------------------
6213 -- Is_Global_Entity --
6214 ----------------------
6216 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
6221 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
6225 if Ekind
(E
) = E_Variable
then
6226 if Scope
(E
) = Func
then
6229 -- A protected call from a barrier to another object is ok
6231 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
6234 -- If the variable is within the package body we consider
6235 -- this safe. This is a common (if dubious) idiom.
6237 elsif S
= Scope
(Prot
)
6238 and then Ekind_In
(S
, E_Package
, E_Generic_Package
)
6239 and then Nkind
(Parent
(E
)) = N_Object_Declaration
6240 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
6245 Error_Msg_N
("potentially unsynchronized barrier??", N
);
6246 Error_Msg_N
("\& should be private component of type??", N
);
6252 end Is_Global_Entity
;
6254 procedure Check_Unprotected_Barrier
is
6255 new Traverse_Proc
(Is_Global_Entity
);
6257 -- Start of processing for Expand_Entry_Barrier
6260 if No_Run_Time_Mode
then
6261 Error_Msg_CRT
("entry barrier", N
);
6265 -- The body of the entry barrier must be analyzed in the context of the
6266 -- protected object, but its scope is external to it, just as any other
6267 -- unprotected version of a protected operation. The specification has
6268 -- been produced when the protected type declaration was elaborated. We
6269 -- build the body, insert it in the enclosing scope, but analyze it in
6270 -- the current context. A more uniform approach would be to treat the
6271 -- barrier just as a protected function, and discard the protected
6272 -- version of it because it is never called.
6274 if Expander_Active
then
6275 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6276 Func
:= Barrier_Function
(Ent
);
6277 Set_Corresponding_Spec
(B_F
, Func
);
6279 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
6281 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
6282 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
6285 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
6287 Set_Discriminals
(Spec_Decl
);
6288 Set_Scope
(Func
, Scope
(Prot
));
6291 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6294 -- The Ravenscar profile restricts barriers to simple variables declared
6295 -- within the protected object. We also allow Boolean constants, since
6296 -- these appear in several published examples and are also allowed by
6299 -- Note that after analysis variables in this context will be replaced
6300 -- by the corresponding prival, that is to say a renaming of a selected
6301 -- component of the form _Object.Var. If expansion is disabled, as
6302 -- within a generic, we check that the entity appears in the current
6305 if Is_Entity_Name
(Cond
) then
6307 -- A small optimization of useless renamings. If the scope of the
6308 -- entity of the condition is not the barrier function, then the
6309 -- condition does not reference any of the generated renamings
6310 -- within the function.
6312 if Expander_Active
and then Scope
(Entity
(Cond
)) /= Func
then
6313 Set_Declarations
(B_F
, Empty_List
);
6316 if Entity
(Cond
) = Standard_False
6318 Entity
(Cond
) = Standard_True
6322 elsif not Expander_Active
6323 and then Scope
(Entity
(Cond
)) = Current_Scope
6327 -- Check for case of _object.all.field (note that the explicit
6328 -- dereference gets inserted by analyze/expand of _object.field)
6330 elsif Present
(Renamed_Object
(Entity
(Cond
)))
6332 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
6336 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
6342 -- It is not a boolean variable or literal, so check the restriction.
6343 -- Note that it is safe to be calling Check_Restriction from here, even
6344 -- though this is part of the expander, since Expand_Entry_Barrier is
6345 -- called from Sem_Ch9 even in -gnatc mode.
6347 Check_Restriction
(Simple_Barriers
, Cond
);
6349 -- Emit warning if barrier contains global entities and is thus
6350 -- potentially unsynchronized.
6352 Check_Unprotected_Barrier
(Cond
);
6353 end Expand_Entry_Barrier
;
6355 ------------------------------
6356 -- Expand_N_Abort_Statement --
6357 ------------------------------
6359 -- Expand abort T1, T2, .. Tn; into:
6360 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6362 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6363 Loc
: constant Source_Ptr
:= Sloc
(N
);
6364 Tlist
: constant List_Id
:= Names
(N
);
6370 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6373 Tasknm
:= First
(Tlist
);
6375 while Present
(Tasknm
) loop
6378 -- A task interface class-wide type object is being aborted. Retrieve
6379 -- its _task_id by calling a dispatching routine.
6381 if Ada_Version
>= Ada_2005
6382 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6383 and then Is_Interface
(Etype
(Tasknm
))
6384 and then Is_Task_Interface
(Etype
(Tasknm
))
6386 Append_To
(Component_Associations
(Aggr
),
6387 Make_Component_Association
(Loc
,
6388 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6391 -- Task_Id (Tasknm._disp_get_task_id)
6393 Make_Unchecked_Type_Conversion
(Loc
,
6395 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
6397 Make_Selected_Component
(Loc
,
6398 Prefix
=> New_Copy_Tree
(Tasknm
),
6400 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6403 Append_To
(Component_Associations
(Aggr
),
6404 Make_Component_Association
(Loc
,
6405 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6406 Expression
=> Concurrent_Ref
(Tasknm
)));
6413 Make_Procedure_Call_Statement
(Loc
,
6414 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6415 Parameter_Associations
=> New_List
(
6416 Make_Qualified_Expression
(Loc
,
6417 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6418 Expression
=> Aggr
))));
6421 end Expand_N_Abort_Statement
;
6423 -------------------------------
6424 -- Expand_N_Accept_Statement --
6425 -------------------------------
6427 -- This procedure handles expansion of accept statements that stand alone,
6428 -- i.e. they are not part of an accept alternative. The expansion of
6429 -- accept statement in accept alternatives is handled by the routines
6430 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6431 -- following description applies only to stand alone accept statements.
6433 -- If there is no handled statement sequence, or only null statements, then
6434 -- this is called a trivial accept, and the expansion is:
6436 -- Accept_Trivial (entry-index)
6438 -- If there is a handled statement sequence, then the expansion is:
6445 -- Accept_Call (entry-index, Ann);
6446 -- Renaming_Declarations for formals
6447 -- <statement sequence from N_Accept_Statement node>
6448 -- Complete_Rendezvous;
6453 -- <exception handler from N_Accept_Statement node>
6454 -- Complete_Rendezvous;
6456 -- <exception handler from N_Accept_Statement node>
6457 -- Complete_Rendezvous;
6462 -- when all others =>
6463 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6466 -- The first three declarations were already inserted ahead of the accept
6467 -- statement by the Expand_Accept_Declarations procedure, which was called
6468 -- directly from the semantics during analysis of the accept statement,
6469 -- before analyzing its contained statements.
6471 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6472 -- from possible expansion activity (the original source of course does
6473 -- not have any declarations associated with the accept statement, since
6474 -- an accept statement has no declarative part). In particular, if the
6475 -- expander is active, the first such declaration is the declaration of
6476 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6478 -- The two blocks are merged into a single block if the inner block has
6479 -- no exception handlers, but otherwise two blocks are required, since
6480 -- exceptions might be raised in the exception handlers of the inner
6481 -- block, and Exceptional_Complete_Rendezvous must be called.
6483 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6484 Loc
: constant Source_Ptr
:= Sloc
(N
);
6485 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6486 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6487 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6488 Eent
: constant Entity_Id
:= Entity
(Ename
);
6489 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6490 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6491 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6497 -- If the accept statement is not part of a list, then its parent must
6498 -- be an accept alternative, and, as described above, we do not do any
6499 -- expansion for such accept statements at this level.
6501 if not Is_List_Member
(N
) then
6502 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6505 -- Trivial accept case (no statement sequence, or null statements).
6506 -- If the accept statement has declarations, then just insert them
6507 -- before the procedure call.
6509 elsif Trivial_Accept_OK
6510 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6512 -- Remove declarations for renamings, because the parameter block
6513 -- will not be assigned.
6520 D
:= First
(Declarations
(N
));
6521 while Present
(D
) loop
6523 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6531 if Present
(Declarations
(N
)) then
6532 Insert_Actions
(N
, Declarations
(N
));
6536 Make_Procedure_Call_Statement
(Loc
,
6537 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6538 Parameter_Associations
=> New_List
(
6539 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6543 -- Discard Entry_Address that was created for it, so it will not be
6544 -- emitted if this accept statement is in the statement part of a
6545 -- delay alternative.
6547 if Present
(Stats
) then
6548 Remove_Last_Elmt
(Acstack
);
6551 -- Case of statement sequence present
6554 -- Construct the block, using the declarations from the accept
6555 -- statement if any to initialize the declarations of the block.
6557 Blkent
:= Make_Temporary
(Loc
, 'A');
6558 Set_Ekind
(Blkent
, E_Block
);
6559 Set_Etype
(Blkent
, Standard_Void_Type
);
6560 Set_Scope
(Blkent
, Current_Scope
);
6563 Make_Block_Statement
(Loc
,
6564 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6565 Declarations
=> Declarations
(N
),
6566 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6568 -- For the analysis of the generated declarations, the parent node
6569 -- must be properly set.
6571 Set_Parent
(Block
, Parent
(N
));
6573 -- Prepend call to Accept_Call to main statement sequence If the
6574 -- accept has exception handlers, the statement sequence is wrapped
6575 -- in a block. Insert call and renaming declarations in the
6576 -- declarations of the block, so they are elaborated before the
6580 Make_Procedure_Call_Statement
(Loc
,
6581 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6582 Parameter_Associations
=> New_List
(
6583 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6584 New_Occurrence_Of
(Ann
, Loc
)));
6586 if Parent
(Stats
) = N
then
6587 Prepend
(Call
, Statements
(Stats
));
6589 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6594 Push_Scope
(Blkent
);
6602 D
:= First
(Declarations
(N
));
6603 while Present
(D
) loop
6606 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6608 -- The renaming declarations for the formals were created
6609 -- during analysis of the accept statement, and attached to
6610 -- the list of declarations. Place them now in the context
6611 -- of the accept block or subprogram.
6614 Typ
:= Entity
(Subtype_Mark
(D
));
6615 Insert_After
(Call
, D
);
6618 -- If the formal is class_wide, it does not have an actual
6619 -- subtype. The analysis of the renaming declaration creates
6620 -- one, but we need to retain the class-wide nature of the
6623 if Is_Class_Wide_Type
(Typ
) then
6624 Set_Etype
(Defining_Identifier
(D
), Typ
);
6635 -- Replace the accept statement by the new block
6640 -- Last step is to unstack the Accept_Address value
6642 Remove_Last_Elmt
(Acstack
);
6644 end Expand_N_Accept_Statement
;
6646 ----------------------------------
6647 -- Expand_N_Asynchronous_Select --
6648 ----------------------------------
6650 -- This procedure assumes that the trigger statement is an entry call or
6651 -- a dispatching procedure call. A delay alternative should already have
6652 -- been expanded into an entry call to the appropriate delay object Wait
6655 -- If the trigger is a task entry call, the select is implemented with
6656 -- a Task_Entry_Call:
6661 -- P : parms := (parm, parm, parm);
6663 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6665 -- procedure _clean is
6668 -- Cancel_Task_Entry_Call (C);
6675 -- (<acceptor-task>, -- Acceptor
6676 -- <entry-index>, -- E
6677 -- P'Address, -- Uninterpreted_Data
6678 -- Asynchronous_Call, -- Mode
6679 -- B); -- Rendezvous_Successful
6686 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6689 -- when Abort_Signal => Abort_Undefer;
6696 -- <triggered-statements>
6700 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6701 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6705 -- P : parms := (parm, parm, parm);
6707 -- Call_Simple (acceptor-task, entry-index, P'Address);
6713 -- so the task at hand is to convert the latter expansion into the former
6715 -- If the trigger is a protected entry call, the select is implemented
6716 -- with Protected_Entry_Call:
6719 -- P : E1_Params := (param, param, param);
6720 -- Bnn : Communications_Block;
6725 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6727 -- procedure _clean is
6730 -- if Enqueued (Bnn) then
6731 -- Cancel_Protected_Entry_Call (Bnn);
6738 -- Protected_Entry_Call
6739 -- (po._object'Access, -- Object
6740 -- <entry index>, -- E
6741 -- P'Address, -- Uninterpreted_Data
6742 -- Asynchronous_Call, -- Mode
6745 -- if Enqueued (Bnn) then
6749 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6752 -- when Abort_Signal => Abort_Undefer;
6755 -- if not Cancelled (Bnn) then
6756 -- <triggered-statements>
6760 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6764 -- P : E1_Params := (param, param, param);
6765 -- Bnn : Communications_Block;
6768 -- Protected_Entry_Call
6769 -- (po._object'Access, -- Object
6770 -- <entry index>, -- E
6771 -- P'Address, -- Uninterpreted_Data
6772 -- Simple_Call, -- Mode
6779 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6783 -- B : Boolean := False;
6784 -- Bnn : Communication_Block;
6785 -- C : Ada.Tags.Prim_Op_Kind;
6786 -- D : System.Storage_Elements.Dummy_Communication_Block;
6787 -- K : Ada.Tags.Tagged_Kind :=
6788 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6789 -- P : Parameters := (Param1 .. ParamN);
6794 -- if K = Ada.Tags.TK_Limited_Tagged
6795 -- or else K = Ada.Tags.TK_Tagged
6797 -- <dispatching-call>;
6798 -- <triggering-statements>;
6802 -- Ada.Tags.Get_Offset_Index
6803 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6805 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6807 -- if C = POK_Protected_Entry then
6809 -- procedure _clean is
6811 -- if Enqueued (Bnn) then
6812 -- Cancel_Protected_Entry_Call (Bnn);
6818 -- _Disp_Asynchronous_Select
6819 -- (<object>, S, P'Address, D, B);
6820 -- Bnn := Communication_Block (D);
6822 -- Param1 := P.Param1;
6824 -- ParamN := P.ParamN;
6826 -- if Enqueued (Bnn) then
6827 -- <abortable-statements>
6830 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6833 -- when Abort_Signal => Abort_Undefer;
6836 -- if not Cancelled (Bnn) then
6837 -- <triggering-statements>
6840 -- elsif C = POK_Task_Entry then
6842 -- procedure _clean is
6844 -- Cancel_Task_Entry_Call (U);
6850 -- _Disp_Asynchronous_Select
6851 -- (<object>, S, P'Address, D, B);
6852 -- Bnn := Communication_Bloc (D);
6854 -- Param1 := P.Param1;
6856 -- ParamN := P.ParamN;
6861 -- <abortable-statements>
6863 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6866 -- when Abort_Signal => Abort_Undefer;
6870 -- <triggering-statements>
6875 -- <dispatching-call>;
6876 -- <triggering-statements>
6881 -- The job is to convert this to the asynchronous form
6883 -- If the trigger is a delay statement, it will have been expanded into
6884 -- a call to one of the GNARL delay procedures. This routine will convert
6885 -- this into a protected entry call on a delay object and then continue
6886 -- processing as for a protected entry call trigger. This requires
6887 -- declaring a Delay_Block object and adding a pointer to this object to
6888 -- the parameter list of the delay procedure to form the parameter list of
6889 -- the entry call. This object is used by the runtime to queue the delay
6892 -- For a description of the use of P and the assignments after the call,
6893 -- see Expand_N_Entry_Call_Statement.
6895 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6896 Loc
: constant Source_Ptr
:= Sloc
(N
);
6897 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6898 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6900 Abort_Block_Ent
: Entity_Id
;
6901 Abortable_Block
: Node_Id
;
6904 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6905 Blk_Typ
: Entity_Id
;
6907 Call_Ent
: Entity_Id
;
6908 Cancel_Param
: Entity_Id
;
6909 Cleanup_Block
: Node_Id
;
6910 Cleanup_Block_Ent
: Entity_Id
;
6911 Cleanup_Stmts
: List_Id
;
6912 Conc_Typ_Stmts
: List_Id
;
6914 Dblock_Ent
: Entity_Id
;
6919 Enqueue_Call
: Node_Id
;
6922 Handler_Stmt
: Node_Id
;
6924 Lim_Typ_Stmts
: List_Id
;
6930 ProtE_Stmts
: List_Id
;
6931 ProtP_Stmts
: List_Id
;
6934 TaskE_Stmts
: List_Id
;
6937 B
: Entity_Id
; -- Call status flag
6938 Bnn
: Entity_Id
; -- Communication block
6939 C
: Entity_Id
; -- Call kind
6940 K
: Entity_Id
; -- Tagged kind
6941 P
: Entity_Id
; -- Parameter block
6942 S
: Entity_Id
; -- Primitive operation slot
6943 T
: Entity_Id
; -- Additional status flag
6945 procedure Rewrite_Abortable_Part
;
6946 -- If the trigger is a dispatching call, the expansion inserts multiple
6947 -- copies of the abortable part. This is both inefficient, and may lead
6948 -- to duplicate definitions that the back-end will reject, when the
6949 -- abortable part includes loops. This procedure rewrites the abortable
6950 -- part into a call to a generated procedure.
6952 ----------------------------
6953 -- Rewrite_Abortable_Part --
6954 ----------------------------
6956 procedure Rewrite_Abortable_Part
is
6957 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6962 Make_Subprogram_Body
(Loc
,
6964 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6965 Declarations
=> New_List
,
6966 Handled_Statement_Sequence
=>
6967 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6968 Insert_Before
(N
, Decl
);
6971 -- Rewrite abortable part into a call to this procedure.
6975 Make_Procedure_Call_Statement
(Loc
,
6976 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6977 end Rewrite_Abortable_Part
;
6980 Process_Statements_For_Controlled_Objects
(Trig
);
6981 Process_Statements_For_Controlled_Objects
(Abrt
);
6983 Ecall
:= Triggering_Statement
(Trig
);
6985 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6987 -- Retrieve Astats and Tstats now because the finalization machinery may
6988 -- wrap them in blocks.
6990 Astats
:= Statements
(Abrt
);
6991 Tstats
:= Statements
(Trig
);
6993 -- The arguments in the call may require dynamic allocation, and the
6994 -- call statement may have been transformed into a block. The block
6995 -- may contain additional declarations for internal entities, and the
6996 -- original call is found by sequential search.
6998 if Nkind
(Ecall
) = N_Block_Statement
then
6999 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
7000 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
7001 N_Entry_Call_Statement
)
7007 -- This is either a dispatching call or a delay statement used as a
7008 -- trigger which was expanded into a procedure call.
7010 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
7011 if Ada_Version
>= Ada_2005
7013 (No
(Original_Node
(Ecall
))
7014 or else not Nkind_In
(Original_Node
(Ecall
),
7015 N_Delay_Relative_Statement
,
7016 N_Delay_Until_Statement
))
7018 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
7020 Rewrite_Abortable_Part
;
7024 -- Call status flag processing, generate:
7025 -- B : Boolean := False;
7027 B
:= Build_B
(Loc
, Decls
);
7029 -- Communication block processing, generate:
7030 -- Bnn : Communication_Block;
7032 Bnn
:= Make_Temporary
(Loc
, 'B');
7034 Make_Object_Declaration
(Loc
,
7035 Defining_Identifier
=> Bnn
,
7036 Object_Definition
=>
7037 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
7039 -- Call kind processing, generate:
7040 -- C : Ada.Tags.Prim_Op_Kind;
7042 C
:= Build_C
(Loc
, Decls
);
7044 -- Tagged kind processing, generate:
7045 -- K : Ada.Tags.Tagged_Kind :=
7046 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7048 -- Dummy communication block, generate:
7049 -- D : Dummy_Communication_Block;
7052 Make_Object_Declaration
(Loc
,
7053 Defining_Identifier
=>
7054 Make_Defining_Identifier
(Loc
, Name_uD
),
7055 Object_Definition
=>
7057 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
7059 K
:= Build_K
(Loc
, Decls
, Obj
);
7061 -- Parameter block processing
7063 Blk_Typ
:= Build_Parameter_Block
7064 (Loc
, Actuals
, Formals
, Decls
);
7065 P
:= Parameter_Block_Pack
7066 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7068 -- Dispatch table slot processing, generate:
7071 S
:= Build_S
(Loc
, Decls
);
7073 -- Additional status flag processing, generate:
7076 T
:= Make_Temporary
(Loc
, 'T');
7078 Make_Object_Declaration
(Loc
,
7079 Defining_Identifier
=> T
,
7080 Object_Definition
=>
7081 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7083 ------------------------------
7084 -- Protected entry handling --
7085 ------------------------------
7088 -- Param1 := P.Param1;
7090 -- ParamN := P.ParamN;
7092 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7095 -- Bnn := Communication_Block (D);
7097 Prepend_To
(Cleanup_Stmts
,
7098 Make_Assignment_Statement
(Loc
,
7099 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
7101 Make_Unchecked_Type_Conversion
(Loc
,
7103 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7104 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7107 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7109 Prepend_To
(Cleanup_Stmts
,
7110 Make_Procedure_Call_Statement
(Loc
,
7114 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
7116 Parameter_Associations
=>
7118 New_Copy_Tree
(Obj
), -- <object>
7119 New_Occurrence_Of
(S
, Loc
), -- S
7120 Make_Attribute_Reference
(Loc
, -- P'Address
7121 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7122 Attribute_Name
=> Name_Address
),
7123 Make_Identifier
(Loc
, Name_uD
), -- D
7124 New_Occurrence_Of
(B
, Loc
)))); -- B
7127 -- if Enqueued (Bnn) then
7128 -- <abortable-statements>
7131 Append_To
(Cleanup_Stmts
,
7132 Make_Implicit_If_Statement
(N
,
7134 Make_Function_Call
(Loc
,
7136 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7137 Parameter_Associations
=>
7138 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
7141 New_Copy_List_Tree
(Astats
)));
7143 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7144 -- will then generate a _clean for the communication block Bnn.
7148 -- procedure _clean is
7150 -- if Enqueued (Bnn) then
7151 -- Cancel_Protected_Entry_Call (Bnn);
7160 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7162 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7164 -- Wrap the cleanup block in an exception handling block
7170 -- when Abort_Signal => Abort_Undefer;
7173 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7176 Make_Implicit_Label_Declaration
(Loc
,
7177 Defining_Identifier
=> Abort_Block_Ent
),
7180 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7183 -- if not Cancelled (Bnn) then
7184 -- <triggering-statements>
7187 Append_To
(ProtE_Stmts
,
7188 Make_Implicit_If_Statement
(N
,
7192 Make_Function_Call
(Loc
,
7194 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7195 Parameter_Associations
=>
7196 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7199 New_Copy_List_Tree
(Tstats
)));
7201 -------------------------
7202 -- Task entry handling --
7203 -------------------------
7206 -- Param1 := P.Param1;
7208 -- ParamN := P.ParamN;
7210 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7213 -- Bnn := Communication_Block (D);
7215 Append_To
(TaskE_Stmts
,
7216 Make_Assignment_Statement
(Loc
,
7218 New_Occurrence_Of
(Bnn
, Loc
),
7220 Make_Unchecked_Type_Conversion
(Loc
,
7222 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
),
7223 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7226 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7228 Prepend_To
(TaskE_Stmts
,
7229 Make_Procedure_Call_Statement
(Loc
,
7232 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7233 Name_uDisp_Asynchronous_Select
),
7236 Parameter_Associations
=>
7238 New_Copy_Tree
(Obj
), -- <object>
7239 New_Occurrence_Of
(S
, Loc
), -- S
7240 Make_Attribute_Reference
(Loc
, -- P'Address
7241 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7242 Attribute_Name
=> Name_Address
),
7243 Make_Identifier
(Loc
, Name_uD
), -- D
7244 New_Occurrence_Of
(B
, Loc
)))); -- B
7249 Prepend_To
(TaskE_Stmts
,
7250 Make_Procedure_Call_Statement
(Loc
,
7251 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Defer
), Loc
),
7252 Parameter_Associations
=> No_List
));
7256 -- <abortable-statements>
7258 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7260 Prepend_To
(Cleanup_Stmts
,
7261 Make_Procedure_Call_Statement
(Loc
,
7262 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
),
7263 Parameter_Associations
=> No_List
));
7265 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7266 -- will generate a _clean for the additional status flag.
7270 -- procedure _clean is
7272 -- Cancel_Task_Entry_Call (U);
7280 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7282 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7284 -- Wrap the cleanup block in an exception handling block
7290 -- when Abort_Signal => Abort_Undefer;
7293 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7295 Append_To
(TaskE_Stmts
,
7296 Make_Implicit_Label_Declaration
(Loc
,
7297 Defining_Identifier
=> Abort_Block_Ent
));
7299 Append_To
(TaskE_Stmts
,
7301 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7305 -- <triggering-statements>
7308 Append_To
(TaskE_Stmts
,
7309 Make_Implicit_If_Statement
(N
,
7311 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7314 New_Copy_List_Tree
(Tstats
)));
7316 ----------------------------------
7317 -- Protected procedure handling --
7318 ----------------------------------
7321 -- <dispatching-call>;
7322 -- <triggering-statements>
7324 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7325 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7328 -- S := Ada.Tags.Get_Offset_Index
7329 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7332 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7335 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7337 Append_To
(Conc_Typ_Stmts
,
7338 Make_Procedure_Call_Statement
(Loc
,
7341 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7342 Name_uDisp_Get_Prim_Op_Kind
),
7344 Parameter_Associations
=>
7346 New_Copy_Tree
(Obj
),
7347 New_Occurrence_Of
(S
, Loc
),
7348 New_Occurrence_Of
(C
, Loc
))));
7351 -- if C = POK_Procedure_Entry then
7353 -- elsif C = POK_Task_Entry then
7359 Append_To
(Conc_Typ_Stmts
,
7360 Make_Implicit_If_Statement
(N
,
7364 New_Occurrence_Of
(C
, Loc
),
7366 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7373 Make_Elsif_Part
(Loc
,
7377 New_Occurrence_Of
(C
, Loc
),
7379 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7388 -- <dispatching-call>;
7389 -- <triggering-statements>
7391 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7392 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7395 -- if K = Ada.Tags.TK_Limited_Tagged
7396 -- or else K = Ada.Tags.TK_Tagged
7404 Make_Implicit_If_Statement
(N
,
7405 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7406 Then_Statements
=> Lim_Typ_Stmts
,
7407 Else_Statements
=> Conc_Typ_Stmts
));
7410 Make_Block_Statement
(Loc
,
7413 Handled_Statement_Sequence
=>
7414 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7419 -- Delay triggering statement processing
7422 -- Add a Delay_Block object to the parameter list of the delay
7423 -- procedure to form the parameter list of the Wait entry call.
7425 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7427 Pdef
:= Entity
(Name
(Ecall
));
7429 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7431 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7433 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7435 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7437 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7438 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7441 Append_To
(Parameter_Associations
(Ecall
),
7442 Make_Attribute_Reference
(Loc
,
7443 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7444 Attribute_Name
=> Name_Unchecked_Access
));
7446 -- Create the inner block to protect the abortable part
7448 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7451 Make_Procedure_Call_Statement
(Loc
,
7452 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
)));
7455 Make_Block_Statement
(Loc
,
7456 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7457 Handled_Statement_Sequence
=>
7458 Make_Handled_Sequence_Of_Statements
(Loc
,
7459 Statements
=> Astats
),
7460 Has_Created_Identifier
=> True,
7461 Is_Asynchronous_Call_Block
=> True);
7463 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7466 Make_Implicit_If_Statement
(N
,
7468 Make_Function_Call
(Loc
,
7469 Name
=> Enqueue_Call
,
7470 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7472 New_List
(Make_Block_Statement
(Loc
,
7473 Handled_Statement_Sequence
=>
7474 Make_Handled_Sequence_Of_Statements
(Loc
,
7475 Statements
=> New_List
(
7476 Make_Implicit_Label_Declaration
(Loc
,
7477 Defining_Identifier
=> Blk_Ent
,
7478 Label_Construct
=> Abortable_Block
),
7480 Exception_Handlers
=> Hdle
)))));
7482 Stmts
:= New_List
(Ecall
);
7484 -- Construct statement sequence for new block
7487 Make_Implicit_If_Statement
(N
,
7489 Make_Function_Call
(Loc
,
7490 Name
=> New_Occurrence_Of
(
7491 RTE
(RE_Timed_Out
), Loc
),
7492 Parameter_Associations
=> New_List
(
7493 Make_Attribute_Reference
(Loc
,
7494 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7495 Attribute_Name
=> Name_Unchecked_Access
))),
7496 Then_Statements
=> Tstats
));
7498 -- The result is the new block
7500 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7503 Make_Block_Statement
(Loc
,
7504 Declarations
=> New_List
(
7505 Make_Object_Declaration
(Loc
,
7506 Defining_Identifier
=> Dblock_Ent
,
7507 Aliased_Present
=> True,
7508 Object_Definition
=>
7509 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7511 Handled_Statement_Sequence
=>
7512 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7522 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7523 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7525 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7526 Decls
:= Declarations
(Ecall
);
7528 if Is_Protected_Type
(Etype
(Concval
)) then
7530 -- Get the declarations of the block expanded from the entry call
7532 Decl
:= First
(Decls
);
7533 while Present
(Decl
)
7534 and then (Nkind
(Decl
) /= N_Object_Declaration
7535 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7536 RE_Communication_Block
))
7541 pragma Assert
(Present
(Decl
));
7542 Cancel_Param
:= Defining_Identifier
(Decl
);
7544 -- Change the mode of the Protected_Entry_Call call
7546 -- Protected_Entry_Call (
7547 -- Object => po._object'Access,
7548 -- E => <entry index>;
7549 -- Uninterpreted_Data => P'Address;
7550 -- Mode => Asynchronous_Call;
7553 -- Skip assignments to temporaries created for in-out parameters
7555 -- This makes unwarranted assumptions about the shape of the expanded
7556 -- tree for the call, and should be cleaned up ???
7558 Stmt
:= First
(Stmts
);
7559 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7565 Param
:= First
(Parameter_Associations
(Call
));
7566 while Present
(Param
)
7567 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7572 pragma Assert
(Present
(Param
));
7573 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7576 -- Append an if statement to execute the abortable part
7579 -- if Enqueued (Bnn) then
7582 Make_Implicit_If_Statement
(N
,
7584 Make_Function_Call
(Loc
,
7585 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7586 Parameter_Associations
=> New_List
(
7587 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7588 Then_Statements
=> Astats
));
7591 Make_Block_Statement
(Loc
,
7592 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7593 Handled_Statement_Sequence
=>
7594 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7595 Has_Created_Identifier
=> True,
7596 Is_Asynchronous_Call_Block
=> True);
7598 -- For the VM call Update_Exception instead of Abort_Undefer.
7599 -- See 4jexcept.ads for an explanation.
7601 if VM_Target
= No_VM
then
7602 if Exception_Mechanism
= Back_End_Exceptions
then
7604 -- Aborts are not deferred at beginning of exception handlers
7607 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7610 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7611 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
),
7612 Parameter_Associations
=> No_List
);
7615 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7616 Name
=> New_Occurrence_Of
(RTE
(RE_Update_Exception
), Loc
),
7617 Parameter_Associations
=> New_List
(
7618 Make_Function_Call
(Loc
,
7619 Name
=> New_Occurrence_Of
7620 (RTE
(RE_Current_Target_Exception
), Loc
))));
7624 Make_Block_Statement
(Loc
,
7625 Handled_Statement_Sequence
=>
7626 Make_Handled_Sequence_Of_Statements
(Loc
,
7627 Statements
=> New_List
(
7628 Make_Implicit_Label_Declaration
(Loc
,
7629 Defining_Identifier
=> Blk_Ent
,
7630 Label_Construct
=> Abortable_Block
),
7635 Exception_Handlers
=> New_List
(
7636 Make_Implicit_Exception_Handler
(Loc
,
7638 -- when Abort_Signal =>
7639 -- Abort_Undefer.all;
7641 Exception_Choices
=>
7642 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7643 Statements
=> New_List
(Handler_Stmt
))))),
7645 -- if not Cancelled (Bnn) then
7646 -- triggered statements
7649 Make_Implicit_If_Statement
(N
,
7650 Condition
=> Make_Op_Not
(Loc
,
7652 Make_Function_Call
(Loc
,
7653 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7654 Parameter_Associations
=> New_List
(
7655 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7656 Then_Statements
=> Tstats
));
7658 -- Asynchronous task entry call
7665 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7667 -- Insert declaration of B in declarations of existing block
7670 Make_Object_Declaration
(Loc
,
7671 Defining_Identifier
=> B
,
7672 Object_Definition
=>
7673 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7675 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7677 -- Insert declaration of C in declarations of existing block
7680 Make_Object_Declaration
(Loc
,
7681 Defining_Identifier
=> Cancel_Param
,
7682 Object_Definition
=>
7683 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7685 -- Remove and save the call to Call_Simple
7687 Stmt
:= First
(Stmts
);
7689 -- Skip assignments to temporaries created for in-out parameters.
7690 -- This makes unwarranted assumptions about the shape of the expanded
7691 -- tree for the call, and should be cleaned up ???
7693 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7699 -- Create the inner block to protect the abortable part
7701 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7704 Make_Procedure_Call_Statement
(Loc
,
7705 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Loc
)));
7708 Make_Block_Statement
(Loc
,
7709 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7710 Handled_Statement_Sequence
=>
7711 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7712 Has_Created_Identifier
=> True,
7713 Is_Asynchronous_Call_Block
=> True);
7716 Make_Block_Statement
(Loc
,
7717 Handled_Statement_Sequence
=>
7718 Make_Handled_Sequence_Of_Statements
(Loc
,
7719 Statements
=> New_List
(
7720 Make_Implicit_Label_Declaration
(Loc
,
7721 Defining_Identifier
=> Blk_Ent
,
7722 Label_Construct
=> Abortable_Block
),
7724 Exception_Handlers
=> Hdle
)));
7726 -- Create new call statement
7728 Params
:= Parameter_Associations
(Call
);
7731 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7732 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7735 Make_Procedure_Call_Statement
(Loc
,
7736 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7737 Parameter_Associations
=> Params
));
7739 -- Construct statement sequence for new block
7742 Make_Implicit_If_Statement
(N
,
7744 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7745 Then_Statements
=> Tstats
));
7747 -- Protected the call against abort
7750 Make_Procedure_Call_Statement
(Loc
,
7751 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Defer
), Loc
),
7752 Parameter_Associations
=> Empty_List
));
7755 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7757 -- The result is the new block
7760 Make_Block_Statement
(Loc
,
7761 Declarations
=> Decls
,
7762 Handled_Statement_Sequence
=>
7763 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7766 end Expand_N_Asynchronous_Select
;
7768 -------------------------------------
7769 -- Expand_N_Conditional_Entry_Call --
7770 -------------------------------------
7772 -- The conditional task entry call is converted to a call to
7777 -- P : parms := (parm, parm, parm);
7781 -- (<acceptor-task>, -- Acceptor
7782 -- <entry-index>, -- E
7783 -- P'Address, -- Uninterpreted_Data
7784 -- Conditional_Call, -- Mode
7785 -- B); -- Rendezvous_Successful
7790 -- normal-statements
7796 -- For a description of the use of P and the assignments after the call,
7797 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7798 -- conditional entry call has already been expanded (by the Expand_N_Entry
7799 -- _Call_Statement procedure) as follows:
7802 -- P : parms := (parm, parm, parm);
7804 -- ... info for in-out parameters
7805 -- Call_Simple (acceptor-task, entry-index, P'Address);
7811 -- so the task at hand is to convert the latter expansion into the former
7813 -- The conditional protected entry call is converted to a call to
7814 -- Protected_Entry_Call:
7817 -- P : parms := (parm, parm, parm);
7818 -- Bnn : Communications_Block;
7821 -- Protected_Entry_Call
7822 -- (po._object'Access, -- Object
7823 -- <entry index>, -- E
7824 -- P'Address, -- Uninterpreted_Data
7825 -- Conditional_Call, -- Mode
7830 -- if Cancelled (Bnn) then
7833 -- normal-statements
7837 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7841 -- B : Boolean := False;
7842 -- C : Ada.Tags.Prim_Op_Kind;
7843 -- K : Ada.Tags.Tagged_Kind :=
7844 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7845 -- P : Parameters := (Param1 .. ParamN);
7849 -- if K = Ada.Tags.TK_Limited_Tagged
7850 -- or else K = Ada.Tags.TK_Tagged
7852 -- <dispatching-call>;
7853 -- <triggering-statements>
7857 -- Ada.Tags.Get_Offset_Index
7858 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7860 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7862 -- if C = POK_Protected_Entry
7863 -- or else C = POK_Task_Entry
7865 -- Param1 := P.Param1;
7867 -- ParamN := P.ParamN;
7871 -- if C = POK_Procedure
7872 -- or else C = POK_Protected_Procedure
7873 -- or else C = POK_Task_Procedure
7875 -- <dispatching-call>;
7878 -- <triggering-statements>
7880 -- <else-statements>
7885 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7886 Loc
: constant Source_Ptr
:= Sloc
(N
);
7887 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7888 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7891 Blk_Typ
: Entity_Id
;
7893 Call_Ent
: Entity_Id
;
7894 Conc_Typ_Stmts
: List_Id
;
7898 Lim_Typ_Stmts
: List_Id
;
7905 Transient_Blk
: Node_Id
;
7908 B
: Entity_Id
; -- Call status flag
7909 C
: Entity_Id
; -- Call kind
7910 K
: Entity_Id
; -- Tagged kind
7911 P
: Entity_Id
; -- Parameter block
7912 S
: Entity_Id
; -- Primitive operation slot
7915 Process_Statements_For_Controlled_Objects
(N
);
7917 if Ada_Version
>= Ada_2005
7918 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7920 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7925 -- Call status flag processing, generate:
7926 -- B : Boolean := False;
7928 B
:= Build_B
(Loc
, Decls
);
7930 -- Call kind processing, generate:
7931 -- C : Ada.Tags.Prim_Op_Kind;
7933 C
:= Build_C
(Loc
, Decls
);
7935 -- Tagged kind processing, generate:
7936 -- K : Ada.Tags.Tagged_Kind :=
7937 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7939 K
:= Build_K
(Loc
, Decls
, Obj
);
7941 -- Parameter block processing
7943 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7944 P
:= Parameter_Block_Pack
7945 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7947 -- Dispatch table slot processing, generate:
7950 S
:= Build_S
(Loc
, Decls
);
7953 -- S := Ada.Tags.Get_Offset_Index
7954 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7957 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7960 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7962 Append_To
(Conc_Typ_Stmts
,
7963 Make_Procedure_Call_Statement
(Loc
,
7966 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7967 Name_uDisp_Conditional_Select
),
7969 Parameter_Associations
=>
7971 New_Copy_Tree
(Obj
), -- <object>
7972 New_Occurrence_Of
(S
, Loc
), -- S
7973 Make_Attribute_Reference
(Loc
, -- P'Address
7974 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7975 Attribute_Name
=> Name_Address
),
7976 New_Occurrence_Of
(C
, Loc
), -- C
7977 New_Occurrence_Of
(B
, Loc
)))); -- B
7980 -- if C = POK_Protected_Entry
7981 -- or else C = POK_Task_Entry
7983 -- Param1 := P.Param1;
7985 -- ParamN := P.ParamN;
7988 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7990 -- Generate the if statement only when the packed parameters need
7991 -- explicit assignments to their corresponding actuals.
7993 if Present
(Unpack
) then
7994 Append_To
(Conc_Typ_Stmts
,
7995 Make_Implicit_If_Statement
(N
,
8001 New_Occurrence_Of
(C
, Loc
),
8003 New_Occurrence_Of
(RTE
(
8004 RE_POK_Protected_Entry
), Loc
)),
8009 New_Occurrence_Of
(C
, Loc
),
8011 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
8013 Then_Statements
=> Unpack
));
8018 -- if C = POK_Procedure
8019 -- or else C = POK_Protected_Procedure
8020 -- or else C = POK_Task_Procedure
8022 -- <dispatching-call>
8024 -- <normal-statements>
8026 -- <else-statements>
8029 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
8031 Prepend_To
(N_Stats
,
8032 Make_Implicit_If_Statement
(N
,
8038 New_Occurrence_Of
(C
, Loc
),
8040 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
8047 New_Occurrence_Of
(C
, Loc
),
8049 New_Occurrence_Of
(RTE
(
8050 RE_POK_Protected_Procedure
), Loc
)),
8055 New_Occurrence_Of
(C
, Loc
),
8057 New_Occurrence_Of
(RTE
(
8058 RE_POK_Task_Procedure
), Loc
)))),
8063 Append_To
(Conc_Typ_Stmts
,
8064 Make_Implicit_If_Statement
(N
,
8065 Condition
=> New_Occurrence_Of
(B
, Loc
),
8066 Then_Statements
=> N_Stats
,
8067 Else_Statements
=> Else_Statements
(N
)));
8070 -- <dispatching-call>;
8071 -- <triggering-statements>
8073 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
8074 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
8077 -- if K = Ada.Tags.TK_Limited_Tagged
8078 -- or else K = Ada.Tags.TK_Tagged
8086 Make_Implicit_If_Statement
(N
,
8087 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
8088 Then_Statements
=> Lim_Typ_Stmts
,
8089 Else_Statements
=> Conc_Typ_Stmts
));
8092 Make_Block_Statement
(Loc
,
8095 Handled_Statement_Sequence
=>
8096 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8098 -- As described above, the entry alternative is transformed into a
8099 -- block that contains the gnulli call, and possibly assignment
8100 -- statements for in-out parameters. The gnulli call may itself be
8101 -- rewritten into a transient block if some unconstrained parameters
8102 -- require it. We need to retrieve the call to complete its parameter
8107 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
8109 if Present
(Transient_Blk
)
8110 and then Nkind
(Transient_Blk
) = N_Block_Statement
8112 Blk
:= Transient_Blk
;
8115 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
8116 Stmt
:= First
(Stmts
);
8117 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
8122 Params
:= Parameter_Associations
(Call
);
8124 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
8126 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8128 Param
:= First
(Params
);
8129 while Present
(Param
)
8130 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
8135 pragma Assert
(Present
(Param
));
8137 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8141 -- Find the Communication_Block parameter for the call to the
8142 -- Cancelled function.
8144 Decl
:= First
(Declarations
(Blk
));
8145 while Present
(Decl
)
8146 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
8147 RE_Communication_Block
)
8152 -- Add an if statement to execute the else part if the call
8153 -- does not succeed (as indicated by the Cancelled predicate).
8156 Make_Implicit_If_Statement
(N
,
8157 Condition
=> Make_Function_Call
(Loc
,
8158 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
8159 Parameter_Associations
=> New_List
(
8160 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
8161 Then_Statements
=> Else_Statements
(N
),
8162 Else_Statements
=> Statements
(Alt
)));
8165 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8167 -- Insert declaration of B in declarations of existing block
8169 if No
(Declarations
(Blk
)) then
8170 Set_Declarations
(Blk
, New_List
);
8173 Prepend_To
(Declarations
(Blk
),
8174 Make_Object_Declaration
(Loc
,
8175 Defining_Identifier
=> B
,
8176 Object_Definition
=>
8177 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8179 -- Create new call statement
8182 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8183 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
8186 Make_Procedure_Call_Statement
(Loc
,
8187 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
8188 Parameter_Associations
=> Params
));
8190 -- Construct statement sequence for new block
8193 Make_Implicit_If_Statement
(N
,
8194 Condition
=> New_Occurrence_Of
(B
, Loc
),
8195 Then_Statements
=> Statements
(Alt
),
8196 Else_Statements
=> Else_Statements
(N
)));
8199 -- The result is the new block
8202 Make_Block_Statement
(Loc
,
8203 Declarations
=> Declarations
(Blk
),
8204 Handled_Statement_Sequence
=>
8205 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8209 end Expand_N_Conditional_Entry_Call
;
8211 ---------------------------------------
8212 -- Expand_N_Delay_Relative_Statement --
8213 ---------------------------------------
8215 -- Delay statement is implemented as a procedure call to Delay_For
8216 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8217 -- simple delays imposed by the use of Protected Objects.
8219 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8220 Loc
: constant Source_Ptr
:= Sloc
(N
);
8223 Make_Procedure_Call_Statement
(Loc
,
8224 Name
=> New_Occurrence_Of
(RTE
(RO_CA_Delay_For
), Loc
),
8225 Parameter_Associations
=> New_List
(Expression
(N
))));
8227 end Expand_N_Delay_Relative_Statement
;
8229 ------------------------------------
8230 -- Expand_N_Delay_Until_Statement --
8231 ------------------------------------
8233 -- Delay Until statement is implemented as a procedure call to
8234 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8236 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8237 Loc
: constant Source_Ptr
:= Sloc
(N
);
8241 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8242 Typ
:= RTE
(RO_CA_Delay_Until
);
8244 Typ
:= RTE
(RO_RT_Delay_Until
);
8248 Make_Procedure_Call_Statement
(Loc
,
8249 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8250 Parameter_Associations
=> New_List
(Expression
(N
))));
8253 end Expand_N_Delay_Until_Statement
;
8255 -------------------------
8256 -- Expand_N_Entry_Body --
8257 -------------------------
8259 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8261 -- Associate discriminals with the next protected operation body to be
8264 if Present
(Next_Protected_Operation
(N
)) then
8265 Set_Discriminals
(Parent
(Current_Scope
));
8267 end Expand_N_Entry_Body
;
8269 -----------------------------------
8270 -- Expand_N_Entry_Call_Statement --
8271 -----------------------------------
8273 -- An entry call is expanded into GNARLI calls to implement a simple entry
8274 -- call (see Build_Simple_Entry_Call).
8276 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8282 if No_Run_Time_Mode
then
8283 Error_Msg_CRT
("entry call", N
);
8287 -- If this entry call is part of an asynchronous select, don't expand it
8288 -- here; it will be expanded with the select statement. Don't expand
8289 -- timed entry calls either, as they are translated into asynchronous
8292 -- ??? This whole approach is questionable; it may be better to go back
8293 -- to allowing the expansion to take place and then attempting to fix it
8294 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8295 -- whether the expanded call is on a task or protected entry.
8297 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8298 or else N
/= Triggering_Statement
(Parent
(N
)))
8299 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8300 or else N
/= Entry_Call_Statement
(Parent
(N
))
8301 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8303 Extract_Entry
(N
, Concval
, Ename
, Index
);
8304 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8306 end Expand_N_Entry_Call_Statement
;
8308 --------------------------------
8309 -- Expand_N_Entry_Declaration --
8310 --------------------------------
8312 -- If there are parameters, then first, each of the formals is marked by
8313 -- setting Is_Entry_Formal. Next a record type is built which is used to
8314 -- hold the parameter values. The name of this record type is entryP where
8315 -- entry is the name of the entry, with an additional corresponding access
8316 -- type called entryPA. The record type has matching components for each
8317 -- formal (the component names are the same as the formal names). For
8318 -- elementary types, the component type matches the formal type. For
8319 -- composite types, an access type is declared (with the name formalA)
8320 -- which designates the formal type, and the type of the component is this
8321 -- access type. Finally the Entry_Component of each formal is set to
8322 -- reference the corresponding record component.
8324 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8325 Loc
: constant Source_Ptr
:= Sloc
(N
);
8326 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8327 Components
: List_Id
;
8330 Last_Decl
: Node_Id
;
8331 Component
: Entity_Id
;
8334 Rec_Ent
: Entity_Id
;
8335 Acc_Ent
: Entity_Id
;
8338 Formal
:= First_Formal
(Entry_Ent
);
8341 -- Most processing is done only if parameters are present
8343 if Present
(Formal
) then
8344 Components
:= New_List
;
8346 -- Loop through formals
8348 while Present
(Formal
) loop
8349 Set_Is_Entry_Formal
(Formal
);
8351 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8352 Set_Entry_Component
(Formal
, Component
);
8353 Set_Entry_Formal
(Component
, Formal
);
8354 Ftype
:= Etype
(Formal
);
8356 -- Declare new access type and then append
8358 Ctype
:= Make_Temporary
(Loc
, 'A');
8361 Make_Full_Type_Declaration
(Loc
,
8362 Defining_Identifier
=> Ctype
,
8364 Make_Access_To_Object_Definition
(Loc
,
8365 All_Present
=> True,
8366 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8367 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8369 Insert_After
(Last_Decl
, Decl
);
8372 Append_To
(Components
,
8373 Make_Component_Declaration
(Loc
,
8374 Defining_Identifier
=> Component
,
8375 Component_Definition
=>
8376 Make_Component_Definition
(Loc
,
8377 Aliased_Present
=> False,
8378 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8380 Next_Formal_With_Extras
(Formal
);
8383 -- Create the Entry_Parameter_Record declaration
8385 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8388 Make_Full_Type_Declaration
(Loc
,
8389 Defining_Identifier
=> Rec_Ent
,
8391 Make_Record_Definition
(Loc
,
8393 Make_Component_List
(Loc
,
8394 Component_Items
=> Components
)));
8396 Insert_After
(Last_Decl
, Decl
);
8399 -- Construct and link in the corresponding access type
8401 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8403 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8406 Make_Full_Type_Declaration
(Loc
,
8407 Defining_Identifier
=> Acc_Ent
,
8409 Make_Access_To_Object_Definition
(Loc
,
8410 All_Present
=> True,
8411 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8413 Insert_After
(Last_Decl
, Decl
);
8415 end Expand_N_Entry_Declaration
;
8417 -----------------------------
8418 -- Expand_N_Protected_Body --
8419 -----------------------------
8421 -- Protected bodies are expanded to the completion of the subprograms
8422 -- created for the corresponding protected type. These are a protected and
8423 -- unprotected version of each protected subprogram in the object, a
8424 -- function to calculate each entry barrier, and a procedure to execute the
8425 -- sequence of statements of each protected entry body. For example, for
8426 -- protected type ptype:
8429 -- (O : System.Address;
8430 -- E : Protected_Entry_Index)
8433 -- <discriminant renamings>
8434 -- <private object renamings>
8436 -- return <barrier expression>;
8439 -- procedure pprocN (_object : in out poV;...) is
8440 -- <discriminant renamings>
8441 -- <private object renamings>
8443 -- <sequence of statements>
8446 -- procedure pprocP (_object : in out poV;...) is
8447 -- procedure _clean is
8450 -- ptypeS (_object, Pn);
8451 -- Unlock (_object._object'Access);
8452 -- Abort_Undefer.all;
8457 -- Lock (_object._object'Access);
8458 -- pprocN (_object;...);
8463 -- function pfuncN (_object : poV;...) return Return_Type is
8464 -- <discriminant renamings>
8465 -- <private object renamings>
8467 -- <sequence of statements>
8470 -- function pfuncP (_object : poV) return Return_Type is
8471 -- procedure _clean is
8473 -- Unlock (_object._object'Access);
8474 -- Abort_Undefer.all;
8479 -- Lock (_object._object'Access);
8480 -- return pfuncN (_object);
8487 -- (O : System.Address;
8488 -- P : System.Address;
8489 -- E : Protected_Entry_Index)
8491 -- <discriminant renamings>
8492 -- <private object renamings>
8493 -- type poVP is access poV;
8494 -- _Object : ptVP := ptVP!(O);
8498 -- <statement sequence>
8499 -- Complete_Entry_Body (_Object._Object);
8501 -- when all others =>
8502 -- Exceptional_Complete_Entry_Body (
8503 -- _Object._Object, Get_GNAT_Exception);
8507 -- The type poV is the record created for the protected type to hold
8508 -- the state of the protected object.
8510 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8511 Loc
: constant Source_Ptr
:= Sloc
(N
);
8512 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8514 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8515 -- This flag indicates whether the lock free implementation is active
8517 Current_Node
: Node_Id
;
8518 Disp_Op_Body
: Node_Id
;
8519 New_Op_Body
: Node_Id
;
8523 function Build_Dispatching_Subprogram_Body
8526 Prot_Bod
: Node_Id
) return Node_Id
;
8527 -- Build a dispatching version of the protected subprogram body. The
8528 -- newly generated subprogram contains a call to the original protected
8529 -- body. The following code is generated:
8531 -- function <protected-function-name> (Param1 .. ParamN) return
8534 -- return <protected-function-name>P (Param1 .. ParamN);
8535 -- end <protected-function-name>;
8539 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8541 -- <protected-procedure-name>P (Param1 .. ParamN);
8542 -- end <protected-procedure-name>
8544 ---------------------------------------
8545 -- Build_Dispatching_Subprogram_Body --
8546 ---------------------------------------
8548 function Build_Dispatching_Subprogram_Body
8551 Prot_Bod
: Node_Id
) return Node_Id
8553 Loc
: constant Source_Ptr
:= Sloc
(N
);
8560 -- Generate a specification without a letter suffix in order to
8561 -- override an interface function or procedure.
8563 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8565 -- The formal parameters become the actuals of the protected function
8566 -- or procedure call.
8568 Actuals
:= New_List
;
8569 Formal
:= First
(Parameter_Specifications
(Spec
));
8570 while Present
(Formal
) loop
8572 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8576 if Nkind
(Spec
) = N_Procedure_Specification
then
8579 Make_Procedure_Call_Statement
(Loc
,
8581 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8582 Parameter_Associations
=> Actuals
));
8585 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8589 Make_Simple_Return_Statement
(Loc
,
8591 Make_Function_Call
(Loc
,
8593 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8594 Parameter_Associations
=> Actuals
)));
8598 Make_Subprogram_Body
(Loc
,
8599 Declarations
=> Empty_List
,
8600 Specification
=> Spec
,
8601 Handled_Statement_Sequence
=>
8602 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8603 end Build_Dispatching_Subprogram_Body
;
8605 -- Start of processing for Expand_N_Protected_Body
8608 if No_Run_Time_Mode
then
8609 Error_Msg_CRT
("protected body", N
);
8613 -- This is the proper body corresponding to a stub. The declarations
8614 -- must be inserted at the point of the stub, which in turn is in the
8615 -- declarative part of the parent unit.
8617 if Nkind
(Parent
(N
)) = N_Subunit
then
8618 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8623 Op_Body
:= First
(Declarations
(N
));
8625 -- The protected body is replaced with the bodies of its
8626 -- protected operations, and the declarations for internal objects
8627 -- that may have been created for entry family bounds.
8629 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8632 while Present
(Op_Body
) loop
8633 case Nkind
(Op_Body
) is
8634 when N_Subprogram_Declaration
=>
8637 when N_Subprogram_Body
=>
8639 -- Do not create bodies for eliminated operations
8641 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8642 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8644 if Lock_Free_Active
then
8646 Build_Lock_Free_Unprotected_Subprogram_Body
8650 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8653 Insert_After
(Current_Node
, New_Op_Body
);
8654 Current_Node
:= New_Op_Body
;
8655 Analyze
(New_Op_Body
);
8657 -- Build the corresponding protected operation. It may
8658 -- appear that this is needed only if this is a visible
8659 -- operation of the type, or if it is an interrupt handler,
8660 -- and this was the strategy used previously in GNAT.
8662 -- However, the operation may be exported through a 'Access
8663 -- to an external caller. This is the common idiom in code
8664 -- that uses the Ada 2005 Timing_Events package. As a result
8665 -- we need to produce the protected body for both visible
8666 -- and private operations, as well as operations that only
8667 -- have a body in the source, and for which we create a
8668 -- declaration in the protected body itself.
8670 if Present
(Corresponding_Spec
(Op_Body
)) then
8671 if Lock_Free_Active
then
8673 Build_Lock_Free_Protected_Subprogram_Body
8674 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8677 Build_Protected_Subprogram_Body
8678 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8681 Insert_After
(Current_Node
, New_Op_Body
);
8682 Analyze
(New_Op_Body
);
8684 Current_Node
:= New_Op_Body
;
8686 -- Generate an overriding primitive operation body for
8687 -- this subprogram if the protected type implements an
8690 if Ada_Version
>= Ada_2005
8692 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8695 Build_Dispatching_Subprogram_Body
8696 (Op_Body
, Pid
, New_Op_Body
);
8698 Insert_After
(Current_Node
, Disp_Op_Body
);
8699 Analyze
(Disp_Op_Body
);
8701 Current_Node
:= Disp_Op_Body
;
8706 when N_Entry_Body
=>
8707 Op_Id
:= Defining_Identifier
(Op_Body
);
8708 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8710 Insert_After
(Current_Node
, New_Op_Body
);
8711 Current_Node
:= New_Op_Body
;
8712 Analyze
(New_Op_Body
);
8714 when N_Implicit_Label_Declaration
=>
8717 when N_Itype_Reference
=>
8718 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8720 when N_Freeze_Entity
=>
8721 New_Op_Body
:= New_Copy
(Op_Body
);
8723 if Present
(Entity
(Op_Body
))
8724 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8726 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8729 Insert_After
(Current_Node
, New_Op_Body
);
8730 Current_Node
:= New_Op_Body
;
8731 Analyze
(New_Op_Body
);
8734 New_Op_Body
:= New_Copy
(Op_Body
);
8735 Insert_After
(Current_Node
, New_Op_Body
);
8736 Current_Node
:= New_Op_Body
;
8737 Analyze
(New_Op_Body
);
8739 when N_Object_Declaration
=>
8740 pragma Assert
(not Comes_From_Source
(Op_Body
));
8741 New_Op_Body
:= New_Copy
(Op_Body
);
8742 Insert_After
(Current_Node
, New_Op_Body
);
8743 Current_Node
:= New_Op_Body
;
8744 Analyze
(New_Op_Body
);
8747 raise Program_Error
;
8754 -- Finally, create the body of the function that maps an entry index
8755 -- into the corresponding body index, except when there is no entry, or
8756 -- in a Ravenscar-like profile.
8758 if Corresponding_Runtime_Package
(Pid
) =
8759 System_Tasking_Protected_Objects_Entries
8761 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8762 Insert_After
(Current_Node
, New_Op_Body
);
8763 Current_Node
:= New_Op_Body
;
8764 Analyze
(New_Op_Body
);
8767 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8768 -- protected body. At this point all wrapper specs have been created,
8769 -- frozen and included in the dispatch table for the protected type.
8771 if Ada_Version
>= Ada_2005
then
8772 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8774 end Expand_N_Protected_Body
;
8776 -----------------------------------------
8777 -- Expand_N_Protected_Type_Declaration --
8778 -----------------------------------------
8780 -- First we create a corresponding record type declaration used to
8781 -- represent values of this protected type.
8782 -- The general form of this type declaration is
8784 -- type poV (discriminants) is record
8785 -- _Object : aliased <kind>Protection
8786 -- [(<entry count> [, <handler count>])];
8787 -- [entry_family : array (bounds) of Void;]
8788 -- <private data fields>
8791 -- The discriminants are present only if the corresponding protected type
8792 -- has discriminants, and they exactly mirror the protected type
8793 -- discriminants. The private data fields similarly mirror the private
8794 -- declarations of the protected type.
8796 -- The Object field is always present. It contains RTS specific data used
8797 -- to control the protected object. It is declared as Aliased so that it
8798 -- can be passed as a pointer to the RTS. This allows the protected record
8799 -- to be referenced within RTS data structures. An appropriate Protection
8800 -- type and discriminant are generated.
8802 -- The Service field is present for protected objects with entries. It
8803 -- contains sufficient information to allow the entry service procedure for
8804 -- this object to be called when the object is not known till runtime.
8806 -- One entry_family component is present for each entry family in the
8807 -- task definition (see Expand_N_Task_Type_Declaration).
8809 -- When a protected object is declared, an instance of the protected type
8810 -- value record is created. The elaboration of this declaration creates the
8811 -- correct bounds for the entry families, and also evaluates the priority
8812 -- expression if needed. The initialization routine for the protected type
8813 -- itself then calls Initialize_Protection with appropriate parameters to
8814 -- initialize the value of the Task_Id field. Install_Handlers may be also
8815 -- called if a pragma Attach_Handler applies.
8817 -- Note: this record is passed to the subprograms created by the expansion
8818 -- of protected subprograms and entries. It is an in parameter to protected
8819 -- functions and an in out parameter to procedures and entry bodies. The
8820 -- Entity_Id for this created record type is placed in the
8821 -- Corresponding_Record_Type field of the associated protected type entity.
8823 -- Next we create a procedure specifications for protected subprograms and
8824 -- entry bodies. For each protected subprograms two subprograms are
8825 -- created, an unprotected and a protected version. The unprotected version
8826 -- is called from within other operations of the same protected object.
8828 -- We also build the call to register the procedure if a pragma
8829 -- Interrupt_Handler applies.
8831 -- A single subprogram is created to service all entry bodies; it has an
8832 -- additional boolean out parameter indicating that the previous entry call
8833 -- made by the current task was serviced immediately, i.e. not by proxy.
8834 -- The O parameter contains a pointer to a record object of the type
8835 -- described above. An untyped interface is used here to allow this
8836 -- procedure to be called in places where the type of the object to be
8837 -- serviced is not known. This must be done, for example, when a call that
8838 -- may have been requeued is cancelled; the corresponding object must be
8839 -- serviced, but which object that is not known till runtime.
8842 -- (O : System.Address; P : out Boolean);
8843 -- procedure pprocN (_object : in out poV);
8844 -- procedure pproc (_object : in out poV);
8845 -- function pfuncN (_object : poV);
8846 -- function pfunc (_object : poV);
8849 -- Note that this must come after the record type declaration, since
8850 -- the specs refer to this type.
8852 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8853 Loc
: constant Source_Ptr
:= Sloc
(N
);
8854 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8856 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8857 -- This flag indicates whether the lock free implementation is active
8859 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8860 -- This contains two lists; one for visible and one for private decls
8864 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8868 Comp_Id
: Entity_Id
;
8870 Current_Node
: Node_Id
:= N
;
8871 Entries_Aggr
: Node_Id
;
8872 Body_Id
: Entity_Id
;
8875 Object_Comp
: Node_Id
;
8877 procedure Check_Inlining
(Subp
: Entity_Id
);
8878 -- If the original operation has a pragma Inline, propagate the flag
8879 -- to the internal body, for possible inlining later on. The source
8880 -- operation is invisible to the back-end and is never actually called.
8882 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean;
8883 -- If a component size is not static then a warning will be emitted
8884 -- in Ravenscar or other restricted contexts. When a component is non-
8885 -- static because of a discriminant constraint we can specialize the
8886 -- warning by mentioning discriminants explicitly.
8888 procedure Expand_Entry_Declaration
(Comp
: Entity_Id
);
8889 -- Create the subprograms for the barrier and for the body, and append
8890 -- then to Entry_Bodies_Array.
8892 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8893 -- When compiling under the Ravenscar profile, private components must
8894 -- have a static size, or else a protected object will require heap
8895 -- allocation, violating the corresponding restriction. It is preferable
8896 -- to make this check here, because it provides a better error message
8897 -- than the back-end, which refers to the object as a whole.
8899 procedure Register_Handler
;
8900 -- For a protected operation that is an interrupt handler, add the
8901 -- freeze action that will register it as such.
8903 --------------------
8904 -- Check_Inlining --
8905 --------------------
8907 procedure Check_Inlining
(Subp
: Entity_Id
) is
8909 if Is_Inlined
(Subp
) then
8910 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8911 Set_Is_Inlined
(Subp
, False);
8915 ------------------------
8916 -- Discriminated_Size --
8917 ------------------------
8919 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean is
8920 Typ
: constant Entity_Id
:= Etype
(Comp
);
8923 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean;
8924 -- Check whether the bound of an index is non-static and does denote
8925 -- a discriminant, in which case any protected object of the type
8926 -- will have a non-static size.
8928 ----------------------
8929 -- Non_Static_Bound --
8930 ----------------------
8932 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean is
8934 if Is_OK_Static_Expression
(Bound
) then
8937 elsif Is_Entity_Name
(Bound
)
8938 and then Present
(Discriminal_Link
(Entity
(Bound
)))
8945 end Non_Static_Bound
;
8947 -- Start of processing for Discriminated_Size
8950 if not Is_Array_Type
(Typ
) then
8954 if Ekind
(Typ
) = E_Array_Subtype
then
8955 Index
:= First_Index
(Typ
);
8956 while Present
(Index
) loop
8957 if Non_Static_Bound
(Low_Bound
(Index
))
8958 or else Non_Static_Bound
(High_Bound
(Index
))
8970 end Discriminated_Size
;
8972 ---------------------------
8973 -- Static_Component_Size --
8974 ---------------------------
8976 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8977 Typ
: constant Entity_Id
:= Etype
(Comp
);
8981 if Is_Scalar_Type
(Typ
) then
8984 elsif Is_Array_Type
(Typ
) then
8985 return Compile_Time_Known_Bounds
(Typ
);
8987 elsif Is_Record_Type
(Typ
) then
8988 C
:= First_Component
(Typ
);
8989 while Present
(C
) loop
8990 if not Static_Component_Size
(C
) then
8999 -- Any other type will be checked by the back-end
9004 end Static_Component_Size
;
9006 ------------------------------
9007 -- Expand_Entry_Declaration --
9008 ------------------------------
9010 procedure Expand_Entry_Declaration
(Comp
: Entity_Id
) is
9015 E_Count
:= E_Count
+ 1;
9016 Comp_Id
:= Defining_Identifier
(Comp
);
9019 Make_Defining_Identifier
(Loc
,
9020 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9022 Make_Subprogram_Declaration
(Loc
,
9024 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9026 Insert_After
(Current_Node
, Sub
);
9029 -- Build wrapper procedure for pre/postconditions
9031 Build_PPC_Wrapper
(Comp_Id
, N
);
9033 Set_Protected_Body_Subprogram
9034 (Defining_Identifier
(Comp
),
9035 Defining_Unit_Name
(Specification
(Sub
)));
9037 Current_Node
:= Sub
;
9040 Make_Defining_Identifier
(Loc
,
9041 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
9043 Make_Subprogram_Declaration
(Loc
,
9045 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9047 Insert_After
(Current_Node
, Sub
);
9049 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9050 Set_Barrier_Function
(Comp_Id
, Bdef
);
9051 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9052 Current_Node
:= Sub
;
9054 -- Collect pointers to the protected subprogram and the barrier
9055 -- of the current entry, for insertion into Entry_Bodies_Array.
9057 Append_To
(Expressions
(Entries_Aggr
),
9058 Make_Aggregate
(Loc
,
9059 Expressions
=> New_List
(
9060 Make_Attribute_Reference
(Loc
,
9061 Prefix
=> New_Occurrence_Of
(Bdef
, Loc
),
9062 Attribute_Name
=> Name_Unrestricted_Access
),
9063 Make_Attribute_Reference
(Loc
,
9064 Prefix
=> New_Occurrence_Of
(Edef
, Loc
),
9065 Attribute_Name
=> Name_Unrestricted_Access
))));
9066 end Expand_Entry_Declaration
;
9068 ----------------------
9069 -- Register_Handler --
9070 ----------------------
9072 procedure Register_Handler
is
9074 -- All semantic checks already done in Sem_Prag
9076 Prot_Proc
: constant Entity_Id
:=
9077 Defining_Unit_Name
(Specification
(Current_Node
));
9079 Proc_Address
: constant Node_Id
:=
9080 Make_Attribute_Reference
(Loc
,
9082 New_Occurrence_Of
(Prot_Proc
, Loc
),
9083 Attribute_Name
=> Name_Address
);
9085 RTS_Call
: constant Entity_Id
:=
9086 Make_Procedure_Call_Statement
(Loc
,
9089 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
9090 Parameter_Associations
=> New_List
(Proc_Address
));
9092 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
9093 end Register_Handler
;
9095 -- Start of processing for Expand_N_Protected_Type_Declaration
9098 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
9101 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
9104 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
9106 Qualify_Entity_Names
(N
);
9108 -- If the type has discriminants, their occurrences in the declaration
9109 -- have been replaced by the corresponding discriminals. For components
9110 -- that are constrained by discriminants, their homologues in the
9111 -- corresponding record type must refer to the discriminants of that
9112 -- record, so we must apply a new renaming to subtypes_indications:
9114 -- protected discriminant => discriminal => record discriminant
9116 -- This replacement is not applied to default expressions, for which
9117 -- the discriminal is correct.
9119 if Has_Discriminants
(Prot_Typ
) then
9125 Disc
:= First_Discriminant
(Prot_Typ
);
9126 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
9127 while Present
(Disc
) loop
9128 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
9129 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
9130 Next_Discriminant
(Disc
);
9136 -- Fill in the component declarations
9138 -- Add components for entry families. For each entry family, create an
9139 -- anonymous type declaration with the same size, and analyze the type.
9141 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9143 pragma Assert
(Present
(Pdef
));
9145 -- Add private field components
9147 if Present
(Private_Declarations
(Pdef
)) then
9148 Priv
:= First
(Private_Declarations
(Pdef
));
9149 while Present
(Priv
) loop
9150 if Nkind
(Priv
) = N_Component_Declaration
then
9151 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9153 -- When compiling for a restricted profile, the private
9154 -- components must have a static size. If not, this is an
9155 -- error for a single protected declaration, and rates a
9156 -- warning on a protected type declaration.
9158 if not Comes_From_Source
(Prot_Typ
) then
9160 -- It's ok to be checking this restriction at expansion
9161 -- time, because this is only for the restricted profile,
9162 -- which is not subject to strict RM conformance, so it
9163 -- is OK to miss this check in -gnatc mode.
9165 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9167 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9168 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9171 -- Any object of the type will be non-static.
9173 Error_Msg_N
("component has non-static size??", Priv
);
9175 ("\creation of protected object of type& will"
9176 & " violate restriction "
9177 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9180 -- Object will be non-static if discriminants are.
9183 ("creation of protected object of type& with "
9184 & "non-static discriminants will violate"
9185 & " restriction No_Implicit_Heap_Allocations??",
9191 -- The component definition consists of a subtype indication,
9192 -- or (in Ada 2005) an access definition. Make a copy of the
9193 -- proper definition.
9196 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9197 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9199 Nent
: constant Entity_Id
:=
9200 Make_Defining_Identifier
(Sloc
(Oent
),
9201 Chars
=> Chars
(Oent
));
9204 if Present
(Subtype_Indication
(Old_Comp
)) then
9206 Make_Component_Definition
(Sloc
(Oent
),
9207 Aliased_Present
=> False,
9208 Subtype_Indication
=>
9209 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
9213 Make_Component_Definition
(Sloc
(Oent
),
9214 Aliased_Present
=> False,
9215 Access_Definition
=>
9216 New_Copy_Tree
(Access_Definition
(Old_Comp
),
9221 Make_Component_Declaration
(Loc
,
9222 Defining_Identifier
=> Nent
,
9223 Component_Definition
=> New_Comp
,
9224 Expression
=> Expression
(Priv
));
9226 Set_Has_Per_Object_Constraint
(Nent
,
9227 Has_Per_Object_Constraint
(Oent
));
9229 Append_To
(Cdecls
, New_Priv
);
9232 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9234 -- Make the unprotected version of the subprogram available
9235 -- for expansion of intra object calls. There is need for
9236 -- a protected version only if the subprogram is an interrupt
9237 -- handler, otherwise this operation can only be called from
9241 Make_Subprogram_Declaration
(Loc
,
9243 Build_Protected_Sub_Specification
9244 (Priv
, Prot_Typ
, Unprotected_Mode
));
9246 Insert_After
(Current_Node
, Sub
);
9249 Set_Protected_Body_Subprogram
9250 (Defining_Unit_Name
(Specification
(Priv
)),
9251 Defining_Unit_Name
(Specification
(Sub
)));
9252 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9253 Current_Node
:= Sub
;
9256 Make_Subprogram_Declaration
(Loc
,
9258 Build_Protected_Sub_Specification
9259 (Priv
, Prot_Typ
, Protected_Mode
));
9261 Insert_After
(Current_Node
, Sub
);
9263 Current_Node
:= Sub
;
9265 if Is_Interrupt_Handler
9266 (Defining_Unit_Name
(Specification
(Priv
)))
9268 if not Restricted_Profile
then
9278 -- Except for the lock-free implementation, append the _Object field
9279 -- with the right type to the component list. We need to compute the
9280 -- number of entries, and in some cases the number of Attach_Handler
9283 if not Lock_Free_Active
then
9286 Num_Attach_Handler
: Int
:= 0;
9287 Protection_Subtype
: Node_Id
;
9288 Entry_Count_Expr
: constant Node_Id
:=
9289 Build_Entry_Count_Expression
9290 (Prot_Typ
, Cdecls
, Loc
);
9293 if Has_Attach_Handler
(Prot_Typ
) then
9294 Ritem
:= First_Rep_Item
(Prot_Typ
);
9295 while Present
(Ritem
) loop
9296 if Nkind
(Ritem
) = N_Pragma
9297 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9299 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9302 Next_Rep_Item
(Ritem
);
9306 -- Determine the proper protection type. There are two special
9307 -- cases: 1) when the protected type has dynamic interrupt
9308 -- handlers, and 2) when it has static handlers and we use a
9309 -- restricted profile.
9311 if Has_Attach_Handler
(Prot_Typ
)
9312 and then not Restricted_Profile
9314 Protection_Subtype
:=
9315 Make_Subtype_Indication
(Loc
,
9318 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9320 Make_Index_Or_Discriminant_Constraint
(Loc
,
9321 Constraints
=> New_List
(
9323 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9325 elsif Has_Interrupt_Handler
(Prot_Typ
)
9326 and then not Restriction_Active
(No_Dynamic_Attachment
)
9328 Protection_Subtype
:=
9329 Make_Subtype_Indication
(Loc
,
9332 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9334 Make_Index_Or_Discriminant_Constraint
(Loc
,
9335 Constraints
=> New_List
(Entry_Count_Expr
)));
9338 case Corresponding_Runtime_Package
(Prot_Typ
) is
9339 when System_Tasking_Protected_Objects_Entries
=>
9340 Protection_Subtype
:=
9341 Make_Subtype_Indication
(Loc
,
9344 (RTE
(RE_Protection_Entries
), Loc
),
9346 Make_Index_Or_Discriminant_Constraint
(Loc
,
9347 Constraints
=> New_List
(Entry_Count_Expr
)));
9349 when System_Tasking_Protected_Objects_Single_Entry
=>
9350 Protection_Subtype
:=
9351 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9353 when System_Tasking_Protected_Objects
=>
9354 Protection_Subtype
:=
9355 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9358 raise Program_Error
;
9363 Make_Component_Declaration
(Loc
,
9364 Defining_Identifier
=>
9365 Make_Defining_Identifier
(Loc
, Name_uObject
),
9366 Component_Definition
=>
9367 Make_Component_Definition
(Loc
,
9368 Aliased_Present
=> True,
9369 Subtype_Indication
=> Protection_Subtype
));
9372 -- Put the _Object component after the private component so that it
9373 -- be finalized early as required by 9.4 (20)
9375 Append_To
(Cdecls
, Object_Comp
);
9378 Insert_After
(Current_Node
, Rec_Decl
);
9379 Current_Node
:= Rec_Decl
;
9381 -- Analyze the record declaration immediately after construction,
9382 -- because the initialization procedure is needed for single object
9383 -- declarations before the next entity is analyzed (the freeze call
9384 -- that generates this initialization procedure is found below).
9386 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9388 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9389 -- the corresponding record is frozen. If any wrappers are generated,
9390 -- Current_Node is updated accordingly.
9392 if Ada_Version
>= Ada_2005
then
9393 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9396 -- Collect pointers to entry bodies and their barriers, to be placed
9397 -- in the Entry_Bodies_Array for the type. For each entry/family we
9398 -- add an expression to the aggregate which is the initial value of
9399 -- this array. The array is declared after all protected subprograms.
9401 if Has_Entries
(Prot_Typ
) then
9402 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9404 Entries_Aggr
:= Empty
;
9407 -- Build two new procedure specifications for each protected subprogram;
9408 -- one to call from outside the object and one to call from inside.
9409 -- Build a barrier function and an entry body action procedure
9410 -- specification for each protected entry. Initialize the entry body
9411 -- array. If subprogram is flagged as eliminated, do not generate any
9412 -- internal operations.
9415 Comp
:= First
(Visible_Declarations
(Pdef
));
9416 while Present
(Comp
) loop
9417 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9419 Make_Subprogram_Declaration
(Loc
,
9421 Build_Protected_Sub_Specification
9422 (Comp
, Prot_Typ
, Unprotected_Mode
));
9424 Insert_After
(Current_Node
, Sub
);
9427 Set_Protected_Body_Subprogram
9428 (Defining_Unit_Name
(Specification
(Comp
)),
9429 Defining_Unit_Name
(Specification
(Sub
)));
9430 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9432 -- Make the protected version of the subprogram available for
9433 -- expansion of external calls.
9435 Current_Node
:= Sub
;
9438 Make_Subprogram_Declaration
(Loc
,
9440 Build_Protected_Sub_Specification
9441 (Comp
, Prot_Typ
, Protected_Mode
));
9443 Insert_After
(Current_Node
, Sub
);
9446 Current_Node
:= Sub
;
9448 -- Generate an overriding primitive operation specification for
9449 -- this subprogram if the protected type implements an interface.
9451 if Ada_Version
>= Ada_2005
9453 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9456 Make_Subprogram_Declaration
(Loc
,
9458 Build_Protected_Sub_Specification
9459 (Comp
, Prot_Typ
, Dispatching_Mode
));
9461 Insert_After
(Current_Node
, Sub
);
9464 Current_Node
:= Sub
;
9467 -- If a pragma Interrupt_Handler applies, build and add a call to
9468 -- Register_Interrupt_Handler to the freezing actions of the
9469 -- protected version (Current_Node) of the subprogram:
9471 -- system.interrupts.register_interrupt_handler
9472 -- (prot_procP'address);
9474 if not Restricted_Profile
9475 and then Is_Interrupt_Handler
9476 (Defining_Unit_Name
(Specification
(Comp
)))
9481 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9483 Expand_Entry_Declaration
(Comp
);
9490 -- If there are some private entry declarations, expand it as if they
9491 -- were visible entries.
9493 if Present
(Private_Declarations
(Pdef
)) then
9494 Comp
:= First
(Private_Declarations
(Pdef
));
9495 while Present
(Comp
) loop
9496 if Nkind
(Comp
) = N_Entry_Declaration
then
9497 Expand_Entry_Declaration
(Comp
);
9504 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9505 -- all protected subprograms have been collected.
9507 if Has_Entries
(Prot_Typ
) then
9509 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9510 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9512 case Corresponding_Runtime_Package
(Prot_Typ
) is
9513 when System_Tasking_Protected_Objects_Entries
=>
9514 Body_Arr
:= Make_Object_Declaration
(Loc
,
9515 Defining_Identifier
=> Body_Id
,
9516 Aliased_Present
=> True,
9517 Object_Definition
=>
9518 Make_Subtype_Indication
(Loc
,
9519 Subtype_Mark
=> New_Occurrence_Of
(
9520 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9522 Make_Index_Or_Discriminant_Constraint
(Loc
,
9523 Constraints
=> New_List
(
9525 Make_Integer_Literal
(Loc
, 1),
9526 Make_Integer_Literal
(Loc
, E_Count
))))),
9527 Expression
=> Entries_Aggr
);
9529 when System_Tasking_Protected_Objects_Single_Entry
=>
9530 Body_Arr
:= Make_Object_Declaration
(Loc
,
9531 Defining_Identifier
=> Body_Id
,
9532 Aliased_Present
=> True,
9533 Object_Definition
=> New_Occurrence_Of
9534 (RTE
(RE_Entry_Body
), Loc
),
9535 Expression
=> Remove_Head
(Expressions
(Entries_Aggr
)));
9538 raise Program_Error
;
9541 -- A pointer to this array will be placed in the corresponding record
9542 -- by its initialization procedure so this needs to be analyzed here.
9544 Insert_After
(Current_Node
, Body_Arr
);
9545 Current_Node
:= Body_Arr
;
9548 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9550 -- Finally, build the function that maps an entry index into the
9551 -- corresponding body. A pointer to this function is placed in each
9552 -- object of the type. Except for a ravenscar-like profile (no abort,
9553 -- no entry queue, 1 entry)
9555 if Corresponding_Runtime_Package
(Prot_Typ
) =
9556 System_Tasking_Protected_Objects_Entries
9559 Make_Subprogram_Declaration
(Loc
,
9560 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9561 Insert_After
(Current_Node
, Sub
);
9565 end Expand_N_Protected_Type_Declaration
;
9567 --------------------------------
9568 -- Expand_N_Requeue_Statement --
9569 --------------------------------
9571 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9572 -- operations, depending on the source and destination (task or protected
9573 -- object). A dispatching requeue statement is expanded into a call to the
9574 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9575 -- jump around the remainder of processing for the original entry and, if
9576 -- the destination is (different) protected object, to attempt to service
9577 -- it. The following illustrates the various cases:
9580 -- (O : System.Address;
9581 -- P : System.Address;
9582 -- E : Protected_Entry_Index)
9584 -- <discriminant renamings>
9585 -- <private object renamings>
9586 -- type poVP is access poV;
9587 -- _object : ptVP := ptVP!(O);
9591 -- <start of statement sequence for entry>
9593 -- -- Requeue from one protected entry body to another protected
9596 -- Requeue_Protected_Entry (
9597 -- _object._object'Access,
9598 -- new._object'Access,
9603 -- <some more of the statement sequence for entry>
9605 -- -- Requeue from an entry body to a task entry
9607 -- Requeue_Protected_To_Task_Entry (
9613 -- <rest of statement sequence for entry>
9614 -- Complete_Entry_Body (_object._object);
9617 -- when all others =>
9618 -- Exceptional_Complete_Entry_Body (
9619 -- _object._object, Get_GNAT_Exception);
9623 -- Requeue of a task entry call to a task entry
9625 -- Accept_Call (E, Ann);
9626 -- <start of statement sequence for accept statement>
9627 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9629 -- <rest of statement sequence for accept statement>
9631 -- Complete_Rendezvous;
9634 -- when all others =>
9635 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9637 -- Requeue of a task entry call to a protected entry
9639 -- Accept_Call (E, Ann);
9640 -- <start of statement sequence for accept statement>
9641 -- Requeue_Task_To_Protected_Entry (
9642 -- new._object'Access,
9647 -- <rest of statement sequence for accept statement>
9649 -- Complete_Rendezvous;
9652 -- when all others =>
9653 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9655 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9656 -- marked by pragma Implemented (XXX, By_Entry).
9658 -- The requeue is inside a protected entry:
9661 -- (O : System.Address;
9662 -- P : System.Address;
9663 -- E : Protected_Entry_Index)
9665 -- <discriminant renamings>
9666 -- <private object renamings>
9667 -- type poVP is access poV;
9668 -- _object : ptVP := ptVP!(O);
9672 -- <start of statement sequence for entry>
9675 -- (<interface class-wide object>,
9678 -- Ada.Tags.Get_Offset_Index
9680 -- <interface dispatch table index of target entry>),
9684 -- <rest of statement sequence for entry>
9685 -- Complete_Entry_Body (_object._object);
9688 -- when all others =>
9689 -- Exceptional_Complete_Entry_Body (
9690 -- _object._object, Get_GNAT_Exception);
9694 -- The requeue is inside a task entry:
9696 -- Accept_Call (E, Ann);
9697 -- <start of statement sequence for accept statement>
9699 -- (<interface class-wide object>,
9702 -- Ada.Tags.Get_Offset_Index
9704 -- <interface dispatch table index of target entrt>),
9708 -- <rest of statement sequence for accept statement>
9710 -- Complete_Rendezvous;
9713 -- when all others =>
9714 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9716 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9717 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9718 -- statement is replaced by a dispatching call with actual parameters taken
9719 -- from the inner-most accept statement or entry body.
9721 -- Target.Primitive (Param1, ..., ParamN);
9723 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9724 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9728 -- S : constant Offset_Index :=
9729 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9730 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9733 -- if C = POK_Protected_Entry
9734 -- or else C = POK_Task_Entry
9736 -- <statements for dispatching requeue>
9738 -- elsif C = POK_Protected_Procedure then
9739 -- <dispatching call equivalent>
9742 -- raise Program_Error;
9746 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9747 Loc
: constant Source_Ptr
:= Sloc
(N
);
9748 Conc_Typ
: Entity_Id
;
9752 Old_Typ
: Entity_Id
;
9754 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9755 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9756 -- the form Concval.Ename. It is statically known that Ename is allowed
9757 -- to be implemented by a protected procedure. Create a dispatching call
9758 -- equivalent of Concval.Ename taking the actual parameters from the
9759 -- inner-most accept statement or entry body.
9761 function Build_Dispatching_Requeue
return Node_Id
;
9762 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9763 -- the form Concval.Ename. It is statically known that Ename is allowed
9764 -- to be implemented by a protected or a task entry. Create a call to
9765 -- primitive _Disp_Requeue which handles the low-level actions.
9767 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9768 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9769 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9770 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9771 -- determines at runtime whether Ename denotes an entry or a procedure
9772 -- and perform the appropriate kind of dispatching select.
9774 function Build_Normal_Requeue
return Node_Id
;
9775 -- N denotes a non-dispatching requeue statement to either a task or a
9776 -- protected entry. Build the appropriate runtime call to perform the
9779 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9780 -- For a protected entry, create a return statement to skip the rest of
9781 -- the entry body. Otherwise, create a goto statement to skip the rest
9782 -- of a task accept statement. The lookup for the enclosing entry body
9783 -- or accept statement starts from Search.
9785 ---------------------------------------
9786 -- Build_Dispatching_Call_Equivalent --
9787 ---------------------------------------
9789 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9790 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9791 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9798 -- Climb the parent chain looking for the inner-most entry body or
9799 -- accept statement.
9802 while Present
(Acc_Ent
)
9803 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9806 Acc_Ent
:= Parent
(Acc_Ent
);
9809 -- A requeue statement should be housed inside an entry body or an
9810 -- accept statement at some level. If this is not the case, then the
9811 -- tree is malformed.
9813 pragma Assert
(Present
(Acc_Ent
));
9815 -- Recover the list of formal parameters
9817 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9818 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9821 Formals
:= Parameter_Specifications
(Acc_Ent
);
9823 -- Create the actual parameters for the dispatching call. These are
9824 -- simply copies of the entry body or accept statement formals in the
9825 -- same order as they appear.
9829 if Present
(Formals
) then
9830 Actuals
:= New_List
;
9831 Formal
:= First
(Formals
);
9832 while Present
(Formal
) loop
9834 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9840 -- Obj.Call_Ent (Actuals);
9843 Make_Procedure_Call_Statement
(Loc
,
9845 Make_Selected_Component
(Loc
,
9846 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9847 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9849 Parameter_Associations
=> Actuals
);
9850 end Build_Dispatching_Call_Equivalent
;
9852 -------------------------------
9853 -- Build_Dispatching_Requeue --
9854 -------------------------------
9856 function Build_Dispatching_Requeue
return Node_Id
is
9857 Params
: constant List_Id
:= New_List
;
9860 -- Process the "with abort" parameter
9863 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9865 -- Process the entry wrapper's position in the primary dispatch
9866 -- table parameter. Generate:
9868 -- Ada.Tags.Get_Entry_Index
9869 -- (T => To_Tag_Ptr (Obj'Address).all,
9871 -- Ada.Tags.Get_Offset_Index
9872 -- (Ada.Tags.Tag (Concval),
9873 -- <interface dispatch table position of Ename>));
9875 -- Note that Obj'Address is recursively expanded into a call to
9876 -- Base_Address (Obj).
9878 if Tagged_Type_Expansion
then
9880 Make_Function_Call
(Loc
,
9881 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9882 Parameter_Associations
=> New_List
(
9884 Make_Explicit_Dereference
(Loc
,
9885 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9886 Make_Attribute_Reference
(Loc
,
9887 Prefix
=> New_Copy_Tree
(Concval
),
9888 Attribute_Name
=> Name_Address
))),
9890 Make_Function_Call
(Loc
,
9891 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9892 Parameter_Associations
=> New_List
(
9893 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9894 Make_Integer_Literal
(Loc
,
9895 DT_Position
(Entity
(Ename
))))))));
9901 Make_Function_Call
(Loc
,
9902 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9903 Parameter_Associations
=> New_List
(
9905 Make_Attribute_Reference
(Loc
,
9907 Attribute_Name
=> Name_Tag
),
9909 Make_Function_Call
(Loc
,
9910 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9912 Parameter_Associations
=> New_List
(
9916 Make_Attribute_Reference
(Loc
,
9918 Attribute_Name
=> Name_Tag
),
9922 Make_Attribute_Reference
(Loc
,
9923 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9924 Attribute_Name
=> Name_Tag
),
9928 Make_Integer_Literal
(Loc
,
9929 DT_Position
(Entity
(Ename
))))))));
9932 -- Specific actuals for protected to XXX requeue
9934 if Is_Protected_Type
(Old_Typ
) then
9936 Make_Attribute_Reference
(Loc
, -- _object'Address
9938 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9939 Attribute_Name
=> Name_Address
));
9941 Prepend_To
(Params
, -- True
9942 New_Occurrence_Of
(Standard_True
, Loc
));
9944 -- Specific actuals for task to XXX requeue
9947 pragma Assert
(Is_Task_Type
(Old_Typ
));
9949 Prepend_To
(Params
, -- null
9950 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
9952 Prepend_To
(Params
, -- False
9953 New_Occurrence_Of
(Standard_False
, Loc
));
9956 -- Add the object parameter
9958 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9961 -- _Disp_Requeue (<Params>);
9963 -- Find entity for Disp_Requeue operation, which belongs to
9964 -- the type and may not be directly visible.
9971 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9972 while Present
(Elmt
) loop
9974 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9979 Make_Procedure_Call_Statement
(Loc
,
9980 Name
=> New_Occurrence_Of
(Op
, Loc
),
9981 Parameter_Associations
=> Params
);
9983 end Build_Dispatching_Requeue
;
9985 --------------------------------------
9986 -- Build_Dispatching_Requeue_To_Any --
9987 --------------------------------------
9989 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9990 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9991 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9992 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
10002 -- Dispatch table slot processing, generate:
10005 S
:= Build_S
(Loc
, Decls
);
10007 -- Call kind processing, generate:
10008 -- C : Ada.Tags.Prim_Op_Kind;
10010 C
:= Build_C
(Loc
, Decls
);
10013 -- S := Ada.Tags.Get_Offset_Index
10014 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10016 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10019 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10022 Make_Procedure_Call_Statement
(Loc
,
10024 New_Occurrence_Of
(
10025 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10026 Name_uDisp_Get_Prim_Op_Kind
),
10028 Parameter_Associations
=> New_List
(
10029 New_Copy_Tree
(Obj
),
10030 New_Occurrence_Of
(S
, Loc
),
10031 New_Occurrence_Of
(C
, Loc
))));
10035 -- if C = POK_Protected_Entry
10036 -- or else C = POK_Task_Entry
10039 Make_Implicit_If_Statement
(N
,
10045 New_Occurrence_Of
(C
, Loc
),
10047 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10052 New_Occurrence_Of
(C
, Loc
),
10054 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10056 -- Dispatching requeue equivalent
10058 Then_Statements
=> New_List
(
10059 Build_Dispatching_Requeue
,
10062 -- elsif C = POK_Protected_Procedure then
10064 Elsif_Parts
=> New_List
(
10065 Make_Elsif_Part
(Loc
,
10069 New_Occurrence_Of
(C
, Loc
),
10071 New_Occurrence_Of
(
10072 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10074 -- Dispatching call equivalent
10076 Then_Statements
=> New_List
(
10077 Build_Dispatching_Call_Equivalent
))),
10080 -- raise Program_Error;
10083 Else_Statements
=> New_List
(
10084 Make_Raise_Program_Error
(Loc
,
10085 Reason
=> PE_Explicit_Raise
))));
10087 -- Wrap everything into a block
10090 Make_Block_Statement
(Loc
,
10091 Declarations
=> Decls
,
10092 Handled_Statement_Sequence
=>
10093 Make_Handled_Sequence_Of_Statements
(Loc
,
10094 Statements
=> Stmts
));
10095 end Build_Dispatching_Requeue_To_Any
;
10097 --------------------------
10098 -- Build_Normal_Requeue --
10099 --------------------------
10101 function Build_Normal_Requeue
return Node_Id
is
10102 Params
: constant List_Id
:= New_List
;
10107 -- Process the "with abort" parameter
10109 Prepend_To
(Params
,
10110 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10112 -- Add the index expression to the parameters. It is common among all
10115 Prepend_To
(Params
,
10116 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10118 if Is_Protected_Type
(Old_Typ
) then
10120 Self_Param
: Node_Id
;
10124 Make_Attribute_Reference
(Loc
,
10126 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10128 Name_Unchecked_Access
);
10130 -- Protected to protected requeue
10132 if Is_Protected_Type
(Conc_Typ
) then
10134 New_Occurrence_Of
(
10135 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10138 Make_Attribute_Reference
(Loc
,
10140 Concurrent_Ref
(Concval
),
10142 Name_Unchecked_Access
);
10144 -- Protected to task requeue
10146 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10148 New_Occurrence_Of
(
10149 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10151 Param
:= Concurrent_Ref
(Concval
);
10154 Prepend_To
(Params
, Param
);
10155 Prepend_To
(Params
, Self_Param
);
10158 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10160 -- Task to protected requeue
10162 if Is_Protected_Type
(Conc_Typ
) then
10164 New_Occurrence_Of
(
10165 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10168 Make_Attribute_Reference
(Loc
,
10170 Concurrent_Ref
(Concval
),
10172 Name_Unchecked_Access
);
10174 -- Task to task requeue
10176 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10178 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10180 Param
:= Concurrent_Ref
(Concval
);
10183 Prepend_To
(Params
, Param
);
10187 Make_Procedure_Call_Statement
(Loc
,
10189 Parameter_Associations
=> Params
);
10190 end Build_Normal_Requeue
;
10192 --------------------------
10193 -- Build_Skip_Statement --
10194 --------------------------
10196 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10197 Skip_Stmt
: Node_Id
;
10200 -- Build a return statement to skip the rest of the entire body
10202 if Is_Protected_Type
(Old_Typ
) then
10203 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10205 -- If the requeue is within a task, find the end label of the
10206 -- enclosing accept statement and create a goto statement to it.
10214 -- Climb the parent chain looking for the enclosing accept
10217 Acc
:= Parent
(Search
);
10218 while Present
(Acc
)
10219 and then Nkind
(Acc
) /= N_Accept_Statement
10221 Acc
:= Parent
(Acc
);
10224 -- The last statement is the second label used for completing
10225 -- the rendezvous the usual way. The label we are looking for
10226 -- is right before it.
10229 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10231 pragma Assert
(Nkind
(Label
) = N_Label
);
10233 -- Generate a goto statement to skip the rest of the accept
10236 Make_Goto_Statement
(Loc
,
10238 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10242 Set_Analyzed
(Skip_Stmt
);
10245 end Build_Skip_Statement
;
10247 -- Start of processing for Expand_N_Requeue_Statement
10250 -- Extract the components of the entry call
10252 Extract_Entry
(N
, Concval
, Ename
, Index
);
10253 Conc_Typ
:= Etype
(Concval
);
10255 -- If the prefix is an access to class-wide type, dereference to get
10256 -- object and entry type.
10258 if Is_Access_Type
(Conc_Typ
) then
10259 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10261 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10262 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10265 -- Examine the scope stack in order to find nearest enclosing protected
10266 -- or task type. This will constitute our invocation source.
10268 Old_Typ
:= Current_Scope
;
10269 while Present
(Old_Typ
)
10270 and then not Is_Protected_Type
(Old_Typ
)
10271 and then not Is_Task_Type
(Old_Typ
)
10273 Old_Typ
:= Scope
(Old_Typ
);
10276 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10277 -- Concval.Ename where the type of Concval is class-wide concurrent
10280 if Ada_Version
>= Ada_2012
10281 and then Present
(Concval
)
10282 and then Is_Class_Wide_Type
(Conc_Typ
)
10283 and then Is_Concurrent_Interface
(Conc_Typ
)
10286 Has_Impl
: Boolean := False;
10287 Impl_Kind
: Name_Id
:= No_Name
;
10290 -- Check whether the Ename is flagged by pragma Implemented
10292 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10294 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10297 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10298 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10301 and then Impl_Kind
= Name_By_Entry
10303 Rewrite
(N
, Build_Dispatching_Requeue
);
10305 Insert_After
(N
, Build_Skip_Statement
(N
));
10307 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10308 -- a protected procedure. In this case the requeue is transformed
10309 -- into a dispatching call.
10312 and then Impl_Kind
= Name_By_Protected_Procedure
10314 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10317 -- The procedure_or_entry_NAME's implementation kind is either
10318 -- By_Any, Optional, or pragma Implemented was not applied at all.
10319 -- In this case a runtime test determines whether Ename denotes an
10320 -- entry or a protected procedure and performs the appropriate
10324 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10329 -- Processing for regular (non-dispatching) requeues
10332 Rewrite
(N
, Build_Normal_Requeue
);
10334 Insert_After
(N
, Build_Skip_Statement
(N
));
10336 end Expand_N_Requeue_Statement
;
10338 -------------------------------
10339 -- Expand_N_Selective_Accept --
10340 -------------------------------
10342 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10343 Loc
: constant Source_Ptr
:= Sloc
(N
);
10344 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10346 -- Note: in the below declarations a lot of new lists are allocated
10347 -- unconditionally which may well not end up being used. That's not
10348 -- a good idea since it wastes space gratuitously ???
10350 Accept_Case
: List_Id
;
10351 Accept_List
: constant List_Id
:= New_List
;
10354 Alt_List
: constant List_Id
:= New_List
;
10355 Alt_Stats
: List_Id
;
10356 Ann
: Entity_Id
:= Empty
;
10358 Check_Guard
: Boolean := True;
10360 Decls
: constant List_Id
:= New_List
;
10361 Stats
: constant List_Id
:= New_List
;
10362 Body_List
: constant List_Id
:= New_List
;
10363 Trailing_List
: constant List_Id
:= New_List
;
10366 Else_Present
: Boolean := False;
10367 Terminate_Alt
: Node_Id
:= Empty
;
10368 Select_Mode
: Node_Id
;
10370 Delay_Case
: List_Id
;
10371 Delay_Count
: Integer := 0;
10372 Delay_Val
: Entity_Id
;
10373 Delay_Index
: Entity_Id
;
10374 Delay_Min
: Entity_Id
;
10375 Delay_Num
: Int
:= 1;
10376 Delay_Alt_List
: List_Id
:= New_List
;
10377 Delay_List
: constant List_Id
:= New_List
;
10381 First_Delay
: Boolean := True;
10382 Guard_Open
: Entity_Id
;
10388 Num_Accept
: Nat
:= 0;
10390 Time_Type
: Entity_Id
;
10391 Select_Call
: Node_Id
;
10393 Qnam
: constant Entity_Id
:=
10394 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10396 Xnam
: constant Entity_Id
:=
10397 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10399 -----------------------
10400 -- Local subprograms --
10401 -----------------------
10403 function Accept_Or_Raise
return List_Id
;
10404 -- For the rare case where delay alternatives all have guards, and
10405 -- all of them are closed, it is still possible that there were open
10406 -- accept alternatives with no callers. We must reexamine the
10407 -- Accept_List, and execute a selective wait with no else if some
10408 -- accept is open. If none, we raise program_error.
10410 procedure Add_Accept
(Alt
: Node_Id
);
10411 -- Process a single accept statement in a select alternative. Build
10412 -- procedure for body of accept, and add entry to dispatch table with
10413 -- expression for guard, in preparation for call to run time select.
10415 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10416 -- Manufacture a label using Num as a serial number and declare it.
10417 -- The declaration is appended to Decls. The label marks the trailing
10418 -- statements of an accept or delay alternative.
10420 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10421 -- Build call to Selective_Wait runtime routine
10423 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10424 -- Add code to compare value of delay with previous values, and
10425 -- generate case entry for trailing statements.
10427 procedure Process_Accept_Alternative
10431 -- Add code to call corresponding procedure, and branch to
10432 -- trailing statements, if any.
10434 ---------------------
10435 -- Accept_Or_Raise --
10436 ---------------------
10438 function Accept_Or_Raise
return List_Id
is
10441 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10444 -- We generate the following:
10446 -- for J in q'range loop
10447 -- if q(J).S /=null_task_entry then
10448 -- selective_wait (simple_mode,...);
10454 -- if no rendez_vous then
10455 -- raise program_error;
10458 -- Note that the code needs to know that the selector name
10459 -- in an Accept_Alternative is named S.
10461 Cond
:= Make_Op_Ne
(Loc
,
10463 Make_Selected_Component
(Loc
,
10465 Make_Indexed_Component
(Loc
,
10466 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10467 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10468 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10470 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10472 Stats
:= New_List
(
10473 Make_Implicit_Loop_Statement
(N
,
10474 Iteration_Scheme
=>
10475 Make_Iteration_Scheme
(Loc
,
10476 Loop_Parameter_Specification
=>
10477 Make_Loop_Parameter_Specification
(Loc
,
10478 Defining_Identifier
=> J
,
10479 Discrete_Subtype_Definition
=>
10480 Make_Attribute_Reference
(Loc
,
10481 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10482 Attribute_Name
=> Name_Range
,
10483 Expressions
=> New_List
(
10484 Make_Integer_Literal
(Loc
, 1))))),
10486 Statements
=> New_List
(
10487 Make_Implicit_If_Statement
(N
,
10489 Then_Statements
=> New_List
(
10491 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10492 Make_Exit_Statement
(Loc
))))));
10495 Make_Raise_Program_Error
(Loc
,
10496 Condition
=> Make_Op_Eq
(Loc
,
10497 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10499 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10500 Reason
=> PE_All_Guards_Closed
));
10503 end Accept_Or_Raise
;
10509 procedure Add_Accept
(Alt
: Node_Id
) is
10510 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10511 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10512 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10513 Eent
: constant Entity_Id
:= Entity
(Ename
);
10514 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10515 Null_Body
: Node_Id
;
10516 Proc_Body
: Node_Id
;
10517 PB_Ent
: Entity_Id
;
10523 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10526 if Present
(Condition
(Alt
)) then
10528 Make_If_Expression
(Eloc
, New_List
(
10530 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10531 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10534 Entry_Index_Expression
10535 (Eloc
, Eent
, Index
, Scope
(Eent
));
10538 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10539 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10541 -- Always add call to Abort_Undefer when generating code, since
10542 -- this is what the runtime expects (abort deferred in
10543 -- Selective_Wait). In CodePeer mode this only confuses the
10544 -- analysis with unknown calls, so don't do it.
10546 if not CodePeer_Mode
then
10548 Make_Procedure_Call_Statement
(Eloc
,
10549 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Undefer
), Eloc
));
10551 (First
(Statements
(Handled_Statement_Sequence
10552 (Accept_Statement
(Alt
)))),
10558 Make_Defining_Identifier
(Eloc
,
10559 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10561 if Comes_From_Source
(Alt
) then
10562 Set_Debug_Info_Needed
(PB_Ent
);
10566 Make_Subprogram_Body
(Eloc
,
10568 Make_Procedure_Specification
(Eloc
,
10569 Defining_Unit_Name
=> PB_Ent
),
10570 Declarations
=> Declarations
(Acc_Stm
),
10571 Handled_Statement_Sequence
=>
10572 Build_Accept_Body
(Accept_Statement
(Alt
)));
10574 -- During the analysis of the body of the accept statement, any
10575 -- zero cost exception handler records were collected in the
10576 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10577 -- This is where we move them to where they belong, namely the
10578 -- newly created procedure.
10580 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10581 Append
(Proc_Body
, Body_List
);
10584 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10586 -- if accept statement has declarations, insert above, given that
10587 -- we are not creating a body for the accept.
10589 if Present
(Declarations
(Acc_Stm
)) then
10590 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10594 Append_To
(Accept_List
,
10595 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10597 Num_Accept
:= Num_Accept
+ 1;
10600 ----------------------------
10601 -- Make_And_Declare_Label --
10602 ----------------------------
10604 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10608 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10610 Make_Label
(Loc
, Lab_Id
);
10613 Make_Implicit_Label_Declaration
(Loc
,
10614 Defining_Identifier
=>
10615 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10616 Label_Construct
=> Lab
));
10619 end Make_And_Declare_Label
;
10621 ----------------------
10622 -- Make_Select_Call --
10623 ----------------------
10625 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10626 Params
: constant List_Id
:= New_List
;
10630 Make_Attribute_Reference
(Loc
,
10631 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10632 Attribute_Name
=> Name_Unchecked_Access
));
10633 Append_To
(Params
, Select_Mode
);
10634 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10635 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10638 Make_Procedure_Call_Statement
(Loc
,
10639 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10640 Parameter_Associations
=> Params
);
10641 end Make_Select_Call
;
10643 --------------------------------
10644 -- Process_Accept_Alternative --
10645 --------------------------------
10647 procedure Process_Accept_Alternative
10652 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10653 Alt_Stats
: List_Id
;
10656 Adjust_Condition
(Condition
(Alt
));
10658 -- Accept with body
10660 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10663 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10666 (Defining_Unit_Name
(Specification
(Proc
)),
10669 -- Accept with no body (followed by trailing statements)
10672 Alt_Stats
:= Empty_List
;
10675 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10677 -- After the call, if any, branch to trailing statements, if any.
10678 -- We create a label for each, as well as the corresponding label
10681 if not Is_Empty_List
(Statements
(Alt
)) then
10682 Lab
:= Make_And_Declare_Label
(Index
);
10683 Append
(Lab
, Trailing_List
);
10684 Append_List
(Statements
(Alt
), Trailing_List
);
10685 Append_To
(Trailing_List
,
10686 Make_Goto_Statement
(Loc
,
10687 Name
=> New_Copy
(Identifier
(End_Lab
))));
10693 Append_To
(Alt_Stats
,
10694 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10696 Append_To
(Alt_List
,
10697 Make_Case_Statement_Alternative
(Loc
,
10698 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10699 Statements
=> Alt_Stats
));
10700 end Process_Accept_Alternative
;
10702 -------------------------------
10703 -- Process_Delay_Alternative --
10704 -------------------------------
10706 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10707 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10709 Delay_Alt
: List_Id
;
10712 -- Deal with C/Fortran boolean as delay condition
10714 Adjust_Condition
(Condition
(Alt
));
10716 -- Determine the smallest specified delay
10718 -- for each delay alternative generate:
10720 -- if guard-expression then
10721 -- Delay_Val := delay-expression;
10722 -- Guard_Open := True;
10723 -- if Delay_Val < Delay_Min then
10724 -- Delay_Min := Delay_Val;
10725 -- Delay_Index := Index;
10729 -- The enclosing if-statement is omitted if there is no guard
10731 if Delay_Count
= 1 or else First_Delay
then
10732 First_Delay
:= False;
10734 Delay_Alt
:= New_List
(
10735 Make_Assignment_Statement
(Loc
,
10736 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10737 Expression
=> Expression
(Delay_Statement
(Alt
))));
10739 if Delay_Count
> 1 then
10740 Append_To
(Delay_Alt
,
10741 Make_Assignment_Statement
(Loc
,
10742 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10743 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10747 Delay_Alt
:= New_List
(
10748 Make_Assignment_Statement
(Loc
,
10749 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10750 Expression
=> Expression
(Delay_Statement
(Alt
))));
10752 if Time_Type
= Standard_Duration
then
10755 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10756 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10759 -- The scope of the time type must define a comparison
10760 -- operator. The scope itself may not be visible, so we
10761 -- construct a node with entity information to insure that
10762 -- semantic analysis can find the proper operator.
10765 Make_Function_Call
(Loc
,
10766 Name
=> Make_Selected_Component
(Loc
,
10768 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10770 Make_Operator_Symbol
(Loc
,
10771 Chars
=> Name_Op_Lt
,
10772 Strval
=> No_String
)),
10773 Parameter_Associations
=>
10775 New_Occurrence_Of
(Delay_Val
, Loc
),
10776 New_Occurrence_Of
(Delay_Min
, Loc
)));
10778 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10781 Append_To
(Delay_Alt
,
10782 Make_Implicit_If_Statement
(N
,
10784 Then_Statements
=> New_List
(
10785 Make_Assignment_Statement
(Loc
,
10786 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10787 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10789 Make_Assignment_Statement
(Loc
,
10790 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10791 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10794 if Check_Guard
then
10795 Append_To
(Delay_Alt
,
10796 Make_Assignment_Statement
(Loc
,
10797 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10798 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10801 if Present
(Condition
(Alt
)) then
10802 Delay_Alt
:= New_List
(
10803 Make_Implicit_If_Statement
(N
,
10804 Condition
=> Condition
(Alt
),
10805 Then_Statements
=> Delay_Alt
));
10808 Append_List
(Delay_Alt
, Delay_List
);
10810 Ensure_Statement_Present
(Dloc
, Alt
);
10812 -- If the delay alternative has a statement part, add choice to the
10813 -- case statements for delays.
10815 if not Is_Empty_List
(Statements
(Alt
)) then
10817 if Delay_Count
= 1 then
10818 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10821 Append_To
(Delay_Alt_List
,
10822 Make_Case_Statement_Alternative
(Loc
,
10823 Discrete_Choices
=> New_List
(
10824 Make_Integer_Literal
(Loc
, Index
)),
10825 Statements
=> Statements
(Alt
)));
10828 elsif Delay_Count
= 1 then
10830 -- If the single delay has no trailing statements, add a branch
10831 -- to the exit label to the selective wait.
10833 Delay_Alt_List
:= New_List
(
10834 Make_Goto_Statement
(Loc
,
10835 Name
=> New_Copy
(Identifier
(End_Lab
))));
10838 end Process_Delay_Alternative
;
10840 -- Start of processing for Expand_N_Selective_Accept
10843 Process_Statements_For_Controlled_Objects
(N
);
10845 -- First insert some declarations before the select. The first is:
10849 -- This variable holds the parameters passed to the accept body. This
10850 -- declaration has already been inserted by the time we get here by
10851 -- a call to Expand_Accept_Declarations made from the semantics when
10852 -- processing the first accept statement contained in the select. We
10853 -- can find this entity as Accept_Address (E), where E is any of the
10854 -- entries references by contained accept statements.
10856 -- The first step is to scan the list of Selective_Accept_Statements
10857 -- to find this entity, and also count the number of accepts, and
10858 -- determine if terminated, delay or else is present:
10862 Alt
:= First
(Alts
);
10863 while Present
(Alt
) loop
10864 Process_Statements_For_Controlled_Objects
(Alt
);
10866 if Nkind
(Alt
) = N_Accept_Alternative
then
10869 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10870 Delay_Count
:= Delay_Count
+ 1;
10872 -- If the delays are relative delays, the delay expressions have
10873 -- type Standard_Duration. Otherwise they must have some time type
10874 -- recognized by GNAT.
10876 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10877 Time_Type
:= Standard_Duration
;
10879 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10881 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10882 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10887 "& is not a time type (RM 9.6(6))",
10888 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10889 Time_Type
:= Standard_Duration
;
10890 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10894 if No
(Condition
(Alt
)) then
10896 -- This guard will always be open
10898 Check_Guard
:= False;
10901 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10902 Adjust_Condition
(Condition
(Alt
));
10903 Terminate_Alt
:= Alt
;
10906 Num_Alts
:= Num_Alts
+ 1;
10910 Else_Present
:= Present
(Else_Statements
(N
));
10912 -- At the same time (see procedure Add_Accept) we build the accept list:
10914 -- Qnn : Accept_List (1 .. num-select) := (
10915 -- (null-body, entry-index),
10916 -- (null-body, entry-index),
10918 -- (null_body, entry-index));
10920 -- In the above declaration, null-body is True if the corresponding
10921 -- accept has no body, and false otherwise. The entry is either the
10922 -- entry index expression if there is no guard, or if a guard is
10923 -- present, then an if expression of the form:
10925 -- (if guard then entry-index else Null_Task_Entry)
10927 -- If a guard is statically known to be false, the entry can simply
10928 -- be omitted from the accept list.
10931 Make_Object_Declaration
(Loc
,
10932 Defining_Identifier
=> Qnam
,
10933 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10934 Aliased_Present
=> True,
10936 Make_Qualified_Expression
(Loc
,
10938 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
10940 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10942 -- Then we declare the variable that holds the index for the accept
10943 -- that will be selected for service:
10945 -- Xnn : Select_Index;
10948 Make_Object_Declaration
(Loc
,
10949 Defining_Identifier
=> Xnam
,
10950 Object_Definition
=>
10951 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
10953 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
10955 -- After this follow procedure declarations for each accept body
10957 -- procedure Pnn is
10962 -- where the ... are statements from the corresponding procedure body.
10963 -- No parameters are involved, since the parameters are passed via Ann
10964 -- and the parameter references have already been expanded to be direct
10965 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10966 -- any embedded tasking statements (which would normally be illegal in
10967 -- procedures), have been converted to calls to the tasking runtime so
10968 -- there is no problem in putting them into procedures.
10970 -- The original accept statement has been expanded into a block in
10971 -- the same fashion as for simple accepts (see Build_Accept_Body).
10973 -- Note: we don't really need to build these procedures for the case
10974 -- where no delay statement is present, but it is just as easy to
10975 -- build them unconditionally, and not significantly inefficient,
10976 -- since if they are short they will be inlined anyway.
10978 -- The procedure declarations have been assembled in Body_List
10980 -- If delays are present, we must compute the required delay.
10981 -- We first generate the declarations:
10983 -- Delay_Index : Boolean := 0;
10984 -- Delay_Min : Some_Time_Type.Time;
10985 -- Delay_Val : Some_Time_Type.Time;
10987 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10988 -- active delay that is actually chosen as the basis for the possible
10989 -- delay if an immediate rendez-vous is not possible.
10991 -- In the most common case there is a single delay statement, and this
10992 -- is handled specially.
10994 if Delay_Count
> 0 then
10996 -- Generate the required declarations
10999 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
11001 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
11003 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
11006 Make_Object_Declaration
(Loc
,
11007 Defining_Identifier
=> Delay_Val
,
11008 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
11011 Make_Object_Declaration
(Loc
,
11012 Defining_Identifier
=> Delay_Index
,
11013 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11014 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11017 Make_Object_Declaration
(Loc
,
11018 Defining_Identifier
=> Delay_Min
,
11019 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11021 Unchecked_Convert_To
(Time_Type
,
11022 Make_Attribute_Reference
(Loc
,
11024 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11025 Attribute_Name
=> Name_Last
))));
11027 -- Create Duration and Delay_Mode objects used for passing a delay
11030 D
:= Make_Temporary
(Loc
, 'D');
11031 M
:= Make_Temporary
(Loc
, 'M');
11037 -- Note that these values are defined in s-osprim.ads and must
11038 -- be kept in sync:
11040 -- Relative : constant := 0;
11041 -- Absolute_Calendar : constant := 1;
11042 -- Absolute_RT : constant := 2;
11044 if Time_Type
= Standard_Duration
then
11045 Discr
:= Make_Integer_Literal
(Loc
, 0);
11047 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11048 Discr
:= Make_Integer_Literal
(Loc
, 1);
11052 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11053 Discr
:= Make_Integer_Literal
(Loc
, 2);
11057 Make_Object_Declaration
(Loc
,
11058 Defining_Identifier
=> D
,
11059 Object_Definition
=>
11060 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11063 Make_Object_Declaration
(Loc
,
11064 Defining_Identifier
=> M
,
11065 Object_Definition
=>
11066 New_Occurrence_Of
(Standard_Integer
, Loc
),
11067 Expression
=> Discr
));
11070 if Check_Guard
then
11072 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11075 Make_Object_Declaration
(Loc
,
11076 Defining_Identifier
=> Guard_Open
,
11077 Object_Definition
=>
11078 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11080 New_Occurrence_Of
(Standard_False
, Loc
)));
11083 -- Delay_Count is zero, don't need M and D set (suppress warning)
11090 if Present
(Terminate_Alt
) then
11092 -- If the terminate alternative guard is False, use
11093 -- Simple_Mode; otherwise use Terminate_Mode.
11095 if Present
(Condition
(Terminate_Alt
)) then
11096 Select_Mode
:= Make_If_Expression
(Loc
,
11097 New_List
(Condition
(Terminate_Alt
),
11098 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11099 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11101 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11104 elsif Else_Present
or Delay_Count
> 0 then
11105 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11108 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11111 Select_Call
:= Make_Select_Call
(Select_Mode
);
11112 Append
(Select_Call
, Stats
);
11114 -- Now generate code to act on the result. There is an entry
11115 -- in this case for each accept statement with a non-null body,
11116 -- followed by a branch to the statements that follow the Accept.
11117 -- In the absence of delay alternatives, we generate:
11120 -- when No_Rendezvous => -- omitted if simple mode
11135 -- Lab0: Else_Statements;
11138 -- Lab1: Trailing_Statements1;
11141 -- Lab2: Trailing_Statements2;
11146 -- Generate label for common exit
11148 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11150 -- First entry is the default case, when no rendezvous is possible
11152 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11154 if Else_Present
then
11156 -- If no rendezvous is possible, the else part is executed
11158 Lab
:= Make_And_Declare_Label
(0);
11159 Alt_Stats
:= New_List
(
11160 Make_Goto_Statement
(Loc
,
11161 Name
=> New_Copy
(Identifier
(Lab
))));
11163 Append
(Lab
, Trailing_List
);
11164 Append_List
(Else_Statements
(N
), Trailing_List
);
11165 Append_To
(Trailing_List
,
11166 Make_Goto_Statement
(Loc
,
11167 Name
=> New_Copy
(Identifier
(End_Lab
))));
11169 Alt_Stats
:= New_List
(
11170 Make_Goto_Statement
(Loc
,
11171 Name
=> New_Copy
(Identifier
(End_Lab
))));
11174 Append_To
(Alt_List
,
11175 Make_Case_Statement_Alternative
(Loc
,
11176 Discrete_Choices
=> Choices
,
11177 Statements
=> Alt_Stats
));
11179 -- We make use of the fact that Accept_Index is an integer type, and
11180 -- generate successive literals for entries for each accept. Only those
11181 -- for which there is a body or trailing statements get a case entry.
11183 Alt
:= First
(Select_Alternatives
(N
));
11184 Proc
:= First
(Body_List
);
11185 while Present
(Alt
) loop
11187 if Nkind
(Alt
) = N_Accept_Alternative
then
11188 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11189 Index
:= Index
+ 1;
11192 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11197 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11198 Process_Delay_Alternative
(Alt
, Delay_Num
);
11199 Delay_Num
:= Delay_Num
+ 1;
11205 -- An others choice is always added to the main case, as well
11206 -- as the delay case (to satisfy the compiler).
11208 Append_To
(Alt_List
,
11209 Make_Case_Statement_Alternative
(Loc
,
11210 Discrete_Choices
=>
11211 New_List
(Make_Others_Choice
(Loc
)),
11213 New_List
(Make_Goto_Statement
(Loc
,
11214 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11216 Accept_Case
:= New_List
(
11217 Make_Case_Statement
(Loc
,
11218 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11219 Alternatives
=> Alt_List
));
11221 Append_List
(Trailing_List
, Accept_Case
);
11222 Append_List
(Body_List
, Decls
);
11224 -- Construct case statement for trailing statements of delay
11225 -- alternatives, if there are several of them.
11227 if Delay_Count
> 1 then
11228 Append_To
(Delay_Alt_List
,
11229 Make_Case_Statement_Alternative
(Loc
,
11230 Discrete_Choices
=>
11231 New_List
(Make_Others_Choice
(Loc
)),
11233 New_List
(Make_Null_Statement
(Loc
))));
11235 Delay_Case
:= New_List
(
11236 Make_Case_Statement
(Loc
,
11237 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11238 Alternatives
=> Delay_Alt_List
));
11240 Delay_Case
:= Delay_Alt_List
;
11243 -- If there are no delay alternatives, we append the case statement
11244 -- to the statement list.
11246 if Delay_Count
= 0 then
11247 Append_List
(Accept_Case
, Stats
);
11249 -- Delay alternatives present
11252 -- If delay alternatives are present we generate:
11254 -- find minimum delay.
11255 -- DX := minimum delay;
11256 -- M := <delay mode>;
11257 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11260 -- if X = No_Rendezvous then
11261 -- case statement for delay statements.
11263 -- case statement for accept alternatives.
11274 -- The type of the delay expression is known to be legal
11276 if Time_Type
= Standard_Duration
then
11277 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11279 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11280 Conv
:= Make_Function_Call
(Loc
,
11281 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11282 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11286 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11288 Conv
:= Make_Function_Call
(Loc
,
11289 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11290 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11293 Stmt
:= Make_Assignment_Statement
(Loc
,
11294 Name
=> New_Occurrence_Of
(D
, Loc
),
11295 Expression
=> Conv
);
11297 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11299 Parms
:= Parameter_Associations
(Select_Call
);
11300 Parm
:= First
(Parms
);
11302 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11306 pragma Assert
(Present
(Parm
));
11307 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11310 -- Prepare two new parameters of Duration and Delay_Mode type
11311 -- which represent the value and the mode of the minimum delay.
11314 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11315 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11317 -- Create a call to RTS
11319 Rewrite
(Select_Call
,
11320 Make_Procedure_Call_Statement
(Loc
,
11321 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11322 Parameter_Associations
=> Parms
));
11324 -- This new call should follow the calculation of the minimum
11327 Insert_List_Before
(Select_Call
, Delay_List
);
11329 if Check_Guard
then
11331 Make_Implicit_If_Statement
(N
,
11332 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11333 Then_Statements
=> New_List
(
11334 New_Copy_Tree
(Stmt
),
11335 New_Copy_Tree
(Select_Call
)),
11336 Else_Statements
=> Accept_Or_Raise
);
11337 Rewrite
(Select_Call
, Stmt
);
11339 Insert_Before
(Select_Call
, Stmt
);
11343 Make_Implicit_If_Statement
(N
,
11344 Condition
=> Make_Op_Eq
(Loc
,
11345 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11347 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11349 Then_Statements
=> Delay_Case
,
11350 Else_Statements
=> Accept_Case
);
11352 Append
(Cases
, Stats
);
11356 Append
(End_Lab
, Stats
);
11358 -- Replace accept statement with appropriate block
11361 Make_Block_Statement
(Loc
,
11362 Declarations
=> Decls
,
11363 Handled_Statement_Sequence
=>
11364 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11367 -- Note: have to worry more about abort deferral in above code ???
11369 -- Final step is to unstack the Accept_Address entries for all accept
11370 -- statements appearing in accept alternatives in the select statement
11372 Alt
:= First
(Alts
);
11373 while Present
(Alt
) loop
11374 if Nkind
(Alt
) = N_Accept_Alternative
then
11375 Remove_Last_Elmt
(Accept_Address
11376 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11381 end Expand_N_Selective_Accept
;
11383 --------------------------------------
11384 -- Expand_N_Single_Task_Declaration --
11385 --------------------------------------
11387 -- Single task declarations should never be present after semantic
11388 -- analysis, since we expect them to be replaced by a declaration of an
11389 -- anonymous task type, followed by a declaration of the task object. We
11390 -- include this routine to make sure that is happening.
11392 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11394 raise Program_Error
;
11395 end Expand_N_Single_Task_Declaration
;
11397 ------------------------
11398 -- Expand_N_Task_Body --
11399 ------------------------
11401 -- Given a task body
11403 -- task body tname is
11409 -- This expansion routine converts it into a procedure and sets the
11410 -- elaboration flag for the procedure to true, to represent the fact
11411 -- that the task body is now elaborated:
11413 -- procedure tnameB (_Task : access tnameV) is
11414 -- discriminal : dtype renames _Task.discriminant;
11416 -- procedure _clean is
11418 -- Abort_Defer.all;
11420 -- Abort_Undefer.all;
11425 -- Abort_Undefer.all;
11427 -- System.Task_Stages.Complete_Activation;
11435 -- In addition, if the task body is an activator, then a call to activate
11436 -- tasks is added at the start of the statements, before the call to
11437 -- Complete_Activation, and if in addition the task is a master then it
11438 -- must be established as a master. These calls are inserted and analyzed
11439 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11442 -- There is one discriminal declaration line generated for each
11443 -- discriminant that is present to provide an easy reference point for
11444 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11446 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11447 -- task body procedures have a profile (Arg : System.Address). That is
11448 -- needed because GNARLI has to use the same access-to-subprogram type
11449 -- for all task types. We depend here on knowing that in GNAT, passing
11450 -- an address argument by value is identical to passing a record value
11451 -- by access (in either case a single pointer is passed), so even though
11452 -- this procedure has the wrong profile. In fact it's all OK, since the
11453 -- callings sequence is identical.
11455 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11456 Loc
: constant Source_Ptr
:= Sloc
(N
);
11457 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11461 Insert_Nod
: Node_Id
;
11462 -- Used to determine the proper location of wrapper body insertions
11465 -- Add renaming declarations for discriminals and a declaration for the
11466 -- entry family index (if applicable).
11468 Install_Private_Data_Declarations
11469 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11471 -- Add a call to Abort_Undefer at the very beginning of the task
11472 -- body since this body is called with abort still deferred.
11474 if Abort_Allowed
then
11475 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11477 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11481 -- The statement part has already been protected with an at_end and
11482 -- cleanup actions. The call to Complete_Activation must be placed
11483 -- at the head of the sequence of statements of that block. The
11484 -- declarations have been merged in this sequence of statements but
11485 -- the first real statement is accessible from the First_Real_Statement
11486 -- field (which was set for exactly this purpose).
11488 if Restricted_Profile
then
11489 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11491 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11495 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11499 Make_Subprogram_Body
(Loc
,
11500 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11501 Declarations
=> Declarations
(N
),
11502 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11504 -- If the task contains generic instantiations, cleanup actions are
11505 -- delayed until after instantiation. Transfer the activation chain to
11506 -- the subprogram, to insure that the activation call is properly
11507 -- generated. It the task body contains inner tasks, indicate that the
11508 -- subprogram is a task master.
11510 if Delay_Cleanups
(Ttyp
) then
11511 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11512 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11515 Rewrite
(N
, New_N
);
11518 -- Set elaboration flag immediately after task body. If the body is a
11519 -- subunit, the flag is set in the declarative part containing the stub.
11521 if Nkind
(Parent
(N
)) /= N_Subunit
then
11523 Make_Assignment_Statement
(Loc
,
11525 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11526 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11529 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11530 -- the task body. At this point all wrapper specs have been created,
11531 -- frozen and included in the dispatch table for the task type.
11533 if Ada_Version
>= Ada_2005
then
11534 if Nkind
(Parent
(N
)) = N_Subunit
then
11535 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11540 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11542 end Expand_N_Task_Body
;
11544 ------------------------------------
11545 -- Expand_N_Task_Type_Declaration --
11546 ------------------------------------
11548 -- We have several things to do. First we must create a Boolean flag used
11549 -- to mark if the body is elaborated yet. This variable gets set to True
11550 -- when the body of the task is elaborated (we can't rely on the normal
11551 -- ABE mechanism for the task body, since we need to pass an access to
11552 -- this elaboration boolean to the runtime routines).
11554 -- taskE : aliased Boolean := False;
11556 -- Next a variable is declared to hold the task stack size (either the
11557 -- default : Unspecified_Size, or a value that is set by a pragma
11558 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11559 -- the variable is initialized with this value:
11561 -- taskZ : Size_Type := Unspecified_Size;
11563 -- taskZ : Size_Type := Size_Type (size_expression);
11565 -- Note: No variable is needed to hold the task relative deadline since
11566 -- its value would never be static because the parameter is of a private
11567 -- type (Ada.Real_Time.Time_Span).
11569 -- Next we create a corresponding record type declaration used to represent
11570 -- values of this task. The general form of this type declaration is
11572 -- type taskV (discriminants) is record
11573 -- _Task_Id : Task_Id;
11574 -- entry_family : array (bounds) of Void;
11575 -- _Priority : Integer := priority_expression;
11576 -- _Size : Size_Type := size_expression;
11577 -- _Task_Info : Task_Info_Type := task_info_expression;
11578 -- _CPU : Integer := cpu_range_expression;
11579 -- _Relative_Deadline : Time_Span := time_span_expression;
11580 -- _Domain : Dispatching_Domain := dd_expression;
11583 -- The discriminants are present only if the corresponding task type has
11584 -- discriminants, and they exactly mirror the task type discriminants.
11586 -- The Id field is always present. It contains the Task_Id value, as set by
11587 -- the call to Create_Task. Note that although the task is limited, the
11588 -- task value record type is not limited, so there is no problem in passing
11589 -- this field as an out parameter to Create_Task.
11591 -- One entry_family component is present for each entry family in the task
11592 -- definition. The bounds correspond to the bounds of the entry family
11593 -- (which may depend on discriminants). The element type is void, since we
11594 -- only need the bounds information for determining the entry index. Note
11595 -- that the use of an anonymous array would normally be illegal in this
11596 -- context, but this is a parser check, and the semantics is quite prepared
11597 -- to handle such a case.
11599 -- The _Size field is present only if a Storage_Size pragma appears in the
11600 -- task definition. The expression captures the argument that was present
11601 -- in the pragma, and is used to override the task stack size otherwise
11602 -- associated with the task type.
11604 -- The _Priority field is present only if the task entity has a Priority or
11605 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11606 -- definition clause). It will be filled at the freeze point, when the
11607 -- record init proc is built, to capture the expression of the rep item
11608 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11609 -- here since aspect evaluations are delayed till the freeze point.
11611 -- The _Task_Info field is present only if a Task_Info pragma appears in
11612 -- the task definition. The expression captures the argument that was
11613 -- present in the pragma, and is used to provide the Task_Image parameter
11614 -- to the call to Create_Task.
11616 -- The _CPU field is present only if the task entity has a CPU rep item
11617 -- (pragma, aspect specification or attribute definition clause). It will
11618 -- be filled at the freeze point, when the record init proc is built, to
11619 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11620 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11621 -- are delayed till the freeze point.
11623 -- The _Relative_Deadline field is present only if a Relative_Deadline
11624 -- pragma appears in the task definition. The expression captures the
11625 -- argument that was present in the pragma, and is used to provide the
11626 -- Relative_Deadline parameter to the call to Create_Task.
11628 -- The _Domain field is present only if the task entity has a
11629 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11630 -- definition clause). It will be filled at the freeze point, when the
11631 -- record init proc is built, to capture the expression of the rep item
11632 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11633 -- here since aspect evaluations are delayed till the freeze point.
11635 -- When a task is declared, an instance of the task value record is
11636 -- created. The elaboration of this declaration creates the correct bounds
11637 -- for the entry families, and also evaluates the size, priority, and
11638 -- task_Info expressions if needed. The initialization routine for the task
11639 -- type itself then calls Create_Task with appropriate parameters to
11640 -- initialize the value of the Task_Id field.
11642 -- Note: the address of this record is passed as the "Discriminants"
11643 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11644 -- body procedure, it does not matter that it does not quite match the
11645 -- GNARLI model of what is being passed (the record contains more than just
11646 -- the discriminants, but the discriminants can be found from the record
11649 -- The Entity_Id for this created record type is placed in the
11650 -- Corresponding_Record_Type field of the associated task type entity.
11652 -- Next we create a procedure specification for the task body procedure:
11654 -- procedure taskB (_Task : access taskV);
11656 -- Note that this must come after the record type declaration, since
11657 -- the spec refers to this type. It turns out that the initialization
11658 -- procedure for the value type references the task body spec, but that's
11659 -- fine, since it won't be generated till the freeze point for the type,
11660 -- which is certainly after the task body spec declaration.
11662 -- Finally, we set the task index value field of the entry attribute in
11663 -- the case of a simple entry.
11665 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11666 Loc
: constant Source_Ptr
:= Sloc
(N
);
11667 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11668 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11669 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11670 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11672 Body_Decl
: Node_Id
;
11674 Decl_Stack
: Node_Id
;
11675 Elab_Decl
: Node_Id
;
11676 Ent_Stack
: Entity_Id
;
11677 Proc_Spec
: Node_Id
;
11678 Rec_Decl
: Node_Id
;
11679 Rec_Ent
: Entity_Id
;
11680 Size_Decl
: Entity_Id
;
11681 Task_Size
: Node_Id
;
11683 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11684 -- Searches the task definition T for the first occurrence of the pragma
11685 -- Relative Deadline. The caller has ensured that the pragma is present
11686 -- in the task definition. Note that this routine cannot be implemented
11687 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11688 -- not chained because their expansion into a procedure call statement
11689 -- would cause a break in the chain.
11691 ----------------------------------
11692 -- Get_Relative_Deadline_Pragma --
11693 ----------------------------------
11695 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11699 N
:= First
(Visible_Declarations
(T
));
11700 while Present
(N
) loop
11701 if Nkind
(N
) = N_Pragma
11702 and then Pragma_Name
(N
) = Name_Relative_Deadline
11710 N
:= First
(Private_Declarations
(T
));
11711 while Present
(N
) loop
11712 if Nkind
(N
) = N_Pragma
11713 and then Pragma_Name
(N
) = Name_Relative_Deadline
11721 raise Program_Error
;
11722 end Get_Relative_Deadline_Pragma
;
11724 -- Start of processing for Expand_N_Task_Type_Declaration
11727 -- If already expanded, nothing to do
11729 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11733 -- Here we will do the expansion
11735 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11737 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11738 Cdecls
:= Component_Items
(Component_List
11739 (Type_Definition
(Rec_Decl
)));
11741 Qualify_Entity_Names
(N
);
11743 -- First create the elaboration variable
11746 Make_Object_Declaration
(Loc
,
11747 Defining_Identifier
=>
11748 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11749 Chars
=> New_External_Name
(Tasknm
, 'E')),
11750 Aliased_Present
=> True,
11751 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11752 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11754 Insert_After
(N
, Elab_Decl
);
11756 -- Next create the declaration of the size variable (tasknmZ)
11758 Set_Storage_Size_Variable
(Tasktyp
,
11759 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11760 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11762 if Present
(Taskdef
)
11763 and then Has_Storage_Size_Pragma
(Taskdef
)
11765 Is_OK_Static_Expression
11767 (First
(Pragma_Argument_Associations
11768 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11771 Make_Object_Declaration
(Loc
,
11772 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11773 Object_Definition
=>
11774 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11776 Convert_To
(RTE
(RE_Size_Type
),
11778 (Expression
(First
(Pragma_Argument_Associations
11780 (TaskId
, Name_Storage_Size
)))))));
11784 Make_Object_Declaration
(Loc
,
11785 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11786 Object_Definition
=>
11787 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11789 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11792 Insert_After
(Elab_Decl
, Size_Decl
);
11794 -- Next build the rest of the corresponding record declaration. This is
11795 -- done last, since the corresponding record initialization procedure
11796 -- will reference the previously created entities.
11798 -- Fill in the component declarations -- first the _Task_Id field
11801 Make_Component_Declaration
(Loc
,
11802 Defining_Identifier
=>
11803 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11804 Component_Definition
=>
11805 Make_Component_Definition
(Loc
,
11806 Aliased_Present
=> False,
11807 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11810 -- Declare static ATCB (that is, created by the expander) if we are
11811 -- using the Restricted run time.
11813 if Restricted_Profile
then
11815 Make_Component_Declaration
(Loc
,
11816 Defining_Identifier
=>
11817 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11819 Component_Definition
=>
11820 Make_Component_Definition
(Loc
,
11821 Aliased_Present
=> True,
11822 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11824 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11827 Make_Index_Or_Discriminant_Constraint
(Loc
,
11829 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11833 -- Declare static stack (that is, created by the expander) if we are
11834 -- using the Restricted run time on a bare board configuration.
11836 if Restricted_Profile
11837 and then Preallocated_Stacks_On_Target
11839 -- First we need to extract the appropriate stack size
11841 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11843 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11845 Expr_N
: constant Node_Id
:=
11846 Expression
(First
(
11847 Pragma_Argument_Associations
(
11848 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11849 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11850 P
: constant Node_Id
:= Parent
(Expr_N
);
11853 -- The stack is defined inside the corresponding record.
11854 -- Therefore if the size of the stack is set by means of
11855 -- a discriminant, we must reference the discriminant of the
11856 -- corresponding record type.
11858 if Nkind
(Expr_N
) in N_Has_Entity
11859 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11863 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11865 Set_Parent
(Task_Size
, P
);
11866 Set_Etype
(Task_Size
, Etyp
);
11867 Set_Analyzed
(Task_Size
);
11870 Task_Size
:= Relocate_Node
(Expr_N
);
11876 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
11879 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11880 Defining_Identifier
=> Ent_Stack
,
11882 Component_Definition
=>
11883 Make_Component_Definition
(Loc
,
11884 Aliased_Present
=> True,
11885 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11887 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11890 Make_Index_Or_Discriminant_Constraint
(Loc
,
11891 Constraints
=> New_List
(Make_Range
(Loc
,
11892 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11893 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11896 Append_To
(Cdecls
, Decl_Stack
);
11898 -- The appropriate alignment for the stack is ensured by the run-time
11899 -- code in charge of task creation.
11903 -- Add components for entry families
11905 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11907 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11908 -- item is present.
11910 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
11912 Make_Component_Declaration
(Loc
,
11913 Defining_Identifier
=>
11914 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11915 Component_Definition
=>
11916 Make_Component_Definition
(Loc
,
11917 Aliased_Present
=> False,
11918 Subtype_Indication
=>
11919 New_Occurrence_Of
(Standard_Integer
, Loc
))));
11922 -- Add the _Size component if a Storage_Size pragma is present
11924 if Present
(Taskdef
)
11925 and then Has_Storage_Size_Pragma
(Taskdef
)
11928 Make_Component_Declaration
(Loc
,
11929 Defining_Identifier
=>
11930 Make_Defining_Identifier
(Loc
, Name_uSize
),
11932 Component_Definition
=>
11933 Make_Component_Definition
(Loc
,
11934 Aliased_Present
=> False,
11935 Subtype_Indication
=>
11936 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
11939 Convert_To
(RTE
(RE_Size_Type
),
11941 Expression
(First
(
11942 Pragma_Argument_Associations
(
11943 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
11946 -- Add the _Task_Info component if a Task_Info pragma is present
11948 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
11950 Make_Component_Declaration
(Loc
,
11951 Defining_Identifier
=>
11952 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11954 Component_Definition
=>
11955 Make_Component_Definition
(Loc
,
11956 Aliased_Present
=> False,
11957 Subtype_Indication
=>
11958 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
11960 Expression
=> New_Copy
(
11961 Expression
(First
(
11962 Pragma_Argument_Associations
(
11964 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
11967 -- Add the _CPU component if a CPU rep item is present
11969 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
11971 Make_Component_Declaration
(Loc
,
11972 Defining_Identifier
=>
11973 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11975 Component_Definition
=>
11976 Make_Component_Definition
(Loc
,
11977 Aliased_Present
=> False,
11978 Subtype_Indication
=>
11979 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
11982 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11983 -- present. If we are using a restricted run time this component will
11984 -- not be added (deadlines are not allowed by the Ravenscar profile).
11986 if not Restricted_Profile
11987 and then Present
(Taskdef
)
11988 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11991 Make_Component_Declaration
(Loc
,
11992 Defining_Identifier
=>
11993 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11995 Component_Definition
=>
11996 Make_Component_Definition
(Loc
,
11997 Aliased_Present
=> False,
11998 Subtype_Indication
=>
11999 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
12002 Convert_To
(RTE
(RE_Time_Span
),
12004 Expression
(First
(
12005 Pragma_Argument_Associations
(
12006 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12009 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12010 -- item is present. If we are using a restricted run time this component
12011 -- will not be added (dispatching domains are not allowed by the
12012 -- Ravenscar profile).
12014 if not Restricted_Profile
12017 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12020 Make_Component_Declaration
(Loc
,
12021 Defining_Identifier
=>
12022 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12024 Component_Definition
=>
12025 Make_Component_Definition
(Loc
,
12026 Aliased_Present
=> False,
12027 Subtype_Indication
=>
12029 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12032 Insert_After
(Size_Decl
, Rec_Decl
);
12034 -- Analyze the record declaration immediately after construction,
12035 -- because the initialization procedure is needed for single task
12036 -- declarations before the next entity is analyzed.
12038 Analyze
(Rec_Decl
);
12040 -- Create the declaration of the task body procedure
12042 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12044 Make_Subprogram_Declaration
(Loc
,
12045 Specification
=> Proc_Spec
);
12047 Insert_After
(Rec_Decl
, Body_Decl
);
12049 -- The subprogram does not comes from source, so we have to indicate the
12050 -- need for debugging information explicitly.
12052 if Comes_From_Source
(Original_Node
(N
)) then
12053 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12056 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12057 -- the corresponding record has been frozen.
12059 if Ada_Version
>= Ada_2005
then
12060 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12063 -- Ada 2005 (AI-345): We must defer freezing to allow further
12064 -- declaration of primitive subprograms covering task interfaces
12066 if Ada_Version
<= Ada_95
then
12068 -- Now we can freeze the corresponding record. This needs manually
12069 -- freezing, since it is really part of the task type, and the task
12070 -- type is frozen at this stage. We of course need the initialization
12071 -- procedure for this corresponding record type and we won't get it
12072 -- in time if we don't freeze now.
12075 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
12077 if Is_Non_Empty_List
(L
) then
12078 Insert_List_After
(Body_Decl
, L
);
12083 -- Complete the expansion of access types to the current task type, if
12084 -- any were declared.
12086 Expand_Previous_Access_Type
(Tasktyp
);
12088 -- Create wrappers for entries that have pre/postconditions
12094 Ent
:= First_Entity
(Tasktyp
);
12095 while Present
(Ent
) loop
12096 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
12097 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
12099 Build_PPC_Wrapper
(Ent
, N
);
12105 end Expand_N_Task_Type_Declaration
;
12107 -------------------------------
12108 -- Expand_N_Timed_Entry_Call --
12109 -------------------------------
12111 -- A timed entry call in normal case is not implemented using ATC mechanism
12112 -- anymore for efficiency reason.
12122 -- is expanded as follows:
12124 -- 1) When T.E is a task entry_call;
12128 -- X : Task_Entry_Index := <entry index>;
12129 -- DX : Duration := To_Duration (D);
12130 -- M : Delay_Mode := <discriminant>;
12131 -- P : parms := (parm, parm, parm);
12134 -- Timed_Protected_Entry_Call
12135 -- (<acceptor-task>, X, P'Address, DX, M, B);
12143 -- 2) When T.E is a protected entry_call;
12147 -- X : Protected_Entry_Index := <entry index>;
12148 -- DX : Duration := To_Duration (D);
12149 -- M : Delay_Mode := <discriminant>;
12150 -- P : parms := (parm, parm, parm);
12153 -- Timed_Protected_Entry_Call
12154 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12162 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12163 -- is no delay and the triggering statements are executed. We first
12164 -- determine the kind of of the triggering call and then execute a
12165 -- synchronized operation or a direct call.
12168 -- B : Boolean := False;
12169 -- C : Ada.Tags.Prim_Op_Kind;
12170 -- DX : Duration := To_Duration (D)
12171 -- K : Ada.Tags.Tagged_Kind :=
12172 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12173 -- M : Integer :=...;
12174 -- P : Parameters := (Param1 .. ParamN);
12178 -- if K = Ada.Tags.TK_Limited_Tagged
12179 -- or else K = Ada.Tags.TK_Tagged
12181 -- <dispatching-call>;
12186 -- Ada.Tags.Get_Offset_Index
12187 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12189 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12191 -- if C = POK_Protected_Entry
12192 -- or else C = POK_Task_Entry
12194 -- Param1 := P.Param1;
12196 -- ParamN := P.ParamN;
12200 -- if C = POK_Procedure
12201 -- or else C = POK_Protected_Procedure
12202 -- or else C = POK_Task_Procedure
12204 -- <dispatching-call>;
12210 -- <triggering-statements>
12212 -- <timed-statements>
12216 -- The triggering statement and the sequence of timed statements have not
12217 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12218 -- global references if within an instantiation.
12220 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12221 Loc
: constant Source_Ptr
:= Sloc
(N
);
12224 Blk_Typ
: Entity_Id
;
12226 Call_Ent
: Entity_Id
;
12227 Conc_Typ_Stmts
: List_Id
;
12229 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12232 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12234 D_Type
: Entity_Id
;
12237 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12238 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12243 Is_Disp_Select
: Boolean;
12244 Lim_Typ_Stmts
: List_Id
;
12253 B
: Entity_Id
; -- Call status flag
12254 C
: Entity_Id
; -- Call kind
12255 D
: Entity_Id
; -- Delay
12256 K
: Entity_Id
; -- Tagged kind
12257 M
: Entity_Id
; -- Delay mode
12258 P
: Entity_Id
; -- Parameter block
12259 S
: Entity_Id
; -- Primitive operation slot
12261 -- Start of processing for Expand_N_Timed_Entry_Call
12264 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12265 -- was already reported on spec, so do not attempt to expand the call.
12267 if Restriction_Active
(No_Select_Statements
) then
12271 Process_Statements_For_Controlled_Objects
(E_Alt
);
12272 Process_Statements_For_Controlled_Objects
(D_Alt
);
12274 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12276 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12277 -- may wrap them in blocks.
12279 E_Stats
:= Statements
(E_Alt
);
12280 D_Stats
:= Statements
(D_Alt
);
12282 -- The arguments in the call may require dynamic allocation, and the
12283 -- call statement may have been transformed into a block. The block
12284 -- may contain additional declarations for internal entities, and the
12285 -- original call is found by sequential search.
12287 if Nkind
(E_Call
) = N_Block_Statement
then
12288 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12289 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12290 N_Entry_Call_Statement
)
12297 Ada_Version
>= Ada_2005
12298 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12300 if Is_Disp_Select
then
12301 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12307 -- B : Boolean := False;
12309 B
:= Build_B
(Loc
, Decls
);
12312 -- C : Ada.Tags.Prim_Op_Kind;
12314 C
:= Build_C
(Loc
, Decls
);
12316 -- Because the analysis of all statements was disabled, manually
12317 -- analyze the delay statement.
12320 D_Stat
:= Original_Node
(D_Stat
);
12323 -- Build an entry call using Simple_Entry_Call
12325 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12326 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12328 Decls
:= Declarations
(E_Call
);
12329 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12338 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12341 Make_Object_Declaration
(Loc
,
12342 Defining_Identifier
=> B
,
12343 Object_Definition
=>
12344 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12347 -- Duration and mode processing
12349 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12351 -- Use the type of the delay expression (Calendar or Real_Time) to
12352 -- generate the appropriate conversion.
12354 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12355 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12356 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12358 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12359 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12361 Make_Function_Call
(Loc
,
12362 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12363 Parameter_Associations
=>
12364 New_List
(New_Copy
(Expression
(D_Stat
))));
12366 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12367 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12369 Make_Function_Call
(Loc
,
12370 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12371 Parameter_Associations
=>
12372 New_List
(New_Copy
(Expression
(D_Stat
))));
12375 D
:= Make_Temporary
(Loc
, 'D');
12381 Make_Object_Declaration
(Loc
,
12382 Defining_Identifier
=> D
,
12383 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12385 M
:= Make_Temporary
(Loc
, 'M');
12388 -- M : Integer := (0 | 1 | 2);
12391 Make_Object_Declaration
(Loc
,
12392 Defining_Identifier
=> M
,
12393 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12394 Expression
=> D_Disc
));
12396 -- Do the assignment at this stage only because the evaluation of the
12397 -- expression must not occur before (see ACVC C97302A).
12400 Make_Assignment_Statement
(Loc
,
12401 Name
=> New_Occurrence_Of
(D
, Loc
),
12402 Expression
=> D_Conv
));
12404 -- Parameter block processing
12406 -- Manually create the parameter block for dispatching calls. In the
12407 -- case of entries, the block has already been created during the call
12408 -- to Build_Simple_Entry_Call.
12410 if Is_Disp_Select
then
12412 -- Tagged kind processing, generate:
12413 -- K : Ada.Tags.Tagged_Kind :=
12414 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12416 K
:= Build_K
(Loc
, Decls
, Obj
);
12418 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12420 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12422 -- Dispatch table slot processing, generate:
12425 S
:= Build_S
(Loc
, Decls
);
12428 -- S := Ada.Tags.Get_Offset_Index
12429 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12432 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12435 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12437 -- where Obj is the controlling formal parameter, S is the dispatch
12438 -- table slot number of the dispatching operation, P is the wrapped
12439 -- parameter block, D is the duration, M is the duration mode, C is
12440 -- the call kind and B is the call status.
12442 Params
:= New_List
;
12444 Append_To
(Params
, New_Copy_Tree
(Obj
));
12445 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12447 Make_Attribute_Reference
(Loc
,
12448 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12449 Attribute_Name
=> Name_Address
));
12450 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12451 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12452 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12453 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12455 Append_To
(Conc_Typ_Stmts
,
12456 Make_Procedure_Call_Statement
(Loc
,
12460 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12461 Parameter_Associations
=> Params
));
12464 -- if C = POK_Protected_Entry
12465 -- or else C = POK_Task_Entry
12467 -- Param1 := P.Param1;
12469 -- ParamN := P.ParamN;
12472 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12474 -- Generate the if statement only when the packed parameters need
12475 -- explicit assignments to their corresponding actuals.
12477 if Present
(Unpack
) then
12478 Append_To
(Conc_Typ_Stmts
,
12479 Make_Implicit_If_Statement
(N
,
12485 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12488 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12492 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12494 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12496 Then_Statements
=> Unpack
));
12502 -- if C = POK_Procedure
12503 -- or else C = POK_Protected_Procedure
12504 -- or else C = POK_Task_Procedure
12506 -- <dispatching-call>
12510 N_Stats
:= New_List
(
12511 Make_Implicit_If_Statement
(N
,
12516 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12518 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12524 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12526 New_Occurrence_Of
(RTE
(
12527 RE_POK_Protected_Procedure
), Loc
)),
12530 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12533 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12535 Then_Statements
=> New_List
(E_Call
)));
12537 Append_To
(Conc_Typ_Stmts
,
12538 Make_Implicit_If_Statement
(N
,
12539 Condition
=> New_Occurrence_Of
(B
, Loc
),
12540 Then_Statements
=> N_Stats
));
12543 -- <dispatching-call>;
12547 New_List
(New_Copy_Tree
(E_Call
),
12548 Make_Assignment_Statement
(Loc
,
12549 Name
=> New_Occurrence_Of
(B
, Loc
),
12550 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12553 -- if K = Ada.Tags.TK_Limited_Tagged
12554 -- or else K = Ada.Tags.TK_Tagged
12562 Make_Implicit_If_Statement
(N
,
12563 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12564 Then_Statements
=> Lim_Typ_Stmts
,
12565 Else_Statements
=> Conc_Typ_Stmts
));
12570 -- <triggering-statements>
12572 -- <timed-statements>
12576 Make_Implicit_If_Statement
(N
,
12577 Condition
=> New_Occurrence_Of
(B
, Loc
),
12578 Then_Statements
=> E_Stats
,
12579 Else_Statements
=> D_Stats
));
12582 -- Simple case of a non-dispatching trigger. Skip assignments to
12583 -- temporaries created for in-out parameters.
12585 -- This makes unwarranted assumptions about the shape of the expanded
12586 -- tree for the call, and should be cleaned up ???
12588 Stmt
:= First
(Stmts
);
12589 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12593 -- Do the assignment at this stage only because the evaluation
12594 -- of the expression must not occur before (see ACVC C97302A).
12596 Insert_Before
(Stmt
,
12597 Make_Assignment_Statement
(Loc
,
12598 Name
=> New_Occurrence_Of
(D
, Loc
),
12599 Expression
=> D_Conv
));
12602 Params
:= Parameter_Associations
(Call
);
12604 -- For a protected type, we build a Timed_Protected_Entry_Call
12606 if Is_Protected_Type
(Etype
(Concval
)) then
12608 -- Create a new call statement
12610 Param
:= First
(Params
);
12611 while Present
(Param
)
12612 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12617 Dummy
:= Remove_Next
(Next
(Param
));
12619 -- Remove garbage is following the Cancel_Param if present
12621 Dummy
:= Next
(Param
);
12623 -- Remove the mode of the Protected_Entry_Call call, then remove
12624 -- the Communication_Block of the Protected_Entry_Call call, and
12625 -- finally add Duration and a Delay_Mode parameter
12627 pragma Assert
(Present
(Param
));
12628 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12630 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12632 -- Add a Boolean flag for successful entry call
12634 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12636 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12637 when System_Tasking_Protected_Objects_Entries
=>
12639 Make_Procedure_Call_Statement
(Loc
,
12642 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12643 Parameter_Associations
=> Params
));
12646 raise Program_Error
;
12649 -- For the task case, build a Timed_Task_Entry_Call
12652 -- Create a new call statement
12654 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12655 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12656 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12659 Make_Procedure_Call_Statement
(Loc
,
12661 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12662 Parameter_Associations
=> Params
));
12666 Make_Implicit_If_Statement
(N
,
12667 Condition
=> New_Occurrence_Of
(B
, Loc
),
12668 Then_Statements
=> E_Stats
,
12669 Else_Statements
=> D_Stats
));
12673 Make_Block_Statement
(Loc
,
12674 Declarations
=> Decls
,
12675 Handled_Statement_Sequence
=>
12676 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12679 end Expand_N_Timed_Entry_Call
;
12681 ----------------------------------------
12682 -- Expand_Protected_Body_Declarations --
12683 ----------------------------------------
12685 procedure Expand_Protected_Body_Declarations
12687 Spec_Id
: Entity_Id
)
12690 if No_Run_Time_Mode
then
12691 Error_Msg_CRT
("protected body", N
);
12694 elsif Expander_Active
then
12696 -- Associate discriminals with the first subprogram or entry body to
12699 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12700 Set_Discriminals
(Parent
(Spec_Id
));
12703 end Expand_Protected_Body_Declarations
;
12705 -------------------------
12706 -- External_Subprogram --
12707 -------------------------
12709 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12710 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12713 -- The internal and external subprograms follow each other on the entity
12714 -- chain. Note that previously private operations had no separate
12715 -- external subprogram. We now create one in all cases, because a
12716 -- private operation may actually appear in an external call, through
12717 -- a 'Access reference used for a callback.
12719 -- If the operation is a function that returns an anonymous access type,
12720 -- the corresponding itype appears before the operation, and must be
12723 -- This mechanism is fragile, there should be a real link between the
12724 -- two versions of the operation, but there is no place to put it ???
12726 if Is_Access_Type
(Next_Entity
(Subp
)) then
12727 return Next_Entity
(Next_Entity
(Subp
));
12729 return Next_Entity
(Subp
);
12731 end External_Subprogram
;
12733 ------------------------------
12734 -- Extract_Dispatching_Call --
12735 ------------------------------
12737 procedure Extract_Dispatching_Call
12739 Call_Ent
: out Entity_Id
;
12740 Object
: out Entity_Id
;
12741 Actuals
: out List_Id
;
12742 Formals
: out List_Id
)
12744 Call_Nam
: Node_Id
;
12747 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12749 if Present
(Original_Node
(N
)) then
12750 Call_Nam
:= Name
(Original_Node
(N
));
12752 Call_Nam
:= Name
(N
);
12755 -- Retrieve the name of the dispatching procedure. It contains the
12756 -- dispatch table slot number.
12759 case Nkind
(Call_Nam
) is
12760 when N_Identifier
=>
12763 when N_Selected_Component
=>
12764 Call_Nam
:= Selector_Name
(Call_Nam
);
12767 raise Program_Error
;
12772 Actuals
:= Parameter_Associations
(N
);
12773 Call_Ent
:= Entity
(Call_Nam
);
12774 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12775 Object
:= First
(Actuals
);
12777 if Present
(Original_Node
(Object
)) then
12778 Object
:= Original_Node
(Object
);
12781 -- If the type of the dispatching object is an access type then return
12782 -- an explicit dereference.
12784 if Is_Access_Type
(Etype
(Object
)) then
12785 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12788 end Extract_Dispatching_Call
;
12790 -------------------
12791 -- Extract_Entry --
12792 -------------------
12794 procedure Extract_Entry
12796 Concval
: out Node_Id
;
12797 Ename
: out Node_Id
;
12798 Index
: out Node_Id
)
12800 Nam
: constant Node_Id
:= Name
(N
);
12803 -- For a simple entry, the name is a selected component, with the
12804 -- prefix being the task value, and the selector being the entry.
12806 if Nkind
(Nam
) = N_Selected_Component
then
12807 Concval
:= Prefix
(Nam
);
12808 Ename
:= Selector_Name
(Nam
);
12811 -- For a member of an entry family, the name is an indexed component
12812 -- where the prefix is a selected component, whose prefix in turn is
12813 -- the task value, and whose selector is the entry family. The single
12814 -- expression in the expressions list of the indexed component is the
12815 -- subscript for the family.
12817 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12818 Concval
:= Prefix
(Prefix
(Nam
));
12819 Ename
:= Selector_Name
(Prefix
(Nam
));
12820 Index
:= First
(Expressions
(Nam
));
12823 -- Through indirection, the type may actually be a limited view of a
12824 -- concurrent type. When compiling a call, the non-limited view of the
12825 -- type is visible.
12827 if From_Limited_With
(Etype
(Concval
)) then
12828 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
12832 -------------------
12833 -- Family_Offset --
12834 -------------------
12836 function Family_Offset
12841 Cap
: Boolean) return Node_Id
12847 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12848 -- If one of the bounds is a reference to a discriminant, replace with
12849 -- corresponding discriminal of type. Within the body of a task retrieve
12850 -- the renamed discriminant by simple visibility, using its generated
12851 -- name. Within a protected object, find the original discriminant and
12852 -- replace it with the discriminal of the current protected operation.
12854 ------------------------------
12855 -- Convert_Discriminant_Ref --
12856 ------------------------------
12858 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12859 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12864 if Is_Entity_Name
(Bound
)
12865 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12867 if Is_Task_Type
(Ttyp
)
12868 and then Has_Completion
(Ttyp
)
12870 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12871 Find_Direct_Name
(B
);
12873 elsif Is_Protected_Type
(Ttyp
) then
12874 D
:= First_Discriminant
(Ttyp
);
12875 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12876 Next_Discriminant
(D
);
12879 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
12882 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
12885 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12889 B
:= New_Copy_Tree
(Bound
);
12893 Make_Attribute_Reference
(Loc
,
12894 Attribute_Name
=> Name_Pos
,
12895 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12896 Expressions
=> New_List
(B
));
12897 end Convert_Discriminant_Ref
;
12899 -- Start of processing for Family_Offset
12902 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12903 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12906 if Is_Task_Type
(Ttyp
) then
12907 Ityp
:= RTE
(RE_Task_Entry_Index
);
12909 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12913 Make_Attribute_Reference
(Loc
,
12914 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12915 Attribute_Name
=> Name_Min
,
12916 Expressions
=> New_List
(
12918 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12921 Make_Attribute_Reference
(Loc
,
12922 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12923 Attribute_Name
=> Name_Max
,
12924 Expressions
=> New_List
(
12926 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12929 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12936 function Family_Size
12941 Cap
: Boolean) return Node_Id
12946 if Is_Task_Type
(Ttyp
) then
12947 Ityp
:= RTE
(RE_Task_Entry_Index
);
12949 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12953 Make_Attribute_Reference
(Loc
,
12954 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
12955 Attribute_Name
=> Name_Max
,
12956 Expressions
=> New_List
(
12959 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12961 Make_Integer_Literal
(Loc
, 1)),
12962 Make_Integer_Literal
(Loc
, 0)));
12965 ----------------------------
12966 -- Find_Enclosing_Context --
12967 ----------------------------
12969 procedure Find_Enclosing_Context
12971 Context
: out Node_Id
;
12972 Context_Id
: out Entity_Id
;
12973 Context_Decls
: out List_Id
)
12976 -- Traverse the parent chain looking for an enclosing body, block,
12977 -- package or return statement.
12979 Context
:= Parent
(N
);
12980 while not Nkind_In
(Context
, N_Block_Statement
,
12982 N_Extended_Return_Statement
,
12984 N_Package_Declaration
,
12988 Context
:= Parent
(Context
);
12991 -- Extract the constituents of the context
12993 if Nkind
(Context
) = N_Extended_Return_Statement
then
12994 Context_Decls
:= Return_Object_Declarations
(Context
);
12995 Context_Id
:= Return_Statement_Entity
(Context
);
12997 -- Package declarations and bodies use a common library-level activation
12998 -- chain or task master, therefore return the package declaration as the
12999 -- proper carrier for the appropriate flag.
13001 elsif Nkind
(Context
) = N_Package_Body
then
13002 Context_Decls
:= Declarations
(Context
);
13003 Context_Id
:= Corresponding_Spec
(Context
);
13004 Context
:= Parent
(Context_Id
);
13006 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13007 Context
:= Parent
(Parent
(Context
));
13009 Context
:= Parent
(Context
);
13012 elsif Nkind
(Context
) = N_Package_Declaration
then
13013 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13014 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13016 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13017 Context_Id
:= Defining_Identifier
(Context_Id
);
13021 Context_Decls
:= Declarations
(Context
);
13023 if Nkind
(Context
) = N_Block_Statement
then
13024 Context_Id
:= Entity
(Identifier
(Context
));
13026 elsif Nkind
(Context
) = N_Entry_Body
then
13027 Context_Id
:= Defining_Identifier
(Context
);
13029 elsif Nkind
(Context
) = N_Subprogram_Body
then
13030 if Present
(Corresponding_Spec
(Context
)) then
13031 Context_Id
:= Corresponding_Spec
(Context
);
13033 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13035 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13036 Context_Id
:= Defining_Identifier
(Context_Id
);
13040 elsif Nkind
(Context
) = N_Task_Body
then
13041 Context_Id
:= Corresponding_Spec
(Context
);
13044 raise Program_Error
;
13048 pragma Assert
(Present
(Context
));
13049 pragma Assert
(Present
(Context_Id
));
13050 pragma Assert
(Present
(Context_Decls
));
13051 end Find_Enclosing_Context
;
13053 -----------------------
13054 -- Find_Master_Scope --
13055 -----------------------
13057 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13061 -- In Ada 2005, the master is the innermost enclosing scope that is not
13062 -- transient. If the enclosing block is the rewriting of a call or the
13063 -- scope is an extended return statement this is valid master. The
13064 -- master in an extended return is only used within the return, and is
13065 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13066 -- now before that overwriting occurs.
13070 if Ada_Version
>= Ada_2005
then
13071 while Is_Internal
(S
) loop
13072 if Nkind
(Parent
(S
)) = N_Block_Statement
13074 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
13078 elsif Ekind
(S
) = E_Return_Statement
then
13088 end Find_Master_Scope
;
13090 -------------------------------
13091 -- First_Protected_Operation --
13092 -------------------------------
13094 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13095 First_Op
: Node_Id
;
13098 First_Op
:= First
(D
);
13099 while Present
(First_Op
)
13100 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
13106 end First_Protected_Operation
;
13108 ---------------------------------------
13109 -- Install_Private_Data_Declarations --
13110 ---------------------------------------
13112 procedure Install_Private_Data_Declarations
13114 Spec_Id
: Entity_Id
;
13115 Conc_Typ
: Entity_Id
;
13116 Body_Nod
: Node_Id
;
13118 Barrier
: Boolean := False;
13119 Family
: Boolean := False)
13121 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13124 Insert_Node
: Node_Id
:= Empty
;
13125 Obj_Ent
: Entity_Id
;
13127 procedure Add
(Decl
: Node_Id
);
13128 -- Add a single declaration after Insert_Node. If this is the first
13129 -- addition, Decl is added to the front of Decls and it becomes the
13132 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13133 -- The bounds of an entry index may depend on discriminants, create a
13134 -- reference to the corresponding prival. Otherwise return a duplicate
13135 -- of the original bound.
13141 procedure Add
(Decl
: Node_Id
) is
13143 if No
(Insert_Node
) then
13144 Prepend_To
(Decls
, Decl
);
13146 Insert_After
(Insert_Node
, Decl
);
13149 Insert_Node
:= Decl
;
13152 --------------------------
13153 -- Replace_Discriminant --
13154 --------------------------
13156 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13158 if Nkind
(Bound
) = N_Identifier
13159 and then Is_Discriminal
(Entity
(Bound
))
13161 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13163 return Duplicate_Subexpr
(Bound
);
13167 -- Start of processing for Install_Private_Data_Declarations
13170 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13171 -- formal parameter _O, _object or _task depending on the context.
13173 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13175 -- Special processing of _O for barrier functions, protected entries
13182 (Ekind
(Spec_Id
) = E_Entry
13183 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13186 Conc_Rec
: constant Entity_Id
:=
13187 Corresponding_Record_Type
(Conc_Typ
);
13188 Typ_Id
: constant Entity_Id
:=
13189 Make_Defining_Identifier
(Loc
,
13190 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13193 -- type prot_typVP is access prot_typV;
13196 Make_Full_Type_Declaration
(Loc
,
13197 Defining_Identifier
=> Typ_Id
,
13199 Make_Access_To_Object_Definition
(Loc
,
13200 Subtype_Indication
=>
13201 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13205 -- _object : prot_typVP := prot_typV (_O);
13208 Make_Object_Declaration
(Loc
,
13209 Defining_Identifier
=>
13210 Make_Defining_Identifier
(Loc
, Name_uObject
),
13211 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13213 Unchecked_Convert_To
(Typ_Id
,
13214 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13217 -- Set the reference to the concurrent object
13219 Obj_Ent
:= Defining_Identifier
(Decl
);
13223 -- Step 2: Create the Protection object and build its declaration for
13224 -- any protected entry (family) of subprogram. Note for the lock-free
13225 -- implementation, the Protection object is not needed anymore.
13227 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13229 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13233 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13235 -- Determine the proper protection type
13237 if Has_Attach_Handler
(Conc_Typ
)
13238 and then not Restricted_Profile
13240 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13242 elsif Has_Interrupt_Handler
(Conc_Typ
)
13243 and then not Restriction_Active
(No_Dynamic_Attachment
)
13245 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13248 case Corresponding_Runtime_Package
(Conc_Typ
) is
13249 when System_Tasking_Protected_Objects_Entries
=>
13250 Prot_Typ
:= RE_Protection_Entries
;
13252 when System_Tasking_Protected_Objects_Single_Entry
=>
13253 Prot_Typ
:= RE_Protection_Entry
;
13255 when System_Tasking_Protected_Objects
=>
13256 Prot_Typ
:= RE_Protection
;
13259 raise Program_Error
;
13264 -- conc_typR : protection_typ renames _object._object;
13267 Make_Object_Renaming_Declaration
(Loc
,
13268 Defining_Identifier
=> Prot_Ent
,
13270 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13272 Make_Selected_Component
(Loc
,
13273 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13274 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13279 -- Step 3: Add discriminant renamings (if any)
13281 if Has_Discriminants
(Conc_Typ
) then
13286 D
:= First_Discriminant
(Conc_Typ
);
13287 while Present
(D
) loop
13289 -- Adjust the source location
13291 Set_Sloc
(Discriminal
(D
), Loc
);
13294 -- discr_name : discr_typ renames _object.discr_name;
13296 -- discr_name : discr_typ renames _task.discr_name;
13299 Make_Object_Renaming_Declaration
(Loc
,
13300 Defining_Identifier
=> Discriminal
(D
),
13301 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13303 Make_Selected_Component
(Loc
,
13304 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13305 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13308 Next_Discriminant
(D
);
13313 -- Step 4: Add private component renamings (if any)
13315 if Is_Protected
then
13316 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13318 if Present
(Private_Declarations
(Def
)) then
13321 Comp_Id
: Entity_Id
;
13322 Decl_Id
: Entity_Id
;
13325 Comp
:= First
(Private_Declarations
(Def
));
13326 while Present
(Comp
) loop
13327 if Nkind
(Comp
) = N_Component_Declaration
then
13328 Comp_Id
:= Defining_Identifier
(Comp
);
13330 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13332 -- Minimal decoration
13334 if Ekind
(Spec_Id
) = E_Function
then
13335 Set_Ekind
(Decl_Id
, E_Constant
);
13337 Set_Ekind
(Decl_Id
, E_Variable
);
13340 Set_Prival
(Comp_Id
, Decl_Id
);
13341 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13342 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13345 -- comp_name : comp_typ renames _object.comp_name;
13348 Make_Object_Renaming_Declaration
(Loc
,
13349 Defining_Identifier
=> Decl_Id
,
13351 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13353 Make_Selected_Component
(Loc
,
13355 New_Occurrence_Of
(Obj_Ent
, Loc
),
13357 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13367 -- Step 5: Add the declaration of the entry index and the associated
13368 -- type for barrier functions and entry families.
13370 if (Barrier
and then Family
)
13371 or else Ekind
(Spec_Id
) = E_Entry_Family
13374 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13375 Index
: constant Entity_Id
:=
13376 Defining_Identifier
(
13377 Entry_Index_Specification
(
13378 Entry_Body_Formal_Part
(Body_Nod
)));
13379 Index_Con
: constant Entity_Id
:=
13380 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13382 Index_Typ
: Entity_Id
;
13386 -- Minimal decoration
13388 Set_Ekind
(Index_Con
, E_Constant
);
13389 Set_Entry_Index_Constant
(Index
, Index_Con
);
13390 Set_Discriminal_Link
(Index_Con
, Index
);
13392 -- Retrieve the bounds of the entry family
13394 High
:= Type_High_Bound
(Etype
(Index
));
13395 Low
:= Type_Low_Bound
(Etype
(Index
));
13397 -- In the simple case the entry family is given by a subtype
13398 -- mark and the index constant has the same type.
13400 if Is_Entity_Name
(Original_Node
(
13401 Discrete_Subtype_Definition
(Parent
(Index
))))
13403 Index_Typ
:= Etype
(Index
);
13405 -- Otherwise a new subtype declaration is required
13408 High
:= Replace_Bound
(High
);
13409 Low
:= Replace_Bound
(Low
);
13411 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13414 -- subtype Jnn is <Etype of Index> range Low .. High;
13417 Make_Subtype_Declaration
(Loc
,
13418 Defining_Identifier
=> Index_Typ
,
13419 Subtype_Indication
=>
13420 Make_Subtype_Indication
(Loc
,
13422 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13424 Make_Range_Constraint
(Loc
,
13425 Range_Expression
=>
13426 Make_Range
(Loc
, Low
, High
))));
13430 Set_Etype
(Index_Con
, Index_Typ
);
13432 -- Create the object which designates the index:
13433 -- J : constant Jnn :=
13434 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13436 -- where Jnn is the subtype created above or the original type of
13437 -- the index, _E is a formal of the protected body subprogram and
13438 -- <index expr> is the index of the first family member.
13441 Make_Object_Declaration
(Loc
,
13442 Defining_Identifier
=> Index_Con
,
13443 Constant_Present
=> True,
13444 Object_Definition
=>
13445 New_Occurrence_Of
(Index_Typ
, Loc
),
13448 Make_Attribute_Reference
(Loc
,
13450 New_Occurrence_Of
(Index_Typ
, Loc
),
13451 Attribute_Name
=> Name_Val
,
13453 Expressions
=> New_List
(
13457 Make_Op_Subtract
(Loc
,
13459 New_Occurrence_Of
(E
, Loc
),
13461 Entry_Index_Expression
(Loc
,
13462 Defining_Identifier
(Body_Nod
),
13466 Make_Attribute_Reference
(Loc
,
13468 New_Occurrence_Of
(Index_Typ
, Loc
),
13469 Attribute_Name
=> Name_Pos
,
13470 Expressions
=> New_List
(
13471 Make_Attribute_Reference
(Loc
,
13473 New_Occurrence_Of
(Index_Typ
, Loc
),
13474 Attribute_Name
=> Name_First
)))))));
13478 end Install_Private_Data_Declarations
;
13480 -----------------------
13481 -- Is_Exception_Safe --
13482 -----------------------
13484 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
13486 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
13487 -- Return True whenever encountering a subprogram call or raise
13488 -- statement of any kind in the sequence of statements
13490 ---------------------
13491 -- Has_Side_Effect --
13492 ---------------------
13494 -- What is this doing buried two levels down in exp_ch9. It seems like a
13495 -- generally useful function, and indeed there may be code duplication
13496 -- going on here ???
13498 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
13502 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
13503 -- Indicate whether N is a subprogram call or a raise statement
13505 ----------------------
13506 -- Is_Call_Or_Raise --
13507 ----------------------
13509 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
13511 return Nkind_In
(N
, N_Procedure_Call_Statement
,
13514 N_Raise_Constraint_Error
,
13515 N_Raise_Program_Error
,
13516 N_Raise_Storage_Error
);
13517 end Is_Call_Or_Raise
;
13519 -- Start of processing for Has_Side_Effect
13523 while Present
(Stmt
) loop
13524 if Is_Call_Or_Raise
(Stmt
) then
13528 -- An object declaration can also contain a function call or a
13529 -- raise statement.
13531 if Nkind
(Stmt
) = N_Object_Declaration
then
13532 Expr
:= Expression
(Stmt
);
13534 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
13543 end Has_Side_Effect
;
13545 -- Start of processing for Is_Exception_Safe
13548 -- When exceptions can't be propagated, the subprogram returns normally
13550 if No_Exception_Handlers_Set
then
13554 -- If the checks handled by the back end are not disabled, we cannot
13555 -- ensure that no exception will be raised.
13557 if not Access_Checks_Suppressed
(Empty
)
13558 or else not Discriminant_Checks_Suppressed
(Empty
)
13559 or else not Range_Checks_Suppressed
(Empty
)
13560 or else not Index_Checks_Suppressed
(Empty
)
13561 or else Opt
.Stack_Checking_Enabled
13566 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
13569 (First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
13575 end Is_Exception_Safe
;
13577 ---------------------------------
13578 -- Is_Potentially_Large_Family --
13579 ---------------------------------
13581 function Is_Potentially_Large_Family
13582 (Base_Index
: Entity_Id
;
13583 Conctyp
: Entity_Id
;
13585 Hi
: Node_Id
) return Boolean
13588 return Scope
(Base_Index
) = Standard_Standard
13589 and then Base_Index
= Base_Type
(Standard_Integer
)
13590 and then Has_Discriminants
(Conctyp
)
13592 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13594 (Denotes_Discriminant
(Lo
, True)
13596 Denotes_Discriminant
(Hi
, True));
13597 end Is_Potentially_Large_Family
;
13599 -------------------------------------
13600 -- Is_Private_Primitive_Subprogram --
13601 -------------------------------------
13603 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13606 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13607 and then Is_Private_Primitive
(Id
);
13608 end Is_Private_Primitive_Subprogram
;
13614 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13615 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13616 Formal
: Entity_Id
;
13619 Formal
:= First_Formal
(Bod_Subp
);
13620 while Present
(Formal
) loop
13622 -- Look for formal parameter _E
13624 if Chars
(Formal
) = Name_uE
then
13628 Next_Formal
(Formal
);
13631 -- A protected body subprogram should always have the parameter in
13634 raise Program_Error
;
13637 --------------------------------
13638 -- Make_Initialize_Protection --
13639 --------------------------------
13641 function Make_Initialize_Protection
13642 (Protect_Rec
: Entity_Id
) return List_Id
13644 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13647 Ptyp
: constant Node_Id
:=
13648 Corresponding_Concurrent_Type
(Protect_Rec
);
13650 L
: constant List_Id
:= New_List
;
13651 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13652 Prio_Type
: Entity_Id
;
13653 Prio_Var
: Entity_Id
:= Empty
;
13654 Restricted
: constant Boolean := Restricted_Profile
;
13657 -- We may need two calls to properly initialize the object, one to
13658 -- Initialize_Protection, and possibly one to Install_Handlers if we
13659 -- have a pragma Attach_Handler.
13661 -- Get protected declaration. In the case of a task type declaration,
13662 -- this is simply the parent of the protected type entity. In the single
13663 -- protected object declaration, this parent will be the implicit type,
13664 -- and we can find the corresponding single protected object declaration
13665 -- by searching forward in the declaration list in the tree.
13667 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13668 -- of this type should have been removed during semantic analysis.
13670 Pdec
:= Parent
(Ptyp
);
13671 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13672 N_Single_Protected_Declaration
)
13677 -- Build the parameter list for the call. Note that _Init is the name
13678 -- of the formal for the object to be initialized, which is the task
13679 -- value record itself.
13683 -- For lock-free implementation, skip initializations of the Protection
13686 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13687 -- Object parameter. This is a pointer to the object of type
13688 -- Protection used by the GNARL to control the protected object.
13691 Make_Attribute_Reference
(Loc
,
13693 Make_Selected_Component
(Loc
,
13694 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13695 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13696 Attribute_Name
=> Name_Unchecked_Access
));
13698 -- Priority parameter. Set to Unspecified_Priority unless there is a
13699 -- Priority rep item, in which case we take the value from the pragma
13700 -- or attribute definition clause, or there is an Interrupt_Priority
13701 -- rep item and no Priority rep item, and we set the ceiling to
13702 -- Interrupt_Priority'Last, an implementation-defined value, see
13705 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13707 Prio_Clause
: constant Node_Id
:=
13709 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13716 if Nkind
(Prio_Clause
) = N_Pragma
then
13719 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13721 -- Get_Rep_Item returns either priority pragma.
13723 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13724 Prio_Type
:= RTE
(RE_Any_Priority
);
13726 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13729 -- Attribute definition clause Priority
13732 if Chars
(Prio_Clause
) = Name_Priority
then
13733 Prio_Type
:= RTE
(RE_Any_Priority
);
13735 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13738 Prio
:= Expression
(Prio_Clause
);
13741 -- Always create a locale variable to capture the priority.
13742 -- The priority is also passed to Install_Restriced_Handlers.
13743 -- Note that it is really necessary to create this variable
13744 -- explicitly. It might be thought that removing side effects
13745 -- would the appropriate approach, but that could generate
13746 -- declarations improperly placed in the enclosing scope.
13748 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13750 Make_Object_Declaration
(Loc
,
13751 Defining_Identifier
=> Prio_Var
,
13752 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13753 Expression
=> Relocate_Node
(Prio
)));
13755 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13758 -- When no priority is specified but an xx_Handler pragma is, we
13759 -- default to System.Interrupts.Default_Interrupt_Priority, see
13762 elsif Has_Attach_Handler
(Ptyp
)
13763 or else Has_Interrupt_Handler
(Ptyp
)
13766 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13768 -- Normal case, no priority or xx_Handler specified, default priority
13772 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13775 -- Test for Compiler_Info parameter. This parameter allows entry body
13776 -- procedures and barrier functions to be called from the runtime. It
13777 -- is a pointer to the record generated by the compiler to represent
13778 -- the protected object.
13780 -- A protected type without entries that covers an interface and
13781 -- overrides the abstract routines with protected procedures is
13782 -- considered equivalent to a protected type with entries in the
13783 -- context of dispatching select statements.
13785 -- Protected types with interrupt handlers (when not using a
13786 -- restricted profile) are also considered equivalent to protected
13787 -- types with entries.
13789 -- The types which are used (Static_Interrupt_Protection and
13790 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13793 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13795 Called_Subp
: RE_Id
;
13799 when System_Tasking_Protected_Objects_Entries
=>
13800 Called_Subp
:= RE_Initialize_Protection_Entries
;
13802 -- Argument Compiler_Info
13805 Make_Attribute_Reference
(Loc
,
13806 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13807 Attribute_Name
=> Name_Address
));
13809 when System_Tasking_Protected_Objects_Single_Entry
=>
13810 Called_Subp
:= RE_Initialize_Protection_Entry
;
13812 -- Argument Compiler_Info
13815 Make_Attribute_Reference
(Loc
,
13816 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13817 Attribute_Name
=> Name_Address
));
13819 when System_Tasking_Protected_Objects
=>
13820 Called_Subp
:= RE_Initialize_Protection
;
13823 raise Program_Error
;
13826 -- Entry_Bodies parameter. This is a pointer to an array of
13827 -- pointers to the entry body procedures and barrier functions of
13828 -- the object. If the protected type has no entries this object
13829 -- will not exist, in this case, pass a null (it can happen when
13830 -- there are protected interrupt handlers or interfaces).
13833 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13835 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13836 -- multiple entries).
13839 Make_Attribute_Reference
(Loc
,
13840 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13841 Attribute_Name
=> Name_Unrestricted_Access
));
13843 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13845 -- Find index mapping function (clumsy but ok for now)
13847 while Ekind
(P_Arr
) /= E_Function
loop
13848 Next_Entity
(P_Arr
);
13852 Make_Attribute_Reference
(Loc
,
13853 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
13854 Attribute_Name
=> Name_Unrestricted_Access
));
13857 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13859 -- This is the case where we have a protected object with
13860 -- interfaces and no entries, and the single entry restriction
13861 -- is in effect. We pass a null pointer for the entry
13862 -- parameter because there is no actual entry.
13864 Append_To
(Args
, Make_Null
(Loc
));
13866 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13868 -- This is the case where we have a protected object with no
13870 -- - either interrupt handlers with non restricted profile,
13872 -- Note that the types which are used for interrupt handlers
13873 -- (Static/Dynamic_Interrupt_Protection) are derived from
13874 -- Protection_Entries. We pass two null pointers because there
13875 -- is no actual entry, and the initialization procedure needs
13876 -- both Entry_Bodies and Find_Body_Index.
13878 Append_To
(Args
, Make_Null
(Loc
));
13879 Append_To
(Args
, Make_Null
(Loc
));
13883 Make_Procedure_Call_Statement
(Loc
,
13885 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
13886 Parameter_Associations
=> Args
));
13890 if Has_Attach_Handler
(Ptyp
) then
13892 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13893 -- make the following call:
13895 -- Install_Handlers (_object,
13896 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13898 -- or, in the case of Ravenscar:
13900 -- Install_Restricted_Handlers
13901 -- (Prio, (Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13904 Args
: constant List_Id
:= New_List
;
13905 Table
: constant List_Id
:= New_List
;
13906 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13909 -- Build the Priority parameter (only for ravenscar)
13913 -- Priority comes from a pragma
13915 if Present
(Prio_Var
) then
13916 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13918 -- Priority is the default one
13923 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
13927 -- Build the Attach_Handler table argument
13929 while Present
(Ritem
) loop
13930 if Nkind
(Ritem
) = N_Pragma
13931 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13934 Handler
: constant Node_Id
:=
13935 First
(Pragma_Argument_Associations
(Ritem
));
13937 Interrupt
: constant Node_Id
:= Next
(Handler
);
13938 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13942 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13943 Unchecked_Convert_To
13944 (RTE
(RE_System_Interrupt_Id
), Expr
),
13945 Make_Attribute_Reference
(Loc
,
13947 Make_Selected_Component
(Loc
,
13949 Make_Identifier
(Loc
, Name_uInit
),
13951 Duplicate_Subexpr_No_Checks
13952 (Expression
(Handler
))),
13953 Attribute_Name
=> Name_Access
))));
13957 Next_Rep_Item
(Ritem
);
13960 -- Append the table argument we just built
13962 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13964 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13965 -- call to the statements.
13968 -- Call a simplified version of Install_Handlers to be used
13969 -- when the Ravenscar restrictions are in effect
13970 -- (Install_Restricted_Handlers).
13973 Make_Procedure_Call_Statement
(Loc
,
13976 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13977 Parameter_Associations
=> Args
));
13980 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13982 -- First, prepends the _object argument
13985 Make_Attribute_Reference
(Loc
,
13987 Make_Selected_Component
(Loc
,
13988 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13990 Make_Identifier
(Loc
, Name_uObject
)),
13991 Attribute_Name
=> Name_Unchecked_Access
));
13994 -- Then, insert call to Install_Handlers
13997 Make_Procedure_Call_Statement
(Loc
,
13999 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
14000 Parameter_Associations
=> Args
));
14006 end Make_Initialize_Protection
;
14008 ---------------------------
14009 -- Make_Task_Create_Call --
14010 ---------------------------
14012 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
14013 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14023 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14024 Tnam
:= Chars
(Ttyp
);
14026 -- Get task declaration. In the case of a task type declaration, this is
14027 -- simply the parent of the task type entity. In the single task
14028 -- declaration, this parent will be the implicit type, and we can find
14029 -- the corresponding single task declaration by searching forward in the
14030 -- declaration list in the tree.
14032 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14033 -- this type should have been removed during semantic analysis.
14035 Tdec
:= Parent
(Ttyp
);
14036 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
14037 N_Single_Task_Declaration
)
14042 -- Now we can find the task definition from this declaration
14044 Tdef
:= Task_Definition
(Tdec
);
14046 -- Build the parameter list for the call. Note that _Init is the name
14047 -- of the formal for the object to be initialized, which is the task
14048 -- value record itself.
14052 -- Priority parameter. Set to Unspecified_Priority unless there is a
14053 -- Priority rep item, in which case we take the value from the rep item.
14055 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14057 Make_Selected_Component
(Loc
,
14058 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14059 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14062 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14065 -- Optional Stack parameter
14067 if Restricted_Profile
then
14069 -- If the stack has been preallocated by the expander then
14070 -- pass its address. Otherwise, pass a null address.
14072 if Preallocated_Stacks_On_Target
then
14074 Make_Attribute_Reference
(Loc
,
14076 Make_Selected_Component
(Loc
,
14077 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14078 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14079 Attribute_Name
=> Name_Address
));
14083 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14087 -- Size parameter. If no Storage_Size pragma is present, then
14088 -- the size is taken from the taskZ variable for the type, which
14089 -- is either Unspecified_Size, or has been reset by the use of
14090 -- a Storage_Size attribute definition clause. If a pragma is
14091 -- present, then the size is taken from the _Size field of the
14092 -- task value record, which was set from the pragma value.
14095 and then Has_Storage_Size_Pragma
(Tdef
)
14098 Make_Selected_Component
(Loc
,
14099 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14100 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14104 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14107 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14108 -- Task_Info pragma, in which case we take the value from the pragma.
14110 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14112 Make_Selected_Component
(Loc
,
14113 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14114 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14118 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14121 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14122 -- in which case we take the value from the rep item. The parameter is
14123 -- passed as an Integer because in the case of unspecified CPU the
14124 -- value is not in the range of CPU_Range.
14126 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14128 Convert_To
(Standard_Integer
,
14129 Make_Selected_Component
(Loc
,
14130 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14131 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14134 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14137 if not Restricted_Profile
then
14139 -- Deadline parameter. If no Relative_Deadline pragma is present,
14140 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14141 -- the deadline is taken from the _Relative_Deadline field of the
14142 -- task value record, which was set from the pragma value. Note that
14143 -- this parameter must not be generated for the restricted profiles
14144 -- since Ravenscar does not allow deadlines.
14146 -- Case where pragma Relative_Deadline applies: use given value
14149 and then Has_Relative_Deadline_Pragma
(Tdef
)
14152 Make_Selected_Component
(Loc
,
14153 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14155 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14157 -- No pragma Relative_Deadline apply to the task
14161 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14164 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14165 -- present, then the dispatching domain is null. If a rep item is
14166 -- present, then the dispatching domain is taken from the
14167 -- _Dispatching_Domain field of the task value record, which was set
14168 -- from the rep item value. Note that this parameter must not be
14169 -- generated for the restricted profiles since Ravenscar does not
14170 -- allow dispatching domains.
14172 -- Case where Dispatching_Domain rep item applies: use given value
14175 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14178 Make_Selected_Component
(Loc
,
14180 Make_Identifier
(Loc
, Name_uInit
),
14182 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14184 -- No pragma or aspect Dispatching_Domain apply to the task
14187 Append_To
(Args
, Make_Null
(Loc
));
14190 -- Number of entries. This is an expression of the form:
14192 -- n + _Init.a'Length + _Init.a'B'Length + ...
14194 -- where a,b... are the entry family names for the task definition
14197 Build_Entry_Count_Expression
14202 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
14204 Append_To
(Args
, Ecount
);
14206 -- Master parameter. This is a reference to the _Master parameter of
14207 -- the initialization procedure, except in the case of the pragma
14208 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14209 -- System.Tasking.Library_Task_Level.
14211 if Restriction_Active
(No_Task_Hierarchy
) = False then
14212 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14215 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14219 -- State parameter. This is a pointer to the task body procedure. The
14220 -- required value is obtained by taking 'Unrestricted_Access of the task
14221 -- body procedure and converting it (with an unchecked conversion) to
14222 -- the type required by the task kernel. For further details, see the
14223 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14224 -- than 'Address in order to avoid creating trampolines.
14227 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14228 Subp_Ptr_Typ
: constant Node_Id
:=
14229 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14230 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14233 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14234 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14236 -- Be sure to freeze a reference to the access-to-subprogram type,
14237 -- otherwise gigi will complain that it's in the wrong scope, because
14238 -- it's actually inside the init procedure for the record type that
14239 -- corresponds to the task type.
14241 -- This processing is causing a crash in the .NET/JVM back ends that
14242 -- is not yet understood, so skip it in these cases ???
14244 if VM_Target
= No_VM
then
14245 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14246 Append_Freeze_Action
(Task_Rec
, Ref
);
14249 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14250 Make_Qualified_Expression
(Loc
,
14251 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14253 Make_Attribute_Reference
(Loc
,
14254 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14255 Attribute_Name
=> Name_Unrestricted_Access
))));
14257 -- For the .NET/JVM cases revert to the original code below ???
14261 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14262 Make_Attribute_Reference
(Loc
,
14263 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14264 Attribute_Name
=> Name_Address
)));
14268 -- Discriminants parameter. This is just the address of the task
14269 -- value record itself (which contains the discriminant values
14272 Make_Attribute_Reference
(Loc
,
14273 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14274 Attribute_Name
=> Name_Address
));
14276 -- Elaborated parameter. This is an access to the elaboration Boolean
14279 Make_Attribute_Reference
(Loc
,
14280 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14281 Attribute_Name
=> Name_Unchecked_Access
));
14283 -- Add Chain parameter (not done for sequential elaboration policy, see
14284 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14286 if Partition_Elaboration_Policy
/= 'S' then
14287 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14290 -- Task name parameter. Take this from the _Task_Id parameter to the
14291 -- init call unless there is a Task_Name pragma, in which case we take
14292 -- the value from the pragma.
14294 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14295 -- Copy expression in full, because it may be dynamic and have
14302 (Pragma_Argument_Associations
14304 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14307 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14310 -- Created_Task parameter. This is the _Task_Id field of the task
14314 Make_Selected_Component
(Loc
,
14315 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14316 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14322 if Restricted_Profile
then
14323 if Partition_Elaboration_Policy
= 'S' then
14324 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14326 Create_RE
:= RE_Create_Restricted_Task
;
14329 Create_RE
:= RE_Create_Task
;
14332 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14336 Make_Procedure_Call_Statement
(Loc
,
14338 Parameter_Associations
=> Args
);
14339 end Make_Task_Create_Call
;
14341 ------------------------------
14342 -- Next_Protected_Operation --
14343 ------------------------------
14345 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14349 Next_Op
:= Next
(N
);
14350 while Present
(Next_Op
)
14351 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
14357 end Next_Protected_Operation
;
14359 ---------------------
14360 -- Null_Statements --
14361 ---------------------
14363 function Null_Statements
(Stats
: List_Id
) return Boolean is
14367 Stmt
:= First
(Stats
);
14368 while Nkind
(Stmt
) /= N_Empty
14369 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14371 (Nkind
(Stmt
) = N_Pragma
14373 Nam_In
(Pragma_Name
(Stmt
), Name_Unreferenced
,
14380 return Nkind
(Stmt
) = N_Empty
;
14381 end Null_Statements
;
14383 --------------------------
14384 -- Parameter_Block_Pack --
14385 --------------------------
14387 function Parameter_Block_Pack
14389 Blk_Typ
: Entity_Id
;
14393 Stmts
: List_Id
) return Node_Id
14395 Actual
: Entity_Id
;
14396 Expr
: Node_Id
:= Empty
;
14397 Formal
: Entity_Id
;
14398 Has_Param
: Boolean := False;
14401 Temp_Asn
: Node_Id
;
14402 Temp_Nam
: Node_Id
;
14405 Actual
:= First
(Actuals
);
14406 Formal
:= Defining_Identifier
(First
(Formals
));
14407 Params
:= New_List
;
14408 while Present
(Actual
) loop
14409 if Is_By_Copy_Type
(Etype
(Actual
)) then
14411 -- Jnn : aliased <formal-type>
14413 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14416 Make_Object_Declaration
(Loc
,
14417 Aliased_Present
=> True,
14418 Defining_Identifier
=> Temp_Nam
,
14419 Object_Definition
=>
14420 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14422 if Ekind
(Formal
) /= E_Out_Parameter
then
14428 New_Occurrence_Of
(Temp_Nam
, Loc
);
14430 Set_Assignment_OK
(Temp_Asn
);
14433 Make_Assignment_Statement
(Loc
,
14435 Expression
=> New_Copy_Tree
(Actual
)));
14439 -- Jnn'unchecked_access
14442 Make_Attribute_Reference
(Loc
,
14443 Attribute_Name
=> Name_Unchecked_Access
,
14444 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14448 -- The controlling parameter is omitted
14451 if not Is_Controlling_Actual
(Actual
) then
14453 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14459 Next_Actual
(Actual
);
14460 Next_Formal_With_Extras
(Formal
);
14464 Expr
:= Make_Aggregate
(Loc
, Params
);
14469 -- J1'unchecked_access;
14470 -- <actual2>'reference;
14473 P
:= Make_Temporary
(Loc
, 'P');
14476 Make_Object_Declaration
(Loc
,
14477 Defining_Identifier
=> P
,
14478 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14479 Expression
=> Expr
));
14482 end Parameter_Block_Pack
;
14484 ----------------------------
14485 -- Parameter_Block_Unpack --
14486 ----------------------------
14488 function Parameter_Block_Unpack
14492 Formals
: List_Id
) return List_Id
14494 Actual
: Entity_Id
;
14496 Formal
: Entity_Id
;
14497 Has_Asnmt
: Boolean := False;
14498 Result
: constant List_Id
:= New_List
;
14501 Actual
:= First
(Actuals
);
14502 Formal
:= Defining_Identifier
(First
(Formals
));
14503 while Present
(Actual
) loop
14504 if Is_By_Copy_Type
(Etype
(Actual
))
14505 and then Ekind
(Formal
) /= E_In_Parameter
14508 -- <actual> := P.<formal>;
14511 Make_Assignment_Statement
(Loc
,
14515 Make_Explicit_Dereference
(Loc
,
14516 Make_Selected_Component
(Loc
,
14518 New_Occurrence_Of
(P
, Loc
),
14520 Make_Identifier
(Loc
, Chars
(Formal
)))));
14522 Set_Assignment_OK
(Name
(Asnmt
));
14523 Append_To
(Result
, Asnmt
);
14528 Next_Actual
(Actual
);
14529 Next_Formal_With_Extras
(Formal
);
14535 return New_List
(Make_Null_Statement
(Loc
));
14537 end Parameter_Block_Unpack
;
14539 ----------------------
14540 -- Set_Discriminals --
14541 ----------------------
14543 procedure Set_Discriminals
(Dec
: Node_Id
) is
14546 D_Minal
: Entity_Id
;
14549 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14550 Pdef
:= Defining_Identifier
(Dec
);
14552 if Has_Discriminants
(Pdef
) then
14553 D
:= First_Discriminant
(Pdef
);
14554 while Present
(D
) loop
14556 Make_Defining_Identifier
(Sloc
(D
),
14557 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14559 Set_Ekind
(D_Minal
, E_Constant
);
14560 Set_Etype
(D_Minal
, Etype
(D
));
14561 Set_Scope
(D_Minal
, Pdef
);
14562 Set_Discriminal
(D
, D_Minal
);
14563 Set_Discriminal_Link
(D_Minal
, D
);
14565 Next_Discriminant
(D
);
14568 end Set_Discriminals
;
14570 -----------------------
14571 -- Trivial_Accept_OK --
14572 -----------------------
14574 function Trivial_Accept_OK
return Boolean is
14576 case Opt
.Task_Dispatching_Policy
is
14578 -- If we have the default task dispatching policy in effect, we can
14579 -- definitely do the optimization (one way of looking at this is to
14580 -- think of the formal definition of the default policy being allowed
14581 -- to run any task it likes after a rendezvous, so even if notionally
14582 -- a full rescheduling occurs, we can say that our dispatching policy
14583 -- (i.e. the default dispatching policy) reorders the queue to be the
14584 -- same as just before the call.
14589 -- FIFO_Within_Priorities certainly does not permit this
14590 -- optimization since the Rendezvous is a scheduling action that may
14591 -- require some other task to be run.
14596 -- For now, disallow the optimization for all other policies. This
14597 -- may be over-conservative, but it is certainly not incorrect.
14603 end Trivial_Accept_OK
;