I am trying to combine two transformations that differ only by a logical
not. I unsuccessfully tried using the ? annotation, disjunctions, and dots.
Any advice would be appreciated. This is on v1.0.1 + 4 patches.

bash> cat bang.c
void main() {
    int x = 0;

    if ( x = 1 ) {
        x = 1;
    }

    if ( ! (x=1) ) {
        x = 1;
    }
}
bash> cat bang.cocci
@@
identifier i;
expression E;
statement S;
@@

+ i = E;
  if (
- i = E
+ i
  ) S

@@
identifier i;
expression E;
statement S;
@@

+ i = E;
  if (
  !
- (i = E)
+ i
  ) S
bash> spatch --sp-file bang.cocci bang.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
HANDLING: bang.c
diff =
--- bang.c
+++ /tmp/cocci-output-8392-707d21-bang.c
@@ -1,11 +1,13 @@
 void main() {
     int x = 0;

-    if ( x = 1 ) {
+    x = 1;
+    if (x) {
         x = 1;
     }

-    if ( ! (x=1) ) {
+    x = 1;
+    if ( ! x) {
         x = 1;
     }
 }
bash> cat bang2.cocci
@@
identifier i;
expression E;
statement S;
@@

+ i = E;
  if (
? !
- (i = E)
+ i
  ) S

bash> spatch --sp-file bang2.cocci bang.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
Fatal error: exception Failure("opt only allowed for the elements of a
statement list")

Thank you,

Kris
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to