[Cocci] Problem when using a macro for mangling function names
ali-erdem.ozcan at st.com
Fri Mar 20 19:37:16 CET 2009
Julia Lawall wrote:
>> So if my understanding is good, spatch doesn't really expand the macros, it
>> only extends the parsing rules to take them into account. Am I right ?
> This is correct.
>>> I will try to find a way to solve the problem. Is this pattern very common
>>> in the code you are working with?
>> Unfortunately yes. This is something that we cannot get rid of.
>> Moreover, another pattern which is very common is
>> #define METHOD(foo, bar) componentName_##foo##_##bar
>> I think this may raise other problems since
>> 1. void METHOD(foor,bar)(params) is not valid C code as opposed to void
>> METH(foo)(params) - as highlighted by Yoann.
> It doesn't matter. This is fine as long as there is no metavariable that
> matches the call to METHOD.
>> 2. if the macro expansion semantics is not took into account (hypothesis that
>> might be wrong depending on the answer of my above question), then the
>> metavariable could be bound to something wrong. Indeed, I believe that the
>> metavariable should be bound to 'foo' (in the above case) and not to METH(foo)
>> because a direct reference to 'foo' may appear later in the code without the
>> use of the METH macro.
> But since METH(foo) converts foo into something else, I guess you would
> not want a match on foo? That would cause dropping the first argument of
> any random call to foo.
Please excuse my bad explanation, it was confusing.
Indeed, I don't want the metavariable to be bound to 'foo' nor to
METH(foo). I want it to be bound to the expanded value of METH(foo).
For instance, say
#define METH(x) prefix_##x
I want the metavariable to be bound to prefix_foo when a METH(foo) is
encountered. I want that because, it is legal that somewhere else in the
code, there is direct reference to prefix_foo, and this should be
detected by spatch to patch the code correctly. I have the feeling (as
a lambda user) that what I want could be not so easy to implement if
spatch doesn't really expand the macros. What do you think about that?
More information about the Cocci