It is a problem of parser ambiguity.  You need to tell Coccinelle that it
should be parsed as an expression:

@expression@
identifier I1, I2;
expression E;
@@
- I1->x[I2++] = E
+ I1->x[I2] = E, I2++

In principle, it could use the fact that the - code is an expression to
deduce that the + code should be an expression as well, but it does not do
that.

julia

On Mon, 18 Jun 2012, Dmitry Antipov wrote:

> In the following and similar code fragment(s):
>
> struct s {
>   int x[10];
> };
>
> void f (struct s *sp, int i, int j, int k)
> {
>   sp->x[i++] = j;
>   sp->x[i++] = k;
> }
>
> I would like to replace 'sp->x[i++] = j' to 'sp->x[i] = j, i++' and so.
> My spatch is:
>
> @@
> identifier I1, I2;
> expression E;
> @@
> - I1->x[I2++] = E
> + I1->x[I2] = E, I2++
>
> It doesn't work with the message:
>
> Fatal error: exception Failure("plus: parse error:
>  = File "test.cocci", line 6, column 15,  charpos = 72
>     around = ',', whole content = + I1->x[I2] = E, I2++
> ")
>
> Why it is so? Spatch complains about syntax error at ',',
> but IIUC C comma operator is syntactically correct here.
> Spatch is 1.0.0-rc12.
>
> Dmitry
> _______________________________________________
> Cocci mailing list
> [email protected]
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
>
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to