diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2015-09-04 15:27:51 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.com> | 2015-10-26 15:39:44 -0400 |
commit | 74a8478f9ea2b3e70640a64db8acd54d4225a2c4 (patch) | |
tree | bae08da287d7430998ddd3f71524d96cfc38bf02 /scripts | |
parent | 60fb33afb93a85e6ca5804397a9dc6f6907fa58f (diff) |
coccinelle: misc: move constants to the right
Move constants to the right in binary operators.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Michal Marek <mmarek@suse.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/coccinelle/misc/compare_const_fl.cocci | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/scripts/coccinelle/misc/compare_const_fl.cocci b/scripts/coccinelle/misc/compare_const_fl.cocci new file mode 100644 index 000000000000..b5d4bab60263 --- /dev/null +++ b/scripts/coccinelle/misc/compare_const_fl.cocci | |||
@@ -0,0 +1,171 @@ | |||
1 | /// Move constants to the right of binary operators. | ||
2 | //# Depends on personal taste in some cases. | ||
3 | /// | ||
4 | // Confidence: Moderate | ||
5 | // Copyright: (C) 2015 Copyright: (C) 2015 Julia Lawall, Inria. GPLv2. | ||
6 | // URL: http://coccinelle.lip6.fr/ | ||
7 | // Options: --no-includes --include-headers | ||
8 | |||
9 | virtual patch | ||
10 | virtual context | ||
11 | virtual org | ||
12 | virtual report | ||
13 | |||
14 | @r1 depends on patch && !context && !org && !report | ||
15 | disable bitor_comm, neg_if_exp@ | ||
16 | constant c,c1; | ||
17 | local idexpression i; | ||
18 | expression e,e1,e2; | ||
19 | binary operator b = {==,!=,&,|}; | ||
20 | type t; | ||
21 | @@ | ||
22 | |||
23 | ( | ||
24 | c b (c1) | ||
25 | | | ||
26 | sizeof(t) b e1 | ||
27 | | | ||
28 | sizeof e b e1 | ||
29 | | | ||
30 | i b e1 | ||
31 | | | ||
32 | c | e1 | e2 | ... | ||
33 | | | ||
34 | c | (e ? e1 : e2) | ||
35 | | | ||
36 | - c | ||
37 | + e | ||
38 | b | ||
39 | - e | ||
40 | + c | ||
41 | ) | ||
42 | |||
43 | @r2 depends on patch && !context && !org && !report | ||
44 | disable gtr_lss, gtr_lss_eq, not_int2@ | ||
45 | constant c,c1; | ||
46 | expression e,e1,e2; | ||
47 | binary operator b; | ||
48 | binary operator b1 = {<,<=},b2 = {<,<=}; | ||
49 | binary operator b3 = {>,>=},b4 = {>,>=}; | ||
50 | local idexpression i; | ||
51 | type t; | ||
52 | @@ | ||
53 | |||
54 | ( | ||
55 | c b c1 | ||
56 | | | ||
57 | sizeof(t) b e1 | ||
58 | | | ||
59 | sizeof e b e1 | ||
60 | | | ||
61 | (e1 b1 e) && (e b2 e2) | ||
62 | | | ||
63 | (e1 b3 e) && (e b4 e2) | ||
64 | | | ||
65 | i b e | ||
66 | | | ||
67 | - c < e | ||
68 | + e > c | ||
69 | | | ||
70 | - c <= e | ||
71 | + e >= c | ||
72 | | | ||
73 | - c > e | ||
74 | + e < c | ||
75 | | | ||
76 | - c >= e | ||
77 | + e <= c | ||
78 | ) | ||
79 | |||
80 | // ---------------------------------------------------------------------------- | ||
81 | |||
82 | @r1_context depends on !patch && (context || org || report) | ||
83 | disable bitor_comm, neg_if_exp exists@ | ||
84 | type t; | ||
85 | binary operator b = {==,!=,&,|}; | ||
86 | constant c, c1; | ||
87 | expression e, e1, e2; | ||
88 | local idexpression i; | ||
89 | position j0; | ||
90 | @@ | ||
91 | |||
92 | ( | ||
93 | c b (c1) | ||
94 | | | ||
95 | sizeof(t) b e1 | ||
96 | | | ||
97 | sizeof e b e1 | ||
98 | | | ||
99 | i b e1 | ||
100 | | | ||
101 | c | e1 | e2 | ... | ||
102 | | | ||
103 | c | (e ? e1 : e2) | ||
104 | | | ||
105 | * c@j0 b e | ||
106 | ) | ||
107 | |||
108 | @r2_context depends on !patch && (context || org || report) | ||
109 | disable gtr_lss, gtr_lss_eq, not_int2 exists@ | ||
110 | type t; | ||
111 | binary operator b, b1 = {<,<=}, b2 = {<,<=}, b3 = {>,>=}, b4 = {>,>=}; | ||
112 | constant c, c1; | ||
113 | expression e, e1, e2; | ||
114 | local idexpression i; | ||
115 | position j0; | ||
116 | @@ | ||
117 | |||
118 | ( | ||
119 | c b c1 | ||
120 | | | ||
121 | sizeof(t) b e1 | ||
122 | | | ||
123 | sizeof e b e1 | ||
124 | | | ||
125 | (e1 b1 e) && (e b2 e2) | ||
126 | | | ||
127 | (e1 b3 e) && (e b4 e2) | ||
128 | | | ||
129 | i b e | ||
130 | | | ||
131 | * c@j0 < e | ||
132 | | | ||
133 | * c@j0 <= e | ||
134 | | | ||
135 | * c@j0 > e | ||
136 | | | ||
137 | * c@j0 >= e | ||
138 | ) | ||
139 | |||
140 | // ---------------------------------------------------------------------------- | ||
141 | |||
142 | @script:python r1_org depends on org@ | ||
143 | j0 << r1_context.j0; | ||
144 | @@ | ||
145 | |||
146 | msg = "Move constant to right." | ||
147 | coccilib.org.print_todo(j0[0], msg) | ||
148 | |||
149 | @script:python r2_org depends on org@ | ||
150 | j0 << r2_context.j0; | ||
151 | @@ | ||
152 | |||
153 | msg = "Move constant to right." | ||
154 | coccilib.org.print_todo(j0[0], msg) | ||
155 | |||
156 | // ---------------------------------------------------------------------------- | ||
157 | |||
158 | @script:python r1_report depends on report@ | ||
159 | j0 << r1_context.j0; | ||
160 | @@ | ||
161 | |||
162 | msg = "Move constant to right." | ||
163 | coccilib.report.print_report(j0[0], msg) | ||
164 | |||
165 | @script:python r2_report depends on report@ | ||
166 | j0 << r2_context.j0; | ||
167 | @@ | ||
168 | |||
169 | msg = "Move constant to right." | ||
170 | coccilib.report.print_report(j0[0], msg) | ||
171 | |||