Coccinelle archive on lore.kernel.org
 help / Atom feed
* [Cocci] Can I pass a variable from a Python script in one rule to another rule in the same .cocci file?
@ 2019-01-04 21:57 Timur Tabi
  2019-01-05  6:25 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Timur Tabi @ 2019-01-04 21:57 UTC (permalink / raw)
  To: cocci

In one rule, I have some Python code that parses a string literal to
see what it looks like.  If I detect a specific pattern, then I want
another rule (that has no Python code) to act differently.

More specifically, if a string literal passed as a parameter to
DBG_PRINTF() starts with "NVRM: ", then I want my script to replace
DBG_PRINTF with NV_PRINTF.  This works today.

If the string does not begin with "NVRM:", however, then I want
DBG_PRINTF changed to NV_PRINTF_EX instead.

If this can't work, an alternative would be to create a second script
that handles DBG_PRINTF to NV_PRINTF_EX.  However, it would need to
abort the change if the Python script detects that NVRM: doesn't
exist.  So is there a way for Python to return a value that says,
"Woah, stop and undo everything you just did!"
_______________________________________________
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] Can I pass a variable from a Python script in one rule to another rule in the same .cocci file?
  2019-01-04 21:57 [Cocci] Can I pass a variable from a Python script in one rule to another rule in the same .cocci file? Timur Tabi
@ 2019-01-05  6:25 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2019-01-05  6:25 UTC (permalink / raw)
  To: Timur Tabi; +Cc: cocci



On Fri, 4 Jan 2019, Timur Tabi wrote:

> In one rule, I have some Python code that parses a string literal to
> see what it looks like.  If I detect a specific pattern, then I want
> another rule (that has no Python code) to act differently.
>
> More specifically, if a string literal passed as a parameter to
> DBG_PRINTF() starts with "NVRM: ", then I want my script to replace
> DBG_PRINTF with NV_PRINTF.  This works today.
>
> If the string does not begin with "NVRM:", however, then I want
> DBG_PRINTF changed to NV_PRINTF_EX instead.
>
> If this can't work, an alternative would be to create a second script
> that handles DBG_PRINTF to NV_PRINTF_EX.  However, it would need to
> abort the change if the Python script detects that NVRM: doesn't
> exist.  So is there a way for Python to return a value that says,
> "Woah, stop and undo everything you just did!"

I think that you want to use cocci.include_match(False)

In your python script, make the checks that you want, and then if you are
not satisfied with the results, use cocci.include_match(False) to get the
curent match of the metavariables to disappear.  You may need to rematch
something to get the information needed for the second change option.

julia

> _______________________________________________
> 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, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-04 21:57 [Cocci] Can I pass a variable from a Python script in one rule to another rule in the same .cocci file? Timur Tabi
2019-01-05  6:25 ` Julia Lawall

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox