1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Errout; use Errout;
30 with Exp_Ch9; use Exp_Ch9;
31 with Elists; use Elists;
32 with Freeze; use Freeze;
33 with Itypes; use Itypes;
34 with Lib.Xref; use Lib.Xref;
35 with Namet; use Namet;
36 with Nlists; use Nlists;
37 with Nmake; use Nmake;
39 with Restrict; use Restrict;
40 with Rident; use Rident;
41 with Rtsfind; use Rtsfind;
43 with Sem_Ch3; use Sem_Ch3;
44 with Sem_Ch5; use Sem_Ch5;
45 with Sem_Ch6; use Sem_Ch6;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Eval; use Sem_Eval;
48 with Sem_Res; use Sem_Res;
49 with Sem_Type; use Sem_Type;
50 with Sem_Util; use Sem_Util;
51 with Sem_Warn; use Sem_Warn;
52 with Snames; use Snames;
53 with Stand; use Stand;
54 with Sinfo; use Sinfo;
56 with Targparm; use Targparm;
57 with Tbuild; use Tbuild;
58 with Uintp; use Uintp;
60 package body Sem_Ch9 is
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions);
67 -- Given either a protected definition or a task definition in D, check
68 -- the corresponding restriction parameter identifier R, and if it is set,
69 -- count the entries (checking the static requirement), and compare with
72 procedure Check_Interfaces (N : Node_Id; T : Entity_Id);
73 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
74 -- Complete decoration of T and check legality of the covered interfaces.
76 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id;
77 -- Find entity in corresponding task or protected declaration. Use full
78 -- view if first declaration was for an incomplete type.
80 procedure Install_Declarations (Spec : Entity_Id);
81 -- Utility to make visible in corresponding body the entities defined in
82 -- task, protected type declaration, or entry declaration.
84 -----------------------------
85 -- Analyze_Abort_Statement --
86 -----------------------------
88 procedure Analyze_Abort_Statement (N : Node_Id) is
93 T_Name := First (Names (N));
94 while Present (T_Name) loop
97 if Is_Task_Type (Etype (T_Name))
98 or else (Ada_Version >= Ada_05
99 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
100 and then Is_Interface (Etype (T_Name))
101 and then Is_Task_Interface (Etype (T_Name)))
105 if Ada_Version >= Ada_05 then
106 Error_Msg_N ("expect task name or task interface class-wide "
107 & "object for ABORT", T_Name);
109 Error_Msg_N ("expect task name for ABORT", T_Name);
118 Check_Restriction (No_Abort_Statements, N);
119 Check_Potentially_Blocking_Operation (N);
120 end Analyze_Abort_Statement;
122 --------------------------------
123 -- Analyze_Accept_Alternative --
124 --------------------------------
126 procedure Analyze_Accept_Alternative (N : Node_Id) is
128 Tasking_Used := True;
130 if Present (Pragmas_Before (N)) then
131 Analyze_List (Pragmas_Before (N));
134 if Present (Condition (N)) then
135 Analyze_And_Resolve (Condition (N), Any_Boolean);
138 Analyze (Accept_Statement (N));
140 if Is_Non_Empty_List (Statements (N)) then
141 Analyze_Statements (Statements (N));
143 end Analyze_Accept_Alternative;
145 ------------------------------
146 -- Analyze_Accept_Statement --
147 ------------------------------
149 procedure Analyze_Accept_Statement (N : Node_Id) is
150 Nam : constant Entity_Id := Entry_Direct_Name (N);
151 Formals : constant List_Id := Parameter_Specifications (N);
152 Index : constant Node_Id := Entry_Index (N);
153 Stats : constant Node_Id := Handled_Statement_Sequence (N);
154 Accept_Id : Entity_Id;
155 Entry_Nam : Entity_Id;
158 Task_Nam : Entity_Id;
160 -----------------------
161 -- Actual_Index_Type --
162 -----------------------
164 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
165 -- If the bounds of an entry family depend on task discriminants, create
166 -- a new index type where a discriminant is replaced by the local
167 -- variable that renames it in the task body.
169 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
170 Typ : constant Entity_Id := Entry_Index_Type (E);
171 Lo : constant Node_Id := Type_Low_Bound (Typ);
172 Hi : constant Node_Id := Type_High_Bound (Typ);
175 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
176 -- If bound is discriminant reference, replace with corresponding
177 -- local variable of the same name.
179 -----------------------------
180 -- Actual_Discriminant_Ref --
181 -----------------------------
183 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
184 Typ : constant Entity_Id := Etype (Bound);
187 if not Is_Entity_Name (Bound)
188 or else Ekind (Entity (Bound)) /= E_Discriminant
192 Ref := Make_Identifier (Sloc (N), Chars (Entity (Bound)));
197 end Actual_Discriminant_Ref;
199 -- Start of processing for Actual_Index_Type
202 if not Has_Discriminants (Task_Nam)
203 or else (not Is_Entity_Name (Lo)
204 and then not Is_Entity_Name (Hi))
206 return Entry_Index_Type (E);
208 New_T := Create_Itype (Ekind (Typ), N);
209 Set_Etype (New_T, Base_Type (Typ));
210 Set_Size_Info (New_T, Typ);
211 Set_RM_Size (New_T, RM_Size (Typ));
212 Set_Scalar_Range (New_T,
213 Make_Range (Sloc (N),
214 Low_Bound => Actual_Discriminant_Ref (Lo),
215 High_Bound => Actual_Discriminant_Ref (Hi)));
219 end Actual_Index_Type;
221 -- Start of processing for Analyze_Accept_Statement
224 Tasking_Used := True;
226 -- Entry name is initialized to Any_Id. It should get reset to the
227 -- matching entry entity. An error is signalled if it is not reset.
231 for J in reverse 0 .. Scope_Stack.Last loop
232 Task_Nam := Scope_Stack.Table (J).Entity;
233 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
234 Kind := Ekind (Task_Nam);
236 if Kind /= E_Block and then Kind /= E_Loop
237 and then not Is_Entry (Task_Nam)
239 Error_Msg_N ("enclosing body of accept must be a task", N);
244 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
245 Error_Msg_N ("invalid context for accept statement", N);
249 -- In order to process the parameters, we create a defining
250 -- identifier that can be used as the name of the scope. The
251 -- name of the accept statement itself is not a defining identifier,
252 -- and we cannot use its name directly because the task may have
253 -- any number of accept statements for the same entry.
255 if Present (Index) then
256 Accept_Id := New_Internal_Entity
257 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
259 Accept_Id := New_Internal_Entity
260 (E_Entry, Current_Scope, Sloc (N), 'E');
263 Set_Etype (Accept_Id, Standard_Void_Type);
264 Set_Accept_Address (Accept_Id, New_Elmt_List);
266 if Present (Formals) then
267 Push_Scope (Accept_Id);
268 Process_Formals (Formals, N);
269 Create_Extra_Formals (Accept_Id);
273 -- We set the default expressions processed flag because we don't need
274 -- default expression functions. This is really more like body entity
275 -- than a spec entity anyway.
277 Set_Default_Expressions_Processed (Accept_Id);
279 E := First_Entity (Etype (Task_Nam));
280 while Present (E) loop
281 if Chars (E) = Chars (Nam)
282 and then (Ekind (E) = Ekind (Accept_Id))
283 and then Type_Conformant (Accept_Id, E)
292 if Entry_Nam = Any_Id then
293 Error_Msg_N ("no entry declaration matches accept statement", N);
296 Set_Entity (Nam, Entry_Nam);
297 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
298 Style.Check_Identifier (Nam, Entry_Nam);
301 -- Verify that the entry is not hidden by a procedure declared in the
302 -- current block (pathological but possible).
304 if Current_Scope /= Task_Nam then
309 E1 := First_Entity (Current_Scope);
310 while Present (E1) loop
311 if Ekind (E1) = E_Procedure
312 and then Chars (E1) = Chars (Entry_Nam)
313 and then Type_Conformant (E1, Entry_Nam)
315 Error_Msg_N ("entry name is not visible", N);
323 Set_Convention (Accept_Id, Convention (Entry_Nam));
324 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
326 for J in reverse 0 .. Scope_Stack.Last loop
327 exit when Task_Nam = Scope_Stack.Table (J).Entity;
329 if Entry_Nam = Scope_Stack.Table (J).Entity then
330 Error_Msg_N ("duplicate accept statement for same entry", N);
341 when N_Task_Body | N_Compilation_Unit =>
343 when N_Asynchronous_Select =>
344 Error_Msg_N ("accept statements are not allowed within" &
345 " an asynchronous select inner" &
346 " to the enclosing task body", N);
354 if Ekind (E) = E_Entry_Family then
356 Error_Msg_N ("missing entry index in accept for entry family", N);
358 Analyze_And_Resolve (Index, Entry_Index_Type (E));
359 Apply_Range_Check (Index, Actual_Index_Type (E));
362 elsif Present (Index) then
363 Error_Msg_N ("invalid entry index in accept for simple entry", N);
366 -- If label declarations present, analyze them. They are declared in the
367 -- enclosing task, but their enclosing scope is the entry itself, so
368 -- that goto's to the label are recognized as local to the accept.
370 if Present (Declarations (N)) then
376 Decl := First (Declarations (N));
377 while Present (Decl) loop
381 (Nkind (Decl) = N_Implicit_Label_Declaration);
383 Id := Defining_Identifier (Decl);
384 Set_Enclosing_Scope (Id, Entry_Nam);
390 -- If statements are present, they must be analyzed in the context of
391 -- the entry, so that references to formals are correctly resolved. We
392 -- also have to add the declarations that are required by the expansion
393 -- of the accept statement in this case if expansion active.
395 -- In the case of a select alternative of a selective accept, the
396 -- expander references the address declaration even if there is no
399 -- We also need to create the renaming declarations for the local
400 -- variables that will replace references to the formals within the
403 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
405 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
406 -- fields on all entry formals (this loop ignores all other entities).
407 -- Reset Referenced, Referenced_As_LHS and Has_Pragma_Unreferenced as
408 -- well, so that we can post accurate warnings on each accept statement
409 -- for the same entry.
411 E := First_Entity (Entry_Nam);
412 while Present (E) loop
413 if Is_Formal (E) then
414 Set_Never_Set_In_Source (E, True);
415 Set_Is_True_Constant (E, False);
416 Set_Current_Value (E, Empty);
417 Set_Referenced (E, False);
418 Set_Referenced_As_LHS (E, False);
419 Set_Has_Pragma_Unreferenced (E, False);
425 -- Analyze statements if present
427 if Present (Stats) then
428 Push_Scope (Entry_Nam);
429 Install_Declarations (Entry_Nam);
431 Set_Actual_Subtypes (N, Current_Scope);
434 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
438 -- Some warning checks
440 Check_Potentially_Blocking_Operation (N);
441 Check_References (Entry_Nam, N);
442 Set_Entry_Accepted (Entry_Nam);
443 end Analyze_Accept_Statement;
445 ---------------------------------
446 -- Analyze_Asynchronous_Select --
447 ---------------------------------
449 procedure Analyze_Asynchronous_Select (N : Node_Id) is
454 Tasking_Used := True;
455 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
456 Check_Restriction (No_Select_Statements, N);
458 if Ada_Version >= Ada_05 then
459 Trigger := Triggering_Statement (Triggering_Alternative (N));
463 -- The trigger is a dispatching procedure. Postpone the analysis of
464 -- the triggering and abortable statements until the expansion of
465 -- this asynchronous select in Expand_N_Asynchronous_Select. This
466 -- action is required since otherwise we would get a gigi abort from
467 -- the code replication in Expand_N_Asynchronous_Select of an already
468 -- analyzed statement list.
471 and then Nkind (Trigger) = N_Procedure_Call_Statement
472 and then Present (Parameter_Associations (Trigger))
474 Param := First (Parameter_Associations (Trigger));
476 if Is_Controlling_Actual (Param)
477 and then Is_Interface (Etype (Param))
479 if Is_Limited_Record (Etype (Param)) then
483 ("dispatching operation of limited or synchronized " &
484 "interface required (RM 9.7.2(3))!", N);
490 -- Analyze the statements. We analyze statements in the abortable part,
491 -- because this is the section that is executed first, and that way our
492 -- remembering of saved values and checks is accurate.
494 Analyze_Statements (Statements (Abortable_Part (N)));
495 Analyze (Triggering_Alternative (N));
496 end Analyze_Asynchronous_Select;
498 ------------------------------------
499 -- Analyze_Conditional_Entry_Call --
500 ------------------------------------
502 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
504 Check_Restriction (No_Select_Statements, N);
505 Tasking_Used := True;
506 Analyze (Entry_Call_Alternative (N));
508 if List_Length (Else_Statements (N)) = 1
509 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
512 ("suspicious form of conditional entry call?", N);
514 ("\`SELECT OR` may be intended rather than `SELECT ELSE`", N);
517 Analyze_Statements (Else_Statements (N));
518 end Analyze_Conditional_Entry_Call;
520 --------------------------------
521 -- Analyze_Delay_Alternative --
522 --------------------------------
524 procedure Analyze_Delay_Alternative (N : Node_Id) is
529 Tasking_Used := True;
530 Check_Restriction (No_Delay, N);
532 if Present (Pragmas_Before (N)) then
533 Analyze_List (Pragmas_Before (N));
536 if Nkind (Parent (N)) = N_Selective_Accept
537 or else Nkind (Parent (N)) = N_Timed_Entry_Call
539 Expr := Expression (Delay_Statement (N));
541 -- Defer full analysis until the statement is expanded, to insure
542 -- that generated code does not move past the guard. The delay
543 -- expression is only evaluated if the guard is open.
545 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
546 Pre_Analyze_And_Resolve (Expr, Standard_Duration);
548 Pre_Analyze_And_Resolve (Expr);
551 Typ := First_Subtype (Etype (Expr));
553 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
554 and then not Is_RTE (Typ, RO_CA_Time)
555 and then not Is_RTE (Typ, RO_RT_Time)
557 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
560 Check_Restriction (No_Fixed_Point, Expr);
563 Analyze (Delay_Statement (N));
566 if Present (Condition (N)) then
567 Analyze_And_Resolve (Condition (N), Any_Boolean);
570 if Is_Non_Empty_List (Statements (N)) then
571 Analyze_Statements (Statements (N));
573 end Analyze_Delay_Alternative;
575 ----------------------------
576 -- Analyze_Delay_Relative --
577 ----------------------------
579 procedure Analyze_Delay_Relative (N : Node_Id) is
580 E : constant Node_Id := Expression (N);
582 Check_Restriction (No_Relative_Delay, N);
583 Tasking_Used := True;
584 Check_Restriction (No_Delay, N);
585 Check_Potentially_Blocking_Operation (N);
586 Analyze_And_Resolve (E, Standard_Duration);
587 Check_Restriction (No_Fixed_Point, E);
588 end Analyze_Delay_Relative;
590 -------------------------
591 -- Analyze_Delay_Until --
592 -------------------------
594 procedure Analyze_Delay_Until (N : Node_Id) is
595 E : constant Node_Id := Expression (N);
599 Tasking_Used := True;
600 Check_Restriction (No_Delay, N);
601 Check_Potentially_Blocking_Operation (N);
603 Typ := First_Subtype (Etype (E));
605 if not Is_RTE (Typ, RO_CA_Time) and then
606 not Is_RTE (Typ, RO_RT_Time)
608 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
610 end Analyze_Delay_Until;
612 ------------------------
613 -- Analyze_Entry_Body --
614 ------------------------
616 procedure Analyze_Entry_Body (N : Node_Id) is
617 Id : constant Entity_Id := Defining_Identifier (N);
618 Decls : constant List_Id := Declarations (N);
619 Stats : constant Node_Id := Handled_Statement_Sequence (N);
620 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
621 P_Type : constant Entity_Id := Current_Scope;
622 Entry_Name : Entity_Id;
626 Tasking_Used := True;
628 -- Entry_Name is initialized to Any_Id. It should get reset to the
629 -- matching entry entity. An error is signalled if it is not reset
631 Entry_Name := Any_Id;
635 if Present (Entry_Index_Specification (Formals)) then
636 Set_Ekind (Id, E_Entry_Family);
638 Set_Ekind (Id, E_Entry);
641 Set_Scope (Id, Current_Scope);
642 Set_Etype (Id, Standard_Void_Type);
643 Set_Accept_Address (Id, New_Elmt_List);
645 E := First_Entity (P_Type);
646 while Present (E) loop
647 if Chars (E) = Chars (Id)
648 and then (Ekind (E) = Ekind (Id))
649 and then Type_Conformant (Id, E)
652 Set_Convention (Id, Convention (E));
653 Set_Corresponding_Body (Parent (Entry_Name), Id);
654 Check_Fully_Conformant (Id, E, N);
656 if Ekind (Id) = E_Entry_Family then
657 if not Fully_Conformant_Discrete_Subtypes (
658 Discrete_Subtype_Definition (Parent (E)),
659 Discrete_Subtype_Definition
660 (Entry_Index_Specification (Formals)))
663 ("index not fully conformant with previous declaration",
664 Discrete_Subtype_Definition
665 (Entry_Index_Specification (Formals)));
668 -- The elaboration of the entry body does not recompute the
669 -- bounds of the index, which may have side effects. Inherit
670 -- the bounds from the entry declaration. This is critical
671 -- if the entry has a per-object constraint. If a bound is
672 -- given by a discriminant, it must be reanalyzed in order
673 -- to capture the discriminal of the current entry, rather
674 -- than that of the protected type.
677 Index_Spec : constant Node_Id :=
678 Entry_Index_Specification (Formals);
680 Def : constant Node_Id :=
682 (Discrete_Subtype_Definition (Parent (E)));
687 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
689 Set_Etype (Def, Empty);
690 Set_Analyzed (Def, False);
692 -- Keep the original subtree to ensure a properly
693 -- formed tree (e.g. for ASIS use).
696 (Discrete_Subtype_Definition (Index_Spec), Def);
698 Set_Analyzed (Low_Bound (Def), False);
699 Set_Analyzed (High_Bound (Def), False);
701 if Denotes_Discriminant (Low_Bound (Def)) then
702 Set_Entity (Low_Bound (Def), Empty);
705 if Denotes_Discriminant (High_Bound (Def)) then
706 Set_Entity (High_Bound (Def), Empty);
710 Make_Index (Def, Index_Spec);
712 (Defining_Identifier (Index_Spec), Etype (Def));
724 if Entry_Name = Any_Id then
725 Error_Msg_N ("no entry declaration matches entry body", N);
728 elsif Has_Completion (Entry_Name) then
729 Error_Msg_N ("duplicate entry body", N);
733 Set_Has_Completion (Entry_Name);
734 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
735 Style.Check_Identifier (Id, Entry_Name);
738 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
739 Push_Scope (Entry_Name);
741 Exp_Ch9.Expand_Entry_Body_Declarations (N);
742 Install_Declarations (Entry_Name);
743 Set_Actual_Subtypes (N, Current_Scope);
745 -- The entity for the protected subprogram corresponding to the entry
746 -- has been created. We retain the name of this entity in the entry
747 -- body, for use when the corresponding subprogram body is created.
748 -- Note that entry bodies have no corresponding_spec, and there is no
749 -- easy link back in the tree between the entry body and the entity for
750 -- the entry itself, which is why we must propagate some attributes
751 -- explicitly from spec to body.
753 Set_Protected_Body_Subprogram
754 (Id, Protected_Body_Subprogram (Entry_Name));
756 Set_Entry_Parameters_Type
757 (Id, Entry_Parameters_Type (Entry_Name));
759 if Present (Decls) then
760 Analyze_Declarations (Decls);
763 if Present (Stats) then
767 -- Check for unreferenced variables etc. Before the Check_References
768 -- call, we transfer Never_Set_In_Source and Referenced flags from
769 -- parameters in the spec to the corresponding entities in the body,
770 -- since we want the warnings on the body entities. Note that we do
771 -- not have to transfer Referenced_As_LHS, since that flag can only
772 -- be set for simple variables.
774 -- At the same time, we set the flags on the spec entities to suppress
775 -- any warnings on the spec formals, since we also scan the spec.
776 -- Finally, we propagate the Entry_Component attribute to the body
777 -- formals, for use in the renaming declarations created later for the
778 -- formals (see exp_ch9.Add_Formal_Renamings).
785 E1 := First_Entity (Entry_Name);
786 while Present (E1) loop
787 E2 := First_Entity (Id);
788 while Present (E2) loop
789 exit when Chars (E1) = Chars (E2);
793 -- If no matching body entity, then we already had a detected
794 -- error of some kind, so just forget about worrying about these
801 if Ekind (E1) = E_Out_Parameter then
802 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
803 Set_Never_Set_In_Source (E1, False);
806 Set_Referenced (E2, Referenced (E1));
808 Set_Entry_Component (E2, Entry_Component (E1));
814 Check_References (Id);
817 -- We still need to check references for the spec, since objects
818 -- declared in the body are chained (in the First_Entity sense) to
819 -- the spec rather than the body in the case of entries.
821 Check_References (Entry_Name);
823 -- Process the end label, and terminate the scope
825 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
828 -- If this is an entry family, remove the loop created to provide
829 -- a scope for the entry index.
831 if Ekind (Id) = E_Entry_Family
832 and then Present (Entry_Index_Specification (Formals))
836 end Analyze_Entry_Body;
838 ------------------------------------
839 -- Analyze_Entry_Body_Formal_Part --
840 ------------------------------------
842 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
843 Id : constant Entity_Id := Defining_Identifier (Parent (N));
844 Index : constant Node_Id := Entry_Index_Specification (N);
845 Formals : constant List_Id := Parameter_Specifications (N);
848 Tasking_Used := True;
850 if Present (Index) then
853 -- The entry index functions like a loop variable, thus it is known
854 -- to have a valid value.
856 Set_Is_Known_Valid (Defining_Identifier (Index));
859 if Present (Formals) then
860 Set_Scope (Id, Current_Scope);
862 Process_Formals (Formals, Parent (N));
865 end Analyze_Entry_Body_Formal_Part;
867 ------------------------------------
868 -- Analyze_Entry_Call_Alternative --
869 ------------------------------------
871 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
872 Call : constant Node_Id := Entry_Call_Statement (N);
875 Tasking_Used := True;
877 if Present (Pragmas_Before (N)) then
878 Analyze_List (Pragmas_Before (N));
881 if Nkind (Call) = N_Attribute_Reference then
883 -- Possibly a stream attribute, but definitely illegal. Other
884 -- illegalitles, such as procedure calls, are diagnosed after
887 Error_Msg_N ("entry call alternative requires an entry call", Call);
893 if Is_Non_Empty_List (Statements (N)) then
894 Analyze_Statements (Statements (N));
896 end Analyze_Entry_Call_Alternative;
898 -------------------------------
899 -- Analyze_Entry_Declaration --
900 -------------------------------
902 procedure Analyze_Entry_Declaration (N : Node_Id) is
903 Formals : constant List_Id := Parameter_Specifications (N);
904 Id : constant Entity_Id := Defining_Identifier (N);
905 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
908 Generate_Definition (Id);
909 Tasking_Used := True;
912 Set_Ekind (Id, E_Entry);
915 Set_Ekind (Id, E_Entry_Family);
917 Make_Index (D_Sdef, N, Id);
920 Set_Etype (Id, Standard_Void_Type);
921 Set_Convention (Id, Convention_Entry);
922 Set_Accept_Address (Id, New_Elmt_List);
924 if Present (Formals) then
925 Set_Scope (Id, Current_Scope);
927 Process_Formals (Formals, N);
928 Create_Extra_Formals (Id);
932 if Ekind (Id) = E_Entry then
933 New_Overloaded_Entity (Id);
936 Generate_Reference_To_Formals (Id);
937 end Analyze_Entry_Declaration;
939 ---------------------------------------
940 -- Analyze_Entry_Index_Specification --
941 ---------------------------------------
943 -- The Defining_Identifier of the entry index specification is local to the
944 -- entry body, but it must be available in the entry barrier which is
945 -- evaluated outside of the entry body. The index is eventually renamed as
946 -- a run-time object, so is visibility is strictly a front-end concern. In
947 -- order to make it available to the barrier, we create an additional
948 -- scope, as for a loop, whose only declaration is the index name. This
949 -- loop is not attached to the tree and does not appear as an entity local
950 -- to the protected type, so its existence need only be knwown to routines
951 -- that process entry families.
953 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
954 Iden : constant Node_Id := Defining_Identifier (N);
955 Def : constant Node_Id := Discrete_Subtype_Definition (N);
956 Loop_Id : constant Entity_Id :=
957 Make_Defining_Identifier (Sloc (N),
958 Chars => New_Internal_Name ('L'));
961 Tasking_Used := True;
964 -- There is no elaboration of the entry index specification. Therefore,
965 -- if the index is a range, it is not resolved and expanded, but the
966 -- bounds are inherited from the entry declaration, and reanalyzed.
967 -- See Analyze_Entry_Body.
969 if Nkind (Def) /= N_Range then
973 Set_Ekind (Loop_Id, E_Loop);
974 Set_Scope (Loop_Id, Current_Scope);
975 Push_Scope (Loop_Id);
977 Set_Ekind (Iden, E_Entry_Index_Parameter);
978 Set_Etype (Iden, Etype (Def));
979 end Analyze_Entry_Index_Specification;
981 ----------------------------
982 -- Analyze_Protected_Body --
983 ----------------------------
985 procedure Analyze_Protected_Body (N : Node_Id) is
986 Body_Id : constant Entity_Id := Defining_Identifier (N);
990 -- This is initially the entity of the protected object or protected
991 -- type involved, but is replaced by the protected type always in the
992 -- case of a single protected declaration, since this is the proper
996 -- This is the entity of the protected object or protected type
997 -- involved, and is the entity used for cross-reference purposes
998 -- (it differs from Spec_Id in the case of a single protected
999 -- object, since Spec_Id is set to the protected type in this case).
1002 Tasking_Used := True;
1003 Set_Ekind (Body_Id, E_Protected_Body);
1004 Spec_Id := Find_Concurrent_Spec (Body_Id);
1006 if Present (Spec_Id)
1007 and then Ekind (Spec_Id) = E_Protected_Type
1011 elsif Present (Spec_Id)
1012 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1013 and then not Comes_From_Source (Etype (Spec_Id))
1018 Error_Msg_N ("missing specification for protected body", Body_Id);
1023 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1024 Style.Check_Identifier (Body_Id, Spec_Id);
1026 -- The declarations are always attached to the type
1028 if Ekind (Spec_Id) /= E_Protected_Type then
1029 Spec_Id := Etype (Spec_Id);
1032 Push_Scope (Spec_Id);
1033 Set_Corresponding_Spec (N, Spec_Id);
1034 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1035 Set_Has_Completion (Spec_Id);
1036 Install_Declarations (Spec_Id);
1038 Exp_Ch9.Expand_Protected_Body_Declarations (N, Spec_Id);
1040 Last_E := Last_Entity (Spec_Id);
1042 Analyze_Declarations (Declarations (N));
1044 -- For visibility purposes, all entities in the body are private. Set
1045 -- First_Private_Entity accordingly, if there was no private part in the
1046 -- protected declaration.
1048 if No (First_Private_Entity (Spec_Id)) then
1049 if Present (Last_E) then
1050 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1052 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1056 Check_Completion (Body_Id);
1057 Check_References (Spec_Id);
1058 Process_End_Label (N, 't', Ref_Id);
1060 end Analyze_Protected_Body;
1062 ----------------------------------
1063 -- Analyze_Protected_Definition --
1064 ----------------------------------
1066 procedure Analyze_Protected_Definition (N : Node_Id) is
1071 Tasking_Used := True;
1072 Analyze_Declarations (Visible_Declarations (N));
1074 if Present (Private_Declarations (N))
1075 and then not Is_Empty_List (Private_Declarations (N))
1077 L := Last_Entity (Current_Scope);
1078 Analyze_Declarations (Private_Declarations (N));
1081 Set_First_Private_Entity (Current_Scope, Next_Entity (L));
1083 Set_First_Private_Entity (Current_Scope,
1084 First_Entity (Current_Scope));
1088 E := First_Entity (Current_Scope);
1089 while Present (E) loop
1090 if Ekind (E) = E_Function
1091 or else Ekind (E) = E_Procedure
1093 Set_Convention (E, Convention_Protected);
1095 elsif Is_Task_Type (Etype (E))
1096 or else Has_Task (Etype (E))
1098 Set_Has_Task (Current_Scope);
1104 Check_Max_Entries (N, Max_Protected_Entries);
1105 Process_End_Label (N, 'e', Current_Scope);
1106 end Analyze_Protected_Definition;
1108 ----------------------------
1109 -- Analyze_Protected_Type --
1110 ----------------------------
1112 procedure Analyze_Protected_Type (N : Node_Id) is
1113 Def_Id : constant Entity_Id := Defining_Identifier (N);
1118 if No_Run_Time_Mode then
1119 Error_Msg_CRT ("protected type", N);
1123 Tasking_Used := True;
1124 Check_Restriction (No_Protected_Types, N);
1126 T := Find_Type_Name (N);
1128 if Ekind (T) = E_Incomplete_Type then
1130 Set_Completion_Referenced (T);
1133 Set_Ekind (T, E_Protected_Type);
1134 Set_Is_First_Subtype (T, True);
1135 Init_Size_Align (T);
1137 Set_Has_Delayed_Freeze (T, True);
1138 Set_Stored_Constraint (T, No_Elist);
1141 if Ada_Version >= Ada_05 then
1142 Check_Interfaces (N, T);
1145 if Present (Discriminant_Specifications (N)) then
1146 if Has_Discriminants (T) then
1148 -- Install discriminants. Also, verify conformance of
1149 -- discriminants of previous and current view. ???
1151 Install_Declarations (T);
1153 Process_Discriminants (N);
1157 Set_Is_Constrained (T, not Has_Discriminants (T));
1159 -- Perform minimal expansion of the protected type while inside of a
1160 -- generic. The corresponding record is needed for various semantic
1163 if Ada_Version >= Ada_05
1164 and then Inside_A_Generic
1166 Insert_After_And_Analyze (N,
1167 Build_Corresponding_Record (N, T, Sloc (T)));
1170 Analyze (Protected_Definition (N));
1172 -- Protected types with entries are controlled (because of the
1173 -- Protection component if nothing else), same for any protected type
1174 -- with interrupt handlers. Note that we need to analyze the protected
1175 -- definition to set Has_Entries and such.
1177 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
1178 or else Number_Entries (T) > 1)
1181 or else Has_Interrupt_Handler (T)
1182 or else Has_Attach_Handler (T))
1184 Set_Has_Controlled_Component (T, True);
1187 -- The Ekind of components is E_Void during analysis to detect illegal
1188 -- uses. Now it can be set correctly.
1190 E := First_Entity (Current_Scope);
1191 while Present (E) loop
1192 if Ekind (E) = E_Void then
1193 Set_Ekind (E, E_Component);
1194 Init_Component_Location (E);
1202 -- Case of a completion of a private declaration
1205 and then Is_Private_Type (Def_Id)
1207 -- Deal with preelaborable initialization. Note that this processing
1208 -- is done by Process_Full_View, but as can be seen below, in this
1209 -- case the call to Process_Full_View is skipped if any serious
1210 -- errors have occurred, and we don't want to lose this check.
1212 if Known_To_Have_Preelab_Init (Def_Id) then
1213 Set_Must_Have_Preelab_Init (T);
1216 -- Create corresponding record now, because some private dependents
1217 -- may be subtypes of the partial view. Skip if errors are present,
1218 -- to prevent cascaded messages.
1220 if Serious_Errors_Detected = 0
1221 and then Expander_Active
1223 Expand_N_Protected_Type_Declaration (N);
1224 Process_Full_View (N, T, Def_Id);
1227 end Analyze_Protected_Type;
1229 ---------------------
1230 -- Analyze_Requeue --
1231 ---------------------
1233 procedure Analyze_Requeue (N : Node_Id) is
1234 Count : Natural := 0;
1235 Entry_Name : Node_Id := Name (N);
1236 Entry_Id : Entity_Id;
1239 Enclosing : Entity_Id;
1240 Target_Obj : Node_Id := Empty;
1241 Req_Scope : Entity_Id;
1242 Outer_Ent : Entity_Id;
1245 Check_Restriction (No_Requeue_Statements, N);
1246 Check_Unreachable_Code (N);
1247 Tasking_Used := True;
1250 for J in reverse 0 .. Scope_Stack.Last loop
1251 Enclosing := Scope_Stack.Table (J).Entity;
1252 exit when Is_Entry (Enclosing);
1254 if Ekind (Enclosing) /= E_Block
1255 and then Ekind (Enclosing) /= E_Loop
1257 Error_Msg_N ("requeue must appear within accept or entry body", N);
1262 Analyze (Entry_Name);
1264 if Etype (Entry_Name) = Any_Type then
1268 if Nkind (Entry_Name) = N_Selected_Component then
1269 Target_Obj := Prefix (Entry_Name);
1270 Entry_Name := Selector_Name (Entry_Name);
1273 -- If an explicit target object is given then we have to check the
1274 -- restrictions of 9.5.4(6).
1276 if Present (Target_Obj) then
1278 -- Locate containing concurrent unit and determine enclosing entry
1279 -- body or outermost enclosing accept statement within the unit.
1282 for S in reverse 0 .. Scope_Stack.Last loop
1283 Req_Scope := Scope_Stack.Table (S).Entity;
1285 exit when Ekind (Req_Scope) in Task_Kind
1286 or else Ekind (Req_Scope) in Protected_Kind;
1288 if Is_Entry (Req_Scope) then
1289 Outer_Ent := Req_Scope;
1293 pragma Assert (Present (Outer_Ent));
1295 -- Check that the accessibility level of the target object is not
1296 -- greater or equal to the outermost enclosing accept statement (or
1297 -- entry body) unless it is a parameter of the innermost enclosing
1298 -- accept statement (or entry body).
1300 if Object_Access_Level (Target_Obj) >= Scope_Depth (Outer_Ent)
1302 (not Is_Entity_Name (Target_Obj)
1303 or else Ekind (Entity (Target_Obj)) not in Formal_Kind
1304 or else Enclosing /= Scope (Entity (Target_Obj)))
1307 ("target object has invalid level for requeue", Target_Obj);
1311 -- Overloaded case, find right interpretation
1313 if Is_Overloaded (Entry_Name) then
1316 Get_First_Interp (Entry_Name, I, It);
1317 while Present (It.Nam) loop
1318 if No (First_Formal (It.Nam))
1319 or else Subtype_Conformant (Enclosing, It.Nam)
1321 -- Ada 2005 (AI-345): Since protected and task types have
1322 -- primitive entry wrappers, we only consider source entries.
1324 if Comes_From_Source (It.Nam) then
1332 Get_Next_Interp (I, It);
1336 Error_Msg_N ("no entry matches context", N);
1339 elsif Count > 1 then
1340 Error_Msg_N ("ambiguous entry name in requeue", N);
1344 Set_Is_Overloaded (Entry_Name, False);
1345 Set_Entity (Entry_Name, Entry_Id);
1348 -- Non-overloaded cases
1350 -- For the case of a reference to an element of an entry family, the
1351 -- Entry_Name is an indexed component.
1353 elsif Nkind (Entry_Name) = N_Indexed_Component then
1355 -- Requeue to an entry out of the body
1357 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
1358 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
1360 -- Requeue from within the body itself
1362 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
1363 Entry_Id := Entity (Prefix (Entry_Name));
1366 Error_Msg_N ("invalid entry_name specified", N);
1370 -- If we had a requeue of the form REQUEUE A (B), then the parser
1371 -- accepted it (because it could have been a requeue on an entry index.
1372 -- If A turns out not to be an entry family, then the analysis of A (B)
1373 -- turned it into a function call.
1375 elsif Nkind (Entry_Name) = N_Function_Call then
1377 ("arguments not allowed in requeue statement",
1378 First (Parameter_Associations (Entry_Name)));
1381 -- Normal case of no entry family, no argument
1384 Entry_Id := Entity (Entry_Name);
1387 -- Resolve entry, and check that it is subtype conformant with the
1388 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1390 if not Is_Entry (Entry_Id) then
1391 Error_Msg_N ("expect entry name in requeue statement", Name (N));
1392 elsif Ekind (Entry_Id) = E_Entry_Family
1393 and then Nkind (Entry_Name) /= N_Indexed_Component
1395 Error_Msg_N ("missing index for entry family component", Name (N));
1398 Resolve_Entry (Name (N));
1399 Generate_Reference (Entry_Id, Entry_Name);
1401 if Present (First_Formal (Entry_Id)) then
1402 if VM_Target = JVM_Target and then not Inspector_Mode then
1404 ("arguments unsupported in requeue statement",
1405 First_Formal (Entry_Id));
1409 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
1411 -- Processing for parameters accessed by the requeue
1417 Ent := First_Formal (Enclosing);
1418 while Present (Ent) loop
1420 -- For OUT or IN OUT parameter, the effect of the requeue is
1421 -- to assign the parameter a value on exit from the requeued
1422 -- body, so we can set it as source assigned. We also clear
1423 -- the Is_True_Constant indication. We do not need to clear
1424 -- Current_Value, since the effect of the requeue is to
1425 -- perform an unconditional goto so that any further
1426 -- references will not occur anyway.
1428 if Ekind (Ent) = E_Out_Parameter
1430 Ekind (Ent) = E_In_Out_Parameter
1432 Set_Never_Set_In_Source (Ent, False);
1433 Set_Is_True_Constant (Ent, False);
1436 -- For all parameters, the requeue acts as a reference,
1437 -- since the value of the parameter is passed to the new
1438 -- entry, so we want to suppress unreferenced warnings.
1440 Set_Referenced (Ent);
1446 end Analyze_Requeue;
1448 ------------------------------
1449 -- Analyze_Selective_Accept --
1450 ------------------------------
1452 procedure Analyze_Selective_Accept (N : Node_Id) is
1453 Alts : constant List_Id := Select_Alternatives (N);
1456 Accept_Present : Boolean := False;
1457 Terminate_Present : Boolean := False;
1458 Delay_Present : Boolean := False;
1459 Relative_Present : Boolean := False;
1460 Alt_Count : Uint := Uint_0;
1463 Check_Restriction (No_Select_Statements, N);
1464 Tasking_Used := True;
1466 -- Loop to analyze alternatives
1468 Alt := First (Alts);
1469 while Present (Alt) loop
1470 Alt_Count := Alt_Count + 1;
1473 if Nkind (Alt) = N_Delay_Alternative then
1474 if Delay_Present then
1476 if Relative_Present /=
1477 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
1480 ("delay_until and delay_relative alternatives ", Alt);
1482 ("\cannot appear in the same selective_wait", Alt);
1486 Delay_Present := True;
1488 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
1491 elsif Nkind (Alt) = N_Terminate_Alternative then
1492 if Terminate_Present then
1493 Error_Msg_N ("only one terminate alternative allowed", N);
1495 Terminate_Present := True;
1496 Check_Restriction (No_Terminate_Alternatives, N);
1499 elsif Nkind (Alt) = N_Accept_Alternative then
1500 Accept_Present := True;
1502 -- Check for duplicate accept
1506 Stm : constant Node_Id := Accept_Statement (Alt);
1507 EDN : constant Node_Id := Entry_Direct_Name (Stm);
1511 if Nkind (EDN) = N_Identifier
1512 and then No (Condition (Alt))
1513 and then Present (Entity (EDN)) -- defend against junk
1514 and then Ekind (Entity (EDN)) = E_Entry
1516 Ent := Entity (EDN);
1518 Alt1 := First (Alts);
1519 while Alt1 /= Alt loop
1520 if Nkind (Alt1) = N_Accept_Alternative
1521 and then No (Condition (Alt1))
1524 Stm1 : constant Node_Id := Accept_Statement (Alt1);
1525 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
1528 if Nkind (EDN1) = N_Identifier then
1529 if Entity (EDN1) = Ent then
1530 Error_Msg_Sloc := Sloc (Stm1);
1532 ("?accept duplicates one on line#", Stm);
1548 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
1549 Check_Potentially_Blocking_Operation (N);
1551 if Terminate_Present and Delay_Present then
1552 Error_Msg_N ("at most one of terminate or delay alternative", N);
1554 elsif not Accept_Present then
1556 ("select must contain at least one accept alternative", N);
1559 if Present (Else_Statements (N)) then
1560 if Terminate_Present or Delay_Present then
1561 Error_Msg_N ("else part not allowed with other alternatives", N);
1564 Analyze_Statements (Else_Statements (N));
1566 end Analyze_Selective_Accept;
1568 ------------------------------
1569 -- Analyze_Single_Protected --
1570 ------------------------------
1572 procedure Analyze_Single_Protected (N : Node_Id) is
1573 Loc : constant Source_Ptr := Sloc (N);
1574 Id : constant Node_Id := Defining_Identifier (N);
1578 O_Name : constant Entity_Id := Id;
1581 Generate_Definition (Id);
1582 Tasking_Used := True;
1584 -- The node is rewritten as a protected type declaration, in exact
1585 -- analogy with what is done with single tasks.
1588 Make_Defining_Identifier (Sloc (Id),
1589 New_External_Name (Chars (Id), 'T'));
1592 Make_Protected_Type_Declaration (Loc,
1593 Defining_Identifier => T,
1594 Protected_Definition => Relocate_Node (Protected_Definition (N)),
1595 Interface_List => Interface_List (N));
1598 Make_Object_Declaration (Loc,
1599 Defining_Identifier => O_Name,
1600 Object_Definition => Make_Identifier (Loc, Chars (T)));
1602 Rewrite (N, T_Decl);
1603 Insert_After (N, O_Decl);
1604 Mark_Rewrite_Insertion (O_Decl);
1606 -- Enter names of type and object before analysis, because the name of
1607 -- the object may be used in its own body.
1610 Set_Ekind (T, E_Protected_Type);
1613 Enter_Name (O_Name);
1614 Set_Ekind (O_Name, E_Variable);
1615 Set_Etype (O_Name, T);
1617 -- Instead of calling Analyze on the new node, call the proper analysis
1618 -- procedure directly. Otherwise the node would be expanded twice, with
1619 -- disastrous result.
1621 Analyze_Protected_Type (N);
1622 end Analyze_Single_Protected;
1624 -------------------------
1625 -- Analyze_Single_Task --
1626 -------------------------
1628 procedure Analyze_Single_Task (N : Node_Id) is
1629 Loc : constant Source_Ptr := Sloc (N);
1630 Id : constant Node_Id := Defining_Identifier (N);
1634 O_Name : constant Entity_Id := Id;
1637 Generate_Definition (Id);
1638 Tasking_Used := True;
1640 -- The node is rewritten as a task type declaration, followed by an
1641 -- object declaration of that anonymous task type.
1644 Make_Defining_Identifier (Sloc (Id),
1645 New_External_Name (Chars (Id), Suffix => "TK"));
1648 Make_Task_Type_Declaration (Loc,
1649 Defining_Identifier => T,
1650 Task_Definition => Relocate_Node (Task_Definition (N)),
1651 Interface_List => Interface_List (N));
1653 -- We use the original defining identifier of the single task in the
1654 -- generated object declaration, so that debugging information can
1655 -- be attached to it when compiling with -gnatD. The parent of the
1656 -- entity is the new object declaration. The single_task_declaration
1657 -- is not used further in semantics or code generation, but is scanned
1658 -- when generating debug information, and therefore needs the updated
1659 -- Sloc information for the entity (see Sprint).
1662 Make_Object_Declaration (Loc,
1663 Defining_Identifier => O_Name,
1664 Object_Definition => Make_Identifier (Loc, Chars (T)));
1666 Rewrite (N, T_Decl);
1667 Insert_After (N, O_Decl);
1668 Mark_Rewrite_Insertion (O_Decl);
1670 -- Enter names of type and object before analysis, because the name of
1671 -- the object may be used in its own body.
1674 Set_Ekind (T, E_Task_Type);
1677 Enter_Name (O_Name);
1678 Set_Ekind (O_Name, E_Variable);
1679 Set_Etype (O_Name, T);
1681 -- Instead of calling Analyze on the new node, call the proper analysis
1682 -- procedure directly. Otherwise the node would be expanded twice, with
1683 -- disastrous result.
1685 Analyze_Task_Type (N);
1686 end Analyze_Single_Task;
1688 -----------------------
1689 -- Analyze_Task_Body --
1690 -----------------------
1692 procedure Analyze_Task_Body (N : Node_Id) is
1693 Body_Id : constant Entity_Id := Defining_Identifier (N);
1694 HSS : constant Node_Id := Handled_Statement_Sequence (N);
1697 Spec_Id : Entity_Id;
1698 -- This is initially the entity of the task or task type involved, but
1699 -- is replaced by the task type always in the case of a single task
1700 -- declaration, since this is the proper scope to be used.
1703 -- This is the entity of the task or task type, and is the entity used
1704 -- for cross-reference purposes (it differs from Spec_Id in the case of
1705 -- a single task, since Spec_Id is set to the task type)
1708 Tasking_Used := True;
1709 Set_Ekind (Body_Id, E_Task_Body);
1710 Set_Scope (Body_Id, Current_Scope);
1711 Spec_Id := Find_Concurrent_Spec (Body_Id);
1713 -- The spec is either a task type declaration, or a single task
1714 -- declaration for which we have created an anonymous type.
1716 if Present (Spec_Id)
1717 and then Ekind (Spec_Id) = E_Task_Type
1721 elsif Present (Spec_Id)
1722 and then Ekind (Etype (Spec_Id)) = E_Task_Type
1723 and then not Comes_From_Source (Etype (Spec_Id))
1728 Error_Msg_N ("missing specification for task body", Body_Id);
1732 if Has_Completion (Spec_Id)
1733 and then Present (Corresponding_Body (Parent (Spec_Id)))
1735 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
1736 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
1739 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
1744 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1745 Style.Check_Identifier (Body_Id, Spec_Id);
1747 -- Deal with case of body of single task (anonymous type was created)
1749 if Ekind (Spec_Id) = E_Variable then
1750 Spec_Id := Etype (Spec_Id);
1753 Push_Scope (Spec_Id);
1754 Set_Corresponding_Spec (N, Spec_Id);
1755 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1756 Set_Has_Completion (Spec_Id);
1757 Install_Declarations (Spec_Id);
1758 Last_E := Last_Entity (Spec_Id);
1760 Analyze_Declarations (Declarations (N));
1762 -- For visibility purposes, all entities in the body are private. Set
1763 -- First_Private_Entity accordingly, if there was no private part in the
1764 -- protected declaration.
1766 if No (First_Private_Entity (Spec_Id)) then
1767 if Present (Last_E) then
1768 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1770 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1774 -- Mark all handlers as not suitable for local raise optimization,
1775 -- since this optimization causes difficulties in a task context.
1777 if Present (Exception_Handlers (HSS)) then
1781 Handlr := First (Exception_Handlers (HSS));
1782 while Present (Handlr) loop
1783 Set_Local_Raise_Not_OK (Handlr);
1789 -- Now go ahead and complete analysis of the task body
1792 Check_Completion (Body_Id);
1793 Check_References (Body_Id);
1794 Check_References (Spec_Id);
1796 -- Check for entries with no corresponding accept
1802 Ent := First_Entity (Spec_Id);
1803 while Present (Ent) loop
1805 and then not Entry_Accepted (Ent)
1806 and then Comes_From_Source (Ent)
1808 Error_Msg_NE ("no accept for entry &?", N, Ent);
1815 Process_End_Label (HSS, 't', Ref_Id);
1817 end Analyze_Task_Body;
1819 -----------------------------
1820 -- Analyze_Task_Definition --
1821 -----------------------------
1823 procedure Analyze_Task_Definition (N : Node_Id) is
1827 Tasking_Used := True;
1829 if Present (Visible_Declarations (N)) then
1830 Analyze_Declarations (Visible_Declarations (N));
1833 if Present (Private_Declarations (N)) then
1834 L := Last_Entity (Current_Scope);
1835 Analyze_Declarations (Private_Declarations (N));
1838 Set_First_Private_Entity
1839 (Current_Scope, Next_Entity (L));
1841 Set_First_Private_Entity
1842 (Current_Scope, First_Entity (Current_Scope));
1846 Check_Max_Entries (N, Max_Task_Entries);
1847 Process_End_Label (N, 'e', Current_Scope);
1848 end Analyze_Task_Definition;
1850 -----------------------
1851 -- Analyze_Task_Type --
1852 -----------------------
1854 procedure Analyze_Task_Type (N : Node_Id) is
1855 Def_Id : constant Entity_Id := Defining_Identifier (N);
1859 Check_Restriction (No_Tasking, N);
1860 Tasking_Used := True;
1861 T := Find_Type_Name (N);
1862 Generate_Definition (T);
1864 if Ekind (T) = E_Incomplete_Type then
1866 Set_Completion_Referenced (T);
1869 Set_Ekind (T, E_Task_Type);
1870 Set_Is_First_Subtype (T, True);
1871 Set_Has_Task (T, True);
1872 Init_Size_Align (T);
1874 Set_Has_Delayed_Freeze (T, True);
1875 Set_Stored_Constraint (T, No_Elist);
1878 if Ada_Version >= Ada_05 then
1879 Check_Interfaces (N, T);
1882 if Present (Discriminant_Specifications (N)) then
1883 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1884 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
1887 if Has_Discriminants (T) then
1889 -- Install discriminants. Also, verify conformance of
1890 -- discriminants of previous and current view. ???
1892 Install_Declarations (T);
1894 Process_Discriminants (N);
1898 Set_Is_Constrained (T, not Has_Discriminants (T));
1900 -- Perform minimal expansion of the task type while inside a generic
1901 -- context. The corresponding record is needed for various semantic
1904 if Inside_A_Generic then
1905 Insert_After_And_Analyze (N,
1906 Build_Corresponding_Record (N, T, Sloc (T)));
1909 if Present (Task_Definition (N)) then
1910 Analyze_Task_Definition (Task_Definition (N));
1913 if not Is_Library_Level_Entity (T) then
1914 Check_Restriction (No_Task_Hierarchy, N);
1919 -- Case of a completion of a private declaration
1922 and then Is_Private_Type (Def_Id)
1924 -- Deal with preelaborable initialization. Note that this processing
1925 -- is done by Process_Full_View, but as can be seen below, in this
1926 -- case the call to Process_Full_View is skipped if any serious
1927 -- errors have occurred, and we don't want to lose this check.
1929 if Known_To_Have_Preelab_Init (Def_Id) then
1930 Set_Must_Have_Preelab_Init (T);
1933 -- Create corresponding record now, because some private dependents
1934 -- may be subtypes of the partial view. Skip if errors are present,
1935 -- to prevent cascaded messages.
1937 if Serious_Errors_Detected = 0
1938 and then Expander_Active
1940 Expand_N_Task_Type_Declaration (N);
1941 Process_Full_View (N, T, Def_Id);
1944 end Analyze_Task_Type;
1946 -----------------------------------
1947 -- Analyze_Terminate_Alternative --
1948 -----------------------------------
1950 procedure Analyze_Terminate_Alternative (N : Node_Id) is
1952 Tasking_Used := True;
1954 if Present (Pragmas_Before (N)) then
1955 Analyze_List (Pragmas_Before (N));
1958 if Present (Condition (N)) then
1959 Analyze_And_Resolve (Condition (N), Any_Boolean);
1961 end Analyze_Terminate_Alternative;
1963 ------------------------------
1964 -- Analyze_Timed_Entry_Call --
1965 ------------------------------
1967 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
1969 Check_Restriction (No_Select_Statements, N);
1970 Tasking_Used := True;
1971 Analyze (Entry_Call_Alternative (N));
1972 Analyze (Delay_Alternative (N));
1973 end Analyze_Timed_Entry_Call;
1975 ------------------------------------
1976 -- Analyze_Triggering_Alternative --
1977 ------------------------------------
1979 procedure Analyze_Triggering_Alternative (N : Node_Id) is
1980 Trigger : constant Node_Id := Triggering_Statement (N);
1983 Tasking_Used := True;
1985 if Present (Pragmas_Before (N)) then
1986 Analyze_List (Pragmas_Before (N));
1991 if Comes_From_Source (Trigger)
1992 and then Nkind (Trigger) not in N_Delay_Statement
1993 and then Nkind (Trigger) /= N_Entry_Call_Statement
1995 if Ada_Version < Ada_05 then
1997 ("triggering statement must be delay or entry call", Trigger);
1999 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
2000 -- procedure_or_entry_call, the procedure_name or pro- cedure_prefix
2001 -- of the procedure_call_statement shall denote an entry renamed by a
2002 -- procedure, or (a view of) a primitive subprogram of a limited
2003 -- interface whose first parameter is a controlling parameter.
2005 elsif Nkind (Trigger) = N_Procedure_Call_Statement
2006 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
2007 and then not Is_Controlling_Limited_Procedure
2008 (Entity (Name (Trigger)))
2010 Error_Msg_N ("triggering statement must be delay, procedure " &
2011 "or entry call", Trigger);
2015 if Is_Non_Empty_List (Statements (N)) then
2016 Analyze_Statements (Statements (N));
2018 end Analyze_Triggering_Alternative;
2020 -----------------------
2021 -- Check_Max_Entries --
2022 -----------------------
2024 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
2027 procedure Count (L : List_Id);
2028 -- Count entries in given declaration list
2034 procedure Count (L : List_Id) is
2043 while Present (D) loop
2044 if Nkind (D) = N_Entry_Declaration then
2046 DSD : constant Node_Id :=
2047 Discrete_Subtype_Definition (D);
2050 -- If not an entry family, then just one entry
2053 Ecount := Ecount + 1;
2055 -- If entry family with static bounds, count entries
2057 elsif Is_OK_Static_Subtype (Etype (DSD)) then
2059 Lo : constant Uint :=
2061 (Type_Low_Bound (Etype (DSD)));
2062 Hi : constant Uint :=
2064 (Type_High_Bound (Etype (DSD)));
2068 Ecount := Ecount + Hi - Lo + 1;
2072 -- Entry family with non-static bounds
2075 -- If restriction is set, then this is an error
2077 if Restrictions.Set (R) then
2079 ("static subtype required by Restriction pragma",
2082 -- Otherwise we record an unknown count restriction
2085 Check_Restriction (R, D);
2095 -- Start of processing for Check_Max_Entries
2099 Count (Visible_Declarations (D));
2100 Count (Private_Declarations (D));
2103 Check_Restriction (R, D, Ecount);
2105 end Check_Max_Entries;
2107 ----------------------
2108 -- Check_Interfaces --
2109 ----------------------
2111 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
2113 Iface_Typ : Entity_Id;
2116 pragma Assert (Nkind (N) = N_Protected_Type_Declaration
2117 or else Nkind (N) = N_Task_Type_Declaration);
2119 if Present (Interface_List (N)) then
2120 Set_Is_Tagged_Type (T);
2122 Iface := First (Interface_List (N));
2123 while Present (Iface) loop
2124 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
2126 if not Is_Interface (Iface_Typ) then
2128 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
2131 -- Ada 2005 (AI-251): "The declaration of a specific descendant
2132 -- of an interface type freezes the interface type" RM 13.14.
2134 Freeze_Before (N, Etype (Iface));
2136 if Nkind (N) = N_Protected_Type_Declaration then
2138 -- Ada 2005 (AI-345): Protected types can only implement
2139 -- limited, synchronized, or protected interfaces (note that
2140 -- the predicate Is_Limited_Interface includes synchronized
2141 -- and protected interfaces).
2143 if Is_Task_Interface (Iface_Typ) then
2144 Error_Msg_N ("(Ada 2005) protected type cannot implement "
2145 & "a task interface", Iface);
2147 elsif not Is_Limited_Interface (Iface_Typ) then
2148 Error_Msg_N ("(Ada 2005) protected type cannot implement "
2149 & "a non-limited interface", Iface);
2152 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
2154 -- Ada 2005 (AI-345): Task types can only implement limited,
2155 -- synchronized, or task interfaces (note that the predicate
2156 -- Is_Limited_Interface includes synchronized and task
2159 if Is_Protected_Interface (Iface_Typ) then
2160 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
2161 "protected interface", Iface);
2163 elsif not Is_Limited_Interface (Iface_Typ) then
2164 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
2165 "non-limited interface", Iface);
2174 if not Has_Private_Declaration (T) then
2178 -- Additional checks on full-types associated with private type
2179 -- declarations. Search for the private type declaration.
2182 Full_T_Ifaces : Elist_Id;
2185 Priv_T_Ifaces : Elist_Id;
2188 Priv_T := First_Entity (Scope (T));
2190 pragma Assert (Present (Priv_T));
2192 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
2193 exit when Full_View (Priv_T) = T;
2196 Next_Entity (Priv_T);
2199 -- In case of synchronized types covering interfaces the private type
2200 -- declaration must be limited.
2202 if Present (Interface_List (N))
2203 and then not Is_Limited_Record (Priv_T)
2205 Error_Msg_Sloc := Sloc (Priv_T);
2206 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
2207 "private type#", T);
2210 -- RM 7.3 (7.1/2): If the full view has a partial view that is
2211 -- tagged then check RM 7.3 subsidiary rules.
2213 if Is_Tagged_Type (Priv_T)
2214 and then not Error_Posted (N)
2216 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
2217 -- type if and only if the full type is a synchronized tagged type
2219 if Is_Synchronized_Tagged_Type (Priv_T)
2220 and then not Is_Synchronized_Tagged_Type (T)
2223 ("(Ada 2005) full view must be a synchronized tagged " &
2224 "type ('R'M 7.3 (7.2/2))", Priv_T);
2226 elsif Is_Synchronized_Tagged_Type (T)
2227 and then not Is_Synchronized_Tagged_Type (Priv_T)
2230 ("(Ada 2005) partial view must be a synchronized tagged " &
2231 "type ('R'M 7.3 (7.2/2))", T);
2234 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
2235 -- interface type if and only if the full type is descendant of
2236 -- the interface type.
2238 if Present (Interface_List (N))
2239 or else (Is_Tagged_Type (Priv_T)
2240 and then Has_Abstract_Interfaces
2241 (Priv_T, Use_Full_View => False))
2243 if Is_Tagged_Type (Priv_T) then
2244 Collect_Abstract_Interfaces
2245 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
2248 if Is_Tagged_Type (T) then
2249 Collect_Abstract_Interfaces (T, Full_T_Ifaces);
2252 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
2254 if Present (Iface) then
2255 Error_Msg_NE ("interface & not implemented by full type " &
2256 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
2259 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
2261 if Present (Iface) then
2262 Error_Msg_NE ("interface & not implemented by partial " &
2263 "view (RM-2005 7.3 (7.3/2))", T, Iface);
2268 end Check_Interfaces;
2270 --------------------------
2271 -- Find_Concurrent_Spec --
2272 --------------------------
2274 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
2275 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
2278 -- The type may have been given by an incomplete type declaration.
2279 -- Find full view now.
2281 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
2282 Spec_Id := Full_View (Spec_Id);
2286 end Find_Concurrent_Spec;
2288 --------------------------
2289 -- Install_Declarations --
2290 --------------------------
2292 procedure Install_Declarations (Spec : Entity_Id) is
2296 E := First_Entity (Spec);
2297 while Present (E) loop
2298 Prev := Current_Entity (E);
2299 Set_Current_Entity (E);
2300 Set_Is_Immediately_Visible (E);
2301 Set_Homonym (E, Prev);
2304 end Install_Declarations;