coccinelle: misc: add excluded_middle.cocci script
PATCH 1/1 coccinelle: misc: add excluded_middle.cocci script
Check for "!A || A && B" condition. It's equivalent to "!A || B" condition.
--- scripts/coccinelle/misc/excluded_middle.cocci | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/coccinelle/misc/excluded_middle.cocci
scripts/coccinelle/misc/excluded_middle.cocci new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Condition "!A || A && B" is equalent to "!A || B". +/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@r depends on !patch@ +expression A, B; +position p; +@@ + +* !A || (A && B)@p + +@depends on patch@ +expression A, B; +@@ + + !A || +- (A && + B +- ) + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING condition !A || A && B is equivalent to !A || B") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING condition !A || A && B is equivalent to !A || B")
Signature · 6 lines
2.26.2 _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 16 lines · Denis Efremov
Check for "!A || A && B" condition. It's equivalent to "!A || B" condition.
Signed-off-by Denis Efremov <[email protected]>--- scripts/coccinelle/misc/excluded_middle.cocci | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/coccinelle/misc/excluded_middle.cocciscripts/coccinelle/misc/excluded_middle.cocci new file +0
-0
scripts/coccinelle/misc/excluded_middle.cocci line 3
Quoted 3 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +3
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Condition "!A || A && B" is equalent to "!A || B".
s/equalent/equivalent/
Quoted 44 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +37
-1+/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@r depends on !patch@ +expression A, B; +position p; +@@ + +* !A || (A && B)@p + +@depends on patch@ +expression A, B; +@@ + + !A || +- (A && + B +- ) + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING condition !A || A && B is equivalent to !A || B") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING condition !A || A && B is equivalent to !A || B") --2.26.2
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Signature · 5 lines
Jim _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
Julia Lawall
maintainerQuoted 15 lines · Denis Efremov
Check for "!A || A && B" condition. It's equivalent to "!A || B" condition.
Signed-off-by Denis Efremov <[email protected]>--- scripts/coccinelle/misc/excluded_middle.cocci | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/coccinelle/misc/excluded_middle.cocciscripts/coccinelle/misc/excluded_middle.cocci new file +0
-0
scripts/coccinelle/misc/excluded_middle.cocci line 3
Quoted 3 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +3
-0@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Condition "!A || A && B" is equalent to "!A || B".
As was noted, there is a spelling mistake here.
Quoted 6 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +6
-0+/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers + +virtual patch
scripts/coccinelle/misc/excluded_middle.cocci line 19
Quoted 10 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +10
-0+virtual context +virtual org +virtual report + +@r depends on !patch@ +expression A, B; +position p; +@@ + +* !A || (A && B)@p
In org mode, the token with the position variable gets highlighted in color. It would be more meaningful to put the position variable on the && operator.
scripts/coccinelle/misc/excluded_middle.cocci line 28
Quoted 9 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +9
-0+ +@depends on patch@ +expression A, B; +@@ + + !A || +- (A && + B +- )
I found it better to say
- (A && B)
+ B
There are some cases where B should be moved one space to the left and by removing B and adding it back again that will happen. I didn't see any case where the result was less good.
scripts/coccinelle/misc/excluded_middle.cocci line 40
Quoted 11 lines
scripts/coccinelle/misc/excluded_middle.cocci new file +11
-0+@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING condition !A || A && B is equivalent to !A || B") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING condition !A || A && B is equivalent to !A || B")
I'm not sure that you need the word condition, but up to you.
julia
PATCH v2 1/1 coccinelle: misc: add excluded_middle.cocci script
In reply to Denis EfremovCheck for !A || A && B condition. It's equivalent to !A || B.
---
Changes in v2:
- spelling mistake fixed
- position variable moved on the && operator
- patch pattern changed to - (A && B)
- word "condition" removed from warning message
scripts/coccinelle/misc/excluded_middle.cocci | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 scripts/coccinelle/misc/excluded_middle.cocci
scripts/coccinelle/misc/excluded_middle.cocci new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Condition !A || A && B is equivalent to !A || B. +/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@r depends on !patch@ +expression A, B; +position p; +@@ + +* !A || (A &&@p B) + +@depends on patch@ +expression A, B; +@@ + + !A || +- (A && B) ++ B + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING !A || A && B is equivalent to !A || B") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING !A || A && B is equivalent to !A || B")
Signature · 1 line
2.26.2
Quoted 3 lines · Denis Efremov
Check for !A || A && B condition. It's equivalent to !A || B.
Signed-off-by Denis Efremov <[email protected]>
Applied, thanks.
Quoted 60 lines
---
Changes in v2:
- spelling mistake fixed
- position variable moved on the && operator
- patch pattern changed to - (A && B)
- word "condition" removed from warning messagescripts/coccinelle/misc/excluded_middle.cocci | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 scripts/coccinelle/misc/excluded_middle.cocciscripts/coccinelle/misc/excluded_middle.cocci new file +39
-1@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Condition !A || A && B is equivalent to !A || B. +/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@r depends on !patch@ +expression A, B; +position p; +@@ + +* !A || (A &&@p B) + +@depends on patch@ +expression A, B; +@@ + + !A || +- (A && B) ++ B + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING !A || A && B is equivalent to !A || B") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING !A || A && B is equivalent to !A || B") --2.26.2