Release coccinelle-0.2.0rc1
[bpt/coccinelle.git] / tests / array.cocci
CommitLineData
7f004419
C
1// Use the macro ARRAY_SIZE when possible
2//
3// Confidence: High
4// Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU. GPLv2.
5// URL: http://coccinelle.lip6.fr/rules/array.html
6// Options: -I ... -all_includes can give more complete results
7virtual org
8virtual patch
9
10@i@
11@@
12
13#include <linux/kernel.h>
14
15/////////////////////////////////////
16/////////////////////////////////////
17@depends on i && patch && !org@
18type T;
19T[] E;
20@@
21
22- (sizeof(E)/sizeof(*E))
23+ ARRAY_SIZE(E)
24
25@depends on i && patch && !org@
26type T;
27T[] E;
28@@
29
30- (sizeof(E)/sizeof(E[...]))
31+ ARRAY_SIZE(E)
32
33@depends on i && patch && !org@
34type T;
35T[] E;
36@@
37
38- (sizeof(E)/sizeof(T))
39+ ARRAY_SIZE(E)
40
41@n_patch depends on patch && !org@
42identifier AS,E;
43@@
44
45- #define AS(E) ARRAY_SIZE(E)
46
47@ depends on patch && !org@
48expression E;
49identifier n_patch.AS;
50@@
51
52- AS(E)
53+ ARRAY_SIZE(E)
54
55
56/////////////////////////////////////
57/////////////////////////////////////
58@arr_ptr depends on i && !patch && org@
59type T;
60T[] E;
61position p;
34e49164 62@@
7f004419
C
63
64 (sizeof(E@p)/sizeof(*E))
65
66@arr_tab depends on i && !patch && org@
34e49164 67type T;
7f004419
C
68T[] E;
69position p;
70@@
71
72 (sizeof(E@p)/sizeof(E[...]))
73
74@arr_typ depends on i && !patch && org@
75type T;
76T[] E;
77position p;
78@@
79
80 (sizeof(E@p)/sizeof(T))
81
82@n_org depends on !patch && org@
83identifier AS,E;
34e49164
C
84@@
85
7f004419
C
86#define AS(E) ARRAY_SIZE(E)
87
88@arr_def depends on !patch && org@
89expression E;
90identifier n_org.AS;
91position p;
92@@
93
94AS@p(E)
95
96@script:python@
97p << arr_ptr.p;
98e << arr_ptr.E;
99@@
100cocci.print_main(e,p)
101
102@script:python@
103p << arr_tab.p;
104e << arr_tab.E;
105@@
106cocci.print_main(e,p)
107
108@script:python@
109p << arr_typ.p;
110e << arr_typ.E;
111@@
112cocci.print_main(e,p)
113
114@script:python@
115p << arr_def.p;
116e << arr_def.E;
117@@
118cocci.print_main(e,p)