[cfe-commits] Comment Callback - first try - for review
Chris Lattner
clattner at apple.com
Sun Oct 26 13:36:51 PDT 2008
On Oct 26, 2008, at 12:40 PM, Sebastian Redl wrote:
> Hi,
>
> Just one comment:
>
>> - /// When this is set to 2 it returns comments and whitespace.
>> When set to 1
>> - /// it returns comments, when it is set to 0 it returns normal
>> tokens only.
>> + /// When this is set to 3 it returns comments and whitespace.
>> When set to 2
>> + /// it returns comments. When set to 1 it call the PP callback
>> on comment but
>> + /// only return normal tokens. When it is set to 0 it returns
>> normal tokens
>> + /// only.
>> unsigned char ExtendedTokenMode;
>>
>
> How about an enum for that?
Yeah, I agree, it is overdue. :)
Overall, the approach of extending ExtendedTokenMode and adding a hook
to PPCallbacks seems very nice.
Some minor bits:
Please finish this comment:
+ /// Comment - This callback is invoked when a comment is encountered
+ /// only when ...
+ virtual void Comment(SourceLocation Loc, unsigned Length) {
In this code:
// If we are returning comments as tokens, return this comment as a
token.
+ if(isCommentCallbackMode()) {
+ PP->getPPCallbacks()->Comment(getSourceLocation(BufferPtr),
CurPtr-BufferPtr);
+ } else if (inKeepCommentMode()) {
FormTokenWithChars(Result, CurPtr, tok::comment);
Space after 'if' please. Also, this is a hot path, it would be better
to do one "if" to check to see if we're in any comment flavor mode,
something like this:
if (inLexCommentMode()) {
if(isCommentCallbackMode()) {
PP->getPPCallbacks()->Comment(getSourceLocation(BufferPtr),
CurPtr-BufferPtr);
} else if (inKeepCommentMode()) {
FormTokenWithChars(Result, CurPtr, tok::comment);
..
}
-Chris
More information about the cfe-commits
mailing list