xref: /linux/scripts/coccinelle/misc/semicolon.cocci (revision 680e6ffa15103ab610c0fc1241d2f98c801b13e2)
1///
2/// Remove unneeded semicolon.
3///
4// Confidence: Moderate
5// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6.  GPLv2.
6// URL: http://coccinelle.lip6.fr/
7// Comments: Some false positives on empty default cases in switch statements.
8// Options: --no-includes --include-headers
9
10virtual patch
11virtual report
12virtual context
13virtual org
14
15@r_default@
16position p;
17@@
18switch (...)
19{
20default: ...;@p
21}
22
23@r_case@
24position p;
25@@
26(
27switch (...)
28{
29case ...:;@p
30}
31|
32switch (...)
33{
34case ...:...
35case ...:;@p
36}
37|
38switch (...)
39{
40case ...:...
41case ...:
42case ...:;@p
43}
44)
45
46@r1@
47statement S;
48position p1;
49position p != {r_default.p, r_case.p};
50identifier label;
51@@
52(
53label:;
54|
55S@p1;@p
56)
57
58@script:python@
59p << r1.p;
60p1 << r1.p1;
61@@
62if p[0].line != p1[0].line_end:
63	cocci.include_match(False)
64
65@depends on patch@
66position r1.p;
67@@
68-;@p
69
70@script:python depends on report@
71p << r1.p;
72@@
73coccilib.report.print_report(p[0],"Unneeded semicolon")
74
75@depends on context@
76position r1.p;
77@@
78*;@p
79
80@script:python depends on org@
81p << r1.p;
82@@
83cocci.print_main("Unneeded semicolon",p)
84