diff mbox series

[-next,v2,4/9] coccinelle: Add rules to find str_lo{w}_hi{gh}() replacements

Message ID 20240904091451.3328272-5-lihongbo22@huawei.com (mailing list archive)
State Superseded
Headers show
Series coccinelle: Add some rules for string_chioces helpers. | expand

Commit Message

Hongbo Li Sept. 4, 2024, 9:14 a.m. UTC
As other rules done, we add rules for str_lo{w}_hi{gh}()
to check the relative opportunities.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
 scripts/coccinelle/api/string_choices.cocci | 46 +++++++++++++++++++++
 1 file changed, 46 insertions(+)
diff mbox series

Patch

diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index 67818cd6ee09..53fd34a0fcb4 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -177,3 +177,49 @@  e << str_high_low_r.E;
 @@
 
 coccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e)
+
+@str_lo_hi depends on patch@
+expression E;
+@@
+(
+-      ((E) ? "lo" : "hi")
++      str_lo_hi(E)
+)
+
+@str_lo_hi_r depends on !patch exists@
+expression E;
+position P;
+@@
+(
+*      ((E@P) ? "lo" : "hi")
+)
+
+@script:python depends on report@
+p << str_lo_hi_r.P;
+e << str_lo_hi_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_lo_hi(%s)" % e)
+
+@str_low_high depends on patch@
+expression E;
+@@
+(
+-      ((E) ? "low" : "high")
++      str_low_high(E)
+)
+
+@str_low_high_r depends on !patch exists@
+expression E;
+position P;
+@@
+(
+*      ((E@P) ? "low" : "high")
+)
+
+@script:python depends on report@
+p << str_low_high_r.P;
+e << str_low_high_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_low_high(%s)" % e)