lkml.org 
[lkml]   [2011]   [Jun]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3] coccinelle: if (ret) return ret; return ret; semantic patch
On Tue, 14 Jun 2011, Greg Dietsche wrote:

> Semantic patch to find code that matches this pattern:
> if (...) return ret;
> return ret;
>
> Version 2:
> Incorporate review comments from Julia Lawall
> Add matches for a number of other similar patterns.
>
> Version 3:
> Incorporating more review comments from Julia.
>
> Signed-off-by: Greg Dietsche <Gregory.Dietsche@cuw.edu>
> ---
> scripts/coccinelle/misc/doublereturn.cocci | 31 ++++++++++++++++++++++++++++
> 1 files changed, 31 insertions(+), 0 deletions(-)
> create mode 100644 scripts/coccinelle/misc/doublereturn.cocci
>
> diff --git a/scripts/coccinelle/misc/doublereturn.cocci b/scripts/coccinelle/misc/doublereturn.cocci
> new file mode 100644
> index 0000000..2de8564
> --- /dev/null
> +++ b/scripts/coccinelle/misc/doublereturn.cocci
> @@ -0,0 +1,31 @@
> +// Removing unecessary code that matches this core pattern:
> +// -if(...) return ret;
> +// return ret;
> +//
> +// Confidence: High
> +// Copyright: (C) 2011 Greg Dietsche GPLv2.
> +// URL: http://www.gregd.org
> +// Comments:
> +// Options: -no_includes
> +
> +virtual patch
> +
> +@depends on patch@
> +expression ret;
> +identifier x, y;
> +identifier f;
> +identifier is_ordinal_table ~= "IS_ORDINAL_TABLE_\(ONE\|TWO\)";
> +@@
> +(
> +//via an isomorphism this also covers x and unlikely(x)
> +-if (likely(x)) return ret;
> +|
> +-if (\(IS_ERR\|IS_ZERO\)(x)) return ret;
> +|
> +-if (is_ordinal_table(x,y)) return ret;
> +|
> +if(<+...f(...)...+>) return ret;
> +|
> +-if (...) return ret;
> +)
> +return ret;

It doesn't matter in this case, but in general the use of regular
expressions should be a last resort. The problem is that when coccinelle
is searching for relevant files, it doesn't interpret regular expressions,
and so it would just take all files. But in this case it doesn't matter,
because including eg if (...) return ret; will cause it to consider all
files anyway.

julia


\
 
 \ /
  Last update: 2011-06-15 07:53    [W:0.857 / U:0.208 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site