On Fri, 21 Jan 2011, Philipp Kutin wrote:

> Hi,
> 
> I'm trying to do my first steps with Coccinelle but can't get the following to
> work: basically, for debugging, I want to implement a poor man's array bound
> check by doing something like
> 
> @@
> expression E;
> @@
> 
> - sprite[E]
> + sprite[{( int tmp=E; (tmp<0 ? (*(int*)123=234) : tmp) )}]
> 
> .
> Since GCC's statement-exprs are probably unsupported, a second try is
> 
> + sprite[tmp_global=(E), (tmp_global<0 ? (*(int*)123=234) : tmp_global)]
> 
> .
> However, this also gives a parse error although it's valid C code. Is the
> comma operator unsupported or am I missing something?
> Since there be always cases where the user "knows better", is there a way to
> match syntactically, but replace in a textual fashion? So that in the above
> example, the "-" line would truly do a parse but the "+" line would only
> substitute the meta-variables but leave everything else as literal text.

No, the comma operator isn't supported.  I could add that.

The approach that we have taken is to try to ensure that the before and 
after versions are valid code.  I can see the advantage of doing the 
opposite in your case, but I suspect that it would lead to more mistakes 
than cases where it would be helpful.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to