1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Einfo
; use Einfo
;
30 with Errout
; use Errout
;
31 with Exp_Ch9
; use Exp_Ch9
;
32 with Elists
; use Elists
;
33 with Freeze
; use Freeze
;
34 with Itypes
; use Itypes
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Nlists
; use Nlists
;
37 with Nmake
; use Nmake
;
39 with Restrict
; use Restrict
;
40 with Rident
; use Rident
;
41 with Rtsfind
; use Rtsfind
;
43 with Sem_Ch3
; use Sem_Ch3
;
44 with Sem_Ch5
; use Sem_Ch5
;
45 with Sem_Ch6
; use Sem_Ch6
;
46 with Sem_Ch8
; use Sem_Ch8
;
47 with Sem_Eval
; use Sem_Eval
;
48 with Sem_Res
; use Sem_Res
;
49 with Sem_Type
; use Sem_Type
;
50 with Sem_Util
; use Sem_Util
;
51 with Sem_Warn
; use Sem_Warn
;
52 with Snames
; use Snames
;
53 with Stand
; use Stand
;
54 with Sinfo
; use Sinfo
;
56 with Tbuild
; use Tbuild
;
57 with Uintp
; use Uintp
;
59 package body Sem_Ch9
is
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
);
66 -- Given either a protected definition or a task definition in D, check
67 -- the corresponding restriction parameter identifier R, and if it is set,
68 -- count the entries (checking the static requirement), and compare with
71 procedure Check_Overriding_Indicator
(Def
: Node_Id
);
72 -- Ada 2005 (AI-397): Check the overriding indicator of entries and
73 -- subprograms of protected or task types. Def is the definition of the
74 -- protected or task type.
76 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
;
77 -- Find entity in corresponding task or protected declaration. Use full
78 -- view if first declaration was for an incomplete type.
80 procedure Install_Declarations
(Spec
: Entity_Id
);
81 -- Utility to make visible in corresponding body the entities defined in
82 -- task, protected type declaration, or entry declaration.
84 -----------------------------
85 -- Analyze_Abort_Statement --
86 -----------------------------
88 procedure Analyze_Abort_Statement
(N
: Node_Id
) is
93 T_Name
:= First
(Names
(N
));
94 while Present
(T_Name
) loop
97 if Is_Task_Type
(Etype
(T_Name
))
98 or else (Ada_Version
>= Ada_05
99 and then Ekind
(Etype
(T_Name
)) = E_Class_Wide_Type
100 and then Is_Interface
(Etype
(T_Name
))
101 and then Is_Task_Interface
(Etype
(T_Name
)))
105 if Ada_Version
>= Ada_05
then
106 Error_Msg_N
("expect task name or task interface class-wide "
107 & "object for ABORT", T_Name
);
109 Error_Msg_N
("expect task name for ABORT", T_Name
);
118 Check_Restriction
(No_Abort_Statements
, N
);
119 Check_Potentially_Blocking_Operation
(N
);
120 end Analyze_Abort_Statement
;
122 --------------------------------
123 -- Analyze_Accept_Alternative --
124 --------------------------------
126 procedure Analyze_Accept_Alternative
(N
: Node_Id
) is
128 Tasking_Used
:= True;
130 if Present
(Pragmas_Before
(N
)) then
131 Analyze_List
(Pragmas_Before
(N
));
134 if Present
(Condition
(N
)) then
135 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
138 Analyze
(Accept_Statement
(N
));
140 if Is_Non_Empty_List
(Statements
(N
)) then
141 Analyze_Statements
(Statements
(N
));
143 end Analyze_Accept_Alternative
;
145 ------------------------------
146 -- Analyze_Accept_Statement --
147 ------------------------------
149 procedure Analyze_Accept_Statement
(N
: Node_Id
) is
150 Nam
: constant Entity_Id
:= Entry_Direct_Name
(N
);
151 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
152 Index
: constant Node_Id
:= Entry_Index
(N
);
153 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
154 Accept_Id
: Entity_Id
;
155 Entry_Nam
: Entity_Id
;
158 Task_Nam
: Entity_Id
;
160 -----------------------
161 -- Actual_Index_Type --
162 -----------------------
164 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
165 -- If the bounds of an entry family depend on task discriminants, create
166 -- a new index type where a discriminant is replaced by the local
167 -- variable that renames it in the task body.
169 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
170 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
171 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
172 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
175 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
176 -- If bound is discriminant reference, replace with corresponding
177 -- local variable of the same name.
179 -----------------------------
180 -- Actual_Discriminant_Ref --
181 -----------------------------
183 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
184 Typ
: constant Entity_Id
:= Etype
(Bound
);
187 if not Is_Entity_Name
(Bound
)
188 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
192 Ref
:= Make_Identifier
(Sloc
(N
), Chars
(Entity
(Bound
)));
197 end Actual_Discriminant_Ref
;
199 -- Start of processing for Actual_Index_Type
202 if not Has_Discriminants
(Task_Nam
)
203 or else (not Is_Entity_Name
(Lo
)
204 and then not Is_Entity_Name
(Hi
))
206 return Entry_Index_Type
(E
);
208 New_T
:= Create_Itype
(Ekind
(Typ
), N
);
209 Set_Etype
(New_T
, Base_Type
(Typ
));
210 Set_Size_Info
(New_T
, Typ
);
211 Set_RM_Size
(New_T
, RM_Size
(Typ
));
212 Set_Scalar_Range
(New_T
,
213 Make_Range
(Sloc
(N
),
214 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
215 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
219 end Actual_Index_Type
;
221 -- Start of processing for Analyze_Accept_Statement
224 Tasking_Used
:= True;
226 -- Entry name is initialized to Any_Id. It should get reset to the
227 -- matching entry entity. An error is signalled if it is not reset.
231 for J
in reverse 0 .. Scope_Stack
.Last
loop
232 Task_Nam
:= Scope_Stack
.Table
(J
).Entity
;
233 exit when Ekind
(Etype
(Task_Nam
)) = E_Task_Type
;
234 Kind
:= Ekind
(Task_Nam
);
236 if Kind
/= E_Block
and then Kind
/= E_Loop
237 and then not Is_Entry
(Task_Nam
)
239 Error_Msg_N
("enclosing body of accept must be a task", N
);
244 if Ekind
(Etype
(Task_Nam
)) /= E_Task_Type
then
245 Error_Msg_N
("invalid context for accept statement", N
);
249 -- In order to process the parameters, we create a defining
250 -- identifier that can be used as the name of the scope. The
251 -- name of the accept statement itself is not a defining identifier,
252 -- and we cannot use its name directly because the task may have
253 -- any number of accept statements for the same entry.
255 if Present
(Index
) then
256 Accept_Id
:= New_Internal_Entity
257 (E_Entry_Family
, Current_Scope
, Sloc
(N
), 'E');
259 Accept_Id
:= New_Internal_Entity
260 (E_Entry
, Current_Scope
, Sloc
(N
), 'E');
263 Set_Etype
(Accept_Id
, Standard_Void_Type
);
264 Set_Accept_Address
(Accept_Id
, New_Elmt_List
);
266 if Present
(Formals
) then
267 New_Scope
(Accept_Id
);
268 Process_Formals
(Formals
, N
);
269 Create_Extra_Formals
(Accept_Id
);
273 -- We set the default expressions processed flag because we don't need
274 -- default expression functions. This is really more like body entity
275 -- than a spec entity anyway.
277 Set_Default_Expressions_Processed
(Accept_Id
);
279 E
:= First_Entity
(Etype
(Task_Nam
));
280 while Present
(E
) loop
281 if Chars
(E
) = Chars
(Nam
)
282 and then (Ekind
(E
) = Ekind
(Accept_Id
))
283 and then Type_Conformant
(Accept_Id
, E
)
292 if Entry_Nam
= Any_Id
then
293 Error_Msg_N
("no entry declaration matches accept statement", N
);
296 Set_Entity
(Nam
, Entry_Nam
);
297 Generate_Reference
(Entry_Nam
, Nam
, 'b', Set_Ref
=> False);
298 Style
.Check_Identifier
(Nam
, Entry_Nam
);
301 -- Verify that the entry is not hidden by a procedure declared in the
302 -- current block (pathological but possible).
304 if Current_Scope
/= Task_Nam
then
309 E1
:= First_Entity
(Current_Scope
);
310 while Present
(E1
) loop
311 if Ekind
(E1
) = E_Procedure
312 and then Chars
(E1
) = Chars
(Entry_Nam
)
313 and then Type_Conformant
(E1
, Entry_Nam
)
315 Error_Msg_N
("entry name is not visible", N
);
323 Set_Convention
(Accept_Id
, Convention
(Entry_Nam
));
324 Check_Fully_Conformant
(Accept_Id
, Entry_Nam
, N
);
326 for J
in reverse 0 .. Scope_Stack
.Last
loop
327 exit when Task_Nam
= Scope_Stack
.Table
(J
).Entity
;
329 if Entry_Nam
= Scope_Stack
.Table
(J
).Entity
then
330 Error_Msg_N
("duplicate accept statement for same entry", N
);
341 when N_Task_Body | N_Compilation_Unit
=>
343 when N_Asynchronous_Select
=>
344 Error_Msg_N
("accept statements are not allowed within" &
345 " an asynchronous select inner" &
346 " to the enclosing task body", N
);
354 if Ekind
(E
) = E_Entry_Family
then
356 Error_Msg_N
("missing entry index in accept for entry family", N
);
358 Analyze_And_Resolve
(Index
, Entry_Index_Type
(E
));
359 Apply_Range_Check
(Index
, Actual_Index_Type
(E
));
362 elsif Present
(Index
) then
363 Error_Msg_N
("invalid entry index in accept for simple entry", N
);
366 -- If label declarations present, analyze them. They are declared in the
367 -- enclosing task, but their enclosing scope is the entry itself, so
368 -- that goto's to the label are recognized as local to the accept.
370 if Present
(Declarations
(N
)) then
376 Decl
:= First
(Declarations
(N
));
377 while Present
(Decl
) loop
381 (Nkind
(Decl
) = N_Implicit_Label_Declaration
);
383 Id
:= Defining_Identifier
(Decl
);
384 Set_Enclosing_Scope
(Id
, Entry_Nam
);
390 -- If statements are present, they must be analyzed in the context of
391 -- the entry, so that references to formals are correctly resolved. We
392 -- also have to add the declarations that are required by the expansion
393 -- of the accept statement in this case if expansion active.
395 -- In the case of a select alternative of a selective accept, the
396 -- expander references the address declaration even if there is no
399 -- We also need to create the renaming declarations for the local
400 -- variables that will replace references to the formals within the
403 Exp_Ch9
.Expand_Accept_Declarations
(N
, Entry_Nam
);
405 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
406 -- fields on all entry formals (this loop ignores all other entities).
407 -- Reset Set_Referenced and Has_Pragma_Unreferenced as well, so that we
408 -- can post accurate warnings on each accept statement for the same
411 E
:= First_Entity
(Entry_Nam
);
412 while Present
(E
) loop
413 if Is_Formal
(E
) then
414 Set_Never_Set_In_Source
(E
, True);
415 Set_Is_True_Constant
(E
, False);
416 Set_Current_Value
(E
, Empty
);
417 Set_Referenced
(E
, False);
418 Set_Has_Pragma_Unreferenced
(E
, False);
424 -- Analyze statements if present
426 if Present
(Stats
) then
427 New_Scope
(Entry_Nam
);
428 Install_Declarations
(Entry_Nam
);
430 Set_Actual_Subtypes
(N
, Current_Scope
);
433 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Nam
);
437 -- Some warning checks
439 Check_Potentially_Blocking_Operation
(N
);
440 Check_References
(Entry_Nam
, N
);
441 Set_Entry_Accepted
(Entry_Nam
);
442 end Analyze_Accept_Statement
;
444 ---------------------------------
445 -- Analyze_Asynchronous_Select --
446 ---------------------------------
448 procedure Analyze_Asynchronous_Select
(N
: Node_Id
) is
453 Tasking_Used
:= True;
454 Check_Restriction
(Max_Asynchronous_Select_Nesting
, N
);
455 Check_Restriction
(No_Select_Statements
, N
);
457 if Ada_Version
>= Ada_05
then
458 Trigger
:= Triggering_Statement
(Triggering_Alternative
(N
));
462 -- The trigger is a dispatching procedure. Postpone the analysis of
463 -- the triggering and abortable statements until the expansion of
464 -- this asynchronous select in Expand_N_Asynchronous_Select. This
465 -- action is required since otherwise we would get a gigi abort from
466 -- the code replication in Expand_N_Asynchronous_Select of an already
467 -- analyzed statement list.
470 and then Nkind
(Trigger
) = N_Procedure_Call_Statement
471 and then Present
(Parameter_Associations
(Trigger
))
473 Param
:= First
(Parameter_Associations
(Trigger
));
475 if Is_Controlling_Actual
(Param
)
476 and then Is_Interface
(Etype
(Param
))
478 if Is_Limited_Record
(Etype
(Param
)) then
482 ("dispatching operation of limited or synchronized " &
483 "interface required ('R'M 9.7.2(3))!", N
);
489 -- Analyze the statements. We analyze statements in the abortable part,
490 -- because this is the section that is executed first, and that way our
491 -- remembering of saved values and checks is accurate.
493 Analyze_Statements
(Statements
(Abortable_Part
(N
)));
494 Analyze
(Triggering_Alternative
(N
));
495 end Analyze_Asynchronous_Select
;
497 ------------------------------------
498 -- Analyze_Conditional_Entry_Call --
499 ------------------------------------
501 procedure Analyze_Conditional_Entry_Call
(N
: Node_Id
) is
503 Check_Restriction
(No_Select_Statements
, N
);
504 Tasking_Used
:= True;
505 Analyze
(Entry_Call_Alternative
(N
));
507 if List_Length
(Else_Statements
(N
)) = 1
508 and then Nkind
(First
(Else_Statements
(N
))) in N_Delay_Statement
511 ("suspicious form of conditional entry call?", N
);
513 ("\`SELECT OR` may be intended rather than `SELECT ELSE`", N
);
516 Analyze_Statements
(Else_Statements
(N
));
517 end Analyze_Conditional_Entry_Call
;
519 --------------------------------
520 -- Analyze_Delay_Alternative --
521 --------------------------------
523 procedure Analyze_Delay_Alternative
(N
: Node_Id
) is
528 Tasking_Used
:= True;
529 Check_Restriction
(No_Delay
, N
);
531 if Present
(Pragmas_Before
(N
)) then
532 Analyze_List
(Pragmas_Before
(N
));
535 if Nkind
(Parent
(N
)) = N_Selective_Accept
536 or else Nkind
(Parent
(N
)) = N_Timed_Entry_Call
538 Expr
:= Expression
(Delay_Statement
(N
));
540 -- Defer full analysis until the statement is expanded, to insure
541 -- that generated code does not move past the guard. The delay
542 -- expression is only evaluated if the guard is open.
544 if Nkind
(Delay_Statement
(N
)) = N_Delay_Relative_Statement
then
545 Pre_Analyze_And_Resolve
(Expr
, Standard_Duration
);
547 Pre_Analyze_And_Resolve
(Expr
);
550 Typ
:= First_Subtype
(Etype
(Expr
));
552 if Nkind
(Delay_Statement
(N
)) = N_Delay_Until_Statement
553 and then not Is_RTE
(Typ
, RO_CA_Time
)
554 and then not Is_RTE
(Typ
, RO_RT_Time
)
556 Error_Msg_N
("expect Time types for `DELAY UNTIL`", Expr
);
559 Check_Restriction
(No_Fixed_Point
, Expr
);
562 Analyze
(Delay_Statement
(N
));
565 if Present
(Condition
(N
)) then
566 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
569 if Is_Non_Empty_List
(Statements
(N
)) then
570 Analyze_Statements
(Statements
(N
));
572 end Analyze_Delay_Alternative
;
574 ----------------------------
575 -- Analyze_Delay_Relative --
576 ----------------------------
578 procedure Analyze_Delay_Relative
(N
: Node_Id
) is
579 E
: constant Node_Id
:= Expression
(N
);
582 Check_Restriction
(No_Relative_Delay
, N
);
583 Tasking_Used
:= True;
584 Check_Restriction
(No_Delay
, N
);
585 Check_Potentially_Blocking_Operation
(N
);
586 Analyze_And_Resolve
(E
, Standard_Duration
);
587 Check_Restriction
(No_Fixed_Point
, E
);
588 end Analyze_Delay_Relative
;
590 -------------------------
591 -- Analyze_Delay_Until --
592 -------------------------
594 procedure Analyze_Delay_Until
(N
: Node_Id
) is
595 E
: constant Node_Id
:= Expression
(N
);
599 Tasking_Used
:= True;
600 Check_Restriction
(No_Delay
, N
);
601 Check_Potentially_Blocking_Operation
(N
);
603 Typ
:= First_Subtype
(Etype
(E
));
605 if not Is_RTE
(Typ
, RO_CA_Time
) and then
606 not Is_RTE
(Typ
, RO_RT_Time
)
608 Error_Msg_N
("expect Time types for `DELAY UNTIL`", E
);
610 end Analyze_Delay_Until
;
612 ------------------------
613 -- Analyze_Entry_Body --
614 ------------------------
616 procedure Analyze_Entry_Body
(N
: Node_Id
) is
617 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
618 Decls
: constant List_Id
:= Declarations
(N
);
619 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
620 Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
621 P_Type
: constant Entity_Id
:= Current_Scope
;
622 Entry_Name
: Entity_Id
;
626 Tasking_Used
:= True;
628 -- Entry_Name is initialized to Any_Id. It should get reset to the
629 -- matching entry entity. An error is signalled if it is not reset
631 Entry_Name
:= Any_Id
;
635 if Present
(Entry_Index_Specification
(Formals
)) then
636 Set_Ekind
(Id
, E_Entry_Family
);
638 Set_Ekind
(Id
, E_Entry
);
641 Set_Scope
(Id
, Current_Scope
);
642 Set_Etype
(Id
, Standard_Void_Type
);
643 Set_Accept_Address
(Id
, New_Elmt_List
);
645 E
:= First_Entity
(P_Type
);
646 while Present
(E
) loop
647 if Chars
(E
) = Chars
(Id
)
648 and then (Ekind
(E
) = Ekind
(Id
))
649 and then Type_Conformant
(Id
, E
)
652 Set_Convention
(Id
, Convention
(E
));
653 Set_Corresponding_Body
(Parent
(Entry_Name
), Id
);
654 Check_Fully_Conformant
(Id
, E
, N
);
656 if Ekind
(Id
) = E_Entry_Family
then
657 if not Fully_Conformant_Discrete_Subtypes
(
658 Discrete_Subtype_Definition
(Parent
(E
)),
659 Discrete_Subtype_Definition
660 (Entry_Index_Specification
(Formals
)))
663 ("index not fully conformant with previous declaration",
664 Discrete_Subtype_Definition
665 (Entry_Index_Specification
(Formals
)));
668 -- The elaboration of the entry body does not recompute the
669 -- bounds of the index, which may have side effects. Inherit
670 -- the bounds from the entry declaration. This is critical
671 -- if the entry has a per-object constraint. If a bound is
672 -- given by a discriminant, it must be reanalyzed in order
673 -- to capture the discriminal of the current entry, rather
674 -- than that of the protected type.
677 Index_Spec
: constant Node_Id
:=
678 Entry_Index_Specification
(Formals
);
680 Def
: constant Node_Id
:=
682 (Discrete_Subtype_Definition
(Parent
(E
)));
687 (Discrete_Subtype_Definition
(Index_Spec
))) = N_Range
689 Set_Etype
(Def
, Empty
);
690 Set_Analyzed
(Def
, False);
692 -- Keep the original subtree to ensure a properly
693 -- formed tree (e.g. for ASIS use).
696 (Discrete_Subtype_Definition
(Index_Spec
), Def
);
698 Set_Analyzed
(Low_Bound
(Def
), False);
699 Set_Analyzed
(High_Bound
(Def
), False);
701 if Denotes_Discriminant
(Low_Bound
(Def
)) then
702 Set_Entity
(Low_Bound
(Def
), Empty
);
705 if Denotes_Discriminant
(High_Bound
(Def
)) then
706 Set_Entity
(High_Bound
(Def
), Empty
);
710 Make_Index
(Def
, Index_Spec
);
712 (Defining_Identifier
(Index_Spec
), Etype
(Def
));
724 if Entry_Name
= Any_Id
then
725 Error_Msg_N
("no entry declaration matches entry body", N
);
728 elsif Has_Completion
(Entry_Name
) then
729 Error_Msg_N
("duplicate entry body", N
);
733 Set_Has_Completion
(Entry_Name
);
734 Generate_Reference
(Entry_Name
, Id
, 'b', Set_Ref
=> False);
735 Style
.Check_Identifier
(Id
, Entry_Name
);
738 Exp_Ch9
.Expand_Entry_Barrier
(N
, Entry_Name
);
739 New_Scope
(Entry_Name
);
741 Exp_Ch9
.Expand_Entry_Body_Declarations
(N
);
742 Install_Declarations
(Entry_Name
);
743 Set_Actual_Subtypes
(N
, Current_Scope
);
745 -- The entity for the protected subprogram corresponding to the entry
746 -- has been created. We retain the name of this entity in the entry
747 -- body, for use when the corresponding subprogram body is created.
748 -- Note that entry bodies have no corresponding_spec, and there is no
749 -- easy link back in the tree between the entry body and the entity for
750 -- the entry itself, which is why we must propagate some attributes
751 -- explicitly from spec to body.
753 Set_Protected_Body_Subprogram
754 (Id
, Protected_Body_Subprogram
(Entry_Name
));
756 Set_Entry_Parameters_Type
757 (Id
, Entry_Parameters_Type
(Entry_Name
));
759 if Present
(Decls
) then
760 Analyze_Declarations
(Decls
);
763 if Present
(Stats
) then
767 -- Check for unreferenced variables etc. Before the Check_References
768 -- call, we transfer Never_Set_In_Source and Referenced flags from
769 -- parameters in the spec to the corresponding entities in the body,
770 -- since we want the warnings on the body entities. Note that we do
771 -- not have to transfer Referenced_As_LHS, since that flag can only
772 -- be set for simple variables.
774 -- At the same time, we set the flags on the spec entities to suppress
775 -- any warnings on the spec formals, since we also scan the spec.
776 -- Finally, we propagate the Entry_Component attribute to the body
777 -- formals, for use in the renaming declarations created later for the
778 -- formals (see exp_ch9.Add_Formal_Renamings).
785 E1
:= First_Entity
(Entry_Name
);
786 while Present
(E1
) loop
787 E2
:= First_Entity
(Id
);
788 while Present
(E2
) loop
789 exit when Chars
(E1
) = Chars
(E2
);
793 -- If no matching body entity, then we already had a detected
794 -- error of some kind, so just forget about worrying about these
801 if Ekind
(E1
) = E_Out_Parameter
then
802 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
803 Set_Never_Set_In_Source
(E1
, False);
806 Set_Referenced
(E2
, Referenced
(E1
));
808 Set_Entry_Component
(E2
, Entry_Component
(E1
));
814 Check_References
(Id
);
817 -- We still need to check references for the spec, since objects
818 -- declared in the body are chained (in the First_Entity sense) to
819 -- the spec rather than the body in the case of entries.
821 Check_References
(Entry_Name
);
823 -- Process the end label, and terminate the scope
825 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Name
);
828 -- If this is an entry family, remove the loop created to provide
829 -- a scope for the entry index.
831 if Ekind
(Id
) = E_Entry_Family
832 and then Present
(Entry_Index_Specification
(Formals
))
836 end Analyze_Entry_Body
;
838 ------------------------------------
839 -- Analyze_Entry_Body_Formal_Part --
840 ------------------------------------
842 procedure Analyze_Entry_Body_Formal_Part
(N
: Node_Id
) is
843 Id
: constant Entity_Id
:= Defining_Identifier
(Parent
(N
));
844 Index
: constant Node_Id
:= Entry_Index_Specification
(N
);
845 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
848 Tasking_Used
:= True;
850 if Present
(Index
) then
854 if Present
(Formals
) then
855 Set_Scope
(Id
, Current_Scope
);
857 Process_Formals
(Formals
, Parent
(N
));
860 end Analyze_Entry_Body_Formal_Part
;
862 ------------------------------------
863 -- Analyze_Entry_Call_Alternative --
864 ------------------------------------
866 procedure Analyze_Entry_Call_Alternative
(N
: Node_Id
) is
867 Call
: constant Node_Id
:= Entry_Call_Statement
(N
);
870 Tasking_Used
:= True;
872 if Present
(Pragmas_Before
(N
)) then
873 Analyze_List
(Pragmas_Before
(N
));
876 if Nkind
(Call
) = N_Attribute_Reference
then
878 -- Possibly a stream attribute, but definitely illegal. Other
879 -- illegalitles, such as procedure calls, are diagnosed after
882 Error_Msg_N
("entry call alternative requires an entry call", Call
);
888 if Is_Non_Empty_List
(Statements
(N
)) then
889 Analyze_Statements
(Statements
(N
));
891 end Analyze_Entry_Call_Alternative
;
893 -------------------------------
894 -- Analyze_Entry_Declaration --
895 -------------------------------
897 procedure Analyze_Entry_Declaration
(N
: Node_Id
) is
898 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
899 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
900 D_Sdef
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
903 Generate_Definition
(Id
);
904 Tasking_Used
:= True;
907 Set_Ekind
(Id
, E_Entry
);
910 Set_Ekind
(Id
, E_Entry_Family
);
912 Make_Index
(D_Sdef
, N
, Id
);
915 Set_Etype
(Id
, Standard_Void_Type
);
916 Set_Convention
(Id
, Convention_Entry
);
917 Set_Accept_Address
(Id
, New_Elmt_List
);
919 if Present
(Formals
) then
920 Set_Scope
(Id
, Current_Scope
);
922 Process_Formals
(Formals
, N
);
923 Create_Extra_Formals
(Id
);
927 if Ekind
(Id
) = E_Entry
then
928 New_Overloaded_Entity
(Id
);
930 end Analyze_Entry_Declaration
;
932 ---------------------------------------
933 -- Analyze_Entry_Index_Specification --
934 ---------------------------------------
936 -- The Defining_Identifier of the entry index specification is local to the
937 -- entry body, but it must be available in the entry barrier which is
938 -- evaluated outside of the entry body. The index is eventually renamed as
939 -- a run-time object, so is visibility is strictly a front-end concern. In
940 -- order to make it available to the barrier, we create an additional
941 -- scope, as for a loop, whose only declaration is the index name. This
942 -- loop is not attached to the tree and does not appear as an entity local
943 -- to the protected type, so its existence need only be knwown to routines
944 -- that process entry families.
946 procedure Analyze_Entry_Index_Specification
(N
: Node_Id
) is
947 Iden
: constant Node_Id
:= Defining_Identifier
(N
);
948 Def
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
949 Loop_Id
: constant Entity_Id
:=
950 Make_Defining_Identifier
(Sloc
(N
),
951 Chars
=> New_Internal_Name
('L'));
954 Tasking_Used
:= True;
957 -- There is no elaboration of the entry index specification. Therefore,
958 -- if the index is a range, it is not resolved and expanded, but the
959 -- bounds are inherited from the entry declaration, and reanalyzed.
960 -- See Analyze_Entry_Body.
962 if Nkind
(Def
) /= N_Range
then
966 Set_Ekind
(Loop_Id
, E_Loop
);
967 Set_Scope
(Loop_Id
, Current_Scope
);
970 Set_Ekind
(Iden
, E_Entry_Index_Parameter
);
971 Set_Etype
(Iden
, Etype
(Def
));
972 end Analyze_Entry_Index_Specification
;
974 ----------------------------
975 -- Analyze_Protected_Body --
976 ----------------------------
978 procedure Analyze_Protected_Body
(N
: Node_Id
) is
979 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
983 -- This is initially the entity of the protected object or protected
984 -- type involved, but is replaced by the protected type always in the
985 -- case of a single protected declaration, since this is the proper
989 -- This is the entity of the protected object or protected type
990 -- involved, and is the entity used for cross-reference purposes
991 -- (it differs from Spec_Id in the case of a single protected
992 -- object, since Spec_Id is set to the protected type in this case).
995 Tasking_Used
:= True;
996 Set_Ekind
(Body_Id
, E_Protected_Body
);
997 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
1000 and then Ekind
(Spec_Id
) = E_Protected_Type
1004 elsif Present
(Spec_Id
)
1005 and then Ekind
(Etype
(Spec_Id
)) = E_Protected_Type
1006 and then not Comes_From_Source
(Etype
(Spec_Id
))
1011 Error_Msg_N
("missing specification for protected body", Body_Id
);
1016 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
1017 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1019 -- The declarations are always attached to the type
1021 if Ekind
(Spec_Id
) /= E_Protected_Type
then
1022 Spec_Id
:= Etype
(Spec_Id
);
1025 New_Scope
(Spec_Id
);
1026 Set_Corresponding_Spec
(N
, Spec_Id
);
1027 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
1028 Set_Has_Completion
(Spec_Id
);
1029 Install_Declarations
(Spec_Id
);
1031 Exp_Ch9
.Expand_Protected_Body_Declarations
(N
, Spec_Id
);
1033 Last_E
:= Last_Entity
(Spec_Id
);
1035 Analyze_Declarations
(Declarations
(N
));
1037 -- For visibility purposes, all entities in the body are private. Set
1038 -- First_Private_Entity accordingly, if there was no private part in the
1039 -- protected declaration.
1041 if No
(First_Private_Entity
(Spec_Id
)) then
1042 if Present
(Last_E
) then
1043 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
1045 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
1049 Check_Completion
(Body_Id
);
1050 Check_References
(Spec_Id
);
1051 Process_End_Label
(N
, 't', Ref_Id
);
1053 end Analyze_Protected_Body
;
1055 ----------------------------------
1056 -- Analyze_Protected_Definition --
1057 ----------------------------------
1059 procedure Analyze_Protected_Definition
(N
: Node_Id
) is
1064 Tasking_Used
:= True;
1065 Analyze_Declarations
(Visible_Declarations
(N
));
1067 if Present
(Private_Declarations
(N
))
1068 and then not Is_Empty_List
(Private_Declarations
(N
))
1070 L
:= Last_Entity
(Current_Scope
);
1071 Analyze_Declarations
(Private_Declarations
(N
));
1074 Set_First_Private_Entity
(Current_Scope
, Next_Entity
(L
));
1076 Set_First_Private_Entity
(Current_Scope
,
1077 First_Entity
(Current_Scope
));
1081 E
:= First_Entity
(Current_Scope
);
1082 while Present
(E
) loop
1083 if Ekind
(E
) = E_Function
1084 or else Ekind
(E
) = E_Procedure
1086 Set_Convention
(E
, Convention_Protected
);
1088 elsif Is_Task_Type
(Etype
(E
))
1089 or else Has_Task
(Etype
(E
))
1091 Set_Has_Task
(Current_Scope
);
1097 Check_Max_Entries
(N
, Max_Protected_Entries
);
1098 Process_End_Label
(N
, 'e', Current_Scope
);
1099 Check_Overriding_Indicator
(N
);
1100 end Analyze_Protected_Definition
;
1102 ----------------------------
1103 -- Analyze_Protected_Type --
1104 ----------------------------
1106 procedure Analyze_Protected_Type
(N
: Node_Id
) is
1109 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1111 Iface_Def
: Node_Id
;
1112 Iface_Typ
: Entity_Id
;
1115 if No_Run_Time_Mode
then
1116 Error_Msg_CRT
("protected type", N
);
1120 Tasking_Used
:= True;
1121 Check_Restriction
(No_Protected_Types
, N
);
1123 T
:= Find_Type_Name
(N
);
1125 if Ekind
(T
) = E_Incomplete_Type
then
1127 Set_Completion_Referenced
(T
);
1130 Set_Ekind
(T
, E_Protected_Type
);
1131 Set_Is_First_Subtype
(T
, True);
1132 Init_Size_Align
(T
);
1134 Set_Has_Delayed_Freeze
(T
, True);
1135 Set_Stored_Constraint
(T
, No_Elist
);
1138 -- Ada 2005 (AI-345)
1140 if Present
(Interface_List
(N
)) then
1141 Set_Is_Tagged_Type
(T
);
1143 Iface
:= First
(Interface_List
(N
));
1144 while Present
(Iface
) loop
1145 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
1146 Iface_Def
:= Type_Definition
(Parent
(Iface_Typ
));
1148 if not Is_Interface
(Iface_Typ
) then
1149 Error_Msg_NE
("(Ada 2005) & must be an interface",
1153 -- Ada 2005 (AI-251): "The declaration of a specific descendant
1154 -- of an interface type freezes the interface type" RM 13.14.
1156 Freeze_Before
(N
, Etype
(Iface
));
1158 -- Ada 2005 (AI-345): Protected types can only implement
1159 -- limited, synchronized or protected interfaces.
1161 if Limited_Present
(Iface_Def
)
1162 or else Synchronized_Present
(Iface_Def
)
1163 or else Protected_Present
(Iface_Def
)
1167 elsif Task_Present
(Iface_Def
) then
1168 Error_Msg_N
("(Ada 2005) protected type cannot implement a "
1169 & "task interface", Iface
);
1172 Error_Msg_N
("(Ada 2005) protected type cannot implement a "
1173 & "non-limited interface", Iface
);
1180 -- If this is the full-declaration associated with a private
1181 -- declaration that implement interfaces, then the private type
1182 -- declaration must be limited.
1184 if Has_Private_Declaration
(T
) then
1189 E
:= First_Entity
(Scope
(T
));
1191 pragma Assert
(Present
(E
));
1193 if Is_Type
(E
) and then Present
(Full_View
(E
)) then
1194 exit when Full_View
(E
) = T
;
1200 if not Is_Limited_Record
(E
) then
1201 Error_Msg_Sloc
:= Sloc
(E
);
1203 ("(Ada 2005) private type declaration # must be limited",
1210 if Present
(Discriminant_Specifications
(N
)) then
1211 if Has_Discriminants
(T
) then
1213 -- Install discriminants. Also, verify conformance of
1214 -- discriminants of previous and current view. ???
1216 Install_Declarations
(T
);
1218 Process_Discriminants
(N
);
1222 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
1224 Analyze
(Protected_Definition
(N
));
1226 -- Protected types with entries are controlled (because of the
1227 -- Protection component if nothing else), same for any protected type
1228 -- with interrupt handlers. Note that we need to analyze the protected
1229 -- definition to set Has_Entries and such.
1231 if (Abort_Allowed
or else Restriction_Active
(No_Entry_Queue
) = False
1232 or else Number_Entries
(T
) > 1)
1235 or else Has_Interrupt_Handler
(T
)
1236 or else Has_Attach_Handler
(T
))
1238 Set_Has_Controlled_Component
(T
, True);
1241 -- The Ekind of components is E_Void during analysis to detect illegal
1242 -- uses. Now it can be set correctly.
1244 E
:= First_Entity
(Current_Scope
);
1245 while Present
(E
) loop
1246 if Ekind
(E
) = E_Void
then
1247 Set_Ekind
(E
, E_Component
);
1248 Init_Component_Location
(E
);
1257 and then Is_Private_Type
(Def_Id
)
1258 and then Has_Discriminants
(Def_Id
)
1259 and then Expander_Active
1261 Exp_Ch9
.Expand_N_Protected_Type_Declaration
(N
);
1262 Process_Full_View
(N
, T
, Def_Id
);
1264 end Analyze_Protected_Type
;
1266 ---------------------
1267 -- Analyze_Requeue --
1268 ---------------------
1270 procedure Analyze_Requeue
(N
: Node_Id
) is
1271 Count
: Natural := 0;
1272 Entry_Name
: Node_Id
:= Name
(N
);
1273 Entry_Id
: Entity_Id
;
1276 Enclosing
: Entity_Id
;
1277 Target_Obj
: Node_Id
:= Empty
;
1278 Req_Scope
: Entity_Id
;
1279 Outer_Ent
: Entity_Id
;
1282 Check_Restriction
(No_Requeue_Statements
, N
);
1283 Check_Unreachable_Code
(N
);
1284 Tasking_Used
:= True;
1287 for J
in reverse 0 .. Scope_Stack
.Last
loop
1288 Enclosing
:= Scope_Stack
.Table
(J
).Entity
;
1289 exit when Is_Entry
(Enclosing
);
1291 if Ekind
(Enclosing
) /= E_Block
1292 and then Ekind
(Enclosing
) /= E_Loop
1294 Error_Msg_N
("requeue must appear within accept or entry body", N
);
1299 Analyze
(Entry_Name
);
1301 if Etype
(Entry_Name
) = Any_Type
then
1305 if Nkind
(Entry_Name
) = N_Selected_Component
then
1306 Target_Obj
:= Prefix
(Entry_Name
);
1307 Entry_Name
:= Selector_Name
(Entry_Name
);
1310 -- If an explicit target object is given then we have to check the
1311 -- restrictions of 9.5.4(6).
1313 if Present
(Target_Obj
) then
1315 -- Locate containing concurrent unit and determine enclosing entry
1316 -- body or outermost enclosing accept statement within the unit.
1319 for S
in reverse 0 .. Scope_Stack
.Last
loop
1320 Req_Scope
:= Scope_Stack
.Table
(S
).Entity
;
1322 exit when Ekind
(Req_Scope
) in Task_Kind
1323 or else Ekind
(Req_Scope
) in Protected_Kind
;
1325 if Is_Entry
(Req_Scope
) then
1326 Outer_Ent
:= Req_Scope
;
1330 pragma Assert
(Present
(Outer_Ent
));
1332 -- Check that the accessibility level of the target object is not
1333 -- greater or equal to the outermost enclosing accept statement (or
1334 -- entry body) unless it is a parameter of the innermost enclosing
1335 -- accept statement (or entry body).
1337 if Object_Access_Level
(Target_Obj
) >= Scope_Depth
(Outer_Ent
)
1339 (not Is_Entity_Name
(Target_Obj
)
1340 or else Ekind
(Entity
(Target_Obj
)) not in Formal_Kind
1341 or else Enclosing
/= Scope
(Entity
(Target_Obj
)))
1344 ("target object has invalid level for requeue", Target_Obj
);
1348 -- Overloaded case, find right interpretation
1350 if Is_Overloaded
(Entry_Name
) then
1353 Get_First_Interp
(Entry_Name
, I
, It
);
1354 while Present
(It
.Nam
) loop
1355 if No
(First_Formal
(It
.Nam
))
1356 or else Subtype_Conformant
(Enclosing
, It
.Nam
)
1358 -- Ada 2005 (AI-345): Since protected and task types have
1359 -- primitive entry wrappers, we only consider source entries.
1361 if Comes_From_Source
(It
.Nam
) then
1369 Get_Next_Interp
(I
, It
);
1373 Error_Msg_N
("no entry matches context", N
);
1376 elsif Count
> 1 then
1377 Error_Msg_N
("ambiguous entry name in requeue", N
);
1381 Set_Is_Overloaded
(Entry_Name
, False);
1382 Set_Entity
(Entry_Name
, Entry_Id
);
1385 -- Non-overloaded cases
1387 -- For the case of a reference to an element of an entry family, the
1388 -- Entry_Name is an indexed component.
1390 elsif Nkind
(Entry_Name
) = N_Indexed_Component
then
1392 -- Requeue to an entry out of the body
1394 if Nkind
(Prefix
(Entry_Name
)) = N_Selected_Component
then
1395 Entry_Id
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
1397 -- Requeue from within the body itself
1399 elsif Nkind
(Prefix
(Entry_Name
)) = N_Identifier
then
1400 Entry_Id
:= Entity
(Prefix
(Entry_Name
));
1403 Error_Msg_N
("invalid entry_name specified", N
);
1407 -- If we had a requeue of the form REQUEUE A (B), then the parser
1408 -- accepted it (because it could have been a requeue on an entry index.
1409 -- If A turns out not to be an entry family, then the analysis of A (B)
1410 -- turned it into a function call.
1412 elsif Nkind
(Entry_Name
) = N_Function_Call
then
1414 ("arguments not allowed in requeue statement",
1415 First
(Parameter_Associations
(Entry_Name
)));
1418 -- Normal case of no entry family, no argument
1421 Entry_Id
:= Entity
(Entry_Name
);
1424 -- Resolve entry, and check that it is subtype conformant with the
1425 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1427 if not Is_Entry
(Entry_Id
) then
1428 Error_Msg_N
("expect entry name in requeue statement", Name
(N
));
1429 elsif Ekind
(Entry_Id
) = E_Entry_Family
1430 and then Nkind
(Entry_Name
) /= N_Indexed_Component
1432 Error_Msg_N
("missing index for entry family component", Name
(N
));
1435 Resolve_Entry
(Name
(N
));
1436 Generate_Reference
(Entry_Id
, Entry_Name
);
1438 if Present
(First_Formal
(Entry_Id
)) then
1439 Check_Subtype_Conformant
(Enclosing
, Entry_Id
, Name
(N
));
1441 -- Processing for parameters accessed by the requeue
1447 Ent
:= First_Formal
(Enclosing
);
1448 while Present
(Ent
) loop
1450 -- For OUT or IN OUT parameter, the effect of the requeue is
1451 -- to assign the parameter a value on exit from the requeued
1452 -- body, so we can set it as source assigned. We also clear
1453 -- the Is_True_Constant indication. We do not need to clear
1454 -- Current_Value, since the effect of the requeue is to
1455 -- perform an unconditional goto so that any further
1456 -- references will not occur anyway.
1458 if Ekind
(Ent
) = E_Out_Parameter
1460 Ekind
(Ent
) = E_In_Out_Parameter
1462 Set_Never_Set_In_Source
(Ent
, False);
1463 Set_Is_True_Constant
(Ent
, False);
1466 -- For all parameters, the requeue acts as a reference,
1467 -- since the value of the parameter is passed to the new
1468 -- entry, so we want to suppress unreferenced warnings.
1470 Set_Referenced
(Ent
);
1476 end Analyze_Requeue
;
1478 ------------------------------
1479 -- Analyze_Selective_Accept --
1480 ------------------------------
1482 procedure Analyze_Selective_Accept
(N
: Node_Id
) is
1483 Alts
: constant List_Id
:= Select_Alternatives
(N
);
1486 Accept_Present
: Boolean := False;
1487 Terminate_Present
: Boolean := False;
1488 Delay_Present
: Boolean := False;
1489 Relative_Present
: Boolean := False;
1490 Alt_Count
: Uint
:= Uint_0
;
1493 Check_Restriction
(No_Select_Statements
, N
);
1494 Tasking_Used
:= True;
1496 -- Loop to analyze alternatives
1498 Alt
:= First
(Alts
);
1499 while Present
(Alt
) loop
1500 Alt_Count
:= Alt_Count
+ 1;
1503 if Nkind
(Alt
) = N_Delay_Alternative
then
1504 if Delay_Present
then
1506 if Relative_Present
/=
1507 (Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
)
1510 ("delay_until and delay_relative alternatives ", Alt
);
1512 ("\cannot appear in the same selective_wait", Alt
);
1516 Delay_Present
:= True;
1518 Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
;
1521 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
1522 if Terminate_Present
then
1523 Error_Msg_N
("only one terminate alternative allowed", N
);
1525 Terminate_Present
:= True;
1526 Check_Restriction
(No_Terminate_Alternatives
, N
);
1529 elsif Nkind
(Alt
) = N_Accept_Alternative
then
1530 Accept_Present
:= True;
1532 -- Check for duplicate accept
1536 Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
1537 EDN
: constant Node_Id
:= Entry_Direct_Name
(Stm
);
1541 if Nkind
(EDN
) = N_Identifier
1542 and then No
(Condition
(Alt
))
1543 and then Present
(Entity
(EDN
)) -- defend against junk
1544 and then Ekind
(Entity
(EDN
)) = E_Entry
1546 Ent
:= Entity
(EDN
);
1548 Alt1
:= First
(Alts
);
1549 while Alt1
/= Alt
loop
1550 if Nkind
(Alt1
) = N_Accept_Alternative
1551 and then No
(Condition
(Alt1
))
1554 Stm1
: constant Node_Id
:= Accept_Statement
(Alt1
);
1555 EDN1
: constant Node_Id
:= Entry_Direct_Name
(Stm1
);
1558 if Nkind
(EDN1
) = N_Identifier
then
1559 if Entity
(EDN1
) = Ent
then
1560 Error_Msg_Sloc
:= Sloc
(Stm1
);
1562 ("?accept duplicates one on line#", Stm
);
1578 Check_Restriction
(Max_Select_Alternatives
, N
, Alt_Count
);
1579 Check_Potentially_Blocking_Operation
(N
);
1581 if Terminate_Present
and Delay_Present
then
1582 Error_Msg_N
("at most one of terminate or delay alternative", N
);
1584 elsif not Accept_Present
then
1586 ("select must contain at least one accept alternative", N
);
1589 if Present
(Else_Statements
(N
)) then
1590 if Terminate_Present
or Delay_Present
then
1591 Error_Msg_N
("else part not allowed with other alternatives", N
);
1594 Analyze_Statements
(Else_Statements
(N
));
1596 end Analyze_Selective_Accept
;
1598 ------------------------------
1599 -- Analyze_Single_Protected --
1600 ------------------------------
1602 procedure Analyze_Single_Protected
(N
: Node_Id
) is
1603 Loc
: constant Source_Ptr
:= Sloc
(N
);
1604 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1608 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1611 Generate_Definition
(Id
);
1612 Tasking_Used
:= True;
1614 -- The node is rewritten as a protected type declaration, in exact
1615 -- analogy with what is done with single tasks.
1618 Make_Defining_Identifier
(Sloc
(Id
),
1619 New_External_Name
(Chars
(Id
), 'T'));
1622 Make_Protected_Type_Declaration
(Loc
,
1623 Defining_Identifier
=> T
,
1624 Protected_Definition
=> Relocate_Node
(Protected_Definition
(N
)),
1625 Interface_List
=> Interface_List
(N
));
1628 Make_Object_Declaration
(Loc
,
1629 Defining_Identifier
=> O_Name
,
1630 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1632 Rewrite
(N
, T_Decl
);
1633 Insert_After
(N
, O_Decl
);
1634 Mark_Rewrite_Insertion
(O_Decl
);
1636 -- Enter names of type and object before analysis, because the name of
1637 -- the object may be used in its own body.
1640 Set_Ekind
(T
, E_Protected_Type
);
1643 Enter_Name
(O_Name
);
1644 Set_Ekind
(O_Name
, E_Variable
);
1645 Set_Etype
(O_Name
, T
);
1647 -- Instead of calling Analyze on the new node, call the proper analysis
1648 -- procedure directly. Otherwise the node would be expanded twice, with
1649 -- disastrous result.
1651 Analyze_Protected_Type
(N
);
1652 end Analyze_Single_Protected
;
1654 -------------------------
1655 -- Analyze_Single_Task --
1656 -------------------------
1658 procedure Analyze_Single_Task
(N
: Node_Id
) is
1659 Loc
: constant Source_Ptr
:= Sloc
(N
);
1660 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1664 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1667 Generate_Definition
(Id
);
1668 Tasking_Used
:= True;
1670 -- The node is rewritten as a task type declaration, followed by an
1671 -- object declaration of that anonymous task type.
1674 Make_Defining_Identifier
(Sloc
(Id
),
1675 New_External_Name
(Chars
(Id
), Suffix
=> "TK"));
1678 Make_Task_Type_Declaration
(Loc
,
1679 Defining_Identifier
=> T
,
1680 Task_Definition
=> Relocate_Node
(Task_Definition
(N
)),
1681 Interface_List
=> Interface_List
(N
));
1684 Make_Object_Declaration
(Loc
,
1685 Defining_Identifier
=> O_Name
,
1686 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1688 Rewrite
(N
, T_Decl
);
1689 Insert_After
(N
, O_Decl
);
1690 Mark_Rewrite_Insertion
(O_Decl
);
1692 -- Enter names of type and object before analysis, because the name of
1693 -- the object may be used in its own body.
1696 Set_Ekind
(T
, E_Task_Type
);
1699 Enter_Name
(O_Name
);
1700 Set_Ekind
(O_Name
, E_Variable
);
1701 Set_Etype
(O_Name
, T
);
1703 -- Instead of calling Analyze on the new node, call the proper analysis
1704 -- procedure directly. Otherwise the node would be expanded twice, with
1705 -- disastrous result.
1707 Analyze_Task_Type
(N
);
1708 end Analyze_Single_Task
;
1710 -----------------------
1711 -- Analyze_Task_Body --
1712 -----------------------
1714 procedure Analyze_Task_Body
(N
: Node_Id
) is
1715 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1718 Spec_Id
: Entity_Id
;
1719 -- This is initially the entity of the task or task type involved, but
1720 -- is replaced by the task type always in the case of a single task
1721 -- declaration, since this is the proper scope to be used.
1724 -- This is the entity of the task or task type, and is the entity used
1725 -- for cross-reference purposes (it differs from Spec_Id in the case of
1726 -- a single task, since Spec_Id is set to the task type)
1729 Tasking_Used
:= True;
1730 Set_Ekind
(Body_Id
, E_Task_Body
);
1731 Set_Scope
(Body_Id
, Current_Scope
);
1732 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
1734 -- The spec is either a task type declaration, or a single task
1735 -- declaration for which we have created an anonymous type.
1737 if Present
(Spec_Id
)
1738 and then Ekind
(Spec_Id
) = E_Task_Type
1742 elsif Present
(Spec_Id
)
1743 and then Ekind
(Etype
(Spec_Id
)) = E_Task_Type
1744 and then not Comes_From_Source
(Etype
(Spec_Id
))
1749 Error_Msg_N
("missing specification for task body", Body_Id
);
1753 if Has_Completion
(Spec_Id
)
1754 and then Present
(Corresponding_Body
(Parent
(Spec_Id
)))
1756 if Nkind
(Parent
(Spec_Id
)) = N_Task_Type_Declaration
then
1757 Error_Msg_NE
("duplicate body for task type&", N
, Spec_Id
);
1760 Error_Msg_NE
("duplicate body for task&", N
, Spec_Id
);
1765 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
1766 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1768 -- Deal with case of body of single task (anonymous type was created)
1770 if Ekind
(Spec_Id
) = E_Variable
then
1771 Spec_Id
:= Etype
(Spec_Id
);
1774 New_Scope
(Spec_Id
);
1775 Set_Corresponding_Spec
(N
, Spec_Id
);
1776 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
1777 Set_Has_Completion
(Spec_Id
);
1778 Install_Declarations
(Spec_Id
);
1779 Last_E
:= Last_Entity
(Spec_Id
);
1781 Analyze_Declarations
(Declarations
(N
));
1783 -- For visibility purposes, all entities in the body are private. Set
1784 -- First_Private_Entity accordingly, if there was no private part in the
1785 -- protected declaration.
1787 if No
(First_Private_Entity
(Spec_Id
)) then
1788 if Present
(Last_E
) then
1789 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
1791 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
1795 Analyze
(Handled_Statement_Sequence
(N
));
1796 Check_Completion
(Body_Id
);
1797 Check_References
(Body_Id
);
1798 Check_References
(Spec_Id
);
1800 -- Check for entries with no corresponding accept
1806 Ent
:= First_Entity
(Spec_Id
);
1807 while Present
(Ent
) loop
1809 and then not Entry_Accepted
(Ent
)
1810 and then Comes_From_Source
(Ent
)
1812 Error_Msg_NE
("no accept for entry &?", N
, Ent
);
1819 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Ref_Id
);
1821 end Analyze_Task_Body
;
1823 -----------------------------
1824 -- Analyze_Task_Definition --
1825 -----------------------------
1827 procedure Analyze_Task_Definition
(N
: Node_Id
) is
1831 Tasking_Used
:= True;
1833 if Present
(Visible_Declarations
(N
)) then
1834 Analyze_Declarations
(Visible_Declarations
(N
));
1837 if Present
(Private_Declarations
(N
)) then
1838 L
:= Last_Entity
(Current_Scope
);
1839 Analyze_Declarations
(Private_Declarations
(N
));
1842 Set_First_Private_Entity
1843 (Current_Scope
, Next_Entity
(L
));
1845 Set_First_Private_Entity
1846 (Current_Scope
, First_Entity
(Current_Scope
));
1850 Check_Max_Entries
(N
, Max_Task_Entries
);
1851 Process_End_Label
(N
, 'e', Current_Scope
);
1852 Check_Overriding_Indicator
(N
);
1853 end Analyze_Task_Definition
;
1855 -----------------------
1856 -- Analyze_Task_Type --
1857 -----------------------
1859 procedure Analyze_Task_Type
(N
: Node_Id
) is
1861 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1863 Iface_Def
: Node_Id
;
1864 Iface_Typ
: Entity_Id
;
1867 Check_Restriction
(No_Tasking
, N
);
1868 Tasking_Used
:= True;
1869 T
:= Find_Type_Name
(N
);
1870 Generate_Definition
(T
);
1872 if Ekind
(T
) = E_Incomplete_Type
then
1874 Set_Completion_Referenced
(T
);
1877 Set_Ekind
(T
, E_Task_Type
);
1878 Set_Is_First_Subtype
(T
, True);
1879 Set_Has_Task
(T
, True);
1880 Init_Size_Align
(T
);
1882 Set_Has_Delayed_Freeze
(T
, True);
1883 Set_Stored_Constraint
(T
, No_Elist
);
1886 -- Ada 2005 (AI-345)
1888 if Present
(Interface_List
(N
)) then
1889 Set_Is_Tagged_Type
(T
);
1891 Iface
:= First
(Interface_List
(N
));
1892 while Present
(Iface
) loop
1893 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
1894 Iface_Def
:= Type_Definition
(Parent
(Iface_Typ
));
1896 if not Is_Interface
(Iface_Typ
) then
1897 Error_Msg_NE
("(Ada 2005) & must be an interface",
1901 -- Ada 2005 (AI-251): The declaration of a specific descendant
1902 -- of an interface type freezes the interface type (RM 13.14).
1904 Freeze_Before
(N
, Etype
(Iface
));
1906 -- Ada 2005 (AI-345): Task types can only implement limited,
1907 -- synchronized or task interfaces.
1909 if Limited_Present
(Iface_Def
)
1910 or else Synchronized_Present
(Iface_Def
)
1911 or else Task_Present
(Iface_Def
)
1915 elsif Protected_Present
(Iface_Def
) then
1916 Error_Msg_N
("(Ada 2005) task type cannot implement a " &
1917 "protected interface", Iface
);
1920 Error_Msg_N
("(Ada 2005) task type cannot implement a " &
1921 "non-limited interface", Iface
);
1928 -- If this is the full-declaration associated with a private
1929 -- declaration that implement interfaces, then the private
1930 -- type declaration must be limited.
1932 if Has_Private_Declaration
(T
) then
1937 E
:= First_Entity
(Scope
(T
));
1939 pragma Assert
(Present
(E
));
1941 if Is_Type
(E
) and then Present
(Full_View
(E
)) then
1942 exit when Full_View
(E
) = T
;
1948 if not Is_Limited_Record
(E
) then
1949 Error_Msg_Sloc
:= Sloc
(E
);
1951 ("(Ada 2005) private type declaration # must be limited",
1958 if Present
(Discriminant_Specifications
(N
)) then
1959 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1960 Error_Msg_N
("(Ada 83) task discriminant not allowed!", N
);
1963 if Has_Discriminants
(T
) then
1965 -- Install discriminants. Also, verify conformance of
1966 -- discriminants of previous and current view. ???
1968 Install_Declarations
(T
);
1970 Process_Discriminants
(N
);
1974 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
1976 if Present
(Task_Definition
(N
)) then
1977 Analyze_Task_Definition
(Task_Definition
(N
));
1980 if not Is_Library_Level_Entity
(T
) then
1981 Check_Restriction
(No_Task_Hierarchy
, N
);
1987 and then Is_Private_Type
(Def_Id
)
1988 and then Has_Discriminants
(Def_Id
)
1989 and then Expander_Active
1991 Exp_Ch9
.Expand_N_Task_Type_Declaration
(N
);
1992 Process_Full_View
(N
, T
, Def_Id
);
1994 end Analyze_Task_Type
;
1996 -----------------------------------
1997 -- Analyze_Terminate_Alternative --
1998 -----------------------------------
2000 procedure Analyze_Terminate_Alternative
(N
: Node_Id
) is
2002 Tasking_Used
:= True;
2004 if Present
(Pragmas_Before
(N
)) then
2005 Analyze_List
(Pragmas_Before
(N
));
2008 if Present
(Condition
(N
)) then
2009 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
2011 end Analyze_Terminate_Alternative
;
2013 ------------------------------
2014 -- Analyze_Timed_Entry_Call --
2015 ------------------------------
2017 procedure Analyze_Timed_Entry_Call
(N
: Node_Id
) is
2019 Check_Restriction
(No_Select_Statements
, N
);
2020 Tasking_Used
:= True;
2021 Analyze
(Entry_Call_Alternative
(N
));
2022 Analyze
(Delay_Alternative
(N
));
2023 end Analyze_Timed_Entry_Call
;
2025 ------------------------------------
2026 -- Analyze_Triggering_Alternative --
2027 ------------------------------------
2029 procedure Analyze_Triggering_Alternative
(N
: Node_Id
) is
2030 Trigger
: constant Node_Id
:= Triggering_Statement
(N
);
2033 Tasking_Used
:= True;
2035 if Present
(Pragmas_Before
(N
)) then
2036 Analyze_List
(Pragmas_Before
(N
));
2041 if Comes_From_Source
(Trigger
)
2042 and then Nkind
(Trigger
) not in N_Delay_Statement
2043 and then Nkind
(Trigger
) /= N_Entry_Call_Statement
2045 if Ada_Version
< Ada_05
then
2047 ("triggering statement must be delay or entry call", Trigger
);
2049 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
2050 -- procedure_or_entry_call, the procedure_name or pro- cedure_prefix
2051 -- of the procedure_call_statement shall denote an entry renamed by a
2052 -- procedure, or (a view of) a primitive subprogram of a limited
2053 -- interface whose first parameter is a controlling parameter.
2055 elsif Nkind
(Trigger
) = N_Procedure_Call_Statement
2056 and then not Is_Renamed_Entry
(Entity
(Name
(Trigger
)))
2057 and then not Is_Controlling_Limited_Procedure
2058 (Entity
(Name
(Trigger
)))
2060 Error_Msg_N
("triggering statement must be delay, procedure " &
2061 "or entry call", Trigger
);
2065 if Is_Non_Empty_List
(Statements
(N
)) then
2066 Analyze_Statements
(Statements
(N
));
2068 end Analyze_Triggering_Alternative
;
2070 -----------------------
2071 -- Check_Max_Entries --
2072 -----------------------
2074 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
) is
2077 procedure Count
(L
: List_Id
);
2078 -- Count entries in given declaration list
2084 procedure Count
(L
: List_Id
) is
2093 while Present
(D
) loop
2094 if Nkind
(D
) = N_Entry_Declaration
then
2096 DSD
: constant Node_Id
:=
2097 Discrete_Subtype_Definition
(D
);
2100 -- If not an entry family, then just one entry
2103 Ecount
:= Ecount
+ 1;
2105 -- If entry family with static bounds, count entries
2107 elsif Is_OK_Static_Subtype
(Etype
(DSD
)) then
2109 Lo
: constant Uint
:=
2111 (Type_Low_Bound
(Etype
(DSD
)));
2112 Hi
: constant Uint
:=
2114 (Type_High_Bound
(Etype
(DSD
)));
2118 Ecount
:= Ecount
+ Hi
- Lo
+ 1;
2122 -- Entry family with non-static bounds
2125 -- If restriction is set, then this is an error
2127 if Restrictions
.Set
(R
) then
2129 ("static subtype required by Restriction pragma",
2132 -- Otherwise we record an unknown count restriction
2135 Check_Restriction
(R
, D
);
2145 -- Start of processing for Check_Max_Entries
2149 Count
(Visible_Declarations
(D
));
2150 Count
(Private_Declarations
(D
));
2153 Check_Restriction
(R
, D
, Ecount
);
2155 end Check_Max_Entries
;
2157 --------------------------------
2158 -- Check_Overriding_Indicator --
2159 --------------------------------
2161 procedure Check_Overriding_Indicator
(Def
: Node_Id
) is
2162 Aliased_Hom
: Entity_Id
;
2166 Ifaces
: constant List_Id
:= Interface_List
(Parent
(Def
));
2167 Overrides
: Boolean;
2169 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Def
);
2171 function Matches_Prefixed_View_Profile
2173 Entry_Params
: List_Id
;
2174 Proc_Params
: List_Id
) return Boolean;
2175 -- Ada 2005 (AI-397): Determine if an entry parameter profile matches
2176 -- the prefixed view profile of an abstract procedure. Also determine
2177 -- whether the abstract procedure belongs to an implemented interface.
2179 -----------------------------------
2180 -- Matches_Prefixed_View_Profile --
2181 -----------------------------------
2183 function Matches_Prefixed_View_Profile
2185 Entry_Params
: List_Id
;
2186 Proc_Params
: List_Id
) return Boolean
2188 Entry_Param
: Node_Id
;
2189 Proc_Param
: Node_Id
;
2190 Proc_Param_Typ
: Entity_Id
;
2192 function Includes_Interface
2194 Ifaces
: List_Id
) return Boolean;
2195 -- Determine if an interface is contained in a list of interfaces
2197 ------------------------
2198 -- Includes_Interface --
2199 ------------------------
2201 function Includes_Interface
2203 Ifaces
: List_Id
) return Boolean
2208 Ent
:= First
(Ifaces
);
2209 while Present
(Ent
) loop
2210 if Etype
(Ent
) = Iface
then
2218 end Includes_Interface
;
2220 -- Start of processing for Matches_Prefixed_View_Profile
2223 Proc_Param
:= First
(Proc_Params
);
2224 Proc_Param_Typ
:= Etype
(Parameter_Type
(Proc_Param
));
2226 -- The first parameter of the abstract procedure must be of an
2227 -- interface type. The task or protected type must also implement
2230 if not Is_Interface
(Proc_Param_Typ
)
2231 or else not Includes_Interface
(Proc_Param_Typ
, Ifaces
)
2236 Entry_Param
:= First
(Entry_Params
);
2237 Proc_Param
:= Next
(Proc_Param
);
2238 while Present
(Entry_Param
) and then Present
(Proc_Param
) loop
2240 -- The two parameters must be mode conformant and have the exact
2243 if Ekind
(Defining_Identifier
(Entry_Param
)) /=
2244 Ekind
(Defining_Identifier
(Proc_Param
))
2245 or else Etype
(Parameter_Type
(Entry_Param
)) /=
2246 Etype
(Parameter_Type
(Proc_Param
))
2255 -- One of the lists is longer than the other
2257 if Present
(Entry_Param
) or else Present
(Proc_Param
) then
2262 end Matches_Prefixed_View_Profile
;
2264 -- Start of processing for Check_Overriding_Indicator
2267 if Present
(Ifaces
) then
2268 Decl
:= First
(Vis_Decls
);
2269 while Present
(Decl
) loop
2271 -- Consider entries with either "overriding" or "not overriding"
2272 -- indicator present.
2274 if Nkind
(Decl
) = N_Entry_Declaration
2275 and then (Must_Override
(Decl
)
2277 Must_Not_Override
(Decl
))
2279 Def_Id
:= Defining_Identifier
(Decl
);
2283 Hom
:= Homonym
(Def_Id
);
2284 while Present
(Hom
) loop
2286 -- The current entry may override a procedure from an
2287 -- implemented interface.
2289 if Ekind
(Hom
) = E_Procedure
2290 and then (Is_Abstract
(Hom
)
2292 Null_Present
(Parent
(Hom
)))
2295 while Present
(Alias
(Aliased_Hom
)) loop
2296 Aliased_Hom
:= Alias
(Aliased_Hom
);
2299 if Matches_Prefixed_View_Profile
(Ifaces
,
2300 Parameter_Specifications
(Decl
),
2301 Parameter_Specifications
(Parent
(Aliased_Hom
)))
2308 Hom
:= Homonym
(Hom
);
2312 if Must_Not_Override
(Decl
) then
2313 Error_Msg_NE
("entry& is overriding", Def_Id
, Def_Id
);
2316 if Must_Override
(Decl
) then
2317 Error_Msg_NE
("entry& is not overriding", Def_Id
, Def_Id
);
2321 -- Consider subprograms with either "overriding" or "not
2322 -- overriding" indicator present.
2324 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2325 and then (Must_Override
(Specification
(Decl
))
2327 Must_Not_Override
(Specification
(Decl
)))
2329 Spec
:= Specification
(Decl
);
2330 Def_Id
:= Defining_Unit_Name
(Spec
);
2334 Hom
:= Homonym
(Def_Id
);
2335 while Present
(Hom
) loop
2339 if Ekind
(Def_Id
) = E_Function
2340 and then Ekind
(Hom
) = E_Function
2341 and then Is_Abstract
(Hom
)
2342 and then Matches_Prefixed_View_Profile
(Ifaces
,
2343 Parameter_Specifications
(Spec
),
2344 Parameter_Specifications
(Parent
(Hom
)))
2345 and then Etype
(Result_Definition
(Spec
)) =
2346 Etype
(Result_Definition
(Parent
(Hom
)))
2353 elsif Ekind
(Def_Id
) = E_Procedure
2354 and then Ekind
(Hom
) = E_Procedure
2355 and then (Is_Abstract
(Hom
)
2357 Null_Present
(Parent
(Hom
)))
2358 and then Matches_Prefixed_View_Profile
(Ifaces
,
2359 Parameter_Specifications
(Spec
),
2360 Parameter_Specifications
(Parent
(Hom
)))
2366 Hom
:= Homonym
(Hom
);
2370 if Must_Not_Override
(Spec
) then
2372 ("subprogram& is overriding", Def_Id
, Def_Id
);
2375 if Must_Override
(Spec
) then
2377 ("subprogram& is not overriding", Def_Id
, Def_Id
);
2385 -- The protected or task type is not implementing an interface, we need
2386 -- to check for the presence of "overriding" entries or subprograms and
2387 -- flag them as erroneous.
2390 Decl
:= First
(Vis_Decls
);
2391 while Present
(Decl
) loop
2392 if Nkind
(Decl
) = N_Entry_Declaration
2393 and then Must_Override
(Decl
)
2395 Def_Id
:= Defining_Identifier
(Decl
);
2396 Error_Msg_NE
("entry& is not overriding", Def_Id
, Def_Id
);
2398 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2399 and then Must_Override
(Specification
(Decl
))
2401 Def_Id
:= Defining_Identifier
(Specification
(Decl
));
2402 Error_Msg_NE
("subprogram& is not overriding", Def_Id
, Def_Id
);
2408 end Check_Overriding_Indicator
;
2410 --------------------------
2411 -- Find_Concurrent_Spec --
2412 --------------------------
2414 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
is
2415 Spec_Id
: Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2418 -- The type may have been given by an incomplete type declaration.
2419 -- Find full view now.
2421 if Present
(Spec_Id
) and then Ekind
(Spec_Id
) = E_Incomplete_Type
then
2422 Spec_Id
:= Full_View
(Spec_Id
);
2426 end Find_Concurrent_Spec
;
2428 --------------------------
2429 -- Install_Declarations --
2430 --------------------------
2432 procedure Install_Declarations
(Spec
: Entity_Id
) is
2436 E
:= First_Entity
(Spec
);
2437 while Present
(E
) loop
2438 Prev
:= Current_Entity
(E
);
2439 Set_Current_Entity
(E
);
2440 Set_Is_Immediately_Visible
(E
);
2441 Set_Homonym
(E
, Prev
);
2444 end Install_Declarations
;