From e8a21ffe5226aad4970bd1facd4a3464a4b436f1 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sat, 11 Nov 2017 08:48:28 +0100 Subject: Rework list implementation, use iterator. --- src/ghdldrv/ghdlcomp.adb | 17 +++++++++++------ src/ghdldrv/ghdllocal.adb | 16 ++++++++++------ src/ghdldrv/ghdlxml.adb | 10 ++++++---- 3 files changed, 27 insertions(+), 16 deletions(-) (limited to 'src/ghdldrv') diff --git a/src/ghdldrv/ghdlcomp.adb b/src/ghdldrv/ghdlcomp.adb index 9b45584d2..56487b863 100644 --- a/src/ghdldrv/ghdlcomp.adb +++ b/src/ghdldrv/ghdlcomp.adb @@ -594,6 +594,7 @@ package body Ghdlcomp is Files_List : Iir_List; File : Iir_Design_File; + It : List_Iterator; Next_Arg : Natural; Date : Date_Type; @@ -614,9 +615,9 @@ package body Ghdlcomp is end loop; Date := Get_Date (Libraries.Work_Library); - for I in Natural loop - File := Get_Nth_Element (Files_List, I); - exit when File = Null_Iir; + It := List_Iterate (Files_List); + while Is_Valid (It) loop + File := Get_Element (It); if File = Std_Package.Std_Standard_File then null; @@ -645,6 +646,8 @@ package body Ghdlcomp is -- Need to be written to disk. Set_Elab_Flag (Lib, True); end if; + + Next (It); end loop; -- Save modified libraries. @@ -730,6 +733,7 @@ package body Ghdlcomp is HT : constant Character := Ada.Characters.Latin_1.HT; Files_List : Iir_List; File : Iir_Design_File; + Files_It : List_Iterator; Lib : Iir_Library_Declaration; Dir_Id : Name_Id; @@ -820,9 +824,9 @@ package body Ghdlcomp is Put_Line ("# Targets to analyze libraries"); Put_Line ("init: force"); - for I in Natural loop - File := Get_Nth_Element (Files_List, I); - exit when File = Null_Iir; + Files_It := List_Iterate (Files_List); + while Is_Valid (Files_It) loop + File := Get_Element (Files_It); Dir_Id := Get_Design_File_Directory (File); if not Is_Makeable_File (File) then -- Builtin file. @@ -853,6 +857,7 @@ package body Ghdlcomp is Put (Image (Get_Design_File_Filename (File))); New_Line; end if; + Next (Files_It); end loop; New_Line; diff --git a/src/ghdldrv/ghdllocal.adb b/src/ghdldrv/ghdllocal.adb index 88c887418..ff3531c27 100644 --- a/src/ghdldrv/ghdllocal.adb +++ b/src/ghdldrv/ghdllocal.adb @@ -1274,6 +1274,7 @@ package body Ghdllocal is is El : Iir_Design_File; Depend_List : Iir_List; + Depend_It : List_Iterator; begin if Get_Elab_Flag (File) then return; @@ -1282,10 +1283,11 @@ package body Ghdllocal is Set_Elab_Flag (File, True); Depend_List := Get_File_Dependence_List (File); if Depend_List /= Null_Iir_List then - for I in Natural loop - El := Get_Nth_Element (Depend_List, I); - exit when El = Null_Iir; + Depend_It := List_Iterate (Depend_List); + while Is_Valid (Depend_It) loop + El := Get_Element (Depend_It); Build_Dependence_List (El, List); + Next (Depend_It); end loop; end if; Append_Element (List, File); @@ -1450,14 +1452,15 @@ package body Ghdllocal is Depends : constant Iir_List := Get_Dependence_List (Unit); Stamp : constant Time_Stamp_Id := Get_Analysis_Time_Stamp (File); + Depends_It : List_Iterator; El : Iir; Dep : Iir_Design_Unit; Dep_File : Iir_Design_File; begin if Depends /= Null_Iir_List then - for I in Natural loop - El := Get_Nth_Element (Depends, I); - exit when El = Null_Iir; + Depends_It := List_Iterate (Depends); + while Is_Valid (Depends_It) loop + El := Get_Element (Depends_It); Dep := Libraries.Find_Design_Unit (El); if Dep = Null_Iir then if Flag_Verbose then @@ -1483,6 +1486,7 @@ package body Ghdllocal is end if; return True; end if; + Next (Depends_It); end loop; end if; end; diff --git a/src/ghdldrv/ghdlxml.adb b/src/ghdldrv/ghdlxml.adb index 6bad81aad..9913aaf76 100644 --- a/src/ghdldrv/ghdlxml.adb +++ b/src/ghdldrv/ghdlxml.adb @@ -234,6 +234,7 @@ package body Ghdlxml is procedure Disp_Iir_List (Id : String; L : Iir_List; Ref : Boolean) is El : Iir; + It : List_Iterator; begin case L is when Null_Iir_List => @@ -249,14 +250,15 @@ package body Ghdlxml is Put_Attribute ("list-id", Strip (Iir_List'Image (L))); Put_Stag_End; - for I in Natural loop - El := Get_Nth_Element (L, I); - exit when El = Null_Iir; + It := List_Iterate (L); + while Is_Valid (It) loop + El := Get_Element (It); if Ref then - Disp_Iir_Ref ("el", El); + Disp_Iir_Ref ("el", El); else Disp_Iir ("el", El); end if; + Next (It); end loop; Put_Etag (Id); -- cgit v1.2.3