syscall, runtime: always call XSI strerror_r
[official-gcc.git] / gcc / ada / sem_ch9.adb
blobe43e3ae0b416f00bbe208461899c891d35e86eb2
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-2022, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Contracts; use Contracts;
30 with Einfo; use Einfo;
31 with Einfo.Entities; use Einfo.Entities;
32 with Einfo.Utils; use Einfo.Utils;
33 with Errout; use Errout;
34 with Exp_Ch9; use Exp_Ch9;
35 with Elists; use Elists;
36 with Freeze; use Freeze;
37 with Layout; use Layout;
38 with Lib; use Lib;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Opt; use Opt;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
47 with Sem; use Sem;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Ch3; use Sem_Ch3;
50 with Sem_Ch5; use Sem_Ch5;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Ch13; use Sem_Ch13;
54 with Sem_Elab; use Sem_Elab;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Type; use Sem_Type;
59 with Sem_Util; use Sem_Util;
60 with Sem_Warn; use Sem_Warn;
61 with Snames; use Snames;
62 with Stand; use Stand;
63 with Sinfo; use Sinfo;
64 with Sinfo.Nodes; use Sinfo.Nodes;
65 with Sinfo.Utils; use Sinfo.Utils;
66 with Style;
67 with Targparm; use Targparm;
68 with Tbuild; use Tbuild;
69 with Uintp; use Uintp;
71 package body Sem_Ch9 is
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 function Allows_Lock_Free_Implementation
78 (N : Node_Id;
79 Lock_Free_Given : Boolean := False) return Boolean;
80 -- This routine returns True iff N satisfies the following list of lock-
81 -- free restrictions for protected type declaration and protected body:
83 -- 1) Protected type declaration
84 -- May not contain entries
85 -- Protected subprogram declarations may not have non-elementary
86 -- parameters.
88 -- 2) Protected Body
89 -- Each protected subprogram body within N must satisfy:
90 -- May reference only one protected component
91 -- May not reference non-constant entities outside the protected
92 -- subprogram scope.
93 -- May not contain address representation items, allocators and
94 -- quantified expressions.
95 -- May not contain delay, goto, loop and procedure call
96 -- statements.
97 -- May not contain exported and imported entities
98 -- May not dereference access values
99 -- Function calls and attribute references must be static
101 -- If Lock_Free_Given is True, an error message is issued when False is
102 -- returned.
104 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions);
105 -- Given either a protected definition or a task definition in D, check
106 -- the corresponding restriction parameter identifier R, and if it is set,
107 -- count the entries (checking the static requirement), and compare with
108 -- the given maximum.
110 procedure Check_Interfaces (N : Node_Id; T : Entity_Id);
111 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
112 -- Complete decoration of T and check legality of the covered interfaces.
114 procedure Check_Triggering_Statement
115 (Trigger : Node_Id;
116 Error_Node : Node_Id;
117 Is_Dispatching : out Boolean);
118 -- Examine the triggering statement of a select statement, conditional or
119 -- timed entry call. If Trigger is a dispatching call, return its status
120 -- in Is_Dispatching and check whether the primitive belongs to a limited
121 -- interface. If it does not, emit an error at Error_Node.
123 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id;
124 -- Find entity in corresponding task or protected declaration. Use full
125 -- view if first declaration was for an incomplete type.
127 -------------------------------------
128 -- Allows_Lock_Free_Implementation --
129 -------------------------------------
131 function Allows_Lock_Free_Implementation
132 (N : Node_Id;
133 Lock_Free_Given : Boolean := False) return Boolean
135 Errors_Count : Nat := 0;
136 -- Errors_Count is a count of errors detected by the compiler so far
137 -- when Lock_Free_Given is True.
139 begin
140 pragma Assert
141 (Nkind (N) in N_Protected_Type_Declaration | N_Protected_Body);
143 -- Get the number of errors detected by the compiler so far
145 if Lock_Free_Given then
146 Errors_Count := Serious_Errors_Detected;
147 end if;
149 -- Protected type declaration case
151 if Nkind (N) = N_Protected_Type_Declaration then
152 declare
153 Pdef : constant Node_Id := Protected_Definition (N);
154 Priv_Decls : constant List_Id := Private_Declarations (Pdef);
155 Vis_Decls : constant List_Id := Visible_Declarations (Pdef);
156 Decl : Node_Id;
158 begin
159 -- Examine the visible and the private declarations
161 Decl := First (Vis_Decls);
162 while Present (Decl) loop
164 -- Entries and entry families are not allowed by the lock-free
165 -- restrictions.
167 if Nkind (Decl) = N_Entry_Declaration then
168 if Lock_Free_Given then
169 Error_Msg_N
170 ("entry not allowed when Lock_Free given", Decl);
171 else
172 return False;
173 end if;
175 -- Non-elementary parameters in protected procedure are not
176 -- allowed by the lock-free restrictions.
178 elsif Nkind (Decl) = N_Subprogram_Declaration
179 and then
180 Nkind (Specification (Decl)) = N_Procedure_Specification
181 then
182 declare
183 Par_Specs : constant List_Id :=
184 Parameter_Specifications
185 (Specification (Decl));
187 Par : Node_Id;
189 begin
190 Par := First (Par_Specs);
191 while Present (Par) loop
192 if not Is_Elementary_Type
193 (Etype (Defining_Identifier (Par)))
194 then
195 if Lock_Free_Given then
196 Error_Msg_NE
197 ("non-elementary parameter& not allowed "
198 & "when Lock_Free given",
199 Par, Defining_Identifier (Par));
200 else
201 return False;
202 end if;
203 end if;
205 Next (Par);
206 end loop;
207 end;
209 elsif Nkind (Decl) = N_Subprogram_Declaration
210 and then
211 Nkind (Specification (Decl)) = N_Function_Specification
212 and then
213 Nkind (Result_Definition (Specification (Decl)))
214 in N_Has_Entity
215 and then
216 Needs_Secondary_Stack
217 (Entity (Result_Definition (Specification (Decl))))
218 then
219 if Lock_Free_Given then
220 -- Message text is imprecise; "unconstrained" is
221 -- similar to "needs secondary stack" but not identical.
222 Error_Msg_N
223 ("unconstrained function result subtype not allowed "
224 & "when Lock_Free given",
225 Decl);
226 else
227 return False;
228 end if;
229 end if;
231 -- Examine private declarations after visible declarations
233 if No (Next (Decl))
234 and then List_Containing (Decl) = Vis_Decls
235 then
236 Decl := First (Priv_Decls);
237 else
238 Next (Decl);
239 end if;
240 end loop;
241 end;
243 -- Protected body case
245 else
246 Protected_Body_Case : declare
247 Decls : constant List_Id := Declarations (N);
248 Pid : constant Entity_Id := Corresponding_Spec (N);
249 Prot_Typ_Decl : constant Node_Id := Parent (Pid);
250 Prot_Def : constant Node_Id :=
251 Protected_Definition (Prot_Typ_Decl);
252 Priv_Decls : constant List_Id :=
253 Private_Declarations (Prot_Def);
254 Decl : Node_Id;
256 function Satisfies_Lock_Free_Requirements
257 (Sub_Body : Node_Id) return Boolean;
258 -- Return True if protected subprogram body Sub_Body satisfies all
259 -- requirements of a lock-free implementation.
261 --------------------------------------
262 -- Satisfies_Lock_Free_Requirements --
263 --------------------------------------
265 function Satisfies_Lock_Free_Requirements
266 (Sub_Body : Node_Id) return Boolean
268 Comp : Entity_Id := Empty;
269 -- Track the current component which the body references
271 Errors_Count : Nat := 0;
272 -- Errors_Count is a count of errors detected by the compiler
273 -- so far when Lock_Free_Given is True.
275 function Check_Node (N : Node_Id) return Traverse_Result;
276 -- Check that node N meets the lock free restrictions
278 ----------------
279 -- Check_Node --
280 ----------------
282 function Check_Node (N : Node_Id) return Traverse_Result is
283 Kind : constant Node_Kind := Nkind (N);
285 -- The following function belongs in sem_eval ???
287 function Is_Static_Function (Attr : Node_Id) return Boolean;
288 -- Given an attribute reference node Attr, return True if
289 -- Attr denotes a static function according to the rules in
290 -- (RM 4.9 (22)).
292 ------------------------
293 -- Is_Static_Function --
294 ------------------------
296 function Is_Static_Function
297 (Attr : Node_Id) return Boolean
299 Para : Node_Id;
301 begin
302 pragma Assert (Nkind (Attr) = N_Attribute_Reference);
304 case Attribute_Name (Attr) is
305 when Name_Max
306 | Name_Min
307 | Name_Pred
308 | Name_Succ
309 | Name_Value
310 | Name_Wide_Value
311 | Name_Wide_Wide_Value
313 -- A language-defined attribute denotes a static
314 -- function if the prefix denotes a static scalar
315 -- subtype, and if the parameter and result types
316 -- are scalar (RM 4.9 (22)).
318 if Is_Scalar_Type (Etype (Attr))
319 and then Is_Scalar_Type (Etype (Prefix (Attr)))
320 and then
321 Is_OK_Static_Subtype (Etype (Prefix (Attr)))
322 then
323 Para := First (Expressions (Attr));
325 while Present (Para) loop
326 if not Is_Scalar_Type (Etype (Para)) then
327 return False;
328 end if;
330 Next (Para);
331 end loop;
333 return True;
335 else
336 return False;
337 end if;
339 when others =>
340 return False;
341 end case;
342 end Is_Static_Function;
344 -- Start of processing for Check_Node
346 begin
347 -- Allocators restricted
349 if Kind = N_Allocator then
350 if Lock_Free_Given then
351 Error_Msg_N ("allocator not allowed", N);
352 return Skip;
353 end if;
355 return Abandon;
357 -- Aspects Address, Export and Import restricted
359 elsif Kind = N_Aspect_Specification then
360 declare
361 Asp_Name : constant Name_Id :=
362 Chars (Identifier (N));
363 Asp_Id : constant Aspect_Id :=
364 Get_Aspect_Id (Asp_Name);
366 begin
367 if Asp_Id = Aspect_Address or else
368 Asp_Id = Aspect_Export or else
369 Asp_Id = Aspect_Import
370 then
371 Error_Msg_Name_1 := Asp_Name;
373 if Lock_Free_Given then
374 Error_Msg_N ("aspect% not allowed", N);
375 return Skip;
376 end if;
378 return Abandon;
379 end if;
380 end;
382 -- Address attribute definition clause restricted
384 elsif Kind = N_Attribute_Definition_Clause
385 and then Get_Attribute_Id (Chars (N)) =
386 Attribute_Address
387 then
388 Error_Msg_Name_1 := Chars (N);
390 if Lock_Free_Given then
391 if From_Aspect_Specification (N) then
392 Error_Msg_N ("aspect% not allowed", N);
393 else
394 Error_Msg_N ("% clause not allowed", N);
395 end if;
397 return Skip;
398 end if;
400 return Abandon;
402 -- Non-static Attribute references that don't denote a
403 -- static function restricted.
405 elsif Kind = N_Attribute_Reference
406 and then not Is_OK_Static_Expression (N)
407 and then not Is_Static_Function (N)
408 then
409 if Lock_Free_Given then
410 Error_Msg_N
411 ("non-static attribute reference not allowed", N);
412 return Skip;
413 end if;
415 return Abandon;
417 -- Delay statements restricted
419 elsif Kind in N_Delay_Statement then
420 if Lock_Free_Given then
421 Error_Msg_N ("delay not allowed", N);
422 return Skip;
423 end if;
425 return Abandon;
427 -- Dereferences of access values restricted
429 elsif Kind = N_Explicit_Dereference
430 or else (Kind = N_Selected_Component
431 and then Is_Access_Type (Etype (Prefix (N))))
432 then
433 if Lock_Free_Given then
434 Error_Msg_N
435 ("dereference of access value not allowed", N);
436 return Skip;
437 end if;
439 return Abandon;
441 -- Non-static function calls restricted
443 elsif Kind = N_Function_Call
444 and then not Is_OK_Static_Expression (N)
445 then
446 if Lock_Free_Given then
447 Error_Msg_N
448 ("non-static function call not allowed", N);
449 return Skip;
450 end if;
452 return Abandon;
454 -- Goto statements restricted
456 elsif Kind in N_Goto_Statement | N_Goto_When_Statement then
457 if Lock_Free_Given then
458 Error_Msg_N ("goto statement not allowed", N);
459 return Skip;
460 end if;
462 return Abandon;
464 -- References
466 elsif Kind in N_Identifier | N_Expanded_Name
467 and then Present (Entity (N))
468 then
469 declare
470 Id : constant Entity_Id := Entity (N);
471 Sub_Id : constant Entity_Id :=
472 Corresponding_Spec (Sub_Body);
474 begin
475 -- Prohibit references to non-constant entities
476 -- outside the protected subprogram scope.
478 -- References to variables in System.Scalar_Values
479 -- generated because of pragma Initialize_Scalars are
480 -- allowed, because once those variables are
481 -- initialized by the binder-generated code, they
482 -- behave like constants.
484 if Is_Assignable (Id)
485 and then not
486 Scope_Within_Or_Same (Scope (Id), Sub_Id)
487 and then not
488 Scope_Within_Or_Same
489 (Scope (Id),
490 Protected_Body_Subprogram (Sub_Id))
491 and then not
492 (Is_RTU (Scope (Id), System_Scalar_Values)
493 and then not Comes_From_Source (N))
494 then
495 if Lock_Free_Given then
496 Error_Msg_NE
497 ("reference to global variable& not allowed",
498 N, Id);
499 return Skip;
500 end if;
502 return Abandon;
503 end if;
504 end;
506 -- Loop statements restricted
508 elsif Kind = N_Loop_Statement then
509 if Lock_Free_Given then
510 Error_Msg_N ("loop not allowed", N);
511 return Skip;
512 end if;
514 return Abandon;
516 -- Pragmas Export and Import restricted
518 elsif Kind = N_Pragma then
519 declare
520 Prag_Name : constant Name_Id :=
521 Pragma_Name (N);
522 Prag_Id : constant Pragma_Id :=
523 Get_Pragma_Id (Prag_Name);
525 begin
526 if Prag_Id = Pragma_Export
527 or else Prag_Id = Pragma_Import
528 then
529 Error_Msg_Name_1 := Prag_Name;
531 if Lock_Free_Given then
532 if From_Aspect_Specification (N) then
533 Error_Msg_N ("aspect% not allowed", N);
534 else
535 Error_Msg_N ("pragma% not allowed", N);
536 end if;
538 return Skip;
539 end if;
541 return Abandon;
542 end if;
543 end;
545 -- Procedure call statements restricted
547 elsif Kind = N_Procedure_Call_Statement then
548 if Lock_Free_Given then
549 Error_Msg_N ("procedure call not allowed", N);
550 return Skip;
551 end if;
553 return Abandon;
555 -- Quantified expression restricted. Note that we have
556 -- to check the original node as well, since at this
557 -- stage, it may have been rewritten.
559 elsif Kind = N_Quantified_Expression
560 or else
561 Nkind (Original_Node (N)) = N_Quantified_Expression
562 then
563 if Lock_Free_Given then
564 Error_Msg_N
565 ("quantified expression not allowed", N);
566 return Skip;
567 end if;
569 return Abandon;
570 end if;
572 -- A protected subprogram (function or procedure) may
573 -- reference only one component of the protected type, plus
574 -- the type of the component must support atomic operation.
576 if Kind in N_Identifier | N_Expanded_Name
577 and then Present (Entity (N))
578 then
579 declare
580 Id : constant Entity_Id := Entity (N);
581 Comp_Decl : Node_Id;
582 Comp_Id : Entity_Id := Empty;
583 Comp_Type : Entity_Id;
585 begin
586 if Ekind (Id) = E_Component then
587 Comp_Id := Id;
589 elsif Ekind (Id) in E_Constant | E_Variable
590 and then Present (Prival_Link (Id))
591 then
592 Comp_Id := Prival_Link (Id);
593 end if;
595 if Present (Comp_Id) then
596 Comp_Decl := Parent (Comp_Id);
597 Comp_Type := Etype (Comp_Id);
599 if Nkind (Comp_Decl) = N_Component_Declaration
600 and then Is_List_Member (Comp_Decl)
601 and then List_Containing (Comp_Decl) = Priv_Decls
602 then
603 -- Skip generic types since, in that case, we
604 -- will not build a body anyway (in the generic
605 -- template), and the size in the template may
606 -- have a fake value.
608 if not Is_Generic_Type (Comp_Type) then
610 -- Make sure the protected component type has
611 -- size and alignment fields set at this
612 -- point whenever this is possible.
614 Layout_Type (Comp_Type);
616 if not
617 Support_Atomic_Primitives (Comp_Type)
618 then
619 if Lock_Free_Given then
620 Error_Msg_NE
621 ("type of& must support atomic " &
622 "operations",
623 N, Comp_Id);
624 return Skip;
625 end if;
627 return Abandon;
628 end if;
629 end if;
631 -- Check if another protected component has
632 -- already been accessed by the subprogram body.
634 if No (Comp) then
635 Comp := Comp_Id;
637 elsif Comp /= Comp_Id then
638 if Lock_Free_Given then
639 Error_Msg_N
640 ("only one protected component allowed",
642 return Skip;
643 end if;
645 return Abandon;
646 end if;
647 end if;
648 end if;
649 end;
650 end if;
652 return OK;
653 end Check_Node;
655 function Check_All_Nodes is new Traverse_Func (Check_Node);
657 -- Start of processing for Satisfies_Lock_Free_Requirements
659 begin
660 if not Support_Atomic_Primitives_On_Target then
661 if Lock_Free_Given then
662 Error_Msg_N
663 ("Lock_Free aspect requires target support for "
664 & "atomic primitives", N);
665 end if;
666 return False;
667 end if;
669 -- Deal with case where Ceiling_Locking locking policy is
670 -- in effect.
672 if Locking_Policy = 'C' then
673 if Lock_Free_Given then
674 -- Explicit Lock_Free aspect spec overrides
675 -- Ceiling_Locking so we generate a warning.
677 Error_Msg_N
678 ("Lock_Free aspect specification overrides "
679 & "Ceiling_Locking locking policy??", N);
680 else
681 -- If Ceiling_Locking locking policy is in effect, then
682 -- Lock_Free can be explicitly specified but it is
683 -- never the default.
685 return False;
686 end if;
687 end if;
689 -- Get the number of errors detected by the compiler so far
691 if Lock_Free_Given then
692 Errors_Count := Serious_Errors_Detected;
693 end if;
695 if Check_All_Nodes (Sub_Body) = OK
696 and then (not Lock_Free_Given
697 or else Errors_Count = Serious_Errors_Detected)
698 then
699 -- Establish a relation between the subprogram body and the
700 -- unique protected component it references.
702 if Present (Comp) then
703 Lock_Free_Subprogram_Table.Append
704 (Lock_Free_Subprogram'(Sub_Body, Comp));
705 end if;
707 return True;
708 else
709 return False;
710 end if;
711 end Satisfies_Lock_Free_Requirements;
713 -- Start of processing for Protected_Body_Case
715 begin
716 Decl := First (Decls);
717 while Present (Decl) loop
718 if Nkind (Decl) = N_Subprogram_Body
719 and then not Satisfies_Lock_Free_Requirements (Decl)
720 then
721 if Lock_Free_Given then
722 Error_Msg_N
723 ("illegal body when Lock_Free given", Decl);
724 else
725 return False;
726 end if;
727 end if;
729 Next (Decl);
730 end loop;
731 end Protected_Body_Case;
732 end if;
734 -- When Lock_Free is given, check if no error has been detected during
735 -- the process.
737 if Lock_Free_Given
738 and then Errors_Count /= Serious_Errors_Detected
739 then
740 return False;
741 end if;
743 return True;
744 end Allows_Lock_Free_Implementation;
746 -----------------------------
747 -- Analyze_Abort_Statement --
748 -----------------------------
750 procedure Analyze_Abort_Statement (N : Node_Id) is
751 T_Name : Node_Id;
753 begin
754 Tasking_Used := True;
756 T_Name := First (Names (N));
757 while Present (T_Name) loop
758 Analyze (T_Name);
760 if Is_Task_Type (Etype (T_Name))
761 or else (Ada_Version >= Ada_2005
762 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
763 and then Is_Interface (Etype (T_Name))
764 and then Is_Task_Interface (Etype (T_Name)))
765 then
766 Resolve (T_Name);
767 else
768 if Ada_Version >= Ada_2005 then
769 Error_Msg_N ("expect task name or task interface class-wide "
770 & "object for ABORT", T_Name);
771 else
772 Error_Msg_N ("expect task name for ABORT", T_Name);
773 end if;
775 return;
776 end if;
778 Next (T_Name);
779 end loop;
781 Check_Restriction (No_Abort_Statements, N);
782 Check_Potentially_Blocking_Operation (N);
783 end Analyze_Abort_Statement;
785 --------------------------------
786 -- Analyze_Accept_Alternative --
787 --------------------------------
789 procedure Analyze_Accept_Alternative (N : Node_Id) is
790 begin
791 Tasking_Used := True;
793 if Present (Pragmas_Before (N)) then
794 Analyze_List (Pragmas_Before (N));
795 end if;
797 if Present (Condition (N)) then
798 Analyze_And_Resolve (Condition (N), Any_Boolean);
799 end if;
801 Analyze (Accept_Statement (N));
803 if Is_Non_Empty_List (Statements (N)) then
804 Analyze_Statements (Statements (N));
805 end if;
806 end Analyze_Accept_Alternative;
808 ------------------------------
809 -- Analyze_Accept_Statement --
810 ------------------------------
812 procedure Analyze_Accept_Statement (N : Node_Id) is
813 Nam : constant Entity_Id := Entry_Direct_Name (N);
814 Formals : constant List_Id := Parameter_Specifications (N);
815 Index : constant Node_Id := Entry_Index (N);
816 Stats : constant Node_Id := Handled_Statement_Sequence (N);
817 Accept_Id : Entity_Id;
818 Entry_Nam : Entity_Id;
819 E : Entity_Id;
820 Kind : Entity_Kind;
821 Task_Nam : Entity_Id := Empty; -- initialize to prevent warning
823 begin
824 Tasking_Used := True;
826 -- Entry name is initialized to Any_Id. It should get reset to the
827 -- matching entry entity. An error is signalled if it is not reset.
829 Entry_Nam := Any_Id;
831 for J in reverse 0 .. Scope_Stack.Last loop
832 Task_Nam := Scope_Stack.Table (J).Entity;
833 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
834 Kind := Ekind (Task_Nam);
836 if Kind /= E_Block and then Kind /= E_Loop
837 and then not Is_Entry (Task_Nam)
838 then
839 Error_Msg_N ("enclosing body of ACCEPT must be a task", N);
840 return;
841 end if;
842 end loop;
844 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
845 Error_Msg_N ("invalid context for ACCEPT statement", N);
846 return;
847 end if;
849 -- In order to process the parameters, we create a defining identifier
850 -- that can be used as the name of the scope. The name of the accept
851 -- statement itself is not a defining identifier, and we cannot use
852 -- its name directly because the task may have any number of accept
853 -- statements for the same entry.
855 if Present (Index) then
856 Accept_Id := New_Internal_Entity
857 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
858 else
859 Accept_Id := New_Internal_Entity
860 (E_Entry, Current_Scope, Sloc (N), 'E');
861 end if;
863 Set_Etype (Accept_Id, Standard_Void_Type);
864 Set_Accept_Address (Accept_Id, New_Elmt_List);
866 if Present (Formals) then
867 Push_Scope (Accept_Id);
868 Process_Formals (Formals, N);
869 Create_Extra_Formals (Accept_Id);
870 End_Scope;
871 end if;
873 -- We set the default expressions processed flag because we don't need
874 -- default expression functions. This is really more like body entity
875 -- than a spec entity anyway.
877 Set_Default_Expressions_Processed (Accept_Id);
879 E := First_Entity (Etype (Task_Nam));
880 while Present (E) loop
881 if Chars (E) = Chars (Nam)
882 and then (Ekind (E) = Ekind (Accept_Id))
883 and then Type_Conformant (Accept_Id, E)
884 then
885 Entry_Nam := E;
886 exit;
887 end if;
889 Next_Entity (E);
890 end loop;
892 if Entry_Nam = Any_Id then
893 Error_Msg_N ("no entry declaration matches ACCEPT statement", N);
894 return;
895 else
896 Set_Entity (Nam, Entry_Nam);
897 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
898 Style.Check_Identifier (Nam, Entry_Nam);
899 end if;
901 -- Verify that the entry is not hidden by a procedure declared in the
902 -- current block (pathological but possible).
904 if Current_Scope /= Task_Nam then
905 declare
906 E1 : Entity_Id;
908 begin
909 E1 := First_Entity (Current_Scope);
910 while Present (E1) loop
911 if Ekind (E1) = E_Procedure
912 and then Chars (E1) = Chars (Entry_Nam)
913 and then Type_Conformant (E1, Entry_Nam)
914 then
915 Error_Msg_N ("entry name is not visible", N);
916 end if;
918 Next_Entity (E1);
919 end loop;
920 end;
921 end if;
923 Set_Convention (Accept_Id, Convention (Entry_Nam));
924 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
926 for J in reverse 0 .. Scope_Stack.Last loop
927 exit when Task_Nam = Scope_Stack.Table (J).Entity;
929 if Entry_Nam = Scope_Stack.Table (J).Entity then
930 Error_Msg_N
931 ("duplicate ACCEPT statement for same entry (RM 9.5.2 (15))", N);
933 -- Do not continue analysis of accept statement, to prevent
934 -- cascaded errors.
936 return;
937 end if;
938 end loop;
940 declare
941 P : Node_Id := N;
942 begin
943 loop
944 P := Parent (P);
945 case Nkind (P) is
946 when N_Compilation_Unit
947 | N_Task_Body
949 exit;
951 when N_Asynchronous_Select =>
952 Error_Msg_N
953 ("ACCEPT statement not allowed within an "
954 & "asynchronous SELECT inner to the enclosing task body",
956 exit;
958 when others =>
959 null;
960 end case;
961 end loop;
962 end;
964 if Ekind (Entry_Nam) = E_Entry_Family then
965 if No (Index) then
966 Error_Msg_N ("missing entry index in accept for entry family", N);
967 else
968 Analyze_And_Resolve (Index, Entry_Index_Type (Entry_Nam));
969 Apply_Scalar_Range_Check (Index, Entry_Index_Type (Entry_Nam));
970 end if;
972 elsif Present (Index) then
973 Error_Msg_N ("invalid entry index in accept for simple entry", N);
974 end if;
976 -- If label declarations present, analyze them. They are declared in the
977 -- enclosing task, but their enclosing scope is the entry itself, so
978 -- that goto's to the label are recognized as local to the accept.
980 if Present (Declarations (N)) then
981 declare
982 Decl : Node_Id;
983 Id : Entity_Id;
985 begin
986 Decl := First (Declarations (N));
987 while Present (Decl) loop
988 Analyze (Decl);
990 pragma Assert
991 (Nkind (Decl) = N_Implicit_Label_Declaration);
993 Id := Defining_Identifier (Decl);
994 Set_Enclosing_Scope (Id, Entry_Nam);
995 Next (Decl);
996 end loop;
997 end;
998 end if;
1000 -- If statements are present, they must be analyzed in the context of
1001 -- the entry, so that references to formals are correctly resolved. We
1002 -- also have to add the declarations that are required by the expansion
1003 -- of the accept statement in this case if expansion active.
1005 -- In the case of a select alternative of a selective accept, the
1006 -- expander references the address declaration even if there is no
1007 -- statement list.
1009 -- We also need to create the renaming declarations for the local
1010 -- variables that will replace references to the formals within the
1011 -- accept statement.
1013 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
1015 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
1016 -- fields on all entry formals (this loop ignores all other entities).
1017 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
1018 -- well, so that we can post accurate warnings on each accept statement
1019 -- for the same entry.
1021 E := First_Entity (Entry_Nam);
1022 while Present (E) loop
1023 if Is_Formal (E) then
1024 Set_Never_Set_In_Source (E, True);
1025 Set_Is_True_Constant (E, False);
1026 Set_Current_Value (E, Empty);
1027 Set_Referenced (E, False);
1028 Set_Referenced_As_LHS (E, False);
1029 Set_Referenced_As_Out_Parameter (E, False);
1030 Set_Has_Pragma_Unreferenced (E, False);
1031 end if;
1033 Next_Entity (E);
1034 end loop;
1036 -- Analyze statements if present
1038 if Present (Stats) then
1039 Push_Scope (Entry_Nam);
1040 Install_Declarations (Entry_Nam);
1042 Set_Actual_Subtypes (N, Current_Scope);
1044 Analyze (Stats);
1045 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
1046 End_Scope;
1047 end if;
1049 -- Some warning checks
1051 Check_Potentially_Blocking_Operation (N);
1052 Check_References (Entry_Nam, N);
1053 Set_Entry_Accepted (Entry_Nam);
1054 end Analyze_Accept_Statement;
1056 ---------------------------------
1057 -- Analyze_Asynchronous_Select --
1058 ---------------------------------
1060 procedure Analyze_Asynchronous_Select (N : Node_Id) is
1061 Is_Disp_Select : Boolean := False;
1062 Trigger : Node_Id;
1064 begin
1065 Tasking_Used := True;
1066 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
1067 Check_Restriction (No_Select_Statements, N);
1069 if Ada_Version >= Ada_2005 then
1070 Trigger := Triggering_Statement (Triggering_Alternative (N));
1072 Analyze (Trigger);
1074 -- Ada 2005 (AI-345): Check for a potential dispatching select
1076 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1077 end if;
1079 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
1080 -- select will have to duplicate the triggering statements. Postpone
1081 -- the analysis of the statements till expansion. Analyze only if the
1082 -- expander is disabled in order to catch any semantic errors.
1084 if Is_Disp_Select then
1085 if not Expander_Active then
1086 Analyze_Statements (Statements (Abortable_Part (N)));
1087 Analyze (Triggering_Alternative (N));
1088 end if;
1090 -- Analyze the statements. We analyze statements in the abortable part,
1091 -- because this is the section that is executed first, and that way our
1092 -- remembering of saved values and checks is accurate.
1094 else
1095 Analyze_Statements (Statements (Abortable_Part (N)));
1096 Analyze (Triggering_Alternative (N));
1097 end if;
1098 end Analyze_Asynchronous_Select;
1100 ------------------------------------
1101 -- Analyze_Conditional_Entry_Call --
1102 ------------------------------------
1104 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
1105 Trigger : constant Node_Id :=
1106 Entry_Call_Statement (Entry_Call_Alternative (N));
1107 Is_Disp_Select : Boolean := False;
1109 begin
1110 Tasking_Used := True;
1111 Check_Restriction (No_Select_Statements, N);
1113 -- Ada 2005 (AI-345): The trigger may be a dispatching call
1115 if Ada_Version >= Ada_2005 then
1116 Analyze (Trigger);
1117 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1118 end if;
1120 if List_Length (Else_Statements (N)) = 1
1121 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
1122 then
1123 Error_Msg_N
1124 ("suspicious form of conditional entry call??!", N);
1125 Error_Msg_N
1126 ("\`SELECT OR` may be intended rather than `SELECT ELSE`??!", N);
1127 end if;
1129 -- Postpone the analysis of the statements till expansion. Analyze only
1130 -- if the expander is disabled in order to catch any semantic errors.
1132 if Is_Disp_Select then
1133 if not Expander_Active then
1134 Analyze (Entry_Call_Alternative (N));
1135 Analyze_Statements (Else_Statements (N));
1136 end if;
1138 -- Regular select analysis
1140 else
1141 Analyze (Entry_Call_Alternative (N));
1142 Analyze_Statements (Else_Statements (N));
1143 end if;
1144 end Analyze_Conditional_Entry_Call;
1146 --------------------------------
1147 -- Analyze_Delay_Alternative --
1148 --------------------------------
1150 procedure Analyze_Delay_Alternative (N : Node_Id) is
1151 Expr : Node_Id;
1152 Typ : Entity_Id;
1154 begin
1155 Tasking_Used := True;
1156 Check_Restriction (No_Delay, N);
1158 if Present (Pragmas_Before (N)) then
1159 Analyze_List (Pragmas_Before (N));
1160 end if;
1162 if Nkind (Parent (N)) in N_Selective_Accept | N_Timed_Entry_Call then
1163 Expr := Expression (Delay_Statement (N));
1165 -- Defer full analysis until the statement is expanded, to insure
1166 -- that generated code does not move past the guard. The delay
1167 -- expression is only evaluated if the guard is open.
1169 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
1170 Preanalyze_And_Resolve (Expr, Standard_Duration);
1171 else
1172 Preanalyze_And_Resolve (Expr);
1173 end if;
1175 Typ := First_Subtype (Etype (Expr));
1177 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
1178 and then not Is_RTE (Typ, RO_CA_Time)
1179 and then not Is_RTE (Typ, RO_RT_Time)
1180 then
1181 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
1182 end if;
1184 Check_Restriction (No_Fixed_Point, Expr);
1186 else
1187 Analyze (Delay_Statement (N));
1188 end if;
1190 if Present (Condition (N)) then
1191 Analyze_And_Resolve (Condition (N), Any_Boolean);
1192 end if;
1194 if Is_Non_Empty_List (Statements (N)) then
1195 Analyze_Statements (Statements (N));
1196 end if;
1197 end Analyze_Delay_Alternative;
1199 ----------------------------
1200 -- Analyze_Delay_Relative --
1201 ----------------------------
1203 procedure Analyze_Delay_Relative (N : Node_Id) is
1204 E : constant Node_Id := Expression (N);
1206 begin
1207 Tasking_Used := True;
1208 Check_Restriction (No_Relative_Delay, N);
1209 Check_Restriction (No_Delay, N);
1210 Check_Potentially_Blocking_Operation (N);
1211 Analyze_And_Resolve (E, Standard_Duration);
1212 Check_Restriction (No_Fixed_Point, E);
1214 -- In SPARK mode the relative delay statement introduces an implicit
1215 -- dependency on the Ada.Real_Time.Clock_Time abstract state, so we must
1216 -- force the loading of the Ada.Real_Time package.
1218 if GNATprove_Mode then
1219 SPARK_Implicit_Load (RO_RT_Time);
1220 end if;
1221 end Analyze_Delay_Relative;
1223 -------------------------
1224 -- Analyze_Delay_Until --
1225 -------------------------
1227 procedure Analyze_Delay_Until (N : Node_Id) is
1228 E : constant Node_Id := Expression (N);
1229 Typ : Entity_Id;
1231 begin
1232 Tasking_Used := True;
1233 Check_Restriction (No_Delay, N);
1234 Check_Potentially_Blocking_Operation (N);
1235 Analyze_And_Resolve (E);
1236 Typ := First_Subtype (Etype (E));
1238 if not Is_RTE (Typ, RO_CA_Time) and then
1239 not Is_RTE (Typ, RO_RT_Time)
1240 then
1241 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
1242 end if;
1243 end Analyze_Delay_Until;
1245 ------------------------
1246 -- Analyze_Entry_Body --
1247 ------------------------
1249 procedure Analyze_Entry_Body (N : Node_Id) is
1250 Id : constant Entity_Id := Defining_Identifier (N);
1251 Decls : constant List_Id := Declarations (N);
1252 Stats : constant Node_Id := Handled_Statement_Sequence (N);
1253 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1254 P_Type : constant Entity_Id := Current_Scope;
1255 E : Entity_Id;
1256 Entry_Name : Entity_Id;
1258 begin
1259 -- An entry body freezes the contract of the nearest enclosing package
1260 -- body and all other contracts encountered in the same declarative part
1261 -- up to and excluding the entry body. This ensures that any annotations
1262 -- referenced by the contract of an entry or subprogram body declared
1263 -- within the current protected body are available.
1265 Freeze_Previous_Contracts (N);
1267 Tasking_Used := True;
1269 -- Entry_Name is initialized to Any_Id. It should get reset to the
1270 -- matching entry entity. An error is signalled if it is not reset.
1272 Entry_Name := Any_Id;
1274 Analyze (Formals);
1276 if Present (Entry_Index_Specification (Formals)) then
1277 Mutate_Ekind (Id, E_Entry_Family);
1278 else
1279 Mutate_Ekind (Id, E_Entry);
1280 end if;
1282 Set_Etype (Id, Standard_Void_Type);
1283 Set_Scope (Id, Current_Scope);
1284 Set_Accept_Address (Id, New_Elmt_List);
1286 -- Set the SPARK_Mode from the current context (may be overwritten later
1287 -- with an explicit pragma).
1289 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1290 Set_SPARK_Pragma_Inherited (Id);
1292 -- Analyze any aspect specifications that appear on the entry body
1294 if Has_Aspects (N) then
1295 Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
1296 end if;
1298 E := First_Entity (P_Type);
1299 while Present (E) loop
1300 if Chars (E) = Chars (Id)
1301 and then Ekind (E) = Ekind (Id)
1302 and then Type_Conformant (Id, E)
1303 then
1304 Entry_Name := E;
1305 Set_Convention (Id, Convention (E));
1306 Set_Corresponding_Body (Parent (E), Id);
1307 Check_Fully_Conformant (Id, E, N);
1309 if Ekind (Id) = E_Entry_Family then
1310 if not Fully_Conformant_Discrete_Subtypes (
1311 Discrete_Subtype_Definition (Parent (E)),
1312 Discrete_Subtype_Definition
1313 (Entry_Index_Specification (Formals)))
1314 then
1315 Error_Msg_N
1316 ("index not fully conformant with previous declaration",
1317 Discrete_Subtype_Definition
1318 (Entry_Index_Specification (Formals)));
1320 else
1321 -- The elaboration of the entry body does not recompute the
1322 -- bounds of the index, which may have side effects. Inherit
1323 -- the bounds from the entry declaration. This is critical
1324 -- if the entry has a per-object constraint. If a bound is
1325 -- given by a discriminant, it must be reanalyzed in order
1326 -- to capture the discriminal of the current entry, rather
1327 -- than that of the protected type.
1329 declare
1330 Index_Spec : constant Node_Id :=
1331 Entry_Index_Specification (Formals);
1333 Def : constant Node_Id :=
1334 New_Copy_Tree
1335 (Discrete_Subtype_Definition (Parent (E)));
1337 begin
1338 if Nkind
1339 (Original_Node
1340 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
1341 then
1342 Set_Etype (Def, Empty);
1343 Set_Analyzed (Def, False);
1345 -- Keep the original subtree to ensure a properly
1346 -- formed tree.
1348 Rewrite
1349 (Discrete_Subtype_Definition (Index_Spec), Def);
1351 Set_Analyzed (Low_Bound (Def), False);
1352 Set_Analyzed (High_Bound (Def), False);
1354 if Denotes_Discriminant (Low_Bound (Def)) then
1355 Set_Entity (Low_Bound (Def), Empty);
1356 end if;
1358 if Denotes_Discriminant (High_Bound (Def)) then
1359 Set_Entity (High_Bound (Def), Empty);
1360 end if;
1362 Analyze (Def);
1363 Make_Index (Def, Index_Spec);
1364 Set_Etype
1365 (Defining_Identifier (Index_Spec), Etype (Def));
1366 end if;
1367 end;
1368 end if;
1369 end if;
1371 exit;
1372 end if;
1374 Next_Entity (E);
1375 end loop;
1377 if Entry_Name = Any_Id then
1378 Error_Msg_N ("no entry declaration matches entry body", N);
1379 return;
1381 elsif Has_Completion (Entry_Name) then
1382 Error_Msg_N ("duplicate entry body", N);
1383 return;
1385 else
1386 Set_Has_Completion (Entry_Name);
1387 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
1388 Style.Check_Identifier (Id, Entry_Name);
1389 end if;
1391 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
1392 Push_Scope (Entry_Name);
1394 Install_Declarations (Entry_Name);
1395 Set_Actual_Subtypes (N, Current_Scope);
1397 -- The entity for the protected subprogram corresponding to the entry
1398 -- has been created. We retain the name of this entity in the entry
1399 -- body, for use when the corresponding subprogram body is created.
1400 -- Note that entry bodies have no Corresponding_Spec, and there is no
1401 -- easy link back in the tree between the entry body and the entity for
1402 -- the entry itself, which is why we must propagate some attributes
1403 -- explicitly from spec to body.
1405 Set_Protected_Body_Subprogram
1406 (Id, Protected_Body_Subprogram (Entry_Name));
1408 Set_Entry_Parameters_Type
1409 (Id, Entry_Parameters_Type (Entry_Name));
1411 -- Add a declaration for the Protection object, renaming declarations
1412 -- for the discriminals and privals and finally a declaration for the
1413 -- entry family index (if applicable).
1415 if Expander_Active
1416 and then Is_Protected_Type (P_Type)
1417 then
1418 Install_Private_Data_Declarations
1419 (Sloc (N), Entry_Name, P_Type, N, Decls);
1420 end if;
1422 if Present (Decls) then
1423 Analyze_Declarations (Decls);
1424 Inspect_Deferred_Constant_Completion (Decls);
1425 end if;
1427 -- Process the contract of the subprogram body after all declarations
1428 -- have been analyzed. This ensures that any contract-related pragmas
1429 -- are available through the N_Contract node of the body.
1431 Analyze_Entry_Or_Subprogram_Body_Contract (Id);
1433 if Present (Stats) then
1434 Analyze (Stats);
1435 end if;
1437 -- Check for unreferenced variables etc. Before the Check_References
1438 -- call, we transfer Never_Set_In_Source and Referenced flags from
1439 -- parameters in the spec to the corresponding entities in the body,
1440 -- since we want the warnings on the body entities. Note that we do not
1441 -- have to transfer Referenced_As_LHS, since that flag can only be set
1442 -- for simple variables, but we include Has_Pragma_Unreferenced,
1443 -- which may have been specified for a formal in the body.
1445 -- At the same time, we set the flags on the spec entities to suppress
1446 -- any warnings on the spec formals, since we also scan the spec.
1447 -- Finally, we propagate the Entry_Component attribute to the body
1448 -- formals, for use in the renaming declarations created later for the
1449 -- formals (see exp_ch9.Add_Formal_Renamings).
1451 declare
1452 E1 : Entity_Id;
1453 E2 : Entity_Id;
1455 begin
1456 E1 := First_Entity (Entry_Name);
1457 while Present (E1) loop
1458 E2 := First_Entity (Id);
1459 while Present (E2) loop
1460 exit when Chars (E1) = Chars (E2);
1461 Next_Entity (E2);
1462 end loop;
1464 -- If no matching body entity, then we already had a detected
1465 -- error of some kind, so just don't worry about these warnings.
1467 if No (E2) then
1468 goto Continue;
1469 end if;
1471 if Ekind (E1) = E_Out_Parameter then
1472 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1473 Set_Never_Set_In_Source (E1, False);
1474 end if;
1476 Set_Referenced (E2, Referenced (E1));
1477 Set_Referenced (E1);
1478 Set_Has_Pragma_Unreferenced (E2, Has_Pragma_Unreferenced (E1));
1479 Set_Entry_Component (E2, Entry_Component (E1));
1481 <<Continue>>
1482 Next_Entity (E1);
1483 end loop;
1485 Check_References (Id);
1486 end;
1488 -- We still need to check references for the spec, since objects
1489 -- declared in the body are chained (in the First_Entity sense) to
1490 -- the spec rather than the body in the case of entries.
1492 Check_References (Entry_Name);
1494 -- Process the end label, and terminate the scope
1496 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
1497 Update_Use_Clause_Chain;
1498 End_Scope;
1500 -- If this is an entry family, remove the loop created to provide
1501 -- a scope for the entry index.
1503 if Ekind (Id) = E_Entry_Family
1504 and then Present (Entry_Index_Specification (Formals))
1505 then
1506 End_Scope;
1507 end if;
1508 end Analyze_Entry_Body;
1510 ------------------------------------
1511 -- Analyze_Entry_Body_Formal_Part --
1512 ------------------------------------
1514 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
1515 Id : constant Entity_Id := Defining_Identifier (Parent (N));
1516 Index : constant Node_Id := Entry_Index_Specification (N);
1517 Formals : constant List_Id := Parameter_Specifications (N);
1519 begin
1520 Tasking_Used := True;
1522 if Present (Index) then
1523 Analyze (Index);
1525 -- The entry index functions like a loop variable, thus it is known
1526 -- to have a valid value.
1528 Set_Is_Known_Valid (Defining_Identifier (Index));
1529 end if;
1531 if Present (Formals) then
1532 Set_Scope (Id, Current_Scope);
1533 Push_Scope (Id);
1534 Process_Formals (Formals, Parent (N));
1535 End_Scope;
1536 end if;
1537 end Analyze_Entry_Body_Formal_Part;
1539 ------------------------------------
1540 -- Analyze_Entry_Call_Alternative --
1541 ------------------------------------
1543 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
1544 Call : constant Node_Id := Entry_Call_Statement (N);
1546 begin
1547 Tasking_Used := True;
1549 if Present (Pragmas_Before (N)) then
1550 Analyze_List (Pragmas_Before (N));
1551 end if;
1553 if Nkind (Call) = N_Attribute_Reference then
1555 -- Possibly a stream attribute, but definitely illegal. Other
1556 -- illegalities, such as procedure calls, are diagnosed after
1557 -- resolution.
1559 Error_Msg_N ("entry call alternative requires an entry call", Call);
1560 return;
1561 end if;
1563 Analyze (Call);
1565 -- An indirect call in this context is illegal. A procedure call that
1566 -- does not involve a renaming of an entry is illegal as well, but this
1567 -- and other semantic errors are caught during resolution.
1569 if Nkind (Call) = N_Explicit_Dereference then
1570 Error_Msg_N
1571 ("entry call or dispatching primitive of interface required", N);
1572 end if;
1574 if Is_Non_Empty_List (Statements (N)) then
1575 Analyze_Statements (Statements (N));
1576 end if;
1577 end Analyze_Entry_Call_Alternative;
1579 -------------------------------
1580 -- Analyze_Entry_Declaration --
1581 -------------------------------
1583 procedure Analyze_Entry_Declaration (N : Node_Id) is
1584 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
1585 Def_Id : constant Entity_Id := Defining_Identifier (N);
1586 Formals : constant List_Id := Parameter_Specifications (N);
1588 begin
1589 Generate_Definition (Def_Id);
1591 Tasking_Used := True;
1593 -- Case of no discrete subtype definition
1595 if No (D_Sdef) then
1596 Mutate_Ekind (Def_Id, E_Entry);
1598 -- Processing for discrete subtype definition present
1600 else
1601 Enter_Name (Def_Id);
1602 Mutate_Ekind (Def_Id, E_Entry_Family);
1603 Analyze (D_Sdef);
1604 Make_Index (D_Sdef, N, Def_Id);
1606 -- Check subtype with predicate in entry family
1608 Bad_Predicated_Subtype_Use
1609 ("subtype& has predicate, not allowed in entry family",
1610 D_Sdef, Etype (D_Sdef));
1612 -- Check entry family static bounds outside allowed limits
1614 -- Note: originally this check was not performed here, but in that
1615 -- case the check happens deep in the expander, and the message is
1616 -- posted at the wrong location, and omitted in -gnatc mode.
1617 -- If the type of the entry index is a generic formal, no check
1618 -- is possible. In an instance, the check is not static and a run-
1619 -- time exception will be raised if the bounds are unreasonable.
1621 declare
1622 PEI : constant Entity_Id := RTE (RE_Protected_Entry_Index);
1623 LB : constant Uint := Expr_Value (Type_Low_Bound (PEI));
1624 UB : constant Uint := Expr_Value (Type_High_Bound (PEI));
1626 LBR : Node_Id;
1627 UBR : Node_Id;
1629 begin
1631 -- No bounds checking if the type is generic or if previous error.
1632 -- In an instance the check is dynamic.
1634 if Is_Generic_Type (Etype (D_Sdef))
1635 or else In_Instance
1636 or else Error_Posted (D_Sdef)
1637 then
1638 goto Skip_LB;
1640 elsif Nkind (D_Sdef) = N_Range then
1641 LBR := Low_Bound (D_Sdef);
1643 elsif Is_Entity_Name (D_Sdef)
1644 and then Is_Type (Entity (D_Sdef))
1645 then
1646 LBR := Type_Low_Bound (Entity (D_Sdef));
1648 else
1649 goto Skip_LB;
1650 end if;
1652 if Is_OK_Static_Expression (LBR)
1653 and then Expr_Value (LBR) < LB
1654 then
1655 Error_Msg_Uint_1 := LB;
1656 Error_Msg_N ("entry family low bound must be '>'= ^!", D_Sdef);
1657 end if;
1659 <<Skip_LB>>
1660 if Is_Generic_Type (Etype (D_Sdef))
1661 or else In_Instance
1662 or else Error_Posted (D_Sdef)
1663 then
1664 goto Skip_UB;
1666 elsif Nkind (D_Sdef) = N_Range then
1667 UBR := High_Bound (D_Sdef);
1669 elsif Is_Entity_Name (D_Sdef)
1670 and then Is_Type (Entity (D_Sdef))
1671 then
1672 UBR := Type_High_Bound (Entity (D_Sdef));
1674 else
1675 goto Skip_UB;
1676 end if;
1678 if Is_OK_Static_Expression (UBR)
1679 and then Expr_Value (UBR) > UB
1680 then
1681 Error_Msg_Uint_1 := UB;
1682 Error_Msg_N ("entry family high bound must be '<'= ^!", D_Sdef);
1683 end if;
1685 <<Skip_UB>>
1686 null;
1687 end;
1688 end if;
1690 -- Decorate Def_Id
1692 Set_Etype (Def_Id, Standard_Void_Type);
1693 Set_Convention (Def_Id, Convention_Entry);
1694 Set_Accept_Address (Def_Id, New_Elmt_List);
1696 -- Set the SPARK_Mode from the current context (may be overwritten later
1697 -- with an explicit pragma). Task entries are excluded because they are
1698 -- not completed by entry bodies.
1700 if Ekind (Current_Scope) = E_Protected_Type then
1701 Set_SPARK_Pragma (Def_Id, SPARK_Mode_Pragma);
1702 Set_SPARK_Pragma_Inherited (Def_Id);
1703 end if;
1705 -- Preserve relevant elaboration-related attributes of the context which
1706 -- are no longer available or very expensive to recompute once analysis,
1707 -- resolution, and expansion are over.
1709 Mark_Elaboration_Attributes
1710 (N_Id => Def_Id,
1711 Checks => True,
1712 Warnings => True);
1714 -- Process formals
1716 if Present (Formals) then
1717 Set_Scope (Def_Id, Current_Scope);
1718 Push_Scope (Def_Id);
1719 Process_Formals (Formals, N);
1720 Create_Extra_Formals (Def_Id);
1721 End_Scope;
1722 end if;
1724 if Ekind (Def_Id) = E_Entry then
1725 New_Overloaded_Entity (Def_Id);
1726 end if;
1728 Generate_Reference_To_Formals (Def_Id);
1730 if Has_Aspects (N) then
1731 Analyze_Aspect_Specifications (N, Def_Id);
1732 end if;
1733 end Analyze_Entry_Declaration;
1735 ---------------------------------------
1736 -- Analyze_Entry_Index_Specification --
1737 ---------------------------------------
1739 -- The Defining_Identifier of the entry index specification is local to the
1740 -- entry body, but it must be available in the entry barrier which is
1741 -- evaluated outside of the entry body. The index is eventually renamed as
1742 -- a run-time object, so its visibility is strictly a front-end concern. In
1743 -- order to make it available to the barrier, we create an additional
1744 -- scope, as for a loop, whose only declaration is the index name. This
1745 -- loop is not attached to the tree and does not appear as an entity local
1746 -- to the protected type, so its existence need only be known to routines
1747 -- that process entry families.
1749 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
1750 Iden : constant Node_Id := Defining_Identifier (N);
1751 Def : constant Node_Id := Discrete_Subtype_Definition (N);
1752 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L');
1754 begin
1755 Tasking_Used := True;
1756 Analyze (Def);
1758 -- There is no elaboration of the entry index specification. Therefore,
1759 -- if the index is a range, it is not resolved and expanded, but the
1760 -- bounds are inherited from the entry declaration, and reanalyzed.
1761 -- See Analyze_Entry_Body.
1763 if Nkind (Def) /= N_Range then
1764 Make_Index (Def, N);
1765 end if;
1767 Mutate_Ekind (Loop_Id, E_Loop);
1768 Set_Scope (Loop_Id, Current_Scope);
1769 Push_Scope (Loop_Id);
1770 Enter_Name (Iden);
1771 Mutate_Ekind (Iden, E_Entry_Index_Parameter);
1772 Set_Etype (Iden, Etype (Def));
1773 end Analyze_Entry_Index_Specification;
1775 ----------------------------
1776 -- Analyze_Protected_Body --
1777 ----------------------------
1779 procedure Analyze_Protected_Body (N : Node_Id) is
1780 Body_Id : constant Entity_Id := Defining_Identifier (N);
1781 Last_E : Entity_Id;
1783 Spec_Id : Entity_Id;
1784 -- This is initially the entity of the protected object or protected
1785 -- type involved, but is replaced by the protected type always in the
1786 -- case of a single protected declaration, since this is the proper
1787 -- scope to be used.
1789 Ref_Id : Entity_Id;
1790 -- This is the entity of the protected object or protected type
1791 -- involved, and is the entity used for cross-reference purposes (it
1792 -- differs from Spec_Id in the case of a single protected object, since
1793 -- Spec_Id is set to the protected type in this case).
1795 function Lock_Free_Disabled return Boolean;
1796 -- This routine returns False if the protected object has a Lock_Free
1797 -- aspect specification or a Lock_Free pragma that turns off the
1798 -- lock-free implementation (e.g. whose expression is False).
1800 ------------------------
1801 -- Lock_Free_Disabled --
1802 ------------------------
1804 function Lock_Free_Disabled return Boolean is
1805 Ritem : constant Node_Id :=
1806 Get_Rep_Item
1807 (Spec_Id, Name_Lock_Free, Check_Parents => False);
1809 begin
1810 if Present (Ritem) then
1812 -- Pragma with one argument
1814 if Nkind (Ritem) = N_Pragma
1815 and then Present (Pragma_Argument_Associations (Ritem))
1816 then
1817 return
1818 Is_False
1819 (Static_Boolean
1820 (Expression
1821 (First (Pragma_Argument_Associations (Ritem)))));
1823 -- Aspect Specification with expression present
1825 elsif Nkind (Ritem) = N_Aspect_Specification
1826 and then Present (Expression (Ritem))
1827 then
1828 return Is_False (Static_Boolean (Expression (Ritem)));
1830 -- Otherwise, return False
1832 else
1833 return False;
1834 end if;
1835 end if;
1837 return False;
1838 end Lock_Free_Disabled;
1840 -- Start of processing for Analyze_Protected_Body
1842 begin
1843 -- A protected body freezes the contract of the nearest enclosing
1844 -- package body and all other contracts encountered in the same
1845 -- declarative part up to and excluding the protected body. This
1846 -- ensures that any annotations referenced by the contract of an
1847 -- entry or subprogram body declared within the current protected
1848 -- body are available.
1850 Freeze_Previous_Contracts (N);
1852 Tasking_Used := True;
1853 Mutate_Ekind (Body_Id, E_Protected_Body);
1854 Set_Etype (Body_Id, Standard_Void_Type);
1855 Spec_Id := Find_Concurrent_Spec (Body_Id);
1857 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Protected_Type then
1858 null;
1860 elsif Present (Spec_Id)
1861 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1862 and then not Comes_From_Source (Etype (Spec_Id))
1863 then
1864 null;
1866 else
1867 Error_Msg_N ("missing specification for protected body", Body_Id);
1868 return;
1869 end if;
1871 Ref_Id := Spec_Id;
1872 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1873 Style.Check_Identifier (Body_Id, Spec_Id);
1875 -- The declarations are always attached to the type
1877 if Ekind (Spec_Id) /= E_Protected_Type then
1878 Spec_Id := Etype (Spec_Id);
1879 end if;
1881 if Has_Aspects (N) then
1882 Analyze_Aspect_Specifications (N, Body_Id);
1883 end if;
1885 Push_Scope (Spec_Id);
1886 Set_Corresponding_Spec (N, Spec_Id);
1887 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1888 Set_Has_Completion (Spec_Id);
1889 Install_Declarations (Spec_Id);
1890 Expand_Protected_Body_Declarations (N, Spec_Id);
1891 Last_E := Last_Entity (Spec_Id);
1893 Analyze_Declarations (Declarations (N));
1895 -- For visibility purposes, all entities in the body are private. Set
1896 -- First_Private_Entity accordingly, if there was no private part in the
1897 -- protected declaration.
1899 if No (First_Private_Entity (Spec_Id)) then
1900 if Present (Last_E) then
1901 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1902 else
1903 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1904 end if;
1905 end if;
1907 Check_Completion (Body_Id);
1908 Check_References (Spec_Id);
1909 Process_End_Label (N, 't', Ref_Id);
1910 Update_Use_Clause_Chain;
1911 End_Scope;
1913 -- When a Lock_Free aspect specification/pragma forces the lock-free
1914 -- implementation, verify the protected body meets all the restrictions,
1915 -- otherwise Allows_Lock_Free_Implementation issues an error message.
1917 if Uses_Lock_Free (Spec_Id) then
1918 if not Allows_Lock_Free_Implementation (N, True) then
1919 return;
1920 end if;
1922 -- In other cases, if there is no aspect specification/pragma that
1923 -- disables the lock-free implementation, check both the protected
1924 -- declaration and body satisfy the lock-free restrictions.
1926 elsif not Lock_Free_Disabled
1927 and then Allows_Lock_Free_Implementation (Parent (Spec_Id))
1928 and then Allows_Lock_Free_Implementation (N)
1929 then
1930 Set_Uses_Lock_Free (Spec_Id);
1931 end if;
1932 end Analyze_Protected_Body;
1934 ----------------------------------
1935 -- Analyze_Protected_Definition --
1936 ----------------------------------
1938 procedure Analyze_Protected_Definition (N : Node_Id) is
1939 procedure Undelay_Itypes (T : Entity_Id);
1940 -- Itypes created for the private components of a protected type
1941 -- do not receive freeze nodes, because there is no scope in which
1942 -- they can be elaborated, and they can depend on discriminants of
1943 -- the enclosed protected type. Given that the components can be
1944 -- composite types with inner components, we traverse recursively
1945 -- the private components of the protected type, and indicate that
1946 -- all itypes within are frozen. This ensures that no freeze nodes
1947 -- will be generated for them. In the case of itypes that are access
1948 -- types we need to complete their representation by calling layout,
1949 -- which would otherwise be invoked when freezing a type.
1951 -- On the other hand, components of the corresponding record are
1952 -- frozen (or receive itype references) as for other records.
1954 --------------------
1955 -- Undelay_Itypes --
1956 --------------------
1958 procedure Undelay_Itypes (T : Entity_Id) is
1959 Comp : Entity_Id;
1961 begin
1962 if Is_Protected_Type (T) then
1963 Comp := First_Private_Entity (T);
1964 elsif Is_Record_Type (T) then
1965 Comp := First_Entity (T);
1966 else
1967 return;
1968 end if;
1970 while Present (Comp) loop
1971 if Is_Type (Comp) and then Is_Itype (Comp) then
1972 Set_Has_Delayed_Freeze (Comp, False);
1973 Set_Is_Frozen (Comp);
1975 if Is_Access_Type (Comp) then
1976 Layout_Type (Comp);
1977 end if;
1979 if Is_Record_Type (Comp) or else Is_Protected_Type (Comp) then
1980 Undelay_Itypes (Comp);
1981 end if;
1982 end if;
1984 Next_Entity (Comp);
1985 end loop;
1986 end Undelay_Itypes;
1988 -- Local variables
1990 Prot_Typ : constant Entity_Id := Current_Scope;
1991 Item_Id : Entity_Id;
1992 Last_Id : Entity_Id;
1994 -- Start of processing for Analyze_Protected_Definition
1996 begin
1997 Tasking_Used := True;
1998 Analyze_Declarations (Visible_Declarations (N));
2000 if not Is_Empty_List (Private_Declarations (N)) then
2001 Last_Id := Last_Entity (Prot_Typ);
2002 Analyze_Declarations (Private_Declarations (N));
2004 if Present (Last_Id) then
2005 Set_First_Private_Entity (Prot_Typ, Next_Entity (Last_Id));
2006 else
2007 Set_First_Private_Entity (Prot_Typ, First_Entity (Prot_Typ));
2008 end if;
2009 end if;
2011 Item_Id := First_Entity (Prot_Typ);
2012 while Present (Item_Id) loop
2013 if Ekind (Item_Id) in E_Function | E_Procedure then
2014 Set_Convention (Item_Id, Convention_Protected);
2015 else
2016 Propagate_Concurrent_Flags (Prot_Typ, Etype (Item_Id));
2018 if Chars (Item_Id) /= Name_uParent
2019 and then Needs_Finalization (Etype (Item_Id))
2020 then
2021 Set_Has_Controlled_Component (Prot_Typ);
2022 end if;
2023 end if;
2025 Next_Entity (Item_Id);
2026 end loop;
2028 Undelay_Itypes (Prot_Typ);
2030 Check_Max_Entries (N, Max_Protected_Entries);
2031 Process_End_Label (N, 'e', Prot_Typ);
2032 end Analyze_Protected_Definition;
2034 ----------------------------------------
2035 -- Analyze_Protected_Type_Declaration --
2036 ----------------------------------------
2038 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
2039 Def_Id : constant Entity_Id := Defining_Identifier (N);
2040 E : Entity_Id;
2041 T : Entity_Id;
2043 begin
2044 if No_Run_Time_Mode then
2045 Error_Msg_CRT ("protected type", N);
2047 if Has_Aspects (N) then
2048 Analyze_Aspect_Specifications (N, Def_Id);
2049 end if;
2051 return;
2052 end if;
2054 Tasking_Used := True;
2055 Check_Restriction (No_Protected_Types, N);
2057 T := Find_Type_Name (N);
2059 -- In the case of an incomplete type, use the full view, unless it's not
2060 -- present (as can occur for an incomplete view from a limited with).
2062 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
2063 T := Full_View (T);
2064 Set_Completion_Referenced (T);
2065 end if;
2067 Mutate_Ekind (T, E_Protected_Type);
2068 Set_Is_First_Subtype (T);
2069 Reinit_Size_Align (T);
2070 Set_Etype (T, T);
2071 Set_Has_Delayed_Freeze (T);
2072 Set_Stored_Constraint (T, No_Elist);
2074 -- Initialize type's primitive operations list, for possible use when
2075 -- the extension of prefixed call notation for untagged types is enabled
2076 -- (such as by use of -gnatX).
2078 Set_Direct_Primitive_Operations (T, New_Elmt_List);
2080 -- Mark this type as a protected type for the sake of restrictions,
2081 -- unless the protected type is declared in a private part of a package
2082 -- of the runtime. With this exception, the Suspension_Object from
2083 -- Ada.Synchronous_Task_Control can be implemented using a protected
2084 -- object without triggering violations of No_Local_Protected_Objects
2085 -- when the user locally declares such an object. This may look like a
2086 -- trick, but the user doesn't have to know how Suspension_Object is
2087 -- implemented.
2089 if In_Private_Part (Current_Scope)
2090 and then Is_Internal_Unit (Current_Sem_Unit)
2091 then
2092 Set_Has_Protected (T, False);
2093 else
2094 Set_Has_Protected (T);
2095 end if;
2097 -- Set the SPARK_Mode from the current context (may be overwritten later
2098 -- with an explicit pragma).
2100 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
2101 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
2102 Set_SPARK_Pragma_Inherited (T);
2103 Set_SPARK_Aux_Pragma_Inherited (T);
2105 Push_Scope (T);
2107 if Ada_Version >= Ada_2005 then
2108 Check_Interfaces (N, T);
2109 end if;
2111 if Present (Discriminant_Specifications (N)) then
2112 if Has_Discriminants (T) then
2114 -- Install discriminants. Also, verify conformance of
2115 -- discriminants of previous and current view. ???
2117 Install_Declarations (T);
2118 else
2119 Process_Discriminants (N);
2120 end if;
2121 end if;
2123 Set_Is_Constrained (T, not Has_Discriminants (T));
2125 -- If aspects are present, analyze them now. They can make references to
2126 -- the discriminants of the type, but not to any components.
2128 if Has_Aspects (N) then
2130 -- The protected type is the full view of a private type. Analyze the
2131 -- aspects with the entity of the private type to ensure that after
2132 -- both views are exchanged, the aspect are actually associated with
2133 -- the full view.
2135 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2136 Analyze_Aspect_Specifications (N, T);
2137 else
2138 Analyze_Aspect_Specifications (N, Def_Id);
2139 end if;
2140 end if;
2142 Analyze (Protected_Definition (N));
2144 -- In the case where the protected type is declared at a nested level
2145 -- and the No_Local_Protected_Objects restriction applies, issue a
2146 -- warning that objects of the type will violate the restriction.
2148 if Restriction_Check_Required (No_Local_Protected_Objects)
2149 and then not Is_Library_Level_Entity (T)
2150 and then Comes_From_Source (T)
2151 then
2152 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
2154 if Error_Msg_Sloc = No_Location then
2155 Error_Msg_N
2156 ("objects of this type will violate " &
2157 "`No_Local_Protected_Objects`??", N);
2158 else
2159 Error_Msg_N
2160 ("objects of this type will violate " &
2161 "`No_Local_Protected_Objects`#??", N);
2162 end if;
2163 end if;
2165 -- Protected types with entries are controlled (because of the
2166 -- Protection component if nothing else), same for any protected type
2167 -- with interrupt handlers. Note that we need to analyze the protected
2168 -- definition to set Has_Entries and such.
2170 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
2171 or else Number_Entries (T) > 1)
2172 and then not Restricted_Profile
2173 and then
2174 (Has_Entries (T)
2175 or else Has_Interrupt_Handler (T)
2176 or else Has_Attach_Handler (T))
2177 then
2178 Set_Has_Controlled_Component (T, True);
2179 end if;
2181 -- The Ekind of components is E_Void during analysis to detect illegal
2182 -- uses. Now it can be set correctly.
2184 E := First_Entity (Current_Scope);
2185 while Present (E) loop
2186 if Ekind (E) = E_Void then
2187 Mutate_Ekind (E, E_Component);
2188 Reinit_Component_Location (E);
2189 end if;
2191 Next_Entity (E);
2192 end loop;
2194 End_Scope;
2196 -- When a Lock_Free aspect forces the lock-free implementation, check N
2197 -- meets all the lock-free restrictions. Otherwise, an error message is
2198 -- issued by Allows_Lock_Free_Implementation.
2200 if Uses_Lock_Free (Defining_Identifier (N)) then
2202 -- Complain when there is an explicit aspect/pragma Priority (or
2203 -- Interrupt_Priority) while the lock-free implementation is forced
2204 -- by an aspect/pragma.
2206 declare
2207 Id : constant Entity_Id := Defining_Identifier (Original_Node (N));
2208 -- The warning must be issued on the original identifier in order
2209 -- to deal properly with the case of a single protected object.
2211 Prio_Item : constant Node_Id :=
2212 Get_Rep_Item (Def_Id, Name_Priority, False);
2214 begin
2215 if Present (Prio_Item) then
2217 -- Aspect case
2219 if Nkind (Prio_Item) = N_Aspect_Specification
2220 or else From_Aspect_Specification (Prio_Item)
2221 then
2222 Error_Msg_Name_1 := Chars (Identifier (Prio_Item));
2223 Error_Msg_NE
2224 ("aspect% for & has no effect when Lock_Free given??",
2225 Prio_Item, Id);
2227 -- Pragma case
2229 else
2230 Error_Msg_Name_1 := Pragma_Name (Prio_Item);
2231 Error_Msg_NE
2232 ("pragma% for & has no effect when Lock_Free given??",
2233 Prio_Item, Id);
2234 end if;
2235 end if;
2236 end;
2238 if not Allows_Lock_Free_Implementation (N, Lock_Free_Given => True)
2239 then
2240 return;
2241 end if;
2242 end if;
2244 -- If the Attach_Handler aspect is specified or the Interrupt_Handler
2245 -- aspect is True, then the initial ceiling priority must be in the
2246 -- range of System.Interrupt_Priority. It is therefore recommanded
2247 -- to use the Interrupt_Priority aspect instead of the Priority aspect.
2249 if Has_Interrupt_Handler (T) or else Has_Attach_Handler (T) then
2250 declare
2251 Prio_Item : constant Node_Id :=
2252 Get_Rep_Item (Def_Id, Name_Priority, False);
2254 begin
2255 if Present (Prio_Item) then
2257 -- Aspect case
2259 if (Nkind (Prio_Item) = N_Aspect_Specification
2260 or else From_Aspect_Specification (Prio_Item))
2261 and then Chars (Identifier (Prio_Item)) = Name_Priority
2262 then
2263 Error_Msg_N
2264 ("aspect Interrupt_Priority is preferred in presence of "
2265 & "handlers??", Prio_Item);
2267 -- Pragma case
2269 elsif Nkind (Prio_Item) = N_Pragma
2270 and then Pragma_Name (Prio_Item) = Name_Priority
2271 then
2272 Error_Msg_N
2273 ("pragma Interrupt_Priority is preferred in presence of "
2274 & "handlers??", Prio_Item);
2275 end if;
2276 end if;
2277 end;
2278 end if;
2280 -- Case of a completion of a private declaration
2282 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2284 -- Deal with preelaborable initialization. Note that this processing
2285 -- is done by Process_Full_View, but as can be seen below, in this
2286 -- case the call to Process_Full_View is skipped if any serious
2287 -- errors have occurred, and we don't want to lose this check.
2289 if Known_To_Have_Preelab_Init (Def_Id) then
2290 Set_Must_Have_Preelab_Init (T);
2291 end if;
2293 -- Propagate Default_Initial_Condition-related attributes from the
2294 -- private type to the protected type.
2296 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
2298 -- Propagate invariant-related attributes from the private type to
2299 -- the protected type.
2301 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
2303 -- Propagate predicate-related attributes from the private type to
2304 -- the protected type.
2306 Propagate_Predicate_Attributes (T, From_Typ => Def_Id);
2308 -- Create corresponding record now, because some private dependents
2309 -- may be subtypes of the partial view.
2311 -- Skip if errors are present, to prevent cascaded messages
2313 if Serious_Errors_Detected = 0
2315 -- Also skip if expander is not active
2317 and then Expander_Active
2318 then
2319 Expand_N_Protected_Type_Declaration (N);
2320 Process_Full_View (N, T, Def_Id);
2321 end if;
2322 end if;
2324 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
2325 -- is required for the ceiling priority protocol checks triggered by
2326 -- calls originating from protected subprograms and entries.
2328 if GNATprove_Mode then
2329 SPARK_Implicit_Load (RE_Interrupt_Priority);
2330 end if;
2331 end Analyze_Protected_Type_Declaration;
2333 ---------------------
2334 -- Analyze_Requeue --
2335 ---------------------
2337 procedure Analyze_Requeue (N : Node_Id) is
2339 procedure Check_Wrong_Attribute_In_Postconditions
2340 (Entry_Id : Entity_Id;
2341 Error_Node : Node_Id);
2342 -- Check that the requeue target Entry_Id does not have an specific or
2343 -- class-wide postcondition that references an Old or Index attribute.
2345 ---------------------------------------------
2346 -- Check_Wrong_Attribute_In_Postconditions --
2347 ---------------------------------------------
2349 procedure Check_Wrong_Attribute_In_Postconditions
2350 (Entry_Id : Entity_Id;
2351 Error_Node : Node_Id)
2353 function Check_Node (N : Node_Id) return Traverse_Result;
2354 -- Check that N is not a reference to attribute Index or Old; report
2355 -- an error otherwise.
2357 ----------------
2358 -- Check_Node --
2359 ----------------
2361 function Check_Node (N : Node_Id) return Traverse_Result is
2362 begin
2363 if Nkind (N) = N_Attribute_Reference
2364 and then Attribute_Name (N) in Name_Index
2365 | Name_Old
2366 then
2367 Error_Msg_Name_1 := Attribute_Name (N);
2368 Error_Msg_N
2369 ("target of requeue must not have references to attribute % "
2370 & "in postcondition",
2371 Error_Node);
2372 end if;
2374 return OK;
2375 end Check_Node;
2377 procedure Check_Attr_Refs is new Traverse_Proc (Check_Node);
2379 -- Local variables
2381 Prag : Node_Id;
2382 begin
2383 Prag := Pre_Post_Conditions (Contract (Entry_Id));
2385 while Present (Prag) loop
2386 if Pragma_Name (Prag) = Name_Postcondition then
2387 Check_Attr_Refs (First (Pragma_Argument_Associations (Prag)));
2388 end if;
2390 Prag := Next_Pragma (Prag);
2391 end loop;
2392 end Check_Wrong_Attribute_In_Postconditions;
2394 -- Local variables
2396 Count : Natural := 0;
2397 Entry_Name : Node_Id := Name (N);
2398 Entry_Id : Entity_Id;
2399 I : Interp_Index;
2400 Is_Disp_Req : Boolean;
2401 It : Interp;
2402 Enclosing : Entity_Id;
2403 Target_Obj : Node_Id := Empty;
2404 Req_Scope : Entity_Id;
2405 Outer_Ent : Entity_Id;
2406 Synch_Type : Entity_Id := Empty;
2408 -- Start of processing for Analyze_Requeue
2410 begin
2411 -- Preserve relevant elaboration-related attributes of the context which
2412 -- are no longer available or very expensive to recompute once analysis,
2413 -- resolution, and expansion are over.
2415 Mark_Elaboration_Attributes
2416 (N_Id => N,
2417 Checks => True,
2418 Modes => True,
2419 Warnings => True);
2421 Tasking_Used := True;
2422 Check_Restriction (No_Requeue_Statements, N);
2423 Check_Unreachable_Code (N);
2425 Enclosing := Empty;
2426 for J in reverse 0 .. Scope_Stack.Last loop
2427 Enclosing := Scope_Stack.Table (J).Entity;
2428 exit when Is_Entry (Enclosing);
2430 if Ekind (Enclosing) not in E_Block | E_Loop then
2431 Error_Msg_N ("requeue must appear within accept or entry body", N);
2432 return;
2433 end if;
2434 end loop;
2436 Analyze (Entry_Name);
2438 if Etype (Entry_Name) = Any_Type then
2439 return;
2440 end if;
2442 if Nkind (Entry_Name) = N_Selected_Component then
2443 Target_Obj := Prefix (Entry_Name);
2444 Entry_Name := Selector_Name (Entry_Name);
2445 end if;
2447 -- If an explicit target object is given then we have to check the
2448 -- restrictions of 9.5.4(6).
2450 if Present (Target_Obj) then
2452 -- Locate containing concurrent unit and determine enclosing entry
2453 -- body or outermost enclosing accept statement within the unit.
2455 Outer_Ent := Empty;
2456 for S in reverse 0 .. Scope_Stack.Last loop
2457 Req_Scope := Scope_Stack.Table (S).Entity;
2459 exit when Is_Concurrent_Type (Req_Scope);
2461 if Is_Entry (Req_Scope) then
2462 Outer_Ent := Req_Scope;
2463 end if;
2464 end loop;
2466 pragma Assert (Present (Outer_Ent));
2468 -- Check that the accessibility level of the target object is not
2469 -- greater or equal to the outermost enclosing accept statement (or
2470 -- entry body) unless it is a parameter of the innermost enclosing
2471 -- accept statement (or entry body).
2473 if Static_Accessibility_Level (Target_Obj, Zero_On_Dynamic_Level)
2474 >= Scope_Depth (Outer_Ent)
2475 and then
2476 (not Is_Entity_Name (Target_Obj)
2477 or else not Is_Formal (Entity (Target_Obj))
2478 or else Enclosing /= Scope (Entity (Target_Obj)))
2479 then
2480 Error_Msg_N
2481 ("target object has invalid level for requeue", Target_Obj);
2482 end if;
2483 end if;
2485 -- Overloaded case, find right interpretation
2487 if Is_Overloaded (Entry_Name) then
2488 Entry_Id := Empty;
2490 -- Loop over candidate interpretations and filter out any that are
2491 -- not parameterless, are not type conformant, are not entries, or
2492 -- do not come from source.
2494 Get_First_Interp (Entry_Name, I, It);
2495 while Present (It.Nam) loop
2497 -- Note: we test type conformance here, not subtype conformance.
2498 -- Subtype conformance will be tested later on, but it is better
2499 -- for error output in some cases not to do that here.
2501 if (No (First_Formal (It.Nam))
2502 or else (Type_Conformant (Enclosing, It.Nam)))
2503 and then Ekind (It.Nam) = E_Entry
2504 then
2505 -- Ada 2005 (AI-345): Since protected and task types have
2506 -- primitive entry wrappers, we only consider source entries.
2508 if Comes_From_Source (It.Nam) then
2509 Count := Count + 1;
2510 Entry_Id := It.Nam;
2511 else
2512 Remove_Interp (I);
2513 end if;
2514 end if;
2516 Get_Next_Interp (I, It);
2517 end loop;
2519 if Count = 0 then
2520 Error_Msg_N ("no entry matches context", N);
2521 return;
2523 elsif Count > 1 then
2524 Error_Msg_N ("ambiguous entry name in requeue", N);
2525 return;
2527 else
2528 Set_Is_Overloaded (Entry_Name, False);
2529 Set_Entity (Entry_Name, Entry_Id);
2530 end if;
2532 -- Non-overloaded cases
2534 -- For the case of a reference to an element of an entry family, the
2535 -- Entry_Name is an indexed component.
2537 elsif Nkind (Entry_Name) = N_Indexed_Component then
2539 -- Requeue to an entry out of the body
2541 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
2542 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
2544 -- Requeue from within the body itself
2546 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
2547 Entry_Id := Entity (Prefix (Entry_Name));
2549 else
2550 Error_Msg_N ("invalid entry_name specified", N);
2551 return;
2552 end if;
2554 -- If we had a requeue of the form REQUEUE A (B), then the parser
2555 -- accepted it (because it could have been a requeue on an entry index.
2556 -- If A turns out not to be an entry family, then the analysis of A (B)
2557 -- turned it into a function call.
2559 elsif Nkind (Entry_Name) = N_Function_Call then
2560 Error_Msg_N
2561 ("arguments not allowed in requeue statement",
2562 First (Parameter_Associations (Entry_Name)));
2563 return;
2565 -- Normal case of no entry family, no argument
2567 else
2568 Entry_Id := Entity (Entry_Name);
2569 end if;
2571 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
2572 -- target type must be a concurrent interface class-wide type and the
2573 -- target must be a procedure, flagged by pragma Implemented. The
2574 -- target may be an access to class-wide type, in which case it must
2575 -- be dereferenced.
2577 if Present (Target_Obj) then
2578 Synch_Type := Etype (Target_Obj);
2580 if Is_Access_Type (Synch_Type) then
2581 Synch_Type := Designated_Type (Synch_Type);
2582 end if;
2583 end if;
2585 Is_Disp_Req :=
2586 Ada_Version >= Ada_2012
2587 and then Present (Target_Obj)
2588 and then Is_Class_Wide_Type (Synch_Type)
2589 and then Is_Concurrent_Interface (Synch_Type)
2590 and then Ekind (Entry_Id) = E_Procedure
2591 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
2593 -- Resolve entry, and check that it is subtype conformant with the
2594 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
2595 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
2597 if not Is_Entry (Entry_Id)
2598 and then not Is_Disp_Req
2599 then
2600 Error_Msg_N ("expect entry name in requeue statement", Name (N));
2602 elsif Ekind (Entry_Id) = E_Entry_Family
2603 and then Nkind (Entry_Name) /= N_Indexed_Component
2604 then
2605 Error_Msg_N ("missing index for entry family component", Name (N));
2607 else
2608 Resolve_Entry (Name (N));
2609 Generate_Reference (Entry_Id, Entry_Name);
2611 if Present (First_Formal (Entry_Id)) then
2613 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
2614 -- the first parameter of Entry_Id since it is the interface
2615 -- controlling formal.
2617 if Ada_Version >= Ada_2012 and then Is_Disp_Req then
2618 declare
2619 Enclosing_Formal : Entity_Id;
2620 Target_Formal : Entity_Id;
2622 begin
2623 Enclosing_Formal := First_Formal (Enclosing);
2624 Target_Formal := Next_Formal (First_Formal (Entry_Id));
2625 while Present (Enclosing_Formal)
2626 and then Present (Target_Formal)
2627 loop
2628 if not Conforming_Types
2629 (T1 => Etype (Enclosing_Formal),
2630 T2 => Etype (Target_Formal),
2631 Ctype => Subtype_Conformant)
2632 then
2633 Error_Msg_Node_2 := Target_Formal;
2634 Error_Msg_NE
2635 ("formal & is not subtype conformant with &" &
2636 "in dispatching requeue", N, Enclosing_Formal);
2637 end if;
2639 Next_Formal (Enclosing_Formal);
2640 Next_Formal (Target_Formal);
2641 end loop;
2642 end;
2643 else
2644 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
2645 end if;
2647 -- Processing for parameters accessed by the requeue
2649 declare
2650 Ent : Entity_Id;
2652 begin
2653 Ent := First_Formal (Enclosing);
2654 while Present (Ent) loop
2656 -- For OUT or IN OUT parameter, the effect of the requeue is
2657 -- to assign the parameter a value on exit from the requeued
2658 -- body, so we can set it as source assigned. We also clear
2659 -- the Is_True_Constant indication. We do not need to clear
2660 -- Current_Value, since the effect of the requeue is to
2661 -- perform an unconditional goto so that any further
2662 -- references will not occur anyway.
2664 if Ekind (Ent) in E_Out_Parameter | E_In_Out_Parameter then
2665 Set_Never_Set_In_Source (Ent, False);
2666 Set_Is_True_Constant (Ent, False);
2667 end if;
2669 -- For all parameters, the requeue acts as a reference,
2670 -- since the value of the parameter is passed to the new
2671 -- entry, so we want to suppress unreferenced warnings.
2673 Set_Referenced (Ent);
2674 Next_Formal (Ent);
2675 end loop;
2676 end;
2677 end if;
2678 end if;
2680 -- AI05-0225: the target protected object of a requeue must be a
2681 -- variable. This is a binding interpretation that applies to all
2682 -- versions of the language. Note that the subprogram does not have
2683 -- to be a protected operation: it can be an primitive implemented
2684 -- by entry with a formal that is a protected interface.
2686 if Present (Target_Obj)
2687 and then not Is_Variable (Target_Obj)
2688 then
2689 Error_Msg_N
2690 ("target protected object of requeue must be a variable", N);
2691 end if;
2693 -- Ada 2022 (AI12-0143): The requeue target shall not have an
2694 -- applicable specific or class-wide postcondition which includes
2695 -- an Old or Index attribute reference.
2697 if Ekind (Entry_Id) = E_Entry_Family
2698 and then Present (Contract (Entry_Id))
2699 then
2700 Check_Wrong_Attribute_In_Postconditions
2701 (Entry_Id => Entry_Id,
2702 Error_Node => Entry_Name);
2703 end if;
2705 -- A requeue statement is treated as a call for purposes of ABE checks
2706 -- and diagnostics. Annotate the tree by creating a call marker in case
2707 -- the requeue statement is transformed by expansion.
2709 Build_Call_Marker (N);
2710 end Analyze_Requeue;
2712 ------------------------------
2713 -- Analyze_Selective_Accept --
2714 ------------------------------
2716 procedure Analyze_Selective_Accept (N : Node_Id) is
2717 Alts : constant List_Id := Select_Alternatives (N);
2718 Alt : Node_Id;
2720 Accept_Present : Boolean := False;
2721 Terminate_Present : Boolean := False;
2722 Delay_Present : Boolean := False;
2723 Relative_Present : Boolean := False;
2724 Alt_Count : Uint := Uint_0;
2726 begin
2727 Tasking_Used := True;
2728 Check_Restriction (No_Select_Statements, N);
2730 -- Loop to analyze alternatives
2732 Alt := First (Alts);
2733 while Present (Alt) loop
2734 Alt_Count := Alt_Count + 1;
2735 Analyze (Alt);
2737 if Nkind (Alt) = N_Delay_Alternative then
2738 if Delay_Present then
2740 if Relative_Present /=
2741 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
2742 then
2743 Error_Msg_N
2744 ("delay_until and delay_relative alternatives", Alt);
2745 Error_Msg_N
2746 ("\cannot appear in the same selective_wait", Alt);
2747 end if;
2749 else
2750 Delay_Present := True;
2751 Relative_Present :=
2752 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
2753 end if;
2755 elsif Nkind (Alt) = N_Terminate_Alternative then
2756 if Terminate_Present then
2757 Error_Msg_N ("only one terminate alternative allowed", N);
2758 else
2759 Terminate_Present := True;
2760 Check_Restriction (No_Terminate_Alternatives, N);
2761 end if;
2763 elsif Nkind (Alt) = N_Accept_Alternative then
2764 Accept_Present := True;
2766 -- Check for duplicate accept
2768 declare
2769 Alt1 : Node_Id;
2770 Stm : constant Node_Id := Accept_Statement (Alt);
2771 EDN : constant Node_Id := Entry_Direct_Name (Stm);
2772 Ent : Entity_Id;
2774 begin
2775 if Nkind (EDN) = N_Identifier
2776 and then No (Condition (Alt))
2777 and then Present (Entity (EDN)) -- defend against junk
2778 and then Ekind (Entity (EDN)) = E_Entry
2779 then
2780 Ent := Entity (EDN);
2782 Alt1 := First (Alts);
2783 while Alt1 /= Alt loop
2784 if Nkind (Alt1) = N_Accept_Alternative
2785 and then No (Condition (Alt1))
2786 then
2787 declare
2788 Stm1 : constant Node_Id := Accept_Statement (Alt1);
2789 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
2791 begin
2792 if Nkind (EDN1) = N_Identifier then
2793 if Entity (EDN1) = Ent then
2794 Error_Msg_Sloc := Sloc (Stm1);
2795 Error_Msg_N
2796 ("ACCEPT duplicates one on line#??", Stm);
2797 exit;
2798 end if;
2799 end if;
2800 end;
2801 end if;
2803 Next (Alt1);
2804 end loop;
2805 end if;
2806 end;
2807 end if;
2809 Next (Alt);
2810 end loop;
2812 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
2813 Check_Potentially_Blocking_Operation (N);
2815 if Terminate_Present and Delay_Present then
2816 Error_Msg_N ("at most one of TERMINATE or DELAY alternative", N);
2818 elsif not Accept_Present then
2819 Error_Msg_N
2820 ("SELECT must contain at least one ACCEPT alternative", N);
2821 end if;
2823 if Present (Else_Statements (N)) then
2824 if Terminate_Present or Delay_Present then
2825 Error_Msg_N ("ELSE part not allowed with other alternatives", N);
2826 end if;
2828 Analyze_Statements (Else_Statements (N));
2829 end if;
2830 end Analyze_Selective_Accept;
2832 ------------------------------------------
2833 -- Analyze_Single_Protected_Declaration --
2834 ------------------------------------------
2836 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
2837 Loc : constant Source_Ptr := Sloc (N);
2838 Obj_Id : constant Node_Id := Defining_Identifier (N);
2839 Obj_Decl : Node_Id;
2840 Typ : Entity_Id;
2842 begin
2843 Generate_Definition (Obj_Id);
2844 Tasking_Used := True;
2846 -- A single protected declaration is transformed into a pair of an
2847 -- anonymous protected type and an object of that type. Generate:
2849 -- protected type Typ is ...;
2851 Typ :=
2852 Make_Defining_Identifier (Sloc (Obj_Id),
2853 Chars => New_External_Name (Chars (Obj_Id), 'T'));
2855 Rewrite (N,
2856 Make_Protected_Type_Declaration (Loc,
2857 Defining_Identifier => Typ,
2858 Protected_Definition => Relocate_Node (Protected_Definition (N)),
2859 Interface_List => Interface_List (N)));
2861 -- Use the original defining identifier of the single protected
2862 -- declaration in the generated object declaration to allow for debug
2863 -- information to be attached to it when compiling with -gnatD. The
2864 -- parent of the entity is the new object declaration. The single
2865 -- protected declaration is not used in semantics or code generation,
2866 -- but is scanned when generating debug information, and therefore needs
2867 -- the updated Sloc information from the entity (see Sprint). Generate:
2869 -- Obj : Typ;
2871 Obj_Decl :=
2872 Make_Object_Declaration (Loc,
2873 Defining_Identifier => Obj_Id,
2874 Object_Definition => New_Occurrence_Of (Typ, Loc));
2876 Insert_After (N, Obj_Decl);
2877 Mark_Rewrite_Insertion (Obj_Decl);
2879 -- Relocate aspect Part_Of from the original single protected
2880 -- declaration to the anonymous object declaration. This emulates the
2881 -- placement of an equivalent source pragma.
2883 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2885 -- Relocate pragma Part_Of from the visible declarations of the original
2886 -- single protected declaration to the anonymous object declaration. The
2887 -- new placement better reflects the role of the pragma.
2889 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2891 -- Enter the names of the anonymous protected type and the object before
2892 -- analysis takes places, because the name of the object may be used in
2893 -- its own body.
2895 Enter_Name (Typ);
2896 Mutate_Ekind (Typ, E_Protected_Type);
2897 Set_Etype (Typ, Typ);
2898 Set_Anonymous_Object (Typ, Obj_Id);
2900 Enter_Name (Obj_Id);
2901 Mutate_Ekind (Obj_Id, E_Variable);
2902 Set_Etype (Obj_Id, Typ);
2903 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2904 Set_SPARK_Pragma_Inherited (Obj_Id);
2906 -- Instead of calling Analyze on the new node, call the proper analysis
2907 -- procedure directly. Otherwise the node would be expanded twice, with
2908 -- disastrous result.
2910 Analyze_Protected_Type_Declaration (N);
2912 if Has_Aspects (N) then
2913 Analyze_Aspect_Specifications (N, Obj_Id);
2914 end if;
2915 end Analyze_Single_Protected_Declaration;
2917 -------------------------------------
2918 -- Analyze_Single_Task_Declaration --
2919 -------------------------------------
2921 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
2922 Loc : constant Source_Ptr := Sloc (N);
2923 Obj_Id : constant Node_Id := Defining_Identifier (N);
2924 Obj_Decl : Node_Id;
2925 Typ : Entity_Id;
2927 begin
2928 Generate_Definition (Obj_Id);
2929 Tasking_Used := True;
2931 -- A single task declaration is transformed into a pair of an anonymous
2932 -- task type and an object of that type. Generate:
2934 -- task type Typ is ...;
2936 Typ :=
2937 Make_Defining_Identifier (Sloc (Obj_Id),
2938 Chars => New_External_Name (Chars (Obj_Id), Suffix => "TK"));
2940 Rewrite (N,
2941 Make_Task_Type_Declaration (Loc,
2942 Defining_Identifier => Typ,
2943 Task_Definition => Relocate_Node (Task_Definition (N)),
2944 Interface_List => Interface_List (N)));
2946 -- Use the original defining identifier of the single task declaration
2947 -- in the generated object declaration to allow for debug information
2948 -- to be attached to it when compiling with -gnatD. The parent of the
2949 -- entity is the new object declaration. The single task declaration
2950 -- is not used in semantics or code generation, but is scanned when
2951 -- generating debug information, and therefore needs the updated Sloc
2952 -- information from the entity (see Sprint). Generate:
2954 -- Obj : Typ;
2956 Obj_Decl :=
2957 Make_Object_Declaration (Loc,
2958 Defining_Identifier => Obj_Id,
2959 Object_Definition => New_Occurrence_Of (Typ, Loc));
2961 Insert_After (N, Obj_Decl);
2962 Mark_Rewrite_Insertion (Obj_Decl);
2964 -- Relocate aspects Depends, Global and Part_Of from the original single
2965 -- task declaration to the anonymous object declaration. This emulates
2966 -- the placement of an equivalent source pragma.
2968 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2970 -- Relocate pragmas Depends, Global and Part_Of from the visible
2971 -- declarations of the original single protected declaration to the
2972 -- anonymous object declaration. The new placement better reflects the
2973 -- role of the pragmas.
2975 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2977 -- Enter the names of the anonymous task type and the object before
2978 -- analysis takes places, because the name of the object may be used
2979 -- in its own body.
2981 Enter_Name (Typ);
2982 Mutate_Ekind (Typ, E_Task_Type);
2983 Set_Etype (Typ, Typ);
2984 Set_Anonymous_Object (Typ, Obj_Id);
2986 Enter_Name (Obj_Id);
2987 Mutate_Ekind (Obj_Id, E_Variable);
2988 Set_Etype (Obj_Id, Typ);
2989 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2990 Set_SPARK_Pragma_Inherited (Obj_Id);
2992 -- Preserve relevant elaboration-related attributes of the context which
2993 -- are no longer available or very expensive to recompute once analysis,
2994 -- resolution, and expansion are over.
2996 Mark_Elaboration_Attributes
2997 (N_Id => Obj_Id,
2998 Checks => True,
2999 Warnings => True);
3001 -- Instead of calling Analyze on the new node, call the proper analysis
3002 -- procedure directly. Otherwise the node would be expanded twice, with
3003 -- disastrous result.
3005 Analyze_Task_Type_Declaration (N);
3007 if Has_Aspects (N) then
3008 Analyze_Aspect_Specifications (N, Obj_Id);
3009 end if;
3010 end Analyze_Single_Task_Declaration;
3012 -----------------------
3013 -- Analyze_Task_Body --
3014 -----------------------
3016 procedure Analyze_Task_Body (N : Node_Id) is
3017 Body_Id : constant Entity_Id := Defining_Identifier (N);
3018 Decls : constant List_Id := Declarations (N);
3019 HSS : constant Node_Id := Handled_Statement_Sequence (N);
3020 Last_E : Entity_Id;
3022 Spec_Id : Entity_Id;
3023 -- This is initially the entity of the task or task type involved, but
3024 -- is replaced by the task type always in the case of a single task
3025 -- declaration, since this is the proper scope to be used.
3027 Ref_Id : Entity_Id;
3028 -- This is the entity of the task or task type, and is the entity used
3029 -- for cross-reference purposes (it differs from Spec_Id in the case of
3030 -- a single task, since Spec_Id is set to the task type).
3032 begin
3033 -- A task body freezes the contract of the nearest enclosing package
3034 -- body and all other contracts encountered in the same declarative part
3035 -- up to and excluding the task body. This ensures that annotations
3036 -- referenced by the contract of an entry or subprogram body declared
3037 -- within the current protected body are available.
3039 Freeze_Previous_Contracts (N);
3041 Tasking_Used := True;
3042 Set_Scope (Body_Id, Current_Scope);
3043 Mutate_Ekind (Body_Id, E_Task_Body);
3044 Set_Etype (Body_Id, Standard_Void_Type);
3045 Spec_Id := Find_Concurrent_Spec (Body_Id);
3047 -- The spec is either a task type declaration, or a single task
3048 -- declaration for which we have created an anonymous type.
3050 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Task_Type then
3051 null;
3053 elsif Present (Spec_Id)
3054 and then Ekind (Etype (Spec_Id)) = E_Task_Type
3055 and then not Comes_From_Source (Etype (Spec_Id))
3056 then
3057 null;
3059 else
3060 Error_Msg_N ("missing specification for task body", Body_Id);
3061 return;
3062 end if;
3064 if Has_Completion (Spec_Id)
3065 and then Present (Corresponding_Body (Parent (Spec_Id)))
3066 then
3067 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
3068 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
3069 else
3070 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
3071 end if;
3072 end if;
3074 Ref_Id := Spec_Id;
3075 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
3076 Style.Check_Identifier (Body_Id, Spec_Id);
3078 -- Deal with case of body of single task (anonymous type was created)
3080 if Ekind (Spec_Id) = E_Variable then
3081 Spec_Id := Etype (Spec_Id);
3082 end if;
3084 -- Set the SPARK_Mode from the current context (may be overwritten later
3085 -- with an explicit pragma).
3087 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
3088 Set_SPARK_Pragma_Inherited (Body_Id);
3090 if Has_Aspects (N) then
3091 Analyze_Aspect_Specifications (N, Body_Id);
3092 end if;
3094 Push_Scope (Spec_Id);
3095 Set_Corresponding_Spec (N, Spec_Id);
3096 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
3097 Set_Has_Completion (Spec_Id);
3098 Install_Declarations (Spec_Id);
3099 Last_E := Last_Entity (Spec_Id);
3101 Analyze_Declarations (Decls);
3102 Inspect_Deferred_Constant_Completion (Decls);
3104 -- For visibility purposes, all entities in the body are private. Set
3105 -- First_Private_Entity accordingly, if there was no private part in the
3106 -- protected declaration.
3108 if No (First_Private_Entity (Spec_Id)) then
3109 if Present (Last_E) then
3110 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
3111 else
3112 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
3113 end if;
3115 -- The entity list of the current scope now includes entities in
3116 -- the spec as well as the body. Their declarations will become
3117 -- part of the statement sequence of the task body procedure that
3118 -- is built during expansion. Indicate that aspect specifications
3119 -- for these entities need not be rechecked. The guards on
3120 -- Check_Aspect_At_End_Of_Declarations are not sufficient to
3121 -- suppress these checks, because the declarations come from source.
3123 declare
3124 Priv : Entity_Id := First_Private_Entity (Spec_Id);
3126 begin
3127 while Present (Priv) loop
3128 Set_Has_Delayed_Aspects (Priv, False);
3129 Next_Entity (Priv);
3130 end loop;
3131 end;
3132 end if;
3134 -- Mark all handlers as not suitable for local raise optimization,
3135 -- since this optimization causes difficulties in a task context.
3137 if Present (Exception_Handlers (HSS)) then
3138 declare
3139 Handlr : Node_Id;
3140 begin
3141 Handlr := First (Exception_Handlers (HSS));
3142 while Present (Handlr) loop
3143 Set_Local_Raise_Not_OK (Handlr);
3144 Next (Handlr);
3145 end loop;
3146 end;
3147 end if;
3149 -- Now go ahead and complete analysis of the task body
3151 Analyze (HSS);
3152 Check_Completion (Body_Id);
3153 Check_References (Body_Id);
3154 Check_References (Spec_Id);
3156 -- Check for entries with no corresponding accept
3158 declare
3159 Ent : Entity_Id;
3161 begin
3162 Ent := First_Entity (Spec_Id);
3163 while Present (Ent) loop
3164 if Is_Entry (Ent)
3165 and then not Entry_Accepted (Ent)
3166 and then Comes_From_Source (Ent)
3167 then
3168 Error_Msg_NE ("no accept for entry &??", N, Ent);
3169 end if;
3171 Next_Entity (Ent);
3172 end loop;
3173 end;
3175 Process_End_Label (HSS, 't', Ref_Id);
3176 Update_Use_Clause_Chain;
3177 End_Scope;
3178 end Analyze_Task_Body;
3180 -----------------------------
3181 -- Analyze_Task_Definition --
3182 -----------------------------
3184 procedure Analyze_Task_Definition (N : Node_Id) is
3185 L : Entity_Id;
3187 begin
3188 Tasking_Used := True;
3190 if Present (Visible_Declarations (N)) then
3191 Analyze_Declarations (Visible_Declarations (N));
3192 end if;
3194 if Present (Private_Declarations (N)) then
3195 L := Last_Entity (Current_Scope);
3196 Analyze_Declarations (Private_Declarations (N));
3198 if Present (L) then
3199 Set_First_Private_Entity
3200 (Current_Scope, Next_Entity (L));
3201 else
3202 Set_First_Private_Entity
3203 (Current_Scope, First_Entity (Current_Scope));
3204 end if;
3205 end if;
3207 Check_Max_Entries (N, Max_Task_Entries);
3208 Process_End_Label (N, 'e', Current_Scope);
3209 end Analyze_Task_Definition;
3211 -----------------------------------
3212 -- Analyze_Task_Type_Declaration --
3213 -----------------------------------
3215 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
3216 Def_Id : constant Entity_Id := Defining_Identifier (N);
3217 T : Entity_Id;
3219 begin
3220 -- Attempt to use tasking in no run time mode is not allowe. Issue hard
3221 -- error message to disable expansion which leads to crashes.
3223 if Opt.No_Run_Time_Mode then
3224 Error_Msg_N ("tasking not allowed in No_Run_Time mode", N);
3226 -- Otherwise soft check for no tasking restriction
3228 else
3229 Check_Restriction (No_Tasking, N);
3230 end if;
3232 -- Proceed ahead with analysis of task type declaration
3234 Tasking_Used := True;
3236 -- The sequential partition elaboration policy is supported only in the
3237 -- restricted profile.
3239 if Partition_Elaboration_Policy = 'S'
3240 and then not Restricted_Profile
3241 then
3242 Error_Msg_N
3243 ("sequential elaboration supported only in restricted profile", N);
3244 end if;
3246 T := Find_Type_Name (N);
3247 Generate_Definition (T);
3249 -- In the case of an incomplete type, use the full view, unless it's not
3250 -- present (as can occur for an incomplete view from a limited with).
3251 -- Initialize the Corresponding_Record_Type (which overlays the Private
3252 -- Dependents field of the incomplete view).
3254 if Ekind (T) = E_Incomplete_Type then
3255 if Present (Full_View (T)) then
3256 T := Full_View (T);
3257 Set_Completion_Referenced (T);
3259 else
3260 Mutate_Ekind (T, E_Task_Type);
3261 Set_Corresponding_Record_Type (T, Empty);
3262 end if;
3263 end if;
3265 Mutate_Ekind (T, E_Task_Type);
3266 Set_Is_First_Subtype (T, True);
3267 Set_Has_Task (T, True);
3268 Reinit_Size_Align (T);
3269 Set_Etype (T, T);
3270 Set_Has_Delayed_Freeze (T, True);
3271 Set_Stored_Constraint (T, No_Elist);
3273 -- Initialize type's primitive operations list, for possible use when
3274 -- the extension of prefixed call notation for untagged types is enabled
3275 -- (such as by use of -gnatX).
3277 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3279 -- Set the SPARK_Mode from the current context (may be overwritten later
3280 -- with an explicit pragma).
3282 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
3283 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
3284 Set_SPARK_Pragma_Inherited (T);
3285 Set_SPARK_Aux_Pragma_Inherited (T);
3287 -- Preserve relevant elaboration-related attributes of the context which
3288 -- are no longer available or very expensive to recompute once analysis,
3289 -- resolution, and expansion are over.
3291 Mark_Elaboration_Attributes
3292 (N_Id => T,
3293 Checks => True,
3294 Warnings => True);
3296 Push_Scope (T);
3298 if Ada_Version >= Ada_2005 then
3299 Check_Interfaces (N, T);
3300 end if;
3302 if Present (Discriminant_Specifications (N)) then
3303 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3304 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
3305 end if;
3307 if Has_Discriminants (T) then
3309 -- Install discriminants. Also, verify conformance of
3310 -- discriminants of previous and current view. ???
3312 Install_Declarations (T);
3313 else
3314 Process_Discriminants (N);
3315 end if;
3316 end if;
3318 Set_Is_Constrained (T, not Has_Discriminants (T));
3320 if Has_Aspects (N) then
3322 -- The task type is the full view of a private type. Analyze the
3323 -- aspects with the entity of the private type to ensure that after
3324 -- both views are exchanged, the aspect are actually associated with
3325 -- the full view.
3327 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3328 Analyze_Aspect_Specifications (N, T);
3329 else
3330 Analyze_Aspect_Specifications (N, Def_Id);
3331 end if;
3332 end if;
3334 if Present (Task_Definition (N)) then
3335 Analyze_Task_Definition (Task_Definition (N));
3336 end if;
3338 -- In the case where the task type is declared at a nested level and the
3339 -- No_Task_Hierarchy restriction applies, issue a warning that objects
3340 -- of the type will violate the restriction.
3342 if Restriction_Check_Required (No_Task_Hierarchy)
3343 and then not Is_Library_Level_Entity (T)
3344 and then Comes_From_Source (T)
3345 and then not CodePeer_Mode
3346 then
3347 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
3349 if Error_Msg_Sloc = No_Location then
3350 Error_Msg_N
3351 ("objects of this type will violate `No_Task_Hierarchy`??", N);
3352 else
3353 Error_Msg_N
3354 ("objects of this type will violate `No_Task_Hierarchy`#??", N);
3355 end if;
3356 end if;
3358 End_Scope;
3360 -- Case of a completion of a private declaration
3362 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3364 -- Deal with preelaborable initialization. Note that this processing
3365 -- is done by Process_Full_View, but as can be seen below, in this
3366 -- case the call to Process_Full_View is skipped if any serious
3367 -- errors have occurred, and we don't want to lose this check.
3369 if Known_To_Have_Preelab_Init (Def_Id) then
3370 Set_Must_Have_Preelab_Init (T);
3371 end if;
3373 -- Propagate Default_Initial_Condition-related attributes from the
3374 -- private type to the task type.
3376 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
3378 -- Propagate invariant-related attributes from the private type to
3379 -- task type.
3381 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
3383 -- Propagate predicate-related attributes from the private type to
3384 -- task type.
3386 Propagate_Predicate_Attributes (T, From_Typ => Def_Id);
3388 -- Create corresponding record now, because some private dependents
3389 -- may be subtypes of the partial view.
3391 -- Skip if errors are present, to prevent cascaded messages
3393 if Serious_Errors_Detected = 0
3395 -- Also skip if expander is not active
3397 and then Expander_Active
3398 then
3399 Expand_N_Task_Type_Declaration (N);
3400 Process_Full_View (N, T, Def_Id);
3401 end if;
3402 end if;
3404 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
3405 -- is required for the ceiling priority protocol checks triggered by
3406 -- calls originating from tasks.
3408 if GNATprove_Mode then
3409 SPARK_Implicit_Load (RE_Interrupt_Priority);
3410 end if;
3411 end Analyze_Task_Type_Declaration;
3413 -----------------------------------
3414 -- Analyze_Terminate_Alternative --
3415 -----------------------------------
3417 procedure Analyze_Terminate_Alternative (N : Node_Id) is
3418 begin
3419 Tasking_Used := True;
3421 if Present (Pragmas_Before (N)) then
3422 Analyze_List (Pragmas_Before (N));
3423 end if;
3425 if Present (Condition (N)) then
3426 Analyze_And_Resolve (Condition (N), Any_Boolean);
3427 end if;
3428 end Analyze_Terminate_Alternative;
3430 ------------------------------
3431 -- Analyze_Timed_Entry_Call --
3432 ------------------------------
3434 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
3435 Trigger : constant Node_Id :=
3436 Entry_Call_Statement (Entry_Call_Alternative (N));
3437 Is_Disp_Select : Boolean := False;
3439 begin
3440 Tasking_Used := True;
3441 Check_Restriction (No_Select_Statements, N);
3443 -- Ada 2005 (AI-345): The trigger may be a dispatching call
3445 if Ada_Version >= Ada_2005 then
3446 Analyze (Trigger);
3447 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
3448 end if;
3450 -- Postpone the analysis of the statements till expansion. Analyze only
3451 -- if the expander is disabled in order to catch any semantic errors.
3453 if Is_Disp_Select then
3454 if not Expander_Active then
3455 Analyze (Entry_Call_Alternative (N));
3456 Analyze (Delay_Alternative (N));
3457 end if;
3459 -- Regular select analysis
3461 else
3462 Analyze (Entry_Call_Alternative (N));
3463 Analyze (Delay_Alternative (N));
3464 end if;
3465 end Analyze_Timed_Entry_Call;
3467 ------------------------------------
3468 -- Analyze_Triggering_Alternative --
3469 ------------------------------------
3471 procedure Analyze_Triggering_Alternative (N : Node_Id) is
3472 Trigger : constant Node_Id := Triggering_Statement (N);
3474 begin
3475 Tasking_Used := True;
3477 if Present (Pragmas_Before (N)) then
3478 Analyze_List (Pragmas_Before (N));
3479 end if;
3481 Analyze (Trigger);
3483 if Comes_From_Source (Trigger)
3484 and then Nkind (Trigger) not in N_Delay_Statement
3485 and then Nkind (Trigger) /= N_Entry_Call_Statement
3486 then
3487 if Ada_Version < Ada_2005 then
3488 Error_Msg_N
3489 ("triggering statement must be delay or entry call", Trigger);
3491 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
3492 -- procedure_or_entry_call, the procedure_name or procedure_prefix
3493 -- of the procedure_call_statement shall denote an entry renamed by a
3494 -- procedure, or (a view of) a primitive subprogram of a limited
3495 -- interface whose first parameter is a controlling parameter.
3497 elsif Nkind (Trigger) = N_Procedure_Call_Statement
3498 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
3499 and then not Is_Controlling_Limited_Procedure
3500 (Entity (Name (Trigger)))
3501 then
3502 Error_Msg_N
3503 ("triggering statement must be procedure or entry call " &
3504 "or delay statement", Trigger);
3505 end if;
3506 end if;
3508 if Is_Non_Empty_List (Statements (N)) then
3509 Analyze_Statements (Statements (N));
3510 end if;
3511 end Analyze_Triggering_Alternative;
3513 -----------------------
3514 -- Check_Max_Entries --
3515 -----------------------
3517 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
3518 Ecount : Uint;
3520 procedure Count (L : List_Id);
3521 -- Count entries in given declaration list
3523 -----------
3524 -- Count --
3525 -----------
3527 procedure Count (L : List_Id) is
3528 D : Node_Id;
3530 begin
3531 if No (L) then
3532 return;
3533 end if;
3535 D := First (L);
3536 while Present (D) loop
3537 if Nkind (D) = N_Entry_Declaration then
3538 declare
3539 DSD : constant Node_Id :=
3540 Discrete_Subtype_Definition (D);
3542 begin
3543 -- If not an entry family, then just one entry
3545 if No (DSD) then
3546 Ecount := Ecount + 1;
3548 -- If entry family with static bounds, count entries
3550 elsif Is_OK_Static_Subtype (Etype (DSD)) then
3551 declare
3552 Lo : constant Uint :=
3553 Expr_Value
3554 (Type_Low_Bound (Etype (DSD)));
3555 Hi : constant Uint :=
3556 Expr_Value
3557 (Type_High_Bound (Etype (DSD)));
3559 begin
3560 if Hi >= Lo then
3561 Ecount := Ecount + Hi - Lo + 1;
3562 end if;
3563 end;
3565 -- Entry family with non-static bounds
3567 else
3568 -- Record an unknown count restriction, and if the
3569 -- restriction is active, post a message or warning.
3571 Check_Restriction (R, D);
3572 end if;
3573 end;
3574 end if;
3576 Next (D);
3577 end loop;
3578 end Count;
3580 -- Start of processing for Check_Max_Entries
3582 begin
3583 Ecount := Uint_0;
3584 Count (Visible_Declarations (D));
3585 Count (Private_Declarations (D));
3587 if Ecount > 0 then
3588 Check_Restriction (R, D, Ecount);
3589 end if;
3590 end Check_Max_Entries;
3592 ----------------------
3593 -- Check_Interfaces --
3594 ----------------------
3596 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
3597 Iface : Node_Id;
3598 Iface_Typ : Entity_Id;
3600 begin
3601 pragma Assert
3602 (Nkind (N) in N_Protected_Type_Declaration | N_Task_Type_Declaration);
3604 if Present (Interface_List (N)) then
3605 Set_Is_Tagged_Type (T);
3607 -- The primitive operations of a tagged synchronized type are placed
3608 -- on the Corresponding_Record for proper dispatching, but are
3609 -- attached to the synchronized type itself when expansion is
3610 -- disabled.
3612 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3614 Iface := First (Interface_List (N));
3615 while Present (Iface) loop
3616 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
3618 if not Is_Interface (Iface_Typ) then
3619 Error_Msg_NE
3620 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
3622 else
3623 -- Ada 2005 (AI-251): "The declaration of a specific descendant
3624 -- of an interface type freezes the interface type" RM 13.14.
3626 Freeze_Before (N, Etype (Iface));
3628 if Nkind (N) = N_Protected_Type_Declaration then
3630 -- Ada 2005 (AI-345): Protected types can only implement
3631 -- limited, synchronized, or protected interfaces (note that
3632 -- the predicate Is_Limited_Interface includes synchronized
3633 -- and protected interfaces).
3635 if Is_Task_Interface (Iface_Typ) then
3636 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3637 & "a task interface", Iface);
3639 elsif not Is_Limited_Interface (Iface_Typ) then
3640 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3641 & "a non-limited interface", Iface);
3642 end if;
3644 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
3646 -- Ada 2005 (AI-345): Task types can only implement limited,
3647 -- synchronized, or task interfaces (note that the predicate
3648 -- Is_Limited_Interface includes synchronized and task
3649 -- interfaces).
3651 if Is_Protected_Interface (Iface_Typ) then
3652 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3653 "protected interface", Iface);
3655 elsif not Is_Limited_Interface (Iface_Typ) then
3656 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3657 "non-limited interface", Iface);
3658 end if;
3659 end if;
3660 end if;
3662 Next (Iface);
3663 end loop;
3665 -- Check consistency of any nonoverridable aspects that are
3666 -- inherited from multiple sources.
3668 Check_Inherited_Nonoverridable_Aspects
3669 (Inheritor => N,
3670 Interface_List => Interface_List (N),
3671 Parent_Type => Empty);
3672 end if;
3674 if not Has_Private_Declaration (T) then
3675 return;
3676 end if;
3678 -- Additional checks on full-types associated with private type
3679 -- declarations. Search for the private type declaration.
3681 declare
3682 Full_T_Ifaces : Elist_Id := No_Elist;
3683 Iface : Node_Id;
3684 Priv_T : Entity_Id;
3685 Priv_T_Ifaces : Elist_Id := No_Elist;
3687 begin
3688 Priv_T := First_Entity (Scope (T));
3689 loop
3690 pragma Assert (Present (Priv_T));
3692 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
3693 exit when Full_View (Priv_T) = T;
3694 end if;
3696 Next_Entity (Priv_T);
3697 end loop;
3699 -- In case of synchronized types covering interfaces the private type
3700 -- declaration must be limited.
3702 if Present (Interface_List (N))
3703 and then not Is_Limited_Type (Priv_T)
3704 then
3705 Error_Msg_Sloc := Sloc (Priv_T);
3706 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
3707 "private type#", T);
3708 end if;
3710 -- RM 7.3 (7.1/2): If the full view has a partial view that is
3711 -- tagged then check RM 7.3 subsidiary rules.
3713 if Is_Tagged_Type (Priv_T)
3714 and then not Error_Posted (N)
3715 then
3716 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
3717 -- type if and only if the full type is a synchronized tagged type
3719 if Is_Synchronized_Tagged_Type (Priv_T)
3720 and then not Is_Synchronized_Tagged_Type (T)
3721 then
3722 Error_Msg_N
3723 ("(Ada 2005) full view must be a synchronized tagged " &
3724 "type (RM 7.3 (7.2/2))", Priv_T);
3726 elsif Is_Synchronized_Tagged_Type (T)
3727 and then not Is_Synchronized_Tagged_Type (Priv_T)
3728 then
3729 Error_Msg_N
3730 ("(Ada 2005) partial view must be a synchronized tagged " &
3731 "type (RM 7.3 (7.2/2))", T);
3732 end if;
3734 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
3735 -- interface type if and only if the full type is descendant of
3736 -- the interface type.
3738 if Present (Interface_List (N))
3739 or else (Is_Tagged_Type (Priv_T)
3740 and then Has_Interfaces
3741 (Priv_T, Use_Full_View => False))
3742 then
3743 if Is_Tagged_Type (Priv_T) then
3744 Collect_Interfaces
3745 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
3746 end if;
3748 if Is_Tagged_Type (T) then
3749 Collect_Interfaces (T, Full_T_Ifaces);
3750 end if;
3752 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
3754 if Present (Iface) then
3755 Error_Msg_NE
3756 ("interface in partial view& not implemented by full "
3757 & "type (RM-2005 7.3 (7.3/2))", T, Iface);
3758 end if;
3760 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
3762 if Present (Iface) then
3763 Error_Msg_NE
3764 ("interface & not implemented by partial " &
3765 "view (RM-2005 7.3 (7.3/2))", T, Iface);
3766 end if;
3767 end if;
3768 end if;
3769 end;
3770 end Check_Interfaces;
3772 --------------------------------
3773 -- Check_Triggering_Statement --
3774 --------------------------------
3776 procedure Check_Triggering_Statement
3777 (Trigger : Node_Id;
3778 Error_Node : Node_Id;
3779 Is_Dispatching : out Boolean)
3781 Param : Node_Id;
3783 begin
3784 Is_Dispatching := False;
3786 -- It is not possible to have a dispatching trigger if we are not in
3787 -- Ada 2005 mode.
3789 if Ada_Version >= Ada_2005
3790 and then Nkind (Trigger) = N_Procedure_Call_Statement
3791 and then Present (Parameter_Associations (Trigger))
3792 then
3793 Param := First (Parameter_Associations (Trigger));
3795 if Is_Controlling_Actual (Param)
3796 and then Is_Interface (Etype (Param))
3797 then
3798 if Is_Limited_Record (Etype (Param)) then
3799 Is_Dispatching := True;
3800 else
3801 Error_Msg_N
3802 ("dispatching operation of limited or synchronized " &
3803 "interface required (RM 9.7.2(3))!", Error_Node);
3804 end if;
3806 elsif Nkind (Trigger) = N_Explicit_Dereference then
3807 Error_Msg_N
3808 ("entry call or dispatching primitive of interface required",
3809 Trigger);
3810 end if;
3811 end if;
3812 end Check_Triggering_Statement;
3814 --------------------------
3815 -- Find_Concurrent_Spec --
3816 --------------------------
3818 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
3819 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
3821 begin
3822 -- The type may have been given by an incomplete type declaration.
3823 -- Find full view now.
3825 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
3826 Spec_Id := Full_View (Spec_Id);
3827 end if;
3829 return Spec_Id;
3830 end Find_Concurrent_Spec;
3832 --------------------------
3833 -- Install_Declarations --
3834 --------------------------
3836 procedure Install_Declarations (Spec : Entity_Id) is
3837 E : Entity_Id;
3838 Prev : Entity_Id;
3839 begin
3840 E := First_Entity (Spec);
3841 while Present (E) loop
3842 Prev := Current_Entity (E);
3843 Set_Current_Entity (E);
3844 Set_Is_Immediately_Visible (E);
3845 Set_Homonym (E, Prev);
3846 Next_Entity (E);
3847 end loop;
3848 end Install_Declarations;
3850 end Sem_Ch9;