Re: Coccinelle

Samuel Abraham <[email protected]> Mon, 31 Mar 2025 07:52:33 +0100
Newsgroups dev.linux.lists.outreachy
Message-ID <CADYq+fZJd03PNRbrAaVyzWjXN9GZw9mZFV_M6F9AkKyrRY5gVQ@mail.gmail.com>
On Sun, Mar 30, 2025 at 3:56 PM Julia Lawall <[email protected]> wrote:
>
> Hello,
>
> The actual internship project will involve using Coccinelle.  Some warm up
> examplesin using Coccinelle are available at the following URL:
>
> https://who.paris.inria.fr/Julia.Lawall/outreachy25/

Hello Julia,
I have been studying the SmPL examples and some documentation.
But I have some questions as regards the flow of execution of the SmPL.

Firstly, I found out you are the writer and maintainer of Coccinelle, and I just
want to say a job well done.

Looking at the first example of the SmPL,

@initialize:ocaml@   => This defines an ocaml function
@@

let same_function p q =
  (List.hd p).Coccilib.current_element = (List.hd
q).Coccilib.current_element. => This checks if both p and q belong to
the same function

@r@.   => Defines a named rule 'r'
expression e;  => matches an expression
position p;       => Does this store the match's position like the
line number in the file?
symbol true,false;
@@

e =@p \(true\|false\)
This line above is where I am majorly confused.
Please clarify: Are we setting the value of the expression to true or
false and storing the position of the match?

@@
expression r.e;          => Here, we are referencing the expression in
rule 'r' to replace the expression we have matched?
position q : script:ocaml(r.p) { same_function p q };  => we are
setting position q if it the same as position p from the same_function
@@

e =@q
(
- 1
+ true
|
- 0
+ false
)

Then this line above replaces the 1 with true or 0 with false in the
expression that had been set previously above.
But my question is, are we setting the value of e =@p \(true\|false\)
or it just a place holder that will be replaced by any expression
we match
Then we can now check the matched expression if it is 0 and replace
with true and if is 1 we replace with false?

@s@
type T;
T e;
identifier fld;
symbol true,false;
@@

e.fld = \(true\|false\) ==> Same question applies here too

@@
type s.T;
T e;
identifier s.fld;
@@

e.fld =
(
- 1
+ true
|
- 0
+ false
)

Thanks

Adekunle.