xref: /linux/scripts/coccinelle/api/string_choices.cocci (revision c94cd9508b1335b949fd13ebd269313c65492df0)
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-	((E > 1) ? "s" : "")
21+	str_plural(E)
22)
23
24@str_plural_r depends on !patch exists@
25expression E;
26position P;
27@@
28(
29*	((E@P == 1) ? "" : "s")
30|
31*	((E@P != 1) ? "s" : "")
32|
33*	((E@P > 1) ? "s" : "")
34)
35
36@script:python depends on report@
37p << str_plural_r.P;
38e << str_plural_r.E;
39@@
40
41coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
42
43@str_up_down depends on patch@
44expression E;
45@@
46(
47-	((E) ? "up" : "down")
48+	str_up_down(E)
49)
50
51@str_up_down_r depends on !patch exists@
52expression E;
53position P;
54@@
55(
56*	((E@P) ? "up" : "down")
57)
58
59@script:python depends on report@
60p << str_up_down_r.P;
61e << str_up_down_r.E;
62@@
63
64coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)
65
66@str_down_up depends on patch@
67expression E;
68@@
69(
70-      ((E) ? "down" : "up")
71+      str_down_up(E)
72)
73
74@str_down_up_r depends on !patch exists@
75expression E;
76position P;
77@@
78(
79*      ((E@P) ? "down" : "up")
80)
81
82@script:python depends on report@
83p << str_down_up_r.P;
84e << str_down_up_r.E;
85@@
86
87coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)
88