1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Atree
; use Atree
;
28 with Aspects
; use Aspects
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Einfo
; use Einfo
;
32 with Einfo
.Entities
; use Einfo
.Entities
;
33 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Elists
; use Elists
;
35 with Errout
; use Errout
;
36 with Exp_Ch3
; use Exp_Ch3
;
37 with Exp_Ch6
; use Exp_Ch6
;
38 with Exp_Ch11
; use Exp_Ch11
;
39 with Exp_Dbug
; use Exp_Dbug
;
40 with Exp_Sel
; use Exp_Sel
;
41 with Exp_Smem
; use Exp_Smem
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Freeze
; use Freeze
;
46 with Itypes
; use Itypes
;
47 with Namet
; use Namet
;
48 with Nlists
; use Nlists
;
49 with Nmake
; use Nmake
;
51 with Restrict
; use Restrict
;
52 with Rident
; use Rident
;
53 with Rtsfind
; use Rtsfind
;
55 with Sem_Aux
; use Sem_Aux
;
56 with Sem_Ch5
; use Sem_Ch5
;
57 with Sem_Ch6
; use Sem_Ch6
;
58 with Sem_Ch8
; use Sem_Ch8
;
59 with Sem_Ch9
; use Sem_Ch9
;
60 with Sem_Ch11
; use Sem_Ch11
;
61 with Sem_Ch13
; use Sem_Ch13
;
62 with Sem_Elab
; use Sem_Elab
;
63 with Sem_Eval
; use Sem_Eval
;
64 with Sem_Res
; use Sem_Res
;
65 with Sem_Util
; use Sem_Util
;
66 with Sinfo
; use Sinfo
;
67 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
68 with Sinfo
.Utils
; use Sinfo
.Utils
;
69 with Snames
; use Snames
;
70 with Stand
; use Stand
;
71 with Targparm
; use Targparm
;
72 with Tbuild
; use Tbuild
;
73 with Uintp
; use Uintp
;
74 with Validsw
; use Validsw
;
76 package body Exp_Ch9
is
78 -- The following constant establishes the upper bound for the index of
79 -- an entry family. It is used to limit the allocated size of protected
80 -- types with defaulted discriminant of an integer type, when the bound
81 -- of some entry family depends on a discriminant. The limitation to entry
82 -- families of 128K should be reasonable in all cases, and is a documented
83 -- implementation restriction.
85 Entry_Family_Bound
: constant Pos
:= 2**16;
87 -----------------------
88 -- Local Subprograms --
89 -----------------------
91 function Actual_Index_Expression
95 Tsk
: Entity_Id
) return Node_Id
;
96 -- Compute the index position for an entry call. Tsk is the target task. If
97 -- the bounds of some entry family depend on discriminants, the expression
98 -- computed by this function uses the discriminants of the target task.
100 procedure Add_Object_Pointer
102 Conc_Typ
: Entity_Id
;
104 -- Prepend an object pointer declaration to the declaration list Decls.
105 -- This object pointer is initialized to a type conversion of the System.
106 -- Address pointer passed to entry barrier functions and entry body
109 procedure Add_Formal_Renamings
114 -- Create renaming declarations for the formals, inside the procedure that
115 -- implements an entry body. The renamings make the original names of the
116 -- formals accessible to gdb, and serve no other purpose.
117 -- Spec is the specification of the procedure being built.
118 -- Decls is the list of declarations to be enhanced.
119 -- Ent is the entity for the original entry body.
121 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
122 -- Transform accept statement into a block with added exception handler.
123 -- Used both for simple accept statements and for accept alternatives in
124 -- select statements. Astat is the accept statement.
126 function Build_Barrier_Function
129 Pid
: Entity_Id
) return Node_Id
;
130 -- Build the function body returning the value of the barrier expression
131 -- for the specified entry body.
133 function Build_Barrier_Function_Specification
135 Def_Id
: Entity_Id
) return Node_Id
;
136 -- Build a specification for a function implementing the protected entry
137 -- barrier of the specified entry body.
139 function Build_Corresponding_Record
142 Loc
: Source_Ptr
) return Node_Id
;
143 -- Common to tasks and protected types. Copy discriminant specifications,
144 -- build record declaration. N is the type declaration, Ctyp is the
145 -- concurrent entity (task type or protected type).
147 function Build_Dispatching_Tag_Check
149 N
: Node_Id
) return Node_Id
;
150 -- Utility to create the tree to check whether the dispatching call in
151 -- a timed entry call, a conditional entry call, or an asynchronous
152 -- transfer of control is a call to a primitive of a non-synchronized type.
153 -- K is the temporary that holds the tagged kind of the target object, and
154 -- N is the enclosing construct.
156 function Build_Entry_Count_Expression
157 (Concurrent_Type
: Entity_Id
;
158 Loc
: Source_Ptr
) return Node_Id
;
159 -- Compute number of entries for concurrent object. This is a count of
160 -- simple entries, followed by an expression that computes the length
161 -- of the range of each entry family. A single array with that size is
162 -- allocated for each concurrent object of the type.
164 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
165 -- Build the function that translates the entry index in the call
166 -- (which depends on the size of entry families) into an index into the
167 -- Entry_Bodies_Array, to determine the body and barrier function used
168 -- in a protected entry call. A pointer to this function appears in every
171 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
172 -- Build subprogram declaration for previous one
174 function Build_Lock_Free_Protected_Subprogram_Body
177 Unprot_Spec
: Node_Id
) return Node_Id
;
178 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
179 -- the subprogram specification of the unprotected version of N. Transform
180 -- N such that it invokes the unprotected version of the body.
182 function Build_Lock_Free_Unprotected_Subprogram_Body
184 Prot_Typ
: Node_Id
) return Node_Id
;
185 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
186 -- of N where the original statements of N are synchronized through atomic
187 -- actions such as compare and exchange. Prior to invoking this routine, it
188 -- has been established that N can be implemented in a lock-free fashion.
190 function Build_Parameter_Block
194 Decls
: List_Id
) return Entity_Id
;
195 -- Generate an access type for each actual parameter in the list Actuals.
196 -- Create an encapsulating record that contains all the actuals and return
197 -- its type. Generate:
198 -- type Ann1 is access all <actual1-type>
200 -- type AnnN is access all <actualN-type>
201 -- type Pnn is record
207 function Build_Protected_Entry
210 Pid
: Node_Id
) return Node_Id
;
211 -- Build the procedure implementing the statement sequence of the specified
214 function Build_Protected_Entry_Specification
217 Ent_Id
: Entity_Id
) return Node_Id
;
218 -- Build a specification for the procedure implementing the statements of
219 -- the specified entry body. Add attributes associating it with the entry
220 -- defining identifier Ent_Id.
222 function Build_Protected_Spec
224 Obj_Type
: Entity_Id
;
226 Unprotected
: Boolean := False) return List_Id
;
227 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
228 -- Subprogram_Type. Builds signature of protected subprogram, adding the
229 -- formal that corresponds to the object itself. For an access to protected
230 -- subprogram, there is no object type to specify, so the parameter has
231 -- type Address and mode In. An indirect call through such a pointer will
232 -- convert the address to a reference to the actual object. The object is
233 -- a limited record and therefore a by_reference type.
235 function Build_Protected_Subprogram_Body
238 N_Op_Spec
: Node_Id
) return Node_Id
;
239 -- This function is used to construct the protected version of a protected
240 -- subprogram. Its statement sequence first defers abort, then locks the
241 -- associated protected object, and then enters a block that contains a
242 -- call to the unprotected version of the subprogram (for details, see
243 -- Build_Unprotected_Subprogram_Body). This block statement requires a
244 -- cleanup handler that unlocks the object in all cases. For details,
245 -- see Exp_Ch7.Expand_Cleanup_Actions.
247 function Build_Renamed_Formal_Declaration
251 Renamed_Formal
: Node_Id
) return Node_Id
;
252 -- Create a renaming declaration for a formal, within a protected entry
253 -- body or an accept body. The renamed object is a component of the
254 -- parameter block that is a parameter in the entry call.
256 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
257 -- does not dereference the corresponding component to prevent an illegal
258 -- use of the incomplete type (AI05-0151).
260 function Build_Selected_Name
262 Selector
: Entity_Id
;
263 Append_Char
: Character := ' ') return Name_Id
;
264 -- Build a name in the form of Prefix__Selector, with an optional character
265 -- appended. This is used for internal subprograms generated for operations
266 -- of protected types, including barrier functions. For the subprograms
267 -- generated for entry bodies and entry barriers, the generated name
268 -- includes a sequence number that makes names unique in the presence of
269 -- entry overloading. This is necessary because entry body procedures and
270 -- barrier functions all have the same signature.
272 procedure Build_Simple_Entry_Call
277 -- Build the call corresponding to the task entry call. N is the task entry
278 -- call, Concval is the concurrent object, Ename is the entry name and
279 -- Index is the entry family index.
280 -- Note that N might be expanded into an N_Block_Statement if it gets
283 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
284 -- This routine constructs a specification for the procedure that we will
285 -- build for the task body for task type T. The spec has the form:
287 -- procedure tnameB (_Task : access tnameV);
289 -- where name is the character name taken from the task type entity that
290 -- is passed as the argument to the procedure, and tnameV is the task
291 -- value type that is associated with the task type.
293 function Build_Unprotected_Subprogram_Body
295 Pid
: Node_Id
) return Node_Id
;
296 -- This routine constructs the unprotected version of a protected
297 -- subprogram body, which contains all of the code in the original,
298 -- unexpanded body. This is the version of the protected subprogram that is
299 -- called from all protected operations on the same object, including the
300 -- protected version of the same subprogram.
302 procedure Build_Wrapper_Bodies
306 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
307 -- record of a concurrent type. N is the insertion node where all bodies
308 -- will be placed. This routine builds the bodies of the subprograms which
309 -- serve as an indirection mechanism to overriding primitives of concurrent
310 -- types, entries and protected procedures. Any new body is analyzed.
312 procedure Build_Wrapper_Specs
316 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
317 -- record of a concurrent type. N is the insertion node where all specs
318 -- will be placed. This routine builds the specs of the subprograms which
319 -- serve as an indirection mechanism to overriding primitives of concurrent
320 -- types, entries and protected procedures. Any new spec is analyzed.
322 procedure Collect_Entry_Families
325 Current_Node
: in out Node_Id
;
326 Conctyp
: Entity_Id
);
327 -- For each entry family in a concurrent type, create an anonymous array
328 -- type of the right size, and add a component to the corresponding_record.
330 function Concurrent_Object
331 (Spec_Id
: Entity_Id
;
332 Conc_Typ
: Entity_Id
) return Entity_Id
;
333 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
334 -- the entity associated with the concurrent object in the Protected_Body_
335 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
336 -- denotes formal parameter _O, _object or _task.
338 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
;
339 -- Copy the result type of a function specification, when building the
340 -- internal operation corresponding to a protected function, or when
341 -- expanding an access to protected function. If the result is an anonymous
342 -- access to subprogram itself, we need to create a new signature with the
343 -- same parameter names and the same resolved types, but with new entities
346 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean;
347 -- Return whether a secondary stack for the task T should be created by the
348 -- expander. The secondary stack for a task will be created by the expander
349 -- if the size of the stack has been specified by the Secondary_Stack_Size
350 -- representation aspect and either the No_Implicit_Heap_Allocations or
351 -- No_Implicit_Task_Allocations restrictions are in effect and the
352 -- No_Secondary_Stack restriction is not.
354 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
);
355 -- Decls is a list which may contain the declarations created by Install_
356 -- Private_Data_Declarations. All generated entities are marked as needing
357 -- debug info and debug nodes are manually generation where necessary. This
358 -- step of the expansion must to be done after private data has been moved
359 -- to its final resting scope to ensure proper visibility of debug objects.
361 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
);
362 -- If control flow optimizations are suppressed, and Alt is an accept,
363 -- delay, or entry call alternative with no trailing statements, insert
364 -- a null trailing statement with the given Loc (which is the sloc of
365 -- the accept, delay, or entry call statement). There might not be any
366 -- generated code for the accept, delay, or entry call itself (the effect
367 -- of these statements is part of the general processing done for the
368 -- enclosing selective accept, timed entry call, or asynchronous select),
369 -- and the null statement is there to carry the sloc of that statement to
370 -- the back-end for trace-based coverage analysis purposes.
372 procedure Extract_Dispatching_Call
374 Call_Ent
: out Entity_Id
;
375 Object
: out Entity_Id
;
376 Actuals
: out List_Id
;
377 Formals
: out List_Id
);
378 -- Given a dispatching call, extract the entity of the name of the call,
379 -- its actual dispatching object, its actual parameters and the formal
380 -- parameters of the overridden interface-level version. If the type of
381 -- the dispatching object is an access type then an explicit dereference
382 -- is returned in Object.
384 procedure Extract_Entry
386 Concval
: out Node_Id
;
388 Index
: out Node_Id
);
389 -- Given an entry call, returns the associated concurrent object, the entry
390 -- name, and the entry family index.
392 function Family_Offset
397 Cap
: Boolean) return Node_Id
;
398 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
399 -- accept statement, or the upper bound in the discrete subtype of an entry
400 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
401 -- type of the entry. If Cap is true, the result is capped according to
402 -- Entry_Family_Bound.
409 Cap
: Boolean) return Node_Id
;
410 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
411 -- family, and handle properly the superflat case. This is equivalent to
412 -- the use of 'Length on the index type, but must use Family_Offset to
413 -- handle properly the case of bounds that depend on discriminants. If
414 -- Cap is true, the result is capped according to Entry_Family_Bound.
416 procedure Find_Enclosing_Context
418 Context
: out Node_Id
;
419 Context_Id
: out Entity_Id
;
420 Context_Decls
: out List_Id
);
421 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
422 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
423 -- nearest enclosing body, block, package, or return statement and return
424 -- its constituents. Context is the enclosing construct, Context_Id is
425 -- the scope of Context_Id and Context_Decls is the declarative list of
428 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
;
429 -- Given a subprogram identifier, return the entity which is associated
430 -- with the protection entry index in the Protected_Body_Subprogram or
431 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
434 function Is_Potentially_Large_Family
435 (Base_Index
: Entity_Id
;
438 Hi
: Node_Id
) return Boolean;
439 -- Determine whether an entry family is potentially large because one of
440 -- its bounds denotes a discrminant.
442 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean;
443 -- Determine whether Id is a function or a procedure and is marked as a
444 -- private primitive.
446 function Null_Statements
(Stats
: List_Id
) return Boolean;
447 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
448 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
449 -- to still count as null. Returns True for a null sequence. The argument
450 -- is the list of statements from the DO-END sequence.
452 function Parameter_Block_Pack
458 Stmts
: List_Id
) return Entity_Id
;
459 -- Set the components of the generated parameter block with the values
460 -- of the actual parameters. Generate aliased temporaries to capture the
461 -- values for types that are passed by copy. Otherwise generate a reference
462 -- to the actual's value. Return the address of the aggregate block.
464 -- Jnn1 : alias <formal-type1>;
465 -- Jnn1 := <actual1>;
468 -- Jnn1'unchecked_access;
469 -- <actual2>'reference;
472 function Parameter_Block_Unpack
476 Formals
: List_Id
) return List_Id
;
477 -- Retrieve the values of the components from the parameter block and
478 -- assign then to the original actual parameters. Generate:
479 -- <actual1> := P.<formal1>;
481 -- <actualN> := P.<formalN>;
483 procedure Reset_Scopes_To
(Bod
: Node_Id
; E
: Entity_Id
);
484 -- Reset the scope of declarations and blocks at the top level of Bod to
485 -- be E. Bod is either a block or a subprogram body. Used after expanding
486 -- various kinds of entry bodies into their corresponding constructs. This
487 -- is needed during unnesting to determine whether a body generated for an
488 -- entry or an accept alternative includes uplevel references.
490 function Trivial_Accept_OK
return Boolean;
491 -- If there is no DO-END block for an accept, or if the DO-END block has
492 -- only null statements, then it is possible to do the Rendezvous with much
493 -- less overhead using the Accept_Trivial routine in the run-time library.
494 -- However, this is not always a valid optimization. Whether it is valid or
495 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
496 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
497 -- a rescheduling is required, so this optimization is not allowed. This
498 -- function returns True if the optimization is permitted.
500 -----------------------------
501 -- Actual_Index_Expression --
502 -----------------------------
504 function Actual_Index_Expression
508 Tsk
: Entity_Id
) return Node_Id
510 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
518 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
519 -- Compute difference between bounds of entry family
521 --------------------------
522 -- Actual_Family_Offset --
523 --------------------------
525 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
527 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
528 -- Replace a reference to a discriminant with a selected component
529 -- denoting the discriminant of the target task.
531 -----------------------------
532 -- Actual_Discriminant_Ref --
533 -----------------------------
535 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
536 Typ
: constant Entity_Id
:= Etype
(Bound
);
540 if not Is_Entity_Name
(Bound
)
541 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
543 if Nkind
(Bound
) = N_Attribute_Reference
then
546 B
:= New_Copy_Tree
(Bound
);
551 Make_Selected_Component
(Sloc
,
552 Prefix
=> New_Copy_Tree
(Tsk
),
553 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
555 Analyze_And_Resolve
(B
, Typ
);
559 Make_Attribute_Reference
(Sloc
,
560 Attribute_Name
=> Name_Pos
,
561 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
562 Expressions
=> New_List
(B
));
563 end Actual_Discriminant_Ref
;
565 -- Start of processing for Actual_Family_Offset
569 Make_Op_Subtract
(Sloc
,
570 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
571 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
572 end Actual_Family_Offset
;
574 -- Start of processing for Actual_Index_Expression
577 -- The queues of entries and entry families appear in textual order in
578 -- the associated record. The entry index is computed as the sum of the
579 -- number of queues for all entries that precede the designated one, to
580 -- which is added the index expression, if this expression denotes a
581 -- member of a family.
583 -- The following is a place holder for the count of simple entries
585 Num
:= Make_Integer_Literal
(Sloc
, 1);
587 -- We construct an expression which is a series of addition operations.
588 -- See comments in Entry_Index_Expression, which is identical in
591 if Present
(Index
) then
592 S
:= Entry_Index_Type
(Ent
);
594 -- First make sure the index is in range if requested. The index type
595 -- has been directly set on the prefix, see Resolve_Entry.
597 if Do_Range_Check
(Index
) then
599 (Index
, Etype
(Prefix
(Parent
(Index
))), CE_Range_Check_Failed
);
606 Actual_Family_Offset
(
607 Make_Attribute_Reference
(Sloc
,
608 Attribute_Name
=> Name_Pos
,
609 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
610 Expressions
=> New_List
(Relocate_Node
(Index
))),
611 Type_Low_Bound
(S
)));
616 -- Now add lengths of preceding entries and entry families
618 Prev
:= First_Entity
(Ttyp
);
619 while Chars
(Prev
) /= Chars
(Ent
)
620 or else Ekind
(Prev
) /= Ekind
(Ent
)
621 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
623 if Ekind
(Prev
) = E_Entry
then
624 Set_Intval
(Num
, Intval
(Num
) + 1);
626 elsif Ekind
(Prev
) = E_Entry_Family
then
627 S
:= Entry_Index_Type
(Prev
);
629 -- The need for the following full view retrieval stems from this
630 -- complex case of nested generics and tasking:
633 -- type Formal_Index is range <>;
636 -- type Index is private;
643 -- type Index is new Formal_Index range 1 .. 10;
646 -- package body Outer is
648 -- entry Fam (Index); -- (2)
651 -- package body Inner is -- (3)
659 -- We are currently building the index expression for the entry
660 -- call "T.E" (1). Part of the expansion must mention the range
661 -- of the discrete type "Index" (2) of entry family "Fam".
663 -- However only the private view of type "Index" is available to
664 -- the inner generic (3) because there was no prior mention of
665 -- the type inside "Inner". This visibility requirement is
666 -- implicit and cannot be detected during the construction of
667 -- the generic trees and needs special handling.
670 and then Is_Private_Type
(S
)
671 and then Present
(Full_View
(S
))
676 Lo
:= Type_Low_Bound
(S
);
677 Hi
:= Type_High_Bound
(S
);
684 Left_Opnd
=> Actual_Family_Offset
(Hi
, Lo
),
685 Right_Opnd
=> Make_Integer_Literal
(Sloc
, 1)));
687 -- Other components are anonymous types to be ignored
697 end Actual_Index_Expression
;
699 --------------------------
700 -- Add_Formal_Renamings --
701 --------------------------
703 procedure Add_Formal_Renamings
709 Ptr
: constant Entity_Id
:=
711 (Next
(First
(Parameter_Specifications
(Spec
))));
712 -- The name of the formal that holds the address of the parameter block
719 Renamed_Formal
: Node_Id
;
722 Formal
:= First_Formal
(Ent
);
723 while Present
(Formal
) loop
724 Comp
:= Entry_Component
(Formal
);
726 Make_Defining_Identifier
(Sloc
(Formal
),
727 Chars
=> Chars
(Formal
));
728 Set_Etype
(New_F
, Etype
(Formal
));
729 Set_Scope
(New_F
, Ent
);
731 -- Now we set debug info needed on New_F even though it does not come
732 -- from source, so that the debugger will get the right information
733 -- for these generated names.
735 Set_Debug_Info_Needed
(New_F
);
737 if Ekind
(Formal
) = E_In_Parameter
then
738 Mutate_Ekind
(New_F
, E_Constant
);
740 Mutate_Ekind
(New_F
, E_Variable
);
741 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
744 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
747 Make_Selected_Component
(Loc
,
749 Make_Explicit_Dereference
(Loc
,
750 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
751 Make_Identifier
(Loc
, Chars
(Ptr
)))),
752 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
));
755 Build_Renamed_Formal_Declaration
756 (New_F
, Formal
, Comp
, Renamed_Formal
);
758 Append
(Decl
, Decls
);
759 Set_Renamed_Object
(Formal
, New_F
);
760 Next_Formal
(Formal
);
762 end Add_Formal_Renamings
;
764 ------------------------
765 -- Add_Object_Pointer --
766 ------------------------
768 procedure Add_Object_Pointer
770 Conc_Typ
: Entity_Id
;
773 Rec_Typ
: constant Entity_Id
:= Corresponding_Record_Type
(Conc_Typ
);
778 -- Create the renaming declaration for the Protection object of a
779 -- protected type. _Object is used by Complete_Entry_Body.
780 -- ??? An attempt to make this a renaming was unsuccessful.
782 -- Build the entity for the access type
785 Make_Defining_Identifier
(Loc
,
786 New_External_Name
(Chars
(Rec_Typ
), 'P'));
789 -- _object : poVP := poVP!O;
792 Make_Object_Declaration
(Loc
,
793 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uObject
),
794 Object_Definition
=> New_Occurrence_Of
(Obj_Ptr
, Loc
),
796 Unchecked_Convert_To
(Obj_Ptr
, Make_Identifier
(Loc
, Name_uO
)));
797 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
798 Prepend_To
(Decls
, Decl
);
801 -- type poVP is access poV;
804 Make_Full_Type_Declaration
(Loc
,
805 Defining_Identifier
=>
808 Make_Access_To_Object_Definition
(Loc
,
809 Subtype_Indication
=>
810 New_Occurrence_Of
(Rec_Typ
, Loc
)));
811 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
812 Prepend_To
(Decls
, Decl
);
813 end Add_Object_Pointer
;
815 -----------------------
816 -- Build_Accept_Body --
817 -----------------------
819 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
820 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
821 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
828 -- At the end of the statement sequence, Complete_Rendezvous is called.
829 -- A label skipping the Complete_Rendezvous, and all other accept
830 -- processing, has already been added for the expansion of requeue
831 -- statements. The Sloc is copied from the last statement since it
832 -- is really part of this last statement.
836 (Sloc
(Last
(Statements
(Stats
))), RE_Complete_Rendezvous
);
837 Insert_Before
(Last
(Statements
(Stats
)), Call
);
840 -- Ada 2022 (AI12-0279)
842 if Has_Yield_Aspect
(Entity
(Entry_Direct_Name
(Astat
)))
843 and then RTE_Available
(RE_Yield
)
845 Insert_Action_After
(Call
,
846 Make_Procedure_Call_Statement
(Loc
,
847 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
850 -- If exception handlers are present, then append Complete_Rendezvous
851 -- calls to the handlers, and construct the required outer block. As
852 -- above, the Sloc is copied from the last statement in the sequence.
854 if Present
(Exception_Handlers
(Stats
)) then
855 Hand
:= First
(Exception_Handlers
(Stats
));
856 while Present
(Hand
) loop
859 (Sloc
(Last
(Statements
(Hand
))), RE_Complete_Rendezvous
);
860 Append
(Call
, Statements
(Hand
));
863 -- Ada 2022 (AI12-0279)
865 if Has_Yield_Aspect
(Entity
(Entry_Direct_Name
(Astat
)))
866 and then RTE_Available
(RE_Yield
)
868 Insert_Action_After
(Call
,
869 Make_Procedure_Call_Statement
(Loc
,
870 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
877 Make_Handled_Sequence_Of_Statements
(Loc
,
878 Statements
=> New_List
(
879 Make_Block_Statement
(Loc
,
880 Handled_Statement_Sequence
=> Stats
)));
886 -- At this stage we know that the new statement sequence does
887 -- not have an exception handler part, so we supply one to call
888 -- Exceptional_Complete_Rendezvous. This handler is
890 -- when all others =>
891 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
893 -- We handle Abort_Signal to make sure that we properly catch the abort
894 -- case and wake up the caller.
897 Make_Procedure_Call_Statement
(Sloc
(Stats
),
898 Name
=> New_Occurrence_Of
(
899 RTE
(RE_Exceptional_Complete_Rendezvous
), Sloc
(Stats
)),
900 Parameter_Associations
=> New_List
(
901 Make_Function_Call
(Sloc
(Stats
),
904 (RTE
(RE_Get_GNAT_Exception
), Sloc
(Stats
)))));
906 Ohandle
:= Make_Others_Choice
(Loc
);
907 Set_All_Others
(Ohandle
);
909 Set_Exception_Handlers
(New_S
,
911 Make_Implicit_Exception_Handler
(Loc
,
912 Exception_Choices
=> New_List
(Ohandle
),
914 Statements
=> New_List
(Call
))));
916 -- Ada 2022 (AI12-0279)
918 if Has_Yield_Aspect
(Entity
(Entry_Direct_Name
(Astat
)))
919 and then RTE_Available
(RE_Yield
)
921 Insert_Action_After
(Call
,
922 Make_Procedure_Call_Statement
(Loc
,
923 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
926 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
927 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
928 Expand_Exception_Handlers
(New_S
);
930 -- Exceptional_Complete_Rendezvous must be called with abort still
931 -- deferred, which is the case for a "when all others" handler.
934 end Build_Accept_Body
;
936 -----------------------------------
937 -- Build_Activation_Chain_Entity --
938 -----------------------------------
940 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
941 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean;
942 -- Determine whether an extended return statement has activation chain
944 --------------------------
945 -- Has_Activation_Chain --
946 --------------------------
948 function Has_Activation_Chain
(Stmt
: Node_Id
) return Boolean is
952 Decl
:= First
(Return_Object_Declarations
(Stmt
));
953 while Present
(Decl
) loop
954 if Nkind
(Decl
) = N_Object_Declaration
955 and then Chars
(Defining_Identifier
(Decl
)) = Name_uChain
964 end Has_Activation_Chain
;
969 Context_Id
: Entity_Id
;
972 -- Start of processing for Build_Activation_Chain_Entity
975 -- No action needed if the run-time has no tasking support
977 if Global_No_Tasking
then
981 -- Activation chain is never used for sequential elaboration policy, see
982 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
984 if Partition_Elaboration_Policy
= 'S' then
988 Find_Enclosing_Context
(N
, Context
, Context_Id
, Decls
);
990 -- If activation chain entity has not been declared already, create one
992 if Nkind
(Context
) = N_Extended_Return_Statement
993 or else No
(Activation_Chain_Entity
(Context
))
995 -- Since extended return statements do not store the entity of the
996 -- chain, examine the return object declarations to avoid creating
999 if Nkind
(Context
) = N_Extended_Return_Statement
1000 and then Has_Activation_Chain
(Context
)
1006 Loc
: constant Source_Ptr
:= Sloc
(Context
);
1011 Chain
:= Make_Defining_Identifier
(Sloc
(N
), Name_uChain
);
1013 -- Note: An extended return statement is not really a task
1014 -- activator, but it does have an activation chain on which to
1015 -- store the tasks temporarily. On successful return, the tasks
1016 -- on this chain are moved to the chain passed in by the caller.
1017 -- We do not build an Activation_Chain_Entity for an extended
1018 -- return statement, because we do not want to build a call to
1019 -- Activate_Tasks. Task activation is the responsibility of the
1022 if Nkind
(Context
) /= N_Extended_Return_Statement
then
1023 Set_Activation_Chain_Entity
(Context
, Chain
);
1027 Make_Object_Declaration
(Loc
,
1028 Defining_Identifier
=> Chain
,
1029 Aliased_Present
=> True,
1030 Object_Definition
=>
1031 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
));
1033 Prepend_To
(Decls
, Decl
);
1035 -- Ensure that _chain appears in the proper scope of the context
1037 if Context_Id
/= Current_Scope
then
1038 Push_Scope
(Context_Id
);
1046 end Build_Activation_Chain_Entity
;
1048 ----------------------------
1049 -- Build_Barrier_Function --
1050 ----------------------------
1052 function Build_Barrier_Function
1055 Pid
: Entity_Id
) return Node_Id
1057 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
1058 Cond
: constant Node_Id
:= Condition
(Ent_Formals
);
1059 Loc
: constant Source_Ptr
:= Sloc
(Cond
);
1060 Func_Id
: constant Entity_Id
:= Barrier_Function
(Ent
);
1061 Op_Decls
: constant List_Id
:= New_List
;
1063 Func_Body
: Node_Id
;
1066 -- Add a declaration for the Protection object, renaming declarations
1067 -- for the discriminals and privals and finally a declaration for the
1068 -- entry family index (if applicable).
1070 Install_Private_Data_Declarations
(Sloc
(N
),
1076 Family
=> Ekind
(Ent
) = E_Entry_Family
);
1078 -- If compiling with -fpreserve-control-flow, make sure we insert an
1079 -- IF statement so that the back-end knows to generate a conditional
1080 -- branch instruction, even if the condition is just the name of a
1081 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1082 -- such redundant IF statements under -fpreserve-control-flow
1083 -- (whether coming from this routine, or directly from source).
1085 if Opt
.Suppress_Control_Flow_Optimizations
then
1087 Make_Implicit_If_Statement
(Cond
,
1089 Then_Statements
=> New_List
(
1090 Make_Simple_Return_Statement
(Loc
,
1091 New_Occurrence_Of
(Standard_True
, Loc
))),
1093 Else_Statements
=> New_List
(
1094 Make_Simple_Return_Statement
(Loc
,
1095 New_Occurrence_Of
(Standard_False
, Loc
))));
1098 Stmt
:= Make_Simple_Return_Statement
(Loc
, Cond
);
1101 -- Note: the condition in the barrier function needs to be properly
1102 -- processed for the C/Fortran boolean possibility, but this happens
1103 -- automatically since the return statement does this normalization.
1106 Make_Subprogram_Body
(Loc
,
1108 Build_Barrier_Function_Specification
(Loc
,
1109 Make_Defining_Identifier
(Loc
, Chars
(Func_Id
))),
1110 Declarations
=> Op_Decls
,
1111 Handled_Statement_Sequence
=>
1112 Make_Handled_Sequence_Of_Statements
(Loc
,
1113 Statements
=> New_List
(Stmt
)));
1114 Set_Is_Entry_Barrier_Function
(Func_Body
);
1117 end Build_Barrier_Function
;
1119 ------------------------------------------
1120 -- Build_Barrier_Function_Specification --
1121 ------------------------------------------
1123 function Build_Barrier_Function_Specification
1125 Def_Id
: Entity_Id
) return Node_Id
1128 Set_Debug_Info_Needed
(Def_Id
);
1131 Make_Function_Specification
(Loc
,
1132 Defining_Unit_Name
=> Def_Id
,
1133 Parameter_Specifications
=> New_List
(
1134 Make_Parameter_Specification
(Loc
,
1135 Defining_Identifier
=>
1136 Make_Defining_Identifier
(Loc
, Name_uO
),
1138 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
1140 Make_Parameter_Specification
(Loc
,
1141 Defining_Identifier
=>
1142 Make_Defining_Identifier
(Loc
, Name_uE
),
1144 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1146 Result_Definition
=>
1147 New_Occurrence_Of
(Standard_Boolean
, Loc
));
1148 end Build_Barrier_Function_Specification
;
1150 --------------------------
1151 -- Build_Call_With_Task --
1152 --------------------------
1154 function Build_Call_With_Task
1156 E
: Entity_Id
) return Node_Id
1158 Loc
: constant Source_Ptr
:= Sloc
(N
);
1161 Make_Function_Call
(Loc
,
1162 Name
=> New_Occurrence_Of
(E
, Loc
),
1163 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
1164 end Build_Call_With_Task
;
1166 -----------------------------
1167 -- Build_Class_Wide_Master --
1168 -----------------------------
1170 procedure Build_Class_Wide_Master
(Typ
: Entity_Id
) is
1171 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1172 Master_Decl
: Node_Id
;
1173 Master_Id
: Entity_Id
;
1174 Master_Scope
: Entity_Id
;
1176 Related_Node
: Node_Id
;
1180 -- No action needed if the run-time has no tasking support
1182 if Global_No_Tasking
then
1186 -- Find the declaration that created the access type, which is either a
1187 -- type declaration, or an object declaration with an access definition,
1188 -- in which case the type is anonymous.
1190 if Is_Itype
(Typ
) then
1191 Related_Node
:= Associated_Node_For_Itype
(Typ
);
1193 Related_Node
:= Parent
(Typ
);
1196 Master_Scope
:= Find_Master_Scope
(Typ
);
1198 -- Nothing to do if the master scope already contains a _master entity.
1199 -- The only exception to this is the following scenario:
1202 -- Transient_Scope_1
1205 -- Transient_Scope_2
1208 -- In this case the source scope is marked as having the master entity
1209 -- even though the actual declaration appears inside an inner scope. If
1210 -- the second transient scope requires a _master, it cannot use the one
1211 -- already declared because the entity is not visible.
1213 Name_Id
:= Make_Identifier
(Loc
, Name_uMaster
);
1214 Master_Decl
:= Empty
;
1216 if not Has_Master_Entity
(Master_Scope
)
1217 or else No
(Current_Entity_In_Scope
(Name_Id
))
1224 Master_Decl
:= Build_Master_Declaration
(Loc
);
1226 -- Ensure that the master declaration is placed before its use
1228 Ins_Nod
:= Find_Hook_Context
(Related_Node
);
1229 while not Is_List_Member
(Ins_Nod
) loop
1230 Ins_Nod
:= Parent
(Ins_Nod
);
1233 Par_Nod
:= Parent
(List_Containing
(Ins_Nod
));
1235 -- For internal blocks created by Wrap_Loop_Statement, Wrap_
1236 -- Statements_In_Block, and Build_Abort_Undefer_Block, remember
1237 -- that they have a task master entity declaration; required by
1238 -- Build_Master_Entity to avoid creating another master entity,
1239 -- and also ensures that subsequent calls to Find_Master_Scope
1240 -- return this scope as the master scope of Typ.
1242 if Is_Internal_Block
(Par_Nod
) then
1243 Set_Has_Master_Entity
(Entity
(Identifier
(Par_Nod
)));
1245 elsif Nkind
(Par_Nod
) = N_Handled_Sequence_Of_Statements
1246 and then Is_Internal_Block
(Parent
(Par_Nod
))
1248 Set_Has_Master_Entity
(Entity
(Identifier
(Parent
(Par_Nod
))));
1250 -- Otherwise remember that this scope has an associated task
1251 -- master entity declaration.
1254 Set_Has_Master_Entity
(Master_Scope
);
1257 Insert_Before
(First
(List_Containing
(Ins_Nod
)), Master_Decl
);
1258 Analyze
(Master_Decl
);
1260 -- Mark the containing scope as a task master. Masters associated
1261 -- with return statements are already marked at this stage (see
1262 -- Analyze_Subprogram_Body).
1264 if Ekind
(Current_Scope
) /= E_Return_Statement
then
1266 Par
: Node_Id
:= Related_Node
;
1269 while Nkind
(Par
) /= N_Compilation_Unit
loop
1270 Par
:= Parent
(Par
);
1272 -- If we fall off the top, we are at the outer level,
1273 -- and the environment task is our effective master,
1274 -- so nothing to mark.
1277 N_Block_Statement | N_Subprogram_Body | N_Task_Body
1279 Set_Is_Task_Master
(Par
);
1289 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(Typ
), 'M'));
1292 -- typeMnn renames _master;
1295 Make_Object_Renaming_Declaration
(Loc
,
1296 Defining_Identifier
=> Master_Id
,
1297 Subtype_Mark
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
1300 -- If the master is declared locally, add the renaming declaration
1301 -- immediately after it, to prevent access-before-elaboration in the
1304 if Present
(Master_Decl
) then
1305 Insert_After
(Master_Decl
, Ren_Decl
);
1309 Insert_Action
(Related_Node
, Ren_Decl
);
1312 Set_Master_Id
(Typ
, Master_Id
);
1313 end Build_Class_Wide_Master
;
1315 --------------------------------
1316 -- Build_Corresponding_Record --
1317 --------------------------------
1319 function Build_Corresponding_Record
1322 Loc
: Source_Ptr
) return Node_Id
1324 Rec_Ent
: constant Entity_Id
:=
1325 Make_Defining_Identifier
1326 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
1329 New_Disc
: Entity_Id
;
1333 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
1334 Mutate_Ekind
(Rec_Ent
, E_Record_Type
);
1335 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
1336 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
1337 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
1338 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
1341 -- Use discriminals to create list of discriminants for record, and
1342 -- create new discriminals for use in default expressions, etc. It is
1343 -- worth noting that a task discriminant gives rise to 5 entities;
1345 -- a) The original discriminant.
1346 -- b) The discriminal for use in the task.
1347 -- c) The discriminant of the corresponding record.
1348 -- d) The discriminal for the init proc of the corresponding record.
1349 -- e) The local variable that renames the discriminant in the procedure
1350 -- for the task body.
1352 -- In fact the discriminals b) are used in the renaming declarations
1353 -- for e). See details in einfo (Handling of Discriminants).
1355 if Present
(Discriminant_Specifications
(N
)) then
1357 Disc
:= First_Discriminant
(Ctyp
);
1359 while Present
(Disc
) loop
1360 New_Disc
:= CR_Discriminant
(Disc
);
1363 Make_Discriminant_Specification
(Loc
,
1364 Defining_Identifier
=> New_Disc
,
1365 Discriminant_Type
=>
1366 New_Occurrence_Of
(Etype
(Disc
), Loc
),
1368 New_Copy
(Discriminant_Default_Value
(Disc
))));
1370 Next_Discriminant
(Disc
);
1377 -- Now we can construct the record type declaration. Note that this
1378 -- record is "limited tagged". It is "limited" to reflect the underlying
1379 -- limitedness of the task or protected object that it represents, and
1380 -- ensuring for example that it is properly passed by reference. It is
1381 -- "tagged" to give support to dispatching calls through interfaces. We
1382 -- propagate here the list of interfaces covered by the concurrent type
1383 -- (Ada 2005: AI-345).
1386 Make_Full_Type_Declaration
(Loc
,
1387 Defining_Identifier
=> Rec_Ent
,
1388 Discriminant_Specifications
=> Dlist
,
1390 Make_Record_Definition
(Loc
,
1392 Make_Component_List
(Loc
, Component_Items
=> Cdecls
),
1394 Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Ctyp
),
1395 Interface_List
=> Interface_List
(N
),
1396 Limited_Present
=> True));
1397 end Build_Corresponding_Record
;
1399 ---------------------------------
1400 -- Build_Dispatching_Tag_Check --
1401 ---------------------------------
1403 function Build_Dispatching_Tag_Check
1405 N
: Node_Id
) return Node_Id
1407 Loc
: constant Source_Ptr
:= Sloc
(N
);
1414 New_Occurrence_Of
(K
, Loc
),
1416 New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
)),
1420 New_Occurrence_Of
(K
, Loc
),
1422 New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
)));
1423 end Build_Dispatching_Tag_Check
;
1425 ----------------------------------
1426 -- Build_Entry_Count_Expression --
1427 ----------------------------------
1429 function Build_Entry_Count_Expression
1430 (Concurrent_Type
: Entity_Id
;
1431 Loc
: Source_Ptr
) return Node_Id
1442 -- Count number of non-family entries
1445 Ent
:= First_Entity
(Concurrent_Type
);
1446 while Present
(Ent
) loop
1447 if Ekind
(Ent
) = E_Entry
then
1454 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
1456 -- Loop through entry families building the addition nodes
1458 Ent
:= First_Entity
(Concurrent_Type
);
1459 while Present
(Ent
) loop
1460 if Ekind
(Ent
) = E_Entry_Family
then
1461 Typ
:= Entry_Index_Type
(Ent
);
1462 Hi
:= Type_High_Bound
(Typ
);
1463 Lo
:= Type_Low_Bound
(Typ
);
1464 Large
:= Is_Potentially_Large_Family
1465 (Base_Type
(Typ
), Concurrent_Type
, Lo
, Hi
);
1468 Left_Opnd
=> Ecount
,
1470 Family_Size
(Loc
, Hi
, Lo
, Concurrent_Type
, Large
));
1477 end Build_Entry_Count_Expression
;
1479 ------------------------------
1480 -- Build_Master_Declaration --
1481 ------------------------------
1483 function Build_Master_Declaration
(Loc
: Source_Ptr
) return Node_Id
is
1484 Master_Decl
: Node_Id
;
1487 -- Generate a dummy master if tasks or tasking hierarchies are
1490 -- _Master : constant Integer := Library_Task_Level;
1492 if not Tasking_Allowed
1493 or else Restrictions
.Set
(No_Task_Hierarchy
)
1494 or else not RTE_Available
(RE_Current_Master
)
1497 Make_Object_Declaration
(Loc
,
1498 Defining_Identifier
=>
1499 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1500 Constant_Present
=> True,
1501 Object_Definition
=>
1502 New_Occurrence_Of
(Standard_Integer
, Loc
),
1504 Make_Integer_Literal
(Loc
, Library_Task_Level
));
1507 -- _master : constant Integer := Current_Master.all;
1511 Make_Object_Declaration
(Loc
,
1512 Defining_Identifier
=>
1513 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1514 Constant_Present
=> True,
1515 Object_Definition
=>
1516 New_Occurrence_Of
(Standard_Integer
, Loc
),
1518 Make_Explicit_Dereference
(Loc
,
1519 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
1523 end Build_Master_Declaration
;
1525 ---------------------------
1526 -- Build_Parameter_Block --
1527 ---------------------------
1529 function Build_Parameter_Block
1533 Decls
: List_Id
) return Entity_Id
1539 Has_Comp
: Boolean := False;
1543 Actual
:= First
(Actuals
);
1545 Formal
:= Defining_Identifier
(First
(Formals
));
1547 while Present
(Actual
) loop
1548 if not Is_Controlling_Actual
(Actual
) then
1551 -- type Ann is access all <actual-type>
1553 Comp_Nam
:= Make_Temporary
(Loc
, 'A');
1554 Set_Is_Param_Block_Component_Type
(Comp_Nam
);
1557 Make_Full_Type_Declaration
(Loc
,
1558 Defining_Identifier
=> Comp_Nam
,
1560 Make_Access_To_Object_Definition
(Loc
,
1561 All_Present
=> True,
1562 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
1563 Subtype_Indication
=>
1564 New_Occurrence_Of
(Etype
(Actual
), Loc
))));
1570 Make_Component_Declaration
(Loc
,
1571 Defining_Identifier
=>
1572 Make_Defining_Identifier
(Loc
, Chars
(Formal
)),
1573 Component_Definition
=>
1574 Make_Component_Definition
(Loc
,
1577 Subtype_Indication
=>
1578 New_Occurrence_Of
(Comp_Nam
, Loc
))));
1583 Next_Actual
(Actual
);
1584 Next_Formal_With_Extras
(Formal
);
1587 Rec_Nam
:= Make_Temporary
(Loc
, 'P');
1592 -- type Pnn is record
1597 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1598 -- the original parameter names and Ann1 .. AnnN are the access to
1602 Make_Full_Type_Declaration
(Loc
,
1603 Defining_Identifier
=>
1606 Make_Record_Definition
(Loc
,
1608 Make_Component_List
(Loc
, Comps
))));
1611 -- type Pnn is null record;
1614 Make_Full_Type_Declaration
(Loc
,
1615 Defining_Identifier
=>
1618 Make_Record_Definition
(Loc
,
1619 Null_Present
=> True,
1620 Component_List
=> Empty
)));
1624 end Build_Parameter_Block
;
1626 --------------------------------------
1627 -- Build_Renamed_Formal_Declaration --
1628 --------------------------------------
1630 function Build_Renamed_Formal_Declaration
1634 Renamed_Formal
: Node_Id
) return Node_Id
1636 Loc
: constant Source_Ptr
:= Sloc
(New_F
);
1640 -- If the formal is a tagged incomplete type, it is already passed
1641 -- by reference, so it is sufficient to rename the pointer component
1642 -- that corresponds to the actual. Otherwise we need to dereference
1643 -- the pointer component to obtain the actual.
1645 if Is_Incomplete_Type
(Etype
(Formal
))
1646 and then Is_Tagged_Type
(Etype
(Formal
))
1649 Make_Object_Renaming_Declaration
(Loc
,
1650 Defining_Identifier
=> New_F
,
1651 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Comp
), Loc
),
1652 Name
=> Renamed_Formal
);
1656 Make_Object_Renaming_Declaration
(Loc
,
1657 Defining_Identifier
=> New_F
,
1658 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Formal
), Loc
),
1660 Make_Explicit_Dereference
(Loc
, Renamed_Formal
));
1664 end Build_Renamed_Formal_Declaration
;
1666 --------------------------
1667 -- Build_Wrapper_Bodies --
1668 --------------------------
1670 procedure Build_Wrapper_Bodies
1675 Rec_Typ
: Entity_Id
;
1677 function Build_Wrapper_Body
1679 Subp_Id
: Entity_Id
;
1680 Obj_Typ
: Entity_Id
;
1681 Formals
: List_Id
) return Node_Id
;
1682 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1683 -- associated with a protected or task type. Subp_Id is the subprogram
1684 -- name which will be wrapped. Obj_Typ is the type of the new formal
1685 -- parameter which handles dispatching and object notation. Formals are
1686 -- the original formals of Subp_Id which will be explicitly replicated.
1688 ------------------------
1689 -- Build_Wrapper_Body --
1690 ------------------------
1692 function Build_Wrapper_Body
1694 Subp_Id
: Entity_Id
;
1695 Obj_Typ
: Entity_Id
;
1696 Formals
: List_Id
) return Node_Id
1698 Body_Spec
: Node_Id
;
1701 Body_Spec
:= Build_Wrapper_Spec
(Subp_Id
, Obj_Typ
, Formals
);
1703 -- The subprogram is not overriding or is not a primitive declared
1704 -- between two views.
1706 if No
(Body_Spec
) then
1711 Actuals
: List_Id
:= No_List
;
1713 First_Form
: Node_Id
;
1718 -- Map formals to actuals. Use the list built for the wrapper
1719 -- spec, skipping the object notation parameter.
1721 First_Form
:= First
(Parameter_Specifications
(Body_Spec
));
1723 Formal
:= First_Form
;
1726 if Present
(Formal
) then
1727 Actuals
:= New_List
;
1728 while Present
(Formal
) loop
1730 Make_Identifier
(Loc
,
1731 Chars
=> Chars
(Defining_Identifier
(Formal
))));
1736 -- Special processing for primitives declared between a private
1737 -- type and its completion: the wrapper needs a properly typed
1738 -- parameter if the wrapped operation has a controlling first
1739 -- parameter. Note that this might not be the case for a function
1740 -- with a controlling result.
1742 if Is_Private_Primitive_Subprogram
(Subp_Id
) then
1743 if No
(Actuals
) then
1744 Actuals
:= New_List
;
1747 if Is_Controlling_Formal
(First_Formal
(Subp_Id
)) then
1748 Prepend_To
(Actuals
,
1749 Unchecked_Convert_To
1750 (Corresponding_Concurrent_Type
(Obj_Typ
),
1751 Make_Identifier
(Loc
, Name_uO
)));
1754 Prepend_To
(Actuals
,
1755 Make_Identifier
(Loc
,
1756 Chars
=> Chars
(Defining_Identifier
(First_Form
))));
1759 Nam
:= New_Occurrence_Of
(Subp_Id
, Loc
);
1761 -- An access-to-variable object parameter requires an explicit
1762 -- dereference in the unchecked conversion. This case occurs
1763 -- when a protected entry wrapper must override an interface
1764 -- level procedure with interface access as first parameter.
1766 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1768 if Nkind
(Parameter_Type
(First_Form
)) =
1772 Make_Explicit_Dereference
(Loc
,
1773 Prefix
=> Make_Identifier
(Loc
, Name_uO
));
1775 Conv_Id
:= Make_Identifier
(Loc
, Name_uO
);
1779 Make_Selected_Component
(Loc
,
1781 Unchecked_Convert_To
1782 (Corresponding_Concurrent_Type
(Obj_Typ
), Conv_Id
),
1783 Selector_Name
=> New_Occurrence_Of
(Subp_Id
, Loc
));
1786 -- Create the subprogram body. For a function, the call to the
1787 -- actual subprogram has to be converted to the corresponding
1788 -- record if it is a controlling result.
1790 if Ekind
(Subp_Id
) = E_Function
then
1796 Make_Function_Call
(Loc
,
1798 Parameter_Associations
=> Actuals
);
1800 if Has_Controlling_Result
(Subp_Id
) then
1802 Unchecked_Convert_To
1803 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Res
);
1807 Make_Subprogram_Body
(Loc
,
1808 Specification
=> Body_Spec
,
1809 Declarations
=> Empty_List
,
1810 Handled_Statement_Sequence
=>
1811 Make_Handled_Sequence_Of_Statements
(Loc
,
1812 Statements
=> New_List
(
1813 Make_Simple_Return_Statement
(Loc
, Res
))));
1818 Make_Subprogram_Body
(Loc
,
1819 Specification
=> Body_Spec
,
1820 Declarations
=> Empty_List
,
1821 Handled_Statement_Sequence
=>
1822 Make_Handled_Sequence_Of_Statements
(Loc
,
1823 Statements
=> New_List
(
1824 Make_Procedure_Call_Statement
(Loc
,
1826 Parameter_Associations
=> Actuals
))));
1829 end Build_Wrapper_Body
;
1831 -- Start of processing for Build_Wrapper_Bodies
1834 if Is_Concurrent_Type
(Typ
) then
1835 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
1840 -- Generate wrapper bodies for a concurrent type which implements an
1843 if Present
(Interfaces
(Rec_Typ
)) then
1845 Insert_Nod
: Node_Id
;
1847 Prim_Elmt
: Elmt_Id
;
1848 Prim_Decl
: Node_Id
;
1850 Wrap_Body
: Node_Id
;
1851 Wrap_Id
: Entity_Id
;
1856 -- Examine all primitive operations of the corresponding record
1857 -- type, looking for wrapper specs. Generate bodies in order to
1860 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Rec_Typ
));
1861 while Present
(Prim_Elmt
) loop
1862 Prim
:= Node
(Prim_Elmt
);
1864 if (Ekind
(Prim
) = E_Function
1865 or else Ekind
(Prim
) = E_Procedure
)
1866 and then Is_Primitive_Wrapper
(Prim
)
1868 Subp
:= Wrapped_Entity
(Prim
);
1869 Prim_Decl
:= Parent
(Parent
(Prim
));
1872 Build_Wrapper_Body
(Loc
,
1875 Formals
=> Parameter_Specifications
(Parent
(Subp
)));
1876 Wrap_Id
:= Defining_Unit_Name
(Specification
(Wrap_Body
));
1878 Set_Corresponding_Spec
(Wrap_Body
, Prim
);
1879 Set_Corresponding_Body
(Prim_Decl
, Wrap_Id
);
1881 Insert_After
(Insert_Nod
, Wrap_Body
);
1882 Insert_Nod
:= Wrap_Body
;
1884 Analyze
(Wrap_Body
);
1887 Next_Elmt
(Prim_Elmt
);
1891 end Build_Wrapper_Bodies
;
1893 ------------------------
1894 -- Build_Wrapper_Spec --
1895 ------------------------
1897 function Build_Wrapper_Spec
1898 (Subp_Id
: Entity_Id
;
1899 Obj_Typ
: Entity_Id
;
1900 Formals
: List_Id
) return Node_Id
1902 function Overriding_Possible
1903 (Iface_Op
: Entity_Id
;
1904 Wrapper
: Entity_Id
) return Boolean;
1905 -- Determine whether a primitive operation can be overridden by Wrapper.
1906 -- Iface_Op is the candidate primitive operation of an interface type,
1907 -- Wrapper is the generated entry wrapper.
1909 function Replicate_Formals
1911 Formals
: List_Id
) return List_Id
;
1912 -- An explicit parameter replication is required due to the Is_Entry_
1913 -- Formal flag being set for all the formals of an entry. The explicit
1914 -- replication removes the flag that would otherwise cause a different
1915 -- path of analysis.
1917 -------------------------
1918 -- Overriding_Possible --
1919 -------------------------
1921 function Overriding_Possible
1922 (Iface_Op
: Entity_Id
;
1923 Wrapper
: Entity_Id
) return Boolean
1925 Iface_Op_Spec
: constant Node_Id
:= Parent
(Iface_Op
);
1926 Wrapper_Spec
: constant Node_Id
:= Parent
(Wrapper
);
1928 function Type_Conformant_Parameters
1929 (Iface_Op_Params
: List_Id
;
1930 Wrapper_Params
: List_Id
) return Boolean;
1931 -- Determine whether the parameters of the generated entry wrapper
1932 -- and those of a primitive operation are type conformant. During
1933 -- this check, the first parameter of the primitive operation is
1934 -- skipped if it is a controlling argument: protected functions
1935 -- may have a controlling result.
1937 --------------------------------
1938 -- Type_Conformant_Parameters --
1939 --------------------------------
1941 function Type_Conformant_Parameters
1942 (Iface_Op_Params
: List_Id
;
1943 Wrapper_Params
: List_Id
) return Boolean
1945 Iface_Op_Param
: Node_Id
;
1946 Iface_Op_Typ
: Entity_Id
;
1947 Wrapper_Param
: Node_Id
;
1948 Wrapper_Typ
: Entity_Id
;
1951 -- Skip the first (controlling) parameter of primitive operation
1953 Iface_Op_Param
:= First
(Iface_Op_Params
);
1955 if Present
(First_Formal
(Iface_Op
))
1956 and then Is_Controlling_Formal
(First_Formal
(Iface_Op
))
1958 Next
(Iface_Op_Param
);
1961 Wrapper_Param
:= First
(Wrapper_Params
);
1962 while Present
(Iface_Op_Param
)
1963 and then Present
(Wrapper_Param
)
1965 Iface_Op_Typ
:= Find_Parameter_Type
(Iface_Op_Param
);
1966 Wrapper_Typ
:= Find_Parameter_Type
(Wrapper_Param
);
1968 -- The two parameters must be mode conformant
1970 if not Conforming_Types
1971 (Iface_Op_Typ
, Wrapper_Typ
, Mode_Conformant
)
1976 Next
(Iface_Op_Param
);
1977 Next
(Wrapper_Param
);
1980 -- One of the lists is longer than the other
1982 if Present
(Iface_Op_Param
) or else Present
(Wrapper_Param
) then
1987 end Type_Conformant_Parameters
;
1989 -- Start of processing for Overriding_Possible
1992 if Chars
(Iface_Op
) /= Chars
(Wrapper
) then
1996 -- If an inherited subprogram is implemented by a protected procedure
1997 -- or an entry, then the first parameter of the inherited subprogram
1998 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2000 if Ekind
(Iface_Op
) = E_Procedure
2001 and then Present
(Parameter_Specifications
(Iface_Op_Spec
))
2004 Obj_Param
: constant Node_Id
:=
2005 First
(Parameter_Specifications
(Iface_Op_Spec
));
2007 if not Out_Present
(Obj_Param
)
2008 and then Nkind
(Parameter_Type
(Obj_Param
)) /=
2017 Type_Conformant_Parameters
2018 (Parameter_Specifications
(Iface_Op_Spec
),
2019 Parameter_Specifications
(Wrapper_Spec
));
2020 end Overriding_Possible
;
2022 -----------------------
2023 -- Replicate_Formals --
2024 -----------------------
2026 function Replicate_Formals
2028 Formals
: List_Id
) return List_Id
2030 New_Formals
: constant List_Id
:= New_List
;
2032 Param_Type
: Node_Id
;
2035 Formal
:= First
(Formals
);
2037 -- Skip the object parameter when dealing with primitives declared
2038 -- between two views.
2040 if Is_Private_Primitive_Subprogram
(Subp_Id
)
2041 and then not Has_Controlling_Result
(Subp_Id
)
2046 while Present
(Formal
) loop
2048 -- Create an explicit copy of the entry parameter
2050 -- When creating the wrapper subprogram for a primitive operation
2051 -- of a protected interface we must construct an equivalent
2052 -- signature to that of the overriding operation. For regular
2053 -- parameters we can just use the type of the formal, but for
2054 -- access to subprogram parameters we need to reanalyze the
2055 -- parameter type to create local entities for the signature of
2056 -- the subprogram type. Using the entities of the overriding
2057 -- subprogram will result in out-of-scope errors in the back-end.
2059 if Nkind
(Parameter_Type
(Formal
)) = N_Access_Definition
then
2060 Param_Type
:= Copy_Separate_Tree
(Parameter_Type
(Formal
));
2063 New_Occurrence_Of
(Etype
(Parameter_Type
(Formal
)), Loc
);
2066 Append_To
(New_Formals
,
2067 Make_Parameter_Specification
(Loc
,
2068 Defining_Identifier
=>
2069 Make_Defining_Identifier
(Loc
,
2070 Chars
=> Chars
(Defining_Identifier
(Formal
))),
2071 In_Present
=> In_Present
(Formal
),
2072 Out_Present
=> Out_Present
(Formal
),
2073 Null_Exclusion_Present
=> Null_Exclusion_Present
(Formal
),
2074 Parameter_Type
=> Param_Type
));
2080 end Replicate_Formals
;
2084 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
2085 First_Param
: Node_Id
:= Empty
;
2087 Iface_Elmt
: Elmt_Id
;
2088 Iface_Op
: Entity_Id
;
2089 Iface_Op_Elmt
: Elmt_Id
;
2090 Overridden_Subp
: Entity_Id
;
2092 -- Start of processing for Build_Wrapper_Spec
2095 -- No point in building wrappers for untagged concurrent types
2097 pragma Assert
(Is_Tagged_Type
(Obj_Typ
));
2099 -- Check if this subprogram has a profile that matches some interface
2102 Check_Synchronized_Overriding
(Subp_Id
, Overridden_Subp
);
2104 if Present
(Overridden_Subp
) then
2106 First
(Parameter_Specifications
(Parent
(Overridden_Subp
)));
2108 -- An entry or a protected procedure can override a routine where the
2109 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2110 -- type. Since the wrapper must have the exact same signature as that of
2111 -- the overridden subprogram, we try to find the overriding candidate
2112 -- and use its controlling formal.
2114 -- Check every implemented interface
2116 elsif Present
(Interfaces
(Obj_Typ
)) then
2117 Iface_Elmt
:= First_Elmt
(Interfaces
(Obj_Typ
));
2118 Search
: while Present
(Iface_Elmt
) loop
2119 Iface
:= Node
(Iface_Elmt
);
2121 -- Check every interface primitive
2123 if Present
(Primitive_Operations
(Iface
)) then
2124 Iface_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
2125 while Present
(Iface_Op_Elmt
) loop
2126 Iface_Op
:= Node
(Iface_Op_Elmt
);
2128 -- Ignore predefined primitives
2130 if not Is_Predefined_Dispatching_Operation
(Iface_Op
) then
2131 Iface_Op
:= Ultimate_Alias
(Iface_Op
);
2133 -- The current primitive operation can be overridden by
2134 -- the generated entry wrapper.
2136 if Overriding_Possible
(Iface_Op
, Subp_Id
) then
2138 First
(Parameter_Specifications
(Parent
(Iface_Op
)));
2144 Next_Elmt
(Iface_Op_Elmt
);
2148 Next_Elmt
(Iface_Elmt
);
2152 -- Do not generate the wrapper if no interface primitive is covered by
2153 -- the subprogram and it is not a primitive declared between two views
2154 -- (see Process_Full_View).
2157 and then not Is_Private_Primitive_Subprogram
(Subp_Id
)
2163 Wrapper_Id
: constant Entity_Id
:=
2164 Make_Defining_Identifier
(Loc
, Chars
(Subp_Id
));
2165 New_Formals
: List_Id
;
2166 Obj_Param
: Node_Id
;
2167 Obj_Param_Typ
: Entity_Id
;
2170 -- Minimum decoration is needed to catch the entity in
2171 -- Sem_Ch6.Override_Dispatching_Operation.
2173 if Ekind
(Subp_Id
) = E_Function
then
2174 Mutate_Ekind
(Wrapper_Id
, E_Function
);
2176 Mutate_Ekind
(Wrapper_Id
, E_Procedure
);
2179 Set_Is_Primitive_Wrapper
(Wrapper_Id
);
2180 Set_Wrapped_Entity
(Wrapper_Id
, Subp_Id
);
2181 Set_Is_Private_Primitive
(Wrapper_Id
,
2182 Is_Private_Primitive_Subprogram
(Subp_Id
));
2184 -- Process the formals
2186 New_Formals
:= Replicate_Formals
(Loc
, Formals
);
2188 -- A function with a controlling result and no first controlling
2189 -- formal needs no additional parameter.
2191 if Has_Controlling_Result
(Subp_Id
)
2193 (No
(First_Formal
(Subp_Id
))
2194 or else not Is_Controlling_Formal
(First_Formal
(Subp_Id
)))
2198 -- Routine Subp_Id has been found to override an interface primitive.
2199 -- If the interface operation has an access parameter, create a copy
2200 -- of it, with the same null exclusion indicator if present.
2202 elsif Present
(First_Param
) then
2203 if Nkind
(Parameter_Type
(First_Param
)) = N_Access_Definition
then
2205 Make_Access_Definition
(Loc
,
2207 New_Occurrence_Of
(Obj_Typ
, Loc
),
2208 Null_Exclusion_Present
=>
2209 Null_Exclusion_Present
(Parameter_Type
(First_Param
)),
2211 Constant_Present
(Parameter_Type
(First_Param
)));
2213 Obj_Param_Typ
:= New_Occurrence_Of
(Obj_Typ
, Loc
);
2217 Make_Parameter_Specification
(Loc
,
2218 Defining_Identifier
=>
2219 Make_Defining_Identifier
(Loc
,
2221 In_Present
=> In_Present
(First_Param
),
2222 Out_Present
=> Out_Present
(First_Param
),
2223 Parameter_Type
=> Obj_Param_Typ
);
2225 Prepend_To
(New_Formals
, Obj_Param
);
2227 -- If we are dealing with a primitive declared between two views,
2228 -- implemented by a synchronized operation, we need to create
2229 -- a default parameter. The mode of the parameter must match that
2230 -- of the primitive operation.
2233 pragma Assert
(Is_Private_Primitive_Subprogram
(Subp_Id
));
2236 Make_Parameter_Specification
(Loc
,
2237 Defining_Identifier
=>
2238 Make_Defining_Identifier
(Loc
, Name_uO
),
2240 In_Present
(Parent
(First_Entity
(Subp_Id
))),
2241 Out_Present
=> Ekind
(Subp_Id
) /= E_Function
,
2242 Parameter_Type
=> New_Occurrence_Of
(Obj_Typ
, Loc
));
2244 Prepend_To
(New_Formals
, Obj_Param
);
2247 -- Build the final spec. If it is a function with a controlling
2248 -- result, it is a primitive operation of the corresponding
2249 -- record type, so mark the spec accordingly.
2251 if Ekind
(Subp_Id
) = E_Function
then
2256 if Has_Controlling_Result
(Subp_Id
) then
2259 (Corresponding_Record_Type
(Etype
(Subp_Id
)), Loc
);
2261 Res_Def
:= New_Copy
(Result_Definition
(Parent
(Subp_Id
)));
2265 Make_Function_Specification
(Loc
,
2266 Defining_Unit_Name
=> Wrapper_Id
,
2267 Parameter_Specifications
=> New_Formals
,
2268 Result_Definition
=> Res_Def
);
2272 Make_Procedure_Specification
(Loc
,
2273 Defining_Unit_Name
=> Wrapper_Id
,
2274 Parameter_Specifications
=> New_Formals
);
2277 end Build_Wrapper_Spec
;
2279 -------------------------
2280 -- Build_Wrapper_Specs --
2281 -------------------------
2283 procedure Build_Wrapper_Specs
2289 Rec_Typ
: Entity_Id
;
2290 procedure Scan_Declarations
(L
: List_Id
);
2291 -- Common processing for visible and private declarations
2292 -- of a protected type.
2294 procedure Scan_Declarations
(L
: List_Id
) is
2296 Wrap_Decl
: Node_Id
;
2297 Wrap_Spec
: Node_Id
;
2305 while Present
(Decl
) loop
2308 if Nkind
(Decl
) = N_Entry_Declaration
2309 and then Ekind
(Defining_Identifier
(Decl
)) = E_Entry
2313 (Subp_Id
=> Defining_Identifier
(Decl
),
2315 Formals
=> Parameter_Specifications
(Decl
));
2317 elsif Nkind
(Decl
) = N_Subprogram_Declaration
then
2320 (Subp_Id
=> Defining_Unit_Name
(Specification
(Decl
)),
2323 Parameter_Specifications
(Specification
(Decl
)));
2326 if Present
(Wrap_Spec
) then
2328 Make_Subprogram_Declaration
(Loc
,
2329 Specification
=> Wrap_Spec
);
2331 Insert_After
(N
, Wrap_Decl
);
2334 Analyze
(Wrap_Decl
);
2339 end Scan_Declarations
;
2341 -- start of processing for Build_Wrapper_Specs
2344 if Is_Protected_Type
(Typ
) then
2345 Def
:= Protected_Definition
(Parent
(Typ
));
2346 else pragma Assert
(Is_Task_Type
(Typ
));
2347 Def
:= Task_Definition
(Parent
(Typ
));
2350 Rec_Typ
:= Corresponding_Record_Type
(Typ
);
2352 -- Generate wrapper specs for a concurrent type which implements an
2353 -- interface. Operations in both the visible and private parts may
2354 -- implement progenitor operations.
2356 if Present
(Interfaces
(Rec_Typ
)) and then Present
(Def
) then
2357 Scan_Declarations
(Visible_Declarations
(Def
));
2358 Scan_Declarations
(Private_Declarations
(Def
));
2360 end Build_Wrapper_Specs
;
2362 ---------------------------
2363 -- Build_Find_Body_Index --
2364 ---------------------------
2366 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
2367 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2370 Has_F
: Boolean := False;
2372 If_St
: Node_Id
:= Empty
;
2375 Decls
: List_Id
:= New_List
;
2376 Ret
: Node_Id
:= Empty
;
2378 Siz
: Node_Id
:= Empty
;
2380 procedure Add_If_Clause
(Expr
: Node_Id
);
2381 -- Add test for range of current entry
2383 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
2384 -- If a bound of an entry is given by a discriminant, retrieve the
2385 -- actual value of the discriminant from the enclosing object.
2391 procedure Add_If_Clause
(Expr
: Node_Id
) is
2393 Stats
: constant List_Id
:=
2395 Make_Simple_Return_Statement
(Loc
,
2396 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
2399 -- Index for current entry body
2403 -- Compute total length of entry queues so far
2411 Right_Opnd
=> Expr
);
2416 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
2419 -- Map entry queue indexes in the range of the current family
2420 -- into the current index, that designates the entry body.
2424 Make_Implicit_If_Statement
(Typ
,
2426 Then_Statements
=> Stats
,
2427 Elsif_Parts
=> New_List
);
2431 Append_To
(Elsif_Parts
(If_St
),
2432 Make_Elsif_Part
(Loc
,
2434 Then_Statements
=> Stats
));
2438 ------------------------------
2439 -- Convert_Discriminant_Ref --
2440 ------------------------------
2442 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
2446 if Is_Entity_Name
(Bound
)
2447 and then Ekind
(Entity
(Bound
)) = E_Discriminant
2450 Make_Selected_Component
(Loc
,
2452 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2453 Make_Explicit_Dereference
(Loc
,
2454 Make_Identifier
(Loc
, Name_uObject
))),
2455 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
2456 Set_Etype
(B
, Etype
(Entity
(Bound
)));
2458 B
:= New_Copy_Tree
(Bound
);
2462 end Convert_Discriminant_Ref
;
2464 -- Start of processing for Build_Find_Body_Index
2467 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
2469 Ent
:= First_Entity
(Typ
);
2470 while Present
(Ent
) loop
2471 if Ekind
(Ent
) = E_Entry_Family
then
2481 -- If the protected type has no entry families, there is a one-one
2482 -- correspondence between entry queue and entry body.
2485 Make_Simple_Return_Statement
(Loc
,
2486 Expression
=> Make_Identifier
(Loc
, Name_uE
));
2489 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2492 -- if E <= l1 then return 1;
2493 -- elsif E <= l1 + l2 then return 2;
2498 Ent
:= First_Entity
(Typ
);
2500 Add_Object_Pointer
(Loc
, Typ
, Decls
);
2502 while Present
(Ent
) loop
2503 if Ekind
(Ent
) = E_Entry
then
2504 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
2506 elsif Ekind
(Ent
) = E_Entry_Family
then
2507 E_Typ
:= Entry_Index_Type
(Ent
);
2508 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
2509 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
2510 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
, False));
2519 Make_Simple_Return_Statement
(Loc
,
2520 Expression
=> Make_Integer_Literal
(Loc
, 1));
2523 -- Ranges are in increasing order, so last one doesn't need guard
2526 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
2529 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
2531 -- If Elsif_Parts becomes empty then remove it entirely, as
2532 -- otherwise we would violate the invariant of If_Statement
2533 -- node described in Sinfo.
2535 if Is_Empty_List
(Elsif_Parts
(Ret
)) then
2536 pragma Assert
(Elsif_Parts
(Ret
) /= No_List
);
2537 Set_Elsif_Parts
(Ret
, No_List
);
2544 Make_Subprogram_Body
(Loc
,
2545 Specification
=> Spec
,
2546 Declarations
=> Decls
,
2547 Handled_Statement_Sequence
=>
2548 Make_Handled_Sequence_Of_Statements
(Loc
,
2549 Statements
=> New_List
(Ret
)));
2550 end Build_Find_Body_Index
;
2552 --------------------------------
2553 -- Build_Find_Body_Index_Spec --
2554 --------------------------------
2556 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
2557 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2558 Id
: constant Entity_Id
:=
2559 Make_Defining_Identifier
(Loc
,
2560 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
2561 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
2562 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
2566 Make_Function_Specification
(Loc
,
2567 Defining_Unit_Name
=> Id
,
2568 Parameter_Specifications
=> New_List
(
2569 Make_Parameter_Specification
(Loc
,
2570 Defining_Identifier
=> Parm1
,
2572 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2574 Make_Parameter_Specification
(Loc
,
2575 Defining_Identifier
=> Parm2
,
2577 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))),
2579 Result_Definition
=> New_Occurrence_Of
(
2580 RTE
(RE_Protected_Entry_Index
), Loc
));
2581 end Build_Find_Body_Index_Spec
;
2583 -----------------------------------------------
2584 -- Build_Lock_Free_Protected_Subprogram_Body --
2585 -----------------------------------------------
2587 function Build_Lock_Free_Protected_Subprogram_Body
2590 Unprot_Spec
: Node_Id
) return Node_Id
2592 Actuals
: constant List_Id
:= New_List
;
2593 Loc
: constant Source_Ptr
:= Sloc
(N
);
2594 Spec
: constant Node_Id
:= Specification
(N
);
2595 Unprot_Id
: constant Entity_Id
:= Defining_Unit_Name
(Unprot_Spec
);
2597 Prot_Spec
: Node_Id
;
2601 -- Create the protected version of the body
2604 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Protected_Mode
);
2606 -- Build the actual parameters which appear in the call to the
2607 -- unprotected version of the body.
2609 Formal
:= First
(Parameter_Specifications
(Prot_Spec
));
2610 while Present
(Formal
) loop
2612 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
2617 -- Function case, generate:
2618 -- return <Unprot_Func_Call>;
2620 if Nkind
(Spec
) = N_Function_Specification
then
2622 Make_Simple_Return_Statement
(Loc
,
2624 Make_Function_Call
(Loc
,
2626 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2627 Parameter_Associations
=> Actuals
));
2629 -- Procedure case, call the unprotected version
2633 Make_Procedure_Call_Statement
(Loc
,
2635 Make_Identifier
(Loc
, Chars
(Unprot_Id
)),
2636 Parameter_Associations
=> Actuals
);
2640 Make_Subprogram_Body
(Loc
,
2641 Declarations
=> Empty_List
,
2642 Specification
=> Prot_Spec
,
2643 Handled_Statement_Sequence
=>
2644 Make_Handled_Sequence_Of_Statements
(Loc
,
2645 Statements
=> New_List
(Stmt
)));
2646 end Build_Lock_Free_Protected_Subprogram_Body
;
2648 -------------------------------------------------
2649 -- Build_Lock_Free_Unprotected_Subprogram_Body --
2650 -------------------------------------------------
2652 -- Procedures which meet the lock-free implementation requirements and
2653 -- reference a unique scalar component Comp are expanded in the following
2656 -- procedure P (...) is
2657 -- Expected_Comp : constant Comp_Type :=
2659 -- (System.Atomic_Primitives.Lock_Free_Read_N
2660 -- (_Object.Comp'Address));
2664 -- <original declarations before the object renaming declaration
2667 -- Desired_Comp : Comp_Type := Expected_Comp;
2668 -- Comp : Comp_Type renames Desired_Comp;
2670 -- <original declarations after the object renaming declaration
2674 -- <original statements>
2675 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
2676 -- (_Object.Comp'Address,
2677 -- Interfaces.Unsigned_N (Expected_Comp),
2678 -- Interfaces.Unsigned_N (Desired_Comp));
2683 -- Each return and raise statement of P is transformed into an atomic
2686 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2687 -- (_Object.Comp'Address,
2688 -- Interfaces.Unsigned_N (Expected_Comp),
2689 -- Interfaces.Unsigned_N (Desired_Comp));
2691 -- <original statement>
2696 -- Functions which meet the lock-free implementation requirements and
2697 -- reference a unique scalar component Comp are expanded in the following
2700 -- function F (...) return ... is
2701 -- <original declarations before the object renaming declaration
2704 -- Expected_Comp : constant Comp_Type :=
2706 -- (System.Atomic_Primitives.Lock_Free_Read_N
2707 -- (_Object.Comp'Address));
2708 -- Comp : Comp_Type renames Expected_Comp;
2710 -- <original declarations after the object renaming declaration of
2714 -- <original statements>
2717 function Build_Lock_Free_Unprotected_Subprogram_Body
2719 Prot_Typ
: Node_Id
) return Node_Id
2721 function Referenced_Component
(N
: Node_Id
) return Entity_Id
;
2722 -- Subprograms which meet the lock-free implementation criteria are
2723 -- allowed to reference only one unique component. Return the prival
2724 -- of the said component.
2726 --------------------------
2727 -- Referenced_Component --
2728 --------------------------
2730 function Referenced_Component
(N
: Node_Id
) return Entity_Id
is
2733 Source_Comp
: Entity_Id
:= Empty
;
2736 -- Find the unique source component which N references in its
2739 for Index
in 1 .. Lock_Free_Subprogram_Table
.Last
loop
2741 Element
: Lock_Free_Subprogram
renames
2742 Lock_Free_Subprogram_Table
.Table
(Index
);
2744 if Element
.Sub_Body
= N
then
2745 Source_Comp
:= Element
.Comp_Id
;
2751 if No
(Source_Comp
) then
2755 -- Find the prival which corresponds to the source component within
2756 -- the declarations of N.
2758 Decl
:= First
(Declarations
(N
));
2759 while Present
(Decl
) loop
2761 -- Privals appear as object renamings
2763 if Nkind
(Decl
) = N_Object_Renaming_Declaration
then
2764 Comp
:= Defining_Identifier
(Decl
);
2766 if Present
(Prival_Link
(Comp
))
2767 and then Prival_Link
(Comp
) = Source_Comp
2777 end Referenced_Component
;
2781 Comp
: constant Entity_Id
:= Referenced_Component
(N
);
2782 Loc
: constant Source_Ptr
:= Sloc
(N
);
2783 Hand_Stmt_Seq
: Node_Id
:= Handled_Statement_Sequence
(N
);
2784 Decls
: List_Id
:= Declarations
(N
);
2786 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
2789 -- Add renamings for the protection object, discriminals, privals, and
2790 -- the entry index constant for use by debugger.
2792 Debug_Private_Data_Declarations
(Decls
);
2794 -- Perform the lock-free expansion when the subprogram references a
2795 -- protected component.
2797 if Present
(Comp
) then
2798 Protected_Component_Ref
: declare
2799 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
2800 Comp_Sel_Nam
: constant Node_Id
:= Name
(Comp_Decl
);
2801 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
2803 Is_Procedure
: constant Boolean :=
2804 Ekind
(Corresponding_Spec
(N
)) = E_Procedure
;
2805 -- Indicates if N is a protected procedure body
2807 Block_Decls
: List_Id
:= No_List
;
2808 Try_Write
: Entity_Id
;
2809 Desired_Comp
: Entity_Id
;
2812 Label_Id
: Entity_Id
:= Empty
;
2814 Expected_Comp
: Entity_Id
;
2817 New_Copy_List_Tree
(Statements
(Hand_Stmt_Seq
));
2819 Unsigned
: Entity_Id
;
2821 function Process_Node
(N
: Node_Id
) return Traverse_Result
;
2822 -- Transform a single node if it is a return statement, a raise
2823 -- statement or a reference to Comp.
2825 procedure Process_Stmts
(Stmts
: List_Id
);
2826 -- Given a statement sequence Stmts, wrap any return or raise
2827 -- statements in the following manner:
2829 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2830 -- (_Object.Comp'Address,
2831 -- Interfaces.Unsigned_N (Expected_Comp),
2832 -- Interfaces.Unsigned_N (Desired_Comp))
2843 function Process_Node
(N
: Node_Id
) return Traverse_Result
is
2845 procedure Wrap_Statement
(Stmt
: Node_Id
);
2846 -- Wrap an arbitrary statement inside an if statement where the
2847 -- condition does an atomic check on the state of the object.
2849 --------------------
2850 -- Wrap_Statement --
2851 --------------------
2853 procedure Wrap_Statement
(Stmt
: Node_Id
) is
2855 -- The first time through, create the declaration of a label
2856 -- which is used to skip the remainder of source statements
2857 -- if the state of the object has changed.
2859 if No
(Label_Id
) then
2861 Make_Identifier
(Loc
, New_External_Name
('L', 0));
2862 Set_Entity
(Label_Id
,
2863 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
2867 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2868 -- (_Object.Comp'Address,
2869 -- Interfaces.Unsigned_N (Expected_Comp),
2870 -- Interfaces.Unsigned_N (Desired_Comp))
2878 Make_Implicit_If_Statement
(N
,
2880 Make_Function_Call
(Loc
,
2882 New_Occurrence_Of
(Try_Write
, Loc
),
2883 Parameter_Associations
=> New_List
(
2884 Make_Attribute_Reference
(Loc
,
2885 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
2886 Attribute_Name
=> Name_Address
),
2888 Unchecked_Convert_To
(Unsigned
,
2889 New_Occurrence_Of
(Expected_Comp
, Loc
)),
2891 Unchecked_Convert_To
(Unsigned
,
2892 New_Occurrence_Of
(Desired_Comp
, Loc
)))),
2894 Then_Statements
=> New_List
(Relocate_Node
(Stmt
)),
2896 Else_Statements
=> New_List
(
2897 Make_Goto_Statement
(Loc
,
2899 New_Occurrence_Of
(Entity
(Label_Id
), Loc
)))));
2902 -- Start of processing for Process_Node
2905 -- Wrap each return and raise statement that appear inside a
2906 -- procedure. Skip the last return statement which is added by
2907 -- default since it is transformed into an exit statement.
2910 and then ((Nkind
(N
) = N_Simple_Return_Statement
2911 and then N
/= Last
(Stmts
))
2912 or else Nkind
(N
) = N_Extended_Return_Statement
2913 or else (Nkind
(N
) in
2914 N_Raise_xxx_Error | N_Raise_Statement
2915 and then Comes_From_Source
(N
)))
2923 Set_Analyzed
(N
, False);
2928 procedure Process_Nodes
is new Traverse_Proc
(Process_Node
);
2934 procedure Process_Stmts
(Stmts
: List_Id
) is
2937 Stmt
:= First
(Stmts
);
2938 while Present
(Stmt
) loop
2939 Process_Nodes
(Stmt
);
2944 -- Start of processing for Protected_Component_Ref
2947 -- Get the type size
2949 if Known_Static_Esize
(Comp_Type
) then
2950 Typ_Size
:= UI_To_Int
(Esize
(Comp_Type
));
2952 -- If the Esize (Object_Size) is unknown at compile time, look at
2953 -- the RM_Size (Value_Size) since it may have been set by an
2954 -- explicit representation clause.
2956 elsif Known_Static_RM_Size
(Comp_Type
) then
2957 Typ_Size
:= UI_To_Int
(RM_Size
(Comp_Type
));
2959 -- Should not happen since this has already been checked in
2960 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
2963 raise Program_Error
;
2966 -- Retrieve all relevant atomic routines and types
2970 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_8
);
2971 Read
:= RTE
(RE_Lock_Free_Read_8
);
2972 Unsigned
:= RTE
(RE_Uint8
);
2975 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_16
);
2976 Read
:= RTE
(RE_Lock_Free_Read_16
);
2977 Unsigned
:= RTE
(RE_Uint16
);
2980 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_32
);
2981 Read
:= RTE
(RE_Lock_Free_Read_32
);
2982 Unsigned
:= RTE
(RE_Uint32
);
2985 Try_Write
:= RTE
(RE_Lock_Free_Try_Write_64
);
2986 Read
:= RTE
(RE_Lock_Free_Read_64
);
2987 Unsigned
:= RTE
(RE_Uint64
);
2990 raise Program_Error
;
2994 -- Expected_Comp : constant Comp_Type :=
2996 -- (System.Atomic_Primitives.Lock_Free_Read_N
2997 -- (_Object.Comp'Address));
3000 Make_Defining_Identifier
(Loc
,
3001 New_External_Name
(Chars
(Comp
), Suffix
=> "_saved"));
3004 Make_Object_Declaration
(Loc
,
3005 Defining_Identifier
=> Expected_Comp
,
3006 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3007 Constant_Present
=> True,
3009 Unchecked_Convert_To
(Comp_Type
,
3010 Make_Function_Call
(Loc
,
3011 Name
=> New_Occurrence_Of
(Read
, Loc
),
3012 Parameter_Associations
=> New_List
(
3013 Make_Attribute_Reference
(Loc
,
3014 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3015 Attribute_Name
=> Name_Address
)))));
3017 -- Protected procedures
3019 if Is_Procedure
then
3020 -- Move the original declarations inside the generated block
3022 Block_Decls
:= Decls
;
3024 -- Reset the declarations list of the protected procedure to
3025 -- contain only Decl.
3027 Decls
:= New_List
(Decl
);
3030 -- Desired_Comp : Comp_Type := Expected_Comp;
3033 Make_Defining_Identifier
(Loc
,
3034 New_External_Name
(Chars
(Comp
), Suffix
=> "_current"));
3036 -- Insert the declarations of Expected_Comp and Desired_Comp in
3037 -- the block declarations right before the renaming of the
3038 -- protected component.
3040 Insert_Before
(Comp_Decl
,
3041 Make_Object_Declaration
(Loc
,
3042 Defining_Identifier
=> Desired_Comp
,
3043 Object_Definition
=> New_Occurrence_Of
(Comp_Type
, Loc
),
3045 New_Occurrence_Of
(Expected_Comp
, Loc
)));
3047 -- Protected function
3050 Desired_Comp
:= Expected_Comp
;
3052 -- Insert the declaration of Expected_Comp in the function
3053 -- declarations right before the renaming of the protected
3056 Insert_Before
(Comp_Decl
, Decl
);
3059 -- Rewrite the protected component renaming declaration to be a
3060 -- renaming of Desired_Comp.
3063 -- Comp : Comp_Type renames Desired_Comp;
3066 Make_Object_Renaming_Declaration
(Loc
,
3067 Defining_Identifier
=>
3068 Defining_Identifier
(Comp_Decl
),
3070 New_Occurrence_Of
(Comp_Type
, Loc
),
3072 New_Occurrence_Of
(Desired_Comp
, Loc
)));
3074 -- Wrap any return or raise statements in Stmts in same the manner
3075 -- described in Process_Stmts.
3077 Process_Stmts
(Stmts
);
3080 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3081 -- (_Object.Comp'Address,
3082 -- Interfaces.Unsigned_N (Expected_Comp),
3083 -- Interfaces.Unsigned_N (Desired_Comp))
3085 if Is_Procedure
then
3087 Make_Exit_Statement
(Loc
,
3089 Make_Function_Call
(Loc
,
3091 New_Occurrence_Of
(Try_Write
, Loc
),
3092 Parameter_Associations
=> New_List
(
3093 Make_Attribute_Reference
(Loc
,
3094 Prefix
=> Relocate_Node
(Comp_Sel_Nam
),
3095 Attribute_Name
=> Name_Address
),
3097 Unchecked_Convert_To
(Unsigned
,
3098 New_Occurrence_Of
(Expected_Comp
, Loc
)),
3100 Unchecked_Convert_To
(Unsigned
,
3101 New_Occurrence_Of
(Desired_Comp
, Loc
)))));
3103 -- Small optimization: transform the default return statement
3104 -- of a procedure into the atomic exit statement.
3106 if Nkind
(Last
(Stmts
)) = N_Simple_Return_Statement
then
3107 Rewrite
(Last
(Stmts
), Stmt
);
3109 Append_To
(Stmts
, Stmt
);
3113 -- Create the declaration of the label used to skip the rest of
3114 -- the source statements when the object state changes.
3116 if Present
(Label_Id
) then
3117 Label
:= Make_Label
(Loc
, Label_Id
);
3119 Make_Implicit_Label_Declaration
(Loc
,
3120 Defining_Identifier
=> Entity
(Label_Id
),
3121 Label_Construct
=> Label
));
3122 Append_To
(Stmts
, Label
);
3134 if Is_Procedure
then
3137 Make_Loop_Statement
(Loc
,
3138 Statements
=> New_List
(
3139 Make_Block_Statement
(Loc
,
3140 Declarations
=> Block_Decls
,
3141 Handled_Statement_Sequence
=>
3142 Make_Handled_Sequence_Of_Statements
(Loc
,
3143 Statements
=> Stmts
))),
3144 End_Label
=> Empty
));
3148 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
);
3149 end Protected_Component_Ref
;
3152 -- Make an unprotected version of the subprogram for use within the same
3153 -- object, with new name and extra parameter representing the object.
3156 Make_Subprogram_Body
(Loc
,
3158 Build_Protected_Sub_Specification
(N
, Prot_Typ
, Unprotected_Mode
),
3159 Declarations
=> Decls
,
3160 Handled_Statement_Sequence
=> Hand_Stmt_Seq
);
3161 end Build_Lock_Free_Unprotected_Subprogram_Body
;
3163 -------------------------
3164 -- Build_Master_Entity --
3165 -------------------------
3167 procedure Build_Master_Entity
(Obj_Or_Typ
: Entity_Id
) is
3168 Loc
: constant Source_Ptr
:= Sloc
(Obj_Or_Typ
);
3170 Context_Id
: Entity_Id
;
3176 -- No action needed if the run-time has no tasking support
3178 if Global_No_Tasking
then
3182 if Is_Itype
(Obj_Or_Typ
) then
3183 Par
:= Associated_Node_For_Itype
(Obj_Or_Typ
);
3185 Par
:= Parent
(Obj_Or_Typ
);
3188 -- When creating a master for a record component which is either a task
3189 -- or access-to-task, the enclosing record is the master scope and the
3190 -- proper insertion point is the component list.
3192 if Is_Record_Type
(Current_Scope
) then
3194 Context_Id
:= Current_Scope
;
3195 Decls
:= List_Containing
(Context
);
3197 -- Default case for object declarations and access types. Note that the
3198 -- context is updated to the nearest enclosing body, block, package, or
3199 -- return statement.
3202 Find_Enclosing_Context
(Par
, Context
, Context_Id
, Decls
);
3205 -- When the enclosing context is a BIP function whose result type has
3206 -- tasks, the function has an extra formal that is the master of the
3207 -- tasks to be created by its returned object (that is, when its
3208 -- enclosing context is a return statement). However, if the body of
3209 -- the function creates tasks before its return statements, such tasks
3210 -- need their own master.
3212 if Has_Master_Entity
(Context_Id
)
3213 and then Ekind
(Context_Id
) = E_Function
3214 and then Is_Build_In_Place_Function
(Context_Id
)
3215 and then Needs_BIP_Task_Actuals
(Context_Id
)
3217 -- No need to add it again if previously added
3220 Master_Present
: Boolean;
3223 -- Handle transient scopes
3225 if Context_Id
/= Current_Scope
then
3226 Push_Scope
(Context_Id
);
3228 Present
(Current_Entity_In_Scope
(Name_uMaster
));
3232 Present
(Current_Entity_In_Scope
(Name_uMaster
));
3235 if Master_Present
then
3240 -- Nothing to do if the context already has a master; internally built
3241 -- finalizers don't need a master.
3243 elsif Has_Master_Entity
(Context_Id
)
3244 or else Is_Finalizer
(Context_Id
)
3249 Decl
:= Build_Master_Declaration
(Loc
);
3251 -- The master is inserted at the start of the declarative list of the
3254 Prepend_To
(Decls
, Decl
);
3256 -- In certain cases where transient scopes are involved, the immediate
3257 -- scope is not always the proper master scope. Ensure that the master
3258 -- declaration and entity appear in the same context.
3260 if Context_Id
/= Current_Scope
then
3261 Push_Scope
(Context_Id
);
3268 -- Mark the enclosing scope and its associated construct as being task
3271 Set_Has_Master_Entity
(Context_Id
);
3273 while Present
(Context
)
3274 and then Nkind
(Context
) /= N_Compilation_Unit
3276 if Nkind
(Context
) in
3277 N_Block_Statement | N_Subprogram_Body | N_Task_Body
3279 Set_Is_Task_Master
(Context
);
3282 elsif Nkind
(Parent
(Context
)) = N_Subunit
then
3283 Context
:= Corresponding_Stub
(Parent
(Context
));
3286 Context
:= Parent
(Context
);
3288 end Build_Master_Entity
;
3290 ---------------------------
3291 -- Build_Master_Renaming --
3292 ---------------------------
3294 procedure Build_Master_Renaming
3295 (Ptr_Typ
: Entity_Id
;
3296 Ins_Nod
: Node_Id
:= Empty
)
3298 Loc
: constant Source_Ptr
:= Sloc
(Ptr_Typ
);
3300 Master_Decl
: Node_Id
;
3301 Master_Id
: Entity_Id
;
3304 -- No action needed if the run-time has no tasking support
3306 if Global_No_Tasking
then
3310 -- Determine the proper context to insert the master renaming
3312 if Present
(Ins_Nod
) then
3315 elsif Is_Itype
(Ptr_Typ
) then
3316 Context
:= Associated_Node_For_Itype
(Ptr_Typ
);
3318 -- When the context references a discriminant or a component of a
3319 -- private type and we are processing declarations in the private
3320 -- part of the enclosing package, we must insert the master renaming
3321 -- before the full declaration of the private type; otherwise the
3322 -- master renaming would be inserted in the public part of the
3323 -- package (and hence before the declaration of _master).
3325 if In_Private_Part
(Current_Scope
) then
3327 Ctx
: Node_Id
:= Context
;
3330 if Nkind
(Context
) = N_Discriminant_Specification
then
3331 Ctx
:= Parent
(Ctx
);
3333 while Nkind
(Ctx
) in
3334 N_Component_Declaration | N_Component_List
3336 Ctx
:= Parent
(Ctx
);
3340 if Nkind
(Ctx
) in N_Private_Type_Declaration
3341 | N_Private_Extension_Declaration
3343 Context
:= Parent
(Full_View
(Defining_Identifier
(Ctx
)));
3349 Context
:= Parent
(Ptr_Typ
);
3353 -- <Ptr_Typ>M : Master_Id renames _Master;
3354 -- and add a numeric suffix to the name to ensure that it is
3355 -- unique in case other access types in nested constructs
3356 -- are homonyms of this one.
3359 Make_Defining_Identifier
(Loc
,
3360 New_External_Name
(Chars
(Ptr_Typ
), 'M', -1));
3363 Make_Object_Renaming_Declaration
(Loc
,
3364 Defining_Identifier
=> Master_Id
,
3366 New_Occurrence_Of
(Standard_Integer
, Loc
),
3367 Name
=> Make_Identifier
(Loc
, Name_uMaster
));
3369 Insert_Action
(Context
, Master_Decl
);
3371 -- The renamed master now services the access type
3373 Set_Master_Id
(Ptr_Typ
, Master_Id
);
3374 end Build_Master_Renaming
;
3376 ---------------------------
3377 -- Build_Protected_Entry --
3378 ---------------------------
3380 function Build_Protected_Entry
3383 Pid
: Node_Id
) return Node_Id
3385 Bod_Decls
: constant List_Id
:= New_List
;
3386 Decls
: constant List_Id
:= Declarations
(N
);
3387 End_Lab
: constant Node_Id
:=
3388 End_Label
(Handled_Statement_Sequence
(N
));
3389 End_Loc
: constant Source_Ptr
:=
3390 Sloc
(Last
(Statements
(Handled_Statement_Sequence
(N
))));
3391 -- Used for the generated call to Complete_Entry_Body
3393 Loc
: constant Source_Ptr
:= Sloc
(N
);
3395 Block_Id
: Entity_Id
;
3398 Bod_Stmts
: List_Id
;
3401 Proc_Body
: Node_Id
;
3403 EH_Loc
: Source_Ptr
;
3404 -- Used for the exception handler, inserted at end of the body
3407 -- Set the source location on the exception handler only when debugging
3408 -- the expanded code (see Make_Implicit_Exception_Handler).
3410 if Debug_Generated_Code
then
3413 -- Otherwise the inserted code should not be visible to the debugger
3416 EH_Loc
:= No_Location
;
3420 Make_Defining_Identifier
(Loc
,
3421 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
3422 Bod_Spec
:= Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Empty
);
3424 -- Add the following declarations:
3426 -- type poVP is access poV;
3427 -- _object : poVP := poVP (_O);
3429 -- where _O is the formal parameter associated with the concurrent
3430 -- object. These declarations are needed for Complete_Entry_Body.
3432 Add_Object_Pointer
(Loc
, Pid
, Bod_Decls
);
3434 -- Add renamings for all formals, the Protection object, discriminals,
3435 -- privals and the entry index constant for use by debugger.
3437 Add_Formal_Renamings
(Bod_Spec
, Bod_Decls
, Ent
, Loc
);
3438 Debug_Private_Data_Declarations
(Decls
);
3440 -- Put the declarations and the statements from the entry
3444 Make_Block_Statement
(Loc
,
3445 Declarations
=> Decls
,
3446 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
)));
3448 -- Analyze now and reset scopes for declarations so that Scope fields
3449 -- currently denoting the entry will now denote the block scope, and
3450 -- the block's scope will be set to the new procedure entity.
3452 Analyze_Statements
(Bod_Stmts
);
3454 Block_Id
:= Entity
(Identifier
(First
(Bod_Stmts
)));
3456 Set_Scope
(Block_Id
, Protected_Body_Subprogram
(Ent
));
3457 Set_Uses_Sec_Stack
(Block_Id
, Uses_Sec_Stack
(Corresponding_Spec
(N
)));
3459 Reset_Scopes_To
(First
(Bod_Stmts
), Block_Id
);
3461 case Corresponding_Runtime_Package
(Pid
) is
3462 when System_Tasking_Protected_Objects_Entries
=>
3463 Append_To
(Bod_Stmts
,
3464 Make_Procedure_Call_Statement
(End_Loc
,
3466 New_Occurrence_Of
(RTE
(RE_Complete_Entry_Body
), Loc
),
3467 Parameter_Associations
=> New_List
(
3468 Make_Attribute_Reference
(End_Loc
,
3470 Make_Selected_Component
(End_Loc
,
3472 Make_Identifier
(End_Loc
, Name_uObject
),
3474 Make_Identifier
(End_Loc
, Name_uObject
)),
3475 Attribute_Name
=> Name_Unchecked_Access
))));
3477 when System_Tasking_Protected_Objects_Single_Entry
=>
3479 -- Historically, a call to Complete_Single_Entry_Body was
3480 -- inserted, but it was a null procedure.
3485 raise Program_Error
;
3488 -- When exceptions cannot be propagated, we never need to call
3489 -- Exception_Complete_Entry_Body.
3491 if No_Exception_Handlers_Set
then
3493 Make_Subprogram_Body
(Loc
,
3494 Specification
=> Bod_Spec
,
3495 Declarations
=> Bod_Decls
,
3496 Handled_Statement_Sequence
=>
3497 Make_Handled_Sequence_Of_Statements
(Loc
,
3498 Statements
=> Bod_Stmts
,
3499 End_Label
=> End_Lab
));
3502 Ohandle
:= Make_Others_Choice
(Loc
);
3503 Set_All_Others
(Ohandle
);
3505 case Corresponding_Runtime_Package
(Pid
) is
3506 when System_Tasking_Protected_Objects_Entries
=>
3509 (RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
3511 when System_Tasking_Protected_Objects_Single_Entry
=>
3514 (RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
3517 raise Program_Error
;
3520 -- Create body of entry procedure. The renaming declarations are
3521 -- placed ahead of the block that contains the actual entry body.
3524 Make_Subprogram_Body
(Loc
,
3525 Specification
=> Bod_Spec
,
3526 Declarations
=> Bod_Decls
,
3527 Handled_Statement_Sequence
=>
3528 Make_Handled_Sequence_Of_Statements
(Loc
,
3529 Statements
=> Bod_Stmts
,
3530 End_Label
=> End_Lab
,
3531 Exception_Handlers
=> New_List
(
3532 Make_Implicit_Exception_Handler
(EH_Loc
,
3533 Exception_Choices
=> New_List
(Ohandle
),
3535 Statements
=> New_List
(
3536 Make_Procedure_Call_Statement
(EH_Loc
,
3538 Parameter_Associations
=> New_List
(
3539 Make_Attribute_Reference
(EH_Loc
,
3541 Make_Selected_Component
(EH_Loc
,
3543 Make_Identifier
(EH_Loc
, Name_uObject
),
3545 Make_Identifier
(EH_Loc
, Name_uObject
)),
3546 Attribute_Name
=> Name_Unchecked_Access
),
3548 Make_Function_Call
(EH_Loc
,
3551 (RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
3553 -- Establish link between subprogram body and source entry body
3555 Set_Corresponding_Entry_Body
(Proc_Body
, N
);
3556 Set_At_End_Proc
(Proc_Body
, At_End_Proc
(N
));
3558 Reset_Scopes_To
(Proc_Body
, Protected_Body_Subprogram
(Ent
));
3561 end Build_Protected_Entry
;
3563 -----------------------------------------
3564 -- Build_Protected_Entry_Specification --
3565 -----------------------------------------
3567 function Build_Protected_Entry_Specification
3570 Ent_Id
: Entity_Id
) return Node_Id
3572 P
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uP
);
3575 Set_Debug_Info_Needed
(Def_Id
);
3577 if Present
(Ent_Id
) then
3578 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
3582 Make_Procedure_Specification
(Loc
,
3583 Defining_Unit_Name
=> Def_Id
,
3584 Parameter_Specifications
=> New_List
(
3585 Make_Parameter_Specification
(Loc
,
3586 Defining_Identifier
=>
3587 Make_Defining_Identifier
(Loc
, Name_uO
),
3589 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3591 Make_Parameter_Specification
(Loc
,
3592 Defining_Identifier
=> P
,
3594 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3596 Make_Parameter_Specification
(Loc
,
3597 Defining_Identifier
=>
3598 Make_Defining_Identifier
(Loc
, Name_uE
),
3600 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
))));
3601 end Build_Protected_Entry_Specification
;
3603 --------------------------
3604 -- Build_Protected_Spec --
3605 --------------------------
3607 function Build_Protected_Spec
3609 Obj_Type
: Entity_Id
;
3611 Unprotected
: Boolean := False) return List_Id
3613 Loc
: constant Source_Ptr
:= Sloc
(N
);
3617 New_Formal
: Entity_Id
;
3618 New_Plist
: List_Id
;
3621 New_Plist
:= New_List
;
3623 Formal
:= First_Formal
(Ident
);
3624 while Present
(Formal
) loop
3626 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
3627 Set_Comes_From_Source
(New_Formal
, Comes_From_Source
(Formal
));
3630 Mutate_Ekind
(New_Formal
, Ekind
(Formal
));
3631 Set_Protected_Formal
(Formal
, New_Formal
);
3634 Append_To
(New_Plist
,
3635 Make_Parameter_Specification
(Loc
,
3636 Defining_Identifier
=> New_Formal
,
3637 Aliased_Present
=> Aliased_Present
(Parent
(Formal
)),
3638 In_Present
=> In_Present
(Parent
(Formal
)),
3639 Out_Present
=> Out_Present
(Parent
(Formal
)),
3640 Parameter_Type
=> New_Occurrence_Of
(Etype
(Formal
), Loc
)));
3642 Next_Formal
(Formal
);
3645 -- If the subprogram is a procedure and the context is not an access
3646 -- to protected subprogram, the parameter is in-out. Otherwise it is
3650 Make_Parameter_Specification
(Loc
,
3651 Defining_Identifier
=>
3652 Make_Defining_Identifier
(Loc
, Name_uObject
),
3655 (Etype
(Ident
) = Standard_Void_Type
3656 and then not Is_RTE
(Obj_Type
, RE_Address
)),
3658 New_Occurrence_Of
(Obj_Type
, Loc
));
3659 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
3660 Prepend_To
(New_Plist
, Decl
);
3663 end Build_Protected_Spec
;
3665 ---------------------------------------
3666 -- Build_Protected_Sub_Specification --
3667 ---------------------------------------
3669 function Build_Protected_Sub_Specification
3671 Prot_Typ
: Entity_Id
;
3672 Mode
: Subprogram_Protection_Mode
) return Node_Id
3674 Loc
: constant Source_Ptr
:= Sloc
(N
);
3678 New_Plist
: List_Id
;
3681 Append_Chr
: constant array (Subprogram_Protection_Mode
) of Character :=
3682 (Dispatching_Mode
=> ' ',
3683 Protected_Mode
=> 'P',
3684 Unprotected_Mode
=> 'N');
3687 if Ekind
(Defining_Unit_Name
(Specification
(N
))) = E_Subprogram_Body
3689 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
3694 Def_Id
:= Defining_Unit_Name
(Specification
(Decl
));
3697 Build_Protected_Spec
3698 (Decl
, Corresponding_Record_Type
(Prot_Typ
), Def_Id
,
3699 Mode
= Unprotected_Mode
);
3701 Make_Defining_Identifier
(Loc
,
3702 Chars
=> Build_Selected_Name
(Prot_Typ
, Def_Id
, Append_Chr
(Mode
)));
3704 -- Reference the original nondispatching subprogram since the analysis
3705 -- of the object.operation notation may need its original name (see
3706 -- Sem_Ch4.Names_Match).
3708 if Mode
= Dispatching_Mode
then
3709 Mutate_Ekind
(New_Id
, Ekind
(Def_Id
));
3710 Set_Original_Protected_Subprogram
(New_Id
, Def_Id
);
3713 -- Link the protected or unprotected version to the original subprogram
3716 Mutate_Ekind
(New_Id
, Ekind
(Def_Id
));
3717 Set_Protected_Subprogram
(New_Id
, Def_Id
);
3719 -- The unprotected operation carries the user code, and debugging
3720 -- information must be generated for it, even though this spec does
3721 -- not come from source. It is also convenient to allow gdb to step
3722 -- into the protected operation, even though it only contains lock/
3725 Set_Debug_Info_Needed
(New_Id
);
3727 -- If a pragma Eliminate applies to the source entity, the internal
3728 -- subprograms will be eliminated as well.
3730 Set_Is_Eliminated
(New_Id
, Is_Eliminated
(Def_Id
));
3732 -- It seems we should set Has_Nested_Subprogram here, but instead we
3733 -- currently set it in Expand_N_Protected_Body, because the entity
3734 -- created here isn't the one that Corresponding_Spec of the body
3735 -- will later be set to, and that's the entity where it's needed. ???
3737 Set_Has_Nested_Subprogram
(New_Id
, Has_Nested_Subprogram
(Def_Id
));
3739 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
3741 Make_Procedure_Specification
(Loc
,
3742 Defining_Unit_Name
=> New_Id
,
3743 Parameter_Specifications
=> New_Plist
);
3745 -- Create a new specification for the anonymous subprogram type
3749 Make_Function_Specification
(Loc
,
3750 Defining_Unit_Name
=> New_Id
,
3751 Parameter_Specifications
=> New_Plist
,
3752 Result_Definition
=>
3753 Copy_Result_Type
(Result_Definition
(Specification
(Decl
))));
3755 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
3759 end Build_Protected_Sub_Specification
;
3761 -------------------------------------
3762 -- Build_Protected_Subprogram_Body --
3763 -------------------------------------
3765 function Build_Protected_Subprogram_Body
3768 N_Op_Spec
: Node_Id
) return Node_Id
3770 Might_Raise
: constant Boolean := Sem_Util
.Might_Raise
(N
);
3772 Loc
: constant Source_Ptr
:= Sloc
(N
);
3773 Op_Spec
: constant Node_Id
:= Specification
(N
);
3774 P_Op_Spec
: constant Node_Id
:=
3775 Build_Protected_Sub_Specification
(N
, Pid
, Protected_Mode
);
3778 Lock_Name
: Node_Id
;
3779 Lock_Stmt
: Node_Id
;
3780 Object_Parm
: Node_Id
;
3783 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
3784 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
3788 Unprot_Call
: Node_Id
;
3791 -- Build a list of the formal parameters of the protected version of
3792 -- the subprogram to use as the actual parameters of the unprotected
3795 Uactuals
:= New_List
;
3796 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
3797 while Present
(Pformal
) loop
3798 Append_To
(Uactuals
,
3799 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))));
3803 -- Make a call to the unprotected version of the subprogram built above
3804 -- for use by the protected version built below.
3806 if Nkind
(Op_Spec
) = N_Function_Specification
then
3809 Make_Simple_Return_Statement
(Loc
,
3811 Make_Function_Call
(Loc
,
3813 Make_Identifier
(Loc
,
3814 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3815 Parameter_Associations
=> Uactuals
));
3818 R
:= Make_Temporary
(Loc
, 'R');
3821 Make_Object_Declaration
(Loc
,
3822 Defining_Identifier
=> R
,
3823 Constant_Present
=> True,
3824 Object_Definition
=>
3825 New_Copy
(Result_Definition
(N_Op_Spec
)),
3827 Make_Function_Call
(Loc
,
3829 Make_Identifier
(Loc
,
3830 Chars
=> Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3831 Parameter_Associations
=> Uactuals
));
3834 Make_Simple_Return_Statement
(Loc
,
3835 Expression
=> New_Occurrence_Of
(R
, Loc
));
3838 if Has_Aspect
(Pid
, Aspect_Exclusive_Functions
)
3840 (No
(Find_Value_Of_Aspect
(Pid
, Aspect_Exclusive_Functions
))
3842 Is_True
(Static_Boolean
(Find_Value_Of_Aspect
3843 (Pid
, Aspect_Exclusive_Functions
))))
3845 Lock_Kind
:= RE_Lock
;
3847 Lock_Kind
:= RE_Lock_Read_Only
;
3851 Make_Procedure_Call_Statement
(Loc
,
3853 Make_Identifier
(Loc
, Chars
(Defining_Unit_Name
(N_Op_Spec
))),
3854 Parameter_Associations
=> Uactuals
);
3856 Lock_Kind
:= RE_Lock
;
3859 -- Wrap call in block that will be covered by an at_end handler
3863 Make_Block_Statement
(Loc
,
3864 Handled_Statement_Sequence
=>
3865 Make_Handled_Sequence_Of_Statements
(Loc
,
3866 Statements
=> New_List
(Unprot_Call
)));
3869 -- Make the protected subprogram body. This locks the protected
3870 -- object and calls the unprotected version of the subprogram.
3872 case Corresponding_Runtime_Package
(Pid
) is
3873 when System_Tasking_Protected_Objects_Entries
=>
3874 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entries
), Loc
);
3876 when System_Tasking_Protected_Objects_Single_Entry
=>
3877 Lock_Name
:= New_Occurrence_Of
(RTE
(RE_Lock_Entry
), Loc
);
3879 when System_Tasking_Protected_Objects
=>
3880 Lock_Name
:= New_Occurrence_Of
(RTE
(Lock_Kind
), Loc
);
3883 raise Program_Error
;
3887 Make_Attribute_Reference
(Loc
,
3889 Make_Selected_Component
(Loc
,
3890 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
3891 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
3892 Attribute_Name
=> Name_Unchecked_Access
);
3895 Make_Procedure_Call_Statement
(Loc
,
3897 Parameter_Associations
=> New_List
(Object_Parm
));
3899 if Abort_Allowed
then
3901 Build_Runtime_Call
(Loc
, RE_Abort_Defer
),
3905 Stmts
:= New_List
(Lock_Stmt
);
3909 Append
(Unprot_Call
, Stmts
);
3911 if Nkind
(Op_Spec
) = N_Function_Specification
then
3913 Stmts
:= Empty_List
;
3915 Append
(Unprot_Call
, Stmts
);
3918 Build_Protected_Subprogram_Call_Cleanup
(Op_Spec
, Pid
, Loc
, Stmts
);
3920 if Nkind
(Op_Spec
) = N_Function_Specification
then
3921 Append_To
(Stmts
, Return_Stmt
);
3922 Append_To
(Pre_Stmts
,
3923 Make_Block_Statement
(Loc
,
3924 Declarations
=> New_List
(Unprot_Call
),
3925 Handled_Statement_Sequence
=>
3926 Make_Handled_Sequence_Of_Statements
(Loc
,
3927 Statements
=> Stmts
)));
3933 Make_Subprogram_Body
(Loc
,
3934 Declarations
=> Empty_List
,
3935 Specification
=> P_Op_Spec
,
3936 Handled_Statement_Sequence
=>
3937 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
3939 -- Mark this subprogram as a protected subprogram body so that the
3940 -- cleanup will be inserted. This is done only in the Might_Raise
3941 -- case because otherwise the cleanup has already been inserted.
3944 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
3948 end Build_Protected_Subprogram_Body
;
3950 -------------------------------------
3951 -- Build_Protected_Subprogram_Call --
3952 -------------------------------------
3954 procedure Build_Protected_Subprogram_Call
3958 External
: Boolean := True)
3960 Loc
: constant Source_Ptr
:= Sloc
(N
);
3961 Sub
: constant Entity_Id
:= Entity
(Name
);
3967 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
3970 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
3973 if Present
(Parameter_Associations
(N
)) then
3974 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
3979 -- If the type is an untagged derived type, convert to the root type,
3980 -- which is the one on which the operations are defined.
3982 if Nkind
(Rec
) = N_Unchecked_Type_Conversion
3983 and then not Is_Tagged_Type
(Etype
(Rec
))
3984 and then Is_Derived_Type
(Etype
(Rec
))
3986 Set_Etype
(Rec
, Root_Type
(Etype
(Rec
)));
3987 Set_Subtype_Mark
(Rec
,
3988 New_Occurrence_Of
(Root_Type
(Etype
(Rec
)), Sloc
(N
)));
3991 Prepend
(Rec
, Params
);
3993 if Ekind
(Sub
) = E_Procedure
then
3995 Make_Procedure_Call_Statement
(Loc
,
3997 Parameter_Associations
=> Params
));
4000 pragma Assert
(Ekind
(Sub
) = E_Function
);
4002 Make_Function_Call
(Loc
,
4004 Parameter_Associations
=> Params
));
4006 -- Preserve type of call for subsequent processing (required for
4007 -- call to Wrap_Transient_Expression in the case of a shared passive
4010 Set_Etype
(N
, Etype
(New_Sub
));
4014 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
4015 and then Is_Entity_Name
(Expression
(Rec
))
4016 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
4018 Add_Shared_Var_Lock_Procs
(N
);
4020 end Build_Protected_Subprogram_Call
;
4022 ---------------------------------------------
4023 -- Build_Protected_Subprogram_Call_Cleanup --
4024 ---------------------------------------------
4026 procedure Build_Protected_Subprogram_Call_Cleanup
4035 -- If the associated protected object has entries, a protected
4036 -- procedure has to service entry queues. In this case generate:
4038 -- Service_Entries (_object._object'Access);
4040 if Nkind
(Op_Spec
) = N_Procedure_Specification
4041 and then Has_Entries
(Conc_Typ
)
4043 case Corresponding_Runtime_Package
(Conc_Typ
) is
4044 when System_Tasking_Protected_Objects_Entries
=>
4045 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entries
), Loc
);
4047 when System_Tasking_Protected_Objects_Single_Entry
=>
4048 Nam
:= New_Occurrence_Of
(RTE
(RE_Service_Entry
), Loc
);
4051 raise Program_Error
;
4055 Make_Procedure_Call_Statement
(Loc
,
4057 Parameter_Associations
=> New_List
(
4058 Make_Attribute_Reference
(Loc
,
4060 Make_Selected_Component
(Loc
,
4061 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4062 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4063 Attribute_Name
=> Name_Unchecked_Access
))));
4067 -- Unlock (_object._object'Access);
4069 case Corresponding_Runtime_Package
(Conc_Typ
) is
4070 when System_Tasking_Protected_Objects_Entries
=>
4071 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entries
), Loc
);
4073 when System_Tasking_Protected_Objects_Single_Entry
=>
4074 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock_Entry
), Loc
);
4076 when System_Tasking_Protected_Objects
=>
4077 Nam
:= New_Occurrence_Of
(RTE
(RE_Unlock
), Loc
);
4080 raise Program_Error
;
4084 Make_Procedure_Call_Statement
(Loc
,
4086 Parameter_Associations
=> New_List
(
4087 Make_Attribute_Reference
(Loc
,
4089 Make_Selected_Component
(Loc
,
4090 Prefix
=> Make_Identifier
(Loc
, Name_uObject
),
4091 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
4092 Attribute_Name
=> Name_Unchecked_Access
))));
4098 if Abort_Allowed
then
4099 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4101 end Build_Protected_Subprogram_Call_Cleanup
;
4103 -------------------------
4104 -- Build_Selected_Name --
4105 -------------------------
4107 function Build_Selected_Name
4108 (Prefix
: Entity_Id
;
4109 Selector
: Entity_Id
;
4110 Append_Char
: Character := ' ') return Name_Id
4112 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
4113 Select_Len
: Natural;
4116 Get_Name_String
(Chars
(Selector
));
4117 Select_Len
:= Name_Len
;
4118 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
4119 Get_Name_String
(Chars
(Prefix
));
4121 -- If scope is anonymous type, discard suffix to recover name of
4122 -- single protected object. Otherwise use protected type name.
4124 if Name_Buffer
(Name_Len
) = 'T' then
4125 Name_Len
:= Name_Len
- 1;
4128 Add_Str_To_Name_Buffer
("__");
4129 for J
in 1 .. Select_Len
loop
4130 Add_Char_To_Name_Buffer
(Select_Buffer
(J
));
4133 -- Now add the Append_Char if specified. The encoding to follow
4134 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4135 -- then the entity is associated to a protected type subprogram.
4136 -- Otherwise, it is a protected type entry. For each case, the
4137 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4139 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4141 if Append_Char
/= ' ' then
4142 if Append_Char
in 'P' |
'N' then
4143 Add_Char_To_Name_Buffer
(Append_Char
);
4146 Add_Str_To_Name_Buffer
((1 => '_', 2 => Append_Char
));
4147 return New_External_Name
(Name_Find
, ' ', -1);
4152 end Build_Selected_Name
;
4154 -----------------------------
4155 -- Build_Simple_Entry_Call --
4156 -----------------------------
4158 -- A task entry call is converted to a call to Call_Simple
4161 -- P : parms := (parm, parm, parm);
4163 -- Call_Simple (acceptor-task, entry-index, P'Address);
4169 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4170 -- the parameters, and the constructed aggregate value contains either the
4171 -- parameters or, in the case of non-elementary types, references to these
4172 -- parameters. Then the address of this aggregate is passed to the runtime
4173 -- routine, along with the task id value and the task entry index value.
4174 -- Pnn is only required if parameters are present.
4176 -- The assignments after the call are present only in the case of in-out
4177 -- or out parameters for elementary types, and are used to assign back the
4178 -- resulting values of such parameters.
4180 -- Note: the reason that we insert a block here is that in the context
4181 -- of selects, conditional entry calls etc. the entry call statement
4182 -- appears on its own, not as an element of a list.
4184 -- A protected entry call is converted to a Protected_Entry_Call:
4187 -- P : E1_Params := (param, param, param);
4189 -- Bnn : Communications_Block;
4192 -- P : E1_Params := (param, param, param);
4193 -- Bnn : Communications_Block;
4196 -- Protected_Entry_Call (
4197 -- Object => po._object'Access,
4198 -- E => <entry index>;
4199 -- Uninterpreted_Data => P'Address;
4200 -- Mode => Simple_Call;
4207 procedure Build_Simple_Entry_Call
4216 -- If call has been inlined, nothing left to do
4218 if Nkind
(N
) = N_Block_Statement
then
4222 -- Convert entry call to Call_Simple call
4225 Loc
: constant Source_Ptr
:= Sloc
(N
);
4226 Parms
: constant List_Id
:= Parameter_Associations
(N
);
4227 Stats
: constant List_Id
:= New_List
;
4230 Comm_Name
: Entity_Id
;
4234 Ent_Acc
: Entity_Id
;
4236 Iface_Tag
: Entity_Id
;
4237 Iface_Typ
: Entity_Id
;
4250 -- Simple entry and entry family cases merge here
4252 Ent
:= Entity
(Ename
);
4253 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
4254 Conctyp
:= Etype
(Concval
);
4256 -- Special case for protected subprogram calls
4258 if Is_Protected_Type
(Conctyp
)
4259 and then Is_Subprogram
(Entity
(Ename
))
4261 if not Is_Eliminated
(Entity
(Ename
)) then
4262 Build_Protected_Subprogram_Call
4263 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
4270 -- First parameter is the Task_Id value from the task value or the
4271 -- Object from the protected object value, obtained by selecting
4272 -- the _Task_Id or _Object from the result of doing an unchecked
4273 -- conversion to convert the value to the corresponding record type.
4275 if Nkind
(Concval
) = N_Function_Call
4276 and then Is_Task_Type
(Conctyp
)
4277 and then Ada_Version
>= Ada_2005
4280 ExpR
: constant Node_Id
:= Relocate_Node
(Concval
);
4281 Obj
: constant Entity_Id
:= Make_Temporary
(Loc
, 'F', ExpR
);
4286 Make_Object_Declaration
(Loc
,
4287 Defining_Identifier
=> Obj
,
4288 Object_Definition
=> New_Occurrence_Of
(Conctyp
, Loc
),
4289 Expression
=> ExpR
);
4290 Set_Etype
(Obj
, Conctyp
);
4291 Decls
:= New_List
(Decl
);
4292 Rewrite
(Concval
, New_Occurrence_Of
(Obj
, Loc
));
4299 Parm1
:= Concurrent_Ref
(Concval
);
4301 -- Second parameter is the entry index, computed by the routine
4302 -- provided for this purpose. The value of this expression is
4303 -- assigned to an intermediate variable to assure that any entry
4304 -- family index expressions are evaluated before the entry
4307 if not Is_Protected_Type
(Conctyp
)
4309 Corresponding_Runtime_Package
(Conctyp
) =
4310 System_Tasking_Protected_Objects_Entries
4312 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
4315 Make_Object_Declaration
(Loc
,
4316 Defining_Identifier
=> X
,
4317 Object_Definition
=>
4318 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
4319 Expression
=> Actual_Index_Expression
(
4320 Loc
, Entity
(Ename
), Index
, Concval
));
4322 Append_To
(Decls
, Xdecl
);
4323 Parm2
:= New_Occurrence_Of
(X
, Loc
);
4330 -- The third parameter is the packaged parameters. If there are
4331 -- none, then it is just the null address, since nothing is passed.
4334 Parm3
:= New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
);
4337 -- Case of parameters present, where third argument is the address
4338 -- of a packaged record containing the required parameter values.
4341 -- First build a list of parameter values, which are references to
4342 -- objects of the parameter types.
4346 Actual
:= First_Actual
(N
);
4347 Formal
:= First_Formal
(Ent
);
4348 while Present
(Actual
) loop
4350 -- If it is a by-copy type, copy it to a new variable. The
4351 -- packaged record has a field that points to this variable.
4353 if Is_By_Copy_Type
(Etype
(Actual
)) then
4355 Make_Object_Declaration
(Loc
,
4356 Defining_Identifier
=> Make_Temporary
(Loc
, 'J'),
4357 Aliased_Present
=> True,
4358 Object_Definition
=>
4359 New_Occurrence_Of
(Etype
(Formal
), Loc
));
4361 -- Mark the object as not needing initialization since the
4362 -- initialization is performed separately, avoiding errors
4363 -- on cases such as formals of null-excluding access types.
4365 Set_No_Initialization
(N_Node
);
4367 -- We must make a separate assignment statement for the
4368 -- case of limited types. We cannot assign it unless the
4369 -- Assignment_OK flag is set first. An out formal of an
4370 -- access type or whose type has a Default_Value must also
4371 -- be initialized from the actual (see RM 6.4.1 (13-13.1)),
4372 -- but no constraint, predicate, or null-exclusion check is
4373 -- applied before the call.
4375 if Ekind
(Formal
) /= E_Out_Parameter
4376 or else Is_Access_Type
(Etype
(Formal
))
4378 (Is_Scalar_Type
(Etype
(Formal
))
4380 Present
(Default_Aspect_Value
(Etype
(Formal
))))
4383 New_Occurrence_Of
(Defining_Identifier
(N_Node
), Loc
);
4384 Set_Assignment_OK
(N_Var
);
4386 Make_Assignment_Statement
(Loc
,
4388 Expression
=> Relocate_Node
(Actual
)));
4390 -- Mark the object as internal, so we don't later reset
4391 -- No_Initialization flag in Default_Initialize_Object,
4392 -- which would lead to needless default initialization.
4393 -- We don't set this outside the if statement, because
4394 -- out scalar parameters without Default_Value do require
4395 -- default initialization if Initialize_Scalars applies.
4397 Set_Is_Internal
(Defining_Identifier
(N_Node
));
4399 -- If actual is an out parameter of a null-excluding
4400 -- access type, there is access check on entry, so set
4401 -- Suppress_Assignment_Checks on the generated statement
4402 -- that assigns the actual to the parameter block.
4404 Set_Suppress_Assignment_Checks
(Last
(Stats
));
4407 Append
(N_Node
, Decls
);
4410 Make_Attribute_Reference
(Loc
,
4411 Attribute_Name
=> Name_Unchecked_Access
,
4414 (Defining_Identifier
(N_Node
), Loc
)));
4417 -- Interface class-wide formal
4419 if Ada_Version
>= Ada_2005
4420 and then Ekind
(Etype
(Formal
)) = E_Class_Wide_Type
4421 and then Is_Interface
(Etype
(Formal
))
4423 Iface_Typ
:= Etype
(Etype
(Formal
));
4426 -- formal_iface_type! (actual.iface_tag)'reference
4429 Find_Interface_Tag
(Etype
(Actual
), Iface_Typ
);
4430 pragma Assert
(Present
(Iface_Tag
));
4433 Make_Reference
(Loc
,
4434 Unchecked_Convert_To
(Iface_Typ
,
4435 Make_Selected_Component
(Loc
,
4437 Relocate_Node
(Actual
),
4439 New_Occurrence_Of
(Iface_Tag
, Loc
)))));
4445 Make_Reference
(Loc
, Relocate_Node
(Actual
)));
4449 Next_Actual
(Actual
);
4450 Next_Formal_With_Extras
(Formal
);
4453 -- Now build the declaration of parameters initialized with the
4454 -- aggregate containing this constructed parameter list.
4456 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
4459 Make_Object_Declaration
(Loc
,
4460 Defining_Identifier
=> P
,
4461 Object_Definition
=>
4462 New_Occurrence_Of
(Designated_Type
(Ent_Acc
), Loc
),
4464 Make_Aggregate
(Loc
, Expressions
=> Plist
));
4467 Make_Attribute_Reference
(Loc
,
4468 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4469 Attribute_Name
=> Name_Address
);
4471 Append
(Pdecl
, Decls
);
4474 -- Now we can create the call, case of protected type
4476 if Is_Protected_Type
(Conctyp
) then
4477 case Corresponding_Runtime_Package
(Conctyp
) is
4478 when System_Tasking_Protected_Objects_Entries
=>
4480 -- Change the type of the index declaration
4482 Set_Object_Definition
(Xdecl
,
4483 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Index
), Loc
));
4485 -- Some additional declarations for protected entry calls
4491 -- Bnn : Communications_Block;
4493 Comm_Name
:= Make_Temporary
(Loc
, 'B');
4496 Make_Object_Declaration
(Loc
,
4497 Defining_Identifier
=> Comm_Name
,
4498 Object_Definition
=>
4500 (RTE
(RE_Communication_Block
), Loc
)));
4502 -- Some additional statements for protected entry calls
4504 -- Protected_Entry_Call
4505 -- (Object => po._object'Access,
4506 -- E => <entry index>;
4507 -- Uninterpreted_Data => P'Address;
4508 -- Mode => Simple_Call;
4512 Make_Procedure_Call_Statement
(Loc
,
4514 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
4516 Parameter_Associations
=> New_List
(
4517 Make_Attribute_Reference
(Loc
,
4518 Attribute_Name
=> Name_Unchecked_Access
,
4522 New_Occurrence_Of
(RTE
(RE_Simple_Call
), Loc
),
4523 New_Occurrence_Of
(Comm_Name
, Loc
)));
4525 when System_Tasking_Protected_Objects_Single_Entry
=>
4527 -- Protected_Single_Entry_Call
4528 -- (Object => po._object'Access,
4529 -- Uninterpreted_Data => P'Address);
4532 Make_Procedure_Call_Statement
(Loc
,
4535 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
4537 Parameter_Associations
=> New_List
(
4538 Make_Attribute_Reference
(Loc
,
4539 Attribute_Name
=> Name_Unchecked_Access
,
4544 raise Program_Error
;
4547 -- Case of task type
4551 Make_Procedure_Call_Statement
(Loc
,
4553 New_Occurrence_Of
(RTE
(RE_Call_Simple
), Loc
),
4554 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
4558 Append_To
(Stats
, Call
);
4560 -- If there are out or in/out parameters by copy add assignment
4561 -- statements for the result values.
4563 if Present
(Parms
) then
4564 Actual
:= First_Actual
(N
);
4565 Formal
:= First_Formal
(Ent
);
4567 Set_Assignment_OK
(Actual
);
4568 while Present
(Actual
) loop
4569 if Is_By_Copy_Type
(Etype
(Actual
))
4570 and then Ekind
(Formal
) /= E_In_Parameter
4573 Make_Assignment_Statement
(Loc
,
4574 Name
=> New_Copy
(Actual
),
4576 Make_Explicit_Dereference
(Loc
,
4577 Make_Selected_Component
(Loc
,
4578 Prefix
=> New_Occurrence_Of
(P
, Loc
),
4580 Make_Identifier
(Loc
, Chars
(Formal
)))));
4582 -- In all cases (including limited private types) we want
4583 -- the assignment to be valid.
4585 Set_Assignment_OK
(Name
(N_Node
));
4587 -- If the call is the triggering alternative in an
4588 -- asynchronous select, or the entry_call alternative of a
4589 -- conditional entry call, the assignments for in-out
4590 -- parameters are incorporated into the statement list that
4591 -- follows, so that there are executed only if the entry
4594 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
4595 and then N
= Triggering_Statement
(Parent
(N
)))
4597 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4598 and then N
= Entry_Call_Statement
(Parent
(N
)))
4600 if No
(Statements
(Parent
(N
))) then
4601 Set_Statements
(Parent
(N
), New_List
);
4604 Prepend
(N_Node
, Statements
(Parent
(N
)));
4607 Insert_After
(Call
, N_Node
);
4611 Next_Actual
(Actual
);
4612 Next_Formal_With_Extras
(Formal
);
4616 -- Finally, create block and analyze it
4619 Make_Block_Statement
(Loc
,
4620 Declarations
=> Decls
,
4621 Handled_Statement_Sequence
=>
4622 Make_Handled_Sequence_Of_Statements
(Loc
,
4623 Statements
=> Stats
)));
4627 end Build_Simple_Entry_Call
;
4629 --------------------------------
4630 -- Build_Task_Activation_Call --
4631 --------------------------------
4633 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
4634 function Activation_Call_Loc
return Source_Ptr
;
4635 -- Find a suitable source location for the activation call
4637 -------------------------
4638 -- Activation_Call_Loc --
4639 -------------------------
4641 function Activation_Call_Loc
return Source_Ptr
is
4643 -- The activation call must carry the location of the "end" keyword
4644 -- when the context is a package declaration.
4646 if Nkind
(N
) = N_Package_Declaration
then
4647 return End_Keyword_Location
(N
);
4649 -- Otherwise the activation call must carry the location of the
4653 return Begin_Keyword_Location
(N
);
4655 end Activation_Call_Loc
;
4666 -- Start of processing for Build_Task_Activation_Call
4669 -- For sequential elaboration policy, all the tasks will be activated at
4670 -- the end of the elaboration.
4672 if Partition_Elaboration_Policy
= 'S' then
4675 -- Do not create an activation call for a package spec if the package
4676 -- has a completing body. The activation call will be inserted after
4677 -- the "begin" of the body.
4679 elsif Nkind
(N
) = N_Package_Declaration
4680 and then Present
(Corresponding_Body
(N
))
4685 -- Obtain the activation chain entity. Block statements, entry bodies,
4686 -- subprogram bodies, and task bodies keep the entity in their nodes.
4687 -- Package bodies on the other hand store it in the declaration of the
4688 -- corresponding package spec.
4692 if Nkind
(Owner
) = N_Package_Body
then
4693 Owner
:= Unit_Declaration_Node
(Corresponding_Spec
(Owner
));
4696 Chain
:= Activation_Chain_Entity
(Owner
);
4698 -- Nothing to do when there are no tasks to activate. This is indicated
4699 -- by a missing activation chain entity; also skip generating it when
4700 -- it is a ghost entity.
4702 if No
(Chain
) or else Is_Ignored_Ghost_Entity
(Chain
) then
4705 -- The availability of the activation chain entity does not ensure
4706 -- that we have tasks to activate because it may have been declared
4707 -- by the frontend to pass a required extra formal to a build-in-place
4708 -- subprogram call. If we are within the scope of a protected type and
4709 -- pragma Detect_Blocking is active we can assume that no tasks will be
4710 -- activated; if tasks are created in a protected object and this pragma
4711 -- is active then the frontend emits a warning and Program_Error is
4712 -- raised at runtime.
4714 elsif Detect_Blocking
and then Within_Protected_Type
(Current_Scope
) then
4718 -- The location of the activation call must be as close as possible to
4719 -- the intended semantic location of the activation because the ABE
4720 -- mechanism relies heavily on accurate locations.
4722 Loc
:= Activation_Call_Loc
;
4724 if Restricted_Profile
then
4725 Name
:= New_Occurrence_Of
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
4727 Name
:= New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
);
4731 Make_Procedure_Call_Statement
(Loc
,
4733 Parameter_Associations
=>
4734 New_List
(Make_Attribute_Reference
(Loc
,
4735 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4736 Attribute_Name
=> Name_Unchecked_Access
)));
4738 if Nkind
(N
) = N_Package_Declaration
then
4739 if Present
(Private_Declarations
(Specification
(N
))) then
4740 Append
(Call
, Private_Declarations
(Specification
(N
)));
4742 Append
(Call
, Visible_Declarations
(Specification
(N
)));
4746 -- The call goes at the start of the statement sequence after the
4747 -- start of exception range label if one is present.
4749 if Present
(Handled_Statement_Sequence
(N
)) then
4750 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4752 -- A special case, skip exception range label if one is present
4753 -- (from front end zcx processing).
4755 if Nkind
(Stmt
) = N_Label
and then Exception_Junk
(Stmt
) then
4759 -- Another special case, if the first statement is a block from
4760 -- optimization of a local raise to a goto, then the call goes
4761 -- inside this block.
4763 if Nkind
(Stmt
) = N_Block_Statement
4764 and then Exception_Junk
(Stmt
)
4766 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
4769 -- Insertion point is after any exception label pushes, since we
4770 -- want it covered by any local handlers.
4772 while Nkind
(Stmt
) in N_Push_xxx_Label
loop
4776 -- Now we have the proper insertion point
4778 Insert_Before
(Stmt
, Call
);
4781 Set_Handled_Statement_Sequence
(N
,
4782 Make_Handled_Sequence_Of_Statements
(Loc
,
4783 Statements
=> New_List
(Call
)));
4789 if Legacy_Elaboration_Checks
then
4790 Check_Task_Activation
(N
);
4792 end Build_Task_Activation_Call
;
4794 -------------------------------
4795 -- Build_Task_Allocate_Block --
4796 -------------------------------
4798 procedure Build_Task_Allocate_Block
4803 T
: constant Entity_Id
:= Entity
(Expression
(N
));
4804 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
4805 Loc
: constant Source_Ptr
:= Sloc
(N
);
4806 Chain
: constant Entity_Id
:=
4807 Make_Defining_Identifier
(Loc
, Name_uChain
);
4808 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4813 Make_Block_Statement
(Loc
,
4814 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4815 Declarations
=> New_List
(
4817 -- _Chain : Activation_Chain;
4819 Make_Object_Declaration
(Loc
,
4820 Defining_Identifier
=> Chain
,
4821 Aliased_Present
=> True,
4822 Object_Definition
=>
4823 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4825 Handled_Statement_Sequence
=>
4826 Make_Handled_Sequence_Of_Statements
(Loc
,
4828 Statements
=> New_List
(
4832 Make_Procedure_Call_Statement
(Loc
,
4833 Name
=> New_Occurrence_Of
(Init
, Loc
),
4834 Parameter_Associations
=> Args
),
4836 -- Activate_Tasks (_Chain);
4838 Make_Procedure_Call_Statement
(Loc
,
4839 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4840 Parameter_Associations
=> New_List
(
4841 Make_Attribute_Reference
(Loc
,
4842 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4843 Attribute_Name
=> Name_Unchecked_Access
))))),
4845 Has_Created_Identifier
=> True,
4846 Is_Task_Allocation_Block
=> True);
4849 Make_Implicit_Label_Declaration
(Loc
,
4850 Defining_Identifier
=> Blkent
,
4851 Label_Construct
=> Block
));
4853 Append_To
(Actions
, Block
);
4855 Set_Activation_Chain_Entity
(Block
, Chain
);
4856 end Build_Task_Allocate_Block
;
4858 -----------------------------------------------
4859 -- Build_Task_Allocate_Block_With_Init_Stmts --
4860 -----------------------------------------------
4862 procedure Build_Task_Allocate_Block_With_Init_Stmts
4865 Init_Stmts
: List_Id
)
4867 Loc
: constant Source_Ptr
:= Sloc
(N
);
4868 Chain
: constant Entity_Id
:=
4869 Make_Defining_Identifier
(Loc
, Name_uChain
);
4870 Blkent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
4874 Append_To
(Init_Stmts
,
4875 Make_Procedure_Call_Statement
(Loc
,
4876 Name
=> New_Occurrence_Of
(RTE
(RE_Activate_Tasks
), Loc
),
4877 Parameter_Associations
=> New_List
(
4878 Make_Attribute_Reference
(Loc
,
4879 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
4880 Attribute_Name
=> Name_Unchecked_Access
))));
4883 Make_Block_Statement
(Loc
,
4884 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
4885 Declarations
=> New_List
(
4887 -- _Chain : Activation_Chain;
4889 Make_Object_Declaration
(Loc
,
4890 Defining_Identifier
=> Chain
,
4891 Aliased_Present
=> True,
4892 Object_Definition
=>
4893 New_Occurrence_Of
(RTE
(RE_Activation_Chain
), Loc
))),
4895 Handled_Statement_Sequence
=>
4896 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
4898 Has_Created_Identifier
=> True,
4899 Is_Task_Allocation_Block
=> True);
4902 Make_Implicit_Label_Declaration
(Loc
,
4903 Defining_Identifier
=> Blkent
,
4904 Label_Construct
=> Block
));
4906 Append_To
(Actions
, Block
);
4908 Set_Activation_Chain_Entity
(Block
, Chain
);
4909 end Build_Task_Allocate_Block_With_Init_Stmts
;
4911 -----------------------------------
4912 -- Build_Task_Proc_Specification --
4913 -----------------------------------
4915 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
4916 Loc
: constant Source_Ptr
:= Sloc
(T
);
4917 Spec_Id
: Entity_Id
;
4920 -- Case of explicit task type, suffix TB
4922 if Comes_From_Source
(T
) then
4924 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), "TB"));
4926 -- Case of anonymous task type, suffix B
4930 Make_Defining_Identifier
(Loc
, New_External_Name
(Chars
(T
), 'B'));
4933 Set_Is_Internal
(Spec_Id
);
4935 -- Associate the procedure with the task, if this is the declaration
4936 -- (and not the body) of the procedure.
4938 if No
(Task_Body_Procedure
(T
)) then
4939 Set_Task_Body_Procedure
(T
, Spec_Id
);
4943 Make_Procedure_Specification
(Loc
,
4944 Defining_Unit_Name
=> Spec_Id
,
4945 Parameter_Specifications
=> New_List
(
4946 Make_Parameter_Specification
(Loc
,
4947 Defining_Identifier
=>
4948 Make_Defining_Identifier
(Loc
, Name_uTask
),
4950 Make_Access_Definition
(Loc
,
4952 New_Occurrence_Of
(Corresponding_Record_Type
(T
), Loc
)))));
4953 end Build_Task_Proc_Specification
;
4955 ---------------------------------------
4956 -- Build_Unprotected_Subprogram_Body --
4957 ---------------------------------------
4959 function Build_Unprotected_Subprogram_Body
4961 Pid
: Node_Id
) return Node_Id
4963 Decls
: constant List_Id
:= Declarations
(N
);
4966 -- Add renamings for the Protection object, discriminals, privals, and
4967 -- the entry index constant for use by debugger.
4969 Debug_Private_Data_Declarations
(Decls
);
4971 -- Make an unprotected version of the subprogram for use within the same
4972 -- object, with a new name and an additional parameter representing the
4976 Make_Subprogram_Body
(Sloc
(N
),
4978 Build_Protected_Sub_Specification
(N
, Pid
, Unprotected_Mode
),
4979 Declarations
=> Decls
,
4980 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
),
4981 At_End_Proc
=> At_End_Proc
(N
));
4982 end Build_Unprotected_Subprogram_Body
;
4984 ----------------------------
4985 -- Collect_Entry_Families --
4986 ----------------------------
4988 procedure Collect_Entry_Families
4991 Current_Node
: in out Node_Id
;
4992 Conctyp
: Entity_Id
)
4995 Efam_Decl
: Node_Id
;
4996 Efam_Type
: Entity_Id
;
4999 Efam
:= First_Entity
(Conctyp
);
5000 while Present
(Efam
) loop
5001 if Ekind
(Efam
) = E_Entry_Family
then
5002 Efam_Type
:= Make_Temporary
(Loc
, 'F');
5005 Eityp
: constant Entity_Id
:= Entry_Index_Type
(Efam
);
5006 Lo
: constant Node_Id
:= Type_Low_Bound
(Eityp
);
5007 Hi
: constant Node_Id
:= Type_High_Bound
(Eityp
);
5012 Bityp
:= Base_Type
(Eityp
);
5014 if Is_Potentially_Large_Family
(Bityp
, Conctyp
, Lo
, Hi
) then
5015 Bityp
:= Make_Temporary
(Loc
, 'B');
5018 Make_Subtype_Declaration
(Loc
,
5019 Defining_Identifier
=> Bityp
,
5020 Subtype_Indication
=>
5021 Make_Subtype_Indication
(Loc
,
5023 New_Occurrence_Of
(Standard_Integer
, Loc
),
5025 Make_Range_Constraint
(Loc
,
5026 Range_Expression
=> Make_Range
(Loc
,
5027 Make_Integer_Literal
5028 (Loc
, -Entry_Family_Bound
),
5029 Make_Integer_Literal
5030 (Loc
, Entry_Family_Bound
- 1)))));
5032 Insert_After
(Current_Node
, Bdecl
);
5033 Current_Node
:= Bdecl
;
5038 Make_Full_Type_Declaration
(Loc
,
5039 Defining_Identifier
=> Efam_Type
,
5041 Make_Unconstrained_Array_Definition
(Loc
,
5043 (New_List
(New_Occurrence_Of
(Bityp
, Loc
))),
5045 Component_Definition
=>
5046 Make_Component_Definition
(Loc
,
5047 Aliased_Present
=> False,
5048 Subtype_Indication
=>
5049 New_Occurrence_Of
(Standard_Character
, Loc
))));
5052 Insert_After
(Current_Node
, Efam_Decl
);
5053 Current_Node
:= Efam_Decl
;
5054 Analyze
(Efam_Decl
);
5057 Make_Component_Declaration
(Loc
,
5058 Defining_Identifier
=>
5059 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
5061 Component_Definition
=>
5062 Make_Component_Definition
(Loc
,
5063 Aliased_Present
=> False,
5064 Subtype_Indication
=>
5065 Make_Subtype_Indication
(Loc
,
5067 New_Occurrence_Of
(Efam_Type
, Loc
),
5070 Make_Index_Or_Discriminant_Constraint
(Loc
,
5071 Constraints
=> New_List
(
5072 New_Occurrence_Of
(Entry_Index_Type
(Efam
),
5078 end Collect_Entry_Families
;
5080 -----------------------
5081 -- Concurrent_Object --
5082 -----------------------
5084 function Concurrent_Object
5085 (Spec_Id
: Entity_Id
;
5086 Conc_Typ
: Entity_Id
) return Entity_Id
5089 -- Parameter _O or _object
5091 if Is_Protected_Type
(Conc_Typ
) then
5092 return First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
5097 pragma Assert
(Is_Task_Type
(Conc_Typ
));
5098 return First_Formal
(Task_Body_Procedure
(Conc_Typ
));
5100 end Concurrent_Object
;
5102 ----------------------
5103 -- Copy_Result_Type --
5104 ----------------------
5106 function Copy_Result_Type
(Res
: Node_Id
) return Node_Id
is
5107 New_Res
: constant Node_Id
:= New_Copy_Tree
(Res
);
5112 -- If the result type is an access_to_subprogram, we must create new
5113 -- entities for its spec.
5115 if Nkind
(New_Res
) = N_Access_Definition
5116 and then Present
(Access_To_Subprogram_Definition
(New_Res
))
5118 -- Provide new entities for the formals
5120 Par_Spec
:= First
(Parameter_Specifications
5121 (Access_To_Subprogram_Definition
(New_Res
)));
5122 while Present
(Par_Spec
) loop
5123 Formal
:= Defining_Identifier
(Par_Spec
);
5124 Set_Defining_Identifier
(Par_Spec
,
5125 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)));
5131 end Copy_Result_Type
;
5133 --------------------
5134 -- Concurrent_Ref --
5135 --------------------
5137 -- The expression returned for a reference to a concurrent object has the
5140 -- taskV!(name)._Task_Id
5144 -- objectV!(name)._Object
5146 -- for a protected object. For the case of an access to a concurrent
5147 -- object, there is an extra explicit dereference:
5149 -- taskV!(name.all)._Task_Id
5150 -- objectV!(name.all)._Object
5152 -- here taskV and objectV are the types for the associated records, which
5153 -- contain the required _Task_Id and _Object fields for tasks and protected
5154 -- objects, respectively.
5156 -- For the case of a task type name, the expression is
5160 -- i.e. a call to the Self function which returns precisely this Task_Id
5162 -- For the case of a protected type name, the expression is
5166 -- which is a renaming of the _object field of the current object
5167 -- record, passed into protected operations as a parameter.
5169 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
5170 Loc
: constant Source_Ptr
:= Sloc
(N
);
5171 Ntyp
: constant Entity_Id
:= Etype
(N
);
5175 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
5176 -- Check whether the reference is to the immediately enclosing task
5177 -- type, or to an outer one (rare but legal).
5179 ---------------------
5180 -- Is_Current_Task --
5181 ---------------------
5183 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
5187 Scop
:= Current_Scope
;
5188 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
5192 elsif Is_Task_Type
(Scop
) then
5195 -- If this is a procedure nested within the task type, we must
5196 -- assume that it can be called from an inner task, and therefore
5197 -- cannot treat it as a local reference.
5199 elsif Is_Overloadable
(Scop
) and then In_Open_Scopes
(T
) then
5203 Scop
:= Scope
(Scop
);
5207 -- We know that we are within the task body, so should have found it
5210 raise Program_Error
;
5211 end Is_Current_Task
;
5213 -- Start of processing for Concurrent_Ref
5216 if Is_Access_Type
(Ntyp
) then
5217 Dtyp
:= Designated_Type
(Ntyp
);
5219 if Is_Protected_Type
(Dtyp
) then
5220 Sel
:= Name_uObject
;
5222 Sel
:= Name_uTask_Id
;
5226 Make_Selected_Component
(Loc
,
5228 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
5229 Make_Explicit_Dereference
(Loc
, N
)),
5230 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5232 elsif Is_Entity_Name
(N
) and then Is_Concurrent_Type
(Entity
(N
)) then
5233 if Is_Task_Type
(Entity
(N
)) then
5235 if Is_Current_Task
(Entity
(N
)) then
5237 Make_Function_Call
(Loc
,
5238 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
));
5243 T_Self
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
5244 T_Body
: constant Node_Id
:=
5245 Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
5249 Make_Object_Declaration
(Loc
,
5250 Defining_Identifier
=> T_Self
,
5251 Object_Definition
=>
5252 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
5254 Make_Function_Call
(Loc
,
5255 Name
=> New_Occurrence_Of
(RTE
(RE_Self
), Loc
)));
5256 Prepend
(Decl
, Declarations
(T_Body
));
5258 Set_Scope
(T_Self
, Entity
(N
));
5259 return New_Occurrence_Of
(T_Self
, Loc
);
5264 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
5267 New_Occurrence_Of
(Find_Protection_Object
(Current_Scope
), Loc
);
5271 if Is_Protected_Type
(Ntyp
) then
5272 Sel
:= Name_uObject
;
5273 elsif Is_Task_Type
(Ntyp
) then
5274 Sel
:= Name_uTask_Id
;
5276 raise Program_Error
;
5280 Make_Selected_Component
(Loc
,
5282 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
5284 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
5288 ------------------------
5289 -- Convert_Concurrent --
5290 ------------------------
5292 function Convert_Concurrent
5294 Typ
: Entity_Id
) return Node_Id
5297 if not Is_Concurrent_Type
(Typ
) then
5301 Unchecked_Convert_To
5302 (Corresponding_Record_Type
(Typ
), New_Copy_Tree
(N
));
5304 end Convert_Concurrent
;
5306 -------------------------------------
5307 -- Create_Secondary_Stack_For_Task --
5308 -------------------------------------
5310 function Create_Secondary_Stack_For_Task
(T
: Node_Id
) return Boolean is
5313 (Restriction_Active
(No_Implicit_Heap_Allocations
)
5314 or else Restriction_Active
(No_Implicit_Task_Allocations
))
5315 and then not Restriction_Active
(No_Secondary_Stack
)
5316 and then Has_Rep_Pragma
5317 (T
, Name_Secondary_Stack_Size
, Check_Parents
=> False);
5318 end Create_Secondary_Stack_For_Task
;
5320 -------------------------------------
5321 -- Debug_Private_Data_Declarations --
5322 -------------------------------------
5324 procedure Debug_Private_Data_Declarations
(Decls
: List_Id
) is
5325 Debug_Nod
: Node_Id
;
5329 Decl
:= First
(Decls
);
5330 while Present
(Decl
) and then not Comes_From_Source
(Decl
) loop
5332 -- Declaration for concurrent entity _object and its access type,
5333 -- along with the entry index subtype:
5334 -- type prot_typVP is access prot_typV;
5335 -- _object : prot_typVP := prot_typV (_O);
5336 -- subtype Jnn is <Type of Index> range Low .. High;
5338 if Nkind
(Decl
) in N_Full_Type_Declaration | N_Object_Declaration
then
5339 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5341 -- Declaration for the Protection object, discriminals, privals, and
5342 -- entry index constant:
5343 -- conc_typR : protection_typ renames _object._object;
5344 -- discr_nameD : discr_typ renames _object.discr_name;
5345 -- discr_nameD : discr_typ renames _task.discr_name;
5346 -- prival_name : comp_typ renames _object.comp_name;
5347 -- J : constant Jnn :=
5348 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5350 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
5351 Set_Debug_Info_Needed
(Defining_Identifier
(Decl
));
5352 Debug_Nod
:= Debug_Renaming_Declaration
(Decl
);
5354 if Present
(Debug_Nod
) then
5355 Insert_After
(Decl
, Debug_Nod
);
5361 end Debug_Private_Data_Declarations
;
5363 ------------------------------
5364 -- Ensure_Statement_Present --
5365 ------------------------------
5367 procedure Ensure_Statement_Present
(Loc
: Source_Ptr
; Alt
: Node_Id
) is
5371 if Opt
.Suppress_Control_Flow_Optimizations
5372 and then Is_Empty_List
(Statements
(Alt
))
5374 Stmt
:= Make_Null_Statement
(Loc
);
5376 -- Mark NULL statement as coming from source so that it is not
5377 -- eliminated by GIGI.
5379 -- Another covert channel. If this is a requirement, it must be
5380 -- documented in sinfo/einfo ???
5382 Set_Comes_From_Source
(Stmt
, True);
5384 Set_Statements
(Alt
, New_List
(Stmt
));
5386 end Ensure_Statement_Present
;
5388 ----------------------------
5389 -- Entry_Index_Expression --
5390 ----------------------------
5392 function Entry_Index_Expression
5396 Ttyp
: Entity_Id
) return Node_Id
5406 -- The queues of entries and entry families appear in textual order in
5407 -- the associated record. The entry index is computed as the sum of the
5408 -- number of queues for all entries that precede the designated one, to
5409 -- which is added the index expression, if this expression denotes a
5410 -- member of a family.
5412 -- The following is a place holder for the count of simple entries
5414 Num
:= Make_Integer_Literal
(Sloc
, 1);
5416 -- We construct an expression which is a series of addition operations.
5417 -- The first operand is the number of single entries that precede this
5418 -- one, the second operand is the index value relative to the start of
5419 -- the referenced family, and the remaining operands are the lengths of
5420 -- the entry families that precede this entry, i.e. the constructed
5423 -- number_simple_entries +
5424 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5425 -- family'length + ...
5427 -- where index-value is the given index value, and s is the index
5428 -- subtype (we have to use pos because the subtype might be an
5429 -- enumeration type preventing direct subtraction). Note that the task
5430 -- entry array is one-indexed.
5432 -- The upper bound of the entry family may be a discriminant, so we
5433 -- retrieve the lower bound explicitly to compute offset, rather than
5434 -- using the index subtype which may mention a discriminant.
5436 if Present
(Index
) then
5437 S
:= Entry_Index_Type
(Ent
);
5439 -- First make sure the index is in range if requested. The index type
5440 -- is the pristine Entry_Index_Type of the entry.
5442 if Do_Range_Check
(Index
) then
5443 Generate_Range_Check
(Index
, S
, CE_Range_Check_Failed
);
5452 Make_Attribute_Reference
(Sloc
,
5453 Attribute_Name
=> Name_Pos
,
5454 Prefix
=> New_Occurrence_Of
(Base_Type
(S
), Sloc
),
5455 Expressions
=> New_List
(Relocate_Node
(Index
))),
5463 -- Now add lengths of preceding entries and entry families
5465 Prev
:= First_Entity
(Ttyp
);
5466 while Chars
(Prev
) /= Chars
(Ent
)
5467 or else Ekind
(Prev
) /= Ekind
(Ent
)
5468 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
5470 if Ekind
(Prev
) = E_Entry
then
5471 Set_Intval
(Num
, Intval
(Num
) + 1);
5473 elsif Ekind
(Prev
) = E_Entry_Family
then
5474 S
:= Entry_Index_Type
(Prev
);
5475 Lo
:= Type_Low_Bound
(S
);
5476 Hi
:= Type_High_Bound
(S
);
5481 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
, False));
5483 -- Other components are anonymous types to be ignored
5493 end Entry_Index_Expression
;
5495 ---------------------------
5496 -- Establish_Task_Master --
5497 ---------------------------
5499 procedure Establish_Task_Master
(N
: Node_Id
) is
5503 if Restriction_Active
(No_Task_Hierarchy
) = False then
5504 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
5506 -- The block may have no declarations (and nevertheless be a task
5507 -- master) if it contains a call that may return an object that
5510 if No
(Declarations
(N
)) then
5511 Set_Declarations
(N
, New_List
(Call
));
5513 Prepend_To
(Declarations
(N
), Call
);
5518 end Establish_Task_Master
;
5520 --------------------------------
5521 -- Expand_Accept_Declarations --
5522 --------------------------------
5524 -- Part of the expansion of an accept statement involves the creation of
5525 -- a declaration that can be referenced from the statement sequence of
5530 -- This declaration is inserted immediately before the accept statement
5531 -- and it is important that it be inserted before the statements of the
5532 -- statement sequence are analyzed. Thus it would be too late to create
5533 -- this declaration in the Expand_N_Accept_Statement routine, which is
5534 -- why there is a separate procedure to be called directly from Sem_Ch9.
5536 -- Ann is used to hold the address of the record containing the parameters
5537 -- (see Expand_N_Entry_Call for more details on how this record is built).
5538 -- References to the parameters do an unchecked conversion of this address
5539 -- to a pointer to the required record type, and then access the field that
5540 -- holds the value of the required parameter. The entity for the address
5541 -- variable is held as the top stack element (i.e. the last element) of the
5542 -- Accept_Address stack in the corresponding entry entity, and this element
5543 -- must be set in place before the statements are processed.
5545 -- The above description applies to the case of a stand alone accept
5546 -- statement, i.e. one not appearing as part of a select alternative.
5548 -- For the case of an accept that appears as part of a select alternative
5549 -- of a selective accept, we must still create the declaration right away,
5550 -- since Ann is needed immediately, but there is an important difference:
5552 -- The declaration is inserted before the selective accept, not before
5553 -- the accept statement (which is not part of a list anyway, and so would
5554 -- not accommodate inserted declarations)
5556 -- We only need one address variable for the entire selective accept. So
5557 -- the Ann declaration is created only for the first accept alternative,
5558 -- and subsequent accept alternatives reference the same Ann variable.
5560 -- We can distinguish the two cases by seeing whether the accept statement
5561 -- is part of a list. If not, then it must be in an accept alternative.
5563 -- To expand the requeue statement, a label is provided at the end of the
5564 -- accept statement or alternative of which it is a part, so that the
5565 -- statement can be skipped after the requeue is complete. This label is
5566 -- created here rather than during the expansion of the accept statement,
5567 -- because it will be needed by any requeue statements within the accept,
5568 -- which are expanded before the accept.
5570 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
5571 Loc
: constant Source_Ptr
:= Sloc
(N
);
5572 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
5573 Ann
: Entity_Id
:= Empty
;
5580 if Expander_Active
then
5582 -- If we have no handled statement sequence, we may need to build
5583 -- a dummy sequence consisting of a null statement. This can be
5584 -- skipped if the trivial accept optimization is permitted.
5586 if not Trivial_Accept_OK
5587 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
5589 Set_Handled_Statement_Sequence
(N
,
5590 Make_Handled_Sequence_Of_Statements
(Loc
,
5591 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
5594 -- Create and declare two labels to be placed at the end of the
5595 -- accept statement. The first label is used to allow requeues to
5596 -- skip the remainder of entry processing. The second label is used
5597 -- to skip the remainder of entry processing if the rendezvous
5598 -- completes in the middle of the accept body.
5600 if Present
(Handled_Statement_Sequence
(N
)) then
5605 Ent
:= Make_Temporary
(Loc
, 'L');
5606 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5608 Make_Implicit_Label_Declaration
(Loc
,
5609 Defining_Identifier
=> Ent
,
5610 Label_Construct
=> Lab
);
5611 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5613 Ent
:= Make_Temporary
(Loc
, 'L');
5614 Lab
:= Make_Label
(Loc
, New_Occurrence_Of
(Ent
, Loc
));
5616 Make_Implicit_Label_Declaration
(Loc
,
5617 Defining_Identifier
=> Ent
,
5618 Label_Construct
=> Lab
);
5619 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
5627 -- Case of stand alone accept statement
5629 if Is_List_Member
(N
) then
5631 if Present
(Handled_Statement_Sequence
(N
)) then
5632 Ann
:= Make_Temporary
(Loc
, 'A');
5635 Make_Object_Declaration
(Loc
,
5636 Defining_Identifier
=> Ann
,
5637 Object_Definition
=>
5638 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5640 Insert_Before_And_Analyze
(N
, Adecl
);
5641 Insert_Before_And_Analyze
(N
, Ldecl
);
5642 Insert_Before_And_Analyze
(N
, Ldecl2
);
5645 -- Case of accept statement which is in an accept alternative
5649 Acc_Alt
: constant Node_Id
:= Parent
(N
);
5650 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
5654 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
5655 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
5657 -- ??? Consider a single label for select statements
5659 if Present
(Handled_Statement_Sequence
(N
)) then
5661 Statements
(Handled_Statement_Sequence
(N
)));
5665 Statements
(Handled_Statement_Sequence
(N
)));
5669 -- Find first accept alternative of the selective accept. A
5670 -- valid selective accept must have at least one accept in it.
5672 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
5674 while Nkind
(Alt
) /= N_Accept_Alternative
loop
5678 -- If this is the first accept statement, then we have to
5679 -- create the Ann variable, as for the stand alone case, except
5680 -- that it is inserted before the selective accept. Similarly,
5681 -- a label for requeue expansion must be declared.
5683 if N
= Accept_Statement
(Alt
) then
5684 Ann
:= Make_Temporary
(Loc
, 'A');
5686 Make_Object_Declaration
(Loc
,
5687 Defining_Identifier
=> Ann
,
5688 Object_Definition
=>
5689 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
5691 Insert_Before_And_Analyze
(Sel_Acc
, Adecl
);
5693 -- If this is not the first accept statement, then find the Ann
5694 -- variable allocated by the first accept and use it.
5698 Node
(Last_Elmt
(Accept_Address
5699 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
5704 -- Merge here with Ann either created or referenced, and Adecl
5705 -- pointing to the corresponding declaration. Remaining processing
5706 -- is the same for the two cases.
5708 if Present
(Ann
) then
5709 Append_Elmt
(Ann
, Accept_Address
(Ent
));
5710 Set_Debug_Info_Needed
(Ann
);
5713 -- Create renaming declarations for the entry formals. Each reference
5714 -- to a formal becomes a dereference of a component of the parameter
5715 -- block, whose address is held in Ann. These declarations are
5716 -- eventually inserted into the accept block, and analyzed there so
5717 -- that they have the proper scope for gdb and do not conflict with
5718 -- other declarations.
5720 if Present
(Parameter_Specifications
(N
))
5721 and then Present
(Handled_Statement_Sequence
(N
))
5728 Renamed_Formal
: Node_Id
;
5732 Formal
:= First_Formal
(Ent
);
5734 while Present
(Formal
) loop
5735 Comp
:= Entry_Component
(Formal
);
5736 New_F
:= Make_Defining_Identifier
(Loc
, Chars
(Formal
));
5738 Set_Etype
(New_F
, Etype
(Formal
));
5739 Set_Scope
(New_F
, Ent
);
5741 -- Now we set debug info needed on New_F even though it does
5742 -- not come from source, so that the debugger will get the
5743 -- right information for these generated names.
5745 Set_Debug_Info_Needed
(New_F
);
5747 if Ekind
(Formal
) = E_In_Parameter
then
5748 Mutate_Ekind
(New_F
, E_Constant
);
5750 Mutate_Ekind
(New_F
, E_Variable
);
5751 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
5754 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
5757 Make_Selected_Component
(Loc
,
5759 Make_Explicit_Dereference
(Loc
,
5760 Unchecked_Convert_To
(
5761 Entry_Parameters_Type
(Ent
),
5762 New_Occurrence_Of
(Ann
, Loc
))),
5764 New_Occurrence_Of
(Comp
, Loc
));
5767 Build_Renamed_Formal_Declaration
5768 (New_F
, Formal
, Comp
, Renamed_Formal
);
5770 if No
(Declarations
(N
)) then
5771 Set_Declarations
(N
, New_List
);
5774 Append
(Decl
, Declarations
(N
));
5775 Set_Renamed_Object
(Formal
, New_F
);
5776 Next_Formal
(Formal
);
5783 end Expand_Accept_Declarations
;
5785 ---------------------------------------------
5786 -- Expand_Access_Protected_Subprogram_Type --
5787 ---------------------------------------------
5789 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
5790 Loc
: constant Source_Ptr
:= Sloc
(N
);
5791 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5792 D_T
: constant Entity_Id
:= Designated_Type
(T
);
5793 D_T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'D');
5794 E_T
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
5795 P_List
: constant List_Id
:=
5796 Build_Protected_Spec
(N
, RTE
(RE_Address
), D_T
, False);
5804 -- Create access to subprogram with full signature
5806 if Etype
(D_T
) /= Standard_Void_Type
then
5808 Make_Access_Function_Definition
(Loc
,
5809 Parameter_Specifications
=> P_List
,
5810 Result_Definition
=>
5811 Copy_Result_Type
(Result_Definition
(Type_Definition
(N
))));
5815 Make_Access_Procedure_Definition
(Loc
,
5816 Parameter_Specifications
=> P_List
);
5820 Make_Full_Type_Declaration
(Loc
,
5821 Defining_Identifier
=> D_T2
,
5822 Type_Definition
=> Def1
);
5824 -- Declare the new types before the original one since the latter will
5825 -- refer to them through the Equivalent_Type slot.
5827 Insert_Before_And_Analyze
(N
, Decl1
);
5829 -- Associate the access to subprogram with its original access to
5830 -- protected subprogram type. Needed by the backend to know that this
5831 -- type corresponds with an access to protected subprogram type.
5833 Set_Original_Access_Type
(D_T2
, T
);
5835 -- Create Equivalent_Type, a record with two components for an access to
5836 -- object and an access to subprogram.
5839 Make_Component_Declaration
(Loc
,
5840 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
5841 Component_Definition
=>
5842 Make_Component_Definition
(Loc
,
5843 Aliased_Present
=> False,
5844 Subtype_Indication
=>
5845 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
5847 Make_Component_Declaration
(Loc
,
5848 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5849 Component_Definition
=>
5850 Make_Component_Definition
(Loc
,
5851 Aliased_Present
=> False,
5852 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
5855 Make_Full_Type_Declaration
(Loc
,
5856 Defining_Identifier
=> E_T
,
5858 Make_Record_Definition
(Loc
,
5860 Make_Component_List
(Loc
, Component_Items
=> Comps
)));
5862 Insert_Before_And_Analyze
(N
, Decl2
);
5863 Set_Equivalent_Type
(T
, E_T
);
5864 end Expand_Access_Protected_Subprogram_Type
;
5866 --------------------------
5867 -- Expand_Entry_Barrier --
5868 --------------------------
5870 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
5871 Cond
: constant Node_Id
:= Condition
(Entry_Body_Formal_Part
(N
));
5872 Prot
: constant Entity_Id
:= Scope
(Ent
);
5873 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
5875 Func_Id
: Entity_Id
:= Empty
;
5876 -- The entity of the barrier function
5878 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
;
5879 -- Check whether entity in Barrier is external to protected type.
5880 -- If so, barrier may not be properly synchronized.
5882 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
;
5883 -- Check whether N meets the Pure_Barriers restriction. Return OK if
5886 function Is_Simple_Barrier
(N
: Node_Id
) return Boolean;
5887 -- Check whether N meets the Simple_Barriers restriction. Return OK if
5890 ----------------------
5891 -- Is_Global_Entity --
5892 ----------------------
5894 function Is_Global_Entity
(N
: Node_Id
) return Traverse_Result
is
5899 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
5903 if Ekind
(E
) = E_Variable
then
5905 -- If the variable is local to the barrier function generated
5906 -- during expansion, it is ok. If expansion is not performed,
5907 -- then Func is Empty so this test cannot succeed.
5909 if Scope
(E
) = Func_Id
then
5912 -- A protected call from a barrier to another object is ok
5914 elsif Ekind
(Etype
(E
)) = E_Protected_Type
then
5917 -- If the variable is within the package body we consider
5918 -- this safe. This is a common (if dubious) idiom.
5920 elsif S
= Scope
(Prot
)
5921 and then Is_Package_Or_Generic_Package
(S
)
5922 and then Nkind
(Parent
(E
)) = N_Object_Declaration
5923 and then Nkind
(Parent
(Parent
(E
))) = N_Package_Body
5928 Error_Msg_N
("potentially unsynchronized barrier??", N
);
5929 Error_Msg_N
("\& should be private component of type??", N
);
5935 end Is_Global_Entity
;
5937 procedure Check_Unprotected_Barrier
is
5938 new Traverse_Proc
(Is_Global_Entity
);
5940 -----------------------
5941 -- Is_Simple_Barrier --
5942 -----------------------
5944 function Is_Simple_Barrier
(N
: Node_Id
) return Boolean is
5948 if Is_Static_Expression
(N
) then
5950 elsif Ada_Version
>= Ada_2022
5951 and then Nkind
(N
) in N_Selected_Component | N_Indexed_Component
5952 and then Statically_Names_Object
(N
)
5954 -- Restriction relaxed in Ada 2022 to allow statically named
5956 return Is_Simple_Barrier
(Prefix
(N
));
5959 -- Check if the name is a component of the protected object. If
5960 -- the expander is active, the component has been transformed into a
5961 -- renaming of _object.all.component. Original_Node is needed in case
5962 -- validity checking is enabled, in which case the simple object
5963 -- reference will have been rewritten.
5965 if Expander_Active
then
5967 -- The expanded name may have been constant folded in which case
5968 -- the original node is not necessarily an entity name (e.g. an
5969 -- indexed component).
5971 if not Is_Entity_Name
(Original_Node
(N
)) then
5975 Renamed
:= Renamed_Object
(Entity
(Original_Node
(N
)));
5979 and then Nkind
(Renamed
) = N_Selected_Component
5980 and then Chars
(Prefix
(Prefix
(Renamed
))) = Name_uObject
;
5981 elsif not Is_Entity_Name
(N
) then
5984 return Is_Protected_Component
(Entity
(N
));
5986 end Is_Simple_Barrier
;
5988 ---------------------
5989 -- Is_Pure_Barrier --
5990 ---------------------
5992 function Is_Pure_Barrier
(N
: Node_Id
) return Traverse_Result
is
5995 when N_Expanded_Name
5999 -- Because of N_Expanded_Name case, return Skip instead of OK.
6001 if No
(Entity
(N
)) then
6004 elsif Is_Numeric_Type
(Entity
(N
)) then
6008 case Ekind
(Entity
(N
)) is
6014 when E_Enumeration_Literal
6018 if not Is_OK_Static_Expression
(N
) then
6027 if Is_Simple_Barrier
(N
) then
6033 -- The count attribute has been transformed into run-time
6036 if Is_RTE
(Entity
(N
), RE_Protected_Count
)
6037 or else Is_RTE
(Entity
(N
), RE_Protected_Count_Entry
)
6046 when N_Function_Call
=>
6048 -- Function call checks are carried out as part of the analysis
6049 -- of the function call name.
6053 when N_Character_Literal
6062 if Ekind
(Entity
(N
)) = E_Operator
then
6066 when N_Short_Circuit
6072 when N_Indexed_Component | N_Selected_Component
=>
6073 if Statically_Names_Object
(N
) then
6074 return Is_Pure_Barrier
(Prefix
(N
));
6079 when N_Case_Expression_Alternative
=>
6080 -- do not traverse Discrete_Choices subtree
6081 if Is_Pure_Barrier
(Expression
(N
)) /= Abandon
then
6085 when N_Expression_With_Actions
=>
6086 -- this may occur in the case of a Count attribute reference
6087 if Is_Rewrite_Substitution
(N
)
6088 and then Is_Pure_Barrier
(Original_Node
(N
)) /= Abandon
6093 when N_Membership_Test
=>
6094 if Is_Pure_Barrier
(Left_Opnd
(N
)) /= Abandon
6095 and then All_Membership_Choices_Static
(N
)
6100 when N_Type_Conversion
=>
6102 -- Conversions to Universal_Integer do not raise constraint
6103 -- errors. Likewise if the expression's type is statically
6104 -- compatible with the target's type.
6106 if Etype
(N
) = Universal_Integer
6107 or else Subtypes_Statically_Compatible
6108 (Etype
(Expression
(N
)), Etype
(N
))
6113 when N_Unchecked_Type_Conversion
=>
6121 end Is_Pure_Barrier
;
6123 function Check_Pure_Barriers
is new Traverse_Func
(Is_Pure_Barrier
);
6127 Cond_Id
: Entity_Id
;
6128 Entry_Body
: Node_Id
;
6129 Func_Body
: Node_Id
:= Empty
;
6131 -- Start of processing for Expand_Entry_Barrier
6134 if No_Run_Time_Mode
then
6135 Error_Msg_CRT
("entry barrier", N
);
6139 -- Prevent cascaded errors
6141 if Nkind
(Cond
) = N_Error
then
6145 -- The body of the entry barrier must be analyzed in the context of the
6146 -- protected object, but its scope is external to it, just as any other
6147 -- unprotected version of a protected operation. The specification has
6148 -- been produced when the protected type declaration was elaborated. We
6149 -- build the body, insert it in the enclosing scope, but analyze it in
6150 -- the current context. A more uniform approach would be to treat the
6151 -- barrier just as a protected function, and discard the protected
6152 -- version of it because it is never called.
6154 if Expander_Active
then
6155 Func_Body
:= Build_Barrier_Function
(N
, Ent
, Prot
);
6156 Func_Id
:= Barrier_Function
(Ent
);
6157 Set_Corresponding_Spec
(Func_Body
, Func_Id
);
6159 Entry_Body
:= Parent
(Corresponding_Body
(Spec_Decl
));
6161 if Nkind
(Parent
(Entry_Body
)) = N_Subunit
then
6162 Entry_Body
:= Corresponding_Stub
(Parent
(Entry_Body
));
6165 Insert_Before_And_Analyze
(Entry_Body
, Func_Body
);
6167 Set_Discriminals
(Spec_Decl
);
6168 Set_Scope
(Func_Id
, Scope
(Prot
));
6171 Analyze_And_Resolve
(Cond
, Any_Boolean
);
6174 -- Check Simple_Barriers and Pure_Barriers restrictions.
6175 -- Note that it is safe to be calling Check_Restriction from here, even
6176 -- though this is part of the expander, since Expand_Entry_Barrier is
6177 -- called from Sem_Ch9 even in -gnatc mode.
6179 if not Is_Simple_Barrier
(Cond
) then
6180 -- flag restriction violation
6181 Check_Restriction
(Simple_Barriers
, Cond
);
6184 if Check_Pure_Barriers
(Cond
) = Abandon
then
6185 -- flag restriction violation
6186 Check_Restriction
(Pure_Barriers
, Cond
);
6188 -- Emit warning if barrier contains global entities and is thus
6189 -- potentially unsynchronized (if Pure_Barriers restrictions
6190 -- are met then no need to check for this).
6191 Check_Unprotected_Barrier
(Cond
);
6194 if Is_Entity_Name
(Cond
) then
6195 Cond_Id
:= Entity
(Cond
);
6197 -- Perform a small optimization of simple barrier functions. If the
6198 -- scope of the condition's entity is not the barrier function, then
6199 -- the condition does not depend on any of the generated renamings.
6200 -- If this is the case, eliminate the renamings as they are useless.
6201 -- This optimization is not performed when the condition was folded
6202 -- and validity checks are in effect because the original condition
6203 -- may have produced at least one check that depends on the generated
6207 and then Scope
(Cond_Id
) /= Func_Id
6208 and then not Validity_Check_Operands
6210 Set_Declarations
(Func_Body
, Empty_List
);
6213 -- Note that after analysis variables in this context will be
6214 -- replaced by the corresponding prival, that is to say a renaming
6215 -- of a selected component of the form _Object.Var. If expansion is
6216 -- disabled, as within a generic, we check that the entity appears in
6217 -- the current scope.
6219 end Expand_Entry_Barrier
;
6221 ------------------------------
6222 -- Expand_N_Abort_Statement --
6223 ------------------------------
6225 -- Expand abort T1, T2, .. Tn; into:
6226 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6228 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
6229 Loc
: constant Source_Ptr
:= Sloc
(N
);
6230 Tlist
: constant List_Id
:= Names
(N
);
6236 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
6239 Tasknm
:= First
(Tlist
);
6241 while Present
(Tasknm
) loop
6244 -- A task interface class-wide type object is being aborted. Retrieve
6245 -- its _task_id by calling a dispatching routine.
6247 if Ada_Version
>= Ada_2005
6248 and then Ekind
(Etype
(Tasknm
)) = E_Class_Wide_Type
6249 and then Is_Interface
(Etype
(Tasknm
))
6250 and then Is_Task_Interface
(Etype
(Tasknm
))
6252 Append_To
(Component_Associations
(Aggr
),
6253 Make_Component_Association
(Loc
,
6254 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6257 -- Task_Id (Tasknm._disp_get_task_id)
6259 Unchecked_Convert_To
6260 (RTE
(RO_ST_Task_Id
),
6261 Make_Selected_Component
(Loc
,
6262 Prefix
=> New_Copy_Tree
(Tasknm
),
6264 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
6267 Append_To
(Component_Associations
(Aggr
),
6268 Make_Component_Association
(Loc
,
6269 Choices
=> New_List
(Make_Integer_Literal
(Loc
, Count
)),
6270 Expression
=> Concurrent_Ref
(Tasknm
)));
6277 Make_Procedure_Call_Statement
(Loc
,
6278 Name
=> New_Occurrence_Of
(RTE
(RE_Abort_Tasks
), Loc
),
6279 Parameter_Associations
=> New_List
(
6280 Make_Qualified_Expression
(Loc
,
6281 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Task_List
), Loc
),
6282 Expression
=> Aggr
))));
6285 end Expand_N_Abort_Statement
;
6287 -------------------------------
6288 -- Expand_N_Accept_Statement --
6289 -------------------------------
6291 -- This procedure handles expansion of accept statements that stand alone,
6292 -- i.e. they are not part of an accept alternative. The expansion of
6293 -- accept statement in accept alternatives is handled by the routines
6294 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6295 -- following description applies only to stand alone accept statements.
6297 -- If there is no handled statement sequence, or only null statements, then
6298 -- this is called a trivial accept, and the expansion is:
6300 -- Accept_Trivial (entry-index)
6302 -- If there is a handled statement sequence, then the expansion is:
6309 -- Accept_Call (entry-index, Ann);
6310 -- Renaming_Declarations for formals
6311 -- <statement sequence from N_Accept_Statement node>
6312 -- Complete_Rendezvous;
6317 -- <exception handler from N_Accept_Statement node>
6318 -- Complete_Rendezvous;
6320 -- <exception handler from N_Accept_Statement node>
6321 -- Complete_Rendezvous;
6326 -- when all others =>
6327 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6330 -- The first three declarations were already inserted ahead of the accept
6331 -- statement by the Expand_Accept_Declarations procedure, which was called
6332 -- directly from the semantics during analysis of the accept statement,
6333 -- before analyzing its contained statements.
6335 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6336 -- from possible expansion activity (the original source of course does
6337 -- not have any declarations associated with the accept statement, since
6338 -- an accept statement has no declarative part). In particular, if the
6339 -- expander is active, the first such declaration is the declaration of
6340 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6342 -- The two blocks are merged into a single block if the inner block has
6343 -- no exception handlers, but otherwise two blocks are required, since
6344 -- exceptions might be raised in the exception handlers of the inner
6345 -- block, and Exceptional_Complete_Rendezvous must be called.
6347 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
6348 Loc
: constant Source_Ptr
:= Sloc
(N
);
6349 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
6350 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
6351 Eindx
: constant Node_Id
:= Entry_Index
(N
);
6352 Eent
: constant Entity_Id
:= Entity
(Ename
);
6353 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
6354 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
6355 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
6361 -- If the accept statement is not part of a list, then its parent must
6362 -- be an accept alternative, and, as described above, we do not do any
6363 -- expansion for such accept statements at this level.
6365 if not Is_List_Member
(N
) then
6366 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
6369 -- Trivial accept case (no statement sequence, or null statements).
6370 -- If the accept statement has declarations, then just insert them
6371 -- before the procedure call.
6373 elsif Trivial_Accept_OK
6374 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
6376 -- Remove declarations for renamings, because the parameter block
6377 -- will not be assigned.
6384 D
:= First
(Declarations
(N
));
6385 while Present
(D
) loop
6387 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6395 if Present
(Declarations
(N
)) then
6396 Insert_Actions
(N
, Declarations
(N
));
6400 Make_Procedure_Call_Statement
(Loc
,
6401 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Trivial
), Loc
),
6402 Parameter_Associations
=> New_List
(
6403 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
6407 -- Ada 2022 (AI12-0279)
6409 if Has_Yield_Aspect
(Eent
)
6410 and then RTE_Available
(RE_Yield
)
6412 Insert_Action_After
(N
,
6413 Make_Procedure_Call_Statement
(Loc
,
6414 New_Occurrence_Of
(RTE
(RE_Yield
), Loc
)));
6417 -- Discard Entry_Address that was created for it, so it will not be
6418 -- emitted if this accept statement is in the statement part of a
6419 -- delay alternative.
6421 if Present
(Stats
) then
6422 Remove_Last_Elmt
(Acstack
);
6425 -- Case of statement sequence present
6428 -- Construct the block, using the declarations from the accept
6429 -- statement if any to initialize the declarations of the block.
6431 Blkent
:= Make_Temporary
(Loc
, 'A');
6432 Mutate_Ekind
(Blkent
, E_Block
);
6433 Set_Etype
(Blkent
, Standard_Void_Type
);
6434 Set_Scope
(Blkent
, Current_Scope
);
6437 Make_Block_Statement
(Loc
,
6438 Identifier
=> New_Occurrence_Of
(Blkent
, Loc
),
6439 Declarations
=> Declarations
(N
),
6440 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
6442 -- Reset the Scope of local entities associated with the accept
6443 -- statement (that currently reference the entry scope) to the
6444 -- block scope, to avoid having references to the locals treated
6445 -- as up-level references.
6447 Reset_Scopes_To
(Block
, Blkent
);
6449 -- For the analysis of the generated declarations, the parent node
6450 -- must be properly set.
6452 Set_Parent
(Block
, Parent
(N
));
6453 Set_Parent
(Blkent
, Block
);
6455 -- Prepend call to Accept_Call to main statement sequence If the
6456 -- accept has exception handlers, the statement sequence is wrapped
6457 -- in a block. Insert call and renaming declarations in the
6458 -- declarations of the block, so they are elaborated before the
6462 Make_Procedure_Call_Statement
(Loc
,
6463 Name
=> New_Occurrence_Of
(RTE
(RE_Accept_Call
), Loc
),
6464 Parameter_Associations
=> New_List
(
6465 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
6466 New_Occurrence_Of
(Ann
, Loc
)));
6468 if Parent
(Stats
) = N
then
6469 Prepend
(Call
, Statements
(Stats
));
6471 Set_Declarations
(Parent
(Stats
), New_List
(Call
));
6476 Push_Scope
(Blkent
);
6484 D
:= First
(Declarations
(N
));
6485 while Present
(D
) loop
6488 if Nkind
(D
) = N_Object_Renaming_Declaration
then
6490 -- The renaming declarations for the formals were created
6491 -- during analysis of the accept statement, and attached to
6492 -- the list of declarations. Place them now in the context
6493 -- of the accept block or subprogram.
6496 Typ
:= Entity
(Subtype_Mark
(D
));
6497 Insert_After
(Call
, D
);
6500 -- If the formal is class_wide, it does not have an actual
6501 -- subtype. The analysis of the renaming declaration creates
6502 -- one, but we need to retain the class-wide nature of the
6505 if Is_Class_Wide_Type
(Typ
) then
6506 Set_Etype
(Defining_Identifier
(D
), Typ
);
6517 -- Replace the accept statement by the new block
6522 -- Last step is to unstack the Accept_Address value
6524 Remove_Last_Elmt
(Acstack
);
6526 end Expand_N_Accept_Statement
;
6528 ----------------------------------
6529 -- Expand_N_Asynchronous_Select --
6530 ----------------------------------
6532 -- This procedure assumes that the trigger statement is an entry call or
6533 -- a dispatching procedure call. A delay alternative should already have
6534 -- been expanded into an entry call to the appropriate delay object Wait
6537 -- If the trigger is a task entry call, the select is implemented with
6538 -- a Task_Entry_Call:
6543 -- P : parms := (parm, parm, parm);
6545 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6547 -- procedure _clean is
6550 -- Cancel_Task_Entry_Call (C);
6557 -- (<acceptor-task>, -- Acceptor
6558 -- <entry-index>, -- E
6559 -- P'Address, -- Uninterpreted_Data
6560 -- Asynchronous_Call, -- Mode
6561 -- B); -- Rendezvous_Successful
6568 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6571 -- when Abort_Signal => Abort_Undefer;
6578 -- <triggered-statements>
6582 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6583 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6587 -- P : parms := (parm, parm, parm);
6589 -- Call_Simple (acceptor-task, entry-index, P'Address);
6595 -- so the task at hand is to convert the latter expansion into the former
6597 -- If the trigger is a protected entry call, the select is implemented
6598 -- with Protected_Entry_Call:
6601 -- P : E1_Params := (param, param, param);
6602 -- Bnn : Communications_Block;
6607 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6609 -- procedure _clean is
6612 -- if Enqueued (Bnn) then
6613 -- Cancel_Protected_Entry_Call (Bnn);
6620 -- Protected_Entry_Call
6621 -- (po._object'Access, -- Object
6622 -- <entry index>, -- E
6623 -- P'Address, -- Uninterpreted_Data
6624 -- Asynchronous_Call, -- Mode
6627 -- if Enqueued (Bnn) then
6631 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6634 -- when Abort_Signal => Abort_Undefer;
6637 -- if not Cancelled (Bnn) then
6638 -- <triggered-statements>
6642 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6646 -- P : E1_Params := (param, param, param);
6647 -- Bnn : Communications_Block;
6650 -- Protected_Entry_Call
6651 -- (po._object'Access, -- Object
6652 -- <entry index>, -- E
6653 -- P'Address, -- Uninterpreted_Data
6654 -- Simple_Call, -- Mode
6661 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6665 -- B : Boolean := False;
6666 -- Bnn : Communication_Block;
6667 -- C : Ada.Tags.Prim_Op_Kind;
6668 -- D : System.Storage_Elements.Dummy_Communication_Block;
6669 -- K : Ada.Tags.Tagged_Kind :=
6670 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6671 -- P : Parameters := (Param1 .. ParamN);
6676 -- if K = Ada.Tags.TK_Limited_Tagged
6677 -- or else K = Ada.Tags.TK_Tagged
6679 -- <dispatching-call>;
6680 -- <triggering-statements>;
6684 -- Ada.Tags.Get_Offset_Index
6685 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6687 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6689 -- if C = POK_Protected_Entry then
6691 -- procedure _clean is
6693 -- if Enqueued (Bnn) then
6694 -- Cancel_Protected_Entry_Call (Bnn);
6700 -- _Disp_Asynchronous_Select
6701 -- (<object>, S, P'Address, D, B);
6702 -- Bnn := Communication_Block (D);
6704 -- Param1 := P.Param1;
6706 -- ParamN := P.ParamN;
6708 -- if Enqueued (Bnn) then
6709 -- <abortable-statements>
6712 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6715 -- when Abort_Signal => Abort_Undefer;
6718 -- if not Cancelled (Bnn) then
6719 -- <triggering-statements>
6722 -- elsif C = POK_Task_Entry then
6724 -- procedure _clean is
6726 -- Cancel_Task_Entry_Call (U);
6732 -- _Disp_Asynchronous_Select
6733 -- (<object>, S, P'Address, D, B);
6734 -- Bnn := Communication_Bloc (D);
6736 -- Param1 := P.Param1;
6738 -- ParamN := P.ParamN;
6743 -- <abortable-statements>
6745 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6748 -- when Abort_Signal => Abort_Undefer;
6752 -- <triggering-statements>
6757 -- <dispatching-call>;
6758 -- <triggering-statements>
6763 -- The job is to convert this to the asynchronous form
6765 -- If the trigger is a delay statement, it will have been expanded into
6766 -- a call to one of the GNARL delay procedures. This routine will convert
6767 -- this into a protected entry call on a delay object and then continue
6768 -- processing as for a protected entry call trigger. This requires
6769 -- declaring a Delay_Block object and adding a pointer to this object to
6770 -- the parameter list of the delay procedure to form the parameter list of
6771 -- the entry call. This object is used by the runtime to queue the delay
6774 -- For a description of the use of P and the assignments after the call,
6775 -- see Expand_N_Entry_Call_Statement.
6777 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
6778 Loc
: constant Source_Ptr
:= Sloc
(N
);
6779 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
6780 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
6782 Abort_Block_Ent
: Entity_Id
;
6783 Abortable_Block
: Node_Id
;
6786 Blk_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6787 Blk_Typ
: Entity_Id
;
6789 Call_Ent
: Entity_Id
;
6790 Cancel_Param
: Entity_Id
;
6791 Cleanup_Block
: Node_Id
;
6792 Cleanup_Block_Ent
: Entity_Id
;
6793 Cleanup_Stmts
: List_Id
;
6794 Conc_Typ_Stmts
: List_Id
;
6796 Dblock_Ent
: Entity_Id
;
6801 Enqueue_Call
: Node_Id
;
6805 Lim_Typ_Stmts
: List_Id
;
6811 ProtE_Stmts
: List_Id
;
6812 ProtP_Stmts
: List_Id
;
6815 TaskE_Stmts
: List_Id
;
6818 B
: Entity_Id
; -- Call status flag
6819 Bnn
: Entity_Id
; -- Communication block
6820 C
: Entity_Id
; -- Call kind
6821 K
: Entity_Id
; -- Tagged kind
6822 P
: Entity_Id
; -- Parameter block
6823 S
: Entity_Id
; -- Primitive operation slot
6824 T
: Entity_Id
; -- Additional status flag
6826 procedure Rewrite_Abortable_Part
;
6827 -- If the trigger is a dispatching call, the expansion inserts multiple
6828 -- copies of the abortable part. This is both inefficient, and may lead
6829 -- to duplicate definitions that the back-end will reject, when the
6830 -- abortable part includes loops. This procedure rewrites the abortable
6831 -- part into a call to a generated procedure.
6833 ----------------------------
6834 -- Rewrite_Abortable_Part --
6835 ----------------------------
6837 procedure Rewrite_Abortable_Part
is
6838 Proc
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uA
);
6843 Make_Subprogram_Body
(Loc
,
6845 Make_Procedure_Specification
(Loc
, Defining_Unit_Name
=> Proc
),
6846 Declarations
=> New_List
,
6847 Handled_Statement_Sequence
=>
6848 Make_Handled_Sequence_Of_Statements
(Loc
, Astats
));
6849 Insert_Before
(N
, Decl
);
6852 -- Rewrite abortable part into a call to this procedure
6856 Make_Procedure_Call_Statement
(Loc
,
6857 Name
=> New_Occurrence_Of
(Proc
, Loc
)));
6858 end Rewrite_Abortable_Part
;
6860 -- Start of processing for Expand_N_Asynchronous_Select
6863 -- Asynchronous select is not supported on restricted runtimes. Don't
6866 if Restricted_Profile
then
6870 Process_Statements_For_Controlled_Objects
(Trig
);
6871 Process_Statements_For_Controlled_Objects
(Abrt
);
6873 Ecall
:= Triggering_Statement
(Trig
);
6875 Ensure_Statement_Present
(Sloc
(Ecall
), Trig
);
6877 -- Retrieve Astats and Tstats now because the finalization machinery may
6878 -- wrap them in blocks.
6880 Astats
:= Statements
(Abrt
);
6881 Tstats
:= Statements
(Trig
);
6883 -- The arguments in the call may require dynamic allocation, and the
6884 -- call statement may have been transformed into a block. The block
6885 -- may contain additional declarations for internal entities, and the
6886 -- original call is found by sequential search.
6888 if Nkind
(Ecall
) = N_Block_Statement
then
6889 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
6890 while Nkind
(Ecall
) not in
6891 N_Procedure_Call_Statement | N_Entry_Call_Statement
6897 -- This is either a dispatching call or a delay statement used as a
6898 -- trigger which was expanded into a procedure call.
6900 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
6901 if Ada_Version
>= Ada_2005
6903 (No
(Original_Node
(Ecall
))
6904 or else Nkind
(Original_Node
(Ecall
)) not in N_Delay_Statement
)
6906 Extract_Dispatching_Call
(Ecall
, Call_Ent
, Obj
, Actuals
, Formals
);
6908 Rewrite_Abortable_Part
;
6912 -- Call status flag processing, generate:
6913 -- B : Boolean := False;
6915 B
:= Build_B
(Loc
, Decls
);
6917 -- Communication block processing, generate:
6918 -- Bnn : Communication_Block;
6920 Bnn
:= Make_Temporary
(Loc
, 'B');
6922 Make_Object_Declaration
(Loc
,
6923 Defining_Identifier
=> Bnn
,
6924 Object_Definition
=>
6925 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
6927 -- Call kind processing, generate:
6928 -- C : Ada.Tags.Prim_Op_Kind;
6930 C
:= Build_C
(Loc
, Decls
);
6932 -- Tagged kind processing, generate:
6933 -- K : Ada.Tags.Tagged_Kind :=
6934 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6936 -- Dummy communication block, generate:
6937 -- D : Dummy_Communication_Block;
6940 Make_Object_Declaration
(Loc
,
6941 Defining_Identifier
=>
6942 Make_Defining_Identifier
(Loc
, Name_uD
),
6943 Object_Definition
=>
6945 (RTE
(RE_Dummy_Communication_Block
), Loc
)));
6947 K
:= Build_K
(Loc
, Decls
, Obj
);
6949 -- Parameter block processing
6951 Blk_Typ
:= Build_Parameter_Block
6952 (Loc
, Actuals
, Formals
, Decls
);
6953 P
:= Parameter_Block_Pack
6954 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
6956 -- Dispatch table slot processing, generate:
6959 S
:= Build_S
(Loc
, Decls
);
6961 -- Additional status flag processing, generate:
6964 T
:= Make_Temporary
(Loc
, 'T');
6966 Make_Object_Declaration
(Loc
,
6967 Defining_Identifier
=> T
,
6968 Object_Definition
=>
6969 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
6971 ------------------------------
6972 -- Protected entry handling --
6973 ------------------------------
6976 -- Param1 := P.Param1;
6978 -- ParamN := P.ParamN;
6980 Cleanup_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
6983 -- Bnn := Communication_Block (D);
6985 Prepend_To
(Cleanup_Stmts
,
6986 Make_Assignment_Statement
(Loc
,
6987 Name
=> New_Occurrence_Of
(Bnn
, Loc
),
6989 Unchecked_Convert_To
6990 (RTE
(RE_Communication_Block
),
6991 Make_Identifier
(Loc
, Name_uD
))));
6994 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6996 Prepend_To
(Cleanup_Stmts
,
6997 Make_Procedure_Call_Statement
(Loc
,
7001 (Etype
(Etype
(Obj
)), Name_uDisp_Asynchronous_Select
),
7003 Parameter_Associations
=>
7005 New_Copy_Tree
(Obj
), -- <object>
7006 New_Occurrence_Of
(S
, Loc
), -- S
7007 Make_Attribute_Reference
(Loc
, -- P'Address
7008 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7009 Attribute_Name
=> Name_Address
),
7010 Make_Identifier
(Loc
, Name_uD
), -- D
7011 New_Occurrence_Of
(B
, Loc
)))); -- B
7014 -- if Enqueued (Bnn) then
7015 -- <abortable-statements>
7018 Append_To
(Cleanup_Stmts
,
7019 Make_Implicit_If_Statement
(N
,
7021 Make_Function_Call
(Loc
,
7023 New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7024 Parameter_Associations
=>
7025 New_List
(New_Occurrence_Of
(Bnn
, Loc
))),
7028 New_Copy_List_Tree
(Astats
)));
7030 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7031 -- will then generate a _clean for the communication block Bnn.
7035 -- procedure _clean is
7037 -- if Enqueued (Bnn) then
7038 -- Cancel_Protected_Entry_Call (Bnn);
7047 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7049 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, Bnn
);
7051 -- Wrap the cleanup block in an exception handling block
7057 -- when Abort_Signal => Abort_Undefer;
7060 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7063 Make_Implicit_Label_Declaration
(Loc
,
7064 Defining_Identifier
=> Abort_Block_Ent
),
7067 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7070 -- if not Cancelled (Bnn) then
7071 -- <triggering-statements>
7074 Append_To
(ProtE_Stmts
,
7075 Make_Implicit_If_Statement
(N
,
7079 Make_Function_Call
(Loc
,
7081 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7082 Parameter_Associations
=>
7083 New_List
(New_Occurrence_Of
(Bnn
, Loc
)))),
7086 New_Copy_List_Tree
(Tstats
)));
7088 -------------------------
7089 -- Task entry handling --
7090 -------------------------
7093 -- Param1 := P.Param1;
7095 -- ParamN := P.ParamN;
7097 TaskE_Stmts
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7100 -- Bnn := Communication_Block (D);
7102 Append_To
(TaskE_Stmts
,
7103 Make_Assignment_Statement
(Loc
,
7105 New_Occurrence_Of
(Bnn
, Loc
),
7107 Unchecked_Convert_To
7108 (RTE
(RE_Communication_Block
),
7109 Make_Identifier
(Loc
, Name_uD
))));
7112 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7114 Prepend_To
(TaskE_Stmts
,
7115 Make_Procedure_Call_Statement
(Loc
,
7118 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7119 Name_uDisp_Asynchronous_Select
),
7122 Parameter_Associations
=> New_List
(
7123 New_Copy_Tree
(Obj
), -- <object>
7124 New_Occurrence_Of
(S
, Loc
), -- S
7125 Make_Attribute_Reference
(Loc
, -- P'Address
7126 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7127 Attribute_Name
=> Name_Address
),
7128 Make_Identifier
(Loc
, Name_uD
), -- D
7129 New_Occurrence_Of
(B
, Loc
)))); -- B
7134 Prepend_To
(TaskE_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7138 -- <abortable-statements>
7140 Cleanup_Stmts
:= New_Copy_List_Tree
(Astats
);
7143 (Cleanup_Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7145 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7146 -- will generate a _clean for the additional status flag.
7150 -- procedure _clean is
7152 -- Cancel_Task_Entry_Call (U);
7160 Cleanup_Block_Ent
:= Make_Temporary
(Loc
, 'C');
7162 Build_Cleanup_Block
(Loc
, Cleanup_Block_Ent
, Cleanup_Stmts
, T
);
7164 -- Wrap the cleanup block in an exception handling block
7170 -- when Abort_Signal => Abort_Undefer;
7173 Abort_Block_Ent
:= Make_Temporary
(Loc
, 'A');
7175 Append_To
(TaskE_Stmts
,
7176 Make_Implicit_Label_Declaration
(Loc
,
7177 Defining_Identifier
=> Abort_Block_Ent
));
7179 Append_To
(TaskE_Stmts
,
7181 (Loc
, Abort_Block_Ent
, Cleanup_Block_Ent
, Cleanup_Block
));
7185 -- <triggering-statements>
7188 Append_To
(TaskE_Stmts
,
7189 Make_Implicit_If_Statement
(N
,
7191 Make_Op_Not
(Loc
, Right_Opnd
=> New_Occurrence_Of
(T
, Loc
)),
7194 New_Copy_List_Tree
(Tstats
)));
7196 ----------------------------------
7197 -- Protected procedure handling --
7198 ----------------------------------
7201 -- <dispatching-call>;
7202 -- <triggering-statements>
7204 ProtP_Stmts
:= New_Copy_List_Tree
(Tstats
);
7205 Prepend_To
(ProtP_Stmts
, New_Copy_Tree
(Ecall
));
7208 -- S := Ada.Tags.Get_Offset_Index
7209 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7212 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7215 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7217 Append_To
(Conc_Typ_Stmts
,
7218 Make_Procedure_Call_Statement
(Loc
,
7221 (Find_Prim_Op
(Etype
(Etype
(Obj
)),
7222 Name_uDisp_Get_Prim_Op_Kind
),
7224 Parameter_Associations
=>
7226 New_Copy_Tree
(Obj
),
7227 New_Occurrence_Of
(S
, Loc
),
7228 New_Occurrence_Of
(C
, Loc
))));
7231 -- if C = POK_Procedure_Entry then
7233 -- elsif C = POK_Task_Entry then
7239 Append_To
(Conc_Typ_Stmts
,
7240 Make_Implicit_If_Statement
(N
,
7244 New_Occurrence_Of
(C
, Loc
),
7246 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
7253 Make_Elsif_Part
(Loc
,
7257 New_Occurrence_Of
(C
, Loc
),
7259 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
)),
7268 -- <dispatching-call>;
7269 -- <triggering-statements>
7271 Lim_Typ_Stmts
:= New_Copy_List_Tree
(Tstats
);
7272 Prepend_To
(Lim_Typ_Stmts
, New_Copy_Tree
(Ecall
));
7275 -- if K = Ada.Tags.TK_Limited_Tagged
7276 -- or else K = Ada.Tags.TK_Tagged
7284 Make_Implicit_If_Statement
(N
,
7285 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7286 Then_Statements
=> Lim_Typ_Stmts
,
7287 Else_Statements
=> Conc_Typ_Stmts
));
7290 Make_Block_Statement
(Loc
,
7293 Handled_Statement_Sequence
=>
7294 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7299 -- Delay triggering statement processing
7302 -- Add a Delay_Block object to the parameter list of the delay
7303 -- procedure to form the parameter list of the Wait entry call.
7305 Dblock_Ent
:= Make_Temporary
(Loc
, 'D');
7307 Pdef
:= Entity
(Name
(Ecall
));
7309 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
7311 New_Occurrence_Of
(RTE
(RE_Enqueue_Duration
), Loc
);
7313 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
7315 New_Occurrence_Of
(RTE
(RE_Enqueue_Calendar
), Loc
);
7317 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
7318 Enqueue_Call
:= New_Occurrence_Of
(RTE
(RE_Enqueue_RT
), Loc
);
7321 Append_To
(Parameter_Associations
(Ecall
),
7322 Make_Attribute_Reference
(Loc
,
7323 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7324 Attribute_Name
=> Name_Unchecked_Access
));
7326 -- Create the inner block to protect the abortable part
7328 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7330 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7333 Make_Block_Statement
(Loc
,
7334 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7335 Handled_Statement_Sequence
=>
7336 Make_Handled_Sequence_Of_Statements
(Loc
,
7337 Statements
=> Astats
),
7338 Has_Created_Identifier
=> True,
7339 Is_Asynchronous_Call_Block
=> True);
7341 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7344 Make_Implicit_If_Statement
(N
,
7346 Make_Function_Call
(Loc
,
7347 Name
=> Enqueue_Call
,
7348 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
7350 New_List
(Make_Block_Statement
(Loc
,
7351 Handled_Statement_Sequence
=>
7352 Make_Handled_Sequence_Of_Statements
(Loc
,
7353 Statements
=> New_List
(
7354 Make_Implicit_Label_Declaration
(Loc
,
7355 Defining_Identifier
=> Blk_Ent
,
7356 Label_Construct
=> Abortable_Block
),
7358 Exception_Handlers
=> Hdle
)))));
7360 Stmts
:= New_List
(Ecall
);
7362 -- Construct statement sequence for new block
7365 Make_Implicit_If_Statement
(N
,
7367 Make_Function_Call
(Loc
,
7368 Name
=> New_Occurrence_Of
(
7369 RTE
(RE_Timed_Out
), Loc
),
7370 Parameter_Associations
=> New_List
(
7371 Make_Attribute_Reference
(Loc
,
7372 Prefix
=> New_Occurrence_Of
(Dblock_Ent
, Loc
),
7373 Attribute_Name
=> Name_Unchecked_Access
))),
7374 Then_Statements
=> Tstats
));
7376 -- The result is the new block
7378 Set_Entry_Cancel_Parameter
(Blk_Ent
, Dblock_Ent
);
7381 Make_Block_Statement
(Loc
,
7382 Declarations
=> New_List
(
7383 Make_Object_Declaration
(Loc
,
7384 Defining_Identifier
=> Dblock_Ent
,
7385 Aliased_Present
=> True,
7386 Object_Definition
=>
7387 New_Occurrence_Of
(RTE
(RE_Delay_Block
), Loc
))),
7389 Handled_Statement_Sequence
=>
7390 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7400 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
7401 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
7403 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
7404 Decls
:= Declarations
(Ecall
);
7406 if Is_Protected_Type
(Etype
(Concval
)) then
7408 -- Get the declarations of the block expanded from the entry call
7410 Decl
:= First
(Decls
);
7411 while Present
(Decl
)
7412 and then (Nkind
(Decl
) /= N_Object_Declaration
7413 or else not Is_RTE
(Etype
(Object_Definition
(Decl
)),
7414 RE_Communication_Block
))
7419 pragma Assert
(Present
(Decl
));
7420 Cancel_Param
:= Defining_Identifier
(Decl
);
7422 -- Change the mode of the Protected_Entry_Call call
7424 -- Protected_Entry_Call (
7425 -- Object => po._object'Access,
7426 -- E => <entry index>;
7427 -- Uninterpreted_Data => P'Address;
7428 -- Mode => Asynchronous_Call;
7431 -- Skip assignments to temporaries created for in-out parameters
7433 -- This makes unwarranted assumptions about the shape of the expanded
7434 -- tree for the call, and should be cleaned up ???
7436 Stmt
:= First
(Stmts
);
7437 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7443 Param
:= First
(Parameter_Associations
(Call
));
7444 while Present
(Param
)
7445 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
7450 pragma Assert
(Present
(Param
));
7451 Rewrite
(Param
, New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7454 -- Append an if statement to execute the abortable part
7457 -- if Enqueued (Bnn) then
7460 Make_Implicit_If_Statement
(N
,
7462 Make_Function_Call
(Loc
,
7463 Name
=> New_Occurrence_Of
(RTE
(RE_Enqueued
), Loc
),
7464 Parameter_Associations
=> New_List
(
7465 New_Occurrence_Of
(Cancel_Param
, Loc
))),
7466 Then_Statements
=> Astats
));
7469 Make_Block_Statement
(Loc
,
7470 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7471 Handled_Statement_Sequence
=>
7472 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
),
7473 Has_Created_Identifier
=> True,
7474 Is_Asynchronous_Call_Block
=> True);
7477 Make_Block_Statement
(Loc
,
7478 Handled_Statement_Sequence
=>
7479 Make_Handled_Sequence_Of_Statements
(Loc
,
7480 Statements
=> New_List
(
7481 Make_Implicit_Label_Declaration
(Loc
,
7482 Defining_Identifier
=> Blk_Ent
,
7483 Label_Construct
=> Abortable_Block
),
7488 Exception_Handlers
=> New_List
(
7489 Make_Implicit_Exception_Handler
(Loc
,
7491 -- when Abort_Signal =>
7494 Exception_Choices
=>
7495 New_List
(New_Occurrence_Of
(Stand
.Abort_Signal
, Loc
)),
7496 Statements
=> New_List
(Make_Null_Statement
(Loc
)))))),
7498 -- if not Cancelled (Bnn) then
7499 -- triggered statements
7502 Make_Implicit_If_Statement
(N
,
7503 Condition
=> Make_Op_Not
(Loc
,
7505 Make_Function_Call
(Loc
,
7506 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
7507 Parameter_Associations
=> New_List
(
7508 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
7509 Then_Statements
=> Tstats
));
7511 -- Asynchronous task entry call
7518 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7520 -- Insert declaration of B in declarations of existing block
7523 Make_Object_Declaration
(Loc
,
7524 Defining_Identifier
=> B
,
7525 Object_Definition
=>
7526 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
7528 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
7530 -- Insert the declaration of C in the declarations of the existing
7531 -- block. The variable is initialized to something (True or False,
7532 -- does not matter) to prevent CodePeer from complaining about a
7533 -- possible read of an uninitialized variable.
7536 Make_Object_Declaration
(Loc
,
7537 Defining_Identifier
=> Cancel_Param
,
7538 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
7539 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
),
7540 Has_Init_Expression
=> True));
7542 -- Remove and save the call to Call_Simple
7544 Stmt
:= First
(Stmts
);
7546 -- Skip assignments to temporaries created for in-out parameters.
7547 -- This makes unwarranted assumptions about the shape of the expanded
7548 -- tree for the call, and should be cleaned up ???
7550 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7556 -- Create the inner block to protect the abortable part
7558 Hdle
:= New_List
(Build_Abort_Block_Handler
(Loc
));
7560 if Abort_Allowed
then
7561 Prepend_To
(Astats
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
7565 Make_Block_Statement
(Loc
,
7566 Identifier
=> New_Occurrence_Of
(Blk_Ent
, Loc
),
7567 Handled_Statement_Sequence
=>
7568 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Astats
),
7569 Has_Created_Identifier
=> True,
7570 Is_Asynchronous_Call_Block
=> True);
7573 Make_Block_Statement
(Loc
,
7574 Handled_Statement_Sequence
=>
7575 Make_Handled_Sequence_Of_Statements
(Loc
,
7576 Statements
=> New_List
(
7577 Make_Implicit_Label_Declaration
(Loc
,
7578 Defining_Identifier
=> Blk_Ent
,
7579 Label_Construct
=> Abortable_Block
),
7581 Exception_Handlers
=> Hdle
)));
7583 -- Create new call statement
7585 Params
:= Parameter_Associations
(Call
);
7588 New_Occurrence_Of
(RTE
(RE_Asynchronous_Call
), Loc
));
7589 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
7592 Make_Procedure_Call_Statement
(Loc
,
7593 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
7594 Parameter_Associations
=> Params
));
7596 -- Construct statement sequence for new block
7599 Make_Implicit_If_Statement
(N
,
7601 Make_Op_Not
(Loc
, New_Occurrence_Of
(Cancel_Param
, Loc
)),
7602 Then_Statements
=> Tstats
));
7604 -- Protected the call against abort
7606 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
7609 Set_Entry_Cancel_Parameter
(Blk_Ent
, Cancel_Param
);
7611 -- The result is the new block
7614 Make_Block_Statement
(Loc
,
7615 Declarations
=> Decls
,
7616 Handled_Statement_Sequence
=>
7617 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7620 end Expand_N_Asynchronous_Select
;
7622 -------------------------------------
7623 -- Expand_N_Conditional_Entry_Call --
7624 -------------------------------------
7626 -- The conditional task entry call is converted to a call to
7631 -- P : parms := (parm, parm, parm);
7635 -- (<acceptor-task>, -- Acceptor
7636 -- <entry-index>, -- E
7637 -- P'Address, -- Uninterpreted_Data
7638 -- Conditional_Call, -- Mode
7639 -- B); -- Rendezvous_Successful
7644 -- normal-statements
7650 -- For a description of the use of P and the assignments after the call,
7651 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7652 -- conditional entry call has already been expanded (by the Expand_N_Entry
7653 -- _Call_Statement procedure) as follows:
7656 -- P : parms := (parm, parm, parm);
7658 -- ... info for in-out parameters
7659 -- Call_Simple (acceptor-task, entry-index, P'Address);
7665 -- so the task at hand is to convert the latter expansion into the former
7667 -- The conditional protected entry call is converted to a call to
7668 -- Protected_Entry_Call:
7671 -- P : parms := (parm, parm, parm);
7672 -- Bnn : Communications_Block;
7675 -- Protected_Entry_Call
7676 -- (po._object'Access, -- Object
7677 -- <entry index>, -- E
7678 -- P'Address, -- Uninterpreted_Data
7679 -- Conditional_Call, -- Mode
7684 -- if Cancelled (Bnn) then
7687 -- normal-statements
7691 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7695 -- B : Boolean := False;
7696 -- C : Ada.Tags.Prim_Op_Kind;
7697 -- K : Ada.Tags.Tagged_Kind :=
7698 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7699 -- P : Parameters := (Param1 .. ParamN);
7703 -- if K = Ada.Tags.TK_Limited_Tagged
7704 -- or else K = Ada.Tags.TK_Tagged
7706 -- <dispatching-call>;
7707 -- -- <triggering-statements> (code factorized after if-stmt)
7711 -- Ada.Tags.Get_Offset_Index
7712 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7714 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7716 -- if C = POK_Protected_Entry
7717 -- or else C = POK_Task_Entry
7719 -- Param1 := P.Param1;
7721 -- ParamN := P.ParamN;
7725 -- if C = POK_Procedure
7726 -- or else C = POK_Protected_Procedure
7727 -- or else C = POK_Task_Procedure
7729 -- <dispatching-call>;
7732 -- -- <triggering-statements> (code factorized after if-stmt)
7734 -- <else-statements>
7735 -- goto L0; -- skip triggering statements
7738 -- <triggering-statements>
7742 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
7743 Loc
: constant Source_Ptr
:= Sloc
(N
);
7744 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
7745 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
7748 Blk_Typ
: Entity_Id
;
7750 Call_Ent
: Entity_Id
;
7751 Conc_Typ_Stmts
: List_Id
;
7756 Label_Id
: Entity_Id
:= Empty
;
7757 Lim_Typ_Stmts
: List_Id
;
7764 Transient_Blk
: Node_Id
;
7767 B
: Entity_Id
; -- Call status flag
7768 C
: Entity_Id
; -- Call kind
7769 K
: Entity_Id
; -- Tagged kind
7770 P
: Entity_Id
; -- Parameter block
7771 S
: Entity_Id
; -- Primitive operation slot
7774 Process_Statements_For_Controlled_Objects
(N
);
7776 if Ada_Version
>= Ada_2005
7777 and then Nkind
(Blk
) = N_Procedure_Call_Statement
7779 Extract_Dispatching_Call
(Blk
, Call_Ent
, Obj
, Actuals
, Formals
);
7784 -- Call status flag processing, generate:
7785 -- B : Boolean := False;
7787 B
:= Build_B
(Loc
, Decls
);
7789 -- Call kind processing, generate:
7790 -- C : Ada.Tags.Prim_Op_Kind;
7792 C
:= Build_C
(Loc
, Decls
);
7794 -- Tagged kind processing, generate:
7795 -- K : Ada.Tags.Tagged_Kind :=
7796 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7798 K
:= Build_K
(Loc
, Decls
, Obj
);
7800 -- Parameter block processing
7802 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
7803 P
:= Parameter_Block_Pack
7804 (Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
7806 -- Dispatch table slot processing, generate:
7809 S
:= Build_S
(Loc
, Decls
);
7812 -- S := Ada.Tags.Get_Offset_Index
7813 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7816 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
7819 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7821 Append_To
(Conc_Typ_Stmts
,
7822 Make_Procedure_Call_Statement
(Loc
,
7825 Find_Prim_Op
(Etype
(Etype
(Obj
)),
7826 Name_uDisp_Conditional_Select
),
7828 Parameter_Associations
=>
7830 New_Copy_Tree
(Obj
), -- <object>
7831 New_Occurrence_Of
(S
, Loc
), -- S
7832 Make_Attribute_Reference
(Loc
, -- P'Address
7833 Prefix
=> New_Occurrence_Of
(P
, Loc
),
7834 Attribute_Name
=> Name_Address
),
7835 New_Occurrence_Of
(C
, Loc
), -- C
7836 New_Occurrence_Of
(B
, Loc
)))); -- B
7839 -- if C = POK_Protected_Entry
7840 -- or else C = POK_Task_Entry
7842 -- Param1 := P.Param1;
7844 -- ParamN := P.ParamN;
7847 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
7849 -- Generate the if statement only when the packed parameters need
7850 -- explicit assignments to their corresponding actuals.
7852 if Present
(Unpack
) then
7853 Append_To
(Conc_Typ_Stmts
,
7854 Make_Implicit_If_Statement
(N
,
7860 New_Occurrence_Of
(C
, Loc
),
7862 New_Occurrence_Of
(RTE
(
7863 RE_POK_Protected_Entry
), Loc
)),
7868 New_Occurrence_Of
(C
, Loc
),
7870 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
7872 Then_Statements
=> Unpack
));
7877 -- if C = POK_Procedure
7878 -- or else C = POK_Protected_Procedure
7879 -- or else C = POK_Task_Procedure
7881 -- <dispatching-call>
7883 -- -- <triggering-stataments> (code factorized after if-stmt)
7885 -- <else-statements>
7886 -- goto L0; -- skip triggering statements
7889 N_Stats
:= New_List
;
7891 Prepend_To
(N_Stats
,
7892 Make_Implicit_If_Statement
(N
,
7898 New_Occurrence_Of
(C
, Loc
),
7900 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
7907 New_Occurrence_Of
(C
, Loc
),
7909 New_Occurrence_Of
(RTE
(
7910 RE_POK_Protected_Procedure
), Loc
)),
7915 New_Occurrence_Of
(C
, Loc
),
7917 New_Occurrence_Of
(RTE
(
7918 RE_POK_Task_Procedure
), Loc
)))),
7923 Label_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', 0));
7924 Set_Entity
(Label_Id
,
7925 Make_Defining_Identifier
(Loc
, Chars
(Label_Id
)));
7927 Append_To
(Else_Statements
(N
),
7928 Make_Goto_Statement
(Loc
,
7929 Name
=> New_Occurrence_Of
(Entity
(Label_Id
), Loc
)));
7931 Append_To
(Conc_Typ_Stmts
,
7932 Make_Implicit_If_Statement
(N
,
7933 Condition
=> New_Occurrence_Of
(B
, Loc
),
7934 Then_Statements
=> N_Stats
,
7935 Else_Statements
=> Else_Statements
(N
)));
7938 -- <dispatching-call>;
7939 -- -- <triggering-statements> (code factorized after if-stmt)
7941 Lim_Typ_Stmts
:= New_List
(New_Copy_Tree
(Blk
));
7944 -- if K = Ada.Tags.TK_Limited_Tagged
7945 -- or else K = Ada.Tags.TK_Tagged
7953 Make_Implicit_If_Statement
(N
,
7954 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
7955 Then_Statements
=> Lim_Typ_Stmts
,
7956 Else_Statements
=> Conc_Typ_Stmts
));
7958 Label
:= Make_Label
(Loc
, Label_Id
);
7960 Make_Implicit_Label_Declaration
(Loc
,
7961 Defining_Identifier
=> Entity
(Label_Id
),
7962 Label_Construct
=> Label
));
7964 Append_List_To
(Stmts
, Statements
(Alt
)); -- triggering-statements
7965 Append_To
(Stmts
, Label
);
7968 Make_Block_Statement
(Loc
,
7971 Handled_Statement_Sequence
=>
7972 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7974 -- As described above, the entry alternative is transformed into a
7975 -- block that contains the gnulli call, and possibly assignment
7976 -- statements for in-out parameters. The gnulli call may itself be
7977 -- rewritten into a transient block if some unconstrained parameters
7978 -- require it. We need to retrieve the call to complete its parameter
7983 First
(Statements
(Handled_Statement_Sequence
(Blk
)));
7985 if Present
(Transient_Blk
)
7986 and then Nkind
(Transient_Blk
) = N_Block_Statement
7988 Blk
:= Transient_Blk
;
7991 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
7992 Stmt
:= First
(Stmts
);
7993 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7998 Params
:= Parameter_Associations
(Call
);
8000 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
8002 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8004 Param
:= First
(Params
);
8005 while Present
(Param
)
8006 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
8011 pragma Assert
(Present
(Param
));
8013 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8017 -- Find the Communication_Block parameter for the call to the
8018 -- Cancelled function.
8020 Decl
:= First
(Declarations
(Blk
));
8021 while Present
(Decl
)
8022 and then not Is_RTE
(Etype
(Object_Definition
(Decl
)),
8023 RE_Communication_Block
)
8028 -- Add an if statement to execute the else part if the call
8029 -- does not succeed (as indicated by the Cancelled predicate).
8032 Make_Implicit_If_Statement
(N
,
8033 Condition
=> Make_Function_Call
(Loc
,
8034 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
8035 Parameter_Associations
=> New_List
(
8036 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
))),
8037 Then_Statements
=> Else_Statements
(N
),
8038 Else_Statements
=> Statements
(Alt
)));
8041 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
8043 -- Insert declaration of B in declarations of existing block
8045 if No
(Declarations
(Blk
)) then
8046 Set_Declarations
(Blk
, New_List
);
8049 Prepend_To
(Declarations
(Blk
),
8050 Make_Object_Declaration
(Loc
,
8051 Defining_Identifier
=> B
,
8052 Object_Definition
=>
8053 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8055 -- Create new call statement
8058 New_Occurrence_Of
(RTE
(RE_Conditional_Call
), Loc
));
8059 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
8062 Make_Procedure_Call_Statement
(Loc
,
8063 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
8064 Parameter_Associations
=> Params
));
8066 -- Construct statement sequence for new block
8069 Make_Implicit_If_Statement
(N
,
8070 Condition
=> New_Occurrence_Of
(B
, Loc
),
8071 Then_Statements
=> Statements
(Alt
),
8072 Else_Statements
=> Else_Statements
(N
)));
8075 -- The result is the new block
8078 Make_Block_Statement
(Loc
,
8079 Declarations
=> Declarations
(Blk
),
8080 Handled_Statement_Sequence
=>
8081 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
8086 Reset_Scopes_To
(N
, Entity
(Identifier
(N
)));
8087 end Expand_N_Conditional_Entry_Call
;
8089 ---------------------------------------
8090 -- Expand_N_Delay_Relative_Statement --
8091 ---------------------------------------
8093 -- Delay statement is implemented as a procedure call to Delay_For
8094 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8095 -- simple delays imposed by the use of Protected Objects.
8097 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
8098 Loc
: constant Source_Ptr
:= Sloc
(N
);
8102 -- Try to use Ada.Calendar.Delays.Delay_For if available.
8104 if RTE_Available
(RO_CA_Delay_For
) then
8105 Proc
:= RTE
(RO_CA_Delay_For
);
8107 -- Otherwise, use System.Relative_Delays.Delay_For and emit an error
8108 -- message if not available. This is the implementation used on
8109 -- restricted platforms when Ada.Calendar is not available.
8112 Proc
:= RTE
(RO_RD_Delay_For
);
8116 Make_Procedure_Call_Statement
(Loc
,
8117 Name
=> New_Occurrence_Of
(Proc
, Loc
),
8118 Parameter_Associations
=> New_List
(Expression
(N
))));
8120 end Expand_N_Delay_Relative_Statement
;
8122 ------------------------------------
8123 -- Expand_N_Delay_Until_Statement --
8124 ------------------------------------
8126 -- Delay Until statement is implemented as a procedure call to
8127 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8129 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
8130 Loc
: constant Source_Ptr
:= Sloc
(N
);
8134 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
8135 Typ
:= RTE
(RO_CA_Delay_Until
);
8137 Typ
:= RTE
(RO_RT_Delay_Until
);
8141 Make_Procedure_Call_Statement
(Loc
,
8142 Name
=> New_Occurrence_Of
(Typ
, Loc
),
8143 Parameter_Associations
=> New_List
(Expression
(N
))));
8146 end Expand_N_Delay_Until_Statement
;
8148 -------------------------
8149 -- Expand_N_Entry_Body --
8150 -------------------------
8152 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
8154 -- Associate discriminals with the next protected operation body to be
8157 if Present
(Next_Protected_Operation
(N
)) then
8158 Set_Discriminals
(Parent
(Current_Scope
));
8160 end Expand_N_Entry_Body
;
8162 -----------------------------------
8163 -- Expand_N_Entry_Call_Statement --
8164 -----------------------------------
8166 -- An entry call is expanded into GNARLI calls to implement a simple entry
8167 -- call (see Build_Simple_Entry_Call).
8169 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
8175 if No_Run_Time_Mode
then
8176 Error_Msg_CRT
("entry call", N
);
8180 -- If this entry call is part of an asynchronous select, don't expand it
8181 -- here; it will be expanded with the select statement. Don't expand
8182 -- timed entry calls either, as they are translated into asynchronous
8185 -- ??? This whole approach is questionable; it may be better to go back
8186 -- to allowing the expansion to take place and then attempting to fix it
8187 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8188 -- whether the expanded call is on a task or protected entry.
8190 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
8191 or else N
/= Triggering_Statement
(Parent
(N
)))
8192 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
8193 or else N
/= Entry_Call_Statement
(Parent
(N
))
8194 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
8196 Extract_Entry
(N
, Concval
, Ename
, Index
);
8197 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
8199 end Expand_N_Entry_Call_Statement
;
8201 --------------------------------
8202 -- Expand_N_Entry_Declaration --
8203 --------------------------------
8205 -- If there are parameters, then first, each of the formals is marked by
8206 -- setting Is_Entry_Formal. Next a record type is built which is used to
8207 -- hold the parameter values. The name of this record type is entryP where
8208 -- entry is the name of the entry, with an additional corresponding access
8209 -- type called entryPA. The record type has matching components for each
8210 -- formal (the component names are the same as the formal names). For
8211 -- elementary types, the component type matches the formal type. For
8212 -- composite types, an access type is declared (with the name formalA)
8213 -- which designates the formal type, and the type of the component is this
8214 -- access type. Finally the Entry_Component of each formal is set to
8215 -- reference the corresponding record component.
8217 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
8218 Loc
: constant Source_Ptr
:= Sloc
(N
);
8219 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
8220 Components
: List_Id
;
8223 Last_Decl
: Node_Id
;
8224 Component
: Entity_Id
;
8227 Rec_Ent
: Entity_Id
;
8228 Acc_Ent
: Entity_Id
;
8231 Formal
:= First_Formal
(Entry_Ent
);
8234 -- Most processing is done only if parameters are present
8236 if Present
(Formal
) then
8237 Components
:= New_List
;
8239 -- Loop through formals
8241 while Present
(Formal
) loop
8242 Set_Is_Entry_Formal
(Formal
);
8244 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
8245 Set_Entry_Component
(Formal
, Component
);
8246 Set_Entry_Formal
(Component
, Formal
);
8247 Ftype
:= Etype
(Formal
);
8249 -- Declare new access type and then append
8251 Ctype
:= Make_Temporary
(Loc
, 'A');
8252 Set_Is_Param_Block_Component_Type
(Ctype
);
8255 Make_Full_Type_Declaration
(Loc
,
8256 Defining_Identifier
=> Ctype
,
8258 Make_Access_To_Object_Definition
(Loc
,
8259 All_Present
=> True,
8260 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
8261 Subtype_Indication
=> New_Occurrence_Of
(Ftype
, Loc
)));
8263 Insert_After
(Last_Decl
, Decl
);
8266 Append_To
(Components
,
8267 Make_Component_Declaration
(Loc
,
8268 Defining_Identifier
=> Component
,
8269 Component_Definition
=>
8270 Make_Component_Definition
(Loc
,
8271 Aliased_Present
=> False,
8272 Subtype_Indication
=> New_Occurrence_Of
(Ctype
, Loc
))));
8274 Next_Formal_With_Extras
(Formal
);
8277 -- Create the Entry_Parameter_Record declaration
8279 Rec_Ent
:= Make_Temporary
(Loc
, 'P');
8282 Make_Full_Type_Declaration
(Loc
,
8283 Defining_Identifier
=> Rec_Ent
,
8285 Make_Record_Definition
(Loc
,
8287 Make_Component_List
(Loc
,
8288 Component_Items
=> Components
)));
8290 Insert_After
(Last_Decl
, Decl
);
8293 -- Construct and link in the corresponding access type
8295 Acc_Ent
:= Make_Temporary
(Loc
, 'A');
8297 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
8300 Make_Full_Type_Declaration
(Loc
,
8301 Defining_Identifier
=> Acc_Ent
,
8303 Make_Access_To_Object_Definition
(Loc
,
8304 All_Present
=> True,
8305 Subtype_Indication
=> New_Occurrence_Of
(Rec_Ent
, Loc
)));
8307 Insert_After
(Last_Decl
, Decl
);
8309 end Expand_N_Entry_Declaration
;
8311 -----------------------------
8312 -- Expand_N_Protected_Body --
8313 -----------------------------
8315 -- Protected bodies are expanded to the completion of the subprograms
8316 -- created for the corresponding protected type. These are a protected and
8317 -- unprotected version of each protected subprogram in the object, a
8318 -- function to calculate each entry barrier, and a procedure to execute the
8319 -- sequence of statements of each protected entry body. For example, for
8320 -- protected type ptype:
8323 -- (O : System.Address;
8324 -- E : Protected_Entry_Index)
8327 -- <discriminant renamings>
8328 -- <private object renamings>
8330 -- return <barrier expression>;
8333 -- procedure pprocN (_object : in out poV;...) is
8334 -- <discriminant renamings>
8335 -- <private object renamings>
8337 -- <sequence of statements>
8340 -- procedure pprocP (_object : in out poV;...) is
8341 -- procedure _clean is
8344 -- ptypeS (_object, Pn);
8345 -- Unlock (_object._object'Access);
8346 -- Abort_Undefer.all;
8351 -- Lock (_object._object'Access);
8352 -- pprocN (_object;...);
8357 -- function pfuncN (_object : poV;...) return Return_Type is
8358 -- <discriminant renamings>
8359 -- <private object renamings>
8361 -- <sequence of statements>
8364 -- function pfuncP (_object : poV) return Return_Type is
8365 -- procedure _clean is
8367 -- Unlock (_object._object'Access);
8368 -- Abort_Undefer.all;
8373 -- Lock (_object._object'Access);
8374 -- return pfuncN (_object);
8381 -- (O : System.Address;
8382 -- P : System.Address;
8383 -- E : Protected_Entry_Index)
8385 -- <discriminant renamings>
8386 -- <private object renamings>
8387 -- type poVP is access poV;
8388 -- _Object : ptVP := ptVP!(O);
8392 -- <statement sequence>
8393 -- Complete_Entry_Body (_Object._Object);
8395 -- when all others =>
8396 -- Exceptional_Complete_Entry_Body (
8397 -- _Object._Object, Get_GNAT_Exception);
8401 -- The type poV is the record created for the protected type to hold
8402 -- the state of the protected object.
8404 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
8405 Loc
: constant Source_Ptr
:= Sloc
(N
);
8406 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
8408 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Pid
);
8409 -- This flag indicates whether the lock free implementation is active
8411 Current_Node
: Node_Id
;
8412 Disp_Op_Body
: Node_Id
;
8413 New_Op_Body
: Node_Id
;
8414 New_Op_Spec
: Node_Id
;
8418 Op_Spec
: Entity_Id
;
8420 function Build_Dispatching_Subprogram_Body
8423 Prot_Bod
: Node_Id
) return Node_Id
;
8424 -- Build a dispatching version of the protected subprogram body. The
8425 -- newly generated subprogram contains a call to the original protected
8426 -- body. The following code is generated:
8428 -- function <protected-function-name> (Param1 .. ParamN) return
8431 -- return <protected-function-name>P (Param1 .. ParamN);
8432 -- end <protected-function-name>;
8436 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8438 -- <protected-procedure-name>P (Param1 .. ParamN);
8439 -- end <protected-procedure-name>
8441 ---------------------------------------
8442 -- Build_Dispatching_Subprogram_Body --
8443 ---------------------------------------
8445 function Build_Dispatching_Subprogram_Body
8448 Prot_Bod
: Node_Id
) return Node_Id
8450 Loc
: constant Source_Ptr
:= Sloc
(N
);
8457 -- Generate a specification without a letter suffix in order to
8458 -- override an interface function or procedure.
8460 Spec
:= Build_Protected_Sub_Specification
(N
, Pid
, Dispatching_Mode
);
8462 -- The formal parameters become the actuals of the protected function
8463 -- or procedure call.
8465 Actuals
:= New_List
;
8466 Formal
:= First
(Parameter_Specifications
(Spec
));
8467 while Present
(Formal
) loop
8469 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
8473 if Nkind
(Spec
) = N_Procedure_Specification
then
8476 Make_Procedure_Call_Statement
(Loc
,
8478 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8479 Parameter_Associations
=> Actuals
));
8482 pragma Assert
(Nkind
(Spec
) = N_Function_Specification
);
8486 Make_Simple_Return_Statement
(Loc
,
8488 Make_Function_Call
(Loc
,
8490 New_Occurrence_Of
(Corresponding_Spec
(Prot_Bod
), Loc
),
8491 Parameter_Associations
=> Actuals
)));
8495 Make_Subprogram_Body
(Loc
,
8496 Declarations
=> Empty_List
,
8497 Specification
=> Spec
,
8498 Handled_Statement_Sequence
=>
8499 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
8500 end Build_Dispatching_Subprogram_Body
;
8502 -- Start of processing for Expand_N_Protected_Body
8505 if No_Run_Time_Mode
then
8506 Error_Msg_CRT
("protected body", N
);
8510 -- This is the proper body corresponding to a stub. The declarations
8511 -- must be inserted at the point of the stub, which in turn is in the
8512 -- declarative part of the parent unit.
8514 if Nkind
(Parent
(N
)) = N_Subunit
then
8515 Current_Node
:= Corresponding_Stub
(Parent
(N
));
8520 Op_Body
:= First
(Declarations
(N
));
8522 -- The protected body is replaced with the bodies of its protected
8523 -- operations, and the declarations for internal objects that may
8524 -- have been created for entry family bounds.
8526 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
8529 while Present
(Op_Body
) loop
8530 case Nkind
(Op_Body
) is
8531 when N_Subprogram_Declaration
=>
8534 when N_Subprogram_Body
=>
8535 Op_Spec
:= Corresponding_Spec
(Op_Body
);
8537 -- Do not create bodies for eliminated operations
8539 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
8540 and then not Is_Eliminated
(Op_Spec
)
8542 if Lock_Free_Active
then
8544 Build_Lock_Free_Unprotected_Subprogram_Body
8548 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
8551 Insert_After
(Current_Node
, New_Op_Body
);
8552 Current_Node
:= New_Op_Body
;
8553 Analyze
(New_Op_Body
);
8555 New_Op_Spec
:= Corresponding_Spec
(New_Op_Body
);
8557 -- When the original subprogram body has nested subprograms,
8558 -- the new body also has them, so set the flag accordingly.
8560 Set_Has_Nested_Subprogram
8561 (New_Op_Spec
, Has_Nested_Subprogram
(New_Op_Spec
));
8563 -- Similarly, when the original subprogram body uses the
8564 -- secondary stack, the new body also does. This is needed
8565 -- when the cleanup actions of the subprogram are delayed
8566 -- because it contains a package instance with a body.
8568 Set_Uses_Sec_Stack
(New_Op_Spec
, Uses_Sec_Stack
(Op_Spec
));
8570 -- Now reset the scopes of the top-level nested subprograms
8571 -- and other declaration entities so that they now refer to
8572 -- the new body's entity (it would preferable to do this
8573 -- within Build_Protected_Sub_Specification, which is called
8574 -- from Build_Unprotected_Subprogram_Body, but the needed
8575 -- subprogram entity isn't available via Corresponding_Spec
8576 -- until after the above Analyze call).
8578 Reset_Scopes_To
(New_Op_Body
, New_Op_Spec
);
8580 -- Build the corresponding protected operation. This is
8581 -- needed only if this is a public or private operation of
8584 Op_Decl
:= Unit_Declaration_Node
(Op_Spec
);
8586 if Nkind
(Parent
(Op_Decl
)) = N_Protected_Definition
then
8587 if Lock_Free_Active
then
8589 Build_Lock_Free_Protected_Subprogram_Body
8590 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8593 Build_Protected_Subprogram_Body
8594 (Op_Body
, Pid
, Specification
(New_Op_Body
));
8597 Insert_After
(Current_Node
, New_Op_Body
);
8598 Current_Node
:= New_Op_Body
;
8599 Analyze
(New_Op_Body
);
8601 -- Generate an overriding primitive operation body for
8602 -- this subprogram if the protected type implements
8605 if Ada_Version
>= Ada_2005
8607 Present
(Interfaces
(Corresponding_Record_Type
(Pid
)))
8610 Build_Dispatching_Subprogram_Body
(
8611 Op_Body
, Pid
, New_Op_Body
);
8613 Insert_After
(Current_Node
, Disp_Op_Body
);
8614 Current_Node
:= Disp_Op_Body
;
8615 Analyze
(Disp_Op_Body
);
8620 when N_Entry_Body
=>
8621 Op_Id
:= Defining_Identifier
(Op_Body
);
8622 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
8624 Insert_After
(Current_Node
, New_Op_Body
);
8625 Current_Node
:= New_Op_Body
;
8626 Analyze
(New_Op_Body
);
8628 when N_Implicit_Label_Declaration
=>
8634 New_Op_Body
:= New_Copy
(Op_Body
);
8635 Insert_After
(Current_Node
, New_Op_Body
);
8636 Current_Node
:= New_Op_Body
;
8638 when N_Freeze_Entity
=>
8639 New_Op_Body
:= New_Copy
(Op_Body
);
8641 if Present
(Entity
(Op_Body
))
8642 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
8644 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
8647 Insert_After
(Current_Node
, New_Op_Body
);
8648 Current_Node
:= New_Op_Body
;
8649 Analyze
(New_Op_Body
);
8652 New_Op_Body
:= New_Copy
(Op_Body
);
8653 Insert_After
(Current_Node
, New_Op_Body
);
8654 Current_Node
:= New_Op_Body
;
8655 Analyze
(New_Op_Body
);
8657 when N_Object_Declaration
=>
8658 pragma Assert
(not Comes_From_Source
(Op_Body
));
8659 New_Op_Body
:= New_Copy
(Op_Body
);
8660 Insert_After
(Current_Node
, New_Op_Body
);
8661 Current_Node
:= New_Op_Body
;
8662 Analyze
(New_Op_Body
);
8665 raise Program_Error
;
8671 -- Finally, create the body of the function that maps an entry index
8672 -- into the corresponding body index, except when there is no entry, or
8673 -- in a Ravenscar-like profile.
8675 if Corresponding_Runtime_Package
(Pid
) =
8676 System_Tasking_Protected_Objects_Entries
8678 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
8679 Insert_After
(Current_Node
, New_Op_Body
);
8680 Current_Node
:= New_Op_Body
;
8681 Analyze
(New_Op_Body
);
8684 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8685 -- protected body. At this point all wrapper specs have been created,
8686 -- frozen and included in the dispatch table for the protected type.
8688 if Ada_Version
>= Ada_2005
then
8689 Build_Wrapper_Bodies
(Loc
, Pid
, Current_Node
);
8691 end Expand_N_Protected_Body
;
8693 -----------------------------------------
8694 -- Expand_N_Protected_Type_Declaration --
8695 -----------------------------------------
8697 -- First we create a corresponding record type declaration used to
8698 -- represent values of this protected type.
8699 -- The general form of this type declaration is
8701 -- type poV (discriminants) is record
8702 -- _Object : aliased <kind>Protection
8703 -- [(<entry count> [, <handler count>])];
8704 -- [entry_family : array (bounds) of Void;]
8705 -- <private data fields>
8708 -- The discriminants are present only if the corresponding protected type
8709 -- has discriminants, and they exactly mirror the protected type
8710 -- discriminants. The private data fields similarly mirror the private
8711 -- declarations of the protected type.
8713 -- The Object field is always present. It contains RTS specific data used
8714 -- to control the protected object. It is declared as Aliased so that it
8715 -- can be passed as a pointer to the RTS. This allows the protected record
8716 -- to be referenced within RTS data structures. An appropriate Protection
8717 -- type and discriminant are generated.
8719 -- The Service field is present for protected objects with entries. It
8720 -- contains sufficient information to allow the entry service procedure for
8721 -- this object to be called when the object is not known till runtime.
8723 -- One entry_family component is present for each entry family in the
8724 -- task definition (see Expand_N_Task_Type_Declaration).
8726 -- When a protected object is declared, an instance of the protected type
8727 -- value record is created. The elaboration of this declaration creates the
8728 -- correct bounds for the entry families, and also evaluates the priority
8729 -- expression if needed. The initialization routine for the protected type
8730 -- itself then calls Initialize_Protection with appropriate parameters to
8731 -- initialize the value of the Task_Id field. Install_Handlers may be also
8732 -- called if a pragma Attach_Handler applies.
8734 -- Note: this record is passed to the subprograms created by the expansion
8735 -- of protected subprograms and entries. It is an in parameter to protected
8736 -- functions and an in out parameter to procedures and entry bodies. The
8737 -- Entity_Id for this created record type is placed in the
8738 -- Corresponding_Record_Type field of the associated protected type entity.
8740 -- Next we create a procedure specifications for protected subprograms and
8741 -- entry bodies. For each protected subprograms two subprograms are
8742 -- created, an unprotected and a protected version. The unprotected version
8743 -- is called from within other operations of the same protected object.
8745 -- We also build the call to register the procedure if a pragma
8746 -- Interrupt_Handler applies.
8748 -- A single subprogram is created to service all entry bodies; it has an
8749 -- additional boolean out parameter indicating that the previous entry call
8750 -- made by the current task was serviced immediately, i.e. not by proxy.
8751 -- The O parameter contains a pointer to a record object of the type
8752 -- described above. An untyped interface is used here to allow this
8753 -- procedure to be called in places where the type of the object to be
8754 -- serviced is not known. This must be done, for example, when a call that
8755 -- may have been requeued is cancelled; the corresponding object must be
8756 -- serviced, but which object that is not known till runtime.
8759 -- (O : System.Address; P : out Boolean);
8760 -- procedure pprocN (_object : in out poV);
8761 -- procedure pproc (_object : in out poV);
8762 -- function pfuncN (_object : poV);
8763 -- function pfunc (_object : poV);
8766 -- Note that this must come after the record type declaration, since
8767 -- the specs refer to this type.
8769 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
8770 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
8771 Loc
: constant Source_Ptr
:= Sloc
(N
);
8772 Prot_Typ
: constant Entity_Id
:= Defining_Identifier
(N
);
8774 Lock_Free_Active
: constant Boolean := Uses_Lock_Free
(Prot_Typ
);
8775 -- This flag indicates whether the lock free implementation is active
8777 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
8778 -- This contains two lists; one for visible and one for private decls
8780 Current_Node
: Node_Id
:= N
;
8782 Entries_Aggr
: Node_Id
;
8786 procedure Check_Inlining
(Subp
: Entity_Id
);
8787 -- If the original operation has a pragma Inline, propagate the flag
8788 -- to the internal body, for possible inlining later on. The source
8789 -- operation is invisible to the back-end and is never actually called.
8791 procedure Expand_Entry_Declaration
(Decl
: Node_Id
);
8792 -- Create the entry barrier and the procedure body for entry declaration
8793 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8795 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean;
8796 -- When compiling under the Ravenscar profile, private components must
8797 -- have a static size, or else a protected object will require heap
8798 -- allocation, violating the corresponding restriction. It is preferable
8799 -- to make this check here, because it provides a better error message
8800 -- than the back-end, which refers to the object as a whole.
8802 procedure Register_Handler
;
8803 -- For a protected operation that is an interrupt handler, add the
8804 -- freeze action that will register it as such.
8806 procedure Replace_Access_Definition
(Comp
: Node_Id
);
8807 -- If a private component of the type is an access to itself, this
8808 -- is not a reference to the current instance, but an access type out
8809 -- of which one might construct a list. If such a component exists, we
8810 -- create an incomplete type for the equivalent record type, and
8811 -- a named access type for it, that replaces the access definition
8812 -- of the original component. This is similar to what is done for
8813 -- records in Check_Anonymous_Access_Components, but simpler, because
8814 -- the corresponding record type has no previous declaration.
8815 -- This needs to be done only once, even if there are several such
8816 -- access components. The following entity stores the constructed
8819 Acc_T
: Entity_Id
:= Empty
;
8821 --------------------
8822 -- Check_Inlining --
8823 --------------------
8825 procedure Check_Inlining
(Subp
: Entity_Id
) is
8827 if Is_Inlined
(Subp
) then
8828 Set_Is_Inlined
(Protected_Body_Subprogram
(Subp
));
8829 Set_Is_Inlined
(Subp
, False);
8832 if Has_Pragma_No_Inline
(Subp
) then
8833 Set_Has_Pragma_No_Inline
(Protected_Body_Subprogram
(Subp
));
8837 ---------------------------
8838 -- Static_Component_Size --
8839 ---------------------------
8841 function Static_Component_Size
(Comp
: Entity_Id
) return Boolean is
8842 Typ
: constant Entity_Id
:= Etype
(Comp
);
8846 if Is_Scalar_Type
(Typ
) then
8849 elsif Is_Array_Type
(Typ
) then
8850 return Compile_Time_Known_Bounds
(Typ
);
8852 elsif Is_Record_Type
(Typ
) then
8853 C
:= First_Component
(Typ
);
8854 while Present
(C
) loop
8855 if not Static_Component_Size
(C
) then
8864 -- Any other type will be checked by the back-end
8869 end Static_Component_Size
;
8871 ------------------------------
8872 -- Expand_Entry_Declaration --
8873 ------------------------------
8875 procedure Expand_Entry_Declaration
(Decl
: Node_Id
) is
8876 Ent_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
8882 E_Count
:= E_Count
+ 1;
8884 -- Create the protected body subprogram
8887 Make_Defining_Identifier
(Loc
,
8888 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'E'));
8889 Set_Protected_Body_Subprogram
(Ent_Id
, Bod_Id
);
8892 Make_Subprogram_Declaration
(Loc
,
8894 Build_Protected_Entry_Specification
(Loc
, Bod_Id
, Ent_Id
));
8896 Insert_After
(Current_Node
, Subp
);
8897 Current_Node
:= Subp
;
8901 -- Build a wrapper procedure to handle contract cases, preconditions,
8902 -- and postconditions.
8904 Build_Entry_Contract_Wrapper
(Ent_Id
, N
);
8906 -- Create the barrier function
8909 Make_Defining_Identifier
(Loc
,
8910 Chars
=> Build_Selected_Name
(Prot_Typ
, Ent_Id
, 'B'));
8911 Set_Barrier_Function
(Ent_Id
, Bar_Id
);
8914 Make_Subprogram_Declaration
(Loc
,
8916 Build_Barrier_Function_Specification
(Loc
, Bar_Id
));
8917 Set_Is_Entry_Barrier_Function
(Subp
);
8919 Insert_After
(Current_Node
, Subp
);
8920 Current_Node
:= Subp
;
8924 Set_Protected_Body_Subprogram
(Bar_Id
, Bar_Id
);
8925 Set_Scope
(Bar_Id
, Scope
(Ent_Id
));
8927 -- Collect pointers to the protected subprogram and the barrier
8928 -- of the current entry, for insertion into Entry_Bodies_Array.
8930 Append_To
(Expressions
(Entries_Aggr
),
8931 Make_Aggregate
(Loc
,
8932 Expressions
=> New_List
(
8933 Make_Attribute_Reference
(Loc
,
8934 Prefix
=> New_Occurrence_Of
(Bar_Id
, Loc
),
8935 Attribute_Name
=> Name_Unrestricted_Access
),
8936 Make_Attribute_Reference
(Loc
,
8937 Prefix
=> New_Occurrence_Of
(Bod_Id
, Loc
),
8938 Attribute_Name
=> Name_Unrestricted_Access
))));
8939 end Expand_Entry_Declaration
;
8941 ----------------------
8942 -- Register_Handler --
8943 ----------------------
8945 procedure Register_Handler
is
8947 -- All semantic checks already done in Sem_Prag
8949 Prot_Proc
: constant Entity_Id
:=
8950 Defining_Unit_Name
(Specification
(Current_Node
));
8952 Proc_Address
: constant Node_Id
:=
8953 Make_Attribute_Reference
(Loc
,
8955 New_Occurrence_Of
(Prot_Proc
, Loc
),
8956 Attribute_Name
=> Name_Address
);
8958 RTS_Call
: constant Entity_Id
:=
8959 Make_Procedure_Call_Statement
(Loc
,
8962 (RTE
(RE_Register_Interrupt_Handler
), Loc
),
8963 Parameter_Associations
=> New_List
(Proc_Address
));
8965 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
8966 end Register_Handler
;
8968 -------------------------------
8969 -- Replace_Access_Definition --
8970 -------------------------------
8972 procedure Replace_Access_Definition
(Comp
: Node_Id
) is
8973 Loc
: constant Source_Ptr
:= Sloc
(Comp
);
8981 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Rec_Id
));
8982 Inc_D
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
8983 Acc_T
:= Make_Temporary
(Loc
, 'S');
8985 Make_Access_To_Object_Definition
(Loc
,
8986 Subtype_Indication
=> New_Occurrence_Of
(Inc_T
, Loc
));
8988 Make_Full_Type_Declaration
(Loc
,
8989 Defining_Identifier
=> Acc_T
,
8990 Type_Definition
=> Acc_Def
);
8992 Insert_Before
(Rec_Decl
, Inc_D
);
8995 Insert_Before
(Rec_Decl
, Acc_D
);
8999 Set_Access_Definition
(Comp
, Empty
);
9000 Set_Subtype_Indication
(Comp
, New_Occurrence_Of
(Acc_T
, Loc
));
9001 end Replace_Access_Definition
;
9006 Body_Id
: Entity_Id
;
9012 Object_Comp
: Node_Id
;
9016 -- Start of processing for Expand_N_Protected_Type_Declaration
9019 if Present
(Corresponding_Record_Type
(Prot_Typ
)) then
9022 Rec_Decl
:= Build_Corresponding_Record
(N
, Prot_Typ
, Loc
);
9023 Rec_Id
:= Defining_Identifier
(Rec_Decl
);
9026 Cdecls
:= Component_Items
(Component_List
(Type_Definition
(Rec_Decl
)));
9028 Qualify_Entity_Names
(N
);
9030 -- If the type has discriminants, their occurrences in the declaration
9031 -- have been replaced by the corresponding discriminals. For components
9032 -- that are constrained by discriminants, their homologues in the
9033 -- corresponding record type must refer to the discriminants of that
9034 -- record, so we must apply a new renaming to subtypes_indications:
9036 -- protected discriminant => discriminal => record discriminant
9038 -- This replacement is not applied to default expressions, for which
9039 -- the discriminal is correct.
9041 if Has_Discriminants
(Prot_Typ
) then
9047 Disc
:= First_Discriminant
(Prot_Typ
);
9048 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
9049 while Present
(Disc
) loop
9050 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
9051 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
9052 Next_Discriminant
(Disc
);
9058 -- Fill in the component declarations
9060 -- Add components for entry families. For each entry family, create an
9061 -- anonymous type declaration with the same size, and analyze the type.
9063 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prot_Typ
);
9065 pragma Assert
(Present
(Pdef
));
9067 Insert_After
(Current_Node
, Rec_Decl
);
9068 Current_Node
:= Rec_Decl
;
9070 -- Add private field components
9072 Priv
:= First
(Private_Declarations
(Pdef
));
9073 while Present
(Priv
) loop
9074 if Nkind
(Priv
) = N_Component_Declaration
then
9075 if not Static_Component_Size
(Defining_Identifier
(Priv
)) then
9077 -- When compiling for a restricted profile, the private
9078 -- components must have a static size. If not, this is an error
9079 -- for a single protected declaration, and rates a warning on a
9080 -- protected type declaration.
9082 if not Comes_From_Source
(Prot_Typ
) then
9084 -- It's ok to be checking this restriction at expansion
9085 -- time, because this is only for the restricted profile,
9086 -- which is not subject to strict RM conformance, so it
9087 -- is OK to miss this check in -gnatc mode.
9089 Check_Restriction
(No_Implicit_Heap_Allocations
, Priv
);
9091 (No_Implicit_Protected_Object_Allocations
, Priv
);
9093 elsif Restriction_Active
(No_Implicit_Heap_Allocations
) then
9094 if not Discriminated_Size
(Defining_Identifier
(Priv
))
9096 -- Any object of the type will be non-static
9098 Error_Msg_N
("component has non-static size??", Priv
);
9100 ("\creation of protected object of type& will "
9101 & "violate restriction "
9102 & "No_Implicit_Heap_Allocations??", Priv
, Prot_Typ
);
9104 -- Object will be non-static if discriminants are
9107 ("creation of protected object of type& with "
9108 & "non-static discriminants will violate "
9109 & "restriction No_Implicit_Heap_Allocations??",
9113 -- Likewise for No_Implicit_Protected_Object_Allocations
9115 elsif Restriction_Active
9116 (No_Implicit_Protected_Object_Allocations
)
9118 if not Discriminated_Size
(Defining_Identifier
(Priv
)) then
9119 -- Any object of the type will be non-static
9121 Error_Msg_N
("component has non-static size??", Priv
);
9123 ("\creation of protected object of type& will violate "
9125 & "No_Implicit_Protected_Object_Allocations??",
9128 -- Object will be non-static if discriminants are
9131 ("creation of protected object of type& with "
9132 & "non-static discriminants will violate restriction "
9133 & "No_Implicit_Protected_Object_Allocations??",
9139 -- The component definition consists of a subtype indication, or
9140 -- (in Ada 2005) an access definition. Make a copy of the proper
9144 Old_Comp
: constant Node_Id
:= Component_Definition
(Priv
);
9145 Oent
: constant Entity_Id
:= Defining_Identifier
(Priv
);
9146 Nent
: constant Entity_Id
:=
9147 Make_Defining_Identifier
(Sloc
(Oent
),
9148 Chars
=> Chars
(Oent
));
9152 if Present
(Subtype_Indication
(Old_Comp
)) then
9154 Make_Component_Definition
(Sloc
(Oent
),
9155 Aliased_Present
=> False,
9156 Subtype_Indication
=>
9158 (Subtype_Indication
(Old_Comp
), Discr_Map
));
9161 Make_Component_Definition
(Sloc
(Oent
),
9162 Aliased_Present
=> False,
9163 Access_Definition
=>
9165 (Access_Definition
(Old_Comp
), Discr_Map
));
9167 -- A self-reference in the private part becomes a
9168 -- self-reference to the corresponding record.
9170 if Entity
(Subtype_Mark
(Access_Definition
(New_Comp
)))
9173 Replace_Access_Definition
(New_Comp
);
9178 Make_Component_Declaration
(Loc
,
9179 Defining_Identifier
=> Nent
,
9180 Component_Definition
=> New_Comp
,
9181 Expression
=> Expression
(Priv
));
9183 Set_Has_Per_Object_Constraint
(Nent
,
9184 Has_Per_Object_Constraint
(Oent
));
9186 Append_To
(Cdecls
, New_Priv
);
9189 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
9191 -- Make the unprotected version of the subprogram available for
9192 -- expansion of intra object calls. There is need for a protected
9193 -- version only if the subprogram is an interrupt handler,
9194 -- otherwise this operation can only be called from within the
9198 Make_Subprogram_Declaration
(Loc
,
9200 Build_Protected_Sub_Specification
9201 (Priv
, Prot_Typ
, Unprotected_Mode
));
9203 Insert_After
(Current_Node
, Sub
);
9206 Set_Protected_Body_Subprogram
9207 (Defining_Unit_Name
(Specification
(Priv
)),
9208 Defining_Unit_Name
(Specification
(Sub
)));
9209 Check_Inlining
(Defining_Unit_Name
(Specification
(Priv
)));
9210 Current_Node
:= Sub
;
9213 Make_Subprogram_Declaration
(Loc
,
9215 Build_Protected_Sub_Specification
9216 (Priv
, Prot_Typ
, Protected_Mode
));
9218 Insert_After
(Current_Node
, Sub
);
9220 Current_Node
:= Sub
;
9222 if Is_Interrupt_Handler
9223 (Defining_Unit_Name
(Specification
(Priv
)))
9225 if not Restricted_Profile
then
9234 -- Except for the lock-free implementation, append the _Object field
9235 -- with the right type to the component list. We need to compute the
9236 -- number of entries, and in some cases the number of Attach_Handler
9239 if not Lock_Free_Active
then
9241 Entry_Count_Expr
: constant Node_Id
:=
9242 Build_Entry_Count_Expression
9244 Num_Attach_Handler
: Nat
:= 0;
9245 Protection_Subtype
: Node_Id
;
9249 if Has_Attach_Handler
(Prot_Typ
) then
9250 Ritem
:= First_Rep_Item
(Prot_Typ
);
9251 while Present
(Ritem
) loop
9252 if Nkind
(Ritem
) = N_Pragma
9253 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
9255 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
9258 Next_Rep_Item
(Ritem
);
9262 -- Determine the proper protection type. There are two special
9263 -- cases: 1) when the protected type has dynamic interrupt
9264 -- handlers, and 2) when it has static handlers and we use a
9265 -- restricted profile.
9267 if Has_Attach_Handler
(Prot_Typ
)
9268 and then not Restricted_Profile
9270 Protection_Subtype
:=
9271 Make_Subtype_Indication
(Loc
,
9274 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
9276 Make_Index_Or_Discriminant_Constraint
(Loc
,
9277 Constraints
=> New_List
(
9279 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
9281 elsif Has_Interrupt_Handler
(Prot_Typ
)
9282 and then not Restriction_Active
(No_Dynamic_Attachment
)
9284 Protection_Subtype
:=
9285 Make_Subtype_Indication
(Loc
,
9288 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
9290 Make_Index_Or_Discriminant_Constraint
(Loc
,
9291 Constraints
=> New_List
(Entry_Count_Expr
)));
9294 case Corresponding_Runtime_Package
(Prot_Typ
) is
9295 when System_Tasking_Protected_Objects_Entries
=>
9296 Protection_Subtype
:=
9297 Make_Subtype_Indication
(Loc
,
9300 (RTE
(RE_Protection_Entries
), Loc
),
9302 Make_Index_Or_Discriminant_Constraint
(Loc
,
9303 Constraints
=> New_List
(Entry_Count_Expr
)));
9305 when System_Tasking_Protected_Objects_Single_Entry
=>
9306 Protection_Subtype
:=
9307 New_Occurrence_Of
(RTE
(RE_Protection_Entry
), Loc
);
9309 when System_Tasking_Protected_Objects
=>
9310 Protection_Subtype
:=
9311 New_Occurrence_Of
(RTE
(RE_Protection
), Loc
);
9314 raise Program_Error
;
9319 Make_Component_Declaration
(Loc
,
9320 Defining_Identifier
=>
9321 Make_Defining_Identifier
(Loc
, Name_uObject
),
9322 Component_Definition
=>
9323 Make_Component_Definition
(Loc
,
9324 Aliased_Present
=> True,
9325 Subtype_Indication
=> Protection_Subtype
));
9328 -- Put the _Object component after the private component so that it
9329 -- be finalized early as required by 9.4 (20)
9331 Append_To
(Cdecls
, Object_Comp
);
9334 -- Analyze the record declaration immediately after construction,
9335 -- because the initialization procedure is needed for single object
9336 -- declarations before the next entity is analyzed (the freeze call
9337 -- that generates this initialization procedure is found below).
9339 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
9341 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9342 -- the corresponding record is frozen. If any wrappers are generated,
9343 -- Current_Node is updated accordingly.
9345 if Ada_Version
>= Ada_2005
then
9346 Build_Wrapper_Specs
(Loc
, Prot_Typ
, Current_Node
);
9349 -- Collect pointers to entry bodies and their barriers, to be placed
9350 -- in the Entry_Bodies_Array for the type. For each entry/family we
9351 -- add an expression to the aggregate which is the initial value of
9352 -- this array. The array is declared after all protected subprograms.
9354 if Has_Entries
(Prot_Typ
) then
9355 Entries_Aggr
:= Make_Aggregate
(Loc
, Expressions
=> New_List
);
9357 Entries_Aggr
:= Empty
;
9360 -- Build two new procedure specifications for each protected subprogram;
9361 -- one to call from outside the object and one to call from inside.
9362 -- Build a barrier function and an entry body action procedure
9363 -- specification for each protected entry. Initialize the entry body
9364 -- array. If subprogram is flagged as eliminated, do not generate any
9365 -- internal operations.
9368 Comp
:= First
(Visible_Declarations
(Pdef
));
9369 while Present
(Comp
) loop
9370 if Nkind
(Comp
) = N_Subprogram_Declaration
then
9372 Make_Subprogram_Declaration
(Loc
,
9374 Build_Protected_Sub_Specification
9375 (Comp
, Prot_Typ
, Unprotected_Mode
));
9377 Insert_After
(Current_Node
, Sub
);
9380 Set_Protected_Body_Subprogram
9381 (Defining_Unit_Name
(Specification
(Comp
)),
9382 Defining_Unit_Name
(Specification
(Sub
)));
9383 Check_Inlining
(Defining_Unit_Name
(Specification
(Comp
)));
9385 -- Make the protected version of the subprogram available for
9386 -- expansion of external calls.
9388 Current_Node
:= Sub
;
9391 Make_Subprogram_Declaration
(Loc
,
9393 Build_Protected_Sub_Specification
9394 (Comp
, Prot_Typ
, Protected_Mode
));
9396 Insert_After
(Current_Node
, Sub
);
9399 Current_Node
:= Sub
;
9401 -- Generate an overriding primitive operation specification for
9402 -- this subprogram if the protected type implements an interface
9403 -- and Build_Wrapper_Spec did not generate its wrapper.
9405 if Ada_Version
>= Ada_2005
9407 Present
(Interfaces
(Corresponding_Record_Type
(Prot_Typ
)))
9410 Found
: Boolean := False;
9411 Prim_Elmt
: Elmt_Id
;
9417 (Primitive_Operations
9418 (Corresponding_Record_Type
(Prot_Typ
)));
9420 while Present
(Prim_Elmt
) loop
9421 Prim_Op
:= Node
(Prim_Elmt
);
9423 if Is_Primitive_Wrapper
(Prim_Op
)
9424 and then Wrapped_Entity
(Prim_Op
) =
9425 Defining_Entity
(Specification
(Comp
))
9431 Next_Elmt
(Prim_Elmt
);
9436 Make_Subprogram_Declaration
(Loc
,
9438 Build_Protected_Sub_Specification
9439 (Comp
, Prot_Typ
, Dispatching_Mode
));
9441 Insert_After
(Current_Node
, Sub
);
9444 Current_Node
:= Sub
;
9449 -- If a pragma Interrupt_Handler applies, build and add a call to
9450 -- Register_Interrupt_Handler to the freezing actions of the
9451 -- protected version (Current_Node) of the subprogram:
9453 -- system.interrupts.register_interrupt_handler
9454 -- (prot_procP'address);
9456 if not Restricted_Profile
9457 and then Is_Interrupt_Handler
9458 (Defining_Unit_Name
(Specification
(Comp
)))
9463 elsif Nkind
(Comp
) = N_Entry_Declaration
then
9464 Expand_Entry_Declaration
(Comp
);
9470 -- If there are some private entry declarations, expand it as if they
9471 -- were visible entries.
9473 Comp
:= First
(Private_Declarations
(Pdef
));
9474 while Present
(Comp
) loop
9475 if Nkind
(Comp
) = N_Entry_Declaration
then
9476 Expand_Entry_Declaration
(Comp
);
9482 -- Create the declaration of an array object which contains the values
9483 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9484 -- type. This object is later passed to the appropriate protected object
9485 -- initialization routine.
9487 if Has_Entries
(Prot_Typ
)
9488 and then Corresponding_Runtime_Package
(Prot_Typ
) =
9489 System_Tasking_Protected_Objects_Entries
9496 Maxes_Id
: Entity_Id
;
9497 Need_Array
: Boolean := False;
9500 -- First check if there is any Max_Queue_Length pragma
9502 Item
:= First_Entity
(Prot_Typ
);
9503 while Present
(Item
) loop
9504 if Is_Entry
(Item
) and then Has_Max_Queue_Length
(Item
) then
9512 -- Gather the Max_Queue_Length values of all entries in a list. A
9513 -- value of zero indicates that the entry has no limitation on its
9518 Item
:= First_Entity
(Prot_Typ
);
9520 while Present
(Item
) loop
9521 if Is_Entry
(Item
) then
9524 Make_Integer_Literal
9525 (Loc
, Get_Max_Queue_Length
(Item
)));
9531 -- Create the declaration of the array object. Generate:
9533 -- Maxes_Id : aliased constant
9534 -- Protected_Entry_Queue_Max_Array
9535 -- (1 .. Count) := (..., ...);
9538 Make_Defining_Identifier
(Loc
,
9539 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'B'));
9542 Make_Object_Declaration
(Loc
,
9543 Defining_Identifier
=> Maxes_Id
,
9544 Aliased_Present
=> True,
9545 Constant_Present
=> True,
9546 Object_Definition
=>
9547 Make_Subtype_Indication
(Loc
,
9550 (RTE
(RE_Protected_Entry_Queue_Max_Array
), Loc
),
9552 Make_Index_Or_Discriminant_Constraint
(Loc
,
9553 Constraints
=> New_List
(
9555 Make_Integer_Literal
(Loc
, 1),
9556 Make_Integer_Literal
(Loc
, Count
))))),
9557 Expression
=> Make_Aggregate
(Loc
, Maxes
));
9559 -- A pointer to this array will be placed in the corresponding
9560 -- record by its initialization procedure so this needs to be
9563 Insert_After
(Current_Node
, Max_Vals
);
9564 Current_Node
:= Max_Vals
;
9567 Set_Entry_Max_Queue_Lengths_Array
(Prot_Typ
, Maxes_Id
);
9572 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9573 -- all protected subprograms have been collected.
9575 if Has_Entries
(Prot_Typ
) then
9577 Make_Defining_Identifier
(Sloc
(Prot_Typ
),
9578 Chars
=> New_External_Name
(Chars
(Prot_Typ
), 'A'));
9580 case Corresponding_Runtime_Package
(Prot_Typ
) is
9581 when System_Tasking_Protected_Objects_Entries
=>
9582 Expr
:= Entries_Aggr
;
9584 Make_Subtype_Indication
(Loc
,
9587 (RTE
(RE_Protected_Entry_Body_Array
), Loc
),
9589 Make_Index_Or_Discriminant_Constraint
(Loc
,
9590 Constraints
=> New_List
(
9592 Make_Integer_Literal
(Loc
, 1),
9593 Make_Integer_Literal
(Loc
, E_Count
)))));
9595 when System_Tasking_Protected_Objects_Single_Entry
=>
9596 Expr
:= Remove_Head
(Expressions
(Entries_Aggr
));
9597 Obj_Def
:= New_Occurrence_Of
(RTE
(RE_Entry_Body
), Loc
);
9600 raise Program_Error
;
9604 Make_Object_Declaration
(Loc
,
9605 Defining_Identifier
=> Body_Id
,
9606 Aliased_Present
=> True,
9607 Constant_Present
=> True,
9608 Object_Definition
=> Obj_Def
,
9609 Expression
=> Expr
);
9611 -- A pointer to this array will be placed in the corresponding record
9612 -- by its initialization procedure so this needs to be analyzed here.
9614 Insert_After
(Current_Node
, Body_Arr
);
9615 Current_Node
:= Body_Arr
;
9618 Set_Entry_Bodies_Array
(Prot_Typ
, Body_Id
);
9620 -- Finally, build the function that maps an entry index into the
9621 -- corresponding body. A pointer to this function is placed in each
9622 -- object of the type. Except for a ravenscar-like profile (no abort,
9623 -- no entry queue, 1 entry)
9625 if Corresponding_Runtime_Package
(Prot_Typ
) =
9626 System_Tasking_Protected_Objects_Entries
9629 Make_Subprogram_Declaration
(Loc
,
9630 Specification
=> Build_Find_Body_Index_Spec
(Prot_Typ
));
9632 Insert_After
(Current_Node
, Sub
);
9636 end Expand_N_Protected_Type_Declaration
;
9638 --------------------------------
9639 -- Expand_N_Requeue_Statement --
9640 --------------------------------
9642 -- A nondispatching requeue statement is expanded into one of four GNARLI
9643 -- operations, depending on the source and destination (task or protected
9644 -- object). A dispatching requeue statement is expanded into a call to the
9645 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9646 -- jump around the remainder of processing for the original entry and, if
9647 -- the destination is (different) protected object, to attempt to service
9648 -- it. The following illustrates the various cases:
9651 -- (O : System.Address;
9652 -- P : System.Address;
9653 -- E : Protected_Entry_Index)
9655 -- <discriminant renamings>
9656 -- <private object renamings>
9657 -- type poVP is access poV;
9658 -- _object : ptVP := ptVP!(O);
9662 -- <start of statement sequence for entry>
9664 -- -- Requeue from one protected entry body to another protected
9667 -- Requeue_Protected_Entry (
9668 -- _object._object'Access,
9669 -- new._object'Access,
9674 -- <some more of the statement sequence for entry>
9676 -- -- Requeue from an entry body to a task entry
9678 -- Requeue_Protected_To_Task_Entry (
9684 -- <rest of statement sequence for entry>
9685 -- Complete_Entry_Body (_object._object);
9688 -- when all others =>
9689 -- Exceptional_Complete_Entry_Body (
9690 -- _object._object, Get_GNAT_Exception);
9694 -- Requeue of a task entry call to a task entry
9696 -- Accept_Call (E, Ann);
9697 -- <start of statement sequence for accept statement>
9698 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9700 -- <rest of statement sequence for accept statement>
9702 -- Complete_Rendezvous;
9705 -- when all others =>
9706 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9708 -- Requeue of a task entry call to a protected entry
9710 -- Accept_Call (E, Ann);
9711 -- <start of statement sequence for accept statement>
9712 -- Requeue_Task_To_Protected_Entry (
9713 -- new._object'Access,
9718 -- <rest of statement sequence for accept statement>
9720 -- Complete_Rendezvous;
9723 -- when all others =>
9724 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9726 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9727 -- marked by pragma Implemented (XXX, By_Entry).
9729 -- The requeue is inside a protected entry:
9732 -- (O : System.Address;
9733 -- P : System.Address;
9734 -- E : Protected_Entry_Index)
9736 -- <discriminant renamings>
9737 -- <private object renamings>
9738 -- type poVP is access poV;
9739 -- _object : ptVP := ptVP!(O);
9743 -- <start of statement sequence for entry>
9746 -- (<interface class-wide object>,
9749 -- Ada.Tags.Get_Offset_Index
9751 -- <interface dispatch table index of target entry>),
9755 -- <rest of statement sequence for entry>
9756 -- Complete_Entry_Body (_object._object);
9759 -- when all others =>
9760 -- Exceptional_Complete_Entry_Body (
9761 -- _object._object, Get_GNAT_Exception);
9765 -- The requeue is inside a task entry:
9767 -- Accept_Call (E, Ann);
9768 -- <start of statement sequence for accept statement>
9770 -- (<interface class-wide object>,
9773 -- Ada.Tags.Get_Offset_Index
9775 -- <interface dispatch table index of target entrt>),
9779 -- <rest of statement sequence for accept statement>
9781 -- Complete_Rendezvous;
9784 -- when all others =>
9785 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9787 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9788 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9789 -- statement is replaced by a dispatching call with actual parameters taken
9790 -- from the inner-most accept statement or entry body.
9792 -- Target.Primitive (Param1, ..., ParamN);
9794 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9795 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9799 -- S : constant Offset_Index :=
9800 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9801 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9804 -- if C = POK_Protected_Entry
9805 -- or else C = POK_Task_Entry
9807 -- <statements for dispatching requeue>
9809 -- elsif C = POK_Protected_Procedure then
9810 -- <dispatching call equivalent>
9813 -- raise Program_Error;
9817 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
9818 Loc
: constant Source_Ptr
:= Sloc
(N
);
9819 Conc_Typ
: Entity_Id
;
9822 Enc_Subp
: Entity_Id
;
9824 Old_Typ
: Entity_Id
;
9826 function Build_Dispatching_Call_Equivalent
return Node_Id
;
9827 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9828 -- the form Concval.Ename. It is statically known that Ename is allowed
9829 -- to be implemented by a protected procedure. Create a dispatching call
9830 -- equivalent of Concval.Ename taking the actual parameters from the
9831 -- inner-most accept statement or entry body.
9833 function Build_Dispatching_Requeue
return Node_Id
;
9834 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9835 -- the form Concval.Ename. It is statically known that Ename is allowed
9836 -- to be implemented by a protected or a task entry. Create a call to
9837 -- primitive _Disp_Requeue which handles the low-level actions.
9839 function Build_Dispatching_Requeue_To_Any
return Node_Id
;
9840 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9841 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9842 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9843 -- determines at runtime whether Ename denotes an entry or a procedure
9844 -- and perform the appropriate kind of dispatching select.
9846 function Build_Normal_Requeue
return Node_Id
;
9847 -- N denotes a nondispatching requeue statement to either a task or a
9848 -- protected entry. Build the appropriate runtime call to perform the
9851 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
;
9852 -- For a protected entry, create a return statement to skip the rest of
9853 -- the entry body. Otherwise, create a goto statement to skip the rest
9854 -- of a task accept statement. The lookup for the enclosing entry body
9855 -- or accept statement starts from Search.
9857 ---------------------------------------
9858 -- Build_Dispatching_Call_Equivalent --
9859 ---------------------------------------
9861 function Build_Dispatching_Call_Equivalent
return Node_Id
is
9862 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
9863 Obj
: constant Node_Id
:= Original_Node
(Concval
);
9870 -- Climb the parent chain looking for the inner-most entry body or
9871 -- accept statement.
9874 while Present
(Acc_Ent
)
9875 and then Nkind
(Acc_Ent
) not in N_Accept_Statement | N_Entry_Body
9877 Acc_Ent
:= Parent
(Acc_Ent
);
9880 -- A requeue statement should be housed inside an entry body or an
9881 -- accept statement at some level. If this is not the case, then the
9882 -- tree is malformed.
9884 pragma Assert
(Present
(Acc_Ent
));
9886 -- Recover the list of formal parameters
9888 if Nkind
(Acc_Ent
) = N_Entry_Body
then
9889 Acc_Ent
:= Entry_Body_Formal_Part
(Acc_Ent
);
9892 Formals
:= Parameter_Specifications
(Acc_Ent
);
9894 -- Create the actual parameters for the dispatching call. These are
9895 -- simply copies of the entry body or accept statement formals in the
9896 -- same order as they appear.
9900 if Present
(Formals
) then
9901 Actuals
:= New_List
;
9902 Formal
:= First
(Formals
);
9903 while Present
(Formal
) loop
9905 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Formal
))));
9911 -- Obj.Call_Ent (Actuals);
9914 Make_Procedure_Call_Statement
(Loc
,
9916 Make_Selected_Component
(Loc
,
9917 Prefix
=> Make_Identifier
(Loc
, Chars
(Obj
)),
9918 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Call_Ent
))),
9920 Parameter_Associations
=> Actuals
);
9921 end Build_Dispatching_Call_Equivalent
;
9923 -------------------------------
9924 -- Build_Dispatching_Requeue --
9925 -------------------------------
9927 function Build_Dispatching_Requeue
return Node_Id
is
9928 Params
: constant List_Id
:= New_List
;
9931 -- Process the "with abort" parameter
9934 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
9936 -- Process the entry wrapper's position in the primary dispatch
9937 -- table parameter. Generate:
9939 -- Ada.Tags.Get_Entry_Index
9940 -- (T => To_Tag_Ptr (Obj'Address).all,
9942 -- Ada.Tags.Get_Offset_Index
9943 -- (Ada.Tags.Tag (Concval),
9944 -- <interface dispatch table position of Ename>));
9946 -- Note that Obj'Address is recursively expanded into a call to
9947 -- Base_Address (Obj).
9949 if Tagged_Type_Expansion
then
9951 Make_Function_Call
(Loc
,
9952 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9953 Parameter_Associations
=> New_List
(
9955 Make_Explicit_Dereference
(Loc
,
9956 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
9957 Make_Attribute_Reference
(Loc
,
9958 Prefix
=> New_Copy_Tree
(Concval
),
9959 Attribute_Name
=> Name_Address
))),
9961 Make_Function_Call
(Loc
,
9962 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9963 Parameter_Associations
=> New_List
(
9964 Unchecked_Convert_To
(RTE
(RE_Tag
), Concval
),
9965 Make_Integer_Literal
(Loc
,
9966 DT_Position
(Entity
(Ename
))))))));
9972 Make_Function_Call
(Loc
,
9973 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
9974 Parameter_Associations
=> New_List
(
9976 Make_Attribute_Reference
(Loc
,
9978 Attribute_Name
=> Name_Tag
),
9980 Make_Function_Call
(Loc
,
9981 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Offset_Index
), Loc
),
9983 Parameter_Associations
=> New_List
(
9987 Make_Attribute_Reference
(Loc
,
9989 Attribute_Name
=> Name_Tag
),
9993 Make_Attribute_Reference
(Loc
,
9994 Prefix
=> New_Occurrence_Of
(Etype
(Concval
), Loc
),
9995 Attribute_Name
=> Name_Tag
),
9999 Make_Integer_Literal
(Loc
,
10000 DT_Position
(Entity
(Ename
))))))));
10003 -- Specific actuals for protected to XXX requeue
10005 if Is_Protected_Type
(Old_Typ
) then
10006 Prepend_To
(Params
,
10007 Make_Attribute_Reference
(Loc
, -- _object'Address
10009 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10010 Attribute_Name
=> Name_Address
));
10012 Prepend_To
(Params
, -- True
10013 New_Occurrence_Of
(Standard_True
, Loc
));
10015 -- Specific actuals for task to XXX requeue
10018 pragma Assert
(Is_Task_Type
(Old_Typ
));
10020 Prepend_To
(Params
, -- null
10021 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
10023 Prepend_To
(Params
, -- False
10024 New_Occurrence_Of
(Standard_False
, Loc
));
10027 -- Add the object parameter
10029 Prepend_To
(Params
, New_Copy_Tree
(Concval
));
10032 -- _Disp_Requeue (<Params>);
10034 -- Find entity for Disp_Requeue operation, which belongs to
10035 -- the type and may not be directly visible.
10039 Op
: Entity_Id
:= Empty
;
10042 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Conc_Typ
)));
10043 while Present
(Elmt
) loop
10045 exit when Chars
(Op
) = Name_uDisp_Requeue
;
10049 pragma Assert
(Present
(Op
));
10052 Make_Procedure_Call_Statement
(Loc
,
10053 Name
=> New_Occurrence_Of
(Op
, Loc
),
10054 Parameter_Associations
=> Params
);
10056 end Build_Dispatching_Requeue
;
10058 --------------------------------------
10059 -- Build_Dispatching_Requeue_To_Any --
10060 --------------------------------------
10062 function Build_Dispatching_Requeue_To_Any
return Node_Id
is
10063 Call_Ent
: constant Entity_Id
:= Entity
(Ename
);
10064 Obj
: constant Node_Id
:= Original_Node
(Concval
);
10065 Skip
: constant Node_Id
:= Build_Skip_Statement
(N
);
10075 -- Dispatch table slot processing, generate:
10078 S
:= Build_S
(Loc
, Decls
);
10080 -- Call kind processing, generate:
10081 -- C : Ada.Tags.Prim_Op_Kind;
10083 C
:= Build_C
(Loc
, Decls
);
10086 -- S := Ada.Tags.Get_Offset_Index
10087 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10089 Append_To
(Stmts
, Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
10092 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10095 Make_Procedure_Call_Statement
(Loc
,
10097 New_Occurrence_Of
(
10098 Find_Prim_Op
(Etype
(Etype
(Obj
)),
10099 Name_uDisp_Get_Prim_Op_Kind
),
10101 Parameter_Associations
=> New_List
(
10102 New_Copy_Tree
(Obj
),
10103 New_Occurrence_Of
(S
, Loc
),
10104 New_Occurrence_Of
(C
, Loc
))));
10108 -- if C = POK_Protected_Entry
10109 -- or else C = POK_Task_Entry
10112 Make_Implicit_If_Statement
(N
,
10118 New_Occurrence_Of
(C
, Loc
),
10120 New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
)),
10125 New_Occurrence_Of
(C
, Loc
),
10127 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
10129 -- Dispatching requeue equivalent
10131 Then_Statements
=> New_List
(
10132 Build_Dispatching_Requeue
,
10135 -- elsif C = POK_Protected_Procedure then
10137 Elsif_Parts
=> New_List
(
10138 Make_Elsif_Part
(Loc
,
10142 New_Occurrence_Of
(C
, Loc
),
10144 New_Occurrence_Of
(
10145 RTE
(RE_POK_Protected_Procedure
), Loc
)),
10147 -- Dispatching call equivalent
10149 Then_Statements
=> New_List
(
10150 Build_Dispatching_Call_Equivalent
))),
10153 -- raise Program_Error;
10156 Else_Statements
=> New_List
(
10157 Make_Raise_Program_Error
(Loc
,
10158 Reason
=> PE_Explicit_Raise
))));
10160 -- Wrap everything into a block
10163 Make_Block_Statement
(Loc
,
10164 Declarations
=> Decls
,
10165 Handled_Statement_Sequence
=>
10166 Make_Handled_Sequence_Of_Statements
(Loc
,
10167 Statements
=> Stmts
));
10168 end Build_Dispatching_Requeue_To_Any
;
10170 --------------------------
10171 -- Build_Normal_Requeue --
10172 --------------------------
10174 function Build_Normal_Requeue
return Node_Id
is
10175 Params
: constant List_Id
:= New_List
;
10180 -- Process the "with abort" parameter
10182 Prepend_To
(Params
,
10183 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
));
10185 -- Add the index expression to the parameters. It is common among all
10188 Prepend_To
(Params
,
10189 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conc_Typ
));
10191 if Is_Protected_Type
(Old_Typ
) then
10193 Self_Param
: Node_Id
;
10197 Make_Attribute_Reference
(Loc
,
10199 Concurrent_Ref
(New_Occurrence_Of
(Old_Typ
, Loc
)),
10201 Name_Unchecked_Access
);
10203 -- Protected to protected requeue
10205 if Is_Protected_Type
(Conc_Typ
) then
10207 New_Occurrence_Of
(
10208 RTE
(RE_Requeue_Protected_Entry
), Loc
);
10211 Make_Attribute_Reference
(Loc
,
10213 Concurrent_Ref
(Concval
),
10215 Name_Unchecked_Access
);
10217 -- Protected to task requeue
10219 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10221 New_Occurrence_Of
(
10222 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
);
10224 Param
:= Concurrent_Ref
(Concval
);
10227 Prepend_To
(Params
, Param
);
10228 Prepend_To
(Params
, Self_Param
);
10231 else pragma Assert
(Is_Task_Type
(Old_Typ
));
10233 -- Task to protected requeue
10235 if Is_Protected_Type
(Conc_Typ
) then
10237 New_Occurrence_Of
(
10238 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
);
10241 Make_Attribute_Reference
(Loc
,
10243 Concurrent_Ref
(Concval
),
10245 Name_Unchecked_Access
);
10247 -- Task to task requeue
10249 else pragma Assert
(Is_Task_Type
(Conc_Typ
));
10251 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
);
10253 Param
:= Concurrent_Ref
(Concval
);
10256 Prepend_To
(Params
, Param
);
10260 Make_Procedure_Call_Statement
(Loc
,
10262 Parameter_Associations
=> Params
);
10263 end Build_Normal_Requeue
;
10265 --------------------------
10266 -- Build_Skip_Statement --
10267 --------------------------
10269 function Build_Skip_Statement
(Search
: Node_Id
) return Node_Id
is
10270 Skip_Stmt
: Node_Id
;
10273 -- Build a return statement to skip the rest of the entire body
10275 if Is_Protected_Type
(Old_Typ
) then
10276 Skip_Stmt
:= Make_Simple_Return_Statement
(Loc
);
10278 -- If the requeue is within a task, find the end label of the
10279 -- enclosing accept statement and create a goto statement to it.
10287 -- Climb the parent chain looking for the enclosing accept
10290 Acc
:= Parent
(Search
);
10291 while Present
(Acc
)
10292 and then Nkind
(Acc
) /= N_Accept_Statement
10294 Acc
:= Parent
(Acc
);
10297 -- The last statement is the second label used for completing
10298 -- the rendezvous the usual way. The label we are looking for
10299 -- is right before it.
10302 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc
))));
10304 pragma Assert
(Nkind
(Label
) = N_Label
);
10306 -- Generate a goto statement to skip the rest of the accept
10309 Make_Goto_Statement
(Loc
,
10311 New_Occurrence_Of
(Entity
(Identifier
(Label
)), Loc
));
10315 Set_Analyzed
(Skip_Stmt
);
10318 end Build_Skip_Statement
;
10320 -- Start of processing for Expand_N_Requeue_Statement
10323 -- Extract the components of the entry call
10325 Extract_Entry
(N
, Concval
, Ename
, Index
);
10326 Conc_Typ
:= Etype
(Concval
);
10328 -- Examine the scope stack in order to find nearest enclosing concurrent
10329 -- type. This will constitute our invocation source.
10331 Old_Typ
:= Current_Scope
;
10332 while Present
(Old_Typ
)
10333 and then not Is_Concurrent_Type
(Old_Typ
)
10335 Old_Typ
:= Scope
(Old_Typ
);
10338 -- Obtain the innermost enclosing callable construct for use in
10339 -- generating a dynamic accessibility check.
10341 Enc_Subp
:= Current_Scope
;
10343 if Ekind
(Enc_Subp
) not in Entry_Kind | Subprogram_Kind
then
10344 Enc_Subp
:= Enclosing_Subprogram
(Enc_Subp
);
10347 -- Generate a dynamic accessibility check on the target object
10349 Insert_Before_And_Analyze
(N
,
10350 Make_Raise_Program_Error
(Loc
,
10353 Left_Opnd
=> Accessibility_Level
(Name
(N
), Dynamic_Level
),
10354 Right_Opnd
=> Make_Integer_Literal
(Loc
,
10355 Scope_Depth
(Enc_Subp
))),
10356 Reason
=> PE_Accessibility_Check_Failed
));
10358 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10359 -- Concval.Ename where the type of Concval is class-wide concurrent
10362 if Ada_Version
>= Ada_2012
10363 and then Present
(Concval
)
10364 and then Is_Class_Wide_Type
(Conc_Typ
)
10365 and then Is_Concurrent_Interface
(Conc_Typ
)
10368 Has_Impl
: Boolean := False;
10369 Impl_Kind
: Name_Id
:= No_Name
;
10372 -- Check whether the Ename is flagged by pragma Implemented
10374 if Has_Rep_Pragma
(Entity
(Ename
), Name_Implemented
) then
10376 Impl_Kind
:= Implementation_Kind
(Entity
(Ename
));
10379 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10380 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10382 if Has_Impl
and then Impl_Kind
= Name_By_Entry
then
10383 Rewrite
(N
, Build_Dispatching_Requeue
);
10385 Insert_After
(N
, Build_Skip_Statement
(N
));
10387 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10388 -- a protected procedure. In this case the requeue is transformed
10389 -- into a dispatching call.
10392 and then Impl_Kind
= Name_By_Protected_Procedure
10394 Rewrite
(N
, Build_Dispatching_Call_Equivalent
);
10397 -- The procedure_or_entry_NAME's implementation kind is either
10398 -- By_Any, Optional, or pragma Implemented was not applied at all.
10399 -- In this case a runtime test determines whether Ename denotes an
10400 -- entry or a protected procedure and performs the appropriate
10404 Rewrite
(N
, Build_Dispatching_Requeue_To_Any
);
10409 -- Processing for regular (nondispatching) requeues
10412 Rewrite
(N
, Build_Normal_Requeue
);
10414 Insert_After
(N
, Build_Skip_Statement
(N
));
10416 end Expand_N_Requeue_Statement
;
10418 -------------------------------
10419 -- Expand_N_Selective_Accept --
10420 -------------------------------
10422 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
10423 Loc
: constant Source_Ptr
:= Sloc
(N
);
10424 Alts
: constant List_Id
:= Select_Alternatives
(N
);
10426 -- Note: in the below declarations a lot of new lists are allocated
10427 -- unconditionally which may well not end up being used. That's not
10428 -- a good idea since it wastes space gratuitously ???
10430 Accept_Case
: List_Id
;
10431 Accept_List
: constant List_Id
:= New_List
;
10434 Alt_List
: constant List_Id
:= New_List
;
10435 Alt_Stats
: List_Id
;
10436 Ann
: Entity_Id
:= Empty
;
10438 Check_Guard
: Boolean := True;
10440 Decls
: constant List_Id
:= New_List
;
10441 Stats
: constant List_Id
:= New_List
;
10442 Body_List
: constant List_Id
:= New_List
;
10443 Trailing_List
: constant List_Id
:= New_List
;
10446 Else_Present
: Boolean := False;
10447 Terminate_Alt
: Node_Id
:= Empty
;
10448 Select_Mode
: Node_Id
;
10450 Delay_Case
: List_Id
;
10451 Delay_Count
: Integer := 0;
10452 Delay_Val
: Entity_Id
;
10453 Delay_Index
: Entity_Id
;
10454 Delay_Min
: Entity_Id
;
10455 Delay_Num
: Pos
:= 1;
10456 Delay_Alt_List
: List_Id
:= New_List
;
10457 Delay_List
: constant List_Id
:= New_List
;
10461 First_Delay
: Boolean := True;
10462 Guard_Open
: Entity_Id
;
10468 Num_Accept
: Nat
:= 0;
10470 Time_Type
: Entity_Id
:= Empty
;
10471 Select_Call
: Node_Id
;
10473 Qnam
: constant Entity_Id
:=
10474 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
10476 Xnam
: constant Entity_Id
:=
10477 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
10479 -----------------------
10480 -- Local subprograms --
10481 -----------------------
10483 function Accept_Or_Raise
return List_Id
;
10484 -- For the rare case where delay alternatives all have guards, and
10485 -- all of them are closed, it is still possible that there were open
10486 -- accept alternatives with no callers. We must reexamine the
10487 -- Accept_List, and execute a selective wait with no else if some
10488 -- accept is open. If none, we raise program_error.
10490 procedure Add_Accept
(Alt
: Node_Id
);
10491 -- Process a single accept statement in a select alternative. Build
10492 -- procedure for body of accept, and add entry to dispatch table with
10493 -- expression for guard, in preparation for call to run time select.
10495 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
10496 -- Manufacture a label using Num as a serial number and declare it.
10497 -- The declaration is appended to Decls. The label marks the trailing
10498 -- statements of an accept or delay alternative.
10500 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
10501 -- Build call to Selective_Wait runtime routine
10503 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
10504 -- Add code to compare value of delay with previous values, and
10505 -- generate case entry for trailing statements.
10507 procedure Process_Accept_Alternative
10511 -- Add code to call corresponding procedure, and branch to
10512 -- trailing statements, if any.
10514 ---------------------
10515 -- Accept_Or_Raise --
10516 ---------------------
10518 function Accept_Or_Raise
return List_Id
is
10521 J
: constant Entity_Id
:= Make_Temporary
(Loc
, 'J');
10524 -- We generate the following:
10526 -- for J in q'range loop
10527 -- if q(J).S /=null_task_entry then
10528 -- selective_wait (simple_mode,...);
10534 -- if no rendez_vous then
10535 -- raise program_error;
10538 -- Note that the code needs to know that the selector name
10539 -- in an Accept_Alternative is named S.
10541 Cond
:= Make_Op_Ne
(Loc
,
10543 Make_Selected_Component
(Loc
,
10545 Make_Indexed_Component
(Loc
,
10546 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10547 Expressions
=> New_List
(New_Occurrence_Of
(J
, Loc
))),
10548 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
10550 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Loc
));
10552 Stats
:= New_List
(
10553 Make_Implicit_Loop_Statement
(N
,
10554 Iteration_Scheme
=>
10555 Make_Iteration_Scheme
(Loc
,
10556 Loop_Parameter_Specification
=>
10557 Make_Loop_Parameter_Specification
(Loc
,
10558 Defining_Identifier
=> J
,
10559 Discrete_Subtype_Definition
=>
10560 Make_Attribute_Reference
(Loc
,
10561 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10562 Attribute_Name
=> Name_Range
,
10563 Expressions
=> New_List
(
10564 Make_Integer_Literal
(Loc
, 1))))),
10566 Statements
=> New_List
(
10567 Make_Implicit_If_Statement
(N
,
10569 Then_Statements
=> New_List
(
10571 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)),
10572 Make_Exit_Statement
(Loc
))))));
10575 Make_Raise_Program_Error
(Loc
,
10576 Condition
=> Make_Op_Eq
(Loc
,
10577 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
10579 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
10580 Reason
=> PE_All_Guards_Closed
));
10583 end Accept_Or_Raise
;
10589 procedure Add_Accept
(Alt
: Node_Id
) is
10590 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
10591 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
10592 Eloc
: constant Source_Ptr
:= Sloc
(Ename
);
10593 Eent
: constant Entity_Id
:= Entity
(Ename
);
10594 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
10598 Null_Body
: Node_Id
;
10599 PB_Ent
: Entity_Id
;
10600 Proc_Body
: Node_Id
;
10602 -- Start of processing for Add_Accept
10606 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
10609 if Present
(Condition
(Alt
)) then
10611 Make_If_Expression
(Eloc
, New_List
(
10613 Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
)),
10614 New_Occurrence_Of
(RTE
(RE_Null_Task_Entry
), Eloc
)));
10616 Expr
:= Entry_Index_Expression
(Eloc
, Eent
, Index
, Scope
(Eent
));
10619 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
10620 Null_Body
:= New_Occurrence_Of
(Standard_False
, Eloc
);
10622 -- Always add call to Abort_Undefer when generating code, since
10623 -- this is what the runtime expects (abort deferred in
10624 -- Selective_Wait). In CodePeer mode this only confuses the
10625 -- analysis with unknown calls, so don't do it.
10627 if not CodePeer_Mode
then
10628 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
10630 (First
(Statements
(Handled_Statement_Sequence
10631 (Accept_Statement
(Alt
)))),
10637 Make_Defining_Identifier
(Eloc
,
10638 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
10640 -- Link the acceptor to the original receiving entry
10642 Mutate_Ekind
(PB_Ent
, E_Procedure
);
10643 Set_Receiving_Entry
(PB_Ent
, Eent
);
10645 if Comes_From_Source
(Alt
) then
10646 Set_Debug_Info_Needed
(PB_Ent
);
10650 Make_Subprogram_Body
(Eloc
,
10652 Make_Procedure_Specification
(Eloc
,
10653 Defining_Unit_Name
=> PB_Ent
),
10654 Declarations
=> Declarations
(Acc_Stm
),
10655 Handled_Statement_Sequence
=>
10656 Build_Accept_Body
(Accept_Statement
(Alt
)));
10658 Reset_Scopes_To
(Proc_Body
, PB_Ent
);
10660 -- During the analysis of the body of the accept statement, any
10661 -- zero cost exception handler records were collected in the
10662 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10663 -- This is where we move them to where they belong, namely the
10664 -- newly created procedure.
10666 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
10667 Append
(Proc_Body
, Body_List
);
10670 Null_Body
:= New_Occurrence_Of
(Standard_True
, Eloc
);
10672 -- if accept statement has declarations, insert above, given that
10673 -- we are not creating a body for the accept.
10675 if Present
(Declarations
(Acc_Stm
)) then
10676 Insert_Actions
(N
, Declarations
(Acc_Stm
));
10680 Append_To
(Accept_List
,
10681 Make_Aggregate
(Eloc
, Expressions
=> New_List
(Null_Body
, Expr
)));
10683 Num_Accept
:= Num_Accept
+ 1;
10686 ----------------------------
10687 -- Make_And_Declare_Label --
10688 ----------------------------
10690 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
10694 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
10696 Make_Label
(Loc
, Lab_Id
);
10699 Make_Implicit_Label_Declaration
(Loc
,
10700 Defining_Identifier
=>
10701 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
10702 Label_Construct
=> Lab
));
10705 end Make_And_Declare_Label
;
10707 ----------------------
10708 -- Make_Select_Call --
10709 ----------------------
10711 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
10712 Params
: constant List_Id
:= New_List
;
10716 Make_Attribute_Reference
(Loc
,
10717 Prefix
=> New_Occurrence_Of
(Qnam
, Loc
),
10718 Attribute_Name
=> Name_Unchecked_Access
));
10719 Append_To
(Params
, Select_Mode
);
10720 Append_To
(Params
, New_Occurrence_Of
(Ann
, Loc
));
10721 Append_To
(Params
, New_Occurrence_Of
(Xnam
, Loc
));
10724 Make_Procedure_Call_Statement
(Loc
,
10725 Name
=> New_Occurrence_Of
(RTE
(RE_Selective_Wait
), Loc
),
10726 Parameter_Associations
=> Params
);
10727 end Make_Select_Call
;
10729 --------------------------------
10730 -- Process_Accept_Alternative --
10731 --------------------------------
10733 procedure Process_Accept_Alternative
10738 Astmt
: constant Node_Id
:= Accept_Statement
(Alt
);
10739 Alt_Stats
: List_Id
;
10742 Adjust_Condition
(Condition
(Alt
));
10744 -- Accept with body
10746 if Present
(Handled_Statement_Sequence
(Astmt
)) then
10749 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10752 (Defining_Unit_Name
(Specification
(Proc
)),
10755 -- Accept with no body (followed by trailing statements)
10759 Entry_Id
: constant Entity_Id
:=
10760 Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)));
10762 -- Ada 2022 (AI12-0279)
10764 if Has_Yield_Aspect
(Entry_Id
)
10765 and then RTE_Available
(RE_Yield
)
10769 Make_Procedure_Call_Statement
(Sloc
(Proc
),
10770 New_Occurrence_Of
(RTE
(RE_Yield
), Sloc
(Proc
))));
10772 Alt_Stats
:= Empty_List
;
10777 Ensure_Statement_Present
(Sloc
(Astmt
), Alt
);
10779 -- After the call, if any, branch to trailing statements, if any.
10780 -- We create a label for each, as well as the corresponding label
10783 if not Is_Empty_List
(Statements
(Alt
)) then
10784 Lab
:= Make_And_Declare_Label
(Index
);
10785 Append
(Lab
, Trailing_List
);
10786 Append_List
(Statements
(Alt
), Trailing_List
);
10787 Append_To
(Trailing_List
,
10788 Make_Goto_Statement
(Loc
,
10789 Name
=> New_Copy
(Identifier
(End_Lab
))));
10795 Append_To
(Alt_Stats
,
10796 Make_Goto_Statement
(Loc
, Name
=> New_Copy
(Identifier
(Lab
))));
10798 Append_To
(Alt_List
,
10799 Make_Case_Statement_Alternative
(Loc
,
10800 Discrete_Choices
=> New_List
(Make_Integer_Literal
(Loc
, Index
)),
10801 Statements
=> Alt_Stats
));
10802 end Process_Accept_Alternative
;
10804 -------------------------------
10805 -- Process_Delay_Alternative --
10806 -------------------------------
10808 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
10809 Dloc
: constant Source_Ptr
:= Sloc
(Delay_Statement
(Alt
));
10811 Delay_Alt
: List_Id
;
10814 -- Deal with C/Fortran boolean as delay condition
10816 Adjust_Condition
(Condition
(Alt
));
10818 -- Determine the smallest specified delay
10820 -- for each delay alternative generate:
10822 -- if guard-expression then
10823 -- Delay_Val := delay-expression;
10824 -- Guard_Open := True;
10825 -- if Delay_Val < Delay_Min then
10826 -- Delay_Min := Delay_Val;
10827 -- Delay_Index := Index;
10831 -- The enclosing if-statement is omitted if there is no guard
10833 if Delay_Count
= 1 or else First_Delay
then
10834 First_Delay
:= False;
10836 Delay_Alt
:= New_List
(
10837 Make_Assignment_Statement
(Loc
,
10838 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10839 Expression
=> Expression
(Delay_Statement
(Alt
))));
10841 if Delay_Count
> 1 then
10842 Append_To
(Delay_Alt
,
10843 Make_Assignment_Statement
(Loc
,
10844 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10845 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
10849 Delay_Alt
:= New_List
(
10850 Make_Assignment_Statement
(Loc
,
10851 Name
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10852 Expression
=> Expression
(Delay_Statement
(Alt
))));
10854 if Time_Type
= Standard_Duration
then
10857 Left_Opnd
=> New_Occurrence_Of
(Delay_Val
, Loc
),
10858 Right_Opnd
=> New_Occurrence_Of
(Delay_Min
, Loc
));
10861 -- The scope of the time type must define a comparison
10862 -- operator. The scope itself may not be visible, so we
10863 -- construct a node with entity information to insure that
10864 -- semantic analysis can find the proper operator.
10867 Make_Function_Call
(Loc
,
10868 Name
=> Make_Selected_Component
(Loc
,
10870 New_Occurrence_Of
(Scope
(Time_Type
), Loc
),
10872 Make_Operator_Symbol
(Loc
,
10873 Chars
=> Name_Op_Lt
,
10874 Strval
=> No_String
)),
10875 Parameter_Associations
=>
10877 New_Occurrence_Of
(Delay_Val
, Loc
),
10878 New_Occurrence_Of
(Delay_Min
, Loc
)));
10880 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
10883 Append_To
(Delay_Alt
,
10884 Make_Implicit_If_Statement
(N
,
10886 Then_Statements
=> New_List
(
10887 Make_Assignment_Statement
(Loc
,
10888 Name
=> New_Occurrence_Of
(Delay_Min
, Loc
),
10889 Expression
=> New_Occurrence_Of
(Delay_Val
, Loc
)),
10891 Make_Assignment_Statement
(Loc
,
10892 Name
=> New_Occurrence_Of
(Delay_Index
, Loc
),
10893 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
10896 if Check_Guard
then
10897 Append_To
(Delay_Alt
,
10898 Make_Assignment_Statement
(Loc
,
10899 Name
=> New_Occurrence_Of
(Guard_Open
, Loc
),
10900 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
10903 if Present
(Condition
(Alt
)) then
10904 Delay_Alt
:= New_List
(
10905 Make_Implicit_If_Statement
(N
,
10906 Condition
=> Condition
(Alt
),
10907 Then_Statements
=> Delay_Alt
));
10910 Append_List
(Delay_Alt
, Delay_List
);
10912 Ensure_Statement_Present
(Dloc
, Alt
);
10914 -- If the delay alternative has a statement part, add choice to the
10915 -- case statements for delays.
10917 if not Is_Empty_List
(Statements
(Alt
)) then
10919 if Delay_Count
= 1 then
10920 Append_List
(Statements
(Alt
), Delay_Alt_List
);
10923 Append_To
(Delay_Alt_List
,
10924 Make_Case_Statement_Alternative
(Loc
,
10925 Discrete_Choices
=> New_List
(
10926 Make_Integer_Literal
(Loc
, Index
)),
10927 Statements
=> Statements
(Alt
)));
10930 elsif Delay_Count
= 1 then
10932 -- If the single delay has no trailing statements, add a branch
10933 -- to the exit label to the selective wait.
10935 Delay_Alt_List
:= New_List
(
10936 Make_Goto_Statement
(Loc
,
10937 Name
=> New_Copy
(Identifier
(End_Lab
))));
10940 end Process_Delay_Alternative
;
10942 -- Start of processing for Expand_N_Selective_Accept
10945 Process_Statements_For_Controlled_Objects
(N
);
10947 -- First insert some declarations before the select. The first is:
10951 -- This variable holds the parameters passed to the accept body. This
10952 -- declaration has already been inserted by the time we get here by
10953 -- a call to Expand_Accept_Declarations made from the semantics when
10954 -- processing the first accept statement contained in the select. We
10955 -- can find this entity as Accept_Address (E), where E is any of the
10956 -- entries references by contained accept statements.
10958 -- The first step is to scan the list of Selective_Accept_Statements
10959 -- to find this entity, and also count the number of accepts, and
10960 -- determine if terminated, delay or else is present:
10964 Alt
:= First
(Alts
);
10965 while Present
(Alt
) loop
10966 Process_Statements_For_Controlled_Objects
(Alt
);
10968 if Nkind
(Alt
) = N_Accept_Alternative
then
10971 elsif Nkind
(Alt
) = N_Delay_Alternative
then
10972 Delay_Count
:= Delay_Count
+ 1;
10974 -- If the delays are relative delays, the delay expressions have
10975 -- type Standard_Duration. Otherwise they must have some time type
10976 -- recognized by GNAT.
10978 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
10979 Time_Type
:= Standard_Duration
;
10981 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
10983 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
10984 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
10988 -- Move this check to sem???
10990 "& is not a time type (RM 9.6(6))",
10991 Expression
(Delay_Statement
(Alt
)), Time_Type
);
10992 Time_Type
:= Standard_Duration
;
10993 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
10997 if No
(Condition
(Alt
)) then
10999 -- This guard will always be open
11001 Check_Guard
:= False;
11004 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
11005 Adjust_Condition
(Condition
(Alt
));
11006 Terminate_Alt
:= Alt
;
11009 Num_Alts
:= Num_Alts
+ 1;
11013 Else_Present
:= Present
(Else_Statements
(N
));
11015 -- At the same time (see procedure Add_Accept) we build the accept list:
11017 -- Qnn : Accept_List (1 .. num-select) := (
11018 -- (null-body, entry-index),
11019 -- (null-body, entry-index),
11021 -- (null_body, entry-index));
11023 -- In the above declaration, null-body is True if the corresponding
11024 -- accept has no body, and false otherwise. The entry is either the
11025 -- entry index expression if there is no guard, or if a guard is
11026 -- present, then an if expression of the form:
11028 -- (if guard then entry-index else Null_Task_Entry)
11030 -- If a guard is statically known to be false, the entry can simply
11031 -- be omitted from the accept list.
11034 Make_Object_Declaration
(Loc
,
11035 Defining_Identifier
=> Qnam
,
11036 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
11037 Aliased_Present
=> True,
11039 Make_Qualified_Expression
(Loc
,
11041 New_Occurrence_Of
(RTE
(RE_Accept_List
), Loc
),
11043 Make_Aggregate
(Loc
, Expressions
=> Accept_List
))));
11045 -- Then we declare the variable that holds the index for the accept
11046 -- that will be selected for service:
11048 -- Xnn : Select_Index;
11051 Make_Object_Declaration
(Loc
,
11052 Defining_Identifier
=> Xnam
,
11053 Object_Definition
=>
11054 New_Occurrence_Of
(RTE
(RE_Select_Index
), Loc
),
11056 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)));
11058 -- After this follow procedure declarations for each accept body
11060 -- procedure Pnn is
11065 -- where the ... are statements from the corresponding procedure body.
11066 -- No parameters are involved, since the parameters are passed via Ann
11067 -- and the parameter references have already been expanded to be direct
11068 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
11069 -- any embedded tasking statements (which would normally be illegal in
11070 -- procedures), have been converted to calls to the tasking runtime so
11071 -- there is no problem in putting them into procedures.
11073 -- The original accept statement has been expanded into a block in
11074 -- the same fashion as for simple accepts (see Build_Accept_Body).
11076 -- Note: we don't really need to build these procedures for the case
11077 -- where no delay statement is present, but it is just as easy to
11078 -- build them unconditionally, and not significantly inefficient,
11079 -- since if they are short they will be inlined anyway.
11081 -- The procedure declarations have been assembled in Body_List
11083 -- If delays are present, we must compute the required delay.
11084 -- We first generate the declarations:
11086 -- Delay_Index : Boolean := 0;
11087 -- Delay_Min : Some_Time_Type.Time;
11088 -- Delay_Val : Some_Time_Type.Time;
11090 -- Delay_Index will be set to the index of the minimum delay, i.e. the
11091 -- active delay that is actually chosen as the basis for the possible
11092 -- delay if an immediate rendez-vous is not possible.
11094 -- In the most common case there is a single delay statement, and this
11095 -- is handled specially.
11097 if Delay_Count
> 0 then
11099 -- Generate the required declarations
11102 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
11104 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
11106 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
11108 pragma Assert
(Present
(Time_Type
));
11111 Make_Object_Declaration
(Loc
,
11112 Defining_Identifier
=> Delay_Val
,
11113 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
)));
11116 Make_Object_Declaration
(Loc
,
11117 Defining_Identifier
=> Delay_Index
,
11118 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
11119 Expression
=> Make_Integer_Literal
(Loc
, 0)));
11122 Make_Object_Declaration
(Loc
,
11123 Defining_Identifier
=> Delay_Min
,
11124 Object_Definition
=> New_Occurrence_Of
(Time_Type
, Loc
),
11126 Unchecked_Convert_To
(Time_Type
,
11127 Make_Attribute_Reference
(Loc
,
11129 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
11130 Attribute_Name
=> Name_Last
))));
11132 -- Create Duration and Delay_Mode objects used for passing a delay
11135 D
:= Make_Temporary
(Loc
, 'D');
11136 M
:= Make_Temporary
(Loc
, 'M');
11142 -- Note that these values are defined in s-osprim.ads and must
11143 -- be kept in sync:
11145 -- Relative : constant := 0;
11146 -- Absolute_Calendar : constant := 1;
11147 -- Absolute_RT : constant := 2;
11149 if Time_Type
= Standard_Duration
then
11150 Discr
:= Make_Integer_Literal
(Loc
, 0);
11152 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11153 Discr
:= Make_Integer_Literal
(Loc
, 1);
11157 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11158 Discr
:= Make_Integer_Literal
(Loc
, 2);
11162 Make_Object_Declaration
(Loc
,
11163 Defining_Identifier
=> D
,
11164 Object_Definition
=>
11165 New_Occurrence_Of
(Standard_Duration
, Loc
)));
11168 Make_Object_Declaration
(Loc
,
11169 Defining_Identifier
=> M
,
11170 Object_Definition
=>
11171 New_Occurrence_Of
(Standard_Integer
, Loc
),
11172 Expression
=> Discr
));
11175 if Check_Guard
then
11177 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
11180 Make_Object_Declaration
(Loc
,
11181 Defining_Identifier
=> Guard_Open
,
11182 Object_Definition
=>
11183 New_Occurrence_Of
(Standard_Boolean
, Loc
),
11185 New_Occurrence_Of
(Standard_False
, Loc
)));
11188 -- Delay_Count is zero, don't need M and D set (suppress warning)
11195 if Present
(Terminate_Alt
) then
11197 -- If the terminate alternative guard is False, use
11198 -- Simple_Mode; otherwise use Terminate_Mode.
11200 if Present
(Condition
(Terminate_Alt
)) then
11201 Select_Mode
:= Make_If_Expression
(Loc
,
11202 New_List
(Condition
(Terminate_Alt
),
11203 New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
),
11204 New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
)));
11206 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Terminate_Mode
), Loc
);
11209 elsif Else_Present
or Delay_Count
> 0 then
11210 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Else_Mode
), Loc
);
11213 Select_Mode
:= New_Occurrence_Of
(RTE
(RE_Simple_Mode
), Loc
);
11216 Select_Call
:= Make_Select_Call
(Select_Mode
);
11217 Append
(Select_Call
, Stats
);
11219 -- Now generate code to act on the result. There is an entry
11220 -- in this case for each accept statement with a non-null body,
11221 -- followed by a branch to the statements that follow the Accept.
11222 -- In the absence of delay alternatives, we generate:
11225 -- when No_Rendezvous => -- omitted if simple mode
11240 -- Lab0: Else_Statements;
11243 -- Lab1: Trailing_Statements1;
11246 -- Lab2: Trailing_Statements2;
11251 -- Generate label for common exit
11253 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
11255 -- First entry is the default case, when no rendezvous is possible
11257 Choices
:= New_List
(New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
));
11259 if Else_Present
then
11261 -- If no rendezvous is possible, the else part is executed
11263 Lab
:= Make_And_Declare_Label
(0);
11264 Alt_Stats
:= New_List
(
11265 Make_Goto_Statement
(Loc
,
11266 Name
=> New_Copy
(Identifier
(Lab
))));
11268 Append
(Lab
, Trailing_List
);
11269 Append_List
(Else_Statements
(N
), Trailing_List
);
11270 Append_To
(Trailing_List
,
11271 Make_Goto_Statement
(Loc
,
11272 Name
=> New_Copy
(Identifier
(End_Lab
))));
11274 Alt_Stats
:= New_List
(
11275 Make_Goto_Statement
(Loc
,
11276 Name
=> New_Copy
(Identifier
(End_Lab
))));
11279 Append_To
(Alt_List
,
11280 Make_Case_Statement_Alternative
(Loc
,
11281 Discrete_Choices
=> Choices
,
11282 Statements
=> Alt_Stats
));
11284 -- We make use of the fact that Accept_Index is an integer type, and
11285 -- generate successive literals for entries for each accept. Only those
11286 -- for which there is a body or trailing statements get a case entry.
11288 Alt
:= First
(Select_Alternatives
(N
));
11289 Proc
:= First
(Body_List
);
11290 while Present
(Alt
) loop
11292 if Nkind
(Alt
) = N_Accept_Alternative
then
11293 Process_Accept_Alternative
(Alt
, Index
, Proc
);
11294 Index
:= Index
+ 1;
11297 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
11302 elsif Nkind
(Alt
) = N_Delay_Alternative
then
11303 Process_Delay_Alternative
(Alt
, Delay_Num
);
11304 Delay_Num
:= Delay_Num
+ 1;
11310 -- An others choice is always added to the main case, as well
11311 -- as the delay case (to satisfy the compiler).
11313 Append_To
(Alt_List
,
11314 Make_Case_Statement_Alternative
(Loc
,
11315 Discrete_Choices
=>
11316 New_List
(Make_Others_Choice
(Loc
)),
11318 New_List
(Make_Goto_Statement
(Loc
,
11319 Name
=> New_Copy
(Identifier
(End_Lab
))))));
11321 Accept_Case
:= New_List
(
11322 Make_Case_Statement
(Loc
,
11323 Expression
=> New_Occurrence_Of
(Xnam
, Loc
),
11324 Alternatives
=> Alt_List
));
11326 Append_List
(Trailing_List
, Accept_Case
);
11327 Append_List
(Body_List
, Decls
);
11329 -- Construct case statement for trailing statements of delay
11330 -- alternatives, if there are several of them.
11332 if Delay_Count
> 1 then
11333 Append_To
(Delay_Alt_List
,
11334 Make_Case_Statement_Alternative
(Loc
,
11335 Discrete_Choices
=>
11336 New_List
(Make_Others_Choice
(Loc
)),
11338 New_List
(Make_Null_Statement
(Loc
))));
11340 Delay_Case
:= New_List
(
11341 Make_Case_Statement
(Loc
,
11342 Expression
=> New_Occurrence_Of
(Delay_Index
, Loc
),
11343 Alternatives
=> Delay_Alt_List
));
11345 Delay_Case
:= Delay_Alt_List
;
11348 -- If there are no delay alternatives, we append the case statement
11349 -- to the statement list.
11351 if Delay_Count
= 0 then
11352 Append_List
(Accept_Case
, Stats
);
11354 -- Delay alternatives present
11357 -- If delay alternatives are present we generate:
11359 -- find minimum delay.
11360 -- DX := minimum delay;
11361 -- M := <delay mode>;
11362 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11365 -- if X = No_Rendezvous then
11366 -- case statement for delay statements.
11368 -- case statement for accept alternatives.
11379 -- The type of the delay expression is known to be legal
11381 if Time_Type
= Standard_Duration
then
11382 Conv
:= New_Occurrence_Of
(Delay_Min
, Loc
);
11384 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
11385 Conv
:= Make_Function_Call
(Loc
,
11386 New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
11387 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11391 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
11393 Conv
:= Make_Function_Call
(Loc
,
11394 New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
11395 New_List
(New_Occurrence_Of
(Delay_Min
, Loc
)));
11398 Stmt
:= Make_Assignment_Statement
(Loc
,
11399 Name
=> New_Occurrence_Of
(D
, Loc
),
11400 Expression
=> Conv
);
11402 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11404 Parms
:= Parameter_Associations
(Select_Call
);
11406 Parm
:= First
(Parms
);
11407 while Present
(Parm
) and then Parm
/= Select_Mode
loop
11411 pragma Assert
(Present
(Parm
));
11412 Rewrite
(Parm
, New_Occurrence_Of
(RTE
(RE_Delay_Mode
), Loc
));
11415 -- Prepare two new parameters of Duration and Delay_Mode type
11416 -- which represent the value and the mode of the minimum delay.
11419 Insert_After
(Parm
, New_Occurrence_Of
(M
, Loc
));
11420 Insert_After
(Parm
, New_Occurrence_Of
(D
, Loc
));
11422 -- Create a call to RTS
11424 Rewrite
(Select_Call
,
11425 Make_Procedure_Call_Statement
(Loc
,
11426 Name
=> New_Occurrence_Of
(RTE
(RE_Timed_Selective_Wait
), Loc
),
11427 Parameter_Associations
=> Parms
));
11429 -- This new call should follow the calculation of the minimum
11432 Insert_List_Before
(Select_Call
, Delay_List
);
11434 if Check_Guard
then
11436 Make_Implicit_If_Statement
(N
,
11437 Condition
=> New_Occurrence_Of
(Guard_Open
, Loc
),
11438 Then_Statements
=> New_List
(
11439 New_Copy_Tree
(Stmt
),
11440 New_Copy_Tree
(Select_Call
)),
11441 Else_Statements
=> Accept_Or_Raise
);
11442 Rewrite
(Select_Call
, Stmt
);
11444 Insert_Before
(Select_Call
, Stmt
);
11448 Make_Implicit_If_Statement
(N
,
11449 Condition
=> Make_Op_Eq
(Loc
,
11450 Left_Opnd
=> New_Occurrence_Of
(Xnam
, Loc
),
11452 New_Occurrence_Of
(RTE
(RE_No_Rendezvous
), Loc
)),
11454 Then_Statements
=> Delay_Case
,
11455 Else_Statements
=> Accept_Case
);
11457 Append
(Cases
, Stats
);
11461 Append
(End_Lab
, Stats
);
11463 -- Replace accept statement with appropriate block
11466 Make_Block_Statement
(Loc
,
11467 Declarations
=> Decls
,
11468 Handled_Statement_Sequence
=>
11469 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
)));
11472 -- Note: have to worry more about abort deferral in above code ???
11474 -- Final step is to unstack the Accept_Address entries for all accept
11475 -- statements appearing in accept alternatives in the select statement
11477 Alt
:= First
(Alts
);
11478 while Present
(Alt
) loop
11479 if Nkind
(Alt
) = N_Accept_Alternative
then
11480 Remove_Last_Elmt
(Accept_Address
11481 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
11486 end Expand_N_Selective_Accept
;
11488 -------------------------------------------
11489 -- Expand_N_Single_Protected_Declaration --
11490 -------------------------------------------
11492 -- A single protected declaration should never be present after semantic
11493 -- analysis because it is transformed into a protected type declaration
11494 -- and an accompanying anonymous object. This routine ensures that the
11495 -- transformation takes place.
11497 procedure Expand_N_Single_Protected_Declaration
(N
: Node_Id
) is
11499 raise Program_Error
;
11500 end Expand_N_Single_Protected_Declaration
;
11502 --------------------------------------
11503 -- Expand_N_Single_Task_Declaration --
11504 --------------------------------------
11506 -- A single task declaration should never be present after semantic
11507 -- analysis because it is transformed into a task type declaration and
11508 -- an accompanying anonymous object. This routine ensures that the
11509 -- transformation takes place.
11511 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
11513 raise Program_Error
;
11514 end Expand_N_Single_Task_Declaration
;
11516 ------------------------
11517 -- Expand_N_Task_Body --
11518 ------------------------
11520 -- Given a task body
11522 -- task body tname is
11528 -- This expansion routine converts it into a procedure and sets the
11529 -- elaboration flag for the procedure to true, to represent the fact
11530 -- that the task body is now elaborated:
11532 -- procedure tnameB (_Task : access tnameV) is
11533 -- discriminal : dtype renames _Task.discriminant;
11535 -- procedure _clean is
11537 -- Abort_Defer.all;
11539 -- Abort_Undefer.all;
11544 -- Abort_Undefer.all;
11546 -- System.Task_Stages.Complete_Activation;
11554 -- In addition, if the task body is an activator, then a call to activate
11555 -- tasks is added at the start of the statements, before the call to
11556 -- Complete_Activation, and if in addition the task is a master then it
11557 -- must be established as a master. These calls are inserted and analyzed
11558 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11561 -- There is one discriminal declaration line generated for each
11562 -- discriminant that is present to provide an easy reference point for
11563 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11565 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11566 -- task body procedures have a profile (Arg : System.Address). That is
11567 -- needed because GNARLI has to use the same access-to-subprogram type
11568 -- for all task types. We depend here on knowing that in GNAT, passing
11569 -- an address argument by value is identical to passing a record value
11570 -- by access (in either case a single pointer is passed), so even though
11571 -- this procedure has the wrong profile. In fact it's all OK, since the
11572 -- callings sequence is identical.
11574 procedure Expand_N_Task_Body
(N
: Node_Id
) is
11575 Loc
: constant Source_Ptr
:= Sloc
(N
);
11576 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
11580 Insert_Nod
: Node_Id
;
11581 -- Used to determine the proper location of wrapper body insertions
11584 -- if no task body procedure, means we had an error in configurable
11585 -- run-time mode, and there is no point in proceeding further.
11587 if No
(Task_Body_Procedure
(Ttyp
)) then
11591 -- Add renaming declarations for discriminals and a declaration for the
11592 -- entry family index (if applicable).
11594 Install_Private_Data_Declarations
11595 (Loc
, Task_Body_Procedure
(Ttyp
), Ttyp
, N
, Declarations
(N
));
11597 -- Add a call to Abort_Undefer at the very beginning of the task
11598 -- body since this body is called with abort still deferred.
11600 if Abort_Allowed
then
11601 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
11602 Prepend
(Call
, Declarations
(N
));
11606 -- Place call to Complete_Activation at the head of the statement list.
11608 if Restricted_Profile
then
11609 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
11611 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
11615 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
11619 Make_Subprogram_Body
(Loc
,
11620 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
11621 Declarations
=> Declarations
(N
),
11622 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
11623 Set_Is_Task_Body_Procedure
(New_N
);
11624 Set_At_End_Proc
(New_N
, At_End_Proc
(N
));
11626 -- If the task contains generic instantiations, cleanup actions are
11627 -- delayed until after instantiation. Transfer the activation chain to
11628 -- the subprogram, to insure that the activation call is properly
11629 -- generated. It the task body contains inner tasks, indicate that the
11630 -- subprogram is a task master.
11632 if Delay_Cleanups
(Ttyp
) then
11633 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
11634 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
11637 Rewrite
(N
, New_N
);
11640 -- Set elaboration flag immediately after task body. If the body is a
11641 -- subunit, the flag is set in the declarative part containing the stub.
11643 if Nkind
(Parent
(N
)) /= N_Subunit
then
11645 Make_Assignment_Statement
(Loc
,
11647 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
11648 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
11651 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11652 -- the task body. At this point all wrapper specs have been created,
11653 -- frozen and included in the dispatch table for the task type.
11655 if Ada_Version
>= Ada_2005
then
11656 if Nkind
(Parent
(N
)) = N_Subunit
then
11657 Insert_Nod
:= Corresponding_Stub
(Parent
(N
));
11662 Build_Wrapper_Bodies
(Loc
, Ttyp
, Insert_Nod
);
11664 end Expand_N_Task_Body
;
11666 ------------------------------------
11667 -- Expand_N_Task_Type_Declaration --
11668 ------------------------------------
11670 -- We have several things to do. First we must create a Boolean flag used
11671 -- to mark if the body is elaborated yet. This variable gets set to True
11672 -- when the body of the task is elaborated (we can't rely on the normal
11673 -- ABE mechanism for the task body, since we need to pass an access to
11674 -- this elaboration boolean to the runtime routines).
11676 -- taskE : aliased Boolean := False;
11678 -- Next a variable is declared to hold the task stack size (either the
11679 -- default : Unspecified_Size, or a value that is set by a pragma
11680 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11681 -- the variable is initialized with this value:
11683 -- taskZ : Size_Type := Unspecified_Size;
11685 -- taskZ : Size_Type := Size_Type (size_expression);
11687 -- Note: No variable is needed to hold the task relative deadline since
11688 -- its value would never be static because the parameter is of a private
11689 -- type (Ada.Real_Time.Time_Span).
11691 -- Next we create a corresponding record type declaration used to represent
11692 -- values of this task. The general form of this type declaration is
11694 -- type taskV (discriminants) is record
11695 -- _Task_Id : Task_Id;
11696 -- entry_family : array (bounds) of Void;
11697 -- _Priority : Integer := priority_expression;
11698 -- _Size : Size_Type := size_expression;
11699 -- _Secondary_Stack_Size : Size_Type := size_expression;
11700 -- _Task_Info : Task_Info_Type := task_info_expression;
11701 -- _CPU : Integer := cpu_range_expression;
11702 -- _Relative_Deadline : Time_Span := time_span_expression;
11703 -- _Domain : Dispatching_Domain := dd_expression;
11706 -- The discriminants are present only if the corresponding task type has
11707 -- discriminants, and they exactly mirror the task type discriminants.
11709 -- The Id field is always present. It contains the Task_Id value, as set by
11710 -- the call to Create_Task. Note that although the task is limited, the
11711 -- task value record type is not limited, so there is no problem in passing
11712 -- this field as an out parameter to Create_Task.
11714 -- One entry_family component is present for each entry family in the task
11715 -- definition. The bounds correspond to the bounds of the entry family
11716 -- (which may depend on discriminants). The element type is void, since we
11717 -- only need the bounds information for determining the entry index. Note
11718 -- that the use of an anonymous array would normally be illegal in this
11719 -- context, but this is a parser check, and the semantics is quite prepared
11720 -- to handle such a case.
11722 -- The _Size field is present only if a Storage_Size pragma appears in the
11723 -- task definition. The expression captures the argument that was present
11724 -- in the pragma, and is used to override the task stack size otherwise
11725 -- associated with the task type.
11727 -- The _Secondary_Stack_Size field is present only the task entity has a
11728 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11729 -- when the record init proc is built, to capture the expression of the
11730 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11731 -- be filled here since aspect evaluations are delayed till the freeze
11734 -- The _Priority field is present only if the task entity has a Priority or
11735 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11736 -- definition clause). It will be filled at the freeze point, when the
11737 -- record init proc is built, to capture the expression of the rep item
11738 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11739 -- here since aspect evaluations are delayed till the freeze point.
11741 -- The _Task_Info field is present only if a Task_Info pragma appears in
11742 -- the task definition. The expression captures the argument that was
11743 -- present in the pragma, and is used to provide the Task_Image parameter
11744 -- to the call to Create_Task.
11746 -- The _CPU field is present only if the task entity has a CPU rep item
11747 -- (pragma, aspect specification or attribute definition clause). It will
11748 -- be filled at the freeze point, when the record init proc is built, to
11749 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11750 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11751 -- are delayed till the freeze point.
11753 -- The _Relative_Deadline field is present only if a Relative_Deadline
11754 -- pragma appears in the task definition. The expression captures the
11755 -- argument that was present in the pragma, and is used to provide the
11756 -- Relative_Deadline parameter to the call to Create_Task.
11758 -- The _Domain field is present only if the task entity has a
11759 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11760 -- definition clause). It will be filled at the freeze point, when the
11761 -- record init proc is built, to capture the expression of the rep item
11762 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11763 -- here since aspect evaluations are delayed till the freeze point.
11765 -- When a task is declared, an instance of the task value record is
11766 -- created. The elaboration of this declaration creates the correct bounds
11767 -- for the entry families, and also evaluates the size, priority, and
11768 -- task_Info expressions if needed. The initialization routine for the task
11769 -- type itself then calls Create_Task with appropriate parameters to
11770 -- initialize the value of the Task_Id field.
11772 -- Note: the address of this record is passed as the "Discriminants"
11773 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11774 -- body procedure, it does not matter that it does not quite match the
11775 -- GNARLI model of what is being passed (the record contains more than just
11776 -- the discriminants, but the discriminants can be found from the record
11779 -- The Entity_Id for this created record type is placed in the
11780 -- Corresponding_Record_Type field of the associated task type entity.
11782 -- Next we create a procedure specification for the task body procedure:
11784 -- procedure taskB (_Task : access taskV);
11786 -- Note that this must come after the record type declaration, since
11787 -- the spec refers to this type. It turns out that the initialization
11788 -- procedure for the value type references the task body spec, but that's
11789 -- fine, since it won't be generated till the freeze point for the type,
11790 -- which is certainly after the task body spec declaration.
11792 -- Finally, we set the task index value field of the entry attribute in
11793 -- the case of a simple entry.
11795 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
11796 Loc
: constant Source_Ptr
:= Sloc
(N
);
11797 TaskId
: constant Entity_Id
:= Defining_Identifier
(N
);
11798 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11799 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
11800 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
11802 Body_Decl
: Node_Id
;
11804 Decl_Stack
: Node_Id
;
11806 Elab_Decl
: Node_Id
;
11807 Ent_Stack
: Entity_Id
;
11808 Proc_Spec
: Node_Id
;
11809 Rec_Decl
: Node_Id
;
11810 Rec_Ent
: Entity_Id
;
11811 Size_Decl
: Entity_Id
;
11812 Task_Size
: Node_Id
;
11814 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
;
11815 -- Searches the task definition T for the first occurrence of the pragma
11816 -- Relative Deadline. The caller has ensured that the pragma is present
11817 -- in the task definition. Note that this routine cannot be implemented
11818 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11819 -- not chained because their expansion into a procedure call statement
11820 -- would cause a break in the chain.
11822 ----------------------------------
11823 -- Get_Relative_Deadline_Pragma --
11824 ----------------------------------
11826 function Get_Relative_Deadline_Pragma
(T
: Node_Id
) return Node_Id
is
11830 N
:= First
(Visible_Declarations
(T
));
11831 while Present
(N
) loop
11832 if Nkind
(N
) = N_Pragma
11833 and then Pragma_Name
(N
) = Name_Relative_Deadline
11841 N
:= First
(Private_Declarations
(T
));
11842 while Present
(N
) loop
11843 if Nkind
(N
) = N_Pragma
11844 and then Pragma_Name
(N
) = Name_Relative_Deadline
11852 raise Program_Error
;
11853 end Get_Relative_Deadline_Pragma
;
11855 -- Start of processing for Expand_N_Task_Type_Declaration
11858 -- If already expanded, nothing to do
11860 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
11864 -- Here we will do the expansion
11866 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
11868 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
11869 Cdecls
:= Component_Items
(Component_List
11870 (Type_Definition
(Rec_Decl
)));
11872 Qualify_Entity_Names
(N
);
11874 -- First create the elaboration variable
11877 Make_Object_Declaration
(Loc
,
11878 Defining_Identifier
=>
11879 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11880 Chars
=> New_External_Name
(Tasknm
, 'E')),
11881 Aliased_Present
=> True,
11882 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
11883 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
));
11885 Insert_After
(N
, Elab_Decl
);
11887 -- Next create the declaration of the size variable (tasknmZ)
11889 Set_Storage_Size_Variable
(Tasktyp
,
11890 Make_Defining_Identifier
(Sloc
(Tasktyp
),
11891 Chars
=> New_External_Name
(Tasknm
, 'Z')));
11893 if Present
(Taskdef
)
11894 and then Has_Storage_Size_Pragma
(Taskdef
)
11896 Is_OK_Static_Expression
11898 (First
(Pragma_Argument_Associations
11899 (Get_Rep_Pragma
(TaskId
, Name_Storage_Size
)))))
11902 Make_Object_Declaration
(Loc
,
11903 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11904 Object_Definition
=>
11905 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11907 Convert_To
(RTE
(RE_Size_Type
),
11909 (Expression
(First
(Pragma_Argument_Associations
11911 (TaskId
, Name_Storage_Size
)))))));
11915 Make_Object_Declaration
(Loc
,
11916 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
11917 Object_Definition
=>
11918 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
),
11920 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
11923 Insert_After
(Elab_Decl
, Size_Decl
);
11925 -- Next build the rest of the corresponding record declaration. This is
11926 -- done last, since the corresponding record initialization procedure
11927 -- will reference the previously created entities.
11929 -- Fill in the component declarations -- first the _Task_Id field
11932 Make_Component_Declaration
(Loc
,
11933 Defining_Identifier
=>
11934 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
11935 Component_Definition
=>
11936 Make_Component_Definition
(Loc
,
11937 Aliased_Present
=> False,
11938 Subtype_Indication
=> New_Occurrence_Of
(RTE
(RO_ST_Task_Id
),
11941 -- Declare static ATCB (that is, created by the expander) if we are
11942 -- using the Restricted run time.
11944 if Restricted_Profile
then
11946 Make_Component_Declaration
(Loc
,
11947 Defining_Identifier
=>
11948 Make_Defining_Identifier
(Loc
, Name_uATCB
),
11950 Component_Definition
=>
11951 Make_Component_Definition
(Loc
,
11952 Aliased_Present
=> True,
11953 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
11955 New_Occurrence_Of
(RTE
(RE_Ada_Task_Control_Block
), Loc
),
11958 Make_Index_Or_Discriminant_Constraint
(Loc
,
11960 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
11964 -- Declare static stack (that is, created by the expander) if we are
11965 -- using the Restricted run time on a bare board configuration.
11967 if Restricted_Profile
and then Preallocated_Stacks_On_Target
then
11969 -- First we need to extract the appropriate stack size
11971 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
11973 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
11975 Expr_N
: constant Node_Id
:=
11976 Expression
(First
(
11977 Pragma_Argument_Associations
(
11978 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))));
11979 Etyp
: constant Entity_Id
:= Etype
(Expr_N
);
11980 P
: constant Node_Id
:= Parent
(Expr_N
);
11983 -- The stack is defined inside the corresponding record.
11984 -- Therefore if the size of the stack is set by means of
11985 -- a discriminant, we must reference the discriminant of the
11986 -- corresponding record type.
11988 if Nkind
(Expr_N
) in N_Has_Entity
11989 and then Present
(Discriminal_Link
(Entity
(Expr_N
)))
11993 (CR_Discriminant
(Discriminal_Link
(Entity
(Expr_N
))),
11995 Set_Parent
(Task_Size
, P
);
11996 Set_Etype
(Task_Size
, Etyp
);
11997 Set_Analyzed
(Task_Size
);
12000 Task_Size
:= New_Copy_Tree
(Expr_N
);
12006 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
);
12009 Decl_Stack
:= Make_Component_Declaration
(Loc
,
12010 Defining_Identifier
=> Ent_Stack
,
12012 Component_Definition
=>
12013 Make_Component_Definition
(Loc
,
12014 Aliased_Present
=> True,
12015 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
12017 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
12020 Make_Index_Or_Discriminant_Constraint
(Loc
,
12021 Constraints
=> New_List
(Make_Range
(Loc
,
12022 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
12023 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
12026 Append_To
(Cdecls
, Decl_Stack
);
12028 -- The appropriate alignment for the stack is ensured by the run-time
12029 -- code in charge of task creation.
12033 -- Declare a static secondary stack if the conditions for a statically
12034 -- generated stack are met.
12036 if Create_Secondary_Stack_For_Task
(TaskId
) then
12038 Size_Expr
: constant Node_Id
:=
12039 Expression
(First
(
12040 Pragma_Argument_Associations
(
12041 Get_Rep_Pragma
(TaskId
,
12042 Name_Secondary_Stack_Size
))));
12044 Stack_Size
: Node_Id
;
12047 -- The secondary stack is defined inside the corresponding
12048 -- record. Therefore if the size of the stack is set by means
12049 -- of a discriminant, we must reference the discriminant of the
12050 -- corresponding record type.
12052 if Nkind
(Size_Expr
) in N_Has_Entity
12053 and then Present
(Discriminal_Link
(Entity
(Size_Expr
)))
12057 (CR_Discriminant
(Discriminal_Link
(Entity
(Size_Expr
))),
12059 Set_Parent
(Stack_Size
, Parent
(Size_Expr
));
12060 Set_Etype
(Stack_Size
, Etype
(Size_Expr
));
12061 Set_Analyzed
(Stack_Size
);
12064 Stack_Size
:= New_Copy_Tree
(Size_Expr
);
12067 -- Create the secondary stack for the task
12070 Make_Component_Declaration
(Loc
,
12071 Defining_Identifier
=>
12072 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack
),
12073 Component_Definition
=>
12074 Make_Component_Definition
(Loc
,
12075 Aliased_Present
=> True,
12076 Subtype_Indication
=>
12077 Make_Subtype_Indication
(Loc
,
12079 New_Occurrence_Of
(RTE
(RE_SS_Stack
), Loc
),
12081 Make_Index_Or_Discriminant_Constraint
(Loc
,
12082 Constraints
=> New_List
(
12083 Convert_To
(RTE
(RE_Size_Type
),
12086 Append_To
(Cdecls
, Decl_SS
);
12090 -- Add components for entry families
12092 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
12094 -- Add the _Priority component if a Interrupt_Priority or Priority rep
12095 -- item is present.
12097 if Has_Rep_Item
(TaskId
, Name_Priority
, Check_Parents
=> False) then
12099 Make_Component_Declaration
(Loc
,
12100 Defining_Identifier
=>
12101 Make_Defining_Identifier
(Loc
, Name_uPriority
),
12102 Component_Definition
=>
12103 Make_Component_Definition
(Loc
,
12104 Aliased_Present
=> False,
12105 Subtype_Indication
=>
12106 New_Occurrence_Of
(Standard_Integer
, Loc
))));
12109 -- Add the _Size component if a Storage_Size pragma is present
12111 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
12113 Make_Component_Declaration
(Loc
,
12114 Defining_Identifier
=>
12115 Make_Defining_Identifier
(Loc
, Name_uSize
),
12117 Component_Definition
=>
12118 Make_Component_Definition
(Loc
,
12119 Aliased_Present
=> False,
12120 Subtype_Indication
=>
12121 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
)),
12124 Convert_To
(RTE
(RE_Size_Type
),
12126 Expression
(First
(
12127 Pragma_Argument_Associations
(
12128 Get_Rep_Pragma
(TaskId
, Name_Storage_Size
))))))));
12131 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
12132 -- pragma is present.
12135 (TaskId
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
12138 Make_Component_Declaration
(Loc
,
12139 Defining_Identifier
=>
12140 Make_Defining_Identifier
(Loc
, Name_uSecondary_Stack_Size
),
12142 Component_Definition
=>
12143 Make_Component_Definition
(Loc
,
12144 Aliased_Present
=> False,
12145 Subtype_Indication
=>
12146 New_Occurrence_Of
(RTE
(RE_Size_Type
), Loc
))));
12149 -- Add the _Task_Info component if a Task_Info pragma is present
12151 if Has_Rep_Pragma
(TaskId
, Name_Task_Info
, Check_Parents
=> False) then
12153 Make_Component_Declaration
(Loc
,
12154 Defining_Identifier
=>
12155 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
12157 Component_Definition
=>
12158 Make_Component_Definition
(Loc
,
12159 Aliased_Present
=> False,
12160 Subtype_Indication
=>
12161 New_Occurrence_Of
(RTE
(RE_Task_Info_Type
), Loc
)),
12163 Expression
=> New_Copy
(
12164 Expression
(First
(
12165 Pragma_Argument_Associations
(
12167 (TaskId
, Name_Task_Info
, Check_Parents
=> False)))))));
12170 -- Add the _CPU component if a CPU rep item is present
12172 if Has_Rep_Item
(TaskId
, Name_CPU
, Check_Parents
=> False) then
12174 Make_Component_Declaration
(Loc
,
12175 Defining_Identifier
=>
12176 Make_Defining_Identifier
(Loc
, Name_uCPU
),
12178 Component_Definition
=>
12179 Make_Component_Definition
(Loc
,
12180 Aliased_Present
=> False,
12181 Subtype_Indication
=>
12182 New_Occurrence_Of
(RTE
(RE_CPU_Range
), Loc
))));
12185 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
12186 -- present. If we are using a restricted run time this component will
12187 -- not be added (deadlines are not allowed by the Ravenscar profile),
12188 -- unless the task dispatching policy is EDF (for GNAT_Ravenscar_EDF
12191 if (not Restricted_Profile
or else Task_Dispatching_Policy
= 'E')
12192 and then Present
(Taskdef
)
12193 and then Has_Relative_Deadline_Pragma
(Taskdef
)
12196 Make_Component_Declaration
(Loc
,
12197 Defining_Identifier
=>
12198 Make_Defining_Identifier
(Loc
, Name_uRelative_Deadline
),
12200 Component_Definition
=>
12201 Make_Component_Definition
(Loc
,
12202 Aliased_Present
=> False,
12203 Subtype_Indication
=>
12204 New_Occurrence_Of
(RTE
(RE_Time_Span
), Loc
)),
12207 Convert_To
(RTE
(RE_Time_Span
),
12209 Expression
(First
(
12210 Pragma_Argument_Associations
(
12211 Get_Relative_Deadline_Pragma
(Taskdef
))))))));
12214 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12215 -- item is present. If we are using a restricted run time this component
12216 -- will not be added (dispatching domains are not allowed by the
12217 -- Ravenscar profile).
12219 if not Restricted_Profile
12222 (TaskId
, Name_Dispatching_Domain
, Check_Parents
=> False)
12225 Make_Component_Declaration
(Loc
,
12226 Defining_Identifier
=>
12227 Make_Defining_Identifier
(Loc
, Name_uDispatching_Domain
),
12229 Component_Definition
=>
12230 Make_Component_Definition
(Loc
,
12231 Aliased_Present
=> False,
12232 Subtype_Indication
=>
12234 (RTE
(RE_Dispatching_Domain_Access
), Loc
))));
12237 Insert_After
(Size_Decl
, Rec_Decl
);
12239 -- Analyze the record declaration immediately after construction,
12240 -- because the initialization procedure is needed for single task
12241 -- declarations before the next entity is analyzed.
12243 Analyze
(Rec_Decl
);
12245 -- Create the declaration of the task body procedure
12247 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
12249 Make_Subprogram_Declaration
(Loc
,
12250 Specification
=> Proc_Spec
);
12251 Set_Is_Task_Body_Procedure
(Body_Decl
);
12253 Insert_After
(Rec_Decl
, Body_Decl
);
12255 -- The subprogram does not comes from source, so we have to indicate the
12256 -- need for debugging information explicitly.
12258 if Comes_From_Source
(Original_Node
(N
)) then
12259 Set_Debug_Info_Needed
(Defining_Entity
(Proc_Spec
));
12262 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12263 -- the corresponding record has been frozen.
12265 if Ada_Version
>= Ada_2005
then
12266 Build_Wrapper_Specs
(Loc
, Tasktyp
, Rec_Decl
);
12269 -- Ada 2005 (AI-345): We must defer freezing to allow further
12270 -- declaration of primitive subprograms covering task interfaces
12272 if Ada_Version
<= Ada_95
then
12274 -- Now we can freeze the corresponding record. This needs manually
12275 -- freezing, since it is really part of the task type, and the task
12276 -- type is frozen at this stage. We of course need the initialization
12277 -- procedure for this corresponding record type and we won't get it
12278 -- in time if we don't freeze now.
12280 Insert_List_After
(Body_Decl
, List
=> Freeze_Entity
(Rec_Ent
, N
));
12283 -- Complete the expansion of access types to the current task type, if
12284 -- any were declared.
12286 Expand_Previous_Access_Type
(Tasktyp
);
12288 -- Create wrappers for entries that have contract cases, preconditions
12289 -- and postconditions.
12295 Ent
:= First_Entity
(Tasktyp
);
12296 while Present
(Ent
) loop
12297 if Ekind
(Ent
) in E_Entry | E_Entry_Family
then
12298 Build_Entry_Contract_Wrapper
(Ent
, N
);
12304 end Expand_N_Task_Type_Declaration
;
12306 -------------------------------
12307 -- Expand_N_Timed_Entry_Call --
12308 -------------------------------
12310 -- A timed entry call in normal case is not implemented using ATC mechanism
12311 -- anymore for efficiency reason.
12321 -- is expanded as follows:
12323 -- 1) When T.E is a task entry_call;
12327 -- X : Task_Entry_Index := <entry index>;
12328 -- DX : Duration := To_Duration (D);
12329 -- M : Delay_Mode := <discriminant>;
12330 -- P : parms := (parm, parm, parm);
12333 -- Timed_Protected_Entry_Call
12334 -- (<acceptor-task>, X, P'Address, DX, M, B);
12342 -- 2) When T.E is a protected entry_call;
12346 -- X : Protected_Entry_Index := <entry index>;
12347 -- DX : Duration := To_Duration (D);
12348 -- M : Delay_Mode := <discriminant>;
12349 -- P : parms := (parm, parm, parm);
12352 -- Timed_Protected_Entry_Call
12353 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12361 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12362 -- is no delay and the triggering statements are executed. We first
12363 -- determine the kind of the triggering call and then execute a
12364 -- synchronized operation or a direct call.
12367 -- B : Boolean := False;
12368 -- C : Ada.Tags.Prim_Op_Kind;
12369 -- DX : Duration := To_Duration (D)
12370 -- K : Ada.Tags.Tagged_Kind :=
12371 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12372 -- M : Integer :=...;
12373 -- P : Parameters := (Param1 .. ParamN);
12377 -- if K = Ada.Tags.TK_Limited_Tagged
12378 -- or else K = Ada.Tags.TK_Tagged
12380 -- <dispatching-call>;
12385 -- Ada.Tags.Get_Offset_Index
12386 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12388 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12390 -- if C = POK_Protected_Entry
12391 -- or else C = POK_Task_Entry
12393 -- Param1 := P.Param1;
12395 -- ParamN := P.ParamN;
12399 -- if C = POK_Procedure
12400 -- or else C = POK_Protected_Procedure
12401 -- or else C = POK_Task_Procedure
12403 -- <dispatching-call>;
12409 -- <triggering-statements>
12411 -- <timed-statements>
12415 -- The triggering statement and the sequence of timed statements have not
12416 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12417 -- global references if within an instantiation.
12419 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
12421 Blk_Typ
: Entity_Id
;
12423 Call_Ent
: Entity_Id
;
12424 Conc_Typ_Stmts
: List_Id
;
12425 Concval
: Node_Id
:= Empty
; -- init to avoid warning
12426 D_Alt
: constant Node_Id
:= Delay_Alternative
(N
);
12429 D_Stat
: Node_Id
:= Delay_Statement
(D_Alt
);
12431 D_Type
: Entity_Id
;
12434 E_Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
12435 E_Call
: Node_Id
:= Entry_Call_Statement
(E_Alt
);
12440 Is_Disp_Select
: Boolean;
12441 Lim_Typ_Stmts
: List_Id
;
12442 Loc
: constant Source_Ptr
:= Sloc
(D_Stat
);
12451 B
: Entity_Id
; -- Call status flag
12452 C
: Entity_Id
; -- Call kind
12453 D
: Entity_Id
; -- Delay
12454 K
: Entity_Id
; -- Tagged kind
12455 M
: Entity_Id
; -- Delay mode
12456 P
: Entity_Id
; -- Parameter block
12457 S
: Entity_Id
; -- Primitive operation slot
12459 -- Start of processing for Expand_N_Timed_Entry_Call
12462 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12463 -- was already reported on spec, so do not attempt to expand the call.
12465 if Restriction_Active
(No_Select_Statements
) then
12469 Process_Statements_For_Controlled_Objects
(E_Alt
);
12470 Process_Statements_For_Controlled_Objects
(D_Alt
);
12472 Ensure_Statement_Present
(Sloc
(D_Stat
), D_Alt
);
12474 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12475 -- may wrap them in blocks.
12477 E_Stats
:= Statements
(E_Alt
);
12478 D_Stats
:= Statements
(D_Alt
);
12480 -- The arguments in the call may require dynamic allocation, and the
12481 -- call statement may have been transformed into a block. The block
12482 -- may contain additional declarations for internal entities, and the
12483 -- original call is found by sequential search.
12485 if Nkind
(E_Call
) = N_Block_Statement
then
12486 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
12487 while Nkind
(E_Call
) not in
12488 N_Procedure_Call_Statement | N_Entry_Call_Statement
12495 Ada_Version
>= Ada_2005
12496 and then Nkind
(E_Call
) = N_Procedure_Call_Statement
;
12498 if Is_Disp_Select
then
12499 Extract_Dispatching_Call
(E_Call
, Call_Ent
, Obj
, Actuals
, Formals
);
12505 -- B : Boolean := False;
12507 B
:= Build_B
(Loc
, Decls
);
12510 -- C : Ada.Tags.Prim_Op_Kind;
12512 C
:= Build_C
(Loc
, Decls
);
12514 -- Because the analysis of all statements was disabled, manually
12515 -- analyze the delay statement.
12518 D_Stat
:= Original_Node
(D_Stat
);
12521 -- Build an entry call using Simple_Entry_Call
12523 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
12524 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
12526 Decls
:= Declarations
(E_Call
);
12527 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
12536 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
12539 Make_Object_Declaration
(Loc
,
12540 Defining_Identifier
=> B
,
12541 Object_Definition
=>
12542 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
12545 -- Duration and mode processing
12547 D_Type
:= Base_Type
(Etype
(Expression
(D_Stat
)));
12549 -- Use the type of the delay expression (Calendar or Real_Time) to
12550 -- generate the appropriate conversion.
12552 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
12553 D_Disc
:= Make_Integer_Literal
(Loc
, 0);
12554 D_Conv
:= Relocate_Node
(Expression
(D_Stat
));
12556 elsif Is_RTE
(D_Type
, RO_CA_Time
) then
12557 D_Disc
:= Make_Integer_Literal
(Loc
, 1);
12559 Make_Function_Call
(Loc
,
12560 Name
=> New_Occurrence_Of
(RTE
(RO_CA_To_Duration
), Loc
),
12561 Parameter_Associations
=>
12562 New_List
(New_Copy
(Expression
(D_Stat
))));
12564 else pragma Assert
(Is_RTE
(D_Type
, RO_RT_Time
));
12565 D_Disc
:= Make_Integer_Literal
(Loc
, 2);
12567 Make_Function_Call
(Loc
,
12568 Name
=> New_Occurrence_Of
(RTE
(RO_RT_To_Duration
), Loc
),
12569 Parameter_Associations
=>
12570 New_List
(New_Copy
(Expression
(D_Stat
))));
12573 D
:= Make_Temporary
(Loc
, 'D');
12579 Make_Object_Declaration
(Loc
,
12580 Defining_Identifier
=> D
,
12581 Object_Definition
=> New_Occurrence_Of
(Standard_Duration
, Loc
)));
12583 M
:= Make_Temporary
(Loc
, 'M');
12586 -- M : Integer := (0 | 1 | 2);
12589 Make_Object_Declaration
(Loc
,
12590 Defining_Identifier
=> M
,
12591 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
12592 Expression
=> D_Disc
));
12594 -- Parameter block processing
12596 -- Manually create the parameter block for dispatching calls. In the
12597 -- case of entries, the block has already been created during the call
12598 -- to Build_Simple_Entry_Call.
12600 if Is_Disp_Select
then
12602 -- Compute the delay at this stage because the evaluation of its
12603 -- expression must not occur earlier (see ACVC C97302A).
12606 Make_Assignment_Statement
(Loc
,
12607 Name
=> New_Occurrence_Of
(D
, Loc
),
12608 Expression
=> D_Conv
));
12610 -- Tagged kind processing, generate:
12611 -- K : Ada.Tags.Tagged_Kind :=
12612 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12614 K
:= Build_K
(Loc
, Decls
, Obj
);
12616 Blk_Typ
:= Build_Parameter_Block
(Loc
, Actuals
, Formals
, Decls
);
12618 Parameter_Block_Pack
(Loc
, Blk_Typ
, Actuals
, Formals
, Decls
, Stmts
);
12620 -- Dispatch table slot processing, generate:
12623 S
:= Build_S
(Loc
, Decls
);
12626 -- S := Ada.Tags.Get_Offset_Index
12627 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12630 New_List
(Build_S_Assignment
(Loc
, S
, Obj
, Call_Ent
));
12633 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12635 -- where Obj is the controlling formal parameter, S is the dispatch
12636 -- table slot number of the dispatching operation, P is the wrapped
12637 -- parameter block, D is the duration, M is the duration mode, C is
12638 -- the call kind and B is the call status.
12640 Params
:= New_List
;
12642 Append_To
(Params
, New_Copy_Tree
(Obj
));
12643 Append_To
(Params
, New_Occurrence_Of
(S
, Loc
));
12645 Make_Attribute_Reference
(Loc
,
12646 Prefix
=> New_Occurrence_Of
(P
, Loc
),
12647 Attribute_Name
=> Name_Address
));
12648 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12649 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12650 Append_To
(Params
, New_Occurrence_Of
(C
, Loc
));
12651 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12653 Append_To
(Conc_Typ_Stmts
,
12654 Make_Procedure_Call_Statement
(Loc
,
12658 (Etype
(Etype
(Obj
)), Name_uDisp_Timed_Select
), Loc
),
12659 Parameter_Associations
=> Params
));
12662 -- if C = POK_Protected_Entry
12663 -- or else C = POK_Task_Entry
12665 -- Param1 := P.Param1;
12667 -- ParamN := P.ParamN;
12670 Unpack
:= Parameter_Block_Unpack
(Loc
, P
, Actuals
, Formals
);
12672 -- Generate the if statement only when the packed parameters need
12673 -- explicit assignments to their corresponding actuals.
12675 if Present
(Unpack
) then
12676 Append_To
(Conc_Typ_Stmts
,
12677 Make_Implicit_If_Statement
(N
,
12683 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12686 (RTE
(RE_POK_Protected_Entry
), Loc
)),
12690 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12692 New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
))),
12694 Then_Statements
=> Unpack
));
12700 -- if C = POK_Procedure
12701 -- or else C = POK_Protected_Procedure
12702 -- or else C = POK_Task_Procedure
12704 -- <dispatching-call>
12708 N_Stats
:= New_List
(
12709 Make_Implicit_If_Statement
(N
,
12714 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12716 New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
)),
12722 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12724 New_Occurrence_Of
(RTE
(
12725 RE_POK_Protected_Procedure
), Loc
)),
12728 Left_Opnd
=> New_Occurrence_Of
(C
, Loc
),
12731 (RTE
(RE_POK_Task_Procedure
), Loc
)))),
12733 Then_Statements
=> New_List
(E_Call
)));
12735 Append_To
(Conc_Typ_Stmts
,
12736 Make_Implicit_If_Statement
(N
,
12737 Condition
=> New_Occurrence_Of
(B
, Loc
),
12738 Then_Statements
=> N_Stats
));
12741 -- <dispatching-call>;
12745 New_List
(New_Copy_Tree
(E_Call
),
12746 Make_Assignment_Statement
(Loc
,
12747 Name
=> New_Occurrence_Of
(B
, Loc
),
12748 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
12751 -- if K = Ada.Tags.TK_Limited_Tagged
12752 -- or else K = Ada.Tags.TK_Tagged
12760 Make_Implicit_If_Statement
(N
,
12761 Condition
=> Build_Dispatching_Tag_Check
(K
, N
),
12762 Then_Statements
=> Lim_Typ_Stmts
,
12763 Else_Statements
=> Conc_Typ_Stmts
));
12768 -- <triggering-statements>
12770 -- <timed-statements>
12774 Make_Implicit_If_Statement
(N
,
12775 Condition
=> New_Occurrence_Of
(B
, Loc
),
12776 Then_Statements
=> E_Stats
,
12777 Else_Statements
=> D_Stats
));
12780 -- Simple case of a nondispatching trigger. Skip assignments to
12781 -- temporaries created for in-out parameters.
12783 -- This makes unwarranted assumptions about the shape of the expanded
12784 -- tree for the call, and should be cleaned up ???
12786 Stmt
:= First
(Stmts
);
12787 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
12791 -- Compute the delay at this stage because the evaluation of
12792 -- its expression must not occur earlier (see ACVC C97302A).
12794 Insert_Before
(Stmt
,
12795 Make_Assignment_Statement
(Loc
,
12796 Name
=> New_Occurrence_Of
(D
, Loc
),
12797 Expression
=> D_Conv
));
12800 Params
:= Parameter_Associations
(Call
);
12802 -- For a protected type, we build a Timed_Protected_Entry_Call
12804 if Is_Protected_Type
(Etype
(Concval
)) then
12806 -- Create a new call statement
12808 Param
:= First
(Params
);
12809 while Present
(Param
)
12810 and then not Is_RTE
(Etype
(Param
), RE_Call_Modes
)
12815 Dummy
:= Remove_Next
(Next
(Param
));
12817 -- Remove garbage is following the Cancel_Param if present
12819 Dummy
:= Next
(Param
);
12821 -- Remove the mode of the Protected_Entry_Call call, then remove
12822 -- the Communication_Block of the Protected_Entry_Call call, and
12823 -- finally add Duration and a Delay_Mode parameter
12825 pragma Assert
(Present
(Param
));
12826 Rewrite
(Param
, New_Occurrence_Of
(D
, Loc
));
12828 Rewrite
(Dummy
, New_Occurrence_Of
(M
, Loc
));
12830 -- Add a Boolean flag for successful entry call
12832 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12834 case Corresponding_Runtime_Package
(Etype
(Concval
)) is
12835 when System_Tasking_Protected_Objects_Entries
=>
12837 Make_Procedure_Call_Statement
(Loc
,
12840 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
12841 Parameter_Associations
=> Params
));
12844 raise Program_Error
;
12847 -- For the task case, build a Timed_Task_Entry_Call
12850 -- Create a new call statement
12852 Append_To
(Params
, New_Occurrence_Of
(D
, Loc
));
12853 Append_To
(Params
, New_Occurrence_Of
(M
, Loc
));
12854 Append_To
(Params
, New_Occurrence_Of
(B
, Loc
));
12857 Make_Procedure_Call_Statement
(Loc
,
12859 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
12860 Parameter_Associations
=> Params
));
12864 Make_Implicit_If_Statement
(N
,
12865 Condition
=> New_Occurrence_Of
(B
, Loc
),
12866 Then_Statements
=> E_Stats
,
12867 Else_Statements
=> D_Stats
));
12871 Make_Block_Statement
(Loc
,
12872 Declarations
=> Decls
,
12873 Handled_Statement_Sequence
=>
12874 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
12878 -- Some items in Decls used to be in the N_Block in E_Call that is
12879 -- constructed in Expand_Entry_Call, and are now in the new Block
12880 -- into which N has been rewritten. Adjust their scopes to reflect that.
12882 if Nkind
(E_Call
) = N_Block_Statement
then
12883 Obj
:= First_Entity
(Entity
(Identifier
(E_Call
)));
12884 while Present
(Obj
) loop
12885 Set_Scope
(Obj
, Entity
(Identifier
(N
)));
12890 Reset_Scopes_To
(N
, Entity
(Identifier
(N
)));
12891 end Expand_N_Timed_Entry_Call
;
12893 ----------------------------------------
12894 -- Expand_Protected_Body_Declarations --
12895 ----------------------------------------
12897 procedure Expand_Protected_Body_Declarations
12899 Spec_Id
: Entity_Id
)
12902 if No_Run_Time_Mode
then
12903 Error_Msg_CRT
("protected body", N
);
12906 elsif Expander_Active
then
12908 -- Associate discriminals with the first subprogram or entry body to
12911 if Present
(First_Protected_Operation
(Declarations
(N
))) then
12912 Set_Discriminals
(Parent
(Spec_Id
));
12915 end Expand_Protected_Body_Declarations
;
12917 -------------------------
12918 -- External_Subprogram --
12919 -------------------------
12921 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
12922 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
12925 -- The internal and external subprograms follow each other on the entity
12926 -- chain. Note that previously private operations had no separate
12927 -- external subprogram. We now create one in all cases, because a
12928 -- private operation may actually appear in an external call, through
12929 -- a 'Access reference used for a callback.
12931 -- If the operation is a function that returns an anonymous access type,
12932 -- the corresponding itype appears before the operation, and must be
12935 -- This mechanism is fragile, there should be a real link between the
12936 -- two versions of the operation, but there is no place to put it ???
12938 if Is_Access_Type
(Next_Entity
(Subp
)) then
12939 return Next_Entity
(Next_Entity
(Subp
));
12941 return Next_Entity
(Subp
);
12943 end External_Subprogram
;
12945 ------------------------------
12946 -- Extract_Dispatching_Call --
12947 ------------------------------
12949 procedure Extract_Dispatching_Call
12951 Call_Ent
: out Entity_Id
;
12952 Object
: out Entity_Id
;
12953 Actuals
: out List_Id
;
12954 Formals
: out List_Id
)
12956 Call_Nam
: Node_Id
;
12959 pragma Assert
(Nkind
(N
) = N_Procedure_Call_Statement
);
12961 if Present
(Original_Node
(N
)) then
12962 Call_Nam
:= Name
(Original_Node
(N
));
12964 Call_Nam
:= Name
(N
);
12967 -- Retrieve the name of the dispatching procedure. It contains the
12968 -- dispatch table slot number.
12971 case Nkind
(Call_Nam
) is
12972 when N_Identifier
=>
12975 when N_Selected_Component
=>
12976 Call_Nam
:= Selector_Name
(Call_Nam
);
12979 raise Program_Error
;
12983 Actuals
:= Parameter_Associations
(N
);
12984 Call_Ent
:= Entity
(Call_Nam
);
12985 Formals
:= Parameter_Specifications
(Parent
(Call_Ent
));
12986 Object
:= First
(Actuals
);
12988 if Present
(Original_Node
(Object
)) then
12989 Object
:= Original_Node
(Object
);
12992 -- If the type of the dispatching object is an access type then return
12993 -- an explicit dereference of a copy of the object, and note that this
12994 -- is the controlling actual of the call.
12996 if Is_Access_Type
(Etype
(Object
)) then
12998 Make_Explicit_Dereference
(Sloc
(N
), New_Copy_Tree
(Object
));
13000 Set_Is_Controlling_Actual
(Object
);
13002 end Extract_Dispatching_Call
;
13004 -------------------
13005 -- Extract_Entry --
13006 -------------------
13008 procedure Extract_Entry
13010 Concval
: out Node_Id
;
13011 Ename
: out Node_Id
;
13012 Index
: out Node_Id
)
13014 Nam
: constant Node_Id
:= Name
(N
);
13017 -- For a simple entry, the name is a selected component, with the
13018 -- prefix being the task value, and the selector being the entry.
13020 if Nkind
(Nam
) = N_Selected_Component
then
13021 Concval
:= Prefix
(Nam
);
13022 Ename
:= Selector_Name
(Nam
);
13025 -- For a member of an entry family, the name is an indexed component
13026 -- where the prefix is a selected component, whose prefix in turn is
13027 -- the task value, and whose selector is the entry family. The single
13028 -- expression in the expressions list of the indexed component is the
13029 -- subscript for the family.
13031 else pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
13032 Concval
:= Prefix
(Prefix
(Nam
));
13033 Ename
:= Selector_Name
(Prefix
(Nam
));
13034 Index
:= First
(Expressions
(Nam
));
13037 -- Through indirection, the type may actually be a limited view of a
13038 -- concurrent type. When compiling a call, the non-limited view of the
13039 -- type is visible.
13041 if From_Limited_With
(Etype
(Concval
)) then
13042 Set_Etype
(Concval
, Non_Limited_View
(Etype
(Concval
)));
13046 -------------------
13047 -- Family_Offset --
13048 -------------------
13050 function Family_Offset
13055 Cap
: Boolean) return Node_Id
13061 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
13062 -- If one of the bounds is a reference to a discriminant, replace with
13063 -- corresponding discriminal of type. Within the body of a task retrieve
13064 -- the renamed discriminant by simple visibility, using its generated
13065 -- name. Within a protected object, find the original discriminant and
13066 -- replace it with the discriminal of the current protected operation.
13068 ------------------------------
13069 -- Convert_Discriminant_Ref --
13070 ------------------------------
13072 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
13073 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
13078 if Is_Entity_Name
(Bound
)
13079 and then Ekind
(Entity
(Bound
)) = E_Discriminant
13081 if Is_Task_Type
(Ttyp
) and then Has_Completion
(Ttyp
) then
13082 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13083 Find_Direct_Name
(B
);
13085 elsif Is_Protected_Type
(Ttyp
) then
13086 D
:= First_Discriminant
(Ttyp
);
13087 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
13088 Next_Discriminant
(D
);
13091 B
:= New_Occurrence_Of
(Discriminal
(D
), Loc
);
13094 B
:= New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
13097 elsif Nkind
(Bound
) = N_Attribute_Reference
then
13101 B
:= New_Copy_Tree
(Bound
);
13105 Make_Attribute_Reference
(Loc
,
13106 Attribute_Name
=> Name_Pos
,
13107 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
13108 Expressions
=> New_List
(B
));
13109 end Convert_Discriminant_Ref
;
13111 -- Start of processing for Family_Offset
13114 Real_Hi
:= Convert_Discriminant_Ref
(Hi
);
13115 Real_Lo
:= Convert_Discriminant_Ref
(Lo
);
13118 if Is_Task_Type
(Ttyp
) then
13119 Ityp
:= RTE
(RE_Task_Entry_Index
);
13121 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13125 Make_Attribute_Reference
(Loc
,
13126 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13127 Attribute_Name
=> Name_Min
,
13128 Expressions
=> New_List
(
13130 Make_Integer_Literal
(Loc
, Entry_Family_Bound
- 1)));
13133 Make_Attribute_Reference
(Loc
,
13134 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13135 Attribute_Name
=> Name_Max
,
13136 Expressions
=> New_List
(
13138 Make_Integer_Literal
(Loc
, -Entry_Family_Bound
)));
13141 return Make_Op_Subtract
(Loc
, Real_Hi
, Real_Lo
);
13148 function Family_Size
13153 Cap
: Boolean) return Node_Id
13158 if Is_Task_Type
(Ttyp
) then
13159 Ityp
:= RTE
(RE_Task_Entry_Index
);
13161 Ityp
:= RTE
(RE_Protected_Entry_Index
);
13165 Make_Attribute_Reference
(Loc
,
13166 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
13167 Attribute_Name
=> Name_Max
,
13168 Expressions
=> New_List
(
13170 Left_Opnd
=> Family_Offset
(Loc
, Hi
, Lo
, Ttyp
, Cap
),
13171 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)),
13172 Make_Integer_Literal
(Loc
, 0)));
13175 ----------------------------
13176 -- Find_Enclosing_Context --
13177 ----------------------------
13179 procedure Find_Enclosing_Context
13181 Context
: out Node_Id
;
13182 Context_Id
: out Entity_Id
;
13183 Context_Decls
: out List_Id
)
13186 -- Traverse the parent chain looking for an enclosing body, block,
13187 -- package or return statement.
13189 Context
:= Parent
(N
);
13190 while Present
(Context
) loop
13191 if Nkind
(Context
) in N_Entry_Body
13192 | N_Extended_Return_Statement
13194 | N_Package_Declaration
13195 | N_Subprogram_Body
13200 -- Do not consider block created to protect a list of statements with
13201 -- an Abort_Defer / Abort_Undefer_Direct pair.
13203 elsif Nkind
(Context
) = N_Block_Statement
13204 and then not Is_Abort_Block
(Context
)
13209 Context
:= Parent
(Context
);
13212 pragma Assert
(Present
(Context
));
13214 -- Extract the constituents of the context
13216 if Nkind
(Context
) = N_Extended_Return_Statement
then
13217 Context_Decls
:= Return_Object_Declarations
(Context
);
13218 Context_Id
:= Return_Statement_Entity
(Context
);
13220 -- Package declarations and bodies use a common library-level activation
13221 -- chain or task master, therefore return the package declaration as the
13222 -- proper carrier for the appropriate flag.
13224 elsif Nkind
(Context
) = N_Package_Body
then
13225 Context_Decls
:= Declarations
(Context
);
13226 Context_Id
:= Corresponding_Spec
(Context
);
13227 Context
:= Parent
(Context_Id
);
13229 if Nkind
(Context
) = N_Defining_Program_Unit_Name
then
13230 Context
:= Parent
(Parent
(Context
));
13232 Context
:= Parent
(Context
);
13235 elsif Nkind
(Context
) = N_Package_Declaration
then
13236 Context_Decls
:= Visible_Declarations
(Specification
(Context
));
13237 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13239 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13240 Context_Id
:= Defining_Identifier
(Context_Id
);
13244 if Nkind
(Context
) = N_Block_Statement
then
13245 Context_Id
:= Entity
(Identifier
(Context
));
13247 if No
(Declarations
(Context
)) then
13248 Set_Declarations
(Context
, New_List
);
13251 elsif Nkind
(Context
) = N_Entry_Body
then
13252 Context_Id
:= Defining_Identifier
(Context
);
13254 elsif Nkind
(Context
) = N_Subprogram_Body
then
13255 if Present
(Corresponding_Spec
(Context
)) then
13256 Context_Id
:= Corresponding_Spec
(Context
);
13258 Context_Id
:= Defining_Unit_Name
(Specification
(Context
));
13260 if Nkind
(Context_Id
) = N_Defining_Program_Unit_Name
then
13261 Context_Id
:= Defining_Identifier
(Context_Id
);
13265 elsif Nkind
(Context
) = N_Task_Body
then
13266 Context_Id
:= Corresponding_Spec
(Context
);
13269 raise Program_Error
;
13272 Context_Decls
:= Declarations
(Context
);
13275 pragma Assert
(Present
(Context_Id
));
13276 pragma Assert
(Present
(Context_Decls
));
13277 end Find_Enclosing_Context
;
13279 -----------------------
13280 -- Find_Master_Scope --
13281 -----------------------
13283 function Find_Master_Scope
(E
: Entity_Id
) return Entity_Id
is
13287 -- In Ada 2005, the master is the innermost enclosing scope that is not
13288 -- transient. If the enclosing block is the rewriting of a call or the
13289 -- scope is an extended return statement this is valid master. The
13290 -- master in an extended return is only used within the return, and is
13291 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13292 -- now before that overwriting occurs.
13296 if Ada_Version
>= Ada_2005
then
13297 while Is_Internal
(S
) loop
13298 if Nkind
(Parent
(S
)) = N_Block_Statement
13299 and then Has_Master_Entity
(S
)
13303 elsif Ekind
(S
) = E_Return_Statement
then
13313 end Find_Master_Scope
;
13315 -------------------------------
13316 -- First_Protected_Operation --
13317 -------------------------------
13319 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
13320 First_Op
: Node_Id
;
13323 First_Op
:= First
(D
);
13324 while Present
(First_Op
)
13325 and then Nkind
(First_Op
) not in N_Subprogram_Body | N_Entry_Body
13331 end First_Protected_Operation
;
13333 ---------------------------------------
13334 -- Install_Private_Data_Declarations --
13335 ---------------------------------------
13337 procedure Install_Private_Data_Declarations
13339 Spec_Id
: Entity_Id
;
13340 Conc_Typ
: Entity_Id
;
13341 Body_Nod
: Node_Id
;
13343 Barrier
: Boolean := False;
13344 Family
: Boolean := False)
13346 Is_Protected
: constant Boolean := Is_Protected_Type
(Conc_Typ
);
13349 Insert_Node
: Node_Id
:= Empty
;
13350 Obj_Ent
: Entity_Id
;
13352 procedure Add
(Decl
: Node_Id
);
13353 -- Add a single declaration after Insert_Node. If this is the first
13354 -- addition, Decl is added to the front of Decls and it becomes the
13357 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
;
13358 -- The bounds of an entry index may depend on discriminants, create a
13359 -- reference to the corresponding prival. Otherwise return a duplicate
13360 -- of the original bound.
13366 procedure Add
(Decl
: Node_Id
) is
13368 if No
(Insert_Node
) then
13369 Prepend_To
(Decls
, Decl
);
13371 Insert_After
(Insert_Node
, Decl
);
13374 Insert_Node
:= Decl
;
13377 -------------------
13378 -- Replace_Bound --
13379 -------------------
13381 function Replace_Bound
(Bound
: Node_Id
) return Node_Id
is
13383 if Nkind
(Bound
) = N_Identifier
13384 and then Is_Discriminal
(Entity
(Bound
))
13386 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
13388 return Duplicate_Subexpr
(Bound
);
13392 -- Start of processing for Install_Private_Data_Declarations
13395 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13396 -- formal parameter _O, _object or _task depending on the context.
13398 Obj_Ent
:= Concurrent_Object
(Spec_Id
, Conc_Typ
);
13400 -- Special processing of _O for barrier functions, protected entries
13407 (Ekind
(Spec_Id
) = E_Entry
13408 or else Ekind
(Spec_Id
) = E_Entry_Family
))
13411 Conc_Rec
: constant Entity_Id
:=
13412 Corresponding_Record_Type
(Conc_Typ
);
13413 Typ_Id
: constant Entity_Id
:=
13414 Make_Defining_Identifier
(Loc
,
13415 New_External_Name
(Chars
(Conc_Rec
), 'P'));
13418 -- type prot_typVP is access prot_typV;
13421 Make_Full_Type_Declaration
(Loc
,
13422 Defining_Identifier
=> Typ_Id
,
13424 Make_Access_To_Object_Definition
(Loc
,
13425 Subtype_Indication
=>
13426 New_Occurrence_Of
(Conc_Rec
, Loc
)));
13430 -- _object : prot_typVP := prot_typV (_O);
13433 Make_Object_Declaration
(Loc
,
13434 Defining_Identifier
=>
13435 Make_Defining_Identifier
(Loc
, Name_uObject
),
13436 Object_Definition
=> New_Occurrence_Of
(Typ_Id
, Loc
),
13438 Unchecked_Convert_To
(Typ_Id
,
13439 New_Occurrence_Of
(Obj_Ent
, Loc
)));
13442 -- Set the reference to the concurrent object
13444 Obj_Ent
:= Defining_Identifier
(Decl
);
13448 -- Step 2: Create the Protection object and build its declaration for
13449 -- any protected entry (family) of subprogram. Note for the lock-free
13450 -- implementation, the Protection object is not needed anymore.
13452 if Is_Protected
and then not Uses_Lock_Free
(Conc_Typ
) then
13454 Prot_Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
13458 Set_Protection_Object
(Spec_Id
, Prot_Ent
);
13460 -- Determine the proper protection type
13462 if Has_Attach_Handler
(Conc_Typ
)
13463 and then not Restricted_Profile
13465 Prot_Typ
:= RE_Static_Interrupt_Protection
;
13467 elsif Has_Interrupt_Handler
(Conc_Typ
)
13468 and then not Restriction_Active
(No_Dynamic_Attachment
)
13470 Prot_Typ
:= RE_Dynamic_Interrupt_Protection
;
13473 case Corresponding_Runtime_Package
(Conc_Typ
) is
13474 when System_Tasking_Protected_Objects_Entries
=>
13475 Prot_Typ
:= RE_Protection_Entries
;
13477 when System_Tasking_Protected_Objects_Single_Entry
=>
13478 Prot_Typ
:= RE_Protection_Entry
;
13480 when System_Tasking_Protected_Objects
=>
13481 Prot_Typ
:= RE_Protection
;
13484 raise Program_Error
;
13489 -- conc_typR : protection_typ renames _object._object;
13492 Make_Object_Renaming_Declaration
(Loc
,
13493 Defining_Identifier
=> Prot_Ent
,
13495 New_Occurrence_Of
(RTE
(Prot_Typ
), Loc
),
13497 Make_Selected_Component
(Loc
,
13498 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13499 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
13505 -- Step 3: Add discriminant renamings (if any)
13507 if Has_Discriminants
(Conc_Typ
) then
13512 D
:= First_Discriminant
(Conc_Typ
);
13513 while Present
(D
) loop
13515 -- Adjust the source location
13517 Set_Sloc
(Discriminal
(D
), Loc
);
13520 -- discr_name : discr_typ renames _object.discr_name;
13522 -- discr_name : discr_typ renames _task.discr_name;
13525 Make_Object_Renaming_Declaration
(Loc
,
13526 Defining_Identifier
=> Discriminal
(D
),
13527 Subtype_Mark
=> New_Occurrence_Of
(Etype
(D
), Loc
),
13529 Make_Selected_Component
(Loc
,
13530 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13531 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
))));
13535 -- Set debug info needed on this renaming declaration even
13536 -- though it does not come from source, so that the debugger
13537 -- will get the right information for these generated names.
13539 Set_Debug_Info_Needed
(Discriminal
(D
));
13541 Next_Discriminant
(D
);
13546 -- Step 4: Add private component renamings (if any)
13548 if Is_Protected
then
13549 Def
:= Protected_Definition
(Parent
(Conc_Typ
));
13551 if Present
(Private_Declarations
(Def
)) then
13554 Comp_Id
: Entity_Id
;
13555 Decl_Id
: Entity_Id
;
13559 Comp
:= First
(Private_Declarations
(Def
));
13560 while Present
(Comp
) loop
13561 if Nkind
(Comp
) = N_Component_Declaration
then
13562 Comp_Id
:= Defining_Identifier
(Comp
);
13563 Nam
:= Chars
(Comp_Id
);
13564 Decl_Id
:= Make_Defining_Identifier
(Sloc
(Comp_Id
), Nam
);
13566 -- Minimal decoration
13568 if Ekind
(Spec_Id
) = E_Function
then
13569 Mutate_Ekind
(Decl_Id
, E_Constant
);
13571 Mutate_Ekind
(Decl_Id
, E_Variable
);
13574 Set_Prival
(Comp_Id
, Decl_Id
);
13575 Set_Prival_Link
(Decl_Id
, Comp_Id
);
13576 Set_Is_Aliased
(Decl_Id
, Is_Aliased
(Comp_Id
));
13577 Set_Is_Independent
(Decl_Id
, Is_Independent
(Comp_Id
));
13579 -- Copy the Comes_From_Source flag of the component, as
13580 -- the renaming may be the only entity directly seen by
13581 -- the user in the context, but do not warn for it.
13583 Set_Comes_From_Source
13584 (Decl_Id
, Comes_From_Source
(Comp_Id
));
13585 Set_Warnings_Off
(Decl_Id
);
13588 -- comp_name : comp_typ renames _object.comp_name;
13591 Make_Object_Renaming_Declaration
(Loc
,
13592 Defining_Identifier
=> Decl_Id
,
13594 New_Occurrence_Of
(Etype
(Comp_Id
), Loc
),
13596 Make_Selected_Component
(Loc
,
13597 Prefix
=> New_Occurrence_Of
(Obj_Ent
, Loc
),
13598 Selector_Name
=> Make_Identifier
(Loc
, Nam
)));
13609 -- Step 5: Add the declaration of the entry index and the associated
13610 -- type for barrier functions and entry families.
13612 if (Barrier
and Family
) or else Ekind
(Spec_Id
) = E_Entry_Family
then
13614 E
: constant Entity_Id
:= Index_Object
(Spec_Id
);
13615 Index
: constant Entity_Id
:=
13616 Defining_Identifier
13617 (Entry_Index_Specification
13618 (Entry_Body_Formal_Part
(Body_Nod
)));
13619 Index_Con
: constant Entity_Id
:=
13620 Make_Defining_Identifier
(Loc
, Chars
(Index
));
13622 Index_Typ
: Entity_Id
;
13626 -- Minimal decoration
13628 Mutate_Ekind
(Index_Con
, E_Constant
);
13629 Set_Entry_Index_Constant
(Index
, Index_Con
);
13630 Set_Discriminal_Link
(Index_Con
, Index
);
13632 -- Retrieve the bounds of the entry family
13634 High
:= Type_High_Bound
(Etype
(Index
));
13635 Low
:= Type_Low_Bound
(Etype
(Index
));
13637 -- In the simple case the entry family is given by a subtype mark
13638 -- and the index constant has the same type.
13640 if Is_Entity_Name
(Original_Node
(
13641 Discrete_Subtype_Definition
(Parent
(Index
))))
13643 Index_Typ
:= Etype
(Index
);
13645 -- Otherwise a new subtype declaration is required
13648 High
:= Replace_Bound
(High
);
13649 Low
:= Replace_Bound
(Low
);
13651 Index_Typ
:= Make_Temporary
(Loc
, 'J');
13654 -- subtype Jnn is <Etype of Index> range Low .. High;
13657 Make_Subtype_Declaration
(Loc
,
13658 Defining_Identifier
=> Index_Typ
,
13659 Subtype_Indication
=>
13660 Make_Subtype_Indication
(Loc
,
13662 New_Occurrence_Of
(Base_Type
(Etype
(Index
)), Loc
),
13664 Make_Range_Constraint
(Loc
,
13665 Range_Expression
=>
13666 Make_Range
(Loc
, Low
, High
))));
13670 Set_Etype
(Index_Con
, Index_Typ
);
13672 -- Create the object which designates the index:
13673 -- J : constant Jnn :=
13674 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13676 -- where Jnn is the subtype created above or the original type of
13677 -- the index, _E is a formal of the protected body subprogram and
13678 -- <index expr> is the index of the first family member.
13681 Make_Object_Declaration
(Loc
,
13682 Defining_Identifier
=> Index_Con
,
13683 Constant_Present
=> True,
13684 Object_Definition
=>
13685 New_Occurrence_Of
(Index_Typ
, Loc
),
13688 Make_Attribute_Reference
(Loc
,
13690 New_Occurrence_Of
(Index_Typ
, Loc
),
13691 Attribute_Name
=> Name_Val
,
13693 Expressions
=> New_List
(
13697 Make_Op_Subtract
(Loc
,
13698 Left_Opnd
=> New_Occurrence_Of
(E
, Loc
),
13700 Entry_Index_Expression
(Loc
,
13701 Defining_Identifier
(Body_Nod
),
13705 Make_Attribute_Reference
(Loc
,
13707 New_Occurrence_Of
(Index_Typ
, Loc
),
13708 Attribute_Name
=> Name_Pos
,
13709 Expressions
=> New_List
(
13710 Make_Attribute_Reference
(Loc
,
13712 New_Occurrence_Of
(Index_Typ
, Loc
),
13713 Attribute_Name
=> Name_First
)))))));
13717 end Install_Private_Data_Declarations
;
13719 ---------------------------------
13720 -- Is_Potentially_Large_Family --
13721 ---------------------------------
13723 function Is_Potentially_Large_Family
13724 (Base_Index
: Entity_Id
;
13725 Conctyp
: Entity_Id
;
13727 Hi
: Node_Id
) return Boolean
13730 return Scope
(Base_Index
) = Standard_Standard
13731 and then Base_Index
= Base_Type
(Standard_Integer
)
13732 and then Has_Defaulted_Discriminants
(Conctyp
)
13734 (Denotes_Discriminant
(Lo
, True)
13736 Denotes_Discriminant
(Hi
, True));
13737 end Is_Potentially_Large_Family
;
13739 -------------------------------------
13740 -- Is_Private_Primitive_Subprogram --
13741 -------------------------------------
13743 function Is_Private_Primitive_Subprogram
(Id
: Entity_Id
) return Boolean is
13746 (Ekind
(Id
) = E_Function
or else Ekind
(Id
) = E_Procedure
)
13747 and then Is_Private_Primitive
(Id
);
13748 end Is_Private_Primitive_Subprogram
;
13754 function Index_Object
(Spec_Id
: Entity_Id
) return Entity_Id
is
13755 Bod_Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(Spec_Id
);
13756 Formal
: Entity_Id
;
13759 Formal
:= First_Formal
(Bod_Subp
);
13760 while Present
(Formal
) loop
13762 -- Look for formal parameter _E
13764 if Chars
(Formal
) = Name_uE
then
13768 Next_Formal
(Formal
);
13771 -- A protected body subprogram should always have the parameter in
13774 raise Program_Error
;
13777 --------------------------------
13778 -- Make_Initialize_Protection --
13779 --------------------------------
13781 function Make_Initialize_Protection
13782 (Protect_Rec
: Entity_Id
) return List_Id
13784 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
13787 Ptyp
: constant Node_Id
:=
13788 Corresponding_Concurrent_Type
(Protect_Rec
);
13790 L
: constant List_Id
:= New_List
;
13791 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
13792 Prio_Type
: Entity_Id
;
13793 Prio_Var
: Entity_Id
:= Empty
;
13794 Restricted
: constant Boolean := Restricted_Profile
;
13797 -- We may need two calls to properly initialize the object, one to
13798 -- Initialize_Protection, and possibly one to Install_Handlers if we
13799 -- have a pragma Attach_Handler.
13801 -- Get protected declaration. In the case of a task type declaration,
13802 -- this is simply the parent of the protected type entity. In the single
13803 -- protected object declaration, this parent will be the implicit type,
13804 -- and we can find the corresponding single protected object declaration
13805 -- by searching forward in the declaration list in the tree.
13807 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13808 -- of this type should have been removed during semantic analysis.
13810 Pdec
:= Parent
(Ptyp
);
13811 while Nkind
(Pdec
) not in
13812 N_Protected_Type_Declaration | N_Single_Protected_Declaration
13817 -- Build the parameter list for the call. Note that _Init is the name
13818 -- of the formal for the object to be initialized, which is the task
13819 -- value record itself.
13823 -- For lock-free implementation, skip initializations of the Protection
13826 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
13828 -- Object parameter. This is a pointer to the object of type
13829 -- Protection used by the GNARL to control the protected object.
13832 Make_Attribute_Reference
(Loc
,
13834 Make_Selected_Component
(Loc
,
13835 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13836 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
13837 Attribute_Name
=> Name_Unchecked_Access
));
13839 -- Priority parameter. Set to Unspecified_Priority unless there is a
13840 -- Priority rep item, in which case we take the value from the pragma
13841 -- or attribute definition clause, or there is an Interrupt_Priority
13842 -- rep item and no Priority rep item, and we set the ceiling to
13843 -- Interrupt_Priority'Last, an implementation-defined value, see
13846 if Has_Rep_Item
(Ptyp
, Name_Priority
, Check_Parents
=> False) then
13848 Prio_Clause
: constant Node_Id
:=
13850 (Ptyp
, Name_Priority
, Check_Parents
=> False);
13857 if Nkind
(Prio_Clause
) = N_Pragma
then
13860 (First
(Pragma_Argument_Associations
(Prio_Clause
)));
13862 -- Get_Rep_Item returns either priority pragma
13864 if Pragma_Name
(Prio_Clause
) = Name_Priority
then
13865 Prio_Type
:= RTE
(RE_Any_Priority
);
13867 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13870 -- Attribute definition clause Priority
13873 if Chars
(Prio_Clause
) = Name_Priority
then
13874 Prio_Type
:= RTE
(RE_Any_Priority
);
13876 Prio_Type
:= RTE
(RE_Interrupt_Priority
);
13879 Prio
:= Expression
(Prio_Clause
);
13882 -- Always create a locale variable to capture the priority.
13883 -- The priority is also passed to Install_Restriced_Handlers.
13884 -- Note that it is really necessary to create this variable
13885 -- explicitly. It might be thought that removing side effects
13886 -- would the appropriate approach, but that could generate
13887 -- declarations improperly placed in the enclosing scope.
13889 Prio_Var
:= Make_Temporary
(Loc
, 'R', Prio
);
13891 Make_Object_Declaration
(Loc
,
13892 Defining_Identifier
=> Prio_Var
,
13893 Object_Definition
=> New_Occurrence_Of
(Prio_Type
, Loc
),
13894 Expression
=> Relocate_Node
(Prio
)));
13896 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
13899 -- When no priority is specified but an xx_Handler pragma is, we
13900 -- default to System.Interrupts.Default_Interrupt_Priority, see
13903 elsif Has_Attach_Handler
(Ptyp
)
13904 or else Has_Interrupt_Handler
(Ptyp
)
13907 New_Occurrence_Of
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
13909 -- Normal case, no priority or xx_Handler specified, default priority
13913 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
13916 -- Deadline_Floor parameter for GNAT_Ravenscar_EDF runtimes
13918 if Restricted_Profile
and Task_Dispatching_Policy
= 'E' then
13919 Deadline_Floor
: declare
13920 Item
: constant Node_Id
:=
13922 (Ptyp
, Name_Deadline_Floor
, Check_Parents
=> False);
13924 Deadline
: Node_Id
;
13927 if Present
(Item
) then
13929 -- Pragma Deadline_Floor
13931 if Nkind
(Item
) = N_Pragma
then
13934 (First
(Pragma_Argument_Associations
(Item
)));
13936 -- Attribute definition clause Deadline_Floor
13940 (Nkind
(Item
) = N_Attribute_Definition_Clause
);
13942 Deadline
:= Expression
(Item
);
13945 Append_To
(Args
, Deadline
);
13947 -- Unusual case: default deadline
13951 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
13953 end Deadline_Floor
;
13956 -- Test for Compiler_Info parameter. This parameter allows entry body
13957 -- procedures and barrier functions to be called from the runtime. It
13958 -- is a pointer to the record generated by the compiler to represent
13959 -- the protected object.
13961 -- A protected type without entries that covers an interface and
13962 -- overrides the abstract routines with protected procedures is
13963 -- considered equivalent to a protected type with entries in the
13964 -- context of dispatching select statements.
13966 -- Protected types with interrupt handlers (when not using a
13967 -- restricted profile) are also considered equivalent to protected
13968 -- types with entries.
13970 -- The types which are used (Static_Interrupt_Protection and
13971 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13974 Pkg_Id
: constant RTU_Id
:= Corresponding_Runtime_Package
(Ptyp
);
13976 Called_Subp
: RE_Id
;
13980 when System_Tasking_Protected_Objects_Entries
=>
13981 Called_Subp
:= RE_Initialize_Protection_Entries
;
13983 -- Argument Compiler_Info
13986 Make_Attribute_Reference
(Loc
,
13987 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13988 Attribute_Name
=> Name_Address
));
13990 when System_Tasking_Protected_Objects_Single_Entry
=>
13991 Called_Subp
:= RE_Initialize_Protection_Entry
;
13993 -- Argument Compiler_Info
13996 Make_Attribute_Reference
(Loc
,
13997 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
13998 Attribute_Name
=> Name_Address
));
14000 when System_Tasking_Protected_Objects
=>
14001 Called_Subp
:= RE_Initialize_Protection
;
14004 raise Program_Error
;
14007 -- Entry_Queue_Maxes parameter. This is an access to an array of
14008 -- naturals representing the entry queue maximums for each entry
14009 -- in the protected type. Zero represents no max. The access is
14010 -- null if there is no limit for all entries (usual case).
14013 and then Pkg_Id
= System_Tasking_Protected_Objects_Entries
14015 if Present
(Entry_Max_Queue_Lengths_Array
(Ptyp
)) then
14017 Make_Attribute_Reference
(Loc
,
14020 (Entry_Max_Queue_Lengths_Array
(Ptyp
), Loc
),
14021 Attribute_Name
=> Name_Unrestricted_Access
));
14023 Append_To
(Args
, Make_Null
(Loc
));
14026 -- Edge cases exist where entry initialization functions are
14027 -- called, but no entries exist, so null is appended.
14029 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
14030 Append_To
(Args
, Make_Null
(Loc
));
14033 -- Entry_Bodies parameter. This is a pointer to an array of
14034 -- pointers to the entry body procedures and barrier functions of
14035 -- the object. If the protected type has no entries this object
14036 -- will not exist, in this case, pass a null (it can happen when
14037 -- there are protected interrupt handlers or interfaces).
14040 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
14042 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
14043 -- multiple entries).
14046 Make_Attribute_Reference
(Loc
,
14047 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
14048 Attribute_Name
=> Name_Unrestricted_Access
));
14050 if Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
14052 -- Find index mapping function (clumsy but ok for now)
14054 while Ekind
(P_Arr
) /= E_Function
loop
14055 Next_Entity
(P_Arr
);
14059 Make_Attribute_Reference
(Loc
,
14060 Prefix
=> New_Occurrence_Of
(P_Arr
, Loc
),
14061 Attribute_Name
=> Name_Unrestricted_Access
));
14064 elsif Pkg_Id
= System_Tasking_Protected_Objects_Single_Entry
then
14066 -- This is the case where we have a protected object with
14067 -- interfaces and no entries, and the single entry restriction
14068 -- is in effect. We pass a null pointer for the entry
14069 -- parameter because there is no actual entry.
14071 Append_To
(Args
, Make_Null
(Loc
));
14073 elsif Pkg_Id
= System_Tasking_Protected_Objects_Entries
then
14075 -- This is the case where we have a protected object with no
14077 -- - either interrupt handlers with non restricted profile,
14079 -- Note that the types which are used for interrupt handlers
14080 -- (Static/Dynamic_Interrupt_Protection) are derived from
14081 -- Protection_Entries. We pass two null pointers because there
14082 -- is no actual entry, and the initialization procedure needs
14083 -- both Entry_Bodies and Find_Body_Index.
14085 Append_To
(Args
, Make_Null
(Loc
));
14086 Append_To
(Args
, Make_Null
(Loc
));
14090 Make_Procedure_Call_Statement
(Loc
,
14092 New_Occurrence_Of
(RTE
(Called_Subp
), Loc
),
14093 Parameter_Associations
=> Args
));
14097 if Has_Attach_Handler
(Ptyp
) then
14099 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
14100 -- make the following call:
14102 -- Install_Handlers (_object,
14103 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
14105 -- or, in the case of Ravenscar:
14107 -- Install_Restricted_Handlers
14108 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
14111 Args
: constant List_Id
:= New_List
;
14112 Table
: constant List_Id
:= New_List
;
14113 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
14116 -- Build the Priority parameter (only for ravenscar)
14120 -- Priority comes from a pragma
14122 if Present
(Prio_Var
) then
14123 Append_To
(Args
, New_Occurrence_Of
(Prio_Var
, Loc
));
14125 -- Priority is the default one
14130 (RTE
(RE_Default_Interrupt_Priority
), Loc
));
14134 -- Build the Attach_Handler table argument
14136 while Present
(Ritem
) loop
14137 if Nkind
(Ritem
) = N_Pragma
14138 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
14141 Handler
: constant Node_Id
:=
14142 First
(Pragma_Argument_Associations
(Ritem
));
14144 Interrupt
: constant Node_Id
:= Next
(Handler
);
14145 Expr
: constant Node_Id
:= Expression
(Interrupt
);
14149 Make_Aggregate
(Loc
, Expressions
=> New_List
(
14150 Unchecked_Convert_To
14151 (RTE
(RE_System_Interrupt_Id
), Expr
),
14152 Make_Attribute_Reference
(Loc
,
14154 Make_Selected_Component
(Loc
,
14156 Make_Identifier
(Loc
, Name_uInit
),
14158 Duplicate_Subexpr_No_Checks
14159 (Expression
(Handler
))),
14160 Attribute_Name
=> Name_Access
))));
14164 Next_Rep_Item
(Ritem
);
14167 -- Append the table argument we just built
14169 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
14171 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14172 -- call to the statements.
14175 -- Call a simplified version of Install_Handlers to be used
14176 -- when the Ravenscar restrictions are in effect
14177 -- (Install_Restricted_Handlers).
14180 Make_Procedure_Call_Statement
(Loc
,
14183 (RTE
(RE_Install_Restricted_Handlers
), Loc
),
14184 Parameter_Associations
=> Args
));
14187 if not Uses_Lock_Free
(Defining_Identifier
(Pdec
)) then
14189 -- First, prepends the _object argument
14192 Make_Attribute_Reference
(Loc
,
14194 Make_Selected_Component
(Loc
,
14195 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14197 Make_Identifier
(Loc
, Name_uObject
)),
14198 Attribute_Name
=> Name_Unchecked_Access
));
14201 -- Then, insert call to Install_Handlers
14204 Make_Procedure_Call_Statement
(Loc
,
14206 New_Occurrence_Of
(RTE
(RE_Install_Handlers
), Loc
),
14207 Parameter_Associations
=> Args
));
14213 end Make_Initialize_Protection
;
14215 ---------------------------
14216 -- Make_Task_Create_Call --
14217 ---------------------------
14219 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
14220 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
14230 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
14231 Tnam
:= Chars
(Ttyp
);
14233 -- Get task declaration. In the case of a task type declaration, this is
14234 -- simply the parent of the task type entity. In the single task
14235 -- declaration, this parent will be the implicit type, and we can find
14236 -- the corresponding single task declaration by searching forward in the
14237 -- declaration list in the tree.
14239 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14240 -- this type should have been removed during semantic analysis.
14242 Tdec
:= Parent
(Ttyp
);
14243 while Nkind
(Tdec
) not in
14244 N_Task_Type_Declaration | N_Single_Task_Declaration
14249 -- Now we can find the task definition from this declaration
14251 Tdef
:= Task_Definition
(Tdec
);
14253 -- Build the parameter list for the call. Note that _Init is the name
14254 -- of the formal for the object to be initialized, which is the task
14255 -- value record itself.
14259 -- Priority parameter. Set to Unspecified_Priority unless there is a
14260 -- Priority rep item, in which case we take the value from the rep item.
14261 -- Not used on Ravenscar_EDF profile.
14263 if not (Restricted_Profile
and then Task_Dispatching_Policy
= 'E') then
14264 if Has_Rep_Item
(Ttyp
, Name_Priority
, Check_Parents
=> False) then
14266 Make_Selected_Component
(Loc
,
14267 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14268 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
14271 New_Occurrence_Of
(RTE
(RE_Unspecified_Priority
), Loc
));
14275 -- Optional Stack parameter
14277 if Restricted_Profile
then
14279 -- If the stack has been preallocated by the expander then
14280 -- pass its address. Otherwise, pass a null address.
14282 if Preallocated_Stacks_On_Target
then
14284 Make_Attribute_Reference
(Loc
,
14286 Make_Selected_Component
(Loc
,
14287 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14288 Selector_Name
=> Make_Identifier
(Loc
, Name_uStack
)),
14289 Attribute_Name
=> Name_Address
));
14293 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
14297 -- Size parameter. If no Storage_Size pragma is present, then
14298 -- the size is taken from the taskZ variable for the type, which
14299 -- is either Unspecified_Size, or has been reset by the use of
14300 -- a Storage_Size attribute definition clause. If a pragma is
14301 -- present, then the size is taken from the _Size field of the
14302 -- task value record, which was set from the pragma value.
14304 if Present
(Tdef
) and then Has_Storage_Size_Pragma
(Tdef
) then
14306 Make_Selected_Component
(Loc
,
14307 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14308 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
14312 New_Occurrence_Of
(Storage_Size_Variable
(Ttyp
), Loc
));
14315 -- Secondary_Stack parameter used for restricted profiles
14317 if Restricted_Profile
then
14319 -- If the secondary stack has been allocated by the expander then
14320 -- pass its access pointer. Otherwise, pass null.
14322 if Create_Secondary_Stack_For_Task
(Ttyp
) then
14324 Make_Attribute_Reference
(Loc
,
14326 Make_Selected_Component
(Loc
,
14327 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14329 Make_Identifier
(Loc
, Name_uSecondary_Stack
)),
14330 Attribute_Name
=> Name_Unrestricted_Access
));
14333 Append_To
(Args
, Make_Null
(Loc
));
14337 -- Secondary_Stack_Size parameter. Set RE_Unspecified_Size unless there
14338 -- is a Secondary_Stack_Size pragma, in which case take the value from
14339 -- the pragma. If the restriction No_Secondary_Stack is active then a
14340 -- size of 0 is passed regardless to prevent the allocation of the
14343 if Restriction_Active
(No_Secondary_Stack
) then
14344 Append_To
(Args
, Make_Integer_Literal
(Loc
, 0));
14346 elsif Has_Rep_Pragma
14347 (Ttyp
, Name_Secondary_Stack_Size
, Check_Parents
=> False)
14350 Make_Selected_Component
(Loc
,
14351 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14353 Make_Identifier
(Loc
, Name_uSecondary_Stack_Size
)));
14357 New_Occurrence_Of
(RTE
(RE_Unspecified_Size
), Loc
));
14360 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14361 -- Task_Info pragma, in which case we take the value from the pragma.
14363 if Has_Rep_Pragma
(Ttyp
, Name_Task_Info
, Check_Parents
=> False) then
14365 Make_Selected_Component
(Loc
,
14366 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14367 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
14371 New_Occurrence_Of
(RTE
(RE_Unspecified_Task_Info
), Loc
));
14374 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14375 -- in which case we take the value from the rep item. The parameter is
14376 -- passed as an Integer because in the case of unspecified CPU the
14377 -- value is not in the range of CPU_Range.
14379 if Has_Rep_Item
(Ttyp
, Name_CPU
, Check_Parents
=> False) then
14381 Convert_To
(Standard_Integer
,
14382 Make_Selected_Component
(Loc
,
14383 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14384 Selector_Name
=> Make_Identifier
(Loc
, Name_uCPU
))));
14387 New_Occurrence_Of
(RTE
(RE_Unspecified_CPU
), Loc
));
14390 if not Restricted_Profile
or else Task_Dispatching_Policy
= 'E' then
14392 -- Deadline parameter. If no Relative_Deadline pragma is present,
14393 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14394 -- the deadline is taken from the _Relative_Deadline field of the
14395 -- task value record, which was set from the pragma value. Note that
14396 -- this parameter must not be generated for the restricted profiles
14397 -- since Ravenscar does not allow deadlines.
14399 -- Case where pragma Relative_Deadline applies: use given value
14401 if Present
(Tdef
) and then Has_Relative_Deadline_Pragma
(Tdef
) then
14403 Make_Selected_Component
(Loc
,
14404 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14406 Make_Identifier
(Loc
, Name_uRelative_Deadline
)));
14408 -- No pragma Relative_Deadline apply to the task
14412 New_Occurrence_Of
(RTE
(RE_Time_Span_Zero
), Loc
));
14416 if not Restricted_Profile
then
14418 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14419 -- present, then the dispatching domain is null. If a rep item is
14420 -- present, then the dispatching domain is taken from the
14421 -- _Dispatching_Domain field of the task value record, which was set
14422 -- from the rep item value.
14424 -- Case where Dispatching_Domain rep item applies: use given value
14427 (Ttyp
, Name_Dispatching_Domain
, Check_Parents
=> False)
14430 Make_Selected_Component
(Loc
,
14432 Make_Identifier
(Loc
, Name_uInit
),
14434 Make_Identifier
(Loc
, Name_uDispatching_Domain
)));
14436 -- No pragma or aspect Dispatching_Domain applies to the task
14439 Append_To
(Args
, Make_Null
(Loc
));
14442 -- Number of entries. This is an expression of the form:
14444 -- n + _Init.a'Length + _Init.a'B'Length + ...
14446 -- where a,b... are the entry family names for the task definition
14448 Ecount
:= Build_Entry_Count_Expression
(Ttyp
, Loc
);
14449 Append_To
(Args
, Ecount
);
14451 -- Master parameter. This is a reference to the _Master parameter of
14452 -- the initialization procedure, except in the case of the pragma
14453 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14454 -- System.Tasking.Library_Task_Level.
14456 if Restriction_Active
(No_Task_Hierarchy
) = False then
14457 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
14459 Append_To
(Args
, Make_Integer_Literal
(Loc
, Library_Task_Level
));
14463 -- State parameter. This is a pointer to the task body procedure. The
14464 -- required value is obtained by taking 'Unrestricted_Access of the task
14465 -- body procedure and converting it (with an unchecked conversion) to
14466 -- the type required by the task kernel. For further details, see the
14467 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14468 -- than 'Address in order to avoid creating trampolines.
14471 Body_Proc
: constant Node_Id
:= Get_Task_Body_Procedure
(Ttyp
);
14472 Subp_Ptr_Typ
: constant Node_Id
:=
14473 Create_Itype
(E_Access_Subprogram_Type
, Tdec
);
14474 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
14477 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Body_Proc
);
14478 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
14480 -- Be sure to freeze a reference to the access-to-subprogram type,
14481 -- otherwise gigi will complain that it's in the wrong scope, because
14482 -- it's actually inside the init procedure for the record type that
14483 -- corresponds to the task type.
14485 Set_Itype
(Ref
, Subp_Ptr_Typ
);
14486 Append_Freeze_Action
(Task_Rec
, Ref
);
14489 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
14490 Make_Qualified_Expression
(Loc
,
14491 Subtype_Mark
=> New_Occurrence_Of
(Subp_Ptr_Typ
, Loc
),
14493 Make_Attribute_Reference
(Loc
,
14494 Prefix
=> New_Occurrence_Of
(Body_Proc
, Loc
),
14495 Attribute_Name
=> Name_Unrestricted_Access
))));
14498 -- Discriminants parameter. This is just the address of the task
14499 -- value record itself (which contains the discriminant values
14502 Make_Attribute_Reference
(Loc
,
14503 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14504 Attribute_Name
=> Name_Address
));
14506 -- Elaborated parameter. This is an access to the elaboration Boolean
14509 Make_Attribute_Reference
(Loc
,
14510 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
14511 Attribute_Name
=> Name_Unchecked_Access
));
14513 -- Add Chain parameter (not done for sequential elaboration policy, see
14514 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14516 if Partition_Elaboration_Policy
/= 'S' then
14517 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
14520 -- Task name parameter. Take this from the _Task_Id parameter to the
14521 -- init call unless there is a Task_Name pragma, in which case we take
14522 -- the value from the pragma.
14524 if Has_Rep_Pragma
(Ttyp
, Name_Task_Name
, Check_Parents
=> False) then
14525 -- Copy expression in full, because it may be dynamic and have
14532 (Pragma_Argument_Associations
14534 (Ttyp
, Name_Task_Name
, Check_Parents
=> False))))));
14537 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
14540 -- Created_Task parameter. This is the _Task_Id field of the task
14544 Make_Selected_Component
(Loc
,
14545 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
14546 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
14552 if Restricted_Profile
then
14553 if Partition_Elaboration_Policy
= 'S' then
14554 Create_RE
:= RE_Create_Restricted_Task_Sequential
;
14556 Create_RE
:= RE_Create_Restricted_Task
;
14559 Create_RE
:= RE_Create_Task
;
14562 Name
:= New_Occurrence_Of
(RTE
(Create_RE
), Loc
);
14566 Make_Procedure_Call_Statement
(Loc
,
14568 Parameter_Associations
=> Args
);
14569 end Make_Task_Create_Call
;
14571 ------------------------------
14572 -- Next_Protected_Operation --
14573 ------------------------------
14575 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
14579 -- Check whether there is a subsequent body for a protected operation
14580 -- in the current protected body. In Ada2012 that includes expression
14581 -- functions that are completions.
14583 Next_Op
:= Next
(N
);
14584 while Present
(Next_Op
)
14585 and then Nkind
(Next_Op
) not in
14586 N_Subprogram_Body | N_Entry_Body | N_Expression_Function
14592 end Next_Protected_Operation
;
14594 ---------------------
14595 -- Null_Statements --
14596 ---------------------
14598 function Null_Statements
(Stats
: List_Id
) return Boolean is
14602 Stmt
:= First
(Stats
);
14603 while Nkind
(Stmt
) /= N_Empty
14604 and then (Nkind
(Stmt
) in N_Null_Statement | N_Label
14606 (Nkind
(Stmt
) = N_Pragma
14608 Pragma_Name_Unmapped
(Stmt
) in Name_Unreferenced
14615 return Nkind
(Stmt
) = N_Empty
;
14616 end Null_Statements
;
14618 --------------------------
14619 -- Parameter_Block_Pack --
14620 --------------------------
14622 function Parameter_Block_Pack
14624 Blk_Typ
: Entity_Id
;
14628 Stmts
: List_Id
) return Entity_Id
14630 Actual
: Entity_Id
;
14631 Expr
: Node_Id
:= Empty
;
14632 Formal
: Entity_Id
;
14633 Has_Param
: Boolean := False;
14636 Temp_Asn
: Node_Id
;
14637 Temp_Nam
: Node_Id
;
14640 Actual
:= First
(Actuals
);
14641 Formal
:= Defining_Identifier
(First
(Formals
));
14642 Params
:= New_List
;
14643 while Present
(Actual
) loop
14644 if Is_By_Copy_Type
(Etype
(Actual
)) then
14646 -- Jnn : aliased <formal-type>
14648 Temp_Nam
:= Make_Temporary
(Loc
, 'J');
14651 Make_Object_Declaration
(Loc
,
14652 Aliased_Present
=> True,
14653 Defining_Identifier
=> Temp_Nam
,
14654 Object_Definition
=>
14655 New_Occurrence_Of
(Etype
(Formal
), Loc
)));
14657 -- The object is initialized with an explicit assignment
14658 -- later. Indicate that it does not need an initialization
14659 -- to prevent spurious warnings if the type excludes null.
14661 Set_No_Initialization
(Last
(Decls
));
14663 if Ekind
(Formal
) /= E_Out_Parameter
then
14669 New_Occurrence_Of
(Temp_Nam
, Loc
);
14671 Set_Assignment_OK
(Temp_Asn
);
14674 Make_Assignment_Statement
(Loc
,
14676 Expression
=> New_Copy_Tree
(Actual
)));
14679 -- If the actual is not controlling, generate:
14681 -- Jnn'unchecked_access
14683 -- and add it to aggegate for access to formals. Note that the
14684 -- actual may be by-copy but still be a controlling actual if it
14685 -- is an access to class-wide interface.
14687 if not Is_Controlling_Actual
(Actual
) then
14689 Make_Attribute_Reference
(Loc
,
14690 Attribute_Name
=> Name_Unchecked_Access
,
14691 Prefix
=> New_Occurrence_Of
(Temp_Nam
, Loc
)));
14696 -- The controlling parameter is omitted
14699 if not Is_Controlling_Actual
(Actual
) then
14701 Make_Reference
(Loc
, New_Copy_Tree
(Actual
)));
14707 Next_Actual
(Actual
);
14708 Next_Formal_With_Extras
(Formal
);
14712 Expr
:= Make_Aggregate
(Loc
, Params
);
14717 -- J1'unchecked_access;
14718 -- <actual2>'reference;
14721 P
:= Make_Temporary
(Loc
, 'P');
14724 Make_Object_Declaration
(Loc
,
14725 Defining_Identifier
=> P
,
14726 Object_Definition
=> New_Occurrence_Of
(Blk_Typ
, Loc
),
14727 Expression
=> Expr
));
14730 end Parameter_Block_Pack
;
14732 ----------------------------
14733 -- Parameter_Block_Unpack --
14734 ----------------------------
14736 function Parameter_Block_Unpack
14740 Formals
: List_Id
) return List_Id
14742 Actual
: Entity_Id
;
14744 Formal
: Entity_Id
;
14745 Has_Asnmt
: Boolean := False;
14746 Result
: constant List_Id
:= New_List
;
14749 Actual
:= First
(Actuals
);
14750 Formal
:= Defining_Identifier
(First
(Formals
));
14751 while Present
(Actual
) loop
14752 if Is_By_Copy_Type
(Etype
(Actual
))
14753 and then Ekind
(Formal
) /= E_In_Parameter
14756 -- <actual> := P.<formal>;
14759 Make_Assignment_Statement
(Loc
,
14763 Make_Explicit_Dereference
(Loc
,
14764 Make_Selected_Component
(Loc
,
14766 New_Occurrence_Of
(P
, Loc
),
14768 Make_Identifier
(Loc
, Chars
(Formal
)))));
14770 Set_Assignment_OK
(Name
(Asnmt
));
14771 Append_To
(Result
, Asnmt
);
14776 Next_Actual
(Actual
);
14777 Next_Formal_With_Extras
(Formal
);
14783 return New_List
(Make_Null_Statement
(Loc
));
14785 end Parameter_Block_Unpack
;
14787 ---------------------
14788 -- Reset_Scopes_To --
14789 ---------------------
14791 procedure Reset_Scopes_To
(Bod
: Node_Id
; E
: Entity_Id
) is
14792 function Reset_Scope
(N
: Node_Id
) return Traverse_Result
;
14793 -- Temporaries may have been declared during expansion of the procedure
14794 -- created for an entry body or an accept alternative. Indicate that
14795 -- their scope is the new body, to ensure proper generation of uplevel
14796 -- references where needed during unnesting.
14798 procedure Reset_Scopes
is new Traverse_Proc
(Reset_Scope
);
14804 function Reset_Scope
(N
: Node_Id
) return Traverse_Result
is
14808 -- If this is a block statement with an Identifier, it forms a scope,
14809 -- so we want to reset its scope but not look inside.
14812 and then Nkind
(N
) = N_Block_Statement
14813 and then Present
(Identifier
(N
))
14815 Set_Scope
(Entity
(Identifier
(N
)), E
);
14818 -- Ditto for a package declaration or a full type declaration, etc.
14820 elsif (Nkind
(N
) = N_Package_Declaration
14821 and then N
/= Specification
(N
))
14822 or else Nkind
(N
) in N_Declaration
14823 or else Nkind
(N
) in N_Renaming_Declaration
14825 Set_Scope
(Defining_Entity
(N
), E
);
14830 -- Scan declarations in new body. Declarations in the statement
14831 -- part will be handled during later traversal.
14833 Decl
:= First
(Declarations
(N
));
14834 while Present
(Decl
) loop
14835 Reset_Scopes
(Decl
);
14839 elsif Nkind
(N
) = N_Freeze_Entity
then
14841 -- Scan the actions associated with a freeze node, which may
14842 -- actually be declarations with entities that need to have
14843 -- their scopes reset.
14845 Decl
:= First
(Actions
(N
));
14846 while Present
(Decl
) loop
14847 Reset_Scopes
(Decl
);
14851 elsif N
/= Bod
and then Nkind
(N
) in N_Proper_Body
then
14853 -- A subprogram without a separate declaration may be encountered,
14854 -- and we need to reset the subprogram's entity's scope.
14856 if Nkind
(N
) = N_Subprogram_Body
then
14857 Set_Scope
(Defining_Entity
(Specification
(N
)), E
);
14866 -- Start of processing for Reset_Scopes_To
14869 Reset_Scopes
(Bod
);
14870 end Reset_Scopes_To
;
14872 ----------------------
14873 -- Set_Discriminals --
14874 ----------------------
14876 procedure Set_Discriminals
(Dec
: Node_Id
) is
14879 D_Minal
: Entity_Id
;
14882 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
14883 Pdef
:= Defining_Identifier
(Dec
);
14885 if Has_Discriminants
(Pdef
) then
14886 D
:= First_Discriminant
(Pdef
);
14887 while Present
(D
) loop
14889 Make_Defining_Identifier
(Sloc
(D
),
14890 Chars
=> New_External_Name
(Chars
(D
), 'D'));
14892 Mutate_Ekind
(D_Minal
, E_Constant
);
14893 Set_Etype
(D_Minal
, Etype
(D
));
14894 Set_Scope
(D_Minal
, Pdef
);
14895 Set_Discriminal
(D
, D_Minal
);
14896 Set_Discriminal_Link
(D_Minal
, D
);
14898 Next_Discriminant
(D
);
14901 end Set_Discriminals
;
14903 -----------------------
14904 -- Trivial_Accept_OK --
14905 -----------------------
14907 function Trivial_Accept_OK
return Boolean is
14909 case Opt
.Task_Dispatching_Policy
is
14911 -- If we have the default task dispatching policy in effect, we can
14912 -- definitely do the optimization (one way of looking at this is to
14913 -- think of the formal definition of the default policy being allowed
14914 -- to run any task it likes after a rendezvous, so even if notionally
14915 -- a full rescheduling occurs, we can say that our dispatching policy
14916 -- (i.e. the default dispatching policy) reorders the queue to be the
14917 -- same as just before the call.
14922 -- FIFO_Within_Priorities certainly does not permit this
14923 -- optimization since the Rendezvous is a scheduling action that may
14924 -- require some other task to be run.
14929 -- For now, disallow the optimization for all other policies. This
14930 -- may be over-conservative, but it is certainly not incorrect.
14935 end Trivial_Accept_OK
;