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. This would have to be run with -all_includes, or better yet -recursive_includes, which will make it extremely slow. You can improve the performance a bit by caching abstract syntax trees: -cache_prefix /tmp/vdcache -cache_limit 200

@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;
@@

fn(es,
- (void *)
  E,...)

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to