Eric Leblond | 12 Jul 2012 11:50
Gravatar

Avoiding conditional code

Hello,

I'm currently running spatch (via coccigrep) on a code and I've got
matches in some conditional code:

#ifdef UNITTESTS
...
#endif

I would like to be able to not do matches on this part of the code. Is
their an easy way to do so ?

BR,
--

-- 
Eric Leblond 
Blog: http://home.regit.org/ - Portfolio: http://regit.500px.com/
Hello,

I'm currently running spatch (via coccigrep) on a code and I've got
matches in some conditional code:

#ifdef UNITTESTS
...
#endif

I would like to be able to not do matches on this part of the code. Is
their an easy way to do so ?

(Continue reading)

Julia Lawall | 12 Jul 2012 14:30
Picon
Favicon

Re: Avoiding conditional code

On Thu, 12 Jul 2012, Eric Leblond wrote:

> Hello,
>
> I'm currently running spatch (via coccigrep) on a code and I've got
> matches in some conditional code:
>
> #ifdef UNITTESTS
> ...
> #endif
>
> I would like to be able to not do matches on this part of the code. Is
> their an easy way to do so ?

No.  The matching process doesn't see the ifdefs.  There is a notion of
skipping code that is under #if 0.  It could indeed be nice to generalize
that to other constants.  Ideally, we would do partial evaluations as
well, ie if we know that X is undefined, then perhaps X && Y is also
undefined.  I can look into it.

julia
Eric Leblond | 13 Jul 2012 11:23
Gravatar

Re: Avoiding conditional code

Hello,

Le jeudi 12 juillet 2012 à 14:30 +0200, Julia Lawall a écrit :
> On Thu, 12 Jul 2012, Eric Leblond wrote:
> 
> > Hello,
> >
> > I'm currently running spatch (via coccigrep) on a code and I've got
> > matches in some conditional code:
> >
> > #ifdef UNITTESTS
> > ...
> > #endif
> >
> > I would like to be able to not do matches on this part of the code. Is
> > their an easy way to do so ?
> 
> No.  The matching process doesn't see the ifdefs.  There is a notion of
> skipping code that is under #if 0.  It could indeed be nice to generalize
> that to other constants.  Ideally, we would do partial evaluations as
> well, ie if we know that X is undefined, then perhaps X && Y is also
> undefined.  I can look into it.

That could be great. I'm sure it could help in a lot of situation for
example changing API for a single OS on a complex project.

BR,
--

-- 
Eric Leblond 
Blog: http://home.regit.org/ - Portfolio: http://regit.500px.com/
(Continue reading)

Julia Lawall | 13 Jul 2012 16:01
Picon
Favicon

Re: Avoiding conditional code

> > > #ifdef UNITTESTS
> > > ...
> > > #endif
> > >
> > > I would like to be able to not do matches on this part of the code. Is
> > > their an easy way to do so ?
> >
> > No.  The matching process doesn't see the ifdefs.  There is a notion of
> > skipping code that is under #if 0.  It could indeed be nice to generalize
> > that to other constants.  Ideally, we would do partial evaluations as
> > well, ie if we know that X is undefined, then perhaps X && Y is also
> > undefined.  I can look into it.
>
> That could be great. I'm sure it could help in a lot of situation for
> example changing API for a single OS on a complex project.

Attached is a patch that works for #ifdef and #ifndef.  In your case, you
would give spatch the argument --undefined UNITTESTS.  It should then
ignode the code under #ifdef UNITTESTS.  You can also specify several
names, eg --defined FOO,BAR,XXX.  The names should be separated by commas,
but not spaces.

Interpretation of #if is not supported.  Actually, the arguments to #if
are not parsed, so it would be quite a bit more work.  But it is probably
not impossible to handle as well.

julia
Attachment (newp.patch): text/x-diff, 2781 bytes
> > > #ifdef UNITTESTS
(Continue reading)

Eric Leblond | 13 Jul 2012 16:34
Gravatar

Re: Avoiding conditional code

Hello,

Le vendredi 13 juillet 2012 à 16:01 +0200, Julia Lawall a écrit :
> > > > #ifdef UNITTESTS
> > > > ...
> > > > #endif
> > > >
> > > > I would like to be able to not do matches on this part of the code. Is
> > > > their an easy way to do so ?
> > >
> > > No.  The matching process doesn't see the ifdefs.  There is a notion of
> > > skipping code that is under #if 0.  It could indeed be nice to generalize
> > > that to other constants.  Ideally, we would do partial evaluations as
> > > well, ie if we know that X is undefined, then perhaps X && Y is also
> > > undefined.  I can look into it.
> >
> > That could be great. I'm sure it could help in a lot of situation for
> > example changing API for a single OS on a complex project.
> 
> Attached is a patch that works for #ifdef and #ifndef.  In your case, you
> would give spatch the argument --undefined UNITTESTS.  It should then
> ignode the code under #ifdef UNITTESTS.  You can also specify several
> names, eg --defined FOO,BAR,XXX.  The names should be separated by commas,
> but not spaces.

That's just awesome. It works perfectly! Thanks a lot!

Do you plan to add it to the git tree ?

BR,
(Continue reading)

Julia Lawall | 13 Jul 2012 16:36
Picon
Favicon

Re: Avoiding conditional code

On Fri, 13 Jul 2012, Eric Leblond wrote:

> Hello,
>
> Le vendredi 13 juillet 2012 à 16:01 +0200, Julia Lawall a écrit :
> > > > > #ifdef UNITTESTS
> > > > > ...
> > > > > #endif
> > > > >
> > > > > I would like to be able to not do matches on this part of the code. Is
> > > > > their an easy way to do so ?
> > > >
> > > > No.  The matching process doesn't see the ifdefs.  There is a notion of
> > > > skipping code that is under #if 0.  It could indeed be nice to generalize
> > > > that to other constants.  Ideally, we would do partial evaluations as
> > > > well, ie if we know that X is undefined, then perhaps X && Y is also
> > > > undefined.  I can look into it.
> > >
> > > That could be great. I'm sure it could help in a lot of situation for
> > > example changing API for a single OS on a complex project.
> >
> > Attached is a patch that works for #ifdef and #ifndef.  In your case, you
> > would give spatch the argument --undefined UNITTESTS.  It should then
> > ignode the code under #ifdef UNITTESTS.  You can also specify several
> > names, eg --defined FOO,BAR,XXX.  The names should be separated by commas,
> > but not spaces.
>
> That's just awesome. It works perfectly! Thanks a lot!
>
> Do you plan to add it to the git tree ?
(Continue reading)

Eric Leblond | 13 Jul 2012 16:47
Gravatar

Re: Avoiding conditional code

Hello,

Le vendredi 13 juillet 2012 à 16:36 +0200, Julia Lawall a écrit :
> On Fri, 13 Jul 2012, Eric Leblond wrote:
> 
> > Hello,
> >
> > Le vendredi 13 juillet 2012 à 16:01 +0200, Julia Lawall a écrit :
> > > > > > #ifdef UNITTESTS
> > > > > > ...
> > > > > > #endif
> > > > > >
> > > > > > I would like to be able to not do matches on this part of the code. Is
> > > > > > their an easy way to do so ?
> > > > >
> > > > > No.  The matching process doesn't see the ifdefs.  There is a notion of
> > > > > skipping code that is under #if 0.  It could indeed be nice to generalize
> > > > > that to other constants.  Ideally, we would do partial evaluations as
> > > > > well, ie if we know that X is undefined, then perhaps X && Y is also
> > > > > undefined.  I can look into it.
> > > >
> > > > That could be great. I'm sure it could help in a lot of situation for
> > > > example changing API for a single OS on a complex project.
> > >
> > > Attached is a patch that works for #ifdef and #ifndef.  In your case, you
> > > would give spatch the argument --undefined UNITTESTS.  It should then
> > > ignode the code under #ifdef UNITTESTS.  You can also specify several
> > > names, eg --defined FOO,BAR,XXX.  The names should be separated by commas,
> > > but not spaces.
> >
(Continue reading)


Gmane