From 445032728dd46e3692a9aed879c6cf350259a53a Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Tue, 1 Dec 2020 15:18:34 +0100 Subject: [PATCH] [Ada] Reduce scopes of local variables for case and if statements gcc/ada/ * sem_ch5.adb (Analyze_Case_Statement): Change local variable Exp to constant; remove unreferenced Last_Choice variable; reduce scope of other variables. (Analyze_If_Statement): Reduce scope of a local variable; add comment. --- gcc/ada/sem_ch5.adb | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index 0b1db8510c4..380d6017414 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -1389,16 +1389,7 @@ package body Sem_Ch5 is ---------------------------- procedure Analyze_Case_Statement (N : Node_Id) is - Exp : Node_Id; - Exp_Type : Entity_Id; - Exp_Btype : Entity_Id; - Last_Choice : Nat; - - Others_Present : Boolean; - -- Indicates if Others was present - - pragma Warnings (Off, Last_Choice); - -- Don't care about assigned value + Exp : constant Node_Id := Expression (N); Statements_Analyzed : Boolean := False; -- Set True if at least some statement sequences get analyzed. If False @@ -1406,9 +1397,6 @@ package body Sem_Ch5 is -- the case statement, and as a result it is not a good idea to output -- warning messages about unreachable code. - Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count; - -- Recursively save value of this global, will be restored on exit - procedure Non_Static_Choice_Error (Choice : Node_Id); -- Error routine invoked by the generic instantiation below when the -- case statement has a non static choice. @@ -1492,11 +1480,21 @@ package body Sem_Ch5 is Analyze_Statements (Statements (Alternative)); end Process_Statements; + -- Local variables + + Exp_Type : Entity_Id; + Exp_Btype : Entity_Id; + + Others_Present : Boolean; + -- Indicates if Others was present + + Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count; + -- Recursively save value of this global, will be restored on exit + -- Start of processing for Analyze_Case_Statement begin Unblocked_Exit_Count := 0; - Exp := Expression (N); Analyze (Exp); -- The expression must be of any discrete type. In rare cases, the @@ -1775,8 +1773,6 @@ package body Sem_Ch5 is -- on which they depend will not be available at the freeze point. procedure Analyze_If_Statement (N : Node_Id) is - E : Node_Id; - Save_Unblocked_Exit_Count : constant Nat := Unblocked_Exit_Count; -- Recursively save value of this global, will be restored on exit @@ -1841,6 +1837,11 @@ package body Sem_Ch5 is end if; end Analyze_Cond_Then; + -- Local variables + + E : Node_Id; + -- For iterating over elsif parts + -- Start of processing for Analyze_If_Statement begin -- 2.30.2