Debian Codegraph @

gcc/ada/sem_ch9.adb

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