Skip to content

Commit e847254

Browse files
committed
Merge branch 'topic/gnatcheck/split_rule_interfaces' into 'master'
Avoid emitting hint messages when only using the new rule options API Closes #455 See merge request eng/libadalang/langkit-query-language!461
2 parents e7fb303 + bc3375d commit e847254

File tree

8 files changed

+196
-82
lines changed

8 files changed

+196
-82
lines changed

lkql_checker/src/gnatcheck-diagnoses.adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,13 +1292,13 @@ package body Gnatcheck.Diagnoses is
12921292
("<coding-standard from-file=""", Indent_Level => 1);
12931293
end if;
12941294

1295-
if not Individual_Rules_Set and then Rule_File_Name /= null then
1295+
if not Individual_Rules_Set and then Legacy_Rule_File_Name /= null then
12961296
if Text_Report_ON then
1297-
Report (Rule_File_Name.all);
1297+
Report (Legacy_Rule_File_Name.all);
12981298
end if;
12991299

13001300
if XML_Report_ON then
1301-
XML_Report (Rule_File_Name.all & """>");
1301+
XML_Report (Legacy_Rule_File_Name.all & """>");
13021302
end if;
13031303
else
13041304
-- Creating the list of active rules

lkql_checker/src/gnatcheck-options.ads

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ package Gnatcheck.Options is
209209
-- section of the report file. If this option is not set, this section is
210210
-- not created in the report file.
211211

212-
Individual_Rules_Set : Boolean := False;
213-
More_Then_One_Rule_File_Set : Boolean := False;
212+
Individual_Rules_Set : Boolean := False;
213+
More_Than_One_Legacy_Rule_File_Set : Boolean := False;
214214
-- Flags used to detect if all the rules specified for a given gnatcheck
215215
-- call, should be set when parsing rule options
216216

217-
Rule_File_Name : GNAT.OS_Lib.String_Access;
218-
-- If More_Then_One_Rule_File_Set is OFF and if a rule file has been
219-
-- processed, keeps the name of this file, otherwise is null.
217+
Legacy_Rule_File_Name : GNAT.OS_Lib.String_Access;
218+
-- If ``More_Than_One_Legacy_Rule_File_Set`` is OFF and if a rule file has
219+
-- been processed, keeps the name of this file, otherwise is null.
220220

221221
LKQL_Rule_File_Name : Unbounded_String := Null_Unbounded_String;
222222
-- Name of the LKQL file to process as a rule file. We assume that the

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ package body Gnatcheck.Projects is
9999
(Self : Gnatcheck_Reporter) return GPR2.Reporter.Verbosity_Level;
100100

101101
Gpr2_Reporter : Gnatcheck_Reporter;
102-
-- Make libgpt2 report messages using the proper gnatcheck.Output API
102+
-- Make libgpr2 report messages using the proper ``Gnatcheck.Output`` API.
103103

104104
function Report_Missing_File (Log : String) return Boolean
105105
is (Index (Log, "source file") /= 0 and then Index (Log, "not found") /= 0);
@@ -1056,7 +1056,7 @@ package body Gnatcheck.Projects is
10561056
-- Process_Rule_Options --
10571057
--------------------------
10581058

1059-
type Option_Kind is (File, Option);
1059+
type Option_Kind is (File, Legacy_Option, Single_Rule_Name);
10601060

10611061
type Option_Record is record
10621062
Kind : Option_Kind;
@@ -1080,43 +1080,53 @@ package body Gnatcheck.Projects is
10801080
for O of Rule_Options loop
10811081
case O.Kind is
10821082
when File =>
1083-
Process_Rule_File (To_String (O.Value));
1083+
Process_Legacy_Rule_File (To_String (O.Value));
10841084

1085-
when Option =>
1086-
Process_Rule_Option (To_String (O.Value), Defined_At => "");
1085+
when Legacy_Option =>
1086+
Process_Legacy_Rule_Option
1087+
(To_String (O.Value), Defined_At => "");
1088+
1089+
when Single_Rule_Name =>
1090+
Process_Single_Rule_Name (To_String (O.Value));
10871091
end case;
10881092
end loop;
10891093
Process_Compiler_Instances;
10901094
end Process_Rule_Options;
10911095

1092-
---------------------
1093-
-- Add_Rule_Option --
1094-
---------------------
1096+
----------------------------
1097+
-- Add_Legacy_Rule_Option --
1098+
----------------------------
10951099

1096-
procedure Add_Rule_Option (Opt : String; Prepend : Boolean := False) is
1100+
procedure Add_Legacy_Rule_Option (Opt : String; Prepend : Boolean := False)
1101+
is
10971102
use Ada.Strings.Unbounded;
10981103

10991104
Opt_Rec : constant Option_Record :=
1100-
(Option, To_Unbounded_String (Trim (Opt, Both)));
1105+
(Legacy_Option, To_Unbounded_String (Trim (Opt, Both)));
11011106
begin
11021107
if Prepend then
11031108
Rule_Options.Prepend (Opt_Rec);
11041109
else
11051110
Rule_Options.Append (Opt_Rec);
11061111
end if;
1107-
end Add_Rule_Option;
1112+
end Add_Legacy_Rule_Option;
11081113

11091114
----------------------
11101115
-- Add_Rule_By_Name --
11111116
----------------------
11121117

11131118
procedure Add_Rule_By_Name (Rule_Name : String; Prepend : Boolean := False)
11141119
is
1115-
Lower_Rule : constant String := To_Lower (Rule_Name);
1116-
Prefix : constant String :=
1117-
(if Lower_Rule = "all" then "+" else "+R");
1120+
use Ada.Strings.Unbounded;
1121+
1122+
Opt_Rec : constant Option_Record :=
1123+
(Single_Rule_Name, To_Unbounded_String (Trim (Rule_Name, Both)));
11181124
begin
1119-
Add_Rule_Option (Prefix & Lower_Rule, Prepend => Prepend);
1125+
if Prepend then
1126+
Rule_Options.Prepend (Opt_Rec);
1127+
else
1128+
Rule_Options.Append (Opt_Rec);
1129+
end if;
11201130
end Add_Rule_By_Name;
11211131

11221132
------------------------
@@ -1225,16 +1235,16 @@ package body Gnatcheck.Projects is
12251235
(Option_Record'
12261236
(File,
12271237
To_Unbounded_String (Parameter (Parser => Parser))));
1228-
if not More_Then_One_Rule_File_Set then
1229-
Rule_File_Name :=
1238+
if not More_Than_One_Legacy_Rule_File_Set then
1239+
Legacy_Rule_File_Name :=
12301240
new String'(Parameter (Parser => Parser));
1231-
More_Then_One_Rule_File_Set := True;
1241+
More_Than_One_Legacy_Rule_File_Set := True;
12321242
else
1233-
Free (Rule_File_Name);
1243+
Free (Legacy_Rule_File_Name);
12341244
end if;
12351245

12361246
when others =>
1237-
Add_Rule_Option (Full_Switch (Parser => Parser));
1247+
Add_Legacy_Rule_Option (Full_Switch (Parser => Parser));
12381248
Individual_Rules_Set := True;
12391249
end case;
12401250
if not Rules_Depreciation_Emitted then

lkql_checker/src/gnatcheck-projects.ads

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ package Gnatcheck.Projects is
240240
procedure Process_Rule_Options;
241241
-- Process all the rule options found as part of scanning arguments
242242

243-
procedure Add_Rule_Option (Opt : String; Prepend : Boolean := False);
243+
procedure Add_Legacy_Rule_Option (Opt : String; Prepend : Boolean := False);
244244
-- Add the given ``Opt`` to the list of rule options processed by
245245
-- ``Process_Rule_Options`` as a command-line rule option (e.g. +R...).
246246
-- If ``Prepend`` is set to True, add the rule option at the start of
247247
-- the processing list.
248248

249249
procedure Add_Rule_By_Name (Rule_Name : String; Prepend : Boolean := False);
250-
-- Use ``Add_Rule_Option`` to forge a new rule option enabling the given
251-
-- rule without any parameter.
250+
-- Use ``Add_Legacy_Rule_Option`` to forge a new rule option enabling the
251+
-- given rule without any parameter.
252252

253253
procedure Set_LKQL_Rule_File (File : String; Project_Relative : Boolean);
254254
-- Set the given ``File`` as the LKQL rule file to process during the

0 commit comments

Comments
 (0)