On 11/25/2019 1:10 PM, Julia Lawall wrote: > On Mon, 25 Nov 2019, David Frey wrote: > >> Hi, >> >> I'm trying to write a .cocci file to transform all calls to a function >> "f(ex)" to something like this: >> >> #ifdef USE_F >> f(ex) >> #else >> g(ex) >> #endif >> >> The function has this signature: >> bool f(int x); >> >> This is the patch that I tried to use: >> @@ >> expression ex; >> @@ >> +#ifdef USE_F >> f(ex) >> +#else >> +g(ex) >> +#endif >> >> >> This is the result of running it: >> $ spatch --show-c --sp-file test.cocci test.c >> init_defs_builtins: /usr/bin/../lib/coccinelle/standard.h >> plus: parse error: >> File "test.cocci", line 7, column 1, charpos = 50 >> around = 'g', >> whole content = +g(ex) >> >> What is wrong with the patch above? > > Coccinelle doesn't currently support adding ifdefs on expressions, only on > statements. > > You could try for some typical usage contexts, like > > +ifdef... > x = f(ex); > +#else > +x = g(ex); > +#endif > > julia >
Hi Julia, Thanks for your explanation and your suggestion. I ended up creating a new header that was like this: #ifdef SOMETHING #define foo_backport_x(_arg) bar_x(_arg) #define foo_backport_y(_arg) bar_y(_arg) #else #define foo_backport_x(_arg) foo_x(_arg) #define foo_backport_y(_arg) foo_y(_arg) #endif and then I defined coccinelle rules to change: foo_x -> foo_backport_x foo_y -> foo_backport_y It's not the most elegant solution, but it works. David _______________________________________________ Cocci mailing list [email protected] https://systeme.lip6.fr/mailman/listinfo/cocci
