Skip to contentSkip to conversation

Support for unary operator matching

cocci Stefan Winter 2 participants 2 messages Apr 2, 2025

lore
Share & tools
lore
#0 lore raw

Hi,

I'm trying to match a unary operator with Coccinelle:

$ cat unary.cocci
@@
expression x;
unary operator o = {-};
@@
- o x
+ x

But it seems Coccinelle is choking on "unary":

$ spatch --cocci-file unary.cocci <(echo "int i = -42;")     
init_defs_builtins: /usr/lib/coccinelle/standard.h
meta: parse error: 
  File "unary.cocci", line 3, column 0, charpos = 17
  around = 'unary',
  whole content = unary operator o = {-};

Did I get something wrong or is this supposed to work according to
https://coccinelle.gitlabpages.inria.fr/website/docs/main_grammar.html ?

Thanks,
Stefan

#1 lore raw
Quoted 1 line

But it seems Coccinelle is choking on "unary":

I wonder also why a SmPL script variant (like the following) does not get accepted by the software combination “Coccinelle 1.3-00083-g4093aad2d” so far.

@deletion@
expression x;
unary operator uo = { - };
@@
-uo
x

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci suggestion_for_Stefan_Winter-20250402.cocci …
meta: parse error:
File "suggestion_for_Stefan_Winter-20250402.cocci", line 3, column 0, charpos = 25
around = 'unary',
whole content = unary operator uo = { - };

Regards,
Markus