Skip to contentSkip to conversation

Development challenges for handling of selected code repetitions (with SmPL)?

cocci Markus Elfring 2 participants 4 messages Dec 11, 2024 – Dec 12, 2024

lore
Share & tools
lore
#0 lore raw

Hello,

I hope that some software development concerns can be clarified also together with a script variant (like the following) for the semantic patch language.

@adjustment@
expression call;
expression * pointer;
statement action;
@@
if (pointer)
+{
action
<+... when != puts("Hello");
call(pointer);
...+>
+}

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci move_call_into_if_branch2.cocci …
12: no available token to attach to

A) Can any collateral evolution become possible according to the shown error message?

B) The information “Dots may be modified with a when clause, indicating a pattern that should not occur anywhere within the matched sequence.” is provided in the documentation.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/ff57802f2bd1ab1bca063810dbeacf6fdce08b95/docs/manual/cocci_syntax.tex#L1030

Such when clauses influence extra code which may eventually appear around the searched code pattern.
But I would appreciate here if only selected repetitions of the specified code will be taken into account for this use case.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/ff57802f2bd1ab1bca063810dbeacf6fdce08b95/docs/manual/cocci_syntax.tex#L797

Regards,
Markus

#1 lore raw
Quoted 12 lines · Markus Elfring

Hello,

I hope that some software development concerns can be clarified also together with a script variant (like the following) for the semantic patch language.

@adjustment@
expression call;
expression * pointer;
statement action;
@@
if (pointer)

Review

Quoted 6 lines
(quoted diff) +2 -0
+{
    action
 <+... when != puts("Hello");
 call(pointer);
 ...+>
+}

As noted, there is nothing to attach the } to. The ... goes to the end of the function unless there is the when.

julia

Quoted 25 lines

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci move_call_into_if_branch2.cocci …
12: no available token to attach to

A) Can any collateral evolution become possible according to the shown error message?

B) The information “Dots may be modified with a when clause, indicating a pattern that should not occur anywhere within the matched sequence.” is provided in the documentation.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/ff57802f2bd1ab1bca063810dbeacf6fdce08b95/docs/manual/cocci_syntax.tex#L1030

Such when clauses influence extra code which may eventually appear around the searched code pattern.
But I would appreciate here if only selected repetitions of the specified code will be taken into account for this use case.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/ff57802f2bd1ab1bca063810dbeacf6fdce08b95/docs/manual/cocci_syntax.tex#L797

Regards,
Markus

#2 lore raw
Quoted 6 lines
Quoted 6 lines

@adjustment@
expression call;
expression * pointer;
statement action;
@@
if (pointer)

Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +2 -0
+{
    action
 <+... when != puts("Hello");
 call(pointer);
 ...+>
+}

As noted, there is nothing to attach the } to.

I suggest to reconsider the software situation a bit more.

Quoted 2 lines

The ... goes to the end of
the function unless there is the when.

I might be looking for other variations of indicated system functionality.

* May any statement combinations (also behind an if check) be converted to a compound statement (by adding extra curly brackets)?

* Can the possible code repetition ever be expressed in better ways besides the usage of the SmPL ellipses so far?

Regards,
Markus

#3 lore raw
In reply to Julia Lawall
Quoted 1 line

As noted, there is nothing to attach the } to.

Would you like to help more to enable such a connection even if code filter repetitions get involved?

Quoted 2 lines

The ... goes to the end of
the function unless there is the when.

Will such information influence any imaginations for possible software documentations?

I see further design options.

1. Additional notations for indicating code repetitions

2. It is demonstrated already how something can be selected by the means of when clauses. Further settings can become relevant. They should probably not be confused with when clauses. Thus I imagine that additional parameters can be specified behind a key word like “config” for SmPL ellipses.

Regards,
Markus