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