Re: [Cocci] [PATCHv2] coccinelle: Add a script to find unnecessary ifs with no body

2013-11-08 Thread Michal Marek
On 2.11.2013 17:49, Julia Lawall wrote:
 +@r depends on report || context@
 +expression E;
 +position p;
 +@@
 +if@p (E) {}
 
 There should be a * in front of the if, to support context mode.

Josh, will you send a v3 with the above fix?

Thanks,
Michal

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCHv2] coccinelle: Add a script to find unnecessary ifs with no body

2013-11-02 Thread Josh Triplett
This script finds code like this, with an unnecessary if:

if (foo) {}

Provides report mode only, since patching often eliminates conditionals
that contain TODO comments or similar.

Signed-off-by: Josh Triplett j...@joshtriplett.org
---

v2: Drop patch mode.

 scripts/coccinelle/misc/unnecessary-if.cocci | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 scripts/coccinelle/misc/unnecessary-if.cocci

diff --git a/scripts/coccinelle/misc/unnecessary-if.cocci 
b/scripts/coccinelle/misc/unnecessary-if.cocci
new file mode 100644
index 000..28ac895
--- /dev/null
+++ b/scripts/coccinelle/misc/unnecessary-if.cocci
@@ -0,0 +1,23 @@
+/// Find unnecessary ifs with no statements.
+//
+// Report mode only, since patch mode often deletes ifs that contain TODO
+// comments.
+//
+// Confidence: High
+// Options: --no-includes --include-headers
+
+virtual report
+virtual context
+
+@r depends on report || context@
+expression E;
+position p;
+@@
+if@p (E) {}
+
+@script:python depends on report@
+p  r.p;
+@@
+
+msg = WARNING: Unnecessary if with no body.
+coccilib.report.print_report(p[0], msg)
-- 
1.8.4.2

___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci