HTMLDiagnostics.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. //===--- HTMLDiagnostics.cpp - HTML Diagnostics for Paths ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the HTMLDiagnostics object.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/Decl.h"
  15. #include "clang/Basic/FileManager.h"
  16. #include "clang/Basic/SourceManager.h"
  17. #include "clang/Lex/Lexer.h"
  18. #include "clang/Lex/Preprocessor.h"
  19. #include "clang/Rewrite/Core/HTMLRewrite.h"
  20. #include "clang/Rewrite/Core/Rewriter.h"
  21. #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
  22. #include "clang/StaticAnalyzer/Core/CheckerManager.h"
  23. #include "clang/StaticAnalyzer/Core/IssueHash.h"
  24. #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
  25. #include "llvm/Support/Errc.h"
  26. #include "llvm/Support/FileSystem.h"
  27. #include "llvm/Support/MemoryBuffer.h"
  28. #include "llvm/Support/Path.h"
  29. #include "llvm/Support/raw_ostream.h"
  30. #include <sstream>
  31. using namespace clang;
  32. using namespace ento;
  33. //===----------------------------------------------------------------------===//
  34. // Boilerplate.
  35. //===----------------------------------------------------------------------===//
  36. namespace {
  37. class HTMLDiagnostics : public PathDiagnosticConsumer {
  38. std::string Directory;
  39. bool createdDir, noDir;
  40. const Preprocessor &PP;
  41. AnalyzerOptions &AnalyzerOpts;
  42. public:
  43. HTMLDiagnostics(AnalyzerOptions &AnalyzerOpts, const std::string& prefix, const Preprocessor &pp);
  44. ~HTMLDiagnostics() override { FlushDiagnostics(nullptr); }
  45. void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
  46. FilesMade *filesMade) override;
  47. StringRef getName() const override {
  48. return "HTMLDiagnostics";
  49. }
  50. unsigned ProcessMacroPiece(raw_ostream &os,
  51. const PathDiagnosticMacroPiece& P,
  52. unsigned num);
  53. void HandlePiece(Rewriter& R, FileID BugFileID,
  54. const PathDiagnosticPiece& P, unsigned num, unsigned max);
  55. void HighlightRange(Rewriter& R, FileID BugFileID, SourceRange Range,
  56. const char *HighlightStart = "<span class=\"mrange\">",
  57. const char *HighlightEnd = "</span>");
  58. void ReportDiag(const PathDiagnostic& D,
  59. FilesMade *filesMade);
  60. };
  61. } // end anonymous namespace
  62. HTMLDiagnostics::HTMLDiagnostics(AnalyzerOptions &AnalyzerOpts,
  63. const std::string& prefix,
  64. const Preprocessor &pp)
  65. : Directory(prefix), createdDir(false), noDir(false), PP(pp), AnalyzerOpts(AnalyzerOpts) {
  66. }
  67. void ento::createHTMLDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
  68. PathDiagnosticConsumers &C,
  69. const std::string& prefix,
  70. const Preprocessor &PP) {
  71. C.push_back(new HTMLDiagnostics(AnalyzerOpts, prefix, PP));
  72. }
  73. //===----------------------------------------------------------------------===//
  74. // Report processing.
  75. //===----------------------------------------------------------------------===//
  76. void HTMLDiagnostics::FlushDiagnosticsImpl(
  77. std::vector<const PathDiagnostic *> &Diags,
  78. FilesMade *filesMade) {
  79. for (std::vector<const PathDiagnostic *>::iterator it = Diags.begin(),
  80. et = Diags.end(); it != et; ++it) {
  81. ReportDiag(**it, filesMade);
  82. }
  83. }
  84. void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
  85. FilesMade *filesMade) {
  86. // Create the HTML directory if it is missing.
  87. if (!createdDir) {
  88. createdDir = true;
  89. if (std::error_code ec = llvm::sys::fs::create_directories(Directory)) {
  90. llvm::errs() << "warning: could not create directory '"
  91. << Directory << "': " << ec.message() << '\n';
  92. noDir = true;
  93. return;
  94. }
  95. }
  96. if (noDir)
  97. return;
  98. // First flatten out the entire path to make it easier to use.
  99. PathPieces path = D.path.flatten(/*ShouldFlattenMacros=*/false);
  100. // The path as already been prechecked that all parts of the path are
  101. // from the same file and that it is non-empty.
  102. const SourceManager &SMgr = (*path.begin())->getLocation().getManager();
  103. assert(!path.empty());
  104. FileID FID =
  105. (*path.begin())->getLocation().asLocation().getExpansionLoc().getFileID();
  106. assert(FID.isValid());
  107. // Create a new rewriter to generate HTML.
  108. Rewriter R(const_cast<SourceManager&>(SMgr), PP.getLangOpts());
  109. // Get the function/method name
  110. SmallString<128> declName("unknown");
  111. int offsetDecl = 0;
  112. if (const Decl *DeclWithIssue = D.getDeclWithIssue()) {
  113. if (const NamedDecl *ND = dyn_cast<NamedDecl>(DeclWithIssue)) {
  114. declName = ND->getDeclName().getAsString();
  115. }
  116. if (const Stmt *Body = DeclWithIssue->getBody()) {
  117. // Retrieve the relative position of the declaration which will be used
  118. // for the file name
  119. FullSourceLoc L(
  120. SMgr.getExpansionLoc((*path.rbegin())->getLocation().asLocation()),
  121. SMgr);
  122. FullSourceLoc FunL(SMgr.getExpansionLoc(Body->getLocStart()), SMgr);
  123. offsetDecl = L.getExpansionLineNumber() - FunL.getExpansionLineNumber();
  124. }
  125. }
  126. // Process the path.
  127. unsigned n = path.size();
  128. unsigned max = n;
  129. for (PathPieces::const_reverse_iterator I = path.rbegin(),
  130. E = path.rend();
  131. I != E; ++I, --n)
  132. HandlePiece(R, FID, **I, n, max);
  133. // Add line numbers, header, footer, etc.
  134. // unsigned FID = R.getSourceMgr().getMainFileID();
  135. html::EscapeText(R, FID);
  136. html::AddLineNumbers(R, FID);
  137. // If we have a preprocessor, relex the file and syntax highlight.
  138. // We might not have a preprocessor if we come from a deserialized AST file,
  139. // for example.
  140. html::SyntaxHighlight(R, FID, PP);
  141. html::HighlightMacros(R, FID, PP);
  142. // Get the full directory name of the analyzed file.
  143. const FileEntry* Entry = SMgr.getFileEntryForID(FID);
  144. // This is a cludge; basically we want to append either the full
  145. // working directory if we have no directory information. This is
  146. // a work in progress.
  147. llvm::SmallString<0> DirName;
  148. if (llvm::sys::path::is_relative(Entry->getName())) {
  149. llvm::sys::fs::current_path(DirName);
  150. DirName += '/';
  151. }
  152. int LineNumber = (*path.rbegin())->getLocation().asLocation().getExpansionLineNumber();
  153. int ColumnNumber = (*path.rbegin())->getLocation().asLocation().getExpansionColumnNumber();
  154. // Add the name of the file as an <h1> tag.
  155. {
  156. std::string s;
  157. llvm::raw_string_ostream os(s);
  158. os << "<!-- REPORTHEADER -->\n"
  159. << "<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n"
  160. "<tr><td class=\"rowname\">File:</td><td>"
  161. << html::EscapeText(DirName)
  162. << html::EscapeText(Entry->getName())
  163. << "</td></tr>\n<tr><td class=\"rowname\">Location:</td><td>"
  164. "<a href=\"#EndPath\">line "
  165. << LineNumber
  166. << ", column "
  167. << ColumnNumber
  168. << "</a></td></tr>\n"
  169. "<tr><td class=\"rowname\">Description:</td><td>"
  170. << D.getVerboseDescription() << "</td></tr>\n";
  171. // Output any other meta data.
  172. for (PathDiagnostic::meta_iterator I=D.meta_begin(), E=D.meta_end();
  173. I!=E; ++I) {
  174. os << "<tr><td></td><td>" << html::EscapeText(*I) << "</td></tr>\n";
  175. }
  176. os << "</table>\n<!-- REPORTSUMMARYEXTRA -->\n"
  177. "<h3>Annotated Source Code</h3>\n";
  178. R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str());
  179. }
  180. // Embed meta-data tags.
  181. {
  182. std::string s;
  183. llvm::raw_string_ostream os(s);
  184. StringRef BugDesc = D.getVerboseDescription();
  185. if (!BugDesc.empty())
  186. os << "\n<!-- BUGDESC " << BugDesc << " -->\n";
  187. StringRef BugType = D.getBugType();
  188. if (!BugType.empty())
  189. os << "\n<!-- BUGTYPE " << BugType << " -->\n";
  190. PathDiagnosticLocation UPDLoc = D.getUniqueingLoc();
  191. FullSourceLoc L(SMgr.getExpansionLoc(UPDLoc.isValid()
  192. ? UPDLoc.asLocation()
  193. : D.getLocation().asLocation()),
  194. SMgr);
  195. const Decl *DeclWithIssue = D.getDeclWithIssue();
  196. StringRef BugCategory = D.getCategory();
  197. if (!BugCategory.empty())
  198. os << "\n<!-- BUGCATEGORY " << BugCategory << " -->\n";
  199. os << "\n<!-- BUGFILE " << DirName << Entry->getName() << " -->\n";
  200. os << "\n<!-- FILENAME " << llvm::sys::path::filename(Entry->getName()) << " -->\n";
  201. os << "\n<!-- FUNCTIONNAME " << declName << " -->\n";
  202. os << "\n<!-- ISSUEHASHCONTENTOFLINEINCONTEXT "
  203. << GetIssueHash(SMgr, L, D.getCheckName(), D.getBugType(), DeclWithIssue,
  204. PP.getLangOpts()) << " -->\n";
  205. os << "\n<!-- BUGLINE "
  206. << LineNumber
  207. << " -->\n";
  208. os << "\n<!-- BUGCOLUMN "
  209. << ColumnNumber
  210. << " -->\n";
  211. os << "\n<!-- BUGPATHLENGTH " << path.size() << " -->\n";
  212. // Mark the end of the tags.
  213. os << "\n<!-- BUGMETAEND -->\n";
  214. // Insert the text.
  215. R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str());
  216. }
  217. // Add CSS, header, and footer.
  218. html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
  219. // Get the rewrite buffer.
  220. const RewriteBuffer *Buf = R.getRewriteBufferFor(FID);
  221. if (!Buf) {
  222. llvm::errs() << "warning: no diagnostics generated for main file.\n";
  223. return;
  224. }
  225. // Create a path for the target HTML file.
  226. int FD;
  227. SmallString<128> Model, ResultPath;
  228. if (!AnalyzerOpts.shouldWriteStableReportFilename()) {
  229. llvm::sys::path::append(Model, Directory, "report-%%%%%%.html");
  230. if (std::error_code EC =
  231. llvm::sys::fs::make_absolute(Model)) {
  232. llvm::errs() << "warning: could not make '" << Model
  233. << "' absolute: " << EC.message() << '\n';
  234. return;
  235. }
  236. if (std::error_code EC =
  237. llvm::sys::fs::createUniqueFile(Model, FD, ResultPath)) {
  238. llvm::errs() << "warning: could not create file in '" << Directory
  239. << "': " << EC.message() << '\n';
  240. return;
  241. }
  242. } else {
  243. int i = 1;
  244. std::error_code EC;
  245. do {
  246. // Find a filename which is not already used
  247. std::stringstream filename;
  248. Model = "";
  249. filename << "report-"
  250. << llvm::sys::path::filename(Entry->getName()).str()
  251. << "-" << declName.c_str()
  252. << "-" << offsetDecl
  253. << "-" << i << ".html";
  254. llvm::sys::path::append(Model, Directory,
  255. filename.str());
  256. EC = llvm::sys::fs::openFileForWrite(Model,
  257. FD,
  258. llvm::sys::fs::F_RW |
  259. llvm::sys::fs::F_Excl);
  260. if (EC && EC != llvm::errc::file_exists) {
  261. llvm::errs() << "warning: could not create file '" << Model
  262. << "': " << EC.message() << '\n';
  263. return;
  264. }
  265. i++;
  266. } while (EC);
  267. }
  268. llvm::raw_fd_ostream os(FD, true);
  269. if (filesMade)
  270. filesMade->addDiagnostic(D, getName(),
  271. llvm::sys::path::filename(ResultPath));
  272. // Emit the HTML to disk.
  273. for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I)
  274. os << *I;
  275. }
  276. void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID,
  277. const PathDiagnosticPiece& P,
  278. unsigned num, unsigned max) {
  279. // For now, just draw a box above the line in question, and emit the
  280. // warning.
  281. FullSourceLoc Pos = P.getLocation().asLocation();
  282. if (!Pos.isValid())
  283. return;
  284. SourceManager &SM = R.getSourceMgr();
  285. assert(&Pos.getManager() == &SM && "SourceManagers are different!");
  286. std::pair<FileID, unsigned> LPosInfo = SM.getDecomposedExpansionLoc(Pos);
  287. if (LPosInfo.first != BugFileID)
  288. return;
  289. const llvm::MemoryBuffer *Buf = SM.getBuffer(LPosInfo.first);
  290. const char* FileStart = Buf->getBufferStart();
  291. // Compute the column number. Rewind from the current position to the start
  292. // of the line.
  293. unsigned ColNo = SM.getColumnNumber(LPosInfo.first, LPosInfo.second);
  294. const char *TokInstantiationPtr =Pos.getExpansionLoc().getCharacterData();
  295. const char *LineStart = TokInstantiationPtr-ColNo;
  296. // Compute LineEnd.
  297. const char *LineEnd = TokInstantiationPtr;
  298. const char* FileEnd = Buf->getBufferEnd();
  299. while (*LineEnd != '\n' && LineEnd != FileEnd)
  300. ++LineEnd;
  301. // Compute the margin offset by counting tabs and non-tabs.
  302. unsigned PosNo = 0;
  303. for (const char* c = LineStart; c != TokInstantiationPtr; ++c)
  304. PosNo += *c == '\t' ? 8 : 1;
  305. // Create the html for the message.
  306. const char *Kind = nullptr;
  307. switch (P.getKind()) {
  308. case PathDiagnosticPiece::Call:
  309. llvm_unreachable("Calls should already be handled");
  310. case PathDiagnosticPiece::Event: Kind = "Event"; break;
  311. case PathDiagnosticPiece::ControlFlow: Kind = "Control"; break;
  312. // Setting Kind to "Control" is intentional.
  313. case PathDiagnosticPiece::Macro: Kind = "Control"; break;
  314. }
  315. std::string sbuf;
  316. llvm::raw_string_ostream os(sbuf);
  317. os << "\n<tr><td class=\"num\"></td><td class=\"line\"><div id=\"";
  318. if (num == max)
  319. os << "EndPath";
  320. else
  321. os << "Path" << num;
  322. os << "\" class=\"msg";
  323. if (Kind)
  324. os << " msg" << Kind;
  325. os << "\" style=\"margin-left:" << PosNo << "ex";
  326. // Output a maximum size.
  327. if (!isa<PathDiagnosticMacroPiece>(P)) {
  328. // Get the string and determining its maximum substring.
  329. const std::string& Msg = P.getString();
  330. unsigned max_token = 0;
  331. unsigned cnt = 0;
  332. unsigned len = Msg.size();
  333. for (std::string::const_iterator I=Msg.begin(), E=Msg.end(); I!=E; ++I)
  334. switch (*I) {
  335. default:
  336. ++cnt;
  337. continue;
  338. case ' ':
  339. case '\t':
  340. case '\n':
  341. if (cnt > max_token) max_token = cnt;
  342. cnt = 0;
  343. }
  344. if (cnt > max_token)
  345. max_token = cnt;
  346. // Determine the approximate size of the message bubble in em.
  347. unsigned em;
  348. const unsigned max_line = 120;
  349. if (max_token >= max_line)
  350. em = max_token / 2;
  351. else {
  352. unsigned characters = max_line;
  353. unsigned lines = len / max_line;
  354. if (lines > 0) {
  355. for (; characters > max_token; --characters)
  356. if (len / characters > lines) {
  357. ++characters;
  358. break;
  359. }
  360. }
  361. em = characters / 2;
  362. }
  363. if (em < max_line/2)
  364. os << "; max-width:" << em << "em";
  365. }
  366. else
  367. os << "; max-width:100em";
  368. os << "\">";
  369. if (max > 1) {
  370. os << "<table class=\"msgT\"><tr><td valign=\"top\">";
  371. os << "<div class=\"PathIndex";
  372. if (Kind) os << " PathIndex" << Kind;
  373. os << "\">" << num << "</div>";
  374. if (num > 1) {
  375. os << "</td><td><div class=\"PathNav\"><a href=\"#Path"
  376. << (num - 1)
  377. << "\" title=\"Previous event ("
  378. << (num - 1)
  379. << ")\">&#x2190;</a></div></td>";
  380. }
  381. os << "</td><td>";
  382. }
  383. if (const PathDiagnosticMacroPiece *MP =
  384. dyn_cast<PathDiagnosticMacroPiece>(&P)) {
  385. os << "Within the expansion of the macro '";
  386. // Get the name of the macro by relexing it.
  387. {
  388. FullSourceLoc L = MP->getLocation().asLocation().getExpansionLoc();
  389. assert(L.isFileID());
  390. StringRef BufferInfo = L.getBufferData();
  391. std::pair<FileID, unsigned> LocInfo = L.getDecomposedLoc();
  392. const char* MacroName = LocInfo.second + BufferInfo.data();
  393. Lexer rawLexer(SM.getLocForStartOfFile(LocInfo.first), PP.getLangOpts(),
  394. BufferInfo.begin(), MacroName, BufferInfo.end());
  395. Token TheTok;
  396. rawLexer.LexFromRawLexer(TheTok);
  397. for (unsigned i = 0, n = TheTok.getLength(); i < n; ++i)
  398. os << MacroName[i];
  399. }
  400. os << "':\n";
  401. if (max > 1) {
  402. os << "</td>";
  403. if (num < max) {
  404. os << "<td><div class=\"PathNav\"><a href=\"#";
  405. if (num == max - 1)
  406. os << "EndPath";
  407. else
  408. os << "Path" << (num + 1);
  409. os << "\" title=\"Next event ("
  410. << (num + 1)
  411. << ")\">&#x2192;</a></div></td>";
  412. }
  413. os << "</tr></table>";
  414. }
  415. // Within a macro piece. Write out each event.
  416. ProcessMacroPiece(os, *MP, 0);
  417. }
  418. else {
  419. os << html::EscapeText(P.getString());
  420. if (max > 1) {
  421. os << "</td>";
  422. if (num < max) {
  423. os << "<td><div class=\"PathNav\"><a href=\"#";
  424. if (num == max - 1)
  425. os << "EndPath";
  426. else
  427. os << "Path" << (num + 1);
  428. os << "\" title=\"Next event ("
  429. << (num + 1)
  430. << ")\">&#x2192;</a></div></td>";
  431. }
  432. os << "</tr></table>";
  433. }
  434. }
  435. os << "</div></td></tr>";
  436. // Insert the new html.
  437. unsigned DisplayPos = LineEnd - FileStart;
  438. SourceLocation Loc =
  439. SM.getLocForStartOfFile(LPosInfo.first).getLocWithOffset(DisplayPos);
  440. R.InsertTextBefore(Loc, os.str());
  441. // Now highlight the ranges.
  442. ArrayRef<SourceRange> Ranges = P.getRanges();
  443. for (ArrayRef<SourceRange>::iterator I = Ranges.begin(),
  444. E = Ranges.end(); I != E; ++I) {
  445. HighlightRange(R, LPosInfo.first, *I);
  446. }
  447. }
  448. static void EmitAlphaCounter(raw_ostream &os, unsigned n) {
  449. unsigned x = n % ('z' - 'a');
  450. n /= 'z' - 'a';
  451. if (n > 0)
  452. EmitAlphaCounter(os, n);
  453. os << char('a' + x);
  454. }
  455. unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os,
  456. const PathDiagnosticMacroPiece& P,
  457. unsigned num) {
  458. for (PathPieces::const_iterator I = P.subPieces.begin(), E=P.subPieces.end();
  459. I!=E; ++I) {
  460. if (const PathDiagnosticMacroPiece *MP =
  461. dyn_cast<PathDiagnosticMacroPiece>(*I)) {
  462. num = ProcessMacroPiece(os, *MP, num);
  463. continue;
  464. }
  465. if (PathDiagnosticEventPiece *EP = dyn_cast<PathDiagnosticEventPiece>(*I)) {
  466. os << "<div class=\"msg msgEvent\" style=\"width:94%; "
  467. "margin-left:5px\">"
  468. "<table class=\"msgT\"><tr>"
  469. "<td valign=\"top\"><div class=\"PathIndex PathIndexEvent\">";
  470. EmitAlphaCounter(os, num++);
  471. os << "</div></td><td valign=\"top\">"
  472. << html::EscapeText(EP->getString())
  473. << "</td></tr></table></div>\n";
  474. }
  475. }
  476. return num;
  477. }
  478. void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID,
  479. SourceRange Range,
  480. const char *HighlightStart,
  481. const char *HighlightEnd) {
  482. SourceManager &SM = R.getSourceMgr();
  483. const LangOptions &LangOpts = R.getLangOpts();
  484. SourceLocation InstantiationStart = SM.getExpansionLoc(Range.getBegin());
  485. unsigned StartLineNo = SM.getExpansionLineNumber(InstantiationStart);
  486. SourceLocation InstantiationEnd = SM.getExpansionLoc(Range.getEnd());
  487. unsigned EndLineNo = SM.getExpansionLineNumber(InstantiationEnd);
  488. if (EndLineNo < StartLineNo)
  489. return;
  490. if (SM.getFileID(InstantiationStart) != BugFileID ||
  491. SM.getFileID(InstantiationEnd) != BugFileID)
  492. return;
  493. // Compute the column number of the end.
  494. unsigned EndColNo = SM.getExpansionColumnNumber(InstantiationEnd);
  495. unsigned OldEndColNo = EndColNo;
  496. if (EndColNo) {
  497. // Add in the length of the token, so that we cover multi-char tokens.
  498. EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SM, LangOpts)-1;
  499. }
  500. // Highlight the range. Make the span tag the outermost tag for the
  501. // selected range.
  502. SourceLocation E =
  503. InstantiationEnd.getLocWithOffset(EndColNo - OldEndColNo);
  504. html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd);
  505. }