2016-10-17 16:53:18

by Andrew Davis

[permalink] [raw]
Subject: [PATCH v2] Coccinelle: Add misc/boolconv.cocci

Add a script to check for unneeded conversions to bool.

Signed-off-by: Andrew F. Davis <[email protected]>
Acked-by: Julia Lawall <[email protected]>
---
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 <[email protected]> GPLv2.
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+//----------------------------------------------------------
+// For patch mode
+//----------------------------------------------------------
+
+@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@p
+
+//----------------------------------------------------------
+// For org mode
+//----------------------------------------------------------
+
+@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.10.1


2016-10-17 20:55:01

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH v2] Coccinelle: Add misc/boolconv.cocci

On Mon, 17 Oct 2016, Andrew F. Davis wrote:

> Add a script to check for unneeded conversions to bool.

What changed since the previous version?

julia


>
> Signed-off-by: Andrew F. Davis <[email protected]>
> Acked-by: Julia Lawall <[email protected]>
> ---
> 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 <[email protected]> GPLv2.
> +
> +virtual patch
> +virtual context
> +virtual org
> +virtual report
> +
> +//----------------------------------------------------------
> +// For patch mode
> +//----------------------------------------------------------
> +
> +@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@p
> +
> +//----------------------------------------------------------
> +// For org mode
> +//----------------------------------------------------------
> +
> +@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.10.1
>
>

2016-10-17 21:08:45

by Andrew Davis

[permalink] [raw]
Subject: Re: [PATCH v2] Coccinelle: Add misc/boolconv.cocci

On 10/17/2016 03:54 PM, Julia Lawall wrote:
> On Mon, 17 Oct 2016, Andrew F. Davis wrote:
>
>> Add a script to check for unneeded conversions to bool.
>
> What changed since the previous version?
>

Nothing, just a resend, forgot to label it as such.

Andrew

> julia
>
>
>>
>> Signed-off-by: Andrew F. Davis <[email protected]>
>> Acked-by: Julia Lawall <[email protected]>
>> ---
>> 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 <[email protected]> GPLv2.
>> +
>> +virtual patch
>> +virtual context
>> +virtual org
>> +virtual report
>> +
>> +//----------------------------------------------------------
>> +// For patch mode
>> +//----------------------------------------------------------
>> +
>> +@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@p
>> +
>> +//----------------------------------------------------------
>> +// For org mode
>> +//----------------------------------------------------------
>> +
>> +@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.10.1
>>
>>

2016-12-10 22:49:47

by Michal Marek

[permalink] [raw]
Subject: Re: [PATCH v2] Coccinelle: Add misc/boolconv.cocci

On Mon, Oct 17, 2016 at 11:52:24AM -0500, Andrew F. Davis wrote:
> Add a script to check for unneeded conversions to bool.
>
> Signed-off-by: Andrew F. Davis <[email protected]>
> Acked-by: Julia Lawall <[email protected]>

Applied to kbuild.git#misc, thanks.

Michal