On Thu, 28 Oct 2010, Andi Kleen wrote:

> > > How to express that in smpl? 
> > 
> > ... when != S
> > {Some statement}
> > 
> > where S is a statement metavariable.  {Some statement} might also be 
> > another statement metavariable if you don't know what kind of statement to 
> > expect.  There is probably some more complicated way of dealing with 
> > functions that only have declarations and no following statement, but I 
> > guess that would be quite rare.
> 
> Thanks Julia. That worked, except that it skipped the empty line
> after the declarations too, so I ended up with
> 
> foo()
> {
>       int x;
>                <--- empty line
>       int y;   <--- my new statement
> 
> But I guess that can be manually removed or is there a way to tell this
> cocci too?

The following should work, but it does not.  It attaches to each 
declaration. I think it is optimising too much the S.  I will take a look 
later today.

@r@
declaration D;
statement S;
identifier f;
position p;
@@

f(...) {
 ... when any
 d...@p
 S
 ... when any
}

@@
declaration D;
position r.p;
@@

D
+ int a;

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

Reply via email to