All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] [PATCH] Coccinelle: Add misc/boolconv.cocci
@ 2016-06-23 18:53 ` Andrew F. Davis
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew F. Davis @ 2016-06-23 18:53 UTC (permalink / raw)
  To: cocci

Add a script to check for unneeded conversions to bool.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 scripts/coccinelle/misc/boolconv.cocci | 90 ++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 scripts/coccinelle/misc/boolconv.cocci

diff --git a/scripts/coccinelle/misc/boolconv.cocci b/scripts/coccinelle/misc/boolconv.cocci
new file mode 100644
index 0000000..33c464d
--- /dev/null
+++ b/scripts/coccinelle/misc/boolconv.cocci
@@ -0,0 +1,90 @@
+/// Remove unneeded conversion to bool
+///
+//# Relational and logical operators evaluate to bool,
+//# explicit conversion is overly verbose and unneeded.
+//
+// Copyright: (C) 2016 Andrew F. Davis <afd@ti.com> GPLv2.
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+//----------------------------------------------------------
+//  For patch mode
+//----------------------------------------------------------
+
+ at depends on patch@
+expression A, B;
+symbol true, false;
+@@
+
+(
+  A == B
+|
+  A != B
+|
+  A > B
+|
+  A < B
+|
+  A >= B
+|
+  A <= B
+|
+  A && B
+|
+  A || B
+)
+- ? true : false
+
+//----------------------------------------------------------
+//  For context mode
+//----------------------------------------------------------
+
+@r depends on !patch@
+expression A, B;
+symbol true, false;
+position p;
+@@
+
+(
+  A == B
+|
+  A != B
+|
+  A > B
+|
+  A < B
+|
+  A >= B
+|
+  A <= B
+|
+  A && B
+|
+  A || B
+)
+* ? true : false at p
+
+//----------------------------------------------------------
+//  For org mode
+//----------------------------------------------------------
+
+ at script:python depends on r&&org@
+p << r.p;
+@@
+
+msg = "WARNING: conversion to bool not needed here"
+coccilib.org.print_todo(p[0], msg)
+
+//----------------------------------------------------------
+//  For report mode
+//----------------------------------------------------------
+
+@script:python depends on r&&report@
+p << r.p;
+@@
+
+msg = "WARNING: conversion to bool not needed here"
+coccilib.report.print_report(p[0], msg)
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-06-26 22:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-23 18:53 [Cocci] [PATCH] Coccinelle: Add misc/boolconv.cocci Andrew F. Davis
2016-06-23 18:53 ` Andrew F. Davis
2016-06-23 19:12 ` [Cocci] " Joe Perches
2016-06-23 19:12   ` Joe Perches
2016-06-23 19:22   ` [Cocci] " Andrew F. Davis
2016-06-23 19:22     ` Andrew F. Davis
2016-06-26 22:01 ` [Cocci] " Julia Lawall
2016-06-26 22:01   ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.