[cfe-commits] r64421 - /cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Chris Lattner
sabre at nondot.org
Thu Feb 12 16:51:30 PST 2009
Author: lattner
Date: Thu Feb 12 18:51:30 2009
New Revision: 64421
URL: http://llvm.org/viewvc/llvm-project?rev=64421&view=rev
Log:
make "floating macro bubble" output of -emit-html much prettier:
only insert spaces between tokens if the code had them or if they
are actually required to avoid pasting. This reuses the same
logic as -E mode.
Modified:
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=64421&r1=64420&r2=64421&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Thu Feb 12 18:51:30 2009
@@ -15,6 +15,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Rewrite/Rewriter.h"
#include "clang/Rewrite/HTMLRewrite.h"
+#include "clang/Lex/TokenConcatenation.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
@@ -428,6 +429,8 @@
// Start parsing the specified input file.
PP.EnterMainSourceFile();
+ TokenConcatenation ConcatInfo(PP);
+
// Lex all the tokens.
const SourceManager &SourceMgr = PP.getSourceManager();
Token Tok;
@@ -465,6 +468,7 @@
std::string Expansion = PP.getSpelling(Tok);
unsigned LineLen = Expansion.size();
+ Token PrevTok = Tok;
// Okay, eat this token, getting the next one.
PP.Lex(Tok);
@@ -480,9 +484,18 @@
}
LineLen -= Expansion.size();
+
+ // 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))
+ Expansion += ' ';
+
// Escape any special characters in the token text.
- Expansion += ' ' + EscapeText(PP.getSpelling(Tok));
+ Expansion += EscapeText(PP.getSpelling(Tok));
LineLen += Expansion.size();
+
+ PrevTok = Tok;
PP.Lex(Tok);
}
More information about the cfe-commits
mailing list