Skip to contentSkip to conversation

How to fix a parse error for another SmPL script?

cocci Markus Elfring 2 participants 16 messages Jul 26, 2024 – Jul 28, 2024

lore
Share & tools
lore
#0 lore raw

Hello,

A simple source code transformation was demonstrated.
https://lore.kernel.org/all/?q=convert%20comma%20to%20semicolon

Concrete patch example:
https://lore.kernel.org/linux-kernel/[email protected]/

Thus I constructed another tiny script variant for the semantic patch language.

@adjustment@
assignment operator ao;
expression e, ex, te, tex;
@@
<+...
te ao e
-,
+;
...+>
tex ao ex;

I stumbled on undesirable behaviour once more also with the software combination “Coccinelle 1.2-00038-g2297fc0f”.

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_comma_to_semicolon.cocci …
minus: parse error:
File "convert_comma_to_semicolon.cocci", line 9, column 1, charpos = 90
around = '...+>',
whole content = ...+>

See also:
Get the non-optional nest construct completely working for SmPL 2017-08-18
https://github.com/coccinelle/coccinelle/issues/114

How can corresponding software components be improved?

Regards,
Markus

#1 lore raw
Quoted 11 lines · Markus Elfring

Hello,

A simple source code transformation was demonstrated.
https://lore.kernel.org/all/?q=convert%20comma%20to%20semicolon

Concrete patch example:
https://lore.kernel.org/linux-kernel/[email protected]/

Thus I constructed another tiny script variant for the semantic patch language.

Quoted 10 lines

@adjustment@
assignment operator ao;
expression e, ex, te, tex;
@@
<+...
te ao e
-,
+;
...+>
tex ao ex;

The above semantic patch does not parse because te ao e, is not a valid C term. There is no term in the C language that ends with a comma.

julia

Quoted 24 lines

I stumbled on undesirable behaviour once more also with the software combination “Coccinelle 1.2-00038-g2297fc0f”.

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci convert_comma_to_semicolon.cocci …
minus: parse error:
File "convert_comma_to_semicolon.cocci", line 9, column 1, charpos = 90
around = '...+>',
whole content = ...+>

See also:
Get the non-optional nest construct completely working for SmPL 2017-08-18
https://github.com/coccinelle/coccinelle/issues/114

How can corresponding software components be improved?

Regards,
Markus

#3 lore raw
Quoted 11 lines · Markus Elfring
Quoted 11 lines
Quoted 10 lines

@adjustment@
assignment operator ao;
expression e, ex, te, tex;
@@
<+...
te ao e
-,
+;
...+>
tex ao ex;

Quoted 5 lines
Quoted 2 lines

The above semantic patch does not parse because te ao e, is not a valid C term. There is no term in the C language that ends with a comma.

Please reconsider such a view once more.
https://en.cppreference.com/w/c/language/operator_other#Comma_operator

The link you cite says:

The comma operator expression has the form
lhs , rhs

That doesn't end in a comma. There is no rhs within the <+... ...+>

julia

Quoted 4 lines

Regards,
Markus

#4 lore raw

Re: [cocci] Data processing challenges according to the comma operator

Quoted 9 lines
Quoted 2 lines

Please reconsider such a view once more.
https://en.cppreference.com/w/c/language/operator_other#Comma_operator

The link you cite says:

The comma operator expression has the form
lhs , rhs

That doesn't end in a comma. There is no rhs within the <+... ...+>

Can subexpressions be supported by the semantic patch language for such a “binary” operator?

Regards,
Markus

#5 lore raw

Re: [cocci] Data processing challenges according to the comma operator

Quoted 5 lines · Markus Elfring
Quoted 5 lines
Quoted 2 lines

Please reconsider such a view once more.
https://en.cppreference.com/w/c/language/operator_other#Comma_operator

The link you cite says:

Quoted 7 lines
Quoted 4 lines

The comma operator expression has the form
lhs , rhs

That doesn't end in a comma. There is no rhs within the <+... ...+>

Can subexpressions be supported by the semantic patch language for such a “binary” operator?

A subexpression is also an expression. There is nothing specific about this operator. The rule in Coccinelle is that when you write <+... ...+>, the term in the middle has to be a complete expression or statement.

julia

#6 lore raw

Re: [cocci] Data processing challenges according to the comma operator

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Please reconsider such a view once more.
https://en.cppreference.com/w/c/language/operator_other#Comma_operator

The link you cite says:

The comma operator expression has the form
lhs , rhs

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

That doesn't end in a comma. There is no rhs within the <+... ...+>

Can subexpressions be supported by the semantic patch language for such a “binary” operator?

A subexpression is also an expression.

There is a desire to express special source code search restrictions.

Quoted 1 line

There is nothing specific about this operator.

Its parameters should be matched (or even captured) here.

Quoted 2 lines

The rule in Coccinelle is that when you write <+... ...+>, the term in the middle has to be a complete expression or statement.

This should be the case for the discussed SmPL script example.

Regards,
Markus

#7 lore raw

Re: [cocci] Data processing challenges according to the comma operator

In reply to Julia Lawall
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

The comma operator expression has the form
lhs , rhs

That doesn't end in a comma. There is no rhs within the <+... ...+>

Can subexpressions be supported by the semantic patch language for such a “binary” operator?

A subexpression is also an expression. There is nothing specific about this operator.

How do you call the construct of an expression together with an operator (like a comma for example) on the right side?

Quoted 2 lines

The rule in Coccinelle is that when you write <+... ...+>,
the term in the middle has to be a complete expression or statement.

Will additional source code search operators become relevant here?

Do further development resources need to be allocated anyhow?

Regards,
Markus

#8 lore raw

Re: [cocci] Data processing challenges according to the comma operator

Quoted 5 lines · Markus Elfring
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The comma operator expression has the form
lhs , rhs

That doesn't end in a comma. There is no rhs within the <+... ...+>

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Can subexpressions be supported by the semantic patch language for such a “binary” operator?

A subexpression is also an expression. There is nothing specific about this operator.

How do you call the construct of an expression together with an operator (like a comma for example) on the right side?

Nothing.

Quoted 8 lines
Quoted 4 lines

The rule in Coccinelle is that when you write <+... ...+>,
the term in the middle has to be a complete expression or statement.

Will additional source code search operators become relevant here?

Do further development resources need to be allocated anyhow?

No there is no interest in supporting random fragments of terms. They are hard to parse and it's not clear that the generated code would be even syntactically correct.

julia

#9 lore raw

Re: [cocci] Data processing challenges according to the comma operator

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

The comma operator expression has the form
lhs , rhs

That doesn't end in a comma. There is no rhs within the <+... ...+>

Can subexpressions be supported by the semantic patch language for such a “binary” operator?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

A subexpression is also an expression. There is nothing specific about this operator.

How do you call the construct of an expression together with an operator (like a comma for example) on the right side?

Nothing.

Such a feedback hinders a bit the development of a solution, doesn't it?

I would find further clarification helpful for a corresponding terminology.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The rule in Coccinelle is that when you write <+... ...+>,
the term in the middle has to be a complete expression or statement.

Will additional source code search operators become relevant here?

Do further development resources need to be allocated anyhow?

No there is no interest in supporting random fragments of terms.

Different development interests are distributed between involved parties. Syntax items can hopefully be better discussed.

Quoted 2 lines

They are hard to parse and it's not clear that the generated code would be even syntactically correct.

Such application concerns can eventually be clarified better.

Regards,
Markus

#10 lore raw

Re: [cocci] Data processing challenges according to the comma operator

In reply to Julia Lawall
Quoted 2 lines

The above semantic patch does not parse because te ao e, is not a valid C term. There is no term in the C language that ends with a comma.

Can a source code search approach (like the following) become supported?

@display@
expression list el;
@@
*el;

https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/587259e014d0c83ac051702354da4d53e0905d12/docs/manual/cocci_syntax.tex#L359-362
https://github.com/coccinelle/coccinelle/blob/2297fc0f90ce8bef78d2977e9aacc188d7e87c6d/docs/manual/cocci_syntax.tex#L359-L362

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci show_comma_expression_statements.cocci …
minus: parse error:
File "show_comma_expression_statements.cocci", line 4, column 1, charpos = 34
around = 'el',
whole content = *el;

Regards,
Markus

#11 lore raw

Re: [cocci] Code adjustment challenges according to the comma operator (with SmPL)

In reply to Julia Lawall
Quoted 2 lines

The above semantic patch does not parse because te ao e, is not a valid C term. There is no term in the C language that ends with a comma.

I constructed another tiny script variant for the semantic patch language.

@replacement@
expression x, y;
@@
x
-,
+;
y;

I would like to point out that such a simple source code transformation approach found 156 files from the software “Linux next-20240726” for possible updates. Will further collateral evolution become interesting accordingly?

Regards,
Markus

#12 lore raw

Re: [cocci] Code adjustment challenges according to the comma operator (with SmPL)

Quoted 15 lines · Markus Elfring
Quoted 2 lines

The above semantic patch does not parse because te ao e, is not a valid C term. There is no term in the C language that ends with a comma.

I constructed another tiny script variant for the semantic patch language.

@replacement@
expression x, y;
@@
x
-,
+;
y;

Quoted 3 lines

I would like to point out that such a simple source code transformation approach found 156 files from the software “Linux next-20240726” for possible updates. Will further collateral evolution become interesting accordingly?

I think that you have to look at the examples and judget whether the use of the comma operator is helpful in each case.

julia

#13 lore raw

Re: [cocci] Code adjustment challenges according to the comma operator (with SmPL)

Quoted 6 lines
Quoted 3 lines

I would like to point out that such a simple source code transformation approach found 156 files from the software “Linux next-20240726” for possible updates. Will further collateral evolution become interesting accordingly?

I think that you have to look at the examples and judget whether the use of the comma operator is helpful in each case.

Would you become interested to support the integration of another SmPL script variant for the coccicheck tool?

Regards,
Markus

#14 lore raw

Re: [cocci] Code adjustment challenges according to the comma operator (with SmPL)

Quoted 9 lines · Markus Elfring
Quoted 6 lines
Quoted 3 lines

I would like to point out that such a simple source code transformation approach found 156 files from the software “Linux next-20240726” for possible updates. Will further collateral evolution become interesting accordingly?

I think that you have to look at the examples and judget whether the use of the comma operator is helpful in each case.

Would you become interested to support the integration of another SmPL script variant for the coccicheck tool?

I think that such a script already exists. Or at least the transformation has aready been extensively applied some years ago.

julia

#15 lore raw

Re: [cocci] Code adjustment challenges according to the comma operator (with SmPL)

Quoted 5 lines
Quoted 2 lines

Would you become interested to support the integration of another SmPL script variant for the coccicheck tool?

I think that such a script already exists. Or at least the transformation has aready been extensively applied some years ago.

Which transformation approaches have you got in mind so far?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle?h=v6.10

Regards,
Markus