1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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
;
32 with Elists
; use Elists
;
33 with Itypes
; use Itypes
;
34 with Lib
.Xref
; use Lib
.Xref
;
35 with Nlists
; use Nlists
;
36 with Nmake
; use Nmake
;
38 with Restrict
; use Restrict
;
39 with Rident
; use Rident
;
40 with Rtsfind
; use Rtsfind
;
42 with Sem_Ch3
; use Sem_Ch3
;
43 with Sem_Ch5
; use Sem_Ch5
;
44 with Sem_Ch6
; use Sem_Ch6
;
45 with Sem_Ch8
; use Sem_Ch8
;
46 with Sem_Eval
; use Sem_Eval
;
47 with Sem_Res
; use Sem_Res
;
48 with Sem_Type
; use Sem_Type
;
49 with Sem_Util
; use Sem_Util
;
50 with Sem_Warn
; use Sem_Warn
;
51 with Snames
; use Snames
;
52 with Stand
; use Stand
;
53 with Sinfo
; use Sinfo
;
55 with Tbuild
; use Tbuild
;
56 with Uintp
; use Uintp
;
58 package body Sem_Ch9
is
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
);
65 -- Given either a protected definition or a task definition in D, check
66 -- the corresponding restriction parameter identifier R, and if it is set,
67 -- count the entries (checking the static requirement), and compare with
70 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
;
71 -- Find entity in corresponding task or protected declaration. Use full
72 -- view if first declaration was for an incomplete type.
74 procedure Install_Declarations
(Spec
: Entity_Id
);
75 -- Utility to make visible in corresponding body the entities defined
76 -- in task, protected type declaration, or entry declaration.
78 -----------------------------
79 -- Analyze_Abort_Statement --
80 -----------------------------
82 procedure Analyze_Abort_Statement
(N
: Node_Id
) is
87 T_Name
:= First
(Names
(N
));
88 while Present
(T_Name
) loop
91 if not Is_Task_Type
(Etype
(T_Name
)) then
92 Error_Msg_N
("expect task name for ABORT", T_Name
);
101 Check_Restriction
(No_Abort_Statements
, N
);
102 Check_Potentially_Blocking_Operation
(N
);
103 end Analyze_Abort_Statement
;
105 --------------------------------
106 -- Analyze_Accept_Alternative --
107 --------------------------------
109 procedure Analyze_Accept_Alternative
(N
: Node_Id
) is
111 Tasking_Used
:= True;
113 if Present
(Pragmas_Before
(N
)) then
114 Analyze_List
(Pragmas_Before
(N
));
117 if Present
(Condition
(N
)) then
118 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
121 Analyze
(Accept_Statement
(N
));
123 if Is_Non_Empty_List
(Statements
(N
)) then
124 Analyze_Statements
(Statements
(N
));
126 end Analyze_Accept_Alternative
;
128 ------------------------------
129 -- Analyze_Accept_Statement --
130 ------------------------------
132 procedure Analyze_Accept_Statement
(N
: Node_Id
) is
133 Nam
: constant Entity_Id
:= Entry_Direct_Name
(N
);
134 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
135 Index
: constant Node_Id
:= Entry_Index
(N
);
136 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
137 Accept_Id
: Entity_Id
;
138 Entry_Nam
: Entity_Id
;
141 Task_Nam
: Entity_Id
;
143 -----------------------
144 -- Actual_Index_Type --
145 -----------------------
147 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
148 -- If the bounds of an entry family depend on task discriminants,
149 -- create a new index type where a discriminant is replaced by the
150 -- local variable that renames it in the task body.
152 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
153 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
154 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
155 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
158 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
159 -- If bound is discriminant reference, replace with corresponding
160 -- local variable of the same name.
162 -----------------------------
163 -- Actual_Discriminant_Ref --
164 -----------------------------
166 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
167 Typ
: constant Entity_Id
:= Etype
(Bound
);
171 if not Is_Entity_Name
(Bound
)
172 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
177 Ref
:= Make_Identifier
(Sloc
(N
), Chars
(Entity
(Bound
)));
182 end Actual_Discriminant_Ref
;
184 -- Start of processing for Actual_Index_Type
187 if not Has_Discriminants
(Task_Nam
)
188 or else (not Is_Entity_Name
(Lo
)
189 and then not Is_Entity_Name
(Hi
))
191 return Entry_Index_Type
(E
);
193 New_T
:= Create_Itype
(Ekind
(Typ
), N
);
194 Set_Etype
(New_T
, Base_Type
(Typ
));
195 Set_Size_Info
(New_T
, Typ
);
196 Set_RM_Size
(New_T
, RM_Size
(Typ
));
197 Set_Scalar_Range
(New_T
,
198 Make_Range
(Sloc
(N
),
199 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
200 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
204 end Actual_Index_Type
;
206 -- Start of processing for Analyze_Accept_Statement
209 Tasking_Used
:= True;
211 -- Entry name is initialized to Any_Id. It should get reset to the
212 -- matching entry entity. An error is signalled if it is not reset.
216 for J
in reverse 0 .. Scope_Stack
.Last
loop
217 Task_Nam
:= Scope_Stack
.Table
(J
).Entity
;
218 exit when Ekind
(Etype
(Task_Nam
)) = E_Task_Type
;
219 Kind
:= Ekind
(Task_Nam
);
221 if Kind
/= E_Block
and then Kind
/= E_Loop
222 and then not Is_Entry
(Task_Nam
)
224 Error_Msg_N
("enclosing body of accept must be a task", N
);
229 if Ekind
(Etype
(Task_Nam
)) /= E_Task_Type
then
230 Error_Msg_N
("invalid context for accept statement", N
);
234 -- In order to process the parameters, we create a defining
235 -- identifier that can be used as the name of the scope. The
236 -- name of the accept statement itself is not a defining identifier,
237 -- and we cannot use its name directly because the task may have
238 -- any number of accept statements for the same entry.
240 if Present
(Index
) then
241 Accept_Id
:= New_Internal_Entity
242 (E_Entry_Family
, Current_Scope
, Sloc
(N
), 'E');
244 Accept_Id
:= New_Internal_Entity
245 (E_Entry
, Current_Scope
, Sloc
(N
), 'E');
248 Set_Etype
(Accept_Id
, Standard_Void_Type
);
249 Set_Accept_Address
(Accept_Id
, New_Elmt_List
);
251 if Present
(Formals
) then
252 New_Scope
(Accept_Id
);
253 Process_Formals
(Formals
, N
);
254 Create_Extra_Formals
(Accept_Id
);
258 -- We set the default expressions processed flag because we don't
259 -- need default expression functions. This is really more like a
260 -- body entity than a spec entity anyway.
262 Set_Default_Expressions_Processed
(Accept_Id
);
264 E
:= First_Entity
(Etype
(Task_Nam
));
265 while Present
(E
) loop
266 if Chars
(E
) = Chars
(Nam
)
267 and then (Ekind
(E
) = Ekind
(Accept_Id
))
268 and then Type_Conformant
(Accept_Id
, E
)
277 if Entry_Nam
= Any_Id
then
278 Error_Msg_N
("no entry declaration matches accept statement", N
);
281 Set_Entity
(Nam
, Entry_Nam
);
282 Generate_Reference
(Entry_Nam
, Nam
, 'b', Set_Ref
=> False);
283 Style
.Check_Identifier
(Nam
, Entry_Nam
);
286 -- Verify that the entry is not hidden by a procedure declared in
287 -- the current block (pathological but possible).
289 if Current_Scope
/= Task_Nam
then
294 E1
:= First_Entity
(Current_Scope
);
296 while Present
(E1
) loop
298 if Ekind
(E1
) = E_Procedure
299 and then Chars
(E1
) = Chars
(Entry_Nam
)
300 and then Type_Conformant
(E1
, Entry_Nam
)
302 Error_Msg_N
("entry name is not visible", N
);
310 Set_Convention
(Accept_Id
, Convention
(Entry_Nam
));
311 Check_Fully_Conformant
(Accept_Id
, Entry_Nam
, N
);
313 for J
in reverse 0 .. Scope_Stack
.Last
loop
314 exit when Task_Nam
= Scope_Stack
.Table
(J
).Entity
;
316 if Entry_Nam
= Scope_Stack
.Table
(J
).Entity
then
317 Error_Msg_N
("duplicate accept statement for same entry", N
);
328 when N_Task_Body | N_Compilation_Unit
=>
330 when N_Asynchronous_Select
=>
331 Error_Msg_N
("accept statements are not allowed within" &
332 " an asynchronous select inner" &
333 " to the enclosing task body", N
);
341 if Ekind
(E
) = E_Entry_Family
then
343 Error_Msg_N
("missing entry index in accept for entry family", N
);
345 Analyze_And_Resolve
(Index
, Entry_Index_Type
(E
));
346 Apply_Range_Check
(Index
, Actual_Index_Type
(E
));
349 elsif Present
(Index
) then
350 Error_Msg_N
("invalid entry index in accept for simple entry", N
);
353 -- If label declarations present, analyze them. They are declared
354 -- in the enclosing task, but their enclosing scope is the entry itself,
355 -- so that goto's to the label are recognized as local to the accept.
357 if Present
(Declarations
(N
)) then
364 Decl
:= First
(Declarations
(N
));
366 while Present
(Decl
) loop
370 (Nkind
(Decl
) = N_Implicit_Label_Declaration
);
372 Id
:= Defining_Identifier
(Decl
);
373 Set_Enclosing_Scope
(Id
, Entry_Nam
);
379 -- If statements are present, they must be analyzed in the context
380 -- of the entry, so that references to formals are correctly resolved.
381 -- We also have to add the declarations that are required by the
382 -- expansion of the accept statement in this case if expansion active.
384 -- In the case of a select alternative of a selective accept,
385 -- the expander references the address declaration even if there
386 -- is no statement list.
387 -- We also need to create the renaming declarations for the local
388 -- variables that will replace references to the formals within
391 Exp_Ch9
.Expand_Accept_Declarations
(N
, Entry_Nam
);
393 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
394 -- fields on all entry formals (this loop ignores all other entities).
395 -- Reset Set_Referenced and Has_Pragma_Unreferenced as well, so that
396 -- we can post accurate warnings on each accept statement for the same
399 E
:= First_Entity
(Entry_Nam
);
400 while Present
(E
) loop
401 if Is_Formal
(E
) then
402 Set_Never_Set_In_Source
(E
, True);
403 Set_Is_True_Constant
(E
, False);
404 Set_Current_Value
(E
, Empty
);
405 Set_Referenced
(E
, False);
406 Set_Has_Pragma_Unreferenced
(E
, False);
412 -- Analyze statements if present
414 if Present
(Stats
) then
415 New_Scope
(Entry_Nam
);
416 Install_Declarations
(Entry_Nam
);
418 Set_Actual_Subtypes
(N
, Current_Scope
);
421 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Nam
);
425 -- Some warning checks
427 Check_Potentially_Blocking_Operation
(N
);
428 Check_References
(Entry_Nam
, N
);
429 Set_Entry_Accepted
(Entry_Nam
);
430 end Analyze_Accept_Statement
;
432 ---------------------------------
433 -- Analyze_Asynchronous_Select --
434 ---------------------------------
436 procedure Analyze_Asynchronous_Select
(N
: Node_Id
) is
438 Tasking_Used
:= True;
439 Check_Restriction
(Max_Asynchronous_Select_Nesting
, N
);
440 Check_Restriction
(No_Select_Statements
, N
);
442 -- Analyze the statements. We analyze statements in the abortable part
443 -- first, because this is the section that is executed first, and that
444 -- way our remembering of saved values and checks is accurate.
446 Analyze_Statements
(Statements
(Abortable_Part
(N
)));
447 Analyze
(Triggering_Alternative
(N
));
448 end Analyze_Asynchronous_Select
;
450 ------------------------------------
451 -- Analyze_Conditional_Entry_Call --
452 ------------------------------------
454 procedure Analyze_Conditional_Entry_Call
(N
: Node_Id
) is
456 Check_Restriction
(No_Select_Statements
, N
);
457 Tasking_Used
:= True;
458 Analyze
(Entry_Call_Alternative
(N
));
459 Analyze_Statements
(Else_Statements
(N
));
460 end Analyze_Conditional_Entry_Call
;
462 --------------------------------
463 -- Analyze_Delay_Alternative --
464 --------------------------------
466 procedure Analyze_Delay_Alternative
(N
: Node_Id
) is
470 Tasking_Used
:= True;
471 Check_Restriction
(No_Delay
, N
);
473 if Present
(Pragmas_Before
(N
)) then
474 Analyze_List
(Pragmas_Before
(N
));
477 if Nkind
(Parent
(N
)) = N_Selective_Accept
478 or else Nkind
(Parent
(N
)) = N_Timed_Entry_Call
480 Expr
:= Expression
(Delay_Statement
(N
));
482 -- defer full analysis until the statement is expanded, to insure
483 -- that generated code does not move past the guard. The delay
484 -- expression is only evaluated if the guard is open.
486 if Nkind
(Delay_Statement
(N
)) = N_Delay_Relative_Statement
then
487 Pre_Analyze_And_Resolve
(Expr
, Standard_Duration
);
490 Pre_Analyze_And_Resolve
(Expr
);
493 if Nkind
(Delay_Statement
(N
)) = N_Delay_Until_Statement
and then
494 not Is_RTE
(Base_Type
(Etype
(Expr
)), RO_CA_Time
) and then
495 not Is_RTE
(Base_Type
(Etype
(Expr
)), RO_RT_Time
)
497 Error_Msg_N
("expect Time types for `DELAY UNTIL`", Expr
);
500 Check_Restriction
(No_Fixed_Point
, Expr
);
502 Analyze
(Delay_Statement
(N
));
505 if Present
(Condition
(N
)) then
506 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
509 if Is_Non_Empty_List
(Statements
(N
)) then
510 Analyze_Statements
(Statements
(N
));
512 end Analyze_Delay_Alternative
;
514 ----------------------------
515 -- Analyze_Delay_Relative --
516 ----------------------------
518 procedure Analyze_Delay_Relative
(N
: Node_Id
) is
519 E
: constant Node_Id
:= Expression
(N
);
522 Check_Restriction
(No_Relative_Delay
, N
);
523 Tasking_Used
:= True;
524 Check_Restriction
(No_Delay
, N
);
525 Check_Potentially_Blocking_Operation
(N
);
526 Analyze_And_Resolve
(E
, Standard_Duration
);
527 Check_Restriction
(No_Fixed_Point
, E
);
528 end Analyze_Delay_Relative
;
530 -------------------------
531 -- Analyze_Delay_Until --
532 -------------------------
534 procedure Analyze_Delay_Until
(N
: Node_Id
) is
535 E
: constant Node_Id
:= Expression
(N
);
538 Tasking_Used
:= True;
539 Check_Restriction
(No_Delay
, N
);
540 Check_Potentially_Blocking_Operation
(N
);
543 if not Is_RTE
(Base_Type
(Etype
(E
)), RO_CA_Time
) and then
544 not Is_RTE
(Base_Type
(Etype
(E
)), RO_RT_Time
)
546 Error_Msg_N
("expect Time types for `DELAY UNTIL`", E
);
548 end Analyze_Delay_Until
;
550 ------------------------
551 -- Analyze_Entry_Body --
552 ------------------------
554 procedure Analyze_Entry_Body
(N
: Node_Id
) is
555 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
556 Decls
: constant List_Id
:= Declarations
(N
);
557 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
558 Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
559 P_Type
: constant Entity_Id
:= Current_Scope
;
560 Entry_Name
: Entity_Id
;
564 Tasking_Used
:= True;
566 -- Entry_Name is initialized to Any_Id. It should get reset to the
567 -- matching entry entity. An error is signalled if it is not reset
569 Entry_Name
:= Any_Id
;
573 if Present
(Entry_Index_Specification
(Formals
)) then
574 Set_Ekind
(Id
, E_Entry_Family
);
576 Set_Ekind
(Id
, E_Entry
);
579 Set_Scope
(Id
, Current_Scope
);
580 Set_Etype
(Id
, Standard_Void_Type
);
581 Set_Accept_Address
(Id
, New_Elmt_List
);
583 E
:= First_Entity
(P_Type
);
584 while Present
(E
) loop
585 if Chars
(E
) = Chars
(Id
)
586 and then (Ekind
(E
) = Ekind
(Id
))
587 and then Type_Conformant
(Id
, E
)
590 Set_Convention
(Id
, Convention
(E
));
591 Set_Corresponding_Body
(Parent
(Entry_Name
), Id
);
592 Check_Fully_Conformant
(Id
, E
, N
);
594 if Ekind
(Id
) = E_Entry_Family
then
595 if not Fully_Conformant_Discrete_Subtypes
(
596 Discrete_Subtype_Definition
(Parent
(E
)),
597 Discrete_Subtype_Definition
598 (Entry_Index_Specification
(Formals
)))
601 ("index not fully conformant with previous declaration",
602 Discrete_Subtype_Definition
603 (Entry_Index_Specification
(Formals
)));
606 -- The elaboration of the entry body does not recompute
607 -- the bounds of the index, which may have side effects.
608 -- Inherit the bounds from the entry declaration. This
609 -- is critical if the entry has a per-object constraint.
610 -- If a bound is given by a discriminant, it must be
611 -- reanalyzed in order to capture the discriminal of the
612 -- current entry, rather than that of the protected type.
615 Index_Spec
: constant Node_Id
:=
616 Entry_Index_Specification
(Formals
);
618 Def
: constant Node_Id
:=
620 (Discrete_Subtype_Definition
(Parent
(E
)));
625 (Discrete_Subtype_Definition
(Index_Spec
))) = N_Range
627 Set_Etype
(Def
, Empty
);
628 Set_Analyzed
(Def
, False);
629 Set_Discrete_Subtype_Definition
(Index_Spec
, Def
);
630 Set_Analyzed
(Low_Bound
(Def
), False);
631 Set_Analyzed
(High_Bound
(Def
), False);
633 if Denotes_Discriminant
(Low_Bound
(Def
)) then
634 Set_Entity
(Low_Bound
(Def
), Empty
);
637 if Denotes_Discriminant
(High_Bound
(Def
)) then
638 Set_Entity
(High_Bound
(Def
), Empty
);
642 Make_Index
(Def
, Index_Spec
);
644 (Defining_Identifier
(Index_Spec
), Etype
(Def
));
656 if Entry_Name
= Any_Id
then
657 Error_Msg_N
("no entry declaration matches entry body", N
);
660 elsif Has_Completion
(Entry_Name
) then
661 Error_Msg_N
("duplicate entry body", N
);
665 Set_Has_Completion
(Entry_Name
);
666 Generate_Reference
(Entry_Name
, Id
, 'b', Set_Ref
=> False);
667 Style
.Check_Identifier
(Id
, Entry_Name
);
670 Exp_Ch9
.Expand_Entry_Barrier
(N
, Entry_Name
);
671 New_Scope
(Entry_Name
);
673 Exp_Ch9
.Expand_Entry_Body_Declarations
(N
);
674 Install_Declarations
(Entry_Name
);
675 Set_Actual_Subtypes
(N
, Current_Scope
);
677 -- The entity for the protected subprogram corresponding to the entry
678 -- has been created. We retain the name of this entity in the entry
679 -- body, for use when the corresponding subprogram body is created.
680 -- Note that entry bodies have to corresponding_spec, and there is no
681 -- easy link back in the tree between the entry body and the entity for
684 Set_Protected_Body_Subprogram
(Id
,
685 Protected_Body_Subprogram
(Entry_Name
));
687 if Present
(Decls
) then
688 Analyze_Declarations
(Decls
);
691 if Present
(Stats
) then
695 -- Check for unreferenced variables etc. Before the Check_References
696 -- call, we transfer Never_Set_In_Source and Referenced flags from
697 -- parameters in the spec to the corresponding entities in the body,
698 -- since we want the warnings on the body entities. Note that we do
699 -- not have to transfer Referenced_As_LHS, since that flag can only
700 -- be set for simple variables.
702 -- At the same time, we set the flags on the spec entities to suppress
703 -- any warnings on the spec formals, since we also scan the spec.
710 E1
:= First_Entity
(Entry_Name
);
711 while Present
(E1
) loop
712 E2
:= First_Entity
(Id
);
713 while Present
(E2
) loop
714 exit when Chars
(E1
) = Chars
(E2
);
718 -- If no matching body entity, then we already had
719 -- a detected error of some kind, so just forget
720 -- about worrying about these warnings.
726 if Ekind
(E1
) = E_Out_Parameter
then
727 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
728 Set_Never_Set_In_Source
(E1
, False);
731 Set_Referenced
(E2
, Referenced
(E1
));
738 Check_References
(Id
);
741 -- We still need to check references for the spec, since objects
742 -- declared in the body are chained (in the First_Entity sense) to
743 -- the spec rather than the body in the case of entries.
745 Check_References
(Entry_Name
);
747 -- Process the end label, and terminate the scope
749 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Name
);
752 -- If this is an entry family, remove the loop created to provide
753 -- a scope for the entry index.
755 if Ekind
(Id
) = E_Entry_Family
756 and then Present
(Entry_Index_Specification
(Formals
))
761 end Analyze_Entry_Body
;
763 ------------------------------------
764 -- Analyze_Entry_Body_Formal_Part --
765 ------------------------------------
767 procedure Analyze_Entry_Body_Formal_Part
(N
: Node_Id
) is
768 Id
: constant Entity_Id
:= Defining_Identifier
(Parent
(N
));
769 Index
: constant Node_Id
:= Entry_Index_Specification
(N
);
770 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
773 Tasking_Used
:= True;
775 if Present
(Index
) then
779 if Present
(Formals
) then
780 Set_Scope
(Id
, Current_Scope
);
782 Process_Formals
(Formals
, Parent
(N
));
785 end Analyze_Entry_Body_Formal_Part
;
787 ------------------------------------
788 -- Analyze_Entry_Call_Alternative --
789 ------------------------------------
791 procedure Analyze_Entry_Call_Alternative
(N
: Node_Id
) is
792 Call
: constant Node_Id
:= Entry_Call_Statement
(N
);
795 Tasking_Used
:= True;
797 if Present
(Pragmas_Before
(N
)) then
798 Analyze_List
(Pragmas_Before
(N
));
801 if Nkind
(Call
) = N_Attribute_Reference
then
803 -- Possibly a stream attribute, but definitely illegal. Other
804 -- illegalitles, such as procedure calls, are diagnosed after
807 Error_Msg_N
("entry call alternative requires an entry call", Call
);
813 if Is_Non_Empty_List
(Statements
(N
)) then
814 Analyze_Statements
(Statements
(N
));
816 end Analyze_Entry_Call_Alternative
;
818 -------------------------------
819 -- Analyze_Entry_Declaration --
820 -------------------------------
822 procedure Analyze_Entry_Declaration
(N
: Node_Id
) is
823 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
824 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
825 D_Sdef
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
828 Generate_Definition
(Id
);
829 Tasking_Used
:= True;
832 Set_Ekind
(Id
, E_Entry
);
835 Set_Ekind
(Id
, E_Entry_Family
);
837 Make_Index
(D_Sdef
, N
, Id
);
840 Set_Etype
(Id
, Standard_Void_Type
);
841 Set_Convention
(Id
, Convention_Entry
);
842 Set_Accept_Address
(Id
, New_Elmt_List
);
844 if Present
(Formals
) then
845 Set_Scope
(Id
, Current_Scope
);
847 Process_Formals
(Formals
, N
);
848 Create_Extra_Formals
(Id
);
852 if Ekind
(Id
) = E_Entry
then
853 New_Overloaded_Entity
(Id
);
855 end Analyze_Entry_Declaration
;
857 ---------------------------------------
858 -- Analyze_Entry_Index_Specification --
859 ---------------------------------------
861 -- The defining_Identifier of the entry index specification is local
862 -- to the entry body, but must be available in the entry barrier,
863 -- which is evaluated outside of the entry body. The index is eventually
864 -- renamed as a run-time object, so is visibility is strictly a front-end
865 -- concern. In order to make it available to the barrier, we create
866 -- an additional scope, as for a loop, whose only declaration is the
867 -- index name. This loop is not attached to the tree and does not appear
868 -- as an entity local to the protected type, so its existence need only
869 -- be knwown to routines that process entry families.
871 procedure Analyze_Entry_Index_Specification
(N
: Node_Id
) is
872 Iden
: constant Node_Id
:= Defining_Identifier
(N
);
873 Def
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
874 Loop_Id
: constant Entity_Id
:=
875 Make_Defining_Identifier
(Sloc
(N
),
876 Chars
=> New_Internal_Name
('L'));
879 Tasking_Used
:= True;
882 -- There is no elaboration of the entry index specification. Therefore,
883 -- if the index is a range, it is not resolved and expanded, but the
884 -- bounds are inherited from the entry declaration, and reanalyzed.
885 -- See Analyze_Entry_Body.
887 if Nkind
(Def
) /= N_Range
then
891 Set_Ekind
(Loop_Id
, E_Loop
);
892 Set_Scope
(Loop_Id
, Current_Scope
);
895 Set_Ekind
(Iden
, E_Entry_Index_Parameter
);
896 Set_Etype
(Iden
, Etype
(Def
));
897 end Analyze_Entry_Index_Specification
;
899 ----------------------------
900 -- Analyze_Protected_Body --
901 ----------------------------
903 procedure Analyze_Protected_Body
(N
: Node_Id
) is
904 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
908 -- This is initially the entity of the protected object or protected
909 -- type involved, but is replaced by the protected type always in the
910 -- case of a single protected declaration, since this is the proper
914 -- This is the entity of the protected object or protected type
915 -- involved, and is the entity used for cross-reference purposes
916 -- (it differs from Spec_Id in the case of a single protected
917 -- object, since Spec_Id is set to the protected type in this case).
920 Tasking_Used
:= True;
921 Set_Ekind
(Body_Id
, E_Protected_Body
);
922 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
925 and then Ekind
(Spec_Id
) = E_Protected_Type
929 elsif Present
(Spec_Id
)
930 and then Ekind
(Etype
(Spec_Id
)) = E_Protected_Type
931 and then not Comes_From_Source
(Etype
(Spec_Id
))
936 Error_Msg_N
("missing specification for protected body", Body_Id
);
941 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
942 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
944 -- The declarations are always attached to the type
946 if Ekind
(Spec_Id
) /= E_Protected_Type
then
947 Spec_Id
:= Etype
(Spec_Id
);
951 Set_Corresponding_Spec
(N
, Spec_Id
);
952 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
953 Set_Has_Completion
(Spec_Id
);
954 Install_Declarations
(Spec_Id
);
956 Exp_Ch9
.Expand_Protected_Body_Declarations
(N
, Spec_Id
);
958 Last_E
:= Last_Entity
(Spec_Id
);
960 Analyze_Declarations
(Declarations
(N
));
962 -- For visibility purposes, all entities in the body are private.
963 -- Set First_Private_Entity accordingly, if there was no private
964 -- part in the protected declaration.
966 if No
(First_Private_Entity
(Spec_Id
)) then
967 if Present
(Last_E
) then
968 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
970 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
974 Check_Completion
(Body_Id
);
975 Check_References
(Spec_Id
);
976 Process_End_Label
(N
, 't', Ref_Id
);
978 end Analyze_Protected_Body
;
980 ----------------------------------
981 -- Analyze_Protected_Definition --
982 ----------------------------------
984 procedure Analyze_Protected_Definition
(N
: Node_Id
) is
989 Tasking_Used
:= True;
990 Analyze_Declarations
(Visible_Declarations
(N
));
992 if Present
(Private_Declarations
(N
))
993 and then not Is_Empty_List
(Private_Declarations
(N
))
995 L
:= Last_Entity
(Current_Scope
);
996 Analyze_Declarations
(Private_Declarations
(N
));
999 Set_First_Private_Entity
(Current_Scope
, Next_Entity
(L
));
1002 Set_First_Private_Entity
(Current_Scope
,
1003 First_Entity
(Current_Scope
));
1007 E
:= First_Entity
(Current_Scope
);
1009 while Present
(E
) loop
1011 if Ekind
(E
) = E_Function
1012 or else Ekind
(E
) = E_Procedure
1014 Set_Convention
(E
, Convention_Protected
);
1016 elsif Is_Task_Type
(Etype
(E
))
1017 or else Has_Task
(Etype
(E
))
1019 Set_Has_Task
(Current_Scope
);
1025 Check_Max_Entries
(N
, Max_Protected_Entries
);
1026 Process_End_Label
(N
, 'e', Current_Scope
);
1027 end Analyze_Protected_Definition
;
1029 ----------------------------
1030 -- Analyze_Protected_Type --
1031 ----------------------------
1033 procedure Analyze_Protected_Type
(N
: Node_Id
) is
1036 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1039 if No_Run_Time_Mode
then
1040 Error_Msg_CRT
("protected type", N
);
1044 Tasking_Used
:= True;
1045 Check_Restriction
(No_Protected_Types
, N
);
1047 T
:= Find_Type_Name
(N
);
1049 if Ekind
(T
) = E_Incomplete_Type
then
1051 Set_Completion_Referenced
(T
);
1054 Set_Ekind
(T
, E_Protected_Type
);
1055 Init_Size_Align
(T
);
1057 Set_Is_First_Subtype
(T
, True);
1058 Set_Has_Delayed_Freeze
(T
, True);
1059 Set_Stored_Constraint
(T
, No_Elist
);
1062 if Present
(Discriminant_Specifications
(N
)) then
1063 if Has_Discriminants
(T
) then
1065 -- Install discriminants. Also, verify conformance of
1066 -- discriminants of previous and current view. ???
1068 Install_Declarations
(T
);
1070 Process_Discriminants
(N
);
1074 Analyze
(Protected_Definition
(N
));
1076 -- Protected types with entries are controlled (because of the
1077 -- Protection component if nothing else), same for any protected type
1078 -- with interrupt handlers. Note that we need to analyze the protected
1079 -- definition to set Has_Entries and such.
1081 if (Abort_Allowed
or else Restriction_Active
(No_Entry_Queue
) = False
1082 or else Number_Entries
(T
) > 1)
1085 or else Has_Interrupt_Handler
(T
)
1086 or else Has_Attach_Handler
(T
))
1088 Set_Has_Controlled_Component
(T
, True);
1091 -- The Ekind of components is E_Void during analysis to detect
1092 -- illegal uses. Now it can be set correctly.
1094 E
:= First_Entity
(Current_Scope
);
1096 while Present
(E
) loop
1097 if Ekind
(E
) = E_Void
then
1098 Set_Ekind
(E
, E_Component
);
1099 Init_Component_Location
(E
);
1108 and then Is_Private_Type
(Def_Id
)
1109 and then Has_Discriminants
(Def_Id
)
1110 and then Expander_Active
1112 Exp_Ch9
.Expand_N_Protected_Type_Declaration
(N
);
1113 Process_Full_View
(N
, T
, Def_Id
);
1115 end Analyze_Protected_Type
;
1117 ---------------------
1118 -- Analyze_Requeue --
1119 ---------------------
1121 procedure Analyze_Requeue
(N
: Node_Id
) is
1122 Entry_Name
: Node_Id
:= Name
(N
);
1123 Entry_Id
: Entity_Id
;
1127 Enclosing
: Entity_Id
;
1128 Target_Obj
: Node_Id
:= Empty
;
1129 Req_Scope
: Entity_Id
;
1130 Outer_Ent
: Entity_Id
;
1133 Check_Restriction
(No_Requeue_Statements
, N
);
1134 Check_Unreachable_Code
(N
);
1135 Tasking_Used
:= True;
1138 for J
in reverse 0 .. Scope_Stack
.Last
loop
1139 Enclosing
:= Scope_Stack
.Table
(J
).Entity
;
1140 exit when Is_Entry
(Enclosing
);
1142 if Ekind
(Enclosing
) /= E_Block
1143 and then Ekind
(Enclosing
) /= E_Loop
1145 Error_Msg_N
("requeue must appear within accept or entry body", N
);
1150 Analyze
(Entry_Name
);
1152 if Etype
(Entry_Name
) = Any_Type
then
1156 if Nkind
(Entry_Name
) = N_Selected_Component
then
1157 Target_Obj
:= Prefix
(Entry_Name
);
1158 Entry_Name
:= Selector_Name
(Entry_Name
);
1161 -- If an explicit target object is given then we have to check
1162 -- the restrictions of 9.5.4(6).
1164 if Present
(Target_Obj
) then
1166 -- Locate containing concurrent unit and determine enclosing entry
1167 -- body or outermost enclosing accept statement within the unit.
1170 for S
in reverse 0 .. Scope_Stack
.Last
loop
1171 Req_Scope
:= Scope_Stack
.Table
(S
).Entity
;
1173 exit when Ekind
(Req_Scope
) in Task_Kind
1174 or else Ekind
(Req_Scope
) in Protected_Kind
;
1176 if Is_Entry
(Req_Scope
) then
1177 Outer_Ent
:= Req_Scope
;
1181 pragma Assert
(Present
(Outer_Ent
));
1183 -- Check that the accessibility level of the target object
1184 -- is not greater or equal to the outermost enclosing accept
1185 -- statement (or entry body) unless it is a parameter of the
1186 -- innermost enclosing accept statement (or entry body).
1188 if Object_Access_Level
(Target_Obj
) >= Scope_Depth
(Outer_Ent
)
1190 (not Is_Entity_Name
(Target_Obj
)
1191 or else Ekind
(Entity
(Target_Obj
)) not in Formal_Kind
1192 or else Enclosing
/= Scope
(Entity
(Target_Obj
)))
1195 ("target object has invalid level for requeue", Target_Obj
);
1199 -- Overloaded case, find right interpretation
1201 if Is_Overloaded
(Entry_Name
) then
1202 Get_First_Interp
(Entry_Name
, I
, It
);
1206 while Present
(It
.Nam
) loop
1207 if No
(First_Formal
(It
.Nam
))
1208 or else Subtype_Conformant
(Enclosing
, It
.Nam
)
1214 Error_Msg_N
("ambiguous entry name in requeue", N
);
1219 Get_Next_Interp
(I
, It
);
1223 Error_Msg_N
("no entry matches context", N
);
1226 Set_Entity
(Entry_Name
, Entry_Id
);
1229 -- Non-overloaded cases
1231 -- For the case of a reference to an element of an entry family,
1232 -- the Entry_Name is an indexed component.
1234 elsif Nkind
(Entry_Name
) = N_Indexed_Component
then
1236 -- Requeue to an entry out of the body
1238 if Nkind
(Prefix
(Entry_Name
)) = N_Selected_Component
then
1239 Entry_Id
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
1241 -- Requeue from within the body itself
1243 elsif Nkind
(Prefix
(Entry_Name
)) = N_Identifier
then
1244 Entry_Id
:= Entity
(Prefix
(Entry_Name
));
1247 Error_Msg_N
("invalid entry_name specified", N
);
1251 -- If we had a requeue of the form REQUEUE A (B), then the parser
1252 -- accepted it (because it could have been a requeue on an entry
1253 -- index. If A turns out not to be an entry family, then the analysis
1254 -- of A (B) turned it into a function call.
1256 elsif Nkind
(Entry_Name
) = N_Function_Call
then
1258 ("arguments not allowed in requeue statement",
1259 First
(Parameter_Associations
(Entry_Name
)));
1262 -- Normal case of no entry family, no argument
1265 Entry_Id
:= Entity
(Entry_Name
);
1268 -- Resolve entry, and check that it is subtype conformant with the
1269 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1271 if not Is_Entry
(Entry_Id
) then
1272 Error_Msg_N
("expect entry name in requeue statement", Name
(N
));
1273 elsif Ekind
(Entry_Id
) = E_Entry_Family
1274 and then Nkind
(Entry_Name
) /= N_Indexed_Component
1276 Error_Msg_N
("missing index for entry family component", Name
(N
));
1279 Resolve_Entry
(Name
(N
));
1280 Generate_Reference
(Entry_Id
, Entry_Name
);
1282 if Present
(First_Formal
(Entry_Id
)) then
1283 Check_Subtype_Conformant
(Enclosing
, Entry_Id
, Name
(N
));
1285 -- Processing for parameters accessed by the requeue
1288 Ent
: Entity_Id
:= First_Formal
(Enclosing
);
1291 while Present
(Ent
) loop
1293 -- For OUT or IN OUT parameter, the effect of the requeue
1294 -- is to assign the parameter a value on exit from the
1295 -- requeued body, so we can set it as source assigned.
1296 -- We also clear the Is_True_Constant indication. We do
1297 -- not need to clear Current_Value, since the effect of
1298 -- the requeue is to perform an unconditional goto so
1299 -- that any further references will not occur anyway.
1301 if Ekind
(Ent
) = E_Out_Parameter
1303 Ekind
(Ent
) = E_In_Out_Parameter
1305 Set_Never_Set_In_Source
(Ent
, False);
1306 Set_Is_True_Constant
(Ent
, False);
1309 -- For all parameters, the requeue acts as a reference,
1310 -- since the value of the parameter is passed to the
1311 -- new entry, so we want to suppress unreferenced warnings.
1313 Set_Referenced
(Ent
);
1319 end Analyze_Requeue
;
1321 ------------------------------
1322 -- Analyze_Selective_Accept --
1323 ------------------------------
1325 procedure Analyze_Selective_Accept
(N
: Node_Id
) is
1326 Alts
: constant List_Id
:= Select_Alternatives
(N
);
1329 Accept_Present
: Boolean := False;
1330 Terminate_Present
: Boolean := False;
1331 Delay_Present
: Boolean := False;
1332 Relative_Present
: Boolean := False;
1333 Alt_Count
: Uint
:= Uint_0
;
1336 Check_Restriction
(No_Select_Statements
, N
);
1337 Tasking_Used
:= True;
1339 Alt
:= First
(Alts
);
1340 while Present
(Alt
) loop
1341 Alt_Count
:= Alt_Count
+ 1;
1344 if Nkind
(Alt
) = N_Delay_Alternative
then
1345 if Delay_Present
then
1347 if Relative_Present
/=
1348 (Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
)
1351 ("delay_until and delay_relative alternatives ", Alt
);
1353 ("\cannot appear in the same selective_wait", Alt
);
1357 Delay_Present
:= True;
1359 Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
;
1362 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
1363 if Terminate_Present
then
1364 Error_Msg_N
("Only one terminate alternative allowed", N
);
1366 Terminate_Present
:= True;
1367 Check_Restriction
(No_Terminate_Alternatives
, N
);
1370 elsif Nkind
(Alt
) = N_Accept_Alternative
then
1371 Accept_Present
:= True;
1373 -- Check for duplicate accept
1377 Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
1378 EDN
: constant Node_Id
:= Entry_Direct_Name
(Stm
);
1382 if Nkind
(EDN
) = N_Identifier
1383 and then No
(Condition
(Alt
))
1384 and then Present
(Entity
(EDN
)) -- defend against junk
1385 and then Ekind
(Entity
(EDN
)) = E_Entry
1387 Ent
:= Entity
(EDN
);
1389 Alt1
:= First
(Alts
);
1390 while Alt1
/= Alt
loop
1391 if Nkind
(Alt1
) = N_Accept_Alternative
1392 and then No
(Condition
(Alt1
))
1395 Stm1
: constant Node_Id
:= Accept_Statement
(Alt1
);
1396 EDN1
: constant Node_Id
:= Entry_Direct_Name
(Stm1
);
1399 if Nkind
(EDN1
) = N_Identifier
then
1400 if Entity
(EDN1
) = Ent
then
1401 Error_Msg_Sloc
:= Sloc
(Stm1
);
1403 ("?accept duplicates one on line#", Stm
);
1419 Check_Restriction
(Max_Select_Alternatives
, N
, Alt_Count
);
1420 Check_Potentially_Blocking_Operation
(N
);
1422 if Terminate_Present
and Delay_Present
then
1423 Error_Msg_N
("at most one of terminate or delay alternative", N
);
1425 elsif not Accept_Present
then
1427 ("select must contain at least one accept alternative", N
);
1430 if Present
(Else_Statements
(N
)) then
1431 if Terminate_Present
or Delay_Present
then
1432 Error_Msg_N
("else part not allowed with other alternatives", N
);
1435 Analyze_Statements
(Else_Statements
(N
));
1437 end Analyze_Selective_Accept
;
1439 ------------------------------
1440 -- Analyze_Single_Protected --
1441 ------------------------------
1443 procedure Analyze_Single_Protected
(N
: Node_Id
) is
1444 Loc
: constant Source_Ptr
:= Sloc
(N
);
1445 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1449 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1452 Generate_Definition
(Id
);
1453 Tasking_Used
:= True;
1455 -- The node is rewritten as a protected type declaration,
1456 -- in exact analogy with what is done with single tasks.
1459 Make_Defining_Identifier
(Sloc
(Id
),
1460 New_External_Name
(Chars
(Id
), 'T'));
1463 Make_Protected_Type_Declaration
(Loc
,
1464 Defining_Identifier
=> T
,
1465 Protected_Definition
=> Relocate_Node
(Protected_Definition
(N
)));
1468 Make_Object_Declaration
(Loc
,
1469 Defining_Identifier
=> O_Name
,
1470 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1472 Rewrite
(N
, T_Decl
);
1473 Insert_After
(N
, O_Decl
);
1474 Mark_Rewrite_Insertion
(O_Decl
);
1476 -- Enter names of type and object before analysis, because the name
1477 -- of the object may be used in its own body.
1480 Set_Ekind
(T
, E_Protected_Type
);
1483 Enter_Name
(O_Name
);
1484 Set_Ekind
(O_Name
, E_Variable
);
1485 Set_Etype
(O_Name
, T
);
1487 -- Instead of calling Analyze on the new node, call directly
1488 -- the proper analysis procedure. Otherwise the node would be
1489 -- expanded twice, with disastrous result.
1491 Analyze_Protected_Type
(N
);
1493 end Analyze_Single_Protected
;
1495 -------------------------
1496 -- Analyze_Single_Task --
1497 -------------------------
1499 procedure Analyze_Single_Task
(N
: Node_Id
) is
1500 Loc
: constant Source_Ptr
:= Sloc
(N
);
1501 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1505 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1508 Generate_Definition
(Id
);
1509 Tasking_Used
:= True;
1511 -- The node is rewritten as a task type declaration, followed
1512 -- by an object declaration of that anonymous task type.
1515 Make_Defining_Identifier
(Sloc
(Id
),
1516 New_External_Name
(Chars
(Id
), Suffix
=> "TK"));
1519 Make_Task_Type_Declaration
(Loc
,
1520 Defining_Identifier
=> T
,
1521 Task_Definition
=> Relocate_Node
(Task_Definition
(N
)));
1524 Make_Object_Declaration
(Loc
,
1525 Defining_Identifier
=> O_Name
,
1526 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1528 Rewrite
(N
, T_Decl
);
1529 Insert_After
(N
, O_Decl
);
1530 Mark_Rewrite_Insertion
(O_Decl
);
1532 -- Enter names of type and object before analysis, because the name
1533 -- of the object may be used in its own body.
1536 Set_Ekind
(T
, E_Task_Type
);
1539 Enter_Name
(O_Name
);
1540 Set_Ekind
(O_Name
, E_Variable
);
1541 Set_Etype
(O_Name
, T
);
1543 -- Instead of calling Analyze on the new node, call directly
1544 -- the proper analysis procedure. Otherwise the node would be
1545 -- expanded twice, with disastrous result.
1547 Analyze_Task_Type
(N
);
1548 end Analyze_Single_Task
;
1550 -----------------------
1551 -- Analyze_Task_Body --
1552 -----------------------
1554 procedure Analyze_Task_Body
(N
: Node_Id
) is
1555 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1558 Spec_Id
: Entity_Id
;
1559 -- This is initially the entity of the task or task type involved,
1560 -- but is replaced by the task type always in the case of a single
1561 -- task declaration, since this is the proper scope to be used.
1564 -- This is the entity of the task or task type, and is the entity
1565 -- used for cross-reference purposes (it differs from Spec_Id in
1566 -- the case of a single task, since Spec_Id is set to the task type)
1569 Tasking_Used
:= True;
1570 Set_Ekind
(Body_Id
, E_Task_Body
);
1571 Set_Scope
(Body_Id
, Current_Scope
);
1572 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
1574 -- The spec is either a task type declaration, or a single task
1575 -- declaration for which we have created an anonymous type.
1577 if Present
(Spec_Id
)
1578 and then Ekind
(Spec_Id
) = E_Task_Type
1582 elsif Present
(Spec_Id
)
1583 and then Ekind
(Etype
(Spec_Id
)) = E_Task_Type
1584 and then not Comes_From_Source
(Etype
(Spec_Id
))
1589 Error_Msg_N
("missing specification for task body", Body_Id
);
1593 if Has_Completion
(Spec_Id
)
1594 and then Present
(Corresponding_Body
(Parent
(Spec_Id
)))
1596 if Nkind
(Parent
(Spec_Id
)) = N_Task_Type_Declaration
then
1597 Error_Msg_NE
("duplicate body for task type&", N
, Spec_Id
);
1600 Error_Msg_NE
("duplicate body for task&", N
, Spec_Id
);
1605 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
1606 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1608 -- Deal with case of body of single task (anonymous type was created)
1610 if Ekind
(Spec_Id
) = E_Variable
then
1611 Spec_Id
:= Etype
(Spec_Id
);
1614 New_Scope
(Spec_Id
);
1615 Set_Corresponding_Spec
(N
, Spec_Id
);
1616 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
1617 Set_Has_Completion
(Spec_Id
);
1618 Install_Declarations
(Spec_Id
);
1619 Last_E
:= Last_Entity
(Spec_Id
);
1621 Analyze_Declarations
(Declarations
(N
));
1623 -- For visibility purposes, all entities in the body are private.
1624 -- Set First_Private_Entity accordingly, if there was no private
1625 -- part in the protected declaration.
1627 if No
(First_Private_Entity
(Spec_Id
)) then
1628 if Present
(Last_E
) then
1629 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
1631 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
1635 Analyze
(Handled_Statement_Sequence
(N
));
1636 Check_Completion
(Body_Id
);
1637 Check_References
(Body_Id
);
1638 Check_References
(Spec_Id
);
1640 -- Check for entries with no corresponding accept
1646 Ent
:= First_Entity
(Spec_Id
);
1648 while Present
(Ent
) loop
1650 and then not Entry_Accepted
(Ent
)
1651 and then Comes_From_Source
(Ent
)
1653 Error_Msg_NE
("no accept for entry &?", N
, Ent
);
1660 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Ref_Id
);
1662 end Analyze_Task_Body
;
1664 -----------------------------
1665 -- Analyze_Task_Definition --
1666 -----------------------------
1668 procedure Analyze_Task_Definition
(N
: Node_Id
) is
1672 Tasking_Used
:= True;
1674 if Present
(Visible_Declarations
(N
)) then
1675 Analyze_Declarations
(Visible_Declarations
(N
));
1678 if Present
(Private_Declarations
(N
)) then
1679 L
:= Last_Entity
(Current_Scope
);
1680 Analyze_Declarations
(Private_Declarations
(N
));
1683 Set_First_Private_Entity
1684 (Current_Scope
, Next_Entity
(L
));
1686 Set_First_Private_Entity
1687 (Current_Scope
, First_Entity
(Current_Scope
));
1691 Check_Max_Entries
(N
, Max_Task_Entries
);
1692 Process_End_Label
(N
, 'e', Current_Scope
);
1693 end Analyze_Task_Definition
;
1695 -----------------------
1696 -- Analyze_Task_Type --
1697 -----------------------
1699 procedure Analyze_Task_Type
(N
: Node_Id
) is
1701 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1704 Check_Restriction
(No_Tasking
, N
);
1705 Tasking_Used
:= True;
1706 T
:= Find_Type_Name
(N
);
1707 Generate_Definition
(T
);
1709 if Ekind
(T
) = E_Incomplete_Type
then
1711 Set_Completion_Referenced
(T
);
1714 Set_Ekind
(T
, E_Task_Type
);
1715 Set_Is_First_Subtype
(T
, True);
1716 Set_Has_Task
(T
, True);
1717 Init_Size_Align
(T
);
1719 Set_Has_Delayed_Freeze
(T
, True);
1720 Set_Stored_Constraint
(T
, No_Elist
);
1723 if Present
(Discriminant_Specifications
(N
)) then
1724 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1725 Error_Msg_N
("(Ada 83) task discriminant not allowed!", N
);
1728 if Has_Discriminants
(T
) then
1730 -- Install discriminants. Also, verify conformance of
1731 -- discriminants of previous and current view. ???
1733 Install_Declarations
(T
);
1735 Process_Discriminants
(N
);
1739 if Present
(Task_Definition
(N
)) then
1740 Analyze_Task_Definition
(Task_Definition
(N
));
1743 if not Is_Library_Level_Entity
(T
) then
1744 Check_Restriction
(No_Task_Hierarchy
, N
);
1750 and then Is_Private_Type
(Def_Id
)
1751 and then Has_Discriminants
(Def_Id
)
1752 and then Expander_Active
1754 Exp_Ch9
.Expand_N_Task_Type_Declaration
(N
);
1755 Process_Full_View
(N
, T
, Def_Id
);
1757 end Analyze_Task_Type
;
1759 -----------------------------------
1760 -- Analyze_Terminate_Alternative --
1761 -----------------------------------
1763 procedure Analyze_Terminate_Alternative
(N
: Node_Id
) is
1765 Tasking_Used
:= True;
1767 if Present
(Pragmas_Before
(N
)) then
1768 Analyze_List
(Pragmas_Before
(N
));
1771 if Present
(Condition
(N
)) then
1772 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
1774 end Analyze_Terminate_Alternative
;
1776 ------------------------------
1777 -- Analyze_Timed_Entry_Call --
1778 ------------------------------
1780 procedure Analyze_Timed_Entry_Call
(N
: Node_Id
) is
1782 Check_Restriction
(No_Select_Statements
, N
);
1783 Tasking_Used
:= True;
1784 Analyze
(Entry_Call_Alternative
(N
));
1785 Analyze
(Delay_Alternative
(N
));
1786 end Analyze_Timed_Entry_Call
;
1788 ------------------------------------
1789 -- Analyze_Triggering_Alternative --
1790 ------------------------------------
1792 procedure Analyze_Triggering_Alternative
(N
: Node_Id
) is
1793 Trigger
: constant Node_Id
:= Triggering_Statement
(N
);
1796 Tasking_Used
:= True;
1798 if Present
(Pragmas_Before
(N
)) then
1799 Analyze_List
(Pragmas_Before
(N
));
1803 if Comes_From_Source
(Trigger
)
1804 and then Nkind
(Trigger
) /= N_Delay_Until_Statement
1805 and then Nkind
(Trigger
) /= N_Delay_Relative_Statement
1806 and then Nkind
(Trigger
) /= N_Entry_Call_Statement
1809 ("triggering statement must be delay or entry call", Trigger
);
1812 if Is_Non_Empty_List
(Statements
(N
)) then
1813 Analyze_Statements
(Statements
(N
));
1815 end Analyze_Triggering_Alternative
;
1817 -----------------------
1818 -- Check_Max_Entries --
1819 -----------------------
1821 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
) is
1824 procedure Count
(L
: List_Id
);
1825 -- Count entries in given declaration list
1831 procedure Count
(L
: List_Id
) is
1840 while Present
(D
) loop
1841 if Nkind
(D
) = N_Entry_Declaration
then
1843 DSD
: constant Node_Id
:=
1844 Discrete_Subtype_Definition
(D
);
1847 -- If not an entry family, then just one entry
1850 Ecount
:= Ecount
+ 1;
1852 -- If entry family with static bounds, count entries
1854 elsif Is_OK_Static_Subtype
(Etype
(DSD
)) then
1856 Lo
: constant Uint
:=
1858 (Type_Low_Bound
(Etype
(DSD
)));
1859 Hi
: constant Uint
:=
1861 (Type_High_Bound
(Etype
(DSD
)));
1865 Ecount
:= Ecount
+ Hi
- Lo
+ 1;
1869 -- Entry family with non-static bounds
1872 -- If restriction is set, then this is an error
1874 if Restrictions
.Set
(R
) then
1876 ("static subtype required by Restriction pragma",
1879 -- Otherwise we record an unknown count restriction
1882 Check_Restriction
(R
, D
);
1892 -- Start of processing for Check_Max_Entries
1896 Count
(Visible_Declarations
(D
));
1897 Count
(Private_Declarations
(D
));
1900 Check_Restriction
(R
, D
, Ecount
);
1902 end Check_Max_Entries
;
1904 --------------------------
1905 -- Find_Concurrent_Spec --
1906 --------------------------
1908 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
is
1909 Spec_Id
: Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
1912 -- The type may have been given by an incomplete type declaration.
1913 -- Find full view now.
1915 if Present
(Spec_Id
) and then Ekind
(Spec_Id
) = E_Incomplete_Type
then
1916 Spec_Id
:= Full_View
(Spec_Id
);
1920 end Find_Concurrent_Spec
;
1922 --------------------------
1923 -- Install_Declarations --
1924 --------------------------
1926 procedure Install_Declarations
(Spec
: Entity_Id
) is
1931 E
:= First_Entity
(Spec
);
1933 while Present
(E
) loop
1934 Prev
:= Current_Entity
(E
);
1935 Set_Current_Entity
(E
);
1936 Set_Is_Immediately_Visible
(E
);
1937 Set_Homonym
(E
, Prev
);
1940 end Install_Declarations
;