Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Using the same replacement for different source code
@ 2019-11-12 12:15 Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2019-11-12 12:15 UTC (permalink / raw)
  To: Coccinelle

Hello,

The following change specification gets accepted by the Coccinelle software.

@replacement@
expression x, y;
@@
(
-x + y
+compute(x, y)
|
-x * y
+compute(x, y)
)


I would appreciate if the specification of duplicate SmPL code
can be avoided also for such an use case.
Thus I have tried further code variants out for the semantic patch language.

@replacement@
expression x, y;
@@
(
-x + y
|
-x * y
)
+compute(x, y)


An error message is reported then.

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci replacement_for_two_cases2.cocci
…
9: no available token to attach to


@replacement@
expression x, y;
@@
- \( x + y \| x * y \)
+compute(x, y)

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci replacement_for_two_cases3.cocci
…
5: no available token to attach to


Can such a transformation approach ever work for similar source code?

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

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

* Re: [Cocci] Using the same replacement for different source code
  2019-11-14 16:14         ` Julia Lawall
@ 2019-11-14 16:34           ` Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2019-11-14 16:34 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

> OK, so we have an example that works.

Probably not only for a simple parsing test.


> What doesn't work that you are asking about?

We got different development views around applications of SmPL disjunctions
for source code replacements.

* Which open issues will still be reconsidered here?

* Will it become more interesting then to move special stuff into SmPL constraints?

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

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

* Re: [Cocci] Using the same replacement for different source code
  2019-11-14 16:12       ` Markus Elfring
@ 2019-11-14 16:14         ` Julia Lawall
  2019-11-14 16:34           ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2019-11-14 16:14 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle



On Thu, 14 Nov 2019, Markus Elfring wrote:

> >> @replacement@
> >> binary operator bo = { +, * };
> >> expression x, y;
> >> @@
> >> +compute(
> >>          x
> >> -        bo
> >> +        ,
> >>          y
> >> +       )
> >
> > I can't figure out what this is an example of?
>
> It shows just a possible transformation specification where a SmPL constraint
> is applied instead of a related SmPL disjunction.
>
> See also:
> https://lore.kernel.org/cocci/59c2f820-af2b-030f-3f8e-1dc0fd23f4ba@web.de/
> https://systeme.lip6.fr/pipermail/cocci/2019-November/006582.html
>
>
> > Does this work or not?
>
> This bit of SmPL code gets parsed by the Coccinelle software as expected.
>
> Does it demonstrate similar development opportunities?

OK, so we have an example that works.  What doesn't work that you are
asking about?

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

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

* Re: [Cocci] Using the same replacement for different source code
  2019-11-14 15:35     ` Julia Lawall
@ 2019-11-14 16:12       ` Markus Elfring
  2019-11-14 16:14         ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2019-11-14 16:12 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

>> @replacement@
>> binary operator bo = { +, * };
>> expression x, y;
>> @@
>> +compute(
>>          x
>> -        bo
>> +        ,
>>          y
>> +       )
>
> I can't figure out what this is an example of?

It shows just a possible transformation specification where a SmPL constraint
is applied instead of a related SmPL disjunction.

See also:
https://lore.kernel.org/cocci/59c2f820-af2b-030f-3f8e-1dc0fd23f4ba@web.de/
https://systeme.lip6.fr/pipermail/cocci/2019-November/006582.html


> Does this work or not?

This bit of SmPL code gets parsed by the Coccinelle software as expected.

Does it demonstrate similar development opportunities?

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

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

* Re: [Cocci] Using the same replacement for different source code
  2019-11-14  7:12   ` Markus Elfring
@ 2019-11-14 15:35     ` Julia Lawall
  2019-11-14 16:12       ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2019-11-14 15:35 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle



On Thu, 14 Nov 2019, Markus Elfring wrote:

> I am looking for possibilities to reduce undesirable code duplication
> also for applications of the semantic patch language.
> How much common code can be put into SmPL constraints for this purpose
> (when the usage of SmPL disjunctions shows limitations so far)?
>
> Example:
> @replacement@
> binary operator bo = { +, * };
> expression x, y;
> @@
> +compute(
>          x
> -        bo
> +        ,
>          y
> +       )

I can't figure out what this is an example of?  What do you want to do?
Does this work or not?

julia

>
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Using the same replacement for different source code
  2019-11-12 13:24 ` Julia Lawall
@ 2019-11-14  7:12   ` Markus Elfring
  2019-11-14 15:35     ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2019-11-14  7:12 UTC (permalink / raw)
  To: Coccinelle

I am looking for possibilities to reduce undesirable code duplication
also for applications of the semantic patch language.
How much common code can be put into SmPL constraints for this purpose
(when the usage of SmPL disjunctions shows limitations so far)?

Example:
@replacement@
binary operator bo = { +, * };
expression x, y;
@@
+compute(
         x
-        bo
+        ,
         y
+       )


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

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

* Re: [Cocci] Using the same replacement for different source code
  2019-11-12 12:15 Markus Elfring
@ 2019-11-12 13:24 ` Julia Lawall
  2019-11-14  7:12   ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2019-11-12 13:24 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

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



On Tue, 12 Nov 2019, Markus Elfring wrote:

> Hello,
>
> The following change specification gets accepted by the Coccinelle software.
>
> @replacement@
> expression x, y;
> @@
> (
> -x + y
> +compute(x, y)
> |
> -x * y
> +compute(x, y)
> )
>
>
> I would appreciate if the specification of duplicate SmPL code

It can't.  You have asked this many times before.

julia

> can be avoided also for such an use case.
> Thus I have tried further code variants out for the semantic patch language.
>
> @replacement@
> expression x, y;
> @@
> (
> -x + y
> |
> -x * y
> )
> +compute(x, y)
>
>
> An error message is reported then.
>
> elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci replacement_for_two_cases2.cocci
> …
> 9: no available token to attach to
>
>
> @replacement@
> expression x, y;
> @@
> - \( x + y \| x * y \)
> +compute(x, y)
>
> elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci replacement_for_two_cases3.cocci
> …
> 5: no available token to attach to
>
>
> Can such a transformation approach ever work for similar source code?
>
> 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] 8+ messages in thread

* [Cocci] Using the same replacement for different source code
@ 2019-11-12 12:15 Markus Elfring
  2019-11-12 13:24 ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2019-11-12 12:15 UTC (permalink / raw)
  To: Coccinelle

Hello,

The following change specification gets accepted by the Coccinelle software.

@replacement@
expression x, y;
@@
(
-x + y
+compute(x, y)
|
-x * y
+compute(x, y)
)


I would appreciate if the specification of duplicate SmPL code
can be avoided also for such an use case.
Thus I have tried further code variants out for the semantic patch language.

@replacement@
expression x, y;
@@
(
-x + y
|
-x * y
)
+compute(x, y)


An error message is reported then.

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci replacement_for_two_cases2.cocci
…
9: no available token to attach to


@replacement@
expression x, y;
@@
- \( x + y \| x * y \)
+compute(x, y)

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch --parse-cocci replacement_for_two_cases3.cocci
…
5: no available token to attach to


Can such a transformation approach ever work for similar source code?

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

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

end of thread, back to index

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 12:15 [Cocci] Using the same replacement for different source code Markus Elfring
2019-11-12 12:15 Markus Elfring
2019-11-12 13:24 ` Julia Lawall
2019-11-14  7:12   ` Markus Elfring
2019-11-14 15:35     ` Julia Lawall
2019-11-14 16:12       ` Markus Elfring
2019-11-14 16:14         ` Julia Lawall
2019-11-14 16:34           ` 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
	public-inbox-index cocci

Example config snippet for mirrors

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