From: Julia Lawall <julia.lawall@inria.fr>
To: David Young <dyoung@netbsd.org>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] transforming arguments to statement macros?
Date: Fri, 3 Jan 2020 07:32:09 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.21.2001030727330.2980@hadrien> (raw)
In-Reply-To: <20200102220345.GF17258@pobox.com>
--- 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
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-01-03 6:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-02 22:03 [Cocci] transforming arguments to statement macros? David Young
2020-01-03 6:32 ` Julia Lawall [this message]
2020-01-03 16:03 ` David Young
2020-01-05 9:47 ` Markus Elfring
2020-01-05 10:05 ` Julia Lawall
2020-01-05 11:32 ` Markus Elfring
2020-01-05 13:54 ` Markus Elfring
2020-01-06 12:07 ` [Cocci] Adding semicolons after macro calls Markus Elfring
2020-01-06 12:20 ` Julia Lawall
2020-01-06 12:48 ` [Cocci] Improving support for data processing around " Markus Elfring
2020-01-08 22:05 ` [Cocci] transforming arguments to statement macros? Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.21.2001030727330.2980@hadrien \
--to=julia.lawall@inria.fr \
--cc=cocci@systeme.lip6.fr \
--cc=dyoung@netbsd.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).