From: Markus Elfring <Markus.Elfring@web.de>
To: "Christian A. Ehrhardt" <lk@c--e.de>, cocci@inria.fr
Subject: Re: [cocci] Replacing cast in nested initializers
Date: Thu, 23 Jan 2025 14:26:01 +0100 [thread overview]
Message-ID: <1974acbf-e116-4c6c-8402-e0a5786f81a5@web.de> (raw)
In-Reply-To: <Z4re766p6mujr7h4@cae.in-ulm.de>
> I am trying to replace casts in nested struct initialisers.
> My patch attempt looks like this:
>
> @@
> identifier __type;
> identifier __name;
> expression __data;
> @@
>
> | struct __type __name[...] = {
> | ...,
> | {
> | ...,
> | - (del_t)
> | + (add_t)
> | &__data
> | ,...
> | }
> | ,...
> | };
>
> Running this on this .c file
>
> | struct foo foos[] = {
> | { (del_t)&x1 },
> | { (del_t)0 },
> | { (del_t)&x2 }
> | };
I find your usage of pipe characters confusing here.
> I would expect the first and the third cast (in front of "&x1" and "&x2)
> to be replaced.
>
> However, only the first cast (in front of "&x1") is replaced and
> I get a warning the del_t might have to be meta variable. If I add
>
> | typedef del_t;
>
> to the patch only the last cast (in front of "&x2") is replaced.
>
> What am I doing wrong?
I suggest to take another look at applications of SmPL dot variants.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/8aa44ca0ff45be70f124802696ea58c75843e2a9/docs/manual/cocci_syntax.tex#L793
Will you get further development ideas from additional information
for the semantic patch language like the following?
@casting@
identifier my_name, my_type;
expression data;
@@
struct my_type my_name[...]
=
{
...,
<+...
{
...,
(
-del_t
+add_t
)
&data
, ...
}
,
...+>
};
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci suggestion_for_Christian_Ehrhardt.cocci
…
minus: parse error:
File "suggestion_for_Christian_Ehrhardt.cocci", line 14, column 1, charpos = 291
around = '{',
whole content = {
Regards,
Markus
prev parent reply other threads:[~2025-01-23 13:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-17 22:51 [cocci] Replacing cast in nested initializers Christian A. Ehrhardt
2025-01-23 13:26 ` Markus Elfring [this message]
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=1974acbf-e116-4c6c-8402-e0a5786f81a5@web.de \
--to=markus.elfring@web.de \
--cc=cocci@inria.fr \
--cc=lk@c--e.de \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).