Hi,
I'm trying do the following kind of transformations:
int x, y;
char *p;
bool b, c;
-b = x || !y;
+b = (x != 0) || (y == 0);
-c = !p;
+c = (p == NULL);
-if (x & 3)
+if ((x & 3) != 0)
f();
// etc
That is: trying to eliminate implicit boolean-ness (and add parentheses as
well).
I was thinking along the lines of first finding expressions
that are in "boolean context" (part of a || or && expression,
or an if/for/while condition, maybe something else too?).
Then find sub-expressions of those that are not of the form 'E op F'
where 'op' is a comparison operator (==, !=, <=, ...).
And finally depending on whether they are pointer or integer and
whether they are negated, replace them with the above constructs (x != 0,
etc.)
Is this the right way to think about this? Meaning does it fit the mental
model
of Coccinelle, or some other approach is needed? (E.g. it crossed my mind to
maybe match all expressions and try to filter out "unwanted" ones via
position p != { ... } constraints but that seemed infeasible.)
Thanks!
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci