cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] warning: line 202: should __func__ be a metavariable?
@ 2018-12-04 22:56 Timur Tabi
  2018-12-05  6:56 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Timur Tabi @ 2018-12-04 22:56 UTC (permalink / raw)
  To: cocci

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

// 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
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] warning: line 202: should __func__ be a metavariable?
  2018-12-04 22:56 [Cocci] warning: line 202: should __func__ be a metavariable? Timur Tabi
@ 2018-12-05  6:56 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2018-12-05  6:56 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci



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
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2018-12-05  6:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-04 22:56 [Cocci] warning: line 202: should __func__ be a metavariable? Timur Tabi
2018-12-05  6:56 ` 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).