All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] convert if (x) stmt to if (x) {stmt}
@ 2018-05-16 16:21 ron minnich
  2018-05-16 19:15 ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: ron minnich @ 2018-05-16 16:21 UTC (permalink / raw)
  To: cocci

we've found another one of these
if (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.

ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20180516/8e8c83ca/attachment.html>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cocci] convert if (x) stmt to if (x) {stmt}
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-05-16 19:15 UTC (permalink / raw)
  To: cocci



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...

julia


>
> ron
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cocci] convert if (x) stmt to if (x) {stmt}
  2018-05-16 19:15 ` Julia Lawall
@ 2018-05-16 19:39   ` Julia Lawall
  2018-05-16 19:41     ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-05-16 19:39 UTC (permalink / raw)
  To: cocci



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...

julia

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cocci] convert if (x) stmt to if (x) {stmt}
  2018-05-16 19:39   ` Julia Lawall
@ 2018-05-16 19:41     ` Julia Lawall
       [not found]       ` <f9593244-a490-295b-537d-5dcc5e1017d5@users.sourceforge.net>
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-05-16 19:41 UTC (permalink / raw)
  To: cocci



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cocci] convert if (x) stmt to if (x) {stmt}
       [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>
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2018-05-17  7:21 UTC (permalink / raw)
  To: cocci



On Thu, 17 May 2018, SF Markus Elfring wrote:

> >> 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.
>
> Please reconsider this suggestion.
>
> * I guess that there can statements occur which are not expressions.
>
> * Should return values trigger any more software development concerns?

I don't think you understood the idea at all.  The rule will likely make
hundreds or throusands of changes.  There is little risk in the case of
e;.  Getting all of those cases out of the way first will reduce the size
of the result that has to be checked carefully.

julia



>
>
> > Then you could commit that, and then run the original rule,
> > thus being able to focus on the more complex results.
>
> The application of additional SmPL script variants can help.
> I am curious on how the fine-tuning of corresponding implementation details
> will evolve further.
>
> Regards,
> Markus
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cocci] convert if (x) stmt to if (x) {stmt}
       [not found]                       ` <cea31c3d-fde8-e866-a03c-de868148ed12@users.sourceforge.net>
@ 2018-05-18 17:12                         ` Julia Lawall
  0 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2018-05-18 17:12 UTC (permalink / raw)
  To: cocci



On Fri, 18 May 2018, SF Markus Elfring wrote:

> >> I understood one suggestion in the way for a SmPL specification
> >> like the following.
> >>
> >> if (...)
> >> +{
> >>  S;
> >> +e;
> >> +}
> >
> > The rule has no goal of adding some unknown e;.
>
> How does this feedback fit to your wording ?In each rule that contains S1,
> you first could replace the S1 by e; ???

I didn't mean to write a semantic patch to remove S1 and add e;.  I meant
to put e; instead of S1 in the rule, producing the rule below.

julia

>
>
> > if (...)
> > + {
> >   e;
> > + }
> >   else S
> >
> > I don't see why one should consider whether e; should have been written in
> > a different way in making this transformation.
>
> It seems that you present another variant for a SmPL script.
>
> I assume that there are further constraints to consider for the discussed
> change pattern.
>
> Regards,
> Markus
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-05-18 17:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
     [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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.