From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Question on dealing with parameters and arguments
Date: Mon, 11 May 2015 11:38:33 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.10.1505111129290.2393@hadrien> (raw)
In-Reply-To: <BAY181-W56C207434972A5F64436C7B8DB0@phx.gbl>
> 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
prev parent reply other threads:[~2015-05-11 9:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-11 9:25 [Cocci] Question on dealing with parameters and arguments ZhouYuan
2015-05-11 9:38 ` Julia Lawall [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.10.1505111129290.2393@hadrien \
--to=julia.lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox