diff options
| author | Andrew F. Davis <afd@ti.com> | 2016-10-17 12:52:24 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.com> | 2016-12-11 06:07:00 -0500 |
| commit | 75238b9e6aadca6d9255d4b385e026385e78bb15 (patch) | |
| tree | b70aba337eaa03d0c0258280c8e5ce37637cb06a /scripts | |
| parent | 1001354ca34179f3db924eb66672442a173147dc (diff) | |
Coccinelle: Add misc/boolconv.cocci
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>
Signed-off-by: Michal Marek <mmarek@suse.com>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/coccinelle/misc/boolconv.cocci | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/scripts/coccinelle/misc/boolconv.cocci b/scripts/coccinelle/misc/boolconv.cocci new file mode 100644 index 000000000000..33c464d6bc71 --- /dev/null +++ b/scripts/coccinelle/misc/boolconv.cocci | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /// Remove unneeded conversion to bool | ||
| 2 | /// | ||
| 3 | //# Relational and logical operators evaluate to bool, | ||
| 4 | //# explicit conversion is overly verbose and unneeded. | ||
| 5 | // | ||
| 6 | // Copyright: (C) 2016 Andrew F. Davis <afd@ti.com> GPLv2. | ||
| 7 | |||
| 8 | virtual patch | ||
| 9 | virtual context | ||
| 10 | virtual org | ||
| 11 | virtual report | ||
| 12 | |||
| 13 | //---------------------------------------------------------- | ||
| 14 | // For patch mode | ||
| 15 | //---------------------------------------------------------- | ||
| 16 | |||
| 17 | @depends on patch@ | ||
| 18 | expression A, B; | ||
| 19 | symbol true, false; | ||
| 20 | @@ | ||
| 21 | |||
| 22 | ( | ||
| 23 | A == B | ||
| 24 | | | ||
| 25 | A != B | ||
| 26 | | | ||
| 27 | A > B | ||
| 28 | | | ||
| 29 | A < B | ||
| 30 | | | ||
| 31 | A >= B | ||
| 32 | | | ||
| 33 | A <= B | ||
| 34 | | | ||
| 35 | A && B | ||
| 36 | | | ||
| 37 | A || B | ||
| 38 | ) | ||
| 39 | - ? true : false | ||
| 40 | |||
| 41 | //---------------------------------------------------------- | ||
| 42 | // For context mode | ||
| 43 | //---------------------------------------------------------- | ||
| 44 | |||
| 45 | @r depends on !patch@ | ||
| 46 | expression A, B; | ||
| 47 | symbol true, false; | ||
| 48 | position p; | ||
| 49 | @@ | ||
| 50 | |||
| 51 | ( | ||
| 52 | A == B | ||
| 53 | | | ||
| 54 | A != B | ||
| 55 | | | ||
| 56 | A > B | ||
| 57 | | | ||
| 58 | A < B | ||
| 59 | | | ||
| 60 | A >= B | ||
| 61 | | | ||
| 62 | A <= B | ||
| 63 | | | ||
| 64 | A && B | ||
| 65 | | | ||
| 66 | A || B | ||
| 67 | ) | ||
| 68 | * ? true : false@p | ||
| 69 | |||
| 70 | //---------------------------------------------------------- | ||
| 71 | // For org mode | ||
| 72 | //---------------------------------------------------------- | ||
| 73 | |||
| 74 | @script:python depends on r&&org@ | ||
| 75 | p << r.p; | ||
| 76 | @@ | ||
| 77 | |||
| 78 | msg = "WARNING: conversion to bool not needed here" | ||
| 79 | coccilib.org.print_todo(p[0], msg) | ||
| 80 | |||
| 81 | //---------------------------------------------------------- | ||
| 82 | // For report mode | ||
| 83 | //---------------------------------------------------------- | ||
| 84 | |||
| 85 | @script:python depends on r&&report@ | ||
| 86 | p << r.p; | ||
| 87 | @@ | ||
| 88 | |||
| 89 | msg = "WARNING: conversion to bool not needed here" | ||
| 90 | coccilib.report.print_report(p[0], msg) | ||
