Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Question on dealing with parameters and arguments
@ 2015-05-11  9:25 ZhouYuan
  2015-05-11  9:38 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: ZhouYuan @ 2015-05-11  9:25 UTC (permalink / raw)
  To: cocci

Hi, 
Here I met some problems about dealing with the parameter and argument in SmPL. 
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.
I would be very appreciated if anyone could provide some suggestions on the questions above. 
Thank you so much for your time!
Best regards,Yuan 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150511/b31d76cb/attachment.html>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Cocci] Question on dealing with parameters and arguments
  2015-05-11  9:25 [Cocci] Question on dealing with parameters and arguments ZhouYuan
@ 2015-05-11  9:38 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2015-05-11  9:38 UTC (permalink / raw)
  To: cocci

> 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 at 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-11  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-11  9:25 [Cocci] Question on dealing with parameters and arguments ZhouYuan
2015-05-11  9:38 ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox