Release coccinelle-0.2.3rc4
[bpt/coccinelle.git] / tests / rcu2.cocci
1 // prepare for transformation
2
3 @@
4 idexpression struct list_head *I;
5 @@
6
7 - I
8 + _Y(I)
9
10 @@
11 identifier I;
12 expression E;
13 iterator name list_for_each_rcu;
14 statement S;
15 @@
16
17 list_for_each_rcu(
18 - _Y(I)
19 + _X(I)
20 ,E)
21 S
22
23 @@
24 identifier I;
25 expression E;
26 iterator name list_for_each;
27 statement S;
28 @@
29
30 list_for_each(
31 - _Y(I)
32 + _X(I)
33 ,E)
34 S
35
36 @@
37 identifier I;
38 expression E;
39 iterator name list_for_each_prev;
40 statement S;
41 @@
42
43 list_for_each_prev(
44 - _Y(I)
45 + _X(I)
46 ,E)
47 S
48
49 @@
50 type T;
51 identifier I;
52 expression E;
53 @@
54
55 list_entry(
56 - _Y(I)
57 + _X(I)
58 ,T,E)
59
60 // the case where the list element is just stored in a variable
61
62 @r@
63 type T,T1;
64 identifier I, x;
65 expression E, E1, E2;
66 iterator name list_for_each_entry_rcu;
67 @@
68
69 <... when != _Y(I)
70 - list_for_each_rcu(_X(I),E1)
71 + list_for_each_entry_rcu(x,E1,E2)
72 {
73 ... when != \(_Y(I)\|_X(I)\|x=E\)
74 when != T1 x;
75 - x = list_entry(_X(I),T,E2);
76 ... when != \(_Y(I)\|_X(I)\|x=E\)
77 }
78 ...>
79
80 @ra@
81 type T,T1;
82 identifier I, x;
83 expression E, E1, E2;
84 iterator name list_for_each_entry;
85 @@
86
87 <... when != _Y(I)
88 - list_for_each(_X(I),E1)
89 + list_for_each_entry(x,E1,E2)
90 {
91 ... when != \(_Y(I)\|_X(I)\|x=E\)
92 when != T1 x;
93 - x = list_entry(_X(I),T,E2);
94 ... when != \(_Y(I)\|_X(I)\|x=E\)
95 }
96 ...>
97
98 @rb@
99 type T,T1;
100 identifier I, x;
101 expression E, E1, E2;
102 iterator name list_for_each_entry_reverse;
103 @@
104
105 <... when != _Y(I)
106 - list_for_each_prev(_X(I),E1)
107 + list_for_each_entry_reverse(x,E1,E2)
108 {
109 ... when != \(_Y(I)\|_X(I)\|x=E\)
110 when != T1 x;
111 - x = list_entry(_X(I),T,E2);
112 ... when != \(_Y(I)\|_X(I)\|x=E\)
113 }
114 ...>
115
116 // instances of the above that we can't treat because of the local variable
117 // problem. seems better to do nothing.
118
119 @r1@
120 type T,T1;
121 identifier I, x;
122 expression E1, E2;
123 @@
124
125 list_for_each_rcu(
126 - _X(I)
127 + _Y(I)
128 ,E1)
129 {
130 ...
131 (
132 T1 x;
133 ...
134 x =
135 - list_entry(_X(I),T,E2);
136 + _LOCAL_DECL(list_entry(_X(I),T,E2));
137 |
138 T1 x =
139 - list_entry(_X(I),T,E2);
140 + _LOCAL_DECL(list_entry(_X(I),T,E2));
141 )
142 ...
143 }
144
145 @r1a@
146 type T,T1;
147 identifier I, x;
148 expression E1, E2;
149 @@
150
151 list_for_each(
152 - _X(I)
153 + _Y(I)
154 ,E1)
155 {
156 ...
157 (
158 T1 x;
159 ...
160 x =
161 - list_entry(_X(I),T,E2);
162 + _LOCAL_DECL(list_entry(_X(I),T,E2));
163 |
164 T1 x =
165 - list_entry(_X(I),T,E2);
166 + _LOCAL_DECL(list_entry(_X(I),T,E2));
167 )
168 ...
169 }
170
171 @r1b@
172 type T,T1;
173 identifier I, x;
174 expression E1, E2;
175 @@
176
177 list_for_each_prev(
178 - _X(I)
179 + _Y(I)
180 ,E1)
181 {
182 ...
183 (
184 T1 x;
185 ...
186 x =
187 - list_entry(_X(I),T,E2);
188 + _LOCAL_DECL(list_entry(_X(I),T,E2));
189 |
190 T1 x =
191 - list_entry(_X(I),T,E2);
192 + _LOCAL_DECL(list_entry(_X(I),T,E2));
193 )
194 ...
195 }
196
197 // the case where the list element is used for something else (often a return)
198
199 @@
200 type T;
201 identifier I;
202 expression E1, E2;
203 @@
204
205 - struct list_head *I;
206 + T *I;
207 <+... when != _Y(I)
208 - list_for_each_rcu(_X(I),E1)
209 + list_for_each_entry_rcu(I,E1,E2)
210 {
211 <+... when != _Y(I)
212 - list_entry(_X(I),T,E2)
213 + I
214 ...+>
215 }
216 ...+>
217
218 @@
219 type T;
220 identifier I;
221 expression E1, E2;
222 @@
223
224 - struct list_head *I;
225 + T *I;
226 <+... when != _Y(I)
227 - list_for_each(_X(I),E1)
228 + list_for_each_entry(I,E1,E2)
229 {
230 <+... when != _Y(I)
231 - list_entry(_X(I),T,E2)
232 + I
233 ...+>
234 }
235 ...+>
236
237 @@
238 type T;
239 identifier I;
240 expression E1, E2;
241 @@
242
243 - struct list_head *I;
244 + T *I;
245 <+... when != _Y(I)
246 - list_for_each_prev(_X(I),E1)
247 + list_for_each_entry_reverse(I,E1,E2)
248 {
249 <+... when != _Y(I)
250 - list_entry(_X(I),T,E2)
251 + I
252 ...+>
253 }
254 ...+>
255
256 // clean up
257
258 @@
259 struct list_head *I;
260 @@
261
262 (
263 - _X(I)
264 + I
265 |
266 - _Y(I)
267 + I
268 )
269
270 @@
271 expression I;
272 @@
273
274 (
275 - _X(I)
276 + _INCONSISTENT_MODIF(I)
277 |
278 - _Y(I)
279 + _INCONSISTENT_MODIF(I)
280 )
281
282 @ depends on r || ra @
283 identifier I;
284 @@
285
286 - struct list_head *I;
287 ... when != I