Skip to content

Commit 39d7dc7

Browse files
committed
Migrate the '--kp-version' switch to Opt_Parse
1 parent 7f86002 commit 39d7dc7

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

lkql_checker/src/gnatcheck-options.adb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ package body Gnatcheck.Options is
261261
end if;
262262

263263
loop
264-
Initial_Char := Getopt ("-kp-version= ", Parser => Parser);
264+
Initial_Char := Getopt (" ", Parser => Parser);
265265

266266
case Initial_Char is
267267
when ASCII.NUL =>
@@ -291,14 +291,6 @@ package body Gnatcheck.Options is
291291

292292
exit when not Success;
293293

294-
when '-' =>
295-
if not First_Pass then
296-
if Full_Switch (Parser => Parser) = "-kp-version" then
297-
Free (KP_Version);
298-
KP_Version := new String'(Parameter (Parser => Parser));
299-
end if;
300-
end if;
301-
302294
when others =>
303295
Error
304296
("unrecognized switch: " & Full_Switch (Parser => Parser));

lkql_checker/src/gnatcheck-options.ads

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ package Gnatcheck.Options is
7575
Legacy : Boolean := False;
7676
-- If True, run in legacy mode, with no support for additional rule files.
7777

78-
KP_Version : GNAT.OS_Lib.String_Access;
79-
-- If set, the relevant GNAT version to check when running gnatkp.
80-
8178
Exempted_Units : GNAT.OS_Lib.String_Access := null;
8279
-- '--ignore=<filename>
8380
-- File containing a list of units to be exempted. (Depending on a tool,
@@ -279,6 +276,15 @@ package Gnatcheck.Options is
279276
"specify the charset of the source files (default is "
280277
& "latin-1)");
281278

279+
package KP_Version is new
280+
Parse_Option
281+
(Parser => Parser,
282+
Long => "--kp-version",
283+
Name => "KP version",
284+
Arg_Type => Unbounded_String,
285+
Default_Val => Null_Unbounded_String,
286+
Help => "enable all KP detectors matching GNAT <version>");
287+
282288
package Lkql_Path is new
283289
Parse_Option_List
284290
(Parser => Parser,

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,15 +1206,16 @@ package body Gnatcheck.Projects is
12061206
-- If GNATcheck is in KP mode and there is a command line specified KP
12071207
-- version, we have to iterate over all implemented rules to enable
12081208
-- those which match the version.
1209-
if Gnatkp_Mode and then KP_Version /= null then
1209+
if Gnatkp_Mode and then Arg.KP_Version.Get /= Null_Unbounded_String then
12101210
for Rule_Cursor in All_Rules.Iterate loop
12111211
declare
12121212
Id : constant Rule_Id := Rule_Map.Key (Rule_Cursor);
12131213
Rule : constant Rule_Info := All_Rules (Rule_Cursor);
12141214
Instance : Rule_Instance_Access;
12151215
begin
12161216
if Rule.Impact /= null
1217-
and then Match (KP_Version.all, Rule.Impact.all)
1217+
and then Match
1218+
(To_String (Arg.KP_Version.Get), Rule.Impact.all)
12181219
then
12191220
if Rule.Target /= null
12201221
and then Target /= Null_Unbounded_String
@@ -1245,7 +1246,8 @@ package body Gnatcheck.Projects is
12451246
Active_Rule_Present := not All_Rule_Instances.Is_Empty;
12461247

12471248
if not (Active_Rule_Present or else Analyze_Compiler_Output) then
1248-
if Gnatkp_Mode and then KP_Version /= null then
1249+
if Gnatkp_Mode and then Arg.KP_Version.Get /= Null_Unbounded_String
1250+
then
12491251
Error ("no rule for the given kp-version");
12501252
No_Detectors_For_KP_Version := True;
12511253
return;

lkql_checker/src/gnatcheck-rules-rule_table.adb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,10 +1559,12 @@ package body Gnatcheck.Rules.Rule_Table is
15591559
if Gnatkp_Mode then
15601560
Print ("gnatkp currently implements the following detectors:");
15611561

1562-
if KP_Version /= null then
1562+
if Arg.KP_Version.Get /= Null_Unbounded_String then
15631563
for Rule in All_Rules.Iterate loop
15641564
if All_Rules (Rule).Impact = null
1565-
or else (Match (KP_Version.all, All_Rules (Rule).Impact.all)
1565+
or else (Match
1566+
(To_String (Arg.KP_Version.Get),
1567+
All_Rules (Rule).Impact.all)
15661568
and then (All_Rules (Rule).Target = null
15671569
or else To_String (Target) = ""
15681570
or else Match

0 commit comments

Comments
 (0)