Skip to contentSkip to conversation

Using the same replacement for different source code

Cocci Markus Elfring 2 participants 7 messages Nov 12, 2019 – Nov 14, 2019

lore
Share & tools
lore
#0 lore raw

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 16 lines · Markus Elfring

Hello,

The following change specification gets accepted by the Coccinelle software.

@replacement@
expression x, y;
@@
(

(quoted diff) +1 -1
-x + y
+compute(x, y)

|

(quoted diff) +1 -1
-x * y
+compute(x, y)

)

Quoted 1 line

I would appreciate if the specification of duplicate SmPL code

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

julia

Quoted 32 lines

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

Quoted 9 lines

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

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

#2 lore raw

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw
Quoted 10 lines · Markus Elfring

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

Review

Quoted 6 lines
(quoted diff) +3 -1
+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

Quoted 9 lines

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

#4 lore raw
Quoted 11 lines

Review

Quoted 10 lines

@replacement@
binary operator bo = { +, * };
expression x, y;
@@

(quoted diff) +3 -1
+compute(
         x
-        bo
+        ,
         y
+       )
Quoted 1 line

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/[email protected]/
https://systeme.lip6.fr/pipermail/cocci/2019-November/006582.html

Quoted 1 line

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#5 lore raw
Quoted 21 lines · Markus Elfring
Quoted 11 lines

Review

Quoted 10 lines

@replacement@
binary operator bo = { +, * };
expression x, y;
@@

(quoted diff) +3 -1
+compute(
         x
-        bo
+        ,
         y
+       )
Quoted 1 line

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/[email protected]/
https://systeme.lip6.fr/pipermail/cocci/2019-November/006582.html

Quoted 5 lines
Quoted 1 line

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#6 lore raw
Quoted 1 line

OK, so we have an example that works.

Probably not only for a simple parsing test.

Quoted 1 line

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci