cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Max <msuraev@sysmocom.de>
To: cocci@systeme.lip6.fr
Subject: [Cocci] replacing defines
Date: Wed, 12 Dec 2018 13:17:33 +0100	[thread overview]
Message-ID: <a752b0e8-8ed0-1e86-eff7-3d91e87b11ae@sysmocom.de> (raw)

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;
identifier a, b, c;
@@
- 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

             reply	other threads:[~2018-12-12 12:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12 12:17 Max [this message]
2018-12-12 12:26 ` [Cocci] replacing defines Julia Lawall
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=a752b0e8-8ed0-1e86-eff7-3d91e87b11ae@sysmocom.de \
    --to=msuraev@sysmocom.de \
    --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;
as well as URLs for NNTP newsgroup(s).