summaryrefslogtreecommitdiff
path: root/scripts/coccinelle/api/string_choices.cocci
blob: 5e729f187f22ebea49a842bfe941b59fc262ab38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: GPL-2.0-only
/// Find places to use string_choices.h's various helpers.
//
// Confidence: Medium
// Options: --no-includes --include-headers
virtual patch
virtual context
virtual report

@str_plural depends on patch@
expression E;
@@
(
-	((E == 1) ? "" : "s")
+	str_plural(E)
|
-	((E != 1) ? "s" : "")
+	str_plural(E)
|
-	((E > 1) ? "s" : "")
+	str_plural(E)
)

@str_plural_r depends on !patch exists@
expression E;
position P;
@@
(
*	((E@P == 1) ? "" : "s")
|
*	((E@P != 1) ? "s" : "")
|
*	((E@P > 1) ? "s" : "")
)

@script:python depends on report@
p << str_plural_r.P;
e << str_plural_r.E;
@@

coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)

@str_up_down depends on patch@
expression E;
@@
(
-	((E) ? "up" : "down")
+	str_up_down(E)
)

@str_up_down_r depends on !patch exists@
expression E;
position P;
@@
(
*	((E@P) ? "up" : "down")
)

@script:python depends on report@
p << str_up_down_r.P;
e << str_up_down_r.E;
@@

coccilib.report.print_report(p[0], "opportunity for str_up_down(%s)" % e)

@str_down_up depends on patch@
expression E;
@@
(
-      ((E) ? "down" : "up")
+      str_down_up(E)
)

@str_down_up_r depends on !patch exists@
expression E;
position P;
@@
(
*      ((E@P) ? "down" : "up")
)

@script:python depends on report@
p << str_down_up_r.P;
e << str_down_up_r.E;
@@

coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)