[Cocci] Problem when using a macro for mangling function names
Julia Lawall
julia at diku.dk
Fri Mar 20 18:52:56 CET 2009
On Fri, 20 Mar 2009, Yoann Padioleau wrote:
> Julia Lawall <julia at diku.dk> writes:
>
> > The problem is that it is not allowed to bind a metavariable to the result
> > of expanding a macro. The error message is indeed not very graceful. The
> > problem though is that the metavariable is bound to foo, not METH(foo),
> > and would thus match the wrong thing in your later rules, so just getting
> > rid of the assert would not really solve the problem.
> >
> > I will try to find a way to solve the problem.
>
> I think his example is quite common. Maybe we could extend
> the parser and engine to allow such "elaborated" ident. Another place where
> we have subtelities is in the definition of the macro itself, like
> in his #define METH(x) x##foo. For the moment the lexer
> agglomerate x##foo in a single token. We could do better as some
> analysis may want to know that this is not a regular ident.
> In ast_c.ml we could have
>
> ...
> | Ident of ident
> ...
> and ident =
> | RegularIdent of string
> | MacroConstructingIdent of string * string list
> | MacroConcatenation of string * string
>
> In the short term we could easily add then a new heuristic_hook in
> standard.h like
>
> #define METH(x) MACRO_CONSTRUCTING_IDENT
>
> to help the parser spot those idents.
>
> (just like we have right now in standard.h some
> #define DEBUG0(x) MACROSTATEMENT
> )
>
> Later we can add some heuristics in parsing_hacks to infer
> them automatically, or as you suggest trying to leverage
> the information in actual definitions, when available.
It seems fine to me.
julia
More information about the Cocci
mailing list