* [Cocci] elision of unneeded parens
@ 2015-10-12 21:38 ron minnich
2015-10-12 21:43 ` Peter Senna Tschudin
0 siblings, 1 reply; 7+ messages in thread
From: ron minnich @ 2015-10-12 21:38 UTC (permalink / raw)
To: cocci
I've had someone request something and I want to show them how cool
coccinnelle is. If only I were smart enough!
There are lots of things like this:
if ((a == b) && (c != e))
which I'd like to turn in to
if (a == b && c == d) ...
anyway, is this one simple?
ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20151012/f11d93f8/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] elision of unneeded parens
2015-10-12 21:38 [Cocci] elision of unneeded parens ron minnich
@ 2015-10-12 21:43 ` Peter Senna Tschudin
2015-10-12 21:45 ` ron minnich
0 siblings, 1 reply; 7+ messages in thread
From: Peter Senna Tschudin @ 2015-10-12 21:43 UTC (permalink / raw)
To: cocci
On Mon, Oct 12, 2015 at 11:38 PM, ron minnich <rminnich@gmail.com> wrote:
> I've had someone request something and I want to show them how cool
> coccinnelle is. If only I were smart enough!
>
> There are lots of things like this:
> if ((a == b) && (c != e))
>
> which I'd like to turn in to
> if (a == b && c == d) ...
Where does d comes from?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] elision of unneeded parens
2015-10-12 21:43 ` Peter Senna Tschudin
@ 2015-10-12 21:45 ` ron minnich
2015-10-12 21:48 ` Peter Senna Tschudin
0 siblings, 1 reply; 7+ messages in thread
From: ron minnich @ 2015-10-12 21:45 UTC (permalink / raw)
To: cocci
wow, I can't type.
Let me say it more sensibly, even if wrong :-)
[[[ I know this is wrong, it's kind of "what I want it to do" ]]]
@@
expression E1, E2;
statement S;
function f;
@@
f(...){<...
-if ((E1) && (E2))
+if (E1 && E2)
S
...> }
Is that any more sensible?
thanks
ron
On Mon, Oct 12, 2015 at 2:43 PM Peter Senna Tschudin <peter.senna@gmail.com>
wrote:
> On Mon, Oct 12, 2015 at 11:38 PM, ron minnich <rminnich@gmail.com> wrote:
> > I've had someone request something and I want to show them how cool
> > coccinnelle is. If only I were smart enough!
> >
> > There are lots of things like this:
> > if ((a == b) && (c != e))
> >
> > which I'd like to turn in to
> > if (a == b && c == d) ...
> Where does d comes from?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20151012/ed61135b/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] elision of unneeded parens
2015-10-12 21:45 ` ron minnich
@ 2015-10-12 21:48 ` Peter Senna Tschudin
2015-10-12 21:54 ` Peter Senna Tschudin
0 siblings, 1 reply; 7+ messages in thread
From: Peter Senna Tschudin @ 2015-10-12 21:48 UTC (permalink / raw)
To: cocci
On Mon, Oct 12, 2015 at 11:45 PM, ron minnich <rminnich@gmail.com> wrote:
> wow, I can't type.
>
> Let me say it more sensibly, even if wrong :-)
> [[[ I know this is wrong, it's kind of "what I want it to do" ]]]
>
> @@
> expression E1, E2;
> statement S;
> function f;
> @@
> f(...){<...
> -if ((E1) && (E2))
> +if (E1 && E2)
> S
> ...> }
>
> Is that any more sensible?
My example adds '== d'...
$ cat /tmp/test.cocci
@@
expression a, b, c, e;
@@
-((a == b) && (c != e))
+a == b && c == d
$ clear;spatch /tmp/test.cocci kernel/locking/lockdep.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
HANDLING: kernel/locking/lockdep.c
diff =
--- kernel/locking/lockdep.c
+++ /tmp/cocci-output-9601-607267-lockdep.c
@@ -1420,7 +1420,7 @@ print_shortest_lock_dependencies(struct
print_stack_trace(&entry->trace, 2);
printk("\n");
- if (depth == 0 && (entry != root)) {
+ if (depth == 0 && entry == d) {
printk("lockdep:%s bad path found in chain graph\n", __func__);
break;
}
@@ -2322,7 +2322,7 @@ print_irq_inversion_bug(struct task_stru
/* Find a middle lock (if one exists) */
depth = get_lock_depth(other);
do {
- if (depth == 0 && (entry != root)) {
+ if (depth == 0 && entry == d) {
printk("lockdep:%s bad path found in chain graph\n", __func__);
break;
}
@@ -4198,7 +4198,7 @@ retry:
* if it's not sleeping (or if it's not the current
* task):
*/
- if (p->state == TASK_RUNNING && p != current)
+ if (p->state == TASK_RUNNING && p == d)
continue;
if (p->lockdep_depth)
lockdep_print_held_locks(p);
Does this help?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] elision of unneeded parens
2015-10-12 21:48 ` Peter Senna Tschudin
@ 2015-10-12 21:54 ` Peter Senna Tschudin
2015-10-13 3:55 ` ron minnich
0 siblings, 1 reply; 7+ messages in thread
From: Peter Senna Tschudin @ 2015-10-12 21:54 UTC (permalink / raw)
To: cocci
_very risky_:
@@
expression a, b;
@@
-(
\(a == b\|a != b\)
-)
On Mon, Oct 12, 2015 at 11:48 PM, Peter Senna Tschudin
<peter.senna@gmail.com> wrote:
> On Mon, Oct 12, 2015 at 11:45 PM, ron minnich <rminnich@gmail.com> wrote:
>> wow, I can't type.
>>
>> Let me say it more sensibly, even if wrong :-)
>> [[[ I know this is wrong, it's kind of "what I want it to do" ]]]
>>
>> @@
>> expression E1, E2;
>> statement S;
>> function f;
>> @@
>> f(...){<...
>> -if ((E1) && (E2))
>> +if (E1 && E2)
>> S
>> ...> }
>>
>> Is that any more sensible?
>
> My example adds '== d'...
>
> $ cat /tmp/test.cocci
> @@
> expression a, b, c, e;
> @@
> -((a == b) && (c != e))
> +a == b && c == d
>
> $ clear;spatch /tmp/test.cocci kernel/locking/lockdep.c
> init_defs_builtins: /usr/local/lib/coccinelle/standard.h
> HANDLING: kernel/locking/lockdep.c
> diff =
> --- kernel/locking/lockdep.c
> +++ /tmp/cocci-output-9601-607267-lockdep.c
> @@ -1420,7 +1420,7 @@ print_shortest_lock_dependencies(struct
> print_stack_trace(&entry->trace, 2);
> printk("\n");
>
> - if (depth == 0 && (entry != root)) {
> + if (depth == 0 && entry == d) {
> printk("lockdep:%s bad path found in chain graph\n", __func__);
> break;
> }
> @@ -2322,7 +2322,7 @@ print_irq_inversion_bug(struct task_stru
> /* Find a middle lock (if one exists) */
> depth = get_lock_depth(other);
> do {
> - if (depth == 0 && (entry != root)) {
> + if (depth == 0 && entry == d) {
> printk("lockdep:%s bad path found in chain graph\n", __func__);
> break;
> }
> @@ -4198,7 +4198,7 @@ retry:
> * if it's not sleeping (or if it's not the current
> * task):
> */
> - if (p->state == TASK_RUNNING && p != current)
> + if (p->state == TASK_RUNNING && p == d)
> continue;
> if (p->lockdep_depth)
> lockdep_print_held_locks(p);
>
> Does this help?
--
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] elision of unneeded parens
2015-10-12 21:54 ` Peter Senna Tschudin
@ 2015-10-13 3:55 ` ron minnich
2015-10-13 5:33 ` Julia Lawall
0 siblings, 1 reply; 7+ messages in thread
From: ron minnich @ 2015-10-13 3:55 UTC (permalink / raw)
To: cocci
Peter, many thinks!
I keep thing, however, that it ought to be possible to do something like
if ((E1) relop (E2))
if (E1 relop E2)
Am I asking too much :-)
ron
On Mon, Oct 12, 2015 at 2:54 PM Peter Senna Tschudin <peter.senna@gmail.com>
wrote:
> _very risky_:
>
> @@
> expression a, b;
> @@
> -(
> \(a == b\|a != b\)
> -)
>
>
> On Mon, Oct 12, 2015 at 11:48 PM, Peter Senna Tschudin
> <peter.senna@gmail.com> wrote:
> > On Mon, Oct 12, 2015 at 11:45 PM, ron minnich <rminnich@gmail.com>
> wrote:
> >> wow, I can't type.
> >>
> >> Let me say it more sensibly, even if wrong :-)
> >> [[[ I know this is wrong, it's kind of "what I want it to do" ]]]
> >>
> >> @@
> >> expression E1, E2;
> >> statement S;
> >> function f;
> >> @@
> >> f(...){<...
> >> -if ((E1) && (E2))
> >> +if (E1 && E2)
> >> S
> >> ...> }
> >>
> >> Is that any more sensible?
> >
> > My example adds '== d'...
> >
> > $ cat /tmp/test.cocci
> > @@
> > expression a, b, c, e;
> > @@
> > -((a == b) && (c != e))
> > +a == b && c == d
> >
> > $ clear;spatch /tmp/test.cocci kernel/locking/lockdep.c
> > init_defs_builtins: /usr/local/lib/coccinelle/standard.h
> > HANDLING: kernel/locking/lockdep.c
> > diff =
> > --- kernel/locking/lockdep.c
> > +++ /tmp/cocci-output-9601-607267-lockdep.c
> > @@ -1420,7 +1420,7 @@ print_shortest_lock_dependencies(struct
> > print_stack_trace(&entry->trace, 2);
> > printk("\n");
> >
> > - if (depth == 0 && (entry != root)) {
> > + if (depth == 0 && entry == d) {
> > printk("lockdep:%s bad path found in chain graph\n", __func__);
> > break;
> > }
> > @@ -2322,7 +2322,7 @@ print_irq_inversion_bug(struct task_stru
> > /* Find a middle lock (if one exists) */
> > depth = get_lock_depth(other);
> > do {
> > - if (depth == 0 && (entry != root)) {
> > + if (depth == 0 && entry == d) {
> > printk("lockdep:%s bad path found in chain graph\n", __func__);
> > break;
> > }
> > @@ -4198,7 +4198,7 @@ retry:
> > * if it's not sleeping (or if it's not the current
> > * task):
> > */
> > - if (p->state == TASK_RUNNING && p != current)
> > + if (p->state == TASK_RUNNING && p == d)
> > continue;
> > if (p->lockdep_depth)
> > lockdep_print_held_locks(p);
> >
> > Does this help?
>
>
>
> --
> Peter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20151013/148dbee2/attachment.html>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Cocci] elision of unneeded parens
2015-10-13 3:55 ` ron minnich
@ 2015-10-13 5:33 ` Julia Lawall
0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2015-10-13 5:33 UTC (permalink / raw)
To: cocci
This seems to work pretty well. Unfortunately, the spacing is not as nice
as one would hope for showing off to someone else.
@@
binary operator op = {==,!=};
expression e1,e2,e3,e4,e5;
@@
(
(e3 || e4)
|
-(
e1 op e2
-)
)
&&
e5
@@
binary operator op = {==,!=};
expression e1,e2,e3,e4,e5;
@@
e5
&&
(
(e3 || e4)
|
-(
e1 op e2
-)
)
-----------------------------------------------------
int main () {
if ((a == b) && (c != d)) return 12;
if ((a == b) && (c != d) && (c == d)) return 12;
if (a == b && (c != d)) return 12;
if (a == b && (c != d) && (c == d)) return 12;
if ((a == b) && c != d) return 12;
if ((a == b) && c != d && (c == d)) return 12;
if ((a == b) && (c != d) && c == d) return 12;
if ((a == b) && c != d && c == d) return 12;
if (a == b && (c != d) && c == d) return 12;
if ((a == b) + c) return 12; // should not change
}
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-10-13 5:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 21:38 [Cocci] elision of unneeded parens ron minnich
2015-10-12 21:43 ` Peter Senna Tschudin
2015-10-12 21:45 ` ron minnich
2015-10-12 21:48 ` Peter Senna Tschudin
2015-10-12 21:54 ` Peter Senna Tschudin
2015-10-13 3:55 ` ron minnich
2015-10-13 5:33 ` Julia Lawall
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.