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
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to