On 12/02/2016 10:48 PM, SF Markus Elfring wrote:
>> Why not just define a python function that you can call in a script to do
>> your big regexp for you?
>
> Would any more developers and reviewers like to extend a source code analysis
> approach with a regular expression (or other data structure) like the
> following?
Why would you want to use that?
Just use the regexp directly, e.g.
identifier action1 = "regexp";
I'm using big regexp'es that way. Yes, I do find the perl style compact
regexp easier to read.
And for more specialized stuff I'm passing the identifier through a
python rule for further filtering.
bye
michael
>
> SmPL script example:
>
> @initialize:python@
> @@
> import re
> compiled = re.compile("""^
> (?:
> k(?:
> [cmz]alloc
> | (?:m(?:
> alloc_array
> | em(?:
> _cache_alloc(?:_node)?
> | dup
> )
> )
> | zalloc_node
> )
> | str(?:
> dup(?:_const)?
> | ndup
> )
> )
> | of_find_matching_node
> # Alternation placeholder
> )$""", re.VERBOSE)
>
> def is_selected(id):
> match = compiled.search(id)
> if match:
> return True
> else:
> return False
>
> @find_too_late_checking@
> expression assign1, assign2, ex1, ex2;
> identifier action1: script:python() { is_selected(action1) },
> action2: script:python() { is_selected(action2) },
> work;
> statement is, es;
> type return_type;
> @@
> return_type work(...)
> {
> ... when any
> *ex1 = action1(...);
> ex2 = action2(...);
> ... when any
> when != (ex1 = assign1)
> when != (ex2 = assign2)
> if (
> * \( !(ex1) \| (ex1) == NULL \)
> || \( !(ex2) \| (ex2) == NULL \)
> || ...)
> is
> else
> es
> ... when any
> }
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci