Skip to content

Commit 9eb8747

Browse files
committed
Merge branch 'topic/gnatcheck/located_outputs' into 'master'
Conform GNATcheck messages to the GNAT diagnosis format when possible See merge request eng/libadalang/langkit-query-language!507
2 parents 8f7029b + d4251d1 commit 9eb8747

File tree

23 files changed

+296
-406
lines changed

23 files changed

+296
-406
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ package body Gnatcheck.Compiler is
10661066
if R_Id = Not_A_Restriction_Id
10671067
and then Special_R_Id = Not_A_Special_Restriction_Id
10681068
then
1069-
Error
1069+
Instance.Error
10701070
("wrong restriction identifier : " & Rest_Name & ", ignored");
10711071
Bad_Rule_Detected := True;
10721072
return;
@@ -1078,7 +1078,7 @@ package body Gnatcheck.Compiler is
10781078
(Lower_Rest_Name, I_Name, Cursor, Success);
10791079
if not Success and then Restriction_To_Instance (Cursor) /= I_Name
10801080
then
1081-
Error
1081+
Instance.Error
10821082
("cannot enable the same restriction in different rule "
10831083
& "instances: "
10841084
& Rest_Name);
@@ -1097,7 +1097,7 @@ package body Gnatcheck.Compiler is
10971097
exit;
10981098

10991099
else
1100-
Error
1100+
Instance.Error
11011101
("wrong structure of restriction rule parameter "
11021102
& Param
11031103
& ", ignored");
@@ -1111,7 +1111,7 @@ package body Gnatcheck.Compiler is
11111111
if R_Id in All_Boolean_Restrictions then
11121112

11131113
if Arg_Present then
1114-
Error
1114+
Instance.Error
11151115
("RESTRICTIONS rule parameter: "
11161116
& Param
11171117
& " can not contain expression, ignored");
@@ -1123,7 +1123,7 @@ package body Gnatcheck.Compiler is
11231123
elsif R_Id /= Not_A_Restriction_Id then
11241124

11251125
if not Arg_Present then
1126-
Error
1126+
Instance.Error
11271127
("RESTRICTIONS rule parameter: "
11281128
& Param
11291129
& " should contain an expression, ignored");
@@ -1150,7 +1150,7 @@ package body Gnatcheck.Compiler is
11501150
end if;
11511151
end loop;
11521152

1153-
Error
1153+
Instance.Error
11541154
("expression for RESTRICTIONS rule parameter: "
11551155
& Param (First_Idx .. Last_Idx)
11561156
& " is specified more than once");
@@ -1160,7 +1160,7 @@ package body Gnatcheck.Compiler is
11601160
Restriction_Setting (R_Id).Param.Append (R_Val'Img);
11611161
exception
11621162
when Constraint_Error =>
1163-
Error
1163+
Instance.Error
11641164
("wrong restriction parameter expression in "
11651165
& Param
11661166
& ", ignored");
@@ -1186,7 +1186,7 @@ package body Gnatcheck.Compiler is
11861186
case Special_R_Id is
11871187
when No_Dependence =>
11881188
if not Arg_Present then
1189-
Error
1189+
Instance.Error
11901190
("Restrictions rule parameter: "
11911191
& Param
11921192
& " should contain a unit name, ignored");
@@ -1201,7 +1201,7 @@ package body Gnatcheck.Compiler is
12011201

12021202
when No_Use_Of_Entity =>
12031203
if not Arg_Present then
1204-
Error
1204+
Instance.Error
12051205
("Restrictions rule parameter: "
12061206
& Param
12071207
& " should contain an entity name, ignored");
@@ -1216,7 +1216,7 @@ package body Gnatcheck.Compiler is
12161216

12171217
when No_Specification_Of_Aspect =>
12181218
if not Arg_Present then
1219-
Error
1219+
Instance.Error
12201220
("Restrictions rule parameter: "
12211221
& Param
12221222
& " should contain an aspect name, ignored");
@@ -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;
@@ -1357,7 +1357,7 @@ package body Gnatcheck.Compiler is
13571357

13581358
Style_To_Instance.Insert ([C], Name, Cursor, Success);
13591359
if not Success and then Style_To_Instance (Cursor) /= Name then
1360-
Error
1360+
Instance.Error
13611361
("cannot enable the same style check in different rule "
13621362
& "instances: "
13631363
& C);
@@ -1433,7 +1433,7 @@ package body Gnatcheck.Compiler is
14331433
if Param (J) in 'e' | 's'
14341434
and then (J = Param'First or else Param (J - 1) not in '.' | '_')
14351435
then
1436-
Error
1436+
Instance.Error
14371437
("Warnings rule cannot have "
14381438
& Param (J)
14391439
& " parameter, parameter string "
@@ -1458,7 +1458,7 @@ package body Gnatcheck.Compiler is
14581458

14591459
Warning_To_Instance.Insert (Param (I .. J), Name, Cursor, Success);
14601460
if not Success and then Warning_To_Instance (Cursor) /= Name then
1461-
Error
1461+
Instance.Error
14621462
("cannot enable the same warning in different rule instances: "
14631463
& Param (I .. J));
14641464
Bad_Rule_Detected := True;

lkql_checker/src/gnatcheck-output.adb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ package body Gnatcheck.Output is
103103
(Message : String;
104104
Tag : Message_Tags := None;
105105
Tool_Name : Boolean := False;
106+
Location : String := "";
106107
New_Line : Boolean := False;
107108
Log_Message : Boolean := False)
108109
is
109110
Final_Message : constant String :=
110111
(if Tool_Name then Executable & ": " else "")
112+
& (if Location /= "" then Location & ": " else "")
111113
& (case Tag is
112114
when Info => "info: ",
113115
when Warning => "warning: ",
@@ -134,12 +136,13 @@ package body Gnatcheck.Output is
134136
-- Error --
135137
-----------
136138

137-
procedure Error (Message : String) is
139+
procedure Error (Message : String; Location : String := "") is
138140
begin
139141
Emit_Message
140142
(Message,
141143
Tag => Error,
142-
Tool_Name => True,
144+
Tool_Name => Location = "",
145+
Location => Location,
143146
New_Line => True,
144147
Log_Message => True);
145148
end Error;
@@ -570,16 +573,17 @@ package body Gnatcheck.Output is
570573
-- Warning --
571574
-------------
572575

573-
procedure Warning (Message : String) is
576+
procedure Warning (Message : String; Location : String := "") is
574577
begin
575578
if Arg.Warnings_As_Errors.Get then
576-
Error (Message);
579+
Error (Message, Location);
577580
Error_From_Warning := True;
578581
else
579582
Emit_Message
580583
(Message,
581584
Tag => Warning,
582-
Tool_Name => True,
585+
Tool_Name => Location = "",
586+
Location => Location,
583587
New_Line => True,
584588
Log_Message => True);
585589
end if;

lkql_checker/src/gnatcheck-output.ads

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ package Gnatcheck.Output is
4141
procedure Report_Missing_File (From_File, Missing_File : String);
4242
-- Reports that a required file could not be found
4343

44-
procedure Error (Message : String);
45-
-- Sends ``Message`` into stderr, prefixed by "tool_name: error: ".
44+
procedure Error (Message : String; Location : String := "");
45+
-- Sends ``Message`` into stderr, prefixed by "tool_name: error: " if
46+
-- ``Location`` is an empty string, otherwise the message is prefixed
47+
-- by "<location>: error: ".
4648

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

5052
procedure Info (Message : String);
@@ -73,6 +75,7 @@ package Gnatcheck.Output is
7375
(Message : String;
7476
Tag : Message_Tags := None;
7577
Tool_Name : Boolean := False;
78+
Location : String := "";
7679
New_Line : Boolean := False;
7780
Log_Message : Boolean := False);
7881
-- Common procedure to emit a message to the user in ``Standard_Error``,
@@ -81,6 +84,8 @@ package Gnatcheck.Output is
8184
-- ``Tag``: Tag to add to the message when emitting it
8285
-- ``Tool_Name``: Whether to include the tool name at the start of the
8386
-- message (ex: "gnatcheck: ...")
87+
-- ``Location`` : Location string to append to the message just before the
88+
-- tag.
8489
-- ``New_Line``: Whether to add a end-of-line character at the end of the
8590
-- message
8691
-- ``Log_Message``: Whether to log this message in the current ``Log_File``

lkql_checker/src/gnatcheck-projects-aggregate.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ package body Gnatcheck.Projects.Aggregate is
202202
begin
203203
if Full_Tool_Name = null then
204204
Error
205-
("Cannot locate "
205+
("cannot locate "
206206
& Executable
207207
& " on PATH, possible installation problem");
208208
raise Fatal_Error;
@@ -344,7 +344,7 @@ package body Gnatcheck.Projects.Aggregate is
344344
Iterator_El := Element (Iterator_C);
345345
exception
346346
when others =>
347-
Error ("Cannot start iterator on aggregated projects");
347+
Error ("cannot start iterator on aggregated projects");
348348
raise Fatal_Error;
349349
end Start_Prj_Iterator;
350350

0 commit comments

Comments
 (0)