On Thu, 5 May 2011, Isaac Huang wrote:

> Hi list, what I want to do is simply:
> 
> @@
> expression E;
> @@
> -spin_lock(E);
> +prefix_spin_lock(E);
> 
> But I need to add a same prefix to more than 10 functions, so I'd
> prefer to do something like:
> 
> @@
> expression E;
> identifier func ~= "^\(foo\|bar\|blah\)$";
> @@
> -func(E);
> +prefix_$(func)(E);
> 
> So as not to duplicate the same patch for each such function, but I
> couldn't figure out how to do it. Any suggestions?

You could use python.  This is illustarted by the following, which changes 
the name of all one-argument functions.  I will add this to the demos 
directory.

@r@
expression E;
identifier func;
@@
func(E);

@script:python s@
func << r.func;
prefix_func;
@@

prefix_func = "one_argument_function_%s" % func

@@
expression E;
identifier r.func,s.prefix_func;
@@
-func(E);
+prefix_func(E);

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

Reply via email to