#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"
// Start parsing the specified input file.
PP.EnterMainSourceFile();
+ TokenConcatenation ConcatInfo(PP);
+
// Lex all the tokens.
const SourceManager &SourceMgr = PP.getSourceManager();
Token Tok;
std::string Expansion = PP.getSpelling(Tok);
unsigned LineLen = Expansion.size();
+ Token PrevTok = Tok;
// Okay, eat this token, getting the next one.
PP.Lex(Tok);
}
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);
}