Skip to content

Commit f6b3f52

Browse files
committed
Merge branch 'pmderodat/refactoring' into 'master'
instrument-projects.adb: minor refactorings See merge request eng/das/cov/gnatcoverage!339 For eng/das/cov/gnatcoverage#84
2 parents 66fd041 + 167e4bc commit f6b3f52

File tree

1 file changed

+101
-115
lines changed

1 file changed

+101
-115
lines changed

tools/gnatcov/instrument-projects.adb

Lines changed: 101 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
------------------------------------------------------------------------------
1818

1919
with Ada.Characters.Handling; use Ada.Characters.Handling;
20-
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
2120
with Ada.Containers.Hashed_Maps;
2221
with Ada.Containers.Indefinite_Ordered_Maps;
2322
with Ada.Containers.Indefinite_Ordered_Sets;
@@ -853,131 +852,123 @@ is
853852
-- that belong to a non-root project.
854853

855854
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.
855+
for Source of Project_Sources loop
856+
if To_Language (Source.Language) = Language then
857+
declare
858+
use Prj_Has_Manual_Helper_Sets;
859+
860+
Prj_Info : constant Project_Info_Access :=
861+
Get_Or_Create_Project_Info (IC, Source.Project);
862+
Prj : Prj_Desc renames Prj_Info.Desc;
863+
Is_Root_Prj : constant Boolean :=
864+
Prj.Prj_Name = Root_Project_Info.Project.Name;
865+
Source_Name : constant String :=
866+
GNATCOLL.VFS."+" (Source.File.Full_Name);
867+
Helper_Unit : Unbounded_String;
868+
Contained_Indication : Boolean := False;
869+
begin
870+
Instrumenter.Replace_Manual_Dump_Indication
871+
(Contained_Indication,
872+
Prj_Info.Desc,
873+
Source);
897874

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);
875+
if Contained_Indication and then not Is_Root_Prj then
903876

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;
877+
-- A call to the dump buffers procedure is only able to dump
878+
-- the buffers of the project it is in and its subprojects,
879+
-- meaning coverage data for all projects higher in the
880+
-- project tree will be missing. Record what file this call
881+
-- was in to warn the user later.
935882

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.
883+
Non_Root_Src_Calls.Include (Source_Name);
884+
end if;
939885

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

945-
GNATCOLL.VFS.Unchecked_Free (Source_Files);
946-
end;
937+
GNATCOLL.VFS.Unchecked_Free (Source_Files);
938+
end;
947939

948-
Prj_Has_Manual_Helper.Insert (Prj.Prj_Name);
949-
end if;
940+
Prj_Has_Manual_Helper.Insert (Prj.Prj_Name);
941+
end if;
950942

951-
Manual_Dump_Inserted :=
952-
Manual_Dump_Inserted or else Contained_Indication;
953-
end;
954-
end if;
955-
end;
943+
Manual_Dump_Inserted :=
944+
Manual_Dump_Inserted or else Contained_Indication;
945+
end;
946+
end if;
956947
end loop;
957948

958949
if not Non_Root_Src_Calls.Is_Empty then
950+
959951
-- For each manual dump call inserted in a file belonging to a
960952
-- non-root project, warn the user the coverage data it will produce
961953
-- will not cover the whole project tree.
962954

963955
declare
964-
All_File_Names : Unbounded_String := +"";
956+
All_File_Names : Unbounded_String;
965957
begin
966958
for File_Name of Non_Root_Src_Calls loop
967-
All_File_Names :=
968-
All_File_Names & (+File_Name) & Ada.Characters.Latin_1.LF;
959+
Append (All_File_Names, File_Name);
960+
Append (All_File_Names, ASCII.LF);
969961
end loop;
970962

971-
Outputs.Warn ("Manual dump trigger indications were found in"
972-
& " subprojects in the following files:"
973-
& Ada.Characters.Latin_1.LF
974-
& (+All_File_Names)
975-
& "The coverage report built from the source traces"
976-
& " they will produce will show all code from"
977-
& " projects higher in the project tree as not"
978-
& " covered. To get a full coverage analysis,"
979-
& " consider placing the manual dump buffers"
980-
& " indication in the root project.");
963+
Outputs.Warn
964+
("Manual dump trigger indications were found in subprojects in"
965+
& " the following files:" & ASCII.LF
966+
& (+All_File_Names)
967+
& "The coverage report built from the source traces they will"
968+
& " produce will show all code from projects higher in the"
969+
& " project tree as not covered. To get a full coverage"
970+
& " analysis, consider placing the manual dump buffers"
971+
& " indication in the root project.");
981972
end;
982973
end if;
983974
end Insert_Manual_Dump_Trigger;
@@ -1047,7 +1038,7 @@ is
10471038
C_Language => C_Instrumenter'Access,
10481039
CPP_Language => CPP_Instrumenter'Access);
10491040

1050-
-- Start of processing for Instrument_Units_Of_Interest
1041+
-- Start of processing for Instrument_Units_Of_Interest
10511042

10521043
begin
10531044
-- Set the instrumentation tag
@@ -1212,6 +1203,7 @@ begin
12121203
CPP_Instrumenter := Create_CPP_Instrumenter (IC.Tag);
12131204

12141205
if Dump_Config.Trigger = Manual then
1206+
12151207
-- Replace manual dump indications for C-like languages
12161208

12171209
for Lang in C_Family_Language loop
@@ -1257,7 +1249,6 @@ begin
12571249
Instrument_Source_Args.Append
12581250
(Common_Switches (Cmd_Instrument_Source));
12591251
for Cur in Instrumented_Sources.Iterate loop
1260-
12611252
declare
12621253
Unit_Args : String_Vectors.Vector :=
12631254
Instrument_Source_Args.Copy;
@@ -1283,12 +1274,7 @@ begin
12831274

12841275
-- Add the arguments that are specific to the compilation unit
12851276

1286-
Unit_Args.Append
1287-
(Compilation_Unit_Options
1288-
(IC,
1289-
Desc,
1290-
LU_Info));
1291-
1277+
Unit_Args.Append (Compilation_Unit_Options (IC, Desc, LU_Info));
12921278
Unit_Args.Append (+"--sid=" & Obj_SID);
12931279

12941280
-- We instrument the body, spec and separates as a whole

0 commit comments

Comments
 (0)