xref: /linux/scripts/coccinelle/api/string_choices.cocci (revision 68e4b0e024e3ee4d4bc8bf212f4db63e0e3ad094)
11d02f252SKees Cook// SPDX-License-Identifier: GPL-2.0-only
21d02f252SKees Cook/// Find places to use string_choices.h's various helpers.
31d02f252SKees Cook//
41d02f252SKees Cook// Confidence: Medium
51d02f252SKees Cook// Options: --no-includes --include-headers
61d02f252SKees Cookvirtual patch
71d02f252SKees Cookvirtual context
81d02f252SKees Cookvirtual report
91d02f252SKees Cook
101d02f252SKees Cook@str_plural depends on patch@
111d02f252SKees Cookexpression E;
121d02f252SKees Cook@@
131d02f252SKees Cook(
141d02f252SKees Cook-	((E == 1) ? "" : "s")
151d02f252SKees Cook+	str_plural(E)
161d02f252SKees Cook|
171d02f252SKees Cook-	((E > 1) ? "s" : "")
181d02f252SKees Cook+	str_plural(E)
191d02f252SKees Cook)
201d02f252SKees Cook
21*4003ba66SJulia Lawall@str_plural_r depends on !patch@
221d02f252SKees Cookexpression E;
231d02f252SKees Cookposition P;
241d02f252SKees Cook@@
251d02f252SKees Cook(
26*4003ba66SJulia Lawall*	(E@P == 1) ? "" : "s"
271d02f252SKees Cook|
28*4003ba66SJulia Lawall*	(E@P > 1) ? "s" : ""
291d02f252SKees Cook)
301d02f252SKees Cook
311d02f252SKees Cook@script:python depends on report@
321d02f252SKees Cookp << str_plural_r.P;
331d02f252SKees Cooke << str_plural_r.E;
341d02f252SKees Cook@@
351d02f252SKees Cook
361d02f252SKees Cookcoccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
379b97452bSMichal Wajdeczko
38*4003ba66SJulia Lawall@str_up_down depends on patch disable neg_if_exp@
399b97452bSMichal Wajdeczkoexpression E;
409b97452bSMichal Wajdeczko@@
419b97452bSMichal Wajdeczko-	((E) ? "up" : "down")
429b97452bSMichal Wajdeczko+	str_up_down(E)
439b97452bSMichal Wajdeczko
44*4003ba66SJulia Lawall@str_up_down_r depends on !patch disable neg_if_exp@
459b97452bSMichal Wajdeczkoexpression E;
469b97452bSMichal Wajdeczkoposition P;
479b97452bSMichal Wajdeczko@@
48*4003ba66SJulia Lawall*	E@P ? "up" : "down"
499b97452bSMichal Wajdeczko
509b97452bSMichal Wajdeczko@script:python depends on report@
519b97452bSMichal Wajdeczkop << str_up_down_r.P;
529b97452bSMichal Wajdeczkoe << str_up_down_r.E;
539b97452bSMichal Wajdeczko@@
549b97452bSMichal Wajdeczko
559b97452bSMichal Wajdeczkococcilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
560336f898SKees Cook
57*4003ba66SJulia Lawall@str_down_up depends on patch disable neg_if_exp@
580336f898SKees Cookexpression E;
590336f898SKees Cook@@
600336f898SKees Cook-      ((E) ? "down" : "up")
610336f898SKees Cook+      str_down_up(E)
620336f898SKees Cook
63*4003ba66SJulia Lawall@str_down_up_r depends on !patch disable neg_if_exp@
640336f898SKees Cookexpression E;
650336f898SKees Cookposition P;
660336f898SKees Cook@@
67*4003ba66SJulia Lawall*      E@P ? "down" : "up"
680336f898SKees Cook
690336f898SKees Cook@script:python depends on report@
700336f898SKees Cookp << str_down_up_r.P;
710336f898SKees Cooke << str_down_up_r.E;
720336f898SKees Cook@@
730336f898SKees Cook
740336f898SKees Cookcoccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)
75716bf84eSHongbo Li
76*4003ba66SJulia Lawall@str_true_false depends on patch disable neg_if_exp@
77716bf84eSHongbo Liexpression E;
78716bf84eSHongbo Li@@
79716bf84eSHongbo Li-      ((E) ? "true" : "false")
80716bf84eSHongbo Li+      str_true_false(E)
81716bf84eSHongbo Li
82*4003ba66SJulia Lawall@str_true_false_r depends on !patch disable neg_if_exp@
83716bf84eSHongbo Liexpression E;
84716bf84eSHongbo Liposition P;
85716bf84eSHongbo Li@@
86*4003ba66SJulia Lawall*      E@P ? "true" : "false"
87716bf84eSHongbo Li
88716bf84eSHongbo Li@script:python depends on report@
89716bf84eSHongbo Lip << str_true_false_r.P;
90716bf84eSHongbo Lie << str_true_false_r.E;
91716bf84eSHongbo Li@@
92716bf84eSHongbo Li
93716bf84eSHongbo Licoccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e)
948a0236baSHongbo Li
95*4003ba66SJulia Lawall@str_false_true depends on patch disable neg_if_exp@
968a0236baSHongbo Liexpression E;
978a0236baSHongbo Li@@
988a0236baSHongbo Li-      ((E) ? "false" : "true")
998a0236baSHongbo Li+      str_false_true(E)
1008a0236baSHongbo Li
101*4003ba66SJulia Lawall@str_false_true_r depends on !patch disable neg_if_exp@
1028a0236baSHongbo Liexpression E;
1038a0236baSHongbo Liposition P;
1048a0236baSHongbo Li@@
105*4003ba66SJulia Lawall*      E@P ? "false" : "true"
1068a0236baSHongbo Li
1078a0236baSHongbo Li@script:python depends on report@
1088a0236baSHongbo Lip << str_false_true_r.P;
1098a0236baSHongbo Lie << str_false_true_r.E;
1108a0236baSHongbo Li@@
1118a0236baSHongbo Li
1128a0236baSHongbo Licoccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e)
113d4c75440SHongbo Li
114*4003ba66SJulia Lawall@str_hi_lo depends on patch disable neg_if_exp@
115d4c75440SHongbo Liexpression E;
116d4c75440SHongbo Li@@
117d4c75440SHongbo Li-      ((E) ? "hi" : "lo")
118d4c75440SHongbo Li+      str_hi_lo(E)
119d4c75440SHongbo Li
120*4003ba66SJulia Lawall@str_hi_lo_r depends on !patch disable neg_if_exp@
121d4c75440SHongbo Liexpression E;
122d4c75440SHongbo Liposition P;
123d4c75440SHongbo Li@@
124*4003ba66SJulia Lawall*      E@P ? "hi" : "lo"
125d4c75440SHongbo Li
126d4c75440SHongbo Li@script:python depends on report@
127d4c75440SHongbo Lip << str_hi_lo_r.P;
128d4c75440SHongbo Lie << str_hi_lo_r.E;
129d4c75440SHongbo Li@@
130d4c75440SHongbo Li
131d4c75440SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_hi_lo(%s)" % e)
132d4c75440SHongbo Li
133*4003ba66SJulia Lawall@str_high_low depends on patch disable neg_if_exp@
134d4c75440SHongbo Liexpression E;
135d4c75440SHongbo Li@@
136d4c75440SHongbo Li-      ((E) ? "high" : "low")
137d4c75440SHongbo Li+      str_high_low(E)
138d4c75440SHongbo Li
139*4003ba66SJulia Lawall@str_high_low_r depends on !patch disable neg_if_exp@
140d4c75440SHongbo Liexpression E;
141d4c75440SHongbo Liposition P;
142d4c75440SHongbo Li@@
143*4003ba66SJulia Lawall*      E@P ? "high" : "low"
144d4c75440SHongbo Li
145d4c75440SHongbo Li@script:python depends on report@
146d4c75440SHongbo Lip << str_high_low_r.P;
147d4c75440SHongbo Lie << str_high_low_r.E;
148d4c75440SHongbo Li@@
149d4c75440SHongbo Li
150d4c75440SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e)
1515b7ca450SHongbo Li
152*4003ba66SJulia Lawall@str_lo_hi depends on patch disable neg_if_exp@
1535b7ca450SHongbo Liexpression E;
1545b7ca450SHongbo Li@@
1555b7ca450SHongbo Li-      ((E) ? "lo" : "hi")
1565b7ca450SHongbo Li+      str_lo_hi(E)
1575b7ca450SHongbo Li
158*4003ba66SJulia Lawall@str_lo_hi_r depends on !patch disable neg_if_exp@
1595b7ca450SHongbo Liexpression E;
1605b7ca450SHongbo Liposition P;
1615b7ca450SHongbo Li@@
162*4003ba66SJulia Lawall*      E@P ? "lo" : "hi"
1635b7ca450SHongbo Li
1645b7ca450SHongbo Li@script:python depends on report@
1655b7ca450SHongbo Lip << str_lo_hi_r.P;
1665b7ca450SHongbo Lie << str_lo_hi_r.E;
1675b7ca450SHongbo Li@@
1685b7ca450SHongbo Li
1695b7ca450SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_lo_hi(%s)" % e)
1705b7ca450SHongbo Li
171*4003ba66SJulia Lawall@str_low_high depends on patch disable neg_if_exp@
1725b7ca450SHongbo Liexpression E;
1735b7ca450SHongbo Li@@
1745b7ca450SHongbo Li-      ((E) ? "low" : "high")
1755b7ca450SHongbo Li+      str_low_high(E)
1765b7ca450SHongbo Li
177*4003ba66SJulia Lawall@str_low_high_r depends on !patch disable neg_if_exp@
1785b7ca450SHongbo Liexpression E;
1795b7ca450SHongbo Liposition P;
1805b7ca450SHongbo Li@@
181*4003ba66SJulia Lawall*      E@P ? "low" : "high"
1825b7ca450SHongbo Li
1835b7ca450SHongbo Li@script:python depends on report@
1845b7ca450SHongbo Lip << str_low_high_r.P;
1855b7ca450SHongbo Lie << str_low_high_r.E;
1865b7ca450SHongbo Li@@
1875b7ca450SHongbo Li
1885b7ca450SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_low_high(%s)" % e)
189dd2275d3SHongbo Li
190dd2275d3SHongbo Li@str_enable_disable depends on patch@
191dd2275d3SHongbo Liexpression E;
192dd2275d3SHongbo Li@@
193dd2275d3SHongbo Li-      ((E) ? "enable" : "disable")
194dd2275d3SHongbo Li+      str_enable_disable(E)
195dd2275d3SHongbo Li
196*4003ba66SJulia Lawall@str_enable_disable_r depends on !patch@
197dd2275d3SHongbo Liexpression E;
198dd2275d3SHongbo Liposition P;
199dd2275d3SHongbo Li@@
200*4003ba66SJulia Lawall*      E@P ? "enable" : "disable"
201dd2275d3SHongbo Li
202dd2275d3SHongbo Li@script:python depends on report@
203dd2275d3SHongbo Lip << str_enable_disable_r.P;
204dd2275d3SHongbo Lie << str_enable_disable_r.E;
205dd2275d3SHongbo Li@@
206dd2275d3SHongbo Li
207dd2275d3SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_enable_disable(%s)" % e)
208dd2275d3SHongbo Li
209dd2275d3SHongbo Li@str_enabled_disabled depends on patch@
210dd2275d3SHongbo Liexpression E;
211dd2275d3SHongbo Li@@
212dd2275d3SHongbo Li-      ((E) ? "enabled" : "disabled")
213dd2275d3SHongbo Li+      str_enabled_disabled(E)
214dd2275d3SHongbo Li
215*4003ba66SJulia Lawall@str_enabled_disabled_r depends on !patch@
216dd2275d3SHongbo Liexpression E;
217dd2275d3SHongbo Liposition P;
218dd2275d3SHongbo Li@@
219*4003ba66SJulia Lawall*      E@P ? "enabled" : "disabled"
220dd2275d3SHongbo Li
221dd2275d3SHongbo Li@script:python depends on report@
222dd2275d3SHongbo Lip << str_enabled_disabled_r.P;
223dd2275d3SHongbo Lie << str_enabled_disabled_r.E;
224dd2275d3SHongbo Li@@
225dd2275d3SHongbo Li
226dd2275d3SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_enabled_disabled(%s)" % e)
227ba4b514aSHongbo Li
228*4003ba66SJulia Lawall@str_read_write depends on patch disable neg_if_exp@
229ba4b514aSHongbo Liexpression E;
230ba4b514aSHongbo Li@@
231ba4b514aSHongbo Li-      ((E) ? "read" : "write")
232ba4b514aSHongbo Li+      str_read_write(E)
233ba4b514aSHongbo Li
234*4003ba66SJulia Lawall@str_read_write_r depends on !patch disable neg_if_exp@
235ba4b514aSHongbo Liexpression E;
236ba4b514aSHongbo Liposition P;
237ba4b514aSHongbo Li@@
238*4003ba66SJulia Lawall*      E@P ? "read" : "write"
239ba4b514aSHongbo Li
240ba4b514aSHongbo Li@script:python depends on report@
241ba4b514aSHongbo Lip << str_read_write_r.P;
242ba4b514aSHongbo Lie << str_read_write_r.E;
243ba4b514aSHongbo Li@@
244ba4b514aSHongbo Li
245ba4b514aSHongbo Licoccilib.report.print_report(p[0], "opportunity for str_read_write(%s)" % e)
246c81ca023SHongbo Li
247*4003ba66SJulia Lawall@str_write_read depends on patch disable neg_if_exp@
248c81ca023SHongbo Liexpression E;
249c81ca023SHongbo Li@@
250c81ca023SHongbo Li-      ((E) ? "write" : "read")
251c81ca023SHongbo Li+      str_write_read(E)
252c81ca023SHongbo Li
253*4003ba66SJulia Lawall@str_write_read_r depends on !patch disable neg_if_exp@
254c81ca023SHongbo Liexpression E;
255c81ca023SHongbo Liposition P;
256c81ca023SHongbo Li@@
257*4003ba66SJulia Lawall*      E@P ? "write" : "read"
258c81ca023SHongbo Li
259c81ca023SHongbo Li@script:python depends on report@
260c81ca023SHongbo Lip << str_write_read_r.P;
261c81ca023SHongbo Lie << str_write_read_r.E;
262c81ca023SHongbo Li@@
263c81ca023SHongbo Li
264c81ca023SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_write_read(%s)" % e)
2659b5b4810SHongbo Li
2669b5b4810SHongbo Li@str_on_off depends on patch@
2679b5b4810SHongbo Liexpression E;
2689b5b4810SHongbo Li@@
2699b5b4810SHongbo Li-      ((E) ? "on" : "off")
2709b5b4810SHongbo Li+      str_on_off(E)
2719b5b4810SHongbo Li
272*4003ba66SJulia Lawall@str_on_off_r depends on !patch@
2739b5b4810SHongbo Liexpression E;
2749b5b4810SHongbo Liposition P;
2759b5b4810SHongbo Li@@
276*4003ba66SJulia Lawall*      E@P ? "on" : "off"
2779b5b4810SHongbo Li
2789b5b4810SHongbo Li@script:python depends on report@
2799b5b4810SHongbo Lip << str_on_off_r.P;
2809b5b4810SHongbo Lie << str_on_off_r.E;
2819b5b4810SHongbo Li@@
2829b5b4810SHongbo Li
2839b5b4810SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_on_off(%s)" % e)
284253244cdSHongbo Li
285253244cdSHongbo Li@str_yes_no depends on patch@
286253244cdSHongbo Liexpression E;
287253244cdSHongbo Li@@
288253244cdSHongbo Li-      ((E) ? "yes" : "no")
289253244cdSHongbo Li+      str_yes_no(E)
290253244cdSHongbo Li
291*4003ba66SJulia Lawall@str_yes_no_r depends on !patch@
292253244cdSHongbo Liexpression E;
293253244cdSHongbo Liposition P;
294253244cdSHongbo Li@@
295*4003ba66SJulia Lawall*      E@P ? "yes" : "no"
296253244cdSHongbo Li
297253244cdSHongbo Li@script:python depends on report@
298253244cdSHongbo Lip << str_yes_no_r.P;
299253244cdSHongbo Lie << str_yes_no_r.E;
300253244cdSHongbo Li@@
301253244cdSHongbo Li
302253244cdSHongbo Licoccilib.report.print_report(p[0], "opportunity for str_yes_no(%s)" % e)
303