Working with backreferences in SmPL scripts?
Hello,
I have tried another small SmPL script out.
@replacement@
expression ex;
identifier var;
@@
var
- = var +
+ +=
ex
elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch simplify_addition1.cocci Test_increment1.c …
@@ -1,6 +1,6 @@
int main(void)
{
int counter = 3;
-counter = counter + 5;
+counter += 5;
return counter;
}
I have repeated this transformation approach with the following source code.
int main(void)
{
int x = 2, y = 3;
x = y + 5;
return x;
}
This test example did not present a generated change suggestion. I find that such a result can be interpreted in two ways then.
1. The Coccinelle software ensured that the specified metavariable “var” referred to the same source code at all shown places with the consequence that the variable “y” could not match in this test case.
2. A possible data output was not displayed despite of the detail that the variable “y” is also an identifier according to the syntax of the C programming language.
Would there be a need to express a relationship to a previous match by a kind of notation for backreferences?
The situation can become challenging for the safe handling of advanced statements in more meaningful source files.
* How do you think about to help with the reconsideration (and occasional deletion) of duplicate code by the means of the semantic patch language?
* Would you like to clarify the desired software behaviour for such use cases?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 30 lines · Markus Elfring
Hello,
I have tried another small SmPL script out.
@replacement@
expression ex;
identifier var;
@@
var(quoted diff) +1
-1- = var + + += exelfring@Sonne:~/Projekte/Coccinelle/Probe> spatch
simplify_addition1.cocciTest_increment1.c…(quoted diff) +1
-1@@ -1,6 +1,6 @@ int main(void) { int counter = 3; -counter = counter + 5; +counter += 5; return counter; }I have repeated this transformation approach with the following source code.
Quoted 6 lines
int main(void)
{
int x = 2, y = 3;
x = y + 5;
return x;
}
A metavariable is always bound to the same value within a given control-flow path. I have no idea what you are trying to get at with this example.
julia
Quoted 23 lines
This test example did not present a generated change suggestion. I find that such a result can be interpreted in two ways then.
1. The Coccinelle software ensured that the specified metavariable “var” referred to the same source code at all shown places with the consequence that the variable “y” could not match in this test case.
2. A possible data output was not displayed despite of the detail that the variable “y” is also an identifier according to the syntax of the C programming language.
Would there be a need to express a relationship to a previous match by a kind of notation for backreferences?The situation can become challenging for the safe handling of advanced statements in more meaningful source files.
* How do you think about to help with the reconsideration (and occasional deletion) of duplicate code by the means of the semantic patch language?
Quoted 9 lines
* Would you like to clarify the desired software behaviour for such use cases?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Quoted 2 lines
A metavariable is always bound to the same value within a given control-flow path.
Thanks for this information.
Quoted 1 line
I have no idea what you are trying to get at with this example.
Some goals can match to my use case description.
* Is another nice refactoring application demonstrated for
the semantic patch language to trigger constructive development discussions?
* Can such test cases help to clarify views about questionable software behaviour (from analysis of longer source files with more interesting statements)?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci