1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Errout; use Errout;
30 with Expander; use Expander;
31 with Exp_Util; use Exp_Util;
32 with Freeze; use Freeze;
34 with Lib.Xref; use Lib.Xref;
35 with Namet; use Namet;
36 with Nlists; use Nlists;
37 with Nmake; use Nmake;
39 with Restrict; use Restrict;
40 with Rident; use Rident;
41 with Rtsfind; use Rtsfind;
43 with Sem_Aux; use Sem_Aux;
44 with Sem_Case; use Sem_Case;
45 with Sem_Ch3; use Sem_Ch3;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Disp; use Sem_Disp;
48 with Sem_Elab; use Sem_Elab;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sem_Util; use Sem_Util;
53 with Sem_Warn; use Sem_Warn;
54 with Snames; use Snames;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Uintp; use Uintp;
61 package body Sem_Ch5 is
63 Unblocked_Exit_Count : Nat := 0;
64 -- This variable is used when processing if statements, case statements,
65 -- and block statements. It counts the number of exit points that are not
66 -- blocked by unconditional transfer instructions: for IF and CASE, these
67 -- are the branches of the conditional; for a block, they are the statement
68 -- sequence of the block, and the statement sequences of any exception
69 -- handlers that are part of the block. When processing is complete, if
70 -- this count is zero, it means that control cannot fall through the IF,
71 -- CASE or block statement. This is used for the generation of warning
72 -- messages. This variable is recursively saved on entry to processing the
73 -- construct, and restored on exit.
75 ------------------------
76 -- Analyze_Assignment --
77 ------------------------
79 procedure Analyze_Assignment (N : Node_Id) is
80 Lhs : constant Node_Id := Name (N);
81 Rhs : constant Node_Id := Expression (N);
86 procedure Diagnose_Non_Variable_Lhs (N : Node_Id);
87 -- N is the node for the left hand side of an assignment, and it is not
88 -- a variable. This routine issues an appropriate diagnostic.
91 -- This is called to kill current value settings of a simple variable
92 -- on the left hand side. We call it if we find any error in analyzing
93 -- the assignment, and at the end of processing before setting any new
94 -- current values in place.
96 procedure Set_Assignment_Type
98 Opnd_Type : in out Entity_Id);
99 -- Opnd is either the Lhs or Rhs of the assignment, and Opnd_Type is the
100 -- nominal subtype. This procedure is used to deal with cases where the
101 -- nominal subtype must be replaced by the actual subtype.
103 -------------------------------
104 -- Diagnose_Non_Variable_Lhs --
105 -------------------------------
107 procedure Diagnose_Non_Variable_Lhs (N : Node_Id) is
109 -- Not worth posting another error if left hand side already flagged
110 -- as being illegal in some respect.
112 if Error_Posted (N) then
115 -- Some special bad cases of entity names
117 elsif Is_Entity_Name (N) then
119 Ent : constant Entity_Id := Entity (N);
122 if Ekind (Ent) = E_In_Parameter then
124 ("assignment to IN mode parameter not allowed", N);
126 -- Renamings of protected private components are turned into
127 -- constants when compiling a protected function. In the case
128 -- of single protected types, the private component appears
131 elsif (Is_Prival (Ent)
133 (Ekind (Current_Scope) = E_Function
134 or else Ekind (Enclosing_Dynamic_Scope
135 (Current_Scope)) = E_Function))
137 (Ekind (Ent) = E_Component
138 and then Is_Protected_Type (Scope (Ent)))
141 ("protected function cannot modify protected object", N);
143 elsif Ekind (Ent) = E_Loop_Parameter then
145 ("assignment to loop parameter not allowed", N);
149 ("left hand side of assignment must be a variable", N);
153 -- For indexed components or selected components, test prefix
155 elsif Nkind (N) = N_Indexed_Component then
156 Diagnose_Non_Variable_Lhs (Prefix (N));
158 -- Another special case for assignment to discriminant
160 elsif Nkind (N) = N_Selected_Component then
161 if Present (Entity (Selector_Name (N)))
162 and then Ekind (Entity (Selector_Name (N))) = E_Discriminant
165 ("assignment to discriminant not allowed", N);
167 Diagnose_Non_Variable_Lhs (Prefix (N));
171 -- If we fall through, we have no special message to issue!
173 Error_Msg_N ("left hand side of assignment must be a variable", N);
175 end Diagnose_Non_Variable_Lhs;
181 procedure Kill_Lhs is
183 if Is_Entity_Name (Lhs) then
185 Ent : constant Entity_Id := Entity (Lhs);
187 if Present (Ent) then
188 Kill_Current_Values (Ent);
194 -------------------------
195 -- Set_Assignment_Type --
196 -------------------------
198 procedure Set_Assignment_Type
200 Opnd_Type : in out Entity_Id)
203 Require_Entity (Opnd);
205 -- If the assignment operand is an in-out or out parameter, then we
206 -- get the actual subtype (needed for the unconstrained case). If the
207 -- operand is the actual in an entry declaration, then within the
208 -- accept statement it is replaced with a local renaming, which may
209 -- also have an actual subtype.
211 if Is_Entity_Name (Opnd)
212 and then (Ekind (Entity (Opnd)) = E_Out_Parameter
213 or else Ekind (Entity (Opnd)) =
215 or else Ekind (Entity (Opnd)) =
216 E_Generic_In_Out_Parameter
218 (Ekind (Entity (Opnd)) = E_Variable
219 and then Nkind (Parent (Entity (Opnd))) =
220 N_Object_Renaming_Declaration
221 and then Nkind (Parent (Parent (Entity (Opnd)))) =
224 Opnd_Type := Get_Actual_Subtype (Opnd);
226 -- If assignment operand is a component reference, then we get the
227 -- actual subtype of the component for the unconstrained case.
229 elsif Nkind_In (Opnd, N_Selected_Component, N_Explicit_Dereference)
230 and then not Is_Unchecked_Union (Opnd_Type)
232 Decl := Build_Actual_Subtype_Of_Component (Opnd_Type, Opnd);
234 if Present (Decl) then
235 Insert_Action (N, Decl);
236 Mark_Rewrite_Insertion (Decl);
238 Opnd_Type := Defining_Identifier (Decl);
239 Set_Etype (Opnd, Opnd_Type);
240 Freeze_Itype (Opnd_Type, N);
242 elsif Is_Constrained (Etype (Opnd)) then
243 Opnd_Type := Etype (Opnd);
246 -- For slice, use the constrained subtype created for the slice
248 elsif Nkind (Opnd) = N_Slice then
249 Opnd_Type := Etype (Opnd);
251 end Set_Assignment_Type;
253 -- Start of processing for Analyze_Assignment
256 Mark_Coextensions (N, Rhs);
261 -- Ensure that we never do an assignment on a variable marked as
262 -- as Safe_To_Reevaluate.
264 pragma Assert (not Is_Entity_Name (Lhs)
265 or else Ekind (Entity (Lhs)) /= E_Variable
266 or else not Is_Safe_To_Reevaluate (Entity (Lhs)));
268 -- Start type analysis for assignment
272 -- In the most general case, both Lhs and Rhs can be overloaded, and we
273 -- must compute the intersection of the possible types on each side.
275 if Is_Overloaded (Lhs) then
282 Get_First_Interp (Lhs, I, It);
284 while Present (It.Typ) loop
285 if Has_Compatible_Type (Rhs, It.Typ) then
286 if T1 /= Any_Type then
288 -- An explicit dereference is overloaded if the prefix
289 -- is. Try to remove the ambiguity on the prefix, the
290 -- error will be posted there if the ambiguity is real.
292 if Nkind (Lhs) = N_Explicit_Dereference then
295 PI1 : Interp_Index := 0;
301 Get_First_Interp (Prefix (Lhs), PI, PIt);
303 while Present (PIt.Typ) loop
304 if Is_Access_Type (PIt.Typ)
305 and then Has_Compatible_Type
306 (Rhs, Designated_Type (PIt.Typ))
310 Disambiguate (Prefix (Lhs),
313 if PIt = No_Interp then
315 ("ambiguous left-hand side"
316 & " in assignment", Lhs);
319 Resolve (Prefix (Lhs), PIt.Typ);
329 Get_Next_Interp (PI, PIt);
335 ("ambiguous left-hand side in assignment", Lhs);
343 Get_Next_Interp (I, It);
347 if T1 = Any_Type then
349 ("no valid types for left-hand side for assignment", Lhs);
355 -- The resulting assignment type is T1, so now we will resolve the left
356 -- hand side of the assignment using this determined type.
360 -- Cases where Lhs is not a variable
362 if not Is_Variable (Lhs) then
364 -- Ada 2005 (AI-327): Check assignment to the attribute Priority of a
372 if Ada_Version >= Ada_2005 then
374 -- Handle chains of renamings
377 while Nkind (Ent) in N_Has_Entity
378 and then Present (Entity (Ent))
379 and then Present (Renamed_Object (Entity (Ent)))
381 Ent := Renamed_Object (Entity (Ent));
384 if (Nkind (Ent) = N_Attribute_Reference
385 and then Attribute_Name (Ent) = Name_Priority)
387 -- Renamings of the attribute Priority applied to protected
388 -- objects have been previously expanded into calls to the
389 -- Get_Ceiling run-time subprogram.
392 (Nkind (Ent) = N_Function_Call
393 and then (Entity (Name (Ent)) = RTE (RE_Get_Ceiling)
395 Entity (Name (Ent)) = RTE (RO_PE_Get_Ceiling)))
397 -- The enclosing subprogram cannot be a protected function
400 while not (Is_Subprogram (S)
401 and then Convention (S) = Convention_Protected)
402 and then S /= Standard_Standard
407 if Ekind (S) = E_Function
408 and then Convention (S) = Convention_Protected
411 ("protected function cannot modify protected object",
415 -- Changes of the ceiling priority of the protected object
416 -- are only effective if the Ceiling_Locking policy is in
417 -- effect (AARM D.5.2 (5/2)).
419 if Locking_Policy /= 'C' then
420 Error_Msg_N ("assignment to the attribute PRIORITY has " &
422 Error_Msg_N ("\since no Locking_Policy has been " &
431 Diagnose_Non_Variable_Lhs (Lhs);
434 -- Error of assigning to limited type. We do however allow this in
435 -- certain cases where the front end generates the assignments.
437 elsif Is_Limited_Type (T1)
438 and then not Assignment_OK (Lhs)
439 and then not Assignment_OK (Original_Node (Lhs))
440 and then not Is_Value_Type (T1)
442 -- CPP constructors can only be called in declarations
444 if Is_CPP_Constructor_Call (Rhs) then
445 Error_Msg_N ("invalid use of 'C'P'P constructor", Rhs);
448 ("left hand of assignment must not be limited type", Lhs);
449 Explain_Limited_Type (T1, Lhs);
453 -- Enforce RM 3.9.3 (8): the target of an assignment operation cannot be
454 -- abstract. This is only checked when the assignment Comes_From_Source,
455 -- because in some cases the expander generates such assignments (such
456 -- in the _assign operation for an abstract type).
458 elsif Is_Abstract_Type (T1) and then Comes_From_Source (N) then
460 ("target of assignment operation must not be abstract", Lhs);
463 -- Resolution may have updated the subtype, in case the left-hand side
464 -- is a private protected component. Use the correct subtype to avoid
465 -- scoping issues in the back-end.
469 -- Ada 2005 (AI-50217, AI-326): Check wrong dereference of incomplete
470 -- type. For example:
474 -- type Acc is access P.T;
477 -- with Pkg; use Acc;
478 -- procedure Example is
481 -- A.all := B.all; -- ERROR
484 if Nkind (Lhs) = N_Explicit_Dereference
485 and then Ekind (T1) = E_Incomplete_Type
487 Error_Msg_N ("invalid use of incomplete type", Lhs);
492 -- Now we can complete the resolution of the right hand side
494 Set_Assignment_Type (Lhs, T1);
497 -- This is the point at which we check for an unset reference
499 Check_Unset_Reference (Rhs);
500 Check_Unprotected_Access (Lhs, Rhs);
502 -- Remaining steps are skipped if Rhs was syntactically in error
511 if not Covers (T1, T2) then
512 Wrong_Type (Rhs, Etype (Lhs));
517 -- Ada 2005 (AI-326): In case of explicit dereference of incomplete
518 -- types, use the non-limited view if available
520 if Nkind (Rhs) = N_Explicit_Dereference
521 and then Ekind (T2) = E_Incomplete_Type
522 and then Is_Tagged_Type (T2)
523 and then Present (Non_Limited_View (T2))
525 T2 := Non_Limited_View (T2);
528 Set_Assignment_Type (Rhs, T2);
530 if Total_Errors_Detected /= 0 then
540 if T1 = Any_Type or else T2 = Any_Type then
545 -- If the rhs is class-wide or dynamically tagged, then require the lhs
546 -- to be class-wide. The case where the rhs is a dynamically tagged call
547 -- to a dispatching operation with a controlling access result is
548 -- excluded from this check, since the target has an access type (and
549 -- no tag propagation occurs in that case).
551 if (Is_Class_Wide_Type (T2)
552 or else (Is_Dynamically_Tagged (Rhs)
553 and then not Is_Access_Type (T1)))
554 and then not Is_Class_Wide_Type (T1)
556 Error_Msg_N ("dynamically tagged expression not allowed!", Rhs);
558 elsif Is_Class_Wide_Type (T1)
559 and then not Is_Class_Wide_Type (T2)
560 and then not Is_Tag_Indeterminate (Rhs)
561 and then not Is_Dynamically_Tagged (Rhs)
563 Error_Msg_N ("dynamically tagged expression required!", Rhs);
566 -- Propagate the tag from a class-wide target to the rhs when the rhs
567 -- is a tag-indeterminate call.
569 if Is_Tag_Indeterminate (Rhs) then
570 if Is_Class_Wide_Type (T1) then
571 Propagate_Tag (Lhs, Rhs);
573 elsif Nkind (Rhs) = N_Function_Call
574 and then Is_Entity_Name (Name (Rhs))
575 and then Is_Abstract_Subprogram (Entity (Name (Rhs)))
578 ("call to abstract function must be dispatching", Name (Rhs));
580 elsif Nkind (Rhs) = N_Qualified_Expression
581 and then Nkind (Expression (Rhs)) = N_Function_Call
582 and then Is_Entity_Name (Name (Expression (Rhs)))
584 Is_Abstract_Subprogram (Entity (Name (Expression (Rhs))))
587 ("call to abstract function must be dispatching",
588 Name (Expression (Rhs)));
592 -- Ada 2005 (AI-385): When the lhs type is an anonymous access type,
593 -- apply an implicit conversion of the rhs to that type to force
594 -- appropriate static and run-time accessibility checks. This applies
595 -- as well to anonymous access-to-subprogram types that are component
596 -- subtypes or formal parameters.
598 if Ada_Version >= Ada_2005
599 and then Is_Access_Type (T1)
601 if Is_Local_Anonymous_Access (T1)
602 or else Ekind (T2) = E_Anonymous_Access_Subprogram_Type
604 Rewrite (Rhs, Convert_To (T1, Relocate_Node (Rhs)));
605 Analyze_And_Resolve (Rhs, T1);
609 -- Ada 2005 (AI-231): Assignment to not null variable
611 if Ada_Version >= Ada_2005
612 and then Can_Never_Be_Null (T1)
613 and then not Assignment_OK (Lhs)
615 -- Case where we know the right hand side is null
617 if Known_Null (Rhs) then
618 Apply_Compile_Time_Constraint_Error
620 Msg => "(Ada 2005) null not allowed in null-excluding objects?",
621 Reason => CE_Null_Not_Allowed);
623 -- We still mark this as a possible modification, that's necessary
624 -- to reset Is_True_Constant, and desirable for xref purposes.
626 Note_Possible_Modification (Lhs, Sure => True);
629 -- If we know the right hand side is non-null, then we convert to the
630 -- target type, since we don't need a run time check in that case.
632 elsif not Can_Never_Be_Null (T2) then
633 Rewrite (Rhs, Convert_To (T1, Relocate_Node (Rhs)));
634 Analyze_And_Resolve (Rhs, T1);
638 if Is_Scalar_Type (T1) then
639 Apply_Scalar_Range_Check (Rhs, Etype (Lhs));
641 -- For array types, verify that lengths match. If the right hand side
642 -- is a function call that has been inlined, the assignment has been
643 -- rewritten as a block, and the constraint check will be applied to the
644 -- assignment within the block.
646 elsif Is_Array_Type (T1)
648 (Nkind (Rhs) /= N_Type_Conversion
649 or else Is_Constrained (Etype (Rhs)))
651 (Nkind (Rhs) /= N_Function_Call
652 or else Nkind (N) /= N_Block_Statement)
654 -- Assignment verifies that the length of the Lsh and Rhs are equal,
655 -- but of course the indexes do not have to match. If the right-hand
656 -- side is a type conversion to an unconstrained type, a length check
657 -- is performed on the expression itself during expansion. In rare
658 -- cases, the redundant length check is computed on an index type
659 -- with a different representation, triggering incorrect code in the
662 Apply_Length_Check (Rhs, Etype (Lhs));
665 -- Discriminant checks are applied in the course of expansion
670 -- Note: modifications of the Lhs may only be recorded after
671 -- checks have been applied.
673 Note_Possible_Modification (Lhs, Sure => True);
674 Check_Order_Dependence;
676 -- ??? a real accessibility check is needed when ???
678 -- Post warning for redundant assignment or variable to itself
680 if Warn_On_Redundant_Constructs
682 -- We only warn for source constructs
684 and then Comes_From_Source (N)
686 -- Where the object is the same on both sides
688 and then Same_Object (Lhs, Original_Node (Rhs))
690 -- But exclude the case where the right side was an operation that
691 -- got rewritten (e.g. JUNK + K, where K was known to be zero). We
692 -- don't want to warn in such a case, since it is reasonable to write
693 -- such expressions especially when K is defined symbolically in some
696 and then Nkind (Original_Node (Rhs)) not in N_Op
698 if Nkind (Lhs) in N_Has_Entity then
699 Error_Msg_NE -- CODEFIX
700 ("?useless assignment of & to itself!", N, Entity (Lhs));
702 Error_Msg_N -- CODEFIX
703 ("?useless assignment of object to itself!", N);
707 -- Check for non-allowed composite assignment
709 if not Support_Composite_Assign_On_Target
710 and then (Is_Array_Type (T1) or else Is_Record_Type (T1))
711 and then (not Has_Size_Clause (T1) or else Esize (T1) > 64)
713 Error_Msg_CRT ("composite assignment", N);
716 -- Check elaboration warning for left side if not in elab code
718 if not In_Subprogram_Or_Concurrent_Unit then
719 Check_Elab_Assign (Lhs);
722 -- Set Referenced_As_LHS if appropriate. We only set this flag if the
723 -- assignment is a source assignment in the extended main source unit.
724 -- We are not interested in any reference information outside this
725 -- context, or in compiler generated assignment statements.
727 if Comes_From_Source (N)
728 and then In_Extended_Main_Source_Unit (Lhs)
730 Set_Referenced_Modified (Lhs, Out_Param => False);
733 -- Final step. If left side is an entity, then we may be able to reset
734 -- the current tracked values to new safe values. We only have something
735 -- to do if the left side is an entity name, and expansion has not
736 -- modified the node into something other than an assignment, and of
737 -- course we only capture values if it is safe to do so.
739 if Is_Entity_Name (Lhs)
740 and then Nkind (N) = N_Assignment_Statement
743 Ent : constant Entity_Id := Entity (Lhs);
746 if Safe_To_Capture_Value (N, Ent) then
748 -- If simple variable on left side, warn if this assignment
749 -- blots out another one (rendering it useless) and note
750 -- location of assignment in case no one references value. We
751 -- only do this for source assignments, otherwise we can
752 -- generate bogus warnings when an assignment is rewritten as
753 -- another assignment, and gets tied up with itself.
755 -- Note: we don't use Record_Last_Assignment here, because we
756 -- have lots of other stuff to do under control of this test.
758 if Warn_On_Modified_Unread
759 and then Is_Assignable (Ent)
760 and then Comes_From_Source (N)
761 and then In_Extended_Main_Source_Unit (Ent)
763 Warn_On_Useless_Assignment (Ent, N);
764 Set_Last_Assignment (Ent, Lhs);
767 -- If we are assigning an access type and the left side is an
768 -- entity, then make sure that the Is_Known_[Non_]Null flags
769 -- properly reflect the state of the entity after assignment.
771 if Is_Access_Type (T1) then
772 if Known_Non_Null (Rhs) then
773 Set_Is_Known_Non_Null (Ent, True);
775 elsif Known_Null (Rhs)
776 and then not Can_Never_Be_Null (Ent)
778 Set_Is_Known_Null (Ent, True);
781 Set_Is_Known_Null (Ent, False);
783 if not Can_Never_Be_Null (Ent) then
784 Set_Is_Known_Non_Null (Ent, False);
788 -- For discrete types, we may be able to set the current value
789 -- if the value is known at compile time.
791 elsif Is_Discrete_Type (T1)
792 and then Compile_Time_Known_Value (Rhs)
794 Set_Current_Value (Ent, Rhs);
796 Set_Current_Value (Ent, Empty);
799 -- If not safe to capture values, kill them
806 end Analyze_Assignment;
808 -----------------------------
809 -- Analyze_Block_Statement --
810 -----------------------------
812 procedure Analyze_Block_Statement (N : Node_Id) is
813 Decls : constant List_Id := Declarations (N);
814 Id : constant Node_Id := Identifier (N);
815 HSS : constant Node_Id := Handled_Statement_Sequence (N);
818 -- In formal mode, we reject block statements. Note that the case of
819 -- block statements generated by the expander is fine.
821 if Nkind (Original_Node (N)) = N_Block_Statement then
822 Check_Formal_Restriction ("block statement is not allowed", N);
825 -- If no handled statement sequence is present, things are really messed
826 -- up, and we just return immediately (defence against previous errors).
832 -- Normal processing with HSS present
835 EH : constant List_Id := Exception_Handlers (HSS);
836 Ent : Entity_Id := Empty;
839 Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count;
840 -- Recursively save value of this global, will be restored on exit
843 -- Initialize unblocked exit count for statements of begin block
844 -- plus one for each exception handler that is present.
846 Unblocked_Exit_Count := 1;
849 Unblocked_Exit_Count := Unblocked_Exit_Count + List_Length (EH);
852 -- If a label is present analyze it and mark it as referenced
858 -- An error defense. If we have an identifier, but no entity, then
859 -- something is wrong. If previous errors, then just remove the
860 -- identifier and continue, otherwise raise an exception.
863 if Total_Errors_Detected /= 0 then
864 Set_Identifier (N, Empty);
870 Set_Ekind (Ent, E_Block);
871 Generate_Reference (Ent, N, ' ');
872 Generate_Definition (Ent);
874 if Nkind (Parent (Ent)) = N_Implicit_Label_Declaration then
875 Set_Label_Construct (Parent (Ent), N);
880 -- If no entity set, create a label entity
883 Ent := New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B');
884 Set_Identifier (N, New_Occurrence_Of (Ent, Sloc (N)));
888 Set_Etype (Ent, Standard_Void_Type);
889 Set_Block_Node (Ent, Identifier (N));
892 if Present (Decls) then
893 Analyze_Declarations (Decls);
895 Inspect_Deferred_Constant_Completion (Decls);
899 Process_End_Label (HSS, 'e', Ent);
901 -- If exception handlers are present, then we indicate that enclosing
902 -- scopes contain a block with handlers. We only need to mark non-
908 Set_Has_Nested_Block_With_Handler (S);
909 exit when Is_Overloadable (S)
910 or else Ekind (S) = E_Package
911 or else Is_Generic_Unit (S);
916 Check_References (Ent);
917 Warn_On_Useless_Assignments (Ent);
920 if Unblocked_Exit_Count = 0 then
921 Unblocked_Exit_Count := Save_Unblocked_Exit_Count;
922 Check_Unreachable_Code (N);
924 Unblocked_Exit_Count := Save_Unblocked_Exit_Count;
927 end Analyze_Block_Statement;
929 ----------------------------
930 -- Analyze_Case_Statement --
931 ----------------------------
933 procedure Analyze_Case_Statement (N : Node_Id) is
935 Exp_Type : Entity_Id;
936 Exp_Btype : Entity_Id;
939 Others_Present : Boolean;
941 pragma Warnings (Off, Last_Choice);
942 pragma Warnings (Off, Dont_Care);
943 -- Don't care about assigned values
945 Statements_Analyzed : Boolean := False;
946 -- Set True if at least some statement sequences get analyzed. If False
947 -- on exit, means we had a serious error that prevented full analysis of
948 -- the case statement, and as a result it is not a good idea to output
949 -- warning messages about unreachable code.
951 Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count;
952 -- Recursively save value of this global, will be restored on exit
954 procedure Non_Static_Choice_Error (Choice : Node_Id);
955 -- Error routine invoked by the generic instantiation below when the
956 -- case statement has a non static choice.
958 procedure Process_Statements (Alternative : Node_Id);
959 -- Analyzes all the statements associated with a case alternative.
960 -- Needed by the generic instantiation below.
962 package Case_Choices_Processing is new
963 Generic_Choices_Processing
964 (Get_Alternatives => Alternatives,
965 Get_Choices => Discrete_Choices,
966 Process_Empty_Choice => No_OP,
967 Process_Non_Static_Choice => Non_Static_Choice_Error,
968 Process_Associated_Node => Process_Statements);
969 use Case_Choices_Processing;
970 -- Instantiation of the generic choice processing package
972 -----------------------------
973 -- Non_Static_Choice_Error --
974 -----------------------------
976 procedure Non_Static_Choice_Error (Choice : Node_Id) is
979 ("choice given in case statement is not static!", Choice);
980 end Non_Static_Choice_Error;
982 ------------------------
983 -- Process_Statements --
984 ------------------------
986 procedure Process_Statements (Alternative : Node_Id) is
987 Choices : constant List_Id := Discrete_Choices (Alternative);
991 Unblocked_Exit_Count := Unblocked_Exit_Count + 1;
992 Statements_Analyzed := True;
994 -- An interesting optimization. If the case statement expression
995 -- is a simple entity, then we can set the current value within an
996 -- alternative if the alternative has one possible value.
1000 -- when 2 | 3 => beta
1001 -- when others => gamma
1003 -- Here we know that N is initially 1 within alpha, but for beta and
1004 -- gamma, we do not know anything more about the initial value.
1006 if Is_Entity_Name (Exp) then
1007 Ent := Entity (Exp);
1009 if Ekind_In (Ent, E_Variable,
1013 if List_Length (Choices) = 1
1014 and then Nkind (First (Choices)) in N_Subexpr
1015 and then Compile_Time_Known_Value (First (Choices))
1017 Set_Current_Value (Entity (Exp), First (Choices));
1020 Analyze_Statements (Statements (Alternative));
1022 -- After analyzing the case, set the current value to empty
1023 -- since we won't know what it is for the next alternative
1024 -- (unless reset by this same circuit), or after the case.
1026 Set_Current_Value (Entity (Exp), Empty);
1031 -- Case where expression is not an entity name of a variable
1033 Analyze_Statements (Statements (Alternative));
1034 end Process_Statements;
1036 -- Start of processing for Analyze_Case_Statement
1039 Unblocked_Exit_Count := 0;
1040 Exp := Expression (N);
1043 -- The expression must be of any discrete type. In rare cases, the
1044 -- expander constructs a case statement whose expression has a private
1045 -- type whose full view is discrete. This can happen when generating
1046 -- a stream operation for a variant type after the type is frozen,
1047 -- when the partial of view of the type of the discriminant is private.
1048 -- In that case, use the full view to analyze case alternatives.
1050 if not Is_Overloaded (Exp)
1051 and then not Comes_From_Source (N)
1052 and then Is_Private_Type (Etype (Exp))
1053 and then Present (Full_View (Etype (Exp)))
1054 and then Is_Discrete_Type (Full_View (Etype (Exp)))
1056 Resolve (Exp, Etype (Exp));
1057 Exp_Type := Full_View (Etype (Exp));
1060 Analyze_And_Resolve (Exp, Any_Discrete);
1061 Exp_Type := Etype (Exp);
1064 Check_Unset_Reference (Exp);
1065 Exp_Btype := Base_Type (Exp_Type);
1067 -- The expression must be of a discrete type which must be determinable
1068 -- independently of the context in which the expression occurs, but
1069 -- using the fact that the expression must be of a discrete type.
1070 -- Moreover, the type this expression must not be a character literal
1071 -- (which is always ambiguous) or, for Ada-83, a generic formal type.
1073 -- If error already reported by Resolve, nothing more to do
1075 if Exp_Btype = Any_Discrete
1076 or else Exp_Btype = Any_Type
1080 elsif Exp_Btype = Any_Character then
1082 ("character literal as case expression is ambiguous", Exp);
1085 elsif Ada_Version = Ada_83
1086 and then (Is_Generic_Type (Exp_Btype)
1087 or else Is_Generic_Type (Root_Type (Exp_Btype)))
1090 ("(Ada 83) case expression cannot be of a generic type", Exp);
1094 -- If the case expression is a formal object of mode in out, then treat
1095 -- it as having a nonstatic subtype by forcing use of the base type
1096 -- (which has to get passed to Check_Case_Choices below). Also use base
1097 -- type when the case expression is parenthesized.
1099 if Paren_Count (Exp) > 0
1100 or else (Is_Entity_Name (Exp)
1101 and then Ekind (Entity (Exp)) = E_Generic_In_Out_Parameter)
1103 Exp_Type := Exp_Btype;
1106 -- Call instantiated Analyze_Choices which does the rest of the work
1108 Analyze_Choices (N, Exp_Type, Dont_Care, Others_Present);
1110 -- A case statement with a single OTHERS alternative is not allowed
1111 -- in SPARK or ALFA.
1114 and then List_Length (Alternatives (N)) = 1
1116 Check_Formal_Restriction
1117 ("OTHERS as unique case alternative is not allowed", N);
1120 if Exp_Type = Universal_Integer and then not Others_Present then
1121 Error_Msg_N ("case on universal integer requires OTHERS choice", Exp);
1124 -- If all our exits were blocked by unconditional transfers of control,
1125 -- then the entire CASE statement acts as an unconditional transfer of
1126 -- control, so treat it like one, and check unreachable code. Skip this
1127 -- test if we had serious errors preventing any statement analysis.
1129 if Unblocked_Exit_Count = 0 and then Statements_Analyzed then
1130 Unblocked_Exit_Count := Save_Unblocked_Exit_Count;
1131 Check_Unreachable_Code (N);
1133 Unblocked_Exit_Count := Save_Unblocked_Exit_Count;
1136 if not Expander_Active
1137 and then Compile_Time_Known_Value (Expression (N))
1138 and then Serious_Errors_Detected = 0
1141 Chosen : constant Node_Id := Find_Static_Alternative (N);
1145 Alt := First (Alternatives (N));
1146 while Present (Alt) loop
1147 if Alt /= Chosen then
1148 Remove_Warning_Messages (Statements (Alt));
1155 end Analyze_Case_Statement;
1157 ----------------------------
1158 -- Analyze_Exit_Statement --
1159 ----------------------------
1161 -- If the exit includes a name, it must be the name of a currently open
1162 -- loop. Otherwise there must be an innermost open loop on the stack, to
1163 -- which the statement implicitly refers.
1165 -- Additionally, in formal mode:
1167 -- The exit can only name the closest enclosing loop;
1169 -- An exit with a when clause must be directly contained in a loop;
1171 -- An exit without a when clause must be directly contained in an
1172 -- if-statement with no elsif or else, which is itself directly contained
1173 -- in a loop. The exit must be the last statement in the if-statement.
1175 procedure Analyze_Exit_Statement (N : Node_Id) is
1176 Target : constant Node_Id := Name (N);
1177 Cond : constant Node_Id := Condition (N);
1178 Scope_Id : Entity_Id;
1184 Check_Unreachable_Code (N);
1187 if Present (Target) then
1189 U_Name := Entity (Target);
1191 if not In_Open_Scopes (U_Name) or else Ekind (U_Name) /= E_Loop then
1192 Error_Msg_N ("invalid loop name in exit statement", N);
1196 if Has_Loop_In_Inner_Open_Scopes (U_Name) then
1197 Check_Formal_Restriction
1198 ("exit label must name the closest enclosing loop", N);
1201 Set_Has_Exit (U_Name);
1208 for J in reverse 0 .. Scope_Stack.Last loop
1209 Scope_Id := Scope_Stack.Table (J).Entity;
1210 Kind := Ekind (Scope_Id);
1213 and then (No (Target) or else Scope_Id = U_Name)
1215 Set_Has_Exit (Scope_Id);
1218 elsif Kind = E_Block
1219 or else Kind = E_Loop
1220 or else Kind = E_Return_Statement
1226 ("cannot exit from program unit or accept statement", N);
1231 -- Verify that if present the condition is a Boolean expression
1233 if Present (Cond) then
1234 Analyze_And_Resolve (Cond, Any_Boolean);
1235 Check_Unset_Reference (Cond);
1238 -- In formal mode, verify that the exit statement respects the SPARK
1241 if Present (Cond) then
1242 if Nkind (Parent (N)) /= N_Loop_Statement then
1243 Check_Formal_Restriction
1244 ("exit with when clause must be directly in loop", N);
1248 if Nkind (Parent (N)) /= N_If_Statement then
1249 if Nkind (Parent (N)) = N_Elsif_Part then
1250 Check_Formal_Restriction
1251 ("exit must be in IF without ELSIF", N);
1253 Check_Formal_Restriction ("exit must be directly in IF", N);
1256 elsif Nkind (Parent (Parent (N))) /= N_Loop_Statement then
1257 Check_Formal_Restriction
1258 ("exit must be in IF directly in loop", N);
1260 -- First test the presence of ELSE, so that an exit in an ELSE
1261 -- leads to an error mentioning the ELSE.
1263 elsif Present (Else_Statements (Parent (N))) then
1264 Check_Formal_Restriction ("exit must be in IF without ELSE", N);
1266 -- An exit in an ELSIF does not reach here, as it would have been
1267 -- detected in the case (Nkind (Parent (N)) /= N_If_Statement).
1269 elsif Present (Elsif_Parts (Parent (N))) then
1270 Check_Formal_Restriction ("exit must be in IF without ELSIF", N);
1274 -- Chain exit statement to associated loop entity
1276 Set_Next_Exit_Statement (N, First_Exit_Statement (Scope_Id));
1277 Set_First_Exit_Statement (Scope_Id, N);
1279 -- Since the exit may take us out of a loop, any previous assignment
1280 -- statement is not useless, so clear last assignment indications. It
1281 -- is OK to keep other current values, since if the exit statement
1282 -- does not exit, then the current values are still valid.
1284 Kill_Current_Values (Last_Assignment_Only => True);
1285 end Analyze_Exit_Statement;
1287 ----------------------------
1288 -- Analyze_Goto_Statement --
1289 ----------------------------
1291 procedure Analyze_Goto_Statement (N : Node_Id) is
1292 Label : constant Node_Id := Name (N);
1293 Scope_Id : Entity_Id;
1294 Label_Scope : Entity_Id;
1295 Label_Ent : Entity_Id;
1298 Check_Formal_Restriction ("goto statement is not allowed", N);
1300 -- Actual semantic checks
1302 Check_Unreachable_Code (N);
1303 Kill_Current_Values (Last_Assignment_Only => True);
1306 Label_Ent := Entity (Label);
1308 -- Ignore previous error
1310 if Label_Ent = Any_Id then
1313 -- We just have a label as the target of a goto
1315 elsif Ekind (Label_Ent) /= E_Label then
1316 Error_Msg_N ("target of goto statement must be a label", Label);
1319 -- Check that the target of the goto is reachable according to Ada
1320 -- scoping rules. Note: the special gotos we generate for optimizing
1321 -- local handling of exceptions would violate these rules, but we mark
1322 -- such gotos as analyzed when built, so this code is never entered.
1324 elsif not Reachable (Label_Ent) then
1325 Error_Msg_N ("target of goto statement is not reachable", Label);
1329 -- Here if goto passes initial validity checks
1331 Label_Scope := Enclosing_Scope (Label_Ent);
1333 for J in reverse 0 .. Scope_Stack.Last loop
1334 Scope_Id := Scope_Stack.Table (J).Entity;
1336 if Label_Scope = Scope_Id
1337 or else (Ekind (Scope_Id) /= E_Block
1338 and then Ekind (Scope_Id) /= E_Loop
1339 and then Ekind (Scope_Id) /= E_Return_Statement)
1341 if Scope_Id /= Label_Scope then
1343 ("cannot exit from program unit or accept statement", N);
1350 raise Program_Error;
1351 end Analyze_Goto_Statement;
1353 --------------------------
1354 -- Analyze_If_Statement --
1355 --------------------------
1357 -- A special complication arises in the analysis of if statements
1359 -- The expander has circuitry to completely delete code that it can tell
1360 -- will not be executed (as a result of compile time known conditions). In
1361 -- the analyzer, we ensure that code that will be deleted in this manner is
1362 -- analyzed but not expanded. This is obviously more efficient, but more
1363 -- significantly, difficulties arise if code is expanded and then
1364 -- eliminated (e.g. exception table entries disappear). Similarly, itypes
1365 -- generated in deleted code must be frozen from start, because the nodes
1366 -- on which they depend will not be available at the freeze point.
1368 procedure Analyze_If_Statement (N : Node_Id) is
1371 Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count;
1372 -- Recursively save value of this global, will be restored on exit
1374 Save_In_Deleted_Code : Boolean;
1376 Del : Boolean := False;
1377 -- This flag gets set True if a True condition has been found, which
1378 -- means that remaining ELSE/ELSIF parts are deleted.
1380 procedure Analyze_Cond_Then (Cnode : Node_Id);
1381 -- This is applied to either the N_If_Statement node itself or to an
1382 -- N_Elsif_Part node. It deals with analyzing the condition and the THEN
1383 -- statements associated with it.
1385 -----------------------
1386 -- Analyze_Cond_Then --
1387 -----------------------
1389 procedure Analyze_Cond_Then (Cnode : Node_Id) is
1390 Cond : constant Node_Id := Condition (Cnode);
1391 Tstm : constant List_Id := Then_Statements (Cnode);
1394 Unblocked_Exit_Count := Unblocked_Exit_Count + 1;
1395 Analyze_And_Resolve (Cond, Any_Boolean);
1396 Check_Unset_Reference (Cond);
1397 Set_Current_Value_Condition (Cnode);
1399 -- If already deleting, then just analyze then statements
1402 Analyze_Statements (Tstm);
1404 -- Compile time known value, not deleting yet
1406 elsif Compile_Time_Known_Value (Cond) then
1407 Save_In_Deleted_Code := In_Deleted_Code;
1409 -- If condition is True, then analyze the THEN statements and set
1410 -- no expansion for ELSE and ELSIF parts.
1412 if Is_True (Expr_Value (Cond)) then
1413 Analyze_Statements (Tstm);
1415 Expander_Mode_Save_And_Set (False);
1416 In_Deleted_Code := True;
1418 -- If condition is False, analyze THEN with expansion off
1420 else -- Is_False (Expr_Value (Cond))
1421 Expander_Mode_Save_And_Set (False);
1422 In_Deleted_Code := True;
1423 Analyze_Statements (Tstm);
1424 Expander_Mode_Restore;
1425 In_Deleted_Code := Save_In_Deleted_Code;
1428 -- Not known at compile time, not deleting, normal analysis
1431 Analyze_Statements (Tstm);
1433 end Analyze_Cond_Then;
1435 -- Start of Analyze_If_Statement
1438 -- Initialize exit count for else statements. If there is no else part,
1439 -- this count will stay non-zero reflecting the fact that the uncovered
1440 -- else case is an unblocked exit.
1442 Unblocked_Exit_Count := 1;
1443 Analyze_Cond_Then (N);
1445 -- Now to analyze the elsif parts if any are present
1447 if Present (Elsif_Parts (N)) then
1448 E := First (Elsif_Parts (N));
1449 while Present (E) loop
1450 Analyze_Cond_Then (E);
1455 if Present (Else_Statements (N)) then
1456 Analyze_Statements (Else_Statements (N));
1459 -- If all our exits were blocked by unconditional transfers of control,
1460 -- then the entire IF statement acts as an unconditional transfer of
1461 -- control, so treat it like one, and check unreachable code.
1463 if Unblocked_Exit_Count = 0 then
1464 Unblocked_Exit_Count := Save_Unblocked_Exit_Count;
1465 Check_Unreachable_Code (N);
1467 Unblocked_Exit_Count := Save_Unblocked_Exit_Count;
1471 Expander_Mode_Restore;
1472 In_Deleted_Code := Save_In_Deleted_Code;
1475 if not Expander_Active
1476 and then Compile_Time_Known_Value (Condition (N))
1477 and then Serious_Errors_Detected = 0
1479 if Is_True (Expr_Value (Condition (N))) then
1480 Remove_Warning_Messages (Else_Statements (N));
1482 if Present (Elsif_Parts (N)) then
1483 E := First (Elsif_Parts (N));
1484 while Present (E) loop
1485 Remove_Warning_Messages (Then_Statements (E));
1491 Remove_Warning_Messages (Then_Statements (N));
1494 end Analyze_If_Statement;
1496 ----------------------------------------
1497 -- Analyze_Implicit_Label_Declaration --
1498 ----------------------------------------
1500 -- An implicit label declaration is generated in the innermost enclosing
1501 -- declarative part. This is done for labels, and block and loop names.
1503 -- Note: any changes in this routine may need to be reflected in
1504 -- Analyze_Label_Entity.
1506 procedure Analyze_Implicit_Label_Declaration (N : Node_Id) is
1507 Id : constant Node_Id := Defining_Identifier (N);
1510 Set_Ekind (Id, E_Label);
1511 Set_Etype (Id, Standard_Void_Type);
1512 Set_Enclosing_Scope (Id, Current_Scope);
1513 end Analyze_Implicit_Label_Declaration;
1515 ------------------------------
1516 -- Analyze_Iteration_Scheme --
1517 ------------------------------
1519 procedure Analyze_Iteration_Scheme (N : Node_Id) is
1521 procedure Process_Bounds (R : Node_Id);
1522 -- If the iteration is given by a range, create temporaries and
1523 -- assignment statements block to capture the bounds and perform
1524 -- required finalization actions in case a bound includes a function
1525 -- call that uses the temporary stack. We first pre-analyze a copy of
1526 -- the range in order to determine the expected type, and analyze and
1527 -- resolve the original bounds.
1529 procedure Check_Controlled_Array_Attribute (DS : Node_Id);
1530 -- If the bounds are given by a 'Range reference on a function call
1531 -- that returns a controlled array, introduce an explicit declaration
1532 -- to capture the bounds, so that the function result can be finalized
1533 -- in timely fashion.
1535 function Has_Call_Using_Secondary_Stack (N : Node_Id) return Boolean;
1536 -- N is the node for an arbitrary construct. This function searches the
1537 -- construct N to see if any expressions within it contain function
1538 -- calls that use the secondary stack, returning True if any such call
1539 -- is found, and False otherwise.
1541 procedure Pre_Analyze_Range (R_Copy : Node_Id);
1542 -- Determine expected type of range or domain of iteration of Ada 2012
1543 -- loop by analyzing separate copy. Do the analysis and resolution of
1544 -- the copy of the bound(s) with expansion disabled, to prevent the
1545 -- generation of finalization actions. This prevents memory leaks when
1546 -- the bounds contain calls to functions returning controlled arrays or
1547 -- when the domain of iteration is a container.
1549 -----------------------
1550 -- Pre_Analyze_Range --
1551 -----------------------
1553 procedure Pre_Analyze_Range (R_Copy : Node_Id) is
1554 Save_Analysis : Boolean;
1556 Save_Analysis := Full_Analysis;
1557 Full_Analysis := False;
1558 Expander_Mode_Save_And_Set (False);
1562 if Nkind (R_Copy) in N_Subexpr
1563 and then Is_Overloaded (R_Copy)
1566 -- Apply preference rules for range of predefined integer types,
1567 -- or diagnose true ambiguity.
1572 Found : Entity_Id := Empty;
1575 Get_First_Interp (R_Copy, I, It);
1576 while Present (It.Typ) loop
1577 if Is_Discrete_Type (It.Typ) then
1581 if Scope (Found) = Standard_Standard then
1584 elsif Scope (It.Typ) = Standard_Standard then
1588 -- Both of them are user-defined
1591 ("ambiguous bounds in range of iteration",
1593 Error_Msg_N ("\possible interpretations:", R_Copy);
1594 Error_Msg_NE ("\\} ", R_Copy, Found);
1595 Error_Msg_NE ("\\} ", R_Copy, It.Typ);
1601 Get_Next_Interp (I, It);
1606 if Is_Entity_Name (R_Copy)
1607 and then Is_Type (Entity (R_Copy))
1610 -- Subtype mark in iteration scheme
1614 elsif Nkind (R_Copy) in N_Subexpr then
1616 -- Expression in range, or Ada 2012 iterator
1621 Expander_Mode_Restore;
1622 Full_Analysis := Save_Analysis;
1623 end Pre_Analyze_Range;
1625 --------------------
1626 -- Process_Bounds --
1627 --------------------
1629 procedure Process_Bounds (R : Node_Id) is
1630 Loc : constant Source_Ptr := Sloc (N);
1631 R_Copy : constant Node_Id := New_Copy_Tree (R);
1632 Lo : constant Node_Id := Low_Bound (R);
1633 Hi : constant Node_Id := High_Bound (R);
1634 New_Lo_Bound : Node_Id;
1635 New_Hi_Bound : Node_Id;
1639 (Original_Bound : Node_Id;
1640 Analyzed_Bound : Node_Id) return Node_Id;
1641 -- Capture value of bound and return captured value
1648 (Original_Bound : Node_Id;
1649 Analyzed_Bound : Node_Id) return Node_Id
1656 -- If the bound is a constant or an object, no need for a separate
1657 -- declaration. If the bound is the result of previous expansion
1658 -- it is already analyzed and should not be modified. Note that
1659 -- the Bound will be resolved later, if needed, as part of the
1660 -- call to Make_Index (literal bounds may need to be resolved to
1663 if Analyzed (Original_Bound) then
1664 return Original_Bound;
1666 elsif Nkind_In (Analyzed_Bound, N_Integer_Literal,
1667 N_Character_Literal)
1668 or else Is_Entity_Name (Analyzed_Bound)
1670 Analyze_And_Resolve (Original_Bound, Typ);
1671 return Original_Bound;
1674 -- Here we need to capture the value
1676 Analyze_And_Resolve (Original_Bound, Typ);
1678 -- Normally, the best approach is simply to generate a constant
1679 -- declaration that captures the bound. However, there is a nasty
1680 -- case where this is wrong. If the bound is complex, and has a
1681 -- possible use of the secondary stack, we need to generate a
1682 -- separate assignment statement to ensure the creation of a block
1683 -- which will release the secondary stack.
1685 -- We prefer the constant declaration, since it leaves us with a
1686 -- proper trace of the value, useful in optimizations that get rid
1687 -- of junk range checks.
1689 if not Has_Call_Using_Secondary_Stack (Original_Bound) then
1690 Force_Evaluation (Original_Bound);
1691 return Original_Bound;
1694 Id := Make_Temporary (Loc, 'R', Original_Bound);
1696 -- Here we make a declaration with a separate assignment
1697 -- statement, and insert before loop header.
1700 Make_Object_Declaration (Loc,
1701 Defining_Identifier => Id,
1702 Object_Definition => New_Occurrence_Of (Typ, Loc));
1705 Make_Assignment_Statement (Loc,
1706 Name => New_Occurrence_Of (Id, Loc),
1707 Expression => Relocate_Node (Original_Bound));
1709 -- We must recursively clean in the relocated expression the flag
1710 -- analyzed to ensure that the expression is reanalyzed. Required
1711 -- to ensure that the transient scope is established now (because
1712 -- Establish_Transient_Scope discarded generating transient scopes
1713 -- in the analysis of the iteration scheme).
1715 Reset_Analyzed_Flags (Expression (Assign));
1717 Insert_Actions (Parent (N), New_List (Decl, Assign));
1719 -- Now that this temporary variable is initialized we decorate it
1720 -- as safe-to-reevaluate to inform to the backend that no further
1721 -- asignment will be issued and hence it can be handled as side
1722 -- effect free. Note that this decoration must be done when the
1723 -- assignment has been analyzed because otherwise it will be
1724 -- rejected (see Analyze_Assignment).
1726 Set_Is_Safe_To_Reevaluate (Id);
1728 Rewrite (Original_Bound, New_Occurrence_Of (Id, Loc));
1730 if Nkind (Assign) = N_Assignment_Statement then
1731 return Expression (Assign);
1733 return Original_Bound;
1737 -- Start of processing for Process_Bounds
1740 Set_Parent (R_Copy, Parent (R));
1741 Pre_Analyze_Range (R_Copy);
1742 Typ := Etype (R_Copy);
1744 -- If the type of the discrete range is Universal_Integer, then the
1745 -- bound's type must be resolved to Integer, and any object used to
1746 -- hold the bound must also have type Integer, unless the literal
1747 -- bounds are constant-folded expressions with a user-defined type.
1749 if Typ = Universal_Integer then
1750 if Nkind (Lo) = N_Integer_Literal
1751 and then Present (Etype (Lo))
1752 and then Scope (Etype (Lo)) /= Standard_Standard
1756 elsif Nkind (Hi) = N_Integer_Literal
1757 and then Present (Etype (Hi))
1758 and then Scope (Etype (Hi)) /= Standard_Standard
1763 Typ := Standard_Integer;
1769 New_Lo_Bound := One_Bound (Lo, Low_Bound (R_Copy));
1770 New_Hi_Bound := One_Bound (Hi, High_Bound (R_Copy));
1772 -- Propagate staticness to loop range itself, in case the
1773 -- corresponding subtype is static.
1775 if New_Lo_Bound /= Lo
1776 and then Is_Static_Expression (New_Lo_Bound)
1778 Rewrite (Low_Bound (R), New_Copy (New_Lo_Bound));
1781 if New_Hi_Bound /= Hi
1782 and then Is_Static_Expression (New_Hi_Bound)
1784 Rewrite (High_Bound (R), New_Copy (New_Hi_Bound));
1788 --------------------------------------
1789 -- Check_Controlled_Array_Attribute --
1790 --------------------------------------
1792 procedure Check_Controlled_Array_Attribute (DS : Node_Id) is
1794 if Nkind (DS) = N_Attribute_Reference
1795 and then Is_Entity_Name (Prefix (DS))
1796 and then Ekind (Entity (Prefix (DS))) = E_Function
1797 and then Is_Array_Type (Etype (Entity (Prefix (DS))))
1800 Component_Type (Etype (Entity (Prefix (DS)))))
1801 and then Expander_Active
1804 Loc : constant Source_Ptr := Sloc (N);
1805 Arr : constant Entity_Id := Etype (Entity (Prefix (DS)));
1806 Indx : constant Entity_Id :=
1807 Base_Type (Etype (First_Index (Arr)));
1808 Subt : constant Entity_Id := Make_Temporary (Loc, 'S');
1813 Make_Subtype_Declaration (Loc,
1814 Defining_Identifier => Subt,
1815 Subtype_Indication =>
1816 Make_Subtype_Indication (Loc,
1817 Subtype_Mark => New_Reference_To (Indx, Loc),
1819 Make_Range_Constraint (Loc,
1820 Relocate_Node (DS))));
1821 Insert_Before (Parent (N), Decl);
1825 Make_Attribute_Reference (Loc,
1826 Prefix => New_Reference_To (Subt, Loc),
1827 Attribute_Name => Attribute_Name (DS)));
1831 end Check_Controlled_Array_Attribute;
1833 ------------------------------------
1834 -- Has_Call_Using_Secondary_Stack --
1835 ------------------------------------
1837 function Has_Call_Using_Secondary_Stack (N : Node_Id) return Boolean is
1839 function Check_Call (N : Node_Id) return Traverse_Result;
1840 -- Check if N is a function call which uses the secondary stack
1846 function Check_Call (N : Node_Id) return Traverse_Result is
1849 Return_Typ : Entity_Id;
1852 if Nkind (N) = N_Function_Call then
1855 -- Call using access to subprogram with explicit dereference
1857 if Nkind (Nam) = N_Explicit_Dereference then
1858 Subp := Etype (Nam);
1863 Subp := Entity (Nam);
1866 Return_Typ := Etype (Subp);
1868 if Is_Composite_Type (Return_Typ)
1869 and then not Is_Constrained (Return_Typ)
1873 elsif Sec_Stack_Needed_For_Return (Subp) then
1878 -- Continue traversing the tree
1883 function Check_Calls is new Traverse_Func (Check_Call);
1885 -- Start of processing for Has_Call_Using_Secondary_Stack
1888 return Check_Calls (N) = Abandon;
1889 end Has_Call_Using_Secondary_Stack;
1891 -- Start of processing for Analyze_Iteration_Scheme
1894 -- If this is a rewritten quantified expression, the iteration scheme
1895 -- has been analyzed already. Do no repeat analysis because the loop
1896 -- variable is already declared.
1898 if Analyzed (N) then
1902 -- For an infinite loop, there is no iteration scheme
1908 -- Iteration scheme is present
1911 Cond : constant Node_Id := Condition (N);
1914 -- For WHILE loop, verify that the condition is a Boolean expression
1915 -- and resolve and check it.
1917 if Present (Cond) then
1918 Analyze_And_Resolve (Cond, Any_Boolean);
1919 Check_Unset_Reference (Cond);
1920 Set_Current_Value_Condition (N);
1923 -- For an iterator specification with "of", pre-analyze range to
1924 -- capture function calls that may require finalization actions.
1926 elsif Present (Iterator_Specification (N)) then
1927 Pre_Analyze_Range (Name (Iterator_Specification (N)));
1928 Analyze_Iterator_Specification (Iterator_Specification (N));
1930 -- Else we have a FOR loop
1934 LP : constant Node_Id := Loop_Parameter_Specification (N);
1935 Id : constant Entity_Id := Defining_Identifier (LP);
1936 DS : constant Node_Id := Discrete_Subtype_Definition (LP);
1943 -- We always consider the loop variable to be referenced, since
1944 -- the loop may be used just for counting purposes.
1946 Generate_Reference (Id, N, ' ');
1948 -- Check for the case of loop variable hiding a local variable
1949 -- (used later on to give a nice warning if the hidden variable
1950 -- is never assigned).
1953 H : constant Entity_Id := Homonym (Id);
1956 and then Enclosing_Dynamic_Scope (H) =
1957 Enclosing_Dynamic_Scope (Id)
1958 and then Ekind (H) = E_Variable
1959 and then Is_Discrete_Type (Etype (H))
1961 Set_Hiding_Loop_Variable (H, Id);
1965 -- Loop parameter specification must include subtype mark in
1968 if Nkind (DS) = N_Range then
1969 Check_Formal_Restriction
1970 ("loop parameter specification must include subtype mark",
1974 -- Now analyze the subtype definition. If it is a range, create
1975 -- temporaries for bounds.
1977 if Nkind (DS) = N_Range
1978 and then Expander_Active
1980 Process_Bounds (DS);
1982 -- expander not active or else range of iteration is a subtype
1983 -- indication, an entity, or a function call that yields an
1984 -- aggregate or a container.
1987 D_Copy := New_Copy_Tree (DS);
1988 Set_Parent (D_Copy, Parent (DS));
1989 Pre_Analyze_Range (D_Copy);
1991 if Nkind (D_Copy) = N_Function_Call
1993 (Is_Entity_Name (D_Copy)
1994 and then not Is_Type (Entity (D_Copy)))
1996 -- This is an iterator specification. Rewrite as such
1997 -- and analyze, to capture function calls that may
1998 -- require finalization actions.
2001 I_Spec : constant Node_Id :=
2002 Make_Iterator_Specification (Sloc (LP),
2003 Defining_Identifier =>
2006 Subtype_Indication => Empty,
2008 Reverse_Present (LP));
2010 Set_Iterator_Specification (N, I_Spec);
2011 Set_Loop_Parameter_Specification (N, Empty);
2012 Analyze_Iterator_Specification (I_Spec);
2016 -- Domain of iteration is not a function call, and is
2017 -- side-effect free.
2028 -- Some additional checks if we are iterating through a type
2030 if Is_Entity_Name (DS)
2031 and then Present (Entity (DS))
2032 and then Is_Type (Entity (DS))
2034 -- The subtype indication may denote the completion of an
2035 -- incomplete type declaration.
2037 if Ekind (Entity (DS)) = E_Incomplete_Type then
2038 Set_Entity (DS, Get_Full_View (Entity (DS)));
2039 Set_Etype (DS, Entity (DS));
2042 -- Attempt to iterate through non-static predicate
2044 if Is_Discrete_Type (Entity (DS))
2045 and then Present (Predicate_Function (Entity (DS)))
2046 and then No (Static_Predicate (Entity (DS)))
2048 Bad_Predicated_Subtype_Use
2049 ("cannot use subtype& with non-static "
2050 & "predicate for loop iteration", DS, Entity (DS));
2054 -- Error if not discrete type
2056 if not Is_Discrete_Type (Etype (DS)) then
2057 Wrong_Type (DS, Any_Discrete);
2058 Set_Etype (DS, Any_Type);
2061 Check_Controlled_Array_Attribute (DS);
2063 Make_Index (DS, LP, In_Iter_Schm => True);
2065 Set_Ekind (Id, E_Loop_Parameter);
2067 -- If the loop is part of a predicate or precondition, it may
2068 -- be analyzed twice, once in the source and once on the copy
2069 -- used to check conformance. Preserve the original itype
2070 -- because the second one may be created in a different scope,
2071 -- e.g. a precondition procedure, leading to a crash in GIGI.
2073 if No (Etype (Id)) or else Etype (Id) = Any_Type then
2074 Set_Etype (Id, Etype (DS));
2077 -- Treat a range as an implicit reference to the type, to
2078 -- inhibit spurious warnings.
2080 Generate_Reference (Base_Type (Etype (DS)), N, ' ');
2081 Set_Is_Known_Valid (Id, True);
2083 -- The loop is not a declarative part, so the only entity
2084 -- declared "within" must be frozen explicitly.
2087 Flist : constant List_Id := Freeze_Entity (Id, N);
2089 if Is_Non_Empty_List (Flist) then
2090 Insert_Actions (N, Flist);
2094 -- Check for null or possibly null range and issue warning. We
2095 -- suppress such messages in generic templates and instances,
2096 -- because in practice they tend to be dubious in these cases.
2098 if Nkind (DS) = N_Range and then Comes_From_Source (N) then
2100 L : constant Node_Id := Low_Bound (DS);
2101 H : constant Node_Id := High_Bound (DS);
2104 -- If range of loop is null, issue warning
2106 if Compile_Time_Compare
2107 (L, H, Assume_Valid => True) = GT
2109 -- Suppress the warning if inside a generic template
2110 -- or instance, since in practice they tend to be
2111 -- dubious in these cases since they can result from
2112 -- intended parametrization.
2114 if not Inside_A_Generic
2115 and then not In_Instance
2117 -- Specialize msg if invalid values could make the
2118 -- loop non-null after all.
2120 if Compile_Time_Compare
2121 (L, H, Assume_Valid => False) = GT
2124 ("?loop range is null, loop will not execute",
2127 -- Since we know the range of the loop is null,
2128 -- set the appropriate flag to remove the loop
2129 -- entirely during expansion.
2131 Set_Is_Null_Loop (Parent (N));
2133 -- Here is where the loop could execute because
2134 -- of invalid values, so issue appropriate
2135 -- message and in this case we do not set the
2136 -- Is_Null_Loop flag since the loop may execute.
2140 ("?loop range may be null, "
2141 & "loop may not execute",
2144 ("?can only execute if invalid values "
2150 -- In either case, suppress warnings in the body of
2151 -- the loop, since it is likely that these warnings
2152 -- will be inappropriate if the loop never actually
2153 -- executes, which is likely.
2155 Set_Suppress_Loop_Warnings (Parent (N));
2157 -- The other case for a warning is a reverse loop
2158 -- where the upper bound is the integer literal zero
2159 -- or one, and the lower bound can be positive.
2161 -- For example, we have
2163 -- for J in reverse N .. 1 loop
2165 -- In practice, this is very likely to be a case of
2166 -- reversing the bounds incorrectly in the range.
2168 elsif Reverse_Present (LP)
2169 and then Nkind (Original_Node (H)) =
2171 and then (Intval (Original_Node (H)) = Uint_0
2173 Intval (Original_Node (H)) = Uint_1)
2175 Error_Msg_N ("?loop range may be null", DS);
2176 Error_Msg_N ("\?bounds may be wrong way round", DS);
2183 end Analyze_Iteration_Scheme;
2185 -------------------------------------
2186 -- Analyze_Iterator_Specification --
2187 -------------------------------------
2189 procedure Analyze_Iterator_Specification (N : Node_Id) is
2190 Loc : constant Source_Ptr := Sloc (N);
2191 Def_Id : constant Node_Id := Defining_Identifier (N);
2192 Subt : constant Node_Id := Subtype_Indication (N);
2193 Container : constant Node_Id := Name (N);
2199 Enter_Name (Def_Id);
2200 Set_Ekind (Def_Id, E_Variable);
2202 if Present (Subt) then
2206 -- If it is an expression, the container is pre-analyzed in the caller.
2207 -- If it it of a controlled type we need a block for the finalization
2208 -- actions. As for loop bounds that need finalization, we create a
2209 -- declaration and an assignment to trigger these actions.
2211 if Present (Etype (Container))
2212 and then Is_Controlled (Etype (Container))
2213 and then not Is_Entity_Name (Container)
2216 Id : constant Entity_Id := Make_Temporary (Loc, 'R', Container);
2222 Typ := Etype (Container);
2225 Make_Object_Declaration (Loc,
2226 Defining_Identifier => Id,
2227 Object_Definition => New_Occurrence_Of (Typ, Loc));
2230 Make_Assignment_Statement (Loc,
2231 Name => New_Occurrence_Of (Id, Loc),
2232 Expression => Relocate_Node (Container));
2234 Insert_Actions (Parent (N), New_List (Decl, Assign));
2239 -- Container is an entity or an array with uncontrolled components
2241 Analyze_And_Resolve (Container);
2244 Typ := Etype (Container);
2246 if Is_Array_Type (Typ) then
2247 if Of_Present (N) then
2248 Set_Etype (Def_Id, Component_Type (Typ));
2251 ("to iterate over the elements of an array, use OF", N);
2252 Set_Etype (Def_Id, Etype (First_Index (Typ)));
2255 -- Iteration over a container
2258 Set_Ekind (Def_Id, E_Loop_Parameter);
2260 if Of_Present (N) then
2262 -- Find the Element_Type in the package instance that defines the
2265 Ent := First_Entity (Scope (Base_Type (Typ)));
2266 while Present (Ent) loop
2267 if Chars (Ent) = Name_Element_Type then
2268 Set_Etype (Def_Id, Ent);
2276 -- Find the Cursor type in similar fashion
2278 Ent := First_Entity (Scope (Base_Type (Typ)));
2279 while Present (Ent) loop
2280 if Chars (Ent) = Name_Cursor then
2281 Set_Etype (Def_Id, Ent);
2289 end Analyze_Iterator_Specification;
2295 -- Note: the semantic work required for analyzing labels (setting them as
2296 -- reachable) was done in a prepass through the statements in the block,
2297 -- so that forward gotos would be properly handled. See Analyze_Statements
2298 -- for further details. The only processing required here is to deal with
2299 -- optimizations that depend on an assumption of sequential control flow,
2300 -- since of course the occurrence of a label breaks this assumption.
2302 procedure Analyze_Label (N : Node_Id) is
2303 pragma Warnings (Off, N);
2305 Kill_Current_Values;
2308 --------------------------
2309 -- Analyze_Label_Entity --
2310 --------------------------
2312 procedure Analyze_Label_Entity (E : Entity_Id) is
2314 Set_Ekind (E, E_Label);
2315 Set_Etype (E, Standard_Void_Type);
2316 Set_Enclosing_Scope (E, Current_Scope);
2317 Set_Reachable (E, True);
2318 end Analyze_Label_Entity;
2320 ----------------------------
2321 -- Analyze_Loop_Statement --
2322 ----------------------------
2324 procedure Analyze_Loop_Statement (N : Node_Id) is
2325 Loop_Statement : constant Node_Id := N;
2327 Id : constant Node_Id := Identifier (Loop_Statement);
2328 Iter : constant Node_Id := Iteration_Scheme (Loop_Statement);
2332 if Present (Id) then
2334 -- Make name visible, e.g. for use in exit statements. Loop labels
2335 -- are always considered to be referenced.
2340 -- Guard against serious error (typically, a scope mismatch when
2341 -- semantic analysis is requested) by creating loop entity to
2342 -- continue analysis.
2345 if Total_Errors_Detected /= 0 then
2348 (E_Loop, Current_Scope, Sloc (Loop_Statement), 'L');
2350 raise Program_Error;
2354 Generate_Reference (Ent, Loop_Statement, ' ');
2355 Generate_Definition (Ent);
2357 -- If we found a label, mark its type. If not, ignore it, since it
2358 -- means we have a conflicting declaration, which would already
2359 -- have been diagnosed at declaration time. Set Label_Construct
2360 -- of the implicit label declaration, which is not created by the
2361 -- parser for generic units.
2363 if Ekind (Ent) = E_Label then
2364 Set_Ekind (Ent, E_Loop);
2366 if Nkind (Parent (Ent)) = N_Implicit_Label_Declaration then
2367 Set_Label_Construct (Parent (Ent), Loop_Statement);
2372 -- Case of no identifier present
2377 (E_Loop, Current_Scope, Sloc (Loop_Statement), 'L');
2378 Set_Etype (Ent, Standard_Void_Type);
2379 Set_Parent (Ent, Loop_Statement);
2382 -- Kill current values on entry to loop, since statements in the body of
2383 -- the loop may have been executed before the loop is entered. Similarly
2384 -- we kill values after the loop, since we do not know that the body of
2385 -- the loop was executed.
2387 Kill_Current_Values;
2389 Analyze_Iteration_Scheme (Iter);
2390 Analyze_Statements (Statements (Loop_Statement));
2391 Process_End_Label (Loop_Statement, 'e', Ent);
2393 Kill_Current_Values;
2395 -- Check for infinite loop. Skip check for generated code, since it
2396 -- justs waste time and makes debugging the routine called harder.
2398 -- Note that we have to wait till the body of the loop is fully analyzed
2399 -- before making this call, since Check_Infinite_Loop_Warning relies on
2400 -- being able to use semantic visibility information to find references.
2402 if Comes_From_Source (N) then
2403 Check_Infinite_Loop_Warning (N);
2406 -- Code after loop is unreachable if the loop has no WHILE or FOR and
2407 -- contains no EXIT statements within the body of the loop.
2409 if No (Iter) and then not Has_Exit (Ent) then
2410 Check_Unreachable_Code (N);
2412 end Analyze_Loop_Statement;
2414 ----------------------------
2415 -- Analyze_Null_Statement --
2416 ----------------------------
2418 -- Note: the semantics of the null statement is implemented by a single
2419 -- null statement, too bad everything isn't as simple as this!
2421 procedure Analyze_Null_Statement (N : Node_Id) is
2422 pragma Warnings (Off, N);
2425 end Analyze_Null_Statement;
2427 ------------------------
2428 -- Analyze_Statements --
2429 ------------------------
2431 procedure Analyze_Statements (L : List_Id) is
2436 -- The labels declared in the statement list are reachable from
2437 -- statements in the list. We do this as a prepass so that any goto
2438 -- statement will be properly flagged if its target is not reachable.
2439 -- This is not required, but is nice behavior!
2442 while Present (S) loop
2443 if Nkind (S) = N_Label then
2444 Analyze (Identifier (S));
2445 Lab := Entity (Identifier (S));
2447 -- If we found a label mark it as reachable
2449 if Ekind (Lab) = E_Label then
2450 Generate_Definition (Lab);
2451 Set_Reachable (Lab);
2453 if Nkind (Parent (Lab)) = N_Implicit_Label_Declaration then
2454 Set_Label_Construct (Parent (Lab), S);
2457 -- If we failed to find a label, it means the implicit declaration
2458 -- of the label was hidden. A for-loop parameter can do this to
2459 -- a label with the same name inside the loop, since the implicit
2460 -- label declaration is in the innermost enclosing body or block
2464 Error_Msg_Sloc := Sloc (Lab);
2466 ("implicit label declaration for & is hidden#",
2474 -- Perform semantic analysis on all statements
2476 Conditional_Statements_Begin;
2479 while Present (S) loop
2484 Conditional_Statements_End;
2486 -- Make labels unreachable. Visibility is not sufficient, because labels
2487 -- in one if-branch for example are not reachable from the other branch,
2488 -- even though their declarations are in the enclosing declarative part.
2491 while Present (S) loop
2492 if Nkind (S) = N_Label then
2493 Set_Reachable (Entity (Identifier (S)), False);
2498 end Analyze_Statements;
2500 ----------------------------
2501 -- Check_Unreachable_Code --
2502 ----------------------------
2504 procedure Check_Unreachable_Code (N : Node_Id) is
2505 Error_Node : Node_Id;
2509 if Is_List_Member (N)
2510 and then Comes_From_Source (N)
2516 Nxt := Original_Node (Next (N));
2518 -- If a label follows us, then we never have dead code, since
2519 -- someone could branch to the label, so we just ignore it, unless
2520 -- we are in formal mode where goto statements are not allowed.
2522 if Nkind (Nxt) = N_Label
2523 and then not (Formal_Verification_Mode
2524 or else Restriction_Check_Required (SPARK))
2528 -- Otherwise see if we have a real statement following us
2531 and then Comes_From_Source (Nxt)
2532 and then Is_Statement (Nxt)
2534 -- Special very annoying exception. If we have a return that
2535 -- follows a raise, then we allow it without a warning, since
2536 -- the Ada RM annoyingly requires a useless return here!
2538 if Nkind (Original_Node (N)) /= N_Raise_Statement
2539 or else Nkind (Nxt) /= N_Simple_Return_Statement
2541 -- The rather strange shenanigans with the warning message
2542 -- here reflects the fact that Kill_Dead_Code is very good
2543 -- at removing warnings in deleted code, and this is one
2544 -- warning we would prefer NOT to have removed.
2548 -- If we have unreachable code, analyze and remove the
2549 -- unreachable code, since it is useless and we don't
2550 -- want to generate junk warnings.
2552 -- We skip this step if we are not in code generation mode.
2553 -- This is the one case where we remove dead code in the
2554 -- semantics as opposed to the expander, and we do not want
2555 -- to remove code if we are not in code generation mode,
2556 -- since this messes up the ASIS trees.
2558 -- Note that one might react by moving the whole circuit to
2559 -- exp_ch5, but then we lose the warning in -gnatc mode.
2561 if Operating_Mode = Generate_Code then
2565 -- Quit deleting when we have nothing more to delete
2566 -- or if we hit a label (since someone could transfer
2567 -- control to a label, so we should not delete it).
2569 exit when No (Nxt) or else Nkind (Nxt) = N_Label;
2571 -- Statement/declaration is to be deleted
2575 Kill_Dead_Code (Nxt);
2579 -- Now issue the warning (or error in formal mode)
2581 if SPARK_Mode or else Restriction_Check_Required (SPARK) then
2582 Check_Formal_Restriction
2583 ("unreachable code is not allowed", Error_Node);
2585 Error_Msg ("?unreachable code!", Sloc (Error_Node));
2589 -- If the unconditional transfer of control instruction is the
2590 -- last statement of a sequence, then see if our parent is one of
2591 -- the constructs for which we count unblocked exits, and if so,
2592 -- adjust the count.
2597 -- Statements in THEN part or ELSE part of IF statement
2599 if Nkind (P) = N_If_Statement then
2602 -- Statements in ELSIF part of an IF statement
2604 elsif Nkind (P) = N_Elsif_Part then
2606 pragma Assert (Nkind (P) = N_If_Statement);
2608 -- Statements in CASE statement alternative
2610 elsif Nkind (P) = N_Case_Statement_Alternative then
2612 pragma Assert (Nkind (P) = N_Case_Statement);
2614 -- Statements in body of block
2616 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
2617 and then Nkind (Parent (P)) = N_Block_Statement
2621 -- Statements in exception handler in a block
2623 elsif Nkind (P) = N_Exception_Handler
2624 and then Nkind (Parent (P)) = N_Handled_Sequence_Of_Statements
2625 and then Nkind (Parent (Parent (P))) = N_Block_Statement
2629 -- None of these cases, so return
2635 -- This was one of the cases we are looking for (i.e. the
2636 -- parent construct was IF, CASE or block) so decrement count.
2638 Unblocked_Exit_Count := Unblocked_Exit_Count - 1;
2642 end Check_Unreachable_Code;