Skip to contentSkip to conversation

Searching for switch statements with SmPL?

cocci Markus Elfring 2 participants 9 messages Nov 8, 2025 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

I would appreciate if another source code analysis can be achieved also by the means of the semantic patch language.
Thus I tried the following SmPL script variant out.

@display@
constant c;
expression e;
statement s;
@@
(switch (e)
{
<+... case c: ... break; ...+>
}
|
*switch (...) s
)

Unfortunately, I am wondering about the following information.

Questionable test result (according to the software combination “Coccinelle 1.3.0”):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> /usr/bin/spatch --parse-cocci show_switch_without_break2.cocci …
minus: parse error:
File "show_switch_without_break2.cocci", line 8, column 1, charpos = 68
around = '<+...',
whole content = <+... case c: ... break; ...+>

Under which circumstances will such data processing become better supported?

Regards,
Markus

#1 lore raw
Quoted 35 lines · Markus Elfring

Hello,

I would appreciate if another source code analysis can be achieved also by the means of the semantic patch language.
Thus I tried the following SmPL script variant out.

@display@
constant c;
expression e;
statement s;
@@
(switch (e)
{
<+... case c: ... break; ...+>
}
|
*switch (...) s
)

Unfortunately, I am wondering about the following information.

Questionable test result (according to the software combination “Coccinelle 1.3.0”):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> /usr/bin/spatch --parse-cocci show_switch_without_break2.cocci …
minus: parse error:
File "show_switch_without_break2.cocci", line 8, column 1, charpos = 68
around = '<+...',
whole content = <+... case c: ... break; ...+>

Quoted 1 line

Under which circumstances will such data processing become better supported?

None. All cases are directly attached to the { of the switch, like if branches are attached to an if header. So the nest doesn’t make sense.

Quoted 3 lines

Regards,
Markus

#2 lore raw
Quoted 2 lines
Quoted 1 line

Under which circumstances will such data processing become better supported?

None. All cases are directly attached to the { of the switch, like if branches are attached to an if header. So the nest doesn’t make sense.

I hope that better common understanding can be achieved for more desirable software behaviour also according to such a feedback.

Which SmPL script variant would you find more reasonable for the mentioned use case?

Regards,
Markus

#3 lore raw
Quoted 15 lines · Markus Elfring



Quoted 3 lines
Quoted 2 lines

Under which circumstances will such data processing become better supported?

None. All cases are directly attached to the { of the switch, like if branches are attached to an if header. So the nest doesn’t make sense.

I hope that better common understanding can be achieved for more desirable software behaviour also according to such a feedback.

Which SmPL script variant would you find more reasonable for the mentioned use case?

Just remove the <+… …+>

Quoted 2 lines

Regards,
Markus

#5 lore raw

Yes. You used * so paths are considered individually Sent from my iPhone

Quoted 14 lines · Markus Elfring



Quoted 5 lines
Quoted 3 lines

Which SmPL script variant would you find more reasonable for the mentioned use case?

Just remove the <+… …+>

May switch statements contain multiple cases?
https://cppreference.com/w/c/language/switch.html

Regards,
Markus

#6 lore raw
Quoted 1 line

Yes. You used * so paths are considered individually

Our development views might differ again on affected technical details.

* Which metavariable type would really fit to variable case distinctions by switch statements?

* Which implementation detail did hinder the desired parsing of SmPL code?

Regards,
Markus

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 1 line

There is no meta variable for case lines.

Did I stumble on another (temporary) software limitation then?

Quoted 1 line

The <+… …+> caused the parsing problem as far as I know.

I would expect that such an SmPL dot variant can usually handle multiple items.

Regards,
Markus

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

Just remove the <+… …+>

Another interpretation:
Do you propose to restrict the source code search approach to a few known case distinctions?

Should the metavariable usage be adjusted any more accordingly?

Regards,
Markus