From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id D12D33858013; Thu, 6 Jan 2022 17:14:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D12D33858013 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6311] [Ada] Remove unnecessary guards for non-empty lists X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: 4ca7f4e26dd10243da57584175db137115e5aefd X-Git-Newrev: a9f0ee1dfc2a083ede548e38f9c2554163a87a16 Message-Id: <20220106171438.D12D33858013@sourceware.org> Date: Thu, 6 Jan 2022 17:14:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jan 2022 17:14:38 -0000 https://gcc.gnu.org/g:a9f0ee1dfc2a083ede548e38f9c2554163a87a16 commit r12-6311-ga9f0ee1dfc2a083ede548e38f9c2554163a87a16 Author: Piotr Trojanek Date: Wed Dec 8 15:19:49 2021 +0100 [Ada] Remove unnecessary guards for non-empty lists gcc/ada/ * errout.adb (Remove_Warning_Messages): Remove unnecessary guard. * exp_util.adb (Kill_Dead_Code): Likewise. * par_sco.adb (Traverse_Declarations_Or_Statements): Likewise. * sem_ch3.adb (Build_Derived_Record_Type): Likewise. * sem_ch4.adb (Traverse_Interfaces): Likewise. * sem_eval.adb (Traverse_Interfaces): Likewise. * sem_util.adb (Collect_Interfaces): Likewise. (Has_Non_Null_Statements, Side_Effect_Free_Statements): Likewise; turn into WHILE loops, for consistency. Diff: --- gcc/ada/errout.adb | 12 +++---- gcc/ada/exp_util.adb | 14 ++++---- gcc/ada/par_sco.adb | 21 +++++------- gcc/ada/sem_ch3.adb | 12 +++---- gcc/ada/sem_ch4.adb | 34 +++++++++---------- gcc/ada/sem_eval.adb | 12 +++---- gcc/ada/sem_util.adb | 95 ++++++++++++++++++++++++---------------------------- 7 files changed, 90 insertions(+), 110 deletions(-) diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 652dbf0422a..8bfbe46315a 100644 --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -3378,13 +3378,11 @@ package body Errout is procedure Remove_Warning_Messages (L : List_Id) is Stat : Node_Id; begin - if Is_Non_Empty_List (L) then - Stat := First (L); - while Present (Stat) loop - Remove_Warning_Messages (Stat); - Next (Stat); - end loop; - end if; + Stat := First (L); + while Present (Stat) loop + Remove_Warning_Messages (Stat); + Next (Stat); + end loop; end Remove_Warning_Messages; -------------------- diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 99372e39fcf..7a3e4b597e8 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -9495,14 +9495,12 @@ package body Exp_Util is begin W := Warn; - if Is_Non_Empty_List (L) then - N := First (L); - while Present (N) loop - Kill_Dead_Code (N, W); - W := False; - Next (N); - end loop; - end if; + N := First (L); + while Present (N) loop + Kill_Dead_Code (N, W); + W := False; + Next (N); + end loop; end Kill_Dead_Code; ----------------------------- diff --git a/gcc/ada/par_sco.adb b/gcc/ada/par_sco.adb index 09e4d500249..5ddd213ae2e 100644 --- a/gcc/ada/par_sco.adb +++ b/gcc/ada/par_sco.adb @@ -2417,21 +2417,18 @@ package body Par_SCO is -- Loop through statements or declarations - if Is_Non_Empty_List (L) then - N := First (L); - while Present (N) loop + N := First (L); + while Present (N) loop - -- Note: For separate bodies, we see the tree after Par.Labl has - -- introduced implicit labels, so we need to ignore those nodes. + -- Note: For separate bodies, we see the tree after Par.Labl has + -- introduced implicit labels, so we need to ignore those nodes. - if Nkind (N) /= N_Implicit_Label_Declaration then - Traverse_One (N); - end if; - - Next (N); - end loop; + if Nkind (N) /= N_Implicit_Label_Declaration then + Traverse_One (N); + end if; - end if; + Next (N); + end loop; -- End sequence of statements and flush deferred decisions diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index d05fbcd26a6..7643cd16377 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -9351,13 +9351,11 @@ package body Sem_Ch3 is declare Iface : Node_Id; begin - if Is_Non_Empty_List (Interface_List (Type_Def)) then - Iface := First (Interface_List (Type_Def)); - while Present (Iface) loop - Freeze_Before (N, Etype (Iface)); - Next (Iface); - end loop; - end if; + Iface := First (Interface_List (Type_Def)); + while Present (Iface) loop + Freeze_Before (N, Etype (Iface)); + Next (Iface); + end loop; end; end if; diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index bf453f2a5db..36ebf37859f 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -9597,31 +9597,29 @@ package body Sem_Ch4 is begin Error := False; - if Is_Non_Empty_List (Intface_List) then - Intface := First (Intface_List); - while Present (Intface) loop + Intface := First (Intface_List); + while Present (Intface) loop - -- Look for acceptable class-wide homonyms associated with - -- the interface. + -- Look for acceptable class-wide homonyms associated with the + -- interface. - Traverse_Homonyms (Etype (Intface), Error); + Traverse_Homonyms (Etype (Intface), Error); - if Error then - return; - end if; + if Error then + return; + end if; - -- Continue the search by looking at each of the interface's - -- associated interface ancestors. + -- Continue the search by looking at each of the interface's + -- associated interface ancestors. - Traverse_Interfaces (Etype (Intface), Error); + Traverse_Interfaces (Etype (Intface), Error); - if Error then - return; - end if; + if Error then + return; + end if; - Next (Intface); - end loop; - end if; + Next (Intface); + end loop; end Traverse_Interfaces; -- Start of processing for Try_Class_Wide_Operation diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 7270172dce9..33303c4015b 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -7479,13 +7479,11 @@ package body Sem_Eval is procedure Why_Not_Static_List (L : List_Id) is N : Node_Id; begin - if Is_Non_Empty_List (L) then - N := First (L); - while Present (N) loop - Why_Not_Static (N); - Next (N); - end loop; - end if; + N := First (L); + while Present (N) loop + Why_Not_Static (N); + Next (N); + end loop; end Why_Not_Static_List; -- Start of processing for Why_Not_Static diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 3cf94292f79..48f4bfb7d92 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6046,31 +6046,29 @@ package body Sem_Util is -- Traverse the graph of ancestor interfaces - if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then - Id := First (Abstract_Interface_List (Full_T)); - while Present (Id) loop - Iface := Etype (Id); - - -- Protect against wrong uses. For example: - -- type I is interface; - -- type O is tagged null record; - -- type Wrong is new I and O with null record; -- ERROR - - if Is_Interface (Iface) then - if Exclude_Parents - and then Etype (T) /= T - and then Interface_Present_In_Ancestor (Etype (T), Iface) - then - null; - else - Collect (Iface); - Append_Unique_Elmt (Iface, Ifaces_List); - end if; + Id := First (Abstract_Interface_List (Full_T)); + while Present (Id) loop + Iface := Etype (Id); + + -- Protect against wrong uses. For example: + -- type I is interface; + -- type O is tagged null record; + -- type Wrong is new I and O with null record; -- ERROR + + if Is_Interface (Iface) then + if Exclude_Parents + and then Etype (T) /= T + and then Interface_Present_In_Ancestor (Etype (T), Iface) + then + null; + else + Collect (Iface); + Append_Unique_Elmt (Iface, Ifaces_List); end if; + end if; - Next (Id); - end loop; - end if; + Next (Id); + end loop; end Collect; -- Start of processing for Collect_Interfaces @@ -13024,18 +13022,15 @@ package body Sem_Util is Node : Node_Id; begin - if Is_Non_Empty_List (L) then - Node := First (L); + Node := First (L); - loop - if Nkind (Node) not in N_Null_Statement | N_Call_Marker then - return True; - end if; + while Present (Node) loop + if Nkind (Node) not in N_Null_Statement | N_Call_Marker then + return True; + end if; - Next (Node); - exit when Node = Empty; - end loop; - end if; + Next (Node); + end loop; return False; end Has_Non_Null_Statements; @@ -13094,28 +13089,26 @@ package body Sem_Util is Node : Node_Id; begin - if Is_Non_Empty_List (L) then - Node := First (L); + Node := First (L); - loop - case Nkind (Node) is - when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error => - null; - when N_Object_Declaration => - if Present (Expression (Node)) - and then not Side_Effect_Free (Expression (Node)) - then - return False; - end if; + while Present (Node) loop + case Nkind (Node) is + when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error => + null; - when others => + when N_Object_Declaration => + if Present (Expression (Node)) + and then not Side_Effect_Free (Expression (Node)) + then return False; - end case; + end if; - Next (Node); - exit when Node = Empty; - end loop; - end if; + when others => + return False; + end case; + + Next (Node); + end loop; return True; end Side_Effect_Free_Statements;