[cfe-dev] Patch to allow comment translators implementation

Chris Lattner clattner at apple.com
Wed Jan 27 13:48:22 PST 2010

>>> Perhaps I've explained badly, please follow this example:
>>> #if 0
>>> /* openmp comments */
>>> int a;
>>> #endif
>>> The preprocessor see the #if 0 directive and then enter
>>> SkipExcludedConditionalBlock where the lexing proceed.
>>> When we lex the comment the CommentHandler is invoked and it push some
>>> tokens using EnterTokenStream (i.e. setting CurTokenLexer), but none of
>>> this tokens is read by SkipExcludedConditionalBlock (without the patch
>>> you've discarded).
>>> This means that when SkipExcludedConditionalBlock returns and normal
>>> lexing proceed the Preprocessor will read the tokens previously inserted
>>> in the bad context i.e. after the #endif.
>>>> #if 0 skipping is also performance sensitive.
>> There are a few alternatives wrt to apply the missing part of the
>> original patch:
>> 1) do not call comment handlers when skipping excluded conditional block
>> 2) have a way inside comment handlers to know that we are inside an
>> excluded conditional block (so to avoid to call EnterTokenStream)
>> I think that 2) is better as it is more flexyble.
> I've not yet heard anything from you, what do you think is the proper
> way to fix the problem above?

Hi Abramo,

I'm sorry for the delay.  I think that #1 is the best approach.  Comment handles should not be invoked on things in #if 0 blocks, because #if 0 blocks should be completely skipped according to the rules of the preprocessor: not doing this would invalidate the "include once" optimization that is applied to files wrapped in the "#ifndef FOO_H / #define FOO_H ... #endif" idiom.

In short, I think that #1 is the right fix.


More information about the cfe-dev mailing list