[cfe-commits] r101218 - in /cfe/trunk: include/clang/Lex/TokenConcatenation.h lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/TokenConcatenation.cpp lib/Rewrite/HTMLRewrite.cpp test/Preprocessor/output_paste_avoid.c
Chris Lattner
sabre at nondot.org
Tue Apr 13 20:57:19 PDT 2010
Author: lattner
Date: Tue Apr 13 22:57:19 2010
New Revision: 101218
URL: http://llvm.org/viewvc/llvm-project?rev=101218&view=rev
Log:
make the token paste avoidance logic turn "..." into ".. ." instead of ". . ."
when avoiding paste. Patch by David Peixotto!
Modified:
cfe/trunk/include/clang/Lex/TokenConcatenation.h
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Lex/TokenConcatenation.cpp
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
cfe/trunk/test/Preprocessor/output_paste_avoid.c
Modified: cfe/trunk/include/clang/Lex/TokenConcatenation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/TokenConcatenation.h?rev=101218&r1=101217&r2=101218&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/TokenConcatenation.h (original)
+++ cfe/trunk/include/clang/Lex/TokenConcatenation.h Tue Apr 13 22:57:19 2010
@@ -58,7 +58,9 @@
public:
TokenConcatenation(Preprocessor &PP);
- bool AvoidConcat(const Token &PrevTok, const Token &Tok) const;
+ bool AvoidConcat(const Token &PrevPrevTok,
+ const Token &PrevTok,
+ const Token &Tok) const;
private:
/// StartsWithL - Return true if the spelling of this token starts with 'L'.
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=101218&r1=101217&r2=101218&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Tue Apr 13 22:57:19 2010
@@ -125,8 +125,9 @@
}
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 @@
PrintPPOutputPPCallbacks *Callbacks,
llvm::raw_ostream &OS) {
char Buffer[256];
+ Token PrevPrevTok;
Token PrevTok;
while (1) {
@@ -407,7 +409,7 @@
// 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 @@
if (Tok.is(tok::eof)) break;
+ PrevPrevTok = PrevTok;
PrevTok = Tok;
PP.Lex(Tok);
}
Modified: cfe/trunk/lib/Lex/TokenConcatenation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenConcatenation.cpp?rev=101218&r1=101217&r2=101218&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenConcatenation.cpp (original)
+++ cfe/trunk/lib/Lex/TokenConcatenation.cpp Tue Apr 13 22:57:19 2010
@@ -124,7 +124,8 @@
/// 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 @@
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 == '&';
Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=101218&r1=101217&r2=101218&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Apr 13 22:57:19 2010
@@ -533,6 +533,7 @@
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 @@
// 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);
}
Modified: cfe/trunk/test/Preprocessor/output_paste_avoid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/output_paste_avoid.c?rev=101218&r1=101217&r2=101218&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/output_paste_avoid.c (original)
+++ cfe/trunk/test/Preprocessor/output_paste_avoid.c Tue Apr 13 22:57:19 2010
@@ -4,8 +4,11 @@
#define y(a) ..a
A: y(.)
// This should print as ".. ." to avoid turning into ...
-// CHECK: A: . . .
+// CHECK: A: .. .
+#define X 0 .. 1
+B: X
+// CHECK: B: 0 .. 1
#define DOT .
C: ..DOT
More information about the cfe-commits
mailing list