All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] coccinelle: boolconv: improve script to handle more cases
@ 2017-09-23 13:55 Aishwarya Pant
  2017-09-23 14:44 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Aishwarya Pant @ 2017-09-23 13:55 UTC (permalink / raw)
  To: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek; +Cc: outreachy-kernel

Given expressions A, B and a binary operator op, the current script checks for
cases where
	A op B ? true : false can be replaced by A op B

This can be extended to handle the other case where
	A op B ? false : true can be replaced by !(A op B)

Moreover we can use the binary operator type to catch all desirable comparisons
in one go instead of writing them down.

Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
---

Okay I'm not sure if A op B ? false : true conversion to !(A op B) is even
desirable because it might hinder code readability in certain cases.
Just putting it out here because while I was running coccicheck in staging
drivers a few cases like the above turned up.
---
 scripts/coccinelle/misc/boolconv.cocci | 43 ++++++++--------------------------
 1 file changed, 10 insertions(+), 33 deletions(-)

diff --git a/scripts/coccinelle/misc/boolconv.cocci b/scripts/coccinelle/misc/boolconv.cocci
index 33c464d..9b32b5f 100644
--- a/scripts/coccinelle/misc/boolconv.cocci
+++ b/scripts/coccinelle/misc/boolconv.cocci
@@ -16,27 +16,19 @@ virtual report
 
 @depends on patch@
 expression A, B;
+binary operator op = {==,!=,>,<,>=,<=,&&,||};
 symbol true, false;
 @@
 
 (
-  A == B
-|
-  A != B
-|
-  A > B
-|
-  A < B
-|
-  A >= B
-|
-  A <= B
-|
-  A && B
+  A op B
+- ? true : false
 |
-  A || B
++ !(
+  A op B
++ )
+- ? false : true
 )
-- ? true : false
 
 //----------------------------------------------------------
 //  For context mode
@@ -44,28 +36,13 @@ symbol true, false;
 
 @r depends on !patch@
 expression A, B;
+binary operator op = {==,!=,>,<,>=,<=,&&,||};
 symbol true, false;
 position p;
 @@
 
-(
-  A == B
-|
-  A != B
-|
-  A > B
-|
-  A < B
-|
-  A >= B
-|
-  A <= B
-|
-  A && B
-|
-  A || B
-)
-* ? true : false@p
+  A op B
+* ? \(true\|false\) : \(false@p\|true@p\)
 
 //----------------------------------------------------------
 //  For org mode
-- 
2.7.4



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

* Re: [PATCH] coccinelle: boolconv: improve script to handle more cases
  2017-09-23 13:55 [PATCH] coccinelle: boolconv: improve script to handle more cases Aishwarya Pant
@ 2017-09-23 14:44 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2017-09-23 14:44 UTC (permalink / raw)
  To: Aishwarya Pant
  Cc: Gilles Muller, Nicolas Palix, Michal Marek, outreachy-kernel



On Sat, 23 Sep 2017, Aishwarya Pant wrote:

> Given expressions A, B and a binary operator op, the current script checks for
> cases where
> 	A op B ? true : false can be replaced by A op B
>
> This can be extended to handle the other case where
> 	A op B ? false : true can be replaced by !(A op B)
>
> Moreover we can use the binary operator type to catch all desirable comparisons
> in one go instead of writing them down.
>
> Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
> ---
>
> Okay I'm not sure if A op B ? false : true conversion to !(A op B) is even
> desirable because it might hinder code readability in certain cases.
> Just putting it out here because while I was running coccicheck in staging
> drivers a few cases like the above turned up.

Maybe the user can decide what they want to do in this case.

Acked-by: Julia Lawall <julia.lawall@lip6.fr>

> ---
>  scripts/coccinelle/misc/boolconv.cocci | 43 ++++++++--------------------------
>  1 file changed, 10 insertions(+), 33 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/boolconv.cocci b/scripts/coccinelle/misc/boolconv.cocci
> index 33c464d..9b32b5f 100644
> --- a/scripts/coccinelle/misc/boolconv.cocci
> +++ b/scripts/coccinelle/misc/boolconv.cocci
> @@ -16,27 +16,19 @@ virtual report
>
>  @depends on patch@
>  expression A, B;
> +binary operator op = {==,!=,>,<,>=,<=,&&,||};
>  symbol true, false;
>  @@
>
>  (
> -  A == B
> -|
> -  A != B
> -|
> -  A > B
> -|
> -  A < B
> -|
> -  A >= B
> -|
> -  A <= B
> -|
> -  A && B
> +  A op B
> +- ? true : false
>  |
> -  A || B
> ++ !(
> +  A op B
> ++ )
> +- ? false : true
>  )
> -- ? true : false
>
>  //----------------------------------------------------------
>  //  For context mode
> @@ -44,28 +36,13 @@ symbol true, false;
>
>  @r depends on !patch@
>  expression A, B;
> +binary operator op = {==,!=,>,<,>=,<=,&&,||};
>  symbol true, false;
>  position p;
>  @@
>
> -(
> -  A == B
> -|
> -  A != B
> -|
> -  A > B
> -|
> -  A < B
> -|
> -  A >= B
> -|
> -  A <= B
> -|
> -  A && B
> -|
> -  A || B
> -)
> -* ? true : false@p
> +  A op B
> +* ? \(true\|false\) : \(false@p\|true@p\)
>
>  //----------------------------------------------------------
>  //  For org mode
> --
> 2.7.4
>
>


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

end of thread, other threads:[~2017-09-23 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-23 13:55 [PATCH] coccinelle: boolconv: improve script to handle more cases Aishwarya Pant
2017-09-23 14:44 ` 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.