Skip to content

Commit d4251d1

Browse files
committed
Add optional location to warning messages
1 parent 5fbb161 commit d4251d1

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ package body Gnatcheck.Compiler is
12521252
| Static_Dispatch_Tables
12531253
| No_Exception_Propagation
12541254
then
1255-
Warning
1255+
Instance.Warning
12561256
("restriction "
12571257
& To_Mixed (R_Id'Img)
12581258
& " ignored - only fully effective during code generation");
@@ -1272,22 +1272,22 @@ package body Gnatcheck.Compiler is
12721272
| No_Entry_Queue
12731273
| No_Reentrancy
12741274
then
1275-
Warning
1275+
Instance.Warning
12761276
("restriction "
12771277
& To_Mixed (R_Id'Img)
12781278
& " ignored - cannot be checked statically");
12791279

12801280
Restriction_Setting (R_Id).Active := False;
12811281

12821282
elsif R_Id = No_Recursion then
1283-
Warning
1283+
Instance.Warning
12841284
("restriction No_Recursion ignored (cannot be checked statically), "
12851285
& "use rule Recursive_Subprograms instead");
12861286

12871287
Restriction_Setting (R_Id).Active := False;
12881288

12891289
elsif R_Id = Max_Asynchronous_Select_Nesting and then R_Val /= 0 then
1290-
Warning
1290+
Instance.Warning
12911291
("restriction Max_Asynchronous_Select_Nesting ignored - "
12921292
& "cannot be checked statically if parameter is not 0");
12931293
Restriction_Setting (R_Id).Active := False;

lkql_checker/src/gnatcheck-output.adb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,17 @@ package body Gnatcheck.Output is
573573
-- Warning --
574574
-------------
575575

576-
procedure Warning (Message : String) is
576+
procedure Warning (Message : String; Location : String := "") is
577577
begin
578578
if Arg.Warnings_As_Errors.Get then
579-
Error (Message);
579+
Error (Message, Location);
580580
Error_From_Warning := True;
581581
else
582582
Emit_Message
583583
(Message,
584584
Tag => Warning,
585-
Tool_Name => True,
585+
Tool_Name => Location = "",
586+
Location => Location,
586587
New_Line => True,
587588
Log_Message => True);
588589
end if;

lkql_checker/src/gnatcheck-output.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ package Gnatcheck.Output is
4646
-- ``Location`` is an empty string, otherwise the message is prefixed
4747
-- by "<location>: error: ".
4848

49-
procedure Warning (Message : String);
49+
procedure Warning (Message : String; Location : String := "");
5050
-- Sends ``Message`` into stderr, prefixed by "tool_name: warning: ".
5151

5252
procedure Info (Message : String);

lkql_checker/src/gnatcheck-rules-rule_table.adb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,8 @@ package body Gnatcheck.Rules.Rule_Table is
12981298
Output_Rule_File : constant String :=
12991299
(if Arg.Full_Source_Locations.Get
13001300
then LKQL_Rule_File_Name
1301-
else Base_Name (LKQL_Rule_File_Name));
1301+
else Base_Name (LKQL_Rule_File_Name))
1302+
& ":1:1";
13021303
Rule_Name : constant String := Instance_Object.Get ("ruleName");
13031304
Instance_Name : constant String :=
13041305
(if Instance_Object.Has_Field ("instanceName")
@@ -1333,7 +1334,7 @@ package body Gnatcheck.Rules.Rule_Table is
13331334

13341335
procedure Error_In_Rule_File (Msg : String) is
13351336
begin
1336-
Error (Msg, Location => Output_Rule_File & ":1:1");
1337+
Error (Msg, Location => Output_Rule_File);
13371338
Bad_Rule_Detected := True;
13381339
end Error_In_Rule_File;
13391340

lkql_checker/src/gnatcheck-rules.adb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,20 @@ package body Gnatcheck.Rules is
29902990
end if;
29912991
end Error;
29922992

2993+
-------------
2994+
-- Warning --
2995+
-------------
2996+
2997+
procedure Warning (Self : Rule_Instance'Class; Message : String) is
2998+
begin
2999+
if Self.Defined_At /= Null_Unbounded_String then
3000+
Gnatcheck.Output.Warning
3001+
(Message, Location => To_String (Self.Defined_At));
3002+
else
3003+
Gnatcheck.Output.Warning (Message);
3004+
end if;
3005+
end Warning;
3006+
29933007
-- == Overriding operations on rule instances
29943008

29953009
------------------------------------

lkql_checker/src/gnatcheck-rules.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ package Gnatcheck.Rules is
276276
procedure Error (Self : Rule_Instance'Class; Message : String);
277277
-- Emit an error message about the ``Self`` rule instance
278278

279+
procedure Warning (Self : Rule_Instance'Class; Message : String);
280+
-- Emit a warning message about the ``Self`` rule instance
281+
279282
procedure Free is new
280283
Ada.Unchecked_Deallocation (Rule_Instance'Class, Rule_Instance_Access);
281284
-- Free the memory allocated for a rule instance
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Without "warnings as errors"
22
============================
33

4-
gnatcheck: warning: restriction No_Recursion ignored (cannot be checked statically), use rule Recursive_Subprograms instead
4+
rules.lkql:1:1: warning: restriction No_Recursion ignored (cannot be checked statically), use rule Recursive_Subprograms instead
55
main.adb:3:04: rule violation: goto statement
66

77
With "warnings as errors"
88
=========================
99

10-
gnatcheck: error: restriction No_Recursion ignored (cannot be checked statically), use rule Recursive_Subprograms instead
10+
rules.lkql:1:1: error: restriction No_Recursion ignored (cannot be checked statically), use rule Recursive_Subprograms instead
1111
main.adb:3:04: rule violation: goto statement
1212
>>>program returned status code 2

0 commit comments

Comments
 (0)