diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-07-29 06:30:25 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-07-29 06:30:25 +0000 |
| commit | 457fc15bc5beb48fb3041a7525b6731edf720cc8 (patch) | |
| tree | 878e141457ea9f7f4b03d3f6d3c8a707dfaa6cd1 /clang/Lex/Preprocessor.cpp | |
| parent | 2be41154652c162e5ab5db6ea41a651c4dc3263f (diff) | |
| download | bcm5719-llvm-457fc15bc5beb48fb3041a7525b6731edf720cc8.tar.gz bcm5719-llvm-457fc15bc5beb48fb3041a7525b6731edf720cc8.zip | |
Implement comment saving mode: the -C and -CC options.
llvm-svn: 38783
Diffstat (limited to 'clang/Lex/Preprocessor.cpp')
| -rw-r--r-- | clang/Lex/Preprocessor.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp index b6c6bc3610d..229aaacd55c 100644 --- a/clang/Lex/Preprocessor.cpp +++ b/clang/Lex/Preprocessor.cpp @@ -755,6 +755,10 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName, return 0; } // Otherwise, continue to add the tokens to this variable argument. + } else if (Tok.getKind() == tok::comment && !Features.KeepMacroComments) { + // If this is a comment token in the argument list and we're just in + // -C mode (not -CC mode), discard the comment. + continue; } ArgTokens.push_back(Tok); @@ -1221,6 +1225,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, // directive mode. Tell the lexer this so any newlines we see will be // converted into an EOM token (this terminates the macro). CurLexer->ParsingPreprocessorDirective = true; + CurLexer->KeepCommentMode = false; + // Read the next token, the directive flavor. LexUnexpandedToken(Tok); @@ -1229,6 +1235,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, // something bogus), skip it. if (Tok.getKind() != tok::identifier) { CurLexer->ParsingPreprocessorDirective = false; + // Restore comment saving mode. + CurLexer->KeepCommentMode = Features.KeepComments; continue; } @@ -1242,6 +1250,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, if (FirstChar >= 'a' && FirstChar <= 'z' && FirstChar != 'i' && FirstChar != 'e') { CurLexer->ParsingPreprocessorDirective = false; + // Restore comment saving mode. + CurLexer->KeepCommentMode = Features.KeepComments; continue; } @@ -1261,6 +1271,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, IdLen = DirectiveStr.size(); if (IdLen >= 20) { CurLexer->ParsingPreprocessorDirective = false; + // Restore comment saving mode. + CurLexer->KeepCommentMode = Features.KeepComments; continue; } memcpy(Directive, &DirectiveStr[0], IdLen); @@ -1339,6 +1351,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, } CurLexer->ParsingPreprocessorDirective = false; + // Restore comment saving mode. + CurLexer->KeepCommentMode = Features.KeepComments; } // Finally, if we are out of the conditional (saw an #endif or ran off the end @@ -1698,6 +1712,10 @@ void Preprocessor::HandleDefineDirective(LexerToken &DefineTok) { if (MacroNameTok.getKind() == tok::eom) return; + // If we are supposed to keep comments in #defines, reenable comment saving + // mode. + CurLexer->KeepCommentMode = Features.KeepMacroComments; + MacroInfo *MI = new MacroInfo(MacroNameTok.getLocation()); LexerToken Tok; |

