On Wed, 30 Jun 2010, Nicolas Palix wrote:
> On Wednesday 30 June 2010 14:49:04 Julia Lawall wrote:
> > On Wed, 30 Jun 2010, Lucas De Marchi wrote:
> >
> > > Hi, I'm a developer of EFL libraries and recently we changed our API
> > > in a way that I think could be automated by Coccinelle. So, I started
> > > looking on this software yesterday.
> > >
> > > What we did is changing the signature of some callback functions to
> > > return Eina_Bool instead of int. Eina_Bool is a typedef for unsigned
> > > char that is declared in a header included by Eina.h. I'm making some
> > > tests with the following snippet:
> > >
> > > --------------
> > > #include <Eina.h>
> > > #include <Ecore.h>
> > >
> > > static int test_func(void *data) {
> > > if (data == NULL) {
> > > ecore_main_loop_quit();
> > > return 0;
> > > }
> > >
> > > return 1;
> > > }
> > >
> > > int main(void) {
> > > ecore_init();
> > > ecore_timer_add(1, test_func, 1);
> > > ecore_main_loop_begin();
> > > ecore_shutdown();
> > > return 0;
> > > }
> > > ------------------------------
> > >
> > > Applying the following semantic patch:
> > >
> > > ------------------------------
> > > @r1@
> > > identifier fn;
> > > @@
> > > ecore_timer_add(..., fn, ...);
> > >
> > > @r2@
> > > identifier r1.fn;
> > > identifier data;
> > > @@
> > > - int
> > > + Eina_Bool
> > > fn(void *data) {
> > > ...
> > > (
> > > - return 0;
> > > + return EINA_FALSE;
> > > |
> > > - return 1;
> > > + return EINA_TRUE;
> > > )
> > > ...
> > > }
> > > ---------------------------------
> > >
> > > However it's not working because of that Eina_Bool. If I change
> > > Eina_Bool to char, it works as expected. I tried playing with the
> > > -all_includes and -I options but it doesn't work either. What am I
> > > doing wrong?
> >
> > -all_includes and -I are for the .c file, but your problem is for the
> > semantic patch. In a semantic patch, you can declare new type names using
> > typedef, among the metavariables. So you should put:
> >
> > @r2@
> > identifier r1.fn;
> > identifier data;
> > typedef Eina_bool;
> > @@
> >
> > The declaration is taken into account for the entire rest of the semantic
> > patch, not just the current rule.
> >
>
> I think you will also have to use <+... ...+> in r2 instead of ...
> to match any returns.
No, a return is always at the end of the control flow path. Thereis
furthermore no need to have ... after a return.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)