Skip to content

Commit e200232

Browse files
committed
instrument-projects.adb: remove useless use of container cursor
In a container iteration through a "for Cur in Container.Iterate" loop, the cursor is used only once, to get access to the container element. Switch to the "for Item of Container" loop instead to simplify the code (no need for a declare block anymore: less nesting involved).
1 parent 66fd041 commit e200232

File tree

1 file changed

+85
-93
lines changed

1 file changed

+85
-93
lines changed

tools/gnatcov/instrument-projects.adb

Lines changed: 85 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -853,106 +853,98 @@ is
853853
-- that belong to a non-root project.
854854

855855
begin
856-
for Source_C in Project_Sources.Iterate loop
857-
declare
858-
Source : constant File_Info := File_Info_Sets.Element (Source_C);
859-
begin
860-
if To_Language (Source.Language) = Language then
861-
declare
862-
use Prj_Has_Manual_Helper_Sets;
863-
864-
Prj_Info : constant Project_Info_Access :=
865-
Get_Or_Create_Project_Info (IC, Source.Project);
866-
Prj : Prj_Desc renames Prj_Info.Desc;
867-
Is_Root_Prj : constant Boolean :=
868-
Prj.Prj_Name = Root_Project_Info.Project.Name;
869-
Source_Name : constant String :=
870-
GNATCOLL.VFS."+" (Source.File.Full_Name);
871-
Helper_Unit : Unbounded_String;
872-
Contained_Indication : Boolean := False;
873-
874-
begin
875-
Instrumenter.Replace_Manual_Dump_Indication
876-
(Contained_Indication,
877-
Prj_Info.Desc,
878-
Source);
879-
880-
if Contained_Indication and then not Is_Root_Prj
881-
then
882-
-- A call to the dump buffers procedure is only able to
883-
-- dump the buffers of the project it is in and its
884-
-- subprojects, meaning coverage data for all projects
885-
-- higher in the project tree will be missing. Record
886-
-- what file this call was in to warn the user later.
887-
888-
Non_Root_Src_Calls.Include (Source_Name);
889-
end if;
890-
891-
-- Only generate one manual dump helper unit per project.
892-
-- At this point, if the project's object directory and the
893-
-- instrumented sources directory do not exist there is no
894-
-- need to emit the dump helper unit. There are no units of
895-
-- interest or call to a manual dump procedure for this
896-
-- project.
856+
for Source of Project_Sources loop
857+
if To_Language (Source.Language) = Language then
858+
declare
859+
use Prj_Has_Manual_Helper_Sets;
860+
861+
Prj_Info : constant Project_Info_Access :=
862+
Get_Or_Create_Project_Info (IC, Source.Project);
863+
Prj : Prj_Desc renames Prj_Info.Desc;
864+
Is_Root_Prj : constant Boolean :=
865+
Prj.Prj_Name = Root_Project_Info.Project.Name;
866+
Source_Name : constant String :=
867+
GNATCOLL.VFS."+" (Source.File.Full_Name);
868+
Helper_Unit : Unbounded_String;
869+
Contained_Indication : Boolean := False;
870+
begin
871+
Instrumenter.Replace_Manual_Dump_Indication
872+
(Contained_Indication,
873+
Prj_Info.Desc,
874+
Source);
897875

898-
if Prj_Has_Manual_Helper.Find (Prj.Prj_Name) = No_Element
899-
and then Dump_Helper_Output_Dir_Exists (Source, Prj)
900-
then
901-
Instrumenter.Emit_Dump_Helper_Unit_Manual
902-
(Helper_Unit, Dump_Config, Prj);
876+
if Contained_Indication and then not Is_Root_Prj then
903877

904-
declare
905-
use Files_Table;
906-
Instr_Units : Unit_Sets.Set;
907-
Source_Files : GNATCOLL.VFS.File_Array_Access
908-
:= Source.Project.Source_Files (Recursive => True);
909-
begin
910-
for S of Source_Files.all loop
911-
declare
912-
use Unit_Maps;
913-
Unit_C : constant Unit_Maps.Cursor :=
914-
Instrumented_Sources.Find
915-
(+To_Compilation_Unit
916-
(Project.Project.Info (S)).Unit_Name);
917-
begin
918-
if Unit_C /= Unit_Maps.No_Element then
919-
declare
920-
Unit : constant Library_Unit_Info :=
921-
Element (Unit_C);
922-
Instr_Unit : constant Compilation_Unit :=
923-
Compilation_Unit'
924-
(Unit.Language_Kind,
925-
Unit.Unit_Name);
926-
begin
927-
if not Instr_Units.Contains (Instr_Unit)
928-
then
929-
Instr_Units.Insert (Instr_Unit);
930-
end if;
931-
end;
932-
end if;
933-
end;
934-
end loop;
878+
-- A call to the dump buffers procedure is only able to dump
879+
-- the buffers of the project it is in and its subprojects,
880+
-- meaning coverage data for all projects higher in the
881+
-- project tree will be missing. Record what file this call
882+
-- was in to warn the user later.
935883

936-
-- The creation of the root project's buffers list
937-
-- unit is already taken care of by the regular
938-
-- instrumentation process, so skip it.
884+
Non_Root_Src_Calls.Include (Source_Name);
885+
end if;
939886

940-
if not Is_Root_Prj then
941-
Instrumenter.Emit_Buffers_List_Unit
942-
(Instr_Units, Prj);
943-
end if;
887+
-- Only generate one manual dump helper unit per project. At
888+
-- this point, if the project's object directory and the
889+
-- instrumented sources directory do not exist there is no need
890+
-- to emit the dump helper unit. There are no units of interest
891+
-- or call to a manual dump procedure for this project.
892+
893+
if Prj_Has_Manual_Helper.Find (Prj.Prj_Name) = No_Element
894+
and then Dump_Helper_Output_Dir_Exists (Source, Prj)
895+
then
896+
Instrumenter.Emit_Dump_Helper_Unit_Manual
897+
(Helper_Unit, Dump_Config, Prj);
898+
899+
declare
900+
use Files_Table;
901+
Instr_Units : Unit_Sets.Set;
902+
Source_Files : GNATCOLL.VFS.File_Array_Access :=
903+
Source.Project.Source_Files (Recursive => True);
904+
begin
905+
for S of Source_Files.all loop
906+
declare
907+
use Unit_Maps;
908+
Unit_C : constant Unit_Maps.Cursor :=
909+
Instrumented_Sources.Find
910+
(+To_Compilation_Unit
911+
(Project.Project.Info (S)).Unit_Name);
912+
begin
913+
if Unit_C /= Unit_Maps.No_Element then
914+
declare
915+
Unit : constant Library_Unit_Info :=
916+
Element (Unit_C);
917+
Instr_Unit : constant Compilation_Unit :=
918+
Compilation_Unit'
919+
(Unit.Language_Kind,
920+
Unit.Unit_Name);
921+
begin
922+
if not Instr_Units.Contains (Instr_Unit) then
923+
Instr_Units.Insert (Instr_Unit);
924+
end if;
925+
end;
926+
end if;
927+
end;
928+
end loop;
929+
930+
-- The creation of the root project's buffers list unit
931+
-- is already taken care of by the regular
932+
-- instrumentation process, so skip it.
933+
934+
if not Is_Root_Prj then
935+
Instrumenter.Emit_Buffers_List_Unit (Instr_Units, Prj);
936+
end if;
944937

945-
GNATCOLL.VFS.Unchecked_Free (Source_Files);
946-
end;
938+
GNATCOLL.VFS.Unchecked_Free (Source_Files);
939+
end;
947940

948-
Prj_Has_Manual_Helper.Insert (Prj.Prj_Name);
949-
end if;
941+
Prj_Has_Manual_Helper.Insert (Prj.Prj_Name);
942+
end if;
950943

951-
Manual_Dump_Inserted :=
952-
Manual_Dump_Inserted or else Contained_Indication;
953-
end;
954-
end if;
955-
end;
944+
Manual_Dump_Inserted :=
945+
Manual_Dump_Inserted or else Contained_Indication;
946+
end;
947+
end if;
956948
end loop;
957949

958950
if not Non_Root_Src_Calls.Is_Empty then

0 commit comments

Comments
 (0)