13134e9dffbb623c64f231cbca033f90f83158c6
[deb_dpdk.git] / devtools / cocci / mtod-offset.cocci
1 //
2 // Replace explicit packet offset computations with rte_pktmbuf_mtod_offset().
3 //
4 @disable paren@
5 typedef uint8_t;
6 expression M, O;
7 @@
8 (
9 - rte_pktmbuf_mtod(M, char *) + O
10 + rte_pktmbuf_mtod_offset(M, char *, O)
11 |
12 - rte_pktmbuf_mtod(M, char *) - O
13 + rte_pktmbuf_mtod_offset(M, char *, -O)
14 |
15 - rte_pktmbuf_mtod(M, unsigned char *) + O
16 + rte_pktmbuf_mtod_offset(M, unsigned char *, O)
17 |
18 - rte_pktmbuf_mtod(M, unsigned char *) - O
19 + rte_pktmbuf_mtod_offset(M, unsigned char *, -O)
20 |
21 - rte_pktmbuf_mtod(M, uint8_t *) + O
22 + rte_pktmbuf_mtod_offset(M, uint8_t *, O)
23 |
24 - rte_pktmbuf_mtod(M, uint8_t *) - O
25 + rte_pktmbuf_mtod_offset(M, uint8_t *, -O)
26 )
27
28
29 //
30 // Fold subsequent offset terms into pre-existing offset used in
31 // rte_pktmbuf_mtod_offset().
32 //
33 @disable paren@
34 expression M, O1, O2;
35 @@
36 (
37 - rte_pktmbuf_mtod_offset(M, char *, O1) + O2
38 + rte_pktmbuf_mtod_offset(M, char *, O1 + O2)
39 |
40 - rte_pktmbuf_mtod_offset(M, char *, O1) - O2
41 + rte_pktmbuf_mtod_offset(M, char *, O1 - O2)
42 |
43 - rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2
44 + rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2)
45 |
46 - rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2
47 + rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2)
48 |
49 - rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2
50 + rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2)
51 |
52 - rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2
53 + rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2)
54 )
55
56
57 //
58 // Cleanup rules.  Fold in double casts, remove unnecessary paranthesis, etc.
59 //
60 @disable paren@
61 expression M, O;
62 type C, T;
63 @@
64 (
65 - (C)rte_pktmbuf_mtod_offset(M, T, O)
66 + rte_pktmbuf_mtod_offset(M, C, O)
67 |
68 - (rte_pktmbuf_mtod_offset(M, T, O))
69 + rte_pktmbuf_mtod_offset(M, T, O)
70 |
71 - (C)rte_pktmbuf_mtod(M, T)
72 + rte_pktmbuf_mtod(M, C)
73 |
74 - (rte_pktmbuf_mtod(M, T))
75 + rte_pktmbuf_mtod(M, T)
76 )