Skip to content

Commit f794335

Browse files
committed
Merge branch 'topic/float_eq_follow_renamings' into 'master'
Enhance the Float_Equality_Checks rule to be able to follow renamings See merge request eng/libadalang/langkit-query-language!128
2 parents 21898f3 + 8b366a4 commit f794335

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

lkql_checker/doc/gnatcheck_rm/predefined_rules.rst

+9-6
Original file line numberDiff line numberDiff line change
@@ -7192,13 +7192,16 @@ This rule has no parameters.
71927192

71937193
Flag all explicit calls to the predefined equality operations for
71947194
floating-point types and private types whose completions are floating-point
7195-
types. Both '``=``' and '``/=``' operations are checked.
7196-
User-defined equality operations are not flagged, nor are uses of operators
7197-
that are renamings of the predefined equality operations.
7198-
Also, the '``=``' and '``/=``' operations for fixed-point types
7199-
are not flagged.
7195+
types. Both '=' and '/=' operations are checked. User-defined equality
7196+
operations are not flagged. Also, the '=' and '/=' operations for fixed-point
7197+
types are not flagged. Uses of operators that are renamings of the predefined
7198+
equality operations will be flagged if `Follow_Renamings` is true.
7199+
7200+
This rule has the following (optional) parameter for the ``+R`` option:
7201+
7202+
*Follow_Renamings*
7203+
Take renamings of predefined equality operations into account.
72007204

7201-
This rule has no parameters.
72027205

72037206
.. rubric:: Example
72047207

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Flag all explicit calls to the predefined equality operations for
22
# floating-point types and private types whose completions are floating-point
33
# types. Both '=' and '/=' operations are checked. User-defined equality
4-
# operations are not flagged, nor are uses of operators that are renamings of
5-
# the predefined equality operations. Also, the '=' and '/=' operations for
6-
# fixed-point types are not flagged.
4+
# operations are not flagged. Also, the '=' and '/=' operations for fixed-point
5+
# types are not flagged. Uses of operators that are renamings of the predefined
6+
# equality operations will be flagged if `follow_renamings` is true.
77

88
import stdlib
99

@@ -12,11 +12,13 @@ fun is_float(n) =
1212
when t.p_full_view().p_is_float_type()
1313

1414
@check(message="use of equality operation for float values", category="Feature")
15-
fun float_equality_checks(node) =
16-
node is (RelationOp(f_op is op@(OpEq or OpNeq))
17-
when stdlib.is_predefined_op(op) and is_float(node.f_left))
15+
fun float_equality_checks(node, follow_renamings=false) =
16+
node is (
17+
RelationOp(f_op is op@(OpEq or OpNeq))
18+
when stdlib.is_predefined_op(op, follow_renamings) and is_float(node.f_left)
19+
)
1820
or CallExpr
1921
when (node.f_name.p_name_is("\"=\"") or
2022
node.f_name.p_name_is("\"/=\""))
21-
and stdlib.is_predefined_op(node)
23+
and stdlib.is_predefined_op(node, follow_renamings)
2224
and is_float(node.f_suffix[1].f_r_expr)

lkql_checker/share/lkql/stdlib.lkql

+3-2
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ fun param_pos(n, pos: int = 0) =
154154
if not n then pos else param_pos(n?.previous_sibling(), pos+1)
155155

156156
# TODO: move this in LAL
157-
fun is_predefined_op(op) =
157+
fun is_predefined_op(op, follow_renamings=false) =
158158
|" Return true if op is a predefined operator
159159
{
160160
val ref = op.p_referenced_decl();
161+
val real_ref = if follow_renamings then ultimate_subprogram_alias(ref) else ref;
161162
# TODO: remove null check once all operators are synthesized (UB16-053)
162-
not ref or ref is SyntheticSubpDecl
163+
not real_ref or real_ref is SyntheticSubpDecl
163164
}
164165

165166
fun is_standard_numeric(n) =

0 commit comments

Comments
 (0)