I'm not sure if what I'm writing down above is already making you dizzy, but
there is more.
You can see an abstract rule as some form of "let" abstraction: let this meta
variable stand for a more complex pattern.
Here I've got a pattern where "e" stands for an integer expression that must be the addition of two other
integer expressions. We give the instantiation of the abstract rule an explicit name "r" and can then inherit
from it to get access to some of the meta variables "a" and "b" that it matches:
@@
int e = rule add as r;
int r.a;
int r.b;
@@
- f(e)
+ (a - b)
In the near future, you will be able to use the name of a rule as a
metavariable that matches the whole thing that that rule matched. This
seems to be the same as what is expressed here, but with a simpler syntax:
@r@
int a,b;
@@
a+b
@@
expression r.r;
int r.a,r.b;
@@
- f(r)
+ f(a)
In this case, though, I think that splitting the pattern into two rules is
a really bad idea. But there are probably cases where it is useful - my
main motivation was eg to be able to move function definitions around.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)