coccinelle: Add rules to find str_false_true() replacements
authorHongbo Li <lihongbo22@huawei.com>
Wed, 11 Sep 2024 01:09:19 +0000 (09:09 +0800)
committerJulia Lawall <Julia.Lawall@inria.fr>
Sat, 28 Sep 2024 19:21:50 +0000 (21:21 +0200)
As done with str_true_false(), add checks for str_false_true()
opportunities. A simple test can find over 9 cases currently
exist in the tree.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
scripts/coccinelle/api/string_choices.cocci

index 6942ad7c422444cc5a0fbdb02f3acc612a940b69..c3c5bc94fab0be1f4877cfae418882057886c60a 100644 (file)
@@ -104,3 +104,22 @@ e << str_true_false_r.E;
 @@
 
 coccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e)
+
+@str_false_true depends on patch@
+expression E;
+@@
+-      ((E) ? "false" : "true")
++      str_false_true(E)
+
+@str_false_true_r depends on !patch exists@
+expression E;
+position P;
+@@
+*      ((E@P) ? "false" : "true")
+
+@script:python depends on report@
+p << str_false_true_r.P;
+e << str_false_true_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e)