From: Julia Lawall <julia.lawall@lip6.fr>
To: 藤本太希 <fjtkut@gmail.com>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] how to use Coccinelle
Date: Fri, 14 Dec 2018 09:08:00 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1812140902120.3571@hadrien> (raw)
In-Reply-To: <CADa4oMViD=7G5=54L9n2fK=2AdPQs14bBRMNRXxJjUWiZV6iLg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2178 bytes --]
On Fri, 14 Dec 2018, 藤本太希 wrote:
>
> Hello.
>
> I am a student of Kochi University of Technology in Japan.
>
> I have asked a question before.
>
> Thank you for all your help on that occasion.
>
> This time I have two questions about how to use Coccinelle.
>
>
>
> This is the first question.
>
> Identifiers can be declared in scripts.
>
> Can you declare the type in same way?
>
> For example, there are the following programs.
>
> ———————————————————
>
> @script:python pre@
>
> alloc;
>
> @@
>
> coccinelle.alloc = “malloc”
>
>
> @ rule1 @
>
> type T={int, double};
>
> identifier v, pre.alloc;
>
> @@
>
> T v;
>
> …
>
> alloc(...)
>
>
> @ rule2 @
>
> type T={int, double};
>
> identifier v, pre.alloc;
>
> @@
>
> T v;
>
> … when != alloc(…)
>
> ———————————————————
>
> In these two rules there is T of type with the same restriction.
>
> Can you declare this like alloc?
>
> Do you have to declare in each rule?
I think that you can say
type T = {r1.type1, r1.type2};
In your python rule, though, you should say eg
coccinelle.type1 = make_type("int")
It is necessary to make the list of possible types in each rule. If you
said type rule1.T; in rule2, that would only be the specific binding of T
chosen in rule1.
>
>
>
> Next is the second question.
>
> In the previous answer you said
>
> “Coccinelle rather focuses on the case where variables are all defined at the top of a function”.
>
> Do you mean that we can not distinguish between the same name variables?
>
> For example, there are the following programs.
>
> ———————————————————
>
> —c-program—
>
> void foo() {
>
> int a;
>
> {
>
> int a;
>
> hoge(a);
>
> }
>
> }
>
>
> —cocci—
>
> @rule@
>
> identifier v;
>
> type T;
>
> @@
>
> T v;
>
> …
>
> hoge(v);
>
> ———————————————————
>
> matched first a and second a.
An identifier is just a name. It has no notion of scope. If you want to
be sure that the second one is not matched, then you should put
T v;
... when != T1 v;
hoge(v);
julia
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
prev parent reply other threads:[~2018-12-14 8:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-14 7:34 [Cocci] how to use Coccinelle 藤本太希
2018-12-14 8:08 ` 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.20.1812140902120.3571@hadrien \
--to=julia.lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=fjtkut@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).