1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Contracts; use Contracts;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Exp_Ch9; use Exp_Ch9;
34 with Elists; use Elists;
35 with Freeze; use Freeze;
36 with Layout; use Layout;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Rtsfind; use Rtsfind;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Ch3; use Sem_Ch3;
48 with Sem_Ch5; use Sem_Ch5;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch13; use Sem_Ch13;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Res; use Sem_Res;
54 with Sem_Type; use Sem_Type;
55 with Sem_Util; use Sem_Util;
56 with Sem_Warn; use Sem_Warn;
57 with Snames; use Snames;
58 with Stand; use Stand;
59 with Sinfo; use Sinfo;
61 with Tbuild; use Tbuild;
62 with Uintp; use Uintp;
64 package body Sem_Ch9 is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 function Allows_Lock_Free_Implementation
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:
76 -- 1) Protected type declaration
77 -- May not contain entries
78 -- Protected subprogram declarations may not have non-elementary
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
86 -- May not contain address representation items, allocators and
87 -- quantified expressions.
88 -- May not contain delay, goto, loop and procedure call
90 -- May not contain exported and imported entities
91 -- May not dereference access values
92 -- Function calls and attribute references must be static
94 -- If Lock_Free_Given is True, an error message is issued when False is
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.
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.
107 procedure Check_Triggering_Statement
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.
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.
120 -------------------------------------
121 -- Allows_Lock_Free_Implementation --
122 -------------------------------------
124 function Allows_Lock_Free_Implementation
126 Lock_Free_Given : Boolean := False) return Boolean
129 -- Errors_Count is a count of errors detected by the compiler so far
130 -- when Lock_Free_Given is True.
133 pragma Assert (Nkind_In (N, N_Protected_Type_Declaration,
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.
140 if not Lock_Free_Given and then not Debug_Flag_9 then
144 -- Get the number of errors detected by the compiler so far
146 if Lock_Free_Given then
147 Errors_Count := Serious_Errors_Detected;
150 -- Protected type declaration case
152 if Nkind (N) = N_Protected_Type_Declaration then
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);
160 -- Examine the visible and the private declarations
162 Decl := First (Vis_Decls);
163 while Present (Decl) loop
165 -- Entries and entry families are not allowed by the lock-free
168 if Nkind (Decl) = N_Entry_Declaration then
169 if Lock_Free_Given then
171 ("entry not allowed when Lock_Free given", Decl);
176 -- Non-elementary parameters in protected procedure are not
177 -- allowed by the lock-free restrictions.
179 elsif Nkind (Decl) = N_Subprogram_Declaration
181 Nkind (Specification (Decl)) = N_Procedure_Specification
183 Present (Parameter_Specifications (Specification (Decl)))
186 Par_Specs : constant List_Id :=
187 Parameter_Specifications
188 (Specification (Decl));
193 Par := First (Par_Specs);
194 while Present (Par) loop
195 if not Is_Elementary_Type
196 (Etype (Defining_Identifier (Par)))
198 if Lock_Free_Given then
200 ("non-elementary parameter& not allowed "
201 & "when Lock_Free given",
202 Par, Defining_Identifier (Par));
213 -- Examine private declarations after visible declarations
216 and then List_Containing (Decl) = Vis_Decls
218 Decl := First (Priv_Decls);
225 -- Protected body case
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);
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.
243 --------------------------------------
244 -- Satisfies_Lock_Free_Requirements --
245 --------------------------------------
247 function Satisfies_Lock_Free_Requirements
248 (Sub_Body : Node_Id) return Boolean
250 Is_Procedure : constant Boolean :=
251 Ekind (Corresponding_Spec (Sub_Body)) =
253 -- Indicates if Sub_Body is a procedure body
255 Comp : Entity_Id := Empty;
256 -- Track the current component which the body references
259 -- Errors_Count is a count of errors detected by the compiler
260 -- so far when Lock_Free_Given is True.
262 function Check_Node (N : Node_Id) return Traverse_Result;
263 -- Check that node N meets the lock free restrictions
269 function Check_Node (N : Node_Id) return Traverse_Result is
270 Kind : constant Node_Kind := Nkind (N);
272 -- The following function belongs in sem_eval ???
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
279 ------------------------
280 -- Is_Static_Function --
281 ------------------------
283 function Is_Static_Function
284 (Attr : Node_Id) return Boolean
289 pragma Assert (Nkind (Attr) = N_Attribute_Reference);
291 case Attribute_Name (Attr) is
298 Name_Wide_Wide_Value =>
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)).
305 if Is_Scalar_Type (Etype (Attr))
306 and then Is_Scalar_Type (Etype (Prefix (Attr)))
308 Is_OK_Static_Subtype (Etype (Prefix (Attr)))
310 Para := First (Expressions (Attr));
312 while Present (Para) loop
313 if not Is_Scalar_Type (Etype (Para)) then
326 when others => return False;
328 end Is_Static_Function;
330 -- Start of processing for Check_Node
334 -- Allocators restricted
336 if Kind = N_Allocator then
337 if Lock_Free_Given then
338 Error_Msg_N ("allocator not allowed", N);
344 -- Aspects Address, Export and Import restricted
346 elsif Kind = N_Aspect_Specification then
348 Asp_Name : constant Name_Id :=
349 Chars (Identifier (N));
350 Asp_Id : constant Aspect_Id :=
351 Get_Aspect_Id (Asp_Name);
354 if Asp_Id = Aspect_Address or else
355 Asp_Id = Aspect_Export or else
356 Asp_Id = Aspect_Import
358 Error_Msg_Name_1 := Asp_Name;
360 if Lock_Free_Given then
361 Error_Msg_N ("aspect% not allowed", N);
369 -- Address attribute definition clause restricted
371 elsif Kind = N_Attribute_Definition_Clause
372 and then Get_Attribute_Id (Chars (N)) =
375 Error_Msg_Name_1 := Chars (N);
377 if Lock_Free_Given then
378 if From_Aspect_Specification (N) then
379 Error_Msg_N ("aspect% not allowed", N);
381 Error_Msg_N ("% clause not allowed", N);
389 -- Non-static Attribute references that don't denote a
390 -- static function restricted.
392 elsif Kind = N_Attribute_Reference
393 and then not Is_OK_Static_Expression (N)
394 and then not Is_Static_Function (N)
396 if Lock_Free_Given then
398 ("non-static attribute reference not allowed", N);
404 -- Delay statements restricted
406 elsif Kind in N_Delay_Statement then
407 if Lock_Free_Given then
408 Error_Msg_N ("delay not allowed", N);
414 -- Dereferences of access values restricted
416 elsif Kind = N_Explicit_Dereference
417 or else (Kind = N_Selected_Component
418 and then Is_Access_Type (Etype (Prefix (N))))
420 if Lock_Free_Given then
422 ("dereference of access value not allowed", N);
428 -- Non-static function calls restricted
430 elsif Kind = N_Function_Call
431 and then not Is_OK_Static_Expression (N)
433 if Lock_Free_Given then
435 ("non-static function call not allowed", N);
441 -- Goto statements restricted
443 elsif Kind = N_Goto_Statement then
444 if Lock_Free_Given then
445 Error_Msg_N ("goto statement not allowed", N);
453 elsif Kind = N_Identifier
454 and then Present (Entity (N))
457 Id : constant Entity_Id := Entity (N);
458 Sub_Id : constant Entity_Id :=
459 Corresponding_Spec (Sub_Body);
462 -- Prohibit references to non-constant entities
463 -- outside the protected subprogram scope.
465 if Ekind (Id) in Assignable_Kind
467 Scope_Within_Or_Same (Scope (Id), Sub_Id)
471 Protected_Body_Subprogram (Sub_Id))
473 if Lock_Free_Given then
475 ("reference to global variable& not " &
484 -- Loop statements restricted
486 elsif Kind = N_Loop_Statement then
487 if Lock_Free_Given then
488 Error_Msg_N ("loop not allowed", N);
494 -- Pragmas Export and Import restricted
496 elsif Kind = N_Pragma then
498 Prag_Name : constant Name_Id := Pragma_Name (N);
499 Prag_Id : constant Pragma_Id :=
500 Get_Pragma_Id (Prag_Name);
503 if Prag_Id = Pragma_Export
504 or else Prag_Id = Pragma_Import
506 Error_Msg_Name_1 := Prag_Name;
508 if Lock_Free_Given then
509 if From_Aspect_Specification (N) then
510 Error_Msg_N ("aspect% not allowed", N);
512 Error_Msg_N ("pragma% not allowed", N);
522 -- Procedure call statements restricted
524 elsif Kind = N_Procedure_Call_Statement then
525 if Lock_Free_Given then
526 Error_Msg_N ("procedure call not allowed", N);
532 -- Quantified expression restricted. Note that we have
533 -- to check the original node as well, since at this
534 -- stage, it may have been rewritten.
536 elsif Kind = N_Quantified_Expression
538 Nkind (Original_Node (N)) = N_Quantified_Expression
540 if Lock_Free_Given then
542 ("quantified expression not allowed", N);
550 -- A protected subprogram (function or procedure) may
551 -- reference only one component of the protected type, plus
552 -- the type of the component must support atomic operation.
554 if Kind = N_Identifier
555 and then Present (Entity (N))
558 Id : constant Entity_Id := Entity (N);
560 Comp_Id : Entity_Id := Empty;
561 Comp_Type : Entity_Id;
564 if Ekind (Id) = E_Component then
567 elsif Ekind_In (Id, E_Constant, E_Variable)
568 and then Present (Prival_Link (Id))
570 Comp_Id := Prival_Link (Id);
573 if Present (Comp_Id) then
574 Comp_Decl := Parent (Comp_Id);
575 Comp_Type := Etype (Comp_Id);
577 if Nkind (Comp_Decl) = N_Component_Declaration
578 and then Is_List_Member (Comp_Decl)
579 and then List_Containing (Comp_Decl) = Priv_Decls
581 -- Skip generic types since, in that case, we
582 -- will not build a body anyway (in the generic
583 -- template), and the size in the template may
584 -- have a fake value.
586 if not Is_Generic_Type (Comp_Type) then
588 -- Make sure the protected component type has
589 -- size and alignment fields set at this
590 -- point whenever this is possible.
592 Layout_Type (Comp_Type);
595 Support_Atomic_Primitives (Comp_Type)
597 if Lock_Free_Given then
599 ("type of& must support atomic " &
609 -- Check if another protected component has
610 -- already been accessed by the subprogram body.
615 elsif Comp /= Comp_Id then
616 if Lock_Free_Given then
618 ("only one protected component allowed",
633 function Check_All_Nodes is new Traverse_Func (Check_Node);
635 -- Start of processing for Satisfies_Lock_Free_Requirements
638 -- Get the number of errors detected by the compiler so far
640 if Lock_Free_Given then
641 Errors_Count := Serious_Errors_Detected;
644 if Check_All_Nodes (Sub_Body) = OK
645 and then (not Lock_Free_Given
646 or else Errors_Count = Serious_Errors_Detected)
648 -- Establish a relation between the subprogram body and the
649 -- unique protected component it references.
651 if Present (Comp) then
652 Lock_Free_Subprogram_Table.Append
653 (Lock_Free_Subprogram'(Sub_Body, Comp));
660 end Satisfies_Lock_Free_Requirements;
662 -- Start of processing for Protected_Body_Case
665 Decl := First (Decls);
666 while Present (Decl) loop
667 if Nkind (Decl) = N_Subprogram_Body
668 and then not Satisfies_Lock_Free_Requirements (Decl)
670 if Lock_Free_Given then
672 ("illegal body when Lock_Free given", Decl);
680 end Protected_Body_Case;
683 -- When Lock_Free is given, check if no error has been detected during
687 and then Errors_Count /= Serious_Errors_Detected
693 end Allows_Lock_Free_Implementation;
695 -----------------------------
696 -- Analyze_Abort_Statement --
697 -----------------------------
699 procedure Analyze_Abort_Statement (N : Node_Id) is
703 Tasking_Used := True;
704 Check_SPARK_05_Restriction ("abort statement is not allowed", N);
706 T_Name := First (Names (N));
707 while Present (T_Name) loop
710 if Is_Task_Type (Etype (T_Name))
711 or else (Ada_Version >= Ada_2005
712 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
713 and then Is_Interface (Etype (T_Name))
714 and then Is_Task_Interface (Etype (T_Name)))
718 if Ada_Version >= Ada_2005 then
719 Error_Msg_N ("expect task name or task interface class-wide "
720 & "object for ABORT", T_Name);
722 Error_Msg_N ("expect task name for ABORT", T_Name);
731 Check_Restriction (No_Abort_Statements, N);
732 Check_Potentially_Blocking_Operation (N);
733 end Analyze_Abort_Statement;
735 --------------------------------
736 -- Analyze_Accept_Alternative --
737 --------------------------------
739 procedure Analyze_Accept_Alternative (N : Node_Id) is
741 Tasking_Used := True;
743 if Present (Pragmas_Before (N)) then
744 Analyze_List (Pragmas_Before (N));
747 if Present (Condition (N)) then
748 Analyze_And_Resolve (Condition (N), Any_Boolean);
751 Analyze (Accept_Statement (N));
753 if Is_Non_Empty_List (Statements (N)) then
754 Analyze_Statements (Statements (N));
756 end Analyze_Accept_Alternative;
758 ------------------------------
759 -- Analyze_Accept_Statement --
760 ------------------------------
762 procedure Analyze_Accept_Statement (N : Node_Id) is
763 Nam : constant Entity_Id := Entry_Direct_Name (N);
764 Formals : constant List_Id := Parameter_Specifications (N);
765 Index : constant Node_Id := Entry_Index (N);
766 Stats : constant Node_Id := Handled_Statement_Sequence (N);
767 Accept_Id : Entity_Id;
768 Entry_Nam : Entity_Id;
771 Task_Nam : Entity_Id;
774 Tasking_Used := True;
775 Check_SPARK_05_Restriction ("accept statement is not allowed", N);
777 -- Entry name is initialized to Any_Id. It should get reset to the
778 -- matching entry entity. An error is signalled if it is not reset.
782 for J in reverse 0 .. Scope_Stack.Last loop
783 Task_Nam := Scope_Stack.Table (J).Entity;
784 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
785 Kind := Ekind (Task_Nam);
787 if Kind /= E_Block and then Kind /= E_Loop
788 and then not Is_Entry (Task_Nam)
790 Error_Msg_N ("enclosing body of accept must be a task", N);
795 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
796 Error_Msg_N ("invalid context for accept statement", N);
800 -- In order to process the parameters, we create a defining identifier
801 -- that can be used as the name of the scope. The name of the accept
802 -- statement itself is not a defining identifier, and we cannot use
803 -- its name directly because the task may have any number of accept
804 -- statements for the same entry.
806 if Present (Index) then
807 Accept_Id := New_Internal_Entity
808 (E_Entry_Family, Current_Scope, Sloc (N), 'E');
810 Accept_Id := New_Internal_Entity
811 (E_Entry, Current_Scope, Sloc (N), 'E');
814 Set_Etype (Accept_Id, Standard_Void_Type);
815 Set_Accept_Address (Accept_Id, New_Elmt_List);
817 if Present (Formals) then
818 Push_Scope (Accept_Id);
819 Process_Formals (Formals, N);
820 Create_Extra_Formals (Accept_Id);
824 -- We set the default expressions processed flag because we don't need
825 -- default expression functions. This is really more like body entity
826 -- than a spec entity anyway.
828 Set_Default_Expressions_Processed (Accept_Id);
830 E := First_Entity (Etype (Task_Nam));
831 while Present (E) loop
832 if Chars (E) = Chars (Nam)
833 and then (Ekind (E) = Ekind (Accept_Id))
834 and then Type_Conformant (Accept_Id, E)
843 if Entry_Nam = Any_Id then
844 Error_Msg_N ("no entry declaration matches accept statement", N);
847 Set_Entity (Nam, Entry_Nam);
848 Generate_Reference (Entry_Nam, Nam, 'b', Set_Ref => False);
849 Style.Check_Identifier (Nam, Entry_Nam);
852 -- Verify that the entry is not hidden by a procedure declared in the
853 -- current block (pathological but possible).
855 if Current_Scope /= Task_Nam then
860 E1 := First_Entity (Current_Scope);
861 while Present (E1) loop
862 if Ekind (E1) = E_Procedure
863 and then Chars (E1) = Chars (Entry_Nam)
864 and then Type_Conformant (E1, Entry_Nam)
866 Error_Msg_N ("entry name is not visible", N);
874 Set_Convention (Accept_Id, Convention (Entry_Nam));
875 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
877 for J in reverse 0 .. Scope_Stack.Last loop
878 exit when Task_Nam = Scope_Stack.Table (J).Entity;
880 if Entry_Nam = Scope_Stack.Table (J).Entity then
881 Error_Msg_N ("duplicate accept statement for same entry", N);
891 when N_Task_Body | N_Compilation_Unit =>
893 when N_Asynchronous_Select =>
894 Error_Msg_N ("accept statements are not allowed within" &
895 " an asynchronous select inner" &
896 " to the enclosing task body", N);
904 if Ekind (E) = E_Entry_Family then
906 Error_Msg_N ("missing entry index in accept for entry family", N);
908 Analyze_And_Resolve (Index, Entry_Index_Type (E));
909 Apply_Range_Check (Index, Entry_Index_Type (E));
912 elsif Present (Index) then
913 Error_Msg_N ("invalid entry index in accept for simple entry", N);
916 -- If label declarations present, analyze them. They are declared in the
917 -- enclosing task, but their enclosing scope is the entry itself, so
918 -- that goto's to the label are recognized as local to the accept.
920 if Present (Declarations (N)) then
926 Decl := First (Declarations (N));
927 while Present (Decl) loop
931 (Nkind (Decl) = N_Implicit_Label_Declaration);
933 Id := Defining_Identifier (Decl);
934 Set_Enclosing_Scope (Id, Entry_Nam);
940 -- If statements are present, they must be analyzed in the context of
941 -- the entry, so that references to formals are correctly resolved. We
942 -- also have to add the declarations that are required by the expansion
943 -- of the accept statement in this case if expansion active.
945 -- In the case of a select alternative of a selective accept, the
946 -- expander references the address declaration even if there is no
949 -- We also need to create the renaming declarations for the local
950 -- variables that will replace references to the formals within the
953 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
955 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
956 -- fields on all entry formals (this loop ignores all other entities).
957 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
958 -- well, so that we can post accurate warnings on each accept statement
959 -- for the same entry.
961 E := First_Entity (Entry_Nam);
962 while Present (E) loop
963 if Is_Formal (E) then
964 Set_Never_Set_In_Source (E, True);
965 Set_Is_True_Constant (E, False);
966 Set_Current_Value (E, Empty);
967 Set_Referenced (E, False);
968 Set_Referenced_As_LHS (E, False);
969 Set_Referenced_As_Out_Parameter (E, False);
970 Set_Has_Pragma_Unreferenced (E, False);
976 -- Analyze statements if present
978 if Present (Stats) then
979 Push_Scope (Entry_Nam);
980 Install_Declarations (Entry_Nam);
982 Set_Actual_Subtypes (N, Current_Scope);
985 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Nam);
989 -- Some warning checks
991 Check_Potentially_Blocking_Operation (N);
992 Check_References (Entry_Nam, N);
993 Set_Entry_Accepted (Entry_Nam);
994 end Analyze_Accept_Statement;
996 ---------------------------------
997 -- Analyze_Asynchronous_Select --
998 ---------------------------------
1000 procedure Analyze_Asynchronous_Select (N : Node_Id) is
1001 Is_Disp_Select : Boolean := False;
1005 Tasking_Used := True;
1006 Check_SPARK_05_Restriction ("select statement is not allowed", N);
1007 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
1008 Check_Restriction (No_Select_Statements, N);
1010 if Ada_Version >= Ada_2005 then
1011 Trigger := Triggering_Statement (Triggering_Alternative (N));
1015 -- Ada 2005 (AI-345): Check for a potential dispatching select
1017 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1020 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
1021 -- select will have to duplicate the triggering statements. Postpone
1022 -- the analysis of the statements till expansion. Analyze only if the
1023 -- expander is disabled in order to catch any semantic errors.
1025 if Is_Disp_Select then
1026 if not Expander_Active then
1027 Analyze_Statements (Statements (Abortable_Part (N)));
1028 Analyze (Triggering_Alternative (N));
1031 -- Analyze the statements. We analyze statements in the abortable part,
1032 -- because this is the section that is executed first, and that way our
1033 -- remembering of saved values and checks is accurate.
1036 Analyze_Statements (Statements (Abortable_Part (N)));
1037 Analyze (Triggering_Alternative (N));
1039 end Analyze_Asynchronous_Select;
1041 ------------------------------------
1042 -- Analyze_Conditional_Entry_Call --
1043 ------------------------------------
1045 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
1046 Trigger : constant Node_Id :=
1047 Entry_Call_Statement (Entry_Call_Alternative (N));
1048 Is_Disp_Select : Boolean := False;
1051 Tasking_Used := True;
1052 Check_SPARK_05_Restriction ("select statement is not allowed", N);
1053 Check_Restriction (No_Select_Statements, N);
1055 -- Ada 2005 (AI-345): The trigger may be a dispatching call
1057 if Ada_Version >= Ada_2005 then
1059 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1062 if List_Length (Else_Statements (N)) = 1
1063 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
1066 ("suspicious form of conditional entry call??!", N);
1068 ("\`SELECT OR` may be intended rather than `SELECT ELSE`??!", N);
1071 -- Postpone the analysis of the statements till expansion. Analyze only
1072 -- if the expander is disabled in order to catch any semantic errors.
1074 if Is_Disp_Select then
1075 if not Expander_Active then
1076 Analyze (Entry_Call_Alternative (N));
1077 Analyze_Statements (Else_Statements (N));
1080 -- Regular select analysis
1083 Analyze (Entry_Call_Alternative (N));
1084 Analyze_Statements (Else_Statements (N));
1086 end Analyze_Conditional_Entry_Call;
1088 --------------------------------
1089 -- Analyze_Delay_Alternative --
1090 --------------------------------
1092 procedure Analyze_Delay_Alternative (N : Node_Id) is
1097 Tasking_Used := True;
1098 Check_Restriction (No_Delay, N);
1100 if Present (Pragmas_Before (N)) then
1101 Analyze_List (Pragmas_Before (N));
1104 if Nkind_In (Parent (N), N_Selective_Accept, N_Timed_Entry_Call) then
1105 Expr := Expression (Delay_Statement (N));
1107 -- Defer full analysis until the statement is expanded, to insure
1108 -- that generated code does not move past the guard. The delay
1109 -- expression is only evaluated if the guard is open.
1111 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
1112 Preanalyze_And_Resolve (Expr, Standard_Duration);
1114 Preanalyze_And_Resolve (Expr);
1117 Typ := First_Subtype (Etype (Expr));
1119 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
1120 and then not Is_RTE (Typ, RO_CA_Time)
1121 and then not Is_RTE (Typ, RO_RT_Time)
1123 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
1126 Check_Restriction (No_Fixed_Point, Expr);
1129 Analyze (Delay_Statement (N));
1132 if Present (Condition (N)) then
1133 Analyze_And_Resolve (Condition (N), Any_Boolean);
1136 if Is_Non_Empty_List (Statements (N)) then
1137 Analyze_Statements (Statements (N));
1139 end Analyze_Delay_Alternative;
1141 ----------------------------
1142 -- Analyze_Delay_Relative --
1143 ----------------------------
1145 procedure Analyze_Delay_Relative (N : Node_Id) is
1146 E : constant Node_Id := Expression (N);
1148 Tasking_Used := True;
1149 Check_SPARK_05_Restriction ("delay statement is not allowed", N);
1150 Check_Restriction (No_Relative_Delay, N);
1151 Check_Restriction (No_Delay, N);
1152 Check_Potentially_Blocking_Operation (N);
1153 Analyze_And_Resolve (E, Standard_Duration);
1154 Check_Restriction (No_Fixed_Point, E);
1155 end Analyze_Delay_Relative;
1157 -------------------------
1158 -- Analyze_Delay_Until --
1159 -------------------------
1161 procedure Analyze_Delay_Until (N : Node_Id) is
1162 E : constant Node_Id := Expression (N);
1166 Tasking_Used := True;
1167 Check_SPARK_05_Restriction ("delay statement is not allowed", N);
1168 Check_Restriction (No_Delay, N);
1169 Check_Potentially_Blocking_Operation (N);
1171 Typ := First_Subtype (Etype (E));
1173 if not Is_RTE (Typ, RO_CA_Time) and then
1174 not Is_RTE (Typ, RO_RT_Time)
1176 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
1178 end Analyze_Delay_Until;
1180 ------------------------
1181 -- Analyze_Entry_Body --
1182 ------------------------
1184 procedure Analyze_Entry_Body (N : Node_Id) is
1185 Id : constant Entity_Id := Defining_Identifier (N);
1186 Decls : constant List_Id := Declarations (N);
1187 Stats : constant Node_Id := Handled_Statement_Sequence (N);
1188 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1189 P_Type : constant Entity_Id := Current_Scope;
1191 Entry_Name : Entity_Id;
1194 -- An entry body "freezes" the contract of the nearest enclosing
1195 -- package body. This ensures that any annotations referenced by the
1196 -- contract of an entry or subprogram body declared within the current
1197 -- protected body are available.
1199 Analyze_Enclosing_Package_Body_Contract (N);
1201 Tasking_Used := True;
1203 -- Entry_Name is initialized to Any_Id. It should get reset to the
1204 -- matching entry entity. An error is signalled if it is not reset.
1206 Entry_Name := Any_Id;
1210 if Present (Entry_Index_Specification (Formals)) then
1211 Set_Ekind (Id, E_Entry_Family);
1213 Set_Ekind (Id, E_Entry);
1216 Set_Scope (Id, Current_Scope);
1217 Set_Etype (Id, Standard_Void_Type);
1218 Set_Accept_Address (Id, New_Elmt_List);
1220 -- Set the SPARK_Mode from the current context (may be overwritten later
1221 -- with an explicit pragma).
1223 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1224 Set_SPARK_Pragma_Inherited (Id);
1226 E := First_Entity (P_Type);
1227 while Present (E) loop
1228 if Chars (E) = Chars (Id)
1229 and then (Ekind (E) = Ekind (Id))
1230 and then Type_Conformant (Id, E)
1233 Set_Convention (Id, Convention (E));
1234 Set_Corresponding_Body (Parent (E), Id);
1235 Check_Fully_Conformant (Id, E, N);
1237 if Ekind (Id) = E_Entry_Family then
1238 if not Fully_Conformant_Discrete_Subtypes (
1239 Discrete_Subtype_Definition (Parent (E)),
1240 Discrete_Subtype_Definition
1241 (Entry_Index_Specification (Formals)))
1244 ("index not fully conformant with previous declaration",
1245 Discrete_Subtype_Definition
1246 (Entry_Index_Specification (Formals)));
1249 -- The elaboration of the entry body does not recompute the
1250 -- bounds of the index, which may have side effects. Inherit
1251 -- the bounds from the entry declaration. This is critical
1252 -- if the entry has a per-object constraint. If a bound is
1253 -- given by a discriminant, it must be reanalyzed in order
1254 -- to capture the discriminal of the current entry, rather
1255 -- than that of the protected type.
1258 Index_Spec : constant Node_Id :=
1259 Entry_Index_Specification (Formals);
1261 Def : constant Node_Id :=
1263 (Discrete_Subtype_Definition (Parent (E)));
1268 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
1270 Set_Etype (Def, Empty);
1271 Set_Analyzed (Def, False);
1273 -- Keep the original subtree to ensure a properly
1274 -- formed tree (e.g. for ASIS use).
1277 (Discrete_Subtype_Definition (Index_Spec), Def);
1279 Set_Analyzed (Low_Bound (Def), False);
1280 Set_Analyzed (High_Bound (Def), False);
1282 if Denotes_Discriminant (Low_Bound (Def)) then
1283 Set_Entity (Low_Bound (Def), Empty);
1286 if Denotes_Discriminant (High_Bound (Def)) then
1287 Set_Entity (High_Bound (Def), Empty);
1291 Make_Index (Def, Index_Spec);
1293 (Defining_Identifier (Index_Spec), Etype (Def));
1305 if Entry_Name = Any_Id then
1306 Error_Msg_N ("no entry declaration matches entry body", N);
1309 elsif Has_Completion (Entry_Name) then
1310 Error_Msg_N ("duplicate entry body", N);
1314 Set_Has_Completion (Entry_Name);
1315 Generate_Reference (Entry_Name, Id, 'b', Set_Ref => False);
1316 Style.Check_Identifier (Id, Entry_Name);
1319 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
1320 Push_Scope (Entry_Name);
1322 Install_Declarations (Entry_Name);
1323 Set_Actual_Subtypes (N, Current_Scope);
1325 -- The entity for the protected subprogram corresponding to the entry
1326 -- has been created. We retain the name of this entity in the entry
1327 -- body, for use when the corresponding subprogram body is created.
1328 -- Note that entry bodies have no Corresponding_Spec, and there is no
1329 -- easy link back in the tree between the entry body and the entity for
1330 -- the entry itself, which is why we must propagate some attributes
1331 -- explicitly from spec to body.
1333 Set_Protected_Body_Subprogram
1334 (Id, Protected_Body_Subprogram (Entry_Name));
1336 Set_Entry_Parameters_Type
1337 (Id, Entry_Parameters_Type (Entry_Name));
1339 -- Add a declaration for the Protection object, renaming declarations
1340 -- for the discriminals and privals and finally a declaration for the
1341 -- entry family index (if applicable).
1344 and then Is_Protected_Type (P_Type)
1346 Install_Private_Data_Declarations
1347 (Sloc (N), Entry_Name, P_Type, N, Decls);
1350 if Present (Decls) then
1351 Analyze_Declarations (Decls);
1352 Inspect_Deferred_Constant_Completion (Decls);
1355 if Present (Stats) then
1359 -- Check for unreferenced variables etc. Before the Check_References
1360 -- call, we transfer Never_Set_In_Source and Referenced flags from
1361 -- parameters in the spec to the corresponding entities in the body,
1362 -- since we want the warnings on the body entities. Note that we do not
1363 -- have to transfer Referenced_As_LHS, since that flag can only be set
1364 -- for simple variables, but we include Has_Pragma_Unreferenced,
1365 -- which may have been specified for a formal in the body.
1367 -- At the same time, we set the flags on the spec entities to suppress
1368 -- any warnings on the spec formals, since we also scan the spec.
1369 -- Finally, we propagate the Entry_Component attribute to the body
1370 -- formals, for use in the renaming declarations created later for the
1371 -- formals (see exp_ch9.Add_Formal_Renamings).
1378 E1 := First_Entity (Entry_Name);
1379 while Present (E1) loop
1380 E2 := First_Entity (Id);
1381 while Present (E2) loop
1382 exit when Chars (E1) = Chars (E2);
1386 -- If no matching body entity, then we already had a detected
1387 -- error of some kind, so just don't worry about these warnings.
1393 if Ekind (E1) = E_Out_Parameter then
1394 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1395 Set_Never_Set_In_Source (E1, False);
1398 Set_Referenced (E2, Referenced (E1));
1399 Set_Referenced (E1);
1400 Set_Has_Pragma_Unreferenced (E2, Has_Pragma_Unreferenced (E1));
1401 Set_Entry_Component (E2, Entry_Component (E1));
1407 Check_References (Id);
1410 -- We still need to check references for the spec, since objects
1411 -- declared in the body are chained (in the First_Entity sense) to
1412 -- the spec rather than the body in the case of entries.
1414 Check_References (Entry_Name);
1416 -- Process the end label, and terminate the scope
1418 Process_End_Label (Handled_Statement_Sequence (N), 't', Entry_Name);
1421 -- If this is an entry family, remove the loop created to provide
1422 -- a scope for the entry index.
1424 if Ekind (Id) = E_Entry_Family
1425 and then Present (Entry_Index_Specification (Formals))
1429 end Analyze_Entry_Body;
1431 ------------------------------------
1432 -- Analyze_Entry_Body_Formal_Part --
1433 ------------------------------------
1435 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
1436 Id : constant Entity_Id := Defining_Identifier (Parent (N));
1437 Index : constant Node_Id := Entry_Index_Specification (N);
1438 Formals : constant List_Id := Parameter_Specifications (N);
1441 Tasking_Used := True;
1443 if Present (Index) then
1446 -- The entry index functions like a loop variable, thus it is known
1447 -- to have a valid value.
1449 Set_Is_Known_Valid (Defining_Identifier (Index));
1452 if Present (Formals) then
1453 Set_Scope (Id, Current_Scope);
1455 Process_Formals (Formals, Parent (N));
1458 end Analyze_Entry_Body_Formal_Part;
1460 ------------------------------------
1461 -- Analyze_Entry_Call_Alternative --
1462 ------------------------------------
1464 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
1465 Call : constant Node_Id := Entry_Call_Statement (N);
1468 Tasking_Used := True;
1469 Check_SPARK_05_Restriction ("entry call is not allowed", N);
1471 if Present (Pragmas_Before (N)) then
1472 Analyze_List (Pragmas_Before (N));
1475 if Nkind (Call) = N_Attribute_Reference then
1477 -- Possibly a stream attribute, but definitely illegal. Other
1478 -- illegalities, such as procedure calls, are diagnosed after
1481 Error_Msg_N ("entry call alternative requires an entry call", Call);
1487 -- An indirect call in this context is illegal. A procedure call that
1488 -- does not involve a renaming of an entry is illegal as well, but this
1489 -- and other semantic errors are caught during resolution.
1491 if Nkind (Call) = N_Explicit_Dereference then
1493 ("entry call or dispatching primitive of interface required ", N);
1496 if Is_Non_Empty_List (Statements (N)) then
1497 Analyze_Statements (Statements (N));
1499 end Analyze_Entry_Call_Alternative;
1501 -------------------------------
1502 -- Analyze_Entry_Declaration --
1503 -------------------------------
1505 procedure Analyze_Entry_Declaration (N : Node_Id) is
1506 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
1507 Def_Id : constant Entity_Id := Defining_Identifier (N);
1508 Formals : constant List_Id := Parameter_Specifications (N);
1511 Generate_Definition (Def_Id);
1513 Tasking_Used := True;
1515 -- Case of no discrete subtype definition
1518 Set_Ekind (Def_Id, E_Entry);
1520 -- Processing for discrete subtype definition present
1523 Enter_Name (Def_Id);
1524 Set_Ekind (Def_Id, E_Entry_Family);
1526 Make_Index (D_Sdef, N, Def_Id);
1528 -- Check subtype with predicate in entry family
1530 Bad_Predicated_Subtype_Use
1531 ("subtype& has predicate, not allowed in entry family",
1532 D_Sdef, Etype (D_Sdef));
1534 -- Check entry family static bounds outside allowed limits
1536 -- Note: originally this check was not performed here, but in that
1537 -- case the check happens deep in the expander, and the message is
1538 -- posted at the wrong location, and omitted in -gnatc mode.
1539 -- If the type of the entry index is a generic formal, no check
1540 -- is possible. In an instance, the check is not static and a run-
1541 -- time exception will be raised if the bounds are unreasonable.
1544 PEI : constant Entity_Id := RTE (RE_Protected_Entry_Index);
1545 LB : constant Uint := Expr_Value (Type_Low_Bound (PEI));
1546 UB : constant Uint := Expr_Value (Type_High_Bound (PEI));
1553 -- No bounds checking if the type is generic or if previous error.
1554 -- In an instance the check is dynamic.
1556 if Is_Generic_Type (Etype (D_Sdef))
1558 or else Error_Posted (D_Sdef)
1562 elsif Nkind (D_Sdef) = N_Range then
1563 LBR := Low_Bound (D_Sdef);
1565 elsif Is_Entity_Name (D_Sdef)
1566 and then Is_Type (Entity (D_Sdef))
1568 LBR := Type_Low_Bound (Entity (D_Sdef));
1574 if Is_OK_Static_Expression (LBR)
1575 and then Expr_Value (LBR) < LB
1577 Error_Msg_Uint_1 := LB;
1578 Error_Msg_N ("entry family low bound must be '>'= ^!", D_Sdef);
1582 if Is_Generic_Type (Etype (D_Sdef))
1584 or else Error_Posted (D_Sdef)
1588 elsif Nkind (D_Sdef) = N_Range then
1589 UBR := High_Bound (D_Sdef);
1591 elsif Is_Entity_Name (D_Sdef)
1592 and then Is_Type (Entity (D_Sdef))
1594 UBR := Type_High_Bound (Entity (D_Sdef));
1600 if Is_OK_Static_Expression (UBR)
1601 and then Expr_Value (UBR) > UB
1603 Error_Msg_Uint_1 := UB;
1604 Error_Msg_N ("entry family high bound must be '<'= ^!", D_Sdef);
1614 Set_Etype (Def_Id, Standard_Void_Type);
1615 Set_Convention (Def_Id, Convention_Entry);
1616 Set_Accept_Address (Def_Id, New_Elmt_List);
1618 -- Set the SPARK_Mode from the current context (may be overwritten later
1619 -- with an explicit pragma). Task entries are excluded because they are
1620 -- not completed by entry bodies.
1622 if Ekind (Current_Scope) = E_Protected_Type then
1623 Set_SPARK_Pragma (Def_Id, SPARK_Mode_Pragma);
1624 Set_SPARK_Pragma_Inherited (Def_Id);
1629 if Present (Formals) then
1630 Set_Scope (Def_Id, Current_Scope);
1631 Push_Scope (Def_Id);
1632 Process_Formals (Formals, N);
1633 Create_Extra_Formals (Def_Id);
1637 if Ekind (Def_Id) = E_Entry then
1638 New_Overloaded_Entity (Def_Id);
1641 Generate_Reference_To_Formals (Def_Id);
1643 if Has_Aspects (N) then
1644 Analyze_Aspect_Specifications (N, Def_Id);
1646 end Analyze_Entry_Declaration;
1648 ---------------------------------------
1649 -- Analyze_Entry_Index_Specification --
1650 ---------------------------------------
1652 -- The Defining_Identifier of the entry index specification is local to the
1653 -- entry body, but it must be available in the entry barrier which is
1654 -- evaluated outside of the entry body. The index is eventually renamed as
1655 -- a run-time object, so is visibility is strictly a front-end concern. In
1656 -- order to make it available to the barrier, we create an additional
1657 -- scope, as for a loop, whose only declaration is the index name. This
1658 -- loop is not attached to the tree and does not appear as an entity local
1659 -- to the protected type, so its existence need only be known to routines
1660 -- that process entry families.
1662 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
1663 Iden : constant Node_Id := Defining_Identifier (N);
1664 Def : constant Node_Id := Discrete_Subtype_Definition (N);
1665 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L');
1668 Tasking_Used := True;
1671 -- There is no elaboration of the entry index specification. Therefore,
1672 -- if the index is a range, it is not resolved and expanded, but the
1673 -- bounds are inherited from the entry declaration, and reanalyzed.
1674 -- See Analyze_Entry_Body.
1676 if Nkind (Def) /= N_Range then
1677 Make_Index (Def, N);
1680 Set_Ekind (Loop_Id, E_Loop);
1681 Set_Scope (Loop_Id, Current_Scope);
1682 Push_Scope (Loop_Id);
1684 Set_Ekind (Iden, E_Entry_Index_Parameter);
1685 Set_Etype (Iden, Etype (Def));
1686 end Analyze_Entry_Index_Specification;
1688 ----------------------------
1689 -- Analyze_Protected_Body --
1690 ----------------------------
1692 procedure Analyze_Protected_Body (N : Node_Id) is
1693 Body_Id : constant Entity_Id := Defining_Identifier (N);
1696 Spec_Id : Entity_Id;
1697 -- This is initially the entity of the protected object or protected
1698 -- type involved, but is replaced by the protected type always in the
1699 -- case of a single protected declaration, since this is the proper
1700 -- scope to be used.
1703 -- This is the entity of the protected object or protected type
1704 -- involved, and is the entity used for cross-reference purposes (it
1705 -- differs from Spec_Id in the case of a single protected object, since
1706 -- Spec_Id is set to the protected type in this case).
1708 function Lock_Free_Disabled return Boolean;
1709 -- This routine returns False if the protected object has a Lock_Free
1710 -- aspect specification or a Lock_Free pragma that turns off the
1711 -- lock-free implementation (e.g. whose expression is False).
1713 ------------------------
1714 -- Lock_Free_Disabled --
1715 ------------------------
1717 function Lock_Free_Disabled return Boolean is
1718 Ritem : constant Node_Id :=
1720 (Spec_Id, Name_Lock_Free, Check_Parents => False);
1723 if Present (Ritem) then
1725 -- Pragma with one argument
1727 if Nkind (Ritem) = N_Pragma
1728 and then Present (Pragma_Argument_Associations (Ritem))
1734 (First (Pragma_Argument_Associations (Ritem)))));
1736 -- Aspect Specification with expression present
1738 elsif Nkind (Ritem) = N_Aspect_Specification
1739 and then Present (Expression (Ritem))
1741 return Is_False (Static_Boolean (Expression (Ritem)));
1743 -- Otherwise, return False
1751 end Lock_Free_Disabled;
1753 -- Start of processing for Analyze_Protected_Body
1756 -- A protected body "freezes" the contract of the nearest enclosing
1757 -- package body. This ensures that any annotations referenced by the
1758 -- contract of an entry or subprogram body declared within the current
1759 -- protected body are available.
1761 Analyze_Enclosing_Package_Body_Contract (N);
1763 Tasking_Used := True;
1764 Set_Ekind (Body_Id, E_Protected_Body);
1765 Set_Etype (Body_Id, Standard_Void_Type);
1766 Spec_Id := Find_Concurrent_Spec (Body_Id);
1768 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Protected_Type then
1771 elsif Present (Spec_Id)
1772 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1773 and then not Comes_From_Source (Etype (Spec_Id))
1778 Error_Msg_N ("missing specification for protected body", Body_Id);
1783 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
1784 Style.Check_Identifier (Body_Id, Spec_Id);
1786 -- The declarations are always attached to the type
1788 if Ekind (Spec_Id) /= E_Protected_Type then
1789 Spec_Id := Etype (Spec_Id);
1792 if Has_Aspects (N) then
1793 Analyze_Aspect_Specifications (N, Body_Id);
1796 Push_Scope (Spec_Id);
1797 Set_Corresponding_Spec (N, Spec_Id);
1798 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1799 Set_Has_Completion (Spec_Id);
1800 Install_Declarations (Spec_Id);
1802 Expand_Protected_Body_Declarations (N, Spec_Id);
1804 Last_E := Last_Entity (Spec_Id);
1806 Analyze_Declarations (Declarations (N));
1808 -- For visibility purposes, all entities in the body are private. Set
1809 -- First_Private_Entity accordingly, if there was no private part in the
1810 -- protected declaration.
1812 if No (First_Private_Entity (Spec_Id)) then
1813 if Present (Last_E) then
1814 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1816 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1820 Check_Completion (Body_Id);
1821 Check_References (Spec_Id);
1822 Process_End_Label (N, 't', Ref_Id);
1825 -- When a Lock_Free aspect specification/pragma forces the lock-free
1826 -- implementation, verify the protected body meets all the restrictions,
1827 -- otherwise Allows_Lock_Free_Implementation issues an error message.
1829 if Uses_Lock_Free (Spec_Id) then
1830 if not Allows_Lock_Free_Implementation (N, True) then
1834 -- In other cases, if there is no aspect specification/pragma that
1835 -- disables the lock-free implementation, check both the protected
1836 -- declaration and body satisfy the lock-free restrictions.
1838 elsif not Lock_Free_Disabled
1839 and then Allows_Lock_Free_Implementation (Parent (Spec_Id))
1840 and then Allows_Lock_Free_Implementation (N)
1842 Set_Uses_Lock_Free (Spec_Id);
1844 end Analyze_Protected_Body;
1846 ----------------------------------
1847 -- Analyze_Protected_Definition --
1848 ----------------------------------
1850 procedure Analyze_Protected_Definition (N : Node_Id) is
1854 procedure Undelay_Itypes (T : Entity_Id);
1855 -- Itypes created for the private components of a protected type
1856 -- do not receive freeze nodes, because there is no scope in which
1857 -- they can be elaborated, and they can depend on discriminants of
1858 -- the enclosed protected type. Given that the components can be
1859 -- composite types with inner components, we traverse recursively
1860 -- the private components of the protected type, and indicate that
1861 -- all itypes within are frozen. This ensures that no freeze nodes
1862 -- will be generated for them.
1864 -- On the other hand, components of the corresponding record are
1865 -- frozen (or receive itype references) as for other records.
1867 --------------------
1868 -- Undelay_Itypes --
1869 --------------------
1871 procedure Undelay_Itypes (T : Entity_Id) is
1875 if Is_Protected_Type (T) then
1876 Comp := First_Private_Entity (T);
1877 elsif Is_Record_Type (T) then
1878 Comp := First_Entity (T);
1883 while Present (Comp) loop
1885 and then Is_Itype (Comp)
1887 Set_Has_Delayed_Freeze (Comp, False);
1888 Set_Is_Frozen (Comp);
1890 if Is_Record_Type (Comp)
1891 or else Is_Protected_Type (Comp)
1893 Undelay_Itypes (Comp);
1901 -- Start of processing for Analyze_Protected_Definition
1904 Tasking_Used := True;
1905 Check_SPARK_05_Restriction ("protected definition is not allowed", N);
1906 Analyze_Declarations (Visible_Declarations (N));
1908 if Present (Private_Declarations (N))
1909 and then not Is_Empty_List (Private_Declarations (N))
1911 L := Last_Entity (Current_Scope);
1912 Analyze_Declarations (Private_Declarations (N));
1915 Set_First_Private_Entity (Current_Scope, Next_Entity (L));
1917 Set_First_Private_Entity (Current_Scope,
1918 First_Entity (Current_Scope));
1922 E := First_Entity (Current_Scope);
1923 while Present (E) loop
1924 if Ekind_In (E, E_Function, E_Procedure) then
1925 Set_Convention (E, Convention_Protected);
1927 elsif Is_Task_Type (Etype (E))
1928 or else Has_Task (Etype (E))
1930 Set_Has_Task (Current_Scope);
1932 elsif Is_Protected_Type (Etype (E))
1933 or else Has_Protected (Etype (E))
1935 Set_Has_Protected (Current_Scope);
1941 Undelay_Itypes (Current_Scope);
1943 Check_Max_Entries (N, Max_Protected_Entries);
1944 Process_End_Label (N, 'e', Current_Scope);
1945 end Analyze_Protected_Definition;
1947 ----------------------------------------
1948 -- Analyze_Protected_Type_Declaration --
1949 ----------------------------------------
1951 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
1952 Def_Id : constant Entity_Id := Defining_Identifier (N);
1957 if No_Run_Time_Mode then
1958 Error_Msg_CRT ("protected type", N);
1960 if Has_Aspects (N) then
1961 Analyze_Aspect_Specifications (N, Def_Id);
1967 Tasking_Used := True;
1968 Check_Restriction (No_Protected_Types, N);
1970 T := Find_Type_Name (N);
1972 -- In the case of an incomplete type, use the full view, unless it's not
1973 -- present (as can occur for an incomplete view from a limited with).
1975 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
1977 Set_Completion_Referenced (T);
1980 Set_Ekind (T, E_Protected_Type);
1981 Set_Is_First_Subtype (T, True);
1982 Set_Has_Protected (T, True);
1983 Init_Size_Align (T);
1985 Set_Has_Delayed_Freeze (T, True);
1986 Set_Stored_Constraint (T, No_Elist);
1988 -- Set the SPARK_Mode from the current context (may be overwritten later
1989 -- with an explicit pragma).
1991 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
1992 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
1993 Set_SPARK_Pragma_Inherited (T);
1994 Set_SPARK_Aux_Pragma_Inherited (T);
1998 if Ada_Version >= Ada_2005 then
1999 Check_Interfaces (N, T);
2002 if Present (Discriminant_Specifications (N)) then
2003 if Has_Discriminants (T) then
2005 -- Install discriminants. Also, verify conformance of
2006 -- discriminants of previous and current view. ???
2008 Install_Declarations (T);
2010 Process_Discriminants (N);
2014 Set_Is_Constrained (T, not Has_Discriminants (T));
2016 -- If aspects are present, analyze them now. They can make references
2017 -- to the discriminants of the type, but not to any components.
2019 if Has_Aspects (N) then
2020 Analyze_Aspect_Specifications (N, Def_Id);
2023 Analyze (Protected_Definition (N));
2025 -- In the case where the protected type is declared at a nested level
2026 -- and the No_Local_Protected_Objects restriction applies, issue a
2027 -- warning that objects of the type will violate the restriction.
2029 if Restriction_Check_Required (No_Local_Protected_Objects)
2030 and then not Is_Library_Level_Entity (T)
2031 and then Comes_From_Source (T)
2033 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
2035 if Error_Msg_Sloc = No_Location then
2037 ("objects of this type will violate " &
2038 "`No_Local_Protected_Objects`??", N);
2041 ("objects of this type will violate " &
2042 "`No_Local_Protected_Objects`#??", N);
2046 -- Protected types with entries are controlled (because of the
2047 -- Protection component if nothing else), same for any protected type
2048 -- with interrupt handlers. Note that we need to analyze the protected
2049 -- definition to set Has_Entries and such.
2051 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
2052 or else Number_Entries (T) > 1)
2055 or else Has_Interrupt_Handler (T)
2056 or else Has_Attach_Handler (T))
2058 Set_Has_Controlled_Component (T, True);
2061 -- The Ekind of components is E_Void during analysis to detect illegal
2062 -- uses. Now it can be set correctly.
2064 E := First_Entity (Current_Scope);
2065 while Present (E) loop
2066 if Ekind (E) = E_Void then
2067 Set_Ekind (E, E_Component);
2068 Init_Component_Location (E);
2076 -- When a Lock_Free aspect forces the lock-free implementation, check N
2077 -- meets all the lock-free restrictions. Otherwise, an error message is
2078 -- issued by Allows_Lock_Free_Implementation.
2080 if Uses_Lock_Free (Defining_Identifier (N)) then
2082 -- Complain when there is an explicit aspect/pragma Priority (or
2083 -- Interrupt_Priority) while the lock-free implementation is forced
2084 -- by an aspect/pragma.
2087 Id : constant Entity_Id := Defining_Identifier (Original_Node (N));
2088 -- The warning must be issued on the original identifier in order
2089 -- to deal properly with the case of a single protected object.
2091 Prio_Item : constant Node_Id :=
2092 Get_Rep_Item (Def_Id, Name_Priority, False);
2095 if Present (Prio_Item) then
2099 if Nkind (Prio_Item) = N_Aspect_Specification
2100 or else From_Aspect_Specification (Prio_Item)
2102 Error_Msg_Name_1 := Chars (Identifier (Prio_Item));
2103 Error_Msg_NE ("aspect% for & has no effect when Lock_Free" &
2104 " given??", Prio_Item, Id);
2109 Error_Msg_Name_1 := Pragma_Name (Prio_Item);
2110 Error_Msg_NE ("pragma% for & has no effect when Lock_Free" &
2111 " given??", Prio_Item, Id);
2116 if not Allows_Lock_Free_Implementation (N, True) then
2121 -- If the Attach_Handler aspect is specified or the Interrupt_Handler
2122 -- aspect is True, then the initial ceiling priority must be in the
2123 -- range of System.Interrupt_Priority. It is therefore recommanded
2124 -- to use the Interrupt_Priority aspect instead of the Priority aspect.
2126 if Has_Interrupt_Handler (T) or else Has_Attach_Handler (T) then
2128 Prio_Item : constant Node_Id :=
2129 Get_Rep_Item (Def_Id, Name_Priority, False);
2132 if Present (Prio_Item) then
2136 if (Nkind (Prio_Item) = N_Aspect_Specification
2137 or else From_Aspect_Specification (Prio_Item))
2138 and then Chars (Identifier (Prio_Item)) = Name_Priority
2140 Error_Msg_N ("aspect Interrupt_Priority is preferred "
2141 & "in presence of handlers??", Prio_Item);
2145 elsif Nkind (Prio_Item) = N_Pragma
2146 and then Pragma_Name (Prio_Item) = Name_Priority
2148 Error_Msg_N ("pragma Interrupt_Priority is preferred "
2149 & "in presence of handlers??", Prio_Item);
2155 -- Case of a completion of a private declaration
2157 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2159 -- Deal with preelaborable initialization. Note that this processing
2160 -- is done by Process_Full_View, but as can be seen below, in this
2161 -- case the call to Process_Full_View is skipped if any serious
2162 -- errors have occurred, and we don't want to lose this check.
2164 if Known_To_Have_Preelab_Init (Def_Id) then
2165 Set_Must_Have_Preelab_Init (T);
2168 -- Create corresponding record now, because some private dependents
2169 -- may be subtypes of the partial view.
2171 -- Skip if errors are present, to prevent cascaded messages
2173 if Serious_Errors_Detected = 0
2175 -- Also skip if expander is not active
2177 and then Expander_Active
2179 Expand_N_Protected_Type_Declaration (N);
2180 Process_Full_View (N, T, Def_Id);
2183 end Analyze_Protected_Type_Declaration;
2185 ---------------------
2186 -- Analyze_Requeue --
2187 ---------------------
2189 procedure Analyze_Requeue (N : Node_Id) is
2190 Count : Natural := 0;
2191 Entry_Name : Node_Id := Name (N);
2192 Entry_Id : Entity_Id;
2194 Is_Disp_Req : Boolean;
2196 Enclosing : Entity_Id;
2197 Target_Obj : Node_Id := Empty;
2198 Req_Scope : Entity_Id;
2199 Outer_Ent : Entity_Id;
2200 Synch_Type : Entity_Id;
2203 Tasking_Used := True;
2204 Check_SPARK_05_Restriction ("requeue statement is not allowed", N);
2205 Check_Restriction (No_Requeue_Statements, N);
2206 Check_Unreachable_Code (N);
2209 for J in reverse 0 .. Scope_Stack.Last loop
2210 Enclosing := Scope_Stack.Table (J).Entity;
2211 exit when Is_Entry (Enclosing);
2213 if not Ekind_In (Enclosing, E_Block, E_Loop) then
2214 Error_Msg_N ("requeue must appear within accept or entry body", N);
2219 Analyze (Entry_Name);
2221 if Etype (Entry_Name) = Any_Type then
2225 if Nkind (Entry_Name) = N_Selected_Component then
2226 Target_Obj := Prefix (Entry_Name);
2227 Entry_Name := Selector_Name (Entry_Name);
2230 -- If an explicit target object is given then we have to check the
2231 -- restrictions of 9.5.4(6).
2233 if Present (Target_Obj) then
2235 -- Locate containing concurrent unit and determine enclosing entry
2236 -- body or outermost enclosing accept statement within the unit.
2239 for S in reverse 0 .. Scope_Stack.Last loop
2240 Req_Scope := Scope_Stack.Table (S).Entity;
2242 exit when Ekind (Req_Scope) in Task_Kind
2243 or else Ekind (Req_Scope) in Protected_Kind;
2245 if Is_Entry (Req_Scope) then
2246 Outer_Ent := Req_Scope;
2250 pragma Assert (Present (Outer_Ent));
2252 -- Check that the accessibility level of the target object is not
2253 -- greater or equal to the outermost enclosing accept statement (or
2254 -- entry body) unless it is a parameter of the innermost enclosing
2255 -- accept statement (or entry body).
2257 if Object_Access_Level (Target_Obj) >= Scope_Depth (Outer_Ent)
2259 (not Is_Entity_Name (Target_Obj)
2260 or else Ekind (Entity (Target_Obj)) not in Formal_Kind
2261 or else Enclosing /= Scope (Entity (Target_Obj)))
2264 ("target object has invalid level for requeue", Target_Obj);
2268 -- Overloaded case, find right interpretation
2270 if Is_Overloaded (Entry_Name) then
2273 -- Loop over candidate interpretations and filter out any that are
2274 -- not parameterless, are not type conformant, are not entries, or
2275 -- do not come from source.
2277 Get_First_Interp (Entry_Name, I, It);
2278 while Present (It.Nam) loop
2280 -- Note: we test type conformance here, not subtype conformance.
2281 -- Subtype conformance will be tested later on, but it is better
2282 -- for error output in some cases not to do that here.
2284 if (No (First_Formal (It.Nam))
2285 or else (Type_Conformant (Enclosing, It.Nam)))
2286 and then Ekind (It.Nam) = E_Entry
2288 -- Ada 2005 (AI-345): Since protected and task types have
2289 -- primitive entry wrappers, we only consider source entries.
2291 if Comes_From_Source (It.Nam) then
2299 Get_Next_Interp (I, It);
2303 Error_Msg_N ("no entry matches context", N);
2306 elsif Count > 1 then
2307 Error_Msg_N ("ambiguous entry name in requeue", N);
2311 Set_Is_Overloaded (Entry_Name, False);
2312 Set_Entity (Entry_Name, Entry_Id);
2315 -- Non-overloaded cases
2317 -- For the case of a reference to an element of an entry family, the
2318 -- Entry_Name is an indexed component.
2320 elsif Nkind (Entry_Name) = N_Indexed_Component then
2322 -- Requeue to an entry out of the body
2324 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
2325 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
2327 -- Requeue from within the body itself
2329 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
2330 Entry_Id := Entity (Prefix (Entry_Name));
2333 Error_Msg_N ("invalid entry_name specified", N);
2337 -- If we had a requeue of the form REQUEUE A (B), then the parser
2338 -- accepted it (because it could have been a requeue on an entry index.
2339 -- If A turns out not to be an entry family, then the analysis of A (B)
2340 -- turned it into a function call.
2342 elsif Nkind (Entry_Name) = N_Function_Call then
2344 ("arguments not allowed in requeue statement",
2345 First (Parameter_Associations (Entry_Name)));
2348 -- Normal case of no entry family, no argument
2351 Entry_Id := Entity (Entry_Name);
2354 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
2355 -- target type must be a concurrent interface class-wide type and the
2356 -- target must be a procedure, flagged by pragma Implemented. The
2357 -- target may be an access to class-wide type, in which case it must
2360 if Present (Target_Obj) then
2361 Synch_Type := Etype (Target_Obj);
2363 if Is_Access_Type (Synch_Type) then
2364 Synch_Type := Designated_Type (Synch_Type);
2369 Ada_Version >= Ada_2012
2370 and then Present (Target_Obj)
2371 and then Is_Class_Wide_Type (Synch_Type)
2372 and then Is_Concurrent_Interface (Synch_Type)
2373 and then Ekind (Entry_Id) = E_Procedure
2374 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
2376 -- Resolve entry, and check that it is subtype conformant with the
2377 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
2378 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
2380 if not Is_Entry (Entry_Id)
2381 and then not Is_Disp_Req
2383 Error_Msg_N ("expect entry name in requeue statement", Name (N));
2385 elsif Ekind (Entry_Id) = E_Entry_Family
2386 and then Nkind (Entry_Name) /= N_Indexed_Component
2388 Error_Msg_N ("missing index for entry family component", Name (N));
2391 Resolve_Entry (Name (N));
2392 Generate_Reference (Entry_Id, Entry_Name);
2394 if Present (First_Formal (Entry_Id)) then
2396 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
2397 -- the first parameter of Entry_Id since it is the interface
2398 -- controlling formal.
2400 if Ada_Version >= Ada_2012 and then Is_Disp_Req then
2402 Enclosing_Formal : Entity_Id;
2403 Target_Formal : Entity_Id;
2406 Enclosing_Formal := First_Formal (Enclosing);
2407 Target_Formal := Next_Formal (First_Formal (Entry_Id));
2408 while Present (Enclosing_Formal)
2409 and then Present (Target_Formal)
2411 if not Conforming_Types
2412 (T1 => Etype (Enclosing_Formal),
2413 T2 => Etype (Target_Formal),
2414 Ctype => Subtype_Conformant)
2416 Error_Msg_Node_2 := Target_Formal;
2418 ("formal & is not subtype conformant with &" &
2419 "in dispatching requeue", N, Enclosing_Formal);
2422 Next_Formal (Enclosing_Formal);
2423 Next_Formal (Target_Formal);
2427 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
2430 -- Processing for parameters accessed by the requeue
2436 Ent := First_Formal (Enclosing);
2437 while Present (Ent) loop
2439 -- For OUT or IN OUT parameter, the effect of the requeue is
2440 -- to assign the parameter a value on exit from the requeued
2441 -- body, so we can set it as source assigned. We also clear
2442 -- the Is_True_Constant indication. We do not need to clear
2443 -- Current_Value, since the effect of the requeue is to
2444 -- perform an unconditional goto so that any further
2445 -- references will not occur anyway.
2447 if Ekind_In (Ent, E_Out_Parameter, E_In_Out_Parameter) then
2448 Set_Never_Set_In_Source (Ent, False);
2449 Set_Is_True_Constant (Ent, False);
2452 -- For all parameters, the requeue acts as a reference,
2453 -- since the value of the parameter is passed to the new
2454 -- entry, so we want to suppress unreferenced warnings.
2456 Set_Referenced (Ent);
2463 -- AI05-0225: the target protected object of a requeue must be a
2464 -- variable. This is a binding interpretation that applies to all
2465 -- versions of the language. Note that the subprogram does not have
2466 -- to be a protected operation: it can be an primitive implemented
2467 -- by entry with a formal that is a protected interface.
2469 if Present (Target_Obj)
2470 and then not Is_Variable (Target_Obj)
2473 ("target protected object of requeue must be a variable", N);
2475 end Analyze_Requeue;
2477 ------------------------------
2478 -- Analyze_Selective_Accept --
2479 ------------------------------
2481 procedure Analyze_Selective_Accept (N : Node_Id) is
2482 Alts : constant List_Id := Select_Alternatives (N);
2485 Accept_Present : Boolean := False;
2486 Terminate_Present : Boolean := False;
2487 Delay_Present : Boolean := False;
2488 Relative_Present : Boolean := False;
2489 Alt_Count : Uint := Uint_0;
2492 Tasking_Used := True;
2493 Check_SPARK_05_Restriction ("select statement is not allowed", N);
2494 Check_Restriction (No_Select_Statements, N);
2496 -- Loop to analyze alternatives
2498 Alt := First (Alts);
2499 while Present (Alt) loop
2500 Alt_Count := Alt_Count + 1;
2503 if Nkind (Alt) = N_Delay_Alternative then
2504 if Delay_Present then
2506 if Relative_Present /=
2507 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
2510 ("delay_until and delay_relative alternatives ", Alt);
2512 ("\cannot appear in the same selective_wait", Alt);
2516 Delay_Present := True;
2518 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
2521 elsif Nkind (Alt) = N_Terminate_Alternative then
2522 if Terminate_Present then
2523 Error_Msg_N ("only one terminate alternative allowed", N);
2525 Terminate_Present := True;
2526 Check_Restriction (No_Terminate_Alternatives, N);
2529 elsif Nkind (Alt) = N_Accept_Alternative then
2530 Accept_Present := True;
2532 -- Check for duplicate accept
2536 Stm : constant Node_Id := Accept_Statement (Alt);
2537 EDN : constant Node_Id := Entry_Direct_Name (Stm);
2541 if Nkind (EDN) = N_Identifier
2542 and then No (Condition (Alt))
2543 and then Present (Entity (EDN)) -- defend against junk
2544 and then Ekind (Entity (EDN)) = E_Entry
2546 Ent := Entity (EDN);
2548 Alt1 := First (Alts);
2549 while Alt1 /= Alt loop
2550 if Nkind (Alt1) = N_Accept_Alternative
2551 and then No (Condition (Alt1))
2554 Stm1 : constant Node_Id := Accept_Statement (Alt1);
2555 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
2558 if Nkind (EDN1) = N_Identifier then
2559 if Entity (EDN1) = Ent then
2560 Error_Msg_Sloc := Sloc (Stm1);
2562 ("accept duplicates one on line#??", Stm);
2578 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
2579 Check_Potentially_Blocking_Operation (N);
2581 if Terminate_Present and Delay_Present then
2582 Error_Msg_N ("at most one of terminate or delay alternative", N);
2584 elsif not Accept_Present then
2586 ("select must contain at least one accept alternative", N);
2589 if Present (Else_Statements (N)) then
2590 if Terminate_Present or Delay_Present then
2591 Error_Msg_N ("else part not allowed with other alternatives", N);
2594 Analyze_Statements (Else_Statements (N));
2596 end Analyze_Selective_Accept;
2598 ------------------------------------------
2599 -- Analyze_Single_Protected_Declaration --
2600 ------------------------------------------
2602 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
2603 Loc : constant Source_Ptr := Sloc (N);
2604 Id : constant Node_Id := Defining_Identifier (N);
2608 O_Name : constant Entity_Id := Id;
2611 Generate_Definition (Id);
2612 Tasking_Used := True;
2614 -- The node is rewritten as a protected type declaration, in exact
2615 -- analogy with what is done with single tasks.
2618 Make_Defining_Identifier (Sloc (Id),
2619 New_External_Name (Chars (Id), 'T'));
2622 Make_Protected_Type_Declaration (Loc,
2623 Defining_Identifier => T,
2624 Protected_Definition => Relocate_Node (Protected_Definition (N)),
2625 Interface_List => Interface_List (N));
2628 Make_Object_Declaration (Loc,
2629 Defining_Identifier => O_Name,
2630 Object_Definition => Make_Identifier (Loc, Chars (T)));
2632 Rewrite (N, T_Decl);
2633 Insert_After (N, O_Decl);
2634 Mark_Rewrite_Insertion (O_Decl);
2636 -- Enter names of type and object before analysis, because the name of
2637 -- the object may be used in its own body.
2640 Set_Ekind (T, E_Protected_Type);
2643 Enter_Name (O_Name);
2644 Set_Ekind (O_Name, E_Variable);
2645 Set_Etype (O_Name, T);
2647 -- Instead of calling Analyze on the new node, call the proper analysis
2648 -- procedure directly. Otherwise the node would be expanded twice, with
2649 -- disastrous result.
2651 Analyze_Protected_Type_Declaration (N);
2653 if Has_Aspects (N) then
2654 Analyze_Aspect_Specifications (N, Id);
2656 end Analyze_Single_Protected_Declaration;
2658 -------------------------------------
2659 -- Analyze_Single_Task_Declaration --
2660 -------------------------------------
2662 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
2663 Loc : constant Source_Ptr := Sloc (N);
2664 Id : constant Node_Id := Defining_Identifier (N);
2668 O_Name : constant Entity_Id := Id;
2671 Generate_Definition (Id);
2672 Tasking_Used := True;
2674 -- The node is rewritten as a task type declaration, followed by an
2675 -- object declaration of that anonymous task type.
2678 Make_Defining_Identifier (Sloc (Id),
2679 New_External_Name (Chars (Id), Suffix => "TK"));
2682 Make_Task_Type_Declaration (Loc,
2683 Defining_Identifier => T,
2684 Task_Definition => Relocate_Node (Task_Definition (N)),
2685 Interface_List => Interface_List (N));
2687 -- We use the original defining identifier of the single task in the
2688 -- generated object declaration, so that debugging information can
2689 -- be attached to it when compiling with -gnatD. The parent of the
2690 -- entity is the new object declaration. The single_task_declaration
2691 -- is not used further in semantics or code generation, but is scanned
2692 -- when generating debug information, and therefore needs the updated
2693 -- Sloc information for the entity (see Sprint). Aspect specifications
2694 -- are moved from the single task node to the object declaration node.
2697 Make_Object_Declaration (Loc,
2698 Defining_Identifier => O_Name,
2699 Object_Definition => Make_Identifier (Loc, Chars (T)));
2701 Rewrite (N, T_Decl);
2702 Insert_After (N, O_Decl);
2703 Mark_Rewrite_Insertion (O_Decl);
2705 -- Enter names of type and object before analysis, because the name of
2706 -- the object may be used in its own body.
2709 Set_Ekind (T, E_Task_Type);
2712 Enter_Name (O_Name);
2713 Set_Ekind (O_Name, E_Variable);
2714 Set_Etype (O_Name, T);
2716 -- Instead of calling Analyze on the new node, call the proper analysis
2717 -- procedure directly. Otherwise the node would be expanded twice, with
2718 -- disastrous result.
2720 Analyze_Task_Type_Declaration (N);
2722 if Has_Aspects (N) then
2723 Analyze_Aspect_Specifications (N, Id);
2725 end Analyze_Single_Task_Declaration;
2727 -----------------------
2728 -- Analyze_Task_Body --
2729 -----------------------
2731 procedure Analyze_Task_Body (N : Node_Id) is
2732 Body_Id : constant Entity_Id := Defining_Identifier (N);
2733 Decls : constant List_Id := Declarations (N);
2734 HSS : constant Node_Id := Handled_Statement_Sequence (N);
2737 Spec_Id : Entity_Id;
2738 -- This is initially the entity of the task or task type involved, but
2739 -- is replaced by the task type always in the case of a single task
2740 -- declaration, since this is the proper scope to be used.
2743 -- This is the entity of the task or task type, and is the entity used
2744 -- for cross-reference purposes (it differs from Spec_Id in the case of
2745 -- a single task, since Spec_Id is set to the task type).
2748 -- A task body "freezes" the contract of the nearest enclosing package
2749 -- body. This ensures that any annotations referenced by the contract
2750 -- of an entry or subprogram body declared within the current protected
2751 -- body are available.
2753 Analyze_Enclosing_Package_Body_Contract (N);
2755 Tasking_Used := True;
2756 Set_Scope (Body_Id, Current_Scope);
2757 Set_Ekind (Body_Id, E_Task_Body);
2758 Set_Etype (Body_Id, Standard_Void_Type);
2759 Spec_Id := Find_Concurrent_Spec (Body_Id);
2761 -- The spec is either a task type declaration, or a single task
2762 -- declaration for which we have created an anonymous type.
2764 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Task_Type then
2767 elsif Present (Spec_Id)
2768 and then Ekind (Etype (Spec_Id)) = E_Task_Type
2769 and then not Comes_From_Source (Etype (Spec_Id))
2774 Error_Msg_N ("missing specification for task body", Body_Id);
2778 if Has_Completion (Spec_Id)
2779 and then Present (Corresponding_Body (Parent (Spec_Id)))
2781 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
2782 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
2784 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
2789 Generate_Reference (Ref_Id, Body_Id, 'b', Set_Ref => False);
2790 Style.Check_Identifier (Body_Id, Spec_Id);
2792 -- Deal with case of body of single task (anonymous type was created)
2794 if Ekind (Spec_Id) = E_Variable then
2795 Spec_Id := Etype (Spec_Id);
2798 -- Set the SPARK_Mode from the current context (may be overwritten later
2799 -- with an explicit pragma).
2801 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
2802 Set_SPARK_Pragma_Inherited (Body_Id);
2804 if Has_Aspects (N) then
2805 Analyze_Aspect_Specifications (N, Body_Id);
2808 Push_Scope (Spec_Id);
2809 Set_Corresponding_Spec (N, Spec_Id);
2810 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
2811 Set_Has_Completion (Spec_Id);
2812 Install_Declarations (Spec_Id);
2813 Last_E := Last_Entity (Spec_Id);
2815 Analyze_Declarations (Decls);
2816 Inspect_Deferred_Constant_Completion (Decls);
2818 -- For visibility purposes, all entities in the body are private. Set
2819 -- First_Private_Entity accordingly, if there was no private part in the
2820 -- protected declaration.
2822 if No (First_Private_Entity (Spec_Id)) then
2823 if Present (Last_E) then
2824 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
2826 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
2830 -- Mark all handlers as not suitable for local raise optimization,
2831 -- since this optimization causes difficulties in a task context.
2833 if Present (Exception_Handlers (HSS)) then
2837 Handlr := First (Exception_Handlers (HSS));
2838 while Present (Handlr) loop
2839 Set_Local_Raise_Not_OK (Handlr);
2845 -- Now go ahead and complete analysis of the task body
2848 Check_Completion (Body_Id);
2849 Check_References (Body_Id);
2850 Check_References (Spec_Id);
2852 -- Check for entries with no corresponding accept
2858 Ent := First_Entity (Spec_Id);
2859 while Present (Ent) loop
2861 and then not Entry_Accepted (Ent)
2862 and then Comes_From_Source (Ent)
2864 Error_Msg_NE ("no accept for entry &??", N, Ent);
2871 Process_End_Label (HSS, 't', Ref_Id);
2873 end Analyze_Task_Body;
2875 -----------------------------
2876 -- Analyze_Task_Definition --
2877 -----------------------------
2879 procedure Analyze_Task_Definition (N : Node_Id) is
2883 Tasking_Used := True;
2884 Check_SPARK_05_Restriction ("task definition is not allowed", N);
2886 if Present (Visible_Declarations (N)) then
2887 Analyze_Declarations (Visible_Declarations (N));
2890 if Present (Private_Declarations (N)) then
2891 L := Last_Entity (Current_Scope);
2892 Analyze_Declarations (Private_Declarations (N));
2895 Set_First_Private_Entity
2896 (Current_Scope, Next_Entity (L));
2898 Set_First_Private_Entity
2899 (Current_Scope, First_Entity (Current_Scope));
2903 Check_Max_Entries (N, Max_Task_Entries);
2904 Process_End_Label (N, 'e', Current_Scope);
2905 end Analyze_Task_Definition;
2907 -----------------------------------
2908 -- Analyze_Task_Type_Declaration --
2909 -----------------------------------
2911 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
2912 Def_Id : constant Entity_Id := Defining_Identifier (N);
2916 -- Attempt to use tasking in no run time mode is not allowe. Issue hard
2917 -- error message to disable expansion which leads to crashes.
2919 if Opt.No_Run_Time_Mode then
2920 Error_Msg_N ("tasking not allowed in No_Run_Time mode", N);
2922 -- Otherwise soft check for no tasking restriction
2925 Check_Restriction (No_Tasking, N);
2928 -- Proceed ahead with analysis of task type declaration
2930 Tasking_Used := True;
2932 -- The sequential partition elaboration policy is supported only in the
2933 -- restricted profile.
2935 if Partition_Elaboration_Policy = 'S'
2936 and then not Restricted_Profile
2939 ("sequential elaboration supported only in restricted profile", N);
2942 T := Find_Type_Name (N);
2943 Generate_Definition (T);
2945 -- In the case of an incomplete type, use the full view, unless it's not
2946 -- present (as can occur for an incomplete view from a limited with).
2947 -- Initialize the Corresponding_Record_Type (which overlays the Private
2948 -- Dependents field of the incomplete view).
2950 if Ekind (T) = E_Incomplete_Type then
2951 if Present (Full_View (T)) then
2953 Set_Completion_Referenced (T);
2956 Set_Ekind (T, E_Task_Type);
2957 Set_Corresponding_Record_Type (T, Empty);
2961 Set_Ekind (T, E_Task_Type);
2962 Set_Is_First_Subtype (T, True);
2963 Set_Has_Task (T, True);
2964 Init_Size_Align (T);
2966 Set_Has_Delayed_Freeze (T, True);
2967 Set_Stored_Constraint (T, No_Elist);
2969 -- Set the SPARK_Mode from the current context (may be overwritten later
2970 -- with an explicit pragma).
2972 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
2973 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
2974 Set_SPARK_Pragma_Inherited (T);
2975 Set_SPARK_Aux_Pragma_Inherited (T);
2979 if Ada_Version >= Ada_2005 then
2980 Check_Interfaces (N, T);
2983 if Present (Discriminant_Specifications (N)) then
2984 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2985 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
2988 if Has_Discriminants (T) then
2990 -- Install discriminants. Also, verify conformance of
2991 -- discriminants of previous and current view. ???
2993 Install_Declarations (T);
2995 Process_Discriminants (N);
2999 Set_Is_Constrained (T, not Has_Discriminants (T));
3001 if Has_Aspects (N) then
3002 Analyze_Aspect_Specifications (N, Def_Id);
3005 if Present (Task_Definition (N)) then
3006 Analyze_Task_Definition (Task_Definition (N));
3009 -- In the case where the task type is declared at a nested level and the
3010 -- No_Task_Hierarchy restriction applies, issue a warning that objects
3011 -- of the type will violate the restriction.
3013 if Restriction_Check_Required (No_Task_Hierarchy)
3014 and then not Is_Library_Level_Entity (T)
3015 and then Comes_From_Source (T)
3017 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
3019 if Error_Msg_Sloc = No_Location then
3021 ("objects of this type will violate `No_Task_Hierarchy`??", N);
3024 ("objects of this type will violate `No_Task_Hierarchy`#??", N);
3030 -- Case of a completion of a private declaration
3033 and then Is_Private_Type (Def_Id)
3035 -- Deal with preelaborable initialization. Note that this processing
3036 -- is done by Process_Full_View, but as can be seen below, in this
3037 -- case the call to Process_Full_View is skipped if any serious
3038 -- errors have occurred, and we don't want to lose this check.
3040 if Known_To_Have_Preelab_Init (Def_Id) then
3041 Set_Must_Have_Preelab_Init (T);
3044 -- Create corresponding record now, because some private dependents
3045 -- may be subtypes of the partial view.
3047 -- Skip if errors are present, to prevent cascaded messages
3049 if Serious_Errors_Detected = 0
3051 -- Also skip if expander is not active
3053 and then Expander_Active
3055 Expand_N_Task_Type_Declaration (N);
3056 Process_Full_View (N, T, Def_Id);
3059 end Analyze_Task_Type_Declaration;
3061 -----------------------------------
3062 -- Analyze_Terminate_Alternative --
3063 -----------------------------------
3065 procedure Analyze_Terminate_Alternative (N : Node_Id) is
3067 Tasking_Used := True;
3069 if Present (Pragmas_Before (N)) then
3070 Analyze_List (Pragmas_Before (N));
3073 if Present (Condition (N)) then
3074 Analyze_And_Resolve (Condition (N), Any_Boolean);
3076 end Analyze_Terminate_Alternative;
3078 ------------------------------
3079 -- Analyze_Timed_Entry_Call --
3080 ------------------------------
3082 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
3083 Trigger : constant Node_Id :=
3084 Entry_Call_Statement (Entry_Call_Alternative (N));
3085 Is_Disp_Select : Boolean := False;
3088 Tasking_Used := True;
3089 Check_SPARK_05_Restriction ("select statement is not allowed", N);
3090 Check_Restriction (No_Select_Statements, N);
3092 -- Ada 2005 (AI-345): The trigger may be a dispatching call
3094 if Ada_Version >= Ada_2005 then
3096 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
3099 -- Postpone the analysis of the statements till expansion. Analyze only
3100 -- if the expander is disabled in order to catch any semantic errors.
3102 if Is_Disp_Select then
3103 if not Expander_Active then
3104 Analyze (Entry_Call_Alternative (N));
3105 Analyze (Delay_Alternative (N));
3108 -- Regular select analysis
3111 Analyze (Entry_Call_Alternative (N));
3112 Analyze (Delay_Alternative (N));
3114 end Analyze_Timed_Entry_Call;
3116 ------------------------------------
3117 -- Analyze_Triggering_Alternative --
3118 ------------------------------------
3120 procedure Analyze_Triggering_Alternative (N : Node_Id) is
3121 Trigger : constant Node_Id := Triggering_Statement (N);
3124 Tasking_Used := True;
3126 if Present (Pragmas_Before (N)) then
3127 Analyze_List (Pragmas_Before (N));
3132 if Comes_From_Source (Trigger)
3133 and then Nkind (Trigger) not in N_Delay_Statement
3134 and then Nkind (Trigger) /= N_Entry_Call_Statement
3136 if Ada_Version < Ada_2005 then
3138 ("triggering statement must be delay or entry call", Trigger);
3140 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
3141 -- procedure_or_entry_call, the procedure_name or procedure_prefix
3142 -- of the procedure_call_statement shall denote an entry renamed by a
3143 -- procedure, or (a view of) a primitive subprogram of a limited
3144 -- interface whose first parameter is a controlling parameter.
3146 elsif Nkind (Trigger) = N_Procedure_Call_Statement
3147 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
3148 and then not Is_Controlling_Limited_Procedure
3149 (Entity (Name (Trigger)))
3152 ("triggering statement must be procedure or entry call " &
3153 "or delay statement", Trigger);
3157 if Is_Non_Empty_List (Statements (N)) then
3158 Analyze_Statements (Statements (N));
3160 end Analyze_Triggering_Alternative;
3162 -----------------------
3163 -- Check_Max_Entries --
3164 -----------------------
3166 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
3169 procedure Count (L : List_Id);
3170 -- Count entries in given declaration list
3176 procedure Count (L : List_Id) is
3185 while Present (D) loop
3186 if Nkind (D) = N_Entry_Declaration then
3188 DSD : constant Node_Id :=
3189 Discrete_Subtype_Definition (D);
3192 -- If not an entry family, then just one entry
3195 Ecount := Ecount + 1;
3197 -- If entry family with static bounds, count entries
3199 elsif Is_OK_Static_Subtype (Etype (DSD)) then
3201 Lo : constant Uint :=
3203 (Type_Low_Bound (Etype (DSD)));
3204 Hi : constant Uint :=
3206 (Type_High_Bound (Etype (DSD)));
3210 Ecount := Ecount + Hi - Lo + 1;
3214 -- Entry family with non-static bounds
3217 -- Record an unknown count restriction, and if the
3218 -- restriction is active, post a message or warning.
3220 Check_Restriction (R, D);
3229 -- Start of processing for Check_Max_Entries
3233 Count (Visible_Declarations (D));
3234 Count (Private_Declarations (D));
3237 Check_Restriction (R, D, Ecount);
3239 end Check_Max_Entries;
3241 ----------------------
3242 -- Check_Interfaces --
3243 ----------------------
3245 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
3247 Iface_Typ : Entity_Id;
3251 (Nkind_In (N, N_Protected_Type_Declaration, N_Task_Type_Declaration));
3253 if Present (Interface_List (N)) then
3254 Set_Is_Tagged_Type (T);
3256 -- The primitive operations of a tagged synchronized type are placed
3257 -- on the Corresponding_Record for proper dispatching, but are
3258 -- attached to the synchronized type itself when expansion is
3259 -- disabled, for ASIS use.
3261 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3263 Iface := First (Interface_List (N));
3264 while Present (Iface) loop
3265 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
3267 if not Is_Interface (Iface_Typ) then
3269 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
3272 -- Ada 2005 (AI-251): "The declaration of a specific descendant
3273 -- of an interface type freezes the interface type" RM 13.14.
3275 Freeze_Before (N, Etype (Iface));
3277 if Nkind (N) = N_Protected_Type_Declaration then
3279 -- Ada 2005 (AI-345): Protected types can only implement
3280 -- limited, synchronized, or protected interfaces (note that
3281 -- the predicate Is_Limited_Interface includes synchronized
3282 -- and protected interfaces).
3284 if Is_Task_Interface (Iface_Typ) then
3285 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3286 & "a task interface", Iface);
3288 elsif not Is_Limited_Interface (Iface_Typ) then
3289 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3290 & "a non-limited interface", Iface);
3293 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
3295 -- Ada 2005 (AI-345): Task types can only implement limited,
3296 -- synchronized, or task interfaces (note that the predicate
3297 -- Is_Limited_Interface includes synchronized and task
3300 if Is_Protected_Interface (Iface_Typ) then
3301 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3302 "protected interface", Iface);
3304 elsif not Is_Limited_Interface (Iface_Typ) then
3305 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3306 "non-limited interface", Iface);
3315 if not Has_Private_Declaration (T) then
3319 -- Additional checks on full-types associated with private type
3320 -- declarations. Search for the private type declaration.
3323 Full_T_Ifaces : Elist_Id;
3326 Priv_T_Ifaces : Elist_Id;
3329 Priv_T := First_Entity (Scope (T));
3331 pragma Assert (Present (Priv_T));
3333 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
3334 exit when Full_View (Priv_T) = T;
3337 Next_Entity (Priv_T);
3340 -- In case of synchronized types covering interfaces the private type
3341 -- declaration must be limited.
3343 if Present (Interface_List (N))
3344 and then not Is_Limited_Type (Priv_T)
3346 Error_Msg_Sloc := Sloc (Priv_T);
3347 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
3348 "private type#", T);
3351 -- RM 7.3 (7.1/2): If the full view has a partial view that is
3352 -- tagged then check RM 7.3 subsidiary rules.
3354 if Is_Tagged_Type (Priv_T)
3355 and then not Error_Posted (N)
3357 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
3358 -- type if and only if the full type is a synchronized tagged type
3360 if Is_Synchronized_Tagged_Type (Priv_T)
3361 and then not Is_Synchronized_Tagged_Type (T)
3364 ("(Ada 2005) full view must be a synchronized tagged " &
3365 "type (RM 7.3 (7.2/2))", Priv_T);
3367 elsif Is_Synchronized_Tagged_Type (T)
3368 and then not Is_Synchronized_Tagged_Type (Priv_T)
3371 ("(Ada 2005) partial view must be a synchronized tagged " &
3372 "type (RM 7.3 (7.2/2))", T);
3375 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
3376 -- interface type if and only if the full type is descendant of
3377 -- the interface type.
3379 if Present (Interface_List (N))
3380 or else (Is_Tagged_Type (Priv_T)
3381 and then Has_Interfaces
3382 (Priv_T, Use_Full_View => False))
3384 if Is_Tagged_Type (Priv_T) then
3386 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
3389 if Is_Tagged_Type (T) then
3390 Collect_Interfaces (T, Full_T_Ifaces);
3393 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
3395 if Present (Iface) then
3397 ("interface in partial view& not implemented by full "
3398 & "type (RM-2005 7.3 (7.3/2))", T, Iface);
3401 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
3403 if Present (Iface) then
3405 ("interface & not implemented by partial " &
3406 "view (RM-2005 7.3 (7.3/2))", T, Iface);
3411 end Check_Interfaces;
3413 --------------------------------
3414 -- Check_Triggering_Statement --
3415 --------------------------------
3417 procedure Check_Triggering_Statement
3419 Error_Node : Node_Id;
3420 Is_Dispatching : out Boolean)
3425 Is_Dispatching := False;
3427 -- It is not possible to have a dispatching trigger if we are not in
3430 if Ada_Version >= Ada_2005
3431 and then Nkind (Trigger) = N_Procedure_Call_Statement
3432 and then Present (Parameter_Associations (Trigger))
3434 Param := First (Parameter_Associations (Trigger));
3436 if Is_Controlling_Actual (Param)
3437 and then Is_Interface (Etype (Param))
3439 if Is_Limited_Record (Etype (Param)) then
3440 Is_Dispatching := True;
3443 ("dispatching operation of limited or synchronized " &
3444 "interface required (RM 9.7.2(3))!", Error_Node);
3447 elsif Nkind (Trigger) = N_Explicit_Dereference then
3449 ("entry call or dispatching primitive of interface required ",
3453 end Check_Triggering_Statement;
3455 --------------------------
3456 -- Find_Concurrent_Spec --
3457 --------------------------
3459 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
3460 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
3463 -- The type may have been given by an incomplete type declaration.
3464 -- Find full view now.
3466 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
3467 Spec_Id := Full_View (Spec_Id);
3471 end Find_Concurrent_Spec;
3473 --------------------------
3474 -- Install_Declarations --
3475 --------------------------
3477 procedure Install_Declarations (Spec : Entity_Id) is
3481 E := First_Entity (Spec);
3482 while Present (E) loop
3483 Prev := Current_Entity (E);
3484 Set_Current_Entity (E);
3485 Set_Is_Immediately_Visible (E);
3486 Set_Homonym (E, Prev);
3489 end Install_Declarations;