cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Working with backreferences in SmPL scripts?
@ 2019-04-17  7:45 Markus Elfring
  2019-04-17  7:57 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2019-04-17  7:45 UTC (permalink / raw)
  To: Coccinelle

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
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-17  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17  7:45 [Cocci] Working with backreferences in SmPL scripts? Markus Elfring
2019-04-17  7:57 ` Julia Lawall
2019-04-17  8:23   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).