1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
33 with Exp_Ch9
; use Exp_Ch9
;
34 with Elists
; use Elists
;
35 with Fname
; use Fname
;
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_Eval
; use Sem_Eval
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Snames
; use Snames
;
61 with Stand
; use Stand
;
62 with Sinfo
; use Sinfo
;
64 with Tbuild
; use Tbuild
;
65 with Uintp
; use Uintp
;
67 package body Sem_Ch9
is
69 -----------------------
70 -- Local Subprograms --
71 -----------------------
73 function Allows_Lock_Free_Implementation
75 Lock_Free_Given
: Boolean := False) return Boolean;
76 -- This routine returns True iff N satisfies the following list of lock-
77 -- free restrictions for protected type declaration and protected body:
79 -- 1) Protected type declaration
80 -- May not contain entries
81 -- Protected subprogram declarations may not have non-elementary
85 -- Each protected subprogram body within N must satisfy:
86 -- May reference only one protected component
87 -- May not reference non-constant entities outside the protected
89 -- May not contain address representation items, allocators and
90 -- quantified expressions.
91 -- May not contain delay, goto, loop and procedure call
93 -- May not contain exported and imported entities
94 -- May not dereference access values
95 -- Function calls and attribute references must be static
97 -- If Lock_Free_Given is True, an error message is issued when False is
100 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
);
101 -- Given either a protected definition or a task definition in D, check
102 -- the corresponding restriction parameter identifier R, and if it is set,
103 -- count the entries (checking the static requirement), and compare with
104 -- the given maximum.
106 procedure Check_Interfaces
(N
: Node_Id
; T
: Entity_Id
);
107 -- N is an N_Protected_Type_Declaration or N_Task_Type_Declaration node.
108 -- Complete decoration of T and check legality of the covered interfaces.
110 procedure Check_Triggering_Statement
112 Error_Node
: Node_Id
;
113 Is_Dispatching
: out Boolean);
114 -- Examine the triggering statement of a select statement, conditional or
115 -- timed entry call. If Trigger is a dispatching call, return its status
116 -- in Is_Dispatching and check whether the primitive belongs to a limited
117 -- interface. If it does not, emit an error at Error_Node.
119 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
;
120 -- Find entity in corresponding task or protected declaration. Use full
121 -- view if first declaration was for an incomplete type.
123 -------------------------------------
124 -- Allows_Lock_Free_Implementation --
125 -------------------------------------
127 function Allows_Lock_Free_Implementation
129 Lock_Free_Given
: Boolean := False) return Boolean
132 -- Errors_Count is a count of errors detected by the compiler so far
133 -- when Lock_Free_Given is True.
136 pragma Assert
(Nkind_In
(N
, N_Protected_Type_Declaration
,
139 -- The lock-free implementation is currently enabled through a debug
140 -- flag. When Lock_Free_Given is True, an aspect Lock_Free forces the
141 -- lock-free implementation. In that case, the debug flag is not needed.
143 if not Lock_Free_Given
and then not Debug_Flag_9
then
147 -- Get the number of errors detected by the compiler so far
149 if Lock_Free_Given
then
150 Errors_Count
:= Serious_Errors_Detected
;
153 -- Protected type declaration case
155 if Nkind
(N
) = N_Protected_Type_Declaration
then
157 Pdef
: constant Node_Id
:= Protected_Definition
(N
);
158 Priv_Decls
: constant List_Id
:= Private_Declarations
(Pdef
);
159 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Pdef
);
163 -- Examine the visible and the private declarations
165 Decl
:= First
(Vis_Decls
);
166 while Present
(Decl
) loop
168 -- Entries and entry families are not allowed by the lock-free
171 if Nkind
(Decl
) = N_Entry_Declaration
then
172 if Lock_Free_Given
then
174 ("entry not allowed when Lock_Free given", Decl
);
179 -- Non-elementary parameters in protected procedure are not
180 -- allowed by the lock-free restrictions.
182 elsif Nkind
(Decl
) = N_Subprogram_Declaration
184 Nkind
(Specification
(Decl
)) = N_Procedure_Specification
186 Present
(Parameter_Specifications
(Specification
(Decl
)))
189 Par_Specs
: constant List_Id
:=
190 Parameter_Specifications
191 (Specification
(Decl
));
196 Par
:= First
(Par_Specs
);
197 while Present
(Par
) loop
198 if not Is_Elementary_Type
199 (Etype
(Defining_Identifier
(Par
)))
201 if Lock_Free_Given
then
203 ("non-elementary parameter& not allowed "
204 & "when Lock_Free given",
205 Par
, Defining_Identifier
(Par
));
216 -- Examine private declarations after visible declarations
219 and then List_Containing
(Decl
) = Vis_Decls
221 Decl
:= First
(Priv_Decls
);
228 -- Protected body case
231 Protected_Body_Case
: declare
232 Decls
: constant List_Id
:= Declarations
(N
);
233 Pid
: constant Entity_Id
:= Corresponding_Spec
(N
);
234 Prot_Typ_Decl
: constant Node_Id
:= Parent
(Pid
);
235 Prot_Def
: constant Node_Id
:=
236 Protected_Definition
(Prot_Typ_Decl
);
237 Priv_Decls
: constant List_Id
:=
238 Private_Declarations
(Prot_Def
);
241 function Satisfies_Lock_Free_Requirements
242 (Sub_Body
: Node_Id
) return Boolean;
243 -- Return True if protected subprogram body Sub_Body satisfies all
244 -- requirements of a lock-free implementation.
246 --------------------------------------
247 -- Satisfies_Lock_Free_Requirements --
248 --------------------------------------
250 function Satisfies_Lock_Free_Requirements
251 (Sub_Body
: Node_Id
) return Boolean
253 Is_Procedure
: constant Boolean :=
254 Ekind
(Corresponding_Spec
(Sub_Body
)) =
256 -- Indicates if Sub_Body is a procedure body
258 Comp
: Entity_Id
:= Empty
;
259 -- Track the current component which the body references
262 -- Errors_Count is a count of errors detected by the compiler
263 -- so far when Lock_Free_Given is True.
265 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
266 -- Check that node N meets the lock free restrictions
272 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
273 Kind
: constant Node_Kind
:= Nkind
(N
);
275 -- The following function belongs in sem_eval ???
277 function Is_Static_Function
(Attr
: Node_Id
) return Boolean;
278 -- Given an attribute reference node Attr, return True if
279 -- Attr denotes a static function according to the rules in
282 ------------------------
283 -- Is_Static_Function --
284 ------------------------
286 function Is_Static_Function
287 (Attr
: Node_Id
) return Boolean
292 pragma Assert
(Nkind
(Attr
) = N_Attribute_Reference
);
294 case Attribute_Name
(Attr
) is
301 Name_Wide_Wide_Value
=>
303 -- A language-defined attribute denotes a static
304 -- function if the prefix denotes a static scalar
305 -- subtype, and if the parameter and result types
306 -- are scalar (RM 4.9 (22)).
308 if Is_Scalar_Type
(Etype
(Attr
))
309 and then Is_Scalar_Type
(Etype
(Prefix
(Attr
)))
311 Is_OK_Static_Subtype
(Etype
(Prefix
(Attr
)))
313 Para
:= First
(Expressions
(Attr
));
315 while Present
(Para
) loop
316 if not Is_Scalar_Type
(Etype
(Para
)) then
329 when others => return False;
331 end Is_Static_Function
;
333 -- Start of processing for Check_Node
337 -- Allocators restricted
339 if Kind
= N_Allocator
then
340 if Lock_Free_Given
then
341 Error_Msg_N
("allocator not allowed", N
);
347 -- Aspects Address, Export and Import restricted
349 elsif Kind
= N_Aspect_Specification
then
351 Asp_Name
: constant Name_Id
:=
352 Chars
(Identifier
(N
));
353 Asp_Id
: constant Aspect_Id
:=
354 Get_Aspect_Id
(Asp_Name
);
357 if Asp_Id
= Aspect_Address
or else
358 Asp_Id
= Aspect_Export
or else
359 Asp_Id
= Aspect_Import
361 Error_Msg_Name_1
:= Asp_Name
;
363 if Lock_Free_Given
then
364 Error_Msg_N
("aspect% not allowed", N
);
372 -- Address attribute definition clause restricted
374 elsif Kind
= N_Attribute_Definition_Clause
375 and then Get_Attribute_Id
(Chars
(N
)) =
378 Error_Msg_Name_1
:= Chars
(N
);
380 if Lock_Free_Given
then
381 if From_Aspect_Specification
(N
) then
382 Error_Msg_N
("aspect% not allowed", N
);
384 Error_Msg_N
("% clause not allowed", N
);
392 -- Non-static Attribute references that don't denote a
393 -- static function restricted.
395 elsif Kind
= N_Attribute_Reference
396 and then not Is_OK_Static_Expression
(N
)
397 and then not Is_Static_Function
(N
)
399 if Lock_Free_Given
then
401 ("non-static attribute reference not allowed", N
);
407 -- Delay statements restricted
409 elsif Kind
in N_Delay_Statement
then
410 if Lock_Free_Given
then
411 Error_Msg_N
("delay not allowed", N
);
417 -- Dereferences of access values restricted
419 elsif Kind
= N_Explicit_Dereference
420 or else (Kind
= N_Selected_Component
421 and then Is_Access_Type
(Etype
(Prefix
(N
))))
423 if Lock_Free_Given
then
425 ("dereference of access value not allowed", N
);
431 -- Non-static function calls restricted
433 elsif Kind
= N_Function_Call
434 and then not Is_OK_Static_Expression
(N
)
436 if Lock_Free_Given
then
438 ("non-static function call not allowed", N
);
444 -- Goto statements restricted
446 elsif Kind
= N_Goto_Statement
then
447 if Lock_Free_Given
then
448 Error_Msg_N
("goto statement not allowed", N
);
456 elsif Kind
= N_Identifier
457 and then Present
(Entity
(N
))
460 Id
: constant Entity_Id
:= Entity
(N
);
461 Sub_Id
: constant Entity_Id
:=
462 Corresponding_Spec
(Sub_Body
);
465 -- Prohibit references to non-constant entities
466 -- outside the protected subprogram scope.
468 if Ekind
(Id
) in Assignable_Kind
470 Scope_Within_Or_Same
(Scope
(Id
), Sub_Id
)
474 Protected_Body_Subprogram
(Sub_Id
))
476 if Lock_Free_Given
then
478 ("reference to global variable& not " &
487 -- Loop statements restricted
489 elsif Kind
= N_Loop_Statement
then
490 if Lock_Free_Given
then
491 Error_Msg_N
("loop not allowed", N
);
497 -- Pragmas Export and Import restricted
499 elsif Kind
= N_Pragma
then
501 Prag_Name
: constant Name_Id
:= Pragma_Name
(N
);
502 Prag_Id
: constant Pragma_Id
:=
503 Get_Pragma_Id
(Prag_Name
);
506 if Prag_Id
= Pragma_Export
507 or else Prag_Id
= Pragma_Import
509 Error_Msg_Name_1
:= Prag_Name
;
511 if Lock_Free_Given
then
512 if From_Aspect_Specification
(N
) then
513 Error_Msg_N
("aspect% not allowed", N
);
515 Error_Msg_N
("pragma% not allowed", N
);
525 -- Procedure call statements restricted
527 elsif Kind
= N_Procedure_Call_Statement
then
528 if Lock_Free_Given
then
529 Error_Msg_N
("procedure call not allowed", N
);
535 -- Quantified expression restricted. Note that we have
536 -- to check the original node as well, since at this
537 -- stage, it may have been rewritten.
539 elsif Kind
= N_Quantified_Expression
541 Nkind
(Original_Node
(N
)) = N_Quantified_Expression
543 if Lock_Free_Given
then
545 ("quantified expression not allowed", N
);
553 -- A protected subprogram (function or procedure) may
554 -- reference only one component of the protected type, plus
555 -- the type of the component must support atomic operation.
557 if Kind
= N_Identifier
558 and then Present
(Entity
(N
))
561 Id
: constant Entity_Id
:= Entity
(N
);
563 Comp_Id
: Entity_Id
:= Empty
;
564 Comp_Type
: Entity_Id
;
567 if Ekind
(Id
) = E_Component
then
570 elsif Ekind_In
(Id
, E_Constant
, E_Variable
)
571 and then Present
(Prival_Link
(Id
))
573 Comp_Id
:= Prival_Link
(Id
);
576 if Present
(Comp_Id
) then
577 Comp_Decl
:= Parent
(Comp_Id
);
578 Comp_Type
:= Etype
(Comp_Id
);
580 if Nkind
(Comp_Decl
) = N_Component_Declaration
581 and then Is_List_Member
(Comp_Decl
)
582 and then List_Containing
(Comp_Decl
) = Priv_Decls
584 -- Skip generic types since, in that case, we
585 -- will not build a body anyway (in the generic
586 -- template), and the size in the template may
587 -- have a fake value.
589 if not Is_Generic_Type
(Comp_Type
) then
591 -- Make sure the protected component type has
592 -- size and alignment fields set at this
593 -- point whenever this is possible.
595 Layout_Type
(Comp_Type
);
598 Support_Atomic_Primitives
(Comp_Type
)
600 if Lock_Free_Given
then
602 ("type of& must support atomic " &
612 -- Check if another protected component has
613 -- already been accessed by the subprogram body.
618 elsif Comp
/= Comp_Id
then
619 if Lock_Free_Given
then
621 ("only one protected component allowed",
636 function Check_All_Nodes
is new Traverse_Func
(Check_Node
);
638 -- Start of processing for Satisfies_Lock_Free_Requirements
641 -- Get the number of errors detected by the compiler so far
643 if Lock_Free_Given
then
644 Errors_Count
:= Serious_Errors_Detected
;
647 if Check_All_Nodes
(Sub_Body
) = OK
648 and then (not Lock_Free_Given
649 or else Errors_Count
= Serious_Errors_Detected
)
651 -- Establish a relation between the subprogram body and the
652 -- unique protected component it references.
654 if Present
(Comp
) then
655 Lock_Free_Subprogram_Table
.Append
656 (Lock_Free_Subprogram
'(Sub_Body, Comp));
663 end Satisfies_Lock_Free_Requirements;
665 -- Start of processing for Protected_Body_Case
668 Decl := First (Decls);
669 while Present (Decl) loop
670 if Nkind (Decl) = N_Subprogram_Body
671 and then not Satisfies_Lock_Free_Requirements (Decl)
673 if Lock_Free_Given then
675 ("illegal body when Lock_Free given", Decl);
683 end Protected_Body_Case;
686 -- When Lock_Free is given, check if no error has been detected during
690 and then Errors_Count /= Serious_Errors_Detected
696 end Allows_Lock_Free_Implementation;
698 -----------------------------
699 -- Analyze_Abort_Statement --
700 -----------------------------
702 procedure Analyze_Abort_Statement (N : Node_Id) is
706 Tasking_Used := True;
707 Check_SPARK_05_Restriction ("abort statement is not allowed", N);
709 T_Name := First (Names (N));
710 while Present (T_Name) loop
713 if Is_Task_Type (Etype (T_Name))
714 or else (Ada_Version >= Ada_2005
715 and then Ekind (Etype (T_Name)) = E_Class_Wide_Type
716 and then Is_Interface (Etype (T_Name))
717 and then Is_Task_Interface (Etype (T_Name)))
721 if Ada_Version >= Ada_2005 then
722 Error_Msg_N ("expect task name or task interface class-wide "
723 & "object for ABORT", T_Name);
725 Error_Msg_N ("expect task name for ABORT", T_Name);
734 Check_Restriction (No_Abort_Statements, N);
735 Check_Potentially_Blocking_Operation (N);
736 end Analyze_Abort_Statement;
738 --------------------------------
739 -- Analyze_Accept_Alternative --
740 --------------------------------
742 procedure Analyze_Accept_Alternative (N : Node_Id) is
744 Tasking_Used := True;
746 if Present (Pragmas_Before (N)) then
747 Analyze_List (Pragmas_Before (N));
750 if Present (Condition (N)) then
751 Analyze_And_Resolve (Condition (N), Any_Boolean);
754 Analyze (Accept_Statement (N));
756 if Is_Non_Empty_List (Statements (N)) then
757 Analyze_Statements (Statements (N));
759 end Analyze_Accept_Alternative;
761 ------------------------------
762 -- Analyze_Accept_Statement --
763 ------------------------------
765 procedure Analyze_Accept_Statement (N : Node_Id) is
766 Nam : constant Entity_Id := Entry_Direct_Name (N);
767 Formals : constant List_Id := Parameter_Specifications (N);
768 Index : constant Node_Id := Entry_Index (N);
769 Stats : constant Node_Id := Handled_Statement_Sequence (N);
770 Accept_Id : Entity_Id;
771 Entry_Nam : Entity_Id;
774 Task_Nam : Entity_Id;
777 Tasking_Used := True;
778 Check_SPARK_05_Restriction ("accept statement is not allowed", N);
780 -- Entry name is initialized to Any_Id. It should get reset to the
781 -- matching entry entity. An error is signalled if it is not reset.
785 for J in reverse 0 .. Scope_Stack.Last loop
786 Task_Nam := Scope_Stack.Table (J).Entity;
787 exit when Ekind (Etype (Task_Nam)) = E_Task_Type;
788 Kind := Ekind (Task_Nam);
790 if Kind /= E_Block and then Kind /= E_Loop
791 and then not Is_Entry (Task_Nam)
793 Error_Msg_N ("enclosing body of accept must be a task", N);
798 if Ekind (Etype (Task_Nam)) /= E_Task_Type then
799 Error_Msg_N ("invalid context for accept statement", N);
803 -- In order to process the parameters, we create a defining identifier
804 -- that can be used as the name of the scope. The name of the accept
805 -- statement itself is not a defining identifier, and we cannot use
806 -- its name directly because the task may have any number of accept
807 -- statements for the same entry.
809 if Present (Index) then
810 Accept_Id := New_Internal_Entity
811 (E_Entry_Family, Current_Scope, Sloc (N), 'E
');
813 Accept_Id := New_Internal_Entity
814 (E_Entry, Current_Scope, Sloc (N), 'E
');
817 Set_Etype (Accept_Id, Standard_Void_Type);
818 Set_Accept_Address (Accept_Id, New_Elmt_List);
820 if Present (Formals) then
821 Push_Scope (Accept_Id);
822 Process_Formals (Formals, N);
823 Create_Extra_Formals (Accept_Id);
827 -- We set the default expressions processed flag because we don't need
828 -- default expression functions. This is really more like body entity
829 -- than a spec entity anyway.
831 Set_Default_Expressions_Processed (Accept_Id);
833 E := First_Entity (Etype (Task_Nam));
834 while Present (E) loop
835 if Chars (E) = Chars (Nam)
836 and then (Ekind (E) = Ekind (Accept_Id))
837 and then Type_Conformant (Accept_Id, E)
846 if Entry_Nam = Any_Id then
847 Error_Msg_N ("no entry declaration matches accept statement", N);
850 Set_Entity (Nam, Entry_Nam);
851 Generate_Reference (Entry_Nam, Nam, 'b
', Set_Ref => False);
852 Style.Check_Identifier (Nam, Entry_Nam);
855 -- Verify that the entry is not hidden by a procedure declared in the
856 -- current block (pathological but possible).
858 if Current_Scope /= Task_Nam then
863 E1 := First_Entity (Current_Scope);
864 while Present (E1) loop
865 if Ekind (E1) = E_Procedure
866 and then Chars (E1) = Chars (Entry_Nam)
867 and then Type_Conformant (E1, Entry_Nam)
869 Error_Msg_N ("entry name is not visible", N);
877 Set_Convention (Accept_Id, Convention (Entry_Nam));
878 Check_Fully_Conformant (Accept_Id, Entry_Nam, N);
880 for J in reverse 0 .. Scope_Stack.Last loop
881 exit when Task_Nam = Scope_Stack.Table (J).Entity;
883 if Entry_Nam = Scope_Stack.Table (J).Entity then
884 Error_Msg_N ("duplicate accept statement for same entry", N);
894 when N_Task_Body | N_Compilation_Unit =>
896 when N_Asynchronous_Select =>
897 Error_Msg_N ("accept statements are not allowed within" &
898 " an asynchronous select inner" &
899 " to the enclosing task body", N);
907 if Ekind (E) = E_Entry_Family then
909 Error_Msg_N ("missing entry index in accept for entry family", N);
911 Analyze_And_Resolve (Index, Entry_Index_Type (E));
912 Apply_Range_Check (Index, Entry_Index_Type (E));
915 elsif Present (Index) then
916 Error_Msg_N ("invalid entry index in accept for simple entry", N);
919 -- If label declarations present, analyze them. They are declared in the
920 -- enclosing task, but their enclosing scope is the entry itself, so
921 -- that goto's to the label are recognized as local to the accept.
923 if Present (Declarations (N)) then
929 Decl := First (Declarations (N));
930 while Present (Decl) loop
934 (Nkind (Decl) = N_Implicit_Label_Declaration);
936 Id := Defining_Identifier (Decl);
937 Set_Enclosing_Scope (Id, Entry_Nam);
943 -- If statements are present, they must be analyzed in the context of
944 -- the entry, so that references to formals are correctly resolved. We
945 -- also have to add the declarations that are required by the expansion
946 -- of the accept statement in this case if expansion active.
948 -- In the case of a select alternative of a selective accept, the
949 -- expander references the address declaration even if there is no
952 -- We also need to create the renaming declarations for the local
953 -- variables that will replace references to the formals within the
956 Exp_Ch9.Expand_Accept_Declarations (N, Entry_Nam);
958 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
959 -- fields on all entry formals (this loop ignores all other entities).
960 -- Reset Referenced, Referenced_As_xxx and Has_Pragma_Unreferenced as
961 -- well, so that we can post accurate warnings on each accept statement
962 -- for the same entry.
964 E := First_Entity (Entry_Nam);
965 while Present (E) loop
966 if Is_Formal (E) then
967 Set_Never_Set_In_Source (E, True);
968 Set_Is_True_Constant (E, False);
969 Set_Current_Value (E, Empty);
970 Set_Referenced (E, False);
971 Set_Referenced_As_LHS (E, False);
972 Set_Referenced_As_Out_Parameter (E, False);
973 Set_Has_Pragma_Unreferenced (E, False);
979 -- Analyze statements if present
981 if Present (Stats) then
982 Push_Scope (Entry_Nam);
983 Install_Declarations (Entry_Nam);
985 Set_Actual_Subtypes (N, Current_Scope);
988 Process_End_Label (Handled_Statement_Sequence (N), 't
', Entry_Nam);
992 -- Some warning checks
994 Check_Potentially_Blocking_Operation (N);
995 Check_References (Entry_Nam, N);
996 Set_Entry_Accepted (Entry_Nam);
997 end Analyze_Accept_Statement;
999 ---------------------------------
1000 -- Analyze_Asynchronous_Select --
1001 ---------------------------------
1003 procedure Analyze_Asynchronous_Select (N : Node_Id) is
1004 Is_Disp_Select : Boolean := False;
1008 Tasking_Used := True;
1009 Check_SPARK_05_Restriction ("select statement is not allowed", N);
1010 Check_Restriction (Max_Asynchronous_Select_Nesting, N);
1011 Check_Restriction (No_Select_Statements, N);
1013 if Ada_Version >= Ada_2005 then
1014 Trigger := Triggering_Statement (Triggering_Alternative (N));
1018 -- Ada 2005 (AI-345): Check for a potential dispatching select
1020 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1023 -- Ada 2005 (AI-345): The expansion of the dispatching asynchronous
1024 -- select will have to duplicate the triggering statements. Postpone
1025 -- the analysis of the statements till expansion. Analyze only if the
1026 -- expander is disabled in order to catch any semantic errors.
1028 if Is_Disp_Select then
1029 if not Expander_Active then
1030 Analyze_Statements (Statements (Abortable_Part (N)));
1031 Analyze (Triggering_Alternative (N));
1034 -- Analyze the statements. We analyze statements in the abortable part,
1035 -- because this is the section that is executed first, and that way our
1036 -- remembering of saved values and checks is accurate.
1039 Analyze_Statements (Statements (Abortable_Part (N)));
1040 Analyze (Triggering_Alternative (N));
1042 end Analyze_Asynchronous_Select;
1044 ------------------------------------
1045 -- Analyze_Conditional_Entry_Call --
1046 ------------------------------------
1048 procedure Analyze_Conditional_Entry_Call (N : Node_Id) is
1049 Trigger : constant Node_Id :=
1050 Entry_Call_Statement (Entry_Call_Alternative (N));
1051 Is_Disp_Select : Boolean := False;
1054 Tasking_Used := True;
1055 Check_SPARK_05_Restriction ("select statement is not allowed", N);
1056 Check_Restriction (No_Select_Statements, N);
1058 -- Ada 2005 (AI-345): The trigger may be a dispatching call
1060 if Ada_Version >= Ada_2005 then
1062 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
1065 if List_Length (Else_Statements (N)) = 1
1066 and then Nkind (First (Else_Statements (N))) in N_Delay_Statement
1069 ("suspicious form of conditional entry call??!", N);
1071 ("\`SELECT OR` may be intended rather than `SELECT ELSE`??!", N);
1074 -- Postpone the analysis of the statements till expansion. Analyze only
1075 -- if the expander is disabled in order to catch any semantic errors.
1077 if Is_Disp_Select then
1078 if not Expander_Active then
1079 Analyze (Entry_Call_Alternative (N));
1080 Analyze_Statements (Else_Statements (N));
1083 -- Regular select analysis
1086 Analyze (Entry_Call_Alternative (N));
1087 Analyze_Statements (Else_Statements (N));
1089 end Analyze_Conditional_Entry_Call;
1091 --------------------------------
1092 -- Analyze_Delay_Alternative --
1093 --------------------------------
1095 procedure Analyze_Delay_Alternative (N : Node_Id) is
1100 Tasking_Used := True;
1101 Check_Restriction (No_Delay, N);
1103 if Present (Pragmas_Before (N)) then
1104 Analyze_List (Pragmas_Before (N));
1107 if Nkind_In (Parent (N), N_Selective_Accept, N_Timed_Entry_Call) then
1108 Expr := Expression (Delay_Statement (N));
1110 -- Defer full analysis until the statement is expanded, to insure
1111 -- that generated code does not move past the guard. The delay
1112 -- expression is only evaluated if the guard is open.
1114 if Nkind (Delay_Statement (N)) = N_Delay_Relative_Statement then
1115 Preanalyze_And_Resolve (Expr, Standard_Duration);
1117 Preanalyze_And_Resolve (Expr);
1120 Typ := First_Subtype (Etype (Expr));
1122 if Nkind (Delay_Statement (N)) = N_Delay_Until_Statement
1123 and then not Is_RTE (Typ, RO_CA_Time)
1124 and then not Is_RTE (Typ, RO_RT_Time)
1126 Error_Msg_N ("expect Time types for `DELAY UNTIL`", Expr);
1129 Check_Restriction (No_Fixed_Point, Expr);
1132 Analyze (Delay_Statement (N));
1135 if Present (Condition (N)) then
1136 Analyze_And_Resolve (Condition (N), Any_Boolean);
1139 if Is_Non_Empty_List (Statements (N)) then
1140 Analyze_Statements (Statements (N));
1142 end Analyze_Delay_Alternative;
1144 ----------------------------
1145 -- Analyze_Delay_Relative --
1146 ----------------------------
1148 procedure Analyze_Delay_Relative (N : Node_Id) is
1149 E : constant Node_Id := Expression (N);
1151 Tasking_Used := True;
1152 Check_SPARK_05_Restriction ("delay statement is not allowed", N);
1153 Check_Restriction (No_Relative_Delay, N);
1154 Check_Restriction (No_Delay, N);
1155 Check_Potentially_Blocking_Operation (N);
1156 Analyze_And_Resolve (E, Standard_Duration);
1157 Check_Restriction (No_Fixed_Point, E);
1158 end Analyze_Delay_Relative;
1160 -------------------------
1161 -- Analyze_Delay_Until --
1162 -------------------------
1164 procedure Analyze_Delay_Until (N : Node_Id) is
1165 E : constant Node_Id := Expression (N);
1169 Tasking_Used := True;
1170 Check_SPARK_05_Restriction ("delay statement is not allowed", N);
1171 Check_Restriction (No_Delay, N);
1172 Check_Potentially_Blocking_Operation (N);
1174 Typ := First_Subtype (Etype (E));
1176 if not Is_RTE (Typ, RO_CA_Time) and then
1177 not Is_RTE (Typ, RO_RT_Time)
1179 Error_Msg_N ("expect Time types for `DELAY UNTIL`", E);
1181 end Analyze_Delay_Until;
1183 ------------------------
1184 -- Analyze_Entry_Body --
1185 ------------------------
1187 procedure Analyze_Entry_Body (N : Node_Id) is
1188 Id : constant Entity_Id := Defining_Identifier (N);
1189 Decls : constant List_Id := Declarations (N);
1190 Stats : constant Node_Id := Handled_Statement_Sequence (N);
1191 Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1192 P_Type : constant Entity_Id := Current_Scope;
1194 Entry_Name : Entity_Id;
1197 -- An entry body "freezes" the contract of the nearest enclosing package
1198 -- body and all other contracts encountered in the same declarative part
1199 -- up to and excluding the entry body. This ensures that any annotations
1200 -- referenced by the contract of an entry or subprogram body declared
1201 -- within the current protected body are available.
1203 Analyze_Previous_Contracts (N);
1205 Tasking_Used := True;
1207 -- Entry_Name is initialized to Any_Id. It should get reset to the
1208 -- matching entry entity. An error is signalled if it is not reset.
1210 Entry_Name := Any_Id;
1214 if Present (Entry_Index_Specification (Formals)) then
1215 Set_Ekind (Id, E_Entry_Family);
1217 Set_Ekind (Id, E_Entry);
1220 Set_Etype (Id, Standard_Void_Type);
1221 Set_Scope (Id, Current_Scope);
1222 Set_Accept_Address (Id, New_Elmt_List);
1224 -- Set the SPARK_Mode from the current context (may be overwritten later
1225 -- with an explicit pragma).
1227 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
1228 Set_SPARK_Pragma_Inherited (Id);
1230 -- Analyze any aspect specifications that appear on the entry body
1232 if Has_Aspects (N) then
1233 Analyze_Aspect_Specifications_On_Body_Or_Stub (N);
1236 E := First_Entity (P_Type);
1237 while Present (E) loop
1238 if Chars (E) = Chars (Id)
1239 and then (Ekind (E) = Ekind (Id))
1240 and then Type_Conformant (Id, E)
1243 Set_Convention (Id, Convention (E));
1244 Set_Corresponding_Body (Parent (E), Id);
1245 Check_Fully_Conformant (Id, E, N);
1247 if Ekind (Id) = E_Entry_Family then
1248 if not Fully_Conformant_Discrete_Subtypes (
1249 Discrete_Subtype_Definition (Parent (E)),
1250 Discrete_Subtype_Definition
1251 (Entry_Index_Specification (Formals)))
1254 ("index not fully conformant with previous declaration",
1255 Discrete_Subtype_Definition
1256 (Entry_Index_Specification (Formals)));
1259 -- The elaboration of the entry body does not recompute the
1260 -- bounds of the index, which may have side effects. Inherit
1261 -- the bounds from the entry declaration. This is critical
1262 -- if the entry has a per-object constraint. If a bound is
1263 -- given by a discriminant, it must be reanalyzed in order
1264 -- to capture the discriminal of the current entry, rather
1265 -- than that of the protected type.
1268 Index_Spec : constant Node_Id :=
1269 Entry_Index_Specification (Formals);
1271 Def : constant Node_Id :=
1273 (Discrete_Subtype_Definition (Parent (E)));
1278 (Discrete_Subtype_Definition (Index_Spec))) = N_Range
1280 Set_Etype (Def, Empty);
1281 Set_Analyzed (Def, False);
1283 -- Keep the original subtree to ensure a properly
1284 -- formed tree (e.g. for ASIS use).
1287 (Discrete_Subtype_Definition (Index_Spec), Def);
1289 Set_Analyzed (Low_Bound (Def), False);
1290 Set_Analyzed (High_Bound (Def), False);
1292 if Denotes_Discriminant (Low_Bound (Def)) then
1293 Set_Entity (Low_Bound (Def), Empty);
1296 if Denotes_Discriminant (High_Bound (Def)) then
1297 Set_Entity (High_Bound (Def), Empty);
1301 Make_Index (Def, Index_Spec);
1303 (Defining_Identifier (Index_Spec), Etype (Def));
1315 if Entry_Name = Any_Id then
1316 Error_Msg_N ("no entry declaration matches entry body", N);
1319 elsif Has_Completion (Entry_Name) then
1320 Error_Msg_N ("duplicate entry body", N);
1324 Set_Has_Completion (Entry_Name);
1325 Generate_Reference (Entry_Name, Id, 'b
', Set_Ref => False);
1326 Style.Check_Identifier (Id, Entry_Name);
1329 Exp_Ch9.Expand_Entry_Barrier (N, Entry_Name);
1330 Push_Scope (Entry_Name);
1332 Install_Declarations (Entry_Name);
1333 Set_Actual_Subtypes (N, Current_Scope);
1335 -- The entity for the protected subprogram corresponding to the entry
1336 -- has been created. We retain the name of this entity in the entry
1337 -- body, for use when the corresponding subprogram body is created.
1338 -- Note that entry bodies have no Corresponding_Spec, and there is no
1339 -- easy link back in the tree between the entry body and the entity for
1340 -- the entry itself, which is why we must propagate some attributes
1341 -- explicitly from spec to body.
1343 Set_Protected_Body_Subprogram
1344 (Id, Protected_Body_Subprogram (Entry_Name));
1346 Set_Entry_Parameters_Type
1347 (Id, Entry_Parameters_Type (Entry_Name));
1349 -- Add a declaration for the Protection object, renaming declarations
1350 -- for the discriminals and privals and finally a declaration for the
1351 -- entry family index (if applicable).
1354 and then Is_Protected_Type (P_Type)
1356 Install_Private_Data_Declarations
1357 (Sloc (N), Entry_Name, P_Type, N, Decls);
1360 if Present (Decls) then
1361 Analyze_Declarations (Decls);
1362 Inspect_Deferred_Constant_Completion (Decls);
1365 -- Process the contract of the subprogram body after all declarations
1366 -- have been analyzed. This ensures that any contract-related pragmas
1367 -- are available through the N_Contract node of the body.
1369 Analyze_Entry_Or_Subprogram_Body_Contract (Id);
1371 if Present (Stats) then
1375 -- Check for unreferenced variables etc. Before the Check_References
1376 -- call, we transfer Never_Set_In_Source and Referenced flags from
1377 -- parameters in the spec to the corresponding entities in the body,
1378 -- since we want the warnings on the body entities. Note that we do not
1379 -- have to transfer Referenced_As_LHS, since that flag can only be set
1380 -- for simple variables, but we include Has_Pragma_Unreferenced,
1381 -- which may have been specified for a formal in the body.
1383 -- At the same time, we set the flags on the spec entities to suppress
1384 -- any warnings on the spec formals, since we also scan the spec.
1385 -- Finally, we propagate the Entry_Component attribute to the body
1386 -- formals, for use in the renaming declarations created later for the
1387 -- formals (see exp_ch9.Add_Formal_Renamings).
1394 E1 := First_Entity (Entry_Name);
1395 while Present (E1) loop
1396 E2 := First_Entity (Id);
1397 while Present (E2) loop
1398 exit when Chars (E1) = Chars (E2);
1402 -- If no matching body entity, then we already had a detected
1403 -- error of some kind, so just don't worry about these warnings.
1409 if Ekind (E1) = E_Out_Parameter then
1410 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1411 Set_Never_Set_In_Source (E1, False);
1414 Set_Referenced (E2, Referenced (E1));
1415 Set_Referenced (E1);
1416 Set_Has_Pragma_Unreferenced (E2, Has_Pragma_Unreferenced (E1));
1417 Set_Entry_Component (E2, Entry_Component (E1));
1423 Check_References (Id);
1426 -- We still need to check references for the spec, since objects
1427 -- declared in the body are chained (in the First_Entity sense) to
1428 -- the spec rather than the body in the case of entries.
1430 Check_References (Entry_Name);
1432 -- Process the end label, and terminate the scope
1434 Process_End_Label (Handled_Statement_Sequence (N), 't
', Entry_Name);
1437 -- If this is an entry family, remove the loop created to provide
1438 -- a scope for the entry index.
1440 if Ekind (Id) = E_Entry_Family
1441 and then Present (Entry_Index_Specification (Formals))
1445 end Analyze_Entry_Body;
1447 ------------------------------------
1448 -- Analyze_Entry_Body_Formal_Part --
1449 ------------------------------------
1451 procedure Analyze_Entry_Body_Formal_Part (N : Node_Id) is
1452 Id : constant Entity_Id := Defining_Identifier (Parent (N));
1453 Index : constant Node_Id := Entry_Index_Specification (N);
1454 Formals : constant List_Id := Parameter_Specifications (N);
1457 Tasking_Used := True;
1459 if Present (Index) then
1462 -- The entry index functions like a loop variable, thus it is known
1463 -- to have a valid value.
1465 Set_Is_Known_Valid (Defining_Identifier (Index));
1468 if Present (Formals) then
1469 Set_Scope (Id, Current_Scope);
1471 Process_Formals (Formals, Parent (N));
1474 end Analyze_Entry_Body_Formal_Part;
1476 ------------------------------------
1477 -- Analyze_Entry_Call_Alternative --
1478 ------------------------------------
1480 procedure Analyze_Entry_Call_Alternative (N : Node_Id) is
1481 Call : constant Node_Id := Entry_Call_Statement (N);
1484 Tasking_Used := True;
1485 Check_SPARK_05_Restriction ("entry call is not allowed", N);
1487 if Present (Pragmas_Before (N)) then
1488 Analyze_List (Pragmas_Before (N));
1491 if Nkind (Call) = N_Attribute_Reference then
1493 -- Possibly a stream attribute, but definitely illegal. Other
1494 -- illegalities, such as procedure calls, are diagnosed after
1497 Error_Msg_N ("entry call alternative requires an entry call", Call);
1503 -- An indirect call in this context is illegal. A procedure call that
1504 -- does not involve a renaming of an entry is illegal as well, but this
1505 -- and other semantic errors are caught during resolution.
1507 if Nkind (Call) = N_Explicit_Dereference then
1509 ("entry call or dispatching primitive of interface required ", N);
1512 if Is_Non_Empty_List (Statements (N)) then
1513 Analyze_Statements (Statements (N));
1515 end Analyze_Entry_Call_Alternative;
1517 -------------------------------
1518 -- Analyze_Entry_Declaration --
1519 -------------------------------
1521 procedure Analyze_Entry_Declaration (N : Node_Id) is
1522 D_Sdef : constant Node_Id := Discrete_Subtype_Definition (N);
1523 Def_Id : constant Entity_Id := Defining_Identifier (N);
1524 Formals : constant List_Id := Parameter_Specifications (N);
1527 Generate_Definition (Def_Id);
1529 Tasking_Used := True;
1531 -- Case of no discrete subtype definition
1534 Set_Ekind (Def_Id, E_Entry);
1536 -- Processing for discrete subtype definition present
1539 Enter_Name (Def_Id);
1540 Set_Ekind (Def_Id, E_Entry_Family);
1542 Make_Index (D_Sdef, N, Def_Id);
1544 -- Check subtype with predicate in entry family
1546 Bad_Predicated_Subtype_Use
1547 ("subtype& has predicate, not allowed in entry family",
1548 D_Sdef, Etype (D_Sdef));
1550 -- Check entry family static bounds outside allowed limits
1552 -- Note: originally this check was not performed here, but in that
1553 -- case the check happens deep in the expander, and the message is
1554 -- posted at the wrong location, and omitted in -gnatc mode.
1555 -- If the type of the entry index is a generic formal, no check
1556 -- is possible. In an instance, the check is not static and a run-
1557 -- time exception will be raised if the bounds are unreasonable.
1560 PEI : constant Entity_Id := RTE (RE_Protected_Entry_Index);
1561 LB : constant Uint := Expr_Value (Type_Low_Bound (PEI));
1562 UB : constant Uint := Expr_Value (Type_High_Bound (PEI));
1569 -- No bounds checking if the type is generic or if previous error.
1570 -- In an instance the check is dynamic.
1572 if Is_Generic_Type (Etype (D_Sdef))
1574 or else Error_Posted (D_Sdef)
1578 elsif Nkind (D_Sdef) = N_Range then
1579 LBR := Low_Bound (D_Sdef);
1581 elsif Is_Entity_Name (D_Sdef)
1582 and then Is_Type (Entity (D_Sdef))
1584 LBR := Type_Low_Bound (Entity (D_Sdef));
1590 if Is_OK_Static_Expression (LBR)
1591 and then Expr_Value (LBR) < LB
1593 Error_Msg_Uint_1 := LB;
1594 Error_Msg_N ("entry family low bound must be '>'= ^!", D_Sdef);
1598 if Is_Generic_Type (Etype (D_Sdef))
1600 or else Error_Posted (D_Sdef)
1604 elsif Nkind (D_Sdef) = N_Range then
1605 UBR := High_Bound (D_Sdef);
1607 elsif Is_Entity_Name (D_Sdef)
1608 and then Is_Type (Entity (D_Sdef))
1610 UBR := Type_High_Bound (Entity (D_Sdef));
1616 if Is_OK_Static_Expression (UBR)
1617 and then Expr_Value (UBR) > UB
1619 Error_Msg_Uint_1 := UB;
1620 Error_Msg_N ("entry family high bound must be '<'= ^!", D_Sdef);
1630 Set_Etype (Def_Id, Standard_Void_Type);
1631 Set_Convention (Def_Id, Convention_Entry);
1632 Set_Accept_Address (Def_Id, New_Elmt_List);
1634 -- Set the SPARK_Mode from the current context (may be overwritten later
1635 -- with an explicit pragma). Task entries are excluded because they are
1636 -- not completed by entry bodies.
1638 if Ekind (Current_Scope) = E_Protected_Type then
1639 Set_SPARK_Pragma (Def_Id, SPARK_Mode_Pragma);
1640 Set_SPARK_Pragma_Inherited (Def_Id);
1645 if Present (Formals) then
1646 Set_Scope (Def_Id, Current_Scope);
1647 Push_Scope (Def_Id);
1648 Process_Formals (Formals, N);
1649 Create_Extra_Formals (Def_Id);
1653 if Ekind (Def_Id) = E_Entry then
1654 New_Overloaded_Entity (Def_Id);
1657 Generate_Reference_To_Formals (Def_Id);
1659 if Has_Aspects (N) then
1660 Analyze_Aspect_Specifications (N, Def_Id);
1662 end Analyze_Entry_Declaration;
1664 ---------------------------------------
1665 -- Analyze_Entry_Index_Specification --
1666 ---------------------------------------
1668 -- The Defining_Identifier of the entry index specification is local to the
1669 -- entry body, but it must be available in the entry barrier which is
1670 -- evaluated outside of the entry body. The index is eventually renamed as
1671 -- a run-time object, so is visibility is strictly a front-end concern. In
1672 -- order to make it available to the barrier, we create an additional
1673 -- scope, as for a loop, whose only declaration is the index name. This
1674 -- loop is not attached to the tree and does not appear as an entity local
1675 -- to the protected type, so its existence need only be known to routines
1676 -- that process entry families.
1678 procedure Analyze_Entry_Index_Specification (N : Node_Id) is
1679 Iden : constant Node_Id := Defining_Identifier (N);
1680 Def : constant Node_Id := Discrete_Subtype_Definition (N);
1681 Loop_Id : constant Entity_Id := Make_Temporary (Sloc (N), 'L
');
1684 Tasking_Used := True;
1687 -- There is no elaboration of the entry index specification. Therefore,
1688 -- if the index is a range, it is not resolved and expanded, but the
1689 -- bounds are inherited from the entry declaration, and reanalyzed.
1690 -- See Analyze_Entry_Body.
1692 if Nkind (Def) /= N_Range then
1693 Make_Index (Def, N);
1696 Set_Ekind (Loop_Id, E_Loop);
1697 Set_Scope (Loop_Id, Current_Scope);
1698 Push_Scope (Loop_Id);
1700 Set_Ekind (Iden, E_Entry_Index_Parameter);
1701 Set_Etype (Iden, Etype (Def));
1702 end Analyze_Entry_Index_Specification;
1704 ----------------------------
1705 -- Analyze_Protected_Body --
1706 ----------------------------
1708 procedure Analyze_Protected_Body (N : Node_Id) is
1709 Body_Id : constant Entity_Id := Defining_Identifier (N);
1712 Spec_Id : Entity_Id;
1713 -- This is initially the entity of the protected object or protected
1714 -- type involved, but is replaced by the protected type always in the
1715 -- case of a single protected declaration, since this is the proper
1716 -- scope to be used.
1719 -- This is the entity of the protected object or protected type
1720 -- involved, and is the entity used for cross-reference purposes (it
1721 -- differs from Spec_Id in the case of a single protected object, since
1722 -- Spec_Id is set to the protected type in this case).
1724 function Lock_Free_Disabled return Boolean;
1725 -- This routine returns False if the protected object has a Lock_Free
1726 -- aspect specification or a Lock_Free pragma that turns off the
1727 -- lock-free implementation (e.g. whose expression is False).
1729 ------------------------
1730 -- Lock_Free_Disabled --
1731 ------------------------
1733 function Lock_Free_Disabled return Boolean is
1734 Ritem : constant Node_Id :=
1736 (Spec_Id, Name_Lock_Free, Check_Parents => False);
1739 if Present (Ritem) then
1741 -- Pragma with one argument
1743 if Nkind (Ritem) = N_Pragma
1744 and then Present (Pragma_Argument_Associations (Ritem))
1750 (First (Pragma_Argument_Associations (Ritem)))));
1752 -- Aspect Specification with expression present
1754 elsif Nkind (Ritem) = N_Aspect_Specification
1755 and then Present (Expression (Ritem))
1757 return Is_False (Static_Boolean (Expression (Ritem)));
1759 -- Otherwise, return False
1767 end Lock_Free_Disabled;
1769 -- Start of processing for Analyze_Protected_Body
1772 -- A protected body "freezes" the contract of the nearest enclosing
1773 -- package body and all other contracts encountered in the same
1774 -- declarative part up to and excluding the protected body. This ensures
1775 -- that any annotations referenced by the contract of an entry or
1776 -- subprogram body declared within the current protected body are
1779 Analyze_Previous_Contracts (N);
1781 Tasking_Used := True;
1782 Set_Ekind (Body_Id, E_Protected_Body);
1783 Set_Etype (Body_Id, Standard_Void_Type);
1784 Spec_Id := Find_Concurrent_Spec (Body_Id);
1786 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Protected_Type then
1789 elsif Present (Spec_Id)
1790 and then Ekind (Etype (Spec_Id)) = E_Protected_Type
1791 and then not Comes_From_Source (Etype (Spec_Id))
1796 Error_Msg_N ("missing specification for protected body", Body_Id);
1801 Generate_Reference (Ref_Id, Body_Id, 'b
', Set_Ref => False);
1802 Style.Check_Identifier (Body_Id, Spec_Id);
1804 -- The declarations are always attached to the type
1806 if Ekind (Spec_Id) /= E_Protected_Type then
1807 Spec_Id := Etype (Spec_Id);
1810 if Has_Aspects (N) then
1811 Analyze_Aspect_Specifications (N, Body_Id);
1814 Push_Scope (Spec_Id);
1815 Set_Corresponding_Spec (N, Spec_Id);
1816 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
1817 Set_Has_Completion (Spec_Id);
1818 Install_Declarations (Spec_Id);
1819 Expand_Protected_Body_Declarations (N, Spec_Id);
1820 Last_E := Last_Entity (Spec_Id);
1822 Analyze_Declarations (Declarations (N));
1824 -- For visibility purposes, all entities in the body are private. Set
1825 -- First_Private_Entity accordingly, if there was no private part in the
1826 -- protected declaration.
1828 if No (First_Private_Entity (Spec_Id)) then
1829 if Present (Last_E) then
1830 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
1832 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
1836 Check_Completion (Body_Id);
1837 Check_References (Spec_Id);
1838 Process_End_Label (N, 't
', Ref_Id);
1841 -- When a Lock_Free aspect specification/pragma forces the lock-free
1842 -- implementation, verify the protected body meets all the restrictions,
1843 -- otherwise Allows_Lock_Free_Implementation issues an error message.
1845 if Uses_Lock_Free (Spec_Id) then
1846 if not Allows_Lock_Free_Implementation (N, True) then
1850 -- In other cases, if there is no aspect specification/pragma that
1851 -- disables the lock-free implementation, check both the protected
1852 -- declaration and body satisfy the lock-free restrictions.
1854 elsif not Lock_Free_Disabled
1855 and then Allows_Lock_Free_Implementation (Parent (Spec_Id))
1856 and then Allows_Lock_Free_Implementation (N)
1858 Set_Uses_Lock_Free (Spec_Id);
1860 end Analyze_Protected_Body;
1862 ----------------------------------
1863 -- Analyze_Protected_Definition --
1864 ----------------------------------
1866 procedure Analyze_Protected_Definition (N : Node_Id) is
1870 procedure Undelay_Itypes (T : Entity_Id);
1871 -- Itypes created for the private components of a protected type
1872 -- do not receive freeze nodes, because there is no scope in which
1873 -- they can be elaborated, and they can depend on discriminants of
1874 -- the enclosed protected type. Given that the components can be
1875 -- composite types with inner components, we traverse recursively
1876 -- the private components of the protected type, and indicate that
1877 -- all itypes within are frozen. This ensures that no freeze nodes
1878 -- will be generated for them. In the case of itypes that are access
1879 -- types we need to complete their representation by calling layout,
1880 -- which would otherwise be invoked when freezing a type.
1882 -- On the other hand, components of the corresponding record are
1883 -- frozen (or receive itype references) as for other records.
1885 --------------------
1886 -- Undelay_Itypes --
1887 --------------------
1889 procedure Undelay_Itypes (T : Entity_Id) is
1893 if Is_Protected_Type (T) then
1894 Comp := First_Private_Entity (T);
1895 elsif Is_Record_Type (T) then
1896 Comp := First_Entity (T);
1901 while Present (Comp) loop
1903 and then Is_Itype (Comp)
1905 Set_Has_Delayed_Freeze (Comp, False);
1906 Set_Is_Frozen (Comp);
1908 if Is_Access_Type (Comp) then
1912 if Is_Record_Type (Comp)
1913 or else Is_Protected_Type (Comp)
1915 Undelay_Itypes (Comp);
1923 -- Start of processing for Analyze_Protected_Definition
1926 Tasking_Used := True;
1927 Check_SPARK_05_Restriction ("protected definition is not allowed", N);
1928 Analyze_Declarations (Visible_Declarations (N));
1930 if Present (Private_Declarations (N))
1931 and then not Is_Empty_List (Private_Declarations (N))
1933 L := Last_Entity (Current_Scope);
1934 Analyze_Declarations (Private_Declarations (N));
1937 Set_First_Private_Entity (Current_Scope, Next_Entity (L));
1939 Set_First_Private_Entity (Current_Scope,
1940 First_Entity (Current_Scope));
1944 E := First_Entity (Current_Scope);
1945 while Present (E) loop
1946 if Ekind_In (E, E_Function, E_Procedure) then
1947 Set_Convention (E, Convention_Protected);
1949 Propagate_Concurrent_Flags (Current_Scope, Etype (E));
1955 Undelay_Itypes (Current_Scope);
1957 Check_Max_Entries (N, Max_Protected_Entries);
1958 Process_End_Label (N, 'e
', Current_Scope);
1959 end Analyze_Protected_Definition;
1961 ----------------------------------------
1962 -- Analyze_Protected_Type_Declaration --
1963 ----------------------------------------
1965 procedure Analyze_Protected_Type_Declaration (N : Node_Id) is
1966 Def_Id : constant Entity_Id := Defining_Identifier (N);
1971 if No_Run_Time_Mode then
1972 Error_Msg_CRT ("protected type", N);
1974 if Has_Aspects (N) then
1975 Analyze_Aspect_Specifications (N, Def_Id);
1981 Tasking_Used := True;
1982 Check_Restriction (No_Protected_Types, N);
1984 T := Find_Type_Name (N);
1986 -- In the case of an incomplete type, use the full view, unless it's not
1987 -- present (as can occur for an incomplete view from a limited with).
1989 if Ekind (T) = E_Incomplete_Type and then Present (Full_View (T)) then
1991 Set_Completion_Referenced (T);
1994 Set_Ekind (T, E_Protected_Type);
1995 Set_Is_First_Subtype (T);
1996 Init_Size_Align (T);
1998 Set_Has_Delayed_Freeze (T);
1999 Set_Stored_Constraint (T, No_Elist);
2001 -- Mark this type as a protected type for the sake of restrictions,
2002 -- unless the protected type is declared in a private part of a package
2003 -- of the runtime. With this exception, the Suspension_Object from
2004 -- Ada.Synchronous_Task_Control can be implemented using a protected
2005 -- object without triggering violations of No_Local_Protected_Objects
2006 -- when the user locally declares such an object. This may look like a
2007 -- trick, but the user doesn't have to know how Suspension_Object is
2010 if In_Private_Part (Current_Scope)
2011 and then Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit))
2013 Set_Has_Protected (T, False);
2015 Set_Has_Protected (T);
2018 -- Set the SPARK_Mode from the current context (may be overwritten later
2019 -- with an explicit pragma).
2021 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
2022 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
2023 Set_SPARK_Pragma_Inherited (T);
2024 Set_SPARK_Aux_Pragma_Inherited (T);
2028 if Ada_Version >= Ada_2005 then
2029 Check_Interfaces (N, T);
2032 if Present (Discriminant_Specifications (N)) then
2033 if Has_Discriminants (T) then
2035 -- Install discriminants. Also, verify conformance of
2036 -- discriminants of previous and current view. ???
2038 Install_Declarations (T);
2040 Process_Discriminants (N);
2044 Set_Is_Constrained (T, not Has_Discriminants (T));
2046 -- If aspects are present, analyze them now. They can make references to
2047 -- the discriminants of the type, but not to any components.
2049 if Has_Aspects (N) then
2051 -- The protected type is the full view of a private type. Analyze the
2052 -- aspects with the entity of the private type to ensure that after
2053 -- both views are exchanged, the aspect are actually associated with
2056 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2057 Analyze_Aspect_Specifications (N, T);
2059 Analyze_Aspect_Specifications (N, Def_Id);
2063 Analyze (Protected_Definition (N));
2065 -- In the case where the protected type is declared at a nested level
2066 -- and the No_Local_Protected_Objects restriction applies, issue a
2067 -- warning that objects of the type will violate the restriction.
2069 if Restriction_Check_Required (No_Local_Protected_Objects)
2070 and then not Is_Library_Level_Entity (T)
2071 and then Comes_From_Source (T)
2073 Error_Msg_Sloc := Restrictions_Loc (No_Local_Protected_Objects);
2075 if Error_Msg_Sloc = No_Location then
2077 ("objects of this type will violate " &
2078 "`No_Local_Protected_Objects`??", N);
2081 ("objects of this type will violate " &
2082 "`No_Local_Protected_Objects`#??", N);
2086 -- Protected types with entries are controlled (because of the
2087 -- Protection component if nothing else), same for any protected type
2088 -- with interrupt handlers. Note that we need to analyze the protected
2089 -- definition to set Has_Entries and such.
2091 if (Abort_Allowed or else Restriction_Active (No_Entry_Queue) = False
2092 or else Number_Entries (T) > 1)
2093 and then not Restricted_Profile
2096 or else Has_Interrupt_Handler (T)
2097 or else Has_Attach_Handler (T))
2099 Set_Has_Controlled_Component (T, True);
2102 -- The Ekind of components is E_Void during analysis to detect illegal
2103 -- uses. Now it can be set correctly.
2105 E := First_Entity (Current_Scope);
2106 while Present (E) loop
2107 if Ekind (E) = E_Void then
2108 Set_Ekind (E, E_Component);
2109 Init_Component_Location (E);
2117 -- When a Lock_Free aspect forces the lock-free implementation, check N
2118 -- meets all the lock-free restrictions. Otherwise, an error message is
2119 -- issued by Allows_Lock_Free_Implementation.
2121 if Uses_Lock_Free (Defining_Identifier (N)) then
2123 -- Complain when there is an explicit aspect/pragma Priority (or
2124 -- Interrupt_Priority) while the lock-free implementation is forced
2125 -- by an aspect/pragma.
2128 Id : constant Entity_Id := Defining_Identifier (Original_Node (N));
2129 -- The warning must be issued on the original identifier in order
2130 -- to deal properly with the case of a single protected object.
2132 Prio_Item : constant Node_Id :=
2133 Get_Rep_Item (Def_Id, Name_Priority, False);
2136 if Present (Prio_Item) then
2140 if Nkind (Prio_Item) = N_Aspect_Specification
2141 or else From_Aspect_Specification (Prio_Item)
2143 Error_Msg_Name_1 := Chars (Identifier (Prio_Item));
2145 ("aspect% for & has no effect when Lock_Free given??",
2151 Error_Msg_Name_1 := Pragma_Name (Prio_Item);
2153 ("pragma% for & has no effect when Lock_Free given??",
2159 if not Allows_Lock_Free_Implementation (N, Lock_Free_Given => True)
2165 -- If the Attach_Handler aspect is specified or the Interrupt_Handler
2166 -- aspect is True, then the initial ceiling priority must be in the
2167 -- range of System.Interrupt_Priority. It is therefore recommanded
2168 -- to use the Interrupt_Priority aspect instead of the Priority aspect.
2170 if Has_Interrupt_Handler (T) or else Has_Attach_Handler (T) then
2172 Prio_Item : constant Node_Id :=
2173 Get_Rep_Item (Def_Id, Name_Priority, False);
2176 if Present (Prio_Item) then
2180 if (Nkind (Prio_Item) = N_Aspect_Specification
2181 or else From_Aspect_Specification (Prio_Item))
2182 and then Chars (Identifier (Prio_Item)) = Name_Priority
2185 ("aspect Interrupt_Priority is preferred in presence of "
2186 & "handlers??", Prio_Item);
2190 elsif Nkind (Prio_Item) = N_Pragma
2191 and then Pragma_Name (Prio_Item) = Name_Priority
2194 ("pragma Interrupt_Priority is preferred in presence of "
2195 & "handlers??", Prio_Item);
2201 -- Case of a completion of a private declaration
2203 if T /= Def_Id and then Is_Private_Type (Def_Id) then
2205 -- Deal with preelaborable initialization. Note that this processing
2206 -- is done by Process_Full_View, but as can be seen below, in this
2207 -- case the call to Process_Full_View is skipped if any serious
2208 -- errors have occurred, and we don't want to lose this check.
2210 if Known_To_Have_Preelab_Init (Def_Id) then
2211 Set_Must_Have_Preelab_Init (T);
2214 -- Propagate invariant-related attributes from the private type to
2215 -- the protected type.
2217 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
2219 -- Create corresponding record now, because some private dependents
2220 -- may be subtypes of the partial view.
2222 -- Skip if errors are present, to prevent cascaded messages
2224 if Serious_Errors_Detected = 0
2226 -- Also skip if expander is not active
2228 and then Expander_Active
2230 Expand_N_Protected_Type_Declaration (N);
2231 Process_Full_View (N, T, Def_Id);
2234 end Analyze_Protected_Type_Declaration;
2236 ---------------------
2237 -- Analyze_Requeue --
2238 ---------------------
2240 procedure Analyze_Requeue (N : Node_Id) is
2241 Count : Natural := 0;
2242 Entry_Name : Node_Id := Name (N);
2243 Entry_Id : Entity_Id;
2245 Is_Disp_Req : Boolean;
2247 Enclosing : Entity_Id;
2248 Target_Obj : Node_Id := Empty;
2249 Req_Scope : Entity_Id;
2250 Outer_Ent : Entity_Id;
2251 Synch_Type : Entity_Id;
2254 Tasking_Used := True;
2255 Check_SPARK_05_Restriction ("requeue statement is not allowed", N);
2256 Check_Restriction (No_Requeue_Statements, N);
2257 Check_Unreachable_Code (N);
2260 for J in reverse 0 .. Scope_Stack.Last loop
2261 Enclosing := Scope_Stack.Table (J).Entity;
2262 exit when Is_Entry (Enclosing);
2264 if not Ekind_In (Enclosing, E_Block, E_Loop) then
2265 Error_Msg_N ("requeue must appear within accept or entry body", N);
2270 Analyze (Entry_Name);
2272 if Etype (Entry_Name) = Any_Type then
2276 if Nkind (Entry_Name) = N_Selected_Component then
2277 Target_Obj := Prefix (Entry_Name);
2278 Entry_Name := Selector_Name (Entry_Name);
2281 -- If an explicit target object is given then we have to check the
2282 -- restrictions of 9.5.4(6).
2284 if Present (Target_Obj) then
2286 -- Locate containing concurrent unit and determine enclosing entry
2287 -- body or outermost enclosing accept statement within the unit.
2290 for S in reverse 0 .. Scope_Stack.Last loop
2291 Req_Scope := Scope_Stack.Table (S).Entity;
2293 exit when Ekind (Req_Scope) in Task_Kind
2294 or else Ekind (Req_Scope) in Protected_Kind;
2296 if Is_Entry (Req_Scope) then
2297 Outer_Ent := Req_Scope;
2301 pragma Assert (Present (Outer_Ent));
2303 -- Check that the accessibility level of the target object is not
2304 -- greater or equal to the outermost enclosing accept statement (or
2305 -- entry body) unless it is a parameter of the innermost enclosing
2306 -- accept statement (or entry body).
2308 if Object_Access_Level (Target_Obj) >= Scope_Depth (Outer_Ent)
2310 (not Is_Entity_Name (Target_Obj)
2311 or else Ekind (Entity (Target_Obj)) not in Formal_Kind
2312 or else Enclosing /= Scope (Entity (Target_Obj)))
2315 ("target object has invalid level for requeue", Target_Obj);
2319 -- Overloaded case, find right interpretation
2321 if Is_Overloaded (Entry_Name) then
2324 -- Loop over candidate interpretations and filter out any that are
2325 -- not parameterless, are not type conformant, are not entries, or
2326 -- do not come from source.
2328 Get_First_Interp (Entry_Name, I, It);
2329 while Present (It.Nam) loop
2331 -- Note: we test type conformance here, not subtype conformance.
2332 -- Subtype conformance will be tested later on, but it is better
2333 -- for error output in some cases not to do that here.
2335 if (No (First_Formal (It.Nam))
2336 or else (Type_Conformant (Enclosing, It.Nam)))
2337 and then Ekind (It.Nam) = E_Entry
2339 -- Ada 2005 (AI-345): Since protected and task types have
2340 -- primitive entry wrappers, we only consider source entries.
2342 if Comes_From_Source (It.Nam) then
2350 Get_Next_Interp (I, It);
2354 Error_Msg_N ("no entry matches context", N);
2357 elsif Count > 1 then
2358 Error_Msg_N ("ambiguous entry name in requeue", N);
2362 Set_Is_Overloaded (Entry_Name, False);
2363 Set_Entity (Entry_Name, Entry_Id);
2366 -- Non-overloaded cases
2368 -- For the case of a reference to an element of an entry family, the
2369 -- Entry_Name is an indexed component.
2371 elsif Nkind (Entry_Name) = N_Indexed_Component then
2373 -- Requeue to an entry out of the body
2375 if Nkind (Prefix (Entry_Name)) = N_Selected_Component then
2376 Entry_Id := Entity (Selector_Name (Prefix (Entry_Name)));
2378 -- Requeue from within the body itself
2380 elsif Nkind (Prefix (Entry_Name)) = N_Identifier then
2381 Entry_Id := Entity (Prefix (Entry_Name));
2384 Error_Msg_N ("invalid entry_name specified", N);
2388 -- If we had a requeue of the form REQUEUE A (B), then the parser
2389 -- accepted it (because it could have been a requeue on an entry index.
2390 -- If A turns out not to be an entry family, then the analysis of A (B)
2391 -- turned it into a function call.
2393 elsif Nkind (Entry_Name) = N_Function_Call then
2395 ("arguments not allowed in requeue statement",
2396 First (Parameter_Associations (Entry_Name)));
2399 -- Normal case of no entry family, no argument
2402 Entry_Id := Entity (Entry_Name);
2405 -- Ada 2012 (AI05-0030): Potential dispatching requeue statement. The
2406 -- target type must be a concurrent interface class-wide type and the
2407 -- target must be a procedure, flagged by pragma Implemented. The
2408 -- target may be an access to class-wide type, in which case it must
2411 if Present (Target_Obj) then
2412 Synch_Type := Etype (Target_Obj);
2414 if Is_Access_Type (Synch_Type) then
2415 Synch_Type := Designated_Type (Synch_Type);
2420 Ada_Version >= Ada_2012
2421 and then Present (Target_Obj)
2422 and then Is_Class_Wide_Type (Synch_Type)
2423 and then Is_Concurrent_Interface (Synch_Type)
2424 and then Ekind (Entry_Id) = E_Procedure
2425 and then Has_Rep_Pragma (Entry_Id, Name_Implemented);
2427 -- Resolve entry, and check that it is subtype conformant with the
2428 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
2429 -- Ada 2005 (AI05-0030): Do not emit an error for this specific case.
2431 if not Is_Entry (Entry_Id)
2432 and then not Is_Disp_Req
2434 Error_Msg_N ("expect entry name in requeue statement", Name (N));
2436 elsif Ekind (Entry_Id) = E_Entry_Family
2437 and then Nkind (Entry_Name) /= N_Indexed_Component
2439 Error_Msg_N ("missing index for entry family component", Name (N));
2442 Resolve_Entry (Name (N));
2443 Generate_Reference (Entry_Id, Entry_Name);
2445 if Present (First_Formal (Entry_Id)) then
2447 -- Ada 2012 (AI05-0030): Perform type conformance after skipping
2448 -- the first parameter of Entry_Id since it is the interface
2449 -- controlling formal.
2451 if Ada_Version >= Ada_2012 and then Is_Disp_Req then
2453 Enclosing_Formal : Entity_Id;
2454 Target_Formal : Entity_Id;
2457 Enclosing_Formal := First_Formal (Enclosing);
2458 Target_Formal := Next_Formal (First_Formal (Entry_Id));
2459 while Present (Enclosing_Formal)
2460 and then Present (Target_Formal)
2462 if not Conforming_Types
2463 (T1 => Etype (Enclosing_Formal),
2464 T2 => Etype (Target_Formal),
2465 Ctype => Subtype_Conformant)
2467 Error_Msg_Node_2 := Target_Formal;
2469 ("formal & is not subtype conformant with &" &
2470 "in dispatching requeue", N, Enclosing_Formal);
2473 Next_Formal (Enclosing_Formal);
2474 Next_Formal (Target_Formal);
2478 Check_Subtype_Conformant (Enclosing, Entry_Id, Name (N));
2481 -- Processing for parameters accessed by the requeue
2487 Ent := First_Formal (Enclosing);
2488 while Present (Ent) loop
2490 -- For OUT or IN OUT parameter, the effect of the requeue is
2491 -- to assign the parameter a value on exit from the requeued
2492 -- body, so we can set it as source assigned. We also clear
2493 -- the Is_True_Constant indication. We do not need to clear
2494 -- Current_Value, since the effect of the requeue is to
2495 -- perform an unconditional goto so that any further
2496 -- references will not occur anyway.
2498 if Ekind_In (Ent, E_Out_Parameter, E_In_Out_Parameter) then
2499 Set_Never_Set_In_Source (Ent, False);
2500 Set_Is_True_Constant (Ent, False);
2503 -- For all parameters, the requeue acts as a reference,
2504 -- since the value of the parameter is passed to the new
2505 -- entry, so we want to suppress unreferenced warnings.
2507 Set_Referenced (Ent);
2514 -- AI05-0225: the target protected object of a requeue must be a
2515 -- variable. This is a binding interpretation that applies to all
2516 -- versions of the language. Note that the subprogram does not have
2517 -- to be a protected operation: it can be an primitive implemented
2518 -- by entry with a formal that is a protected interface.
2520 if Present (Target_Obj)
2521 and then not Is_Variable (Target_Obj)
2524 ("target protected object of requeue must be a variable", N);
2526 end Analyze_Requeue;
2528 ------------------------------
2529 -- Analyze_Selective_Accept --
2530 ------------------------------
2532 procedure Analyze_Selective_Accept (N : Node_Id) is
2533 Alts : constant List_Id := Select_Alternatives (N);
2536 Accept_Present : Boolean := False;
2537 Terminate_Present : Boolean := False;
2538 Delay_Present : Boolean := False;
2539 Relative_Present : Boolean := False;
2540 Alt_Count : Uint := Uint_0;
2543 Tasking_Used := True;
2544 Check_SPARK_05_Restriction ("select statement is not allowed", N);
2545 Check_Restriction (No_Select_Statements, N);
2547 -- Loop to analyze alternatives
2549 Alt := First (Alts);
2550 while Present (Alt) loop
2551 Alt_Count := Alt_Count + 1;
2554 if Nkind (Alt) = N_Delay_Alternative then
2555 if Delay_Present then
2557 if Relative_Present /=
2558 (Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement)
2561 ("delay_until and delay_relative alternatives ", Alt);
2563 ("\cannot appear in the same selective_wait", Alt);
2567 Delay_Present := True;
2569 Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement;
2572 elsif Nkind (Alt) = N_Terminate_Alternative then
2573 if Terminate_Present then
2574 Error_Msg_N ("only one terminate alternative allowed", N);
2576 Terminate_Present := True;
2577 Check_Restriction (No_Terminate_Alternatives, N);
2580 elsif Nkind (Alt) = N_Accept_Alternative then
2581 Accept_Present := True;
2583 -- Check for duplicate accept
2587 Stm : constant Node_Id := Accept_Statement (Alt);
2588 EDN : constant Node_Id := Entry_Direct_Name (Stm);
2592 if Nkind (EDN) = N_Identifier
2593 and then No (Condition (Alt))
2594 and then Present (Entity (EDN)) -- defend against junk
2595 and then Ekind (Entity (EDN)) = E_Entry
2597 Ent := Entity (EDN);
2599 Alt1 := First (Alts);
2600 while Alt1 /= Alt loop
2601 if Nkind (Alt1) = N_Accept_Alternative
2602 and then No (Condition (Alt1))
2605 Stm1 : constant Node_Id := Accept_Statement (Alt1);
2606 EDN1 : constant Node_Id := Entry_Direct_Name (Stm1);
2609 if Nkind (EDN1) = N_Identifier then
2610 if Entity (EDN1) = Ent then
2611 Error_Msg_Sloc := Sloc (Stm1);
2613 ("accept duplicates one on line#??", Stm);
2629 Check_Restriction (Max_Select_Alternatives, N, Alt_Count);
2630 Check_Potentially_Blocking_Operation (N);
2632 if Terminate_Present and Delay_Present then
2633 Error_Msg_N ("at most one of terminate or delay alternative", N);
2635 elsif not Accept_Present then
2637 ("select must contain at least one accept alternative", N);
2640 if Present (Else_Statements (N)) then
2641 if Terminate_Present or Delay_Present then
2642 Error_Msg_N ("else part not allowed with other alternatives", N);
2645 Analyze_Statements (Else_Statements (N));
2647 end Analyze_Selective_Accept;
2649 ------------------------------------------
2650 -- Analyze_Single_Protected_Declaration --
2651 ------------------------------------------
2653 procedure Analyze_Single_Protected_Declaration (N : Node_Id) is
2654 Loc : constant Source_Ptr := Sloc (N);
2655 Obj_Id : constant Node_Id := Defining_Identifier (N);
2660 Generate_Definition (Obj_Id);
2661 Tasking_Used := True;
2663 -- A single protected declaration is transformed into a pair of an
2664 -- anonymous protected type and an object of that type. Generate:
2666 -- protected type Typ is ...;
2669 Make_Defining_Identifier (Sloc (Obj_Id),
2670 Chars => New_External_Name (Chars (Obj_Id), 'T
'));
2673 Make_Protected_Type_Declaration (Loc,
2674 Defining_Identifier => Typ,
2675 Protected_Definition => Relocate_Node (Protected_Definition (N)),
2676 Interface_List => Interface_List (N)));
2678 -- Use the original defining identifier of the single protected
2679 -- declaration in the generated object declaration to allow for debug
2680 -- information to be attached to it when compiling with -gnatD. The
2681 -- parent of the entity is the new object declaration. The single
2682 -- protected declaration is not used in semantics or code generation,
2683 -- but is scanned when generating debug information, and therefore needs
2684 -- the updated Sloc information from the entity (see Sprint). Generate:
2689 Make_Object_Declaration (Loc,
2690 Defining_Identifier => Obj_Id,
2691 Object_Definition => New_Occurrence_Of (Typ, Loc));
2693 Insert_After (N, Obj_Decl);
2694 Mark_Rewrite_Insertion (Obj_Decl);
2696 -- Relocate aspect Part_Of from the the original single protected
2697 -- declaration to the anonymous object declaration. This emulates the
2698 -- placement of an equivalent source pragma.
2700 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2702 -- Relocate pragma Part_Of from the visible declarations of the original
2703 -- single protected declaration to the anonymous object declaration. The
2704 -- new placement better reflects the role of the pragma.
2706 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2708 -- Enter the names of the anonymous protected type and the object before
2709 -- analysis takes places, because the name of the object may be used in
2713 Set_Ekind (Typ, E_Protected_Type);
2714 Set_Etype (Typ, Typ);
2715 Set_Anonymous_Object (Typ, Obj_Id);
2717 Enter_Name (Obj_Id);
2718 Set_Ekind (Obj_Id, E_Variable);
2719 Set_Etype (Obj_Id, Typ);
2720 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2721 Set_SPARK_Pragma_Inherited (Obj_Id);
2723 -- Instead of calling Analyze on the new node, call the proper analysis
2724 -- procedure directly. Otherwise the node would be expanded twice, with
2725 -- disastrous result.
2727 Analyze_Protected_Type_Declaration (N);
2729 if Has_Aspects (N) then
2730 Analyze_Aspect_Specifications (N, Obj_Id);
2732 end Analyze_Single_Protected_Declaration;
2734 -------------------------------------
2735 -- Analyze_Single_Task_Declaration --
2736 -------------------------------------
2738 procedure Analyze_Single_Task_Declaration (N : Node_Id) is
2739 Loc : constant Source_Ptr := Sloc (N);
2740 Obj_Id : constant Node_Id := Defining_Identifier (N);
2745 Generate_Definition (Obj_Id);
2746 Tasking_Used := True;
2748 -- A single task declaration is transformed into a pait of an anonymous
2749 -- task type and an object of that type. Generate:
2751 -- task type Typ is ...;
2754 Make_Defining_Identifier (Sloc (Obj_Id),
2755 Chars => New_External_Name (Chars (Obj_Id), Suffix => "TK"));
2758 Make_Task_Type_Declaration (Loc,
2759 Defining_Identifier => Typ,
2760 Task_Definition => Relocate_Node (Task_Definition (N)),
2761 Interface_List => Interface_List (N)));
2763 -- Use the original defining identifier of the single task declaration
2764 -- in the generated object declaration to allow for debug information
2765 -- to be attached to it when compiling with -gnatD. The parent of the
2766 -- entity is the new object declaration. The single task declaration
2767 -- is not used in semantics or code generation, but is scanned when
2768 -- generating debug information, and therefore needs the updated Sloc
2769 -- information from the entity (see Sprint). Generate:
2774 Make_Object_Declaration (Loc,
2775 Defining_Identifier => Obj_Id,
2776 Object_Definition => New_Occurrence_Of (Typ, Loc));
2778 Insert_After (N, Obj_Decl);
2779 Mark_Rewrite_Insertion (Obj_Decl);
2781 -- Relocate aspects Depends, Global and Part_Of from the original single
2782 -- task declaration to the anonymous object declaration. This emulates
2783 -- the placement of an equivalent source pragma.
2785 Move_Or_Merge_Aspects (N, To => Obj_Decl);
2787 -- Relocate pragmas Depends, Global and Part_Of from the visible
2788 -- declarations of the original single protected declaration to the
2789 -- anonymous object declaration. The new placement better reflects the
2790 -- role of the pragmas.
2792 Relocate_Pragmas_To_Anonymous_Object (N, Obj_Decl);
2794 -- Enter the names of the anonymous task type and the object before
2795 -- analysis takes places, because the name of the object may be used
2799 Set_Ekind (Typ, E_Task_Type);
2800 Set_Etype (Typ, Typ);
2801 Set_Anonymous_Object (Typ, Obj_Id);
2803 Enter_Name (Obj_Id);
2804 Set_Ekind (Obj_Id, E_Variable);
2805 Set_Etype (Obj_Id, Typ);
2806 Set_SPARK_Pragma (Obj_Id, SPARK_Mode_Pragma);
2807 Set_SPARK_Pragma_Inherited (Obj_Id);
2809 -- Instead of calling Analyze on the new node, call the proper analysis
2810 -- procedure directly. Otherwise the node would be expanded twice, with
2811 -- disastrous result.
2813 Analyze_Task_Type_Declaration (N);
2815 if Has_Aspects (N) then
2816 Analyze_Aspect_Specifications (N, Obj_Id);
2818 end Analyze_Single_Task_Declaration;
2820 -----------------------
2821 -- Analyze_Task_Body --
2822 -----------------------
2824 procedure Analyze_Task_Body (N : Node_Id) is
2825 Body_Id : constant Entity_Id := Defining_Identifier (N);
2826 Decls : constant List_Id := Declarations (N);
2827 HSS : constant Node_Id := Handled_Statement_Sequence (N);
2830 Spec_Id : Entity_Id;
2831 -- This is initially the entity of the task or task type involved, but
2832 -- is replaced by the task type always in the case of a single task
2833 -- declaration, since this is the proper scope to be used.
2836 -- This is the entity of the task or task type, and is the entity used
2837 -- for cross-reference purposes (it differs from Spec_Id in the case of
2838 -- a single task, since Spec_Id is set to the task type).
2841 -- A task body "freezes" the contract of the nearest enclosing package
2842 -- body and all other contracts encountered in the same declarative part
2843 -- up to and excluding the task body. This ensures that annotations
2844 -- referenced by the contract of an entry or subprogram body declared
2845 -- within the current protected body are available.
2847 Analyze_Previous_Contracts (N);
2849 Tasking_Used := True;
2850 Set_Scope (Body_Id, Current_Scope);
2851 Set_Ekind (Body_Id, E_Task_Body);
2852 Set_Etype (Body_Id, Standard_Void_Type);
2853 Spec_Id := Find_Concurrent_Spec (Body_Id);
2855 -- The spec is either a task type declaration, or a single task
2856 -- declaration for which we have created an anonymous type.
2858 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Task_Type then
2861 elsif Present (Spec_Id)
2862 and then Ekind (Etype (Spec_Id)) = E_Task_Type
2863 and then not Comes_From_Source (Etype (Spec_Id))
2868 Error_Msg_N ("missing specification for task body", Body_Id);
2872 if Has_Completion (Spec_Id)
2873 and then Present (Corresponding_Body (Parent (Spec_Id)))
2875 if Nkind (Parent (Spec_Id)) = N_Task_Type_Declaration then
2876 Error_Msg_NE ("duplicate body for task type&", N, Spec_Id);
2878 Error_Msg_NE ("duplicate body for task&", N, Spec_Id);
2883 Generate_Reference (Ref_Id, Body_Id, 'b
', Set_Ref => False);
2884 Style.Check_Identifier (Body_Id, Spec_Id);
2886 -- Deal with case of body of single task (anonymous type was created)
2888 if Ekind (Spec_Id) = E_Variable then
2889 Spec_Id := Etype (Spec_Id);
2892 -- Set the SPARK_Mode from the current context (may be overwritten later
2893 -- with an explicit pragma).
2895 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
2896 Set_SPARK_Pragma_Inherited (Body_Id);
2898 if Has_Aspects (N) then
2899 Analyze_Aspect_Specifications (N, Body_Id);
2902 Push_Scope (Spec_Id);
2903 Set_Corresponding_Spec (N, Spec_Id);
2904 Set_Corresponding_Body (Parent (Spec_Id), Body_Id);
2905 Set_Has_Completion (Spec_Id);
2906 Install_Declarations (Spec_Id);
2907 Last_E := Last_Entity (Spec_Id);
2909 Analyze_Declarations (Decls);
2910 Inspect_Deferred_Constant_Completion (Decls);
2912 -- For visibility purposes, all entities in the body are private. Set
2913 -- First_Private_Entity accordingly, if there was no private part in the
2914 -- protected declaration.
2916 if No (First_Private_Entity (Spec_Id)) then
2917 if Present (Last_E) then
2918 Set_First_Private_Entity (Spec_Id, Next_Entity (Last_E));
2920 Set_First_Private_Entity (Spec_Id, First_Entity (Spec_Id));
2924 -- Mark all handlers as not suitable for local raise optimization,
2925 -- since this optimization causes difficulties in a task context.
2927 if Present (Exception_Handlers (HSS)) then
2931 Handlr := First (Exception_Handlers (HSS));
2932 while Present (Handlr) loop
2933 Set_Local_Raise_Not_OK (Handlr);
2939 -- Now go ahead and complete analysis of the task body
2942 Check_Completion (Body_Id);
2943 Check_References (Body_Id);
2944 Check_References (Spec_Id);
2946 -- Check for entries with no corresponding accept
2952 Ent := First_Entity (Spec_Id);
2953 while Present (Ent) loop
2955 and then not Entry_Accepted (Ent)
2956 and then Comes_From_Source (Ent)
2958 Error_Msg_NE ("no accept for entry &??", N, Ent);
2965 Process_End_Label (HSS, 't
', Ref_Id);
2967 end Analyze_Task_Body;
2969 -----------------------------
2970 -- Analyze_Task_Definition --
2971 -----------------------------
2973 procedure Analyze_Task_Definition (N : Node_Id) is
2977 Tasking_Used := True;
2978 Check_SPARK_05_Restriction ("task definition is not allowed", N);
2980 if Present (Visible_Declarations (N)) then
2981 Analyze_Declarations (Visible_Declarations (N));
2984 if Present (Private_Declarations (N)) then
2985 L := Last_Entity (Current_Scope);
2986 Analyze_Declarations (Private_Declarations (N));
2989 Set_First_Private_Entity
2990 (Current_Scope, Next_Entity (L));
2992 Set_First_Private_Entity
2993 (Current_Scope, First_Entity (Current_Scope));
2997 Check_Max_Entries (N, Max_Task_Entries);
2998 Process_End_Label (N, 'e
', Current_Scope);
2999 end Analyze_Task_Definition;
3001 -----------------------------------
3002 -- Analyze_Task_Type_Declaration --
3003 -----------------------------------
3005 procedure Analyze_Task_Type_Declaration (N : Node_Id) is
3006 Def_Id : constant Entity_Id := Defining_Identifier (N);
3010 -- Attempt to use tasking in no run time mode is not allowe. Issue hard
3011 -- error message to disable expansion which leads to crashes.
3013 if Opt.No_Run_Time_Mode then
3014 Error_Msg_N ("tasking not allowed in No_Run_Time mode", N);
3016 -- Otherwise soft check for no tasking restriction
3019 Check_Restriction (No_Tasking, N);
3022 -- Proceed ahead with analysis of task type declaration
3024 Tasking_Used := True;
3026 -- The sequential partition elaboration policy is supported only in the
3027 -- restricted profile.
3029 if Partition_Elaboration_Policy = 'S
'
3030 and then not Restricted_Profile
3033 ("sequential elaboration supported only in restricted profile", N);
3036 T := Find_Type_Name (N);
3037 Generate_Definition (T);
3039 -- In the case of an incomplete type, use the full view, unless it's not
3040 -- present (as can occur for an incomplete view from a limited with).
3041 -- Initialize the Corresponding_Record_Type (which overlays the Private
3042 -- Dependents field of the incomplete view).
3044 if Ekind (T) = E_Incomplete_Type then
3045 if Present (Full_View (T)) then
3047 Set_Completion_Referenced (T);
3050 Set_Ekind (T, E_Task_Type);
3051 Set_Corresponding_Record_Type (T, Empty);
3055 Set_Ekind (T, E_Task_Type);
3056 Set_Is_First_Subtype (T, True);
3057 Set_Has_Task (T, True);
3058 Init_Size_Align (T);
3060 Set_Has_Delayed_Freeze (T, True);
3061 Set_Stored_Constraint (T, No_Elist);
3063 -- Set the SPARK_Mode from the current context (may be overwritten later
3064 -- with an explicit pragma).
3066 Set_SPARK_Pragma (T, SPARK_Mode_Pragma);
3067 Set_SPARK_Aux_Pragma (T, SPARK_Mode_Pragma);
3068 Set_SPARK_Pragma_Inherited (T);
3069 Set_SPARK_Aux_Pragma_Inherited (T);
3073 if Ada_Version >= Ada_2005 then
3074 Check_Interfaces (N, T);
3077 if Present (Discriminant_Specifications (N)) then
3078 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
3079 Error_Msg_N ("(Ada 83) task discriminant not allowed!", N);
3082 if Has_Discriminants (T) then
3084 -- Install discriminants. Also, verify conformance of
3085 -- discriminants of previous and current view. ???
3087 Install_Declarations (T);
3089 Process_Discriminants (N);
3093 Set_Is_Constrained (T, not Has_Discriminants (T));
3095 if Has_Aspects (N) then
3097 -- The task type is the full view of a private type. Analyze the
3098 -- aspects with the entity of the private type to ensure that after
3099 -- both views are exchanged, the aspect are actually associated with
3102 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3103 Analyze_Aspect_Specifications (N, T);
3105 Analyze_Aspect_Specifications (N, Def_Id);
3109 if Present (Task_Definition (N)) then
3110 Analyze_Task_Definition (Task_Definition (N));
3113 -- In the case where the task type is declared at a nested level and the
3114 -- No_Task_Hierarchy restriction applies, issue a warning that objects
3115 -- of the type will violate the restriction.
3117 if Restriction_Check_Required (No_Task_Hierarchy)
3118 and then not Is_Library_Level_Entity (T)
3119 and then Comes_From_Source (T)
3120 and then not CodePeer_Mode
3122 Error_Msg_Sloc := Restrictions_Loc (No_Task_Hierarchy);
3124 if Error_Msg_Sloc = No_Location then
3126 ("objects of this type will violate `No_Task_Hierarchy`??", N);
3129 ("objects of this type will violate `No_Task_Hierarchy`#??", N);
3135 -- Case of a completion of a private declaration
3137 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3139 -- Deal with preelaborable initialization. Note that this processing
3140 -- is done by Process_Full_View, but as can be seen below, in this
3141 -- case the call to Process_Full_View is skipped if any serious
3142 -- errors have occurred, and we don't want to lose this check.
3144 if Known_To_Have_Preelab_Init (Def_Id) then
3145 Set_Must_Have_Preelab_Init (T);
3148 -- Propagate invariant-related attributes from the private type to
3151 Propagate_Invariant_Attributes (T, From_Typ => Def_Id);
3153 -- Create corresponding record now, because some private dependents
3154 -- may be subtypes of the partial view.
3156 -- Skip if errors are present, to prevent cascaded messages
3158 if Serious_Errors_Detected = 0
3160 -- Also skip if expander is not active
3162 and then Expander_Active
3164 Expand_N_Task_Type_Declaration (N);
3165 Process_Full_View (N, T, Def_Id);
3168 end Analyze_Task_Type_Declaration;
3170 -----------------------------------
3171 -- Analyze_Terminate_Alternative --
3172 -----------------------------------
3174 procedure Analyze_Terminate_Alternative (N : Node_Id) is
3176 Tasking_Used := True;
3178 if Present (Pragmas_Before (N)) then
3179 Analyze_List (Pragmas_Before (N));
3182 if Present (Condition (N)) then
3183 Analyze_And_Resolve (Condition (N), Any_Boolean);
3185 end Analyze_Terminate_Alternative;
3187 ------------------------------
3188 -- Analyze_Timed_Entry_Call --
3189 ------------------------------
3191 procedure Analyze_Timed_Entry_Call (N : Node_Id) is
3192 Trigger : constant Node_Id :=
3193 Entry_Call_Statement (Entry_Call_Alternative (N));
3194 Is_Disp_Select : Boolean := False;
3197 Tasking_Used := True;
3198 Check_SPARK_05_Restriction ("select statement is not allowed", N);
3199 Check_Restriction (No_Select_Statements, N);
3201 -- Ada 2005 (AI-345): The trigger may be a dispatching call
3203 if Ada_Version >= Ada_2005 then
3205 Check_Triggering_Statement (Trigger, N, Is_Disp_Select);
3208 -- Postpone the analysis of the statements till expansion. Analyze only
3209 -- if the expander is disabled in order to catch any semantic errors.
3211 if Is_Disp_Select then
3212 if not Expander_Active then
3213 Analyze (Entry_Call_Alternative (N));
3214 Analyze (Delay_Alternative (N));
3217 -- Regular select analysis
3220 Analyze (Entry_Call_Alternative (N));
3221 Analyze (Delay_Alternative (N));
3223 end Analyze_Timed_Entry_Call;
3225 ------------------------------------
3226 -- Analyze_Triggering_Alternative --
3227 ------------------------------------
3229 procedure Analyze_Triggering_Alternative (N : Node_Id) is
3230 Trigger : constant Node_Id := Triggering_Statement (N);
3233 Tasking_Used := True;
3235 if Present (Pragmas_Before (N)) then
3236 Analyze_List (Pragmas_Before (N));
3241 if Comes_From_Source (Trigger)
3242 and then Nkind (Trigger) not in N_Delay_Statement
3243 and then Nkind (Trigger) /= N_Entry_Call_Statement
3245 if Ada_Version < Ada_2005 then
3247 ("triggering statement must be delay or entry call", Trigger);
3249 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
3250 -- procedure_or_entry_call, the procedure_name or procedure_prefix
3251 -- of the procedure_call_statement shall denote an entry renamed by a
3252 -- procedure, or (a view of) a primitive subprogram of a limited
3253 -- interface whose first parameter is a controlling parameter.
3255 elsif Nkind (Trigger) = N_Procedure_Call_Statement
3256 and then not Is_Renamed_Entry (Entity (Name (Trigger)))
3257 and then not Is_Controlling_Limited_Procedure
3258 (Entity (Name (Trigger)))
3261 ("triggering statement must be procedure or entry call " &
3262 "or delay statement", Trigger);
3266 if Is_Non_Empty_List (Statements (N)) then
3267 Analyze_Statements (Statements (N));
3269 end Analyze_Triggering_Alternative;
3271 -----------------------
3272 -- Check_Max_Entries --
3273 -----------------------
3275 procedure Check_Max_Entries (D : Node_Id; R : All_Parameter_Restrictions) is
3278 procedure Count (L : List_Id);
3279 -- Count entries in given declaration list
3285 procedure Count (L : List_Id) is
3294 while Present (D) loop
3295 if Nkind (D) = N_Entry_Declaration then
3297 DSD : constant Node_Id :=
3298 Discrete_Subtype_Definition (D);
3301 -- If not an entry family, then just one entry
3304 Ecount := Ecount + 1;
3306 -- If entry family with static bounds, count entries
3308 elsif Is_OK_Static_Subtype (Etype (DSD)) then
3310 Lo : constant Uint :=
3312 (Type_Low_Bound (Etype (DSD)));
3313 Hi : constant Uint :=
3315 (Type_High_Bound (Etype (DSD)));
3319 Ecount := Ecount + Hi - Lo + 1;
3323 -- Entry family with non-static bounds
3326 -- Record an unknown count restriction, and if the
3327 -- restriction is active, post a message or warning.
3329 Check_Restriction (R, D);
3338 -- Start of processing for Check_Max_Entries
3342 Count (Visible_Declarations (D));
3343 Count (Private_Declarations (D));
3346 Check_Restriction (R, D, Ecount);
3348 end Check_Max_Entries;
3350 ----------------------
3351 -- Check_Interfaces --
3352 ----------------------
3354 procedure Check_Interfaces (N : Node_Id; T : Entity_Id) is
3356 Iface_Typ : Entity_Id;
3360 (Nkind_In (N, N_Protected_Type_Declaration, N_Task_Type_Declaration));
3362 if Present (Interface_List (N)) then
3363 Set_Is_Tagged_Type (T);
3365 -- The primitive operations of a tagged synchronized type are placed
3366 -- on the Corresponding_Record for proper dispatching, but are
3367 -- attached to the synchronized type itself when expansion is
3368 -- disabled, for ASIS use.
3370 Set_Direct_Primitive_Operations (T, New_Elmt_List);
3372 Iface := First (Interface_List (N));
3373 while Present (Iface) loop
3374 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
3376 if not Is_Interface (Iface_Typ) then
3378 ("(Ada 2005) & must be an interface", Iface, Iface_Typ);
3381 -- Ada 2005 (AI-251): "The declaration of a specific descendant
3382 -- of an interface type freezes the interface type" RM 13.14.
3384 Freeze_Before (N, Etype (Iface));
3386 if Nkind (N) = N_Protected_Type_Declaration then
3388 -- Ada 2005 (AI-345): Protected types can only implement
3389 -- limited, synchronized, or protected interfaces (note that
3390 -- the predicate Is_Limited_Interface includes synchronized
3391 -- and protected interfaces).
3393 if Is_Task_Interface (Iface_Typ) then
3394 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3395 & "a task interface", Iface);
3397 elsif not Is_Limited_Interface (Iface_Typ) then
3398 Error_Msg_N ("(Ada 2005) protected type cannot implement "
3399 & "a non-limited interface", Iface);
3402 else pragma Assert (Nkind (N) = N_Task_Type_Declaration);
3404 -- Ada 2005 (AI-345): Task types can only implement limited,
3405 -- synchronized, or task interfaces (note that the predicate
3406 -- Is_Limited_Interface includes synchronized and task
3409 if Is_Protected_Interface (Iface_Typ) then
3410 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3411 "protected interface", Iface);
3413 elsif not Is_Limited_Interface (Iface_Typ) then
3414 Error_Msg_N ("(Ada 2005) task type cannot implement a " &
3415 "non-limited interface", Iface);
3424 if not Has_Private_Declaration (T) then
3428 -- Additional checks on full-types associated with private type
3429 -- declarations. Search for the private type declaration.
3432 Full_T_Ifaces : Elist_Id;
3435 Priv_T_Ifaces : Elist_Id;
3438 Priv_T := First_Entity (Scope (T));
3440 pragma Assert (Present (Priv_T));
3442 if Is_Type (Priv_T) and then Present (Full_View (Priv_T)) then
3443 exit when Full_View (Priv_T) = T;
3446 Next_Entity (Priv_T);
3449 -- In case of synchronized types covering interfaces the private type
3450 -- declaration must be limited.
3452 if Present (Interface_List (N))
3453 and then not Is_Limited_Type (Priv_T)
3455 Error_Msg_Sloc := Sloc (Priv_T);
3456 Error_Msg_N ("(Ada 2005) limited type declaration expected for " &
3457 "private type#", T);
3460 -- RM 7.3 (7.1/2): If the full view has a partial view that is
3461 -- tagged then check RM 7.3 subsidiary rules.
3463 if Is_Tagged_Type (Priv_T)
3464 and then not Error_Posted (N)
3466 -- RM 7.3 (7.2/2): The partial view shall be a synchronized tagged
3467 -- type if and only if the full type is a synchronized tagged type
3469 if Is_Synchronized_Tagged_Type (Priv_T)
3470 and then not Is_Synchronized_Tagged_Type (T)
3473 ("(Ada 2005) full view must be a synchronized tagged " &
3474 "type (RM 7.3 (7.2/2))", Priv_T);
3476 elsif Is_Synchronized_Tagged_Type (T)
3477 and then not Is_Synchronized_Tagged_Type (Priv_T)
3480 ("(Ada 2005) partial view must be a synchronized tagged " &
3481 "type (RM 7.3 (7.2/2))", T);
3484 -- RM 7.3 (7.3/2): The partial view shall be a descendant of an
3485 -- interface type if and only if the full type is descendant of
3486 -- the interface type.
3488 if Present (Interface_List (N))
3489 or else (Is_Tagged_Type (Priv_T)
3490 and then Has_Interfaces
3491 (Priv_T, Use_Full_View => False))
3493 if Is_Tagged_Type (Priv_T) then
3495 (Priv_T, Priv_T_Ifaces, Use_Full_View => False);
3498 if Is_Tagged_Type (T) then
3499 Collect_Interfaces (T, Full_T_Ifaces);
3502 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
3504 if Present (Iface) then
3506 ("interface in partial view& not implemented by full "
3507 & "type (RM-2005 7.3 (7.3/2))", T, Iface);
3510 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
3512 if Present (Iface) then
3514 ("interface & not implemented by partial " &
3515 "view (RM-2005 7.3 (7.3/2))", T, Iface);
3520 end Check_Interfaces;
3522 --------------------------------
3523 -- Check_Triggering_Statement --
3524 --------------------------------
3526 procedure Check_Triggering_Statement
3528 Error_Node : Node_Id;
3529 Is_Dispatching : out Boolean)
3534 Is_Dispatching := False;
3536 -- It is not possible to have a dispatching trigger if we are not in
3539 if Ada_Version >= Ada_2005
3540 and then Nkind (Trigger) = N_Procedure_Call_Statement
3541 and then Present (Parameter_Associations (Trigger))
3543 Param := First (Parameter_Associations (Trigger));
3545 if Is_Controlling_Actual (Param)
3546 and then Is_Interface (Etype (Param))
3548 if Is_Limited_Record (Etype (Param)) then
3549 Is_Dispatching := True;
3552 ("dispatching operation of limited or synchronized " &
3553 "interface required (RM 9.7.2(3))!", Error_Node);
3556 elsif Nkind (Trigger) = N_Explicit_Dereference then
3558 ("entry call or dispatching primitive of interface required ",
3562 end Check_Triggering_Statement;
3564 --------------------------
3565 -- Find_Concurrent_Spec --
3566 --------------------------
3568 function Find_Concurrent_Spec (Body_Id : Entity_Id) return Entity_Id is
3569 Spec_Id : Entity_Id := Current_Entity_In_Scope (Body_Id);
3572 -- The type may have been given by an incomplete type declaration.
3573 -- Find full view now.
3575 if Present (Spec_Id) and then Ekind (Spec_Id) = E_Incomplete_Type then
3576 Spec_Id := Full_View (Spec_Id);
3580 end Find_Concurrent_Spec;
3582 --------------------------
3583 -- Install_Declarations --
3584 --------------------------
3586 procedure Install_Declarations (Spec : Entity_Id) is
3590 E := First_Entity (Spec);
3591 while Present (E) loop
3592 Prev := Current_Entity (E);
3593 Set_Current_Entity (E);
3594 Set_Is_Immediately_Visible (E);
3595 Set_Homonym (E, Prev);
3598 end Install_Declarations;