@@ -70,6 +70,8 @@ with Ada.Strings.Fixed;
7070
7171with TGen.Libgen ;
7272
73+ with Libadalang.Common ;
74+
7375package body Test.Actions is
7476
7577 SPT : GNATCOLL.Projects.Project_Tree
@@ -237,6 +239,7 @@ package body Test.Actions is
237239 return Result;
238240 end Process_Comma_Separated_String ;
239241
242+ use Ada.Strings.Fixed;
240243 begin
241244 GNATCOLL.Traces.Parse_Config_File;
242245 Test.Common.Verbose := Arg (Cmd, Verbose);
@@ -250,6 +253,34 @@ package body Test.Actions is
250253 return ;
251254 end if ;
252255
256+ declare
257+ Subp_Hash : constant String_Access := Arg (Cmd, Dump_Subp_Hash);
258+ Separator_Index : constant Natural :=
259+ (if Subp_Hash /= null then Index (Subp_Hash.all , " :" , 1 ) else 0 );
260+ begin
261+ if Subp_Hash /= null then
262+ if Separator_Index = 0 then
263+ Cmd_Error_No_Help
264+ (" Unexpected format for --dump-subp-hash, expected <filename>"
265+ & " :<line>" );
266+ end if ;
267+ Test.Common.Subp_File_Name :=
268+ new String'(Subp_Hash.all (1 .. Separator_Index - 1 ));
269+ begin
270+ Test.Common.Subp_Line_Nbr :=
271+ Natural'Value
272+ ((Subp_Hash.all (Separator_Index + 1 .. Subp_Hash'Length)));
273+ exception
274+ when others =>
275+ Cmd_Error_No_Help (" <line> must be a Natural." );
276+ end ;
277+ Utils.Command_Lines.Append_File_Name
278+ (Cmd, Test.Common.Subp_File_Name.all );
279+ Test.Common.Quiet := True;
280+ return ;
281+ end if ;
282+ end ;
283+
253284 Test.Common.Instrument := Arg (Cmd, Dump_Test_Inputs);
254285
255286 Test.Common.Lang_Version :=
@@ -1135,10 +1166,18 @@ package body Test.Actions is
11351166 -- ---------
11361167
11371168 procedure Final (Tool : in out Test_Tool; Cmd : Command_Line) is
1169+ use Ada.Strings.Unbounded;
11381170 Src_Prj : constant String :=
11391171 Tool.Project_Tree.Root_Project.Project_Path.Display_Full_Name;
11401172 begin
11411173
1174+ -- Abort here if we the switch --dump-subp-hash is on. This return
1175+ -- should not be moved further down.
1176+
1177+ if Test.Common.Subp_File_Name /= null then
1178+ return ;
1179+ end if ;
1180+
11421181 -- If the tool project is an aggregate one, exit early and do nothing.
11431182 -- The aggregated projects will be processed in sequence in subprocess
11441183 -- calls made by the driver.
@@ -1238,6 +1277,8 @@ package body Test.Actions is
12381277 BOM_Seen : Boolean;
12391278 Unit : Analysis_Unit)
12401279 is
1280+ use Libadalang.Common;
1281+ use Ada.Strings.Unbounded;
12411282 pragma Unreferenced (Tool, Input, BOM_Seen); -- ????
12421283 begin
12431284 if Debug_Flag_V then
@@ -1246,6 +1287,40 @@ package body Test.Actions is
12461287 PP_Trivia (Unit);
12471288 end if ;
12481289
1290+ if Test.Common.Subp_File_Name /= null
1291+ and then Test.Common.Subp_File_Name.all = File_Name
1292+ then
1293+ declare
1294+ Found_Hash : Boolean := False;
1295+
1296+ function Visit (Node : Ada_Node'Class) return Visit_Status;
1297+
1298+ function Visit (Node : Ada_Node'Class) return Visit_Status is
1299+ begin
1300+ if Kind (Node) in Ada_Basic_Subp_Decl
1301+ and then Natural (Node.Sloc_Range.Start_Line)
1302+ = Test.Common.Subp_Line_Nbr
1303+ then
1304+ Ada.Text_IO.Put (Test.Common.Mangle_Hash_16 (Node));
1305+ Found_Hash := True;
1306+ return Stop;
1307+ end if ;
1308+ return Into;
1309+ end Visit ;
1310+ begin
1311+ Traverse (Root (Unit), Visit'Access );
1312+ if not Found_Hash then
1313+ Ada.Text_IO.Put
1314+ (" Subprogram in "
1315+ & Test.Common.Subp_File_Name.all
1316+ & " at line "
1317+ & Natural'Image (Test.Common.Subp_Line_Nbr)
1318+ & " could not be found." );
1319+ end if ;
1320+ return ;
1321+ end ;
1322+ end if ;
1323+
12491324 if Test.Common.Harness_Only then
12501325 Test.Harness.Process_Source (Unit);
12511326 else
@@ -1374,6 +1449,8 @@ package body Test.Actions is
13741449 (" --gen-test-num=n - Specify the number of test inputs to be generated (experimental, defaults to 5)\n" );
13751450 Put
13761451 (" --gen-test-subprograms=file:line - Specify a comma separated list of subprograms declared at file:line to generate test cases for\n" );
1452+ Put
1453+ (" --dump-subp-hash=file:line - Print the hash of the subprogram at file:line in the standard output and bypass all other swicthes.\n" );
13771454 Put
13781455 (" --serialized-test-dir=dir - Specify in which directory test inputs should be generated (experimental)\n" );
13791456 Put
0 commit comments