cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Concatenating parameters into a string
@ 2020-01-13 22:21 Timur Tabi
  2020-01-13 22:33 ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2020-01-13 22:21 UTC (permalink / raw)
  To: cocci

I don't know how to properly describe what I'm trying to do, so I'll
just show an example.

The code I'm working on has dozens of annoying macros that concatenate
parameters into strings.  For example,

#define DRF_DEF(d,r,f,c)  \
       (((NvU32)(NV ## d ## r ## f ## c))<<DRF_SHIFT(NV ## d ## r ## f))

So given DRF_DEF(one, two, three, four), it will generated:

(((NvU32)(NV_one_two_three_four))<<DRF_SHIFT(NV_one_two_three))

I'm trying to create a cocci rule that will replace all of these
macros with their expanded equivalents, but I don't know how to handle
the ## feature of macros.  So far I have this:

@@
expression d, r, f, n, v;
@@
-FLD_SET_DRF_NUM(d, r, f, n, v)
+((v) & ~DRF_SHIFTMASK(NV d r f)) | DRF_NUM(d, r, f, n)

But this gives an error because "NV d r f" is not valid C.
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2020-01-14  7:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 22:21 [Cocci] Concatenating parameters into a string Timur Tabi
2020-01-13 22:33 ` Julia Lawall
2020-01-13 22:46   ` Timur Tabi
2020-01-13 23:04     ` Julia Lawall
2020-01-14  0:01       ` Timur Tabi
2020-01-14  7:16         ` Julia Lawall

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