From 486754660bb926339aefcf012a3f848592babb8b Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 28 Jul 2018 11:06:01 +0000 Subject: Vendor import of clang trunk r338150: https://llvm.org/svn/llvm-project/cfe/trunk@338150 --- lib/Rewrite/HTMLRewrite.cpp | 224 +++++++++++++++++++++++++++----------------- 1 file changed, 139 insertions(+), 85 deletions(-) (limited to 'lib/Rewrite/HTMLRewrite.cpp') diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 618c0179f100..d93961f3582e 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -30,7 +30,8 @@ using namespace clang; /// start/end tags are placed at the start/end of each line if the range is /// multiline. void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E, - const char *StartTag, const char *EndTag) { + const char *StartTag, const char *EndTag, + bool IsTokenRange) { SourceManager &SM = R.getSourceMgr(); B = SM.getExpansionLoc(B); E = SM.getExpansionLoc(E); @@ -41,7 +42,8 @@ void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E, unsigned EOffset = SM.getFileOffset(E); // Include the whole end token in the range. - EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts()); + if (IsTokenRange) + EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts()); bool Invalid = false; const char *BufferStart = SM.getBufferData(FID, &Invalid).data(); @@ -210,9 +212,9 @@ static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo, SmallString<256> Str; llvm::raw_svector_ostream OS(Str); - OS << "" - << LineNo << ""; + OS << "" + << "" << LineNo + << ""; if (B == E) { // Handle empty lines. OS << " "; @@ -263,7 +265,10 @@ void html::AddLineNumbers(Rewriter& R, FileID FID) { } // Add one big table tag that surrounds all of the code. - RB.InsertTextBefore(0, "\n"); + std::string s; + llvm::raw_string_ostream os(s); + os << "
\n"; + RB.InsertTextBefore(0, os.str()); RB.InsertTextAfter(FileEnd - FileBeg, "
"); } @@ -285,78 +290,128 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, if (!title.empty()) os << "" << html::EscapeText(title) << "\n"; - os << "\n\n"; + os << R"<<<( + + +)<<<"; // Generate header R.InsertTextBefore(StartLoc, os.str()); @@ -535,16 +590,15 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { // Okay, we have the first token of a macro expansion: highlight the // expansion by inserting a start tag before the macro expansion and // end tag after it. - std::pair LLoc = - SM.getExpansionRange(Tok.getLocation()); + CharSourceRange LLoc = SM.getExpansionRange(Tok.getLocation()); // Ignore tokens whose instantiation location was not the main file. - if (SM.getFileID(LLoc.first) != FID) { + if (SM.getFileID(LLoc.getBegin()) != FID) { TmpPP.Lex(Tok); continue; } - assert(SM.getFileID(LLoc.second) == FID && + assert(SM.getFileID(LLoc.getEnd()) == FID && "Start and end of expansion must be in the same ultimate file!"); std::string Expansion = EscapeText(TmpPP.getSpelling(Tok)); @@ -559,7 +613,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { // instantiation. It would be really nice to pop up a window with all the // spelling of the tokens or something. while (!Tok.is(tok::eof) && - SM.getExpansionLoc(Tok.getLocation()) == LLoc.first) { + SM.getExpansionLoc(Tok.getLocation()) == LLoc.getBegin()) { // Insert a newline if the macro expansion is getting large. if (LineLen > 60) { Expansion += "
"; @@ -588,8 +642,8 @@ void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) { // highlighted. Expansion = "" + Expansion + ""; - HighlightRange(R, LLoc.first, LLoc.second, - "", Expansion.c_str()); + HighlightRange(R, LLoc.getBegin(), LLoc.getEnd(), "", + Expansion.c_str(), LLoc.isTokenRange()); } // Restore the preprocessor's old state. -- cgit v1.2.3