cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] replacing defines
@ 2018-12-12 12:17 Max
  2018-12-12 12:26 ` Julia Lawall
  0 siblings, 1 reply; 11+ messages in thread
From: Max @ 2018-12-12 12:17 UTC (permalink / raw)
  To: cocci

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-12-18 16:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 12:17 [Cocci] replacing defines Max
2018-12-12 12:26 ` 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

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).