From: der.herr@hofr.at (Nicholas Mc Guire)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Question about the use of "...when !=" in SmPL
Date: Sat, 9 May 2015 16:09:41 +0200 [thread overview]
Message-ID: <20150509140941.GA13643@opentech.at> (raw)
In-Reply-To: <BAY181-W739E92CD2131317A21ED42B8DF0@phx.gbl>
On Thu, 07 May 2015, ZhouYuan wrote:
your second question regardin if/else was not yet addressed - so here are
some notes on trying to solve this - again this might not be the right
approach - only got it to work by removing the if structure isomorphisms !
<snip>
>
> Also, another example can be witnessed here. I wrote another patch to
> check whether there is an "else" after "if" statement:
>
> @rule534@
> function F;
> position p;
> statement S1, S2;
> @@
> F at p (...){
> if (...) S1
> ...when != else S2
> }
>
> But i also got the same "minus: parse error" at the line of when.
> I would be so appreciated if someone could give me some suggestions about
> what is wrong in my Patch and how to use when correctly.
> Thank you so much!
The problem here I think is the default.iso that does not allow
to distinguish the if and else as you like - if we take a simple
general if match like:
<snip>
@ifelse@
function f;
statement S1, S2;
position p;
@@
f (...){
<...
if@p (...) S1 else S2
...>
}
<snip>
and run
hofrat at debian:/tmp$ spatch --parse-cocci if.cocci
we get:
ifelse:f(...) {
<...
(
(
if at ifelse:p (...) ifelse:S1 else ifelse:S2
|
if at ifelse:p (...) ifelse:S1
)
|
(
if at ifelse:p (...) ifelse:S2 else ifelse:S1
|
if@ifelse:p (...) ifelse:S2
)
)
...>
}
so the standard.iso "if structure isomorphisms" are not allowing you
to differenciate the if and else here. if you copy that file into
"my.iso" and remove those if structure isomorphisms then you can
differenciate if with and without else.
<snip>
@ifonly@
function f;
statement S1;
position p;
@@
f (...){
<...
*if@p (...) S1
...>
}
@script: python depends on ifonly@
p<<ifonly.p;
@@
print "%s %s" % (p[0].file, p[0].line)
<snip>
The test-case is:
#include <stdio.h>
<snip>
int bar(void)
{
int x=2;
if (x) {
printf("2\n");
} else {
printf("!2\n");
}
return 0;
}
int foo(void)
{
int x=2;
if (x) {
printf("2\n");
}
}
<snip>
run this now with the changed iso file
hofrat at debian:/tmp$ spatch --sp-file if.cocci --iso-file my.iso if.c
init_defs_builtins: /usr/local/share/coccinelle/standard.h
HANDLING: if.c
if.c 17
diff =
--- if.c
+++ /tmp/cocci-output-12260-c3738e-if.c
@@ -14,8 +14,5 @@ int bar(void)
int foo(void)
{
int x=2;
- if (x) {
- printf("2\n");
- }
}
thx!
hofrat
next prev parent reply other threads:[~2015-05-09 14:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-07 2:32 [Cocci] Question about the use of "...when !=" in SmPL ZhouYuan
2015-05-09 7:47 ` Nicholas Mc Guire
2015-05-09 8:10 ` [Cocci] Source code analysis around "switch" SF Markus Elfring
2015-05-09 8:28 ` Nicholas Mc Guire
2015-05-09 8:40 ` SF Markus Elfring
2015-05-09 8:36 ` [Cocci] Question about the use of "...when !=" in SmPL Julia Lawall
2015-05-09 10:08 ` Nicholas Mc Guire
2015-05-09 14:09 ` Nicholas Mc Guire [this message]
2015-05-09 16:47 ` Julia Lawall
2015-05-10 7:29 ` [Cocci] Data provided by position variables SF Markus Elfring
2015-05-10 8:40 ` Julia Lawall
2015-05-10 8:47 ` SF Markus Elfring
2015-05-09 16:49 ` [Cocci] Question about the use of "...when !=" in SmPL Nicholas Mc Guire
2015-05-10 7:49 ` [Cocci] Improving small SmPL examples SF Markus Elfring
2015-05-10 12:58 ` [Cocci] Question about the use of "...when !=" in SmPL Julia Lawall
2015-05-10 16:28 ` [Cocci] Fine-tuning for switch statements SF Markus Elfring
2015-05-10 16:31 ` Julia Lawall
2015-05-10 16:34 ` SF Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150509140941.GA13643@opentech.at \
--to=der.herr@hofr.at \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.