ada: Fix renaming of predefined equality operator for unchecked union types
[official-gcc.git] / gcc / ada / sem_ch9.adb
blob72821c51c3f82a1942c237b93e8b48e3c8f0f20b
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-2023, 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 Accessibility; use Accessibility;
27 with Aspects; use Aspects;
28 with Atree; use Atree;
29 with Checks; use Checks;
30 with Contracts; use Contracts;
31 with Einfo; use Einfo;
32 with Einfo.Entities; use Einfo.Entities;
33 with Einfo.Utils; use Einfo.Utils;
34 with Errout; use Errout;
35 with Exp_Ch9; use Exp_Ch9;
36 with Elists; use Elists;
37 with Freeze; use Freeze;
38 with Layout; use Layout;
39 with Lib; use Lib;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
44 with Opt; use Opt;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
48 with Sem; use Sem;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Ch3; use Sem_Ch3;
51 with Sem_Ch5; use Sem_Ch5;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Ch13; use Sem_Ch13;
55 with Sem_Elab; use Sem_Elab;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Type; use Sem_Type;
60 with Sem_Util; use Sem_Util;
61 with Sem_Warn; use Sem_Warn;
62 with Snames; use Snames;
63 with Stand; use Stand;
64 with Sinfo; use Sinfo;
65 with Sinfo.Nodes; use Sinfo.Nodes;
66 with Sinfo.Utils; use Sinfo.Utils;
67 with Style;
68 with Targparm; use Targparm;
69 with Tbuild; use Tbuild;
70 with Uintp; use Uintp;
72 package body Sem_Ch9 is
74 -----------------------
75 -- Local Subprograms --
76 -----------------------
78 function Allows_Lock_Free_Implementation
79 (N : Node_Id;
80 Lock_Free_Given : Boolean := False) return Boolean;
81 -- This routine returns True iff N satisfies the following list of lock-
82 -- free restrictions for protected type declaration and protected body:
84 -- 1) Protected type declaration
85 -- May not contain entries
86 -- Protected subprogram declarations may not have non-elementary
87 -- parameters.
89 -- 2) Protected Body
90 -- Each protected subprogram body within N must satisfy:
91 -- May reference only one protected component
92 -- May not reference non-constant entities outside the protected
93 -- subprogram scope.
94 -- May not contain address representation items, allocators and
95 -- quantified expressions.
96 -- May not contain delay, goto, loop and procedure call
97 -- statements.
98 -- May not contain exported and imported entities
99 -- May not dereference access values
100 -- Function calls and attribute references must be static
102 -- If Lock_Free_Given is True, an error message is issued when False is
103 -- returned.
105 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions);
106 -- Given either a protected definition or a task definition in D, check
107 -- the corresponding restriction parameter identifier R, and if it is set,
108 -- count the entries (checking the static requirement), and compare with
109 -- the given maximum.
111 procedure Check_Interfaces (N : Node_Id; T : Entity_Id);
112 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
113 -- Complete decoration of T and check legality of the covered interfaces.
115 procedure Check_Triggering_Statement
116 (Trigger : Node_Id;
117 Error_Node : Node_Id;
118 Is_Dispatching : out Boolean);
119 -- Examine the triggering statement of a select statement, conditional or
120 -- timed entry call. If Trigger is a dispatching call, return its status
121 -- in Is_Dispatching and check whether the primitive belongs to a limited
122 -- interface. If it does not, emit an error at Error_Node.
124 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id;
125 -- Find entity in corresponding task or protected declaration. Use full
126 -- view if first declaration was for an incomplete type.
128 -------------------------------------
129 -- Allows_Lock_Free_Implementation --
130 -------------------------------------
132 function Allows_Lock_Free_Implementation
133 (N : Node_Id;
134 Lock_Free_Given : Boolean := False) return Boolean
136 Errors_Count : Nat := 0;
137 -- Errors_Count is a count of errors detected by the compiler so far
138 -- when Lock_Free_Given is True.
140 begin
141 pragma Assert
142 (Nkind (N) in N_Protected_Type_Declaration | N_Protected_Body);
144 -- Get the number of errors detected by the compiler so far
146 if Lock_Free_Given then
147 Errors_Count := Serious_Errors_Detected;
148 end if;
150 -- Protected type declaration case
152 if Nkind (N) = N_Protected_Type_Declaration then
153 declare
154 Pdef : constant Node_Id := Protected_Definition (N);
155 Priv_Decls : constant List_Id := Private_Declarations (Pdef);
156 Vis_Decls : constant List_Id := Visible_Declarations (Pdef);
157 Decl : Node_Id;
159 begin
160 -- Examine the visible and the private declarations
162 Decl := First (Vis_Decls);
163 while Present (Decl) loop
165 -- Entries and entry families are not allowed by the lock-free
166 -- restrictions.
168 if Nkind (Decl) = N_Entry_Declaration then
169 if Lock_Free_Given then
170 Error_Msg_N
171 ("entry not allowed when Lock_Free given", Decl);
172 else
173 return False;
174 end if;
176 -- Non-elementary parameters in protected procedure are not
177 -- allowed by the lock-free restrictions.
179 elsif Nkind (Decl) = N_Subprogram_Declaration
180 and then
181 Nkind (Specification (Decl)) = N_Procedure_Specification
182 then
183 declare
184 Par_Specs : constant List_Id :=
185 Parameter_Specifications
186 (Specification (Decl));
188 Par : Node_Id;
190 begin
191 Par := First (Par_Specs);
192 while Present (Par) loop
193 if not Is_Elementary_Type
194 (Etype (Defining_Identifier (Par)))
195 then
196 if Lock_Free_Given then
197 Error_Msg_NE
198 ("non-elementary parameter& not allowed "
199 & "when Lock_Free given",
200 Par, Defining_Identifier (Par));
201 else
202 return False;
203 end if;
204 end if;
206 Next (Par);
207 end loop;
208 end;
210 elsif Nkind (Decl) = N_Subprogram_Declaration
211 and then
212 Nkind (Specification (Decl)) = N_Function_Specification
213 and then
214 Nkind (Result_Definition (Specification (Decl)))
215 in N_Has_Entity
216 and then
217 Needs_Secondary_Stack
218 (Entity (Result_Definition (Specification (Decl))))
219 then
220 if Lock_Free_Given then
221 -- Message text is imprecise; "unconstrained" is
222 -- similar to "needs secondary stack" but not identical.
223 Error_Msg_N
224 ("unconstrained function result subtype not allowed "
225 & "when Lock_Free given",
226 Decl);
227 else
228 return False;
229 end if;
230 end if;
232 -- Examine private declarations after visible declarations
234 if No (Next (Decl))
235 and then List_Containing (Decl) = Vis_Decls
236 then
237 Decl := First (Priv_Decls);
238 else
239 Next (Decl);
240 end if;
241 end loop;
242 end;
244 -- Protected body case
246 else
247 Protected_Body_Case : declare
248 Decls : constant List_Id := Declarations (N);
249 Pid : constant Entity_Id := Corresponding_Spec (N);
250 Prot_Typ_Decl : constant Node_Id := Parent (Pid);
251 Prot_Def : constant Node_Id :=
252 Protected_Definition (Prot_Typ_Decl);
253 Priv_Decls : constant List_Id :=
254 Private_Declarations (Prot_Def);
255 Decl : Node_Id;
257 function Satisfies_Lock_Free_Requirements
258 (Sub_Body : Node_Id) return Boolean;
259 -- Return True if protected subprogram body Sub_Body satisfies all
260 -- requirements of a lock-free implementation.
262 --------------------------------------
263 -- Satisfies_Lock_Free_Requirements --
264 --------------------------------------
266 function Satisfies_Lock_Free_Requirements
267 (Sub_Body : Node_Id) return Boolean
269 Comp : Entity_Id := Empty;
270 -- Track the current component which the body references
272 Errors_Count : Nat := 0;
273 -- Errors_Count is a count of errors detected by the compiler
274 -- so far when Lock_Free_Given is True.
276 function Check_Node (N : Node_Id) return Traverse_Result;
277 -- Check that node N meets the lock free restrictions
279 ----------------
280 -- Check_Node --
281 ----------------
283 function Check_Node (N : Node_Id) return Traverse_Result is
284 Kind : constant Node_Kind := Nkind (N);
286 -- The following function belongs in sem_eval ???
288 function Is_Static_Function (Attr : Node_Id) return Boolean;
289 -- Given an attribute reference node Attr, return True if
290 -- Attr denotes a static function according to the rules in
291 -- (RM 4.9 (22)).
293 ------------------------
294 -- Is_Static_Function --
295 ------------------------
297 function Is_Static_Function
298 (Attr : Node_Id) return Boolean
300 Para : Node_Id;
302 begin
303 pragma Assert (Nkind (Attr) = N_Attribute_Reference);
305 case Attribute_Name (Attr) is
306 when Name_Max
307 | Name_Min
308 | Name_Pred
309 | Name_Succ
310 | Name_Value
311 | Name_Wide_Value
312 | Name_Wide_Wide_Value
314 -- A language-defined attribute denotes a static
315 -- function if the prefix denotes a static scalar
316 -- subtype, and if the parameter and result types
317 -- are scalar (RM 4.9 (22)).
319 if Is_Scalar_Type (Etype (Attr))
320 and then Is_Scalar_Type (Etype (Prefix (Attr)))
321 and then
322 Is_OK_Static_Subtype (Etype (Prefix (Attr)))
323 then
324 Para := First (Expressions (Attr));
326 while Present (Para) loop
327 if not Is_Scalar_Type (Etype (Para)) then
328 return False;
329 end if;
331 Next (Para);
332 end loop;
334 return True;
336 else
337 return False;
338 end if;
340 when others =>
341 return False;
342 end case;
343 end Is_Static_Function;
345 -- Start of processing for Check_Node
347 begin
348 -- Allocators restricted
350 if Kind = N_Allocator then
351 if Lock_Free_Given then
352 Error_Msg_N ("allocator not allowed", N);
353 return Skip;
354 end if;
356 return Abandon;
358 -- Aspects Address, Export and Import restricted
360 elsif Kind = N_Aspect_Specification then
361 declare
362 Asp_Name : constant Name_Id :=
363 Chars (Identifier (N));
364 Asp_Id : constant Aspect_Id :=
365 Get_Aspect_Id (Asp_Name);
367 begin
368 if Asp_Id = Aspect_Address or else
369 Asp_Id = Aspect_Export or else
370 Asp_Id = Aspect_Import
371 then
372 Error_Msg_Name_1 := Asp_Name;
374 if Lock_Free_Given then
375 Error_Msg_N ("aspect% not allowed", N);
376 return Skip;
377 end if;
379 return Abandon;
380 end if;
381 end;
383 -- Address attribute definition clause restricted
385 elsif Kind = N_Attribute_Definition_Clause
386 and then Get_Attribute_Id (Chars (N)) =
387 Attribute_Address
388 then
389 Error_Msg_Name_1 := Chars (N);
391 if Lock_Free_Given then
392 if From_Aspect_Specification (N) then
393 Error_Msg_N ("aspect% not allowed", N);
394 else
395 Error_Msg_N ("% clause not allowed", N);
396 end if;
398 return Skip;
399 end if;
401 return Abandon;
403 -- Non-static Attribute references that don't denote a
404 -- static function restricted.
406 elsif Kind = N_Attribute_Reference
407 and then not Is_OK_Static_Expression (N)
408 and then not Is_Static_Function (N)
409 then
410 if Lock_Free_Given then
411 Error_Msg_N
412 ("non-static attribute reference not allowed", N);
413 return Skip;
414 end if;
416 return Abandon;
418 -- Delay statements restricted
420 elsif Kind in N_Delay_Statement then
421 if Lock_Free_Given then
422 Error_Msg_N ("delay not allowed", N);
423 return Skip;
424 end if;
426 return Abandon;
428 -- Dereferences of access values restricted
430 elsif Kind = N_Explicit_Dereference
431 or else (Kind = N_Selected_Component
432 and then Is_Access_Type (Etype (Prefix (N))))
433 then
434 if Lock_Free_Given then
435 Error_Msg_N
436 ("dereference of access value not allowed", N);
437 return Skip;
438 end if;
440 return Abandon;
442 -- Non-static function calls restricted
444 elsif Kind = N_Function_Call
445 and then not Is_OK_Static_Expression (N)
446 then
447 if Lock_Free_Given then
448 Error_Msg_N
449 ("non-static function call not allowed", N);
450 return Skip;
451 end if;
453 return Abandon;
455 -- Goto statements restricted
457 elsif Kind in N_Goto_Statement | N_Goto_When_Statement then
458 if Lock_Free_Given then
459 Error_Msg_N ("goto statement not allowed", N);
460 return Skip;
461 end if;
463 return Abandon;
465 -- References
467 elsif Kind in N_Identifier | N_Expanded_Name
468 and then Present (Entity (N))
469 then
470 declare
471 Id : constant Entity_Id := Entity (N);
472 Sub_Id : constant Entity_Id :=
473 Corresponding_Spec (Sub_Body);
475 begin
476 -- Prohibit references to non-constant entities
477 -- outside the protected subprogram scope.
479 -- References to variables in System.Scalar_Values
480 -- generated because of pragma Initialize_Scalars are
481 -- allowed, because once those variables are
482 -- initialized by the binder-generated code, they
483 -- behave like constants.
485 if Is_Assignable (Id)
486 and then not
487 Scope_Within_Or_Same (Scope (Id), Sub_Id)
488 and then not
489 Scope_Within_Or_Same
490 (Scope (Id),
491 Protected_Body_Subprogram (Sub_Id))
492 and then not
493 (Is_RTU (Scope (Id), System_Scalar_Values)
494 and then not Comes_From_Source (N))
495 then
496 if Lock_Free_Given then
497 Error_Msg_NE
498 ("reference to global variable& not allowed",
499 N, Id);
500 return Skip;
501 end if;
503 return Abandon;
504 end if;
505 end;
507 -- Loop statements restricted
509 elsif Kind = N_Loop_Statement then
510 if Lock_Free_Given then
511 Error_Msg_N ("loop not allowed", N);
512 return Skip;
513 end if;
515 return Abandon;
517 -- Pragmas Export and Import restricted
519 elsif Kind = N_Pragma then
520 declare
521 Prag_Name : constant Name_Id :=
522 Pragma_Name (N);
523 Prag_Id : constant Pragma_Id :=
524 Get_Pragma_Id (Prag_Name);
526 begin
527 if Prag_Id = Pragma_Export
528 or else Prag_Id = Pragma_Import
529 then
530 Error_Msg_Name_1 := Prag_Name;
532 if Lock_Free_Given then
533 if From_Aspect_Specification (N) then
534 Error_Msg_N ("aspect% not allowed", N);
535 else
536 Error_Msg_N ("pragma% not allowed", N);
537 end if;
539 return Skip;
540 end if;
542 return Abandon;
543 end if;
544 end;
546 -- Procedure call statements restricted
548 elsif Kind = N_Procedure_Call_Statement then
549 if Lock_Free_Given then
550 Error_Msg_N ("procedure call not allowed", N);
551 return Skip;
552 end if;
554 return Abandon;
556 -- Quantified expression restricted. Note that we have
557 -- to check the original node as well, since at this
558 -- stage, it may have been rewritten.
560 elsif Kind = N_Quantified_Expression
561 or else
562 Nkind (Original_Node (N)) = N_Quantified_Expression
563 then
564 if Lock_Free_Given then
565 Error_Msg_N
566 ("quantified expression not allowed", N);
567 return Skip;
568 end if;
570 return Abandon;
571 end if;
573 -- A protected subprogram (function or procedure) may
574 -- reference only one component of the protected type, plus
575 -- the type of the component must support atomic operation.
577 if Kind in N_Identifier | N_Expanded_Name
578 and then Present (Entity (N))
579 then
580 declare
581 Id : constant Entity_Id := Entity (N);
582 Comp_Decl : Node_Id;
583 Comp_Id : Entity_Id := Empty;
584 Comp_Type : Entity_Id;
586 begin
587 if Ekind (Id) = E_Component then
588 Comp_Id := Id;
590 elsif Ekind (Id) in E_Constant | E_Variable
591 and then Present (Prival_Link (Id))
592 then
593 Comp_Id := Prival_Link (Id);
594 end if;
596 if Present (Comp_Id) then
597 Comp_Decl := Parent (Comp_Id);
598 Comp_Type := Etype (Comp_Id);
600 if Nkind (Comp_Decl) = N_Component_Declaration
601 and then Is_List_Member (Comp_Decl)
602 and then List_Containing (Comp_Decl) = Priv_Decls
603 then
604 -- Skip generic types since, in that case, we
605 -- will not build a body anyway (in the generic
606 -- template), and the size in the template may
607 -- have a fake value.
609 if not Is_Generic_Type (Comp_Type) then
611 -- Make sure the protected component type has
612 -- size and alignment fields set at this
613 -- point whenever this is possible.
615 Layout_Type (Comp_Type);
617 if not
618 Support_Atomic_Primitives (Comp_Type)
619 then
620 if Lock_Free_Given then
621 Error_Msg_NE
622 ("type of& must support atomic " &
623 "operations",
624 N, Comp_Id);
625 return Skip;
626 end if;
628 return Abandon;
629 end if;
630 end if;
632 -- Check if another protected component has
633 -- already been accessed by the subprogram body.
635 if No (Comp) then
636 Comp := Comp_Id;
638 elsif Comp /= Comp_Id then
639 if Lock_Free_Given then
640 Error_Msg_N
641 ("only one protected component allowed",
643 return Skip;
644 end if;
646 return Abandon;
647 end if;
648 end if;
649 end if;
650 end;
651 end if;
653 return OK;
654 end Check_Node;
656 function Check_All_Nodes is new Traverse_Func (Check_Node);
658 -- Start of processing for Satisfies_Lock_Free_Requirements
660 begin
661 if not Support_Atomic_Primitives_On_Target then
662 if Lock_Free_Given then
663 Error_Msg_N
664 ("Lock_Free aspect requires target support for "
665 & "atomic primitives", N);
666 end if;
667 return False;
668 end if;
670 -- Deal with case where Ceiling_Locking locking policy is
671 -- in effect.
673 if Locking_Policy = 'C' then
674 if Lock_Free_Given then
675 -- Explicit Lock_Free aspect spec overrides
676 -- Ceiling_Locking so we generate a warning.
678 Error_Msg_N
679 ("Lock_Free aspect specification overrides "
680 & "Ceiling_Locking locking policy??", N);
681 else
682 -- If Ceiling_Locking locking policy is in effect, then
683 -- Lock_Free can be explicitly specified but it is
684 -- never the default.
686 return False;
687 end if;
688 end if;
690 -- Get the number of errors detected by the compiler so far
692 if Lock_Free_Given then
693 Errors_Count := Serious_Errors_Detected;
694 end if;
696 if Check_All_Nodes (Sub_Body) = OK
697 and then (not Lock_Free_Given
698 or else Errors_Count = Serious_Errors_Detected)
699 then
700 -- Establish a relation between the subprogram body and the
701 -- unique protected component it references.
703 if Present (Comp) then
704 Lock_Free_Subprogram_Table.Append
705 (Lock_Free_Subprogram'(Sub_Body, Comp));
706 end if;
708 return True;
709 else
710 return False;
711 end if;
712 end Satisfies_Lock_Free_Requirements;
714 -- Start of processing for Protected_Body_Case
716 begin
717 Decl := First (Decls);
718 while Present (Decl) loop
719 if Nkind (Decl) = N_Subprogram_Body
720 and then not Satisfies_Lock_Free_Requirements (Decl)
721 then
722 if Lock_Free_Given then
723 Error_Msg_N
724 ("illegal body when Lock_Free given", Decl);
725 else
726 return False;
727 end if;
728 end if;
730 Next (Decl);
731 end loop;
732 end Protected_Body_Case;
733 end if;
735 -- When Lock_Free is given, check if no error has been detected during
736 -- the process.
738 if Lock_Free_Given
739 and then Errors_Count /= Serious_Errors_Detected
740 then
741 return False;
742 end if;
744 return True;
745 end Allows_Lock_Free_Implementation;
747 -----------------------------
748 -- Analyze_Abort_Statement --
749 -----------------------------
751 procedure Analyze_Abort_Statement (N : Node_Id) is
752 T_Name : Node_Id;
754 begin
755 Tasking_Used := True;
757 T_Name := First (Names (N));
758 while Present (T_Name) loop
759 Analyze (T_Name);
761 if Is_Task_Type (Etype (T_Name))
762 or else (Ada_Version >= Ada_2005
763 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
764 and then Is_Interface (Etype (T_Name))
765 and then Is_Task_Interface (Etype (T_Name)))
766 then
767 Resolve (T_Name);
768 else
769 if Ada_Version >= Ada_2005 then
770 Error_Msg_N ("expect task name or task interface class-wide "
771 & "object for ABORT", T_Name);
772 else
773 Error_Msg_N ("expect task name for ABORT", T_Name);
774 end if;
776 return;
777 end if;
779 Next (T_Name);
780 end loop;
782 Check_Restriction (No_Abort_Statements, N);
783 Check_Potentially_Blocking_Operation (N);
784 end Analyze_Abort_Statement;
786 --------------------------------
787 -- Analyze_Accept_Alternative --
788 --------------------------------
790 procedure Analyze_Accept_Alternative (N : Node_Id) is
791 begin
792 Tasking_Used := True;
794 if Present (Pragmas_Before (N)) then
795 Analyze_List (Pragmas_Before (N));
796 end if;
798 if Present (Condition (N)) then
799 Analyze_And_Resolve (Condition (N), Any_Boolean);
800 end if;
802 Analyze (Accept_Statement (N));
804 if Is_Non_Empty_List (Statements (N)) then
805 Analyze_Statements (Statements (N));
806 end if;
807 end Analyze_Accept_Alternative;
809 ------------------------------
810 -- Analyze_Accept_Statement --
811 ------------------------------
813 procedure Analyze_Accept_Statement (N : Node_Id) is
814 Nam : constant Entity_Id := Entry_Direct_Name (N);
815 Formals : constant List_Id := Parameter_Specifications (N);
816 Index : constant Node_Id := Entry_Index (N);
817 Stats : constant Node_Id := Handled_Statement_Sequence (N);
818 Accept_Id : Entity_Id;
819 Entry_Nam : Entity_Id;
820 E : Entity_Id;
821 Kind : Entity_Kind;
822 Task_Nam : Entity_Id := Empty; -- initialize to prevent warning
824 begin
825 Tasking_Used := True;
827 -- Entry name is initialized to Any_Id. It should get reset to the
828 -- matching entry entity. An error is signalled if it is not reset.
830 Entry_Nam := Any_Id;
832 for J in reverse 0 .. Scope_Stack.Last loop
833 Task_Nam := Scope_Stack.Table (J).Entity;
834 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
835 Kind := Ekind (Task_Nam);
837 if Kind /= E_Block and then Kind /= E_Loop
838 and then not Is_Entry (Task_Nam)
839 then
840 Error_Msg_N ("enclosing body of ACCEPT must be a task", N);
841 return;
842 end if;
843 end loop;
845 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
846 Error_Msg_N ("invalid context for ACCEPT statement", N);
847 return;
848 end if;
850 -- In order to process the parameters, we create a defining identifier
851 -- that can be used as the name of the scope. The name of the accept
852 -- statement itself is not a defining identifier, and we cannot use
853 -- its name directly because the task may have any number of accept
854 -- statements for the same entry.
856 if Present (Index) then
857 Accept_Id := New_Internal_Entity
858 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
859 else
860 Accept_Id := New_Internal_Entity
861 (E_Entry, Current_Scope, Sloc (N), 'E');
862 end if;
864 Set_Etype (Accept_Id, Standard_Void_Type);
865 Set_Accept_Address (Accept_Id, New_Elmt_List);
867 if Present (Formals) then
868 Push_Scope (Accept_Id);
869 Process_Formals (Formals, N);
870 Create_Extra_Formals (Accept_Id);
871 End_Scope;
872 end if;
874 -- We set the default expressions processed flag because we don't need
875 -- default expression functions. This is really more like body entity
876 -- than a spec entity anyway.
878 Set_Default_Expressions_Processed (Accept_Id);
880 E := First_Entity (Etype (Task_Nam));
881 while Present (E) loop
882 if Chars (E) = Chars (Nam)
883 and then Ekind (E) = Ekind (Accept_Id)
884 and then Type_Conformant (Accept_Id, E)
885 then
886 Entry_Nam := E;
887 exit;
888 end if;
890 Next_Entity (E);
891 end loop;
893 if Entry_Nam = Any_Id then
894 Error_Msg_N ("no entry declaration matches ACCEPT statement", N);
895 return;
896 else
897 Set_Entity (Nam, Entry_Nam);
898 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
899 Style.Check_Identifier (Nam, Entry_Nam);
900 end if;
902 -- Verify that the entry is not hidden by a procedure declared in the
903 -- current block (pathological but possible).
905 if Current_Scope /= Task_Nam then
906 declare
907 E1 : Entity_Id;
909 begin
910 E1 := First_Entity (Current_Scope);
911 while Present (E1) loop
912 if Ekind (E1) = E_Procedure
913 and then Chars (E1) = Chars (Entry_Nam)
914 and then Type_Conformant (E1, Entry_Nam)
915 then
916 Error_Msg_N ("entry name is not visible", N);
917 end if;
919 Next_Entity (E1);
920 end loop;
921 end;
922 end if;
924 Set_Convention (Accept_Id, Convention (Entry_Nam));
925 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
927 for J in reverse 0 .. Scope_Stack.Last loop
928 exit when Task_Nam = Scope_Stack.Table (J).Entity;
930 if Entry_Nam = Scope_Stack.Table (J).Entity then
931 Error_Msg_N
932 ("duplicate ACCEPT statement for same entry (RM 9.5.2 (15))", N);
934 -- Do not continue analysis of accept statement, to prevent
935 -- cascaded errors.
937 return;
938 end if;
939 end loop;
941 declare
942 P : Node_Id := N;
943 begin
944 loop
945 P := Parent (P);
946 case Nkind (P) is
947 when N_Compilation_Unit
948 | N_Task_Body
950 exit;
952 when N_Asynchronous_Select =>
953 Error_Msg_N
954 ("ACCEPT statement not allowed within an "
955 & "asynchronous SELECT inner to the enclosing task body",
957 exit;
959 when others =>
960 null;
961 end case;
962 end loop;
963 end;
965 if Ekind (Entry_Nam) = E_Entry_Family then
966 if No (Index) then
967 Error_Msg_N ("missing entry index in accept for entry family", N);
968 else
969 Analyze_And_Resolve (Index, Entry_Index_Type (Entry_Nam));
970 Apply_Scalar_Range_Check (Index, Entry_Index_Type (Entry_Nam));
971 end if;
973 elsif Present (Index) then
974 Error_Msg_N ("invalid entry index in accept for simple entry", N);
975 end if;
977 -- If label declarations present, analyze them. They are declared in the
978 -- enclosing task, but their enclosing scope is the entry itself, so
979 -- that goto's to the label are recognized as local to the accept.
981 if Present (Declarations (N)) then
982 declare
983 Decl : Node_Id;
984 Id : Entity_Id;
986 begin
987 Decl := First (Declarations (N));
988 while Present (Decl) loop
989 Analyze (Decl);
991 pragma Assert
992 (Nkind (Decl) = N_Implicit_Label_Declaration);
994 Id := Defining_Identifier (Decl);
995 Set_Enclosing_Scope (Id, Entry_Nam);
996 Next (Decl);
997 end loop;
998 end;
999 end if;
1001 -- If statements are present, they must be analyzed in the context of
1002 -- the entry, so that references to formals are correctly resolved. We
1003 -- also have to add the declarations that are required by the expansion
1004 -- of the accept statement in this case if expansion active.
1006 -- In the case of a select alternative of a selective accept, the
1007 -- expander references the address declaration even if there is no
1008 -- statement list.
1010 -- We also need to create the renaming declarations for the local
1011 -- variables that will replace references to the formals within the
1012 -- accept statement.
1014 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
1016 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
1017 -- fields on all entry formals (this loop ignores all other entities).
1018 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
1019 -- well, so that we can post accurate warnings on each accept statement
1020 -- for the same entry.
1022 E := First_Entity (Entry_Nam);
1023 while Present (E) loop
1024 if Is_Formal (E) then
1025 Set_Never_Set_In_Source (E, True);
1026 Set_Is_True_Constant (E, False);
1027 Set_Current_Value (E, Empty);
1028 Set_Referenced (E, False);
1029 Set_Referenced_As_LHS (E, False);
1030 Set_Referenced_As_Out_Parameter (E, False);
1031 Set_Has_Pragma_Unreferenced (E, False);
1032 end if;
1034 Next_Entity (E);
1035 end loop;
1037 -- Analyze statements if present
1039 if Present (Stats) then
1040 Push_Scope (Entry_Nam);
1041 Install_Declarations (Entry_Nam);
1043 Set_Actual_Subtypes (N, Current_Scope);
1045 Analyze (Stats);
1046 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
1047 End_Scope;
1048 end if;
1050 -- Some warning checks
1052 Check_Potentially_Blocking_Operation (N);
1053 Check_References (Entry_Nam, N);
1054 Set_Entry_Accepted (Entry_Nam);
1055 end Analyze_Accept_Statement;
1057 ---------------------------------
1058 -- Analyze_Asynchronous_Select --
1059 ---------------------------------
1061 procedure Analyze_Asynchronous_Select (N : Node_Id) is
1062 Is_Disp_Select : Boolean := False;
1063 Trigger : Node_Id;
1065 begin
1066 Tasking_Used := True;
1067 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
1068 Check_Restriction (No_Select_Statements, N);
1070 if Ada_Version >= Ada_2005 then
1071 Trigger := Triggering_Statement (Triggering_Alternative (N));
1073 Analyze (Trigger);
1075 -- Ada 2005 (AI-345): Check for a potential dispatching select
1077 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1078 end if;
1080 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
1081 -- select will have to duplicate the triggering statements. Postpone
1082 -- the analysis of the statements till expansion. Analyze only if the
1083 -- expander is disabled in order to catch any semantic errors.
1085 if Is_Disp_Select then
1086 if not Expander_Active then
1087 Analyze_Statements (Statements (Abortable_Part (N)));
1088 Analyze (Triggering_Alternative (N));
1089 end if;
1091 -- Analyze the statements. We analyze statements in the abortable part,
1092 -- because this is the section that is executed first, and that way our
1093 -- remembering of saved values and checks is accurate.
1095 else
1096 Analyze_Statements (Statements (Abortable_Part (N)));
1097 Analyze (Triggering_Alternative (N));
1098 end if;
1099 end Analyze_Asynchronous_Select;
1101 ------------------------------------
1102 -- Analyze_Conditional_Entry_Call --
1103 ------------------------------------
1105 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
1106 Trigger : constant Node_Id :=
1107 Entry_Call_Statement (Entry_Call_Alternative (N));
1108 Is_Disp_Select : Boolean := False;
1110 begin
1111 Tasking_Used := True;
1112 Check_Restriction (No_Select_Statements, N);
1114 -- Ada 2005 (AI-345): The trigger may be a dispatching call
1116 if Ada_Version >= Ada_2005 then
1117 Analyze (Trigger);
1118 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1119 end if;
1121 if List_Length (Else_Statements (N)) = 1
1122 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
1123 then
1124 Error_Msg_N
1125 ("suspicious form of conditional entry call??!", N);
1126 Error_Msg_N
1127 ("\`SELECT OR` may be intended rather than `SELECT ELSE`??!", N);
1128 end if;
1130 -- Postpone the analysis of the statements till expansion. Analyze only
1131 -- if the expander is disabled in order to catch any semantic errors.
1133 if Is_Disp_Select then
1134 if not Expander_Active then
1135 Analyze (Entry_Call_Alternative (N));
1136 Analyze_Statements (Else_Statements (N));
1137 end if;
1139 -- Regular select analysis
1141 else
1142 Analyze (Entry_Call_Alternative (N));
1143 Analyze_Statements (Else_Statements (N));
1144 end if;
1145 end Analyze_Conditional_Entry_Call;
1147 --------------------------------
1148 -- Analyze_Delay_Alternative --
1149 --------------------------------
1151 procedure Analyze_Delay_Alternative (N : Node_Id) is
1152 Expr : Node_Id;
1153 Typ : Entity_Id;
1155 begin
1156 Tasking_Used := True;
1157 Check_Restriction (No_Delay, N);
1159 if Present (Pragmas_Before (N)) then
1160 Analyze_List (Pragmas_Before (N));
1161 end if;
1163 if Nkind (Parent (N)) in N_Selective_Accept | N_Timed_Entry_Call then
1164 Expr := Expression (Delay_Statement (N));
1166 -- Defer full analysis until the statement is expanded, to insure
1167 -- that generated code does not move past the guard. The delay
1168 -- expression is only evaluated if the guard is open.
1170 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
1171 Preanalyze_And_Resolve (Expr, Standard_Duration);
1172 else
1173 Preanalyze_And_Resolve (Expr);
1174 end if;
1176 Typ := First_Subtype (Etype (Expr));
1178 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
1179 and then not Is_RTE (Typ, RO_CA_Time)
1180 and then not Is_RTE (Typ, RO_RT_Time)
1181 then
1182 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
1183 end if;
1185 Check_Restriction (No_Fixed_Point, Expr);
1187 else
1188 Analyze (Delay_Statement (N));
1189 end if;
1191 if Present (Condition (N)) then
1192 Analyze_And_Resolve (Condition (N), Any_Boolean);
1193 end if;
1195 if Is_Non_Empty_List (Statements (N)) then
1196 Analyze_Statements (Statements (N));
1197 end if;
1198 end Analyze_Delay_Alternative;
1200 ----------------------------
1201 -- Analyze_Delay_Relative --
1202 ----------------------------
1204 procedure Analyze_Delay_Relative (N : Node_Id) is
1205 E : constant Node_Id := Expression (N);
1207 begin
1208 Tasking_Used := True;
1209 Check_Restriction (No_Relative_Delay, N);
1210 Check_Restriction (No_Delay, N);
1211 Check_Potentially_Blocking_Operation (N);
1212 Analyze_And_Resolve (E, Standard_Duration);
1213 Check_Restriction (No_Fixed_Point, E);
1215 -- In SPARK mode the relative delay statement introduces an implicit
1216 -- dependency on the Ada.Real_Time.Clock_Time abstract state, so we must
1217 -- force the loading of the Ada.Real_Time package.
1219 if GNATprove_Mode then
1220 SPARK_Implicit_Load (RO_RT_Time);
1221 end if;
1222 end Analyze_Delay_Relative;
1224 -------------------------
1225 -- Analyze_Delay_Until --
1226 -------------------------
1228 procedure Analyze_Delay_Until (N : Node_Id) is
1229 E : constant Node_Id := Expression (N);
1230 Typ : Entity_Id;
1232 begin
1233 Tasking_Used := True;
1234 Check_Restriction (No_Delay, N);
1235 Check_Potentially_Blocking_Operation (N);
1236 Analyze_And_Resolve (E);
1237 Typ := First_Subtype (Etype (E));
1239 if not Is_RTE (Typ, RO_CA_Time) and then
1240 not Is_RTE (Typ, RO_RT_Time)
1241 then
1242 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
1243 end if;
1244 end Analyze_Delay_Until;
1246 ------------------------
1247 -- Analyze_Entry_Body --
1248 ------------------------
1250 procedure Analyze_Entry_Body (N : Node_Id) is
1251 Id : constant Entity_Id := Defining_Identifier (N);
1252 Decls : constant List_Id := Declarations (N);
1253 Stats : constant Node_Id := Handled_Statement_Sequence (N);
1254 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1255 P_Type : constant Entity_Id := Current_Scope;
1256 E : Entity_Id;
1257 Entry_Name : Entity_Id;
1259 begin
1260 -- An entry body freezes the contract of the nearest enclosing package
1261 -- body and all other contracts encountered in the same declarative part
1262 -- up to and excluding the entry body. This ensures that any annotations
1263 -- referenced by the contract of an entry or subprogram body declared
1264 -- within the current protected body are available.
1266 Freeze_Previous_Contracts (N);
1268 Tasking_Used := True;
1270 -- Entry_Name is initialized to Any_Id. It should get reset to the
1271 -- matching entry entity. An error is signalled if it is not reset.
1273 Entry_Name := Any_Id;
1275 Analyze (Formals);
1277 if Present (Entry_Index_Specification (Formals)) then
1278 Mutate_Ekind (Id, E_Entry_Family);
1279 else
1280 Mutate_Ekind (Id, E_Entry);
1281 end if;
1283 Set_Etype (Id, Standard_Void_Type);
1284 Set_Scope (Id, Current_Scope);
1285 Set_Accept_Address (Id, New_Elmt_List);
1287 -- Set the SPARK_Mode from the current context (may be overwritten later
1288 -- with an explicit pragma).
1290 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1291 Set_SPARK_Pragma_Inherited (Id);
1293 -- Analyze any aspect specifications that appear on the entry body
1295 if Has_Aspects (N) then
1296 Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
1297 end if;
1299 E := First_Entity (P_Type);
1300 while Present (E) loop
1301 if Chars (E) = Chars (Id)
1302 and then Ekind (E) = Ekind (Id)
1303 and then Type_Conformant (Id, E)
1304 then
1305 Entry_Name := E;
1306 Set_Convention (Id, Convention (E));
1307 Set_Corresponding_Body (Parent (E), Id);
1308 Set_Corresponding_Spec (N, E);
1309 Check_Fully_Conformant (Id, E, N);
1311 if Ekind (Id) = E_Entry_Family then
1312 if not Fully_Conformant_Discrete_Subtypes (
1313 Discrete_Subtype_Definition (Parent (E)),
1314 Discrete_Subtype_Definition
1315 (Entry_Index_Specification (Formals)))
1316 then
1317 Error_Msg_N
1318 ("index not fully conformant with previous declaration",
1319 Discrete_Subtype_Definition
1320 (Entry_Index_Specification (Formals)));
1322 else
1323 -- The elaboration of the entry body does not recompute the
1324 -- bounds of the index, which may have side effects. Inherit
1325 -- the bounds from the entry declaration. This is critical
1326 -- if the entry has a per-object constraint. If a bound is
1327 -- given by a discriminant, it must be reanalyzed in order
1328 -- to capture the discriminal of the current entry, rather
1329 -- than that of the protected type.
1331 declare
1332 Index_Spec : constant Node_Id :=
1333 Entry_Index_Specification (Formals);
1335 Def : constant Node_Id :=
1336 New_Copy_Tree
1337 (Discrete_Subtype_Definition (Parent (E)));
1339 begin
1340 if Nkind
1341 (Original_Node
1342 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
1343 then
1344 Set_Etype (Def, Empty);
1345 Set_Analyzed (Def, False);
1347 -- Keep the original subtree to ensure a properly
1348 -- formed tree.
1350 Rewrite
1351 (Discrete_Subtype_Definition (Index_Spec), Def);
1353 Set_Analyzed (Low_Bound (Def), False);
1354 Set_Analyzed (High_Bound (Def), False);
1356 if Denotes_Discriminant (Low_Bound (Def)) then
1357 Set_Entity (Low_Bound (Def), Empty);
1358 end if;
1360 if Denotes_Discriminant (High_Bound (Def)) then
1361 Set_Entity (High_Bound (Def), Empty);
1362 end if;
1364 Analyze (Def);
1365 Make_Index (Def, Index_Spec);
1366 Set_Etype
1367 (Defining_Identifier (Index_Spec), Etype (Def));
1368 end if;
1369 end;
1370 end if;
1371 end if;
1373 exit;
1374 end if;
1376 Next_Entity (E);
1377 end loop;
1379 if Entry_Name = Any_Id then
1380 Error_Msg_N ("no entry declaration matches entry body", N);
1381 return;
1383 elsif Has_Completion (Entry_Name) then
1384 Error_Msg_N ("duplicate entry body", N);
1385 return;
1387 else
1388 Set_Has_Completion (Entry_Name);
1389 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
1390 Style.Check_Identifier (Id, Entry_Name);
1391 end if;
1393 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
1394 Push_Scope (Entry_Name);
1396 Install_Declarations (Entry_Name);
1397 Set_Actual_Subtypes (N, Current_Scope);
1399 -- The entity for the protected subprogram corresponding to the entry
1400 -- has been created. We retain the name of this entity in the entry
1401 -- body, for use when the corresponding subprogram body is created.
1402 -- Note that entry bodies have no Corresponding_Spec, and there is no
1403 -- easy link back in the tree between the entry body and the entity for
1404 -- the entry itself, which is why we must propagate some attributes
1405 -- explicitly from spec to body.
1407 Set_Protected_Body_Subprogram
1408 (Id, Protected_Body_Subprogram (Entry_Name));
1410 Set_Entry_Parameters_Type
1411 (Id, Entry_Parameters_Type (Entry_Name));
1413 -- Add a declaration for the Protection object, renaming declarations
1414 -- for the discriminals and privals and finally a declaration for the
1415 -- entry family index (if applicable).
1417 if Expander_Active
1418 and then Is_Protected_Type (P_Type)
1419 then
1420 Install_Private_Data_Declarations
1421 (Sloc (N), Entry_Name, P_Type, N, Decls);
1422 end if;
1424 if Present (Decls) then
1425 Analyze_Declarations (Decls);
1426 Inspect_Deferred_Constant_Completion (Decls);
1427 end if;
1429 -- Process the contract of the subprogram body after all declarations
1430 -- have been analyzed. This ensures that any contract-related pragmas
1431 -- are available through the N_Contract node of the body.
1433 Analyze_Entry_Or_Subprogram_Body_Contract (Id);
1435 if Present (Stats) then
1436 Analyze (Stats);
1437 end if;
1439 -- Check for unreferenced variables etc. Before the Check_References
1440 -- call, we transfer Never_Set_In_Source and Referenced flags from
1441 -- parameters in the spec to the corresponding entities in the body,
1442 -- since we want the warnings on the body entities. Note that we do not
1443 -- have to transfer Referenced_As_LHS, since that flag can only be set
1444 -- for simple variables, but we include Has_Pragma_Unreferenced,
1445 -- which may have been specified for a formal in the body.
1447 -- At the same time, we set the flags on the spec entities to suppress
1448 -- any warnings on the spec formals, since we also scan the spec.
1449 -- Finally, we propagate the Entry_Component attribute to the body
1450 -- formals, for use in the renaming declarations created later for the
1451 -- formals (see exp_ch9.Add_Formal_Renamings).
1453 declare
1454 E1 : Entity_Id;
1455 E2 : Entity_Id;
1457 begin
1458 E1 := First_Entity (Entry_Name);
1459 while Present (E1) loop
1460 E2 := First_Entity (Id);
1461 while Present (E2) loop
1462 exit when Chars (E1) = Chars (E2);
1463 Next_Entity (E2);
1464 end loop;
1466 -- If no matching body entity, then we already had a detected
1467 -- error of some kind, so just don't worry about these warnings.
1469 if No (E2) then
1470 goto Continue;
1471 end if;
1473 if Ekind (E1) = E_Out_Parameter then
1474 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1475 Set_Never_Set_In_Source (E1, False);
1476 end if;
1478 Set_Referenced (E2, Referenced (E1));
1479 Set_Referenced (E1);
1480 Set_Has_Pragma_Unreferenced (E2, Has_Pragma_Unreferenced (E1));
1481 Set_Entry_Component (E2, Entry_Component (E1));
1483 <<Continue>>
1484 Next_Entity (E1);
1485 end loop;
1487 Check_References (Id);
1488 end;
1490 -- We still need to check references for the spec, since objects
1491 -- declared in the body are chained (in the First_Entity sense) to
1492 -- the spec rather than the body in the case of entries.
1494 Check_References (Entry_Name);
1496 -- Process the end label, and terminate the scope
1498 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
1499 Update_Use_Clause_Chain;
1500 End_Scope;
1502 -- If this is an entry family, remove the loop created to provide
1503 -- a scope for the entry index.
1505 if Ekind (Id) = E_Entry_Family
1506 and then Present (Entry_Index_Specification (Formals))
1507 then
1508 End_Scope;
1509 end if;
1510 end Analyze_Entry_Body;
1512 ------------------------------------
1513 -- Analyze_Entry_Body_Formal_Part --
1514 ------------------------------------
1516 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
1517 Id : constant Entity_Id := Defining_Identifier (Parent (N));
1518 Index : constant Node_Id := Entry_Index_Specification (N);
1519 Formals : constant List_Id := Parameter_Specifications (N);
1521 begin
1522 Tasking_Used := True;
1524 if Present (Index) then
1525 Analyze (Index);
1527 -- The entry index functions like a loop variable, thus it is known
1528 -- to have a valid value.
1530 Set_Is_Known_Valid (Defining_Identifier (Index));
1531 end if;
1533 if Present (Formals) then
1534 Set_Scope (Id, Current_Scope);
1535 Push_Scope (Id);
1536 Process_Formals (Formals, Parent (N));
1537 End_Scope;
1538 end if;
1539 end Analyze_Entry_Body_Formal_Part;
1541 ------------------------------------
1542 -- Analyze_Entry_Call_Alternative --
1543 ------------------------------------
1545 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
1546 Call : constant Node_Id := Entry_Call_Statement (N);
1548 begin
1549 Tasking_Used := True;
1551 if Present (Pragmas_Before (N)) then
1552 Analyze_List (Pragmas_Before (N));
1553 end if;
1555 if Nkind (Call) = N_Attribute_Reference then
1557 -- Possibly a stream attribute, but definitely illegal. Other
1558 -- illegalities, such as procedure calls, are diagnosed after
1559 -- resolution.
1561 Error_Msg_N ("entry call alternative requires an entry call", Call);
1562 return;
1563 end if;
1565 Analyze (Call);
1567 -- An indirect call in this context is illegal. A procedure call that
1568 -- does not involve a renaming of an entry is illegal as well, but this
1569 -- and other semantic errors are caught during resolution.
1571 if Nkind (Call) = N_Explicit_Dereference then
1572 Error_Msg_N
1573 ("entry call or dispatching primitive of interface required", N);
1574 end if;
1576 if Is_Non_Empty_List (Statements (N)) then
1577 Analyze_Statements (Statements (N));
1578 end if;
1579 end Analyze_Entry_Call_Alternative;
1581 -------------------------------
1582 -- Analyze_Entry_Declaration --
1583 -------------------------------
1585 procedure Analyze_Entry_Declaration (N : Node_Id) is
1586 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
1587 Def_Id : constant Entity_Id := Defining_Identifier (N);
1588 Formals : constant List_Id := Parameter_Specifications (N);
1590 begin
1591 Generate_Definition (Def_Id);
1593 Tasking_Used := True;
1595 -- Case of no discrete subtype definition
1597 if No (D_Sdef) then
1598 Mutate_Ekind (Def_Id, E_Entry);
1600 -- Processing for discrete subtype definition present
1602 else
1603 Enter_Name (Def_Id);
1604 Mutate_Ekind (Def_Id, E_Entry_Family);
1605 Analyze (D_Sdef);
1606 Make_Index (D_Sdef, N, Def_Id);
1608 -- Check subtype with predicate in entry family
1610 Bad_Predicated_Subtype_Use
1611 ("subtype& has predicate, not allowed in entry family",
1612 D_Sdef, Etype (D_Sdef));
1614 -- Check entry family static bounds outside allowed limits
1616 -- Note: originally this check was not performed here, but in that
1617 -- case the check happens deep in the expander, and the message is
1618 -- posted at the wrong location, and omitted in -gnatc mode.
1619 -- If the type of the entry index is a generic formal, no check
1620 -- is possible. In an instance, the check is not static and a run-
1621 -- time exception will be raised if the bounds are unreasonable.
1623 declare
1624 PEI : constant Entity_Id := RTE (RE_Protected_Entry_Index);
1625 LB : constant Uint := Expr_Value (Type_Low_Bound (PEI));
1626 UB : constant Uint := Expr_Value (Type_High_Bound (PEI));
1628 LBR : Node_Id;
1629 UBR : Node_Id;
1631 begin
1633 -- No bounds checking if the type is generic or if previous error.
1634 -- In an instance the check is dynamic.
1636 if Is_Generic_Type (Etype (D_Sdef))
1637 or else In_Instance
1638 or else Error_Posted (D_Sdef)
1639 then
1640 goto Skip_LB;
1642 elsif Nkind (D_Sdef) = N_Range then
1643 LBR := Low_Bound (D_Sdef);
1645 elsif Is_Entity_Name (D_Sdef)
1646 and then Is_Type (Entity (D_Sdef))
1647 then
1648 LBR := Type_Low_Bound (Entity (D_Sdef));
1650 else
1651 goto Skip_LB;
1652 end if;
1654 if Is_OK_Static_Expression (LBR)
1655 and then Expr_Value (LBR) < LB
1656 then
1657 Error_Msg_Uint_1 := LB;
1658 Error_Msg_N ("entry family low bound must be '>'= ^!", D_Sdef);
1659 end if;
1661 <<Skip_LB>>
1662 if Is_Generic_Type (Etype (D_Sdef))
1663 or else In_Instance
1664 or else Error_Posted (D_Sdef)
1665 then
1666 goto Skip_UB;
1668 elsif Nkind (D_Sdef) = N_Range then
1669 UBR := High_Bound (D_Sdef);
1671 elsif Is_Entity_Name (D_Sdef)
1672 and then Is_Type (Entity (D_Sdef))
1673 then
1674 UBR := Type_High_Bound (Entity (D_Sdef));
1676 else
1677 goto Skip_UB;
1678 end if;
1680 if Is_OK_Static_Expression (UBR)
1681 and then Expr_Value (UBR) > UB
1682 then
1683 Error_Msg_Uint_1 := UB;
1684 Error_Msg_N ("entry family high bound must be '<'= ^!", D_Sdef);
1685 end if;
1687 <<Skip_UB>>
1688 null;
1689 end;
1690 end if;
1692 -- Decorate Def_Id
1694 Set_Etype (Def_Id, Standard_Void_Type);
1695 Set_Convention (Def_Id, Convention_Entry);
1696 Set_Accept_Address (Def_Id, New_Elmt_List);
1698 -- Set the SPARK_Mode from the current context (may be overwritten later
1699 -- with an explicit pragma). Task entries are excluded because they are
1700 -- not completed by entry bodies.
1702 if Ekind (Current_Scope) = E_Protected_Type then
1703 Set_SPARK_Pragma (Def_Id, SPARK_Mode_Pragma);
1704 Set_SPARK_Pragma_Inherited (Def_Id);
1705 end if;
1707 -- Preserve relevant elaboration-related attributes of the context which
1708 -- are no longer available or very expensive to recompute once analysis,
1709 -- resolution, and expansion are over.
1711 Mark_Elaboration_Attributes
1712 (N_Id => Def_Id,
1713 Checks => True,
1714 Warnings => True);
1716 -- Process formals
1718 if Present (Formals) then
1719 Set_Scope (Def_Id, Current_Scope);
1720 Push_Scope (Def_Id);
1721 Process_Formals (Formals, N);
1722 Create_Extra_Formals (Def_Id);
1723 End_Scope;
1724 end if;
1726 if Ekind (Def_Id) = E_Entry then
1727 New_Overloaded_Entity (Def_Id);
1728 end if;
1730 Generate_Reference_To_Formals (Def_Id);
1732 if Has_Aspects (N) then
1733 Analyze_Aspect_Specifications (N, Def_Id);
1734 end if;
1735 end Analyze_Entry_Declaration;
1737 ---------------------------------------
1738 -- Analyze_Entry_Index_Specification --
1739 ---------------------------------------
1741 -- The Defining_Identifier of the entry index specification is local to the
1742 -- entry body, but it must be available in the entry barrier which is
1743 -- evaluated outside of the entry body. The index is eventually renamed as
1744 -- a run-time object, so its visibility is strictly a front-end concern. In
1745 -- order to make it available to the barrier, we create an additional
1746 -- scope, as for a loop, whose only declaration is the index name. This
1747 -- loop is not attached to the tree and does not appear as an entity local
1748 -- to the protected type, so its existence need only be known to routines
1749 -- that process entry families.
1751 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
1752 Iden : constant Node_Id := Defining_Identifier (N);
1753 Def : constant Node_Id := Discrete_Subtype_Definition (N);
1754 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L');
1756 begin
1757 Tasking_Used := True;
1758 Analyze (Def);
1760 -- There is no elaboration of the entry index specification. Therefore,
1761 -- if the index is a range, it is not resolved and expanded, but the
1762 -- bounds are inherited from the entry declaration, and reanalyzed.
1763 -- See Analyze_Entry_Body.
1765 if Nkind (Def) /= N_Range then
1766 Make_Index (Def, N);
1767 end if;
1769 Mutate_Ekind (Loop_Id, E_Loop);
1770 Set_Scope (Loop_Id, Current_Scope);
1771 Push_Scope (Loop_Id);
1772 Enter_Name (Iden);
1773 Mutate_Ekind (Iden, E_Entry_Index_Parameter);
1774 Set_Etype (Iden, Etype (Def));
1775 end Analyze_Entry_Index_Specification;
1777 ----------------------------
1778 -- Analyze_Protected_Body --
1779 ----------------------------
1781 procedure Analyze_Protected_Body (N : Node_Id) is
1782 Body_Id : constant Entity_Id := Defining_Identifier (N);
1783 Last_E : Entity_Id;
1785 Spec_Id : Entity_Id;
1786 -- This is initially the entity of the protected object or protected
1787 -- type involved, but is replaced by the protected type always in the
1788 -- case of a single protected declaration, since this is the proper
1789 -- scope to be used.
1791 Ref_Id : Entity_Id;
1792 -- This is the entity of the protected object or protected type
1793 -- involved, and is the entity used for cross-reference purposes (it
1794 -- differs from Spec_Id in the case of a single protected object, since
1795 -- Spec_Id is set to the protected type in this case).
1797 function Lock_Free_Disabled return Boolean;
1798 -- This routine returns False if the protected object has a Lock_Free
1799 -- aspect specification or a Lock_Free pragma that turns off the
1800 -- lock-free implementation (e.g. whose expression is False).
1802 ------------------------
1803 -- Lock_Free_Disabled --
1804 ------------------------
1806 function Lock_Free_Disabled return Boolean is
1807 Ritem : constant Node_Id :=
1808 Get_Rep_Item
1809 (Spec_Id, Name_Lock_Free, Check_Parents => False);
1811 begin
1812 if Present (Ritem) then
1814 -- Pragma with one argument
1816 if Nkind (Ritem) = N_Pragma
1817 and then Present (Pragma_Argument_Associations (Ritem))
1818 then
1819 return
1820 Is_False
1821 (Static_Boolean
1822 (Expression
1823 (First (Pragma_Argument_Associations (Ritem)))));
1825 -- Aspect Specification with expression present
1827 elsif Nkind (Ritem) = N_Aspect_Specification
1828 and then Present (Expression (Ritem))
1829 then
1830 return Is_False (Static_Boolean (Expression (Ritem)));
1832 -- Otherwise, return False
1834 else
1835 return False;
1836 end if;
1837 end if;
1839 return False;
1840 end Lock_Free_Disabled;
1842 -- Start of processing for Analyze_Protected_Body
1844 begin
1845 -- A protected body freezes the contract of the nearest enclosing
1846 -- package body and all other contracts encountered in the same
1847 -- declarative part up to and excluding the protected body. This
1848 -- ensures that any annotations referenced by the contract of an
1849 -- entry or subprogram body declared within the current protected
1850 -- body are available.
1852 Freeze_Previous_Contracts (N);
1854 Tasking_Used := True;
1855 Mutate_Ekind (Body_Id, E_Protected_Body);
1856 Set_Etype (Body_Id, Standard_Void_Type);
1857 Spec_Id := Find_Concurrent_Spec (Body_Id);
1859 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Protected_Type then
1860 null;
1862 elsif Present (Spec_Id)
1863 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1864 and then not Comes_From_Source (Etype (Spec_Id))
1865 then
1866 null;
1868 else
1869 Error_Msg_N ("missing specification for protected body", Body_Id);
1870 return;
1871 end if;
1873 Ref_Id := Spec_Id;
1874 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1875 Style.Check_Identifier (Body_Id, Spec_Id);
1877 -- The declarations are always attached to the type
1879 if Ekind (Spec_Id) /= E_Protected_Type then
1880 Spec_Id := Etype (Spec_Id);
1881 end if;
1883 if Has_Aspects (N) then
1884 Analyze_Aspect_Specifications (N, Body_Id);
1885 end if;
1887 Push_Scope (Spec_Id);
1888 Set_Corresponding_Spec (N, Spec_Id);
1889 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1890 Set_Has_Completion (Spec_Id);
1891 Install_Declarations (Spec_Id);
1892 Expand_Protected_Body_Declarations (N, Spec_Id);
1893 Last_E := Last_Entity (Spec_Id);
1895 Analyze_Declarations (Declarations (N));
1897 -- For visibility purposes, all entities in the body are private. Set
1898 -- First_Private_Entity accordingly, if there was no private part in the
1899 -- protected declaration.
1901 if No (First_Private_Entity (Spec_Id)) then
1902 if Present (Last_E) then
1903 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1904 else
1905 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1906 end if;
1907 end if;
1909 Check_Completion (Body_Id);
1910 Check_References (Spec_Id);
1911 Process_End_Label (N, 't', Ref_Id);
1912 Update_Use_Clause_Chain;
1913 End_Scope;
1915 -- When a Lock_Free aspect specification/pragma forces the lock-free
1916 -- implementation, verify the protected body meets all the restrictions,
1917 -- otherwise Allows_Lock_Free_Implementation issues an error message.
1919 if Uses_Lock_Free (Spec_Id) then
1920 if not Allows_Lock_Free_Implementation (N, True) then
1921 return;
1922 end if;
1924 -- In other cases, if there is no aspect specification/pragma that
1925 -- disables the lock-free implementation, check both the protected
1926 -- declaration and body satisfy the lock-free restrictions.
1928 elsif not Lock_Free_Disabled
1929 and then Allows_Lock_Free_Implementation (Parent (Spec_Id))
1930 and then Allows_Lock_Free_Implementation (N)
1931 then
1932 Set_Uses_Lock_Free (Spec_Id);
1933 end if;
1934 end Analyze_Protected_Body;
1936 ----------------------------------
1937 -- Analyze_Protected_Definition --
1938 ----------------------------------
1940 procedure Analyze_Protected_Definition (N : Node_Id) is
1941 procedure Undelay_Itypes (T : Entity_Id);
1942 -- Itypes created for the private components of a protected type
1943 -- do not receive freeze nodes, because there is no scope in which
1944 -- they can be elaborated, and they can depend on discriminants of
1945 -- the enclosed protected type. Given that the components can be
1946 -- composite types with inner components, we traverse recursively
1947 -- the private components of the protected type, and indicate that
1948 -- all itypes within are frozen. This ensures that no freeze nodes
1949 -- will be generated for them. In the case of itypes that are access
1950 -- types we need to complete their representation by calling layout,
1951 -- which would otherwise be invoked when freezing a type.
1953 -- On the other hand, components of the corresponding record are
1954 -- frozen (or receive itype references) as for other records.
1956 --------------------
1957 -- Undelay_Itypes --
1958 --------------------
1960 procedure Undelay_Itypes (T : Entity_Id) is
1961 Comp : Entity_Id;
1963 begin
1964 if Is_Protected_Type (T) then
1965 Comp := First_Private_Entity (T);
1966 elsif Is_Record_Type (T) then
1967 Comp := First_Entity (T);
1968 else
1969 return;
1970 end if;
1972 while Present (Comp) loop
1973 if Is_Type (Comp) and then Is_Itype (Comp) then
1974 Set_Has_Delayed_Freeze (Comp, False);
1975 Set_Is_Frozen (Comp);
1977 if Is_Access_Type (Comp) then
1978 Layout_Type (Comp);
1979 end if;
1981 if Is_Record_Type (Comp) or else Is_Protected_Type (Comp) then
1982 Undelay_Itypes (Comp);
1983 end if;
1984 end if;
1986 Next_Entity (Comp);
1987 end loop;
1988 end Undelay_Itypes;
1990 -- Local variables
1992 Prot_Typ : constant Entity_Id := Current_Scope;
1993 Item_Id : Entity_Id;
1994 Last_Id : Entity_Id;
1996 -- Start of processing for Analyze_Protected_Definition
1998 begin
1999 Tasking_Used := True;
2000 Analyze_Declarations (Visible_Declarations (N));
2002 if not Is_Empty_List (Private_Declarations (N)) then
2003 Last_Id := Last_Entity (Prot_Typ);
2004 Analyze_Declarations (Private_Declarations (N));
2006 if Present (Last_Id) then
2007 Set_First_Private_Entity (Prot_Typ, Next_Entity (Last_Id));
2008 else
2009 Set_First_Private_Entity (Prot_Typ, First_Entity (Prot_Typ));
2010 end if;
2011 end if;
2013 Item_Id := First_Entity (Prot_Typ);
2014 while Present (Item_Id) loop
2015 if Ekind (Item_Id) in E_Function | E_Procedure then
2016 Set_Convention (Item_Id, Convention_Protected);
2017 else
2018 Propagate_Concurrent_Flags (Prot_Typ, Etype (Item_Id));
2020 if Chars (Item_Id) /= Name_uParent
2021 and then Needs_Finalization (Etype (Item_Id))
2022 then
2023 Set_Has_Controlled_Component (Prot_Typ);
2024 end if;
2025 end if;
2027 Next_Entity (Item_Id);
2028 end loop;
2030 Undelay_Itypes (Prot_Typ);
2032 Check_Max_Entries (N, Max_Protected_Entries);
2033 Process_End_Label (N, 'e', Prot_Typ);
2034 end Analyze_Protected_Definition;
2036 ----------------------------------------
2037 -- Analyze_Protected_Type_Declaration --
2038 ----------------------------------------
2040 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
2041 Def_Id : constant Entity_Id := Defining_Identifier (N);
2042 E : Entity_Id;
2043 T : Entity_Id;
2045 begin
2046 if No_Run_Time_Mode then
2047 Error_Msg_CRT ("protected type", N);
2049 if Has_Aspects (N) then
2050 Analyze_Aspect_Specifications (N, Def_Id);
2051 end if;
2053 return;
2054 end if;
2056 Tasking_Used := True;
2057 Check_Restriction (No_Protected_Types, N);
2059 T := Find_Type_Name (N);
2061 -- In the case of an incomplete type, use the full view, unless it's not
2062 -- present (as can occur for an incomplete view from a limited with).
2064 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
2065 T := Full_View (T);
2066 Set_Completion_Referenced (T);
2067 end if;
2069 Mutate_Ekind (T, E_Protected_Type);
2070 Set_Is_Not_Self_Hidden (T);
2071 Set_Is_First_Subtype (T);
2072 Reinit_Size_Align (T);
2073 Set_Etype (T, T);
2074 Set_Has_Delayed_Freeze (T);
2075 Set_Stored_Constraint (T, No_Elist);
2077 -- Initialize type's primitive operations list, for possible use when
2078 -- the extension of prefixed call notation for untagged types is enabled
2079 -- (such as by use of -gnatX).
2081 Set_Direct_Primitive_Operations (T, New_Elmt_List);
2083 -- Mark this type as a protected type for the sake of restrictions,
2084 -- unless the protected type is declared in a private part of a package
2085 -- of the runtime. With this exception, the Suspension_Object from
2086 -- Ada.Synchronous_Task_Control can be implemented using a protected
2087 -- object without triggering violations of No_Local_Protected_Objects
2088 -- when the user locally declares such an object. This may look like a
2089 -- trick, but the user doesn't have to know how Suspension_Object is
2090 -- implemented.
2092 if In_Private_Part (Current_Scope)
2093 and then Is_Internal_Unit (Current_Sem_Unit)
2094 then
2095 Set_Has_Protected (T, False);
2096 else
2097 Set_Has_Protected (T);
2098 end if;
2100 -- Set the SPARK_Mode from the current context (may be overwritten later
2101 -- with an explicit pragma).
2103 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
2104 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
2105 Set_SPARK_Pragma_Inherited (T);
2106 Set_SPARK_Aux_Pragma_Inherited (T);
2108 Push_Scope (T);
2110 if Ada_Version >= Ada_2005 then
2111 Check_Interfaces (N, T);
2112 end if;
2114 if Present (Discriminant_Specifications (N)) then
2115 if Has_Discriminants (T) then
2117 -- Install discriminants. Also, verify conformance of
2118 -- discriminants of previous and current view. ???
2120 Install_Declarations (T);
2121 else
2122 Process_Discriminants (N);
2123 end if;
2124 end if;
2126 Set_Is_Constrained (T, not Has_Discriminants (T));
2128 -- If aspects are present, analyze them now. They can make references to
2129 -- the discriminants of the type, but not to any components.
2131 if Has_Aspects (N) then
2133 -- The protected type is the full view of a private type. Analyze the
2134 -- aspects with the entity of the private type to ensure that after
2135 -- both views are exchanged, the aspect are actually associated with
2136 -- the full view.
2138 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2139 Analyze_Aspect_Specifications (N, T);
2140 else
2141 Analyze_Aspect_Specifications (N, Def_Id);
2142 end if;
2143 end if;
2145 Analyze (Protected_Definition (N));
2147 -- In the case where the protected type is declared at a nested level
2148 -- and the No_Local_Protected_Objects restriction applies, issue a
2149 -- warning that objects of the type will violate the restriction.
2151 if Restriction_Check_Required (No_Local_Protected_Objects)
2152 and then not Is_Library_Level_Entity (T)
2153 and then Comes_From_Source (T)
2154 then
2155 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
2157 if Error_Msg_Sloc = No_Location then
2158 Error_Msg_N
2159 ("objects of this type will violate " &
2160 "`No_Local_Protected_Objects`??", N);
2161 else
2162 Error_Msg_N
2163 ("objects of this type will violate " &
2164 "`No_Local_Protected_Objects`#??", N);
2165 end if;
2166 end if;
2168 -- Protected types with entries are controlled (because of the
2169 -- Protection component if nothing else), same for any protected type
2170 -- with interrupt handlers. Note that we need to analyze the protected
2171 -- definition to set Has_Entries and such.
2173 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
2174 or else Number_Entries (T) > 1)
2175 and then not Restricted_Profile
2176 and then
2177 (Has_Entries (T)
2178 or else Has_Interrupt_Handler (T)
2179 or else Has_Attach_Handler (T))
2180 then
2181 Set_Has_Controlled_Component (T, True);
2182 end if;
2184 -- The Ekind of components is E_Void during analysis for historical
2185 -- reasons. Now it can be set correctly.
2187 E := First_Entity (Current_Scope);
2188 while Present (E) loop
2189 if Ekind (E) = E_Void then
2190 if not Is_Itype (E) then
2191 Mutate_Ekind (E, E_Component);
2192 Reinit_Component_Location (E);
2193 end if;
2194 end if;
2196 Next_Entity (E);
2197 end loop;
2199 End_Scope;
2201 -- When a Lock_Free aspect forces the lock-free implementation, check N
2202 -- meets all the lock-free restrictions. Otherwise, an error message is
2203 -- issued by Allows_Lock_Free_Implementation.
2205 if Uses_Lock_Free (Defining_Identifier (N)) then
2207 -- Complain when there is an explicit aspect/pragma Priority (or
2208 -- Interrupt_Priority) while the lock-free implementation is forced
2209 -- by an aspect/pragma.
2211 declare
2212 Id : constant Entity_Id := Defining_Identifier (Original_Node (N));
2213 -- The warning must be issued on the original identifier in order
2214 -- to deal properly with the case of a single protected object.
2216 Prio_Item : constant Node_Id :=
2217 Get_Rep_Item (Def_Id, Name_Priority, False);
2219 begin
2220 if Present (Prio_Item) then
2222 -- Aspect case
2224 if Nkind (Prio_Item) = N_Aspect_Specification
2225 or else From_Aspect_Specification (Prio_Item)
2226 then
2227 Error_Msg_Name_1 := Chars (Identifier (Prio_Item));
2228 Error_Msg_NE
2229 ("aspect% for & has no effect when Lock_Free given??",
2230 Prio_Item, Id);
2232 -- Pragma case
2234 else
2235 Error_Msg_Name_1 := Pragma_Name (Prio_Item);
2236 Error_Msg_NE
2237 ("pragma% for & has no effect when Lock_Free given??",
2238 Prio_Item, Id);
2239 end if;
2240 end if;
2241 end;
2243 if not Allows_Lock_Free_Implementation (N, Lock_Free_Given => True)
2244 then
2245 return;
2246 end if;
2247 end if;
2249 -- If the Attach_Handler aspect is specified or the Interrupt_Handler
2250 -- aspect is True, then the initial ceiling priority must be in the
2251 -- range of System.Interrupt_Priority. It is therefore recommanded
2252 -- to use the Interrupt_Priority aspect instead of the Priority aspect.
2254 if Has_Interrupt_Handler (T) or else Has_Attach_Handler (T) then
2255 declare
2256 Prio_Item : constant Node_Id :=
2257 Get_Rep_Item (Def_Id, Name_Priority, False);
2259 begin
2260 if Present (Prio_Item) then
2262 -- Aspect case
2264 if (Nkind (Prio_Item) = N_Aspect_Specification
2265 or else From_Aspect_Specification (Prio_Item))
2266 and then Chars (Identifier (Prio_Item)) = Name_Priority
2267 then
2268 Error_Msg_N
2269 ("aspect Interrupt_Priority is preferred in presence of "
2270 & "handlers??", Prio_Item);
2272 -- Pragma case
2274 elsif Nkind (Prio_Item) = N_Pragma
2275 and then Pragma_Name (Prio_Item) = Name_Priority
2276 then
2277 Error_Msg_N
2278 ("pragma Interrupt_Priority is preferred in presence of "
2279 & "handlers??", Prio_Item);
2280 end if;
2281 end if;
2282 end;
2283 end if;
2285 -- Case of a completion of a private declaration
2287 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2289 -- Deal with preelaborable initialization. Note that this processing
2290 -- is done by Process_Full_View, but as can be seen below, in this
2291 -- case the call to Process_Full_View is skipped if any serious
2292 -- errors have occurred, and we don't want to lose this check.
2294 if Known_To_Have_Preelab_Init (Def_Id) then
2295 Set_Must_Have_Preelab_Init (T);
2296 end if;
2298 -- Propagate Default_Initial_Condition-related attributes from the
2299 -- private type to the protected type.
2301 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
2303 -- Propagate invariant-related attributes from the private type to
2304 -- the protected type.
2306 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
2308 -- Propagate predicate-related attributes from the private type to
2309 -- the protected type.
2311 Propagate_Predicate_Attributes (T, From_Typ => Def_Id);
2313 -- Create corresponding record now, because some private dependents
2314 -- may be subtypes of the partial view.
2316 -- Skip if errors are present, to prevent cascaded messages
2318 if Serious_Errors_Detected = 0
2320 -- Also skip if expander is not active
2322 and then Expander_Active
2323 then
2324 Expand_N_Protected_Type_Declaration (N);
2325 Process_Full_View (N, T, Def_Id);
2326 end if;
2327 end if;
2329 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
2330 -- is required for the ceiling priority protocol checks triggered by
2331 -- calls originating from protected subprograms and entries.
2333 if GNATprove_Mode then
2334 SPARK_Implicit_Load (RE_Interrupt_Priority);
2335 end if;
2336 end Analyze_Protected_Type_Declaration;
2338 ---------------------
2339 -- Analyze_Requeue --
2340 ---------------------
2342 procedure Analyze_Requeue (N : Node_Id) is
2344 procedure Check_Wrong_Attribute_In_Postconditions
2345 (Entry_Id : Entity_Id;
2346 Error_Node : Node_Id);
2347 -- Check that the requeue target Entry_Id does not have an specific or
2348 -- class-wide postcondition that references an Old or Index attribute.
2350 ---------------------------------------------
2351 -- Check_Wrong_Attribute_In_Postconditions --
2352 ---------------------------------------------
2354 procedure Check_Wrong_Attribute_In_Postconditions
2355 (Entry_Id : Entity_Id;
2356 Error_Node : Node_Id)
2358 function Check_Node (N : Node_Id) return Traverse_Result;
2359 -- Check that N is not a reference to attribute Index or Old; report
2360 -- an error otherwise.
2362 ----------------
2363 -- Check_Node --
2364 ----------------
2366 function Check_Node (N : Node_Id) return Traverse_Result is
2367 begin
2368 if Nkind (N) = N_Attribute_Reference
2369 and then Attribute_Name (N) in Name_Index
2370 | Name_Old
2371 then
2372 Error_Msg_Name_1 := Attribute_Name (N);
2373 Error_Msg_N
2374 ("target of requeue must not have references to attribute % "
2375 & "in postcondition",
2376 Error_Node);
2377 end if;
2379 return OK;
2380 end Check_Node;
2382 procedure Check_Attr_Refs is new Traverse_Proc (Check_Node);
2384 -- Local variables
2386 Prag : Node_Id;
2387 begin
2388 Prag := Pre_Post_Conditions (Contract (Entry_Id));
2390 while Present (Prag) loop
2391 if Pragma_Name (Prag) = Name_Postcondition then
2392 Check_Attr_Refs (First (Pragma_Argument_Associations (Prag)));
2393 end if;
2395 Prag := Next_Pragma (Prag);
2396 end loop;
2397 end Check_Wrong_Attribute_In_Postconditions;
2399 -- Local variables
2401 Count : Natural := 0;
2402 Entry_Name : Node_Id := Name (N);
2403 Entry_Id : Entity_Id;
2404 I : Interp_Index;
2405 Is_Disp_Req : Boolean;
2406 It : Interp;
2407 Enclosing : Entity_Id;
2408 Target_Obj : Node_Id := Empty;
2409 Req_Scope : Entity_Id;
2410 Outer_Ent : Entity_Id;
2411 Synch_Type : Entity_Id := Empty;
2413 -- Start of processing for Analyze_Requeue
2415 begin
2416 -- Preserve relevant elaboration-related attributes of the context which
2417 -- are no longer available or very expensive to recompute once analysis,
2418 -- resolution, and expansion are over.
2420 Mark_Elaboration_Attributes
2421 (N_Id => N,
2422 Checks => True,
2423 Modes => True,
2424 Warnings => True);
2426 Tasking_Used := True;
2427 Check_Restriction (No_Requeue_Statements, N);
2428 Check_Unreachable_Code (N);
2430 Enclosing := Empty;
2431 for J in reverse 0 .. Scope_Stack.Last loop
2432 Enclosing := Scope_Stack.Table (J).Entity;
2433 exit when Is_Entry (Enclosing);
2435 if Ekind (Enclosing) not in E_Block | E_Loop then
2436 Error_Msg_N ("requeue must appear within accept or entry body", N);
2437 return;
2438 end if;
2439 end loop;
2441 Analyze (Entry_Name);
2443 if Etype (Entry_Name) = Any_Type then
2444 return;
2445 end if;
2447 if Nkind (Entry_Name) = N_Selected_Component then
2448 Target_Obj := Prefix (Entry_Name);
2449 Entry_Name := Selector_Name (Entry_Name);
2450 end if;
2452 -- If an explicit target object is given then we have to check the
2453 -- restrictions of 9.5.4(6).
2455 if Present (Target_Obj) then
2457 -- Locate containing concurrent unit and determine enclosing entry
2458 -- body or outermost enclosing accept statement within the unit.
2460 Outer_Ent := Empty;
2461 for S in reverse 0 .. Scope_Stack.Last loop
2462 Req_Scope := Scope_Stack.Table (S).Entity;
2464 exit when Is_Concurrent_Type (Req_Scope);
2466 if Is_Entry (Req_Scope) then
2467 Outer_Ent := Req_Scope;
2468 end if;
2469 end loop;
2471 pragma Assert (Present (Outer_Ent));
2473 -- Check that the accessibility level of the target object is not
2474 -- greater or equal to the outermost enclosing accept statement (or
2475 -- entry body) unless it is a parameter of the innermost enclosing
2476 -- accept statement (or entry body).
2478 if Static_Accessibility_Level (Target_Obj, Zero_On_Dynamic_Level)
2479 >= Scope_Depth (Outer_Ent)
2480 and then
2481 (not Is_Entity_Name (Target_Obj)
2482 or else not Is_Formal (Entity (Target_Obj))
2483 or else Enclosing /= Scope (Entity (Target_Obj)))
2484 then
2485 Error_Msg_N
2486 ("target object has invalid level for requeue", Target_Obj);
2487 end if;
2488 end if;
2490 -- Overloaded case, find right interpretation
2492 if Is_Overloaded (Entry_Name) then
2493 Entry_Id := Empty;
2495 -- Loop over candidate interpretations and filter out any that are
2496 -- not parameterless, are not type conformant, are not entries, or
2497 -- do not come from source.
2499 Get_First_Interp (Entry_Name, I, It);
2500 while Present (It.Nam) loop
2502 -- Note: we test type conformance here, not subtype conformance.
2503 -- Subtype conformance will be tested later on, but it is better
2504 -- for error output in some cases not to do that here.
2506 if (No (First_Formal (It.Nam))
2507 or else Type_Conformant (Enclosing, It.Nam))
2508 and then Ekind (It.Nam) = E_Entry
2509 then
2510 -- Ada 2005 (AI-345): Since protected and task types have
2511 -- primitive entry wrappers, we only consider source entries.
2513 if Comes_From_Source (It.Nam) then
2514 Count := Count + 1;
2515 Entry_Id := It.Nam;
2516 else
2517 Remove_Interp (I);
2518 end if;
2519 end if;
2521 Get_Next_Interp (I, It);
2522 end loop;
2524 if Count = 0 then
2525 Error_Msg_N ("no entry matches context", N);
2526 return;
2528 elsif Count > 1 then
2529 Error_Msg_N ("ambiguous entry name in requeue", N);
2530 return;
2532 else
2533 Set_Is_Overloaded (Entry_Name, False);
2534 Set_Entity (Entry_Name, Entry_Id);
2535 end if;
2537 -- Non-overloaded cases
2539 -- For the case of a reference to an element of an entry family, the
2540 -- Entry_Name is an indexed component.
2542 elsif Nkind (Entry_Name) = N_Indexed_Component then
2544 -- Requeue to an entry out of the body
2546 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
2547 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
2549 -- Requeue from within the body itself
2551 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
2552 Entry_Id := Entity (Prefix (Entry_Name));
2554 else
2555 Error_Msg_N ("invalid entry_name specified", N);
2556 return;
2557 end if;
2559 -- If we had a requeue of the form REQUEUE A (B), then the parser
2560 -- accepted it (because it could have been a requeue on an entry index.
2561 -- If A turns out not to be an entry family, then the analysis of A (B)
2562 -- turned it into a function call.
2564 elsif Nkind (Entry_Name) = N_Function_Call then
2565 Error_Msg_N
2566 ("arguments not allowed in requeue statement",
2567 First (Parameter_Associations (Entry_Name)));
2568 return;
2570 -- Normal case of no entry family, no argument
2572 else
2573 Entry_Id := Entity (Entry_Name);
2574 end if;
2576 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
2577 -- target type must be a concurrent interface class-wide type and the
2578 -- target must be a procedure, flagged by pragma Implemented. The
2579 -- target may be an access to class-wide type, in which case it must
2580 -- be dereferenced.
2582 if Present (Target_Obj) then
2583 Synch_Type := Etype (Target_Obj);
2585 if Is_Access_Type (Synch_Type) then
2586 Synch_Type := Designated_Type (Synch_Type);
2587 end if;
2588 end if;
2590 Is_Disp_Req :=
2591 Ada_Version >= Ada_2012
2592 and then Present (Target_Obj)
2593 and then Is_Class_Wide_Type (Synch_Type)
2594 and then Is_Concurrent_Interface (Synch_Type)
2595 and then Ekind (Entry_Id) = E_Procedure
2596 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
2598 -- Resolve entry, and check that it is subtype conformant with the
2599 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
2600 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
2602 if not Is_Entry (Entry_Id)
2603 and then not Is_Disp_Req
2604 then
2605 Error_Msg_N ("expect entry name in requeue statement", Name (N));
2607 elsif Ekind (Entry_Id) = E_Entry_Family
2608 and then Nkind (Entry_Name) /= N_Indexed_Component
2609 then
2610 Error_Msg_N ("missing index for entry family component", Name (N));
2612 else
2613 Resolve_Entry (Name (N));
2614 Generate_Reference (Entry_Id, Entry_Name);
2616 if Present (First_Formal (Entry_Id)) then
2618 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
2619 -- the first parameter of Entry_Id since it is the interface
2620 -- controlling formal.
2622 if Ada_Version >= Ada_2012 and then Is_Disp_Req then
2623 declare
2624 Enclosing_Formal : Entity_Id;
2625 Target_Formal : Entity_Id;
2627 begin
2628 Enclosing_Formal := First_Formal (Enclosing);
2629 Target_Formal := Next_Formal (First_Formal (Entry_Id));
2630 while Present (Enclosing_Formal)
2631 and then Present (Target_Formal)
2632 loop
2633 if not Conforming_Types
2634 (T1 => Etype (Enclosing_Formal),
2635 T2 => Etype (Target_Formal),
2636 Ctype => Subtype_Conformant)
2637 then
2638 Error_Msg_Node_2 := Target_Formal;
2639 Error_Msg_NE
2640 ("formal & is not subtype conformant with &" &
2641 "in dispatching requeue", N, Enclosing_Formal);
2642 end if;
2644 Next_Formal (Enclosing_Formal);
2645 Next_Formal (Target_Formal);
2646 end loop;
2647 end;
2648 else
2649 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
2650 end if;
2652 -- Processing for parameters accessed by the requeue
2654 declare
2655 Ent : Entity_Id;
2657 begin
2658 Ent := First_Formal (Enclosing);
2659 while Present (Ent) loop
2661 -- For OUT or IN OUT parameter, the effect of the requeue is
2662 -- to assign the parameter a value on exit from the requeued
2663 -- body, so we can set it as source assigned. We also clear
2664 -- the Is_True_Constant indication. We do not need to clear
2665 -- Current_Value, since the effect of the requeue is to
2666 -- perform an unconditional goto so that any further
2667 -- references will not occur anyway.
2669 if Ekind (Ent) in E_Out_Parameter | E_In_Out_Parameter then
2670 Set_Never_Set_In_Source (Ent, False);
2671 Set_Is_True_Constant (Ent, False);
2672 end if;
2674 -- For all parameters, the requeue acts as a reference,
2675 -- since the value of the parameter is passed to the new
2676 -- entry, so we want to suppress unreferenced warnings.
2678 Set_Referenced (Ent);
2679 Next_Formal (Ent);
2680 end loop;
2681 end;
2682 end if;
2683 end if;
2685 -- AI05-0225: the target protected object of a requeue must be a
2686 -- variable. This is a binding interpretation that applies to all
2687 -- versions of the language. Note that the subprogram does not have
2688 -- to be a protected operation: it can be an primitive implemented
2689 -- by entry with a formal that is a protected interface.
2691 if Present (Target_Obj)
2692 and then not Is_Variable (Target_Obj)
2693 then
2694 Error_Msg_N
2695 ("target protected object of requeue must be a variable", N);
2696 end if;
2698 -- Ada 2022 (AI12-0143): The requeue target shall not have an
2699 -- applicable specific or class-wide postcondition which includes
2700 -- an Old or Index attribute reference.
2702 if Ekind (Entry_Id) = E_Entry_Family
2703 and then Present (Contract (Entry_Id))
2704 then
2705 Check_Wrong_Attribute_In_Postconditions
2706 (Entry_Id => Entry_Id,
2707 Error_Node => Entry_Name);
2708 end if;
2710 -- A requeue statement is treated as a call for purposes of ABE checks
2711 -- and diagnostics. Annotate the tree by creating a call marker in case
2712 -- the requeue statement is transformed by expansion.
2714 Build_Call_Marker (N);
2715 end Analyze_Requeue;
2717 ------------------------------
2718 -- Analyze_Selective_Accept --
2719 ------------------------------
2721 procedure Analyze_Selective_Accept (N : Node_Id) is
2722 Alts : constant List_Id := Select_Alternatives (N);
2723 Alt : Node_Id;
2725 Accept_Present : Boolean := False;
2726 Terminate_Present : Boolean := False;
2727 Delay_Present : Boolean := False;
2728 Relative_Present : Boolean := False;
2729 Alt_Count : Uint := Uint_0;
2731 begin
2732 Tasking_Used := True;
2733 Check_Restriction (No_Select_Statements, N);
2735 -- Loop to analyze alternatives
2737 Alt := First (Alts);
2738 while Present (Alt) loop
2739 Alt_Count := Alt_Count + 1;
2740 Analyze (Alt);
2742 if Nkind (Alt) = N_Delay_Alternative then
2743 if Delay_Present then
2745 if Relative_Present /=
2746 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
2747 then
2748 Error_Msg_N
2749 ("delay_until and delay_relative alternatives", Alt);
2750 Error_Msg_N
2751 ("\cannot appear in the same selective_wait", Alt);
2752 end if;
2754 else
2755 Delay_Present := True;
2756 Relative_Present :=
2757 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
2758 end if;
2760 elsif Nkind (Alt) = N_Terminate_Alternative then
2761 if Terminate_Present then
2762 Error_Msg_N ("only one terminate alternative allowed", N);
2763 else
2764 Terminate_Present := True;
2765 Check_Restriction (No_Terminate_Alternatives, N);
2766 end if;
2768 elsif Nkind (Alt) = N_Accept_Alternative then
2769 Accept_Present := True;
2771 -- Check for duplicate accept
2773 declare
2774 Alt1 : Node_Id;
2775 Stm : constant Node_Id := Accept_Statement (Alt);
2776 EDN : constant Node_Id := Entry_Direct_Name (Stm);
2777 Ent : Entity_Id;
2779 begin
2780 if Nkind (EDN) = N_Identifier
2781 and then No (Condition (Alt))
2782 and then Present (Entity (EDN)) -- defend against junk
2783 and then Ekind (Entity (EDN)) = E_Entry
2784 then
2785 Ent := Entity (EDN);
2787 Alt1 := First (Alts);
2788 while Alt1 /= Alt loop
2789 if Nkind (Alt1) = N_Accept_Alternative
2790 and then No (Condition (Alt1))
2791 then
2792 declare
2793 Stm1 : constant Node_Id := Accept_Statement (Alt1);
2794 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
2796 begin
2797 if Nkind (EDN1) = N_Identifier then
2798 if Entity (EDN1) = Ent then
2799 Error_Msg_Sloc := Sloc (Stm1);
2800 Error_Msg_N
2801 ("ACCEPT duplicates one on line#??", Stm);
2802 exit;
2803 end if;
2804 end if;
2805 end;
2806 end if;
2808 Next (Alt1);
2809 end loop;
2810 end if;
2811 end;
2812 end if;
2814 Next (Alt);
2815 end loop;
2817 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
2818 Check_Potentially_Blocking_Operation (N);
2820 if Terminate_Present and Delay_Present then
2821 Error_Msg_N ("at most one of TERMINATE or DELAY alternative", N);
2823 elsif not Accept_Present then
2824 Error_Msg_N
2825 ("SELECT must contain at least one ACCEPT alternative", N);
2826 end if;
2828 if Present (Else_Statements (N)) then
2829 if Terminate_Present or Delay_Present then
2830 Error_Msg_N ("ELSE part not allowed with other alternatives", N);
2831 end if;
2833 Analyze_Statements (Else_Statements (N));
2834 end if;
2835 end Analyze_Selective_Accept;
2837 ------------------------------------------
2838 -- Analyze_Single_Protected_Declaration --
2839 ------------------------------------------
2841 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
2842 Loc : constant Source_Ptr := Sloc (N);
2843 Obj_Id : constant Node_Id := Defining_Identifier (N);
2844 Obj_Decl : Node_Id;
2845 Typ : Entity_Id;
2847 begin
2848 Generate_Definition (Obj_Id);
2849 Tasking_Used := True;
2851 -- A single protected declaration is transformed into a pair of an
2852 -- anonymous protected type and an object of that type. Generate:
2854 -- protected type Typ is ...;
2856 Typ :=
2857 Make_Defining_Identifier (Sloc (Obj_Id),
2858 Chars => New_External_Name (Chars (Obj_Id), 'T'));
2860 Rewrite (N,
2861 Make_Protected_Type_Declaration (Loc,
2862 Defining_Identifier => Typ,
2863 Protected_Definition => Relocate_Node (Protected_Definition (N)),
2864 Interface_List => Interface_List (N)));
2866 -- Use the original defining identifier of the single protected
2867 -- declaration in the generated object declaration to allow for debug
2868 -- information to be attached to it when compiling with -gnatD. The
2869 -- parent of the entity is the new object declaration. The single
2870 -- protected declaration is not used in semantics or code generation,
2871 -- but is scanned when generating debug information, and therefore needs
2872 -- the updated Sloc information from the entity (see Sprint). Generate:
2874 -- Obj : Typ;
2876 Obj_Decl :=
2877 Make_Object_Declaration (Loc,
2878 Defining_Identifier => Obj_Id,
2879 Object_Definition => New_Occurrence_Of (Typ, Loc));
2881 Insert_After (N, Obj_Decl);
2882 Mark_Rewrite_Insertion (Obj_Decl);
2884 -- Relocate aspect Part_Of from the original single protected
2885 -- declaration to the anonymous object declaration. This emulates the
2886 -- placement of an equivalent source pragma.
2888 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2890 -- Relocate pragma Part_Of from the visible declarations of the original
2891 -- single protected declaration to the anonymous object declaration. The
2892 -- new placement better reflects the role of the pragma.
2894 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2896 -- Enter the names of the anonymous protected type and the object before
2897 -- analysis takes places, because the name of the object may be used in
2898 -- its own body.
2900 Enter_Name (Typ);
2901 Mutate_Ekind (Typ, E_Protected_Type);
2902 Set_Etype (Typ, Typ);
2903 Set_Anonymous_Object (Typ, Obj_Id);
2905 Enter_Name (Obj_Id);
2906 Mutate_Ekind (Obj_Id, E_Variable);
2907 Set_Is_Not_Self_Hidden (Obj_Id);
2908 Set_Etype (Obj_Id, Typ);
2909 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2910 Set_SPARK_Pragma_Inherited (Obj_Id);
2912 -- Instead of calling Analyze on the new node, call the proper analysis
2913 -- procedure directly. Otherwise the node would be expanded twice, with
2914 -- disastrous result.
2916 Analyze_Protected_Type_Declaration (N);
2918 if Has_Aspects (N) then
2919 Analyze_Aspect_Specifications (N, Obj_Id);
2920 end if;
2921 end Analyze_Single_Protected_Declaration;
2923 -------------------------------------
2924 -- Analyze_Single_Task_Declaration --
2925 -------------------------------------
2927 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
2928 Loc : constant Source_Ptr := Sloc (N);
2929 Obj_Id : constant Node_Id := Defining_Identifier (N);
2930 Obj_Decl : Node_Id;
2931 Typ : Entity_Id;
2933 begin
2934 Generate_Definition (Obj_Id);
2935 Tasking_Used := True;
2937 -- A single task declaration is transformed into a pair of an anonymous
2938 -- task type and an object of that type. Generate:
2940 -- task type Typ is ...;
2942 Typ :=
2943 Make_Defining_Identifier (Sloc (Obj_Id),
2944 Chars => New_External_Name (Chars (Obj_Id), Suffix => "TK"));
2946 Rewrite (N,
2947 Make_Task_Type_Declaration (Loc,
2948 Defining_Identifier => Typ,
2949 Task_Definition => Relocate_Node (Task_Definition (N)),
2950 Interface_List => Interface_List (N)));
2952 -- Use the original defining identifier of the single task declaration
2953 -- in the generated object declaration to allow for debug information
2954 -- to be attached to it when compiling with -gnatD. The parent of the
2955 -- entity is the new object declaration. The single task declaration
2956 -- is not used in semantics or code generation, but is scanned when
2957 -- generating debug information, and therefore needs the updated Sloc
2958 -- information from the entity (see Sprint). Generate:
2960 -- Obj : Typ;
2962 Obj_Decl :=
2963 Make_Object_Declaration (Loc,
2964 Defining_Identifier => Obj_Id,
2965 Object_Definition => New_Occurrence_Of (Typ, Loc));
2967 Insert_After (N, Obj_Decl);
2968 Mark_Rewrite_Insertion (Obj_Decl);
2970 -- Relocate aspects Depends, Global and Part_Of from the original single
2971 -- task declaration to the anonymous object declaration. This emulates
2972 -- the placement of an equivalent source pragma.
2974 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2976 -- Relocate pragmas Depends, Global and Part_Of from the visible
2977 -- declarations of the original single protected declaration to the
2978 -- anonymous object declaration. The new placement better reflects the
2979 -- role of the pragmas.
2981 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2983 -- Enter the names of the anonymous task type and the object before
2984 -- analysis takes places, because the name of the object may be used
2985 -- in its own body.
2987 Enter_Name (Typ);
2988 Mutate_Ekind (Typ, E_Task_Type);
2989 Set_Etype (Typ, Typ);
2990 Set_Anonymous_Object (Typ, Obj_Id);
2992 Enter_Name (Obj_Id);
2993 Mutate_Ekind (Obj_Id, E_Variable);
2994 Set_Is_Not_Self_Hidden (Obj_Id);
2995 Set_Etype (Obj_Id, Typ);
2996 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2997 Set_SPARK_Pragma_Inherited (Obj_Id);
2999 -- Preserve relevant elaboration-related attributes of the context which
3000 -- are no longer available or very expensive to recompute once analysis,
3001 -- resolution, and expansion are over.
3003 Mark_Elaboration_Attributes
3004 (N_Id => Obj_Id,
3005 Checks => True,
3006 Warnings => True);
3008 -- Instead of calling Analyze on the new node, call the proper analysis
3009 -- procedure directly. Otherwise the node would be expanded twice, with
3010 -- disastrous result.
3012 Analyze_Task_Type_Declaration (N);
3014 if Has_Aspects (N) then
3015 Analyze_Aspect_Specifications (N, Obj_Id);
3016 end if;
3017 end Analyze_Single_Task_Declaration;
3019 -----------------------
3020 -- Analyze_Task_Body --
3021 -----------------------
3023 procedure Analyze_Task_Body (N : Node_Id) is
3024 Body_Id : constant Entity_Id := Defining_Identifier (N);
3025 Decls : constant List_Id := Declarations (N);
3026 HSS : constant Node_Id := Handled_Statement_Sequence (N);
3027 Last_E : Entity_Id;
3029 Spec_Id : Entity_Id;
3030 -- This is initially the entity of the task or task type involved, but
3031 -- is replaced by the task type always in the case of a single task
3032 -- declaration, since this is the proper scope to be used.
3034 Ref_Id : Entity_Id;
3035 -- This is the entity of the task or task type, and is the entity used
3036 -- for cross-reference purposes (it differs from Spec_Id in the case of
3037 -- a single task, since Spec_Id is set to the task type).
3039 begin
3040 -- A task body freezes the contract of the nearest enclosing package
3041 -- body and all other contracts encountered in the same declarative part
3042 -- up to and excluding the task body. This ensures that annotations
3043 -- referenced by the contract of an entry or subprogram body declared
3044 -- within the current protected body are available.
3046 Freeze_Previous_Contracts (N);
3048 Tasking_Used := True;
3049 Set_Scope (Body_Id, Current_Scope);
3050 Mutate_Ekind (Body_Id, E_Task_Body);
3051 Set_Etype (Body_Id, Standard_Void_Type);
3052 Spec_Id := Find_Concurrent_Spec (Body_Id);
3054 -- The spec is either a task type declaration, or a single task
3055 -- declaration for which we have created an anonymous type.
3057 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Task_Type then
3058 null;
3060 elsif Present (Spec_Id)
3061 and then Ekind (Etype (Spec_Id)) = E_Task_Type
3062 and then not Comes_From_Source (Etype (Spec_Id))
3063 then
3064 null;
3066 else
3067 Error_Msg_N ("missing specification for task body", Body_Id);
3068 return;
3069 end if;
3071 if Has_Completion (Spec_Id)
3072 and then Present (Corresponding_Body (Parent (Spec_Id)))
3073 then
3074 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
3075 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
3076 else
3077 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
3078 end if;
3079 end if;
3081 Ref_Id := Spec_Id;
3082 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
3083 Style.Check_Identifier (Body_Id, Spec_Id);
3085 -- Deal with case of body of single task (anonymous type was created)
3087 if Ekind (Spec_Id) = E_Variable then
3088 Spec_Id := Etype (Spec_Id);
3089 end if;
3091 -- Set the SPARK_Mode from the current context (may be overwritten later
3092 -- with an explicit pragma).
3094 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
3095 Set_SPARK_Pragma_Inherited (Body_Id);
3097 if Has_Aspects (N) then
3098 Analyze_Aspect_Specifications (N, Body_Id);
3099 end if;
3101 Push_Scope (Spec_Id);
3102 Set_Corresponding_Spec (N, Spec_Id);
3103 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
3104 Set_Has_Completion (Spec_Id);
3105 Install_Declarations (Spec_Id);
3106 Last_E := Last_Entity (Spec_Id);
3108 Analyze_Declarations (Decls);
3109 Inspect_Deferred_Constant_Completion (Decls);
3111 -- For visibility purposes, all entities in the body are private. Set
3112 -- First_Private_Entity accordingly, if there was no private part in the
3113 -- protected declaration.
3115 if No (First_Private_Entity (Spec_Id)) then
3116 if Present (Last_E) then
3117 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
3118 else
3119 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
3120 end if;
3122 -- The entity list of the current scope now includes entities in
3123 -- the spec as well as the body. Their declarations will become
3124 -- part of the statement sequence of the task body procedure that
3125 -- is built during expansion. Indicate that aspect specifications
3126 -- for these entities need not be rechecked. The guards on
3127 -- Check_Aspect_At_End_Of_Declarations are not sufficient to
3128 -- suppress these checks, because the declarations come from source.
3130 declare
3131 Priv : Entity_Id := First_Private_Entity (Spec_Id);
3133 begin
3134 while Present (Priv) loop
3135 Set_Has_Delayed_Aspects (Priv, False);
3136 Next_Entity (Priv);
3137 end loop;
3138 end;
3139 end if;
3141 -- Mark all handlers as not suitable for local raise optimization,
3142 -- since this optimization causes difficulties in a task context.
3144 if Present (Exception_Handlers (HSS)) then
3145 declare
3146 Handlr : Node_Id;
3147 begin
3148 Handlr := First (Exception_Handlers (HSS));
3149 while Present (Handlr) loop
3150 Set_Local_Raise_Not_OK (Handlr);
3151 Next (Handlr);
3152 end loop;
3153 end;
3154 end if;
3156 -- Now go ahead and complete analysis of the task body
3158 Analyze (HSS);
3159 Check_Completion (Body_Id);
3160 Check_References (Body_Id);
3161 Check_References (Spec_Id);
3163 -- Check for entries with no corresponding accept
3165 declare
3166 Ent : Entity_Id;
3168 begin
3169 Ent := First_Entity (Spec_Id);
3170 while Present (Ent) loop
3171 if Is_Entry (Ent)
3172 and then not Entry_Accepted (Ent)
3173 and then Comes_From_Source (Ent)
3174 then
3175 Error_Msg_NE ("no accept for entry &??", N, Ent);
3176 end if;
3178 Next_Entity (Ent);
3179 end loop;
3180 end;
3182 Process_End_Label (HSS, 't', Ref_Id);
3183 Update_Use_Clause_Chain;
3184 End_Scope;
3185 end Analyze_Task_Body;
3187 -----------------------------
3188 -- Analyze_Task_Definition --
3189 -----------------------------
3191 procedure Analyze_Task_Definition (N : Node_Id) is
3192 L : Entity_Id;
3194 begin
3195 Tasking_Used := True;
3197 if Present (Visible_Declarations (N)) then
3198 Analyze_Declarations (Visible_Declarations (N));
3199 end if;
3201 if Present (Private_Declarations (N)) then
3202 L := Last_Entity (Current_Scope);
3203 Analyze_Declarations (Private_Declarations (N));
3205 if Present (L) then
3206 Set_First_Private_Entity
3207 (Current_Scope, Next_Entity (L));
3208 else
3209 Set_First_Private_Entity
3210 (Current_Scope, First_Entity (Current_Scope));
3211 end if;
3212 end if;
3214 Check_Max_Entries (N, Max_Task_Entries);
3215 Process_End_Label (N, 'e', Current_Scope);
3216 end Analyze_Task_Definition;
3218 -----------------------------------
3219 -- Analyze_Task_Type_Declaration --
3220 -----------------------------------
3222 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
3223 Def_Id : constant Entity_Id := Defining_Identifier (N);
3224 T : Entity_Id;
3226 begin
3227 -- Attempt to use tasking in no run time mode is not allowe. Issue hard
3228 -- error message to disable expansion which leads to crashes.
3230 if Opt.No_Run_Time_Mode then
3231 Error_Msg_N ("tasking not allowed in No_Run_Time mode", N);
3233 -- Otherwise soft check for no tasking restriction
3235 else
3236 Check_Restriction (No_Tasking, N);
3237 end if;
3239 -- Proceed ahead with analysis of task type declaration
3241 Tasking_Used := True;
3243 -- The sequential partition elaboration policy is supported only in the
3244 -- restricted profile.
3246 if Partition_Elaboration_Policy = 'S'
3247 and then not Restricted_Profile
3248 then
3249 Error_Msg_N
3250 ("sequential elaboration supported only in restricted profile", N);
3251 end if;
3253 T := Find_Type_Name (N);
3254 Generate_Definition (T);
3256 -- In the case of an incomplete type, use the full view, unless it's not
3257 -- present (as can occur for an incomplete view from a limited with).
3258 -- Initialize the Corresponding_Record_Type (which overlays the Private
3259 -- Dependents field of the incomplete view).
3261 if Ekind (T) = E_Incomplete_Type then
3262 if Present (Full_View (T)) then
3263 T := Full_View (T);
3264 Set_Completion_Referenced (T);
3266 else
3267 Mutate_Ekind (T, E_Task_Type);
3268 Set_Corresponding_Record_Type (T, Empty);
3269 end if;
3270 end if;
3272 Mutate_Ekind (T, E_Task_Type);
3273 Set_Is_Not_Self_Hidden (T);
3274 Set_Is_First_Subtype (T, True);
3275 Set_Has_Task (T, True);
3276 Reinit_Size_Align (T);
3277 Set_Etype (T, T);
3278 Set_Has_Delayed_Freeze (T, True);
3279 Set_Stored_Constraint (T, No_Elist);
3281 -- Initialize type's primitive operations list, for possible use when
3282 -- the extension of prefixed call notation for untagged types is enabled
3283 -- (such as by use of -gnatX).
3285 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3287 -- Set the SPARK_Mode from the current context (may be overwritten later
3288 -- with an explicit pragma).
3290 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
3291 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
3292 Set_SPARK_Pragma_Inherited (T);
3293 Set_SPARK_Aux_Pragma_Inherited (T);
3295 -- Preserve relevant elaboration-related attributes of the context which
3296 -- are no longer available or very expensive to recompute once analysis,
3297 -- resolution, and expansion are over.
3299 Mark_Elaboration_Attributes
3300 (N_Id => T,
3301 Checks => True,
3302 Warnings => True);
3304 Push_Scope (T);
3306 if Ada_Version >= Ada_2005 then
3307 Check_Interfaces (N, T);
3308 end if;
3310 if Present (Discriminant_Specifications (N)) then
3311 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3312 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
3313 end if;
3315 if Has_Discriminants (T) then
3317 -- Install discriminants. Also, verify conformance of
3318 -- discriminants of previous and current view. ???
3320 Install_Declarations (T);
3321 else
3322 Process_Discriminants (N);
3323 end if;
3324 end if;
3326 Set_Is_Constrained (T, not Has_Discriminants (T));
3328 if Has_Aspects (N) then
3330 -- The task type is the full view of a private type. Analyze the
3331 -- aspects with the entity of the private type to ensure that after
3332 -- both views are exchanged, the aspect are actually associated with
3333 -- the full view.
3335 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3336 Analyze_Aspect_Specifications (N, T);
3337 else
3338 Analyze_Aspect_Specifications (N, Def_Id);
3339 end if;
3340 end if;
3342 if Present (Task_Definition (N)) then
3343 Analyze_Task_Definition (Task_Definition (N));
3344 end if;
3346 -- In the case where the task type is declared at a nested level and the
3347 -- No_Task_Hierarchy restriction applies, issue a warning that objects
3348 -- of the type will violate the restriction.
3350 if Restriction_Check_Required (No_Task_Hierarchy)
3351 and then not Is_Library_Level_Entity (T)
3352 and then Comes_From_Source (T)
3353 and then not CodePeer_Mode
3354 then
3355 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
3357 if Error_Msg_Sloc = No_Location then
3358 Error_Msg_N
3359 ("objects of this type will violate `No_Task_Hierarchy`??", N);
3360 else
3361 Error_Msg_N
3362 ("objects of this type will violate `No_Task_Hierarchy`#??", N);
3363 end if;
3364 end if;
3366 End_Scope;
3368 -- Case of a completion of a private declaration
3370 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3372 -- Deal with preelaborable initialization. Note that this processing
3373 -- is done by Process_Full_View, but as can be seen below, in this
3374 -- case the call to Process_Full_View is skipped if any serious
3375 -- errors have occurred, and we don't want to lose this check.
3377 if Known_To_Have_Preelab_Init (Def_Id) then
3378 Set_Must_Have_Preelab_Init (T);
3379 end if;
3381 -- Propagate Default_Initial_Condition-related attributes from the
3382 -- private type to the task type.
3384 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
3386 -- Propagate invariant-related attributes from the private type to
3387 -- task type.
3389 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
3391 -- Propagate predicate-related attributes from the private type to
3392 -- task type.
3394 Propagate_Predicate_Attributes (T, From_Typ => Def_Id);
3396 -- Create corresponding record now, because some private dependents
3397 -- may be subtypes of the partial view.
3399 -- Skip if errors are present, to prevent cascaded messages
3401 if Serious_Errors_Detected = 0
3403 -- Also skip if expander is not active
3405 and then Expander_Active
3406 then
3407 Expand_N_Task_Type_Declaration (N);
3408 Process_Full_View (N, T, Def_Id);
3409 end if;
3410 end if;
3412 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
3413 -- is required for the ceiling priority protocol checks triggered by
3414 -- calls originating from tasks.
3416 if GNATprove_Mode then
3417 SPARK_Implicit_Load (RE_Interrupt_Priority);
3418 end if;
3419 end Analyze_Task_Type_Declaration;
3421 -----------------------------------
3422 -- Analyze_Terminate_Alternative --
3423 -----------------------------------
3425 procedure Analyze_Terminate_Alternative (N : Node_Id) is
3426 begin
3427 Tasking_Used := True;
3429 if Present (Pragmas_Before (N)) then
3430 Analyze_List (Pragmas_Before (N));
3431 end if;
3433 if Present (Condition (N)) then
3434 Analyze_And_Resolve (Condition (N), Any_Boolean);
3435 end if;
3436 end Analyze_Terminate_Alternative;
3438 ------------------------------
3439 -- Analyze_Timed_Entry_Call --
3440 ------------------------------
3442 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
3443 Trigger : constant Node_Id :=
3444 Entry_Call_Statement (Entry_Call_Alternative (N));
3445 Is_Disp_Select : Boolean := False;
3447 begin
3448 Tasking_Used := True;
3449 Check_Restriction (No_Select_Statements, N);
3451 -- Ada 2005 (AI-345): The trigger may be a dispatching call
3453 if Ada_Version >= Ada_2005 then
3454 Analyze (Trigger);
3455 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
3456 end if;
3458 -- Postpone the analysis of the statements till expansion. Analyze only
3459 -- if the expander is disabled in order to catch any semantic errors.
3461 if Is_Disp_Select then
3462 if not Expander_Active then
3463 Analyze (Entry_Call_Alternative (N));
3464 Analyze (Delay_Alternative (N));
3465 end if;
3467 -- Regular select analysis
3469 else
3470 Analyze (Entry_Call_Alternative (N));
3471 Analyze (Delay_Alternative (N));
3472 end if;
3473 end Analyze_Timed_Entry_Call;
3475 ------------------------------------
3476 -- Analyze_Triggering_Alternative --
3477 ------------------------------------
3479 procedure Analyze_Triggering_Alternative (N : Node_Id) is
3480 Trigger : constant Node_Id := Triggering_Statement (N);
3482 begin
3483 Tasking_Used := True;
3485 if Present (Pragmas_Before (N)) then
3486 Analyze_List (Pragmas_Before (N));
3487 end if;
3489 Analyze (Trigger);
3491 if Comes_From_Source (Trigger)
3492 and then Nkind (Trigger) not in N_Delay_Statement
3493 and then Nkind (Trigger) /= N_Entry_Call_Statement
3494 then
3495 if Ada_Version < Ada_2005 then
3496 Error_Msg_N
3497 ("triggering statement must be delay or entry call", Trigger);
3499 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
3500 -- procedure_or_entry_call, the procedure_name or procedure_prefix
3501 -- of the procedure_call_statement shall denote an entry renamed by a
3502 -- procedure, or (a view of) a primitive subprogram of a limited
3503 -- interface whose first parameter is a controlling parameter.
3505 elsif Nkind (Trigger) = N_Procedure_Call_Statement
3506 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
3507 and then not Is_Controlling_Limited_Procedure
3508 (Entity (Name (Trigger)))
3509 then
3510 Error_Msg_N
3511 ("triggering statement must be procedure or entry call " &
3512 "or delay statement", Trigger);
3513 end if;
3514 end if;
3516 if Is_Non_Empty_List (Statements (N)) then
3517 Analyze_Statements (Statements (N));
3518 end if;
3519 end Analyze_Triggering_Alternative;
3521 -----------------------
3522 -- Check_Max_Entries --
3523 -----------------------
3525 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
3526 Ecount : Uint;
3528 procedure Count (L : List_Id);
3529 -- Count entries in given declaration list
3531 -----------
3532 -- Count --
3533 -----------
3535 procedure Count (L : List_Id) is
3536 D : Node_Id;
3538 begin
3539 if No (L) then
3540 return;
3541 end if;
3543 D := First (L);
3544 while Present (D) loop
3545 if Nkind (D) = N_Entry_Declaration then
3546 declare
3547 DSD : constant Node_Id :=
3548 Discrete_Subtype_Definition (D);
3550 begin
3551 -- If not an entry family, then just one entry
3553 if No (DSD) then
3554 Ecount := Ecount + 1;
3556 -- If entry family with static bounds, count entries
3558 elsif Is_OK_Static_Subtype (Etype (DSD)) then
3559 declare
3560 Lo : constant Uint :=
3561 Expr_Value
3562 (Type_Low_Bound (Etype (DSD)));
3563 Hi : constant Uint :=
3564 Expr_Value
3565 (Type_High_Bound (Etype (DSD)));
3567 begin
3568 if Hi >= Lo then
3569 Ecount := Ecount + Hi - Lo + 1;
3570 end if;
3571 end;
3573 -- Entry family with non-static bounds
3575 else
3576 -- Record an unknown count restriction, and if the
3577 -- restriction is active, post a message or warning.
3579 Check_Restriction (R, D);
3580 end if;
3581 end;
3582 end if;
3584 Next (D);
3585 end loop;
3586 end Count;
3588 -- Start of processing for Check_Max_Entries
3590 begin
3591 Ecount := Uint_0;
3592 Count (Visible_Declarations (D));
3593 Count (Private_Declarations (D));
3595 if Ecount > 0 then
3596 Check_Restriction (R, D, Ecount);
3597 end if;
3598 end Check_Max_Entries;
3600 ----------------------
3601 -- Check_Interfaces --
3602 ----------------------
3604 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
3605 Iface : Node_Id;
3606 Iface_Typ : Entity_Id;
3608 begin
3609 pragma Assert
3610 (Nkind (N) in N_Protected_Type_Declaration | N_Task_Type_Declaration);
3612 if Present (Interface_List (N)) then
3613 Set_Is_Tagged_Type (T);
3615 -- The primitive operations of a tagged synchronized type are placed
3616 -- on the Corresponding_Record for proper dispatching, but are
3617 -- attached to the synchronized type itself when expansion is
3618 -- disabled.
3620 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3622 Iface := First (Interface_List (N));
3623 while Present (Iface) loop
3624 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
3626 if not Is_Interface (Iface_Typ) then
3627 Error_Msg_NE
3628 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
3630 else
3631 -- Ada 2005 (AI-251): "The declaration of a specific descendant
3632 -- of an interface type freezes the interface type" RM 13.14.
3634 Freeze_Before (N, Etype (Iface));
3636 if Nkind (N) = N_Protected_Type_Declaration then
3638 -- Ada 2005 (AI-345): Protected types can only implement
3639 -- limited, synchronized, or protected interfaces (note that
3640 -- the predicate Is_Limited_Interface includes synchronized
3641 -- and protected interfaces).
3643 if Is_Task_Interface (Iface_Typ) then
3644 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3645 & "a task interface", Iface);
3647 elsif not Is_Limited_Interface (Iface_Typ) then
3648 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3649 & "a non-limited interface", Iface);
3650 end if;
3652 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
3654 -- Ada 2005 (AI-345): Task types can only implement limited,
3655 -- synchronized, or task interfaces (note that the predicate
3656 -- Is_Limited_Interface includes synchronized and task
3657 -- interfaces).
3659 if Is_Protected_Interface (Iface_Typ) then
3660 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3661 "protected interface", Iface);
3663 elsif not Is_Limited_Interface (Iface_Typ) then
3664 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3665 "non-limited interface", Iface);
3666 end if;
3667 end if;
3668 end if;
3670 Next (Iface);
3671 end loop;
3673 -- Check consistency of any nonoverridable aspects that are
3674 -- inherited from multiple sources.
3676 Check_Inherited_Nonoverridable_Aspects
3677 (Inheritor => N,
3678 Interface_List => Interface_List (N),
3679 Parent_Type => Empty);
3680 end if;
3682 if not Has_Private_Declaration (T) then
3683 return;
3684 end if;
3686 -- Additional checks on full-types associated with private type
3687 -- declarations. Search for the private type declaration.
3689 declare
3690 Full_T_Ifaces : Elist_Id := No_Elist;
3691 Iface : Node_Id;
3692 Priv_T : Entity_Id;
3693 Priv_T_Ifaces : Elist_Id := No_Elist;
3695 begin
3696 Priv_T := First_Entity (Scope (T));
3697 loop
3698 pragma Assert (Present (Priv_T));
3700 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
3701 exit when Full_View (Priv_T) = T;
3702 end if;
3704 Next_Entity (Priv_T);
3705 end loop;
3707 -- In case of synchronized types covering interfaces the private type
3708 -- declaration must be limited.
3710 if Present (Interface_List (N))
3711 and then not Is_Limited_Type (Priv_T)
3712 then
3713 Error_Msg_Sloc := Sloc (Priv_T);
3714 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
3715 "private type#", T);
3716 end if;
3718 -- RM 7.3 (7.1/2): If the full view has a partial view that is
3719 -- tagged then check RM 7.3 subsidiary rules.
3721 if Is_Tagged_Type (Priv_T)
3722 and then not Error_Posted (N)
3723 then
3724 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
3725 -- type if and only if the full type is a synchronized tagged type
3727 if Is_Synchronized_Tagged_Type (Priv_T)
3728 and then not Is_Synchronized_Tagged_Type (T)
3729 then
3730 Error_Msg_N
3731 ("(Ada 2005) full view must be a synchronized tagged " &
3732 "type (RM 7.3 (7.2/2))", Priv_T);
3734 elsif Is_Synchronized_Tagged_Type (T)
3735 and then not Is_Synchronized_Tagged_Type (Priv_T)
3736 then
3737 Error_Msg_N
3738 ("(Ada 2005) partial view must be a synchronized tagged " &
3739 "type (RM 7.3 (7.2/2))", T);
3740 end if;
3742 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
3743 -- interface type if and only if the full type is descendant of
3744 -- the interface type.
3746 if Present (Interface_List (N))
3747 or else (Is_Tagged_Type (Priv_T)
3748 and then Has_Interfaces
3749 (Priv_T, Use_Full_View => False))
3750 then
3751 if Is_Tagged_Type (Priv_T) then
3752 Collect_Interfaces
3753 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
3754 end if;
3756 if Is_Tagged_Type (T) then
3757 Collect_Interfaces (T, Full_T_Ifaces);
3758 end if;
3760 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
3762 if Present (Iface) then
3763 Error_Msg_NE
3764 ("interface in partial view& not implemented by full "
3765 & "type (RM-2005 7.3 (7.3/2))", T, Iface);
3766 end if;
3768 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
3770 if Present (Iface) then
3771 Error_Msg_NE
3772 ("interface & not implemented by partial " &
3773 "view (RM-2005 7.3 (7.3/2))", T, Iface);
3774 end if;
3775 end if;
3776 end if;
3777 end;
3778 end Check_Interfaces;
3780 --------------------------------
3781 -- Check_Triggering_Statement --
3782 --------------------------------
3784 procedure Check_Triggering_Statement
3785 (Trigger : Node_Id;
3786 Error_Node : Node_Id;
3787 Is_Dispatching : out Boolean)
3789 Param : Node_Id;
3791 begin
3792 Is_Dispatching := False;
3794 -- It is not possible to have a dispatching trigger if we are not in
3795 -- Ada 2005 mode.
3797 if Ada_Version >= Ada_2005
3798 and then Nkind (Trigger) = N_Procedure_Call_Statement
3799 and then Present (Parameter_Associations (Trigger))
3800 then
3801 Param := First (Parameter_Associations (Trigger));
3803 if Is_Controlling_Actual (Param)
3804 and then Is_Interface (Etype (Param))
3805 then
3806 if Is_Limited_Record (Etype (Param)) then
3807 Is_Dispatching := True;
3808 else
3809 Error_Msg_N
3810 ("dispatching operation of limited or synchronized " &
3811 "interface required (RM 9.7.2(3))!", Error_Node);
3812 end if;
3814 elsif Nkind (Trigger) = N_Explicit_Dereference then
3815 Error_Msg_N
3816 ("entry call or dispatching primitive of interface required",
3817 Trigger);
3818 end if;
3819 end if;
3820 end Check_Triggering_Statement;
3822 --------------------------
3823 -- Find_Concurrent_Spec --
3824 --------------------------
3826 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
3827 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
3829 begin
3830 -- The type may have been given by an incomplete type declaration.
3831 -- Find full view now.
3833 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
3834 Spec_Id := Full_View (Spec_Id);
3835 end if;
3837 return Spec_Id;
3838 end Find_Concurrent_Spec;
3840 --------------------------
3841 -- Install_Declarations --
3842 --------------------------
3844 procedure Install_Declarations (Spec : Entity_Id) is
3845 E : Entity_Id;
3846 Prev : Entity_Id;
3847 begin
3848 E := First_Entity (Spec);
3849 while Present (E) loop
3850 Prev := Current_Entity (E);
3851 Set_Current_Entity (E);
3852 Set_Is_Immediately_Visible (E);
3853 Set_Homonym (E, Prev);
3854 Next_Entity (E);
3855 end loop;
3856 end Install_Declarations;
3858 end Sem_Ch9;