1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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_Entry_Count_Expression
140 (Concurrent_Type
: Node_Id
;
141 Component_List
: List_Id
;
142 Loc
: Source_Ptr
) return Node_Id
;
143 -- Compute number of entries for concurrent object. This is a count of
144 -- simple entries, followed by an expression that computes the length
145 -- of the range of each entry family. A single array with that size is
146 -- allocated for each concurrent object of the type.
148 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
149 -- Build the function that translates the entry index in the call
150 -- (which depends on the size of entry families) into an index into the
151 -- Entry_Bodies_Array, to determine the body and barrier function used
152 -- in a protected entry call. A pointer to this function appears in every
155 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
156 -- Build subprogram declaration for previous one
158 function Build_Lock_Free_Protected_Subprogram_Body
161 Unprot_Spec
: Node_Id
) return Node_Id
;
162 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
163 -- the subprogram specification of the unprotected version of N. Transform
164 -- N such that it invokes the unprotected version of the body.
166 function Build_Lock_Free_Unprotected_Subprogram_Body
168 Prot_Typ
: Node_Id
) return Node_Id
;
169 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
170 -- of N where the original statements of N are synchronized through atomic
171 -- actions such as compare and exchange. Prior to invoking this routine, it
172 -- has been established that N can be implemented in a lock-free fashion.
174 function Build_Parameter_Block
178 Decls
: List_Id
) return Entity_Id
;
179 -- Generate an access type for each actual parameter in the list Actuals.
180 -- Create an encapsulating record that contains all the actuals and return
181 -- its type. Generate:
182 -- type Ann1 is access all <actual1-type>
184 -- type AnnN is access all <actualN-type>
185 -- type Pnn is record
191 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
);
192 -- Build body of wrapper procedure for an entry or entry family that has
193 -- pre/postconditions. The body gathers the PPC's and expands them in the
194 -- usual way, and performs the entry call itself. This way preconditions
195 -- are evaluated before the call is queued. E is the entry in question,
196 -- and Decl is the enclosing synchronized type declaration at whose
197 -- freeze point the generated body is analyzed.
199 function Build_Protected_Entry
202 Pid
: Node_Id
) return Node_Id
;
203 -- Build the procedure implementing the statement sequence of the specified
206 function Build_Protected_Entry_Specification
209 Ent_Id
: Entity_Id
) return Node_Id
;
210 -- Build a specification for the procedure implementing the statements of
211 -- the specified entry body. Add attributes associating it with the entry
212 -- defining identifier Ent_Id.
214 function Build_Protected_Spec
216 Obj_Type
: Entity_Id
;
218 Unprotected
: Boolean := False) return List_Id
;
219 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
220 -- Subprogram_Type. Builds signature of protected subprogram, adding the
221 -- formal that corresponds to the object itself. For an access to protected
222 -- subprogram, there is no object type to specify, so the parameter has
223 -- type Address and mode In. An indirect call through such a pointer will
224 -- convert the address to a reference to the actual object. The object is
225 -- a limited record and therefore a by_reference type.
227 function Build_Protected_Subprogram_Body
230 N_Op_Spec
: Node_Id
) return Node_Id
;
231 -- This function is used to construct the protected version of a protected
232 -- subprogram. Its statement sequence first defers abort, then locks
233 -- the associated protected object, and then enters a block that contains
234 -- a call to the unprotected version of the subprogram (for details, see
235 -- Build_Unprotected_Subprogram_Body). This block statement requires
236 -- a cleanup handler that unlocks the object in all cases.
237 -- (see Exp_Ch7.Expand_Cleanup_Actions).
239 function Build_Renamed_Formal_Declaration
243 Renamed_Formal
: Node_Id
) return Node_Id
;
244 -- Create a renaming declaration for a formal, within a protected entry
245 -- body or an accept body. The renamed object is a component of the
246 -- parameter block that is a parameter in the entry call.
248 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
249 -- does not dereference the corresponding component to prevent an illegal
250 -- use of the incomplete type (AI05-0151).
252 function Build_Selected_Name
254 Selector
: Entity_Id
;
255 Append_Char
: Character := ' ') return Name_Id
;
256 -- Build a name in the form of Prefix__Selector, with an optional
257 -- character appended. This is used for internal subprograms generated
258 -- for operations of protected types, including barrier functions.
259 -- For the subprograms generated for entry bodies and entry barriers,
260 -- the generated name includes a sequence number that makes names
261 -- unique in the presence of entry overloading. This is necessary
262 -- because entry body procedures and barrier functions all have the
265 procedure Build_Simple_Entry_Call
270 -- Some comments here would be useful ???
272 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
273 -- This routine constructs a specification for the procedure that we will
274 -- build for the task body for task type T. The spec has the form:
276 -- procedure tnameB (_Task : access tnameV);
278 -- where name is the character name taken from the task type entity that
279 -- is passed as the argument to the procedure, and tnameV is the task
280 -- value type that is associated with the task type.
282 function Build_Unprotected_Subprogram_Body
284 Pid
: Node_Id
) return Node_Id
;
285 -- This routine constructs the unprotected version of a protected
286 -- subprogram body, which is contains all of the code in the
287 -- original, unexpanded body. This is the version of the protected
288 -- subprogram that is called from all protected operations on the same
289 -- object, including the protected version of the same subprogram.
291 procedure Build_Wrapper_Bodies
295 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
296 -- record of a concurrent type. N is the insertion node where all bodies
297 -- will be placed. This routine builds the bodies of the subprograms which
298 -- serve as an indirection mechanism to overriding primitives of concurrent
299 -- types, entries and protected procedures. Any new body is analyzed.
301 procedure Build_Wrapper_Specs
305 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
306 -- record of a concurrent type. N is the insertion node where all specs
307 -- will be placed. This routine builds the specs of the subprograms which
308 -- serve as an indirection mechanism to overriding primitives of concurrent
309 -- types, entries and protected procedures. Any new spec is analyzed.
311 procedure Collect_Entry_Families
314 Current_Node
: in out Node_Id
;
315 Conctyp
: Entity_Id
);
316 -- For each entry family in a concurrent type, create an anonymous array
317 -- type of the right size, and add a component to the corresponding_record.
319 function Concurrent_Object
320 (Spec_Id
: Entity_Id
;
321 Conc_Typ
: Entity_Id
) return Entity_Id
;
322 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
323 -- the entity associated with the concurrent object in the Protected_Body_
324 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
325 -- denotes formal parameter _O, _object or _task.
327 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
328 -- Copy the result type of a function specification, when building the
329 -- internal operation corresponding to a protected function, or when
330 -- expanding an access to protected function. If the result is an anonymous
331 -- access to subprogram itself, we need to create a new signature with the
332 -- same parameter names and the same resolved types, but with new entities
335 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
336 -- Decls is a list which may contain the declarations created by Install_
337 -- Private_Data_Declarations. All generated entities are marked as needing
338 -- debug info and debug nodes are manually generation where necessary. This
339 -- step of the expansion must to be done after private data has been moved
340 -- to its final resting scope to ensure proper visibility of debug objects.
342 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
343 -- If control flow optimizations are suppressed, and Alt is an accept,
344 -- delay, or entry call alternative with no trailing statements, insert a
345 -- null trailing statement with the given Loc (which is the sloc of the
346 -- accept, delay, or entry call statement). There might not be any
347 -- generated code for the accept, delay, or entry call itself (the
348 -- effect of these statements is part of the general processsing done
349 -- for the enclosing selective accept, timed entry call, or asynchronous
350 -- select), and the null statement is there to carry the sloc of that
351 -- statement to the back-end for trace-based coverage analysis purposes.
353 procedure Extract_Dispatching_Call
355 Call_Ent
: out Entity_Id
;
356 Object
: out Entity_Id
;
357 Actuals
: out List_Id
;
358 Formals
: out List_Id
);
359 -- Given a dispatching call, extract the entity of the name of the call,
360 -- its actual dispatching object, its actual parameters and the formal
361 -- parameters of the overridden interface-level version. If the type of
362 -- the dispatching object is an access type then an explicit dereference
363 -- is returned in Object.
365 procedure Extract_Entry
367 Concval
: out Node_Id
;
369 Index
: out Node_Id
);
370 -- Given an entry call, returns the associated concurrent object,
371 -- the entry name, and the entry family index.
373 function Family_Offset
378 Cap
: Boolean) return Node_Id
;
379 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in
380 -- an accept statement, or the upper bound in the discrete subtype of
381 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
382 -- the concurrent type of the entry. If Cap is true, the result is
383 -- capped according to Entry_Family_Bound.
390 Cap
: Boolean) return Node_Id
;
391 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
392 -- a family, and handle properly the superflat case. This is equivalent
393 -- to the use of 'Length on the index type, but must use Family_Offset
394 -- to handle properly the case of bounds that depend on discriminants.
395 -- If Cap is true, the result is capped according to Entry_Family_Bound.
397 procedure Find_Enclosing_Context
399 Context
: out Node_Id
;
400 Context_Id
: out Entity_Id
;
401 Context_Decls
: out List_Id
);
402 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
403 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
404 -- nearest enclosing body, block, package or return statement and return
405 -- its constituents. Context is the enclosing construct, Context_Id is
406 -- the scope of Context_Id and Context_Decls is the declarative list of
409 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
410 -- Given a subprogram identifier, return the entity which is associated
411 -- with the protection entry index in the Protected_Body_Subprogram or the
412 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
415 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
416 -- Tell whether a given subprogram cannot raise an exception
418 function Is_Potentially_Large_Family
419 (Base_Index
: Entity_Id
;
422 Hi
: Node_Id
) return Boolean;
424 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
425 -- Determine whether Id is a function or a procedure and is marked as a
426 -- private primitive.
428 function Null_Statements
(Stats
: List_Id
) return Boolean;
429 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
430 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
431 -- well to still count as null. Returns True for a null sequence. The
432 -- argument is the list of statements from the DO-END sequence.
434 function Parameter_Block_Pack
440 Stmts
: List_Id
) return Entity_Id
;
441 -- Set the components of the generated parameter block with the values of
442 -- the actual parameters. Generate aliased temporaries to capture the
443 -- values for types that are passed by copy. Otherwise generate a reference
444 -- to the actual's value. Return the address of the aggregate block.
446 -- Jnn1 : alias <formal-type1>;
447 -- Jnn1 := <actual1>;
450 -- Jnn1'unchecked_access;
451 -- <actual2>'reference;
454 function Parameter_Block_Unpack
458 Formals
: List_Id
) return List_Id
;
459 -- Retrieve the values of the components from the parameter block and
460 -- assign then to the original actual parameters. Generate:
461 -- <actual1> := P.<formal1>;
463 -- <actualN> := P.<formalN>;
465 function Trivial_Accept_OK
return Boolean;
466 -- If there is no DO-END block for an accept, or if the DO-END block has
467 -- only null statements, then it is possible to do the Rendezvous with much
468 -- less overhead using the Accept_Trivial routine in the run-time library.
469 -- However, this is not always a valid optimization. Whether it is valid or
470 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
471 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
472 -- a rescheduling is required, so this optimization is not allowed. This
473 -- function returns True if the optimization is permitted.
475 -----------------------------
476 -- Actual_Index_Expression --
477 -----------------------------
479 function Actual_Index_Expression
483 Tsk
: Entity_Id
) return Node_Id
485 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
493 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
494 -- Compute difference between bounds of entry family
496 --------------------------
497 -- Actual_Family_Offset --
498 --------------------------
500 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
502 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
503 -- Replace a reference to a discriminant with a selected component
504 -- denoting the discriminant of the target task.
506 -----------------------------
507 -- Actual_Discriminant_Ref --
508 -----------------------------
510 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
511 Typ
: constant Entity_Id
:= Etype
(Bound
);
515 if not Is_Entity_Name
(Bound
)
516 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
518 if Nkind
(Bound
) = N_Attribute_Reference
then
521 B
:= New_Copy_Tree
(Bound
);
526 Make_Selected_Component
(Sloc
,
527 Prefix
=> New_Copy_Tree
(Tsk
),
528 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
530 Analyze_And_Resolve
(B
, Typ
);
534 Make_Attribute_Reference
(Sloc
,
535 Attribute_Name
=> Name_Pos
,
536 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
537 Expressions
=> New_List
(B
));
538 end Actual_Discriminant_Ref
;
540 -- Start of processing for Actual_Family_Offset
544 Make_Op_Subtract
(Sloc
,
545 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
546 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
547 end Actual_Family_Offset
;
549 -- Start of processing for Actual_Index_Expression
552 -- The queues of entries and entry families appear in textual order in
553 -- the associated record. The entry index is computed as the sum of the
554 -- number of queues for all entries that precede the designated one, to
555 -- which is added the index expression, if this expression denotes a
556 -- member of a family.
558 -- The following is a place holder for the count of simple entries
560 Num
:= Make_Integer_Literal
(Sloc
, 1);
562 -- We construct an expression which is a series of addition operations.
563 -- See comments in Entry_Index_Expression, which is identical in
566 if Present
(Index
) then
567 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
574 Actual_Family_Offset
(
575 Make_Attribute_Reference
(Sloc
,
576 Attribute_Name
=> Name_Pos
,
577 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
578 Expressions
=> New_List
(Relocate_Node
(Index
))),
579 Type_Low_Bound
(S
)));
584 -- Now add lengths of preceding entries and entry families
586 Prev
:= First_Entity
(Ttyp
);
588 while Chars
(Prev
) /= Chars
(Ent
)
589 or else (Ekind
(Prev
) /= Ekind
(Ent
))
590 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
592 if Ekind
(Prev
) = E_Entry
then
593 Set_Intval
(Num
, Intval
(Num
) + 1);
595 elsif Ekind
(Prev
) = E_Entry_Family
then
597 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
599 -- The need for the following full view retrieval stems from
600 -- this complex case of nested generics and tasking:
603 -- type Formal_Index is range <>;
606 -- type Index is private;
613 -- type Index is new Formal_Index range 1 .. 10;
616 -- package body Outer is
618 -- entry Fam (Index); -- (2)
621 -- package body Inner is -- (3)
629 -- We are currently building the index expression for the entry
630 -- call "T.E" (1). Part of the expansion must mention the range
631 -- of the discrete type "Index" (2) of entry family "Fam".
632 -- However only the private view of type "Index" is available to
633 -- the inner generic (3) because there was no prior mention of
634 -- the type inside "Inner". This visibility requirement is
635 -- implicit and cannot be detected during the construction of
636 -- the generic trees and needs special handling.
639 and then Is_Private_Type
(S
)
640 and then Present
(Full_View
(S
))
645 Lo
:= Type_Low_Bound
(S
);
646 Hi
:= Type_High_Bound
(S
);
654 Actual_Family_Offset
(Hi
, Lo
),
656 Make_Integer_Literal
(Sloc
, 1)));
658 -- Other components are anonymous types to be ignored
668 end Actual_Index_Expression
;
670 --------------------------
671 -- Add_Formal_Renamings --
672 --------------------------
674 procedure Add_Formal_Renamings
680 Ptr
: constant Entity_Id
:=
682 (Next
(First
(Parameter_Specifications
(Spec
))));
683 -- The name of the formal that holds the address of the parameter block
690 Renamed_Formal
: Node_Id
;
693 Formal
:= First_Formal
(Ent
);
694 while Present
(Formal
) loop
695 Comp
:= Entry_Component
(Formal
);
697 Make_Defining_Identifier
(Sloc
(Formal
),
698 Chars
=> Chars
(Formal
));
699 Set_Etype
(New_F
, Etype
(Formal
));
700 Set_Scope
(New_F
, Ent
);
702 -- Now we set debug info needed on New_F even though it does not
703 -- come from source, so that the debugger will get the right
704 -- information for these generated names.
706 Set_Debug_Info_Needed
(New_F
);
708 if Ekind
(Formal
) = E_In_Parameter
then
709 Set_Ekind
(New_F
, E_Constant
);
711 Set_Ekind
(New_F
, E_Variable
);
712 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
715 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
718 Make_Selected_Component
(Loc
,
720 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
721 Make_Identifier
(Loc
, Chars
(Ptr
))),
722 Selector_Name
=> New_Reference_To
(Comp
, Loc
));
725 Build_Renamed_Formal_Declaration
726 (New_F
, Formal
, Comp
, Renamed_Formal
);
728 Append
(Decl
, Decls
);
729 Set_Renamed_Object
(Formal
, New_F
);
730 Next_Formal
(Formal
);
732 end Add_Formal_Renamings
;
734 ------------------------
735 -- Add_Object_Pointer --
736 ------------------------
738 procedure Add_Object_Pointer
740 Conc_Typ
: Entity_Id
;
743 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
748 -- Create the renaming declaration for the Protection object of a
749 -- protected type. _Object is used by Complete_Entry_Body.
750 -- ??? An attempt to make this a renaming was unsuccessful.
752 -- Build the entity for the access type
755 Make_Defining_Identifier
(Loc
,
756 New_External_Name
(Chars
(Rec_Typ
), 'P'));
759 -- _object : poVP := poVP!O;
762 Make_Object_Declaration
(Loc
,
763 Defining_Identifier
=>
764 Make_Defining_Identifier
(Loc
, Name_uObject
),
766 New_Reference_To
(Obj_Ptr
, Loc
),
768 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
769 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
770 Prepend_To
(Decls
, Decl
);
773 -- type poVP is access poV;
776 Make_Full_Type_Declaration
(Loc
,
777 Defining_Identifier
=>
780 Make_Access_To_Object_Definition
(Loc
,
781 Subtype_Indication
=>
782 New_Reference_To
(Rec_Typ
, Loc
)));
783 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
784 Prepend_To
(Decls
, Decl
);
785 end Add_Object_Pointer
;
787 -----------------------
788 -- Build_Accept_Body --
789 -----------------------
791 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
792 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
793 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
800 -- At the end of the statement sequence, Complete_Rendezvous is called.
801 -- A label skipping the Complete_Rendezvous, and all other accept
802 -- processing, has already been added for the expansion of requeue
803 -- statements. The Sloc is copied from the last statement since it
804 -- is really part of this last statement.
808 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
809 Insert_Before
(Last
(Statements
(Stats
)), Call
);
812 -- If exception handlers are present, then append Complete_Rendezvous
813 -- calls to the handlers, and construct the required outer block. As
814 -- above, the Sloc is copied from the last statement in the sequence.
816 if Present
(Exception_Handlers
(Stats
)) then
817 Hand
:= First
(Exception_Handlers
(Stats
));
818 while Present
(Hand
) loop
821 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
822 Append
(Call
, Statements
(Hand
));
828 Make_Handled_Sequence_Of_Statements
(Loc
,
829 Statements
=> New_List
(
830 Make_Block_Statement
(Loc
,
831 Handled_Statement_Sequence
=> Stats
)));
837 -- At this stage we know that the new statement sequence does not
838 -- have an exception handler part, so we supply one to call
839 -- Exceptional_Complete_Rendezvous. This handler is
841 -- when all others =>
842 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
844 -- We handle Abort_Signal to make sure that we properly catch the abort
845 -- case and wake up the caller.
847 Ohandle
:= Make_Others_Choice
(Loc
);
848 Set_All_Others
(Ohandle
);
850 Set_Exception_Handlers
(New_S
,
852 Make_Implicit_Exception_Handler
(Loc
,
853 Exception_Choices
=> New_List
(Ohandle
),
855 Statements
=> New_List
(
856 Make_Procedure_Call_Statement
(Sloc
(Stats
),
857 Name
=> New_Reference_To
(
858 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
859 Parameter_Associations
=> New_List
(
860 Make_Function_Call
(Sloc
(Stats
),
861 Name
=> New_Reference_To
(
862 RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))))))));
864 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
865 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
866 Expand_Exception_Handlers
(New_S
);
868 -- Exceptional_Complete_Rendezvous must be called with abort
869 -- still deferred, which is the case for a "when all others" handler.
872 end Build_Accept_Body
;
874 -----------------------------------
875 -- Build_Activation_Chain_Entity --
876 -----------------------------------
878 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
879 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
880 -- Determine whether an extended return statement has an activation
883 --------------------------
884 -- Has_Activation_Chain --
885 --------------------------
887 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
891 Decl
:= First
(Return_Object_Declarations
(Stmt
));
892 while Present
(Decl
) loop
893 if Nkind
(Decl
) = N_Object_Declaration
894 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
903 end Has_Activation_Chain
;
908 Context_Id
: Entity_Id
;
911 -- Start of processing for Build_Activation_Chain_Entity
914 -- Activation chain is never used for sequential elaboration policy, see
915 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
917 if Partition_Elaboration_Policy
= 'S' then
921 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
923 -- If activation chain entity has not been declared already, create one
925 if Nkind
(Context
) = N_Extended_Return_Statement
926 or else No
(Activation_Chain_Entity
(Context
))
928 -- Since extended return statements do not store the entity of the
929 -- chain, examine the return object declarations to avoid creating
932 if Nkind
(Context
) = N_Extended_Return_Statement
933 and then Has_Activation_Chain
(Context
)
939 Loc
: constant Source_Ptr
:= Sloc
(Context
);
944 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
946 -- Note: An extended return statement is not really a task
947 -- activator, but it does have an activation chain on which to
948 -- store the tasks temporarily. On successful return, the tasks
949 -- on this chain are moved to the chain passed in by the caller.
950 -- We do not build an Activation_Chain_Entity for an extended
951 -- return statement, because we do not want to build a call to
952 -- Activate_Tasks. Task activation is the responsibility of the
955 if Nkind
(Context
) /= N_Extended_Return_Statement
then
956 Set_Activation_Chain_Entity
(Context
, Chain
);
960 Make_Object_Declaration
(Loc
,
961 Defining_Identifier
=> Chain
,
962 Aliased_Present
=> True,
964 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
));
966 Prepend_To
(Decls
, Decl
);
968 -- Ensure that the _chain appears in the proper scope of the
971 if Context_Id
/= Current_Scope
then
972 Push_Scope
(Context_Id
);
980 end Build_Activation_Chain_Entity
;
982 ----------------------------
983 -- Build_Barrier_Function --
984 ----------------------------
986 function Build_Barrier_Function
989 Pid
: Node_Id
) return Node_Id
991 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
992 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
993 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
994 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
995 Op_Decls
: constant List_Id
:= New_List
;
1000 -- Add a declaration for the Protection object, renaming declarations
1001 -- for the discriminals and privals and finally a declaration for the
1002 -- entry family index (if applicable).
1004 Install_Private_Data_Declarations
(Sloc
(N
),
1010 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1012 -- If compiling with -fpreserve-control-flow, make sure we insert an
1013 -- IF statement so that the back-end knows to generate a conditional
1014 -- branch instruction, even if the condition is just the name of a
1017 if Opt
.Suppress_Control_Flow_Optimizations
then
1018 Stmt
:= Make_Implicit_If_Statement
(Cond
,
1020 Then_Statements
=> New_List
(
1021 Make_Simple_Return_Statement
(Loc
,
1022 New_Occurrence_Of
(Standard_True
, Loc
))),
1023 Else_Statements
=> New_List
(
1024 Make_Simple_Return_Statement
(Loc
,
1025 New_Occurrence_Of
(Standard_False
, Loc
))));
1028 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1031 -- Note: the condition in the barrier function needs to be properly
1032 -- processed for the C/Fortran boolean possibility, but this happens
1033 -- automatically since the return statement does this normalization.
1036 Make_Subprogram_Body
(Loc
,
1038 Build_Barrier_Function_Specification
(Loc
,
1039 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1040 Declarations
=> Op_Decls
,
1041 Handled_Statement_Sequence
=>
1042 Make_Handled_Sequence_Of_Statements
(Loc
,
1043 Statements
=> New_List
(Stmt
)));
1044 Set_Is_Entry_Barrier_Function
(Func_Body
);
1047 end Build_Barrier_Function
;
1049 ------------------------------------------
1050 -- Build_Barrier_Function_Specification --
1051 ------------------------------------------
1053 function Build_Barrier_Function_Specification
1055 Def_Id
: Entity_Id
) return Node_Id
1058 Set_Debug_Info_Needed
(Def_Id
);
1060 return Make_Function_Specification
(Loc
,
1061 Defining_Unit_Name
=> Def_Id
,
1062 Parameter_Specifications
=> New_List
(
1063 Make_Parameter_Specification
(Loc
,
1064 Defining_Identifier
=>
1065 Make_Defining_Identifier
(Loc
, Name_uO
),
1067 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1069 Make_Parameter_Specification
(Loc
,
1070 Defining_Identifier
=>
1071 Make_Defining_Identifier
(Loc
, Name_uE
),
1073 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1075 Result_Definition
=>
1076 New_Reference_To
(Standard_Boolean
, Loc
));
1077 end Build_Barrier_Function_Specification
;
1079 --------------------------
1080 -- Build_Call_With_Task --
1081 --------------------------
1083 function Build_Call_With_Task
1085 E
: Entity_Id
) return Node_Id
1087 Loc
: constant Source_Ptr
:= Sloc
(N
);
1090 Make_Function_Call
(Loc
,
1091 Name
=> New_Reference_To
(E
, Loc
),
1092 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1093 end Build_Call_With_Task
;
1095 -----------------------------
1096 -- Build_Class_Wide_Master --
1097 -----------------------------
1099 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1100 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1101 Master_Id
: Entity_Id
;
1102 Master_Scope
: Entity_Id
;
1104 Related_Node
: Node_Id
;
1108 -- Nothing to do if there is no task hierarchy
1110 if Restriction_Active
(No_Task_Hierarchy
) then
1114 -- Find the declaration that created the access type. It is either a
1115 -- type declaration, or an object declaration with an access definition,
1116 -- in which case the type is anonymous.
1118 if Is_Itype
(Typ
) then
1119 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1121 Related_Node
:= Parent
(Typ
);
1124 Master_Scope
:= Find_Master_Scope
(Typ
);
1126 -- Nothing to do if the master scope already contains a _master entity.
1127 -- The only exception to this is the following scenario:
1130 -- Transient_Scope_1
1133 -- Transient_Scope_2
1136 -- In this case the source scope is marked as having the master entity
1137 -- even though the actual declaration appears inside an inner scope. If
1138 -- the second transient scope requires a _master, it cannot use the one
1139 -- already declared because the entity is not visible.
1141 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1143 if not Has_Master_Entity
(Master_Scope
)
1144 or else No
(Current_Entity_In_Scope
(Name_Id
))
1147 Master_Decl
: Node_Id
;
1150 Set_Has_Master_Entity
(Master_Scope
);
1153 -- _master : constant Integer := Current_Master.all;
1156 Make_Object_Declaration
(Loc
,
1157 Defining_Identifier
=>
1158 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1159 Constant_Present
=> True,
1160 Object_Definition
=>
1161 New_Reference_To
(Standard_Integer
, Loc
),
1163 Make_Explicit_Dereference
(Loc
,
1164 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
1166 Insert_Action
(Related_Node
, Master_Decl
);
1167 Analyze
(Master_Decl
);
1169 -- Mark the containing scope as a task master. Masters associated
1170 -- with return statements are already marked at this stage (see
1171 -- Analyze_Subprogram_Body).
1173 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1175 Par
: Node_Id
:= Related_Node
;
1178 while Nkind
(Par
) /= N_Compilation_Unit
loop
1179 Par
:= Parent
(Par
);
1181 -- If we fall off the top, we are at the outer level, and
1182 -- the environment task is our effective master, so
1185 if Nkind_In
(Par
, N_Block_Statement
,
1189 Set_Is_Task_Master
(Par
);
1199 Make_Defining_Identifier
(Loc
,
1200 New_External_Name
(Chars
(Typ
), 'M'));
1203 -- Mnn renames _master;
1206 Make_Object_Renaming_Declaration
(Loc
,
1207 Defining_Identifier
=> Master_Id
,
1208 Subtype_Mark
=> New_Reference_To
(Standard_Integer
, Loc
),
1211 Insert_Action
(Related_Node
, Ren_Decl
);
1213 Set_Master_Id
(Typ
, Master_Id
);
1214 end Build_Class_Wide_Master
;
1216 --------------------------------
1217 -- Build_Corresponding_Record --
1218 --------------------------------
1220 function Build_Corresponding_Record
1223 Loc
: Source_Ptr
) return Node_Id
1225 Rec_Ent
: constant Entity_Id
:=
1226 Make_Defining_Identifier
1227 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1230 New_Disc
: Entity_Id
;
1234 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1235 Set_Ekind
(Rec_Ent
, E_Record_Type
);
1236 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1237 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1238 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1239 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1242 -- Use discriminals to create list of discriminants for record, and
1243 -- create new discriminals for use in default expressions, etc. It is
1244 -- worth noting that a task discriminant gives rise to 5 entities;
1246 -- a) The original discriminant.
1247 -- b) The discriminal for use in the task.
1248 -- c) The discriminant of the corresponding record.
1249 -- d) The discriminal for the init proc of the corresponding record.
1250 -- e) The local variable that renames the discriminant in the procedure
1251 -- for the task body.
1253 -- In fact the discriminals b) are used in the renaming declarations
1254 -- for e). See details in einfo (Handling of Discriminants).
1256 if Present
(Discriminant_Specifications
(N
)) then
1258 Disc
:= First_Discriminant
(Ctyp
);
1260 while Present
(Disc
) loop
1261 New_Disc
:= CR_Discriminant
(Disc
);
1264 Make_Discriminant_Specification
(Loc
,
1265 Defining_Identifier
=> New_Disc
,
1266 Discriminant_Type
=>
1267 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1269 New_Copy
(Discriminant_Default_Value
(Disc
))));
1271 Next_Discriminant
(Disc
);
1278 -- Now we can construct the record type declaration. Note that this
1279 -- record is "limited tagged". It is "limited" to reflect the underlying
1280 -- limitedness of the task or protected object that it represents, and
1281 -- ensuring for example that it is properly passed by reference. It is
1282 -- "tagged" to give support to dispatching calls through interfaces. We
1283 -- propagate here the list of interfaces covered by the concurrent type
1284 -- (Ada 2005: AI-345).
1287 Make_Full_Type_Declaration
(Loc
,
1288 Defining_Identifier
=> Rec_Ent
,
1289 Discriminant_Specifications
=> Dlist
,
1291 Make_Record_Definition
(Loc
,
1293 Make_Component_List
(Loc
,
1294 Component_Items
=> Cdecls
),
1296 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1297 Interface_List
=> Interface_List
(N
),
1298 Limited_Present
=> True));
1299 end Build_Corresponding_Record
;
1301 ----------------------------------
1302 -- Build_Entry_Count_Expression --
1303 ----------------------------------
1305 function Build_Entry_Count_Expression
1306 (Concurrent_Type
: Node_Id
;
1307 Component_List
: List_Id
;
1308 Loc
: Source_Ptr
) return Node_Id
1320 -- Count number of non-family entries
1323 Ent
:= First_Entity
(Concurrent_Type
);
1324 while Present
(Ent
) loop
1325 if Ekind
(Ent
) = E_Entry
then
1332 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1334 -- Loop through entry families building the addition nodes
1336 Ent
:= First_Entity
(Concurrent_Type
);
1337 Comp
:= First
(Component_List
);
1338 while Present
(Ent
) loop
1339 if Ekind
(Ent
) = E_Entry_Family
then
1340 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
1344 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1345 Hi
:= Type_High_Bound
(Typ
);
1346 Lo
:= Type_Low_Bound
(Typ
);
1347 Large
:= Is_Potentially_Large_Family
1348 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1351 Left_Opnd
=> Ecount
,
1352 Right_Opnd
=> Family_Size
1353 (Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1360 end Build_Entry_Count_Expression
;
1362 -----------------------
1363 -- Build_Entry_Names --
1364 -----------------------
1366 procedure Build_Entry_Names
1368 Obj_Typ
: Entity_Id
;
1371 Loc
: constant Source_Ptr
:= Sloc
(Obj_Ref
);
1372 Data
: Entity_Id
:= Empty
;
1373 Index
: Entity_Id
:= Empty
;
1374 Typ
: Entity_Id
:= Obj_Typ
;
1376 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
);
1377 -- Given an entry [family], create a static string which denotes the
1378 -- name of Comp_Id and assign it to the underlying data structure which
1379 -- contains the entry names of a concurrent object.
1381 function Object_Reference
return Node_Id
;
1382 -- Return a reference to field _object or _task_id depending on the
1383 -- concurrent object being processed.
1385 ----------------------
1386 -- Build_Entry_Name --
1387 ----------------------
1389 procedure Build_Entry_Name
(Comp_Id
: Entity_Id
) is
1390 function Build_Range
(Def
: Node_Id
) return Node_Id
;
1391 -- Given a discrete subtype definition of an entry family, generate a
1392 -- range node which covers the range of Def's type.
1394 procedure Create_Index_And_Data
;
1395 -- Generate the declarations of variables Index and Data. Subsequent
1396 -- calls do nothing.
1398 function Increment_Index
return Node_Id
;
1399 -- Increment the index used in the assignment of string names to the
1402 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
;
1403 -- Given the name of a temporary variable, create the following
1404 -- declaration for it:
1406 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1408 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
;
1409 -- Given the name of a temporary variable, place it in the array of
1410 -- string names. Generate:
1412 -- Data (Index) := Def_Id'Unchecked_Access;
1418 function Build_Range
(Def
: Node_Id
) return Node_Id
is
1419 High
: Node_Id
:= Type_High_Bound
(Etype
(Def
));
1420 Low
: Node_Id
:= Type_Low_Bound
(Etype
(Def
));
1423 -- If a bound references a discriminant, generate an identifier
1424 -- with the same name. Resolution will map it to the formals of
1427 if Is_Entity_Name
(Low
)
1428 and then Ekind
(Entity
(Low
)) = E_Discriminant
1431 Make_Selected_Component
(Loc
,
1432 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1433 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Low
)));
1435 Low
:= New_Copy_Tree
(Low
);
1438 if Is_Entity_Name
(High
)
1439 and then Ekind
(Entity
(High
)) = E_Discriminant
1442 Make_Selected_Component
(Loc
,
1443 Prefix
=> New_Copy_Tree
(Obj_Ref
),
1444 Selector_Name
=> Make_Identifier
(Loc
, Chars
(High
)));
1446 High
:= New_Copy_Tree
(High
);
1452 High_Bound
=> High
);
1455 ---------------------------
1456 -- Create_Index_And_Data --
1457 ---------------------------
1459 procedure Create_Index_And_Data
is
1461 if No
(Index
) and then No
(Data
) then
1468 if Is_Protected_Type
(Typ
) then
1469 Count
:= RO_PE_Number_Of_Entries
;
1470 Data_Typ
:= RE_Protected_Entry_Names_Array
;
1472 Count
:= RO_ST_Number_Of_Entries
;
1473 Data_Typ
:= RE_Task_Entry_Names_Array
;
1476 -- Step 1: Generate the declaration of the index variable:
1478 -- Index : Entry_Index := 1;
1480 Index
:= Make_Temporary
(Loc
, 'I');
1483 Make_Object_Declaration
(Loc
,
1484 Defining_Identifier
=> Index
,
1485 Object_Definition
=>
1486 New_Reference_To
(RTE
(RE_Entry_Index
), Loc
),
1487 Expression
=> Make_Integer_Literal
(Loc
, 1)));
1489 -- Step 2: Generate the declaration of an array to house all
1492 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1493 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1495 Size
:= Make_Temporary
(Loc
, 'S');
1498 Make_Object_Declaration
(Loc
,
1499 Defining_Identifier
=> Size
,
1500 Constant_Present
=> True,
1501 Object_Definition
=>
1502 New_Reference_To
(RTE
(RE_Entry_Index
), Loc
),
1504 Make_Function_Call
(Loc
,
1506 New_Reference_To
(RTE
(Count
), Loc
),
1507 Parameter_Associations
=>
1508 New_List
(Object_Reference
))));
1510 Data
:= Make_Temporary
(Loc
, 'A');
1513 Make_Object_Declaration
(Loc
,
1514 Defining_Identifier
=> Data
,
1515 Aliased_Present
=> True,
1516 Object_Definition
=>
1517 New_Reference_To
(RTE
(Data_Typ
), Loc
),
1519 Make_Aggregate
(Loc
,
1520 Component_Associations
=> New_List
(
1521 Make_Component_Association
(Loc
,
1522 Choices
=> New_List
(
1524 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
1525 High_Bound
=> New_Reference_To
(Size
, Loc
))),
1526 Expression
=> Make_Null
(Loc
))))));
1529 end Create_Index_And_Data
;
1531 ---------------------
1532 -- Increment_Index --
1533 ---------------------
1535 function Increment_Index
return Node_Id
is
1538 Make_Assignment_Statement
(Loc
,
1539 Name
=> New_Reference_To
(Index
, Loc
),
1542 Left_Opnd
=> New_Reference_To
(Index
, Loc
),
1543 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
1544 end Increment_Index
;
1546 ----------------------
1547 -- Name_Declaration --
1548 ----------------------
1550 function Name_Declaration
(Def_Id
: Entity_Id
) return Node_Id
is
1553 Make_Object_Declaration
(Loc
,
1554 Defining_Identifier
=> Def_Id
,
1555 Aliased_Present
=> True,
1556 Constant_Present
=> True,
1557 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
1559 Make_String_Literal
(Loc
, String_From_Name_Buffer
));
1560 end Name_Declaration
;
1562 --------------------
1563 -- Set_Entry_Name --
1564 --------------------
1566 function Set_Entry_Name
(Def_Id
: Entity_Id
) return Node_Id
is
1569 Make_Assignment_Statement
(Loc
,
1571 Make_Indexed_Component
(Loc
,
1572 Prefix
=> New_Reference_To
(Data
, Loc
),
1573 Expressions
=> New_List
(New_Reference_To
(Index
, Loc
))),
1576 Make_Attribute_Reference
(Loc
,
1577 Prefix
=> New_Reference_To
(Def_Id
, Loc
),
1578 Attribute_Name
=> Name_Unchecked_Access
));
1583 Temp_Id
: Entity_Id
;
1586 -- Start of processing for Build_Entry_Name
1589 if Ekind
(Comp_Id
) = E_Entry_Family
then
1590 Subt_Def
:= Discrete_Subtype_Definition
(Parent
(Comp_Id
));
1592 Create_Index_And_Data
;
1594 -- Step 1: Create the string name of the entry family.
1596 -- Temp : aliased constant String := "name ()";
1598 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1599 Get_Name_String
(Chars
(Comp_Id
));
1600 Add_Char_To_Name_Buffer
(' ');
1601 Add_Char_To_Name_Buffer
('(');
1602 Add_Char_To_Name_Buffer
(')');
1604 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1607 -- for Member in Family_Low .. Family_High loop
1608 -- Set_Entry_Name (...);
1609 -- Index := Index + 1;
1613 Make_Loop_Statement
(Loc
,
1615 Make_Iteration_Scheme
(Loc
,
1616 Loop_Parameter_Specification
=>
1617 Make_Loop_Parameter_Specification
(Loc
,
1618 Defining_Identifier
=>
1619 Make_Temporary
(Loc
, 'L'),
1620 Discrete_Subtype_Definition
=>
1621 Build_Range
(Subt_Def
))),
1623 Statements
=> New_List
(
1624 Set_Entry_Name
(Temp_Id
),
1626 End_Label
=> Empty
));
1631 Create_Index_And_Data
;
1633 -- Step 1: Create the string name of the entry. Generate:
1634 -- Temp : aliased constant String := "name";
1636 Temp_Id
:= Make_Temporary
(Loc
, 'S');
1637 Get_Name_String
(Chars
(Comp_Id
));
1639 Append_To
(Stmts
, Name_Declaration
(Temp_Id
));
1641 -- Step 2: Associate the string name with the underlying data
1644 Append_To
(Stmts
, Set_Entry_Name
(Temp_Id
));
1645 Append_To
(Stmts
, Increment_Index
);
1647 end Build_Entry_Name
;
1649 ----------------------
1650 -- Object_Reference --
1651 ----------------------
1653 function Object_Reference
return Node_Id
is
1654 Conc_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Typ
);
1659 if Is_Protected_Type
(Typ
) then
1660 Field
:= Name_uObject
;
1662 Field
:= Name_uTask_Id
;
1666 Make_Selected_Component
(Loc
,
1668 Unchecked_Convert_To
(Conc_Typ
, New_Copy_Tree
(Obj_Ref
)),
1669 Selector_Name
=> Make_Identifier
(Loc
, Field
));
1671 if Is_Protected_Type
(Typ
) then
1673 Make_Attribute_Reference
(Loc
,
1675 Attribute_Name
=> Name_Unchecked_Access
);
1679 end Object_Reference
;
1686 -- Start of processing for Build_Entry_Names
1689 -- Retrieve the original concurrent type
1691 if Is_Concurrent_Record_Type
(Typ
) then
1692 Typ
:= Corresponding_Concurrent_Type
(Typ
);
1695 pragma Assert
(Is_Concurrent_Type
(Typ
));
1697 -- Nothing to do if the type has no entries
1699 if not Has_Entries
(Typ
) then
1703 -- Avoid generating entry names for a protected type with only one entry
1705 if Is_Protected_Type
(Typ
)
1706 and then Find_Protection_Type
(Base_Type
(Typ
)) /=
1707 RTE
(RE_Protection_Entries
)
1712 -- Step 1: Populate the array with statically generated strings denoting
1713 -- entries and entry family names.
1715 Comp
:= First_Entity
(Typ
);
1716 while Present
(Comp
) loop
1717 if Comes_From_Source
(Comp
)
1718 and then Ekind_In
(Comp
, E_Entry
, E_Entry_Family
)
1720 Build_Entry_Name
(Comp
);
1726 -- Step 2: Associate the array with the related concurrent object:
1728 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1730 if Present
(Data
) then
1731 if Is_Protected_Type
(Typ
) then
1732 Proc
:= RO_PE_Set_Entry_Names
;
1734 Proc
:= RO_ST_Set_Entry_Names
;
1738 Make_Procedure_Call_Statement
(Loc
,
1739 Name
=> New_Reference_To
(RTE
(Proc
), Loc
),
1740 Parameter_Associations
=> New_List
(
1742 Make_Attribute_Reference
(Loc
,
1743 Prefix
=> New_Reference_To
(Data
, Loc
),
1744 Attribute_Name
=> Name_Unchecked_Access
))));
1746 end Build_Entry_Names
;
1748 ---------------------------
1749 -- Build_Parameter_Block --
1750 ---------------------------
1752 function Build_Parameter_Block
1756 Decls
: List_Id
) return Entity_Id
1762 Has_Comp
: Boolean := False;
1766 Actual
:= First
(Actuals
);
1768 Formal
:= Defining_Identifier
(First
(Formals
));
1770 while Present
(Actual
) loop
1771 if not Is_Controlling_Actual
(Actual
) then
1774 -- type Ann is access all <actual-type>
1776 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1779 Make_Full_Type_Declaration
(Loc
,
1780 Defining_Identifier
=> Comp_Nam
,
1782 Make_Access_To_Object_Definition
(Loc
,
1783 All_Present
=> True,
1784 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1785 Subtype_Indication
=>
1786 New_Reference_To
(Etype
(Actual
), Loc
))));
1792 Make_Component_Declaration
(Loc
,
1793 Defining_Identifier
=>
1794 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1795 Component_Definition
=>
1796 Make_Component_Definition
(Loc
,
1799 Subtype_Indication
=>
1800 New_Reference_To
(Comp_Nam
, Loc
))));
1805 Next_Actual
(Actual
);
1806 Next_Formal_With_Extras
(Formal
);
1809 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1814 -- type Pnn is record
1819 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1820 -- the original parameter names and Ann1 .. AnnN are the access to
1824 Make_Full_Type_Declaration
(Loc
,
1825 Defining_Identifier
=>
1828 Make_Record_Definition
(Loc
,
1830 Make_Component_List
(Loc
, Comps
))));
1833 -- type Pnn is null record;
1836 Make_Full_Type_Declaration
(Loc
,
1837 Defining_Identifier
=>
1840 Make_Record_Definition
(Loc
,
1841 Null_Present
=> True,
1842 Component_List
=> Empty
)));
1846 end Build_Parameter_Block
;
1848 --------------------------------------
1849 -- Build_Renamed_Formal_Declaration --
1850 --------------------------------------
1852 function Build_Renamed_Formal_Declaration
1856 Renamed_Formal
: Node_Id
) return Node_Id
1858 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1862 -- If the formal is a tagged incomplete type, it is already passed
1863 -- by reference, so it is sufficient to rename the pointer component
1864 -- that corresponds to the actual. Otherwise we need to dereference
1865 -- the pointer component to obtain the actual.
1867 if Is_Incomplete_Type
(Etype
(Formal
))
1868 and then Is_Tagged_Type
(Etype
(Formal
))
1871 Make_Object_Renaming_Declaration
(Loc
,
1872 Defining_Identifier
=> New_F
,
1873 Subtype_Mark
=> New_Reference_To
(Etype
(Comp
), Loc
),
1874 Name
=> Renamed_Formal
);
1878 Make_Object_Renaming_Declaration
(Loc
,
1879 Defining_Identifier
=> New_F
,
1880 Subtype_Mark
=> New_Reference_To
(Etype
(Formal
), Loc
),
1882 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1886 end Build_Renamed_Formal_Declaration
;
1888 -----------------------
1889 -- Build_PPC_Wrapper --
1890 -----------------------
1892 procedure Build_PPC_Wrapper
(E
: Entity_Id
; Decl
: Node_Id
) is
1893 Loc
: constant Source_Ptr
:= Sloc
(E
);
1894 Synch_Type
: constant Entity_Id
:= Scope
(E
);
1896 Wrapper_Id
: constant Entity_Id
:=
1897 Make_Defining_Identifier
(Loc
,
1898 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1899 -- the wrapper procedure name
1901 Wrapper_Body
: Node_Id
;
1903 Synch_Id
: constant Entity_Id
:=
1904 Make_Defining_Identifier
(Loc
,
1905 Chars
=> New_External_Name
(Chars
(Scope
(E
)), 'A'));
1906 -- The parameter that designates the synchronized object in the call
1908 Actuals
: constant List_Id
:= New_List
;
1909 -- The actuals in the entry call
1911 Decls
: constant List_Id
:= New_List
;
1913 Entry_Call
: Node_Id
;
1914 Entry_Name
: Node_Id
;
1917 -- The specification of the wrapper procedure
1921 -- Only build the wrapper if entry has pre/postconditions.
1922 -- Should this be done unconditionally instead ???
1928 P
:= Spec_PPC_List
(Contract
(E
));
1933 -- Transfer ppc pragmas to the declarations of the wrapper
1935 while Present
(P
) loop
1936 if Pragma_Name
(P
) = Name_Precondition
1937 or else Pragma_Name
(P
) = Name_Postcondition
1939 Append
(Relocate_Node
(P
), Decls
);
1940 Set_Analyzed
(Last
(Decls
), False);
1943 P
:= Next_Pragma
(P
);
1947 -- First formal is synchronized object
1950 Make_Parameter_Specification
(Loc
,
1951 Defining_Identifier
=> Synch_Id
,
1952 Out_Present
=> True,
1954 Parameter_Type
=> New_Occurrence_Of
(Scope
(E
), Loc
)));
1957 Make_Selected_Component
(Loc
,
1958 Prefix
=> New_Occurrence_Of
(Synch_Id
, Loc
),
1959 Selector_Name
=> New_Occurrence_Of
(E
, Loc
));
1961 -- If entity is entry family, second formal is the corresponding index,
1962 -- and entry name is an indexed component.
1964 if Ekind
(E
) = E_Entry_Family
then
1966 Index
: constant Entity_Id
:=
1967 Make_Defining_Identifier
(Loc
, Name_I
);
1970 Make_Parameter_Specification
(Loc
,
1971 Defining_Identifier
=> Index
,
1973 New_Occurrence_Of
(Entry_Index_Type
(E
), Loc
)));
1976 Make_Indexed_Component
(Loc
,
1977 Prefix
=> Entry_Name
,
1978 Expressions
=> New_List
(New_Occurrence_Of
(Index
, Loc
)));
1983 Make_Procedure_Call_Statement
(Loc
,
1985 Parameter_Associations
=> Actuals
);
1987 -- Now add formals that match those of the entry, and build actuals for
1988 -- the nested entry call.
1992 New_Form
: Entity_Id
;
1993 Parm_Spec
: Node_Id
;
1996 Form
:= First_Formal
(E
);
1997 while Present
(Form
) loop
1998 New_Form
:= Make_Defining_Identifier
(Loc
, Chars
(Form
));
2000 Make_Parameter_Specification
(Loc
,
2001 Defining_Identifier
=> New_Form
,
2002 Out_Present
=> Out_Present
(Parent
(Form
)),
2003 In_Present
=> In_Present
(Parent
(Form
)),
2004 Parameter_Type
=> New_Occurrence_Of
(Etype
(Form
), Loc
));
2006 Append
(Parm_Spec
, Specs
);
2007 Append
(New_Occurrence_Of
(New_Form
, Loc
), Actuals
);
2012 -- Add renaming declarations for the discriminants of the enclosing
2013 -- type, which may be visible in the preconditions.
2015 if Has_Discriminants
(Synch_Type
) then
2021 D
:= First_Discriminant
(Synch_Type
);
2022 while Present
(D
) loop
2024 Make_Object_Renaming_Declaration
(Loc
,
2025 Defining_Identifier
=>
2026 Make_Defining_Identifier
(Loc
, Chars
(D
)),
2027 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
2029 Make_Selected_Component
(Loc
,
2030 Prefix
=> New_Reference_To
(Synch_Id
, Loc
),
2031 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
2032 Prepend
(Decl
, Decls
);
2033 Next_Discriminant
(D
);
2038 Set_PPC_Wrapper
(E
, Wrapper_Id
);
2040 Make_Subprogram_Body
(Loc
,
2042 Make_Procedure_Specification
(Loc
,
2043 Defining_Unit_Name
=> Wrapper_Id
,
2044 Parameter_Specifications
=> Specs
),
2045 Declarations
=> Decls
,
2046 Handled_Statement_Sequence
=>
2047 Make_Handled_Sequence_Of_Statements
(Loc
,
2048 Statements
=> New_List
(Entry_Call
)));
2050 -- The wrapper body is analyzed when the enclosing type is frozen
2052 Append_Freeze_Action
(Defining_Entity
(Decl
), Wrapper_Body
);
2053 end Build_PPC_Wrapper
;
2055 --------------------------
2056 -- Build_Wrapper_Bodies --
2057 --------------------------
2059 procedure Build_Wrapper_Bodies
2064 Rec_Typ
: Entity_Id
;
2066 function Build_Wrapper_Body
2068 Subp_Id
: Entity_Id
;
2069 Obj_Typ
: Entity_Id
;
2070 Formals
: List_Id
) return Node_Id
;
2071 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2072 -- associated with a protected or task type. Subp_Id is the subprogram
2073 -- name which will be wrapped. Obj_Typ is the type of the new formal
2074 -- parameter which handles dispatching and object notation. Formals are
2075 -- the original formals of Subp_Id which will be explicitly replicated.
2077 ------------------------
2078 -- Build_Wrapper_Body --
2079 ------------------------
2081 function Build_Wrapper_Body
2083 Subp_Id
: Entity_Id
;
2084 Obj_Typ
: Entity_Id
;
2085 Formals
: List_Id
) return Node_Id
2087 Body_Spec
: Node_Id
;
2090 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
2092 -- The subprogram is not overriding or is not a primitive declared
2093 -- between two views.
2095 if No
(Body_Spec
) then
2100 Actuals
: List_Id
:= No_List
;
2102 First_Form
: Node_Id
;
2107 -- Map formals to actuals. Use the list built for the wrapper
2108 -- spec, skipping the object notation parameter.
2110 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
2112 Formal
:= First_Form
;
2115 if Present
(Formal
) then
2116 Actuals
:= New_List
;
2117 while Present
(Formal
) loop
2119 Make_Identifier
(Loc
,
2120 Chars
=> Chars
(Defining_Identifier
(Formal
))));
2125 -- Special processing for primitives declared between a private
2126 -- type and its completion: the wrapper needs a properly typed
2127 -- parameter if the wrapped operation has a controlling first
2128 -- parameter. Note that this might not be the case for a function
2129 -- with a controlling result.
2131 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
2132 if No
(Actuals
) then
2133 Actuals
:= New_List
;
2136 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
2137 Prepend_To
(Actuals
,
2138 Unchecked_Convert_To
2139 (Corresponding_Concurrent_Type
(Obj_Typ
),
2140 Make_Identifier
(Loc
, Name_uO
)));
2143 Prepend_To
(Actuals
,
2144 Make_Identifier
(Loc
,
2145 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
2148 Nam
:= New_Reference_To
(Subp_Id
, Loc
);
2150 -- An access-to-variable object parameter requires an explicit
2151 -- dereference in the unchecked conversion. This case occurs
2152 -- when a protected entry wrapper must override an interface
2153 -- level procedure with interface access as first parameter.
2155 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2157 if Nkind
(Parameter_Type
(First_Form
)) =
2161 Make_Explicit_Dereference
(Loc
,
2162 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
2164 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
2168 Make_Selected_Component
(Loc
,
2170 Unchecked_Convert_To
2171 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
2172 Selector_Name
=> New_Reference_To
(Subp_Id
, Loc
));
2175 -- Create the subprogram body. For a function, the call to the
2176 -- actual subprogram has to be converted to the corresponding
2177 -- record if it is a controlling result.
2179 if Ekind
(Subp_Id
) = E_Function
then
2185 Make_Function_Call
(Loc
,
2187 Parameter_Associations
=> Actuals
);
2189 if Has_Controlling_Result
(Subp_Id
) then
2191 Unchecked_Convert_To
2192 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
2196 Make_Subprogram_Body
(Loc
,
2197 Specification
=> Body_Spec
,
2198 Declarations
=> Empty_List
,
2199 Handled_Statement_Sequence
=>
2200 Make_Handled_Sequence_Of_Statements
(Loc
,
2201 Statements
=> New_List
(
2202 Make_Simple_Return_Statement
(Loc
, Res
))));
2207 Make_Subprogram_Body
(Loc
,
2208 Specification
=> Body_Spec
,
2209 Declarations
=> Empty_List
,
2210 Handled_Statement_Sequence
=>
2211 Make_Handled_Sequence_Of_Statements
(Loc
,
2212 Statements
=> New_List
(
2213 Make_Procedure_Call_Statement
(Loc
,
2215 Parameter_Associations
=> Actuals
))));
2218 end Build_Wrapper_Body
;
2220 -- Start of processing for Build_Wrapper_Bodies
2223 if Is_Concurrent_Type
(Typ
) then
2224 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2229 -- Generate wrapper bodies for a concurrent type which implements an
2232 if Present
(Interfaces
(Rec_Typ
)) then
2234 Insert_Nod
: Node_Id
;
2236 Prim_Elmt
: Elmt_Id
;
2237 Prim_Decl
: Node_Id
;
2239 Wrap_Body
: Node_Id
;
2240 Wrap_Id
: Entity_Id
;
2245 -- Examine all primitive operations of the corresponding record
2246 -- type, looking for wrapper specs. Generate bodies in order to
2249 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
2250 while Present
(Prim_Elmt
) loop
2251 Prim
:= Node
(Prim_Elmt
);
2253 if (Ekind
(Prim
) = E_Function
2254 or else Ekind
(Prim
) = E_Procedure
)
2255 and then Is_Primitive_Wrapper
(Prim
)
2257 Subp
:= Wrapped_Entity
(Prim
);
2258 Prim_Decl
:= Parent
(Parent
(Prim
));
2261 Build_Wrapper_Body
(Loc
,
2264 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
2265 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
2267 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
2268 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
2270 Insert_After
(Insert_Nod
, Wrap_Body
);
2271 Insert_Nod
:= Wrap_Body
;
2273 Analyze
(Wrap_Body
);
2276 Next_Elmt
(Prim_Elmt
);
2280 end Build_Wrapper_Bodies
;
2282 ------------------------
2283 -- Build_Wrapper_Spec --
2284 ------------------------
2286 function Build_Wrapper_Spec
2287 (Subp_Id
: Entity_Id
;
2288 Obj_Typ
: Entity_Id
;
2289 Formals
: List_Id
) return Node_Id
2291 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2292 First_Param
: Node_Id
;
2294 Iface_Elmt
: Elmt_Id
;
2295 Iface_Op
: Entity_Id
;
2296 Iface_Op_Elmt
: Elmt_Id
;
2298 function Overriding_Possible
2299 (Iface_Op
: Entity_Id
;
2300 Wrapper
: Entity_Id
) return Boolean;
2301 -- Determine whether a primitive operation can be overridden by Wrapper.
2302 -- Iface_Op is the candidate primitive operation of an interface type,
2303 -- Wrapper is the generated entry wrapper.
2305 function Replicate_Formals
2307 Formals
: List_Id
) return List_Id
;
2308 -- An explicit parameter replication is required due to the Is_Entry_
2309 -- Formal flag being set for all the formals of an entry. The explicit
2310 -- replication removes the flag that would otherwise cause a different
2311 -- path of analysis.
2313 -------------------------
2314 -- Overriding_Possible --
2315 -------------------------
2317 function Overriding_Possible
2318 (Iface_Op
: Entity_Id
;
2319 Wrapper
: Entity_Id
) return Boolean
2321 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
2322 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
2324 function Type_Conformant_Parameters
2325 (Iface_Op_Params
: List_Id
;
2326 Wrapper_Params
: List_Id
) return Boolean;
2327 -- Determine whether the parameters of the generated entry wrapper
2328 -- and those of a primitive operation are type conformant. During
2329 -- this check, the first parameter of the primitive operation is
2330 -- skipped if it is a controlling argument: protected functions
2331 -- may have a controlling result.
2333 --------------------------------
2334 -- Type_Conformant_Parameters --
2335 --------------------------------
2337 function Type_Conformant_Parameters
2338 (Iface_Op_Params
: List_Id
;
2339 Wrapper_Params
: List_Id
) return Boolean
2341 Iface_Op_Param
: Node_Id
;
2342 Iface_Op_Typ
: Entity_Id
;
2343 Wrapper_Param
: Node_Id
;
2344 Wrapper_Typ
: Entity_Id
;
2347 -- Skip the first (controlling) parameter of primitive operation
2349 Iface_Op_Param
:= First
(Iface_Op_Params
);
2351 if Present
(First_Formal
(Iface_Op
))
2352 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
2354 Iface_Op_Param
:= Next
(Iface_Op_Param
);
2357 Wrapper_Param
:= First
(Wrapper_Params
);
2358 while Present
(Iface_Op_Param
)
2359 and then Present
(Wrapper_Param
)
2361 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
2362 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
2364 -- The two parameters must be mode conformant
2366 if not Conforming_Types
2367 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
2372 Next
(Iface_Op_Param
);
2373 Next
(Wrapper_Param
);
2376 -- One of the lists is longer than the other
2378 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
2383 end Type_Conformant_Parameters
;
2385 -- Start of processing for Overriding_Possible
2388 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
2392 -- If an inherited subprogram is implemented by a protected procedure
2393 -- or an entry, then the first parameter of the inherited subprogram
2394 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2396 if Ekind
(Iface_Op
) = E_Procedure
2397 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2400 Obj_Param
: constant Node_Id
:=
2401 First
(Parameter_Specifications
(Iface_Op_Spec
));
2403 if not Out_Present
(Obj_Param
)
2404 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2413 Type_Conformant_Parameters
(
2414 Parameter_Specifications
(Iface_Op_Spec
),
2415 Parameter_Specifications
(Wrapper_Spec
));
2416 end Overriding_Possible
;
2418 -----------------------
2419 -- Replicate_Formals --
2420 -----------------------
2422 function Replicate_Formals
2424 Formals
: List_Id
) return List_Id
2426 New_Formals
: constant List_Id
:= New_List
;
2428 Param_Type
: Node_Id
;
2431 Formal
:= First
(Formals
);
2433 -- Skip the object parameter when dealing with primitives declared
2434 -- between two views.
2436 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2437 and then not Has_Controlling_Result
(Subp_Id
)
2439 Formal
:= Next
(Formal
);
2442 while Present
(Formal
) loop
2444 -- Create an explicit copy of the entry parameter
2446 -- When creating the wrapper subprogram for a primitive operation
2447 -- of a protected interface we must construct an equivalent
2448 -- signature to that of the overriding operation. For regular
2449 -- parameters we can just use the type of the formal, but for
2450 -- access to subprogram parameters we need to reanalyze the
2451 -- parameter type to create local entities for the signature of
2452 -- the subprogram type. Using the entities of the overriding
2453 -- subprogram will result in out-of-scope errors in the back-end.
2455 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2456 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2459 New_Reference_To
(Etype
(Parameter_Type
(Formal
)), Loc
);
2462 Append_To
(New_Formals
,
2463 Make_Parameter_Specification
(Loc
,
2464 Defining_Identifier
=>
2465 Make_Defining_Identifier
(Loc
,
2466 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2467 In_Present
=> In_Present
(Formal
),
2468 Out_Present
=> Out_Present
(Formal
),
2469 Parameter_Type
=> Param_Type
));
2475 end Replicate_Formals
;
2477 -- Start of processing for Build_Wrapper_Spec
2480 -- There is no point in building wrappers for non-tagged concurrent
2483 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2485 -- An entry or a protected procedure can override a routine where the
2486 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2487 -- type. Since the wrapper must have the exact same signature as that of
2488 -- the overridden subprogram, we try to find the overriding candidate
2489 -- and use its controlling formal.
2491 First_Param
:= Empty
;
2493 -- Check every implemented interface
2495 if Present
(Interfaces
(Obj_Typ
)) then
2496 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2497 Search
: while Present
(Iface_Elmt
) loop
2498 Iface
:= Node
(Iface_Elmt
);
2500 -- Check every interface primitive
2502 if Present
(Primitive_Operations
(Iface
)) then
2503 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2504 while Present
(Iface_Op_Elmt
) loop
2505 Iface_Op
:= Node
(Iface_Op_Elmt
);
2507 -- Ignore predefined primitives
2509 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2510 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2512 -- The current primitive operation can be overridden by
2513 -- the generated entry wrapper.
2515 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2517 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2523 Next_Elmt
(Iface_Op_Elmt
);
2527 Next_Elmt
(Iface_Elmt
);
2531 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2532 -- this subprogram and this is not a primitive declared between two
2533 -- views then force the generation of a wrapper. As an optimization,
2534 -- previous versions of the frontend avoid generating the wrapper;
2535 -- however, the wrapper facilitates locating and reporting an error
2536 -- when a duplicate declaration is found later. See example in
2540 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2543 (Corresponding_Concurrent_Type
(Obj_Typ
))
2546 Make_Parameter_Specification
(Loc
,
2547 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
2549 Out_Present
=> False,
2550 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2552 -- For entries and procedures of protected types the mode of
2553 -- the controlling argument must be in-out.
2557 Make_Parameter_Specification
(Loc
,
2558 Defining_Identifier
=>
2559 Make_Defining_Identifier
(Loc
,
2562 Out_Present
=> (Ekind
(Subp_Id
) /= E_Function
),
2563 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2568 Wrapper_Id
: constant Entity_Id
:=
2569 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2570 New_Formals
: List_Id
;
2571 Obj_Param
: Node_Id
;
2572 Obj_Param_Typ
: Entity_Id
;
2575 -- Minimum decoration is needed to catch the entity in
2576 -- Sem_Ch6.Override_Dispatching_Operation.
2578 if Ekind
(Subp_Id
) = E_Function
then
2579 Set_Ekind
(Wrapper_Id
, E_Function
);
2581 Set_Ekind
(Wrapper_Id
, E_Procedure
);
2584 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2585 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2586 Set_Is_Private_Primitive
(Wrapper_Id
,
2587 Is_Private_Primitive_Subprogram
(Subp_Id
));
2589 -- Process the formals
2591 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2593 -- A function with a controlling result and no first controlling
2594 -- formal needs no additional parameter.
2596 if Has_Controlling_Result
(Subp_Id
)
2598 (No
(First_Formal
(Subp_Id
))
2599 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2603 -- Routine Subp_Id has been found to override an interface primitive.
2604 -- If the interface operation has an access parameter, create a copy
2605 -- of it, with the same null exclusion indicator if present.
2607 elsif Present
(First_Param
) then
2608 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2610 Make_Access_Definition
(Loc
,
2612 New_Reference_To
(Obj_Typ
, Loc
));
2613 Set_Null_Exclusion_Present
(Obj_Param_Typ
,
2614 Null_Exclusion_Present
(Parameter_Type
(First_Param
)));
2617 Obj_Param_Typ
:= New_Reference_To
(Obj_Typ
, Loc
);
2621 Make_Parameter_Specification
(Loc
,
2622 Defining_Identifier
=>
2623 Make_Defining_Identifier
(Loc
,
2625 In_Present
=> In_Present
(First_Param
),
2626 Out_Present
=> Out_Present
(First_Param
),
2627 Parameter_Type
=> Obj_Param_Typ
);
2629 Prepend_To
(New_Formals
, Obj_Param
);
2631 -- If we are dealing with a primitive declared between two views,
2632 -- implemented by a synchronized operation, we need to create
2633 -- a default parameter. The mode of the parameter must match that
2634 -- of the primitive operation.
2637 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2639 Make_Parameter_Specification
(Loc
,
2640 Defining_Identifier
=>
2641 Make_Defining_Identifier
(Loc
, Name_uO
),
2642 In_Present
=> In_Present
(Parent
(First_Entity
(Subp_Id
))),
2643 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2644 Parameter_Type
=> New_Reference_To
(Obj_Typ
, Loc
));
2645 Prepend_To
(New_Formals
, Obj_Param
);
2648 -- Build the final spec. If it is a function with a controlling
2649 -- result, it is a primitive operation of the corresponding
2650 -- record type, so mark the spec accordingly.
2652 if Ekind
(Subp_Id
) = E_Function
then
2657 if Has_Controlling_Result
(Subp_Id
) then
2660 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2662 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2666 Make_Function_Specification
(Loc
,
2667 Defining_Unit_Name
=> Wrapper_Id
,
2668 Parameter_Specifications
=> New_Formals
,
2669 Result_Definition
=> Res_Def
);
2673 Make_Procedure_Specification
(Loc
,
2674 Defining_Unit_Name
=> Wrapper_Id
,
2675 Parameter_Specifications
=> New_Formals
);
2678 end Build_Wrapper_Spec
;
2680 -------------------------
2681 -- Build_Wrapper_Specs --
2682 -------------------------
2684 procedure Build_Wrapper_Specs
2690 Rec_Typ
: Entity_Id
;
2691 procedure Scan_Declarations
(L
: List_Id
);
2692 -- Common processing for visible and private declarations
2693 -- of a protected type.
2695 procedure Scan_Declarations
(L
: List_Id
) is
2697 Wrap_Decl
: Node_Id
;
2698 Wrap_Spec
: Node_Id
;
2706 while Present
(Decl
) loop
2709 if Nkind
(Decl
) = N_Entry_Declaration
2710 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2714 (Subp_Id
=> Defining_Identifier
(Decl
),
2716 Formals
=> Parameter_Specifications
(Decl
));
2718 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2721 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2724 Parameter_Specifications
(Specification
(Decl
)));
2727 if Present
(Wrap_Spec
) then
2729 Make_Subprogram_Declaration
(Loc
,
2730 Specification
=> Wrap_Spec
);
2732 Insert_After
(N
, Wrap_Decl
);
2735 Analyze
(Wrap_Decl
);
2740 end Scan_Declarations
;
2742 -- start of processing for Build_Wrapper_Specs
2745 if Is_Protected_Type
(Typ
) then
2746 Def
:= Protected_Definition
(Parent
(Typ
));
2747 else pragma Assert
(Is_Task_Type
(Typ
));
2748 Def
:= Task_Definition
(Parent
(Typ
));
2751 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2753 -- Generate wrapper specs for a concurrent type which implements an
2754 -- interface. Operations in both the visible and private parts may
2755 -- implement progenitor operations.
2757 if Present
(Interfaces
(Rec_Typ
))
2758 and then Present
(Def
)
2760 Scan_Declarations
(Visible_Declarations
(Def
));
2761 Scan_Declarations
(Private_Declarations
(Def
));
2763 end Build_Wrapper_Specs
;
2765 ---------------------------
2766 -- Build_Find_Body_Index --
2767 ---------------------------
2769 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2770 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2773 Has_F
: Boolean := False;
2775 If_St
: Node_Id
:= Empty
;
2778 Decls
: List_Id
:= New_List
;
2781 Siz
: Node_Id
:= Empty
;
2783 procedure Add_If_Clause
(Expr
: Node_Id
);
2784 -- Add test for range of current entry
2786 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2787 -- If a bound of an entry is given by a discriminant, retrieve the
2788 -- actual value of the discriminant from the enclosing object.
2794 procedure Add_If_Clause
(Expr
: Node_Id
) is
2796 Stats
: constant List_Id
:=
2798 Make_Simple_Return_Statement
(Loc
,
2799 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2802 -- Index for current entry body
2806 -- Compute total length of entry queues so far
2814 Right_Opnd
=> Expr
);
2819 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2822 -- Map entry queue indexes in the range of the current family
2823 -- into the current index, that designates the entry body.
2827 Make_Implicit_If_Statement
(Typ
,
2829 Then_Statements
=> Stats
,
2830 Elsif_Parts
=> New_List
);
2834 Append_To
(Elsif_Parts
(If_St
),
2835 Make_Elsif_Part
(Loc
,
2837 Then_Statements
=> Stats
));
2841 ------------------------------
2842 -- Convert_Discriminant_Ref --
2843 ------------------------------
2845 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2849 if Is_Entity_Name
(Bound
)
2850 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2853 Make_Selected_Component
(Loc
,
2855 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2856 Make_Explicit_Dereference
(Loc
,
2857 Make_Identifier
(Loc
, Name_uObject
))),
2858 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2859 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2861 B
:= New_Copy_Tree
(Bound
);
2865 end Convert_Discriminant_Ref
;
2867 -- Start of processing for Build_Find_Body_Index
2870 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2872 Ent
:= First_Entity
(Typ
);
2873 while Present
(Ent
) loop
2874 if Ekind
(Ent
) = E_Entry_Family
then
2884 -- If the protected type has no entry families, there is a one-one
2885 -- correspondence between entry queue and entry body.
2888 Make_Simple_Return_Statement
(Loc
,
2889 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2892 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2895 -- if E <= l1 then return 1;
2896 -- elsif E <= l1 + l2 then return 2;
2901 Ent
:= First_Entity
(Typ
);
2903 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2905 while Present
(Ent
) loop
2906 if Ekind
(Ent
) = E_Entry
then
2907 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2909 elsif Ekind
(Ent
) = E_Entry_Family
then
2910 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
2911 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2912 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2913 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2922 Make_Simple_Return_Statement
(Loc
,
2923 Expression
=> Make_Integer_Literal
(Loc
, 1));
2925 elsif Nkind
(Ret
) = N_If_Statement
then
2927 -- Ranges are in increasing order, so last one doesn't need guard
2930 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2933 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2939 Make_Subprogram_Body
(Loc
,
2940 Specification
=> Spec
,
2941 Declarations
=> Decls
,
2942 Handled_Statement_Sequence
=>
2943 Make_Handled_Sequence_Of_Statements
(Loc
,
2944 Statements
=> New_List
(Ret
)));
2945 end Build_Find_Body_Index
;
2947 --------------------------------
2948 -- Build_Find_Body_Index_Spec --
2949 --------------------------------
2951 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2952 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2953 Id
: constant Entity_Id
:=
2954 Make_Defining_Identifier
(Loc
,
2955 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2956 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2957 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2961 Make_Function_Specification
(Loc
,
2962 Defining_Unit_Name
=> Id
,
2963 Parameter_Specifications
=> New_List
(
2964 Make_Parameter_Specification
(Loc
,
2965 Defining_Identifier
=> Parm1
,
2967 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2969 Make_Parameter_Specification
(Loc
,
2970 Defining_Identifier
=> Parm2
,
2972 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2974 Result_Definition
=> New_Occurrence_Of
(
2975 RTE
(RE_Protected_Entry_Index
), Loc
));
2976 end Build_Find_Body_Index_Spec
;
2978 -----------------------------------------------
2979 -- Build_Lock_Free_Protected_Subprogram_Body --
2980 -----------------------------------------------
2982 function Build_Lock_Free_Protected_Subprogram_Body
2985 Unprot_Spec
: Node_Id
) return Node_Id
2987 Actuals
: constant List_Id
:= New_List
;
2988 Loc
: constant Source_Ptr
:= Sloc
(N
);
2989 Spec
: constant Node_Id
:= Specification
(N
);
2990 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
2992 Prot_Spec
: Node_Id
;
2996 -- Create the protected version of the body
2999 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
3001 -- Build the actual parameters which appear in the call to the
3002 -- unprotected version of the body.
3004 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
3005 while Present
(Formal
) loop
3007 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
3012 -- Function case, generate:
3013 -- return <Unprot_Func_Call>;
3015 if Nkind
(Spec
) = N_Function_Specification
then
3017 Make_Simple_Return_Statement
(Loc
,
3019 Make_Function_Call
(Loc
,
3021 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3022 Parameter_Associations
=> Actuals
));
3024 -- Procedure case, call the unprotected version
3028 Make_Procedure_Call_Statement
(Loc
,
3030 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
3031 Parameter_Associations
=> Actuals
);
3035 Make_Subprogram_Body
(Loc
,
3036 Declarations
=> Empty_List
,
3037 Specification
=> Prot_Spec
,
3038 Handled_Statement_Sequence
=>
3039 Make_Handled_Sequence_Of_Statements
(Loc
,
3040 Statements
=> New_List
(Stmt
)));
3041 end Build_Lock_Free_Protected_Subprogram_Body
;
3043 -------------------------------------------------
3044 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3045 -------------------------------------------------
3047 -- Procedures which meet the lock-free implementation requirements and
3048 -- reference a unique scalar component Comp are expanded in the following
3051 -- procedure P (...) is
3052 -- Expected_Comp : constant Comp_Type :=
3054 -- (System.Atomic_Primitives.Lock_Free_Read_N
3055 -- (_Object.Comp'Address));
3059 -- <original declarations before the object renaming declaration
3062 -- Desired_Comp : Comp_Type := Expected_Comp;
3063 -- Comp : Comp_Type renames Desired_Comp;
3065 -- <original delarations after the object renaming declaration
3069 -- <original statements>
3070 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3071 -- (_Object.Comp'Address,
3072 -- Interfaces.Unsigned_N (Expected_Comp),
3073 -- Interfaces.Unsigned_N (Desired_Comp));
3078 -- Each return and raise statement of P is transformed into an atomic
3081 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3082 -- (_Object.Comp'Address,
3083 -- Interfaces.Unsigned_N (Expected_Comp),
3084 -- Interfaces.Unsigned_N (Desired_Comp));
3086 -- <original statement>
3091 -- Functions which meet the lock-free implementation requirements and
3092 -- reference a unique scalar component Comp are expanded in the following
3095 -- function F (...) return ... is
3096 -- <original declarations before the object renaming declaration
3099 -- Expected_Comp : constant Comp_Type :=
3101 -- (System.Atomic_Primitives.Lock_Free_Read_N
3102 -- (_Object.Comp'Address));
3103 -- Comp : Comp_Type renames Expected_Comp;
3105 -- <original delarations after the object renaming declaration of
3109 -- <original statements>
3112 function Build_Lock_Free_Unprotected_Subprogram_Body
3114 Prot_Typ
: Node_Id
) return Node_Id
3116 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
3117 -- Subprograms which meet the lock-free implementation criteria are
3118 -- allowed to reference only one unique component. Return the prival
3119 -- of the said component.
3121 --------------------------
3122 -- Referenced_Component --
3123 --------------------------
3125 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
3128 Source_Comp
: Entity_Id
:= Empty
;
3131 -- Find the unique source component which N references in its
3134 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
3136 Element
: Lock_Free_Subprogram
renames
3137 Lock_Free_Subprogram_Table
.Table
(Index
);
3139 if Element
.Sub_Body
= N
then
3140 Source_Comp
:= Element
.Comp_Id
;
3146 if No
(Source_Comp
) then
3150 -- Find the prival which corresponds to the source component within
3151 -- the declarations of N.
3153 Decl
:= First
(Declarations
(N
));
3154 while Present
(Decl
) loop
3156 -- Privals appear as object renamings
3158 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
3159 Comp
:= Defining_Identifier
(Decl
);
3161 if Present
(Prival_Link
(Comp
))
3162 and then Prival_Link
(Comp
) = Source_Comp
3172 end Referenced_Component
;
3176 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
3177 Loc
: constant Source_Ptr
:= Sloc
(N
);
3178 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
3179 Decls
: List_Id
:= Declarations
(N
);
3181 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3184 -- Add renamings for the protection object, discriminals, privals and
3185 -- the entry index constant for use by debugger.
3187 Debug_Private_Data_Declarations
(Decls
);
3189 -- Perform the lock-free expansion when the subprogram references a
3190 -- protected component.
3192 if Present
(Comp
) then
3193 Protected_Component_Ref
: declare
3194 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
3195 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
3196 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
3198 Is_Procedure
: constant Boolean :=
3199 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
3200 -- Indicates if N is a protected procedure body
3202 Block_Decls
: List_Id
;
3203 Try_Write
: Entity_Id
;
3204 Desired_Comp
: Entity_Id
;
3207 Label_Id
: Entity_Id
:= Empty
;
3209 Expected_Comp
: Entity_Id
;
3212 New_Copy_List
(Statements
(Hand_Stmt_Seq
));
3214 Unsigned
: Entity_Id
;
3216 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
3217 -- Transform a single node if it is a return statement, a raise
3218 -- statement or a reference to Comp.
3220 procedure Process_Stmts
(Stmts
: List_Id
);
3221 -- Given a statement sequence Stmts, wrap any return or raise
3222 -- statements in the following manner:
3224 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3225 -- (_Object.Comp'Address,
3226 -- Interfaces.Unsigned_N (Expected_Comp),
3227 -- Interfaces.Unsigned_N (Desired_Comp))
3238 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
3240 procedure Wrap_Statement
(Stmt
: Node_Id
);
3241 -- Wrap an arbitrary statement inside an if statement where the
3242 -- condition does an atomic check on the state of the object.
3244 --------------------
3245 -- Wrap_Statement --
3246 --------------------
3248 procedure Wrap_Statement
(Stmt
: Node_Id
) is
3250 -- The first time through, create the declaration of a label
3251 -- which is used to skip the remainder of source statements
3252 -- if the state of the object has changed.
3254 if No
(Label_Id
) then
3256 Make_Identifier
(Loc
, New_External_Name
('L', 0));
3257 Set_Entity
(Label_Id
,
3258 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
3262 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3263 -- (_Object.Comp'Address,
3264 -- Interfaces.Unsigned_N (Expected_Comp),
3265 -- Interfaces.Unsigned_N (Desired_Comp))
3273 Make_Implicit_If_Statement
(N
,
3275 Make_Function_Call
(Loc
,
3277 New_Reference_To
(Try_Write
, Loc
),
3278 Parameter_Associations
=> New_List
(
3279 Make_Attribute_Reference
(Loc
,
3280 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3281 Attribute_Name
=> Name_Address
),
3283 Unchecked_Convert_To
(Unsigned
,
3284 New_Reference_To
(Expected_Comp
, Loc
)),
3286 Unchecked_Convert_To
(Unsigned
,
3287 New_Reference_To
(Desired_Comp
, Loc
)))),
3289 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
3291 Else_Statements
=> New_List
(
3292 Make_Goto_Statement
(Loc
,
3294 New_Reference_To
(Entity
(Label_Id
), Loc
)))));
3297 -- Start of processing for Process_Node
3300 -- Wrap each return and raise statement that appear inside a
3301 -- procedure. Skip the last return statement which is added by
3302 -- default since it is transformed into an exit statement.
3305 and then ((Nkind
(N
) = N_Simple_Return_Statement
3306 and then N
/= Last
(Stmts
))
3307 or else Nkind
(N
) = N_Extended_Return_Statement
3308 or else (Nkind_In
(N
, N_Raise_Constraint_Error
,
3309 N_Raise_Program_Error
,
3311 N_Raise_Storage_Error
)
3312 and then Comes_From_Source
(N
)))
3320 Set_Analyzed
(N
, False);
3325 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
3331 procedure Process_Stmts
(Stmts
: List_Id
) is
3334 Stmt
:= First
(Stmts
);
3335 while Present
(Stmt
) loop
3336 Process_Nodes
(Stmt
);
3341 -- Start of processing for Protected_Component_Ref
3344 -- Get the type size
3346 if Known_Static_Esize
(Comp_Type
) then
3347 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
3349 -- If the Esize (Object_Size) is unknown at compile-time, look at
3350 -- the RM_Size (Value_Size) since it may have been set by an
3351 -- explicit representation clause.
3353 elsif Known_Static_RM_Size
(Comp_Type
) then
3354 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
3356 -- Should not happen since this has already been checked in
3357 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3360 raise Program_Error
;
3363 -- Retrieve all relevant atomic routines and types
3367 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
3368 Read
:= RTE
(RE_Lock_Free_Read_8
);
3369 Unsigned
:= RTE
(RE_Uint8
);
3372 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
3373 Read
:= RTE
(RE_Lock_Free_Read_16
);
3374 Unsigned
:= RTE
(RE_Uint16
);
3377 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
3378 Read
:= RTE
(RE_Lock_Free_Read_32
);
3379 Unsigned
:= RTE
(RE_Uint32
);
3382 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
3383 Read
:= RTE
(RE_Lock_Free_Read_64
);
3384 Unsigned
:= RTE
(RE_Uint64
);
3387 raise Program_Error
;
3391 -- Expected_Comp : constant Comp_Type :=
3393 -- (System.Atomic_Primitives.Lock_Free_Read_N
3394 -- (_Object.Comp'Address));
3397 Make_Defining_Identifier
(Loc
,
3398 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3401 Make_Object_Declaration
(Loc
,
3402 Defining_Identifier
=> Expected_Comp
,
3403 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3404 Constant_Present
=> True,
3406 Unchecked_Convert_To
(Comp_Type
,
3407 Make_Function_Call
(Loc
,
3408 Name
=> New_Reference_To
(Read
, Loc
),
3409 Parameter_Associations
=> New_List
(
3410 Make_Attribute_Reference
(Loc
,
3411 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3412 Attribute_Name
=> Name_Address
)))));
3414 -- Protected procedures
3416 if Is_Procedure
then
3417 -- Move the original declarations inside the generated block
3419 Block_Decls
:= Decls
;
3421 -- Reset the declarations list of the protected procedure to
3422 -- contain only Decl.
3424 Decls
:= New_List
(Decl
);
3427 -- Desired_Comp : Comp_Type := Expected_Comp;
3430 Make_Defining_Identifier
(Loc
,
3431 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3433 -- Insert the declarations of Expected_Comp and Desired_Comp in
3434 -- the block declarations right before the renaming of the
3435 -- protected component.
3437 Insert_Before
(Comp_Decl
,
3438 Make_Object_Declaration
(Loc
,
3439 Defining_Identifier
=> Desired_Comp
,
3440 Object_Definition
=> New_Reference_To
(Comp_Type
, Loc
),
3442 New_Reference_To
(Expected_Comp
, Loc
)));
3444 -- Protected function
3447 Desired_Comp
:= Expected_Comp
;
3449 -- Insert the declaration of Expected_Comp in the function
3450 -- declarations right before the renaming of the protected
3453 Insert_Before
(Comp_Decl
, Decl
);
3456 -- Rewrite the protected component renaming declaration to be a
3457 -- renaming of Desired_Comp.
3460 -- Comp : Comp_Type renames Desired_Comp;
3463 Make_Object_Renaming_Declaration
(Loc
,
3464 Defining_Identifier
=>
3465 Defining_Identifier
(Comp_Decl
),
3467 New_Occurrence_Of
(Comp_Type
, Loc
),
3469 New_Reference_To
(Desired_Comp
, Loc
)));
3471 -- Wrap any return or raise statements in Stmts in same the manner
3472 -- described in Process_Stmts.
3474 Process_Stmts
(Stmts
);
3477 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3478 -- (_Object.Comp'Address,
3479 -- Interfaces.Unsigned_N (Expected_Comp),
3480 -- Interfaces.Unsigned_N (Desired_Comp))
3482 if Is_Procedure
then
3484 Make_Exit_Statement
(Loc
,
3486 Make_Function_Call
(Loc
,
3488 New_Reference_To
(Try_Write
, Loc
),
3489 Parameter_Associations
=> New_List
(
3490 Make_Attribute_Reference
(Loc
,
3491 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3492 Attribute_Name
=> Name_Address
),
3494 Unchecked_Convert_To
(Unsigned
,
3495 New_Reference_To
(Expected_Comp
, Loc
)),
3497 Unchecked_Convert_To
(Unsigned
,
3498 New_Reference_To
(Desired_Comp
, Loc
)))));
3500 -- Small optimization: transform the default return statement
3501 -- of a procedure into the atomic exit statement.
3503 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3504 Rewrite
(Last
(Stmts
), Stmt
);
3506 Append_To
(Stmts
, Stmt
);
3510 -- Create the declaration of the label used to skip the rest of
3511 -- the source statements when the object state changes.
3513 if Present
(Label_Id
) then
3514 Label
:= Make_Label
(Loc
, Label_Id
);
3516 Make_Implicit_Label_Declaration
(Loc
,
3517 Defining_Identifier
=> Entity
(Label_Id
),
3518 Label_Construct
=> Label
));
3519 Append_To
(Stmts
, Label
);
3531 if Is_Procedure
then
3534 Make_Loop_Statement
(Loc
,
3535 Statements
=> New_List
(
3536 Make_Block_Statement
(Loc
,
3537 Declarations
=> Block_Decls
,
3538 Handled_Statement_Sequence
=>
3539 Make_Handled_Sequence_Of_Statements
(Loc
,
3540 Statements
=> Stmts
))),
3541 End_Label
=> Empty
));
3545 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3546 end Protected_Component_Ref
;
3549 -- Make an unprotected version of the subprogram for use within the same
3550 -- object, with new name and extra parameter representing the object.
3553 Make_Subprogram_Body
(Loc
,
3555 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3556 Declarations
=> Decls
,
3557 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3558 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3560 -------------------------
3561 -- Build_Master_Entity --
3562 -------------------------
3564 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3565 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3567 Context_Id
: Entity_Id
;
3573 if Is_Itype
(Obj_Or_Typ
) then
3574 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3576 Par
:= Parent
(Obj_Or_Typ
);
3579 -- When creating a master for a record component which is either a task
3580 -- or access-to-task, the enclosing record is the master scope and the
3581 -- proper insertion point is the component list.
3583 if Is_Record_Type
(Current_Scope
) then
3585 Context_Id
:= Current_Scope
;
3586 Decls
:= List_Containing
(Context
);
3588 -- Default case for object declarations and access types. Note that the
3589 -- context is updated to the nearest enclosing body, block, package or
3590 -- return statement.
3593 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3596 -- Do not create a master if one already exists or there is no task
3599 if Has_Master_Entity
(Context_Id
)
3600 or else Restriction_Active
(No_Task_Hierarchy
)
3605 -- Create a master, generate:
3606 -- _Master : constant Master_Id := Current_Master.all;
3609 Make_Object_Declaration
(Loc
,
3610 Defining_Identifier
=>
3611 Make_Defining_Identifier
(Loc
, Name_uMaster
),
3612 Constant_Present
=> True,
3613 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3615 Make_Explicit_Dereference
(Loc
,
3616 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
3618 -- The master is inserted at the start of the declarative list of the
3621 Prepend_To
(Decls
, Decl
);
3623 -- In certain cases where transient scopes are involved, the immediate
3624 -- scope is not always the proper master scope. Ensure that the master
3625 -- declaration and entity appear in the same context.
3627 if Context_Id
/= Current_Scope
then
3628 Push_Scope
(Context_Id
);
3635 -- Mark the enclosing scope and its associated construct as being task
3638 Set_Has_Master_Entity
(Context_Id
);
3640 while Present
(Context
)
3641 and then Nkind
(Context
) /= N_Compilation_Unit
3643 if Nkind_In
(Context
, N_Block_Statement
,
3647 Set_Is_Task_Master
(Context
);
3650 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3651 Context
:= Corresponding_Stub
(Parent
(Context
));
3654 Context
:= Parent
(Context
);
3656 end Build_Master_Entity
;
3658 ---------------------------
3659 -- Build_Master_Renaming --
3660 ---------------------------
3662 procedure Build_Master_Renaming
3663 (Ptr_Typ
: Entity_Id
;
3664 Ins_Nod
: Node_Id
:= Empty
)
3666 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3668 Master_Decl
: Node_Id
;
3669 Master_Id
: Entity_Id
;
3672 -- Nothing to do if there is no task hierarchy
3674 if Restriction_Active
(No_Task_Hierarchy
) then
3678 -- Determine the proper context to insert the master renaming
3680 if Present
(Ins_Nod
) then
3682 elsif Is_Itype
(Ptr_Typ
) then
3683 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3685 Context
:= Parent
(Ptr_Typ
);
3689 -- <Ptr_Typ>M : Master_Id renames _Master;
3692 Make_Defining_Identifier
(Loc
,
3693 New_External_Name
(Chars
(Ptr_Typ
), 'M'));
3696 Make_Object_Renaming_Declaration
(Loc
,
3697 Defining_Identifier
=> Master_Id
,
3698 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
3699 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3701 Insert_Action
(Context
, Master_Decl
);
3703 -- The renamed master now services the access type
3705 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3706 end Build_Master_Renaming
;
3708 -----------------------------------------
3709 -- Build_Private_Protected_Declaration --
3710 -----------------------------------------
3712 function Build_Private_Protected_Declaration
3713 (N
: Node_Id
) return Entity_Id
3715 Loc
: constant Source_Ptr
:= Sloc
(N
);
3716 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3721 Spec_Id
: Entity_Id
;
3724 Formal
:= First_Formal
(Body_Id
);
3726 -- The protected operation always has at least one formal, namely the
3727 -- object itself, but it is only placed in the parameter list if
3728 -- expansion is enabled.
3730 if Present
(Formal
) or else Expander_Active
then
3731 Plist
:= Copy_Parameter_List
(Body_Id
);
3736 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
3738 Make_Procedure_Specification
(Loc
,
3739 Defining_Unit_Name
=>
3740 Make_Defining_Identifier
(Sloc
(Body_Id
),
3741 Chars
=> Chars
(Body_Id
)),
3742 Parameter_Specifications
=>
3746 Make_Function_Specification
(Loc
,
3747 Defining_Unit_Name
=>
3748 Make_Defining_Identifier
(Sloc
(Body_Id
),
3749 Chars
=> Chars
(Body_Id
)),
3750 Parameter_Specifications
=> Plist
,
3751 Result_Definition
=>
3752 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
3755 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> New_Spec
);
3756 Insert_Before
(N
, Decl
);
3757 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
3759 -- Indicate that the entity comes from source, to ensure that cross-
3760 -- reference information is properly generated. The body itself is
3761 -- rewritten during expansion, and the body entity will not appear in
3762 -- calls to the operation.
3764 Set_Comes_From_Source
(Spec_Id
, True);
3766 Set_Has_Completion
(Spec_Id
);
3767 Set_Convention
(Spec_Id
, Convention_Protected
);
3769 end Build_Private_Protected_Declaration
;
3771 ---------------------------
3772 -- Build_Protected_Entry --
3773 ---------------------------
3775 function Build_Protected_Entry
3778 Pid
: Node_Id
) return Node_Id
3780 Loc
: constant Source_Ptr
:= Sloc
(N
);
3782 Decls
: constant List_Id
:= Declarations
(N
);
3783 End_Lab
: constant Node_Id
:=
3784 End_Label
(Handled_Statement_Sequence
(N
));
3785 End_Loc
: constant Source_Ptr
:=
3786 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3787 -- Used for the generated call to Complete_Entry_Body
3789 Han_Loc
: Source_Ptr
;
3790 -- Used for the exception handler, inserted at end of the body
3792 Op_Decls
: constant List_Id
:= New_List
;
3800 -- Set the source location on the exception handler only when debugging
3801 -- the expanded code (see Make_Implicit_Exception_Handler).
3803 if Debug_Generated_Code
then
3806 -- Otherwise the inserted code should not be visible to the debugger
3809 Han_Loc
:= No_Location
;
3813 Make_Defining_Identifier
(Loc
,
3814 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3816 Build_Protected_Entry_Specification
(Loc
, Edef
, Empty
);
3818 -- Add the following declarations:
3819 -- type poVP is access poV;
3820 -- _object : poVP := poVP (_O);
3822 -- where _O is the formal parameter associated with the concurrent
3823 -- object. These declarations are needed for Complete_Entry_Body.
3825 Add_Object_Pointer
(Loc
, Pid
, Op_Decls
);
3827 -- Add renamings for all formals, the Protection object, discriminals,
3828 -- privals and the entry index constant for use by debugger.
3830 Add_Formal_Renamings
(Espec
, Op_Decls
, Ent
, Loc
);
3831 Debug_Private_Data_Declarations
(Decls
);
3833 case Corresponding_Runtime_Package
(Pid
) is
3834 when System_Tasking_Protected_Objects_Entries
=>
3836 New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
);
3838 when System_Tasking_Protected_Objects_Single_Entry
=>
3840 New_Reference_To
(RTE
(RE_Complete_Single_Entry_Body
), Loc
);
3843 raise Program_Error
;
3846 Op_Stats
:= New_List
(
3847 Make_Block_Statement
(Loc
,
3848 Declarations
=> Decls
,
3849 Handled_Statement_Sequence
=>
3850 Handled_Statement_Sequence
(N
)),
3852 Make_Procedure_Call_Statement
(End_Loc
,
3854 Parameter_Associations
=> New_List
(
3855 Make_Attribute_Reference
(End_Loc
,
3857 Make_Selected_Component
(End_Loc
,
3858 Prefix
=> Make_Identifier
(End_Loc
, Name_uObject
),
3859 Selector_Name
=> Make_Identifier
(End_Loc
, Name_uObject
)),
3860 Attribute_Name
=> Name_Unchecked_Access
))));
3862 -- When exceptions can not be propagated, we never need to call
3863 -- Exception_Complete_Entry_Body
3865 if No_Exception_Handlers_Set
then
3867 Make_Subprogram_Body
(Loc
,
3868 Specification
=> Espec
,
3869 Declarations
=> Op_Decls
,
3870 Handled_Statement_Sequence
=>
3871 Make_Handled_Sequence_Of_Statements
(Loc
,
3872 Statements
=> Op_Stats
,
3873 End_Label
=> End_Lab
));
3876 Ohandle
:= Make_Others_Choice
(Loc
);
3877 Set_All_Others
(Ohandle
);
3879 case Corresponding_Runtime_Package
(Pid
) is
3880 when System_Tasking_Protected_Objects_Entries
=>
3883 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3885 when System_Tasking_Protected_Objects_Single_Entry
=>
3888 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3891 raise Program_Error
;
3894 -- Establish link between subprogram body entity and source entry
3896 Set_Corresponding_Protected_Entry
(Edef
, Ent
);
3898 -- Create body of entry procedure. The renaming declarations are
3899 -- placed ahead of the block that contains the actual entry body.
3902 Make_Subprogram_Body
(Loc
,
3903 Specification
=> Espec
,
3904 Declarations
=> Op_Decls
,
3905 Handled_Statement_Sequence
=>
3906 Make_Handled_Sequence_Of_Statements
(Loc
,
3907 Statements
=> Op_Stats
,
3908 End_Label
=> End_Lab
,
3909 Exception_Handlers
=> New_List
(
3910 Make_Implicit_Exception_Handler
(Han_Loc
,
3911 Exception_Choices
=> New_List
(Ohandle
),
3913 Statements
=> New_List
(
3914 Make_Procedure_Call_Statement
(Han_Loc
,
3916 Parameter_Associations
=> New_List
(
3917 Make_Attribute_Reference
(Han_Loc
,
3919 Make_Selected_Component
(Han_Loc
,
3921 Make_Identifier
(Han_Loc
, Name_uObject
),
3923 Make_Identifier
(Han_Loc
, Name_uObject
)),
3924 Attribute_Name
=> Name_Unchecked_Access
),
3926 Make_Function_Call
(Han_Loc
,
3927 Name
=> New_Reference_To
(
3928 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3930 end Build_Protected_Entry
;
3932 -----------------------------------------
3933 -- Build_Protected_Entry_Specification --
3934 -----------------------------------------
3936 function Build_Protected_Entry_Specification
3939 Ent_Id
: Entity_Id
) return Node_Id
3941 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3944 Set_Debug_Info_Needed
(Def_Id
);
3946 if Present
(Ent_Id
) then
3947 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3951 Make_Procedure_Specification
(Loc
,
3952 Defining_Unit_Name
=> Def_Id
,
3953 Parameter_Specifications
=> New_List
(
3954 Make_Parameter_Specification
(Loc
,
3955 Defining_Identifier
=>
3956 Make_Defining_Identifier
(Loc
, Name_uO
),
3958 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3960 Make_Parameter_Specification
(Loc
,
3961 Defining_Identifier
=> P
,
3963 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3965 Make_Parameter_Specification
(Loc
,
3966 Defining_Identifier
=>
3967 Make_Defining_Identifier
(Loc
, Name_uE
),
3969 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
3970 end Build_Protected_Entry_Specification
;
3972 --------------------------
3973 -- Build_Protected_Spec --
3974 --------------------------
3976 function Build_Protected_Spec
3978 Obj_Type
: Entity_Id
;
3980 Unprotected
: Boolean := False) return List_Id
3982 Loc
: constant Source_Ptr
:= Sloc
(N
);
3985 New_Plist
: List_Id
;
3986 New_Param
: Node_Id
;
3989 New_Plist
:= New_List
;
3991 Formal
:= First_Formal
(Ident
);
3992 while Present
(Formal
) loop
3994 Make_Parameter_Specification
(Loc
,
3995 Defining_Identifier
=>
3996 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
3997 In_Present
=> In_Present
(Parent
(Formal
)),
3998 Out_Present
=> Out_Present
(Parent
(Formal
)),
3999 Parameter_Type
=> New_Reference_To
(Etype
(Formal
), Loc
));
4002 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
4005 Append
(New_Param
, New_Plist
);
4006 Next_Formal
(Formal
);
4009 -- If the subprogram is a procedure and the context is not an access
4010 -- to protected subprogram, the parameter is in-out. Otherwise it is
4014 Make_Parameter_Specification
(Loc
,
4015 Defining_Identifier
=>
4016 Make_Defining_Identifier
(Loc
, Name_uObject
),
4019 (Etype
(Ident
) = Standard_Void_Type
4020 and then not Is_RTE
(Obj_Type
, RE_Address
)),
4022 New_Reference_To
(Obj_Type
, Loc
));
4023 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
4024 Prepend_To
(New_Plist
, Decl
);
4027 end Build_Protected_Spec
;
4029 ---------------------------------------
4030 -- Build_Protected_Sub_Specification --
4031 ---------------------------------------
4033 function Build_Protected_Sub_Specification
4035 Prot_Typ
: Entity_Id
;
4036 Mode
: Subprogram_Protection_Mode
) return Node_Id
4038 Loc
: constant Source_Ptr
:= Sloc
(N
);
4042 New_Plist
: List_Id
;
4045 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
4046 (Dispatching_Mode
=> ' ',
4047 Protected_Mode
=> 'P',
4048 Unprotected_Mode
=> 'N');
4051 if Ekind
(Defining_Unit_Name
(Specification
(N
))) =
4054 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
4059 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
4062 Build_Protected_Spec
4063 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
4064 Mode
= Unprotected_Mode
);
4066 Make_Defining_Identifier
(Loc
,
4067 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
4069 -- The unprotected operation carries the user code, and debugging
4070 -- information must be generated for it, even though this spec does
4071 -- not come from source. It is also convenient to allow gdb to step
4072 -- into the protected operation, even though it only contains lock/
4075 Set_Debug_Info_Needed
(New_Id
);
4077 -- If a pragma Eliminate applies to the source entity, the internal
4078 -- subprograms will be eliminated as well.
4080 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
4082 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
4084 Make_Procedure_Specification
(Loc
,
4085 Defining_Unit_Name
=> New_Id
,
4086 Parameter_Specifications
=> New_Plist
);
4088 -- Create a new specification for the anonymous subprogram type
4092 Make_Function_Specification
(Loc
,
4093 Defining_Unit_Name
=> New_Id
,
4094 Parameter_Specifications
=> New_Plist
,
4095 Result_Definition
=>
4096 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
4098 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
4102 end Build_Protected_Sub_Specification
;
4104 -------------------------------------
4105 -- Build_Protected_Subprogram_Body --
4106 -------------------------------------
4108 function Build_Protected_Subprogram_Body
4111 N_Op_Spec
: Node_Id
) return Node_Id
4113 Loc
: constant Source_Ptr
:= Sloc
(N
);
4115 P_Op_Spec
: Node_Id
;
4118 Unprot_Call
: Node_Id
;
4120 Lock_Name
: Node_Id
;
4121 Lock_Stmt
: Node_Id
;
4122 Service_Name
: Node_Id
;
4124 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
4125 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
4127 Object_Parm
: Node_Id
;
4132 Op_Spec
:= Specification
(N
);
4133 Exc_Safe
:= Is_Exception_Safe
(N
);
4136 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
4138 -- Build a list of the formal parameters of the protected version of
4139 -- the subprogram to use as the actual parameters of the unprotected
4142 Uactuals
:= New_List
;
4143 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
4144 while Present
(Pformal
) loop
4145 Append_To
(Uactuals
,
4146 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
4150 -- Make a call to the unprotected version of the subprogram built above
4151 -- for use by the protected version built below.
4153 if Nkind
(Op_Spec
) = N_Function_Specification
then
4155 R
:= Make_Temporary
(Loc
, 'R');
4157 Make_Object_Declaration
(Loc
,
4158 Defining_Identifier
=> R
,
4159 Constant_Present
=> True,
4160 Object_Definition
=> New_Copy
(Result_Definition
(N_Op_Spec
)),
4162 Make_Function_Call
(Loc
,
4163 Name
=> Make_Identifier
(Loc
,
4164 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4165 Parameter_Associations
=> Uactuals
));
4168 Make_Simple_Return_Statement
(Loc
,
4169 Expression
=> New_Reference_To
(R
, Loc
));
4172 Unprot_Call
:= Make_Simple_Return_Statement
(Loc
,
4173 Expression
=> Make_Function_Call
(Loc
,
4175 Make_Identifier
(Loc
,
4176 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4177 Parameter_Associations
=> Uactuals
));
4180 Lock_Kind
:= RE_Lock_Read_Only
;
4184 Make_Procedure_Call_Statement
(Loc
,
4186 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
4187 Parameter_Associations
=> Uactuals
);
4189 Lock_Kind
:= RE_Lock
;
4192 -- Wrap call in block that will be covered by an at_end handler
4194 if not Exc_Safe
then
4195 Unprot_Call
:= Make_Block_Statement
(Loc
,
4196 Handled_Statement_Sequence
=>
4197 Make_Handled_Sequence_Of_Statements
(Loc
,
4198 Statements
=> New_List
(Unprot_Call
)));
4201 -- Make the protected subprogram body. This locks the protected
4202 -- object and calls the unprotected version of the subprogram.
4204 case Corresponding_Runtime_Package
(Pid
) is
4205 when System_Tasking_Protected_Objects_Entries
=>
4206 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
4207 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
4209 when System_Tasking_Protected_Objects_Single_Entry
=>
4210 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
4211 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
4213 when System_Tasking_Protected_Objects
=>
4214 Lock_Name
:= New_Reference_To
(RTE
(Lock_Kind
), Loc
);
4215 Service_Name
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
4218 raise Program_Error
;
4222 Make_Attribute_Reference
(Loc
,
4224 Make_Selected_Component
(Loc
,
4225 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4226 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4227 Attribute_Name
=> Name_Unchecked_Access
);
4229 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
4231 Parameter_Associations
=> New_List
(Object_Parm
));
4233 if Abort_Allowed
then
4235 Make_Procedure_Call_Statement
(Loc
,
4236 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
4237 Parameter_Associations
=> Empty_List
),
4241 Stmts
:= New_List
(Lock_Stmt
);
4244 if not Exc_Safe
then
4245 Append
(Unprot_Call
, Stmts
);
4247 if Nkind
(Op_Spec
) = N_Function_Specification
then
4249 Stmts
:= Empty_List
;
4251 Append
(Unprot_Call
, Stmts
);
4255 Make_Procedure_Call_Statement
(Loc
,
4256 Name
=> Service_Name
,
4257 Parameter_Associations
=>
4258 New_List
(New_Copy_Tree
(Object_Parm
))),
4261 if Abort_Allowed
then
4263 Make_Procedure_Call_Statement
(Loc
,
4264 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
4265 Parameter_Associations
=> Empty_List
),
4269 if Nkind
(Op_Spec
) = N_Function_Specification
then
4270 Append
(Return_Stmt
, Stmts
);
4271 Append
(Make_Block_Statement
(Loc
,
4272 Declarations
=> New_List
(Unprot_Call
),
4273 Handled_Statement_Sequence
=>
4274 Make_Handled_Sequence_Of_Statements
(Loc
,
4275 Statements
=> Stmts
)), Pre_Stmts
);
4281 Make_Subprogram_Body
(Loc
,
4282 Declarations
=> Empty_List
,
4283 Specification
=> P_Op_Spec
,
4284 Handled_Statement_Sequence
=>
4285 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
4287 if not Exc_Safe
then
4288 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
4292 end Build_Protected_Subprogram_Body
;
4294 -------------------------------------
4295 -- Build_Protected_Subprogram_Call --
4296 -------------------------------------
4298 procedure Build_Protected_Subprogram_Call
4302 External
: Boolean := True)
4304 Loc
: constant Source_Ptr
:= Sloc
(N
);
4305 Sub
: constant Entity_Id
:= Entity
(Name
);
4311 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
4314 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
4317 if Present
(Parameter_Associations
(N
)) then
4318 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
4323 -- If the type is an untagged derived type, convert to the root type,
4324 -- which is the one on which the operations are defined.
4326 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
4327 and then not Is_Tagged_Type
(Etype
(Rec
))
4328 and then Is_Derived_Type
(Etype
(Rec
))
4330 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
4331 Set_Subtype_Mark
(Rec
,
4332 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
4335 Prepend
(Rec
, Params
);
4337 if Ekind
(Sub
) = E_Procedure
then
4339 Make_Procedure_Call_Statement
(Loc
,
4341 Parameter_Associations
=> Params
));
4344 pragma Assert
(Ekind
(Sub
) = E_Function
);
4346 Make_Function_Call
(Loc
,
4348 Parameter_Associations
=> Params
));
4352 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4353 and then Is_Entity_Name
(Expression
(Rec
))
4354 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4356 Add_Shared_Var_Lock_Procs
(N
);
4358 end Build_Protected_Subprogram_Call
;
4360 -------------------------
4361 -- Build_Selected_Name --
4362 -------------------------
4364 function Build_Selected_Name
4365 (Prefix
: Entity_Id
;
4366 Selector
: Entity_Id
;
4367 Append_Char
: Character := ' ') return Name_Id
4369 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4370 Select_Len
: Natural;
4373 Get_Name_String
(Chars
(Selector
));
4374 Select_Len
:= Name_Len
;
4375 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4376 Get_Name_String
(Chars
(Prefix
));
4378 -- If scope is anonymous type, discard suffix to recover name of
4379 -- single protected object. Otherwise use protected type name.
4381 if Name_Buffer
(Name_Len
) = 'T' then
4382 Name_Len
:= Name_Len
- 1;
4385 Add_Str_To_Name_Buffer
("__");
4386 for J
in 1 .. Select_Len
loop
4387 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4390 -- Now add the Append_Char if specified. The encoding to follow
4391 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4392 -- then the entity is associated to a protected type subprogram.
4393 -- Otherwise, it is a protected type entry. For each case, the
4394 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4396 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4398 if Append_Char
/= ' ' then
4399 if Append_Char
= 'P' or Append_Char
= 'N' then
4400 Add_Char_To_Name_Buffer
(Append_Char
);
4403 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4404 return New_External_Name
(Name_Find
, ' ', -1);
4409 end Build_Selected_Name
;
4411 -----------------------------
4412 -- Build_Simple_Entry_Call --
4413 -----------------------------
4415 -- A task entry call is converted to a call to Call_Simple
4418 -- P : parms := (parm, parm, parm);
4420 -- Call_Simple (acceptor-task, entry-index, P'Address);
4426 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4427 -- the parameters, and the constructed aggregate value contains either the
4428 -- parameters or, in the case of non-elementary types, references to these
4429 -- parameters. Then the address of this aggregate is passed to the runtime
4430 -- routine, along with the task id value and the task entry index value.
4431 -- Pnn is only required if parameters are present.
4433 -- The assignments after the call are present only in the case of in-out
4434 -- or out parameters for elementary types, and are used to assign back the
4435 -- resulting values of such parameters.
4437 -- Note: the reason that we insert a block here is that in the context
4438 -- of selects, conditional entry calls etc. the entry call statement
4439 -- appears on its own, not as an element of a list.
4441 -- A protected entry call is converted to a Protected_Entry_Call:
4444 -- P : E1_Params := (param, param, param);
4446 -- Bnn : Communications_Block;
4449 -- P : E1_Params := (param, param, param);
4450 -- Bnn : Communications_Block;
4453 -- Protected_Entry_Call (
4454 -- Object => po._object'Access,
4455 -- E => <entry index>;
4456 -- Uninterpreted_Data => P'Address;
4457 -- Mode => Simple_Call;
4464 procedure Build_Simple_Entry_Call
4473 -- If call has been inlined, nothing left to do
4475 if Nkind
(N
) = N_Block_Statement
then
4479 -- Convert entry call to Call_Simple call
4482 Loc
: constant Source_Ptr
:= Sloc
(N
);
4483 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4484 Stats
: constant List_Id
:= New_List
;
4487 Comm_Name
: Entity_Id
;
4491 Ent_Acc
: Entity_Id
;
4493 Iface_Tag
: Entity_Id
;
4494 Iface_Typ
: Entity_Id
;
4507 -- Simple entry and entry family cases merge here
4509 Ent
:= Entity
(Ename
);
4510 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4511 Conctyp
:= Etype
(Concval
);
4513 -- If prefix is an access type, dereference to obtain the task type
4515 if Is_Access_Type
(Conctyp
) then
4516 Conctyp
:= Designated_Type
(Conctyp
);
4519 -- Special case for protected subprogram calls
4521 if Is_Protected_Type
(Conctyp
)
4522 and then Is_Subprogram
(Entity
(Ename
))
4524 if not Is_Eliminated
(Entity
(Ename
)) then
4525 Build_Protected_Subprogram_Call
4526 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4533 -- First parameter is the Task_Id value from the task value or the
4534 -- Object from the protected object value, obtained by selecting
4535 -- the _Task_Id or _Object from the result of doing an unchecked
4536 -- conversion to convert the value to the corresponding record type.
4538 if Nkind
(Concval
) = N_Function_Call
4539 and then Is_Task_Type
(Conctyp
)
4540 and then Ada_Version
>= Ada_2005
4543 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4544 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4549 Make_Object_Declaration
(Loc
,
4550 Defining_Identifier
=> Obj
,
4551 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4552 Expression
=> ExpR
);
4553 Set_Etype
(Obj
, Conctyp
);
4554 Decls
:= New_List
(Decl
);
4555 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4562 Parm1
:= Concurrent_Ref
(Concval
);
4564 -- Second parameter is the entry index, computed by the routine
4565 -- provided for this purpose. The value of this expression is
4566 -- assigned to an intermediate variable to assure that any entry
4567 -- family index expressions are evaluated before the entry
4571 or else Restriction_Active
(No_Entry_Queue
) = False
4572 or else not Is_Protected_Type
(Conctyp
)
4573 or else Number_Entries
(Conctyp
) > 1
4574 or else (Has_Attach_Handler
(Conctyp
)
4575 and then not Restricted_Profile
)
4577 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4580 Make_Object_Declaration
(Loc
,
4581 Defining_Identifier
=> X
,
4582 Object_Definition
=>
4583 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
4584 Expression
=> Actual_Index_Expression
(
4585 Loc
, Entity
(Ename
), Index
, Concval
));
4587 Append_To
(Decls
, Xdecl
);
4588 Parm2
:= New_Reference_To
(X
, Loc
);
4595 -- The third parameter is the packaged parameters. If there are
4596 -- none, then it is just the null address, since nothing is passed.
4599 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
4602 -- Case of parameters present, where third argument is the address
4603 -- of a packaged record containing the required parameter values.
4606 -- First build a list of parameter values, which are references to
4607 -- objects of the parameter types.
4611 Actual
:= First_Actual
(N
);
4612 Formal
:= First_Formal
(Ent
);
4614 while Present
(Actual
) loop
4616 -- If it is a by_copy_type, copy it to a new variable. The
4617 -- packaged record has a field that points to this variable.
4619 if Is_By_Copy_Type
(Etype
(Actual
)) then
4621 Make_Object_Declaration
(Loc
,
4622 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4623 Aliased_Present
=> True,
4624 Object_Definition
=>
4625 New_Reference_To
(Etype
(Formal
), Loc
));
4627 -- Mark the object as not needing initialization since the
4628 -- initialization is performed separately, avoiding errors
4629 -- on cases such as formals of null-excluding access types.
4631 Set_No_Initialization
(N_Node
);
4633 -- We must make an assignment statement separate for the
4634 -- case of limited type. We cannot assign it unless the
4635 -- Assignment_OK flag is set first. An out formal of an
4636 -- access type must also be initialized from the actual,
4637 -- as stated in RM 6.4.1 (13).
4639 if Ekind
(Formal
) /= E_Out_Parameter
4640 or else Is_Access_Type
(Etype
(Formal
))
4643 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
4644 Set_Assignment_OK
(N_Var
);
4646 Make_Assignment_Statement
(Loc
,
4648 Expression
=> Relocate_Node
(Actual
)));
4651 Append
(N_Node
, Decls
);
4654 Make_Attribute_Reference
(Loc
,
4655 Attribute_Name
=> Name_Unchecked_Access
,
4657 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4659 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4661 elsif Is_VM_By_Copy_Actual
(Actual
) then
4663 Make_Object_Declaration
(Loc
,
4664 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4665 Aliased_Present
=> True,
4666 Object_Definition
=>
4667 New_Reference_To
(Etype
(Formal
), Loc
),
4668 Expression
=> New_Copy_Tree
(Actual
));
4669 Set_Assignment_OK
(N_Node
);
4671 Append
(N_Node
, Decls
);
4674 Make_Attribute_Reference
(Loc
,
4675 Attribute_Name
=> Name_Unchecked_Access
,
4677 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
4680 -- Interface class-wide formal
4682 if Ada_Version
>= Ada_2005
4683 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4684 and then Is_Interface
(Etype
(Formal
))
4686 Iface_Typ
:= Etype
(Etype
(Formal
));
4689 -- formal_iface_type! (actual.iface_tag)'reference
4692 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4693 pragma Assert
(Present
(Iface_Tag
));
4696 Make_Reference
(Loc
,
4697 Unchecked_Convert_To
(Iface_Typ
,
4698 Make_Selected_Component
(Loc
,
4700 Relocate_Node
(Actual
),
4702 New_Reference_To
(Iface_Tag
, Loc
)))));
4708 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4712 Next_Actual
(Actual
);
4713 Next_Formal_With_Extras
(Formal
);
4716 -- Now build the declaration of parameters initialized with the
4717 -- aggregate containing this constructed parameter list.
4719 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4722 Make_Object_Declaration
(Loc
,
4723 Defining_Identifier
=> P
,
4724 Object_Definition
=>
4725 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
4727 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4730 Make_Attribute_Reference
(Loc
,
4731 Prefix
=> New_Reference_To
(P
, Loc
),
4732 Attribute_Name
=> Name_Address
);
4734 Append
(Pdecl
, Decls
);
4737 -- Now we can create the call, case of protected type
4739 if Is_Protected_Type
(Conctyp
) then
4740 case Corresponding_Runtime_Package
(Conctyp
) is
4741 when System_Tasking_Protected_Objects_Entries
=>
4743 -- Change the type of the index declaration
4745 Set_Object_Definition
(Xdecl
,
4746 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
4748 -- Some additional declarations for protected entry calls
4754 -- Bnn : Communications_Block;
4756 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4759 Make_Object_Declaration
(Loc
,
4760 Defining_Identifier
=> Comm_Name
,
4761 Object_Definition
=>
4762 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
4764 -- Some additional statements for protected entry calls
4766 -- Protected_Entry_Call (
4767 -- Object => po._object'Access,
4768 -- E => <entry index>;
4769 -- Uninterpreted_Data => P'Address;
4770 -- Mode => Simple_Call;
4774 Make_Procedure_Call_Statement
(Loc
,
4776 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
4778 Parameter_Associations
=> New_List
(
4779 Make_Attribute_Reference
(Loc
,
4780 Attribute_Name
=> Name_Unchecked_Access
,
4784 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
4785 New_Occurrence_Of
(Comm_Name
, Loc
)));
4787 when System_Tasking_Protected_Objects_Single_Entry
=>
4788 -- Protected_Single_Entry_Call (
4789 -- Object => po._object'Access,
4790 -- Uninterpreted_Data => P'Address;
4791 -- Mode => Simple_Call);
4794 Make_Procedure_Call_Statement
(Loc
,
4795 Name
=> New_Reference_To
(
4796 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4798 Parameter_Associations
=> New_List
(
4799 Make_Attribute_Reference
(Loc
,
4800 Attribute_Name
=> Name_Unchecked_Access
,
4803 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
4806 raise Program_Error
;
4809 -- Case of task type
4813 Make_Procedure_Call_Statement
(Loc
,
4814 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
4815 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4819 Append_To
(Stats
, Call
);
4821 -- If there are out or in/out parameters by copy add assignment
4822 -- statements for the result values.
4824 if Present
(Parms
) then
4825 Actual
:= First_Actual
(N
);
4826 Formal
:= First_Formal
(Ent
);
4828 Set_Assignment_OK
(Actual
);
4829 while Present
(Actual
) loop
4830 if (Is_By_Copy_Type
(Etype
(Actual
))
4831 or else Is_VM_By_Copy_Actual
(Actual
))
4832 and then Ekind
(Formal
) /= E_In_Parameter
4835 Make_Assignment_Statement
(Loc
,
4836 Name
=> New_Copy
(Actual
),
4838 Make_Explicit_Dereference
(Loc
,
4839 Make_Selected_Component
(Loc
,
4840 Prefix
=> New_Reference_To
(P
, Loc
),
4842 Make_Identifier
(Loc
, Chars
(Formal
)))));
4844 -- In all cases (including limited private types) we want
4845 -- the assignment to be valid.
4847 Set_Assignment_OK
(Name
(N_Node
));
4849 -- If the call is the triggering alternative in an
4850 -- asynchronous select, or the entry_call alternative of a
4851 -- conditional entry call, the assignments for in-out
4852 -- parameters are incorporated into the statement list that
4853 -- follows, so that there are executed only if the entry
4856 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4857 and then N
= Triggering_Statement
(Parent
(N
)))
4859 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4860 and then N
= Entry_Call_Statement
(Parent
(N
)))
4862 if No
(Statements
(Parent
(N
))) then
4863 Set_Statements
(Parent
(N
), New_List
);
4866 Prepend
(N_Node
, Statements
(Parent
(N
)));
4869 Insert_After
(Call
, N_Node
);
4873 Next_Actual
(Actual
);
4874 Next_Formal_With_Extras
(Formal
);
4878 -- Finally, create block and analyze it
4881 Make_Block_Statement
(Loc
,
4882 Declarations
=> Decls
,
4883 Handled_Statement_Sequence
=>
4884 Make_Handled_Sequence_Of_Statements
(Loc
,
4885 Statements
=> Stats
)));
4889 end Build_Simple_Entry_Call
;
4891 --------------------------------
4892 -- Build_Task_Activation_Call --
4893 --------------------------------
4895 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4896 Loc
: constant Source_Ptr
:= Sloc
(N
);
4903 -- For sequential elaboration policy, all the tasks will be activated at
4904 -- the end of the elaboration.
4906 if Partition_Elaboration_Policy
= 'S' then
4910 -- Get the activation chain entity. Except in the case of a package
4911 -- body, this is in the node that was passed. For a package body, we
4912 -- have to find the corresponding package declaration node.
4914 if Nkind
(N
) = N_Package_Body
then
4915 P
:= Corresponding_Spec
(N
);
4918 exit when Nkind
(P
) = N_Package_Declaration
;
4921 Chain
:= Activation_Chain_Entity
(P
);
4924 Chain
:= Activation_Chain_Entity
(N
);
4927 if Present
(Chain
) then
4928 if Restricted_Profile
then
4929 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4931 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
4935 Make_Procedure_Call_Statement
(Loc
,
4937 Parameter_Associations
=>
4938 New_List
(Make_Attribute_Reference
(Loc
,
4939 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4940 Attribute_Name
=> Name_Unchecked_Access
)));
4942 if Nkind
(N
) = N_Package_Declaration
then
4943 if Present
(Corresponding_Body
(N
)) then
4946 elsif Present
(Private_Declarations
(Specification
(N
))) then
4947 Append
(Call
, Private_Declarations
(Specification
(N
)));
4950 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4954 if Present
(Handled_Statement_Sequence
(N
)) then
4956 -- The call goes at the start of the statement sequence
4957 -- after the start of exception range label if one is present.
4963 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4965 -- A special case, skip exception range label if one is
4966 -- present (from front end zcx processing).
4968 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
4972 -- Another special case, if the first statement is a block
4973 -- from optimization of a local raise to a goto, then the
4974 -- call goes inside this block.
4976 if Nkind
(Stm
) = N_Block_Statement
4977 and then Exception_Junk
(Stm
)
4980 First
(Statements
(Handled_Statement_Sequence
(Stm
)));
4983 -- Insertion point is after any exception label pushes,
4984 -- since we want it covered by any local handlers.
4986 while Nkind
(Stm
) in N_Push_xxx_Label
loop
4990 -- Now we have the proper insertion point
4992 Insert_Before
(Stm
, Call
);
4996 Set_Handled_Statement_Sequence
(N
,
4997 Make_Handled_Sequence_Of_Statements
(Loc
,
4998 Statements
=> New_List
(Call
)));
5003 Check_Task_Activation
(N
);
5005 end Build_Task_Activation_Call
;
5007 -------------------------------
5008 -- Build_Task_Allocate_Block --
5009 -------------------------------
5011 procedure Build_Task_Allocate_Block
5016 T
: constant Entity_Id
:= Entity
(Expression
(N
));
5017 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
5018 Loc
: constant Source_Ptr
:= Sloc
(N
);
5019 Chain
: constant Entity_Id
:=
5020 Make_Defining_Identifier
(Loc
, Name_uChain
);
5021 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5026 Make_Block_Statement
(Loc
,
5027 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5028 Declarations
=> New_List
(
5030 -- _Chain : Activation_Chain;
5032 Make_Object_Declaration
(Loc
,
5033 Defining_Identifier
=> Chain
,
5034 Aliased_Present
=> True,
5035 Object_Definition
=>
5036 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
5038 Handled_Statement_Sequence
=>
5039 Make_Handled_Sequence_Of_Statements
(Loc
,
5041 Statements
=> New_List
(
5045 Make_Procedure_Call_Statement
(Loc
,
5046 Name
=> New_Reference_To
(Init
, Loc
),
5047 Parameter_Associations
=> Args
),
5049 -- Activate_Tasks (_Chain);
5051 Make_Procedure_Call_Statement
(Loc
,
5052 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
5053 Parameter_Associations
=> New_List
(
5054 Make_Attribute_Reference
(Loc
,
5055 Prefix
=> New_Reference_To
(Chain
, Loc
),
5056 Attribute_Name
=> Name_Unchecked_Access
))))),
5058 Has_Created_Identifier
=> True,
5059 Is_Task_Allocation_Block
=> True);
5062 Make_Implicit_Label_Declaration
(Loc
,
5063 Defining_Identifier
=> Blkent
,
5064 Label_Construct
=> Block
));
5066 Append_To
(Actions
, Block
);
5068 Set_Activation_Chain_Entity
(Block
, Chain
);
5069 end Build_Task_Allocate_Block
;
5071 -----------------------------------------------
5072 -- Build_Task_Allocate_Block_With_Init_Stmts --
5073 -----------------------------------------------
5075 procedure Build_Task_Allocate_Block_With_Init_Stmts
5078 Init_Stmts
: List_Id
)
5080 Loc
: constant Source_Ptr
:= Sloc
(N
);
5081 Chain
: constant Entity_Id
:=
5082 Make_Defining_Identifier
(Loc
, Name_uChain
);
5083 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
5087 Append_To
(Init_Stmts
,
5088 Make_Procedure_Call_Statement
(Loc
,
5089 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
5090 Parameter_Associations
=> New_List
(
5091 Make_Attribute_Reference
(Loc
,
5092 Prefix
=> New_Reference_To
(Chain
, Loc
),
5093 Attribute_Name
=> Name_Unchecked_Access
))));
5096 Make_Block_Statement
(Loc
,
5097 Identifier
=> New_Reference_To
(Blkent
, Loc
),
5098 Declarations
=> New_List
(
5100 -- _Chain : Activation_Chain;
5102 Make_Object_Declaration
(Loc
,
5103 Defining_Identifier
=> Chain
,
5104 Aliased_Present
=> True,
5105 Object_Definition
=>
5106 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
5108 Handled_Statement_Sequence
=>
5109 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
5111 Has_Created_Identifier
=> True,
5112 Is_Task_Allocation_Block
=> True);
5115 Make_Implicit_Label_Declaration
(Loc
,
5116 Defining_Identifier
=> Blkent
,
5117 Label_Construct
=> Block
));
5119 Append_To
(Actions
, Block
);
5121 Set_Activation_Chain_Entity
(Block
, Chain
);
5122 end Build_Task_Allocate_Block_With_Init_Stmts
;
5124 -----------------------------------
5125 -- Build_Task_Proc_Specification --
5126 -----------------------------------
5128 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
5129 Loc
: constant Source_Ptr
:= Sloc
(T
);
5130 Spec_Id
: Entity_Id
;
5133 -- Case of explicit task type, suffix TB
5135 if Comes_From_Source
(T
) then
5137 Make_Defining_Identifier
(Loc
,
5138 Chars
=> New_External_Name
(Chars
(T
), "TB"));
5140 -- Case of anonymous task type, suffix B
5144 Make_Defining_Identifier
(Loc
,
5145 Chars
=> New_External_Name
(Chars
(T
), 'B'));
5148 Set_Is_Internal
(Spec_Id
);
5150 -- Associate the procedure with the task, if this is the declaration
5151 -- (and not the body) of the procedure.
5153 if No
(Task_Body_Procedure
(T
)) then
5154 Set_Task_Body_Procedure
(T
, Spec_Id
);
5158 Make_Procedure_Specification
(Loc
,
5159 Defining_Unit_Name
=> Spec_Id
,
5160 Parameter_Specifications
=> New_List
(
5161 Make_Parameter_Specification
(Loc
,
5162 Defining_Identifier
=>
5163 Make_Defining_Identifier
(Loc
, Name_uTask
),
5165 Make_Access_Definition
(Loc
,
5167 New_Reference_To
(Corresponding_Record_Type
(T
), Loc
)))));
5168 end Build_Task_Proc_Specification
;
5170 ---------------------------------------
5171 -- Build_Unprotected_Subprogram_Body --
5172 ---------------------------------------
5174 function Build_Unprotected_Subprogram_Body
5176 Pid
: Node_Id
) return Node_Id
5178 Decls
: constant List_Id
:= Declarations
(N
);
5181 -- Add renamings for the Protection object, discriminals, privals and
5182 -- the entry index constant for use by debugger.
5184 Debug_Private_Data_Declarations
(Decls
);
5186 -- Make an unprotected version of the subprogram for use within the same
5187 -- object, with a new name and an additional parameter representing the
5191 Make_Subprogram_Body
(Sloc
(N
),
5193 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
5194 Declarations
=> Decls
,
5195 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
5196 end Build_Unprotected_Subprogram_Body
;
5198 ----------------------------
5199 -- Collect_Entry_Families --
5200 ----------------------------
5202 procedure Collect_Entry_Families
5205 Current_Node
: in out Node_Id
;
5206 Conctyp
: Entity_Id
)
5209 Efam_Decl
: Node_Id
;
5210 Efam_Type
: Entity_Id
;
5213 Efam
:= First_Entity
(Conctyp
);
5214 while Present
(Efam
) loop
5215 if Ekind
(Efam
) = E_Entry_Family
then
5216 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5221 (Etype
(Discrete_Subtype_Definition
(Parent
(Efam
))));
5223 Bas_Decl
: Node_Id
:= Empty
;
5228 (Discrete_Subtype_Definition
(Parent
(Efam
)), Lo
, Hi
);
5230 if Is_Potentially_Large_Family
(Bas
, Conctyp
, Lo
, Hi
) then
5231 Bas
:= Make_Temporary
(Loc
, 'B');
5234 Make_Subtype_Declaration
(Loc
,
5235 Defining_Identifier
=> Bas
,
5236 Subtype_Indication
=>
5237 Make_Subtype_Indication
(Loc
,
5239 New_Occurrence_Of
(Standard_Integer
, Loc
),
5241 Make_Range_Constraint
(Loc
,
5242 Range_Expression
=> Make_Range
(Loc
,
5243 Make_Integer_Literal
5244 (Loc
, -Entry_Family_Bound
),
5245 Make_Integer_Literal
5246 (Loc
, Entry_Family_Bound
- 1)))));
5248 Insert_After
(Current_Node
, Bas_Decl
);
5249 Current_Node
:= Bas_Decl
;
5254 Make_Full_Type_Declaration
(Loc
,
5255 Defining_Identifier
=> Efam_Type
,
5257 Make_Unconstrained_Array_Definition
(Loc
,
5259 (New_List
(New_Occurrence_Of
(Bas
, Loc
))),
5261 Component_Definition
=>
5262 Make_Component_Definition
(Loc
,
5263 Aliased_Present
=> False,
5264 Subtype_Indication
=>
5265 New_Reference_To
(Standard_Character
, Loc
))));
5268 Insert_After
(Current_Node
, Efam_Decl
);
5269 Current_Node
:= Efam_Decl
;
5270 Analyze
(Efam_Decl
);
5273 Make_Component_Declaration
(Loc
,
5274 Defining_Identifier
=>
5275 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5277 Component_Definition
=>
5278 Make_Component_Definition
(Loc
,
5279 Aliased_Present
=> False,
5280 Subtype_Indication
=>
5281 Make_Subtype_Indication
(Loc
,
5283 New_Occurrence_Of
(Efam_Type
, Loc
),
5286 Make_Index_Or_Discriminant_Constraint
(Loc
,
5287 Constraints
=> New_List
(
5289 (Etype
(Discrete_Subtype_Definition
5290 (Parent
(Efam
))), Loc
)))))));
5296 end Collect_Entry_Families
;
5298 -----------------------
5299 -- Concurrent_Object --
5300 -----------------------
5302 function Concurrent_Object
5303 (Spec_Id
: Entity_Id
;
5304 Conc_Typ
: Entity_Id
) return Entity_Id
5307 -- Parameter _O or _object
5309 if Is_Protected_Type
(Conc_Typ
) then
5310 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5315 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5316 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5318 end Concurrent_Object
;
5320 ----------------------
5321 -- Copy_Result_Type --
5322 ----------------------
5324 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5325 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5330 -- If the result type is an access_to_subprogram, we must create new
5331 -- entities for its spec.
5333 if Nkind
(New_Res
) = N_Access_Definition
5334 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5336 -- Provide new entities for the formals
5338 Par_Spec
:= First
(Parameter_Specifications
5339 (Access_To_Subprogram_Definition
(New_Res
)));
5340 while Present
(Par_Spec
) loop
5341 Formal
:= Defining_Identifier
(Par_Spec
);
5342 Set_Defining_Identifier
(Par_Spec
,
5343 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5349 end Copy_Result_Type
;
5351 --------------------
5352 -- Concurrent_Ref --
5353 --------------------
5355 -- The expression returned for a reference to a concurrent object has the
5358 -- taskV!(name)._Task_Id
5362 -- objectV!(name)._Object
5364 -- for a protected object. For the case of an access to a concurrent
5365 -- object, there is an extra explicit dereference:
5367 -- taskV!(name.all)._Task_Id
5368 -- objectV!(name.all)._Object
5370 -- here taskV and objectV are the types for the associated records, which
5371 -- contain the required _Task_Id and _Object fields for tasks and protected
5372 -- objects, respectively.
5374 -- For the case of a task type name, the expression is
5378 -- i.e. a call to the Self function which returns precisely this Task_Id
5380 -- For the case of a protected type name, the expression is
5384 -- which is a renaming of the _object field of the current object
5385 -- record, passed into protected operations as a parameter.
5387 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5388 Loc
: constant Source_Ptr
:= Sloc
(N
);
5389 Ntyp
: constant Entity_Id
:= Etype
(N
);
5393 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5394 -- Check whether the reference is to the immediately enclosing task
5395 -- type, or to an outer one (rare but legal).
5397 ---------------------
5398 -- Is_Current_Task --
5399 ---------------------
5401 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5405 Scop
:= Current_Scope
;
5406 while Present
(Scop
)
5407 and then Scop
/= Standard_Standard
5413 elsif Is_Task_Type
(Scop
) then
5416 -- If this is a procedure nested within the task type, we must
5417 -- assume that it can be called from an inner task, and therefore
5418 -- cannot treat it as a local reference.
5420 elsif Is_Overloadable
(Scop
)
5421 and then In_Open_Scopes
(T
)
5426 Scop
:= Scope
(Scop
);
5430 -- We know that we are within the task body, so should have found it
5433 raise Program_Error
;
5434 end Is_Current_Task
;
5436 -- Start of processing for Concurrent_Ref
5439 if Is_Access_Type
(Ntyp
) then
5440 Dtyp
:= Designated_Type
(Ntyp
);
5442 if Is_Protected_Type
(Dtyp
) then
5443 Sel
:= Name_uObject
;
5445 Sel
:= Name_uTask_Id
;
5449 Make_Selected_Component
(Loc
,
5451 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5452 Make_Explicit_Dereference
(Loc
, N
)),
5453 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5455 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5456 if Is_Task_Type
(Entity
(N
)) then
5458 if Is_Current_Task
(Entity
(N
)) then
5460 Make_Function_Call
(Loc
,
5461 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
5466 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5467 T_Body
: constant Node_Id
:=
5468 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5472 Make_Object_Declaration
(Loc
,
5473 Defining_Identifier
=> T_Self
,
5474 Object_Definition
=>
5475 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5477 Make_Function_Call
(Loc
,
5478 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
5479 Prepend
(Decl
, Declarations
(T_Body
));
5481 Set_Scope
(T_Self
, Entity
(N
));
5482 return New_Occurrence_Of
(T_Self
, Loc
);
5487 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5490 New_Reference_To
(Find_Protection_Object
(Current_Scope
), Loc
);
5494 if Is_Protected_Type
(Ntyp
) then
5495 Sel
:= Name_uObject
;
5497 elsif Is_Task_Type
(Ntyp
) then
5498 Sel
:= Name_uTask_Id
;
5501 raise Program_Error
;
5505 Make_Selected_Component
(Loc
,
5507 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5509 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5513 ------------------------
5514 -- Convert_Concurrent --
5515 ------------------------
5517 function Convert_Concurrent
5519 Typ
: Entity_Id
) return Node_Id
5522 if not Is_Concurrent_Type
(Typ
) then
5526 Unchecked_Convert_To
5527 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5529 end Convert_Concurrent
;
5531 -------------------------------------
5532 -- Debug_Private_Data_Declarations --
5533 -------------------------------------
5535 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5536 Debug_Nod
: Node_Id
;
5540 Decl
:= First
(Decls
);
5541 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5542 -- Declaration for concurrent entity _object and its access type,
5543 -- along with the entry index subtype:
5544 -- type prot_typVP is access prot_typV;
5545 -- _object : prot_typVP := prot_typV (_O);
5546 -- subtype Jnn is <Type of Index> range Low .. High;
5548 if Nkind_In
(Decl
, N_Full_Type_Declaration
, N_Object_Declaration
) then
5549 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5551 -- Declaration for the Protection object, discriminals, privals and
5552 -- entry index constant:
5553 -- conc_typR : protection_typ renames _object._object;
5554 -- discr_nameD : discr_typ renames _object.discr_name;
5555 -- discr_nameD : discr_typ renames _task.discr_name;
5556 -- prival_name : comp_typ renames _object.comp_name;
5557 -- J : constant Jnn :=
5558 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5560 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5561 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5562 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5564 if Present
(Debug_Nod
) then
5565 Insert_After
(Decl
, Debug_Nod
);
5571 end Debug_Private_Data_Declarations
;
5573 ------------------------------
5574 -- Ensure_Statement_Present --
5575 ------------------------------
5577 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5581 if Opt
.Suppress_Control_Flow_Optimizations
5582 and then Is_Empty_List
(Statements
(Alt
))
5584 Stmt
:= Make_Null_Statement
(Loc
);
5586 -- Mark NULL statement as coming from source so that it is not
5587 -- eliminated by GIGI.
5589 -- Another covert channel! If this is a requirement, it must be
5590 -- documented in sinfo/einfo ???
5592 Set_Comes_From_Source
(Stmt
, True);
5594 Set_Statements
(Alt
, New_List
(Stmt
));
5596 end Ensure_Statement_Present
;
5598 ----------------------------
5599 -- Entry_Index_Expression --
5600 ----------------------------
5602 function Entry_Index_Expression
5606 Ttyp
: Entity_Id
) return Node_Id
5616 -- The queues of entries and entry families appear in textual order in
5617 -- the associated record. The entry index is computed as the sum of the
5618 -- number of queues for all entries that precede the designated one, to
5619 -- which is added the index expression, if this expression denotes a
5620 -- member of a family.
5622 -- The following is a place holder for the count of simple entries
5624 Num
:= Make_Integer_Literal
(Sloc
, 1);
5626 -- We construct an expression which is a series of addition operations.
5627 -- The first operand is the number of single entries that precede this
5628 -- one, the second operand is the index value relative to the start of
5629 -- the referenced family, and the remaining operands are the lengths of
5630 -- the entry families that precede this entry, i.e. the constructed
5633 -- number_simple_entries +
5634 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5635 -- family'length + ...
5637 -- where index-value is the given index value, and s is the index
5638 -- subtype (we have to use pos because the subtype might be an
5639 -- enumeration type preventing direct subtraction). Note that the task
5640 -- entry array is one-indexed.
5642 -- The upper bound of the entry family may be a discriminant, so we
5643 -- retrieve the lower bound explicitly to compute offset, rather than
5644 -- using the index subtype which may mention a discriminant.
5646 if Present
(Index
) then
5647 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
5656 Make_Attribute_Reference
(Sloc
,
5657 Attribute_Name
=> Name_Pos
,
5658 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
5659 Expressions
=> New_List
(Relocate_Node
(Index
))),
5667 -- Now add lengths of preceding entries and entry families
5669 Prev
:= First_Entity
(Ttyp
);
5671 while Chars
(Prev
) /= Chars
(Ent
)
5672 or else (Ekind
(Prev
) /= Ekind
(Ent
))
5673 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5675 if Ekind
(Prev
) = E_Entry
then
5676 Set_Intval
(Num
, Intval
(Num
) + 1);
5678 elsif Ekind
(Prev
) = E_Entry_Family
then
5680 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
5681 Lo
:= Type_Low_Bound
(S
);
5682 Hi
:= Type_High_Bound
(S
);
5687 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5689 -- Other components are anonymous types to be ignored
5699 end Entry_Index_Expression
;
5701 ---------------------------
5702 -- Establish_Task_Master --
5703 ---------------------------
5705 procedure Establish_Task_Master
(N
: Node_Id
) is
5709 if Restriction_Active
(No_Task_Hierarchy
) = False then
5710 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5712 -- The block may have no declarations, and nevertheless be a task
5713 -- master, if it contains a call that may return an object that
5716 if No
(Declarations
(N
)) then
5717 Set_Declarations
(N
, New_List
(Call
));
5719 Prepend_To
(Declarations
(N
), Call
);
5724 end Establish_Task_Master
;
5726 --------------------------------
5727 -- Expand_Accept_Declarations --
5728 --------------------------------
5730 -- Part of the expansion of an accept statement involves the creation of
5731 -- a declaration that can be referenced from the statement sequence of
5736 -- This declaration is inserted immediately before the accept statement
5737 -- and it is important that it be inserted before the statements of the
5738 -- statement sequence are analyzed. Thus it would be too late to create
5739 -- this declaration in the Expand_N_Accept_Statement routine, which is
5740 -- why there is a separate procedure to be called directly from Sem_Ch9.
5742 -- Ann is used to hold the address of the record containing the parameters
5743 -- (see Expand_N_Entry_Call for more details on how this record is built).
5744 -- References to the parameters do an unchecked conversion of this address
5745 -- to a pointer to the required record type, and then access the field that
5746 -- holds the value of the required parameter. The entity for the address
5747 -- variable is held as the top stack element (i.e. the last element) of the
5748 -- Accept_Address stack in the corresponding entry entity, and this element
5749 -- must be set in place before the statements are processed.
5751 -- The above description applies to the case of a stand alone accept
5752 -- statement, i.e. one not appearing as part of a select alternative.
5754 -- For the case of an accept that appears as part of a select alternative
5755 -- of a selective accept, we must still create the declaration right away,
5756 -- since Ann is needed immediately, but there is an important difference:
5758 -- The declaration is inserted before the selective accept, not before
5759 -- the accept statement (which is not part of a list anyway, and so would
5760 -- not accommodate inserted declarations)
5762 -- We only need one address variable for the entire selective accept. So
5763 -- the Ann declaration is created only for the first accept alternative,
5764 -- and subsequent accept alternatives reference the same Ann variable.
5766 -- We can distinguish the two cases by seeing whether the accept statement
5767 -- is part of a list. If not, then it must be in an accept alternative.
5769 -- To expand the requeue statement, a label is provided at the end of the
5770 -- accept statement or alternative of which it is a part, so that the
5771 -- statement can be skipped after the requeue is complete. This label is
5772 -- created here rather than during the expansion of the accept statement,
5773 -- because it will be needed by any requeue statements within the accept,
5774 -- which are expanded before the accept.
5776 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5777 Loc
: constant Source_Ptr
:= Sloc
(N
);
5778 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5779 Ann
: Entity_Id
:= Empty
;
5786 if Full_Expander_Active
then
5788 -- If we have no handled statement sequence, we may need to build
5789 -- a dummy sequence consisting of a null statement. This can be
5790 -- skipped if the trivial accept optimization is permitted.
5792 if not Trivial_Accept_OK
5794 (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5796 Set_Handled_Statement_Sequence
(N
,
5797 Make_Handled_Sequence_Of_Statements
(Loc
,
5798 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5801 -- Create and declare two labels to be placed at the end of the
5802 -- accept statement. The first label is used to allow requeues to
5803 -- skip the remainder of entry processing. The second label is used
5804 -- to skip the remainder of entry processing if the rendezvous
5805 -- completes in the middle of the accept body.
5807 if Present
(Handled_Statement_Sequence
(N
)) then
5812 Ent
:= Make_Temporary
(Loc
, 'L');
5813 Lab
:= Make_Label
(Loc
, New_Reference_To
(Ent
, Loc
));
5815 Make_Implicit_Label_Declaration
(Loc
,
5816 Defining_Identifier
=> Ent
,
5817 Label_Construct
=> Lab
);
5818 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5820 Ent
:= Make_Temporary
(Loc
, 'L');
5821 Lab
:= Make_Label
(Loc
, New_Reference_To
(Ent
, Loc
));
5823 Make_Implicit_Label_Declaration
(Loc
,
5824 Defining_Identifier
=> Ent
,
5825 Label_Construct
=> Lab
);
5826 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5834 -- Case of stand alone accept statement
5836 if Is_List_Member
(N
) then
5838 if Present
(Handled_Statement_Sequence
(N
)) then
5839 Ann
:= Make_Temporary
(Loc
, 'A');
5842 Make_Object_Declaration
(Loc
,
5843 Defining_Identifier
=> Ann
,
5844 Object_Definition
=>
5845 New_Reference_To
(RTE
(RE_Address
), Loc
));
5847 Insert_Before_And_Analyze
(N
, Adecl
);
5848 Insert_Before_And_Analyze
(N
, Ldecl
);
5849 Insert_Before_And_Analyze
(N
, Ldecl2
);
5852 -- Case of accept statement which is in an accept alternative
5856 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5857 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5861 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5862 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5864 -- ??? Consider a single label for select statements
5866 if Present
(Handled_Statement_Sequence
(N
)) then
5868 Statements
(Handled_Statement_Sequence
(N
)));
5872 Statements
(Handled_Statement_Sequence
(N
)));
5876 -- Find first accept alternative of the selective accept. A
5877 -- valid selective accept must have at least one accept in it.
5879 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5881 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5885 -- If we are the first accept statement, then we have to create
5886 -- the Ann variable, as for the stand alone case, except that
5887 -- it is inserted before the selective accept. Similarly, a
5888 -- label for requeue expansion must be declared.
5890 if N
= Accept_Statement
(Alt
) then
5891 Ann
:= Make_Temporary
(Loc
, 'A');
5893 Make_Object_Declaration
(Loc
,
5894 Defining_Identifier
=> Ann
,
5895 Object_Definition
=>
5896 New_Reference_To
(RTE
(RE_Address
), Loc
));
5898 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5900 -- If we are not the first accept statement, then find the Ann
5901 -- variable allocated by the first accept and use it.
5905 Node
(Last_Elmt
(Accept_Address
5906 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5911 -- Merge here with Ann either created or referenced, and Adecl
5912 -- pointing to the corresponding declaration. Remaining processing
5913 -- is the same for the two cases.
5915 if Present
(Ann
) then
5916 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5917 Set_Debug_Info_Needed
(Ann
);
5920 -- Create renaming declarations for the entry formals. Each reference
5921 -- to a formal becomes a dereference of a component of the parameter
5922 -- block, whose address is held in Ann. These declarations are
5923 -- eventually inserted into the accept block, and analyzed there so
5924 -- that they have the proper scope for gdb and do not conflict with
5925 -- other declarations.
5927 if Present
(Parameter_Specifications
(N
))
5928 and then Present
(Handled_Statement_Sequence
(N
))
5935 Renamed_Formal
: Node_Id
;
5939 Formal
:= First_Formal
(Ent
);
5941 while Present
(Formal
) loop
5942 Comp
:= Entry_Component
(Formal
);
5943 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5945 Set_Etype
(New_F
, Etype
(Formal
));
5946 Set_Scope
(New_F
, Ent
);
5948 -- Now we set debug info needed on New_F even though it does
5949 -- not come from source, so that the debugger will get the
5950 -- right information for these generated names.
5952 Set_Debug_Info_Needed
(New_F
);
5954 if Ekind
(Formal
) = E_In_Parameter
then
5955 Set_Ekind
(New_F
, E_Constant
);
5957 Set_Ekind
(New_F
, E_Variable
);
5958 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5961 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5964 Make_Selected_Component
(Loc
,
5966 Unchecked_Convert_To
(
5967 Entry_Parameters_Type
(Ent
),
5968 New_Reference_To
(Ann
, Loc
)),
5970 New_Reference_To
(Comp
, Loc
));
5973 Build_Renamed_Formal_Declaration
5974 (New_F
, Formal
, Comp
, Renamed_Formal
);
5976 if No
(Declarations
(N
)) then
5977 Set_Declarations
(N
, New_List
);
5980 Append
(Decl
, Declarations
(N
));
5981 Set_Renamed_Object
(Formal
, New_F
);
5982 Next_Formal
(Formal
);
5989 end Expand_Accept_Declarations
;
5991 ---------------------------------------------
5992 -- Expand_Access_Protected_Subprogram_Type --
5993 ---------------------------------------------
5995 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5996 Loc
: constant Source_Ptr
:= Sloc
(N
);
5998 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5999 D_T
: constant Entity_Id
:= Designated_Type
(T
);
6000 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
6001 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
6002 P_List
: constant List_Id
:= Build_Protected_Spec
6003 (N
, RTE
(RE_Address
), D_T
, False);
6009 -- Create access to subprogram with full signature
6011 if Etype
(D_T
) /= Standard_Void_Type
then
6013 Make_Access_Function_Definition
(Loc
,
6014 Parameter_Specifications
=> P_List
,
6015 Result_Definition
=>
6016 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
6020 Make_Access_Procedure_Definition
(Loc
,
6021 Parameter_Specifications
=> P_List
);
6025 Make_Full_Type_Declaration
(Loc
,
6026 Defining_Identifier
=> D_T2
,
6027 Type_Definition
=> Def1
);
6029 Insert_After_And_Analyze
(N
, Decl1
);
6031 -- Associate the access to subprogram with its original access to
6032 -- protected subprogram type. Needed by the backend to know that this
6033 -- type corresponds with an access to protected subprogram type.
6035 Set_Original_Access_Type
(D_T2
, T
);
6037 -- Create Equivalent_Type, a record with two components for an access to
6038 -- object and an access to subprogram.
6041 Make_Component_Declaration
(Loc
,
6042 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6043 Component_Definition
=>
6044 Make_Component_Definition
(Loc
,
6045 Aliased_Present
=> False,
6046 Subtype_Indication
=>
6047 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
6049 Make_Component_Declaration
(Loc
,
6050 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
6051 Component_Definition
=>
6052 Make_Component_Definition
(Loc
,
6053 Aliased_Present
=> False,
6054 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
6057 Make_Full_Type_Declaration
(Loc
,
6058 Defining_Identifier
=> E_T
,
6060 Make_Record_Definition
(Loc
,
6062 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
6064 Insert_After_And_Analyze
(Decl1
, Decl2
);
6065 Set_Equivalent_Type
(T
, E_T
);
6066 end Expand_Access_Protected_Subprogram_Type
;
6068 --------------------------
6069 -- Expand_Entry_Barrier --
6070 --------------------------
6072 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
6073 Cond
: constant Node_Id
:=
6074 Condition
(Entry_Body_Formal_Part
(N
));
6075 Prot
: constant Entity_Id
:= Scope
(Ent
);
6076 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
6079 Body_Decl
: Node_Id
;
6082 if No_Run_Time_Mode
then
6083 Error_Msg_CRT
("entry barrier", N
);
6087 -- The body of the entry barrier must be analyzed in the context of the
6088 -- protected object, but its scope is external to it, just as any other
6089 -- unprotected version of a protected operation. The specification has
6090 -- been produced when the protected type declaration was elaborated. We
6091 -- build the body, insert it in the enclosing scope, but analyze it in
6092 -- the current context. A more uniform approach would be to treat the
6093 -- barrier just as a protected function, and discard the protected
6094 -- version of it because it is never called.
6096 if Full_Expander_Active
then
6097 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6098 Func
:= Barrier_Function
(Ent
);
6099 Set_Corresponding_Spec
(B_F
, Func
);
6101 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
6103 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
6104 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
6107 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
6109 Set_Discriminals
(Spec_Decl
);
6110 Set_Scope
(Func
, Scope
(Prot
));
6113 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6116 -- The Ravenscar profile restricts barriers to simple variables declared
6117 -- within the protected object. We also allow Boolean constants, since
6118 -- these appear in several published examples and are also allowed by
6119 -- the Aonix compiler.
6121 -- Note that after analysis variables in this context will be replaced
6122 -- by the corresponding prival, that is to say a renaming of a selected
6123 -- component of the form _Object.Var. If expansion is disabled, as
6124 -- within a generic, we check that the entity appears in the current
6127 if Is_Entity_Name
(Cond
) then
6129 -- A small optimization of useless renamings. If the scope of the
6130 -- entity of the condition is not the barrier function, then the
6131 -- condition does not reference any of the generated renamings
6132 -- within the function.
6134 if Full_Expander_Active
and then Scope
(Entity
(Cond
)) /= Func
then
6135 Set_Declarations
(B_F
, Empty_List
);
6138 if Entity
(Cond
) = Standard_False
6140 Entity
(Cond
) = Standard_True
6144 elsif not Expander_Active
6145 and then Scope
(Entity
(Cond
)) = Current_Scope
6149 -- Check for case of _object.all.field (note that the explicit
6150 -- dereference gets inserted by analyze/expand of _object.field)
6152 elsif Present
(Renamed_Object
(Entity
(Cond
)))
6154 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
6158 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
6164 -- It is not a boolean variable or literal, so check the restriction
6166 Check_Restriction
(Simple_Barriers
, Cond
);
6167 end Expand_Entry_Barrier
;
6169 ------------------------------
6170 -- Expand_N_Abort_Statement --
6171 ------------------------------
6173 -- Expand abort T1, T2, .. Tn; into:
6174 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6176 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6177 Loc
: constant Source_Ptr
:= Sloc
(N
);
6178 Tlist
: constant List_Id
:= Names
(N
);
6184 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6187 Tasknm
:= First
(Tlist
);
6189 while Present
(Tasknm
) loop
6192 -- A task interface class-wide type object is being aborted.
6193 -- Retrieve its _task_id by calling a dispatching routine.
6195 if Ada_Version
>= Ada_2005
6196 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6197 and then Is_Interface
(Etype
(Tasknm
))
6198 and then Is_Task_Interface
(Etype
(Tasknm
))
6200 Append_To
(Component_Associations
(Aggr
),
6201 Make_Component_Association
(Loc
,
6202 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6205 -- Task_Id (Tasknm._disp_get_task_id)
6207 Make_Unchecked_Type_Conversion
(Loc
,
6209 New_Reference_To
(RTE
(RO_ST_Task_Id
), Loc
),
6211 Make_Selected_Component
(Loc
,
6212 Prefix
=> New_Copy_Tree
(Tasknm
),
6214 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6217 Append_To
(Component_Associations
(Aggr
),
6218 Make_Component_Association
(Loc
,
6219 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6220 Expression
=> Concurrent_Ref
(Tasknm
)));
6227 Make_Procedure_Call_Statement
(Loc
,
6228 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
6229 Parameter_Associations
=> New_List
(
6230 Make_Qualified_Expression
(Loc
,
6231 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
6232 Expression
=> Aggr
))));
6235 end Expand_N_Abort_Statement
;
6237 -------------------------------
6238 -- Expand_N_Accept_Statement --
6239 -------------------------------
6241 -- This procedure handles expansion of accept statements that stand
6242 -- alone, i.e. they are not part of an accept alternative. The expansion
6243 -- of accept statement in accept alternatives is handled by the routines
6244 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6245 -- following description applies only to stand alone accept statements.
6247 -- If there is no handled statement sequence, or only null statements,
6248 -- then this is called a trivial accept, and the expansion is:
6250 -- Accept_Trivial (entry-index)
6252 -- If there is a handled statement sequence, then the expansion is:
6259 -- Accept_Call (entry-index, Ann);
6260 -- Renaming_Declarations for formals
6261 -- <statement sequence from N_Accept_Statement node>
6262 -- Complete_Rendezvous;
6267 -- <exception handler from N_Accept_Statement node>
6268 -- Complete_Rendezvous;
6270 -- <exception handler from N_Accept_Statement node>
6271 -- Complete_Rendezvous;
6276 -- when all others =>
6277 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6280 -- The first three declarations were already inserted ahead of the accept
6281 -- statement by the Expand_Accept_Declarations procedure, which was called
6282 -- directly from the semantics during analysis of the accept statement,
6283 -- before analyzing its contained statements.
6285 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6286 -- from possible expansion activity (the original source of course does
6287 -- not have any declarations associated with the accept statement, since
6288 -- an accept statement has no declarative part). In particular, if the
6289 -- expander is active, the first such declaration is the declaration of
6290 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6292 -- The two blocks are merged into a single block if the inner block has
6293 -- no exception handlers, but otherwise two blocks are required, since
6294 -- exceptions might be raised in the exception handlers of the inner
6295 -- block, and Exceptional_Complete_Rendezvous must be called.
6297 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6298 Loc
: constant Source_Ptr
:= Sloc
(N
);
6299 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6300 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6301 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6302 Eent
: constant Entity_Id
:= Entity
(Ename
);
6303 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6304 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6305 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6311 -- If the accept statement is not part of a list, then its parent must
6312 -- be an accept alternative, and, as described above, we do not do any
6313 -- expansion for such accept statements at this level.
6315 if not Is_List_Member
(N
) then
6316 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6319 -- Trivial accept case (no statement sequence, or null statements).
6320 -- If the accept statement has declarations, then just insert them
6321 -- before the procedure call.
6323 elsif Trivial_Accept_OK
6324 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6326 -- Remove declarations for renamings, because the parameter block
6327 -- will not be assigned.
6334 D
:= First
(Declarations
(N
));
6336 while Present
(D
) loop
6338 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6346 if Present
(Declarations
(N
)) then
6347 Insert_Actions
(N
, Declarations
(N
));
6351 Make_Procedure_Call_Statement
(Loc
,
6352 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
6353 Parameter_Associations
=> New_List
(
6354 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6358 -- Discard Entry_Address that was created for it, so it will not be
6359 -- emitted if this accept statement is in the statement part of a
6360 -- delay alternative.
6362 if Present
(Stats
) then
6363 Remove_Last_Elmt
(Acstack
);
6366 -- Case of statement sequence present
6369 -- Construct the block, using the declarations from the accept
6370 -- statement if any to initialize the declarations of the block.
6372 Blkent
:= Make_Temporary
(Loc
, 'A');
6373 Set_Ekind
(Blkent
, E_Block
);
6374 Set_Etype
(Blkent
, Standard_Void_Type
);
6375 Set_Scope
(Blkent
, Current_Scope
);
6378 Make_Block_Statement
(Loc
,
6379 Identifier
=> New_Reference_To
(Blkent
, Loc
),
6380 Declarations
=> Declarations
(N
),
6381 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6383 -- For the analysis of the generated declarations, the parent node
6384 -- must be properly set.
6386 Set_Parent
(Block
, Parent
(N
));
6388 -- Prepend call to Accept_Call to main statement sequence If the
6389 -- accept has exception handlers, the statement sequence is wrapped
6390 -- in a block. Insert call and renaming declarations in the
6391 -- declarations of the block, so they are elaborated before the
6395 Make_Procedure_Call_Statement
(Loc
,
6396 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
6397 Parameter_Associations
=> New_List
(
6398 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6399 New_Reference_To
(Ann
, Loc
)));
6401 if Parent
(Stats
) = N
then
6402 Prepend
(Call
, Statements
(Stats
));
6404 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6409 Push_Scope
(Blkent
);
6417 D
:= First
(Declarations
(N
));
6418 while Present
(D
) loop
6421 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6423 -- The renaming declarations for the formals were created
6424 -- during analysis of the accept statement, and attached to
6425 -- the list of declarations. Place them now in the context
6426 -- of the accept block or subprogram.
6429 Typ
:= Entity
(Subtype_Mark
(D
));
6430 Insert_After
(Call
, D
);
6433 -- If the formal is class_wide, it does not have an actual
6434 -- subtype. The analysis of the renaming declaration creates
6435 -- one, but we need to retain the class-wide nature of the
6438 if Is_Class_Wide_Type
(Typ
) then
6439 Set_Etype
(Defining_Identifier
(D
), Typ
);
6450 -- Replace the accept statement by the new block
6455 -- Last step is to unstack the Accept_Address value
6457 Remove_Last_Elmt
(Acstack
);
6459 end Expand_N_Accept_Statement
;
6461 ----------------------------------
6462 -- Expand_N_Asynchronous_Select --
6463 ----------------------------------
6465 -- This procedure assumes that the trigger statement is an entry call or
6466 -- a dispatching procedure call. A delay alternative should already have
6467 -- been expanded into an entry call to the appropriate delay object Wait
6470 -- If the trigger is a task entry call, the select is implemented with
6471 -- a Task_Entry_Call:
6476 -- P : parms := (parm, parm, parm);
6478 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6480 -- procedure _clean is
6483 -- Cancel_Task_Entry_Call (C);
6490 -- (<acceptor-task>, -- Acceptor
6491 -- <entry-index>, -- E
6492 -- P'Address, -- Uninterpreted_Data
6493 -- Asynchronous_Call, -- Mode
6494 -- B); -- Rendezvous_Successful
6501 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6504 -- when Abort_Signal => Abort_Undefer;
6511 -- <triggered-statements>
6515 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6516 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6520 -- P : parms := (parm, parm, parm);
6522 -- Call_Simple (acceptor-task, entry-index, P'Address);
6528 -- so the task at hand is to convert the latter expansion into the former
6530 -- If the trigger is a protected entry call, the select is implemented
6531 -- with Protected_Entry_Call:
6534 -- P : E1_Params := (param, param, param);
6535 -- Bnn : Communications_Block;
6540 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6542 -- procedure _clean is
6545 -- if Enqueued (Bnn) then
6546 -- Cancel_Protected_Entry_Call (Bnn);
6553 -- Protected_Entry_Call
6554 -- (po._object'Access, -- Object
6555 -- <entry index>, -- E
6556 -- P'Address, -- Uninterpreted_Data
6557 -- Asynchronous_Call, -- Mode
6560 -- if Enqueued (Bnn) then
6564 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6567 -- when Abort_Signal => Abort_Undefer;
6570 -- if not Cancelled (Bnn) then
6571 -- <triggered-statements>
6575 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6579 -- P : E1_Params := (param, param, param);
6580 -- Bnn : Communications_Block;
6583 -- Protected_Entry_Call
6584 -- (po._object'Access, -- Object
6585 -- <entry index>, -- E
6586 -- P'Address, -- Uninterpreted_Data
6587 -- Simple_Call, -- Mode
6594 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6598 -- B : Boolean := False;
6599 -- Bnn : Communication_Block;
6600 -- C : Ada.Tags.Prim_Op_Kind;
6601 -- D : System.Storage_Elements.Dummy_Communication_Block;
6602 -- K : Ada.Tags.Tagged_Kind :=
6603 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6604 -- P : Parameters := (Param1 .. ParamN);
6609 -- if K = Ada.Tags.TK_Limited_Tagged then
6610 -- <dispatching-call>;
6611 -- <triggering-statements>;
6615 -- Ada.Tags.Get_Offset_Index
6616 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6618 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6620 -- if C = POK_Protected_Entry then
6622 -- procedure _clean is
6624 -- if Enqueued (Bnn) then
6625 -- Cancel_Protected_Entry_Call (Bnn);
6631 -- _Disp_Asynchronous_Select
6632 -- (<object>, S, P'Address, D, B);
6633 -- Bnn := Communication_Block (D);
6635 -- Param1 := P.Param1;
6637 -- ParamN := P.ParamN;
6639 -- if Enqueued (Bnn) then
6640 -- <abortable-statements>
6643 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6646 -- when Abort_Signal => Abort_Undefer;
6649 -- if not Cancelled (Bnn) then
6650 -- <triggering-statements>
6653 -- elsif C = POK_Task_Entry then
6655 -- procedure _clean is
6657 -- Cancel_Task_Entry_Call (U);
6663 -- _Disp_Asynchronous_Select
6664 -- (<object>, S, P'Address, D, B);
6665 -- Bnn := Communication_Bloc (D);
6667 -- Param1 := P.Param1;
6669 -- ParamN := P.ParamN;
6674 -- <abortable-statements>
6676 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6679 -- when Abort_Signal => Abort_Undefer;
6683 -- <triggering-statements>
6688 -- <dispatching-call>;
6689 -- <triggering-statements>
6694 -- The job is to convert this to the asynchronous form
6696 -- If the trigger is a delay statement, it will have been expanded into a
6697 -- call to one of the GNARL delay procedures. This routine will convert
6698 -- this into a protected entry call on a delay object and then continue
6699 -- processing as for a protected entry call trigger. This requires
6700 -- declaring a Delay_Block object and adding a pointer to this object to
6701 -- the parameter list of the delay procedure to form the parameter list of
6702 -- the entry call. This object is used by the runtime to queue the delay
6705 -- For a description of the use of P and the assignments after the call,
6706 -- see Expand_N_Entry_Call_Statement.
6708 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6709 Loc
: constant Source_Ptr
:= Sloc
(N
);
6710 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6711 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6713 Abort_Block_Ent
: Entity_Id
;
6714 Abortable_Block
: Node_Id
;
6717 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6718 Blk_Typ
: Entity_Id
;
6720 Call_Ent
: Entity_Id
;
6721 Cancel_Param
: Entity_Id
;
6722 Cleanup_Block
: Node_Id
;
6723 Cleanup_Block_Ent
: Entity_Id
;
6724 Cleanup_Stmts
: List_Id
;
6725 Conc_Typ_Stmts
: List_Id
;
6727 Dblock_Ent
: Entity_Id
;
6732 Enqueue_Call
: Node_Id
;
6735 Handler_Stmt
: Node_Id
;
6737 Lim_Typ_Stmts
: List_Id
;
6743 ProtE_Stmts
: List_Id
;
6744 ProtP_Stmts
: List_Id
;
6747 TaskE_Stmts
: List_Id
;
6750 B
: Entity_Id
; -- Call status flag
6751 Bnn
: Entity_Id
; -- Communication block
6752 C
: Entity_Id
; -- Call kind
6753 K
: Entity_Id
; -- Tagged kind
6754 P
: Entity_Id
; -- Parameter block
6755 S
: Entity_Id
; -- Primitive operation slot
6756 T
: Entity_Id
; -- Additional status flag
6759 Process_Statements_For_Controlled_Objects
(Trig
);
6760 Process_Statements_For_Controlled_Objects
(Abrt
);
6762 Ecall
:= Triggering_Statement
(Trig
);
6764 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6766 -- Retrieve Astats and Tstats now because the finalization machinery may
6767 -- wrap them in blocks.
6769 Astats
:= Statements
(Abrt
);
6770 Tstats
:= Statements
(Trig
);
6772 -- The arguments in the call may require dynamic allocation, and the
6773 -- call statement may have been transformed into a block. The block
6774 -- may contain additional declarations for internal entities, and the
6775 -- original call is found by sequential search.
6777 if Nkind
(Ecall
) = N_Block_Statement
then
6778 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6779 while not Nkind_In
(Ecall
, N_Procedure_Call_Statement
,
6780 N_Entry_Call_Statement
)
6786 -- This is either a dispatching call or a delay statement used as a
6787 -- trigger which was expanded into a procedure call.
6789 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6790 if Ada_Version
>= Ada_2005
6792 (No
(Original_Node
(Ecall
))
6793 or else not Nkind_In
(Original_Node
(Ecall
),
6794 N_Delay_Relative_Statement
,
6795 N_Delay_Until_Statement
))
6797 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6802 -- Call status flag processing, generate:
6803 -- B : Boolean := False;
6805 B
:= Build_B
(Loc
, Decls
);
6807 -- Communication block processing, generate:
6808 -- Bnn : Communication_Block;
6810 Bnn
:= Make_Temporary
(Loc
, 'B');
6812 Make_Object_Declaration
(Loc
,
6813 Defining_Identifier
=> Bnn
,
6814 Object_Definition
=>
6815 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
6817 -- Call kind processing, generate:
6818 -- C : Ada.Tags.Prim_Op_Kind;
6820 C
:= Build_C
(Loc
, Decls
);
6822 -- Tagged kind processing, generate:
6823 -- K : Ada.Tags.Tagged_Kind :=
6824 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6826 -- Dummy communication block, generate:
6827 -- D : Dummy_Communication_Block;
6830 Make_Object_Declaration
(Loc
,
6831 Defining_Identifier
=>
6832 Make_Defining_Identifier
(Loc
, Name_uD
),
6833 Object_Definition
=>
6835 RTE
(RE_Dummy_Communication_Block
), Loc
)));
6837 K
:= Build_K
(Loc
, Decls
, Obj
);
6839 -- Parameter block processing
6841 Blk_Typ
:= Build_Parameter_Block
6842 (Loc
, Actuals
, Formals
, Decls
);
6843 P
:= Parameter_Block_Pack
6844 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6846 -- Dispatch table slot processing, generate:
6849 S
:= Build_S
(Loc
, Decls
);
6851 -- Additional status flag processing, generate:
6854 T
:= Make_Temporary
(Loc
, 'T');
6856 Make_Object_Declaration
(Loc
,
6857 Defining_Identifier
=> T
,
6858 Object_Definition
=>
6859 New_Reference_To
(Standard_Boolean
, Loc
)));
6861 ------------------------------
6862 -- Protected entry handling --
6863 ------------------------------
6866 -- Param1 := P.Param1;
6868 -- ParamN := P.ParamN;
6870 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6873 -- Bnn := Communication_Block (D);
6875 Prepend_To
(Cleanup_Stmts
,
6876 Make_Assignment_Statement
(Loc
,
6878 New_Reference_To
(Bnn
, Loc
),
6880 Make_Unchecked_Type_Conversion
(Loc
,
6882 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
6883 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
6886 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6888 Prepend_To
(Cleanup_Stmts
,
6889 Make_Procedure_Call_Statement
(Loc
,
6892 Find_Prim_Op
(Etype
(Etype
(Obj
)),
6893 Name_uDisp_Asynchronous_Select
),
6895 Parameter_Associations
=>
6897 New_Copy_Tree
(Obj
), -- <object>
6898 New_Reference_To
(S
, Loc
), -- S
6899 Make_Attribute_Reference
(Loc
, -- P'Address
6900 Prefix
=> New_Reference_To
(P
, Loc
),
6901 Attribute_Name
=> Name_Address
),
6902 Make_Identifier
(Loc
, Name_uD
), -- D
6903 New_Reference_To
(B
, Loc
)))); -- B
6906 -- if Enqueued (Bnn) then
6907 -- <abortable-statements>
6910 Append_To
(Cleanup_Stmts
,
6911 Make_Implicit_If_Statement
(N
,
6913 Make_Function_Call
(Loc
,
6915 New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
6916 Parameter_Associations
=>
6917 New_List
(New_Reference_To
(Bnn
, Loc
))),
6920 New_Copy_List_Tree
(Astats
)));
6922 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6923 -- will then generate a _clean for the communication block Bnn.
6927 -- procedure _clean is
6929 -- if Enqueued (Bnn) then
6930 -- Cancel_Protected_Entry_Call (Bnn);
6939 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
6941 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
6943 -- Wrap the cleanup block in an exception handling block
6949 -- when Abort_Signal => Abort_Undefer;
6952 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
6955 Make_Implicit_Label_Declaration
(Loc
,
6956 Defining_Identifier
=> Abort_Block_Ent
),
6959 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
6962 -- if not Cancelled (Bnn) then
6963 -- <triggering-statements>
6966 Append_To
(ProtE_Stmts
,
6967 Make_Implicit_If_Statement
(N
,
6971 Make_Function_Call
(Loc
,
6973 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
6974 Parameter_Associations
=>
6975 New_List
(New_Reference_To
(Bnn
, Loc
)))),
6978 New_Copy_List_Tree
(Tstats
)));
6980 -------------------------
6981 -- Task entry handling --
6982 -------------------------
6985 -- Param1 := P.Param1;
6987 -- ParamN := P.ParamN;
6989 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6992 -- Bnn := Communication_Block (D);
6994 Append_To
(TaskE_Stmts
,
6995 Make_Assignment_Statement
(Loc
,
6997 New_Reference_To
(Bnn
, Loc
),
6999 Make_Unchecked_Type_Conversion
(Loc
,
7001 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
),
7002 Expression
=> Make_Identifier
(Loc
, Name_uD
))));
7005 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7007 Prepend_To
(TaskE_Stmts
,
7008 Make_Procedure_Call_Statement
(Loc
,
7011 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7012 Name_uDisp_Asynchronous_Select
),
7015 Parameter_Associations
=>
7017 New_Copy_Tree
(Obj
), -- <object>
7018 New_Reference_To
(S
, Loc
), -- S
7019 Make_Attribute_Reference
(Loc
, -- P'Address
7020 Prefix
=> New_Reference_To
(P
, Loc
),
7021 Attribute_Name
=> Name_Address
),
7022 Make_Identifier
(Loc
, Name_uD
), -- D
7023 New_Reference_To
(B
, Loc
)))); -- B
7028 Prepend_To
(TaskE_Stmts
,
7029 Make_Procedure_Call_Statement
(Loc
,
7030 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7031 Parameter_Associations
=> No_List
));
7035 -- <abortable-statements>
7037 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7039 Prepend_To
(Cleanup_Stmts
,
7040 Make_Procedure_Call_Statement
(Loc
,
7041 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7042 Parameter_Associations
=> No_List
));
7044 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7045 -- will generate a _clean for the additional status flag.
7049 -- procedure _clean is
7051 -- Cancel_Task_Entry_Call (U);
7059 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7061 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7063 -- Wrap the cleanup block in an exception handling block
7069 -- when Abort_Signal => Abort_Undefer;
7072 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7074 Append_To
(TaskE_Stmts
,
7075 Make_Implicit_Label_Declaration
(Loc
,
7076 Defining_Identifier
=> Abort_Block_Ent
));
7078 Append_To
(TaskE_Stmts
,
7080 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7084 -- <triggering-statements>
7087 Append_To
(TaskE_Stmts
,
7088 Make_Implicit_If_Statement
(N
,
7090 Make_Op_Not
(Loc
, Right_Opnd
=> New_Reference_To
(T
, Loc
)),
7093 New_Copy_List_Tree
(Tstats
)));
7095 ----------------------------------
7096 -- Protected procedure handling --
7097 ----------------------------------
7100 -- <dispatching-call>;
7101 -- <triggering-statements>
7103 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7104 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7107 -- S := Ada.Tags.Get_Offset_Index
7108 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7111 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7114 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7116 Append_To
(Conc_Typ_Stmts
,
7117 Make_Procedure_Call_Statement
(Loc
,
7120 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7121 Name_uDisp_Get_Prim_Op_Kind
),
7123 Parameter_Associations
=>
7125 New_Copy_Tree
(Obj
),
7126 New_Reference_To
(S
, Loc
),
7127 New_Reference_To
(C
, Loc
))));
7130 -- if C = POK_Procedure_Entry then
7132 -- elsif C = POK_Task_Entry then
7138 Append_To
(Conc_Typ_Stmts
,
7139 Make_Implicit_If_Statement
(N
,
7143 New_Reference_To
(C
, Loc
),
7145 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7152 Make_Elsif_Part
(Loc
,
7156 New_Reference_To
(C
, Loc
),
7158 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
)),
7167 -- <dispatching-call>;
7168 -- <triggering-statements>
7170 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7171 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7174 -- if K = Ada.Tags.TK_Limited_Tagged then
7181 Make_Implicit_If_Statement
(N
,
7185 New_Reference_To
(K
, Loc
),
7187 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
7196 Make_Block_Statement
(Loc
,
7199 Handled_Statement_Sequence
=>
7200 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7205 -- Delay triggering statement processing
7208 -- Add a Delay_Block object to the parameter list of the delay
7209 -- procedure to form the parameter list of the Wait entry call.
7211 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7213 Pdef
:= Entity
(Name
(Ecall
));
7215 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7217 New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
7219 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7221 New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
7223 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7224 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
7227 Append_To
(Parameter_Associations
(Ecall
),
7228 Make_Attribute_Reference
(Loc
,
7229 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7230 Attribute_Name
=> Name_Unchecked_Access
));
7232 -- Create the inner block to protect the abortable part
7234 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7237 Make_Procedure_Call_Statement
(Loc
,
7238 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7241 Make_Block_Statement
(Loc
,
7242 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7243 Handled_Statement_Sequence
=>
7244 Make_Handled_Sequence_Of_Statements
(Loc
,
7245 Statements
=> Astats
),
7246 Has_Created_Identifier
=> True,
7247 Is_Asynchronous_Call_Block
=> True);
7249 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7252 Make_Implicit_If_Statement
(N
,
7254 Make_Function_Call
(Loc
,
7255 Name
=> Enqueue_Call
,
7256 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7258 New_List
(Make_Block_Statement
(Loc
,
7259 Handled_Statement_Sequence
=>
7260 Make_Handled_Sequence_Of_Statements
(Loc
,
7261 Statements
=> New_List
(
7262 Make_Implicit_Label_Declaration
(Loc
,
7263 Defining_Identifier
=> Blk_Ent
,
7264 Label_Construct
=> Abortable_Block
),
7266 Exception_Handlers
=> Hdle
)))));
7268 Stmts
:= New_List
(Ecall
);
7270 -- Construct statement sequence for new block
7273 Make_Implicit_If_Statement
(N
,
7275 Make_Function_Call
(Loc
,
7276 Name
=> New_Reference_To
(
7277 RTE
(RE_Timed_Out
), Loc
),
7278 Parameter_Associations
=> New_List
(
7279 Make_Attribute_Reference
(Loc
,
7280 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
7281 Attribute_Name
=> Name_Unchecked_Access
))),
7282 Then_Statements
=> Tstats
));
7284 -- The result is the new block
7286 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7289 Make_Block_Statement
(Loc
,
7290 Declarations
=> New_List
(
7291 Make_Object_Declaration
(Loc
,
7292 Defining_Identifier
=> Dblock_Ent
,
7293 Aliased_Present
=> True,
7294 Object_Definition
=> New_Reference_To
(
7295 RTE
(RE_Delay_Block
), Loc
))),
7297 Handled_Statement_Sequence
=>
7298 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7308 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7309 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7311 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7312 Decls
:= Declarations
(Ecall
);
7314 if Is_Protected_Type
(Etype
(Concval
)) then
7316 -- Get the declarations of the block expanded from the entry call
7318 Decl
:= First
(Decls
);
7319 while Present
(Decl
)
7321 (Nkind
(Decl
) /= N_Object_Declaration
7322 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7323 RE_Communication_Block
))
7328 pragma Assert
(Present
(Decl
));
7329 Cancel_Param
:= Defining_Identifier
(Decl
);
7331 -- Change the mode of the Protected_Entry_Call call
7333 -- Protected_Entry_Call (
7334 -- Object => po._object'Access,
7335 -- E => <entry index>;
7336 -- Uninterpreted_Data => P'Address;
7337 -- Mode => Asynchronous_Call;
7340 Stmt
:= First
(Stmts
);
7342 -- Skip assignments to temporaries created for in-out parameters
7344 -- This makes unwarranted assumptions about the shape of the expanded
7345 -- tree for the call, and should be cleaned up ???
7347 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7353 Param
:= First
(Parameter_Associations
(Call
));
7354 while Present
(Param
)
7355 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7360 pragma Assert
(Present
(Param
));
7361 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7364 -- Append an if statement to execute the abortable part
7367 -- if Enqueued (Bnn) then
7370 Make_Implicit_If_Statement
(N
,
7372 Make_Function_Call
(Loc
,
7373 Name
=> New_Reference_To
(RTE
(RE_Enqueued
), Loc
),
7374 Parameter_Associations
=> New_List
(
7375 New_Reference_To
(Cancel_Param
, Loc
))),
7376 Then_Statements
=> Astats
));
7379 Make_Block_Statement
(Loc
,
7380 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7381 Handled_Statement_Sequence
=>
7382 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7383 Has_Created_Identifier
=> True,
7384 Is_Asynchronous_Call_Block
=> True);
7386 -- For the VM call Update_Exception instead of Abort_Undefer.
7387 -- See 4jexcept.ads for an explanation.
7389 if VM_Target
= No_VM
then
7390 if Exception_Mechanism
= Back_End_Exceptions
then
7392 -- Aborts are not deferred at beginning of exception handlers
7395 Handler_Stmt
:= Make_Null_Statement
(Loc
);
7398 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7399 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
7400 Parameter_Associations
=> No_List
);
7403 Handler_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
7404 Name
=> New_Reference_To
(RTE
(RE_Update_Exception
), Loc
),
7405 Parameter_Associations
=> New_List
(
7406 Make_Function_Call
(Loc
,
7407 Name
=> New_Occurrence_Of
7408 (RTE
(RE_Current_Target_Exception
), Loc
))));
7412 Make_Block_Statement
(Loc
,
7413 Handled_Statement_Sequence
=>
7414 Make_Handled_Sequence_Of_Statements
(Loc
,
7415 Statements
=> New_List
(
7416 Make_Implicit_Label_Declaration
(Loc
,
7417 Defining_Identifier
=> Blk_Ent
,
7418 Label_Construct
=> Abortable_Block
),
7423 Exception_Handlers
=> New_List
(
7424 Make_Implicit_Exception_Handler
(Loc
,
7426 -- when Abort_Signal =>
7427 -- Abort_Undefer.all;
7429 Exception_Choices
=>
7430 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
7431 Statements
=> New_List
(Handler_Stmt
))))),
7433 -- if not Cancelled (Bnn) then
7434 -- triggered statements
7437 Make_Implicit_If_Statement
(N
,
7438 Condition
=> Make_Op_Not
(Loc
,
7440 Make_Function_Call
(Loc
,
7441 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7442 Parameter_Associations
=> New_List
(
7443 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7444 Then_Statements
=> Tstats
));
7446 -- Asynchronous task entry call
7453 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7455 -- Insert declaration of B in declarations of existing block
7458 Make_Object_Declaration
(Loc
,
7459 Defining_Identifier
=> B
,
7460 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7462 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7464 -- Insert declaration of C in declarations of existing block
7467 Make_Object_Declaration
(Loc
,
7468 Defining_Identifier
=> Cancel_Param
,
7469 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7471 -- Remove and save the call to Call_Simple
7473 Stmt
:= First
(Stmts
);
7475 -- Skip assignments to temporaries created for in-out parameters.
7476 -- This makes unwarranted assumptions about the shape of the expanded
7477 -- tree for the call, and should be cleaned up ???
7479 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7485 -- Create the inner block to protect the abortable part
7487 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7490 Make_Procedure_Call_Statement
(Loc
,
7491 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
7494 Make_Block_Statement
(Loc
,
7495 Identifier
=> New_Reference_To
(Blk_Ent
, Loc
),
7496 Handled_Statement_Sequence
=>
7497 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7498 Has_Created_Identifier
=> True,
7499 Is_Asynchronous_Call_Block
=> True);
7502 Make_Block_Statement
(Loc
,
7503 Handled_Statement_Sequence
=>
7504 Make_Handled_Sequence_Of_Statements
(Loc
,
7505 Statements
=> New_List
(
7506 Make_Implicit_Label_Declaration
(Loc
,
7507 Defining_Identifier
=> Blk_Ent
,
7508 Label_Construct
=> Abortable_Block
),
7510 Exception_Handlers
=> Hdle
)));
7512 -- Create new call statement
7514 Params
:= Parameter_Associations
(Call
);
7517 New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
7518 Append_To
(Params
, New_Reference_To
(B
, Loc
));
7521 Make_Procedure_Call_Statement
(Loc
,
7522 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7523 Parameter_Associations
=> Params
));
7525 -- Construct statement sequence for new block
7528 Make_Implicit_If_Statement
(N
,
7530 Make_Op_Not
(Loc
, New_Reference_To
(Cancel_Param
, Loc
)),
7531 Then_Statements
=> Tstats
));
7533 -- Protected the call against abort
7536 Make_Procedure_Call_Statement
(Loc
,
7537 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
7538 Parameter_Associations
=> Empty_List
));
7541 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7543 -- The result is the new block
7546 Make_Block_Statement
(Loc
,
7547 Declarations
=> Decls
,
7548 Handled_Statement_Sequence
=>
7549 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7552 end Expand_N_Asynchronous_Select
;
7554 -------------------------------------
7555 -- Expand_N_Conditional_Entry_Call --
7556 -------------------------------------
7558 -- The conditional task entry call is converted to a call to
7563 -- P : parms := (parm, parm, parm);
7567 -- (<acceptor-task>, -- Acceptor
7568 -- <entry-index>, -- E
7569 -- P'Address, -- Uninterpreted_Data
7570 -- Conditional_Call, -- Mode
7571 -- B); -- Rendezvous_Successful
7576 -- normal-statements
7582 -- For a description of the use of P and the assignments after the call,
7583 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7584 -- conditional entry call has already been expanded (by the Expand_N_Entry
7585 -- _Call_Statement procedure) as follows:
7588 -- P : parms := (parm, parm, parm);
7590 -- ... info for in-out parameters
7591 -- Call_Simple (acceptor-task, entry-index, P'Address);
7597 -- so the task at hand is to convert the latter expansion into the former
7599 -- The conditional protected entry call is converted to a call to
7600 -- Protected_Entry_Call:
7603 -- P : parms := (parm, parm, parm);
7604 -- Bnn : Communications_Block;
7607 -- Protected_Entry_Call
7608 -- (po._object'Access, -- Object
7609 -- <entry index>, -- E
7610 -- P'Address, -- Uninterpreted_Data
7611 -- Conditional_Call, -- Mode
7616 -- if Cancelled (Bnn) then
7619 -- normal-statements
7623 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7627 -- B : Boolean := False;
7628 -- C : Ada.Tags.Prim_Op_Kind;
7629 -- K : Ada.Tags.Tagged_Kind :=
7630 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7631 -- P : Parameters := (Param1 .. ParamN);
7635 -- if K = Ada.Tags.TK_Limited_Tagged then
7636 -- <dispatching-call>;
7637 -- <triggering-statements>
7641 -- Ada.Tags.Get_Offset_Index
7642 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7644 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7646 -- if C = POK_Protected_Entry
7647 -- or else C = POK_Task_Entry
7649 -- Param1 := P.Param1;
7651 -- ParamN := P.ParamN;
7655 -- if C = POK_Procedure
7656 -- or else C = POK_Protected_Procedure
7657 -- or else C = POK_Task_Procedure
7659 -- <dispatching-call>;
7662 -- <triggering-statements>
7664 -- <else-statements>
7669 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7670 Loc
: constant Source_Ptr
:= Sloc
(N
);
7671 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7672 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7675 Blk_Typ
: Entity_Id
;
7677 Call_Ent
: Entity_Id
;
7678 Conc_Typ_Stmts
: List_Id
;
7682 Lim_Typ_Stmts
: List_Id
;
7689 Transient_Blk
: Node_Id
;
7692 B
: Entity_Id
; -- Call status flag
7693 C
: Entity_Id
; -- Call kind
7694 K
: Entity_Id
; -- Tagged kind
7695 P
: Entity_Id
; -- Parameter block
7696 S
: Entity_Id
; -- Primitive operation slot
7699 Process_Statements_For_Controlled_Objects
(N
);
7701 if Ada_Version
>= Ada_2005
7702 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7704 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7709 -- Call status flag processing, generate:
7710 -- B : Boolean := False;
7712 B
:= Build_B
(Loc
, Decls
);
7714 -- Call kind processing, generate:
7715 -- C : Ada.Tags.Prim_Op_Kind;
7717 C
:= Build_C
(Loc
, Decls
);
7719 -- Tagged kind processing, generate:
7720 -- K : Ada.Tags.Tagged_Kind :=
7721 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7723 K
:= Build_K
(Loc
, Decls
, Obj
);
7725 -- Parameter block processing
7727 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7728 P
:= Parameter_Block_Pack
7729 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7731 -- Dispatch table slot processing, generate:
7734 S
:= Build_S
(Loc
, Decls
);
7737 -- S := Ada.Tags.Get_Offset_Index
7738 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7741 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7744 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7746 Append_To
(Conc_Typ_Stmts
,
7747 Make_Procedure_Call_Statement
(Loc
,
7750 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7751 Name_uDisp_Conditional_Select
),
7753 Parameter_Associations
=>
7755 New_Copy_Tree
(Obj
), -- <object>
7756 New_Reference_To
(S
, Loc
), -- S
7757 Make_Attribute_Reference
(Loc
, -- P'Address
7758 Prefix
=> New_Reference_To
(P
, Loc
),
7759 Attribute_Name
=> Name_Address
),
7760 New_Reference_To
(C
, Loc
), -- C
7761 New_Reference_To
(B
, Loc
)))); -- B
7764 -- if C = POK_Protected_Entry
7765 -- or else C = POK_Task_Entry
7767 -- Param1 := P.Param1;
7769 -- ParamN := P.ParamN;
7772 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7774 -- Generate the if statement only when the packed parameters need
7775 -- explicit assignments to their corresponding actuals.
7777 if Present
(Unpack
) then
7778 Append_To
(Conc_Typ_Stmts
,
7779 Make_Implicit_If_Statement
(N
,
7785 New_Reference_To
(C
, Loc
),
7787 New_Reference_To
(RTE
(
7788 RE_POK_Protected_Entry
), Loc
)),
7793 New_Reference_To
(C
, Loc
),
7795 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
7797 Then_Statements
=> Unpack
));
7802 -- if C = POK_Procedure
7803 -- or else C = POK_Protected_Procedure
7804 -- or else C = POK_Task_Procedure
7806 -- <dispatching-call>
7808 -- <normal-statements>
7810 -- <else-statements>
7813 N_Stats
:= New_Copy_List_Tree
(Statements
(Alt
));
7815 Prepend_To
(N_Stats
,
7816 Make_Implicit_If_Statement
(N
,
7822 New_Reference_To
(C
, Loc
),
7824 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
7831 New_Reference_To
(C
, Loc
),
7833 New_Reference_To
(RTE
(
7834 RE_POK_Protected_Procedure
), Loc
)),
7839 New_Reference_To
(C
, Loc
),
7841 New_Reference_To
(RTE
(
7842 RE_POK_Task_Procedure
), Loc
)))),
7847 Append_To
(Conc_Typ_Stmts
,
7848 Make_Implicit_If_Statement
(N
,
7849 Condition
=> New_Reference_To
(B
, Loc
),
7850 Then_Statements
=> N_Stats
,
7851 Else_Statements
=> Else_Statements
(N
)));
7854 -- <dispatching-call>;
7855 -- <triggering-statements>
7857 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Statements
(Alt
));
7858 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Blk
));
7861 -- if K = Ada.Tags.TK_Limited_Tagged then
7868 Make_Implicit_If_Statement
(N
,
7872 New_Reference_To
(K
, Loc
),
7874 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
7883 Make_Block_Statement
(Loc
,
7886 Handled_Statement_Sequence
=>
7887 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7889 -- As described above, the entry alternative is transformed into a
7890 -- block that contains the gnulli call, and possibly assignment
7891 -- statements for in-out parameters. The gnulli call may itself be
7892 -- rewritten into a transient block if some unconstrained parameters
7893 -- require it. We need to retrieve the call to complete its parameter
7898 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
7900 if Present
(Transient_Blk
)
7901 and then Nkind
(Transient_Blk
) = N_Block_Statement
7903 Blk
:= Transient_Blk
;
7906 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
7907 Stmt
:= First
(Stmts
);
7908 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7913 Params
:= Parameter_Associations
(Call
);
7915 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
7917 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7919 Param
:= First
(Params
);
7920 while Present
(Param
)
7921 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7926 pragma Assert
(Present
(Param
));
7927 Rewrite
(Param
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7931 -- Find the Communication_Block parameter for the call to the
7932 -- Cancelled function.
7934 Decl
:= First
(Declarations
(Blk
));
7935 while Present
(Decl
)
7936 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7937 RE_Communication_Block
)
7942 -- Add an if statement to execute the else part if the call
7943 -- does not succeed (as indicated by the Cancelled predicate).
7946 Make_Implicit_If_Statement
(N
,
7947 Condition
=> Make_Function_Call
(Loc
,
7948 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
7949 Parameter_Associations
=> New_List
(
7950 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
7951 Then_Statements
=> Else_Statements
(N
),
7952 Else_Statements
=> Statements
(Alt
)));
7955 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7957 -- Insert declaration of B in declarations of existing block
7959 if No
(Declarations
(Blk
)) then
7960 Set_Declarations
(Blk
, New_List
);
7963 Prepend_To
(Declarations
(Blk
),
7964 Make_Object_Declaration
(Loc
,
7965 Defining_Identifier
=> B
,
7966 Object_Definition
=>
7967 New_Reference_To
(Standard_Boolean
, Loc
)));
7969 -- Create new call statement
7972 New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
7973 Append_To
(Params
, New_Reference_To
(B
, Loc
));
7976 Make_Procedure_Call_Statement
(Loc
,
7977 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
7978 Parameter_Associations
=> Params
));
7980 -- Construct statement sequence for new block
7983 Make_Implicit_If_Statement
(N
,
7984 Condition
=> New_Reference_To
(B
, Loc
),
7985 Then_Statements
=> Statements
(Alt
),
7986 Else_Statements
=> Else_Statements
(N
)));
7989 -- The result is the new block
7992 Make_Block_Statement
(Loc
,
7993 Declarations
=> Declarations
(Blk
),
7994 Handled_Statement_Sequence
=>
7995 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7999 end Expand_N_Conditional_Entry_Call
;
8001 ---------------------------------------
8002 -- Expand_N_Delay_Relative_Statement --
8003 ---------------------------------------
8005 -- Delay statement is implemented as a procedure call to Delay_For
8006 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8007 -- simple delays imposed by the use of Protected Objects.
8009 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8010 Loc
: constant Source_Ptr
:= Sloc
(N
);
8013 Make_Procedure_Call_Statement
(Loc
,
8014 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
8015 Parameter_Associations
=> New_List
(Expression
(N
))));
8017 end Expand_N_Delay_Relative_Statement
;
8019 ------------------------------------
8020 -- Expand_N_Delay_Until_Statement --
8021 ------------------------------------
8023 -- Delay Until statement is implemented as a procedure call to
8024 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8026 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8027 Loc
: constant Source_Ptr
:= Sloc
(N
);
8031 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8032 Typ
:= RTE
(RO_CA_Delay_Until
);
8034 Typ
:= RTE
(RO_RT_Delay_Until
);
8038 Make_Procedure_Call_Statement
(Loc
,
8039 Name
=> New_Reference_To
(Typ
, Loc
),
8040 Parameter_Associations
=> New_List
(Expression
(N
))));
8043 end Expand_N_Delay_Until_Statement
;
8045 -------------------------
8046 -- Expand_N_Entry_Body --
8047 -------------------------
8049 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8051 -- Associate discriminals with the next protected operation body to be
8054 if Present
(Next_Protected_Operation
(N
)) then
8055 Set_Discriminals
(Parent
(Current_Scope
));
8057 end Expand_N_Entry_Body
;
8059 -----------------------------------
8060 -- Expand_N_Entry_Call_Statement --
8061 -----------------------------------
8063 -- An entry call is expanded into GNARLI calls to implement a simple entry
8064 -- call (see Build_Simple_Entry_Call).
8066 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8072 if No_Run_Time_Mode
then
8073 Error_Msg_CRT
("entry call", N
);
8077 -- If this entry call is part of an asynchronous select, don't expand it
8078 -- here; it will be expanded with the select statement. Don't expand
8079 -- timed entry calls either, as they are translated into asynchronous
8082 -- ??? This whole approach is questionable; it may be better to go back
8083 -- to allowing the expansion to take place and then attempting to fix it
8084 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8085 -- whether the expanded call is on a task or protected entry.
8087 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8088 or else N
/= Triggering_Statement
(Parent
(N
)))
8089 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8090 or else N
/= Entry_Call_Statement
(Parent
(N
))
8091 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8093 Extract_Entry
(N
, Concval
, Ename
, Index
);
8094 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8096 end Expand_N_Entry_Call_Statement
;
8098 --------------------------------
8099 -- Expand_N_Entry_Declaration --
8100 --------------------------------
8102 -- If there are parameters, then first, each of the formals is marked by
8103 -- setting Is_Entry_Formal. Next a record type is built which is used to
8104 -- hold the parameter values. The name of this record type is entryP where
8105 -- entry is the name of the entry, with an additional corresponding access
8106 -- type called entryPA. The record type has matching components for each
8107 -- formal (the component names are the same as the formal names). For
8108 -- elementary types, the component type matches the formal type. For
8109 -- composite types, an access type is declared (with the name formalA)
8110 -- which designates the formal type, and the type of the component is this
8111 -- access type. Finally the Entry_Component of each formal is set to
8112 -- reference the corresponding record component.
8114 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8115 Loc
: constant Source_Ptr
:= Sloc
(N
);
8116 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8117 Components
: List_Id
;
8120 Last_Decl
: Node_Id
;
8121 Component
: Entity_Id
;
8124 Rec_Ent
: Entity_Id
;
8125 Acc_Ent
: Entity_Id
;
8128 Formal
:= First_Formal
(Entry_Ent
);
8131 -- Most processing is done only if parameters are present
8133 if Present
(Formal
) then
8134 Components
:= New_List
;
8136 -- Loop through formals
8138 while Present
(Formal
) loop
8139 Set_Is_Entry_Formal
(Formal
);
8141 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8142 Set_Entry_Component
(Formal
, Component
);
8143 Set_Entry_Formal
(Component
, Formal
);
8144 Ftype
:= Etype
(Formal
);
8146 -- Declare new access type and then append
8148 Ctype
:= Make_Temporary
(Loc
, 'A');
8151 Make_Full_Type_Declaration
(Loc
,
8152 Defining_Identifier
=> Ctype
,
8154 Make_Access_To_Object_Definition
(Loc
,
8155 All_Present
=> True,
8156 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8157 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
8159 Insert_After
(Last_Decl
, Decl
);
8162 Append_To
(Components
,
8163 Make_Component_Declaration
(Loc
,
8164 Defining_Identifier
=> Component
,
8165 Component_Definition
=>
8166 Make_Component_Definition
(Loc
,
8167 Aliased_Present
=> False,
8168 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
8170 Next_Formal_With_Extras
(Formal
);
8173 -- Create the Entry_Parameter_Record declaration
8175 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8178 Make_Full_Type_Declaration
(Loc
,
8179 Defining_Identifier
=> Rec_Ent
,
8181 Make_Record_Definition
(Loc
,
8183 Make_Component_List
(Loc
,
8184 Component_Items
=> Components
)));
8186 Insert_After
(Last_Decl
, Decl
);
8189 -- Construct and link in the corresponding access type
8191 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8193 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8196 Make_Full_Type_Declaration
(Loc
,
8197 Defining_Identifier
=> Acc_Ent
,
8199 Make_Access_To_Object_Definition
(Loc
,
8200 All_Present
=> True,
8201 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
8203 Insert_After
(Last_Decl
, Decl
);
8205 end Expand_N_Entry_Declaration
;
8207 -----------------------------
8208 -- Expand_N_Protected_Body --
8209 -----------------------------
8211 -- Protected bodies are expanded to the completion of the subprograms
8212 -- created for the corresponding protected type. These are a protected and
8213 -- unprotected version of each protected subprogram in the object, a
8214 -- function to calculate each entry barrier, and a procedure to execute the
8215 -- sequence of statements of each protected entry body. For example, for
8216 -- protected type ptype:
8219 -- (O : System.Address;
8220 -- E : Protected_Entry_Index)
8223 -- <discriminant renamings>
8224 -- <private object renamings>
8226 -- return <barrier expression>;
8229 -- procedure pprocN (_object : in out poV;...) is
8230 -- <discriminant renamings>
8231 -- <private object renamings>
8233 -- <sequence of statements>
8236 -- procedure pprocP (_object : in out poV;...) is
8237 -- procedure _clean is
8240 -- ptypeS (_object, Pn);
8241 -- Unlock (_object._object'Access);
8242 -- Abort_Undefer.all;
8247 -- Lock (_object._object'Access);
8248 -- pprocN (_object;...);
8253 -- function pfuncN (_object : poV;...) return Return_Type is
8254 -- <discriminant renamings>
8255 -- <private object renamings>
8257 -- <sequence of statements>
8260 -- function pfuncP (_object : poV) return Return_Type is
8261 -- procedure _clean is
8263 -- Unlock (_object._object'Access);
8264 -- Abort_Undefer.all;
8269 -- Lock (_object._object'Access);
8270 -- return pfuncN (_object);
8277 -- (O : System.Address;
8278 -- P : System.Address;
8279 -- E : Protected_Entry_Index)
8281 -- <discriminant renamings>
8282 -- <private object renamings>
8283 -- type poVP is access poV;
8284 -- _Object : ptVP := ptVP!(O);
8288 -- <statement sequence>
8289 -- Complete_Entry_Body (_Object._Object);
8291 -- when all others =>
8292 -- Exceptional_Complete_Entry_Body (
8293 -- _Object._Object, Get_GNAT_Exception);
8297 -- The type poV is the record created for the protected type to hold
8298 -- the state of the protected object.
8300 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8301 Loc
: constant Source_Ptr
:= Sloc
(N
);
8302 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8304 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8305 -- This flag indicates whether the lock free implementation is active
8307 Current_Node
: Node_Id
;
8308 Disp_Op_Body
: Node_Id
;
8309 New_Op_Body
: Node_Id
;
8310 Num_Entries
: Natural := 0;
8314 function Build_Dispatching_Subprogram_Body
8317 Prot_Bod
: Node_Id
) return Node_Id
;
8318 -- Build a dispatching version of the protected subprogram body. The
8319 -- newly generated subprogram contains a call to the original protected
8320 -- body. The following code is generated:
8322 -- function <protected-function-name> (Param1 .. ParamN) return
8325 -- return <protected-function-name>P (Param1 .. ParamN);
8326 -- end <protected-function-name>;
8330 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8332 -- <protected-procedure-name>P (Param1 .. ParamN);
8333 -- end <protected-procedure-name>
8335 ---------------------------------------
8336 -- Build_Dispatching_Subprogram_Body --
8337 ---------------------------------------
8339 function Build_Dispatching_Subprogram_Body
8342 Prot_Bod
: Node_Id
) return Node_Id
8344 Loc
: constant Source_Ptr
:= Sloc
(N
);
8351 -- Generate a specification without a letter suffix in order to
8352 -- override an interface function or procedure.
8354 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8356 -- The formal parameters become the actuals of the protected function
8357 -- or procedure call.
8359 Actuals
:= New_List
;
8360 Formal
:= First
(Parameter_Specifications
(Spec
));
8361 while Present
(Formal
) loop
8363 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8367 if Nkind
(Spec
) = N_Procedure_Specification
then
8370 Make_Procedure_Call_Statement
(Loc
,
8372 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8373 Parameter_Associations
=> Actuals
));
8376 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8380 Make_Simple_Return_Statement
(Loc
,
8382 Make_Function_Call
(Loc
,
8384 New_Reference_To
(Corresponding_Spec
(Prot_Bod
), Loc
),
8385 Parameter_Associations
=> Actuals
)));
8389 Make_Subprogram_Body
(Loc
,
8390 Declarations
=> Empty_List
,
8391 Specification
=> Spec
,
8392 Handled_Statement_Sequence
=>
8393 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8394 end Build_Dispatching_Subprogram_Body
;
8396 -- Start of processing for Expand_N_Protected_Body
8399 if No_Run_Time_Mode
then
8400 Error_Msg_CRT
("protected body", N
);
8404 -- This is the proper body corresponding to a stub. The declarations
8405 -- must be inserted at the point of the stub, which in turn is in the
8406 -- declarative part of the parent unit.
8408 if Nkind
(Parent
(N
)) = N_Subunit
then
8409 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8414 Op_Body
:= First
(Declarations
(N
));
8416 -- The protected body is replaced with the bodies of its
8417 -- protected operations, and the declarations for internal objects
8418 -- that may have been created for entry family bounds.
8420 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8423 while Present
(Op_Body
) loop
8424 case Nkind
(Op_Body
) is
8425 when N_Subprogram_Declaration
=>
8428 when N_Subprogram_Body
=>
8430 -- Do not create bodies for eliminated operations
8432 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8433 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
8435 if Lock_Free_Active
then
8437 Build_Lock_Free_Unprotected_Subprogram_Body
8441 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8444 Insert_After
(Current_Node
, New_Op_Body
);
8445 Current_Node
:= New_Op_Body
;
8446 Analyze
(New_Op_Body
);
8448 -- Build the corresponding protected operation. It may
8449 -- appear that this is needed only if this is a visible
8450 -- operation of the type, or if it is an interrupt handler,
8451 -- and this was the strategy used previously in GNAT.
8453 -- However, the operation may be exported through a 'Access
8454 -- to an external caller. This is the common idiom in code
8455 -- that uses the Ada 2005 Timing_Events package. As a result
8456 -- we need to produce the protected body for both visible
8457 -- and private operations, as well as operations that only
8458 -- have a body in the source, and for which we create a
8459 -- declaration in the protected body itself.
8461 if Present
(Corresponding_Spec
(Op_Body
)) then
8462 if Lock_Free_Active
then
8464 Build_Lock_Free_Protected_Subprogram_Body
8465 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8468 Build_Protected_Subprogram_Body
8469 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8472 Insert_After
(Current_Node
, New_Op_Body
);
8473 Analyze
(New_Op_Body
);
8475 Current_Node
:= New_Op_Body
;
8477 -- Generate an overriding primitive operation body for
8478 -- this subprogram if the protected type implements an
8481 if Ada_Version
>= Ada_2005
8483 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8486 Build_Dispatching_Subprogram_Body
8487 (Op_Body
, Pid
, New_Op_Body
);
8489 Insert_After
(Current_Node
, Disp_Op_Body
);
8490 Analyze
(Disp_Op_Body
);
8492 Current_Node
:= Disp_Op_Body
;
8497 when N_Entry_Body
=>
8498 Op_Id
:= Defining_Identifier
(Op_Body
);
8499 Num_Entries
:= Num_Entries
+ 1;
8501 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8503 Insert_After
(Current_Node
, New_Op_Body
);
8504 Current_Node
:= New_Op_Body
;
8505 Analyze
(New_Op_Body
);
8507 when N_Implicit_Label_Declaration
=>
8510 when N_Itype_Reference
=>
8511 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
8513 when N_Freeze_Entity
=>
8514 New_Op_Body
:= New_Copy
(Op_Body
);
8516 if Present
(Entity
(Op_Body
))
8517 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8519 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8522 Insert_After
(Current_Node
, New_Op_Body
);
8523 Current_Node
:= New_Op_Body
;
8524 Analyze
(New_Op_Body
);
8527 New_Op_Body
:= New_Copy
(Op_Body
);
8528 Insert_After
(Current_Node
, New_Op_Body
);
8529 Current_Node
:= New_Op_Body
;
8530 Analyze
(New_Op_Body
);
8532 when N_Object_Declaration
=>
8533 pragma Assert
(not Comes_From_Source
(Op_Body
));
8534 New_Op_Body
:= New_Copy
(Op_Body
);
8535 Insert_After
(Current_Node
, New_Op_Body
);
8536 Current_Node
:= New_Op_Body
;
8537 Analyze
(New_Op_Body
);
8540 raise Program_Error
;
8547 -- Finally, create the body of the function that maps an entry index
8548 -- into the corresponding body index, except when there is no entry, or
8549 -- in a Ravenscar-like profile.
8551 if Corresponding_Runtime_Package
(Pid
) =
8552 System_Tasking_Protected_Objects_Entries
8554 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8555 Insert_After
(Current_Node
, New_Op_Body
);
8556 Current_Node
:= New_Op_Body
;
8557 Analyze
(New_Op_Body
);
8560 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8561 -- protected body. At this point all wrapper specs have been created,
8562 -- frozen and included in the dispatch table for the protected type.
8564 if Ada_Version
>= Ada_2005
then
8565 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8567 end Expand_N_Protected_Body
;
8569 -----------------------------------------
8570 -- Expand_N_Protected_Type_Declaration --
8571 -----------------------------------------
8573 -- First we create a corresponding record type declaration used to
8574 -- represent values of this protected type.
8575 -- The general form of this type declaration is
8577 -- type poV (discriminants) is record
8578 -- _Object : aliased <kind>Protection
8579 -- [(<entry count> [, <handler count>])];
8580 -- [entry_family : array (bounds) of Void;]
8581 -- <private data fields>
8584 -- The discriminants are present only if the corresponding protected type
8585 -- has discriminants, and they exactly mirror the protected type
8586 -- discriminants. The private data fields similarly mirror the private
8587 -- declarations of the protected type.
8589 -- The Object field is always present. It contains RTS specific data used
8590 -- to control the protected object. It is declared as Aliased so that it
8591 -- can be passed as a pointer to the RTS. This allows the protected record
8592 -- to be referenced within RTS data structures. An appropriate Protection
8593 -- type and discriminant are generated.
8595 -- The Service field is present for protected objects with entries. It
8596 -- contains sufficient information to allow the entry service procedure for
8597 -- this object to be called when the object is not known till runtime.
8599 -- One entry_family component is present for each entry family in the
8600 -- task definition (see Expand_N_Task_Type_Declaration).
8602 -- When a protected object is declared, an instance of the protected type
8603 -- value record is created. The elaboration of this declaration creates the
8604 -- correct bounds for the entry families, and also evaluates the priority
8605 -- expression if needed. The initialization routine for the protected type
8606 -- itself then calls Initialize_Protection with appropriate parameters to
8607 -- initialize the value of the Task_Id field. Install_Handlers may be also
8608 -- called if a pragma Attach_Handler applies.
8610 -- Note: this record is passed to the subprograms created by the expansion
8611 -- of protected subprograms and entries. It is an in parameter to protected
8612 -- functions and an in out parameter to procedures and entry bodies. The
8613 -- Entity_Id for this created record type is placed in the
8614 -- Corresponding_Record_Type field of the associated protected type entity.
8616 -- Next we create a procedure specifications for protected subprograms and
8617 -- entry bodies. For each protected subprograms two subprograms are
8618 -- created, an unprotected and a protected version. The unprotected version
8619 -- is called from within other operations of the same protected object.
8621 -- We also build the call to register the procedure if a pragma
8622 -- Interrupt_Handler applies.
8624 -- A single subprogram is created to service all entry bodies; it has an
8625 -- additional boolean out parameter indicating that the previous entry call
8626 -- made by the current task was serviced immediately, i.e. not by proxy.
8627 -- The O parameter contains a pointer to a record object of the type
8628 -- described above. An untyped interface is used here to allow this
8629 -- procedure to be called in places where the type of the object to be
8630 -- serviced is not known. This must be done, for example, when a call that
8631 -- may have been requeued is cancelled; the corresponding object must be
8632 -- serviced, but which object that is not known till runtime.
8635 -- (O : System.Address; P : out Boolean);
8636 -- procedure pprocN (_object : in out poV);
8637 -- procedure pproc (_object : in out poV);
8638 -- function pfuncN (_object : poV);
8639 -- function pfunc (_object : poV);
8642 -- Note that this must come after the record type declaration, since
8643 -- the specs refer to this type.
8645 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8646 Loc
: constant Source_Ptr
:= Sloc
(N
);
8647 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8649 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8650 -- This flag indicates whether the lock free implementation is active
8652 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8653 -- This contains two lists; one for visible and one for private decls
8657 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8661 Comp_Id
: Entity_Id
;
8663 Current_Node
: Node_Id
:= N
;
8664 Bdef
: Entity_Id
:= Empty
; -- avoid uninit warning
8665 Edef
: Entity_Id
:= Empty
; -- avoid uninit warning
8666 Entries_Aggr
: Node_Id
;
8667 Body_Id
: Entity_Id
;
8670 Object_Comp
: Node_Id
;
8672 procedure Check_Inlining
(Subp
: Entity_Id
);
8673 -- If the original operation has a pragma Inline, propagate the flag
8674 -- to the internal body, for possible inlining later on. The source
8675 -- operation is invisible to the back-end and is never actually called.
8677 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8678 -- When compiling under the Ravenscar profile, private components must
8679 -- have a static size, or else a protected object will require heap
8680 -- allocation, violating the corresponding restriction. It is preferable
8681 -- to make this check here, because it provides a better error message
8682 -- than the back-end, which refers to the object as a whole.
8684 procedure Register_Handler
;
8685 -- For a protected operation that is an interrupt handler, add the
8686 -- freeze action that will register it as such.
8688 --------------------
8689 -- Check_Inlining --
8690 --------------------
8692 procedure Check_Inlining
(Subp
: Entity_Id
) is
8694 if Is_Inlined
(Subp
) then
8695 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8696 Set_Is_Inlined
(Subp
, False);
8700 ---------------------------------
8701 -- Check_Static_Component_Size --
8702 ---------------------------------
8704 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8705 Typ
: constant Entity_Id
:= Etype
(Comp
);
8709 if Is_Scalar_Type
(Typ
) then
8712 elsif Is_Array_Type
(Typ
) then
8713 return Compile_Time_Known_Bounds
(Typ
);
8715 elsif Is_Record_Type
(Typ
) then
8716 C
:= First_Component
(Typ
);
8717 while Present
(C
) loop
8718 if not Static_Component_Size
(C
) then
8727 -- Any other type will be checked by the back-end
8732 end Static_Component_Size
;
8734 ----------------------
8735 -- Register_Handler --
8736 ----------------------
8738 procedure Register_Handler
is
8740 -- All semantic checks already done in Sem_Prag
8742 Prot_Proc
: constant Entity_Id
:=
8743 Defining_Unit_Name
(Specification
(Current_Node
));
8745 Proc_Address
: constant Node_Id
:=
8746 Make_Attribute_Reference
(Loc
,
8748 New_Reference_To
(Prot_Proc
, Loc
),
8749 Attribute_Name
=> Name_Address
);
8751 RTS_Call
: constant Entity_Id
:=
8752 Make_Procedure_Call_Statement
(Loc
,
8755 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8756 Parameter_Associations
=> New_List
(Proc_Address
));
8758 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8759 end Register_Handler
;
8761 -- Start of processing for Expand_N_Protected_Type_Declaration
8764 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
8767 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
8770 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
8772 Qualify_Entity_Names
(N
);
8774 -- If the type has discriminants, their occurrences in the declaration
8775 -- have been replaced by the corresponding discriminals. For components
8776 -- that are constrained by discriminants, their homologues in the
8777 -- corresponding record type must refer to the discriminants of that
8778 -- record, so we must apply a new renaming to subtypes_indications:
8780 -- protected discriminant => discriminal => record discriminant
8782 -- This replacement is not applied to default expressions, for which
8783 -- the discriminal is correct.
8785 if Has_Discriminants
(Prot_Typ
) then
8791 Disc
:= First_Discriminant
(Prot_Typ
);
8792 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
8793 while Present
(Disc
) loop
8794 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
8795 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
8796 Next_Discriminant
(Disc
);
8802 -- Fill in the component declarations
8804 -- Add components for entry families. For each entry family, create an
8805 -- anonymous type declaration with the same size, and analyze the type.
8807 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
8809 pragma Assert
(Present
(Pdef
));
8811 -- Add private field components
8813 if Present
(Private_Declarations
(Pdef
)) then
8814 Priv
:= First
(Private_Declarations
(Pdef
));
8815 while Present
(Priv
) loop
8816 if Nkind
(Priv
) = N_Component_Declaration
then
8817 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
8819 -- When compiling for a restricted profile, the private
8820 -- components must have a static size. If not, this is an
8821 -- error for a single protected declaration, and rates a
8822 -- warning on a protected type declaration.
8824 if not Comes_From_Source
(Prot_Typ
) then
8825 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
8827 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
8828 Error_Msg_N
("component has non-static size??", Priv
);
8830 ("\creation of protected object of type& will violate"
8831 & " restriction No_Implicit_Heap_Allocations??",
8836 -- The component definition consists of a subtype indication,
8837 -- or (in Ada 2005) an access definition. Make a copy of the
8838 -- proper definition.
8841 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
8842 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
8844 Nent
: constant Entity_Id
:=
8845 Make_Defining_Identifier
(Sloc
(Oent
),
8846 Chars
=> Chars
(Oent
));
8849 if Present
(Subtype_Indication
(Old_Comp
)) then
8851 Make_Component_Definition
(Sloc
(Oent
),
8852 Aliased_Present
=> False,
8853 Subtype_Indication
=>
8854 New_Copy_Tree
(Subtype_Indication
(Old_Comp
),
8858 Make_Component_Definition
(Sloc
(Oent
),
8859 Aliased_Present
=> False,
8860 Access_Definition
=>
8861 New_Copy_Tree
(Access_Definition
(Old_Comp
),
8866 Make_Component_Declaration
(Loc
,
8867 Defining_Identifier
=> Nent
,
8868 Component_Definition
=> New_Comp
,
8869 Expression
=> Expression
(Priv
));
8871 Set_Has_Per_Object_Constraint
(Nent
,
8872 Has_Per_Object_Constraint
(Oent
));
8874 Append_To
(Cdecls
, New_Priv
);
8877 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
8879 -- Make the unprotected version of the subprogram available
8880 -- for expansion of intra object calls. There is need for
8881 -- a protected version only if the subprogram is an interrupt
8882 -- handler, otherwise this operation can only be called from
8886 Make_Subprogram_Declaration
(Loc
,
8888 Build_Protected_Sub_Specification
8889 (Priv
, Prot_Typ
, Unprotected_Mode
));
8891 Insert_After
(Current_Node
, Sub
);
8894 Set_Protected_Body_Subprogram
8895 (Defining_Unit_Name
(Specification
(Priv
)),
8896 Defining_Unit_Name
(Specification
(Sub
)));
8897 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
8898 Current_Node
:= Sub
;
8901 Make_Subprogram_Declaration
(Loc
,
8903 Build_Protected_Sub_Specification
8904 (Priv
, Prot_Typ
, Protected_Mode
));
8906 Insert_After
(Current_Node
, Sub
);
8908 Current_Node
:= Sub
;
8910 if Is_Interrupt_Handler
8911 (Defining_Unit_Name
(Specification
(Priv
)))
8913 if not Restricted_Profile
then
8923 -- Except for the lock-free implementation, prepend the _Object field
8924 -- with the right type to the component list. We need to compute the
8925 -- number of entries, and in some cases the number of Attach_Handler
8928 if not Lock_Free_Active
then
8931 Num_Attach_Handler
: Int
:= 0;
8932 Protection_Subtype
: Node_Id
;
8933 Entry_Count_Expr
: constant Node_Id
:=
8934 Build_Entry_Count_Expression
8935 (Prot_Typ
, Cdecls
, Loc
);
8938 -- Could this be simplified using Corresponding_Runtime_Package???
8940 if Has_Attach_Handler
(Prot_Typ
) then
8941 Ritem
:= First_Rep_Item
(Prot_Typ
);
8942 while Present
(Ritem
) loop
8943 if Nkind
(Ritem
) = N_Pragma
8944 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
8946 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
8949 Next_Rep_Item
(Ritem
);
8952 if Restricted_Profile
then
8953 if Has_Entries
(Prot_Typ
) then
8954 Protection_Subtype
:=
8955 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
8957 Protection_Subtype
:=
8958 New_Reference_To
(RTE
(RE_Protection
), Loc
);
8962 Protection_Subtype
:=
8963 Make_Subtype_Indication
(Loc
,
8966 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
8968 Make_Index_Or_Discriminant_Constraint
(Loc
,
8969 Constraints
=> New_List
(
8971 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
8974 elsif Has_Interrupt_Handler
(Prot_Typ
)
8975 and then not Restriction_Active
(No_Dynamic_Attachment
)
8977 Protection_Subtype
:=
8978 Make_Subtype_Indication
(Loc
,
8981 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
8983 Make_Index_Or_Discriminant_Constraint
(Loc
,
8984 Constraints
=> New_List
(Entry_Count_Expr
)));
8986 -- Type has explicit entries or generated primitive entry wrappers
8988 elsif Has_Entries
(Prot_Typ
)
8989 or else (Ada_Version
>= Ada_2005
8990 and then Present
(Interface_List
(N
)))
8992 case Corresponding_Runtime_Package
(Prot_Typ
) is
8993 when System_Tasking_Protected_Objects_Entries
=>
8994 Protection_Subtype
:=
8995 Make_Subtype_Indication
(Loc
,
8998 (RTE
(RE_Protection_Entries
), Loc
),
9000 Make_Index_Or_Discriminant_Constraint
(Loc
,
9001 Constraints
=> New_List
(Entry_Count_Expr
)));
9003 when System_Tasking_Protected_Objects_Single_Entry
=>
9004 Protection_Subtype
:=
9005 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
9008 raise Program_Error
;
9012 Protection_Subtype
:=
9013 New_Reference_To
(RTE
(RE_Protection
), Loc
);
9017 Make_Component_Declaration
(Loc
,
9018 Defining_Identifier
=>
9019 Make_Defining_Identifier
(Loc
, Name_uObject
),
9020 Component_Definition
=>
9021 Make_Component_Definition
(Loc
,
9022 Aliased_Present
=> True,
9023 Subtype_Indication
=> Protection_Subtype
));
9026 -- Put the _Object component after the private component so that it
9027 -- be finalized early as required by 9.4 (20)
9029 Append_To
(Cdecls
, Object_Comp
);
9032 Insert_After
(Current_Node
, Rec_Decl
);
9033 Current_Node
:= Rec_Decl
;
9035 -- Analyze the record declaration immediately after construction,
9036 -- because the initialization procedure is needed for single object
9037 -- declarations before the next entity is analyzed (the freeze call
9038 -- that generates this initialization procedure is found below).
9040 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9042 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9043 -- the corresponding record is frozen. If any wrappers are generated,
9044 -- Current_Node is updated accordingly.
9046 if Ada_Version
>= Ada_2005
then
9047 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9050 -- Collect pointers to entry bodies and their barriers, to be placed
9051 -- in the Entry_Bodies_Array for the type. For each entry/family we
9052 -- add an expression to the aggregate which is the initial value of
9053 -- this array. The array is declared after all protected subprograms.
9055 if Has_Entries
(Prot_Typ
) then
9056 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9058 Entries_Aggr
:= Empty
;
9061 -- Build two new procedure specifications for each protected subprogram;
9062 -- one to call from outside the object and one to call from inside.
9063 -- Build a barrier function and an entry body action procedure
9064 -- specification for each protected entry. Initialize the entry body
9065 -- array. If subprogram is flagged as eliminated, do not generate any
9066 -- internal operations.
9069 Comp
:= First
(Visible_Declarations
(Pdef
));
9070 while Present
(Comp
) loop
9071 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9073 Make_Subprogram_Declaration
(Loc
,
9075 Build_Protected_Sub_Specification
9076 (Comp
, Prot_Typ
, Unprotected_Mode
));
9078 Insert_After
(Current_Node
, Sub
);
9081 Set_Protected_Body_Subprogram
9082 (Defining_Unit_Name
(Specification
(Comp
)),
9083 Defining_Unit_Name
(Specification
(Sub
)));
9084 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9086 -- Make the protected version of the subprogram available for
9087 -- expansion of external calls.
9089 Current_Node
:= Sub
;
9092 Make_Subprogram_Declaration
(Loc
,
9094 Build_Protected_Sub_Specification
9095 (Comp
, Prot_Typ
, Protected_Mode
));
9097 Insert_After
(Current_Node
, Sub
);
9100 Current_Node
:= Sub
;
9102 -- Generate an overriding primitive operation specification for
9103 -- this subprogram if the protected type implements an interface.
9105 if Ada_Version
>= Ada_2005
9107 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9110 Make_Subprogram_Declaration
(Loc
,
9112 Build_Protected_Sub_Specification
9113 (Comp
, Prot_Typ
, Dispatching_Mode
));
9115 Insert_After
(Current_Node
, Sub
);
9118 Current_Node
:= Sub
;
9121 -- If a pragma Interrupt_Handler applies, build and add a call to
9122 -- Register_Interrupt_Handler to the freezing actions of the
9123 -- protected version (Current_Node) of the subprogram:
9125 -- system.interrupts.register_interrupt_handler
9126 -- (prot_procP'address);
9128 if not Restricted_Profile
9129 and then Is_Interrupt_Handler
9130 (Defining_Unit_Name
(Specification
(Comp
)))
9135 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9136 E_Count
:= E_Count
+ 1;
9137 Comp_Id
:= Defining_Identifier
(Comp
);
9140 Make_Defining_Identifier
(Loc
,
9141 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9143 Make_Subprogram_Declaration
(Loc
,
9145 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9147 Insert_After
(Current_Node
, Sub
);
9150 -- Build wrapper procedure for pre/postconditions
9152 Build_PPC_Wrapper
(Comp_Id
, N
);
9154 Set_Protected_Body_Subprogram
9155 (Defining_Identifier
(Comp
),
9156 Defining_Unit_Name
(Specification
(Sub
)));
9158 Current_Node
:= Sub
;
9161 Make_Defining_Identifier
(Loc
,
9162 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'B'));
9164 Make_Subprogram_Declaration
(Loc
,
9166 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9168 Insert_After
(Current_Node
, Sub
);
9170 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9171 Set_Barrier_Function
(Comp_Id
, Bdef
);
9172 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9173 Current_Node
:= Sub
;
9175 -- Collect pointers to the protected subprogram and the barrier
9176 -- of the current entry, for insertion into Entry_Bodies_Array.
9178 Append_To
(Expressions
(Entries_Aggr
),
9179 Make_Aggregate
(Loc
,
9180 Expressions
=> New_List
(
9181 Make_Attribute_Reference
(Loc
,
9182 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9183 Attribute_Name
=> Name_Unrestricted_Access
),
9184 Make_Attribute_Reference
(Loc
,
9185 Prefix
=> New_Reference_To
(Edef
, Loc
),
9186 Attribute_Name
=> Name_Unrestricted_Access
))));
9192 -- If there are some private entry declarations, expand it as if they
9193 -- were visible entries.
9195 if Present
(Private_Declarations
(Pdef
)) then
9196 Comp
:= First
(Private_Declarations
(Pdef
));
9197 while Present
(Comp
) loop
9198 if Nkind
(Comp
) = N_Entry_Declaration
then
9199 E_Count
:= E_Count
+ 1;
9200 Comp_Id
:= Defining_Identifier
(Comp
);
9203 Make_Defining_Identifier
(Loc
,
9204 Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9206 Make_Subprogram_Declaration
(Loc
,
9208 Build_Protected_Entry_Specification
(Loc
, Edef
, Comp_Id
));
9210 Insert_After
(Current_Node
, Sub
);
9213 Set_Protected_Body_Subprogram
9214 (Defining_Identifier
(Comp
),
9215 Defining_Unit_Name
(Specification
(Sub
)));
9217 Current_Node
:= Sub
;
9220 Make_Defining_Identifier
(Loc
,
9221 Chars
=> Build_Selected_Name
(Prot_Typ
, Comp_Id
, 'E'));
9224 Make_Subprogram_Declaration
(Loc
,
9226 Build_Barrier_Function_Specification
(Loc
, Bdef
));
9228 Insert_After
(Current_Node
, Sub
);
9230 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
9231 Set_Barrier_Function
(Comp_Id
, Bdef
);
9232 Set_Scope
(Bdef
, Scope
(Comp_Id
));
9233 Current_Node
:= Sub
;
9235 -- Collect pointers to the protected subprogram and the barrier
9236 -- of the current entry, for insertion into Entry_Bodies_Array.
9238 Append_To
(Expressions
(Entries_Aggr
),
9239 Make_Aggregate
(Loc
,
9240 Expressions
=> New_List
(
9241 Make_Attribute_Reference
(Loc
,
9242 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9243 Attribute_Name
=> Name_Unrestricted_Access
),
9244 Make_Attribute_Reference
(Loc
,
9245 Prefix
=> New_Reference_To
(Edef
, Loc
),
9246 Attribute_Name
=> Name_Unrestricted_Access
))));
9253 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9254 -- all protected subprograms have been collected.
9256 if Has_Entries
(Prot_Typ
) then
9258 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9259 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9261 case Corresponding_Runtime_Package
(Prot_Typ
) is
9262 when System_Tasking_Protected_Objects_Entries
=>
9263 Body_Arr
:= Make_Object_Declaration
(Loc
,
9264 Defining_Identifier
=> Body_Id
,
9265 Aliased_Present
=> True,
9266 Object_Definition
=>
9267 Make_Subtype_Indication
(Loc
,
9268 Subtype_Mark
=> New_Reference_To
(
9269 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9271 Make_Index_Or_Discriminant_Constraint
(Loc
,
9272 Constraints
=> New_List
(
9274 Make_Integer_Literal
(Loc
, 1),
9275 Make_Integer_Literal
(Loc
, E_Count
))))),
9276 Expression
=> Entries_Aggr
);
9278 when System_Tasking_Protected_Objects_Single_Entry
=>
9279 Body_Arr
:= Make_Object_Declaration
(Loc
,
9280 Defining_Identifier
=> Body_Id
,
9281 Aliased_Present
=> True,
9282 Object_Definition
=> New_Reference_To
9283 (RTE
(RE_Entry_Body
), Loc
),
9285 Make_Aggregate
(Loc
,
9286 Expressions
=> New_List
(
9287 Make_Attribute_Reference
(Loc
,
9288 Prefix
=> New_Reference_To
(Bdef
, Loc
),
9289 Attribute_Name
=> Name_Unrestricted_Access
),
9290 Make_Attribute_Reference
(Loc
,
9291 Prefix
=> New_Reference_To
(Edef
, Loc
),
9292 Attribute_Name
=> Name_Unrestricted_Access
))));
9295 raise Program_Error
;
9298 -- A pointer to this array will be placed in the corresponding record
9299 -- by its initialization procedure so this needs to be analyzed here.
9301 Insert_After
(Current_Node
, Body_Arr
);
9302 Current_Node
:= Body_Arr
;
9305 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9307 -- Finally, build the function that maps an entry index into the
9308 -- corresponding body. A pointer to this function is placed in each
9309 -- object of the type. Except for a ravenscar-like profile (no abort,
9310 -- no entry queue, 1 entry)
9312 if Corresponding_Runtime_Package
(Prot_Typ
) =
9313 System_Tasking_Protected_Objects_Entries
9316 Make_Subprogram_Declaration
(Loc
,
9317 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9318 Insert_After
(Current_Node
, Sub
);
9322 end Expand_N_Protected_Type_Declaration
;
9324 --------------------------------
9325 -- Expand_N_Requeue_Statement --
9326 --------------------------------
9328 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9329 -- operations, depending on the source and destination (task or protected
9330 -- object). A dispatching requeue statement is expanded into a call to the
9331 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9332 -- jump around the remainder of processing for the original entry and, if
9333 -- the destination is (different) protected object, to attempt to service
9334 -- it. The following illustrates the various cases:
9337 -- (O : System.Address;
9338 -- P : System.Address;
9339 -- E : Protected_Entry_Index)
9341 -- <discriminant renamings>
9342 -- <private object renamings>
9343 -- type poVP is access poV;
9344 -- _object : ptVP := ptVP!(O);
9348 -- <start of statement sequence for entry>
9350 -- -- Requeue from one protected entry body to another protected
9353 -- Requeue_Protected_Entry (
9354 -- _object._object'Access,
9355 -- new._object'Access,
9360 -- <some more of the statement sequence for entry>
9362 -- -- Requeue from an entry body to a task entry
9364 -- Requeue_Protected_To_Task_Entry (
9370 -- <rest of statement sequence for entry>
9371 -- Complete_Entry_Body (_object._object);
9374 -- when all others =>
9375 -- Exceptional_Complete_Entry_Body (
9376 -- _object._object, Get_GNAT_Exception);
9380 -- Requeue of a task entry call to a task entry
9382 -- Accept_Call (E, Ann);
9383 -- <start of statement sequence for accept statement>
9384 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9386 -- <rest of statement sequence for accept statement>
9388 -- Complete_Rendezvous;
9391 -- when all others =>
9392 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9394 -- Requeue of a task entry call to a protected entry
9396 -- Accept_Call (E, Ann);
9397 -- <start of statement sequence for accept statement>
9398 -- Requeue_Task_To_Protected_Entry (
9399 -- new._object'Access,
9404 -- <rest of statement sequence for accept statement>
9406 -- Complete_Rendezvous;
9409 -- when all others =>
9410 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9412 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9413 -- marked by pragma Implemented (XXX, By_Entry).
9415 -- The requeue is inside a protected entry:
9418 -- (O : System.Address;
9419 -- P : System.Address;
9420 -- E : Protected_Entry_Index)
9422 -- <discriminant renamings>
9423 -- <private object renamings>
9424 -- type poVP is access poV;
9425 -- _object : ptVP := ptVP!(O);
9429 -- <start of statement sequence for entry>
9432 -- (<interface class-wide object>,
9435 -- Ada.Tags.Get_Offset_Index
9437 -- <interface dispatch table index of target entry>),
9441 -- <rest of statement sequence for entry>
9442 -- Complete_Entry_Body (_object._object);
9445 -- when all others =>
9446 -- Exceptional_Complete_Entry_Body (
9447 -- _object._object, Get_GNAT_Exception);
9451 -- The requeue is inside a task entry:
9453 -- Accept_Call (E, Ann);
9454 -- <start of statement sequence for accept statement>
9456 -- (<interface class-wide object>,
9459 -- Ada.Tags.Get_Offset_Index
9461 -- <interface dispatch table index of target entrt>),
9465 -- <rest of statement sequence for accept statement>
9467 -- Complete_Rendezvous;
9470 -- when all others =>
9471 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9473 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9474 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9475 -- statement is replaced by a dispatching call with actual parameters taken
9476 -- from the inner-most accept statement or entry body.
9478 -- Target.Primitive (Param1, ..., ParamN);
9480 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9481 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9485 -- S : constant Offset_Index :=
9486 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9487 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9490 -- if C = POK_Protected_Entry
9491 -- or else C = POK_Task_Entry
9493 -- <statements for dispatching requeue>
9495 -- elsif C = POK_Protected_Procedure then
9496 -- <dispatching call equivalent>
9499 -- raise Program_Error;
9503 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9504 Loc
: constant Source_Ptr
:= Sloc
(N
);
9505 Conc_Typ
: Entity_Id
;
9509 Old_Typ
: Entity_Id
;
9511 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9512 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9513 -- the form Concval.Ename. It is statically known that Ename is allowed
9514 -- to be implemented by a protected procedure. Create a dispatching call
9515 -- equivalent of Concval.Ename taking the actual parameters from the
9516 -- inner-most accept statement or entry body.
9518 function Build_Dispatching_Requeue
return Node_Id
;
9519 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9520 -- the form Concval.Ename. It is statically known that Ename is allowed
9521 -- to be implemented by a protected or a task entry. Create a call to
9522 -- primitive _Disp_Requeue which handles the low-level actions.
9524 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9525 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9526 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9527 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9528 -- determines at runtime whether Ename denotes an entry or a procedure
9529 -- and perform the appropriate kind of dispatching select.
9531 function Build_Normal_Requeue
return Node_Id
;
9532 -- N denotes a non-dispatching requeue statement to either a task or a
9533 -- protected entry. Build the appropriate runtime call to perform the
9536 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9537 -- For a protected entry, create a return statement to skip the rest of
9538 -- the entry body. Otherwise, create a goto statement to skip the rest
9539 -- of a task accept statement. The lookup for the enclosing entry body
9540 -- or accept statement starts from Search.
9542 ---------------------------------------
9543 -- Build_Dispatching_Call_Equivalent --
9544 ---------------------------------------
9546 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9547 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9548 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9555 -- Climb the parent chain looking for the inner-most entry body or
9556 -- accept statement.
9559 while Present
(Acc_Ent
)
9560 and then not Nkind_In
(Acc_Ent
, N_Accept_Statement
,
9563 Acc_Ent
:= Parent
(Acc_Ent
);
9566 -- A requeue statement should be housed inside an entry body or an
9567 -- accept statement at some level. If this is not the case, then the
9568 -- tree is malformed.
9570 pragma Assert
(Present
(Acc_Ent
));
9572 -- Recover the list of formal parameters
9574 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9575 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9578 Formals
:= Parameter_Specifications
(Acc_Ent
);
9580 -- Create the actual parameters for the dispatching call. These are
9581 -- simply copies of the entry body or accept statement formals in the
9582 -- same order as they appear.
9586 if Present
(Formals
) then
9587 Actuals
:= New_List
;
9588 Formal
:= First
(Formals
);
9589 while Present
(Formal
) loop
9591 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9597 -- Obj.Call_Ent (Actuals);
9600 Make_Procedure_Call_Statement
(Loc
,
9602 Make_Selected_Component
(Loc
,
9603 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9604 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9606 Parameter_Associations
=> Actuals
);
9607 end Build_Dispatching_Call_Equivalent
;
9609 -------------------------------
9610 -- Build_Dispatching_Requeue --
9611 -------------------------------
9613 function Build_Dispatching_Requeue
return Node_Id
is
9614 Params
: constant List_Id
:= New_List
;
9617 -- Process the "with abort" parameter
9620 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9622 -- Process the entry wrapper's position in the primary dispatch
9623 -- table parameter. Generate:
9625 -- Ada.Tags.Get_Entry_Index
9626 -- (T => To_Tag_Ptr (Obj'Address).all,
9628 -- Ada.Tags.Get_Offset_Index
9629 -- (Ada.Tags.Tag (Concval),
9630 -- <interface dispatch table position of Ename>));
9632 -- Note that Obj'Address is recursively expanded into a call to
9633 -- Base_Address (Obj).
9635 if Tagged_Type_Expansion
then
9637 Make_Function_Call
(Loc
,
9638 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9639 Parameter_Associations
=> New_List
(
9641 Make_Explicit_Dereference
(Loc
,
9642 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9643 Make_Attribute_Reference
(Loc
,
9644 Prefix
=> New_Copy_Tree
(Concval
),
9645 Attribute_Name
=> Name_Address
))),
9647 Make_Function_Call
(Loc
,
9648 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9649 Parameter_Associations
=> New_List
(
9650 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9651 Make_Integer_Literal
(Loc
,
9652 DT_Position
(Entity
(Ename
))))))));
9658 Make_Function_Call
(Loc
,
9659 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
9660 Parameter_Associations
=> New_List
(
9662 Make_Attribute_Reference
(Loc
,
9664 Attribute_Name
=> Name_Tag
),
9666 Make_Function_Call
(Loc
,
9667 Name
=> New_Reference_To
(RTE
(RE_Get_Offset_Index
), Loc
),
9669 Parameter_Associations
=> New_List
(
9673 Make_Attribute_Reference
(Loc
,
9675 Attribute_Name
=> Name_Tag
),
9679 Make_Attribute_Reference
(Loc
,
9680 Prefix
=> New_Reference_To
(Etype
(Concval
), Loc
),
9681 Attribute_Name
=> Name_Tag
),
9685 Make_Integer_Literal
(Loc
,
9686 DT_Position
(Entity
(Ename
))))))));
9689 -- Specific actuals for protected to XXX requeue
9691 if Is_Protected_Type
(Old_Typ
) then
9693 Make_Attribute_Reference
(Loc
, -- _object'Address
9695 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9696 Attribute_Name
=> Name_Address
));
9698 Prepend_To
(Params
, -- True
9699 New_Reference_To
(Standard_True
, Loc
));
9701 -- Specific actuals for task to XXX requeue
9704 pragma Assert
(Is_Task_Type
(Old_Typ
));
9706 Prepend_To
(Params
, -- null
9707 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
9709 Prepend_To
(Params
, -- False
9710 New_Reference_To
(Standard_False
, Loc
));
9713 -- Add the object parameter
9715 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
9718 -- _Disp_Requeue (<Params>);
9720 -- Find entity for Disp_Requeue operation, which belongs to
9721 -- the type and may not be directly visible.
9728 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
9729 while Present
(Elmt
) loop
9731 exit when Chars
(Op
) = Name_uDisp_Requeue
;
9736 Make_Procedure_Call_Statement
(Loc
,
9737 Name
=> New_Occurrence_Of
(Op
, Loc
),
9738 Parameter_Associations
=> Params
);
9740 end Build_Dispatching_Requeue
;
9742 --------------------------------------
9743 -- Build_Dispatching_Requeue_To_Any --
9744 --------------------------------------
9746 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
9747 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9748 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9749 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
9759 -- Dispatch table slot processing, generate:
9762 S
:= Build_S
(Loc
, Decls
);
9764 -- Call kind processing, generate:
9765 -- C : Ada.Tags.Prim_Op_Kind;
9767 C
:= Build_C
(Loc
, Decls
);
9770 -- S := Ada.Tags.Get_Offset_Index
9771 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9773 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
9776 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9779 Make_Procedure_Call_Statement
(Loc
,
9782 Find_Prim_Op
(Etype
(Etype
(Obj
)),
9783 Name_uDisp_Get_Prim_Op_Kind
),
9785 Parameter_Associations
=> New_List
(
9786 New_Copy_Tree
(Obj
),
9787 New_Reference_To
(S
, Loc
),
9788 New_Reference_To
(C
, Loc
))));
9792 -- if C = POK_Protected_Entry
9793 -- or else C = POK_Task_Entry
9796 Make_Implicit_If_Statement
(N
,
9802 New_Reference_To
(C
, Loc
),
9804 New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
)),
9809 New_Reference_To
(C
, Loc
),
9811 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
9813 -- Dispatching requeue equivalent
9815 Then_Statements
=> New_List
(
9816 Build_Dispatching_Requeue
,
9819 -- elsif C = POK_Protected_Procedure then
9821 Elsif_Parts
=> New_List
(
9822 Make_Elsif_Part
(Loc
,
9826 New_Reference_To
(C
, Loc
),
9829 RTE
(RE_POK_Protected_Procedure
), Loc
)),
9831 -- Dispatching call equivalent
9833 Then_Statements
=> New_List
(
9834 Build_Dispatching_Call_Equivalent
))),
9837 -- raise Program_Error;
9840 Else_Statements
=> New_List
(
9841 Make_Raise_Program_Error
(Loc
,
9842 Reason
=> PE_Explicit_Raise
))));
9844 -- Wrap everything into a block
9847 Make_Block_Statement
(Loc
,
9848 Declarations
=> Decls
,
9849 Handled_Statement_Sequence
=>
9850 Make_Handled_Sequence_Of_Statements
(Loc
,
9851 Statements
=> Stmts
));
9852 end Build_Dispatching_Requeue_To_Any
;
9854 --------------------------
9855 -- Build_Normal_Requeue --
9856 --------------------------
9858 function Build_Normal_Requeue
return Node_Id
is
9859 Params
: constant List_Id
:= New_List
;
9864 -- Process the "with abort" parameter
9867 New_Reference_To
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9869 -- Add the index expression to the parameters. It is common among all
9873 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
9875 if Is_Protected_Type
(Old_Typ
) then
9877 Self_Param
: Node_Id
;
9881 Make_Attribute_Reference
(Loc
,
9883 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
9885 Name_Unchecked_Access
);
9887 -- Protected to protected requeue
9889 if Is_Protected_Type
(Conc_Typ
) then
9892 RTE
(RE_Requeue_Protected_Entry
), Loc
);
9895 Make_Attribute_Reference
(Loc
,
9897 Concurrent_Ref
(Concval
),
9899 Name_Unchecked_Access
);
9901 -- Protected to task requeue
9903 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9906 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
9908 Param
:= Concurrent_Ref
(Concval
);
9911 Prepend_To
(Params
, Param
);
9912 Prepend_To
(Params
, Self_Param
);
9915 else pragma Assert
(Is_Task_Type
(Old_Typ
));
9917 -- Task to protected requeue
9919 if Is_Protected_Type
(Conc_Typ
) then
9922 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
9925 Make_Attribute_Reference
(Loc
,
9927 Concurrent_Ref
(Concval
),
9929 Name_Unchecked_Access
);
9931 -- Task to task requeue
9933 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
9935 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
);
9937 Param
:= Concurrent_Ref
(Concval
);
9940 Prepend_To
(Params
, Param
);
9944 Make_Procedure_Call_Statement
(Loc
,
9946 Parameter_Associations
=> Params
);
9947 end Build_Normal_Requeue
;
9949 --------------------------
9950 -- Build_Skip_Statement --
9951 --------------------------
9953 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
9954 Skip_Stmt
: Node_Id
;
9957 -- Build a return statement to skip the rest of the entire body
9959 if Is_Protected_Type
(Old_Typ
) then
9960 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
9962 -- If the requeue is within a task, find the end label of the
9963 -- enclosing accept statement and create a goto statement to it.
9971 -- Climb the parent chain looking for the enclosing accept
9974 Acc
:= Parent
(Search
);
9976 and then Nkind
(Acc
) /= N_Accept_Statement
9978 Acc
:= Parent
(Acc
);
9981 -- The last statement is the second label used for completing
9982 -- the rendezvous the usual way. The label we are looking for
9983 -- is right before it.
9986 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
9988 pragma Assert
(Nkind
(Label
) = N_Label
);
9990 -- Generate a goto statement to skip the rest of the accept
9993 Make_Goto_Statement
(Loc
,
9995 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
9999 Set_Analyzed
(Skip_Stmt
);
10002 end Build_Skip_Statement
;
10004 -- Start of processing for Expand_N_Requeue_Statement
10007 -- Extract the components of the entry call
10009 Extract_Entry
(N
, Concval
, Ename
, Index
);
10010 Conc_Typ
:= Etype
(Concval
);
10012 -- If the prefix is an access to class-wide type, dereference to get
10013 -- object and entry type.
10015 if Is_Access_Type
(Conc_Typ
) then
10016 Conc_Typ
:= Designated_Type
(Conc_Typ
);
10018 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Concval
)));
10019 Analyze_And_Resolve
(Concval
, Conc_Typ
);
10022 -- Examine the scope stack in order to find nearest enclosing protected
10023 -- or task type. This will constitute our invocation source.
10025 Old_Typ
:= Current_Scope
;
10026 while Present
(Old_Typ
)
10027 and then not Is_Protected_Type
(Old_Typ
)
10028 and then not Is_Task_Type
(Old_Typ
)
10030 Old_Typ
:= Scope
(Old_Typ
);
10033 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10034 -- Concval.Ename where the type of Concval is class-wide concurrent
10037 if Ada_Version
>= Ada_2012
10038 and then Present
(Concval
)
10039 and then Is_Class_Wide_Type
(Conc_Typ
)
10040 and then Is_Concurrent_Interface
(Conc_Typ
)
10043 Has_Impl
: Boolean := False;
10044 Impl_Kind
: Name_Id
:= No_Name
;
10047 -- Check whether the Ename is flagged by pragma Implemented
10049 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10051 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10054 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10055 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10058 and then Impl_Kind
= Name_By_Entry
10060 Rewrite
(N
, Build_Dispatching_Requeue
);
10062 Insert_After
(N
, Build_Skip_Statement
(N
));
10064 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10065 -- a protected procedure. In this case the requeue is transformed
10066 -- into a dispatching call.
10069 and then Impl_Kind
= Name_By_Protected_Procedure
10071 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10074 -- The procedure_or_entry_NAME's implementation kind is either
10075 -- By_Any, Optional, or pragma Implemented was not applied at all.
10076 -- In this case a runtime test determines whether Ename denotes an
10077 -- entry or a protected procedure and performs the appropriate
10081 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10086 -- Processing for regular (non-dispatching) requeues
10089 Rewrite
(N
, Build_Normal_Requeue
);
10091 Insert_After
(N
, Build_Skip_Statement
(N
));
10093 end Expand_N_Requeue_Statement
;
10095 -------------------------------
10096 -- Expand_N_Selective_Accept --
10097 -------------------------------
10099 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10100 Loc
: constant Source_Ptr
:= Sloc
(N
);
10101 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10103 -- Note: in the below declarations a lot of new lists are allocated
10104 -- unconditionally which may well not end up being used. That's not
10105 -- a good idea since it wastes space gratuitously ???
10107 Accept_Case
: List_Id
;
10108 Accept_List
: constant List_Id
:= New_List
;
10111 Alt_List
: constant List_Id
:= New_List
;
10112 Alt_Stats
: List_Id
;
10113 Ann
: Entity_Id
:= Empty
;
10115 Check_Guard
: Boolean := True;
10117 Decls
: constant List_Id
:= New_List
;
10118 Stats
: constant List_Id
:= New_List
;
10119 Body_List
: constant List_Id
:= New_List
;
10120 Trailing_List
: constant List_Id
:= New_List
;
10123 Else_Present
: Boolean := False;
10124 Terminate_Alt
: Node_Id
:= Empty
;
10125 Select_Mode
: Node_Id
;
10127 Delay_Case
: List_Id
;
10128 Delay_Count
: Integer := 0;
10129 Delay_Val
: Entity_Id
;
10130 Delay_Index
: Entity_Id
;
10131 Delay_Min
: Entity_Id
;
10132 Delay_Num
: Int
:= 1;
10133 Delay_Alt_List
: List_Id
:= New_List
;
10134 Delay_List
: constant List_Id
:= New_List
;
10138 First_Delay
: Boolean := True;
10139 Guard_Open
: Entity_Id
;
10145 Num_Accept
: Nat
:= 0;
10147 Time_Type
: Entity_Id
;
10148 Select_Call
: Node_Id
;
10150 Qnam
: constant Entity_Id
:=
10151 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10153 Xnam
: constant Entity_Id
:=
10154 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10156 -----------------------
10157 -- Local subprograms --
10158 -----------------------
10160 function Accept_Or_Raise
return List_Id
;
10161 -- For the rare case where delay alternatives all have guards, and
10162 -- all of them are closed, it is still possible that there were open
10163 -- accept alternatives with no callers. We must reexamine the
10164 -- Accept_List, and execute a selective wait with no else if some
10165 -- accept is open. If none, we raise program_error.
10167 procedure Add_Accept
(Alt
: Node_Id
);
10168 -- Process a single accept statement in a select alternative. Build
10169 -- procedure for body of accept, and add entry to dispatch table with
10170 -- expression for guard, in preparation for call to run time select.
10172 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10173 -- Manufacture a label using Num as a serial number and declare it.
10174 -- The declaration is appended to Decls. The label marks the trailing
10175 -- statements of an accept or delay alternative.
10177 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10178 -- Build call to Selective_Wait runtime routine
10180 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10181 -- Add code to compare value of delay with previous values, and
10182 -- generate case entry for trailing statements.
10184 procedure Process_Accept_Alternative
10188 -- Add code to call corresponding procedure, and branch to
10189 -- trailing statements, if any.
10191 ---------------------
10192 -- Accept_Or_Raise --
10193 ---------------------
10195 function Accept_Or_Raise
return List_Id
is
10198 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10201 -- We generate the following:
10203 -- for J in q'range loop
10204 -- if q(J).S /=null_task_entry then
10205 -- selective_wait (simple_mode,...);
10211 -- if no rendez_vous then
10212 -- raise program_error;
10215 -- Note that the code needs to know that the selector name
10216 -- in an Accept_Alternative is named S.
10218 Cond
:= Make_Op_Ne
(Loc
,
10220 Make_Selected_Component
(Loc
,
10222 Make_Indexed_Component
(Loc
,
10223 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10224 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
10225 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10227 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
10229 Stats
:= New_List
(
10230 Make_Implicit_Loop_Statement
(N
,
10231 Iteration_Scheme
=>
10232 Make_Iteration_Scheme
(Loc
,
10233 Loop_Parameter_Specification
=>
10234 Make_Loop_Parameter_Specification
(Loc
,
10235 Defining_Identifier
=> J
,
10236 Discrete_Subtype_Definition
=>
10237 Make_Attribute_Reference
(Loc
,
10238 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10239 Attribute_Name
=> Name_Range
,
10240 Expressions
=> New_List
(
10241 Make_Integer_Literal
(Loc
, 1))))),
10243 Statements
=> New_List
(
10244 Make_Implicit_If_Statement
(N
,
10246 Then_Statements
=> New_List
(
10248 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
10249 Make_Exit_Statement
(Loc
))))));
10252 Make_Raise_Program_Error
(Loc
,
10253 Condition
=> Make_Op_Eq
(Loc
,
10254 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
10256 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
10257 Reason
=> PE_All_Guards_Closed
));
10260 end Accept_Or_Raise
;
10266 procedure Add_Accept
(Alt
: Node_Id
) is
10267 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10268 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10269 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10270 Eent
: constant Entity_Id
:= Entity
(Ename
);
10271 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10272 Null_Body
: Node_Id
;
10273 Proc_Body
: Node_Id
;
10274 PB_Ent
: Entity_Id
;
10280 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10283 if Present
(Condition
(Alt
)) then
10285 Make_If_Expression
(Eloc
, New_List
(
10287 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10288 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10291 Entry_Index_Expression
10292 (Eloc
, Eent
, Index
, Scope
(Eent
));
10295 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10296 Null_Body
:= New_Reference_To
(Standard_False
, Eloc
);
10298 if Abort_Allowed
then
10299 Call
:= Make_Procedure_Call_Statement
(Eloc
,
10300 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Eloc
));
10301 Insert_Before
(First
(Statements
(Handled_Statement_Sequence
(
10302 Accept_Statement
(Alt
)))), Call
);
10307 Make_Defining_Identifier
(Eloc
,
10308 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10310 if Comes_From_Source
(Alt
) then
10311 Set_Debug_Info_Needed
(PB_Ent
);
10315 Make_Subprogram_Body
(Eloc
,
10317 Make_Procedure_Specification
(Eloc
,
10318 Defining_Unit_Name
=> PB_Ent
),
10319 Declarations
=> Declarations
(Acc_Stm
),
10320 Handled_Statement_Sequence
=>
10321 Build_Accept_Body
(Accept_Statement
(Alt
)));
10323 -- During the analysis of the body of the accept statement, any
10324 -- zero cost exception handler records were collected in the
10325 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10326 -- This is where we move them to where they belong, namely the
10327 -- newly created procedure.
10329 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10330 Append
(Proc_Body
, Body_List
);
10333 Null_Body
:= New_Reference_To
(Standard_True
, Eloc
);
10335 -- if accept statement has declarations, insert above, given that
10336 -- we are not creating a body for the accept.
10338 if Present
(Declarations
(Acc_Stm
)) then
10339 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10343 Append_To
(Accept_List
,
10344 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10346 Num_Accept
:= Num_Accept
+ 1;
10349 ----------------------------
10350 -- Make_And_Declare_Label --
10351 ----------------------------
10353 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10357 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10359 Make_Label
(Loc
, Lab_Id
);
10362 Make_Implicit_Label_Declaration
(Loc
,
10363 Defining_Identifier
=>
10364 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10365 Label_Construct
=> Lab
));
10368 end Make_And_Declare_Label
;
10370 ----------------------
10371 -- Make_Select_Call --
10372 ----------------------
10374 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10375 Params
: constant List_Id
:= New_List
;
10379 Make_Attribute_Reference
(Loc
,
10380 Prefix
=> New_Reference_To
(Qnam
, Loc
),
10381 Attribute_Name
=> Name_Unchecked_Access
),
10383 Append
(Select_Mode
, Params
);
10384 Append
(New_Reference_To
(Ann
, Loc
), Params
);
10385 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
10388 Make_Procedure_Call_Statement
(Loc
,
10389 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
10390 Parameter_Associations
=> Params
);
10391 end Make_Select_Call
;
10393 --------------------------------
10394 -- Process_Accept_Alternative --
10395 --------------------------------
10397 procedure Process_Accept_Alternative
10402 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10403 Alt_Stats
: List_Id
;
10406 Adjust_Condition
(Condition
(Alt
));
10408 -- Accept with body
10410 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10413 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10416 (Defining_Unit_Name
(Specification
(Proc
)),
10419 -- Accept with no body (followed by trailing statements)
10422 Alt_Stats
:= Empty_List
;
10425 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10427 -- After the call, if any, branch to trailing statements, if any.
10428 -- We create a label for each, as well as the corresponding label
10431 if not Is_Empty_List
(Statements
(Alt
)) then
10432 Lab
:= Make_And_Declare_Label
(Index
);
10433 Append
(Lab
, Trailing_List
);
10434 Append_List
(Statements
(Alt
), Trailing_List
);
10435 Append_To
(Trailing_List
,
10436 Make_Goto_Statement
(Loc
,
10437 Name
=> New_Copy
(Identifier
(End_Lab
))));
10443 Append_To
(Alt_Stats
,
10444 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10446 Append_To
(Alt_List
,
10447 Make_Case_Statement_Alternative
(Loc
,
10448 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10449 Statements
=> Alt_Stats
));
10450 end Process_Accept_Alternative
;
10452 -------------------------------
10453 -- Process_Delay_Alternative --
10454 -------------------------------
10456 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10457 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10459 Delay_Alt
: List_Id
;
10462 -- Deal with C/Fortran boolean as delay condition
10464 Adjust_Condition
(Condition
(Alt
));
10466 -- Determine the smallest specified delay
10468 -- for each delay alternative generate:
10470 -- if guard-expression then
10471 -- Delay_Val := delay-expression;
10472 -- Guard_Open := True;
10473 -- if Delay_Val < Delay_Min then
10474 -- Delay_Min := Delay_Val;
10475 -- Delay_Index := Index;
10479 -- The enclosing if-statement is omitted if there is no guard
10481 if Delay_Count
= 1 or else First_Delay
then
10482 First_Delay
:= False;
10484 Delay_Alt
:= New_List
(
10485 Make_Assignment_Statement
(Loc
,
10486 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10487 Expression
=> Expression
(Delay_Statement
(Alt
))));
10489 if Delay_Count
> 1 then
10490 Append_To
(Delay_Alt
,
10491 Make_Assignment_Statement
(Loc
,
10492 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10493 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10497 Delay_Alt
:= New_List
(
10498 Make_Assignment_Statement
(Loc
,
10499 Name
=> New_Reference_To
(Delay_Val
, Loc
),
10500 Expression
=> Expression
(Delay_Statement
(Alt
))));
10502 if Time_Type
= Standard_Duration
then
10505 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
10506 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
10509 -- The scope of the time type must define a comparison
10510 -- operator. The scope itself may not be visible, so we
10511 -- construct a node with entity information to insure that
10512 -- semantic analysis can find the proper operator.
10515 Make_Function_Call
(Loc
,
10516 Name
=> Make_Selected_Component
(Loc
,
10518 New_Reference_To
(Scope
(Time_Type
), Loc
),
10520 Make_Operator_Symbol
(Loc
,
10521 Chars
=> Name_Op_Lt
,
10522 Strval
=> No_String
)),
10523 Parameter_Associations
=>
10525 New_Reference_To
(Delay_Val
, Loc
),
10526 New_Reference_To
(Delay_Min
, Loc
)));
10528 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10531 Append_To
(Delay_Alt
,
10532 Make_Implicit_If_Statement
(N
,
10534 Then_Statements
=> New_List
(
10535 Make_Assignment_Statement
(Loc
,
10536 Name
=> New_Reference_To
(Delay_Min
, Loc
),
10537 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
10539 Make_Assignment_Statement
(Loc
,
10540 Name
=> New_Reference_To
(Delay_Index
, Loc
),
10541 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10544 if Check_Guard
then
10545 Append_To
(Delay_Alt
,
10546 Make_Assignment_Statement
(Loc
,
10547 Name
=> New_Reference_To
(Guard_Open
, Loc
),
10548 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
10551 if Present
(Condition
(Alt
)) then
10552 Delay_Alt
:= New_List
(
10553 Make_Implicit_If_Statement
(N
,
10554 Condition
=> Condition
(Alt
),
10555 Then_Statements
=> Delay_Alt
));
10558 Append_List
(Delay_Alt
, Delay_List
);
10560 Ensure_Statement_Present
(Dloc
, Alt
);
10562 -- If the delay alternative has a statement part, add choice to the
10563 -- case statements for delays.
10565 if not Is_Empty_List
(Statements
(Alt
)) then
10567 if Delay_Count
= 1 then
10568 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10571 Append_To
(Delay_Alt_List
,
10572 Make_Case_Statement_Alternative
(Loc
,
10573 Discrete_Choices
=> New_List
(
10574 Make_Integer_Literal
(Loc
, Index
)),
10575 Statements
=> Statements
(Alt
)));
10578 elsif Delay_Count
= 1 then
10580 -- If the single delay has no trailing statements, add a branch
10581 -- to the exit label to the selective wait.
10583 Delay_Alt_List
:= New_List
(
10584 Make_Goto_Statement
(Loc
,
10585 Name
=> New_Copy
(Identifier
(End_Lab
))));
10588 end Process_Delay_Alternative
;
10590 -- Start of processing for Expand_N_Selective_Accept
10593 Process_Statements_For_Controlled_Objects
(N
);
10595 -- First insert some declarations before the select. The first is:
10599 -- This variable holds the parameters passed to the accept body. This
10600 -- declaration has already been inserted by the time we get here by
10601 -- a call to Expand_Accept_Declarations made from the semantics when
10602 -- processing the first accept statement contained in the select. We
10603 -- can find this entity as Accept_Address (E), where E is any of the
10604 -- entries references by contained accept statements.
10606 -- The first step is to scan the list of Selective_Accept_Statements
10607 -- to find this entity, and also count the number of accepts, and
10608 -- determine if terminated, delay or else is present:
10612 Alt
:= First
(Alts
);
10613 while Present
(Alt
) loop
10614 Process_Statements_For_Controlled_Objects
(Alt
);
10616 if Nkind
(Alt
) = N_Accept_Alternative
then
10619 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10620 Delay_Count
:= Delay_Count
+ 1;
10622 -- If the delays are relative delays, the delay expressions have
10623 -- type Standard_Duration. Otherwise they must have some time type
10624 -- recognized by GNAT.
10626 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10627 Time_Type
:= Standard_Duration
;
10629 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10631 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10632 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10637 "& is not a time type (RM 9.6(6))",
10638 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10639 Time_Type
:= Standard_Duration
;
10640 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10644 if No
(Condition
(Alt
)) then
10646 -- This guard will always be open
10648 Check_Guard
:= False;
10651 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
10652 Adjust_Condition
(Condition
(Alt
));
10653 Terminate_Alt
:= Alt
;
10656 Num_Alts
:= Num_Alts
+ 1;
10660 Else_Present
:= Present
(Else_Statements
(N
));
10662 -- At the same time (see procedure Add_Accept) we build the accept list:
10664 -- Qnn : Accept_List (1 .. num-select) := (
10665 -- (null-body, entry-index),
10666 -- (null-body, entry-index),
10668 -- (null_body, entry-index));
10670 -- In the above declaration, null-body is True if the corresponding
10671 -- accept has no body, and false otherwise. The entry is either the
10672 -- entry index expression if there is no guard, or if a guard is
10673 -- present, then an if expression of the form:
10675 -- (if guard then entry-index else Null_Task_Entry)
10677 -- If a guard is statically known to be false, the entry can simply
10678 -- be omitted from the accept list.
10681 Make_Object_Declaration
(Loc
,
10682 Defining_Identifier
=> Qnam
,
10683 Object_Definition
=> New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10684 Aliased_Present
=> True,
10686 Make_Qualified_Expression
(Loc
,
10688 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
10690 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
10692 -- Then we declare the variable that holds the index for the accept
10693 -- that will be selected for service:
10695 -- Xnn : Select_Index;
10698 Make_Object_Declaration
(Loc
,
10699 Defining_Identifier
=> Xnam
,
10700 Object_Definition
=>
10701 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
10703 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)));
10705 -- After this follow procedure declarations for each accept body
10707 -- procedure Pnn is
10712 -- where the ... are statements from the corresponding procedure body.
10713 -- No parameters are involved, since the parameters are passed via Ann
10714 -- and the parameter references have already been expanded to be direct
10715 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10716 -- any embedded tasking statements (which would normally be illegal in
10717 -- procedures), have been converted to calls to the tasking runtime so
10718 -- there is no problem in putting them into procedures.
10720 -- The original accept statement has been expanded into a block in
10721 -- the same fashion as for simple accepts (see Build_Accept_Body).
10723 -- Note: we don't really need to build these procedures for the case
10724 -- where no delay statement is present, but it is just as easy to
10725 -- build them unconditionally, and not significantly inefficient,
10726 -- since if they are short they will be inlined anyway.
10728 -- The procedure declarations have been assembled in Body_List
10730 -- If delays are present, we must compute the required delay.
10731 -- We first generate the declarations:
10733 -- Delay_Index : Boolean := 0;
10734 -- Delay_Min : Some_Time_Type.Time;
10735 -- Delay_Val : Some_Time_Type.Time;
10737 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10738 -- active delay that is actually chosen as the basis for the possible
10739 -- delay if an immediate rendez-vous is not possible.
10741 -- In the most common case there is a single delay statement, and this
10742 -- is handled specially.
10744 if Delay_Count
> 0 then
10746 -- Generate the required declarations
10749 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
10751 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
10753 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
10756 Make_Object_Declaration
(Loc
,
10757 Defining_Identifier
=> Delay_Val
,
10758 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
10761 Make_Object_Declaration
(Loc
,
10762 Defining_Identifier
=> Delay_Index
,
10763 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
10764 Expression
=> Make_Integer_Literal
(Loc
, 0)));
10767 Make_Object_Declaration
(Loc
,
10768 Defining_Identifier
=> Delay_Min
,
10769 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
10771 Unchecked_Convert_To
(Time_Type
,
10772 Make_Attribute_Reference
(Loc
,
10774 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
10775 Attribute_Name
=> Name_Last
))));
10777 -- Create Duration and Delay_Mode objects used for passing a delay
10780 D
:= Make_Temporary
(Loc
, 'D');
10781 M
:= Make_Temporary
(Loc
, 'M');
10787 -- Note that these values are defined in s-osprim.ads and must
10788 -- be kept in sync:
10790 -- Relative : constant := 0;
10791 -- Absolute_Calendar : constant := 1;
10792 -- Absolute_RT : constant := 2;
10794 if Time_Type
= Standard_Duration
then
10795 Discr
:= Make_Integer_Literal
(Loc
, 0);
10797 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
10798 Discr
:= Make_Integer_Literal
(Loc
, 1);
10802 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
10803 Discr
:= Make_Integer_Literal
(Loc
, 2);
10807 Make_Object_Declaration
(Loc
,
10808 Defining_Identifier
=> D
,
10809 Object_Definition
=>
10810 New_Reference_To
(Standard_Duration
, Loc
)));
10813 Make_Object_Declaration
(Loc
,
10814 Defining_Identifier
=> M
,
10815 Object_Definition
=>
10816 New_Reference_To
(Standard_Integer
, Loc
),
10817 Expression
=> Discr
));
10820 if Check_Guard
then
10822 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
10825 Make_Object_Declaration
(Loc
,
10826 Defining_Identifier
=> Guard_Open
,
10827 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
10828 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
10831 -- Delay_Count is zero, don't need M and D set (suppress warning)
10838 if Present
(Terminate_Alt
) then
10840 -- If the terminate alternative guard is False, use
10841 -- Simple_Mode; otherwise use Terminate_Mode.
10843 if Present
(Condition
(Terminate_Alt
)) then
10844 Select_Mode
:= Make_If_Expression
(Loc
,
10845 New_List
(Condition
(Terminate_Alt
),
10846 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
10847 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
10849 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
10852 elsif Else_Present
or Delay_Count
> 0 then
10853 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
10856 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
10859 Select_Call
:= Make_Select_Call
(Select_Mode
);
10860 Append
(Select_Call
, Stats
);
10862 -- Now generate code to act on the result. There is an entry
10863 -- in this case for each accept statement with a non-null body,
10864 -- followed by a branch to the statements that follow the Accept.
10865 -- In the absence of delay alternatives, we generate:
10868 -- when No_Rendezvous => -- omitted if simple mode
10883 -- Lab0: Else_Statements;
10886 -- Lab1: Trailing_Statements1;
10889 -- Lab2: Trailing_Statements2;
10894 -- Generate label for common exit
10896 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
10898 -- First entry is the default case, when no rendezvous is possible
10900 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
10902 if Else_Present
then
10904 -- If no rendezvous is possible, the else part is executed
10906 Lab
:= Make_And_Declare_Label
(0);
10907 Alt_Stats
:= New_List
(
10908 Make_Goto_Statement
(Loc
,
10909 Name
=> New_Copy
(Identifier
(Lab
))));
10911 Append
(Lab
, Trailing_List
);
10912 Append_List
(Else_Statements
(N
), Trailing_List
);
10913 Append_To
(Trailing_List
,
10914 Make_Goto_Statement
(Loc
,
10915 Name
=> New_Copy
(Identifier
(End_Lab
))));
10917 Alt_Stats
:= New_List
(
10918 Make_Goto_Statement
(Loc
,
10919 Name
=> New_Copy
(Identifier
(End_Lab
))));
10922 Append_To
(Alt_List
,
10923 Make_Case_Statement_Alternative
(Loc
,
10924 Discrete_Choices
=> Choices
,
10925 Statements
=> Alt_Stats
));
10927 -- We make use of the fact that Accept_Index is an integer type, and
10928 -- generate successive literals for entries for each accept. Only those
10929 -- for which there is a body or trailing statements get a case entry.
10931 Alt
:= First
(Select_Alternatives
(N
));
10932 Proc
:= First
(Body_List
);
10933 while Present
(Alt
) loop
10935 if Nkind
(Alt
) = N_Accept_Alternative
then
10936 Process_Accept_Alternative
(Alt
, Index
, Proc
);
10937 Index
:= Index
+ 1;
10940 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
10945 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10946 Process_Delay_Alternative
(Alt
, Delay_Num
);
10947 Delay_Num
:= Delay_Num
+ 1;
10953 -- An others choice is always added to the main case, as well
10954 -- as the delay case (to satisfy the compiler).
10956 Append_To
(Alt_List
,
10957 Make_Case_Statement_Alternative
(Loc
,
10958 Discrete_Choices
=>
10959 New_List
(Make_Others_Choice
(Loc
)),
10961 New_List
(Make_Goto_Statement
(Loc
,
10962 Name
=> New_Copy
(Identifier
(End_Lab
))))));
10964 Accept_Case
:= New_List
(
10965 Make_Case_Statement
(Loc
,
10966 Expression
=> New_Reference_To
(Xnam
, Loc
),
10967 Alternatives
=> Alt_List
));
10969 Append_List
(Trailing_List
, Accept_Case
);
10970 Append_List
(Body_List
, Decls
);
10972 -- Construct case statement for trailing statements of delay
10973 -- alternatives, if there are several of them.
10975 if Delay_Count
> 1 then
10976 Append_To
(Delay_Alt_List
,
10977 Make_Case_Statement_Alternative
(Loc
,
10978 Discrete_Choices
=>
10979 New_List
(Make_Others_Choice
(Loc
)),
10981 New_List
(Make_Null_Statement
(Loc
))));
10983 Delay_Case
:= New_List
(
10984 Make_Case_Statement
(Loc
,
10985 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
10986 Alternatives
=> Delay_Alt_List
));
10988 Delay_Case
:= Delay_Alt_List
;
10991 -- If there are no delay alternatives, we append the case statement
10992 -- to the statement list.
10994 if Delay_Count
= 0 then
10995 Append_List
(Accept_Case
, Stats
);
10997 -- Delay alternatives present
11000 -- If delay alternatives are present we generate:
11002 -- find minimum delay.
11003 -- DX := minimum delay;
11004 -- M := <delay mode>;
11005 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11008 -- if X = No_Rendezvous then
11009 -- case statement for delay statements.
11011 -- case statement for accept alternatives.
11022 -- The type of the delay expression is known to be legal
11024 if Time_Type
= Standard_Duration
then
11025 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
11027 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11028 Conv
:= Make_Function_Call
(Loc
,
11029 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
11030 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
11034 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11036 Conv
:= Make_Function_Call
(Loc
,
11037 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
11038 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
11041 Stmt
:= Make_Assignment_Statement
(Loc
,
11042 Name
=> New_Reference_To
(D
, Loc
),
11043 Expression
=> Conv
);
11045 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11047 Parms
:= Parameter_Associations
(Select_Call
);
11048 Parm
:= First
(Parms
);
11050 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11054 pragma Assert
(Present
(Parm
));
11055 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
11058 -- Prepare two new parameters of Duration and Delay_Mode type
11059 -- which represent the value and the mode of the minimum delay.
11062 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
11063 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
11065 -- Create a call to RTS
11067 Rewrite
(Select_Call
,
11068 Make_Procedure_Call_Statement
(Loc
,
11069 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11070 Parameter_Associations
=> Parms
));
11072 -- This new call should follow the calculation of the minimum
11075 Insert_List_Before
(Select_Call
, Delay_List
);
11077 if Check_Guard
then
11079 Make_Implicit_If_Statement
(N
,
11080 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
11081 Then_Statements
=> New_List
(
11082 New_Copy_Tree
(Stmt
),
11083 New_Copy_Tree
(Select_Call
)),
11084 Else_Statements
=> Accept_Or_Raise
);
11085 Rewrite
(Select_Call
, Stmt
);
11087 Insert_Before
(Select_Call
, Stmt
);
11091 Make_Implicit_If_Statement
(N
,
11092 Condition
=> Make_Op_Eq
(Loc
,
11093 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
11095 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
11097 Then_Statements
=> Delay_Case
,
11098 Else_Statements
=> Accept_Case
);
11100 Append
(Cases
, Stats
);
11103 Append
(End_Lab
, Stats
);
11105 -- Replace accept statement with appropriate block
11108 Make_Block_Statement
(Loc
,
11109 Declarations
=> Decls
,
11110 Handled_Statement_Sequence
=>
11111 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11114 -- Note: have to worry more about abort deferral in above code ???
11116 -- Final step is to unstack the Accept_Address entries for all accept
11117 -- statements appearing in accept alternatives in the select statement
11119 Alt
:= First
(Alts
);
11120 while Present
(Alt
) loop
11121 if Nkind
(Alt
) = N_Accept_Alternative
then
11122 Remove_Last_Elmt
(Accept_Address
11123 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11128 end Expand_N_Selective_Accept
;
11130 --------------------------------------
11131 -- Expand_N_Single_Task_Declaration --
11132 --------------------------------------
11134 -- Single task declarations should never be present after semantic
11135 -- analysis, since we expect them to be replaced by a declaration of an
11136 -- anonymous task type, followed by a declaration of the task object. We
11137 -- include this routine to make sure that is happening!
11139 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11141 raise Program_Error
;
11142 end Expand_N_Single_Task_Declaration
;
11144 ------------------------
11145 -- Expand_N_Task_Body --
11146 ------------------------
11148 -- Given a task body
11150 -- task body tname is
11156 -- This expansion routine converts it into a procedure and sets the
11157 -- elaboration flag for the procedure to true, to represent the fact
11158 -- that the task body is now elaborated:
11160 -- procedure tnameB (_Task : access tnameV) is
11161 -- discriminal : dtype renames _Task.discriminant;
11163 -- procedure _clean is
11165 -- Abort_Defer.all;
11167 -- Abort_Undefer.all;
11172 -- Abort_Undefer.all;
11174 -- System.Task_Stages.Complete_Activation;
11182 -- In addition, if the task body is an activator, then a call to activate
11183 -- tasks is added at the start of the statements, before the call to
11184 -- Complete_Activation, and if in addition the task is a master then it
11185 -- must be established as a master. These calls are inserted and analyzed
11186 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11189 -- There is one discriminal declaration line generated for each
11190 -- discriminant that is present to provide an easy reference point for
11191 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11193 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11194 -- task body procedures have a profile (Arg : System.Address). That is
11195 -- needed because GNARLI has to use the same access-to-subprogram type
11196 -- for all task types. We depend here on knowing that in GNAT, passing
11197 -- an address argument by value is identical to passing a record value
11198 -- by access (in either case a single pointer is passed), so even though
11199 -- this procedure has the wrong profile. In fact it's all OK, since the
11200 -- callings sequence is identical.
11202 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11203 Loc
: constant Source_Ptr
:= Sloc
(N
);
11204 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11208 Insert_Nod
: Node_Id
;
11209 -- Used to determine the proper location of wrapper body insertions
11212 -- Add renaming declarations for discriminals and a declaration for the
11213 -- entry family index (if applicable).
11215 Install_Private_Data_Declarations
11216 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11218 -- Add a call to Abort_Undefer at the very beginning of the task
11219 -- body since this body is called with abort still deferred.
11221 if Abort_Allowed
then
11222 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11224 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11228 -- The statement part has already been protected with an at_end and
11229 -- cleanup actions. The call to Complete_Activation must be placed
11230 -- at the head of the sequence of statements of that block. The
11231 -- declarations have been merged in this sequence of statements but
11232 -- the first real statement is accessible from the First_Real_Statement
11233 -- field (which was set for exactly this purpose).
11235 if Restricted_Profile
then
11236 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11238 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11242 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
11246 Make_Subprogram_Body
(Loc
,
11247 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11248 Declarations
=> Declarations
(N
),
11249 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11251 -- If the task contains generic instantiations, cleanup actions are
11252 -- delayed until after instantiation. Transfer the activation chain to
11253 -- the subprogram, to insure that the activation call is properly
11254 -- generated. It the task body contains inner tasks, indicate that the
11255 -- subprogram is a task master.
11257 if Delay_Cleanups
(Ttyp
) then
11258 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11259 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11262 Rewrite
(N
, New_N
);
11265 -- Set elaboration flag immediately after task body. If the body is a
11266 -- subunit, the flag is set in the declarative part containing the stub.
11268 if Nkind
(Parent
(N
)) /= N_Subunit
then
11270 Make_Assignment_Statement
(Loc
,
11272 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11273 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
11276 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11277 -- the task body. At this point all wrapper specs have been created,
11278 -- frozen and included in the dispatch table for the task type.
11280 if Ada_Version
>= Ada_2005
then
11281 if Nkind
(Parent
(N
)) = N_Subunit
then
11282 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11287 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11289 end Expand_N_Task_Body
;
11291 ------------------------------------
11292 -- Expand_N_Task_Type_Declaration --
11293 ------------------------------------
11295 -- We have several things to do. First we must create a Boolean flag used
11296 -- to mark if the body is elaborated yet. This variable gets set to True
11297 -- when the body of the task is elaborated (we can't rely on the normal
11298 -- ABE mechanism for the task body, since we need to pass an access to
11299 -- this elaboration boolean to the runtime routines).
11301 -- taskE : aliased Boolean := False;
11303 -- Next a variable is declared to hold the task stack size (either the
11304 -- default : Unspecified_Size, or a value that is set by a pragma
11305 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11306 -- the variable is initialized with this value:
11308 -- taskZ : Size_Type := Unspecified_Size;
11310 -- taskZ : Size_Type := Size_Type (size_expression);
11312 -- Note: No variable is needed to hold the task relative deadline since
11313 -- its value would never be static because the parameter is of a private
11314 -- type (Ada.Real_Time.Time_Span).
11316 -- Next we create a corresponding record type declaration used to represent
11317 -- values of this task. The general form of this type declaration is
11319 -- type taskV (discriminants) is record
11320 -- _Task_Id : Task_Id;
11321 -- entry_family : array (bounds) of Void;
11322 -- _Priority : Integer := priority_expression;
11323 -- _Size : Size_Type := size_expression;
11324 -- _Task_Info : Task_Info_Type := task_info_expression;
11325 -- _CPU : Integer := cpu_range_expression;
11326 -- _Relative_Deadline : Time_Span := time_span_expression;
11327 -- _Domain : Dispatching_Domain := dd_expression;
11330 -- The discriminants are present only if the corresponding task type has
11331 -- discriminants, and they exactly mirror the task type discriminants.
11333 -- The Id field is always present. It contains the Task_Id value, as set by
11334 -- the call to Create_Task. Note that although the task is limited, the
11335 -- task value record type is not limited, so there is no problem in passing
11336 -- this field as an out parameter to Create_Task.
11338 -- One entry_family component is present for each entry family in the task
11339 -- definition. The bounds correspond to the bounds of the entry family
11340 -- (which may depend on discriminants). The element type is void, since we
11341 -- only need the bounds information for determining the entry index. Note
11342 -- that the use of an anonymous array would normally be illegal in this
11343 -- context, but this is a parser check, and the semantics is quite prepared
11344 -- to handle such a case.
11346 -- The _Size field is present only if a Storage_Size pragma appears in the
11347 -- task definition. The expression captures the argument that was present
11348 -- in the pragma, and is used to override the task stack size otherwise
11349 -- associated with the task type.
11351 -- The _Priority field is present only if the task entity has a Priority or
11352 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11353 -- definition clause). It will be filled at the freeze point, when the
11354 -- record init proc is built, to capture the expression of the rep item
11355 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11356 -- here since aspect evaluations are delayed till the freeze point.
11358 -- The _Task_Info field is present only if a Task_Info pragma appears in
11359 -- the task definition. The expression captures the argument that was
11360 -- present in the pragma, and is used to provide the Task_Image parameter
11361 -- to the call to Create_Task.
11363 -- The _CPU field is present only if the task entity has a CPU rep item
11364 -- (pragma, aspect specification or attribute definition clause). It will
11365 -- be filled at the freeze point, when the record init proc is built, to
11366 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11367 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11368 -- are delayed till the freeze point.
11370 -- The _Relative_Deadline field is present only if a Relative_Deadline
11371 -- pragma appears in the task definition. The expression captures the
11372 -- argument that was present in the pragma, and is used to provide the
11373 -- Relative_Deadline parameter to the call to Create_Task.
11375 -- The _Domain field is present only if the task entity has a
11376 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11377 -- definition clause). It will be filled at the freeze point, when the
11378 -- record init proc is built, to capture the expression of the rep item
11379 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11380 -- here since aspect evaluations are delayed till the freeze point.
11382 -- When a task is declared, an instance of the task value record is
11383 -- created. The elaboration of this declaration creates the correct bounds
11384 -- for the entry families, and also evaluates the size, priority, and
11385 -- task_Info expressions if needed. The initialization routine for the task
11386 -- type itself then calls Create_Task with appropriate parameters to
11387 -- initialize the value of the Task_Id field.
11389 -- Note: the address of this record is passed as the "Discriminants"
11390 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11391 -- body procedure, it does not matter that it does not quite match the
11392 -- GNARLI model of what is being passed (the record contains more than just
11393 -- the discriminants, but the discriminants can be found from the record
11396 -- The Entity_Id for this created record type is placed in the
11397 -- Corresponding_Record_Type field of the associated task type entity.
11399 -- Next we create a procedure specification for the task body procedure:
11401 -- procedure taskB (_Task : access taskV);
11403 -- Note that this must come after the record type declaration, since
11404 -- the spec refers to this type. It turns out that the initialization
11405 -- procedure for the value type references the task body spec, but that's
11406 -- fine, since it won't be generated till the freeze point for the type,
11407 -- which is certainly after the task body spec declaration.
11409 -- Finally, we set the task index value field of the entry attribute in
11410 -- the case of a simple entry.
11412 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11413 Loc
: constant Source_Ptr
:= Sloc
(N
);
11414 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11415 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11416 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11417 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11419 Body_Decl
: Node_Id
;
11421 Decl_Stack
: Node_Id
;
11422 Elab_Decl
: Node_Id
;
11423 Ent_Stack
: Entity_Id
;
11424 Proc_Spec
: Node_Id
;
11425 Rec_Decl
: Node_Id
;
11426 Rec_Ent
: Entity_Id
;
11427 Size_Decl
: Entity_Id
;
11428 Task_Size
: Node_Id
;
11430 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11431 -- Searches the task definition T for the first occurrence of the pragma
11432 -- Relative Deadline. The caller has ensured that the pragma is present
11433 -- in the task definition. Note that this routine cannot be implemented
11434 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11435 -- not chained because their expansion into a procedure call statement
11436 -- would cause a break in the chain.
11438 ----------------------------------
11439 -- Get_Relative_Deadline_Pragma --
11440 ----------------------------------
11442 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11446 N
:= First
(Visible_Declarations
(T
));
11447 while Present
(N
) loop
11448 if Nkind
(N
) = N_Pragma
11449 and then Pragma_Name
(N
) = Name_Relative_Deadline
11457 N
:= First
(Private_Declarations
(T
));
11458 while Present
(N
) loop
11459 if Nkind
(N
) = N_Pragma
11460 and then Pragma_Name
(N
) = Name_Relative_Deadline
11468 raise Program_Error
;
11469 end Get_Relative_Deadline_Pragma
;
11471 -- Start of processing for Expand_N_Task_Type_Declaration
11474 -- If already expanded, nothing to do
11476 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11480 -- Here we will do the expansion
11482 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11484 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11485 Cdecls
:= Component_Items
(Component_List
11486 (Type_Definition
(Rec_Decl
)));
11488 Qualify_Entity_Names
(N
);
11490 -- First create the elaboration variable
11493 Make_Object_Declaration
(Loc
,
11494 Defining_Identifier
=>
11495 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11496 Chars
=> New_External_Name
(Tasknm
, 'E')),
11497 Aliased_Present
=> True,
11498 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
11499 Expression
=> New_Reference_To
(Standard_False
, Loc
));
11501 Insert_After
(N
, Elab_Decl
);
11503 -- Next create the declaration of the size variable (tasknmZ)
11505 Set_Storage_Size_Variable
(Tasktyp
,
11506 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11507 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11509 if Present
(Taskdef
)
11510 and then Has_Storage_Size_Pragma
(Taskdef
)
11512 Is_Static_Expression
11514 (First
(Pragma_Argument_Associations
11515 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11518 Make_Object_Declaration
(Loc
,
11519 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11520 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11522 Convert_To
(RTE
(RE_Size_Type
),
11524 (Expression
(First
(Pragma_Argument_Associations
11526 (TaskId
, Name_Storage_Size
)))))));
11530 Make_Object_Declaration
(Loc
,
11531 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11532 Object_Definition
=>
11533 New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
11535 New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
11538 Insert_After
(Elab_Decl
, Size_Decl
);
11540 -- Next build the rest of the corresponding record declaration. This is
11541 -- done last, since the corresponding record initialization procedure
11542 -- will reference the previously created entities.
11544 -- Fill in the component declarations -- first the _Task_Id field
11547 Make_Component_Declaration
(Loc
,
11548 Defining_Identifier
=>
11549 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11550 Component_Definition
=>
11551 Make_Component_Definition
(Loc
,
11552 Aliased_Present
=> False,
11553 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
11556 -- Declare static ATCB (that is, created by the expander) if we are
11557 -- using the Restricted run time.
11559 if Restricted_Profile
then
11561 Make_Component_Declaration
(Loc
,
11562 Defining_Identifier
=>
11563 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11565 Component_Definition
=>
11566 Make_Component_Definition
(Loc
,
11567 Aliased_Present
=> True,
11568 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11570 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11573 Make_Index_Or_Discriminant_Constraint
(Loc
,
11575 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11579 -- Declare static stack (that is, created by the expander) if we are
11580 -- using the Restricted run time on a bare board configuration.
11582 if Restricted_Profile
11583 and then Preallocated_Stacks_On_Target
11585 -- First we need to extract the appropriate stack size
11587 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11589 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11591 Expr_N
: constant Node_Id
:=
11592 Expression
(First
(
11593 Pragma_Argument_Associations
(
11594 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11595 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11596 P
: constant Node_Id
:= Parent
(Expr_N
);
11599 -- The stack is defined inside the corresponding record.
11600 -- Therefore if the size of the stack is set by means of
11601 -- a discriminant, we must reference the discriminant of the
11602 -- corresponding record type.
11604 if Nkind
(Expr_N
) in N_Has_Entity
11605 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11609 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11611 Set_Parent
(Task_Size
, P
);
11612 Set_Etype
(Task_Size
, Etyp
);
11613 Set_Analyzed
(Task_Size
);
11616 Task_Size
:= Relocate_Node
(Expr_N
);
11622 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
11625 Decl_Stack
:= Make_Component_Declaration
(Loc
,
11626 Defining_Identifier
=> Ent_Stack
,
11628 Component_Definition
=>
11629 Make_Component_Definition
(Loc
,
11630 Aliased_Present
=> True,
11631 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11633 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
11636 Make_Index_Or_Discriminant_Constraint
(Loc
,
11637 Constraints
=> New_List
(Make_Range
(Loc
,
11638 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
11639 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
11642 Append_To
(Cdecls
, Decl_Stack
);
11644 -- The appropriate alignment for the stack is ensured by the run-time
11645 -- code in charge of task creation.
11649 -- Add components for entry families
11651 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
11653 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11654 -- item is present.
11656 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
11658 Make_Component_Declaration
(Loc
,
11659 Defining_Identifier
=>
11660 Make_Defining_Identifier
(Loc
, Name_uPriority
),
11661 Component_Definition
=>
11662 Make_Component_Definition
(Loc
,
11663 Aliased_Present
=> False,
11664 Subtype_Indication
=>
11665 New_Reference_To
(Standard_Integer
, Loc
))));
11668 -- Add the _Size component if a Storage_Size pragma is present
11670 if Present
(Taskdef
)
11671 and then Has_Storage_Size_Pragma
(Taskdef
)
11674 Make_Component_Declaration
(Loc
,
11675 Defining_Identifier
=>
11676 Make_Defining_Identifier
(Loc
, Name_uSize
),
11678 Component_Definition
=>
11679 Make_Component_Definition
(Loc
,
11680 Aliased_Present
=> False,
11681 Subtype_Indication
=>
11682 New_Reference_To
(RTE
(RE_Size_Type
), Loc
)),
11685 Convert_To
(RTE
(RE_Size_Type
),
11687 Expression
(First
(
11688 Pragma_Argument_Associations
(
11689 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
11692 -- Add the _Task_Info component if a Task_Info pragma is present
11694 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
11696 Make_Component_Declaration
(Loc
,
11697 Defining_Identifier
=>
11698 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
11700 Component_Definition
=>
11701 Make_Component_Definition
(Loc
,
11702 Aliased_Present
=> False,
11703 Subtype_Indication
=>
11704 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
11706 Expression
=> New_Copy
(
11707 Expression
(First
(
11708 Pragma_Argument_Associations
(
11710 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
11713 -- Add the _CPU component if a CPU rep item is present
11715 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
11717 Make_Component_Declaration
(Loc
,
11718 Defining_Identifier
=>
11719 Make_Defining_Identifier
(Loc
, Name_uCPU
),
11721 Component_Definition
=>
11722 Make_Component_Definition
(Loc
,
11723 Aliased_Present
=> False,
11724 Subtype_Indication
=>
11725 New_Reference_To
(RTE
(RE_CPU_Range
), Loc
))));
11728 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11729 -- present. If we are using a restricted run time this component will
11730 -- not be added (deadlines are not allowed by the Ravenscar profile).
11732 if not Restricted_Profile
11733 and then Present
(Taskdef
)
11734 and then Has_Relative_Deadline_Pragma
(Taskdef
)
11737 Make_Component_Declaration
(Loc
,
11738 Defining_Identifier
=>
11739 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
11741 Component_Definition
=>
11742 Make_Component_Definition
(Loc
,
11743 Aliased_Present
=> False,
11744 Subtype_Indication
=>
11745 New_Reference_To
(RTE
(RE_Time_Span
), Loc
)),
11748 Convert_To
(RTE
(RE_Time_Span
),
11750 Expression
(First
(
11751 Pragma_Argument_Associations
(
11752 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
11755 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
11756 -- item is present. If we are using a restricted run time this component
11757 -- will not be added (dispatching domains are not allowed by the
11758 -- Ravenscar profile).
11760 if not Restricted_Profile
11763 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
11766 Make_Component_Declaration
(Loc
,
11767 Defining_Identifier
=>
11768 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
11770 Component_Definition
=>
11771 Make_Component_Definition
(Loc
,
11772 Aliased_Present
=> False,
11773 Subtype_Indication
=>
11775 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
11778 Insert_After
(Size_Decl
, Rec_Decl
);
11780 -- Analyze the record declaration immediately after construction,
11781 -- because the initialization procedure is needed for single task
11782 -- declarations before the next entity is analyzed.
11784 Analyze
(Rec_Decl
);
11786 -- Create the declaration of the task body procedure
11788 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
11790 Make_Subprogram_Declaration
(Loc
,
11791 Specification
=> Proc_Spec
);
11793 Insert_After
(Rec_Decl
, Body_Decl
);
11795 -- The subprogram does not comes from source, so we have to indicate the
11796 -- need for debugging information explicitly.
11798 if Comes_From_Source
(Original_Node
(N
)) then
11799 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
11802 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11803 -- the corresponding record has been frozen.
11805 if Ada_Version
>= Ada_2005
then
11806 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
11809 -- Ada 2005 (AI-345): We must defer freezing to allow further
11810 -- declaration of primitive subprograms covering task interfaces
11812 if Ada_Version
<= Ada_95
then
11814 -- Now we can freeze the corresponding record. This needs manually
11815 -- freezing, since it is really part of the task type, and the task
11816 -- type is frozen at this stage. We of course need the initialization
11817 -- procedure for this corresponding record type and we won't get it
11818 -- in time if we don't freeze now.
11821 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, N
);
11823 if Is_Non_Empty_List
(L
) then
11824 Insert_List_After
(Body_Decl
, L
);
11829 -- Complete the expansion of access types to the current task type, if
11830 -- any were declared.
11832 Expand_Previous_Access_Type
(Tasktyp
);
11834 -- Create wrappers for entries that have pre/postconditions
11840 Ent
:= First_Entity
(Tasktyp
);
11841 while Present
(Ent
) loop
11842 if Ekind_In
(Ent
, E_Entry
, E_Entry_Family
)
11843 and then Present
(Spec_PPC_List
(Contract
(Ent
)))
11845 Build_PPC_Wrapper
(Ent
, N
);
11851 end Expand_N_Task_Type_Declaration
;
11853 -------------------------------
11854 -- Expand_N_Timed_Entry_Call --
11855 -------------------------------
11857 -- A timed entry call in normal case is not implemented using ATC mechanism
11858 -- anymore for efficiency reason.
11868 -- is expanded as follows:
11870 -- 1) When T.E is a task entry_call;
11874 -- X : Task_Entry_Index := <entry index>;
11875 -- DX : Duration := To_Duration (D);
11876 -- M : Delay_Mode := <discriminant>;
11877 -- P : parms := (parm, parm, parm);
11880 -- Timed_Protected_Entry_Call
11881 -- (<acceptor-task>, X, P'Address, DX, M, B);
11889 -- 2) When T.E is a protected entry_call;
11893 -- X : Protected_Entry_Index := <entry index>;
11894 -- DX : Duration := To_Duration (D);
11895 -- M : Delay_Mode := <discriminant>;
11896 -- P : parms := (parm, parm, parm);
11899 -- Timed_Protected_Entry_Call
11900 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
11908 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
11911 -- B : Boolean := False;
11912 -- C : Ada.Tags.Prim_Op_Kind;
11913 -- DX : Duration := To_Duration (D)
11914 -- K : Ada.Tags.Tagged_Kind :=
11915 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
11916 -- M : Integer :=...;
11917 -- P : Parameters := (Param1 .. ParamN);
11921 -- if K = Ada.Tags.TK_Limited_Tagged then
11922 -- <dispatching-call>;
11923 -- <triggering-statements>
11927 -- Ada.Tags.Get_Offset_Index
11928 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
11930 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
11932 -- if C = POK_Protected_Entry
11933 -- or else C = POK_Task_Entry
11935 -- Param1 := P.Param1;
11937 -- ParamN := P.ParamN;
11941 -- if C = POK_Procedure
11942 -- or else C = POK_Protected_Procedure
11943 -- or else C = POK_Task_Procedure
11945 -- <dispatching-call>;
11948 -- <triggering-statements>
11950 -- <timed-statements>
11955 -- The triggering statement and the sequence of timed statements have not
11956 -- been analyzed yet (see Analyzed_Timed_Entry_Call). They may contain
11957 -- local declarations, and therefore the copies that are made during
11958 -- expansion must be disjoint, as for any other inlining.
11960 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
11961 Loc
: constant Source_Ptr
:= Sloc
(N
);
11964 Blk_Typ
: Entity_Id
;
11966 Call_Ent
: Entity_Id
;
11967 Conc_Typ_Stmts
: List_Id
;
11969 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
11972 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
11974 D_Type
: Entity_Id
;
11977 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
11978 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
11983 Is_Disp_Select
: Boolean;
11984 Lim_Typ_Stmts
: List_Id
;
11993 B
: Entity_Id
; -- Call status flag
11994 C
: Entity_Id
; -- Call kind
11995 D
: Entity_Id
; -- Delay
11996 K
: Entity_Id
; -- Tagged kind
11997 M
: Entity_Id
; -- Delay mode
11998 P
: Entity_Id
; -- Parameter block
11999 S
: Entity_Id
; -- Primitive operation slot
12002 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12003 -- was already reported on spec, so do not attempt to expand the call.
12005 if Restriction_Active
(No_Select_Statements
) then
12009 Process_Statements_For_Controlled_Objects
(E_Alt
);
12010 Process_Statements_For_Controlled_Objects
(D_Alt
);
12012 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12014 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12015 -- may wrap them in blocks.
12017 E_Stats
:= Statements
(E_Alt
);
12018 D_Stats
:= Statements
(D_Alt
);
12020 -- The arguments in the call may require dynamic allocation, and the
12021 -- call statement may have been transformed into a block. The block
12022 -- may contain additional declarations for internal entities, and the
12023 -- original call is found by sequential search.
12025 if Nkind
(E_Call
) = N_Block_Statement
then
12026 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12027 while not Nkind_In
(E_Call
, N_Procedure_Call_Statement
,
12028 N_Entry_Call_Statement
)
12035 Ada_Version
>= Ada_2005
12036 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12038 if Is_Disp_Select
then
12039 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12045 -- B : Boolean := False;
12047 B
:= Build_B
(Loc
, Decls
);
12050 -- C : Ada.Tags.Prim_Op_Kind;
12052 C
:= Build_C
(Loc
, Decls
);
12054 -- Because the analysis of all statements was disabled, manually
12055 -- analyze the delay statement.
12058 D_Stat
:= Original_Node
(D_Stat
);
12061 -- Build an entry call using Simple_Entry_Call
12063 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12064 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12066 Decls
:= Declarations
(E_Call
);
12067 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12076 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12079 Make_Object_Declaration
(Loc
,
12080 Defining_Identifier
=> B
,
12081 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
12084 -- Duration and mode processing
12086 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12088 -- Use the type of the delay expression (Calendar or Real_Time) to
12089 -- generate the appropriate conversion.
12091 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12092 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12093 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12095 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12096 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12098 Make_Function_Call
(Loc
,
12099 Name
=> New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
12100 Parameter_Associations
=>
12101 New_List
(New_Copy
(Expression
(D_Stat
))));
12103 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12104 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12106 Make_Function_Call
(Loc
,
12107 Name
=> New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
12108 Parameter_Associations
=>
12109 New_List
(New_Copy
(Expression
(D_Stat
))));
12112 D
:= Make_Temporary
(Loc
, 'D');
12118 Make_Object_Declaration
(Loc
,
12119 Defining_Identifier
=> D
,
12120 Object_Definition
=> New_Reference_To
(Standard_Duration
, Loc
)));
12122 M
:= Make_Temporary
(Loc
, 'M');
12125 -- M : Integer := (0 | 1 | 2);
12128 Make_Object_Declaration
(Loc
,
12129 Defining_Identifier
=> M
,
12130 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
12131 Expression
=> D_Disc
));
12133 -- Do the assignment at this stage only because the evaluation of the
12134 -- expression must not occur before (see ACVC C97302A).
12137 Make_Assignment_Statement
(Loc
,
12138 Name
=> New_Reference_To
(D
, Loc
),
12139 Expression
=> D_Conv
));
12141 -- Parameter block processing
12143 -- Manually create the parameter block for dispatching calls. In the
12144 -- case of entries, the block has already been created during the call
12145 -- to Build_Simple_Entry_Call.
12147 if Is_Disp_Select
then
12149 -- Tagged kind processing, generate:
12150 -- K : Ada.Tags.Tagged_Kind :=
12151 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12153 K
:= Build_K
(Loc
, Decls
, Obj
);
12155 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12157 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12159 -- Dispatch table slot processing, generate:
12162 S
:= Build_S
(Loc
, Decls
);
12165 -- S := Ada.Tags.Get_Offset_Index
12166 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12169 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12172 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12174 -- where Obj is the controlling formal parameter, S is the dispatch
12175 -- table slot number of the dispatching operation, P is the wrapped
12176 -- parameter block, D is the duration, M is the duration mode, C is
12177 -- the call kind and B is the call status.
12179 Params
:= New_List
;
12181 Append_To
(Params
, New_Copy_Tree
(Obj
));
12182 Append_To
(Params
, New_Reference_To
(S
, Loc
));
12184 Make_Attribute_Reference
(Loc
,
12185 Prefix
=> New_Reference_To
(P
, Loc
),
12186 Attribute_Name
=> Name_Address
));
12187 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12188 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12189 Append_To
(Params
, New_Reference_To
(C
, Loc
));
12190 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12192 Append_To
(Conc_Typ_Stmts
,
12193 Make_Procedure_Call_Statement
(Loc
,
12197 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12198 Parameter_Associations
=> Params
));
12201 -- if C = POK_Protected_Entry
12202 -- or else C = POK_Task_Entry
12204 -- Param1 := P.Param1;
12206 -- ParamN := P.ParamN;
12209 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12211 -- Generate the if statement only when the packed parameters need
12212 -- explicit assignments to their corresponding actuals.
12214 if Present
(Unpack
) then
12215 Append_To
(Conc_Typ_Stmts
,
12216 Make_Implicit_If_Statement
(N
,
12222 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12225 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12229 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12231 New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
))),
12233 Then_Statements
=> Unpack
));
12239 -- if C = POK_Procedure
12240 -- or else C = POK_Protected_Procedure
12241 -- or else C = POK_Task_Procedure
12243 -- <dispatching-call>
12245 -- <triggering-statements>
12247 -- <timed-statements>
12250 N_Stats
:= Copy_Separate_List
(E_Stats
);
12252 Prepend_To
(N_Stats
,
12253 Make_Implicit_If_Statement
(N
,
12259 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12261 New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
)),
12267 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12269 New_Reference_To
(RTE
(
12270 RE_POK_Protected_Procedure
), Loc
)),
12273 Left_Opnd
=> New_Reference_To
(C
, Loc
),
12276 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12278 Then_Statements
=> New_List
(E_Call
)));
12280 Append_To
(Conc_Typ_Stmts
,
12281 Make_Implicit_If_Statement
(N
,
12282 Condition
=> New_Reference_To
(B
, Loc
),
12283 Then_Statements
=> N_Stats
,
12284 Else_Statements
=> D_Stats
));
12287 -- <dispatching-call>;
12288 -- <triggering-statements>
12290 Lim_Typ_Stmts
:= Copy_Separate_List
(E_Stats
);
12291 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(E_Call
));
12294 -- if K = Ada.Tags.TK_Limited_Tagged then
12301 Make_Implicit_If_Statement
(N
,
12304 Left_Opnd
=> New_Reference_To
(K
, Loc
),
12306 New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
12307 Then_Statements
=> Lim_Typ_Stmts
,
12308 Else_Statements
=> Conc_Typ_Stmts
));
12311 -- Skip assignments to temporaries created for in-out parameters.
12312 -- This makes unwarranted assumptions about the shape of the expanded
12313 -- tree for the call, and should be cleaned up ???
12315 Stmt
:= First
(Stmts
);
12316 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12320 -- Do the assignment at this stage only because the evaluation
12321 -- of the expression must not occur before (see ACVC C97302A).
12323 Insert_Before
(Stmt
,
12324 Make_Assignment_Statement
(Loc
,
12325 Name
=> New_Reference_To
(D
, Loc
),
12326 Expression
=> D_Conv
));
12329 Params
:= Parameter_Associations
(Call
);
12331 -- For a protected type, we build a Timed_Protected_Entry_Call
12333 if Is_Protected_Type
(Etype
(Concval
)) then
12335 -- Create a new call statement
12337 Param
:= First
(Params
);
12338 while Present
(Param
)
12339 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12344 Dummy
:= Remove_Next
(Next
(Param
));
12346 -- Remove garbage is following the Cancel_Param if present
12348 Dummy
:= Next
(Param
);
12350 -- Remove the mode of the Protected_Entry_Call call, then remove
12351 -- the Communication_Block of the Protected_Entry_Call call, and
12352 -- finally add Duration and a Delay_Mode parameter
12354 pragma Assert
(Present
(Param
));
12355 Rewrite
(Param
, New_Reference_To
(D
, Loc
));
12357 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
12359 -- Add a Boolean flag for successful entry call
12361 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12363 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12364 when System_Tasking_Protected_Objects_Entries
=>
12366 Make_Procedure_Call_Statement
(Loc
,
12369 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12370 Parameter_Associations
=> Params
));
12372 when System_Tasking_Protected_Objects_Single_Entry
=>
12373 Param
:= First
(Params
);
12374 while Present
(Param
)
12376 Is_RTE
(Etype
(Param
), RE_Protected_Entry_Index
)
12384 Make_Procedure_Call_Statement
(Loc
,
12387 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
12388 Parameter_Associations
=> Params
));
12391 raise Program_Error
;
12394 -- For the task case, build a Timed_Task_Entry_Call
12397 -- Create a new call statement
12399 Append_To
(Params
, New_Reference_To
(D
, Loc
));
12400 Append_To
(Params
, New_Reference_To
(M
, Loc
));
12401 Append_To
(Params
, New_Reference_To
(B
, Loc
));
12404 Make_Procedure_Call_Statement
(Loc
,
12406 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12407 Parameter_Associations
=> Params
));
12411 Make_Implicit_If_Statement
(N
,
12412 Condition
=> New_Reference_To
(B
, Loc
),
12413 Then_Statements
=> E_Stats
,
12414 Else_Statements
=> D_Stats
));
12418 Make_Block_Statement
(Loc
,
12419 Declarations
=> Decls
,
12420 Handled_Statement_Sequence
=>
12421 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12424 end Expand_N_Timed_Entry_Call
;
12426 ----------------------------------------
12427 -- Expand_Protected_Body_Declarations --
12428 ----------------------------------------
12430 procedure Expand_Protected_Body_Declarations
12432 Spec_Id
: Entity_Id
)
12435 if No_Run_Time_Mode
then
12436 Error_Msg_CRT
("protected body", N
);
12439 elsif Full_Expander_Active
then
12441 -- Associate discriminals with the first subprogram or entry body to
12444 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12445 Set_Discriminals
(Parent
(Spec_Id
));
12448 end Expand_Protected_Body_Declarations
;
12450 -------------------------
12451 -- External_Subprogram --
12452 -------------------------
12454 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12455 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12458 -- The internal and external subprograms follow each other on the entity
12459 -- chain. Note that previously private operations had no separate
12460 -- external subprogram. We now create one in all cases, because a
12461 -- private operation may actually appear in an external call, through
12462 -- a 'Access reference used for a callback.
12464 -- If the operation is a function that returns an anonymous access type,
12465 -- the corresponding itype appears before the operation, and must be
12468 -- This mechanism is fragile, there should be a real link between the
12469 -- two versions of the operation, but there is no place to put it ???
12471 if Is_Access_Type
(Next_Entity
(Subp
)) then
12472 return Next_Entity
(Next_Entity
(Subp
));
12474 return Next_Entity
(Subp
);
12476 end External_Subprogram
;
12478 ------------------------------
12479 -- Extract_Dispatching_Call --
12480 ------------------------------
12482 procedure Extract_Dispatching_Call
12484 Call_Ent
: out Entity_Id
;
12485 Object
: out Entity_Id
;
12486 Actuals
: out List_Id
;
12487 Formals
: out List_Id
)
12489 Call_Nam
: Node_Id
;
12492 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12494 if Present
(Original_Node
(N
)) then
12495 Call_Nam
:= Name
(Original_Node
(N
));
12497 Call_Nam
:= Name
(N
);
12500 -- Retrieve the name of the dispatching procedure. It contains the
12501 -- dispatch table slot number.
12504 case Nkind
(Call_Nam
) is
12505 when N_Identifier
=>
12508 when N_Selected_Component
=>
12509 Call_Nam
:= Selector_Name
(Call_Nam
);
12512 raise Program_Error
;
12517 Actuals
:= Parameter_Associations
(N
);
12518 Call_Ent
:= Entity
(Call_Nam
);
12519 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12520 Object
:= First
(Actuals
);
12522 if Present
(Original_Node
(Object
)) then
12523 Object
:= Original_Node
(Object
);
12526 -- If the type of the dispatching object is an access type then return
12527 -- an explicit dereference.
12529 if Is_Access_Type
(Etype
(Object
)) then
12530 Object
:= Make_Explicit_Dereference
(Sloc
(N
), Object
);
12533 end Extract_Dispatching_Call
;
12535 -------------------
12536 -- Extract_Entry --
12537 -------------------
12539 procedure Extract_Entry
12541 Concval
: out Node_Id
;
12542 Ename
: out Node_Id
;
12543 Index
: out Node_Id
)
12545 Nam
: constant Node_Id
:= Name
(N
);
12548 -- For a simple entry, the name is a selected component, with the
12549 -- prefix being the task value, and the selector being the entry.
12551 if Nkind
(Nam
) = N_Selected_Component
then
12552 Concval
:= Prefix
(Nam
);
12553 Ename
:= Selector_Name
(Nam
);
12556 -- For a member of an entry family, the name is an indexed component
12557 -- where the prefix is a selected component, whose prefix in turn is
12558 -- the task value, and whose selector is the entry family. The single
12559 -- expression in the expressions list of the indexed component is the
12560 -- subscript for the family.
12562 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
12563 Concval
:= Prefix
(Prefix
(Nam
));
12564 Ename
:= Selector_Name
(Prefix
(Nam
));
12565 Index
:= First
(Expressions
(Nam
));
12569 -------------------
12570 -- Family_Offset --
12571 -------------------
12573 function Family_Offset
12578 Cap
: Boolean) return Node_Id
12584 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
12585 -- If one of the bounds is a reference to a discriminant, replace with
12586 -- corresponding discriminal of type. Within the body of a task retrieve
12587 -- the renamed discriminant by simple visibility, using its generated
12588 -- name. Within a protected object, find the original discriminant and
12589 -- replace it with the discriminal of the current protected operation.
12591 ------------------------------
12592 -- Convert_Discriminant_Ref --
12593 ------------------------------
12595 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
12596 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
12601 if Is_Entity_Name
(Bound
)
12602 and then Ekind
(Entity
(Bound
)) = E_Discriminant
12604 if Is_Task_Type
(Ttyp
)
12605 and then Has_Completion
(Ttyp
)
12607 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12608 Find_Direct_Name
(B
);
12610 elsif Is_Protected_Type
(Ttyp
) then
12611 D
:= First_Discriminant
(Ttyp
);
12612 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
12613 Next_Discriminant
(D
);
12616 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
12619 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
12622 elsif Nkind
(Bound
) = N_Attribute_Reference
then
12626 B
:= New_Copy_Tree
(Bound
);
12630 Make_Attribute_Reference
(Loc
,
12631 Attribute_Name
=> Name_Pos
,
12632 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
12633 Expressions
=> New_List
(B
));
12634 end Convert_Discriminant_Ref
;
12636 -- Start of processing for Family_Offset
12639 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
12640 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
12643 if Is_Task_Type
(Ttyp
) then
12644 Ityp
:= RTE
(RE_Task_Entry_Index
);
12646 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12650 Make_Attribute_Reference
(Loc
,
12651 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12652 Attribute_Name
=> Name_Min
,
12653 Expressions
=> New_List
(
12655 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
12658 Make_Attribute_Reference
(Loc
,
12659 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12660 Attribute_Name
=> Name_Max
,
12661 Expressions
=> New_List
(
12663 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
12666 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
12673 function Family_Size
12678 Cap
: Boolean) return Node_Id
12683 if Is_Task_Type
(Ttyp
) then
12684 Ityp
:= RTE
(RE_Task_Entry_Index
);
12686 Ityp
:= RTE
(RE_Protected_Entry_Index
);
12690 Make_Attribute_Reference
(Loc
,
12691 Prefix
=> New_Reference_To
(Ityp
, Loc
),
12692 Attribute_Name
=> Name_Max
,
12693 Expressions
=> New_List
(
12696 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
12698 Make_Integer_Literal
(Loc
, 1)),
12699 Make_Integer_Literal
(Loc
, 0)));
12702 ----------------------------
12703 -- Find_Enclosing_Context --
12704 ----------------------------
12706 procedure Find_Enclosing_Context
12708 Context
: out Node_Id
;
12709 Context_Id
: out Entity_Id
;
12710 Context_Decls
: out List_Id
)
12713 -- Traverse the parent chain looking for an enclosing body, block,
12714 -- package or return statement.
12716 Context
:= Parent
(N
);
12717 while not Nkind_In
(Context
, N_Block_Statement
,
12719 N_Extended_Return_Statement
,
12721 N_Package_Declaration
,
12725 Context
:= Parent
(Context
);
12728 -- Extract the constituents of the context
12730 if Nkind
(Context
) = N_Extended_Return_Statement
then
12731 Context_Decls
:= Return_Object_Declarations
(Context
);
12732 Context_Id
:= Return_Statement_Entity
(Context
);
12734 -- Package declarations and bodies use a common library-level activation
12735 -- chain or task master, therefore return the package declaration as the
12736 -- proper carrier for the appropriate flag.
12738 elsif Nkind
(Context
) = N_Package_Body
then
12739 Context_Decls
:= Declarations
(Context
);
12740 Context_Id
:= Corresponding_Spec
(Context
);
12741 Context
:= Parent
(Context_Id
);
12743 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
12744 Context
:= Parent
(Parent
(Context
));
12746 Context
:= Parent
(Context
);
12749 elsif Nkind
(Context
) = N_Package_Declaration
then
12750 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
12751 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12753 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12754 Context_Id
:= Defining_Identifier
(Context_Id
);
12758 Context_Decls
:= Declarations
(Context
);
12760 if Nkind
(Context
) = N_Block_Statement
then
12761 Context_Id
:= Entity
(Identifier
(Context
));
12763 elsif Nkind
(Context
) = N_Entry_Body
then
12764 Context_Id
:= Defining_Identifier
(Context
);
12766 elsif Nkind
(Context
) = N_Subprogram_Body
then
12767 if Present
(Corresponding_Spec
(Context
)) then
12768 Context_Id
:= Corresponding_Spec
(Context
);
12770 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
12772 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
12773 Context_Id
:= Defining_Identifier
(Context_Id
);
12777 elsif Nkind
(Context
) = N_Task_Body
then
12778 Context_Id
:= Corresponding_Spec
(Context
);
12781 raise Program_Error
;
12785 pragma Assert
(Present
(Context
));
12786 pragma Assert
(Present
(Context_Id
));
12787 pragma Assert
(Present
(Context_Decls
));
12788 end Find_Enclosing_Context
;
12790 -----------------------
12791 -- Find_Master_Scope --
12792 -----------------------
12794 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
12798 -- In Ada 2005, the master is the innermost enclosing scope that is not
12799 -- transient. If the enclosing block is the rewriting of a call or the
12800 -- scope is an extended return statement this is valid master. The
12801 -- master in an extended return is only used within the return, and is
12802 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12803 -- now before that overwriting occurs.
12807 if Ada_Version
>= Ada_2005
then
12808 while Is_Internal
(S
) loop
12809 if Nkind
(Parent
(S
)) = N_Block_Statement
12811 Nkind
(Original_Node
(Parent
(S
))) = N_Procedure_Call_Statement
12815 elsif Ekind
(S
) = E_Return_Statement
then
12825 end Find_Master_Scope
;
12827 -------------------------------
12828 -- First_Protected_Operation --
12829 -------------------------------
12831 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
12832 First_Op
: Node_Id
;
12835 First_Op
:= First
(D
);
12836 while Present
(First_Op
)
12837 and then not Nkind_In
(First_Op
, N_Subprogram_Body
, N_Entry_Body
)
12843 end First_Protected_Operation
;
12845 ---------------------------------------
12846 -- Install_Private_Data_Declarations --
12847 ---------------------------------------
12849 procedure Install_Private_Data_Declarations
12851 Spec_Id
: Entity_Id
;
12852 Conc_Typ
: Entity_Id
;
12853 Body_Nod
: Node_Id
;
12855 Barrier
: Boolean := False;
12856 Family
: Boolean := False)
12858 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
12861 Insert_Node
: Node_Id
:= Empty
;
12862 Obj_Ent
: Entity_Id
;
12864 procedure Add
(Decl
: Node_Id
);
12865 -- Add a single declaration after Insert_Node. If this is the first
12866 -- addition, Decl is added to the front of Decls and it becomes the
12869 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
12870 -- The bounds of an entry index may depend on discriminants, create a
12871 -- reference to the corresponding prival. Otherwise return a duplicate
12872 -- of the original bound.
12878 procedure Add
(Decl
: Node_Id
) is
12880 if No
(Insert_Node
) then
12881 Prepend_To
(Decls
, Decl
);
12883 Insert_After
(Insert_Node
, Decl
);
12886 Insert_Node
:= Decl
;
12889 --------------------------
12890 -- Replace_Discriminant --
12891 --------------------------
12893 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
12895 if Nkind
(Bound
) = N_Identifier
12896 and then Is_Discriminal
(Entity
(Bound
))
12898 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
12900 return Duplicate_Subexpr
(Bound
);
12904 -- Start of processing for Install_Private_Data_Declarations
12907 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
12908 -- formal parameter _O, _object or _task depending on the context.
12910 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
12912 -- Special processing of _O for barrier functions, protected entries
12919 (Ekind
(Spec_Id
) = E_Entry
12920 or else Ekind
(Spec_Id
) = E_Entry_Family
))
12923 Conc_Rec
: constant Entity_Id
:=
12924 Corresponding_Record_Type
(Conc_Typ
);
12925 Typ_Id
: constant Entity_Id
:=
12926 Make_Defining_Identifier
(Loc
,
12927 New_External_Name
(Chars
(Conc_Rec
), 'P'));
12930 -- type prot_typVP is access prot_typV;
12933 Make_Full_Type_Declaration
(Loc
,
12934 Defining_Identifier
=> Typ_Id
,
12936 Make_Access_To_Object_Definition
(Loc
,
12937 Subtype_Indication
=>
12938 New_Reference_To
(Conc_Rec
, Loc
)));
12942 -- _object : prot_typVP := prot_typV (_O);
12945 Make_Object_Declaration
(Loc
,
12946 Defining_Identifier
=>
12947 Make_Defining_Identifier
(Loc
, Name_uObject
),
12948 Object_Definition
=> New_Reference_To
(Typ_Id
, Loc
),
12950 Unchecked_Convert_To
(Typ_Id
,
12951 New_Reference_To
(Obj_Ent
, Loc
)));
12954 -- Set the reference to the concurrent object
12956 Obj_Ent
:= Defining_Identifier
(Decl
);
12960 -- Step 2: Create the Protection object and build its declaration for
12961 -- any protected entry (family) of subprogram. Note for the lock-free
12962 -- implementation, the Protection object is not needed anymore.
12964 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
12966 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
12970 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
12972 -- Determine the proper protection type
12974 if Has_Attach_Handler
(Conc_Typ
)
12975 and then not Restricted_Profile
12976 and then not Restriction_Active
(No_Dynamic_Attachment
)
12978 Prot_Typ
:= RE_Static_Interrupt_Protection
;
12980 elsif Has_Interrupt_Handler
(Conc_Typ
)
12981 and then not Restriction_Active
(No_Dynamic_Attachment
)
12983 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
12985 -- The type has explicit entries or generated primitive entry
12988 elsif Has_Entries
(Conc_Typ
)
12990 (Ada_Version
>= Ada_2005
12991 and then Present
(Interface_List
(Parent
(Conc_Typ
))))
12993 case Corresponding_Runtime_Package
(Conc_Typ
) is
12994 when System_Tasking_Protected_Objects_Entries
=>
12995 Prot_Typ
:= RE_Protection_Entries
;
12997 when System_Tasking_Protected_Objects_Single_Entry
=>
12998 Prot_Typ
:= RE_Protection_Entry
;
13001 raise Program_Error
;
13005 Prot_Typ
:= RE_Protection
;
13009 -- conc_typR : protection_typ renames _object._object;
13012 Make_Object_Renaming_Declaration
(Loc
,
13013 Defining_Identifier
=> Prot_Ent
,
13015 New_Reference_To
(RTE
(Prot_Typ
), Loc
),
13017 Make_Selected_Component
(Loc
,
13018 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13019 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13024 -- Step 3: Add discriminant renamings (if any)
13026 if Has_Discriminants
(Conc_Typ
) then
13031 D
:= First_Discriminant
(Conc_Typ
);
13032 while Present
(D
) loop
13034 -- Adjust the source location
13036 Set_Sloc
(Discriminal
(D
), Loc
);
13039 -- discr_name : discr_typ renames _object.discr_name;
13041 -- discr_name : discr_typ renames _task.discr_name;
13044 Make_Object_Renaming_Declaration
(Loc
,
13045 Defining_Identifier
=> Discriminal
(D
),
13046 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
13048 Make_Selected_Component
(Loc
,
13049 Prefix
=> New_Reference_To
(Obj_Ent
, Loc
),
13050 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13053 Next_Discriminant
(D
);
13058 -- Step 4: Add private component renamings (if any)
13060 if Is_Protected
then
13061 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13063 if Present
(Private_Declarations
(Def
)) then
13066 Comp_Id
: Entity_Id
;
13067 Decl_Id
: Entity_Id
;
13070 Comp
:= First
(Private_Declarations
(Def
));
13071 while Present
(Comp
) loop
13072 if Nkind
(Comp
) = N_Component_Declaration
then
13073 Comp_Id
:= Defining_Identifier
(Comp
);
13075 Make_Defining_Identifier
(Loc
, Chars
(Comp_Id
));
13077 -- Minimal decoration
13079 if Ekind
(Spec_Id
) = E_Function
then
13080 Set_Ekind
(Decl_Id
, E_Constant
);
13082 Set_Ekind
(Decl_Id
, E_Variable
);
13085 Set_Prival
(Comp_Id
, Decl_Id
);
13086 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13087 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13090 -- comp_name : comp_typ renames _object.comp_name;
13093 Make_Object_Renaming_Declaration
(Loc
,
13094 Defining_Identifier
=> Decl_Id
,
13096 New_Reference_To
(Etype
(Comp_Id
), Loc
),
13098 Make_Selected_Component
(Loc
,
13100 New_Reference_To
(Obj_Ent
, Loc
),
13102 Make_Identifier
(Loc
, Chars
(Comp_Id
))));
13112 -- Step 5: Add the declaration of the entry index and the associated
13113 -- type for barrier functions and entry families.
13115 if (Barrier
and then Family
)
13116 or else Ekind
(Spec_Id
) = E_Entry_Family
13119 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13120 Index
: constant Entity_Id
:=
13121 Defining_Identifier
(
13122 Entry_Index_Specification
(
13123 Entry_Body_Formal_Part
(Body_Nod
)));
13124 Index_Con
: constant Entity_Id
:=
13125 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13127 Index_Typ
: Entity_Id
;
13131 -- Minimal decoration
13133 Set_Ekind
(Index_Con
, E_Constant
);
13134 Set_Entry_Index_Constant
(Index
, Index_Con
);
13135 Set_Discriminal_Link
(Index_Con
, Index
);
13137 -- Retrieve the bounds of the entry family
13139 High
:= Type_High_Bound
(Etype
(Index
));
13140 Low
:= Type_Low_Bound
(Etype
(Index
));
13142 -- In the simple case the entry family is given by a subtype
13143 -- mark and the index constant has the same type.
13145 if Is_Entity_Name
(Original_Node
(
13146 Discrete_Subtype_Definition
(Parent
(Index
))))
13148 Index_Typ
:= Etype
(Index
);
13150 -- Otherwise a new subtype declaration is required
13153 High
:= Replace_Bound
(High
);
13154 Low
:= Replace_Bound
(Low
);
13156 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13159 -- subtype Jnn is <Etype of Index> range Low .. High;
13162 Make_Subtype_Declaration
(Loc
,
13163 Defining_Identifier
=> Index_Typ
,
13164 Subtype_Indication
=>
13165 Make_Subtype_Indication
(Loc
,
13167 New_Reference_To
(Base_Type
(Etype
(Index
)), Loc
),
13169 Make_Range_Constraint
(Loc
,
13170 Range_Expression
=>
13171 Make_Range
(Loc
, Low
, High
))));
13175 Set_Etype
(Index_Con
, Index_Typ
);
13177 -- Create the object which designates the index:
13178 -- J : constant Jnn :=
13179 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13181 -- where Jnn is the subtype created above or the original type of
13182 -- the index, _E is a formal of the protected body subprogram and
13183 -- <index expr> is the index of the first family member.
13186 Make_Object_Declaration
(Loc
,
13187 Defining_Identifier
=> Index_Con
,
13188 Constant_Present
=> True,
13189 Object_Definition
=>
13190 New_Reference_To
(Index_Typ
, Loc
),
13193 Make_Attribute_Reference
(Loc
,
13195 New_Reference_To
(Index_Typ
, Loc
),
13196 Attribute_Name
=> Name_Val
,
13198 Expressions
=> New_List
(
13202 Make_Op_Subtract
(Loc
,
13204 New_Reference_To
(E
, Loc
),
13206 Entry_Index_Expression
(Loc
,
13207 Defining_Identifier
(Body_Nod
),
13211 Make_Attribute_Reference
(Loc
,
13213 New_Reference_To
(Index_Typ
, Loc
),
13214 Attribute_Name
=> Name_Pos
,
13215 Expressions
=> New_List
(
13216 Make_Attribute_Reference
(Loc
,
13218 New_Reference_To
(Index_Typ
, Loc
),
13219 Attribute_Name
=> Name_First
)))))));
13223 end Install_Private_Data_Declarations
;
13225 -----------------------
13226 -- Is_Exception_Safe --
13227 -----------------------
13229 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
13231 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
13232 -- Return True whenever encountering a subprogram call or raise
13233 -- statement of any kind in the sequence of statements
13235 ---------------------
13236 -- Has_Side_Effect --
13237 ---------------------
13239 -- What is this doing buried two levels down in exp_ch9. It seems like a
13240 -- generally useful function, and indeed there may be code duplication
13241 -- going on here ???
13243 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
13247 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
13248 -- Indicate whether N is a subprogram call or a raise statement
13250 ----------------------
13251 -- Is_Call_Or_Raise --
13252 ----------------------
13254 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
13256 return Nkind_In
(N
, N_Procedure_Call_Statement
,
13259 N_Raise_Constraint_Error
,
13260 N_Raise_Program_Error
,
13261 N_Raise_Storage_Error
);
13262 end Is_Call_Or_Raise
;
13264 -- Start of processing for Has_Side_Effect
13268 while Present
(Stmt
) loop
13269 if Is_Call_Or_Raise
(Stmt
) then
13273 -- An object declaration can also contain a function call or a
13274 -- raise statement.
13276 if Nkind
(Stmt
) = N_Object_Declaration
then
13277 Expr
:= Expression
(Stmt
);
13279 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
13288 end Has_Side_Effect
;
13290 -- Start of processing for Is_Exception_Safe
13293 -- If the checks handled by the back end are not disabled, we cannot
13294 -- ensure that no exception will be raised.
13296 if not Access_Checks_Suppressed
(Empty
)
13297 or else not Discriminant_Checks_Suppressed
(Empty
)
13298 or else not Range_Checks_Suppressed
(Empty
)
13299 or else not Index_Checks_Suppressed
(Empty
)
13300 or else Opt
.Stack_Checking_Enabled
13305 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
13308 (First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
13314 end Is_Exception_Safe
;
13316 ---------------------------------
13317 -- Is_Potentially_Large_Family --
13318 ---------------------------------
13320 function Is_Potentially_Large_Family
13321 (Base_Index
: Entity_Id
;
13322 Conctyp
: Entity_Id
;
13324 Hi
: Node_Id
) return Boolean
13327 return Scope
(Base_Index
) = Standard_Standard
13328 and then Base_Index
= Base_Type
(Standard_Integer
)
13329 and then Has_Discriminants
(Conctyp
)
13331 Present
(Discriminant_Default_Value
(First_Discriminant
(Conctyp
)))
13333 (Denotes_Discriminant
(Lo
, True)
13335 Denotes_Discriminant
(Hi
, True));
13336 end Is_Potentially_Large_Family
;
13338 -------------------------------------
13339 -- Is_Private_Primitive_Subprogram --
13340 -------------------------------------
13342 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13345 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13346 and then Is_Private_Primitive
(Id
);
13347 end Is_Private_Primitive_Subprogram
;
13353 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13354 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13355 Formal
: Entity_Id
;
13358 Formal
:= First_Formal
(Bod_Subp
);
13359 while Present
(Formal
) loop
13361 -- Look for formal parameter _E
13363 if Chars
(Formal
) = Name_uE
then
13367 Next_Formal
(Formal
);
13370 -- A protected body subprogram should always have the parameter in
13373 raise Program_Error
;
13376 --------------------------------
13377 -- Make_Initialize_Protection --
13378 --------------------------------
13380 function Make_Initialize_Protection
13381 (Protect_Rec
: Entity_Id
) return List_Id
13383 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13386 Ptyp
: constant Node_Id
:=
13387 Corresponding_Concurrent_Type
(Protect_Rec
);
13389 L
: constant List_Id
:= New_List
;
13390 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13391 Restricted
: constant Boolean := Restricted_Profile
;
13394 -- We may need two calls to properly initialize the object, one to
13395 -- Initialize_Protection, and possibly one to Install_Handlers if we
13396 -- have a pragma Attach_Handler.
13398 -- Get protected declaration. In the case of a task type declaration,
13399 -- this is simply the parent of the protected type entity. In the single
13400 -- protected object declaration, this parent will be the implicit type,
13401 -- and we can find the corresponding single protected object declaration
13402 -- by searching forward in the declaration list in the tree.
13404 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13405 -- of this type should have been removed during semantic analysis.
13407 Pdec
:= Parent
(Ptyp
);
13408 while not Nkind_In
(Pdec
, N_Protected_Type_Declaration
,
13409 N_Single_Protected_Declaration
)
13414 -- Build the parameter list for the call. Note that _Init is the name
13415 -- of the formal for the object to be initialized, which is the task
13416 -- value record itself.
13420 -- For lock-free implementation, skip initializations of the Protection
13423 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13424 -- Object parameter. This is a pointer to the object of type
13425 -- Protection used by the GNARL to control the protected object.
13428 Make_Attribute_Reference
(Loc
,
13430 Make_Selected_Component
(Loc
,
13431 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13432 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13433 Attribute_Name
=> Name_Unchecked_Access
));
13435 -- Priority parameter. Set to Unspecified_Priority unless there is a
13436 -- Priority rep item, in which case we take the value from the pragma
13437 -- or attribute definition clause, or there is an Interrupt_Priority
13438 -- rep item and no Priority rep item, and we set the ceiling to
13439 -- Interrupt_Priority'Last, an implementation-defined value, see
13442 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13444 Prio_Clause
: constant Node_Id
:=
13446 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13454 if Nkind
(Prio_Clause
) = N_Pragma
then
13457 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13459 -- Attribute definition clause Priority
13462 Prio
:= Expression
(Prio_Clause
);
13465 -- If priority is a static expression, then we can duplicate it
13466 -- with no problem and simply append it to the argument list.
13468 if Is_Static_Expression
(Prio
) then
13470 Duplicate_Subexpr_No_Checks
(Prio
));
13472 -- Otherwise, the priority may be a per-object expression, if
13473 -- it depends on a discriminant of the type. In this case,
13474 -- create local variable to capture the expression. Note that
13475 -- it is really necessary to create this variable explicitly.
13476 -- It might be thought that removing side effects would the
13477 -- appropriate approach, but that could generate declarations
13478 -- improperly placed in the enclosing scope.
13480 -- Note: Use System.Any_Priority as the expected type for the
13481 -- non-static priority expression, in case the expression has
13482 -- not been analyzed yet (as occurs for example with pragma
13483 -- Interrupt_Priority).
13486 Temp
:= Make_Temporary
(Loc
, 'R', Prio
);
13488 Make_Object_Declaration
(Loc
,
13489 Defining_Identifier
=> Temp
,
13490 Object_Definition
=>
13491 New_Occurrence_Of
(RTE
(RE_Any_Priority
), Loc
),
13492 Expression
=> Relocate_Node
(Prio
)));
13494 Append_To
(Args
, New_Occurrence_Of
(Temp
, Loc
));
13498 -- When no priority is specified but an xx_Handler pragma is, we
13499 -- default to System.Interrupts.Default_Interrupt_Priority, see
13502 elsif Has_Attach_Handler
(Ptyp
)
13503 or else Has_Interrupt_Handler
(Ptyp
)
13506 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13508 -- Normal case, no priority or xx_Handler specified, default priority
13512 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13515 -- Test for Compiler_Info parameter. This parameter allows entry body
13516 -- procedures and barrier functions to be called from the runtime. It
13517 -- is a pointer to the record generated by the compiler to represent
13518 -- the protected object.
13520 -- A protected type without entries that covers an interface and
13521 -- overrides the abstract routines with protected procedures is
13522 -- considered equivalent to a protected type with entries in the
13523 -- context of dispatching select statements.
13526 or else Has_Interfaces
(Protect_Rec
)
13528 ((Has_Attach_Handler
(Ptyp
) or else Has_Interrupt_Handler
(Ptyp
))
13529 and then not Restriction_Active
(No_Dynamic_Attachment
))
13532 Pkg_Id
: constant RTU_Id
:=
13533 Corresponding_Runtime_Package
(Ptyp
);
13535 Called_Subp
: RE_Id
;
13539 when System_Tasking_Protected_Objects_Entries
=>
13540 Called_Subp
:= RE_Initialize_Protection_Entries
;
13542 when System_Tasking_Protected_Objects
=>
13543 Called_Subp
:= RE_Initialize_Protection
;
13545 when System_Tasking_Protected_Objects_Single_Entry
=>
13546 Called_Subp
:= RE_Initialize_Protection_Entry
;
13549 raise Program_Error
;
13553 or else not Restricted
13554 or else Has_Interfaces
(Protect_Rec
)
13557 Make_Attribute_Reference
(Loc
,
13558 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13559 Attribute_Name
=> Name_Address
));
13562 -- Entry_Bodies parameter. This is a pointer to an array of
13563 -- pointers to the entry body procedures and barrier functions
13564 -- of the object. If the protected type has no entries this
13565 -- object will not exist, in this case, pass a null.
13568 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
13571 Make_Attribute_Reference
(Loc
,
13572 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13573 Attribute_Name
=> Name_Unrestricted_Access
));
13575 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13577 -- Find index mapping function (clumsy but ok for now)
13579 while Ekind
(P_Arr
) /= E_Function
loop
13580 Next_Entity
(P_Arr
);
13584 Make_Attribute_Reference
(Loc
,
13585 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
13586 Attribute_Name
=> Name_Unrestricted_Access
));
13590 System_Tasking_Protected_Objects_Single_Entry
13592 Append_To
(Args
, Make_Null
(Loc
));
13594 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
13595 Append_To
(Args
, Make_Null
(Loc
));
13596 Append_To
(Args
, Make_Null
(Loc
));
13600 Make_Procedure_Call_Statement
(Loc
,
13601 Name
=> New_Reference_To
(RTE
(Called_Subp
), Loc
),
13602 Parameter_Associations
=> Args
));
13606 Make_Procedure_Call_Statement
(Loc
,
13607 Name
=> New_Reference_To
(RTE
(RE_Initialize_Protection
), Loc
),
13608 Parameter_Associations
=> Args
));
13612 if Has_Attach_Handler
(Ptyp
) then
13614 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13615 -- make the following call:
13617 -- Install_Handlers (_object,
13618 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13620 -- or, in the case of Ravenscar:
13622 -- Install_Restricted_Handlers
13623 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13626 Args
: constant List_Id
:= New_List
;
13627 Table
: constant List_Id
:= New_List
;
13628 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
13631 -- Build the Attach_Handler table argument
13633 while Present
(Ritem
) loop
13634 if Nkind
(Ritem
) = N_Pragma
13635 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
13638 Handler
: constant Node_Id
:=
13639 First
(Pragma_Argument_Associations
(Ritem
));
13641 Interrupt
: constant Node_Id
:= Next
(Handler
);
13642 Expr
: constant Node_Id
:= Expression
(Interrupt
);
13646 Make_Aggregate
(Loc
, Expressions
=> New_List
(
13647 Unchecked_Convert_To
13648 (RTE
(RE_System_Interrupt_Id
), Expr
),
13649 Make_Attribute_Reference
(Loc
,
13650 Prefix
=> Make_Selected_Component
(Loc
,
13651 Make_Identifier
(Loc
, Name_uInit
),
13652 Duplicate_Subexpr_No_Checks
13653 (Expression
(Handler
))),
13654 Attribute_Name
=> Name_Access
))));
13658 Next_Rep_Item
(Ritem
);
13661 -- Append the table argument we just built
13663 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
13665 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13666 -- call to the statements.
13669 -- Call a simplified version of Install_Handlers to be used
13670 -- when the Ravenscar restrictions are in effect
13671 -- (Install_Restricted_Handlers).
13674 Make_Procedure_Call_Statement
(Loc
,
13677 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
13678 Parameter_Associations
=> Args
));
13681 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13682 -- First, prepends the _object argument
13685 Make_Attribute_Reference
(Loc
,
13687 Make_Selected_Component
(Loc
,
13688 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13690 Make_Identifier
(Loc
, Name_uObject
)),
13691 Attribute_Name
=> Name_Unchecked_Access
));
13694 -- Then, insert call to Install_Handlers
13697 Make_Procedure_Call_Statement
(Loc
,
13698 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
13699 Parameter_Associations
=> Args
));
13705 end Make_Initialize_Protection
;
13707 ---------------------------
13708 -- Make_Task_Create_Call --
13709 ---------------------------
13711 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
13712 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
13722 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
13723 Tnam
:= Chars
(Ttyp
);
13725 -- Get task declaration. In the case of a task type declaration, this is
13726 -- simply the parent of the task type entity. In the single task
13727 -- declaration, this parent will be the implicit type, and we can find
13728 -- the corresponding single task declaration by searching forward in the
13729 -- declaration list in the tree.
13731 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13732 -- this type should have been removed during semantic analysis.
13734 Tdec
:= Parent
(Ttyp
);
13735 while not Nkind_In
(Tdec
, N_Task_Type_Declaration
,
13736 N_Single_Task_Declaration
)
13741 -- Now we can find the task definition from this declaration
13743 Tdef
:= Task_Definition
(Tdec
);
13745 -- Build the parameter list for the call. Note that _Init is the name
13746 -- of the formal for the object to be initialized, which is the task
13747 -- value record itself.
13751 -- Priority parameter. Set to Unspecified_Priority unless there is a
13752 -- Priority rep item, in which case we take the value from the rep item.
13754 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
13756 Make_Selected_Component
(Loc
,
13757 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13758 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
13761 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
13764 -- Optional Stack parameter
13766 if Restricted_Profile
then
13768 -- If the stack has been preallocated by the expander then
13769 -- pass its address. Otherwise, pass a null address.
13771 if Preallocated_Stacks_On_Target
then
13773 Make_Attribute_Reference
(Loc
,
13775 Make_Selected_Component
(Loc
,
13776 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13777 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
13778 Attribute_Name
=> Name_Address
));
13782 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
13786 -- Size parameter. If no Storage_Size pragma is present, then
13787 -- the size is taken from the taskZ variable for the type, which
13788 -- is either Unspecified_Size, or has been reset by the use of
13789 -- a Storage_Size attribute definition clause. If a pragma is
13790 -- present, then the size is taken from the _Size field of the
13791 -- task value record, which was set from the pragma value.
13794 and then Has_Storage_Size_Pragma
(Tdef
)
13797 Make_Selected_Component
(Loc
,
13798 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13799 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
13803 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
13806 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
13807 -- Task_Info pragma, in which case we take the value from the pragma.
13809 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
13811 Make_Selected_Component
(Loc
,
13812 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13813 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
13817 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
13820 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
13821 -- in which case we take the value from the rep item. The parameter is
13822 -- passed as an Integer because in the case of unspecified CPU the
13823 -- value is not in the range of CPU_Range.
13825 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
13827 Convert_To
(Standard_Integer
,
13828 Make_Selected_Component
(Loc
,
13829 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13830 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
13833 New_Reference_To
(RTE
(RE_Unspecified_CPU
), Loc
));
13836 if not Restricted_Profile
then
13838 -- Deadline parameter. If no Relative_Deadline pragma is present,
13839 -- then the deadline is Time_Span_Zero. If a pragma is present, then
13840 -- the deadline is taken from the _Relative_Deadline field of the
13841 -- task value record, which was set from the pragma value. Note that
13842 -- this parameter must not be generated for the restricted profiles
13843 -- since Ravenscar does not allow deadlines.
13845 -- Case where pragma Relative_Deadline applies: use given value
13848 and then Has_Relative_Deadline_Pragma
(Tdef
)
13851 Make_Selected_Component
(Loc
,
13853 Make_Identifier
(Loc
, Name_uInit
),
13855 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
13857 -- No pragma Relative_Deadline apply to the task
13861 New_Reference_To
(RTE
(RE_Time_Span_Zero
), Loc
));
13864 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
13865 -- present, then the dispatching domain is null. If a rep item is
13866 -- present, then the dispatching domain is taken from the
13867 -- _Dispatching_Domain field of the task value record, which was set
13868 -- from the rep item value. Note that this parameter must not be
13869 -- generated for the restricted profiles since Ravenscar does not
13870 -- allow dispatching domains.
13872 -- Case where Dispatching_Domain rep item applies: use given value
13875 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
13878 Make_Selected_Component
(Loc
,
13880 Make_Identifier
(Loc
, Name_uInit
),
13882 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
13884 -- No pragma or aspect Dispatching_Domain apply to the task
13887 Append_To
(Args
, Make_Null
(Loc
));
13890 -- Number of entries. This is an expression of the form:
13892 -- n + _Init.a'Length + _Init.a'B'Length + ...
13894 -- where a,b... are the entry family names for the task definition
13897 Build_Entry_Count_Expression
13902 (Parent
(Corresponding_Record_Type
(Ttyp
))))),
13904 Append_To
(Args
, Ecount
);
13906 -- Master parameter. This is a reference to the _Master parameter of
13907 -- the initialization procedure, except in the case of the pragma
13908 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
13909 -- System.Tasking.Library_Task_Level.
13911 if Restriction_Active
(No_Task_Hierarchy
) = False then
13912 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
13915 New_Occurrence_Of
(RTE
(RE_Library_Task_Level
), Loc
));
13919 -- State parameter. This is a pointer to the task body procedure. The
13920 -- required value is obtained by taking 'Unrestricted_Access of the task
13921 -- body procedure and converting it (with an unchecked conversion) to
13922 -- the type required by the task kernel. For further details, see the
13923 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
13924 -- than 'Address in order to avoid creating trampolines.
13927 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
13928 Subp_Ptr_Typ
: constant Node_Id
:=
13929 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
13930 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
13933 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
13934 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
13936 -- Be sure to freeze a reference to the access-to-subprogram type,
13937 -- otherwise gigi will complain that it's in the wrong scope, because
13938 -- it's actually inside the init procedure for the record type that
13939 -- corresponds to the task type.
13941 -- This processing is causing a crash in the .NET/JVM back ends that
13942 -- is not yet understood, so skip it in these cases ???
13944 if VM_Target
= No_VM
then
13945 Set_Itype
(Ref
, Subp_Ptr_Typ
);
13946 Append_Freeze_Action
(Task_Rec
, Ref
);
13949 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
13950 Make_Qualified_Expression
(Loc
,
13951 Subtype_Mark
=> New_Reference_To
(Subp_Ptr_Typ
, Loc
),
13953 Make_Attribute_Reference
(Loc
,
13955 New_Occurrence_Of
(Body_Proc
, Loc
),
13956 Attribute_Name
=> Name_Unrestricted_Access
))));
13958 -- For the .NET/JVM cases revert to the original code below ???
13962 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
13963 Make_Attribute_Reference
(Loc
,
13965 New_Occurrence_Of
(Body_Proc
, Loc
),
13966 Attribute_Name
=> Name_Address
)));
13970 -- Discriminants parameter. This is just the address of the task
13971 -- value record itself (which contains the discriminant values
13974 Make_Attribute_Reference
(Loc
,
13975 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13976 Attribute_Name
=> Name_Address
));
13978 -- Elaborated parameter. This is an access to the elaboration Boolean
13981 Make_Attribute_Reference
(Loc
,
13982 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
13983 Attribute_Name
=> Name_Unchecked_Access
));
13985 -- Add Chain parameter (not done for sequential elaboration policy, see
13986 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
13988 if Partition_Elaboration_Policy
/= 'S' then
13989 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
13992 -- Task name parameter. Take this from the _Task_Id parameter to the
13993 -- init call unless there is a Task_Name pragma, in which case we take
13994 -- the value from the pragma.
13996 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
13997 -- Copy expression in full, because it may be dynamic and have
14004 (Pragma_Argument_Associations
14006 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14009 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14012 -- Created_Task parameter. This is the _Task_Id field of the task
14016 Make_Selected_Component
(Loc
,
14017 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14018 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14024 if Restricted_Profile
then
14025 if Partition_Elaboration_Policy
= 'S' then
14026 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14028 Create_RE
:= RE_Create_Restricted_Task
;
14031 Create_RE
:= RE_Create_Task
;
14034 Name
:= New_Reference_To
(RTE
(Create_RE
), Loc
);
14038 Make_Procedure_Call_Statement
(Loc
,
14040 Parameter_Associations
=> Args
);
14041 end Make_Task_Create_Call
;
14043 ------------------------------
14044 -- Next_Protected_Operation --
14045 ------------------------------
14047 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14051 Next_Op
:= Next
(N
);
14052 while Present
(Next_Op
)
14053 and then not Nkind_In
(Next_Op
, N_Subprogram_Body
, N_Entry_Body
)
14059 end Next_Protected_Operation
;
14061 ---------------------
14062 -- Null_Statements --
14063 ---------------------
14065 function Null_Statements
(Stats
: List_Id
) return Boolean is
14069 Stmt
:= First
(Stats
);
14070 while Nkind
(Stmt
) /= N_Empty
14071 and then (Nkind_In
(Stmt
, N_Null_Statement
, N_Label
)
14073 (Nkind
(Stmt
) = N_Pragma
14074 and then (Pragma_Name
(Stmt
) = Name_Unreferenced
14076 Pragma_Name
(Stmt
) = Name_Unmodified
14078 Pragma_Name
(Stmt
) = Name_Warnings
)))
14083 return Nkind
(Stmt
) = N_Empty
;
14084 end Null_Statements
;
14086 --------------------------
14087 -- Parameter_Block_Pack --
14088 --------------------------
14090 function Parameter_Block_Pack
14092 Blk_Typ
: Entity_Id
;
14096 Stmts
: List_Id
) return Node_Id
14098 Actual
: Entity_Id
;
14099 Expr
: Node_Id
:= Empty
;
14100 Formal
: Entity_Id
;
14101 Has_Param
: Boolean := False;
14104 Temp_Asn
: Node_Id
;
14105 Temp_Nam
: Node_Id
;
14108 Actual
:= First
(Actuals
);
14109 Formal
:= Defining_Identifier
(First
(Formals
));
14110 Params
:= New_List
;
14112 while Present
(Actual
) loop
14113 if Is_By_Copy_Type
(Etype
(Actual
)) then
14115 -- Jnn : aliased <formal-type>
14117 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14120 Make_Object_Declaration
(Loc
,
14123 Defining_Identifier
=>
14125 Object_Definition
=>
14126 New_Reference_To
(Etype
(Formal
), Loc
)));
14128 if Ekind
(Formal
) /= E_Out_Parameter
then
14134 New_Reference_To
(Temp_Nam
, Loc
);
14136 Set_Assignment_OK
(Temp_Asn
);
14139 Make_Assignment_Statement
(Loc
,
14143 New_Copy_Tree
(Actual
)));
14147 -- Jnn'unchecked_access
14150 Make_Attribute_Reference
(Loc
,
14152 Name_Unchecked_Access
,
14154 New_Reference_To
(Temp_Nam
, Loc
)));
14158 -- The controlling parameter is omitted
14161 if not Is_Controlling_Actual
(Actual
) then
14163 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14169 Next_Actual
(Actual
);
14170 Next_Formal_With_Extras
(Formal
);
14174 Expr
:= Make_Aggregate
(Loc
, Params
);
14179 -- J1'unchecked_access;
14180 -- <actual2>'reference;
14183 P
:= Make_Temporary
(Loc
, 'P');
14186 Make_Object_Declaration
(Loc
,
14187 Defining_Identifier
=>
14189 Object_Definition
=>
14190 New_Reference_To
(Blk_Typ
, Loc
),
14195 end Parameter_Block_Pack
;
14197 ----------------------------
14198 -- Parameter_Block_Unpack --
14199 ----------------------------
14201 function Parameter_Block_Unpack
14205 Formals
: List_Id
) return List_Id
14207 Actual
: Entity_Id
;
14209 Formal
: Entity_Id
;
14210 Has_Asnmt
: Boolean := False;
14211 Result
: constant List_Id
:= New_List
;
14214 Actual
:= First
(Actuals
);
14215 Formal
:= Defining_Identifier
(First
(Formals
));
14216 while Present
(Actual
) loop
14217 if Is_By_Copy_Type
(Etype
(Actual
))
14218 and then Ekind
(Formal
) /= E_In_Parameter
14221 -- <actual> := P.<formal>;
14224 Make_Assignment_Statement
(Loc
,
14228 Make_Explicit_Dereference
(Loc
,
14229 Make_Selected_Component
(Loc
,
14231 New_Reference_To
(P
, Loc
),
14233 Make_Identifier
(Loc
, Chars
(Formal
)))));
14235 Set_Assignment_OK
(Name
(Asnmt
));
14236 Append_To
(Result
, Asnmt
);
14241 Next_Actual
(Actual
);
14242 Next_Formal_With_Extras
(Formal
);
14248 return New_List
(Make_Null_Statement
(Loc
));
14250 end Parameter_Block_Unpack
;
14252 ----------------------
14253 -- Set_Discriminals --
14254 ----------------------
14256 procedure Set_Discriminals
(Dec
: Node_Id
) is
14259 D_Minal
: Entity_Id
;
14262 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14263 Pdef
:= Defining_Identifier
(Dec
);
14265 if Has_Discriminants
(Pdef
) then
14266 D
:= First_Discriminant
(Pdef
);
14267 while Present
(D
) loop
14269 Make_Defining_Identifier
(Sloc
(D
),
14270 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14272 Set_Ekind
(D_Minal
, E_Constant
);
14273 Set_Etype
(D_Minal
, Etype
(D
));
14274 Set_Scope
(D_Minal
, Pdef
);
14275 Set_Discriminal
(D
, D_Minal
);
14276 Set_Discriminal_Link
(D_Minal
, D
);
14278 Next_Discriminant
(D
);
14281 end Set_Discriminals
;
14283 -----------------------
14284 -- Trivial_Accept_OK --
14285 -----------------------
14287 function Trivial_Accept_OK
return Boolean is
14289 case Opt
.Task_Dispatching_Policy
is
14291 -- If we have the default task dispatching policy in effect, we can
14292 -- definitely do the optimization (one way of looking at this is to
14293 -- think of the formal definition of the default policy being allowed
14294 -- to run any task it likes after a rendezvous, so even if notionally
14295 -- a full rescheduling occurs, we can say that our dispatching policy
14296 -- (i.e. the default dispatching policy) reorders the queue to be the
14297 -- same as just before the call.
14302 -- FIFO_Within_Priorities certainly does not permit this
14303 -- optimization since the Rendezvous is a scheduling action that may
14304 -- require some other task to be run.
14309 -- For now, disallow the optimization for all other policies. This
14310 -- may be over-conservative, but it is certainly not incorrect.
14316 end Trivial_Accept_OK
;