Coccinelle: Add misc/boolconv.cocci
PATCH v2 1/1 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
scripts/coccinelle/misc/boolconv.cocci new file +90 -0
@@ -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 +//---------------------------------------------------------- + + 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)
Signature · 1 line
2.10.1
Quoted 1 line · Andrew F. Davis
Add a script to check for unneeded conversions to bool.
What changed since the previous version?
julia
Quoted 108 lines
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.cocciscripts/coccinelle/misc/boolconv.cocci new file +90
-1@@ -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 +//---------------------------------------------------------- + + 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 +//---------------------------------------------------------- + + at 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 +//---------------------------------------------------------- + + at 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
Quoted 6 lines · Julia Lawall
Quoted 1 line · Andrew F. Davis
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
Quoted 111 lines
julia
Quoted 108 lines
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.cocciscripts/coccinelle/misc/boolconv.cocci new file +90
-1@@ -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 +//---------------------------------------------------------- + + 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 +//---------------------------------------------------------- + + at 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 +//---------------------------------------------------------- + + at 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
Quoted 4 lines · Andrew F. Davis
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