Re: [cocci] Adjusting attributes for variables with SmPL?

Pierrick Philippe <[email protected]> Thu, 28 May 2026 10:12:11 +0200
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
On 5/28/26 09:48, Julia Lawall wrote:
>
> On Thu, 28 May 2026, Pierrick Philippe wrote:
>
>> 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)
> You don't have to put the whole thing in content.  Content could just make
> the string, and then the replacement rule could have built the rest.
I have tried it, and spatch was complaining for some reason.
Though it might be to my lack of experience with SmPL.
I can provide the output if needed.

Pierrick

>
> julia
>
>>> @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
> >