Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1430051 > unrolled thread
| Started by | "Andrew F. Davis" <afd@ti.com> |
|---|---|
| First post | 2016-06-23 21:00 +0200 |
| Last post | 2016-06-27 00:10 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] Coccinelle: Add misc/boolconv.cocci "Andrew F. Davis" <afd@ti.com> - 2016-06-23 21:00 +0200
Re: [PATCH] Coccinelle: Add misc/boolconv.cocci Joe Perches <joe@perches.com> - 2016-06-23 21:20 +0200
Re: [PATCH] Coccinelle: Add misc/boolconv.cocci "Andrew F. Davis" <afd@ti.com> - 2016-06-23 21:30 +0200
Re: [PATCH] Coccinelle: Add misc/boolconv.cocci Julia Lawall <julia.lawall@lip6.fr> - 2016-06-27 00:10 +0200
| From | "Andrew F. Davis" <afd@ti.com> |
|---|---|
| Date | 2016-06-23 21:00 +0200 |
| Subject | [PATCH] Coccinelle: Add misc/boolconv.cocci |
| Message-ID | <rNi13-5I7-7@gated-at.bofh.it> |
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 +//---------------------------------------------------------- + +@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.9.0
[toc] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2016-06-23 21:20 +0200 |
| Message-ID | <rNikp-64A-1@gated-at.bofh.it> |
| In reply to | #1430051 |
On Thu, 2016-06-23 at 13:53 -0500, Andrew F. Davis wrote: > Add a script to check for unneeded conversions to bool. this could also be extended for bool functions that: return !!expression; and return expression != 0;
[toc] | [prev] | [next] | [standalone]
| From | "Andrew F. Davis" <afd@ti.com> |
|---|---|
| Date | 2016-06-23 21:30 +0200 |
| Message-ID | <rNiu5-68M-3@gated-at.bofh.it> |
| In reply to | #1430067 |
On 06/23/2016 02:12 PM, Joe Perches wrote: > On Thu, 2016-06-23 at 13:53 -0500, Andrew F. Davis wrote: >> Add a script to check for unneeded conversions to bool. > > this could also be extended for bool functions that: > > return !!expression; > and > return expression != 0; > Agreed, it's in the works, I was going to post this current set with some patches to the kernel that is detects, then add additional checks and their kernel fixes incrementally. For the second suggestion I think we could have additions to boolinit.cocci that include the results of comparison/logical operations. Thanks, Andrew
[toc] | [prev] | [next] | [standalone]
| From | Julia Lawall <julia.lawall@lip6.fr> |
|---|---|
| Date | 2016-06-27 00:10 +0200 |
| Message-ID | <rOqpA-5R-41@gated-at.bofh.it> |
| In reply to | #1430051 |
On Thu, 23 Jun 2016, Andrew F. Davis wrote: > Add a script to check for unneeded conversions to bool. > > Signed-off-by: Andrew F. Davis <afd@ti.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> > --- > 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 > +//---------------------------------------------------------- > + > +@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.9.0 > >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web