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