[Cocci] Change function invocations argument

Julia Lawall julia.lawall at lip6.fr
Sat Dec 20 21:32:59 CET 2014

On Sat, 20 Dec 2014, Eliseo Martínez wrote:

> Hi, 
> For a given function, I want to change all invocations in this way:
> Turn the second argument of the form “(long_u)(expression)” into “(uintmax_t)expression”.
> I’ve done a patch for that but is failing with a not very much informative message error.
> Here is it:
> ```
> eliseo at ubuntu:~/projects/os/neovim/neovim$ cat sample.cocci 
> @@ expression e1, e2, e3; @@
>   put_bytes(
>     e1,
> -   (long_u)(e2),
> +   (uintmax_t)e2,
>     e3)

long_u and uintmax_t are not part of the C language, and Coccinelle is not 
always able to infer typedefs.  Just add:

typedef long_u, uintmax_t;

in your metavariable list.  This should only be done in the first rule in 
which the typename is relevant.


More information about the Cocci mailing list