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
);
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.
238 if Present
(Index
) then
239 Ityp
:= New_Internal_Entity
240 (E_Entry_Family
, Current_Scope
, Sloc
(N
), 'E');
242 Ityp
:= New_Internal_Entity
243 (E_Entry
, Current_Scope
, Sloc
(N
), 'E');
246 Set_Etype
(Ityp
, Standard_Void_Type
);
247 Set_Accept_Address
(Ityp
, New_Elmt_List
);
249 if Present
(Formals
) then
251 Process_Formals
(Formals
, N
);
252 Create_Extra_Formals
(Ityp
);
256 -- We set the default expressions processed flag because we don't
257 -- need default expression functions. This is really more like a
258 -- body entity than a spec entity anyway.
260 Set_Default_Expressions_Processed
(Ityp
);
262 E
:= First_Entity
(Etype
(Task_Nam
));
264 while Present
(E
) loop
265 if Chars
(E
) = Chars
(Nam
)
266 and then (Ekind
(E
) = Ekind
(Ityp
))
267 and then Type_Conformant
(Ityp
, E
)
276 if Entry_Nam
= Any_Id
then
277 Error_Msg_N
("no entry declaration matches accept statement", N
);
280 Set_Entity
(Nam
, Entry_Nam
);
281 Generate_Reference
(Entry_Nam
, Nam
, 'b', Set_Ref
=> False);
282 Style
.Check_Identifier
(Nam
, Entry_Nam
);
285 -- Verify that the entry is not hidden by a procedure declared in
286 -- the current block (pathological but possible).
288 if Current_Scope
/= Task_Nam
then
293 E1
:= First_Entity
(Current_Scope
);
295 while Present
(E1
) loop
297 if Ekind
(E1
) = E_Procedure
298 and then Chars
(E1
) = Chars
(Entry_Nam
)
299 and then Type_Conformant
(E1
, Entry_Nam
)
301 Error_Msg_N
("entry name is not visible", N
);
309 Set_Convention
(Ityp
, Convention
(Entry_Nam
));
310 Check_Fully_Conformant
(Ityp
, Entry_Nam
, N
);
312 for J
in reverse 0 .. Scope_Stack
.Last
loop
313 exit when Task_Nam
= Scope_Stack
.Table
(J
).Entity
;
315 if Entry_Nam
= Scope_Stack
.Table
(J
).Entity
then
316 Error_Msg_N
("duplicate accept statement for same entry", N
);
327 when N_Task_Body | N_Compilation_Unit
=>
329 when N_Asynchronous_Select
=>
330 Error_Msg_N
("accept statements are not allowed within" &
331 " an asynchronous select inner" &
332 " to the enclosing task body", N
);
340 if Ekind
(E
) = E_Entry_Family
then
342 Error_Msg_N
("missing entry index in accept for entry family", N
);
344 Analyze_And_Resolve
(Index
, Entry_Index_Type
(E
));
345 Apply_Range_Check
(Index
, Actual_Index_Type
(E
));
348 elsif Present
(Index
) then
349 Error_Msg_N
("invalid entry index in accept for simple entry", N
);
352 -- If label declarations present, analyze them. They are declared
353 -- in the enclosing task, but their enclosing scope is the entry itself,
354 -- so that goto's to the label are recognized as local to the accept.
356 if Present
(Declarations
(N
)) then
363 Decl
:= First
(Declarations
(N
));
365 while Present
(Decl
) loop
369 (Nkind
(Decl
) = N_Implicit_Label_Declaration
);
371 Id
:= Defining_Identifier
(Decl
);
372 Set_Enclosing_Scope
(Id
, Entry_Nam
);
378 -- If statements are present, they must be analyzed in the context
379 -- of the entry, so that references to formals are correctly resolved.
380 -- We also have to add the declarations that are required by the
381 -- expansion of the accept statement in this case if expansion active.
383 -- In the case of a select alternative of a selective accept,
384 -- the expander references the address declaration even if there
385 -- is no statement list.
386 -- We also need to create the renaming declarations for the local
387 -- variables that will replace references to the formals within
390 Exp_Ch9
.Expand_Accept_Declarations
(N
, Entry_Nam
);
392 -- Set Never_Set_In_Source and clear Is_True_Constant/Current_Value
393 -- fields on all entry formals (this loop ignores all other entities).
395 E
:= First_Entity
(Entry_Nam
);
396 while Present
(E
) loop
397 if Is_Formal
(E
) then
398 Set_Never_Set_In_Source
(E
, True);
399 Set_Is_True_Constant
(E
, False);
400 Set_Current_Value
(E
, Empty
);
406 -- Analyze statements if present
408 if Present
(Stats
) then
409 New_Scope
(Entry_Nam
);
410 Install_Declarations
(Entry_Nam
);
412 Set_Actual_Subtypes
(N
, Current_Scope
);
415 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Nam
);
419 -- Some warning checks
421 Check_Potentially_Blocking_Operation
(N
);
422 Check_References
(Entry_Nam
, N
);
423 Set_Entry_Accepted
(Entry_Nam
);
424 end Analyze_Accept_Statement
;
426 ---------------------------------
427 -- Analyze_Asynchronous_Select --
428 ---------------------------------
430 procedure Analyze_Asynchronous_Select
(N
: Node_Id
) is
432 Tasking_Used
:= True;
433 Check_Restriction
(Max_Asynchronous_Select_Nesting
, N
);
434 Check_Restriction
(No_Select_Statements
, N
);
436 -- Analyze the statements. We analyze statements in the abortable part
437 -- first, because this is the section that is executed first, and that
438 -- way our remembering of saved values and checks is accurate.
440 Analyze_Statements
(Statements
(Abortable_Part
(N
)));
441 Analyze
(Triggering_Alternative
(N
));
442 end Analyze_Asynchronous_Select
;
444 ------------------------------------
445 -- Analyze_Conditional_Entry_Call --
446 ------------------------------------
448 procedure Analyze_Conditional_Entry_Call
(N
: Node_Id
) is
450 Check_Restriction
(No_Select_Statements
, N
);
451 Tasking_Used
:= True;
452 Analyze
(Entry_Call_Alternative
(N
));
453 Analyze_Statements
(Else_Statements
(N
));
454 end Analyze_Conditional_Entry_Call
;
456 --------------------------------
457 -- Analyze_Delay_Alternative --
458 --------------------------------
460 procedure Analyze_Delay_Alternative
(N
: Node_Id
) is
464 Tasking_Used
:= True;
465 Check_Restriction
(No_Delay
, N
);
467 if Present
(Pragmas_Before
(N
)) then
468 Analyze_List
(Pragmas_Before
(N
));
471 if Nkind
(Parent
(N
)) = N_Selective_Accept
472 or else Nkind
(Parent
(N
)) = N_Timed_Entry_Call
474 Expr
:= Expression
(Delay_Statement
(N
));
476 -- defer full analysis until the statement is expanded, to insure
477 -- that generated code does not move past the guard. The delay
478 -- expression is only evaluated if the guard is open.
480 if Nkind
(Delay_Statement
(N
)) = N_Delay_Relative_Statement
then
481 Pre_Analyze_And_Resolve
(Expr
, Standard_Duration
);
484 Pre_Analyze_And_Resolve
(Expr
);
487 if Nkind
(Delay_Statement
(N
)) = N_Delay_Until_Statement
and then
488 not Is_RTE
(Base_Type
(Etype
(Expr
)), RO_CA_Time
) and then
489 not Is_RTE
(Base_Type
(Etype
(Expr
)), RO_RT_Time
)
491 Error_Msg_N
("expect Time types for `DELAY UNTIL`", Expr
);
494 Check_Restriction
(No_Fixed_Point
, Expr
);
496 Analyze
(Delay_Statement
(N
));
499 if Present
(Condition
(N
)) then
500 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
503 if Is_Non_Empty_List
(Statements
(N
)) then
504 Analyze_Statements
(Statements
(N
));
506 end Analyze_Delay_Alternative
;
508 ----------------------------
509 -- Analyze_Delay_Relative --
510 ----------------------------
512 procedure Analyze_Delay_Relative
(N
: Node_Id
) is
513 E
: constant Node_Id
:= Expression
(N
);
516 Check_Restriction
(No_Relative_Delay
, N
);
517 Tasking_Used
:= True;
518 Check_Restriction
(No_Delay
, N
);
519 Check_Potentially_Blocking_Operation
(N
);
520 Analyze_And_Resolve
(E
, Standard_Duration
);
521 Check_Restriction
(No_Fixed_Point
, E
);
522 end Analyze_Delay_Relative
;
524 -------------------------
525 -- Analyze_Delay_Until --
526 -------------------------
528 procedure Analyze_Delay_Until
(N
: Node_Id
) is
529 E
: constant Node_Id
:= Expression
(N
);
532 Tasking_Used
:= True;
533 Check_Restriction
(No_Delay
, N
);
534 Check_Potentially_Blocking_Operation
(N
);
537 if not Is_RTE
(Base_Type
(Etype
(E
)), RO_CA_Time
) and then
538 not Is_RTE
(Base_Type
(Etype
(E
)), RO_RT_Time
)
540 Error_Msg_N
("expect Time types for `DELAY UNTIL`", E
);
542 end Analyze_Delay_Until
;
544 ------------------------
545 -- Analyze_Entry_Body --
546 ------------------------
548 procedure Analyze_Entry_Body
(N
: Node_Id
) is
549 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
550 Decls
: constant List_Id
:= Declarations
(N
);
551 Stats
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
552 Formals
: constant Node_Id
:= Entry_Body_Formal_Part
(N
);
553 P_Type
: constant Entity_Id
:= Current_Scope
;
554 Entry_Name
: Entity_Id
;
558 Tasking_Used
:= True;
560 -- Entry_Name is initialized to Any_Id. It should get reset to the
561 -- matching entry entity. An error is signalled if it is not reset
563 Entry_Name
:= Any_Id
;
567 if Present
(Entry_Index_Specification
(Formals
)) then
568 Set_Ekind
(Id
, E_Entry_Family
);
570 Set_Ekind
(Id
, E_Entry
);
573 Set_Scope
(Id
, Current_Scope
);
574 Set_Etype
(Id
, Standard_Void_Type
);
575 Set_Accept_Address
(Id
, New_Elmt_List
);
577 E
:= First_Entity
(P_Type
);
578 while Present
(E
) loop
579 if Chars
(E
) = Chars
(Id
)
580 and then (Ekind
(E
) = Ekind
(Id
))
581 and then Type_Conformant
(Id
, E
)
584 Set_Convention
(Id
, Convention
(E
));
585 Set_Corresponding_Body
(Parent
(Entry_Name
), Id
);
586 Check_Fully_Conformant
(Id
, E
, N
);
588 if Ekind
(Id
) = E_Entry_Family
then
589 if not Fully_Conformant_Discrete_Subtypes
(
590 Discrete_Subtype_Definition
(Parent
(E
)),
591 Discrete_Subtype_Definition
592 (Entry_Index_Specification
(Formals
)))
595 ("index not fully conformant with previous declaration",
596 Discrete_Subtype_Definition
597 (Entry_Index_Specification
(Formals
)));
600 -- The elaboration of the entry body does not recompute
601 -- the bounds of the index, which may have side effects.
602 -- Inherit the bounds from the entry declaration. This
603 -- is critical if the entry has a per-object constraint.
604 -- If a bound is given by a discriminant, it must be
605 -- reanalyzed in order to capture the discriminal of the
606 -- current entry, rather than that of the protected type.
609 Index_Spec
: constant Node_Id
:=
610 Entry_Index_Specification
(Formals
);
612 Def
: constant Node_Id
:=
614 (Discrete_Subtype_Definition
(Parent
(E
)));
619 (Discrete_Subtype_Definition
(Index_Spec
))) = N_Range
621 Set_Etype
(Def
, Empty
);
622 Set_Analyzed
(Def
, False);
623 Set_Discrete_Subtype_Definition
(Index_Spec
, Def
);
624 Set_Analyzed
(Low_Bound
(Def
), False);
625 Set_Analyzed
(High_Bound
(Def
), False);
627 if Denotes_Discriminant
(Low_Bound
(Def
)) then
628 Set_Entity
(Low_Bound
(Def
), Empty
);
631 if Denotes_Discriminant
(High_Bound
(Def
)) then
632 Set_Entity
(High_Bound
(Def
), Empty
);
636 Make_Index
(Def
, Index_Spec
);
638 (Defining_Identifier
(Index_Spec
), Etype
(Def
));
650 if Entry_Name
= Any_Id
then
651 Error_Msg_N
("no entry declaration matches entry body", N
);
654 elsif Has_Completion
(Entry_Name
) then
655 Error_Msg_N
("duplicate entry body", N
);
659 Set_Has_Completion
(Entry_Name
);
660 Generate_Reference
(Entry_Name
, Id
, 'b', Set_Ref
=> False);
661 Style
.Check_Identifier
(Id
, Entry_Name
);
664 Exp_Ch9
.Expand_Entry_Barrier
(N
, Entry_Name
);
665 New_Scope
(Entry_Name
);
667 Exp_Ch9
.Expand_Entry_Body_Declarations
(N
);
668 Install_Declarations
(Entry_Name
);
669 Set_Actual_Subtypes
(N
, Current_Scope
);
671 -- The entity for the protected subprogram corresponding to the entry
672 -- has been created. We retain the name of this entity in the entry
673 -- body, for use when the corresponding subprogram body is created.
674 -- Note that entry bodies have to corresponding_spec, and there is no
675 -- easy link back in the tree between the entry body and the entity for
678 Set_Protected_Body_Subprogram
(Id
,
679 Protected_Body_Subprogram
(Entry_Name
));
681 if Present
(Decls
) then
682 Analyze_Declarations
(Decls
);
685 if Present
(Stats
) then
689 -- Check for unreferenced variables etc. Before the Check_References
690 -- call, we transfer Never_Set_In_Source and Referenced flags from
691 -- parameters in the spec to the corresponding entities in the body,
692 -- since we want the warnings on the body entities. Note that we do
693 -- not have to transfer Referenced_As_LHS, since that flag can only
694 -- be set for simple variables.
696 -- At the same time, we set the flags on the spec entities to suppress
697 -- any warnings on the spec formals, since we also scan the spec.
704 E1
:= First_Entity
(Entry_Name
);
705 while Present
(E1
) loop
706 E2
:= First_Entity
(Id
);
707 while Present
(E2
) loop
708 exit when Chars
(E1
) = Chars
(E2
);
712 -- If no matching body entity, then we already had
713 -- a detected error of some kind, so just forget
714 -- about worrying about these warnings.
720 if Ekind
(E1
) = E_Out_Parameter
then
721 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
722 Set_Never_Set_In_Source
(E1
, False);
725 Set_Referenced
(E2
, Referenced
(E1
));
732 Check_References
(Id
);
735 -- We still need to check references for the spec, since objects
736 -- declared in the body are chained (in the First_Entity sense) to
737 -- the spec rather than the body in the case of entries.
739 Check_References
(Entry_Name
);
741 -- Process the end label, and terminate the scope
743 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Entry_Name
);
746 -- If this is an entry family, remove the loop created to provide
747 -- a scope for the entry index.
749 if Ekind
(Id
) = E_Entry_Family
750 and then Present
(Entry_Index_Specification
(Formals
))
755 end Analyze_Entry_Body
;
757 ------------------------------------
758 -- Analyze_Entry_Body_Formal_Part --
759 ------------------------------------
761 procedure Analyze_Entry_Body_Formal_Part
(N
: Node_Id
) is
762 Id
: constant Entity_Id
:= Defining_Identifier
(Parent
(N
));
763 Index
: constant Node_Id
:= Entry_Index_Specification
(N
);
764 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
767 Tasking_Used
:= True;
769 if Present
(Index
) then
773 if Present
(Formals
) then
774 Set_Scope
(Id
, Current_Scope
);
776 Process_Formals
(Formals
, Parent
(N
));
779 end Analyze_Entry_Body_Formal_Part
;
781 ------------------------------------
782 -- Analyze_Entry_Call_Alternative --
783 ------------------------------------
785 procedure Analyze_Entry_Call_Alternative
(N
: Node_Id
) is
786 Call
: constant Node_Id
:= Entry_Call_Statement
(N
);
789 Tasking_Used
:= True;
791 if Present
(Pragmas_Before
(N
)) then
792 Analyze_List
(Pragmas_Before
(N
));
795 if Nkind
(Call
) = N_Attribute_Reference
then
797 -- Possibly a stream attribute, but definitely illegal. Other
798 -- illegalitles, such as procedure calls, are diagnosed after
801 Error_Msg_N
("entry call alternative requires an entry call", Call
);
807 if Is_Non_Empty_List
(Statements
(N
)) then
808 Analyze_Statements
(Statements
(N
));
810 end Analyze_Entry_Call_Alternative
;
812 -------------------------------
813 -- Analyze_Entry_Declaration --
814 -------------------------------
816 procedure Analyze_Entry_Declaration
(N
: Node_Id
) is
817 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
818 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
819 D_Sdef
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
822 Generate_Definition
(Id
);
823 Tasking_Used
:= True;
826 Set_Ekind
(Id
, E_Entry
);
829 Set_Ekind
(Id
, E_Entry_Family
);
831 Make_Index
(D_Sdef
, N
, Id
);
834 Set_Etype
(Id
, Standard_Void_Type
);
835 Set_Convention
(Id
, Convention_Entry
);
836 Set_Accept_Address
(Id
, New_Elmt_List
);
838 if Present
(Formals
) then
839 Set_Scope
(Id
, Current_Scope
);
841 Process_Formals
(Formals
, N
);
842 Create_Extra_Formals
(Id
);
846 if Ekind
(Id
) = E_Entry
then
847 New_Overloaded_Entity
(Id
);
849 end Analyze_Entry_Declaration
;
851 ---------------------------------------
852 -- Analyze_Entry_Index_Specification --
853 ---------------------------------------
855 -- The defining_Identifier of the entry index specification is local
856 -- to the entry body, but must be available in the entry barrier,
857 -- which is evaluated outside of the entry body. The index is eventually
858 -- renamed as a run-time object, so is visibility is strictly a front-end
859 -- concern. In order to make it available to the barrier, we create
860 -- an additional scope, as for a loop, whose only declaration is the
861 -- index name. This loop is not attached to the tree and does not appear
862 -- as an entity local to the protected type, so its existence need only
863 -- be knwown to routines that process entry families.
865 procedure Analyze_Entry_Index_Specification
(N
: Node_Id
) is
866 Iden
: constant Node_Id
:= Defining_Identifier
(N
);
867 Def
: constant Node_Id
:= Discrete_Subtype_Definition
(N
);
868 Loop_Id
: constant Entity_Id
:=
869 Make_Defining_Identifier
(Sloc
(N
),
870 Chars
=> New_Internal_Name
('L'));
873 Tasking_Used
:= True;
876 -- There is no elaboration of the entry index specification. Therefore,
877 -- if the index is a range, it is not resolved and expanded, but the
878 -- bounds are inherited from the entry declaration, and reanalyzed.
879 -- See Analyze_Entry_Body.
881 if Nkind
(Def
) /= N_Range
then
885 Set_Ekind
(Loop_Id
, E_Loop
);
886 Set_Scope
(Loop_Id
, Current_Scope
);
889 Set_Ekind
(Iden
, E_Entry_Index_Parameter
);
890 Set_Etype
(Iden
, Etype
(Def
));
891 end Analyze_Entry_Index_Specification
;
893 ----------------------------
894 -- Analyze_Protected_Body --
895 ----------------------------
897 procedure Analyze_Protected_Body
(N
: Node_Id
) is
898 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
902 -- This is initially the entity of the protected object or protected
903 -- type involved, but is replaced by the protected type always in the
904 -- case of a single protected declaration, since this is the proper
908 -- This is the entity of the protected object or protected type
909 -- involved, and is the entity used for cross-reference purposes
910 -- (it differs from Spec_Id in the case of a single protected
911 -- object, since Spec_Id is set to the protected type in this case).
914 Tasking_Used
:= True;
915 Set_Ekind
(Body_Id
, E_Protected_Body
);
916 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
919 and then Ekind
(Spec_Id
) = E_Protected_Type
923 elsif Present
(Spec_Id
)
924 and then Ekind
(Etype
(Spec_Id
)) = E_Protected_Type
925 and then not Comes_From_Source
(Etype
(Spec_Id
))
930 Error_Msg_N
("missing specification for protected body", Body_Id
);
935 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
936 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
938 -- The declarations are always attached to the type
940 if Ekind
(Spec_Id
) /= E_Protected_Type
then
941 Spec_Id
:= Etype
(Spec_Id
);
945 Set_Corresponding_Spec
(N
, Spec_Id
);
946 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
947 Set_Has_Completion
(Spec_Id
);
948 Install_Declarations
(Spec_Id
);
950 Exp_Ch9
.Expand_Protected_Body_Declarations
(N
, Spec_Id
);
952 Last_E
:= Last_Entity
(Spec_Id
);
954 Analyze_Declarations
(Declarations
(N
));
956 -- For visibility purposes, all entities in the body are private.
957 -- Set First_Private_Entity accordingly, if there was no private
958 -- part in the protected declaration.
960 if No
(First_Private_Entity
(Spec_Id
)) then
961 if Present
(Last_E
) then
962 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
964 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
968 Check_Completion
(Body_Id
);
969 Check_References
(Spec_Id
);
970 Process_End_Label
(N
, 't', Ref_Id
);
972 end Analyze_Protected_Body
;
974 ----------------------------------
975 -- Analyze_Protected_Definition --
976 ----------------------------------
978 procedure Analyze_Protected_Definition
(N
: Node_Id
) is
983 Tasking_Used
:= True;
984 Analyze_Declarations
(Visible_Declarations
(N
));
986 if Present
(Private_Declarations
(N
))
987 and then not Is_Empty_List
(Private_Declarations
(N
))
989 L
:= Last_Entity
(Current_Scope
);
990 Analyze_Declarations
(Private_Declarations
(N
));
993 Set_First_Private_Entity
(Current_Scope
, Next_Entity
(L
));
996 Set_First_Private_Entity
(Current_Scope
,
997 First_Entity
(Current_Scope
));
1001 E
:= First_Entity
(Current_Scope
);
1003 while Present
(E
) loop
1005 if Ekind
(E
) = E_Function
1006 or else Ekind
(E
) = E_Procedure
1008 Set_Convention
(E
, Convention_Protected
);
1010 elsif Is_Task_Type
(Etype
(E
))
1011 or else Has_Task
(Etype
(E
))
1013 Set_Has_Task
(Current_Scope
);
1019 Check_Max_Entries
(N
, Max_Protected_Entries
);
1020 Process_End_Label
(N
, 'e', Current_Scope
);
1021 end Analyze_Protected_Definition
;
1023 ----------------------------
1024 -- Analyze_Protected_Type --
1025 ----------------------------
1027 procedure Analyze_Protected_Type
(N
: Node_Id
) is
1030 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1033 if No_Run_Time_Mode
then
1034 Error_Msg_CRT
("protected type", N
);
1038 Tasking_Used
:= True;
1039 Check_Restriction
(No_Protected_Types
, N
);
1041 T
:= Find_Type_Name
(N
);
1043 if Ekind
(T
) = E_Incomplete_Type
then
1045 Set_Completion_Referenced
(T
);
1048 Set_Ekind
(T
, E_Protected_Type
);
1049 Init_Size_Align
(T
);
1051 Set_Is_First_Subtype
(T
, True);
1052 Set_Has_Delayed_Freeze
(T
, True);
1053 Set_Stored_Constraint
(T
, No_Elist
);
1056 if Present
(Discriminant_Specifications
(N
)) then
1057 if Has_Discriminants
(T
) then
1059 -- Install discriminants. Also, verify conformance of
1060 -- discriminants of previous and current view. ???
1062 Install_Declarations
(T
);
1064 Process_Discriminants
(N
);
1068 Analyze
(Protected_Definition
(N
));
1070 -- Protected types with entries are controlled (because of the
1071 -- Protection component if nothing else), same for any protected type
1072 -- with interrupt handlers. Note that we need to analyze the protected
1073 -- definition to set Has_Entries and such.
1075 if (Abort_Allowed
or else Restriction_Active
(No_Entry_Queue
) = False
1076 or else Number_Entries
(T
) > 1)
1079 or else Has_Interrupt_Handler
(T
)
1080 or else Has_Attach_Handler
(T
))
1082 Set_Has_Controlled_Component
(T
, True);
1085 -- The Ekind of components is E_Void during analysis to detect
1086 -- illegal uses. Now it can be set correctly.
1088 E
:= First_Entity
(Current_Scope
);
1090 while Present
(E
) loop
1091 if Ekind
(E
) = E_Void
then
1092 Set_Ekind
(E
, E_Component
);
1093 Init_Component_Location
(E
);
1102 and then Is_Private_Type
(Def_Id
)
1103 and then Has_Discriminants
(Def_Id
)
1104 and then Expander_Active
1106 Exp_Ch9
.Expand_N_Protected_Type_Declaration
(N
);
1107 Process_Full_View
(N
, T
, Def_Id
);
1109 end Analyze_Protected_Type
;
1111 ---------------------
1112 -- Analyze_Requeue --
1113 ---------------------
1115 procedure Analyze_Requeue
(N
: Node_Id
) is
1116 Entry_Name
: Node_Id
:= Name
(N
);
1117 Entry_Id
: Entity_Id
;
1121 Enclosing
: Entity_Id
;
1122 Target_Obj
: Node_Id
:= Empty
;
1123 Req_Scope
: Entity_Id
;
1124 Outer_Ent
: Entity_Id
;
1127 Check_Restriction
(No_Requeue_Statements
, N
);
1128 Check_Unreachable_Code
(N
);
1129 Tasking_Used
:= True;
1132 for J
in reverse 0 .. Scope_Stack
.Last
loop
1133 Enclosing
:= Scope_Stack
.Table
(J
).Entity
;
1134 exit when Is_Entry
(Enclosing
);
1136 if Ekind
(Enclosing
) /= E_Block
1137 and then Ekind
(Enclosing
) /= E_Loop
1139 Error_Msg_N
("requeue must appear within accept or entry body", N
);
1144 Analyze
(Entry_Name
);
1146 if Etype
(Entry_Name
) = Any_Type
then
1150 if Nkind
(Entry_Name
) = N_Selected_Component
then
1151 Target_Obj
:= Prefix
(Entry_Name
);
1152 Entry_Name
:= Selector_Name
(Entry_Name
);
1155 -- If an explicit target object is given then we have to check
1156 -- the restrictions of 9.5.4(6).
1158 if Present
(Target_Obj
) then
1160 -- Locate containing concurrent unit and determine enclosing entry
1161 -- body or outermost enclosing accept statement within the unit.
1164 for S
in reverse 0 .. Scope_Stack
.Last
loop
1165 Req_Scope
:= Scope_Stack
.Table
(S
).Entity
;
1167 exit when Ekind
(Req_Scope
) in Task_Kind
1168 or else Ekind
(Req_Scope
) in Protected_Kind
;
1170 if Is_Entry
(Req_Scope
) then
1171 Outer_Ent
:= Req_Scope
;
1175 pragma Assert
(Present
(Outer_Ent
));
1177 -- Check that the accessibility level of the target object
1178 -- is not greater or equal to the outermost enclosing accept
1179 -- statement (or entry body) unless it is a parameter of the
1180 -- innermost enclosing accept statement (or entry body).
1182 if Object_Access_Level
(Target_Obj
) >= Scope_Depth
(Outer_Ent
)
1184 (not Is_Entity_Name
(Target_Obj
)
1185 or else Ekind
(Entity
(Target_Obj
)) not in Formal_Kind
1186 or else Enclosing
/= Scope
(Entity
(Target_Obj
)))
1189 ("target object has invalid level for requeue", Target_Obj
);
1193 -- Overloaded case, find right interpretation
1195 if Is_Overloaded
(Entry_Name
) then
1196 Get_First_Interp
(Entry_Name
, I
, It
);
1200 while Present
(It
.Nam
) loop
1201 if No
(First_Formal
(It
.Nam
))
1202 or else Subtype_Conformant
(Enclosing
, It
.Nam
)
1208 Error_Msg_N
("ambiguous entry name in requeue", N
);
1213 Get_Next_Interp
(I
, It
);
1217 Error_Msg_N
("no entry matches context", N
);
1220 Set_Entity
(Entry_Name
, Entry_Id
);
1223 -- Non-overloaded cases
1225 -- For the case of a reference to an element of an entry family,
1226 -- the Entry_Name is an indexed component.
1228 elsif Nkind
(Entry_Name
) = N_Indexed_Component
then
1230 -- Requeue to an entry out of the body
1232 if Nkind
(Prefix
(Entry_Name
)) = N_Selected_Component
then
1233 Entry_Id
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
1235 -- Requeue from within the body itself
1237 elsif Nkind
(Prefix
(Entry_Name
)) = N_Identifier
then
1238 Entry_Id
:= Entity
(Prefix
(Entry_Name
));
1241 Error_Msg_N
("invalid entry_name specified", N
);
1245 -- If we had a requeue of the form REQUEUE A (B), then the parser
1246 -- accepted it (because it could have been a requeue on an entry
1247 -- index. If A turns out not to be an entry family, then the analysis
1248 -- of A (B) turned it into a function call.
1250 elsif Nkind
(Entry_Name
) = N_Function_Call
then
1252 ("arguments not allowed in requeue statement",
1253 First
(Parameter_Associations
(Entry_Name
)));
1256 -- Normal case of no entry family, no argument
1259 Entry_Id
:= Entity
(Entry_Name
);
1262 -- Resolve entry, and check that it is subtype conformant with the
1263 -- enclosing construct if this construct has formals (RM 9.5.4(5)).
1265 if not Is_Entry
(Entry_Id
) then
1266 Error_Msg_N
("expect entry name in requeue statement", Name
(N
));
1267 elsif Ekind
(Entry_Id
) = E_Entry_Family
1268 and then Nkind
(Entry_Name
) /= N_Indexed_Component
1270 Error_Msg_N
("missing index for entry family component", Name
(N
));
1273 Resolve_Entry
(Name
(N
));
1274 Generate_Reference
(Entry_Id
, Entry_Name
);
1276 if Present
(First_Formal
(Entry_Id
)) then
1277 Check_Subtype_Conformant
(Enclosing
, Entry_Id
, Name
(N
));
1279 -- Processing for parameters accessed by the requeue
1282 Ent
: Entity_Id
:= First_Formal
(Enclosing
);
1285 while Present
(Ent
) loop
1287 -- For OUT or IN OUT parameter, the effect of the requeue
1288 -- is to assign the parameter a value on exit from the
1289 -- requeued body, so we can set it as source assigned.
1290 -- We also clear the Is_True_Constant indication. We do
1291 -- not need to clear Current_Value, since the effect of
1292 -- the requeue is to perform an unconditional goto so
1293 -- that any further references will not occur anyway.
1295 if Ekind
(Ent
) = E_Out_Parameter
1297 Ekind
(Ent
) = E_In_Out_Parameter
1299 Set_Never_Set_In_Source
(Ent
, False);
1300 Set_Is_True_Constant
(Ent
, False);
1303 -- For all parameters, the requeue acts as a reference,
1304 -- since the value of the parameter is passed to the
1305 -- new entry, so we want to suppress unreferenced warnings.
1307 Set_Referenced
(Ent
);
1313 end Analyze_Requeue
;
1315 ------------------------------
1316 -- Analyze_Selective_Accept --
1317 ------------------------------
1319 procedure Analyze_Selective_Accept
(N
: Node_Id
) is
1320 Alts
: constant List_Id
:= Select_Alternatives
(N
);
1323 Accept_Present
: Boolean := False;
1324 Terminate_Present
: Boolean := False;
1325 Delay_Present
: Boolean := False;
1326 Relative_Present
: Boolean := False;
1327 Alt_Count
: Uint
:= Uint_0
;
1330 Check_Restriction
(No_Select_Statements
, N
);
1331 Tasking_Used
:= True;
1333 Alt
:= First
(Alts
);
1334 while Present
(Alt
) loop
1335 Alt_Count
:= Alt_Count
+ 1;
1338 if Nkind
(Alt
) = N_Delay_Alternative
then
1339 if Delay_Present
then
1341 if Relative_Present
/=
1342 (Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
)
1345 ("delay_until and delay_relative alternatives ", Alt
);
1347 ("\cannot appear in the same selective_wait", Alt
);
1351 Delay_Present
:= True;
1353 Nkind
(Delay_Statement
(Alt
)) = N_Delay_Relative_Statement
;
1356 elsif Nkind
(Alt
) = N_Terminate_Alternative
then
1357 if Terminate_Present
then
1358 Error_Msg_N
("Only one terminate alternative allowed", N
);
1360 Terminate_Present
:= True;
1361 Check_Restriction
(No_Terminate_Alternatives
, N
);
1364 elsif Nkind
(Alt
) = N_Accept_Alternative
then
1365 Accept_Present
:= True;
1367 -- Check for duplicate accept
1371 Stm
: constant Node_Id
:= Accept_Statement
(Alt
);
1372 EDN
: constant Node_Id
:= Entry_Direct_Name
(Stm
);
1376 if Nkind
(EDN
) = N_Identifier
1377 and then No
(Condition
(Alt
))
1378 and then Present
(Entity
(EDN
)) -- defend against junk
1379 and then Ekind
(Entity
(EDN
)) = E_Entry
1381 Ent
:= Entity
(EDN
);
1383 Alt1
:= First
(Alts
);
1384 while Alt1
/= Alt
loop
1385 if Nkind
(Alt1
) = N_Accept_Alternative
1386 and then No
(Condition
(Alt1
))
1389 Stm1
: constant Node_Id
:= Accept_Statement
(Alt1
);
1390 EDN1
: constant Node_Id
:= Entry_Direct_Name
(Stm1
);
1393 if Nkind
(EDN1
) = N_Identifier
then
1394 if Entity
(EDN1
) = Ent
then
1395 Error_Msg_Sloc
:= Sloc
(Stm1
);
1397 ("?accept duplicates one on line#", Stm
);
1413 Check_Restriction
(Max_Select_Alternatives
, N
, Alt_Count
);
1414 Check_Potentially_Blocking_Operation
(N
);
1416 if Terminate_Present
and Delay_Present
then
1417 Error_Msg_N
("at most one of terminate or delay alternative", N
);
1419 elsif not Accept_Present
then
1421 ("select must contain at least one accept alternative", N
);
1424 if Present
(Else_Statements
(N
)) then
1425 if Terminate_Present
or Delay_Present
then
1426 Error_Msg_N
("else part not allowed with other alternatives", N
);
1429 Analyze_Statements
(Else_Statements
(N
));
1431 end Analyze_Selective_Accept
;
1433 ------------------------------
1434 -- Analyze_Single_Protected --
1435 ------------------------------
1437 procedure Analyze_Single_Protected
(N
: Node_Id
) is
1438 Loc
: constant Source_Ptr
:= Sloc
(N
);
1439 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1443 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1446 Generate_Definition
(Id
);
1447 Tasking_Used
:= True;
1449 -- The node is rewritten as a protected type declaration,
1450 -- in exact analogy with what is done with single tasks.
1453 Make_Defining_Identifier
(Sloc
(Id
),
1454 New_External_Name
(Chars
(Id
), 'T'));
1457 Make_Protected_Type_Declaration
(Loc
,
1458 Defining_Identifier
=> T
,
1459 Protected_Definition
=> Relocate_Node
(Protected_Definition
(N
)));
1462 Make_Object_Declaration
(Loc
,
1463 Defining_Identifier
=> O_Name
,
1464 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1466 Rewrite
(N
, T_Decl
);
1467 Insert_After
(N
, O_Decl
);
1468 Mark_Rewrite_Insertion
(O_Decl
);
1470 -- Enter names of type and object before analysis, because the name
1471 -- of the object may be used in its own body.
1474 Set_Ekind
(T
, E_Protected_Type
);
1477 Enter_Name
(O_Name
);
1478 Set_Ekind
(O_Name
, E_Variable
);
1479 Set_Etype
(O_Name
, T
);
1481 -- Instead of calling Analyze on the new node, call directly
1482 -- the proper analysis procedure. Otherwise the node would be
1483 -- expanded twice, with disastrous result.
1485 Analyze_Protected_Type
(N
);
1487 end Analyze_Single_Protected
;
1489 -------------------------
1490 -- Analyze_Single_Task --
1491 -------------------------
1493 procedure Analyze_Single_Task
(N
: Node_Id
) is
1494 Loc
: constant Source_Ptr
:= Sloc
(N
);
1495 Id
: constant Node_Id
:= Defining_Identifier
(N
);
1499 O_Name
: constant Entity_Id
:= New_Copy
(Id
);
1502 Generate_Definition
(Id
);
1503 Tasking_Used
:= True;
1505 -- The node is rewritten as a task type declaration, followed
1506 -- by an object declaration of that anonymous task type.
1509 Make_Defining_Identifier
(Sloc
(Id
),
1510 New_External_Name
(Chars
(Id
), Suffix
=> "TK"));
1513 Make_Task_Type_Declaration
(Loc
,
1514 Defining_Identifier
=> T
,
1515 Task_Definition
=> Relocate_Node
(Task_Definition
(N
)));
1518 Make_Object_Declaration
(Loc
,
1519 Defining_Identifier
=> O_Name
,
1520 Object_Definition
=> Make_Identifier
(Loc
, Chars
(T
)));
1522 Rewrite
(N
, T_Decl
);
1523 Insert_After
(N
, O_Decl
);
1524 Mark_Rewrite_Insertion
(O_Decl
);
1526 -- Enter names of type and object before analysis, because the name
1527 -- of the object may be used in its own body.
1530 Set_Ekind
(T
, E_Task_Type
);
1533 Enter_Name
(O_Name
);
1534 Set_Ekind
(O_Name
, E_Variable
);
1535 Set_Etype
(O_Name
, T
);
1537 -- Instead of calling Analyze on the new node, call directly
1538 -- the proper analysis procedure. Otherwise the node would be
1539 -- expanded twice, with disastrous result.
1541 Analyze_Task_Type
(N
);
1542 end Analyze_Single_Task
;
1544 -----------------------
1545 -- Analyze_Task_Body --
1546 -----------------------
1548 procedure Analyze_Task_Body
(N
: Node_Id
) is
1549 Body_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1552 Spec_Id
: Entity_Id
;
1553 -- This is initially the entity of the task or task type involved,
1554 -- but is replaced by the task type always in the case of a single
1555 -- task declaration, since this is the proper scope to be used.
1558 -- This is the entity of the task or task type, and is the entity
1559 -- used for cross-reference purposes (it differs from Spec_Id in
1560 -- the case of a single task, since Spec_Id is set to the task type)
1563 Tasking_Used
:= True;
1564 Set_Ekind
(Body_Id
, E_Task_Body
);
1565 Set_Scope
(Body_Id
, Current_Scope
);
1566 Spec_Id
:= Find_Concurrent_Spec
(Body_Id
);
1568 -- The spec is either a task type declaration, or a single task
1569 -- declaration for which we have created an anonymous type.
1571 if Present
(Spec_Id
)
1572 and then Ekind
(Spec_Id
) = E_Task_Type
1576 elsif Present
(Spec_Id
)
1577 and then Ekind
(Etype
(Spec_Id
)) = E_Task_Type
1578 and then not Comes_From_Source
(Etype
(Spec_Id
))
1583 Error_Msg_N
("missing specification for task body", Body_Id
);
1587 if Has_Completion
(Spec_Id
)
1588 and then Present
(Corresponding_Body
(Parent
(Spec_Id
)))
1590 if Nkind
(Parent
(Spec_Id
)) = N_Task_Type_Declaration
then
1591 Error_Msg_NE
("duplicate body for task type&", N
, Spec_Id
);
1594 Error_Msg_NE
("duplicate body for task&", N
, Spec_Id
);
1599 Generate_Reference
(Ref_Id
, Body_Id
, 'b', Set_Ref
=> False);
1600 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1602 -- Deal with case of body of single task (anonymous type was created)
1604 if Ekind
(Spec_Id
) = E_Variable
then
1605 Spec_Id
:= Etype
(Spec_Id
);
1608 New_Scope
(Spec_Id
);
1609 Set_Corresponding_Spec
(N
, Spec_Id
);
1610 Set_Corresponding_Body
(Parent
(Spec_Id
), Body_Id
);
1611 Set_Has_Completion
(Spec_Id
);
1612 Install_Declarations
(Spec_Id
);
1613 Last_E
:= Last_Entity
(Spec_Id
);
1615 Analyze_Declarations
(Declarations
(N
));
1617 -- For visibility purposes, all entities in the body are private.
1618 -- Set First_Private_Entity accordingly, if there was no private
1619 -- part in the protected declaration.
1621 if No
(First_Private_Entity
(Spec_Id
)) then
1622 if Present
(Last_E
) then
1623 Set_First_Private_Entity
(Spec_Id
, Next_Entity
(Last_E
));
1625 Set_First_Private_Entity
(Spec_Id
, First_Entity
(Spec_Id
));
1629 Analyze
(Handled_Statement_Sequence
(N
));
1630 Check_Completion
(Body_Id
);
1631 Check_References
(Body_Id
);
1632 Check_References
(Spec_Id
);
1634 -- Check for entries with no corresponding accept
1640 Ent
:= First_Entity
(Spec_Id
);
1642 while Present
(Ent
) loop
1644 and then not Entry_Accepted
(Ent
)
1645 and then Comes_From_Source
(Ent
)
1647 Error_Msg_NE
("no accept for entry &?", N
, Ent
);
1654 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Ref_Id
);
1656 end Analyze_Task_Body
;
1658 -----------------------------
1659 -- Analyze_Task_Definition --
1660 -----------------------------
1662 procedure Analyze_Task_Definition
(N
: Node_Id
) is
1666 Tasking_Used
:= True;
1668 if Present
(Visible_Declarations
(N
)) then
1669 Analyze_Declarations
(Visible_Declarations
(N
));
1672 if Present
(Private_Declarations
(N
)) then
1673 L
:= Last_Entity
(Current_Scope
);
1674 Analyze_Declarations
(Private_Declarations
(N
));
1677 Set_First_Private_Entity
1678 (Current_Scope
, Next_Entity
(L
));
1680 Set_First_Private_Entity
1681 (Current_Scope
, First_Entity
(Current_Scope
));
1685 Check_Max_Entries
(N
, Max_Task_Entries
);
1686 Process_End_Label
(N
, 'e', Current_Scope
);
1687 end Analyze_Task_Definition
;
1689 -----------------------
1690 -- Analyze_Task_Type --
1691 -----------------------
1693 procedure Analyze_Task_Type
(N
: Node_Id
) is
1695 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1698 Check_Restriction
(No_Tasking
, N
);
1699 Tasking_Used
:= True;
1700 T
:= Find_Type_Name
(N
);
1701 Generate_Definition
(T
);
1703 if Ekind
(T
) = E_Incomplete_Type
then
1705 Set_Completion_Referenced
(T
);
1708 Set_Ekind
(T
, E_Task_Type
);
1709 Set_Is_First_Subtype
(T
, True);
1710 Set_Has_Task
(T
, True);
1711 Init_Size_Align
(T
);
1713 Set_Has_Delayed_Freeze
(T
, True);
1714 Set_Stored_Constraint
(T
, No_Elist
);
1717 if Present
(Discriminant_Specifications
(N
)) then
1718 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1719 Error_Msg_N
("(Ada 83) task discriminant not allowed!", N
);
1722 if Has_Discriminants
(T
) then
1724 -- Install discriminants. Also, verify conformance of
1725 -- discriminants of previous and current view. ???
1727 Install_Declarations
(T
);
1729 Process_Discriminants
(N
);
1733 if Present
(Task_Definition
(N
)) then
1734 Analyze_Task_Definition
(Task_Definition
(N
));
1737 if not Is_Library_Level_Entity
(T
) then
1738 Check_Restriction
(No_Task_Hierarchy
, N
);
1744 and then Is_Private_Type
(Def_Id
)
1745 and then Has_Discriminants
(Def_Id
)
1746 and then Expander_Active
1748 Exp_Ch9
.Expand_N_Task_Type_Declaration
(N
);
1749 Process_Full_View
(N
, T
, Def_Id
);
1751 end Analyze_Task_Type
;
1753 -----------------------------------
1754 -- Analyze_Terminate_Alternative --
1755 -----------------------------------
1757 procedure Analyze_Terminate_Alternative
(N
: Node_Id
) is
1759 Tasking_Used
:= True;
1761 if Present
(Pragmas_Before
(N
)) then
1762 Analyze_List
(Pragmas_Before
(N
));
1765 if Present
(Condition
(N
)) then
1766 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
1768 end Analyze_Terminate_Alternative
;
1770 ------------------------------
1771 -- Analyze_Timed_Entry_Call --
1772 ------------------------------
1774 procedure Analyze_Timed_Entry_Call
(N
: Node_Id
) is
1776 Check_Restriction
(No_Select_Statements
, N
);
1777 Tasking_Used
:= True;
1778 Analyze
(Entry_Call_Alternative
(N
));
1779 Analyze
(Delay_Alternative
(N
));
1780 end Analyze_Timed_Entry_Call
;
1782 ------------------------------------
1783 -- Analyze_Triggering_Alternative --
1784 ------------------------------------
1786 procedure Analyze_Triggering_Alternative
(N
: Node_Id
) is
1787 Trigger
: constant Node_Id
:= Triggering_Statement
(N
);
1790 Tasking_Used
:= True;
1792 if Present
(Pragmas_Before
(N
)) then
1793 Analyze_List
(Pragmas_Before
(N
));
1797 if Comes_From_Source
(Trigger
)
1798 and then Nkind
(Trigger
) /= N_Delay_Until_Statement
1799 and then Nkind
(Trigger
) /= N_Delay_Relative_Statement
1800 and then Nkind
(Trigger
) /= N_Entry_Call_Statement
1803 ("triggering statement must be delay or entry call", Trigger
);
1806 if Is_Non_Empty_List
(Statements
(N
)) then
1807 Analyze_Statements
(Statements
(N
));
1809 end Analyze_Triggering_Alternative
;
1811 -----------------------
1812 -- Check_Max_Entries --
1813 -----------------------
1815 procedure Check_Max_Entries
(D
: Node_Id
; R
: All_Parameter_Restrictions
) is
1818 procedure Count
(L
: List_Id
);
1819 -- Count entries in given declaration list
1825 procedure Count
(L
: List_Id
) is
1834 while Present
(D
) loop
1835 if Nkind
(D
) = N_Entry_Declaration
then
1837 DSD
: constant Node_Id
:=
1838 Discrete_Subtype_Definition
(D
);
1841 -- If not an entry family, then just one entry
1844 Ecount
:= Ecount
+ 1;
1846 -- If entry family with static bounds, count entries
1848 elsif Is_OK_Static_Subtype
(Etype
(DSD
)) then
1850 Lo
: constant Uint
:=
1852 (Type_Low_Bound
(Etype
(DSD
)));
1853 Hi
: constant Uint
:=
1855 (Type_High_Bound
(Etype
(DSD
)));
1859 Ecount
:= Ecount
+ Hi
- Lo
+ 1;
1863 -- Entry family with non-static bounds
1866 -- If restriction is set, then this is an error
1868 if Restrictions
.Set
(R
) then
1870 ("static subtype required by Restriction pragma",
1873 -- Otherwise we record an unknown count restriction
1876 Check_Restriction
(R
, D
);
1886 -- Start of processing for Check_Max_Entries
1890 Count
(Visible_Declarations
(D
));
1891 Count
(Private_Declarations
(D
));
1894 Check_Restriction
(R
, D
, Ecount
);
1896 end Check_Max_Entries
;
1898 --------------------------
1899 -- Find_Concurrent_Spec --
1900 --------------------------
1902 function Find_Concurrent_Spec
(Body_Id
: Entity_Id
) return Entity_Id
is
1903 Spec_Id
: Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
1906 -- The type may have been given by an incomplete type declaration.
1907 -- Find full view now.
1909 if Present
(Spec_Id
) and then Ekind
(Spec_Id
) = E_Incomplete_Type
then
1910 Spec_Id
:= Full_View
(Spec_Id
);
1914 end Find_Concurrent_Spec
;
1916 --------------------------
1917 -- Install_Declarations --
1918 --------------------------
1920 procedure Install_Declarations
(Spec
: Entity_Id
) is
1925 E
:= First_Entity
(Spec
);
1927 while Present
(E
) loop
1928 Prev
:= Current_Entity
(E
);
1929 Set_Current_Entity
(E
);
1930 Set_Is_Immediately_Visible
(E
);
1931 Set_Homonym
(E
, Prev
);
1934 end Install_Declarations
;