cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] convert if (x) stmt to if (x) {stmt}
Date: Wed, 16 May 2018 21:41:11 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1805162139340.3296@hadrien> (raw)
In-Reply-To: <alpine.DEB.2.20.1805162137550.3296@hadrien>



On Wed, 16 May 2018, Julia Lawall wrote:

>
>
> 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 at p (...) { ... } else S
>
> @disable braces1,braces2,braces3,braces4,neg_if @
> position p != r.p;
> statement S,S1;
> @@
>
> if at p (...)
> + {
>   S1
> + }
>   else S
>
> @s disable braces1,braces2,braces3,braces4,neg_if @
> position p;
> statement S;
> @@
>
> if at p (...) S else { ... }
>
> @disable braces1,braces2,braces3,braces4,neg_if @
> position p != s.p;
> statement S,S1;
> @@
>
> if at p (...) S else
> + {
>   S1
> + }
>
> I would suggest to proceed carefully...

In each rule that contains S1, you first could replace the S1 by e; where
e is an expression metavariable.  That would get a lot of simple cases out
of the way.  Then you could commit that, and then run the original rule,
thus being able to focus on the more complex results.

julia

  reply	other threads:[~2018-05-16 19:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16 16:21 [Cocci] convert if (x) stmt to if (x) {stmt} ron minnich
2018-05-16 19:15 ` Julia Lawall
2018-05-16 19:39   ` Julia Lawall
2018-05-16 19:41     ` Julia Lawall [this message]
     [not found]       ` <f9593244-a490-295b-537d-5dcc5e1017d5@users.sourceforge.net>
2018-05-17  7:21         ` Julia Lawall
     [not found]           ` <b44ad180-3d38-ba5e-80ab-bc932263dba7@users.sourceforge.net>
     [not found]             ` <alpine.DEB.2.20.1805172248210.2273@hadrien>
     [not found]               ` <0c08d40c-4047-db00-9b4a-4d6a7799afe0@users.sourceforge.net>
     [not found]                 ` <alpine.DEB.2.20.1805181759490.3339@hadrien>
     [not found]                   ` <2240107d-5e70-6489-f48a-5f6675c55c64@users.sourceforge.net>
     [not found]                     ` <alpine.DEB.2.20.1805181842590.3339@hadrien>
     [not found]                       ` <cea31c3d-fde8-e866-a03c-de868148ed12@users.sourceforge.net>
2018-05-18 17:12                         ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1805162139340.3296@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).