1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Exp_Ch9; use Exp_Ch9;
32 with Elists; use Elists;
33 with Freeze; use Freeze;
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_Aux; use Sem_Aux;
44 with Sem_Ch3; use Sem_Ch3;
45 with Sem_Ch5; use Sem_Ch5;
46 with Sem_Ch6; use Sem_Ch6;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Ch13; use Sem_Ch13;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sem_Util; use Sem_Util;
53 with Sem_Warn; use Sem_Warn;
54 with Snames; use Snames;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Uintp; use Uintp;
62 package body Sem_Ch9 is
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions);
69 -- Given either a protected definition or a task definition in D, check
70 -- the corresponding restriction parameter identifier R, and if it is set,
71 -- count the entries (checking the static requirement), and compare with
74 procedure Check_Interfaces (N : Node_Id; T : Entity_Id);
75 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
76 -- Complete decoration of T and check legality of the covered interfaces.
78 procedure Check_Triggering_Statement
81 Is_Dispatching : out Boolean);
82 -- Examine the triggering statement of a select statement, conditional or
83 -- timed entry call. If Trigger is a dispatching call, return its status
84 -- in Is_Dispatching and check whether the primitive belongs to a limited
85 -- interface. If it does not, emit an error at Error_Node.
87 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id;
88 -- Find entity in corresponding task or protected declaration. Use full
89 -- view if first declaration was for an incomplete type.
91 procedure Install_Declarations (Spec : Entity_Id);
92 -- Utility to make visible in corresponding body the entities defined in
93 -- task, protected type declaration, or entry declaration.
95 -----------------------------
96 -- Analyze_Abort_Statement --
97 -----------------------------
99 procedure Analyze_Abort_Statement (N : Node_Id) is
103 -- Abort statement is not allowed in SPARK or ALFA
105 if Formal_Verification_Mode then
106 Error_Msg_F ("|~~abort statement is not allowed", N);
109 -- Proceed with analysis
111 Tasking_Used := True;
112 T_Name := First (Names (N));
113 while Present (T_Name) loop
116 if Is_Task_Type (Etype (T_Name))
117 or else (Ada_Version >= Ada_2005
118 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
119 and then Is_Interface (Etype (T_Name))
120 and then Is_Task_Interface (Etype (T_Name)))
124 if Ada_Version >= Ada_2005 then
125 Error_Msg_N ("expect task name or task interface class-wide "
126 & "object for ABORT", T_Name);
128 Error_Msg_N ("expect task name for ABORT", T_Name);
137 Check_Restriction (No_Abort_Statements, N);
138 Check_Potentially_Blocking_Operation (N);
139 end Analyze_Abort_Statement;
141 --------------------------------
142 -- Analyze_Accept_Alternative --
143 --------------------------------
145 procedure Analyze_Accept_Alternative (N : Node_Id) is
147 Tasking_Used := True;
149 if Present (Pragmas_Before (N)) then
150 Analyze_List (Pragmas_Before (N));
153 if Present (Condition (N)) then
154 Analyze_And_Resolve (Condition (N), Any_Boolean);
157 Analyze (Accept_Statement (N));
159 if Is_Non_Empty_List (Statements (N)) then
160 Analyze_Statements (Statements (N));
162 end Analyze_Accept_Alternative;
164 ------------------------------
165 -- Analyze_Accept_Statement --
166 ------------------------------
168 procedure Analyze_Accept_Statement (N : Node_Id) is
169 Nam : constant Entity_Id := Entry_Direct_Name (N);
170 Formals : constant List_Id := Parameter_Specifications (N);
171 Index : constant Node_Id := Entry_Index (N);
172 Stats : constant Node_Id := Handled_Statement_Sequence (N);
173 Accept_Id : Entity_Id;
174 Entry_Nam : Entity_Id;
177 Task_Nam : Entity_Id;
180 -- Accept statement is not allowed in SPARK or ALFA
182 if Formal_Verification_Mode then
183 Error_Msg_F ("|~~accept statement is not allowed", N);
186 -- Proceed with analysis
188 Tasking_Used := True;
190 -- Entry name is initialized to Any_Id. It should get reset to the
191 -- matching entry entity. An error is signalled if it is not reset.
195 for J in reverse 0 .. Scope_Stack.Last loop
196 Task_Nam := Scope_Stack.Table (J).Entity;
197 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
198 Kind := Ekind (Task_Nam);
200 if Kind /= E_Block and then Kind /= E_Loop
201 and then not Is_Entry (Task_Nam)
203 Error_Msg_N ("enclosing body of accept must be a task", N);
208 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
209 Error_Msg_N ("invalid context for accept statement", N);
213 -- In order to process the parameters, we create a defining identifier
214 -- that can be used as the name of the scope. The name of the accept
215 -- statement itself is not a defining identifier, and we cannot use
216 -- its name directly because the task may have any number of accept
217 -- statements for the same entry.
219 if Present (Index) then
220 Accept_Id := New_Internal_Entity
221 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
223 Accept_Id := New_Internal_Entity
224 (E_Entry, Current_Scope, Sloc (N), 'E');
227 Set_Etype (Accept_Id, Standard_Void_Type);
228 Set_Accept_Address (Accept_Id, New_Elmt_List);
230 if Present (Formals) then
231 Push_Scope (Accept_Id);
232 Process_Formals (Formals, N);
233 Create_Extra_Formals (Accept_Id);
237 -- We set the default expressions processed flag because we don't need
238 -- default expression functions. This is really more like body entity
239 -- than a spec entity anyway.
241 Set_Default_Expressions_Processed (Accept_Id);
243 E := First_Entity (Etype (Task_Nam));
244 while Present (E) loop
245 if Chars (E) = Chars (Nam)
246 and then (Ekind (E) = Ekind (Accept_Id))
247 and then Type_Conformant (Accept_Id, E)
256 if Entry_Nam = Any_Id then
257 Error_Msg_N ("no entry declaration matches accept statement", N);
260 Set_Entity (Nam, Entry_Nam);
261 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
262 Style.Check_Identifier (Nam, Entry_Nam);
265 -- Verify that the entry is not hidden by a procedure declared in the
266 -- current block (pathological but possible).
268 if Current_Scope /= Task_Nam then
273 E1 := First_Entity (Current_Scope);
274 while Present (E1) loop
275 if Ekind (E1) = E_Procedure
276 and then Chars (E1) = Chars (Entry_Nam)
277 and then Type_Conformant (E1, Entry_Nam)
279 Error_Msg_N ("entry name is not visible", N);
287 Set_Convention (Accept_Id, Convention (Entry_Nam));
288 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
290 for J in reverse 0 .. Scope_Stack.Last loop
291 exit when Task_Nam = Scope_Stack.Table (J).Entity;
293 if Entry_Nam = Scope_Stack.Table (J).Entity then
294 Error_Msg_N ("duplicate accept statement for same entry", N);
304 when N_Task_Body | N_Compilation_Unit =>
306 when N_Asynchronous_Select =>
307 Error_Msg_N ("accept statements are not allowed within" &
308 " an asynchronous select inner" &
309 " to the enclosing task body", N);
317 if Ekind (E) = E_Entry_Family then
319 Error_Msg_N ("missing entry index in accept for entry family", N);
321 Analyze_And_Resolve (Index, Entry_Index_Type (E));
322 Apply_Range_Check (Index, Entry_Index_Type (E));
325 elsif Present (Index) then
326 Error_Msg_N ("invalid entry index in accept for simple entry", N);
329 -- If label declarations present, analyze them. They are declared in the
330 -- enclosing task, but their enclosing scope is the entry itself, so
331 -- that goto's to the label are recognized as local to the accept.
333 if Present (Declarations (N)) then
339 Decl := First (Declarations (N));
340 while Present (Decl) loop
344 (Nkind (Decl) = N_Implicit_Label_Declaration);
346 Id := Defining_Identifier (Decl);
347 Set_Enclosing_Scope (Id, Entry_Nam);
353 -- If statements are present, they must be analyzed in the context of
354 -- the entry, so that references to formals are correctly resolved. We
355 -- also have to add the declarations that are required by the expansion
356 -- of the accept statement in this case if expansion active.
358 -- In the case of a select alternative of a selective accept, the
359 -- expander references the address declaration even if there is no
362 -- We also need to create the renaming declarations for the local
363 -- variables that will replace references to the formals within the
366 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
368 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
369 -- fields on all entry formals (this loop ignores all other entities).
370 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
371 -- well, so that we can post accurate warnings on each accept statement
372 -- for the same entry.
374 E := First_Entity (Entry_Nam);
375 while Present (E) loop
376 if Is_Formal (E) then
377 Set_Never_Set_In_Source (E, True);
378 Set_Is_True_Constant (E, False);
379 Set_Current_Value (E, Empty);
380 Set_Referenced (E, False);
381 Set_Referenced_As_LHS (E, False);
382 Set_Referenced_As_Out_Parameter (E, False);
383 Set_Has_Pragma_Unreferenced (E, False);
389 -- Analyze statements if present
391 if Present (Stats) then
392 Push_Scope (Entry_Nam);
393 Install_Declarations (Entry_Nam);
395 Set_Actual_Subtypes (N, Current_Scope);
398 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
402 -- Some warning checks
404 Check_Potentially_Blocking_Operation (N);
405 Check_References (Entry_Nam, N);
406 Set_Entry_Accepted (Entry_Nam);
407 end Analyze_Accept_Statement;
409 ---------------------------------
410 -- Analyze_Asynchronous_Select --
411 ---------------------------------
413 procedure Analyze_Asynchronous_Select (N : Node_Id) is
414 Is_Disp_Select : Boolean := False;
418 -- Select statement is not allowed in SPARK or ALFA
420 if Formal_Verification_Mode then
421 Error_Msg_F ("|~~select statement is not allowed", N);
424 -- Proceed with analysis
426 Tasking_Used := True;
427 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
428 Check_Restriction (No_Select_Statements, N);
430 if Ada_Version >= Ada_2005 then
431 Trigger := Triggering_Statement (Triggering_Alternative (N));
435 -- Ada 2005 (AI-345): Check for a potential dispatching select
437 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
440 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
441 -- select will have to duplicate the triggering statements. Postpone
442 -- the analysis of the statements till expansion. Analyze only if the
443 -- expander is disabled in order to catch any semantic errors.
445 if Is_Disp_Select then
446 if not Expander_Active then
447 Analyze_Statements (Statements (Abortable_Part (N)));
448 Analyze (Triggering_Alternative (N));
451 -- Analyze the statements. We analyze statements in the abortable part,
452 -- because this is the section that is executed first, and that way our
453 -- remembering of saved values and checks is accurate.
456 Analyze_Statements (Statements (Abortable_Part (N)));
457 Analyze (Triggering_Alternative (N));
459 end Analyze_Asynchronous_Select;
461 ------------------------------------
462 -- Analyze_Conditional_Entry_Call --
463 ------------------------------------
465 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
466 Trigger : constant Node_Id :=
467 Entry_Call_Statement (Entry_Call_Alternative (N));
468 Is_Disp_Select : Boolean := False;
471 -- Select statement is not allowed in SPARK or ALFA
473 if Formal_Verification_Mode then
474 Error_Msg_F ("|~~select statement is not allowed", N);
477 -- Proceed with analysis
479 Check_Restriction (No_Select_Statements, N);
480 Tasking_Used := True;
482 -- Ada 2005 (AI-345): The trigger may be a dispatching call
484 if Ada_Version >= Ada_2005 then
486 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
489 if List_Length (Else_Statements (N)) = 1
490 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
493 ("suspicious form of conditional entry call?!", N);
495 ("\`SELECT OR` may be intended rather than `SELECT ELSE`!", N);
498 -- Postpone the analysis of the statements till expansion. Analyze only
499 -- if the expander is disabled in order to catch any semantic errors.
501 if Is_Disp_Select then
502 if not Expander_Active then
503 Analyze (Entry_Call_Alternative (N));
504 Analyze_Statements (Else_Statements (N));
507 -- Regular select analysis
510 Analyze (Entry_Call_Alternative (N));
511 Analyze_Statements (Else_Statements (N));
513 end Analyze_Conditional_Entry_Call;
515 --------------------------------
516 -- Analyze_Delay_Alternative --
517 --------------------------------
519 procedure Analyze_Delay_Alternative (N : Node_Id) is
524 Tasking_Used := True;
525 Check_Restriction (No_Delay, N);
527 if Present (Pragmas_Before (N)) then
528 Analyze_List (Pragmas_Before (N));
531 if Nkind_In (Parent (N), N_Selective_Accept, N_Timed_Entry_Call) then
532 Expr := Expression (Delay_Statement (N));
534 -- Defer full analysis until the statement is expanded, to insure
535 -- that generated code does not move past the guard. The delay
536 -- expression is only evaluated if the guard is open.
538 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
539 Preanalyze_And_Resolve (Expr, Standard_Duration);
541 Preanalyze_And_Resolve (Expr);
544 Typ := First_Subtype (Etype (Expr));
546 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
547 and then not Is_RTE (Typ, RO_CA_Time)
548 and then not Is_RTE (Typ, RO_RT_Time)
550 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
553 Check_Restriction (No_Fixed_Point, Expr);
556 Analyze (Delay_Statement (N));
559 if Present (Condition (N)) then
560 Analyze_And_Resolve (Condition (N), Any_Boolean);
563 if Is_Non_Empty_List (Statements (N)) then
564 Analyze_Statements (Statements (N));
566 end Analyze_Delay_Alternative;
568 ----------------------------
569 -- Analyze_Delay_Relative --
570 ----------------------------
572 procedure Analyze_Delay_Relative (N : Node_Id) is
573 E : constant Node_Id := Expression (N);
575 -- Delay statement is not allowed in SPARK or ALFA
577 if Formal_Verification_Mode then
578 Error_Msg_F ("|~~delay statement is not allowed", N);
581 -- Proceed with analysis
583 Check_Restriction (No_Relative_Delay, N);
584 Tasking_Used := True;
585 Check_Restriction (No_Delay, N);
586 Check_Potentially_Blocking_Operation (N);
587 Analyze_And_Resolve (E, Standard_Duration);
588 Check_Restriction (No_Fixed_Point, E);
589 end Analyze_Delay_Relative;
591 -------------------------
592 -- Analyze_Delay_Until --
593 -------------------------
595 procedure Analyze_Delay_Until (N : Node_Id) is
596 E : constant Node_Id := Expression (N);
600 -- Delay statement is not allowed in SPARK or ALFA
602 if Formal_Verification_Mode then
603 Error_Msg_F ("|~~delay statement is not allowed", N);
606 -- Proceed with analysis
608 Tasking_Used := True;
609 Check_Restriction (No_Delay, N);
610 Check_Potentially_Blocking_Operation (N);
612 Typ := First_Subtype (Etype (E));
614 if not Is_RTE (Typ, RO_CA_Time) and then
615 not Is_RTE (Typ, RO_RT_Time)
617 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
619 end Analyze_Delay_Until;
621 ------------------------
622 -- Analyze_Entry_Body --
623 ------------------------
625 procedure Analyze_Entry_Body (N : Node_Id) is
626 Id : constant Entity_Id := Defining_Identifier (N);
627 Decls : constant List_Id := Declarations (N);
628 Stats : constant Node_Id := Handled_Statement_Sequence (N);
629 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
630 P_Type : constant Entity_Id := Current_Scope;
632 Entry_Name : Entity_Id;
635 Tasking_Used := True;
637 -- Entry_Name is initialized to Any_Id. It should get reset to the
638 -- matching entry entity. An error is signalled if it is not reset
640 Entry_Name := Any_Id;
644 if Present (Entry_Index_Specification (Formals)) then
645 Set_Ekind (Id, E_Entry_Family);
647 Set_Ekind (Id, E_Entry);
650 Set_Scope (Id, Current_Scope);
651 Set_Etype (Id, Standard_Void_Type);
652 Set_Accept_Address (Id, New_Elmt_List);
654 E := First_Entity (P_Type);
655 while Present (E) loop
656 if Chars (E) = Chars (Id)
657 and then (Ekind (E) = Ekind (Id))
658 and then Type_Conformant (Id, E)
661 Set_Convention (Id, Convention (E));
662 Set_Corresponding_Body (Parent (Entry_Name), Id);
663 Check_Fully_Conformant (Id, E, N);
665 if Ekind (Id) = E_Entry_Family then
666 if not Fully_Conformant_Discrete_Subtypes (
667 Discrete_Subtype_Definition (Parent (E)),
668 Discrete_Subtype_Definition
669 (Entry_Index_Specification (Formals)))
672 ("index not fully conformant with previous declaration",
673 Discrete_Subtype_Definition
674 (Entry_Index_Specification (Formals)));
677 -- The elaboration of the entry body does not recompute the
678 -- bounds of the index, which may have side effects. Inherit
679 -- the bounds from the entry declaration. This is critical
680 -- if the entry has a per-object constraint. If a bound is
681 -- given by a discriminant, it must be reanalyzed in order
682 -- to capture the discriminal of the current entry, rather
683 -- than that of the protected type.
686 Index_Spec : constant Node_Id :=
687 Entry_Index_Specification (Formals);
689 Def : constant Node_Id :=
691 (Discrete_Subtype_Definition (Parent (E)));
696 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
698 Set_Etype (Def, Empty);
699 Set_Analyzed (Def, False);
701 -- Keep the original subtree to ensure a properly
702 -- formed tree (e.g. for ASIS use).
705 (Discrete_Subtype_Definition (Index_Spec), Def);
707 Set_Analyzed (Low_Bound (Def), False);
708 Set_Analyzed (High_Bound (Def), False);
710 if Denotes_Discriminant (Low_Bound (Def)) then
711 Set_Entity (Low_Bound (Def), Empty);
714 if Denotes_Discriminant (High_Bound (Def)) then
715 Set_Entity (High_Bound (Def), Empty);
719 Make_Index (Def, Index_Spec);
721 (Defining_Identifier (Index_Spec), Etype (Def));
733 if Entry_Name = Any_Id then
734 Error_Msg_N ("no entry declaration matches entry body", N);
737 elsif Has_Completion (Entry_Name) then
738 Error_Msg_N ("duplicate entry body", N);
742 Set_Has_Completion (Entry_Name);
743 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
744 Style.Check_Identifier (Id, Entry_Name);
747 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
748 Push_Scope (Entry_Name);
750 Install_Declarations (Entry_Name);
751 Set_Actual_Subtypes (N, Current_Scope);
753 -- The entity for the protected subprogram corresponding to the entry
754 -- has been created. We retain the name of this entity in the entry
755 -- body, for use when the corresponding subprogram body is created.
756 -- Note that entry bodies have no corresponding_spec, and there is no
757 -- easy link back in the tree between the entry body and the entity for
758 -- the entry itself, which is why we must propagate some attributes
759 -- explicitly from spec to body.
761 Set_Protected_Body_Subprogram
762 (Id, Protected_Body_Subprogram (Entry_Name));
764 Set_Entry_Parameters_Type
765 (Id, Entry_Parameters_Type (Entry_Name));
767 -- Add a declaration for the Protection object, renaming declarations
768 -- for the discriminals and privals and finally a declaration for the
769 -- entry family index (if applicable).
772 and then Is_Protected_Type (P_Type)
774 Install_Private_Data_Declarations
775 (Sloc (N), Entry_Name, P_Type, N, Decls);
778 if Present (Decls) then
779 Analyze_Declarations (Decls);
780 Inspect_Deferred_Constant_Completion (Decls);
783 if Present (Stats) then
787 -- Check for unreferenced variables etc. Before the Check_References
788 -- call, we transfer Never_Set_In_Source and Referenced flags from
789 -- parameters in the spec to the corresponding entities in the body,
790 -- since we want the warnings on the body entities. Note that we do
791 -- not have to transfer Referenced_As_LHS, since that flag can only
792 -- be set for simple variables.
794 -- At the same time, we set the flags on the spec entities to suppress
795 -- any warnings on the spec formals, since we also scan the spec.
796 -- Finally, we propagate the Entry_Component attribute to the body
797 -- formals, for use in the renaming declarations created later for the
798 -- formals (see exp_ch9.Add_Formal_Renamings).
805 E1 := First_Entity (Entry_Name);
806 while Present (E1) loop
807 E2 := First_Entity (Id);
808 while Present (E2) loop
809 exit when Chars (E1) = Chars (E2);
813 -- If no matching body entity, then we already had a detected
814 -- error of some kind, so just don't worry about these warnings.
820 if Ekind (E1) = E_Out_Parameter then
821 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
822 Set_Never_Set_In_Source (E1, False);
825 Set_Referenced (E2, Referenced (E1));
827 Set_Entry_Component (E2, Entry_Component (E1));
833 Check_References (Id);
836 -- We still need to check references for the spec, since objects
837 -- declared in the body are chained (in the First_Entity sense) to
838 -- the spec rather than the body in the case of entries.
840 Check_References (Entry_Name);
842 -- Process the end label, and terminate the scope
844 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
847 -- If this is an entry family, remove the loop created to provide
848 -- a scope for the entry index.
850 if Ekind (Id) = E_Entry_Family
851 and then Present (Entry_Index_Specification (Formals))
855 end Analyze_Entry_Body;
857 ------------------------------------
858 -- Analyze_Entry_Body_Formal_Part --
859 ------------------------------------
861 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
862 Id : constant Entity_Id := Defining_Identifier (Parent (N));
863 Index : constant Node_Id := Entry_Index_Specification (N);
864 Formals : constant List_Id := Parameter_Specifications (N);
867 Tasking_Used := True;
869 if Present (Index) then
872 -- The entry index functions like a loop variable, thus it is known
873 -- to have a valid value.
875 Set_Is_Known_Valid (Defining_Identifier (Index));
878 if Present (Formals) then
879 Set_Scope (Id, Current_Scope);
881 Process_Formals (Formals, Parent (N));
884 end Analyze_Entry_Body_Formal_Part;
886 ------------------------------------
887 -- Analyze_Entry_Call_Alternative --
888 ------------------------------------
890 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
891 Call : constant Node_Id := Entry_Call_Statement (N);
894 -- Entry call is not allowed in SPARK or ALFA
896 if Formal_Verification_Mode then
897 Error_Msg_F ("|~~entry call is not allowed", N);
900 -- Proceed with analysis
902 Tasking_Used := True;
904 if Present (Pragmas_Before (N)) then
905 Analyze_List (Pragmas_Before (N));
908 if Nkind (Call) = N_Attribute_Reference then
910 -- Possibly a stream attribute, but definitely illegal. Other
911 -- illegalities, such as procedure calls, are diagnosed after
914 Error_Msg_N ("entry call alternative requires an entry call", Call);
920 if Is_Non_Empty_List (Statements (N)) then
921 Analyze_Statements (Statements (N));
923 end Analyze_Entry_Call_Alternative;
925 -------------------------------
926 -- Analyze_Entry_Declaration --
927 -------------------------------
929 procedure Analyze_Entry_Declaration (N : Node_Id) is
930 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
931 Def_Id : constant Entity_Id := Defining_Identifier (N);
932 Formals : constant List_Id := Parameter_Specifications (N);
935 Generate_Definition (Def_Id);
936 Tasking_Used := True;
938 -- Case of no discrete subtype definition
941 Set_Ekind (Def_Id, E_Entry);
943 -- Processing for discrete subtype definition present
947 Set_Ekind (Def_Id, E_Entry_Family);
949 Make_Index (D_Sdef, N, Def_Id);
951 -- Check subtype with predicate in entry family
953 Bad_Predicated_Subtype_Use
954 ("subtype& has predicate, not allowed in entry family",
955 D_Sdef, Etype (D_Sdef));
960 Set_Etype (Def_Id, Standard_Void_Type);
961 Set_Convention (Def_Id, Convention_Entry);
962 Set_Accept_Address (Def_Id, New_Elmt_List);
966 if Present (Formals) then
967 Set_Scope (Def_Id, Current_Scope);
969 Process_Formals (Formals, N);
970 Create_Extra_Formals (Def_Id);
974 if Ekind (Def_Id) = E_Entry then
975 New_Overloaded_Entity (Def_Id);
978 Generate_Reference_To_Formals (Def_Id);
979 Analyze_Aspect_Specifications (N, Def_Id, Aspect_Specifications (N));
980 end Analyze_Entry_Declaration;
982 ---------------------------------------
983 -- Analyze_Entry_Index_Specification --
984 ---------------------------------------
986 -- The Defining_Identifier of the entry index specification is local to the
987 -- entry body, but it must be available in the entry barrier which is
988 -- evaluated outside of the entry body. The index is eventually renamed as
989 -- a run-time object, so is visibility is strictly a front-end concern. In
990 -- order to make it available to the barrier, we create an additional
991 -- scope, as for a loop, whose only declaration is the index name. This
992 -- loop is not attached to the tree and does not appear as an entity local
993 -- to the protected type, so its existence need only be known to routines
994 -- that process entry families.
996 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
997 Iden : constant Node_Id := Defining_Identifier (N);
998 Def : constant Node_Id := Discrete_Subtype_Definition (N);
999 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L');
1002 Tasking_Used := True;
1005 -- There is no elaboration of the entry index specification. Therefore,
1006 -- if the index is a range, it is not resolved and expanded, but the
1007 -- bounds are inherited from the entry declaration, and reanalyzed.
1008 -- See Analyze_Entry_Body.
1010 if Nkind (Def) /= N_Range then
1011 Make_Index (Def, N);
1014 Set_Ekind (Loop_Id, E_Loop);
1015 Set_Scope (Loop_Id, Current_Scope);
1016 Push_Scope (Loop_Id);
1018 Set_Ekind (Iden, E_Entry_Index_Parameter);
1019 Set_Etype (Iden, Etype (Def));
1020 end Analyze_Entry_Index_Specification;
1022 ----------------------------
1023 -- Analyze_Protected_Body --
1024 ----------------------------
1026 procedure Analyze_Protected_Body (N : Node_Id) is
1027 Body_Id : constant Entity_Id := Defining_Identifier (N);
1030 Spec_Id : Entity_Id;
1031 -- This is initially the entity of the protected object or protected
1032 -- type involved, but is replaced by the protected type always in the
1033 -- case of a single protected declaration, since this is the proper
1034 -- scope to be used.
1037 -- This is the entity of the protected object or protected type
1038 -- involved, and is the entity used for cross-reference purposes (it
1039 -- differs from Spec_Id in the case of a single protected object, since
1040 -- Spec_Id is set to the protected type in this case).
1043 Tasking_Used := True;
1044 Set_Ekind (Body_Id, E_Protected_Body);
1045 Spec_Id := Find_Concurrent_Spec (Body_Id);
1047 if Present (Spec_Id)
1048 and then Ekind (Spec_Id) = E_Protected_Type
1052 elsif Present (Spec_Id)
1053 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1054 and then not Comes_From_Source (Etype (Spec_Id))
1059 Error_Msg_N ("missing specification for protected body", Body_Id);
1064 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1065 Style.Check_Identifier (Body_Id, Spec_Id);
1067 -- The declarations are always attached to the type
1069 if Ekind (Spec_Id) /= E_Protected_Type then
1070 Spec_Id := Etype (Spec_Id);
1073 Push_Scope (Spec_Id);
1074 Set_Corresponding_Spec (N, Spec_Id);
1075 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1076 Set_Has_Completion (Spec_Id);
1077 Install_Declarations (Spec_Id);
1079 Expand_Protected_Body_Declarations (N, Spec_Id);
1081 Last_E := Last_Entity (Spec_Id);
1083 Analyze_Declarations (Declarations (N));
1085 -- For visibility purposes, all entities in the body are private. Set
1086 -- First_Private_Entity accordingly, if there was no private part in the
1087 -- protected declaration.
1089 if No (First_Private_Entity (Spec_Id)) then
1090 if Present (Last_E) then
1091 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1093 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1097 Check_Completion (Body_Id);
1098 Check_References (Spec_Id);
1099 Process_End_Label (N, 't', Ref_Id);
1101 end Analyze_Protected_Body;
1103 ----------------------------------
1104 -- Analyze_Protected_Definition --
1105 ----------------------------------
1107 procedure Analyze_Protected_Definition (N : Node_Id) is
1111 procedure Undelay_Itypes (T : Entity_Id);
1112 -- Itypes created for the private components of a protected type
1113 -- do not receive freeze nodes, because there is no scope in which
1114 -- they can be elaborated, and they can depend on discriminants of
1115 -- the enclosed protected type. Given that the components can be
1116 -- composite types with inner components, we traverse recursively
1117 -- the private components of the protected type, and indicate that
1118 -- all itypes within are frozen. This ensures that no freeze nodes
1119 -- will be generated for them.
1121 -- On the other hand, components of the corresponding record are
1122 -- frozen (or receive itype references) as for other records.
1124 --------------------
1125 -- Undelay_Itypes --
1126 --------------------
1128 procedure Undelay_Itypes (T : Entity_Id) is
1132 if Is_Protected_Type (T) then
1133 Comp := First_Private_Entity (T);
1134 elsif Is_Record_Type (T) then
1135 Comp := First_Entity (T);
1140 while Present (Comp) loop
1142 and then Is_Itype (Comp)
1144 Set_Has_Delayed_Freeze (Comp, False);
1145 Set_Is_Frozen (Comp);
1147 if Is_Record_Type (Comp)
1148 or else Is_Protected_Type (Comp)
1150 Undelay_Itypes (Comp);
1158 -- Start of processing for Analyze_Protected_Definition
1161 Tasking_Used := True;
1162 Analyze_Declarations (Visible_Declarations (N));
1164 if Present (Private_Declarations (N))
1165 and then not Is_Empty_List (Private_Declarations (N))
1167 L := Last_Entity (Current_Scope);
1168 Analyze_Declarations (Private_Declarations (N));
1171 Set_First_Private_Entity (Current_Scope, Next_Entity (L));
1173 Set_First_Private_Entity (Current_Scope,
1174 First_Entity (Current_Scope));
1178 E := First_Entity (Current_Scope);
1179 while Present (E) loop
1180 if Ekind_In (E, E_Function, E_Procedure) then
1181 Set_Convention (E, Convention_Protected);
1183 elsif Is_Task_Type (Etype (E))
1184 or else Has_Task (Etype (E))
1186 Set_Has_Task (Current_Scope);
1192 Undelay_Itypes (Current_Scope);
1194 Check_Max_Entries (N, Max_Protected_Entries);
1195 Process_End_Label (N, 'e', Current_Scope);
1196 end Analyze_Protected_Definition;
1198 ----------------------------------------
1199 -- Analyze_Protected_Type_Declaration --
1200 ----------------------------------------
1202 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
1203 Def_Id : constant Entity_Id := Defining_Identifier (N);
1208 if No_Run_Time_Mode then
1209 Error_Msg_CRT ("protected type", N);
1213 Tasking_Used := True;
1214 Check_Restriction (No_Protected_Types, N);
1216 T := Find_Type_Name (N);
1218 -- In the case of an incomplete type, use the full view, unless it's not
1219 -- present (as can occur for an incomplete view from a limited with).
1221 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
1223 Set_Completion_Referenced (T);
1226 Set_Ekind (T, E_Protected_Type);
1227 Set_Is_First_Subtype (T, True);
1228 Init_Size_Align (T);
1230 Set_Has_Delayed_Freeze (T, True);
1231 Set_Stored_Constraint (T, No_Elist);
1234 if Ada_Version >= Ada_2005 then
1235 Check_Interfaces (N, T);
1238 if Present (Discriminant_Specifications (N)) then
1239 if Has_Discriminants (T) then
1241 -- Install discriminants. Also, verify conformance of
1242 -- discriminants of previous and current view. ???
1244 Install_Declarations (T);
1246 Process_Discriminants (N);
1250 Set_Is_Constrained (T, not Has_Discriminants (T));
1252 Analyze (Protected_Definition (N));
1254 -- In the case where the protected type is declared at a nested level
1255 -- and the No_Local_Protected_Objects restriction applies, issue a
1256 -- warning that objects of the type will violate the restriction.
1258 if Restriction_Check_Required (No_Local_Protected_Objects)
1259 and then not Is_Library_Level_Entity (T)
1260 and then Comes_From_Source (T)
1262 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
1264 if Error_Msg_Sloc = No_Location then
1266 ("objects of this type will violate " &
1267 "`No_Local_Protected_Objects`?", N);
1270 ("objects of this type will violate " &
1271 "`No_Local_Protected_Objects`?#", N);
1275 -- Protected types with entries are controlled (because of the
1276 -- Protection component if nothing else), same for any protected type
1277 -- with interrupt handlers. Note that we need to analyze the protected
1278 -- definition to set Has_Entries and such.
1280 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
1281 or else Number_Entries (T) > 1)
1284 or else Has_Interrupt_Handler (T)
1285 or else Has_Attach_Handler (T))
1287 Set_Has_Controlled_Component (T, True);
1290 -- The Ekind of components is E_Void during analysis to detect illegal
1291 -- uses. Now it can be set correctly.
1293 E := First_Entity (Current_Scope);
1294 while Present (E) loop
1295 if Ekind (E) = E_Void then
1296 Set_Ekind (E, E_Component);
1297 Init_Component_Location (E);
1305 -- Case of a completion of a private declaration
1308 and then Is_Private_Type (Def_Id)
1310 -- Deal with preelaborable initialization. Note that this processing
1311 -- is done by Process_Full_View, but as can be seen below, in this
1312 -- case the call to Process_Full_View is skipped if any serious
1313 -- errors have occurred, and we don't want to lose this check.
1315 if Known_To_Have_Preelab_Init (Def_Id) then
1316 Set_Must_Have_Preelab_Init (T);
1319 -- Create corresponding record now, because some private dependents
1320 -- may be subtypes of the partial view. Skip if errors are present,
1321 -- to prevent cascaded messages.
1323 if Serious_Errors_Detected = 0
1324 and then Expander_Active
1326 Expand_N_Protected_Type_Declaration (N);
1327 Process_Full_View (N, T, Def_Id);
1332 Analyze_Aspect_Specifications (N, Def_Id, Aspect_Specifications (N));
1333 end Analyze_Protected_Type_Declaration;
1335 ---------------------
1336 -- Analyze_Requeue --
1337 ---------------------
1339 procedure Analyze_Requeue (N : Node_Id) is
1340 Count : Natural := 0;
1341 Entry_Name : Node_Id := Name (N);
1342 Entry_Id : Entity_Id;
1344 Is_Disp_Req : Boolean;
1346 Enclosing : Entity_Id;
1347 Target_Obj : Node_Id := Empty;
1348 Req_Scope : Entity_Id;
1349 Outer_Ent : Entity_Id;
1352 -- Requeue statement is not allowed in SPARK or ALFA
1354 if Formal_Verification_Mode then
1355 Error_Msg_F ("|~~requeue statement is not allowed", N);
1358 -- Proceed with analysis
1360 Check_Restriction (No_Requeue_Statements, N);
1361 Check_Unreachable_Code (N);
1362 Tasking_Used := True;
1365 for J in reverse 0 .. Scope_Stack.Last loop
1366 Enclosing := Scope_Stack.Table (J).Entity;
1367 exit when Is_Entry (Enclosing);
1369 if not Ekind_In (Enclosing, E_Block, E_Loop) then
1370 Error_Msg_N ("requeue must appear within accept or entry body", N);
1375 Analyze (Entry_Name);
1377 if Etype (Entry_Name) = Any_Type then
1381 if Nkind (Entry_Name) = N_Selected_Component then
1382 Target_Obj := Prefix (Entry_Name);
1383 Entry_Name := Selector_Name (Entry_Name);
1386 -- If an explicit target object is given then we have to check the
1387 -- restrictions of 9.5.4(6).
1389 if Present (Target_Obj) then
1391 -- Locate containing concurrent unit and determine enclosing entry
1392 -- body or outermost enclosing accept statement within the unit.
1395 for S in reverse 0 .. Scope_Stack.Last loop
1396 Req_Scope := Scope_Stack.Table (S).Entity;
1398 exit when Ekind (Req_Scope) in Task_Kind
1399 or else Ekind (Req_Scope) in Protected_Kind;
1401 if Is_Entry (Req_Scope) then
1402 Outer_Ent := Req_Scope;
1406 pragma Assert (Present (Outer_Ent));
1408 -- Check that the accessibility level of the target object is not
1409 -- greater or equal to the outermost enclosing accept statement (or
1410 -- entry body) unless it is a parameter of the innermost enclosing
1411 -- accept statement (or entry body).
1413 if Object_Access_Level (Target_Obj) >= Scope_Depth (Outer_Ent)
1415 (not Is_Entity_Name (Target_Obj)
1416 or else Ekind (Entity (Target_Obj)) not in Formal_Kind
1417 or else Enclosing /= Scope (Entity (Target_Obj)))
1420 ("target object has invalid level for requeue", Target_Obj);
1424 -- Overloaded case, find right interpretation
1426 if Is_Overloaded (Entry_Name) then
1429 -- Loop over candidate interpretations and filter out any that are
1430 -- not parameterless, are not type conformant, are not entries, or
1431 -- do not come from source.
1433 Get_First_Interp (Entry_Name, I, It);
1434 while Present (It.Nam) loop
1436 -- Note: we test type conformance here, not subtype conformance.
1437 -- Subtype conformance will be tested later on, but it is better
1438 -- for error output in some cases not to do that here.
1440 if (No (First_Formal (It.Nam))
1441 or else (Type_Conformant (Enclosing, It.Nam)))
1442 and then Ekind (It.Nam) = E_Entry
1444 -- Ada 2005 (AI-345): Since protected and task types have
1445 -- primitive entry wrappers, we only consider source entries.
1447 if Comes_From_Source (It.Nam) then
1455 Get_Next_Interp (I, It);
1459 Error_Msg_N ("no entry matches context", N);
1462 elsif Count > 1 then
1463 Error_Msg_N ("ambiguous entry name in requeue", N);
1467 Set_Is_Overloaded (Entry_Name, False);
1468 Set_Entity (Entry_Name, Entry_Id);
1471 -- Non-overloaded cases
1473 -- For the case of a reference to an element of an entry family, the
1474 -- Entry_Name is an indexed component.
1476 elsif Nkind (Entry_Name) = N_Indexed_Component then
1478 -- Requeue to an entry out of the body
1480 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
1481 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
1483 -- Requeue from within the body itself
1485 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
1486 Entry_Id := Entity (Prefix (Entry_Name));
1489 Error_Msg_N ("invalid entry_name specified", N);
1493 -- If we had a requeue of the form REQUEUE A (B), then the parser
1494 -- accepted it (because it could have been a requeue on an entry index.
1495 -- If A turns out not to be an entry family, then the analysis of A (B)
1496 -- turned it into a function call.
1498 elsif Nkind (Entry_Name) = N_Function_Call then
1500 ("arguments not allowed in requeue statement",
1501 First (Parameter_Associations (Entry_Name)));
1504 -- Normal case of no entry family, no argument
1507 Entry_Id := Entity (Entry_Name);
1510 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
1511 -- target type must be a concurrent interface class-wide type and the
1512 -- target must be a procedure, flagged by pragma Implemented.
1515 Ada_Version >= Ada_2012
1516 and then Present (Target_Obj)
1517 and then Is_Class_Wide_Type (Etype (Target_Obj))
1518 and then Is_Concurrent_Interface (Etype (Target_Obj))
1519 and then Ekind (Entry_Id) = E_Procedure
1520 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
1522 -- Resolve entry, and check that it is subtype conformant with the
1523 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1524 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
1526 if not Is_Entry (Entry_Id)
1527 and then not Is_Disp_Req
1529 Error_Msg_N ("expect entry name in requeue statement", Name (N));
1531 elsif Ekind (Entry_Id) = E_Entry_Family
1532 and then Nkind (Entry_Name) /= N_Indexed_Component
1534 Error_Msg_N ("missing index for entry family component", Name (N));
1537 Resolve_Entry (Name (N));
1538 Generate_Reference (Entry_Id, Entry_Name);
1540 if Present (First_Formal (Entry_Id)) then
1541 if VM_Target = JVM_Target then
1543 ("arguments unsupported in requeue statement",
1544 First_Formal (Entry_Id));
1548 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
1549 -- the first parameter of Entry_Id since it is the interface
1550 -- controlling formal.
1552 if Ada_Version >= Ada_2012
1553 and then Is_Disp_Req
1556 Enclosing_Formal : Entity_Id;
1557 Target_Formal : Entity_Id;
1560 Enclosing_Formal := First_Formal (Enclosing);
1561 Target_Formal := Next_Formal (First_Formal (Entry_Id));
1562 while Present (Enclosing_Formal)
1563 and then Present (Target_Formal)
1565 if not Conforming_Types
1566 (T1 => Etype (Enclosing_Formal),
1567 T2 => Etype (Target_Formal),
1568 Ctype => Subtype_Conformant)
1570 Error_Msg_Node_2 := Target_Formal;
1572 ("formal & is not subtype conformant with &" &
1573 "in dispatching requeue", N, Enclosing_Formal);
1576 Next_Formal (Enclosing_Formal);
1577 Next_Formal (Target_Formal);
1581 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
1584 -- Processing for parameters accessed by the requeue
1590 Ent := First_Formal (Enclosing);
1591 while Present (Ent) loop
1593 -- For OUT or IN OUT parameter, the effect of the requeue is
1594 -- to assign the parameter a value on exit from the requeued
1595 -- body, so we can set it as source assigned. We also clear
1596 -- the Is_True_Constant indication. We do not need to clear
1597 -- Current_Value, since the effect of the requeue is to
1598 -- perform an unconditional goto so that any further
1599 -- references will not occur anyway.
1601 if Ekind_In (Ent, E_Out_Parameter, E_In_Out_Parameter) then
1602 Set_Never_Set_In_Source (Ent, False);
1603 Set_Is_True_Constant (Ent, False);
1606 -- For all parameters, the requeue acts as a reference,
1607 -- since the value of the parameter is passed to the new
1608 -- entry, so we want to suppress unreferenced warnings.
1610 Set_Referenced (Ent);
1616 end Analyze_Requeue;
1618 ------------------------------
1619 -- Analyze_Selective_Accept --
1620 ------------------------------
1622 procedure Analyze_Selective_Accept (N : Node_Id) is
1623 Alts : constant List_Id := Select_Alternatives (N);
1626 Accept_Present : Boolean := False;
1627 Terminate_Present : Boolean := False;
1628 Delay_Present : Boolean := False;
1629 Relative_Present : Boolean := False;
1630 Alt_Count : Uint := Uint_0;
1633 -- Select statement is not allowed in SPARK or ALFA
1635 if Formal_Verification_Mode then
1636 Error_Msg_F ("|~~select statement is not allowed", N);
1639 -- Proceed with analysis
1641 Check_Restriction (No_Select_Statements, N);
1642 Tasking_Used := True;
1644 -- Loop to analyze alternatives
1646 Alt := First (Alts);
1647 while Present (Alt) loop
1648 Alt_Count := Alt_Count + 1;
1651 if Nkind (Alt) = N_Delay_Alternative then
1652 if Delay_Present then
1654 if Relative_Present /=
1655 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
1658 ("delay_until and delay_relative alternatives ", Alt);
1660 ("\cannot appear in the same selective_wait", Alt);
1664 Delay_Present := True;
1666 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
1669 elsif Nkind (Alt) = N_Terminate_Alternative then
1670 if Terminate_Present then
1671 Error_Msg_N ("only one terminate alternative allowed", N);
1673 Terminate_Present := True;
1674 Check_Restriction (No_Terminate_Alternatives, N);
1677 elsif Nkind (Alt) = N_Accept_Alternative then
1678 Accept_Present := True;
1680 -- Check for duplicate accept
1684 Stm : constant Node_Id := Accept_Statement (Alt);
1685 EDN : constant Node_Id := Entry_Direct_Name (Stm);
1689 if Nkind (EDN) = N_Identifier
1690 and then No (Condition (Alt))
1691 and then Present (Entity (EDN)) -- defend against junk
1692 and then Ekind (Entity (EDN)) = E_Entry
1694 Ent := Entity (EDN);
1696 Alt1 := First (Alts);
1697 while Alt1 /= Alt loop
1698 if Nkind (Alt1) = N_Accept_Alternative
1699 and then No (Condition (Alt1))
1702 Stm1 : constant Node_Id := Accept_Statement (Alt1);
1703 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
1706 if Nkind (EDN1) = N_Identifier then
1707 if Entity (EDN1) = Ent then
1708 Error_Msg_Sloc := Sloc (Stm1);
1710 ("?accept duplicates one on line#", Stm);
1726 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
1727 Check_Potentially_Blocking_Operation (N);
1729 if Terminate_Present and Delay_Present then
1730 Error_Msg_N ("at most one of terminate or delay alternative", N);
1732 elsif not Accept_Present then
1734 ("select must contain at least one accept alternative", N);
1737 if Present (Else_Statements (N)) then
1738 if Terminate_Present or Delay_Present then
1739 Error_Msg_N ("else part not allowed with other alternatives", N);
1742 Analyze_Statements (Else_Statements (N));
1744 end Analyze_Selective_Accept;
1746 ------------------------------------------
1747 -- Analyze_Single_Protected_Declaration --
1748 ------------------------------------------
1750 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
1751 Loc : constant Source_Ptr := Sloc (N);
1752 Id : constant Node_Id := Defining_Identifier (N);
1756 O_Name : constant Entity_Id := Id;
1759 Generate_Definition (Id);
1760 Tasking_Used := True;
1762 -- The node is rewritten as a protected type declaration, in exact
1763 -- analogy with what is done with single tasks.
1766 Make_Defining_Identifier (Sloc (Id),
1767 New_External_Name (Chars (Id), 'T'));
1770 Make_Protected_Type_Declaration (Loc,
1771 Defining_Identifier => T,
1772 Protected_Definition => Relocate_Node (Protected_Definition (N)),
1773 Interface_List => Interface_List (N));
1776 Make_Object_Declaration (Loc,
1777 Defining_Identifier => O_Name,
1778 Object_Definition => Make_Identifier (Loc, Chars (T)));
1780 Move_Aspects (N, O_Decl);
1781 Rewrite (N, T_Decl);
1782 Insert_After (N, O_Decl);
1783 Mark_Rewrite_Insertion (O_Decl);
1785 -- Enter names of type and object before analysis, because the name of
1786 -- the object may be used in its own body.
1789 Set_Ekind (T, E_Protected_Type);
1792 Enter_Name (O_Name);
1793 Set_Ekind (O_Name, E_Variable);
1794 Set_Etype (O_Name, T);
1796 -- Instead of calling Analyze on the new node, call the proper analysis
1797 -- procedure directly. Otherwise the node would be expanded twice, with
1798 -- disastrous result.
1800 Analyze_Protected_Type_Declaration (N);
1801 Analyze_Aspect_Specifications (N, Id, Aspect_Specifications (N));
1802 end Analyze_Single_Protected_Declaration;
1804 -------------------------------------
1805 -- Analyze_Single_Task_Declaration --
1806 -------------------------------------
1808 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
1809 Loc : constant Source_Ptr := Sloc (N);
1810 Id : constant Node_Id := Defining_Identifier (N);
1814 O_Name : constant Entity_Id := Id;
1817 Generate_Definition (Id);
1818 Tasking_Used := True;
1820 -- The node is rewritten as a task type declaration, followed by an
1821 -- object declaration of that anonymous task type.
1824 Make_Defining_Identifier (Sloc (Id),
1825 New_External_Name (Chars (Id), Suffix => "TK"));
1828 Make_Task_Type_Declaration (Loc,
1829 Defining_Identifier => T,
1830 Task_Definition => Relocate_Node (Task_Definition (N)),
1831 Interface_List => Interface_List (N));
1833 -- We use the original defining identifier of the single task in the
1834 -- generated object declaration, so that debugging information can
1835 -- be attached to it when compiling with -gnatD. The parent of the
1836 -- entity is the new object declaration. The single_task_declaration
1837 -- is not used further in semantics or code generation, but is scanned
1838 -- when generating debug information, and therefore needs the updated
1839 -- Sloc information for the entity (see Sprint). Aspect specifications
1840 -- are moved from the single task node to the object declaration node.
1843 Make_Object_Declaration (Loc,
1844 Defining_Identifier => O_Name,
1845 Object_Definition => Make_Identifier (Loc, Chars (T)));
1847 Move_Aspects (N, O_Decl);
1848 Rewrite (N, T_Decl);
1849 Insert_After (N, O_Decl);
1850 Mark_Rewrite_Insertion (O_Decl);
1852 -- Enter names of type and object before analysis, because the name of
1853 -- the object may be used in its own body.
1856 Set_Ekind (T, E_Task_Type);
1859 Enter_Name (O_Name);
1860 Set_Ekind (O_Name, E_Variable);
1861 Set_Etype (O_Name, T);
1863 -- Instead of calling Analyze on the new node, call the proper analysis
1864 -- procedure directly. Otherwise the node would be expanded twice, with
1865 -- disastrous result.
1867 Analyze_Task_Type_Declaration (N);
1868 Analyze_Aspect_Specifications (N, Id, Aspect_Specifications (N));
1869 end Analyze_Single_Task_Declaration;
1871 -----------------------
1872 -- Analyze_Task_Body --
1873 -----------------------
1875 procedure Analyze_Task_Body (N : Node_Id) is
1876 Body_Id : constant Entity_Id := Defining_Identifier (N);
1877 Decls : constant List_Id := Declarations (N);
1878 HSS : constant Node_Id := Handled_Statement_Sequence (N);
1881 Spec_Id : Entity_Id;
1882 -- This is initially the entity of the task or task type involved, but
1883 -- is replaced by the task type always in the case of a single task
1884 -- declaration, since this is the proper scope to be used.
1887 -- This is the entity of the task or task type, and is the entity used
1888 -- for cross-reference purposes (it differs from Spec_Id in the case of
1889 -- a single task, since Spec_Id is set to the task type)
1892 Tasking_Used := True;
1893 Set_Ekind (Body_Id, E_Task_Body);
1894 Set_Scope (Body_Id, Current_Scope);
1895 Spec_Id := Find_Concurrent_Spec (Body_Id);
1897 -- The spec is either a task type declaration, or a single task
1898 -- declaration for which we have created an anonymous type.
1900 if Present (Spec_Id)
1901 and then Ekind (Spec_Id) = E_Task_Type
1905 elsif Present (Spec_Id)
1906 and then Ekind (Etype (Spec_Id)) = E_Task_Type
1907 and then not Comes_From_Source (Etype (Spec_Id))
1912 Error_Msg_N ("missing specification for task body", Body_Id);
1916 if Has_Completion (Spec_Id)
1917 and then Present (Corresponding_Body (Parent (Spec_Id)))
1919 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
1920 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
1923 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
1928 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1929 Style.Check_Identifier (Body_Id, Spec_Id);
1931 -- Deal with case of body of single task (anonymous type was created)
1933 if Ekind (Spec_Id) = E_Variable then
1934 Spec_Id := Etype (Spec_Id);
1937 Push_Scope (Spec_Id);
1938 Set_Corresponding_Spec (N, Spec_Id);
1939 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1940 Set_Has_Completion (Spec_Id);
1941 Install_Declarations (Spec_Id);
1942 Last_E := Last_Entity (Spec_Id);
1944 Analyze_Declarations (Decls);
1945 Inspect_Deferred_Constant_Completion (Decls);
1947 -- For visibility purposes, all entities in the body are private. Set
1948 -- First_Private_Entity accordingly, if there was no private part in the
1949 -- protected declaration.
1951 if No (First_Private_Entity (Spec_Id)) then
1952 if Present (Last_E) then
1953 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1955 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1959 -- Mark all handlers as not suitable for local raise optimization,
1960 -- since this optimization causes difficulties in a task context.
1962 if Present (Exception_Handlers (HSS)) then
1966 Handlr := First (Exception_Handlers (HSS));
1967 while Present (Handlr) loop
1968 Set_Local_Raise_Not_OK (Handlr);
1974 -- Now go ahead and complete analysis of the task body
1977 Check_Completion (Body_Id);
1978 Check_References (Body_Id);
1979 Check_References (Spec_Id);
1981 -- Check for entries with no corresponding accept
1987 Ent := First_Entity (Spec_Id);
1988 while Present (Ent) loop
1990 and then not Entry_Accepted (Ent)
1991 and then Comes_From_Source (Ent)
1993 Error_Msg_NE ("no accept for entry &?", N, Ent);
2000 Process_End_Label (HSS, 't', Ref_Id);
2002 end Analyze_Task_Body;
2004 -----------------------------
2005 -- Analyze_Task_Definition --
2006 -----------------------------
2008 procedure Analyze_Task_Definition (N : Node_Id) is
2012 Tasking_Used := True;
2014 if Present (Visible_Declarations (N)) then
2015 Analyze_Declarations (Visible_Declarations (N));
2018 if Present (Private_Declarations (N)) then
2019 L := Last_Entity (Current_Scope);
2020 Analyze_Declarations (Private_Declarations (N));
2023 Set_First_Private_Entity
2024 (Current_Scope, Next_Entity (L));
2026 Set_First_Private_Entity
2027 (Current_Scope, First_Entity (Current_Scope));
2031 Check_Max_Entries (N, Max_Task_Entries);
2032 Process_End_Label (N, 'e', Current_Scope);
2033 end Analyze_Task_Definition;
2035 -----------------------------------
2036 -- Analyze_Task_Type_Declaration --
2037 -----------------------------------
2039 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
2040 Def_Id : constant Entity_Id := Defining_Identifier (N);
2044 Check_Restriction (No_Tasking, N);
2045 Tasking_Used := True;
2046 T := Find_Type_Name (N);
2047 Generate_Definition (T);
2049 -- In the case of an incomplete type, use the full view, unless it's not
2050 -- present (as can occur for an incomplete view from a limited with).
2052 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
2054 Set_Completion_Referenced (T);
2057 Set_Ekind (T, E_Task_Type);
2058 Set_Is_First_Subtype (T, True);
2059 Set_Has_Task (T, True);
2060 Init_Size_Align (T);
2062 Set_Has_Delayed_Freeze (T, True);
2063 Set_Stored_Constraint (T, No_Elist);
2066 if Ada_Version >= Ada_2005 then
2067 Check_Interfaces (N, T);
2070 if Present (Discriminant_Specifications (N)) then
2071 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2072 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
2075 if Has_Discriminants (T) then
2077 -- Install discriminants. Also, verify conformance of
2078 -- discriminants of previous and current view. ???
2080 Install_Declarations (T);
2082 Process_Discriminants (N);
2086 Set_Is_Constrained (T, not Has_Discriminants (T));
2088 if Present (Task_Definition (N)) then
2089 Analyze_Task_Definition (Task_Definition (N));
2092 -- In the case where the task type is declared at a nested level and the
2093 -- No_Task_Hierarchy restriction applies, issue a warning that objects
2094 -- of the type will violate the restriction.
2096 if Restriction_Check_Required (No_Task_Hierarchy)
2097 and then not Is_Library_Level_Entity (T)
2098 and then Comes_From_Source (T)
2100 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
2102 if Error_Msg_Sloc = No_Location then
2104 ("objects of this type will violate `No_Task_Hierarchy`?", N);
2107 ("objects of this type will violate `No_Task_Hierarchy`?#", N);
2113 -- Case of a completion of a private declaration
2116 and then Is_Private_Type (Def_Id)
2118 -- Deal with preelaborable initialization. Note that this processing
2119 -- is done by Process_Full_View, but as can be seen below, in this
2120 -- case the call to Process_Full_View is skipped if any serious
2121 -- errors have occurred, and we don't want to lose this check.
2123 if Known_To_Have_Preelab_Init (Def_Id) then
2124 Set_Must_Have_Preelab_Init (T);
2127 -- Create corresponding record now, because some private dependents
2128 -- may be subtypes of the partial view. Skip if errors are present,
2129 -- to prevent cascaded messages.
2131 if Serious_Errors_Detected = 0
2132 and then Expander_Active
2134 Expand_N_Task_Type_Declaration (N);
2135 Process_Full_View (N, T, Def_Id);
2139 Analyze_Aspect_Specifications (N, Def_Id, Aspect_Specifications (N));
2140 end Analyze_Task_Type_Declaration;
2142 -----------------------------------
2143 -- Analyze_Terminate_Alternative --
2144 -----------------------------------
2146 procedure Analyze_Terminate_Alternative (N : Node_Id) is
2148 Tasking_Used := True;
2150 if Present (Pragmas_Before (N)) then
2151 Analyze_List (Pragmas_Before (N));
2154 if Present (Condition (N)) then
2155 Analyze_And_Resolve (Condition (N), Any_Boolean);
2157 end Analyze_Terminate_Alternative;
2159 ------------------------------
2160 -- Analyze_Timed_Entry_Call --
2161 ------------------------------
2163 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
2164 Trigger : constant Node_Id :=
2165 Entry_Call_Statement (Entry_Call_Alternative (N));
2166 Is_Disp_Select : Boolean := False;
2169 -- Select statement is not allowed in SPARK or ALFA
2171 if Formal_Verification_Mode then
2172 Error_Msg_F ("|~~select statement is not allowed", N);
2175 -- Proceed with analysis
2177 Check_Restriction (No_Select_Statements, N);
2178 Tasking_Used := True;
2180 -- Ada 2005 (AI-345): The trigger may be a dispatching call
2182 if Ada_Version >= Ada_2005 then
2184 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
2187 -- Postpone the analysis of the statements till expansion. Analyze only
2188 -- if the expander is disabled in order to catch any semantic errors.
2190 if Is_Disp_Select then
2191 if not Expander_Active then
2192 Analyze (Entry_Call_Alternative (N));
2193 Analyze (Delay_Alternative (N));
2196 -- Regular select analysis
2199 Analyze (Entry_Call_Alternative (N));
2200 Analyze (Delay_Alternative (N));
2202 end Analyze_Timed_Entry_Call;
2204 ------------------------------------
2205 -- Analyze_Triggering_Alternative --
2206 ------------------------------------
2208 procedure Analyze_Triggering_Alternative (N : Node_Id) is
2209 Trigger : constant Node_Id := Triggering_Statement (N);
2212 Tasking_Used := True;
2214 if Present (Pragmas_Before (N)) then
2215 Analyze_List (Pragmas_Before (N));
2220 if Comes_From_Source (Trigger)
2221 and then Nkind (Trigger) not in N_Delay_Statement
2222 and then Nkind (Trigger) /= N_Entry_Call_Statement
2224 if Ada_Version < Ada_2005 then
2226 ("triggering statement must be delay or entry call", Trigger);
2228 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
2229 -- procedure_or_entry_call, the procedure_name or procedure_prefix
2230 -- of the procedure_call_statement shall denote an entry renamed by a
2231 -- procedure, or (a view of) a primitive subprogram of a limited
2232 -- interface whose first parameter is a controlling parameter.
2234 elsif Nkind (Trigger) = N_Procedure_Call_Statement
2235 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
2236 and then not Is_Controlling_Limited_Procedure
2237 (Entity (Name (Trigger)))
2239 Error_Msg_N ("triggering statement must be delay, procedure " &
2240 "or entry call", Trigger);
2244 if Is_Non_Empty_List (Statements (N)) then
2245 Analyze_Statements (Statements (N));
2247 end Analyze_Triggering_Alternative;
2249 -----------------------
2250 -- Check_Max_Entries --
2251 -----------------------
2253 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
2256 procedure Count (L : List_Id);
2257 -- Count entries in given declaration list
2263 procedure Count (L : List_Id) is
2272 while Present (D) loop
2273 if Nkind (D) = N_Entry_Declaration then
2275 DSD : constant Node_Id :=
2276 Discrete_Subtype_Definition (D);
2279 -- If not an entry family, then just one entry
2282 Ecount := Ecount + 1;
2284 -- If entry family with static bounds, count entries
2286 elsif Is_OK_Static_Subtype (Etype (DSD)) then
2288 Lo : constant Uint :=
2290 (Type_Low_Bound (Etype (DSD)));
2291 Hi : constant Uint :=
2293 (Type_High_Bound (Etype (DSD)));
2297 Ecount := Ecount + Hi - Lo + 1;
2301 -- Entry family with non-static bounds
2304 -- Record an unknown count restriction, and if the
2305 -- restriction is active, post a message or warning.
2307 Check_Restriction (R, D);
2316 -- Start of processing for Check_Max_Entries
2320 Count (Visible_Declarations (D));
2321 Count (Private_Declarations (D));
2324 Check_Restriction (R, D, Ecount);
2326 end Check_Max_Entries;
2328 ----------------------
2329 -- Check_Interfaces --
2330 ----------------------
2332 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
2334 Iface_Typ : Entity_Id;
2338 (Nkind_In (N, N_Protected_Type_Declaration, N_Task_Type_Declaration));
2340 if Present (Interface_List (N)) then
2341 Set_Is_Tagged_Type (T);
2343 Iface := First (Interface_List (N));
2344 while Present (Iface) loop
2345 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
2347 if not Is_Interface (Iface_Typ) then
2349 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
2352 -- Ada 2005 (AI-251): "The declaration of a specific descendant
2353 -- of an interface type freezes the interface type" RM 13.14.
2355 Freeze_Before (N, Etype (Iface));
2357 if Nkind (N) = N_Protected_Type_Declaration then
2359 -- Ada 2005 (AI-345): Protected types can only implement
2360 -- limited, synchronized, or protected interfaces (note that
2361 -- the predicate Is_Limited_Interface includes synchronized
2362 -- and protected interfaces).
2364 if Is_Task_Interface (Iface_Typ) then
2365 Error_Msg_N ("(Ada 2005) protected type cannot implement "
2366 & "a task interface", Iface);
2368 elsif not Is_Limited_Interface (Iface_Typ) then
2369 Error_Msg_N ("(Ada 2005) protected type cannot implement "
2370 & "a non-limited interface", Iface);
2373 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
2375 -- Ada 2005 (AI-345): Task types can only implement limited,
2376 -- synchronized, or task interfaces (note that the predicate
2377 -- Is_Limited_Interface includes synchronized and task
2380 if Is_Protected_Interface (Iface_Typ) then
2381 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
2382 "protected interface", Iface);
2384 elsif not Is_Limited_Interface (Iface_Typ) then
2385 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
2386 "non-limited interface", Iface);
2395 if not Has_Private_Declaration (T) then
2399 -- Additional checks on full-types associated with private type
2400 -- declarations. Search for the private type declaration.
2403 Full_T_Ifaces : Elist_Id;
2406 Priv_T_Ifaces : Elist_Id;
2409 Priv_T := First_Entity (Scope (T));
2411 pragma Assert (Present (Priv_T));
2413 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
2414 exit when Full_View (Priv_T) = T;
2417 Next_Entity (Priv_T);
2420 -- In case of synchronized types covering interfaces the private type
2421 -- declaration must be limited.
2423 if Present (Interface_List (N))
2424 and then not Is_Limited_Record (Priv_T)
2426 Error_Msg_Sloc := Sloc (Priv_T);
2427 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
2428 "private type#", T);
2431 -- RM 7.3 (7.1/2): If the full view has a partial view that is
2432 -- tagged then check RM 7.3 subsidiary rules.
2434 if Is_Tagged_Type (Priv_T)
2435 and then not Error_Posted (N)
2437 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
2438 -- type if and only if the full type is a synchronized tagged type
2440 if Is_Synchronized_Tagged_Type (Priv_T)
2441 and then not Is_Synchronized_Tagged_Type (T)
2444 ("(Ada 2005) full view must be a synchronized tagged " &
2445 "type (RM 7.3 (7.2/2))", Priv_T);
2447 elsif Is_Synchronized_Tagged_Type (T)
2448 and then not Is_Synchronized_Tagged_Type (Priv_T)
2451 ("(Ada 2005) partial view must be a synchronized tagged " &
2452 "type (RM 7.3 (7.2/2))", T);
2455 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
2456 -- interface type if and only if the full type is descendant of
2457 -- the interface type.
2459 if Present (Interface_List (N))
2460 or else (Is_Tagged_Type (Priv_T)
2461 and then Has_Interfaces
2462 (Priv_T, Use_Full_View => False))
2464 if Is_Tagged_Type (Priv_T) then
2466 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
2469 if Is_Tagged_Type (T) then
2470 Collect_Interfaces (T, Full_T_Ifaces);
2473 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
2475 if Present (Iface) then
2477 ("interface & not implemented by full type " &
2478 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
2481 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
2483 if Present (Iface) then
2485 ("interface & not implemented by partial " &
2486 "view (RM-2005 7.3 (7.3/2))", T, Iface);
2491 end Check_Interfaces;
2493 --------------------------------
2494 -- Check_Triggering_Statement --
2495 --------------------------------
2497 procedure Check_Triggering_Statement
2499 Error_Node : Node_Id;
2500 Is_Dispatching : out Boolean)
2505 Is_Dispatching := False;
2507 -- It is not possible to have a dispatching trigger if we are not in
2510 if Ada_Version >= Ada_2005
2511 and then Nkind (Trigger) = N_Procedure_Call_Statement
2512 and then Present (Parameter_Associations (Trigger))
2514 Param := First (Parameter_Associations (Trigger));
2516 if Is_Controlling_Actual (Param)
2517 and then Is_Interface (Etype (Param))
2519 if Is_Limited_Record (Etype (Param)) then
2520 Is_Dispatching := True;
2523 ("dispatching operation of limited or synchronized " &
2524 "interface required (RM 9.7.2(3))!", Error_Node);
2528 end Check_Triggering_Statement;
2530 --------------------------
2531 -- Find_Concurrent_Spec --
2532 --------------------------
2534 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
2535 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
2538 -- The type may have been given by an incomplete type declaration.
2539 -- Find full view now.
2541 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
2542 Spec_Id := Full_View (Spec_Id);
2546 end Find_Concurrent_Spec;
2548 --------------------------
2549 -- Install_Declarations --
2550 --------------------------
2552 procedure Install_Declarations (Spec : Entity_Id) is
2556 E := First_Entity (Spec);
2557 while Present (E) loop
2558 Prev := Current_Entity (E);
2559 Set_Current_Entity (E);
2560 Set_Is_Immediately_Visible (E);
2561 Set_Homonym (E, Prev);
2564 end Install_Declarations;