re PR rtl-optimization/34522 (inefficient code for long long multiply when only low...
[official-gcc.git] / gcc / ada / sem_ch9.adb
blobec4ce80bff1469ffc00254ddeccf7f95e667bf91
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 9 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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;
38 with Opt; use Opt;
39 with Restrict; use Restrict;
40 with Rident; use Rident;
41 with Rtsfind; use Rtsfind;
42 with Sem; use Sem;
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;
55 with Style;
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
70 -- the given maximum.
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 procedure Check_Triggering_Statement
77 (Trigger : Node_Id;
78 Error_Node : Node_Id;
79 Is_Dispatching : out Boolean);
80 -- Examine the triggering statement of a select statement, conditional or
81 -- timed entry call. If Trigger is a dispatching call, return its status
82 -- in Is_Dispatching and check whether the primitive belongs to a limited
83 -- interface. If it does not, emit an error at Error_Node.
85 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id;
86 -- Find entity in corresponding task or protected declaration. Use full
87 -- view if first declaration was for an incomplete type.
89 procedure Install_Declarations (Spec : Entity_Id);
90 -- Utility to make visible in corresponding body the entities defined in
91 -- task, protected type declaration, or entry declaration.
93 -----------------------------
94 -- Analyze_Abort_Statement --
95 -----------------------------
97 procedure Analyze_Abort_Statement (N : Node_Id) is
98 T_Name : Node_Id;
100 begin
101 Tasking_Used := True;
102 T_Name := First (Names (N));
103 while Present (T_Name) loop
104 Analyze (T_Name);
106 if Is_Task_Type (Etype (T_Name))
107 or else (Ada_Version >= Ada_05
108 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
109 and then Is_Interface (Etype (T_Name))
110 and then Is_Task_Interface (Etype (T_Name)))
111 then
112 Resolve (T_Name);
113 else
114 if Ada_Version >= Ada_05 then
115 Error_Msg_N ("expect task name or task interface class-wide "
116 & "object for ABORT", T_Name);
117 else
118 Error_Msg_N ("expect task name for ABORT", T_Name);
119 end if;
121 return;
122 end if;
124 Next (T_Name);
125 end loop;
127 Check_Restriction (No_Abort_Statements, N);
128 Check_Potentially_Blocking_Operation (N);
129 end Analyze_Abort_Statement;
131 --------------------------------
132 -- Analyze_Accept_Alternative --
133 --------------------------------
135 procedure Analyze_Accept_Alternative (N : Node_Id) is
136 begin
137 Tasking_Used := True;
139 if Present (Pragmas_Before (N)) then
140 Analyze_List (Pragmas_Before (N));
141 end if;
143 if Present (Condition (N)) then
144 Analyze_And_Resolve (Condition (N), Any_Boolean);
145 end if;
147 Analyze (Accept_Statement (N));
149 if Is_Non_Empty_List (Statements (N)) then
150 Analyze_Statements (Statements (N));
151 end if;
152 end Analyze_Accept_Alternative;
154 ------------------------------
155 -- Analyze_Accept_Statement --
156 ------------------------------
158 procedure Analyze_Accept_Statement (N : Node_Id) is
159 Nam : constant Entity_Id := Entry_Direct_Name (N);
160 Formals : constant List_Id := Parameter_Specifications (N);
161 Index : constant Node_Id := Entry_Index (N);
162 Stats : constant Node_Id := Handled_Statement_Sequence (N);
163 Accept_Id : Entity_Id;
164 Entry_Nam : Entity_Id;
165 E : Entity_Id;
166 Kind : Entity_Kind;
167 Task_Nam : Entity_Id;
169 -----------------------
170 -- Actual_Index_Type --
171 -----------------------
173 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
174 -- If the bounds of an entry family depend on task discriminants, create
175 -- a new index type where a discriminant is replaced by the local
176 -- variable that renames it in the task body.
178 -----------------------
179 -- Actual_Index_Type --
180 -----------------------
182 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
183 Typ : constant Entity_Id := Entry_Index_Type (E);
184 Lo : constant Node_Id := Type_Low_Bound (Typ);
185 Hi : constant Node_Id := Type_High_Bound (Typ);
186 New_T : Entity_Id;
188 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
189 -- If bound is discriminant reference, replace with corresponding
190 -- local variable of the same name.
192 -----------------------------
193 -- Actual_Discriminant_Ref --
194 -----------------------------
196 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
197 Typ : constant Entity_Id := Etype (Bound);
198 Ref : Node_Id;
199 begin
200 if not Is_Entity_Name (Bound)
201 or else Ekind (Entity (Bound)) /= E_Discriminant
202 then
203 return Bound;
204 else
205 Ref := Make_Identifier (Sloc (N), Chars (Entity (Bound)));
206 Analyze (Ref);
207 Resolve (Ref, Typ);
208 return Ref;
209 end if;
210 end Actual_Discriminant_Ref;
212 -- Start of processing for Actual_Index_Type
214 begin
215 if not Has_Discriminants (Task_Nam)
216 or else (not Is_Entity_Name (Lo)
217 and then not Is_Entity_Name (Hi))
218 then
219 return Entry_Index_Type (E);
220 else
221 New_T := Create_Itype (Ekind (Typ), N);
222 Set_Etype (New_T, Base_Type (Typ));
223 Set_Size_Info (New_T, Typ);
224 Set_RM_Size (New_T, RM_Size (Typ));
225 Set_Scalar_Range (New_T,
226 Make_Range (Sloc (N),
227 Low_Bound => Actual_Discriminant_Ref (Lo),
228 High_Bound => Actual_Discriminant_Ref (Hi)));
230 return New_T;
231 end if;
232 end Actual_Index_Type;
234 -- Start of processing for Analyze_Accept_Statement
236 begin
237 Tasking_Used := True;
239 -- Entry name is initialized to Any_Id. It should get reset to the
240 -- matching entry entity. An error is signalled if it is not reset.
242 Entry_Nam := Any_Id;
244 for J in reverse 0 .. Scope_Stack.Last loop
245 Task_Nam := Scope_Stack.Table (J).Entity;
246 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
247 Kind := Ekind (Task_Nam);
249 if Kind /= E_Block and then Kind /= E_Loop
250 and then not Is_Entry (Task_Nam)
251 then
252 Error_Msg_N ("enclosing body of accept must be a task", N);
253 return;
254 end if;
255 end loop;
257 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
258 Error_Msg_N ("invalid context for accept statement", N);
259 return;
260 end if;
262 -- In order to process the parameters, we create a defining
263 -- identifier that can be used as the name of the scope. The
264 -- name of the accept statement itself is not a defining identifier,
265 -- and we cannot use its name directly because the task may have
266 -- any number of accept statements for the same entry.
268 if Present (Index) then
269 Accept_Id := New_Internal_Entity
270 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
271 else
272 Accept_Id := New_Internal_Entity
273 (E_Entry, Current_Scope, Sloc (N), 'E');
274 end if;
276 Set_Etype (Accept_Id, Standard_Void_Type);
277 Set_Accept_Address (Accept_Id, New_Elmt_List);
279 if Present (Formals) then
280 Push_Scope (Accept_Id);
281 Process_Formals (Formals, N);
282 Create_Extra_Formals (Accept_Id);
283 End_Scope;
284 end if;
286 -- We set the default expressions processed flag because we don't need
287 -- default expression functions. This is really more like body entity
288 -- than a spec entity anyway.
290 Set_Default_Expressions_Processed (Accept_Id);
292 E := First_Entity (Etype (Task_Nam));
293 while Present (E) loop
294 if Chars (E) = Chars (Nam)
295 and then (Ekind (E) = Ekind (Accept_Id))
296 and then Type_Conformant (Accept_Id, E)
297 then
298 Entry_Nam := E;
299 exit;
300 end if;
302 Next_Entity (E);
303 end loop;
305 if Entry_Nam = Any_Id then
306 Error_Msg_N ("no entry declaration matches accept statement", N);
307 return;
308 else
309 Set_Entity (Nam, Entry_Nam);
310 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
311 Style.Check_Identifier (Nam, Entry_Nam);
312 end if;
314 -- Verify that the entry is not hidden by a procedure declared in the
315 -- current block (pathological but possible).
317 if Current_Scope /= Task_Nam then
318 declare
319 E1 : Entity_Id;
321 begin
322 E1 := First_Entity (Current_Scope);
323 while Present (E1) loop
324 if Ekind (E1) = E_Procedure
325 and then Chars (E1) = Chars (Entry_Nam)
326 and then Type_Conformant (E1, Entry_Nam)
327 then
328 Error_Msg_N ("entry name is not visible", N);
329 end if;
331 Next_Entity (E1);
332 end loop;
333 end;
334 end if;
336 Set_Convention (Accept_Id, Convention (Entry_Nam));
337 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
339 for J in reverse 0 .. Scope_Stack.Last loop
340 exit when Task_Nam = Scope_Stack.Table (J).Entity;
342 if Entry_Nam = Scope_Stack.Table (J).Entity then
343 Error_Msg_N ("duplicate accept statement for same entry", N);
344 end if;
346 end loop;
348 declare
349 P : Node_Id := N;
350 begin
351 loop
352 P := Parent (P);
353 case Nkind (P) is
354 when N_Task_Body | N_Compilation_Unit =>
355 exit;
356 when N_Asynchronous_Select =>
357 Error_Msg_N ("accept statements are not allowed within" &
358 " an asynchronous select inner" &
359 " to the enclosing task body", N);
360 exit;
361 when others =>
362 null;
363 end case;
364 end loop;
365 end;
367 if Ekind (E) = E_Entry_Family then
368 if No (Index) then
369 Error_Msg_N ("missing entry index in accept for entry family", N);
370 else
371 Analyze_And_Resolve (Index, Entry_Index_Type (E));
372 Apply_Range_Check (Index, Actual_Index_Type (E));
373 end if;
375 elsif Present (Index) then
376 Error_Msg_N ("invalid entry index in accept for simple entry", N);
377 end if;
379 -- If label declarations present, analyze them. They are declared in the
380 -- enclosing task, but their enclosing scope is the entry itself, so
381 -- that goto's to the label are recognized as local to the accept.
383 if Present (Declarations (N)) then
384 declare
385 Decl : Node_Id;
386 Id : Entity_Id;
388 begin
389 Decl := First (Declarations (N));
390 while Present (Decl) loop
391 Analyze (Decl);
393 pragma Assert
394 (Nkind (Decl) = N_Implicit_Label_Declaration);
396 Id := Defining_Identifier (Decl);
397 Set_Enclosing_Scope (Id, Entry_Nam);
398 Next (Decl);
399 end loop;
400 end;
401 end if;
403 -- If statements are present, they must be analyzed in the context of
404 -- the entry, so that references to formals are correctly resolved. We
405 -- also have to add the declarations that are required by the expansion
406 -- of the accept statement in this case if expansion active.
408 -- In the case of a select alternative of a selective accept, the
409 -- expander references the address declaration even if there is no
410 -- statement list.
412 -- We also need to create the renaming declarations for the local
413 -- variables that will replace references to the formals within the
414 -- accept statement.
416 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
418 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
419 -- fields on all entry formals (this loop ignores all other entities).
420 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
421 -- well, so that we can post accurate warnings on each accept statement
422 -- for the same entry.
424 E := First_Entity (Entry_Nam);
425 while Present (E) loop
426 if Is_Formal (E) then
427 Set_Never_Set_In_Source (E, True);
428 Set_Is_True_Constant (E, False);
429 Set_Current_Value (E, Empty);
430 Set_Referenced (E, False);
431 Set_Referenced_As_LHS (E, False);
432 Set_Referenced_As_Out_Parameter (E, False);
433 Set_Has_Pragma_Unreferenced (E, False);
434 end if;
436 Next_Entity (E);
437 end loop;
439 -- Analyze statements if present
441 if Present (Stats) then
442 Push_Scope (Entry_Nam);
443 Install_Declarations (Entry_Nam);
445 Set_Actual_Subtypes (N, Current_Scope);
447 Analyze (Stats);
448 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
449 End_Scope;
450 end if;
452 -- Some warning checks
454 Check_Potentially_Blocking_Operation (N);
455 Check_References (Entry_Nam, N);
456 Set_Entry_Accepted (Entry_Nam);
457 end Analyze_Accept_Statement;
459 ---------------------------------
460 -- Analyze_Asynchronous_Select --
461 ---------------------------------
463 procedure Analyze_Asynchronous_Select (N : Node_Id) is
464 Is_Disp_Select : Boolean := False;
465 Trigger : Node_Id;
467 begin
468 Tasking_Used := True;
469 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
470 Check_Restriction (No_Select_Statements, N);
472 if Ada_Version >= Ada_05 then
473 Trigger := Triggering_Statement (Triggering_Alternative (N));
475 Analyze (Trigger);
477 -- Ada 2005 (AI-345): Check for a potential dispatching select
479 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
480 end if;
482 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
483 -- select will have to duplicate the triggering statements. Postpone
484 -- the analysis of the statements till expansion. Analyze only if the
485 -- expander is disabled in order to catch any semantic errors.
487 if Is_Disp_Select then
488 if not Expander_Active then
489 Analyze_Statements (Statements (Abortable_Part (N)));
490 Analyze (Triggering_Alternative (N));
491 end if;
493 -- Analyze the statements. We analyze statements in the abortable part,
494 -- because this is the section that is executed first, and that way our
495 -- remembering of saved values and checks is accurate.
497 else
498 Analyze_Statements (Statements (Abortable_Part (N)));
499 Analyze (Triggering_Alternative (N));
500 end if;
501 end Analyze_Asynchronous_Select;
503 ------------------------------------
504 -- Analyze_Conditional_Entry_Call --
505 ------------------------------------
507 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
508 Trigger : constant Node_Id :=
509 Entry_Call_Statement (Entry_Call_Alternative (N));
510 Is_Disp_Select : Boolean := False;
512 begin
513 Check_Restriction (No_Select_Statements, N);
514 Tasking_Used := True;
516 -- Ada 2005 (AI-345): The trigger may be a dispatching call
518 if Ada_Version >= Ada_05 then
519 Analyze (Trigger);
520 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
521 end if;
523 if List_Length (Else_Statements (N)) = 1
524 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
525 then
526 Error_Msg_N
527 ("suspicious form of conditional entry call?!", N);
528 Error_Msg_N
529 ("\`SELECT OR` may be intended rather than `SELECT ELSE`!", N);
530 end if;
532 -- Postpone the analysis of the statements till expansion. Analyze only
533 -- if the expander is disabled in order to catch any semantic errors.
535 if Is_Disp_Select then
536 if not Expander_Active then
537 Analyze (Entry_Call_Alternative (N));
538 Analyze_Statements (Else_Statements (N));
539 end if;
541 -- Regular select analysis
543 else
544 Analyze (Entry_Call_Alternative (N));
545 Analyze_Statements (Else_Statements (N));
546 end if;
547 end Analyze_Conditional_Entry_Call;
549 --------------------------------
550 -- Analyze_Delay_Alternative --
551 --------------------------------
553 procedure Analyze_Delay_Alternative (N : Node_Id) is
554 Expr : Node_Id;
555 Typ : Entity_Id;
557 begin
558 Tasking_Used := True;
559 Check_Restriction (No_Delay, N);
561 if Present (Pragmas_Before (N)) then
562 Analyze_List (Pragmas_Before (N));
563 end if;
565 if Nkind_In (Parent (N), N_Selective_Accept, N_Timed_Entry_Call) then
566 Expr := Expression (Delay_Statement (N));
568 -- Defer full analysis until the statement is expanded, to insure
569 -- that generated code does not move past the guard. The delay
570 -- expression is only evaluated if the guard is open.
572 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
573 Pre_Analyze_And_Resolve (Expr, Standard_Duration);
574 else
575 Pre_Analyze_And_Resolve (Expr);
576 end if;
578 Typ := First_Subtype (Etype (Expr));
580 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
581 and then not Is_RTE (Typ, RO_CA_Time)
582 and then not Is_RTE (Typ, RO_RT_Time)
583 then
584 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
585 end if;
587 Check_Restriction (No_Fixed_Point, Expr);
589 else
590 Analyze (Delay_Statement (N));
591 end if;
593 if Present (Condition (N)) then
594 Analyze_And_Resolve (Condition (N), Any_Boolean);
595 end if;
597 if Is_Non_Empty_List (Statements (N)) then
598 Analyze_Statements (Statements (N));
599 end if;
600 end Analyze_Delay_Alternative;
602 ----------------------------
603 -- Analyze_Delay_Relative --
604 ----------------------------
606 procedure Analyze_Delay_Relative (N : Node_Id) is
607 E : constant Node_Id := Expression (N);
608 begin
609 Check_Restriction (No_Relative_Delay, N);
610 Tasking_Used := True;
611 Check_Restriction (No_Delay, N);
612 Check_Potentially_Blocking_Operation (N);
613 Analyze_And_Resolve (E, Standard_Duration);
614 Check_Restriction (No_Fixed_Point, E);
615 end Analyze_Delay_Relative;
617 -------------------------
618 -- Analyze_Delay_Until --
619 -------------------------
621 procedure Analyze_Delay_Until (N : Node_Id) is
622 E : constant Node_Id := Expression (N);
623 Typ : Entity_Id;
625 begin
626 Tasking_Used := True;
627 Check_Restriction (No_Delay, N);
628 Check_Potentially_Blocking_Operation (N);
629 Analyze (E);
630 Typ := First_Subtype (Etype (E));
632 if not Is_RTE (Typ, RO_CA_Time) and then
633 not Is_RTE (Typ, RO_RT_Time)
634 then
635 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
636 end if;
637 end Analyze_Delay_Until;
639 ------------------------
640 -- Analyze_Entry_Body --
641 ------------------------
643 procedure Analyze_Entry_Body (N : Node_Id) is
644 Id : constant Entity_Id := Defining_Identifier (N);
645 Decls : constant List_Id := Declarations (N);
646 Stats : constant Node_Id := Handled_Statement_Sequence (N);
647 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
648 P_Type : constant Entity_Id := Current_Scope;
649 Entry_Name : Entity_Id;
650 E : Entity_Id;
652 begin
653 Tasking_Used := True;
655 -- Entry_Name is initialized to Any_Id. It should get reset to the
656 -- matching entry entity. An error is signalled if it is not reset
658 Entry_Name := Any_Id;
660 Analyze (Formals);
662 if Present (Entry_Index_Specification (Formals)) then
663 Set_Ekind (Id, E_Entry_Family);
664 else
665 Set_Ekind (Id, E_Entry);
666 end if;
668 Set_Scope (Id, Current_Scope);
669 Set_Etype (Id, Standard_Void_Type);
670 Set_Accept_Address (Id, New_Elmt_List);
672 E := First_Entity (P_Type);
673 while Present (E) loop
674 if Chars (E) = Chars (Id)
675 and then (Ekind (E) = Ekind (Id))
676 and then Type_Conformant (Id, E)
677 then
678 Entry_Name := E;
679 Set_Convention (Id, Convention (E));
680 Set_Corresponding_Body (Parent (Entry_Name), Id);
681 Check_Fully_Conformant (Id, E, N);
683 if Ekind (Id) = E_Entry_Family then
684 if not Fully_Conformant_Discrete_Subtypes (
685 Discrete_Subtype_Definition (Parent (E)),
686 Discrete_Subtype_Definition
687 (Entry_Index_Specification (Formals)))
688 then
689 Error_Msg_N
690 ("index not fully conformant with previous declaration",
691 Discrete_Subtype_Definition
692 (Entry_Index_Specification (Formals)));
694 else
695 -- The elaboration of the entry body does not recompute the
696 -- bounds of the index, which may have side effects. Inherit
697 -- the bounds from the entry declaration. This is critical
698 -- if the entry has a per-object constraint. If a bound is
699 -- given by a discriminant, it must be reanalyzed in order
700 -- to capture the discriminal of the current entry, rather
701 -- than that of the protected type.
703 declare
704 Index_Spec : constant Node_Id :=
705 Entry_Index_Specification (Formals);
707 Def : constant Node_Id :=
708 New_Copy_Tree
709 (Discrete_Subtype_Definition (Parent (E)));
711 begin
712 if Nkind
713 (Original_Node
714 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
715 then
716 Set_Etype (Def, Empty);
717 Set_Analyzed (Def, False);
719 -- Keep the original subtree to ensure a properly
720 -- formed tree (e.g. for ASIS use).
722 Rewrite
723 (Discrete_Subtype_Definition (Index_Spec), Def);
725 Set_Analyzed (Low_Bound (Def), False);
726 Set_Analyzed (High_Bound (Def), False);
728 if Denotes_Discriminant (Low_Bound (Def)) then
729 Set_Entity (Low_Bound (Def), Empty);
730 end if;
732 if Denotes_Discriminant (High_Bound (Def)) then
733 Set_Entity (High_Bound (Def), Empty);
734 end if;
736 Analyze (Def);
737 Make_Index (Def, Index_Spec);
738 Set_Etype
739 (Defining_Identifier (Index_Spec), Etype (Def));
740 end if;
741 end;
742 end if;
743 end if;
745 exit;
746 end if;
748 Next_Entity (E);
749 end loop;
751 if Entry_Name = Any_Id then
752 Error_Msg_N ("no entry declaration matches entry body", N);
753 return;
755 elsif Has_Completion (Entry_Name) then
756 Error_Msg_N ("duplicate entry body", N);
757 return;
759 else
760 Set_Has_Completion (Entry_Name);
761 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
762 Style.Check_Identifier (Id, Entry_Name);
763 end if;
765 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
766 Push_Scope (Entry_Name);
768 Exp_Ch9.Expand_Entry_Body_Declarations (N);
769 Install_Declarations (Entry_Name);
770 Set_Actual_Subtypes (N, Current_Scope);
772 -- The entity for the protected subprogram corresponding to the entry
773 -- has been created. We retain the name of this entity in the entry
774 -- body, for use when the corresponding subprogram body is created.
775 -- Note that entry bodies have no corresponding_spec, and there is no
776 -- easy link back in the tree between the entry body and the entity for
777 -- the entry itself, which is why we must propagate some attributes
778 -- explicitly from spec to body.
780 Set_Protected_Body_Subprogram
781 (Id, Protected_Body_Subprogram (Entry_Name));
783 Set_Entry_Parameters_Type
784 (Id, Entry_Parameters_Type (Entry_Name));
786 if Present (Decls) then
787 Analyze_Declarations (Decls);
788 end if;
790 if Present (Stats) then
791 Analyze (Stats);
792 end if;
794 -- Check for unreferenced variables etc. Before the Check_References
795 -- call, we transfer Never_Set_In_Source and Referenced flags from
796 -- parameters in the spec to the corresponding entities in the body,
797 -- since we want the warnings on the body entities. Note that we do
798 -- not have to transfer Referenced_As_LHS, since that flag can only
799 -- be set for simple variables.
801 -- At the same time, we set the flags on the spec entities to suppress
802 -- any warnings on the spec formals, since we also scan the spec.
803 -- Finally, we propagate the Entry_Component attribute to the body
804 -- formals, for use in the renaming declarations created later for the
805 -- formals (see exp_ch9.Add_Formal_Renamings).
807 declare
808 E1 : Entity_Id;
809 E2 : Entity_Id;
811 begin
812 E1 := First_Entity (Entry_Name);
813 while Present (E1) loop
814 E2 := First_Entity (Id);
815 while Present (E2) loop
816 exit when Chars (E1) = Chars (E2);
817 Next_Entity (E2);
818 end loop;
820 -- If no matching body entity, then we already had a detected
821 -- error of some kind, so just don't worry about these warnings.
823 if No (E2) then
824 goto Continue;
825 end if;
827 if Ekind (E1) = E_Out_Parameter then
828 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
829 Set_Never_Set_In_Source (E1, False);
830 end if;
832 Set_Referenced (E2, Referenced (E1));
833 Set_Referenced (E1);
834 Set_Entry_Component (E2, Entry_Component (E1));
836 <<Continue>>
837 Next_Entity (E1);
838 end loop;
840 Check_References (Id);
841 end;
843 -- We still need to check references for the spec, since objects
844 -- declared in the body are chained (in the First_Entity sense) to
845 -- the spec rather than the body in the case of entries.
847 Check_References (Entry_Name);
849 -- Process the end label, and terminate the scope
851 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
852 End_Scope;
854 -- If this is an entry family, remove the loop created to provide
855 -- a scope for the entry index.
857 if Ekind (Id) = E_Entry_Family
858 and then Present (Entry_Index_Specification (Formals))
859 then
860 End_Scope;
861 end if;
862 end Analyze_Entry_Body;
864 ------------------------------------
865 -- Analyze_Entry_Body_Formal_Part --
866 ------------------------------------
868 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
869 Id : constant Entity_Id := Defining_Identifier (Parent (N));
870 Index : constant Node_Id := Entry_Index_Specification (N);
871 Formals : constant List_Id := Parameter_Specifications (N);
873 begin
874 Tasking_Used := True;
876 if Present (Index) then
877 Analyze (Index);
879 -- The entry index functions like a loop variable, thus it is known
880 -- to have a valid value.
882 Set_Is_Known_Valid (Defining_Identifier (Index));
883 end if;
885 if Present (Formals) then
886 Set_Scope (Id, Current_Scope);
887 Push_Scope (Id);
888 Process_Formals (Formals, Parent (N));
889 End_Scope;
890 end if;
891 end Analyze_Entry_Body_Formal_Part;
893 ------------------------------------
894 -- Analyze_Entry_Call_Alternative --
895 ------------------------------------
897 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
898 Call : constant Node_Id := Entry_Call_Statement (N);
900 begin
901 Tasking_Used := True;
903 if Present (Pragmas_Before (N)) then
904 Analyze_List (Pragmas_Before (N));
905 end if;
907 if Nkind (Call) = N_Attribute_Reference then
909 -- Possibly a stream attribute, but definitely illegal. Other
910 -- illegalitles, such as procedure calls, are diagnosed after
911 -- resolution.
913 Error_Msg_N ("entry call alternative requires an entry call", Call);
914 return;
915 end if;
917 Analyze (Call);
919 if Is_Non_Empty_List (Statements (N)) then
920 Analyze_Statements (Statements (N));
921 end if;
922 end Analyze_Entry_Call_Alternative;
924 -------------------------------
925 -- Analyze_Entry_Declaration --
926 -------------------------------
928 procedure Analyze_Entry_Declaration (N : Node_Id) is
929 Formals : constant List_Id := Parameter_Specifications (N);
930 Id : constant Entity_Id := Defining_Identifier (N);
931 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
933 begin
934 Generate_Definition (Id);
935 Tasking_Used := True;
937 if No (D_Sdef) then
938 Set_Ekind (Id, E_Entry);
939 else
940 Enter_Name (Id);
941 Set_Ekind (Id, E_Entry_Family);
942 Analyze (D_Sdef);
943 Make_Index (D_Sdef, N, Id);
944 end if;
946 Set_Etype (Id, Standard_Void_Type);
947 Set_Convention (Id, Convention_Entry);
948 Set_Accept_Address (Id, New_Elmt_List);
950 if Present (Formals) then
951 Set_Scope (Id, Current_Scope);
952 Push_Scope (Id);
953 Process_Formals (Formals, N);
954 Create_Extra_Formals (Id);
955 End_Scope;
956 end if;
958 if Ekind (Id) = E_Entry then
959 New_Overloaded_Entity (Id);
960 end if;
962 Generate_Reference_To_Formals (Id);
963 end Analyze_Entry_Declaration;
965 ---------------------------------------
966 -- Analyze_Entry_Index_Specification --
967 ---------------------------------------
969 -- The Defining_Identifier of the entry index specification is local to the
970 -- entry body, but it must be available in the entry barrier which is
971 -- evaluated outside of the entry body. The index is eventually renamed as
972 -- a run-time object, so is visibility is strictly a front-end concern. In
973 -- order to make it available to the barrier, we create an additional
974 -- scope, as for a loop, whose only declaration is the index name. This
975 -- loop is not attached to the tree and does not appear as an entity local
976 -- to the protected type, so its existence need only be knwown to routines
977 -- that process entry families.
979 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
980 Iden : constant Node_Id := Defining_Identifier (N);
981 Def : constant Node_Id := Discrete_Subtype_Definition (N);
982 Loop_Id : constant Entity_Id :=
983 Make_Defining_Identifier (Sloc (N),
984 Chars => New_Internal_Name ('L'));
986 begin
987 Tasking_Used := True;
988 Analyze (Def);
990 -- There is no elaboration of the entry index specification. Therefore,
991 -- if the index is a range, it is not resolved and expanded, but the
992 -- bounds are inherited from the entry declaration, and reanalyzed.
993 -- See Analyze_Entry_Body.
995 if Nkind (Def) /= N_Range then
996 Make_Index (Def, N);
997 end if;
999 Set_Ekind (Loop_Id, E_Loop);
1000 Set_Scope (Loop_Id, Current_Scope);
1001 Push_Scope (Loop_Id);
1002 Enter_Name (Iden);
1003 Set_Ekind (Iden, E_Entry_Index_Parameter);
1004 Set_Etype (Iden, Etype (Def));
1005 end Analyze_Entry_Index_Specification;
1007 ----------------------------
1008 -- Analyze_Protected_Body --
1009 ----------------------------
1011 procedure Analyze_Protected_Body (N : Node_Id) is
1012 Body_Id : constant Entity_Id := Defining_Identifier (N);
1013 Last_E : Entity_Id;
1015 Spec_Id : Entity_Id;
1016 -- This is initially the entity of the protected object or protected
1017 -- type involved, but is replaced by the protected type always in the
1018 -- case of a single protected declaration, since this is the proper
1019 -- scope to be used.
1021 Ref_Id : Entity_Id;
1022 -- This is the entity of the protected object or protected type
1023 -- involved, and is the entity used for cross-reference purposes (it
1024 -- differs from Spec_Id in the case of a single protected object, since
1025 -- Spec_Id is set to the protected type in this case).
1027 begin
1028 Tasking_Used := True;
1029 Set_Ekind (Body_Id, E_Protected_Body);
1030 Spec_Id := Find_Concurrent_Spec (Body_Id);
1032 if Present (Spec_Id)
1033 and then Ekind (Spec_Id) = E_Protected_Type
1034 then
1035 null;
1037 elsif Present (Spec_Id)
1038 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1039 and then not Comes_From_Source (Etype (Spec_Id))
1040 then
1041 null;
1043 else
1044 Error_Msg_N ("missing specification for protected body", Body_Id);
1045 return;
1046 end if;
1048 Ref_Id := Spec_Id;
1049 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1050 Style.Check_Identifier (Body_Id, Spec_Id);
1052 -- The declarations are always attached to the type
1054 if Ekind (Spec_Id) /= E_Protected_Type then
1055 Spec_Id := Etype (Spec_Id);
1056 end if;
1058 Push_Scope (Spec_Id);
1059 Set_Corresponding_Spec (N, Spec_Id);
1060 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1061 Set_Has_Completion (Spec_Id);
1062 Install_Declarations (Spec_Id);
1064 Exp_Ch9.Expand_Protected_Body_Declarations (N, Spec_Id);
1066 Last_E := Last_Entity (Spec_Id);
1068 Analyze_Declarations (Declarations (N));
1070 -- For visibility purposes, all entities in the body are private. Set
1071 -- First_Private_Entity accordingly, if there was no private part in the
1072 -- protected declaration.
1074 if No (First_Private_Entity (Spec_Id)) then
1075 if Present (Last_E) then
1076 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1077 else
1078 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1079 end if;
1080 end if;
1082 Check_Completion (Body_Id);
1083 Check_References (Spec_Id);
1084 Process_End_Label (N, 't', Ref_Id);
1085 End_Scope;
1086 end Analyze_Protected_Body;
1088 ----------------------------------
1089 -- Analyze_Protected_Definition --
1090 ----------------------------------
1092 procedure Analyze_Protected_Definition (N : Node_Id) is
1093 E : Entity_Id;
1094 L : Entity_Id;
1096 begin
1097 Tasking_Used := True;
1098 Analyze_Declarations (Visible_Declarations (N));
1100 if Present (Private_Declarations (N))
1101 and then not Is_Empty_List (Private_Declarations (N))
1102 then
1103 L := Last_Entity (Current_Scope);
1104 Analyze_Declarations (Private_Declarations (N));
1106 if Present (L) then
1107 Set_First_Private_Entity (Current_Scope, Next_Entity (L));
1108 else
1109 Set_First_Private_Entity (Current_Scope,
1110 First_Entity (Current_Scope));
1111 end if;
1112 end if;
1114 E := First_Entity (Current_Scope);
1115 while Present (E) loop
1116 if Ekind (E) = E_Function
1117 or else Ekind (E) = E_Procedure
1118 then
1119 Set_Convention (E, Convention_Protected);
1121 elsif Is_Task_Type (Etype (E))
1122 or else Has_Task (Etype (E))
1123 then
1124 Set_Has_Task (Current_Scope);
1125 end if;
1127 Next_Entity (E);
1128 end loop;
1130 Check_Max_Entries (N, Max_Protected_Entries);
1131 Process_End_Label (N, 'e', Current_Scope);
1132 end Analyze_Protected_Definition;
1134 ----------------------------
1135 -- Analyze_Protected_Type --
1136 ----------------------------
1138 procedure Analyze_Protected_Type (N : Node_Id) is
1139 Def_Id : constant Entity_Id := Defining_Identifier (N);
1140 E : Entity_Id;
1141 T : Entity_Id;
1143 begin
1144 if No_Run_Time_Mode then
1145 Error_Msg_CRT ("protected type", N);
1146 return;
1147 end if;
1149 Tasking_Used := True;
1150 Check_Restriction (No_Protected_Types, N);
1152 T := Find_Type_Name (N);
1154 if Ekind (T) = E_Incomplete_Type then
1155 T := Full_View (T);
1156 Set_Completion_Referenced (T);
1157 end if;
1159 Set_Ekind (T, E_Protected_Type);
1160 Set_Is_First_Subtype (T, True);
1161 Init_Size_Align (T);
1162 Set_Etype (T, T);
1163 Set_Has_Delayed_Freeze (T, True);
1164 Set_Stored_Constraint (T, No_Elist);
1165 Push_Scope (T);
1167 if Ada_Version >= Ada_05 then
1168 Check_Interfaces (N, T);
1169 end if;
1171 if Present (Discriminant_Specifications (N)) then
1172 if Has_Discriminants (T) then
1174 -- Install discriminants. Also, verify conformance of
1175 -- discriminants of previous and current view. ???
1177 Install_Declarations (T);
1178 else
1179 Process_Discriminants (N);
1180 end if;
1181 end if;
1183 Set_Is_Constrained (T, not Has_Discriminants (T));
1185 -- Perform minimal expansion of protected type while inside a generic.
1186 -- The corresponding record is needed for various semantic checks.
1188 if Ada_Version >= Ada_05
1189 and then Inside_A_Generic
1190 then
1191 Insert_After_And_Analyze (N,
1192 Build_Corresponding_Record (N, T, Sloc (T)));
1193 end if;
1195 Analyze (Protected_Definition (N));
1197 -- Protected types with entries are controlled (because of the
1198 -- Protection component if nothing else), same for any protected type
1199 -- with interrupt handlers. Note that we need to analyze the protected
1200 -- definition to set Has_Entries and such.
1202 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
1203 or else Number_Entries (T) > 1)
1204 and then
1205 (Has_Entries (T)
1206 or else Has_Interrupt_Handler (T)
1207 or else Has_Attach_Handler (T))
1208 then
1209 Set_Has_Controlled_Component (T, True);
1210 end if;
1212 -- The Ekind of components is E_Void during analysis to detect illegal
1213 -- uses. Now it can be set correctly.
1215 E := First_Entity (Current_Scope);
1216 while Present (E) loop
1217 if Ekind (E) = E_Void then
1218 Set_Ekind (E, E_Component);
1219 Init_Component_Location (E);
1220 end if;
1222 Next_Entity (E);
1223 end loop;
1225 End_Scope;
1227 -- Case of a completion of a private declaration
1229 if T /= Def_Id
1230 and then Is_Private_Type (Def_Id)
1231 then
1232 -- Deal with preelaborable initialization. Note that this processing
1233 -- is done by Process_Full_View, but as can be seen below, in this
1234 -- case the call to Process_Full_View is skipped if any serious
1235 -- errors have occurred, and we don't want to lose this check.
1237 if Known_To_Have_Preelab_Init (Def_Id) then
1238 Set_Must_Have_Preelab_Init (T);
1239 end if;
1241 -- Create corresponding record now, because some private dependents
1242 -- may be subtypes of the partial view. Skip if errors are present,
1243 -- to prevent cascaded messages.
1245 if Serious_Errors_Detected = 0
1246 and then Expander_Active
1247 then
1248 Expand_N_Protected_Type_Declaration (N);
1249 Process_Full_View (N, T, Def_Id);
1250 end if;
1251 end if;
1252 end Analyze_Protected_Type;
1254 ---------------------
1255 -- Analyze_Requeue --
1256 ---------------------
1258 procedure Analyze_Requeue (N : Node_Id) is
1259 Count : Natural := 0;
1260 Entry_Name : Node_Id := Name (N);
1261 Entry_Id : Entity_Id;
1262 I : Interp_Index;
1263 Is_Disp_Req : Boolean;
1264 It : Interp;
1265 Enclosing : Entity_Id;
1266 Target_Obj : Node_Id := Empty;
1267 Req_Scope : Entity_Id;
1268 Outer_Ent : Entity_Id;
1270 begin
1271 Check_Restriction (No_Requeue_Statements, N);
1272 Check_Unreachable_Code (N);
1273 Tasking_Used := True;
1275 Enclosing := Empty;
1276 for J in reverse 0 .. Scope_Stack.Last loop
1277 Enclosing := Scope_Stack.Table (J).Entity;
1278 exit when Is_Entry (Enclosing);
1280 if Ekind (Enclosing) /= E_Block
1281 and then Ekind (Enclosing) /= E_Loop
1282 then
1283 Error_Msg_N ("requeue must appear within accept or entry body", N);
1284 return;
1285 end if;
1286 end loop;
1288 Analyze (Entry_Name);
1290 if Etype (Entry_Name) = Any_Type then
1291 return;
1292 end if;
1294 if Nkind (Entry_Name) = N_Selected_Component then
1295 Target_Obj := Prefix (Entry_Name);
1296 Entry_Name := Selector_Name (Entry_Name);
1297 end if;
1299 -- If an explicit target object is given then we have to check the
1300 -- restrictions of 9.5.4(6).
1302 if Present (Target_Obj) then
1304 -- Locate containing concurrent unit and determine enclosing entry
1305 -- body or outermost enclosing accept statement within the unit.
1307 Outer_Ent := Empty;
1308 for S in reverse 0 .. Scope_Stack.Last loop
1309 Req_Scope := Scope_Stack.Table (S).Entity;
1311 exit when Ekind (Req_Scope) in Task_Kind
1312 or else Ekind (Req_Scope) in Protected_Kind;
1314 if Is_Entry (Req_Scope) then
1315 Outer_Ent := Req_Scope;
1316 end if;
1317 end loop;
1319 pragma Assert (Present (Outer_Ent));
1321 -- Check that the accessibility level of the target object is not
1322 -- greater or equal to the outermost enclosing accept statement (or
1323 -- entry body) unless it is a parameter of the innermost enclosing
1324 -- accept statement (or entry body).
1326 if Object_Access_Level (Target_Obj) >= Scope_Depth (Outer_Ent)
1327 and then
1328 (not Is_Entity_Name (Target_Obj)
1329 or else Ekind (Entity (Target_Obj)) not in Formal_Kind
1330 or else Enclosing /= Scope (Entity (Target_Obj)))
1331 then
1332 Error_Msg_N
1333 ("target object has invalid level for requeue", Target_Obj);
1334 end if;
1335 end if;
1337 -- Overloaded case, find right interpretation
1339 if Is_Overloaded (Entry_Name) then
1340 Entry_Id := Empty;
1342 -- Loop over candidate interpretations and filter out any that are
1343 -- not parameterless, are not type conformant, are not entries, or
1344 -- do not come from source.
1346 Get_First_Interp (Entry_Name, I, It);
1347 while Present (It.Nam) loop
1349 -- Note: we test type conformance here, not subtype conformance.
1350 -- Subtype conformance will be tested later on, but it is better
1351 -- for error output in some cases not to do that here.
1353 if (No (First_Formal (It.Nam))
1354 or else (Type_Conformant (Enclosing, It.Nam)))
1355 and then Ekind (It.Nam) = E_Entry
1356 then
1357 -- Ada 2005 (AI-345): Since protected and task types have
1358 -- primitive entry wrappers, we only consider source entries.
1360 if Comes_From_Source (It.Nam) then
1361 Count := Count + 1;
1362 Entry_Id := It.Nam;
1363 else
1364 Remove_Interp (I);
1365 end if;
1366 end if;
1368 Get_Next_Interp (I, It);
1369 end loop;
1371 if Count = 0 then
1372 Error_Msg_N ("no entry matches context", N);
1373 return;
1375 elsif Count > 1 then
1376 Error_Msg_N ("ambiguous entry name in requeue", N);
1377 return;
1379 else
1380 Set_Is_Overloaded (Entry_Name, False);
1381 Set_Entity (Entry_Name, Entry_Id);
1382 end if;
1384 -- Non-overloaded cases
1386 -- For the case of a reference to an element of an entry family, the
1387 -- Entry_Name is an indexed component.
1389 elsif Nkind (Entry_Name) = N_Indexed_Component then
1391 -- Requeue to an entry out of the body
1393 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
1394 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
1396 -- Requeue from within the body itself
1398 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
1399 Entry_Id := Entity (Prefix (Entry_Name));
1401 else
1402 Error_Msg_N ("invalid entry_name specified", N);
1403 return;
1404 end if;
1406 -- If we had a requeue of the form REQUEUE A (B), then the parser
1407 -- accepted it (because it could have been a requeue on an entry index.
1408 -- If A turns out not to be an entry family, then the analysis of A (B)
1409 -- turned it into a function call.
1411 elsif Nkind (Entry_Name) = N_Function_Call then
1412 Error_Msg_N
1413 ("arguments not allowed in requeue statement",
1414 First (Parameter_Associations (Entry_Name)));
1415 return;
1417 -- Normal case of no entry family, no argument
1419 else
1420 Entry_Id := Entity (Entry_Name);
1421 end if;
1423 -- Ada 2005 (AI05-0030): Potential dispatching requeue statement. The
1424 -- target type must be a concurrent interface class-wide type and the
1425 -- entry name must be a procedure, flagged by pragma Implemented_By_
1426 -- Entry.
1428 Is_Disp_Req :=
1429 Ada_Version >= Ada_05
1430 and then Present (Target_Obj)
1431 and then Is_Class_Wide_Type (Etype (Target_Obj))
1432 and then Is_Concurrent_Interface (Etype (Target_Obj))
1433 and then Ekind (Entry_Id) = E_Procedure
1434 and then Implemented_By_Entry (Entry_Id);
1436 -- Resolve entry, and check that it is subtype conformant with the
1437 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1438 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
1440 if not Is_Entry (Entry_Id)
1441 and then not Is_Disp_Req
1442 then
1443 Error_Msg_N ("expect entry name in requeue statement", Name (N));
1445 elsif Ekind (Entry_Id) = E_Entry_Family
1446 and then Nkind (Entry_Name) /= N_Indexed_Component
1447 then
1448 Error_Msg_N ("missing index for entry family component", Name (N));
1450 else
1451 Resolve_Entry (Name (N));
1452 Generate_Reference (Entry_Id, Entry_Name);
1454 if Present (First_Formal (Entry_Id)) then
1455 if VM_Target = JVM_Target and then not Inspector_Mode then
1456 Error_Msg_N
1457 ("arguments unsupported in requeue statement",
1458 First_Formal (Entry_Id));
1459 return;
1460 end if;
1462 -- Ada 2005 (AI05-0030): Perform type conformance after skipping
1463 -- the first parameter of Entry_Id since it is the interface
1464 -- controlling formal.
1466 if Is_Disp_Req then
1467 declare
1468 Enclosing_Formal : Entity_Id;
1469 Target_Formal : Entity_Id;
1471 begin
1472 Enclosing_Formal := First_Formal (Enclosing);
1473 Target_Formal := Next_Formal (First_Formal (Entry_Id));
1474 while Present (Enclosing_Formal)
1475 and then Present (Target_Formal)
1476 loop
1477 if not Conforming_Types
1478 (T1 => Etype (Enclosing_Formal),
1479 T2 => Etype (Target_Formal),
1480 Ctype => Subtype_Conformant)
1481 then
1482 Error_Msg_Node_2 := Target_Formal;
1483 Error_Msg_NE
1484 ("formal & is not subtype conformant with &" &
1485 "in dispatching requeue", N, Enclosing_Formal);
1486 end if;
1488 Next_Formal (Enclosing_Formal);
1489 Next_Formal (Target_Formal);
1490 end loop;
1491 end;
1492 else
1493 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
1494 end if;
1496 -- Processing for parameters accessed by the requeue
1498 declare
1499 Ent : Entity_Id;
1501 begin
1502 Ent := First_Formal (Enclosing);
1503 while Present (Ent) loop
1505 -- For OUT or IN OUT parameter, the effect of the requeue is
1506 -- to assign the parameter a value on exit from the requeued
1507 -- body, so we can set it as source assigned. We also clear
1508 -- the Is_True_Constant indication. We do not need to clear
1509 -- Current_Value, since the effect of the requeue is to
1510 -- perform an unconditional goto so that any further
1511 -- references will not occur anyway.
1513 if Ekind (Ent) = E_Out_Parameter
1514 or else
1515 Ekind (Ent) = E_In_Out_Parameter
1516 then
1517 Set_Never_Set_In_Source (Ent, False);
1518 Set_Is_True_Constant (Ent, False);
1519 end if;
1521 -- For all parameters, the requeue acts as a reference,
1522 -- since the value of the parameter is passed to the new
1523 -- entry, so we want to suppress unreferenced warnings.
1525 Set_Referenced (Ent);
1526 Next_Formal (Ent);
1527 end loop;
1528 end;
1529 end if;
1530 end if;
1531 end Analyze_Requeue;
1533 ------------------------------
1534 -- Analyze_Selective_Accept --
1535 ------------------------------
1537 procedure Analyze_Selective_Accept (N : Node_Id) is
1538 Alts : constant List_Id := Select_Alternatives (N);
1539 Alt : Node_Id;
1541 Accept_Present : Boolean := False;
1542 Terminate_Present : Boolean := False;
1543 Delay_Present : Boolean := False;
1544 Relative_Present : Boolean := False;
1545 Alt_Count : Uint := Uint_0;
1547 begin
1548 Check_Restriction (No_Select_Statements, N);
1549 Tasking_Used := True;
1551 -- Loop to analyze alternatives
1553 Alt := First (Alts);
1554 while Present (Alt) loop
1555 Alt_Count := Alt_Count + 1;
1556 Analyze (Alt);
1558 if Nkind (Alt) = N_Delay_Alternative then
1559 if Delay_Present then
1561 if Relative_Present /=
1562 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
1563 then
1564 Error_Msg_N
1565 ("delay_until and delay_relative alternatives ", Alt);
1566 Error_Msg_N
1567 ("\cannot appear in the same selective_wait", Alt);
1568 end if;
1570 else
1571 Delay_Present := True;
1572 Relative_Present :=
1573 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
1574 end if;
1576 elsif Nkind (Alt) = N_Terminate_Alternative then
1577 if Terminate_Present then
1578 Error_Msg_N ("only one terminate alternative allowed", N);
1579 else
1580 Terminate_Present := True;
1581 Check_Restriction (No_Terminate_Alternatives, N);
1582 end if;
1584 elsif Nkind (Alt) = N_Accept_Alternative then
1585 Accept_Present := True;
1587 -- Check for duplicate accept
1589 declare
1590 Alt1 : Node_Id;
1591 Stm : constant Node_Id := Accept_Statement (Alt);
1592 EDN : constant Node_Id := Entry_Direct_Name (Stm);
1593 Ent : Entity_Id;
1595 begin
1596 if Nkind (EDN) = N_Identifier
1597 and then No (Condition (Alt))
1598 and then Present (Entity (EDN)) -- defend against junk
1599 and then Ekind (Entity (EDN)) = E_Entry
1600 then
1601 Ent := Entity (EDN);
1603 Alt1 := First (Alts);
1604 while Alt1 /= Alt loop
1605 if Nkind (Alt1) = N_Accept_Alternative
1606 and then No (Condition (Alt1))
1607 then
1608 declare
1609 Stm1 : constant Node_Id := Accept_Statement (Alt1);
1610 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
1612 begin
1613 if Nkind (EDN1) = N_Identifier then
1614 if Entity (EDN1) = Ent then
1615 Error_Msg_Sloc := Sloc (Stm1);
1616 Error_Msg_N
1617 ("?accept duplicates one on line#", Stm);
1618 exit;
1619 end if;
1620 end if;
1621 end;
1622 end if;
1624 Next (Alt1);
1625 end loop;
1626 end if;
1627 end;
1628 end if;
1630 Next (Alt);
1631 end loop;
1633 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
1634 Check_Potentially_Blocking_Operation (N);
1636 if Terminate_Present and Delay_Present then
1637 Error_Msg_N ("at most one of terminate or delay alternative", N);
1639 elsif not Accept_Present then
1640 Error_Msg_N
1641 ("select must contain at least one accept alternative", N);
1642 end if;
1644 if Present (Else_Statements (N)) then
1645 if Terminate_Present or Delay_Present then
1646 Error_Msg_N ("else part not allowed with other alternatives", N);
1647 end if;
1649 Analyze_Statements (Else_Statements (N));
1650 end if;
1651 end Analyze_Selective_Accept;
1653 ------------------------------
1654 -- Analyze_Single_Protected --
1655 ------------------------------
1657 procedure Analyze_Single_Protected (N : Node_Id) is
1658 Loc : constant Source_Ptr := Sloc (N);
1659 Id : constant Node_Id := Defining_Identifier (N);
1660 T : Entity_Id;
1661 T_Decl : Node_Id;
1662 O_Decl : Node_Id;
1663 O_Name : constant Entity_Id := Id;
1665 begin
1666 Generate_Definition (Id);
1667 Tasking_Used := True;
1669 -- The node is rewritten as a protected type declaration, in exact
1670 -- analogy with what is done with single tasks.
1672 T :=
1673 Make_Defining_Identifier (Sloc (Id),
1674 New_External_Name (Chars (Id), 'T'));
1676 T_Decl :=
1677 Make_Protected_Type_Declaration (Loc,
1678 Defining_Identifier => T,
1679 Protected_Definition => Relocate_Node (Protected_Definition (N)),
1680 Interface_List => Interface_List (N));
1682 O_Decl :=
1683 Make_Object_Declaration (Loc,
1684 Defining_Identifier => O_Name,
1685 Object_Definition => Make_Identifier (Loc, Chars (T)));
1687 Rewrite (N, T_Decl);
1688 Insert_After (N, O_Decl);
1689 Mark_Rewrite_Insertion (O_Decl);
1691 -- Enter names of type and object before analysis, because the name of
1692 -- the object may be used in its own body.
1694 Enter_Name (T);
1695 Set_Ekind (T, E_Protected_Type);
1696 Set_Etype (T, T);
1698 Enter_Name (O_Name);
1699 Set_Ekind (O_Name, E_Variable);
1700 Set_Etype (O_Name, T);
1702 -- Instead of calling Analyze on the new node, call the proper analysis
1703 -- procedure directly. Otherwise the node would be expanded twice, with
1704 -- disastrous result.
1706 Analyze_Protected_Type (N);
1707 end Analyze_Single_Protected;
1709 -------------------------
1710 -- Analyze_Single_Task --
1711 -------------------------
1713 procedure Analyze_Single_Task (N : Node_Id) is
1714 Loc : constant Source_Ptr := Sloc (N);
1715 Id : constant Node_Id := Defining_Identifier (N);
1716 T : Entity_Id;
1717 T_Decl : Node_Id;
1718 O_Decl : Node_Id;
1719 O_Name : constant Entity_Id := Id;
1721 begin
1722 Generate_Definition (Id);
1723 Tasking_Used := True;
1725 -- The node is rewritten as a task type declaration, followed by an
1726 -- object declaration of that anonymous task type.
1728 T :=
1729 Make_Defining_Identifier (Sloc (Id),
1730 New_External_Name (Chars (Id), Suffix => "TK"));
1732 T_Decl :=
1733 Make_Task_Type_Declaration (Loc,
1734 Defining_Identifier => T,
1735 Task_Definition => Relocate_Node (Task_Definition (N)),
1736 Interface_List => Interface_List (N));
1738 -- We use the original defining identifier of the single task in the
1739 -- generated object declaration, so that debugging information can
1740 -- be attached to it when compiling with -gnatD. The parent of the
1741 -- entity is the new object declaration. The single_task_declaration
1742 -- is not used further in semantics or code generation, but is scanned
1743 -- when generating debug information, and therefore needs the updated
1744 -- Sloc information for the entity (see Sprint).
1746 O_Decl :=
1747 Make_Object_Declaration (Loc,
1748 Defining_Identifier => O_Name,
1749 Object_Definition => Make_Identifier (Loc, Chars (T)));
1751 Rewrite (N, T_Decl);
1752 Insert_After (N, O_Decl);
1753 Mark_Rewrite_Insertion (O_Decl);
1755 -- Enter names of type and object before analysis, because the name of
1756 -- the object may be used in its own body.
1758 Enter_Name (T);
1759 Set_Ekind (T, E_Task_Type);
1760 Set_Etype (T, T);
1762 Enter_Name (O_Name);
1763 Set_Ekind (O_Name, E_Variable);
1764 Set_Etype (O_Name, T);
1766 -- Instead of calling Analyze on the new node, call the proper analysis
1767 -- procedure directly. Otherwise the node would be expanded twice, with
1768 -- disastrous result.
1770 Analyze_Task_Type (N);
1771 end Analyze_Single_Task;
1773 -----------------------
1774 -- Analyze_Task_Body --
1775 -----------------------
1777 procedure Analyze_Task_Body (N : Node_Id) is
1778 Body_Id : constant Entity_Id := Defining_Identifier (N);
1779 HSS : constant Node_Id := Handled_Statement_Sequence (N);
1780 Last_E : Entity_Id;
1782 Spec_Id : Entity_Id;
1783 -- This is initially the entity of the task or task type involved, but
1784 -- is replaced by the task type always in the case of a single task
1785 -- declaration, since this is the proper scope to be used.
1787 Ref_Id : Entity_Id;
1788 -- This is the entity of the task or task type, and is the entity used
1789 -- for cross-reference purposes (it differs from Spec_Id in the case of
1790 -- a single task, since Spec_Id is set to the task type)
1792 begin
1793 Tasking_Used := True;
1794 Set_Ekind (Body_Id, E_Task_Body);
1795 Set_Scope (Body_Id, Current_Scope);
1796 Spec_Id := Find_Concurrent_Spec (Body_Id);
1798 -- The spec is either a task type declaration, or a single task
1799 -- declaration for which we have created an anonymous type.
1801 if Present (Spec_Id)
1802 and then Ekind (Spec_Id) = E_Task_Type
1803 then
1804 null;
1806 elsif Present (Spec_Id)
1807 and then Ekind (Etype (Spec_Id)) = E_Task_Type
1808 and then not Comes_From_Source (Etype (Spec_Id))
1809 then
1810 null;
1812 else
1813 Error_Msg_N ("missing specification for task body", Body_Id);
1814 return;
1815 end if;
1817 if Has_Completion (Spec_Id)
1818 and then Present (Corresponding_Body (Parent (Spec_Id)))
1819 then
1820 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
1821 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
1823 else
1824 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
1825 end if;
1826 end if;
1828 Ref_Id := Spec_Id;
1829 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1830 Style.Check_Identifier (Body_Id, Spec_Id);
1832 -- Deal with case of body of single task (anonymous type was created)
1834 if Ekind (Spec_Id) = E_Variable then
1835 Spec_Id := Etype (Spec_Id);
1836 end if;
1838 Push_Scope (Spec_Id);
1839 Set_Corresponding_Spec (N, Spec_Id);
1840 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1841 Set_Has_Completion (Spec_Id);
1842 Install_Declarations (Spec_Id);
1843 Last_E := Last_Entity (Spec_Id);
1845 Analyze_Declarations (Declarations (N));
1847 -- For visibility purposes, all entities in the body are private. Set
1848 -- First_Private_Entity accordingly, if there was no private part in the
1849 -- protected declaration.
1851 if No (First_Private_Entity (Spec_Id)) then
1852 if Present (Last_E) then
1853 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1854 else
1855 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1856 end if;
1857 end if;
1859 -- Mark all handlers as not suitable for local raise optimization,
1860 -- since this optimization causes difficulties in a task context.
1862 if Present (Exception_Handlers (HSS)) then
1863 declare
1864 Handlr : Node_Id;
1865 begin
1866 Handlr := First (Exception_Handlers (HSS));
1867 while Present (Handlr) loop
1868 Set_Local_Raise_Not_OK (Handlr);
1869 Next (Handlr);
1870 end loop;
1871 end;
1872 end if;
1874 -- Now go ahead and complete analysis of the task body
1876 Analyze (HSS);
1877 Check_Completion (Body_Id);
1878 Check_References (Body_Id);
1879 Check_References (Spec_Id);
1881 -- Check for entries with no corresponding accept
1883 declare
1884 Ent : Entity_Id;
1886 begin
1887 Ent := First_Entity (Spec_Id);
1888 while Present (Ent) loop
1889 if Is_Entry (Ent)
1890 and then not Entry_Accepted (Ent)
1891 and then Comes_From_Source (Ent)
1892 then
1893 Error_Msg_NE ("no accept for entry &?", N, Ent);
1894 end if;
1896 Next_Entity (Ent);
1897 end loop;
1898 end;
1900 Process_End_Label (HSS, 't', Ref_Id);
1901 End_Scope;
1902 end Analyze_Task_Body;
1904 -----------------------------
1905 -- Analyze_Task_Definition --
1906 -----------------------------
1908 procedure Analyze_Task_Definition (N : Node_Id) is
1909 L : Entity_Id;
1911 begin
1912 Tasking_Used := True;
1914 if Present (Visible_Declarations (N)) then
1915 Analyze_Declarations (Visible_Declarations (N));
1916 end if;
1918 if Present (Private_Declarations (N)) then
1919 L := Last_Entity (Current_Scope);
1920 Analyze_Declarations (Private_Declarations (N));
1922 if Present (L) then
1923 Set_First_Private_Entity
1924 (Current_Scope, Next_Entity (L));
1925 else
1926 Set_First_Private_Entity
1927 (Current_Scope, First_Entity (Current_Scope));
1928 end if;
1929 end if;
1931 Check_Max_Entries (N, Max_Task_Entries);
1932 Process_End_Label (N, 'e', Current_Scope);
1933 end Analyze_Task_Definition;
1935 -----------------------
1936 -- Analyze_Task_Type --
1937 -----------------------
1939 procedure Analyze_Task_Type (N : Node_Id) is
1940 Def_Id : constant Entity_Id := Defining_Identifier (N);
1941 T : Entity_Id;
1943 begin
1944 Check_Restriction (No_Tasking, N);
1945 Tasking_Used := True;
1946 T := Find_Type_Name (N);
1947 Generate_Definition (T);
1949 if Ekind (T) = E_Incomplete_Type then
1950 T := Full_View (T);
1951 Set_Completion_Referenced (T);
1952 end if;
1954 Set_Ekind (T, E_Task_Type);
1955 Set_Is_First_Subtype (T, True);
1956 Set_Has_Task (T, True);
1957 Init_Size_Align (T);
1958 Set_Etype (T, T);
1959 Set_Has_Delayed_Freeze (T, True);
1960 Set_Stored_Constraint (T, No_Elist);
1961 Push_Scope (T);
1963 if Ada_Version >= Ada_05 then
1964 Check_Interfaces (N, T);
1965 end if;
1967 if Present (Discriminant_Specifications (N)) then
1968 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1969 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
1970 end if;
1972 if Has_Discriminants (T) then
1974 -- Install discriminants. Also, verify conformance of
1975 -- discriminants of previous and current view. ???
1977 Install_Declarations (T);
1978 else
1979 Process_Discriminants (N);
1980 end if;
1981 end if;
1983 Set_Is_Constrained (T, not Has_Discriminants (T));
1985 -- Perform minimal expansion of the task type while inside a generic
1986 -- context. The corresponding record is needed for various semantic
1987 -- checks.
1989 if Inside_A_Generic then
1990 Insert_After_And_Analyze (N,
1991 Build_Corresponding_Record (N, T, Sloc (T)));
1992 end if;
1994 if Present (Task_Definition (N)) then
1995 Analyze_Task_Definition (Task_Definition (N));
1996 end if;
1998 if not Is_Library_Level_Entity (T) then
1999 Check_Restriction (No_Task_Hierarchy, N);
2000 end if;
2002 End_Scope;
2004 -- Case of a completion of a private declaration
2006 if T /= Def_Id
2007 and then Is_Private_Type (Def_Id)
2008 then
2009 -- Deal with preelaborable initialization. Note that this processing
2010 -- is done by Process_Full_View, but as can be seen below, in this
2011 -- case the call to Process_Full_View is skipped if any serious
2012 -- errors have occurred, and we don't want to lose this check.
2014 if Known_To_Have_Preelab_Init (Def_Id) then
2015 Set_Must_Have_Preelab_Init (T);
2016 end if;
2018 -- Create corresponding record now, because some private dependents
2019 -- may be subtypes of the partial view. Skip if errors are present,
2020 -- to prevent cascaded messages.
2022 if Serious_Errors_Detected = 0
2023 and then Expander_Active
2024 then
2025 Expand_N_Task_Type_Declaration (N);
2026 Process_Full_View (N, T, Def_Id);
2027 end if;
2028 end if;
2029 end Analyze_Task_Type;
2031 -----------------------------------
2032 -- Analyze_Terminate_Alternative --
2033 -----------------------------------
2035 procedure Analyze_Terminate_Alternative (N : Node_Id) is
2036 begin
2037 Tasking_Used := True;
2039 if Present (Pragmas_Before (N)) then
2040 Analyze_List (Pragmas_Before (N));
2041 end if;
2043 if Present (Condition (N)) then
2044 Analyze_And_Resolve (Condition (N), Any_Boolean);
2045 end if;
2046 end Analyze_Terminate_Alternative;
2048 ------------------------------
2049 -- Analyze_Timed_Entry_Call --
2050 ------------------------------
2052 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
2053 Trigger : constant Node_Id :=
2054 Entry_Call_Statement (Entry_Call_Alternative (N));
2055 Is_Disp_Select : Boolean := False;
2057 begin
2058 Check_Restriction (No_Select_Statements, N);
2059 Tasking_Used := True;
2061 -- Ada 2005 (AI-345): The trigger may be a dispatching call
2063 if Ada_Version >= Ada_05 then
2064 Analyze (Trigger);
2065 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
2066 end if;
2068 -- Postpone the analysis of the statements till expansion. Analyze only
2069 -- if the expander is disabled in order to catch any semantic errors.
2071 if Is_Disp_Select then
2072 if not Expander_Active then
2073 Analyze (Entry_Call_Alternative (N));
2074 Analyze (Delay_Alternative (N));
2075 end if;
2077 -- Regular select analysis
2079 else
2080 Analyze (Entry_Call_Alternative (N));
2081 Analyze (Delay_Alternative (N));
2082 end if;
2083 end Analyze_Timed_Entry_Call;
2085 ------------------------------------
2086 -- Analyze_Triggering_Alternative --
2087 ------------------------------------
2089 procedure Analyze_Triggering_Alternative (N : Node_Id) is
2090 Trigger : constant Node_Id := Triggering_Statement (N);
2092 begin
2093 Tasking_Used := True;
2095 if Present (Pragmas_Before (N)) then
2096 Analyze_List (Pragmas_Before (N));
2097 end if;
2099 Analyze (Trigger);
2101 if Comes_From_Source (Trigger)
2102 and then Nkind (Trigger) not in N_Delay_Statement
2103 and then Nkind (Trigger) /= N_Entry_Call_Statement
2104 then
2105 if Ada_Version < Ada_05 then
2106 Error_Msg_N
2107 ("triggering statement must be delay or entry call", Trigger);
2109 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
2110 -- procedure_or_entry_call, the procedure_name or pro- cedure_prefix
2111 -- of the procedure_call_statement shall denote an entry renamed by a
2112 -- procedure, or (a view of) a primitive subprogram of a limited
2113 -- interface whose first parameter is a controlling parameter.
2115 elsif Nkind (Trigger) = N_Procedure_Call_Statement
2116 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
2117 and then not Is_Controlling_Limited_Procedure
2118 (Entity (Name (Trigger)))
2119 then
2120 Error_Msg_N ("triggering statement must be delay, procedure " &
2121 "or entry call", Trigger);
2122 end if;
2123 end if;
2125 if Is_Non_Empty_List (Statements (N)) then
2126 Analyze_Statements (Statements (N));
2127 end if;
2128 end Analyze_Triggering_Alternative;
2130 -----------------------
2131 -- Check_Max_Entries --
2132 -----------------------
2134 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
2135 Ecount : Uint;
2137 procedure Count (L : List_Id);
2138 -- Count entries in given declaration list
2140 -----------
2141 -- Count --
2142 -----------
2144 procedure Count (L : List_Id) is
2145 D : Node_Id;
2147 begin
2148 if No (L) then
2149 return;
2150 end if;
2152 D := First (L);
2153 while Present (D) loop
2154 if Nkind (D) = N_Entry_Declaration then
2155 declare
2156 DSD : constant Node_Id :=
2157 Discrete_Subtype_Definition (D);
2159 begin
2160 -- If not an entry family, then just one entry
2162 if No (DSD) then
2163 Ecount := Ecount + 1;
2165 -- If entry family with static bounds, count entries
2167 elsif Is_OK_Static_Subtype (Etype (DSD)) then
2168 declare
2169 Lo : constant Uint :=
2170 Expr_Value
2171 (Type_Low_Bound (Etype (DSD)));
2172 Hi : constant Uint :=
2173 Expr_Value
2174 (Type_High_Bound (Etype (DSD)));
2176 begin
2177 if Hi >= Lo then
2178 Ecount := Ecount + Hi - Lo + 1;
2179 end if;
2180 end;
2182 -- Entry family with non-static bounds
2184 else
2185 -- If restriction is set, then this is an error
2187 if Restrictions.Set (R) then
2188 Error_Msg_N
2189 ("static subtype required by Restriction pragma",
2190 DSD);
2192 -- Otherwise we record an unknown count restriction
2194 else
2195 Check_Restriction (R, D);
2196 end if;
2197 end if;
2198 end;
2199 end if;
2201 Next (D);
2202 end loop;
2203 end Count;
2205 -- Start of processing for Check_Max_Entries
2207 begin
2208 Ecount := Uint_0;
2209 Count (Visible_Declarations (D));
2210 Count (Private_Declarations (D));
2212 if Ecount > 0 then
2213 Check_Restriction (R, D, Ecount);
2214 end if;
2215 end Check_Max_Entries;
2217 ----------------------
2218 -- Check_Interfaces --
2219 ----------------------
2221 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
2222 Iface : Node_Id;
2223 Iface_Typ : Entity_Id;
2225 begin
2226 pragma Assert
2227 (Nkind_In (N, N_Protected_Type_Declaration, N_Task_Type_Declaration));
2229 if Present (Interface_List (N)) then
2230 Set_Is_Tagged_Type (T);
2232 Iface := First (Interface_List (N));
2233 while Present (Iface) loop
2234 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
2236 if not Is_Interface (Iface_Typ) then
2237 Error_Msg_NE
2238 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
2240 else
2241 -- Ada 2005 (AI-251): "The declaration of a specific descendant
2242 -- of an interface type freezes the interface type" RM 13.14.
2244 Freeze_Before (N, Etype (Iface));
2246 if Nkind (N) = N_Protected_Type_Declaration then
2248 -- Ada 2005 (AI-345): Protected types can only implement
2249 -- limited, synchronized, or protected interfaces (note that
2250 -- the predicate Is_Limited_Interface includes synchronized
2251 -- and protected interfaces).
2253 if Is_Task_Interface (Iface_Typ) then
2254 Error_Msg_N ("(Ada 2005) protected type cannot implement "
2255 & "a task interface", Iface);
2257 elsif not Is_Limited_Interface (Iface_Typ) then
2258 Error_Msg_N ("(Ada 2005) protected type cannot implement "
2259 & "a non-limited interface", Iface);
2260 end if;
2262 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
2264 -- Ada 2005 (AI-345): Task types can only implement limited,
2265 -- synchronized, or task interfaces (note that the predicate
2266 -- Is_Limited_Interface includes synchronized and task
2267 -- interfaces).
2269 if Is_Protected_Interface (Iface_Typ) then
2270 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
2271 "protected interface", Iface);
2273 elsif not Is_Limited_Interface (Iface_Typ) then
2274 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
2275 "non-limited interface", Iface);
2276 end if;
2277 end if;
2278 end if;
2280 Next (Iface);
2281 end loop;
2282 end if;
2284 if not Has_Private_Declaration (T) then
2285 return;
2286 end if;
2288 -- Additional checks on full-types associated with private type
2289 -- declarations. Search for the private type declaration.
2291 declare
2292 Full_T_Ifaces : Elist_Id;
2293 Iface : Node_Id;
2294 Priv_T : Entity_Id;
2295 Priv_T_Ifaces : Elist_Id;
2297 begin
2298 Priv_T := First_Entity (Scope (T));
2299 loop
2300 pragma Assert (Present (Priv_T));
2302 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
2303 exit when Full_View (Priv_T) = T;
2304 end if;
2306 Next_Entity (Priv_T);
2307 end loop;
2309 -- In case of synchronized types covering interfaces the private type
2310 -- declaration must be limited.
2312 if Present (Interface_List (N))
2313 and then not Is_Limited_Record (Priv_T)
2314 then
2315 Error_Msg_Sloc := Sloc (Priv_T);
2316 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
2317 "private type#", T);
2318 end if;
2320 -- RM 7.3 (7.1/2): If the full view has a partial view that is
2321 -- tagged then check RM 7.3 subsidiary rules.
2323 if Is_Tagged_Type (Priv_T)
2324 and then not Error_Posted (N)
2325 then
2326 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
2327 -- type if and only if the full type is a synchronized tagged type
2329 if Is_Synchronized_Tagged_Type (Priv_T)
2330 and then not Is_Synchronized_Tagged_Type (T)
2331 then
2332 Error_Msg_N
2333 ("(Ada 2005) full view must be a synchronized tagged " &
2334 "type (RM 7.3 (7.2/2))", Priv_T);
2336 elsif Is_Synchronized_Tagged_Type (T)
2337 and then not Is_Synchronized_Tagged_Type (Priv_T)
2338 then
2339 Error_Msg_N
2340 ("(Ada 2005) partial view must be a synchronized tagged " &
2341 "type (RM 7.3 (7.2/2))", T);
2342 end if;
2344 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
2345 -- interface type if and only if the full type is descendant of
2346 -- the interface type.
2348 if Present (Interface_List (N))
2349 or else (Is_Tagged_Type (Priv_T)
2350 and then Has_Abstract_Interfaces
2351 (Priv_T, Use_Full_View => False))
2352 then
2353 if Is_Tagged_Type (Priv_T) then
2354 Collect_Abstract_Interfaces
2355 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
2356 end if;
2358 if Is_Tagged_Type (T) then
2359 Collect_Abstract_Interfaces (T, Full_T_Ifaces);
2360 end if;
2362 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
2364 if Present (Iface) then
2365 Error_Msg_NE ("interface & not implemented by full type " &
2366 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
2367 end if;
2369 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
2371 if Present (Iface) then
2372 Error_Msg_NE ("interface & not implemented by partial " &
2373 "view (RM-2005 7.3 (7.3/2))", T, Iface);
2374 end if;
2375 end if;
2376 end if;
2377 end;
2378 end Check_Interfaces;
2380 --------------------------------
2381 -- Check_Triggering_Statement --
2382 --------------------------------
2384 procedure Check_Triggering_Statement
2385 (Trigger : Node_Id;
2386 Error_Node : Node_Id;
2387 Is_Dispatching : out Boolean)
2389 Param : Node_Id;
2391 begin
2392 Is_Dispatching := False;
2394 -- It is not possible to have a dispatching trigger if we are not in
2395 -- Ada 2005 mode.
2397 if Ada_Version >= Ada_05
2398 and then Nkind (Trigger) = N_Procedure_Call_Statement
2399 and then Present (Parameter_Associations (Trigger))
2400 then
2401 Param := First (Parameter_Associations (Trigger));
2403 if Is_Controlling_Actual (Param)
2404 and then Is_Interface (Etype (Param))
2405 then
2406 if Is_Limited_Record (Etype (Param)) then
2407 Is_Dispatching := True;
2408 else
2409 Error_Msg_N
2410 ("dispatching operation of limited or synchronized " &
2411 "interface required (RM 9.7.2(3))!", Error_Node);
2412 end if;
2413 end if;
2414 end if;
2415 end Check_Triggering_Statement;
2417 --------------------------
2418 -- Find_Concurrent_Spec --
2419 --------------------------
2421 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
2422 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
2424 begin
2425 -- The type may have been given by an incomplete type declaration.
2426 -- Find full view now.
2428 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
2429 Spec_Id := Full_View (Spec_Id);
2430 end if;
2432 return Spec_Id;
2433 end Find_Concurrent_Spec;
2435 --------------------------
2436 -- Install_Declarations --
2437 --------------------------
2439 procedure Install_Declarations (Spec : Entity_Id) is
2440 E : Entity_Id;
2441 Prev : Entity_Id;
2442 begin
2443 E := First_Entity (Spec);
2444 while Present (E) loop
2445 Prev := Current_Entity (E);
2446 Set_Current_Entity (E);
2447 Set_Is_Immediately_Visible (E);
2448 Set_Homonym (E, Prev);
2449 Next_Entity (E);
2450 end loop;
2451 end Install_Declarations;
2453 end Sem_Ch9;