Skip to content

Commit c2cdaf7

Browse files
committed
Convert new diagnostics to the GNAT diagnosis format
1 parent 0d70ec9 commit c2cdaf7

File tree

9 files changed

+93
-60
lines changed

9 files changed

+93
-60
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ with Gnatcheck.Rules.Rule_Table; use Gnatcheck.Rules.Rule_Table;
2525
with Gnatcheck.Source_Table; use Gnatcheck.Source_Table;
2626
with Gnatcheck.String_Utilities; use Gnatcheck.String_Utilities;
2727

28-
with GNATCOLL.VFS; use GNATCOLL.VFS;
28+
with GNATCOLL.JSON; use GNATCOLL.JSON;
29+
with GNATCOLL.VFS; use GNATCOLL.VFS;
2930

3031
with Langkit_Support.Slocs; use Langkit_Support.Slocs;
3132

@@ -339,6 +340,10 @@ package body Gnatcheck.Compiler is
339340
-- Analyze one line containing a builder output. Insert the relevant
340341
-- messages into gnatcheck diagnoses table.
341342

343+
procedure Process_Worker_Message
344+
(Message : String; Printer : access procedure (S, L : String));
345+
-- Helper to process messages received from the Worker
346+
342347
------------------
343348
-- Analyze_Line --
344349
------------------
@@ -529,6 +534,24 @@ package body Gnatcheck.Compiler is
529534
else Get_Rule_Id (Message_Kind)));
530535
end Analyze_Line;
531536

537+
----------------------------
538+
-- Process_Worker_Message --
539+
----------------------------
540+
541+
procedure Process_Worker_Message
542+
(Message : String; Printer : access procedure (S, L : String))
543+
is
544+
Decoded_Message : constant Read_Result := Read (Message);
545+
begin
546+
if Decoded_Message.Success then
547+
Printer
548+
(Decoded_Message.Value.Get ("message"),
549+
Decoded_Message.Value.Get ("location"));
550+
else
551+
Printer (Message, "");
552+
end if;
553+
end Process_Worker_Message;
554+
532555
-- Start of processing for Analyze_Output
533556

534557
begin
@@ -601,11 +624,11 @@ package body Gnatcheck.Compiler is
601624
end;
602625
end if;
603626
elsif Line_Len >= 16 and then Line (1 .. 13) = "WORKER_INFO: " then
604-
Info (Line (14 .. Line_Len));
627+
Process_Worker_Message (Line (14 .. Line_Len), Info'Access);
605628
elsif Line_Len >= 16 and then Line (1 .. 16) = "WORKER_WARNING: " then
606-
Warning (Line (17 .. Line_Len));
629+
Process_Worker_Message (Line (17 .. Line_Len), Warning'Access);
607630
elsif Line_Len >= 14 and then Line (1 .. 14) = "WORKER_ERROR: " then
608-
Error (Line (15 .. Line_Len));
631+
Process_Worker_Message (Line (15 .. Line_Len), Error'Access);
609632
Detected_Internal_Error := @ + 1;
610633
Errors := True;
611634
elsif Line_Len >= 23

lkql_checker/src/gnatcheck-output.adb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,13 @@ package body Gnatcheck.Output is
228228
-- Info --
229229
----------
230230

231-
procedure Info (Message : String) is
231+
procedure Info (Message : String; Location : String := "") is
232232
begin
233233
Emit_Message
234234
(Message,
235235
Tag => Info,
236-
Tool_Name => True,
236+
Tool_Name => Location = "",
237+
Location => Location,
237238
New_Line => True,
238239
Log_Message => True);
239240
end Info;

lkql_checker/src/gnatcheck-output.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ package Gnatcheck.Output is
4949
procedure Warning (Message : String; Location : String := "");
5050
-- Sends ``Message`` into stderr, prefixed by "tool_name: warning: ".
5151

52-
procedure Info (Message : String);
52+
procedure Info (Message : String; Location : String := "");
5353
-- Sends ``Message`` into stderr, prefixed by "tool_name: info: ".
5454

5555
procedure Info_In_Tty (Message : String);

lkql_jit/cli/src/main/java/com/adacore/lkql_jit/cli/GNATCheckWorker.java

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@ private static void errorInLKQLRuleFile(
313313
);
314314
}
315315

316+
private static void emitMessageForTheDriver(
317+
final String tag,
318+
final String location,
319+
final String message
320+
) {
321+
System.err.println(
322+
tag + ": {\"location\": \"" + location + "\", \"message\": \"" + message + "\"}"
323+
);
324+
}
325+
316326
/**
317327
* Read the given LKQL file and parse it as a rule configuration file to return the list of
318328
* instances defined in it.
@@ -457,15 +467,15 @@ private static void processInstancesObject(
457467
for (var instance : rule.getValue().subList(i + 1, rule.getValue().size())) {
458468
RuleInstance current = rule.getValue().get(i);
459469
if (current.isEquivalent(instance)) {
460-
System.err.println(
461-
"WORKER_WARNING: duplicate rules with different names, " +
462-
instance.instanceId() +
463-
" from " +
464-
instance.locationToGNATDiagnosisFormatString() +
465-
" runs the same check than rule " +
470+
emitMessageForTheDriver(
471+
"WORKER_WARNING",
472+
current.locationToGNATDiagnosisFormatString(),
473+
"instance " +
466474
current.instanceId() +
467-
" from " +
468-
current.locationToGNATDiagnosisFormatString()
475+
" runs the same check than instance " +
476+
instance.instanceId() +
477+
" declared at " +
478+
instance.locationToGNATDiagnosisFormatString()
469479
);
470480
}
471481
}
@@ -514,34 +524,32 @@ private static void processArgsObject(
514524
// If the instance is already present, compare parameters, if they
515525
// are identical, skip the current instance and emit a warning.
516526
if (oldInstance.arguments().equals(newInstance.arguments())) {
517-
System.err.println(
518-
"WORKER_WARNING: duplicated rule: " +
527+
emitMessageForTheDriver(
528+
"WORKER_WARNING",
529+
newInstance.locationToGNATDiagnosisFormatString(),
530+
"ignore duplicate instance " +
519531
instanceId +
520-
" ignored from " +
521-
newInstance.locationToGNATDiagnosisFormatString() +
522532
", previous declaration at " +
523533
oldInstance.locationToGNATDiagnosisFormatString()
524534
);
525535
} else {
526536
// On the contrary, emit an error.
527-
errorInLKQLRuleFile(
528-
lkqlRuleFile,
529-
"multiple instances with the same name but different configuration: " +
537+
emitMessageForTheDriver(
538+
"WORKER_ERROR",
539+
newInstance.locationToGNATDiagnosisFormatString(),
540+
"instance " +
530541
instanceId +
531-
" at " +
532-
newInstance.locationToGNATDiagnosisFormatString() +
533-
", previous declaration at " +
542+
" has a different configuration than the one previously declared at " +
534543
oldInstance.locationToGNATDiagnosisFormatString() +
535544
" (instances should have unique names)"
536545
);
537546
}
538547
} else {
539548
if (verbose) {
540-
System.err.println(
541-
"WORKER_INFO: register new instance: " +
542-
instanceId +
543-
" from " +
544-
newInstance.locationToGNATDiagnosisFormatString()
549+
emitMessageForTheDriver(
550+
"WORKER_INFO",
551+
newInstance.locationToGNATDiagnosisFormatString(),
552+
"register new instance " + instanceId
545553
);
546554
}
547555
toPopulate.put(instanceId, newInstance);
@@ -575,21 +583,19 @@ private static void processSoleArg(
575583
if (!toPopulate.containsKey(ruleName)) {
576584
toPopulate.put(ruleName, newInstance);
577585
if (verbose) {
578-
System.err.println(
579-
"WORKER_INFO: register new instance: " +
580-
ruleName +
581-
" from " +
582-
newInstance.locationToGNATDiagnosisFormatString()
586+
emitMessageForTheDriver(
587+
"WORKER_INFO",
588+
newInstance.locationToGNATDiagnosisFormatString(),
589+
"register new instance " + ruleName
583590
);
584591
}
585592
} else {
586-
errorInLKQLRuleFile(
587-
lkqlRuleFile,
593+
emitMessageForTheDriver(
594+
"WORKER_ERROR",
595+
newInstance.locationToGNATDiagnosisFormatString(),
588596
"cannot add instance " +
589597
ruleName +
590-
" twice using the shortcut argument format from instances set included in rules set at: " +
591-
newInstance.locationToGNATDiagnosisFormatString() +
592-
". Previous instance has been declared in" +
598+
" twice using the shortcut argument format. Previous instance has been declared in" +
593599
((newInstance
594600
.instanceLocation()
595601
.equals(toPopulate.get(ruleName).instanceLocation()))

testsuite/tests/gnatcheck/lkql_rules_merging/merge_sets/test.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
gnatcheck: info: register new instance: name1a from rules1.lkql:2:13
2-
gnatcheck: info: register new instance: name1b from rules1.lkql:3:13
3-
gnatcheck: info: register new instance: name1c from rules1.lkql:4:13
4-
gnatcheck: info: register new instance: name1d from rules1.lkql:5:13
5-
gnatcheck: info: register new instance: name2a from rules2.lkql:4:13
6-
gnatcheck: info: register new instance: name2b from rules2.lkql:5:13
7-
gnatcheck: info: register new instance: rule2 from rules1.lkql:6:5
8-
gnatcheck: info: register new instance: rule2b from rules2.lkql:6:13
9-
gnatcheck: warning: duplicated rule: rule2b ignored from rules2.lkql:6:40, previous declaration at rules2.lkql:6:13
10-
gnatcheck: info: register new instance: sc1 from rules1.lkql:7:20
11-
gnatcheck: info: register new instance: sc2 from rules1.lkql:8:20
12-
gnatcheck: warning: duplicate rules with different names, rule2 from rules1.lkql:6:5 runs the same check than rule rule2b from rules2.lkql:6:13
1+
rules1.lkql:2:13: info: register new instance name1a
2+
rules1.lkql:3:13: info: register new instance name1b
3+
rules1.lkql:4:13: info: register new instance name1c
4+
rules1.lkql:5:13: info: register new instance name1d
5+
rules2.lkql:4:13: info: register new instance name2a
6+
rules2.lkql:5:13: info: register new instance name2b
7+
rules1.lkql:6:5: info: register new instance rule2
8+
rules2.lkql:6:13: info: register new instance rule2b
9+
rules2.lkql:6:40: warning: ignore duplicate instance rule2b, previous declaration at rules2.lkql:6:13
10+
rules1.lkql:7:20: info: register new instance sc1
11+
rules1.lkql:8:20: info: register new instance sc2
12+
rules2.lkql:6:13: warning: instance rule2b runs the same check than instance rule2 declared at rules1.lkql:6:5
1313
gnatcheck <version> (<date>)
1414
Copyright <date>, AdaCore.
1515
test.adb:1:01: rule violation: rule2 [rule2]

testsuite/tests/gnatcheck/lkql_rules_merging/merge_sets_error_1/test.out

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
gnatcheck: info: register new instance: name1a from rules1.lkql:2:14
2-
gnatcheck: info: register new instance: name1b from rules1.lkql:3:14
3-
gnatcheck: error: multiple instances with the same name but different configuration: name1a at rules2.lkql:4:14, previous declaration at rules1.lkql:2:14 (instances should have unique names) (rules2.lkql)
1+
rules1.lkql:2:14: info: register new instance name1a
2+
rules1.lkql:3:14: info: register new instance name1b
3+
rules2.lkql:4:14: error: instance name1a has a different configuration than the one previously declared at rules1.lkql:2:14 (instances should have unique names)
4+
rules2.lkql:5:14: error: instance name1b has a different configuration than the one previously declared at rules1.lkql:3:14 (instances should have unique names)
5+
rules1.lkql:4:5: info: register new instance rule2
6+
rules2.lkql:6:5: warning: ignore duplicate instance rule2, previous declaration at rules1.lkql:4:5
47
gnatcheck <version> (<date>)
58
Copyright <date>, AdaCore.
69
gnatcheck: error: no rule to check specified

testsuite/tests/gnatcheck/lkql_rules_merging/merge_sets_error_2/test.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
gnatcheck: info: register new instance: style_checks from rules3.lkql:1:13
2-
gnatcheck: error: cannot add instance style_checks twice using the shortcut argument format from instances set included in rules set at: rules3.lkql:1:13. Previous instance has been declared in the same set (rules3.lkql)
1+
rules3.lkql:1:13: info: register new instance style_checks
2+
rules3.lkql:1:13: error: cannot add instance style_checks twice using the shortcut argument format. Previous instance has been declared in the same set
33
gnatcheck <version> (<date>)
44
Copyright <date>, AdaCore.
55
gnatcheck: error: no rule to check specified

testsuite/tests/gnatcheck/lkql_rules_merging/merge_sets_error_3/test.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
gnatcheck: info: register new instance: style_checks from rules1.lkql:2:20
2-
gnatcheck: error: cannot add instance style_checks twice using the shortcut argument format from instances set included in rules set at: rules2.lkql:3:13. Previous instance has been declared in: rules1.lkql:2:20 (rules2.lkql)
1+
rules1.lkql:2:20: info: register new instance style_checks
2+
rules2.lkql:3:13: error: cannot add instance style_checks twice using the shortcut argument format. Previous instance has been declared in: rules1.lkql:2:20
33
gnatcheck <version> (<date>)
44
Copyright <date>, AdaCore.
55
gnatcheck: error: no rule to check specified

testsuite/tests/gnatcheck_errors/invalid_lkql_rules_config/test.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extra_param.lkql:1:1: error: extra argument for rule "goto_statements": 'extra'
8181
Multiple instance with the same name
8282
====================================
8383

84-
gnatcheck: error: multiple instances with the same name but different configuration: an_instance at instance_names.lkql:3:23, previous declaration at instance_names.lkql:2:23 (instances should have unique names) (instance_names.lkql)
84+
instance_names.lkql:3:23: error: instance an_instance has a different configuration than the one previously declared at instance_names.lkql:2:23 (instances should have unique names)
8585
gnatcheck: error: no rule to check specified
8686
try "gnatcheck --help" for more information.
8787
>>>program returned status code 2

0 commit comments

Comments
 (0)