1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, 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 Einfo
; use Einfo
;
31 with Einfo
.Entities
; use Einfo
.Entities
;
32 with Einfo
.Utils
; use Einfo
.Utils
;
33 with Errout
; use Errout
;
34 with Exp_Ch9
; use Exp_Ch9
;
35 with Elists
; use Elists
;
36 with Freeze
; use Freeze
;
37 with Layout
; use Layout
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch5
; use Sem_Ch5
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch13
; use Sem_Ch13
;
54 with Sem_Elab
; use Sem_Elab
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Prag
; use Sem_Prag
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Type
; use Sem_Type
;
59 with Sem_Util
; use Sem_Util
;
60 with Sem_Warn
; use Sem_Warn
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Sinfo
; use Sinfo
;
64 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
65 with Sinfo
.Utils
; use Sinfo
.Utils
;
67 with Targparm
; use Targparm
;
68 with Tbuild
; use Tbuild
;
69 with Uintp
; use Uintp
;
71 package body Sem_Ch9
is
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 function Allows_Lock_Free_Implementation
79 Lock_Free_Given
: Boolean := False) return Boolean;
80 -- This routine returns True iff N satisfies the following list of lock-
81 -- free restrictions for protected type declaration and protected body:
83 -- 1) Protected type declaration
84 -- May not contain entries
85 -- Protected subprogram declarations may not have non-elementary
89 -- Each protected subprogram body within N must satisfy:
90 -- May reference only one protected component
91 -- May not reference non-constant entities outside the protected
93 -- May not contain address representation items, allocators and
94 -- quantified expressions.
95 -- May not contain delay, goto, loop and procedure call
97 -- May not contain exported and imported entities
98 -- May not dereference access values
99 -- Function calls and attribute references must be static
101 -- If Lock_Free_Given is True, an error message is issued when False is
104 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
);
105 -- Given either a protected definition or a task definition in D, check
106 -- the corresponding restriction parameter identifier R, and if it is set,
107 -- count the entries (checking the static requirement), and compare with
108 -- the given maximum.
110 procedure Check_Interfaces
(N
: Node_Id
; T
: Entity_Id
);
111 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
112 -- Complete decoration of T and check legality of the covered interfaces.
114 procedure Check_Triggering_Statement
116 Error_Node
: Node_Id
;
117 Is_Dispatching
: out Boolean);
118 -- Examine the triggering statement of a select statement, conditional or
119 -- timed entry call. If Trigger is a dispatching call, return its status
120 -- in Is_Dispatching and check whether the primitive belongs to a limited
121 -- interface. If it does not, emit an error at Error_Node.
123 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
;
124 -- Find entity in corresponding task or protected declaration. Use full
125 -- view if first declaration was for an incomplete type.
127 -------------------------------------
128 -- Allows_Lock_Free_Implementation --
129 -------------------------------------
131 function Allows_Lock_Free_Implementation
133 Lock_Free_Given
: Boolean := False) return Boolean
135 Errors_Count
: Nat
:= 0;
136 -- Errors_Count is a count of errors detected by the compiler so far
137 -- when Lock_Free_Given is True.
141 (Nkind
(N
) in N_Protected_Type_Declaration | N_Protected_Body
);
143 -- Get the number of errors detected by the compiler so far
145 if Lock_Free_Given
then
146 Errors_Count
:= Serious_Errors_Detected
;
149 -- Protected type declaration case
151 if Nkind
(N
) = N_Protected_Type_Declaration
then
153 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
154 Priv_Decls
: constant List_Id
:= Private_Declarations
(Pdef
);
155 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Pdef
);
159 -- Examine the visible and the private declarations
161 Decl
:= First
(Vis_Decls
);
162 while Present
(Decl
) loop
164 -- Entries and entry families are not allowed by the lock-free
167 if Nkind
(Decl
) = N_Entry_Declaration
then
168 if Lock_Free_Given
then
170 ("entry not allowed when Lock_Free given", Decl
);
175 -- Non-elementary parameters in protected procedure are not
176 -- allowed by the lock-free restrictions.
178 elsif Nkind
(Decl
) = N_Subprogram_Declaration
180 Nkind
(Specification
(Decl
)) = N_Procedure_Specification
183 Par_Specs
: constant List_Id
:=
184 Parameter_Specifications
185 (Specification
(Decl
));
190 Par
:= First
(Par_Specs
);
191 while Present
(Par
) loop
192 if not Is_Elementary_Type
193 (Etype
(Defining_Identifier
(Par
)))
195 if Lock_Free_Given
then
197 ("non-elementary parameter& not allowed "
198 & "when Lock_Free given",
199 Par
, Defining_Identifier
(Par
));
209 elsif Nkind
(Decl
) = N_Subprogram_Declaration
211 Nkind
(Specification
(Decl
)) = N_Function_Specification
213 Nkind
(Result_Definition
(Specification
(Decl
)))
216 Needs_Secondary_Stack
217 (Entity
(Result_Definition
(Specification
(Decl
))))
219 if Lock_Free_Given
then
220 -- Message text is imprecise; "unconstrained" is
221 -- similar to "needs secondary stack" but not identical.
223 ("unconstrained function result subtype not allowed "
224 & "when Lock_Free given",
231 -- Examine private declarations after visible declarations
234 and then List_Containing
(Decl
) = Vis_Decls
236 Decl
:= First
(Priv_Decls
);
243 -- Protected body case
246 Protected_Body_Case
: declare
247 Decls
: constant List_Id
:= Declarations
(N
);
248 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
249 Prot_Typ_Decl
: constant Node_Id
:= Parent
(Pid
);
250 Prot_Def
: constant Node_Id
:=
251 Protected_Definition
(Prot_Typ_Decl
);
252 Priv_Decls
: constant List_Id
:=
253 Private_Declarations
(Prot_Def
);
256 function Satisfies_Lock_Free_Requirements
257 (Sub_Body
: Node_Id
) return Boolean;
258 -- Return True if protected subprogram body Sub_Body satisfies all
259 -- requirements of a lock-free implementation.
261 --------------------------------------
262 -- Satisfies_Lock_Free_Requirements --
263 --------------------------------------
265 function Satisfies_Lock_Free_Requirements
266 (Sub_Body
: Node_Id
) return Boolean
268 Comp
: Entity_Id
:= Empty
;
269 -- Track the current component which the body references
271 Errors_Count
: Nat
:= 0;
272 -- Errors_Count is a count of errors detected by the compiler
273 -- so far when Lock_Free_Given is True.
275 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
276 -- Check that node N meets the lock free restrictions
282 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
283 Kind
: constant Node_Kind
:= Nkind
(N
);
285 -- The following function belongs in sem_eval ???
287 function Is_Static_Function
(Attr
: Node_Id
) return Boolean;
288 -- Given an attribute reference node Attr, return True if
289 -- Attr denotes a static function according to the rules in
292 ------------------------
293 -- Is_Static_Function --
294 ------------------------
296 function Is_Static_Function
297 (Attr
: Node_Id
) return Boolean
302 pragma Assert
(Nkind
(Attr
) = N_Attribute_Reference
);
304 case Attribute_Name
(Attr
) is
311 | Name_Wide_Wide_Value
313 -- A language-defined attribute denotes a static
314 -- function if the prefix denotes a static scalar
315 -- subtype, and if the parameter and result types
316 -- are scalar (RM 4.9 (22)).
318 if Is_Scalar_Type
(Etype
(Attr
))
319 and then Is_Scalar_Type
(Etype
(Prefix
(Attr
)))
321 Is_OK_Static_Subtype
(Etype
(Prefix
(Attr
)))
323 Para
:= First
(Expressions
(Attr
));
325 while Present
(Para
) loop
326 if not Is_Scalar_Type
(Etype
(Para
)) then
342 end Is_Static_Function
;
344 -- Start of processing for Check_Node
347 -- Allocators restricted
349 if Kind
= N_Allocator
then
350 if Lock_Free_Given
then
351 Error_Msg_N
("allocator not allowed", N
);
357 -- Aspects Address, Export and Import restricted
359 elsif Kind
= N_Aspect_Specification
then
361 Asp_Name
: constant Name_Id
:=
362 Chars
(Identifier
(N
));
363 Asp_Id
: constant Aspect_Id
:=
364 Get_Aspect_Id
(Asp_Name
);
367 if Asp_Id
= Aspect_Address
or else
368 Asp_Id
= Aspect_Export
or else
369 Asp_Id
= Aspect_Import
371 Error_Msg_Name_1
:= Asp_Name
;
373 if Lock_Free_Given
then
374 Error_Msg_N
("aspect% not allowed", N
);
382 -- Address attribute definition clause restricted
384 elsif Kind
= N_Attribute_Definition_Clause
385 and then Get_Attribute_Id
(Chars
(N
)) =
388 Error_Msg_Name_1
:= Chars
(N
);
390 if Lock_Free_Given
then
391 if From_Aspect_Specification
(N
) then
392 Error_Msg_N
("aspect% not allowed", N
);
394 Error_Msg_N
("% clause not allowed", N
);
402 -- Non-static Attribute references that don't denote a
403 -- static function restricted.
405 elsif Kind
= N_Attribute_Reference
406 and then not Is_OK_Static_Expression
(N
)
407 and then not Is_Static_Function
(N
)
409 if Lock_Free_Given
then
411 ("non-static attribute reference not allowed", N
);
417 -- Delay statements restricted
419 elsif Kind
in N_Delay_Statement
then
420 if Lock_Free_Given
then
421 Error_Msg_N
("delay not allowed", N
);
427 -- Dereferences of access values restricted
429 elsif Kind
= N_Explicit_Dereference
430 or else (Kind
= N_Selected_Component
431 and then Is_Access_Type
(Etype
(Prefix
(N
))))
433 if Lock_Free_Given
then
435 ("dereference of access value not allowed", N
);
441 -- Non-static function calls restricted
443 elsif Kind
= N_Function_Call
444 and then not Is_OK_Static_Expression
(N
)
446 if Lock_Free_Given
then
448 ("non-static function call not allowed", N
);
454 -- Goto statements restricted
456 elsif Kind
in N_Goto_Statement | N_Goto_When_Statement
then
457 if Lock_Free_Given
then
458 Error_Msg_N
("goto statement not allowed", N
);
466 elsif Kind
in N_Identifier | N_Expanded_Name
467 and then Present
(Entity
(N
))
470 Id
: constant Entity_Id
:= Entity
(N
);
471 Sub_Id
: constant Entity_Id
:=
472 Corresponding_Spec
(Sub_Body
);
475 -- Prohibit references to non-constant entities
476 -- outside the protected subprogram scope.
478 -- References to variables in System.Scalar_Values
479 -- generated because of pragma Initialize_Scalars are
480 -- allowed, because once those variables are
481 -- initialized by the binder-generated code, they
482 -- behave like constants.
484 if Is_Assignable
(Id
)
486 Scope_Within_Or_Same
(Scope
(Id
), Sub_Id
)
490 Protected_Body_Subprogram
(Sub_Id
))
492 (Is_RTU
(Scope
(Id
), System_Scalar_Values
)
493 and then not Comes_From_Source
(N
))
495 if Lock_Free_Given
then
497 ("reference to global variable& not allowed",
506 -- Loop statements restricted
508 elsif Kind
= N_Loop_Statement
then
509 if Lock_Free_Given
then
510 Error_Msg_N
("loop not allowed", N
);
516 -- Pragmas Export and Import restricted
518 elsif Kind
= N_Pragma
then
520 Prag_Name
: constant Name_Id
:=
522 Prag_Id
: constant Pragma_Id
:=
523 Get_Pragma_Id
(Prag_Name
);
526 if Prag_Id
= Pragma_Export
527 or else Prag_Id
= Pragma_Import
529 Error_Msg_Name_1
:= Prag_Name
;
531 if Lock_Free_Given
then
532 if From_Aspect_Specification
(N
) then
533 Error_Msg_N
("aspect% not allowed", N
);
535 Error_Msg_N
("pragma% not allowed", N
);
545 -- Procedure call statements restricted
547 elsif Kind
= N_Procedure_Call_Statement
then
548 if Lock_Free_Given
then
549 Error_Msg_N
("procedure call not allowed", N
);
555 -- Quantified expression restricted. Note that we have
556 -- to check the original node as well, since at this
557 -- stage, it may have been rewritten.
559 elsif Kind
= N_Quantified_Expression
561 Nkind
(Original_Node
(N
)) = N_Quantified_Expression
563 if Lock_Free_Given
then
565 ("quantified expression not allowed", N
);
572 -- A protected subprogram (function or procedure) may
573 -- reference only one component of the protected type, plus
574 -- the type of the component must support atomic operation.
576 if Kind
in N_Identifier | N_Expanded_Name
577 and then Present
(Entity
(N
))
580 Id
: constant Entity_Id
:= Entity
(N
);
582 Comp_Id
: Entity_Id
:= Empty
;
583 Comp_Type
: Entity_Id
;
586 if Ekind
(Id
) = E_Component
then
589 elsif Ekind
(Id
) in E_Constant | E_Variable
590 and then Present
(Prival_Link
(Id
))
592 Comp_Id
:= Prival_Link
(Id
);
595 if Present
(Comp_Id
) then
596 Comp_Decl
:= Parent
(Comp_Id
);
597 Comp_Type
:= Etype
(Comp_Id
);
599 if Nkind
(Comp_Decl
) = N_Component_Declaration
600 and then Is_List_Member
(Comp_Decl
)
601 and then List_Containing
(Comp_Decl
) = Priv_Decls
603 -- Skip generic types since, in that case, we
604 -- will not build a body anyway (in the generic
605 -- template), and the size in the template may
606 -- have a fake value.
608 if not Is_Generic_Type
(Comp_Type
) then
610 -- Make sure the protected component type has
611 -- size and alignment fields set at this
612 -- point whenever this is possible.
614 Layout_Type
(Comp_Type
);
617 Support_Atomic_Primitives
(Comp_Type
)
619 if Lock_Free_Given
then
621 ("type of& must support atomic " &
631 -- Check if another protected component has
632 -- already been accessed by the subprogram body.
637 elsif Comp
/= Comp_Id
then
638 if Lock_Free_Given
then
640 ("only one protected component allowed",
655 function Check_All_Nodes
is new Traverse_Func
(Check_Node
);
657 -- Start of processing for Satisfies_Lock_Free_Requirements
660 if not Support_Atomic_Primitives_On_Target
then
661 if Lock_Free_Given
then
663 ("Lock_Free aspect requires target support for "
664 & "atomic primitives", N
);
669 -- Deal with case where Ceiling_Locking locking policy is
672 if Locking_Policy
= 'C' then
673 if Lock_Free_Given
then
674 -- Explicit Lock_Free aspect spec overrides
675 -- Ceiling_Locking so we generate a warning.
678 ("Lock_Free aspect specification overrides "
679 & "Ceiling_Locking locking policy??", N
);
681 -- If Ceiling_Locking locking policy is in effect, then
682 -- Lock_Free can be explicitly specified but it is
683 -- never the default.
689 -- Get the number of errors detected by the compiler so far
691 if Lock_Free_Given
then
692 Errors_Count
:= Serious_Errors_Detected
;
695 if Check_All_Nodes
(Sub_Body
) = OK
696 and then (not Lock_Free_Given
697 or else Errors_Count
= Serious_Errors_Detected
)
699 -- Establish a relation between the subprogram body and the
700 -- unique protected component it references.
702 if Present
(Comp
) then
703 Lock_Free_Subprogram_Table
.Append
704 (Lock_Free_Subprogram
'(Sub_Body, Comp));
711 end Satisfies_Lock_Free_Requirements;
713 -- Start of processing for Protected_Body_Case
716 Decl := First (Decls);
717 while Present (Decl) loop
718 if Nkind (Decl) = N_Subprogram_Body
719 and then not Satisfies_Lock_Free_Requirements (Decl)
721 if Lock_Free_Given then
723 ("illegal body when Lock_Free given", Decl);
731 end Protected_Body_Case;
734 -- When Lock_Free is given, check if no error has been detected during
738 and then Errors_Count /= Serious_Errors_Detected
744 end Allows_Lock_Free_Implementation;
746 -----------------------------
747 -- Analyze_Abort_Statement --
748 -----------------------------
750 procedure Analyze_Abort_Statement (N : Node_Id) is
754 Tasking_Used := True;
756 T_Name := First (Names (N));
757 while Present (T_Name) loop
760 if Is_Task_Type (Etype (T_Name))
761 or else (Ada_Version >= Ada_2005
762 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
763 and then Is_Interface (Etype (T_Name))
764 and then Is_Task_Interface (Etype (T_Name)))
768 if Ada_Version >= Ada_2005 then
769 Error_Msg_N ("expect task name or task interface class-wide "
770 & "object for ABORT", T_Name);
772 Error_Msg_N ("expect task name for ABORT", T_Name);
781 Check_Restriction (No_Abort_Statements, N);
782 Check_Potentially_Blocking_Operation (N);
783 end Analyze_Abort_Statement;
785 --------------------------------
786 -- Analyze_Accept_Alternative --
787 --------------------------------
789 procedure Analyze_Accept_Alternative (N : Node_Id) is
791 Tasking_Used := True;
793 if Present (Pragmas_Before (N)) then
794 Analyze_List (Pragmas_Before (N));
797 if Present (Condition (N)) then
798 Analyze_And_Resolve (Condition (N), Any_Boolean);
801 Analyze (Accept_Statement (N));
803 if Is_Non_Empty_List (Statements (N)) then
804 Analyze_Statements (Statements (N));
806 end Analyze_Accept_Alternative;
808 ------------------------------
809 -- Analyze_Accept_Statement --
810 ------------------------------
812 procedure Analyze_Accept_Statement (N : Node_Id) is
813 Nam : constant Entity_Id := Entry_Direct_Name (N);
814 Formals : constant List_Id := Parameter_Specifications (N);
815 Index : constant Node_Id := Entry_Index (N);
816 Stats : constant Node_Id := Handled_Statement_Sequence (N);
817 Accept_Id : Entity_Id;
818 Entry_Nam : Entity_Id;
821 Task_Nam : Entity_Id := Empty; -- initialize to prevent warning
824 Tasking_Used := True;
826 -- Entry name is initialized to Any_Id. It should get reset to the
827 -- matching entry entity. An error is signalled if it is not reset.
831 for J in reverse 0 .. Scope_Stack.Last loop
832 Task_Nam := Scope_Stack.Table (J).Entity;
833 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
834 Kind := Ekind (Task_Nam);
836 if Kind /= E_Block and then Kind /= E_Loop
837 and then not Is_Entry (Task_Nam)
839 Error_Msg_N ("enclosing body of ACCEPT must be a task", N);
844 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
845 Error_Msg_N ("invalid context for ACCEPT statement", N);
849 -- In order to process the parameters, we create a defining identifier
850 -- that can be used as the name of the scope. The name of the accept
851 -- statement itself is not a defining identifier, and we cannot use
852 -- its name directly because the task may have any number of accept
853 -- statements for the same entry.
855 if Present (Index) then
856 Accept_Id := New_Internal_Entity
857 (E_Entry_Family, Current_Scope, Sloc (N), 'E
');
859 Accept_Id := New_Internal_Entity
860 (E_Entry, Current_Scope, Sloc (N), 'E
');
863 Set_Etype (Accept_Id, Standard_Void_Type);
864 Set_Accept_Address (Accept_Id, New_Elmt_List);
866 if Present (Formals) then
867 Push_Scope (Accept_Id);
868 Process_Formals (Formals, N);
869 Create_Extra_Formals (Accept_Id);
873 -- We set the default expressions processed flag because we don't need
874 -- default expression functions. This is really more like body entity
875 -- than a spec entity anyway.
877 Set_Default_Expressions_Processed (Accept_Id);
879 E := First_Entity (Etype (Task_Nam));
880 while Present (E) loop
881 if Chars (E) = Chars (Nam)
882 and then (Ekind (E) = Ekind (Accept_Id))
883 and then Type_Conformant (Accept_Id, E)
892 if Entry_Nam = Any_Id then
893 Error_Msg_N ("no entry declaration matches ACCEPT statement", N);
896 Set_Entity (Nam, Entry_Nam);
897 Generate_Reference (Entry_Nam, Nam, 'b
', Set_Ref => False);
898 Style.Check_Identifier (Nam, Entry_Nam);
901 -- Verify that the entry is not hidden by a procedure declared in the
902 -- current block (pathological but possible).
904 if Current_Scope /= Task_Nam then
909 E1 := First_Entity (Current_Scope);
910 while Present (E1) loop
911 if Ekind (E1) = E_Procedure
912 and then Chars (E1) = Chars (Entry_Nam)
913 and then Type_Conformant (E1, Entry_Nam)
915 Error_Msg_N ("entry name is not visible", N);
923 Set_Convention (Accept_Id, Convention (Entry_Nam));
924 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
926 for J in reverse 0 .. Scope_Stack.Last loop
927 exit when Task_Nam = Scope_Stack.Table (J).Entity;
929 if Entry_Nam = Scope_Stack.Table (J).Entity then
931 ("duplicate ACCEPT statement for same entry (RM 9.5.2 (15))", N);
933 -- Do not continue analysis of accept statement, to prevent
946 when N_Compilation_Unit
951 when N_Asynchronous_Select =>
953 ("ACCEPT statement not allowed within an "
954 & "asynchronous SELECT inner to the enclosing task body",
964 if Ekind (Entry_Nam) = E_Entry_Family then
966 Error_Msg_N ("missing entry index in accept for entry family", N);
968 Analyze_And_Resolve (Index, Entry_Index_Type (Entry_Nam));
969 Apply_Scalar_Range_Check (Index, Entry_Index_Type (Entry_Nam));
972 elsif Present (Index) then
973 Error_Msg_N ("invalid entry index in accept for simple entry", N);
976 -- If label declarations present, analyze them. They are declared in the
977 -- enclosing task, but their enclosing scope is the entry itself, so
978 -- that goto's to the label are recognized as local to the accept.
980 if Present (Declarations (N)) then
986 Decl := First (Declarations (N));
987 while Present (Decl) loop
991 (Nkind (Decl) = N_Implicit_Label_Declaration);
993 Id := Defining_Identifier (Decl);
994 Set_Enclosing_Scope (Id, Entry_Nam);
1000 -- If statements are present, they must be analyzed in the context of
1001 -- the entry, so that references to formals are correctly resolved. We
1002 -- also have to add the declarations that are required by the expansion
1003 -- of the accept statement in this case if expansion active.
1005 -- In the case of a select alternative of a selective accept, the
1006 -- expander references the address declaration even if there is no
1009 -- We also need to create the renaming declarations for the local
1010 -- variables that will replace references to the formals within the
1011 -- accept statement.
1013 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
1015 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
1016 -- fields on all entry formals (this loop ignores all other entities).
1017 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
1018 -- well, so that we can post accurate warnings on each accept statement
1019 -- for the same entry.
1021 E := First_Entity (Entry_Nam);
1022 while Present (E) loop
1023 if Is_Formal (E) then
1024 Set_Never_Set_In_Source (E, True);
1025 Set_Is_True_Constant (E, False);
1026 Set_Current_Value (E, Empty);
1027 Set_Referenced (E, False);
1028 Set_Referenced_As_LHS (E, False);
1029 Set_Referenced_As_Out_Parameter (E, False);
1030 Set_Has_Pragma_Unreferenced (E, False);
1036 -- Analyze statements if present
1038 if Present (Stats) then
1039 Push_Scope (Entry_Nam);
1040 Install_Declarations (Entry_Nam);
1042 Set_Actual_Subtypes (N, Current_Scope);
1045 Process_End_Label (Handled_Statement_Sequence (N), 't
', Entry_Nam);
1049 -- Some warning checks
1051 Check_Potentially_Blocking_Operation (N);
1052 Check_References (Entry_Nam, N);
1053 Set_Entry_Accepted (Entry_Nam);
1054 end Analyze_Accept_Statement;
1056 ---------------------------------
1057 -- Analyze_Asynchronous_Select --
1058 ---------------------------------
1060 procedure Analyze_Asynchronous_Select (N : Node_Id) is
1061 Is_Disp_Select : Boolean := False;
1065 Tasking_Used := True;
1066 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
1067 Check_Restriction (No_Select_Statements, N);
1069 if Ada_Version >= Ada_2005 then
1070 Trigger := Triggering_Statement (Triggering_Alternative (N));
1074 -- Ada 2005 (AI-345): Check for a potential dispatching select
1076 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1079 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
1080 -- select will have to duplicate the triggering statements. Postpone
1081 -- the analysis of the statements till expansion. Analyze only if the
1082 -- expander is disabled in order to catch any semantic errors.
1084 if Is_Disp_Select then
1085 if not Expander_Active then
1086 Analyze_Statements (Statements (Abortable_Part (N)));
1087 Analyze (Triggering_Alternative (N));
1090 -- Analyze the statements. We analyze statements in the abortable part,
1091 -- because this is the section that is executed first, and that way our
1092 -- remembering of saved values and checks is accurate.
1095 Analyze_Statements (Statements (Abortable_Part (N)));
1096 Analyze (Triggering_Alternative (N));
1098 end Analyze_Asynchronous_Select;
1100 ------------------------------------
1101 -- Analyze_Conditional_Entry_Call --
1102 ------------------------------------
1104 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
1105 Trigger : constant Node_Id :=
1106 Entry_Call_Statement (Entry_Call_Alternative (N));
1107 Is_Disp_Select : Boolean := False;
1110 Tasking_Used := True;
1111 Check_Restriction (No_Select_Statements, N);
1113 -- Ada 2005 (AI-345): The trigger may be a dispatching call
1115 if Ada_Version >= Ada_2005 then
1117 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1120 if List_Length (Else_Statements (N)) = 1
1121 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
1124 ("suspicious form of conditional entry call??!", N);
1126 ("\`SELECT OR` may be intended rather than `SELECT ELSE`??!", N);
1129 -- Postpone the analysis of the statements till expansion. Analyze only
1130 -- if the expander is disabled in order to catch any semantic errors.
1132 if Is_Disp_Select then
1133 if not Expander_Active then
1134 Analyze (Entry_Call_Alternative (N));
1135 Analyze_Statements (Else_Statements (N));
1138 -- Regular select analysis
1141 Analyze (Entry_Call_Alternative (N));
1142 Analyze_Statements (Else_Statements (N));
1144 end Analyze_Conditional_Entry_Call;
1146 --------------------------------
1147 -- Analyze_Delay_Alternative --
1148 --------------------------------
1150 procedure Analyze_Delay_Alternative (N : Node_Id) is
1155 Tasking_Used := True;
1156 Check_Restriction (No_Delay, N);
1158 if Present (Pragmas_Before (N)) then
1159 Analyze_List (Pragmas_Before (N));
1162 if Nkind (Parent (N)) in N_Selective_Accept | N_Timed_Entry_Call then
1163 Expr := Expression (Delay_Statement (N));
1165 -- Defer full analysis until the statement is expanded, to insure
1166 -- that generated code does not move past the guard. The delay
1167 -- expression is only evaluated if the guard is open.
1169 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
1170 Preanalyze_And_Resolve (Expr, Standard_Duration);
1172 Preanalyze_And_Resolve (Expr);
1175 Typ := First_Subtype (Etype (Expr));
1177 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
1178 and then not Is_RTE (Typ, RO_CA_Time)
1179 and then not Is_RTE (Typ, RO_RT_Time)
1181 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
1184 Check_Restriction (No_Fixed_Point, Expr);
1187 Analyze (Delay_Statement (N));
1190 if Present (Condition (N)) then
1191 Analyze_And_Resolve (Condition (N), Any_Boolean);
1194 if Is_Non_Empty_List (Statements (N)) then
1195 Analyze_Statements (Statements (N));
1197 end Analyze_Delay_Alternative;
1199 ----------------------------
1200 -- Analyze_Delay_Relative --
1201 ----------------------------
1203 procedure Analyze_Delay_Relative (N : Node_Id) is
1204 E : constant Node_Id := Expression (N);
1207 Tasking_Used := True;
1208 Check_Restriction (No_Relative_Delay, N);
1209 Check_Restriction (No_Delay, N);
1210 Check_Potentially_Blocking_Operation (N);
1211 Analyze_And_Resolve (E, Standard_Duration);
1212 Check_Restriction (No_Fixed_Point, E);
1214 -- In SPARK mode the relative delay statement introduces an implicit
1215 -- dependency on the Ada.Real_Time.Clock_Time abstract state, so we must
1216 -- force the loading of the Ada.Real_Time package.
1218 if GNATprove_Mode then
1219 SPARK_Implicit_Load (RO_RT_Time);
1221 end Analyze_Delay_Relative;
1223 -------------------------
1224 -- Analyze_Delay_Until --
1225 -------------------------
1227 procedure Analyze_Delay_Until (N : Node_Id) is
1228 E : constant Node_Id := Expression (N);
1232 Tasking_Used := True;
1233 Check_Restriction (No_Delay, N);
1234 Check_Potentially_Blocking_Operation (N);
1235 Analyze_And_Resolve (E);
1236 Typ := First_Subtype (Etype (E));
1238 if not Is_RTE (Typ, RO_CA_Time) and then
1239 not Is_RTE (Typ, RO_RT_Time)
1241 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
1243 end Analyze_Delay_Until;
1245 ------------------------
1246 -- Analyze_Entry_Body --
1247 ------------------------
1249 procedure Analyze_Entry_Body (N : Node_Id) is
1250 Id : constant Entity_Id := Defining_Identifier (N);
1251 Decls : constant List_Id := Declarations (N);
1252 Stats : constant Node_Id := Handled_Statement_Sequence (N);
1253 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1254 P_Type : constant Entity_Id := Current_Scope;
1256 Entry_Name : Entity_Id;
1259 -- An entry body freezes the contract of the nearest enclosing package
1260 -- body and all other contracts encountered in the same declarative part
1261 -- up to and excluding the entry body. This ensures that any annotations
1262 -- referenced by the contract of an entry or subprogram body declared
1263 -- within the current protected body are available.
1265 Freeze_Previous_Contracts (N);
1267 Tasking_Used := True;
1269 -- Entry_Name is initialized to Any_Id. It should get reset to the
1270 -- matching entry entity. An error is signalled if it is not reset.
1272 Entry_Name := Any_Id;
1276 if Present (Entry_Index_Specification (Formals)) then
1277 Mutate_Ekind (Id, E_Entry_Family);
1279 Mutate_Ekind (Id, E_Entry);
1282 Set_Etype (Id, Standard_Void_Type);
1283 Set_Scope (Id, Current_Scope);
1284 Set_Accept_Address (Id, New_Elmt_List);
1286 -- Set the SPARK_Mode from the current context (may be overwritten later
1287 -- with an explicit pragma).
1289 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1290 Set_SPARK_Pragma_Inherited (Id);
1292 -- Analyze any aspect specifications that appear on the entry body
1294 if Has_Aspects (N) then
1295 Analyze_Aspects_On_Subprogram_Body_Or_Stub (N);
1298 E := First_Entity (P_Type);
1299 while Present (E) loop
1300 if Chars (E) = Chars (Id)
1301 and then Ekind (E) = Ekind (Id)
1302 and then Type_Conformant (Id, E)
1305 Set_Convention (Id, Convention (E));
1306 Set_Corresponding_Body (Parent (E), Id);
1307 Check_Fully_Conformant (Id, E, N);
1309 if Ekind (Id) = E_Entry_Family then
1310 if not Fully_Conformant_Discrete_Subtypes (
1311 Discrete_Subtype_Definition (Parent (E)),
1312 Discrete_Subtype_Definition
1313 (Entry_Index_Specification (Formals)))
1316 ("index not fully conformant with previous declaration",
1317 Discrete_Subtype_Definition
1318 (Entry_Index_Specification (Formals)));
1321 -- The elaboration of the entry body does not recompute the
1322 -- bounds of the index, which may have side effects. Inherit
1323 -- the bounds from the entry declaration. This is critical
1324 -- if the entry has a per-object constraint. If a bound is
1325 -- given by a discriminant, it must be reanalyzed in order
1326 -- to capture the discriminal of the current entry, rather
1327 -- than that of the protected type.
1330 Index_Spec : constant Node_Id :=
1331 Entry_Index_Specification (Formals);
1333 Def : constant Node_Id :=
1335 (Discrete_Subtype_Definition (Parent (E)));
1340 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
1342 Set_Etype (Def, Empty);
1343 Set_Analyzed (Def, False);
1345 -- Keep the original subtree to ensure a properly
1349 (Discrete_Subtype_Definition (Index_Spec), Def);
1351 Set_Analyzed (Low_Bound (Def), False);
1352 Set_Analyzed (High_Bound (Def), False);
1354 if Denotes_Discriminant (Low_Bound (Def)) then
1355 Set_Entity (Low_Bound (Def), Empty);
1358 if Denotes_Discriminant (High_Bound (Def)) then
1359 Set_Entity (High_Bound (Def), Empty);
1363 Make_Index (Def, Index_Spec);
1365 (Defining_Identifier (Index_Spec), Etype (Def));
1377 if Entry_Name = Any_Id then
1378 Error_Msg_N ("no entry declaration matches entry body", N);
1381 elsif Has_Completion (Entry_Name) then
1382 Error_Msg_N ("duplicate entry body", N);
1386 Set_Has_Completion (Entry_Name);
1387 Generate_Reference (Entry_Name, Id, 'b
', Set_Ref => False);
1388 Style.Check_Identifier (Id, Entry_Name);
1391 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
1392 Push_Scope (Entry_Name);
1394 Install_Declarations (Entry_Name);
1395 Set_Actual_Subtypes (N, Current_Scope);
1397 -- The entity for the protected subprogram corresponding to the entry
1398 -- has been created. We retain the name of this entity in the entry
1399 -- body, for use when the corresponding subprogram body is created.
1400 -- Note that entry bodies have no Corresponding_Spec, and there is no
1401 -- easy link back in the tree between the entry body and the entity for
1402 -- the entry itself, which is why we must propagate some attributes
1403 -- explicitly from spec to body.
1405 Set_Protected_Body_Subprogram
1406 (Id, Protected_Body_Subprogram (Entry_Name));
1408 Set_Entry_Parameters_Type
1409 (Id, Entry_Parameters_Type (Entry_Name));
1411 -- Add a declaration for the Protection object, renaming declarations
1412 -- for the discriminals and privals and finally a declaration for the
1413 -- entry family index (if applicable).
1416 and then Is_Protected_Type (P_Type)
1418 Install_Private_Data_Declarations
1419 (Sloc (N), Entry_Name, P_Type, N, Decls);
1422 if Present (Decls) then
1423 Analyze_Declarations (Decls);
1424 Inspect_Deferred_Constant_Completion (Decls);
1427 -- Process the contract of the subprogram body after all declarations
1428 -- have been analyzed. This ensures that any contract-related pragmas
1429 -- are available through the N_Contract node of the body.
1431 Analyze_Entry_Or_Subprogram_Body_Contract (Id);
1433 if Present (Stats) then
1437 -- Check for unreferenced variables etc. Before the Check_References
1438 -- call, we transfer Never_Set_In_Source and Referenced flags from
1439 -- parameters in the spec to the corresponding entities in the body,
1440 -- since we want the warnings on the body entities. Note that we do not
1441 -- have to transfer Referenced_As_LHS, since that flag can only be set
1442 -- for simple variables, but we include Has_Pragma_Unreferenced,
1443 -- which may have been specified for a formal in the body.
1445 -- At the same time, we set the flags on the spec entities to suppress
1446 -- any warnings on the spec formals, since we also scan the spec.
1447 -- Finally, we propagate the Entry_Component attribute to the body
1448 -- formals, for use in the renaming declarations created later for the
1449 -- formals (see exp_ch9.Add_Formal_Renamings).
1456 E1 := First_Entity (Entry_Name);
1457 while Present (E1) loop
1458 E2 := First_Entity (Id);
1459 while Present (E2) loop
1460 exit when Chars (E1) = Chars (E2);
1464 -- If no matching body entity, then we already had a detected
1465 -- error of some kind, so just don't worry about these warnings.
1471 if Ekind (E1) = E_Out_Parameter then
1472 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1473 Set_Never_Set_In_Source (E1, False);
1476 Set_Referenced (E2, Referenced (E1));
1477 Set_Referenced (E1);
1478 Set_Has_Pragma_Unreferenced (E2, Has_Pragma_Unreferenced (E1));
1479 Set_Entry_Component (E2, Entry_Component (E1));
1485 Check_References (Id);
1488 -- We still need to check references for the spec, since objects
1489 -- declared in the body are chained (in the First_Entity sense) to
1490 -- the spec rather than the body in the case of entries.
1492 Check_References (Entry_Name);
1494 -- Process the end label, and terminate the scope
1496 Process_End_Label (Handled_Statement_Sequence (N), 't
', Entry_Name);
1497 Update_Use_Clause_Chain;
1500 -- If this is an entry family, remove the loop created to provide
1501 -- a scope for the entry index.
1503 if Ekind (Id) = E_Entry_Family
1504 and then Present (Entry_Index_Specification (Formals))
1508 end Analyze_Entry_Body;
1510 ------------------------------------
1511 -- Analyze_Entry_Body_Formal_Part --
1512 ------------------------------------
1514 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
1515 Id : constant Entity_Id := Defining_Identifier (Parent (N));
1516 Index : constant Node_Id := Entry_Index_Specification (N);
1517 Formals : constant List_Id := Parameter_Specifications (N);
1520 Tasking_Used := True;
1522 if Present (Index) then
1525 -- The entry index functions like a loop variable, thus it is known
1526 -- to have a valid value.
1528 Set_Is_Known_Valid (Defining_Identifier (Index));
1531 if Present (Formals) then
1532 Set_Scope (Id, Current_Scope);
1534 Process_Formals (Formals, Parent (N));
1537 end Analyze_Entry_Body_Formal_Part;
1539 ------------------------------------
1540 -- Analyze_Entry_Call_Alternative --
1541 ------------------------------------
1543 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
1544 Call : constant Node_Id := Entry_Call_Statement (N);
1547 Tasking_Used := True;
1549 if Present (Pragmas_Before (N)) then
1550 Analyze_List (Pragmas_Before (N));
1553 if Nkind (Call) = N_Attribute_Reference then
1555 -- Possibly a stream attribute, but definitely illegal. Other
1556 -- illegalities, such as procedure calls, are diagnosed after
1559 Error_Msg_N ("entry call alternative requires an entry call", Call);
1565 -- An indirect call in this context is illegal. A procedure call that
1566 -- does not involve a renaming of an entry is illegal as well, but this
1567 -- and other semantic errors are caught during resolution.
1569 if Nkind (Call) = N_Explicit_Dereference then
1571 ("entry call or dispatching primitive of interface required", N);
1574 if Is_Non_Empty_List (Statements (N)) then
1575 Analyze_Statements (Statements (N));
1577 end Analyze_Entry_Call_Alternative;
1579 -------------------------------
1580 -- Analyze_Entry_Declaration --
1581 -------------------------------
1583 procedure Analyze_Entry_Declaration (N : Node_Id) is
1584 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
1585 Def_Id : constant Entity_Id := Defining_Identifier (N);
1586 Formals : constant List_Id := Parameter_Specifications (N);
1589 Generate_Definition (Def_Id);
1591 Tasking_Used := True;
1593 -- Case of no discrete subtype definition
1596 Mutate_Ekind (Def_Id, E_Entry);
1598 -- Processing for discrete subtype definition present
1601 Enter_Name (Def_Id);
1602 Mutate_Ekind (Def_Id, E_Entry_Family);
1604 Make_Index (D_Sdef, N, Def_Id);
1606 -- Check subtype with predicate in entry family
1608 Bad_Predicated_Subtype_Use
1609 ("subtype& has predicate, not allowed in entry family",
1610 D_Sdef, Etype (D_Sdef));
1612 -- Check entry family static bounds outside allowed limits
1614 -- Note: originally this check was not performed here, but in that
1615 -- case the check happens deep in the expander, and the message is
1616 -- posted at the wrong location, and omitted in -gnatc mode.
1617 -- If the type of the entry index is a generic formal, no check
1618 -- is possible. In an instance, the check is not static and a run-
1619 -- time exception will be raised if the bounds are unreasonable.
1622 PEI : constant Entity_Id := RTE (RE_Protected_Entry_Index);
1623 LB : constant Uint := Expr_Value (Type_Low_Bound (PEI));
1624 UB : constant Uint := Expr_Value (Type_High_Bound (PEI));
1631 -- No bounds checking if the type is generic or if previous error.
1632 -- In an instance the check is dynamic.
1634 if Is_Generic_Type (Etype (D_Sdef))
1636 or else Error_Posted (D_Sdef)
1640 elsif Nkind (D_Sdef) = N_Range then
1641 LBR := Low_Bound (D_Sdef);
1643 elsif Is_Entity_Name (D_Sdef)
1644 and then Is_Type (Entity (D_Sdef))
1646 LBR := Type_Low_Bound (Entity (D_Sdef));
1652 if Is_OK_Static_Expression (LBR)
1653 and then Expr_Value (LBR) < LB
1655 Error_Msg_Uint_1 := LB;
1656 Error_Msg_N ("entry family low bound must be '>'= ^!", D_Sdef);
1660 if Is_Generic_Type (Etype (D_Sdef))
1662 or else Error_Posted (D_Sdef)
1666 elsif Nkind (D_Sdef) = N_Range then
1667 UBR := High_Bound (D_Sdef);
1669 elsif Is_Entity_Name (D_Sdef)
1670 and then Is_Type (Entity (D_Sdef))
1672 UBR := Type_High_Bound (Entity (D_Sdef));
1678 if Is_OK_Static_Expression (UBR)
1679 and then Expr_Value (UBR) > UB
1681 Error_Msg_Uint_1 := UB;
1682 Error_Msg_N ("entry family high bound must be '<'= ^!", D_Sdef);
1692 Set_Etype (Def_Id, Standard_Void_Type);
1693 Set_Convention (Def_Id, Convention_Entry);
1694 Set_Accept_Address (Def_Id, New_Elmt_List);
1696 -- Set the SPARK_Mode from the current context (may be overwritten later
1697 -- with an explicit pragma). Task entries are excluded because they are
1698 -- not completed by entry bodies.
1700 if Ekind (Current_Scope) = E_Protected_Type then
1701 Set_SPARK_Pragma (Def_Id, SPARK_Mode_Pragma);
1702 Set_SPARK_Pragma_Inherited (Def_Id);
1705 -- Preserve relevant elaboration-related attributes of the context which
1706 -- are no longer available or very expensive to recompute once analysis,
1707 -- resolution, and expansion are over.
1709 Mark_Elaboration_Attributes
1716 if Present (Formals) then
1717 Set_Scope (Def_Id, Current_Scope);
1718 Push_Scope (Def_Id);
1719 Process_Formals (Formals, N);
1720 Create_Extra_Formals (Def_Id);
1724 if Ekind (Def_Id) = E_Entry then
1725 New_Overloaded_Entity (Def_Id);
1728 Generate_Reference_To_Formals (Def_Id);
1730 if Has_Aspects (N) then
1731 Analyze_Aspect_Specifications (N, Def_Id);
1733 end Analyze_Entry_Declaration;
1735 ---------------------------------------
1736 -- Analyze_Entry_Index_Specification --
1737 ---------------------------------------
1739 -- The Defining_Identifier of the entry index specification is local to the
1740 -- entry body, but it must be available in the entry barrier which is
1741 -- evaluated outside of the entry body. The index is eventually renamed as
1742 -- a run-time object, so its visibility is strictly a front-end concern. In
1743 -- order to make it available to the barrier, we create an additional
1744 -- scope, as for a loop, whose only declaration is the index name. This
1745 -- loop is not attached to the tree and does not appear as an entity local
1746 -- to the protected type, so its existence need only be known to routines
1747 -- that process entry families.
1749 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
1750 Iden : constant Node_Id := Defining_Identifier (N);
1751 Def : constant Node_Id := Discrete_Subtype_Definition (N);
1752 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L
');
1755 Tasking_Used := True;
1758 -- There is no elaboration of the entry index specification. Therefore,
1759 -- if the index is a range, it is not resolved and expanded, but the
1760 -- bounds are inherited from the entry declaration, and reanalyzed.
1761 -- See Analyze_Entry_Body.
1763 if Nkind (Def) /= N_Range then
1764 Make_Index (Def, N);
1767 Mutate_Ekind (Loop_Id, E_Loop);
1768 Set_Scope (Loop_Id, Current_Scope);
1769 Push_Scope (Loop_Id);
1771 Mutate_Ekind (Iden, E_Entry_Index_Parameter);
1772 Set_Etype (Iden, Etype (Def));
1773 end Analyze_Entry_Index_Specification;
1775 ----------------------------
1776 -- Analyze_Protected_Body --
1777 ----------------------------
1779 procedure Analyze_Protected_Body (N : Node_Id) is
1780 Body_Id : constant Entity_Id := Defining_Identifier (N);
1783 Spec_Id : Entity_Id;
1784 -- This is initially the entity of the protected object or protected
1785 -- type involved, but is replaced by the protected type always in the
1786 -- case of a single protected declaration, since this is the proper
1787 -- scope to be used.
1790 -- This is the entity of the protected object or protected type
1791 -- involved, and is the entity used for cross-reference purposes (it
1792 -- differs from Spec_Id in the case of a single protected object, since
1793 -- Spec_Id is set to the protected type in this case).
1795 function Lock_Free_Disabled return Boolean;
1796 -- This routine returns False if the protected object has a Lock_Free
1797 -- aspect specification or a Lock_Free pragma that turns off the
1798 -- lock-free implementation (e.g. whose expression is False).
1800 ------------------------
1801 -- Lock_Free_Disabled --
1802 ------------------------
1804 function Lock_Free_Disabled return Boolean is
1805 Ritem : constant Node_Id :=
1807 (Spec_Id, Name_Lock_Free, Check_Parents => False);
1810 if Present (Ritem) then
1812 -- Pragma with one argument
1814 if Nkind (Ritem) = N_Pragma
1815 and then Present (Pragma_Argument_Associations (Ritem))
1821 (First (Pragma_Argument_Associations (Ritem)))));
1823 -- Aspect Specification with expression present
1825 elsif Nkind (Ritem) = N_Aspect_Specification
1826 and then Present (Expression (Ritem))
1828 return Is_False (Static_Boolean (Expression (Ritem)));
1830 -- Otherwise, return False
1838 end Lock_Free_Disabled;
1840 -- Start of processing for Analyze_Protected_Body
1843 -- A protected body freezes the contract of the nearest enclosing
1844 -- package body and all other contracts encountered in the same
1845 -- declarative part up to and excluding the protected body. This
1846 -- ensures that any annotations referenced by the contract of an
1847 -- entry or subprogram body declared within the current protected
1848 -- body are available.
1850 Freeze_Previous_Contracts (N);
1852 Tasking_Used := True;
1853 Mutate_Ekind (Body_Id, E_Protected_Body);
1854 Set_Etype (Body_Id, Standard_Void_Type);
1855 Spec_Id := Find_Concurrent_Spec (Body_Id);
1857 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Protected_Type then
1860 elsif Present (Spec_Id)
1861 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1862 and then not Comes_From_Source (Etype (Spec_Id))
1867 Error_Msg_N ("missing specification for protected body", Body_Id);
1872 Generate_Reference (Ref_Id, Body_Id, 'b
', Set_Ref => False);
1873 Style.Check_Identifier (Body_Id, Spec_Id);
1875 -- The declarations are always attached to the type
1877 if Ekind (Spec_Id) /= E_Protected_Type then
1878 Spec_Id := Etype (Spec_Id);
1881 if Has_Aspects (N) then
1882 Analyze_Aspect_Specifications (N, Body_Id);
1885 Push_Scope (Spec_Id);
1886 Set_Corresponding_Spec (N, Spec_Id);
1887 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1888 Set_Has_Completion (Spec_Id);
1889 Install_Declarations (Spec_Id);
1890 Expand_Protected_Body_Declarations (N, Spec_Id);
1891 Last_E := Last_Entity (Spec_Id);
1893 Analyze_Declarations (Declarations (N));
1895 -- For visibility purposes, all entities in the body are private. Set
1896 -- First_Private_Entity accordingly, if there was no private part in the
1897 -- protected declaration.
1899 if No (First_Private_Entity (Spec_Id)) then
1900 if Present (Last_E) then
1901 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1903 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1907 Check_Completion (Body_Id);
1908 Check_References (Spec_Id);
1909 Process_End_Label (N, 't
', Ref_Id);
1910 Update_Use_Clause_Chain;
1913 -- When a Lock_Free aspect specification/pragma forces the lock-free
1914 -- implementation, verify the protected body meets all the restrictions,
1915 -- otherwise Allows_Lock_Free_Implementation issues an error message.
1917 if Uses_Lock_Free (Spec_Id) then
1918 if not Allows_Lock_Free_Implementation (N, True) then
1922 -- In other cases, if there is no aspect specification/pragma that
1923 -- disables the lock-free implementation, check both the protected
1924 -- declaration and body satisfy the lock-free restrictions.
1926 elsif not Lock_Free_Disabled
1927 and then Allows_Lock_Free_Implementation (Parent (Spec_Id))
1928 and then Allows_Lock_Free_Implementation (N)
1930 Set_Uses_Lock_Free (Spec_Id);
1932 end Analyze_Protected_Body;
1934 ----------------------------------
1935 -- Analyze_Protected_Definition --
1936 ----------------------------------
1938 procedure Analyze_Protected_Definition (N : Node_Id) is
1939 procedure Undelay_Itypes (T : Entity_Id);
1940 -- Itypes created for the private components of a protected type
1941 -- do not receive freeze nodes, because there is no scope in which
1942 -- they can be elaborated, and they can depend on discriminants of
1943 -- the enclosed protected type. Given that the components can be
1944 -- composite types with inner components, we traverse recursively
1945 -- the private components of the protected type, and indicate that
1946 -- all itypes within are frozen. This ensures that no freeze nodes
1947 -- will be generated for them. In the case of itypes that are access
1948 -- types we need to complete their representation by calling layout,
1949 -- which would otherwise be invoked when freezing a type.
1951 -- On the other hand, components of the corresponding record are
1952 -- frozen (or receive itype references) as for other records.
1954 --------------------
1955 -- Undelay_Itypes --
1956 --------------------
1958 procedure Undelay_Itypes (T : Entity_Id) is
1962 if Is_Protected_Type (T) then
1963 Comp := First_Private_Entity (T);
1964 elsif Is_Record_Type (T) then
1965 Comp := First_Entity (T);
1970 while Present (Comp) loop
1971 if Is_Type (Comp) and then Is_Itype (Comp) then
1972 Set_Has_Delayed_Freeze (Comp, False);
1973 Set_Is_Frozen (Comp);
1975 if Is_Access_Type (Comp) then
1979 if Is_Record_Type (Comp) or else Is_Protected_Type (Comp) then
1980 Undelay_Itypes (Comp);
1990 Prot_Typ : constant Entity_Id := Current_Scope;
1991 Item_Id : Entity_Id;
1992 Last_Id : Entity_Id;
1994 -- Start of processing for Analyze_Protected_Definition
1997 Tasking_Used := True;
1998 Analyze_Declarations (Visible_Declarations (N));
2000 if not Is_Empty_List (Private_Declarations (N)) then
2001 Last_Id := Last_Entity (Prot_Typ);
2002 Analyze_Declarations (Private_Declarations (N));
2004 if Present (Last_Id) then
2005 Set_First_Private_Entity (Prot_Typ, Next_Entity (Last_Id));
2007 Set_First_Private_Entity (Prot_Typ, First_Entity (Prot_Typ));
2011 Item_Id := First_Entity (Prot_Typ);
2012 while Present (Item_Id) loop
2013 if Ekind (Item_Id) in E_Function | E_Procedure then
2014 Set_Convention (Item_Id, Convention_Protected);
2016 Propagate_Concurrent_Flags (Prot_Typ, Etype (Item_Id));
2018 if Chars (Item_Id) /= Name_uParent
2019 and then Needs_Finalization (Etype (Item_Id))
2021 Set_Has_Controlled_Component (Prot_Typ);
2025 Next_Entity (Item_Id);
2028 Undelay_Itypes (Prot_Typ);
2030 Check_Max_Entries (N, Max_Protected_Entries);
2031 Process_End_Label (N, 'e
', Prot_Typ);
2032 end Analyze_Protected_Definition;
2034 ----------------------------------------
2035 -- Analyze_Protected_Type_Declaration --
2036 ----------------------------------------
2038 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
2039 Def_Id : constant Entity_Id := Defining_Identifier (N);
2044 if No_Run_Time_Mode then
2045 Error_Msg_CRT ("protected type", N);
2047 if Has_Aspects (N) then
2048 Analyze_Aspect_Specifications (N, Def_Id);
2054 Tasking_Used := True;
2055 Check_Restriction (No_Protected_Types, N);
2057 T := Find_Type_Name (N);
2059 -- In the case of an incomplete type, use the full view, unless it's not
2060 -- present (as can occur for an incomplete view from a limited with).
2062 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
2064 Set_Completion_Referenced (T);
2067 Mutate_Ekind (T, E_Protected_Type);
2068 Set_Is_First_Subtype (T);
2069 Reinit_Size_Align (T);
2071 Set_Has_Delayed_Freeze (T);
2072 Set_Stored_Constraint (T, No_Elist);
2074 -- Initialize type's primitive operations list, for possible use when
2075 -- the extension of prefixed call notation for untagged types is enabled
2076 -- (such as by use of -gnatX).
2078 Set_Direct_Primitive_Operations (T, New_Elmt_List);
2080 -- Mark this type as a protected type for the sake of restrictions,
2081 -- unless the protected type is declared in a private part of a package
2082 -- of the runtime. With this exception, the Suspension_Object from
2083 -- Ada.Synchronous_Task_Control can be implemented using a protected
2084 -- object without triggering violations of No_Local_Protected_Objects
2085 -- when the user locally declares such an object. This may look like a
2086 -- trick, but the user doesn't have to know how Suspension_Object is
2089 if In_Private_Part (Current_Scope)
2090 and then Is_Internal_Unit (Current_Sem_Unit)
2092 Set_Has_Protected (T, False);
2094 Set_Has_Protected (T);
2097 -- Set the SPARK_Mode from the current context (may be overwritten later
2098 -- with an explicit pragma).
2100 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
2101 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
2102 Set_SPARK_Pragma_Inherited (T);
2103 Set_SPARK_Aux_Pragma_Inherited (T);
2107 if Ada_Version >= Ada_2005 then
2108 Check_Interfaces (N, T);
2111 if Present (Discriminant_Specifications (N)) then
2112 if Has_Discriminants (T) then
2114 -- Install discriminants. Also, verify conformance of
2115 -- discriminants of previous and current view. ???
2117 Install_Declarations (T);
2119 Process_Discriminants (N);
2123 Set_Is_Constrained (T, not Has_Discriminants (T));
2125 -- If aspects are present, analyze them now. They can make references to
2126 -- the discriminants of the type, but not to any components.
2128 if Has_Aspects (N) then
2130 -- The protected type is the full view of a private type. Analyze the
2131 -- aspects with the entity of the private type to ensure that after
2132 -- both views are exchanged, the aspect are actually associated with
2135 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2136 Analyze_Aspect_Specifications (N, T);
2138 Analyze_Aspect_Specifications (N, Def_Id);
2142 Analyze (Protected_Definition (N));
2144 -- In the case where the protected type is declared at a nested level
2145 -- and the No_Local_Protected_Objects restriction applies, issue a
2146 -- warning that objects of the type will violate the restriction.
2148 if Restriction_Check_Required (No_Local_Protected_Objects)
2149 and then not Is_Library_Level_Entity (T)
2150 and then Comes_From_Source (T)
2152 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
2154 if Error_Msg_Sloc = No_Location then
2156 ("objects of this type will violate " &
2157 "`No_Local_Protected_Objects`??", N);
2160 ("objects of this type will violate " &
2161 "`No_Local_Protected_Objects`#??", N);
2165 -- Protected types with entries are controlled (because of the
2166 -- Protection component if nothing else), same for any protected type
2167 -- with interrupt handlers. Note that we need to analyze the protected
2168 -- definition to set Has_Entries and such.
2170 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
2171 or else Number_Entries (T) > 1)
2172 and then not Restricted_Profile
2175 or else Has_Interrupt_Handler (T)
2176 or else Has_Attach_Handler (T))
2178 Set_Has_Controlled_Component (T, True);
2181 -- The Ekind of components is E_Void during analysis to detect illegal
2182 -- uses. Now it can be set correctly.
2184 E := First_Entity (Current_Scope);
2185 while Present (E) loop
2186 if Ekind (E) = E_Void then
2187 Mutate_Ekind (E, E_Component);
2188 Reinit_Component_Location (E);
2196 -- When a Lock_Free aspect forces the lock-free implementation, check N
2197 -- meets all the lock-free restrictions. Otherwise, an error message is
2198 -- issued by Allows_Lock_Free_Implementation.
2200 if Uses_Lock_Free (Defining_Identifier (N)) then
2202 -- Complain when there is an explicit aspect/pragma Priority (or
2203 -- Interrupt_Priority) while the lock-free implementation is forced
2204 -- by an aspect/pragma.
2207 Id : constant Entity_Id := Defining_Identifier (Original_Node (N));
2208 -- The warning must be issued on the original identifier in order
2209 -- to deal properly with the case of a single protected object.
2211 Prio_Item : constant Node_Id :=
2212 Get_Rep_Item (Def_Id, Name_Priority, False);
2215 if Present (Prio_Item) then
2219 if Nkind (Prio_Item) = N_Aspect_Specification
2220 or else From_Aspect_Specification (Prio_Item)
2222 Error_Msg_Name_1 := Chars (Identifier (Prio_Item));
2224 ("aspect% for & has no effect when Lock_Free given??",
2230 Error_Msg_Name_1 := Pragma_Name (Prio_Item);
2232 ("pragma% for & has no effect when Lock_Free given??",
2238 if not Allows_Lock_Free_Implementation (N, Lock_Free_Given => True)
2244 -- If the Attach_Handler aspect is specified or the Interrupt_Handler
2245 -- aspect is True, then the initial ceiling priority must be in the
2246 -- range of System.Interrupt_Priority. It is therefore recommanded
2247 -- to use the Interrupt_Priority aspect instead of the Priority aspect.
2249 if Has_Interrupt_Handler (T) or else Has_Attach_Handler (T) then
2251 Prio_Item : constant Node_Id :=
2252 Get_Rep_Item (Def_Id, Name_Priority, False);
2255 if Present (Prio_Item) then
2259 if (Nkind (Prio_Item) = N_Aspect_Specification
2260 or else From_Aspect_Specification (Prio_Item))
2261 and then Chars (Identifier (Prio_Item)) = Name_Priority
2264 ("aspect Interrupt_Priority is preferred in presence of "
2265 & "handlers??", Prio_Item);
2269 elsif Nkind (Prio_Item) = N_Pragma
2270 and then Pragma_Name (Prio_Item) = Name_Priority
2273 ("pragma Interrupt_Priority is preferred in presence of "
2274 & "handlers??", Prio_Item);
2280 -- Case of a completion of a private declaration
2282 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2284 -- Deal with preelaborable initialization. Note that this processing
2285 -- is done by Process_Full_View, but as can be seen below, in this
2286 -- case the call to Process_Full_View is skipped if any serious
2287 -- errors have occurred, and we don't want to lose this check.
2289 if Known_To_Have_Preelab_Init (Def_Id) then
2290 Set_Must_Have_Preelab_Init (T);
2293 -- Propagate Default_Initial_Condition-related attributes from the
2294 -- private type to the protected type.
2296 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
2298 -- Propagate invariant-related attributes from the private type to
2299 -- the protected type.
2301 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
2303 -- Propagate predicate-related attributes from the private type to
2304 -- the protected type.
2306 Propagate_Predicate_Attributes (T, From_Typ => Def_Id);
2308 -- Create corresponding record now, because some private dependents
2309 -- may be subtypes of the partial view.
2311 -- Skip if errors are present, to prevent cascaded messages
2313 if Serious_Errors_Detected = 0
2315 -- Also skip if expander is not active
2317 and then Expander_Active
2319 Expand_N_Protected_Type_Declaration (N);
2320 Process_Full_View (N, T, Def_Id);
2324 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
2325 -- is required for the ceiling priority protocol checks triggered by
2326 -- calls originating from protected subprograms and entries.
2328 if GNATprove_Mode then
2329 SPARK_Implicit_Load (RE_Interrupt_Priority);
2331 end Analyze_Protected_Type_Declaration;
2333 ---------------------
2334 -- Analyze_Requeue --
2335 ---------------------
2337 procedure Analyze_Requeue (N : Node_Id) is
2339 procedure Check_Wrong_Attribute_In_Postconditions
2340 (Entry_Id : Entity_Id;
2341 Error_Node : Node_Id);
2342 -- Check that the requeue target Entry_Id does not have an specific or
2343 -- class-wide postcondition that references an Old or Index attribute.
2345 ---------------------------------------------
2346 -- Check_Wrong_Attribute_In_Postconditions --
2347 ---------------------------------------------
2349 procedure Check_Wrong_Attribute_In_Postconditions
2350 (Entry_Id : Entity_Id;
2351 Error_Node : Node_Id)
2353 function Check_Node (N : Node_Id) return Traverse_Result;
2354 -- Check that N is not a reference to attribute Index or Old; report
2355 -- an error otherwise.
2361 function Check_Node (N : Node_Id) return Traverse_Result is
2363 if Nkind (N) = N_Attribute_Reference
2364 and then Attribute_Name (N) in Name_Index
2367 Error_Msg_Name_1 := Attribute_Name (N);
2369 ("target of requeue must not have references to attribute % "
2370 & "in postcondition",
2377 procedure Check_Attr_Refs is new Traverse_Proc (Check_Node);
2383 Prag := Pre_Post_Conditions (Contract (Entry_Id));
2385 while Present (Prag) loop
2386 if Pragma_Name (Prag) = Name_Postcondition then
2387 Check_Attr_Refs (First (Pragma_Argument_Associations (Prag)));
2390 Prag := Next_Pragma (Prag);
2392 end Check_Wrong_Attribute_In_Postconditions;
2396 Count : Natural := 0;
2397 Entry_Name : Node_Id := Name (N);
2398 Entry_Id : Entity_Id;
2400 Is_Disp_Req : Boolean;
2402 Enclosing : Entity_Id;
2403 Target_Obj : Node_Id := Empty;
2404 Req_Scope : Entity_Id;
2405 Outer_Ent : Entity_Id;
2406 Synch_Type : Entity_Id := Empty;
2408 -- Start of processing for Analyze_Requeue
2411 -- Preserve relevant elaboration-related attributes of the context which
2412 -- are no longer available or very expensive to recompute once analysis,
2413 -- resolution, and expansion are over.
2415 Mark_Elaboration_Attributes
2421 Tasking_Used := True;
2422 Check_Restriction (No_Requeue_Statements, N);
2423 Check_Unreachable_Code (N);
2426 for J in reverse 0 .. Scope_Stack.Last loop
2427 Enclosing := Scope_Stack.Table (J).Entity;
2428 exit when Is_Entry (Enclosing);
2430 if Ekind (Enclosing) not in E_Block | E_Loop then
2431 Error_Msg_N ("requeue must appear within accept or entry body", N);
2436 Analyze (Entry_Name);
2438 if Etype (Entry_Name) = Any_Type then
2442 if Nkind (Entry_Name) = N_Selected_Component then
2443 Target_Obj := Prefix (Entry_Name);
2444 Entry_Name := Selector_Name (Entry_Name);
2447 -- If an explicit target object is given then we have to check the
2448 -- restrictions of 9.5.4(6).
2450 if Present (Target_Obj) then
2452 -- Locate containing concurrent unit and determine enclosing entry
2453 -- body or outermost enclosing accept statement within the unit.
2456 for S in reverse 0 .. Scope_Stack.Last loop
2457 Req_Scope := Scope_Stack.Table (S).Entity;
2459 exit when Is_Concurrent_Type (Req_Scope);
2461 if Is_Entry (Req_Scope) then
2462 Outer_Ent := Req_Scope;
2466 pragma Assert (Present (Outer_Ent));
2468 -- Check that the accessibility level of the target object is not
2469 -- greater or equal to the outermost enclosing accept statement (or
2470 -- entry body) unless it is a parameter of the innermost enclosing
2471 -- accept statement (or entry body).
2473 if Static_Accessibility_Level (Target_Obj, Zero_On_Dynamic_Level)
2474 >= Scope_Depth (Outer_Ent)
2476 (not Is_Entity_Name (Target_Obj)
2477 or else not Is_Formal (Entity (Target_Obj))
2478 or else Enclosing /= Scope (Entity (Target_Obj)))
2481 ("target object has invalid level for requeue", Target_Obj);
2485 -- Overloaded case, find right interpretation
2487 if Is_Overloaded (Entry_Name) then
2490 -- Loop over candidate interpretations and filter out any that are
2491 -- not parameterless, are not type conformant, are not entries, or
2492 -- do not come from source.
2494 Get_First_Interp (Entry_Name, I, It);
2495 while Present (It.Nam) loop
2497 -- Note: we test type conformance here, not subtype conformance.
2498 -- Subtype conformance will be tested later on, but it is better
2499 -- for error output in some cases not to do that here.
2501 if (No (First_Formal (It.Nam))
2502 or else (Type_Conformant (Enclosing, It.Nam)))
2503 and then Ekind (It.Nam) = E_Entry
2505 -- Ada 2005 (AI-345): Since protected and task types have
2506 -- primitive entry wrappers, we only consider source entries.
2508 if Comes_From_Source (It.Nam) then
2516 Get_Next_Interp (I, It);
2520 Error_Msg_N ("no entry matches context", N);
2523 elsif Count > 1 then
2524 Error_Msg_N ("ambiguous entry name in requeue", N);
2528 Set_Is_Overloaded (Entry_Name, False);
2529 Set_Entity (Entry_Name, Entry_Id);
2532 -- Non-overloaded cases
2534 -- For the case of a reference to an element of an entry family, the
2535 -- Entry_Name is an indexed component.
2537 elsif Nkind (Entry_Name) = N_Indexed_Component then
2539 -- Requeue to an entry out of the body
2541 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
2542 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
2544 -- Requeue from within the body itself
2546 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
2547 Entry_Id := Entity (Prefix (Entry_Name));
2550 Error_Msg_N ("invalid entry_name specified", N);
2554 -- If we had a requeue of the form REQUEUE A (B), then the parser
2555 -- accepted it (because it could have been a requeue on an entry index.
2556 -- If A turns out not to be an entry family, then the analysis of A (B)
2557 -- turned it into a function call.
2559 elsif Nkind (Entry_Name) = N_Function_Call then
2561 ("arguments not allowed in requeue statement",
2562 First (Parameter_Associations (Entry_Name)));
2565 -- Normal case of no entry family, no argument
2568 Entry_Id := Entity (Entry_Name);
2571 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
2572 -- target type must be a concurrent interface class-wide type and the
2573 -- target must be a procedure, flagged by pragma Implemented. The
2574 -- target may be an access to class-wide type, in which case it must
2577 if Present (Target_Obj) then
2578 Synch_Type := Etype (Target_Obj);
2580 if Is_Access_Type (Synch_Type) then
2581 Synch_Type := Designated_Type (Synch_Type);
2586 Ada_Version >= Ada_2012
2587 and then Present (Target_Obj)
2588 and then Is_Class_Wide_Type (Synch_Type)
2589 and then Is_Concurrent_Interface (Synch_Type)
2590 and then Ekind (Entry_Id) = E_Procedure
2591 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
2593 -- Resolve entry, and check that it is subtype conformant with the
2594 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
2595 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
2597 if not Is_Entry (Entry_Id)
2598 and then not Is_Disp_Req
2600 Error_Msg_N ("expect entry name in requeue statement", Name (N));
2602 elsif Ekind (Entry_Id) = E_Entry_Family
2603 and then Nkind (Entry_Name) /= N_Indexed_Component
2605 Error_Msg_N ("missing index for entry family component", Name (N));
2608 Resolve_Entry (Name (N));
2609 Generate_Reference (Entry_Id, Entry_Name);
2611 if Present (First_Formal (Entry_Id)) then
2613 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
2614 -- the first parameter of Entry_Id since it is the interface
2615 -- controlling formal.
2617 if Ada_Version >= Ada_2012 and then Is_Disp_Req then
2619 Enclosing_Formal : Entity_Id;
2620 Target_Formal : Entity_Id;
2623 Enclosing_Formal := First_Formal (Enclosing);
2624 Target_Formal := Next_Formal (First_Formal (Entry_Id));
2625 while Present (Enclosing_Formal)
2626 and then Present (Target_Formal)
2628 if not Conforming_Types
2629 (T1 => Etype (Enclosing_Formal),
2630 T2 => Etype (Target_Formal),
2631 Ctype => Subtype_Conformant)
2633 Error_Msg_Node_2 := Target_Formal;
2635 ("formal & is not subtype conformant with &" &
2636 "in dispatching requeue", N, Enclosing_Formal);
2639 Next_Formal (Enclosing_Formal);
2640 Next_Formal (Target_Formal);
2644 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
2647 -- Processing for parameters accessed by the requeue
2653 Ent := First_Formal (Enclosing);
2654 while Present (Ent) loop
2656 -- For OUT or IN OUT parameter, the effect of the requeue is
2657 -- to assign the parameter a value on exit from the requeued
2658 -- body, so we can set it as source assigned. We also clear
2659 -- the Is_True_Constant indication. We do not need to clear
2660 -- Current_Value, since the effect of the requeue is to
2661 -- perform an unconditional goto so that any further
2662 -- references will not occur anyway.
2664 if Ekind (Ent) in E_Out_Parameter | E_In_Out_Parameter then
2665 Set_Never_Set_In_Source (Ent, False);
2666 Set_Is_True_Constant (Ent, False);
2669 -- For all parameters, the requeue acts as a reference,
2670 -- since the value of the parameter is passed to the new
2671 -- entry, so we want to suppress unreferenced warnings.
2673 Set_Referenced (Ent);
2680 -- AI05-0225: the target protected object of a requeue must be a
2681 -- variable. This is a binding interpretation that applies to all
2682 -- versions of the language. Note that the subprogram does not have
2683 -- to be a protected operation: it can be an primitive implemented
2684 -- by entry with a formal that is a protected interface.
2686 if Present (Target_Obj)
2687 and then not Is_Variable (Target_Obj)
2690 ("target protected object of requeue must be a variable", N);
2693 -- Ada 2022 (AI12-0143): The requeue target shall not have an
2694 -- applicable specific or class-wide postcondition which includes
2695 -- an Old or Index attribute reference.
2697 if Ekind (Entry_Id) = E_Entry_Family
2698 and then Present (Contract (Entry_Id))
2700 Check_Wrong_Attribute_In_Postconditions
2701 (Entry_Id => Entry_Id,
2702 Error_Node => Entry_Name);
2705 -- A requeue statement is treated as a call for purposes of ABE checks
2706 -- and diagnostics. Annotate the tree by creating a call marker in case
2707 -- the requeue statement is transformed by expansion.
2709 Build_Call_Marker (N);
2710 end Analyze_Requeue;
2712 ------------------------------
2713 -- Analyze_Selective_Accept --
2714 ------------------------------
2716 procedure Analyze_Selective_Accept (N : Node_Id) is
2717 Alts : constant List_Id := Select_Alternatives (N);
2720 Accept_Present : Boolean := False;
2721 Terminate_Present : Boolean := False;
2722 Delay_Present : Boolean := False;
2723 Relative_Present : Boolean := False;
2724 Alt_Count : Uint := Uint_0;
2727 Tasking_Used := True;
2728 Check_Restriction (No_Select_Statements, N);
2730 -- Loop to analyze alternatives
2732 Alt := First (Alts);
2733 while Present (Alt) loop
2734 Alt_Count := Alt_Count + 1;
2737 if Nkind (Alt) = N_Delay_Alternative then
2738 if Delay_Present then
2740 if Relative_Present /=
2741 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
2744 ("delay_until and delay_relative alternatives", Alt);
2746 ("\cannot appear in the same selective_wait", Alt);
2750 Delay_Present := True;
2752 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
2755 elsif Nkind (Alt) = N_Terminate_Alternative then
2756 if Terminate_Present then
2757 Error_Msg_N ("only one terminate alternative allowed", N);
2759 Terminate_Present := True;
2760 Check_Restriction (No_Terminate_Alternatives, N);
2763 elsif Nkind (Alt) = N_Accept_Alternative then
2764 Accept_Present := True;
2766 -- Check for duplicate accept
2770 Stm : constant Node_Id := Accept_Statement (Alt);
2771 EDN : constant Node_Id := Entry_Direct_Name (Stm);
2775 if Nkind (EDN) = N_Identifier
2776 and then No (Condition (Alt))
2777 and then Present (Entity (EDN)) -- defend against junk
2778 and then Ekind (Entity (EDN)) = E_Entry
2780 Ent := Entity (EDN);
2782 Alt1 := First (Alts);
2783 while Alt1 /= Alt loop
2784 if Nkind (Alt1) = N_Accept_Alternative
2785 and then No (Condition (Alt1))
2788 Stm1 : constant Node_Id := Accept_Statement (Alt1);
2789 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
2792 if Nkind (EDN1) = N_Identifier then
2793 if Entity (EDN1) = Ent then
2794 Error_Msg_Sloc := Sloc (Stm1);
2796 ("ACCEPT duplicates one on line#??", Stm);
2812 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
2813 Check_Potentially_Blocking_Operation (N);
2815 if Terminate_Present and Delay_Present then
2816 Error_Msg_N ("at most one of TERMINATE or DELAY alternative", N);
2818 elsif not Accept_Present then
2820 ("SELECT must contain at least one ACCEPT alternative", N);
2823 if Present (Else_Statements (N)) then
2824 if Terminate_Present or Delay_Present then
2825 Error_Msg_N ("ELSE part not allowed with other alternatives", N);
2828 Analyze_Statements (Else_Statements (N));
2830 end Analyze_Selective_Accept;
2832 ------------------------------------------
2833 -- Analyze_Single_Protected_Declaration --
2834 ------------------------------------------
2836 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
2837 Loc : constant Source_Ptr := Sloc (N);
2838 Obj_Id : constant Node_Id := Defining_Identifier (N);
2843 Generate_Definition (Obj_Id);
2844 Tasking_Used := True;
2846 -- A single protected declaration is transformed into a pair of an
2847 -- anonymous protected type and an object of that type. Generate:
2849 -- protected type Typ is ...;
2852 Make_Defining_Identifier (Sloc (Obj_Id),
2853 Chars => New_External_Name (Chars (Obj_Id), 'T
'));
2856 Make_Protected_Type_Declaration (Loc,
2857 Defining_Identifier => Typ,
2858 Protected_Definition => Relocate_Node (Protected_Definition (N)),
2859 Interface_List => Interface_List (N)));
2861 -- Use the original defining identifier of the single protected
2862 -- declaration in the generated object declaration to allow for debug
2863 -- information to be attached to it when compiling with -gnatD. The
2864 -- parent of the entity is the new object declaration. The single
2865 -- protected declaration is not used in semantics or code generation,
2866 -- but is scanned when generating debug information, and therefore needs
2867 -- the updated Sloc information from the entity (see Sprint). Generate:
2872 Make_Object_Declaration (Loc,
2873 Defining_Identifier => Obj_Id,
2874 Object_Definition => New_Occurrence_Of (Typ, Loc));
2876 Insert_After (N, Obj_Decl);
2877 Mark_Rewrite_Insertion (Obj_Decl);
2879 -- Relocate aspect Part_Of from the original single protected
2880 -- declaration to the anonymous object declaration. This emulates the
2881 -- placement of an equivalent source pragma.
2883 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2885 -- Relocate pragma Part_Of from the visible declarations of the original
2886 -- single protected declaration to the anonymous object declaration. The
2887 -- new placement better reflects the role of the pragma.
2889 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2891 -- Enter the names of the anonymous protected type and the object before
2892 -- analysis takes places, because the name of the object may be used in
2896 Mutate_Ekind (Typ, E_Protected_Type);
2897 Set_Etype (Typ, Typ);
2898 Set_Anonymous_Object (Typ, Obj_Id);
2900 Enter_Name (Obj_Id);
2901 Mutate_Ekind (Obj_Id, E_Variable);
2902 Set_Etype (Obj_Id, Typ);
2903 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2904 Set_SPARK_Pragma_Inherited (Obj_Id);
2906 -- Instead of calling Analyze on the new node, call the proper analysis
2907 -- procedure directly. Otherwise the node would be expanded twice, with
2908 -- disastrous result.
2910 Analyze_Protected_Type_Declaration (N);
2912 if Has_Aspects (N) then
2913 Analyze_Aspect_Specifications (N, Obj_Id);
2915 end Analyze_Single_Protected_Declaration;
2917 -------------------------------------
2918 -- Analyze_Single_Task_Declaration --
2919 -------------------------------------
2921 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
2922 Loc : constant Source_Ptr := Sloc (N);
2923 Obj_Id : constant Node_Id := Defining_Identifier (N);
2928 Generate_Definition (Obj_Id);
2929 Tasking_Used := True;
2931 -- A single task declaration is transformed into a pair of an anonymous
2932 -- task type and an object of that type. Generate:
2934 -- task type Typ is ...;
2937 Make_Defining_Identifier (Sloc (Obj_Id),
2938 Chars => New_External_Name (Chars (Obj_Id), Suffix => "TK"));
2941 Make_Task_Type_Declaration (Loc,
2942 Defining_Identifier => Typ,
2943 Task_Definition => Relocate_Node (Task_Definition (N)),
2944 Interface_List => Interface_List (N)));
2946 -- Use the original defining identifier of the single task declaration
2947 -- in the generated object declaration to allow for debug information
2948 -- to be attached to it when compiling with -gnatD. The parent of the
2949 -- entity is the new object declaration. The single task declaration
2950 -- is not used in semantics or code generation, but is scanned when
2951 -- generating debug information, and therefore needs the updated Sloc
2952 -- information from the entity (see Sprint). Generate:
2957 Make_Object_Declaration (Loc,
2958 Defining_Identifier => Obj_Id,
2959 Object_Definition => New_Occurrence_Of (Typ, Loc));
2961 Insert_After (N, Obj_Decl);
2962 Mark_Rewrite_Insertion (Obj_Decl);
2964 -- Relocate aspects Depends, Global and Part_Of from the original single
2965 -- task declaration to the anonymous object declaration. This emulates
2966 -- the placement of an equivalent source pragma.
2968 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2970 -- Relocate pragmas Depends, Global and Part_Of from the visible
2971 -- declarations of the original single protected declaration to the
2972 -- anonymous object declaration. The new placement better reflects the
2973 -- role of the pragmas.
2975 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2977 -- Enter the names of the anonymous task type and the object before
2978 -- analysis takes places, because the name of the object may be used
2982 Mutate_Ekind (Typ, E_Task_Type);
2983 Set_Etype (Typ, Typ);
2984 Set_Anonymous_Object (Typ, Obj_Id);
2986 Enter_Name (Obj_Id);
2987 Mutate_Ekind (Obj_Id, E_Variable);
2988 Set_Etype (Obj_Id, Typ);
2989 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2990 Set_SPARK_Pragma_Inherited (Obj_Id);
2992 -- Preserve relevant elaboration-related attributes of the context which
2993 -- are no longer available or very expensive to recompute once analysis,
2994 -- resolution, and expansion are over.
2996 Mark_Elaboration_Attributes
3001 -- Instead of calling Analyze on the new node, call the proper analysis
3002 -- procedure directly. Otherwise the node would be expanded twice, with
3003 -- disastrous result.
3005 Analyze_Task_Type_Declaration (N);
3007 if Has_Aspects (N) then
3008 Analyze_Aspect_Specifications (N, Obj_Id);
3010 end Analyze_Single_Task_Declaration;
3012 -----------------------
3013 -- Analyze_Task_Body --
3014 -----------------------
3016 procedure Analyze_Task_Body (N : Node_Id) is
3017 Body_Id : constant Entity_Id := Defining_Identifier (N);
3018 Decls : constant List_Id := Declarations (N);
3019 HSS : constant Node_Id := Handled_Statement_Sequence (N);
3022 Spec_Id : Entity_Id;
3023 -- This is initially the entity of the task or task type involved, but
3024 -- is replaced by the task type always in the case of a single task
3025 -- declaration, since this is the proper scope to be used.
3028 -- This is the entity of the task or task type, and is the entity used
3029 -- for cross-reference purposes (it differs from Spec_Id in the case of
3030 -- a single task, since Spec_Id is set to the task type).
3033 -- A task body freezes the contract of the nearest enclosing package
3034 -- body and all other contracts encountered in the same declarative part
3035 -- up to and excluding the task body. This ensures that annotations
3036 -- referenced by the contract of an entry or subprogram body declared
3037 -- within the current protected body are available.
3039 Freeze_Previous_Contracts (N);
3041 Tasking_Used := True;
3042 Set_Scope (Body_Id, Current_Scope);
3043 Mutate_Ekind (Body_Id, E_Task_Body);
3044 Set_Etype (Body_Id, Standard_Void_Type);
3045 Spec_Id := Find_Concurrent_Spec (Body_Id);
3047 -- The spec is either a task type declaration, or a single task
3048 -- declaration for which we have created an anonymous type.
3050 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Task_Type then
3053 elsif Present (Spec_Id)
3054 and then Ekind (Etype (Spec_Id)) = E_Task_Type
3055 and then not Comes_From_Source (Etype (Spec_Id))
3060 Error_Msg_N ("missing specification for task body", Body_Id);
3064 if Has_Completion (Spec_Id)
3065 and then Present (Corresponding_Body (Parent (Spec_Id)))
3067 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
3068 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
3070 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
3075 Generate_Reference (Ref_Id, Body_Id, 'b
', Set_Ref => False);
3076 Style.Check_Identifier (Body_Id, Spec_Id);
3078 -- Deal with case of body of single task (anonymous type was created)
3080 if Ekind (Spec_Id) = E_Variable then
3081 Spec_Id := Etype (Spec_Id);
3084 -- Set the SPARK_Mode from the current context (may be overwritten later
3085 -- with an explicit pragma).
3087 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
3088 Set_SPARK_Pragma_Inherited (Body_Id);
3090 if Has_Aspects (N) then
3091 Analyze_Aspect_Specifications (N, Body_Id);
3094 Push_Scope (Spec_Id);
3095 Set_Corresponding_Spec (N, Spec_Id);
3096 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
3097 Set_Has_Completion (Spec_Id);
3098 Install_Declarations (Spec_Id);
3099 Last_E := Last_Entity (Spec_Id);
3101 Analyze_Declarations (Decls);
3102 Inspect_Deferred_Constant_Completion (Decls);
3104 -- For visibility purposes, all entities in the body are private. Set
3105 -- First_Private_Entity accordingly, if there was no private part in the
3106 -- protected declaration.
3108 if No (First_Private_Entity (Spec_Id)) then
3109 if Present (Last_E) then
3110 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
3112 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
3115 -- The entity list of the current scope now includes entities in
3116 -- the spec as well as the body. Their declarations will become
3117 -- part of the statement sequence of the task body procedure that
3118 -- is built during expansion. Indicate that aspect specifications
3119 -- for these entities need not be rechecked. The guards on
3120 -- Check_Aspect_At_End_Of_Declarations are not sufficient to
3121 -- suppress these checks, because the declarations come from source.
3124 Priv : Entity_Id := First_Private_Entity (Spec_Id);
3127 while Present (Priv) loop
3128 Set_Has_Delayed_Aspects (Priv, False);
3134 -- Mark all handlers as not suitable for local raise optimization,
3135 -- since this optimization causes difficulties in a task context.
3137 if Present (Exception_Handlers (HSS)) then
3141 Handlr := First (Exception_Handlers (HSS));
3142 while Present (Handlr) loop
3143 Set_Local_Raise_Not_OK (Handlr);
3149 -- Now go ahead and complete analysis of the task body
3152 Check_Completion (Body_Id);
3153 Check_References (Body_Id);
3154 Check_References (Spec_Id);
3156 -- Check for entries with no corresponding accept
3162 Ent := First_Entity (Spec_Id);
3163 while Present (Ent) loop
3165 and then not Entry_Accepted (Ent)
3166 and then Comes_From_Source (Ent)
3168 Error_Msg_NE ("no accept for entry &??", N, Ent);
3175 Process_End_Label (HSS, 't
', Ref_Id);
3176 Update_Use_Clause_Chain;
3178 end Analyze_Task_Body;
3180 -----------------------------
3181 -- Analyze_Task_Definition --
3182 -----------------------------
3184 procedure Analyze_Task_Definition (N : Node_Id) is
3188 Tasking_Used := True;
3190 if Present (Visible_Declarations (N)) then
3191 Analyze_Declarations (Visible_Declarations (N));
3194 if Present (Private_Declarations (N)) then
3195 L := Last_Entity (Current_Scope);
3196 Analyze_Declarations (Private_Declarations (N));
3199 Set_First_Private_Entity
3200 (Current_Scope, Next_Entity (L));
3202 Set_First_Private_Entity
3203 (Current_Scope, First_Entity (Current_Scope));
3207 Check_Max_Entries (N, Max_Task_Entries);
3208 Process_End_Label (N, 'e
', Current_Scope);
3209 end Analyze_Task_Definition;
3211 -----------------------------------
3212 -- Analyze_Task_Type_Declaration --
3213 -----------------------------------
3215 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
3216 Def_Id : constant Entity_Id := Defining_Identifier (N);
3220 -- Attempt to use tasking in no run time mode is not allowe. Issue hard
3221 -- error message to disable expansion which leads to crashes.
3223 if Opt.No_Run_Time_Mode then
3224 Error_Msg_N ("tasking not allowed in No_Run_Time mode", N);
3226 -- Otherwise soft check for no tasking restriction
3229 Check_Restriction (No_Tasking, N);
3232 -- Proceed ahead with analysis of task type declaration
3234 Tasking_Used := True;
3236 -- The sequential partition elaboration policy is supported only in the
3237 -- restricted profile.
3239 if Partition_Elaboration_Policy = 'S
'
3240 and then not Restricted_Profile
3243 ("sequential elaboration supported only in restricted profile", N);
3246 T := Find_Type_Name (N);
3247 Generate_Definition (T);
3249 -- In the case of an incomplete type, use the full view, unless it's not
3250 -- present (as can occur for an incomplete view from a limited with).
3251 -- Initialize the Corresponding_Record_Type (which overlays the Private
3252 -- Dependents field of the incomplete view).
3254 if Ekind (T) = E_Incomplete_Type then
3255 if Present (Full_View (T)) then
3257 Set_Completion_Referenced (T);
3260 Mutate_Ekind (T, E_Task_Type);
3261 Set_Corresponding_Record_Type (T, Empty);
3265 Mutate_Ekind (T, E_Task_Type);
3266 Set_Is_First_Subtype (T, True);
3267 Set_Has_Task (T, True);
3268 Reinit_Size_Align (T);
3270 Set_Has_Delayed_Freeze (T, True);
3271 Set_Stored_Constraint (T, No_Elist);
3273 -- Initialize type's primitive operations list, for possible use when
3274 -- the extension of prefixed call notation for untagged types is enabled
3275 -- (such as by use of -gnatX).
3277 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3279 -- Set the SPARK_Mode from the current context (may be overwritten later
3280 -- with an explicit pragma).
3282 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
3283 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
3284 Set_SPARK_Pragma_Inherited (T);
3285 Set_SPARK_Aux_Pragma_Inherited (T);
3287 -- Preserve relevant elaboration-related attributes of the context which
3288 -- are no longer available or very expensive to recompute once analysis,
3289 -- resolution, and expansion are over.
3291 Mark_Elaboration_Attributes
3298 if Ada_Version >= Ada_2005 then
3299 Check_Interfaces (N, T);
3302 if Present (Discriminant_Specifications (N)) then
3303 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3304 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
3307 if Has_Discriminants (T) then
3309 -- Install discriminants. Also, verify conformance of
3310 -- discriminants of previous and current view. ???
3312 Install_Declarations (T);
3314 Process_Discriminants (N);
3318 Set_Is_Constrained (T, not Has_Discriminants (T));
3320 if Has_Aspects (N) then
3322 -- The task type is the full view of a private type. Analyze the
3323 -- aspects with the entity of the private type to ensure that after
3324 -- both views are exchanged, the aspect are actually associated with
3327 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3328 Analyze_Aspect_Specifications (N, T);
3330 Analyze_Aspect_Specifications (N, Def_Id);
3334 if Present (Task_Definition (N)) then
3335 Analyze_Task_Definition (Task_Definition (N));
3338 -- In the case where the task type is declared at a nested level and the
3339 -- No_Task_Hierarchy restriction applies, issue a warning that objects
3340 -- of the type will violate the restriction.
3342 if Restriction_Check_Required (No_Task_Hierarchy)
3343 and then not Is_Library_Level_Entity (T)
3344 and then Comes_From_Source (T)
3345 and then not CodePeer_Mode
3347 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
3349 if Error_Msg_Sloc = No_Location then
3351 ("objects of this type will violate `No_Task_Hierarchy`??", N);
3354 ("objects of this type will violate `No_Task_Hierarchy`#??", N);
3360 -- Case of a completion of a private declaration
3362 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3364 -- Deal with preelaborable initialization. Note that this processing
3365 -- is done by Process_Full_View, but as can be seen below, in this
3366 -- case the call to Process_Full_View is skipped if any serious
3367 -- errors have occurred, and we don't want to lose this check.
3369 if Known_To_Have_Preelab_Init (Def_Id) then
3370 Set_Must_Have_Preelab_Init (T);
3373 -- Propagate Default_Initial_Condition-related attributes from the
3374 -- private type to the task type.
3376 Propagate_DIC_Attributes (T, From_Typ => Def_Id);
3378 -- Propagate invariant-related attributes from the private type to
3381 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
3383 -- Propagate predicate-related attributes from the private type to
3386 Propagate_Predicate_Attributes (T, From_Typ => Def_Id);
3388 -- Create corresponding record now, because some private dependents
3389 -- may be subtypes of the partial view.
3391 -- Skip if errors are present, to prevent cascaded messages
3393 if Serious_Errors_Detected = 0
3395 -- Also skip if expander is not active
3397 and then Expander_Active
3399 Expand_N_Task_Type_Declaration (N);
3400 Process_Full_View (N, T, Def_Id);
3404 -- In GNATprove mode, force the loading of a Interrupt_Priority, which
3405 -- is required for the ceiling priority protocol checks triggered by
3406 -- calls originating from tasks.
3408 if GNATprove_Mode then
3409 SPARK_Implicit_Load (RE_Interrupt_Priority);
3411 end Analyze_Task_Type_Declaration;
3413 -----------------------------------
3414 -- Analyze_Terminate_Alternative --
3415 -----------------------------------
3417 procedure Analyze_Terminate_Alternative (N : Node_Id) is
3419 Tasking_Used := True;
3421 if Present (Pragmas_Before (N)) then
3422 Analyze_List (Pragmas_Before (N));
3425 if Present (Condition (N)) then
3426 Analyze_And_Resolve (Condition (N), Any_Boolean);
3428 end Analyze_Terminate_Alternative;
3430 ------------------------------
3431 -- Analyze_Timed_Entry_Call --
3432 ------------------------------
3434 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
3435 Trigger : constant Node_Id :=
3436 Entry_Call_Statement (Entry_Call_Alternative (N));
3437 Is_Disp_Select : Boolean := False;
3440 Tasking_Used := True;
3441 Check_Restriction (No_Select_Statements, N);
3443 -- Ada 2005 (AI-345): The trigger may be a dispatching call
3445 if Ada_Version >= Ada_2005 then
3447 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
3450 -- Postpone the analysis of the statements till expansion. Analyze only
3451 -- if the expander is disabled in order to catch any semantic errors.
3453 if Is_Disp_Select then
3454 if not Expander_Active then
3455 Analyze (Entry_Call_Alternative (N));
3456 Analyze (Delay_Alternative (N));
3459 -- Regular select analysis
3462 Analyze (Entry_Call_Alternative (N));
3463 Analyze (Delay_Alternative (N));
3465 end Analyze_Timed_Entry_Call;
3467 ------------------------------------
3468 -- Analyze_Triggering_Alternative --
3469 ------------------------------------
3471 procedure Analyze_Triggering_Alternative (N : Node_Id) is
3472 Trigger : constant Node_Id := Triggering_Statement (N);
3475 Tasking_Used := True;
3477 if Present (Pragmas_Before (N)) then
3478 Analyze_List (Pragmas_Before (N));
3483 if Comes_From_Source (Trigger)
3484 and then Nkind (Trigger) not in N_Delay_Statement
3485 and then Nkind (Trigger) /= N_Entry_Call_Statement
3487 if Ada_Version < Ada_2005 then
3489 ("triggering statement must be delay or entry call", Trigger);
3491 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
3492 -- procedure_or_entry_call, the procedure_name or procedure_prefix
3493 -- of the procedure_call_statement shall denote an entry renamed by a
3494 -- procedure, or (a view of) a primitive subprogram of a limited
3495 -- interface whose first parameter is a controlling parameter.
3497 elsif Nkind (Trigger) = N_Procedure_Call_Statement
3498 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
3499 and then not Is_Controlling_Limited_Procedure
3500 (Entity (Name (Trigger)))
3503 ("triggering statement must be procedure or entry call " &
3504 "or delay statement", Trigger);
3508 if Is_Non_Empty_List (Statements (N)) then
3509 Analyze_Statements (Statements (N));
3511 end Analyze_Triggering_Alternative;
3513 -----------------------
3514 -- Check_Max_Entries --
3515 -----------------------
3517 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
3520 procedure Count (L : List_Id);
3521 -- Count entries in given declaration list
3527 procedure Count (L : List_Id) is
3536 while Present (D) loop
3537 if Nkind (D) = N_Entry_Declaration then
3539 DSD : constant Node_Id :=
3540 Discrete_Subtype_Definition (D);
3543 -- If not an entry family, then just one entry
3546 Ecount := Ecount + 1;
3548 -- If entry family with static bounds, count entries
3550 elsif Is_OK_Static_Subtype (Etype (DSD)) then
3552 Lo : constant Uint :=
3554 (Type_Low_Bound (Etype (DSD)));
3555 Hi : constant Uint :=
3557 (Type_High_Bound (Etype (DSD)));
3561 Ecount := Ecount + Hi - Lo + 1;
3565 -- Entry family with non-static bounds
3568 -- Record an unknown count restriction, and if the
3569 -- restriction is active, post a message or warning.
3571 Check_Restriction (R, D);
3580 -- Start of processing for Check_Max_Entries
3584 Count (Visible_Declarations (D));
3585 Count (Private_Declarations (D));
3588 Check_Restriction (R, D, Ecount);
3590 end Check_Max_Entries;
3592 ----------------------
3593 -- Check_Interfaces --
3594 ----------------------
3596 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
3598 Iface_Typ : Entity_Id;
3602 (Nkind (N) in N_Protected_Type_Declaration | N_Task_Type_Declaration);
3604 if Present (Interface_List (N)) then
3605 Set_Is_Tagged_Type (T);
3607 -- The primitive operations of a tagged synchronized type are placed
3608 -- on the Corresponding_Record for proper dispatching, but are
3609 -- attached to the synchronized type itself when expansion is
3612 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3614 Iface := First (Interface_List (N));
3615 while Present (Iface) loop
3616 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
3618 if not Is_Interface (Iface_Typ) then
3620 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
3623 -- Ada 2005 (AI-251): "The declaration of a specific descendant
3624 -- of an interface type freezes the interface type" RM 13.14.
3626 Freeze_Before (N, Etype (Iface));
3628 if Nkind (N) = N_Protected_Type_Declaration then
3630 -- Ada 2005 (AI-345): Protected types can only implement
3631 -- limited, synchronized, or protected interfaces (note that
3632 -- the predicate Is_Limited_Interface includes synchronized
3633 -- and protected interfaces).
3635 if Is_Task_Interface (Iface_Typ) then
3636 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3637 & "a task interface", Iface);
3639 elsif not Is_Limited_Interface (Iface_Typ) then
3640 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3641 & "a non-limited interface", Iface);
3644 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
3646 -- Ada 2005 (AI-345): Task types can only implement limited,
3647 -- synchronized, or task interfaces (note that the predicate
3648 -- Is_Limited_Interface includes synchronized and task
3651 if Is_Protected_Interface (Iface_Typ) then
3652 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3653 "protected interface", Iface);
3655 elsif not Is_Limited_Interface (Iface_Typ) then
3656 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3657 "non-limited interface", Iface);
3665 -- Check consistency of any nonoverridable aspects that are
3666 -- inherited from multiple sources.
3668 Check_Inherited_Nonoverridable_Aspects
3670 Interface_List => Interface_List (N),
3671 Parent_Type => Empty);
3674 if not Has_Private_Declaration (T) then
3678 -- Additional checks on full-types associated with private type
3679 -- declarations. Search for the private type declaration.
3682 Full_T_Ifaces : Elist_Id := No_Elist;
3685 Priv_T_Ifaces : Elist_Id := No_Elist;
3688 Priv_T := First_Entity (Scope (T));
3690 pragma Assert (Present (Priv_T));
3692 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
3693 exit when Full_View (Priv_T) = T;
3696 Next_Entity (Priv_T);
3699 -- In case of synchronized types covering interfaces the private type
3700 -- declaration must be limited.
3702 if Present (Interface_List (N))
3703 and then not Is_Limited_Type (Priv_T)
3705 Error_Msg_Sloc := Sloc (Priv_T);
3706 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
3707 "private type#", T);
3710 -- RM 7.3 (7.1/2): If the full view has a partial view that is
3711 -- tagged then check RM 7.3 subsidiary rules.
3713 if Is_Tagged_Type (Priv_T)
3714 and then not Error_Posted (N)
3716 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
3717 -- type if and only if the full type is a synchronized tagged type
3719 if Is_Synchronized_Tagged_Type (Priv_T)
3720 and then not Is_Synchronized_Tagged_Type (T)
3723 ("(Ada 2005) full view must be a synchronized tagged " &
3724 "type (RM 7.3 (7.2/2))", Priv_T);
3726 elsif Is_Synchronized_Tagged_Type (T)
3727 and then not Is_Synchronized_Tagged_Type (Priv_T)
3730 ("(Ada 2005) partial view must be a synchronized tagged " &
3731 "type (RM 7.3 (7.2/2))", T);
3734 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
3735 -- interface type if and only if the full type is descendant of
3736 -- the interface type.
3738 if Present (Interface_List (N))
3739 or else (Is_Tagged_Type (Priv_T)
3740 and then Has_Interfaces
3741 (Priv_T, Use_Full_View => False))
3743 if Is_Tagged_Type (Priv_T) then
3745 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
3748 if Is_Tagged_Type (T) then
3749 Collect_Interfaces (T, Full_T_Ifaces);
3752 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
3754 if Present (Iface) then
3756 ("interface in partial view& not implemented by full "
3757 & "type (RM-2005 7.3 (7.3/2))", T, Iface);
3760 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
3762 if Present (Iface) then
3764 ("interface & not implemented by partial " &
3765 "view (RM-2005 7.3 (7.3/2))", T, Iface);
3770 end Check_Interfaces;
3772 --------------------------------
3773 -- Check_Triggering_Statement --
3774 --------------------------------
3776 procedure Check_Triggering_Statement
3778 Error_Node : Node_Id;
3779 Is_Dispatching : out Boolean)
3784 Is_Dispatching := False;
3786 -- It is not possible to have a dispatching trigger if we are not in
3789 if Ada_Version >= Ada_2005
3790 and then Nkind (Trigger) = N_Procedure_Call_Statement
3791 and then Present (Parameter_Associations (Trigger))
3793 Param := First (Parameter_Associations (Trigger));
3795 if Is_Controlling_Actual (Param)
3796 and then Is_Interface (Etype (Param))
3798 if Is_Limited_Record (Etype (Param)) then
3799 Is_Dispatching := True;
3802 ("dispatching operation of limited or synchronized " &
3803 "interface required (RM 9.7.2(3))!", Error_Node);
3806 elsif Nkind (Trigger) = N_Explicit_Dereference then
3808 ("entry call or dispatching primitive of interface required",
3812 end Check_Triggering_Statement;
3814 --------------------------
3815 -- Find_Concurrent_Spec --
3816 --------------------------
3818 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
3819 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
3822 -- The type may have been given by an incomplete type declaration.
3823 -- Find full view now.
3825 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
3826 Spec_Id := Full_View (Spec_Id);
3830 end Find_Concurrent_Spec;
3832 --------------------------
3833 -- Install_Declarations --
3834 --------------------------
3836 procedure Install_Declarations (Spec : Entity_Id) is
3840 E := First_Entity (Spec);
3841 while Present (E) loop
3842 Prev := Current_Entity (E);
3843 Set_Current_Entity (E);
3844 Set_Is_Immediately_Visible (E);
3845 Set_Homonym (E, Prev);
3848 end Install_Declarations;