From: Julia Lawall <julia.lawall@lip6.fr>
To: Max <msuraev@sysmocom.de>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] replacing defines
Date: Wed, 12 Dec 2018 13:26:09 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1812121322240.4125@hadrien> (raw)
In-Reply-To: <a752b0e8-8ed0-1e86-eff7-3d91e87b11ae@sysmocom.de>
[-- Attachment #1: Type: text/plain, Size: 2874 bytes --]
On Wed, 12 Dec 2018, Max wrote:
> Hi.
>
> I've problem replacing parameterized #define using spatch.
>
> For example, in test.c I have following defines:
>
> ...
>
> #define old_junk(a, b, c) if (c) \
>
> printf(a); \
>
> else \
>
> { printf(b); }
>
> #define new_stuff(a, b, b) my_func(a, b, c)
>
> I would like to replace all the entries of old_junk(x, y, z); with
> new_stuff(x, y, z);
>
> I've tried following spatch:
>
> @@
> identifier old_junk, new_stuff, abort;
You have declared new_stuff and abort as metavariables, meaning that
Coccinelle has to figure out what they should be. But it has no way of
figuring that out in this case. I think that you can just drop the above
line completely, since you say you really want to replace a call to
old_junk by a call to new_stuff. If you wanted to replace all calls to
three argument functions by a call to new_stuff, then you would want
old_junk to be a metavariable, but that is probably not useful.
> identifier a, b, c;
Are you sure that a b and c will only match identifiers, like x. If they
may match expressions, like 2 + 3, then you would want expression in these
cases.
Actually, the fact that old_junk and new_stuff are defined as macros is
irrelevant for this rule. Coccinelle will just look at the calls. It
doesn't expland macros, so it doesn't know whether the call is to a macr
or to a function.
julia
> @@
> - old_junk(a, b, c);
> + if (new_stuff(a, b, c))
>
> + abort();
>
> Which used as "spatch --in-place --sp-file my.spatch tests/test.c"
>
> Unfortunately all I got is "metavariable new_stuff not used in the - or
> context code".
>
> I've tried using "function new_stuff" instead and got another failure:
> "MetaFunc, need more semantic info about id".
>
> Which is the right way to make this sort of replacements?
>
> I'd be happy to get points to the docs which clarify this part as I was
> unable to find anything relevant on
> http://coccinelle.lip6.fr/documentation.php
>
> I went over tutorial slides as well and it feels like I'm missing
> something obvious in here.
>
> I'm using spatch 1.0.4 in latest ubuntu.
>
> --
> - Max Suraev <msuraev@sysmocom.de> http://www.sysmocom.de/
> =======================================================================
> * sysmocom - systems for mobile communications GmbH
> * Alt-Moabit 93
> * 10559 Berlin, Germany
> * Sitz / Registered office: Berlin, HRB 134158 B
> * Geschaeftsfuehrer / Managing Directors: Harald Welte
>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2018-12-12 12:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-12 12:17 [Cocci] replacing defines Max
2018-12-12 12:26 ` Julia Lawall [this message]
2018-12-12 18:00 ` Max
[not found] ` <alpine.DEB.2.21.1812130723160.2458@hadrien>
2018-12-13 16:16 ` Max
2018-12-13 19:56 ` Julia Lawall
2018-12-14 11:31 ` Max
2018-12-18 15:25 ` Max
2018-12-18 15:34 ` Julia Lawall
2018-12-18 15:48 ` Max
2018-12-18 16:10 ` Julia Lawall
2018-12-18 16:26 ` Max
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=alpine.DEB.2.20.1812121322240.4125@hadrien \
--to=julia.lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=msuraev@sysmocom.de \
/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;
as well as URLs for NNTP newsgroup(s).