Coccinelle
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/
These have been pre-tested to ensure that they highlight some interesting changes that you can make in the staging drivers.
Let me know if you have any questions.
julia
Quoted 6 lines · Julia Lawall
Hello,
The actual internship project will involve using Coccinelle. Some warm up
examplesin using Coccinelle are available at the following URL:
Quoted 9 lines
https://who.paris.inria.fr/Julia.Lawall/outreachy25/
These have been pre-tested to ensure that they highlight some interesting changes that you can make in the staging drivers.
Let me know if you have any questions.
julia
Thank you for the update I will give an update soon. Erick
Quoted 6 lines · Julia Lawall
Hello,
The actual internship project will involve using Coccinelle. Some warm up examplesin using Coccinelle are available at the following URL:
Quoted 9 lines
https://who.paris.inria.fr/Julia.Lawall/outreachy25/
These have been pre-tested to ensure that they highlight some interesting changes that you can make in the staging drivers.
Let me know if you have any questions.
julia
Hello Julia.
Thank you for always being so helpful and for your consistent guidance.
I have been able to test the SmPL scripts on some drivers, though without making the changes in place,
just showing the diff.
But I would like to ask, are there specific things we should do at this point with Coccinelle, or should we
send patches transformed with Coccinelle?
Adekunle.
Quoted 20 lines · Samuel Abraham
Quoted 6 lines · Julia Lawall
Hello,
The actual internship project will involve using Coccinelle. Some warm up examplesin using Coccinelle are available at the following URL:
Quoted 9 lines
https://who.paris.inria.fr/Julia.Lawall/outreachy25/
These have been pre-tested to ensure that they highlight some interesting changes that you can make in the staging drivers.
Let me know if you have any questions.
julia
Hello Julia.
Thank you for always being so helpful and for your consistent guidance.
Quoted 6 lines
I have been able to test the SmPL scripts on some drivers, though without making the changes in place,
just showing the diff.
But I would like to ask, are there specific things we should do at this point with Coccinelle, or should we
send patches transformed with Coccinelle?
The goal for the moment is to install and run the tool, and then look at the output and when appropriate send more patches.
julia
Quoted 7 lines · Julia Lawall
Hello,
The actual internship project will involve using Coccinelle. Some warm up examplesin using Coccinelle are available at the following URL:
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.
Quoted 7 lines · Samuel Abraham
Quoted 6 lines · Julia Lawall
Hello,
The actual internship project will involve using Coccinelle. Some warm up examplesin using Coccinelle are available at the following URL:
Quoted 8 lines
Quoted 1 line
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.
Thanks :)
Quoted 9 lines
Looking at the first example of the SmPL,
@initialize:ocaml@ => This defines an ocaml function
@@let
same_functionp 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
Actually, this defines any data that you want to be global to the semantic patch execution. It is also possible to define a finalize that is executed after all of the files have been handled.
You can also use python. Then it would be eg initialize:python.
Quoted 2 lines
@r@. => Defines a named rule 'r'
Yes. You dont' have to name all your rules. But if you want to refer to the metavariables defined in this rule from a later rule, then this rule needs a name.
Quoted 3 lines
expression e; => matches an expression
position p; => Does this store the match's position like the
line number in the file?
Yes. You can also get the function name and the starting and ending lines of the containing function.
Quoted 7 lines
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?
This rule doesn't say it is an ocaml or python script, so it's a pattern matching rule. This is matching an assignment where the right hand side is either true or false. The left hand side is any expression e. You can also write the true or false pattern as:
(
true
|
false
)
where the ( | ) are in column 0. Outside column 0, without \, they are interpreted as somethign to match in the code.
Quoted 4 lines
@@
expression r.e; => Here, we are referencing the expression in
rule 'r' to replace the expression we have matched?
e is going to be an expression, but now it has to look the same as the one matched in rule r. It doesn't have to be at the same position, though.
Quoted 2 lines
position q : script:ocaml(r.p) {
same_functionp q }; => we are setting position q if it the same as position p from thesame_function
r.p is the position that was noted in rule r. Here we want to note a position and see if that position is in the same function as r.p. The idea here is that we may have x = true and then we may have x = 1. But if the second x is declared in a different function than the first x, then it might be the case that the second one is really intended to be an integer. So we take x = true as evidence that x should be a boolean only when the two occurrences of x are in the same function.
This is of course a heuristic. You can try something different, for example getting rid of q entirely, and see what the result is.
Quoted 11 lines
@@
e =@q
(
- 1
+ true
|
- 0
+ false
)
Quoted 3 lines
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\)
No. Pattterns don't change anything. The only way to change the state is to write OCeml or python code (script:ocaml or script:python).
Quoted 4 lines
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?
The two matches of e are intrinsically at different places in the code, since in one case there is true and in the other case there is 1 (or false or 0).
Quoted 9 lines
@s@
type T;
T e;
identifier fld;
symbol true,false;
@@e.fld = \(true\|false\) ==> Same question applies here too
Same answer. No assignment is executed here. We find a random expression of some type, and this expression has some random structure field named fld. The whole thing is found somewhere to be assigned to true or to false in the source code.
I hope it's clearer now. You may want to try running it on some small example to see what it does.
julia
Quoted 20 lines
@@
type s.T;
T e;
identifier s.fld;
@@e.fld =
(
- 1
+ true
|
- 0
+ false
)Thanks
Adekunle.
Quoted 28 lines · Julia Lawall
Quoted 7 lines · Samuel Abraham
Quoted 6 lines · Julia Lawall
Hello,
The actual internship project will involve using Coccinelle. Some warm up examplesin using Coccinelle are available at the following URL:
Quoted 8 lines
Quoted 1 line
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.
Thanks :)
Quoted 5 lines
Looking at the first example of the SmPL,
@initialize:ocaml@ => This defines an ocaml function
@@
Quoted 8 lines
Quoted 4 lines
let
same_functionp q =
(List.hd p).Coccilib.current_element = (List.hd
q).Coccilib.current_element. => This checks if both p and q belong to the same functionActually, this defines any data that you want to be global to the semantic patch execution. It is also possible to define a finalize that is executed after all of the files have been handled.
Okay that is like @finalize:python@?
Quoted 2 lines
You can also use python. Then it would be eg initialize:python.
That's great.
Quoted 7 lines
Quoted 3 lines
@r@. => Defines a named rule 'r'
Yes. You dont' have to name all your rules. But if you want to refer to the metavariables defined in this rule from a later rule, then this rule needs a name.
This is understood
Quoted 7 lines
Quoted 4 lines
expression e; => matches an expression
position p; => Does this store the match's position like the
line number in the file?Yes. You can also get the function name and the starting and ending lines of the containing function.
Okay, I think that was done in the third SmPL example.
Quoted 4 lines
Quoted 4 lines
symbol true,false;
@@
Quoted 8 lines
Quoted 4 lines
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?This rule doesn't say it is an ocaml or python script, so it's a pattern matching rule. This is matching an assignment where the right hand side is either true or false. The left hand side is any expression e. You can
Oh I get now. So we are not assigning \(true\|false\) to e rather, we are defining what to match
on both the left and right hand side of an assignment.
Quoted 12 lines
also write the true or false pattern as:
(
true
|
false
)where the ( | ) are in column 0. Outside column 0, without \, they are interpreted as somethign to match in the code.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
@@
expression r.e; => Here, we are referencing the expression in
rule 'r' to replace the expression we have matched?e is going to be an expression, but now it has to look the same as the one matched in rule r. It doesn't have to be at the same position, though.
Oh, Noted, so we specify that the expression e looks the same as the one in rule r.
We are not modifying the one matched earlier
Quoted 4 lines
Quoted 3 lines
position q : script:ocaml(r.p) {
same_functionp q }; => we are setting position q if it the same as position p from thesame_function
Quoted 8 lines
r.p is the position that was noted in rule r. Here we want to note a position and see if that position is in the same function as r.p. The idea here is that we may have x = true and then we may have x = 1. But if the second x is declared in a different function than the first x, then it might be the case that the second one is really intended to be an integer. So we take x = true as evidence that x should be a boolean only when the two occurrences of x are in the same function.
Okay this is understood too
Quoted 2 lines
This is of course a heuristic. You can try something different, for example getting rid of q entirely, and see what the result is.
Okay I will do that.
Quoted 12 lines
Quoted 12 lines
@@
e =@q
(
- 1
+ true
|
- 0
+ false
)
Quoted 6 lines
Quoted 3 lines
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\)No. Pattterns don't change anything. The only way to change the state is to write OCeml or python code (script:ocaml or script:python).
Okay noted.
Quoted 9 lines
Quoted 5 lines
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?The two matches of e are intrinsically at different places in the code, since in one case there is true and in the other case there is 1 (or false or 0).
Okay this is very well understood now
Quoted 11 lines
Quoted 10 lines
@s@
type T;
T e;
identifier fld;
symbol true,false;
@@e.fld = \(true\|false\) ==> Same question applies here too
Quoted 7 lines
Same answer. No assignment is executed here. We find a random expression of some type, and this expression has some random structure field named fld. The whole thing is found somewhere to be assigned to true or to false in the source code.
I hope it's clearer now. You may want to try running it on some small example to see what it does.
Yes it is much clearer now.
I will try that
Thanks a lot
Adekunle.