Re: [cocci] Adjusting attributes for variables with SmPL?
Pierrick Philippe <[email protected]> Thu, 28 May 2026 09:09:45 +0200
| Newsgroups | fr.inria.cocci |
|---|---|
| Message-ID | <[email protected]> |
On 5/27/26 13:11, Markus Elfring wrote:
>> I haven't tried this, though. Another more complex solution involves
>> passing through python code. You can get inspiration from
>> demos/pythontococci.cocci. You would want to set eg coccinelle.z to a
>> string that additionally contains the desired string quotes.
> Would you find a data processing approach (like the following) “appropriate”?
>
> @searching@
> expression E1, E2;
> identifier F, X;
> initialiser I;
> type T;
> @@
> T F = I;
> ...
> memcmp(&F.X, E1, E2)
>
> @script:python generation@
> f << searching.F;
> x << searching.X;
> content;
> @@
> coccinelle.content = cocci.make_ident("__attribute__((myattr(\"" + x + "\"))) " + f)
>
> @replacement@
> expression searching.E1, searching.E2;
> identifier searching.F, searching.X, generation.content;
> initialiser searching.I;
> type searching.T;
> @@
> T
> -F
> +content
> = I;
> ...
> memcmp(&F.X, E1, E2)
This one is clearly working and the output is as expected, thanks.
I tried writing one on my own but didn't manage to write a working
semantic patch.
Thanks a lot :)
Pierrick
> Regards,
> Markus