Hi,
 
The simple cocci rule:
 
--------
@@
@@
-foo
+bar
--------
 
Will replace function calls of foo wityh function calls of bar - and as a bonus 
it will also update functionpointers to bar.
Unfortunately also other identifiers are matched.
 
Look at this example:
 
------------
void foo(int baz)
{
  printf("foo %d",baz);
}
 
void baz(int foo)
{
  int bar = 5;
  switch (foo) {
  case 1 :
    break ;
  case 2:
    foo(2);
    printf("two");
    break ;
  default:
    printf("baz %d", bar);
    break;
  }
}
 
typedef void (Func)(int);
Func *funclist [] = { foo, baz };
 
void buh(int bah)
{
  (funclist[0])(bah);
  (funclist[1])(bah);
}
------------
 
This will generate this patch:
----------
--- switch.c    2010-01-06 14:13:39.742564000 +0100
+++ /tmp/cocci-output-19759-1fb20a-switch.c     2010-01-06 14:15:52.000000000 
+0100
@@ -6,11 +6,11 @@ void foo(int baz)
 void baz(int foo)
 {
   int bar = 5;
-  switch (foo) {
+  switch (bar) {
   case 1 :
     break ;
   case 2:
-    foo(2);
+    bar(2);
     printf("two");
     break ;
   default:
@@ -20,7 +20,7 @@ void baz(int foo)
 }
 
 typedef void (Func)(int);
-Func *funclist [] = { foo, baz };
+Func *funclist [] = { bar, baz };
 
 void buh(int bah)
 {
----------
 
switch(foo) is changed to switch(bar). Not good. can I avoid this and still get 
function pointers updated?
 
regards,
Andreas Bach Aaen_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to