Skip to content

Commit ba59ff0

Browse files
committed
Merge branch 'topic/update_example' into 'master'
Update the given GNATcheck example See merge request eng/libadalang/langkit-query-language!303
2 parents a9d5802 + 66e6d7e commit ba59ff0

File tree

8 files changed

+178
-93
lines changed

8 files changed

+178
-93
lines changed
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
G N A T C H E C K E X A M P L E
2-
==================================
1+
GNATcheck Example
2+
=================
33

44
This directory contains a simple example of using GNATcheck. This example is
55
derived from one of the examples included in the GNAT compiler distribution
66
(see the subdirectory share/examples/gnat/simple_project of your compiler
77
installation if you have one).
88

9-
Compared to the original example, the following two things have been added:
9+
Compared to the original example, a sample GNATcheck coding standard file named
10+
`rules.lkql` has been added. This is an LKQL file containing a set of GNATcheck
11+
rules and their configuration.
1012

11-
- A sample GNATcheck coding standard file named 'coding_standard.rules'; this
12-
is a text file containing a set of GNATcheck rule options).
13-
14-
- The original project file now contains the package 'Check'; this package
15-
tells GNATcheck to use the coding standard file mentioned above.
16-
17-
If you want to try out GNATcheck on any other project - just copy the sample
18-
coding standard file to another project's directory, and add the
19-
'Check' package to this project file.
13+
If you want to try out GNATcheck on any other project, simply copy the sample
14+
coding standard file to the project's directory, besides the GPR file.
15+
GNATcheck will use it by default when running on this project file.
2016

2117
You can also modify the coding standard file in any way you want - you can
2218
add new rules, change rule parameters, disable some rules. Please refer to
2319
the GNATcheck Reference Manual for more details.
2420

2521

26-
2722
Using GNATcheck from the command line
2823
-------------------------------------
2924

3025
$ gnatcheck -P simple.gpr
3126

3227
GNATcheck will output messages in your command shell, and will also generate
33-
the report file "gnatcheck.out" in the project's objects directory.
28+
the report file `gnatcheck/gnatcheck.out` in the project's object directory.
29+
3430

3531
Using GNATcheck from GPS
3632
------------------------
3733

3834
Open the project file in GPS, then choose the command
39-
'Analyze->Coding Standard->Check Root Project". You will see the diagnoses
35+
`Analyze->Coding Standard->Check Root Project`. You will see the diagnoses
4036
generated by gnatcheck in the 'Locations' GPS window.

lkql_checker/share/examples/coding_standard.rules

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
val rules = @{
2+
Abstract_Type_Declarations,
3+
Anonymous_Arrays,
4+
Anonymous_Subtypes,
5+
Blocks,
6+
7+
Boolean_Relational_Operators,
8+
# Flag each call to a predefined relational operator
9+
# (<, >, <=, >=, = and /=) for the predefined Boolean type.
10+
11+
Complex_Inlined_Subprograms: {N: 3},
12+
# Flag a subprogram (or generic subprogram, or instantiation of a
13+
# subprogram) if pragma Inline is applied to it and at least one of the
14+
# following conditions is met:
15+
# * it contains at least one complex declaration such as a subprogram
16+
# body, package, task, protected declaration, or a generic instantiation
17+
# (except instantiation of Ada.Unchecked_Conversion);
18+
# * it contains at least one complex statement such as a loop, a case or
19+
# an if statement;
20+
# * the number of statements exceeds 3
21+
22+
Controlled_Type_Declarations,
23+
24+
Deep_Inheritance_Hierarchies: {N: 5},
25+
# Flag a tagged derived type declaration or an interface type declaration
26+
# if its depth (in its inheritance hierarchy) exceeds 5
27+
28+
Deeply_Nested_Generics: {N: 3},
29+
# Flag a generic declaration nested in another generic declaration if the
30+
# nesting level of the inner generic exceeds 3
31+
32+
Identifier_Casing: {Others: "mixed"},
33+
# Flag any defining identifier if it casing does not follow the rules: the
34+
# first letter and every letter after underscore are uppercase, all the
35+
# other lettres are lowercase
36+
37+
Identifier_Suffixes: {
38+
Type_Suffix: "_Type",
39+
Access_Suffix: "_Access_Type",
40+
Class_Access_Suffix: "_Class_Type"
41+
},
42+
# Flag any defining identifier if it corresponds to the given kind of
43+
# entities but does not have a specified suffix
44+
45+
Identifier_Prefixes: {
46+
Type: "T_",
47+
Access: "A_",
48+
Constant: "C_"
49+
},
50+
# Flag any defining identifier if it corresponds to the given kind of
51+
# entities but does not have a specified prefix
52+
53+
Non_Qualified_Aggregates,
54+
Non_Short_Circuit_Operators,
55+
56+
OTHERS_In_Aggregates,
57+
OTHERS_In_CASE_Statements,
58+
OTHERS_In_Exception_Handlers,
59+
60+
Warnings: "km",
61+
# Include warnings generated by the compiler with '-gnatwk' (variables that
62+
# could be constants) and '-gnatwm' (modified but unreferenced variables)
63+
# into generated gnatcheck report
64+
65+
Style_Checks: "uO",
66+
# Include warnings generated by the compiler style checks '-gnatyu'
67+
# (unnecessary blank lines) and '-gnatyO' (overriding subprograms are
68+
# not explicitly marked as such.) into generated gnatcheck report
69+
70+
Restrictions: {Arg: ["No_Allocators", "No_Tasking", "No_Dependence => Ada.Containers"]}
71+
# Include warnings generated by the compiler with the specified restrictions
72+
# into generated gnatcheck report
73+
}

lkql_checker/share/examples/simple.gpr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,4 @@ Project Simple is
5050
-- This attribute contains the switches used for "diners" only
5151
end Builder;
5252

53-
package Check is
54-
for Default_Switches ("ada") use ("-rules", "-from=coding_standard.rules");
55-
-- This attribute contains the switches used by the coding standard
56-
-- verifier
57-
end Check;
58-
5953
end Simple;

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,13 @@ package body Gnatcheck.Projects is
369369
(My_Project : Arg_Project_Type;
370370
Filename : String) return String is
371371
begin
372-
if Gnatcheck.Options.Gnatcheck_Prj.Is_Specified then
372+
if Gnatcheck.Options.Gnatcheck_Prj.Is_Specified
373+
and then Gnatcheck.Options.Gnatcheck_Prj.Tree.Is_Defined
374+
then
373375
return Normalize_Pathname
374376
(GNAT.Directory_Operations.Dir_Name
375-
(Gnatcheck.Options.Gnatcheck_Prj.Source_Prj.all) & Filename);
377+
(Gnatcheck_Prj.Tree.Root_Project.Path_Name.String_Value) &
378+
Filename);
376379
else
377380
return Normalize_Pathname (Filename);
378381
end if;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
chop.adb:14:11: PIck_Up does not have casing specified (mixed)
2+
chop.ads:11:18: Stick does not start with subtype prefix T_
3+
phil.adb:21:11: Think_Times does not start with subtype prefix T_
4+
phil.adb:25:11: Meal_Times does not start with subtype prefix T_
5+
phil.adb:31:13: Life_Time does not start with subtype prefix T_
6+
phil.adb:33:05: "Who_Am_I" is not modified, could be declared constant
7+
phil.ads:12:03: violation of restriction "No_Tasking"
8+
phil.ads:12:13: Philosopher does not start with subtype prefix T_
9+
phil.ads:12:26: My_ID does not have casing specified (mixed)
10+
phil.ads:19:08: States does not end with type suffix _Type
11+
phil.ads:19:08: States does not start with subtype prefix T_
12+
random_generic.ads:5:08: Result_Subtype does not end with type suffix _Type
13+
random_generic.ads:5:08: Result_Subtype does not start with subtype prefix T_
14+
room.adb:19:03: violation of restriction "No_Tasking"
15+
room.adb:19:23: anonymous subtype
16+
room.adb:20:03: violation of restriction "No_Tasking"
17+
room.adb:20:23: anonymous subtype
18+
room.adb:21:03: violation of restriction "No_Tasking"
19+
room.adb:21:23: anonymous subtype
20+
room.adb:22:03: violation of restriction "No_Tasking"
21+
room.adb:22:23: anonymous subtype
22+
room.adb:23:03: violation of restriction "No_Tasking"
23+
room.adb:23:23: anonymous subtype
24+
room.adb:25:08: Philosopher_Ptr does not end with access suffix _Access_Type
25+
room.adb:25:08: Philosopher_Ptr does not start with access prefix A_
26+
room.adb:27:11: anonymous array type
27+
room.adb:28:18: anonymous array type
28+
room.adb:29:16: anonymous array type
29+
room.adb:35:05: Blanks does not start with constant prefix C_
30+
room.adb:55:22: aggregate is not a part of a qualified expression
31+
room.adb:56:22: aggregate is not a part of a qualified expression
32+
room.adb:57:22: aggregate is not a part of a qualified expression
33+
room.adb:58:22: aggregate is not a part of a qualified expression
34+
room.adb:59:22: aggregate is not a part of a qualified expression
35+
room.adb:60:01: multiple blank lines
36+
room.adb:62:25: anonymous subtype
37+
room.ads:18:03: Table_Size does not start with constant prefix C_
38+
room.ads:19:11: Table_Type does not start with subtype prefix T_
39+
room.ads:21:12: anonymous array type
40+
room.ads:23:03: violation of restriction "No_Tasking"
41+
screen.adb:15:11: Int_IO does not have casing specified (mixed)
42+
screen.adb:22:13: ClearScreen does not have casing specified (mixed)
43+
screen.adb:28:13: MoveCursor does not have casing specified (mixed)
44+
screen.ads:10:03: ScreenHeight does not have casing specified (mixed)
45+
screen.ads:10:03: ScreenHeight does not start with constant prefix C_
46+
screen.ads:11:03: ScreenWidth does not have casing specified (mixed)
47+
screen.ads:11:03: ScreenWidth does not start with constant prefix C_
48+
screen.ads:13:11: Height does not start with subtype prefix T_
49+
screen.ads:14:11: Width does not start with subtype prefix T_
50+
screen.ads:16:08: Position does not end with type suffix _Type
51+
screen.ads:16:08: Position does not start with subtype prefix T_
52+
screen.ads:25:13: ClearScreen does not have casing specified (mixed)
53+
screen.ads:29:13: MoveCursor does not have casing specified (mixed)
54+
society.ads:11:11: Unique_DNA_Codes does not have casing specified (mixed)
55+
society.ads:11:11: Unique_DNA_Codes does not start with subtype prefix T_
56+
society.ads:13:19: anonymous array type
57+
society.ads:13:46: anonymous subtype
58+
windows.adb:11:18: UpperLeft does not have casing specified (mixed)
59+
windows.adb:18:22: aggregate is not a part of a qualified expression
60+
windows.adb:23:13: EraseToEndOfLine does not have casing specified (mixed)
61+
windows.adb:26:18: anonymous subtype
62+
windows.adb:62:18: anonymous subtype
63+
windows.adb:93:20: anonymous subtype
64+
windows.adb:107:18: anonymous subtype
65+
windows.adb:113:18: anonymous subtype
66+
windows.adb:114:26: aggregate is not a part of a qualified expression
67+
windows.adb:116:26: aggregate is not a part of a qualified expression
68+
windows.adb:121:24: aggregate is not a part of a qualified expression
69+
windows.adb:123:18: anonymous subtype
70+
windows.adb:129:17: aggregate is not a part of a qualified expression
71+
windows.adb:130:17: aggregate is not a part of a qualified expression
72+
windows.adb:134:13: MoveCursor does not have casing specified (mixed)
73+
windows.ads:11:08: Window does not end with type suffix _Type
74+
windows.ads:11:08: Window does not start with subtype prefix T_
75+
windows.ads:13:18: UpperLeft does not have casing specified (mixed)
76+
windows.ads:33:13: MoveCursor does not have casing specified (mixed)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
driver: gnatcheck
2+
format: brief
3+
project: simple
4+
check_flags: False

testsuite/testsuite.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ def set_up(self) -> None:
163163
# Directory that contains GPR files, shared by testcases
164164
os.environ['GPR_PROJECT_PATH'] = P.pathsep.join([
165165
P.join(self.root_dir, 'ada_projects'),
166+
P.abspath(
167+
P.join(
168+
self.root_dir,
169+
'..',
170+
'lkql_checker',
171+
'share',
172+
'examples'
173+
)
174+
),
166175
os.environ.get('GPR_PROJECT_PATH', ''),
167176
])
168177

0 commit comments

Comments
 (0)