On Tue, 10 May 2011, Isaac Huang wrote: > Thank you Julia. I tried: > @r@ > expression E; > identifier func ~= "^\(spin_lock\|spin_unlock\|baaalah\)$"; > @@ > func(E); > > @script:python s@ > func << r.func; > prefix_func; > @@ > > prefix_func = "prefix_%s" % func > print prefix_func > > @@ > expression E; > identifier r.func, s.prefix_func; > @@ > -func(E); > +prefix_func(E); > > > The "print prefix_func" showed correct names like prefix_spin_lock, > but the generated patch had wrong names like: > - spin_lock(&ueq->ueq_lock); > + initial value(&ueq->ueq_lock);
Oops, sorry about that. When you want to send a variable from python to smpl, you have to refer to the variable in the python code as coccinelle.varname. There is an example in demos/pythontococci.cocci: @script:python b@ x << a.x; y; z; @@ print y coccinelle.y = x coccinelle.z = "something" print y The equivalent ocaml script code is: @script:ocaml b@ x << a.x; y; z; @@ y := x; z := "something" That is, in ocaml you can just assign the variables directly. julia > I'm using "spatch version 1.0.0-rc1 with Python support". I'm likely > doing something stupid here but couldn't figure it out. Any ideas? > > Thanks, > Isaac > > On Thu, May 05, 2011 at 06:22:25PM +0200, Julia Lawall wrote: > > ...... > > 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)
