xref: /linux/scripts/coccinelle/api/string_choices.cocci (revision dd2275d349c2f02ceb6cd37f89b8b9920c602488)
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-	((E > 1) ? "s" : "")
211d02f252SKees Cook+	str_plural(E)
221d02f252SKees Cook)
231d02f252SKees Cook
241d02f252SKees Cook@str_plural_r depends on !patch exists@
251d02f252SKees Cookexpression E;
261d02f252SKees Cookposition P;
271d02f252SKees Cook@@
281d02f252SKees Cook(
291d02f252SKees Cook*	((E@P == 1) ? "" : "s")
301d02f252SKees Cook|
311d02f252SKees Cook*	((E@P != 1) ? "s" : "")
321d02f252SKees Cook|
331d02f252SKees Cook*	((E@P > 1) ? "s" : "")
341d02f252SKees Cook)
351d02f252SKees Cook
361d02f252SKees Cook@script:python depends on report@
371d02f252SKees Cookp << str_plural_r.P;
381d02f252SKees Cooke << str_plural_r.E;
391d02f252SKees Cook@@
401d02f252SKees Cook
411d02f252SKees Cookcoccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
429b97452bSMichal Wajdeczko
439b97452bSMichal Wajdeczko@str_up_down depends on patch@
449b97452bSMichal Wajdeczkoexpression E;
459b97452bSMichal Wajdeczko@@
469b97452bSMichal Wajdeczko(
479b97452bSMichal Wajdeczko-	((E) ? "up" : "down")
489b97452bSMichal Wajdeczko+	str_up_down(E)
499b97452bSMichal Wajdeczko)
509b97452bSMichal Wajdeczko
519b97452bSMichal Wajdeczko@str_up_down_r depends on !patch exists@
529b97452bSMichal Wajdeczkoexpression E;
539b97452bSMichal Wajdeczkoposition P;
549b97452bSMichal Wajdeczko@@
559b97452bSMichal Wajdeczko(
569b97452bSMichal Wajdeczko*	((E@P) ? "up" : "down")
579b97452bSMichal Wajdeczko)
589b97452bSMichal Wajdeczko
599b97452bSMichal Wajdeczko@script:python depends on report@
609b97452bSMichal Wajdeczkop << str_up_down_r.P;
619b97452bSMichal Wajdeczkoe << str_up_down_r.E;
629b97452bSMichal Wajdeczko@@
639b97452bSMichal Wajdeczko
649b97452bSMichal Wajdeczkococcilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
650336f898SKees Cook
660336f898SKees Cook@str_down_up depends on patch@
670336f898SKees Cookexpression E;
680336f898SKees Cook@@
690336f898SKees Cook(
700336f898SKees Cook-      ((E) ? "down" : "up")
710336f898SKees Cook+      str_down_up(E)
720336f898SKees Cook)
730336f898SKees Cook
740336f898SKees Cook@str_down_up_r depends on !patch exists@
750336f898SKees Cookexpression E;
760336f898SKees Cookposition P;
770336f898SKees Cook@@
780336f898SKees Cook(
790336f898SKees Cook*      ((E@P) ? "down" : "up")
800336f898SKees Cook)
810336f898SKees Cook
820336f898SKees Cook@script:python depends on report@
830336f898SKees Cookp << str_down_up_r.P;
840336f898SKees Cooke << str_down_up_r.E;
850336f898SKees Cook@@
860336f898SKees Cook
870336f898SKees Cookcoccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)
88716bf84eSHongbo Li
89716bf84eSHongbo Li@str_true_false depends on patch@
90716bf84eSHongbo Liexpression E;
91716bf84eSHongbo Li@@
92716bf84eSHongbo Li-      ((E) ? "true" : "false")
93716bf84eSHongbo Li+      str_true_false(E)
94716bf84eSHongbo Li
95716bf84eSHongbo Li@str_true_false_r depends on !patch exists@
96716bf84eSHongbo Liexpression E;
97716bf84eSHongbo Liposition P;
98716bf84eSHongbo Li@@
99716bf84eSHongbo Li*      ((E@P) ? "true" : "false")
100716bf84eSHongbo Li
101716bf84eSHongbo Li@script:python depends on report@
102716bf84eSHongbo Lip << str_true_false_r.P;
103716bf84eSHongbo Lie << str_true_false_r.E;
104716bf84eSHongbo Li@@
105716bf84eSHongbo Li
106716bf84eSHongbo Licoccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e)
1078a0236baSHongbo Li
1088a0236baSHongbo Li@str_false_true depends on patch@
1098a0236baSHongbo Liexpression E;
1108a0236baSHongbo Li@@
1118a0236baSHongbo Li-      ((E) ? "false" : "true")
1128a0236baSHongbo Li+      str_false_true(E)
1138a0236baSHongbo Li
1148a0236baSHongbo Li@str_false_true_r depends on !patch exists@
1158a0236baSHongbo Liexpression E;
1168a0236baSHongbo Liposition P;
1178a0236baSHongbo Li@@
1188a0236baSHongbo Li*      ((E@P) ? "false" : "true")
1198a0236baSHongbo Li
1208a0236baSHongbo Li@script:python depends on report@
1218a0236baSHongbo Lip << str_false_true_r.P;
1228a0236baSHongbo Lie << str_false_true_r.E;
1238a0236baSHongbo Li@@
1248a0236baSHongbo Li
1258a0236baSHongbo Licoccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e)
126d4c75440SHongbo Li
127d4c75440SHongbo Li@str_hi_lo depends on patch@
128d4c75440SHongbo Liexpression E;
129d4c75440SHongbo Li@@
130d4c75440SHongbo Li(
131d4c75440SHongbo Li-      ((E) ? "hi" : "lo")
132d4c75440SHongbo Li+      str_hi_lo(E)
133d4c75440SHongbo Li)
134d4c75440SHongbo Li
135d4c75440SHongbo Li@str_hi_lo_r depends on !patch exists@
136d4c75440SHongbo Liexpression E;
137d4c75440SHongbo Liposition P;
138d4c75440SHongbo Li@@
139d4c75440SHongbo Li(
140d4c75440SHongbo Li*      ((E@P) ? "hi" : "lo")
141d4c75440SHongbo Li)
142d4c75440SHongbo Li
143d4c75440SHongbo Li@script:python depends on report@
144d4c75440SHongbo Lip << str_hi_lo_r.P;
145d4c75440SHongbo Lie << str_hi_lo_r.E;
146d4c75440SHongbo Li@@
147d4c75440SHongbo Li
148d4c75440SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_hi_lo(%s)" % e)
149d4c75440SHongbo Li
150d4c75440SHongbo Li@str_high_low depends on patch@
151d4c75440SHongbo Liexpression E;
152d4c75440SHongbo Li@@
153d4c75440SHongbo Li-      ((E) ? "high" : "low")
154d4c75440SHongbo Li+      str_high_low(E)
155d4c75440SHongbo Li
156d4c75440SHongbo Li@str_high_low_r depends on !patch exists@
157d4c75440SHongbo Liexpression E;
158d4c75440SHongbo Liposition P;
159d4c75440SHongbo Li@@
160d4c75440SHongbo Li*      ((E@P) ? "high" : "low")
161d4c75440SHongbo Li
162d4c75440SHongbo Li@script:python depends on report@
163d4c75440SHongbo Lip << str_high_low_r.P;
164d4c75440SHongbo Lie << str_high_low_r.E;
165d4c75440SHongbo Li@@
166d4c75440SHongbo Li
167d4c75440SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e)
1685b7ca450SHongbo Li
1695b7ca450SHongbo Li@str_lo_hi depends on patch@
1705b7ca450SHongbo Liexpression E;
1715b7ca450SHongbo Li@@
1725b7ca450SHongbo Li-      ((E) ? "lo" : "hi")
1735b7ca450SHongbo Li+      str_lo_hi(E)
1745b7ca450SHongbo Li
1755b7ca450SHongbo Li@str_lo_hi_r depends on !patch exists@
1765b7ca450SHongbo Liexpression E;
1775b7ca450SHongbo Liposition P;
1785b7ca450SHongbo Li@@
1795b7ca450SHongbo Li*      ((E@P) ? "lo" : "hi")
1805b7ca450SHongbo Li
1815b7ca450SHongbo Li@script:python depends on report@
1825b7ca450SHongbo Lip << str_lo_hi_r.P;
1835b7ca450SHongbo Lie << str_lo_hi_r.E;
1845b7ca450SHongbo Li@@
1855b7ca450SHongbo Li
1865b7ca450SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_lo_hi(%s)" % e)
1875b7ca450SHongbo Li
1885b7ca450SHongbo Li@str_low_high depends on patch@
1895b7ca450SHongbo Liexpression E;
1905b7ca450SHongbo Li@@
1915b7ca450SHongbo Li-      ((E) ? "low" : "high")
1925b7ca450SHongbo Li+      str_low_high(E)
1935b7ca450SHongbo Li
1945b7ca450SHongbo Li@str_low_high_r depends on !patch exists@
1955b7ca450SHongbo Liexpression E;
1965b7ca450SHongbo Liposition P;
1975b7ca450SHongbo Li@@
1985b7ca450SHongbo Li*      ((E@P) ? "low" : "high")
1995b7ca450SHongbo Li
2005b7ca450SHongbo Li@script:python depends on report@
2015b7ca450SHongbo Lip << str_low_high_r.P;
2025b7ca450SHongbo Lie << str_low_high_r.E;
2035b7ca450SHongbo Li@@
2045b7ca450SHongbo Li
2055b7ca450SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_low_high(%s)" % e)
206*dd2275d3SHongbo Li
207*dd2275d3SHongbo Li@str_enable_disable depends on patch@
208*dd2275d3SHongbo Liexpression E;
209*dd2275d3SHongbo Li@@
210*dd2275d3SHongbo Li-      ((E) ? "enable" : "disable")
211*dd2275d3SHongbo Li+      str_enable_disable(E)
212*dd2275d3SHongbo Li
213*dd2275d3SHongbo Li@str_enable_disable_r depends on !patch exists@
214*dd2275d3SHongbo Liexpression E;
215*dd2275d3SHongbo Liposition P;
216*dd2275d3SHongbo Li@@
217*dd2275d3SHongbo Li*      ((E@P) ? "enable" : "disable")
218*dd2275d3SHongbo Li
219*dd2275d3SHongbo Li@script:python depends on report@
220*dd2275d3SHongbo Lip << str_enable_disable_r.P;
221*dd2275d3SHongbo Lie << str_enable_disable_r.E;
222*dd2275d3SHongbo Li@@
223*dd2275d3SHongbo Li
224*dd2275d3SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_enable_disable(%s)" % e)
225*dd2275d3SHongbo Li
226*dd2275d3SHongbo Li@str_enabled_disabled depends on patch@
227*dd2275d3SHongbo Liexpression E;
228*dd2275d3SHongbo Li@@
229*dd2275d3SHongbo Li-      ((E) ? "enabled" : "disabled")
230*dd2275d3SHongbo Li+      str_enabled_disabled(E)
231*dd2275d3SHongbo Li
232*dd2275d3SHongbo Li@str_enabled_disabled_r depends on !patch exists@
233*dd2275d3SHongbo Liexpression E;
234*dd2275d3SHongbo Liposition P;
235*dd2275d3SHongbo Li@@
236*dd2275d3SHongbo Li*      ((E@P) ? "enabled" : "disabled")
237*dd2275d3SHongbo Li
238*dd2275d3SHongbo Li@script:python depends on report@
239*dd2275d3SHongbo Lip << str_enabled_disabled_r.P;
240*dd2275d3SHongbo Lie << str_enabled_disabled_r.E;
241*dd2275d3SHongbo Li@@
242*dd2275d3SHongbo Li
243*dd2275d3SHongbo Licoccilib.report.print_report(p[0], "opportunity for str_enabled_disabled(%s)" % e)
244