[Cocci] Various minor parsing bugs

Iago Abal iago at itu.dk
Fri Jun 26 14:50:12 CEST 2015

Hi Daniel,

On Thu, Jun 25, 2015 at 5:10 AM, Daniel Richard G. <skunk at iskunk.org> wrote:

> Just about, yes. There are idioms like
>     int
>     #ifdef WIN32
>     WINAPI WinMain([...])
>     #else
>     main(int argc, char *argv[])
>     #endif
>     {
> and others where the conditional/surrounding parts can't stand on their
> own. The wisdom of writing code in this way may be questionable, but I
> would be happy for Coccinelle to evaluate the conditional itself, and
> process only one side. (In my case, the WIN32 side is irrelevant.)

Try passing --undefined WIN32 to spatch, this should work for you.
Analogously, you can use --defined <SYMBOL>. This evaluates the condition
of an #ifdef or #ifndef, and may convert them into #if 1 or #if 0. For #if
0, Coccinelle has an option --if0-passing (enabled by default) that will
ignore code under #if 0. The only constraint is that the code under the #if
0 must still be lexically valid C code, because --if0-passing works after

Using your example and passing --undefined WIN32 I get this from Coccinelle:

PARSING: foo.c
(ONCE) CPP-commenting a #if 0 or #if LINUX_VERSION or __cplusplus
passed:#ifdef WIN32
passed:WINAPI WinMain ( [ ... ] )

-- iago
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150626/707dca5b/attachment.html>

More information about the Cocci mailing list