It will just use all possible bindings of all variables, and execute the code
once for each permutation, with no consideration of where the bindings come
from.
I'm not sure that you will consider that to be a desirable result. If you want
something else, you should do your code factorization by defining a function in
the @initialize:python@ rule.
I have written the following draft for a source code filter pattern.
@initialize:python@
result = []
delimiter = '|'
@function_declaration@
type t;
identifier f;
position p;
@@
t@p f(...);
@function_definition@
type t;
identifier f;
position p;
@@
t@p f(...)
{
...
}
@is_void_declared@
identifier function_declaration.f;
@@
void f(...);
@is_void_defined@
identifier function_definition.f;
@@
void f(...)
{
...
}
@script:python collection1 depends on !(is_void_declared || is_void_defined)@
typ << function_declaration.t;
fun << function_declaration.f;
places << function_declaration.p;
@@
for place in places:
fields = []
fields.append(fun.ident)
fields.append(typ)
fields.append("declaration")
fields.append(place.file)
fields.append(place.line)
fields.append(str(int(place.column) + 1))
result.append(delimiter.join(fields))
@script:python collection2 depends on !(is_void_declared || is_void_defined)@
typ << function_definition.t;
fun << function_definition.f;
places << function_definition.p;
@@
for place in places:
fields = []
fields.append(fun.ident)
fields.append(typ)
fields.append("definition")
fields.append(place.file)
fields.append(place.line)
fields.append(str(int(place.column) + 1))
result.append(delimiter.join(fields))
@finalize:python@
if result:
result.insert(0, delimiter.join(("function", '"return type"', "action",
'"source file"', "line", "column")))
print("\r\n".join(result))
else:
print("No result for this analysis!")
Would you like to give any further advices for my difficulty with an usable name
selection for the metavariables in the script rules of this test case?
Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)