[cfe-commits] A patch for PPCallbacks::If() & Elif() functions to fix what the FIXME says.

Douglas Gregor dgregor at apple.com
Thu May 26 16:07:34 PDT 2011

On May 25, 2011, at 8:48 PM, Wei wrote:

> Hi, Douglas,
> How could I re-lex the tokens? Does clang store some state information after lexing tokens? if so, simply set the Lexer::BufferPtr to the position of # is not enough.

Just create a new lexer object at the appropriate place in the buffer, and lex again. Or, lex up to that position.

> My current though is to still use the clang Lex mechanism
> 1) In Preprocessor::HandleIfDirective(), first call Preprocessor::EnableBacktrackAtThisPos().
> 2) In PPCallbacks::If(), call Preprocessor::Backtrack(), so that we can use the lexed tokens, and don't need to worry about the correct state of re-lexing.
> How about your idea? I want to sync with u for the design before I start the coding again :)

Your scheme will work; the main point I wanted to make before is that any change here has to have zero performance impact in the common case. One way to do that is to do nothing in the common case, and then lazily create the "parse" tree representation of the expression by re-lexing when requested.

	- Doug

More information about the cfe-commits mailing list