Skip to content

Commit 32cbdae

Browse files
committed
Merge branch 'topic/490' into 'master'
Fix preprocessor handling during exemption pragma/comment detection Closes #490 See merge request eng/libadalang/langkit-query-language!462
2 parents 5e39af5 + fe5f9d9 commit 32cbdae

File tree

8 files changed

+101
-4
lines changed

8 files changed

+101
-4
lines changed

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ with GPR2.Project.Registry.Attribute;
5050
with GPR2.Project.Registry.Attribute.Description;
5151
with GPR2.Project.Registry.Pack;
5252
with GPR2.Project.Registry.Pack.Description;
53-
with GPR2.Project.View;
5453
with GPR2.Reporter.Console;
5554

5655
with GNATCOLL.Opt_Parse; use GNATCOLL.Opt_Parse;

lkql_checker/src/gnatcheck-projects.ads

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ with GNAT.OS_Lib; use GNAT.OS_Lib;
9393

9494
with GPR2.Containers;
9595
with GPR2.Project.Tree;
96+
with GPR2.Project.View;
9697

9798
package Gnatcheck.Projects is
9899

@@ -168,6 +169,10 @@ package Gnatcheck.Projects is
168169
(My_Project : Arg_Project_Type) return GPR2.Project.Tree.Object;
169170
-- Returns access to project tree object
170171

172+
function View
173+
(My_Project : Arg_Project_Type) return GPR2.Project.View.Object;
174+
-- Returns access to project view object
175+
171176
procedure Store_Project_Source
172177
(My_Project : in out Arg_Project_Type; Project_File_Name : String);
173178
-- If Project_File_Name ends with ".gpr", it is taken to be the name of
@@ -344,6 +349,7 @@ private
344349

345350
type Arg_Project_Type is tagged record
346351
Tree : aliased GPR2.Project.Tree.Object;
352+
View : aliased GPR2.Project.View.Object;
347353
Source_Prj : String_Access;
348354
Source_CGPR : String_Access;
349355
end record;
@@ -352,4 +358,8 @@ private
352358
(My_Project : Arg_Project_Type) return GPR2.Project.Tree.Object
353359
is (My_Project.Tree);
354360

361+
function View
362+
(My_Project : Arg_Project_Type) return GPR2.Project.View.Object
363+
is (My_Project.View);
364+
355365
end Gnatcheck.Projects;

lkql_checker/src/gnatcheck-source_table.adb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ with GPR2.Path_Name;
2525
with GPR2.Project.Tree;
2626
with GPR2.Project.View;
2727

28+
with Langkit_Support.File_Readers; use Langkit_Support.File_Readers;
2829
with Langkit_Support.Generic_API.Introspection;
2930

3031
with Libadalang.Analysis; use Libadalang.Analysis;
32+
with Libadalang.Preprocessing; use Libadalang.Preprocessing;
3133
with Libadalang.Project_Provider; use Libadalang.Project_Provider;
3234
with Libadalang.Iterators;
3335
with Libadalang.Generic_API; use Libadalang.Generic_API;
@@ -1475,8 +1477,11 @@ package body Gnatcheck.Source_Table is
14751477
Partition : GPR2_Provider_And_Projects_Array_Access;
14761478

14771479
function Create_Context return Checker_App.Lkql_Context is
1478-
Charset : constant String := To_String (Arg.Charset.Get);
1479-
Ctx : Checker_App.Lkql_Context;
1480+
Charset : constant String := To_String (Arg.Charset.Get);
1481+
Ctx : Checker_App.Lkql_Context;
1482+
File_Reader : File_Reader_Reference;
1483+
Default_Config : File_Config;
1484+
File_Configs : File_Config_Maps.Map;
14801485
begin
14811486
-- Use a project unit provider, even with the implicit project
14821487
if not In_Aggregate_Project then
@@ -1487,11 +1492,21 @@ package body Gnatcheck.Source_Table is
14871492
-- We can ignore multiple partitions: this will only occur with
14881493
-- aggregate projects, which are handled specially in lalcheck.adb
14891494

1495+
-- Setup the file reader with preprocessing support
1496+
Extract_Preprocessor_Data_From_Project
1497+
(Gnatcheck_Prj.Tree,
1498+
Gnatcheck_Prj.View,
1499+
Default_Config,
1500+
File_Configs);
1501+
1502+
File_Reader := Create_Preprocessor (Default_Config, File_Configs);
1503+
14901504
Ctx.Analysis_Ctx :=
14911505
Create_Context
14921506
(Charset => Charset,
14931507
Unit_Provider => Partition (Partition'First).Provider,
1494-
Event_Handler => EHR_Object);
1508+
Event_Handler => EHR_Object,
1509+
File_Reader => File_Reader);
14951510

14961511
-- Setup the configuration pragma mapping by reading the
14971512
-- configuration file given by the project.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
project Prj is
2+
for Source_Dirs use (".");
3+
for main use ("test.adb");
4+
5+
package Compiler is
6+
for Switches ("Ada") use ("-gnateG", "-gnateDX=Y");
7+
end Compiler;
8+
end Prj;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val rules = @{ Predefined_Numeric_Types }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
procedure Test is
2+
3+
Last_Char_0 : Positive; -- FLAG
4+
5+
#if Z'Defined then
6+
pragma Annotate
7+
(Gnatcheck,
8+
Exempt_On,
9+
"Predefined_Numeric_Types",
10+
"Exemption justification");
11+
Last_Char_1 : Positive;
12+
pragma Annotate (Gnatcheck, Exempt_Off, "Predefined_Numeric_Types");
13+
14+
Last_Char_2 : Positive; --## rule line off Predefined_Numeric_Types ## Exemption justification
15+
16+
--## rule off Predefined_Numeric_Types ## Exemption justification
17+
Last_Char_3 : Positive;
18+
--## rule on Predefined_Numeric_Types
19+
#end if;
20+
begin
21+
null;
22+
end;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1. Summary
2+
3+
fully compliant sources : 0
4+
sources with exempted violations only : 0
5+
sources with non-exempted violations : 1
6+
unverified sources : 0
7+
total sources : 1
8+
ignored sources : 0
9+
10+
non-exempted violations : 1
11+
rule exemption warnings : 0
12+
compilation errors : 0
13+
exempted violations : 0
14+
internal errors : 0
15+
16+
2. Exempted Coding Standard Violations
17+
18+
no exempted violations detected
19+
20+
3. Non-exempted Coding Standard Violations
21+
22+
test.adb:3:18: rule violation: explicit reference to predefined numeric subtype [predefined_numeric_types]
23+
24+
4. Rule exemption problems
25+
26+
no rule exemption problems detected
27+
28+
5. Language violations
29+
30+
no language violations detected
31+
32+
6. Gnatcheck internal errors
33+
34+
no internal error detected
35+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
description: |
2+
This test checks that no rule exemption is processed when exemption pragma or
3+
comment is included in code ignored by the preprocessor.
4+
driver: gnatcheck
5+
show_rule: True
6+
project: prj.gpr
7+
lkql_rule_file: rules.lkql

0 commit comments

Comments
 (0)