Skip to content

Commit 0077283

Browse files
committed
Merge branch 'topic/lowercase_keywords_2' into 'master'
Fix lowercase_keywords rule See merge request eng/libadalang/langkit-query-language!469
2 parents 8ac3e3e + 79c2cc8 commit 0077283

File tree

21 files changed

+114
-39
lines changed

21 files changed

+114
-39
lines changed

lkql_checker/doc/generated/list_of_rules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ GNATcheck rules.
140140
* :ref:`Overloaded_Operators`
141141
* :ref:`Overly_Nested_Control_Structures`
142142
* :ref:`Overly_Nested_Scopes`
143-
* :ref:`Overriding_Marks`
143+
* :ref:`Overriding_Indicators`
144144
* :ref:`Parameters_Aliasing`
145145
* :ref:`Parameters_Out_Of_Order`
146146
* :ref:`POS_On_Enumeration_Types`

lkql_checker/doc/generated/predefined_rules.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6251,12 +6251,12 @@ first construct is flagged
62516251
62526252
62536253
6254-
.. _Overriding_Marks:
6254+
.. _Overriding_Indicators:
62556255

6256-
``Overriding_Marks``
6257-
^^^^^^^^^^^^^^^^^^^^
6256+
``Overriding_Indicators``
6257+
^^^^^^^^^^^^^^^^^^^^^^^^^
62586258

6259-
.. index:: Overriding_Marks
6259+
.. index:: Overriding_Indicators
62606260

62616261
Check that overriding subprograms are explicitly marked as such.
62626262

lkql_checker/share/lkql/lowercase_keywords.lkql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ fun lowercase_keywords(unit, language_version="ada_2022") =
4545
|" packagE Foo is -- FLAG
4646
|" END Foo; -- FLAG
4747
[
48-
{message: "Keyword should be lowercase", loc: tok}
48+
{message: "reserved words should be lowercase", loc: tok}
4949
for tok in unit.tokens
5050
if tok.text.to_lower_case.contains(keyword_matcher(language_version))
51+
and not tok.previous().kind == "tick"
5152
and tok.text.contains(match_uppercase)
53+
5254
]

lkql_checker/share/lkql/no_dependence.lkql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import stdlib
22

3-
@check(category="Style", subcategory="Readability", message="Forbidden dependency")
3+
@check(category="Style", subcategory="Readability", message="forbidden dependence")
44
fun no_dependence(node, unit_names=[]) =
55
|" Flag every explicit dependency (with clause) to any of the library units
66
|" designated by names passed as parameters.

lkql_checker/share/lkql/overriding_marks.lkql renamed to lkql_checker/share/lkql/overriding_indicators.lkql

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,23 @@ fun match_signature(child_prim, parent_prim, child_type, parent_type) =
4242
}
4343
}
4444

45-
@check(category="Style", subcategory="Readability", message="Missing overriding mark")
46-
fun overriding_marks(node) =
45+
fun is_overriding_subprogram(node) =
46+
|" Returns whether the node passed as argument corresponds to an overriding
47+
|" subprogram
48+
node is (BasicSubpDecl | BaseSubpBody) (
49+
p_subp_spec_or_null(): BaseSubpSpec(
50+
p_primitive_subp_first_type(): t@TypeDecl(
51+
p_base_type(): bt@TypeDecl(
52+
p_get_primitives(): primitives@(not null)
53+
when stdlib.any([p for p in primitives if match_signature(node, p, t, bt)])
54+
)
55+
)
56+
)
57+
)
58+
59+
60+
@check(category="Style", subcategory="Readability", message="missing overriding indicator")
61+
fun overriding_indicators(node) =
4762
|" Check that overriding subprograms are explicitly marked as such.
4863
|"
4964
|" This applies to all subprograms of a derived type that override a
@@ -70,18 +85,15 @@ fun overriding_marks(node) =
7085
|" procedure Prim (Self : B) is null; -- FLAG
7186
|" end Foo;
7287
# Select primitives subprograms
73-
node is (BasicSubpDecl | BaseSubpBody) (
74-
p_subp_spec_or_null(): BaseSubpSpec(
75-
p_primitive_subp_first_type(): t@TypeDecl(
76-
p_base_type(): bt@TypeDecl(
77-
p_get_primitives(): primitives@(not null)
78-
when stdlib.any([p for p in primitives if match_signature(node, p, t, bt)])
79-
)
80-
)
81-
),
82-
f_overriding: OverridingUnspecified
88+
(
89+
node is (BasicSubpDecl | BaseSubpBody) (f_overriding: OverridingUnspecified)
90+
when is_overriding_subprogram(node)
8391
)
8492

8593
# Body stubs can also take an "overriding" indicator. In that case, check
8694
# the body.
87-
or node is SubpBodyStub(p_previous_part_for_decl(): dcl) when overriding_marks(dcl)
95+
or (
96+
node is SubpBodyStub(p_previous_part_for_decl(): dcl,
97+
f_overriding: OverridingUnspecified)
98+
when is_overriding_subprogram(dcl)
99+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test_83.adb:1:1: rule violation: reserved words should be lowercase
2+
1 | procedurE Test_83 IS -- FLAG (2)
3+
| ^^^^^^^^^
4+
5+
test_83.adb:1:19: rule violation: reserved words should be lowercase
6+
1 | procedurE Test_83 IS -- FLAG (2)
7+
| ^^
8+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
driver: 'checker'
2+
rule_name: lowercase_keywords
3+
input_sources: ['test_83.adb']
4+
rule_arguments:
5+
lowercase_keywords.language_version: '"ada_83"'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
procedurE Test_83 IS -- FLAG (2)
2+
A : InterfacE; -- NOFLAG
3+
B : TaggeD; -- NOFLAG
4+
begin
5+
null;
6+
end Test_83;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test_95.adb:2:14: rule violation: reserved words should be lowercase
2+
2 | type A is Abstract Tagged null record; -- FLAG (2)
3+
| ^^^^^^^^
4+
5+
test_95.adb:2:23: rule violation: reserved words should be lowercase
6+
2 | type A is Abstract Tagged null record; -- FLAG (2)
7+
| ^^^^^^
8+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
driver: 'checker'
2+
rule_name: lowercase_keywords
3+
input_sources: ['test_95.adb']
4+
rule_arguments:
5+
lowercase_keywords.language_version: '"ada_95"'

0 commit comments

Comments
 (0)