Skip to contentSkip to conversation

Checking parts of binary computations with SmPL?

cocci Markus Elfring 2 participants 5 messages Nov 3, 2021

lore
Share & tools
lore
#0 lore raw

Hello,

I have tried another script variant out for the semantic patch language according to the software combination “Coccinelle 1.0.8-gf4ba8df” (OCaml 4.11.1).

@display@
binary_operator bo;
expression left_ex, rigth_ex;
idexpression idex;
@@
*idex = left_ex bo rigth_ex;

[Markus_Elfring@fedora Probe]$ /usr/bin/spatch --parse-cocci /home/altes_Heim2/elfring/Projekte/Coccinelle/Probe/show_assignment_to_idexpression_from_binary_computation1.cocci
init_defs_builtins: /usr/lib64/coccinelle/standard.h
minus: parse error:
File "/home/altes_Heim2/elfring/Projekte/Coccinelle/Probe/show_assignment_to_idexpression_from_binary_computation1.cocci", line 6, column 16, charpos = 98 around = 'bo',
whole content = *idex = left_ex bo rigth_ex;

Can such a search pattern become usable?

Regards,
Markus

#1 lore raw
Quoted 1 line

binary_operator bo;

I should have omitted an underscore at this place.

The following SmPL script variant gets accepted.

@display@
binary operator bo;
expression left_ex, rigth_ex;
idexpression idex;
@@
*idex = left_ex bo rigth_ex;

Regards,
Markus

#2 lore raw
In reply to Markus Elfring
Quoted 1 line

*idex = left_ex bo rigth_ex;

Such a search pattern looks usable (in principle).
Source code places should be found then where one binary operator is applied at least for computations so that their values will be stored somewhere. But I guess that it is unclear then how many code would be matched by the metavariable “left_ex” (and/or “rigth_ex”).
Is such a system detail improvable anyhow?

Regards,
Markus

#3 lore raw
Quoted 8 lines · Markus Elfring
Quoted 1 line

*idex = left_ex bo rigth_ex;

Such a search pattern looks usable (in principle).
Source code places should be found then where one binary operator is applied at least for computations so that their values will be stored somewhere. But I guess that it is unclear then how many code would be matched by the metavariable “left_ex” (and/or “rigth_ex”).
Is such a system detail improvable anyhow?

Coccinelle parses the code according to the standard precedence rules. So there is no ambiguity. bo will match whatever is at the root of the parse tree.

julia

#4 lore raw
Quoted 8 lines
Quoted 5 lines

Source code places should be found then where one binary operator is applied at least for computations so that their values will be stored somewhere. But I guess that it is unclear then how many code would be matched by the metavariable “left_ex” (and/or “rigth_ex”).
Is such a system detail improvable anyhow?

Coccinelle parses the code according to the standard precedence rules. So there is no ambiguity.

Will such information become relevant for another extension to the software documentation?

Quoted 1 line

bo will match whatever is at the root of the parse tree.

I find such feedback also improvable.

I imagine that a parse tree root can be different from the node which represents a binary computation.

Regards,
Markus