Coccinelle archive on lore.kernel.org
 help / 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 --]

<div dir="ltr">





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Hello. </p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">I am a student of Kochi University of Technology in Japan.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">I have asked a question before.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Thank you for all your help on that occasion.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">This time I have two questions about how to use Coccinelle.</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">This is the first question.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Identifiers can be declared in scripts.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Can you declare the type in same way?</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">For example<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">,</span> there are the following programs.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">———————————————————</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@script:python pre@</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">alloc<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@@</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">coccinelle.alloc = <span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">“</span>malloc<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">”</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@ rule1 @</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">type T={int<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">,</span> double}<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">identifier v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">,</span> pre.alloc<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@@</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">T v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">…</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">alloc<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">(</span>...<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">)</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@ rule2 @</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">type T={int<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">,</span> double}<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">identifier v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">,</span> pre.alloc<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@@</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">T v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">… when != alloc<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">(</span>…<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">———————————————————</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">In these two rules there is T of type with the same restriction.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Can you declare this like alloc?</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Do you have to declare in each rule?</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Next is the second question.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">In the previous answer you said</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)"><span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">“</span>Coccinelle rather focuses on the case where variables are all defined at the top of a function<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">”</span>.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">Do you mean that we can not distinguish between the same name variables?</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">For example<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">,</span> there are the following programs.</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">———————————————————</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">—c-program—</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">void foo<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">()</span> {</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)"><span class="gmail-Apple-converted-space">  </span>int a<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)"><span class="gmail-Apple-converted-space">  </span>{</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)"><span class="gmail-Apple-converted-space">    </span>int a<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)"><span class="gmail-Apple-converted-space">    </span>hoge<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">(</span>a<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">);</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)"><span class="gmail-Apple-converted-space">  </span>}</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">}</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69);min-height:14px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">—cocci—</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@rule@</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">identifier v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">type T<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">@@</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">T v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">;</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">…</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">hoge<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">(</span>v<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">);</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">———————————————————</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:&quot;Helvetica Neue&quot;;color:rgb(69,69,69)">matched first a and second a<span class="gmail-s1" style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:&quot;.Hiragino Kaku Gothic Interface&quot;">.</span></p></div>

[-- 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, back to index

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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox