xref: /linux/scripts/coccinelle/api/string_choices.cocci (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1// SPDX-License-Identifier: GPL-2.0-only
2/// Find places to use string_choices.h's various helpers.
3//
4// Confidence: Medium
5// Options: --no-includes --include-headers
6virtual patch
7virtual context
8virtual report
9
10@str_plural depends on patch@
11expression E;
12@@
13(
14-	((E == 1) ? "" : "s")
15+	str_plural(E)
16|
17-	((E > 1) ? "s" : "")
18+	str_plural(E)
19)
20
21@str_plural_r depends on !patch@
22expression E;
23position P;
24@@
25(
26*	(E@P == 1) ? "" : "s"
27|
28*	(E@P > 1) ? "s" : ""
29)
30
31@script:python depends on report@
32p << str_plural_r.P;
33e << str_plural_r.E;
34@@
35
36coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
37
38@str_up_down depends on patch disable neg_if_exp@
39expression E;
40@@
41-	((E) ? "up" : "down")
42+	str_up_down(E)
43
44@str_up_down_r depends on !patch disable neg_if_exp@
45expression E;
46position P;
47@@
48*	E@P ? "up" : "down"
49
50@script:python depends on report@
51p << str_up_down_r.P;
52e << str_up_down_r.E;
53@@
54
55coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
56
57@str_down_up depends on patch disable neg_if_exp@
58expression E;
59@@
60-      ((E) ? "down" : "up")
61+      str_down_up(E)
62
63@str_down_up_r depends on !patch disable neg_if_exp@
64expression E;
65position P;
66@@
67*      E@P ? "down" : "up"
68
69@script:python depends on report@
70p << str_down_up_r.P;
71e << str_down_up_r.E;
72@@
73
74coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)
75
76@str_true_false depends on patch disable neg_if_exp@
77expression E;
78@@
79-      ((E) ? "true" : "false")
80+      str_true_false(E)
81
82@str_true_false_r depends on !patch disable neg_if_exp@
83expression E;
84position P;
85@@
86*      E@P ? "true" : "false"
87
88@script:python depends on report@
89p << str_true_false_r.P;
90e << str_true_false_r.E;
91@@
92
93coccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e)
94
95@str_false_true depends on patch disable neg_if_exp@
96expression E;
97@@
98-      ((E) ? "false" : "true")
99+      str_false_true(E)
100
101@str_false_true_r depends on !patch disable neg_if_exp@
102expression E;
103position P;
104@@
105*      E@P ? "false" : "true"
106
107@script:python depends on report@
108p << str_false_true_r.P;
109e << str_false_true_r.E;
110@@
111
112coccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e)
113
114@str_hi_lo depends on patch disable neg_if_exp@
115expression E;
116@@
117-      ((E) ? "hi" : "lo")
118+      str_hi_lo(E)
119
120@str_hi_lo_r depends on !patch disable neg_if_exp@
121expression E;
122position P;
123@@
124*      E@P ? "hi" : "lo"
125
126@script:python depends on report@
127p << str_hi_lo_r.P;
128e << str_hi_lo_r.E;
129@@
130
131coccilib.report.print_report(p[0], "opportunity for str_hi_lo(%s)" % e)
132
133@str_high_low depends on patch disable neg_if_exp@
134expression E;
135@@
136-      ((E) ? "high" : "low")
137+      str_high_low(E)
138
139@str_high_low_r depends on !patch disable neg_if_exp@
140expression E;
141position P;
142@@
143*      E@P ? "high" : "low"
144
145@script:python depends on report@
146p << str_high_low_r.P;
147e << str_high_low_r.E;
148@@
149
150coccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e)
151
152@str_lo_hi depends on patch disable neg_if_exp@
153expression E;
154@@
155-      ((E) ? "lo" : "hi")
156+      str_lo_hi(E)
157
158@str_lo_hi_r depends on !patch disable neg_if_exp@
159expression E;
160position P;
161@@
162*      E@P ? "lo" : "hi"
163
164@script:python depends on report@
165p << str_lo_hi_r.P;
166e << str_lo_hi_r.E;
167@@
168
169coccilib.report.print_report(p[0], "opportunity for str_lo_hi(%s)" % e)
170
171@str_low_high depends on patch disable neg_if_exp@
172expression E;
173@@
174-      ((E) ? "low" : "high")
175+      str_low_high(E)
176
177@str_low_high_r depends on !patch disable neg_if_exp@
178expression E;
179position P;
180@@
181*      E@P ? "low" : "high"
182
183@script:python depends on report@
184p << str_low_high_r.P;
185e << str_low_high_r.E;
186@@
187
188coccilib.report.print_report(p[0], "opportunity for str_low_high(%s)" % e)
189
190@str_enable_disable depends on patch@
191expression E;
192@@
193-      ((E) ? "enable" : "disable")
194+      str_enable_disable(E)
195
196@str_enable_disable_r depends on !patch@
197expression E;
198position P;
199@@
200*      E@P ? "enable" : "disable"
201
202@script:python depends on report@
203p << str_enable_disable_r.P;
204e << str_enable_disable_r.E;
205@@
206
207coccilib.report.print_report(p[0], "opportunity for str_enable_disable(%s)" % e)
208
209@str_enabled_disabled depends on patch@
210expression E;
211@@
212-      ((E) ? "enabled" : "disabled")
213+      str_enabled_disabled(E)
214
215@str_enabled_disabled_r depends on !patch@
216expression E;
217position P;
218@@
219*      E@P ? "enabled" : "disabled"
220
221@script:python depends on report@
222p << str_enabled_disabled_r.P;
223e << str_enabled_disabled_r.E;
224@@
225
226coccilib.report.print_report(p[0], "opportunity for str_enabled_disabled(%s)" % e)
227
228@str_read_write depends on patch disable neg_if_exp@
229expression E;
230@@
231-      ((E) ? "read" : "write")
232+      str_read_write(E)
233
234@str_read_write_r depends on !patch disable neg_if_exp@
235expression E;
236position P;
237@@
238*      E@P ? "read" : "write"
239
240@script:python depends on report@
241p << str_read_write_r.P;
242e << str_read_write_r.E;
243@@
244
245coccilib.report.print_report(p[0], "opportunity for str_read_write(%s)" % e)
246
247@str_write_read depends on patch disable neg_if_exp@
248expression E;
249@@
250-      ((E) ? "write" : "read")
251+      str_write_read(E)
252
253@str_write_read_r depends on !patch disable neg_if_exp@
254expression E;
255position P;
256@@
257*      E@P ? "write" : "read"
258
259@script:python depends on report@
260p << str_write_read_r.P;
261e << str_write_read_r.E;
262@@
263
264coccilib.report.print_report(p[0], "opportunity for str_write_read(%s)" % e)
265
266@str_on_off depends on patch@
267expression E;
268@@
269-      ((E) ? "on" : "off")
270+      str_on_off(E)
271
272@str_on_off_r depends on !patch@
273expression E;
274position P;
275@@
276*      E@P ? "on" : "off"
277
278@script:python depends on report@
279p << str_on_off_r.P;
280e << str_on_off_r.E;
281@@
282
283coccilib.report.print_report(p[0], "opportunity for str_on_off(%s)" % e)
284
285@str_yes_no depends on patch@
286expression E;
287@@
288-      ((E) ? "yes" : "no")
289+      str_yes_no(E)
290
291@str_yes_no_r depends on !patch@
292expression E;
293position P;
294@@
295*      E@P ? "yes" : "no"
296
297@script:python depends on report@
298p << str_yes_no_r.P;
299e << str_yes_no_r.E;
300@@
301
302coccilib.report.print_report(p[0], "opportunity for str_yes_no(%s)" % e)
303