When you introduce a wrapper function then you would like that the original function call isn't replaced inside the implementation of the wrapper function itself.

Example C-code:

#include <stdio.h>
int buh(void) {
  printf("wrapper");
  return baz();
}
int main(void) {
  printf("baz");
  
  baz();
  return 1;
}

The following simple semantic patch will also replace “return baz();” with “return buh();” in the wrapper function.

@@
@@

- baz
+ buh

A better solution is to write a rule that matches the wrapper, records the positions of baz in the wrapper function and then only modify references to the function variable that are not in those positions.

@r@
position p;
@@

buh(...) {
<... baz@p ...>
}

@@
position p!=r.p;
@@

- baz@p
+ buh
 
ce_use_wrapper.txt · Last modified: 2009/10/29 16:35 by npalix
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki