[Cocci] Matching function pointer typedef
jglisse at redhat.com
Wed May 16 17:13:46 CEST 2018
On Tue, May 15, 2018 at 05:26:59PM -0400, Jerome Glisse wrote:
> On Tue, May 15, 2018 at 10:53:36PM +0200, Julia Lawall wrote:
> > On Tue, 15 May 2018, Håkon Løvdal wrote:
> > > It's been a while since I used coccinelle, but I think to remember that you must
> > > (and in any case should) keep the non-changing parts outside of the
> > > +/- lines, e.g.
> > >
> > > @@
> > > @@
> > > typedef void (*toto_t)(int a, int b
> > > + , int c
> > > );
> > I think that typedefs of function pointers just don't work. It is looking
> > for typedef type name;. I can try to fix this.
> Above does not work either. The error is same roughly spatch complains
> that it matches whole content ... I have a workaround, namely abusing
> gcc which accept:
> typedef void toto_t(int a, int b);
> For function pointer typedef and then coccinelle on function declaration
> do work. Still it would be nice if coccinelle can understand function
> pointer typedef.
Ok my work around does work that well, it seems gcc allow this abuse
only for function parameter type, it can not be use as a type inside
a structure and so it doesn't cover all cases i am dealing with.
Is there a way to modify code using python inside coccinelle ? I have
seen example that print thing inside coccinelle but i haven't not seen
an example that use coccinelle to match something and then do changes
to the code using python.
I am guessing i can open the file and use the position information to
do that but was wondering if there is already helper provided for that.
More information about the Cocci