--- Please note the new email address ---


On Thu, 2 Jan 2020, David Young wrote:

> I have a semantic patch that renames parameters and local variables
> called `index` to `idx`.  It renames most occurrences, however,
> it does not know how to handle a macro that expands to a block:
>
> #define HGOTO_ERROR(maj, min, ret_val, ...) {                           \
>    do_something(maj, min, __VA_ARGS__);                                 \
>    ret_value = ret_val;                                                       
> \
>    goto done;                                                         \
> }
>
> I'd like for every occurrence of `index` in the HGOTO_ERROR() arguments
> to change to `idx`, HGOTO_ERROR(..., index, ...) -> HGOTO_ERROR(..., idx, 
> ...),
> but spatch leaves those occurrences alone.
>
> Can I write an isomorphism or something to force spatch to process each
> occurrence of HGOTO_ERROR(...) as if it was either the function call
> `hgoto_error(...);` or the block `{ (void)(...); goto done; }` ?

I think that the problem is that there is no ; in the uses of your macro.
So Coccinelle knows that it is some strange code, and it refuses to change
it.  If you run spatch --parse-c on a file that uses the macro, you will
see something able the code being passed.

The proper way to write such a macro, independent of Coccinelle, is as a
while do(0) loop, so that the uses can end in a semicolon.  Then there is
no possibility of strange mistakes if someone actually does put a
semicolon.  Would that be feasible to do?

julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to