re PR target/82015 (PowerPC should check if 2nd argument to __builtin_unpackv1ti...
[official-gcc.git] / gcc / ada / sem_ch9.adb
blob184fe43e50c86ad43f0d68faefac415b8f8b0b79
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-2017, 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 Debug; use Debug;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Exp_Ch9; use Exp_Ch9;
34 with Elists; use Elists;
35 with Freeze; use Freeze;
36 with Layout; use Layout;
37 with Lib; use Lib;
38 with Lib.Xref; use Lib.Xref;
39 with Namet; use Namet;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Opt; use Opt;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Rtsfind; use Rtsfind;
46 with Sem; use Sem;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Ch3; use Sem_Ch3;
49 with Sem_Ch5; use Sem_Ch5;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Ch13; use Sem_Ch13;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Sem_Warn; use Sem_Warn;
59 with Snames; use Snames;
60 with Stand; use Stand;
61 with Sinfo; use Sinfo;
62 with Style;
63 with Tbuild; use Tbuild;
64 with Uintp; use Uintp;
66 package body Sem_Ch9 is
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 function Allows_Lock_Free_Implementation
73 (N : Node_Id;
74 Lock_Free_Given : Boolean := False) return Boolean;
75 -- This routine returns True iff N satisfies the following list of lock-
76 -- free restrictions for protected type declaration and protected body:
78 -- 1) Protected type declaration
79 -- May not contain entries
80 -- Protected subprogram declarations may not have non-elementary
81 -- parameters.
83 -- 2) Protected Body
84 -- Each protected subprogram body within N must satisfy:
85 -- May reference only one protected component
86 -- May not reference non-constant entities outside the protected
87 -- subprogram scope.
88 -- May not contain address representation items, allocators and
89 -- quantified expressions.
90 -- May not contain delay, goto, loop and procedure call
91 -- statements.
92 -- May not contain exported and imported entities
93 -- May not dereference access values
94 -- Function calls and attribute references must be static
96 -- If Lock_Free_Given is True, an error message is issued when False is
97 -- returned.
99 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions);
100 -- Given either a protected definition or a task definition in D, check
101 -- the corresponding restriction parameter identifier R, and if it is set,
102 -- count the entries (checking the static requirement), and compare with
103 -- the given maximum.
105 procedure Check_Interfaces (N : Node_Id; T : Entity_Id);
106 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
107 -- Complete decoration of T and check legality of the covered interfaces.
109 procedure Check_Triggering_Statement
110 (Trigger : Node_Id;
111 Error_Node : Node_Id;
112 Is_Dispatching : out Boolean);
113 -- Examine the triggering statement of a select statement, conditional or
114 -- timed entry call. If Trigger is a dispatching call, return its status
115 -- in Is_Dispatching and check whether the primitive belongs to a limited
116 -- interface. If it does not, emit an error at Error_Node.
118 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id;
119 -- Find entity in corresponding task or protected declaration. Use full
120 -- view if first declaration was for an incomplete type.
122 -------------------------------------
123 -- Allows_Lock_Free_Implementation --
124 -------------------------------------
126 function Allows_Lock_Free_Implementation
127 (N : Node_Id;
128 Lock_Free_Given : Boolean := False) return Boolean
130 Errors_Count : Nat := 0;
131 -- Errors_Count is a count of errors detected by the compiler so far
132 -- when Lock_Free_Given is True.
134 begin
135 pragma Assert (Nkind_In (N, N_Protected_Type_Declaration,
136 N_Protected_Body));
138 -- The lock-free implementation is currently enabled through a debug
139 -- flag. When Lock_Free_Given is True, an aspect Lock_Free forces the
140 -- lock-free implementation. In that case, the debug flag is not needed.
142 if not Lock_Free_Given and then not Debug_Flag_9 then
143 return False;
144 end if;
146 -- Get the number of errors detected by the compiler so far
148 if Lock_Free_Given then
149 Errors_Count := Serious_Errors_Detected;
150 end if;
152 -- Protected type declaration case
154 if Nkind (N) = N_Protected_Type_Declaration then
155 declare
156 Pdef : constant Node_Id := Protected_Definition (N);
157 Priv_Decls : constant List_Id := Private_Declarations (Pdef);
158 Vis_Decls : constant List_Id := Visible_Declarations (Pdef);
159 Decl : Node_Id;
161 begin
162 -- Examine the visible and the private declarations
164 Decl := First (Vis_Decls);
165 while Present (Decl) loop
167 -- Entries and entry families are not allowed by the lock-free
168 -- restrictions.
170 if Nkind (Decl) = N_Entry_Declaration then
171 if Lock_Free_Given then
172 Error_Msg_N
173 ("entry not allowed when Lock_Free given", Decl);
174 else
175 return False;
176 end if;
178 -- Non-elementary parameters in protected procedure are not
179 -- allowed by the lock-free restrictions.
181 elsif Nkind (Decl) = N_Subprogram_Declaration
182 and then
183 Nkind (Specification (Decl)) = N_Procedure_Specification
184 and then
185 Present (Parameter_Specifications (Specification (Decl)))
186 then
187 declare
188 Par_Specs : constant List_Id :=
189 Parameter_Specifications
190 (Specification (Decl));
192 Par : Node_Id;
194 begin
195 Par := First (Par_Specs);
196 while Present (Par) loop
197 if not Is_Elementary_Type
198 (Etype (Defining_Identifier (Par)))
199 then
200 if Lock_Free_Given then
201 Error_Msg_NE
202 ("non-elementary parameter& not allowed "
203 & "when Lock_Free given",
204 Par, Defining_Identifier (Par));
205 else
206 return False;
207 end if;
208 end if;
210 Next (Par);
211 end loop;
212 end;
213 end if;
215 -- Examine private declarations after visible declarations
217 if No (Next (Decl))
218 and then List_Containing (Decl) = Vis_Decls
219 then
220 Decl := First (Priv_Decls);
221 else
222 Next (Decl);
223 end if;
224 end loop;
225 end;
227 -- Protected body case
229 else
230 Protected_Body_Case : declare
231 Decls : constant List_Id := Declarations (N);
232 Pid : constant Entity_Id := Corresponding_Spec (N);
233 Prot_Typ_Decl : constant Node_Id := Parent (Pid);
234 Prot_Def : constant Node_Id :=
235 Protected_Definition (Prot_Typ_Decl);
236 Priv_Decls : constant List_Id :=
237 Private_Declarations (Prot_Def);
238 Decl : Node_Id;
240 function Satisfies_Lock_Free_Requirements
241 (Sub_Body : Node_Id) return Boolean;
242 -- Return True if protected subprogram body Sub_Body satisfies all
243 -- requirements of a lock-free implementation.
245 --------------------------------------
246 -- Satisfies_Lock_Free_Requirements --
247 --------------------------------------
249 function Satisfies_Lock_Free_Requirements
250 (Sub_Body : Node_Id) return Boolean
252 Is_Procedure : constant Boolean :=
253 Ekind (Corresponding_Spec (Sub_Body)) =
254 E_Procedure;
255 -- Indicates if Sub_Body is a procedure body
257 Comp : Entity_Id := Empty;
258 -- Track the current component which the body references
260 Errors_Count : Nat := 0;
261 -- Errors_Count is a count of errors detected by the compiler
262 -- so far when Lock_Free_Given is True.
264 function Check_Node (N : Node_Id) return Traverse_Result;
265 -- Check that node N meets the lock free restrictions
267 ----------------
268 -- Check_Node --
269 ----------------
271 function Check_Node (N : Node_Id) return Traverse_Result is
272 Kind : constant Node_Kind := Nkind (N);
274 -- The following function belongs in sem_eval ???
276 function Is_Static_Function (Attr : Node_Id) return Boolean;
277 -- Given an attribute reference node Attr, return True if
278 -- Attr denotes a static function according to the rules in
279 -- (RM 4.9 (22)).
281 ------------------------
282 -- Is_Static_Function --
283 ------------------------
285 function Is_Static_Function
286 (Attr : Node_Id) return Boolean
288 Para : Node_Id;
290 begin
291 pragma Assert (Nkind (Attr) = N_Attribute_Reference);
293 case Attribute_Name (Attr) is
294 when Name_Max
295 | Name_Min
296 | Name_Pred
297 | Name_Succ
298 | Name_Value
299 | Name_Wide_Value
300 | Name_Wide_Wide_Value
302 -- A language-defined attribute denotes a static
303 -- function if the prefix denotes a static scalar
304 -- subtype, and if the parameter and result types
305 -- are scalar (RM 4.9 (22)).
307 if Is_Scalar_Type (Etype (Attr))
308 and then Is_Scalar_Type (Etype (Prefix (Attr)))
309 and then
310 Is_OK_Static_Subtype (Etype (Prefix (Attr)))
311 then
312 Para := First (Expressions (Attr));
314 while Present (Para) loop
315 if not Is_Scalar_Type (Etype (Para)) then
316 return False;
317 end if;
319 Next (Para);
320 end loop;
322 return True;
324 else
325 return False;
326 end if;
328 when others =>
329 return False;
330 end case;
331 end Is_Static_Function;
333 -- Start of processing for Check_Node
335 begin
336 if Is_Procedure then
337 -- Allocators restricted
339 if Kind = N_Allocator then
340 if Lock_Free_Given then
341 Error_Msg_N ("allocator not allowed", N);
342 return Skip;
343 end if;
345 return Abandon;
347 -- Aspects Address, Export and Import restricted
349 elsif Kind = N_Aspect_Specification then
350 declare
351 Asp_Name : constant Name_Id :=
352 Chars (Identifier (N));
353 Asp_Id : constant Aspect_Id :=
354 Get_Aspect_Id (Asp_Name);
356 begin
357 if Asp_Id = Aspect_Address or else
358 Asp_Id = Aspect_Export or else
359 Asp_Id = Aspect_Import
360 then
361 Error_Msg_Name_1 := Asp_Name;
363 if Lock_Free_Given then
364 Error_Msg_N ("aspect% not allowed", N);
365 return Skip;
366 end if;
368 return Abandon;
369 end if;
370 end;
372 -- Address attribute definition clause restricted
374 elsif Kind = N_Attribute_Definition_Clause
375 and then Get_Attribute_Id (Chars (N)) =
376 Attribute_Address
377 then
378 Error_Msg_Name_1 := Chars (N);
380 if Lock_Free_Given then
381 if From_Aspect_Specification (N) then
382 Error_Msg_N ("aspect% not allowed", N);
383 else
384 Error_Msg_N ("% clause not allowed", N);
385 end if;
387 return Skip;
388 end if;
390 return Abandon;
392 -- Non-static Attribute references that don't denote a
393 -- static function restricted.
395 elsif Kind = N_Attribute_Reference
396 and then not Is_OK_Static_Expression (N)
397 and then not Is_Static_Function (N)
398 then
399 if Lock_Free_Given then
400 Error_Msg_N
401 ("non-static attribute reference not allowed", N);
402 return Skip;
403 end if;
405 return Abandon;
407 -- Delay statements restricted
409 elsif Kind in N_Delay_Statement then
410 if Lock_Free_Given then
411 Error_Msg_N ("delay not allowed", N);
412 return Skip;
413 end if;
415 return Abandon;
417 -- Dereferences of access values restricted
419 elsif Kind = N_Explicit_Dereference
420 or else (Kind = N_Selected_Component
421 and then Is_Access_Type (Etype (Prefix (N))))
422 then
423 if Lock_Free_Given then
424 Error_Msg_N
425 ("dereference of access value not allowed", N);
426 return Skip;
427 end if;
429 return Abandon;
431 -- Non-static function calls restricted
433 elsif Kind = N_Function_Call
434 and then not Is_OK_Static_Expression (N)
435 then
436 if Lock_Free_Given then
437 Error_Msg_N
438 ("non-static function call not allowed", N);
439 return Skip;
440 end if;
442 return Abandon;
444 -- Goto statements restricted
446 elsif Kind = N_Goto_Statement then
447 if Lock_Free_Given then
448 Error_Msg_N ("goto statement not allowed", N);
449 return Skip;
450 end if;
452 return Abandon;
454 -- References
456 elsif Kind = N_Identifier
457 and then Present (Entity (N))
458 then
459 declare
460 Id : constant Entity_Id := Entity (N);
461 Sub_Id : constant Entity_Id :=
462 Corresponding_Spec (Sub_Body);
464 begin
465 -- Prohibit references to non-constant entities
466 -- outside the protected subprogram scope.
468 if Ekind (Id) in Assignable_Kind
469 and then not
470 Scope_Within_Or_Same (Scope (Id), Sub_Id)
471 and then not
472 Scope_Within_Or_Same
473 (Scope (Id),
474 Protected_Body_Subprogram (Sub_Id))
475 then
476 if Lock_Free_Given then
477 Error_Msg_NE
478 ("reference to global variable& not " &
479 "allowed", N, Id);
480 return Skip;
481 end if;
483 return Abandon;
484 end if;
485 end;
487 -- Loop statements restricted
489 elsif Kind = N_Loop_Statement then
490 if Lock_Free_Given then
491 Error_Msg_N ("loop not allowed", N);
492 return Skip;
493 end if;
495 return Abandon;
497 -- Pragmas Export and Import restricted
499 elsif Kind = N_Pragma then
500 declare
501 Prag_Name : constant Name_Id :=
502 Pragma_Name (N);
503 Prag_Id : constant Pragma_Id :=
504 Get_Pragma_Id (Prag_Name);
506 begin
507 if Prag_Id = Pragma_Export
508 or else Prag_Id = Pragma_Import
509 then
510 Error_Msg_Name_1 := Prag_Name;
512 if Lock_Free_Given then
513 if From_Aspect_Specification (N) then
514 Error_Msg_N ("aspect% not allowed", N);
515 else
516 Error_Msg_N ("pragma% not allowed", N);
517 end if;
519 return Skip;
520 end if;
522 return Abandon;
523 end if;
524 end;
526 -- Procedure call statements restricted
528 elsif Kind = N_Procedure_Call_Statement then
529 if Lock_Free_Given then
530 Error_Msg_N ("procedure call not allowed", N);
531 return Skip;
532 end if;
534 return Abandon;
536 -- Quantified expression restricted. Note that we have
537 -- to check the original node as well, since at this
538 -- stage, it may have been rewritten.
540 elsif Kind = N_Quantified_Expression
541 or else
542 Nkind (Original_Node (N)) = N_Quantified_Expression
543 then
544 if Lock_Free_Given then
545 Error_Msg_N
546 ("quantified expression not allowed", N);
547 return Skip;
548 end if;
550 return Abandon;
551 end if;
552 end if;
554 -- A protected subprogram (function or procedure) may
555 -- reference only one component of the protected type, plus
556 -- the type of the component must support atomic operation.
558 if Kind = N_Identifier
559 and then Present (Entity (N))
560 then
561 declare
562 Id : constant Entity_Id := Entity (N);
563 Comp_Decl : Node_Id;
564 Comp_Id : Entity_Id := Empty;
565 Comp_Type : Entity_Id;
567 begin
568 if Ekind (Id) = E_Component then
569 Comp_Id := Id;
571 elsif Ekind_In (Id, E_Constant, E_Variable)
572 and then Present (Prival_Link (Id))
573 then
574 Comp_Id := Prival_Link (Id);
575 end if;
577 if Present (Comp_Id) then
578 Comp_Decl := Parent (Comp_Id);
579 Comp_Type := Etype (Comp_Id);
581 if Nkind (Comp_Decl) = N_Component_Declaration
582 and then Is_List_Member (Comp_Decl)
583 and then List_Containing (Comp_Decl) = Priv_Decls
584 then
585 -- Skip generic types since, in that case, we
586 -- will not build a body anyway (in the generic
587 -- template), and the size in the template may
588 -- have a fake value.
590 if not Is_Generic_Type (Comp_Type) then
592 -- Make sure the protected component type has
593 -- size and alignment fields set at this
594 -- point whenever this is possible.
596 Layout_Type (Comp_Type);
598 if not
599 Support_Atomic_Primitives (Comp_Type)
600 then
601 if Lock_Free_Given then
602 Error_Msg_NE
603 ("type of& must support atomic " &
604 "operations",
605 N, Comp_Id);
606 return Skip;
607 end if;
609 return Abandon;
610 end if;
611 end if;
613 -- Check if another protected component has
614 -- already been accessed by the subprogram body.
616 if No (Comp) then
617 Comp := Comp_Id;
619 elsif Comp /= Comp_Id then
620 if Lock_Free_Given then
621 Error_Msg_N
622 ("only one protected component allowed",
624 return Skip;
625 end if;
627 return Abandon;
628 end if;
629 end if;
630 end if;
631 end;
632 end if;
634 return OK;
635 end Check_Node;
637 function Check_All_Nodes is new Traverse_Func (Check_Node);
639 -- Start of processing for Satisfies_Lock_Free_Requirements
641 begin
642 -- Get the number of errors detected by the compiler so far
644 if Lock_Free_Given then
645 Errors_Count := Serious_Errors_Detected;
646 end if;
648 if Check_All_Nodes (Sub_Body) = OK
649 and then (not Lock_Free_Given
650 or else Errors_Count = Serious_Errors_Detected)
651 then
652 -- Establish a relation between the subprogram body and the
653 -- unique protected component it references.
655 if Present (Comp) then
656 Lock_Free_Subprogram_Table.Append
657 (Lock_Free_Subprogram'(Sub_Body, Comp));
658 end if;
660 return True;
661 else
662 return False;
663 end if;
664 end Satisfies_Lock_Free_Requirements;
666 -- Start of processing for Protected_Body_Case
668 begin
669 Decl := First (Decls);
670 while Present (Decl) loop
671 if Nkind (Decl) = N_Subprogram_Body
672 and then not Satisfies_Lock_Free_Requirements (Decl)
673 then
674 if Lock_Free_Given then
675 Error_Msg_N
676 ("illegal body when Lock_Free given", Decl);
677 else
678 return False;
679 end if;
680 end if;
682 Next (Decl);
683 end loop;
684 end Protected_Body_Case;
685 end if;
687 -- When Lock_Free is given, check if no error has been detected during
688 -- the process.
690 if Lock_Free_Given
691 and then Errors_Count /= Serious_Errors_Detected
692 then
693 return False;
694 end if;
696 return True;
697 end Allows_Lock_Free_Implementation;
699 -----------------------------
700 -- Analyze_Abort_Statement --
701 -----------------------------
703 procedure Analyze_Abort_Statement (N : Node_Id) is
704 T_Name : Node_Id;
706 begin
707 Tasking_Used := True;
708 Check_SPARK_05_Restriction ("abort statement is not allowed", N);
710 T_Name := First (Names (N));
711 while Present (T_Name) loop
712 Analyze (T_Name);
714 if Is_Task_Type (Etype (T_Name))
715 or else (Ada_Version >= Ada_2005
716 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
717 and then Is_Interface (Etype (T_Name))
718 and then Is_Task_Interface (Etype (T_Name)))
719 then
720 Resolve (T_Name);
721 else
722 if Ada_Version >= Ada_2005 then
723 Error_Msg_N ("expect task name or task interface class-wide "
724 & "object for ABORT", T_Name);
725 else
726 Error_Msg_N ("expect task name for ABORT", T_Name);
727 end if;
729 return;
730 end if;
732 Next (T_Name);
733 end loop;
735 Check_Restriction (No_Abort_Statements, N);
736 Check_Potentially_Blocking_Operation (N);
737 end Analyze_Abort_Statement;
739 --------------------------------
740 -- Analyze_Accept_Alternative --
741 --------------------------------
743 procedure Analyze_Accept_Alternative (N : Node_Id) is
744 begin
745 Tasking_Used := True;
747 if Present (Pragmas_Before (N)) then
748 Analyze_List (Pragmas_Before (N));
749 end if;
751 if Present (Condition (N)) then
752 Analyze_And_Resolve (Condition (N), Any_Boolean);
753 end if;
755 Analyze (Accept_Statement (N));
757 if Is_Non_Empty_List (Statements (N)) then
758 Analyze_Statements (Statements (N));
759 end if;
760 end Analyze_Accept_Alternative;
762 ------------------------------
763 -- Analyze_Accept_Statement --
764 ------------------------------
766 procedure Analyze_Accept_Statement (N : Node_Id) is
767 Nam : constant Entity_Id := Entry_Direct_Name (N);
768 Formals : constant List_Id := Parameter_Specifications (N);
769 Index : constant Node_Id := Entry_Index (N);
770 Stats : constant Node_Id := Handled_Statement_Sequence (N);
771 Accept_Id : Entity_Id;
772 Entry_Nam : Entity_Id;
773 E : Entity_Id;
774 Kind : Entity_Kind;
775 Task_Nam : Entity_Id := Empty; -- initialize to prevent warning
777 begin
778 Tasking_Used := True;
779 Check_SPARK_05_Restriction ("accept statement is not allowed", N);
781 -- Entry name is initialized to Any_Id. It should get reset to the
782 -- matching entry entity. An error is signalled if it is not reset.
784 Entry_Nam := Any_Id;
786 for J in reverse 0 .. Scope_Stack.Last loop
787 Task_Nam := Scope_Stack.Table (J).Entity;
788 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
789 Kind := Ekind (Task_Nam);
791 if Kind /= E_Block and then Kind /= E_Loop
792 and then not Is_Entry (Task_Nam)
793 then
794 Error_Msg_N ("enclosing body of accept must be a task", N);
795 return;
796 end if;
797 end loop;
799 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
800 Error_Msg_N ("invalid context for accept statement", N);
801 return;
802 end if;
804 -- In order to process the parameters, we create a defining identifier
805 -- that can be used as the name of the scope. The name of the accept
806 -- statement itself is not a defining identifier, and we cannot use
807 -- its name directly because the task may have any number of accept
808 -- statements for the same entry.
810 if Present (Index) then
811 Accept_Id := New_Internal_Entity
812 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
813 else
814 Accept_Id := New_Internal_Entity
815 (E_Entry, Current_Scope, Sloc (N), 'E');
816 end if;
818 Set_Etype (Accept_Id, Standard_Void_Type);
819 Set_Accept_Address (Accept_Id, New_Elmt_List);
821 if Present (Formals) then
822 Push_Scope (Accept_Id);
823 Process_Formals (Formals, N);
824 Create_Extra_Formals (Accept_Id);
825 End_Scope;
826 end if;
828 -- We set the default expressions processed flag because we don't need
829 -- default expression functions. This is really more like body entity
830 -- than a spec entity anyway.
832 Set_Default_Expressions_Processed (Accept_Id);
834 E := First_Entity (Etype (Task_Nam));
835 while Present (E) loop
836 if Chars (E) = Chars (Nam)
837 and then (Ekind (E) = Ekind (Accept_Id))
838 and then Type_Conformant (Accept_Id, E)
839 then
840 Entry_Nam := E;
841 exit;
842 end if;
844 Next_Entity (E);
845 end loop;
847 if Entry_Nam = Any_Id then
848 Error_Msg_N ("no entry declaration matches accept statement", N);
849 return;
850 else
851 Set_Entity (Nam, Entry_Nam);
852 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
853 Style.Check_Identifier (Nam, Entry_Nam);
854 end if;
856 -- Verify that the entry is not hidden by a procedure declared in the
857 -- current block (pathological but possible).
859 if Current_Scope /= Task_Nam then
860 declare
861 E1 : Entity_Id;
863 begin
864 E1 := First_Entity (Current_Scope);
865 while Present (E1) loop
866 if Ekind (E1) = E_Procedure
867 and then Chars (E1) = Chars (Entry_Nam)
868 and then Type_Conformant (E1, Entry_Nam)
869 then
870 Error_Msg_N ("entry name is not visible", N);
871 end if;
873 Next_Entity (E1);
874 end loop;
875 end;
876 end if;
878 Set_Convention (Accept_Id, Convention (Entry_Nam));
879 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
881 for J in reverse 0 .. Scope_Stack.Last loop
882 exit when Task_Nam = Scope_Stack.Table (J).Entity;
884 if Entry_Nam = Scope_Stack.Table (J).Entity then
885 Error_Msg_N ("duplicate accept statement for same entry", N);
886 end if;
887 end loop;
889 declare
890 P : Node_Id := N;
891 begin
892 loop
893 P := Parent (P);
894 case Nkind (P) is
895 when N_Compilation_Unit
896 | N_Task_Body
898 exit;
900 when N_Asynchronous_Select =>
901 Error_Msg_N
902 ("accept statements are not allowed within an "
903 & "asynchronous select inner to the enclosing task body",
905 exit;
907 when others =>
908 null;
909 end case;
910 end loop;
911 end;
913 if Ekind (E) = E_Entry_Family then
914 if No (Index) then
915 Error_Msg_N ("missing entry index in accept for entry family", N);
916 else
917 Analyze_And_Resolve (Index, Entry_Index_Type (E));
918 Apply_Range_Check (Index, Entry_Index_Type (E));
919 end if;
921 elsif Present (Index) then
922 Error_Msg_N ("invalid entry index in accept for simple entry", N);
923 end if;
925 -- If label declarations present, analyze them. They are declared in the
926 -- enclosing task, but their enclosing scope is the entry itself, so
927 -- that goto's to the label are recognized as local to the accept.
929 if Present (Declarations (N)) then
930 declare
931 Decl : Node_Id;
932 Id : Entity_Id;
934 begin
935 Decl := First (Declarations (N));
936 while Present (Decl) loop
937 Analyze (Decl);
939 pragma Assert
940 (Nkind (Decl) = N_Implicit_Label_Declaration);
942 Id := Defining_Identifier (Decl);
943 Set_Enclosing_Scope (Id, Entry_Nam);
944 Next (Decl);
945 end loop;
946 end;
947 end if;
949 -- If statements are present, they must be analyzed in the context of
950 -- the entry, so that references to formals are correctly resolved. We
951 -- also have to add the declarations that are required by the expansion
952 -- of the accept statement in this case if expansion active.
954 -- In the case of a select alternative of a selective accept, the
955 -- expander references the address declaration even if there is no
956 -- statement list.
958 -- We also need to create the renaming declarations for the local
959 -- variables that will replace references to the formals within the
960 -- accept statement.
962 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
964 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
965 -- fields on all entry formals (this loop ignores all other entities).
966 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
967 -- well, so that we can post accurate warnings on each accept statement
968 -- for the same entry.
970 E := First_Entity (Entry_Nam);
971 while Present (E) loop
972 if Is_Formal (E) then
973 Set_Never_Set_In_Source (E, True);
974 Set_Is_True_Constant (E, False);
975 Set_Current_Value (E, Empty);
976 Set_Referenced (E, False);
977 Set_Referenced_As_LHS (E, False);
978 Set_Referenced_As_Out_Parameter (E, False);
979 Set_Has_Pragma_Unreferenced (E, False);
980 end if;
982 Next_Entity (E);
983 end loop;
985 -- Analyze statements if present
987 if Present (Stats) then
988 Push_Scope (Entry_Nam);
989 Install_Declarations (Entry_Nam);
991 Set_Actual_Subtypes (N, Current_Scope);
993 Analyze (Stats);
994 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
995 End_Scope;
996 end if;
998 -- Some warning checks
1000 Check_Potentially_Blocking_Operation (N);
1001 Check_References (Entry_Nam, N);
1002 Set_Entry_Accepted (Entry_Nam);
1003 end Analyze_Accept_Statement;
1005 ---------------------------------
1006 -- Analyze_Asynchronous_Select --
1007 ---------------------------------
1009 procedure Analyze_Asynchronous_Select (N : Node_Id) is
1010 Is_Disp_Select : Boolean := False;
1011 Trigger : Node_Id;
1013 begin
1014 Tasking_Used := True;
1015 Check_SPARK_05_Restriction ("select statement is not allowed", N);
1016 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
1017 Check_Restriction (No_Select_Statements, N);
1019 if Ada_Version >= Ada_2005 then
1020 Trigger := Triggering_Statement (Triggering_Alternative (N));
1022 Analyze (Trigger);
1024 -- Ada 2005 (AI-345): Check for a potential dispatching select
1026 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1027 end if;
1029 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
1030 -- select will have to duplicate the triggering statements. Postpone
1031 -- the analysis of the statements till expansion. Analyze only if the
1032 -- expander is disabled in order to catch any semantic errors.
1034 if Is_Disp_Select then
1035 if not Expander_Active then
1036 Analyze_Statements (Statements (Abortable_Part (N)));
1037 Analyze (Triggering_Alternative (N));
1038 end if;
1040 -- Analyze the statements. We analyze statements in the abortable part,
1041 -- because this is the section that is executed first, and that way our
1042 -- remembering of saved values and checks is accurate.
1044 else
1045 Analyze_Statements (Statements (Abortable_Part (N)));
1046 Analyze (Triggering_Alternative (N));
1047 end if;
1048 end Analyze_Asynchronous_Select;
1050 ------------------------------------
1051 -- Analyze_Conditional_Entry_Call --
1052 ------------------------------------
1054 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
1055 Trigger : constant Node_Id :=
1056 Entry_Call_Statement (Entry_Call_Alternative (N));
1057 Is_Disp_Select : Boolean := False;
1059 begin
1060 Tasking_Used := True;
1061 Check_SPARK_05_Restriction ("select statement is not allowed", N);
1062 Check_Restriction (No_Select_Statements, N);
1064 -- Ada 2005 (AI-345): The trigger may be a dispatching call
1066 if Ada_Version >= Ada_2005 then
1067 Analyze (Trigger);
1068 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1069 end if;
1071 if List_Length (Else_Statements (N)) = 1
1072 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
1073 then
1074 Error_Msg_N
1075 ("suspicious form of conditional entry call??!", N);
1076 Error_Msg_N
1077 ("\`SELECT OR` may be intended rather than `SELECT ELSE`??!", N);
1078 end if;
1080 -- Postpone the analysis of the statements till expansion. Analyze only
1081 -- if the expander is disabled in order to catch any semantic errors.
1083 if Is_Disp_Select then
1084 if not Expander_Active then
1085 Analyze (Entry_Call_Alternative (N));
1086 Analyze_Statements (Else_Statements (N));
1087 end if;
1089 -- Regular select analysis
1091 else
1092 Analyze (Entry_Call_Alternative (N));
1093 Analyze_Statements (Else_Statements (N));
1094 end if;
1095 end Analyze_Conditional_Entry_Call;
1097 --------------------------------
1098 -- Analyze_Delay_Alternative --
1099 --------------------------------
1101 procedure Analyze_Delay_Alternative (N : Node_Id) is
1102 Expr : Node_Id;
1103 Typ : Entity_Id;
1105 begin
1106 Tasking_Used := True;
1107 Check_Restriction (No_Delay, N);
1109 if Present (Pragmas_Before (N)) then
1110 Analyze_List (Pragmas_Before (N));
1111 end if;
1113 if Nkind_In (Parent (N), N_Selective_Accept, N_Timed_Entry_Call) then
1114 Expr := Expression (Delay_Statement (N));
1116 -- Defer full analysis until the statement is expanded, to insure
1117 -- that generated code does not move past the guard. The delay
1118 -- expression is only evaluated if the guard is open.
1120 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
1121 Preanalyze_And_Resolve (Expr, Standard_Duration);
1122 else
1123 Preanalyze_And_Resolve (Expr);
1124 end if;
1126 Typ := First_Subtype (Etype (Expr));
1128 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
1129 and then not Is_RTE (Typ, RO_CA_Time)
1130 and then not Is_RTE (Typ, RO_RT_Time)
1131 then
1132 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
1133 end if;
1135 Check_Restriction (No_Fixed_Point, Expr);
1137 else
1138 Analyze (Delay_Statement (N));
1139 end if;
1141 if Present (Condition (N)) then
1142 Analyze_And_Resolve (Condition (N), Any_Boolean);
1143 end if;
1145 if Is_Non_Empty_List (Statements (N)) then
1146 Analyze_Statements (Statements (N));
1147 end if;
1148 end Analyze_Delay_Alternative;
1150 ----------------------------
1151 -- Analyze_Delay_Relative --
1152 ----------------------------
1154 procedure Analyze_Delay_Relative (N : Node_Id) is
1155 E : constant Node_Id := Expression (N);
1157 begin
1158 Tasking_Used := True;
1159 Check_SPARK_05_Restriction ("delay statement is not allowed", N);
1160 Check_Restriction (No_Relative_Delay, N);
1161 Check_Restriction (No_Delay, N);
1162 Check_Potentially_Blocking_Operation (N);
1163 Analyze_And_Resolve (E, Standard_Duration);
1164 Check_Restriction (No_Fixed_Point, E);
1166 -- In SPARK mode the relative delay statement introduces an implicit
1167 -- dependency on the Ada.Real_Time.Clock_Time abstract state, so we must
1168 -- force the loading of the Ada.Real_Time package.
1170 if GNATprove_Mode then
1171 SPARK_Implicit_Load (RO_RT_Time);
1172 end if;
1173 end Analyze_Delay_Relative;
1175 -------------------------
1176 -- Analyze_Delay_Until --
1177 -------------------------
1179 procedure Analyze_Delay_Until (N : Node_Id) is
1180 E : constant Node_Id := Expression (N);
1181 Typ : Entity_Id;
1183 begin
1184 Tasking_Used := True;
1185 Check_SPARK_05_Restriction ("delay statement is not allowed", N);
1186 Check_Restriction (No_Delay, N);
1187 Check_Potentially_Blocking_Operation (N);
1188 Analyze_And_Resolve (E);
1189 Typ := First_Subtype (Etype (E));
1191 if not Is_RTE (Typ, RO_CA_Time) and then
1192 not Is_RTE (Typ, RO_RT_Time)
1193 then
1194 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
1195 end if;
1196 end Analyze_Delay_Until;
1198 ------------------------
1199 -- Analyze_Entry_Body --
1200 ------------------------
1202 procedure Analyze_Entry_Body (N : Node_Id) is
1203 Id : constant Entity_Id := Defining_Identifier (N);
1204 Decls : constant List_Id := Declarations (N);
1205 Stats : constant Node_Id := Handled_Statement_Sequence (N);
1206 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1207 P_Type : constant Entity_Id := Current_Scope;
1208 E : Entity_Id;
1209 Entry_Name : Entity_Id;
1211 begin
1212 -- An entry body "freezes" the contract of the nearest enclosing package
1213 -- body and all other contracts encountered in the same declarative part
1214 -- up to and excluding the entry body. This ensures that any annotations
1215 -- referenced by the contract of an entry or subprogram body declared
1216 -- within the current protected body are available.
1218 Analyze_Previous_Contracts (N);
1220 Tasking_Used := True;
1222 -- Entry_Name is initialized to Any_Id. It should get reset to the
1223 -- matching entry entity. An error is signalled if it is not reset.
1225 Entry_Name := Any_Id;
1227 Analyze (Formals);
1229 if Present (Entry_Index_Specification (Formals)) then
1230 Set_Ekind (Id, E_Entry_Family);
1231 else
1232 Set_Ekind (Id, E_Entry);
1233 end if;
1235 Set_Etype (Id, Standard_Void_Type);
1236 Set_Scope (Id, Current_Scope);
1237 Set_Accept_Address (Id, New_Elmt_List);
1239 -- Set the SPARK_Mode from the current context (may be overwritten later
1240 -- with an explicit pragma).
1242 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1243 Set_SPARK_Pragma_Inherited (Id);
1245 -- Analyze any aspect specifications that appear on the entry body
1247 if Has_Aspects (N) then
1248 Analyze_Aspect_Specifications_On_Body_Or_Stub (N);
1249 end if;
1251 E := First_Entity (P_Type);
1252 while Present (E) loop
1253 if Chars (E) = Chars (Id)
1254 and then (Ekind (E) = Ekind (Id))
1255 and then Type_Conformant (Id, E)
1256 then
1257 Entry_Name := E;
1258 Set_Convention (Id, Convention (E));
1259 Set_Corresponding_Body (Parent (E), Id);
1260 Check_Fully_Conformant (Id, E, N);
1262 if Ekind (Id) = E_Entry_Family then
1263 if not Fully_Conformant_Discrete_Subtypes (
1264 Discrete_Subtype_Definition (Parent (E)),
1265 Discrete_Subtype_Definition
1266 (Entry_Index_Specification (Formals)))
1267 then
1268 Error_Msg_N
1269 ("index not fully conformant with previous declaration",
1270 Discrete_Subtype_Definition
1271 (Entry_Index_Specification (Formals)));
1273 else
1274 -- The elaboration of the entry body does not recompute the
1275 -- bounds of the index, which may have side effects. Inherit
1276 -- the bounds from the entry declaration. This is critical
1277 -- if the entry has a per-object constraint. If a bound is
1278 -- given by a discriminant, it must be reanalyzed in order
1279 -- to capture the discriminal of the current entry, rather
1280 -- than that of the protected type.
1282 declare
1283 Index_Spec : constant Node_Id :=
1284 Entry_Index_Specification (Formals);
1286 Def : constant Node_Id :=
1287 New_Copy_Tree
1288 (Discrete_Subtype_Definition (Parent (E)));
1290 begin
1291 if Nkind
1292 (Original_Node
1293 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
1294 then
1295 Set_Etype (Def, Empty);
1296 Set_Analyzed (Def, False);
1298 -- Keep the original subtree to ensure a properly
1299 -- formed tree (e.g. for ASIS use).
1301 Rewrite
1302 (Discrete_Subtype_Definition (Index_Spec), Def);
1304 Set_Analyzed (Low_Bound (Def), False);
1305 Set_Analyzed (High_Bound (Def), False);
1307 if Denotes_Discriminant (Low_Bound (Def)) then
1308 Set_Entity (Low_Bound (Def), Empty);
1309 end if;
1311 if Denotes_Discriminant (High_Bound (Def)) then
1312 Set_Entity (High_Bound (Def), Empty);
1313 end if;
1315 Analyze (Def);
1316 Make_Index (Def, Index_Spec);
1317 Set_Etype
1318 (Defining_Identifier (Index_Spec), Etype (Def));
1319 end if;
1320 end;
1321 end if;
1322 end if;
1324 exit;
1325 end if;
1327 Next_Entity (E);
1328 end loop;
1330 if Entry_Name = Any_Id then
1331 Error_Msg_N ("no entry declaration matches entry body", N);
1332 return;
1334 elsif Has_Completion (Entry_Name) then
1335 Error_Msg_N ("duplicate entry body", N);
1336 return;
1338 else
1339 Set_Has_Completion (Entry_Name);
1340 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
1341 Style.Check_Identifier (Id, Entry_Name);
1342 end if;
1344 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
1345 Push_Scope (Entry_Name);
1347 Install_Declarations (Entry_Name);
1348 Set_Actual_Subtypes (N, Current_Scope);
1350 -- The entity for the protected subprogram corresponding to the entry
1351 -- has been created. We retain the name of this entity in the entry
1352 -- body, for use when the corresponding subprogram body is created.
1353 -- Note that entry bodies have no Corresponding_Spec, and there is no
1354 -- easy link back in the tree between the entry body and the entity for
1355 -- the entry itself, which is why we must propagate some attributes
1356 -- explicitly from spec to body.
1358 Set_Protected_Body_Subprogram
1359 (Id, Protected_Body_Subprogram (Entry_Name));
1361 Set_Entry_Parameters_Type
1362 (Id, Entry_Parameters_Type (Entry_Name));
1364 -- Add a declaration for the Protection object, renaming declarations
1365 -- for the discriminals and privals and finally a declaration for the
1366 -- entry family index (if applicable).
1368 if Expander_Active
1369 and then Is_Protected_Type (P_Type)
1370 then
1371 Install_Private_Data_Declarations
1372 (Sloc (N), Entry_Name, P_Type, N, Decls);
1373 end if;
1375 if Present (Decls) then
1376 Analyze_Declarations (Decls);
1377 Inspect_Deferred_Constant_Completion (Decls);
1378 end if;
1380 -- Process the contract of the subprogram body after all declarations
1381 -- have been analyzed. This ensures that any contract-related pragmas
1382 -- are available through the N_Contract node of the body.
1384 Analyze_Entry_Or_Subprogram_Body_Contract (Id);
1386 if Present (Stats) then
1387 Analyze (Stats);
1388 end if;
1390 -- Check for unreferenced variables etc. Before the Check_References
1391 -- call, we transfer Never_Set_In_Source and Referenced flags from
1392 -- parameters in the spec to the corresponding entities in the body,
1393 -- since we want the warnings on the body entities. Note that we do not
1394 -- have to transfer Referenced_As_LHS, since that flag can only be set
1395 -- for simple variables, but we include Has_Pragma_Unreferenced,
1396 -- which may have been specified for a formal in the body.
1398 -- At the same time, we set the flags on the spec entities to suppress
1399 -- any warnings on the spec formals, since we also scan the spec.
1400 -- Finally, we propagate the Entry_Component attribute to the body
1401 -- formals, for use in the renaming declarations created later for the
1402 -- formals (see exp_ch9.Add_Formal_Renamings).
1404 declare
1405 E1 : Entity_Id;
1406 E2 : Entity_Id;
1408 begin
1409 E1 := First_Entity (Entry_Name);
1410 while Present (E1) loop
1411 E2 := First_Entity (Id);
1412 while Present (E2) loop
1413 exit when Chars (E1) = Chars (E2);
1414 Next_Entity (E2);
1415 end loop;
1417 -- If no matching body entity, then we already had a detected
1418 -- error of some kind, so just don't worry about these warnings.
1420 if No (E2) then
1421 goto Continue;
1422 end if;
1424 if Ekind (E1) = E_Out_Parameter then
1425 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1426 Set_Never_Set_In_Source (E1, False);
1427 end if;
1429 Set_Referenced (E2, Referenced (E1));
1430 Set_Referenced (E1);
1431 Set_Has_Pragma_Unreferenced (E2, Has_Pragma_Unreferenced (E1));
1432 Set_Entry_Component (E2, Entry_Component (E1));
1434 <<Continue>>
1435 Next_Entity (E1);
1436 end loop;
1438 Check_References (Id);
1439 end;
1441 -- We still need to check references for the spec, since objects
1442 -- declared in the body are chained (in the First_Entity sense) to
1443 -- the spec rather than the body in the case of entries.
1445 Check_References (Entry_Name);
1447 -- Process the end label, and terminate the scope
1449 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
1450 End_Scope;
1452 -- If this is an entry family, remove the loop created to provide
1453 -- a scope for the entry index.
1455 if Ekind (Id) = E_Entry_Family
1456 and then Present (Entry_Index_Specification (Formals))
1457 then
1458 End_Scope;
1459 end if;
1460 end Analyze_Entry_Body;
1462 ------------------------------------
1463 -- Analyze_Entry_Body_Formal_Part --
1464 ------------------------------------
1466 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
1467 Id : constant Entity_Id := Defining_Identifier (Parent (N));
1468 Index : constant Node_Id := Entry_Index_Specification (N);
1469 Formals : constant List_Id := Parameter_Specifications (N);
1471 begin
1472 Tasking_Used := True;
1474 if Present (Index) then
1475 Analyze (Index);
1477 -- The entry index functions like a loop variable, thus it is known
1478 -- to have a valid value.
1480 Set_Is_Known_Valid (Defining_Identifier (Index));
1481 end if;
1483 if Present (Formals) then
1484 Set_Scope (Id, Current_Scope);
1485 Push_Scope (Id);
1486 Process_Formals (Formals, Parent (N));
1487 End_Scope;
1488 end if;
1489 end Analyze_Entry_Body_Formal_Part;
1491 ------------------------------------
1492 -- Analyze_Entry_Call_Alternative --
1493 ------------------------------------
1495 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
1496 Call : constant Node_Id := Entry_Call_Statement (N);
1498 begin
1499 Tasking_Used := True;
1500 Check_SPARK_05_Restriction ("entry call is not allowed", N);
1502 if Present (Pragmas_Before (N)) then
1503 Analyze_List (Pragmas_Before (N));
1504 end if;
1506 if Nkind (Call) = N_Attribute_Reference then
1508 -- Possibly a stream attribute, but definitely illegal. Other
1509 -- illegalities, such as procedure calls, are diagnosed after
1510 -- resolution.
1512 Error_Msg_N ("entry call alternative requires an entry call", Call);
1513 return;
1514 end if;
1516 Analyze (Call);
1518 -- An indirect call in this context is illegal. A procedure call that
1519 -- does not involve a renaming of an entry is illegal as well, but this
1520 -- and other semantic errors are caught during resolution.
1522 if Nkind (Call) = N_Explicit_Dereference then
1523 Error_Msg_N
1524 ("entry call or dispatching primitive of interface required ", N);
1525 end if;
1527 if Is_Non_Empty_List (Statements (N)) then
1528 Analyze_Statements (Statements (N));
1529 end if;
1530 end Analyze_Entry_Call_Alternative;
1532 -------------------------------
1533 -- Analyze_Entry_Declaration --
1534 -------------------------------
1536 procedure Analyze_Entry_Declaration (N : Node_Id) is
1537 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
1538 Def_Id : constant Entity_Id := Defining_Identifier (N);
1539 Formals : constant List_Id := Parameter_Specifications (N);
1541 begin
1542 Generate_Definition (Def_Id);
1544 Tasking_Used := True;
1546 -- Case of no discrete subtype definition
1548 if No (D_Sdef) then
1549 Set_Ekind (Def_Id, E_Entry);
1551 -- Processing for discrete subtype definition present
1553 else
1554 Enter_Name (Def_Id);
1555 Set_Ekind (Def_Id, E_Entry_Family);
1556 Analyze (D_Sdef);
1557 Make_Index (D_Sdef, N, Def_Id);
1559 -- Check subtype with predicate in entry family
1561 Bad_Predicated_Subtype_Use
1562 ("subtype& has predicate, not allowed in entry family",
1563 D_Sdef, Etype (D_Sdef));
1565 -- Check entry family static bounds outside allowed limits
1567 -- Note: originally this check was not performed here, but in that
1568 -- case the check happens deep in the expander, and the message is
1569 -- posted at the wrong location, and omitted in -gnatc mode.
1570 -- If the type of the entry index is a generic formal, no check
1571 -- is possible. In an instance, the check is not static and a run-
1572 -- time exception will be raised if the bounds are unreasonable.
1574 declare
1575 PEI : constant Entity_Id := RTE (RE_Protected_Entry_Index);
1576 LB : constant Uint := Expr_Value (Type_Low_Bound (PEI));
1577 UB : constant Uint := Expr_Value (Type_High_Bound (PEI));
1579 LBR : Node_Id;
1580 UBR : Node_Id;
1582 begin
1584 -- No bounds checking if the type is generic or if previous error.
1585 -- In an instance the check is dynamic.
1587 if Is_Generic_Type (Etype (D_Sdef))
1588 or else In_Instance
1589 or else Error_Posted (D_Sdef)
1590 then
1591 goto Skip_LB;
1593 elsif Nkind (D_Sdef) = N_Range then
1594 LBR := Low_Bound (D_Sdef);
1596 elsif Is_Entity_Name (D_Sdef)
1597 and then Is_Type (Entity (D_Sdef))
1598 then
1599 LBR := Type_Low_Bound (Entity (D_Sdef));
1601 else
1602 goto Skip_LB;
1603 end if;
1605 if Is_OK_Static_Expression (LBR)
1606 and then Expr_Value (LBR) < LB
1607 then
1608 Error_Msg_Uint_1 := LB;
1609 Error_Msg_N ("entry family low bound must be '>'= ^!", D_Sdef);
1610 end if;
1612 <<Skip_LB>>
1613 if Is_Generic_Type (Etype (D_Sdef))
1614 or else In_Instance
1615 or else Error_Posted (D_Sdef)
1616 then
1617 goto Skip_UB;
1619 elsif Nkind (D_Sdef) = N_Range then
1620 UBR := High_Bound (D_Sdef);
1622 elsif Is_Entity_Name (D_Sdef)
1623 and then Is_Type (Entity (D_Sdef))
1624 then
1625 UBR := Type_High_Bound (Entity (D_Sdef));
1627 else
1628 goto Skip_UB;
1629 end if;
1631 if Is_OK_Static_Expression (UBR)
1632 and then Expr_Value (UBR) > UB
1633 then
1634 Error_Msg_Uint_1 := UB;
1635 Error_Msg_N ("entry family high bound must be '<'= ^!", D_Sdef);
1636 end if;
1638 <<Skip_UB>>
1639 null;
1640 end;
1641 end if;
1643 -- Decorate Def_Id
1645 Set_Etype (Def_Id, Standard_Void_Type);
1646 Set_Convention (Def_Id, Convention_Entry);
1647 Set_Accept_Address (Def_Id, New_Elmt_List);
1649 -- Set the SPARK_Mode from the current context (may be overwritten later
1650 -- with an explicit pragma). Task entries are excluded because they are
1651 -- not completed by entry bodies.
1653 if Ekind (Current_Scope) = E_Protected_Type then
1654 Set_SPARK_Pragma (Def_Id, SPARK_Mode_Pragma);
1655 Set_SPARK_Pragma_Inherited (Def_Id);
1656 end if;
1658 -- Process formals
1660 if Present (Formals) then
1661 Set_Scope (Def_Id, Current_Scope);
1662 Push_Scope (Def_Id);
1663 Process_Formals (Formals, N);
1664 Create_Extra_Formals (Def_Id);
1665 End_Scope;
1666 end if;
1668 if Ekind (Def_Id) = E_Entry then
1669 New_Overloaded_Entity (Def_Id);
1670 end if;
1672 Generate_Reference_To_Formals (Def_Id);
1674 if Has_Aspects (N) then
1675 Analyze_Aspect_Specifications (N, Def_Id);
1676 end if;
1677 end Analyze_Entry_Declaration;
1679 ---------------------------------------
1680 -- Analyze_Entry_Index_Specification --
1681 ---------------------------------------
1683 -- The Defining_Identifier of the entry index specification is local to the
1684 -- entry body, but it must be available in the entry barrier which is
1685 -- evaluated outside of the entry body. The index is eventually renamed as
1686 -- a run-time object, so its visibility is strictly a front-end concern. In
1687 -- order to make it available to the barrier, we create an additional
1688 -- scope, as for a loop, whose only declaration is the index name. This
1689 -- loop is not attached to the tree and does not appear as an entity local
1690 -- to the protected type, so its existence need only be known to routines
1691 -- that process entry families.
1693 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
1694 Iden : constant Node_Id := Defining_Identifier (N);
1695 Def : constant Node_Id := Discrete_Subtype_Definition (N);
1696 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L');
1698 begin
1699 Tasking_Used := True;
1700 Analyze (Def);
1702 -- There is no elaboration of the entry index specification. Therefore,
1703 -- if the index is a range, it is not resolved and expanded, but the
1704 -- bounds are inherited from the entry declaration, and reanalyzed.
1705 -- See Analyze_Entry_Body.
1707 if Nkind (Def) /= N_Range then
1708 Make_Index (Def, N);
1709 end if;
1711 Set_Ekind (Loop_Id, E_Loop);
1712 Set_Scope (Loop_Id, Current_Scope);
1713 Push_Scope (Loop_Id);
1714 Enter_Name (Iden);
1715 Set_Ekind (Iden, E_Entry_Index_Parameter);
1716 Set_Etype (Iden, Etype (Def));
1717 end Analyze_Entry_Index_Specification;
1719 ----------------------------
1720 -- Analyze_Protected_Body --
1721 ----------------------------
1723 procedure Analyze_Protected_Body (N : Node_Id) is
1724 Body_Id : constant Entity_Id := Defining_Identifier (N);
1725 Last_E : Entity_Id;
1727 Spec_Id : Entity_Id;
1728 -- This is initially the entity of the protected object or protected
1729 -- type involved, but is replaced by the protected type always in the
1730 -- case of a single protected declaration, since this is the proper
1731 -- scope to be used.
1733 Ref_Id : Entity_Id;
1734 -- This is the entity of the protected object or protected type
1735 -- involved, and is the entity used for cross-reference purposes (it
1736 -- differs from Spec_Id in the case of a single protected object, since
1737 -- Spec_Id is set to the protected type in this case).
1739 function Lock_Free_Disabled return Boolean;
1740 -- This routine returns False if the protected object has a Lock_Free
1741 -- aspect specification or a Lock_Free pragma that turns off the
1742 -- lock-free implementation (e.g. whose expression is False).
1744 ------------------------
1745 -- Lock_Free_Disabled --
1746 ------------------------
1748 function Lock_Free_Disabled return Boolean is
1749 Ritem : constant Node_Id :=
1750 Get_Rep_Item
1751 (Spec_Id, Name_Lock_Free, Check_Parents => False);
1753 begin
1754 if Present (Ritem) then
1756 -- Pragma with one argument
1758 if Nkind (Ritem) = N_Pragma
1759 and then Present (Pragma_Argument_Associations (Ritem))
1760 then
1761 return
1762 Is_False
1763 (Static_Boolean
1764 (Expression
1765 (First (Pragma_Argument_Associations (Ritem)))));
1767 -- Aspect Specification with expression present
1769 elsif Nkind (Ritem) = N_Aspect_Specification
1770 and then Present (Expression (Ritem))
1771 then
1772 return Is_False (Static_Boolean (Expression (Ritem)));
1774 -- Otherwise, return False
1776 else
1777 return False;
1778 end if;
1779 end if;
1781 return False;
1782 end Lock_Free_Disabled;
1784 -- Start of processing for Analyze_Protected_Body
1786 begin
1787 -- A protected body "freezes" the contract of the nearest enclosing
1788 -- package body and all other contracts encountered in the same
1789 -- declarative part up to and excluding the protected body. This ensures
1790 -- that any annotations referenced by the contract of an entry or
1791 -- subprogram body declared within the current protected body are
1792 -- available.
1794 Analyze_Previous_Contracts (N);
1796 Tasking_Used := True;
1797 Set_Ekind (Body_Id, E_Protected_Body);
1798 Set_Etype (Body_Id, Standard_Void_Type);
1799 Spec_Id := Find_Concurrent_Spec (Body_Id);
1801 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Protected_Type then
1802 null;
1804 elsif Present (Spec_Id)
1805 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1806 and then not Comes_From_Source (Etype (Spec_Id))
1807 then
1808 null;
1810 else
1811 Error_Msg_N ("missing specification for protected body", Body_Id);
1812 return;
1813 end if;
1815 Ref_Id := Spec_Id;
1816 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1817 Style.Check_Identifier (Body_Id, Spec_Id);
1819 -- The declarations are always attached to the type
1821 if Ekind (Spec_Id) /= E_Protected_Type then
1822 Spec_Id := Etype (Spec_Id);
1823 end if;
1825 if Has_Aspects (N) then
1826 Analyze_Aspect_Specifications (N, Body_Id);
1827 end if;
1829 Push_Scope (Spec_Id);
1830 Set_Corresponding_Spec (N, Spec_Id);
1831 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1832 Set_Has_Completion (Spec_Id);
1833 Install_Declarations (Spec_Id);
1834 Expand_Protected_Body_Declarations (N, Spec_Id);
1835 Last_E := Last_Entity (Spec_Id);
1837 Analyze_Declarations (Declarations (N));
1839 -- For visibility purposes, all entities in the body are private. Set
1840 -- First_Private_Entity accordingly, if there was no private part in the
1841 -- protected declaration.
1843 if No (First_Private_Entity (Spec_Id)) then
1844 if Present (Last_E) then
1845 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1846 else
1847 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1848 end if;
1849 end if;
1851 Check_Completion (Body_Id);
1852 Check_References (Spec_Id);
1853 Process_End_Label (N, 't', Ref_Id);
1854 End_Scope;
1856 -- When a Lock_Free aspect specification/pragma forces the lock-free
1857 -- implementation, verify the protected body meets all the restrictions,
1858 -- otherwise Allows_Lock_Free_Implementation issues an error message.
1860 if Uses_Lock_Free (Spec_Id) then
1861 if not Allows_Lock_Free_Implementation (N, True) then
1862 return;
1863 end if;
1865 -- In other cases, if there is no aspect specification/pragma that
1866 -- disables the lock-free implementation, check both the protected
1867 -- declaration and body satisfy the lock-free restrictions.
1869 elsif not Lock_Free_Disabled
1870 and then Allows_Lock_Free_Implementation (Parent (Spec_Id))
1871 and then Allows_Lock_Free_Implementation (N)
1872 then
1873 Set_Uses_Lock_Free (Spec_Id);
1874 end if;
1875 end Analyze_Protected_Body;
1877 ----------------------------------
1878 -- Analyze_Protected_Definition --
1879 ----------------------------------
1881 procedure Analyze_Protected_Definition (N : Node_Id) is
1882 E : Entity_Id;
1883 L : Entity_Id;
1885 procedure Undelay_Itypes (T : Entity_Id);
1886 -- Itypes created for the private components of a protected type
1887 -- do not receive freeze nodes, because there is no scope in which
1888 -- they can be elaborated, and they can depend on discriminants of
1889 -- the enclosed protected type. Given that the components can be
1890 -- composite types with inner components, we traverse recursively
1891 -- the private components of the protected type, and indicate that
1892 -- all itypes within are frozen. This ensures that no freeze nodes
1893 -- will be generated for them. In the case of itypes that are access
1894 -- types we need to complete their representation by calling layout,
1895 -- which would otherwise be invoked when freezing a type.
1897 -- On the other hand, components of the corresponding record are
1898 -- frozen (or receive itype references) as for other records.
1900 --------------------
1901 -- Undelay_Itypes --
1902 --------------------
1904 procedure Undelay_Itypes (T : Entity_Id) is
1905 Comp : Entity_Id;
1907 begin
1908 if Is_Protected_Type (T) then
1909 Comp := First_Private_Entity (T);
1910 elsif Is_Record_Type (T) then
1911 Comp := First_Entity (T);
1912 else
1913 return;
1914 end if;
1916 while Present (Comp) loop
1917 if Is_Type (Comp)
1918 and then Is_Itype (Comp)
1919 then
1920 Set_Has_Delayed_Freeze (Comp, False);
1921 Set_Is_Frozen (Comp);
1923 if Is_Access_Type (Comp) then
1924 Layout_Type (Comp);
1925 end if;
1927 if Is_Record_Type (Comp)
1928 or else Is_Protected_Type (Comp)
1929 then
1930 Undelay_Itypes (Comp);
1931 end if;
1932 end if;
1934 Next_Entity (Comp);
1935 end loop;
1936 end Undelay_Itypes;
1938 -- Start of processing for Analyze_Protected_Definition
1940 begin
1941 Tasking_Used := True;
1942 Check_SPARK_05_Restriction ("protected definition is not allowed", N);
1943 Analyze_Declarations (Visible_Declarations (N));
1945 if Present (Private_Declarations (N))
1946 and then not Is_Empty_List (Private_Declarations (N))
1947 then
1948 L := Last_Entity (Current_Scope);
1949 Analyze_Declarations (Private_Declarations (N));
1951 if Present (L) then
1952 Set_First_Private_Entity (Current_Scope, Next_Entity (L));
1953 else
1954 Set_First_Private_Entity (Current_Scope,
1955 First_Entity (Current_Scope));
1956 end if;
1957 end if;
1959 E := First_Entity (Current_Scope);
1960 while Present (E) loop
1961 if Ekind_In (E, E_Function, E_Procedure) then
1962 Set_Convention (E, Convention_Protected);
1963 else
1964 Propagate_Concurrent_Flags (Current_Scope, Etype (E));
1965 end if;
1967 Next_Entity (E);
1968 end loop;
1970 Undelay_Itypes (Current_Scope);
1972 Check_Max_Entries (N, Max_Protected_Entries);
1973 Process_End_Label (N, 'e', Current_Scope);
1974 end Analyze_Protected_Definition;
1976 ----------------------------------------
1977 -- Analyze_Protected_Type_Declaration --
1978 ----------------------------------------
1980 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
1981 Def_Id : constant Entity_Id := Defining_Identifier (N);
1982 E : Entity_Id;
1983 T : Entity_Id;
1985 begin
1986 if No_Run_Time_Mode then
1987 Error_Msg_CRT ("protected type", N);
1989 if Has_Aspects (N) then
1990 Analyze_Aspect_Specifications (N, Def_Id);
1991 end if;
1993 return;
1994 end if;
1996 Tasking_Used := True;
1997 Check_Restriction (No_Protected_Types, N);
1999 T := Find_Type_Name (N);
2001 -- In the case of an incomplete type, use the full view, unless it's not
2002 -- present (as can occur for an incomplete view from a limited with).
2004 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
2005 T := Full_View (T);
2006 Set_Completion_Referenced (T);
2007 end if;
2009 Set_Ekind (T, E_Protected_Type);
2010 Set_Is_First_Subtype (T);
2011 Init_Size_Align (T);
2012 Set_Etype (T, T);
2013 Set_Has_Delayed_Freeze (T);
2014 Set_Stored_Constraint (T, No_Elist);
2016 -- Mark this type as a protected type for the sake of restrictions,
2017 -- unless the protected type is declared in a private part of a package
2018 -- of the runtime. With this exception, the Suspension_Object from
2019 -- Ada.Synchronous_Task_Control can be implemented using a protected
2020 -- object without triggering violations of No_Local_Protected_Objects
2021 -- when the user locally declares such an object. This may look like a
2022 -- trick, but the user doesn't have to know how Suspension_Object is
2023 -- implemented.
2025 if In_Private_Part (Current_Scope)
2026 and then Is_Internal_Unit (Current_Sem_Unit)
2027 then
2028 Set_Has_Protected (T, False);
2029 else
2030 Set_Has_Protected (T);
2031 end if;
2033 -- Set the SPARK_Mode from the current context (may be overwritten later
2034 -- with an explicit pragma).
2036 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
2037 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
2038 Set_SPARK_Pragma_Inherited (T);
2039 Set_SPARK_Aux_Pragma_Inherited (T);
2041 Push_Scope (T);
2043 if Ada_Version >= Ada_2005 then
2044 Check_Interfaces (N, T);
2045 end if;
2047 if Present (Discriminant_Specifications (N)) then
2048 if Has_Discriminants (T) then
2050 -- Install discriminants. Also, verify conformance of
2051 -- discriminants of previous and current view. ???
2053 Install_Declarations (T);
2054 else
2055 Process_Discriminants (N);
2056 end if;
2057 end if;
2059 Set_Is_Constrained (T, not Has_Discriminants (T));
2061 -- If aspects are present, analyze them now. They can make references to
2062 -- the discriminants of the type, but not to any components.
2064 if Has_Aspects (N) then
2066 -- The protected type is the full view of a private type. Analyze the
2067 -- aspects with the entity of the private type to ensure that after
2068 -- both views are exchanged, the aspect are actually associated with
2069 -- the full view.
2071 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2072 Analyze_Aspect_Specifications (N, T);
2073 else
2074 Analyze_Aspect_Specifications (N, Def_Id);
2075 end if;
2076 end if;
2078 Analyze (Protected_Definition (N));
2080 -- In the case where the protected type is declared at a nested level
2081 -- and the No_Local_Protected_Objects restriction applies, issue a
2082 -- warning that objects of the type will violate the restriction.
2084 if Restriction_Check_Required (No_Local_Protected_Objects)
2085 and then not Is_Library_Level_Entity (T)
2086 and then Comes_From_Source (T)
2087 then
2088 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
2090 if Error_Msg_Sloc = No_Location then
2091 Error_Msg_N
2092 ("objects of this type will violate " &
2093 "`No_Local_Protected_Objects`??", N);
2094 else
2095 Error_Msg_N
2096 ("objects of this type will violate " &
2097 "`No_Local_Protected_Objects`#??", N);
2098 end if;
2099 end if;
2101 -- Protected types with entries are controlled (because of the
2102 -- Protection component if nothing else), same for any protected type
2103 -- with interrupt handlers. Note that we need to analyze the protected
2104 -- definition to set Has_Entries and such.
2106 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
2107 or else Number_Entries (T) > 1)
2108 and then not Restricted_Profile
2109 and then
2110 (Has_Entries (T)
2111 or else Has_Interrupt_Handler (T)
2112 or else Has_Attach_Handler (T))
2113 then
2114 Set_Has_Controlled_Component (T, True);
2115 end if;
2117 -- The Ekind of components is E_Void during analysis to detect illegal
2118 -- uses. Now it can be set correctly.
2120 E := First_Entity (Current_Scope);
2121 while Present (E) loop
2122 if Ekind (E) = E_Void then
2123 Set_Ekind (E, E_Component);
2124 Init_Component_Location (E);
2125 end if;
2127 Next_Entity (E);
2128 end loop;
2130 End_Scope;
2132 -- When a Lock_Free aspect forces the lock-free implementation, check N
2133 -- meets all the lock-free restrictions. Otherwise, an error message is
2134 -- issued by Allows_Lock_Free_Implementation.
2136 if Uses_Lock_Free (Defining_Identifier (N)) then
2138 -- Complain when there is an explicit aspect/pragma Priority (or
2139 -- Interrupt_Priority) while the lock-free implementation is forced
2140 -- by an aspect/pragma.
2142 declare
2143 Id : constant Entity_Id := Defining_Identifier (Original_Node (N));
2144 -- The warning must be issued on the original identifier in order
2145 -- to deal properly with the case of a single protected object.
2147 Prio_Item : constant Node_Id :=
2148 Get_Rep_Item (Def_Id, Name_Priority, False);
2150 begin
2151 if Present (Prio_Item) then
2153 -- Aspect case
2155 if Nkind (Prio_Item) = N_Aspect_Specification
2156 or else From_Aspect_Specification (Prio_Item)
2157 then
2158 Error_Msg_Name_1 := Chars (Identifier (Prio_Item));
2159 Error_Msg_NE
2160 ("aspect% for & has no effect when Lock_Free given??",
2161 Prio_Item, Id);
2163 -- Pragma case
2165 else
2166 Error_Msg_Name_1 := Pragma_Name (Prio_Item);
2167 Error_Msg_NE
2168 ("pragma% for & has no effect when Lock_Free given??",
2169 Prio_Item, Id);
2170 end if;
2171 end if;
2172 end;
2174 if not Allows_Lock_Free_Implementation (N, Lock_Free_Given => True)
2175 then
2176 return;
2177 end if;
2178 end if;
2180 -- If the Attach_Handler aspect is specified or the Interrupt_Handler
2181 -- aspect is True, then the initial ceiling priority must be in the
2182 -- range of System.Interrupt_Priority. It is therefore recommanded
2183 -- to use the Interrupt_Priority aspect instead of the Priority aspect.
2185 if Has_Interrupt_Handler (T) or else Has_Attach_Handler (T) then
2186 declare
2187 Prio_Item : constant Node_Id :=
2188 Get_Rep_Item (Def_Id, Name_Priority, False);
2190 begin
2191 if Present (Prio_Item) then
2193 -- Aspect case
2195 if (Nkind (Prio_Item) = N_Aspect_Specification
2196 or else From_Aspect_Specification (Prio_Item))
2197 and then Chars (Identifier (Prio_Item)) = Name_Priority
2198 then
2199 Error_Msg_N
2200 ("aspect Interrupt_Priority is preferred in presence of "
2201 & "handlers??", Prio_Item);
2203 -- Pragma case
2205 elsif Nkind (Prio_Item) = N_Pragma
2206 and then Pragma_Name (Prio_Item) = Name_Priority
2207 then
2208 Error_Msg_N
2209 ("pragma Interrupt_Priority is preferred in presence of "
2210 & "handlers??", Prio_Item);
2211 end if;
2212 end if;
2213 end;
2214 end if;
2216 -- Case of a completion of a private declaration
2218 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2220 -- Deal with preelaborable initialization. Note that this processing
2221 -- is done by Process_Full_View, but as can be seen below, in this
2222 -- case the call to Process_Full_View is skipped if any serious
2223 -- errors have occurred, and we don't want to lose this check.
2225 if Known_To_Have_Preelab_Init (Def_Id) then
2226 Set_Must_Have_Preelab_Init (T);
2227 end if;
2229 -- Propagate Default_Initial_Condition-related attributes from the
2230 -- private type to the protected type.
2232 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
2234 -- Propagate invariant-related attributes from the private type to
2235 -- the protected type.
2237 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
2239 -- Create corresponding record now, because some private dependents
2240 -- may be subtypes of the partial view.
2242 -- Skip if errors are present, to prevent cascaded messages
2244 if Serious_Errors_Detected = 0
2246 -- Also skip if expander is not active
2248 and then Expander_Active
2249 then
2250 Expand_N_Protected_Type_Declaration (N);
2251 Process_Full_View (N, T, Def_Id);
2252 end if;
2253 end if;
2255 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
2256 -- is required for the ceiling priority protocol checks triggered by
2257 -- calls originating from protected subprograms and entries.
2259 if GNATprove_Mode then
2260 SPARK_Implicit_Load (RE_Interrupt_Priority);
2261 end if;
2262 end Analyze_Protected_Type_Declaration;
2264 ---------------------
2265 -- Analyze_Requeue --
2266 ---------------------
2268 procedure Analyze_Requeue (N : Node_Id) is
2269 Count : Natural := 0;
2270 Entry_Name : Node_Id := Name (N);
2271 Entry_Id : Entity_Id;
2272 I : Interp_Index;
2273 Is_Disp_Req : Boolean;
2274 It : Interp;
2275 Enclosing : Entity_Id;
2276 Target_Obj : Node_Id := Empty;
2277 Req_Scope : Entity_Id;
2278 Outer_Ent : Entity_Id;
2279 Synch_Type : Entity_Id;
2281 begin
2282 Tasking_Used := True;
2283 Check_SPARK_05_Restriction ("requeue statement is not allowed", N);
2284 Check_Restriction (No_Requeue_Statements, N);
2285 Check_Unreachable_Code (N);
2287 Enclosing := Empty;
2288 for J in reverse 0 .. Scope_Stack.Last loop
2289 Enclosing := Scope_Stack.Table (J).Entity;
2290 exit when Is_Entry (Enclosing);
2292 if not Ekind_In (Enclosing, E_Block, E_Loop) then
2293 Error_Msg_N ("requeue must appear within accept or entry body", N);
2294 return;
2295 end if;
2296 end loop;
2298 Analyze (Entry_Name);
2300 if Etype (Entry_Name) = Any_Type then
2301 return;
2302 end if;
2304 if Nkind (Entry_Name) = N_Selected_Component then
2305 Target_Obj := Prefix (Entry_Name);
2306 Entry_Name := Selector_Name (Entry_Name);
2307 end if;
2309 -- If an explicit target object is given then we have to check the
2310 -- restrictions of 9.5.4(6).
2312 if Present (Target_Obj) then
2314 -- Locate containing concurrent unit and determine enclosing entry
2315 -- body or outermost enclosing accept statement within the unit.
2317 Outer_Ent := Empty;
2318 for S in reverse 0 .. Scope_Stack.Last loop
2319 Req_Scope := Scope_Stack.Table (S).Entity;
2321 exit when Ekind (Req_Scope) in Task_Kind
2322 or else Ekind (Req_Scope) in Protected_Kind;
2324 if Is_Entry (Req_Scope) then
2325 Outer_Ent := Req_Scope;
2326 end if;
2327 end loop;
2329 pragma Assert (Present (Outer_Ent));
2331 -- Check that the accessibility level of the target object is not
2332 -- greater or equal to the outermost enclosing accept statement (or
2333 -- entry body) unless it is a parameter of the innermost enclosing
2334 -- accept statement (or entry body).
2336 if Object_Access_Level (Target_Obj) >= Scope_Depth (Outer_Ent)
2337 and then
2338 (not Is_Entity_Name (Target_Obj)
2339 or else Ekind (Entity (Target_Obj)) not in Formal_Kind
2340 or else Enclosing /= Scope (Entity (Target_Obj)))
2341 then
2342 Error_Msg_N
2343 ("target object has invalid level for requeue", Target_Obj);
2344 end if;
2345 end if;
2347 -- Overloaded case, find right interpretation
2349 if Is_Overloaded (Entry_Name) then
2350 Entry_Id := Empty;
2352 -- Loop over candidate interpretations and filter out any that are
2353 -- not parameterless, are not type conformant, are not entries, or
2354 -- do not come from source.
2356 Get_First_Interp (Entry_Name, I, It);
2357 while Present (It.Nam) loop
2359 -- Note: we test type conformance here, not subtype conformance.
2360 -- Subtype conformance will be tested later on, but it is better
2361 -- for error output in some cases not to do that here.
2363 if (No (First_Formal (It.Nam))
2364 or else (Type_Conformant (Enclosing, It.Nam)))
2365 and then Ekind (It.Nam) = E_Entry
2366 then
2367 -- Ada 2005 (AI-345): Since protected and task types have
2368 -- primitive entry wrappers, we only consider source entries.
2370 if Comes_From_Source (It.Nam) then
2371 Count := Count + 1;
2372 Entry_Id := It.Nam;
2373 else
2374 Remove_Interp (I);
2375 end if;
2376 end if;
2378 Get_Next_Interp (I, It);
2379 end loop;
2381 if Count = 0 then
2382 Error_Msg_N ("no entry matches context", N);
2383 return;
2385 elsif Count > 1 then
2386 Error_Msg_N ("ambiguous entry name in requeue", N);
2387 return;
2389 else
2390 Set_Is_Overloaded (Entry_Name, False);
2391 Set_Entity (Entry_Name, Entry_Id);
2392 end if;
2394 -- Non-overloaded cases
2396 -- For the case of a reference to an element of an entry family, the
2397 -- Entry_Name is an indexed component.
2399 elsif Nkind (Entry_Name) = N_Indexed_Component then
2401 -- Requeue to an entry out of the body
2403 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
2404 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
2406 -- Requeue from within the body itself
2408 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
2409 Entry_Id := Entity (Prefix (Entry_Name));
2411 else
2412 Error_Msg_N ("invalid entry_name specified", N);
2413 return;
2414 end if;
2416 -- If we had a requeue of the form REQUEUE A (B), then the parser
2417 -- accepted it (because it could have been a requeue on an entry index.
2418 -- If A turns out not to be an entry family, then the analysis of A (B)
2419 -- turned it into a function call.
2421 elsif Nkind (Entry_Name) = N_Function_Call then
2422 Error_Msg_N
2423 ("arguments not allowed in requeue statement",
2424 First (Parameter_Associations (Entry_Name)));
2425 return;
2427 -- Normal case of no entry family, no argument
2429 else
2430 Entry_Id := Entity (Entry_Name);
2431 end if;
2433 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
2434 -- target type must be a concurrent interface class-wide type and the
2435 -- target must be a procedure, flagged by pragma Implemented. The
2436 -- target may be an access to class-wide type, in which case it must
2437 -- be dereferenced.
2439 if Present (Target_Obj) then
2440 Synch_Type := Etype (Target_Obj);
2442 if Is_Access_Type (Synch_Type) then
2443 Synch_Type := Designated_Type (Synch_Type);
2444 end if;
2445 end if;
2447 Is_Disp_Req :=
2448 Ada_Version >= Ada_2012
2449 and then Present (Target_Obj)
2450 and then Is_Class_Wide_Type (Synch_Type)
2451 and then Is_Concurrent_Interface (Synch_Type)
2452 and then Ekind (Entry_Id) = E_Procedure
2453 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
2455 -- Resolve entry, and check that it is subtype conformant with the
2456 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
2457 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
2459 if not Is_Entry (Entry_Id)
2460 and then not Is_Disp_Req
2461 then
2462 Error_Msg_N ("expect entry name in requeue statement", Name (N));
2464 elsif Ekind (Entry_Id) = E_Entry_Family
2465 and then Nkind (Entry_Name) /= N_Indexed_Component
2466 then
2467 Error_Msg_N ("missing index for entry family component", Name (N));
2469 else
2470 Resolve_Entry (Name (N));
2471 Generate_Reference (Entry_Id, Entry_Name);
2473 if Present (First_Formal (Entry_Id)) then
2475 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
2476 -- the first parameter of Entry_Id since it is the interface
2477 -- controlling formal.
2479 if Ada_Version >= Ada_2012 and then Is_Disp_Req then
2480 declare
2481 Enclosing_Formal : Entity_Id;
2482 Target_Formal : Entity_Id;
2484 begin
2485 Enclosing_Formal := First_Formal (Enclosing);
2486 Target_Formal := Next_Formal (First_Formal (Entry_Id));
2487 while Present (Enclosing_Formal)
2488 and then Present (Target_Formal)
2489 loop
2490 if not Conforming_Types
2491 (T1 => Etype (Enclosing_Formal),
2492 T2 => Etype (Target_Formal),
2493 Ctype => Subtype_Conformant)
2494 then
2495 Error_Msg_Node_2 := Target_Formal;
2496 Error_Msg_NE
2497 ("formal & is not subtype conformant with &" &
2498 "in dispatching requeue", N, Enclosing_Formal);
2499 end if;
2501 Next_Formal (Enclosing_Formal);
2502 Next_Formal (Target_Formal);
2503 end loop;
2504 end;
2505 else
2506 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
2507 end if;
2509 -- Processing for parameters accessed by the requeue
2511 declare
2512 Ent : Entity_Id;
2514 begin
2515 Ent := First_Formal (Enclosing);
2516 while Present (Ent) loop
2518 -- For OUT or IN OUT parameter, the effect of the requeue is
2519 -- to assign the parameter a value on exit from the requeued
2520 -- body, so we can set it as source assigned. We also clear
2521 -- the Is_True_Constant indication. We do not need to clear
2522 -- Current_Value, since the effect of the requeue is to
2523 -- perform an unconditional goto so that any further
2524 -- references will not occur anyway.
2526 if Ekind_In (Ent, E_Out_Parameter, E_In_Out_Parameter) then
2527 Set_Never_Set_In_Source (Ent, False);
2528 Set_Is_True_Constant (Ent, False);
2529 end if;
2531 -- For all parameters, the requeue acts as a reference,
2532 -- since the value of the parameter is passed to the new
2533 -- entry, so we want to suppress unreferenced warnings.
2535 Set_Referenced (Ent);
2536 Next_Formal (Ent);
2537 end loop;
2538 end;
2539 end if;
2540 end if;
2542 -- AI05-0225: the target protected object of a requeue must be a
2543 -- variable. This is a binding interpretation that applies to all
2544 -- versions of the language. Note that the subprogram does not have
2545 -- to be a protected operation: it can be an primitive implemented
2546 -- by entry with a formal that is a protected interface.
2548 if Present (Target_Obj)
2549 and then not Is_Variable (Target_Obj)
2550 then
2551 Error_Msg_N
2552 ("target protected object of requeue must be a variable", N);
2553 end if;
2554 end Analyze_Requeue;
2556 ------------------------------
2557 -- Analyze_Selective_Accept --
2558 ------------------------------
2560 procedure Analyze_Selective_Accept (N : Node_Id) is
2561 Alts : constant List_Id := Select_Alternatives (N);
2562 Alt : Node_Id;
2564 Accept_Present : Boolean := False;
2565 Terminate_Present : Boolean := False;
2566 Delay_Present : Boolean := False;
2567 Relative_Present : Boolean := False;
2568 Alt_Count : Uint := Uint_0;
2570 begin
2571 Tasking_Used := True;
2572 Check_SPARK_05_Restriction ("select statement is not allowed", N);
2573 Check_Restriction (No_Select_Statements, N);
2575 -- Loop to analyze alternatives
2577 Alt := First (Alts);
2578 while Present (Alt) loop
2579 Alt_Count := Alt_Count + 1;
2580 Analyze (Alt);
2582 if Nkind (Alt) = N_Delay_Alternative then
2583 if Delay_Present then
2585 if Relative_Present /=
2586 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
2587 then
2588 Error_Msg_N
2589 ("delay_until and delay_relative alternatives ", Alt);
2590 Error_Msg_N
2591 ("\cannot appear in the same selective_wait", Alt);
2592 end if;
2594 else
2595 Delay_Present := True;
2596 Relative_Present :=
2597 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
2598 end if;
2600 elsif Nkind (Alt) = N_Terminate_Alternative then
2601 if Terminate_Present then
2602 Error_Msg_N ("only one terminate alternative allowed", N);
2603 else
2604 Terminate_Present := True;
2605 Check_Restriction (No_Terminate_Alternatives, N);
2606 end if;
2608 elsif Nkind (Alt) = N_Accept_Alternative then
2609 Accept_Present := True;
2611 -- Check for duplicate accept
2613 declare
2614 Alt1 : Node_Id;
2615 Stm : constant Node_Id := Accept_Statement (Alt);
2616 EDN : constant Node_Id := Entry_Direct_Name (Stm);
2617 Ent : Entity_Id;
2619 begin
2620 if Nkind (EDN) = N_Identifier
2621 and then No (Condition (Alt))
2622 and then Present (Entity (EDN)) -- defend against junk
2623 and then Ekind (Entity (EDN)) = E_Entry
2624 then
2625 Ent := Entity (EDN);
2627 Alt1 := First (Alts);
2628 while Alt1 /= Alt loop
2629 if Nkind (Alt1) = N_Accept_Alternative
2630 and then No (Condition (Alt1))
2631 then
2632 declare
2633 Stm1 : constant Node_Id := Accept_Statement (Alt1);
2634 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
2636 begin
2637 if Nkind (EDN1) = N_Identifier then
2638 if Entity (EDN1) = Ent then
2639 Error_Msg_Sloc := Sloc (Stm1);
2640 Error_Msg_N
2641 ("accept duplicates one on line#??", Stm);
2642 exit;
2643 end if;
2644 end if;
2645 end;
2646 end if;
2648 Next (Alt1);
2649 end loop;
2650 end if;
2651 end;
2652 end if;
2654 Next (Alt);
2655 end loop;
2657 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
2658 Check_Potentially_Blocking_Operation (N);
2660 if Terminate_Present and Delay_Present then
2661 Error_Msg_N ("at most one of terminate or delay alternative", N);
2663 elsif not Accept_Present then
2664 Error_Msg_N
2665 ("select must contain at least one accept alternative", N);
2666 end if;
2668 if Present (Else_Statements (N)) then
2669 if Terminate_Present or Delay_Present then
2670 Error_Msg_N ("else part not allowed with other alternatives", N);
2671 end if;
2673 Analyze_Statements (Else_Statements (N));
2674 end if;
2675 end Analyze_Selective_Accept;
2677 ------------------------------------------
2678 -- Analyze_Single_Protected_Declaration --
2679 ------------------------------------------
2681 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
2682 Loc : constant Source_Ptr := Sloc (N);
2683 Obj_Id : constant Node_Id := Defining_Identifier (N);
2684 Obj_Decl : Node_Id;
2685 Typ : Entity_Id;
2687 begin
2688 Generate_Definition (Obj_Id);
2689 Tasking_Used := True;
2691 -- A single protected declaration is transformed into a pair of an
2692 -- anonymous protected type and an object of that type. Generate:
2694 -- protected type Typ is ...;
2696 Typ :=
2697 Make_Defining_Identifier (Sloc (Obj_Id),
2698 Chars => New_External_Name (Chars (Obj_Id), 'T'));
2700 Rewrite (N,
2701 Make_Protected_Type_Declaration (Loc,
2702 Defining_Identifier => Typ,
2703 Protected_Definition => Relocate_Node (Protected_Definition (N)),
2704 Interface_List => Interface_List (N)));
2706 -- Use the original defining identifier of the single protected
2707 -- declaration in the generated object declaration to allow for debug
2708 -- information to be attached to it when compiling with -gnatD. The
2709 -- parent of the entity is the new object declaration. The single
2710 -- protected declaration is not used in semantics or code generation,
2711 -- but is scanned when generating debug information, and therefore needs
2712 -- the updated Sloc information from the entity (see Sprint). Generate:
2714 -- Obj : Typ;
2716 Obj_Decl :=
2717 Make_Object_Declaration (Loc,
2718 Defining_Identifier => Obj_Id,
2719 Object_Definition => New_Occurrence_Of (Typ, Loc));
2721 Insert_After (N, Obj_Decl);
2722 Mark_Rewrite_Insertion (Obj_Decl);
2724 -- Relocate aspect Part_Of from the the original single protected
2725 -- declaration to the anonymous object declaration. This emulates the
2726 -- placement of an equivalent source pragma.
2728 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2730 -- Relocate pragma Part_Of from the visible declarations of the original
2731 -- single protected declaration to the anonymous object declaration. The
2732 -- new placement better reflects the role of the pragma.
2734 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2736 -- Enter the names of the anonymous protected type and the object before
2737 -- analysis takes places, because the name of the object may be used in
2738 -- its own body.
2740 Enter_Name (Typ);
2741 Set_Ekind (Typ, E_Protected_Type);
2742 Set_Etype (Typ, Typ);
2743 Set_Anonymous_Object (Typ, Obj_Id);
2745 Enter_Name (Obj_Id);
2746 Set_Ekind (Obj_Id, E_Variable);
2747 Set_Etype (Obj_Id, Typ);
2748 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2749 Set_SPARK_Pragma_Inherited (Obj_Id);
2751 -- Instead of calling Analyze on the new node, call the proper analysis
2752 -- procedure directly. Otherwise the node would be expanded twice, with
2753 -- disastrous result.
2755 Analyze_Protected_Type_Declaration (N);
2757 if Has_Aspects (N) then
2758 Analyze_Aspect_Specifications (N, Obj_Id);
2759 end if;
2760 end Analyze_Single_Protected_Declaration;
2762 -------------------------------------
2763 -- Analyze_Single_Task_Declaration --
2764 -------------------------------------
2766 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
2767 Loc : constant Source_Ptr := Sloc (N);
2768 Obj_Id : constant Node_Id := Defining_Identifier (N);
2769 Obj_Decl : Node_Id;
2770 Typ : Entity_Id;
2772 begin
2773 Generate_Definition (Obj_Id);
2774 Tasking_Used := True;
2776 -- A single task declaration is transformed into a pait of an anonymous
2777 -- task type and an object of that type. Generate:
2779 -- task type Typ is ...;
2781 Typ :=
2782 Make_Defining_Identifier (Sloc (Obj_Id),
2783 Chars => New_External_Name (Chars (Obj_Id), Suffix => "TK"));
2785 Rewrite (N,
2786 Make_Task_Type_Declaration (Loc,
2787 Defining_Identifier => Typ,
2788 Task_Definition => Relocate_Node (Task_Definition (N)),
2789 Interface_List => Interface_List (N)));
2791 -- Use the original defining identifier of the single task declaration
2792 -- in the generated object declaration to allow for debug information
2793 -- to be attached to it when compiling with -gnatD. The parent of the
2794 -- entity is the new object declaration. The single task declaration
2795 -- is not used in semantics or code generation, but is scanned when
2796 -- generating debug information, and therefore needs the updated Sloc
2797 -- information from the entity (see Sprint). Generate:
2799 -- Obj : Typ;
2801 Obj_Decl :=
2802 Make_Object_Declaration (Loc,
2803 Defining_Identifier => Obj_Id,
2804 Object_Definition => New_Occurrence_Of (Typ, Loc));
2806 Insert_After (N, Obj_Decl);
2807 Mark_Rewrite_Insertion (Obj_Decl);
2809 -- Relocate aspects Depends, Global and Part_Of from the original single
2810 -- task declaration to the anonymous object declaration. This emulates
2811 -- the placement of an equivalent source pragma.
2813 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2815 -- Relocate pragmas Depends, Global and Part_Of from the visible
2816 -- declarations of the original single protected declaration to the
2817 -- anonymous object declaration. The new placement better reflects the
2818 -- role of the pragmas.
2820 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2822 -- Enter the names of the anonymous task type and the object before
2823 -- analysis takes places, because the name of the object may be used
2824 -- in its own body.
2826 Enter_Name (Typ);
2827 Set_Ekind (Typ, E_Task_Type);
2828 Set_Etype (Typ, Typ);
2829 Set_Anonymous_Object (Typ, Obj_Id);
2831 Enter_Name (Obj_Id);
2832 Set_Ekind (Obj_Id, E_Variable);
2833 Set_Etype (Obj_Id, Typ);
2834 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2835 Set_SPARK_Pragma_Inherited (Obj_Id);
2837 -- Instead of calling Analyze on the new node, call the proper analysis
2838 -- procedure directly. Otherwise the node would be expanded twice, with
2839 -- disastrous result.
2841 Analyze_Task_Type_Declaration (N);
2843 if Has_Aspects (N) then
2844 Analyze_Aspect_Specifications (N, Obj_Id);
2845 end if;
2846 end Analyze_Single_Task_Declaration;
2848 -----------------------
2849 -- Analyze_Task_Body --
2850 -----------------------
2852 procedure Analyze_Task_Body (N : Node_Id) is
2853 Body_Id : constant Entity_Id := Defining_Identifier (N);
2854 Decls : constant List_Id := Declarations (N);
2855 HSS : constant Node_Id := Handled_Statement_Sequence (N);
2856 Last_E : Entity_Id;
2858 Spec_Id : Entity_Id;
2859 -- This is initially the entity of the task or task type involved, but
2860 -- is replaced by the task type always in the case of a single task
2861 -- declaration, since this is the proper scope to be used.
2863 Ref_Id : Entity_Id;
2864 -- This is the entity of the task or task type, and is the entity used
2865 -- for cross-reference purposes (it differs from Spec_Id in the case of
2866 -- a single task, since Spec_Id is set to the task type).
2868 begin
2869 -- A task body "freezes" the contract of the nearest enclosing package
2870 -- body and all other contracts encountered in the same declarative part
2871 -- up to and excluding the task body. This ensures that annotations
2872 -- referenced by the contract of an entry or subprogram body declared
2873 -- within the current protected body are available.
2875 Analyze_Previous_Contracts (N);
2877 Tasking_Used := True;
2878 Set_Scope (Body_Id, Current_Scope);
2879 Set_Ekind (Body_Id, E_Task_Body);
2880 Set_Etype (Body_Id, Standard_Void_Type);
2881 Spec_Id := Find_Concurrent_Spec (Body_Id);
2883 -- The spec is either a task type declaration, or a single task
2884 -- declaration for which we have created an anonymous type.
2886 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Task_Type then
2887 null;
2889 elsif Present (Spec_Id)
2890 and then Ekind (Etype (Spec_Id)) = E_Task_Type
2891 and then not Comes_From_Source (Etype (Spec_Id))
2892 then
2893 null;
2895 else
2896 Error_Msg_N ("missing specification for task body", Body_Id);
2897 return;
2898 end if;
2900 if Has_Completion (Spec_Id)
2901 and then Present (Corresponding_Body (Parent (Spec_Id)))
2902 then
2903 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
2904 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
2905 else
2906 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
2907 end if;
2908 end if;
2910 Ref_Id := Spec_Id;
2911 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
2912 Style.Check_Identifier (Body_Id, Spec_Id);
2914 -- Deal with case of body of single task (anonymous type was created)
2916 if Ekind (Spec_Id) = E_Variable then
2917 Spec_Id := Etype (Spec_Id);
2918 end if;
2920 -- Set the SPARK_Mode from the current context (may be overwritten later
2921 -- with an explicit pragma).
2923 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
2924 Set_SPARK_Pragma_Inherited (Body_Id);
2926 if Has_Aspects (N) then
2927 Analyze_Aspect_Specifications (N, Body_Id);
2928 end if;
2930 Push_Scope (Spec_Id);
2931 Set_Corresponding_Spec (N, Spec_Id);
2932 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
2933 Set_Has_Completion (Spec_Id);
2934 Install_Declarations (Spec_Id);
2935 Last_E := Last_Entity (Spec_Id);
2937 Analyze_Declarations (Decls);
2938 Inspect_Deferred_Constant_Completion (Decls);
2940 -- For visibility purposes, all entities in the body are private. Set
2941 -- First_Private_Entity accordingly, if there was no private part in the
2942 -- protected declaration.
2944 if No (First_Private_Entity (Spec_Id)) then
2945 if Present (Last_E) then
2946 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
2947 else
2948 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
2949 end if;
2950 end if;
2952 -- Mark all handlers as not suitable for local raise optimization,
2953 -- since this optimization causes difficulties in a task context.
2955 if Present (Exception_Handlers (HSS)) then
2956 declare
2957 Handlr : Node_Id;
2958 begin
2959 Handlr := First (Exception_Handlers (HSS));
2960 while Present (Handlr) loop
2961 Set_Local_Raise_Not_OK (Handlr);
2962 Next (Handlr);
2963 end loop;
2964 end;
2965 end if;
2967 -- Now go ahead and complete analysis of the task body
2969 Analyze (HSS);
2970 Check_Completion (Body_Id);
2971 Check_References (Body_Id);
2972 Check_References (Spec_Id);
2974 -- Check for entries with no corresponding accept
2976 declare
2977 Ent : Entity_Id;
2979 begin
2980 Ent := First_Entity (Spec_Id);
2981 while Present (Ent) loop
2982 if Is_Entry (Ent)
2983 and then not Entry_Accepted (Ent)
2984 and then Comes_From_Source (Ent)
2985 then
2986 Error_Msg_NE ("no accept for entry &??", N, Ent);
2987 end if;
2989 Next_Entity (Ent);
2990 end loop;
2991 end;
2993 Process_End_Label (HSS, 't', Ref_Id);
2994 End_Scope;
2995 end Analyze_Task_Body;
2997 -----------------------------
2998 -- Analyze_Task_Definition --
2999 -----------------------------
3001 procedure Analyze_Task_Definition (N : Node_Id) is
3002 L : Entity_Id;
3004 begin
3005 Tasking_Used := True;
3006 Check_SPARK_05_Restriction ("task definition is not allowed", N);
3008 if Present (Visible_Declarations (N)) then
3009 Analyze_Declarations (Visible_Declarations (N));
3010 end if;
3012 if Present (Private_Declarations (N)) then
3013 L := Last_Entity (Current_Scope);
3014 Analyze_Declarations (Private_Declarations (N));
3016 if Present (L) then
3017 Set_First_Private_Entity
3018 (Current_Scope, Next_Entity (L));
3019 else
3020 Set_First_Private_Entity
3021 (Current_Scope, First_Entity (Current_Scope));
3022 end if;
3023 end if;
3025 Check_Max_Entries (N, Max_Task_Entries);
3026 Process_End_Label (N, 'e', Current_Scope);
3027 end Analyze_Task_Definition;
3029 -----------------------------------
3030 -- Analyze_Task_Type_Declaration --
3031 -----------------------------------
3033 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
3034 Def_Id : constant Entity_Id := Defining_Identifier (N);
3035 T : Entity_Id;
3037 begin
3038 -- Attempt to use tasking in no run time mode is not allowe. Issue hard
3039 -- error message to disable expansion which leads to crashes.
3041 if Opt.No_Run_Time_Mode then
3042 Error_Msg_N ("tasking not allowed in No_Run_Time mode", N);
3044 -- Otherwise soft check for no tasking restriction
3046 else
3047 Check_Restriction (No_Tasking, N);
3048 end if;
3050 -- Proceed ahead with analysis of task type declaration
3052 Tasking_Used := True;
3054 -- The sequential partition elaboration policy is supported only in the
3055 -- restricted profile.
3057 if Partition_Elaboration_Policy = 'S'
3058 and then not Restricted_Profile
3059 then
3060 Error_Msg_N
3061 ("sequential elaboration supported only in restricted profile", N);
3062 end if;
3064 T := Find_Type_Name (N);
3065 Generate_Definition (T);
3067 -- In the case of an incomplete type, use the full view, unless it's not
3068 -- present (as can occur for an incomplete view from a limited with).
3069 -- Initialize the Corresponding_Record_Type (which overlays the Private
3070 -- Dependents field of the incomplete view).
3072 if Ekind (T) = E_Incomplete_Type then
3073 if Present (Full_View (T)) then
3074 T := Full_View (T);
3075 Set_Completion_Referenced (T);
3077 else
3078 Set_Ekind (T, E_Task_Type);
3079 Set_Corresponding_Record_Type (T, Empty);
3080 end if;
3081 end if;
3083 Set_Ekind (T, E_Task_Type);
3084 Set_Is_First_Subtype (T, True);
3085 Set_Has_Task (T, True);
3086 Init_Size_Align (T);
3087 Set_Etype (T, T);
3088 Set_Has_Delayed_Freeze (T, True);
3089 Set_Stored_Constraint (T, No_Elist);
3091 -- Set the SPARK_Mode from the current context (may be overwritten later
3092 -- with an explicit pragma).
3094 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
3095 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
3096 Set_SPARK_Pragma_Inherited (T);
3097 Set_SPARK_Aux_Pragma_Inherited (T);
3099 Push_Scope (T);
3101 if Ada_Version >= Ada_2005 then
3102 Check_Interfaces (N, T);
3103 end if;
3105 if Present (Discriminant_Specifications (N)) then
3106 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3107 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
3108 end if;
3110 if Has_Discriminants (T) then
3112 -- Install discriminants. Also, verify conformance of
3113 -- discriminants of previous and current view. ???
3115 Install_Declarations (T);
3116 else
3117 Process_Discriminants (N);
3118 end if;
3119 end if;
3121 Set_Is_Constrained (T, not Has_Discriminants (T));
3123 if Has_Aspects (N) then
3125 -- The task type is the full view of a private type. Analyze the
3126 -- aspects with the entity of the private type to ensure that after
3127 -- both views are exchanged, the aspect are actually associated with
3128 -- the full view.
3130 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3131 Analyze_Aspect_Specifications (N, T);
3132 else
3133 Analyze_Aspect_Specifications (N, Def_Id);
3134 end if;
3135 end if;
3137 if Present (Task_Definition (N)) then
3138 Analyze_Task_Definition (Task_Definition (N));
3139 end if;
3141 -- In the case where the task type is declared at a nested level and the
3142 -- No_Task_Hierarchy restriction applies, issue a warning that objects
3143 -- of the type will violate the restriction.
3145 if Restriction_Check_Required (No_Task_Hierarchy)
3146 and then not Is_Library_Level_Entity (T)
3147 and then Comes_From_Source (T)
3148 and then not CodePeer_Mode
3149 then
3150 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
3152 if Error_Msg_Sloc = No_Location then
3153 Error_Msg_N
3154 ("objects of this type will violate `No_Task_Hierarchy`??", N);
3155 else
3156 Error_Msg_N
3157 ("objects of this type will violate `No_Task_Hierarchy`#??", N);
3158 end if;
3159 end if;
3161 End_Scope;
3163 -- Case of a completion of a private declaration
3165 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3167 -- Deal with preelaborable initialization. Note that this processing
3168 -- is done by Process_Full_View, but as can be seen below, in this
3169 -- case the call to Process_Full_View is skipped if any serious
3170 -- errors have occurred, and we don't want to lose this check.
3172 if Known_To_Have_Preelab_Init (Def_Id) then
3173 Set_Must_Have_Preelab_Init (T);
3174 end if;
3176 -- Propagate Default_Initial_Condition-related attributes from the
3177 -- private type to the task type.
3179 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
3181 -- Propagate invariant-related attributes from the private type to
3182 -- task type.
3184 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
3186 -- Create corresponding record now, because some private dependents
3187 -- may be subtypes of the partial view.
3189 -- Skip if errors are present, to prevent cascaded messages
3191 if Serious_Errors_Detected = 0
3193 -- Also skip if expander is not active
3195 and then Expander_Active
3196 then
3197 Expand_N_Task_Type_Declaration (N);
3198 Process_Full_View (N, T, Def_Id);
3199 end if;
3200 end if;
3202 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
3203 -- is required for the ceiling priority protocol checks triggered by
3204 -- calls originating from tasks.
3206 if GNATprove_Mode then
3207 SPARK_Implicit_Load (RE_Interrupt_Priority);
3208 end if;
3209 end Analyze_Task_Type_Declaration;
3211 -----------------------------------
3212 -- Analyze_Terminate_Alternative --
3213 -----------------------------------
3215 procedure Analyze_Terminate_Alternative (N : Node_Id) is
3216 begin
3217 Tasking_Used := True;
3219 if Present (Pragmas_Before (N)) then
3220 Analyze_List (Pragmas_Before (N));
3221 end if;
3223 if Present (Condition (N)) then
3224 Analyze_And_Resolve (Condition (N), Any_Boolean);
3225 end if;
3226 end Analyze_Terminate_Alternative;
3228 ------------------------------
3229 -- Analyze_Timed_Entry_Call --
3230 ------------------------------
3232 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
3233 Trigger : constant Node_Id :=
3234 Entry_Call_Statement (Entry_Call_Alternative (N));
3235 Is_Disp_Select : Boolean := False;
3237 begin
3238 Tasking_Used := True;
3239 Check_SPARK_05_Restriction ("select statement is not allowed", N);
3240 Check_Restriction (No_Select_Statements, N);
3242 -- Ada 2005 (AI-345): The trigger may be a dispatching call
3244 if Ada_Version >= Ada_2005 then
3245 Analyze (Trigger);
3246 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
3247 end if;
3249 -- Postpone the analysis of the statements till expansion. Analyze only
3250 -- if the expander is disabled in order to catch any semantic errors.
3252 if Is_Disp_Select then
3253 if not Expander_Active then
3254 Analyze (Entry_Call_Alternative (N));
3255 Analyze (Delay_Alternative (N));
3256 end if;
3258 -- Regular select analysis
3260 else
3261 Analyze (Entry_Call_Alternative (N));
3262 Analyze (Delay_Alternative (N));
3263 end if;
3264 end Analyze_Timed_Entry_Call;
3266 ------------------------------------
3267 -- Analyze_Triggering_Alternative --
3268 ------------------------------------
3270 procedure Analyze_Triggering_Alternative (N : Node_Id) is
3271 Trigger : constant Node_Id := Triggering_Statement (N);
3273 begin
3274 Tasking_Used := True;
3276 if Present (Pragmas_Before (N)) then
3277 Analyze_List (Pragmas_Before (N));
3278 end if;
3280 Analyze (Trigger);
3282 if Comes_From_Source (Trigger)
3283 and then Nkind (Trigger) not in N_Delay_Statement
3284 and then Nkind (Trigger) /= N_Entry_Call_Statement
3285 then
3286 if Ada_Version < Ada_2005 then
3287 Error_Msg_N
3288 ("triggering statement must be delay or entry call", Trigger);
3290 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
3291 -- procedure_or_entry_call, the procedure_name or procedure_prefix
3292 -- of the procedure_call_statement shall denote an entry renamed by a
3293 -- procedure, or (a view of) a primitive subprogram of a limited
3294 -- interface whose first parameter is a controlling parameter.
3296 elsif Nkind (Trigger) = N_Procedure_Call_Statement
3297 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
3298 and then not Is_Controlling_Limited_Procedure
3299 (Entity (Name (Trigger)))
3300 then
3301 Error_Msg_N
3302 ("triggering statement must be procedure or entry call " &
3303 "or delay statement", Trigger);
3304 end if;
3305 end if;
3307 if Is_Non_Empty_List (Statements (N)) then
3308 Analyze_Statements (Statements (N));
3309 end if;
3310 end Analyze_Triggering_Alternative;
3312 -----------------------
3313 -- Check_Max_Entries --
3314 -----------------------
3316 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
3317 Ecount : Uint;
3319 procedure Count (L : List_Id);
3320 -- Count entries in given declaration list
3322 -----------
3323 -- Count --
3324 -----------
3326 procedure Count (L : List_Id) is
3327 D : Node_Id;
3329 begin
3330 if No (L) then
3331 return;
3332 end if;
3334 D := First (L);
3335 while Present (D) loop
3336 if Nkind (D) = N_Entry_Declaration then
3337 declare
3338 DSD : constant Node_Id :=
3339 Discrete_Subtype_Definition (D);
3341 begin
3342 -- If not an entry family, then just one entry
3344 if No (DSD) then
3345 Ecount := Ecount + 1;
3347 -- If entry family with static bounds, count entries
3349 elsif Is_OK_Static_Subtype (Etype (DSD)) then
3350 declare
3351 Lo : constant Uint :=
3352 Expr_Value
3353 (Type_Low_Bound (Etype (DSD)));
3354 Hi : constant Uint :=
3355 Expr_Value
3356 (Type_High_Bound (Etype (DSD)));
3358 begin
3359 if Hi >= Lo then
3360 Ecount := Ecount + Hi - Lo + 1;
3361 end if;
3362 end;
3364 -- Entry family with non-static bounds
3366 else
3367 -- Record an unknown count restriction, and if the
3368 -- restriction is active, post a message or warning.
3370 Check_Restriction (R, D);
3371 end if;
3372 end;
3373 end if;
3375 Next (D);
3376 end loop;
3377 end Count;
3379 -- Start of processing for Check_Max_Entries
3381 begin
3382 Ecount := Uint_0;
3383 Count (Visible_Declarations (D));
3384 Count (Private_Declarations (D));
3386 if Ecount > 0 then
3387 Check_Restriction (R, D, Ecount);
3388 end if;
3389 end Check_Max_Entries;
3391 ----------------------
3392 -- Check_Interfaces --
3393 ----------------------
3395 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
3396 Iface : Node_Id;
3397 Iface_Typ : Entity_Id;
3399 begin
3400 pragma Assert
3401 (Nkind_In (N, N_Protected_Type_Declaration, N_Task_Type_Declaration));
3403 if Present (Interface_List (N)) then
3404 Set_Is_Tagged_Type (T);
3406 -- The primitive operations of a tagged synchronized type are placed
3407 -- on the Corresponding_Record for proper dispatching, but are
3408 -- attached to the synchronized type itself when expansion is
3409 -- disabled, for ASIS use.
3411 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3413 Iface := First (Interface_List (N));
3414 while Present (Iface) loop
3415 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
3417 if not Is_Interface (Iface_Typ) then
3418 Error_Msg_NE
3419 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
3421 else
3422 -- Ada 2005 (AI-251): "The declaration of a specific descendant
3423 -- of an interface type freezes the interface type" RM 13.14.
3425 Freeze_Before (N, Etype (Iface));
3427 if Nkind (N) = N_Protected_Type_Declaration then
3429 -- Ada 2005 (AI-345): Protected types can only implement
3430 -- limited, synchronized, or protected interfaces (note that
3431 -- the predicate Is_Limited_Interface includes synchronized
3432 -- and protected interfaces).
3434 if Is_Task_Interface (Iface_Typ) then
3435 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3436 & "a task interface", Iface);
3438 elsif not Is_Limited_Interface (Iface_Typ) then
3439 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3440 & "a non-limited interface", Iface);
3441 end if;
3443 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
3445 -- Ada 2005 (AI-345): Task types can only implement limited,
3446 -- synchronized, or task interfaces (note that the predicate
3447 -- Is_Limited_Interface includes synchronized and task
3448 -- interfaces).
3450 if Is_Protected_Interface (Iface_Typ) then
3451 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3452 "protected interface", Iface);
3454 elsif not Is_Limited_Interface (Iface_Typ) then
3455 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3456 "non-limited interface", Iface);
3457 end if;
3458 end if;
3459 end if;
3461 Next (Iface);
3462 end loop;
3463 end if;
3465 if not Has_Private_Declaration (T) then
3466 return;
3467 end if;
3469 -- Additional checks on full-types associated with private type
3470 -- declarations. Search for the private type declaration.
3472 declare
3473 Full_T_Ifaces : Elist_Id;
3474 Iface : Node_Id;
3475 Priv_T : Entity_Id;
3476 Priv_T_Ifaces : Elist_Id;
3478 begin
3479 Priv_T := First_Entity (Scope (T));
3480 loop
3481 pragma Assert (Present (Priv_T));
3483 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
3484 exit when Full_View (Priv_T) = T;
3485 end if;
3487 Next_Entity (Priv_T);
3488 end loop;
3490 -- In case of synchronized types covering interfaces the private type
3491 -- declaration must be limited.
3493 if Present (Interface_List (N))
3494 and then not Is_Limited_Type (Priv_T)
3495 then
3496 Error_Msg_Sloc := Sloc (Priv_T);
3497 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
3498 "private type#", T);
3499 end if;
3501 -- RM 7.3 (7.1/2): If the full view has a partial view that is
3502 -- tagged then check RM 7.3 subsidiary rules.
3504 if Is_Tagged_Type (Priv_T)
3505 and then not Error_Posted (N)
3506 then
3507 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
3508 -- type if and only if the full type is a synchronized tagged type
3510 if Is_Synchronized_Tagged_Type (Priv_T)
3511 and then not Is_Synchronized_Tagged_Type (T)
3512 then
3513 Error_Msg_N
3514 ("(Ada 2005) full view must be a synchronized tagged " &
3515 "type (RM 7.3 (7.2/2))", Priv_T);
3517 elsif Is_Synchronized_Tagged_Type (T)
3518 and then not Is_Synchronized_Tagged_Type (Priv_T)
3519 then
3520 Error_Msg_N
3521 ("(Ada 2005) partial view must be a synchronized tagged " &
3522 "type (RM 7.3 (7.2/2))", T);
3523 end if;
3525 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
3526 -- interface type if and only if the full type is descendant of
3527 -- the interface type.
3529 if Present (Interface_List (N))
3530 or else (Is_Tagged_Type (Priv_T)
3531 and then Has_Interfaces
3532 (Priv_T, Use_Full_View => False))
3533 then
3534 if Is_Tagged_Type (Priv_T) then
3535 Collect_Interfaces
3536 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
3537 end if;
3539 if Is_Tagged_Type (T) then
3540 Collect_Interfaces (T, Full_T_Ifaces);
3541 end if;
3543 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
3545 if Present (Iface) then
3546 Error_Msg_NE
3547 ("interface in partial view& not implemented by full "
3548 & "type (RM-2005 7.3 (7.3/2))", T, Iface);
3549 end if;
3551 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
3553 if Present (Iface) then
3554 Error_Msg_NE
3555 ("interface & not implemented by partial " &
3556 "view (RM-2005 7.3 (7.3/2))", T, Iface);
3557 end if;
3558 end if;
3559 end if;
3560 end;
3561 end Check_Interfaces;
3563 --------------------------------
3564 -- Check_Triggering_Statement --
3565 --------------------------------
3567 procedure Check_Triggering_Statement
3568 (Trigger : Node_Id;
3569 Error_Node : Node_Id;
3570 Is_Dispatching : out Boolean)
3572 Param : Node_Id;
3574 begin
3575 Is_Dispatching := False;
3577 -- It is not possible to have a dispatching trigger if we are not in
3578 -- Ada 2005 mode.
3580 if Ada_Version >= Ada_2005
3581 and then Nkind (Trigger) = N_Procedure_Call_Statement
3582 and then Present (Parameter_Associations (Trigger))
3583 then
3584 Param := First (Parameter_Associations (Trigger));
3586 if Is_Controlling_Actual (Param)
3587 and then Is_Interface (Etype (Param))
3588 then
3589 if Is_Limited_Record (Etype (Param)) then
3590 Is_Dispatching := True;
3591 else
3592 Error_Msg_N
3593 ("dispatching operation of limited or synchronized " &
3594 "interface required (RM 9.7.2(3))!", Error_Node);
3595 end if;
3597 elsif Nkind (Trigger) = N_Explicit_Dereference then
3598 Error_Msg_N
3599 ("entry call or dispatching primitive of interface required ",
3600 Trigger);
3601 end if;
3602 end if;
3603 end Check_Triggering_Statement;
3605 --------------------------
3606 -- Find_Concurrent_Spec --
3607 --------------------------
3609 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
3610 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
3612 begin
3613 -- The type may have been given by an incomplete type declaration.
3614 -- Find full view now.
3616 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
3617 Spec_Id := Full_View (Spec_Id);
3618 end if;
3620 return Spec_Id;
3621 end Find_Concurrent_Spec;
3623 --------------------------
3624 -- Install_Declarations --
3625 --------------------------
3627 procedure Install_Declarations (Spec : Entity_Id) is
3628 E : Entity_Id;
3629 Prev : Entity_Id;
3630 begin
3631 E := First_Entity (Spec);
3632 while Present (E) loop
3633 Prev := Current_Entity (E);
3634 Set_Current_Entity (E);
3635 Set_Is_Immediately_Visible (E);
3636 Set_Homonym (E, Prev);
3637 Next_Entity (E);
3638 end loop;
3639 end Install_Declarations;
3641 end Sem_Ch9;