Re: [cocci] Search for the concatenation of meta variable + fixed string

Tobias Deiminger <[email protected]>
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
Hi,

(copy for list, sorry for again messing up To:)

Am 04.12.2025 08:54 schrieb Markus Elfring:
>> Found a workaround using fresh identifier to add an intermediate 
>> helper construct:
> 
> Please reconsider your solution approach once more.
> 
> 
>> @device_attr_ro@
>> declarer name DEVICE_ATTR_RO;
>> typedef __DEVICE_ATTR_RO_T;
>> identifier attr_name;
>> fresh identifier show_fn_name = attr_name ## "_show";
>> @@
>>   DEVICE_ATTR_RO(attr_name);
>> + __DEVICE_ATTR_RO_T attr_name = show_fn_name;
> 
> Would you really like to modify source code here?

No. It's a temporary modification as workaround. I'm using 
--no-show-diff, and don't replace inline.

> Are you more interested in an “ordinary” source code search?

Correct, it's only about searching. But not "ordinary". If there's 
another OSS tool that could do semantic code search, can deal with C 
macros and supports "hops" like first search marro, then search 
definition of function referenced by macro please tell me. Coccinelle is 
the only tool capable enough I currently know.

>> Seems to work good enough. If there are cleaner ways, let me know.
> 
> I suggest to take another look

I took reasonable amount of looks and found no better way than this [1]. 
That's why I'm posting here and hope to receive SmPL snippets that 
demonstrate a more idiomatic less complex way.

> at algorithmic properties.

The linux tree was searched in 44 s locally, which is fine for me.

> Would you need to extract identifiers from selected macro calls?

Yes, I print functions names and positions in python scripts. The 
result, verified with samples, looks complete [2].

Tobias

[1] https://github.com/haxtibal/linux/blob/tdmg/cocci/cocci/sysfs.cocci
[2] 
https://github.com/haxtibal/linux/actions/runs/19922697880/job/57114762347#step:4:512
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.