| Peter Senna Tschudin | 7320bfa | 2012-12-08 15:34:34 -0200 | [diff] [blame] | 1 | /// | 
|  | 2 | /// Removes 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 |  | 
|  | 10 | virtual patch | 
|  | 11 | virtual report | 
|  | 12 | virtual context | 
|  | 13 | virtual org | 
|  | 14 |  | 
|  | 15 | @r_default@ | 
|  | 16 | position p; | 
|  | 17 | @@ | 
|  | 18 | switch (...) | 
|  | 19 | { | 
|  | 20 | default: ...;@p | 
|  | 21 | } | 
|  | 22 |  | 
|  | 23 | @r_case@ | 
|  | 24 | position p; | 
|  | 25 | @@ | 
|  | 26 | ( | 
|  | 27 | switch (...) | 
|  | 28 | { | 
|  | 29 | case ...:;@p | 
|  | 30 | } | 
|  | 31 | | | 
|  | 32 | switch (...) | 
|  | 33 | { | 
|  | 34 | case ...:... | 
|  | 35 | case ...:;@p | 
|  | 36 | } | 
|  | 37 | | | 
|  | 38 | switch (...) | 
|  | 39 | { | 
|  | 40 | case ...:... | 
|  | 41 | case ...: | 
|  | 42 | case ...:;@p | 
|  | 43 | } | 
|  | 44 | ) | 
|  | 45 |  | 
|  | 46 | @r1@ | 
|  | 47 | statement S; | 
|  | 48 | position p1; | 
|  | 49 | position p != {r_default.p, r_case.p}; | 
|  | 50 | identifier label; | 
|  | 51 | @@ | 
|  | 52 | ( | 
|  | 53 | label:; | 
|  | 54 | | | 
|  | 55 | S@p1;@p | 
|  | 56 | ) | 
|  | 57 |  | 
|  | 58 | @script:python@ | 
|  | 59 | p << r1.p; | 
|  | 60 | p1 << r1.p1; | 
|  | 61 | @@ | 
|  | 62 | if p[0].line != p1[0].line_end: | 
|  | 63 | cocci.include_match(False) | 
|  | 64 |  | 
|  | 65 | @depends on patch@ | 
|  | 66 | position r1.p; | 
|  | 67 | @@ | 
|  | 68 | -;@p | 
|  | 69 |  | 
|  | 70 | @script:python depends on report@ | 
|  | 71 | p << r1.p; | 
|  | 72 | @@ | 
|  | 73 | coccilib.report.print_report(p[0],"Unneeded semicolon") | 
|  | 74 |  | 
|  | 75 | @depends on context@ | 
|  | 76 | position r1.p; | 
|  | 77 | @@ | 
|  | 78 | *;@p | 
|  | 79 |  | 
|  | 80 | @script:python depends on org@ | 
|  | 81 | p << r1.p; | 
|  | 82 | @@ | 
|  | 83 | cocci.print_main("Unneeded semicolon",p) |