Discussion:
[Cocci] please help me with a "repetition"
Robert Larice
2018-04-29 11:00:40 UTC
Permalink
Hello,

probably a stupid question,
I'm failing to match something like this

+ int newvar;
i++; i++; ... any sequence of only "i++";
+ buckbear(42);

I don't succeed to express this "maximum length repetition"
in the mids of those two insertions.

Best Regards,
Robert
Julia Lawall
2018-04-29 11:32:18 UTC
Permalink
Post by Robert Larice
Hello,
probably a stupid question,
I'm failing to match something like this
+ int newvar;
i++; i++; ... any sequence of only "i++";
+ buckbear(42);
I don't succeed to express this "maximum length repetition"
in the mids of those two insertions.
It's not completely straightforward. You could try:

@r1@
position p;
@@

i++;
i++;@p

@@
position p != r1.p;
@@

+ int newvar;
i++;@p

@r2@
position p;
@@

i++;@p
i++;

@@
position p != r2.p;
@@

i++;@p
+ buckbear(42);

julia
Post by Robert Larice
Best Regards,
Robert
_______________________________________________
Cocci mailing list
https://systeme.lip6.fr/mailman/listinfo/cocci
Robert Larice
2018-04-29 12:54:17 UTC
Permalink
Post by Julia Lawall
Post by Robert Larice
Hello,
probably a stupid question,
I'm failing to match something like this
+ int newvar;
i++; i++; ... any sequence of only "i++";
+ buckbear(42);
I don't succeed to express this "maximum length repetition"
in the mids of those two insertions.
@r1@
position p;
@@
...
Thank You very much,

your suggestion works perfectly well in my actual task.

I was trying something different,
very aproximately something like:
... when != i++;
+ int newvar;
i++;
and didn't get anywhere.

Thanks !
Robert
Julia Lawall
2018-04-29 13:15:25 UTC
Permalink
Post by Robert Larice
Post by Julia Lawall
Post by Robert Larice
Hello,
probably a stupid question,
I'm failing to match something like this
+ int newvar;
i++; i++; ... any sequence of only "i++";
+ buckbear(42);
I don't succeed to express this "maximum length repetition"
in the mids of those two insertions.
@r1@
position p;
@@
...
Thank You very much,
your suggestion works perfectly well in my actual task.
I was trying something different,
... when != i++;
+ int newvar;
i++;
and didn't get anywhere.
This should work for the first bunch of i++;'s, but not if there are
several of them.

julia

Loading...