1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Exp_Ch3
; use Exp_Ch3
;
32 with Exp_Ch6
; use Exp_Ch6
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Dbug
; use Exp_Dbug
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Sel
; use Exp_Sel
;
37 with Exp_Smem
; use Exp_Smem
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Exp_Util
; use Exp_Util
;
40 with Freeze
; use Freeze
;
42 with Itypes
; use Itypes
;
43 with Namet
; use Namet
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Ch9
; use Sem_Ch9
;
55 with Sem_Ch11
; use Sem_Ch11
;
56 with Sem_Elab
; use Sem_Elab
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Util
; use Sem_Util
;
60 with Sinfo
; use Sinfo
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Stringt
; use Stringt
;
64 with Targparm
; use Targparm
;
65 with Tbuild
; use Tbuild
;
66 with Uintp
; use Uintp
;
68 package body Exp_Ch9
is
70 -- The following constant establishes the upper bound for the index of
71 -- an entry family. It is used to limit the allocated size of protected
72 -- types with defaulted discriminant of an integer type, when the bound
73 -- of some entry family depends on a discriminant. The limitation to
74 -- entry families of 128K should be reasonable in all cases, and is a
75 -- documented 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
206 -- freeze 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
242 -- the associated protected object, and then enters a block that contains
243 -- a call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires
245 -- a cleanup handler that unlocks the object in all cases.
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
266 -- character appended. This is used for internal subprograms generated
267 -- for operations of protected types, including barrier functions.
268 -- For the subprograms generated for entry bodies and entry barriers,
269 -- the generated name includes a sequence number that makes names
270 -- unique in the presence of entry overloading. This is necessary
271 -- because entry body procedures and barrier functions all have the
274 procedure Build_Simple_Entry_Call
279 -- Some comments here would be useful ???
281 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
282 -- This routine constructs a specification for the procedure that we will
283 -- build for the task body for task type T. The spec has the form:
285 -- procedure tnameB (_Task : access tnameV);
287 -- where name is the character name taken from the task type entity that
288 -- is passed as the argument to the procedure, and tnameV is the task
289 -- value type that is associated with the task type.
291 function Build_Unprotected_Subprogram_Body
293 Pid
: Node_Id
) return Node_Id
;
294 -- This routine constructs the unprotected version of a protected
295 -- subprogram body, which is contains all of the code in the
296 -- original, unexpanded body. This is the version of the protected
297 -- subprogram that is called from all protected operations on the same
298 -- object, including the protected version of the same subprogram.
300 procedure Build_Wrapper_Bodies
304 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
305 -- record of a concurrent type. N is the insertion node where all bodies
306 -- will be placed. This routine builds the bodies of the subprograms which
307 -- serve as an indirection mechanism to overriding primitives of concurrent
308 -- types, entries and protected procedures. Any new body is analyzed.
310 procedure Build_Wrapper_Specs
314 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
315 -- record of a concurrent type. N is the insertion node where all specs
316 -- will be placed. This routine builds the specs of the subprograms which
317 -- serve as an indirection mechanism to overriding primitives of concurrent
318 -- types, entries and protected procedures. Any new spec is analyzed.
320 procedure Collect_Entry_Families
323 Current_Node
: in out Node_Id
;
324 Conctyp
: Entity_Id
);
325 -- For each entry family in a concurrent type, create an anonymous array
326 -- type of the right size, and add a component to the corresponding_record.
328 function Concurrent_Object
329 (Spec_Id
: Entity_Id
;
330 Conc_Typ
: Entity_Id
) return Entity_Id
;
331 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
332 -- the entity associated with the concurrent object in the Protected_Body_
333 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
334 -- denotes formal parameter _O, _object or _task.
336 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
337 -- Copy the result type of a function specification, when building the
338 -- internal operation corresponding to a protected function, or when
339 -- expanding an access to protected function. If the result is an anonymous
340 -- access to subprogram itself, we need to create a new signature with the
341 -- same parameter names and the same resolved types, but with new entities
344 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
345 -- Decls is a list which may contain the declarations created by Install_
346 -- Private_Data_Declarations. All generated entities are marked as needing
347 -- debug info and debug nodes are manually generation where necessary. This
348 -- step of the expansion must to be done after private data has been moved
349 -- to its final resting scope to ensure proper visibility of debug objects.
351 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
352 -- If control flow optimizations are suppressed, and Alt is an accept,
353 -- delay, or entry call alternative with no trailing statements, insert a
354 -- null trailing statement with the given Loc (which is the sloc of the
355 -- accept, delay, or entry call statement). There might not be any
356 -- generated code for the accept, delay, or entry call itself (the
357 -- effect of these statements is part of the general processsing done
358 -- for the enclosing selective accept, timed entry call, or asynchronous
359 -- select), and the null statement is there to carry the sloc of that
360 -- statement to the back-end for trace-based coverage analysis purposes.
362 procedure Extract_Dispatching_Call
364 Call_Ent
: out Entity_Id
;
365 Object
: out Entity_Id
;
366 Actuals
: out List_Id
;
367 Formals
: out List_Id
);
368 -- Given a dispatching call, extract the entity of the name of the call,
369 -- its actual dispatching object, its actual parameters and the formal
370 -- parameters of the overridden interface-level version. If the type of
371 -- the dispatching object is an access type then an explicit dereference
372 -- is returned in Object.
374 procedure Extract_Entry
376 Concval
: out Node_Id
;
378 Index
: out Node_Id
);
379 -- Given an entry call, returns the associated concurrent object,
380 -- the entry name, and the entry family index.
382 function Family_Offset
387 Cap
: Boolean) return Node_Id
;
388 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in
389 -- an accept statement, or the upper bound in the discrete subtype of
390 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
391 -- the concurrent type of the entry. If Cap is true, the result is
392 -- capped according to Entry_Family_Bound.
399 Cap
: Boolean) return Node_Id
;
400 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
401 -- a family, and handle properly the superflat case. This is equivalent
402 -- to the use of 'Length on the index type, but must use Family_Offset
403 -- to handle properly the case of bounds that depend on discriminants.
404 -- If Cap is true, the result is capped according to Entry_Family_Bound.
406 procedure Find_Enclosing_Context
408 Context
: out Node_Id
;
409 Context_Id
: out Entity_Id
;
410 Context_Decls
: out List_Id
);
411 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
412 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
413 -- nearest enclosing body, block, package or return statement and return
414 -- its constituents. Context is the enclosing construct, Context_Id is
415 -- the scope of Context_Id and Context_Decls is the declarative list of
418 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
419 -- Given a subprogram identifier, return the entity which is associated
420 -- with the protection entry index in the Protected_Body_Subprogram or the
421 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
424 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
425 -- Tell whether a given subprogram cannot raise an exception
427 function Is_Potentially_Large_Family
428 (Base_Index
: Entity_Id
;
431 Hi
: Node_Id
) return Boolean;
433 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
434 -- Determine whether Id is a function or a procedure and is marked as a
435 -- private primitive.
437 function Null_Statements
(Stats
: List_Id
) return Boolean;
438 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
439 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
440 -- well to still count as null. Returns True for a null sequence. The
441 -- argument is the list of statements from the DO-END sequence.
443 function Parameter_Block_Pack
449 Stmts
: List_Id
) return Entity_Id
;
450 -- Set the components of the generated parameter block with the values of
451 -- the actual parameters. Generate aliased temporaries to capture the
452 -- values for types that are passed by copy. Otherwise generate a reference
453 -- to the actual's value. Return the address of the aggregate block.
455 -- Jnn1 : alias <formal-type1>;
456 -- Jnn1 := <actual1>;
459 -- Jnn1'unchecked_access;
460 -- <actual2>'reference;
463 function Parameter_Block_Unpack
467 Formals
: List_Id
) return List_Id
;
468 -- Retrieve the values of the components from the parameter block and
469 -- assign then to the original actual parameters. Generate:
470 -- <actual1> := P.<formal1>;
472 -- <actualN> := P.<formalN>;
474 function Trivial_Accept_OK
return Boolean;
475 -- If there is no DO-END block for an accept, or if the DO-END block has
476 -- only null statements, then it is possible to do the Rendezvous with much
477 -- less overhead using the Accept_Trivial routine in the run-time library.
478 -- However, this is not always a valid optimization. Whether it is valid or
479 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
480 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
481 -- a rescheduling is required, so this optimization is not allowed. This
482 -- function returns True if the optimization is permitted.
484 -----------------------------
485 -- Actual_Index_Expression --
486 -----------------------------
488 function Actual_Index_Expression
492 Tsk
: Entity_Id
) return Node_Id
494 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
502 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
503 -- Compute difference between bounds of entry family
505 --------------------------
506 -- Actual_Family_Offset --
507 --------------------------
509 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
511 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
512 -- Replace a reference to a discriminant with a selected component
513 -- denoting the discriminant of the target task.
515 -----------------------------
516 -- Actual_Discriminant_Ref --
517 -----------------------------
519 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
520 Typ
: constant Entity_Id
:= Etype
(Bound
);
524 if not Is_Entity_Name
(Bound
)
525 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
527 if Nkind
(Bound
) = N_Attribute_Reference
then
530 B
:= New_Copy_Tree
(Bound
);
535 Make_Selected_Component
(Sloc
,
536 Prefix
=> New_Copy_Tree
(Tsk
),
537 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
539 Analyze_And_Resolve
(B
, Typ
);
543 Make_Attribute_Reference
(Sloc
,
544 Attribute_Name
=> Name_Pos
,
545 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
546 Expressions
=> New_List
(B
));
547 end Actual_Discriminant_Ref
;
549 -- Start of processing for Actual_Family_Offset
553 Make_Op_Subtract
(Sloc
,
554 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
555 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
556 end Actual_Family_Offset
;
558 -- Start of processing for Actual_Index_Expression
561 -- The queues of entries and entry families appear in textual order in
562 -- the associated record. The entry index is computed as the sum of the
563 -- number of queues for all entries that precede the designated one, to
564 -- which is added the index expression, if this expression denotes a
565 -- member of a family.
567 -- The following is a place holder for the count of simple entries
569 Num
:= Make_Integer_Literal
(Sloc
, 1);
571 -- We construct an expression which is a series of addition operations.
572 -- See comments in Entry_Index_Expression, which is identical in
575 if Present
(Index
) then
576 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
583 Actual_Family_Offset
(
584 Make_Attribute_Reference
(Sloc
,
585 Attribute_Name
=> Name_Pos
,
586 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
587 Expressions
=> New_List
(Relocate_Node
(Index
))),
588 Type_Low_Bound
(S
)));
593 -- Now add lengths of preceding entries and entry families
595 Prev
:= First_Entity
(Ttyp
);
597 while Chars
(Prev
) /= Chars
(Ent
)
598 or else (Ekind
(Prev
) /= Ekind
(Ent
))
599 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
601 if Ekind
(Prev
) = E_Entry
then
602 Set_Intval
(Num
, Intval
(Num
) + 1);
604 elsif Ekind
(Prev
) = E_Entry_Family
then
606 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
608 -- The need for the following full view retrieval stems from
609 -- this complex case of nested generics and tasking:
612 -- type Formal_Index is range <>;
615 -- type Index is private;
622 -- type Index is new Formal_Index range 1 .. 10;
625 -- package body Outer is
627 -- entry Fam (Index); -- (2)
630 -- package body Inner is -- (3)
638 -- We are currently building the index expression for the entry
639 -- call "T.E" (1). Part of the expansion must mention the range
640 -- of the discrete type "Index" (2) of entry family "Fam".
641 -- However only the private view of type "Index" is available to
642 -- the inner generic (3) because there was no prior mention of
643 -- the type inside "Inner". This visibility requirement is
644 -- implicit and cannot be detected during the construction of
645 -- the generic trees and needs special handling.
648 and then Is_Private_Type
(S
)
649 and then Present
(Full_View
(S
))
654 Lo
:= Type_Low_Bound
(S
);
655 Hi
:= Type_High_Bound
(S
);
663 Actual_Family_Offset
(Hi
, Lo
),
665 Make_Integer_Literal
(Sloc
, 1)));
667 -- Other components are anonymous types to be ignored
677 end Actual_Index_Expression
;
679 --------------------------
680 -- Add_Formal_Renamings --
681 --------------------------
683 procedure Add_Formal_Renamings
689 Ptr
: constant Entity_Id
:=
691 (Next
(First
(Parameter_Specifications
(Spec
))));
692 -- The name of the formal that holds the address of the parameter block
699 Renamed_Formal
: Node_Id
;
702 Formal
:= First_Formal
(Ent
);
703 while Present
(Formal
) loop
704 Comp
:= Entry_Component
(Formal
);
706 Make_Defining_Identifier
(Sloc
(Formal
),
707 Chars
=> Chars
(Formal
));
708 Set_Etype
(New_F
, Etype
(Formal
));
709 Set_Scope
(New_F
, Ent
);
711 -- Now we set debug info needed on New_F even though it does not
712 -- come from source, so that the debugger will get the right
713 -- information for these generated names.
715 Set_Debug_Info_Needed
(New_F
);
717 if Ekind
(Formal
) = E_In_Parameter
then
718 Set_Ekind
(New_F
, E_Constant
);
720 Set_Ekind
(New_F
, E_Variable
);
721 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
724 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
727 Make_Selected_Component
(Loc
,
729 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
730 Make_Identifier
(Loc
, Chars
(Ptr
))),
731 Selector_Name
=> New_Reference_To
(Comp
, Loc
));
734 Build_Renamed_Formal_Declaration
735 (New_F
, Formal
, Comp
, Renamed_Formal
);
737 Append
(Decl
, Decls
);
738 Set_Renamed_Object
(Formal
, New_F
);
739 Next_Formal
(Formal
);
741 end Add_Formal_Renamings
;
743 ------------------------
744 -- Add_Object_Pointer --
745 ------------------------
747 procedure Add_Object_Pointer
749 Conc_Typ
: Entity_Id
;
752 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
757 -- Create the renaming declaration for the Protection object of a
758 -- protected type. _Object is used by Complete_Entry_Body.
759 -- ??? An attempt to make this a renaming was unsuccessful.
761 -- Build the entity for the access type
764 Make_Defining_Identifier
(Loc
,
765 New_External_Name
(Chars
(Rec_Typ
), 'P'));
768 -- _object : poVP := poVP!O;
771 Make_Object_Declaration
(Loc
,
772 Defining_Identifier
=>
773 Make_Defining_Identifier
(Loc
, Name_uObject
),
775 New_Reference_To
(Obj_Ptr
, Loc
),
777 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
778 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
779 Prepend_To
(Decls
, Decl
);
782 -- type poVP is access poV;
785 Make_Full_Type_Declaration
(Loc
,
786 Defining_Identifier
=>
789 Make_Access_To_Object_Definition
(Loc
,
790 Subtype_Indication
=>
791 New_Reference_To
(Rec_Typ
, Loc
)));
792 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
793 Prepend_To
(Decls
, Decl
);
794 end Add_Object_Pointer
;
796 -----------------------
797 -- Build_Accept_Body --
798 -----------------------
800 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
801 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
802 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
809 -- At the end of the statement sequence, Complete_Rendezvous is called.
810 -- A label skipping the Complete_Rendezvous, and all other accept
811 -- processing, has already been added for the expansion of requeue
812 -- statements. The Sloc is copied from the last statement since it
813 -- is really part of this last statement.
817 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
818 Insert_Before
(Last
(Statements
(Stats
)), Call
);
821 -- If exception handlers are present, then append Complete_Rendezvous
822 -- calls to the handlers, and construct the required outer block. As
823 -- above, the Sloc is copied from the last statement in the sequence.
825 if Present
(Exception_Handlers
(Stats
)) then
826 Hand
:= First
(Exception_Handlers
(Stats
));
827 while Present
(Hand
) loop
830 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
831 Append
(Call
, Statements
(Hand
));
837 Make_Handled_Sequence_Of_Statements
(Loc
,
838 Statements
=> New_List
(
839 Make_Block_Statement
(Loc
,
840 Handled_Statement_Sequence
=> Stats
)));
846 -- At this stage we know that the new statement sequence does not
847 -- have an exception handler part, so we supply one to call
848 -- Exceptional_Complete_Rendezvous. This handler is
850 -- when all others =>
851 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
853 -- We handle Abort_Signal to make sure that we properly catch the abort
854 -- case and wake up the caller.
856 Ohandle
:= Make_Others_Choice
(Loc
);
857 Set_All_Others
(Ohandle
);
859 Set_Exception_Handlers
(New_S
,
861 Make_Implicit_Exception_Handler
(Loc
,
862 Exception_Choices
=> New_List
(Ohandle
),
864 Statements
=> New_List
(
865 Make_Procedure_Call_Statement
(Sloc
(Stats
),
866 Name
=> New_Reference_To
(
867 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
868 Parameter_Associations
=> New_List
(
869 Make_Function_Call
(Sloc
(Stats
),
870 Name
=> New_Reference_To
(
871 RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
873 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
874 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
875 Expand_Exception_Handlers
(New_S
);
877 -- Exceptional_Complete_Rendezvous must be called with abort
878 -- still deferred, which is the case for a "when all others" handler.
881 end Build_Accept_Body
;
883 -----------------------------------
884 -- Build_Activation_Chain_Entity --
885 -----------------------------------
887 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
888 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
889 -- Determine whether an extended return statement has an activation
892 --------------------------
893 -- Has_Activation_Chain --
894 --------------------------
896 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
900 Decl
:= First
(Return_Object_Declarations
(Stmt
));
901 while Present
(Decl
) loop
902 if Nkind
(Decl
) = N_Object_Declaration
903 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
912 end Has_Activation_Chain
;
917 Context_Id
: Entity_Id
;
920 -- Start of processing for Build_Activation_Chain_Entity
923 -- Activation chain is never used for sequential elaboration policy, see
924 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
926 if Partition_Elaboration_Policy
= 'S' then
930 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
932 -- If activation chain entity has not been declared already, create one
934 if Nkind
(Context
) = N_Extended_Return_Statement
935 or else No
(Activation_Chain_Entity
(Context
))
937 -- Since extended return statements do not store the entity of the
938 -- chain, examine the return object declarations to avoid creating
941 if Nkind
(Context
) = N_Extended_Return_Statement
942 and then Has_Activation_Chain
(Context
)
948 Loc
: constant Source_Ptr
:= Sloc
(Context
);
953 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
955 -- Note: An extended return statement is not really a task
956 -- activator, but it does have an activation chain on which to
957 -- store the tasks temporarily. On successful return, the tasks
958 -- on this chain are moved to the chain passed in by the caller.
959 -- We do not build an Activation_Chain_Entity for an extended
960 -- return statement, because we do not want to build a call to
961 -- Activate_Tasks. Task activation is the responsibility of the
964 if Nkind
(Context
) /= N_Extended_Return_Statement
then
965 Set_Activation_Chain_Entity
(Context
, Chain
);
969 Make_Object_Declaration
(Loc
,
970 Defining_Identifier
=> Chain
,
971 Aliased_Present
=> True,
973 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
));
975 Prepend_To
(Decls
, Decl
);
977 -- Ensure that the _chain appears in the proper scope of the
980 if Context_Id
/= Current_Scope
then
981 Push_Scope
(Context_Id
);
989 end Build_Activation_Chain_Entity
;
991 ----------------------------
992 -- Build_Barrier_Function --
993 ----------------------------
995 function Build_Barrier_Function
998 Pid
: Node_Id
) return Node_Id
1000 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
1001 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
1002 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
1003 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
1004 Op_Decls
: constant List_Id
:= New_List
;
1006 Func_Body
: Node_Id
;
1009 -- Add a declaration for the Protection object, renaming declarations
1010 -- for the discriminals and privals and finally a declaration for the
1011 -- entry family index (if applicable).
1013 Install_Private_Data_Declarations
(Sloc
(N
),
1019 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1021 -- If compiling with -fpreserve-control-flow, make sure we insert an
1022 -- IF statement so that the back-end knows to generate a conditional
1023 -- branch instruction, even if the condition is just the name of a
1026 if Opt
.Suppress_Control_Flow_Optimizations
then
1027 Stmt
:= Make_Implicit_If_Statement
(Cond
,
1029 Then_Statements
=> New_List
(
1030 Make_Simple_Return_Statement
(Loc
,
1031 New_Occurrence_Of
(Standard_True
, Loc
))),
1032 Else_Statements
=> New_List
(
1033 Make_Simple_Return_Statement
(Loc
,
1034 New_Occurrence_Of
(Standard_False
, Loc
))));
1037 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1040 -- Note: the condition in the barrier function needs to be properly
1041 -- processed for the C/Fortran boolean possibility, but this happens
1042 -- automatically since the return statement does this normalization.
1045 Make_Subprogram_Body
(Loc
,
1047 Build_Barrier_Function_Specification
(Loc
,
1048 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1049 Declarations
=> Op_Decls
,
1050 Handled_Statement_Sequence
=>
1051 Make_Handled_Sequence_Of_Statements
(Loc
,
1052 Statements
=> New_List
(Stmt
)));
1053 Set_Is_Entry_Barrier_Function
(Func_Body
);
1056 end Build_Barrier_Function
;
1058 ------------------------------------------
1059 -- Build_Barrier_Function_Specification --
1060 ------------------------------------------
1062 function Build_Barrier_Function_Specification
1064 Def_Id
: Entity_Id
) return Node_Id
1067 Set_Debug_Info_Needed
(Def_Id
);
1069 return Make_Function_Specification
(Loc
,
1070 Defining_Unit_Name
=> Def_Id
,
1071 Parameter_Specifications
=> New_List
(
1072 Make_Parameter_Specification
(Loc
,
1073 Defining_Identifier
=>
1074 Make_Defining_Identifier
(Loc
, Name_uO
),
1076 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1078 Make_Parameter_Specification
(Loc
,
1079 Defining_Identifier
=>
1080 Make_Defining_Identifier
(Loc
, Name_uE
),
1082 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1084 Result_Definition
=>
1085 New_Reference_To
(Standard_Boolean
, Loc
));
1086 end Build_Barrier_Function_Specification
;
1088 --------------------------
1089 -- Build_Call_With_Task --
1090 --------------------------
1092 function Build_Call_With_Task
1094 E
: Entity_Id
) return Node_Id
1096 Loc
: constant Source_Ptr
:= Sloc
(N
);
1099 Make_Function_Call
(Loc
,
1100 Name
=> New_Reference_To
(E
, Loc
),
1101 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1102 end Build_Call_With_Task
;
1104 -----------------------------
1105 -- Build_Class_Wide_Master --
1106 -----------------------------
1108 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1109 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1110 Master_Id
: Entity_Id
;
1111 Master_Scope
: Entity_Id
;
1113 Related_Node
: Node_Id
;
1117 -- Nothing to do if there is no task hierarchy
1119 if Restriction_Active
(No_Task_Hierarchy
) then
1123 -- Find the declaration that created the access type. It is either a
1124 -- type declaration, or an object declaration with an access definition,
1125 -- in which case the type is anonymous.
1127 if Is_Itype
(Typ
) then
1128 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1130 Related_Node
:= Parent
(Typ
);
1133 Master_Scope
:= Find_Master_Scope
(Typ
);
1135 -- Nothing to do if the master scope already contains a _master entity.
1136 -- The only exception to this is the following scenario:
1139 -- Transient_Scope_1
1142 -- Transient_Scope_2
1145 -- In this case the source scope is marked as having the master entity
1146 -- even though the actual declaration appears inside an inner scope. If
1147 -- the second transient scope requires a _master, it cannot use the one
1148 -- already declared because the entity is not visible.
1150 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1152 if not Has_Master_Entity
(Master_Scope
)
1153 or else No
(Current_Entity_In_Scope
(Name_Id
))
1156 Master_Decl
: Node_Id
;
1159 Set_Has_Master_Entity
(Master_Scope
);
1162 -- _master : constant Integer := Current_Master.all;
1165 Make_Object_Declaration
(Loc
,
1166 Defining_Identifier
=>
1167 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1168 Constant_Present
=> True,
1169 Object_Definition
=>
1170 New_Reference_To
(Standard_Integer
, Loc
),
1172 Make_Explicit_Dereference
(Loc
,
1173 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
1175 Insert_Action
(Related_Node
, Master_Decl
);
1176 Analyze
(Master_Decl
);
1178 -- Mark the containing scope as a task master. Masters associated
1179 -- with return statements are already marked at this stage (see
1180 -- Analyze_Subprogram_Body).
1182 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1184 Par
: Node_Id
:= Related_Node
;
1187 while Nkind
(Par
) /= N_Compilation_Unit
loop
1188 Par
:= Parent
(Par
);
1190 -- If we fall off the top, we are at the outer level, and
1191 -- the environment task is our effective master, so
1194 if Nkind_In
(Par
, N_Block_Statement
,
1198 Set_Is_Task_Master
(Par
);
1208 Make_Defining_Identifier
(Loc
,
1209 New_External_Name
(Chars
(Typ
), 'M'));
1212 -- Mnn renames _master;
1215 Make_Object_Renaming_Declaration
(Loc
,
1216 Defining_Identifier
=> Master_Id
,
1217 Subtype_Mark
=> New_Reference_To
(Standard_Integer
, Loc
),
1220 Insert_Action
(Related_Node
, Ren_Decl
);
1222 Set_Master_Id
(Typ
, Master_Id
);
1223 end Build_Class_Wide_Master
;
1225 --------------------------------
1226 -- Build_Corresponding_Record --
1227 --------------------------------
1229 function Build_Corresponding_Record
1232 Loc
: Source_Ptr
) return Node_Id
1234 Rec_Ent
: constant Entity_Id
:=
1235 Make_Defining_Identifier
1236 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1239 New_Disc
: Entity_Id
;
1243 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1244 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1245 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1246 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1247 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1248 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1251 -- Use discriminals to create list of discriminants for record, and
1252 -- create new discriminals for use in default expressions, etc. It is
1253 -- worth noting that a task discriminant gives rise to 5 entities;
1255 -- a) The original discriminant.
1256 -- b) The discriminal for use in the task.
1257 -- c) The discriminant of the corresponding record.
1258 -- d) The discriminal for the init proc of the corresponding record.
1259 -- e) The local variable that renames the discriminant in the procedure
1260 -- for the task body.
1262 -- In fact the discriminals b) are used in the renaming declarations
1263 -- for e). See details in einfo (Handling of Discriminants).
1265 if Present
(Discriminant_Specifications
(N
)) then
1267 Disc
:= First_Discriminant
(Ctyp
);
1269 while Present
(Disc
) loop
1270 New_Disc
:= CR_Discriminant
(Disc
);
1273 Make_Discriminant_Specification
(Loc
,
1274 Defining_Identifier
=> New_Disc
,
1275 Discriminant_Type
=>
1276 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1278 New_Copy
(Discriminant_Default_Value
(Disc
))));
1280 Next_Discriminant
(Disc
);
1287 -- Now we can construct the record type declaration. Note that this
1288 -- record is "limited tagged". It is "limited" to reflect the underlying
1289 -- limitedness of the task or protected object that it represents, and
1290 -- ensuring for example that it is properly passed by reference. It is
1291 -- "tagged" to give support to dispatching calls through interfaces. We
1292 -- propagate here the list of interfaces covered by the concurrent type
1293 -- (Ada 2005: AI-345).
1296 Make_Full_Type_Declaration
(Loc
,
1297 Defining_Identifier
=> Rec_Ent
,
1298 Discriminant_Specifications
=> Dlist
,
1300 Make_Record_Definition
(Loc
,
1302 Make_Component_List
(Loc
,
1303 Component_Items
=> Cdecls
),
1305 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1306 Interface_List
=> Interface_List
(N
),
1307 Limited_Present
=> True));
1308 end Build_Corresponding_Record
;
1310 ---------------------------------
1311 -- Build_Dispatching_Tag_Check --
1312 ---------------------------------
1314 function Build_Dispatching_Tag_Check
1316 N
: Node_Id
) return Node_Id
1318 Loc
: constant Source_Ptr
:= Sloc
(N
);
1323 Left_Opnd
=> New_Reference_To
(K
, Loc
),
1324 Right_Opnd
=> New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1326 Left_Opnd
=> New_Reference_To
(K
, Loc
),
1327 Right_Opnd
=> New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
)));
1328 end Build_Dispatching_Tag_Check
;
1330 ----------------------------------
1331 -- Build_Entry_Count_Expression --
1332 ----------------------------------
1334 function Build_Entry_Count_Expression
1335 (Concurrent_Type
: Node_Id
;
1336 Component_List
: List_Id
;
1337 Loc
: Source_Ptr
) return Node_Id
1349 -- Count number of non-family entries
1352 Ent
:= First_Entity
(Concurrent_Type
);
1353 while Present
(Ent
) loop
1354 if Ekind
(Ent
) = E_Entry
then
1361 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1363 -- Loop through entry families building the addition nodes
1365 Ent
:= First_Entity
(Concurrent_Type
);
1366 Comp
:= First
(Component_List
);
1367 while Present
(Ent
) loop
1368 if Ekind
(Ent
) = E_Entry_Family
then
1369 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1373 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1374 Hi
:= Type_High_Bound
(Typ
);
1375 Lo
:= Type_Low_Bound
(Typ
);
1376 Large
:= Is_Potentially_Large_Family
1377 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1380 Left_Opnd
=> Ecount
,
1381 Right_Opnd
=> Family_Size
1382 (Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1389 end Build_Entry_Count_Expression
;
1391 -----------------------
1392 -- Build_Entry_Names --
1393 -----------------------
1395 procedure Build_Entry_Names
1397 Obj_Typ
: Entity_Id
;
1400 Loc
: constant Source_Ptr
:= Sloc
(Obj_Ref
);
1401 Data
: Entity_Id
:= Empty
;
1402 Index
: Entity_Id
:= Empty
;
1403 Typ
: Entity_Id
:= Obj_Typ
;
1405 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
);
1406 -- Given an entry [family], create a static string which denotes the
1407 -- name of Comp_Id and assign it to the underlying data structure which
1408 -- contains the entry names of a concurrent object.
1410 function Object_Reference
return Node_Id
;
1411 -- Return a reference to field _object or _task_id depending on the
1412 -- concurrent object being processed.
1414 ----------------------
1415 -- Build_Entry_Name --
1416 ----------------------
1418 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
) is
1419 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1420 -- Given a discrete subtype definition of an entry family, generate a
1421 -- range node which covers the range of Def's type.
1423 procedure Create_Index_And_Data
;
1424 -- Generate the declarations of variables Index and Data. Subsequent
1425 -- calls do nothing.
1427 function Increment_Index
return Node_Id
;
1428 -- Increment the index used in the assignment of string names to the
1431 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
;
1432 -- Given the name of a temporary variable, create the following
1433 -- declaration for it:
1435 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1437 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
;
1438 -- Given the name of a temporary variable, place it in the array of
1439 -- string names. Generate:
1441 -- Data (Index) := Def_Id'Unchecked_Access;
1447 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1448 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1449 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1452 -- If a bound references a discriminant, generate an identifier
1453 -- with the same name. Resolution will map it to the formals of
1456 if Is_Entity_Name
(Low
)
1457 and then Ekind
(Entity
(Low
)) = E_Discriminant
1460 Make_Selected_Component
(Loc
,
1461 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1462 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Low
)));
1464 Low
:= New_Copy_Tree
(Low
);
1467 if Is_Entity_Name
(High
)
1468 and then Ekind
(Entity
(High
)) = E_Discriminant
1471 Make_Selected_Component
(Loc
,
1472 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1473 Selector_Name
=> Make_Identifier
(Loc
, Chars
(High
)));
1475 High
:= New_Copy_Tree
(High
);
1481 High_Bound
=> High
);
1484 ---------------------------
1485 -- Create_Index_And_Data --
1486 ---------------------------
1488 procedure Create_Index_And_Data
is
1490 if No
(Index
) and then No
(Data
) then
1497 if Is_Protected_Type
(Typ
) then
1498 Count
:= RO_PE_Number_Of_Entries
;
1499 Data_Typ
:= RE_Protected_Entry_Names_Array
;
1501 Count
:= RO_ST_Number_Of_Entries
;
1502 Data_Typ
:= RE_Task_Entry_Names_Array
;
1505 -- Step 1: Generate the declaration of the index variable:
1507 -- Index : Entry_Index := 1;
1509 Index
:= Make_Temporary
(Loc
, 'I');
1512 Make_Object_Declaration
(Loc
,
1513 Defining_Identifier
=> Index
,
1514 Object_Definition
=>
1515 New_Reference_To
(RTE
(RE_Entry_Index
), Loc
),
1516 Expression
=> Make_Integer_Literal
(Loc
, 1)));
1518 -- Step 2: Generate the declaration of an array to house all
1521 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1522 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1524 Size
:= Make_Temporary
(Loc
, 'S');
1527 Make_Object_Declaration
(Loc
,
1528 Defining_Identifier
=> Size
,
1529 Constant_Present
=> True,
1530 Object_Definition
=>
1531 New_Reference_To
(RTE
(RE_Entry_Index
), Loc
),
1533 Make_Function_Call
(Loc
,
1535 New_Reference_To
(RTE
(Count
), Loc
),
1536 Parameter_Associations
=>
1537 New_List
(Object_Reference
))));
1539 Data
:= Make_Temporary
(Loc
, 'A');
1542 Make_Object_Declaration
(Loc
,
1543 Defining_Identifier
=> Data
,
1544 Aliased_Present
=> True,
1545 Object_Definition
=>
1546 New_Reference_To
(RTE
(Data_Typ
), Loc
),
1548 Make_Aggregate
(Loc
,
1549 Component_Associations
=> New_List
(
1550 Make_Component_Association
(Loc
,
1551 Choices
=> New_List
(
1553 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1554 High_Bound
=> New_Reference_To
(Size
, Loc
))),
1555 Expression
=> Make_Null
(Loc
))))));
1558 end Create_Index_And_Data
;
1560 ---------------------
1561 -- Increment_Index --
1562 ---------------------
1564 function Increment_Index
return Node_Id
is
1567 Make_Assignment_Statement
(Loc
,
1568 Name
=> New_Reference_To
(Index
, Loc
),
1571 Left_Opnd
=> New_Reference_To
(Index
, Loc
),
1572 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
1573 end Increment_Index
;
1575 ----------------------
1576 -- Name_Declaration --
1577 ----------------------
1579 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
is
1582 Make_Object_Declaration
(Loc
,
1583 Defining_Identifier
=> Def_Id
,
1584 Aliased_Present
=> True,
1585 Constant_Present
=> True,
1586 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
1588 Make_String_Literal
(Loc
, String_From_Name_Buffer
));
1589 end Name_Declaration
;
1591 --------------------
1592 -- Set_Entry_Name --
1593 --------------------
1595 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
is
1598 Make_Assignment_Statement
(Loc
,
1600 Make_Indexed_Component
(Loc
,
1601 Prefix
=> New_Reference_To
(Data
, Loc
),
1602 Expressions
=> New_List
(New_Reference_To
(Index
, Loc
))),
1605 Make_Attribute_Reference
(Loc
,
1606 Prefix
=> New_Reference_To
(Def_Id
, Loc
),
1607 Attribute_Name
=> Name_Unchecked_Access
));
1612 Temp_Id
: Entity_Id
;
1615 -- Start of processing for Build_Entry_Name
1618 if Ekind
(Comp_Id
) = E_Entry_Family
then
1619 Subt_Def
:= Discrete_Subtype_Definition
(Parent
(Comp_Id
));
1621 Create_Index_And_Data
;
1623 -- Step 1: Create the string name of the entry family.
1625 -- Temp : aliased constant String := "name ()";
1627 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1628 Get_Name_String
(Chars
(Comp_Id
));
1629 Add_Char_To_Name_Buffer
(' ');
1630 Add_Char_To_Name_Buffer
('(');
1631 Add_Char_To_Name_Buffer
(')');
1633 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1636 -- for Member in Family_Low .. Family_High loop
1637 -- Set_Entry_Name (...);
1638 -- Index := Index + 1;
1642 Make_Loop_Statement
(Loc
,
1644 Make_Iteration_Scheme
(Loc
,
1645 Loop_Parameter_Specification
=>
1646 Make_Loop_Parameter_Specification
(Loc
,
1647 Defining_Identifier
=>
1648 Make_Temporary
(Loc
, 'L'),
1649 Discrete_Subtype_Definition
=>
1650 Build_Range
(Subt_Def
))),
1652 Statements
=> New_List
(
1653 Set_Entry_Name
(Temp_Id
),
1655 End_Label
=> Empty
));
1660 Create_Index_And_Data
;
1662 -- Step 1: Create the string name of the entry. Generate:
1663 -- Temp : aliased constant String := "name";
1665 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1666 Get_Name_String
(Chars
(Comp_Id
));
1668 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1670 -- Step 2: Associate the string name with the underlying data
1673 Append_To
(Stmts
, Set_Entry_Name
(Temp_Id
));
1674 Append_To
(Stmts
, Increment_Index
);
1676 end Build_Entry_Name
;
1678 ----------------------
1679 -- Object_Reference --
1680 ----------------------
1682 function Object_Reference
return Node_Id
is
1683 Conc_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Typ
);
1688 if Is_Protected_Type
(Typ
) then
1689 Field
:= Name_uObject
;
1691 Field
:= Name_uTask_Id
;
1695 Make_Selected_Component
(Loc
,
1697 Unchecked_Convert_To
(Conc_Typ
, New_Copy_Tree
(Obj_Ref
)),
1698 Selector_Name
=> Make_Identifier
(Loc
, Field
));
1700 if Is_Protected_Type
(Typ
) then
1702 Make_Attribute_Reference
(Loc
,
1704 Attribute_Name
=> Name_Unchecked_Access
);
1708 end Object_Reference
;
1715 -- Start of processing for Build_Entry_Names
1718 -- Retrieve the original concurrent type
1720 if Is_Concurrent_Record_Type
(Typ
) then
1721 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1724 pragma Assert
(Is_Concurrent_Type
(Typ
));
1726 -- Nothing to do if the type has no entries
1728 if not Has_Entries
(Typ
) then
1732 -- Avoid generating entry names for a protected type with only one entry
1734 if Is_Protected_Type
(Typ
)
1735 and then Find_Protection_Type
(Base_Type
(Typ
)) /=
1736 RTE
(RE_Protection_Entries
)
1741 -- Step 1: Populate the array with statically generated strings denoting
1742 -- entries and entry family names.
1744 Comp
:= First_Entity
(Typ
);
1745 while Present
(Comp
) loop
1746 if Comes_From_Source
(Comp
)
1747 and then Ekind_In
(Comp
, E_Entry
, E_Entry_Family
)
1749 Build_Entry_Name
(Comp
);
1755 -- Step 2: Associate the array with the related concurrent object:
1757 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1759 if Present
(Data
) then
1760 if Is_Protected_Type
(Typ
) then
1761 Proc
:= RO_PE_Set_Entry_Names
;
1763 Proc
:= RO_ST_Set_Entry_Names
;
1767 Make_Procedure_Call_Statement
(Loc
,
1768 Name
=> New_Reference_To
(RTE
(Proc
), Loc
),
1769 Parameter_Associations
=> New_List
(
1771 Make_Attribute_Reference
(Loc
,
1772 Prefix
=> New_Reference_To
(Data
, Loc
),
1773 Attribute_Name
=> Name_Unchecked_Access
))));
1775 end Build_Entry_Names
;
1777 ---------------------------
1778 -- Build_Parameter_Block --
1779 ---------------------------
1781 function Build_Parameter_Block
1785 Decls
: List_Id
) return Entity_Id
1791 Has_Comp
: Boolean := False;
1795 Actual
:= First
(Actuals
);
1797 Formal
:= Defining_Identifier
(First
(Formals
));
1799 while Present
(Actual
) loop
1800 if not Is_Controlling_Actual
(Actual
) then
1803 -- type Ann is access all <actual-type>
1805 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1808 Make_Full_Type_Declaration
(Loc
,
1809 Defining_Identifier
=> Comp_Nam
,
1811 Make_Access_To_Object_Definition
(Loc
,
1812 All_Present
=> True,
1813 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1814 Subtype_Indication
=>
1815 New_Reference_To
(Etype
(Actual
), Loc
))));
1821 Make_Component_Declaration
(Loc
,
1822 Defining_Identifier
=>
1823 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1824 Component_Definition
=>
1825 Make_Component_Definition
(Loc
,
1828 Subtype_Indication
=>
1829 New_Reference_To
(Comp_Nam
, Loc
))));
1834 Next_Actual
(Actual
);
1835 Next_Formal_With_Extras
(Formal
);
1838 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1843 -- type Pnn is record
1848 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1849 -- the original parameter names and Ann1 .. AnnN are the access to
1853 Make_Full_Type_Declaration
(Loc
,
1854 Defining_Identifier
=>
1857 Make_Record_Definition
(Loc
,
1859 Make_Component_List
(Loc
, Comps
))));
1862 -- type Pnn is null record;
1865 Make_Full_Type_Declaration
(Loc
,
1866 Defining_Identifier
=>
1869 Make_Record_Definition
(Loc
,
1870 Null_Present
=> True,
1871 Component_List
=> Empty
)));
1875 end Build_Parameter_Block
;
1877 --------------------------------------
1878 -- Build_Renamed_Formal_Declaration --
1879 --------------------------------------
1881 function Build_Renamed_Formal_Declaration
1885 Renamed_Formal
: Node_Id
) return Node_Id
1887 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1891 -- If the formal is a tagged incomplete type, it is already passed
1892 -- by reference, so it is sufficient to rename the pointer component
1893 -- that corresponds to the actual. Otherwise we need to dereference
1894 -- the pointer component to obtain the actual.
1896 if Is_Incomplete_Type
(Etype
(Formal
))
1897 and then Is_Tagged_Type
(Etype
(Formal
))
1900 Make_Object_Renaming_Declaration
(Loc
,
1901 Defining_Identifier
=> New_F
,
1902 Subtype_Mark
=> New_Reference_To
(Etype
(Comp
), Loc
),
1903 Name
=> Renamed_Formal
);
1907 Make_Object_Renaming_Declaration
(Loc
,
1908 Defining_Identifier
=> New_F
,
1909 Subtype_Mark
=> New_Reference_To
(Etype
(Formal
), Loc
),
1911 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1915 end Build_Renamed_Formal_Declaration
;
1917 -----------------------
1918 -- Build_PPC_Wrapper --
1919 -----------------------
1921 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1922 Loc
: constant Source_Ptr
:= Sloc
(E
);
1923 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1925 Wrapper_Id
: constant Entity_Id
:=
1926 Make_Defining_Identifier
(Loc
,
1927 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1928 -- the wrapper procedure name
1930 Wrapper_Body
: Node_Id
;
1932 Synch_Id
: constant Entity_Id
:=
1933 Make_Defining_Identifier
(Loc
,
1934 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1935 -- The parameter that designates the synchronized object in the call
1937 Actuals
: constant List_Id
:= New_List
;
1938 -- The actuals in the entry call
1940 Decls
: constant List_Id
:= New_List
;
1942 Entry_Call
: Node_Id
;
1943 Entry_Name
: Node_Id
;
1946 -- The specification of the wrapper procedure
1950 -- Only build the wrapper if entry has pre/postconditions.
1951 -- Should this be done unconditionally instead ???
1957 P
:= Pre_Post_Conditions
(Contract
(E
));
1963 -- Transfer ppc pragmas to the declarations of the wrapper
1965 while Present
(P
) loop
1966 if Nam_In
(Pragma_Name
(P
), Name_Precondition
,
1969 Append
(Relocate_Node
(P
), Decls
);
1970 Set_Analyzed
(Last
(Decls
), False);
1973 P
:= Next_Pragma
(P
);
1977 -- First formal is synchronized object
1980 Make_Parameter_Specification
(Loc
,
1981 Defining_Identifier
=> Synch_Id
,
1982 Out_Present
=> True,
1984 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1987 Make_Selected_Component
(Loc
,
1988 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1989 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1991 -- If entity is entry family, second formal is the corresponding index,
1992 -- and entry name is an indexed component.
1994 if Ekind
(E
) = E_Entry_Family
then
1996 Index
: constant Entity_Id
:=
1997 Make_Defining_Identifier
(Loc
, Name_I
);
2000 Make_Parameter_Specification
(Loc
,
2001 Defining_Identifier
=> Index
,
2003 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
2006 Make_Indexed_Component
(Loc
,
2007 Prefix
=> Entry_Name
,
2008 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
2013 Make_Procedure_Call_Statement
(Loc
,
2015 Parameter_Associations
=> Actuals
);
2017 -- Now add formals that match those of the entry, and build actuals for
2018 -- the nested entry call.
2022 New_Form
: Entity_Id
;
2023 Parm_Spec
: Node_Id
;
2026 Form
:= First_Formal
(E
);
2027 while Present
(Form
) loop
2028 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
2030 Make_Parameter_Specification
(Loc
,
2031 Defining_Identifier
=> New_Form
,
2032 Out_Present
=> Out_Present
(Parent
(Form
)),
2033 In_Present
=> In_Present
(Parent
(Form
)),
2034 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
2036 Append
(Parm_Spec
, Specs
);
2037 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
2042 -- Add renaming declarations for the discriminants of the enclosing
2043 -- type, which may be visible in the preconditions.
2045 if Has_Discriminants
(Synch_Type
) then
2051 D
:= First_Discriminant
(Synch_Type
);
2052 while Present
(D
) loop
2054 Make_Object_Renaming_Declaration
(Loc
,
2055 Defining_Identifier
=>
2056 Make_Defining_Identifier
(Loc
, Chars
(D
)),
2057 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
2059 Make_Selected_Component
(Loc
,
2060 Prefix
=> New_Reference_To
(Synch_Id
, Loc
),
2061 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
2062 Prepend
(Decl
, Decls
);
2063 Next_Discriminant
(D
);
2068 Set_PPC_Wrapper
(E
, Wrapper_Id
);
2070 Make_Subprogram_Body
(Loc
,
2072 Make_Procedure_Specification
(Loc
,
2073 Defining_Unit_Name
=> Wrapper_Id
,
2074 Parameter_Specifications
=> Specs
),
2075 Declarations
=> Decls
,
2076 Handled_Statement_Sequence
=>
2077 Make_Handled_Sequence_Of_Statements
(Loc
,
2078 Statements
=> New_List
(Entry_Call
)));
2080 -- The wrapper body is analyzed when the enclosing type is frozen
2082 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
2083 end Build_PPC_Wrapper
;
2085 --------------------------
2086 -- Build_Wrapper_Bodies --
2087 --------------------------
2089 procedure Build_Wrapper_Bodies
2094 Rec_Typ
: Entity_Id
;
2096 function Build_Wrapper_Body
2098 Subp_Id
: Entity_Id
;
2099 Obj_Typ
: Entity_Id
;
2100 Formals
: List_Id
) return Node_Id
;
2101 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2102 -- associated with a protected or task type. Subp_Id is the subprogram
2103 -- name which will be wrapped. Obj_Typ is the type of the new formal
2104 -- parameter which handles dispatching and object notation. Formals are
2105 -- the original formals of Subp_Id which will be explicitly replicated.
2107 ------------------------
2108 -- Build_Wrapper_Body --
2109 ------------------------
2111 function Build_Wrapper_Body
2113 Subp_Id
: Entity_Id
;
2114 Obj_Typ
: Entity_Id
;
2115 Formals
: List_Id
) return Node_Id
2117 Body_Spec
: Node_Id
;
2120 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
2122 -- The subprogram is not overriding or is not a primitive declared
2123 -- between two views.
2125 if No
(Body_Spec
) then
2130 Actuals
: List_Id
:= No_List
;
2132 First_Form
: Node_Id
;
2137 -- Map formals to actuals. Use the list built for the wrapper
2138 -- spec, skipping the object notation parameter.
2140 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
2142 Formal
:= First_Form
;
2145 if Present
(Formal
) then
2146 Actuals
:= New_List
;
2147 while Present
(Formal
) loop
2149 Make_Identifier
(Loc
,
2150 Chars
=> Chars
(Defining_Identifier
(Formal
))));
2155 -- Special processing for primitives declared between a private
2156 -- type and its completion: the wrapper needs a properly typed
2157 -- parameter if the wrapped operation has a controlling first
2158 -- parameter. Note that this might not be the case for a function
2159 -- with a controlling result.
2161 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
2162 if No
(Actuals
) then
2163 Actuals
:= New_List
;
2166 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
2167 Prepend_To
(Actuals
,
2168 Unchecked_Convert_To
2169 (Corresponding_Concurrent_Type
(Obj_Typ
),
2170 Make_Identifier
(Loc
, Name_uO
)));
2173 Prepend_To
(Actuals
,
2174 Make_Identifier
(Loc
,
2175 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
2178 Nam
:= New_Reference_To
(Subp_Id
, Loc
);
2180 -- An access-to-variable object parameter requires an explicit
2181 -- dereference in the unchecked conversion. This case occurs
2182 -- when a protected entry wrapper must override an interface
2183 -- level procedure with interface access as first parameter.
2185 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2187 if Nkind
(Parameter_Type
(First_Form
)) =
2191 Make_Explicit_Dereference
(Loc
,
2192 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
2194 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
2198 Make_Selected_Component
(Loc
,
2200 Unchecked_Convert_To
2201 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
2202 Selector_Name
=> New_Reference_To
(Subp_Id
, Loc
));
2205 -- Create the subprogram body. For a function, the call to the
2206 -- actual subprogram has to be converted to the corresponding
2207 -- record if it is a controlling result.
2209 if Ekind
(Subp_Id
) = E_Function
then
2215 Make_Function_Call
(Loc
,
2217 Parameter_Associations
=> Actuals
);
2219 if Has_Controlling_Result
(Subp_Id
) then
2221 Unchecked_Convert_To
2222 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
2226 Make_Subprogram_Body
(Loc
,
2227 Specification
=> Body_Spec
,
2228 Declarations
=> Empty_List
,
2229 Handled_Statement_Sequence
=>
2230 Make_Handled_Sequence_Of_Statements
(Loc
,
2231 Statements
=> New_List
(
2232 Make_Simple_Return_Statement
(Loc
, Res
))));
2237 Make_Subprogram_Body
(Loc
,
2238 Specification
=> Body_Spec
,
2239 Declarations
=> Empty_List
,
2240 Handled_Statement_Sequence
=>
2241 Make_Handled_Sequence_Of_Statements
(Loc
,
2242 Statements
=> New_List
(
2243 Make_Procedure_Call_Statement
(Loc
,
2245 Parameter_Associations
=> Actuals
))));
2248 end Build_Wrapper_Body
;
2250 -- Start of processing for Build_Wrapper_Bodies
2253 if Is_Concurrent_Type
(Typ
) then
2254 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2259 -- Generate wrapper bodies for a concurrent type which implements an
2262 if Present
(Interfaces
(Rec_Typ
)) then
2264 Insert_Nod
: Node_Id
;
2266 Prim_Elmt
: Elmt_Id
;
2267 Prim_Decl
: Node_Id
;
2269 Wrap_Body
: Node_Id
;
2270 Wrap_Id
: Entity_Id
;
2275 -- Examine all primitive operations of the corresponding record
2276 -- type, looking for wrapper specs. Generate bodies in order to
2279 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2280 while Present
(Prim_Elmt
) loop
2281 Prim
:= Node
(Prim_Elmt
);
2283 if (Ekind
(Prim
) = E_Function
2284 or else Ekind
(Prim
) = E_Procedure
)
2285 and then Is_Primitive_Wrapper
(Prim
)
2287 Subp
:= Wrapped_Entity
(Prim
);
2288 Prim_Decl
:= Parent
(Parent
(Prim
));
2291 Build_Wrapper_Body
(Loc
,
2294 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2295 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2297 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2298 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2300 Insert_After
(Insert_Nod
, Wrap_Body
);
2301 Insert_Nod
:= Wrap_Body
;
2303 Analyze
(Wrap_Body
);
2306 Next_Elmt
(Prim_Elmt
);
2310 end Build_Wrapper_Bodies
;
2312 ------------------------
2313 -- Build_Wrapper_Spec --
2314 ------------------------
2316 function Build_Wrapper_Spec
2317 (Subp_Id
: Entity_Id
;
2318 Obj_Typ
: Entity_Id
;
2319 Formals
: List_Id
) return Node_Id
2321 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2322 First_Param
: Node_Id
;
2324 Iface_Elmt
: Elmt_Id
;
2325 Iface_Op
: Entity_Id
;
2326 Iface_Op_Elmt
: Elmt_Id
;
2328 function Overriding_Possible
2329 (Iface_Op
: Entity_Id
;
2330 Wrapper
: Entity_Id
) return Boolean;
2331 -- Determine whether a primitive operation can be overridden by Wrapper.
2332 -- Iface_Op is the candidate primitive operation of an interface type,
2333 -- Wrapper is the generated entry wrapper.
2335 function Replicate_Formals
2337 Formals
: List_Id
) return List_Id
;
2338 -- An explicit parameter replication is required due to the Is_Entry_
2339 -- Formal flag being set for all the formals of an entry. The explicit
2340 -- replication removes the flag that would otherwise cause a different
2341 -- path of analysis.
2343 -------------------------
2344 -- Overriding_Possible --
2345 -------------------------
2347 function Overriding_Possible
2348 (Iface_Op
: Entity_Id
;
2349 Wrapper
: Entity_Id
) return Boolean
2351 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2352 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2354 function Type_Conformant_Parameters
2355 (Iface_Op_Params
: List_Id
;
2356 Wrapper_Params
: List_Id
) return Boolean;
2357 -- Determine whether the parameters of the generated entry wrapper
2358 -- and those of a primitive operation are type conformant. During
2359 -- this check, the first parameter of the primitive operation is
2360 -- skipped if it is a controlling argument: protected functions
2361 -- may have a controlling result.
2363 --------------------------------
2364 -- Type_Conformant_Parameters --
2365 --------------------------------
2367 function Type_Conformant_Parameters
2368 (Iface_Op_Params
: List_Id
;
2369 Wrapper_Params
: List_Id
) return Boolean
2371 Iface_Op_Param
: Node_Id
;
2372 Iface_Op_Typ
: Entity_Id
;
2373 Wrapper_Param
: Node_Id
;
2374 Wrapper_Typ
: Entity_Id
;
2377 -- Skip the first (controlling) parameter of primitive operation
2379 Iface_Op_Param
:= First
(Iface_Op_Params
);
2381 if Present
(First_Formal
(Iface_Op
))
2382 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2384 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2387 Wrapper_Param
:= First
(Wrapper_Params
);
2388 while Present
(Iface_Op_Param
)
2389 and then Present
(Wrapper_Param
)
2391 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2392 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2394 -- The two parameters must be mode conformant
2396 if not Conforming_Types
2397 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2402 Next
(Iface_Op_Param
);
2403 Next
(Wrapper_Param
);
2406 -- One of the lists is longer than the other
2408 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2413 end Type_Conformant_Parameters
;
2415 -- Start of processing for Overriding_Possible
2418 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2422 -- If an inherited subprogram is implemented by a protected procedure
2423 -- or an entry, then the first parameter of the inherited subprogram
2424 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2426 if Ekind
(Iface_Op
) = E_Procedure
2427 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2430 Obj_Param
: constant Node_Id
:=
2431 First
(Parameter_Specifications
(Iface_Op_Spec
));
2433 if not Out_Present
(Obj_Param
)
2434 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2443 Type_Conformant_Parameters
(
2444 Parameter_Specifications
(Iface_Op_Spec
),
2445 Parameter_Specifications
(Wrapper_Spec
));
2446 end Overriding_Possible
;
2448 -----------------------
2449 -- Replicate_Formals --
2450 -----------------------
2452 function Replicate_Formals
2454 Formals
: List_Id
) return List_Id
2456 New_Formals
: constant List_Id
:= New_List
;
2458 Param_Type
: Node_Id
;
2461 Formal
:= First
(Formals
);
2463 -- Skip the object parameter when dealing with primitives declared
2464 -- between two views.
2466 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2467 and then not Has_Controlling_Result
(Subp_Id
)
2469 Formal
:= Next
(Formal
);
2472 while Present
(Formal
) loop
2474 -- Create an explicit copy of the entry parameter
2476 -- When creating the wrapper subprogram for a primitive operation
2477 -- of a protected interface we must construct an equivalent
2478 -- signature to that of the overriding operation. For regular
2479 -- parameters we can just use the type of the formal, but for
2480 -- access to subprogram parameters we need to reanalyze the
2481 -- parameter type to create local entities for the signature of
2482 -- the subprogram type. Using the entities of the overriding
2483 -- subprogram will result in out-of-scope errors in the back-end.
2485 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2486 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2489 New_Reference_To
(Etype
(Parameter_Type
(Formal
)), Loc
);
2492 Append_To
(New_Formals
,
2493 Make_Parameter_Specification
(Loc
,
2494 Defining_Identifier
=>
2495 Make_Defining_Identifier
(Loc
,
2496 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2497 In_Present
=> In_Present
(Formal
),
2498 Out_Present
=> Out_Present
(Formal
),
2499 Parameter_Type
=> Param_Type
));
2505 end Replicate_Formals
;
2507 -- Start of processing for Build_Wrapper_Spec
2510 -- There is no point in building wrappers for non-tagged concurrent
2513 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2515 -- An entry or a protected procedure can override a routine where the
2516 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2517 -- type. Since the wrapper must have the exact same signature as that of
2518 -- the overridden subprogram, we try to find the overriding candidate
2519 -- and use its controlling formal.
2521 First_Param
:= Empty
;
2523 -- Check every implemented interface
2525 if Present
(Interfaces
(Obj_Typ
)) then
2526 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2527 Search
: while Present
(Iface_Elmt
) loop
2528 Iface
:= Node
(Iface_Elmt
);
2530 -- Check every interface primitive
2532 if Present
(Primitive_Operations
(Iface
)) then
2533 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2534 while Present
(Iface_Op_Elmt
) loop
2535 Iface_Op
:= Node
(Iface_Op_Elmt
);
2537 -- Ignore predefined primitives
2539 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2540 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2542 -- The current primitive operation can be overridden by
2543 -- the generated entry wrapper.
2545 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2547 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2553 Next_Elmt
(Iface_Op_Elmt
);
2557 Next_Elmt
(Iface_Elmt
);
2561 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2562 -- this subprogram and this is not a primitive declared between two
2563 -- views then force the generation of a wrapper. As an optimization,
2564 -- previous versions of the frontend avoid generating the wrapper;
2565 -- however, the wrapper facilitates locating and reporting an error
2566 -- when a duplicate declaration is found later. See example in
2570 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2573 (Corresponding_Concurrent_Type
(Obj_Typ
))
2576 Make_Parameter_Specification
(Loc
,
2577 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
2579 Out_Present
=> False,
2580 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2582 -- For entries and procedures of protected types the mode of
2583 -- the controlling argument must be in-out.
2587 Make_Parameter_Specification
(Loc
,
2588 Defining_Identifier
=>
2589 Make_Defining_Identifier
(Loc
,
2592 Out_Present
=> (Ekind
(Subp_Id
) /= E_Function
),
2593 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2598 Wrapper_Id
: constant Entity_Id
:=
2599 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2600 New_Formals
: List_Id
;
2601 Obj_Param
: Node_Id
;
2602 Obj_Param_Typ
: Entity_Id
;
2605 -- Minimum decoration is needed to catch the entity in
2606 -- Sem_Ch6.Override_Dispatching_Operation.
2608 if Ekind
(Subp_Id
) = E_Function
then
2609 Set_Ekind
(Wrapper_Id
, E_Function
);
2611 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2614 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2615 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2616 Set_Is_Private_Primitive
(Wrapper_Id
,
2617 Is_Private_Primitive_Subprogram
(Subp_Id
));
2619 -- Process the formals
2621 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2623 -- A function with a controlling result and no first controlling
2624 -- formal needs no additional parameter.
2626 if Has_Controlling_Result
(Subp_Id
)
2628 (No
(First_Formal
(Subp_Id
))
2629 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2633 -- Routine Subp_Id has been found to override an interface primitive.
2634 -- If the interface operation has an access parameter, create a copy
2635 -- of it, with the same null exclusion indicator if present.
2637 elsif Present
(First_Param
) then
2638 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2640 Make_Access_Definition
(Loc
,
2642 New_Reference_To
(Obj_Typ
, Loc
));
2643 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2644 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2647 Obj_Param_Typ
:= New_Reference_To
(Obj_Typ
, Loc
);
2651 Make_Parameter_Specification
(Loc
,
2652 Defining_Identifier
=>
2653 Make_Defining_Identifier
(Loc
,
2655 In_Present
=> In_Present
(First_Param
),
2656 Out_Present
=> Out_Present
(First_Param
),
2657 Parameter_Type
=> Obj_Param_Typ
);
2659 Prepend_To
(New_Formals
, Obj_Param
);
2661 -- If we are dealing with a primitive declared between two views,
2662 -- implemented by a synchronized operation, we need to create
2663 -- a default parameter. The mode of the parameter must match that
2664 -- of the primitive operation.
2667 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2669 Make_Parameter_Specification
(Loc
,
2670 Defining_Identifier
=>
2671 Make_Defining_Identifier
(Loc
, Name_uO
),
2672 In_Present
=> In_Present
(Parent
(First_Entity
(Subp_Id
))),
2673 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2674 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2675 Prepend_To
(New_Formals
, Obj_Param
);
2678 -- Build the final spec. If it is a function with a controlling
2679 -- result, it is a primitive operation of the corresponding
2680 -- record type, so mark the spec accordingly.
2682 if Ekind
(Subp_Id
) = E_Function
then
2687 if Has_Controlling_Result
(Subp_Id
) then
2690 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2692 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2696 Make_Function_Specification
(Loc
,
2697 Defining_Unit_Name
=> Wrapper_Id
,
2698 Parameter_Specifications
=> New_Formals
,
2699 Result_Definition
=> Res_Def
);
2703 Make_Procedure_Specification
(Loc
,
2704 Defining_Unit_Name
=> Wrapper_Id
,
2705 Parameter_Specifications
=> New_Formals
);
2708 end Build_Wrapper_Spec
;
2710 -------------------------
2711 -- Build_Wrapper_Specs --
2712 -------------------------
2714 procedure Build_Wrapper_Specs
2720 Rec_Typ
: Entity_Id
;
2721 procedure Scan_Declarations
(L
: List_Id
);
2722 -- Common processing for visible and private declarations
2723 -- of a protected type.
2725 procedure Scan_Declarations
(L
: List_Id
) is
2727 Wrap_Decl
: Node_Id
;
2728 Wrap_Spec
: Node_Id
;
2736 while Present
(Decl
) loop
2739 if Nkind
(Decl
) = N_Entry_Declaration
2740 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2744 (Subp_Id
=> Defining_Identifier
(Decl
),
2746 Formals
=> Parameter_Specifications
(Decl
));
2748 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2751 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2754 Parameter_Specifications
(Specification
(Decl
)));
2757 if Present
(Wrap_Spec
) then
2759 Make_Subprogram_Declaration
(Loc
,
2760 Specification
=> Wrap_Spec
);
2762 Insert_After
(N
, Wrap_Decl
);
2765 Analyze
(Wrap_Decl
);
2770 end Scan_Declarations
;
2772 -- start of processing for Build_Wrapper_Specs
2775 if Is_Protected_Type
(Typ
) then
2776 Def
:= Protected_Definition
(Parent
(Typ
));
2777 else pragma Assert
(Is_Task_Type
(Typ
));
2778 Def
:= Task_Definition
(Parent
(Typ
));
2781 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2783 -- Generate wrapper specs for a concurrent type which implements an
2784 -- interface. Operations in both the visible and private parts may
2785 -- implement progenitor operations.
2787 if Present
(Interfaces
(Rec_Typ
))
2788 and then Present
(Def
)
2790 Scan_Declarations
(Visible_Declarations
(Def
));
2791 Scan_Declarations
(Private_Declarations
(Def
));
2793 end Build_Wrapper_Specs
;
2795 ---------------------------
2796 -- Build_Find_Body_Index --
2797 ---------------------------
2799 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2800 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2803 Has_F
: Boolean := False;
2805 If_St
: Node_Id
:= Empty
;
2808 Decls
: List_Id
:= New_List
;
2811 Siz
: Node_Id
:= Empty
;
2813 procedure Add_If_Clause
(Expr
: Node_Id
);
2814 -- Add test for range of current entry
2816 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2817 -- If a bound of an entry is given by a discriminant, retrieve the
2818 -- actual value of the discriminant from the enclosing object.
2824 procedure Add_If_Clause
(Expr
: Node_Id
) is
2826 Stats
: constant List_Id
:=
2828 Make_Simple_Return_Statement
(Loc
,
2829 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2832 -- Index for current entry body
2836 -- Compute total length of entry queues so far
2844 Right_Opnd
=> Expr
);
2849 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2852 -- Map entry queue indexes in the range of the current family
2853 -- into the current index, that designates the entry body.
2857 Make_Implicit_If_Statement
(Typ
,
2859 Then_Statements
=> Stats
,
2860 Elsif_Parts
=> New_List
);
2864 Append_To
(Elsif_Parts
(If_St
),
2865 Make_Elsif_Part
(Loc
,
2867 Then_Statements
=> Stats
));
2871 ------------------------------
2872 -- Convert_Discriminant_Ref --
2873 ------------------------------
2875 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2879 if Is_Entity_Name
(Bound
)
2880 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2883 Make_Selected_Component
(Loc
,
2885 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2886 Make_Explicit_Dereference
(Loc
,
2887 Make_Identifier
(Loc
, Name_uObject
))),
2888 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2889 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2891 B
:= New_Copy_Tree
(Bound
);
2895 end Convert_Discriminant_Ref
;
2897 -- Start of processing for Build_Find_Body_Index
2900 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2902 Ent
:= First_Entity
(Typ
);
2903 while Present
(Ent
) loop
2904 if Ekind
(Ent
) = E_Entry_Family
then
2914 -- If the protected type has no entry families, there is a one-one
2915 -- correspondence between entry queue and entry body.
2918 Make_Simple_Return_Statement
(Loc
,
2919 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2922 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2925 -- if E <= l1 then return 1;
2926 -- elsif E <= l1 + l2 then return 2;
2931 Ent
:= First_Entity
(Typ
);
2933 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2935 while Present
(Ent
) loop
2936 if Ekind
(Ent
) = E_Entry
then
2937 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2939 elsif Ekind
(Ent
) = E_Entry_Family
then
2940 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2941 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2942 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2943 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2952 Make_Simple_Return_Statement
(Loc
,
2953 Expression
=> Make_Integer_Literal
(Loc
, 1));
2955 elsif Nkind
(Ret
) = N_If_Statement
then
2957 -- Ranges are in increasing order, so last one doesn't need guard
2960 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2963 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2969 Make_Subprogram_Body
(Loc
,
2970 Specification
=> Spec
,
2971 Declarations
=> Decls
,
2972 Handled_Statement_Sequence
=>
2973 Make_Handled_Sequence_Of_Statements
(Loc
,
2974 Statements
=> New_List
(Ret
)));
2975 end Build_Find_Body_Index
;
2977 --------------------------------
2978 -- Build_Find_Body_Index_Spec --
2979 --------------------------------
2981 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2982 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2983 Id
: constant Entity_Id
:=
2984 Make_Defining_Identifier
(Loc
,
2985 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2986 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2987 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2991 Make_Function_Specification
(Loc
,
2992 Defining_Unit_Name
=> Id
,
2993 Parameter_Specifications
=> New_List
(
2994 Make_Parameter_Specification
(Loc
,
2995 Defining_Identifier
=> Parm1
,
2997 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2999 Make_Parameter_Specification
(Loc
,
3000 Defining_Identifier
=> Parm2
,
3002 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
3004 Result_Definition
=> New_Occurrence_Of
(
3005 RTE
(RE_Protected_Entry_Index
), Loc
));
3006 end Build_Find_Body_Index_Spec
;
3008 -----------------------------------------------
3009 -- Build_Lock_Free_Protected_Subprogram_Body --
3010 -----------------------------------------------
3012 function Build_Lock_Free_Protected_Subprogram_Body
3015 Unprot_Spec
: Node_Id
) return Node_Id
3017 Actuals
: constant List_Id
:= New_List
;
3018 Loc
: constant Source_Ptr
:= Sloc
(N
);
3019 Spec
: constant Node_Id
:= Specification
(N
);
3020 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
3022 Prot_Spec
: Node_Id
;
3026 -- Create the protected version of the body
3029 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
3031 -- Build the actual parameters which appear in the call to the
3032 -- unprotected version of the body.
3034 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
3035 while Present
(Formal
) loop
3037 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
3042 -- Function case, generate:
3043 -- return <Unprot_Func_Call>;
3045 if Nkind
(Spec
) = N_Function_Specification
then
3047 Make_Simple_Return_Statement
(Loc
,
3049 Make_Function_Call
(Loc
,
3051 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3052 Parameter_Associations
=> Actuals
));
3054 -- Procedure case, call the unprotected version
3058 Make_Procedure_Call_Statement
(Loc
,
3060 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3061 Parameter_Associations
=> Actuals
);
3065 Make_Subprogram_Body
(Loc
,
3066 Declarations
=> Empty_List
,
3067 Specification
=> Prot_Spec
,
3068 Handled_Statement_Sequence
=>
3069 Make_Handled_Sequence_Of_Statements
(Loc
,
3070 Statements
=> New_List
(Stmt
)));
3071 end Build_Lock_Free_Protected_Subprogram_Body
;
3073 -------------------------------------------------
3074 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3075 -------------------------------------------------
3077 -- Procedures which meet the lock-free implementation requirements and
3078 -- reference a unique scalar component Comp are expanded in the following
3081 -- procedure P (...) is
3082 -- Expected_Comp : constant Comp_Type :=
3084 -- (System.Atomic_Primitives.Lock_Free_Read_N
3085 -- (_Object.Comp'Address));
3089 -- <original declarations before the object renaming declaration
3092 -- Desired_Comp : Comp_Type := Expected_Comp;
3093 -- Comp : Comp_Type renames Desired_Comp;
3095 -- <original delarations after the object renaming declaration
3099 -- <original statements>
3100 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3101 -- (_Object.Comp'Address,
3102 -- Interfaces.Unsigned_N (Expected_Comp),
3103 -- Interfaces.Unsigned_N (Desired_Comp));
3108 -- Each return and raise statement of P is transformed into an atomic
3111 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3112 -- (_Object.Comp'Address,
3113 -- Interfaces.Unsigned_N (Expected_Comp),
3114 -- Interfaces.Unsigned_N (Desired_Comp));
3116 -- <original statement>
3121 -- Functions which meet the lock-free implementation requirements and
3122 -- reference a unique scalar component Comp are expanded in the following
3125 -- function F (...) return ... is
3126 -- <original declarations before the object renaming declaration
3129 -- Expected_Comp : constant Comp_Type :=
3131 -- (System.Atomic_Primitives.Lock_Free_Read_N
3132 -- (_Object.Comp'Address));
3133 -- Comp : Comp_Type renames Expected_Comp;
3135 -- <original delarations after the object renaming declaration of
3139 -- <original statements>
3142 function Build_Lock_Free_Unprotected_Subprogram_Body
3144 Prot_Typ
: Node_Id
) return Node_Id
3146 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
3147 -- Subprograms which meet the lock-free implementation criteria are
3148 -- allowed to reference only one unique component. Return the prival
3149 -- of the said component.
3151 --------------------------
3152 -- Referenced_Component --
3153 --------------------------
3155 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
3158 Source_Comp
: Entity_Id
:= Empty
;
3161 -- Find the unique source component which N references in its
3164 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
3166 Element
: Lock_Free_Subprogram
renames
3167 Lock_Free_Subprogram_Table
.Table
(Index
);
3169 if Element
.Sub_Body
= N
then
3170 Source_Comp
:= Element
.Comp_Id
;
3176 if No
(Source_Comp
) then
3180 -- Find the prival which corresponds to the source component within
3181 -- the declarations of N.
3183 Decl
:= First
(Declarations
(N
));
3184 while Present
(Decl
) loop
3186 -- Privals appear as object renamings
3188 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
3189 Comp
:= Defining_Identifier
(Decl
);
3191 if Present
(Prival_Link
(Comp
))
3192 and then Prival_Link
(Comp
) = Source_Comp
3202 end Referenced_Component
;
3206 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
3207 Loc
: constant Source_Ptr
:= Sloc
(N
);
3208 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
3209 Decls
: List_Id
:= Declarations
(N
);
3211 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3214 -- Add renamings for the protection object, discriminals, privals and
3215 -- the entry index constant for use by debugger.
3217 Debug_Private_Data_Declarations
(Decls
);
3219 -- Perform the lock-free expansion when the subprogram references a
3220 -- protected component.
3222 if Present
(Comp
) then
3223 Protected_Component_Ref
: declare
3224 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
3225 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
3226 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
3228 Is_Procedure
: constant Boolean :=
3229 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
3230 -- Indicates if N is a protected procedure body
3232 Block_Decls
: List_Id
;
3233 Try_Write
: Entity_Id
;
3234 Desired_Comp
: Entity_Id
;
3237 Label_Id
: Entity_Id
:= Empty
;
3239 Expected_Comp
: Entity_Id
;
3242 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
3244 Unsigned
: Entity_Id
;
3246 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
3247 -- Transform a single node if it is a return statement, a raise
3248 -- statement or a reference to Comp.
3250 procedure Process_Stmts
(Stmts
: List_Id
);
3251 -- Given a statement sequence Stmts, wrap any return or raise
3252 -- statements in the following manner:
3254 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3255 -- (_Object.Comp'Address,
3256 -- Interfaces.Unsigned_N (Expected_Comp),
3257 -- Interfaces.Unsigned_N (Desired_Comp))
3268 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3270 procedure Wrap_Statement
(Stmt
: Node_Id
);
3271 -- Wrap an arbitrary statement inside an if statement where the
3272 -- condition does an atomic check on the state of the object.
3274 --------------------
3275 -- Wrap_Statement --
3276 --------------------
3278 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3280 -- The first time through, create the declaration of a label
3281 -- which is used to skip the remainder of source statements
3282 -- if the state of the object has changed.
3284 if No
(Label_Id
) then
3286 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3287 Set_Entity
(Label_Id
,
3288 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3292 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3293 -- (_Object.Comp'Address,
3294 -- Interfaces.Unsigned_N (Expected_Comp),
3295 -- Interfaces.Unsigned_N (Desired_Comp))
3303 Make_Implicit_If_Statement
(N
,
3305 Make_Function_Call
(Loc
,
3307 New_Reference_To
(Try_Write
, Loc
),
3308 Parameter_Associations
=> New_List
(
3309 Make_Attribute_Reference
(Loc
,
3310 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3311 Attribute_Name
=> Name_Address
),
3313 Unchecked_Convert_To
(Unsigned
,
3314 New_Reference_To
(Expected_Comp
, Loc
)),
3316 Unchecked_Convert_To
(Unsigned
,
3317 New_Reference_To
(Desired_Comp
, Loc
)))),
3319 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3321 Else_Statements
=> New_List
(
3322 Make_Goto_Statement
(Loc
,
3324 New_Reference_To
(Entity
(Label_Id
), Loc
)))));
3327 -- Start of processing for Process_Node
3330 -- Wrap each return and raise statement that appear inside a
3331 -- procedure. Skip the last return statement which is added by
3332 -- default since it is transformed into an exit statement.
3335 and then ((Nkind
(N
) = N_Simple_Return_Statement
3336 and then N
/= Last
(Stmts
))
3337 or else Nkind
(N
) = N_Extended_Return_Statement
3338 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3339 N_Raise_Program_Error
,
3341 N_Raise_Storage_Error
)
3342 and then Comes_From_Source
(N
)))
3350 Set_Analyzed
(N
, False);
3355 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3361 procedure Process_Stmts
(Stmts
: List_Id
) is
3364 Stmt
:= First
(Stmts
);
3365 while Present
(Stmt
) loop
3366 Process_Nodes
(Stmt
);
3371 -- Start of processing for Protected_Component_Ref
3374 -- Get the type size
3376 if Known_Static_Esize
(Comp_Type
) then
3377 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3379 -- If the Esize (Object_Size) is unknown at compile time, look at
3380 -- the RM_Size (Value_Size) since it may have been set by an
3381 -- explicit representation clause.
3383 elsif Known_Static_RM_Size
(Comp_Type
) then
3384 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3386 -- Should not happen since this has already been checked in
3387 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3390 raise Program_Error
;
3393 -- Retrieve all relevant atomic routines and types
3397 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3398 Read
:= RTE
(RE_Lock_Free_Read_8
);
3399 Unsigned
:= RTE
(RE_Uint8
);
3402 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3403 Read
:= RTE
(RE_Lock_Free_Read_16
);
3404 Unsigned
:= RTE
(RE_Uint16
);
3407 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3408 Read
:= RTE
(RE_Lock_Free_Read_32
);
3409 Unsigned
:= RTE
(RE_Uint32
);
3412 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3413 Read
:= RTE
(RE_Lock_Free_Read_64
);
3414 Unsigned
:= RTE
(RE_Uint64
);
3417 raise Program_Error
;
3421 -- Expected_Comp : constant Comp_Type :=
3423 -- (System.Atomic_Primitives.Lock_Free_Read_N
3424 -- (_Object.Comp'Address));
3427 Make_Defining_Identifier
(Loc
,
3428 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3431 Make_Object_Declaration
(Loc
,
3432 Defining_Identifier
=> Expected_Comp
,
3433 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3434 Constant_Present
=> True,
3436 Unchecked_Convert_To
(Comp_Type
,
3437 Make_Function_Call
(Loc
,
3438 Name
=> New_Reference_To
(Read
, Loc
),
3439 Parameter_Associations
=> New_List
(
3440 Make_Attribute_Reference
(Loc
,
3441 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3442 Attribute_Name
=> Name_Address
)))));
3444 -- Protected procedures
3446 if Is_Procedure
then
3447 -- Move the original declarations inside the generated block
3449 Block_Decls
:= Decls
;
3451 -- Reset the declarations list of the protected procedure to
3452 -- contain only Decl.
3454 Decls
:= New_List
(Decl
);
3457 -- Desired_Comp : Comp_Type := Expected_Comp;
3460 Make_Defining_Identifier
(Loc
,
3461 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3463 -- Insert the declarations of Expected_Comp and Desired_Comp in
3464 -- the block declarations right before the renaming of the
3465 -- protected component.
3467 Insert_Before
(Comp_Decl
,
3468 Make_Object_Declaration
(Loc
,
3469 Defining_Identifier
=> Desired_Comp
,
3470 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3472 New_Reference_To
(Expected_Comp
, Loc
)));
3474 -- Protected function
3477 Desired_Comp
:= Expected_Comp
;
3479 -- Insert the declaration of Expected_Comp in the function
3480 -- declarations right before the renaming of the protected
3483 Insert_Before
(Comp_Decl
, Decl
);
3486 -- Rewrite the protected component renaming declaration to be a
3487 -- renaming of Desired_Comp.
3490 -- Comp : Comp_Type renames Desired_Comp;
3493 Make_Object_Renaming_Declaration
(Loc
,
3494 Defining_Identifier
=>
3495 Defining_Identifier
(Comp_Decl
),
3497 New_Occurrence_Of
(Comp_Type
, Loc
),
3499 New_Reference_To
(Desired_Comp
, Loc
)));
3501 -- Wrap any return or raise statements in Stmts in same the manner
3502 -- described in Process_Stmts.
3504 Process_Stmts
(Stmts
);
3507 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3508 -- (_Object.Comp'Address,
3509 -- Interfaces.Unsigned_N (Expected_Comp),
3510 -- Interfaces.Unsigned_N (Desired_Comp))
3512 if Is_Procedure
then
3514 Make_Exit_Statement
(Loc
,
3516 Make_Function_Call
(Loc
,
3518 New_Reference_To
(Try_Write
, Loc
),
3519 Parameter_Associations
=> New_List
(
3520 Make_Attribute_Reference
(Loc
,
3521 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3522 Attribute_Name
=> Name_Address
),
3524 Unchecked_Convert_To
(Unsigned
,
3525 New_Reference_To
(Expected_Comp
, Loc
)),
3527 Unchecked_Convert_To
(Unsigned
,
3528 New_Reference_To
(Desired_Comp
, Loc
)))));
3530 -- Small optimization: transform the default return statement
3531 -- of a procedure into the atomic exit statement.
3533 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3534 Rewrite
(Last
(Stmts
), Stmt
);
3536 Append_To
(Stmts
, Stmt
);
3540 -- Create the declaration of the label used to skip the rest of
3541 -- the source statements when the object state changes.
3543 if Present
(Label_Id
) then
3544 Label
:= Make_Label
(Loc
, Label_Id
);
3546 Make_Implicit_Label_Declaration
(Loc
,
3547 Defining_Identifier
=> Entity
(Label_Id
),
3548 Label_Construct
=> Label
));
3549 Append_To
(Stmts
, Label
);
3561 if Is_Procedure
then
3564 Make_Loop_Statement
(Loc
,
3565 Statements
=> New_List
(
3566 Make_Block_Statement
(Loc
,
3567 Declarations
=> Block_Decls
,
3568 Handled_Statement_Sequence
=>
3569 Make_Handled_Sequence_Of_Statements
(Loc
,
3570 Statements
=> Stmts
))),
3571 End_Label
=> Empty
));
3575 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3576 end Protected_Component_Ref
;
3579 -- Make an unprotected version of the subprogram for use within the same
3580 -- object, with new name and extra parameter representing the object.
3583 Make_Subprogram_Body
(Loc
,
3585 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3586 Declarations
=> Decls
,
3587 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3588 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3590 -------------------------
3591 -- Build_Master_Entity --
3592 -------------------------
3594 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3595 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3597 Context_Id
: Entity_Id
;
3603 if Is_Itype
(Obj_Or_Typ
) then
3604 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3606 Par
:= Parent
(Obj_Or_Typ
);
3609 -- When creating a master for a record component which is either a task
3610 -- or access-to-task, the enclosing record is the master scope and the
3611 -- proper insertion point is the component list.
3613 if Is_Record_Type
(Current_Scope
) then
3615 Context_Id
:= Current_Scope
;
3616 Decls
:= List_Containing
(Context
);
3618 -- Default case for object declarations and access types. Note that the
3619 -- context is updated to the nearest enclosing body, block, package or
3620 -- return statement.
3623 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3626 -- Do not create a master if one already exists or there is no task
3629 if Has_Master_Entity
(Context_Id
)
3630 or else Restriction_Active
(No_Task_Hierarchy
)
3635 -- Create a master, generate:
3636 -- _Master : constant Master_Id := Current_Master.all;
3639 Make_Object_Declaration
(Loc
,
3640 Defining_Identifier
=>
3641 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3642 Constant_Present
=> True,
3643 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3645 Make_Explicit_Dereference
(Loc
,
3646 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
3648 -- The master is inserted at the start of the declarative list of the
3651 Prepend_To
(Decls
, Decl
);
3653 -- In certain cases where transient scopes are involved, the immediate
3654 -- scope is not always the proper master scope. Ensure that the master
3655 -- declaration and entity appear in the same context.
3657 if Context_Id
/= Current_Scope
then
3658 Push_Scope
(Context_Id
);
3665 -- Mark the enclosing scope and its associated construct as being task
3668 Set_Has_Master_Entity
(Context_Id
);
3670 while Present
(Context
)
3671 and then Nkind
(Context
) /= N_Compilation_Unit
3673 if Nkind_In
(Context
, N_Block_Statement
,
3677 Set_Is_Task_Master
(Context
);
3680 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3681 Context
:= Corresponding_Stub
(Parent
(Context
));
3684 Context
:= Parent
(Context
);
3686 end Build_Master_Entity
;
3688 ---------------------------
3689 -- Build_Master_Renaming --
3690 ---------------------------
3692 procedure Build_Master_Renaming
3693 (Ptr_Typ
: Entity_Id
;
3694 Ins_Nod
: Node_Id
:= Empty
)
3696 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3698 Master_Decl
: Node_Id
;
3699 Master_Id
: Entity_Id
;
3702 -- Nothing to do if there is no task hierarchy
3704 if Restriction_Active
(No_Task_Hierarchy
) then
3708 -- Determine the proper context to insert the master renaming
3710 if Present
(Ins_Nod
) then
3712 elsif Is_Itype
(Ptr_Typ
) then
3713 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3715 Context
:= Parent
(Ptr_Typ
);
3719 -- <Ptr_Typ>M : Master_Id renames _Master;
3722 Make_Defining_Identifier
(Loc
,
3723 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3726 Make_Object_Renaming_Declaration
(Loc
,
3727 Defining_Identifier
=> Master_Id
,
3728 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3729 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3731 Insert_Action
(Context
, Master_Decl
);
3733 -- The renamed master now services the access type
3735 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3736 end Build_Master_Renaming
;
3738 -----------------------------------------
3739 -- Build_Private_Protected_Declaration --
3740 -----------------------------------------
3742 function Build_Private_Protected_Declaration
3743 (N
: Node_Id
) return Entity_Id
3745 Loc
: constant Source_Ptr
:= Sloc
(N
);
3746 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3751 Spec_Id
: Entity_Id
;
3754 Formal
:= First_Formal
(Body_Id
);
3756 -- The protected operation always has at least one formal, namely the
3757 -- object itself, but it is only placed in the parameter list if
3758 -- expansion is enabled.
3760 if Present
(Formal
) or else Expander_Active
then
3761 Plist
:= Copy_Parameter_List
(Body_Id
);
3766 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3768 Make_Procedure_Specification
(Loc
,
3769 Defining_Unit_Name
=>
3770 Make_Defining_Identifier
(Sloc
(Body_Id
),
3771 Chars
=> Chars
(Body_Id
)),
3772 Parameter_Specifications
=>
3776 Make_Function_Specification
(Loc
,
3777 Defining_Unit_Name
=>
3778 Make_Defining_Identifier
(Sloc
(Body_Id
),
3779 Chars
=> Chars
(Body_Id
)),
3780 Parameter_Specifications
=> Plist
,
3781 Result_Definition
=>
3782 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3785 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3786 Insert_Before
(N
, Decl
);
3787 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3789 -- Indicate that the entity comes from source, to ensure that cross-
3790 -- reference information is properly generated. The body itself is
3791 -- rewritten during expansion, and the body entity will not appear in
3792 -- calls to the operation.
3794 Set_Comes_From_Source
(Spec_Id
, True);
3796 Set_Has_Completion
(Spec_Id
);
3797 Set_Convention
(Spec_Id
, Convention_Protected
);
3799 end Build_Private_Protected_Declaration
;
3801 ---------------------------
3802 -- Build_Protected_Entry --
3803 ---------------------------
3805 function Build_Protected_Entry
3808 Pid
: Node_Id
) return Node_Id
3810 Loc
: constant Source_Ptr
:= Sloc
(N
);
3812 Decls
: constant List_Id
:= Declarations
(N
);
3813 End_Lab
: constant Node_Id
:=
3814 End_Label
(Handled_Statement_Sequence
(N
));
3815 End_Loc
: constant Source_Ptr
:=
3816 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3817 -- Used for the generated call to Complete_Entry_Body
3819 Han_Loc
: Source_Ptr
;
3820 -- Used for the exception handler, inserted at end of the body
3822 Op_Decls
: constant List_Id
:= New_List
;
3830 -- Set the source location on the exception handler only when debugging
3831 -- the expanded code (see Make_Implicit_Exception_Handler).
3833 if Debug_Generated_Code
then
3836 -- Otherwise the inserted code should not be visible to the debugger
3839 Han_Loc
:= No_Location
;
3843 Make_Defining_Identifier
(Loc
,
3844 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3846 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
3848 -- Add the following declarations:
3849 -- type poVP is access poV;
3850 -- _object : poVP := poVP (_O);
3852 -- where _O is the formal parameter associated with the concurrent
3853 -- object. These declarations are needed for Complete_Entry_Body.
3855 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
3857 -- Add renamings for all formals, the Protection object, discriminals,
3858 -- privals and the entry index constant for use by debugger.
3860 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
3861 Debug_Private_Data_Declarations
(Decls
);
3863 case Corresponding_Runtime_Package
(Pid
) is
3864 when System_Tasking_Protected_Objects_Entries
=>
3866 New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
);
3868 when System_Tasking_Protected_Objects_Single_Entry
=>
3870 New_Reference_To
(RTE
(RE_Complete_Single_Entry_Body
), Loc
);
3873 raise Program_Error
;
3876 Op_Stats
:= New_List
(
3877 Make_Block_Statement
(Loc
,
3878 Declarations
=> Decls
,
3879 Handled_Statement_Sequence
=>
3880 Handled_Statement_Sequence
(N
)),
3882 Make_Procedure_Call_Statement
(End_Loc
,
3884 Parameter_Associations
=> New_List
(
3885 Make_Attribute_Reference
(End_Loc
,
3887 Make_Selected_Component
(End_Loc
,
3888 Prefix
=> Make_Identifier
(End_Loc
, Name_uObject
),
3889 Selector_Name
=> Make_Identifier
(End_Loc
, Name_uObject
)),
3890 Attribute_Name
=> Name_Unchecked_Access
))));
3892 -- When exceptions can not be propagated, we never need to call
3893 -- Exception_Complete_Entry_Body
3895 if No_Exception_Handlers_Set
then
3897 Make_Subprogram_Body
(Loc
,
3898 Specification
=> Espec
,
3899 Declarations
=> Op_Decls
,
3900 Handled_Statement_Sequence
=>
3901 Make_Handled_Sequence_Of_Statements
(Loc
,
3902 Statements
=> Op_Stats
,
3903 End_Label
=> End_Lab
));
3906 Ohandle
:= Make_Others_Choice
(Loc
);
3907 Set_All_Others
(Ohandle
);
3909 case Corresponding_Runtime_Package
(Pid
) is
3910 when System_Tasking_Protected_Objects_Entries
=>
3913 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3915 when System_Tasking_Protected_Objects_Single_Entry
=>
3918 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3921 raise Program_Error
;
3924 -- Establish link between subprogram body entity and source entry
3926 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
3928 -- Create body of entry procedure. The renaming declarations are
3929 -- placed ahead of the block that contains the actual entry body.
3932 Make_Subprogram_Body
(Loc
,
3933 Specification
=> Espec
,
3934 Declarations
=> Op_Decls
,
3935 Handled_Statement_Sequence
=>
3936 Make_Handled_Sequence_Of_Statements
(Loc
,
3937 Statements
=> Op_Stats
,
3938 End_Label
=> End_Lab
,
3939 Exception_Handlers
=> New_List
(
3940 Make_Implicit_Exception_Handler
(Han_Loc
,
3941 Exception_Choices
=> New_List
(Ohandle
),
3943 Statements
=> New_List
(
3944 Make_Procedure_Call_Statement
(Han_Loc
,
3946 Parameter_Associations
=> New_List
(
3947 Make_Attribute_Reference
(Han_Loc
,
3949 Make_Selected_Component
(Han_Loc
,
3951 Make_Identifier
(Han_Loc
, Name_uObject
),
3953 Make_Identifier
(Han_Loc
, Name_uObject
)),
3954 Attribute_Name
=> Name_Unchecked_Access
),
3956 Make_Function_Call
(Han_Loc
,
3957 Name
=> New_Reference_To
(
3958 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3960 end Build_Protected_Entry
;
3962 -----------------------------------------
3963 -- Build_Protected_Entry_Specification --
3964 -----------------------------------------
3966 function Build_Protected_Entry_Specification
3969 Ent_Id
: Entity_Id
) return Node_Id
3971 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3974 Set_Debug_Info_Needed
(Def_Id
);
3976 if Present
(Ent_Id
) then
3977 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3981 Make_Procedure_Specification
(Loc
,
3982 Defining_Unit_Name
=> Def_Id
,
3983 Parameter_Specifications
=> New_List
(
3984 Make_Parameter_Specification
(Loc
,
3985 Defining_Identifier
=>
3986 Make_Defining_Identifier
(Loc
, Name_uO
),
3988 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3990 Make_Parameter_Specification
(Loc
,
3991 Defining_Identifier
=> P
,
3993 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3995 Make_Parameter_Specification
(Loc
,
3996 Defining_Identifier
=>
3997 Make_Defining_Identifier
(Loc
, Name_uE
),
3999 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
4000 end Build_Protected_Entry_Specification
;
4002 --------------------------
4003 -- Build_Protected_Spec --
4004 --------------------------
4006 function Build_Protected_Spec
4008 Obj_Type
: Entity_Id
;
4010 Unprotected
: Boolean := False) return List_Id
4012 Loc
: constant Source_Ptr
:= Sloc
(N
);
4015 New_Plist
: List_Id
;
4016 New_Param
: Node_Id
;
4019 New_Plist
:= New_List
;
4021 Formal
:= First_Formal
(Ident
);
4022 while Present
(Formal
) loop
4024 Make_Parameter_Specification
(Loc
,
4025 Defining_Identifier
=>
4026 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
4027 In_Present
=> In_Present
(Parent
(Formal
)),
4028 Out_Present
=> Out_Present
(Parent
(Formal
)),
4029 Parameter_Type
=> New_Reference_To
(Etype
(Formal
), Loc
));
4032 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
4035 Append
(New_Param
, New_Plist
);
4036 Next_Formal
(Formal
);
4039 -- If the subprogram is a procedure and the context is not an access
4040 -- to protected subprogram, the parameter is in-out. Otherwise it is
4044 Make_Parameter_Specification
(Loc
,
4045 Defining_Identifier
=>
4046 Make_Defining_Identifier
(Loc
, Name_uObject
),
4049 (Etype
(Ident
) = Standard_Void_Type
4050 and then not Is_RTE
(Obj_Type
, RE_Address
)),
4052 New_Reference_To
(Obj_Type
, Loc
));
4053 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4054 Prepend_To
(New_Plist
, Decl
);
4057 end Build_Protected_Spec
;
4059 ---------------------------------------
4060 -- Build_Protected_Sub_Specification --
4061 ---------------------------------------
4063 function Build_Protected_Sub_Specification
4065 Prot_Typ
: Entity_Id
;
4066 Mode
: Subprogram_Protection_Mode
) return Node_Id
4068 Loc
: constant Source_Ptr
:= Sloc
(N
);
4072 New_Plist
: List_Id
;
4075 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
4076 (Dispatching_Mode
=> ' ',
4077 Protected_Mode
=> 'P',
4078 Unprotected_Mode
=> 'N');
4081 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
4084 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
4089 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
4092 Build_Protected_Spec
4093 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
4094 Mode
= Unprotected_Mode
);
4096 Make_Defining_Identifier
(Loc
,
4097 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
4099 -- The unprotected operation carries the user code, and debugging
4100 -- information must be generated for it, even though this spec does
4101 -- not come from source. It is also convenient to allow gdb to step
4102 -- into the protected operation, even though it only contains lock/
4105 Set_Debug_Info_Needed
(New_Id
);
4107 -- If a pragma Eliminate applies to the source entity, the internal
4108 -- subprograms will be eliminated as well.
4110 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
4112 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
4114 Make_Procedure_Specification
(Loc
,
4115 Defining_Unit_Name
=> New_Id
,
4116 Parameter_Specifications
=> New_Plist
);
4118 -- Create a new specification for the anonymous subprogram type
4122 Make_Function_Specification
(Loc
,
4123 Defining_Unit_Name
=> New_Id
,
4124 Parameter_Specifications
=> New_Plist
,
4125 Result_Definition
=>
4126 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
4128 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
4132 end Build_Protected_Sub_Specification
;
4134 -------------------------------------
4135 -- Build_Protected_Subprogram_Body --
4136 -------------------------------------
4138 function Build_Protected_Subprogram_Body
4141 N_Op_Spec
: Node_Id
) return Node_Id
4143 Loc
: constant Source_Ptr
:= Sloc
(N
);
4145 P_Op_Spec
: Node_Id
;
4148 Unprot_Call
: Node_Id
;
4150 Lock_Name
: Node_Id
;
4151 Lock_Stmt
: Node_Id
;
4152 Service_Name
: Node_Id
;
4154 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
4155 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
4157 Object_Parm
: Node_Id
;
4162 Op_Spec
:= Specification
(N
);
4163 Exc_Safe
:= Is_Exception_Safe
(N
);
4166 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
4168 -- Build a list of the formal parameters of the protected version of
4169 -- the subprogram to use as the actual parameters of the unprotected
4172 Uactuals
:= New_List
;
4173 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
4174 while Present
(Pformal
) loop
4175 Append_To
(Uactuals
,
4176 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
4180 -- Make a call to the unprotected version of the subprogram built above
4181 -- for use by the protected version built below.
4183 if Nkind
(Op_Spec
) = N_Function_Specification
then
4185 R
:= Make_Temporary
(Loc
, 'R');
4187 Make_Object_Declaration
(Loc
,
4188 Defining_Identifier
=> R
,
4189 Constant_Present
=> True,
4190 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
4192 Make_Function_Call
(Loc
,
4193 Name
=> Make_Identifier
(Loc
,
4194 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4195 Parameter_Associations
=> Uactuals
));
4198 Make_Simple_Return_Statement
(Loc
,
4199 Expression
=> New_Reference_To
(R
, Loc
));
4202 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
4203 Expression
=> Make_Function_Call
(Loc
,
4205 Make_Identifier
(Loc
,
4206 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4207 Parameter_Associations
=> Uactuals
));
4210 Lock_Kind
:= RE_Lock_Read_Only
;
4214 Make_Procedure_Call_Statement
(Loc
,
4216 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4217 Parameter_Associations
=> Uactuals
);
4219 Lock_Kind
:= RE_Lock
;
4222 -- Wrap call in block that will be covered by an at_end handler
4224 if not Exc_Safe
then
4225 Unprot_Call
:= Make_Block_Statement
(Loc
,
4226 Handled_Statement_Sequence
=>
4227 Make_Handled_Sequence_Of_Statements
(Loc
,
4228 Statements
=> New_List
(Unprot_Call
)));
4231 -- Make the protected subprogram body. This locks the protected
4232 -- object and calls the unprotected version of the subprogram.
4234 case Corresponding_Runtime_Package
(Pid
) is
4235 when System_Tasking_Protected_Objects_Entries
=>
4236 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
4237 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
4239 when System_Tasking_Protected_Objects_Single_Entry
=>
4240 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
4241 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
4243 when System_Tasking_Protected_Objects
=>
4244 Lock_Name
:= New_Reference_To
(RTE
(Lock_Kind
), Loc
);
4245 Service_Name
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
4248 raise Program_Error
;
4252 Make_Attribute_Reference
(Loc
,
4254 Make_Selected_Component
(Loc
,
4255 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4256 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4257 Attribute_Name
=> Name_Unchecked_Access
);
4259 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
4261 Parameter_Associations
=> New_List
(Object_Parm
));
4263 if Abort_Allowed
then
4265 Make_Procedure_Call_Statement
(Loc
,
4266 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
4267 Parameter_Associations
=> Empty_List
),
4271 Stmts
:= New_List
(Lock_Stmt
);
4274 if not Exc_Safe
then
4275 Append
(Unprot_Call
, Stmts
);
4277 if Nkind
(Op_Spec
) = N_Function_Specification
then
4279 Stmts
:= Empty_List
;
4281 Append
(Unprot_Call
, Stmts
);
4285 Make_Procedure_Call_Statement
(Loc
,
4286 Name
=> Service_Name
,
4287 Parameter_Associations
=>
4288 New_List
(New_Copy_Tree
(Object_Parm
))),
4291 if Abort_Allowed
then
4293 Make_Procedure_Call_Statement
(Loc
,
4294 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
4295 Parameter_Associations
=> Empty_List
),
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 if not Exc_Safe
then
4318 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4322 end Build_Protected_Subprogram_Body
;
4324 -------------------------------------
4325 -- Build_Protected_Subprogram_Call --
4326 -------------------------------------
4328 procedure Build_Protected_Subprogram_Call
4332 External
: Boolean := True)
4334 Loc
: constant Source_Ptr
:= Sloc
(N
);
4335 Sub
: constant Entity_Id
:= Entity
(Name
);
4341 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4344 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4347 if Present
(Parameter_Associations
(N
)) then
4348 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4353 -- If the type is an untagged derived type, convert to the root type,
4354 -- which is the one on which the operations are defined.
4356 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4357 and then not Is_Tagged_Type
(Etype
(Rec
))
4358 and then Is_Derived_Type
(Etype
(Rec
))
4360 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4361 Set_Subtype_Mark
(Rec
,
4362 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4365 Prepend
(Rec
, Params
);
4367 if Ekind
(Sub
) = E_Procedure
then
4369 Make_Procedure_Call_Statement
(Loc
,
4371 Parameter_Associations
=> Params
));
4374 pragma Assert
(Ekind
(Sub
) = E_Function
);
4376 Make_Function_Call
(Loc
,
4378 Parameter_Associations
=> Params
));
4382 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4383 and then Is_Entity_Name
(Expression
(Rec
))
4384 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4386 Add_Shared_Var_Lock_Procs
(N
);
4388 end Build_Protected_Subprogram_Call
;
4390 -------------------------
4391 -- Build_Selected_Name --
4392 -------------------------
4394 function Build_Selected_Name
4395 (Prefix
: Entity_Id
;
4396 Selector
: Entity_Id
;
4397 Append_Char
: Character := ' ') return Name_Id
4399 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4400 Select_Len
: Natural;
4403 Get_Name_String
(Chars
(Selector
));
4404 Select_Len
:= Name_Len
;
4405 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4406 Get_Name_String
(Chars
(Prefix
));
4408 -- If scope is anonymous type, discard suffix to recover name of
4409 -- single protected object. Otherwise use protected type name.
4411 if Name_Buffer
(Name_Len
) = 'T' then
4412 Name_Len
:= Name_Len
- 1;
4415 Add_Str_To_Name_Buffer
("__");
4416 for J
in 1 .. Select_Len
loop
4417 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4420 -- Now add the Append_Char if specified. The encoding to follow
4421 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4422 -- then the entity is associated to a protected type subprogram.
4423 -- Otherwise, it is a protected type entry. For each case, the
4424 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4426 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4428 if Append_Char
/= ' ' then
4429 if Append_Char
= 'P' or Append_Char
= 'N' then
4430 Add_Char_To_Name_Buffer
(Append_Char
);
4433 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4434 return New_External_Name
(Name_Find
, ' ', -1);
4439 end Build_Selected_Name
;
4441 -----------------------------
4442 -- Build_Simple_Entry_Call --
4443 -----------------------------
4445 -- A task entry call is converted to a call to Call_Simple
4448 -- P : parms := (parm, parm, parm);
4450 -- Call_Simple (acceptor-task, entry-index, P'Address);
4456 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4457 -- the parameters, and the constructed aggregate value contains either the
4458 -- parameters or, in the case of non-elementary types, references to these
4459 -- parameters. Then the address of this aggregate is passed to the runtime
4460 -- routine, along with the task id value and the task entry index value.
4461 -- Pnn is only required if parameters are present.
4463 -- The assignments after the call are present only in the case of in-out
4464 -- or out parameters for elementary types, and are used to assign back the
4465 -- resulting values of such parameters.
4467 -- Note: the reason that we insert a block here is that in the context
4468 -- of selects, conditional entry calls etc. the entry call statement
4469 -- appears on its own, not as an element of a list.
4471 -- A protected entry call is converted to a Protected_Entry_Call:
4474 -- P : E1_Params := (param, param, param);
4476 -- Bnn : Communications_Block;
4479 -- P : E1_Params := (param, param, param);
4480 -- Bnn : Communications_Block;
4483 -- Protected_Entry_Call (
4484 -- Object => po._object'Access,
4485 -- E => <entry index>;
4486 -- Uninterpreted_Data => P'Address;
4487 -- Mode => Simple_Call;
4494 procedure Build_Simple_Entry_Call
4503 -- If call has been inlined, nothing left to do
4505 if Nkind
(N
) = N_Block_Statement
then
4509 -- Convert entry call to Call_Simple call
4512 Loc
: constant Source_Ptr
:= Sloc
(N
);
4513 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4514 Stats
: constant List_Id
:= New_List
;
4517 Comm_Name
: Entity_Id
;
4521 Ent_Acc
: Entity_Id
;
4523 Iface_Tag
: Entity_Id
;
4524 Iface_Typ
: Entity_Id
;
4537 -- Simple entry and entry family cases merge here
4539 Ent
:= Entity
(Ename
);
4540 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4541 Conctyp
:= Etype
(Concval
);
4543 -- If prefix is an access type, dereference to obtain the task type
4545 if Is_Access_Type
(Conctyp
) then
4546 Conctyp
:= Designated_Type
(Conctyp
);
4549 -- Special case for protected subprogram calls
4551 if Is_Protected_Type
(Conctyp
)
4552 and then Is_Subprogram
(Entity
(Ename
))
4554 if not Is_Eliminated
(Entity
(Ename
)) then
4555 Build_Protected_Subprogram_Call
4556 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4563 -- First parameter is the Task_Id value from the task value or the
4564 -- Object from the protected object value, obtained by selecting
4565 -- the _Task_Id or _Object from the result of doing an unchecked
4566 -- conversion to convert the value to the corresponding record type.
4568 if Nkind
(Concval
) = N_Function_Call
4569 and then Is_Task_Type
(Conctyp
)
4570 and then Ada_Version
>= Ada_2005
4573 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4574 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4579 Make_Object_Declaration
(Loc
,
4580 Defining_Identifier
=> Obj
,
4581 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4582 Expression
=> ExpR
);
4583 Set_Etype
(Obj
, Conctyp
);
4584 Decls
:= New_List
(Decl
);
4585 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4592 Parm1
:= Concurrent_Ref
(Concval
);
4594 -- Second parameter is the entry index, computed by the routine
4595 -- provided for this purpose. The value of this expression is
4596 -- assigned to an intermediate variable to assure that any entry
4597 -- family index expressions are evaluated before the entry
4601 or else Restriction_Active
(No_Entry_Queue
) = False
4602 or else not Is_Protected_Type
(Conctyp
)
4603 or else Number_Entries
(Conctyp
) > 1
4604 or else (Has_Attach_Handler
(Conctyp
)
4605 and then not Restricted_Profile
)
4607 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4610 Make_Object_Declaration
(Loc
,
4611 Defining_Identifier
=> X
,
4612 Object_Definition
=>
4613 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
4614 Expression
=> Actual_Index_Expression
(
4615 Loc
, Entity
(Ename
), Index
, Concval
));
4617 Append_To
(Decls
, Xdecl
);
4618 Parm2
:= New_Reference_To
(X
, Loc
);
4625 -- The third parameter is the packaged parameters. If there are
4626 -- none, then it is just the null address, since nothing is passed.
4629 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
4632 -- Case of parameters present, where third argument is the address
4633 -- of a packaged record containing the required parameter values.
4636 -- First build a list of parameter values, which are references to
4637 -- objects of the parameter types.
4641 Actual
:= First_Actual
(N
);
4642 Formal
:= First_Formal
(Ent
);
4644 while Present
(Actual
) loop
4646 -- If it is a by_copy_type, copy it to a new variable. The
4647 -- packaged record has a field that points to this variable.
4649 if Is_By_Copy_Type
(Etype
(Actual
)) then
4651 Make_Object_Declaration
(Loc
,
4652 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4653 Aliased_Present
=> True,
4654 Object_Definition
=>
4655 New_Reference_To
(Etype
(Formal
), Loc
));
4657 -- Mark the object as not needing initialization since the
4658 -- initialization is performed separately, avoiding errors
4659 -- on cases such as formals of null-excluding access types.
4661 Set_No_Initialization
(N_Node
);
4663 -- We must make an assignment statement separate for the
4664 -- case of limited type. We cannot assign it unless the
4665 -- Assignment_OK flag is set first. An out formal of an
4666 -- access type must also be initialized from the actual,
4667 -- as stated in RM 6.4.1 (13).
4669 if Ekind
(Formal
) /= E_Out_Parameter
4670 or else Is_Access_Type
(Etype
(Formal
))
4673 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
4674 Set_Assignment_OK
(N_Var
);
4676 Make_Assignment_Statement
(Loc
,
4678 Expression
=> Relocate_Node
(Actual
)));
4681 Append
(N_Node
, Decls
);
4684 Make_Attribute_Reference
(Loc
,
4685 Attribute_Name
=> Name_Unchecked_Access
,
4687 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4689 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4691 elsif Is_VM_By_Copy_Actual
(Actual
) then
4693 Make_Object_Declaration
(Loc
,
4694 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4695 Aliased_Present
=> True,
4696 Object_Definition
=>
4697 New_Reference_To
(Etype
(Formal
), Loc
),
4698 Expression
=> New_Copy_Tree
(Actual
));
4699 Set_Assignment_OK
(N_Node
);
4701 Append
(N_Node
, Decls
);
4704 Make_Attribute_Reference
(Loc
,
4705 Attribute_Name
=> Name_Unchecked_Access
,
4707 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4710 -- Interface class-wide formal
4712 if Ada_Version
>= Ada_2005
4713 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4714 and then Is_Interface
(Etype
(Formal
))
4716 Iface_Typ
:= Etype
(Etype
(Formal
));
4719 -- formal_iface_type! (actual.iface_tag)'reference
4722 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4723 pragma Assert
(Present
(Iface_Tag
));
4726 Make_Reference
(Loc
,
4727 Unchecked_Convert_To
(Iface_Typ
,
4728 Make_Selected_Component
(Loc
,
4730 Relocate_Node
(Actual
),
4732 New_Reference_To
(Iface_Tag
, Loc
)))));
4738 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4742 Next_Actual
(Actual
);
4743 Next_Formal_With_Extras
(Formal
);
4746 -- Now build the declaration of parameters initialized with the
4747 -- aggregate containing this constructed parameter list.
4749 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4752 Make_Object_Declaration
(Loc
,
4753 Defining_Identifier
=> P
,
4754 Object_Definition
=>
4755 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
4757 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4760 Make_Attribute_Reference
(Loc
,
4761 Prefix
=> New_Reference_To
(P
, Loc
),
4762 Attribute_Name
=> Name_Address
);
4764 Append
(Pdecl
, Decls
);
4767 -- Now we can create the call, case of protected type
4769 if Is_Protected_Type
(Conctyp
) then
4770 case Corresponding_Runtime_Package
(Conctyp
) is
4771 when System_Tasking_Protected_Objects_Entries
=>
4773 -- Change the type of the index declaration
4775 Set_Object_Definition
(Xdecl
,
4776 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
4778 -- Some additional declarations for protected entry calls
4784 -- Bnn : Communications_Block;
4786 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4789 Make_Object_Declaration
(Loc
,
4790 Defining_Identifier
=> Comm_Name
,
4791 Object_Definition
=>
4792 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
4794 -- Some additional statements for protected entry calls
4796 -- Protected_Entry_Call (
4797 -- Object => po._object'Access,
4798 -- E => <entry index>;
4799 -- Uninterpreted_Data => P'Address;
4800 -- Mode => Simple_Call;
4804 Make_Procedure_Call_Statement
(Loc
,
4806 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
4808 Parameter_Associations
=> New_List
(
4809 Make_Attribute_Reference
(Loc
,
4810 Attribute_Name
=> Name_Unchecked_Access
,
4814 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
4815 New_Occurrence_Of
(Comm_Name
, Loc
)));
4817 when System_Tasking_Protected_Objects_Single_Entry
=>
4818 -- Protected_Single_Entry_Call (
4819 -- Object => po._object'Access,
4820 -- Uninterpreted_Data => P'Address;
4821 -- Mode => Simple_Call);
4824 Make_Procedure_Call_Statement
(Loc
,
4825 Name
=> New_Reference_To
(
4826 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4828 Parameter_Associations
=> New_List
(
4829 Make_Attribute_Reference
(Loc
,
4830 Attribute_Name
=> Name_Unchecked_Access
,
4833 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
4836 raise Program_Error
;
4839 -- Case of task type
4843 Make_Procedure_Call_Statement
(Loc
,
4844 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
4845 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4849 Append_To
(Stats
, Call
);
4851 -- If there are out or in/out parameters by copy add assignment
4852 -- statements for the result values.
4854 if Present
(Parms
) then
4855 Actual
:= First_Actual
(N
);
4856 Formal
:= First_Formal
(Ent
);
4858 Set_Assignment_OK
(Actual
);
4859 while Present
(Actual
) loop
4860 if (Is_By_Copy_Type
(Etype
(Actual
))
4861 or else Is_VM_By_Copy_Actual
(Actual
))
4862 and then Ekind
(Formal
) /= E_In_Parameter
4865 Make_Assignment_Statement
(Loc
,
4866 Name
=> New_Copy
(Actual
),
4868 Make_Explicit_Dereference
(Loc
,
4869 Make_Selected_Component
(Loc
,
4870 Prefix
=> New_Reference_To
(P
, Loc
),
4872 Make_Identifier
(Loc
, Chars
(Formal
)))));
4874 -- In all cases (including limited private types) we want
4875 -- the assignment to be valid.
4877 Set_Assignment_OK
(Name
(N_Node
));
4879 -- If the call is the triggering alternative in an
4880 -- asynchronous select, or the entry_call alternative of a
4881 -- conditional entry call, the assignments for in-out
4882 -- parameters are incorporated into the statement list that
4883 -- follows, so that there are executed only if the entry
4886 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4887 and then N
= Triggering_Statement
(Parent
(N
)))
4889 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4890 and then N
= Entry_Call_Statement
(Parent
(N
)))
4892 if No
(Statements
(Parent
(N
))) then
4893 Set_Statements
(Parent
(N
), New_List
);
4896 Prepend
(N_Node
, Statements
(Parent
(N
)));
4899 Insert_After
(Call
, N_Node
);
4903 Next_Actual
(Actual
);
4904 Next_Formal_With_Extras
(Formal
);
4908 -- Finally, create block and analyze it
4911 Make_Block_Statement
(Loc
,
4912 Declarations
=> Decls
,
4913 Handled_Statement_Sequence
=>
4914 Make_Handled_Sequence_Of_Statements
(Loc
,
4915 Statements
=> Stats
)));
4919 end Build_Simple_Entry_Call
;
4921 --------------------------------
4922 -- Build_Task_Activation_Call --
4923 --------------------------------
4925 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4926 Loc
: constant Source_Ptr
:= Sloc
(N
);
4933 -- For sequential elaboration policy, all the tasks will be activated at
4934 -- the end of the elaboration.
4936 if Partition_Elaboration_Policy
= 'S' then
4940 -- Get the activation chain entity. Except in the case of a package
4941 -- body, this is in the node that was passed. For a package body, we
4942 -- have to find the corresponding package declaration node.
4944 if Nkind
(N
) = N_Package_Body
then
4945 P
:= Corresponding_Spec
(N
);
4948 exit when Nkind
(P
) = N_Package_Declaration
;
4951 Chain
:= Activation_Chain_Entity
(P
);
4954 Chain
:= Activation_Chain_Entity
(N
);
4957 if Present
(Chain
) then
4958 if Restricted_Profile
then
4959 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4961 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
4965 Make_Procedure_Call_Statement
(Loc
,
4967 Parameter_Associations
=>
4968 New_List
(Make_Attribute_Reference
(Loc
,
4969 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4970 Attribute_Name
=> Name_Unchecked_Access
)));
4972 if Nkind
(N
) = N_Package_Declaration
then
4973 if Present
(Corresponding_Body
(N
)) then
4976 elsif Present
(Private_Declarations
(Specification
(N
))) then
4977 Append
(Call
, Private_Declarations
(Specification
(N
)));
4980 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4984 if Present
(Handled_Statement_Sequence
(N
)) then
4986 -- The call goes at the start of the statement sequence
4987 -- after the start of exception range label if one is present.
4993 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4995 -- A special case, skip exception range label if one is
4996 -- present (from front end zcx processing).
4998 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
5002 -- Another special case, if the first statement is a block
5003 -- from optimization of a local raise to a goto, then the
5004 -- call goes inside this block.
5006 if Nkind
(Stm
) = N_Block_Statement
5007 and then Exception_Junk
(Stm
)
5010 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
5013 -- Insertion point is after any exception label pushes,
5014 -- since we want it covered by any local handlers.
5016 while Nkind
(Stm
) in N_Push_xxx_Label
loop
5020 -- Now we have the proper insertion point
5022 Insert_Before
(Stm
, Call
);
5026 Set_Handled_Statement_Sequence
(N
,
5027 Make_Handled_Sequence_Of_Statements
(Loc
,
5028 Statements
=> New_List
(Call
)));
5033 Check_Task_Activation
(N
);
5035 end Build_Task_Activation_Call
;
5037 -------------------------------
5038 -- Build_Task_Allocate_Block --
5039 -------------------------------
5041 procedure Build_Task_Allocate_Block
5046 T
: constant Entity_Id
:= Entity
(Expression
(N
));
5047 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
5048 Loc
: constant Source_Ptr
:= Sloc
(N
);
5049 Chain
: constant Entity_Id
:=
5050 Make_Defining_Identifier
(Loc
, Name_uChain
);
5051 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5056 Make_Block_Statement
(Loc
,
5057 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5058 Declarations
=> New_List
(
5060 -- _Chain : Activation_Chain;
5062 Make_Object_Declaration
(Loc
,
5063 Defining_Identifier
=> Chain
,
5064 Aliased_Present
=> True,
5065 Object_Definition
=>
5066 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
5068 Handled_Statement_Sequence
=>
5069 Make_Handled_Sequence_Of_Statements
(Loc
,
5071 Statements
=> New_List
(
5075 Make_Procedure_Call_Statement
(Loc
,
5076 Name
=> New_Reference_To
(Init
, Loc
),
5077 Parameter_Associations
=> Args
),
5079 -- Activate_Tasks (_Chain);
5081 Make_Procedure_Call_Statement
(Loc
,
5082 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
5083 Parameter_Associations
=> New_List
(
5084 Make_Attribute_Reference
(Loc
,
5085 Prefix
=> New_Reference_To
(Chain
, Loc
),
5086 Attribute_Name
=> Name_Unchecked_Access
))))),
5088 Has_Created_Identifier
=> True,
5089 Is_Task_Allocation_Block
=> True);
5092 Make_Implicit_Label_Declaration
(Loc
,
5093 Defining_Identifier
=> Blkent
,
5094 Label_Construct
=> Block
));
5096 Append_To
(Actions
, Block
);
5098 Set_Activation_Chain_Entity
(Block
, Chain
);
5099 end Build_Task_Allocate_Block
;
5101 -----------------------------------------------
5102 -- Build_Task_Allocate_Block_With_Init_Stmts --
5103 -----------------------------------------------
5105 procedure Build_Task_Allocate_Block_With_Init_Stmts
5108 Init_Stmts
: List_Id
)
5110 Loc
: constant Source_Ptr
:= Sloc
(N
);
5111 Chain
: constant Entity_Id
:=
5112 Make_Defining_Identifier
(Loc
, Name_uChain
);
5113 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5117 Append_To
(Init_Stmts
,
5118 Make_Procedure_Call_Statement
(Loc
,
5119 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
5120 Parameter_Associations
=> New_List
(
5121 Make_Attribute_Reference
(Loc
,
5122 Prefix
=> New_Reference_To
(Chain
, Loc
),
5123 Attribute_Name
=> Name_Unchecked_Access
))));
5126 Make_Block_Statement
(Loc
,
5127 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5128 Declarations
=> New_List
(
5130 -- _Chain : Activation_Chain;
5132 Make_Object_Declaration
(Loc
,
5133 Defining_Identifier
=> Chain
,
5134 Aliased_Present
=> True,
5135 Object_Definition
=>
5136 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
5138 Handled_Statement_Sequence
=>
5139 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5141 Has_Created_Identifier
=> True,
5142 Is_Task_Allocation_Block
=> True);
5145 Make_Implicit_Label_Declaration
(Loc
,
5146 Defining_Identifier
=> Blkent
,
5147 Label_Construct
=> Block
));
5149 Append_To
(Actions
, Block
);
5151 Set_Activation_Chain_Entity
(Block
, Chain
);
5152 end Build_Task_Allocate_Block_With_Init_Stmts
;
5154 -----------------------------------
5155 -- Build_Task_Proc_Specification --
5156 -----------------------------------
5158 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5159 Loc
: constant Source_Ptr
:= Sloc
(T
);
5160 Spec_Id
: Entity_Id
;
5163 -- Case of explicit task type, suffix TB
5165 if Comes_From_Source
(T
) then
5167 Make_Defining_Identifier
(Loc
,
5168 Chars
=> New_External_Name
(Chars
(T
), "TB"));
5170 -- Case of anonymous task type, suffix B
5174 Make_Defining_Identifier
(Loc
,
5175 Chars
=> New_External_Name
(Chars
(T
), 'B'));
5178 Set_Is_Internal
(Spec_Id
);
5180 -- Associate the procedure with the task, if this is the declaration
5181 -- (and not the body) of the procedure.
5183 if No
(Task_Body_Procedure
(T
)) then
5184 Set_Task_Body_Procedure
(T
, Spec_Id
);
5188 Make_Procedure_Specification
(Loc
,
5189 Defining_Unit_Name
=> Spec_Id
,
5190 Parameter_Specifications
=> New_List
(
5191 Make_Parameter_Specification
(Loc
,
5192 Defining_Identifier
=>
5193 Make_Defining_Identifier
(Loc
, Name_uTask
),
5195 Make_Access_Definition
(Loc
,
5197 New_Reference_To
(Corresponding_Record_Type
(T
), Loc
)))));
5198 end Build_Task_Proc_Specification
;
5200 ---------------------------------------
5201 -- Build_Unprotected_Subprogram_Body --
5202 ---------------------------------------
5204 function Build_Unprotected_Subprogram_Body
5206 Pid
: Node_Id
) return Node_Id
5208 Decls
: constant List_Id
:= Declarations
(N
);
5211 -- Add renamings for the Protection object, discriminals, privals and
5212 -- the entry index constant for use by debugger.
5214 Debug_Private_Data_Declarations
(Decls
);
5216 -- Make an unprotected version of the subprogram for use within the same
5217 -- object, with a new name and an additional parameter representing the
5221 Make_Subprogram_Body
(Sloc
(N
),
5223 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5224 Declarations
=> Decls
,
5225 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5226 end Build_Unprotected_Subprogram_Body
;
5228 ----------------------------
5229 -- Collect_Entry_Families --
5230 ----------------------------
5232 procedure Collect_Entry_Families
5235 Current_Node
: in out Node_Id
;
5236 Conctyp
: Entity_Id
)
5239 Efam_Decl
: Node_Id
;
5240 Efam_Type
: Entity_Id
;
5243 Efam
:= First_Entity
(Conctyp
);
5244 while Present
(Efam
) loop
5245 if Ekind
(Efam
) = E_Entry_Family
then
5246 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5251 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5253 Bas_Decl
: Node_Id
:= Empty
;
5258 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5260 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5261 Bas
:= Make_Temporary
(Loc
, 'B');
5264 Make_Subtype_Declaration
(Loc
,
5265 Defining_Identifier
=> Bas
,
5266 Subtype_Indication
=>
5267 Make_Subtype_Indication
(Loc
,
5269 New_Occurrence_Of
(Standard_Integer
, Loc
),
5271 Make_Range_Constraint
(Loc
,
5272 Range_Expression
=> Make_Range
(Loc
,
5273 Make_Integer_Literal
5274 (Loc
, -Entry_Family_Bound
),
5275 Make_Integer_Literal
5276 (Loc
, Entry_Family_Bound
- 1)))));
5278 Insert_After
(Current_Node
, Bas_Decl
);
5279 Current_Node
:= Bas_Decl
;
5284 Make_Full_Type_Declaration
(Loc
,
5285 Defining_Identifier
=> Efam_Type
,
5287 Make_Unconstrained_Array_Definition
(Loc
,
5289 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5291 Component_Definition
=>
5292 Make_Component_Definition
(Loc
,
5293 Aliased_Present
=> False,
5294 Subtype_Indication
=>
5295 New_Reference_To
(Standard_Character
, Loc
))));
5298 Insert_After
(Current_Node
, Efam_Decl
);
5299 Current_Node
:= Efam_Decl
;
5300 Analyze
(Efam_Decl
);
5303 Make_Component_Declaration
(Loc
,
5304 Defining_Identifier
=>
5305 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5307 Component_Definition
=>
5308 Make_Component_Definition
(Loc
,
5309 Aliased_Present
=> False,
5310 Subtype_Indication
=>
5311 Make_Subtype_Indication
(Loc
,
5313 New_Occurrence_Of
(Efam_Type
, Loc
),
5316 Make_Index_Or_Discriminant_Constraint
(Loc
,
5317 Constraints
=> New_List
(
5319 (Etype
(Discrete_Subtype_Definition
5320 (Parent
(Efam
))), Loc
)))))));
5326 end Collect_Entry_Families
;
5328 -----------------------
5329 -- Concurrent_Object --
5330 -----------------------
5332 function Concurrent_Object
5333 (Spec_Id
: Entity_Id
;
5334 Conc_Typ
: Entity_Id
) return Entity_Id
5337 -- Parameter _O or _object
5339 if Is_Protected_Type
(Conc_Typ
) then
5340 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5345 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5346 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5348 end Concurrent_Object
;
5350 ----------------------
5351 -- Copy_Result_Type --
5352 ----------------------
5354 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5355 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5360 -- If the result type is an access_to_subprogram, we must create new
5361 -- entities for its spec.
5363 if Nkind
(New_Res
) = N_Access_Definition
5364 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5366 -- Provide new entities for the formals
5368 Par_Spec
:= First
(Parameter_Specifications
5369 (Access_To_Subprogram_Definition
(New_Res
)));
5370 while Present
(Par_Spec
) loop
5371 Formal
:= Defining_Identifier
(Par_Spec
);
5372 Set_Defining_Identifier
(Par_Spec
,
5373 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5379 end Copy_Result_Type
;
5381 --------------------
5382 -- Concurrent_Ref --
5383 --------------------
5385 -- The expression returned for a reference to a concurrent object has the
5388 -- taskV!(name)._Task_Id
5392 -- objectV!(name)._Object
5394 -- for a protected object. For the case of an access to a concurrent
5395 -- object, there is an extra explicit dereference:
5397 -- taskV!(name.all)._Task_Id
5398 -- objectV!(name.all)._Object
5400 -- here taskV and objectV are the types for the associated records, which
5401 -- contain the required _Task_Id and _Object fields for tasks and protected
5402 -- objects, respectively.
5404 -- For the case of a task type name, the expression is
5408 -- i.e. a call to the Self function which returns precisely this Task_Id
5410 -- For the case of a protected type name, the expression is
5414 -- which is a renaming of the _object field of the current object
5415 -- record, passed into protected operations as a parameter.
5417 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5418 Loc
: constant Source_Ptr
:= Sloc
(N
);
5419 Ntyp
: constant Entity_Id
:= Etype
(N
);
5423 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5424 -- Check whether the reference is to the immediately enclosing task
5425 -- type, or to an outer one (rare but legal).
5427 ---------------------
5428 -- Is_Current_Task --
5429 ---------------------
5431 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5435 Scop
:= Current_Scope
;
5436 while Present
(Scop
)
5437 and then Scop
/= Standard_Standard
5443 elsif Is_Task_Type
(Scop
) then
5446 -- If this is a procedure nested within the task type, we must
5447 -- assume that it can be called from an inner task, and therefore
5448 -- cannot treat it as a local reference.
5450 elsif Is_Overloadable
(Scop
)
5451 and then In_Open_Scopes
(T
)
5456 Scop
:= Scope
(Scop
);
5460 -- We know that we are within the task body, so should have found it
5463 raise Program_Error
;
5464 end Is_Current_Task
;
5466 -- Start of processing for Concurrent_Ref
5469 if Is_Access_Type
(Ntyp
) then
5470 Dtyp
:= Designated_Type
(Ntyp
);
5472 if Is_Protected_Type
(Dtyp
) then
5473 Sel
:= Name_uObject
;
5475 Sel
:= Name_uTask_Id
;
5479 Make_Selected_Component
(Loc
,
5481 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5482 Make_Explicit_Dereference
(Loc
, N
)),
5483 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5485 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5486 if Is_Task_Type
(Entity
(N
)) then
5488 if Is_Current_Task
(Entity
(N
)) then
5490 Make_Function_Call
(Loc
,
5491 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
5496 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5497 T_Body
: constant Node_Id
:=
5498 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5502 Make_Object_Declaration
(Loc
,
5503 Defining_Identifier
=> T_Self
,
5504 Object_Definition
=>
5505 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5507 Make_Function_Call
(Loc
,
5508 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
5509 Prepend
(Decl
, Declarations
(T_Body
));
5511 Set_Scope
(T_Self
, Entity
(N
));
5512 return New_Occurrence_Of
(T_Self
, Loc
);
5517 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5520 New_Reference_To
(Find_Protection_Object
(Current_Scope
), Loc
);
5524 if Is_Protected_Type
(Ntyp
) then
5525 Sel
:= Name_uObject
;
5527 elsif Is_Task_Type
(Ntyp
) then
5528 Sel
:= Name_uTask_Id
;
5531 raise Program_Error
;
5535 Make_Selected_Component
(Loc
,
5537 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5539 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5543 ------------------------
5544 -- Convert_Concurrent --
5545 ------------------------
5547 function Convert_Concurrent
5549 Typ
: Entity_Id
) return Node_Id
5552 if not Is_Concurrent_Type
(Typ
) then
5556 Unchecked_Convert_To
5557 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5559 end Convert_Concurrent
;
5561 -------------------------------------
5562 -- Debug_Private_Data_Declarations --
5563 -------------------------------------
5565 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5566 Debug_Nod
: Node_Id
;
5570 Decl
:= First
(Decls
);
5571 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5572 -- Declaration for concurrent entity _object and its access type,
5573 -- along with the entry index subtype:
5574 -- type prot_typVP is access prot_typV;
5575 -- _object : prot_typVP := prot_typV (_O);
5576 -- subtype Jnn is <Type of Index> range Low .. High;
5578 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5579 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5581 -- Declaration for the Protection object, discriminals, privals and
5582 -- entry index constant:
5583 -- conc_typR : protection_typ renames _object._object;
5584 -- discr_nameD : discr_typ renames _object.discr_name;
5585 -- discr_nameD : discr_typ renames _task.discr_name;
5586 -- prival_name : comp_typ renames _object.comp_name;
5587 -- J : constant Jnn :=
5588 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5590 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5591 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5592 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5594 if Present
(Debug_Nod
) then
5595 Insert_After
(Decl
, Debug_Nod
);
5601 end Debug_Private_Data_Declarations
;
5603 ------------------------------
5604 -- Ensure_Statement_Present --
5605 ------------------------------
5607 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5611 if Opt
.Suppress_Control_Flow_Optimizations
5612 and then Is_Empty_List
(Statements
(Alt
))
5614 Stmt
:= Make_Null_Statement
(Loc
);
5616 -- Mark NULL statement as coming from source so that it is not
5617 -- eliminated by GIGI.
5619 -- Another covert channel! If this is a requirement, it must be
5620 -- documented in sinfo/einfo ???
5622 Set_Comes_From_Source
(Stmt
, True);
5624 Set_Statements
(Alt
, New_List
(Stmt
));
5626 end Ensure_Statement_Present
;
5628 ----------------------------
5629 -- Entry_Index_Expression --
5630 ----------------------------
5632 function Entry_Index_Expression
5636 Ttyp
: Entity_Id
) return Node_Id
5646 -- The queues of entries and entry families appear in textual order in
5647 -- the associated record. The entry index is computed as the sum of the
5648 -- number of queues for all entries that precede the designated one, to
5649 -- which is added the index expression, if this expression denotes a
5650 -- member of a family.
5652 -- The following is a place holder for the count of simple entries
5654 Num
:= Make_Integer_Literal
(Sloc
, 1);
5656 -- We construct an expression which is a series of addition operations.
5657 -- The first operand is the number of single entries that precede this
5658 -- one, the second operand is the index value relative to the start of
5659 -- the referenced family, and the remaining operands are the lengths of
5660 -- the entry families that precede this entry, i.e. the constructed
5663 -- number_simple_entries +
5664 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5665 -- family'length + ...
5667 -- where index-value is the given index value, and s is the index
5668 -- subtype (we have to use pos because the subtype might be an
5669 -- enumeration type preventing direct subtraction). Note that the task
5670 -- entry array is one-indexed.
5672 -- The upper bound of the entry family may be a discriminant, so we
5673 -- retrieve the lower bound explicitly to compute offset, rather than
5674 -- using the index subtype which may mention a discriminant.
5676 if Present
(Index
) then
5677 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5686 Make_Attribute_Reference
(Sloc
,
5687 Attribute_Name
=> Name_Pos
,
5688 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
5689 Expressions
=> New_List
(Relocate_Node
(Index
))),
5697 -- Now add lengths of preceding entries and entry families
5699 Prev
:= First_Entity
(Ttyp
);
5701 while Chars
(Prev
) /= Chars
(Ent
)
5702 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5703 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5705 if Ekind
(Prev
) = E_Entry
then
5706 Set_Intval
(Num
, Intval
(Num
) + 1);
5708 elsif Ekind
(Prev
) = E_Entry_Family
then
5710 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5711 Lo
:= Type_Low_Bound
(S
);
5712 Hi
:= Type_High_Bound
(S
);
5717 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5719 -- Other components are anonymous types to be ignored
5729 end Entry_Index_Expression
;
5731 ---------------------------
5732 -- Establish_Task_Master --
5733 ---------------------------
5735 procedure Establish_Task_Master
(N
: Node_Id
) is
5739 if Restriction_Active
(No_Task_Hierarchy
) = False then
5740 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5742 -- The block may have no declarations, and nevertheless be a task
5743 -- master, if it contains a call that may return an object that
5746 if No
(Declarations
(N
)) then
5747 Set_Declarations
(N
, New_List
(Call
));
5749 Prepend_To
(Declarations
(N
), Call
);
5754 end Establish_Task_Master
;
5756 --------------------------------
5757 -- Expand_Accept_Declarations --
5758 --------------------------------
5760 -- Part of the expansion of an accept statement involves the creation of
5761 -- a declaration that can be referenced from the statement sequence of
5766 -- This declaration is inserted immediately before the accept statement
5767 -- and it is important that it be inserted before the statements of the
5768 -- statement sequence are analyzed. Thus it would be too late to create
5769 -- this declaration in the Expand_N_Accept_Statement routine, which is
5770 -- why there is a separate procedure to be called directly from Sem_Ch9.
5772 -- Ann is used to hold the address of the record containing the parameters
5773 -- (see Expand_N_Entry_Call for more details on how this record is built).
5774 -- References to the parameters do an unchecked conversion of this address
5775 -- to a pointer to the required record type, and then access the field that
5776 -- holds the value of the required parameter. The entity for the address
5777 -- variable is held as the top stack element (i.e. the last element) of the
5778 -- Accept_Address stack in the corresponding entry entity, and this element
5779 -- must be set in place before the statements are processed.
5781 -- The above description applies to the case of a stand alone accept
5782 -- statement, i.e. one not appearing as part of a select alternative.
5784 -- For the case of an accept that appears as part of a select alternative
5785 -- of a selective accept, we must still create the declaration right away,
5786 -- since Ann is needed immediately, but there is an important difference:
5788 -- The declaration is inserted before the selective accept, not before
5789 -- the accept statement (which is not part of a list anyway, and so would
5790 -- not accommodate inserted declarations)
5792 -- We only need one address variable for the entire selective accept. So
5793 -- the Ann declaration is created only for the first accept alternative,
5794 -- and subsequent accept alternatives reference the same Ann variable.
5796 -- We can distinguish the two cases by seeing whether the accept statement
5797 -- is part of a list. If not, then it must be in an accept alternative.
5799 -- To expand the requeue statement, a label is provided at the end of the
5800 -- accept statement or alternative of which it is a part, so that the
5801 -- statement can be skipped after the requeue is complete. This label is
5802 -- created here rather than during the expansion of the accept statement,
5803 -- because it will be needed by any requeue statements within the accept,
5804 -- which are expanded before the accept.
5806 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5807 Loc
: constant Source_Ptr
:= Sloc
(N
);
5808 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5809 Ann
: Entity_Id
:= Empty
;
5816 if Full_Expander_Active
then
5818 -- If we have no handled statement sequence, we may need to build
5819 -- a dummy sequence consisting of a null statement. This can be
5820 -- skipped if the trivial accept optimization is permitted.
5822 if not Trivial_Accept_OK
5824 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5826 Set_Handled_Statement_Sequence
(N
,
5827 Make_Handled_Sequence_Of_Statements
(Loc
,
5828 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5831 -- Create and declare two labels to be placed at the end of the
5832 -- accept statement. The first label is used to allow requeues to
5833 -- skip the remainder of entry processing. The second label is used
5834 -- to skip the remainder of entry processing if the rendezvous
5835 -- completes in the middle of the accept body.
5837 if Present
(Handled_Statement_Sequence
(N
)) then
5842 Ent
:= Make_Temporary
(Loc
, 'L');
5843 Lab
:= Make_Label
(Loc
, New_Reference_To
(Ent
, Loc
));
5845 Make_Implicit_Label_Declaration
(Loc
,
5846 Defining_Identifier
=> Ent
,
5847 Label_Construct
=> Lab
);
5848 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5850 Ent
:= Make_Temporary
(Loc
, 'L');
5851 Lab
:= Make_Label
(Loc
, New_Reference_To
(Ent
, Loc
));
5853 Make_Implicit_Label_Declaration
(Loc
,
5854 Defining_Identifier
=> Ent
,
5855 Label_Construct
=> Lab
);
5856 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5864 -- Case of stand alone accept statement
5866 if Is_List_Member
(N
) then
5868 if Present
(Handled_Statement_Sequence
(N
)) then
5869 Ann
:= Make_Temporary
(Loc
, 'A');
5872 Make_Object_Declaration
(Loc
,
5873 Defining_Identifier
=> Ann
,
5874 Object_Definition
=>
5875 New_Reference_To
(RTE
(RE_Address
), Loc
));
5877 Insert_Before_And_Analyze
(N
, Adecl
);
5878 Insert_Before_And_Analyze
(N
, Ldecl
);
5879 Insert_Before_And_Analyze
(N
, Ldecl2
);
5882 -- Case of accept statement which is in an accept alternative
5886 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5887 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5891 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5892 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5894 -- ??? Consider a single label for select statements
5896 if Present
(Handled_Statement_Sequence
(N
)) then
5898 Statements
(Handled_Statement_Sequence
(N
)));
5902 Statements
(Handled_Statement_Sequence
(N
)));
5906 -- Find first accept alternative of the selective accept. A
5907 -- valid selective accept must have at least one accept in it.
5909 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5911 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5915 -- If we are the first accept statement, then we have to create
5916 -- the Ann variable, as for the stand alone case, except that
5917 -- it is inserted before the selective accept. Similarly, a
5918 -- label for requeue expansion must be declared.
5920 if N
= Accept_Statement
(Alt
) then
5921 Ann
:= Make_Temporary
(Loc
, 'A');
5923 Make_Object_Declaration
(Loc
,
5924 Defining_Identifier
=> Ann
,
5925 Object_Definition
=>
5926 New_Reference_To
(RTE
(RE_Address
), Loc
));
5928 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5930 -- If we are not the first accept statement, then find the Ann
5931 -- variable allocated by the first accept and use it.
5935 Node
(Last_Elmt
(Accept_Address
5936 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5941 -- Merge here with Ann either created or referenced, and Adecl
5942 -- pointing to the corresponding declaration. Remaining processing
5943 -- is the same for the two cases.
5945 if Present
(Ann
) then
5946 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5947 Set_Debug_Info_Needed
(Ann
);
5950 -- Create renaming declarations for the entry formals. Each reference
5951 -- to a formal becomes a dereference of a component of the parameter
5952 -- block, whose address is held in Ann. These declarations are
5953 -- eventually inserted into the accept block, and analyzed there so
5954 -- that they have the proper scope for gdb and do not conflict with
5955 -- other declarations.
5957 if Present
(Parameter_Specifications
(N
))
5958 and then Present
(Handled_Statement_Sequence
(N
))
5965 Renamed_Formal
: Node_Id
;
5969 Formal
:= First_Formal
(Ent
);
5971 while Present
(Formal
) loop
5972 Comp
:= Entry_Component
(Formal
);
5973 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5975 Set_Etype
(New_F
, Etype
(Formal
));
5976 Set_Scope
(New_F
, Ent
);
5978 -- Now we set debug info needed on New_F even though it does
5979 -- not come from source, so that the debugger will get the
5980 -- right information for these generated names.
5982 Set_Debug_Info_Needed
(New_F
);
5984 if Ekind
(Formal
) = E_In_Parameter
then
5985 Set_Ekind
(New_F
, E_Constant
);
5987 Set_Ekind
(New_F
, E_Variable
);
5988 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5991 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5994 Make_Selected_Component
(Loc
,
5996 Unchecked_Convert_To
(
5997 Entry_Parameters_Type
(Ent
),
5998 New_Reference_To
(Ann
, Loc
)),
6000 New_Reference_To
(Comp
, Loc
));
6003 Build_Renamed_Formal_Declaration
6004 (New_F
, Formal
, Comp
, Renamed_Formal
);
6006 if No
(Declarations
(N
)) then
6007 Set_Declarations
(N
, New_List
);
6010 Append
(Decl
, Declarations
(N
));
6011 Set_Renamed_Object
(Formal
, New_F
);
6012 Next_Formal
(Formal
);
6019 end Expand_Accept_Declarations
;
6021 ---------------------------------------------
6022 -- Expand_Access_Protected_Subprogram_Type --
6023 ---------------------------------------------
6025 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
6026 Loc
: constant Source_Ptr
:= Sloc
(N
);
6028 T
: constant Entity_Id
:= Defining_Identifier
(N
);
6029 D_T
: constant Entity_Id
:= Designated_Type
(T
);
6030 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
6031 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
6032 P_List
: constant List_Id
:= Build_Protected_Spec
6033 (N
, RTE
(RE_Address
), D_T
, False);
6039 -- Create access to subprogram with full signature
6041 if Etype
(D_T
) /= Standard_Void_Type
then
6043 Make_Access_Function_Definition
(Loc
,
6044 Parameter_Specifications
=> P_List
,
6045 Result_Definition
=>
6046 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
6050 Make_Access_Procedure_Definition
(Loc
,
6051 Parameter_Specifications
=> P_List
);
6055 Make_Full_Type_Declaration
(Loc
,
6056 Defining_Identifier
=> D_T2
,
6057 Type_Definition
=> Def1
);
6059 Insert_After_And_Analyze
(N
, Decl1
);
6061 -- Associate the access to subprogram with its original access to
6062 -- protected subprogram type. Needed by the backend to know that this
6063 -- type corresponds with an access to protected subprogram type.
6065 Set_Original_Access_Type
(D_T2
, T
);
6067 -- Create Equivalent_Type, a record with two components for an access to
6068 -- object and an access to subprogram.
6071 Make_Component_Declaration
(Loc
,
6072 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6073 Component_Definition
=>
6074 Make_Component_Definition
(Loc
,
6075 Aliased_Present
=> False,
6076 Subtype_Indication
=>
6077 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
6079 Make_Component_Declaration
(Loc
,
6080 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
6081 Component_Definition
=>
6082 Make_Component_Definition
(Loc
,
6083 Aliased_Present
=> False,
6084 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
6087 Make_Full_Type_Declaration
(Loc
,
6088 Defining_Identifier
=> E_T
,
6090 Make_Record_Definition
(Loc
,
6092 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
6094 Insert_After_And_Analyze
(Decl1
, Decl2
);
6095 Set_Equivalent_Type
(T
, E_T
);
6096 end Expand_Access_Protected_Subprogram_Type
;
6098 --------------------------
6099 -- Expand_Entry_Barrier --
6100 --------------------------
6102 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
6103 Cond
: constant Node_Id
:=
6104 Condition
(Entry_Body_Formal_Part
(N
));
6105 Prot
: constant Entity_Id
:= Scope
(Ent
);
6106 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
6109 Body_Decl
: Node_Id
;
6112 if No_Run_Time_Mode
then
6113 Error_Msg_CRT
("entry barrier", N
);
6117 -- The body of the entry barrier must be analyzed in the context of the
6118 -- protected object, but its scope is external to it, just as any other
6119 -- unprotected version of a protected operation. The specification has
6120 -- been produced when the protected type declaration was elaborated. We
6121 -- build the body, insert it in the enclosing scope, but analyze it in
6122 -- the current context. A more uniform approach would be to treat the
6123 -- barrier just as a protected function, and discard the protected
6124 -- version of it because it is never called.
6126 if Full_Expander_Active
then
6127 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6128 Func
:= Barrier_Function
(Ent
);
6129 Set_Corresponding_Spec
(B_F
, Func
);
6131 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
6133 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
6134 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
6137 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
6139 Set_Discriminals
(Spec_Decl
);
6140 Set_Scope
(Func
, Scope
(Prot
));
6143 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6146 -- The Ravenscar profile restricts barriers to simple variables declared
6147 -- within the protected object. We also allow Boolean constants, since
6148 -- these appear in several published examples and are also allowed by
6149 -- the Aonix compiler.
6151 -- Note that after analysis variables in this context will be replaced
6152 -- by the corresponding prival, that is to say a renaming of a selected
6153 -- component of the form _Object.Var. If expansion is disabled, as
6154 -- within a generic, we check that the entity appears in the current
6157 if Is_Entity_Name
(Cond
) then
6159 -- A small optimization of useless renamings. If the scope of the
6160 -- entity of the condition is not the barrier function, then the
6161 -- condition does not reference any of the generated renamings
6162 -- within the function.
6164 if Full_Expander_Active
and then Scope
(Entity
(Cond
)) /= Func
then
6165 Set_Declarations
(B_F
, Empty_List
);
6168 if Entity
(Cond
) = Standard_False
6170 Entity
(Cond
) = Standard_True
6174 elsif not Expander_Active
6175 and then Scope
(Entity
(Cond
)) = Current_Scope
6179 -- Check for case of _object.all.field (note that the explicit
6180 -- dereference gets inserted by analyze/expand of _object.field)
6182 elsif Present
(Renamed_Object
(Entity
(Cond
)))
6184 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
6188 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
6194 -- It is not a boolean variable or literal, so check the restriction
6196 Check_Restriction
(Simple_Barriers
, Cond
);
6197 end Expand_Entry_Barrier
;
6199 ------------------------------
6200 -- Expand_N_Abort_Statement --
6201 ------------------------------
6203 -- Expand abort T1, T2, .. Tn; into:
6204 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6206 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6207 Loc
: constant Source_Ptr
:= Sloc
(N
);
6208 Tlist
: constant List_Id
:= Names
(N
);
6214 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6217 Tasknm
:= First
(Tlist
);
6219 while Present
(Tasknm
) loop
6222 -- A task interface class-wide type object is being aborted.
6223 -- Retrieve its _task_id by calling a dispatching routine.
6225 if Ada_Version
>= Ada_2005
6226 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6227 and then Is_Interface
(Etype
(Tasknm
))
6228 and then Is_Task_Interface
(Etype
(Tasknm
))
6230 Append_To
(Component_Associations
(Aggr
),
6231 Make_Component_Association
(Loc
,
6232 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6235 -- Task_Id (Tasknm._disp_get_task_id)
6237 Make_Unchecked_Type_Conversion
(Loc
,
6239 New_Reference_To
(RTE
(RO_ST_Task_Id
), Loc
),
6241 Make_Selected_Component
(Loc
,
6242 Prefix
=> New_Copy_Tree
(Tasknm
),
6244 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6247 Append_To
(Component_Associations
(Aggr
),
6248 Make_Component_Association
(Loc
,
6249 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6250 Expression
=> Concurrent_Ref
(Tasknm
)));
6257 Make_Procedure_Call_Statement
(Loc
,
6258 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
6259 Parameter_Associations
=> New_List
(
6260 Make_Qualified_Expression
(Loc
,
6261 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
6262 Expression
=> Aggr
))));
6265 end Expand_N_Abort_Statement
;
6267 -------------------------------
6268 -- Expand_N_Accept_Statement --
6269 -------------------------------
6271 -- This procedure handles expansion of accept statements that stand
6272 -- alone, i.e. they are not part of an accept alternative. The expansion
6273 -- of accept statement in accept alternatives is handled by the routines
6274 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6275 -- following description applies only to stand alone accept statements.
6277 -- If there is no handled statement sequence, or only null statements,
6278 -- then this is called a trivial accept, and the expansion is:
6280 -- Accept_Trivial (entry-index)
6282 -- If there is a handled statement sequence, then the expansion is:
6289 -- Accept_Call (entry-index, Ann);
6290 -- Renaming_Declarations for formals
6291 -- <statement sequence from N_Accept_Statement node>
6292 -- Complete_Rendezvous;
6297 -- <exception handler from N_Accept_Statement node>
6298 -- Complete_Rendezvous;
6300 -- <exception handler from N_Accept_Statement node>
6301 -- Complete_Rendezvous;
6306 -- when all others =>
6307 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6310 -- The first three declarations were already inserted ahead of the accept
6311 -- statement by the Expand_Accept_Declarations procedure, which was called
6312 -- directly from the semantics during analysis of the accept statement,
6313 -- before analyzing its contained statements.
6315 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6316 -- from possible expansion activity (the original source of course does
6317 -- not have any declarations associated with the accept statement, since
6318 -- an accept statement has no declarative part). In particular, if the
6319 -- expander is active, the first such declaration is the declaration of
6320 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6322 -- The two blocks are merged into a single block if the inner block has
6323 -- no exception handlers, but otherwise two blocks are required, since
6324 -- exceptions might be raised in the exception handlers of the inner
6325 -- block, and Exceptional_Complete_Rendezvous must be called.
6327 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6328 Loc
: constant Source_Ptr
:= Sloc
(N
);
6329 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6330 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6331 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6332 Eent
: constant Entity_Id
:= Entity
(Ename
);
6333 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6334 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6335 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6341 -- If the accept statement is not part of a list, then its parent must
6342 -- be an accept alternative, and, as described above, we do not do any
6343 -- expansion for such accept statements at this level.
6345 if not Is_List_Member
(N
) then
6346 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6349 -- Trivial accept case (no statement sequence, or null statements).
6350 -- If the accept statement has declarations, then just insert them
6351 -- before the procedure call.
6353 elsif Trivial_Accept_OK
6354 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6356 -- Remove declarations for renamings, because the parameter block
6357 -- will not be assigned.
6364 D
:= First
(Declarations
(N
));
6366 while Present
(D
) loop
6368 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6376 if Present
(Declarations
(N
)) then
6377 Insert_Actions
(N
, Declarations
(N
));
6381 Make_Procedure_Call_Statement
(Loc
,
6382 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
6383 Parameter_Associations
=> New_List
(
6384 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6388 -- Discard Entry_Address that was created for it, so it will not be
6389 -- emitted if this accept statement is in the statement part of a
6390 -- delay alternative.
6392 if Present
(Stats
) then
6393 Remove_Last_Elmt
(Acstack
);
6396 -- Case of statement sequence present
6399 -- Construct the block, using the declarations from the accept
6400 -- statement if any to initialize the declarations of the block.
6402 Blkent
:= Make_Temporary
(Loc
, 'A');
6403 Set_Ekind
(Blkent
, E_Block
);
6404 Set_Etype
(Blkent
, Standard_Void_Type
);
6405 Set_Scope
(Blkent
, Current_Scope
);
6408 Make_Block_Statement
(Loc
,
6409 Identifier
=> New_Reference_To
(Blkent
, Loc
),
6410 Declarations
=> Declarations
(N
),
6411 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6413 -- For the analysis of the generated declarations, the parent node
6414 -- must be properly set.
6416 Set_Parent
(Block
, Parent
(N
));
6418 -- Prepend call to Accept_Call to main statement sequence If the
6419 -- accept has exception handlers, the statement sequence is wrapped
6420 -- in a block. Insert call and renaming declarations in the
6421 -- declarations of the block, so they are elaborated before the
6425 Make_Procedure_Call_Statement
(Loc
,
6426 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
6427 Parameter_Associations
=> New_List
(
6428 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6429 New_Reference_To
(Ann
, Loc
)));
6431 if Parent
(Stats
) = N
then
6432 Prepend
(Call
, Statements
(Stats
));
6434 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6439 Push_Scope
(Blkent
);
6447 D
:= First
(Declarations
(N
));
6448 while Present
(D
) loop
6451 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6453 -- The renaming declarations for the formals were created
6454 -- during analysis of the accept statement, and attached to
6455 -- the list of declarations. Place them now in the context
6456 -- of the accept block or subprogram.
6459 Typ
:= Entity
(Subtype_Mark
(D
));
6460 Insert_After
(Call
, D
);
6463 -- If the formal is class_wide, it does not have an actual
6464 -- subtype. The analysis of the renaming declaration creates
6465 -- one, but we need to retain the class-wide nature of the
6468 if Is_Class_Wide_Type
(Typ
) then
6469 Set_Etype
(Defining_Identifier
(D
), Typ
);
6480 -- Replace the accept statement by the new block
6485 -- Last step is to unstack the Accept_Address value
6487 Remove_Last_Elmt
(Acstack
);
6489 end Expand_N_Accept_Statement
;
6491 ----------------------------------
6492 -- Expand_N_Asynchronous_Select --
6493 ----------------------------------
6495 -- This procedure assumes that the trigger statement is an entry call or
6496 -- a dispatching procedure call. A delay alternative should already have
6497 -- been expanded into an entry call to the appropriate delay object Wait
6500 -- If the trigger is a task entry call, the select is implemented with
6501 -- a Task_Entry_Call:
6506 -- P : parms := (parm, parm, parm);
6508 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6510 -- procedure _clean is
6513 -- Cancel_Task_Entry_Call (C);
6520 -- (<acceptor-task>, -- Acceptor
6521 -- <entry-index>, -- E
6522 -- P'Address, -- Uninterpreted_Data
6523 -- Asynchronous_Call, -- Mode
6524 -- B); -- Rendezvous_Successful
6531 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6534 -- when Abort_Signal => Abort_Undefer;
6541 -- <triggered-statements>
6545 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6546 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6550 -- P : parms := (parm, parm, parm);
6552 -- Call_Simple (acceptor-task, entry-index, P'Address);
6558 -- so the task at hand is to convert the latter expansion into the former
6560 -- If the trigger is a protected entry call, the select is implemented
6561 -- with Protected_Entry_Call:
6564 -- P : E1_Params := (param, param, param);
6565 -- Bnn : Communications_Block;
6570 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6572 -- procedure _clean is
6575 -- if Enqueued (Bnn) then
6576 -- Cancel_Protected_Entry_Call (Bnn);
6583 -- Protected_Entry_Call
6584 -- (po._object'Access, -- Object
6585 -- <entry index>, -- E
6586 -- P'Address, -- Uninterpreted_Data
6587 -- Asynchronous_Call, -- Mode
6590 -- if Enqueued (Bnn) then
6594 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6597 -- when Abort_Signal => Abort_Undefer;
6600 -- if not Cancelled (Bnn) then
6601 -- <triggered-statements>
6605 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6609 -- P : E1_Params := (param, param, param);
6610 -- Bnn : Communications_Block;
6613 -- Protected_Entry_Call
6614 -- (po._object'Access, -- Object
6615 -- <entry index>, -- E
6616 -- P'Address, -- Uninterpreted_Data
6617 -- Simple_Call, -- Mode
6624 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6628 -- B : Boolean := False;
6629 -- Bnn : Communication_Block;
6630 -- C : Ada.Tags.Prim_Op_Kind;
6631 -- D : System.Storage_Elements.Dummy_Communication_Block;
6632 -- K : Ada.Tags.Tagged_Kind :=
6633 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6634 -- P : Parameters := (Param1 .. ParamN);
6639 -- if K = Ada.Tags.TK_Limited_Tagged
6640 -- or else K = Ada.Tags.TK_Tagged
6642 -- <dispatching-call>;
6643 -- <triggering-statements>;
6647 -- Ada.Tags.Get_Offset_Index
6648 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6650 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6652 -- if C = POK_Protected_Entry then
6654 -- procedure _clean is
6656 -- if Enqueued (Bnn) then
6657 -- Cancel_Protected_Entry_Call (Bnn);
6663 -- _Disp_Asynchronous_Select
6664 -- (<object>, S, P'Address, D, B);
6665 -- Bnn := Communication_Block (D);
6667 -- Param1 := P.Param1;
6669 -- ParamN := P.ParamN;
6671 -- if Enqueued (Bnn) then
6672 -- <abortable-statements>
6675 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6678 -- when Abort_Signal => Abort_Undefer;
6681 -- if not Cancelled (Bnn) then
6682 -- <triggering-statements>
6685 -- elsif C = POK_Task_Entry then
6687 -- procedure _clean is
6689 -- Cancel_Task_Entry_Call (U);
6695 -- _Disp_Asynchronous_Select
6696 -- (<object>, S, P'Address, D, B);
6697 -- Bnn := Communication_Bloc (D);
6699 -- Param1 := P.Param1;
6701 -- ParamN := P.ParamN;
6706 -- <abortable-statements>
6708 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6711 -- when Abort_Signal => Abort_Undefer;
6715 -- <triggering-statements>
6720 -- <dispatching-call>;
6721 -- <triggering-statements>
6726 -- The job is to convert this to the asynchronous form
6728 -- If the trigger is a delay statement, it will have been expanded into a
6729 -- call to one of the GNARL delay procedures. This routine will convert
6730 -- this into a protected entry call on a delay object and then continue
6731 -- processing as for a protected entry call trigger. This requires
6732 -- declaring a Delay_Block object and adding a pointer to this object to
6733 -- the parameter list of the delay procedure to form the parameter list of
6734 -- the entry call. This object is used by the runtime to queue the delay
6737 -- For a description of the use of P and the assignments after the call,
6738 -- see Expand_N_Entry_Call_Statement.
6740 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6741 Loc
: constant Source_Ptr
:= Sloc
(N
);
6742 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6743 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6745 Abort_Block_Ent
: Entity_Id
;
6746 Abortable_Block
: Node_Id
;
6749 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6750 Blk_Typ
: Entity_Id
;
6752 Call_Ent
: Entity_Id
;
6753 Cancel_Param
: Entity_Id
;
6754 Cleanup_Block
: Node_Id
;
6755 Cleanup_Block_Ent
: Entity_Id
;
6756 Cleanup_Stmts
: List_Id
;
6757 Conc_Typ_Stmts
: List_Id
;
6759 Dblock_Ent
: Entity_Id
;
6764 Enqueue_Call
: Node_Id
;
6767 Handler_Stmt
: Node_Id
;
6769 Lim_Typ_Stmts
: List_Id
;
6775 ProtE_Stmts
: List_Id
;
6776 ProtP_Stmts
: List_Id
;
6779 TaskE_Stmts
: List_Id
;
6782 B
: Entity_Id
; -- Call status flag
6783 Bnn
: Entity_Id
; -- Communication block
6784 C
: Entity_Id
; -- Call kind
6785 K
: Entity_Id
; -- Tagged kind
6786 P
: Entity_Id
; -- Parameter block
6787 S
: Entity_Id
; -- Primitive operation slot
6788 T
: Entity_Id
; -- Additional status flag
6790 procedure Rewrite_Abortable_Part
;
6791 -- If the trigger is a dispatching call, the expansion inserts multiple
6792 -- copies of the abortable part. This is both inefficient, and may lead
6793 -- to duplicate definitions that the back-end will reject, when the
6794 -- abortable part includes loops. This procedure rewrites the abortable
6795 -- part into a call to a generated procedure.
6797 ----------------------------
6798 -- Rewrite_Abortable_Part --
6799 ----------------------------
6801 procedure Rewrite_Abortable_Part
is
6802 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6807 Make_Subprogram_Body
(Loc
,
6809 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6810 Declarations
=> New_List
,
6811 Handled_Statement_Sequence
=>
6812 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6813 Insert_Before
(N
, Decl
);
6816 -- Rewrite abortable part into a call to this procedure.
6820 Make_Procedure_Call_Statement
(Loc
,
6821 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6822 end Rewrite_Abortable_Part
;
6825 Process_Statements_For_Controlled_Objects
(Trig
);
6826 Process_Statements_For_Controlled_Objects
(Abrt
);
6828 Ecall
:= Triggering_Statement
(Trig
);
6830 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6832 -- Retrieve Astats and Tstats now because the finalization machinery may
6833 -- wrap them in blocks.
6835 Astats
:= Statements
(Abrt
);
6836 Tstats
:= Statements
(Trig
);
6838 -- The arguments in the call may require dynamic allocation, and the
6839 -- call statement may have been transformed into a block. The block
6840 -- may contain additional declarations for internal entities, and the
6841 -- original call is found by sequential search.
6843 if Nkind
(Ecall
) = N_Block_Statement
then
6844 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6845 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6846 N_Entry_Call_Statement
)
6852 -- This is either a dispatching call or a delay statement used as a
6853 -- trigger which was expanded into a procedure call.
6855 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6856 if Ada_Version
>= Ada_2005
6858 (No
(Original_Node
(Ecall
))
6859 or else not Nkind_In
(Original_Node
(Ecall
),
6860 N_Delay_Relative_Statement
,
6861 N_Delay_Until_Statement
))
6863 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6865 Rewrite_Abortable_Part
;
6869 -- Call status flag processing, generate:
6870 -- B : Boolean := False;
6872 B
:= Build_B
(Loc
, Decls
);
6874 -- Communication block processing, generate:
6875 -- Bnn : Communication_Block;
6877 Bnn
:= Make_Temporary
(Loc
, 'B');
6879 Make_Object_Declaration
(Loc
,
6880 Defining_Identifier
=> Bnn
,
6881 Object_Definition
=>
6882 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
6884 -- Call kind processing, generate:
6885 -- C : Ada.Tags.Prim_Op_Kind;
6887 C
:= Build_C
(Loc
, Decls
);
6889 -- Tagged kind processing, generate:
6890 -- K : Ada.Tags.Tagged_Kind :=
6891 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6893 -- Dummy communication block, generate:
6894 -- D : Dummy_Communication_Block;
6897 Make_Object_Declaration
(Loc
,
6898 Defining_Identifier
=>
6899 Make_Defining_Identifier
(Loc
, Name_uD
),
6900 Object_Definition
=>
6902 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
6904 K
:= Build_K
(Loc
, Decls
, Obj
);
6906 -- Parameter block processing
6908 Blk_Typ
:= Build_Parameter_Block
6909 (Loc
, Actuals
, Formals
, Decls
);
6910 P
:= Parameter_Block_Pack
6911 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6913 -- Dispatch table slot processing, generate:
6916 S
:= Build_S
(Loc
, Decls
);
6918 -- Additional status flag processing, generate:
6921 T
:= Make_Temporary
(Loc
, 'T');
6923 Make_Object_Declaration
(Loc
,
6924 Defining_Identifier
=> T
,
6925 Object_Definition
=>
6926 New_Reference_To
(Standard_Boolean
, Loc
)));
6928 ------------------------------
6929 -- Protected entry handling --
6930 ------------------------------
6933 -- Param1 := P.Param1;
6935 -- ParamN := P.ParamN;
6937 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6940 -- Bnn := Communication_Block (D);
6942 Prepend_To
(Cleanup_Stmts
,
6943 Make_Assignment_Statement
(Loc
,
6944 Name
=> New_Reference_To
(Bnn
, Loc
),
6946 Make_Unchecked_Type_Conversion
(Loc
,
6948 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
6949 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
6952 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6954 Prepend_To
(Cleanup_Stmts
,
6955 Make_Procedure_Call_Statement
(Loc
,
6959 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
6961 Parameter_Associations
=>
6963 New_Copy_Tree
(Obj
), -- <object>
6964 New_Reference_To
(S
, Loc
), -- S
6965 Make_Attribute_Reference
(Loc
, -- P'Address
6966 Prefix
=> New_Reference_To
(P
, Loc
),
6967 Attribute_Name
=> Name_Address
),
6968 Make_Identifier
(Loc
, Name_uD
), -- D
6969 New_Reference_To
(B
, Loc
)))); -- B
6972 -- if Enqueued (Bnn) then
6973 -- <abortable-statements>
6976 Append_To
(Cleanup_Stmts
,
6977 Make_Implicit_If_Statement
(N
,
6979 Make_Function_Call
(Loc
,
6981 New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
6982 Parameter_Associations
=>
6983 New_List
(New_Reference_To
(Bnn
, Loc
))),
6986 New_Copy_List_Tree
(Astats
)));
6988 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6989 -- will then generate a _clean for the communication block Bnn.
6993 -- procedure _clean is
6995 -- if Enqueued (Bnn) then
6996 -- Cancel_Protected_Entry_Call (Bnn);
7005 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7007 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7009 -- Wrap the cleanup block in an exception handling block
7015 -- when Abort_Signal => Abort_Undefer;
7018 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7021 Make_Implicit_Label_Declaration
(Loc
,
7022 Defining_Identifier
=> Abort_Block_Ent
),
7025 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7028 -- if not Cancelled (Bnn) then
7029 -- <triggering-statements>
7032 Append_To
(ProtE_Stmts
,
7033 Make_Implicit_If_Statement
(N
,
7037 Make_Function_Call
(Loc
,
7039 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
7040 Parameter_Associations
=>
7041 New_List
(New_Reference_To
(Bnn
, Loc
)))),
7044 New_Copy_List_Tree
(Tstats
)));
7046 -------------------------
7047 -- Task entry handling --
7048 -------------------------
7051 -- Param1 := P.Param1;
7053 -- ParamN := P.ParamN;
7055 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7058 -- Bnn := Communication_Block (D);
7060 Append_To
(TaskE_Stmts
,
7061 Make_Assignment_Statement
(Loc
,
7063 New_Reference_To
(Bnn
, Loc
),
7065 Make_Unchecked_Type_Conversion
(Loc
,
7067 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
7068 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7071 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7073 Prepend_To
(TaskE_Stmts
,
7074 Make_Procedure_Call_Statement
(Loc
,
7077 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7078 Name_uDisp_Asynchronous_Select
),
7081 Parameter_Associations
=>
7083 New_Copy_Tree
(Obj
), -- <object>
7084 New_Reference_To
(S
, Loc
), -- S
7085 Make_Attribute_Reference
(Loc
, -- P'Address
7086 Prefix
=> New_Reference_To
(P
, Loc
),
7087 Attribute_Name
=> Name_Address
),
7088 Make_Identifier
(Loc
, Name_uD
), -- D
7089 New_Reference_To
(B
, Loc
)))); -- B
7094 Prepend_To
(TaskE_Stmts
,
7095 Make_Procedure_Call_Statement
(Loc
,
7096 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7097 Parameter_Associations
=> No_List
));
7101 -- <abortable-statements>
7103 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7105 Prepend_To
(Cleanup_Stmts
,
7106 Make_Procedure_Call_Statement
(Loc
,
7107 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7108 Parameter_Associations
=> No_List
));
7110 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7111 -- will generate a _clean for the additional status flag.
7115 -- procedure _clean is
7117 -- Cancel_Task_Entry_Call (U);
7125 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7127 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7129 -- Wrap the cleanup block in an exception handling block
7135 -- when Abort_Signal => Abort_Undefer;
7138 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7140 Append_To
(TaskE_Stmts
,
7141 Make_Implicit_Label_Declaration
(Loc
,
7142 Defining_Identifier
=> Abort_Block_Ent
));
7144 Append_To
(TaskE_Stmts
,
7146 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7150 -- <triggering-statements>
7153 Append_To
(TaskE_Stmts
,
7154 Make_Implicit_If_Statement
(N
,
7156 Make_Op_Not
(Loc
, Right_Opnd
=> New_Reference_To
(T
, Loc
)),
7159 New_Copy_List_Tree
(Tstats
)));
7161 ----------------------------------
7162 -- Protected procedure handling --
7163 ----------------------------------
7166 -- <dispatching-call>;
7167 -- <triggering-statements>
7169 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7170 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7173 -- S := Ada.Tags.Get_Offset_Index
7174 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7177 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7180 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7182 Append_To
(Conc_Typ_Stmts
,
7183 Make_Procedure_Call_Statement
(Loc
,
7186 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7187 Name_uDisp_Get_Prim_Op_Kind
),
7189 Parameter_Associations
=>
7191 New_Copy_Tree
(Obj
),
7192 New_Reference_To
(S
, Loc
),
7193 New_Reference_To
(C
, Loc
))));
7196 -- if C = POK_Procedure_Entry then
7198 -- elsif C = POK_Task_Entry then
7204 Append_To
(Conc_Typ_Stmts
,
7205 Make_Implicit_If_Statement
(N
,
7209 New_Reference_To
(C
, Loc
),
7211 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7218 Make_Elsif_Part
(Loc
,
7222 New_Reference_To
(C
, Loc
),
7224 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
)),
7233 -- <dispatching-call>;
7234 -- <triggering-statements>
7236 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7237 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7240 -- if K = Ada.Tags.TK_Limited_Tagged
7241 -- or else K = Ada.Tags.TK_Tagged
7249 Make_Implicit_If_Statement
(N
,
7250 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7251 Then_Statements
=> Lim_Typ_Stmts
,
7252 Else_Statements
=> Conc_Typ_Stmts
));
7255 Make_Block_Statement
(Loc
,
7258 Handled_Statement_Sequence
=>
7259 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7264 -- Delay triggering statement processing
7267 -- Add a Delay_Block object to the parameter list of the delay
7268 -- procedure to form the parameter list of the Wait entry call.
7270 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7272 Pdef
:= Entity
(Name
(Ecall
));
7274 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7276 New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
7278 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7280 New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
7282 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7283 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
7286 Append_To
(Parameter_Associations
(Ecall
),
7287 Make_Attribute_Reference
(Loc
,
7288 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7289 Attribute_Name
=> Name_Unchecked_Access
));
7291 -- Create the inner block to protect the abortable part
7293 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7296 Make_Procedure_Call_Statement
(Loc
,
7297 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7300 Make_Block_Statement
(Loc
,
7301 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7302 Handled_Statement_Sequence
=>
7303 Make_Handled_Sequence_Of_Statements
(Loc
,
7304 Statements
=> Astats
),
7305 Has_Created_Identifier
=> True,
7306 Is_Asynchronous_Call_Block
=> True);
7308 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7311 Make_Implicit_If_Statement
(N
,
7313 Make_Function_Call
(Loc
,
7314 Name
=> Enqueue_Call
,
7315 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7317 New_List
(Make_Block_Statement
(Loc
,
7318 Handled_Statement_Sequence
=>
7319 Make_Handled_Sequence_Of_Statements
(Loc
,
7320 Statements
=> New_List
(
7321 Make_Implicit_Label_Declaration
(Loc
,
7322 Defining_Identifier
=> Blk_Ent
,
7323 Label_Construct
=> Abortable_Block
),
7325 Exception_Handlers
=> Hdle
)))));
7327 Stmts
:= New_List
(Ecall
);
7329 -- Construct statement sequence for new block
7332 Make_Implicit_If_Statement
(N
,
7334 Make_Function_Call
(Loc
,
7335 Name
=> New_Reference_To
(
7336 RTE
(RE_Timed_Out
), Loc
),
7337 Parameter_Associations
=> New_List
(
7338 Make_Attribute_Reference
(Loc
,
7339 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7340 Attribute_Name
=> Name_Unchecked_Access
))),
7341 Then_Statements
=> Tstats
));
7343 -- The result is the new block
7345 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7348 Make_Block_Statement
(Loc
,
7349 Declarations
=> New_List
(
7350 Make_Object_Declaration
(Loc
,
7351 Defining_Identifier
=> Dblock_Ent
,
7352 Aliased_Present
=> True,
7353 Object_Definition
=>
7354 New_Reference_To
(RTE
(RE_Delay_Block
), Loc
))),
7356 Handled_Statement_Sequence
=>
7357 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7367 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7368 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7370 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7371 Decls
:= Declarations
(Ecall
);
7373 if Is_Protected_Type
(Etype
(Concval
)) then
7375 -- Get the declarations of the block expanded from the entry call
7377 Decl
:= First
(Decls
);
7378 while Present
(Decl
)
7379 and then (Nkind
(Decl
) /= N_Object_Declaration
7380 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7381 RE_Communication_Block
))
7386 pragma Assert
(Present
(Decl
));
7387 Cancel_Param
:= Defining_Identifier
(Decl
);
7389 -- Change the mode of the Protected_Entry_Call call
7391 -- Protected_Entry_Call (
7392 -- Object => po._object'Access,
7393 -- E => <entry index>;
7394 -- Uninterpreted_Data => P'Address;
7395 -- Mode => Asynchronous_Call;
7398 -- Skip assignments to temporaries created for in-out parameters
7400 -- This makes unwarranted assumptions about the shape of the expanded
7401 -- tree for the call, and should be cleaned up ???
7403 Stmt
:= First
(Stmts
);
7404 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7410 Param
:= First
(Parameter_Associations
(Call
));
7411 while Present
(Param
)
7412 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7417 pragma Assert
(Present
(Param
));
7418 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7421 -- Append an if statement to execute the abortable part
7424 -- if Enqueued (Bnn) then
7427 Make_Implicit_If_Statement
(N
,
7429 Make_Function_Call
(Loc
,
7430 Name
=> New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
7431 Parameter_Associations
=> New_List
(
7432 New_Reference_To
(Cancel_Param
, Loc
))),
7433 Then_Statements
=> Astats
));
7436 Make_Block_Statement
(Loc
,
7437 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7438 Handled_Statement_Sequence
=>
7439 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7440 Has_Created_Identifier
=> True,
7441 Is_Asynchronous_Call_Block
=> True);
7443 -- For the VM call Update_Exception instead of Abort_Undefer.
7444 -- See 4jexcept.ads for an explanation.
7446 if VM_Target
= No_VM
then
7447 if Exception_Mechanism
= Back_End_Exceptions
then
7449 -- Aborts are not deferred at beginning of exception handlers
7452 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7455 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7456 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7457 Parameter_Associations
=> No_List
);
7460 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7461 Name
=> New_Reference_To
(RTE
(RE_Update_Exception
), Loc
),
7462 Parameter_Associations
=> New_List
(
7463 Make_Function_Call
(Loc
,
7464 Name
=> New_Occurrence_Of
7465 (RTE
(RE_Current_Target_Exception
), Loc
))));
7469 Make_Block_Statement
(Loc
,
7470 Handled_Statement_Sequence
=>
7471 Make_Handled_Sequence_Of_Statements
(Loc
,
7472 Statements
=> New_List
(
7473 Make_Implicit_Label_Declaration
(Loc
,
7474 Defining_Identifier
=> Blk_Ent
,
7475 Label_Construct
=> Abortable_Block
),
7480 Exception_Handlers
=> New_List
(
7481 Make_Implicit_Exception_Handler
(Loc
,
7483 -- when Abort_Signal =>
7484 -- Abort_Undefer.all;
7486 Exception_Choices
=>
7487 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
7488 Statements
=> New_List
(Handler_Stmt
))))),
7490 -- if not Cancelled (Bnn) then
7491 -- triggered statements
7494 Make_Implicit_If_Statement
(N
,
7495 Condition
=> Make_Op_Not
(Loc
,
7497 Make_Function_Call
(Loc
,
7498 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7499 Parameter_Associations
=> New_List
(
7500 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7501 Then_Statements
=> Tstats
));
7503 -- Asynchronous task entry call
7510 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7512 -- Insert declaration of B in declarations of existing block
7515 Make_Object_Declaration
(Loc
,
7516 Defining_Identifier
=> B
,
7517 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7519 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7521 -- Insert declaration of C in declarations of existing block
7524 Make_Object_Declaration
(Loc
,
7525 Defining_Identifier
=> Cancel_Param
,
7526 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7528 -- Remove and save the call to Call_Simple
7530 Stmt
:= First
(Stmts
);
7532 -- Skip assignments to temporaries created for in-out parameters.
7533 -- This makes unwarranted assumptions about the shape of the expanded
7534 -- tree for the call, and should be cleaned up ???
7536 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7542 -- Create the inner block to protect the abortable part
7544 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7547 Make_Procedure_Call_Statement
(Loc
,
7548 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7551 Make_Block_Statement
(Loc
,
7552 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7553 Handled_Statement_Sequence
=>
7554 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7555 Has_Created_Identifier
=> True,
7556 Is_Asynchronous_Call_Block
=> True);
7559 Make_Block_Statement
(Loc
,
7560 Handled_Statement_Sequence
=>
7561 Make_Handled_Sequence_Of_Statements
(Loc
,
7562 Statements
=> New_List
(
7563 Make_Implicit_Label_Declaration
(Loc
,
7564 Defining_Identifier
=> Blk_Ent
,
7565 Label_Construct
=> Abortable_Block
),
7567 Exception_Handlers
=> Hdle
)));
7569 -- Create new call statement
7571 Params
:= Parameter_Associations
(Call
);
7574 New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7575 Append_To
(Params
, New_Reference_To
(B
, Loc
));
7578 Make_Procedure_Call_Statement
(Loc
,
7579 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7580 Parameter_Associations
=> Params
));
7582 -- Construct statement sequence for new block
7585 Make_Implicit_If_Statement
(N
,
7587 Make_Op_Not
(Loc
, New_Reference_To
(Cancel_Param
, Loc
)),
7588 Then_Statements
=> Tstats
));
7590 -- Protected the call against abort
7593 Make_Procedure_Call_Statement
(Loc
,
7594 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7595 Parameter_Associations
=> Empty_List
));
7598 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7600 -- The result is the new block
7603 Make_Block_Statement
(Loc
,
7604 Declarations
=> Decls
,
7605 Handled_Statement_Sequence
=>
7606 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7609 end Expand_N_Asynchronous_Select
;
7611 -------------------------------------
7612 -- Expand_N_Conditional_Entry_Call --
7613 -------------------------------------
7615 -- The conditional task entry call is converted to a call to
7620 -- P : parms := (parm, parm, parm);
7624 -- (<acceptor-task>, -- Acceptor
7625 -- <entry-index>, -- E
7626 -- P'Address, -- Uninterpreted_Data
7627 -- Conditional_Call, -- Mode
7628 -- B); -- Rendezvous_Successful
7633 -- normal-statements
7639 -- For a description of the use of P and the assignments after the call,
7640 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7641 -- conditional entry call has already been expanded (by the Expand_N_Entry
7642 -- _Call_Statement procedure) as follows:
7645 -- P : parms := (parm, parm, parm);
7647 -- ... info for in-out parameters
7648 -- Call_Simple (acceptor-task, entry-index, P'Address);
7654 -- so the task at hand is to convert the latter expansion into the former
7656 -- The conditional protected entry call is converted to a call to
7657 -- Protected_Entry_Call:
7660 -- P : parms := (parm, parm, parm);
7661 -- Bnn : Communications_Block;
7664 -- Protected_Entry_Call
7665 -- (po._object'Access, -- Object
7666 -- <entry index>, -- E
7667 -- P'Address, -- Uninterpreted_Data
7668 -- Conditional_Call, -- Mode
7673 -- if Cancelled (Bnn) then
7676 -- normal-statements
7680 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7684 -- B : Boolean := False;
7685 -- C : Ada.Tags.Prim_Op_Kind;
7686 -- K : Ada.Tags.Tagged_Kind :=
7687 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7688 -- P : Parameters := (Param1 .. ParamN);
7692 -- if K = Ada.Tags.TK_Limited_Tagged
7693 -- or else K = Ada.Tags.TK_Tagged
7695 -- <dispatching-call>;
7696 -- <triggering-statements>
7700 -- Ada.Tags.Get_Offset_Index
7701 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7703 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7705 -- if C = POK_Protected_Entry
7706 -- or else C = POK_Task_Entry
7708 -- Param1 := P.Param1;
7710 -- ParamN := P.ParamN;
7714 -- if C = POK_Procedure
7715 -- or else C = POK_Protected_Procedure
7716 -- or else C = POK_Task_Procedure
7718 -- <dispatching-call>;
7721 -- <triggering-statements>
7723 -- <else-statements>
7728 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7729 Loc
: constant Source_Ptr
:= Sloc
(N
);
7730 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7731 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7734 Blk_Typ
: Entity_Id
;
7736 Call_Ent
: Entity_Id
;
7737 Conc_Typ_Stmts
: List_Id
;
7741 Lim_Typ_Stmts
: List_Id
;
7748 Transient_Blk
: Node_Id
;
7751 B
: Entity_Id
; -- Call status flag
7752 C
: Entity_Id
; -- Call kind
7753 K
: Entity_Id
; -- Tagged kind
7754 P
: Entity_Id
; -- Parameter block
7755 S
: Entity_Id
; -- Primitive operation slot
7758 Process_Statements_For_Controlled_Objects
(N
);
7760 if Ada_Version
>= Ada_2005
7761 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7763 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7768 -- Call status flag processing, generate:
7769 -- B : Boolean := False;
7771 B
:= Build_B
(Loc
, Decls
);
7773 -- Call kind processing, generate:
7774 -- C : Ada.Tags.Prim_Op_Kind;
7776 C
:= Build_C
(Loc
, Decls
);
7778 -- Tagged kind processing, generate:
7779 -- K : Ada.Tags.Tagged_Kind :=
7780 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7782 K
:= Build_K
(Loc
, Decls
, Obj
);
7784 -- Parameter block processing
7786 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7787 P
:= Parameter_Block_Pack
7788 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7790 -- Dispatch table slot processing, generate:
7793 S
:= Build_S
(Loc
, Decls
);
7796 -- S := Ada.Tags.Get_Offset_Index
7797 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7800 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7803 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7805 Append_To
(Conc_Typ_Stmts
,
7806 Make_Procedure_Call_Statement
(Loc
,
7809 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7810 Name_uDisp_Conditional_Select
),
7812 Parameter_Associations
=>
7814 New_Copy_Tree
(Obj
), -- <object>
7815 New_Reference_To
(S
, Loc
), -- S
7816 Make_Attribute_Reference
(Loc
, -- P'Address
7817 Prefix
=> New_Reference_To
(P
, Loc
),
7818 Attribute_Name
=> Name_Address
),
7819 New_Reference_To
(C
, Loc
), -- C
7820 New_Reference_To
(B
, Loc
)))); -- B
7823 -- if C = POK_Protected_Entry
7824 -- or else C = POK_Task_Entry
7826 -- Param1 := P.Param1;
7828 -- ParamN := P.ParamN;
7831 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7833 -- Generate the if statement only when the packed parameters need
7834 -- explicit assignments to their corresponding actuals.
7836 if Present
(Unpack
) then
7837 Append_To
(Conc_Typ_Stmts
,
7838 Make_Implicit_If_Statement
(N
,
7844 New_Reference_To
(C
, Loc
),
7846 New_Reference_To
(RTE
(
7847 RE_POK_Protected_Entry
), Loc
)),
7852 New_Reference_To
(C
, Loc
),
7854 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
7856 Then_Statements
=> Unpack
));
7861 -- if C = POK_Procedure
7862 -- or else C = POK_Protected_Procedure
7863 -- or else C = POK_Task_Procedure
7865 -- <dispatching-call>
7867 -- <normal-statements>
7869 -- <else-statements>
7872 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7874 Prepend_To
(N_Stats
,
7875 Make_Implicit_If_Statement
(N
,
7881 New_Reference_To
(C
, Loc
),
7883 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
7890 New_Reference_To
(C
, Loc
),
7892 New_Reference_To
(RTE
(
7893 RE_POK_Protected_Procedure
), Loc
)),
7898 New_Reference_To
(C
, Loc
),
7900 New_Reference_To
(RTE
(
7901 RE_POK_Task_Procedure
), Loc
)))),
7906 Append_To
(Conc_Typ_Stmts
,
7907 Make_Implicit_If_Statement
(N
,
7908 Condition
=> New_Reference_To
(B
, Loc
),
7909 Then_Statements
=> N_Stats
,
7910 Else_Statements
=> Else_Statements
(N
)));
7913 -- <dispatching-call>;
7914 -- <triggering-statements>
7916 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
7917 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
7920 -- if K = Ada.Tags.TK_Limited_Tagged
7921 -- or else K = Ada.Tags.TK_Tagged
7929 Make_Implicit_If_Statement
(N
,
7930 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7931 Then_Statements
=> Lim_Typ_Stmts
,
7932 Else_Statements
=> Conc_Typ_Stmts
));
7935 Make_Block_Statement
(Loc
,
7938 Handled_Statement_Sequence
=>
7939 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7941 -- As described above, the entry alternative is transformed into a
7942 -- block that contains the gnulli call, and possibly assignment
7943 -- statements for in-out parameters. The gnulli call may itself be
7944 -- rewritten into a transient block if some unconstrained parameters
7945 -- require it. We need to retrieve the call to complete its parameter
7950 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
7952 if Present
(Transient_Blk
)
7953 and then Nkind
(Transient_Blk
) = N_Block_Statement
7955 Blk
:= Transient_Blk
;
7958 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
7959 Stmt
:= First
(Stmts
);
7960 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7965 Params
:= Parameter_Associations
(Call
);
7967 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
7969 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7971 Param
:= First
(Params
);
7972 while Present
(Param
)
7973 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7978 pragma Assert
(Present
(Param
));
7979 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7983 -- Find the Communication_Block parameter for the call to the
7984 -- Cancelled function.
7986 Decl
:= First
(Declarations
(Blk
));
7987 while Present
(Decl
)
7988 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7989 RE_Communication_Block
)
7994 -- Add an if statement to execute the else part if the call
7995 -- does not succeed (as indicated by the Cancelled predicate).
7998 Make_Implicit_If_Statement
(N
,
7999 Condition
=> Make_Function_Call
(Loc
,
8000 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
8001 Parameter_Associations
=> New_List
(
8002 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
8003 Then_Statements
=> Else_Statements
(N
),
8004 Else_Statements
=> Statements
(Alt
)));
8007 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8009 -- Insert declaration of B in declarations of existing block
8011 if No
(Declarations
(Blk
)) then
8012 Set_Declarations
(Blk
, New_List
);
8015 Prepend_To
(Declarations
(Blk
),
8016 Make_Object_Declaration
(Loc
,
8017 Defining_Identifier
=> B
,
8018 Object_Definition
=>
8019 New_Reference_To
(Standard_Boolean
, Loc
)));
8021 -- Create new call statement
8024 New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
8025 Append_To
(Params
, New_Reference_To
(B
, Loc
));
8028 Make_Procedure_Call_Statement
(Loc
,
8029 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
8030 Parameter_Associations
=> Params
));
8032 -- Construct statement sequence for new block
8035 Make_Implicit_If_Statement
(N
,
8036 Condition
=> New_Reference_To
(B
, Loc
),
8037 Then_Statements
=> Statements
(Alt
),
8038 Else_Statements
=> Else_Statements
(N
)));
8041 -- The result is the new block
8044 Make_Block_Statement
(Loc
,
8045 Declarations
=> Declarations
(Blk
),
8046 Handled_Statement_Sequence
=>
8047 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8051 end Expand_N_Conditional_Entry_Call
;
8053 ---------------------------------------
8054 -- Expand_N_Delay_Relative_Statement --
8055 ---------------------------------------
8057 -- Delay statement is implemented as a procedure call to Delay_For
8058 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8059 -- simple delays imposed by the use of Protected Objects.
8061 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8062 Loc
: constant Source_Ptr
:= Sloc
(N
);
8065 Make_Procedure_Call_Statement
(Loc
,
8066 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
8067 Parameter_Associations
=> New_List
(Expression
(N
))));
8069 end Expand_N_Delay_Relative_Statement
;
8071 ------------------------------------
8072 -- Expand_N_Delay_Until_Statement --
8073 ------------------------------------
8075 -- Delay Until statement is implemented as a procedure call to
8076 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8078 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8079 Loc
: constant Source_Ptr
:= Sloc
(N
);
8083 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8084 Typ
:= RTE
(RO_CA_Delay_Until
);
8086 Typ
:= RTE
(RO_RT_Delay_Until
);
8090 Make_Procedure_Call_Statement
(Loc
,
8091 Name
=> New_Reference_To
(Typ
, Loc
),
8092 Parameter_Associations
=> New_List
(Expression
(N
))));
8095 end Expand_N_Delay_Until_Statement
;
8097 -------------------------
8098 -- Expand_N_Entry_Body --
8099 -------------------------
8101 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8103 -- Associate discriminals with the next protected operation body to be
8106 if Present
(Next_Protected_Operation
(N
)) then
8107 Set_Discriminals
(Parent
(Current_Scope
));
8109 end Expand_N_Entry_Body
;
8111 -----------------------------------
8112 -- Expand_N_Entry_Call_Statement --
8113 -----------------------------------
8115 -- An entry call is expanded into GNARLI calls to implement a simple entry
8116 -- call (see Build_Simple_Entry_Call).
8118 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8124 if No_Run_Time_Mode
then
8125 Error_Msg_CRT
("entry call", N
);
8129 -- If this entry call is part of an asynchronous select, don't expand it
8130 -- here; it will be expanded with the select statement. Don't expand
8131 -- timed entry calls either, as they are translated into asynchronous
8134 -- ??? This whole approach is questionable; it may be better to go back
8135 -- to allowing the expansion to take place and then attempting to fix it
8136 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8137 -- whether the expanded call is on a task or protected entry.
8139 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8140 or else N
/= Triggering_Statement
(Parent
(N
)))
8141 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8142 or else N
/= Entry_Call_Statement
(Parent
(N
))
8143 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8145 Extract_Entry
(N
, Concval
, Ename
, Index
);
8146 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8148 end Expand_N_Entry_Call_Statement
;
8150 --------------------------------
8151 -- Expand_N_Entry_Declaration --
8152 --------------------------------
8154 -- If there are parameters, then first, each of the formals is marked by
8155 -- setting Is_Entry_Formal. Next a record type is built which is used to
8156 -- hold the parameter values. The name of this record type is entryP where
8157 -- entry is the name of the entry, with an additional corresponding access
8158 -- type called entryPA. The record type has matching components for each
8159 -- formal (the component names are the same as the formal names). For
8160 -- elementary types, the component type matches the formal type. For
8161 -- composite types, an access type is declared (with the name formalA)
8162 -- which designates the formal type, and the type of the component is this
8163 -- access type. Finally the Entry_Component of each formal is set to
8164 -- reference the corresponding record component.
8166 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8167 Loc
: constant Source_Ptr
:= Sloc
(N
);
8168 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8169 Components
: List_Id
;
8172 Last_Decl
: Node_Id
;
8173 Component
: Entity_Id
;
8176 Rec_Ent
: Entity_Id
;
8177 Acc_Ent
: Entity_Id
;
8180 Formal
:= First_Formal
(Entry_Ent
);
8183 -- Most processing is done only if parameters are present
8185 if Present
(Formal
) then
8186 Components
:= New_List
;
8188 -- Loop through formals
8190 while Present
(Formal
) loop
8191 Set_Is_Entry_Formal
(Formal
);
8193 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8194 Set_Entry_Component
(Formal
, Component
);
8195 Set_Entry_Formal
(Component
, Formal
);
8196 Ftype
:= Etype
(Formal
);
8198 -- Declare new access type and then append
8200 Ctype
:= Make_Temporary
(Loc
, 'A');
8203 Make_Full_Type_Declaration
(Loc
,
8204 Defining_Identifier
=> Ctype
,
8206 Make_Access_To_Object_Definition
(Loc
,
8207 All_Present
=> True,
8208 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8209 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
8211 Insert_After
(Last_Decl
, Decl
);
8214 Append_To
(Components
,
8215 Make_Component_Declaration
(Loc
,
8216 Defining_Identifier
=> Component
,
8217 Component_Definition
=>
8218 Make_Component_Definition
(Loc
,
8219 Aliased_Present
=> False,
8220 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
8222 Next_Formal_With_Extras
(Formal
);
8225 -- Create the Entry_Parameter_Record declaration
8227 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8230 Make_Full_Type_Declaration
(Loc
,
8231 Defining_Identifier
=> Rec_Ent
,
8233 Make_Record_Definition
(Loc
,
8235 Make_Component_List
(Loc
,
8236 Component_Items
=> Components
)));
8238 Insert_After
(Last_Decl
, Decl
);
8241 -- Construct and link in the corresponding access type
8243 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8245 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8248 Make_Full_Type_Declaration
(Loc
,
8249 Defining_Identifier
=> Acc_Ent
,
8251 Make_Access_To_Object_Definition
(Loc
,
8252 All_Present
=> True,
8253 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
8255 Insert_After
(Last_Decl
, Decl
);
8257 end Expand_N_Entry_Declaration
;
8259 -----------------------------
8260 -- Expand_N_Protected_Body --
8261 -----------------------------
8263 -- Protected bodies are expanded to the completion of the subprograms
8264 -- created for the corresponding protected type. These are a protected and
8265 -- unprotected version of each protected subprogram in the object, a
8266 -- function to calculate each entry barrier, and a procedure to execute the
8267 -- sequence of statements of each protected entry body. For example, for
8268 -- protected type ptype:
8271 -- (O : System.Address;
8272 -- E : Protected_Entry_Index)
8275 -- <discriminant renamings>
8276 -- <private object renamings>
8278 -- return <barrier expression>;
8281 -- procedure pprocN (_object : in out poV;...) is
8282 -- <discriminant renamings>
8283 -- <private object renamings>
8285 -- <sequence of statements>
8288 -- procedure pprocP (_object : in out poV;...) is
8289 -- procedure _clean is
8292 -- ptypeS (_object, Pn);
8293 -- Unlock (_object._object'Access);
8294 -- Abort_Undefer.all;
8299 -- Lock (_object._object'Access);
8300 -- pprocN (_object;...);
8305 -- function pfuncN (_object : poV;...) return Return_Type is
8306 -- <discriminant renamings>
8307 -- <private object renamings>
8309 -- <sequence of statements>
8312 -- function pfuncP (_object : poV) return Return_Type is
8313 -- procedure _clean is
8315 -- Unlock (_object._object'Access);
8316 -- Abort_Undefer.all;
8321 -- Lock (_object._object'Access);
8322 -- return pfuncN (_object);
8329 -- (O : System.Address;
8330 -- P : System.Address;
8331 -- E : Protected_Entry_Index)
8333 -- <discriminant renamings>
8334 -- <private object renamings>
8335 -- type poVP is access poV;
8336 -- _Object : ptVP := ptVP!(O);
8340 -- <statement sequence>
8341 -- Complete_Entry_Body (_Object._Object);
8343 -- when all others =>
8344 -- Exceptional_Complete_Entry_Body (
8345 -- _Object._Object, Get_GNAT_Exception);
8349 -- The type poV is the record created for the protected type to hold
8350 -- the state of the protected object.
8352 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8353 Loc
: constant Source_Ptr
:= Sloc
(N
);
8354 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8356 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8357 -- This flag indicates whether the lock free implementation is active
8359 Current_Node
: Node_Id
;
8360 Disp_Op_Body
: Node_Id
;
8361 New_Op_Body
: Node_Id
;
8362 Num_Entries
: Natural := 0;
8366 function Build_Dispatching_Subprogram_Body
8369 Prot_Bod
: Node_Id
) return Node_Id
;
8370 -- Build a dispatching version of the protected subprogram body. The
8371 -- newly generated subprogram contains a call to the original protected
8372 -- body. The following code is generated:
8374 -- function <protected-function-name> (Param1 .. ParamN) return
8377 -- return <protected-function-name>P (Param1 .. ParamN);
8378 -- end <protected-function-name>;
8382 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8384 -- <protected-procedure-name>P (Param1 .. ParamN);
8385 -- end <protected-procedure-name>
8387 ---------------------------------------
8388 -- Build_Dispatching_Subprogram_Body --
8389 ---------------------------------------
8391 function Build_Dispatching_Subprogram_Body
8394 Prot_Bod
: Node_Id
) return Node_Id
8396 Loc
: constant Source_Ptr
:= Sloc
(N
);
8403 -- Generate a specification without a letter suffix in order to
8404 -- override an interface function or procedure.
8406 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8408 -- The formal parameters become the actuals of the protected function
8409 -- or procedure call.
8411 Actuals
:= New_List
;
8412 Formal
:= First
(Parameter_Specifications
(Spec
));
8413 while Present
(Formal
) loop
8415 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8419 if Nkind
(Spec
) = N_Procedure_Specification
then
8422 Make_Procedure_Call_Statement
(Loc
,
8424 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8425 Parameter_Associations
=> Actuals
));
8428 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8432 Make_Simple_Return_Statement
(Loc
,
8434 Make_Function_Call
(Loc
,
8436 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8437 Parameter_Associations
=> Actuals
)));
8441 Make_Subprogram_Body
(Loc
,
8442 Declarations
=> Empty_List
,
8443 Specification
=> Spec
,
8444 Handled_Statement_Sequence
=>
8445 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8446 end Build_Dispatching_Subprogram_Body
;
8448 -- Start of processing for Expand_N_Protected_Body
8451 if No_Run_Time_Mode
then
8452 Error_Msg_CRT
("protected body", N
);
8456 -- This is the proper body corresponding to a stub. The declarations
8457 -- must be inserted at the point of the stub, which in turn is in the
8458 -- declarative part of the parent unit.
8460 if Nkind
(Parent
(N
)) = N_Subunit
then
8461 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8466 Op_Body
:= First
(Declarations
(N
));
8468 -- The protected body is replaced with the bodies of its
8469 -- protected operations, and the declarations for internal objects
8470 -- that may have been created for entry family bounds.
8472 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8475 while Present
(Op_Body
) loop
8476 case Nkind
(Op_Body
) is
8477 when N_Subprogram_Declaration
=>
8480 when N_Subprogram_Body
=>
8482 -- Do not create bodies for eliminated operations
8484 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8485 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8487 if Lock_Free_Active
then
8489 Build_Lock_Free_Unprotected_Subprogram_Body
8493 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8496 Insert_After
(Current_Node
, New_Op_Body
);
8497 Current_Node
:= New_Op_Body
;
8498 Analyze
(New_Op_Body
);
8500 -- Build the corresponding protected operation. It may
8501 -- appear that this is needed only if this is a visible
8502 -- operation of the type, or if it is an interrupt handler,
8503 -- and this was the strategy used previously in GNAT.
8505 -- However, the operation may be exported through a 'Access
8506 -- to an external caller. This is the common idiom in code
8507 -- that uses the Ada 2005 Timing_Events package. As a result
8508 -- we need to produce the protected body for both visible
8509 -- and private operations, as well as operations that only
8510 -- have a body in the source, and for which we create a
8511 -- declaration in the protected body itself.
8513 if Present
(Corresponding_Spec
(Op_Body
)) then
8514 if Lock_Free_Active
then
8516 Build_Lock_Free_Protected_Subprogram_Body
8517 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8520 Build_Protected_Subprogram_Body
8521 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8524 Insert_After
(Current_Node
, New_Op_Body
);
8525 Analyze
(New_Op_Body
);
8527 Current_Node
:= New_Op_Body
;
8529 -- Generate an overriding primitive operation body for
8530 -- this subprogram if the protected type implements an
8533 if Ada_Version
>= Ada_2005
8535 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8538 Build_Dispatching_Subprogram_Body
8539 (Op_Body
, Pid
, New_Op_Body
);
8541 Insert_After
(Current_Node
, Disp_Op_Body
);
8542 Analyze
(Disp_Op_Body
);
8544 Current_Node
:= Disp_Op_Body
;
8549 when N_Entry_Body
=>
8550 Op_Id
:= Defining_Identifier
(Op_Body
);
8551 Num_Entries
:= Num_Entries
+ 1;
8553 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8555 Insert_After
(Current_Node
, New_Op_Body
);
8556 Current_Node
:= New_Op_Body
;
8557 Analyze
(New_Op_Body
);
8559 when N_Implicit_Label_Declaration
=>
8562 when N_Itype_Reference
=>
8563 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8565 when N_Freeze_Entity
=>
8566 New_Op_Body
:= New_Copy
(Op_Body
);
8568 if Present
(Entity
(Op_Body
))
8569 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8571 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8574 Insert_After
(Current_Node
, New_Op_Body
);
8575 Current_Node
:= New_Op_Body
;
8576 Analyze
(New_Op_Body
);
8579 New_Op_Body
:= New_Copy
(Op_Body
);
8580 Insert_After
(Current_Node
, New_Op_Body
);
8581 Current_Node
:= New_Op_Body
;
8582 Analyze
(New_Op_Body
);
8584 when N_Object_Declaration
=>
8585 pragma Assert
(not Comes_From_Source
(Op_Body
));
8586 New_Op_Body
:= New_Copy
(Op_Body
);
8587 Insert_After
(Current_Node
, New_Op_Body
);
8588 Current_Node
:= New_Op_Body
;
8589 Analyze
(New_Op_Body
);
8592 raise Program_Error
;
8599 -- Finally, create the body of the function that maps an entry index
8600 -- into the corresponding body index, except when there is no entry, or
8601 -- in a Ravenscar-like profile.
8603 if Corresponding_Runtime_Package
(Pid
) =
8604 System_Tasking_Protected_Objects_Entries
8606 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8607 Insert_After
(Current_Node
, New_Op_Body
);
8608 Current_Node
:= New_Op_Body
;
8609 Analyze
(New_Op_Body
);
8612 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8613 -- protected body. At this point all wrapper specs have been created,
8614 -- frozen and included in the dispatch table for the protected type.
8616 if Ada_Version
>= Ada_2005
then
8617 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8619 end Expand_N_Protected_Body
;
8621 -----------------------------------------
8622 -- Expand_N_Protected_Type_Declaration --
8623 -----------------------------------------
8625 -- First we create a corresponding record type declaration used to
8626 -- represent values of this protected type.
8627 -- The general form of this type declaration is
8629 -- type poV (discriminants) is record
8630 -- _Object : aliased <kind>Protection
8631 -- [(<entry count> [, <handler count>])];
8632 -- [entry_family : array (bounds) of Void;]
8633 -- <private data fields>
8636 -- The discriminants are present only if the corresponding protected type
8637 -- has discriminants, and they exactly mirror the protected type
8638 -- discriminants. The private data fields similarly mirror the private
8639 -- declarations of the protected type.
8641 -- The Object field is always present. It contains RTS specific data used
8642 -- to control the protected object. It is declared as Aliased so that it
8643 -- can be passed as a pointer to the RTS. This allows the protected record
8644 -- to be referenced within RTS data structures. An appropriate Protection
8645 -- type and discriminant are generated.
8647 -- The Service field is present for protected objects with entries. It
8648 -- contains sufficient information to allow the entry service procedure for
8649 -- this object to be called when the object is not known till runtime.
8651 -- One entry_family component is present for each entry family in the
8652 -- task definition (see Expand_N_Task_Type_Declaration).
8654 -- When a protected object is declared, an instance of the protected type
8655 -- value record is created. The elaboration of this declaration creates the
8656 -- correct bounds for the entry families, and also evaluates the priority
8657 -- expression if needed. The initialization routine for the protected type
8658 -- itself then calls Initialize_Protection with appropriate parameters to
8659 -- initialize the value of the Task_Id field. Install_Handlers may be also
8660 -- called if a pragma Attach_Handler applies.
8662 -- Note: this record is passed to the subprograms created by the expansion
8663 -- of protected subprograms and entries. It is an in parameter to protected
8664 -- functions and an in out parameter to procedures and entry bodies. The
8665 -- Entity_Id for this created record type is placed in the
8666 -- Corresponding_Record_Type field of the associated protected type entity.
8668 -- Next we create a procedure specifications for protected subprograms and
8669 -- entry bodies. For each protected subprograms two subprograms are
8670 -- created, an unprotected and a protected version. The unprotected version
8671 -- is called from within other operations of the same protected object.
8673 -- We also build the call to register the procedure if a pragma
8674 -- Interrupt_Handler applies.
8676 -- A single subprogram is created to service all entry bodies; it has an
8677 -- additional boolean out parameter indicating that the previous entry call
8678 -- made by the current task was serviced immediately, i.e. not by proxy.
8679 -- The O parameter contains a pointer to a record object of the type
8680 -- described above. An untyped interface is used here to allow this
8681 -- procedure to be called in places where the type of the object to be
8682 -- serviced is not known. This must be done, for example, when a call that
8683 -- may have been requeued is cancelled; the corresponding object must be
8684 -- serviced, but which object that is not known till runtime.
8687 -- (O : System.Address; P : out Boolean);
8688 -- procedure pprocN (_object : in out poV);
8689 -- procedure pproc (_object : in out poV);
8690 -- function pfuncN (_object : poV);
8691 -- function pfunc (_object : poV);
8694 -- Note that this must come after the record type declaration, since
8695 -- the specs refer to this type.
8697 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8698 Loc
: constant Source_Ptr
:= Sloc
(N
);
8699 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8701 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8702 -- This flag indicates whether the lock free implementation is active
8704 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8705 -- This contains two lists; one for visible and one for private decls
8709 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8713 Comp_Id
: Entity_Id
;
8715 Current_Node
: Node_Id
:= N
;
8716 Bdef
: Entity_Id
:= Empty
; -- avoid uninit warning
8717 Edef
: Entity_Id
:= Empty
; -- avoid uninit warning
8718 Entries_Aggr
: Node_Id
;
8719 Body_Id
: Entity_Id
;
8722 Object_Comp
: Node_Id
;
8724 procedure Check_Inlining
(Subp
: Entity_Id
);
8725 -- If the original operation has a pragma Inline, propagate the flag
8726 -- to the internal body, for possible inlining later on. The source
8727 -- operation is invisible to the back-end and is never actually called.
8729 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8730 -- When compiling under the Ravenscar profile, private components must
8731 -- have a static size, or else a protected object will require heap
8732 -- allocation, violating the corresponding restriction. It is preferable
8733 -- to make this check here, because it provides a better error message
8734 -- than the back-end, which refers to the object as a whole.
8736 procedure Register_Handler
;
8737 -- For a protected operation that is an interrupt handler, add the
8738 -- freeze action that will register it as such.
8740 --------------------
8741 -- Check_Inlining --
8742 --------------------
8744 procedure Check_Inlining
(Subp
: Entity_Id
) is
8746 if Is_Inlined
(Subp
) then
8747 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8748 Set_Is_Inlined
(Subp
, False);
8752 ---------------------------------
8753 -- Check_Static_Component_Size --
8754 ---------------------------------
8756 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8757 Typ
: constant Entity_Id
:= Etype
(Comp
);
8761 if Is_Scalar_Type
(Typ
) then
8764 elsif Is_Array_Type
(Typ
) then
8765 return Compile_Time_Known_Bounds
(Typ
);
8767 elsif Is_Record_Type
(Typ
) then
8768 C
:= First_Component
(Typ
);
8769 while Present
(C
) loop
8770 if not Static_Component_Size
(C
) then
8779 -- Any other type will be checked by the back-end
8784 end Static_Component_Size
;
8786 ----------------------
8787 -- Register_Handler --
8788 ----------------------
8790 procedure Register_Handler
is
8792 -- All semantic checks already done in Sem_Prag
8794 Prot_Proc
: constant Entity_Id
:=
8795 Defining_Unit_Name
(Specification
(Current_Node
));
8797 Proc_Address
: constant Node_Id
:=
8798 Make_Attribute_Reference
(Loc
,
8800 New_Reference_To
(Prot_Proc
, Loc
),
8801 Attribute_Name
=> Name_Address
);
8803 RTS_Call
: constant Entity_Id
:=
8804 Make_Procedure_Call_Statement
(Loc
,
8807 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8808 Parameter_Associations
=> New_List
(Proc_Address
));
8810 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8811 end Register_Handler
;
8813 -- Start of processing for Expand_N_Protected_Type_Declaration
8816 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8819 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8822 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8824 Qualify_Entity_Names
(N
);
8826 -- If the type has discriminants, their occurrences in the declaration
8827 -- have been replaced by the corresponding discriminals. For components
8828 -- that are constrained by discriminants, their homologues in the
8829 -- corresponding record type must refer to the discriminants of that
8830 -- record, so we must apply a new renaming to subtypes_indications:
8832 -- protected discriminant => discriminal => record discriminant
8834 -- This replacement is not applied to default expressions, for which
8835 -- the discriminal is correct.
8837 if Has_Discriminants
(Prot_Typ
) then
8843 Disc
:= First_Discriminant
(Prot_Typ
);
8844 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
8845 while Present
(Disc
) loop
8846 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
8847 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
8848 Next_Discriminant
(Disc
);
8854 -- Fill in the component declarations
8856 -- Add components for entry families. For each entry family, create an
8857 -- anonymous type declaration with the same size, and analyze the type.
8859 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
8861 pragma Assert
(Present
(Pdef
));
8863 -- Add private field components
8865 if Present
(Private_Declarations
(Pdef
)) then
8866 Priv
:= First
(Private_Declarations
(Pdef
));
8867 while Present
(Priv
) loop
8868 if Nkind
(Priv
) = N_Component_Declaration
then
8869 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
8871 -- When compiling for a restricted profile, the private
8872 -- components must have a static size. If not, this is an
8873 -- error for a single protected declaration, and rates a
8874 -- warning on a protected type declaration.
8876 if not Comes_From_Source
(Prot_Typ
) then
8877 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
8879 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
8880 Error_Msg_N
("component has non-static size??", Priv
);
8882 ("\creation of protected object of type& will violate"
8883 & " restriction No_Implicit_Heap_Allocations??",
8888 -- The component definition consists of a subtype indication,
8889 -- or (in Ada 2005) an access definition. Make a copy of the
8890 -- proper definition.
8893 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
8894 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
8896 Nent
: constant Entity_Id
:=
8897 Make_Defining_Identifier
(Sloc
(Oent
),
8898 Chars
=> Chars
(Oent
));
8901 if Present
(Subtype_Indication
(Old_Comp
)) then
8903 Make_Component_Definition
(Sloc
(Oent
),
8904 Aliased_Present
=> False,
8905 Subtype_Indication
=>
8906 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
8910 Make_Component_Definition
(Sloc
(Oent
),
8911 Aliased_Present
=> False,
8912 Access_Definition
=>
8913 New_Copy_Tree
(Access_Definition
(Old_Comp
),
8918 Make_Component_Declaration
(Loc
,
8919 Defining_Identifier
=> Nent
,
8920 Component_Definition
=> New_Comp
,
8921 Expression
=> Expression
(Priv
));
8923 Set_Has_Per_Object_Constraint
(Nent
,
8924 Has_Per_Object_Constraint
(Oent
));
8926 Append_To
(Cdecls
, New_Priv
);
8929 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
8931 -- Make the unprotected version of the subprogram available
8932 -- for expansion of intra object calls. There is need for
8933 -- a protected version only if the subprogram is an interrupt
8934 -- handler, otherwise this operation can only be called from
8938 Make_Subprogram_Declaration
(Loc
,
8940 Build_Protected_Sub_Specification
8941 (Priv
, Prot_Typ
, Unprotected_Mode
));
8943 Insert_After
(Current_Node
, Sub
);
8946 Set_Protected_Body_Subprogram
8947 (Defining_Unit_Name
(Specification
(Priv
)),
8948 Defining_Unit_Name
(Specification
(Sub
)));
8949 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
8950 Current_Node
:= Sub
;
8953 Make_Subprogram_Declaration
(Loc
,
8955 Build_Protected_Sub_Specification
8956 (Priv
, Prot_Typ
, Protected_Mode
));
8958 Insert_After
(Current_Node
, Sub
);
8960 Current_Node
:= Sub
;
8962 if Is_Interrupt_Handler
8963 (Defining_Unit_Name
(Specification
(Priv
)))
8965 if not Restricted_Profile
then
8975 -- Except for the lock-free implementation, prepend the _Object field
8976 -- with the right type to the component list. We need to compute the
8977 -- number of entries, and in some cases the number of Attach_Handler
8980 if not Lock_Free_Active
then
8983 Num_Attach_Handler
: Int
:= 0;
8984 Protection_Subtype
: Node_Id
;
8985 Entry_Count_Expr
: constant Node_Id
:=
8986 Build_Entry_Count_Expression
8987 (Prot_Typ
, Cdecls
, Loc
);
8990 if Has_Attach_Handler
(Prot_Typ
) then
8991 Ritem
:= First_Rep_Item
(Prot_Typ
);
8992 while Present
(Ritem
) loop
8993 if Nkind
(Ritem
) = N_Pragma
8994 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
8996 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
8999 Next_Rep_Item
(Ritem
);
9003 -- Determine the proper protection type. There are two special
9004 -- cases: 1) when the protected type has dynamic interrupt
9005 -- handlers, and 2) when it has static handlers and we use a
9006 -- restricted profile.
9008 if Has_Attach_Handler
(Prot_Typ
)
9009 and then not Restricted_Profile
9011 Protection_Subtype
:=
9012 Make_Subtype_Indication
(Loc
,
9015 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9017 Make_Index_Or_Discriminant_Constraint
(Loc
,
9018 Constraints
=> New_List
(
9020 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9022 elsif Has_Interrupt_Handler
(Prot_Typ
)
9023 and then not Restriction_Active
(No_Dynamic_Attachment
)
9025 Protection_Subtype
:=
9026 Make_Subtype_Indication
(Loc
,
9029 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9031 Make_Index_Or_Discriminant_Constraint
(Loc
,
9032 Constraints
=> New_List
(Entry_Count_Expr
)));
9035 case Corresponding_Runtime_Package
(Prot_Typ
) is
9036 when System_Tasking_Protected_Objects_Entries
=>
9037 Protection_Subtype
:=
9038 Make_Subtype_Indication
(Loc
,
9041 (RTE
(RE_Protection_Entries
), Loc
),
9043 Make_Index_Or_Discriminant_Constraint
(Loc
,
9044 Constraints
=> New_List
(Entry_Count_Expr
)));
9046 when System_Tasking_Protected_Objects_Single_Entry
=>
9047 Protection_Subtype
:=
9048 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
9050 when System_Tasking_Protected_Objects
=>
9051 Protection_Subtype
:=
9052 New_Reference_To
(RTE
(RE_Protection
), Loc
);
9055 raise Program_Error
;
9060 Make_Component_Declaration
(Loc
,
9061 Defining_Identifier
=>
9062 Make_Defining_Identifier
(Loc
, Name_uObject
),
9063 Component_Definition
=>
9064 Make_Component_Definition
(Loc
,
9065 Aliased_Present
=> True,
9066 Subtype_Indication
=> Protection_Subtype
));
9069 -- Put the _Object component after the private component so that it
9070 -- be finalized early as required by 9.4 (20)
9072 Append_To
(Cdecls
, Object_Comp
);
9075 Insert_After
(Current_Node
, Rec_Decl
);
9076 Current_Node
:= Rec_Decl
;
9078 -- Analyze the record declaration immediately after construction,
9079 -- because the initialization procedure is needed for single object
9080 -- declarations before the next entity is analyzed (the freeze call
9081 -- that generates this initialization procedure is found below).
9083 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9085 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9086 -- the corresponding record is frozen. If any wrappers are generated,
9087 -- Current_Node is updated accordingly.
9089 if Ada_Version
>= Ada_2005
then
9090 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9093 -- Collect pointers to entry bodies and their barriers, to be placed
9094 -- in the Entry_Bodies_Array for the type. For each entry/family we
9095 -- add an expression to the aggregate which is the initial value of
9096 -- this array. The array is declared after all protected subprograms.
9098 if Has_Entries
(Prot_Typ
) then
9099 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9101 Entries_Aggr
:= Empty
;
9104 -- Build two new procedure specifications for each protected subprogram;
9105 -- one to call from outside the object and one to call from inside.
9106 -- Build a barrier function and an entry body action procedure
9107 -- specification for each protected entry. Initialize the entry body
9108 -- array. If subprogram is flagged as eliminated, do not generate any
9109 -- internal operations.
9112 Comp
:= First
(Visible_Declarations
(Pdef
));
9113 while Present
(Comp
) loop
9114 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9116 Make_Subprogram_Declaration
(Loc
,
9118 Build_Protected_Sub_Specification
9119 (Comp
, Prot_Typ
, Unprotected_Mode
));
9121 Insert_After
(Current_Node
, Sub
);
9124 Set_Protected_Body_Subprogram
9125 (Defining_Unit_Name
(Specification
(Comp
)),
9126 Defining_Unit_Name
(Specification
(Sub
)));
9127 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9129 -- Make the protected version of the subprogram available for
9130 -- expansion of external calls.
9132 Current_Node
:= Sub
;
9135 Make_Subprogram_Declaration
(Loc
,
9137 Build_Protected_Sub_Specification
9138 (Comp
, Prot_Typ
, Protected_Mode
));
9140 Insert_After
(Current_Node
, Sub
);
9143 Current_Node
:= Sub
;
9145 -- Generate an overriding primitive operation specification for
9146 -- this subprogram if the protected type implements an interface.
9148 if Ada_Version
>= Ada_2005
9150 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9153 Make_Subprogram_Declaration
(Loc
,
9155 Build_Protected_Sub_Specification
9156 (Comp
, Prot_Typ
, Dispatching_Mode
));
9158 Insert_After
(Current_Node
, Sub
);
9161 Current_Node
:= Sub
;
9164 -- If a pragma Interrupt_Handler applies, build and add a call to
9165 -- Register_Interrupt_Handler to the freezing actions of the
9166 -- protected version (Current_Node) of the subprogram:
9168 -- system.interrupts.register_interrupt_handler
9169 -- (prot_procP'address);
9171 if not Restricted_Profile
9172 and then Is_Interrupt_Handler
9173 (Defining_Unit_Name
(Specification
(Comp
)))
9178 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9179 E_Count
:= E_Count
+ 1;
9180 Comp_Id
:= Defining_Identifier
(Comp
);
9183 Make_Defining_Identifier
(Loc
,
9184 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9186 Make_Subprogram_Declaration
(Loc
,
9188 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9190 Insert_After
(Current_Node
, Sub
);
9193 -- Build wrapper procedure for pre/postconditions
9195 Build_PPC_Wrapper
(Comp_Id
, N
);
9197 Set_Protected_Body_Subprogram
9198 (Defining_Identifier
(Comp
),
9199 Defining_Unit_Name
(Specification
(Sub
)));
9201 Current_Node
:= Sub
;
9204 Make_Defining_Identifier
(Loc
,
9205 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
9207 Make_Subprogram_Declaration
(Loc
,
9209 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9211 Insert_After
(Current_Node
, Sub
);
9213 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9214 Set_Barrier_Function
(Comp_Id
, Bdef
);
9215 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9216 Current_Node
:= Sub
;
9218 -- Collect pointers to the protected subprogram and the barrier
9219 -- of the current entry, for insertion into Entry_Bodies_Array.
9221 Append_To
(Expressions
(Entries_Aggr
),
9222 Make_Aggregate
(Loc
,
9223 Expressions
=> New_List
(
9224 Make_Attribute_Reference
(Loc
,
9225 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9226 Attribute_Name
=> Name_Unrestricted_Access
),
9227 Make_Attribute_Reference
(Loc
,
9228 Prefix
=> New_Reference_To
(Edef
, Loc
),
9229 Attribute_Name
=> Name_Unrestricted_Access
))));
9235 -- If there are some private entry declarations, expand it as if they
9236 -- were visible entries.
9238 if Present
(Private_Declarations
(Pdef
)) then
9239 Comp
:= First
(Private_Declarations
(Pdef
));
9240 while Present
(Comp
) loop
9241 if Nkind
(Comp
) = N_Entry_Declaration
then
9242 E_Count
:= E_Count
+ 1;
9243 Comp_Id
:= Defining_Identifier
(Comp
);
9246 Make_Defining_Identifier
(Loc
,
9247 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9249 Make_Subprogram_Declaration
(Loc
,
9251 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9253 Insert_After
(Current_Node
, Sub
);
9256 Set_Protected_Body_Subprogram
9257 (Defining_Identifier
(Comp
),
9258 Defining_Unit_Name
(Specification
(Sub
)));
9260 Current_Node
:= Sub
;
9263 Make_Defining_Identifier
(Loc
,
9264 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9267 Make_Subprogram_Declaration
(Loc
,
9269 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9271 Insert_After
(Current_Node
, Sub
);
9273 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9274 Set_Barrier_Function
(Comp_Id
, Bdef
);
9275 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9276 Current_Node
:= Sub
;
9278 -- Collect pointers to the protected subprogram and the barrier
9279 -- of the current entry, for insertion into Entry_Bodies_Array.
9281 Append_To
(Expressions
(Entries_Aggr
),
9282 Make_Aggregate
(Loc
,
9283 Expressions
=> New_List
(
9284 Make_Attribute_Reference
(Loc
,
9285 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9286 Attribute_Name
=> Name_Unrestricted_Access
),
9287 Make_Attribute_Reference
(Loc
,
9288 Prefix
=> New_Reference_To
(Edef
, Loc
),
9289 Attribute_Name
=> Name_Unrestricted_Access
))));
9296 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9297 -- all protected subprograms have been collected.
9299 if Has_Entries
(Prot_Typ
) then
9301 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9302 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9304 case Corresponding_Runtime_Package
(Prot_Typ
) is
9305 when System_Tasking_Protected_Objects_Entries
=>
9306 Body_Arr
:= Make_Object_Declaration
(Loc
,
9307 Defining_Identifier
=> Body_Id
,
9308 Aliased_Present
=> True,
9309 Object_Definition
=>
9310 Make_Subtype_Indication
(Loc
,
9311 Subtype_Mark
=> New_Reference_To
(
9312 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9314 Make_Index_Or_Discriminant_Constraint
(Loc
,
9315 Constraints
=> New_List
(
9317 Make_Integer_Literal
(Loc
, 1),
9318 Make_Integer_Literal
(Loc
, E_Count
))))),
9319 Expression
=> Entries_Aggr
);
9321 when System_Tasking_Protected_Objects_Single_Entry
=>
9322 Body_Arr
:= Make_Object_Declaration
(Loc
,
9323 Defining_Identifier
=> Body_Id
,
9324 Aliased_Present
=> True,
9325 Object_Definition
=> New_Reference_To
9326 (RTE
(RE_Entry_Body
), Loc
),
9328 Make_Aggregate
(Loc
,
9329 Expressions
=> New_List
(
9330 Make_Attribute_Reference
(Loc
,
9331 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9332 Attribute_Name
=> Name_Unrestricted_Access
),
9333 Make_Attribute_Reference
(Loc
,
9334 Prefix
=> New_Reference_To
(Edef
, Loc
),
9335 Attribute_Name
=> Name_Unrestricted_Access
))));
9338 raise Program_Error
;
9341 -- A pointer to this array will be placed in the corresponding record
9342 -- by its initialization procedure so this needs to be analyzed here.
9344 Insert_After
(Current_Node
, Body_Arr
);
9345 Current_Node
:= Body_Arr
;
9348 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9350 -- Finally, build the function that maps an entry index into the
9351 -- corresponding body. A pointer to this function is placed in each
9352 -- object of the type. Except for a ravenscar-like profile (no abort,
9353 -- no entry queue, 1 entry)
9355 if Corresponding_Runtime_Package
(Prot_Typ
) =
9356 System_Tasking_Protected_Objects_Entries
9359 Make_Subprogram_Declaration
(Loc
,
9360 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9361 Insert_After
(Current_Node
, Sub
);
9365 end Expand_N_Protected_Type_Declaration
;
9367 --------------------------------
9368 -- Expand_N_Requeue_Statement --
9369 --------------------------------
9371 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9372 -- operations, depending on the source and destination (task or protected
9373 -- object). A dispatching requeue statement is expanded into a call to the
9374 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9375 -- jump around the remainder of processing for the original entry and, if
9376 -- the destination is (different) protected object, to attempt to service
9377 -- it. The following illustrates the various cases:
9380 -- (O : System.Address;
9381 -- P : System.Address;
9382 -- E : Protected_Entry_Index)
9384 -- <discriminant renamings>
9385 -- <private object renamings>
9386 -- type poVP is access poV;
9387 -- _object : ptVP := ptVP!(O);
9391 -- <start of statement sequence for entry>
9393 -- -- Requeue from one protected entry body to another protected
9396 -- Requeue_Protected_Entry (
9397 -- _object._object'Access,
9398 -- new._object'Access,
9403 -- <some more of the statement sequence for entry>
9405 -- -- Requeue from an entry body to a task entry
9407 -- Requeue_Protected_To_Task_Entry (
9413 -- <rest of statement sequence for entry>
9414 -- Complete_Entry_Body (_object._object);
9417 -- when all others =>
9418 -- Exceptional_Complete_Entry_Body (
9419 -- _object._object, Get_GNAT_Exception);
9423 -- Requeue of a task entry call to a task entry
9425 -- Accept_Call (E, Ann);
9426 -- <start of statement sequence for accept statement>
9427 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9429 -- <rest of statement sequence for accept statement>
9431 -- Complete_Rendezvous;
9434 -- when all others =>
9435 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9437 -- Requeue of a task entry call to a protected entry
9439 -- Accept_Call (E, Ann);
9440 -- <start of statement sequence for accept statement>
9441 -- Requeue_Task_To_Protected_Entry (
9442 -- new._object'Access,
9447 -- <rest of statement sequence for accept statement>
9449 -- Complete_Rendezvous;
9452 -- when all others =>
9453 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9455 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9456 -- marked by pragma Implemented (XXX, By_Entry).
9458 -- The requeue is inside a protected entry:
9461 -- (O : System.Address;
9462 -- P : System.Address;
9463 -- E : Protected_Entry_Index)
9465 -- <discriminant renamings>
9466 -- <private object renamings>
9467 -- type poVP is access poV;
9468 -- _object : ptVP := ptVP!(O);
9472 -- <start of statement sequence for entry>
9475 -- (<interface class-wide object>,
9478 -- Ada.Tags.Get_Offset_Index
9480 -- <interface dispatch table index of target entry>),
9484 -- <rest of statement sequence for entry>
9485 -- Complete_Entry_Body (_object._object);
9488 -- when all others =>
9489 -- Exceptional_Complete_Entry_Body (
9490 -- _object._object, Get_GNAT_Exception);
9494 -- The requeue is inside a task entry:
9496 -- Accept_Call (E, Ann);
9497 -- <start of statement sequence for accept statement>
9499 -- (<interface class-wide object>,
9502 -- Ada.Tags.Get_Offset_Index
9504 -- <interface dispatch table index of target entrt>),
9508 -- <rest of statement sequence for accept statement>
9510 -- Complete_Rendezvous;
9513 -- when all others =>
9514 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9516 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9517 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9518 -- statement is replaced by a dispatching call with actual parameters taken
9519 -- from the inner-most accept statement or entry body.
9521 -- Target.Primitive (Param1, ..., ParamN);
9523 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9524 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9528 -- S : constant Offset_Index :=
9529 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9530 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9533 -- if C = POK_Protected_Entry
9534 -- or else C = POK_Task_Entry
9536 -- <statements for dispatching requeue>
9538 -- elsif C = POK_Protected_Procedure then
9539 -- <dispatching call equivalent>
9542 -- raise Program_Error;
9546 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9547 Loc
: constant Source_Ptr
:= Sloc
(N
);
9548 Conc_Typ
: Entity_Id
;
9552 Old_Typ
: Entity_Id
;
9554 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9555 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9556 -- the form Concval.Ename. It is statically known that Ename is allowed
9557 -- to be implemented by a protected procedure. Create a dispatching call
9558 -- equivalent of Concval.Ename taking the actual parameters from the
9559 -- inner-most accept statement or entry body.
9561 function Build_Dispatching_Requeue
return Node_Id
;
9562 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9563 -- the form Concval.Ename. It is statically known that Ename is allowed
9564 -- to be implemented by a protected or a task entry. Create a call to
9565 -- primitive _Disp_Requeue which handles the low-level actions.
9567 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9568 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9569 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9570 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9571 -- determines at runtime whether Ename denotes an entry or a procedure
9572 -- and perform the appropriate kind of dispatching select.
9574 function Build_Normal_Requeue
return Node_Id
;
9575 -- N denotes a non-dispatching requeue statement to either a task or a
9576 -- protected entry. Build the appropriate runtime call to perform the
9579 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9580 -- For a protected entry, create a return statement to skip the rest of
9581 -- the entry body. Otherwise, create a goto statement to skip the rest
9582 -- of a task accept statement. The lookup for the enclosing entry body
9583 -- or accept statement starts from Search.
9585 ---------------------------------------
9586 -- Build_Dispatching_Call_Equivalent --
9587 ---------------------------------------
9589 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9590 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9591 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9598 -- Climb the parent chain looking for the inner-most entry body or
9599 -- accept statement.
9602 while Present
(Acc_Ent
)
9603 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9606 Acc_Ent
:= Parent
(Acc_Ent
);
9609 -- A requeue statement should be housed inside an entry body or an
9610 -- accept statement at some level. If this is not the case, then the
9611 -- tree is malformed.
9613 pragma Assert
(Present
(Acc_Ent
));
9615 -- Recover the list of formal parameters
9617 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9618 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9621 Formals
:= Parameter_Specifications
(Acc_Ent
);
9623 -- Create the actual parameters for the dispatching call. These are
9624 -- simply copies of the entry body or accept statement formals in the
9625 -- same order as they appear.
9629 if Present
(Formals
) then
9630 Actuals
:= New_List
;
9631 Formal
:= First
(Formals
);
9632 while Present
(Formal
) loop
9634 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9640 -- Obj.Call_Ent (Actuals);
9643 Make_Procedure_Call_Statement
(Loc
,
9645 Make_Selected_Component
(Loc
,
9646 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9647 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9649 Parameter_Associations
=> Actuals
);
9650 end Build_Dispatching_Call_Equivalent
;
9652 -------------------------------
9653 -- Build_Dispatching_Requeue --
9654 -------------------------------
9656 function Build_Dispatching_Requeue
return Node_Id
is
9657 Params
: constant List_Id
:= New_List
;
9660 -- Process the "with abort" parameter
9663 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9665 -- Process the entry wrapper's position in the primary dispatch
9666 -- table parameter. Generate:
9668 -- Ada.Tags.Get_Entry_Index
9669 -- (T => To_Tag_Ptr (Obj'Address).all,
9671 -- Ada.Tags.Get_Offset_Index
9672 -- (Ada.Tags.Tag (Concval),
9673 -- <interface dispatch table position of Ename>));
9675 -- Note that Obj'Address is recursively expanded into a call to
9676 -- Base_Address (Obj).
9678 if Tagged_Type_Expansion
then
9680 Make_Function_Call
(Loc
,
9681 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9682 Parameter_Associations
=> New_List
(
9684 Make_Explicit_Dereference
(Loc
,
9685 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9686 Make_Attribute_Reference
(Loc
,
9687 Prefix
=> New_Copy_Tree
(Concval
),
9688 Attribute_Name
=> Name_Address
))),
9690 Make_Function_Call
(Loc
,
9691 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9692 Parameter_Associations
=> New_List
(
9693 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9694 Make_Integer_Literal
(Loc
,
9695 DT_Position
(Entity
(Ename
))))))));
9701 Make_Function_Call
(Loc
,
9702 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9703 Parameter_Associations
=> New_List
(
9705 Make_Attribute_Reference
(Loc
,
9707 Attribute_Name
=> Name_Tag
),
9709 Make_Function_Call
(Loc
,
9710 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9712 Parameter_Associations
=> New_List
(
9716 Make_Attribute_Reference
(Loc
,
9718 Attribute_Name
=> Name_Tag
),
9722 Make_Attribute_Reference
(Loc
,
9723 Prefix
=> New_Reference_To
(Etype
(Concval
), Loc
),
9724 Attribute_Name
=> Name_Tag
),
9728 Make_Integer_Literal
(Loc
,
9729 DT_Position
(Entity
(Ename
))))))));
9732 -- Specific actuals for protected to XXX requeue
9734 if Is_Protected_Type
(Old_Typ
) then
9736 Make_Attribute_Reference
(Loc
, -- _object'Address
9738 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9739 Attribute_Name
=> Name_Address
));
9741 Prepend_To
(Params
, -- True
9742 New_Reference_To
(Standard_True
, Loc
));
9744 -- Specific actuals for task to XXX requeue
9747 pragma Assert
(Is_Task_Type
(Old_Typ
));
9749 Prepend_To
(Params
, -- null
9750 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
9752 Prepend_To
(Params
, -- False
9753 New_Reference_To
(Standard_False
, Loc
));
9756 -- Add the object parameter
9758 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9761 -- _Disp_Requeue (<Params>);
9763 -- Find entity for Disp_Requeue operation, which belongs to
9764 -- the type and may not be directly visible.
9771 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9772 while Present
(Elmt
) loop
9774 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9779 Make_Procedure_Call_Statement
(Loc
,
9780 Name
=> New_Occurrence_Of
(Op
, Loc
),
9781 Parameter_Associations
=> Params
);
9783 end Build_Dispatching_Requeue
;
9785 --------------------------------------
9786 -- Build_Dispatching_Requeue_To_Any --
9787 --------------------------------------
9789 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9790 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9791 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9792 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
9802 -- Dispatch table slot processing, generate:
9805 S
:= Build_S
(Loc
, Decls
);
9807 -- Call kind processing, generate:
9808 -- C : Ada.Tags.Prim_Op_Kind;
9810 C
:= Build_C
(Loc
, Decls
);
9813 -- S := Ada.Tags.Get_Offset_Index
9814 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9816 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
9819 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9822 Make_Procedure_Call_Statement
(Loc
,
9825 Find_Prim_Op
(Etype
(Etype
(Obj
)),
9826 Name_uDisp_Get_Prim_Op_Kind
),
9828 Parameter_Associations
=> New_List
(
9829 New_Copy_Tree
(Obj
),
9830 New_Reference_To
(S
, Loc
),
9831 New_Reference_To
(C
, Loc
))));
9835 -- if C = POK_Protected_Entry
9836 -- or else C = POK_Task_Entry
9839 Make_Implicit_If_Statement
(N
,
9845 New_Reference_To
(C
, Loc
),
9847 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
9852 New_Reference_To
(C
, Loc
),
9854 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
9856 -- Dispatching requeue equivalent
9858 Then_Statements
=> New_List
(
9859 Build_Dispatching_Requeue
,
9862 -- elsif C = POK_Protected_Procedure then
9864 Elsif_Parts
=> New_List
(
9865 Make_Elsif_Part
(Loc
,
9869 New_Reference_To
(C
, Loc
),
9872 RTE
(RE_POK_Protected_Procedure
), Loc
)),
9874 -- Dispatching call equivalent
9876 Then_Statements
=> New_List
(
9877 Build_Dispatching_Call_Equivalent
))),
9880 -- raise Program_Error;
9883 Else_Statements
=> New_List
(
9884 Make_Raise_Program_Error
(Loc
,
9885 Reason
=> PE_Explicit_Raise
))));
9887 -- Wrap everything into a block
9890 Make_Block_Statement
(Loc
,
9891 Declarations
=> Decls
,
9892 Handled_Statement_Sequence
=>
9893 Make_Handled_Sequence_Of_Statements
(Loc
,
9894 Statements
=> Stmts
));
9895 end Build_Dispatching_Requeue_To_Any
;
9897 --------------------------
9898 -- Build_Normal_Requeue --
9899 --------------------------
9901 function Build_Normal_Requeue
return Node_Id
is
9902 Params
: constant List_Id
:= New_List
;
9907 -- Process the "with abort" parameter
9910 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9912 -- Add the index expression to the parameters. It is common among all
9916 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
9918 if Is_Protected_Type
(Old_Typ
) then
9920 Self_Param
: Node_Id
;
9924 Make_Attribute_Reference
(Loc
,
9926 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9928 Name_Unchecked_Access
);
9930 -- Protected to protected requeue
9932 if Is_Protected_Type
(Conc_Typ
) then
9935 RTE
(RE_Requeue_Protected_Entry
), Loc
);
9938 Make_Attribute_Reference
(Loc
,
9940 Concurrent_Ref
(Concval
),
9942 Name_Unchecked_Access
);
9944 -- Protected to task requeue
9946 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9949 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
9951 Param
:= Concurrent_Ref
(Concval
);
9954 Prepend_To
(Params
, Param
);
9955 Prepend_To
(Params
, Self_Param
);
9958 else pragma Assert
(Is_Task_Type
(Old_Typ
));
9960 -- Task to protected requeue
9962 if Is_Protected_Type
(Conc_Typ
) then
9965 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
9968 Make_Attribute_Reference
(Loc
,
9970 Concurrent_Ref
(Concval
),
9972 Name_Unchecked_Access
);
9974 -- Task to task requeue
9976 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9978 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
);
9980 Param
:= Concurrent_Ref
(Concval
);
9983 Prepend_To
(Params
, Param
);
9987 Make_Procedure_Call_Statement
(Loc
,
9989 Parameter_Associations
=> Params
);
9990 end Build_Normal_Requeue
;
9992 --------------------------
9993 -- Build_Skip_Statement --
9994 --------------------------
9996 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
9997 Skip_Stmt
: Node_Id
;
10000 -- Build a return statement to skip the rest of the entire body
10002 if Is_Protected_Type
(Old_Typ
) then
10003 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10005 -- If the requeue is within a task, find the end label of the
10006 -- enclosing accept statement and create a goto statement to it.
10014 -- Climb the parent chain looking for the enclosing accept
10017 Acc
:= Parent
(Search
);
10018 while Present
(Acc
)
10019 and then Nkind
(Acc
) /= N_Accept_Statement
10021 Acc
:= Parent
(Acc
);
10024 -- The last statement is the second label used for completing
10025 -- the rendezvous the usual way. The label we are looking for
10026 -- is right before it.
10029 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10031 pragma Assert
(Nkind
(Label
) = N_Label
);
10033 -- Generate a goto statement to skip the rest of the accept
10036 Make_Goto_Statement
(Loc
,
10038 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10042 Set_Analyzed
(Skip_Stmt
);
10045 end Build_Skip_Statement
;
10047 -- Start of processing for Expand_N_Requeue_Statement
10050 -- Extract the components of the entry call
10052 Extract_Entry
(N
, Concval
, Ename
, Index
);
10053 Conc_Typ
:= Etype
(Concval
);
10055 -- If the prefix is an access to class-wide type, dereference to get
10056 -- object and entry type.
10058 if Is_Access_Type
(Conc_Typ
) then
10059 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10061 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10062 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10065 -- Examine the scope stack in order to find nearest enclosing protected
10066 -- or task type. This will constitute our invocation source.
10068 Old_Typ
:= Current_Scope
;
10069 while Present
(Old_Typ
)
10070 and then not Is_Protected_Type
(Old_Typ
)
10071 and then not Is_Task_Type
(Old_Typ
)
10073 Old_Typ
:= Scope
(Old_Typ
);
10076 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10077 -- Concval.Ename where the type of Concval is class-wide concurrent
10080 if Ada_Version
>= Ada_2012
10081 and then Present
(Concval
)
10082 and then Is_Class_Wide_Type
(Conc_Typ
)
10083 and then Is_Concurrent_Interface
(Conc_Typ
)
10086 Has_Impl
: Boolean := False;
10087 Impl_Kind
: Name_Id
:= No_Name
;
10090 -- Check whether the Ename is flagged by pragma Implemented
10092 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10094 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10097 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10098 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10101 and then Impl_Kind
= Name_By_Entry
10103 Rewrite
(N
, Build_Dispatching_Requeue
);
10105 Insert_After
(N
, Build_Skip_Statement
(N
));
10107 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10108 -- a protected procedure. In this case the requeue is transformed
10109 -- into a dispatching call.
10112 and then Impl_Kind
= Name_By_Protected_Procedure
10114 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10117 -- The procedure_or_entry_NAME's implementation kind is either
10118 -- By_Any, Optional, or pragma Implemented was not applied at all.
10119 -- In this case a runtime test determines whether Ename denotes an
10120 -- entry or a protected procedure and performs the appropriate
10124 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10129 -- Processing for regular (non-dispatching) requeues
10132 Rewrite
(N
, Build_Normal_Requeue
);
10134 Insert_After
(N
, Build_Skip_Statement
(N
));
10136 end Expand_N_Requeue_Statement
;
10138 -------------------------------
10139 -- Expand_N_Selective_Accept --
10140 -------------------------------
10142 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10143 Loc
: constant Source_Ptr
:= Sloc
(N
);
10144 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10146 -- Note: in the below declarations a lot of new lists are allocated
10147 -- unconditionally which may well not end up being used. That's not
10148 -- a good idea since it wastes space gratuitously ???
10150 Accept_Case
: List_Id
;
10151 Accept_List
: constant List_Id
:= New_List
;
10154 Alt_List
: constant List_Id
:= New_List
;
10155 Alt_Stats
: List_Id
;
10156 Ann
: Entity_Id
:= Empty
;
10158 Check_Guard
: Boolean := True;
10160 Decls
: constant List_Id
:= New_List
;
10161 Stats
: constant List_Id
:= New_List
;
10162 Body_List
: constant List_Id
:= New_List
;
10163 Trailing_List
: constant List_Id
:= New_List
;
10166 Else_Present
: Boolean := False;
10167 Terminate_Alt
: Node_Id
:= Empty
;
10168 Select_Mode
: Node_Id
;
10170 Delay_Case
: List_Id
;
10171 Delay_Count
: Integer := 0;
10172 Delay_Val
: Entity_Id
;
10173 Delay_Index
: Entity_Id
;
10174 Delay_Min
: Entity_Id
;
10175 Delay_Num
: Int
:= 1;
10176 Delay_Alt_List
: List_Id
:= New_List
;
10177 Delay_List
: constant List_Id
:= New_List
;
10181 First_Delay
: Boolean := True;
10182 Guard_Open
: Entity_Id
;
10188 Num_Accept
: Nat
:= 0;
10190 Time_Type
: Entity_Id
;
10191 Select_Call
: Node_Id
;
10193 Qnam
: constant Entity_Id
:=
10194 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10196 Xnam
: constant Entity_Id
:=
10197 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10199 -----------------------
10200 -- Local subprograms --
10201 -----------------------
10203 function Accept_Or_Raise
return List_Id
;
10204 -- For the rare case where delay alternatives all have guards, and
10205 -- all of them are closed, it is still possible that there were open
10206 -- accept alternatives with no callers. We must reexamine the
10207 -- Accept_List, and execute a selective wait with no else if some
10208 -- accept is open. If none, we raise program_error.
10210 procedure Add_Accept
(Alt
: Node_Id
);
10211 -- Process a single accept statement in a select alternative. Build
10212 -- procedure for body of accept, and add entry to dispatch table with
10213 -- expression for guard, in preparation for call to run time select.
10215 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10216 -- Manufacture a label using Num as a serial number and declare it.
10217 -- The declaration is appended to Decls. The label marks the trailing
10218 -- statements of an accept or delay alternative.
10220 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10221 -- Build call to Selective_Wait runtime routine
10223 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10224 -- Add code to compare value of delay with previous values, and
10225 -- generate case entry for trailing statements.
10227 procedure Process_Accept_Alternative
10231 -- Add code to call corresponding procedure, and branch to
10232 -- trailing statements, if any.
10234 ---------------------
10235 -- Accept_Or_Raise --
10236 ---------------------
10238 function Accept_Or_Raise
return List_Id
is
10241 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10244 -- We generate the following:
10246 -- for J in q'range loop
10247 -- if q(J).S /=null_task_entry then
10248 -- selective_wait (simple_mode,...);
10254 -- if no rendez_vous then
10255 -- raise program_error;
10258 -- Note that the code needs to know that the selector name
10259 -- in an Accept_Alternative is named S.
10261 Cond
:= Make_Op_Ne
(Loc
,
10263 Make_Selected_Component
(Loc
,
10265 Make_Indexed_Component
(Loc
,
10266 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10267 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
10268 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10270 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
10272 Stats
:= New_List
(
10273 Make_Implicit_Loop_Statement
(N
,
10274 Iteration_Scheme
=>
10275 Make_Iteration_Scheme
(Loc
,
10276 Loop_Parameter_Specification
=>
10277 Make_Loop_Parameter_Specification
(Loc
,
10278 Defining_Identifier
=> J
,
10279 Discrete_Subtype_Definition
=>
10280 Make_Attribute_Reference
(Loc
,
10281 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10282 Attribute_Name
=> Name_Range
,
10283 Expressions
=> New_List
(
10284 Make_Integer_Literal
(Loc
, 1))))),
10286 Statements
=> New_List
(
10287 Make_Implicit_If_Statement
(N
,
10289 Then_Statements
=> New_List
(
10291 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
10292 Make_Exit_Statement
(Loc
))))));
10295 Make_Raise_Program_Error
(Loc
,
10296 Condition
=> Make_Op_Eq
(Loc
,
10297 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
10299 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
10300 Reason
=> PE_All_Guards_Closed
));
10303 end Accept_Or_Raise
;
10309 procedure Add_Accept
(Alt
: Node_Id
) is
10310 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10311 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10312 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10313 Eent
: constant Entity_Id
:= Entity
(Ename
);
10314 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10315 Null_Body
: Node_Id
;
10316 Proc_Body
: Node_Id
;
10317 PB_Ent
: Entity_Id
;
10323 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10326 if Present
(Condition
(Alt
)) then
10328 Make_If_Expression
(Eloc
, New_List
(
10330 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10331 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10334 Entry_Index_Expression
10335 (Eloc
, Eent
, Index
, Scope
(Eent
));
10338 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10339 Null_Body
:= New_Reference_To
(Standard_False
, Eloc
);
10341 if Abort_Allowed
then
10342 Call
:= Make_Procedure_Call_Statement
(Eloc
,
10343 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Eloc
));
10344 Insert_Before
(First
(Statements
(Handled_Statement_Sequence
(
10345 Accept_Statement
(Alt
)))), Call
);
10350 Make_Defining_Identifier
(Eloc
,
10351 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10353 if Comes_From_Source
(Alt
) then
10354 Set_Debug_Info_Needed
(PB_Ent
);
10358 Make_Subprogram_Body
(Eloc
,
10360 Make_Procedure_Specification
(Eloc
,
10361 Defining_Unit_Name
=> PB_Ent
),
10362 Declarations
=> Declarations
(Acc_Stm
),
10363 Handled_Statement_Sequence
=>
10364 Build_Accept_Body
(Accept_Statement
(Alt
)));
10366 -- During the analysis of the body of the accept statement, any
10367 -- zero cost exception handler records were collected in the
10368 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10369 -- This is where we move them to where they belong, namely the
10370 -- newly created procedure.
10372 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10373 Append
(Proc_Body
, Body_List
);
10376 Null_Body
:= New_Reference_To
(Standard_True
, Eloc
);
10378 -- if accept statement has declarations, insert above, given that
10379 -- we are not creating a body for the accept.
10381 if Present
(Declarations
(Acc_Stm
)) then
10382 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10386 Append_To
(Accept_List
,
10387 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10389 Num_Accept
:= Num_Accept
+ 1;
10392 ----------------------------
10393 -- Make_And_Declare_Label --
10394 ----------------------------
10396 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10400 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10402 Make_Label
(Loc
, Lab_Id
);
10405 Make_Implicit_Label_Declaration
(Loc
,
10406 Defining_Identifier
=>
10407 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10408 Label_Construct
=> Lab
));
10411 end Make_And_Declare_Label
;
10413 ----------------------
10414 -- Make_Select_Call --
10415 ----------------------
10417 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10418 Params
: constant List_Id
:= New_List
;
10422 Make_Attribute_Reference
(Loc
,
10423 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10424 Attribute_Name
=> Name_Unchecked_Access
),
10426 Append
(Select_Mode
, Params
);
10427 Append
(New_Reference_To
(Ann
, Loc
), Params
);
10428 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
10431 Make_Procedure_Call_Statement
(Loc
,
10432 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
10433 Parameter_Associations
=> Params
);
10434 end Make_Select_Call
;
10436 --------------------------------
10437 -- Process_Accept_Alternative --
10438 --------------------------------
10440 procedure Process_Accept_Alternative
10445 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10446 Alt_Stats
: List_Id
;
10449 Adjust_Condition
(Condition
(Alt
));
10451 -- Accept with body
10453 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10456 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10459 (Defining_Unit_Name
(Specification
(Proc
)),
10462 -- Accept with no body (followed by trailing statements)
10465 Alt_Stats
:= Empty_List
;
10468 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10470 -- After the call, if any, branch to trailing statements, if any.
10471 -- We create a label for each, as well as the corresponding label
10474 if not Is_Empty_List
(Statements
(Alt
)) then
10475 Lab
:= Make_And_Declare_Label
(Index
);
10476 Append
(Lab
, Trailing_List
);
10477 Append_List
(Statements
(Alt
), Trailing_List
);
10478 Append_To
(Trailing_List
,
10479 Make_Goto_Statement
(Loc
,
10480 Name
=> New_Copy
(Identifier
(End_Lab
))));
10486 Append_To
(Alt_Stats
,
10487 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10489 Append_To
(Alt_List
,
10490 Make_Case_Statement_Alternative
(Loc
,
10491 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10492 Statements
=> Alt_Stats
));
10493 end Process_Accept_Alternative
;
10495 -------------------------------
10496 -- Process_Delay_Alternative --
10497 -------------------------------
10499 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10500 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10502 Delay_Alt
: List_Id
;
10505 -- Deal with C/Fortran boolean as delay condition
10507 Adjust_Condition
(Condition
(Alt
));
10509 -- Determine the smallest specified delay
10511 -- for each delay alternative generate:
10513 -- if guard-expression then
10514 -- Delay_Val := delay-expression;
10515 -- Guard_Open := True;
10516 -- if Delay_Val < Delay_Min then
10517 -- Delay_Min := Delay_Val;
10518 -- Delay_Index := Index;
10522 -- The enclosing if-statement is omitted if there is no guard
10524 if Delay_Count
= 1 or else First_Delay
then
10525 First_Delay
:= False;
10527 Delay_Alt
:= New_List
(
10528 Make_Assignment_Statement
(Loc
,
10529 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10530 Expression
=> Expression
(Delay_Statement
(Alt
))));
10532 if Delay_Count
> 1 then
10533 Append_To
(Delay_Alt
,
10534 Make_Assignment_Statement
(Loc
,
10535 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10536 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10540 Delay_Alt
:= New_List
(
10541 Make_Assignment_Statement
(Loc
,
10542 Name
=> New_Reference_To
(Delay_Val
, Loc
),
10543 Expression
=> Expression
(Delay_Statement
(Alt
))));
10545 if Time_Type
= Standard_Duration
then
10548 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
10549 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
10552 -- The scope of the time type must define a comparison
10553 -- operator. The scope itself may not be visible, so we
10554 -- construct a node with entity information to insure that
10555 -- semantic analysis can find the proper operator.
10558 Make_Function_Call
(Loc
,
10559 Name
=> Make_Selected_Component
(Loc
,
10561 New_Reference_To
(Scope
(Time_Type
), Loc
),
10563 Make_Operator_Symbol
(Loc
,
10564 Chars
=> Name_Op_Lt
,
10565 Strval
=> No_String
)),
10566 Parameter_Associations
=>
10568 New_Reference_To
(Delay_Val
, Loc
),
10569 New_Reference_To
(Delay_Min
, Loc
)));
10571 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10574 Append_To
(Delay_Alt
,
10575 Make_Implicit_If_Statement
(N
,
10577 Then_Statements
=> New_List
(
10578 Make_Assignment_Statement
(Loc
,
10579 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10580 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
10582 Make_Assignment_Statement
(Loc
,
10583 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10584 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10587 if Check_Guard
then
10588 Append_To
(Delay_Alt
,
10589 Make_Assignment_Statement
(Loc
,
10590 Name
=> New_Reference_To
(Guard_Open
, Loc
),
10591 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
10594 if Present
(Condition
(Alt
)) then
10595 Delay_Alt
:= New_List
(
10596 Make_Implicit_If_Statement
(N
,
10597 Condition
=> Condition
(Alt
),
10598 Then_Statements
=> Delay_Alt
));
10601 Append_List
(Delay_Alt
, Delay_List
);
10603 Ensure_Statement_Present
(Dloc
, Alt
);
10605 -- If the delay alternative has a statement part, add choice to the
10606 -- case statements for delays.
10608 if not Is_Empty_List
(Statements
(Alt
)) then
10610 if Delay_Count
= 1 then
10611 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10614 Append_To
(Delay_Alt_List
,
10615 Make_Case_Statement_Alternative
(Loc
,
10616 Discrete_Choices
=> New_List
(
10617 Make_Integer_Literal
(Loc
, Index
)),
10618 Statements
=> Statements
(Alt
)));
10621 elsif Delay_Count
= 1 then
10623 -- If the single delay has no trailing statements, add a branch
10624 -- to the exit label to the selective wait.
10626 Delay_Alt_List
:= New_List
(
10627 Make_Goto_Statement
(Loc
,
10628 Name
=> New_Copy
(Identifier
(End_Lab
))));
10631 end Process_Delay_Alternative
;
10633 -- Start of processing for Expand_N_Selective_Accept
10636 Process_Statements_For_Controlled_Objects
(N
);
10638 -- First insert some declarations before the select. The first is:
10642 -- This variable holds the parameters passed to the accept body. This
10643 -- declaration has already been inserted by the time we get here by
10644 -- a call to Expand_Accept_Declarations made from the semantics when
10645 -- processing the first accept statement contained in the select. We
10646 -- can find this entity as Accept_Address (E), where E is any of the
10647 -- entries references by contained accept statements.
10649 -- The first step is to scan the list of Selective_Accept_Statements
10650 -- to find this entity, and also count the number of accepts, and
10651 -- determine if terminated, delay or else is present:
10655 Alt
:= First
(Alts
);
10656 while Present
(Alt
) loop
10657 Process_Statements_For_Controlled_Objects
(Alt
);
10659 if Nkind
(Alt
) = N_Accept_Alternative
then
10662 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10663 Delay_Count
:= Delay_Count
+ 1;
10665 -- If the delays are relative delays, the delay expressions have
10666 -- type Standard_Duration. Otherwise they must have some time type
10667 -- recognized by GNAT.
10669 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10670 Time_Type
:= Standard_Duration
;
10672 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10674 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10675 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10680 "& is not a time type (RM 9.6(6))",
10681 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10682 Time_Type
:= Standard_Duration
;
10683 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10687 if No
(Condition
(Alt
)) then
10689 -- This guard will always be open
10691 Check_Guard
:= False;
10694 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10695 Adjust_Condition
(Condition
(Alt
));
10696 Terminate_Alt
:= Alt
;
10699 Num_Alts
:= Num_Alts
+ 1;
10703 Else_Present
:= Present
(Else_Statements
(N
));
10705 -- At the same time (see procedure Add_Accept) we build the accept list:
10707 -- Qnn : Accept_List (1 .. num-select) := (
10708 -- (null-body, entry-index),
10709 -- (null-body, entry-index),
10711 -- (null_body, entry-index));
10713 -- In the above declaration, null-body is True if the corresponding
10714 -- accept has no body, and false otherwise. The entry is either the
10715 -- entry index expression if there is no guard, or if a guard is
10716 -- present, then an if expression of the form:
10718 -- (if guard then entry-index else Null_Task_Entry)
10720 -- If a guard is statically known to be false, the entry can simply
10721 -- be omitted from the accept list.
10724 Make_Object_Declaration
(Loc
,
10725 Defining_Identifier
=> Qnam
,
10726 Object_Definition
=> New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10727 Aliased_Present
=> True,
10729 Make_Qualified_Expression
(Loc
,
10731 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10733 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10735 -- Then we declare the variable that holds the index for the accept
10736 -- that will be selected for service:
10738 -- Xnn : Select_Index;
10741 Make_Object_Declaration
(Loc
,
10742 Defining_Identifier
=> Xnam
,
10743 Object_Definition
=>
10744 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
10746 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)));
10748 -- After this follow procedure declarations for each accept body
10750 -- procedure Pnn is
10755 -- where the ... are statements from the corresponding procedure body.
10756 -- No parameters are involved, since the parameters are passed via Ann
10757 -- and the parameter references have already been expanded to be direct
10758 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10759 -- any embedded tasking statements (which would normally be illegal in
10760 -- procedures), have been converted to calls to the tasking runtime so
10761 -- there is no problem in putting them into procedures.
10763 -- The original accept statement has been expanded into a block in
10764 -- the same fashion as for simple accepts (see Build_Accept_Body).
10766 -- Note: we don't really need to build these procedures for the case
10767 -- where no delay statement is present, but it is just as easy to
10768 -- build them unconditionally, and not significantly inefficient,
10769 -- since if they are short they will be inlined anyway.
10771 -- The procedure declarations have been assembled in Body_List
10773 -- If delays are present, we must compute the required delay.
10774 -- We first generate the declarations:
10776 -- Delay_Index : Boolean := 0;
10777 -- Delay_Min : Some_Time_Type.Time;
10778 -- Delay_Val : Some_Time_Type.Time;
10780 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10781 -- active delay that is actually chosen as the basis for the possible
10782 -- delay if an immediate rendez-vous is not possible.
10784 -- In the most common case there is a single delay statement, and this
10785 -- is handled specially.
10787 if Delay_Count
> 0 then
10789 -- Generate the required declarations
10792 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
10794 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
10796 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
10799 Make_Object_Declaration
(Loc
,
10800 Defining_Identifier
=> Delay_Val
,
10801 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
10804 Make_Object_Declaration
(Loc
,
10805 Defining_Identifier
=> Delay_Index
,
10806 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
10807 Expression
=> Make_Integer_Literal
(Loc
, 0)));
10810 Make_Object_Declaration
(Loc
,
10811 Defining_Identifier
=> Delay_Min
,
10812 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
10814 Unchecked_Convert_To
(Time_Type
,
10815 Make_Attribute_Reference
(Loc
,
10817 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
10818 Attribute_Name
=> Name_Last
))));
10820 -- Create Duration and Delay_Mode objects used for passing a delay
10823 D
:= Make_Temporary
(Loc
, 'D');
10824 M
:= Make_Temporary
(Loc
, 'M');
10830 -- Note that these values are defined in s-osprim.ads and must
10831 -- be kept in sync:
10833 -- Relative : constant := 0;
10834 -- Absolute_Calendar : constant := 1;
10835 -- Absolute_RT : constant := 2;
10837 if Time_Type
= Standard_Duration
then
10838 Discr
:= Make_Integer_Literal
(Loc
, 0);
10840 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10841 Discr
:= Make_Integer_Literal
(Loc
, 1);
10845 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
10846 Discr
:= Make_Integer_Literal
(Loc
, 2);
10850 Make_Object_Declaration
(Loc
,
10851 Defining_Identifier
=> D
,
10852 Object_Definition
=>
10853 New_Reference_To
(Standard_Duration
, Loc
)));
10856 Make_Object_Declaration
(Loc
,
10857 Defining_Identifier
=> M
,
10858 Object_Definition
=>
10859 New_Reference_To
(Standard_Integer
, Loc
),
10860 Expression
=> Discr
));
10863 if Check_Guard
then
10865 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
10868 Make_Object_Declaration
(Loc
,
10869 Defining_Identifier
=> Guard_Open
,
10870 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
10871 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
10874 -- Delay_Count is zero, don't need M and D set (suppress warning)
10881 if Present
(Terminate_Alt
) then
10883 -- If the terminate alternative guard is False, use
10884 -- Simple_Mode; otherwise use Terminate_Mode.
10886 if Present
(Condition
(Terminate_Alt
)) then
10887 Select_Mode
:= Make_If_Expression
(Loc
,
10888 New_List
(Condition
(Terminate_Alt
),
10889 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
10890 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
10892 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
10895 elsif Else_Present
or Delay_Count
> 0 then
10896 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
10899 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
10902 Select_Call
:= Make_Select_Call
(Select_Mode
);
10903 Append
(Select_Call
, Stats
);
10905 -- Now generate code to act on the result. There is an entry
10906 -- in this case for each accept statement with a non-null body,
10907 -- followed by a branch to the statements that follow the Accept.
10908 -- In the absence of delay alternatives, we generate:
10911 -- when No_Rendezvous => -- omitted if simple mode
10926 -- Lab0: Else_Statements;
10929 -- Lab1: Trailing_Statements1;
10932 -- Lab2: Trailing_Statements2;
10937 -- Generate label for common exit
10939 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
10941 -- First entry is the default case, when no rendezvous is possible
10943 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
10945 if Else_Present
then
10947 -- If no rendezvous is possible, the else part is executed
10949 Lab
:= Make_And_Declare_Label
(0);
10950 Alt_Stats
:= New_List
(
10951 Make_Goto_Statement
(Loc
,
10952 Name
=> New_Copy
(Identifier
(Lab
))));
10954 Append
(Lab
, Trailing_List
);
10955 Append_List
(Else_Statements
(N
), Trailing_List
);
10956 Append_To
(Trailing_List
,
10957 Make_Goto_Statement
(Loc
,
10958 Name
=> New_Copy
(Identifier
(End_Lab
))));
10960 Alt_Stats
:= New_List
(
10961 Make_Goto_Statement
(Loc
,
10962 Name
=> New_Copy
(Identifier
(End_Lab
))));
10965 Append_To
(Alt_List
,
10966 Make_Case_Statement_Alternative
(Loc
,
10967 Discrete_Choices
=> Choices
,
10968 Statements
=> Alt_Stats
));
10970 -- We make use of the fact that Accept_Index is an integer type, and
10971 -- generate successive literals for entries for each accept. Only those
10972 -- for which there is a body or trailing statements get a case entry.
10974 Alt
:= First
(Select_Alternatives
(N
));
10975 Proc
:= First
(Body_List
);
10976 while Present
(Alt
) loop
10978 if Nkind
(Alt
) = N_Accept_Alternative
then
10979 Process_Accept_Alternative
(Alt
, Index
, Proc
);
10980 Index
:= Index
+ 1;
10983 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
10988 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10989 Process_Delay_Alternative
(Alt
, Delay_Num
);
10990 Delay_Num
:= Delay_Num
+ 1;
10996 -- An others choice is always added to the main case, as well
10997 -- as the delay case (to satisfy the compiler).
10999 Append_To
(Alt_List
,
11000 Make_Case_Statement_Alternative
(Loc
,
11001 Discrete_Choices
=>
11002 New_List
(Make_Others_Choice
(Loc
)),
11004 New_List
(Make_Goto_Statement
(Loc
,
11005 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11007 Accept_Case
:= New_List
(
11008 Make_Case_Statement
(Loc
,
11009 Expression
=> New_Reference_To
(Xnam
, Loc
),
11010 Alternatives
=> Alt_List
));
11012 Append_List
(Trailing_List
, Accept_Case
);
11013 Append_List
(Body_List
, Decls
);
11015 -- Construct case statement for trailing statements of delay
11016 -- alternatives, if there are several of them.
11018 if Delay_Count
> 1 then
11019 Append_To
(Delay_Alt_List
,
11020 Make_Case_Statement_Alternative
(Loc
,
11021 Discrete_Choices
=>
11022 New_List
(Make_Others_Choice
(Loc
)),
11024 New_List
(Make_Null_Statement
(Loc
))));
11026 Delay_Case
:= New_List
(
11027 Make_Case_Statement
(Loc
,
11028 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
11029 Alternatives
=> Delay_Alt_List
));
11031 Delay_Case
:= Delay_Alt_List
;
11034 -- If there are no delay alternatives, we append the case statement
11035 -- to the statement list.
11037 if Delay_Count
= 0 then
11038 Append_List
(Accept_Case
, Stats
);
11040 -- Delay alternatives present
11043 -- If delay alternatives are present we generate:
11045 -- find minimum delay.
11046 -- DX := minimum delay;
11047 -- M := <delay mode>;
11048 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11051 -- if X = No_Rendezvous then
11052 -- case statement for delay statements.
11054 -- case statement for accept alternatives.
11065 -- The type of the delay expression is known to be legal
11067 if Time_Type
= Standard_Duration
then
11068 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
11070 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11071 Conv
:= Make_Function_Call
(Loc
,
11072 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
11073 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
11077 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11079 Conv
:= Make_Function_Call
(Loc
,
11080 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
11081 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
11084 Stmt
:= Make_Assignment_Statement
(Loc
,
11085 Name
=> New_Reference_To
(D
, Loc
),
11086 Expression
=> Conv
);
11088 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11090 Parms
:= Parameter_Associations
(Select_Call
);
11091 Parm
:= First
(Parms
);
11093 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11097 pragma Assert
(Present
(Parm
));
11098 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
11101 -- Prepare two new parameters of Duration and Delay_Mode type
11102 -- which represent the value and the mode of the minimum delay.
11105 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
11106 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
11108 -- Create a call to RTS
11110 Rewrite
(Select_Call
,
11111 Make_Procedure_Call_Statement
(Loc
,
11112 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11113 Parameter_Associations
=> Parms
));
11115 -- This new call should follow the calculation of the minimum
11118 Insert_List_Before
(Select_Call
, Delay_List
);
11120 if Check_Guard
then
11122 Make_Implicit_If_Statement
(N
,
11123 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
11124 Then_Statements
=> New_List
(
11125 New_Copy_Tree
(Stmt
),
11126 New_Copy_Tree
(Select_Call
)),
11127 Else_Statements
=> Accept_Or_Raise
);
11128 Rewrite
(Select_Call
, Stmt
);
11130 Insert_Before
(Select_Call
, Stmt
);
11134 Make_Implicit_If_Statement
(N
,
11135 Condition
=> Make_Op_Eq
(Loc
,
11136 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
11138 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
11140 Then_Statements
=> Delay_Case
,
11141 Else_Statements
=> Accept_Case
);
11143 Append
(Cases
, Stats
);
11146 Append
(End_Lab
, Stats
);
11148 -- Replace accept statement with appropriate block
11151 Make_Block_Statement
(Loc
,
11152 Declarations
=> Decls
,
11153 Handled_Statement_Sequence
=>
11154 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11157 -- Note: have to worry more about abort deferral in above code ???
11159 -- Final step is to unstack the Accept_Address entries for all accept
11160 -- statements appearing in accept alternatives in the select statement
11162 Alt
:= First
(Alts
);
11163 while Present
(Alt
) loop
11164 if Nkind
(Alt
) = N_Accept_Alternative
then
11165 Remove_Last_Elmt
(Accept_Address
11166 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11171 end Expand_N_Selective_Accept
;
11173 --------------------------------------
11174 -- Expand_N_Single_Task_Declaration --
11175 --------------------------------------
11177 -- Single task declarations should never be present after semantic
11178 -- analysis, since we expect them to be replaced by a declaration of an
11179 -- anonymous task type, followed by a declaration of the task object. We
11180 -- include this routine to make sure that is happening!
11182 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11184 raise Program_Error
;
11185 end Expand_N_Single_Task_Declaration
;
11187 ------------------------
11188 -- Expand_N_Task_Body --
11189 ------------------------
11191 -- Given a task body
11193 -- task body tname is
11199 -- This expansion routine converts it into a procedure and sets the
11200 -- elaboration flag for the procedure to true, to represent the fact
11201 -- that the task body is now elaborated:
11203 -- procedure tnameB (_Task : access tnameV) is
11204 -- discriminal : dtype renames _Task.discriminant;
11206 -- procedure _clean is
11208 -- Abort_Defer.all;
11210 -- Abort_Undefer.all;
11215 -- Abort_Undefer.all;
11217 -- System.Task_Stages.Complete_Activation;
11225 -- In addition, if the task body is an activator, then a call to activate
11226 -- tasks is added at the start of the statements, before the call to
11227 -- Complete_Activation, and if in addition the task is a master then it
11228 -- must be established as a master. These calls are inserted and analyzed
11229 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11232 -- There is one discriminal declaration line generated for each
11233 -- discriminant that is present to provide an easy reference point for
11234 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11236 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11237 -- task body procedures have a profile (Arg : System.Address). That is
11238 -- needed because GNARLI has to use the same access-to-subprogram type
11239 -- for all task types. We depend here on knowing that in GNAT, passing
11240 -- an address argument by value is identical to passing a record value
11241 -- by access (in either case a single pointer is passed), so even though
11242 -- this procedure has the wrong profile. In fact it's all OK, since the
11243 -- callings sequence is identical.
11245 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11246 Loc
: constant Source_Ptr
:= Sloc
(N
);
11247 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11251 Insert_Nod
: Node_Id
;
11252 -- Used to determine the proper location of wrapper body insertions
11255 -- Add renaming declarations for discriminals and a declaration for the
11256 -- entry family index (if applicable).
11258 Install_Private_Data_Declarations
11259 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11261 -- Add a call to Abort_Undefer at the very beginning of the task
11262 -- body since this body is called with abort still deferred.
11264 if Abort_Allowed
then
11265 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11267 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11271 -- The statement part has already been protected with an at_end and
11272 -- cleanup actions. The call to Complete_Activation must be placed
11273 -- at the head of the sequence of statements of that block. The
11274 -- declarations have been merged in this sequence of statements but
11275 -- the first real statement is accessible from the First_Real_Statement
11276 -- field (which was set for exactly this purpose).
11278 if Restricted_Profile
then
11279 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11281 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11285 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11289 Make_Subprogram_Body
(Loc
,
11290 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11291 Declarations
=> Declarations
(N
),
11292 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11294 -- If the task contains generic instantiations, cleanup actions are
11295 -- delayed until after instantiation. Transfer the activation chain to
11296 -- the subprogram, to insure that the activation call is properly
11297 -- generated. It the task body contains inner tasks, indicate that the
11298 -- subprogram is a task master.
11300 if Delay_Cleanups
(Ttyp
) then
11301 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11302 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11305 Rewrite
(N
, New_N
);
11308 -- Set elaboration flag immediately after task body. If the body is a
11309 -- subunit, the flag is set in the declarative part containing the stub.
11311 if Nkind
(Parent
(N
)) /= N_Subunit
then
11313 Make_Assignment_Statement
(Loc
,
11315 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11316 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
11319 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11320 -- the task body. At this point all wrapper specs have been created,
11321 -- frozen and included in the dispatch table for the task type.
11323 if Ada_Version
>= Ada_2005
then
11324 if Nkind
(Parent
(N
)) = N_Subunit
then
11325 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11330 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11332 end Expand_N_Task_Body
;
11334 ------------------------------------
11335 -- Expand_N_Task_Type_Declaration --
11336 ------------------------------------
11338 -- We have several things to do. First we must create a Boolean flag used
11339 -- to mark if the body is elaborated yet. This variable gets set to True
11340 -- when the body of the task is elaborated (we can't rely on the normal
11341 -- ABE mechanism for the task body, since we need to pass an access to
11342 -- this elaboration boolean to the runtime routines).
11344 -- taskE : aliased Boolean := False;
11346 -- Next a variable is declared to hold the task stack size (either the
11347 -- default : Unspecified_Size, or a value that is set by a pragma
11348 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11349 -- the variable is initialized with this value:
11351 -- taskZ : Size_Type := Unspecified_Size;
11353 -- taskZ : Size_Type := Size_Type (size_expression);
11355 -- Note: No variable is needed to hold the task relative deadline since
11356 -- its value would never be static because the parameter is of a private
11357 -- type (Ada.Real_Time.Time_Span).
11359 -- Next we create a corresponding record type declaration used to represent
11360 -- values of this task. The general form of this type declaration is
11362 -- type taskV (discriminants) is record
11363 -- _Task_Id : Task_Id;
11364 -- entry_family : array (bounds) of Void;
11365 -- _Priority : Integer := priority_expression;
11366 -- _Size : Size_Type := size_expression;
11367 -- _Task_Info : Task_Info_Type := task_info_expression;
11368 -- _CPU : Integer := cpu_range_expression;
11369 -- _Relative_Deadline : Time_Span := time_span_expression;
11370 -- _Domain : Dispatching_Domain := dd_expression;
11373 -- The discriminants are present only if the corresponding task type has
11374 -- discriminants, and they exactly mirror the task type discriminants.
11376 -- The Id field is always present. It contains the Task_Id value, as set by
11377 -- the call to Create_Task. Note that although the task is limited, the
11378 -- task value record type is not limited, so there is no problem in passing
11379 -- this field as an out parameter to Create_Task.
11381 -- One entry_family component is present for each entry family in the task
11382 -- definition. The bounds correspond to the bounds of the entry family
11383 -- (which may depend on discriminants). The element type is void, since we
11384 -- only need the bounds information for determining the entry index. Note
11385 -- that the use of an anonymous array would normally be illegal in this
11386 -- context, but this is a parser check, and the semantics is quite prepared
11387 -- to handle such a case.
11389 -- The _Size field is present only if a Storage_Size pragma appears in the
11390 -- task definition. The expression captures the argument that was present
11391 -- in the pragma, and is used to override the task stack size otherwise
11392 -- associated with the task type.
11394 -- The _Priority field is present only if the task entity has a Priority or
11395 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11396 -- definition clause). It will be filled at the freeze point, when the
11397 -- record init proc is built, to capture the expression of the rep item
11398 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11399 -- here since aspect evaluations are delayed till the freeze point.
11401 -- The _Task_Info field is present only if a Task_Info pragma appears in
11402 -- the task definition. The expression captures the argument that was
11403 -- present in the pragma, and is used to provide the Task_Image parameter
11404 -- to the call to Create_Task.
11406 -- The _CPU field is present only if the task entity has a CPU rep item
11407 -- (pragma, aspect specification or attribute definition clause). It will
11408 -- be filled at the freeze point, when the record init proc is built, to
11409 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11410 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11411 -- are delayed till the freeze point.
11413 -- The _Relative_Deadline field is present only if a Relative_Deadline
11414 -- pragma appears in the task definition. The expression captures the
11415 -- argument that was present in the pragma, and is used to provide the
11416 -- Relative_Deadline parameter to the call to Create_Task.
11418 -- The _Domain field is present only if the task entity has a
11419 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11420 -- definition clause). It will be filled at the freeze point, when the
11421 -- record init proc is built, to capture the expression of the rep item
11422 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11423 -- here since aspect evaluations are delayed till the freeze point.
11425 -- When a task is declared, an instance of the task value record is
11426 -- created. The elaboration of this declaration creates the correct bounds
11427 -- for the entry families, and also evaluates the size, priority, and
11428 -- task_Info expressions if needed. The initialization routine for the task
11429 -- type itself then calls Create_Task with appropriate parameters to
11430 -- initialize the value of the Task_Id field.
11432 -- Note: the address of this record is passed as the "Discriminants"
11433 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11434 -- body procedure, it does not matter that it does not quite match the
11435 -- GNARLI model of what is being passed (the record contains more than just
11436 -- the discriminants, but the discriminants can be found from the record
11439 -- The Entity_Id for this created record type is placed in the
11440 -- Corresponding_Record_Type field of the associated task type entity.
11442 -- Next we create a procedure specification for the task body procedure:
11444 -- procedure taskB (_Task : access taskV);
11446 -- Note that this must come after the record type declaration, since
11447 -- the spec refers to this type. It turns out that the initialization
11448 -- procedure for the value type references the task body spec, but that's
11449 -- fine, since it won't be generated till the freeze point for the type,
11450 -- which is certainly after the task body spec declaration.
11452 -- Finally, we set the task index value field of the entry attribute in
11453 -- the case of a simple entry.
11455 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11456 Loc
: constant Source_Ptr
:= Sloc
(N
);
11457 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11458 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11459 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11460 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11462 Body_Decl
: Node_Id
;
11464 Decl_Stack
: Node_Id
;
11465 Elab_Decl
: Node_Id
;
11466 Ent_Stack
: Entity_Id
;
11467 Proc_Spec
: Node_Id
;
11468 Rec_Decl
: Node_Id
;
11469 Rec_Ent
: Entity_Id
;
11470 Size_Decl
: Entity_Id
;
11471 Task_Size
: Node_Id
;
11473 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11474 -- Searches the task definition T for the first occurrence of the pragma
11475 -- Relative Deadline. The caller has ensured that the pragma is present
11476 -- in the task definition. Note that this routine cannot be implemented
11477 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11478 -- not chained because their expansion into a procedure call statement
11479 -- would cause a break in the chain.
11481 ----------------------------------
11482 -- Get_Relative_Deadline_Pragma --
11483 ----------------------------------
11485 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11489 N
:= First
(Visible_Declarations
(T
));
11490 while Present
(N
) loop
11491 if Nkind
(N
) = N_Pragma
11492 and then Pragma_Name
(N
) = Name_Relative_Deadline
11500 N
:= First
(Private_Declarations
(T
));
11501 while Present
(N
) loop
11502 if Nkind
(N
) = N_Pragma
11503 and then Pragma_Name
(N
) = Name_Relative_Deadline
11511 raise Program_Error
;
11512 end Get_Relative_Deadline_Pragma
;
11514 -- Start of processing for Expand_N_Task_Type_Declaration
11517 -- If already expanded, nothing to do
11519 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11523 -- Here we will do the expansion
11525 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11527 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11528 Cdecls
:= Component_Items
(Component_List
11529 (Type_Definition
(Rec_Decl
)));
11531 Qualify_Entity_Names
(N
);
11533 -- First create the elaboration variable
11536 Make_Object_Declaration
(Loc
,
11537 Defining_Identifier
=>
11538 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11539 Chars
=> New_External_Name
(Tasknm
, 'E')),
11540 Aliased_Present
=> True,
11541 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
11542 Expression
=> New_Reference_To
(Standard_False
, Loc
));
11544 Insert_After
(N
, Elab_Decl
);
11546 -- Next create the declaration of the size variable (tasknmZ)
11548 Set_Storage_Size_Variable
(Tasktyp
,
11549 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11550 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11552 if Present
(Taskdef
)
11553 and then Has_Storage_Size_Pragma
(Taskdef
)
11555 Is_Static_Expression
11557 (First
(Pragma_Argument_Associations
11558 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11561 Make_Object_Declaration
(Loc
,
11562 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11563 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11565 Convert_To
(RTE
(RE_Size_Type
),
11567 (Expression
(First
(Pragma_Argument_Associations
11569 (TaskId
, Name_Storage_Size
)))))));
11573 Make_Object_Declaration
(Loc
,
11574 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11575 Object_Definition
=>
11576 New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11578 New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
11581 Insert_After
(Elab_Decl
, Size_Decl
);
11583 -- Next build the rest of the corresponding record declaration. This is
11584 -- done last, since the corresponding record initialization procedure
11585 -- will reference the previously created entities.
11587 -- Fill in the component declarations -- first the _Task_Id field
11590 Make_Component_Declaration
(Loc
,
11591 Defining_Identifier
=>
11592 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11593 Component_Definition
=>
11594 Make_Component_Definition
(Loc
,
11595 Aliased_Present
=> False,
11596 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
11599 -- Declare static ATCB (that is, created by the expander) if we are
11600 -- using the Restricted run time.
11602 if Restricted_Profile
then
11604 Make_Component_Declaration
(Loc
,
11605 Defining_Identifier
=>
11606 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11608 Component_Definition
=>
11609 Make_Component_Definition
(Loc
,
11610 Aliased_Present
=> True,
11611 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11613 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11616 Make_Index_Or_Discriminant_Constraint
(Loc
,
11618 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11622 -- Declare static stack (that is, created by the expander) if we are
11623 -- using the Restricted run time on a bare board configuration.
11625 if Restricted_Profile
11626 and then Preallocated_Stacks_On_Target
11628 -- First we need to extract the appropriate stack size
11630 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11632 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11634 Expr_N
: constant Node_Id
:=
11635 Expression
(First
(
11636 Pragma_Argument_Associations
(
11637 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11638 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11639 P
: constant Node_Id
:= Parent
(Expr_N
);
11642 -- The stack is defined inside the corresponding record.
11643 -- Therefore if the size of the stack is set by means of
11644 -- a discriminant, we must reference the discriminant of the
11645 -- corresponding record type.
11647 if Nkind
(Expr_N
) in N_Has_Entity
11648 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11652 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11654 Set_Parent
(Task_Size
, P
);
11655 Set_Etype
(Task_Size
, Etyp
);
11656 Set_Analyzed
(Task_Size
);
11659 Task_Size
:= Relocate_Node
(Expr_N
);
11665 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
11668 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11669 Defining_Identifier
=> Ent_Stack
,
11671 Component_Definition
=>
11672 Make_Component_Definition
(Loc
,
11673 Aliased_Present
=> True,
11674 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11676 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11679 Make_Index_Or_Discriminant_Constraint
(Loc
,
11680 Constraints
=> New_List
(Make_Range
(Loc
,
11681 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11682 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11685 Append_To
(Cdecls
, Decl_Stack
);
11687 -- The appropriate alignment for the stack is ensured by the run-time
11688 -- code in charge of task creation.
11692 -- Add components for entry families
11694 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11696 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11697 -- item is present.
11699 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
11701 Make_Component_Declaration
(Loc
,
11702 Defining_Identifier
=>
11703 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11704 Component_Definition
=>
11705 Make_Component_Definition
(Loc
,
11706 Aliased_Present
=> False,
11707 Subtype_Indication
=>
11708 New_Reference_To
(Standard_Integer
, Loc
))));
11711 -- Add the _Size component if a Storage_Size pragma is present
11713 if Present
(Taskdef
)
11714 and then Has_Storage_Size_Pragma
(Taskdef
)
11717 Make_Component_Declaration
(Loc
,
11718 Defining_Identifier
=>
11719 Make_Defining_Identifier
(Loc
, Name_uSize
),
11721 Component_Definition
=>
11722 Make_Component_Definition
(Loc
,
11723 Aliased_Present
=> False,
11724 Subtype_Indication
=>
11725 New_Reference_To
(RTE
(RE_Size_Type
), Loc
)),
11728 Convert_To
(RTE
(RE_Size_Type
),
11730 Expression
(First
(
11731 Pragma_Argument_Associations
(
11732 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
11735 -- Add the _Task_Info component if a Task_Info pragma is present
11737 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
11739 Make_Component_Declaration
(Loc
,
11740 Defining_Identifier
=>
11741 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11743 Component_Definition
=>
11744 Make_Component_Definition
(Loc
,
11745 Aliased_Present
=> False,
11746 Subtype_Indication
=>
11747 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
11749 Expression
=> New_Copy
(
11750 Expression
(First
(
11751 Pragma_Argument_Associations
(
11753 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
11756 -- Add the _CPU component if a CPU rep item is present
11758 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
11760 Make_Component_Declaration
(Loc
,
11761 Defining_Identifier
=>
11762 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11764 Component_Definition
=>
11765 Make_Component_Definition
(Loc
,
11766 Aliased_Present
=> False,
11767 Subtype_Indication
=>
11768 New_Reference_To
(RTE
(RE_CPU_Range
), Loc
))));
11771 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11772 -- present. If we are using a restricted run time this component will
11773 -- not be added (deadlines are not allowed by the Ravenscar profile).
11775 if not Restricted_Profile
11776 and then Present
(Taskdef
)
11777 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11780 Make_Component_Declaration
(Loc
,
11781 Defining_Identifier
=>
11782 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11784 Component_Definition
=>
11785 Make_Component_Definition
(Loc
,
11786 Aliased_Present
=> False,
11787 Subtype_Indication
=>
11788 New_Reference_To
(RTE
(RE_Time_Span
), Loc
)),
11791 Convert_To
(RTE
(RE_Time_Span
),
11793 Expression
(First
(
11794 Pragma_Argument_Associations
(
11795 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
11798 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
11799 -- item is present. If we are using a restricted run time this component
11800 -- will not be added (dispatching domains are not allowed by the
11801 -- Ravenscar profile).
11803 if not Restricted_Profile
11806 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
11809 Make_Component_Declaration
(Loc
,
11810 Defining_Identifier
=>
11811 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
11813 Component_Definition
=>
11814 Make_Component_Definition
(Loc
,
11815 Aliased_Present
=> False,
11816 Subtype_Indication
=>
11818 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
11821 Insert_After
(Size_Decl
, Rec_Decl
);
11823 -- Analyze the record declaration immediately after construction,
11824 -- because the initialization procedure is needed for single task
11825 -- declarations before the next entity is analyzed.
11827 Analyze
(Rec_Decl
);
11829 -- Create the declaration of the task body procedure
11831 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
11833 Make_Subprogram_Declaration
(Loc
,
11834 Specification
=> Proc_Spec
);
11836 Insert_After
(Rec_Decl
, Body_Decl
);
11838 -- The subprogram does not comes from source, so we have to indicate the
11839 -- need for debugging information explicitly.
11841 if Comes_From_Source
(Original_Node
(N
)) then
11842 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
11845 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11846 -- the corresponding record has been frozen.
11848 if Ada_Version
>= Ada_2005
then
11849 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
11852 -- Ada 2005 (AI-345): We must defer freezing to allow further
11853 -- declaration of primitive subprograms covering task interfaces
11855 if Ada_Version
<= Ada_95
then
11857 -- Now we can freeze the corresponding record. This needs manually
11858 -- freezing, since it is really part of the task type, and the task
11859 -- type is frozen at this stage. We of course need the initialization
11860 -- procedure for this corresponding record type and we won't get it
11861 -- in time if we don't freeze now.
11864 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
11866 if Is_Non_Empty_List
(L
) then
11867 Insert_List_After
(Body_Decl
, L
);
11872 -- Complete the expansion of access types to the current task type, if
11873 -- any were declared.
11875 Expand_Previous_Access_Type
(Tasktyp
);
11877 -- Create wrappers for entries that have pre/postconditions
11883 Ent
:= First_Entity
(Tasktyp
);
11884 while Present
(Ent
) loop
11885 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
11886 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
11888 Build_PPC_Wrapper
(Ent
, N
);
11894 end Expand_N_Task_Type_Declaration
;
11896 -------------------------------
11897 -- Expand_N_Timed_Entry_Call --
11898 -------------------------------
11900 -- A timed entry call in normal case is not implemented using ATC mechanism
11901 -- anymore for efficiency reason.
11911 -- is expanded as follows:
11913 -- 1) When T.E is a task entry_call;
11917 -- X : Task_Entry_Index := <entry index>;
11918 -- DX : Duration := To_Duration (D);
11919 -- M : Delay_Mode := <discriminant>;
11920 -- P : parms := (parm, parm, parm);
11923 -- Timed_Protected_Entry_Call
11924 -- (<acceptor-task>, X, P'Address, DX, M, B);
11932 -- 2) When T.E is a protected entry_call;
11936 -- X : Protected_Entry_Index := <entry index>;
11937 -- DX : Duration := To_Duration (D);
11938 -- M : Delay_Mode := <discriminant>;
11939 -- P : parms := (parm, parm, parm);
11942 -- Timed_Protected_Entry_Call
11943 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
11951 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
11952 -- is no delay and the triggering statements are executed. We first
11953 -- determine the kind of of the triggering call and then execute a
11954 -- synchronized operation or a direct call.
11957 -- B : Boolean := False;
11958 -- C : Ada.Tags.Prim_Op_Kind;
11959 -- DX : Duration := To_Duration (D)
11960 -- K : Ada.Tags.Tagged_Kind :=
11961 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
11962 -- M : Integer :=...;
11963 -- P : Parameters := (Param1 .. ParamN);
11967 -- if K = Ada.Tags.TK_Limited_Tagged
11968 -- or else K = Ada.Tags.TK_Tagged
11970 -- <dispatching-call>;
11975 -- Ada.Tags.Get_Offset_Index
11976 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
11978 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
11980 -- if C = POK_Protected_Entry
11981 -- or else C = POK_Task_Entry
11983 -- Param1 := P.Param1;
11985 -- ParamN := P.ParamN;
11989 -- if C = POK_Procedure
11990 -- or else C = POK_Protected_Procedure
11991 -- or else C = POK_Task_Procedure
11993 -- <dispatching-call>;
11999 -- <triggering-statements>
12001 -- <timed-statements>
12005 -- The triggering statement and the sequence of timed statements have not
12006 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12007 -- global references if within an instantiation.
12009 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12010 Loc
: constant Source_Ptr
:= Sloc
(N
);
12013 Blk_Typ
: Entity_Id
;
12015 Call_Ent
: Entity_Id
;
12016 Conc_Typ_Stmts
: List_Id
;
12018 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12021 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12023 D_Type
: Entity_Id
;
12026 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12027 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12032 Is_Disp_Select
: Boolean;
12033 Lim_Typ_Stmts
: List_Id
;
12042 B
: Entity_Id
; -- Call status flag
12043 C
: Entity_Id
; -- Call kind
12044 D
: Entity_Id
; -- Delay
12045 K
: Entity_Id
; -- Tagged kind
12046 M
: Entity_Id
; -- Delay mode
12047 P
: Entity_Id
; -- Parameter block
12048 S
: Entity_Id
; -- Primitive operation slot
12050 -- Start of processing for Expand_N_Timed_Entry_Call
12053 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12054 -- was already reported on spec, so do not attempt to expand the call.
12056 if Restriction_Active
(No_Select_Statements
) then
12060 Process_Statements_For_Controlled_Objects
(E_Alt
);
12061 Process_Statements_For_Controlled_Objects
(D_Alt
);
12063 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12065 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12066 -- may wrap them in blocks.
12068 E_Stats
:= Statements
(E_Alt
);
12069 D_Stats
:= Statements
(D_Alt
);
12071 -- The arguments in the call may require dynamic allocation, and the
12072 -- call statement may have been transformed into a block. The block
12073 -- may contain additional declarations for internal entities, and the
12074 -- original call is found by sequential search.
12076 if Nkind
(E_Call
) = N_Block_Statement
then
12077 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12078 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12079 N_Entry_Call_Statement
)
12086 Ada_Version
>= Ada_2005
12087 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12089 if Is_Disp_Select
then
12090 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12096 -- B : Boolean := False;
12098 B
:= Build_B
(Loc
, Decls
);
12101 -- C : Ada.Tags.Prim_Op_Kind;
12103 C
:= Build_C
(Loc
, Decls
);
12105 -- Because the analysis of all statements was disabled, manually
12106 -- analyze the delay statement.
12109 D_Stat
:= Original_Node
(D_Stat
);
12112 -- Build an entry call using Simple_Entry_Call
12114 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12115 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12117 Decls
:= Declarations
(E_Call
);
12118 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12127 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12130 Make_Object_Declaration
(Loc
,
12131 Defining_Identifier
=> B
,
12132 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
12135 -- Duration and mode processing
12137 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12139 -- Use the type of the delay expression (Calendar or Real_Time) to
12140 -- generate the appropriate conversion.
12142 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12143 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12144 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12146 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12147 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12149 Make_Function_Call
(Loc
,
12150 Name
=> New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
12151 Parameter_Associations
=>
12152 New_List
(New_Copy
(Expression
(D_Stat
))));
12154 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12155 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12157 Make_Function_Call
(Loc
,
12158 Name
=> New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
12159 Parameter_Associations
=>
12160 New_List
(New_Copy
(Expression
(D_Stat
))));
12163 D
:= Make_Temporary
(Loc
, 'D');
12169 Make_Object_Declaration
(Loc
,
12170 Defining_Identifier
=> D
,
12171 Object_Definition
=> New_Reference_To
(Standard_Duration
, Loc
)));
12173 M
:= Make_Temporary
(Loc
, 'M');
12176 -- M : Integer := (0 | 1 | 2);
12179 Make_Object_Declaration
(Loc
,
12180 Defining_Identifier
=> M
,
12181 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
12182 Expression
=> D_Disc
));
12184 -- Do the assignment at this stage only because the evaluation of the
12185 -- expression must not occur before (see ACVC C97302A).
12188 Make_Assignment_Statement
(Loc
,
12189 Name
=> New_Reference_To
(D
, Loc
),
12190 Expression
=> D_Conv
));
12192 -- Parameter block processing
12194 -- Manually create the parameter block for dispatching calls. In the
12195 -- case of entries, the block has already been created during the call
12196 -- to Build_Simple_Entry_Call.
12198 if Is_Disp_Select
then
12200 -- Tagged kind processing, generate:
12201 -- K : Ada.Tags.Tagged_Kind :=
12202 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12204 K
:= Build_K
(Loc
, Decls
, Obj
);
12206 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12208 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12210 -- Dispatch table slot processing, generate:
12213 S
:= Build_S
(Loc
, Decls
);
12216 -- S := Ada.Tags.Get_Offset_Index
12217 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12220 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12223 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12225 -- where Obj is the controlling formal parameter, S is the dispatch
12226 -- table slot number of the dispatching operation, P is the wrapped
12227 -- parameter block, D is the duration, M is the duration mode, C is
12228 -- the call kind and B is the call status.
12230 Params
:= New_List
;
12232 Append_To
(Params
, New_Copy_Tree
(Obj
));
12233 Append_To
(Params
, New_Reference_To
(S
, Loc
));
12235 Make_Attribute_Reference
(Loc
,
12236 Prefix
=> New_Reference_To
(P
, Loc
),
12237 Attribute_Name
=> Name_Address
));
12238 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12239 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12240 Append_To
(Params
, New_Reference_To
(C
, Loc
));
12241 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12243 Append_To
(Conc_Typ_Stmts
,
12244 Make_Procedure_Call_Statement
(Loc
,
12248 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12249 Parameter_Associations
=> Params
));
12252 -- if C = POK_Protected_Entry
12253 -- or else C = POK_Task_Entry
12255 -- Param1 := P.Param1;
12257 -- ParamN := P.ParamN;
12260 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12262 -- Generate the if statement only when the packed parameters need
12263 -- explicit assignments to their corresponding actuals.
12265 if Present
(Unpack
) then
12266 Append_To
(Conc_Typ_Stmts
,
12267 Make_Implicit_If_Statement
(N
,
12273 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12276 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12280 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12282 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
12284 Then_Statements
=> Unpack
));
12290 -- if C = POK_Procedure
12291 -- or else C = POK_Protected_Procedure
12292 -- or else C = POK_Task_Procedure
12294 -- <dispatching-call>
12298 N_Stats
:= New_List
(
12299 Make_Implicit_If_Statement
(N
,
12304 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12306 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
12312 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12314 New_Reference_To
(RTE
(
12315 RE_POK_Protected_Procedure
), Loc
)),
12318 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12321 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12323 Then_Statements
=> New_List
(E_Call
)));
12325 Append_To
(Conc_Typ_Stmts
,
12326 Make_Implicit_If_Statement
(N
,
12327 Condition
=> New_Reference_To
(B
, Loc
),
12328 Then_Statements
=> N_Stats
));
12331 -- <dispatching-call>;
12335 New_List
(New_Copy_Tree
(E_Call
),
12336 Make_Assignment_Statement
(Loc
,
12337 Name
=> New_Occurrence_Of
(B
, Loc
),
12338 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12341 -- if K = Ada.Tags.TK_Limited_Tagged
12342 -- or else K = Ada.Tags.TK_Tagged
12350 Make_Implicit_If_Statement
(N
,
12351 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12352 Then_Statements
=> Lim_Typ_Stmts
,
12353 Else_Statements
=> Conc_Typ_Stmts
));
12358 -- <triggering-statements>
12360 -- <timed-statements>
12364 Make_Implicit_If_Statement
(N
,
12365 Condition
=> New_Occurrence_Of
(B
, Loc
),
12366 Then_Statements
=> E_Stats
,
12367 Else_Statements
=> D_Stats
));
12370 -- Simple case of a non-dispatching trigger. Skip assignments to
12371 -- temporaries created for in-out parameters.
12373 -- This makes unwarranted assumptions about the shape of the expanded
12374 -- tree for the call, and should be cleaned up ???
12376 Stmt
:= First
(Stmts
);
12377 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12381 -- Do the assignment at this stage only because the evaluation
12382 -- of the expression must not occur before (see ACVC C97302A).
12384 Insert_Before
(Stmt
,
12385 Make_Assignment_Statement
(Loc
,
12386 Name
=> New_Reference_To
(D
, Loc
),
12387 Expression
=> D_Conv
));
12390 Params
:= Parameter_Associations
(Call
);
12392 -- For a protected type, we build a Timed_Protected_Entry_Call
12394 if Is_Protected_Type
(Etype
(Concval
)) then
12396 -- Create a new call statement
12398 Param
:= First
(Params
);
12399 while Present
(Param
)
12400 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12405 Dummy
:= Remove_Next
(Next
(Param
));
12407 -- Remove garbage is following the Cancel_Param if present
12409 Dummy
:= Next
(Param
);
12411 -- Remove the mode of the Protected_Entry_Call call, then remove
12412 -- the Communication_Block of the Protected_Entry_Call call, and
12413 -- finally add Duration and a Delay_Mode parameter
12415 pragma Assert
(Present
(Param
));
12416 Rewrite
(Param
, New_Reference_To
(D
, Loc
));
12418 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
12420 -- Add a Boolean flag for successful entry call
12422 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12424 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12425 when System_Tasking_Protected_Objects_Entries
=>
12427 Make_Procedure_Call_Statement
(Loc
,
12430 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12431 Parameter_Associations
=> Params
));
12433 when System_Tasking_Protected_Objects_Single_Entry
=>
12434 Param
:= First
(Params
);
12435 while Present
(Param
)
12437 Is_RTE
(Etype
(Param
), RE_Protected_Entry_Index
)
12445 Make_Procedure_Call_Statement
(Loc
,
12448 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
12449 Parameter_Associations
=> Params
));
12452 raise Program_Error
;
12455 -- For the task case, build a Timed_Task_Entry_Call
12458 -- Create a new call statement
12460 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12461 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12462 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12465 Make_Procedure_Call_Statement
(Loc
,
12467 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12468 Parameter_Associations
=> Params
));
12472 Make_Implicit_If_Statement
(N
,
12473 Condition
=> New_Reference_To
(B
, Loc
),
12474 Then_Statements
=> E_Stats
,
12475 Else_Statements
=> D_Stats
));
12479 Make_Block_Statement
(Loc
,
12480 Declarations
=> Decls
,
12481 Handled_Statement_Sequence
=>
12482 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12485 end Expand_N_Timed_Entry_Call
;
12487 ----------------------------------------
12488 -- Expand_Protected_Body_Declarations --
12489 ----------------------------------------
12491 procedure Expand_Protected_Body_Declarations
12493 Spec_Id
: Entity_Id
)
12496 if No_Run_Time_Mode
then
12497 Error_Msg_CRT
("protected body", N
);
12500 elsif Full_Expander_Active
then
12502 -- Associate discriminals with the first subprogram or entry body to
12505 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12506 Set_Discriminals
(Parent
(Spec_Id
));
12509 end Expand_Protected_Body_Declarations
;
12511 -------------------------
12512 -- External_Subprogram --
12513 -------------------------
12515 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12516 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12519 -- The internal and external subprograms follow each other on the entity
12520 -- chain. Note that previously private operations had no separate
12521 -- external subprogram. We now create one in all cases, because a
12522 -- private operation may actually appear in an external call, through
12523 -- a 'Access reference used for a callback.
12525 -- If the operation is a function that returns an anonymous access type,
12526 -- the corresponding itype appears before the operation, and must be
12529 -- This mechanism is fragile, there should be a real link between the
12530 -- two versions of the operation, but there is no place to put it ???
12532 if Is_Access_Type
(Next_Entity
(Subp
)) then
12533 return Next_Entity
(Next_Entity
(Subp
));
12535 return Next_Entity
(Subp
);
12537 end External_Subprogram
;
12539 ------------------------------
12540 -- Extract_Dispatching_Call --
12541 ------------------------------
12543 procedure Extract_Dispatching_Call
12545 Call_Ent
: out Entity_Id
;
12546 Object
: out Entity_Id
;
12547 Actuals
: out List_Id
;
12548 Formals
: out List_Id
)
12550 Call_Nam
: Node_Id
;
12553 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12555 if Present
(Original_Node
(N
)) then
12556 Call_Nam
:= Name
(Original_Node
(N
));
12558 Call_Nam
:= Name
(N
);
12561 -- Retrieve the name of the dispatching procedure. It contains the
12562 -- dispatch table slot number.
12565 case Nkind
(Call_Nam
) is
12566 when N_Identifier
=>
12569 when N_Selected_Component
=>
12570 Call_Nam
:= Selector_Name
(Call_Nam
);
12573 raise Program_Error
;
12578 Actuals
:= Parameter_Associations
(N
);
12579 Call_Ent
:= Entity
(Call_Nam
);
12580 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12581 Object
:= First
(Actuals
);
12583 if Present
(Original_Node
(Object
)) then
12584 Object
:= Original_Node
(Object
);
12587 -- If the type of the dispatching object is an access type then return
12588 -- an explicit dereference.
12590 if Is_Access_Type
(Etype
(Object
)) then
12591 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12594 end Extract_Dispatching_Call
;
12596 -------------------
12597 -- Extract_Entry --
12598 -------------------
12600 procedure Extract_Entry
12602 Concval
: out Node_Id
;
12603 Ename
: out Node_Id
;
12604 Index
: out Node_Id
)
12606 Nam
: constant Node_Id
:= Name
(N
);
12609 -- For a simple entry, the name is a selected component, with the
12610 -- prefix being the task value, and the selector being the entry.
12612 if Nkind
(Nam
) = N_Selected_Component
then
12613 Concval
:= Prefix
(Nam
);
12614 Ename
:= Selector_Name
(Nam
);
12617 -- For a member of an entry family, the name is an indexed component
12618 -- where the prefix is a selected component, whose prefix in turn is
12619 -- the task value, and whose selector is the entry family. The single
12620 -- expression in the expressions list of the indexed component is the
12621 -- subscript for the family.
12623 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12624 Concval
:= Prefix
(Prefix
(Nam
));
12625 Ename
:= Selector_Name
(Prefix
(Nam
));
12626 Index
:= First
(Expressions
(Nam
));
12630 -------------------
12631 -- Family_Offset --
12632 -------------------
12634 function Family_Offset
12639 Cap
: Boolean) return Node_Id
12645 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12646 -- If one of the bounds is a reference to a discriminant, replace with
12647 -- corresponding discriminal of type. Within the body of a task retrieve
12648 -- the renamed discriminant by simple visibility, using its generated
12649 -- name. Within a protected object, find the original discriminant and
12650 -- replace it with the discriminal of the current protected operation.
12652 ------------------------------
12653 -- Convert_Discriminant_Ref --
12654 ------------------------------
12656 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12657 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12662 if Is_Entity_Name
(Bound
)
12663 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12665 if Is_Task_Type
(Ttyp
)
12666 and then Has_Completion
(Ttyp
)
12668 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12669 Find_Direct_Name
(B
);
12671 elsif Is_Protected_Type
(Ttyp
) then
12672 D
:= First_Discriminant
(Ttyp
);
12673 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12674 Next_Discriminant
(D
);
12677 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
12680 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
12683 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12687 B
:= New_Copy_Tree
(Bound
);
12691 Make_Attribute_Reference
(Loc
,
12692 Attribute_Name
=> Name_Pos
,
12693 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12694 Expressions
=> New_List
(B
));
12695 end Convert_Discriminant_Ref
;
12697 -- Start of processing for Family_Offset
12700 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12701 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12704 if Is_Task_Type
(Ttyp
) then
12705 Ityp
:= RTE
(RE_Task_Entry_Index
);
12707 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12711 Make_Attribute_Reference
(Loc
,
12712 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12713 Attribute_Name
=> Name_Min
,
12714 Expressions
=> New_List
(
12716 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12719 Make_Attribute_Reference
(Loc
,
12720 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12721 Attribute_Name
=> Name_Max
,
12722 Expressions
=> New_List
(
12724 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12727 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12734 function Family_Size
12739 Cap
: Boolean) return Node_Id
12744 if Is_Task_Type
(Ttyp
) then
12745 Ityp
:= RTE
(RE_Task_Entry_Index
);
12747 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12751 Make_Attribute_Reference
(Loc
,
12752 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12753 Attribute_Name
=> Name_Max
,
12754 Expressions
=> New_List
(
12757 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12759 Make_Integer_Literal
(Loc
, 1)),
12760 Make_Integer_Literal
(Loc
, 0)));
12763 ----------------------------
12764 -- Find_Enclosing_Context --
12765 ----------------------------
12767 procedure Find_Enclosing_Context
12769 Context
: out Node_Id
;
12770 Context_Id
: out Entity_Id
;
12771 Context_Decls
: out List_Id
)
12774 -- Traverse the parent chain looking for an enclosing body, block,
12775 -- package or return statement.
12777 Context
:= Parent
(N
);
12778 while not Nkind_In
(Context
, N_Block_Statement
,
12780 N_Extended_Return_Statement
,
12782 N_Package_Declaration
,
12786 Context
:= Parent
(Context
);
12789 -- Extract the constituents of the context
12791 if Nkind
(Context
) = N_Extended_Return_Statement
then
12792 Context_Decls
:= Return_Object_Declarations
(Context
);
12793 Context_Id
:= Return_Statement_Entity
(Context
);
12795 -- Package declarations and bodies use a common library-level activation
12796 -- chain or task master, therefore return the package declaration as the
12797 -- proper carrier for the appropriate flag.
12799 elsif Nkind
(Context
) = N_Package_Body
then
12800 Context_Decls
:= Declarations
(Context
);
12801 Context_Id
:= Corresponding_Spec
(Context
);
12802 Context
:= Parent
(Context_Id
);
12804 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
12805 Context
:= Parent
(Parent
(Context
));
12807 Context
:= Parent
(Context
);
12810 elsif Nkind
(Context
) = N_Package_Declaration
then
12811 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
12812 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12814 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12815 Context_Id
:= Defining_Identifier
(Context_Id
);
12819 Context_Decls
:= Declarations
(Context
);
12821 if Nkind
(Context
) = N_Block_Statement
then
12822 Context_Id
:= Entity
(Identifier
(Context
));
12824 elsif Nkind
(Context
) = N_Entry_Body
then
12825 Context_Id
:= Defining_Identifier
(Context
);
12827 elsif Nkind
(Context
) = N_Subprogram_Body
then
12828 if Present
(Corresponding_Spec
(Context
)) then
12829 Context_Id
:= Corresponding_Spec
(Context
);
12831 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12833 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12834 Context_Id
:= Defining_Identifier
(Context_Id
);
12838 elsif Nkind
(Context
) = N_Task_Body
then
12839 Context_Id
:= Corresponding_Spec
(Context
);
12842 raise Program_Error
;
12846 pragma Assert
(Present
(Context
));
12847 pragma Assert
(Present
(Context_Id
));
12848 pragma Assert
(Present
(Context_Decls
));
12849 end Find_Enclosing_Context
;
12851 -----------------------
12852 -- Find_Master_Scope --
12853 -----------------------
12855 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
12859 -- In Ada 2005, the master is the innermost enclosing scope that is not
12860 -- transient. If the enclosing block is the rewriting of a call or the
12861 -- scope is an extended return statement this is valid master. The
12862 -- master in an extended return is only used within the return, and is
12863 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12864 -- now before that overwriting occurs.
12868 if Ada_Version
>= Ada_2005
then
12869 while Is_Internal
(S
) loop
12870 if Nkind
(Parent
(S
)) = N_Block_Statement
12872 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
12876 elsif Ekind
(S
) = E_Return_Statement
then
12886 end Find_Master_Scope
;
12888 -------------------------------
12889 -- First_Protected_Operation --
12890 -------------------------------
12892 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
12893 First_Op
: Node_Id
;
12896 First_Op
:= First
(D
);
12897 while Present
(First_Op
)
12898 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
12904 end First_Protected_Operation
;
12906 ---------------------------------------
12907 -- Install_Private_Data_Declarations --
12908 ---------------------------------------
12910 procedure Install_Private_Data_Declarations
12912 Spec_Id
: Entity_Id
;
12913 Conc_Typ
: Entity_Id
;
12914 Body_Nod
: Node_Id
;
12916 Barrier
: Boolean := False;
12917 Family
: Boolean := False)
12919 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
12922 Insert_Node
: Node_Id
:= Empty
;
12923 Obj_Ent
: Entity_Id
;
12925 procedure Add
(Decl
: Node_Id
);
12926 -- Add a single declaration after Insert_Node. If this is the first
12927 -- addition, Decl is added to the front of Decls and it becomes the
12930 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
12931 -- The bounds of an entry index may depend on discriminants, create a
12932 -- reference to the corresponding prival. Otherwise return a duplicate
12933 -- of the original bound.
12939 procedure Add
(Decl
: Node_Id
) is
12941 if No
(Insert_Node
) then
12942 Prepend_To
(Decls
, Decl
);
12944 Insert_After
(Insert_Node
, Decl
);
12947 Insert_Node
:= Decl
;
12950 --------------------------
12951 -- Replace_Discriminant --
12952 --------------------------
12954 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
12956 if Nkind
(Bound
) = N_Identifier
12957 and then Is_Discriminal
(Entity
(Bound
))
12959 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12961 return Duplicate_Subexpr
(Bound
);
12965 -- Start of processing for Install_Private_Data_Declarations
12968 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
12969 -- formal parameter _O, _object or _task depending on the context.
12971 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
12973 -- Special processing of _O for barrier functions, protected entries
12980 (Ekind
(Spec_Id
) = E_Entry
12981 or else Ekind
(Spec_Id
) = E_Entry_Family
))
12984 Conc_Rec
: constant Entity_Id
:=
12985 Corresponding_Record_Type
(Conc_Typ
);
12986 Typ_Id
: constant Entity_Id
:=
12987 Make_Defining_Identifier
(Loc
,
12988 New_External_Name
(Chars
(Conc_Rec
), 'P'));
12991 -- type prot_typVP is access prot_typV;
12994 Make_Full_Type_Declaration
(Loc
,
12995 Defining_Identifier
=> Typ_Id
,
12997 Make_Access_To_Object_Definition
(Loc
,
12998 Subtype_Indication
=>
12999 New_Reference_To
(Conc_Rec
, Loc
)));
13003 -- _object : prot_typVP := prot_typV (_O);
13006 Make_Object_Declaration
(Loc
,
13007 Defining_Identifier
=>
13008 Make_Defining_Identifier
(Loc
, Name_uObject
),
13009 Object_Definition
=> New_Reference_To
(Typ_Id
, Loc
),
13011 Unchecked_Convert_To
(Typ_Id
,
13012 New_Reference_To
(Obj_Ent
, Loc
)));
13015 -- Set the reference to the concurrent object
13017 Obj_Ent
:= Defining_Identifier
(Decl
);
13021 -- Step 2: Create the Protection object and build its declaration for
13022 -- any protected entry (family) of subprogram. Note for the lock-free
13023 -- implementation, the Protection object is not needed anymore.
13025 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13027 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13031 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13033 -- Determine the proper protection type
13035 if Has_Attach_Handler
(Conc_Typ
)
13036 and then not Restricted_Profile
13038 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13040 elsif Has_Interrupt_Handler
(Conc_Typ
)
13041 and then not Restriction_Active
(No_Dynamic_Attachment
)
13043 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13046 case Corresponding_Runtime_Package
(Conc_Typ
) is
13047 when System_Tasking_Protected_Objects_Entries
=>
13048 Prot_Typ
:= RE_Protection_Entries
;
13050 when System_Tasking_Protected_Objects_Single_Entry
=>
13051 Prot_Typ
:= RE_Protection_Entry
;
13053 when System_Tasking_Protected_Objects
=>
13054 Prot_Typ
:= RE_Protection
;
13057 raise Program_Error
;
13062 -- conc_typR : protection_typ renames _object._object;
13065 Make_Object_Renaming_Declaration
(Loc
,
13066 Defining_Identifier
=> Prot_Ent
,
13068 New_Reference_To
(RTE
(Prot_Typ
), Loc
),
13070 Make_Selected_Component
(Loc
,
13071 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13072 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13077 -- Step 3: Add discriminant renamings (if any)
13079 if Has_Discriminants
(Conc_Typ
) then
13084 D
:= First_Discriminant
(Conc_Typ
);
13085 while Present
(D
) loop
13087 -- Adjust the source location
13089 Set_Sloc
(Discriminal
(D
), Loc
);
13092 -- discr_name : discr_typ renames _object.discr_name;
13094 -- discr_name : discr_typ renames _task.discr_name;
13097 Make_Object_Renaming_Declaration
(Loc
,
13098 Defining_Identifier
=> Discriminal
(D
),
13099 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
13101 Make_Selected_Component
(Loc
,
13102 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13103 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13106 Next_Discriminant
(D
);
13111 -- Step 4: Add private component renamings (if any)
13113 if Is_Protected
then
13114 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13116 if Present
(Private_Declarations
(Def
)) then
13119 Comp_Id
: Entity_Id
;
13120 Decl_Id
: Entity_Id
;
13123 Comp
:= First
(Private_Declarations
(Def
));
13124 while Present
(Comp
) loop
13125 if Nkind
(Comp
) = N_Component_Declaration
then
13126 Comp_Id
:= Defining_Identifier
(Comp
);
13128 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13130 -- Minimal decoration
13132 if Ekind
(Spec_Id
) = E_Function
then
13133 Set_Ekind
(Decl_Id
, E_Constant
);
13135 Set_Ekind
(Decl_Id
, E_Variable
);
13138 Set_Prival
(Comp_Id
, Decl_Id
);
13139 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13140 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13143 -- comp_name : comp_typ renames _object.comp_name;
13146 Make_Object_Renaming_Declaration
(Loc
,
13147 Defining_Identifier
=> Decl_Id
,
13149 New_Reference_To
(Etype
(Comp_Id
), Loc
),
13151 Make_Selected_Component
(Loc
,
13153 New_Reference_To
(Obj_Ent
, Loc
),
13155 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13165 -- Step 5: Add the declaration of the entry index and the associated
13166 -- type for barrier functions and entry families.
13168 if (Barrier
and then Family
)
13169 or else Ekind
(Spec_Id
) = E_Entry_Family
13172 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13173 Index
: constant Entity_Id
:=
13174 Defining_Identifier
(
13175 Entry_Index_Specification
(
13176 Entry_Body_Formal_Part
(Body_Nod
)));
13177 Index_Con
: constant Entity_Id
:=
13178 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13180 Index_Typ
: Entity_Id
;
13184 -- Minimal decoration
13186 Set_Ekind
(Index_Con
, E_Constant
);
13187 Set_Entry_Index_Constant
(Index
, Index_Con
);
13188 Set_Discriminal_Link
(Index_Con
, Index
);
13190 -- Retrieve the bounds of the entry family
13192 High
:= Type_High_Bound
(Etype
(Index
));
13193 Low
:= Type_Low_Bound
(Etype
(Index
));
13195 -- In the simple case the entry family is given by a subtype
13196 -- mark and the index constant has the same type.
13198 if Is_Entity_Name
(Original_Node
(
13199 Discrete_Subtype_Definition
(Parent
(Index
))))
13201 Index_Typ
:= Etype
(Index
);
13203 -- Otherwise a new subtype declaration is required
13206 High
:= Replace_Bound
(High
);
13207 Low
:= Replace_Bound
(Low
);
13209 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13212 -- subtype Jnn is <Etype of Index> range Low .. High;
13215 Make_Subtype_Declaration
(Loc
,
13216 Defining_Identifier
=> Index_Typ
,
13217 Subtype_Indication
=>
13218 Make_Subtype_Indication
(Loc
,
13220 New_Reference_To
(Base_Type
(Etype
(Index
)), Loc
),
13222 Make_Range_Constraint
(Loc
,
13223 Range_Expression
=>
13224 Make_Range
(Loc
, Low
, High
))));
13228 Set_Etype
(Index_Con
, Index_Typ
);
13230 -- Create the object which designates the index:
13231 -- J : constant Jnn :=
13232 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13234 -- where Jnn is the subtype created above or the original type of
13235 -- the index, _E is a formal of the protected body subprogram and
13236 -- <index expr> is the index of the first family member.
13239 Make_Object_Declaration
(Loc
,
13240 Defining_Identifier
=> Index_Con
,
13241 Constant_Present
=> True,
13242 Object_Definition
=>
13243 New_Reference_To
(Index_Typ
, Loc
),
13246 Make_Attribute_Reference
(Loc
,
13248 New_Reference_To
(Index_Typ
, Loc
),
13249 Attribute_Name
=> Name_Val
,
13251 Expressions
=> New_List
(
13255 Make_Op_Subtract
(Loc
,
13257 New_Reference_To
(E
, Loc
),
13259 Entry_Index_Expression
(Loc
,
13260 Defining_Identifier
(Body_Nod
),
13264 Make_Attribute_Reference
(Loc
,
13266 New_Reference_To
(Index_Typ
, Loc
),
13267 Attribute_Name
=> Name_Pos
,
13268 Expressions
=> New_List
(
13269 Make_Attribute_Reference
(Loc
,
13271 New_Reference_To
(Index_Typ
, Loc
),
13272 Attribute_Name
=> Name_First
)))))));
13276 end Install_Private_Data_Declarations
;
13278 -----------------------
13279 -- Is_Exception_Safe --
13280 -----------------------
13282 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
13284 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
13285 -- Return True whenever encountering a subprogram call or raise
13286 -- statement of any kind in the sequence of statements
13288 ---------------------
13289 -- Has_Side_Effect --
13290 ---------------------
13292 -- What is this doing buried two levels down in exp_ch9. It seems like a
13293 -- generally useful function, and indeed there may be code duplication
13294 -- going on here ???
13296 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
13300 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
13301 -- Indicate whether N is a subprogram call or a raise statement
13303 ----------------------
13304 -- Is_Call_Or_Raise --
13305 ----------------------
13307 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
13309 return Nkind_In
(N
, N_Procedure_Call_Statement
,
13312 N_Raise_Constraint_Error
,
13313 N_Raise_Program_Error
,
13314 N_Raise_Storage_Error
);
13315 end Is_Call_Or_Raise
;
13317 -- Start of processing for Has_Side_Effect
13321 while Present
(Stmt
) loop
13322 if Is_Call_Or_Raise
(Stmt
) then
13326 -- An object declaration can also contain a function call or a
13327 -- raise statement.
13329 if Nkind
(Stmt
) = N_Object_Declaration
then
13330 Expr
:= Expression
(Stmt
);
13332 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
13341 end Has_Side_Effect
;
13343 -- Start of processing for Is_Exception_Safe
13346 -- If the checks handled by the back end are not disabled, we cannot
13347 -- ensure that no exception will be raised.
13349 if not Access_Checks_Suppressed
(Empty
)
13350 or else not Discriminant_Checks_Suppressed
(Empty
)
13351 or else not Range_Checks_Suppressed
(Empty
)
13352 or else not Index_Checks_Suppressed
(Empty
)
13353 or else Opt
.Stack_Checking_Enabled
13358 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
13361 (First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
13367 end Is_Exception_Safe
;
13369 ---------------------------------
13370 -- Is_Potentially_Large_Family --
13371 ---------------------------------
13373 function Is_Potentially_Large_Family
13374 (Base_Index
: Entity_Id
;
13375 Conctyp
: Entity_Id
;
13377 Hi
: Node_Id
) return Boolean
13380 return Scope
(Base_Index
) = Standard_Standard
13381 and then Base_Index
= Base_Type
(Standard_Integer
)
13382 and then Has_Discriminants
(Conctyp
)
13384 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13386 (Denotes_Discriminant
(Lo
, True)
13388 Denotes_Discriminant
(Hi
, True));
13389 end Is_Potentially_Large_Family
;
13391 -------------------------------------
13392 -- Is_Private_Primitive_Subprogram --
13393 -------------------------------------
13395 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13398 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13399 and then Is_Private_Primitive
(Id
);
13400 end Is_Private_Primitive_Subprogram
;
13406 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13407 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13408 Formal
: Entity_Id
;
13411 Formal
:= First_Formal
(Bod_Subp
);
13412 while Present
(Formal
) loop
13414 -- Look for formal parameter _E
13416 if Chars
(Formal
) = Name_uE
then
13420 Next_Formal
(Formal
);
13423 -- A protected body subprogram should always have the parameter in
13426 raise Program_Error
;
13429 --------------------------------
13430 -- Make_Initialize_Protection --
13431 --------------------------------
13433 function Make_Initialize_Protection
13434 (Protect_Rec
: Entity_Id
) return List_Id
13436 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13439 Ptyp
: constant Node_Id
:=
13440 Corresponding_Concurrent_Type
(Protect_Rec
);
13442 L
: constant List_Id
:= New_List
;
13443 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13444 Prio_Type
: Entity_Id
;
13445 Restricted
: constant Boolean := Restricted_Profile
;
13448 -- We may need two calls to properly initialize the object, one to
13449 -- Initialize_Protection, and possibly one to Install_Handlers if we
13450 -- have a pragma Attach_Handler.
13452 -- Get protected declaration. In the case of a task type declaration,
13453 -- this is simply the parent of the protected type entity. In the single
13454 -- protected object declaration, this parent will be the implicit type,
13455 -- and we can find the corresponding single protected object declaration
13456 -- by searching forward in the declaration list in the tree.
13458 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13459 -- of this type should have been removed during semantic analysis.
13461 Pdec
:= Parent
(Ptyp
);
13462 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13463 N_Single_Protected_Declaration
)
13468 -- Build the parameter list for the call. Note that _Init is the name
13469 -- of the formal for the object to be initialized, which is the task
13470 -- value record itself.
13474 -- For lock-free implementation, skip initializations of the Protection
13477 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13478 -- Object parameter. This is a pointer to the object of type
13479 -- Protection used by the GNARL to control the protected object.
13482 Make_Attribute_Reference
(Loc
,
13484 Make_Selected_Component
(Loc
,
13485 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13486 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13487 Attribute_Name
=> Name_Unchecked_Access
));
13489 -- Priority parameter. Set to Unspecified_Priority unless there is a
13490 -- Priority rep item, in which case we take the value from the pragma
13491 -- or attribute definition clause, or there is an Interrupt_Priority
13492 -- rep item and no Priority rep item, and we set the ceiling to
13493 -- Interrupt_Priority'Last, an implementation-defined value, see
13496 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13498 Prio_Clause
: constant Node_Id
:=
13500 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13508 if Nkind
(Prio_Clause
) = N_Pragma
then
13511 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13513 -- Get_Rep_Item returns either priority pragma.
13515 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13516 Prio_Type
:= RTE
(RE_Any_Priority
);
13518 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13521 -- Attribute definition clause Priority
13524 if Chars
(Prio_Clause
) = Name_Priority
then
13525 Prio_Type
:= RTE
(RE_Any_Priority
);
13527 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13530 Prio
:= Expression
(Prio_Clause
);
13533 -- If priority is a static expression, then we can duplicate it
13534 -- with no problem and simply append it to the argument list.
13535 -- However, it has only be pre-analyzed, so we need to check
13536 -- now that it is in the bounds of the priority type.
13538 if Is_Static_Expression
(Prio
) then
13539 Set_Analyzed
(Prio
, False);
13541 Make_Type_Conversion
(Loc
,
13542 Subtype_Mark
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13543 Expression
=> Duplicate_Subexpr
(Prio
)));
13545 -- Otherwise, the priority may be a per-object expression, if
13546 -- it depends on a discriminant of the type. In this case,
13547 -- create local variable to capture the expression. Note that
13548 -- it is really necessary to create this variable explicitly.
13549 -- It might be thought that removing side effects would the
13550 -- appropriate approach, but that could generate declarations
13551 -- improperly placed in the enclosing scope.
13554 Temp
:= Make_Temporary
(Loc
, 'R', Prio
);
13556 Make_Object_Declaration
(Loc
,
13557 Defining_Identifier
=> Temp
,
13558 Object_Definition
=>
13559 New_Occurrence_Of
(Prio_Type
, Loc
),
13560 Expression
=> Relocate_Node
(Prio
)));
13562 Append_To
(Args
, New_Occurrence_Of
(Temp
, Loc
));
13566 -- When no priority is specified but an xx_Handler pragma is, we
13567 -- default to System.Interrupts.Default_Interrupt_Priority, see
13570 elsif Has_Attach_Handler
(Ptyp
)
13571 or else Has_Interrupt_Handler
(Ptyp
)
13574 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13576 -- Normal case, no priority or xx_Handler specified, default priority
13580 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13583 -- Test for Compiler_Info parameter. This parameter allows entry body
13584 -- procedures and barrier functions to be called from the runtime. It
13585 -- is a pointer to the record generated by the compiler to represent
13586 -- the protected object.
13588 -- A protected type without entries that covers an interface and
13589 -- overrides the abstract routines with protected procedures is
13590 -- considered equivalent to a protected type with entries in the
13591 -- context of dispatching select statements.
13593 -- Protected types with interrupt handlers (when not using a
13594 -- restricted profile) are also considered equivalent to protected
13595 -- types with entries.
13597 -- The types which are used (Static_Interrupt_Protection and
13598 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13601 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13603 Called_Subp
: RE_Id
;
13607 when System_Tasking_Protected_Objects_Entries
=>
13608 Called_Subp
:= RE_Initialize_Protection_Entries
;
13610 -- Argument Compiler_Info
13613 Make_Attribute_Reference
(Loc
,
13614 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13615 Attribute_Name
=> Name_Address
));
13617 when System_Tasking_Protected_Objects_Single_Entry
=>
13618 Called_Subp
:= RE_Initialize_Protection_Entry
;
13620 -- Argument Compiler_Info
13623 Make_Attribute_Reference
(Loc
,
13624 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13625 Attribute_Name
=> Name_Address
));
13627 when System_Tasking_Protected_Objects
=>
13628 Called_Subp
:= RE_Initialize_Protection
;
13631 raise Program_Error
;
13634 -- Entry_Bodies parameter. This is a pointer to an array of
13635 -- pointers to the entry body procedures and barrier functions of
13636 -- the object. If the protected type has no entries this object
13637 -- will not exist, in this case, pass a null (it can happen when
13638 -- there are protected interrupt handlers or interfaces).
13641 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13643 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13644 -- multiple entries).
13647 Make_Attribute_Reference
(Loc
,
13648 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13649 Attribute_Name
=> Name_Unrestricted_Access
));
13651 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13653 -- Find index mapping function (clumsy but ok for now)
13655 while Ekind
(P_Arr
) /= E_Function
loop
13656 Next_Entity
(P_Arr
);
13660 Make_Attribute_Reference
(Loc
,
13661 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13662 Attribute_Name
=> Name_Unrestricted_Access
));
13665 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
13667 -- This is the case where we have a protected object with
13668 -- interfaces and no entries, and the single entry restriction
13669 -- is in effect. We pass a null pointer for the entry
13670 -- parameter because there is no actual entry.
13672 Append_To
(Args
, Make_Null
(Loc
));
13674 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13676 -- This is the case where we have a protected object with no
13678 -- - either interrupt handlers with non restricted profile,
13680 -- Note that the types which are used for interrupt handlers
13681 -- (Static/Dynamic_Interrupt_Protection) are derived from
13682 -- Protection_Entries. We pass two null pointers because there
13683 -- is no actual entry, and the initialization procedure needs
13684 -- both Entry_Bodies and Find_Body_Index.
13686 Append_To
(Args
, Make_Null
(Loc
));
13687 Append_To
(Args
, Make_Null
(Loc
));
13691 Make_Procedure_Call_Statement
(Loc
,
13692 Name
=> New_Reference_To
(RTE
(Called_Subp
), Loc
),
13693 Parameter_Associations
=> Args
));
13697 if Has_Attach_Handler
(Ptyp
) then
13699 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13700 -- make the following call:
13702 -- Install_Handlers (_object,
13703 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13705 -- or, in the case of Ravenscar:
13707 -- Install_Restricted_Handlers
13708 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13711 Args
: constant List_Id
:= New_List
;
13712 Table
: constant List_Id
:= New_List
;
13713 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13716 -- Build the Attach_Handler table argument
13718 while Present
(Ritem
) loop
13719 if Nkind
(Ritem
) = N_Pragma
13720 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13723 Handler
: constant Node_Id
:=
13724 First
(Pragma_Argument_Associations
(Ritem
));
13726 Interrupt
: constant Node_Id
:= Next
(Handler
);
13727 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13731 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13732 Unchecked_Convert_To
13733 (RTE
(RE_System_Interrupt_Id
), Expr
),
13734 Make_Attribute_Reference
(Loc
,
13735 Prefix
=> Make_Selected_Component
(Loc
,
13736 Make_Identifier
(Loc
, Name_uInit
),
13737 Duplicate_Subexpr_No_Checks
13738 (Expression
(Handler
))),
13739 Attribute_Name
=> Name_Access
))));
13743 Next_Rep_Item
(Ritem
);
13746 -- Append the table argument we just built
13748 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13750 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13751 -- call to the statements.
13754 -- Call a simplified version of Install_Handlers to be used
13755 -- when the Ravenscar restrictions are in effect
13756 -- (Install_Restricted_Handlers).
13759 Make_Procedure_Call_Statement
(Loc
,
13762 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13763 Parameter_Associations
=> Args
));
13766 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13767 -- First, prepends the _object argument
13770 Make_Attribute_Reference
(Loc
,
13772 Make_Selected_Component
(Loc
,
13773 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13775 Make_Identifier
(Loc
, Name_uObject
)),
13776 Attribute_Name
=> Name_Unchecked_Access
));
13779 -- Then, insert call to Install_Handlers
13782 Make_Procedure_Call_Statement
(Loc
,
13783 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
13784 Parameter_Associations
=> Args
));
13790 end Make_Initialize_Protection
;
13792 ---------------------------
13793 -- Make_Task_Create_Call --
13794 ---------------------------
13796 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
13797 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
13807 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
13808 Tnam
:= Chars
(Ttyp
);
13810 -- Get task declaration. In the case of a task type declaration, this is
13811 -- simply the parent of the task type entity. In the single task
13812 -- declaration, this parent will be the implicit type, and we can find
13813 -- the corresponding single task declaration by searching forward in the
13814 -- declaration list in the tree.
13816 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13817 -- this type should have been removed during semantic analysis.
13819 Tdec
:= Parent
(Ttyp
);
13820 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
13821 N_Single_Task_Declaration
)
13826 -- Now we can find the task definition from this declaration
13828 Tdef
:= Task_Definition
(Tdec
);
13830 -- Build the parameter list for the call. Note that _Init is the name
13831 -- of the formal for the object to be initialized, which is the task
13832 -- value record itself.
13836 -- Priority parameter. Set to Unspecified_Priority unless there is a
13837 -- Priority rep item, in which case we take the value from the rep item.
13839 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
13841 Make_Selected_Component
(Loc
,
13842 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13843 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
13846 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13849 -- Optional Stack parameter
13851 if Restricted_Profile
then
13853 -- If the stack has been preallocated by the expander then
13854 -- pass its address. Otherwise, pass a null address.
13856 if Preallocated_Stacks_On_Target
then
13858 Make_Attribute_Reference
(Loc
,
13860 Make_Selected_Component
(Loc
,
13861 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13862 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
13863 Attribute_Name
=> Name_Address
));
13867 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
13871 -- Size parameter. If no Storage_Size pragma is present, then
13872 -- the size is taken from the taskZ variable for the type, which
13873 -- is either Unspecified_Size, or has been reset by the use of
13874 -- a Storage_Size attribute definition clause. If a pragma is
13875 -- present, then the size is taken from the _Size field of the
13876 -- task value record, which was set from the pragma value.
13879 and then Has_Storage_Size_Pragma
(Tdef
)
13882 Make_Selected_Component
(Loc
,
13883 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13884 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
13888 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
13891 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
13892 -- Task_Info pragma, in which case we take the value from the pragma.
13894 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
13896 Make_Selected_Component
(Loc
,
13897 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13898 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
13902 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
13905 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
13906 -- in which case we take the value from the rep item. The parameter is
13907 -- passed as an Integer because in the case of unspecified CPU the
13908 -- value is not in the range of CPU_Range.
13910 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
13912 Convert_To
(Standard_Integer
,
13913 Make_Selected_Component
(Loc
,
13914 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13915 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
13918 New_Reference_To
(RTE
(RE_Unspecified_CPU
), Loc
));
13921 if not Restricted_Profile
then
13923 -- Deadline parameter. If no Relative_Deadline pragma is present,
13924 -- then the deadline is Time_Span_Zero. If a pragma is present, then
13925 -- the deadline is taken from the _Relative_Deadline field of the
13926 -- task value record, which was set from the pragma value. Note that
13927 -- this parameter must not be generated for the restricted profiles
13928 -- since Ravenscar does not allow deadlines.
13930 -- Case where pragma Relative_Deadline applies: use given value
13933 and then Has_Relative_Deadline_Pragma
(Tdef
)
13936 Make_Selected_Component
(Loc
,
13938 Make_Identifier
(Loc
, Name_uInit
),
13940 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
13942 -- No pragma Relative_Deadline apply to the task
13946 New_Reference_To
(RTE
(RE_Time_Span_Zero
), Loc
));
13949 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
13950 -- present, then the dispatching domain is null. If a rep item is
13951 -- present, then the dispatching domain is taken from the
13952 -- _Dispatching_Domain field of the task value record, which was set
13953 -- from the rep item value. Note that this parameter must not be
13954 -- generated for the restricted profiles since Ravenscar does not
13955 -- allow dispatching domains.
13957 -- Case where Dispatching_Domain rep item applies: use given value
13960 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
13963 Make_Selected_Component
(Loc
,
13965 Make_Identifier
(Loc
, Name_uInit
),
13967 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
13969 -- No pragma or aspect Dispatching_Domain apply to the task
13972 Append_To
(Args
, Make_Null
(Loc
));
13975 -- Number of entries. This is an expression of the form:
13977 -- n + _Init.a'Length + _Init.a'B'Length + ...
13979 -- where a,b... are the entry family names for the task definition
13982 Build_Entry_Count_Expression
13987 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
13989 Append_To
(Args
, Ecount
);
13991 -- Master parameter. This is a reference to the _Master parameter of
13992 -- the initialization procedure, except in the case of the pragma
13993 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
13994 -- System.Tasking.Library_Task_Level.
13996 if Restriction_Active
(No_Task_Hierarchy
) = False then
13997 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14000 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
14004 -- State parameter. This is a pointer to the task body procedure. The
14005 -- required value is obtained by taking 'Unrestricted_Access of the task
14006 -- body procedure and converting it (with an unchecked conversion) to
14007 -- the type required by the task kernel. For further details, see the
14008 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14009 -- than 'Address in order to avoid creating trampolines.
14012 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14013 Subp_Ptr_Typ
: constant Node_Id
:=
14014 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14015 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14018 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14019 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14021 -- Be sure to freeze a reference to the access-to-subprogram type,
14022 -- otherwise gigi will complain that it's in the wrong scope, because
14023 -- it's actually inside the init procedure for the record type that
14024 -- corresponds to the task type.
14026 -- This processing is causing a crash in the .NET/JVM back ends that
14027 -- is not yet understood, so skip it in these cases ???
14029 if VM_Target
= No_VM
then
14030 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14031 Append_Freeze_Action
(Task_Rec
, Ref
);
14034 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14035 Make_Qualified_Expression
(Loc
,
14036 Subtype_Mark
=> New_Reference_To
(Subp_Ptr_Typ
, Loc
),
14038 Make_Attribute_Reference
(Loc
,
14040 New_Occurrence_Of
(Body_Proc
, Loc
),
14041 Attribute_Name
=> Name_Unrestricted_Access
))));
14043 -- For the .NET/JVM cases revert to the original code below ???
14047 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14048 Make_Attribute_Reference
(Loc
,
14050 New_Occurrence_Of
(Body_Proc
, Loc
),
14051 Attribute_Name
=> Name_Address
)));
14055 -- Discriminants parameter. This is just the address of the task
14056 -- value record itself (which contains the discriminant values
14059 Make_Attribute_Reference
(Loc
,
14060 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14061 Attribute_Name
=> Name_Address
));
14063 -- Elaborated parameter. This is an access to the elaboration Boolean
14066 Make_Attribute_Reference
(Loc
,
14067 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14068 Attribute_Name
=> Name_Unchecked_Access
));
14070 -- Add Chain parameter (not done for sequential elaboration policy, see
14071 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14073 if Partition_Elaboration_Policy
/= 'S' then
14074 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14077 -- Task name parameter. Take this from the _Task_Id parameter to the
14078 -- init call unless there is a Task_Name pragma, in which case we take
14079 -- the value from the pragma.
14081 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14082 -- Copy expression in full, because it may be dynamic and have
14089 (Pragma_Argument_Associations
14091 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14094 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14097 -- Created_Task parameter. This is the _Task_Id field of the task
14101 Make_Selected_Component
(Loc
,
14102 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14103 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14109 if Restricted_Profile
then
14110 if Partition_Elaboration_Policy
= 'S' then
14111 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14113 Create_RE
:= RE_Create_Restricted_Task
;
14116 Create_RE
:= RE_Create_Task
;
14119 Name
:= New_Reference_To
(RTE
(Create_RE
), Loc
);
14123 Make_Procedure_Call_Statement
(Loc
,
14125 Parameter_Associations
=> Args
);
14126 end Make_Task_Create_Call
;
14128 ------------------------------
14129 -- Next_Protected_Operation --
14130 ------------------------------
14132 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14136 Next_Op
:= Next
(N
);
14137 while Present
(Next_Op
)
14138 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
14144 end Next_Protected_Operation
;
14146 ---------------------
14147 -- Null_Statements --
14148 ---------------------
14150 function Null_Statements
(Stats
: List_Id
) return Boolean is
14154 Stmt
:= First
(Stats
);
14155 while Nkind
(Stmt
) /= N_Empty
14156 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14158 (Nkind
(Stmt
) = N_Pragma
14160 Nam_In
(Pragma_Name
(Stmt
), Name_Unreferenced
,
14167 return Nkind
(Stmt
) = N_Empty
;
14168 end Null_Statements
;
14170 --------------------------
14171 -- Parameter_Block_Pack --
14172 --------------------------
14174 function Parameter_Block_Pack
14176 Blk_Typ
: Entity_Id
;
14180 Stmts
: List_Id
) return Node_Id
14182 Actual
: Entity_Id
;
14183 Expr
: Node_Id
:= Empty
;
14184 Formal
: Entity_Id
;
14185 Has_Param
: Boolean := False;
14188 Temp_Asn
: Node_Id
;
14189 Temp_Nam
: Node_Id
;
14192 Actual
:= First
(Actuals
);
14193 Formal
:= Defining_Identifier
(First
(Formals
));
14194 Params
:= New_List
;
14196 while Present
(Actual
) loop
14197 if Is_By_Copy_Type
(Etype
(Actual
)) then
14199 -- Jnn : aliased <formal-type>
14201 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14204 Make_Object_Declaration
(Loc
,
14207 Defining_Identifier
=>
14209 Object_Definition
=>
14210 New_Reference_To
(Etype
(Formal
), Loc
)));
14212 if Ekind
(Formal
) /= E_Out_Parameter
then
14218 New_Reference_To
(Temp_Nam
, Loc
);
14220 Set_Assignment_OK
(Temp_Asn
);
14223 Make_Assignment_Statement
(Loc
,
14227 New_Copy_Tree
(Actual
)));
14231 -- Jnn'unchecked_access
14234 Make_Attribute_Reference
(Loc
,
14236 Name_Unchecked_Access
,
14238 New_Reference_To
(Temp_Nam
, Loc
)));
14242 -- The controlling parameter is omitted
14245 if not Is_Controlling_Actual
(Actual
) then
14247 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14253 Next_Actual
(Actual
);
14254 Next_Formal_With_Extras
(Formal
);
14258 Expr
:= Make_Aggregate
(Loc
, Params
);
14263 -- J1'unchecked_access;
14264 -- <actual2>'reference;
14267 P
:= Make_Temporary
(Loc
, 'P');
14270 Make_Object_Declaration
(Loc
,
14271 Defining_Identifier
=>
14273 Object_Definition
=>
14274 New_Reference_To
(Blk_Typ
, Loc
),
14279 end Parameter_Block_Pack
;
14281 ----------------------------
14282 -- Parameter_Block_Unpack --
14283 ----------------------------
14285 function Parameter_Block_Unpack
14289 Formals
: List_Id
) return List_Id
14291 Actual
: Entity_Id
;
14293 Formal
: Entity_Id
;
14294 Has_Asnmt
: Boolean := False;
14295 Result
: constant List_Id
:= New_List
;
14298 Actual
:= First
(Actuals
);
14299 Formal
:= Defining_Identifier
(First
(Formals
));
14300 while Present
(Actual
) loop
14301 if Is_By_Copy_Type
(Etype
(Actual
))
14302 and then Ekind
(Formal
) /= E_In_Parameter
14305 -- <actual> := P.<formal>;
14308 Make_Assignment_Statement
(Loc
,
14312 Make_Explicit_Dereference
(Loc
,
14313 Make_Selected_Component
(Loc
,
14315 New_Reference_To
(P
, Loc
),
14317 Make_Identifier
(Loc
, Chars
(Formal
)))));
14319 Set_Assignment_OK
(Name
(Asnmt
));
14320 Append_To
(Result
, Asnmt
);
14325 Next_Actual
(Actual
);
14326 Next_Formal_With_Extras
(Formal
);
14332 return New_List
(Make_Null_Statement
(Loc
));
14334 end Parameter_Block_Unpack
;
14336 ----------------------
14337 -- Set_Discriminals --
14338 ----------------------
14340 procedure Set_Discriminals
(Dec
: Node_Id
) is
14343 D_Minal
: Entity_Id
;
14346 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14347 Pdef
:= Defining_Identifier
(Dec
);
14349 if Has_Discriminants
(Pdef
) then
14350 D
:= First_Discriminant
(Pdef
);
14351 while Present
(D
) loop
14353 Make_Defining_Identifier
(Sloc
(D
),
14354 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14356 Set_Ekind
(D_Minal
, E_Constant
);
14357 Set_Etype
(D_Minal
, Etype
(D
));
14358 Set_Scope
(D_Minal
, Pdef
);
14359 Set_Discriminal
(D
, D_Minal
);
14360 Set_Discriminal_Link
(D_Minal
, D
);
14362 Next_Discriminant
(D
);
14365 end Set_Discriminals
;
14367 -----------------------
14368 -- Trivial_Accept_OK --
14369 -----------------------
14371 function Trivial_Accept_OK
return Boolean is
14373 case Opt
.Task_Dispatching_Policy
is
14375 -- If we have the default task dispatching policy in effect, we can
14376 -- definitely do the optimization (one way of looking at this is to
14377 -- think of the formal definition of the default policy being allowed
14378 -- to run any task it likes after a rendezvous, so even if notionally
14379 -- a full rescheduling occurs, we can say that our dispatching policy
14380 -- (i.e. the default dispatching policy) reorders the queue to be the
14381 -- same as just before the call.
14386 -- FIFO_Within_Priorities certainly does not permit this
14387 -- optimization since the Rendezvous is a scheduling action that may
14388 -- require some other task to be run.
14393 -- For now, disallow the optimization for all other policies. This
14394 -- may be over-conservative, but it is certainly not incorrect.
14400 end Trivial_Accept_OK
;