]> git.proxmox.com Git - mirror_frr.git/blob - tools/coccinelle/hash_const.cocci
lib: hashing functions should take const arguments
[mirror_frr.git] / tools / coccinelle / hash_const.cocci
1 //
2 // Transition hash key signatures to take their argument as const.
3 // Does not handle headers or weirdly named hash functions.
4 //
5 @noconst disable optional_qualifier@
6 identifier A;
7 identifier func =~ ".*key$|.*key_make$|.*hash_make$|.*hash_keymake$|.*hash_key$|.*hash_key.*";
8 @@
9
10 - func (void *A)
11 + func (const void *A)
12 { ... }
13
14 @ depends on noconst disable optional_qualifier @
15 identifier noconst.A;
16 identifier noconst.func;
17 identifier b;
18 type T;
19 @@
20
21 func( ... ) {
22 <...
23 - T b = A;
24 + const T b = A;
25 ...>
26 }
27
28 @ depends on noconst disable optional_qualifier @
29 identifier noconst.A;
30 identifier noconst.func;
31 identifier b;
32 type T;
33 @@
34
35 func(...)
36 {
37 <...
38 - T b = (T) A;
39 + const T b = A;
40 ...>
41 }
42
43 @ depends on noconst disable optional_qualifier @
44 identifier noconst.A;
45 identifier noconst.func;
46 identifier b;
47 type T;
48 @@
49
50 func(...)
51 {
52 <...
53 - T b;
54 + const T b;
55 ...
56 b = A;
57 ...>
58 }
59
60 @ depends on noconst disable optional_qualifier @
61 identifier noconst.A;
62 identifier noconst.func;
63 identifier b;
64 type T;
65 @@
66
67 func(...)
68 {
69 <...
70 - T b;
71 + const T b;
72 ...
73 - b = (T) A;
74 + b = A;
75 ...>
76 }