On Wed, 16 May 2018, Julia Lawall wrote:

>
>
> On Wed, 16 May 2018, ron minnich wrote:
>
> > we've found another one of theseif (x)
> > y
> > z
> >
> > things in firmware that were intended to be
> > if (x) {
> > y
> > z
> > }
> >
> > we're kind of tired of this and want to blanket require {} for all ifs, even
> > one liners.
> >
> > We want to convert the entire code base such that all if (E) S becomes if
> > (E) {S} but of course we don't want to add extra {}. 
> >
> > I don't totally trust my rusty spatch-foo to get this right and was
> > wondering if there's already such a thing out there.
>
> No, I don't know of such a thing.  However
> linux/scripts/coccinelle/ifcol.cocci checks for an if header followed by
> two statements preceded by the same number of whitespace characters.
>
> J'ai fait un essaie pour ce que tu demande.  Pour l'instant, ca tourne...

Sorry, I don't know where the answer in French came from...

Anyway, here is the rule I made:

@r disable braces1,braces2,braces3,braces4,neg_if @
position p;
statement S;
@@

if@p (...) { ... } else S

@disable braces1,braces2,braces3,braces4,neg_if @
position p != r.p;
statement S,S1;
@@

if@p (...)
+ {
  S1
+ }
  else S

@s disable braces1,braces2,braces3,braces4,neg_if @
position p;
statement S;
@@

if@p (...) S else { ... }

@disable braces1,braces2,braces3,braces4,neg_if @
position p != s.p;
statement S,S1;
@@

if@p (...) S else
+ {
  S1
+ }

I would suggest to proceed carefully...

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to