Skip to contentSkip to conversation

Improving handling of position information for SmPL?

cocci Markus Elfring 1 participant 2 messages Sep 28, 2025 – Sep 29, 2025

lore
Share & tools
lore
#0 lore raw

Hello,

A bit of information is provided in the manual of the semantic patch language also for the usage of position metavariables.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/7674e29155d23846c41504948f4e4b1e796d07ec/docs/manual/cocci_syntax.tex#L420-432

Some data processing results can be observed then also according to the software combination “Coccinelle 1.3.0”.

Source file example:
void my_test_number(void)
{
123;
}

A)
find_special_number_without_position.cocci:
@find@
@@
-123;

Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch --show-ctl-text test_special_number.c find_special_number_without_position.cocci …
Let _r_0 = (EX^((TrueBranch v InLoop)) v EX^(EX^(FalseBranch))) in
((_r_0 & (Ex _v . 123;)) v (!_r_0 & (Ex _v . 123;)))
…

B)
find_special_number_with_position.cocci:
@find@
position place;
@@
-123@place;

Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch --show-ctl-text test_special_number.c find_special_number_with_position.cocci …
Let _r_0 = (EX^((TrueBranch v InLoop)) v EX^(EX^(FalseBranch))) in
((_r_0 & (Ex_ place . (Ex _v . 123@place ;))) v
(!_r_0 & (Ex_ place . (Ex _v . 123@place ;))))
…

A corresponding computation tree formula is generated.
But it contains still references to an extra position metavariable despite of the implementation detail that it might not be needed here.

C)
find_special_number_with_reused_position.cocci:
@start@
position place;
@@
123@place;

@reusing@
position start.place;
@@
123@place;

@script:python@
p << start.place;
@@
print(f"file: {p[0].file}\nfunction: {p[0].current_element}\nline: {p[0].line}")

Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> /usr/bin/spatch --show-ctl-text test_special_number.c find_special_number_with_reused_position.cocci …
start =
…
CTL =

(Ex place . (Ex _v . 123@place ;))
…
reusing =
…
CTL =

123@place ;
…

How do you think about to clarify the shown differences in the generated terms?

Will any improvements become helpful for involved software components?

Regards,
Markus

#1 lore raw
Quoted 2 lines

Some data processing results can be observed then also according to the software combination “Coccinelle 1.3.0”.

It seems that the printout of generated computation tree logic terms might not be so helpful so far.

Thus I imagine that another development idea can influence software evolution in desirable directions.

SmPL variables are available to be filled with data. They can get useful contents
* after a source code search was performed
or
* values were set by a supported scripting interface.

Position metavariables have got special properties.
They can be connected to selected source code places.
I am looking for further clarifications also according to corresponding implementation details:
1. It can be determined if position information is actually reused. May any additional variables be omitted from data processing?

2. If position data are inherited, they are attached to found items. I assume that these items do eventually not need to be researched again because code places were marked already.
Would position metavariables suppress any data evaluation for companion items?

Regards,
Markus