cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Need help with Python again
@ 2018-10-11 22:27 Timur Tabi
  2018-10-11 22:33 ` Timur Tabi
  2018-10-12  1:05 ` Julia Lawall
  0 siblings, 2 replies; 4+ messages in thread
From: Timur Tabi @ 2018-10-11 22:27 UTC (permalink / raw)
  To: cocci

I'm trying to write a rule that will remove __FUNCTION__ from
printf-like statements.  That is:

NV_PRINTF(x, "%s: ...", __FUNCTION__, ...)

into

NV_PRINTF(x, "...", ...)

I have this, which is based on existing Python code that works, but I
can't even get it to compile:

@script:python s@
c << r.c;
c2;
@@
import re

print c, c.find('%s')
coccinelle.c2 = c

// Get rid of __FUNCTION__@the beginning of the string
@@
expression list[r.n] r.es;
constant char[] r.c;
identifier s.c2;
@@
NV_PRINTF(es,
-c, __FUNCTION__
+c2
,...);

This produces:

23 24
Fatal error: exception Failure("scriptmeta: parse error: \n = File
\"/home/ttabi/nv_printf2.cocci\", line 2, column 5,  charpos = 23\n
around = 'r', whole content = c << r.c;\n")

Besides whatever is wrong with the script, I'm confused as to how
spatch knows to invoke the Python script in the first place.  What is
it about my unnamed rule that tells spatch to invoke the script?

Also, why is the first parameter (es) an expression list?  Can't I
just use "expression x;" instead?

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-11 22:27 [Cocci] Need help with Python again Timur Tabi
2018-10-11 22:33 ` Timur Tabi
2018-10-12  1:03   ` Julia Lawall
2018-10-12  1:05 ` 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).