summaryrefslogtreecommitdiffstats
path: root/clang/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-13 00:51:30 +0000
committerChris Lattner <sabre@nondot.org>2009-02-13 00:51:30 +0000
commit837b990c539921cca8366476ebf0cb0dc76f9280 (patch)
treecb8449ad81f81e8c2c114d473a90680dbab97dd2 /clang/lib/Rewrite/HTMLRewrite.cpp
parent7ae70391f0da3d89639fa01d1eeb74edb19b3a3b (diff)
downloadbcm5719-llvm-837b990c539921cca8366476ebf0cb0dc76f9280.tar.gz
bcm5719-llvm-837b990c539921cca8366476ebf0cb0dc76f9280.zip
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. llvm-svn: 64421
Diffstat (limited to 'clang/lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--clang/lib/Rewrite/HTMLRewrite.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp
index 6e5d1c32b11..c0f39376007 100644
--- a/clang/lib/Rewrite/HTMLRewrite.cpp
+++ b/clang/lib/Rewrite/HTMLRewrite.cpp
@@ -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 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
// 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 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
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 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
}
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);
}
OpenPOWER on IntegriCloud