reserved_names.cocci 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Check violations for rule 5.7
  2. // https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_02.c
  3. //
  4. // Confidence: Moderate
  5. // Copyright: (C) 2020 Intel Corporation
  6. //
  7. // SPDX-License-Identifier: Apache-2.0
  8. virtual report
  9. @initialize:python@
  10. @@
  11. @common_case@
  12. position p;
  13. identifier t, v;
  14. expression E;
  15. type T;
  16. @@
  17. (
  18. struct t *v@p;
  19. |
  20. struct t v@p;
  21. |
  22. union t v@p;
  23. |
  24. T v@p;
  25. |
  26. T *v@p;
  27. |
  28. struct t *v@p = E;
  29. |
  30. struct t v@p = E;
  31. |
  32. union t v@p = E;
  33. |
  34. T v@p = E;
  35. |
  36. T *v@p = E;
  37. )
  38. @ script:python @
  39. v << common_case.v;
  40. p << common_case.p;
  41. @@
  42. msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v)
  43. with open("scripts/coccinelle/symbols.txt", "r") as fp:
  44. symbols = fp.read().splitlines()
  45. if v in symbols:
  46. coccilib.report.print_report(p[0], msg)
  47. @function_match@
  48. type T;
  49. identifier f;
  50. position p;
  51. @@
  52. T f@p(...) {
  53. ...
  54. }
  55. @ script:python @
  56. v << function_match.f;
  57. @@
  58. msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v)
  59. with open("scripts/coccinelle/symbols.txt", "r") as fp:
  60. symbols = fp.read().splitlines()
  61. if v in symbols:
  62. coccilib.report.print_report(p[0], msg)
  63. @function_parameter@
  64. type T1, T2;
  65. identifier function, v;
  66. position p;
  67. parameter list[n] P1;
  68. parameter list[n1] P2;
  69. @@
  70. T1 function(P1, T2 *v@p, P2) {
  71. ...
  72. }
  73. @ script:python @
  74. v << function_parameter.v;
  75. p << function_parameter.p;
  76. @@
  77. msg = "WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - {}".format(v)
  78. with open("scripts/coccinelle/symbols.txt", "r") as fp:
  79. symbols = fp.read().splitlines()
  80. if v in symbols:
  81. coccilib.report.print_report(p[0], msg)