From: johannes@sipsolutions.net (Johannes Berg)
To: cocci@systeme.lip6.fr
Subject: [Cocci] modifying initializers with spatch?
Date: Fri, 27 Jan 2017 22:43:57 +0100 [thread overview]
Message-ID: <1485553437.14579.4.camel@sipsolutions.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1701261655450.3109@hadrien>
> > To get rid of all the initializers, but (as I'm still on the phone)
> > I haven't tried it yet :)
> >
>
> Put a when any above the T x = line.
>
> On the other hand, ++ makes no guarantee about the order in which
> things are generated.
>
> To ensure the order, put the when any above the T x line, and drop
> the one below and run multiple times.??Then each run will work on the
> last one and put it first, so they will come out in order.
Finally got a chance to try this.
I can't seem to get the ordering right. I'm trying this:
@@
type T;
expression E;
statement S1, S2;
identifier x;
identifier f;
@@
?{
... when != { ... }
????when any
?T x = {
-??.f = E,
?};
... when != S1
+ x.f = E;
?S2
?...
?}
on a very simple file:
int main()
{
struct foo bar = {
.y = 8,
.x = 7,
};
printf("%d\n", bar.x);
printf("%d\n", bar.y);
}
but it doesn't end well:
$ spatch??--sp-file /tmp/init.spatch /tmp/test.c
init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: /tmp/test.c
?????
previous modification:
? <<< x.f = E;
CONTEXT
According to environment 3:
???rule starting on line 1.E -> 8
???rule starting on line 1.f -> id y
???rule starting on line 1.x -> id bar
current modification:
? <<< x.f = E;
CONTEXT
According to environment 3:
???rule starting on line 1.E -> 7
???rule starting on line 1.f -> id x
???rule starting on line 1.x -> id bar
Fatal error: exception Failure("rule starting on line 1: already tagged
token:\nC code context\nFile \"/tmp/test.c\", line 8, column
1,??charpos = 59\n????around = 'printf', whole content =
\tprintf(\"%d\\n\", bar.x);")
If I use ++ instead of +, it still replaces all of them, so I can't run
multiple times (usefully anyway)
OTOH, I haven't found any place where the order actually matters (in
the code base I'm interested in), and although it seems that it
theoretically could matter, I'm not sure I really need to solve that
problem - although I'm thinking I might want to run this not just once
but before each compile, to keep the code neater.
(Note that I also haven't upgraded to the git version yet, TBD)
johannes
next prev parent reply other threads:[~2017-01-27 21:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-26 12:28 [Cocci] modifying initializers with spatch? Johannes Berg
2017-01-26 13:17 ` Julia Lawall
2017-01-26 13:32 ` Johannes Berg
2017-01-26 14:20 ` Julia Lawall
2017-01-26 14:28 ` Johannes Berg
2017-01-26 15:47 ` Julia Lawall
2017-01-26 15:52 ` Johannes Berg
2017-01-26 15:57 ` Julia Lawall
2017-01-27 21:43 ` Johannes Berg [this message]
2017-01-27 21:52 ` Julia Lawall
2017-01-27 22:03 ` Johannes Berg
2017-01-27 22:09 ` Julia Lawall
2017-01-27 22:23 ` Johannes Berg
2017-01-27 23:02 ` Johannes Berg
2017-01-27 23:20 ` Johannes Berg
2017-01-28 6:47 ` Julia Lawall
2017-01-28 8:20 ` Johannes Berg
2017-01-27 7:09 ` Julia Lawall
2017-01-27 8:55 ` Johannes Berg
2017-01-27 13:11 ` Julia Lawall
2017-01-27 16:13 ` Johannes Berg
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=1485553437.14579.4.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox