Skip to content

Commit d4c7544

Browse files
Hongbo LiJuliaLawall
authored andcommitted
coccinelle: Add rules to find str_hi{gh}_lo{w}() replacements
As other rules done, we add rules for str_hi{gh}_lo{w}() to check the relative opportunities. Signed-off-by: Hongbo Li <lihongbo22@huawei.com> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
1 parent 8a0236b commit d4c7544

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

scripts/coccinelle/api/string_choices.cocci

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,45 @@ e << str_false_true_r.E;
123123
@@
124124
125125
coccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e)
126+
127+
@str_hi_lo depends on patch@
128+
expression E;
129+
@@
130+
(
131+
- ((E) ? "hi" : "lo")
132+
+ str_hi_lo(E)
133+
)
134+
135+
@str_hi_lo_r depends on !patch exists@
136+
expression E;
137+
position P;
138+
@@
139+
(
140+
* ((E@P) ? "hi" : "lo")
141+
)
142+
143+
@script:python depends on report@
144+
p << str_hi_lo_r.P;
145+
e << str_hi_lo_r.E;
146+
@@
147+
148+
coccilib.report.print_report(p[0], "opportunity for str_hi_lo(%s)" % e)
149+
150+
@str_high_low depends on patch@
151+
expression E;
152+
@@
153+
- ((E) ? "high" : "low")
154+
+ str_high_low(E)
155+
156+
@str_high_low_r depends on !patch exists@
157+
expression E;
158+
position P;
159+
@@
160+
* ((E@P) ? "high" : "low")
161+
162+
@script:python depends on report@
163+
p << str_high_low_r.P;
164+
e << str_high_low_r.E;
165+
@@
166+
167+
coccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e)

0 commit comments

Comments
 (0)