On Tue, 4 Dec 2018, Timur Tabi wrote:
> I have some rules and Python code that removes __FUNCTION__ as a
> parameter in a call to a function. That all works great. I now want
> it to remove __func__ in exactly the same way. So I copy/pasted my
> rules and just changed __FUNCTION__ to __func__, but spatch complains:
>
> warning: line 202: should __func__ be a metavariable?
> warning: line 218: should __func__ be a metavariable?
> warning: line 229: should __func__ be a metavariable?
>
> I don't even know what this means. Here is one rule that fails:
>
> // Look for NV_PRINTF2 calls that have __func__ as the first parameter
> @r2b depends on rules@
> constant char[] c;
> expression x;
> @@
> NV_PRINTF2(x, c, __func__, ...)
Typically function names and field names might be metavariables or might
be specific desired names, so there is no check for them. On the other
hand, other kinds of expressions are often represented as metavariables,
and a common mistake is to forget to declare one of them. So Coccinelle
gives a warning if such a thing is not declared as a metavariable. You
can silence the warning by adding the metavariable declaration
symbol __func__;
which means to match that thing explicitly. Once you do that in one rule,
it applies thereafter.
julia
>
> // Get rid of __func__ at the beginning of the string
> @script:python s2b@
> c << r2b.c;
> c2;
> @@
> import re
> coccinelle.c2 = re.sub('%s[: ]*', '', c, 1)
>
> @depends on rules@
> expression x;
> constant char[] r2b.c;
> identifier s2b.c2;
> @@
> NV_PRINTF2(x,
> -c, __func__
> +c2
> ,...);
> _______________________________________________
> Cocci mailing list
> [email protected]
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci