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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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;
49 with Sem_Ch6; use Sem_Ch6;
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 Uintp; use Uintp;
62 package body Exp_Ch9 is
64 --------------------------------
65 -- Select_Expansion_Utilities --
66 --------------------------------
68 -- The following constant establishes the upper bound for the index of
69 -- an entry family. It is used to limit the allocated size of protected
70 -- types with defaulted discriminant of an integer type, when the bound
71 -- of some entry family depends on a discriminant. The limitation to
72 -- entry families of 128K should be reasonable in all cases, and is a
73 -- documented implementation restriction. It will be lifted when protected
74 -- entry families are re-implemented as a single ordered queue.
76 Entry_Family_Bound : constant Int := 2**16;
78 -- The following package contains helper routines used in the expansion of
79 -- dispatching asynchronous, conditional and timed selects.
81 package Select_Expansion_Utilities is
82 function Build_Abort_Block
84 Abr_Blk_Ent : Entity_Id;
85 Cln_Blk_Ent : Entity_Id;
86 Blk : Node_Id) return Node_Id;
91 -- when Abort_Signal => Abort_Undefer;
93 -- Abr_Blk_Ent is the name of the generated block, Cln_Blk_Ent is
94 -- the name of the encapsulated cleanup block, Blk is the actual
99 Decls : List_Id) return Entity_Id;
101 -- B : Boolean := False;
102 -- Append the object declaration to the list and return the name of
107 Decls : List_Id) return Entity_Id;
109 -- C : Ada.Tags.Prim_Op_Kind;
110 -- Append the object declaration to the list and return the name of
113 function Build_Cleanup_Block
117 Clean_Ent : Entity_Id) return Node_Id;
120 -- procedure _clean is
129 -- Blk_Ent is the name of the generated block, Stmts is the list
130 -- of encapsulated statements and Clean_Ent is the parameter to
131 -- the _clean procedure.
137 Call_Ent : Entity_Id) return Entity_Id;
139 -- S : constant Integer :=
140 -- Ada.Tags.Get_Offset_Index (
141 -- Unchecked_Convert_To (Ada.Tags.Interface_Tag, Obj),
142 -- DT_Position (Call_Ent));
143 -- where Obj is the pointer to a secondary table, Call_Ent is the
144 -- entity of the dispatching call name. Append the object declaration
145 -- to the list and return its defining identifier.
147 end Select_Expansion_Utilities;
149 -----------------------------------------
150 -- Body for Select_Expansion_Utilities --
151 -----------------------------------------
153 package body Select_Expansion_Utilities is
155 -----------------------
156 -- Build_Abort_Block --
157 -----------------------
159 function Build_Abort_Block
161 Abr_Blk_Ent : Entity_Id;
162 Cln_Blk_Ent : Entity_Id;
163 Blk : Node_Id) return Node_Id
167 Make_Block_Statement (Loc,
168 Identifier => New_Reference_To (Abr_Blk_Ent, Loc),
170 Declarations => No_List,
172 Handled_Statement_Sequence =>
173 Make_Handled_Sequence_Of_Statements (Loc,
176 Make_Implicit_Label_Declaration (Loc,
177 Defining_Identifier =>
183 Exception_Handlers =>
185 Make_Exception_Handler (Loc,
188 New_Reference_To (Stand.Abort_Signal, Loc)),
191 Make_Procedure_Call_Statement (Loc,
193 New_Reference_To (RTE (
194 RE_Abort_Undefer), Loc),
195 Parameter_Associations => No_List))))));
196 end Build_Abort_Block;
204 Decls : List_Id) return Entity_Id
206 B : constant Entity_Id := Make_Defining_Identifier (Loc,
207 Chars => New_Internal_Name ('B'));
211 Make_Object_Declaration (Loc,
212 Defining_Identifier =>
215 New_Reference_To (Standard_Boolean, Loc),
217 New_Reference_To (Standard_False, Loc)));
228 Decls : List_Id) return Entity_Id
230 C : constant Entity_Id := Make_Defining_Identifier (Loc,
231 Chars => New_Internal_Name ('C'));
235 Make_Object_Declaration (Loc,
236 Defining_Identifier =>
239 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc)));
244 -------------------------
245 -- Build_Cleanup_Block --
246 -------------------------
248 function Build_Cleanup_Block
252 Clean_Ent : Entity_Id) return Node_Id
254 Cleanup_Block : constant Node_Id :=
255 Make_Block_Statement (Loc,
256 Identifier => New_Reference_To (Blk_Ent, Loc),
257 Declarations => No_List,
258 Handled_Statement_Sequence =>
259 Make_Handled_Sequence_Of_Statements (Loc,
260 Statements => Stmts),
261 Is_Asynchronous_Call_Block => True);
264 Set_Entry_Cancel_Parameter (Blk_Ent, Clean_Ent);
266 return Cleanup_Block;
267 end Build_Cleanup_Block;
277 Call_Ent : Entity_Id) return Entity_Id
279 S : constant Entity_Id := Make_Defining_Identifier (Loc,
280 Chars => New_Internal_Name ('S'));
284 Make_Object_Declaration (Loc,
285 Defining_Identifier => S,
286 Constant_Present => True,
289 New_Reference_To (Standard_Integer, Loc),
292 Make_Function_Call (Loc,
293 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
294 Parameter_Associations => New_List (
295 Unchecked_Convert_To (RTE (RE_Interface_Tag), Obj),
296 Make_Integer_Literal (Loc, DT_Position (Call_Ent))))));
300 end Select_Expansion_Utilities;
302 package SEU renames Select_Expansion_Utilities;
304 -----------------------
305 -- Local Subprograms --
306 -----------------------
308 function Actual_Index_Expression
312 Tsk : Entity_Id) return Node_Id;
313 -- Compute the index position for an entry call. Tsk is the target
314 -- task. If the bounds of some entry family depend on discriminants,
315 -- the expression computed by this function uses the discriminants
316 -- of the target task.
318 procedure Add_Object_Pointer
322 -- Prepend an object pointer declaration to the declaration list
323 -- Decls. This object pointer is initialized to a type conversion
324 -- of the System.Address pointer passed to entry barrier functions
325 -- and entry body procedures.
327 procedure Add_Formal_Renamings
332 -- Create renaming declarations for the formals, inside the procedure
333 -- that implements an entry body. The renamings make the original names
334 -- of the formals accessible to gdb, and serve no other purpose.
335 -- Spec is the specification of the procedure being built.
336 -- Decls is the list of declarations to be enhanced.
337 -- Ent is the entity for the original entry body.
339 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
340 -- Transform accept statement into a block with added exception handler.
341 -- Used both for simple accept statements and for accept alternatives in
342 -- select statements. Astat is the accept statement.
344 function Build_Barrier_Function
347 Pid : Node_Id) return Node_Id;
348 -- Build the function body returning the value of the barrier expression
349 -- for the specified entry body.
351 function Build_Barrier_Function_Specification
353 Loc : Source_Ptr) return Node_Id;
354 -- Build a specification for a function implementing
355 -- the protected entry barrier of the specified entry body.
357 function Build_Corresponding_Record
360 Loc : Source_Ptr) return Node_Id;
361 -- Common to tasks and protected types. Copy discriminant specifications,
362 -- build record declaration. N is the type declaration, Ctyp is the
363 -- concurrent entity (task type or protected type).
365 function Build_Entry_Count_Expression
366 (Concurrent_Type : Node_Id;
367 Component_List : List_Id;
368 Loc : Source_Ptr) return Node_Id;
369 -- Compute number of entries for concurrent object. This is a count of
370 -- simple entries, followed by an expression that computes the length
371 -- of the range of each entry family. A single array with that size is
372 -- allocated for each concurrent object of the type.
374 function Build_Parameter_Block
378 Decls : List_Id) return Entity_Id;
379 -- Generate an access type for each actual parameter in the list Actuals.
380 -- Cleate an encapsulating record that contains all the actuals and return
381 -- its type. Generate:
382 -- type Ann1 is access all <actual1-type>
384 -- type AnnN is access all <actualN-type>
385 -- type Pnn is record
391 function Build_Wrapper_Body
393 Proc_Nam : Entity_Id;
395 Formals : List_Id) return Node_Id;
396 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
397 -- associated with a protected or task type. This is required to implement
398 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
399 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
400 -- handle object notation, Formals are the original entry formals that will
401 -- be explicitly replicated.
403 function Build_Wrapper_Spec
405 Proc_Nam : Entity_Id;
407 Formals : List_Id) return Node_Id;
408 -- Ada 2005 (AI-345): Build the specification of a primitive operation
409 -- associated with a protected or task type. This is required implement
410 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
411 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
412 -- handle object notation, Formals are the original entry formals that will
413 -- be explicitly replicated.
415 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
416 -- Build the function that translates the entry index in the call
417 -- (which depends on the size of entry families) into an index into the
418 -- Entry_Bodies_Array, to determine the body and barrier function used
419 -- in a protected entry call. A pointer to this function appears in every
422 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
423 -- Build subprogram declaration for previous one
425 function Build_Protected_Entry
428 Pid : Node_Id) return Node_Id;
429 -- Build the procedure implementing the statement sequence of
430 -- the specified entry body.
432 function Build_Protected_Entry_Specification
435 Loc : Source_Ptr) return Node_Id;
436 -- Build a specification for a procedure implementing
437 -- the statement sequence of the specified entry body.
438 -- Add attributes associating it with the entry defining identifier
441 function Build_Protected_Subprogram_Body
444 N_Op_Spec : Node_Id) return Node_Id;
445 -- This function is used to construct the protected version of a protected
446 -- subprogram. Its statement sequence first defers abort, then locks
447 -- the associated protected object, and then enters a block that contains
448 -- a call to the unprotected version of the subprogram (for details, see
449 -- Build_Unprotected_Subprogram_Body). This block statement requires
450 -- a cleanup handler that unlocks the object in all cases.
451 -- (see Exp_Ch7.Expand_Cleanup_Actions).
453 function Build_Protected_Spec
455 Obj_Type : Entity_Id;
456 Unprotected : Boolean := False;
457 Ident : Entity_Id) return List_Id;
458 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
459 -- Subprogram_Type. Builds signature of protected subprogram, adding the
460 -- formal that corresponds to the object itself. For an access to protected
461 -- subprogram, there is no object type to specify, so the additional
462 -- parameter has type Address and mode In. An indirect call through such
463 -- a pointer converts the address to a reference to the actual object.
464 -- The object is a limited record and therefore a by_reference type.
466 function Build_Selected_Name
468 Selector : Entity_Id;
469 Append_Char : Character := ' ') return Name_Id;
470 -- Build a name in the form of Prefix__Selector, with an optional
471 -- character appended. This is used for internal subprograms generated
472 -- for operations of protected types, including barrier functions.
473 -- For the subprograms generated for entry bodies and entry barriers,
474 -- the generated name includes a sequence number that makes names
475 -- unique in the presence of entry overloading. This is necessary
476 -- because entry body procedures and barrier functions all have the
479 procedure Build_Simple_Entry_Call
484 -- Some comments here would be useful ???
486 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
487 -- This routine constructs a specification for the procedure that we will
488 -- build for the task body for task type T. The spec has the form:
490 -- procedure tnameB (_Task : access tnameV);
492 -- where name is the character name taken from the task type entity that
493 -- is passed as the argument to the procedure, and tnameV is the task
494 -- value type that is associated with the task type.
496 function Build_Unprotected_Subprogram_Body
498 Pid : Node_Id) return Node_Id;
499 -- This routine constructs the unprotected version of a protected
500 -- subprogram body, which is contains all of the code in the
501 -- original, unexpanded body. This is the version of the protected
502 -- subprogram that is called from all protected operations on the same
503 -- object, including the protected version of the same subprogram.
505 procedure Collect_Entry_Families
508 Current_Node : in out Node_Id;
509 Conctyp : Entity_Id);
510 -- For each entry family in a concurrent type, create an anonymous array
511 -- type of the right size, and add a component to the corresponding_record.
513 function Family_Offset
517 Ttyp : Entity_Id) return Node_Id;
518 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
519 -- an accept statement, or the upper bound in the discrete subtype of
520 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
521 -- the concurrent type of the entry.
527 Ttyp : Entity_Id) return Node_Id;
528 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
529 -- a family, and handle properly the superflat case. This is equivalent
530 -- to the use of 'Length on the index type, but must use Family_Offset
531 -- to handle properly the case of bounds that depend on discriminants.
533 procedure Extract_Dispatching_Call
535 Call_Ent : out Entity_Id;
536 Object : out Entity_Id;
537 Actuals : out List_Id;
538 Formals : out List_Id);
539 -- Given a dispatching call, extract the entity of the name of the call,
540 -- its object parameter, its actual parameters and the formal parameters
541 -- of the overriden interface-level version.
543 procedure Extract_Entry
545 Concval : out Node_Id;
547 Index : out Node_Id);
548 -- Given an entry call, returns the associated concurrent object,
549 -- the entry name, and the entry family index.
551 function Find_Task_Or_Protected_Pragma
553 P : Name_Id) return Node_Id;
554 -- Searches the task or protected definition T for the first occurrence
555 -- of the pragma whose name is given by P. The caller has ensured that
556 -- the pragma is present in the task definition. A special case is that
557 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
558 -- ??? Should be implemented with the rep item chain mechanism.
560 function Index_Constant_Declaration
562 Index_Id : Entity_Id;
563 Prot : Entity_Id) return List_Id;
564 -- For an entry family and its barrier function, we define a local entity
565 -- that maps the index in the call into the entry index into the object:
567 -- I : constant Index_Type := Index_Type'Val (
568 -- E - <<index of first family member>> +
569 -- Protected_Entry_Index (Index_Type'Pos (Index_Type'First)));
571 function Parameter_Block_Pack
577 Stmts : List_Id) return Entity_Id;
578 -- Set the components of the generated parameter block with the values of
579 -- the actual parameters. Generate aliased temporaries to capture the
580 -- values for types that are passed by copy. Otherwise generate a reference
581 -- to the actual's value. Return the address of the aggregate block.
583 -- Jnn1 : alias <formal-type1>;
584 -- Jnn1 := <actual1>;
587 -- Jnn1'unchecked_access;
588 -- <actual2>'reference;
591 function Parameter_Block_Unpack
595 Formals : List_Id) return List_Id;
596 -- Retrieve the values of the components from the parameter block and
597 -- assign then to the original actual parameters. Generate:
598 -- <actual1> := P.<formal1>;
600 -- <actualN> := P.<formalN>;
602 procedure Update_Prival_Subtypes (N : Node_Id);
603 -- The actual subtypes of the privals will differ from the type of the
604 -- private declaration in the original protected type, if the protected
605 -- type has discriminants or if the prival has constrained components.
606 -- This is because the privals are generated out of sequence w.r.t. the
607 -- analysis of a protected body. After generating the bodies for protected
608 -- operations, we set correctly the type of all references to privals, by
609 -- means of a recursive tree traversal, which is heavy-handed but
612 -----------------------------
613 -- Actual_Index_Expression --
614 -----------------------------
616 function Actual_Index_Expression
620 Tsk : Entity_Id) return Node_Id
622 Ttyp : constant Entity_Id := Etype (Tsk);
630 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
631 -- Compute difference between bounds of entry family
633 --------------------------
634 -- Actual_Family_Offset --
635 --------------------------
637 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
639 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
640 -- Replace a reference to a discriminant with a selected component
641 -- denoting the discriminant of the target task.
643 -----------------------------
644 -- Actual_Discriminant_Ref --
645 -----------------------------
647 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
648 Typ : constant Entity_Id := Etype (Bound);
652 if not Is_Entity_Name (Bound)
653 or else Ekind (Entity (Bound)) /= E_Discriminant
655 if Nkind (Bound) = N_Attribute_Reference then
658 B := New_Copy_Tree (Bound);
663 Make_Selected_Component (Sloc,
664 Prefix => New_Copy_Tree (Tsk),
665 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
667 Analyze_And_Resolve (B, Typ);
671 Make_Attribute_Reference (Sloc,
672 Attribute_Name => Name_Pos,
673 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
674 Expressions => New_List (B));
675 end Actual_Discriminant_Ref;
677 -- Start of processing for Actual_Family_Offset
681 Make_Op_Subtract (Sloc,
682 Left_Opnd => Actual_Discriminant_Ref (Hi),
683 Right_Opnd => Actual_Discriminant_Ref (Lo));
684 end Actual_Family_Offset;
686 -- Start of processing for Actual_Index_Expression
689 -- The queues of entries and entry families appear in textual
690 -- order in the associated record. The entry index is computed as
691 -- the sum of the number of queues for all entries that precede the
692 -- designated one, to which is added the index expression, if this
693 -- expression denotes a member of a family.
695 -- The following is a place holder for the count of simple entries
697 Num := Make_Integer_Literal (Sloc, 1);
699 -- We construct an expression which is a series of addition
700 -- operations. See comments in Entry_Index_Expression, which is
701 -- identical in structure.
703 if Present (Index) then
704 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
711 Actual_Family_Offset (
712 Make_Attribute_Reference (Sloc,
713 Attribute_Name => Name_Pos,
714 Prefix => New_Reference_To (Base_Type (S), Sloc),
715 Expressions => New_List (Relocate_Node (Index))),
716 Type_Low_Bound (S)));
721 -- Now add lengths of preceding entries and entry families
723 Prev := First_Entity (Ttyp);
725 while Chars (Prev) /= Chars (Ent)
726 or else (Ekind (Prev) /= Ekind (Ent))
727 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
729 if Ekind (Prev) = E_Entry then
730 Set_Intval (Num, Intval (Num) + 1);
732 elsif Ekind (Prev) = E_Entry_Family then
734 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
735 Lo := Type_Low_Bound (S);
736 Hi := Type_High_Bound (S);
744 Actual_Family_Offset (Hi, Lo),
746 Make_Integer_Literal (Sloc, 1)));
748 -- Other components are anonymous types to be ignored
758 end Actual_Index_Expression;
760 ----------------------------------
761 -- Add_Discriminal_Declarations --
762 ----------------------------------
764 procedure Add_Discriminal_Declarations
773 if Has_Discriminants (Typ) then
774 D := First_Discriminant (Typ);
776 while Present (D) loop
779 Make_Object_Renaming_Declaration (Loc,
780 Defining_Identifier => Discriminal (D),
781 Subtype_Mark => New_Reference_To (Etype (D), Loc),
783 Make_Selected_Component (Loc,
784 Prefix => Make_Identifier (Loc, Name),
785 Selector_Name => Make_Identifier (Loc, Chars (D)))));
787 Next_Discriminant (D);
790 end Add_Discriminal_Declarations;
792 ------------------------
793 -- Add_Object_Pointer --
794 ------------------------
796 procedure Add_Object_Pointer
805 -- Prepend the declaration of _object. This must be first in the
806 -- declaration list, since it is used by the discriminal and
807 -- prival declarations.
808 -- ??? An attempt to make this a renaming was unsuccessful.
810 -- type poVP is access poV;
811 -- _object : poVP := poVP!O;
814 Make_Defining_Identifier (Loc,
817 (Chars (Corresponding_Record_Type (Pid)), 'P'));
820 Make_Object_Declaration (Loc,
821 Defining_Identifier =>
822 Make_Defining_Identifier (Loc, Name_uObject),
823 Object_Definition => New_Reference_To (Obj_Ptr, Loc),
825 Unchecked_Convert_To (Obj_Ptr,
826 Make_Identifier (Loc, Name_uO)));
827 Set_Needs_Debug_Info (Defining_Identifier (Decl));
828 Prepend_To (Decls, Decl);
831 Make_Full_Type_Declaration (Loc,
832 Defining_Identifier => Obj_Ptr,
833 Type_Definition => Make_Access_To_Object_Definition (Loc,
834 Subtype_Indication =>
835 New_Reference_To (Corresponding_Record_Type (Pid), Loc))));
836 end Add_Object_Pointer;
838 --------------------------
839 -- Add_Formal_Renamings --
840 --------------------------
842 procedure Add_Formal_Renamings
848 Ptr : constant Entity_Id :=
850 (Next (First (Parameter_Specifications (Spec))));
851 -- The name of the formal that holds the address of the parameter block
860 Formal := First_Formal (Ent);
861 while Present (Formal) loop
862 Comp := Entry_Component (Formal);
864 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
865 Set_Etype (New_F, Etype (Formal));
866 Set_Scope (New_F, Ent);
867 Set_Needs_Debug_Info (New_F); -- That's the whole point.
869 if Ekind (Formal) = E_In_Parameter then
870 Set_Ekind (New_F, E_Constant);
872 Set_Ekind (New_F, E_Variable);
873 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
876 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
879 Make_Object_Renaming_Declaration (Loc,
880 Defining_Identifier => New_F,
881 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
883 Make_Explicit_Dereference (Loc,
884 Make_Selected_Component (Loc,
886 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
887 Make_Identifier (Loc, Chars (Ptr))),
889 New_Reference_To (Comp, Loc))));
891 Append (Decl, Decls);
892 Set_Renamed_Object (Formal, New_F);
893 Next_Formal (Formal);
895 end Add_Formal_Renamings;
897 ------------------------------
898 -- Add_Private_Declarations --
899 ------------------------------
901 procedure Add_Private_Declarations
907 Def : constant Node_Id := Protected_Definition (Parent (Typ));
909 Body_Ent : constant Entity_Id := Corresponding_Body (Parent (Typ));
914 pragma Assert (Nkind (Def) = N_Protected_Definition);
916 if Present (Private_Declarations (Def)) then
917 P := First (Private_Declarations (Def));
918 while Present (P) loop
919 if Nkind (P) = N_Component_Declaration then
920 Pdef := Defining_Identifier (P);
922 Make_Object_Renaming_Declaration (Loc,
923 Defining_Identifier => Prival (Pdef),
924 Subtype_Mark => New_Reference_To (Etype (Pdef), Loc),
926 Make_Selected_Component (Loc,
927 Prefix => Make_Identifier (Loc, Name),
928 Selector_Name => Make_Identifier (Loc, Chars (Pdef))));
929 Set_Needs_Debug_Info (Defining_Identifier (Decl));
930 Prepend_To (Decls, Decl);
937 -- One more "prival" for object itself, with the right protection type
940 Protection_Type : RE_Id;
943 if Has_Attach_Handler (Typ) then
944 if Restricted_Profile then
945 if Has_Entries (Typ) then
946 Protection_Type := RE_Protection_Entry;
948 Protection_Type := RE_Protection;
951 Protection_Type := RE_Static_Interrupt_Protection;
954 elsif Has_Interrupt_Handler (Typ) then
955 Protection_Type := RE_Dynamic_Interrupt_Protection;
957 -- The type has explicit entries or generated primitive entry
960 elsif Has_Entries (Typ)
961 or else (Ada_Version >= Ada_05
962 and then Present (Interface_List (Parent (Typ))))
965 or else Restriction_Active (No_Entry_Queue) = False
966 or else Number_Entries (Typ) > 1
968 Protection_Type := RE_Protection_Entries;
970 Protection_Type := RE_Protection_Entry;
974 Protection_Type := RE_Protection;
978 Make_Object_Renaming_Declaration (Loc,
979 Defining_Identifier => Object_Ref (Body_Ent),
980 Subtype_Mark => New_Reference_To (RTE (Protection_Type), Loc),
982 Make_Selected_Component (Loc,
983 Prefix => Make_Identifier (Loc, Name),
984 Selector_Name => Make_Identifier (Loc, Name_uObject)));
985 Set_Needs_Debug_Info (Defining_Identifier (Decl));
986 Prepend_To (Decls, Decl);
988 end Add_Private_Declarations;
990 -----------------------
991 -- Build_Accept_Body --
992 -----------------------
994 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
995 Loc : constant Source_Ptr := Sloc (Astat);
996 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
1003 -- At the end of the statement sequence, Complete_Rendezvous is called.
1004 -- A label skipping the Complete_Rendezvous, and all other accept
1005 -- processing, has already been added for the expansion of requeue
1008 Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous);
1009 Insert_Before (Last (Statements (Stats)), Call);
1012 -- If exception handlers are present, then append Complete_Rendezvous
1013 -- calls to the handlers, and construct the required outer block.
1015 if Present (Exception_Handlers (Stats)) then
1016 Hand := First (Exception_Handlers (Stats));
1018 while Present (Hand) loop
1019 Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous);
1020 Append (Call, Statements (Hand));
1026 Make_Handled_Sequence_Of_Statements (Loc,
1027 Statements => New_List (
1028 Make_Block_Statement (Loc,
1029 Handled_Statement_Sequence => Stats)));
1035 -- At this stage we know that the new statement sequence does not
1036 -- have an exception handler part, so we supply one to call
1037 -- Exceptional_Complete_Rendezvous. This handler is
1039 -- when all others =>
1040 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
1042 -- We handle Abort_Signal to make sure that we properly catch the abort
1043 -- case and wake up the caller.
1045 Ohandle := Make_Others_Choice (Loc);
1046 Set_All_Others (Ohandle);
1048 Set_Exception_Handlers (New_S,
1050 Make_Exception_Handler (Loc,
1051 Exception_Choices => New_List (Ohandle),
1053 Statements => New_List (
1054 Make_Procedure_Call_Statement (Loc,
1055 Name => New_Reference_To (
1056 RTE (RE_Exceptional_Complete_Rendezvous), Loc),
1057 Parameter_Associations => New_List (
1058 Make_Function_Call (Loc,
1059 Name => New_Reference_To (
1060 RTE (RE_Get_GNAT_Exception), Loc))))))));
1062 Set_Parent (New_S, Astat); -- temp parent for Analyze call
1063 Analyze_Exception_Handlers (Exception_Handlers (New_S));
1064 Expand_Exception_Handlers (New_S);
1066 -- Exceptional_Complete_Rendezvous must be called with abort
1067 -- still deferred, which is the case for a "when all others" handler.
1070 end Build_Accept_Body;
1072 -----------------------------------
1073 -- Build_Activation_Chain_Entity --
1074 -----------------------------------
1076 procedure Build_Activation_Chain_Entity (N : Node_Id) is
1082 -- Loop to find enclosing construct containing activation chain variable
1086 while Nkind (P) /= N_Subprogram_Body
1087 and then Nkind (P) /= N_Package_Declaration
1088 and then Nkind (P) /= N_Package_Body
1089 and then Nkind (P) /= N_Block_Statement
1090 and then Nkind (P) /= N_Task_Body
1095 -- If we are in a package body, the activation chain variable is
1096 -- allocated in the corresponding spec. First, we save the package
1097 -- body node because we enter the new entity in its Declarations list.
1101 if Nkind (P) = N_Package_Body then
1102 P := Unit_Declaration_Node (Corresponding_Spec (P));
1103 Decls := Declarations (B);
1105 elsif Nkind (P) = N_Package_Declaration then
1106 Decls := Visible_Declarations (Specification (B));
1109 Decls := Declarations (B);
1112 -- If activation chain entity not already declared, declare it
1114 if No (Activation_Chain_Entity (P)) then
1115 Set_Activation_Chain_Entity
1116 (P, Make_Defining_Identifier (Sloc (N), Name_uChain));
1119 Make_Object_Declaration (Sloc (P),
1120 Defining_Identifier => Activation_Chain_Entity (P),
1121 Aliased_Present => True,
1122 Object_Definition =>
1123 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
1125 Analyze (First (Decls));
1127 end Build_Activation_Chain_Entity;
1129 ----------------------------
1130 -- Build_Barrier_Function --
1131 ----------------------------
1133 function Build_Barrier_Function
1136 Pid : Node_Id) return Node_Id
1138 Loc : constant Source_Ptr := Sloc (N);
1139 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1140 Index_Spec : constant Node_Id := Entry_Index_Specification
1142 Op_Decls : constant List_Id := New_List;
1148 Make_Defining_Identifier (Loc, Chars (Barrier_Function (Ent)));
1149 Bspec := Build_Barrier_Function_Specification (Bdef, Loc);
1151 -- <object pointer declaration>
1152 -- <discriminant renamings>
1153 -- <private object renamings>
1154 -- Add discriminal and private renamings. These names have
1155 -- already been used to expand references to discriminants
1156 -- and private data.
1158 Add_Discriminal_Declarations (Op_Decls, Pid, Name_uObject, Loc);
1159 Add_Private_Declarations (Op_Decls, Pid, Name_uObject, Loc);
1160 Add_Object_Pointer (Op_Decls, Pid, Loc);
1162 -- If this is the barrier for an entry family, the entry index is
1163 -- visible in the body of the barrier. Create a local variable that
1164 -- converts the entry index (which is the last formal of the barrier
1165 -- function) into the appropriate offset into the entry array. The
1166 -- entry index constant must be set, as for the entry body, so that
1167 -- local references to the entry index are correctly replaced with
1168 -- the local variable. This parallels what is done for entry bodies.
1170 if Present (Index_Spec) then
1172 Index_Id : constant Entity_Id := Defining_Identifier (Index_Spec);
1173 Index_Con : constant Entity_Id :=
1174 Make_Defining_Identifier (Loc,
1175 Chars => New_Internal_Name ('J'));
1178 Set_Entry_Index_Constant (Index_Id, Index_Con);
1179 Append_List_To (Op_Decls,
1180 Index_Constant_Declaration (N, Index_Id, Pid));
1184 -- Note: the condition in the barrier function needs to be properly
1185 -- processed for the C/Fortran boolean possibility, but this happens
1186 -- automatically since the return statement does this normalization.
1189 Make_Subprogram_Body (Loc,
1190 Specification => Bspec,
1191 Declarations => Op_Decls,
1192 Handled_Statement_Sequence =>
1193 Make_Handled_Sequence_Of_Statements (Loc,
1194 Statements => New_List (
1195 Make_Return_Statement (Loc,
1196 Expression => Condition (Ent_Formals)))));
1197 end Build_Barrier_Function;
1199 ------------------------------------------
1200 -- Build_Barrier_Function_Specification --
1201 ------------------------------------------
1203 function Build_Barrier_Function_Specification
1204 (Def_Id : Entity_Id;
1205 Loc : Source_Ptr) return Node_Id
1208 Set_Needs_Debug_Info (Def_Id);
1209 return Make_Function_Specification (Loc,
1210 Defining_Unit_Name => Def_Id,
1211 Parameter_Specifications => New_List (
1212 Make_Parameter_Specification (Loc,
1213 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
1215 New_Reference_To (RTE (RE_Address), Loc)),
1217 Make_Parameter_Specification (Loc,
1218 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE),
1220 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1222 Result_Definition => New_Reference_To (Standard_Boolean, Loc));
1223 end Build_Barrier_Function_Specification;
1225 --------------------------
1226 -- Build_Call_With_Task --
1227 --------------------------
1229 function Build_Call_With_Task
1231 E : Entity_Id) return Node_Id
1233 Loc : constant Source_Ptr := Sloc (N);
1236 Make_Function_Call (Loc,
1237 Name => New_Reference_To (E, Loc),
1238 Parameter_Associations => New_List (Concurrent_Ref (N)));
1239 end Build_Call_With_Task;
1241 --------------------------------
1242 -- Build_Corresponding_Record --
1243 --------------------------------
1245 function Build_Corresponding_Record
1248 Loc : Source_Ptr) return Node_Id
1250 Rec_Ent : constant Entity_Id :=
1251 Make_Defining_Identifier
1252 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1255 New_Disc : Entity_Id;
1259 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1260 Set_Ekind (Rec_Ent, E_Record_Type);
1261 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1262 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1263 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1264 Set_Stored_Constraint (Rec_Ent, No_Elist);
1267 -- Use discriminals to create list of discriminants for record, and
1268 -- create new discriminals for use in default expressions, etc. It is
1269 -- worth noting that a task discriminant gives rise to 5 entities;
1271 -- a) The original discriminant.
1272 -- b) The discriminal for use in the task.
1273 -- c) The discriminant of the corresponding record.
1274 -- d) The discriminal for the init proc of the corresponding record.
1275 -- e) The local variable that renames the discriminant in the procedure
1276 -- for the task body.
1278 -- In fact the discriminals b) are used in the renaming declarations
1279 -- for e). See details in einfo (Handling of Discriminants).
1281 if Present (Discriminant_Specifications (N)) then
1283 Disc := First_Discriminant (Ctyp);
1285 while Present (Disc) loop
1286 New_Disc := CR_Discriminant (Disc);
1289 Make_Discriminant_Specification (Loc,
1290 Defining_Identifier => New_Disc,
1291 Discriminant_Type =>
1292 New_Occurrence_Of (Etype (Disc), Loc),
1294 New_Copy (Discriminant_Default_Value (Disc))));
1296 Next_Discriminant (Disc);
1303 -- Now we can construct the record type declaration. Note that this
1304 -- record is "limited tagged". It is "limited" to reflect the underlying
1305 -- limitedness of the task or protected object that it represents, and
1306 -- ensuring for example that it is properly passed by reference. It is
1307 -- "tagged" to give support to dispatching calls through interfaces (Ada
1311 Make_Full_Type_Declaration (Loc,
1312 Defining_Identifier => Rec_Ent,
1313 Discriminant_Specifications => Dlist,
1315 Make_Record_Definition (Loc,
1317 Make_Component_List (Loc,
1318 Component_Items => Cdecls),
1320 Ada_Version >= Ada_05 and then Is_Tagged_Type (Ctyp),
1321 Limited_Present => True));
1322 end Build_Corresponding_Record;
1324 ----------------------------------
1325 -- Build_Entry_Count_Expression --
1326 ----------------------------------
1328 function Build_Entry_Count_Expression
1329 (Concurrent_Type : Node_Id;
1330 Component_List : List_Id;
1331 Loc : Source_Ptr) return Node_Id
1342 -- Count number of non-family entries
1345 Ent := First_Entity (Concurrent_Type);
1346 while Present (Ent) loop
1347 if Ekind (Ent) = E_Entry then
1354 Ecount := Make_Integer_Literal (Loc, Eindx);
1356 -- Loop through entry families building the addition nodes
1358 Ent := First_Entity (Concurrent_Type);
1359 Comp := First (Component_List);
1360 while Present (Ent) loop
1361 if Ekind (Ent) = E_Entry_Family then
1362 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1366 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1367 Hi := Type_High_Bound (Typ);
1368 Lo := Type_Low_Bound (Typ);
1372 Left_Opnd => Ecount,
1373 Right_Opnd => Family_Size (Loc, Hi, Lo, Concurrent_Type));
1380 end Build_Entry_Count_Expression;
1382 ---------------------------
1383 -- Build_Parameter_Block --
1384 ---------------------------
1386 function Build_Parameter_Block
1390 Decls : List_Id) return Entity_Id
1396 Has_Comp : Boolean := False;
1400 Actual := First (Actuals);
1402 Formal := Defining_Identifier (First (Formals));
1404 while Present (Actual) loop
1405 if not Is_Controlling_Actual (Actual) then
1408 -- type Ann is access all <actual-type>
1411 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
1414 Make_Full_Type_Declaration (Loc,
1415 Defining_Identifier =>
1418 Make_Access_To_Object_Definition (Loc,
1422 Ekind (Formal) = E_In_Parameter,
1423 Subtype_Indication =>
1424 New_Reference_To (Etype (Actual), Loc))));
1430 Make_Component_Declaration (Loc,
1431 Defining_Identifier =>
1432 Make_Defining_Identifier (Loc, Chars (Formal)),
1433 Component_Definition =>
1434 Make_Component_Definition (Loc,
1437 Subtype_Indication =>
1438 New_Reference_To (Comp_Nam, Loc))));
1443 Next_Actual (Actual);
1444 Next_Formal_With_Extras (Formal);
1448 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
1453 -- type Pnn is record
1458 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1459 -- the original parameter names and Ann1 .. AnnN are the access to
1463 Make_Full_Type_Declaration (Loc,
1464 Defining_Identifier =>
1467 Make_Record_Definition (Loc,
1469 Make_Component_List (Loc, Comps))));
1472 -- type Pnn is null record;
1475 Make_Full_Type_Declaration (Loc,
1476 Defining_Identifier =>
1479 Make_Record_Definition (Loc,
1480 Null_Present => True,
1481 Component_List => Empty)));
1485 end Build_Parameter_Block;
1487 ------------------------
1488 -- Build_Wrapper_Body --
1489 ------------------------
1491 function Build_Wrapper_Body
1493 Proc_Nam : Entity_Id;
1494 Obj_Typ : Entity_Id;
1495 Formals : List_Id) return Node_Id
1497 Actuals : List_Id := No_List;
1498 Body_Spec : Node_Id;
1500 First_Formal : Node_Id;
1504 Body_Spec := Build_Wrapper_Spec (Loc, Proc_Nam, Obj_Typ, Formals);
1506 -- If we did not generate the specification do have nothing else to do
1508 if Body_Spec = Empty then
1512 -- Map formals to actuals. Use the list built for the wrapper spec,
1513 -- skipping the object notation parameter.
1515 First_Formal := First (Parameter_Specifications (Body_Spec));
1517 Formal := First_Formal;
1520 if Present (Formal) then
1521 Actuals := New_List;
1523 while Present (Formal) loop
1525 Make_Identifier (Loc, Chars =>
1526 Chars (Defining_Identifier (Formal))));
1532 -- An access-to-variable first parameter will require an explicit
1533 -- dereference in the unchecked conversion. This case occurs when
1534 -- a protected entry wrapper must override an interface-level
1535 -- procedure with interface access as first parameter.
1537 -- SubprgName (O.all).Proc_Nam (Formal_1 .. Formal_N)
1539 if Nkind (Parameter_Type (First_Formal)) = N_Access_Definition then
1541 Make_Explicit_Dereference (Loc,
1543 Make_Identifier (Loc, Chars => Name_uO));
1546 Make_Identifier (Loc, Chars => Name_uO);
1549 if Ekind (Proc_Nam) = E_Function then
1551 Make_Subprogram_Body (Loc,
1552 Specification => Body_Spec,
1553 Declarations => Empty_List,
1554 Handled_Statement_Sequence =>
1555 Make_Handled_Sequence_Of_Statements (Loc,
1558 Make_Return_Statement (Loc,
1559 Make_Function_Call (Loc,
1561 Make_Selected_Component (Loc,
1563 Unchecked_Convert_To (
1564 Corresponding_Concurrent_Type (Obj_Typ),
1567 New_Reference_To (Proc_Nam, Loc)),
1568 Parameter_Associations => Actuals)))));
1571 Make_Subprogram_Body (Loc,
1572 Specification => Body_Spec,
1573 Declarations => Empty_List,
1574 Handled_Statement_Sequence =>
1575 Make_Handled_Sequence_Of_Statements (Loc,
1578 Make_Procedure_Call_Statement (Loc,
1580 Make_Selected_Component (Loc,
1582 Unchecked_Convert_To (
1583 Corresponding_Concurrent_Type (Obj_Typ),
1586 New_Reference_To (Proc_Nam, Loc)),
1587 Parameter_Associations => Actuals))));
1589 end Build_Wrapper_Body;
1591 ------------------------
1592 -- Build_Wrapper_Spec --
1593 ------------------------
1595 function Build_Wrapper_Spec
1597 Proc_Nam : Entity_Id;
1598 Obj_Typ : Entity_Id;
1599 Formals : List_Id) return Node_Id
1601 New_Name_Id : constant Entity_Id :=
1602 Make_Defining_Identifier (Loc, Chars (Proc_Nam));
1604 First_Param : Node_Id := Empty;
1606 Iface_Elmt : Elmt_Id := No_Elmt;
1607 New_Formals : List_Id;
1608 Obj_Param : Node_Id;
1609 Obj_Param_Typ : Node_Id;
1610 Iface_Prim_Op : Entity_Id;
1611 Iface_Prim_Op_Elmt : Elmt_Id;
1613 function Overriding_Possible
1614 (Iface_Prim_Op : Entity_Id;
1615 Proc_Nam : Entity_Id) return Boolean;
1616 -- Determine whether a primitive operation can be overriden by the
1617 -- wrapper. Iface_Prim_Op is the candidate primitive operation of an
1618 -- abstract interface type, Proc_Nam is the generated entry wrapper.
1620 function Replicate_Entry_Formals
1622 Formals : List_Id) return List_Id;
1623 -- An explicit parameter replication is required due to the
1624 -- Is_Entry_Formal flag being set for all the formals. The explicit
1625 -- replication removes the flag that would otherwise cause a different
1626 -- path of analysis.
1628 -------------------------
1629 -- Overriding_Possible --
1630 -------------------------
1632 function Overriding_Possible
1633 (Iface_Prim_Op : Entity_Id;
1634 Proc_Nam : Entity_Id) return Boolean
1636 Prim_Op_Spec : constant Node_Id := Parent (Iface_Prim_Op);
1637 Proc_Spec : constant Node_Id := Parent (Proc_Nam);
1639 Is_Access_To_Variable : Boolean;
1640 Is_Out_Present : Boolean;
1642 function Type_Conformant_Parameters
1643 (Prim_Op_Param_Specs : List_Id;
1644 Proc_Param_Specs : List_Id) return Boolean;
1645 -- Determine whether the parameters of the generated entry wrapper
1646 -- and those of a primitive operation are type conformant. During
1647 -- this check, the first parameter of the primitive operation is
1650 --------------------------------
1651 -- Type_Conformant_Parameters --
1652 --------------------------------
1654 function Type_Conformant_Parameters
1655 (Prim_Op_Param_Specs : List_Id;
1656 Proc_Param_Specs : List_Id) return Boolean
1658 Prim_Op_Param : Node_Id;
1659 Proc_Param : Node_Id;
1662 -- Skip the first parameter of the primitive operation
1664 Prim_Op_Param := Next (First (Prim_Op_Param_Specs));
1665 Proc_Param := First (Proc_Param_Specs);
1666 while Present (Prim_Op_Param)
1667 and then Present (Proc_Param)
1669 -- The two parameters must be mode conformant and have
1670 -- the exact same types.
1672 if Ekind (Defining_Identifier (Prim_Op_Param)) /=
1673 Ekind (Defining_Identifier (Proc_Param))
1674 or else Etype (Parameter_Type (Prim_Op_Param)) /=
1675 Etype (Parameter_Type (Proc_Param))
1680 Next (Prim_Op_Param);
1684 -- One of the lists is longer than the other
1686 if Present (Prim_Op_Param) or else Present (Proc_Param) then
1691 end Type_Conformant_Parameters;
1693 -- Start of processing for Overriding_Possible
1696 if Chars (Iface_Prim_Op) /= Chars (Proc_Nam) then
1700 -- Special check for protected procedures: If an inherited subprogram
1701 -- is implemented by a protected procedure or an entry, then the
1702 -- first parameter of the inherited subprogram shall be of mode OUT
1703 -- or IN OUT, or an access-to-variable parameter.
1705 if Ekind (Iface_Prim_Op) = E_Procedure then
1708 Present (Parameter_Specifications (Prim_Op_Spec))
1710 Out_Present (First (Parameter_Specifications (Prim_Op_Spec)));
1712 Is_Access_To_Variable :=
1713 Present (Parameter_Specifications (Prim_Op_Spec))
1715 Nkind (Parameter_Type
1717 (Parameter_Specifications (Prim_Op_Spec))))
1718 = N_Access_Definition;
1720 if not Is_Out_Present
1721 and then not Is_Access_To_Variable
1727 return Type_Conformant_Parameters (
1728 Parameter_Specifications (Prim_Op_Spec),
1729 Parameter_Specifications (Proc_Spec));
1730 end Overriding_Possible;
1732 -----------------------------
1733 -- Replicate_Entry_Formals --
1734 -----------------------------
1736 function Replicate_Entry_Formals
1738 Formals : List_Id) return List_Id
1740 New_Formals : constant List_Id := New_List;
1744 Formal := First (Formals);
1745 while Present (Formal) loop
1747 -- Create an explicit copy of the entry parameter
1749 Append_To (New_Formals,
1750 Make_Parameter_Specification (Loc,
1751 Defining_Identifier =>
1752 Make_Defining_Identifier (Loc,
1753 Chars => Chars (Defining_Identifier (Formal))),
1754 In_Present => In_Present (Formal),
1755 Out_Present => Out_Present (Formal),
1756 Parameter_Type => New_Reference_To (Etype (
1757 Parameter_Type (Formal)), Loc)));
1763 end Replicate_Entry_Formals;
1765 -- Start of processing for Build_Wrapper_Spec
1768 -- The mode is determined by the first parameter of the interface-level
1769 -- procedure that the current entry is trying to override.
1771 pragma Assert (Present (Abstract_Interfaces
1772 (Corresponding_Record_Type (Scope (Proc_Nam)))));
1775 First_Elmt (Abstract_Interfaces
1776 (Corresponding_Record_Type (Scope (Proc_Nam))));
1778 -- We must examine all the protected operations of the implemented
1779 -- interfaces in order to discover a possible overriding candidate.
1781 Examine_Interfaces : while Present (Iface_Elmt) loop
1782 Iface := Node (Iface_Elmt);
1784 if Present (Primitive_Operations (Iface)) then
1785 Iface_Prim_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1786 while Present (Iface_Prim_Op_Elmt) loop
1787 Iface_Prim_Op := Node (Iface_Prim_Op_Elmt);
1789 while Present (Alias (Iface_Prim_Op)) loop
1790 Iface_Prim_Op := Alias (Iface_Prim_Op);
1793 -- The current primitive operation can be overriden by the
1794 -- generated entry wrapper.
1796 if Overriding_Possible (Iface_Prim_Op, Proc_Nam) then
1798 First (Parameter_Specifications (Parent (Iface_Prim_Op)));
1800 exit Examine_Interfaces;
1803 Next_Elmt (Iface_Prim_Op_Elmt);
1807 Next_Elmt (Iface_Elmt);
1808 end loop Examine_Interfaces;
1810 -- Return if no interface primitive can be overriden
1812 if not Present (First_Param) then
1816 New_Formals := Replicate_Entry_Formals (Loc, Formals);
1818 -- ??? Certain source packages contain protected or task types that do
1819 -- not implement any interfaces and are compiled with the -gnat05
1820 -- switch. In this case, a default first parameter is created.
1822 if Present (First_Param) then
1823 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
1825 Make_Access_Definition (Loc,
1827 New_Reference_To (Obj_Typ, Loc));
1829 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
1833 Make_Parameter_Specification (Loc,
1834 Defining_Identifier =>
1835 Make_Defining_Identifier (Loc, Name_uO),
1836 In_Present => In_Present (First_Param),
1837 Out_Present => Out_Present (First_Param),
1838 Parameter_Type => Obj_Param_Typ);
1842 Make_Parameter_Specification (Loc,
1843 Defining_Identifier =>
1844 Make_Defining_Identifier (Loc, Name_uO),
1846 Out_Present => True,
1847 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
1850 Prepend_To (New_Formals, Obj_Param);
1852 -- Minimum decoration needed to catch the entity in
1853 -- Sem_Ch6.Override_Dispatching_Operation
1855 if Ekind (Proc_Nam) = E_Procedure
1856 or else Ekind (Proc_Nam) = E_Entry
1858 Set_Ekind (New_Name_Id, E_Procedure);
1859 Set_Is_Primitive_Wrapper (New_Name_Id);
1860 Set_Wrapped_Entity (New_Name_Id, Proc_Nam);
1863 Make_Procedure_Specification (Loc,
1864 Defining_Unit_Name => New_Name_Id,
1865 Parameter_Specifications => New_Formals);
1867 else pragma Assert (Ekind (Proc_Nam) = E_Function);
1868 Set_Ekind (New_Name_Id, E_Function);
1871 Make_Function_Specification (Loc,
1872 Defining_Unit_Name => New_Name_Id,
1873 Parameter_Specifications => New_Formals,
1874 Result_Definition =>
1875 New_Copy (Result_Definition (Parent (Proc_Nam))));
1877 end Build_Wrapper_Spec;
1879 ---------------------------
1880 -- Build_Find_Body_Index --
1881 ---------------------------
1883 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
1884 Loc : constant Source_Ptr := Sloc (Typ);
1887 Has_F : Boolean := False;
1889 If_St : Node_Id := Empty;
1892 Decls : List_Id := New_List;
1895 Siz : Node_Id := Empty;
1897 procedure Add_If_Clause (Expr : Node_Id);
1898 -- Add test for range of current entry
1900 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
1901 -- If a bound of an entry is given by a discriminant, retrieve the
1902 -- actual value of the discriminant from the enclosing object.
1908 procedure Add_If_Clause (Expr : Node_Id) is
1910 Stats : constant List_Id :=
1912 Make_Return_Statement (Loc,
1913 Expression => Make_Integer_Literal (Loc, Index + 1)));
1916 -- Index for current entry body
1920 -- Compute total length of entry queues so far
1928 Right_Opnd => Expr);
1933 Left_Opnd => Make_Identifier (Loc, Name_uE),
1936 -- Map entry queue indices in the range of the current family
1937 -- into the current index, that designates the entry body.
1941 Make_Implicit_If_Statement (Typ,
1943 Then_Statements => Stats,
1944 Elsif_Parts => New_List);
1950 Make_Elsif_Part (Loc,
1952 Then_Statements => Stats),
1953 Elsif_Parts (If_St));
1957 ------------------------------
1958 -- Convert_Discriminant_Ref --
1959 ------------------------------
1961 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
1965 if Is_Entity_Name (Bound)
1966 and then Ekind (Entity (Bound)) = E_Discriminant
1969 Make_Selected_Component (Loc,
1971 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
1972 Make_Explicit_Dereference (Loc,
1973 Make_Identifier (Loc, Name_uObject))),
1974 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
1975 Set_Etype (B, Etype (Entity (Bound)));
1977 B := New_Copy_Tree (Bound);
1981 end Convert_Discriminant_Ref;
1983 -- Start of processing for Build_Find_Body_Index
1986 Spec := Build_Find_Body_Index_Spec (Typ);
1988 Ent := First_Entity (Typ);
1989 while Present (Ent) loop
1990 if Ekind (Ent) = E_Entry_Family then
2000 -- If the protected type has no entry families, there is a one-one
2001 -- correspondence between entry queue and entry body.
2004 Make_Return_Statement (Loc,
2005 Expression => Make_Identifier (Loc, Name_uE));
2008 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2011 -- if E <= l1 then return 1;
2012 -- elsif E <= l1 + l2 then return 2;
2017 Ent := First_Entity (Typ);
2019 Add_Object_Pointer (Decls, Typ, Loc);
2021 while Present (Ent) loop
2023 if Ekind (Ent) = E_Entry then
2024 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2026 elsif Ekind (Ent) = E_Entry_Family then
2028 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2029 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2030 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2031 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ));
2040 Make_Return_Statement (Loc,
2041 Expression => Make_Integer_Literal (Loc, 1));
2043 elsif Nkind (Ret) = N_If_Statement then
2045 -- Ranges are in increasing order, so last one doesn't need guard
2048 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2051 Set_Else_Statements (Ret, Then_Statements (Nod));
2057 Make_Subprogram_Body (Loc,
2058 Specification => Spec,
2059 Declarations => Decls,
2060 Handled_Statement_Sequence =>
2061 Make_Handled_Sequence_Of_Statements (Loc,
2062 Statements => New_List (Ret)));
2063 end Build_Find_Body_Index;
2065 --------------------------------
2066 -- Build_Find_Body_Index_Spec --
2067 --------------------------------
2069 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2070 Loc : constant Source_Ptr := Sloc (Typ);
2071 Id : constant Entity_Id :=
2072 Make_Defining_Identifier (Loc,
2073 Chars => New_External_Name (Chars (Typ), 'F'));
2074 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2075 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2079 Make_Function_Specification (Loc,
2080 Defining_Unit_Name => Id,
2081 Parameter_Specifications => New_List (
2082 Make_Parameter_Specification (Loc,
2083 Defining_Identifier => Parm1,
2085 New_Reference_To (RTE (RE_Address), Loc)),
2087 Make_Parameter_Specification (Loc,
2088 Defining_Identifier => Parm2,
2090 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2091 Result_Definition => New_Occurrence_Of (
2092 RTE (RE_Protected_Entry_Index), Loc));
2093 end Build_Find_Body_Index_Spec;
2095 -------------------------
2096 -- Build_Master_Entity --
2097 -------------------------
2099 procedure Build_Master_Entity (E : Entity_Id) is
2100 Loc : constant Source_Ptr := Sloc (E);
2108 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2109 -- in internal scopes, unless present already.. Required for nested
2110 -- limited aggregates. This could use some more explanation ????
2112 if Ada_Version >= Ada_05 then
2113 while Is_Internal (S) loop
2118 -- Nothing to do if we already built a master entity for this scope
2119 -- or if there is no task hierarchy.
2121 if Has_Master_Entity (S)
2122 or else Restriction_Active (No_Task_Hierarchy)
2127 -- Otherwise first build the master entity
2128 -- _Master : constant Master_Id := Current_Master.all;
2129 -- and insert it just before the current declaration
2132 Make_Object_Declaration (Loc,
2133 Defining_Identifier =>
2134 Make_Defining_Identifier (Loc, Name_uMaster),
2135 Constant_Present => True,
2136 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2138 Make_Explicit_Dereference (Loc,
2139 New_Reference_To (RTE (RE_Current_Master), Loc)));
2142 Insert_Before (P, Decl);
2145 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2146 -- non-internal scope selected above.
2148 if Ada_Version >= Ada_05 then
2149 Set_Has_Master_Entity (S);
2151 Set_Has_Master_Entity (Scope (E));
2154 -- Now mark the containing scope as a task master
2156 while Nkind (P) /= N_Compilation_Unit loop
2159 -- If we fall off the top, we are at the outer level, and the
2160 -- environment task is our effective master, so nothing to mark.
2162 if Nkind (P) = N_Task_Body
2163 or else Nkind (P) = N_Block_Statement
2164 or else Nkind (P) = N_Subprogram_Body
2166 Set_Is_Task_Master (P, True);
2169 elsif Nkind (Parent (P)) = N_Subunit then
2170 P := Corresponding_Stub (Parent (P));
2173 end Build_Master_Entity;
2175 ---------------------------
2176 -- Build_Protected_Entry --
2177 ---------------------------
2179 function Build_Protected_Entry
2182 Pid : Node_Id) return Node_Id
2184 Loc : constant Source_Ptr := Sloc (N);
2185 Op_Decls : constant List_Id := New_List;
2194 Make_Defining_Identifier (Loc,
2195 Chars => Chars (Protected_Body_Subprogram (Ent)));
2196 Espec := Build_Protected_Entry_Specification (Edef, Empty, Loc);
2198 -- <object pointer declaration>
2200 -- Add object pointer declaration. This is needed by the discriminal and
2201 -- prival renamings, which should already have been inserted into the
2202 -- declaration list.
2204 Add_Object_Pointer (Op_Decls, Pid, Loc);
2206 -- Add renamings for formals for use by debugger
2208 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2211 or else Restriction_Active (No_Entry_Queue) = False
2212 or else Number_Entries (Pid) > 1
2214 Complete := New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2217 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2220 Op_Stats := New_List (
2221 Make_Block_Statement (Loc,
2222 Declarations => Declarations (N),
2223 Handled_Statement_Sequence =>
2224 Handled_Statement_Sequence (N)),
2226 Make_Procedure_Call_Statement (Loc,
2228 Parameter_Associations => New_List (
2229 Make_Attribute_Reference (Loc,
2231 Make_Selected_Component (Loc,
2233 Make_Identifier (Loc, Name_uObject),
2236 Make_Identifier (Loc, Name_uObject)),
2237 Attribute_Name => Name_Unchecked_Access))));
2239 if Restriction_Active (No_Exception_Handlers) then
2241 Make_Subprogram_Body (Loc,
2242 Specification => Espec,
2243 Declarations => Op_Decls,
2244 Handled_Statement_Sequence =>
2245 Make_Handled_Sequence_Of_Statements (Loc, Op_Stats));
2248 Ohandle := Make_Others_Choice (Loc);
2249 Set_All_Others (Ohandle);
2252 or else Restriction_Active (No_Entry_Queue) = False
2253 or else Number_Entries (Pid) > 1
2256 New_Reference_To (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2259 Complete := New_Reference_To (
2260 RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2263 -- Create body of entry procedure. The renaming declarations are
2264 -- placed ahead of the block that contains the actual entry body.
2267 Make_Subprogram_Body (Loc,
2268 Specification => Espec,
2269 Declarations => Op_Decls,
2270 Handled_Statement_Sequence =>
2271 Make_Handled_Sequence_Of_Statements (Loc,
2272 Statements => Op_Stats,
2273 Exception_Handlers => New_List (
2274 Make_Exception_Handler (Loc,
2275 Exception_Choices => New_List (Ohandle),
2277 Statements => New_List (
2278 Make_Procedure_Call_Statement (Loc,
2280 Parameter_Associations => New_List (
2281 Make_Attribute_Reference (Loc,
2283 Make_Selected_Component (Loc,
2285 Make_Identifier (Loc, Name_uObject),
2287 Make_Identifier (Loc, Name_uObject)),
2288 Attribute_Name => Name_Unchecked_Access),
2290 Make_Function_Call (Loc,
2291 Name => New_Reference_To (
2292 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2294 end Build_Protected_Entry;
2296 -----------------------------------------
2297 -- Build_Protected_Entry_Specification --
2298 -----------------------------------------
2300 function Build_Protected_Entry_Specification
2301 (Def_Id : Entity_Id;
2303 Loc : Source_Ptr) return Node_Id
2308 Set_Needs_Debug_Info (Def_Id);
2309 P := Make_Defining_Identifier (Loc, Name_uP);
2311 if Present (Ent_Id) then
2312 Append_Elmt (P, Accept_Address (Ent_Id));
2315 return Make_Procedure_Specification (Loc,
2316 Defining_Unit_Name => Def_Id,
2317 Parameter_Specifications => New_List (
2318 Make_Parameter_Specification (Loc,
2319 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2321 New_Reference_To (RTE (RE_Address), Loc)),
2323 Make_Parameter_Specification (Loc,
2324 Defining_Identifier => P,
2326 New_Reference_To (RTE (RE_Address), Loc)),
2328 Make_Parameter_Specification (Loc,
2329 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE),
2331 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2332 end Build_Protected_Entry_Specification;
2334 --------------------------
2335 -- Build_Protected_Spec --
2336 --------------------------
2338 function Build_Protected_Spec
2340 Obj_Type : Entity_Id;
2341 Unprotected : Boolean := False;
2342 Ident : Entity_Id) return List_Id
2344 Loc : constant Source_Ptr := Sloc (N);
2347 New_Plist : List_Id;
2348 New_Param : Node_Id;
2351 New_Plist := New_List;
2352 Formal := First_Formal (Ident);
2353 while Present (Formal) loop
2355 Make_Parameter_Specification (Loc,
2356 Defining_Identifier =>
2357 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2358 In_Present => In_Present (Parent (Formal)),
2359 Out_Present => Out_Present (Parent (Formal)),
2361 New_Reference_To (Etype (Formal), Loc));
2364 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2367 Append (New_Param, New_Plist);
2368 Next_Formal (Formal);
2371 -- If the subprogram is a procedure and the context is not an access
2372 -- to protected subprogram, the parameter is in-out. Otherwise it is
2376 Make_Parameter_Specification (Loc,
2377 Defining_Identifier =>
2378 Make_Defining_Identifier (Loc, Name_uObject),
2381 (Etype (Ident) = Standard_Void_Type
2382 and then not Is_RTE (Obj_Type, RE_Address)),
2383 Parameter_Type => New_Reference_To (Obj_Type, Loc));
2384 Set_Needs_Debug_Info (Defining_Identifier (Decl));
2385 Prepend_To (New_Plist, Decl);
2388 end Build_Protected_Spec;
2390 ---------------------------------------
2391 -- Build_Protected_Sub_Specification --
2392 ---------------------------------------
2394 function Build_Protected_Sub_Specification
2396 Prottyp : Entity_Id;
2397 Mode : Subprogram_Protection_Mode) return Node_Id
2399 Loc : constant Source_Ptr := Sloc (N);
2403 New_Plist : List_Id;
2406 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2407 (Dispatching_Mode => ' ',
2408 Protected_Mode => 'P',
2409 Unprotected_Mode => 'N');
2413 (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body
2415 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2420 Ident := Defining_Unit_Name (Specification (Decl));
2423 Build_Protected_Spec (Decl,
2424 Corresponding_Record_Type (Prottyp),
2425 Mode = Unprotected_Mode, Ident);
2428 Make_Defining_Identifier (Loc,
2429 Chars => Build_Selected_Name (Prottyp, Ident, Append_Chr (Mode)));
2431 -- The unprotected operation carries the user code, and debugging
2432 -- information must be generated for it, even though this spec does
2433 -- not come from source. It is also convenient to allow gdb to step
2434 -- into the protected operation, even though it only contains lock/
2437 Set_Needs_Debug_Info (New_Id);
2439 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2441 Make_Procedure_Specification (Loc,
2442 Defining_Unit_Name => New_Id,
2443 Parameter_Specifications => New_Plist);
2447 Make_Function_Specification (Loc,
2448 Defining_Unit_Name => New_Id,
2449 Parameter_Specifications => New_Plist,
2450 Result_Definition =>
2451 New_Copy (Result_Definition (Specification (Decl))));
2452 Set_Return_Present (Defining_Unit_Name (New_Spec));
2455 end Build_Protected_Sub_Specification;
2457 -------------------------------------
2458 -- Build_Protected_Subprogram_Body --
2459 -------------------------------------
2461 function Build_Protected_Subprogram_Body
2464 N_Op_Spec : Node_Id) return Node_Id
2466 Loc : constant Source_Ptr := Sloc (N);
2468 P_Op_Spec : Node_Id;
2471 Unprot_Call : Node_Id;
2473 Lock_Name : Node_Id;
2474 Lock_Stmt : Node_Id;
2475 Service_Name : Node_Id;
2477 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2478 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2480 Object_Parm : Node_Id;
2483 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2484 -- Tell whether a given subprogram cannot raise an exception
2486 -----------------------
2487 -- Is_Exception_Safe --
2488 -----------------------
2490 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2492 function Has_Side_Effect (N : Node_Id) return Boolean;
2493 -- Return True whenever encountering a subprogram call or raise
2494 -- statement of any kind in the sequence of statements
2496 ---------------------
2497 -- Has_Side_Effect --
2498 ---------------------
2500 -- What is this doing buried two levels down in exp_ch9. It seems
2501 -- like a generally useful function, and indeed there may be code
2502 -- duplication going on here ???
2504 function Has_Side_Effect (N : Node_Id) return Boolean is
2508 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
2509 -- Indicate whether N is a subprogram call or a raise statement
2511 ----------------------
2512 -- Is_Call_Or_Raise --
2513 ----------------------
2515 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
2517 return Nkind (N) = N_Procedure_Call_Statement
2518 or else Nkind (N) = N_Function_Call
2519 or else Nkind (N) = N_Raise_Statement
2520 or else Nkind (N) = N_Raise_Constraint_Error
2521 or else Nkind (N) = N_Raise_Program_Error
2522 or else Nkind (N) = N_Raise_Storage_Error;
2523 end Is_Call_Or_Raise;
2525 -- Start of processing for Has_Side_Effect
2529 while Present (Stmt) loop
2530 if Is_Call_Or_Raise (Stmt) then
2534 -- An object declaration can also contain a function call
2535 -- or a raise statement
2537 if Nkind (Stmt) = N_Object_Declaration then
2538 Expr := Expression (Stmt);
2540 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
2549 end Has_Side_Effect;
2551 -- Start of processing for Is_Exception_Safe
2554 -- If the checks handled by the back end are not disabled, we cannot
2555 -- ensure that no exception will be raised.
2557 if not Access_Checks_Suppressed (Empty)
2558 or else not Discriminant_Checks_Suppressed (Empty)
2559 or else not Range_Checks_Suppressed (Empty)
2560 or else not Index_Checks_Suppressed (Empty)
2561 or else Opt.Stack_Checking_Enabled
2566 if Has_Side_Effect (First (Declarations (Subprogram)))
2569 First (Statements (Handled_Statement_Sequence (Subprogram))))
2575 end Is_Exception_Safe;
2577 -- Start of processing for Build_Protected_Subprogram_Body
2580 Op_Spec := Specification (N);
2581 Exc_Safe := Is_Exception_Safe (N);
2584 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
2586 -- Build a list of the formal parameters of the protected version of
2587 -- the subprogram to use as the actual parameters of the unprotected
2590 Uactuals := New_List;
2591 Pformal := First (Parameter_Specifications (P_Op_Spec));
2592 while Present (Pformal) loop
2594 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
2599 -- Make a call to the unprotected version of the subprogram built above
2600 -- for use by the protected version built below.
2602 if Nkind (Op_Spec) = N_Function_Specification then
2604 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2606 Make_Object_Declaration (Loc,
2607 Defining_Identifier => R,
2608 Constant_Present => True,
2609 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
2611 Make_Function_Call (Loc,
2612 Name => Make_Identifier (Loc,
2613 Chars (Defining_Unit_Name (N_Op_Spec))),
2614 Parameter_Associations => Uactuals));
2615 Return_Stmt := Make_Return_Statement (Loc,
2616 Expression => New_Reference_To (R, Loc));
2619 Unprot_Call := Make_Return_Statement (Loc,
2620 Expression => Make_Function_Call (Loc,
2622 Make_Identifier (Loc,
2623 Chars (Defining_Unit_Name (N_Op_Spec))),
2624 Parameter_Associations => Uactuals));
2628 Unprot_Call := Make_Procedure_Call_Statement (Loc,
2630 Make_Identifier (Loc,
2631 Chars (Defining_Unit_Name (N_Op_Spec))),
2632 Parameter_Associations => Uactuals);
2635 -- Wrap call in block that will be covered by an at_end handler
2637 if not Exc_Safe then
2638 Unprot_Call := Make_Block_Statement (Loc,
2639 Handled_Statement_Sequence =>
2640 Make_Handled_Sequence_Of_Statements (Loc,
2641 Statements => New_List (Unprot_Call)));
2644 -- Make the protected subprogram body. This locks the protected
2645 -- object and calls the unprotected version of the subprogram.
2647 -- If the protected object is controlled (i.e it has entries or
2648 -- needs finalization for interrupt handling), call Lock_Entries,
2649 -- except if the protected object follows the Ravenscar profile, in
2650 -- which case call Lock_Entry, otherwise call the simplified version,
2653 if Has_Entries (Pid)
2654 or else Has_Interrupt_Handler (Pid)
2655 or else (Has_Attach_Handler (Pid)
2656 and then not Restricted_Profile)
2657 or else (Ada_Version >= Ada_05
2658 and then Present (Interface_List (Parent (Pid))))
2661 or else Restriction_Active (No_Entry_Queue) = False
2662 or else Number_Entries (Pid) > 1
2664 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
2665 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
2668 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
2669 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
2673 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
2674 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
2678 Make_Attribute_Reference (Loc,
2680 Make_Selected_Component (Loc,
2682 Make_Identifier (Loc, Name_uObject),
2684 Make_Identifier (Loc, Name_uObject)),
2685 Attribute_Name => Name_Unchecked_Access);
2687 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
2689 Parameter_Associations => New_List (Object_Parm));
2691 if Abort_Allowed then
2693 Make_Procedure_Call_Statement (Loc,
2694 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
2695 Parameter_Associations => Empty_List),
2699 Stmts := New_List (Lock_Stmt);
2702 if not Exc_Safe then
2703 Append (Unprot_Call, Stmts);
2705 if Nkind (Op_Spec) = N_Function_Specification then
2707 Stmts := Empty_List;
2709 Append (Unprot_Call, Stmts);
2713 Make_Procedure_Call_Statement (Loc,
2714 Name => Service_Name,
2715 Parameter_Associations =>
2716 New_List (New_Copy_Tree (Object_Parm))),
2719 if Abort_Allowed then
2721 Make_Procedure_Call_Statement (Loc,
2722 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
2723 Parameter_Associations => Empty_List),
2727 if Nkind (Op_Spec) = N_Function_Specification then
2728 Append (Return_Stmt, Stmts);
2729 Append (Make_Block_Statement (Loc,
2730 Declarations => New_List (Unprot_Call),
2731 Handled_Statement_Sequence =>
2732 Make_Handled_Sequence_Of_Statements (Loc,
2733 Statements => Stmts)), Pre_Stmts);
2739 Make_Subprogram_Body (Loc,
2740 Declarations => Empty_List,
2741 Specification => P_Op_Spec,
2742 Handled_Statement_Sequence =>
2743 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
2745 if not Exc_Safe then
2746 Set_Is_Protected_Subprogram_Body (Sub_Body);
2750 end Build_Protected_Subprogram_Body;
2752 -------------------------------------
2753 -- Build_Protected_Subprogram_Call --
2754 -------------------------------------
2756 procedure Build_Protected_Subprogram_Call
2760 External : Boolean := True)
2762 Loc : constant Source_Ptr := Sloc (N);
2763 Sub : constant Entity_Id := Entity (Name);
2769 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
2772 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
2775 if Present (Parameter_Associations (N)) then
2776 Params := New_Copy_List_Tree (Parameter_Associations (N));
2781 Prepend (Rec, Params);
2783 if Ekind (Sub) = E_Procedure then
2785 Make_Procedure_Call_Statement (Loc,
2787 Parameter_Associations => Params));
2790 pragma Assert (Ekind (Sub) = E_Function);
2792 Make_Function_Call (Loc,
2794 Parameter_Associations => Params));
2798 and then Nkind (Rec) = N_Unchecked_Type_Conversion
2799 and then Is_Entity_Name (Expression (Rec))
2800 and then Is_Shared_Passive (Entity (Expression (Rec)))
2802 Add_Shared_Var_Lock_Procs (N);
2804 end Build_Protected_Subprogram_Call;
2806 -------------------------
2807 -- Build_Selected_Name --
2808 -------------------------
2810 function Build_Selected_Name
2811 (Prefix : Entity_Id;
2812 Selector : Entity_Id;
2813 Append_Char : Character := ' ') return Name_Id
2815 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
2816 Select_Len : Natural;
2819 Get_Name_String (Chars (Selector));
2820 Select_Len := Name_Len;
2821 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
2822 Get_Name_String (Chars (Prefix));
2824 -- If scope is anonymous type, discard suffix to recover name of
2825 -- single protected object. Otherwise use protected type name.
2827 if Name_Buffer (Name_Len) = 'T' then
2828 Name_Len := Name_Len - 1;
2831 Name_Buffer (Name_Len + 1) := '_';
2832 Name_Buffer (Name_Len + 2) := '_';
2834 Name_Len := Name_Len + 2;
2835 for J in 1 .. Select_Len loop
2836 Name_Len := Name_Len + 1;
2837 Name_Buffer (Name_Len) := Select_Buffer (J);
2840 -- Now add the Append_Char if specified. The encoding to follow
2841 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
2842 -- then the entity is associated to a protected type subprogram.
2843 -- Otherwise, it is a protected type entry. For each case, the
2844 -- encoding to follow for the suffix is documented in exp_dbug.ads.
2846 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
2848 if Append_Char /= ' ' then
2849 if Append_Char = 'P' or Append_Char = 'N' then
2850 Name_Len := Name_Len + 1;
2851 Name_Buffer (Name_Len) := Append_Char;
2854 Name_Buffer (Name_Len + 1) := '_';
2855 Name_Buffer (Name_Len + 2) := Append_Char;
2856 Name_Len := Name_Len + 2;
2857 return New_External_Name (Name_Find, ' ', -1);
2862 end Build_Selected_Name;
2864 -----------------------------
2865 -- Build_Simple_Entry_Call --
2866 -----------------------------
2868 -- A task entry call is converted to a call to Call_Simple
2871 -- P : parms := (parm, parm, parm);
2873 -- Call_Simple (acceptor-task, entry-index, P'Address);
2879 -- Here Pnn is an aggregate of the type constructed for the entry to hold
2880 -- the parameters, and the constructed aggregate value contains either the
2881 -- parameters or, in the case of non-elementary types, references to these
2882 -- parameters. Then the address of this aggregate is passed to the runtime
2883 -- routine, along with the task id value and the task entry index value.
2884 -- Pnn is only required if parameters are present.
2886 -- The assignments after the call are present only in the case of in-out
2887 -- or out parameters for elementary types, and are used to assign back the
2888 -- resulting values of such parameters.
2890 -- Note: the reason that we insert a block here is that in the context
2891 -- of selects, conditional entry calls etc. the entry call statement
2892 -- appears on its own, not as an element of a list.
2894 -- A protected entry call is converted to a Protected_Entry_Call:
2897 -- P : E1_Params := (param, param, param);
2899 -- Bnn : Communications_Block;
2902 -- P : E1_Params := (param, param, param);
2903 -- Bnn : Communications_Block;
2906 -- Protected_Entry_Call (
2907 -- Object => po._object'Access,
2908 -- E => <entry index>;
2909 -- Uninterpreted_Data => P'Address;
2910 -- Mode => Simple_Call;
2917 procedure Build_Simple_Entry_Call
2926 -- Convert entry call to Call_Simple call
2929 Loc : constant Source_Ptr := Sloc (N);
2930 Parms : constant List_Id := Parameter_Associations (N);
2931 Stats : constant List_Id := New_List;
2934 Comm_Name : Entity_Id;
2938 Ent_Acc : Entity_Id;
2940 Iface_Tag : Entity_Id;
2941 Iface_Typ : Entity_Id;
2954 -- Simple entry and entry family cases merge here
2956 Ent := Entity (Ename);
2957 Ent_Acc := Entry_Parameters_Type (Ent);
2958 Conctyp := Etype (Concval);
2960 -- If prefix is an access type, dereference to obtain the task type
2962 if Is_Access_Type (Conctyp) then
2963 Conctyp := Designated_Type (Conctyp);
2966 -- Special case for protected subprogram calls
2968 if Is_Protected_Type (Conctyp)
2969 and then Is_Subprogram (Entity (Ename))
2971 if not Is_Eliminated (Entity (Ename)) then
2972 Build_Protected_Subprogram_Call
2973 (N, Ename, Convert_Concurrent (Concval, Conctyp));
2980 -- First parameter is the Task_Id value from the task value or the
2981 -- Object from the protected object value, obtained by selecting
2982 -- the _Task_Id or _Object from the result of doing an unchecked
2983 -- conversion to convert the value to the corresponding record type.
2985 Parm1 := Concurrent_Ref (Concval);
2987 -- Second parameter is the entry index, computed by the routine
2988 -- provided for this purpose. The value of this expression is
2989 -- assigned to an intermediate variable to assure that any entry
2990 -- family index expressions are evaluated before the entry
2994 or else Restriction_Active (No_Entry_Queue) = False
2995 or else not Is_Protected_Type (Conctyp)
2996 or else Number_Entries (Conctyp) > 1
2998 X := Make_Defining_Identifier (Loc, Name_uX);
3001 Make_Object_Declaration (Loc,
3002 Defining_Identifier => X,
3003 Object_Definition =>
3004 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3005 Expression => Actual_Index_Expression (
3006 Loc, Entity (Ename), Index, Concval));
3008 Decls := New_List (Xdecl);
3009 Parm2 := New_Reference_To (X, Loc);
3017 -- The third parameter is the packaged parameters. If there are
3018 -- none, then it is just the null address, since nothing is passed.
3021 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3024 -- Case of parameters present, where third argument is the address
3025 -- of a packaged record containing the required parameter values.
3028 -- First build a list of parameter values, which are references to
3029 -- objects of the parameter types.
3033 Actual := First_Actual (N);
3034 Formal := First_Formal (Ent);
3036 while Present (Actual) loop
3038 -- If it is a by_copy_type, copy it to a new variable. The
3039 -- packaged record has a field that points to this variable.
3041 if Is_By_Copy_Type (Etype (Actual)) then
3043 Make_Object_Declaration (Loc,
3044 Defining_Identifier =>
3045 Make_Defining_Identifier (Loc,
3046 Chars => New_Internal_Name ('J')),
3047 Aliased_Present => True,
3048 Object_Definition =>
3049 New_Reference_To (Etype (Formal), Loc));
3051 -- We have to make an assignment statement separate for the
3052 -- case of limited type. We cannot assign it unless the
3053 -- Assignment_OK flag is set first.
3055 if Ekind (Formal) /= E_Out_Parameter then
3057 New_Reference_To (Defining_Identifier (N_Node), Loc);
3058 Set_Assignment_OK (N_Var);
3060 Make_Assignment_Statement (Loc,
3062 Expression => Relocate_Node (Actual)));
3065 Append (N_Node, Decls);
3068 Make_Attribute_Reference (Loc,
3069 Attribute_Name => Name_Unchecked_Access,
3071 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3073 -- Interface class-wide formal
3075 if Ada_Version >= Ada_05
3076 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3077 and then Is_Interface (Etype (Formal))
3079 Iface_Typ := Etype (Etype (Formal));
3082 -- formal_iface_type! (actual.iface_tag)'reference
3085 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3086 pragma Assert (Present (Iface_Tag));
3089 Make_Reference (Loc,
3090 Unchecked_Convert_To (Iface_Typ,
3091 Make_Selected_Component (Loc,
3093 Relocate_Node (Actual),
3095 New_Reference_To (Iface_Tag, Loc)))));
3101 Make_Reference (Loc, Relocate_Node (Actual)));
3105 Next_Actual (Actual);
3106 Next_Formal_With_Extras (Formal);
3109 -- Now build the declaration of parameters initialized with the
3110 -- aggregate containing this constructed parameter list.
3112 P := Make_Defining_Identifier (Loc, Name_uP);
3115 Make_Object_Declaration (Loc,
3116 Defining_Identifier => P,
3117 Object_Definition =>
3118 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3120 Make_Aggregate (Loc, Expressions => Plist));
3123 Make_Attribute_Reference (Loc,
3124 Attribute_Name => Name_Address,
3125 Prefix => New_Reference_To (P, Loc));
3127 Append (Pdecl, Decls);
3130 -- Now we can create the call, case of protected type
3132 if Is_Protected_Type (Conctyp) then
3134 or else Restriction_Active (No_Entry_Queue) = False
3135 or else Number_Entries (Conctyp) > 1
3137 -- Change the type of the index declaration
3139 Set_Object_Definition (Xdecl,
3140 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3142 -- Some additional declarations for protected entry calls
3148 -- Bnn : Communications_Block;
3151 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3154 Make_Object_Declaration (Loc,
3155 Defining_Identifier => Comm_Name,
3156 Object_Definition =>
3157 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3159 -- Some additional statements for protected entry calls
3161 -- Protected_Entry_Call (
3162 -- Object => po._object'Access,
3163 -- E => <entry index>;
3164 -- Uninterpreted_Data => P'Address;
3165 -- Mode => Simple_Call;
3169 Make_Procedure_Call_Statement (Loc,
3171 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3173 Parameter_Associations => New_List (
3174 Make_Attribute_Reference (Loc,
3175 Attribute_Name => Name_Unchecked_Access,
3179 New_Reference_To (RTE (RE_Simple_Call), Loc),
3180 New_Occurrence_Of (Comm_Name, Loc)));
3183 -- Protected_Single_Entry_Call (
3184 -- Object => po._object'Access,
3185 -- Uninterpreted_Data => P'Address;
3186 -- Mode => Simple_Call);
3189 Make_Procedure_Call_Statement (Loc,
3190 Name => New_Reference_To (
3191 RTE (RE_Protected_Single_Entry_Call), Loc),
3193 Parameter_Associations => New_List (
3194 Make_Attribute_Reference (Loc,
3195 Attribute_Name => Name_Unchecked_Access,
3198 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3201 -- Case of task type
3205 Make_Procedure_Call_Statement (Loc,
3206 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3207 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3211 Append_To (Stats, Call);
3213 -- If there are out or in/out parameters by copy add assignment
3214 -- statements for the result values.
3216 if Present (Parms) then
3217 Actual := First_Actual (N);
3218 Formal := First_Formal (Ent);
3220 Set_Assignment_OK (Actual);
3221 while Present (Actual) loop
3222 if Is_By_Copy_Type (Etype (Actual))
3223 and then Ekind (Formal) /= E_In_Parameter
3226 Make_Assignment_Statement (Loc,
3227 Name => New_Copy (Actual),
3229 Make_Explicit_Dereference (Loc,
3230 Make_Selected_Component (Loc,
3231 Prefix => New_Reference_To (P, Loc),
3233 Make_Identifier (Loc, Chars (Formal)))));
3235 -- In all cases (including limited private types) we want
3236 -- the assignment to be valid.
3238 Set_Assignment_OK (Name (N_Node));
3240 -- If the call is the triggering alternative in an
3241 -- asynchronous select, or the entry_call alternative of a
3242 -- conditional entry call, the assignments for in-out
3243 -- parameters are incorporated into the statement list that
3244 -- follows, so that there are executed only if the entry
3247 if (Nkind (Parent (N)) = N_Triggering_Alternative
3248 and then N = Triggering_Statement (Parent (N)))
3250 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3251 and then N = Entry_Call_Statement (Parent (N)))
3253 if No (Statements (Parent (N))) then
3254 Set_Statements (Parent (N), New_List);
3257 Prepend (N_Node, Statements (Parent (N)));
3260 Insert_After (Call, N_Node);
3264 Next_Actual (Actual);
3265 Next_Formal_With_Extras (Formal);
3269 -- Finally, create block and analyze it
3272 Make_Block_Statement (Loc,
3273 Declarations => Decls,
3274 Handled_Statement_Sequence =>
3275 Make_Handled_Sequence_Of_Statements (Loc,
3276 Statements => Stats)));
3280 end Build_Simple_Entry_Call;
3282 --------------------------------
3283 -- Build_Task_Activation_Call --
3284 --------------------------------
3286 procedure Build_Task_Activation_Call (N : Node_Id) is
3287 Loc : constant Source_Ptr := Sloc (N);
3294 -- Get the activation chain entity. Except in the case of a package
3295 -- body, this is in the node that w as passed. For a package body, we
3296 -- have to find the corresponding package declaration node.
3298 if Nkind (N) = N_Package_Body then
3299 P := Corresponding_Spec (N);
3303 exit when Nkind (P) = N_Package_Declaration;
3306 Chain := Activation_Chain_Entity (P);
3309 Chain := Activation_Chain_Entity (N);
3312 if Present (Chain) then
3313 if Restricted_Profile then
3314 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3316 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3320 Make_Procedure_Call_Statement (Loc,
3322 Parameter_Associations =>
3323 New_List (Make_Attribute_Reference (Loc,
3324 Prefix => New_Occurrence_Of (Chain, Loc),
3325 Attribute_Name => Name_Unchecked_Access)));
3327 if Nkind (N) = N_Package_Declaration then
3328 if Present (Corresponding_Body (N)) then
3331 elsif Present (Private_Declarations (Specification (N))) then
3332 Append (Call, Private_Declarations (Specification (N)));
3335 Append (Call, Visible_Declarations (Specification (N)));
3339 if Present (Handled_Statement_Sequence (N)) then
3341 -- The call goes at the start of the statement sequence, but
3342 -- after the start of exception range label if one is present.
3348 Stm := First (Statements (Handled_Statement_Sequence (N)));
3350 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3354 Insert_Before (Stm, Call);
3358 Set_Handled_Statement_Sequence (N,
3359 Make_Handled_Sequence_Of_Statements (Loc,
3360 Statements => New_List (Call)));
3365 Check_Task_Activation (N);
3367 end Build_Task_Activation_Call;
3369 -------------------------------
3370 -- Build_Task_Allocate_Block --
3371 -------------------------------
3373 procedure Build_Task_Allocate_Block
3378 T : constant Entity_Id := Entity (Expression (N));
3379 Init : constant Entity_Id := Base_Init_Proc (T);
3380 Loc : constant Source_Ptr := Sloc (N);
3381 Chain : constant Entity_Id :=
3382 Make_Defining_Identifier (Loc, Name_uChain);
3388 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3391 Make_Block_Statement (Loc,
3392 Identifier => New_Reference_To (Blkent, Loc),
3393 Declarations => New_List (
3395 -- _Chain : Activation_Chain;
3397 Make_Object_Declaration (Loc,
3398 Defining_Identifier => Chain,
3399 Aliased_Present => True,
3400 Object_Definition =>
3401 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3403 Handled_Statement_Sequence =>
3404 Make_Handled_Sequence_Of_Statements (Loc,
3406 Statements => New_List (
3410 Make_Procedure_Call_Statement (Loc,
3411 Name => New_Reference_To (Init, Loc),
3412 Parameter_Associations => Args),
3414 -- Activate_Tasks (_Chain);
3416 Make_Procedure_Call_Statement (Loc,
3417 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3418 Parameter_Associations => New_List (
3419 Make_Attribute_Reference (Loc,
3420 Prefix => New_Reference_To (Chain, Loc),
3421 Attribute_Name => Name_Unchecked_Access))))),
3423 Has_Created_Identifier => True,
3424 Is_Task_Allocation_Block => True);
3427 Make_Implicit_Label_Declaration (Loc,
3428 Defining_Identifier => Blkent,
3429 Label_Construct => Block));
3431 Append_To (Actions, Block);
3433 Set_Activation_Chain_Entity (Block, Chain);
3434 end Build_Task_Allocate_Block;
3436 -----------------------------------------------
3437 -- Build_Task_Allocate_Block_With_Init_Stmts --
3438 -----------------------------------------------
3440 procedure Build_Task_Allocate_Block_With_Init_Stmts
3443 Init_Stmts : List_Id)
3445 Loc : constant Source_Ptr := Sloc (N);
3446 Chain : constant Entity_Id :=
3447 Make_Defining_Identifier (Loc, Name_uChain);
3452 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3454 Append_To (Init_Stmts,
3455 Make_Procedure_Call_Statement (Loc,
3456 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3457 Parameter_Associations => New_List (
3458 Make_Attribute_Reference (Loc,
3459 Prefix => New_Reference_To (Chain, Loc),
3460 Attribute_Name => Name_Unchecked_Access))));
3463 Make_Block_Statement (Loc,
3464 Identifier => New_Reference_To (Blkent, Loc),
3465 Declarations => New_List (
3467 -- _Chain : Activation_Chain;
3469 Make_Object_Declaration (Loc,
3470 Defining_Identifier => Chain,
3471 Aliased_Present => True,
3472 Object_Definition =>
3473 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3475 Handled_Statement_Sequence =>
3476 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
3478 Has_Created_Identifier => True,
3479 Is_Task_Allocation_Block => True);
3482 Make_Implicit_Label_Declaration (Loc,
3483 Defining_Identifier => Blkent,
3484 Label_Construct => Block));
3486 Append_To (Actions, Block);
3488 Set_Activation_Chain_Entity (Block, Chain);
3489 end Build_Task_Allocate_Block_With_Init_Stmts;
3491 -----------------------------------
3492 -- Build_Task_Proc_Specification --
3493 -----------------------------------
3495 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
3496 Loc : constant Source_Ptr := Sloc (T);
3497 Nam : constant Name_Id := Chars (T);
3502 Make_Defining_Identifier (Loc,
3503 Chars => New_External_Name (Nam, 'B'));
3504 Set_Is_Internal (Ent);
3506 -- Associate the procedure with the task, if this is the declaration
3507 -- (and not the body) of the procedure.
3509 if No (Task_Body_Procedure (T)) then
3510 Set_Task_Body_Procedure (T, Ent);
3514 Make_Procedure_Specification (Loc,
3515 Defining_Unit_Name => Ent,
3516 Parameter_Specifications =>
3518 Make_Parameter_Specification (Loc,
3519 Defining_Identifier =>
3520 Make_Defining_Identifier (Loc, Name_uTask),
3522 Make_Access_Definition (Loc,
3525 (Corresponding_Record_Type (T), Loc)))));
3526 end Build_Task_Proc_Specification;
3528 ---------------------------------------
3529 -- Build_Unprotected_Subprogram_Body --
3530 ---------------------------------------
3532 function Build_Unprotected_Subprogram_Body
3534 Pid : Node_Id) return Node_Id
3536 Loc : constant Source_Ptr := Sloc (N);
3537 N_Op_Spec : Node_Id;
3541 -- Make an unprotected version of the subprogram for use within the same
3542 -- object, with a new name and an additional parameter representing the
3545 Op_Decls := Declarations (N);
3547 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode);
3550 Make_Subprogram_Body (Loc,
3551 Specification => N_Op_Spec,
3552 Declarations => Op_Decls,
3553 Handled_Statement_Sequence =>
3554 Handled_Statement_Sequence (N));
3555 end Build_Unprotected_Subprogram_Body;
3557 ----------------------------
3558 -- Collect_Entry_Families --
3559 ----------------------------
3561 procedure Collect_Entry_Families
3564 Current_Node : in out Node_Id;
3565 Conctyp : Entity_Id)
3568 Efam_Decl : Node_Id;
3569 Efam_Type : Entity_Id;
3572 Efam := First_Entity (Conctyp);
3574 while Present (Efam) loop
3576 if Ekind (Efam) = E_Entry_Family then
3578 Make_Defining_Identifier (Loc,
3579 Chars => New_Internal_Name ('F'));
3584 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
3585 Bas_Decl : Node_Id := Empty;
3590 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
3591 if Scope (Bas) = Standard_Standard
3592 and then Bas = Base_Type (Standard_Integer)
3593 and then Has_Discriminants (Conctyp)
3595 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
3597 (Denotes_Discriminant (Lo, True)
3598 or else Denotes_Discriminant (Hi, True))
3601 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3603 Make_Subtype_Declaration (Loc,
3604 Defining_Identifier => Bas,
3605 Subtype_Indication =>
3606 Make_Subtype_Indication (Loc,
3608 New_Occurrence_Of (Standard_Integer, Loc),
3610 Make_Range_Constraint (Loc,
3611 Range_Expression => Make_Range (Loc,
3612 Make_Integer_Literal
3613 (Loc, -Entry_Family_Bound),
3614 Make_Integer_Literal
3615 (Loc, Entry_Family_Bound - 1)))));
3617 Insert_After (Current_Node, Bas_Decl);
3618 Current_Node := Bas_Decl;
3623 Make_Full_Type_Declaration (Loc,
3624 Defining_Identifier => Efam_Type,
3626 Make_Unconstrained_Array_Definition (Loc,
3628 (New_List (New_Occurrence_Of (Bas, Loc))),
3630 Component_Definition =>
3631 Make_Component_Definition (Loc,
3632 Aliased_Present => False,
3633 Subtype_Indication =>
3634 New_Reference_To (Standard_Character, Loc))));
3637 Insert_After (Current_Node, Efam_Decl);
3638 Current_Node := Efam_Decl;
3639 Analyze (Efam_Decl);
3642 Make_Component_Declaration (Loc,
3643 Defining_Identifier =>
3644 Make_Defining_Identifier (Loc, Chars (Efam)),
3646 Component_Definition =>
3647 Make_Component_Definition (Loc,
3648 Aliased_Present => False,
3649 Subtype_Indication =>
3650 Make_Subtype_Indication (Loc,
3652 New_Occurrence_Of (Efam_Type, Loc),
3655 Make_Index_Or_Discriminant_Constraint (Loc,
3656 Constraints => New_List (
3658 (Etype (Discrete_Subtype_Definition
3659 (Parent (Efam))), Loc)))))));
3665 end Collect_Entry_Families;
3667 --------------------
3668 -- Concurrent_Ref --
3669 --------------------
3671 -- The expression returned for a reference to a concurrent object has the
3674 -- taskV!(name)._Task_Id
3678 -- objectV!(name)._Object
3680 -- for a protected object. For the case of an access to a concurrent
3681 -- object, there is an extra explicit dereference:
3683 -- taskV!(name.all)._Task_Id
3684 -- objectV!(name.all)._Object
3686 -- here taskV and objectV are the types for the associated records, which
3687 -- contain the required _Task_Id and _Object fields for tasks and protected
3688 -- objects, respectively.
3690 -- For the case of a task type name, the expression is
3694 -- i.e. a call to the Self function which returns precisely this Task_Id
3696 -- For the case of a protected type name, the expression is
3700 -- which is a renaming of the _object field of the current object object
3701 -- record, passed into protected operations as a parameter.
3703 function Concurrent_Ref (N : Node_Id) return Node_Id is
3704 Loc : constant Source_Ptr := Sloc (N);
3705 Ntyp : constant Entity_Id := Etype (N);
3709 function Is_Current_Task (T : Entity_Id) return Boolean;
3710 -- Check whether the reference is to the immediately enclosing task
3711 -- type, or to an outer one (rare but legal).
3713 ---------------------
3714 -- Is_Current_Task --
3715 ---------------------
3717 function Is_Current_Task (T : Entity_Id) return Boolean is
3721 Scop := Current_Scope;
3722 while Present (Scop)
3723 and then Scop /= Standard_Standard
3729 elsif Is_Task_Type (Scop) then
3732 -- If this is a procedure nested within the task type, we must
3733 -- assume that it can be called from an inner task, and therefore
3734 -- cannot treat it as a local reference.
3736 elsif Is_Overloadable (Scop)
3737 and then In_Open_Scopes (T)
3742 Scop := Scope (Scop);
3746 -- We know that we are within the task body, so should have found it
3749 raise Program_Error;
3750 end Is_Current_Task;
3752 -- Start of processing for Concurrent_Ref
3755 if Is_Access_Type (Ntyp) then
3756 Dtyp := Designated_Type (Ntyp);
3758 if Is_Protected_Type (Dtyp) then
3759 Sel := Name_uObject;
3761 Sel := Name_uTask_Id;
3765 Make_Selected_Component (Loc,
3767 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
3768 Make_Explicit_Dereference (Loc, N)),
3769 Selector_Name => Make_Identifier (Loc, Sel));
3771 elsif Is_Entity_Name (N)
3772 and then Is_Concurrent_Type (Entity (N))
3774 if Is_Task_Type (Entity (N)) then
3776 if Is_Current_Task (Entity (N)) then
3778 Make_Function_Call (Loc,
3779 Name => New_Reference_To (RTE (RE_Self), Loc));
3784 T_Self : constant Entity_Id :=
3785 Make_Defining_Identifier (Loc,
3786 Chars => New_Internal_Name ('T'));
3787 T_Body : constant Node_Id :=
3788 Parent (Corresponding_Body (Parent (Entity (N))));
3791 Decl := Make_Object_Declaration (Loc,
3792 Defining_Identifier => T_Self,
3793 Object_Definition =>
3794 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
3796 Make_Function_Call (Loc,
3797 Name => New_Reference_To (RTE (RE_Self), Loc)));
3798 Prepend (Decl, Declarations (T_Body));
3800 Set_Scope (T_Self, Entity (N));
3801 return New_Occurrence_Of (T_Self, Loc);
3806 pragma Assert (Is_Protected_Type (Entity (N)));
3809 Object_Ref (Corresponding_Body (Parent (Base_Type (Ntyp)))),
3814 pragma Assert (Is_Concurrent_Type (Ntyp));
3816 if Is_Protected_Type (Ntyp) then
3817 Sel := Name_uObject;
3819 Sel := Name_uTask_Id;
3823 Make_Selected_Component (Loc,
3825 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
3827 Selector_Name => Make_Identifier (Loc, Sel));
3831 ------------------------
3832 -- Convert_Concurrent --
3833 ------------------------
3835 function Convert_Concurrent
3837 Typ : Entity_Id) return Node_Id
3840 if not Is_Concurrent_Type (Typ) then
3844 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
3847 end Convert_Concurrent;
3849 ----------------------------
3850 -- Entry_Index_Expression --
3851 ----------------------------
3853 function Entry_Index_Expression
3857 Ttyp : Entity_Id) return Node_Id
3867 -- The queues of entries and entry families appear in textual order in
3868 -- the associated record. The entry index is computed as the sum of the
3869 -- number of queues for all entries that precede the designated one, to
3870 -- which is added the index expression, if this expression denotes a
3871 -- member of a family.
3873 -- The following is a place holder for the count of simple entries
3875 Num := Make_Integer_Literal (Sloc, 1);
3877 -- We construct an expression which is a series of addition operations.
3878 -- The first operand is the number of single entries that precede this
3879 -- one, the second operand is the index value relative to the start of
3880 -- the referenced family, and the remaining operands are the lengths of
3881 -- the entry families that precede this entry, i.e. the constructed
3884 -- number_simple_entries +
3885 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
3886 -- family'length + ...
3888 -- where index-value is the given index value, and s is the index
3889 -- subtype (we have to use pos because the subtype might be an
3890 -- enumeration type preventing direct subtraction). Note that the task
3891 -- entry array is one-indexed.
3893 -- The upper bound of the entry family may be a discriminant, so we
3894 -- retrieve the lower bound explicitly to compute offset, rather than
3895 -- using the index subtype which may mention a discriminant.
3897 if Present (Index) then
3898 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
3907 Make_Attribute_Reference (Sloc,
3908 Attribute_Name => Name_Pos,
3909 Prefix => New_Reference_To (Base_Type (S), Sloc),
3910 Expressions => New_List (Relocate_Node (Index))),
3917 -- Now add lengths of preceding entries and entry families
3919 Prev := First_Entity (Ttyp);
3921 while Chars (Prev) /= Chars (Ent)
3922 or else (Ekind (Prev) /= Ekind (Ent))
3923 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
3925 if Ekind (Prev) = E_Entry then
3926 Set_Intval (Num, Intval (Num) + 1);
3928 elsif Ekind (Prev) = E_Entry_Family then
3930 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
3931 Lo := Type_Low_Bound (S);
3932 Hi := Type_High_Bound (S);
3937 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp));
3939 -- Other components are anonymous types to be ignored
3949 end Entry_Index_Expression;
3951 ---------------------------
3952 -- Establish_Task_Master --
3953 ---------------------------
3955 procedure Establish_Task_Master (N : Node_Id) is
3958 if Restriction_Active (No_Task_Hierarchy) = False then
3959 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
3960 Prepend_To (Declarations (N), Call);
3963 end Establish_Task_Master;
3965 --------------------------------
3966 -- Expand_Accept_Declarations --
3967 --------------------------------
3969 -- Part of the expansion of an accept statement involves the creation of
3970 -- a declaration that can be referenced from the statement sequence of
3975 -- This declaration is inserted immediately before the accept statement
3976 -- and it is important that it be inserted before the statements of the
3977 -- statement sequence are analyzed. Thus it would be too late to create
3978 -- this declaration in the Expand_N_Accept_Statement routine, which is
3979 -- why there is a separate procedure to be called directly from Sem_Ch9.
3981 -- Ann is used to hold the address of the record containing the parameters
3982 -- (see Expand_N_Entry_Call for more details on how this record is built).
3983 -- References to the parameters do an unchecked conversion of this address
3984 -- to a pointer to the required record type, and then access the field that
3985 -- holds the value of the required parameter. The entity for the address
3986 -- variable is held as the top stack element (i.e. the last element) of the
3987 -- Accept_Address stack in the corresponding entry entity, and this element
3988 -- must be set in place before the statements are processed.
3990 -- The above description applies to the case of a stand alone accept
3991 -- statement, i.e. one not appearing as part of a select alternative.
3993 -- For the case of an accept that appears as part of a select alternative
3994 -- of a selective accept, we must still create the declaration right away,
3995 -- since Ann is needed immediately, but there is an important difference:
3997 -- The declaration is inserted before the selective accept, not before
3998 -- the accept statement (which is not part of a list anyway, and so would
3999 -- not accommodate inserted declarations)
4001 -- We only need one address variable for the entire selective accept. So
4002 -- the Ann declaration is created only for the first accept alternative,
4003 -- and subsequent accept alternatives reference the same Ann variable.
4005 -- We can distinguish the two cases by seeing whether the accept statement
4006 -- is part of a list. If not, then it must be in an accept alternative.
4008 -- To expand the requeue statement, a label is provided at the end of the
4009 -- accept statement or alternative of which it is a part, so that the
4010 -- statement can be skipped after the requeue is complete. This label is
4011 -- created here rather than during the expansion of the accept statement,
4012 -- because it will be needed by any requeue statements within the accept,
4013 -- which are expanded before the accept.
4015 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4016 Loc : constant Source_Ptr := Sloc (N);
4017 Ann : Entity_Id := Empty;
4025 if Expander_Active then
4027 -- If we have no handled statement sequence, then build a dummy
4028 -- sequence consisting of a null statement. This is only done if
4029 -- pragma FIFO_Within_Priorities is specified. The issue here is
4030 -- that even a null accept body has an effect on the called task
4031 -- in terms of its position in the queue, so we cannot optimize
4032 -- the context switch away. However, if FIFO_Within_Priorities
4033 -- is not active, the optimization is legitimate, since we can
4034 -- say that our dispatching policy (i.e. the default dispatching
4035 -- policy) reorders the queue to be the same as just before the
4036 -- call. In the absence of a specified dispatching policy, we are
4037 -- allowed to modify queue orders for a given priority at will!
4039 if Opt.Task_Dispatching_Policy = 'F' and then
4040 not Present (Handled_Statement_Sequence (N))
4042 Set_Handled_Statement_Sequence (N,
4043 Make_Handled_Sequence_Of_Statements (Loc,
4044 New_List (Make_Null_Statement (Loc))));
4047 -- Create and declare two labels to be placed at the end of the
4048 -- accept statement. The first label is used to allow requeues to
4049 -- skip the remainder of entry processing. The second label is used
4050 -- to skip the remainder of entry processing if the rendezvous
4051 -- completes in the middle of the accept body.
4053 if Present (Handled_Statement_Sequence (N)) then
4054 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4056 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4057 Lab := Make_Label (Loc, Lab_Id);
4059 Make_Implicit_Label_Declaration (Loc,
4060 Defining_Identifier => Entity (Lab_Id),
4061 Label_Construct => Lab);
4062 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4064 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4066 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4067 Lab := Make_Label (Loc, Lab_Id);
4069 Make_Implicit_Label_Declaration (Loc,
4070 Defining_Identifier => Entity (Lab_Id),
4071 Label_Construct => Lab);
4072 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4079 -- Case of stand alone accept statement
4081 if Is_List_Member (N) then
4083 if Present (Handled_Statement_Sequence (N)) then
4085 Make_Defining_Identifier (Loc,
4086 Chars => New_Internal_Name ('A'));
4089 Make_Object_Declaration (Loc,
4090 Defining_Identifier => Ann,
4091 Object_Definition =>
4092 New_Reference_To (RTE (RE_Address), Loc));
4094 Insert_Before (N, Adecl);
4097 Insert_Before (N, Ldecl);
4100 Insert_Before (N, Ldecl2);
4104 -- Case of accept statement which is in an accept alternative
4108 Acc_Alt : constant Node_Id := Parent (N);
4109 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4113 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4114 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4116 -- ??? Consider a single label for select statements
4118 if Present (Handled_Statement_Sequence (N)) then
4120 Statements (Handled_Statement_Sequence (N)));
4124 Statements (Handled_Statement_Sequence (N)));
4128 -- Find first accept alternative of the selective accept. A
4129 -- valid selective accept must have at least one accept in it.
4131 Alt := First (Select_Alternatives (Sel_Acc));
4133 while Nkind (Alt) /= N_Accept_Alternative loop
4137 -- If we are the first accept statement, then we have to create
4138 -- the Ann variable, as for the stand alone case, except that
4139 -- it is inserted before the selective accept. Similarly, a
4140 -- label for requeue expansion must be declared.
4142 if N = Accept_Statement (Alt) then
4144 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4147 Make_Object_Declaration (Loc,
4148 Defining_Identifier => Ann,
4149 Object_Definition =>
4150 New_Reference_To (RTE (RE_Address), Loc));
4152 Insert_Before (Sel_Acc, Adecl);
4155 -- If we are not the first accept statement, then find the Ann
4156 -- variable allocated by the first accept and use it.
4160 Node (Last_Elmt (Accept_Address
4161 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4166 -- Merge here with Ann either created or referenced, and Adecl
4167 -- pointing to the corresponding declaration. Remaining processing
4168 -- is the same for the two cases.
4170 if Present (Ann) then
4171 Append_Elmt (Ann, Accept_Address (Ent));
4172 Set_Needs_Debug_Info (Ann);
4175 -- Create renaming declarations for the entry formals. Each reference
4176 -- to a formal becomes a dereference of a component of the parameter
4177 -- block, whose address is held in Ann. These declarations are
4178 -- eventually inserted into the accept block, and analyzed there so
4179 -- that they have the proper scope for gdb and do not conflict with
4180 -- other declarations.
4182 if Present (Parameter_Specifications (N))
4183 and then Present (Handled_Statement_Sequence (N))
4193 Formal := First_Formal (Ent);
4195 while Present (Formal) loop
4196 Comp := Entry_Component (Formal);
4198 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
4200 Set_Etype (New_F, Etype (Formal));
4201 Set_Scope (New_F, Ent);
4202 Set_Needs_Debug_Info (New_F); -- That's the whole point.
4204 if Ekind (Formal) = E_In_Parameter then
4205 Set_Ekind (New_F, E_Constant);
4207 Set_Ekind (New_F, E_Variable);
4208 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4211 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4214 Make_Object_Renaming_Declaration (Loc,
4215 Defining_Identifier =>
4218 New_Reference_To (Etype (Formal), Loc),
4220 Make_Explicit_Dereference (Loc,
4221 Make_Selected_Component (Loc,
4223 Unchecked_Convert_To (
4224 Entry_Parameters_Type (Ent),
4225 New_Reference_To (Ann, Loc)),
4227 New_Reference_To (Comp, Loc))));
4229 if No (Declarations (N)) then
4230 Set_Declarations (N, New_List);
4233 Append (Decl, Declarations (N));
4234 Set_Renamed_Object (Formal, New_F);
4235 Next_Formal (Formal);
4242 end Expand_Accept_Declarations;
4244 ---------------------------------------------
4245 -- Expand_Access_Protected_Subprogram_Type --
4246 ---------------------------------------------
4248 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4249 Loc : constant Source_Ptr := Sloc (N);
4251 T : constant Entity_Id := Defining_Identifier (N);
4252 D_T : constant Entity_Id := Designated_Type (T);
4253 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4254 Chars => New_Internal_Name ('D'));
4255 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4256 Chars => New_Internal_Name ('E'));
4257 P_List : constant List_Id := Build_Protected_Spec
4258 (N, RTE (RE_Address), False, D_T);
4264 -- Create access to protected subprogram with full signature
4266 if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
4268 Make_Access_Function_Definition (Loc,
4269 Parameter_Specifications => P_List,
4270 Result_Definition =>
4271 New_Copy (Result_Definition (Type_Definition (N))));
4275 Make_Access_Procedure_Definition (Loc,
4276 Parameter_Specifications => P_List);
4280 Make_Full_Type_Declaration (Loc,
4281 Defining_Identifier => D_T2,
4282 Type_Definition => Def1);
4285 Insert_After (N, Decl1);
4287 -- Create Equivalent_Type, a record with two components for an access to
4288 -- object and an access to subprogram.
4291 Make_Component_Declaration (Loc,
4292 Defining_Identifier =>
4293 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4294 Component_Definition =>
4295 Make_Component_Definition (Loc,
4296 Aliased_Present => False,
4297 Subtype_Indication =>
4298 New_Occurrence_Of (RTE (RE_Address), Loc))),
4300 Make_Component_Declaration (Loc,
4301 Defining_Identifier =>
4302 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4303 Component_Definition =>
4304 Make_Component_Definition (Loc,
4305 Aliased_Present => False,
4306 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4309 Make_Full_Type_Declaration (Loc,
4310 Defining_Identifier => E_T,
4312 Make_Record_Definition (Loc,
4314 Make_Component_List (Loc,
4315 Component_Items => Comps)));
4318 Insert_After (Decl1, Decl2);
4319 Set_Equivalent_Type (T, E_T);
4320 end Expand_Access_Protected_Subprogram_Type;
4322 --------------------------
4323 -- Expand_Entry_Barrier --
4324 --------------------------
4326 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4327 Loc : constant Source_Ptr := Sloc (N);
4328 Prot : constant Entity_Id := Scope (Ent);
4329 Spec_Decl : constant Node_Id := Parent (Prot);
4330 Cond : constant Node_Id :=
4331 Condition (Entry_Body_Formal_Part (N));
4334 Body_Decl : Node_Id;
4337 if No_Run_Time_Mode then
4338 Error_Msg_CRT ("entry barrier", N);
4342 -- The body of the entry barrier must be analyzed in the context of the
4343 -- protected object, but its scope is external to it, just as any other
4344 -- unprotected version of a protected operation. The specification has
4345 -- been produced when the protected type declaration was elaborated. We
4346 -- build the body, insert it in the enclosing scope, but analyze it in
4347 -- the current context. A more uniform approach would be to treat
4348 -- barrier just as a protected function, and discard the protected
4349 -- version of it because it is never called.
4351 if Expander_Active then
4352 B_F := Build_Barrier_Function (N, Ent, Prot);
4353 Func := Barrier_Function (Ent);
4354 Set_Corresponding_Spec (B_F, Func);
4356 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4358 if Nkind (Parent (Body_Decl)) = N_Subunit then
4359 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4362 Insert_Before_And_Analyze (Body_Decl, B_F);
4364 Update_Prival_Subtypes (B_F);
4366 Set_Privals (Spec_Decl, N, Loc, After_Barrier => True);
4367 Set_Discriminals (Spec_Decl);
4368 Set_Scope (Func, Scope (Prot));
4371 Analyze_And_Resolve (Cond, Any_Boolean);
4374 -- The Ravenscar profile restricts barriers to simple variables declared
4375 -- within the protected object. We also allow Boolean constants, since
4376 -- these appear in several published examples and are also allowed by
4377 -- the Aonix compiler.
4379 -- Note that after analysis variables in this context will be replaced
4380 -- by the corresponding prival, that is to say a renaming of a selected
4381 -- component of the form _Object.Var. If expansion is disabled, as
4382 -- within a generic, we check that the entity appears in the current
4385 if Is_Entity_Name (Cond) then
4387 if Entity (Cond) = Standard_False
4389 Entity (Cond) = Standard_True
4393 elsif not Expander_Active
4394 and then Scope (Entity (Cond)) = Current_Scope
4398 -- Check for case of _object.all.field (note that the explicit
4399 -- dereference gets inserted by analyze/expand of _object.field)
4401 elsif Present (Renamed_Object (Entity (Cond)))
4403 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
4407 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
4413 -- It is not a boolean variable or literal, so check the restriction
4415 Check_Restriction (Simple_Barriers, Cond);
4416 end Expand_Entry_Barrier;
4418 ------------------------------------
4419 -- Expand_Entry_Body_Declarations --
4420 ------------------------------------
4422 procedure Expand_Entry_Body_Declarations (N : Node_Id) is
4423 Loc : constant Source_Ptr := Sloc (N);
4424 Index_Spec : Node_Id;
4427 if Expander_Active then
4429 -- Expand entry bodies corresponding to entry families
4430 -- by assigning a placeholder for the constant that will
4431 -- be used to expand references to the entry index parameter.
4434 Entry_Index_Specification (Entry_Body_Formal_Part (N));
4436 if Present (Index_Spec) then
4437 Set_Entry_Index_Constant (
4438 Defining_Identifier (Index_Spec),
4439 Make_Defining_Identifier (Loc, New_Internal_Name ('J')));
4442 end Expand_Entry_Body_Declarations;
4444 ------------------------------
4445 -- Expand_N_Abort_Statement --
4446 ------------------------------
4448 -- Expand abort T1, T2, .. Tn; into:
4449 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
4451 procedure Expand_N_Abort_Statement (N : Node_Id) is
4452 Loc : constant Source_Ptr := Sloc (N);
4453 Tlist : constant List_Id := Names (N);
4459 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
4462 Tasknm := First (Tlist);
4464 while Present (Tasknm) loop
4467 -- A task interface class-wide type object is being aborted.
4468 -- Retrieve its _task_id by calling a dispatching routine.
4470 if Ada_Version >= Ada_05
4471 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
4472 and then Is_Interface (Etype (Tasknm))
4473 and then Is_Task_Interface (Etype (Tasknm))
4475 Append_To (Component_Associations (Aggr),
4476 Make_Component_Association (Loc,
4477 Choices => New_List (
4478 Make_Integer_Literal (Loc, Count)),
4481 -- Tasknm._disp_get_task_id
4483 Make_Selected_Component (Loc,
4485 New_Copy_Tree (Tasknm),
4487 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))));
4490 Append_To (Component_Associations (Aggr),
4491 Make_Component_Association (Loc,
4492 Choices => New_List (
4493 Make_Integer_Literal (Loc, Count)),
4494 Expression => Concurrent_Ref (Tasknm)));
4501 Make_Procedure_Call_Statement (Loc,
4502 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
4503 Parameter_Associations => New_List (
4504 Make_Qualified_Expression (Loc,
4505 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
4506 Expression => Aggr))));
4509 end Expand_N_Abort_Statement;
4511 -------------------------------
4512 -- Expand_N_Accept_Statement --
4513 -------------------------------
4515 -- This procedure handles expansion of accept statements that stand
4516 -- alone, i.e. they are not part of an accept alternative. The expansion
4517 -- of accept statement in accept alternatives is handled by the routines
4518 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
4519 -- following description applies only to stand alone accept statements.
4521 -- If there is no handled statement sequence, or only null statements,
4522 -- then this is called a trivial accept, and the expansion is:
4524 -- Accept_Trivial (entry-index)
4526 -- If there is a handled statement sequence, then the expansion is:
4533 -- Accept_Call (entry-index, Ann);
4534 -- Renaming_Declarations for formals
4535 -- <statement sequence from N_Accept_Statement node>
4536 -- Complete_Rendezvous;
4541 -- <exception handler from N_Accept_Statement node>
4542 -- Complete_Rendezvous;
4544 -- <exception handler from N_Accept_Statement node>
4545 -- Complete_Rendezvous;
4550 -- when all others =>
4551 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
4554 -- The first three declarations were already inserted ahead of the accept
4555 -- statement by the Expand_Accept_Declarations procedure, which was called
4556 -- directly from the semantics during analysis of the accept. statement,
4557 -- before analyzing its contained statements.
4559 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
4560 -- from possible expansion activity (the original source of course does
4561 -- not have any declarations associated with the accept statement, since
4562 -- an accept statement has no declarative part). In particular, if the
4563 -- expander is active, the first such declaration is the declaration of
4564 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
4566 -- The two blocks are merged into a single block if the inner block has
4567 -- no exception handlers, but otherwise two blocks are required, since
4568 -- exceptions might be raised in the exception handlers of the inner
4569 -- block, and Exceptional_Complete_Rendezvous must be called.
4571 procedure Expand_N_Accept_Statement (N : Node_Id) is
4572 Loc : constant Source_Ptr := Sloc (N);
4573 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4574 Ename : constant Node_Id := Entry_Direct_Name (N);
4575 Eindx : constant Node_Id := Entry_Index (N);
4576 Eent : constant Entity_Id := Entity (Ename);
4577 Acstack : constant Elist_Id := Accept_Address (Eent);
4578 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
4579 Ttyp : constant Entity_Id := Etype (Scope (Eent));
4584 function Null_Statements (Stats : List_Id) return Boolean;
4585 -- Check for null statement sequence (i.e a list of labels and
4586 -- null statements).
4588 ---------------------
4589 -- Null_Statements --
4590 ---------------------
4592 function Null_Statements (Stats : List_Id) return Boolean is
4596 Stmt := First (Stats);
4597 while Nkind (Stmt) /= N_Empty
4598 and then (Nkind (Stmt) = N_Null_Statement
4600 Nkind (Stmt) = N_Label)
4605 return Nkind (Stmt) = N_Empty;
4606 end Null_Statements;
4608 -- Start of processing for Expand_N_Accept_Statement
4611 -- If accept statement is not part of a list, then its parent must be
4612 -- an accept alternative, and, as described above, we do not do any
4613 -- expansion for such accept statements at this level.
4615 if not Is_List_Member (N) then
4616 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
4619 -- Trivial accept case (no statement sequence, or null statements).
4620 -- If the accept statement has declarations, then just insert them
4621 -- before the procedure call.
4623 -- We avoid this optimization when FIFO_Within_Priorities is active,
4624 -- since it is not correct according to annex D semantics. The problem
4625 -- is that the call is required to reorder the acceptors position on
4626 -- its ready queue, even though there is nothing to be done. However,
4627 -- if no policy is specified, then we decide that our dispatching
4628 -- policy always reorders the queue right after the RV to look the
4629 -- way they were just before the RV. Since we are allowed to freely
4630 -- reorder same-priority queues (this is part of what dispatching
4631 -- policies are all about), the optimization is legitimate.
4633 elsif Opt.Task_Dispatching_Policy /= 'F'
4634 and then (No (Stats) or else Null_Statements (Statements (Stats)))
4636 -- Remove declarations for renamings, because the parameter block
4637 -- will not be assigned.
4644 D := First (Declarations (N));
4646 while Present (D) loop
4648 if Nkind (D) = N_Object_Renaming_Declaration then
4656 if Present (Declarations (N)) then
4657 Insert_Actions (N, Declarations (N));
4661 Make_Procedure_Call_Statement (Loc,
4662 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
4663 Parameter_Associations => New_List (
4664 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
4668 -- Discard Entry_Address that was created for it, so it will not be
4669 -- emitted if this accept statement is in the statement part of a
4670 -- delay alternative.
4672 if Present (Stats) then
4673 Remove_Last_Elmt (Acstack);
4676 -- Case of statement sequence present
4679 -- Construct the block, using the declarations from the accept
4680 -- statement if any to initialize the declarations of the block.
4682 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4683 Set_Ekind (Blkent, E_Block);
4684 Set_Etype (Blkent, Standard_Void_Type);
4685 Set_Scope (Blkent, Current_Scope);
4688 Make_Block_Statement (Loc,
4689 Identifier => New_Reference_To (Blkent, Loc),
4690 Declarations => Declarations (N),
4691 Handled_Statement_Sequence => Build_Accept_Body (N));
4693 -- Prepend call to Accept_Call to main statement sequence If the
4694 -- accept has exception handlers, the statement sequence is wrapped
4695 -- in a block. Insert call and renaming declarations in the
4696 -- declarations of the block, so they are elaborated before the
4700 Make_Procedure_Call_Statement (Loc,
4701 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
4702 Parameter_Associations => New_List (
4703 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
4704 New_Reference_To (Ann, Loc)));
4706 if Parent (Stats) = N then
4707 Prepend (Call, Statements (Stats));
4724 D := First (Declarations (N));
4725 while Present (D) loop
4728 if Nkind (D) = N_Object_Renaming_Declaration then
4730 -- The renaming declarations for the formals were created
4731 -- during analysis of the accept statement, and attached to
4732 -- the list of declarations. Place them now in the context
4733 -- of the accept block or subprogram.
4736 Typ := Entity (Subtype_Mark (D));
4737 Insert_After (Call, D);
4740 -- If the formal is class_wide, it does not have an actual
4741 -- subtype. The analysis of the renaming declaration creates
4742 -- one, but we need to retain the class-wide nature of the
4745 if Is_Class_Wide_Type (Typ) then
4746 Set_Etype (Defining_Identifier (D), Typ);
4757 -- Replace the accept statement by the new block
4762 -- Last step is to unstack the Accept_Address value
4764 Remove_Last_Elmt (Acstack);
4766 end Expand_N_Accept_Statement;
4768 ----------------------------------
4769 -- Expand_N_Asynchronous_Select --
4770 ----------------------------------
4772 -- This procedure assumes that the trigger statement is an entry call or
4773 -- a dispatching procedure call. A delay alternative should already have
4774 -- been expanded into an entry call to the appropriate delay object Wait
4777 -- If the trigger is a task entry call, the select is implemented with
4778 -- a Task_Entry_Call:
4783 -- P : parms := (parm, parm, parm);
4785 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
4787 -- procedure _clean is
4790 -- Cancel_Task_Entry_Call (C);
4800 -- Asynchronous_Call,
4808 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions.
4811 -- when Abort_Signal => Abort_Undefer;
4818 -- <triggered-statements>
4822 -- Note that Build_Simple_Entry_Call is used to expand the entry
4823 -- of the asynchronous entry call (by the
4824 -- Expand_N_Entry_Call_Statement procedure) as follows:
4827 -- P : parms := (parm, parm, parm);
4829 -- Call_Simple (acceptor-task, entry-index, P'Address);
4835 -- so the task at hand is to convert the latter expansion into the former
4837 -- If the trigger is a protected entry call, the select is
4838 -- implemented with Protected_Entry_Call:
4841 -- P : E1_Params := (param, param, param);
4842 -- Bnn : Communications_Block;
4846 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions.
4847 -- procedure _clean is
4850 -- if Enqueued (Bnn) then
4851 -- Cancel_Protected_Entry_Call (Bnn);
4858 -- Protected_Entry_Call (
4859 -- Object => po._object'Access,
4860 -- E => <entry index>;
4861 -- Uninterpreted_Data => P'Address;
4862 -- Mode => Asynchronous_Call;
4864 -- if Enqueued (Bnn) then
4868 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions.
4871 -- when Abort_Signal => Abort_Undefer;
4874 -- if not Cancelled (Bnn) then
4875 -- <triggered-statements>
4879 -- Build_Simple_Entry_Call is used to expand the all to a simple
4880 -- protected entry call:
4883 -- P : E1_Params := (param, param, param);
4884 -- Bnn : Communications_Block;
4887 -- Protected_Entry_Call (
4888 -- Object => po._object'Access,
4889 -- E => <entry index>;
4890 -- Uninterpreted_Data => P'Address;
4891 -- Mode => Simple_Call;
4898 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
4902 -- B : Boolean := False;
4903 -- Bnn : Communication_Block;
4904 -- C : Ada.Tags.Prim_Op_Kind;
4905 -- P : Parameters := (Param1 .. ParamN)
4906 -- S : constant Integer := DT_Position (<dispatching-call>);
4910 -- disp_get_prim_op_kind (<object>, S, C);
4912 -- if C = POK_Protected_Entry then
4914 -- procedure _clean is
4916 -- if Enqueued (Bnn) then
4917 -- Cancel_Protected_Entry_Call (Bnn);
4923 -- disp_asynchronous_select
4924 -- (Obj, S, P'address, Bnn, B);
4926 -- Param1 := P.Param1;
4928 -- ParamN := P.ParamN;
4930 -- if Enqueued (Bnn) then
4931 -- <abortable-statements>
4937 -- when Abort_Signal => Abort_Undefer;
4940 -- if not Cancelled (Bnn) then
4941 -- <triggering-statements>
4944 -- elsif C = POK_Task_Entry then
4946 -- procedure _clean is
4948 -- Cancel_Task_Entry_Call (U);
4954 -- disp_asynchronous_select
4955 -- (<object>, S, P'address, Bnn, B);
4957 -- Param1 := P.Param1;
4959 -- ParamN := P.ParamN;
4964 -- <abortable-statements>
4969 -- when Abort_Signal => Abort_Undefer;
4973 -- <triggering-statements>
4978 -- <dispatching-call>;
4979 -- <triggering-statements>
4982 -- The job is to convert this to the asynchronous form
4984 -- If the trigger is a delay statement, it will have been expanded into a
4985 -- call to one of the GNARL delay procedures. This routine will convert
4986 -- this into a protected entry call on a delay object and then continue
4987 -- processing as for a protected entry call trigger. This requires
4988 -- declaring a Delay_Block object and adding a pointer to this object to
4989 -- the parameter list of the delay procedure to form the parameter list of
4990 -- the entry call. This object is used by the runtime to queue the delay
4993 -- For a description of the use of P and the assignments after the
4994 -- call, see Expand_N_Entry_Call_Statement.
4996 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
4997 Loc : constant Source_Ptr := Sloc (N);
4998 Abrt : constant Node_Id := Abortable_Part (N);
4999 Astats : constant List_Id := Statements (Abrt);
5000 Trig : constant Node_Id := Triggering_Alternative (N);
5001 Tstats : constant List_Id := Statements (Trig);
5003 Abort_Block_Ent : Entity_Id;
5004 Abortable_Block : Node_Id;
5006 Blk_Ent : Entity_Id;
5007 Blk_Typ : Entity_Id;
5009 Call_Ent : Entity_Id;
5010 Cancel_Param : Entity_Id;
5011 Cleanup_Block : Node_Id;
5012 Cleanup_Block_Ent : Entity_Id;
5013 Cleanup_Stmts : List_Id;
5015 Dblock_Ent : Entity_Id;
5020 Enqueue_Call : Node_Id;
5029 ProtE_Stmts : List_Id;
5030 ProtP_Stmts : List_Id;
5033 Target_Undefer : RE_Id;
5034 TaskE_Stmts : List_Id;
5035 Undefer_Args : List_Id := No_List;
5037 B : Entity_Id; -- Call status flag
5038 Bnn : Entity_Id; -- Communication block
5039 C : Entity_Id; -- Call kind
5040 P : Entity_Id; -- Parameter block
5041 S : Entity_Id; -- Primitive operation slot
5042 T : Entity_Id; -- Additional status flag
5045 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5046 Ecall := Triggering_Statement (Trig);
5048 -- The arguments in the call may require dynamic allocation, and the
5049 -- call statement may have been transformed into a block. The block
5050 -- may contain additional declarations for internal entities, and the
5051 -- original call is found by sequential search.
5053 if Nkind (Ecall) = N_Block_Statement then
5054 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5055 while Nkind (Ecall) /= N_Procedure_Call_Statement
5056 and then Nkind (Ecall) /= N_Entry_Call_Statement
5062 -- This is either a dispatching call or a delay statement used as a
5063 -- trigger which was expanded into a procedure call.
5065 if Nkind (Ecall) = N_Procedure_Call_Statement then
5066 if Ada_Version >= Ada_05
5068 (not Present (Original_Node (Ecall))
5070 Nkind (Original_Node (Ecall)) /= N_Delay_Relative_Statement)
5072 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5077 -- Call status flag processing, generate:
5078 -- B : Boolean := False;
5080 B := SEU.Build_B (Loc, Decls);
5082 -- Communication block processing, generate:
5083 -- Bnn : Communication_Block;
5085 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5088 Make_Object_Declaration (Loc,
5089 Defining_Identifier =>
5091 Object_Definition =>
5092 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5094 -- Call kind processing, generate:
5095 -- C : Ada.Tags.Prim_Op_Kind;
5097 C := SEU.Build_C (Loc, Decls);
5099 -- Parameter block processing
5101 Blk_Typ := Build_Parameter_Block
5102 (Loc, Actuals, Formals, Decls);
5103 P := Parameter_Block_Pack
5104 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5106 -- Dispatch table slot processing, generate:
5107 -- S : constant Integer :=
5108 -- Ada.Tags.Get_Offset_Index (
5109 -- Unchecked_Convert_To (Ada.Tags.Interface_Tag, Obj),
5110 -- DT_Position (<dispatching-procedure>));
5112 S := SEU.Build_S (Loc, Decls, Obj, Call_Ent);
5114 -- Additional status flag processing, generate:
5116 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5119 Make_Object_Declaration (Loc,
5120 Defining_Identifier =>
5122 Object_Definition =>
5123 New_Reference_To (Standard_Boolean, Loc)));
5126 Make_Procedure_Call_Statement (Loc,
5129 Find_Prim_Op (Etype (Etype (Obj)),
5130 Name_uDisp_Get_Prim_Op_Kind),
5132 Parameter_Associations =>
5134 New_Copy_Tree (Obj),
5135 New_Reference_To (S, Loc),
5136 New_Reference_To (C, Loc))));
5138 -- ---------------------------------------------------------------
5139 -- Protected entry handling
5142 -- Param1 := P.Param1;
5144 -- ParamN := P.ParamN;
5146 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5149 -- _dispatching_asynchronous_select
5150 -- (<object>, S, P'address, Bnn, B);
5152 Prepend_To (Cleanup_Stmts,
5153 Make_Procedure_Call_Statement (Loc,
5156 Find_Prim_Op (Etype (Etype (Obj)),
5157 Name_uDisp_Asynchronous_Select),
5159 Parameter_Associations =>
5161 New_Copy_Tree (Obj),
5162 New_Reference_To (S, Loc),
5163 Make_Attribute_Reference (Loc,
5164 Prefix => New_Reference_To (P, Loc),
5165 Attribute_Name => Name_Address),
5166 New_Reference_To (Bnn, Loc),
5167 New_Reference_To (B, Loc))));
5170 -- if Enqueued (Bnn) then
5171 -- <abortable-statements>
5174 Append_To (Cleanup_Stmts,
5175 Make_If_Statement (Loc,
5177 Make_Function_Call (Loc,
5179 New_Reference_To (RTE (RE_Enqueued), Loc),
5180 Parameter_Associations =>
5182 New_Reference_To (Bnn, Loc))),
5185 New_Copy_List_Tree (Astats)));
5187 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5188 -- will then generate a _clean for the communication block Bnn.
5192 -- procedure _clean is
5194 -- if Enqueued (Bnn) then
5195 -- Cancel_Protected_Entry_Call (Bnn);
5204 Cleanup_Block_Ent :=
5205 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5207 Cleanup_Block := SEU.Build_Cleanup_Block (Loc,
5208 Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5210 -- Wrap the cleanup block in an exception handling block
5216 -- when Abort_Signal => Abort_Undefer;
5220 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5224 Make_Implicit_Label_Declaration (Loc,
5225 Defining_Identifier => Abort_Block_Ent),
5227 SEU.Build_Abort_Block (Loc,
5228 Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5231 -- if not Cancelled (Bnn) then
5232 -- <triggering-statements>
5235 Append_To (ProtE_Stmts,
5236 Make_If_Statement (Loc,
5240 Make_Function_Call (Loc,
5242 New_Reference_To (RTE (RE_Cancelled), Loc),
5243 Parameter_Associations =>
5245 New_Reference_To (Bnn, Loc)))),
5248 New_Copy_List_Tree (Tstats)));
5250 -- ---------------------------------------------------------------
5251 -- Task entry handling
5254 -- Param1 := P.Param1;
5256 -- ParamN := P.ParamN;
5258 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5261 -- _dispatching_asynchronous_select
5262 -- (<object>, S, P'address, Bnn, B);
5264 Prepend_To (TaskE_Stmts,
5265 Make_Procedure_Call_Statement (Loc,
5268 Find_Prim_Op (Etype (Etype (Obj)),
5269 Name_uDisp_Asynchronous_Select),
5271 Parameter_Associations =>
5273 New_Copy_Tree (Obj),
5274 New_Reference_To (S, Loc),
5275 Make_Attribute_Reference (Loc,
5276 Prefix => New_Reference_To (P, Loc),
5277 Attribute_Name => Name_Address),
5278 New_Reference_To (Bnn, Loc),
5279 New_Reference_To (B, Loc))));
5284 Prepend_To (TaskE_Stmts,
5285 Make_Procedure_Call_Statement (Loc,
5287 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5288 Parameter_Associations =>
5293 -- <abortable-statements>
5295 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5297 Prepend_To (Cleanup_Stmts,
5298 Make_Procedure_Call_Statement (Loc,
5300 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5301 Parameter_Associations =>
5304 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5305 -- will generate a _clean for the additional status flag.
5309 -- procedure _clean is
5311 -- Cancel_Task_Entry_Call (U);
5319 Cleanup_Block_Ent :=
5320 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5322 Cleanup_Block := SEU.Build_Cleanup_Block (Loc,
5323 Cleanup_Block_Ent, Cleanup_Stmts, T);
5325 -- Wrap the cleanup block in an exception handling block
5331 -- when Abort_Signal => Abort_Undefer;
5335 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5337 Append_To (TaskE_Stmts,
5338 Make_Implicit_Label_Declaration (Loc,
5339 Defining_Identifier => Abort_Block_Ent));
5341 Append_To (TaskE_Stmts,
5342 SEU.Build_Abort_Block (Loc,
5343 Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5347 -- <triggering-statements>
5350 Append_To (TaskE_Stmts,
5351 Make_If_Statement (Loc,
5355 New_Reference_To (T, Loc)),
5358 New_Copy_List_Tree (Tstats)));
5360 -------------------------------------------------------------------
5361 -- Protected procedure handling
5364 -- <dispatching-call>;
5365 -- <triggering-statements>
5367 ProtP_Stmts := New_Copy_List_Tree (Tstats);
5368 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
5371 -- if C = POK_Procedure_Entry then
5373 -- elsif C = POK_Task_Entry then
5380 Make_If_Statement (Loc,
5384 New_Reference_To (C, Loc),
5386 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
5393 Make_Elsif_Part (Loc,
5397 New_Reference_To (C, Loc),
5399 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
5408 Make_Block_Statement (Loc,
5411 Handled_Statement_Sequence =>
5412 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5417 -- Delay triggering statement processing
5420 -- Add a Delay_Block object to the parameter list of the delay
5421 -- procedure to form the parameter list of the Wait entry call.
5424 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
5426 Pdef := Entity (Name (Ecall));
5428 if Is_RTE (Pdef, RO_CA_Delay_For) then
5430 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
5432 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
5434 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
5436 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
5437 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
5440 Append_To (Parameter_Associations (Ecall),
5441 Make_Attribute_Reference (Loc,
5442 Prefix => New_Reference_To (Dblock_Ent, Loc),
5443 Attribute_Name => Name_Unchecked_Access));
5445 -- Create the inner block to protect the abortable part
5448 Make_Exception_Handler (Loc,
5449 Exception_Choices =>
5450 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5451 Statements => New_List (
5452 Make_Procedure_Call_Statement (Loc,
5453 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
5456 Make_Procedure_Call_Statement (Loc,
5457 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
5460 Make_Block_Statement (Loc,
5461 Identifier => New_Reference_To (Blk_Ent, Loc),
5462 Handled_Statement_Sequence =>
5463 Make_Handled_Sequence_Of_Statements (Loc,
5464 Statements => Astats),
5465 Has_Created_Identifier => True,
5466 Is_Asynchronous_Call_Block => True);
5468 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
5471 Make_Implicit_If_Statement (N,
5472 Condition => Make_Function_Call (Loc,
5473 Name => Enqueue_Call,
5474 Parameter_Associations => Parameter_Associations (Ecall)),
5476 New_List (Make_Block_Statement (Loc,
5477 Handled_Statement_Sequence =>
5478 Make_Handled_Sequence_Of_Statements (Loc,
5479 Statements => New_List (
5480 Make_Implicit_Label_Declaration (Loc,
5481 Defining_Identifier => Blk_Ent,
5482 Label_Construct => Abortable_Block),
5484 Exception_Handlers => Hdle)))));
5486 Stmts := New_List (Ecall);
5488 -- Construct statement sequence for new block
5491 Make_Implicit_If_Statement (N,
5492 Condition => Make_Function_Call (Loc,
5493 Name => New_Reference_To (
5494 RTE (RE_Timed_Out), Loc),
5495 Parameter_Associations => New_List (
5496 Make_Attribute_Reference (Loc,
5497 Prefix => New_Reference_To (Dblock_Ent, Loc),
5498 Attribute_Name => Name_Unchecked_Access))),
5499 Then_Statements => Tstats));
5501 -- The result is the new block
5503 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
5506 Make_Block_Statement (Loc,
5507 Declarations => New_List (
5508 Make_Object_Declaration (Loc,
5509 Defining_Identifier => Dblock_Ent,
5510 Aliased_Present => True,
5511 Object_Definition => New_Reference_To (
5512 RTE (RE_Delay_Block), Loc))),
5514 Handled_Statement_Sequence =>
5515 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5525 Extract_Entry (Ecall, Concval, Ename, Index);
5526 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
5528 Stmts := Statements (Handled_Statement_Sequence (Ecall));
5529 Decls := Declarations (Ecall);
5531 if Is_Protected_Type (Etype (Concval)) then
5533 -- Get the declarations of the block expanded from the entry call
5535 Decl := First (Decls);
5536 while Present (Decl)
5538 (Nkind (Decl) /= N_Object_Declaration
5539 or else not Is_RTE (Etype (Object_Definition (Decl)),
5540 RE_Communication_Block))
5545 pragma Assert (Present (Decl));
5546 Cancel_Param := Defining_Identifier (Decl);
5548 -- Change the mode of the Protected_Entry_Call call
5550 -- Protected_Entry_Call (
5551 -- Object => po._object'Access,
5552 -- E => <entry index>;
5553 -- Uninterpreted_Data => P'Address;
5554 -- Mode => Asynchronous_Call;
5557 Stmt := First (Stmts);
5559 -- Skip assignments to temporaries created for in-out parameters
5561 -- This makes unwarranted assumptions about the shape of the expanded
5562 -- tree for the call, and should be cleaned up ???
5564 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
5570 Param := First (Parameter_Associations (Call));
5571 while Present (Param)
5572 and then not Is_RTE (Etype (Param), RE_Call_Modes)
5577 pragma Assert (Present (Param));
5578 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
5581 -- Append an if statement to execute the abortable part
5584 -- if Enqueued (Bnn) then
5587 Make_Implicit_If_Statement (N,
5588 Condition => Make_Function_Call (Loc,
5589 Name => New_Reference_To (
5590 RTE (RE_Enqueued), Loc),
5591 Parameter_Associations => New_List (
5592 New_Reference_To (Cancel_Param, Loc))),
5593 Then_Statements => Astats));
5596 Make_Block_Statement (Loc,
5597 Identifier => New_Reference_To (Blk_Ent, Loc),
5598 Handled_Statement_Sequence =>
5599 Make_Handled_Sequence_Of_Statements (Loc,
5600 Statements => Stmts),
5601 Has_Created_Identifier => True,
5602 Is_Asynchronous_Call_Block => True);
5604 -- For the JVM call Update_Exception instead of Abort_Undefer.
5605 -- See 4jexcept.ads for an explanation.
5607 if Hostparm.Java_VM then
5608 Target_Undefer := RE_Update_Exception;
5610 New_List (Make_Function_Call (Loc,
5611 Name => New_Occurrence_Of
5612 (RTE (RE_Current_Target_Exception), Loc)));
5614 Target_Undefer := RE_Abort_Undefer;
5618 Make_Block_Statement (Loc,
5619 Handled_Statement_Sequence =>
5620 Make_Handled_Sequence_Of_Statements (Loc,
5621 Statements => New_List (
5622 Make_Implicit_Label_Declaration (Loc,
5623 Defining_Identifier => Blk_Ent,
5624 Label_Construct => Abortable_Block),
5629 Exception_Handlers => New_List (
5630 Make_Exception_Handler (Loc,
5632 -- when Abort_Signal =>
5633 -- Abort_Undefer.all;
5635 Exception_Choices =>
5636 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5637 Statements => New_List (
5638 Make_Procedure_Call_Statement (Loc,
5639 Name => New_Reference_To (
5640 RTE (Target_Undefer), Loc),
5641 Parameter_Associations => Undefer_Args)))))),
5643 -- if not Cancelled (Bnn) then
5644 -- triggered statements
5647 Make_Implicit_If_Statement (N,
5648 Condition => Make_Op_Not (Loc,
5650 Make_Function_Call (Loc,
5651 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
5652 Parameter_Associations => New_List (
5653 New_Occurrence_Of (Cancel_Param, Loc)))),
5654 Then_Statements => Tstats));
5656 -- Asynchronous task entry call
5663 B := Make_Defining_Identifier (Loc, Name_uB);
5665 -- Insert declaration of B in declarations of existing block
5668 Make_Object_Declaration (Loc,
5669 Defining_Identifier => B,
5670 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
5672 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
5674 -- Insert declaration of C in declarations of existing block
5677 Make_Object_Declaration (Loc,
5678 Defining_Identifier => Cancel_Param,
5679 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
5681 -- Remove and save the call to Call_Simple
5683 Stmt := First (Stmts);
5685 -- Skip assignments to temporaries created for in-out parameters.
5686 -- This makes unwarranted assumptions about the shape of the expanded
5687 -- tree for the call, and should be cleaned up ???
5689 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
5695 -- Create the inner block to protect the abortable part
5698 Make_Exception_Handler (Loc,
5699 Exception_Choices =>
5700 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5701 Statements => New_List (
5702 Make_Procedure_Call_Statement (Loc,
5703 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
5706 Make_Procedure_Call_Statement (Loc,
5707 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
5710 Make_Block_Statement (Loc,
5711 Identifier => New_Reference_To (Blk_Ent, Loc),
5712 Handled_Statement_Sequence =>
5713 Make_Handled_Sequence_Of_Statements (Loc,
5714 Statements => Astats),
5715 Has_Created_Identifier => True,
5716 Is_Asynchronous_Call_Block => True);
5719 Make_Block_Statement (Loc,
5720 Handled_Statement_Sequence =>
5721 Make_Handled_Sequence_Of_Statements (Loc,
5722 Statements => New_List (
5723 Make_Implicit_Label_Declaration (Loc,
5724 Defining_Identifier => Blk_Ent,
5725 Label_Construct => Abortable_Block),
5727 Exception_Handlers => Hdle)));
5729 -- Create new call statement
5731 Params := Parameter_Associations (Call);
5734 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
5736 New_Reference_To (B, Loc));
5739 Make_Procedure_Call_Statement (Loc,
5741 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
5742 Parameter_Associations => Params));
5744 -- Construct statement sequence for new block
5747 Make_Implicit_If_Statement (N,
5750 New_Reference_To (Cancel_Param, Loc)),
5751 Then_Statements => Tstats));
5753 -- Protected the call against abort
5756 Make_Procedure_Call_Statement (Loc,
5757 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
5758 Parameter_Associations => Empty_List));
5761 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
5763 -- The result is the new block
5766 Make_Block_Statement (Loc,
5767 Declarations => Decls,
5768 Handled_Statement_Sequence =>
5769 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5772 end Expand_N_Asynchronous_Select;
5774 -------------------------------------
5775 -- Expand_N_Conditional_Entry_Call --
5776 -------------------------------------
5778 -- The conditional task entry call is converted to a call to
5783 -- P : parms := (parm, parm, parm);
5790 -- Conditional_Call,
5796 -- normal-statements
5802 -- For a description of the use of P and the assignments after the
5803 -- call, see Expand_N_Entry_Call_Statement. Note that the entry call
5804 -- of the conditional entry call has already been expanded (by the
5805 -- Expand_N_Entry_Call_Statement procedure) as follows:
5808 -- P : parms := (parm, parm, parm);
5810 -- ... info for in-out parameters
5811 -- Call_Simple (acceptor-task, entry-index, P'Address);
5817 -- so the task at hand is to convert the latter expansion into the former
5819 -- The conditional protected entry call is converted to a call to
5820 -- Protected_Entry_Call:
5823 -- P : parms := (parm, parm, parm);
5824 -- Bnn : Communications_Block;
5827 -- Protected_Entry_Call (
5828 -- Object => po._object'Access,
5829 -- E => <entry index>;
5830 -- Uninterpreted_Data => P'Address;
5831 -- Mode => Conditional_Call;
5836 -- if Cancelled (Bnn) then
5839 -- normal-statements
5843 -- As for tasks, the entry call of the conditional entry call has
5844 -- already been expanded (by the Expand_N_Entry_Call_Statement procedure)
5848 -- P : E1_Params := (param, param, param);
5849 -- Bnn : Communications_Block;
5852 -- Protected_Entry_Call (
5853 -- Object => po._object'Access,
5854 -- E => <entry index>;
5855 -- Uninterpreted_Data => P'Address;
5856 -- Mode => Simple_Call;
5863 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
5867 -- B : Boolean := False;
5868 -- C : Ada.Tags.Prim_Op_Kind;
5869 -- P : Parameters := (Param1 .. ParamN);
5870 -- S : constant Integer := DT_Position (<dispatching-procedure>);
5873 -- disp_conditional_select (<object>, S, P'address, C, B);
5875 -- if C = POK_Protected_Entry
5876 -- or else C = POK_Task_Entry
5878 -- Param1 := P.Param1;
5880 -- ParamN := P.ParamN;
5884 -- if C = POK_Procedure
5885 -- or else C = POK_Protected_Procedure
5886 -- or else C = POK_Task_Procedure
5888 -- <dispatching-procedure> (<object>, Param1 .. ParamN);
5890 -- <normal-statements>
5892 -- <else-statements>
5896 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
5897 Loc : constant Source_Ptr := Sloc (N);
5898 Alt : constant Node_Id := Entry_Call_Alternative (N);
5899 Blk : Node_Id := Entry_Call_Statement (Alt);
5900 Transient_Blk : Node_Id;
5903 Blk_Typ : Entity_Id;
5905 Call_Ent : Entity_Id;
5917 B : Entity_Id; -- Call status flag
5918 C : Entity_Id; -- Call kind
5919 P : Entity_Id; -- Parameter block
5920 S : Entity_Id; -- Primitive operation slot
5923 if Ada_Version >= Ada_05
5924 and then Nkind (Blk) = N_Procedure_Call_Statement
5926 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
5931 -- Call status flag processing, generate:
5932 -- B : Boolean := False;
5934 B := SEU.Build_B (Loc, Decls);
5936 -- Call kind processing, generate:
5937 -- C : Ada.Tags.Prim_Op_Kind;
5939 C := SEU.Build_C (Loc, Decls);
5941 -- Parameter block processing
5943 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
5944 P := Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals,
5947 -- Dispatch table slot processing, generate:
5948 -- S : constant Integer :=
5949 -- Ada.Tags.Get_Offset_Index (
5950 -- Unchecked_Convert_To (Ada.Tags.Interface_Tag, Obj),
5951 -- DT_Position (<dispatching-procedure>));
5953 S := SEU.Build_S (Loc, Decls, Obj, Call_Ent);
5956 -- _dispatching_conditional_select (<object>, S, P'address, C, B);
5959 Make_Procedure_Call_Statement (Loc,
5962 Find_Prim_Op (Etype (Etype (Obj)),
5963 Name_uDisp_Conditional_Select),
5965 Parameter_Associations =>
5967 New_Copy_Tree (Obj),
5968 New_Reference_To (S, Loc),
5969 Make_Attribute_Reference (Loc,
5970 Prefix => New_Reference_To (P, Loc),
5971 Attribute_Name => Name_Address),
5972 New_Reference_To (C, Loc),
5973 New_Reference_To (B, Loc))));
5976 -- if C = POK_Protected_Entry
5977 -- or else C = POK_Task_Entry
5979 -- Param1 := P.Param1;
5981 -- ParamN := P.ParamN;
5984 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5986 -- Generate the if statement only when the packed parameters need
5987 -- explicit assignments to their corresponding actuals.
5989 if Present (Unpack) then
5991 Make_If_Statement (Loc,
5998 New_Reference_To (C, Loc),
6000 New_Reference_To (RTE (
6001 RE_POK_Protected_Entry), Loc)),
6005 New_Reference_To (C, Loc),
6007 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6009 Then_Statements => Unpack));
6014 -- if C = POK_Procedure
6015 -- or else C = POK_Protected_Procedure
6016 -- or else C = POK_Task_Procedure
6018 -- <dispatching-procedure-call>
6020 -- <normal-statements>
6022 -- <else-statements>
6025 N_Stats := New_Copy_List_Tree (Statements (Alt));
6027 Prepend_To (N_Stats,
6028 Make_If_Statement (Loc,
6034 New_Reference_To (C, Loc),
6036 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6043 New_Reference_To (C, Loc),
6045 New_Reference_To (RTE (
6046 RE_POK_Protected_Procedure), Loc)),
6051 New_Reference_To (C, Loc),
6053 New_Reference_To (RTE (
6054 RE_POK_Task_Procedure), Loc)))),
6060 Make_If_Statement (Loc,
6061 Condition => New_Reference_To (B, Loc),
6062 Then_Statements => N_Stats,
6063 Else_Statements => Else_Statements (N)));
6066 Make_Block_Statement (Loc,
6067 Declarations => Decls,
6068 Handled_Statement_Sequence =>
6069 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6071 -- As described above, The entry alternative is transformed into a
6072 -- block that contains the gnulli call, and possibly assignment
6073 -- statements for in-out parameters. The gnulli call may itself be
6074 -- rewritten into a transient block if some unconstrained parameters
6075 -- require it. We need to retrieve the call to complete its parameter
6080 First_Real_Statement (Handled_Statement_Sequence (Blk));
6082 if Present (Transient_Blk)
6083 and then Nkind (Transient_Blk) = N_Block_Statement
6085 Blk := Transient_Blk;
6088 Stmts := Statements (Handled_Statement_Sequence (Blk));
6089 Stmt := First (Stmts);
6090 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6095 Params := Parameter_Associations (Call);
6097 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6099 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6101 Param := First (Params);
6102 while Present (Param)
6103 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6108 pragma Assert (Present (Param));
6109 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6113 -- Find the Communication_Block parameter for the call to the
6114 -- Cancelled function.
6116 Decl := First (Declarations (Blk));
6117 while Present (Decl)
6118 and then not Is_RTE (Etype (Object_Definition (Decl)),
6119 RE_Communication_Block)
6124 -- Add an if statement to execute the else part if the call
6125 -- does not succeed (as indicated by the Cancelled predicate).
6128 Make_Implicit_If_Statement (N,
6129 Condition => Make_Function_Call (Loc,
6130 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6131 Parameter_Associations => New_List (
6132 New_Reference_To (Defining_Identifier (Decl), Loc))),
6133 Then_Statements => Else_Statements (N),
6134 Else_Statements => Statements (Alt)));
6137 B := Make_Defining_Identifier (Loc, Name_uB);
6139 -- Insert declaration of B in declarations of existing block
6141 if No (Declarations (Blk)) then
6142 Set_Declarations (Blk, New_List);
6145 Prepend_To (Declarations (Blk),
6146 Make_Object_Declaration (Loc,
6147 Defining_Identifier => B,
6148 Object_Definition =>
6149 New_Reference_To (Standard_Boolean, Loc)));
6151 -- Create new call statement
6154 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6155 Append_To (Params, New_Reference_To (B, Loc));
6158 Make_Procedure_Call_Statement (Loc,
6159 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6160 Parameter_Associations => Params));
6162 -- Construct statement sequence for new block
6165 Make_Implicit_If_Statement (N,
6166 Condition => New_Reference_To (B, Loc),
6167 Then_Statements => Statements (Alt),
6168 Else_Statements => Else_Statements (N)));
6171 -- The result is the new block
6174 Make_Block_Statement (Loc,
6175 Declarations => Declarations (Blk),
6176 Handled_Statement_Sequence =>
6177 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6181 end Expand_N_Conditional_Entry_Call;
6183 ---------------------------------------
6184 -- Expand_N_Delay_Relative_Statement --
6185 ---------------------------------------
6187 -- Delay statement is implemented as a procedure call to Delay_For
6188 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6189 -- simple delays imposed by the use of Protected Objects.
6191 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6192 Loc : constant Source_Ptr := Sloc (N);
6195 Make_Procedure_Call_Statement (Loc,
6196 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6197 Parameter_Associations => New_List (Expression (N))));
6199 end Expand_N_Delay_Relative_Statement;
6201 ------------------------------------
6202 -- Expand_N_Delay_Until_Statement --
6203 ------------------------------------
6205 -- Delay Until statement is implemented as a procedure call to
6206 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6208 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6209 Loc : constant Source_Ptr := Sloc (N);
6213 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6214 Typ := RTE (RO_CA_Delay_Until);
6216 Typ := RTE (RO_RT_Delay_Until);
6220 Make_Procedure_Call_Statement (Loc,
6221 Name => New_Reference_To (Typ, Loc),
6222 Parameter_Associations => New_List (Expression (N))));
6225 end Expand_N_Delay_Until_Statement;
6227 -------------------------
6228 -- Expand_N_Entry_Body --
6229 -------------------------
6231 procedure Expand_N_Entry_Body (N : Node_Id) is
6232 Loc : constant Source_Ptr := Sloc (N);
6233 Dec : constant Node_Id := Parent (Current_Scope);
6234 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
6235 Index_Spec : constant Node_Id :=
6236 Entry_Index_Specification (Ent_Formals);
6238 First_Decl : constant Node_Id := First (Declarations (N));
6239 Index_Decl : List_Id;
6242 -- Add the renamings for private declarations and discriminants
6244 Add_Discriminal_Declarations
6245 (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc);
6246 Add_Private_Declarations
6247 (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc);
6249 if Present (Index_Spec) then
6251 Index_Constant_Declaration
6253 Defining_Identifier (Index_Spec), Defining_Identifier (Dec));
6255 -- If the entry has local declarations, insert index declaration
6256 -- before them, because the index may be used therein.
6258 if Present (First_Decl) then
6259 Insert_List_Before (First_Decl, Index_Decl);
6261 Append_List_To (Declarations (N), Index_Decl);
6265 -- Associate privals and discriminals with the next protected operation
6266 -- body to be expanded. These are used to expand references to private
6267 -- data objects and discriminants, respectively.
6269 Next_Op := Next_Protected_Operation (N);
6271 if Present (Next_Op) then
6272 Set_Privals (Dec, Next_Op, Loc);
6273 Set_Discriminals (Dec);
6275 end Expand_N_Entry_Body;
6277 -----------------------------------
6278 -- Expand_N_Entry_Call_Statement --
6279 -----------------------------------
6281 -- An entry call is expanded into GNARLI calls to implement
6282 -- a simple entry call (see Build_Simple_Entry_Call).
6284 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6290 if No_Run_Time_Mode then
6291 Error_Msg_CRT ("entry call", N);
6295 -- If this entry call is part of an asynchronous select, don't expand it
6296 -- here; it will be expanded with the select statement. Don't expand
6297 -- timed entry calls either, as they are translated into asynchronous
6300 -- ??? This whole approach is questionable; it may be better to go back
6301 -- to allowing the expansion to take place and then attempting to fix it
6302 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6303 -- whether the expanded call is on a task or protected entry.
6305 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6306 or else N /= Triggering_Statement (Parent (N)))
6307 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
6308 or else N /= Entry_Call_Statement (Parent (N))
6309 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
6311 Extract_Entry (N, Concval, Ename, Index);
6312 Build_Simple_Entry_Call (N, Concval, Ename, Index);
6314 end Expand_N_Entry_Call_Statement;
6316 --------------------------------
6317 -- Expand_N_Entry_Declaration --
6318 --------------------------------
6320 -- If there are parameters, then first, each of the formals is marked by
6321 -- setting Is_Entry_Formal. Next a record type is built which is used to
6322 -- hold the parameter values. The name of this record type is entryP where
6323 -- entry is the name of the entry, with an additional corresponding access
6324 -- type called entryPA. The record type has matching components for each
6325 -- formal (the component names are the same as the formal names). For
6326 -- elementary types, the component type matches the formal type. For
6327 -- composite types, an access type is declared (with the name formalA)
6328 -- which designates the formal type, and the type of the component is this
6329 -- access type. Finally the Entry_Component of each formal is set to
6330 -- reference the corresponding record component.
6332 procedure Expand_N_Entry_Declaration (N : Node_Id) is
6333 Loc : constant Source_Ptr := Sloc (N);
6334 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
6335 Components : List_Id;
6338 Last_Decl : Node_Id;
6339 Component : Entity_Id;
6342 Rec_Ent : Entity_Id;
6343 Acc_Ent : Entity_Id;
6346 Formal := First_Formal (Entry_Ent);
6349 -- Most processing is done only if parameters are present
6351 if Present (Formal) then
6352 Components := New_List;
6354 -- Loop through formals
6356 while Present (Formal) loop
6357 Set_Is_Entry_Formal (Formal);
6359 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
6360 Set_Entry_Component (Formal, Component);
6361 Set_Entry_Formal (Component, Formal);
6362 Ftype := Etype (Formal);
6364 -- Declare new access type and then append
6367 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6370 Make_Full_Type_Declaration (Loc,
6371 Defining_Identifier => Ctype,
6373 Make_Access_To_Object_Definition (Loc,
6374 All_Present => True,
6375 Constant_Present => Ekind (Formal) = E_In_Parameter,
6376 Subtype_Indication => New_Reference_To (Ftype, Loc)));
6378 Insert_After (Last_Decl, Decl);
6381 Append_To (Components,
6382 Make_Component_Declaration (Loc,
6383 Defining_Identifier => Component,
6384 Component_Definition =>
6385 Make_Component_Definition (Loc,
6386 Aliased_Present => False,
6387 Subtype_Indication => New_Reference_To (Ctype, Loc))));
6389 Next_Formal_With_Extras (Formal);
6392 -- Create the Entry_Parameter_Record declaration
6395 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
6398 Make_Full_Type_Declaration (Loc,
6399 Defining_Identifier => Rec_Ent,
6401 Make_Record_Definition (Loc,
6403 Make_Component_List (Loc,
6404 Component_Items => Components)));
6406 Insert_After (Last_Decl, Decl);
6409 -- Construct and link in the corresponding access type
6412 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6414 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
6417 Make_Full_Type_Declaration (Loc,
6418 Defining_Identifier => Acc_Ent,
6420 Make_Access_To_Object_Definition (Loc,
6421 All_Present => True,
6422 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
6424 Insert_After (Last_Decl, Decl);
6427 end Expand_N_Entry_Declaration;
6429 -----------------------------
6430 -- Expand_N_Protected_Body --
6431 -----------------------------
6433 -- Protected bodies are expanded to the completion of the subprograms
6434 -- created for the corresponding protected type. These are a protected and
6435 -- unprotected version of each protected subprogram in the object, a
6436 -- function to calculate each entry barrier, and a procedure to execute the
6437 -- sequence of statements of each protected entry body. For example, for
6438 -- protected type ptype:
6441 -- (O : System.Address;
6442 -- E : Protected_Entry_Index)
6445 -- <discriminant renamings>
6446 -- <private object renamings>
6448 -- return <barrier expression>;
6451 -- procedure pprocN (_object : in out poV;...) is
6452 -- <discriminant renamings>
6453 -- <private object renamings>
6455 -- <sequence of statements>
6458 -- procedure pprocP (_object : in out poV;...) is
6459 -- procedure _clean is
6462 -- ptypeS (_object, Pn);
6463 -- Unlock (_object._object'Access);
6464 -- Abort_Undefer.all;
6469 -- Lock (_object._object'Access);
6470 -- pprocN (_object;...);
6475 -- function pfuncN (_object : poV;...) return Return_Type is
6476 -- <discriminant renamings>
6477 -- <private object renamings>
6479 -- <sequence of statements>
6482 -- function pfuncP (_object : poV) return Return_Type is
6483 -- procedure _clean is
6485 -- Unlock (_object._object'Access);
6486 -- Abort_Undefer.all;
6491 -- Lock (_object._object'Access);
6492 -- return pfuncN (_object);
6499 -- (O : System.Address;
6500 -- P : System.Address;
6501 -- E : Protected_Entry_Index)
6503 -- <discriminant renamings>
6504 -- <private object renamings>
6505 -- type poVP is access poV;
6506 -- _Object : ptVP := ptVP!(O);
6510 -- <statement sequence>
6511 -- Complete_Entry_Body (_Object._Object);
6513 -- when all others =>
6514 -- Exceptional_Complete_Entry_Body (
6515 -- _Object._Object, Get_GNAT_Exception);
6519 -- The type poV is the record created for the protected type to hold
6520 -- the state of the protected object.
6522 procedure Expand_N_Protected_Body (N : Node_Id) is
6523 Loc : constant Source_Ptr := Sloc (N);
6524 Pid : constant Entity_Id := Corresponding_Spec (N);
6525 Has_Entries : Boolean := False;
6529 Disp_Op_Body : Node_Id;
6530 New_Op_Body : Node_Id;
6531 Current_Node : Node_Id;
6532 Num_Entries : Natural := 0;
6534 function Build_Dispatching_Subprogram_Body
6537 Prot_Bod : Node_Id) return Node_Id;
6538 -- Build a dispatching version of the protected subprogram body. The
6539 -- newly generated subprogram contains a call to the original protected
6540 -- body. The following code is generated:
6542 -- function <protected-function-name> (Param1 .. ParamN) return
6545 -- return <protected-function-name>P (Param1 .. ParamN);
6546 -- end <protected-function-name>;
6550 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
6552 -- <protected-procedure-name>P (Param1 .. ParamN);
6553 -- end <protected-procedure-name>
6555 ---------------------------------------
6556 -- Build_Dispatching_Subprogram_Body --
6557 ---------------------------------------
6559 function Build_Dispatching_Subprogram_Body
6562 Prot_Bod : Node_Id) return Node_Id
6564 Loc : constant Source_Ptr := Sloc (N);
6571 -- Generate a specification without a letter suffix in order to
6572 -- override an interface function or procedure.
6575 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
6577 -- The formal parameters become the actuals of the protected
6578 -- function or procedure call.
6580 Actuals := New_List;
6581 Formal := First (Parameter_Specifications (Spec));
6582 while Present (Formal) loop
6584 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
6589 if Nkind (Spec) = N_Procedure_Specification then
6592 Make_Procedure_Call_Statement (Loc,
6594 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
6595 Parameter_Associations => Actuals));
6597 pragma Assert (Nkind (Spec) = N_Function_Specification);
6601 Make_Return_Statement (Loc,
6603 Make_Function_Call (Loc,
6605 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
6606 Parameter_Associations => Actuals)));
6610 Make_Subprogram_Body (Loc,
6611 Declarations => Empty_List,
6612 Specification => Spec,
6613 Handled_Statement_Sequence =>
6614 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
6615 end Build_Dispatching_Subprogram_Body;
6617 -- Start of processing for Expand_N_Protected_Body
6620 if No_Run_Time_Mode then
6621 Error_Msg_CRT ("protected body", N);
6625 if Nkind (Parent (N)) = N_Subunit then
6627 -- This is the proper body corresponding to a stub. The declarations
6628 -- must be inserted at the point of the stub, which is in the decla-
6629 -- rative part of the parent unit.
6631 Current_Node := Corresponding_Stub (Parent (N));
6637 Op_Body := First (Declarations (N));
6639 -- The protected body is replaced with the bodies of its
6640 -- protected operations, and the declarations for internal objects
6641 -- that may have been created for entry family bounds.
6643 Rewrite (N, Make_Null_Statement (Sloc (N)));
6646 while Present (Op_Body) loop
6647 case Nkind (Op_Body) is
6648 when N_Subprogram_Declaration =>
6651 when N_Subprogram_Body =>
6653 -- Exclude functions created to analyze defaults
6655 if not Is_Eliminated (Defining_Entity (Op_Body))
6656 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
6659 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
6661 Insert_After (Current_Node, New_Op_Body);
6662 Current_Node := New_Op_Body;
6663 Analyze (New_Op_Body);
6665 Update_Prival_Subtypes (New_Op_Body);
6667 -- Build the corresponding protected operation only if
6668 -- this is a visible operation of the type, or if it is
6669 -- an interrupt handler. Otherwise it is only callable
6670 -- from within the object, and the unprotected version
6673 if Present (Corresponding_Spec (Op_Body)) then
6675 Unit_Declaration_Node (Corresponding_Spec (Op_Body));
6677 if Nkind (Parent (Op_Decl)) = N_Protected_Definition
6679 (List_Containing (Op_Decl) =
6680 Visible_Declarations (Parent (Op_Decl))
6682 Is_Interrupt_Handler
6683 (Corresponding_Spec (Op_Body)))
6686 Build_Protected_Subprogram_Body (
6687 Op_Body, Pid, Specification (New_Op_Body));
6689 Insert_After (Current_Node, New_Op_Body);
6690 Analyze (New_Op_Body);
6692 Current_Node := New_Op_Body;
6694 -- Generate an overriding primitive operation body for
6695 -- this subprogram if the protected type implements
6698 if Ada_Version >= Ada_05
6699 and then Present (Abstract_Interfaces (
6700 Corresponding_Record_Type (Pid)))
6703 Build_Dispatching_Subprogram_Body (
6704 Op_Body, Pid, New_Op_Body);
6706 Insert_After (Current_Node, Disp_Op_Body);
6707 Analyze (Disp_Op_Body);
6709 Current_Node := Disp_Op_Body;
6715 when N_Entry_Body =>
6716 Op_Id := Defining_Identifier (Op_Body);
6717 Has_Entries := True;
6718 Num_Entries := Num_Entries + 1;
6720 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
6722 Insert_After (Current_Node, New_Op_Body);
6723 Current_Node := New_Op_Body;
6724 Analyze (New_Op_Body);
6726 Update_Prival_Subtypes (New_Op_Body);
6728 when N_Implicit_Label_Declaration =>
6731 when N_Itype_Reference =>
6732 Insert_After (Current_Node, New_Copy (Op_Body));
6734 when N_Freeze_Entity =>
6735 New_Op_Body := New_Copy (Op_Body);
6737 if Present (Entity (Op_Body))
6738 and then Freeze_Node (Entity (Op_Body)) = Op_Body
6740 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
6743 Insert_After (Current_Node, New_Op_Body);
6744 Current_Node := New_Op_Body;
6745 Analyze (New_Op_Body);
6748 New_Op_Body := New_Copy (Op_Body);
6749 Insert_After (Current_Node, New_Op_Body);
6750 Current_Node := New_Op_Body;
6751 Analyze (New_Op_Body);
6753 when N_Object_Declaration =>
6754 pragma Assert (not Comes_From_Source (Op_Body));
6755 New_Op_Body := New_Copy (Op_Body);
6756 Insert_After (Current_Node, New_Op_Body);
6757 Current_Node := New_Op_Body;
6758 Analyze (New_Op_Body);
6761 raise Program_Error;
6768 -- Finally, create the body of the function that maps an entry index
6769 -- into the corresponding body index, except when there is no entry,
6770 -- or in a ravenscar-like profile (no abort, no entry queue, 1 entry)
6773 and then (Abort_Allowed
6774 or else Restriction_Active (No_Entry_Queue) = False
6775 or else Num_Entries > 1)
6777 New_Op_Body := Build_Find_Body_Index (Pid);
6778 Insert_After (Current_Node, New_Op_Body);
6779 Current_Node := New_Op_Body;
6780 Analyze (New_Op_Body);
6783 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
6784 -- the protected body. At this point the entry specs have been created,
6785 -- frozen and included in the dispatch table for the protected type.
6787 pragma Assert (Present (Corresponding_Record_Type (Pid)));
6789 if Ada_Version >= Ada_05
6790 and then Present (Protected_Definition (Parent (Pid)))
6791 and then Present (Abstract_Interfaces
6792 (Corresponding_Record_Type (Pid)))
6795 Vis_Decl : Node_Id :=
6796 First (Visible_Declarations
6797 (Protected_Definition (Parent (Pid))));
6798 Wrap_Body : Node_Id;
6801 -- Examine the visible declarations of the protected type, looking
6802 -- for an entry declaration. We do not consider entry families
6803 -- since they cannot have dispatching operations, thus they do not
6804 -- need entry wrappers.
6806 while Present (Vis_Decl) loop
6807 if Nkind (Vis_Decl) = N_Entry_Declaration then
6809 Build_Wrapper_Body (Loc,
6810 Proc_Nam => Defining_Identifier (Vis_Decl),
6811 Obj_Typ => Corresponding_Record_Type (Pid),
6812 Formals => Parameter_Specifications (Vis_Decl));
6814 if Wrap_Body /= Empty then
6815 Insert_After (Current_Node, Wrap_Body);
6816 Current_Node := Wrap_Body;
6818 Analyze (Wrap_Body);
6821 elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then
6823 Build_Wrapper_Body (Loc,
6824 Proc_Nam => Defining_Unit_Name
6825 (Specification (Vis_Decl)),
6826 Obj_Typ => Corresponding_Record_Type (Pid),
6827 Formals => Parameter_Specifications
6828 (Specification (Vis_Decl)));
6830 if Wrap_Body /= Empty then
6831 Insert_After (Current_Node, Wrap_Body);
6832 Current_Node := Wrap_Body;
6834 Analyze (Wrap_Body);
6842 end Expand_N_Protected_Body;
6844 -----------------------------------------
6845 -- Expand_N_Protected_Type_Declaration --
6846 -----------------------------------------
6848 -- First we create a corresponding record type declaration used to
6849 -- represent values of this protected type.
6850 -- The general form of this type declaration is
6852 -- type poV (discriminants) is record
6853 -- _Object : aliased <kind>Protection
6854 -- [(<entry count> [, <handler count>])];
6855 -- [entry_family : array (bounds) of Void;]
6856 -- <private data fields>
6859 -- The discriminants are present only if the corresponding protected type
6860 -- has discriminants, and they exactly mirror the protected type
6861 -- discriminants. The private data fields similarly mirror the private
6862 -- declarations of the protected type.
6864 -- The Object field is always present. It contains RTS specific data used
6865 -- to control the protected object. It is declared as Aliased so that it
6866 -- can be passed as a pointer to the RTS. This allows the protected record
6867 -- to be referenced within RTS data structures. An appropriate Protection
6868 -- type and discriminant are generated.
6870 -- The Service field is present for protected objects with entries. It
6871 -- contains sufficient information to allow the entry service procedure for
6872 -- this object to be called when the object is not known till runtime.
6874 -- One entry_family component is present for each entry family in the
6875 -- task definition (see Expand_N_Task_Type_Declaration).
6877 -- When a protected object is declared, an instance of the protected type
6878 -- value record is created. The elaboration of this declaration creates the
6879 -- correct bounds for the entry families, and also evaluates the priority
6880 -- expression if needed. The initialization routine for the protected type
6881 -- itself then calls Initialize_Protection with appropriate parameters to
6882 -- initialize the value of the Task_Id field. Install_Handlers may be also
6883 -- called if a pragma Attach_Handler applies.
6885 -- Note: this record is passed to the subprograms created by the expansion
6886 -- of protected subprograms and entries. It is an in parameter to protected
6887 -- functions and an in out parameter to procedures and entry bodies. The
6888 -- Entity_Id for this created record type is placed in the
6889 -- Corresponding_Record_Type field of the associated protected type entity.
6891 -- Next we create a procedure specifications for protected subprograms and
6892 -- entry bodies. For each protected subprograms two subprograms are
6893 -- created, an unprotected and a protected version. The unprotected version
6894 -- is called from within other operations of the same protected object.
6896 -- We also build the call to register the procedure if a pragma
6897 -- Interrupt_Handler applies.
6899 -- A single subprogram is created to service all entry bodies; it has an
6900 -- additional boolean out parameter indicating that the previous entry call
6901 -- made by the current task was serviced immediately, i.e. not by proxy.
6902 -- The O parameter contains a pointer to a record object of the type
6903 -- described above. An untyped interface is used here to allow this
6904 -- procedure to be called in places where the type of the object to be
6905 -- serviced is not known. This must be done, for example, when a call that
6906 -- may have been requeued is cancelled; the corresponding object must be
6907 -- serviced, but which object that is not known till runtime.
6910 -- (O : System.Address; P : out Boolean);
6911 -- procedure pprocN (_object : in out poV);
6912 -- procedure pproc (_object : in out poV);
6913 -- function pfuncN (_object : poV);
6914 -- function pfunc (_object : poV);
6917 -- Note that this must come after the record type declaration, since
6918 -- the specs refer to this type.
6920 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
6921 Loc : constant Source_Ptr := Sloc (N);
6922 Prottyp : constant Entity_Id := Defining_Identifier (N);
6924 Pdef : constant Node_Id := Protected_Definition (N);
6925 -- This contains two lists; one for visible and one for private decls
6929 Discr_Map : constant Elist_Id := New_Elmt_List;
6934 Comp_Id : Entity_Id;
6936 Current_Node : Node_Id := N;
6937 Bdef : Entity_Id := Empty; -- avoid uninit warning
6938 Edef : Entity_Id := Empty; -- avoid uninit warning
6939 Entries_Aggr : Node_Id;
6940 Body_Id : Entity_Id;
6943 Object_Comp : Node_Id;
6945 procedure Register_Handler;
6946 -- For a protected operation that is an interrupt handler, add the
6947 -- freeze action that will register it as such.
6949 ----------------------
6950 -- Register_Handler --
6951 ----------------------
6953 procedure Register_Handler is
6955 -- All semantic checks already done in Sem_Prag
6957 Prot_Proc : constant Entity_Id :=
6959 (Specification (Current_Node));
6961 Proc_Address : constant Node_Id :=
6962 Make_Attribute_Reference (Loc,
6963 Prefix => New_Reference_To (Prot_Proc, Loc),
6964 Attribute_Name => Name_Address);
6966 RTS_Call : constant Entity_Id :=
6967 Make_Procedure_Call_Statement (Loc,
6970 RTE (RE_Register_Interrupt_Handler), Loc),
6971 Parameter_Associations =>
6972 New_List (Proc_Address));
6974 Append_Freeze_Action (Prot_Proc, RTS_Call);
6975 end Register_Handler;
6977 -- Start of processing for Expand_N_Protected_Type_Declaration
6980 if Present (Corresponding_Record_Type (Prottyp)) then
6983 Rec_Decl := Build_Corresponding_Record (N, Prottyp, Loc);
6984 Cdecls := Component_Items
6985 (Component_List (Type_Definition (Rec_Decl)));
6988 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
6989 -- of implemented interfaces.
6991 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
6993 Qualify_Entity_Names (N);
6995 -- If the type has discriminants, their occurrences in the declaration
6996 -- have been replaced by the corresponding discriminals. For components
6997 -- that are constrained by discriminants, their homologues in the
6998 -- corresponding record type must refer to the discriminants of that
6999 -- record, so we must apply a new renaming to subtypes_indications:
7001 -- protected discriminant => discriminal => record discriminant
7003 -- This replacement is not applied to default expressions, for which
7004 -- the discriminal is correct.
7006 if Has_Discriminants (Prottyp) then
7011 Disc := First_Discriminant (Prottyp);
7012 Decl := First (Discriminant_Specifications (Rec_Decl));
7013 while Present (Disc) loop
7014 Append_Elmt (Discriminal (Disc), Discr_Map);
7015 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7016 Next_Discriminant (Disc);
7022 -- Fill in the component declarations
7024 -- Add components for entry families. For each entry family, create an
7025 -- anonymous type declaration with the same size, and analyze the type.
7027 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prottyp);
7029 -- Prepend the _Object field with the right type to the component list.
7030 -- We need to compute the number of entries, and in some cases the
7031 -- number of Attach_Handler pragmas.
7035 Num_Attach_Handler : Int := 0;
7036 Protection_Subtype : Node_Id;
7037 Entry_Count_Expr : constant Node_Id :=
7038 Build_Entry_Count_Expression
7039 (Prottyp, Cdecls, Loc);
7042 if Has_Attach_Handler (Prottyp) then
7043 Ritem := First_Rep_Item (Prottyp);
7044 while Present (Ritem) loop
7045 if Nkind (Ritem) = N_Pragma
7046 and then Chars (Ritem) = Name_Attach_Handler
7048 Num_Attach_Handler := Num_Attach_Handler + 1;
7051 Next_Rep_Item (Ritem);
7054 if Restricted_Profile then
7055 if Has_Entries (Prottyp) then
7056 Protection_Subtype :=
7057 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7059 Protection_Subtype :=
7060 New_Reference_To (RTE (RE_Protection), Loc);
7063 Protection_Subtype :=
7064 Make_Subtype_Indication
7068 (RTE (RE_Static_Interrupt_Protection), Loc),
7070 Make_Index_Or_Discriminant_Constraint (
7072 Constraints => New_List (
7074 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7077 elsif Has_Interrupt_Handler (Prottyp) then
7078 Protection_Subtype :=
7079 Make_Subtype_Indication (
7081 Subtype_Mark => New_Reference_To
7082 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7084 Make_Index_Or_Discriminant_Constraint (
7086 Constraints => New_List (Entry_Count_Expr)));
7088 -- Type has explicit entries or generated primitive entry wrappers
7090 elsif Has_Entries (Prottyp)
7091 or else (Ada_Version >= Ada_05
7092 and then Present (Interface_List (N)))
7095 or else Restriction_Active (No_Entry_Queue) = False
7096 or else Number_Entries (Prottyp) > 1
7098 Protection_Subtype :=
7099 Make_Subtype_Indication (
7102 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7104 Make_Index_Or_Discriminant_Constraint (
7106 Constraints => New_List (Entry_Count_Expr)));
7109 Protection_Subtype :=
7110 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7114 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7118 Make_Component_Declaration (Loc,
7119 Defining_Identifier =>
7120 Make_Defining_Identifier (Loc, Name_uObject),
7121 Component_Definition =>
7122 Make_Component_Definition (Loc,
7123 Aliased_Present => True,
7124 Subtype_Indication => Protection_Subtype));
7127 pragma Assert (Present (Pdef));
7129 -- Add private field components
7131 if Present (Private_Declarations (Pdef)) then
7132 Priv := First (Private_Declarations (Pdef));
7134 while Present (Priv) loop
7136 if Nkind (Priv) = N_Component_Declaration then
7137 Pent := Defining_Identifier (Priv);
7139 Make_Component_Declaration (Loc,
7140 Defining_Identifier =>
7141 Make_Defining_Identifier (Sloc (Pent), Chars (Pent)),
7142 Component_Definition =>
7143 Make_Component_Definition (Sloc (Pent),
7144 Aliased_Present => False,
7145 Subtype_Indication =>
7146 New_Copy_Tree (Subtype_Indication
7147 (Component_Definition (Priv)),
7149 Expression => Expression (Priv));
7151 Append_To (Cdecls, New_Priv);
7153 elsif Nkind (Priv) = N_Subprogram_Declaration then
7155 -- Make the unprotected version of the subprogram available
7156 -- for expansion of intra object calls. There is need for
7157 -- a protected version only if the subprogram is an interrupt
7158 -- handler, otherwise this operation can only be called from
7162 Make_Subprogram_Declaration (Loc,
7164 Build_Protected_Sub_Specification
7165 (Priv, Prottyp, Unprotected_Mode));
7167 Insert_After (Current_Node, Sub);
7170 Set_Protected_Body_Subprogram
7171 (Defining_Unit_Name (Specification (Priv)),
7172 Defining_Unit_Name (Specification (Sub)));
7174 Current_Node := Sub;
7176 if Is_Interrupt_Handler
7177 (Defining_Unit_Name (Specification (Priv)))
7180 Make_Subprogram_Declaration (Loc,
7182 Build_Protected_Sub_Specification
7183 (Priv, Prottyp, Protected_Mode));
7185 Insert_After (Current_Node, Sub);
7187 Current_Node := Sub;
7189 if not Restricted_Profile then
7199 -- Put the _Object component after the private component so that it
7200 -- be finalized early as required by 9.4 (20)
7202 Append_To (Cdecls, Object_Comp);
7204 Insert_After (Current_Node, Rec_Decl);
7205 Current_Node := Rec_Decl;
7207 -- Analyze the record declaration immediately after construction,
7208 -- because the initialization procedure is needed for single object
7209 -- declarations before the next entity is analyzed (the freeze call
7210 -- that generates this initialization procedure is found below).
7212 Analyze (Rec_Decl, Suppress => All_Checks);
7214 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7215 -- the corresponding record is frozen
7217 if Ada_Version >= Ada_05
7218 and then Present (Visible_Declarations (Pdef))
7219 and then Present (Corresponding_Record_Type
7220 (Defining_Identifier (Parent (Pdef))))
7221 and then Present (Abstract_Interfaces
7222 (Corresponding_Record_Type
7223 (Defining_Identifier (Parent (Pdef)))))
7226 Current_Node : Node_Id := Rec_Decl;
7228 Wrap_Spec : Node_Id;
7232 -- Examine the visible declarations of the protected type, looking
7233 -- for declarations of entries, and subprograms. We do not
7234 -- consider entry families since they cannot have dispatching
7235 -- operations, thus they do not need entry wrappers.
7237 Vis_Decl := First (Visible_Declarations (Pdef));
7239 while Present (Vis_Decl) loop
7243 if Nkind (Vis_Decl) = N_Entry_Declaration
7244 and then not Present (Discrete_Subtype_Definition (Vis_Decl))
7247 Build_Wrapper_Spec (Loc,
7248 Proc_Nam => Defining_Identifier (Vis_Decl),
7249 Obj_Typ => Defining_Identifier (Rec_Decl),
7250 Formals => Parameter_Specifications (Vis_Decl));
7252 elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then
7254 Build_Wrapper_Spec (Loc,
7255 Proc_Nam => Defining_Unit_Name
7256 (Specification (Vis_Decl)),
7257 Obj_Typ => Defining_Identifier (Rec_Decl),
7258 Formals => Parameter_Specifications
7259 (Specification (Vis_Decl)));
7263 if Wrap_Spec /= Empty then
7264 New_N := Make_Subprogram_Declaration (Loc,
7265 Specification => Wrap_Spec);
7267 Insert_After (Current_Node, New_N);
7268 Current_Node := New_N;
7278 -- Collect pointers to entry bodies and their barriers, to be placed
7279 -- in the Entry_Bodies_Array for the type. For each entry/family we
7280 -- add an expression to the aggregate which is the initial value of
7281 -- this array. The array is declared after all protected subprograms.
7283 if Has_Entries (Prottyp) then
7285 Make_Aggregate (Loc, Expressions => New_List);
7288 Entries_Aggr := Empty;
7291 -- Build two new procedure specifications for each protected subprogram;
7292 -- one to call from outside the object and one to call from inside.
7293 -- Build a barrier function and an entry body action procedure
7294 -- specification for each protected entry. Initialize the entry body
7295 -- array. If subprogram is flagged as eliminated, do not generate any
7296 -- internal operations.
7300 Comp := First (Visible_Declarations (Pdef));
7302 while Present (Comp) loop
7303 if Nkind (Comp) = N_Subprogram_Declaration
7304 and then not Is_Eliminated (Defining_Entity (Comp))
7307 Make_Subprogram_Declaration (Loc,
7309 Build_Protected_Sub_Specification
7310 (Comp, Prottyp, Unprotected_Mode));
7312 Insert_After (Current_Node, Sub);
7315 Set_Protected_Body_Subprogram
7316 (Defining_Unit_Name (Specification (Comp)),
7317 Defining_Unit_Name (Specification (Sub)));
7319 -- Make the protected version of the subprogram available for
7320 -- expansion of external calls.
7322 Current_Node := Sub;
7325 Make_Subprogram_Declaration (Loc,
7327 Build_Protected_Sub_Specification
7328 (Comp, Prottyp, Protected_Mode));
7330 Insert_After (Current_Node, Sub);
7333 Current_Node := Sub;
7335 -- Generate an overriding primitive operation specification for
7336 -- this subprogram if the protected type implements an inerface.
7338 if Ada_Version >= Ada_05
7340 Present (Abstract_Interfaces
7341 (Corresponding_Record_Type (Prottyp)))
7344 Make_Subprogram_Declaration (Loc,
7346 Build_Protected_Sub_Specification
7347 (Comp, Prottyp, Dispatching_Mode));
7349 Insert_After (Current_Node, Sub);
7352 Current_Node := Sub;
7355 -- If a pragma Interrupt_Handler applies, build and add a call to
7356 -- Register_Interrupt_Handler to the freezing actions of the
7357 -- protected version (Current_Node) of the subprogram:
7359 -- system.interrupts.register_interrupt_handler
7360 -- (prot_procP'address);
7362 if not Restricted_Profile
7363 and then Is_Interrupt_Handler
7364 (Defining_Unit_Name (Specification (Comp)))
7369 elsif Nkind (Comp) = N_Entry_Declaration then
7370 E_Count := E_Count + 1;
7371 Comp_Id := Defining_Identifier (Comp);
7372 Set_Privals_Chain (Comp_Id, New_Elmt_List);
7374 Make_Defining_Identifier (Loc,
7375 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7377 Make_Subprogram_Declaration (Loc,
7379 Build_Protected_Entry_Specification (Edef, Comp_Id, Loc));
7381 Insert_After (Current_Node, Sub);
7384 Set_Protected_Body_Subprogram (
7385 Defining_Identifier (Comp),
7386 Defining_Unit_Name (Specification (Sub)));
7388 Current_Node := Sub;
7391 Make_Defining_Identifier (Loc,
7392 Build_Selected_Name (Prottyp, Comp_Id, 'B'));
7394 Make_Subprogram_Declaration (Loc,
7396 Build_Barrier_Function_Specification (Bdef, Loc));
7398 Insert_After (Current_Node, Sub);
7400 Set_Protected_Body_Subprogram (Bdef, Bdef);
7401 Set_Barrier_Function (Comp_Id, Bdef);
7402 Set_Scope (Bdef, Scope (Comp_Id));
7403 Current_Node := Sub;
7405 -- Collect pointers to the protected subprogram and the barrier
7406 -- of the current entry, for insertion into Entry_Bodies_Array.
7409 Make_Aggregate (Loc,
7410 Expressions => New_List (
7411 Make_Attribute_Reference (Loc,
7412 Prefix => New_Reference_To (Bdef, Loc),
7413 Attribute_Name => Name_Unrestricted_Access),
7414 Make_Attribute_Reference (Loc,
7415 Prefix => New_Reference_To (Edef, Loc),
7416 Attribute_Name => Name_Unrestricted_Access))),
7417 Expressions (Entries_Aggr));
7424 -- If there are some private entry declarations, expand it as if they
7425 -- were visible entries.
7427 if Present (Private_Declarations (Pdef)) then
7428 Comp := First (Private_Declarations (Pdef));
7429 while Present (Comp) loop
7430 if Nkind (Comp) = N_Entry_Declaration then
7431 E_Count := E_Count + 1;
7432 Comp_Id := Defining_Identifier (Comp);
7433 Set_Privals_Chain (Comp_Id, New_Elmt_List);
7435 Make_Defining_Identifier (Loc,
7436 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7439 Make_Subprogram_Declaration (Loc,
7441 Build_Protected_Entry_Specification (Edef, Comp_Id, Loc));
7443 Insert_After (Current_Node, Sub);
7446 Set_Protected_Body_Subprogram (
7447 Defining_Identifier (Comp),
7448 Defining_Unit_Name (Specification (Sub)));
7450 Current_Node := Sub;
7453 Make_Defining_Identifier (Loc,
7454 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7457 Make_Subprogram_Declaration (Loc,
7459 Build_Barrier_Function_Specification (Bdef, Loc));
7461 Insert_After (Current_Node, Sub);
7463 Set_Protected_Body_Subprogram (Bdef, Bdef);
7464 Set_Barrier_Function (Comp_Id, Bdef);
7465 Set_Scope (Bdef, Scope (Comp_Id));
7466 Current_Node := Sub;
7468 -- Collect pointers to the protected subprogram and the barrier
7469 -- of the current entry, for insertion into Entry_Bodies_Array.
7472 Make_Aggregate (Loc,
7473 Expressions => New_List (
7474 Make_Attribute_Reference (Loc,
7475 Prefix => New_Reference_To (Bdef, Loc),
7476 Attribute_Name => Name_Unrestricted_Access),
7477 Make_Attribute_Reference (Loc,
7478 Prefix => New_Reference_To (Edef, Loc),
7479 Attribute_Name => Name_Unrestricted_Access))),
7480 Expressions (Entries_Aggr));
7487 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
7488 -- all protected subprograms have been collected.
7490 if Has_Entries (Prottyp) then
7491 Body_Id := Make_Defining_Identifier (Sloc (Prottyp),
7492 New_External_Name (Chars (Prottyp), 'A'));
7495 or else Restriction_Active (No_Entry_Queue) = False
7498 Body_Arr := Make_Object_Declaration (Loc,
7499 Defining_Identifier => Body_Id,
7500 Aliased_Present => True,
7501 Object_Definition =>
7502 Make_Subtype_Indication (Loc,
7503 Subtype_Mark => New_Reference_To (
7504 RTE (RE_Protected_Entry_Body_Array), Loc),
7506 Make_Index_Or_Discriminant_Constraint (Loc,
7507 Constraints => New_List (
7509 Make_Integer_Literal (Loc, 1),
7510 Make_Integer_Literal (Loc, E_Count))))),
7511 Expression => Entries_Aggr);
7514 Body_Arr := Make_Object_Declaration (Loc,
7515 Defining_Identifier => Body_Id,
7516 Aliased_Present => True,
7517 Object_Definition => New_Reference_To (RTE (RE_Entry_Body), Loc),
7519 Make_Aggregate (Loc,
7520 Expressions => New_List (
7521 Make_Attribute_Reference (Loc,
7522 Prefix => New_Reference_To (Bdef, Loc),
7523 Attribute_Name => Name_Unrestricted_Access),
7524 Make_Attribute_Reference (Loc,
7525 Prefix => New_Reference_To (Edef, Loc),
7526 Attribute_Name => Name_Unrestricted_Access))));
7529 -- A pointer to this array will be placed in the corresponding record
7530 -- by its initialization procedure so this needs to be analyzed here.
7532 Insert_After (Current_Node, Body_Arr);
7533 Current_Node := Body_Arr;
7536 Set_Entry_Bodies_Array (Prottyp, Body_Id);
7538 -- Finally, build the function that maps an entry index into the
7539 -- corresponding body. A pointer to this function is placed in each
7540 -- object of the type. Except for a ravenscar-like profile (no abort,
7541 -- no entry queue, 1 entry)
7544 or else Restriction_Active (No_Entry_Queue) = False
7548 Make_Subprogram_Declaration (Loc,
7549 Specification => Build_Find_Body_Index_Spec (Prottyp));
7550 Insert_After (Current_Node, Sub);
7554 end Expand_N_Protected_Type_Declaration;
7556 --------------------------------
7557 -- Expand_N_Requeue_Statement --
7558 --------------------------------
7560 -- A requeue statement is expanded into one of four GNARLI operations,
7561 -- depending on the source and destination (task or protected object). In
7562 -- addition, code must be generated to jump around the remainder of
7563 -- processing for the original entry and, if the destination is (different)
7564 -- protected object, to attempt to service it. The following illustrates
7565 -- the various cases:
7568 -- (O : System.Address;
7569 -- P : System.Address;
7570 -- E : Protected_Entry_Index)
7572 -- <discriminant renamings>
7573 -- <private object renamings>
7574 -- type poVP is access poV;
7575 -- _Object : ptVP := ptVP!(O);
7579 -- <start of statement sequence for entry>
7581 -- -- Requeue from one protected entry body to another protected
7584 -- Requeue_Protected_Entry (
7585 -- _object._object'Access,
7586 -- new._object'Access,
7591 -- <some more of the statement sequence for entry>
7593 -- -- Requeue from an entry body to a task entry
7595 -- Requeue_Protected_To_Task_Entry (
7601 -- <rest of statement sequence for entry>
7602 -- Complete_Entry_Body (_Object._Object);
7605 -- when all others =>
7606 -- Exceptional_Complete_Entry_Body (
7607 -- _Object._Object, Get_GNAT_Exception);
7611 -- Requeue of a task entry call to a task entry
7613 -- Accept_Call (E, Ann);
7614 -- <start of statement sequence for accept statement>
7615 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
7617 -- <rest of statement sequence for accept statement>
7619 -- Complete_Rendezvous;
7622 -- when all others =>
7623 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7625 -- Requeue of a task entry call to a protected entry
7627 -- Accept_Call (E, Ann);
7628 -- <start of statement sequence for accept statement>
7629 -- Requeue_Task_To_Protected_Entry (
7630 -- new._object'Access,
7635 -- <rest of statement sequence for accept statement>
7637 -- Complete_Rendezvous;
7640 -- when all others =>
7641 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7643 -- Further details on these expansions can be found in
7644 -- Expand_N_Protected_Body and Expand_N_Accept_Statement.
7646 procedure Expand_N_Requeue_Statement (N : Node_Id) is
7647 Loc : constant Source_Ptr := Sloc (N);
7652 Conctyp : Entity_Id;
7656 Abortable : Node_Id;
7657 Skip_Stat : Node_Id;
7658 Self_Param : Node_Id;
7659 New_Param : Node_Id;
7661 RTS_Call : Entity_Id;
7665 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
7667 -- Set up the target object
7669 Extract_Entry (N, Concval, Ename, Index);
7670 Conctyp := Etype (Concval);
7671 New_Param := Concurrent_Ref (Concval);
7673 -- The target entry index and abortable flag are the same for all cases
7675 Params := New_List (
7676 Entry_Index_Expression (Loc, Entity (Ename), Index, Conctyp),
7679 -- Determine proper GNARLI call and required additional parameters
7680 -- Loop to find nearest enclosing task type or protected type
7682 Oldtyp := Current_Scope;
7684 if Is_Task_Type (Oldtyp) then
7685 if Is_Task_Type (Conctyp) then
7686 RTS_Call := RTE (RE_Requeue_Task_Entry);
7689 pragma Assert (Is_Protected_Type (Conctyp));
7690 RTS_Call := RTE (RE_Requeue_Task_To_Protected_Entry);
7692 Make_Attribute_Reference (Loc,
7693 Prefix => New_Param,
7694 Attribute_Name => Name_Unchecked_Access);
7697 Prepend (New_Param, Params);
7700 elsif Is_Protected_Type (Oldtyp) then
7702 Make_Attribute_Reference (Loc,
7703 Prefix => Concurrent_Ref (New_Occurrence_Of (Oldtyp, Loc)),
7704 Attribute_Name => Name_Unchecked_Access);
7706 if Is_Task_Type (Conctyp) then
7707 RTS_Call := RTE (RE_Requeue_Protected_To_Task_Entry);
7710 pragma Assert (Is_Protected_Type (Conctyp));
7711 RTS_Call := RTE (RE_Requeue_Protected_Entry);
7713 Make_Attribute_Reference (Loc,
7714 Prefix => New_Param,
7715 Attribute_Name => Name_Unchecked_Access);
7718 Prepend (New_Param, Params);
7719 Prepend (Self_Param, Params);
7722 -- If neither task type or protected type, must be in some inner
7723 -- enclosing block, so move on out
7726 Oldtyp := Scope (Oldtyp);
7730 -- Create the GNARLI call
7732 Rcall := Make_Procedure_Call_Statement (Loc,
7734 New_Occurrence_Of (RTS_Call, Loc),
7735 Parameter_Associations => Params);
7740 if Is_Protected_Type (Oldtyp) then
7742 -- Build the return statement to skip the rest of the entry body
7744 Skip_Stat := Make_Return_Statement (Loc);
7747 -- If the requeue is within a task, find the end label of the
7748 -- enclosing accept statement.
7750 Acc_Stat := Parent (N);
7751 while Nkind (Acc_Stat) /= N_Accept_Statement loop
7752 Acc_Stat := Parent (Acc_Stat);
7755 -- The last statement is the second label, used for completing the
7756 -- rendezvous the usual way. The label we are looking for is right
7760 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
7762 pragma Assert (Nkind (Lab_Node) = N_Label);
7764 -- Build the goto statement to skip the rest of the accept
7768 Make_Goto_Statement (Loc,
7769 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
7772 Set_Analyzed (Skip_Stat);
7774 Insert_After (N, Skip_Stat);
7775 end Expand_N_Requeue_Statement;
7777 -------------------------------
7778 -- Expand_N_Selective_Accept --
7779 -------------------------------
7781 procedure Expand_N_Selective_Accept (N : Node_Id) is
7782 Loc : constant Source_Ptr := Sloc (N);
7783 Alts : constant List_Id := Select_Alternatives (N);
7785 -- Note: in the below declarations a lot of new lists are allocated
7786 -- unconditionally which may well not end up being used. That's
7787 -- not a good idea since it wastes space gratuitously ???
7789 Accept_Case : List_Id;
7790 Accept_List : constant List_Id := New_List;
7793 Alt_List : constant List_Id := New_List;
7794 Alt_Stats : List_Id;
7795 Ann : Entity_Id := Empty;
7798 Check_Guard : Boolean := True;
7800 Decls : constant List_Id := New_List;
7801 Stats : constant List_Id := New_List;
7802 Body_List : constant List_Id := New_List;
7803 Trailing_List : constant List_Id := New_List;
7806 Else_Present : Boolean := False;
7807 Terminate_Alt : Node_Id := Empty;
7808 Select_Mode : Node_Id;
7810 Delay_Case : List_Id;
7811 Delay_Count : Integer := 0;
7812 Delay_Val : Entity_Id;
7813 Delay_Index : Entity_Id;
7814 Delay_Min : Entity_Id;
7815 Delay_Num : Int := 1;
7816 Delay_Alt_List : List_Id := New_List;
7817 Delay_List : constant List_Id := New_List;
7821 First_Delay : Boolean := True;
7822 Guard_Open : Entity_Id;
7828 Num_Accept : Nat := 0;
7831 Time_Type : Entity_Id;
7833 Select_Call : Node_Id;
7835 Qnam : constant Entity_Id :=
7836 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
7838 Xnam : constant Entity_Id :=
7839 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
7841 -----------------------
7842 -- Local subprograms --
7843 -----------------------
7845 function Accept_Or_Raise return List_Id;
7846 -- For the rare case where delay alternatives all have guards, and
7847 -- all of them are closed, it is still possible that there were open
7848 -- accept alternatives with no callers. We must reexamine the
7849 -- Accept_List, and execute a selective wait with no else if some
7850 -- accept is open. If none, we raise program_error.
7852 procedure Add_Accept (Alt : Node_Id);
7853 -- Process a single accept statement in a select alternative. Build
7854 -- procedure for body of accept, and add entry to dispatch table with
7855 -- expression for guard, in preparation for call to run time select.
7857 function Make_And_Declare_Label (Num : Int) return Node_Id;
7858 -- Manufacture a label using Num as a serial number and declare it.
7859 -- The declaration is appended to Decls. The label marks the trailing
7860 -- statements of an accept or delay alternative.
7862 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
7863 -- Build call to Selective_Wait runtime routine
7865 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
7866 -- Add code to compare value of delay with previous values, and
7867 -- generate case entry for trailing statements.
7869 procedure Process_Accept_Alternative
7873 -- Add code to call corresponding procedure, and branch to
7874 -- trailing statements, if any.
7876 ---------------------
7877 -- Accept_Or_Raise --
7878 ---------------------
7880 function Accept_Or_Raise return List_Id is
7883 J : constant Entity_Id := Make_Defining_Identifier (Loc,
7884 New_Internal_Name ('J'));
7887 -- We generate the following:
7889 -- for J in q'range loop
7890 -- if q(J).S /=null_task_entry then
7891 -- selective_wait (simple_mode,...);
7897 -- if no rendez_vous then
7898 -- raise program_error;
7901 -- Note that the code needs to know that the selector name
7902 -- in an Accept_Alternative is named S.
7904 Cond := Make_Op_Ne (Loc,
7906 Make_Selected_Component (Loc,
7907 Prefix => Make_Indexed_Component (Loc,
7908 Prefix => New_Reference_To (Qnam, Loc),
7909 Expressions => New_List (New_Reference_To (J, Loc))),
7910 Selector_Name => Make_Identifier (Loc, Name_S)),
7912 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
7915 Make_Implicit_Loop_Statement (N,
7916 Identifier => Empty,
7918 Make_Iteration_Scheme (Loc,
7919 Loop_Parameter_Specification =>
7920 Make_Loop_Parameter_Specification (Loc,
7921 Defining_Identifier => J,
7922 Discrete_Subtype_Definition =>
7923 Make_Attribute_Reference (Loc,
7924 Prefix => New_Reference_To (Qnam, Loc),
7925 Attribute_Name => Name_Range,
7926 Expressions => New_List (
7927 Make_Integer_Literal (Loc, 1))))),
7929 Statements => New_List (
7930 Make_Implicit_If_Statement (N,
7932 Then_Statements => New_List (
7934 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
7935 Make_Exit_Statement (Loc))))));
7938 Make_Raise_Program_Error (Loc,
7939 Condition => Make_Op_Eq (Loc,
7940 Left_Opnd => New_Reference_To (Xnam, Loc),
7942 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
7943 Reason => PE_All_Guards_Closed));
7946 end Accept_Or_Raise;
7952 procedure Add_Accept (Alt : Node_Id) is
7953 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
7954 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
7955 Eent : constant Entity_Id := Entity (Ename);
7956 Index : constant Node_Id := Entry_Index (Acc_Stm);
7957 Null_Body : Node_Id;
7958 Proc_Body : Node_Id;
7965 Ann := Node (Last_Elmt (Accept_Address (Eent)));
7968 if Present (Condition (Alt)) then
7970 Make_Conditional_Expression (Loc, New_List (
7972 Entry_Index_Expression (Loc, Eent, Index, Scope (Eent)),
7973 New_Reference_To (RTE (RE_Null_Task_Entry), Loc)));
7976 Entry_Index_Expression
7977 (Loc, Eent, Index, Scope (Eent));
7980 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
7981 Null_Body := New_Reference_To (Standard_False, Loc);
7983 if Abort_Allowed then
7984 Call := Make_Procedure_Call_Statement (Loc,
7985 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc));
7986 Insert_Before (First (Statements (Handled_Statement_Sequence (
7987 Accept_Statement (Alt)))), Call);
7992 Make_Defining_Identifier (Sloc (Ename),
7993 New_External_Name (Chars (Ename), 'A', Num_Accept));
7995 Set_Needs_Debug_Info (PB_Ent, Comes_From_Source (Alt));
7998 Make_Subprogram_Body (Loc,
8000 Make_Procedure_Specification (Loc,
8001 Defining_Unit_Name => PB_Ent),
8002 Declarations => Declarations (Acc_Stm),
8003 Handled_Statement_Sequence =>
8004 Build_Accept_Body (Accept_Statement (Alt)));
8006 -- During the analysis of the body of the accept statement, any
8007 -- zero cost exception handler records were collected in the
8008 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8009 -- This is where we move them to where they belong, namely the
8010 -- newly created procedure.
8012 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8013 Append (Proc_Body, Body_List);
8016 Null_Body := New_Reference_To (Standard_True, Loc);
8018 -- if accept statement has declarations, insert above, given that
8019 -- we are not creating a body for the accept.
8021 if Present (Declarations (Acc_Stm)) then
8022 Insert_Actions (N, Declarations (Acc_Stm));
8026 Append_To (Accept_List,
8027 Make_Aggregate (Loc, Expressions => New_List (Null_Body, Expr)));
8029 Num_Accept := Num_Accept + 1;
8032 ----------------------------
8033 -- Make_And_Declare_Label --
8034 ----------------------------
8036 function Make_And_Declare_Label (Num : Int) return Node_Id is
8040 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8042 Make_Label (Loc, Lab_Id);
8045 Make_Implicit_Label_Declaration (Loc,
8046 Defining_Identifier =>
8047 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8048 Label_Construct => Lab));
8051 end Make_And_Declare_Label;
8053 ----------------------
8054 -- Make_Select_Call --
8055 ----------------------
8057 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8058 Params : constant List_Id := New_List;
8062 Make_Attribute_Reference (Loc,
8063 Prefix => New_Reference_To (Qnam, Loc),
8064 Attribute_Name => Name_Unchecked_Access),
8066 Append (Select_Mode, Params);
8067 Append (New_Reference_To (Ann, Loc), Params);
8068 Append (New_Reference_To (Xnam, Loc), Params);
8071 Make_Procedure_Call_Statement (Loc,
8072 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8073 Parameter_Associations => Params);
8074 end Make_Select_Call;
8076 --------------------------------
8077 -- Process_Accept_Alternative --
8078 --------------------------------
8080 procedure Process_Accept_Alternative
8085 Choices : List_Id := No_List;
8086 Alt_Stats : List_Id;
8089 Adjust_Condition (Condition (Alt));
8090 Alt_Stats := No_List;
8092 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8093 Choices := New_List (
8094 Make_Integer_Literal (Loc, Index));
8096 Alt_Stats := New_List (
8097 Make_Procedure_Call_Statement (Loc,
8098 Name => New_Reference_To (
8099 Defining_Unit_Name (Specification (Proc)), Loc)));
8102 if Statements (Alt) /= Empty_List then
8104 if No (Alt_Stats) then
8106 -- Accept with no body, followed by trailing statements
8108 Choices := New_List (
8109 Make_Integer_Literal (Loc, Index));
8111 Alt_Stats := New_List;
8114 -- After the call, if any, branch to to trailing statements. We
8115 -- create a label for each, as well as the corresponding label
8118 Lab := Make_And_Declare_Label (Index);
8119 Append_To (Alt_Stats,
8120 Make_Goto_Statement (Loc,
8121 Name => New_Copy (Identifier (Lab))));
8123 Append (Lab, Trailing_List);
8124 Append_List (Statements (Alt), Trailing_List);
8125 Append_To (Trailing_List,
8126 Make_Goto_Statement (Loc,
8127 Name => New_Copy (Identifier (End_Lab))));
8130 if Present (Alt_Stats) then
8132 -- Procedure call. and/or trailing statements
8134 Append_To (Alt_List,
8135 Make_Case_Statement_Alternative (Loc,
8136 Discrete_Choices => Choices,
8137 Statements => Alt_Stats));
8139 end Process_Accept_Alternative;
8141 -------------------------------
8142 -- Process_Delay_Alternative --
8143 -------------------------------
8145 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8148 Delay_Alt : List_Id;
8151 -- Deal with C/Fortran boolean as delay condition
8153 Adjust_Condition (Condition (Alt));
8155 -- Determine the smallest specified delay
8157 -- for each delay alternative generate:
8159 -- if guard-expression then
8160 -- Delay_Val := delay-expression;
8161 -- Guard_Open := True;
8162 -- if Delay_Val < Delay_Min then
8163 -- Delay_Min := Delay_Val;
8164 -- Delay_Index := Index;
8168 -- The enclosing if-statement is omitted if there is no guard
8173 First_Delay := False;
8175 Delay_Alt := New_List (
8176 Make_Assignment_Statement (Loc,
8177 Name => New_Reference_To (Delay_Min, Loc),
8178 Expression => Expression (Delay_Statement (Alt))));
8180 if Delay_Count > 1 then
8181 Append_To (Delay_Alt,
8182 Make_Assignment_Statement (Loc,
8183 Name => New_Reference_To (Delay_Index, Loc),
8184 Expression => Make_Integer_Literal (Loc, Index)));
8188 Delay_Alt := New_List (
8189 Make_Assignment_Statement (Loc,
8190 Name => New_Reference_To (Delay_Val, Loc),
8191 Expression => Expression (Delay_Statement (Alt))));
8193 if Time_Type = Standard_Duration then
8196 Left_Opnd => New_Reference_To (Delay_Val, Loc),
8197 Right_Opnd => New_Reference_To (Delay_Min, Loc));
8200 -- The scope of the time type must define a comparison
8201 -- operator. The scope itself may not be visible, so we
8202 -- construct a node with entity information to insure that
8203 -- semantic analysis can find the proper operator.
8206 Make_Function_Call (Loc,
8207 Name => Make_Selected_Component (Loc,
8208 Prefix => New_Reference_To (Scope (Time_Type), Loc),
8210 Make_Operator_Symbol (Loc,
8211 Chars => Name_Op_Lt,
8212 Strval => No_String)),
8213 Parameter_Associations =>
8215 New_Reference_To (Delay_Val, Loc),
8216 New_Reference_To (Delay_Min, Loc)));
8218 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
8221 Append_To (Delay_Alt,
8222 Make_Implicit_If_Statement (N,
8224 Then_Statements => New_List (
8225 Make_Assignment_Statement (Loc,
8226 Name => New_Reference_To (Delay_Min, Loc),
8227 Expression => New_Reference_To (Delay_Val, Loc)),
8229 Make_Assignment_Statement (Loc,
8230 Name => New_Reference_To (Delay_Index, Loc),
8231 Expression => Make_Integer_Literal (Loc, Index)))));
8235 Append_To (Delay_Alt,
8236 Make_Assignment_Statement (Loc,
8237 Name => New_Reference_To (Guard_Open, Loc),
8238 Expression => New_Reference_To (Standard_True, Loc)));
8241 if Present (Condition (Alt)) then
8242 Delay_Alt := New_List (
8243 Make_Implicit_If_Statement (N,
8244 Condition => Condition (Alt),
8245 Then_Statements => Delay_Alt));
8248 Append_List (Delay_Alt, Delay_List);
8250 -- If the delay alternative has a statement part, add choice to the
8251 -- case statements for delays.
8253 if Present (Statements (Alt)) then
8255 if Delay_Count = 1 then
8256 Append_List (Statements (Alt), Delay_Alt_List);
8259 Choices := New_List (
8260 Make_Integer_Literal (Loc, Index));
8262 Append_To (Delay_Alt_List,
8263 Make_Case_Statement_Alternative (Loc,
8264 Discrete_Choices => Choices,
8265 Statements => Statements (Alt)));
8268 elsif Delay_Count = 1 then
8270 -- If the single delay has no trailing statements, add a branch
8271 -- to the exit label to the selective wait.
8273 Delay_Alt_List := New_List (
8274 Make_Goto_Statement (Loc,
8275 Name => New_Copy (Identifier (End_Lab))));
8278 end Process_Delay_Alternative;
8280 -- Start of processing for Expand_N_Selective_Accept
8283 -- First insert some declarations before the select. The first is:
8287 -- This variable holds the parameters passed to the accept body. This
8288 -- declaration has already been inserted by the time we get here by
8289 -- a call to Expand_Accept_Declarations made from the semantics when
8290 -- processing the first accept statement contained in the select. We
8291 -- can find this entity as Accept_Address (E), where E is any of the
8292 -- entries references by contained accept statements.
8294 -- The first step is to scan the list of Selective_Accept_Statements
8295 -- to find this entity, and also count the number of accepts, and
8296 -- determine if terminated, delay or else is present:
8300 Alt := First (Alts);
8301 while Present (Alt) loop
8303 if Nkind (Alt) = N_Accept_Alternative then
8306 elsif Nkind (Alt) = N_Delay_Alternative then
8307 Delay_Count := Delay_Count + 1;
8309 -- If the delays are relative delays, the delay expressions have
8310 -- type Standard_Duration. Otherwise they must have some time type
8311 -- recognized by GNAT.
8313 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
8314 Time_Type := Standard_Duration;
8316 Time_Type := Etype (Expression (Delay_Statement (Alt)));
8318 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
8319 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
8324 "& is not a time type ('R'M 9.6(6))",
8325 Expression (Delay_Statement (Alt)), Time_Type);
8326 Time_Type := Standard_Duration;
8327 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
8331 if No (Condition (Alt)) then
8333 -- This guard will always be open
8335 Check_Guard := False;
8338 elsif Nkind (Alt) = N_Terminate_Alternative then
8339 Adjust_Condition (Condition (Alt));
8340 Terminate_Alt := Alt;
8343 Num_Alts := Num_Alts + 1;
8347 Else_Present := Present (Else_Statements (N));
8349 -- At the same time (see procedure Add_Accept) we build the accept list:
8351 -- Qnn : Accept_List (1 .. num-select) := (
8352 -- (null-body, entry-index),
8353 -- (null-body, entry-index),
8355 -- (null_body, entry-index));
8357 -- In the above declaration, null-body is True if the corresponding
8358 -- accept has no body, and false otherwise. The entry is either the
8359 -- entry index expression if there is no guard, or if a guard is
8360 -- present, then a conditional expression of the form:
8362 -- (if guard then entry-index else Null_Task_Entry)
8364 -- If a guard is statically known to be false, the entry can simply
8365 -- be omitted from the accept list.
8368 Make_Object_Declaration (Loc,
8369 Defining_Identifier => Qnam,
8370 Object_Definition =>
8371 New_Reference_To (RTE (RE_Accept_List), Loc),
8372 Aliased_Present => True,
8375 Make_Qualified_Expression (Loc,
8377 New_Reference_To (RTE (RE_Accept_List), Loc),
8379 Make_Aggregate (Loc, Expressions => Accept_List)));
8383 -- Then we declare the variable that holds the index for the accept
8384 -- that will be selected for service:
8386 -- Xnn : Select_Index;
8389 Make_Object_Declaration (Loc,
8390 Defining_Identifier => Xnam,
8391 Object_Definition =>
8392 New_Reference_To (RTE (RE_Select_Index), Loc),
8394 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
8398 -- After this follow procedure declarations for each accept body
8405 -- where the ... are statements from the corresponding procedure body.
8406 -- No parameters are involved, since the parameters are passed via Ann
8407 -- and the parameter references have already been expanded to be direct
8408 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
8409 -- any embedded tasking statements (which would normally be illegal in
8410 -- procedures, have been converted to calls to the tasking runtime so
8411 -- there is no problem in putting them into procedures.
8413 -- The original accept statement has been expanded into a block in
8414 -- the same fashion as for simple accepts (see Build_Accept_Body).
8416 -- Note: we don't really need to build these procedures for the case
8417 -- where no delay statement is present, but it is just as easy to
8418 -- build them unconditionally, and not significantly inefficient,
8419 -- since if they are short they will be inlined anyway.
8421 -- The procedure declarations have been assembled in Body_List
8423 -- If delays are present, we must compute the required delay.
8424 -- We first generate the declarations:
8426 -- Delay_Index : Boolean := 0;
8427 -- Delay_Min : Some_Time_Type.Time;
8428 -- Delay_Val : Some_Time_Type.Time;
8430 -- Delay_Index will be set to the index of the minimum delay, i.e. the
8431 -- active delay that is actually chosen as the basis for the possible
8432 -- delay if an immediate rendez-vous is not possible.
8434 -- In the most common case there is a single delay statement, and this
8435 -- is handled specially.
8437 if Delay_Count > 0 then
8439 -- Generate the required declarations
8442 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
8444 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
8446 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
8449 Make_Object_Declaration (Loc,
8450 Defining_Identifier => Delay_Val,
8451 Object_Definition => New_Reference_To (Time_Type, Loc)));
8454 Make_Object_Declaration (Loc,
8455 Defining_Identifier => Delay_Index,
8456 Object_Definition => New_Reference_To (Standard_Integer, Loc),
8457 Expression => Make_Integer_Literal (Loc, 0)));
8460 Make_Object_Declaration (Loc,
8461 Defining_Identifier => Delay_Min,
8462 Object_Definition => New_Reference_To (Time_Type, Loc),
8464 Unchecked_Convert_To (Time_Type,
8465 Make_Attribute_Reference (Loc,
8467 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
8468 Attribute_Name => Name_Last))));
8470 -- Create Duration and Delay_Mode objects used for passing a delay
8473 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
8474 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
8480 -- Note that these values are defined in s-osprim.ads and must
8483 -- Relative : constant := 0;
8484 -- Absolute_Calendar : constant := 1;
8485 -- Absolute_RT : constant := 2;
8487 if Time_Type = Standard_Duration then
8488 Discr := Make_Integer_Literal (Loc, 0);
8490 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
8491 Discr := Make_Integer_Literal (Loc, 1);
8495 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
8496 Discr := Make_Integer_Literal (Loc, 2);
8500 Make_Object_Declaration (Loc,
8501 Defining_Identifier => D,
8502 Object_Definition =>
8503 New_Reference_To (Standard_Duration, Loc)));
8506 Make_Object_Declaration (Loc,
8507 Defining_Identifier => M,
8508 Object_Definition =>
8509 New_Reference_To (Standard_Integer, Loc),
8510 Expression => Discr));
8515 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
8518 Make_Object_Declaration (Loc,
8519 Defining_Identifier => Guard_Open,
8520 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
8521 Expression => New_Reference_To (Standard_False, Loc)));
8524 -- Delay_Count is zero, don't need M and D set (suppress warning)
8531 if Present (Terminate_Alt) then
8533 -- If the terminate alternative guard is False, use
8534 -- Simple_Mode; otherwise use Terminate_Mode.
8536 if Present (Condition (Terminate_Alt)) then
8537 Select_Mode := Make_Conditional_Expression (Loc,
8538 New_List (Condition (Terminate_Alt),
8539 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
8540 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
8542 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
8545 elsif Else_Present or Delay_Count > 0 then
8546 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
8549 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
8552 Select_Call := Make_Select_Call (Select_Mode);
8553 Append (Select_Call, Stats);
8555 -- Now generate code to act on the result. There is an entry
8556 -- in this case for each accept statement with a non-null body,
8557 -- followed by a branch to the statements that follow the Accept.
8558 -- In the absence of delay alternatives, we generate:
8561 -- when No_Rendezvous => -- omitted if simple mode
8576 -- Lab0: Else_Statements;
8579 -- Lab1: Trailing_Statements1;
8582 -- Lab2: Trailing_Statements2;
8587 -- Generate label for common exit
8589 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
8591 -- First entry is the default case, when no rendezvous is possible
8593 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
8595 if Else_Present then
8597 -- If no rendezvous is possible, the else part is executed
8599 Lab := Make_And_Declare_Label (0);
8600 Alt_Stats := New_List (
8601 Make_Goto_Statement (Loc,
8602 Name => New_Copy (Identifier (Lab))));
8604 Append (Lab, Trailing_List);
8605 Append_List (Else_Statements (N), Trailing_List);
8606 Append_To (Trailing_List,
8607 Make_Goto_Statement (Loc,
8608 Name => New_Copy (Identifier (End_Lab))));
8610 Alt_Stats := New_List (
8611 Make_Goto_Statement (Loc,
8612 Name => New_Copy (Identifier (End_Lab))));
8615 Append_To (Alt_List,
8616 Make_Case_Statement_Alternative (Loc,
8617 Discrete_Choices => Choices,
8618 Statements => Alt_Stats));
8620 -- We make use of the fact that Accept_Index is an integer type, and
8621 -- generate successive literals for entries for each accept. Only those
8622 -- for which there is a body or trailing statements get a case entry.
8624 Alt := First (Select_Alternatives (N));
8625 Proc := First (Body_List);
8626 while Present (Alt) loop
8628 if Nkind (Alt) = N_Accept_Alternative then
8629 Process_Accept_Alternative (Alt, Index, Proc);
8633 (Handled_Statement_Sequence (Accept_Statement (Alt)))
8638 elsif Nkind (Alt) = N_Delay_Alternative then
8639 Process_Delay_Alternative (Alt, Delay_Num);
8640 Delay_Num := Delay_Num + 1;
8646 -- An others choice is always added to the main case, as well
8647 -- as the delay case (to satisfy the compiler).
8649 Append_To (Alt_List,
8650 Make_Case_Statement_Alternative (Loc,
8652 New_List (Make_Others_Choice (Loc)),
8654 New_List (Make_Goto_Statement (Loc,
8655 Name => New_Copy (Identifier (End_Lab))))));
8657 Accept_Case := New_List (
8658 Make_Case_Statement (Loc,
8659 Expression => New_Reference_To (Xnam, Loc),
8660 Alternatives => Alt_List));
8662 Append_List (Trailing_List, Accept_Case);
8663 Append (End_Lab, Accept_Case);
8664 Append_List (Body_List, Decls);
8666 -- Construct case statement for trailing statements of delay
8667 -- alternatives, if there are several of them.
8669 if Delay_Count > 1 then
8670 Append_To (Delay_Alt_List,
8671 Make_Case_Statement_Alternative (Loc,
8673 New_List (Make_Others_Choice (Loc)),
8675 New_List (Make_Null_Statement (Loc))));
8677 Delay_Case := New_List (
8678 Make_Case_Statement (Loc,
8679 Expression => New_Reference_To (Delay_Index, Loc),
8680 Alternatives => Delay_Alt_List));
8682 Delay_Case := Delay_Alt_List;
8685 -- If there are no delay alternatives, we append the case statement
8686 -- to the statement list.
8688 if Delay_Count = 0 then
8689 Append_List (Accept_Case, Stats);
8691 -- Delay alternatives present
8694 -- If delay alternatives are present we generate:
8696 -- find minimum delay.
8697 -- DX := minimum delay;
8698 -- M := <delay mode>;
8699 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
8702 -- if X = No_Rendezvous then
8703 -- case statement for delay statements.
8705 -- case statement for accept alternatives.
8716 -- The type of the delay expression is known to be legal
8718 if Time_Type = Standard_Duration then
8719 Conv := New_Reference_To (Delay_Min, Loc);
8721 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
8722 Conv := Make_Function_Call (Loc,
8723 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
8724 New_List (New_Reference_To (Delay_Min, Loc)));
8728 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
8730 Conv := Make_Function_Call (Loc,
8731 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
8732 New_List (New_Reference_To (Delay_Min, Loc)));
8735 Stmt := Make_Assignment_Statement (Loc,
8736 Name => New_Reference_To (D, Loc),
8737 Expression => Conv);
8739 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
8741 Parms := Parameter_Associations (Select_Call);
8742 Parm := First (Parms);
8744 while Present (Parm)
8745 and then Parm /= Select_Mode
8750 pragma Assert (Present (Parm));
8751 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
8754 -- Prepare two new parameters of Duration and Delay_Mode type
8755 -- which represent the value and the mode of the minimum delay.
8758 Insert_After (Parm, New_Reference_To (M, Loc));
8759 Insert_After (Parm, New_Reference_To (D, Loc));
8761 -- Create a call to RTS
8763 Rewrite (Select_Call,
8764 Make_Procedure_Call_Statement (Loc,
8765 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
8766 Parameter_Associations => Parms));
8768 -- This new call should follow the calculation of the minimum
8771 Insert_List_Before (Select_Call, Delay_List);
8775 Make_Implicit_If_Statement (N,
8776 Condition => New_Reference_To (Guard_Open, Loc),
8778 New_List (New_Copy_Tree (Stmt),
8779 New_Copy_Tree (Select_Call)),
8780 Else_Statements => Accept_Or_Raise);
8781 Rewrite (Select_Call, Stmt);
8783 Insert_Before (Select_Call, Stmt);
8787 Make_Implicit_If_Statement (N,
8788 Condition => Make_Op_Eq (Loc,
8789 Left_Opnd => New_Reference_To (Xnam, Loc),
8791 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8793 Then_Statements => Delay_Case,
8794 Else_Statements => Accept_Case);
8796 Append (Cases, Stats);
8800 -- Replace accept statement with appropriate block
8803 Make_Block_Statement (Loc,
8804 Declarations => Decls,
8805 Handled_Statement_Sequence =>
8806 Make_Handled_Sequence_Of_Statements (Loc,
8807 Statements => Stats));
8812 -- Note: have to worry more about abort deferral in above code ???
8814 -- Final step is to unstack the Accept_Address entries for all accept
8815 -- statements appearing in accept alternatives in the select statement
8817 Alt := First (Alts);
8818 while Present (Alt) loop
8819 if Nkind (Alt) = N_Accept_Alternative then
8820 Remove_Last_Elmt (Accept_Address
8821 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
8826 end Expand_N_Selective_Accept;
8828 --------------------------------------
8829 -- Expand_N_Single_Task_Declaration --
8830 --------------------------------------
8832 -- Single task declarations should never be present after semantic
8833 -- analysis, since we expect them to be replaced by a declaration of an
8834 -- anonymous task type, followed by a declaration of the task object. We
8835 -- include this routine to make sure that is happening!
8837 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
8839 raise Program_Error;
8840 end Expand_N_Single_Task_Declaration;
8842 ------------------------
8843 -- Expand_N_Task_Body --
8844 ------------------------
8846 -- Given a task body
8848 -- task body tname is
8854 -- This expansion routine converts it into a procedure and sets the
8855 -- elaboration flag for the procedure to true, to represent the fact
8856 -- that the task body is now elaborated:
8858 -- procedure tnameB (_Task : access tnameV) is
8859 -- discriminal : dtype renames _Task.discriminant;
8861 -- procedure _clean is
8865 -- Abort_Undefer.all;
8870 -- Abort_Undefer.all;
8872 -- System.Task_Stages.Complete_Activation;
8880 -- In addition, if the task body is an activator, then a call to activate
8881 -- tasks is added at the start of the statements, before the call to
8882 -- Complete_Activation, and if in addition the task is a master then it
8883 -- must be established as a master. These calls are inserted and analyzed
8884 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
8887 -- There is one discriminal declaration line generated for each
8888 -- discriminant that is present to provide an easy reference point for
8889 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
8891 -- Note on relationship to GNARLI definition. In the GNARLI definition,
8892 -- task body procedures have a profile (Arg : System.Address). That is
8893 -- needed because GNARLI has to use the same access-to-subprogram type
8894 -- for all task types. We depend here on knowing that in GNAT, passing
8895 -- an address argument by value is identical to passing a record value
8896 -- by access (in either case a single pointer is passed), so even though
8897 -- this procedure has the wrong profile. In fact it's all OK, since the
8898 -- callings sequence is identical.
8900 procedure Expand_N_Task_Body (N : Node_Id) is
8901 Loc : constant Source_Ptr := Sloc (N);
8902 Ttyp : constant Entity_Id := Corresponding_Spec (N);
8907 -- Here we start the expansion by generating discriminal declarations
8909 Add_Discriminal_Declarations (Declarations (N), Ttyp, Name_uTask, Loc);
8911 -- Add a call to Abort_Undefer at the very beginning of the task
8912 -- body since this body is called with abort still deferred.
8914 if Abort_Allowed then
8915 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
8917 (First (Statements (Handled_Statement_Sequence (N))), Call);
8921 -- The statement part has already been protected with an at_end and
8922 -- cleanup actions. The call to Complete_Activation must be placed
8923 -- at the head of the sequence of statements of that block. The
8924 -- declarations have been merged in this sequence of statements but
8925 -- the first real statement is accessible from the First_Real_Statement
8926 -- field (which was set for exactly this purpose).
8928 if Restricted_Profile then
8929 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
8931 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
8935 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
8939 Make_Subprogram_Body (Loc,
8940 Specification => Build_Task_Proc_Specification (Ttyp),
8941 Declarations => Declarations (N),
8942 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
8944 -- If the task contains generic instantiations, cleanup actions
8945 -- are delayed until after instantiation. Transfer the activation
8946 -- chain to the subprogram, to insure that the activation call is
8947 -- properly generated. It the task body contains inner tasks, indicate
8948 -- that the subprogram is a task master.
8950 if Delay_Cleanups (Ttyp) then
8951 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
8952 Set_Is_Task_Master (New_N, Is_Task_Master (N));
8958 -- Set elaboration flag immediately after task body. If the body is a
8959 -- subunit, the flag is set in the declarative part containing the stub.
8961 if Nkind (Parent (N)) /= N_Subunit then
8963 Make_Assignment_Statement (Loc,
8965 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
8966 Expression => New_Reference_To (Standard_True, Loc)));
8969 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
8970 -- the task body. At this point the entry specs have been created,
8971 -- frozen and included in the dispatch table for the task type.
8973 pragma Assert (Present (Corresponding_Record_Type (Ttyp)));
8975 if Ada_Version >= Ada_05
8976 and then Present (Task_Definition (Parent (Ttyp)))
8977 and then Present (Abstract_Interfaces
8978 (Corresponding_Record_Type (Ttyp)))
8981 Current_Node : Node_Id;
8982 Vis_Decl : Node_Id :=
8983 First (Visible_Declarations (Task_Definition (Parent (Ttyp))));
8984 Wrap_Body : Node_Id;
8987 if Nkind (Parent (N)) = N_Subunit then
8988 Current_Node := Corresponding_Stub (Parent (N));
8993 -- Examine the visible declarations of the task type, looking for
8994 -- an entry declaration. We do not consider entry families since
8995 -- they cannot have dispatching operations, thus they do not need
8998 while Present (Vis_Decl) loop
8999 if Nkind (Vis_Decl) = N_Entry_Declaration
9000 and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry
9003 -- Create the specification of the wrapper
9006 Build_Wrapper_Body (Loc,
9007 Proc_Nam => Defining_Identifier (Vis_Decl),
9008 Obj_Typ => Corresponding_Record_Type (Ttyp),
9009 Formals => Parameter_Specifications (Vis_Decl));
9011 if Wrap_Body /= Empty then
9012 Insert_After (Current_Node, Wrap_Body);
9013 Current_Node := Wrap_Body;
9015 Analyze (Wrap_Body);
9023 end Expand_N_Task_Body;
9025 ------------------------------------
9026 -- Expand_N_Task_Type_Declaration --
9027 ------------------------------------
9029 -- We have several things to do. First we must create a Boolean flag used
9030 -- to mark if the body is elaborated yet. This variable gets set to True
9031 -- when the body of the task is elaborated (we can't rely on the normal
9032 -- ABE mechanism for the task body, since we need to pass an access to
9033 -- this elaboration boolean to the runtime routines).
9035 -- taskE : aliased Boolean := False;
9037 -- Next a variable is declared to hold the task stack size (either the
9038 -- default : Unspecified_Size, or a value that is set by a pragma
9039 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9040 -- the variable is initialized with this value:
9042 -- taskZ : Size_Type := Unspecified_Size;
9044 -- taskZ : Size_Type := Size_Type (size_expression);
9046 -- Next we create a corresponding record type declaration used to represent
9047 -- values of this task. The general form of this type declaration is
9049 -- type taskV (discriminants) is record
9050 -- _Task_Id : Task_Id;
9051 -- entry_family : array (bounds) of Void;
9052 -- _Priority : Integer := priority_expression;
9053 -- _Size : Size_Type := Size_Type (size_expression);
9054 -- _Task_Info : Task_Info_Type := task_info_expression;
9057 -- The discriminants are present only if the corresponding task type has
9058 -- discriminants, and they exactly mirror the task type discriminants.
9060 -- The Id field is always present. It contains the Task_Id value, as set by
9061 -- the call to Create_Task. Note that although the task is limited, the
9062 -- task value record type is not limited, so there is no problem in passing
9063 -- this field as an out parameter to Create_Task.
9065 -- One entry_family component is present for each entry family in the task
9066 -- definition. The bounds correspond to the bounds of the entry family
9067 -- (which may depend on discriminants). The element type is void, since we
9068 -- only need the bounds information for determining the entry index. Note
9069 -- that the use of an anonymous array would normally be illegal in this
9070 -- context, but this is a parser check, and the semantics is quite prepared
9071 -- to handle such a case.
9073 -- The _Size field is present only if a Storage_Size pragma appears in the
9074 -- task definition. The expression captures the argument that was present
9075 -- in the pragma, and is used to override the task stack size otherwise
9076 -- associated with the task type.
9078 -- The _Priority field is present only if a Priority or Interrupt_Priority
9079 -- pragma appears in the task definition. The expression captures the
9080 -- argument that was present in the pragma, and is used to provide the Size
9081 -- parameter to the call to Create_Task.
9083 -- The _Task_Info field is present only if a Task_Info pragma appears in
9084 -- the task definition. The expression captures the argument that was
9085 -- present in the pragma, and is used to provide the Task_Image parameter
9086 -- to the call to Create_Task.
9088 -- When a task is declared, an instance of the task value record is
9089 -- created. The elaboration of this declaration creates the correct bounds
9090 -- for the entry families, and also evaluates the size, priority, and
9091 -- task_Info expressions if needed. The initialization routine for the task
9092 -- type itself then calls Create_Task with appropriate parameters to
9093 -- initialize the value of the Task_Id field.
9095 -- Note: the address of this record is passed as the "Discriminants"
9096 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9097 -- body procedure, it does not matter that it does not quite match the
9098 -- GNARLI model of what is being passed (the record contains more than just
9099 -- the discriminants, but the discriminants can be found from the record
9102 -- The Entity_Id for this created record type is placed in the
9103 -- Corresponding_Record_Type field of the associated task type entity.
9105 -- Next we create a procedure specification for the task body procedure:
9107 -- procedure taskB (_Task : access taskV);
9109 -- Note that this must come after the record type declaration, since
9110 -- the spec refers to this type. It turns out that the initialization
9111 -- procedure for the value type references the task body spec, but that's
9112 -- fine, since it won't be generated till the freeze point for the type,
9113 -- which is certainly after the task body spec declaration.
9115 -- Finally, we set the task index value field of the entry attribute in
9116 -- the case of a simple entry.
9118 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9119 Loc : constant Source_Ptr := Sloc (N);
9120 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9121 Tasknm : constant Name_Id := Chars (Tasktyp);
9122 Taskdef : constant Node_Id := Task_Definition (N);
9124 Proc_Spec : Node_Id;
9126 Rec_Ent : Entity_Id;
9128 Elab_Decl : Node_Id;
9129 Size_Decl : Node_Id;
9130 Body_Decl : Node_Id;
9131 Task_Size : Node_Id;
9132 Ent_Stack : Entity_Id;
9133 Decl_Stack : Node_Id;
9136 -- If already expanded, nothing to do
9138 if Present (Corresponding_Record_Type (Tasktyp)) then
9142 -- Here we will do the expansion
9144 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9146 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9147 -- of implemented interfaces.
9149 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9151 Rec_Ent := Defining_Identifier (Rec_Decl);
9152 Cdecls := Component_Items (Component_List
9153 (Type_Definition (Rec_Decl)));
9155 Qualify_Entity_Names (N);
9157 -- First create the elaboration variable
9160 Make_Object_Declaration (Loc,
9161 Defining_Identifier =>
9162 Make_Defining_Identifier (Sloc (Tasktyp),
9163 Chars => New_External_Name (Tasknm, 'E')),
9164 Aliased_Present => True,
9165 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9166 Expression => New_Reference_To (Standard_False, Loc));
9167 Insert_After (N, Elab_Decl);
9169 -- Next create the declaration of the size variable (tasknmZ)
9171 Set_Storage_Size_Variable (Tasktyp,
9172 Make_Defining_Identifier (Sloc (Tasktyp),
9173 Chars => New_External_Name (Tasknm, 'Z')));
9175 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9176 Is_Static_Expression (Expression (First (
9177 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9178 Taskdef, Name_Storage_Size)))))
9181 Make_Object_Declaration (Loc,
9182 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9183 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9185 Convert_To (RTE (RE_Size_Type),
9188 Pragma_Argument_Associations (
9189 Find_Task_Or_Protected_Pragma
9190 (Taskdef, Name_Storage_Size)))))));
9194 Make_Object_Declaration (Loc,
9195 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9196 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9197 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
9200 Insert_After (Elab_Decl, Size_Decl);
9202 -- Next build the rest of the corresponding record declaration. This is
9203 -- done last, since the corresponding record initialization procedure
9204 -- will reference the previously created entities.
9206 -- Fill in the component declarations -- first the _Task_Id field
9209 Make_Component_Declaration (Loc,
9210 Defining_Identifier =>
9211 Make_Defining_Identifier (Loc, Name_uTask_Id),
9212 Component_Definition =>
9213 Make_Component_Definition (Loc,
9214 Aliased_Present => False,
9215 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
9218 -- Declare static ATCB (that is, created by the expander) if we are
9219 -- using the Restricted run time.
9221 if Restricted_Profile then
9223 Make_Component_Declaration (Loc,
9224 Defining_Identifier =>
9225 Make_Defining_Identifier (Loc, Name_uATCB),
9227 Component_Definition =>
9228 Make_Component_Definition (Loc,
9229 Aliased_Present => True,
9230 Subtype_Indication => Make_Subtype_Indication (Loc,
9231 Subtype_Mark => New_Occurrence_Of
9232 (RTE (RE_Ada_Task_Control_Block), Loc),
9235 Make_Index_Or_Discriminant_Constraint (Loc,
9237 New_List (Make_Integer_Literal (Loc, 0)))))));
9241 -- Declare static stack (that is, created by the expander) if we are
9242 -- using the Restricted run time on a bare board configuration.
9244 if Restricted_Profile
9245 and then Preallocated_Stacks_On_Target
9247 -- First we need to extract the appropriate stack size
9249 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
9251 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
9252 Task_Size := Relocate_Node (
9254 Pragma_Argument_Associations (
9255 Find_Task_Or_Protected_Pragma
9256 (Taskdef, Name_Storage_Size)))));
9259 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
9262 Decl_Stack := Make_Component_Declaration (Loc,
9263 Defining_Identifier => Ent_Stack,
9265 Component_Definition =>
9266 Make_Component_Definition (Loc,
9267 Aliased_Present => True,
9268 Subtype_Indication => Make_Subtype_Indication (Loc,
9270 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
9273 Make_Index_Or_Discriminant_Constraint (Loc,
9274 Constraints => New_List (Make_Range (Loc,
9275 Low_Bound => Make_Integer_Literal (Loc, 1),
9276 High_Bound => Convert_To (RTE (RE_Storage_Offset),
9279 Append_To (Cdecls, Decl_Stack);
9281 -- The appropriate alignment for the stack is ensured by the run-time
9282 -- code in charge of task creation.
9286 -- Add components for entry families
9288 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
9290 -- Add the _Priority component if a Priority pragma is present
9292 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
9294 Prag : constant Node_Id :=
9295 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
9299 Expr := First (Pragma_Argument_Associations (Prag));
9301 if Nkind (Expr) = N_Pragma_Argument_Association then
9302 Expr := Expression (Expr);
9305 Expr := New_Copy_Tree (Expr);
9307 -- Add conversion to proper type to do range check if required
9308 -- Note that for runtime units, we allow out of range interrupt
9309 -- priority values to be used in a priority pragma. This is for
9310 -- the benefit of some versions of System.Interrupts which use
9311 -- a special server task with maximum interrupt priority.
9313 if Chars (Prag) = Name_Priority
9314 and then not GNAT_Mode
9316 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
9318 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
9322 Make_Component_Declaration (Loc,
9323 Defining_Identifier =>
9324 Make_Defining_Identifier (Loc, Name_uPriority),
9325 Component_Definition =>
9326 Make_Component_Definition (Loc,
9327 Aliased_Present => False,
9328 Subtype_Indication => New_Reference_To (Standard_Integer,
9330 Expression => Expr));
9334 -- Add the _Task_Size component if a Storage_Size pragma is present
9336 if Present (Taskdef)
9337 and then Has_Storage_Size_Pragma (Taskdef)
9340 Make_Component_Declaration (Loc,
9341 Defining_Identifier =>
9342 Make_Defining_Identifier (Loc, Name_uSize),
9344 Component_Definition =>
9345 Make_Component_Definition (Loc,
9346 Aliased_Present => False,
9347 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
9351 Convert_To (RTE (RE_Size_Type),
9354 Pragma_Argument_Associations (
9355 Find_Task_Or_Protected_Pragma
9356 (Taskdef, Name_Storage_Size))))))));
9359 -- Add the _Task_Info component if a Task_Info pragma is present
9361 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
9363 Make_Component_Declaration (Loc,
9364 Defining_Identifier =>
9365 Make_Defining_Identifier (Loc, Name_uTask_Info),
9367 Component_Definition =>
9368 Make_Component_Definition (Loc,
9369 Aliased_Present => False,
9370 Subtype_Indication =>
9371 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
9373 Expression => New_Copy (
9375 Pragma_Argument_Associations (
9376 Find_Task_Or_Protected_Pragma
9377 (Taskdef, Name_Task_Info)))))));
9380 Insert_After (Size_Decl, Rec_Decl);
9382 -- Analyze the record declaration immediately after construction,
9383 -- because the initialization procedure is needed for single task
9384 -- declarations before the next entity is analyzed.
9388 -- Create the declaration of the task body procedure
9390 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
9392 Make_Subprogram_Declaration (Loc,
9393 Specification => Proc_Spec);
9395 Insert_After (Rec_Decl, Body_Decl);
9397 -- The subprogram does not comes from source, so we have to indicate the
9398 -- need for debugging information explicitly.
9400 Set_Needs_Debug_Info
9401 (Defining_Entity (Proc_Spec), Comes_From_Source (Original_Node (N)));
9403 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
9404 -- the corresponding record has been frozen.
9406 if Ada_Version >= Ada_05
9407 and then Present (Taskdef)
9408 and then Present (Corresponding_Record_Type
9409 (Defining_Identifier (Parent (Taskdef))))
9410 and then Present (Abstract_Interfaces
9411 (Corresponding_Record_Type
9412 (Defining_Identifier (Parent (Taskdef)))))
9415 Current_Node : Node_Id := Rec_Decl;
9416 Vis_Decl : Node_Id := First (Visible_Declarations (Taskdef));
9417 Wrap_Spec : Node_Id;
9421 -- Examine the visible declarations of the task type, looking for
9422 -- an entry declaration. We do not consider entry families since
9423 -- they cannot have dispatching operations, thus they do not need
9426 while Present (Vis_Decl) loop
9427 if Nkind (Vis_Decl) = N_Entry_Declaration
9428 and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry
9431 Build_Wrapper_Spec (Loc,
9432 Proc_Nam => Defining_Identifier (Vis_Decl),
9433 Obj_Typ => Etype (Rec_Ent),
9434 Formals => Parameter_Specifications (Vis_Decl));
9436 if Wrap_Spec /= Empty then
9438 Make_Subprogram_Declaration (Loc,
9439 Specification => Wrap_Spec);
9441 Insert_After (Current_Node, New_N);
9442 Current_Node := New_N;
9453 -- Ada 2005 (AI-345): We must defer freezing to allow further
9454 -- declaration of primitive subprograms covering task interfaces
9456 if Ada_Version <= Ada_95 then
9458 -- Now we can freeze the corresponding record. This needs manually
9459 -- freezing, since it is really part of the task type, and the task
9460 -- type is frozen at this stage. We of course need the initialization
9461 -- procedure for this corresponding record type and we won't get it
9462 -- in time if we don't freeze now.
9465 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
9468 if Is_Non_Empty_List (L) then
9469 Insert_List_After (Body_Decl, L);
9474 -- Complete the expansion of access types to the current task type, if
9475 -- any were declared.
9477 Expand_Previous_Access_Type (Tasktyp);
9478 end Expand_N_Task_Type_Declaration;
9480 -------------------------------
9481 -- Expand_N_Timed_Entry_Call --
9482 -------------------------------
9484 -- A timed entry call in normal case is not implemented using ATC mechanism
9485 -- anymore for efficiency reason.
9495 -- is expanded as follow:
9497 -- 1) When T.E is a task entry_call;
9501 -- X : Task_Entry_Index := <entry index>;
9502 -- DX : Duration := To_Duration (D);
9503 -- M : Delay_Mode := <discriminant>;
9504 -- P : parms := (parm, parm, parm);
9507 -- Timed_Protected_Entry_Call (<acceptor-task>, X, P'Address,
9516 -- 2) When T.E is a protected entry_call;
9520 -- X : Protected_Entry_Index := <entry index>;
9521 -- DX : Duration := To_Duration (D);
9522 -- M : Delay_Mode := <discriminant>;
9523 -- P : parms := (parm, parm, parm);
9526 -- Timed_Protected_Entry_Call (<object>'unchecked_access, X,
9527 -- P'Address, DX, M, B);
9535 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
9538 -- B : Boolean := False;
9539 -- C : Ada.Tags.Prim_Op_Kind;
9540 -- DX : Duration := To_Duration (D)
9541 -- M : Integer :=...;
9542 -- P : Parameters := (Param1 .. ParamN);
9543 -- S : constant Iteger := DT_Position (<dispatching-procedure>);
9546 -- disp_timed_select (<object>, S, P'Address, DX, M, C, B);
9548 -- if C = POK_Protected_Entry
9549 -- or else C = POK_Task_Entry
9551 -- Param1 := P.Param1;
9553 -- ParamN := P.ParamN;
9557 -- if C = POK_Procedure
9558 -- or else C = POK_Protected_Procedure
9559 -- or else C = POK_Task_Procedure
9569 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
9570 Loc : constant Source_Ptr := Sloc (N);
9573 Entry_Call_Statement (Entry_Call_Alternative (N));
9574 E_Stats : constant List_Id :=
9575 Statements (Entry_Call_Alternative (N));
9576 D_Stat : constant Node_Id :=
9577 Delay_Statement (Delay_Alternative (N));
9578 D_Stats : constant List_Id :=
9579 Statements (Delay_Alternative (N));
9582 Blk_Typ : Entity_Id;
9584 Call_Ent : Entity_Id;
9602 B : Entity_Id; -- Call status flag
9603 C : Entity_Id; -- Call kind
9604 D : Entity_Id; -- Delay
9605 M : Entity_Id; -- Delay mode
9606 P : Entity_Id; -- Parameter block
9607 S : Entity_Id; -- Primitive operation slot
9610 -- The arguments in the call may require dynamic allocation, and the
9611 -- call statement may have been transformed into a block. The block
9612 -- may contain additional declarations for internal entities, and the
9613 -- original call is found by sequential search.
9615 if Nkind (E_Call) = N_Block_Statement then
9616 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
9617 while Nkind (E_Call) /= N_Procedure_Call_Statement
9618 and then Nkind (E_Call) /= N_Entry_Call_Statement
9624 if Ada_Version >= Ada_05
9625 and then Nkind (E_Call) = N_Procedure_Call_Statement
9627 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
9633 -- Build an entry call using Simple_Entry_Call
9635 Extract_Entry (E_Call, Concval, Ename, Index);
9636 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
9638 Decls := Declarations (E_Call);
9639 Stmts := Statements (Handled_Statement_Sequence (E_Call));
9646 -- Call status flag processing
9648 if Ada_Version >= Ada_05
9649 and then Nkind (E_Call) = N_Procedure_Call_Statement
9652 -- B : Boolean := False;
9654 B := SEU.Build_B (Loc, Decls);
9660 B := Make_Defining_Identifier (Loc, Name_uB);
9663 Make_Object_Declaration (Loc,
9664 Defining_Identifier =>
9666 Object_Definition =>
9667 New_Reference_To (Standard_Boolean, Loc)));
9670 -- Call kind processing
9672 if Ada_Version >= Ada_05
9673 and then Nkind (E_Call) = N_Procedure_Call_Statement
9676 -- C : Ada.Tags.Prim_Op_Kind;
9678 C := SEU.Build_C (Loc, Decls);
9681 -- Duration and mode processing
9683 D_Type := Base_Type (Etype (Expression (D_Stat)));
9685 -- Use the type of the delay expression (Calendar or Real_Time)
9686 -- to generate the appropriate conversion.
9688 if Nkind (D_Stat) = N_Delay_Relative_Statement then
9689 D_Disc := Make_Integer_Literal (Loc, 0);
9690 D_Conv := Relocate_Node (Expression (D_Stat));
9692 elsif Is_RTE (D_Type, RO_CA_Time) then
9693 D_Disc := Make_Integer_Literal (Loc, 1);
9694 D_Conv := Make_Function_Call (Loc,
9695 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9696 New_List (New_Copy (Expression (D_Stat))));
9698 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
9699 D_Disc := Make_Integer_Literal (Loc, 2);
9700 D_Conv := Make_Function_Call (Loc,
9701 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9702 New_List (New_Copy (Expression (D_Stat))));
9705 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
9711 Make_Object_Declaration (Loc,
9712 Defining_Identifier =>
9714 Object_Definition =>
9715 New_Reference_To (Standard_Duration, Loc)));
9717 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
9720 -- M : Integer := (0 | 1 | 2);
9723 Make_Object_Declaration (Loc,
9724 Defining_Identifier =>
9726 Object_Definition =>
9727 New_Reference_To (Standard_Integer, Loc),
9731 -- Do the assignement at this stage only because the evaluation of the
9732 -- expression must not occur before (see ACVC C97302A).
9735 Make_Assignment_Statement (Loc,
9737 New_Reference_To (D, Loc),
9741 -- Parameter block processing
9743 -- Manually create the parameter block for dispatching calls. In the
9744 -- case of entries, the block has already been created during the call
9745 -- to Build_Simple_Entry_Call.
9747 if Ada_Version >= Ada_05
9748 and then Nkind (E_Call) = N_Procedure_Call_Statement
9750 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
9751 P := Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals,
9754 -- Dispatch table slot processing, generate:
9755 -- S : constant Integer :=
9756 -- Ada.Tags.Get_Offset_Index (
9757 -- Unchecked_Convert_To (Ada.Tags.Interface_Tag, Obj),
9758 -- DT_Position (<dispatching-procedure>));
9760 S := SEU.Build_S (Loc, Decls, Obj, Call_Ent);
9763 -- _dispatching_timed_select (Obj, S, P'address, D, M, C, B);
9765 -- where Obj is the controlling formal parameter, S is the dispatch
9766 -- table slot number of the dispatching operation, P is the wrapped
9767 -- parameter block, D is the duration, M is the duration mode, C is
9768 -- the call kind and B is the call status.
9772 Append_To (Params, New_Copy_Tree (Obj));
9773 Append_To (Params, New_Reference_To (S, Loc));
9774 Append_To (Params, Make_Attribute_Reference (Loc,
9775 Prefix => New_Reference_To (P, Loc),
9776 Attribute_Name => Name_Address));
9777 Append_To (Params, New_Reference_To (D, Loc));
9778 Append_To (Params, New_Reference_To (M, Loc));
9779 Append_To (Params, New_Reference_To (C, Loc));
9780 Append_To (Params, New_Reference_To (B, Loc));
9783 Make_Procedure_Call_Statement (Loc,
9786 Find_Prim_Op (Etype (Etype (Obj)),
9787 Name_uDisp_Timed_Select),
9789 Parameter_Associations =>
9793 -- if C = POK_Protected_Entry
9794 -- or else C = POK_Task_Entry
9796 -- Param1 := P.Param1;
9798 -- ParamN := P.ParamN;
9801 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
9803 -- Generate the if statement only when the packed parameters need
9804 -- explicit assignments to their corresponding actuals.
9806 if Present (Unpack) then
9808 Make_If_Statement (Loc,
9815 New_Reference_To (C, Loc),
9817 New_Reference_To (RTE (
9818 RE_POK_Protected_Entry), Loc)),
9822 New_Reference_To (C, Loc),
9824 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
9826 Then_Statements => Unpack));
9832 -- if C = POK_Procedure
9833 -- or else C = POK_Protected_Procedure
9834 -- or else C = POK_Task_Procedure
9836 -- <dispatching-procedure-call>
9838 -- <normal-statements>
9840 -- <delay-statements>
9843 N_Stats := New_Copy_List_Tree (E_Stats);
9845 Prepend_To (N_Stats,
9846 Make_If_Statement (Loc,
9853 New_Reference_To (C, Loc),
9855 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
9861 New_Reference_To (C, Loc),
9863 New_Reference_To (RTE (
9864 RE_POK_Protected_Procedure), Loc)),
9868 New_Reference_To (C, Loc),
9870 New_Reference_To (RTE (
9871 RE_POK_Task_Procedure), Loc)))),
9874 New_List (E_Call)));
9877 Make_If_Statement (Loc,
9878 Condition => New_Reference_To (B, Loc),
9879 Then_Statements => N_Stats,
9880 Else_Statements => D_Stats));
9882 -- Skip assignments to temporaries created for in-out parameters.
9883 -- This makes unwarranted assumptions about the shape of the expanded
9884 -- tree for the call, and should be cleaned up ???
9886 Stmt := First (Stmts);
9887 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
9891 -- Do the assignement at this stage only because the evaluation
9892 -- of the expression must not occur before (see ACVC C97302A).
9894 Insert_Before (Stmt,
9895 Make_Assignment_Statement (Loc,
9896 Name => New_Reference_To (D, Loc),
9897 Expression => D_Conv));
9900 Params := Parameter_Associations (Call);
9902 -- For a protected type, we build a Timed_Protected_Entry_Call
9904 if Is_Protected_Type (Etype (Concval)) then
9906 -- Create a new call statement
9908 Param := First (Params);
9909 while Present (Param)
9910 and then not Is_RTE (Etype (Param), RE_Call_Modes)
9915 Dummy := Remove_Next (Next (Param));
9917 -- Remove garbage is following the Cancel_Param if present
9919 Dummy := Next (Param);
9921 -- Remove the mode of the Protected_Entry_Call call, then remove
9922 -- the Communication_Block of the Protected_Entry_Call call, and
9923 -- finally add Duration and a Delay_Mode parameter
9925 pragma Assert (Present (Param));
9926 Rewrite (Param, New_Reference_To (D, Loc));
9928 Rewrite (Dummy, New_Reference_To (M, Loc));
9930 -- Add a Boolean flag for successful entry call
9932 Append_To (Params, New_Reference_To (B, Loc));
9935 or else Restriction_Active (No_Entry_Queue) = False
9936 or else Number_Entries (Etype (Concval)) > 1
9939 Make_Procedure_Call_Statement (Loc,
9941 New_Reference_To (RTE (
9942 RE_Timed_Protected_Entry_Call), Loc),
9943 Parameter_Associations => Params));
9945 Param := First (Params);
9946 while Present (Param)
9947 and then not Is_RTE (Etype (Param), RE_Protected_Entry_Index)
9955 Make_Procedure_Call_Statement (Loc,
9956 Name => New_Reference_To (
9957 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
9958 Parameter_Associations => Params));
9961 -- For the task case, build a Timed_Task_Entry_Call
9964 -- Create a new call statement
9966 Append_To (Params, New_Reference_To (D, Loc));
9967 Append_To (Params, New_Reference_To (M, Loc));
9968 Append_To (Params, New_Reference_To (B, Loc));
9971 Make_Procedure_Call_Statement (Loc,
9973 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
9974 Parameter_Associations => Params));
9978 Make_Implicit_If_Statement (N,
9979 Condition => New_Reference_To (B, Loc),
9980 Then_Statements => E_Stats,
9981 Else_Statements => D_Stats));
9985 Make_Block_Statement (Loc,
9986 Declarations => Decls,
9987 Handled_Statement_Sequence =>
9988 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
9991 end Expand_N_Timed_Entry_Call;
9993 ----------------------------------------
9994 -- Expand_Protected_Body_Declarations --
9995 ----------------------------------------
9997 -- Part of the expansion of a protected body involves the creation of a
9998 -- declaration that can be referenced from the statement sequences of the
10003 -- This declaration is inserted in the declarations of the service entries
10004 -- procedure for the protected body, and it is important that it be
10005 -- inserted before the statements of the entry body statement sequences are
10006 -- analyzed. Thus it would be too late to create this declaration in the
10007 -- Expand_N_Protected_Body routine, which is why there is a separate
10008 -- procedure to be called directly from Sem_Ch9.
10010 -- Ann is used to hold the address of the record containing the parameters
10011 -- (see Expand_N_Entry_Call for more details on how this record is built).
10012 -- References to the parameters do an unchecked conversion of this address
10013 -- to a pointer to the required record type, and then access the field that
10014 -- holds the value of the required parameter. The entity for the address
10015 -- variable is held as the top stack element (i.e. the last element) of the
10016 -- Accept_Address stack in the corresponding entry entity, and this element
10017 -- must be set in place before the statements are processed.
10019 -- No stack is needed for entry bodies, since they cannot be nested, but it
10020 -- is kept for consistency between protected and task entries. The stack
10021 -- will never contain more than one element. There is also only one such
10022 -- variable for a given protected body, but this is placed on the
10023 -- Accept_Address stack of all of the entries, again for consistency.
10025 -- To expand the requeue statement, a label is provided at the end of the
10026 -- loop in the entry service routine created by the expander (see
10027 -- Expand_N_Protected_Body for details), so that the statement can be
10028 -- skipped after the requeue is complete. This label is created during the
10029 -- expansion of the entry body, which will take place after the expansion
10030 -- of the requeue statements that it contains, so a placeholder defining
10031 -- identifier is associated with the task type here.
10033 -- Another label is provided following case statement created by the
10034 -- expander. This label is need for implementing return statement from
10035 -- entry body so that a return can be expanded as a goto to this label.
10036 -- This label is created during the expansion of the entry body, which
10037 -- will take place after the expansion of the return statements that it
10038 -- contains. Therefore, just like the label for expanding requeues, we
10039 -- need another placeholder for the label.
10041 procedure Expand_Protected_Body_Declarations
10043 Spec_Id : Entity_Id)
10048 if No_Run_Time_Mode then
10049 Error_Msg_CRT ("protected body", N);
10052 elsif Expander_Active then
10054 -- Associate privals with the first subprogram or entry body to be
10055 -- expanded. These are used to expand references to private data
10058 Op := First_Protected_Operation (Declarations (N));
10060 if Present (Op) then
10061 Set_Discriminals (Parent (Spec_Id));
10062 Set_Privals (Parent (Spec_Id), Op, Sloc (N));
10065 end Expand_Protected_Body_Declarations;
10067 -------------------------
10068 -- External_Subprogram --
10069 -------------------------
10071 function External_Subprogram (E : Entity_Id) return Entity_Id is
10072 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10073 Decl : constant Node_Id := Unit_Declaration_Node (E);
10076 -- If the protected operation is defined in the visible part of the
10077 -- protected type, or if it is an interrupt handler, the internal and
10078 -- external subprograms follow each other on the entity chain. If the
10079 -- operation is defined in the private part of the type, there is no
10080 -- need for a separate locking version of the operation, and internal
10081 -- calls use the protected_body_subprogram directly.
10083 if List_Containing (Decl) = Visible_Declarations (Parent (Decl))
10084 or else Is_Interrupt_Handler (E)
10086 return Next_Entity (Subp);
10090 end External_Subprogram;
10092 ------------------------------
10093 -- Extract_Dispatching_Call --
10094 ------------------------------
10096 procedure Extract_Dispatching_Call
10098 Call_Ent : out Entity_Id;
10099 Object : out Entity_Id;
10100 Actuals : out List_Id;
10101 Formals : out List_Id)
10103 Call_Nam : Node_Id;
10106 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10108 if Present (Original_Node (N)) then
10109 Call_Nam := Name (Original_Node (N));
10111 Call_Nam := Name (N);
10114 -- Retrieve the name of the dispatching procedure. It contains the
10115 -- dispatch table slot number.
10118 case Nkind (Call_Nam) is
10119 when N_Identifier =>
10122 when N_Selected_Component =>
10123 Call_Nam := Selector_Name (Call_Nam);
10126 raise Program_Error;
10131 Actuals := Parameter_Associations (N);
10132 Call_Ent := Entity (Call_Nam);
10133 Formals := Parameter_Specifications (Parent (Call_Ent));
10134 Object := First (Actuals);
10136 if Present (Original_Node (Object)) then
10137 Object := Original_Node (Object);
10139 end Extract_Dispatching_Call;
10141 -------------------
10142 -- Extract_Entry --
10143 -------------------
10145 procedure Extract_Entry
10147 Concval : out Node_Id;
10148 Ename : out Node_Id;
10149 Index : out Node_Id)
10151 Nam : constant Node_Id := Name (N);
10154 -- For a simple entry, the name is a selected component, with the
10155 -- prefix being the task value, and the selector being the entry.
10157 if Nkind (Nam) = N_Selected_Component then
10158 Concval := Prefix (Nam);
10159 Ename := Selector_Name (Nam);
10162 -- For a member of an entry family, the name is an indexed component
10163 -- where the prefix is a selected component, whose prefix in turn is
10164 -- the task value, and whose selector is the entry family. The single
10165 -- expression in the expressions list of the indexed component is the
10166 -- subscript for the family.
10168 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
10169 Concval := Prefix (Prefix (Nam));
10170 Ename := Selector_Name (Prefix (Nam));
10171 Index := First (Expressions (Nam));
10175 -------------------
10176 -- Family_Offset --
10177 -------------------
10179 function Family_Offset
10183 Ttyp : Entity_Id) return Node_Id
10185 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
10186 -- If one of the bounds is a reference to a discriminant, replace with
10187 -- corresponding discriminal of type. Within the body of a task retrieve
10188 -- the renamed discriminant by simple visibility, using its generated
10189 -- name. Within a protected object, find the original dis- criminant and
10190 -- replace it with the discriminal of the current prot- ected operation.
10192 ------------------------------
10193 -- Convert_Discriminant_Ref --
10194 ------------------------------
10196 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
10197 Loc : constant Source_Ptr := Sloc (Bound);
10202 if Is_Entity_Name (Bound)
10203 and then Ekind (Entity (Bound)) = E_Discriminant
10205 if Is_Task_Type (Ttyp)
10206 and then Has_Completion (Ttyp)
10208 B := Make_Identifier (Loc, Chars (Entity (Bound)));
10209 Find_Direct_Name (B);
10211 elsif Is_Protected_Type (Ttyp) then
10212 D := First_Discriminant (Ttyp);
10213 while Chars (D) /= Chars (Entity (Bound)) loop
10214 Next_Discriminant (D);
10217 B := New_Reference_To (Discriminal (D), Loc);
10220 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
10223 elsif Nkind (Bound) = N_Attribute_Reference then
10227 B := New_Copy_Tree (Bound);
10231 Make_Attribute_Reference (Loc,
10232 Attribute_Name => Name_Pos,
10233 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
10234 Expressions => New_List (B));
10235 end Convert_Discriminant_Ref;
10237 -- Start of processing for Family_Offset
10241 Make_Op_Subtract (Loc,
10242 Left_Opnd => Convert_Discriminant_Ref (Hi),
10243 Right_Opnd => Convert_Discriminant_Ref (Lo));
10250 function Family_Size
10254 Ttyp : Entity_Id) return Node_Id
10259 if Is_Task_Type (Ttyp) then
10260 Ityp := RTE (RE_Task_Entry_Index);
10262 Ityp := RTE (RE_Protected_Entry_Index);
10266 Make_Attribute_Reference (Loc,
10267 Prefix => New_Reference_To (Ityp, Loc),
10268 Attribute_Name => Name_Max,
10269 Expressions => New_List (
10272 Family_Offset (Loc, Hi, Lo, Ttyp),
10274 Make_Integer_Literal (Loc, 1)),
10275 Make_Integer_Literal (Loc, 0)));
10278 -----------------------------------
10279 -- Find_Task_Or_Protected_Pragma --
10280 -----------------------------------
10282 function Find_Task_Or_Protected_Pragma
10284 P : Name_Id) return Node_Id
10289 N := First (Visible_Declarations (T));
10290 while Present (N) loop
10291 if Nkind (N) = N_Pragma then
10292 if Chars (N) = P then
10295 elsif P = Name_Priority
10296 and then Chars (N) = Name_Interrupt_Priority
10309 N := First (Private_Declarations (T));
10310 while Present (N) loop
10311 if Nkind (N) = N_Pragma then
10312 if Chars (N) = P then
10315 elsif P = Name_Priority
10316 and then Chars (N) = Name_Interrupt_Priority
10329 raise Program_Error;
10330 end Find_Task_Or_Protected_Pragma;
10332 -------------------------------
10333 -- First_Protected_Operation --
10334 -------------------------------
10336 function First_Protected_Operation (D : List_Id) return Node_Id is
10337 First_Op : Node_Id;
10340 First_Op := First (D);
10341 while Present (First_Op)
10342 and then Nkind (First_Op) /= N_Subprogram_Body
10343 and then Nkind (First_Op) /= N_Entry_Body
10349 end First_Protected_Operation;
10351 --------------------------------
10352 -- Index_Constant_Declaration --
10353 --------------------------------
10355 function Index_Constant_Declaration
10357 Index_Id : Entity_Id;
10358 Prot : Entity_Id) return List_Id
10360 Loc : constant Source_Ptr := Sloc (N);
10361 Decls : constant List_Id := New_List;
10362 Index_Con : constant Entity_Id := Entry_Index_Constant (Index_Id);
10363 Index_Typ : Entity_Id;
10365 Hi : Node_Id := Type_High_Bound (Etype (Index_Id));
10366 Lo : Node_Id := Type_Low_Bound (Etype (Index_Id));
10368 function Replace_Discriminant (Bound : Node_Id) return Node_Id;
10369 -- The bounds of the entry index may depend on discriminants, so each
10370 -- declaration of an entry_index_constant must have its own subtype
10371 -- declaration, using the local renaming of the object discriminant.
10373 --------------------------
10374 -- Replace_Discriminant --
10375 --------------------------
10377 function Replace_Discriminant (Bound : Node_Id) return Node_Id is
10379 if Nkind (Bound) = N_Identifier
10380 and then Ekind (Entity (Bound)) = E_Constant
10381 and then Present (Discriminal_Link (Entity (Bound)))
10383 return Make_Identifier (Loc, Chars (Entity (Bound)));
10385 return Duplicate_Subexpr (Bound);
10387 end Replace_Discriminant;
10389 -- Start of processing for Index_Constant_Declaration
10392 Set_Discriminal_Link (Index_Con, Index_Id);
10394 if Is_Entity_Name (
10395 Original_Node (Discrete_Subtype_Definition (Parent (Index_Id))))
10397 -- Simple case: entry family is given by a subtype mark, and index
10398 -- constant has the same type, no replacement needed.
10400 Index_Typ := Etype (Index_Id);
10403 Hi := Replace_Discriminant (Hi);
10404 Lo := Replace_Discriminant (Lo);
10406 Index_Typ := Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
10409 Make_Subtype_Declaration (Loc,
10410 Defining_Identifier => Index_Typ,
10411 Subtype_Indication =>
10412 Make_Subtype_Indication (Loc,
10414 New_Occurrence_Of (Base_Type (Etype (Index_Id)), Loc),
10416 Make_Range_Constraint (Loc,
10417 Range_Expression => Make_Range (Loc, Lo, Hi)))),
10423 Make_Object_Declaration (Loc,
10424 Defining_Identifier => Index_Con,
10425 Constant_Present => True,
10426 Object_Definition => New_Occurrence_Of (Index_Typ, Loc),
10429 Make_Attribute_Reference (Loc,
10430 Prefix => New_Reference_To (Index_Typ, Loc),
10431 Attribute_Name => Name_Val,
10433 Expressions => New_List (
10437 Make_Op_Subtract (Loc,
10438 Left_Opnd => Make_Identifier (Loc, Name_uE),
10440 Entry_Index_Expression (Loc,
10441 Defining_Identifier (N), Empty, Prot)),
10444 Make_Attribute_Reference (Loc,
10445 Prefix => New_Reference_To (Index_Typ, Loc),
10446 Attribute_Name => Name_Pos,
10447 Expressions => New_List (
10448 Make_Attribute_Reference (Loc,
10449 Prefix => New_Reference_To (Index_Typ, Loc),
10450 Attribute_Name => Name_First))))))),
10454 end Index_Constant_Declaration;
10456 --------------------------------
10457 -- Make_Initialize_Protection --
10458 --------------------------------
10460 function Make_Initialize_Protection
10461 (Protect_Rec : Entity_Id) return List_Id
10463 Loc : constant Source_Ptr := Sloc (Protect_Rec);
10467 Ptyp : constant Node_Id :=
10468 Corresponding_Concurrent_Type (Protect_Rec);
10470 L : constant List_Id := New_List;
10471 Has_Entry : constant Boolean := Has_Entries (Ptyp);
10472 Restricted : constant Boolean := Restricted_Profile;
10475 -- We may need two calls to properly initialize the object, one to
10476 -- Initialize_Protection, and possibly one to Install_Handlers if we
10477 -- have a pragma Attach_Handler.
10479 -- Get protected declaration. In the case of a task type declaration,
10480 -- this is simply the parent of the protected type entity. In the single
10481 -- protected object declaration, this parent will be the implicit type,
10482 -- and we can find the corresponding single protected object declaration
10483 -- by searching forward in the declaration list in the tree.
10485 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
10486 -- of this type should have been removed during semantic analysis.
10488 Pdec := Parent (Ptyp);
10489 while Nkind (Pdec) /= N_Protected_Type_Declaration
10490 and then Nkind (Pdec) /= N_Single_Protected_Declaration
10495 -- Now we can find the object definition from this declaration
10497 Pdef := Protected_Definition (Pdec);
10499 -- Build the parameter list for the call. Note that _Init is the name
10500 -- of the formal for the object to be initialized, which is the task
10501 -- value record itself.
10505 -- Object parameter. This is a pointer to the object of type
10506 -- Protection used by the GNARL to control the protected object.
10509 Make_Attribute_Reference (Loc,
10511 Make_Selected_Component (Loc,
10512 Prefix => Make_Identifier (Loc, Name_uInit),
10513 Selector_Name => Make_Identifier (Loc, Name_uObject)),
10514 Attribute_Name => Name_Unchecked_Access));
10516 -- Priority parameter. Set to Unspecified_Priority unless there is a
10517 -- priority pragma, in which case we take the value from the pragma,
10518 -- or there is an interrupt pragma and no priority pragma, and we
10519 -- set the ceiling to Interrupt_Priority'Last, an implementation-
10520 -- defined value, see D.3(10).
10523 and then Has_Priority_Pragma (Pdef)
10526 Duplicate_Subexpr_No_Checks
10529 (Pragma_Argument_Associations
10530 (Find_Task_Or_Protected_Pragma (Pdef, Name_Priority))))));
10532 elsif Has_Interrupt_Handler (Ptyp)
10533 or else Has_Attach_Handler (Ptyp)
10535 -- When no priority is specified but an xx_Handler pragma is,
10536 -- we default to System.Interrupts.Default_Interrupt_Priority,
10540 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
10544 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
10548 or else Has_Interrupt_Handler (Ptyp)
10549 or else Has_Attach_Handler (Ptyp)
10550 or else (Ada_Version >= Ada_05
10551 and then Present (Interface_List (Parent (Ptyp))))
10553 -- Compiler_Info parameter. This parameter allows entry body
10554 -- procedures and barrier functions to be called from the runtime.
10555 -- It is a pointer to the record generated by the compiler to
10556 -- represent the protected object.
10558 if Has_Entry or else not Restricted then
10560 Make_Attribute_Reference (Loc,
10561 Prefix => Make_Identifier (Loc, Name_uInit),
10562 Attribute_Name => Name_Address));
10567 -- Entry_Bodies parameter. This is a pointer to an array of
10568 -- pointers to the entry body procedures and barrier functions of
10569 -- the object. If the protected type has no entries this object
10570 -- will not exist; in this case, pass a null.
10572 P_Arr := Entry_Bodies_Array (Ptyp);
10575 Make_Attribute_Reference (Loc,
10576 Prefix => New_Reference_To (P_Arr, Loc),
10577 Attribute_Name => Name_Unrestricted_Access));
10580 or else Restriction_Active (No_Entry_Queue) = False
10581 or else Number_Entries (Ptyp) > 1
10583 -- Find index mapping function (clumsy but ok for now)
10585 while Ekind (P_Arr) /= E_Function loop
10586 Next_Entity (P_Arr);
10590 Make_Attribute_Reference (Loc,
10592 New_Reference_To (P_Arr, Loc),
10593 Attribute_Name => Name_Unrestricted_Access));
10596 elsif not Restricted then
10597 Append_To (Args, Make_Null (Loc));
10598 Append_To (Args, Make_Null (Loc));
10602 or else Restriction_Active (No_Entry_Queue) = False
10603 or else Number_Entries (Ptyp) > 1
10606 Make_Procedure_Call_Statement (Loc,
10607 Name => New_Reference_To (
10608 RTE (RE_Initialize_Protection_Entries), Loc),
10609 Parameter_Associations => Args));
10611 elsif not Has_Entry and then Restricted then
10613 Make_Procedure_Call_Statement (Loc,
10614 Name => New_Reference_To (
10615 RTE (RE_Initialize_Protection), Loc),
10616 Parameter_Associations => Args));
10620 Make_Procedure_Call_Statement (Loc,
10621 Name => New_Reference_To (
10622 RTE (RE_Initialize_Protection_Entry), Loc),
10623 Parameter_Associations => Args));
10628 Make_Procedure_Call_Statement (Loc,
10629 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
10630 Parameter_Associations => Args));
10633 if Has_Attach_Handler (Ptyp) then
10635 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
10636 -- make the following call:
10638 -- Install_Handlers (_object,
10639 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
10641 -- or, in the case of Ravenscar:
10643 -- Install_Handlers
10644 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
10647 Args : constant List_Id := New_List;
10648 Table : constant List_Id := New_List;
10649 Ritem : Node_Id := First_Rep_Item (Ptyp);
10652 if not Restricted then
10654 -- Appends the _object argument
10657 Make_Attribute_Reference (Loc,
10659 Make_Selected_Component (Loc,
10660 Prefix => Make_Identifier (Loc, Name_uInit),
10661 Selector_Name => Make_Identifier (Loc, Name_uObject)),
10662 Attribute_Name => Name_Unchecked_Access));
10665 -- Build the Attach_Handler table argument
10667 while Present (Ritem) loop
10668 if Nkind (Ritem) = N_Pragma
10669 and then Chars (Ritem) = Name_Attach_Handler
10672 Handler : constant Node_Id :=
10673 First (Pragma_Argument_Associations (Ritem));
10675 Interrupt : constant Node_Id := Next (Handler);
10676 Expr : constant Node_Id := Expression (Interrupt);
10680 Make_Aggregate (Loc, Expressions => New_List (
10681 Unchecked_Convert_To
10682 (RTE (RE_System_Interrupt_Id), Expr),
10683 Make_Attribute_Reference (Loc,
10684 Prefix => Make_Selected_Component (Loc,
10685 Make_Identifier (Loc, Name_uInit),
10686 Duplicate_Subexpr_No_Checks
10687 (Expression (Handler))),
10688 Attribute_Name => Name_Access))));
10692 Next_Rep_Item (Ritem);
10695 -- Append the table argument we just built
10697 Append_To (Args, Make_Aggregate (Loc, Table));
10699 -- Append the Install_Handler call to the statements
10702 Make_Procedure_Call_Statement (Loc,
10703 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
10704 Parameter_Associations => Args));
10709 end Make_Initialize_Protection;
10711 ---------------------------
10712 -- Make_Task_Create_Call --
10713 ---------------------------
10715 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
10716 Loc : constant Source_Ptr := Sloc (Task_Rec);
10726 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
10727 Tnam := Chars (Ttyp);
10729 -- Get task declaration. In the case of a task type declaration, this is
10730 -- simply the parent of the task type entity. In the single task
10731 -- declaration, this parent will be the implicit type, and we can find
10732 -- the corresponding single task declaration by searching forward in the
10733 -- declaration list in the tree.
10735 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
10736 -- this type should have been removed during semantic analysis.
10738 Tdec := Parent (Ttyp);
10739 while Nkind (Tdec) /= N_Task_Type_Declaration
10740 and then Nkind (Tdec) /= N_Single_Task_Declaration
10745 -- Now we can find the task definition from this declaration
10747 Tdef := Task_Definition (Tdec);
10749 -- Build the parameter list for the call. Note that _Init is the name
10750 -- of the formal for the object to be initialized, which is the task
10751 -- value record itself.
10755 -- Priority parameter. Set to Unspecified_Priority unless there is a
10756 -- priority pragma, in which case we take the value from the pragma.
10758 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
10760 Make_Selected_Component (Loc,
10761 Prefix => Make_Identifier (Loc, Name_uInit),
10762 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
10765 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
10768 -- Optional Stack parameter
10770 if Restricted_Profile then
10772 -- If the stack has been preallocated by the expander then
10773 -- pass its address. Otherwise, pass a null address.
10775 if Preallocated_Stacks_On_Target then
10777 Make_Attribute_Reference (Loc,
10778 Prefix => Make_Selected_Component (Loc,
10779 Prefix => Make_Identifier (Loc, Name_uInit),
10781 Make_Identifier (Loc, Name_uStack)),
10782 Attribute_Name => Name_Address));
10786 New_Reference_To (RTE (RE_Null_Address), Loc));
10790 -- Size parameter. If no Storage_Size pragma is present, then
10791 -- the size is taken from the taskZ variable for the type, which
10792 -- is either Unspecified_Size, or has been reset by the use of
10793 -- a Storage_Size attribute definition clause. If a pragma is
10794 -- present, then the size is taken from the _Size field of the
10795 -- task value record, which was set from the pragma value.
10798 and then Has_Storage_Size_Pragma (Tdef)
10801 Make_Selected_Component (Loc,
10802 Prefix => Make_Identifier (Loc, Name_uInit),
10803 Selector_Name => Make_Identifier (Loc, Name_uSize)));
10807 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
10810 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
10811 -- Task_Info pragma, in which case we take the value from the pragma.
10814 and then Has_Task_Info_Pragma (Tdef)
10817 Make_Selected_Component (Loc,
10818 Prefix => Make_Identifier (Loc, Name_uInit),
10819 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
10823 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
10826 if not Restricted_Profile then
10828 -- Number of entries. This is an expression of the form:
10830 -- n + _Init.a'Length + _Init.a'B'Length + ...
10832 -- where a,b... are the entry family names for the task definition
10834 Ecount := Build_Entry_Count_Expression (
10836 Component_Items (Component_List (
10837 Type_Definition (Parent (
10838 Corresponding_Record_Type (Ttyp))))),
10840 Append_To (Args, Ecount);
10842 -- Master parameter. This is a reference to the _Master parameter of
10843 -- the initialization procedure, except in the case of the pragma
10844 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
10845 -- See comments in System.Tasking.Initialization.Init_RTS for the
10848 if Restriction_Active (No_Task_Hierarchy) = False then
10849 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
10851 Append_To (Args, Make_Integer_Literal (Loc, 3));
10855 -- State parameter. This is a pointer to the task body procedure. The
10856 -- required value is obtained by taking the address of the task body
10857 -- procedure and converting it (with an unchecked conversion) to the
10858 -- type required by the task kernel. For further details, see the
10859 -- description of Expand_Task_Body
10862 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
10863 Make_Attribute_Reference (Loc,
10865 New_Occurrence_Of (Get_Task_Body_Procedure (Ttyp), Loc),
10866 Attribute_Name => Name_Address)));
10868 -- Discriminants parameter. This is just the address of the task
10869 -- value record itself (which contains the discriminant values
10872 Make_Attribute_Reference (Loc,
10873 Prefix => Make_Identifier (Loc, Name_uInit),
10874 Attribute_Name => Name_Address));
10876 -- Elaborated parameter. This is an access to the elaboration Boolean
10879 Make_Attribute_Reference (Loc,
10880 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
10881 Attribute_Name => Name_Unchecked_Access));
10883 -- Chain parameter. This is a reference to the _Chain parameter of
10884 -- the initialization procedure.
10886 Append_To (Args, Make_Identifier (Loc, Name_uChain));
10888 -- Task name parameter. Take this from the _Task_Id parameter to the
10889 -- init call unless there is a Task_Name pragma, in which case we take
10890 -- the value from the pragma.
10893 and then Has_Task_Name_Pragma (Tdef)
10897 Expression (First (
10898 Pragma_Argument_Associations (
10899 Find_Task_Or_Protected_Pragma
10900 (Tdef, Name_Task_Name))))));
10903 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
10906 -- Created_Task parameter. This is the _Task_Id field of the task
10910 Make_Selected_Component (Loc,
10911 Prefix => Make_Identifier (Loc, Name_uInit),
10912 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
10914 if Restricted_Profile then
10915 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
10917 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
10920 return Make_Procedure_Call_Statement (Loc,
10921 Name => Name, Parameter_Associations => Args);
10922 end Make_Task_Create_Call;
10924 ------------------------------
10925 -- Next_Protected_Operation --
10926 ------------------------------
10928 function Next_Protected_Operation (N : Node_Id) return Node_Id is
10932 Next_Op := Next (N);
10933 while Present (Next_Op)
10934 and then Nkind (Next_Op) /= N_Subprogram_Body
10935 and then Nkind (Next_Op) /= N_Entry_Body
10941 end Next_Protected_Operation;
10943 --------------------------
10944 -- Parameter_Block_Pack --
10945 --------------------------
10947 function Parameter_Block_Pack
10949 Blk_Typ : Entity_Id;
10953 Stmts : List_Id) return Node_Id
10955 Actual : Entity_Id;
10956 Expr : Node_Id := Empty;
10957 Formal : Entity_Id;
10958 Has_Param : Boolean := False;
10961 Temp_Asn : Node_Id;
10962 Temp_Nam : Node_Id;
10965 Actual := First (Actuals);
10966 Formal := Defining_Identifier (First (Formals));
10967 Params := New_List;
10969 while Present (Actual) loop
10970 if Is_By_Copy_Type (Etype (Actual)) then
10972 -- Jnn : aliased <formal-type>
10975 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
10978 Make_Object_Declaration (Loc,
10981 Defining_Identifier =>
10983 Object_Definition =>
10984 New_Reference_To (Etype (Formal), Loc)));
10986 if Ekind (Formal) /= E_Out_Parameter then
10992 New_Reference_To (Temp_Nam, Loc);
10994 Set_Assignment_OK (Temp_Asn);
10997 Make_Assignment_Statement (Loc,
11001 New_Copy_Tree (Actual)));
11005 -- Jnn'unchecked_access
11008 Make_Attribute_Reference (Loc,
11010 Name_Unchecked_Access,
11012 New_Reference_To (Temp_Nam, Loc)));
11016 -- The controlling parameter is omitted
11019 if not Is_Controlling_Actual (Actual) then
11021 Make_Reference (Loc, New_Copy_Tree (Actual)));
11027 Next_Actual (Actual);
11028 Next_Formal_With_Extras (Formal);
11032 Expr := Make_Aggregate (Loc, Params);
11037 -- J1'unchecked_access;
11038 -- <actual2>'reference;
11041 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
11044 Make_Object_Declaration (Loc,
11045 Defining_Identifier =>
11047 Object_Definition =>
11048 New_Reference_To (Blk_Typ, Loc),
11053 end Parameter_Block_Pack;
11055 ----------------------------
11056 -- Parameter_Block_Unpack --
11057 ----------------------------
11059 function Parameter_Block_Unpack
11063 Formals : List_Id) return List_Id
11065 Actual : Entity_Id;
11067 Formal : Entity_Id;
11068 Has_Asnmt : Boolean := False;
11069 Result : constant List_Id := New_List;
11072 Actual := First (Actuals);
11073 Formal := Defining_Identifier (First (Formals));
11074 while Present (Actual) loop
11075 if Is_By_Copy_Type (Etype (Actual))
11076 and then Ekind (Formal) /= E_In_Parameter
11079 -- <actual> := P.<formal>;
11082 Make_Assignment_Statement (Loc,
11086 Make_Explicit_Dereference (Loc,
11087 Make_Selected_Component (Loc,
11089 New_Reference_To (P, Loc),
11091 Make_Identifier (Loc, Chars (Formal)))));
11093 Set_Assignment_OK (Name (Asnmt));
11094 Append_To (Result, Asnmt);
11099 Next_Actual (Actual);
11100 Next_Formal_With_Extras (Formal);
11106 return New_List (Make_Null_Statement (Loc));
11108 end Parameter_Block_Unpack;
11110 ----------------------
11111 -- Set_Discriminals --
11112 ----------------------
11114 procedure Set_Discriminals (Dec : Node_Id) is
11117 D_Minal : Entity_Id;
11120 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
11121 Pdef := Defining_Identifier (Dec);
11123 if Has_Discriminants (Pdef) then
11124 D := First_Discriminant (Pdef);
11125 while Present (D) loop
11127 Make_Defining_Identifier (Sloc (D),
11128 Chars => New_External_Name (Chars (D), 'D'));
11130 Set_Ekind (D_Minal, E_Constant);
11131 Set_Etype (D_Minal, Etype (D));
11132 Set_Scope (D_Minal, Pdef);
11133 Set_Discriminal (D, D_Minal);
11134 Set_Discriminal_Link (D_Minal, D);
11136 Next_Discriminant (D);
11139 end Set_Discriminals;
11145 procedure Set_Privals
11149 After_Barrier : Boolean := False)
11155 Body_Ent : Entity_Id;
11156 For_Barrier : constant Boolean :=
11157 Nkind (Op) = N_Entry_Body and then not After_Barrier;
11159 Prec_Decl : constant Node_Id :=
11160 Parent (Corresponding_Record_Type
11161 (Defining_Identifier (Dec)));
11162 Prec_Def : constant Entity_Id := Type_Definition (Prec_Decl);
11163 Obj_Decl : Node_Id;
11164 P_Subtype : Entity_Id;
11165 Assoc_L : constant Elist_Id := New_Elmt_List;
11169 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
11171 (Nkind (Op) = N_Subprogram_Body or else Nkind (Op) = N_Entry_Body);
11173 Def := Protected_Definition (Dec);
11175 if Present (Private_Declarations (Def)) then
11176 P_Decl := First (Private_Declarations (Def));
11177 while Present (P_Decl) loop
11178 if Nkind (P_Decl) = N_Component_Declaration then
11179 P_Id := Defining_Identifier (P_Decl);
11181 if For_Barrier then
11183 Make_Defining_Identifier (Loc,
11184 Chars => New_External_Name (Chars (P_Id), 'P'));
11187 Make_Defining_Identifier (Loc,
11188 Chars => New_External_Name (Chars (P_Id)));
11191 Set_Ekind (Priv, E_Variable);
11192 Set_Etype (Priv, Etype (P_Id));
11193 Set_Scope (Priv, Scope (P_Id));
11194 Set_Esize (Priv, Esize (Etype (P_Id)));
11195 Set_Alignment (Priv, Alignment (Etype (P_Id)));
11197 -- If the type of the component is an itype, we must create a
11198 -- new itype for the corresponding prival in each protected
11199 -- operation, to avoid scoping problems. We create new itypes
11200 -- by copying the tree for the component definition.
11202 if Is_Itype (Etype (P_Id)) then
11203 Append_Elmt (P_Id, Assoc_L);
11204 Append_Elmt (Priv, Assoc_L);
11206 if Nkind (Op) = N_Entry_Body then
11207 Op_Id := Defining_Identifier (Op);
11209 Op_Id := Defining_Unit_Name (Specification (Op));
11213 (New_Copy_Tree (P_Decl, Assoc_L, New_Scope => Op_Id));
11216 Set_Protected_Operation (P_Id, Op);
11217 Set_Prival (P_Id, Priv);
11224 -- There is one more implicit private decl: the object itself. "prival"
11225 -- for this is attached to the protected body defining identifier.
11227 Body_Ent := Corresponding_Body (Dec);
11230 Make_Defining_Identifier (Sloc (Body_Ent),
11231 Chars => New_External_Name (Chars (Body_Ent), 'R'));
11233 -- Set the Etype to the implicit subtype of Protection created when
11234 -- the protected type declaration was expanded. This node will not
11235 -- be analyzed until it is used as the defining identifier for the
11236 -- renaming declaration in the protected operation body, and it will
11237 -- be needed in the references expanded before that body is expanded.
11238 -- Since the Protection field is aliased, set Is_Aliased as well.
11240 Obj_Decl := First (Component_Items (Component_List (Prec_Def)));
11241 while Chars (Defining_Identifier (Obj_Decl)) /= Name_uObject loop
11245 P_Subtype := Etype (Defining_Identifier (Obj_Decl));
11246 Set_Ekind (Priv, E_Variable);
11247 Set_Etype (Priv, P_Subtype);
11248 Set_Is_Aliased (Priv);
11249 Set_Object_Ref (Body_Ent, Priv);
11252 ----------------------------
11253 -- Update_Prival_Subtypes --
11254 ----------------------------
11256 procedure Update_Prival_Subtypes (N : Node_Id) is
11258 function Process (N : Node_Id) return Traverse_Result;
11259 -- Update the etype of occurrences of privals whose etype does not
11260 -- match the current Etype of the prival entity itself.
11262 procedure Update_Array_Bounds (E : Entity_Id);
11263 -- Itypes generated for array expressions may depend on the
11264 -- determinants of the protected object, and need to be processed
11265 -- separately because they are not attached to the tree.
11267 procedure Update_Index_Types (N : Node_Id);
11268 -- Similarly, update the types of expressions in indexed components
11269 -- which may depend on other discriminants.
11275 function Process (N : Node_Id) return Traverse_Result is
11277 if Is_Entity_Name (N) then
11279 E : constant Entity_Id := Entity (N);
11282 and then (Ekind (E) = E_Constant
11283 or else Ekind (E) = E_Variable)
11284 and then Nkind (Parent (E)) = N_Object_Renaming_Declaration
11285 and then not Is_Scalar_Type (Etype (E))
11286 and then Etype (N) /= Etype (E)
11288 Set_Etype (N, Etype (Entity (Original_Node (N))));
11289 Update_Index_Types (N);
11292 and then Ekind (E) = E_Constant
11293 and then Present (Discriminal_Link (E))
11295 Set_Etype (N, Etype (E));
11301 elsif Nkind (N) = N_Defining_Identifier
11302 or else Nkind (N) = N_Defining_Operator_Symbol
11303 or else Nkind (N) = N_Defining_Character_Literal
11307 elsif Nkind (N) = N_String_Literal then
11309 -- Array type, but bounds are constant
11313 elsif Nkind (N) = N_Object_Declaration
11314 and then Is_Itype (Etype (Defining_Identifier (N)))
11315 and then Is_Array_Type (Etype (Defining_Identifier (N)))
11317 Update_Array_Bounds (Etype (Defining_Identifier (N)));
11320 -- For array components of discriminated records, use the base type
11321 -- directly, because it may depend indirectly on the discriminants of
11322 -- the protected type.
11324 -- Cleaner would be a systematic mechanism to compute actual subtypes
11325 -- of private components???
11327 elsif Nkind (N) in N_Has_Etype
11328 and then Present (Etype (N))
11329 and then Is_Array_Type (Etype (N))
11330 and then Nkind (N) = N_Selected_Component
11331 and then Has_Discriminants (Etype (Prefix (N)))
11333 Set_Etype (N, Base_Type (Etype (N)));
11334 Update_Index_Types (N);
11338 if Nkind (N) in N_Has_Etype
11339 and then Present (Etype (N))
11340 and then Is_Itype (Etype (N)) then
11342 if Is_Array_Type (Etype (N)) then
11343 Update_Array_Bounds (Etype (N));
11345 elsif Is_Scalar_Type (Etype (N)) then
11346 Update_Prival_Subtypes (Type_Low_Bound (Etype (N)));
11347 Update_Prival_Subtypes (Type_High_Bound (Etype (N)));
11355 -------------------------
11356 -- Update_Array_Bounds --
11357 -------------------------
11359 procedure Update_Array_Bounds (E : Entity_Id) is
11362 Ind := First_Index (E);
11363 while Present (Ind) loop
11364 Update_Prival_Subtypes (Type_Low_Bound (Etype (Ind)));
11365 Update_Prival_Subtypes (Type_High_Bound (Etype (Ind)));
11368 end Update_Array_Bounds;
11370 ------------------------
11371 -- Update_Index_Types --
11372 ------------------------
11374 procedure Update_Index_Types (N : Node_Id) is
11379 -- If the prefix has an actual subtype that is different from the
11380 -- nominal one, update the types of the indices, so that the proper
11381 -- constraints are applied. Do not apply this transformation to a
11382 -- packed array, where the index type is computed for a byte array
11383 -- and is different from the source index.
11385 if Nkind (Parent (N)) = N_Indexed_Component
11387 not Is_Bit_Packed_Array (Etype (Prefix (Parent (N))))
11389 Indx1 := First (Expressions (Parent (N)));
11390 I_Typ := First_Index (Etype (N));
11392 while Present (Indx1) and then Present (I_Typ) loop
11394 if not Is_Entity_Name (Indx1) then
11395 Set_Etype (Indx1, Base_Type (Etype (I_Typ)));
11399 Next_Index (I_Typ);
11402 end Update_Index_Types;
11404 procedure Traverse is new Traverse_Proc;
11406 -- Start of processing for Update_Prival_Subtypes
11410 end Update_Prival_Subtypes;