1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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
74 -- the 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
82 -- in 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,
166 -- create a new index type where a discriminant is replaced by the
167 -- local 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
);
188 if not Is_Entity_Name
(Bound
)
189 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
194 Ref
:= Make_Identifier
(Sloc
(N
), Chars
(Entity
(Bound
)));
199 end Actual_Discriminant_Ref
;
201 -- Start of processing for Actual_Index_Type
204 if not Has_Discriminants
(Task_Nam
)
205 or else (not Is_Entity_Name
(Lo
)
206 and then not Is_Entity_Name
(Hi
))
208 return Entry_Index_Type
(E
);
210 New_T
:= Create_Itype
(Ekind
(Typ
), N
);
211 Set_Etype
(New_T
, Base_Type
(Typ
));
212 Set_Size_Info
(New_T
, Typ
);
213 Set_RM_Size
(New_T
, RM_Size
(Typ
));
214 Set_Scalar_Range
(New_T
,
215 Make_Range
(Sloc
(N
),
216 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
217 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
221 end Actual_Index_Type
;
223 -- Start of processing for Analyze_Accept_Statement
226 Tasking_Used
:= True;
228 -- Entry name is initialized to Any_Id. It should get reset to the
229 -- matching entry entity. An error is signalled if it is not reset.
233 for J
in reverse 0 .. Scope_Stack
.Last
loop
234 Task_Nam
:= Scope_Stack
.Table
(J
).Entity
;
235 exit when Ekind
(Etype
(Task_Nam
)) = E_Task_Type
;
236 Kind
:= Ekind
(Task_Nam
);
238 if Kind
/= E_Block
and then Kind
/= E_Loop
239 and then not Is_Entry
(Task_Nam
)
241 Error_Msg_N
("enclosing body of accept must be a task", N
);
246 if Ekind
(Etype
(Task_Nam
)) /= E_Task_Type
then
247 Error_Msg_N
("invalid context for accept statement", N
);
251 -- In order to process the parameters, we create a defining
252 -- identifier that can be used as the name of the scope. The
253 -- name of the accept statement itself is not a defining identifier,
254 -- and we cannot use its name directly because the task may have
255 -- any number of accept statements for the same entry.
257 if Present
(Index
) then
258 Accept_Id
:= New_Internal_Entity
259 (E_Entry_Family
, Current_Scope
, Sloc
(N
), 'E');
261 Accept_Id
:= New_Internal_Entity
262 (E_Entry
, Current_Scope
, Sloc
(N
), 'E');
265 Set_Etype
(Accept_Id
, Standard_Void_Type
);
266 Set_Accept_Address
(Accept_Id
, New_Elmt_List
);
268 if Present
(Formals
) then
269 New_Scope
(Accept_Id
);
270 Process_Formals
(Formals
, N
);
271 Create_Extra_Formals
(Accept_Id
);
275 -- We set the default expressions processed flag because we don't
276 -- need default expression functions. This is really more like a
277 -- body entity than a spec entity anyway.
279 Set_Default_Expressions_Processed
(Accept_Id
);
281 E
:= First_Entity
(Etype
(Task_Nam
));
282 while Present
(E
) loop
283 if Chars
(E
) = Chars
(Nam
)
284 and then (Ekind
(E
) = Ekind
(Accept_Id
))
285 and then Type_Conformant
(Accept_Id
, E
)
294 if Entry_Nam
= Any_Id
then
295 Error_Msg_N
("no entry declaration matches accept statement", N
);
298 Set_Entity
(Nam
, Entry_Nam
);
299 Generate_Reference
(Entry_Nam
, Nam
, 'b', Set_Ref
=> False);
300 Style
.Check_Identifier
(Nam
, Entry_Nam
);
303 -- Verify that the entry is not hidden by a procedure declared in
304 -- the current block (pathological but possible).
306 if Current_Scope
/= Task_Nam
then
311 E1
:= First_Entity
(Current_Scope
);
312 while Present
(E1
) loop
313 if Ekind
(E1
) = E_Procedure
314 and then Chars
(E1
) = Chars
(Entry_Nam
)
315 and then Type_Conformant
(E1
, Entry_Nam
)
317 Error_Msg_N
("entry name is not visible", N
);
325 Set_Convention
(Accept_Id
, Convention
(Entry_Nam
));
326 Check_Fully_Conformant
(Accept_Id
, Entry_Nam
, N
);
328 for J
in reverse 0 .. Scope_Stack
.Last
loop
329 exit when Task_Nam
= Scope_Stack
.Table
(J
).Entity
;
331 if Entry_Nam
= Scope_Stack
.Table
(J
).Entity
then
332 Error_Msg_N
("duplicate accept statement for same entry", N
);
343 when N_Task_Body | N_Compilation_Unit
=>
345 when N_Asynchronous_Select
=>
346 Error_Msg_N
("accept statements are not allowed within" &
347 " an asynchronous select inner" &
348 " to the enclosing task body", N
);
356 if Ekind
(E
) = E_Entry_Family
then
358 Error_Msg_N
("missing entry index in accept for entry family", N
);
360 Analyze_And_Resolve
(Index
, Entry_Index_Type
(E
));
361 Apply_Range_Check
(Index
, Actual_Index_Type
(E
));
364 elsif Present
(Index
) then
365 Error_Msg_N
("invalid entry index in accept for simple entry", N
);
368 -- If label declarations present, analyze them. They are declared
369 -- in the enclosing task, but their enclosing scope is the entry itself,
370 -- so that goto's to the label are recognized as local to the accept.
372 if Present
(Declarations
(N
)) then
379 Decl
:= First
(Declarations
(N
));
380 while Present
(Decl
) loop
384 (Nkind
(Decl
) = N_Implicit_Label_Declaration
);
386 Id
:= Defining_Identifier
(Decl
);
387 Set_Enclosing_Scope
(Id
, Entry_Nam
);
393 -- If statements are present, they must be analyzed in the context
394 -- of the entry, so that references to formals are correctly resolved.
395 -- We also have to add the declarations that are required by the
396 -- expansion of the accept statement in this case if expansion active.
398 -- In the case of a select alternative of a selective accept,
399 -- the expander references the address declaration even if there
400 -- is no statement list.
402 -- We also need to create the renaming declarations for the local
403 -- variables that will replace references to the formals within
406 Exp_Ch9
.Expand_Accept_Declarations
(N
, Entry_Nam
);
408 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
409 -- fields on all entry formals (this loop ignores all other entities).
410 -- Reset Set_Referenced and Has_Pragma_Unreferenced as well, so that
411 -- we can post accurate warnings on each accept statement for the same
414 E
:= First_Entity
(Entry_Nam
);
415 while Present
(E
) loop
416 if Is_Formal
(E
) then
417 Set_Never_Set_In_Source
(E
, True);
418 Set_Is_True_Constant
(E
, False);
419 Set_Current_Value
(E
, Empty
);
420 Set_Referenced
(E
, False);
421 Set_Has_Pragma_Unreferenced
(E
, False);
427 -- Analyze statements if present
429 if Present
(Stats
) then
430 New_Scope
(Entry_Nam
);
431 Install_Declarations
(Entry_Nam
);
433 Set_Actual_Subtypes
(N
, Current_Scope
);
436 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Nam
);
440 -- Some warning checks
442 Check_Potentially_Blocking_Operation
(N
);
443 Check_References
(Entry_Nam
, N
);
444 Set_Entry_Accepted
(Entry_Nam
);
445 end Analyze_Accept_Statement
;
447 ---------------------------------
448 -- Analyze_Asynchronous_Select --
449 ---------------------------------
451 procedure Analyze_Asynchronous_Select
(N
: Node_Id
) is
456 Tasking_Used
:= True;
457 Check_Restriction
(Max_Asynchronous_Select_Nesting
, N
);
458 Check_Restriction
(No_Select_Statements
, N
);
460 if Ada_Version
>= Ada_05
then
461 Trigger
:= Triggering_Statement
(Triggering_Alternative
(N
));
465 -- The trigger is a dispatching procedure. Postpone the analysis
466 -- of the triggering and abortable statements until the expansion
467 -- of this asynchronous select in Expand_N_Asynchronous_Select.
468 -- This action is required since the code replication in Expand-
469 -- _N_Asynchronous_Select of an already analyzed statement list
470 -- causes Gigi aborts.
473 and then Nkind
(Trigger
) = N_Procedure_Call_Statement
474 and then Present
(Parameter_Associations
(Trigger
))
476 Param
:= First
(Parameter_Associations
(Trigger
));
478 if Is_Controlling_Actual
(Param
)
479 and then Is_Interface
(Etype
(Param
))
481 if Is_Limited_Record
(Etype
(Param
)) then
485 ("dispatching operation of limited or synchronized " &
486 "interface required ('R'M 9.7.2(3))!", N
);
492 -- Analyze the statements. We analyze statements in the abortable part,
493 -- because this is the section that is executed first, and that way our
494 -- remembering of saved values and checks is accurate.
496 Analyze_Statements
(Statements
(Abortable_Part
(N
)));
497 Analyze
(Triggering_Alternative
(N
));
498 end Analyze_Asynchronous_Select
;
500 ------------------------------------
501 -- Analyze_Conditional_Entry_Call --
502 ------------------------------------
504 procedure Analyze_Conditional_Entry_Call
(N
: Node_Id
) is
506 Check_Restriction
(No_Select_Statements
, N
);
507 Tasking_Used
:= True;
508 Analyze
(Entry_Call_Alternative
(N
));
510 if List_Length
(Else_Statements
(N
)) = 1
511 and then Nkind
(First
(Else_Statements
(N
))) in N_Delay_Statement
514 ("suspicious form of conditional entry call?", N
);
516 ("\`SELECT OR` may be intended rather than `SELECT ELSE`", N
);
519 Analyze_Statements
(Else_Statements
(N
));
520 end Analyze_Conditional_Entry_Call
;
522 --------------------------------
523 -- Analyze_Delay_Alternative --
524 --------------------------------
526 procedure Analyze_Delay_Alternative
(N
: Node_Id
) is
531 Tasking_Used
:= True;
532 Check_Restriction
(No_Delay
, N
);
534 if Present
(Pragmas_Before
(N
)) then
535 Analyze_List
(Pragmas_Before
(N
));
538 if Nkind
(Parent
(N
)) = N_Selective_Accept
539 or else Nkind
(Parent
(N
)) = N_Timed_Entry_Call
541 Expr
:= Expression
(Delay_Statement
(N
));
543 -- defer full analysis until the statement is expanded, to insure
544 -- that generated code does not move past the guard. The delay
545 -- expression is only evaluated if the guard is open.
547 if Nkind
(Delay_Statement
(N
)) = N_Delay_Relative_Statement
then
548 Pre_Analyze_And_Resolve
(Expr
, Standard_Duration
);
550 Pre_Analyze_And_Resolve
(Expr
);
553 Typ
:= First_Subtype
(Etype
(Expr
));
555 if Nkind
(Delay_Statement
(N
)) = N_Delay_Until_Statement
556 and then not Is_RTE
(Typ
, RO_CA_Time
)
557 and then not Is_RTE
(Typ
, RO_RT_Time
)
559 Error_Msg_N
("expect Time types for `DELAY UNTIL`", Expr
);
562 Check_Restriction
(No_Fixed_Point
, Expr
);
565 Analyze
(Delay_Statement
(N
));
568 if Present
(Condition
(N
)) then
569 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
572 if Is_Non_Empty_List
(Statements
(N
)) then
573 Analyze_Statements
(Statements
(N
));
575 end Analyze_Delay_Alternative
;
577 ----------------------------
578 -- Analyze_Delay_Relative --
579 ----------------------------
581 procedure Analyze_Delay_Relative
(N
: Node_Id
) is
582 E
: constant Node_Id
:= Expression
(N
);
585 Check_Restriction
(No_Relative_Delay
, N
);
586 Tasking_Used
:= True;
587 Check_Restriction
(No_Delay
, N
);
588 Check_Potentially_Blocking_Operation
(N
);
589 Analyze_And_Resolve
(E
, Standard_Duration
);
590 Check_Restriction
(No_Fixed_Point
, E
);
591 end Analyze_Delay_Relative
;
593 -------------------------
594 -- Analyze_Delay_Until --
595 -------------------------
597 procedure Analyze_Delay_Until
(N
: Node_Id
) is
598 E
: constant Node_Id
:= Expression
(N
);
602 Tasking_Used
:= True;
603 Check_Restriction
(No_Delay
, N
);
604 Check_Potentially_Blocking_Operation
(N
);
606 Typ
:= First_Subtype
(Etype
(E
));
608 if not Is_RTE
(Typ
, RO_CA_Time
) and then
609 not Is_RTE
(Typ
, RO_RT_Time
)
611 Error_Msg_N
("expect Time types for `DELAY UNTIL`", E
);
613 end Analyze_Delay_Until
;
615 ------------------------
616 -- Analyze_Entry_Body --
617 ------------------------
619 procedure Analyze_Entry_Body
(N
: Node_Id
) is
620 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
621 Decls
: constant List_Id
:= Declarations
(N
);
622 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
623 Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
624 P_Type
: constant Entity_Id
:= Current_Scope
;
625 Entry_Name
: Entity_Id
;
629 Tasking_Used
:= True;
631 -- Entry_Name is initialized to Any_Id. It should get reset to the
632 -- matching entry entity. An error is signalled if it is not reset
634 Entry_Name
:= Any_Id
;
638 if Present
(Entry_Index_Specification
(Formals
)) then
639 Set_Ekind
(Id
, E_Entry_Family
);
641 Set_Ekind
(Id
, E_Entry
);
644 Set_Scope
(Id
, Current_Scope
);
645 Set_Etype
(Id
, Standard_Void_Type
);
646 Set_Accept_Address
(Id
, New_Elmt_List
);
648 E
:= First_Entity
(P_Type
);
649 while Present
(E
) loop
650 if Chars
(E
) = Chars
(Id
)
651 and then (Ekind
(E
) = Ekind
(Id
))
652 and then Type_Conformant
(Id
, E
)
655 Set_Convention
(Id
, Convention
(E
));
656 Set_Corresponding_Body
(Parent
(Entry_Name
), Id
);
657 Check_Fully_Conformant
(Id
, E
, N
);
659 if Ekind
(Id
) = E_Entry_Family
then
660 if not Fully_Conformant_Discrete_Subtypes
(
661 Discrete_Subtype_Definition
(Parent
(E
)),
662 Discrete_Subtype_Definition
663 (Entry_Index_Specification
(Formals
)))
666 ("index not fully conformant with previous declaration",
667 Discrete_Subtype_Definition
668 (Entry_Index_Specification
(Formals
)));
671 -- The elaboration of the entry body does not recompute
672 -- the bounds of the index, which may have side effects.
673 -- Inherit the bounds from the entry declaration. This
674 -- is critical if the entry has a per-object constraint.
675 -- If a bound is given by a discriminant, it must be
676 -- reanalyzed in order to capture the discriminal of the
677 -- current entry, rather than that of the protected type.
680 Index_Spec
: constant Node_Id
:=
681 Entry_Index_Specification
(Formals
);
683 Def
: constant Node_Id
:=
685 (Discrete_Subtype_Definition
(Parent
(E
)));
690 (Discrete_Subtype_Definition
(Index_Spec
))) = N_Range
692 Set_Etype
(Def
, Empty
);
693 Set_Analyzed
(Def
, False);
695 -- Keep the original subtree to ensure tree is
696 -- properly formed (e.g. for ASIS use)
699 (Discrete_Subtype_Definition
(Index_Spec
), Def
);
701 Set_Analyzed
(Low_Bound
(Def
), False);
702 Set_Analyzed
(High_Bound
(Def
), False);
704 if Denotes_Discriminant
(Low_Bound
(Def
)) then
705 Set_Entity
(Low_Bound
(Def
), Empty
);
708 if Denotes_Discriminant
(High_Bound
(Def
)) then
709 Set_Entity
(High_Bound
(Def
), Empty
);
713 Make_Index
(Def
, Index_Spec
);
715 (Defining_Identifier
(Index_Spec
), Etype
(Def
));
727 if Entry_Name
= Any_Id
then
728 Error_Msg_N
("no entry declaration matches entry body", N
);
731 elsif Has_Completion
(Entry_Name
) then
732 Error_Msg_N
("duplicate entry body", N
);
736 Set_Has_Completion
(Entry_Name
);
737 Generate_Reference
(Entry_Name
, Id
, 'b', Set_Ref
=> False);
738 Style
.Check_Identifier
(Id
, Entry_Name
);
741 Exp_Ch9
.Expand_Entry_Barrier
(N
, Entry_Name
);
742 New_Scope
(Entry_Name
);
744 Exp_Ch9
.Expand_Entry_Body_Declarations
(N
);
745 Install_Declarations
(Entry_Name
);
746 Set_Actual_Subtypes
(N
, Current_Scope
);
748 -- The entity for the protected subprogram corresponding to the entry
749 -- has been created. We retain the name of this entity in the entry
750 -- body, for use when the corresponding subprogram body is created.
751 -- Note that entry bodies have no corresponding_spec, and there is no
752 -- easy link back in the tree between the entry body and the entity for
753 -- the entry itself, which is why we must propagate some attributes
754 -- explicitly from spec to body.
756 Set_Protected_Body_Subprogram
757 (Id
, Protected_Body_Subprogram
(Entry_Name
));
759 Set_Entry_Parameters_Type
760 (Id
, Entry_Parameters_Type
(Entry_Name
));
762 if Present
(Decls
) then
763 Analyze_Declarations
(Decls
);
766 if Present
(Stats
) then
770 -- Check for unreferenced variables etc. Before the Check_References
771 -- call, we transfer Never_Set_In_Source and Referenced flags from
772 -- parameters in the spec to the corresponding entities in the body,
773 -- since we want the warnings on the body entities. Note that we do
774 -- not have to transfer Referenced_As_LHS, since that flag can only
775 -- be set for simple variables.
777 -- At the same time, we set the flags on the spec entities to suppress
778 -- any warnings on the spec formals, since we also scan the spec.
779 -- Finally, we propagate the Entry_Component attribute to the body
780 -- formals, for use in the renaming declarations created later for the
781 -- formals (see exp_ch9.Add_Formal_Renamings).
788 E1
:= First_Entity
(Entry_Name
);
789 while Present
(E1
) loop
790 E2
:= First_Entity
(Id
);
791 while Present
(E2
) loop
792 exit when Chars
(E1
) = Chars
(E2
);
796 -- If no matching body entity, then we already had
797 -- a detected error of some kind, so just forget
798 -- about worrying about these warnings.
804 if Ekind
(E1
) = E_Out_Parameter
then
805 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
806 Set_Never_Set_In_Source
(E1
, False);
809 Set_Referenced
(E2
, Referenced
(E1
));
811 Set_Entry_Component
(E2
, Entry_Component
(E1
));
817 Check_References
(Id
);
820 -- We still need to check references for the spec, since objects
821 -- declared in the body are chained (in the First_Entity sense) to
822 -- the spec rather than the body in the case of entries.
824 Check_References
(Entry_Name
);
826 -- Process the end label, and terminate the scope
828 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Name
);
831 -- If this is an entry family, remove the loop created to provide
832 -- a scope for the entry index.
834 if Ekind
(Id
) = E_Entry_Family
835 and then Present
(Entry_Index_Specification
(Formals
))
840 end Analyze_Entry_Body
;
842 ------------------------------------
843 -- Analyze_Entry_Body_Formal_Part --
844 ------------------------------------
846 procedure Analyze_Entry_Body_Formal_Part
(N
: Node_Id
) is
847 Id
: constant Entity_Id
:= Defining_Identifier
(Parent
(N
));
848 Index
: constant Node_Id
:= Entry_Index_Specification
(N
);
849 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
852 Tasking_Used
:= True;
854 if Present
(Index
) then
858 if Present
(Formals
) then
859 Set_Scope
(Id
, Current_Scope
);
861 Process_Formals
(Formals
, Parent
(N
));
864 end Analyze_Entry_Body_Formal_Part
;
866 ------------------------------------
867 -- Analyze_Entry_Call_Alternative --
868 ------------------------------------
870 procedure Analyze_Entry_Call_Alternative
(N
: Node_Id
) is
871 Call
: constant Node_Id
:= Entry_Call_Statement
(N
);
874 Tasking_Used
:= True;
876 if Present
(Pragmas_Before
(N
)) then
877 Analyze_List
(Pragmas_Before
(N
));
880 if Nkind
(Call
) = N_Attribute_Reference
then
882 -- Possibly a stream attribute, but definitely illegal. Other
883 -- illegalitles, such as procedure calls, are diagnosed after
886 Error_Msg_N
("entry call alternative requires an entry call", Call
);
892 if Is_Non_Empty_List
(Statements
(N
)) then
893 Analyze_Statements
(Statements
(N
));
895 end Analyze_Entry_Call_Alternative
;
897 -------------------------------
898 -- Analyze_Entry_Declaration --
899 -------------------------------
901 procedure Analyze_Entry_Declaration
(N
: Node_Id
) is
902 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
903 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
904 D_Sdef
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
907 Generate_Definition
(Id
);
908 Tasking_Used
:= True;
911 Set_Ekind
(Id
, E_Entry
);
914 Set_Ekind
(Id
, E_Entry_Family
);
916 Make_Index
(D_Sdef
, N
, Id
);
919 Set_Etype
(Id
, Standard_Void_Type
);
920 Set_Convention
(Id
, Convention_Entry
);
921 Set_Accept_Address
(Id
, New_Elmt_List
);
923 if Present
(Formals
) then
924 Set_Scope
(Id
, Current_Scope
);
926 Process_Formals
(Formals
, N
);
927 Create_Extra_Formals
(Id
);
931 if Ekind
(Id
) = E_Entry
then
932 New_Overloaded_Entity
(Id
);
934 end Analyze_Entry_Declaration
;
936 ---------------------------------------
937 -- Analyze_Entry_Index_Specification --
938 ---------------------------------------
940 -- The defining_Identifier of the entry index specification is local
941 -- to the entry body, but must be available in the entry barrier,
942 -- which is evaluated outside of the entry body. The index is eventually
943 -- renamed as a run-time object, so is visibility is strictly a front-end
944 -- concern. In order to make it available to the barrier, we create
945 -- an additional scope, as for a loop, whose only declaration is the
946 -- index name. This loop is not attached to the tree and does not appear
947 -- as an entity local to the protected type, so its existence need only
948 -- be knwown to routines that process entry families.
950 procedure Analyze_Entry_Index_Specification
(N
: Node_Id
) is
951 Iden
: constant Node_Id
:= Defining_Identifier
(N
);
952 Def
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
953 Loop_Id
: constant Entity_Id
:=
954 Make_Defining_Identifier
(Sloc
(N
),
955 Chars
=> New_Internal_Name
('L'));
958 Tasking_Used
:= True;
961 -- There is no elaboration of the entry index specification. Therefore,
962 -- if the index is a range, it is not resolved and expanded, but the
963 -- bounds are inherited from the entry declaration, and reanalyzed.
964 -- See Analyze_Entry_Body.
966 if Nkind
(Def
) /= N_Range
then
970 Set_Ekind
(Loop_Id
, E_Loop
);
971 Set_Scope
(Loop_Id
, Current_Scope
);
974 Set_Ekind
(Iden
, E_Entry_Index_Parameter
);
975 Set_Etype
(Iden
, Etype
(Def
));
976 end Analyze_Entry_Index_Specification
;
978 ----------------------------
979 -- Analyze_Protected_Body --
980 ----------------------------
982 procedure Analyze_Protected_Body
(N
: Node_Id
) is
983 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
987 -- This is initially the entity of the protected object or protected
988 -- type involved, but is replaced by the protected type always in the
989 -- case of a single protected declaration, since this is the proper
993 -- This is the entity of the protected object or protected type
994 -- involved, and is the entity used for cross-reference purposes
995 -- (it differs from Spec_Id in the case of a single protected
996 -- object, since Spec_Id is set to the protected type in this case).
999 Tasking_Used
:= True;
1000 Set_Ekind
(Body_Id
, E_Protected_Body
);
1001 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
1003 if Present
(Spec_Id
)
1004 and then Ekind
(Spec_Id
) = E_Protected_Type
1008 elsif Present
(Spec_Id
)
1009 and then Ekind
(Etype
(Spec_Id
)) = E_Protected_Type
1010 and then not Comes_From_Source
(Etype
(Spec_Id
))
1015 Error_Msg_N
("missing specification for protected body", Body_Id
);
1020 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
1021 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1023 -- The declarations are always attached to the type
1025 if Ekind
(Spec_Id
) /= E_Protected_Type
then
1026 Spec_Id
:= Etype
(Spec_Id
);
1029 New_Scope
(Spec_Id
);
1030 Set_Corresponding_Spec
(N
, Spec_Id
);
1031 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
1032 Set_Has_Completion
(Spec_Id
);
1033 Install_Declarations
(Spec_Id
);
1035 Exp_Ch9
.Expand_Protected_Body_Declarations
(N
, Spec_Id
);
1037 Last_E
:= Last_Entity
(Spec_Id
);
1039 Analyze_Declarations
(Declarations
(N
));
1041 -- For visibility purposes, all entities in the body are private.
1042 -- Set First_Private_Entity accordingly, if there was no private
1043 -- part in the protected declaration.
1045 if No
(First_Private_Entity
(Spec_Id
)) then
1046 if Present
(Last_E
) then
1047 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
1049 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
1053 Check_Completion
(Body_Id
);
1054 Check_References
(Spec_Id
);
1055 Process_End_Label
(N
, 't', Ref_Id
);
1057 end Analyze_Protected_Body
;
1059 ----------------------------------
1060 -- Analyze_Protected_Definition --
1061 ----------------------------------
1063 procedure Analyze_Protected_Definition
(N
: Node_Id
) is
1068 Tasking_Used
:= True;
1069 Analyze_Declarations
(Visible_Declarations
(N
));
1071 if Present
(Private_Declarations
(N
))
1072 and then not Is_Empty_List
(Private_Declarations
(N
))
1074 L
:= Last_Entity
(Current_Scope
);
1075 Analyze_Declarations
(Private_Declarations
(N
));
1078 Set_First_Private_Entity
(Current_Scope
, Next_Entity
(L
));
1081 Set_First_Private_Entity
(Current_Scope
,
1082 First_Entity
(Current_Scope
));
1086 E
:= First_Entity
(Current_Scope
);
1087 while Present
(E
) loop
1088 if Ekind
(E
) = E_Function
1089 or else Ekind
(E
) = E_Procedure
1091 Set_Convention
(E
, Convention_Protected
);
1093 elsif Is_Task_Type
(Etype
(E
))
1094 or else Has_Task
(Etype
(E
))
1096 Set_Has_Task
(Current_Scope
);
1102 Check_Max_Entries
(N
, Max_Protected_Entries
);
1103 Process_End_Label
(N
, 'e', Current_Scope
);
1104 Check_Overriding_Indicator
(N
);
1105 end Analyze_Protected_Definition
;
1107 ----------------------------
1108 -- Analyze_Protected_Type --
1109 ----------------------------
1111 procedure Analyze_Protected_Type
(N
: Node_Id
) is
1114 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1116 Iface_Def
: Node_Id
;
1117 Iface_Typ
: Entity_Id
;
1120 if No_Run_Time_Mode
then
1121 Error_Msg_CRT
("protected type", N
);
1125 Tasking_Used
:= True;
1126 Check_Restriction
(No_Protected_Types
, N
);
1128 T
:= Find_Type_Name
(N
);
1130 if Ekind
(T
) = E_Incomplete_Type
then
1132 Set_Completion_Referenced
(T
);
1135 Set_Ekind
(T
, E_Protected_Type
);
1136 Set_Is_First_Subtype
(T
, True);
1137 Init_Size_Align
(T
);
1139 Set_Has_Delayed_Freeze
(T
, True);
1140 Set_Stored_Constraint
(T
, No_Elist
);
1143 -- Ada 2005 (AI-345)
1145 if Present
(Interface_List
(N
)) then
1146 Set_Is_Tagged_Type
(T
);
1148 Iface
:= First
(Interface_List
(N
));
1149 while Present
(Iface
) loop
1150 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
1151 Iface_Def
:= Type_Definition
(Parent
(Iface_Typ
));
1153 if not Is_Interface
(Iface_Typ
) then
1154 Error_Msg_NE
("(Ada 2005) & must be an interface",
1158 -- Ada 2005 (AI-251): "The declaration of a specific
1159 -- descendant of an interface type freezes the interface
1162 Freeze_Before
(N
, Etype
(Iface
));
1164 -- Ada 2005 (AI-345): Protected types can only implement
1165 -- limited, synchronized or protected interfaces.
1167 if Limited_Present
(Iface_Def
)
1168 or else Synchronized_Present
(Iface_Def
)
1169 or else Protected_Present
(Iface_Def
)
1173 elsif Task_Present
(Iface_Def
) then
1174 Error_Msg_N
("(Ada 2005) protected type cannot implement a "
1175 & "task interface", Iface
);
1178 Error_Msg_N
("(Ada 2005) protected type cannot implement a "
1179 & "non-limited interface", Iface
);
1187 if Present
(Discriminant_Specifications
(N
)) then
1188 if Has_Discriminants
(T
) then
1190 -- Install discriminants. Also, verify conformance of
1191 -- discriminants of previous and current view. ???
1193 Install_Declarations
(T
);
1195 Process_Discriminants
(N
);
1199 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
1201 Analyze
(Protected_Definition
(N
));
1203 -- Protected types with entries are controlled (because of the
1204 -- Protection component if nothing else), same for any protected type
1205 -- with interrupt handlers. Note that we need to analyze the protected
1206 -- definition to set Has_Entries and such.
1208 if (Abort_Allowed
or else Restriction_Active
(No_Entry_Queue
) = False
1209 or else Number_Entries
(T
) > 1)
1212 or else Has_Interrupt_Handler
(T
)
1213 or else Has_Attach_Handler
(T
))
1215 Set_Has_Controlled_Component
(T
, True);
1218 -- The Ekind of components is E_Void during analysis to detect
1219 -- illegal uses. Now it can be set correctly.
1221 E
:= First_Entity
(Current_Scope
);
1222 while Present
(E
) loop
1223 if Ekind
(E
) = E_Void
then
1224 Set_Ekind
(E
, E_Component
);
1225 Init_Component_Location
(E
);
1234 and then Is_Private_Type
(Def_Id
)
1235 and then Has_Discriminants
(Def_Id
)
1236 and then Expander_Active
1238 Exp_Ch9
.Expand_N_Protected_Type_Declaration
(N
);
1239 Process_Full_View
(N
, T
, Def_Id
);
1241 end Analyze_Protected_Type
;
1243 ---------------------
1244 -- Analyze_Requeue --
1245 ---------------------
1247 procedure Analyze_Requeue
(N
: Node_Id
) is
1248 Count
: Natural := 0;
1249 Entry_Name
: Node_Id
:= Name
(N
);
1250 Entry_Id
: Entity_Id
;
1253 Enclosing
: Entity_Id
;
1254 Target_Obj
: Node_Id
:= Empty
;
1255 Req_Scope
: Entity_Id
;
1256 Outer_Ent
: Entity_Id
;
1259 Check_Restriction
(No_Requeue_Statements
, N
);
1260 Check_Unreachable_Code
(N
);
1261 Tasking_Used
:= True;
1264 for J
in reverse 0 .. Scope_Stack
.Last
loop
1265 Enclosing
:= Scope_Stack
.Table
(J
).Entity
;
1266 exit when Is_Entry
(Enclosing
);
1268 if Ekind
(Enclosing
) /= E_Block
1269 and then Ekind
(Enclosing
) /= E_Loop
1271 Error_Msg_N
("requeue must appear within accept or entry body", N
);
1276 Analyze
(Entry_Name
);
1278 if Etype
(Entry_Name
) = Any_Type
then
1282 if Nkind
(Entry_Name
) = N_Selected_Component
then
1283 Target_Obj
:= Prefix
(Entry_Name
);
1284 Entry_Name
:= Selector_Name
(Entry_Name
);
1287 -- If an explicit target object is given then we have to check
1288 -- the restrictions of 9.5.4(6).
1290 if Present
(Target_Obj
) then
1292 -- Locate containing concurrent unit and determine enclosing entry
1293 -- body or outermost enclosing accept statement within the unit.
1296 for S
in reverse 0 .. Scope_Stack
.Last
loop
1297 Req_Scope
:= Scope_Stack
.Table
(S
).Entity
;
1299 exit when Ekind
(Req_Scope
) in Task_Kind
1300 or else Ekind
(Req_Scope
) in Protected_Kind
;
1302 if Is_Entry
(Req_Scope
) then
1303 Outer_Ent
:= Req_Scope
;
1307 pragma Assert
(Present
(Outer_Ent
));
1309 -- Check that the accessibility level of the target object
1310 -- is not greater or equal to the outermost enclosing accept
1311 -- statement (or entry body) unless it is a parameter of the
1312 -- innermost enclosing accept statement (or entry body).
1314 if Object_Access_Level
(Target_Obj
) >= Scope_Depth
(Outer_Ent
)
1316 (not Is_Entity_Name
(Target_Obj
)
1317 or else Ekind
(Entity
(Target_Obj
)) not in Formal_Kind
1318 or else Enclosing
/= Scope
(Entity
(Target_Obj
)))
1321 ("target object has invalid level for requeue", Target_Obj
);
1325 -- Overloaded case, find right interpretation
1327 if Is_Overloaded
(Entry_Name
) then
1330 Get_First_Interp
(Entry_Name
, I
, It
);
1331 while Present
(It
.Nam
) loop
1332 if No
(First_Formal
(It
.Nam
))
1333 or else Subtype_Conformant
(Enclosing
, It
.Nam
)
1335 -- Ada 2005 (AI-345): Since protected and task types have
1336 -- primitive entry wrappers, we only consider source entries.
1338 if Comes_From_Source
(It
.Nam
) then
1346 Get_Next_Interp
(I
, It
);
1350 Error_Msg_N
("no entry matches context", N
);
1353 elsif Count
> 1 then
1354 Error_Msg_N
("ambiguous entry name in requeue", N
);
1358 Set_Is_Overloaded
(Entry_Name
, False);
1359 Set_Entity
(Entry_Name
, Entry_Id
);
1362 -- Non-overloaded cases
1364 -- For the case of a reference to an element of an entry family,
1365 -- the Entry_Name is an indexed component.
1367 elsif Nkind
(Entry_Name
) = N_Indexed_Component
then
1369 -- Requeue to an entry out of the body
1371 if Nkind
(Prefix
(Entry_Name
)) = N_Selected_Component
then
1372 Entry_Id
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
1374 -- Requeue from within the body itself
1376 elsif Nkind
(Prefix
(Entry_Name
)) = N_Identifier
then
1377 Entry_Id
:= Entity
(Prefix
(Entry_Name
));
1380 Error_Msg_N
("invalid entry_name specified", N
);
1384 -- If we had a requeue of the form REQUEUE A (B), then the parser
1385 -- accepted it (because it could have been a requeue on an entry
1386 -- index. If A turns out not to be an entry family, then the analysis
1387 -- of A (B) turned it into a function call.
1389 elsif Nkind
(Entry_Name
) = N_Function_Call
then
1391 ("arguments not allowed in requeue statement",
1392 First
(Parameter_Associations
(Entry_Name
)));
1395 -- Normal case of no entry family, no argument
1398 Entry_Id
:= Entity
(Entry_Name
);
1401 -- Resolve entry, and check that it is subtype conformant with the
1402 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1404 if not Is_Entry
(Entry_Id
) then
1405 Error_Msg_N
("expect entry name in requeue statement", Name
(N
));
1406 elsif Ekind
(Entry_Id
) = E_Entry_Family
1407 and then Nkind
(Entry_Name
) /= N_Indexed_Component
1409 Error_Msg_N
("missing index for entry family component", Name
(N
));
1412 Resolve_Entry
(Name
(N
));
1413 Generate_Reference
(Entry_Id
, Entry_Name
);
1415 if Present
(First_Formal
(Entry_Id
)) then
1416 Check_Subtype_Conformant
(Enclosing
, Entry_Id
, Name
(N
));
1418 -- Processing for parameters accessed by the requeue
1424 Ent
:= First_Formal
(Enclosing
);
1425 while Present
(Ent
) loop
1427 -- For OUT or IN OUT parameter, the effect of the requeue
1428 -- is to assign the parameter a value on exit from the
1429 -- requeued body, so we can set it as source assigned.
1430 -- We also clear the Is_True_Constant indication. We do
1431 -- not need to clear Current_Value, since the effect of
1432 -- the requeue is to perform an unconditional goto so
1433 -- that any further references will not occur anyway.
1435 if Ekind
(Ent
) = E_Out_Parameter
1437 Ekind
(Ent
) = E_In_Out_Parameter
1439 Set_Never_Set_In_Source
(Ent
, False);
1440 Set_Is_True_Constant
(Ent
, False);
1443 -- For all parameters, the requeue acts as a reference,
1444 -- since the value of the parameter is passed to the
1445 -- new entry, so we want to suppress unreferenced warnings.
1447 Set_Referenced
(Ent
);
1453 end Analyze_Requeue
;
1455 ------------------------------
1456 -- Analyze_Selective_Accept --
1457 ------------------------------
1459 procedure Analyze_Selective_Accept
(N
: Node_Id
) is
1460 Alts
: constant List_Id
:= Select_Alternatives
(N
);
1463 Accept_Present
: Boolean := False;
1464 Terminate_Present
: Boolean := False;
1465 Delay_Present
: Boolean := False;
1466 Relative_Present
: Boolean := False;
1467 Alt_Count
: Uint
:= Uint_0
;
1470 Check_Restriction
(No_Select_Statements
, N
);
1471 Tasking_Used
:= True;
1473 -- Loop to analyze alternatives
1475 Alt
:= First
(Alts
);
1476 while Present
(Alt
) loop
1477 Alt_Count
:= Alt_Count
+ 1;
1480 if Nkind
(Alt
) = N_Delay_Alternative
then
1481 if Delay_Present
then
1483 if Relative_Present
/=
1484 (Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
)
1487 ("delay_until and delay_relative alternatives ", Alt
);
1489 ("\cannot appear in the same selective_wait", Alt
);
1493 Delay_Present
:= True;
1495 Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
;
1498 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
1499 if Terminate_Present
then
1500 Error_Msg_N
("only one terminate alternative allowed", N
);
1502 Terminate_Present
:= True;
1503 Check_Restriction
(No_Terminate_Alternatives
, N
);
1506 elsif Nkind
(Alt
) = N_Accept_Alternative
then
1507 Accept_Present
:= True;
1509 -- Check for duplicate accept
1513 Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
1514 EDN
: constant Node_Id
:= Entry_Direct_Name
(Stm
);
1518 if Nkind
(EDN
) = N_Identifier
1519 and then No
(Condition
(Alt
))
1520 and then Present
(Entity
(EDN
)) -- defend against junk
1521 and then Ekind
(Entity
(EDN
)) = E_Entry
1523 Ent
:= Entity
(EDN
);
1525 Alt1
:= First
(Alts
);
1526 while Alt1
/= Alt
loop
1527 if Nkind
(Alt1
) = N_Accept_Alternative
1528 and then No
(Condition
(Alt1
))
1531 Stm1
: constant Node_Id
:= Accept_Statement
(Alt1
);
1532 EDN1
: constant Node_Id
:= Entry_Direct_Name
(Stm1
);
1535 if Nkind
(EDN1
) = N_Identifier
then
1536 if Entity
(EDN1
) = Ent
then
1537 Error_Msg_Sloc
:= Sloc
(Stm1
);
1539 ("?accept duplicates one on line#", Stm
);
1555 Check_Restriction
(Max_Select_Alternatives
, N
, Alt_Count
);
1556 Check_Potentially_Blocking_Operation
(N
);
1558 if Terminate_Present
and Delay_Present
then
1559 Error_Msg_N
("at most one of terminate or delay alternative", N
);
1561 elsif not Accept_Present
then
1563 ("select must contain at least one accept alternative", N
);
1566 if Present
(Else_Statements
(N
)) then
1567 if Terminate_Present
or Delay_Present
then
1568 Error_Msg_N
("else part not allowed with other alternatives", N
);
1571 Analyze_Statements
(Else_Statements
(N
));
1573 end Analyze_Selective_Accept
;
1575 ------------------------------
1576 -- Analyze_Single_Protected --
1577 ------------------------------
1579 procedure Analyze_Single_Protected
(N
: Node_Id
) is
1580 Loc
: constant Source_Ptr
:= Sloc
(N
);
1581 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1585 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1588 Generate_Definition
(Id
);
1589 Tasking_Used
:= True;
1591 -- The node is rewritten as a protected type declaration,
1592 -- in exact analogy with what is done with single tasks.
1595 Make_Defining_Identifier
(Sloc
(Id
),
1596 New_External_Name
(Chars
(Id
), 'T'));
1599 Make_Protected_Type_Declaration
(Loc
,
1600 Defining_Identifier
=> T
,
1601 Protected_Definition
=> Relocate_Node
(Protected_Definition
(N
)),
1602 Interface_List
=> Interface_List
(N
));
1604 -- Ada 2005 (AI-399): Mark the object as aliased. Required to use
1605 -- the attribute 'access
1608 Make_Object_Declaration
(Loc
,
1609 Defining_Identifier
=> O_Name
,
1610 Aliased_Present
=> Ada_Version
>= Ada_05
,
1611 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1613 Rewrite
(N
, T_Decl
);
1614 Insert_After
(N
, O_Decl
);
1615 Mark_Rewrite_Insertion
(O_Decl
);
1617 -- Enter names of type and object before analysis, because the name
1618 -- of the object may be used in its own body.
1621 Set_Ekind
(T
, E_Protected_Type
);
1624 Enter_Name
(O_Name
);
1625 Set_Ekind
(O_Name
, E_Variable
);
1626 Set_Etype
(O_Name
, T
);
1628 -- Instead of calling Analyze on the new node, call directly
1629 -- the proper analysis procedure. Otherwise the node would be
1630 -- expanded twice, with disastrous result.
1632 Analyze_Protected_Type
(N
);
1633 end Analyze_Single_Protected
;
1635 -------------------------
1636 -- Analyze_Single_Task --
1637 -------------------------
1639 procedure Analyze_Single_Task
(N
: Node_Id
) is
1640 Loc
: constant Source_Ptr
:= Sloc
(N
);
1641 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1645 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1648 Generate_Definition
(Id
);
1649 Tasking_Used
:= True;
1651 -- The node is rewritten as a task type declaration, followed
1652 -- by an object declaration of that anonymous task type.
1655 Make_Defining_Identifier
(Sloc
(Id
),
1656 New_External_Name
(Chars
(Id
), Suffix
=> "TK"));
1659 Make_Task_Type_Declaration
(Loc
,
1660 Defining_Identifier
=> T
,
1661 Task_Definition
=> Relocate_Node
(Task_Definition
(N
)),
1662 Interface_List
=> Interface_List
(N
));
1664 -- Ada 2005 (AI-399): Mark the object as aliased. Required to use
1665 -- the attribute 'access
1668 Make_Object_Declaration
(Loc
,
1669 Defining_Identifier
=> O_Name
,
1670 Aliased_Present
=> Ada_Version
>= Ada_05
,
1671 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1673 Rewrite
(N
, T_Decl
);
1674 Insert_After
(N
, O_Decl
);
1675 Mark_Rewrite_Insertion
(O_Decl
);
1677 -- Enter names of type and object before analysis, because the name
1678 -- of the object may be used in its own body.
1681 Set_Ekind
(T
, E_Task_Type
);
1684 Enter_Name
(O_Name
);
1685 Set_Ekind
(O_Name
, E_Variable
);
1686 Set_Etype
(O_Name
, T
);
1688 -- Instead of calling Analyze on the new node, call directly
1689 -- the proper analysis procedure. Otherwise the node would be
1690 -- expanded twice, with disastrous result.
1692 Analyze_Task_Type
(N
);
1693 end Analyze_Single_Task
;
1695 -----------------------
1696 -- Analyze_Task_Body --
1697 -----------------------
1699 procedure Analyze_Task_Body
(N
: Node_Id
) is
1700 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1703 Spec_Id
: Entity_Id
;
1704 -- This is initially the entity of the task or task type involved,
1705 -- but is replaced by the task type always in the case of a single
1706 -- task declaration, since this is the proper scope to be used.
1709 -- This is the entity of the task or task type, and is the entity
1710 -- used for cross-reference purposes (it differs from Spec_Id in
1711 -- the case of a single task, since Spec_Id is set to the task type)
1714 Tasking_Used
:= True;
1715 Set_Ekind
(Body_Id
, E_Task_Body
);
1716 Set_Scope
(Body_Id
, Current_Scope
);
1717 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
1719 -- The spec is either a task type declaration, or a single task
1720 -- declaration for which we have created an anonymous type.
1722 if Present
(Spec_Id
)
1723 and then Ekind
(Spec_Id
) = E_Task_Type
1727 elsif Present
(Spec_Id
)
1728 and then Ekind
(Etype
(Spec_Id
)) = E_Task_Type
1729 and then not Comes_From_Source
(Etype
(Spec_Id
))
1734 Error_Msg_N
("missing specification for task body", Body_Id
);
1738 if Has_Completion
(Spec_Id
)
1739 and then Present
(Corresponding_Body
(Parent
(Spec_Id
)))
1741 if Nkind
(Parent
(Spec_Id
)) = N_Task_Type_Declaration
then
1742 Error_Msg_NE
("duplicate body for task type&", N
, Spec_Id
);
1745 Error_Msg_NE
("duplicate body for task&", N
, Spec_Id
);
1750 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
1751 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1753 -- Deal with case of body of single task (anonymous type was created)
1755 if Ekind
(Spec_Id
) = E_Variable
then
1756 Spec_Id
:= Etype
(Spec_Id
);
1759 New_Scope
(Spec_Id
);
1760 Set_Corresponding_Spec
(N
, Spec_Id
);
1761 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
1762 Set_Has_Completion
(Spec_Id
);
1763 Install_Declarations
(Spec_Id
);
1764 Last_E
:= Last_Entity
(Spec_Id
);
1766 Analyze_Declarations
(Declarations
(N
));
1768 -- For visibility purposes, all entities in the body are private.
1769 -- Set First_Private_Entity accordingly, if there was no private
1770 -- part in the protected declaration.
1772 if No
(First_Private_Entity
(Spec_Id
)) then
1773 if Present
(Last_E
) then
1774 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
1776 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
1780 Analyze
(Handled_Statement_Sequence
(N
));
1781 Check_Completion
(Body_Id
);
1782 Check_References
(Body_Id
);
1783 Check_References
(Spec_Id
);
1785 -- Check for entries with no corresponding accept
1791 Ent
:= First_Entity
(Spec_Id
);
1792 while Present
(Ent
) loop
1794 and then not Entry_Accepted
(Ent
)
1795 and then Comes_From_Source
(Ent
)
1797 Error_Msg_NE
("no accept for entry &?", N
, Ent
);
1804 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Ref_Id
);
1806 end Analyze_Task_Body
;
1808 -----------------------------
1809 -- Analyze_Task_Definition --
1810 -----------------------------
1812 procedure Analyze_Task_Definition
(N
: Node_Id
) is
1816 Tasking_Used
:= True;
1818 if Present
(Visible_Declarations
(N
)) then
1819 Analyze_Declarations
(Visible_Declarations
(N
));
1822 if Present
(Private_Declarations
(N
)) then
1823 L
:= Last_Entity
(Current_Scope
);
1824 Analyze_Declarations
(Private_Declarations
(N
));
1827 Set_First_Private_Entity
1828 (Current_Scope
, Next_Entity
(L
));
1830 Set_First_Private_Entity
1831 (Current_Scope
, First_Entity
(Current_Scope
));
1835 Check_Max_Entries
(N
, Max_Task_Entries
);
1836 Process_End_Label
(N
, 'e', Current_Scope
);
1837 Check_Overriding_Indicator
(N
);
1838 end Analyze_Task_Definition
;
1840 -----------------------
1841 -- Analyze_Task_Type --
1842 -----------------------
1844 procedure Analyze_Task_Type
(N
: Node_Id
) is
1846 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1848 Iface_Def
: Node_Id
;
1849 Iface_Typ
: Entity_Id
;
1852 Check_Restriction
(No_Tasking
, N
);
1853 Tasking_Used
:= True;
1854 T
:= Find_Type_Name
(N
);
1855 Generate_Definition
(T
);
1857 if Ekind
(T
) = E_Incomplete_Type
then
1859 Set_Completion_Referenced
(T
);
1862 Set_Ekind
(T
, E_Task_Type
);
1863 Set_Is_First_Subtype
(T
, True);
1864 Set_Has_Task
(T
, True);
1865 Init_Size_Align
(T
);
1867 Set_Has_Delayed_Freeze
(T
, True);
1868 Set_Stored_Constraint
(T
, No_Elist
);
1871 -- Ada 2005 (AI-345)
1873 if Present
(Interface_List
(N
)) then
1874 Set_Is_Tagged_Type
(T
);
1876 Iface
:= First
(Interface_List
(N
));
1877 while Present
(Iface
) loop
1878 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
1879 Iface_Def
:= Type_Definition
(Parent
(Iface_Typ
));
1881 if not Is_Interface
(Iface_Typ
) then
1882 Error_Msg_NE
("(Ada 2005) & must be an interface",
1886 -- Ada 2005 (AI-251): The declaration of a specific descendant
1887 -- of an interface type freezes the interface type (RM 13.14).
1889 Freeze_Before
(N
, Etype
(Iface
));
1891 -- Ada 2005 (AI-345): Task types can only implement limited,
1892 -- synchronized or task interfaces.
1894 if Limited_Present
(Iface_Def
)
1895 or else Synchronized_Present
(Iface_Def
)
1896 or else Task_Present
(Iface_Def
)
1900 elsif Protected_Present
(Iface_Def
) then
1901 Error_Msg_N
("(Ada 2005) task type cannot implement a " &
1902 "protected interface", Iface
);
1905 Error_Msg_N
("(Ada 2005) task type cannot implement a " &
1906 "non-limited interface", Iface
);
1914 if Present
(Discriminant_Specifications
(N
)) then
1915 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1916 Error_Msg_N
("(Ada 83) task discriminant not allowed!", N
);
1919 if Has_Discriminants
(T
) then
1921 -- Install discriminants. Also, verify conformance of
1922 -- discriminants of previous and current view. ???
1924 Install_Declarations
(T
);
1926 Process_Discriminants
(N
);
1930 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
1932 if Present
(Task_Definition
(N
)) then
1933 Analyze_Task_Definition
(Task_Definition
(N
));
1936 if not Is_Library_Level_Entity
(T
) then
1937 Check_Restriction
(No_Task_Hierarchy
, N
);
1943 and then Is_Private_Type
(Def_Id
)
1944 and then Has_Discriminants
(Def_Id
)
1945 and then Expander_Active
1947 Exp_Ch9
.Expand_N_Task_Type_Declaration
(N
);
1948 Process_Full_View
(N
, T
, Def_Id
);
1950 end Analyze_Task_Type
;
1952 -----------------------------------
1953 -- Analyze_Terminate_Alternative --
1954 -----------------------------------
1956 procedure Analyze_Terminate_Alternative
(N
: Node_Id
) is
1958 Tasking_Used
:= True;
1960 if Present
(Pragmas_Before
(N
)) then
1961 Analyze_List
(Pragmas_Before
(N
));
1964 if Present
(Condition
(N
)) then
1965 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
1967 end Analyze_Terminate_Alternative
;
1969 ------------------------------
1970 -- Analyze_Timed_Entry_Call --
1971 ------------------------------
1973 procedure Analyze_Timed_Entry_Call
(N
: Node_Id
) is
1975 Check_Restriction
(No_Select_Statements
, N
);
1976 Tasking_Used
:= True;
1977 Analyze
(Entry_Call_Alternative
(N
));
1978 Analyze
(Delay_Alternative
(N
));
1979 end Analyze_Timed_Entry_Call
;
1981 ------------------------------------
1982 -- Analyze_Triggering_Alternative --
1983 ------------------------------------
1985 procedure Analyze_Triggering_Alternative
(N
: Node_Id
) is
1986 Trigger
: constant Node_Id
:= Triggering_Statement
(N
);
1989 Tasking_Used
:= True;
1991 if Present
(Pragmas_Before
(N
)) then
1992 Analyze_List
(Pragmas_Before
(N
));
1997 if Comes_From_Source
(Trigger
)
1998 and then Nkind
(Trigger
) not in N_Delay_Statement
1999 and then Nkind
(Trigger
) /= N_Entry_Call_Statement
2001 if Ada_Version
< Ada_05
then
2003 ("triggering statement must be delay or entry call", Trigger
);
2005 -- Ada 2005 (AI-345): If a procedure_call_statement is used for a
2006 -- procedure_or_entry_call, the procedure_name or pro- cedure_prefix
2007 -- of the procedure_call_statement shall denote an entry renamed by a
2008 -- procedure, or (a view of) a primitive subprogram of a limited
2009 -- interface whose first parameter is a controlling parameter.
2011 elsif Nkind
(Trigger
) = N_Procedure_Call_Statement
2012 and then not Is_Renamed_Entry
(Entity
(Name
(Trigger
)))
2013 and then not Is_Controlling_Limited_Procedure
2014 (Entity
(Name
(Trigger
)))
2016 Error_Msg_N
("triggering statement must be delay, procedure " &
2017 "or entry call", Trigger
);
2021 if Is_Non_Empty_List
(Statements
(N
)) then
2022 Analyze_Statements
(Statements
(N
));
2024 end Analyze_Triggering_Alternative
;
2026 -----------------------
2027 -- Check_Max_Entries --
2028 -----------------------
2030 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
) is
2033 procedure Count
(L
: List_Id
);
2034 -- Count entries in given declaration list
2040 procedure Count
(L
: List_Id
) is
2049 while Present
(D
) loop
2050 if Nkind
(D
) = N_Entry_Declaration
then
2052 DSD
: constant Node_Id
:=
2053 Discrete_Subtype_Definition
(D
);
2056 -- If not an entry family, then just one entry
2059 Ecount
:= Ecount
+ 1;
2061 -- If entry family with static bounds, count entries
2063 elsif Is_OK_Static_Subtype
(Etype
(DSD
)) then
2065 Lo
: constant Uint
:=
2067 (Type_Low_Bound
(Etype
(DSD
)));
2068 Hi
: constant Uint
:=
2070 (Type_High_Bound
(Etype
(DSD
)));
2074 Ecount
:= Ecount
+ Hi
- Lo
+ 1;
2078 -- Entry family with non-static bounds
2081 -- If restriction is set, then this is an error
2083 if Restrictions
.Set
(R
) then
2085 ("static subtype required by Restriction pragma",
2088 -- Otherwise we record an unknown count restriction
2091 Check_Restriction
(R
, D
);
2101 -- Start of processing for Check_Max_Entries
2105 Count
(Visible_Declarations
(D
));
2106 Count
(Private_Declarations
(D
));
2109 Check_Restriction
(R
, D
, Ecount
);
2111 end Check_Max_Entries
;
2113 --------------------------------
2114 -- Check_Overriding_Indicator --
2115 --------------------------------
2117 procedure Check_Overriding_Indicator
(Def
: Node_Id
) is
2118 Aliased_Hom
: Entity_Id
;
2122 Ifaces
: constant List_Id
:= Interface_List
(Parent
(Def
));
2123 Overrides
: Boolean;
2125 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Def
);
2127 function Matches_Prefixed_View_Profile
2129 Entry_Params
: List_Id
;
2130 Proc_Params
: List_Id
) return Boolean;
2131 -- Ada 2005 (AI-397): Determine if an entry parameter profile matches
2132 -- the prefixed view profile of an abstract procedure. Also determine
2133 -- whether the abstract procedure belongs to an implemented interface.
2135 -----------------------------------
2136 -- Matches_Prefixed_View_Profile --
2137 -----------------------------------
2139 function Matches_Prefixed_View_Profile
2141 Entry_Params
: List_Id
;
2142 Proc_Params
: List_Id
) return Boolean
2144 Entry_Param
: Node_Id
;
2145 Proc_Param
: Node_Id
;
2146 Proc_Param_Typ
: Entity_Id
;
2148 function Includes_Interface
2150 Ifaces
: List_Id
) return Boolean;
2151 -- Determine if an interface is contained in a list of interfaces
2153 ------------------------
2154 -- Includes_Interface --
2155 ------------------------
2157 function Includes_Interface
2159 Ifaces
: List_Id
) return Boolean
2164 Ent
:= First
(Ifaces
);
2165 while Present
(Ent
) loop
2166 if Etype
(Ent
) = Iface
then
2174 end Includes_Interface
;
2176 -- Start of processing for Matches_Prefixed_View_Profile
2179 Proc_Param
:= First
(Proc_Params
);
2180 Proc_Param_Typ
:= Etype
(Parameter_Type
(Proc_Param
));
2182 -- The first parameter of the abstract procedure must be of an
2183 -- interface type. The task or protected type must also implement
2186 if not Is_Interface
(Proc_Param_Typ
)
2187 or else not Includes_Interface
(Proc_Param_Typ
, Ifaces
)
2192 Entry_Param
:= First
(Entry_Params
);
2193 Proc_Param
:= Next
(Proc_Param
);
2194 while Present
(Entry_Param
) and then Present
(Proc_Param
) loop
2196 -- The two parameters must be mode conformant and have the exact
2199 if Ekind
(Defining_Identifier
(Entry_Param
)) /=
2200 Ekind
(Defining_Identifier
(Proc_Param
))
2201 or else Etype
(Parameter_Type
(Entry_Param
)) /=
2202 Etype
(Parameter_Type
(Proc_Param
))
2211 -- One of the lists is longer than the other
2213 if Present
(Entry_Param
) or else Present
(Proc_Param
) then
2218 end Matches_Prefixed_View_Profile
;
2220 -- Start of processing for Check_Overriding_Indicator
2223 if Present
(Ifaces
) then
2224 Decl
:= First
(Vis_Decls
);
2225 while Present
(Decl
) loop
2227 -- Consider entries with either "overriding" or "not overriding"
2228 -- indicator present.
2230 if Nkind
(Decl
) = N_Entry_Declaration
2231 and then (Must_Override
(Decl
)
2233 Must_Not_Override
(Decl
))
2235 Def_Id
:= Defining_Identifier
(Decl
);
2239 Hom
:= Homonym
(Def_Id
);
2240 while Present
(Hom
) loop
2242 -- The current entry may override a procedure from an
2243 -- implemented interface.
2245 if Ekind
(Hom
) = E_Procedure
2246 and then (Is_Abstract
(Hom
)
2248 Null_Present
(Parent
(Hom
)))
2251 while Present
(Alias
(Aliased_Hom
)) loop
2252 Aliased_Hom
:= Alias
(Aliased_Hom
);
2255 if Matches_Prefixed_View_Profile
(Ifaces
,
2256 Parameter_Specifications
(Decl
),
2257 Parameter_Specifications
(Parent
(Aliased_Hom
)))
2264 Hom
:= Homonym
(Hom
);
2268 if Must_Not_Override
(Decl
) then
2269 Error_Msg_NE
("entry& is overriding", Def_Id
, Def_Id
);
2272 if Must_Override
(Decl
) then
2273 Error_Msg_NE
("entry& is not overriding", Def_Id
, Def_Id
);
2277 -- Consider subprograms with either "overriding" or "not
2278 -- overriding" indicator present.
2280 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2281 and then (Must_Override
(Specification
(Decl
))
2283 Must_Not_Override
(Specification
(Decl
)))
2285 Spec
:= Specification
(Decl
);
2286 Def_Id
:= Defining_Unit_Name
(Spec
);
2290 Hom
:= Homonym
(Def_Id
);
2291 while Present
(Hom
) loop
2295 if Ekind
(Def_Id
) = E_Function
2296 and then Ekind
(Hom
) = E_Function
2297 and then Is_Abstract
(Hom
)
2298 and then Matches_Prefixed_View_Profile
(Ifaces
,
2299 Parameter_Specifications
(Spec
),
2300 Parameter_Specifications
(Parent
(Hom
)))
2301 and then Etype
(Result_Definition
(Spec
)) =
2302 Etype
(Result_Definition
(Parent
(Hom
)))
2309 elsif Ekind
(Def_Id
) = E_Procedure
2310 and then Ekind
(Hom
) = E_Procedure
2311 and then (Is_Abstract
(Hom
)
2313 Null_Present
(Parent
(Hom
)))
2314 and then Matches_Prefixed_View_Profile
(Ifaces
,
2315 Parameter_Specifications
(Spec
),
2316 Parameter_Specifications
(Parent
(Hom
)))
2322 Hom
:= Homonym
(Hom
);
2326 if Must_Not_Override
(Spec
) then
2328 ("subprogram& is overriding", Def_Id
, Def_Id
);
2331 if Must_Override
(Spec
) then
2333 ("subprogram& is not overriding", Def_Id
, Def_Id
);
2341 -- The protected or task type is not implementing an interface,
2342 -- we need to check for the presence of "overriding" entries or
2343 -- subprograms and flag them as erroneous.
2346 Decl
:= First
(Vis_Decls
);
2347 while Present
(Decl
) loop
2348 if Nkind
(Decl
) = N_Entry_Declaration
2349 and then Must_Override
(Decl
)
2351 Def_Id
:= Defining_Identifier
(Decl
);
2352 Error_Msg_NE
("entry& is not overriding", Def_Id
, Def_Id
);
2354 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2355 and then Must_Override
(Specification
(Decl
))
2357 Def_Id
:= Defining_Identifier
(Specification
(Decl
));
2358 Error_Msg_NE
("subprogram& is not overriding", Def_Id
, Def_Id
);
2364 end Check_Overriding_Indicator
;
2366 --------------------------
2367 -- Find_Concurrent_Spec --
2368 --------------------------
2370 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
is
2371 Spec_Id
: Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2374 -- The type may have been given by an incomplete type declaration.
2375 -- Find full view now.
2377 if Present
(Spec_Id
) and then Ekind
(Spec_Id
) = E_Incomplete_Type
then
2378 Spec_Id
:= Full_View
(Spec_Id
);
2382 end Find_Concurrent_Spec
;
2384 --------------------------
2385 -- Install_Declarations --
2386 --------------------------
2388 procedure Install_Declarations
(Spec
: Entity_Id
) is
2393 E
:= First_Entity
(Spec
);
2394 while Present
(E
) loop
2395 Prev
:= Current_Entity
(E
);
2396 Set_Current_Entity
(E
);
2397 Set_Is_Immediately_Visible
(E
);
2398 Set_Homonym
(E
, Prev
);
2401 end Install_Declarations
;