On Mon, 27 May 2019, Christoph Böhmwalder wrote:

> Hi,
>
> I'm having trouble understanding coccinelles behaviour here. Consider the
> following C code and cocci rules:
>
>
> #include <stdio.h>
>
> int x;
>
> int main(int argc, char **argv)
> {
>     f(x);
> }
>
>
> @@
> identifier x;
> @@
> - int x;
> + int *x;
>
> @@
> int *x;
> @@
> - f(x)
> + g(x)
>
>
>
> Since I read on some slides[0] that "Later rules see the results of earlier
> rules", I would assume that this would pick up the type change introduced by
> the first rule and replace f by g because it now has an "int *" parameter.
> However, spatch merely outputs the patch to change the type of x. If I change
> the type of the "expected" x in rule 2 to "int", cocci picks it up correctly.
>
> Am I missing something?

Your first rule changes only variable declarations, which consist of a
type, a variable and a semicolon.  If you want to change all int types to
int *, then you can change the first rule to remove the x and the ;.  If
you want to change int x in the parameter list of main, or in the
parameter list of all functions, then you could do

@@
identifier f; // all functions
identifier x;
@@

f(...,
- int x
+ int *x
  ,...) { ... }

You can factor out the common parts, ie int and x from the transformation,
as Markus suggests, but I doubt this would be useful.

julia

>
>
> [0]: http://events17.linuxfoundation.org/sites/events/files/slides/part1.pdf,
> page 43
>
> --
> Regards,
> Christoph
> _______________________________________________
> Cocci mailing list
> [email protected]
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to