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