On Tue, 10 Jul 2012, Lars-Peter Clausen wrote:
> On 07/10/2012 09:26 AM, Julia Lawall wrote:
> > On Tue, 10 Jul 2012, Lars-Peter Clausen wrote:
> >
> >> On 07/10/2012 02:22 AM, Joe Perches wrote:
> >>> I want to elide void * casts in uses of functions with
> >>> pointers only when the function prototypes are declared
> >>> with the appropriate void * arguments.
> >>>
> >>> Any idea/suggestion how to do this?
> >>>
> >>> I tried variants of this but had no success:
> >>>
> >>> @ func_1 @
> >>> type rtn_type;
> >>> identifier arg;
> >>> @@
> >>>
> >>> static int func(void *arg)
> >>> {
> >>> ...
> >>> }
> >>>
> >>> @@
> >>> identifier func1.func;
> >>> expression e;
> >>> @@
> >>>
> >>> - fn((void *)e)
> >>> + fn(e)
> >>>
> >>
> >> It works fine if you get rid of all the typos ;)
> >>
> >> This one is a bit more generic since it allows the void parameter to be at
> >> any position in the argument list:
> >>
> >> @r1@
> >> identifier arg;
> >> identifier fn;
> >> parameter list[n] P;
> >> @@
> >> fn(P, void *arg, ...)
> >> {
> >> ...
> >> }
> >>
> >> @depends on r1@
> >> expression e;
> >> identifier r1.fn;
> >> expression list[r1.n] El;
> >> @@
> >> - fn(El, (void *)e
> >> + fn(El, e
> >> , ...)
> >
> > A further improvement is the following. It checks that the casted argument
> > already has pointer type and takes into account the case where there is only
> > a signature for the function, but no definition.
>
> Yea, looks much nicer :)
>
> >
> > @r@
> > parameter list[n] ps;
> > identifier fn,arg;
> > @@
> >
> > fn(ps,void *arg,...) { ... }
> >
> > @@
> > identifier r.fn;
> > expression *E;
> > expression list[r.n] es;
> > @@
> >
> > fn(es,
> > - (void *)
> > E,...)
> >
> > @rr@
> > parameter list[n] ps;
> > identifier fn,arg;
> > type T;
> > @@
> >
> > T fn(ps,void *arg,...);
> >
> > @@
> > identifier rr.fn;
> > expression *E;
> > expression list[r.n] es;
>
> rr.n instead of r.n, I guess
Oops!
> Btw. if a rule uses identifiers from another rule is this like an implicit
> depends on?
Sort of. If the inherited metavariable is used, it has to have a value,
so there is an implicit depends on. But if there is a disjunction the
variable might not be used in one branch and that branch can match. On
the other hand for script rules, eg python, there is an implicit depends
on. We don't look at the actual python code, we just require all
variables to be bound in advance.
julia
> > @@
> >
> > fn(es,
> > - (void *)
> > E,...)
> >
> > julia
>
>
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)