* [Cocci] logical not
@ 2015-07-15 13:29 Kris Borer
2015-07-15 14:17 ` Julia Lawall
0 siblings, 1 reply; 3+ messages in thread
From: Kris Borer @ 2015-07-15 13:29 UTC (permalink / raw)
To: cocci
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150715/3ddb3bd5/attachment.html>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] logical not
2015-07-15 13:29 [Cocci] logical not Kris Borer
@ 2015-07-15 14:17 ` Julia Lawall
2015-07-15 17:42 ` Kris Borer
0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2015-07-15 14:17 UTC (permalink / raw)
To: cocci
> @@
> identifier i;
> expression E;
> statement S;
> @@
>
> + i = E;
> ? if (
> ? !
> - (i = E)
> + i
> ? ) S
Try this one without the ! and with S converted to
S1 else S2
with S1 and S2 being statement metavariables. I think that the various
isoorphisms should cause this to do everything. But you can check it by
running spatch --parse-cocci file.cocci. for this, it is more readable if
you give your rule a short name, like r, because it will put the name of
the rule in each metavariable that it prints, and the defaut is quite
long.
julia
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] logical not
2015-07-15 14:17 ` Julia Lawall
@ 2015-07-15 17:42 ` Kris Borer
0 siblings, 0 replies; 3+ messages in thread
From: Kris Borer @ 2015-07-15 17:42 UTC (permalink / raw)
To: cocci
Thank you, this approach works for me. I will look more into isomorphisms.
On Wed, Jul 15, 2015 at 10:17 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> > @@
> > identifier i;
> > expression E;
> > statement S;
> > @@
> >
> > + i = E;
> > if (
> > !
> > - (i = E)
> > + i
> > ) S
>
> Try this one without the ! and with S converted to
>
> S1 else S2
>
> with S1 and S2 being statement metavariables. I think that the various
> isoorphisms should cause this to do everything. But you can check it by
> running spatch --parse-cocci file.cocci. for this, it is more readable if
> you give your rule a short name, like r, because it will put the name of
> the rule in each metavariable that it prints, and the defaut is quite
> long.
>
> julia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20150715/a7758e90/attachment-0001.html>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-15 17:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15 13:29 [Cocci] logical not Kris Borer
2015-07-15 14:17 ` Julia Lawall
2015-07-15 17:42 ` Kris Borer
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.