Hi,
I'm trying to figure out how to use a counter (updated from a python
script) in a transformation rule. Suppose I want to rewrite
bar();
bar();
bar();
into
bar(0);
bar(1);
bar(2);
I've concocted the following recipe but it doesn't work.
@script:python defcounter@
counter;
@@
counter = 0
coccinelle.counter = 0
@matchbar@
position barp;
identifier defcounter.counter;
@@
- bar@barp();
+ bar(counter);
@script:python@
dummy << matchbar.barp;
@@
counter = counter + 1
coccinelle.counter = counter
print coccinelle.counter
I guess I need more magic to update the right counter. Any suggestions?
$ spatch -sp_file bar.spatch bar.c
init_defs_builtins: /usr/libexec/coccinelle/standard.h
HANDLING: bar.c
1
2
3
diff =
--- bar.c 2011-03-29 22:55:17.000000000 +0400
+++ /tmp/cocci-output-23161-d1e618-bar.c 2011-03-29 22:55:30.000000000
+0400
@@ -1,6 +1,6 @@
int main()
{
- bar();
- bar();
- bar();
+ bar(0);
+ bar(0);
+ bar(0);
}
Thanks.
Alexander
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)