diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-03-05 23:54:55 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-03-05 23:54:55 +0000 |
commit | 67b66231a836f37d4d2242b746ef74d8d3f47dc7 (patch) | |
tree | 1e3663629a8902bded409abdeb1250c434ea0db3 /clang/lib | |
parent | 3e067534088a1671619f1d6c701ce92e217be96c (diff) | |
download | bcm5719-llvm-67b66231a836f37d4d2242b746ef74d8d3f47dc7.tar.gz bcm5719-llvm-67b66231a836f37d4d2242b746ef74d8d3f47dc7.zip |
Preprocessor: don't keep comments under -traditional-cpp.
This patch is designed for minimal intrusion into normal preprocessing
and compilation; under -E -traditional-cpp, the lexer will still
generate tok::comment nodes since it is preserving all whitespace, but
the output printer will then throw it away.
<rdar://problem/13338680>
llvm-svn: 176534
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/PrintPreprocessedOutput.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 58bbfd3f8af..d894939b4b4 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -515,6 +515,9 @@ struct UnknownPragmaHandler : public PragmaHandler { static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, PrintPPOutputPPCallbacks *Callbacks, raw_ostream &OS) { + bool DropComments = PP.getLangOpts().TraditionalCPP && + !PP.getCommentRetentionState(); + char Buffer[256]; Token PrevPrevTok, PrevTok; PrevPrevTok.startToken(); @@ -537,7 +540,13 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, OS << ' '; } - if (IdentifierInfo *II = Tok.getIdentifierInfo()) { + if (DropComments && Tok.is(tok::comment)) { + // Skip comments. Normally the preprocessor does not generate + // tok::comment nodes at all when not keeping comments, but under + // -traditional-cpp the lexer keeps /all/ whitespace, including comments. + SourceLocation StartLoc = Tok.getLocation(); + Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength())); + } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) { OS << II->getName(); } else if (Tok.isLiteral() && !Tok.needsCleaning() && Tok.getLiteralData()) { |