[cfe-dev] Preprocessor lexer sometimes goes too far?

Douglas Gregor dgregor at apple.com
Tue Nov 9 14:36:54 PST 2010


On Nov 9, 2010, at 10:36 AM, Vladimir Kirillov wrote:

> Hello, cfe-dev!
> 
> Here's an issue:
> 
> I have a program with subclasses of ASTConsumer and PPCallbacks, which
> are passed to ParseAST().
> See the expansions.c attachment which I pass as input to it.
> 
> Sometimes I see that the macro expansion callbacks (and, respectively,
> macro expansion actions) are happening way before the respective code
> gets processed. (See gdb output below)
> 
> How can this behaviour be explained? Is this some kind of optimization
> side effect or something?

The lexer is going to run ahead of the parser while it's expanding macros or when the parser is performing lookahead.

> My program relies on the expansion order so this is critical to me to
> gather relations between expanded macros and the declarations they
> expanded.


Why not go back to look at the source locations of the resulting declarations, then check whether they came from a macro instantiation?

	- Doug



More information about the cfe-dev mailing list