[cocci] Search for the concatenation of meta variable + fixed string (similar fresh identifier)

Tobias Deiminger <[email protected]>
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
Hello again :)

In Linux, the DEVICE_ATTR_RO macro works like this:

static ssize_t led_status_show(struct device *dev, struct 
device_attribute *attr, char *buf) { /* ... */ }

// The macro automatically concatenates led_status + _show for struct 
initialization.
static DEVICE_ATTR_RO(led_status);


I'd like to find the position of all functions assigned by 
DEVICE_ATTR_RO. So I thought to use a 1st rule to search for the 
identifier inside DEVICE_ATTR_RO, then use a 2nd rule to search for the 
inherited meta variable, concatenated with the fixed string "_show". 
Like:

@device_attr_ro@
declarer name DEVICE_ATTR_RO;
identifier attr_name;
@@
   DEVICE_ATTR_RO(attr_name);

@device_attr_ro_show_fn@
identifier device_attr_ro.attr_name;
position p_fn;
@@
   attr_name ## "_show" @ p_fn (...) {...}     // invalid syntax, but you 
get the point


This doesn't work and I couldn't figure how to do it correctly. There's 
"fresh identifier" which looks close, but it only works for +, not for 
search context. Is such a search possible? How?

Tobias
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.