From mboxrd@z Thu Jan 1 00:00:00 1970 From: julia.lawall@lip6.fr (Julia Lawall) Date: Mon, 10 Oct 2016 21:45:54 +0200 (CEST) Subject: [Cocci] Replacing one (specific!) type with another In-Reply-To: <87shs4oxeh.fsf@vostro.rath.org> References: <87r37vzd8j.fsf@vostro.rath.org> <87shsa7p71.fsf@thinkpad.rath.org> <8760p3jwr3.fsf@vostro.rath.org> <87ponay35u.fsf@vostro.rath.org> <87wphhz1x5.fsf@vostro.rath.org> <877f9gqjsn.fsf@vostro.rath.org> <87shs4oxeh.fsf@vostro.rath.org> Message-ID: To: cocci@systeme.lip6.fr List-Id: cocci@systeme.lip6.fr On Mon, 10 Oct 2016, Nikolaus Rath wrote: > On Oct 10 2016, Nikolaus Rath wrote: > > On Oct 10 2016, Julia Lawall wrote: > >> On Sun, 9 Oct 2016, Nikolaus Rath wrote: > >> > >>> On Oct 08 2016, Julia Lawall wrote: > >>> >> > Write separate rules for that. You would need one case for a local > >>> >> > variable and one case fora parameter. You can actually probably just drop > >>> >> > the rule you have currently. I would imagine something like the > >>> >> > following: > >>> >> > > >>> >> > @@ > >>> >> > symbol f, se; // avoid unneeded warnings from Coccinelle > >>> >> > @@ > >>> >> > > >>> >> > struct fuse_session * > >>> >> > -f > >>> >> > +se > >>> >> > ; > >>> >> > <... > >>> >> > -f > >>> >> > +se > >>> >> > ...> > >>> >> > @@ > >>> >> > identifier fn; > >>> >> > @@ > >>> >> > > >>> >> > fn(...,struct fuse_session *f,...) { <... > >> > >> Oops, the first line should be: > >> > >> fn(...,struct fuse_session * > >> -f > >> +se > >> ,...) { <... > >> > >> The rule works fine even when f is the first argument. > > > > Ouch, I guess I could have caught that too. Works like a charm now! > > I claimed success too early. There are still the following cases left: > > > static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) > { > struct fuse_session *f = req->se; > [....] > > I tried to adapt the rules myself as follows: > > @@ > symbol f, se; > @@ > struct fuse_session * > -f > +se > ; > <... > -f > +se > ...> > > @@ > symbol f, se; > expression expr; > @@ > struct fuse_session * > -f > +se > = expr; > <... > -f > +se > ...> > > > @@ > identifier fn; > @@ > fn(...,struct fuse_session * > -f > +se > ,...) { <... > -f > +se > ...> } > > > But this gives an error: > > > Fatal error: exception Failure("meta: parse error: > = File "se-rename.cocci", line 14, column 7, charpos = 79 > around = 'f', whole content = symbol f, se; > ") > > > What am I doing wrong? What version of Coccinelle are you using? Before 1.0.6, it was not possible to declare something to be a symbol more than once. In any case, once it is declared as a symbol, it is always a symbol. julia