semicolon.cocci 1.1 KB

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