> For example, I want to judge whether the parameters and arguments of a
> function have the same type or the same number of elements. But it seems
> hard to obtain them as exactly what they are in C. 
>
> Also, I have noticed that there are two type in meta-variables called
> "parameter list" and "expression list". But I did not find the definition of
> them.

Maybe you want something like the following:

@def@
identifier f,i;
parameter list[n] ps;
type T;
@@

f(ps,T i,...) { ... }

@bad@
identifier def.f;
expression list[def.n] es;
type def.T;
T e;
expression e1;
position p;
@@

f(es,\(e\|e1@p\),...)

@script:python@
p << bad.p;
f << def.f;
n << def.n;
@@

print "argument %s of %s on line %s has wrong type" % (n,f,p[0].line)

-----------------------------------------------

For checking the number of arguments, you could do:

@def@
parameter list[n] ps;
@@

f(ps) { ... }

@bad@
expression list[def.n] es;
expression list[m] es2;
@@

(
f(es)
|
f@p(es2)
)

// add appropriate python code here

-----------------------------------------------

Note that this wil only find problems where the definition and the use of
the function are in the same file.  To consider different files, you need
to use iteration, which is more complicated.  There is an example in
demos/iteration.cocci.  Iteration is also discussed in the talk here

http://coccinelle.lip6.fr/papers/cocciwk4_talk2.pdf

starting on slide 14.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to