diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-14 03:57:19 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-14 03:57:19 +0000 |
commit | 8877321ca66b2887c2f377a7f724a62f34fdf1cd (patch) | |
tree | 396c02ca27e0e2d0af0d4316a229527f6eaf9fa3 /lib | |
parent | dd17394d225b06376e9ae1d23f36cec463fdef01 (diff) |
make the token paste avoidance logic turn "..." into ".. ." instead of ". . ."
when avoiding paste. Patch by David Peixotto!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101218 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 9 | ||||
-rw-r--r-- | lib/Lex/TokenConcatenation.cpp | 6 | ||||
-rw-r--r-- | lib/Rewrite/HTMLRewrite.cpp | 4 |
3 files changed, 13 insertions, 6 deletions
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index a64f6e7c0c..b4718e9ad4 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -125,8 +125,9 @@ public: } bool MoveToLine(unsigned LineNo); - bool AvoidConcat(const Token &PrevTok, const Token &Tok) { - return ConcatInfo.AvoidConcat(PrevTok, Tok); + bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok, + const Token &Tok) { + return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok); } void WriteLineInfo(unsigned LineNo, const char *Extra=0, unsigned ExtraLen=0); @@ -396,6 +397,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, PrintPPOutputPPCallbacks *Callbacks, llvm::raw_ostream &OS) { char Buffer[256]; + Token PrevPrevTok; Token PrevTok; while (1) { @@ -407,7 +409,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, // useful to look at and no concatenation could happen anyway. (Callbacks->hasEmittedTokensOnThisLine() && // Don't print "-" next to "-", it would form "--". - Callbacks->AvoidConcat(PrevTok, Tok))) { + Callbacks->AvoidConcat(PrevPrevTok, PrevTok, Tok))) { OS << ' '; } @@ -438,6 +440,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, if (Tok.is(tok::eof)) break; + PrevPrevTok = PrevTok; PrevTok = Tok; PP.Lex(Tok); } diff --git a/lib/Lex/TokenConcatenation.cpp b/lib/Lex/TokenConcatenation.cpp index 51d2e2326f..fc6db2151a 100644 --- a/lib/Lex/TokenConcatenation.cpp +++ b/lib/Lex/TokenConcatenation.cpp @@ -124,7 +124,8 @@ static char GetFirstChar(Preprocessor &PP, const Token &Tok) { /// but the resulting output won't have incorrect concatenations going on. /// Examples include "..", which we print with a space between, because we /// don't want to track enough to tell "x.." from "...". -bool TokenConcatenation::AvoidConcat(const Token &PrevTok, +bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok, + const Token &PrevTok, const Token &Tok) const { // First, check to see if the tokens were directly adjacent in the original // source. If they were, it must be okay to stick them together: if there @@ -192,7 +193,8 @@ bool TokenConcatenation::AvoidConcat(const Token &PrevTok, return isalnum(FirstChar) || Tok.is(tok::numeric_constant) || FirstChar == '+' || FirstChar == '-' || FirstChar == '.'; case tok::period: // ..., .*, .1234 - return FirstChar == '.' || isdigit(FirstChar) || + return (FirstChar == '.' && PrevPrevTok.is(tok::period)) || + isdigit(FirstChar) || (PP.getLangOptions().CPlusPlus && FirstChar == '*'); case tok::amp: // && return FirstChar == '&'; diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 7b78070a27..5fe064990e 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -533,6 +533,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { std::string Expansion = EscapeText(TmpPP.getSpelling(Tok)); unsigned LineLen = Expansion.size(); + Token PrevPrevTok; Token PrevTok = Tok; // Okay, eat this token, getting the next one. TmpPP.Lex(Tok); @@ -553,13 +554,14 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { // If the tokens were already space separated, or if they must be to avoid // them being implicitly pasted, add a space between them. if (Tok.hasLeadingSpace() || - ConcatInfo.AvoidConcat(PrevTok, Tok)) + ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok)) Expansion += ' '; // Escape any special characters in the token text. Expansion += EscapeText(TmpPP.getSpelling(Tok)); LineLen += Expansion.size(); + PrevPrevTok = PrevTok; PrevTok = Tok; TmpPP.Lex(Tok); } |