fen.cocci 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /// These iterators only exit normally when the loop cursor is NULL, so there
  2. /// is no point to call of_node_put on the final value.
  3. ///
  4. // Confidence: High
  5. // Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
  6. // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
  7. // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
  8. // URL: http://coccinelle.lip6.fr/
  9. // Comments:
  10. // Options: --no-includes --include-headers
  11. virtual patch
  12. virtual context
  13. virtual org
  14. virtual report
  15. @depends on patch@
  16. iterator name for_each_node_by_name;
  17. expression np,E;
  18. identifier l;
  19. @@
  20. for_each_node_by_name(np,...) {
  21. ... when != break;
  22. when != goto l;
  23. }
  24. ... when != np = E
  25. - of_node_put(np);
  26. @depends on patch@
  27. iterator name for_each_node_by_type;
  28. expression np,E;
  29. identifier l;
  30. @@
  31. for_each_node_by_type(np,...) {
  32. ... when != break;
  33. when != goto l;
  34. }
  35. ... when != np = E
  36. - of_node_put(np);
  37. @depends on patch@
  38. iterator name for_each_compatible_node;
  39. expression np,E;
  40. identifier l;
  41. @@
  42. for_each_compatible_node(np,...) {
  43. ... when != break;
  44. when != goto l;
  45. }
  46. ... when != np = E
  47. - of_node_put(np);
  48. @depends on patch@
  49. iterator name for_each_matching_node;
  50. expression np,E;
  51. identifier l;
  52. @@
  53. for_each_matching_node(np,...) {
  54. ... when != break;
  55. when != goto l;
  56. }
  57. ... when != np = E
  58. - of_node_put(np);
  59. // ----------------------------------------------------------------------
  60. @r depends on !patch forall@
  61. //iterator name for_each_node_by_name;
  62. //iterator name for_each_node_by_type;
  63. //iterator name for_each_compatible_node;
  64. //iterator name for_each_matching_node;
  65. expression np,E;
  66. identifier l;
  67. position p1,p2;
  68. @@
  69. (
  70. *for_each_node_by_name@p1(np,...)
  71. {
  72. ... when != break;
  73. when != goto l;
  74. }
  75. |
  76. *for_each_node_by_type@p1(np,...)
  77. {
  78. ... when != break;
  79. when != goto l;
  80. }
  81. |
  82. *for_each_compatible_node@p1(np,...)
  83. {
  84. ... when != break;
  85. when != goto l;
  86. }
  87. |
  88. *for_each_matching_node@p1(np,...)
  89. {
  90. ... when != break;
  91. when != goto l;
  92. }
  93. )
  94. ... when != np = E
  95. * of_node_put@p2(np);
  96. @script:python depends on org@
  97. p1 << r.p1;
  98. p2 << r.p2;
  99. @@
  100. cocci.print_main("unneeded of_node_put",p2)
  101. cocci.print_secs("iterator",p1)
  102. @script:python depends on report@
  103. p1 << r.p1;
  104. p2 << r.p2;
  105. @@
  106. msg = "ERROR: of_node_put not needed after iterator on line %s" % (p1[0].line)
  107. coccilib.report.print_report(p2[0], msg)