On Tue, 5 Jul 2011, Ajay Panyala wrote: > Hello, > > I have a simple rule to add a variable declaration > whenever I see a function call with a certain name > as shown below. > > @initialize:python@ > count = 0 > > @@ > identifier bCall ~= "^\(foo\|bar\|abc\)$" > > @@ > + int x = 42; > bCall(...); > > @script:python@ > @@ > count = count + 1 > > > @@ > identifier cCall ~="^\(foo1\|bar1\|abc1\)$" > > @@ > + int y = 42; > cCall(...); > > @script:python@ > @@ > count = count + 1 > > Is it possible to add the variable declarations (x,y) in such a way > that they are initialized to *count *rather than 42 ?
You can do this in Coccinelle, by declaring a variable in the python code that is inherited as an identifier but actually contains a number represented as a string. Look at demos/pythontococci.cocci to see how to declare variables in python code. Currently, your python rule that increments count is being called once per file. I don't know if that is what you want. If you want it to be once per the occurrence of something, put a position variable on that thing and interit the position variable in the python rule. You don't have to use it in the python rule for anyhting. julia _______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
