* [Cocci] if statements including assignments @ 2013-08-26 19:26 Wolfram Sang 2013-08-26 19:48 ` Julia Lawall 0 siblings, 1 reply; 3+ messages in thread From: Wolfram Sang @ 2013-08-26 19:26 UTC (permalink / raw) To: cocci Hi, I'd basically need something like: if (... when != var) to match. I couldn't find a way to express it. This is needed since there are constructs like: if (var = something()) which I don't want to match since they assign var a value which is fine in my case. Thanks, Wolfram -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20130826/d6e5c95f/attachment.asc> ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] if statements including assignments 2013-08-26 19:26 [Cocci] if statements including assignments Wolfram Sang @ 2013-08-26 19:48 ` Julia Lawall 2013-08-26 20:17 ` Wolfram Sang 0 siblings, 1 reply; 3+ messages in thread From: Julia Lawall @ 2013-08-26 19:48 UTC (permalink / raw) To: cocci On Mon, 26 Aug 2013, Wolfram Sang wrote: > Hi, > > I'd basically need something like: > > if (... when != var) > > to match. I couldn't find a way to express it. This is needed since > there are constructs like: > > if (var = something()) > > which I don't want to match since they assign var a value which is fine > in my case. This is not really clear enough for me to understand what you do want to do. I imagine that you want something like ( if (pattern_you_like) S1 else S2 | * if (pattern_you_dont_like) S1 else S2 ) Where pattern_you_like might be <+... var ...+>, if you like everything that somewhere contains var. I would really rather that all assignments in if tests disappear, because they make more than one way of expressing the same thing, and thus complicate other semantic patches. I made the attached semantic patch to remove them in cases where one could safely put the assignment just before the if, but it touched over 1100 files in the Linux kernel, so I ran out of courage... julia -------------- next part -------------- @ok@ expression e,e1,e2; statement S1,S2,S1a,S2a; position p; type T; identifier i; iterator I; @@ ( if (...) S1a else S2a | while (...) S1a | for (...;...;...) S1a | I (...) S1a | T i; | e; ) if at p ( ( (e1 = e2) != 0 | (e1 = e2) == 0 | (e1 = e2) != NULL | (e1 = e2) == NULL | IS_ERR(e1 = e2) ) ) S1 else S2 @@ expression e1,e2; statement S1,S2; position ok.p; @@ +e1 = e2; if at p ( ( - (e1 = e2) + e1 != 0 | - (e1 = e2) + e1 == 0 | - (e1 = e2) + e1 != NULL | - (e1 = e2) + e1 == NULL | IS_ERR( - e1 = e2 + e1 ) ) ) S1 else S2 @alsook@ expression e1,e2; statement S1,S2; position p; @@ { if at p ( ( (e1 = e2) != 0 | (e1 = e2) == 0 | (e1 = e2) != NULL | (e1 = e2) == NULL | IS_ERR(e1 = e2) ) ) S1 else S2 ... when any } @@ expression e1,e2; statement S1,S2; position alsook.p; @@ +e1 = e2; if at p ( ( - (e1 = e2) + e1 != 0 | - (e1 = e2) + e1 == 0 | - (e1 = e2) + e1 != NULL | - (e1 = e2) + e1 == NULL | IS_ERR( - e1 = e2 + e1 ) ) ) S1 else S2 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] if statements including assignments 2013-08-26 19:48 ` Julia Lawall @ 2013-08-26 20:17 ` Wolfram Sang 0 siblings, 0 replies; 3+ messages in thread From: Wolfram Sang @ 2013-08-26 20:17 UTC (permalink / raw) To: cocci > > I'd basically need something like: > > > > if (... when != var) > > This is not really clear enough for me to understand what you do want to > do. I imagine that you want something like > > ( > if (pattern_you_like) S1 else S2 > | > * if (pattern_you_dont_like) > S1 else S2 > ) Ah, so I was on a good path since I ended up with something similar... > Where pattern_you_like might be <+... var ...+>, if you like everything > that somewhere contains var. ... and this hint made it work, thanks a lot! Before that I was using if (var = ...) S as pattern_I_like. But that never matched and thus always ended up in the pattern_i_dont_like branch. > I would really rather that all assignments in if tests disappear, +1. They are often annoying. > the if, but it touched over 1100 files in the Linux kernel, so I ran out > of courage... :) Thanks, Wolfram -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20130826/ad752540/attachment.asc> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-26 20:17 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-08-26 19:26 [Cocci] if statements including assignments Wolfram Sang 2013-08-26 19:48 ` Julia Lawall 2013-08-26 20:17 ` Wolfram Sang
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.