Coccinelle archive on lore.kernel.org
 help / color / 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

* Re: [Cocci] Working with backreferences in SmPL scripts?
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2019-04-17  7:57 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

[-- Attachment #1: Type: text/plain, Size: 1954 bytes --]



On Wed, 17 Apr 2019, Markus Elfring wrote:

> 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;
> }

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

>
>
> 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
>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Working with backreferences in SmPL scripts?
  2019-04-17  7:57 ` Julia Lawall
@ 2019-04-17  8:23   ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-04-17  8:23 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

> A metavariable is always bound to the same value within a given
> control-flow path.

Thanks for this information.


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

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

end of thread, back to index

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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox