From 903275965921f6f63519f07b4f82467ee39160a1 Mon Sep 17 00:00:00 2001 From: Piotr Trojanek Date: Tue, 11 Aug 2020 22:08:10 +0200 Subject: [PATCH] [Ada] Reduce scope of local variables for detecting extra WITH clauses gcc/ada/ * sem_warn.adb (Check_Unused_Withs): Move local variables from to a nested procedure; Lunit is passed as a parameter to Check_System_Aux and its type is refined from Node_Id to Entity_Id; Cnode is now a constant. --- gcc/ada/sem_warn.adb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index aeea3186572..d1acf2f2312 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -2254,10 +2254,6 @@ package body Sem_Warn is ------------------------ procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit) is - Cnode : Node_Id; - Item : Node_Id; - Lunit : Node_Id; - Ent : Entity_Id; Munite : constant Entity_Id := Cunit_Entity (Main_Unit); -- This is needed for checking the special renaming case @@ -2270,8 +2266,9 @@ package body Sem_Warn is -------------------- procedure Check_One_Unit (Unit : Unit_Number_Type) is + Cnode : constant Node_Id := Cunit (Unit); + Is_Visible_Renaming : Boolean := False; - Pack : Entity_Id; procedure Check_Inner_Package (Pack : Entity_Id); -- Pack is a package local to a unit in a with_clause. Both the unit @@ -2279,7 +2276,7 @@ package body Sem_Warn is -- referenced, then the only occurrence of Pack is in a USE clause -- or a pragma, and a warning is worthwhile as well. - function Check_System_Aux return Boolean; + function Check_System_Aux (Lunit : Entity_Id) return Boolean; -- Before giving a warning on a with_clause for System, check whether -- a system extension is present. @@ -2358,7 +2355,7 @@ package body Sem_Warn is -- Check_System_Aux -- ---------------------- - function Check_System_Aux return Boolean is + function Check_System_Aux (Lunit : Entity_Id) return Boolean is Ent : Entity_Id; begin @@ -2453,11 +2450,16 @@ package body Sem_Warn is return False; end Has_Visible_Entities; + -- Local variables + + Ent : Entity_Id; + Item : Node_Id; + Lunit : Entity_Id; + Pack : Entity_Id; + -- Start of processing for Check_One_Unit begin - Cnode := Cunit (Unit); - -- Only do check in units that are part of the extended main unit. -- This is actually a necessary restriction, because in the case of -- subprogram acting as its own specification, there can be with's in @@ -2576,7 +2578,7 @@ package body Sem_Warn is if Unit = Spec_Unit then Set_No_Entities_Ref_In_Spec (Item); - elsif Check_System_Aux then + elsif Check_System_Aux (Lunit) then null; -- Else the warning may be needed -- 2.30.2