cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] how to use Coccinelle
@ 2018-12-14  7:34 藤本太希
  2018-12-14  8:08 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: 藤本太希 @ 2018-12-14  7:34 UTC (permalink / raw)
  To: cocci


[-- Attachment #1.1: Type: text/plain, Size: 1581 bytes --]

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?



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.

[-- Attachment #1.2: Type: text/html, Size: 21373 bytes --]

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] how to use Coccinelle
  2018-12-14  7:34 [Cocci] how to use Coccinelle 藤本太希
@ 2018-12-14  8:08 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2018-12-14  8:08 UTC (permalink / raw)
  To: 藤本太希; +Cc: cocci

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

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

end of thread, other threads:[~2018-12-14  8:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14  7:34 [Cocci] how to use Coccinelle 藤本太希
2018-12-14  8:08 ` Julia Lawall

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).