On Mon, 13 Jan 2020, Timur Tabi wrote:

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

Sorry, I don't follow what you are trying to do here.  Could you send an
example of the desired before after C code?  I see what you have above,
but I don't see the connection to the rule you have tried to write.

I have the feeling that you will want to use some python code to do
something with the ##s, but I'm not sure.

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to