Skip to content

Commit 09458e7

Browse files
committed
Merge branch 'topic/hx_instances' into 'master'
Include rule instances to the GNATcheck output when using '-hx' Closes #196 See merge request eng/libadalang/langkit-query-language!291
2 parents 07968b8 + 5798a18 commit 09458e7

File tree

5 files changed

+525
-1563
lines changed

5 files changed

+525
-1563
lines changed

lkql_checker/src/gnatcheck-rules-rule_table.adb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ with Gnatcheck.Options; use Gnatcheck.Options;
2424
with Gnatcheck.Output; use Gnatcheck.Output;
2525
with Gnatcheck.String_Utilities; use Gnatcheck.String_Utilities;
2626

27+
with Langkit_Support.Text; use Langkit_Support.Text;
28+
2729
with Rule_Commands; use Rule_Commands;
2830
with Rules_Factory; use Rules_Factory;
2931

@@ -1503,6 +1505,7 @@ package body Gnatcheck.Rules.Rule_Table is
15031505
Rule_Set : Rule_Sets.Set;
15041506
Previous : Rule_Info;
15051507
Has_Previous : Boolean := False;
1508+
Args : Rule_Argument_Vectors.Vector;
15061509
begin
15071510
Info ("<?xml version=""1.0""?>");
15081511
Info ("<gnatcheck>");
@@ -1549,6 +1552,7 @@ package body Gnatcheck.Rules.Rule_Table is
15491552
for Rule of Rule_Set loop
15501553
Rule.XML_Rule_Help (Rule, Level + 1);
15511554
end loop;
1555+
Rule_Set.Clear;
15521556
end;
15531557

15541558
Info (Level * Indent_String & "</category>");
@@ -1563,6 +1567,47 @@ package body Gnatcheck.Rules.Rule_Table is
15631567
-- What about warnings and style checks???
15641568

15651569
Restrictions_Help (Level => 1);
1570+
1571+
-- Display all rule instances
1572+
Info (Indent_String & "<instances>");
1573+
1574+
-- Use the rule ordered set to sort the rules by their name
1575+
for Rule of All_Rules loop
1576+
Rule_Set.Include (Rule);
1577+
end loop;
1578+
1579+
for Rule of Rule_Set loop
1580+
if not Rule.Instances.Is_Empty then
1581+
Info
1582+
(2 * Indent_String & "<rule name=""" & Rule_Name (Rule) & """>");
1583+
1584+
for Instance of Rule.Instances loop
1585+
Instance.Map_Parameters (Args);
1586+
Info
1587+
(3 * Indent_String & "<instance name=""" &
1588+
Instance_Name (Instance.all) & """" &
1589+
(if Args.Is_Empty then " />" else ">"));
1590+
1591+
if not Args.Is_Empty then
1592+
for Arg of Args loop
1593+
Info
1594+
(4 * Indent_String & "<arg name=""" &
1595+
To_String (To_Text (Arg.Name)) & """ value=""" &
1596+
Escape_Quotes (To_String (To_Text (Arg.Value))) &
1597+
""" />");
1598+
end loop;
1599+
Info (3 * Indent_String & "</instance>");
1600+
end if;
1601+
Args.Clear;
1602+
end loop;
1603+
1604+
Info (2 * Indent_String & "</rule>");
1605+
end if;
1606+
end loop;
1607+
1608+
Info (Indent_String & "</instances>");
1609+
1610+
-- Close the XML help
15661611
Info ("</gnatcheck>");
15671612
end XML_Help;
15681613

lkql_checker/src/gnatcheck-string_utilities.ads

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ with Ada.Strings.Hash;
1010

1111
with GNAT.OS_Lib; use GNAT.OS_Lib;
1212

13+
with GNATCOLL.Utils; use GNATCOLL.Utils;
14+
1315
package Gnatcheck.String_Utilities is
1416

1517
-- String-related utilities
@@ -41,6 +43,11 @@ package Gnatcheck.String_Utilities is
4143
-- Removes surrounding quotes or double-quotes from the provided string
4244
-- if any, else just return the string.
4345

46+
function Escape_Quotes (S : String) return String is
47+
(Replace (S, """", "\"""));
48+
-- Escape all quotes in the given string by adding a '\` before each of
49+
-- them.
50+
4451
function Is_White_Space (Ch : Character) return Boolean is
4552
(Ch in ' ' | ASCII.HT);
4653
-- Checks if the argument is either a space or HT character
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
val rules = @{
2+
Goto_Statements: [{}, {instance_name: "Uncond_Goto", only_unconditional: true}],
3+
Redundant_Null_Statements,
4+
Too_Many_Parents: {n: 10},
5+
Calls_In_Exception_Handlers: {subprograms: ["this", "that"]},
6+
Identifier_Prefixes: [{type: "_T"}, {instance_name: "Access_Prefix", access: "_Ptr"}]
7+
}

0 commit comments

Comments
 (0)