Skip to contentSkip to conversation

How to fix parse errors for two SmPL scripts?

cocci Markus Elfring 2 participants 4 messages Jul 19, 2024 – Jul 20, 2024

lore
Share & tools
lore
#0 lore raw

Hello,

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

A)

@replacement@
constant char[] format1, format2;
expression check, input, target;
expression list el;
identifier x;
@@
-if (check)
- target += x(input, format1, el);
-else
- target += x(input, format2, el);
+target += x(input, (check) ? format1 : format2, el);

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator3.cocci …
minus: parse error:
File "use_ternary_operator3.cocci", line 8, column 14, charpos = 144
around = 'x',
whole content = - target += x(input, format1, el);

B)

@replacement2@
expression check, context, target;
expression list inputs;
format list fl1, fl2;
identifier action;
@@
-if (check)
- target += action(context, "%@fl1@", inputs);
-else
- target += action(context, "%@fl2@", inputs);
+target += action(context, (check) ? "%@fl1@" : "%@fl2@", inputs);

Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator4.cocci …
minus: parse error:
File "use_ternary_operator4.cocci", line 8, column 14, charpos = 144
around = 'action',
whole content = - target += action(context, "%@fl1@", inputs);

How can corresponding software components be improved?

Regards,
Markus

#1 lore raw
Quoted 44 lines · Markus Elfring

Hello,

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

A)

@replacement@
constant char[] format1, format2;
expression check, input, target;
expression list el;
identifier x;
@@

(quoted diff) +1 -4
-if (check)
-   target += x(input, format1, el);
-else
-   target += x(input, format2, el);
+target += x(input, (check) ? format1 : format2, el);

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator3.cocci …
minus: parse error:
File "use_ternary_operator3.cocci", line 8, column 14, charpos = 144
around = 'x',
whole content = - target += x(input, format1, el);

B)

@replacement2@
expression check, context, target;
expression list inputs;
format list fl1, fl2;
identifier action;
@@

(quoted diff) +1 -4
-if (check)
-   target += action(context, "%@fl1@", inputs);
-else
-   target += action(context, "%@fl2@", inputs);
+target += action(context, (check) ? "%@fl1@" : "%@fl2@", inputs);
Quoted 7 lines

Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator4.cocci …
minus: parse error:
File "use_ternary_operator4.cocci", line 8, column 14, charpos = 144
around = 'action',
whole content = - target += action(context, "%@fl1@", inputs);

Thanks for the reports. I will look into it.

julia

#2 lore raw
In reply to Markus Elfring
Quoted 44 lines · Markus Elfring

Hello,

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

A)

@replacement@
constant char[] format1, format2;
expression check, input, target;
expression list el;
identifier x;
@@

(quoted diff) +1 -4
-if (check)
-   target += x(input, format1, el);
-else
-   target += x(input, format2, el);
+target += x(input, (check) ? format1 : format2, el);

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator3.cocci …
minus: parse error:
File "use_ternary_operator3.cocci", line 8, column 14, charpos = 144
around = 'x',
whole content = - target += x(input, format1, el);

B)

@replacement2@
expression check, context, target;
expression list inputs;
format list fl1, fl2;
identifier action;
@@

(quoted diff) +1 -4
-if (check)
-   target += action(context, "%@fl1@", inputs);
-else
-   target += action(context, "%@fl2@", inputs);
+target += action(context, (check) ? "%@fl1@" : "%@fl2@", inputs);
Quoted 7 lines

Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator4.cocci …
minus: parse error:
File "use_ternary_operator4.cocci", line 8, column 14, charpos = 144
around = 'action',
whole content = - target += action(context, "%@fl1@", inputs);

It's not the ideal solution, but in the meantime, both work fine if x and action are declared as expression rather than identifier.

julia

#3 lore raw
In reply to Markus Elfring

This problem has been fixed.

julia

Quoted 58 lines · Markus Elfring

Hello,

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

A)

@replacement@
constant char[] format1, format2;
expression check, input, target;
expression list el;
identifier x;
@@

(quoted diff) +1 -4
-if (check)
-   target += x(input, format1, el);
-else
-   target += x(input, format2, el);
+target += x(input, (check) ? format1 : format2, el);

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator3.cocci …
minus: parse error:
File "use_ternary_operator3.cocci", line 8, column 14, charpos = 144
around = 'x',
whole content = - target += x(input, format1, el);

B)

@replacement2@
expression check, context, target;
expression list inputs;
format list fl1, fl2;
identifier action;
@@

(quoted diff) +1 -4
-if (check)
-   target += action(context, "%@fl1@", inputs);
-else
-   target += action(context, "%@fl2@", inputs);
+target += action(context, (check) ? "%@fl1@" : "%@fl2@", inputs);

Another questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_ternary_operator4.cocci …
minus: parse error:
File "use_ternary_operator4.cocci", line 8, column 14, charpos = 144
around = 'action',
whole content = - target += action(context, "%@fl1@", inputs);

How can corresponding software components be improved?

Regards,
Markus