Skip to content

Commit 7c7c6e1

Browse files
committed
lkql_checker: base executable name on Lkql_Checker_Mode
1 parent ecee2e2 commit 7c7c6e1

9 files changed

+41
-28
lines changed

lkql_checker/src/lkql_checker-diagnoses.adb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ package body Lkql_Checker.Diagnoses is
16951695

16961696
procedure Print_Out_Diagnoses is
16971697
Max_Diagnoses : constant Natural :=
1698-
(if Options.Mode = Gnatkp_Mode then 0 else Arg.Max_Diagnoses.Get);
1698+
(if Mode = Gnatkp_Mode then 0 else Arg.Max_Diagnoses.Get);
16991699
Diagnoses_Reported : Natural := 0;
17001700
Limit_Exceeded : Boolean := False;
17011701

@@ -1798,7 +1798,7 @@ package body Lkql_Checker.Diagnoses is
17981798

17991799
Report (Trim (Minute_Of_Check'Img, Left));
18001800

1801-
Report (Executable & " version : " & Version_String);
1801+
Report (Lkql_Checker_Mode_Image & " version : " & Version_String);
18021802

18031803
Report_No_EOL ("command line : ");
18041804
Print_Command_Line;
@@ -1923,7 +1923,7 @@ package body Lkql_Checker.Diagnoses is
19231923
Pragma_Name : constant Text_Type := To_Lower (El.F_Id.Text);
19241924
Pragma_Args : constant LAL.Analysis.Base_Assoc_List := El.F_Args;
19251925
Tool_Name : constant Text_Type :=
1926-
(if Options.Mode = Gnatkp_Mode then "gnatkp" else "gnatcheck");
1926+
(if Mode = Gnatkp_Mode then "gnatkp" else "gnatcheck");
19271927
begin
19281928
return
19291929
Pragma_Name in "annotate" | "gnat_annotate"
@@ -2270,7 +2270,7 @@ package body Lkql_Checker.Diagnoses is
22702270
return;
22712271
end if;
22722272

2273-
if Options.Mode = Gnatkp_Mode then
2273+
if Mode = Gnatkp_Mode then
22742274
Match (Match_Kp_Exempt_Comment, Text, Matches);
22752275
else
22762276
Match (Match_Rule_Exempt_Comment, Text, Matches);

lkql_checker/src/lkql_checker-options.adb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
with GNAT.Command_Line; use GNAT.Command_Line;
2+
with Ada.Command_Line; use Ada.Command_Line;
3+
with Ada.Directories; use Ada.Directories;
24

35
with Lkql_Checker.Output; use Lkql_Checker.Output;
46
with Lkql_Checker.Projects; use Lkql_Checker.Projects;

lkql_checker/src/lkql_checker-options.ads

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
-- This package defines options that are supposed to be of a common interest
77
-- for all the tools.
88

9-
with Ada.Command_Line; use Ada.Command_Line;
10-
with Ada.Directories; use Ada.Directories;
119
with Ada.Environment_Variables;
1210
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
1311

@@ -33,9 +31,6 @@ package Lkql_Checker.Options is
3331
Version_String : constant String :=
3432
Lkql_Checker_Version & " (" & Date & ")";
3533

36-
Executable : constant String := Base_Name (Command_Name);
37-
-- Name of the current executable (e.g. "gnatcheck" or "gnatkp")
38-
3934
Custom_Worker_Var : constant String := "GNATCHECK_WORKER";
4035
-- The name of the environment variable used to define a custom worker
4136
-- executable.
@@ -69,9 +64,6 @@ package Lkql_Checker.Options is
6964
-- tool (includes both wrong parameters and wrong combinations of correct
7065
-- parameters).
7166

72-
Mode : Lkql_Checker_Mode := Gnatcheck_Mode;
73-
-- Set the mode of the driver, either GNATcheck or GNATkp modes.
74-
7567
Legacy : Boolean := False;
7668
-- If True, run in legacy mode, with no support for additional rule files.
7769

@@ -704,10 +696,12 @@ package Lkql_Checker.Options is
704696
-- the specified ``Default_Name``.
705697

706698
function Text_Report_File_Path return String
707-
is (Resolve_Report_File (Text_Output.Get, Executable & ".out"));
699+
is (Resolve_Report_File
700+
(Text_Output.Get, Lkql_Checker_Mode_Image & ".out"));
708701

709702
function XML_Report_File_Path return String
710-
is (Resolve_Report_File (XML_Output.Get, Executable & ".xml"));
703+
is (Resolve_Report_File
704+
(XML_Output.Get, Lkql_Checker_Mode_Image & ".xml"));
711705
end Arg;
712706

713707
--------------------------

lkql_checker/src/lkql_checker-output.adb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ package body Lkql_Checker.Output is
126126
Log_Message : Boolean := False)
127127
is
128128
Final_Message : constant String :=
129-
(if Tool_Name then Executable & ": " else "")
129+
(if Tool_Name then Lkql_Checker_Mode_Image & ": " else "")
130130
& (if Location /= "" then Location & ": " else "")
131131
& (case Tag is
132132
when Info => "info: ",
@@ -255,7 +255,7 @@ package body Lkql_Checker.Output is
255255

256256
procedure Print_Version_Info is
257257
begin
258-
Print (Executable & " " & Version_String);
258+
Print (Lkql_Checker_Mode_Image & " " & Version_String);
259259
Print
260260
("Copyright (C) " & "2004" & '-' & Current_Year & ", AdaCore.",
261261
Log_Message => False);
@@ -363,7 +363,8 @@ package body Lkql_Checker.Output is
363363
begin
364364
if Log_File_Name = null then
365365
Log_File_Name :=
366-
new String'(Global_Report_Dir.all & Executable & ".log");
366+
new String'
367+
(Global_Report_Dir.all & Lkql_Checker_Mode_Image & ".log");
367368
end if;
368369

369370
Open_Or_Create (Log_File_Name.all, Out_File, Log_File);
@@ -432,7 +433,7 @@ package body Lkql_Checker.Output is
432433
begin
433434
pragma Style_Checks ("M200"); -- Allow long lines
434435

435-
if Options.Mode = Gnatkp_Mode then
436+
if Mode = Gnatkp_Mode then
436437
Put_Line ("gnatkp: the GNAT known problem detector");
437438
Put_Line
438439
("usage: gnatkp -Pproject [options] [-rules [-from=file] {+Rkp_id[:param]}]");

lkql_checker/src/lkql_checker-projects-aggregate.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ package body Lkql_Checker.Projects.Aggregate is
199199
Exit_Code : Integer;
200200

201201
Full_Tool_Name : constant String_Access :=
202-
Locate_Exec_On_Path (Executable);
202+
Locate_Exec_On_Path (Lkql_Checker_Mode_Image);
203203

204204
begin
205205
if Full_Tool_Name = null then
206206
Error
207207
("cannot locate "
208-
& Executable
208+
& Lkql_Checker_Mode_Image
209209
& " on PATH, possible installation problem");
210210
raise Fatal_Error;
211211
end if;

lkql_checker/src/lkql_checker-projects.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ package body Lkql_Checker.Projects is
11691169
-- If GNATcheck is in KP mode and there is a command line specified KP
11701170
-- version, we have to iterate over all implemented rules to enable
11711171
-- those which match the version.
1172-
if Options.Mode = Gnatkp_Mode
1172+
if Mode = Gnatkp_Mode
11731173
and then Arg.KP_Version.Get /= Null_Unbounded_String
11741174
then
11751175
for Rule_Cursor in All_Rules.Iterate loop
@@ -1211,7 +1211,7 @@ package body Lkql_Checker.Projects is
12111211
Active_Rule_Present := not All_Rule_Instances.Is_Empty;
12121212

12131213
if not (Active_Rule_Present or else Analyze_Compiler_Output) then
1214-
if Options.Mode = Gnatkp_Mode
1214+
if Mode = Gnatkp_Mode
12151215
and then Arg.KP_Version.Get /= Null_Unbounded_String
12161216
then
12171217
Error ("no rule for the given kp-version");

lkql_checker/src/lkql_checker-rules-rule_table.adb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ package body Lkql_Checker.Rules.Rule_Table is
15561556
Set : Rule_Sets.Set;
15571557

15581558
begin
1559-
if Options.Mode = Gnatkp_Mode then
1559+
if Mode = Gnatkp_Mode then
15601560
Print ("gnatkp currently implements the following detectors:");
15611561

15621562
if Arg.KP_Version.Get /= Null_Unbounded_String then
@@ -1592,7 +1592,9 @@ package body Lkql_Checker.Rules.Rule_Table is
15921592
end loop;
15931593
end if;
15941594
else
1595-
Print (Executable & " currently implements the following rules:");
1595+
Print
1596+
(Lkql_Checker_Mode_Image
1597+
& " currently implements the following rules:");
15961598

15971599
for Rule in All_Rules.Iterate loop
15981600
Set.Include (All_Rules (Rule));
@@ -1607,7 +1609,7 @@ package body Lkql_Checker.Rules.Rule_Table is
16071609
end if;
16081610

16091611
Print
1610-
(Executable
1612+
(Lkql_Checker_Mode_Image
16111613
& " allows activation of the following checks "
16121614
& "provided by GNAT");
16131615
Print

lkql_checker/src/lkql_checker.ads

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77

88
package Lkql_Checker is
99
type Lkql_Checker_Mode is (Gnatcheck_Mode, Gnatkp_Mode);
10+
11+
Mode : Lkql_Checker_Mode;
12+
-- The mode of the driver, either GNATcheck or GNATkp.
13+
14+
function Lkql_Checker_Mode_Image return String;
15+
-- Get the Lkql_Checker_Mode image.
16+
--
17+
-- TODO: Use the Put_Image attribute for Lkql_Checker_Mode instead when
18+
-- switching to Ada_2022.
19+
private
20+
function Lkql_Checker_Mode_Name (Mode : Lkql_Checker_Mode) return String;
21+
-- Return the name associated to the given Mode.
1022
end Lkql_Checker;

lkql_checker/src/main.adb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ procedure Main (Mode : Lkql_Checker_Mode) is
391391

392392
use Ada.Strings.Unbounded;
393393
begin
394-
-- Set GNATcheck mode
395-
Lkql_Checker.Options.Mode := Mode;
394+
-- Set the Lkql_Checker global mode
395+
Lkql_Checker.Mode := Mode;
396396

397397
Initialize_Environment;
398398

@@ -663,7 +663,9 @@ exception
663663
when Parameter_Error =>
664664
-- The diagnosis is already generated
665665
Print
666-
("try """ & Executable & " --help"" for more information.",
666+
("try """
667+
& Lkql_Checker_Mode_Image
668+
& " --help"" for more information.",
667669
Log_Message => False);
668670
OS_Exit (E_Error);
669671

0 commit comments

Comments
 (0)