semicolon.cocci 1.0 KB

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