1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Ch3
; use Exp_Ch3
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Dbug
; use Exp_Dbug
;
36 with Exp_Smem
; use Exp_Smem
;
37 with Exp_Tss
; use Exp_Tss
;
38 with Exp_Util
; use Exp_Util
;
39 with Freeze
; use Freeze
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch11
; use Sem_Ch11
;
52 with Sem_Elab
; use Sem_Elab
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Util
; use Sem_Util
;
55 with Sinfo
; use Sinfo
;
56 with Snames
; use Snames
;
57 with Stand
; use Stand
;
58 with Targparm
; use Targparm
;
59 with Tbuild
; use Tbuild
;
60 with Types
; use Types
;
61 with Uintp
; use Uintp
;
63 package body Exp_Ch9
is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 function Actual_Index_Expression
73 Tsk
: Entity_Id
) return Node_Id
;
74 -- Compute the index position for an entry call. Tsk is the target
75 -- task. If the bounds of some entry family depend on discriminants,
76 -- the expression computed by this function uses the discriminants
77 -- of the target task.
79 function Index_Constant_Declaration
82 Prot
: Entity_Id
) return List_Id
;
83 -- For an entry family and its barrier function, we define a local entity
84 -- that maps the index in the call into the entry index into the object:
86 -- I : constant Index_Type := Index_Type'Val (
87 -- E - <<index of first family member>> +
88 -- Protected_Entry_Index (Index_Type'Pos (Index_Type'First)));
90 procedure Add_Object_Pointer
94 -- Prepend an object pointer declaration to the declaration list
95 -- Decls. This object pointer is initialized to a type conversion
96 -- of the System.Address pointer passed to entry barrier functions
97 -- and entry body procedures.
99 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
;
100 -- Transform accept statement into a block with added exception handler.
101 -- Used both for simple accept statements and for accept alternatives in
102 -- select statements. Astat is the accept statement.
104 function Build_Barrier_Function
107 Pid
: Node_Id
) return Node_Id
;
108 -- Build the function body returning the value of the barrier expression
109 -- for the specified entry body.
111 function Build_Barrier_Function_Specification
113 Loc
: Source_Ptr
) return Node_Id
;
114 -- Build a specification for a function implementing
115 -- the protected entry barrier of the specified entry body.
117 function Build_Corresponding_Record
120 Loc
: Source_Ptr
) return Node_Id
;
121 -- Common to tasks and protected types. Copy discriminant specifications,
122 -- build record declaration. N is the type declaration, Ctyp is the
123 -- concurrent entity (task type or protected type).
125 function Build_Entry_Count_Expression
126 (Concurrent_Type
: Node_Id
;
127 Component_List
: List_Id
;
128 Loc
: Source_Ptr
) return Node_Id
;
129 -- Compute number of entries for concurrent object. This is a count of
130 -- simple entries, followed by an expression that computes the length
131 -- of the range of each entry family. A single array with that size is
132 -- allocated for each concurrent object of the type.
134 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
;
135 -- Build the function that translates the entry index in the call
136 -- (which depends on the size of entry families) into an index into the
137 -- Entry_Bodies_Array, to determine the body and barrier function used
138 -- in a protected entry call. A pointer to this function appears in every
141 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
;
142 -- Build subprogram declaration for previous one
144 function Build_Protected_Entry
147 Pid
: Node_Id
) return Node_Id
;
148 -- Build the procedure implementing the statement sequence of
149 -- the specified entry body.
151 function Build_Protected_Entry_Specification
154 Loc
: Source_Ptr
) return Node_Id
;
155 -- Build a specification for a procedure implementing
156 -- the statement sequence of the specified entry body.
157 -- Add attributes associating it with the entry defining identifier
160 function Build_Protected_Subprogram_Body
163 N_Op_Spec
: Node_Id
) return Node_Id
;
164 -- This function is used to construct the protected version of a protected
165 -- subprogram. Its statement sequence first defers abort, then locks
166 -- the associated protected object, and then enters a block that contains
167 -- a call to the unprotected version of the subprogram (for details, see
168 -- Build_Unprotected_Subprogram_Body). This block statement requires
169 -- a cleanup handler that unlocks the object in all cases.
170 -- (see Exp_Ch7.Expand_Cleanup_Actions).
172 function Build_Protected_Spec
174 Obj_Type
: Entity_Id
;
175 Unprotected
: Boolean := False;
176 Ident
: Entity_Id
) return List_Id
;
177 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
178 -- Subprogram_Type. Builds signature of protected subprogram, adding the
179 -- formal that corresponds to the object itself. For an access to protected
180 -- subprogram, there is no object type to specify, so the additional
181 -- parameter has type Address and mode In. An indirect call through such
182 -- a pointer converts the address to a reference to the actual object.
183 -- The object is a limited record and therefore a by_reference type.
185 function Build_Selected_Name
186 (Prefix
, Selector
: Name_Id
;
187 Append_Char
: Character := ' ') return Name_Id
;
188 -- Build a name in the form of Prefix__Selector, with an optional
189 -- character appended. This is used for internal subprograms generated
190 -- for operations of protected types, including barrier functions.
191 -- For the subprograms generated for entry bodies and entry barriers,
192 -- the generated name includes a sequence number that makes names
193 -- unique in the presence of entry overloading. This is necessary
194 -- because entry body procedures and barrier functions all have the
197 procedure Build_Simple_Entry_Call
202 -- Some comments here would be useful ???
204 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
;
205 -- This routine constructs a specification for the procedure that we will
206 -- build for the task body for task type T. The spec has the form:
208 -- procedure tnameB (_Task : access tnameV);
210 -- where name is the character name taken from the task type entity that
211 -- is passed as the argument to the procedure, and tnameV is the task
212 -- value type that is associated with the task type.
214 function Build_Unprotected_Subprogram_Body
216 Pid
: Node_Id
) return Node_Id
;
217 -- This routine constructs the unprotected version of a protected
218 -- subprogram body, which is contains all of the code in the
219 -- original, unexpanded body. This is the version of the protected
220 -- subprogram that is called from all protected operations on the same
221 -- object, including the protected version of the same subprogram.
223 procedure Collect_Entry_Families
226 Current_Node
: in out Node_Id
;
227 Conctyp
: Entity_Id
);
228 -- For each entry family in a concurrent type, create an anonymous array
229 -- type of the right size, and add a component to the corresponding_record.
231 function Family_Offset
235 Ttyp
: Entity_Id
) return Node_Id
;
236 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
237 -- an accept statement, or the upper bound in the discrete subtype of
238 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
239 -- the concurrent type of the entry.
245 Ttyp
: Entity_Id
) return Node_Id
;
246 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
247 -- a family, and handle properly the superflat case. This is equivalent
248 -- to the use of 'Length on the index type, but must use Family_Offset
249 -- to handle properly the case of bounds that depend on discriminants.
251 procedure Extract_Entry
253 Concval
: out Node_Id
;
255 Index
: out Node_Id
);
256 -- Given an entry call, returns the associated concurrent object,
257 -- the entry name, and the entry family index.
259 function Find_Task_Or_Protected_Pragma
261 P
: Name_Id
) return Node_Id
;
262 -- Searches the task or protected definition T for the first occurrence
263 -- of the pragma whose name is given by P. The caller has ensured that
264 -- the pragma is present in the task definition. A special case is that
265 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
266 -- ??? Should be implemented with the rep item chain mechanism.
268 procedure Update_Prival_Subtypes
(N
: Node_Id
);
269 -- The actual subtypes of the privals will differ from the type of the
270 -- private declaration in the original protected type, if the protected
271 -- type has discriminants or if the prival has constrained components.
272 -- This is because the privals are generated out of sequence w.r.t. the
273 -- analysis of a protected body. After generating the bodies for protected
274 -- operations, we set correctly the type of all references to privals, by
275 -- means of a recursive tree traversal, which is heavy-handed but
278 -----------------------------
279 -- Actual_Index_Expression --
280 -----------------------------
282 function Actual_Index_Expression
286 Tsk
: Entity_Id
) return Node_Id
288 Ttyp
: constant Entity_Id
:= Etype
(Tsk
);
296 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
;
297 -- Compute difference between bounds of entry family
299 --------------------------
300 -- Actual_Family_Offset --
301 --------------------------
303 function Actual_Family_Offset
(Hi
, Lo
: Node_Id
) return Node_Id
is
305 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
306 -- Replace a reference to a discriminant with a selected component
307 -- denoting the discriminant of the target task.
309 -----------------------------
310 -- Actual_Discriminant_Ref --
311 -----------------------------
313 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
314 Typ
: constant Entity_Id
:= Etype
(Bound
);
318 if not Is_Entity_Name
(Bound
)
319 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
321 if Nkind
(Bound
) = N_Attribute_Reference
then
324 B
:= New_Copy_Tree
(Bound
);
329 Make_Selected_Component
(Sloc
,
330 Prefix
=> New_Copy_Tree
(Tsk
),
331 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Sloc
));
333 Analyze_And_Resolve
(B
, Typ
);
337 Make_Attribute_Reference
(Sloc
,
338 Attribute_Name
=> Name_Pos
,
339 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Sloc
),
340 Expressions
=> New_List
(B
));
341 end Actual_Discriminant_Ref
;
343 -- Start of processing for Actual_Family_Offset
347 Make_Op_Subtract
(Sloc
,
348 Left_Opnd
=> Actual_Discriminant_Ref
(Hi
),
349 Right_Opnd
=> Actual_Discriminant_Ref
(Lo
));
350 end Actual_Family_Offset
;
352 -- Start of processing for Actual_Index_Expression
355 -- The queues of entries and entry families appear in textual
356 -- order in the associated record. The entry index is computed as
357 -- the sum of the number of queues for all entries that precede the
358 -- designated one, to which is added the index expression, if this
359 -- expression denotes a member of a family.
361 -- The following is a place holder for the count of simple entries
363 Num
:= Make_Integer_Literal
(Sloc
, 1);
365 -- We construct an expression which is a series of addition
366 -- operations. See comments in Entry_Index_Expression, which is
367 -- identical in structure.
369 if Present
(Index
) then
370 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
377 Actual_Family_Offset
(
378 Make_Attribute_Reference
(Sloc
,
379 Attribute_Name
=> Name_Pos
,
380 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
381 Expressions
=> New_List
(Relocate_Node
(Index
))),
382 Type_Low_Bound
(S
)));
387 -- Now add lengths of preceding entries and entry families
389 Prev
:= First_Entity
(Ttyp
);
391 while Chars
(Prev
) /= Chars
(Ent
)
392 or else (Ekind
(Prev
) /= Ekind
(Ent
))
393 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
395 if Ekind
(Prev
) = E_Entry
then
396 Set_Intval
(Num
, Intval
(Num
) + 1);
398 elsif Ekind
(Prev
) = E_Entry_Family
then
400 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
401 Lo
:= Type_Low_Bound
(S
);
402 Hi
:= Type_High_Bound
(S
);
410 Actual_Family_Offset
(Hi
, Lo
),
412 Make_Integer_Literal
(Sloc
, 1)));
414 -- Other components are anonymous types to be ignored
424 end Actual_Index_Expression
;
426 ----------------------------------
427 -- Add_Discriminal_Declarations --
428 ----------------------------------
430 procedure Add_Discriminal_Declarations
439 if Has_Discriminants
(Typ
) then
440 D
:= First_Discriminant
(Typ
);
442 while Present
(D
) loop
445 Make_Object_Renaming_Declaration
(Loc
,
446 Defining_Identifier
=> Discriminal
(D
),
447 Subtype_Mark
=> New_Reference_To
(Etype
(D
), Loc
),
449 Make_Selected_Component
(Loc
,
450 Prefix
=> Make_Identifier
(Loc
, Name
),
451 Selector_Name
=> Make_Identifier
(Loc
, Chars
(D
)))));
453 Next_Discriminant
(D
);
456 end Add_Discriminal_Declarations
;
458 ------------------------
459 -- Add_Object_Pointer --
460 ------------------------
462 procedure Add_Object_Pointer
470 -- Prepend the declaration of _object. This must be first in the
471 -- declaration list, since it is used by the discriminal and
472 -- prival declarations.
473 -- ??? An attempt to make this a renaming was unsuccessful.
475 -- type poVP is access poV;
476 -- _object : poVP := poVP!O;
479 Make_Defining_Identifier
(Loc
,
482 (Chars
(Corresponding_Record_Type
(Pid
)), 'P'));
485 Make_Object_Declaration
(Loc
,
486 Defining_Identifier
=>
487 Make_Defining_Identifier
(Loc
, Name_uObject
),
488 Object_Definition
=> New_Reference_To
(Obj_Ptr
, Loc
),
490 Unchecked_Convert_To
(Obj_Ptr
,
491 Make_Identifier
(Loc
, Name_uO
))));
494 Make_Full_Type_Declaration
(Loc
,
495 Defining_Identifier
=> Obj_Ptr
,
496 Type_Definition
=> Make_Access_To_Object_Definition
(Loc
,
497 Subtype_Indication
=>
498 New_Reference_To
(Corresponding_Record_Type
(Pid
), Loc
))));
499 end Add_Object_Pointer
;
501 ------------------------------
502 -- Add_Private_Declarations --
503 ------------------------------
505 procedure Add_Private_Declarations
511 Def
: constant Node_Id
:= Protected_Definition
(Parent
(Typ
));
512 Body_Ent
: constant Entity_Id
:= Corresponding_Body
(Parent
(Typ
));
517 pragma Assert
(Nkind
(Def
) = N_Protected_Definition
);
519 if Present
(Private_Declarations
(Def
)) then
520 P
:= First
(Private_Declarations
(Def
));
522 while Present
(P
) loop
523 if Nkind
(P
) = N_Component_Declaration
then
524 Pdef
:= Defining_Identifier
(P
);
526 Make_Object_Renaming_Declaration
(Loc
,
527 Defining_Identifier
=> Prival
(Pdef
),
528 Subtype_Mark
=> New_Reference_To
(Etype
(Pdef
), Loc
),
530 Make_Selected_Component
(Loc
,
531 Prefix
=> Make_Identifier
(Loc
, Name
),
532 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Pdef
)))));
538 -- One more "prival" for the object itself, with the right protection
542 Protection_Type
: RE_Id
;
544 if Has_Attach_Handler
(Typ
) then
545 if Restricted_Profile
then
546 if Has_Entries
(Typ
) then
547 Protection_Type
:= RE_Protection_Entry
;
549 Protection_Type
:= RE_Protection
;
552 Protection_Type
:= RE_Static_Interrupt_Protection
;
555 elsif Has_Interrupt_Handler
(Typ
) then
556 Protection_Type
:= RE_Dynamic_Interrupt_Protection
;
558 elsif Has_Entries
(Typ
) then
560 or else Restriction_Active
(No_Entry_Queue
) = False
561 or else Number_Entries
(Typ
) > 1
563 Protection_Type
:= RE_Protection_Entries
;
565 Protection_Type
:= RE_Protection_Entry
;
569 Protection_Type
:= RE_Protection
;
573 Make_Object_Renaming_Declaration
(Loc
,
574 Defining_Identifier
=> Object_Ref
(Body_Ent
),
575 Subtype_Mark
=> New_Reference_To
(RTE
(Protection_Type
), Loc
),
577 Make_Selected_Component
(Loc
,
578 Prefix
=> Make_Identifier
(Loc
, Name
),
579 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
))));
581 end Add_Private_Declarations
;
583 -----------------------
584 -- Build_Accept_Body --
585 -----------------------
587 function Build_Accept_Body
(Astat
: Node_Id
) return Node_Id
is
588 Loc
: constant Source_Ptr
:= Sloc
(Astat
);
589 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(Astat
);
596 -- At the end of the statement sequence, Complete_Rendezvous is called.
597 -- A label skipping the Complete_Rendezvous, and all other
598 -- accept processing, has already been added for the expansion
599 -- of requeue statements.
601 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Rendezvous
);
602 Insert_Before
(Last
(Statements
(Stats
)), Call
);
605 -- If exception handlers are present, then append Complete_Rendezvous
606 -- calls to the handlers, and construct the required outer block.
608 if Present
(Exception_Handlers
(Stats
)) then
609 Hand
:= First
(Exception_Handlers
(Stats
));
611 while Present
(Hand
) loop
612 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Rendezvous
);
613 Append
(Call
, Statements
(Hand
));
619 Make_Handled_Sequence_Of_Statements
(Loc
,
620 Statements
=> New_List
(
621 Make_Block_Statement
(Loc
,
622 Handled_Statement_Sequence
=> Stats
)));
628 -- At this stage we know that the new statement sequence does not
629 -- have an exception handler part, so we supply one to call
630 -- Exceptional_Complete_Rendezvous. This handler is
632 -- when all others =>
633 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
635 -- We handle Abort_Signal to make sure that we properly catch the abort
636 -- case and wake up the caller.
638 Ohandle
:= Make_Others_Choice
(Loc
);
639 Set_All_Others
(Ohandle
);
641 Set_Exception_Handlers
(New_S
,
643 Make_Exception_Handler
(Loc
,
644 Exception_Choices
=> New_List
(Ohandle
),
646 Statements
=> New_List
(
647 Make_Procedure_Call_Statement
(Loc
,
648 Name
=> New_Reference_To
(
649 RTE
(RE_Exceptional_Complete_Rendezvous
), Loc
),
650 Parameter_Associations
=> New_List
(
651 Make_Function_Call
(Loc
,
652 Name
=> New_Reference_To
(
653 RTE
(RE_Get_GNAT_Exception
), Loc
))))))));
655 Set_Parent
(New_S
, Astat
); -- temp parent for Analyze call
656 Analyze_Exception_Handlers
(Exception_Handlers
(New_S
));
657 Expand_Exception_Handlers
(New_S
);
659 -- Exceptional_Complete_Rendezvous must be called with abort
660 -- still deferred, which is the case for a "when all others" handler.
663 end Build_Accept_Body
;
665 -----------------------------------
666 -- Build_Activation_Chain_Entity --
667 -----------------------------------
669 procedure Build_Activation_Chain_Entity
(N
: Node_Id
) is
675 -- Loop to find enclosing construct containing activation chain variable
679 while Nkind
(P
) /= N_Subprogram_Body
680 and then Nkind
(P
) /= N_Package_Declaration
681 and then Nkind
(P
) /= N_Package_Body
682 and then Nkind
(P
) /= N_Block_Statement
683 and then Nkind
(P
) /= N_Task_Body
688 -- If we are in a package body, the activation chain variable is
689 -- allocated in the corresponding spec. First, we save the package
690 -- body node because we enter the new entity in its Declarations list.
694 if Nkind
(P
) = N_Package_Body
then
695 P
:= Unit_Declaration_Node
(Corresponding_Spec
(P
));
696 Decls
:= Declarations
(B
);
698 elsif Nkind
(P
) = N_Package_Declaration
then
699 Decls
:= Visible_Declarations
(Specification
(B
));
702 Decls
:= Declarations
(B
);
705 -- If activation chain entity not already declared, declare it
707 if No
(Activation_Chain_Entity
(P
)) then
708 Set_Activation_Chain_Entity
709 (P
, Make_Defining_Identifier
(Sloc
(N
), Name_uChain
));
712 Make_Object_Declaration
(Sloc
(P
),
713 Defining_Identifier
=> Activation_Chain_Entity
(P
),
714 Aliased_Present
=> True,
716 New_Reference_To
(RTE
(RE_Activation_Chain
), Sloc
(P
))));
718 Analyze
(First
(Decls
));
720 end Build_Activation_Chain_Entity
;
722 ----------------------------
723 -- Build_Barrier_Function --
724 ----------------------------
726 function Build_Barrier_Function
729 Pid
: Node_Id
) return Node_Id
731 Loc
: constant Source_Ptr
:= Sloc
(N
);
732 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
733 Index_Spec
: constant Node_Id
:= Entry_Index_Specification
735 Op_Decls
: constant List_Id
:= New_List
;
741 Make_Defining_Identifier
(Loc
, Chars
(Barrier_Function
(Ent
)));
742 Bspec
:= Build_Barrier_Function_Specification
(Bdef
, Loc
);
744 -- <object pointer declaration>
745 -- <discriminant renamings>
746 -- <private object renamings>
747 -- Add discriminal and private renamings. These names have
748 -- already been used to expand references to discriminants
751 Add_Discriminal_Declarations
(Op_Decls
, Pid
, Name_uObject
, Loc
);
752 Add_Private_Declarations
(Op_Decls
, Pid
, Name_uObject
, Loc
);
753 Add_Object_Pointer
(Op_Decls
, Pid
, Loc
);
755 -- If this is the barrier for an entry family, the entry index is
756 -- visible in the body of the barrier. Create a local variable that
757 -- converts the entry index (which is the last formal of the barrier
758 -- function) into the appropriate offset into the entry array. The
759 -- entry index constant must be set, as for the entry body, so that
760 -- local references to the entry index are correctly replaced with
761 -- the local variable. This parallels what is done for entry bodies.
763 if Present
(Index_Spec
) then
765 Index_Id
: constant Entity_Id
:= Defining_Identifier
(Index_Spec
);
766 Index_Con
: constant Entity_Id
:=
767 Make_Defining_Identifier
(Loc
,
768 Chars
=> New_Internal_Name
('J'));
771 Set_Entry_Index_Constant
(Index_Id
, Index_Con
);
772 Append_List_To
(Op_Decls
,
773 Index_Constant_Declaration
(N
, Index_Id
, Pid
));
777 -- Note: the condition in the barrier function needs to be properly
778 -- processed for the C/Fortran boolean possibility, but this happens
779 -- automatically since the return statement does this normalization.
782 Make_Subprogram_Body
(Loc
,
783 Specification
=> Bspec
,
784 Declarations
=> Op_Decls
,
785 Handled_Statement_Sequence
=>
786 Make_Handled_Sequence_Of_Statements
(Loc
,
787 Statements
=> New_List
(
788 Make_Return_Statement
(Loc
,
789 Expression
=> Condition
(Ent_Formals
)))));
790 end Build_Barrier_Function
;
792 ------------------------------------------
793 -- Build_Barrier_Function_Specification --
794 ------------------------------------------
796 function Build_Barrier_Function_Specification
798 Loc
: Source_Ptr
) return Node_Id
801 Set_Needs_Debug_Info
(Def_Id
);
802 return Make_Function_Specification
(Loc
,
803 Defining_Unit_Name
=> Def_Id
,
804 Parameter_Specifications
=> New_List
(
805 Make_Parameter_Specification
(Loc
,
806 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
808 New_Reference_To
(RTE
(RE_Address
), Loc
)),
810 Make_Parameter_Specification
(Loc
,
811 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uE
),
813 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
815 Subtype_Mark
=> New_Reference_To
(Standard_Boolean
, Loc
));
816 end Build_Barrier_Function_Specification
;
818 --------------------------
819 -- Build_Call_With_Task --
820 --------------------------
822 function Build_Call_With_Task
824 E
: Entity_Id
) return Node_Id
826 Loc
: constant Source_Ptr
:= Sloc
(N
);
830 Make_Function_Call
(Loc
,
831 Name
=> New_Reference_To
(E
, Loc
),
832 Parameter_Associations
=> New_List
(Concurrent_Ref
(N
)));
833 end Build_Call_With_Task
;
835 --------------------------------
836 -- Build_Corresponding_Record --
837 --------------------------------
839 function Build_Corresponding_Record
842 Loc
: Source_Ptr
) return Node_Id
844 Rec_Ent
: constant Entity_Id
:=
845 Make_Defining_Identifier
846 (Loc
, New_External_Name
(Chars
(Ctyp
), 'V'));
849 New_Disc
: Entity_Id
;
853 Set_Corresponding_Record_Type
(Ctyp
, Rec_Ent
);
854 Set_Ekind
(Rec_Ent
, E_Record_Type
);
855 Set_Has_Delayed_Freeze
(Rec_Ent
, Has_Delayed_Freeze
(Ctyp
));
856 Set_Is_Concurrent_Record_Type
(Rec_Ent
, True);
857 Set_Corresponding_Concurrent_Type
(Rec_Ent
, Ctyp
);
858 Set_Stored_Constraint
(Rec_Ent
, No_Elist
);
861 -- Use discriminals to create list of discriminants for record, and
862 -- create new discriminals for use in default expressions, etc. It is
863 -- worth noting that a task discriminant gives rise to 5 entities;
865 -- a) The original discriminant.
866 -- b) The discriminal for use in the task.
867 -- c) The discriminant of the corresponding record.
868 -- d) The discriminal for the init proc of the corresponding record.
869 -- e) The local variable that renames the discriminant in the procedure
870 -- for the task body.
872 -- In fact the discriminals b) are used in the renaming declarations
873 -- for e). See details in einfo (Handling of Discriminants).
875 if Present
(Discriminant_Specifications
(N
)) then
877 Disc
:= First_Discriminant
(Ctyp
);
879 while Present
(Disc
) loop
880 New_Disc
:= CR_Discriminant
(Disc
);
883 Make_Discriminant_Specification
(Loc
,
884 Defining_Identifier
=> New_Disc
,
886 New_Occurrence_Of
(Etype
(Disc
), Loc
),
888 New_Copy
(Discriminant_Default_Value
(Disc
))));
890 Next_Discriminant
(Disc
);
897 -- Now we can construct the record type declaration. Note that this
898 -- record is limited, reflecting the underlying limitedness of the
899 -- task or protected object that it represents, and ensuring for
900 -- example that it is properly passed by reference.
903 Make_Full_Type_Declaration
(Loc
,
904 Defining_Identifier
=> Rec_Ent
,
905 Discriminant_Specifications
=> Dlist
,
907 Make_Record_Definition
(Loc
,
909 Make_Component_List
(Loc
,
910 Component_Items
=> Cdecls
),
911 Limited_Present
=> True));
912 end Build_Corresponding_Record
;
914 ----------------------------------
915 -- Build_Entry_Count_Expression --
916 ----------------------------------
918 function Build_Entry_Count_Expression
919 (Concurrent_Type
: Node_Id
;
920 Component_List
: List_Id
;
921 Loc
: Source_Ptr
) return Node_Id
932 Ent
:= First_Entity
(Concurrent_Type
);
935 -- Count number of non-family entries
937 while Present
(Ent
) loop
938 if Ekind
(Ent
) = E_Entry
then
945 Ecount
:= Make_Integer_Literal
(Loc
, Eindx
);
947 -- Loop through entry families building the addition nodes
949 Ent
:= First_Entity
(Concurrent_Type
);
950 Comp
:= First
(Component_List
);
952 while Present
(Ent
) loop
953 if Ekind
(Ent
) = E_Entry_Family
then
954 while Chars
(Ent
) /= Chars
(Defining_Identifier
(Comp
)) loop
958 Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
959 Hi
:= Type_High_Bound
(Typ
);
960 Lo
:= Type_Low_Bound
(Typ
);
965 Right_Opnd
=> Family_Size
(Loc
, Hi
, Lo
, Concurrent_Type
));
972 end Build_Entry_Count_Expression
;
974 ---------------------------
975 -- Build_Find_Body_Index --
976 ---------------------------
978 function Build_Find_Body_Index
(Typ
: Entity_Id
) return Node_Id
is
979 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
982 Has_F
: Boolean := False;
984 If_St
: Node_Id
:= Empty
;
987 Decls
: List_Id
:= New_List
;
990 Siz
: Node_Id
:= Empty
;
992 procedure Add_If_Clause
(Expr
: Node_Id
);
993 -- Add test for range of current entry
995 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
996 -- If a bound of an entry is given by a discriminant, retrieve the
997 -- actual value of the discriminant from the enclosing object.
1003 procedure Add_If_Clause
(Expr
: Node_Id
) is
1005 Stats
: constant List_Id
:=
1007 Make_Return_Statement
(Loc
,
1008 Expression
=> Make_Integer_Literal
(Loc
, Index
+ 1)));
1011 -- Index for current entry body
1015 -- Compute total length of entry queues so far
1023 Right_Opnd
=> Expr
);
1028 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
1031 -- Map entry queue indices in the range of the current family
1032 -- into the current index, that designates the entry body.
1036 Make_Implicit_If_Statement
(Typ
,
1038 Then_Statements
=> Stats
,
1039 Elsif_Parts
=> New_List
);
1045 Make_Elsif_Part
(Loc
,
1047 Then_Statements
=> Stats
),
1048 Elsif_Parts
(If_St
));
1052 ------------------------------
1053 -- Convert_Discriminant_Ref --
1054 ------------------------------
1056 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
1060 if Is_Entity_Name
(Bound
)
1061 and then Ekind
(Entity
(Bound
)) = E_Discriminant
1064 Make_Selected_Component
(Loc
,
1066 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
1067 Make_Explicit_Dereference
(Loc
,
1068 Make_Identifier
(Loc
, Name_uObject
))),
1069 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Bound
)));
1070 Set_Etype
(B
, Etype
(Entity
(Bound
)));
1072 B
:= New_Copy_Tree
(Bound
);
1076 end Convert_Discriminant_Ref
;
1078 -- Start of processing for Build_Find_Body_Index
1081 Spec
:= Build_Find_Body_Index_Spec
(Typ
);
1083 Ent
:= First_Entity
(Typ
);
1085 while Present
(Ent
) loop
1087 if Ekind
(Ent
) = E_Entry_Family
then
1097 -- If the protected type has no entry families, there is a one-one
1098 -- correspondence between entry queue and entry body.
1101 Make_Return_Statement
(Loc
,
1102 Expression
=> Make_Identifier
(Loc
, Name_uE
));
1105 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
1108 -- if E <= l1 then return 1;
1109 -- elsif E <= l1 + l2 then return 2;
1114 Ent
:= First_Entity
(Typ
);
1116 Add_Object_Pointer
(Decls
, Typ
, Loc
);
1118 while Present
(Ent
) loop
1120 if Ekind
(Ent
) = E_Entry
then
1121 Add_If_Clause
(Make_Integer_Literal
(Loc
, 1));
1123 elsif Ekind
(Ent
) = E_Entry_Family
then
1125 E_Typ
:= Etype
(Discrete_Subtype_Definition
(Parent
(Ent
)));
1126 Hi
:= Convert_Discriminant_Ref
(Type_High_Bound
(E_Typ
));
1127 Lo
:= Convert_Discriminant_Ref
(Type_Low_Bound
(E_Typ
));
1128 Add_If_Clause
(Family_Size
(Loc
, Hi
, Lo
, Typ
));
1137 Make_Return_Statement
(Loc
,
1138 Expression
=> Make_Integer_Literal
(Loc
, 1));
1140 elsif Nkind
(Ret
) = N_If_Statement
then
1142 -- Ranges are in increasing order, so last one doesn't need a
1146 Nod
: constant Node_Id
:= Last
(Elsif_Parts
(Ret
));
1150 Set_Else_Statements
(Ret
, Then_Statements
(Nod
));
1156 Make_Subprogram_Body
(Loc
,
1157 Specification
=> Spec
,
1158 Declarations
=> Decls
,
1159 Handled_Statement_Sequence
=>
1160 Make_Handled_Sequence_Of_Statements
(Loc
,
1161 Statements
=> New_List
(Ret
)));
1162 end Build_Find_Body_Index
;
1164 --------------------------------
1165 -- Build_Find_Body_Index_Spec --
1166 --------------------------------
1168 function Build_Find_Body_Index_Spec
(Typ
: Entity_Id
) return Node_Id
is
1169 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1170 Id
: constant Entity_Id
:=
1171 Make_Defining_Identifier
(Loc
,
1172 Chars
=> New_External_Name
(Chars
(Typ
), 'F'));
1173 Parm1
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uO
);
1174 Parm2
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uE
);
1178 Make_Function_Specification
(Loc
,
1179 Defining_Unit_Name
=> Id
,
1180 Parameter_Specifications
=> New_List
(
1181 Make_Parameter_Specification
(Loc
,
1182 Defining_Identifier
=> Parm1
,
1184 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1186 Make_Parameter_Specification
(Loc
,
1187 Defining_Identifier
=> Parm2
,
1189 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))),
1190 Subtype_Mark
=> New_Occurrence_Of
(
1191 RTE
(RE_Protected_Entry_Index
), Loc
));
1192 end Build_Find_Body_Index_Spec
;
1194 -------------------------
1195 -- Build_Master_Entity --
1196 -------------------------
1198 procedure Build_Master_Entity
(E
: Entity_Id
) is
1199 Loc
: constant Source_Ptr
:= Sloc
(E
);
1207 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
1208 -- in internal scopes. Required for nested limited aggregates.
1210 if Ada_Version
>= Ada_05
then
1211 while Is_Internal
(S
) loop
1216 -- Nothing to do if we already built a master entity for this scope
1217 -- or if there is no task hierarchy.
1219 if Has_Master_Entity
(S
)
1220 or else Restriction_Active
(No_Task_Hierarchy
)
1225 -- Otherwise first build the master entity
1226 -- _Master : constant Master_Id := Current_Master.all;
1227 -- and insert it just before the current declaration
1230 Make_Object_Declaration
(Loc
,
1231 Defining_Identifier
=>
1232 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1233 Constant_Present
=> True,
1234 Object_Definition
=> New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
1236 Make_Explicit_Dereference
(Loc
,
1237 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
1240 Insert_Before
(P
, Decl
);
1243 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
1244 -- non-internal scope selected above.
1246 if Ada_Version
>= Ada_05
then
1247 Set_Has_Master_Entity
(S
);
1249 Set_Has_Master_Entity
(Scope
(E
));
1252 -- Now mark the containing scope as a task master
1254 while Nkind
(P
) /= N_Compilation_Unit
loop
1257 -- If we fall off the top, we are at the outer level, and the
1258 -- environment task is our effective master, so nothing to mark.
1260 if Nkind
(P
) = N_Task_Body
1261 or else Nkind
(P
) = N_Block_Statement
1262 or else Nkind
(P
) = N_Subprogram_Body
1264 Set_Is_Task_Master
(P
, True);
1267 elsif Nkind
(Parent
(P
)) = N_Subunit
then
1268 P
:= Corresponding_Stub
(Parent
(P
));
1271 end Build_Master_Entity
;
1273 ---------------------------
1274 -- Build_Protected_Entry --
1275 ---------------------------
1277 function Build_Protected_Entry
1280 Pid
: Node_Id
) return Node_Id
1282 Loc
: constant Source_Ptr
:= Sloc
(N
);
1283 Op_Decls
: constant List_Id
:= New_List
;
1292 Make_Defining_Identifier
(Loc
,
1293 Chars
=> Chars
(Protected_Body_Subprogram
(Ent
)));
1294 Espec
:= Build_Protected_Entry_Specification
(Edef
, Empty
, Loc
);
1296 -- <object pointer declaration>
1297 -- Add object pointer declaration. This is needed by the
1298 -- discriminal and prival renamings, which should already
1299 -- have been inserted into the declaration list.
1301 Add_Object_Pointer
(Op_Decls
, Pid
, Loc
);
1304 or else Restriction_Active
(No_Entry_Queue
) = False
1305 or else Number_Entries
(Pid
) > 1
1307 Complete
:= New_Reference_To
(RTE
(RE_Complete_Entry_Body
), Loc
);
1310 New_Reference_To
(RTE
(RE_Complete_Single_Entry_Body
), Loc
);
1313 Op_Stats
:= New_List
(
1314 Make_Block_Statement
(Loc
,
1315 Declarations
=> Declarations
(N
),
1316 Handled_Statement_Sequence
=>
1317 Handled_Statement_Sequence
(N
)),
1319 Make_Procedure_Call_Statement
(Loc
,
1321 Parameter_Associations
=> New_List
(
1322 Make_Attribute_Reference
(Loc
,
1324 Make_Selected_Component
(Loc
,
1326 Make_Identifier
(Loc
, Name_uObject
),
1329 Make_Identifier
(Loc
, Name_uObject
)),
1330 Attribute_Name
=> Name_Unchecked_Access
))));
1332 if Restriction_Active
(No_Exception_Handlers
) then
1334 Make_Subprogram_Body
(Loc
,
1335 Specification
=> Espec
,
1336 Declarations
=> Op_Decls
,
1337 Handled_Statement_Sequence
=>
1338 Make_Handled_Sequence_Of_Statements
(Loc
, Op_Stats
));
1341 Ohandle
:= Make_Others_Choice
(Loc
);
1342 Set_All_Others
(Ohandle
);
1345 or else Restriction_Active
(No_Entry_Queue
) = False
1346 or else Number_Entries
(Pid
) > 1
1349 New_Reference_To
(RTE
(RE_Exceptional_Complete_Entry_Body
), Loc
);
1352 Complete
:= New_Reference_To
(
1353 RTE
(RE_Exceptional_Complete_Single_Entry_Body
), Loc
);
1357 Make_Subprogram_Body
(Loc
,
1358 Specification
=> Espec
,
1359 Declarations
=> Op_Decls
,
1360 Handled_Statement_Sequence
=>
1361 Make_Handled_Sequence_Of_Statements
(Loc
,
1362 Statements
=> Op_Stats
,
1363 Exception_Handlers
=> New_List
(
1364 Make_Exception_Handler
(Loc
,
1365 Exception_Choices
=> New_List
(Ohandle
),
1367 Statements
=> New_List
(
1368 Make_Procedure_Call_Statement
(Loc
,
1370 Parameter_Associations
=> New_List
(
1371 Make_Attribute_Reference
(Loc
,
1373 Make_Selected_Component
(Loc
,
1375 Make_Identifier
(Loc
, Name_uObject
),
1377 Make_Identifier
(Loc
, Name_uObject
)),
1378 Attribute_Name
=> Name_Unchecked_Access
),
1380 Make_Function_Call
(Loc
,
1381 Name
=> New_Reference_To
(
1382 RTE
(RE_Get_GNAT_Exception
), Loc
)))))))));
1384 end Build_Protected_Entry
;
1386 -----------------------------------------
1387 -- Build_Protected_Entry_Specification --
1388 -----------------------------------------
1390 function Build_Protected_Entry_Specification
1391 (Def_Id
: Entity_Id
;
1393 Loc
: Source_Ptr
) return Node_Id
1398 Set_Needs_Debug_Info
(Def_Id
);
1399 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
1401 if Present
(Ent_Id
) then
1402 Append_Elmt
(P
, Accept_Address
(Ent_Id
));
1405 return Make_Procedure_Specification
(Loc
,
1406 Defining_Unit_Name
=> Def_Id
,
1407 Parameter_Specifications
=> New_List
(
1408 Make_Parameter_Specification
(Loc
,
1409 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uO
),
1411 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1413 Make_Parameter_Specification
(Loc
,
1414 Defining_Identifier
=> P
,
1416 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1418 Make_Parameter_Specification
(Loc
,
1419 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uE
),
1421 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
))));
1422 end Build_Protected_Entry_Specification
;
1424 --------------------------
1425 -- Build_Protected_Spec --
1426 --------------------------
1428 function Build_Protected_Spec
1430 Obj_Type
: Entity_Id
;
1431 Unprotected
: Boolean := False;
1432 Ident
: Entity_Id
) return List_Id
1434 Loc
: constant Source_Ptr
:= Sloc
(N
);
1436 New_Plist
: List_Id
;
1437 New_Param
: Node_Id
;
1440 New_Plist
:= New_List
;
1441 Formal
:= First_Formal
(Ident
);
1443 while Present
(Formal
) loop
1445 Make_Parameter_Specification
(Loc
,
1446 Defining_Identifier
=>
1447 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
1448 In_Present
=> In_Present
(Parent
(Formal
)),
1449 Out_Present
=> Out_Present
(Parent
(Formal
)),
1451 New_Reference_To
(Etype
(Formal
), Loc
));
1454 Set_Protected_Formal
(Formal
, Defining_Identifier
(New_Param
));
1457 Append
(New_Param
, New_Plist
);
1458 Next_Formal
(Formal
);
1461 -- If the subprogram is a procedure and the context is not an access
1462 -- to protected subprogram, the parameter is in-out. Otherwise it is
1465 Prepend_To
(New_Plist
,
1466 Make_Parameter_Specification
(Loc
,
1467 Defining_Identifier
=>
1468 Make_Defining_Identifier
(Loc
, Name_uObject
),
1471 (Etype
(Ident
) = Standard_Void_Type
1472 and then not Is_RTE
(Obj_Type
, RE_Address
)),
1473 Parameter_Type
=> New_Reference_To
(Obj_Type
, Loc
)));
1476 end Build_Protected_Spec
;
1478 ---------------------------------------
1479 -- Build_Protected_Sub_Specification --
1480 ---------------------------------------
1482 function Build_Protected_Sub_Specification
1484 Prottyp
: Entity_Id
;
1485 Unprotected
: Boolean := False) return Node_Id
1487 Loc
: constant Source_Ptr
:= Sloc
(N
);
1489 Protnm
: constant Name_Id
:= Chars
(Prottyp
);
1493 New_Plist
: List_Id
;
1494 Append_Char
: Character;
1499 (Defining_Unit_Name
(Specification
(N
))) = E_Subprogram_Body
1501 Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
1506 Ident
:= Defining_Unit_Name
(Specification
(Decl
));
1507 Nam
:= Chars
(Ident
);
1509 New_Plist
:= Build_Protected_Spec
1510 (Decl
, Corresponding_Record_Type
(Prottyp
),
1511 Unprotected
, Ident
);
1520 Make_Defining_Identifier
(Loc
,
1521 Chars
=> Build_Selected_Name
(Protnm
, Nam
, Append_Char
));
1523 -- The unprotected operation carries the user code, and debugging
1524 -- information must be generated for it, even though this spec does
1525 -- not come from source. It is also convenient to allow gdb to step
1526 -- into the protected operation, even though it only contains lock/
1529 Set_Needs_Debug_Info
(New_Id
);
1531 if Nkind
(Specification
(Decl
)) = N_Procedure_Specification
then
1533 Make_Procedure_Specification
(Loc
,
1534 Defining_Unit_Name
=> New_Id
,
1535 Parameter_Specifications
=> New_Plist
);
1539 Make_Function_Specification
(Loc
,
1540 Defining_Unit_Name
=> New_Id
,
1541 Parameter_Specifications
=> New_Plist
,
1542 Subtype_Mark
=> New_Copy
(Subtype_Mark
(Specification
(Decl
))));
1543 Set_Return_Present
(Defining_Unit_Name
(New_Spec
));
1546 end Build_Protected_Sub_Specification
;
1548 -------------------------------------
1549 -- Build_Protected_Subprogram_Body --
1550 -------------------------------------
1552 function Build_Protected_Subprogram_Body
1555 N_Op_Spec
: Node_Id
) return Node_Id
1557 Loc
: constant Source_Ptr
:= Sloc
(N
);
1559 P_Op_Spec
: Node_Id
;
1562 Unprot_Call
: Node_Id
;
1564 Lock_Name
: Node_Id
;
1565 Lock_Stmt
: Node_Id
;
1566 Service_Name
: Node_Id
;
1568 Return_Stmt
: Node_Id
:= Empty
; -- init to avoid gcc 3 warning
1569 Pre_Stmts
: List_Id
:= No_List
; -- init to avoid gcc 3 warning
1571 Object_Parm
: Node_Id
;
1574 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean;
1575 -- Tell whether a given subprogram cannot raise an exception
1577 -----------------------
1578 -- Is_Exception_Safe --
1579 -----------------------
1581 function Is_Exception_Safe
(Subprogram
: Node_Id
) return Boolean is
1583 function Has_Side_Effect
(N
: Node_Id
) return Boolean;
1584 -- Return True whenever encountering a subprogram call or a
1585 -- raise statement of any kind in the sequence of statements N
1587 ---------------------
1588 -- Has_Side_Effect --
1589 ---------------------
1591 -- What is this doing buried two levels down in exp_ch9. It
1592 -- seems like a generally useful function, and indeed there
1593 -- may be code duplication going on here ???
1595 function Has_Side_Effect
(N
: Node_Id
) return Boolean is
1596 Stmt
: Node_Id
:= N
;
1599 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean;
1600 -- Indicate whether N is a subprogram call or a raise statement
1602 function Is_Call_Or_Raise
(N
: Node_Id
) return Boolean is
1604 return Nkind
(N
) = N_Procedure_Call_Statement
1605 or else Nkind
(N
) = N_Function_Call
1606 or else Nkind
(N
) = N_Raise_Statement
1607 or else Nkind
(N
) = N_Raise_Constraint_Error
1608 or else Nkind
(N
) = N_Raise_Program_Error
1609 or else Nkind
(N
) = N_Raise_Storage_Error
;
1610 end Is_Call_Or_Raise
;
1612 -- Start of processing for Has_Side_Effect
1615 while Present
(Stmt
) loop
1616 if Is_Call_Or_Raise
(Stmt
) then
1620 -- An object declaration can also contain a function call
1621 -- or a raise statement
1623 if Nkind
(Stmt
) = N_Object_Declaration
then
1624 Expr
:= Expression
(Stmt
);
1626 if Present
(Expr
) and then Is_Call_Or_Raise
(Expr
) then
1635 end Has_Side_Effect
;
1637 -- Start of processing for Is_Exception_Safe
1640 -- If the checks handled by the back end are not disabled, we cannot
1641 -- ensure that no exception will be raised.
1643 if not Access_Checks_Suppressed
(Empty
)
1644 or else not Discriminant_Checks_Suppressed
(Empty
)
1645 or else not Range_Checks_Suppressed
(Empty
)
1646 or else not Index_Checks_Suppressed
(Empty
)
1647 or else Opt
.Stack_Checking_Enabled
1652 if Has_Side_Effect
(First
(Declarations
(Subprogram
)))
1655 First
(Statements
(Handled_Statement_Sequence
(Subprogram
))))
1661 end Is_Exception_Safe
;
1663 -- Start of processing for Build_Protected_Subprogram_Body
1666 Op_Spec
:= Specification
(N
);
1667 Exc_Safe
:= Is_Exception_Safe
(N
);
1670 Build_Protected_Sub_Specification
(N
,
1671 Pid
, Unprotected
=> False);
1673 -- Build a list of the formal parameters of the protected
1674 -- version of the subprogram to use as the actual parameters
1675 -- of the unprotected version.
1677 Uactuals
:= New_List
;
1678 Pformal
:= First
(Parameter_Specifications
(P_Op_Spec
));
1680 while Present
(Pformal
) loop
1682 Make_Identifier
(Loc
, Chars
(Defining_Identifier
(Pformal
))),
1687 -- Make a call to the unprotected version of the subprogram
1688 -- built above for use by the protected version built below.
1690 if Nkind
(Op_Spec
) = N_Function_Specification
then
1692 R
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
1694 Make_Object_Declaration
(Loc
,
1695 Defining_Identifier
=> R
,
1696 Constant_Present
=> True,
1697 Object_Definition
=> New_Copy
(Subtype_Mark
(N_Op_Spec
)),
1699 Make_Function_Call
(Loc
,
1700 Name
=> Make_Identifier
(Loc
,
1701 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
1702 Parameter_Associations
=> Uactuals
));
1703 Return_Stmt
:= Make_Return_Statement
(Loc
,
1704 Expression
=> New_Reference_To
(R
, Loc
));
1707 Unprot_Call
:= Make_Return_Statement
(Loc
,
1708 Expression
=> Make_Function_Call
(Loc
,
1710 Make_Identifier
(Loc
,
1711 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
1712 Parameter_Associations
=> Uactuals
));
1716 Unprot_Call
:= Make_Procedure_Call_Statement
(Loc
,
1718 Make_Identifier
(Loc
,
1719 Chars
(Defining_Unit_Name
(N_Op_Spec
))),
1720 Parameter_Associations
=> Uactuals
);
1723 -- Wrap call in block that will be covered by an at_end handler
1725 if not Exc_Safe
then
1726 Unprot_Call
:= Make_Block_Statement
(Loc
,
1727 Handled_Statement_Sequence
=>
1728 Make_Handled_Sequence_Of_Statements
(Loc
,
1729 Statements
=> New_List
(Unprot_Call
)));
1732 -- Make the protected subprogram body. This locks the protected
1733 -- object and calls the unprotected version of the subprogram.
1735 -- If the protected object is controlled (i.e it has entries or
1736 -- needs finalization for interrupt handling), call Lock_Entries,
1737 -- except if the protected object follows the Ravenscar profile, in
1738 -- which case call Lock_Entry, otherwise call the simplified version,
1741 if Has_Entries
(Pid
)
1742 or else Has_Interrupt_Handler
(Pid
)
1743 or else (Has_Attach_Handler
(Pid
) and then not Restricted_Profile
)
1746 or else Restriction_Active
(No_Entry_Queue
) = False
1747 or else Number_Entries
(Pid
) > 1
1749 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entries
), Loc
);
1750 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entries
), Loc
);
1753 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock_Entry
), Loc
);
1754 Service_Name
:= New_Reference_To
(RTE
(RE_Service_Entry
), Loc
);
1758 Lock_Name
:= New_Reference_To
(RTE
(RE_Lock
), Loc
);
1759 Service_Name
:= New_Reference_To
(RTE
(RE_Unlock
), Loc
);
1763 Make_Attribute_Reference
(Loc
,
1765 Make_Selected_Component
(Loc
,
1767 Make_Identifier
(Loc
, Name_uObject
),
1769 Make_Identifier
(Loc
, Name_uObject
)),
1770 Attribute_Name
=> Name_Unchecked_Access
);
1772 Lock_Stmt
:= Make_Procedure_Call_Statement
(Loc
,
1774 Parameter_Associations
=> New_List
(Object_Parm
));
1776 if Abort_Allowed
then
1778 Make_Procedure_Call_Statement
(Loc
,
1779 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
1780 Parameter_Associations
=> Empty_List
),
1784 Stmts
:= New_List
(Lock_Stmt
);
1787 if not Exc_Safe
then
1788 Append
(Unprot_Call
, Stmts
);
1790 if Nkind
(Op_Spec
) = N_Function_Specification
then
1792 Stmts
:= Empty_List
;
1794 Append
(Unprot_Call
, Stmts
);
1798 Make_Procedure_Call_Statement
(Loc
,
1799 Name
=> Service_Name
,
1800 Parameter_Associations
=>
1801 New_List
(New_Copy_Tree
(Object_Parm
))),
1804 if Abort_Allowed
then
1806 Make_Procedure_Call_Statement
(Loc
,
1807 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
),
1808 Parameter_Associations
=> Empty_List
),
1812 if Nkind
(Op_Spec
) = N_Function_Specification
then
1813 Append
(Return_Stmt
, Stmts
);
1814 Append
(Make_Block_Statement
(Loc
,
1815 Declarations
=> New_List
(Unprot_Call
),
1816 Handled_Statement_Sequence
=>
1817 Make_Handled_Sequence_Of_Statements
(Loc
,
1818 Statements
=> Stmts
)), Pre_Stmts
);
1824 Make_Subprogram_Body
(Loc
,
1825 Declarations
=> Empty_List
,
1826 Specification
=> P_Op_Spec
,
1827 Handled_Statement_Sequence
=>
1828 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stmts
));
1830 if not Exc_Safe
then
1831 Set_Is_Protected_Subprogram_Body
(Sub_Body
);
1835 end Build_Protected_Subprogram_Body
;
1837 -------------------------------------
1838 -- Build_Protected_Subprogram_Call --
1839 -------------------------------------
1841 procedure Build_Protected_Subprogram_Call
1845 External
: Boolean := True)
1847 Loc
: constant Source_Ptr
:= Sloc
(N
);
1848 Sub
: constant Entity_Id
:= Entity
(Name
);
1854 New_Sub
:= New_Occurrence_Of
(External_Subprogram
(Sub
), Loc
);
1857 New_Occurrence_Of
(Protected_Body_Subprogram
(Sub
), Loc
);
1860 if Present
(Parameter_Associations
(N
)) then
1861 Params
:= New_Copy_List_Tree
(Parameter_Associations
(N
));
1866 Prepend
(Rec
, Params
);
1868 if Ekind
(Sub
) = E_Procedure
then
1870 Make_Procedure_Call_Statement
(Loc
,
1872 Parameter_Associations
=> Params
));
1875 pragma Assert
(Ekind
(Sub
) = E_Function
);
1877 Make_Function_Call
(Loc
,
1879 Parameter_Associations
=> Params
));
1883 and then Nkind
(Rec
) = N_Unchecked_Type_Conversion
1884 and then Is_Entity_Name
(Expression
(Rec
))
1885 and then Is_Shared_Passive
(Entity
(Expression
(Rec
)))
1887 Add_Shared_Var_Lock_Procs
(N
);
1889 end Build_Protected_Subprogram_Call
;
1891 -------------------------
1892 -- Build_Selected_Name --
1893 -------------------------
1895 function Build_Selected_Name
1896 (Prefix
, Selector
: Name_Id
;
1897 Append_Char
: Character := ' ') return Name_Id
1899 Select_Buffer
: String (1 .. Hostparm
.Max_Name_Length
);
1900 Select_Len
: Natural;
1903 Get_Name_String
(Selector
);
1904 Select_Len
:= Name_Len
;
1905 Select_Buffer
(1 .. Select_Len
) := Name_Buffer
(1 .. Name_Len
);
1906 Get_Name_String
(Prefix
);
1908 -- If scope is anonymous type, discard suffix to recover name of
1909 -- single protected object. Otherwise use protected type name.
1911 if Name_Buffer
(Name_Len
) = 'T' then
1912 Name_Len
:= Name_Len
- 1;
1915 Name_Buffer
(Name_Len
+ 1) := '_';
1916 Name_Buffer
(Name_Len
+ 2) := '_';
1918 Name_Len
:= Name_Len
+ 2;
1919 for J
in 1 .. Select_Len
loop
1920 Name_Len
:= Name_Len
+ 1;
1921 Name_Buffer
(Name_Len
) := Select_Buffer
(J
);
1924 if Append_Char
/= ' ' then
1925 Name_Len
:= Name_Len
+ 1;
1926 Name_Buffer
(Name_Len
) := Append_Char
;
1930 end Build_Selected_Name
;
1932 -----------------------------
1933 -- Build_Simple_Entry_Call --
1934 -----------------------------
1936 -- A task entry call is converted to a call to Call_Simple
1939 -- P : parms := (parm, parm, parm);
1941 -- Call_Simple (acceptor-task, entry-index, P'Address);
1947 -- Here Pnn is an aggregate of the type constructed for the entry to hold
1948 -- the parameters, and the constructed aggregate value contains either the
1949 -- parameters or, in the case of non-elementary types, references to these
1950 -- parameters. Then the address of this aggregate is passed to the runtime
1951 -- routine, along with the task id value and the task entry index value.
1952 -- Pnn is only required if parameters are present.
1954 -- The assignments after the call are present only in the case of in-out
1955 -- or out parameters for elementary types, and are used to assign back the
1956 -- resulting values of such parameters.
1958 -- Note: the reason that we insert a block here is that in the context
1959 -- of selects, conditional entry calls etc. the entry call statement
1960 -- appears on its own, not as an element of a list.
1962 -- A protected entry call is converted to a Protected_Entry_Call:
1965 -- P : E1_Params := (param, param, param);
1967 -- Bnn : Communications_Block;
1970 -- P : E1_Params := (param, param, param);
1971 -- Bnn : Communications_Block;
1974 -- Protected_Entry_Call (
1975 -- Object => po._object'Access,
1976 -- E => <entry index>;
1977 -- Uninterpreted_Data => P'Address;
1978 -- Mode => Simple_Call;
1985 procedure Build_Simple_Entry_Call
1994 -- Convert entry call to Call_Simple call
1997 Loc
: constant Source_Ptr
:= Sloc
(N
);
1998 Parms
: constant List_Id
:= Parameter_Associations
(N
);
1999 Stats
: constant List_Id
:= New_List
;
2005 Ent_Acc
: Entity_Id
;
2017 Comm_Name
: Entity_Id
;
2020 -- Simple entry and entry family cases merge here
2022 Ent
:= Entity
(Ename
);
2023 Ent_Acc
:= Entry_Parameters_Type
(Ent
);
2024 Conctyp
:= Etype
(Concval
);
2026 -- If prefix is an access type, dereference to obtain the task type
2028 if Is_Access_Type
(Conctyp
) then
2029 Conctyp
:= Designated_Type
(Conctyp
);
2032 -- Special case for protected subprogram calls
2034 if Is_Protected_Type
(Conctyp
)
2035 and then Is_Subprogram
(Entity
(Ename
))
2037 if not Is_Eliminated
(Entity
(Ename
)) then
2038 Build_Protected_Subprogram_Call
2039 (N
, Ename
, Convert_Concurrent
(Concval
, Conctyp
));
2046 -- First parameter is the Task_Id value from the task value or the
2047 -- Object from the protected object value, obtained by selecting
2048 -- the _Task_Id or _Object from the result of doing an unchecked
2049 -- conversion to convert the value to the corresponding record type.
2051 Parm1
:= Concurrent_Ref
(Concval
);
2053 -- Second parameter is the entry index, computed by the routine
2054 -- provided for this purpose. The value of this expression is
2055 -- assigned to an intermediate variable to assure that any entry
2056 -- family index expressions are evaluated before the entry
2060 or else Restriction_Active
(No_Entry_Queue
) = False
2061 or else not Is_Protected_Type
(Conctyp
)
2062 or else Number_Entries
(Conctyp
) > 1
2064 X
:= Make_Defining_Identifier
(Loc
, Name_uX
);
2067 Make_Object_Declaration
(Loc
,
2068 Defining_Identifier
=> X
,
2069 Object_Definition
=>
2070 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2071 Expression
=> Actual_Index_Expression
(
2072 Loc
, Entity
(Ename
), Index
, Concval
));
2074 Decls
:= New_List
(Xdecl
);
2075 Parm2
:= New_Reference_To
(X
, Loc
);
2083 -- The third parameter is the packaged parameters. If there are
2084 -- none, then it is just the null address, since nothing is passed
2087 Parm3
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
2090 -- Case of parameters present, where third argument is the address
2091 -- of a packaged record containing the required parameter values.
2094 -- First build a list of parameter values, which are
2095 -- references to objects of the parameter types.
2099 Actual
:= First_Actual
(N
);
2100 Formal
:= First_Formal
(Ent
);
2102 while Present
(Actual
) loop
2104 -- If it is a by_copy_type, copy it to a new variable. The
2105 -- packaged record has a field that points to this variable.
2107 if Is_By_Copy_Type
(Etype
(Actual
)) then
2109 Make_Object_Declaration
(Loc
,
2110 Defining_Identifier
=>
2111 Make_Defining_Identifier
(Loc
,
2112 Chars
=> New_Internal_Name
('J')),
2113 Aliased_Present
=> True,
2114 Object_Definition
=>
2115 New_Reference_To
(Etype
(Formal
), Loc
));
2117 -- We have to make an assignment statement separate for
2118 -- the case of limited type. We can not assign it unless
2119 -- the Assignment_OK flag is set first.
2121 if Ekind
(Formal
) /= E_Out_Parameter
then
2123 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
);
2124 Set_Assignment_OK
(N_Var
);
2126 Make_Assignment_Statement
(Loc
,
2128 Expression
=> Relocate_Node
(Actual
)));
2131 Append
(N_Node
, Decls
);
2134 Make_Attribute_Reference
(Loc
,
2135 Attribute_Name
=> Name_Unchecked_Access
,
2137 New_Reference_To
(Defining_Identifier
(N_Node
), Loc
)));
2140 Make_Reference
(Loc
, Prefix
=> Relocate_Node
(Actual
)));
2143 Next_Actual
(Actual
);
2144 Next_Formal_With_Extras
(Formal
);
2147 -- Now build the declaration of parameters initialized with the
2148 -- aggregate containing this constructed parameter list.
2150 P
:= Make_Defining_Identifier
(Loc
, Name_uP
);
2153 Make_Object_Declaration
(Loc
,
2154 Defining_Identifier
=> P
,
2155 Object_Definition
=>
2156 New_Reference_To
(Designated_Type
(Ent_Acc
), Loc
),
2158 Make_Aggregate
(Loc
, Expressions
=> Plist
));
2161 Make_Attribute_Reference
(Loc
,
2162 Attribute_Name
=> Name_Address
,
2163 Prefix
=> New_Reference_To
(P
, Loc
));
2165 Append
(Pdecl
, Decls
);
2168 -- Now we can create the call, case of protected type
2170 if Is_Protected_Type
(Conctyp
) then
2172 or else Restriction_Active
(No_Entry_Queue
) = False
2173 or else Number_Entries
(Conctyp
) > 1
2175 -- Change the type of the index declaration
2177 Set_Object_Definition
(Xdecl
,
2178 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
));
2180 -- Some additional declarations for protected entry calls
2186 -- Bnn : Communications_Block;
2189 Make_Defining_Identifier
(Loc
, New_Internal_Name
('B'));
2192 Make_Object_Declaration
(Loc
,
2193 Defining_Identifier
=> Comm_Name
,
2194 Object_Definition
=>
2195 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2197 -- Some additional statements for protected entry calls
2199 -- Protected_Entry_Call (
2200 -- Object => po._object'Access,
2201 -- E => <entry index>;
2202 -- Uninterpreted_Data => P'Address;
2203 -- Mode => Simple_Call;
2207 Make_Procedure_Call_Statement
(Loc
,
2209 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2211 Parameter_Associations
=> New_List
(
2212 Make_Attribute_Reference
(Loc
,
2213 Attribute_Name
=> Name_Unchecked_Access
,
2217 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
),
2218 New_Occurrence_Of
(Comm_Name
, Loc
)));
2221 -- Protected_Single_Entry_Call (
2222 -- Object => po._object'Access,
2223 -- Uninterpreted_Data => P'Address;
2224 -- Mode => Simple_Call);
2227 Make_Procedure_Call_Statement
(Loc
,
2228 Name
=> New_Reference_To
(
2229 RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2231 Parameter_Associations
=> New_List
(
2232 Make_Attribute_Reference
(Loc
,
2233 Attribute_Name
=> Name_Unchecked_Access
,
2236 New_Reference_To
(RTE
(RE_Simple_Call
), Loc
)));
2239 -- Case of task type
2243 Make_Procedure_Call_Statement
(Loc
,
2244 Name
=> New_Reference_To
(RTE
(RE_Call_Simple
), Loc
),
2245 Parameter_Associations
=> New_List
(Parm1
, Parm2
, Parm3
));
2249 Append_To
(Stats
, Call
);
2251 -- If there are out or in/out parameters by copy
2252 -- add assignment statements for the result values.
2254 if Present
(Parms
) then
2255 Actual
:= First_Actual
(N
);
2256 Formal
:= First_Formal
(Ent
);
2258 Set_Assignment_OK
(Actual
);
2259 while Present
(Actual
) loop
2260 if Is_By_Copy_Type
(Etype
(Actual
))
2261 and then Ekind
(Formal
) /= E_In_Parameter
2264 Make_Assignment_Statement
(Loc
,
2265 Name
=> New_Copy
(Actual
),
2267 Make_Explicit_Dereference
(Loc
,
2268 Make_Selected_Component
(Loc
,
2269 Prefix
=> New_Reference_To
(P
, Loc
),
2271 Make_Identifier
(Loc
, Chars
(Formal
)))));
2273 -- In all cases (including limited private types) we
2274 -- want the assignment to be valid.
2276 Set_Assignment_OK
(Name
(N_Node
));
2278 -- If the call is the triggering alternative in an
2279 -- asynchronous select, or the entry_call alternative
2280 -- of a conditional entry call, the assignments for in-out
2281 -- parameters are incorporated into the statement list
2282 -- that follows, so that there are executed only if the
2283 -- entry call succeeds.
2285 if (Nkind
(Parent
(N
)) = N_Triggering_Alternative
2286 and then N
= Triggering_Statement
(Parent
(N
)))
2288 (Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
2289 and then N
= Entry_Call_Statement
(Parent
(N
)))
2291 if No
(Statements
(Parent
(N
))) then
2292 Set_Statements
(Parent
(N
), New_List
);
2295 Prepend
(N_Node
, Statements
(Parent
(N
)));
2298 Insert_After
(Call
, N_Node
);
2302 Next_Actual
(Actual
);
2303 Next_Formal_With_Extras
(Formal
);
2307 -- Finally, create block and analyze it
2310 Make_Block_Statement
(Loc
,
2311 Declarations
=> Decls
,
2312 Handled_Statement_Sequence
=>
2313 Make_Handled_Sequence_Of_Statements
(Loc
,
2314 Statements
=> Stats
)));
2318 end Build_Simple_Entry_Call
;
2320 --------------------------------
2321 -- Build_Task_Activation_Call --
2322 --------------------------------
2324 procedure Build_Task_Activation_Call
(N
: Node_Id
) is
2325 Loc
: constant Source_Ptr
:= Sloc
(N
);
2332 -- Get the activation chain entity. Except in the case of a package
2333 -- body, this is in the node that w as passed. For a package body, we
2334 -- have to find the corresponding package declaration node.
2336 if Nkind
(N
) = N_Package_Body
then
2337 P
:= Corresponding_Spec
(N
);
2341 exit when Nkind
(P
) = N_Package_Declaration
;
2344 Chain
:= Activation_Chain_Entity
(P
);
2347 Chain
:= Activation_Chain_Entity
(N
);
2350 if Present
(Chain
) then
2351 if Restricted_Profile
then
2352 Name
:= New_Reference_To
(RTE
(RE_Activate_Restricted_Tasks
), Loc
);
2354 Name
:= New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
);
2358 Make_Procedure_Call_Statement
(Loc
,
2360 Parameter_Associations
=>
2361 New_List
(Make_Attribute_Reference
(Loc
,
2362 Prefix
=> New_Occurrence_Of
(Chain
, Loc
),
2363 Attribute_Name
=> Name_Unchecked_Access
)));
2365 if Nkind
(N
) = N_Package_Declaration
then
2366 if Present
(Corresponding_Body
(N
)) then
2369 elsif Present
(Private_Declarations
(Specification
(N
))) then
2370 Append
(Call
, Private_Declarations
(Specification
(N
)));
2373 Append
(Call
, Visible_Declarations
(Specification
(N
)));
2377 if Present
(Handled_Statement_Sequence
(N
)) then
2379 -- The call goes at the start of the statement sequence, but
2380 -- after the start of exception range label if one is present.
2386 Stm
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
2388 if Nkind
(Stm
) = N_Label
and then Exception_Junk
(Stm
) then
2392 Insert_Before
(Stm
, Call
);
2396 Set_Handled_Statement_Sequence
(N
,
2397 Make_Handled_Sequence_Of_Statements
(Loc
,
2398 Statements
=> New_List
(Call
)));
2403 Check_Task_Activation
(N
);
2405 end Build_Task_Activation_Call
;
2407 -------------------------------
2408 -- Build_Task_Allocate_Block --
2409 -------------------------------
2411 procedure Build_Task_Allocate_Block
2416 T
: constant Entity_Id
:= Entity
(Expression
(N
));
2417 Init
: constant Entity_Id
:= Base_Init_Proc
(T
);
2418 Loc
: constant Source_Ptr
:= Sloc
(N
);
2419 Chain
: constant Entity_Id
:=
2420 Make_Defining_Identifier
(Loc
, Name_uChain
);
2426 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
2429 Make_Block_Statement
(Loc
,
2430 Identifier
=> New_Reference_To
(Blkent
, Loc
),
2431 Declarations
=> New_List
(
2433 -- _Chain : Activation_Chain;
2435 Make_Object_Declaration
(Loc
,
2436 Defining_Identifier
=> Chain
,
2437 Aliased_Present
=> True,
2438 Object_Definition
=>
2439 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
2441 Handled_Statement_Sequence
=>
2442 Make_Handled_Sequence_Of_Statements
(Loc
,
2444 Statements
=> New_List
(
2448 Make_Procedure_Call_Statement
(Loc
,
2449 Name
=> New_Reference_To
(Init
, Loc
),
2450 Parameter_Associations
=> Args
),
2452 -- Activate_Tasks (_Chain);
2454 Make_Procedure_Call_Statement
(Loc
,
2455 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
2456 Parameter_Associations
=> New_List
(
2457 Make_Attribute_Reference
(Loc
,
2458 Prefix
=> New_Reference_To
(Chain
, Loc
),
2459 Attribute_Name
=> Name_Unchecked_Access
))))),
2461 Has_Created_Identifier
=> True,
2462 Is_Task_Allocation_Block
=> True);
2465 Make_Implicit_Label_Declaration
(Loc
,
2466 Defining_Identifier
=> Blkent
,
2467 Label_Construct
=> Block
));
2469 Append_To
(Actions
, Block
);
2471 Set_Activation_Chain_Entity
(Block
, Chain
);
2472 end Build_Task_Allocate_Block
;
2474 -----------------------------------------------
2475 -- Build_Task_Allocate_Block_With_Init_Stmts --
2476 -----------------------------------------------
2478 procedure Build_Task_Allocate_Block_With_Init_Stmts
2481 Init_Stmts
: List_Id
)
2483 Loc
: constant Source_Ptr
:= Sloc
(N
);
2484 Chain
: constant Entity_Id
:=
2485 Make_Defining_Identifier
(Loc
, Name_uChain
);
2490 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
2492 Append_To
(Init_Stmts
,
2493 Make_Procedure_Call_Statement
(Loc
,
2494 Name
=> New_Reference_To
(RTE
(RE_Activate_Tasks
), Loc
),
2495 Parameter_Associations
=> New_List
(
2496 Make_Attribute_Reference
(Loc
,
2497 Prefix
=> New_Reference_To
(Chain
, Loc
),
2498 Attribute_Name
=> Name_Unchecked_Access
))));
2501 Make_Block_Statement
(Loc
,
2502 Identifier
=> New_Reference_To
(Blkent
, Loc
),
2503 Declarations
=> New_List
(
2505 -- _Chain : Activation_Chain;
2507 Make_Object_Declaration
(Loc
,
2508 Defining_Identifier
=> Chain
,
2509 Aliased_Present
=> True,
2510 Object_Definition
=>
2511 New_Reference_To
(RTE
(RE_Activation_Chain
), Loc
))),
2513 Handled_Statement_Sequence
=>
2514 Make_Handled_Sequence_Of_Statements
(Loc
, Init_Stmts
),
2516 Has_Created_Identifier
=> True,
2517 Is_Task_Allocation_Block
=> True);
2520 Make_Implicit_Label_Declaration
(Loc
,
2521 Defining_Identifier
=> Blkent
,
2522 Label_Construct
=> Block
));
2524 Append_To
(Actions
, Block
);
2526 Set_Activation_Chain_Entity
(Block
, Chain
);
2527 end Build_Task_Allocate_Block_With_Init_Stmts
;
2529 -----------------------------------
2530 -- Build_Task_Proc_Specification --
2531 -----------------------------------
2533 function Build_Task_Proc_Specification
(T
: Entity_Id
) return Node_Id
is
2534 Loc
: constant Source_Ptr
:= Sloc
(T
);
2535 Nam
: constant Name_Id
:= Chars
(T
);
2540 Make_Defining_Identifier
(Loc
,
2541 Chars
=> New_External_Name
(Nam
, 'B'));
2542 Set_Is_Internal
(Ent
);
2544 -- Associate the procedure with the task, if this is the declaration
2545 -- (and not the body) of the procedure.
2547 if No
(Task_Body_Procedure
(T
)) then
2548 Set_Task_Body_Procedure
(T
, Ent
);
2552 Make_Procedure_Specification
(Loc
,
2553 Defining_Unit_Name
=> Ent
,
2554 Parameter_Specifications
=>
2556 Make_Parameter_Specification
(Loc
,
2557 Defining_Identifier
=>
2558 Make_Defining_Identifier
(Loc
, Name_uTask
),
2560 Make_Access_Definition
(Loc
,
2563 (Corresponding_Record_Type
(T
), Loc
)))));
2564 end Build_Task_Proc_Specification
;
2566 ---------------------------------------
2567 -- Build_Unprotected_Subprogram_Body --
2568 ---------------------------------------
2570 function Build_Unprotected_Subprogram_Body
2572 Pid
: Node_Id
) return Node_Id
2574 Loc
: constant Source_Ptr
:= Sloc
(N
);
2575 N_Op_Spec
: Node_Id
;
2579 -- Make an unprotected version of the subprogram for use
2580 -- within the same object, with a new name and an additional
2581 -- parameter representing the object.
2583 Op_Decls
:= Declarations
(N
);
2585 Build_Protected_Sub_Specification
2586 (N
, Pid
, Unprotected
=> True);
2589 Make_Subprogram_Body
(Loc
,
2590 Specification
=> N_Op_Spec
,
2591 Declarations
=> Op_Decls
,
2592 Handled_Statement_Sequence
=>
2593 Handled_Statement_Sequence
(N
));
2594 end Build_Unprotected_Subprogram_Body
;
2596 ----------------------------
2597 -- Collect_Entry_Families --
2598 ----------------------------
2600 procedure Collect_Entry_Families
2603 Current_Node
: in out Node_Id
;
2604 Conctyp
: Entity_Id
)
2607 Efam_Decl
: Node_Id
;
2608 Efam_Type
: Entity_Id
;
2611 Efam
:= First_Entity
(Conctyp
);
2613 while Present
(Efam
) loop
2615 if Ekind
(Efam
) = E_Entry_Family
then
2617 Make_Defining_Identifier
(Loc
,
2618 Chars
=> New_Internal_Name
('F'));
2621 Make_Full_Type_Declaration
(Loc
,
2622 Defining_Identifier
=> Efam_Type
,
2624 Make_Unconstrained_Array_Definition
(Loc
,
2625 Subtype_Marks
=> (New_List
(
2628 (Etype
(Discrete_Subtype_Definition
2629 (Parent
(Efam
)))), Loc
))),
2631 Component_Definition
=>
2632 Make_Component_Definition
(Loc
,
2633 Aliased_Present
=> False,
2634 Subtype_Indication
=>
2635 New_Reference_To
(Standard_Character
, Loc
))));
2637 Insert_After
(Current_Node
, Efam_Decl
);
2638 Current_Node
:= Efam_Decl
;
2639 Analyze
(Efam_Decl
);
2642 Make_Component_Declaration
(Loc
,
2643 Defining_Identifier
=>
2644 Make_Defining_Identifier
(Loc
, Chars
(Efam
)),
2646 Component_Definition
=>
2647 Make_Component_Definition
(Loc
,
2648 Aliased_Present
=> False,
2649 Subtype_Indication
=>
2650 Make_Subtype_Indication
(Loc
,
2652 New_Occurrence_Of
(Efam_Type
, Loc
),
2655 Make_Index_Or_Discriminant_Constraint
(Loc
,
2656 Constraints
=> New_List
(
2658 (Etype
(Discrete_Subtype_Definition
2659 (Parent
(Efam
))), Loc
)))))));
2665 end Collect_Entry_Families
;
2667 --------------------
2668 -- Concurrent_Ref --
2669 --------------------
2671 -- The expression returned for a reference to a concurrent
2672 -- object has the form:
2674 -- taskV!(name)._Task_Id
2678 -- objectV!(name)._Object
2680 -- for a protected object. For the case of an access to a concurrent
2681 -- object, there is an extra explicit dereference:
2683 -- taskV!(name.all)._Task_Id
2684 -- objectV!(name.all)._Object
2686 -- here taskV and objectV are the types for the associated records, which
2687 -- contain the required _Task_Id and _Object fields for tasks and
2688 -- protected objects, respectively.
2690 -- For the case of a task type name, the expression is
2694 -- i.e. a call to the Self function which returns precisely this Task_Id
2696 -- For the case of a protected type name, the expression is
2700 -- which is a renaming of the _object field of the current object
2701 -- object record, passed into protected operations as a parameter.
2703 function Concurrent_Ref
(N
: Node_Id
) return Node_Id
is
2704 Loc
: constant Source_Ptr
:= Sloc
(N
);
2705 Ntyp
: constant Entity_Id
:= Etype
(N
);
2709 function Is_Current_Task
(T
: Entity_Id
) return Boolean;
2710 -- Check whether the reference is to the immediately enclosing task
2711 -- type, or to an outer one (rare but legal).
2713 ---------------------
2714 -- Is_Current_Task --
2715 ---------------------
2717 function Is_Current_Task
(T
: Entity_Id
) return Boolean is
2721 Scop
:= Current_Scope
;
2722 while Present
(Scop
)
2723 and then Scop
/= Standard_Standard
2729 elsif Is_Task_Type
(Scop
) then
2732 -- If this is a procedure nested within the task type, we must
2733 -- assume that it can be called from an inner task, and therefore
2734 -- cannot treat it as a local reference.
2736 elsif Is_Overloadable
(Scop
)
2737 and then In_Open_Scopes
(T
)
2742 Scop
:= Scope
(Scop
);
2746 -- We know that we are within the task body, so should have
2747 -- found it in scope.
2749 raise Program_Error
;
2750 end Is_Current_Task
;
2752 -- Start of processing for Concurrent_Ref
2755 if Is_Access_Type
(Ntyp
) then
2756 Dtyp
:= Designated_Type
(Ntyp
);
2758 if Is_Protected_Type
(Dtyp
) then
2759 Sel
:= Name_uObject
;
2761 Sel
:= Name_uTask_Id
;
2765 Make_Selected_Component
(Loc
,
2767 Unchecked_Convert_To
(Corresponding_Record_Type
(Dtyp
),
2768 Make_Explicit_Dereference
(Loc
, N
)),
2769 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
2771 elsif Is_Entity_Name
(N
)
2772 and then Is_Concurrent_Type
(Entity
(N
))
2774 if Is_Task_Type
(Entity
(N
)) then
2776 if Is_Current_Task
(Entity
(N
)) then
2778 Make_Function_Call
(Loc
,
2779 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
));
2784 T_Self
: constant Entity_Id
2785 := Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
2786 T_Body
: constant Node_Id
2787 := Parent
(Corresponding_Body
(Parent
(Entity
(N
))));
2790 Decl
:= Make_Object_Declaration
(Loc
,
2791 Defining_Identifier
=> T_Self
,
2792 Object_Definition
=>
2793 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
2795 Make_Function_Call
(Loc
,
2796 Name
=> New_Reference_To
(RTE
(RE_Self
), Loc
)));
2797 Prepend
(Decl
, Declarations
(T_Body
));
2799 Set_Scope
(T_Self
, Entity
(N
));
2800 return New_Occurrence_Of
(T_Self
, Loc
);
2805 pragma Assert
(Is_Protected_Type
(Entity
(N
)));
2808 Object_Ref
(Corresponding_Body
(Parent
(Base_Type
(Ntyp
)))),
2813 pragma Assert
(Is_Concurrent_Type
(Ntyp
));
2815 if Is_Protected_Type
(Ntyp
) then
2816 Sel
:= Name_uObject
;
2818 Sel
:= Name_uTask_Id
;
2822 Make_Selected_Component
(Loc
,
2824 Unchecked_Convert_To
(Corresponding_Record_Type
(Ntyp
),
2826 Selector_Name
=> Make_Identifier
(Loc
, Sel
));
2830 ------------------------
2831 -- Convert_Concurrent --
2832 ------------------------
2834 function Convert_Concurrent
2836 Typ
: Entity_Id
) return Node_Id
2839 if not Is_Concurrent_Type
(Typ
) then
2843 Unchecked_Convert_To
(Corresponding_Record_Type
(Typ
),
2846 end Convert_Concurrent
;
2848 ----------------------------
2849 -- Entry_Index_Expression --
2850 ----------------------------
2852 function Entry_Index_Expression
2856 Ttyp
: Entity_Id
) return Node_Id
2866 -- The queues of entries and entry families appear in textual
2867 -- order in the associated record. The entry index is computed as
2868 -- the sum of the number of queues for all entries that precede the
2869 -- designated one, to which is added the index expression, if this
2870 -- expression denotes a member of a family.
2872 -- The following is a place holder for the count of simple entries
2874 Num
:= Make_Integer_Literal
(Sloc
, 1);
2876 -- We construct an expression which is a series of addition
2877 -- operations. The first operand is the number of single entries that
2878 -- precede this one, the second operand is the index value relative
2879 -- to the start of the referenced family, and the remaining operands
2880 -- are the lengths of the entry families that precede this entry, i.e.
2881 -- the constructed expression is:
2883 -- number_simple_entries +
2884 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
2885 -- family'length + ...
2887 -- where index-value is the given index value, and s is the index
2888 -- subtype (we have to use pos because the subtype might be an
2889 -- enumeration type preventing direct subtraction).
2890 -- Note that the task entry array is one-indexed.
2892 -- The upper bound of the entry family may be a discriminant, so we
2893 -- retrieve the lower bound explicitly to compute offset, rather than
2894 -- using the index subtype which may mention a discriminant.
2896 if Present
(Index
) then
2897 S
:= Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Ent
)));
2906 Make_Attribute_Reference
(Sloc
,
2907 Attribute_Name
=> Name_Pos
,
2908 Prefix
=> New_Reference_To
(Base_Type
(S
), Sloc
),
2909 Expressions
=> New_List
(Relocate_Node
(Index
))),
2916 -- Now add lengths of preceding entries and entry families
2918 Prev
:= First_Entity
(Ttyp
);
2920 while Chars
(Prev
) /= Chars
(Ent
)
2921 or else (Ekind
(Prev
) /= Ekind
(Ent
))
2922 or else not Sem_Ch6
.Type_Conformant
(Ent
, Prev
)
2924 if Ekind
(Prev
) = E_Entry
then
2925 Set_Intval
(Num
, Intval
(Num
) + 1);
2927 elsif Ekind
(Prev
) = E_Entry_Family
then
2929 Etype
(Discrete_Subtype_Definition
(Declaration_Node
(Prev
)));
2930 Lo
:= Type_Low_Bound
(S
);
2931 Hi
:= Type_High_Bound
(S
);
2936 Right_Opnd
=> Family_Size
(Sloc
, Hi
, Lo
, Ttyp
));
2938 -- Other components are anonymous types to be ignored
2948 end Entry_Index_Expression
;
2950 ---------------------------
2951 -- Establish_Task_Master --
2952 ---------------------------
2954 procedure Establish_Task_Master
(N
: Node_Id
) is
2958 if Restriction_Active
(No_Task_Hierarchy
) = False then
2959 Call
:= Build_Runtime_Call
(Sloc
(N
), RE_Enter_Master
);
2960 Prepend_To
(Declarations
(N
), Call
);
2963 end Establish_Task_Master
;
2965 --------------------------------
2966 -- Expand_Accept_Declarations --
2967 --------------------------------
2969 -- Part of the expansion of an accept statement involves the creation of
2970 -- a declaration that can be referenced from the statement sequence of
2975 -- This declaration is inserted immediately before the accept statement
2976 -- and it is important that it be inserted before the statements of the
2977 -- statement sequence are analyzed. Thus it would be too late to create
2978 -- this declaration in the Expand_N_Accept_Statement routine, which is
2979 -- why there is a separate procedure to be called directly from Sem_Ch9.
2981 -- Ann is used to hold the address of the record containing the parameters
2982 -- (see Expand_N_Entry_Call for more details on how this record is built).
2983 -- References to the parameters do an unchecked conversion of this address
2984 -- to a pointer to the required record type, and then access the field that
2985 -- holds the value of the required parameter. The entity for the address
2986 -- variable is held as the top stack element (i.e. the last element) of the
2987 -- Accept_Address stack in the corresponding entry entity, and this element
2988 -- must be set in place before the statements are processed.
2990 -- The above description applies to the case of a stand alone accept
2991 -- statement, i.e. one not appearing as part of a select alternative.
2993 -- For the case of an accept that appears as part of a select alternative
2994 -- of a selective accept, we must still create the declaration right away,
2995 -- since Ann is needed immediately, but there is an important difference:
2997 -- The declaration is inserted before the selective accept, not before
2998 -- the accept statement (which is not part of a list anyway, and so would
2999 -- not accommodate inserted declarations)
3001 -- We only need one address variable for the entire selective accept. So
3002 -- the Ann declaration is created only for the first accept alternative,
3003 -- and subsequent accept alternatives reference the same Ann variable.
3005 -- We can distinguish the two cases by seeing whether the accept statement
3006 -- is part of a list. If not, then it must be in an accept alternative.
3008 -- To expand the requeue statement, a label is provided at the end of
3009 -- the accept statement or alternative of which it is a part, so that
3010 -- the statement can be skipped after the requeue is complete.
3011 -- This label is created here rather than during the expansion of the
3012 -- accept statement, because it will be needed by any requeue
3013 -- statements within the accept, which are expanded before the
3016 procedure Expand_Accept_Declarations
(N
: Node_Id
; Ent
: Entity_Id
) is
3017 Loc
: constant Source_Ptr
:= Sloc
(N
);
3018 Ann
: Entity_Id
:= Empty
;
3026 if Expander_Active
then
3028 -- If we have no handled statement sequence, then build a dummy
3029 -- sequence consisting of a null statement. This is only done if
3030 -- pragma FIFO_Within_Priorities is specified. The issue here is
3031 -- that even a null accept body has an effect on the called task
3032 -- in terms of its position in the queue, so we cannot optimize
3033 -- the context switch away. However, if FIFO_Within_Priorities
3034 -- is not active, the optimization is legitimate, since we can
3035 -- say that our dispatching policy (i.e. the default dispatching
3036 -- policy) reorders the queue to be the same as just before the
3037 -- call. In the absence of a specified dispatching policy, we are
3038 -- allowed to modify queue orders for a given priority at will!
3040 if Opt
.Task_Dispatching_Policy
= 'F' and then
3041 not Present
(Handled_Statement_Sequence
(N
))
3043 Set_Handled_Statement_Sequence
(N
,
3044 Make_Handled_Sequence_Of_Statements
(Loc
,
3045 New_List
(Make_Null_Statement
(Loc
))));
3048 -- Create and declare two labels to be placed at the end of the
3049 -- accept statement. The first label is used to allow requeues to
3050 -- skip the remainder of entry processing. The second label is
3051 -- used to skip the remainder of entry processing if the rendezvous
3052 -- completes in the middle of the accept body.
3054 if Present
(Handled_Statement_Sequence
(N
)) then
3055 Lab_Id
:= Make_Identifier
(Loc
, New_Internal_Name
('L'));
3057 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)));
3058 Lab
:= Make_Label
(Loc
, Lab_Id
);
3060 Make_Implicit_Label_Declaration
(Loc
,
3061 Defining_Identifier
=> Entity
(Lab_Id
),
3062 Label_Construct
=> Lab
);
3063 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
3065 Lab_Id
:= Make_Identifier
(Loc
, New_Internal_Name
('L'));
3067 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)));
3068 Lab
:= Make_Label
(Loc
, Lab_Id
);
3070 Make_Implicit_Label_Declaration
(Loc
,
3071 Defining_Identifier
=> Entity
(Lab_Id
),
3072 Label_Construct
=> Lab
);
3073 Append
(Lab
, Statements
(Handled_Statement_Sequence
(N
)));
3080 -- Case of stand alone accept statement
3082 if Is_List_Member
(N
) then
3084 if Present
(Handled_Statement_Sequence
(N
)) then
3086 Make_Defining_Identifier
(Loc
,
3087 Chars
=> New_Internal_Name
('A'));
3090 Make_Object_Declaration
(Loc
,
3091 Defining_Identifier
=> Ann
,
3092 Object_Definition
=>
3093 New_Reference_To
(RTE
(RE_Address
), Loc
));
3095 Insert_Before
(N
, Adecl
);
3098 Insert_Before
(N
, Ldecl
);
3101 Insert_Before
(N
, Ldecl2
);
3105 -- Case of accept statement which is in an accept alternative
3109 Acc_Alt
: constant Node_Id
:= Parent
(N
);
3110 Sel_Acc
: constant Node_Id
:= Parent
(Acc_Alt
);
3114 pragma Assert
(Nkind
(Acc_Alt
) = N_Accept_Alternative
);
3115 pragma Assert
(Nkind
(Sel_Acc
) = N_Selective_Accept
);
3117 -- ??? Consider a single label for select statements
3119 if Present
(Handled_Statement_Sequence
(N
)) then
3121 Statements
(Handled_Statement_Sequence
(N
)));
3125 Statements
(Handled_Statement_Sequence
(N
)));
3129 -- Find first accept alternative of the selective accept. A
3130 -- valid selective accept must have at least one accept in it.
3132 Alt
:= First
(Select_Alternatives
(Sel_Acc
));
3134 while Nkind
(Alt
) /= N_Accept_Alternative
loop
3138 -- If we are the first accept statement, then we have to
3139 -- create the Ann variable, as for the stand alone case,
3140 -- except that it is inserted before the selective accept.
3141 -- Similarly, a label for requeue expansion must be
3144 if N
= Accept_Statement
(Alt
) then
3146 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3149 Make_Object_Declaration
(Loc
,
3150 Defining_Identifier
=> Ann
,
3151 Object_Definition
=>
3152 New_Reference_To
(RTE
(RE_Address
), Loc
));
3154 Insert_Before
(Sel_Acc
, Adecl
);
3157 -- If we are not the first accept statement, then find the
3158 -- Ann variable allocated by the first accept and use it.
3162 Node
(Last_Elmt
(Accept_Address
3163 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
))))));
3168 -- Merge here with Ann either created or referenced, and Adecl
3169 -- pointing to the corresponding declaration. Remaining processing
3170 -- is the same for the two cases.
3172 if Present
(Ann
) then
3173 Append_Elmt
(Ann
, Accept_Address
(Ent
));
3174 Set_Needs_Debug_Info
(Ann
);
3177 -- Create renaming declarations for the entry formals. Each
3178 -- reference to a formal becomes a dereference of a component
3179 -- of the parameter block, whose address is held in Ann.
3180 -- These declarations are eventually inserted into the accept
3181 -- block, and analyzed there so that they have the proper scope
3182 -- for gdb and do not conflict with other declarations.
3184 if Present
(Parameter_Specifications
(N
))
3185 and then Present
(Handled_Statement_Sequence
(N
))
3195 Formal
:= First_Formal
(Ent
);
3197 while Present
(Formal
) loop
3198 Comp
:= Entry_Component
(Formal
);
3200 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
3201 Set_Etype
(New_F
, Etype
(Formal
));
3202 Set_Scope
(New_F
, Ent
);
3203 Set_Needs_Debug_Info
(New_F
); -- That's the whole point.
3205 if Ekind
(Formal
) = E_In_Parameter
then
3206 Set_Ekind
(New_F
, E_Constant
);
3208 Set_Ekind
(New_F
, E_Variable
);
3209 Set_Extra_Constrained
(New_F
, Extra_Constrained
(Formal
));
3212 Set_Actual_Subtype
(New_F
, Actual_Subtype
(Formal
));
3215 Make_Object_Renaming_Declaration
(Loc
,
3216 Defining_Identifier
=> New_F
,
3217 Subtype_Mark
=> New_Reference_To
(Etype
(Formal
), Loc
),
3219 Make_Explicit_Dereference
(Loc
,
3220 Make_Selected_Component
(Loc
,
3222 Unchecked_Convert_To
(Entry_Parameters_Type
(Ent
),
3223 New_Reference_To
(Ann
, Loc
)),
3225 New_Reference_To
(Comp
, Loc
))));
3227 if No
(Declarations
(N
)) then
3228 Set_Declarations
(N
, New_List
);
3231 Append
(Decl
, Declarations
(N
));
3232 Set_Renamed_Object
(Formal
, New_F
);
3233 Next_Formal
(Formal
);
3240 end Expand_Accept_Declarations
;
3242 ---------------------------------------------
3243 -- Expand_Access_Protected_Subprogram_Type --
3244 ---------------------------------------------
3246 procedure Expand_Access_Protected_Subprogram_Type
(N
: Node_Id
) is
3247 Loc
: constant Source_Ptr
:= Sloc
(N
);
3249 T
: constant Entity_Id
:= Defining_Identifier
(N
);
3250 D_T
: constant Entity_Id
:= Designated_Type
(T
);
3251 D_T2
: constant Entity_Id
:= Make_Defining_Identifier
3252 (Loc
, New_Internal_Name
('D'));
3253 E_T
: constant Entity_Id
:= Make_Defining_Identifier
3254 (Loc
, New_Internal_Name
('E'));
3255 P_List
: constant List_Id
:= Build_Protected_Spec
3256 (N
, RTE
(RE_Address
), False, D_T
);
3262 -- Create access to protected subprogram with full signature
3264 if Nkind
(Type_Definition
(N
)) = N_Access_Function_Definition
then
3266 Make_Access_Function_Definition
(Loc
,
3267 Parameter_Specifications
=> P_List
,
3268 Subtype_Mark
=> New_Copy
(Subtype_Mark
(Type_Definition
(N
))));
3272 Make_Access_Procedure_Definition
(Loc
,
3273 Parameter_Specifications
=> P_List
);
3277 Make_Full_Type_Declaration
(Loc
,
3278 Defining_Identifier
=> D_T2
,
3279 Type_Definition
=> Def1
);
3282 Insert_After
(N
, Decl1
);
3284 -- Create Equivalent_Type, a record with two components for an
3285 -- access to object and an access to subprogram.
3288 Make_Component_Declaration
(Loc
,
3289 Defining_Identifier
=>
3290 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P')),
3291 Component_Definition
=>
3292 Make_Component_Definition
(Loc
,
3293 Aliased_Present
=> False,
3294 Subtype_Indication
=>
3295 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
3297 Make_Component_Declaration
(Loc
,
3298 Defining_Identifier
=>
3299 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S')),
3300 Component_Definition
=>
3301 Make_Component_Definition
(Loc
,
3302 Aliased_Present
=> False,
3303 Subtype_Indication
=> New_Occurrence_Of
(D_T2
, Loc
))));
3306 Make_Full_Type_Declaration
(Loc
,
3307 Defining_Identifier
=> E_T
,
3309 Make_Record_Definition
(Loc
,
3311 Make_Component_List
(Loc
,
3312 Component_Items
=> Comps
)));
3315 Insert_After
(Decl1
, Decl2
);
3316 Set_Equivalent_Type
(T
, E_T
);
3317 end Expand_Access_Protected_Subprogram_Type
;
3319 --------------------------
3320 -- Expand_Entry_Barrier --
3321 --------------------------
3323 procedure Expand_Entry_Barrier
(N
: Node_Id
; Ent
: Entity_Id
) is
3324 Loc
: constant Source_Ptr
:= Sloc
(N
);
3325 Prot
: constant Entity_Id
:= Scope
(Ent
);
3326 Spec_Decl
: constant Node_Id
:= Parent
(Prot
);
3327 Cond
: constant Node_Id
:=
3328 Condition
(Entry_Body_Formal_Part
(N
));
3331 Body_Decl
: Node_Id
;
3334 if No_Run_Time_Mode
then
3335 Error_Msg_CRT
("entry barrier", N
);
3339 -- The body of the entry barrier must be analyzed in the context of
3340 -- the protected object, but its scope is external to it, just as any
3341 -- other unprotected version of a protected operation. The specification
3342 -- has been produced when the protected type declaration was elaborated.
3343 -- We build the body, insert it in the enclosing scope, but analyze it
3344 -- in the current context. A more uniform approach would be to treat a
3345 -- barrier just as a protected function, and discard the protected
3346 -- version of it because it is never called.
3348 if Expander_Active
then
3349 B_F
:= Build_Barrier_Function
(N
, Ent
, Prot
);
3350 Func
:= Barrier_Function
(Ent
);
3351 Set_Corresponding_Spec
(B_F
, Func
);
3353 Body_Decl
:= Parent
(Corresponding_Body
(Spec_Decl
));
3355 if Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
3356 Body_Decl
:= Corresponding_Stub
(Parent
(Body_Decl
));
3359 Insert_Before_And_Analyze
(Body_Decl
, B_F
);
3361 Update_Prival_Subtypes
(B_F
);
3363 Set_Privals
(Spec_Decl
, N
, Loc
);
3364 Set_Discriminals
(Spec_Decl
);
3365 Set_Scope
(Func
, Scope
(Prot
));
3368 Analyze_And_Resolve
(Cond
, Any_Boolean
);
3371 -- The Ravenscar profile restricts barriers to simple variables
3372 -- declared within the protected object. We also allow Boolean
3373 -- constants, since these appear in several published examples
3374 -- and are also allowed by the Aonix compiler.
3376 -- Note that after analysis variables in this context will be
3377 -- replaced by the corresponding prival, that is to say a renaming
3378 -- of a selected component of the form _Object.Var. If expansion is
3379 -- disabled, as within a generic, we check that the entity appears in
3380 -- the current scope.
3382 if Is_Entity_Name
(Cond
) then
3384 if Entity
(Cond
) = Standard_False
3386 Entity
(Cond
) = Standard_True
3390 elsif not Expander_Active
3391 and then Scope
(Entity
(Cond
)) = Current_Scope
3395 -- Check for case of _object.all.field (note that the explicit
3396 -- dereference gets inserted by analyze/expand of _object.field)
3398 elsif Present
(Renamed_Object
(Entity
(Cond
)))
3400 Nkind
(Renamed_Object
(Entity
(Cond
))) = N_Selected_Component
3404 (Prefix
(Renamed_Object
(Entity
(Cond
))))) = Name_uObject
3410 -- It is not a boolean variable or literal, so check the restriction
3412 Check_Restriction
(Simple_Barriers
, Cond
);
3413 end Expand_Entry_Barrier
;
3415 ------------------------------------
3416 -- Expand_Entry_Body_Declarations --
3417 ------------------------------------
3419 procedure Expand_Entry_Body_Declarations
(N
: Node_Id
) is
3420 Loc
: constant Source_Ptr
:= Sloc
(N
);
3421 Index_Spec
: Node_Id
;
3424 if Expander_Active
then
3426 -- Expand entry bodies corresponding to entry families
3427 -- by assigning a placeholder for the constant that will
3428 -- be used to expand references to the entry index parameter.
3431 Entry_Index_Specification
(Entry_Body_Formal_Part
(N
));
3433 if Present
(Index_Spec
) then
3434 Set_Entry_Index_Constant
(
3435 Defining_Identifier
(Index_Spec
),
3436 Make_Defining_Identifier
(Loc
, New_Internal_Name
('J')));
3439 end Expand_Entry_Body_Declarations
;
3441 ------------------------------
3442 -- Expand_N_Abort_Statement --
3443 ------------------------------
3445 -- Expand abort T1, T2, .. Tn; into:
3446 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
3448 procedure Expand_N_Abort_Statement
(N
: Node_Id
) is
3449 Loc
: constant Source_Ptr
:= Sloc
(N
);
3450 Tlist
: constant List_Id
:= Names
(N
);
3456 Aggr
:= Make_Aggregate
(Loc
, Component_Associations
=> New_List
);
3459 Tasknm
:= First
(Tlist
);
3461 while Present
(Tasknm
) loop
3463 Append_To
(Component_Associations
(Aggr
),
3464 Make_Component_Association
(Loc
,
3465 Choices
=> New_List
(
3466 Make_Integer_Literal
(Loc
, Count
)),
3467 Expression
=> Concurrent_Ref
(Tasknm
)));
3472 Make_Procedure_Call_Statement
(Loc
,
3473 Name
=> New_Reference_To
(RTE
(RE_Abort_Tasks
), Loc
),
3474 Parameter_Associations
=> New_List
(
3475 Make_Qualified_Expression
(Loc
,
3476 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Task_List
), Loc
),
3477 Expression
=> Aggr
))));
3480 end Expand_N_Abort_Statement
;
3482 -------------------------------
3483 -- Expand_N_Accept_Statement --
3484 -------------------------------
3486 -- This procedure handles expansion of accept statements that stand
3487 -- alone, i.e. they are not part of an accept alternative. The expansion
3488 -- of accept statement in accept alternatives is handled by the routines
3489 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
3490 -- following description applies only to stand alone accept statements.
3492 -- If there is no handled statement sequence, or only null statements,
3493 -- then this is called a trivial accept, and the expansion is:
3495 -- Accept_Trivial (entry-index)
3497 -- If there is a handled statement sequence, then the expansion is:
3504 -- Accept_Call (entry-index, Ann);
3505 -- Renaming_Declarations for formals
3506 -- <statement sequence from N_Accept_Statement node>
3507 -- Complete_Rendezvous;
3512 -- <exception handler from N_Accept_Statement node>
3513 -- Complete_Rendezvous;
3515 -- <exception handler from N_Accept_Statement node>
3516 -- Complete_Rendezvous;
3521 -- when all others =>
3522 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
3525 -- The first three declarations were already inserted ahead of the
3526 -- accept statement by the Expand_Accept_Declarations procedure, which
3527 -- was called directly from the semantics during analysis of the accept.
3528 -- statement, before analyzing its contained statements.
3530 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
3531 -- from possible expansion activity (the original source of course does
3532 -- not have any declarations associated with the accept statement, since
3533 -- an accept statement has no declarative part). In particular, if the
3534 -- expander is active, the first such declaration is the declaration of
3535 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
3537 -- The two blocks are merged into a single block if the inner block has
3538 -- no exception handlers, but otherwise two blocks are required, since
3539 -- exceptions might be raised in the exception handlers of the inner
3540 -- block, and Exceptional_Complete_Rendezvous must be called.
3542 procedure Expand_N_Accept_Statement
(N
: Node_Id
) is
3543 Loc
: constant Source_Ptr
:= Sloc
(N
);
3544 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
3545 Ename
: constant Node_Id
:= Entry_Direct_Name
(N
);
3546 Eindx
: constant Node_Id
:= Entry_Index
(N
);
3547 Eent
: constant Entity_Id
:= Entity
(Ename
);
3548 Acstack
: constant Elist_Id
:= Accept_Address
(Eent
);
3549 Ann
: constant Entity_Id
:= Node
(Last_Elmt
(Acstack
));
3550 Ttyp
: constant Entity_Id
:= Etype
(Scope
(Eent
));
3555 function Null_Statements
(Stats
: List_Id
) return Boolean;
3556 -- Check for null statement sequence (i.e a list of labels and
3559 function Null_Statements
(Stats
: List_Id
) return Boolean is
3563 Stmt
:= First
(Stats
);
3564 while Nkind
(Stmt
) /= N_Empty
3565 and then (Nkind
(Stmt
) = N_Null_Statement
3567 Nkind
(Stmt
) = N_Label
)
3572 return Nkind
(Stmt
) = N_Empty
;
3573 end Null_Statements
;
3575 -- Start of processing for Expand_N_Accept_Statement
3578 -- If accept statement is not part of a list, then its parent must be
3579 -- an accept alternative, and, as described above, we do not do any
3580 -- expansion for such accept statements at this level.
3582 if not Is_List_Member
(N
) then
3583 pragma Assert
(Nkind
(Parent
(N
)) = N_Accept_Alternative
);
3586 -- Trivial accept case (no statement sequence, or null statements).
3587 -- If the accept statement has declarations, then just insert them
3588 -- before the procedure call.
3590 -- We avoid this optimization when FIFO_Within_Priorities is active,
3591 -- since it is not correct according to annex D semantics. The problem
3592 -- is that the call is required to reorder the acceptors position on
3593 -- its ready queue, even though there is nothing to be done. However,
3594 -- if no policy is specified, then we decide that our dispatching
3595 -- policy always reorders the queue right after the RV to look the
3596 -- way they were just before the RV. Since we are allowed to freely
3597 -- reorder same-priority queues (this is part of what dispatching
3598 -- policies are all about), the optimization is legitimate.
3600 elsif Opt
.Task_Dispatching_Policy
/= 'F'
3601 and then (No
(Stats
) or else Null_Statements
(Statements
(Stats
)))
3603 -- Remove declarations for renamings, because the parameter block
3604 -- will not be assigned.
3611 D
:= First
(Declarations
(N
));
3613 while Present
(D
) loop
3615 if Nkind
(D
) = N_Object_Renaming_Declaration
then
3623 if Present
(Declarations
(N
)) then
3624 Insert_Actions
(N
, Declarations
(N
));
3628 Make_Procedure_Call_Statement
(Loc
,
3629 Name
=> New_Reference_To
(RTE
(RE_Accept_Trivial
), Loc
),
3630 Parameter_Associations
=> New_List
(
3631 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
))));
3635 -- Discard Entry_Address that was created for it, so it will not be
3636 -- emitted if this accept statement is in the statement part of a
3637 -- delay alternative.
3639 if Present
(Stats
) then
3640 Remove_Last_Elmt
(Acstack
);
3643 -- Case of statement sequence present
3646 -- Construct the block, using the declarations from the accept
3647 -- statement if any to initialize the declarations of the block.
3649 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3650 Set_Ekind
(Blkent
, E_Block
);
3651 Set_Etype
(Blkent
, Standard_Void_Type
);
3652 Set_Scope
(Blkent
, Current_Scope
);
3655 Make_Block_Statement
(Loc
,
3656 Identifier
=> New_Reference_To
(Blkent
, Loc
),
3657 Declarations
=> Declarations
(N
),
3658 Handled_Statement_Sequence
=> Build_Accept_Body
(N
));
3660 -- Prepend call to Accept_Call to main statement sequence
3661 -- If the accept has exception handlers, the statement sequence
3662 -- is wrapped in a block. Insert call and renaming declarations
3663 -- in the declarations of the block, so they are elaborated before
3667 Make_Procedure_Call_Statement
(Loc
,
3668 Name
=> New_Reference_To
(RTE
(RE_Accept_Call
), Loc
),
3669 Parameter_Associations
=> New_List
(
3670 Entry_Index_Expression
(Loc
, Entity
(Ename
), Eindx
, Ttyp
),
3671 New_Reference_To
(Ann
, Loc
)));
3673 if Parent
(Stats
) = N
then
3674 Prepend
(Call
, Statements
(Stats
));
3690 D
:= First
(Declarations
(N
));
3692 while Present
(D
) loop
3695 if Nkind
(D
) = N_Object_Renaming_Declaration
then
3696 -- The renaming declarations for the formals were
3697 -- created during analysis of the accept statement,
3698 -- and attached to the list of declarations. Place
3699 -- them now in the context of the accept block or
3703 Typ
:= Entity
(Subtype_Mark
(D
));
3704 Insert_After
(Call
, D
);
3707 -- If the formal is class_wide, it does not have an
3708 -- actual subtype. The analysis of the renaming declaration
3709 -- creates one, but we need to retain the class-wide
3710 -- nature of the entity.
3712 if Is_Class_Wide_Type
(Typ
) then
3713 Set_Etype
(Defining_Identifier
(D
), Typ
);
3724 -- Replace the accept statement by the new block
3729 -- Last step is to unstack the Accept_Address value
3731 Remove_Last_Elmt
(Acstack
);
3733 end Expand_N_Accept_Statement
;
3735 ----------------------------------
3736 -- Expand_N_Asynchronous_Select --
3737 ----------------------------------
3739 -- This procedure assumes that the trigger statement is an entry call. A
3740 -- delay alternative should already have been expanded into an entry call
3741 -- to the appropriate delay object Wait entry.
3743 -- If the trigger is a task entry call, the select is implemented with
3744 -- a Task_Entry_Call:
3749 -- P : parms := (parm, parm, parm);
3751 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
3753 -- procedure _clean is
3756 -- Cancel_Task_Entry_Call (C);
3766 -- Asynchronous_Call,
3774 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions.
3778 -- when Abort_Signal => Abort_Undefer;
3784 -- triggered-statements
3788 -- Note that Build_Simple_Entry_Call is used to expand the entry
3789 -- of the asynchronous entry call (by the
3790 -- Expand_N_Entry_Call_Statement procedure) as follows:
3793 -- P : parms := (parm, parm, parm);
3795 -- Call_Simple (acceptor-task, entry-index, P'Address);
3801 -- so the task at hand is to convert the latter expansion into the former
3803 -- If the trigger is a protected entry call, the select is
3804 -- implemented with Protected_Entry_Call:
3807 -- P : E1_Params := (param, param, param);
3808 -- Bnn : Communications_Block;
3812 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions.
3813 -- procedure _clean is
3816 -- if Enqueued (Bnn) then
3817 -- Cancel_Protected_Entry_Call (Bnn);
3824 -- Protected_Entry_Call (
3825 -- Object => po._object'Access,
3826 -- E => <entry index>;
3827 -- Uninterpreted_Data => P'Address;
3828 -- Mode => Asynchronous_Call;
3830 -- if Enqueued (Bnn) then
3834 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions.
3838 -- when Abort_Signal =>
3843 -- if not Cancelled (Bnn) then
3844 -- triggered statements
3848 -- Build_Simple_Entry_Call is used to expand the all to a simple
3849 -- protected entry call:
3852 -- P : E1_Params := (param, param, param);
3853 -- Bnn : Communications_Block;
3856 -- Protected_Entry_Call (
3857 -- Object => po._object'Access,
3858 -- E => <entry index>;
3859 -- Uninterpreted_Data => P'Address;
3860 -- Mode => Simple_Call;
3867 -- The job is to convert this to the asynchronous form
3869 -- If the trigger is a delay statement, it will have been expanded into a
3870 -- call to one of the GNARL delay procedures. This routine will convert
3871 -- this into a protected entry call on a delay object and then continue
3872 -- processing as for a protected entry call trigger. This requires
3873 -- declaring a Delay_Block object and adding a pointer to this object to
3874 -- the parameter list of the delay procedure to form the parameter list of
3875 -- the entry call. This object is used by the runtime to queue the delay
3878 -- For a description of the use of P and the assignments after the
3879 -- call, see Expand_N_Entry_Call_Statement.
3881 procedure Expand_N_Asynchronous_Select
(N
: Node_Id
) is
3882 Loc
: constant Source_Ptr
:= Sloc
(N
);
3883 Trig
: constant Node_Id
:= Triggering_Alternative
(N
);
3884 Abrt
: constant Node_Id
:= Abortable_Part
(N
);
3885 Tstats
: constant List_Id
:= Statements
(Trig
);
3886 Astats
: constant List_Id
:= Statements
(Abrt
);
3899 Enqueue_Call
: Node_Id
;
3903 Dblock_Ent
: Entity_Id
;
3905 Abortable_Block
: Node_Id
;
3906 Cancel_Param
: Entity_Id
;
3908 Target_Undefer
: RE_Id
;
3909 Undefer_Args
: List_Id
:= No_List
;
3912 Blkent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3913 Ecall
:= Triggering_Statement
(Trig
);
3915 -- The arguments in the call may require dynamic allocation, and the
3916 -- call statement may have been transformed into a block. The block
3917 -- may contain additional declarations for internal entities, and the
3918 -- original call is found by sequential search.
3920 if Nkind
(Ecall
) = N_Block_Statement
then
3921 Ecall
:= First
(Statements
(Handled_Statement_Sequence
(Ecall
)));
3923 while Nkind
(Ecall
) /= N_Procedure_Call_Statement
3924 and then Nkind
(Ecall
) /= N_Entry_Call_Statement
3930 -- If a delay was used as a trigger, it will have been expanded
3931 -- into a procedure call. Convert it to the appropriate sequence of
3932 -- statements, similar to what is done for a task entry call.
3933 -- Note that this currently supports only Duration, Real_Time.Time,
3934 -- and Calendar.Time.
3936 if Nkind
(Ecall
) = N_Procedure_Call_Statement
then
3938 -- Add a Delay_Block object to the parameter list of the
3939 -- delay procedure to form the parameter list of the Wait
3942 Dblock_Ent
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
3944 Pdef
:= Entity
(Name
(Ecall
));
3946 if Is_RTE
(Pdef
, RO_CA_Delay_For
) then
3947 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_Duration
), Loc
);
3949 elsif Is_RTE
(Pdef
, RO_CA_Delay_Until
) then
3950 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_Calendar
), Loc
);
3952 else pragma Assert
(Is_RTE
(Pdef
, RO_RT_Delay_Until
));
3953 Enqueue_Call
:= New_Reference_To
(RTE
(RE_Enqueue_RT
), Loc
);
3956 Append_To
(Parameter_Associations
(Ecall
),
3957 Make_Attribute_Reference
(Loc
,
3958 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
3959 Attribute_Name
=> Name_Unchecked_Access
));
3961 -- Create the inner block to protect the abortable part
3964 Make_Exception_Handler
(Loc
,
3965 Exception_Choices
=>
3966 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
3967 Statements
=> New_List
(
3968 Make_Procedure_Call_Statement
(Loc
,
3969 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)))));
3972 Make_Procedure_Call_Statement
(Loc
,
3973 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
3976 Make_Block_Statement
(Loc
,
3977 Identifier
=> New_Reference_To
(Blkent
, Loc
),
3978 Handled_Statement_Sequence
=>
3979 Make_Handled_Sequence_Of_Statements
(Loc
,
3980 Statements
=> Astats
),
3981 Has_Created_Identifier
=> True,
3982 Is_Asynchronous_Call_Block
=> True);
3984 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
3987 Make_Implicit_If_Statement
(N
,
3988 Condition
=> Make_Function_Call
(Loc
,
3989 Name
=> Enqueue_Call
,
3990 Parameter_Associations
=> Parameter_Associations
(Ecall
)),
3992 New_List
(Make_Block_Statement
(Loc
,
3993 Handled_Statement_Sequence
=>
3994 Make_Handled_Sequence_Of_Statements
(Loc
,
3995 Statements
=> New_List
(
3996 Make_Implicit_Label_Declaration
(Loc
,
3997 Defining_Identifier
=> Blkent
,
3998 Label_Construct
=> Abortable_Block
),
4000 Exception_Handlers
=> Hdle
)))));
4002 Stmts
:= New_List
(Ecall
);
4004 -- Construct statement sequence for new block
4007 Make_Implicit_If_Statement
(N
,
4008 Condition
=> Make_Function_Call
(Loc
,
4009 Name
=> New_Reference_To
(
4010 RTE
(RE_Timed_Out
), Loc
),
4011 Parameter_Associations
=> New_List
(
4012 Make_Attribute_Reference
(Loc
,
4013 Prefix
=> New_Reference_To
(Dblock_Ent
, Loc
),
4014 Attribute_Name
=> Name_Unchecked_Access
))),
4015 Then_Statements
=> Tstats
));
4017 -- The result is the new block
4019 Set_Entry_Cancel_Parameter
(Blkent
, Dblock_Ent
);
4022 Make_Block_Statement
(Loc
,
4023 Declarations
=> New_List
(
4024 Make_Object_Declaration
(Loc
,
4025 Defining_Identifier
=> Dblock_Ent
,
4026 Aliased_Present
=> True,
4027 Object_Definition
=> New_Reference_To
(
4028 RTE
(RE_Delay_Block
), Loc
))),
4030 Handled_Statement_Sequence
=>
4031 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
4040 Extract_Entry
(Ecall
, Concval
, Ename
, Index
);
4041 Build_Simple_Entry_Call
(Ecall
, Concval
, Ename
, Index
);
4043 Stmts
:= Statements
(Handled_Statement_Sequence
(Ecall
));
4044 Decls
:= Declarations
(Ecall
);
4046 if Is_Protected_Type
(Etype
(Concval
)) then
4048 -- Get the declarations of the block expanded from the entry call
4050 Decl
:= First
(Decls
);
4051 while Present
(Decl
)
4052 and then (Nkind
(Decl
) /= N_Object_Declaration
4054 (Etype
(Object_Definition
(Decl
)), RE_Communication_Block
))
4059 pragma Assert
(Present
(Decl
));
4060 Cancel_Param
:= Defining_Identifier
(Decl
);
4062 -- Change the mode of the Protected_Entry_Call call.
4063 -- Protected_Entry_Call (
4064 -- Object => po._object'Access,
4065 -- E => <entry index>;
4066 -- Uninterpreted_Data => P'Address;
4067 -- Mode => Asynchronous_Call;
4070 Stmt
:= First
(Stmts
);
4072 -- Skip assignments to temporaries created for in-out parameters.
4073 -- This makes unwarranted assumptions about the shape of the expanded
4074 -- tree for the call, and should be cleaned up ???
4076 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
4082 Parm
:= First
(Parameter_Associations
(Call
));
4083 while Present
(Parm
)
4084 and then not Is_RTE
(Etype
(Parm
), RE_Call_Modes
)
4089 pragma Assert
(Present
(Parm
));
4090 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
4093 -- Append an if statement to execute the abortable part.
4094 -- if Enqueued (Bnn) then
4097 Make_Implicit_If_Statement
(N
,
4098 Condition
=> Make_Function_Call
(Loc
,
4099 Name
=> New_Reference_To
(
4100 RTE
(RE_Enqueued
), Loc
),
4101 Parameter_Associations
=> New_List
(
4102 New_Reference_To
(Cancel_Param
, Loc
))),
4103 Then_Statements
=> Astats
));
4106 Make_Block_Statement
(Loc
,
4107 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4108 Handled_Statement_Sequence
=>
4109 Make_Handled_Sequence_Of_Statements
(Loc
,
4110 Statements
=> Stmts
),
4111 Has_Created_Identifier
=> True,
4112 Is_Asynchronous_Call_Block
=> True);
4114 -- For the JVM call Update_Exception instead of Abort_Undefer.
4115 -- See 4jexcept.ads for an explanation.
4117 if Hostparm
.Java_VM
then
4118 Target_Undefer
:= RE_Update_Exception
;
4120 New_List
(Make_Function_Call
(Loc
,
4121 Name
=> New_Occurrence_Of
4122 (RTE
(RE_Current_Target_Exception
), Loc
)));
4124 Target_Undefer
:= RE_Abort_Undefer
;
4128 Make_Block_Statement
(Loc
,
4129 Handled_Statement_Sequence
=>
4130 Make_Handled_Sequence_Of_Statements
(Loc
,
4131 Statements
=> New_List
(
4132 Make_Implicit_Label_Declaration
(Loc
,
4133 Defining_Identifier
=> Blkent
,
4134 Label_Construct
=> Abortable_Block
),
4139 Exception_Handlers
=> New_List
(
4140 Make_Exception_Handler
(Loc
,
4142 -- when Abort_Signal =>
4143 -- Abort_Undefer.all;
4145 Exception_Choices
=>
4146 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
4147 Statements
=> New_List
(
4148 Make_Procedure_Call_Statement
(Loc
,
4149 Name
=> New_Reference_To
(
4150 RTE
(Target_Undefer
), Loc
),
4151 Parameter_Associations
=> Undefer_Args
)))))),
4153 -- if not Cancelled (Bnn) then
4154 -- triggered statements
4157 Make_Implicit_If_Statement
(N
,
4158 Condition
=> Make_Op_Not
(Loc
,
4160 Make_Function_Call
(Loc
,
4161 Name
=> New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
4162 Parameter_Associations
=> New_List
(
4163 New_Occurrence_Of
(Cancel_Param
, Loc
)))),
4164 Then_Statements
=> Tstats
));
4166 -- Asynchronous task entry call
4173 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
4175 -- Insert declaration of B in declarations of existing block
4178 Make_Object_Declaration
(Loc
,
4179 Defining_Identifier
=> B
,
4180 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
4182 Cancel_Param
:= Make_Defining_Identifier
(Loc
, Name_uC
);
4184 -- Insert declaration of C in declarations of existing block
4187 Make_Object_Declaration
(Loc
,
4188 Defining_Identifier
=> Cancel_Param
,
4189 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
4191 -- Remove and save the call to Call_Simple
4193 Stmt
:= First
(Stmts
);
4195 -- Skip assignments to temporaries created for in-out parameters.
4196 -- This makes unwarranted assumptions about the shape of the expanded
4197 -- tree for the call, and should be cleaned up ???
4199 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
4205 -- Create the inner block to protect the abortable part
4208 Make_Exception_Handler
(Loc
,
4209 Exception_Choices
=>
4210 New_List
(New_Reference_To
(Stand
.Abort_Signal
, Loc
)),
4211 Statements
=> New_List
(
4212 Make_Procedure_Call_Statement
(Loc
,
4213 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)))));
4216 Make_Procedure_Call_Statement
(Loc
,
4217 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
)));
4220 Make_Block_Statement
(Loc
,
4221 Identifier
=> New_Reference_To
(Blkent
, Loc
),
4222 Handled_Statement_Sequence
=>
4223 Make_Handled_Sequence_Of_Statements
(Loc
,
4224 Statements
=> Astats
),
4225 Has_Created_Identifier
=> True,
4226 Is_Asynchronous_Call_Block
=> True);
4229 Make_Block_Statement
(Loc
,
4230 Handled_Statement_Sequence
=>
4231 Make_Handled_Sequence_Of_Statements
(Loc
,
4232 Statements
=> New_List
(
4233 Make_Implicit_Label_Declaration
(Loc
,
4234 Defining_Identifier
=> Blkent
,
4235 Label_Construct
=> Abortable_Block
),
4237 Exception_Handlers
=> Hdle
)));
4239 -- Create new call statement
4241 Parms
:= Parameter_Associations
(Call
);
4242 Append_To
(Parms
, New_Reference_To
(RTE
(RE_Asynchronous_Call
), Loc
));
4243 Append_To
(Parms
, New_Reference_To
(B
, Loc
));
4245 Make_Procedure_Call_Statement
(Loc
,
4246 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
4247 Parameter_Associations
=> Parms
));
4249 -- Construct statement sequence for new block
4252 Make_Implicit_If_Statement
(N
,
4253 Condition
=> Make_Op_Not
(Loc
,
4254 New_Reference_To
(Cancel_Param
, Loc
)),
4255 Then_Statements
=> Tstats
));
4257 -- Protected the call against abort
4260 Make_Procedure_Call_Statement
(Loc
,
4261 Name
=> New_Reference_To
(RTE
(RE_Abort_Defer
), Loc
),
4262 Parameter_Associations
=> Empty_List
));
4265 Set_Entry_Cancel_Parameter
(Blkent
, Cancel_Param
);
4267 -- The result is the new block
4270 Make_Block_Statement
(Loc
,
4271 Declarations
=> Decls
,
4272 Handled_Statement_Sequence
=>
4273 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
4276 end Expand_N_Asynchronous_Select
;
4278 -------------------------------------
4279 -- Expand_N_Conditional_Entry_Call --
4280 -------------------------------------
4282 -- The conditional task entry call is converted to a call to
4287 -- P : parms := (parm, parm, parm);
4294 -- Conditional_Call,
4300 -- normal-statements
4306 -- For a description of the use of P and the assignments after the
4307 -- call, see Expand_N_Entry_Call_Statement. Note that the entry call
4308 -- of the conditional entry call has already been expanded (by the
4309 -- Expand_N_Entry_Call_Statement procedure) as follows:
4312 -- P : parms := (parm, parm, parm);
4314 -- ... info for in-out parameters
4315 -- Call_Simple (acceptor-task, entry-index, P'Address);
4321 -- so the task at hand is to convert the latter expansion into the former
4323 -- The conditional protected entry call is converted to a call to
4324 -- Protected_Entry_Call:
4327 -- P : parms := (parm, parm, parm);
4328 -- Bnn : Communications_Block;
4331 -- Protected_Entry_Call (
4332 -- Object => po._object'Access,
4333 -- E => <entry index>;
4334 -- Uninterpreted_Data => P'Address;
4335 -- Mode => Conditional_Call;
4340 -- if Cancelled (Bnn) then
4343 -- normal-statements
4347 -- As for tasks, the entry call of the conditional entry call has
4348 -- already been expanded (by the Expand_N_Entry_Call_Statement procedure)
4352 -- P : E1_Params := (param, param, param);
4353 -- Bnn : Communications_Block;
4356 -- Protected_Entry_Call (
4357 -- Object => po._object'Access,
4358 -- E => <entry index>;
4359 -- Uninterpreted_Data => P'Address;
4360 -- Mode => Simple_Call;
4367 procedure Expand_N_Conditional_Entry_Call
(N
: Node_Id
) is
4368 Loc
: constant Source_Ptr
:= Sloc
(N
);
4369 Alt
: constant Node_Id
:= Entry_Call_Alternative
(N
);
4370 Blk
: Node_Id
:= Entry_Call_Statement
(Alt
);
4371 Transient_Blk
: Node_Id
;
4382 -- As described above, The entry alternative is transformed into a
4383 -- block that contains the gnulli call, and possibly assignment
4384 -- statements for in-out parameters. The gnulli call may itself be
4385 -- rewritten into a transient block if some unconstrained parameters
4386 -- require it. We need to retrieve the call to complete its parameter
4390 First_Real_Statement
(Handled_Statement_Sequence
(Blk
));
4392 if Present
(Transient_Blk
)
4394 Nkind
(Transient_Blk
) = N_Block_Statement
4396 Blk
:= Transient_Blk
;
4399 Stmts
:= Statements
(Handled_Statement_Sequence
(Blk
));
4401 Stmt
:= First
(Stmts
);
4403 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
4409 Parms
:= Parameter_Associations
(Call
);
4411 if Is_RTE
(Entity
(Name
(Call
)), RE_Protected_Entry_Call
) then
4413 -- Substitute Conditional_Entry_Call for Simple_Call
4416 Parm
:= First
(Parms
);
4417 while Present
(Parm
)
4418 and then not Is_RTE
(Etype
(Parm
), RE_Call_Modes
)
4423 pragma Assert
(Present
(Parm
));
4424 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
4428 -- Find the Communication_Block parameter for the call
4429 -- to the Cancelled function.
4431 Decl
:= First
(Declarations
(Blk
));
4432 while Present
(Decl
)
4434 Is_RTE
(Etype
(Object_Definition
(Decl
)), RE_Communication_Block
)
4439 -- Add an if statement to execute the else part if the call
4440 -- does not succeed (as indicated by the Cancelled predicate).
4443 Make_Implicit_If_Statement
(N
,
4444 Condition
=> Make_Function_Call
(Loc
,
4445 Name
=> New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
4446 Parameter_Associations
=> New_List
(
4447 New_Reference_To
(Defining_Identifier
(Decl
), Loc
))),
4448 Then_Statements
=> Else_Statements
(N
),
4449 Else_Statements
=> Statements
(Alt
)));
4452 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
4454 -- Insert declaration of B in declarations of existing block
4456 if No
(Declarations
(Blk
)) then
4457 Set_Declarations
(Blk
, New_List
);
4460 Prepend_To
(Declarations
(Blk
),
4461 Make_Object_Declaration
(Loc
,
4462 Defining_Identifier
=> B
,
4463 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
4465 -- Create new call statement
4467 Append_To
(Parms
, New_Reference_To
(RTE
(RE_Conditional_Call
), Loc
));
4468 Append_To
(Parms
, New_Reference_To
(B
, Loc
));
4471 Make_Procedure_Call_Statement
(Loc
,
4472 Name
=> New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
4473 Parameter_Associations
=> Parms
));
4475 -- Construct statement sequence for new block
4478 Make_Implicit_If_Statement
(N
,
4479 Condition
=> New_Reference_To
(B
, Loc
),
4480 Then_Statements
=> Statements
(Alt
),
4481 Else_Statements
=> Else_Statements
(N
)));
4485 -- The result is the new block
4488 Make_Block_Statement
(Loc
,
4489 Declarations
=> Declarations
(Blk
),
4490 Handled_Statement_Sequence
=>
4491 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
4494 end Expand_N_Conditional_Entry_Call
;
4496 ---------------------------------------
4497 -- Expand_N_Delay_Relative_Statement --
4498 ---------------------------------------
4500 -- Delay statement is implemented as a procedure call to Delay_For
4501 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
4502 -- simple delays imposed by the use of Protected Objects.
4504 procedure Expand_N_Delay_Relative_Statement
(N
: Node_Id
) is
4505 Loc
: constant Source_Ptr
:= Sloc
(N
);
4509 Make_Procedure_Call_Statement
(Loc
,
4510 Name
=> New_Reference_To
(RTE
(RO_CA_Delay_For
), Loc
),
4511 Parameter_Associations
=> New_List
(Expression
(N
))));
4513 end Expand_N_Delay_Relative_Statement
;
4515 ------------------------------------
4516 -- Expand_N_Delay_Until_Statement --
4517 ------------------------------------
4519 -- Delay Until statement is implemented as a procedure call to
4520 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
4522 procedure Expand_N_Delay_Until_Statement
(N
: Node_Id
) is
4523 Loc
: constant Source_Ptr
:= Sloc
(N
);
4527 if Is_RTE
(Base_Type
(Etype
(Expression
(N
))), RO_CA_Time
) then
4528 Typ
:= RTE
(RO_CA_Delay_Until
);
4530 Typ
:= RTE
(RO_RT_Delay_Until
);
4534 Make_Procedure_Call_Statement
(Loc
,
4535 Name
=> New_Reference_To
(Typ
, Loc
),
4536 Parameter_Associations
=> New_List
(Expression
(N
))));
4539 end Expand_N_Delay_Until_Statement
;
4541 -------------------------
4542 -- Expand_N_Entry_Body --
4543 -------------------------
4545 procedure Expand_N_Entry_Body
(N
: Node_Id
) is
4546 Loc
: constant Source_Ptr
:= Sloc
(N
);
4547 Dec
: constant Node_Id
:= Parent
(Current_Scope
);
4548 Ent_Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
4549 Index_Spec
: constant Node_Id
:=
4550 Entry_Index_Specification
(Ent_Formals
);
4552 First_Decl
: constant Node_Id
:= First
(Declarations
(N
));
4553 Index_Decl
: List_Id
;
4556 -- Add the renamings for private declarations and discriminants
4558 Add_Discriminal_Declarations
4559 (Declarations
(N
), Defining_Identifier
(Dec
), Name_uObject
, Loc
);
4560 Add_Private_Declarations
4561 (Declarations
(N
), Defining_Identifier
(Dec
), Name_uObject
, Loc
);
4563 if Present
(Index_Spec
) then
4565 Index_Constant_Declaration
4567 Defining_Identifier
(Index_Spec
), Defining_Identifier
(Dec
));
4569 -- If the entry has local declarations, insert index declaration
4570 -- before them, because the index may be used therein.
4572 if Present
(First_Decl
) then
4573 Insert_List_Before
(First_Decl
, Index_Decl
);
4575 Append_List_To
(Declarations
(N
), Index_Decl
);
4579 -- Associate privals and discriminals with the next protected
4580 -- operation body to be expanded. These are used to expand
4581 -- references to private data objects and discriminants,
4584 Next_Op
:= Next_Protected_Operation
(N
);
4586 if Present
(Next_Op
) then
4587 Set_Privals
(Dec
, Next_Op
, Loc
);
4588 Set_Discriminals
(Dec
);
4590 end Expand_N_Entry_Body
;
4592 -----------------------------------
4593 -- Expand_N_Entry_Call_Statement --
4594 -----------------------------------
4596 -- An entry call is expanded into GNARLI calls to implement
4597 -- a simple entry call (see Build_Simple_Entry_Call).
4599 procedure Expand_N_Entry_Call_Statement
(N
: Node_Id
) is
4605 if No_Run_Time_Mode
then
4606 Error_Msg_CRT
("entry call", N
);
4610 -- If this entry call is part of an asynchronous select, don't
4611 -- expand it here; it will be expanded with the select statement.
4612 -- Don't expand timed entry calls either, as they are translated
4613 -- into asynchronous entry calls.
4615 -- ??? This whole approach is questionable; it may be better
4616 -- to go back to allowing the expansion to take place and then
4617 -- attempting to fix it up in Expand_N_Asynchronous_Select.
4618 -- The tricky part is figuring out whether the expanded
4619 -- call is on a task or protected entry.
4621 if (Nkind
(Parent
(N
)) /= N_Triggering_Alternative
4622 or else N
/= Triggering_Statement
(Parent
(N
)))
4623 and then (Nkind
(Parent
(N
)) /= N_Entry_Call_Alternative
4624 or else N
/= Entry_Call_Statement
(Parent
(N
))
4625 or else Nkind
(Parent
(Parent
(N
))) /= N_Timed_Entry_Call
)
4627 Extract_Entry
(N
, Concval
, Ename
, Index
);
4628 Build_Simple_Entry_Call
(N
, Concval
, Ename
, Index
);
4630 end Expand_N_Entry_Call_Statement
;
4632 --------------------------------
4633 -- Expand_N_Entry_Declaration --
4634 --------------------------------
4636 -- If there are parameters, then first, each of the formals is marked
4637 -- by setting Is_Entry_Formal. Next a record type is built which is
4638 -- used to hold the parameter values. The name of this record type is
4639 -- entryP where entry is the name of the entry, with an additional
4640 -- corresponding access type called entryPA. The record type has matching
4641 -- components for each formal (the component names are the same as the
4642 -- formal names). For elementary types, the component type matches the
4643 -- formal type. For composite types, an access type is declared (with
4644 -- the name formalA) which designates the formal type, and the type of
4645 -- the component is this access type. Finally the Entry_Component of
4646 -- each formal is set to reference the corresponding record component.
4648 procedure Expand_N_Entry_Declaration
(N
: Node_Id
) is
4649 Loc
: constant Source_Ptr
:= Sloc
(N
);
4650 Entry_Ent
: constant Entity_Id
:= Defining_Identifier
(N
);
4651 Components
: List_Id
;
4654 Last_Decl
: Node_Id
;
4655 Component
: Entity_Id
;
4658 Rec_Ent
: Entity_Id
;
4659 Acc_Ent
: Entity_Id
;
4662 Formal
:= First_Formal
(Entry_Ent
);
4665 -- Most processing is done only if parameters are present
4667 if Present
(Formal
) then
4668 Components
:= New_List
;
4670 -- Loop through formals
4672 while Present
(Formal
) loop
4673 Set_Is_Entry_Formal
(Formal
);
4675 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
));
4676 Set_Entry_Component
(Formal
, Component
);
4677 Set_Entry_Formal
(Component
, Formal
);
4678 Ftype
:= Etype
(Formal
);
4680 -- Declare new access type and then append
4683 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
4686 Make_Full_Type_Declaration
(Loc
,
4687 Defining_Identifier
=> Ctype
,
4689 Make_Access_To_Object_Definition
(Loc
,
4690 All_Present
=> True,
4691 Constant_Present
=> Ekind
(Formal
) = E_In_Parameter
,
4692 Subtype_Indication
=> New_Reference_To
(Ftype
, Loc
)));
4694 Insert_After
(Last_Decl
, Decl
);
4697 Append_To
(Components
,
4698 Make_Component_Declaration
(Loc
,
4699 Defining_Identifier
=> Component
,
4700 Component_Definition
=>
4701 Make_Component_Definition
(Loc
,
4702 Aliased_Present
=> False,
4703 Subtype_Indication
=> New_Reference_To
(Ctype
, Loc
))));
4705 Next_Formal_With_Extras
(Formal
);
4708 -- Create the Entry_Parameter_Record declaration
4711 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
4714 Make_Full_Type_Declaration
(Loc
,
4715 Defining_Identifier
=> Rec_Ent
,
4717 Make_Record_Definition
(Loc
,
4719 Make_Component_List
(Loc
,
4720 Component_Items
=> Components
)));
4722 Insert_After
(Last_Decl
, Decl
);
4725 -- Construct and link in the corresponding access type
4728 Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
4730 Set_Entry_Parameters_Type
(Entry_Ent
, Acc_Ent
);
4733 Make_Full_Type_Declaration
(Loc
,
4734 Defining_Identifier
=> Acc_Ent
,
4736 Make_Access_To_Object_Definition
(Loc
,
4737 All_Present
=> True,
4738 Subtype_Indication
=> New_Reference_To
(Rec_Ent
, Loc
)));
4740 Insert_After
(Last_Decl
, Decl
);
4743 end Expand_N_Entry_Declaration
;
4745 -----------------------------
4746 -- Expand_N_Protected_Body --
4747 -----------------------------
4749 -- Protected bodies are expanded to the completion of the subprograms
4750 -- created for the corresponding protected type. These are a protected
4751 -- and unprotected version of each protected subprogram in the object,
4752 -- a function to calculate each entry barrier, and a procedure to
4753 -- execute the sequence of statements of each protected entry body.
4754 -- For example, for protected type ptype:
4757 -- (O : System.Address;
4758 -- E : Protected_Entry_Index)
4761 -- <discriminant renamings>
4762 -- <private object renamings>
4764 -- return <barrier expression>;
4767 -- procedure pprocN (_object : in out poV;...) is
4768 -- <discriminant renamings>
4769 -- <private object renamings>
4771 -- <sequence of statements>
4774 -- procedure pproc (_object : in out poV;...) is
4775 -- procedure _clean is
4778 -- ptypeS (_object, Pn);
4779 -- Unlock (_object._object'Access);
4780 -- Abort_Undefer.all;
4785 -- Lock (_object._object'Access);
4786 -- pprocN (_object;...);
4791 -- function pfuncN (_object : poV;...) return Return_Type is
4792 -- <discriminant renamings>
4793 -- <private object renamings>
4795 -- <sequence of statements>
4798 -- function pfunc (_object : poV) return Return_Type is
4799 -- procedure _clean is
4801 -- Unlock (_object._object'Access);
4802 -- Abort_Undefer.all;
4807 -- Lock (_object._object'Access);
4808 -- return pfuncN (_object);
4815 -- (O : System.Address;
4816 -- P : System.Address;
4817 -- E : Protected_Entry_Index)
4819 -- <discriminant renamings>
4820 -- <private object renamings>
4821 -- type poVP is access poV;
4822 -- _Object : ptVP := ptVP!(O);
4826 -- <statement sequence>
4827 -- Complete_Entry_Body (_Object._Object);
4829 -- when all others =>
4830 -- Exceptional_Complete_Entry_Body (
4831 -- _Object._Object, Get_GNAT_Exception);
4835 -- The type poV is the record created for the protected type to hold
4836 -- the state of the protected object.
4838 procedure Expand_N_Protected_Body
(N
: Node_Id
) is
4839 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
4840 Has_Entries
: Boolean := False;
4844 New_Op_Body
: Node_Id
;
4845 Current_Node
: Node_Id
;
4846 Num_Entries
: Natural := 0;
4849 if No_Run_Time_Mode
then
4850 Error_Msg_CRT
("protected body", N
);
4854 if Nkind
(Parent
(N
)) = N_Subunit
then
4856 -- This is the proper body corresponding to a stub. The declarations
4857 -- must be inserted at the point of the stub, which is in the decla-
4858 -- rative part of the parent unit.
4860 Current_Node
:= Corresponding_Stub
(Parent
(N
));
4866 Op_Body
:= First
(Declarations
(N
));
4868 -- The protected body is replaced with the bodies of its
4869 -- protected operations, and the declarations for internal objects
4870 -- that may have been created for entry family bounds.
4872 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4875 while Present
(Op_Body
) loop
4876 case Nkind
(Op_Body
) is
4877 when N_Subprogram_Declaration
=>
4880 when N_Subprogram_Body
=>
4882 -- Exclude functions created to analyze defaults
4884 if not Is_Eliminated
(Defining_Entity
(Op_Body
))
4885 and then not Is_Eliminated
(Corresponding_Spec
(Op_Body
))
4888 Build_Unprotected_Subprogram_Body
(Op_Body
, Pid
);
4890 Insert_After
(Current_Node
, New_Op_Body
);
4891 Current_Node
:= New_Op_Body
;
4892 Analyze
(New_Op_Body
);
4894 Update_Prival_Subtypes
(New_Op_Body
);
4896 -- Build the corresponding protected operation only if
4897 -- this is a visible operation of the type, or if it is
4898 -- an interrupt handler. Otherwise it is only callable
4899 -- from within the object, and the unprotected version
4902 if Present
(Corresponding_Spec
(Op_Body
)) then
4904 Unit_Declaration_Node
(Corresponding_Spec
(Op_Body
));
4906 if Nkind
(Parent
(Op_Decl
)) = N_Protected_Definition
4908 (List_Containing
(Op_Decl
) =
4909 Visible_Declarations
(Parent
(Op_Decl
))
4911 Is_Interrupt_Handler
4912 (Corresponding_Spec
(Op_Body
)))
4915 Build_Protected_Subprogram_Body
(
4916 Op_Body
, Pid
, Specification
(New_Op_Body
));
4918 Insert_After
(Current_Node
, New_Op_Body
);
4919 Analyze
(New_Op_Body
);
4924 when N_Entry_Body
=>
4925 Op_Id
:= Defining_Identifier
(Op_Body
);
4926 Has_Entries
:= True;
4927 Num_Entries
:= Num_Entries
+ 1;
4929 New_Op_Body
:= Build_Protected_Entry
(Op_Body
, Op_Id
, Pid
);
4931 Insert_After
(Current_Node
, New_Op_Body
);
4932 Current_Node
:= New_Op_Body
;
4933 Analyze
(New_Op_Body
);
4935 Update_Prival_Subtypes
(New_Op_Body
);
4937 when N_Implicit_Label_Declaration
=>
4940 when N_Itype_Reference
=>
4941 Insert_After
(Current_Node
, New_Copy
(Op_Body
));
4943 when N_Freeze_Entity
=>
4944 New_Op_Body
:= New_Copy
(Op_Body
);
4946 if Present
(Entity
(Op_Body
))
4947 and then Freeze_Node
(Entity
(Op_Body
)) = Op_Body
4949 Set_Freeze_Node
(Entity
(Op_Body
), New_Op_Body
);
4952 Insert_After
(Current_Node
, New_Op_Body
);
4953 Current_Node
:= New_Op_Body
;
4954 Analyze
(New_Op_Body
);
4957 New_Op_Body
:= New_Copy
(Op_Body
);
4958 Insert_After
(Current_Node
, New_Op_Body
);
4959 Current_Node
:= New_Op_Body
;
4960 Analyze
(New_Op_Body
);
4962 when N_Object_Declaration
=>
4963 pragma Assert
(not Comes_From_Source
(Op_Body
));
4964 New_Op_Body
:= New_Copy
(Op_Body
);
4965 Insert_After
(Current_Node
, New_Op_Body
);
4966 Current_Node
:= New_Op_Body
;
4967 Analyze
(New_Op_Body
);
4970 raise Program_Error
;
4977 -- Finally, create the body of the function that maps an entry index
4978 -- into the corresponding body index, except when there is no entry,
4979 -- or in a ravenscar-like profile (no abort, no entry queue, 1 entry)
4982 and then (Abort_Allowed
4983 or else Restriction_Active
(No_Entry_Queue
) = False
4984 or else Num_Entries
> 1)
4986 New_Op_Body
:= Build_Find_Body_Index
(Pid
);
4987 Insert_After
(Current_Node
, New_Op_Body
);
4988 Analyze
(New_Op_Body
);
4990 end Expand_N_Protected_Body
;
4992 -----------------------------------------
4993 -- Expand_N_Protected_Type_Declaration --
4994 -----------------------------------------
4996 -- First we create a corresponding record type declaration used to
4997 -- represent values of this protected type.
4998 -- The general form of this type declaration is
5000 -- type poV (discriminants) is record
5001 -- _Object : aliased <kind>Protection
5002 -- [(<entry count> [, <handler count>])];
5003 -- [entry_family : array (bounds) of Void;]
5004 -- <private data fields>
5007 -- The discriminants are present only if the corresponding protected
5008 -- type has discriminants, and they exactly mirror the protected type
5009 -- discriminants. The private data fields similarly mirror the
5010 -- private declarations of the protected type.
5012 -- The Object field is always present. It contains RTS specific data
5013 -- used to control the protected object. It is declared as Aliased
5014 -- so that it can be passed as a pointer to the RTS. This allows the
5015 -- protected record to be referenced within RTS data structures.
5016 -- An appropriate Protection type and discriminant are generated.
5018 -- The Service field is present for protected objects with entries. It
5019 -- contains sufficient information to allow the entry service procedure
5020 -- for this object to be called when the object is not known till runtime.
5022 -- One entry_family component is present for each entry family in the
5023 -- task definition (see Expand_N_Task_Type_Declaration).
5025 -- When a protected object is declared, an instance of the protected type
5026 -- value record is created. The elaboration of this declaration creates
5027 -- the correct bounds for the entry families, and also evaluates the
5028 -- priority expression if needed. The initialization routine for
5029 -- the protected type itself then calls Initialize_Protection with
5030 -- appropriate parameters to initialize the value of the Task_Id field.
5031 -- Install_Handlers may be also called if a pragma Attach_Handler applies.
5033 -- Note: this record is passed to the subprograms created by the
5034 -- expansion of protected subprograms and entries. It is an in parameter
5035 -- to protected functions and an in out parameter to procedures and
5036 -- entry bodies. The Entity_Id for this created record type is placed
5037 -- in the Corresponding_Record_Type field of the associated protected
5040 -- Next we create a procedure specifications for protected subprograms
5041 -- and entry bodies. For each protected subprograms two subprograms are
5042 -- created, an unprotected and a protected version. The unprotected
5043 -- version is called from within other operations of the same protected
5046 -- We also build the call to register the procedure if a pragma
5047 -- Interrupt_Handler applies.
5049 -- A single subprogram is created to service all entry bodies; it has an
5050 -- additional boolean out parameter indicating that the previous entry
5051 -- call made by the current task was serviced immediately, i.e. not by
5052 -- proxy. The O parameter contains a pointer to a record object of the
5053 -- type described above. An untyped interface is used here to allow this
5054 -- procedure to be called in places where the type of the object to be
5055 -- serviced is not known. This must be done, for example, when a call
5056 -- that may have been requeued is cancelled; the corresponding object
5057 -- must be serviced, but which object that is not known till runtime.
5060 -- (O : System.Address; P : out Boolean);
5061 -- procedure pprocN (_object : in out poV);
5062 -- procedure pproc (_object : in out poV);
5063 -- function pfuncN (_object : poV);
5064 -- function pfunc (_object : poV);
5067 -- Note that this must come after the record type declaration, since
5068 -- the specs refer to this type.
5070 procedure Expand_N_Protected_Type_Declaration
(N
: Node_Id
) is
5071 Loc
: constant Source_Ptr
:= Sloc
(N
);
5072 Prottyp
: constant Entity_Id
:= Defining_Identifier
(N
);
5073 Protnm
: constant Name_Id
:= Chars
(Prottyp
);
5075 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
5076 -- This contains two lists; one for visible and one for private decls
5080 Discr_Map
: constant Elist_Id
:= New_Elmt_List
;
5085 Comp_Id
: Entity_Id
;
5087 Current_Node
: Node_Id
:= N
;
5088 Bdef
: Entity_Id
:= Empty
; -- avoid uninit warning
5089 Edef
: Entity_Id
:= Empty
; -- avoid uninit warning
5090 Entries_Aggr
: Node_Id
;
5091 Body_Id
: Entity_Id
;
5094 Object_Comp
: Node_Id
;
5096 procedure Register_Handler
;
5097 -- for a protected operation that is an interrupt handler, add the
5098 -- freeze action that will register it as such.
5100 ----------------------
5101 -- Register_Handler --
5102 ----------------------
5104 procedure Register_Handler
is
5106 -- All semantic checks already done in Sem_Prag
5108 Prot_Proc
: constant Entity_Id
:=
5110 (Specification
(Current_Node
));
5112 Proc_Address
: constant Node_Id
:=
5113 Make_Attribute_Reference
(Loc
,
5114 Prefix
=> New_Reference_To
(Prot_Proc
, Loc
),
5115 Attribute_Name
=> Name_Address
);
5117 RTS_Call
: constant Entity_Id
:=
5118 Make_Procedure_Call_Statement
(Loc
,
5121 RTE
(RE_Register_Interrupt_Handler
), Loc
),
5122 Parameter_Associations
=>
5123 New_List
(Proc_Address
));
5125 Append_Freeze_Action
(Prot_Proc
, RTS_Call
);
5126 end Register_Handler
;
5128 -- Start of processing for Expand_N_Protected_Type_Declaration
5131 if Present
(Corresponding_Record_Type
(Prottyp
)) then
5134 Rec_Decl
:= Build_Corresponding_Record
(N
, Prottyp
, Loc
);
5135 Cdecls
:= Component_Items
5136 (Component_List
(Type_Definition
(Rec_Decl
)));
5139 Qualify_Entity_Names
(N
);
5141 -- If the type has discriminants, their occurrences in the declaration
5142 -- have been replaced by the corresponding discriminals. For components
5143 -- that are constrained by discriminants, their homologues in the
5144 -- corresponding record type must refer to the discriminants of that
5145 -- record, so we must apply a new renaming to subtypes_indications:
5147 -- protected discriminant => discriminal => record discriminant.
5148 -- This replacement is not applied to default expressions, for which
5149 -- the discriminal is correct.
5151 if Has_Discriminants
(Prottyp
) then
5157 Disc
:= First_Discriminant
(Prottyp
);
5158 Decl
:= First
(Discriminant_Specifications
(Rec_Decl
));
5160 while Present
(Disc
) loop
5161 Append_Elmt
(Discriminal
(Disc
), Discr_Map
);
5162 Append_Elmt
(Defining_Identifier
(Decl
), Discr_Map
);
5163 Next_Discriminant
(Disc
);
5169 -- Fill in the component declarations
5171 -- Add components for entry families. For each entry family,
5172 -- create an anonymous type declaration with the same size, and
5173 -- analyze the type.
5175 Collect_Entry_Families
(Loc
, Cdecls
, Current_Node
, Prottyp
);
5177 -- Prepend the _Object field with the right type to the component
5178 -- list. We need to compute the number of entries, and in some cases
5179 -- the number of Attach_Handler pragmas.
5183 Num_Attach_Handler
: Int
:= 0;
5184 Protection_Subtype
: Node_Id
;
5185 Entry_Count_Expr
: constant Node_Id
:=
5186 Build_Entry_Count_Expression
5187 (Prottyp
, Cdecls
, Loc
);
5190 if Has_Attach_Handler
(Prottyp
) then
5191 Ritem
:= First_Rep_Item
(Prottyp
);
5192 while Present
(Ritem
) loop
5193 if Nkind
(Ritem
) = N_Pragma
5194 and then Chars
(Ritem
) = Name_Attach_Handler
5196 Num_Attach_Handler
:= Num_Attach_Handler
+ 1;
5199 Next_Rep_Item
(Ritem
);
5202 if Restricted_Profile
then
5203 if Has_Entries
(Prottyp
) then
5204 Protection_Subtype
:=
5205 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
5207 Protection_Subtype
:=
5208 New_Reference_To
(RTE
(RE_Protection
), Loc
);
5211 Protection_Subtype
:=
5212 Make_Subtype_Indication
5216 (RTE
(RE_Static_Interrupt_Protection
), Loc
),
5218 Make_Index_Or_Discriminant_Constraint
(
5220 Constraints
=> New_List
(
5222 Make_Integer_Literal
(Loc
, Num_Attach_Handler
))));
5225 elsif Has_Interrupt_Handler
(Prottyp
) then
5226 Protection_Subtype
:=
5227 Make_Subtype_Indication
(
5229 Subtype_Mark
=> New_Reference_To
5230 (RTE
(RE_Dynamic_Interrupt_Protection
), Loc
),
5232 Make_Index_Or_Discriminant_Constraint
(
5234 Constraints
=> New_List
(Entry_Count_Expr
)));
5236 elsif Has_Entries
(Prottyp
) then
5238 or else Restriction_Active
(No_Entry_Queue
) = False
5239 or else Number_Entries
(Prottyp
) > 1
5241 Protection_Subtype
:=
5242 Make_Subtype_Indication
(
5245 New_Reference_To
(RTE
(RE_Protection_Entries
), Loc
),
5247 Make_Index_Or_Discriminant_Constraint
(
5249 Constraints
=> New_List
(Entry_Count_Expr
)));
5252 Protection_Subtype
:=
5253 New_Reference_To
(RTE
(RE_Protection_Entry
), Loc
);
5257 Protection_Subtype
:= New_Reference_To
(RTE
(RE_Protection
), Loc
);
5261 Make_Component_Declaration
(Loc
,
5262 Defining_Identifier
=>
5263 Make_Defining_Identifier
(Loc
, Name_uObject
),
5264 Component_Definition
=>
5265 Make_Component_Definition
(Loc
,
5266 Aliased_Present
=> True,
5267 Subtype_Indication
=> Protection_Subtype
));
5270 pragma Assert
(Present
(Pdef
));
5272 -- Add private field components
5274 if Present
(Private_Declarations
(Pdef
)) then
5275 Priv
:= First
(Private_Declarations
(Pdef
));
5277 while Present
(Priv
) loop
5279 if Nkind
(Priv
) = N_Component_Declaration
then
5280 Pent
:= Defining_Identifier
(Priv
);
5282 Make_Component_Declaration
(Loc
,
5283 Defining_Identifier
=>
5284 Make_Defining_Identifier
(Sloc
(Pent
), Chars
(Pent
)),
5285 Component_Definition
=>
5286 Make_Component_Definition
(Sloc
(Pent
),
5287 Aliased_Present
=> False,
5288 Subtype_Indication
=>
5289 New_Copy_Tree
(Subtype_Indication
5290 (Component_Definition
(Priv
)),
5292 Expression
=> Expression
(Priv
));
5294 Append_To
(Cdecls
, New_Priv
);
5296 elsif Nkind
(Priv
) = N_Subprogram_Declaration
then
5298 -- Make the unprotected version of the subprogram available
5299 -- for expansion of intra object calls. There is need for
5300 -- a protected version only if the subprogram is an interrupt
5301 -- handler, otherwise this operation can only be called from
5305 Make_Subprogram_Declaration
(Loc
,
5307 Build_Protected_Sub_Specification
5308 (Priv
, Prottyp
, Unprotected
=> True));
5310 Insert_After
(Current_Node
, Sub
);
5313 Set_Protected_Body_Subprogram
5314 (Defining_Unit_Name
(Specification
(Priv
)),
5315 Defining_Unit_Name
(Specification
(Sub
)));
5317 Current_Node
:= Sub
;
5318 if Is_Interrupt_Handler
5319 (Defining_Unit_Name
(Specification
(Priv
)))
5322 Make_Subprogram_Declaration
(Loc
,
5324 Build_Protected_Sub_Specification
5325 (Priv
, Prottyp
, Unprotected
=> False));
5327 Insert_After
(Current_Node
, Sub
);
5329 Current_Node
:= Sub
;
5331 if not Restricted_Profile
then
5341 -- Put the _Object component after the private component so that it
5342 -- be finalized early as required by 9.4 (20)
5344 Append_To
(Cdecls
, Object_Comp
);
5346 Insert_After
(Current_Node
, Rec_Decl
);
5347 Current_Node
:= Rec_Decl
;
5349 -- Analyze the record declaration immediately after construction,
5350 -- because the initialization procedure is needed for single object
5351 -- declarations before the next entity is analyzed (the freeze call
5352 -- that generates this initialization procedure is found below).
5354 Analyze
(Rec_Decl
, Suppress
=> All_Checks
);
5356 -- Collect pointers to entry bodies and their barriers, to be placed
5357 -- in the Entry_Bodies_Array for the type. For each entry/family we
5358 -- add an expression to the aggregate which is the initial value of
5359 -- this array. The array is declared after all protected subprograms.
5361 if Has_Entries
(Prottyp
) then
5363 Make_Aggregate
(Loc
, Expressions
=> New_List
);
5366 Entries_Aggr
:= Empty
;
5369 -- Build two new procedure specifications for each protected
5370 -- subprogram; one to call from outside the object and one to
5371 -- call from inside. Build a barrier function and an entry
5372 -- body action procedure specification for each protected entry.
5373 -- Initialize the entry body array. If subprogram is flagged as
5374 -- eliminated, do not generate any internal operations.
5378 Comp
:= First
(Visible_Declarations
(Pdef
));
5380 while Present
(Comp
) loop
5381 if Nkind
(Comp
) = N_Subprogram_Declaration
5382 and then not Is_Eliminated
(Defining_Entity
(Comp
))
5385 Make_Subprogram_Declaration
(Loc
,
5387 Build_Protected_Sub_Specification
5388 (Comp
, Prottyp
, Unprotected
=> True));
5390 Insert_After
(Current_Node
, Sub
);
5393 Set_Protected_Body_Subprogram
5394 (Defining_Unit_Name
(Specification
(Comp
)),
5395 Defining_Unit_Name
(Specification
(Sub
)));
5397 -- Make the protected version of the subprogram available
5398 -- for expansion of external calls.
5400 Current_Node
:= Sub
;
5403 Make_Subprogram_Declaration
(Loc
,
5405 Build_Protected_Sub_Specification
5406 (Comp
, Prottyp
, Unprotected
=> False));
5408 Insert_After
(Current_Node
, Sub
);
5410 Current_Node
:= Sub
;
5412 -- If a pragma Interrupt_Handler applies, build and add
5413 -- a call to Register_Interrupt_Handler to the freezing actions
5414 -- of the protected version (Current_Node) of the subprogram:
5415 -- system.interrupts.register_interrupt_handler
5416 -- (prot_procP'address);
5418 if not Restricted_Profile
5419 and then Is_Interrupt_Handler
5420 (Defining_Unit_Name
(Specification
(Comp
)))
5425 elsif Nkind
(Comp
) = N_Entry_Declaration
then
5426 E_Count
:= E_Count
+ 1;
5427 Comp_Id
:= Defining_Identifier
(Comp
);
5428 Set_Privals_Chain
(Comp_Id
, New_Elmt_List
);
5430 Make_Defining_Identifier
(Loc
,
5433 New_External_Name
(Chars
(Comp_Id
), Suffix_Index
=> -1),
5436 Make_Subprogram_Declaration
(Loc
,
5438 Build_Protected_Entry_Specification
(Edef
, Comp_Id
, Loc
));
5440 Insert_After
(Current_Node
, Sub
);
5443 Set_Protected_Body_Subprogram
(
5444 Defining_Identifier
(Comp
),
5445 Defining_Unit_Name
(Specification
(Sub
)));
5447 Current_Node
:= Sub
;
5450 Make_Defining_Identifier
(Loc
,
5453 New_External_Name
(Chars
(Comp_Id
), Suffix_Index
=> -1),
5456 Make_Subprogram_Declaration
(Loc
,
5458 Build_Barrier_Function_Specification
(Bdef
, Loc
));
5460 Insert_After
(Current_Node
, Sub
);
5462 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
5463 Set_Barrier_Function
(Comp_Id
, Bdef
);
5464 Set_Scope
(Bdef
, Scope
(Comp_Id
));
5465 Current_Node
:= Sub
;
5467 -- Collect pointers to the protected subprogram and the barrier
5468 -- of the current entry, for insertion into Entry_Bodies_Array.
5471 Make_Aggregate
(Loc
,
5472 Expressions
=> New_List
(
5473 Make_Attribute_Reference
(Loc
,
5474 Prefix
=> New_Reference_To
(Bdef
, Loc
),
5475 Attribute_Name
=> Name_Unrestricted_Access
),
5476 Make_Attribute_Reference
(Loc
,
5477 Prefix
=> New_Reference_To
(Edef
, Loc
),
5478 Attribute_Name
=> Name_Unrestricted_Access
))),
5479 Expressions
(Entries_Aggr
));
5486 -- If there are some private entry declarations, expand it as if they
5487 -- were visible entries.
5489 if Present
(Private_Declarations
(Pdef
)) then
5490 Comp
:= First
(Private_Declarations
(Pdef
));
5492 while Present
(Comp
) loop
5493 if Nkind
(Comp
) = N_Entry_Declaration
then
5494 E_Count
:= E_Count
+ 1;
5495 Comp_Id
:= Defining_Identifier
(Comp
);
5496 Set_Privals_Chain
(Comp_Id
, New_Elmt_List
);
5498 Make_Defining_Identifier
(Loc
,
5501 New_External_Name
(Chars
(Comp_Id
), Suffix_Index
=> -1),
5505 Make_Subprogram_Declaration
(Loc
,
5507 Build_Protected_Entry_Specification
(Edef
, Comp_Id
, Loc
));
5509 Insert_After
(Current_Node
, Sub
);
5512 Set_Protected_Body_Subprogram
(
5513 Defining_Identifier
(Comp
),
5514 Defining_Unit_Name
(Specification
(Sub
)));
5516 Current_Node
:= Sub
;
5519 Make_Defining_Identifier
(Loc
,
5522 New_External_Name
(Chars
(Comp_Id
), Suffix_Index
=> -1),
5525 Make_Subprogram_Declaration
(Loc
,
5527 Build_Barrier_Function_Specification
(Bdef
, Loc
));
5529 Insert_After
(Current_Node
, Sub
);
5531 Set_Protected_Body_Subprogram
(Bdef
, Bdef
);
5532 Set_Barrier_Function
(Comp_Id
, Bdef
);
5533 Set_Scope
(Bdef
, Scope
(Comp_Id
));
5534 Current_Node
:= Sub
;
5536 -- Collect pointers to the protected subprogram and the
5537 -- barrier of the current entry, for insertion into
5538 -- Entry_Bodies_Array.
5541 Make_Aggregate
(Loc
,
5542 Expressions
=> New_List
(
5543 Make_Attribute_Reference
(Loc
,
5544 Prefix
=> New_Reference_To
(Bdef
, Loc
),
5545 Attribute_Name
=> Name_Unrestricted_Access
),
5546 Make_Attribute_Reference
(Loc
,
5547 Prefix
=> New_Reference_To
(Edef
, Loc
),
5548 Attribute_Name
=> Name_Unrestricted_Access
))),
5549 Expressions
(Entries_Aggr
));
5556 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
5557 -- all protected subprograms have been collected.
5559 if Has_Entries
(Prottyp
) then
5560 Body_Id
:= Make_Defining_Identifier
(Sloc
(Prottyp
),
5561 New_External_Name
(Chars
(Prottyp
), 'A'));
5564 or else Restriction_Active
(No_Entry_Queue
) = False
5567 Body_Arr
:= Make_Object_Declaration
(Loc
,
5568 Defining_Identifier
=> Body_Id
,
5569 Aliased_Present
=> True,
5570 Object_Definition
=>
5571 Make_Subtype_Indication
(Loc
,
5572 Subtype_Mark
=> New_Reference_To
(
5573 RTE
(RE_Protected_Entry_Body_Array
), Loc
),
5575 Make_Index_Or_Discriminant_Constraint
(Loc
,
5576 Constraints
=> New_List
(
5578 Make_Integer_Literal
(Loc
, 1),
5579 Make_Integer_Literal
(Loc
, E_Count
))))),
5580 Expression
=> Entries_Aggr
);
5583 Body_Arr
:= Make_Object_Declaration
(Loc
,
5584 Defining_Identifier
=> Body_Id
,
5585 Aliased_Present
=> True,
5586 Object_Definition
=> New_Reference_To
(RTE
(RE_Entry_Body
), Loc
),
5588 Make_Aggregate
(Loc
,
5589 Expressions
=> New_List
(
5590 Make_Attribute_Reference
(Loc
,
5591 Prefix
=> New_Reference_To
(Bdef
, Loc
),
5592 Attribute_Name
=> Name_Unrestricted_Access
),
5593 Make_Attribute_Reference
(Loc
,
5594 Prefix
=> New_Reference_To
(Edef
, Loc
),
5595 Attribute_Name
=> Name_Unrestricted_Access
))));
5598 -- A pointer to this array will be placed in the corresponding
5599 -- record by its initialization procedure, so this needs to be
5602 Insert_After
(Current_Node
, Body_Arr
);
5603 Current_Node
:= Body_Arr
;
5606 Set_Entry_Bodies_Array
(Prottyp
, Body_Id
);
5608 -- Finally, build the function that maps an entry index into the
5609 -- corresponding body. A pointer to this function is placed in each
5610 -- object of the type. Except for a ravenscar-like profile (no abort,
5611 -- no entry queue, 1 entry)
5614 or else Restriction_Active
(No_Entry_Queue
) = False
5618 Make_Subprogram_Declaration
(Loc
,
5619 Specification
=> Build_Find_Body_Index_Spec
(Prottyp
));
5620 Insert_After
(Current_Node
, Sub
);
5624 end Expand_N_Protected_Type_Declaration
;
5626 --------------------------------
5627 -- Expand_N_Requeue_Statement --
5628 --------------------------------
5630 -- A requeue statement is expanded into one of four GNARLI operations,
5631 -- depending on the source and destination (task or protected object).
5632 -- In addition, code must be generated to jump around the remainder of
5633 -- processing for the original entry and, if the destination is a
5634 -- (different) protected object, to attempt to service it.
5635 -- The following illustrates the various cases:
5638 -- (O : System.Address;
5639 -- P : System.Address;
5640 -- E : Protected_Entry_Index)
5642 -- <discriminant renamings>
5643 -- <private object renamings>
5644 -- type poVP is access poV;
5645 -- _Object : ptVP := ptVP!(O);
5649 -- <start of statement sequence for entry>
5651 -- -- Requeue from one protected entry body to another protected
5654 -- Requeue_Protected_Entry (
5655 -- _object._object'Access,
5656 -- new._object'Access,
5661 -- <some more of the statement sequence for entry>
5663 -- -- Requeue from an entry body to a task entry
5665 -- Requeue_Protected_To_Task_Entry (
5671 -- <rest of statement sequence for entry>
5672 -- Complete_Entry_Body (_Object._Object);
5675 -- when all others =>
5676 -- Exceptional_Complete_Entry_Body (
5677 -- _Object._Object, Get_GNAT_Exception);
5681 -- Requeue of a task entry call to a task entry
5683 -- Accept_Call (E, Ann);
5684 -- <start of statement sequence for accept statement>
5685 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
5687 -- <rest of statement sequence for accept statement>
5689 -- Complete_Rendezvous;
5692 -- when all others =>
5693 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5695 -- Requeue of a task entry call to a protected entry
5697 -- Accept_Call (E, Ann);
5698 -- <start of statement sequence for accept statement>
5699 -- Requeue_Task_To_Protected_Entry (
5700 -- new._object'Access,
5705 -- <rest of statement sequence for accept statement>
5707 -- Complete_Rendezvous;
5710 -- when all others =>
5711 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5713 -- Further details on these expansions can be found in
5714 -- Expand_N_Protected_Body and Expand_N_Accept_Statement.
5716 procedure Expand_N_Requeue_Statement
(N
: Node_Id
) is
5717 Loc
: constant Source_Ptr
:= Sloc
(N
);
5722 Conctyp
: Entity_Id
;
5726 Abortable
: Node_Id
;
5727 Skip_Stat
: Node_Id
;
5728 Self_Param
: Node_Id
;
5729 New_Param
: Node_Id
;
5731 RTS_Call
: Entity_Id
;
5735 New_Occurrence_Of
(Boolean_Literals
(Abort_Present
(N
)), Loc
);
5737 -- Set up the target object
5739 Extract_Entry
(N
, Concval
, Ename
, Index
);
5740 Conctyp
:= Etype
(Concval
);
5741 New_Param
:= Concurrent_Ref
(Concval
);
5743 -- The target entry index and abortable flag are the same for all cases
5745 Params
:= New_List
(
5746 Entry_Index_Expression
(Loc
, Entity
(Ename
), Index
, Conctyp
),
5749 -- Determine proper GNARLI call and required additional parameters
5750 -- Loop to find nearest enclosing task type or protected type
5752 Oldtyp
:= Current_Scope
;
5754 if Is_Task_Type
(Oldtyp
) then
5755 if Is_Task_Type
(Conctyp
) then
5756 RTS_Call
:= RTE
(RE_Requeue_Task_Entry
);
5759 pragma Assert
(Is_Protected_Type
(Conctyp
));
5760 RTS_Call
:= RTE
(RE_Requeue_Task_To_Protected_Entry
);
5762 Make_Attribute_Reference
(Loc
,
5763 Prefix
=> New_Param
,
5764 Attribute_Name
=> Name_Unchecked_Access
);
5767 Prepend
(New_Param
, Params
);
5770 elsif Is_Protected_Type
(Oldtyp
) then
5772 Make_Attribute_Reference
(Loc
,
5773 Prefix
=> Concurrent_Ref
(New_Occurrence_Of
(Oldtyp
, Loc
)),
5774 Attribute_Name
=> Name_Unchecked_Access
);
5776 if Is_Task_Type
(Conctyp
) then
5777 RTS_Call
:= RTE
(RE_Requeue_Protected_To_Task_Entry
);
5780 pragma Assert
(Is_Protected_Type
(Conctyp
));
5781 RTS_Call
:= RTE
(RE_Requeue_Protected_Entry
);
5783 Make_Attribute_Reference
(Loc
,
5784 Prefix
=> New_Param
,
5785 Attribute_Name
=> Name_Unchecked_Access
);
5788 Prepend
(New_Param
, Params
);
5789 Prepend
(Self_Param
, Params
);
5792 -- If neither task type or protected type, must be in some
5793 -- inner enclosing block, so move on out
5796 Oldtyp
:= Scope
(Oldtyp
);
5800 -- Create the GNARLI call
5802 Rcall
:= Make_Procedure_Call_Statement
(Loc
,
5804 New_Occurrence_Of
(RTS_Call
, Loc
),
5805 Parameter_Associations
=> Params
);
5810 if Is_Protected_Type
(Oldtyp
) then
5812 -- Build the return statement to skip the rest of the entry body
5814 Skip_Stat
:= Make_Return_Statement
(Loc
);
5817 -- If the requeue is within a task, find the end label of the
5818 -- enclosing accept statement.
5820 Acc_Stat
:= Parent
(N
);
5821 while Nkind
(Acc_Stat
) /= N_Accept_Statement
loop
5822 Acc_Stat
:= Parent
(Acc_Stat
);
5825 -- The last statement is the second label, used for completing the
5826 -- rendezvous the usual way.
5827 -- The label we are looking for is right before it.
5830 Prev
(Last
(Statements
(Handled_Statement_Sequence
(Acc_Stat
))));
5832 pragma Assert
(Nkind
(Lab_Node
) = N_Label
);
5834 -- Build the goto statement to skip the rest of the accept
5838 Make_Goto_Statement
(Loc
,
5839 Name
=> New_Occurrence_Of
(Entity
(Identifier
(Lab_Node
)), Loc
));
5842 Set_Analyzed
(Skip_Stat
);
5844 Insert_After
(N
, Skip_Stat
);
5845 end Expand_N_Requeue_Statement
;
5847 -------------------------------
5848 -- Expand_N_Selective_Accept --
5849 -------------------------------
5851 procedure Expand_N_Selective_Accept
(N
: Node_Id
) is
5852 Loc
: constant Source_Ptr
:= Sloc
(N
);
5853 Alts
: constant List_Id
:= Select_Alternatives
(N
);
5855 -- Note: in the below declarations a lot of new lists are allocated
5856 -- unconditionally which may well not end up being used. That's
5857 -- not a good idea since it wastes space gratuitously ???
5859 Accept_Case
: List_Id
;
5860 Accept_List
: constant List_Id
:= New_List
;
5863 Alt_List
: constant List_Id
:= New_List
;
5864 Alt_Stats
: List_Id
;
5865 Ann
: Entity_Id
:= Empty
;
5868 Check_Guard
: Boolean := True;
5870 Decls
: constant List_Id
:= New_List
;
5871 Stats
: constant List_Id
:= New_List
;
5872 Body_List
: constant List_Id
:= New_List
;
5873 Trailing_List
: constant List_Id
:= New_List
;
5876 Else_Present
: Boolean := False;
5877 Terminate_Alt
: Node_Id
:= Empty
;
5878 Select_Mode
: Node_Id
;
5880 Delay_Case
: List_Id
;
5881 Delay_Count
: Integer := 0;
5882 Delay_Val
: Entity_Id
;
5883 Delay_Index
: Entity_Id
;
5884 Delay_Min
: Entity_Id
;
5885 Delay_Num
: Int
:= 1;
5886 Delay_Alt_List
: List_Id
:= New_List
;
5887 Delay_List
: constant List_Id
:= New_List
;
5891 First_Delay
: Boolean := True;
5892 Guard_Open
: Entity_Id
;
5898 Num_Accept
: Nat
:= 0;
5901 Time_Type
: Entity_Id
;
5903 Select_Call
: Node_Id
;
5905 Qnam
: constant Entity_Id
:=
5906 Make_Defining_Identifier
(Loc
, New_External_Name
('S', 0));
5908 Xnam
: constant Entity_Id
:=
5909 Make_Defining_Identifier
(Loc
, New_External_Name
('J', 1));
5911 -----------------------
5912 -- Local subprograms --
5913 -----------------------
5915 function Accept_Or_Raise
return List_Id
;
5916 -- For the rare case where delay alternatives all have guards, and
5917 -- all of them are closed, it is still possible that there were open
5918 -- accept alternatives with no callers. We must reexamine the
5919 -- Accept_List, and execute a selective wait with no else if some
5920 -- accept is open. If none, we raise program_error.
5922 procedure Add_Accept
(Alt
: Node_Id
);
5923 -- Process a single accept statement in a select alternative. Build
5924 -- procedure for body of accept, and add entry to dispatch table with
5925 -- expression for guard, in preparation for call to run time select.
5927 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
;
5928 -- Manufacture a label using Num as a serial number and declare it.
5929 -- The declaration is appended to Decls. The label marks the trailing
5930 -- statements of an accept or delay alternative.
5932 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
;
5933 -- Build call to Selective_Wait runtime routine
5935 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
);
5936 -- Add code to compare value of delay with previous values, and
5937 -- generate case entry for trailing statements.
5939 procedure Process_Accept_Alternative
5943 -- Add code to call corresponding procedure, and branch to
5944 -- trailing statements, if any.
5946 ---------------------
5947 -- Accept_Or_Raise --
5948 ---------------------
5950 function Accept_Or_Raise
return List_Id
is
5953 J
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
,
5954 New_Internal_Name
('J'));
5957 -- We generate the following:
5959 -- for J in q'range loop
5960 -- if q(J).S /=null_task_entry then
5961 -- selective_wait (simple_mode,...);
5967 -- if no rendez_vous then
5968 -- raise program_error;
5971 -- Note that the code needs to know that the selector name
5972 -- in an Accept_Alternative is named S.
5974 Cond
:= Make_Op_Ne
(Loc
,
5976 Make_Selected_Component
(Loc
,
5977 Prefix
=> Make_Indexed_Component
(Loc
,
5978 Prefix
=> New_Reference_To
(Qnam
, Loc
),
5979 Expressions
=> New_List
(New_Reference_To
(J
, Loc
))),
5980 Selector_Name
=> Make_Identifier
(Loc
, Name_S
)),
5982 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
));
5985 Make_Implicit_Loop_Statement
(N
,
5986 Identifier
=> Empty
,
5988 Make_Iteration_Scheme
(Loc
,
5989 Loop_Parameter_Specification
=>
5990 Make_Loop_Parameter_Specification
(Loc
,
5991 Defining_Identifier
=> J
,
5992 Discrete_Subtype_Definition
=>
5993 Make_Attribute_Reference
(Loc
,
5994 Prefix
=> New_Reference_To
(Qnam
, Loc
),
5995 Attribute_Name
=> Name_Range
,
5996 Expressions
=> New_List
(
5997 Make_Integer_Literal
(Loc
, 1))))),
5999 Statements
=> New_List
(
6000 Make_Implicit_If_Statement
(N
,
6002 Then_Statements
=> New_List
(
6004 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)),
6005 Make_Exit_Statement
(Loc
))))));
6008 Make_Raise_Program_Error
(Loc
,
6009 Condition
=> Make_Op_Eq
(Loc
,
6010 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
6012 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
6013 Reason
=> PE_All_Guards_Closed
));
6016 end Accept_Or_Raise
;
6022 procedure Add_Accept
(Alt
: Node_Id
) is
6023 Acc_Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
6024 Ename
: constant Node_Id
:= Entry_Direct_Name
(Acc_Stm
);
6025 Eent
: constant Entity_Id
:= Entity
(Ename
);
6026 Index
: constant Node_Id
:= Entry_Index
(Acc_Stm
);
6027 Null_Body
: Node_Id
;
6028 Proc_Body
: Node_Id
;
6035 Ann
:= Node
(Last_Elmt
(Accept_Address
(Eent
)));
6038 if Present
(Condition
(Alt
)) then
6040 Make_Conditional_Expression
(Loc
, New_List
(
6042 Entry_Index_Expression
(Loc
, Eent
, Index
, Scope
(Eent
)),
6043 New_Reference_To
(RTE
(RE_Null_Task_Entry
), Loc
)));
6046 Entry_Index_Expression
6047 (Loc
, Eent
, Index
, Scope
(Eent
));
6050 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
6051 Null_Body
:= New_Reference_To
(Standard_False
, Loc
);
6053 if Abort_Allowed
then
6054 Call
:= Make_Procedure_Call_Statement
(Loc
,
6055 Name
=> New_Reference_To
(RTE
(RE_Abort_Undefer
), Loc
));
6056 Insert_Before
(First
(Statements
(Handled_Statement_Sequence
(
6057 Accept_Statement
(Alt
)))), Call
);
6062 Make_Defining_Identifier
(Sloc
(Ename
),
6063 New_External_Name
(Chars
(Ename
), 'A', Num_Accept
));
6065 Set_Needs_Debug_Info
(PB_Ent
, Comes_From_Source
(Alt
));
6068 Make_Subprogram_Body
(Loc
,
6070 Make_Procedure_Specification
(Loc
,
6071 Defining_Unit_Name
=> PB_Ent
),
6072 Declarations
=> Declarations
(Acc_Stm
),
6073 Handled_Statement_Sequence
=>
6074 Build_Accept_Body
(Accept_Statement
(Alt
)));
6076 -- During the analysis of the body of the accept statement, any
6077 -- zero cost exception handler records were collected in the
6078 -- Accept_Handler_Records field of the N_Accept_Alternative
6079 -- node. This is where we move them to where they belong,
6080 -- namely the newly created procedure.
6082 Set_Handler_Records
(PB_Ent
, Accept_Handler_Records
(Alt
));
6083 Append
(Proc_Body
, Body_List
);
6086 Null_Body
:= New_Reference_To
(Standard_True
, Loc
);
6088 -- if accept statement has declarations, insert above, given
6089 -- that we are not creating a body for the accept.
6091 if Present
(Declarations
(Acc_Stm
)) then
6092 Insert_Actions
(N
, Declarations
(Acc_Stm
));
6096 Append_To
(Accept_List
,
6097 Make_Aggregate
(Loc
, Expressions
=> New_List
(Null_Body
, Expr
)));
6099 Num_Accept
:= Num_Accept
+ 1;
6102 ----------------------------
6103 -- Make_And_Declare_Label --
6104 ----------------------------
6106 function Make_And_Declare_Label
(Num
: Int
) return Node_Id
is
6110 Lab_Id
:= Make_Identifier
(Loc
, New_External_Name
('L', Num
));
6112 Make_Label
(Loc
, Lab_Id
);
6115 Make_Implicit_Label_Declaration
(Loc
,
6116 Defining_Identifier
=>
6117 Make_Defining_Identifier
(Loc
, Chars
(Lab_Id
)),
6118 Label_Construct
=> Lab
));
6121 end Make_And_Declare_Label
;
6123 ----------------------
6124 -- Make_Select_Call --
6125 ----------------------
6127 function Make_Select_Call
(Select_Mode
: Entity_Id
) return Node_Id
is
6128 Params
: constant List_Id
:= New_List
;
6132 Make_Attribute_Reference
(Loc
,
6133 Prefix
=> New_Reference_To
(Qnam
, Loc
),
6134 Attribute_Name
=> Name_Unchecked_Access
),
6136 Append
(Select_Mode
, Params
);
6137 Append
(New_Reference_To
(Ann
, Loc
), Params
);
6138 Append
(New_Reference_To
(Xnam
, Loc
), Params
);
6141 Make_Procedure_Call_Statement
(Loc
,
6142 Name
=> New_Reference_To
(RTE
(RE_Selective_Wait
), Loc
),
6143 Parameter_Associations
=> Params
);
6144 end Make_Select_Call
;
6146 --------------------------------
6147 -- Process_Accept_Alternative --
6148 --------------------------------
6150 procedure Process_Accept_Alternative
6155 Choices
: List_Id
:= No_List
;
6156 Alt_Stats
: List_Id
;
6159 Adjust_Condition
(Condition
(Alt
));
6160 Alt_Stats
:= No_List
;
6162 if Present
(Handled_Statement_Sequence
(Accept_Statement
(Alt
))) then
6163 Choices
:= New_List
(
6164 Make_Integer_Literal
(Loc
, Index
));
6166 Alt_Stats
:= New_List
(
6167 Make_Procedure_Call_Statement
(Loc
,
6168 Name
=> New_Reference_To
(
6169 Defining_Unit_Name
(Specification
(Proc
)), Loc
)));
6172 if Statements
(Alt
) /= Empty_List
then
6174 if No
(Alt_Stats
) then
6176 -- Accept with no body, followed by trailing statements
6178 Choices
:= New_List
(
6179 Make_Integer_Literal
(Loc
, Index
));
6181 Alt_Stats
:= New_List
;
6184 -- After the call, if any, branch to to trailing statements.
6185 -- We create a label for each, as well as the corresponding
6186 -- label declaration.
6188 Lab
:= Make_And_Declare_Label
(Index
);
6189 Append_To
(Alt_Stats
,
6190 Make_Goto_Statement
(Loc
,
6191 Name
=> New_Copy
(Identifier
(Lab
))));
6193 Append
(Lab
, Trailing_List
);
6194 Append_List
(Statements
(Alt
), Trailing_List
);
6195 Append_To
(Trailing_List
,
6196 Make_Goto_Statement
(Loc
,
6197 Name
=> New_Copy
(Identifier
(End_Lab
))));
6200 if Present
(Alt_Stats
) then
6202 -- Procedure call. and/or trailing statements
6204 Append_To
(Alt_List
,
6205 Make_Case_Statement_Alternative
(Loc
,
6206 Discrete_Choices
=> Choices
,
6207 Statements
=> Alt_Stats
));
6209 end Process_Accept_Alternative
;
6211 -------------------------------
6212 -- Process_Delay_Alternative --
6213 -------------------------------
6215 procedure Process_Delay_Alternative
(Alt
: Node_Id
; Index
: Int
) is
6218 Delay_Alt
: List_Id
;
6221 -- Deal with C/Fortran boolean as delay condition
6223 Adjust_Condition
(Condition
(Alt
));
6225 -- Determine the smallest specified delay
6227 -- for each delay alternative generate:
6229 -- if guard-expression then
6230 -- Delay_Val := delay-expression;
6231 -- Guard_Open := True;
6232 -- if Delay_Val < Delay_Min then
6233 -- Delay_Min := Delay_Val;
6234 -- Delay_Index := Index;
6238 -- The enclosing if-statement is omitted if there is no guard
6243 First_Delay
:= False;
6245 Delay_Alt
:= New_List
(
6246 Make_Assignment_Statement
(Loc
,
6247 Name
=> New_Reference_To
(Delay_Min
, Loc
),
6248 Expression
=> Expression
(Delay_Statement
(Alt
))));
6250 if Delay_Count
> 1 then
6251 Append_To
(Delay_Alt
,
6252 Make_Assignment_Statement
(Loc
,
6253 Name
=> New_Reference_To
(Delay_Index
, Loc
),
6254 Expression
=> Make_Integer_Literal
(Loc
, Index
)));
6258 Delay_Alt
:= New_List
(
6259 Make_Assignment_Statement
(Loc
,
6260 Name
=> New_Reference_To
(Delay_Val
, Loc
),
6261 Expression
=> Expression
(Delay_Statement
(Alt
))));
6263 if Time_Type
= Standard_Duration
then
6266 Left_Opnd
=> New_Reference_To
(Delay_Val
, Loc
),
6267 Right_Opnd
=> New_Reference_To
(Delay_Min
, Loc
));
6270 -- The scope of the time type must define a comparison
6271 -- operator. The scope itself may not be visible, so we
6272 -- construct a node with entity information to insure that
6273 -- semantic analysis can find the proper operator.
6276 Make_Function_Call
(Loc
,
6277 Name
=> Make_Selected_Component
(Loc
,
6278 Prefix
=> New_Reference_To
(Scope
(Time_Type
), Loc
),
6280 Make_Operator_Symbol
(Loc
,
6281 Chars
=> Name_Op_Lt
,
6282 Strval
=> No_String
)),
6283 Parameter_Associations
=>
6285 New_Reference_To
(Delay_Val
, Loc
),
6286 New_Reference_To
(Delay_Min
, Loc
)));
6288 Set_Entity
(Prefix
(Name
(Cond
)), Scope
(Time_Type
));
6291 Append_To
(Delay_Alt
,
6292 Make_Implicit_If_Statement
(N
,
6294 Then_Statements
=> New_List
(
6295 Make_Assignment_Statement
(Loc
,
6296 Name
=> New_Reference_To
(Delay_Min
, Loc
),
6297 Expression
=> New_Reference_To
(Delay_Val
, Loc
)),
6299 Make_Assignment_Statement
(Loc
,
6300 Name
=> New_Reference_To
(Delay_Index
, Loc
),
6301 Expression
=> Make_Integer_Literal
(Loc
, Index
)))));
6305 Append_To
(Delay_Alt
,
6306 Make_Assignment_Statement
(Loc
,
6307 Name
=> New_Reference_To
(Guard_Open
, Loc
),
6308 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
6311 if Present
(Condition
(Alt
)) then
6312 Delay_Alt
:= New_List
(
6313 Make_Implicit_If_Statement
(N
,
6314 Condition
=> Condition
(Alt
),
6315 Then_Statements
=> Delay_Alt
));
6318 Append_List
(Delay_Alt
, Delay_List
);
6320 -- If the delay alternative has a statement part, add a
6321 -- choice to the case statements for delays.
6323 if Present
(Statements
(Alt
)) then
6325 if Delay_Count
= 1 then
6326 Append_List
(Statements
(Alt
), Delay_Alt_List
);
6329 Choices
:= New_List
(
6330 Make_Integer_Literal
(Loc
, Index
));
6332 Append_To
(Delay_Alt_List
,
6333 Make_Case_Statement_Alternative
(Loc
,
6334 Discrete_Choices
=> Choices
,
6335 Statements
=> Statements
(Alt
)));
6338 elsif Delay_Count
= 1 then
6340 -- If the single delay has no trailing statements, add a branch
6341 -- to the exit label to the selective wait.
6343 Delay_Alt_List
:= New_List
(
6344 Make_Goto_Statement
(Loc
,
6345 Name
=> New_Copy
(Identifier
(End_Lab
))));
6348 end Process_Delay_Alternative
;
6350 -- Start of processing for Expand_N_Selective_Accept
6353 -- First insert some declarations before the select. The first is:
6357 -- This variable holds the parameters passed to the accept body. This
6358 -- declaration has already been inserted by the time we get here by
6359 -- a call to Expand_Accept_Declarations made from the semantics when
6360 -- processing the first accept statement contained in the select. We
6361 -- can find this entity as Accept_Address (E), where E is any of the
6362 -- entries references by contained accept statements.
6364 -- The first step is to scan the list of Selective_Accept_Statements
6365 -- to find this entity, and also count the number of accepts, and
6366 -- determine if terminated, delay or else is present:
6370 Alt
:= First
(Alts
);
6371 while Present
(Alt
) loop
6373 if Nkind
(Alt
) = N_Accept_Alternative
then
6376 elsif Nkind
(Alt
) = N_Delay_Alternative
then
6377 Delay_Count
:= Delay_Count
+ 1;
6379 -- If the delays are relative delays, the delay expressions have
6380 -- type Standard_Duration. Otherwise they must have some time type
6381 -- recognized by GNAT.
6383 if Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
then
6384 Time_Type
:= Standard_Duration
;
6386 Time_Type
:= Etype
(Expression
(Delay_Statement
(Alt
)));
6388 if Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
)
6389 or else Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
)
6394 "& is not a time type ('R'M 9.6(6))",
6395 Expression
(Delay_Statement
(Alt
)), Time_Type
);
6396 Time_Type
:= Standard_Duration
;
6397 Set_Etype
(Expression
(Delay_Statement
(Alt
)), Any_Type
);
6401 if No
(Condition
(Alt
)) then
6403 -- This guard will always be open
6405 Check_Guard
:= False;
6408 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
6409 Adjust_Condition
(Condition
(Alt
));
6410 Terminate_Alt
:= Alt
;
6413 Num_Alts
:= Num_Alts
+ 1;
6417 Else_Present
:= Present
(Else_Statements
(N
));
6419 -- At the same time (see procedure Add_Accept) we build the accept list:
6421 -- Qnn : Accept_List (1 .. num-select) := (
6422 -- (null-body, entry-index),
6423 -- (null-body, entry-index),
6425 -- (null_body, entry-index));
6427 -- In the above declaration, null-body is True if the corresponding
6428 -- accept has no body, and false otherwise. The entry is either the
6429 -- entry index expression if there is no guard, or if a guard is
6430 -- present, then a conditional expression of the form:
6432 -- (if guard then entry-index else Null_Task_Entry)
6434 -- If a guard is statically known to be false, the entry can simply
6435 -- be omitted from the accept list.
6438 Make_Object_Declaration
(Loc
,
6439 Defining_Identifier
=> Qnam
,
6440 Object_Definition
=>
6441 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
6442 Aliased_Present
=> True,
6445 Make_Qualified_Expression
(Loc
,
6447 New_Reference_To
(RTE
(RE_Accept_List
), Loc
),
6449 Make_Aggregate
(Loc
, Expressions
=> Accept_List
)));
6453 -- Then we declare the variable that holds the index for the accept
6454 -- that will be selected for service:
6456 -- Xnn : Select_Index;
6459 Make_Object_Declaration
(Loc
,
6460 Defining_Identifier
=> Xnam
,
6461 Object_Definition
=>
6462 New_Reference_To
(RTE
(RE_Select_Index
), Loc
),
6464 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
6468 -- After this follow procedure declarations for each accept body
6475 -- where the ... are statements from the corresponding procedure body.
6476 -- No parameters are involved, since the parameters are passed via Ann
6477 -- and the parameter references have already been expanded to be direct
6478 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
6479 -- any embedded tasking statements (which would normally be illegal in
6480 -- procedures, have been converted to calls to the tasking runtime so
6481 -- there is no problem in putting them into procedures.
6483 -- The original accept statement has been expanded into a block in
6484 -- the same fashion as for simple accepts (see Build_Accept_Body).
6486 -- Note: we don't really need to build these procedures for the case
6487 -- where no delay statement is present, but it is just as easy to
6488 -- build them unconditionally, and not significantly inefficient,
6489 -- since if they are short they will be inlined anyway.
6491 -- The procedure declarations have been assembled in Body_List
6493 -- If delays are present, we must compute the required delay.
6494 -- We first generate the declarations:
6496 -- Delay_Index : Boolean := 0;
6497 -- Delay_Min : Some_Time_Type.Time;
6498 -- Delay_Val : Some_Time_Type.Time;
6500 -- Delay_Index will be set to the index of the minimum delay, i.e. the
6501 -- active delay that is actually chosen as the basis for the possible
6502 -- delay if an immediate rendez-vous is not possible.
6504 -- In the most common case there is a single delay statement, and this
6505 -- is handled specially.
6507 if Delay_Count
> 0 then
6509 -- Generate the required declarations
6512 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 1));
6514 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 2));
6516 Make_Defining_Identifier
(Loc
, New_External_Name
('D', 3));
6519 Make_Object_Declaration
(Loc
,
6520 Defining_Identifier
=> Delay_Val
,
6521 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
)));
6524 Make_Object_Declaration
(Loc
,
6525 Defining_Identifier
=> Delay_Index
,
6526 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
6527 Expression
=> Make_Integer_Literal
(Loc
, 0)));
6530 Make_Object_Declaration
(Loc
,
6531 Defining_Identifier
=> Delay_Min
,
6532 Object_Definition
=> New_Reference_To
(Time_Type
, Loc
),
6534 Unchecked_Convert_To
(Time_Type
,
6535 Make_Attribute_Reference
(Loc
,
6537 New_Occurrence_Of
(Underlying_Type
(Time_Type
), Loc
),
6538 Attribute_Name
=> Name_Last
))));
6540 -- Create Duration and Delay_Mode objects used for passing a delay
6543 D
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
6544 M
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('M'));
6550 -- Note that these values are defined in s-osprim.ads and must
6553 -- Relative : constant := 0;
6554 -- Absolute_Calendar : constant := 1;
6555 -- Absolute_RT : constant := 2;
6557 if Time_Type
= Standard_Duration
then
6558 Discr
:= Make_Integer_Literal
(Loc
, 0);
6560 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
6561 Discr
:= Make_Integer_Literal
(Loc
, 1);
6565 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
6566 Discr
:= Make_Integer_Literal
(Loc
, 2);
6570 Make_Object_Declaration
(Loc
,
6571 Defining_Identifier
=> D
,
6572 Object_Definition
=>
6573 New_Reference_To
(Standard_Duration
, Loc
)));
6576 Make_Object_Declaration
(Loc
,
6577 Defining_Identifier
=> M
,
6578 Object_Definition
=>
6579 New_Reference_To
(Standard_Integer
, Loc
),
6580 Expression
=> Discr
));
6585 Make_Defining_Identifier
(Loc
, New_External_Name
('G', 1));
6588 Make_Object_Declaration
(Loc
,
6589 Defining_Identifier
=> Guard_Open
,
6590 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
6591 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
6594 -- Delay_Count is zero, don't need M and D set (suppress warning)
6601 if Present
(Terminate_Alt
) then
6603 -- If the terminate alternative guard is False, use
6604 -- Simple_Mode; otherwise use Terminate_Mode.
6606 if Present
(Condition
(Terminate_Alt
)) then
6607 Select_Mode
:= Make_Conditional_Expression
(Loc
,
6608 New_List
(Condition
(Terminate_Alt
),
6609 New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
),
6610 New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
)));
6612 Select_Mode
:= New_Reference_To
(RTE
(RE_Terminate_Mode
), Loc
);
6615 elsif Else_Present
or Delay_Count
> 0 then
6616 Select_Mode
:= New_Reference_To
(RTE
(RE_Else_Mode
), Loc
);
6619 Select_Mode
:= New_Reference_To
(RTE
(RE_Simple_Mode
), Loc
);
6622 Select_Call
:= Make_Select_Call
(Select_Mode
);
6623 Append
(Select_Call
, Stats
);
6625 -- Now generate code to act on the result. There is an entry
6626 -- in this case for each accept statement with a non-null body,
6627 -- followed by a branch to the statements that follow the Accept.
6628 -- In the absence of delay alternatives, we generate:
6631 -- when No_Rendezvous => -- omitted if simple mode
6646 -- Lab0: Else_Statements;
6649 -- Lab1: Trailing_Statements1;
6652 -- Lab2: Trailing_Statements2;
6657 -- Generate label for common exit
6659 End_Lab
:= Make_And_Declare_Label
(Num_Alts
+ 1);
6661 -- First entry is the default case, when no rendezvous is possible
6663 Choices
:= New_List
(New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
));
6665 if Else_Present
then
6667 -- If no rendezvous is possible, the else part is executed
6669 Lab
:= Make_And_Declare_Label
(0);
6670 Alt_Stats
:= New_List
(
6671 Make_Goto_Statement
(Loc
,
6672 Name
=> New_Copy
(Identifier
(Lab
))));
6674 Append
(Lab
, Trailing_List
);
6675 Append_List
(Else_Statements
(N
), Trailing_List
);
6676 Append_To
(Trailing_List
,
6677 Make_Goto_Statement
(Loc
,
6678 Name
=> New_Copy
(Identifier
(End_Lab
))));
6680 Alt_Stats
:= New_List
(
6681 Make_Goto_Statement
(Loc
,
6682 Name
=> New_Copy
(Identifier
(End_Lab
))));
6685 Append_To
(Alt_List
,
6686 Make_Case_Statement_Alternative
(Loc
,
6687 Discrete_Choices
=> Choices
,
6688 Statements
=> Alt_Stats
));
6690 -- We make use of the fact that Accept_Index is an integer type,
6691 -- and generate successive literals for entries for each accept.
6692 -- Only those for which there is a body or trailing statements are
6693 -- given a case entry.
6695 Alt
:= First
(Select_Alternatives
(N
));
6696 Proc
:= First
(Body_List
);
6698 while Present
(Alt
) loop
6700 if Nkind
(Alt
) = N_Accept_Alternative
then
6701 Process_Accept_Alternative
(Alt
, Index
, Proc
);
6705 (Handled_Statement_Sequence
(Accept_Statement
(Alt
)))
6710 elsif Nkind
(Alt
) = N_Delay_Alternative
then
6711 Process_Delay_Alternative
(Alt
, Delay_Num
);
6712 Delay_Num
:= Delay_Num
+ 1;
6718 -- An others choice is always added to the main case, as well
6719 -- as the delay case (to satisfy the compiler).
6721 Append_To
(Alt_List
,
6722 Make_Case_Statement_Alternative
(Loc
,
6724 New_List
(Make_Others_Choice
(Loc
)),
6726 New_List
(Make_Goto_Statement
(Loc
,
6727 Name
=> New_Copy
(Identifier
(End_Lab
))))));
6729 Accept_Case
:= New_List
(
6730 Make_Case_Statement
(Loc
,
6731 Expression
=> New_Reference_To
(Xnam
, Loc
),
6732 Alternatives
=> Alt_List
));
6734 Append_List
(Trailing_List
, Accept_Case
);
6735 Append
(End_Lab
, Accept_Case
);
6736 Append_List
(Body_List
, Decls
);
6738 -- Construct case statement for trailing statements of delay
6739 -- alternatives, if there are several of them.
6741 if Delay_Count
> 1 then
6742 Append_To
(Delay_Alt_List
,
6743 Make_Case_Statement_Alternative
(Loc
,
6745 New_List
(Make_Others_Choice
(Loc
)),
6747 New_List
(Make_Null_Statement
(Loc
))));
6749 Delay_Case
:= New_List
(
6750 Make_Case_Statement
(Loc
,
6751 Expression
=> New_Reference_To
(Delay_Index
, Loc
),
6752 Alternatives
=> Delay_Alt_List
));
6754 Delay_Case
:= Delay_Alt_List
;
6757 -- If there are no delay alternatives, we append the case statement
6758 -- to the statement list.
6760 if Delay_Count
= 0 then
6761 Append_List
(Accept_Case
, Stats
);
6763 -- Delay alternatives present
6766 -- If delay alternatives are present we generate:
6768 -- find minimum delay.
6769 -- DX := minimum delay;
6770 -- M := <delay mode>;
6771 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
6774 -- if X = No_Rendezvous then
6775 -- case statement for delay statements.
6777 -- case statement for accept alternatives.
6788 -- The type of the delay expression is known to be legal
6790 if Time_Type
= Standard_Duration
then
6791 Conv
:= New_Reference_To
(Delay_Min
, Loc
);
6793 elsif Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_CA_Time
) then
6794 Conv
:= Make_Function_Call
(Loc
,
6795 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
6796 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
6800 (Is_RTE
(Base_Type
(Etype
(Time_Type
)), RO_RT_Time
));
6802 Conv
:= Make_Function_Call
(Loc
,
6803 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
6804 New_List
(New_Reference_To
(Delay_Min
, Loc
)));
6807 Stmt
:= Make_Assignment_Statement
(Loc
,
6808 Name
=> New_Reference_To
(D
, Loc
),
6809 Expression
=> Conv
);
6811 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
6813 Parms
:= Parameter_Associations
(Select_Call
);
6814 Parm
:= First
(Parms
);
6816 while Present
(Parm
)
6817 and then Parm
/= Select_Mode
6822 pragma Assert
(Present
(Parm
));
6823 Rewrite
(Parm
, New_Reference_To
(RTE
(RE_Delay_Mode
), Loc
));
6826 -- Prepare two new parameters of Duration and Delay_Mode type
6827 -- which represent the value and the mode of the minimum delay.
6830 Insert_After
(Parm
, New_Reference_To
(M
, Loc
));
6831 Insert_After
(Parm
, New_Reference_To
(D
, Loc
));
6833 -- Create a call to RTS
6835 Rewrite
(Select_Call
,
6836 Make_Procedure_Call_Statement
(Loc
,
6837 Name
=> New_Reference_To
(RTE
(RE_Timed_Selective_Wait
), Loc
),
6838 Parameter_Associations
=> Parms
));
6840 -- This new call should follow the calculation of the
6843 Insert_List_Before
(Select_Call
, Delay_List
);
6847 Make_Implicit_If_Statement
(N
,
6848 Condition
=> New_Reference_To
(Guard_Open
, Loc
),
6850 New_List
(New_Copy_Tree
(Stmt
),
6851 New_Copy_Tree
(Select_Call
)),
6852 Else_Statements
=> Accept_Or_Raise
);
6853 Rewrite
(Select_Call
, Stmt
);
6855 Insert_Before
(Select_Call
, Stmt
);
6859 Make_Implicit_If_Statement
(N
,
6860 Condition
=> Make_Op_Eq
(Loc
,
6861 Left_Opnd
=> New_Reference_To
(Xnam
, Loc
),
6863 New_Reference_To
(RTE
(RE_No_Rendezvous
), Loc
)),
6865 Then_Statements
=> Delay_Case
,
6866 Else_Statements
=> Accept_Case
);
6868 Append
(Cases
, Stats
);
6872 -- Replace accept statement with appropriate block
6875 Make_Block_Statement
(Loc
,
6876 Declarations
=> Decls
,
6877 Handled_Statement_Sequence
=>
6878 Make_Handled_Sequence_Of_Statements
(Loc
,
6879 Statements
=> Stats
));
6884 -- Note: have to worry more about abort deferral in above code ???
6886 -- Final step is to unstack the Accept_Address entries for all accept
6887 -- statements appearing in accept alternatives in the select statement
6889 Alt
:= First
(Alts
);
6890 while Present
(Alt
) loop
6891 if Nkind
(Alt
) = N_Accept_Alternative
then
6892 Remove_Last_Elmt
(Accept_Address
6893 (Entity
(Entry_Direct_Name
(Accept_Statement
(Alt
)))));
6898 end Expand_N_Selective_Accept
;
6900 --------------------------------------
6901 -- Expand_N_Single_Task_Declaration --
6902 --------------------------------------
6904 -- Single task declarations should never be present after semantic
6905 -- analysis, since we expect them to be replaced by a declaration of
6906 -- an anonymous task type, followed by a declaration of the task
6907 -- object. We include this routine to make sure that is happening!
6909 procedure Expand_N_Single_Task_Declaration
(N
: Node_Id
) is
6911 raise Program_Error
;
6912 end Expand_N_Single_Task_Declaration
;
6914 ------------------------
6915 -- Expand_N_Task_Body --
6916 ------------------------
6918 -- Given a task body
6920 -- task body tname is
6926 -- This expansion routine converts it into a procedure and sets the
6927 -- elaboration flag for the procedure to true, to represent the fact
6928 -- that the task body is now elaborated:
6930 -- procedure tnameB (_Task : access tnameV) is
6931 -- discriminal : dtype renames _Task.discriminant;
6933 -- procedure _clean is
6937 -- Abort_Undefer.all;
6942 -- Abort_Undefer.all;
6944 -- System.Task_Stages.Complete_Activation;
6952 -- In addition, if the task body is an activator, then a call to
6953 -- activate tasks is added at the start of the statements, before
6954 -- the call to Complete_Activation, and if in addition the task is
6955 -- a master then it must be established as a master. These calls are
6956 -- inserted and analyzed in Expand_Cleanup_Actions, when the
6957 -- Handled_Sequence_Of_Statements is expanded.
6959 -- There is one discriminal declaration line generated for each
6960 -- discriminant that is present to provide an easy reference point
6961 -- for discriminant references inside the body (see Exp_Ch2.Expand_Name).
6963 -- Note on relationship to GNARLI definition. In the GNARLI definition,
6964 -- task body procedures have a profile (Arg : System.Address). That is
6965 -- needed because GNARLI has to use the same access-to-subprogram type
6966 -- for all task types. We depend here on knowing that in GNAT, passing
6967 -- an address argument by value is identical to passing a record value
6968 -- by access (in either case a single pointer is passed), so even though
6969 -- this procedure has the wrong profile. In fact it's all OK, since the
6970 -- callings sequence is identical.
6972 procedure Expand_N_Task_Body
(N
: Node_Id
) is
6973 Loc
: constant Source_Ptr
:= Sloc
(N
);
6974 Ttyp
: constant Entity_Id
:= Corresponding_Spec
(N
);
6979 -- Here we start the expansion by generating discriminal declarations
6981 Add_Discriminal_Declarations
(Declarations
(N
), Ttyp
, Name_uTask
, Loc
);
6983 -- Add a call to Abort_Undefer at the very beginning of the task
6984 -- body since this body is called with abort still deferred.
6986 if Abort_Allowed
then
6987 Call
:= Build_Runtime_Call
(Loc
, RE_Abort_Undefer
);
6989 (First
(Statements
(Handled_Statement_Sequence
(N
))), Call
);
6993 -- The statement part has already been protected with an at_end and
6994 -- cleanup actions. The call to Complete_Activation must be placed
6995 -- at the head of the sequence of statements of that block. The
6996 -- declarations have been merged in this sequence of statements but
6997 -- the first real statement is accessible from the First_Real_Statement
6998 -- field (which was set for exactly this purpose).
7000 if Restricted_Profile
then
7001 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Restricted_Activation
);
7003 Call
:= Build_Runtime_Call
(Loc
, RE_Complete_Activation
);
7007 (First_Real_Statement
(Handled_Statement_Sequence
(N
)), Call
);
7011 Make_Subprogram_Body
(Loc
,
7012 Specification
=> Build_Task_Proc_Specification
(Ttyp
),
7013 Declarations
=> Declarations
(N
),
7014 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(N
));
7016 -- If the task contains generic instantiations, cleanup actions
7017 -- are delayed until after instantiation. Transfer the activation
7018 -- chain to the subprogram, to insure that the activation call is
7019 -- properly generated. It the task body contains inner tasks, indicate
7020 -- that the subprogram is a task master.
7022 if Delay_Cleanups
(Ttyp
) then
7023 Set_Activation_Chain_Entity
(New_N
, Activation_Chain_Entity
(N
));
7024 Set_Is_Task_Master
(New_N
, Is_Task_Master
(N
));
7030 -- Set elaboration flag immediately after task body. If the body
7031 -- is a subunit, the flag is set in the declarative part that
7032 -- contains the stub.
7034 if Nkind
(Parent
(N
)) /= N_Subunit
then
7036 Make_Assignment_Statement
(Loc
,
7038 Make_Identifier
(Loc
, New_External_Name
(Chars
(Ttyp
), 'E')),
7039 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
7041 end Expand_N_Task_Body
;
7043 ------------------------------------
7044 -- Expand_N_Task_Type_Declaration --
7045 ------------------------------------
7047 -- We have several things to do. First we must create a Boolean flag used
7048 -- to mark if the body is elaborated yet. This variable gets set to True
7049 -- when the body of the task is elaborated (we can't rely on the normal
7050 -- ABE mechanism for the task body, since we need to pass an access to
7051 -- this elaboration boolean to the runtime routines).
7053 -- taskE : aliased Boolean := False;
7055 -- Next a variable is declared to hold the task stack size (either
7056 -- the default : Unspecified_Size, or a value that is set by a pragma
7057 -- Storage_Size). If the value of the pragma Storage_Size is static, then
7058 -- the variable is initialized with this value:
7060 -- taskZ : Size_Type := Unspecified_Size;
7062 -- taskZ : Size_Type := Size_Type (size_expression);
7064 -- Next we create a corresponding record type declaration used to represent
7065 -- values of this task. The general form of this type declaration is
7067 -- type taskV (discriminants) is record
7068 -- _Task_Id : Task_Id;
7069 -- entry_family : array (bounds) of Void;
7070 -- _Priority : Integer := priority_expression;
7071 -- _Size : Size_Type := Size_Type (size_expression);
7072 -- _Task_Info : Task_Info_Type := task_info_expression;
7075 -- The discriminants are present only if the corresponding task type has
7076 -- discriminants, and they exactly mirror the task type discriminants.
7078 -- The Id field is always present. It contains the Task_Id value, as
7079 -- set by the call to Create_Task. Note that although the task is
7080 -- limited, the task value record type is not limited, so there is no
7081 -- problem in passing this field as an out parameter to Create_Task.
7083 -- One entry_family component is present for each entry family in the
7084 -- task definition. The bounds correspond to the bounds of the entry
7085 -- family (which may depend on discriminants). The element type is
7086 -- void, since we only need the bounds information for determining
7087 -- the entry index. Note that the use of an anonymous array would
7088 -- normally be illegal in this context, but this is a parser check,
7089 -- and the semantics is quite prepared to handle such a case.
7091 -- The _Size field is present only if a Storage_Size pragma appears in
7092 -- the task definition. The expression captures the argument that was
7093 -- present in the pragma, and is used to override the task stack size
7094 -- otherwise associated with the task type.
7096 -- The _Priority field is present only if a Priority or Interrupt_Priority
7097 -- pragma appears in the task definition. The expression captures the
7098 -- argument that was present in the pragma, and is used to provide
7099 -- the Size parameter to the call to Create_Task.
7101 -- The _Task_Info field is present only if a Task_Info pragma appears in
7102 -- the task definition. The expression captures the argument that was
7103 -- present in the pragma, and is used to provide the Task_Image parameter
7104 -- to the call to Create_Task.
7106 -- When a task is declared, an instance of the task value record is
7107 -- created. The elaboration of this declaration creates the correct
7108 -- bounds for the entry families, and also evaluates the size, priority,
7109 -- and task_Info expressions if needed. The initialization routine for
7110 -- the task type itself then calls Create_Task with appropriate
7111 -- parameters to initialize the value of the Task_Id field.
7113 -- Note: the address of this record is passed as the "Discriminants"
7114 -- parameter for Create_Task. Since Create_Task merely passes this onto
7115 -- the body procedure, it does not matter that it does not quite match
7116 -- the GNARLI model of what is being passed (the record contains more
7117 -- than just the discriminants, but the discriminants can be found from
7118 -- the record value).
7120 -- The Entity_Id for this created record type is placed in the
7121 -- Corresponding_Record_Type field of the associated task type entity.
7123 -- Next we create a procedure specification for the task body procedure:
7125 -- procedure taskB (_Task : access taskV);
7127 -- Note that this must come after the record type declaration, since
7128 -- the spec refers to this type. It turns out that the initialization
7129 -- procedure for the value type references the task body spec, but that's
7130 -- fine, since it won't be generated till the freeze point for the type,
7131 -- which is certainly after the task body spec declaration.
7133 -- Finally, we set the task index value field of the entry attribute in
7134 -- the case of a simple entry.
7136 procedure Expand_N_Task_Type_Declaration
(N
: Node_Id
) is
7137 Loc
: constant Source_Ptr
:= Sloc
(N
);
7138 Tasktyp
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
7139 Tasknm
: constant Name_Id
:= Chars
(Tasktyp
);
7140 Taskdef
: constant Node_Id
:= Task_Definition
(N
);
7142 Proc_Spec
: Node_Id
;
7144 Rec_Ent
: Entity_Id
;
7146 Elab_Decl
: Node_Id
;
7147 Size_Decl
: Node_Id
;
7148 Body_Decl
: Node_Id
;
7149 Task_Size
: Node_Id
;
7150 Ent_Stack
: Entity_Id
;
7151 Decl_Stack
: Node_Id
;
7154 -- If already expanded, nothing to do
7156 if Present
(Corresponding_Record_Type
(Tasktyp
)) then
7160 -- Here we will do the expansion
7162 Rec_Decl
:= Build_Corresponding_Record
(N
, Tasktyp
, Loc
);
7163 Rec_Ent
:= Defining_Identifier
(Rec_Decl
);
7164 Cdecls
:= Component_Items
(Component_List
7165 (Type_Definition
(Rec_Decl
)));
7167 Qualify_Entity_Names
(N
);
7169 -- First create the elaboration variable
7172 Make_Object_Declaration
(Loc
,
7173 Defining_Identifier
=>
7174 Make_Defining_Identifier
(Sloc
(Tasktyp
),
7175 Chars
=> New_External_Name
(Tasknm
, 'E')),
7176 Aliased_Present
=> True,
7177 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
7178 Expression
=> New_Reference_To
(Standard_False
, Loc
));
7179 Insert_After
(N
, Elab_Decl
);
7181 -- Next create the declaration of the size variable (tasknmZ)
7183 Set_Storage_Size_Variable
(Tasktyp
,
7184 Make_Defining_Identifier
(Sloc
(Tasktyp
),
7185 Chars
=> New_External_Name
(Tasknm
, 'Z')));
7187 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) and then
7188 Is_Static_Expression
(Expression
(First
(
7189 Pragma_Argument_Associations
(Find_Task_Or_Protected_Pragma
(
7190 Taskdef
, Name_Storage_Size
)))))
7193 Make_Object_Declaration
(Loc
,
7194 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
7195 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
7197 Convert_To
(RTE
(RE_Size_Type
),
7200 Pragma_Argument_Associations
(
7201 Find_Task_Or_Protected_Pragma
7202 (Taskdef
, Name_Storage_Size
)))))));
7206 Make_Object_Declaration
(Loc
,
7207 Defining_Identifier
=> Storage_Size_Variable
(Tasktyp
),
7208 Object_Definition
=> New_Reference_To
(RTE
(RE_Size_Type
), Loc
),
7209 Expression
=> New_Reference_To
(RTE
(RE_Unspecified_Size
), Loc
));
7212 Insert_After
(Elab_Decl
, Size_Decl
);
7214 -- Next build the rest of the corresponding record declaration.
7215 -- This is done last, since the corresponding record initialization
7216 -- procedure will reference the previously created entities.
7218 -- Fill in the component declarations -- first the _Task_Id field
7221 Make_Component_Declaration
(Loc
,
7222 Defining_Identifier
=>
7223 Make_Defining_Identifier
(Loc
, Name_uTask_Id
),
7224 Component_Definition
=>
7225 Make_Component_Definition
(Loc
,
7226 Aliased_Present
=> False,
7227 Subtype_Indication
=> New_Reference_To
(RTE
(RO_ST_Task_Id
),
7230 -- Declare static ATCB (that is, created by the expander) if we
7231 -- are using the Restricted run time.
7233 if Restricted_Profile
then
7235 Make_Component_Declaration
(Loc
,
7236 Defining_Identifier
=>
7237 Make_Defining_Identifier
(Loc
, Name_uATCB
),
7239 Component_Definition
=>
7240 Make_Component_Definition
(Loc
,
7241 Aliased_Present
=> True,
7242 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
7243 Subtype_Mark
=> New_Occurrence_Of
7244 (RTE
(RE_Ada_Task_Control_Block
), Loc
),
7247 Make_Index_Or_Discriminant_Constraint
(Loc
,
7249 New_List
(Make_Integer_Literal
(Loc
, 0)))))));
7253 -- Declare static stack (that is, created by the expander) if we
7254 -- are using the Restricted run time on a bare board configuration.
7256 if Restricted_Profile
7257 and then Preallocated_Stacks_On_Target
7259 -- First we need to extract the appropriate stack size
7261 Ent_Stack
:= Make_Defining_Identifier
(Loc
, Name_uStack
);
7263 if Present
(Taskdef
) and then Has_Storage_Size_Pragma
(Taskdef
) then
7264 Task_Size
:= Relocate_Node
(
7266 Pragma_Argument_Associations
(
7267 Find_Task_Or_Protected_Pragma
7268 (Taskdef
, Name_Storage_Size
)))));
7271 New_Reference_To
(RTE
(RE_Default_Stack_Size
), Loc
);
7274 Decl_Stack
:= Make_Component_Declaration
(Loc
,
7275 Defining_Identifier
=> Ent_Stack
,
7277 Component_Definition
=>
7278 Make_Component_Definition
(Loc
,
7279 Aliased_Present
=> True,
7280 Subtype_Indication
=> Make_Subtype_Indication
(Loc
,
7282 New_Occurrence_Of
(RTE
(RE_Storage_Array
), Loc
),
7285 Make_Index_Or_Discriminant_Constraint
(Loc
,
7286 Constraints
=> New_List
(Make_Range
(Loc
,
7287 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7288 High_Bound
=> Convert_To
(RTE
(RE_Storage_Offset
),
7291 Append_To
(Cdecls
, Decl_Stack
);
7293 -- The appropriate alignment for the stack is ensured by the
7294 -- run-time code in charge of task creation.
7298 -- Add components for entry families
7300 Collect_Entry_Families
(Loc
, Cdecls
, Size_Decl
, Tasktyp
);
7302 -- Add the _Priority component if a Priority pragma is present
7304 if Present
(Taskdef
) and then Has_Priority_Pragma
(Taskdef
) then
7306 Prag
: constant Node_Id
:=
7307 Find_Task_Or_Protected_Pragma
(Taskdef
, Name_Priority
);
7311 Expr
:= First
(Pragma_Argument_Associations
(Prag
));
7313 if Nkind
(Expr
) = N_Pragma_Argument_Association
then
7314 Expr
:= Expression
(Expr
);
7317 Expr
:= New_Copy_Tree
(Expr
);
7319 -- Add conversion to proper type to do range check if required
7320 -- Note that for runtime units, we allow out of range interrupt
7321 -- priority values to be used in a priority pragma. This is for
7322 -- the benefit of some versions of System.Interrupts which use
7323 -- a special server task with maximum interrupt priority.
7325 if Chars
(Prag
) = Name_Priority
7326 and then not GNAT_Mode
7328 Rewrite
(Expr
, Convert_To
(RTE
(RE_Priority
), Expr
));
7330 Rewrite
(Expr
, Convert_To
(RTE
(RE_Any_Priority
), Expr
));
7334 Make_Component_Declaration
(Loc
,
7335 Defining_Identifier
=>
7336 Make_Defining_Identifier
(Loc
, Name_uPriority
),
7337 Component_Definition
=>
7338 Make_Component_Definition
(Loc
,
7339 Aliased_Present
=> False,
7340 Subtype_Indication
=> New_Reference_To
(Standard_Integer
,
7342 Expression
=> Expr
));
7346 -- Add the _Task_Size component if a Storage_Size pragma is present
7348 if Present
(Taskdef
)
7349 and then Has_Storage_Size_Pragma
(Taskdef
)
7352 Make_Component_Declaration
(Loc
,
7353 Defining_Identifier
=>
7354 Make_Defining_Identifier
(Loc
, Name_uSize
),
7356 Component_Definition
=>
7357 Make_Component_Definition
(Loc
,
7358 Aliased_Present
=> False,
7359 Subtype_Indication
=> New_Reference_To
(RTE
(RE_Size_Type
),
7363 Convert_To
(RTE
(RE_Size_Type
),
7366 Pragma_Argument_Associations
(
7367 Find_Task_Or_Protected_Pragma
7368 (Taskdef
, Name_Storage_Size
))))))));
7371 -- Add the _Task_Info component if a Task_Info pragma is present
7373 if Present
(Taskdef
) and then Has_Task_Info_Pragma
(Taskdef
) then
7375 Make_Component_Declaration
(Loc
,
7376 Defining_Identifier
=>
7377 Make_Defining_Identifier
(Loc
, Name_uTask_Info
),
7379 Component_Definition
=>
7380 Make_Component_Definition
(Loc
,
7381 Aliased_Present
=> False,
7382 Subtype_Indication
=>
7383 New_Reference_To
(RTE
(RE_Task_Info_Type
), Loc
)),
7385 Expression
=> New_Copy
(
7387 Pragma_Argument_Associations
(
7388 Find_Task_Or_Protected_Pragma
7389 (Taskdef
, Name_Task_Info
)))))));
7392 Insert_After
(Size_Decl
, Rec_Decl
);
7394 -- Analyze the record declaration immediately after construction,
7395 -- because the initialization procedure is needed for single task
7396 -- declarations before the next entity is analyzed.
7400 -- Create the declaration of the task body procedure
7402 Proc_Spec
:= Build_Task_Proc_Specification
(Tasktyp
);
7404 Make_Subprogram_Declaration
(Loc
,
7405 Specification
=> Proc_Spec
);
7407 Insert_After
(Rec_Decl
, Body_Decl
);
7409 -- The subprogram does not comes from source, so we have to indicate
7410 -- the need for debugging information explicitly.
7412 Set_Needs_Debug_Info
7413 (Defining_Entity
(Proc_Spec
), Comes_From_Source
(Original_Node
(N
)));
7415 -- Now we can freeze the corresponding record. This needs manually
7416 -- freezing, since it is really part of the task type, and the task
7417 -- type is frozen at this stage. We of course need the initialization
7418 -- procedure for this corresponding record type and we won't get it
7419 -- in time if we don't freeze now.
7422 L
: constant List_Id
:= Freeze_Entity
(Rec_Ent
, Loc
);
7425 if Is_Non_Empty_List
(L
) then
7426 Insert_List_After
(Body_Decl
, L
);
7430 -- Complete the expansion of access types to the current task
7431 -- type, if any were declared.
7433 Expand_Previous_Access_Type
(Tasktyp
);
7434 end Expand_N_Task_Type_Declaration
;
7436 -------------------------------
7437 -- Expand_N_Timed_Entry_Call --
7438 -------------------------------
7440 -- A timed entry call in normal case is not implemented using ATC
7441 -- mechanism anymore for efficiency reason.
7451 -- is expanded as follow:
7453 -- 1) When T.E is a task entry_call;
7457 -- X : Task_Entry_Index := <entry index>;
7458 -- DX : Duration := To_Duration (D);
7459 -- M : Delay_Mode := <discriminant>;
7460 -- P : parms := (parm, parm, parm);
7463 -- Timed_Protected_Entry_Call (<acceptor-task>, X, P'Address,
7472 -- 2) When T.E is a protected entry_call;
7476 -- X : Protected_Entry_Index := <entry index>;
7477 -- DX : Duration := To_Duration (D);
7478 -- M : Delay_Mode := <discriminant>;
7479 -- P : parms := (parm, parm, parm);
7482 -- Timed_Protected_Entry_Call (<object>'unchecked_access, X,
7483 -- P'Address, DX, M, B);
7491 procedure Expand_N_Timed_Entry_Call
(N
: Node_Id
) is
7492 Loc
: constant Source_Ptr
:= Sloc
(N
);
7495 Entry_Call_Statement
(Entry_Call_Alternative
(N
));
7496 E_Stats
: constant List_Id
:=
7497 Statements
(Entry_Call_Alternative
(N
));
7498 D_Stat
: constant Node_Id
:=
7499 Delay_Statement
(Delay_Alternative
(N
));
7500 D_Stats
: constant List_Id
:=
7501 Statements
(Delay_Alternative
(N
));
7524 -- The arguments in the call may require dynamic allocation, and the
7525 -- call statement may have been transformed into a block. The block
7526 -- may contain additional declarations for internal entities, and the
7527 -- original call is found by sequential search.
7529 if Nkind
(E_Call
) = N_Block_Statement
then
7530 E_Call
:= First
(Statements
(Handled_Statement_Sequence
(E_Call
)));
7532 while Nkind
(E_Call
) /= N_Procedure_Call_Statement
7533 and then Nkind
(E_Call
) /= N_Entry_Call_Statement
7539 -- Build an entry call using Simple_Entry_Call. We will use this as the
7540 -- base for creating appropriate calls.
7542 Extract_Entry
(E_Call
, Concval
, Ename
, Index
);
7543 Build_Simple_Entry_Call
(E_Call
, Concval
, Ename
, Index
);
7545 Stmts
:= Statements
(Handled_Statement_Sequence
(E_Call
));
7546 Decls
:= Declarations
(E_Call
);
7552 Dtyp
:= Base_Type
(Etype
(Expression
(D_Stat
)));
7554 -- Use the type of the delay expression (Calendar or Real_Time)
7555 -- to generate the appropriate conversion.
7557 if Nkind
(D_Stat
) = N_Delay_Relative_Statement
then
7558 Disc
:= Make_Integer_Literal
(Loc
, 0);
7559 Conv
:= Relocate_Node
(Expression
(D_Stat
));
7561 elsif Is_RTE
(Dtyp
, RO_CA_Time
) then
7562 Disc
:= Make_Integer_Literal
(Loc
, 1);
7563 Conv
:= Make_Function_Call
(Loc
,
7564 New_Reference_To
(RTE
(RO_CA_To_Duration
), Loc
),
7565 New_List
(New_Copy
(Expression
(D_Stat
))));
7567 else pragma Assert
(Is_RTE
(Dtyp
, RO_RT_Time
));
7568 Disc
:= Make_Integer_Literal
(Loc
, 2);
7569 Conv
:= Make_Function_Call
(Loc
,
7570 New_Reference_To
(RTE
(RO_RT_To_Duration
), Loc
),
7571 New_List
(New_Copy
(Expression
(D_Stat
))));
7574 -- Create Duration and Delay_Mode objects for passing a delay value
7576 D
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
7577 M
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('M'));
7580 Make_Object_Declaration
(Loc
,
7581 Defining_Identifier
=> D
,
7582 Object_Definition
=> New_Reference_To
(Standard_Duration
, Loc
)));
7585 Make_Object_Declaration
(Loc
,
7586 Defining_Identifier
=> M
,
7587 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
),
7588 Expression
=> Disc
));
7590 B
:= Make_Defining_Identifier
(Loc
, Name_uB
);
7592 -- Create a boolean object used for a return parameter
7595 Make_Object_Declaration
(Loc
,
7596 Defining_Identifier
=> B
,
7597 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
7599 Stmt
:= First
(Stmts
);
7601 -- Skip assignments to temporaries created for in-out parameters.
7602 -- This makes unwarranted assumptions about the shape of the expanded
7603 -- tree for the call, and should be cleaned up ???
7605 while Nkind
(Stmt
) /= N_Procedure_Call_Statement
loop
7609 -- Do the assignement at this stage only because the evaluation of the
7610 -- expression must not occur before (see ACVC C97302A).
7612 Insert_Before
(Stmt
,
7613 Make_Assignment_Statement
(Loc
,
7614 Name
=> New_Reference_To
(D
, Loc
),
7615 Expression
=> Conv
));
7619 Parms
:= Parameter_Associations
(Call
);
7621 -- For a protected type, we build a Timed_Protected_Entry_Call
7623 if Is_Protected_Type
(Etype
(Concval
)) then
7625 -- Create a new call statement
7627 Parm
:= First
(Parms
);
7629 while Present
(Parm
)
7630 and then not Is_RTE
(Etype
(Parm
), RE_Call_Modes
)
7635 Dummy
:= Remove_Next
(Next
(Parm
));
7637 -- Remove garbage is following the Cancel_Param if present
7639 Dummy
:= Next
(Parm
);
7641 -- Remove the mode of the Protected_Entry_Call call, then remove the
7642 -- Communication_Block of the Protected_Entry_Call call, and finally
7643 -- add Duration and a Delay_Mode parameter
7645 pragma Assert
(Present
(Parm
));
7646 Rewrite
(Parm
, New_Reference_To
(D
, Loc
));
7648 Rewrite
(Dummy
, New_Reference_To
(M
, Loc
));
7650 -- Add a Boolean flag for successful entry call
7652 Append_To
(Parms
, New_Reference_To
(B
, Loc
));
7655 or else Restriction_Active
(No_Entry_Queue
) = False
7656 or else Number_Entries
(Etype
(Concval
)) > 1
7659 Make_Procedure_Call_Statement
(Loc
,
7661 New_Reference_To
(RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
7662 Parameter_Associations
=> Parms
));
7665 Parm
:= First
(Parms
);
7667 while Present
(Parm
)
7668 and then not Is_RTE
(Etype
(Parm
), RE_Protected_Entry_Index
)
7676 Make_Procedure_Call_Statement
(Loc
,
7677 Name
=> New_Reference_To
(
7678 RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
7679 Parameter_Associations
=> Parms
));
7682 -- For the task case, build a Timed_Task_Entry_Call
7685 -- Create a new call statement
7687 Append_To
(Parms
, New_Reference_To
(D
, Loc
));
7688 Append_To
(Parms
, New_Reference_To
(M
, Loc
));
7689 Append_To
(Parms
, New_Reference_To
(B
, Loc
));
7692 Make_Procedure_Call_Statement
(Loc
,
7693 Name
=> New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
7694 Parameter_Associations
=> Parms
));
7699 Make_Implicit_If_Statement
(N
,
7700 Condition
=> New_Reference_To
(B
, Loc
),
7701 Then_Statements
=> E_Stats
,
7702 Else_Statements
=> D_Stats
));
7705 Make_Block_Statement
(Loc
,
7706 Declarations
=> Decls
,
7707 Handled_Statement_Sequence
=>
7708 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
)));
7711 end Expand_N_Timed_Entry_Call
;
7713 ----------------------------------------
7714 -- Expand_Protected_Body_Declarations --
7715 ----------------------------------------
7717 -- Part of the expansion of a protected body involves the creation of
7718 -- a declaration that can be referenced from the statement sequences of
7719 -- the entry bodies:
7723 -- This declaration is inserted in the declarations of the service
7724 -- entries procedure for the protected body, and it is important that
7725 -- it be inserted before the statements of the entry body statement
7726 -- sequences are analyzed. Thus it would be too late to create this
7727 -- declaration in the Expand_N_Protected_Body routine, which is why
7728 -- there is a separate procedure to be called directly from Sem_Ch9.
7730 -- Ann is used to hold the address of the record containing the parameters
7731 -- (see Expand_N_Entry_Call for more details on how this record is built).
7732 -- References to the parameters do an unchecked conversion of this address
7733 -- to a pointer to the required record type, and then access the field that
7734 -- holds the value of the required parameter. The entity for the address
7735 -- variable is held as the top stack element (i.e. the last element) of the
7736 -- Accept_Address stack in the corresponding entry entity, and this element
7737 -- must be set in place before the statements are processed.
7739 -- No stack is needed for entry bodies, since they cannot be nested, but
7740 -- it is kept for consistency between protected and task entries. The
7741 -- stack will never contain more than one element. There is also only one
7742 -- such variable for a given protected body, but this is placed on the
7743 -- Accept_Address stack of all of the entries, again for consistency.
7745 -- To expand the requeue statement, a label is provided at the end of
7746 -- the loop in the entry service routine created by the expander (see
7747 -- Expand_N_Protected_Body for details), so that the statement can be
7748 -- skipped after the requeue is complete. This label is created during the
7749 -- expansion of the entry body, which will take place after the expansion
7750 -- of the requeue statements that it contains, so a placeholder defining
7751 -- identifier is associated with the task type here.
7753 -- Another label is provided following case statement created by the
7754 -- expander. This label is need for implementing return statement from
7755 -- entry body so that a return can be expanded as a goto to this label.
7756 -- This label is created during the expansion of the entry body, which
7757 -- will take place after the expansion of the return statements that it
7758 -- contains. Therefore, just like the label for expanding requeues, we
7759 -- need another placeholder for the label.
7761 procedure Expand_Protected_Body_Declarations
7763 Spec_Id
: Entity_Id
)
7768 if No_Run_Time_Mode
then
7769 Error_Msg_CRT
("protected body", N
);
7772 elsif Expander_Active
then
7774 -- Associate privals with the first subprogram or entry
7775 -- body to be expanded. These are used to expand references
7776 -- to private data objects.
7778 Op
:= First_Protected_Operation
(Declarations
(N
));
7780 if Present
(Op
) then
7781 Set_Discriminals
(Parent
(Spec_Id
));
7782 Set_Privals
(Parent
(Spec_Id
), Op
, Sloc
(N
));
7785 end Expand_Protected_Body_Declarations
;
7787 -------------------------
7788 -- External_Subprogram --
7789 -------------------------
7791 function External_Subprogram
(E
: Entity_Id
) return Entity_Id
is
7792 Subp
: constant Entity_Id
:= Protected_Body_Subprogram
(E
);
7793 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
7796 -- If the protected operation is defined in the visible part of the
7797 -- protected type, or if it is an interrupt handler, the internal and
7798 -- external subprograms follow each other on the entity chain. If the
7799 -- operation is defined in the private part of the type, there is no
7800 -- need for a separate locking version of the operation, and internal
7801 -- calls use the protected_body_subprogram directly.
7803 if List_Containing
(Decl
) = Visible_Declarations
(Parent
(Decl
))
7804 or else Is_Interrupt_Handler
(E
)
7806 return Next_Entity
(Subp
);
7810 end External_Subprogram
;
7816 procedure Extract_Entry
7818 Concval
: out Node_Id
;
7819 Ename
: out Node_Id
;
7820 Index
: out Node_Id
)
7822 Nam
: constant Node_Id
:= Name
(N
);
7825 -- For a simple entry, the name is a selected component, with the
7826 -- prefix being the task value, and the selector being the entry.
7828 if Nkind
(Nam
) = N_Selected_Component
then
7829 Concval
:= Prefix
(Nam
);
7830 Ename
:= Selector_Name
(Nam
);
7833 -- For a member of an entry family, the name is an indexed
7834 -- component where the prefix is a selected component,
7835 -- whose prefix in turn is the task value, and whose
7836 -- selector is the entry family. The single expression in
7837 -- the expressions list of the indexed component is the
7838 -- subscript for the family.
7841 pragma Assert
(Nkind
(Nam
) = N_Indexed_Component
);
7842 Concval
:= Prefix
(Prefix
(Nam
));
7843 Ename
:= Selector_Name
(Prefix
(Nam
));
7844 Index
:= First
(Expressions
(Nam
));
7852 function Family_Offset
7856 Ttyp
: Entity_Id
) return Node_Id
7858 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
7859 -- If one of the bounds is a reference to a discriminant, replace
7860 -- with corresponding discriminal of type. Within the body of a task
7861 -- retrieve the renamed discriminant by simple visibility, using its
7862 -- generated name. Within a protected object, find the original dis-
7863 -- criminant and replace it with the discriminal of the current prot-
7866 ------------------------------
7867 -- Convert_Discriminant_Ref --
7868 ------------------------------
7870 function Convert_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
7871 Loc
: constant Source_Ptr
:= Sloc
(Bound
);
7876 if Is_Entity_Name
(Bound
)
7877 and then Ekind
(Entity
(Bound
)) = E_Discriminant
7879 if Is_Task_Type
(Ttyp
)
7880 and then Has_Completion
(Ttyp
)
7882 B
:= Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
7883 Find_Direct_Name
(B
);
7885 elsif Is_Protected_Type
(Ttyp
) then
7886 D
:= First_Discriminant
(Ttyp
);
7888 while Chars
(D
) /= Chars
(Entity
(Bound
)) loop
7889 Next_Discriminant
(D
);
7892 B
:= New_Reference_To
(Discriminal
(D
), Loc
);
7895 B
:= New_Reference_To
(Discriminal
(Entity
(Bound
)), Loc
);
7898 elsif Nkind
(Bound
) = N_Attribute_Reference
then
7902 B
:= New_Copy_Tree
(Bound
);
7906 Make_Attribute_Reference
(Loc
,
7907 Attribute_Name
=> Name_Pos
,
7908 Prefix
=> New_Occurrence_Of
(Etype
(Bound
), Loc
),
7909 Expressions
=> New_List
(B
));
7910 end Convert_Discriminant_Ref
;
7912 -- Start of processing for Family_Offset
7916 Make_Op_Subtract
(Loc
,
7917 Left_Opnd
=> Convert_Discriminant_Ref
(Hi
),
7918 Right_Opnd
=> Convert_Discriminant_Ref
(Lo
));
7925 function Family_Size
7929 Ttyp
: Entity_Id
) return Node_Id
7934 if Is_Task_Type
(Ttyp
) then
7935 Ityp
:= RTE
(RE_Task_Entry_Index
);
7937 Ityp
:= RTE
(RE_Protected_Entry_Index
);
7941 Make_Attribute_Reference
(Loc
,
7942 Prefix
=> New_Reference_To
(Ityp
, Loc
),
7943 Attribute_Name
=> Name_Max
,
7944 Expressions
=> New_List
(
7947 Family_Offset
(Loc
, Hi
, Lo
, Ttyp
),
7949 Make_Integer_Literal
(Loc
, 1)),
7950 Make_Integer_Literal
(Loc
, 0)));
7953 -----------------------------------
7954 -- Find_Task_Or_Protected_Pragma --
7955 -----------------------------------
7957 function Find_Task_Or_Protected_Pragma
7959 P
: Name_Id
) return Node_Id
7964 N
:= First
(Visible_Declarations
(T
));
7966 while Present
(N
) loop
7967 if Nkind
(N
) = N_Pragma
then
7968 if Chars
(N
) = P
then
7971 elsif P
= Name_Priority
7972 and then Chars
(N
) = Name_Interrupt_Priority
7985 N
:= First
(Private_Declarations
(T
));
7987 while Present
(N
) loop
7988 if Nkind
(N
) = N_Pragma
then
7989 if Chars
(N
) = P
then
7992 elsif P
= Name_Priority
7993 and then Chars
(N
) = Name_Interrupt_Priority
8006 raise Program_Error
;
8007 end Find_Task_Or_Protected_Pragma
;
8009 -------------------------------
8010 -- First_Protected_Operation --
8011 -------------------------------
8013 function First_Protected_Operation
(D
: List_Id
) return Node_Id
is
8017 First_Op
:= First
(D
);
8018 while Present
(First_Op
)
8019 and then Nkind
(First_Op
) /= N_Subprogram_Body
8020 and then Nkind
(First_Op
) /= N_Entry_Body
8026 end First_Protected_Operation
;
8028 --------------------------------
8029 -- Index_Constant_Declaration --
8030 --------------------------------
8032 function Index_Constant_Declaration
8034 Index_Id
: Entity_Id
;
8035 Prot
: Entity_Id
) return List_Id
8037 Loc
: constant Source_Ptr
:= Sloc
(N
);
8038 Decls
: constant List_Id
:= New_List
;
8039 Index_Con
: constant Entity_Id
:= Entry_Index_Constant
(Index_Id
);
8040 Index_Typ
: Entity_Id
;
8042 Hi
: Node_Id
:= Type_High_Bound
(Etype
(Index_Id
));
8043 Lo
: Node_Id
:= Type_Low_Bound
(Etype
(Index_Id
));
8045 function Replace_Discriminant
(Bound
: Node_Id
) return Node_Id
;
8046 -- The bounds of the entry index may depend on discriminants, so
8047 -- each declaration of an entry_index_constant must have its own
8048 -- subtype declaration, using the local renaming of the object discri-
8051 --------------------------
8052 -- Replace_Discriminant --
8053 --------------------------
8055 function Replace_Discriminant
(Bound
: Node_Id
) return Node_Id
is
8057 if Nkind
(Bound
) = N_Identifier
8058 and then Ekind
(Entity
(Bound
)) = E_Constant
8059 and then Present
(Discriminal_Link
(Entity
(Bound
)))
8061 return Make_Identifier
(Loc
, Chars
(Entity
(Bound
)));
8063 return Duplicate_Subexpr
(Bound
);
8065 end Replace_Discriminant
;
8067 -- Start of processing for Index_Constant_Declaration
8070 Set_Discriminal_Link
(Index_Con
, Index_Id
);
8073 Original_Node
(Discrete_Subtype_Definition
(Parent
(Index_Id
))))
8075 -- Simple case: entry family is given by a subtype mark, and index
8076 -- constant has the same type, no replacement needed.
8078 Index_Typ
:= Etype
(Index_Id
);
8081 Hi
:= Replace_Discriminant
(Hi
);
8082 Lo
:= Replace_Discriminant
(Lo
);
8084 Index_Typ
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('J'));
8087 Make_Subtype_Declaration
(Loc
,
8088 Defining_Identifier
=> Index_Typ
,
8089 Subtype_Indication
=>
8090 Make_Subtype_Indication
(Loc
,
8092 New_Occurrence_Of
(Base_Type
(Etype
(Index_Id
)), Loc
),
8094 Make_Range_Constraint
(Loc
,
8095 Range_Expression
=> Make_Range
(Loc
, Lo
, Hi
)))),
8101 Make_Object_Declaration
(Loc
,
8102 Defining_Identifier
=> Index_Con
,
8103 Constant_Present
=> True,
8104 Object_Definition
=> New_Occurrence_Of
(Index_Typ
, Loc
),
8107 Make_Attribute_Reference
(Loc
,
8108 Prefix
=> New_Reference_To
(Index_Typ
, Loc
),
8109 Attribute_Name
=> Name_Val
,
8111 Expressions
=> New_List
(
8115 Make_Op_Subtract
(Loc
,
8116 Left_Opnd
=> Make_Identifier
(Loc
, Name_uE
),
8118 Entry_Index_Expression
(Loc
,
8119 Defining_Identifier
(N
), Empty
, Prot
)),
8122 Make_Attribute_Reference
(Loc
,
8123 Prefix
=> New_Reference_To
(Index_Typ
, Loc
),
8124 Attribute_Name
=> Name_Pos
,
8125 Expressions
=> New_List
(
8126 Make_Attribute_Reference
(Loc
,
8127 Prefix
=> New_Reference_To
(Index_Typ
, Loc
),
8128 Attribute_Name
=> Name_First
))))))),
8132 end Index_Constant_Declaration
;
8134 --------------------------------
8135 -- Make_Initialize_Protection --
8136 --------------------------------
8138 function Make_Initialize_Protection
8139 (Protect_Rec
: Entity_Id
) return List_Id
8141 Loc
: constant Source_Ptr
:= Sloc
(Protect_Rec
);
8145 Ptyp
: constant Node_Id
:=
8146 Corresponding_Concurrent_Type
(Protect_Rec
);
8148 L
: constant List_Id
:= New_List
;
8149 Has_Entry
: constant Boolean := Has_Entries
(Ptyp
);
8150 Restricted
: constant Boolean := Restricted_Profile
;
8153 -- We may need two calls to properly initialize the object, one
8154 -- to Initialize_Protection, and possibly one to Install_Handlers
8155 -- if we have a pragma Attach_Handler.
8157 -- Get protected declaration. In the case of a task type declaration,
8158 -- this is simply the parent of the protected type entity.
8159 -- In the single protected object
8160 -- declaration, this parent will be the implicit type, and we can find
8161 -- the corresponding single protected object declaration by
8162 -- searching forward in the declaration list in the tree.
8163 -- ??? I am not sure that the test for N_Single_Protected_Declaration
8164 -- is needed here. Nodes of this type should have been removed
8165 -- during semantic analysis.
8167 Pdec
:= Parent
(Ptyp
);
8169 while Nkind
(Pdec
) /= N_Protected_Type_Declaration
8170 and then Nkind
(Pdec
) /= N_Single_Protected_Declaration
8175 -- Now we can find the object definition from this declaration
8177 Pdef
:= Protected_Definition
(Pdec
);
8179 -- Build the parameter list for the call. Note that _Init is the name
8180 -- of the formal for the object to be initialized, which is the task
8181 -- value record itself.
8185 -- Object parameter. This is a pointer to the object of type
8186 -- Protection used by the GNARL to control the protected object.
8189 Make_Attribute_Reference
(Loc
,
8191 Make_Selected_Component
(Loc
,
8192 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8193 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
8194 Attribute_Name
=> Name_Unchecked_Access
));
8196 -- Priority parameter. Set to Unspecified_Priority unless there is a
8197 -- priority pragma, in which case we take the value from the pragma,
8198 -- or there is an interrupt pragma and no priority pragma, and we
8199 -- set the ceiling to Interrupt_Priority'Last, an implementation-
8200 -- defined value, see D.3(10).
8203 and then Has_Priority_Pragma
(Pdef
)
8206 Duplicate_Subexpr_No_Checks
8209 (Pragma_Argument_Associations
8210 (Find_Task_Or_Protected_Pragma
(Pdef
, Name_Priority
))))));
8212 elsif Has_Interrupt_Handler
(Ptyp
)
8213 or else Has_Attach_Handler
(Ptyp
)
8215 -- When no priority is specified but an xx_Handler pragma is,
8216 -- we default to System.Interrupts.Default_Interrupt_Priority,
8220 New_Reference_To
(RTE
(RE_Default_Interrupt_Priority
), Loc
));
8224 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
8228 or else Has_Interrupt_Handler
(Ptyp
)
8229 or else Has_Attach_Handler
(Ptyp
)
8231 -- Compiler_Info parameter. This parameter allows entry body
8232 -- procedures and barrier functions to be called from the runtime.
8233 -- It is a pointer to the record generated by the compiler to
8234 -- represent the protected object.
8236 if Has_Entry
or else not Restricted
then
8238 Make_Attribute_Reference
(Loc
,
8239 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8240 Attribute_Name
=> Name_Address
));
8244 -- Entry_Bodies parameter. This is a pointer to an array of
8245 -- pointers to the entry body procedures and barrier functions
8246 -- of the object. If the protected type has no entries this
8247 -- object will not exist; in this case, pass a null.
8249 P_Arr
:= Entry_Bodies_Array
(Ptyp
);
8252 Make_Attribute_Reference
(Loc
,
8253 Prefix
=> New_Reference_To
(P_Arr
, Loc
),
8254 Attribute_Name
=> Name_Unrestricted_Access
));
8257 or else Restriction_Active
(No_Entry_Queue
) = False
8258 or else Number_Entries
(Ptyp
) > 1
8260 -- Find index mapping function (clumsy but ok for now)
8262 while Ekind
(P_Arr
) /= E_Function
loop
8263 Next_Entity
(P_Arr
);
8267 Make_Attribute_Reference
(Loc
,
8269 New_Reference_To
(P_Arr
, Loc
),
8270 Attribute_Name
=> Name_Unrestricted_Access
));
8273 elsif not Restricted
then
8274 Append_To
(Args
, Make_Null
(Loc
));
8275 Append_To
(Args
, Make_Null
(Loc
));
8279 or else Restriction_Active
(No_Entry_Queue
) = False
8280 or else Number_Entries
(Ptyp
) > 1
8283 Make_Procedure_Call_Statement
(Loc
,
8284 Name
=> New_Reference_To
(
8285 RTE
(RE_Initialize_Protection_Entries
), Loc
),
8286 Parameter_Associations
=> Args
));
8288 elsif not Has_Entry
and then Restricted
then
8290 Make_Procedure_Call_Statement
(Loc
,
8291 Name
=> New_Reference_To
(
8292 RTE
(RE_Initialize_Protection
), Loc
),
8293 Parameter_Associations
=> Args
));
8297 Make_Procedure_Call_Statement
(Loc
,
8298 Name
=> New_Reference_To
(
8299 RTE
(RE_Initialize_Protection_Entry
), Loc
),
8300 Parameter_Associations
=> Args
));
8305 Make_Procedure_Call_Statement
(Loc
,
8306 Name
=> New_Reference_To
(RTE
(RE_Initialize_Protection
), Loc
),
8307 Parameter_Associations
=> Args
));
8310 if Has_Attach_Handler
(Ptyp
) then
8312 -- We have a list of N Attach_Handler (ProcI, ExprI),
8313 -- and we have to make the following call:
8314 -- Install_Handlers (_object,
8315 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
8316 -- or, in the case of Ravenscar:
8318 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
8321 Args
: constant List_Id
:= New_List
;
8322 Table
: constant List_Id
:= New_List
;
8323 Ritem
: Node_Id
:= First_Rep_Item
(Ptyp
);
8326 if not Restricted
then
8327 -- Appends the _object argument
8330 Make_Attribute_Reference
(Loc
,
8332 Make_Selected_Component
(Loc
,
8333 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8334 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
8335 Attribute_Name
=> Name_Unchecked_Access
));
8338 -- Build the Attach_Handler table argument
8340 while Present
(Ritem
) loop
8341 if Nkind
(Ritem
) = N_Pragma
8342 and then Chars
(Ritem
) = Name_Attach_Handler
8345 Handler
: constant Node_Id
:=
8346 First
(Pragma_Argument_Associations
(Ritem
));
8348 Interrupt
: constant Node_Id
:= Next
(Handler
);
8349 Expr
: constant Node_Id
:= Expression
(Interrupt
);
8353 Make_Aggregate
(Loc
, Expressions
=> New_List
(
8354 Unchecked_Convert_To
8355 (RTE
(RE_System_Interrupt_Id
), Expr
),
8356 Make_Attribute_Reference
(Loc
,
8357 Prefix
=> Make_Selected_Component
(Loc
,
8358 Make_Identifier
(Loc
, Name_uInit
),
8359 Duplicate_Subexpr_No_Checks
8360 (Expression
(Handler
))),
8361 Attribute_Name
=> Name_Access
))));
8365 Next_Rep_Item
(Ritem
);
8368 -- Append the table argument we just built
8370 Append_To
(Args
, Make_Aggregate
(Loc
, Table
));
8372 -- Append the Install_Handler call to the statements
8375 Make_Procedure_Call_Statement
(Loc
,
8376 Name
=> New_Reference_To
(RTE
(RE_Install_Handlers
), Loc
),
8377 Parameter_Associations
=> Args
));
8382 end Make_Initialize_Protection
;
8384 ---------------------------
8385 -- Make_Task_Create_Call --
8386 ---------------------------
8388 function Make_Task_Create_Call
(Task_Rec
: Entity_Id
) return Node_Id
is
8389 Loc
: constant Source_Ptr
:= Sloc
(Task_Rec
);
8399 Ttyp
:= Corresponding_Concurrent_Type
(Task_Rec
);
8400 Tnam
:= Chars
(Ttyp
);
8402 -- Get task declaration. In the case of a task type declaration, this
8403 -- is simply the parent of the task type entity. In the single task
8404 -- declaration, this parent will be the implicit type, and we can find
8405 -- the corresponding single task declaration by searching forward in
8406 -- the declaration list in the tree.
8407 -- ??? I am not sure that the test for N_Single_Task_Declaration
8408 -- is needed here. Nodes of this type should have been removed
8409 -- during semantic analysis.
8411 Tdec
:= Parent
(Ttyp
);
8413 while Nkind
(Tdec
) /= N_Task_Type_Declaration
8414 and then Nkind
(Tdec
) /= N_Single_Task_Declaration
8419 -- Now we can find the task definition from this declaration
8421 Tdef
:= Task_Definition
(Tdec
);
8423 -- Build the parameter list for the call. Note that _Init is the name
8424 -- of the formal for the object to be initialized, which is the task
8425 -- value record itself.
8429 -- Priority parameter. Set to Unspecified_Priority unless there is a
8430 -- priority pragma, in which case we take the value from the pragma.
8432 if Present
(Tdef
) and then Has_Priority_Pragma
(Tdef
) then
8434 Make_Selected_Component
(Loc
,
8435 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8436 Selector_Name
=> Make_Identifier
(Loc
, Name_uPriority
)));
8439 New_Reference_To
(RTE
(RE_Unspecified_Priority
), Loc
));
8442 -- Optional Stack parameter
8444 if Restricted_Profile
then
8446 -- If the stack has been preallocated by the expander then
8447 -- pass its address. Otherwise, pass a null address.
8449 if Preallocated_Stacks_On_Target
then
8451 Make_Attribute_Reference
(Loc
,
8452 Prefix
=> Make_Selected_Component
(Loc
,
8453 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8455 Make_Identifier
(Loc
, Name_uStack
)),
8456 Attribute_Name
=> Name_Address
));
8460 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
8464 -- Size parameter. If no Storage_Size pragma is present, then
8465 -- the size is taken from the taskZ variable for the type, which
8466 -- is either Unspecified_Size, or has been reset by the use of
8467 -- a Storage_Size attribute definition clause. If a pragma is
8468 -- present, then the size is taken from the _Size field of the
8469 -- task value record, which was set from the pragma value.
8472 and then Has_Storage_Size_Pragma
(Tdef
)
8475 Make_Selected_Component
(Loc
,
8476 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8477 Selector_Name
=> Make_Identifier
(Loc
, Name_uSize
)));
8481 New_Reference_To
(Storage_Size_Variable
(Ttyp
), Loc
));
8484 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
8485 -- Task_Info pragma, in which case we take the value from the pragma.
8488 and then Has_Task_Info_Pragma
(Tdef
)
8491 Make_Selected_Component
(Loc
,
8492 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8493 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Info
)));
8497 New_Reference_To
(RTE
(RE_Unspecified_Task_Info
), Loc
));
8500 if not Restricted_Profile
then
8502 -- Number of entries. This is an expression of the form:
8504 -- n + _Init.a'Length + _Init.a'B'Length + ...
8506 -- where a,b... are the entry family names for the task definition
8508 Ecount
:= Build_Entry_Count_Expression
(
8510 Component_Items
(Component_List
(
8511 Type_Definition
(Parent
(
8512 Corresponding_Record_Type
(Ttyp
))))),
8514 Append_To
(Args
, Ecount
);
8516 -- Master parameter. This is a reference to the _Master parameter of
8517 -- the initialization procedure, except in the case of the pragma
8518 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
8519 -- See comments in System.Tasking.Initialization.Init_RTS for the
8522 if Restriction_Active
(No_Task_Hierarchy
) = False then
8523 Append_To
(Args
, Make_Identifier
(Loc
, Name_uMaster
));
8525 Append_To
(Args
, Make_Integer_Literal
(Loc
, 3));
8529 -- State parameter. This is a pointer to the task body procedure. The
8530 -- required value is obtained by taking the address of the task body
8531 -- procedure and converting it (with an unchecked conversion) to the
8532 -- type required by the task kernel. For further details, see the
8533 -- description of Expand_Task_Body
8536 Unchecked_Convert_To
(RTE
(RE_Task_Procedure_Access
),
8537 Make_Attribute_Reference
(Loc
,
8539 New_Occurrence_Of
(Get_Task_Body_Procedure
(Ttyp
), Loc
),
8540 Attribute_Name
=> Name_Address
)));
8542 -- Discriminants parameter. This is just the address of the task
8543 -- value record itself (which contains the discriminant values
8546 Make_Attribute_Reference
(Loc
,
8547 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8548 Attribute_Name
=> Name_Address
));
8550 -- Elaborated parameter. This is an access to the elaboration Boolean
8553 Make_Attribute_Reference
(Loc
,
8554 Prefix
=> Make_Identifier
(Loc
, New_External_Name
(Tnam
, 'E')),
8555 Attribute_Name
=> Name_Unchecked_Access
));
8557 -- Chain parameter. This is a reference to the _Chain parameter of
8558 -- the initialization procedure.
8560 Append_To
(Args
, Make_Identifier
(Loc
, Name_uChain
));
8562 -- Task name parameter. Take this from the _Task_Id parameter to the
8563 -- init call unless there is a Task_Name pragma, in which case we take
8564 -- the value from the pragma.
8567 and then Has_Task_Name_Pragma
(Tdef
)
8572 Pragma_Argument_Associations
(
8573 Find_Task_Or_Protected_Pragma
8574 (Tdef
, Name_Task_Name
))))));
8577 Append_To
(Args
, Make_Identifier
(Loc
, Name_uTask_Name
));
8580 -- Created_Task parameter. This is the _Task_Id field of the task
8584 Make_Selected_Component
(Loc
,
8585 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
8586 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)));
8588 if Restricted_Profile
then
8589 Name
:= New_Reference_To
(RTE
(RE_Create_Restricted_Task
), Loc
);
8591 Name
:= New_Reference_To
(RTE
(RE_Create_Task
), Loc
);
8594 return Make_Procedure_Call_Statement
(Loc
,
8595 Name
=> Name
, Parameter_Associations
=> Args
);
8596 end Make_Task_Create_Call
;
8598 ------------------------------
8599 -- Next_Protected_Operation --
8600 ------------------------------
8602 function Next_Protected_Operation
(N
: Node_Id
) return Node_Id
is
8606 Next_Op
:= Next
(N
);
8608 while Present
(Next_Op
)
8609 and then Nkind
(Next_Op
) /= N_Subprogram_Body
8610 and then Nkind
(Next_Op
) /= N_Entry_Body
8616 end Next_Protected_Operation
;
8618 ----------------------
8619 -- Set_Discriminals --
8620 ----------------------
8622 procedure Set_Discriminals
(Dec
: Node_Id
) is
8625 D_Minal
: Entity_Id
;
8628 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
8629 Pdef
:= Defining_Identifier
(Dec
);
8631 if Has_Discriminants
(Pdef
) then
8632 D
:= First_Discriminant
(Pdef
);
8634 while Present
(D
) loop
8636 Make_Defining_Identifier
(Sloc
(D
),
8637 Chars
=> New_External_Name
(Chars
(D
), 'D'));
8639 Set_Ekind
(D_Minal
, E_Constant
);
8640 Set_Etype
(D_Minal
, Etype
(D
));
8641 Set_Scope
(D_Minal
, Pdef
);
8642 Set_Discriminal
(D
, D_Minal
);
8643 Set_Discriminal_Link
(D_Minal
, D
);
8645 Next_Discriminant
(D
);
8648 end Set_Discriminals
;
8654 procedure Set_Privals
8663 Body_Ent
: Entity_Id
;
8664 Prec_Decl
: constant Node_Id
:=
8665 Parent
(Corresponding_Record_Type
8666 (Defining_Identifier
(Dec
)));
8667 Prec_Def
: constant Entity_Id
:= Type_Definition
(Prec_Decl
);
8669 P_Subtype
: Entity_Id
;
8670 Assoc_L
: constant Elist_Id
:= New_Elmt_List
;
8674 pragma Assert
(Nkind
(Dec
) = N_Protected_Type_Declaration
);
8676 (Nkind
(Op
) = N_Subprogram_Body
or else Nkind
(Op
) = N_Entry_Body
);
8678 Def
:= Protected_Definition
(Dec
);
8680 if Present
(Private_Declarations
(Def
)) then
8682 P_Decl
:= First
(Private_Declarations
(Def
));
8684 while Present
(P_Decl
) loop
8685 if Nkind
(P_Decl
) = N_Component_Declaration
then
8686 P_Id
:= Defining_Identifier
(P_Decl
);
8688 Make_Defining_Identifier
(Loc
,
8689 New_External_Name
(Chars
(P_Id
), 'P'));
8691 Set_Ekind
(Priv
, E_Variable
);
8692 Set_Etype
(Priv
, Etype
(P_Id
));
8693 Set_Scope
(Priv
, Scope
(P_Id
));
8694 Set_Esize
(Priv
, Esize
(Etype
(P_Id
)));
8695 Set_Alignment
(Priv
, Alignment
(Etype
(P_Id
)));
8697 -- If the type of the component is an itype, we must
8698 -- create a new itype for the corresponding prival in
8699 -- each protected operation, to avoid scoping problems.
8700 -- We create new itypes by copying the tree for the
8701 -- component definition.
8703 if Is_Itype
(Etype
(P_Id
)) then
8704 Append_Elmt
(P_Id
, Assoc_L
);
8705 Append_Elmt
(Priv
, Assoc_L
);
8707 if Nkind
(Op
) = N_Entry_Body
then
8708 Op_Id
:= Defining_Identifier
(Op
);
8710 Op_Id
:= Defining_Unit_Name
(Specification
(Op
));
8714 (New_Copy_Tree
(P_Decl
, Assoc_L
, New_Scope
=> Op_Id
));
8717 Set_Protected_Operation
(P_Id
, Op
);
8718 Set_Prival
(P_Id
, Priv
);
8725 -- There is one more implicit private declaration: the object
8726 -- itself. A "prival" for this is attached to the protected
8727 -- body defining identifier.
8729 Body_Ent
:= Corresponding_Body
(Dec
);
8732 Make_Defining_Identifier
(Sloc
(Body_Ent
),
8733 Chars
=> New_External_Name
(Chars
(Body_Ent
), 'R'));
8735 -- Set the Etype to the implicit subtype of Protection created when
8736 -- the protected type declaration was expanded. This node will not
8737 -- be analyzed until it is used as the defining identifier for the
8738 -- renaming declaration in the protected operation body, and it will
8739 -- be needed in the references expanded before that body is expanded.
8740 -- Since the Protection field is aliased, set Is_Aliased as well.
8742 Obj_Decl
:= First
(Component_Items
(Component_List
(Prec_Def
)));
8743 while Chars
(Defining_Identifier
(Obj_Decl
)) /= Name_uObject
loop
8747 P_Subtype
:= Etype
(Defining_Identifier
(Obj_Decl
));
8748 Set_Ekind
(Priv
, E_Variable
);
8749 Set_Etype
(Priv
, P_Subtype
);
8750 Set_Is_Aliased
(Priv
);
8751 Set_Object_Ref
(Body_Ent
, Priv
);
8754 ----------------------------
8755 -- Update_Prival_Subtypes --
8756 ----------------------------
8758 procedure Update_Prival_Subtypes
(N
: Node_Id
) is
8760 function Process
(N
: Node_Id
) return Traverse_Result
;
8761 -- Update the etype of occurrences of privals whose etype does not
8762 -- match the current Etype of the prival entity itself.
8764 procedure Update_Array_Bounds
(E
: Entity_Id
);
8765 -- Itypes generated for array expressions may depend on the
8766 -- determinants of the protected object, and need to be processed
8767 -- separately because they are not attached to the tree.
8769 procedure Update_Index_Types
(N
: Node_Id
);
8770 -- Similarly, update the types of expressions in indexed components
8771 -- which may depend on other discriminants.
8777 function Process
(N
: Node_Id
) return Traverse_Result
is
8779 if Is_Entity_Name
(N
) then
8781 E
: constant Entity_Id
:= Entity
(N
);
8785 and then (Ekind
(E
) = E_Constant
8786 or else Ekind
(E
) = E_Variable
)
8787 and then Nkind
(Parent
(E
)) = N_Object_Renaming_Declaration
8788 and then not Is_Scalar_Type
(Etype
(E
))
8789 and then Etype
(N
) /= Etype
(E
)
8791 Set_Etype
(N
, Etype
(Entity
(Original_Node
(N
))));
8792 Update_Index_Types
(N
);
8795 and then Ekind
(E
) = E_Constant
8796 and then Present
(Discriminal_Link
(E
))
8798 Set_Etype
(N
, Etype
(E
));
8804 elsif Nkind
(N
) = N_Defining_Identifier
8805 or else Nkind
(N
) = N_Defining_Operator_Symbol
8806 or else Nkind
(N
) = N_Defining_Character_Literal
8810 elsif Nkind
(N
) = N_String_Literal
then
8812 -- Array type, but bounds are constant
8816 elsif Nkind
(N
) = N_Object_Declaration
8817 and then Is_Itype
(Etype
(Defining_Identifier
(N
)))
8818 and then Is_Array_Type
(Etype
(Defining_Identifier
(N
)))
8820 Update_Array_Bounds
(Etype
(Defining_Identifier
(N
)));
8823 -- For array components of discriminated records, use the
8824 -- base type directly, because it may depend indirectly
8825 -- on the discriminants of the protected type. Cleaner would
8826 -- be a systematic mechanism to compute actual subtypes of
8827 -- private components ???
8829 elsif Nkind
(N
) in N_Has_Etype
8830 and then Present
(Etype
(N
))
8831 and then Is_Array_Type
(Etype
(N
))
8832 and then Nkind
(N
) = N_Selected_Component
8833 and then Has_Discriminants
(Etype
(Prefix
(N
)))
8835 Set_Etype
(N
, Base_Type
(Etype
(N
)));
8836 Update_Index_Types
(N
);
8840 if Nkind
(N
) in N_Has_Etype
8841 and then Present
(Etype
(N
))
8842 and then Is_Itype
(Etype
(N
)) then
8844 if Is_Array_Type
(Etype
(N
)) then
8845 Update_Array_Bounds
(Etype
(N
));
8847 elsif Is_Scalar_Type
(Etype
(N
)) then
8848 Update_Prival_Subtypes
(Type_Low_Bound
(Etype
(N
)));
8849 Update_Prival_Subtypes
(Type_High_Bound
(Etype
(N
)));
8857 -------------------------
8858 -- Update_Array_Bounds --
8859 -------------------------
8861 procedure Update_Array_Bounds
(E
: Entity_Id
) is
8865 Ind
:= First_Index
(E
);
8867 while Present
(Ind
) loop
8868 Update_Prival_Subtypes
(Type_Low_Bound
(Etype
(Ind
)));
8869 Update_Prival_Subtypes
(Type_High_Bound
(Etype
(Ind
)));
8872 end Update_Array_Bounds
;
8874 ------------------------
8875 -- Update_Index_Types --
8876 ------------------------
8878 procedure Update_Index_Types
(N
: Node_Id
) is
8882 -- If the prefix has an actual subtype that is different
8883 -- from the nominal one, update the types of the indices,
8884 -- so that the proper constraints are applied. Do not
8885 -- apply this transformation to a packed array, where the
8886 -- index type is computed for a byte array and is different
8887 -- from the source index.
8889 if Nkind
(Parent
(N
)) = N_Indexed_Component
8891 not Is_Bit_Packed_Array
(Etype
(Prefix
(Parent
(N
))))
8893 Indx1
:= First
(Expressions
(Parent
(N
)));
8894 I_Typ
:= First_Index
(Etype
(N
));
8896 while Present
(Indx1
) and then Present
(I_Typ
) loop
8898 if not Is_Entity_Name
(Indx1
) then
8899 Set_Etype
(Indx1
, Base_Type
(Etype
(I_Typ
)));
8906 end Update_Index_Types
;
8908 procedure Traverse
is new Traverse_Proc
;
8910 -- Start of processing for Update_Prival_Subtypes
8914 end Update_Prival_Subtypes
;