HTMLRewrite.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. //== HTMLRewrite.cpp - Translate source code into prettified HTML --*- 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 HTMLRewriter class, which is used to translate the
  11. // text of a source file into prettified HTML.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "clang/Rewrite/Core/HTMLRewrite.h"
  15. #include "clang/Basic/SourceManager.h"
  16. #include "clang/Lex/Preprocessor.h"
  17. #include "clang/Lex/TokenConcatenation.h"
  18. #include "clang/Rewrite/Core/Rewriter.h"
  19. #include "llvm/ADT/SmallString.h"
  20. #include "llvm/Support/ErrorHandling.h"
  21. #include "llvm/Support/MemoryBuffer.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #include <memory>
  24. using namespace clang;
  25. /// HighlightRange - Highlight a range in the source code with the specified
  26. /// start/end tags. B/E must be in the same file. This ensures that
  27. /// start/end tags are placed at the start/end of each line if the range is
  28. /// multiline.
  29. void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
  30. const char *StartTag, const char *EndTag) {
  31. SourceManager &SM = R.getSourceMgr();
  32. B = SM.getExpansionLoc(B);
  33. E = SM.getExpansionLoc(E);
  34. FileID FID = SM.getFileID(B);
  35. assert(SM.getFileID(E) == FID && "B/E not in the same file!");
  36. unsigned BOffset = SM.getFileOffset(B);
  37. unsigned EOffset = SM.getFileOffset(E);
  38. // Include the whole end token in the range.
  39. EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());
  40. bool Invalid = false;
  41. const char *BufferStart = SM.getBufferData(FID, &Invalid).data();
  42. if (Invalid)
  43. return;
  44. HighlightRange(R.getEditBuffer(FID), BOffset, EOffset,
  45. BufferStart, StartTag, EndTag);
  46. }
  47. /// HighlightRange - This is the same as the above method, but takes
  48. /// decomposed file locations.
  49. void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
  50. const char *BufferStart,
  51. const char *StartTag, const char *EndTag) {
  52. // Insert the tag at the absolute start/end of the range.
  53. RB.InsertTextAfter(B, StartTag);
  54. RB.InsertTextBefore(E, EndTag);
  55. // Scan the range to see if there is a \r or \n. If so, and if the line is
  56. // not blank, insert tags on that line as well.
  57. bool HadOpenTag = true;
  58. unsigned LastNonWhiteSpace = B;
  59. for (unsigned i = B; i != E; ++i) {
  60. switch (BufferStart[i]) {
  61. case '\r':
  62. case '\n':
  63. // Okay, we found a newline in the range. If we have an open tag, we need
  64. // to insert a close tag at the first non-whitespace before the newline.
  65. if (HadOpenTag)
  66. RB.InsertTextBefore(LastNonWhiteSpace+1, EndTag);
  67. // Instead of inserting an open tag immediately after the newline, we
  68. // wait until we see a non-whitespace character. This prevents us from
  69. // inserting tags around blank lines, and also allows the open tag to
  70. // be put *after* whitespace on a non-blank line.
  71. HadOpenTag = false;
  72. break;
  73. case '\0':
  74. case ' ':
  75. case '\t':
  76. case '\f':
  77. case '\v':
  78. // Ignore whitespace.
  79. break;
  80. default:
  81. // If there is no tag open, do it now.
  82. if (!HadOpenTag) {
  83. RB.InsertTextAfter(i, StartTag);
  84. HadOpenTag = true;
  85. }
  86. // Remember this character.
  87. LastNonWhiteSpace = i;
  88. break;
  89. }
  90. }
  91. }
  92. void html::EscapeText(Rewriter &R, FileID FID,
  93. bool EscapeSpaces, bool ReplaceTabs) {
  94. const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
  95. const char* C = Buf->getBufferStart();
  96. const char* FileEnd = Buf->getBufferEnd();
  97. assert (C <= FileEnd);
  98. RewriteBuffer &RB = R.getEditBuffer(FID);
  99. unsigned ColNo = 0;
  100. for (unsigned FilePos = 0; C != FileEnd ; ++C, ++FilePos) {
  101. switch (*C) {
  102. default: ++ColNo; break;
  103. case '\n':
  104. case '\r':
  105. ColNo = 0;
  106. break;
  107. case ' ':
  108. if (EscapeSpaces)
  109. RB.ReplaceText(FilePos, 1, "&nbsp;");
  110. ++ColNo;
  111. break;
  112. case '\f':
  113. RB.ReplaceText(FilePos, 1, "<hr>");
  114. ColNo = 0;
  115. break;
  116. case '\t': {
  117. if (!ReplaceTabs)
  118. break;
  119. unsigned NumSpaces = 8-(ColNo&7);
  120. if (EscapeSpaces)
  121. RB.ReplaceText(FilePos, 1,
  122. StringRef("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  123. "&nbsp;&nbsp;&nbsp;", 6*NumSpaces));
  124. else
  125. RB.ReplaceText(FilePos, 1, StringRef(" ", NumSpaces));
  126. ColNo += NumSpaces;
  127. break;
  128. }
  129. case '<':
  130. RB.ReplaceText(FilePos, 1, "&lt;");
  131. ++ColNo;
  132. break;
  133. case '>':
  134. RB.ReplaceText(FilePos, 1, "&gt;");
  135. ++ColNo;
  136. break;
  137. case '&':
  138. RB.ReplaceText(FilePos, 1, "&amp;");
  139. ++ColNo;
  140. break;
  141. }
  142. }
  143. }
  144. std::string html::EscapeText(StringRef s, bool EscapeSpaces, bool ReplaceTabs) {
  145. unsigned len = s.size();
  146. std::string Str;
  147. llvm::raw_string_ostream os(Str);
  148. for (unsigned i = 0 ; i < len; ++i) {
  149. char c = s[i];
  150. switch (c) {
  151. default:
  152. os << c; break;
  153. case ' ':
  154. if (EscapeSpaces) os << "&nbsp;";
  155. else os << ' ';
  156. break;
  157. case '\t':
  158. if (ReplaceTabs) {
  159. if (EscapeSpaces)
  160. for (unsigned i = 0; i < 4; ++i)
  161. os << "&nbsp;";
  162. else
  163. for (unsigned i = 0; i < 4; ++i)
  164. os << " ";
  165. }
  166. else
  167. os << c;
  168. break;
  169. case '<': os << "&lt;"; break;
  170. case '>': os << "&gt;"; break;
  171. case '&': os << "&amp;"; break;
  172. }
  173. }
  174. return os.str();
  175. }
  176. static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo,
  177. unsigned B, unsigned E) {
  178. SmallString<256> Str;
  179. llvm::raw_svector_ostream OS(Str);
  180. OS << "<tr><td class=\"num\" id=\"LN"
  181. << LineNo << "\">"
  182. << LineNo << "</td><td class=\"line\">";
  183. if (B == E) { // Handle empty lines.
  184. OS << " </td></tr>";
  185. RB.InsertTextBefore(B, OS.str());
  186. } else {
  187. RB.InsertTextBefore(B, OS.str());
  188. RB.InsertTextBefore(E, "</td></tr>");
  189. }
  190. }
  191. void html::AddLineNumbers(Rewriter& R, FileID FID) {
  192. const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
  193. const char* FileBeg = Buf->getBufferStart();
  194. const char* FileEnd = Buf->getBufferEnd();
  195. const char* C = FileBeg;
  196. RewriteBuffer &RB = R.getEditBuffer(FID);
  197. assert (C <= FileEnd);
  198. unsigned LineNo = 0;
  199. unsigned FilePos = 0;
  200. while (C != FileEnd) {
  201. ++LineNo;
  202. unsigned LineStartPos = FilePos;
  203. unsigned LineEndPos = FileEnd - FileBeg;
  204. assert (FilePos <= LineEndPos);
  205. assert (C < FileEnd);
  206. // Scan until the newline (or end-of-file).
  207. while (C != FileEnd) {
  208. char c = *C;
  209. ++C;
  210. if (c == '\n') {
  211. LineEndPos = FilePos++;
  212. break;
  213. }
  214. ++FilePos;
  215. }
  216. AddLineNumber(RB, LineNo, LineStartPos, LineEndPos);
  217. }
  218. // Add one big table tag that surrounds all of the code.
  219. RB.InsertTextBefore(0, "<table class=\"code\">\n");
  220. RB.InsertTextAfter(FileEnd - FileBeg, "</table>");
  221. }
  222. void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID,
  223. StringRef title) {
  224. const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID);
  225. const char* FileStart = Buf->getBufferStart();
  226. const char* FileEnd = Buf->getBufferEnd();
  227. SourceLocation StartLoc = R.getSourceMgr().getLocForStartOfFile(FID);
  228. SourceLocation EndLoc = StartLoc.getLocWithOffset(FileEnd-FileStart);
  229. std::string s;
  230. llvm::raw_string_ostream os(s);
  231. os << "<!doctype html>\n" // Use HTML 5 doctype
  232. "<html>\n<head>\n";
  233. if (!title.empty())
  234. os << "<title>" << html::EscapeText(title) << "</title>\n";
  235. os << "<style type=\"text/css\">\n"
  236. " body { color:#000000; background-color:#ffffff }\n"
  237. " body { font-family:Helvetica, sans-serif; font-size:10pt }\n"
  238. " h1 { font-size:14pt }\n"
  239. " .code { border-collapse:collapse; width:100%; }\n"
  240. " .code { font-family: \"Monospace\", monospace; font-size:10pt }\n"
  241. " .code { line-height: 1.2em }\n"
  242. " .comment { color: green; font-style: oblique }\n"
  243. " .keyword { color: blue }\n"
  244. " .string_literal { color: red }\n"
  245. " .directive { color: darkmagenta }\n"
  246. // Macro expansions.
  247. " .expansion { display: none; }\n"
  248. " .macro:hover .expansion { display: block; border: 2px solid #FF0000; "
  249. "padding: 2px; background-color:#FFF0F0; font-weight: normal; "
  250. " -webkit-border-radius:5px; -webkit-box-shadow:1px 1px 7px #000; "
  251. " border-radius:5px; box-shadow:1px 1px 7px #000; "
  252. "position: absolute; top: -1em; left:10em; z-index: 1 } \n"
  253. " .macro { color: darkmagenta; background-color:LemonChiffon;"
  254. // Macros are position: relative to provide base for expansions.
  255. " position: relative }\n"
  256. " .num { width:2.5em; padding-right:2ex; background-color:#eeeeee }\n"
  257. " .num { text-align:right; font-size:8pt }\n"
  258. " .num { color:#444444 }\n"
  259. " .line { padding-left: 1ex; border-left: 3px solid #ccc }\n"
  260. " .line { white-space: pre }\n"
  261. " .msg { -webkit-box-shadow:1px 1px 7px #000 }\n"
  262. " .msg { box-shadow:1px 1px 7px #000 }\n"
  263. " .msg { -webkit-border-radius:5px }\n"
  264. " .msg { border-radius:5px }\n"
  265. " .msg { font-family:Helvetica, sans-serif; font-size:8pt }\n"
  266. " .msg { float:left }\n"
  267. " .msg { padding:0.25em 1ex 0.25em 1ex }\n"
  268. " .msg { margin-top:10px; margin-bottom:10px }\n"
  269. " .msg { font-weight:bold }\n"
  270. " .msg { max-width:60em; word-wrap: break-word; white-space: pre-wrap }\n"
  271. " .msgT { padding:0x; spacing:0x }\n"
  272. " .msgEvent { background-color:#fff8b4; color:#000000 }\n"
  273. " .msgControl { background-color:#bbbbbb; color:#000000 }\n"
  274. " .msgNote { background-color:#ddeeff; color:#000000 }\n"
  275. " .mrange { background-color:#dfddf3 }\n"
  276. " .mrange { border-bottom:1px solid #6F9DBE }\n"
  277. " .PathIndex { font-weight: bold; padding:0px 5px; "
  278. "margin-right:5px; }\n"
  279. " .PathIndex { -webkit-border-radius:8px }\n"
  280. " .PathIndex { border-radius:8px }\n"
  281. " .PathIndexEvent { background-color:#bfba87 }\n"
  282. " .PathIndexControl { background-color:#8c8c8c }\n"
  283. " .PathNav a { text-decoration:none; font-size: larger }\n"
  284. " .CodeInsertionHint { font-weight: bold; background-color: #10dd10 }\n"
  285. " .CodeRemovalHint { background-color:#de1010 }\n"
  286. " .CodeRemovalHint { border-bottom:1px solid #6F9DBE }\n"
  287. " table.simpletable {\n"
  288. " padding: 5px;\n"
  289. " font-size:12pt;\n"
  290. " margin:20px;\n"
  291. " border-collapse: collapse; border-spacing: 0px;\n"
  292. " }\n"
  293. " td.rowname {\n"
  294. " text-align: right;\n"
  295. " vertical-align: top;\n"
  296. " font-weight: bold;\n"
  297. " color:#444444;\n"
  298. " padding-right:2ex;\n"
  299. " }\n"
  300. "</style>\n</head>\n<body>";
  301. // Generate header
  302. R.InsertTextBefore(StartLoc, os.str());
  303. // Generate footer
  304. R.InsertTextAfter(EndLoc, "</body></html>\n");
  305. }
  306. /// SyntaxHighlight - Relex the specified FileID and annotate the HTML with
  307. /// information about keywords, macro expansions etc. This uses the macro
  308. /// table state from the end of the file, so it won't be perfectly perfect,
  309. /// but it will be reasonably close.
  310. void html::SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP) {
  311. RewriteBuffer &RB = R.getEditBuffer(FID);
  312. const SourceManager &SM = PP.getSourceManager();
  313. const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
  314. Lexer L(FID, FromFile, SM, PP.getLangOpts());
  315. const char *BufferStart = L.getBuffer().data();
  316. // Inform the preprocessor that we want to retain comments as tokens, so we
  317. // can highlight them.
  318. L.SetCommentRetentionState(true);
  319. // Lex all the tokens in raw mode, to avoid entering #includes or expanding
  320. // macros.
  321. Token Tok;
  322. L.LexFromRawLexer(Tok);
  323. while (Tok.isNot(tok::eof)) {
  324. // Since we are lexing unexpanded tokens, all tokens are from the main
  325. // FileID.
  326. unsigned TokOffs = SM.getFileOffset(Tok.getLocation());
  327. unsigned TokLen = Tok.getLength();
  328. switch (Tok.getKind()) {
  329. default: break;
  330. case tok::identifier:
  331. llvm_unreachable("tok::identifier in raw lexing mode!");
  332. case tok::raw_identifier: {
  333. // Fill in Result.IdentifierInfo and update the token kind,
  334. // looking up the identifier in the identifier table.
  335. PP.LookUpIdentifierInfo(Tok);
  336. // If this is a pp-identifier, for a keyword, highlight it as such.
  337. if (Tok.isNot(tok::identifier))
  338. HighlightRange(RB, TokOffs, TokOffs+TokLen, BufferStart,
  339. "<span class='keyword'>", "</span>");
  340. break;
  341. }
  342. case tok::comment:
  343. HighlightRange(RB, TokOffs, TokOffs+TokLen, BufferStart,
  344. "<span class='comment'>", "</span>");
  345. break;
  346. case tok::utf8_string_literal:
  347. // Chop off the u part of u8 prefix
  348. ++TokOffs;
  349. --TokLen;
  350. // FALL THROUGH to chop the 8
  351. case tok::wide_string_literal:
  352. case tok::utf16_string_literal:
  353. case tok::utf32_string_literal:
  354. // Chop off the L, u, U or 8 prefix
  355. ++TokOffs;
  356. --TokLen;
  357. // FALL THROUGH.
  358. case tok::string_literal:
  359. // FIXME: Exclude the optional ud-suffix from the highlighted range.
  360. HighlightRange(RB, TokOffs, TokOffs+TokLen, BufferStart,
  361. "<span class='string_literal'>", "</span>");
  362. break;
  363. case tok::hash: {
  364. // If this is a preprocessor directive, all tokens to end of line are too.
  365. if (!Tok.isAtStartOfLine())
  366. break;
  367. // Eat all of the tokens until we get to the next one at the start of
  368. // line.
  369. unsigned TokEnd = TokOffs+TokLen;
  370. L.LexFromRawLexer(Tok);
  371. while (!Tok.isAtStartOfLine() && Tok.isNot(tok::eof)) {
  372. TokEnd = SM.getFileOffset(Tok.getLocation())+Tok.getLength();
  373. L.LexFromRawLexer(Tok);
  374. }
  375. // Find end of line. This is a hack.
  376. HighlightRange(RB, TokOffs, TokEnd, BufferStart,
  377. "<span class='directive'>", "</span>");
  378. // Don't skip the next token.
  379. continue;
  380. }
  381. }
  382. L.LexFromRawLexer(Tok);
  383. }
  384. }
  385. /// HighlightMacros - This uses the macro table state from the end of the
  386. /// file, to re-expand macros and insert (into the HTML) information about the
  387. /// macro expansions. This won't be perfectly perfect, but it will be
  388. /// reasonably close.
  389. void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor& PP) {
  390. // Re-lex the raw token stream into a token buffer.
  391. const SourceManager &SM = PP.getSourceManager();
  392. std::vector<Token> TokenStream;
  393. const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
  394. Lexer L(FID, FromFile, SM, PP.getLangOpts());
  395. // Lex all the tokens in raw mode, to avoid entering #includes or expanding
  396. // macros.
  397. while (1) {
  398. Token Tok;
  399. L.LexFromRawLexer(Tok);
  400. // If this is a # at the start of a line, discard it from the token stream.
  401. // We don't want the re-preprocess step to see #defines, #includes or other
  402. // preprocessor directives.
  403. if (Tok.is(tok::hash) && Tok.isAtStartOfLine())
  404. continue;
  405. // If this is a ## token, change its kind to unknown so that repreprocessing
  406. // it will not produce an error.
  407. if (Tok.is(tok::hashhash))
  408. Tok.setKind(tok::unknown);
  409. // If this raw token is an identifier, the raw lexer won't have looked up
  410. // the corresponding identifier info for it. Do this now so that it will be
  411. // macro expanded when we re-preprocess it.
  412. if (Tok.is(tok::raw_identifier))
  413. PP.LookUpIdentifierInfo(Tok);
  414. TokenStream.push_back(Tok);
  415. if (Tok.is(tok::eof)) break;
  416. }
  417. // Temporarily change the diagnostics object so that we ignore any generated
  418. // diagnostics from this pass.
  419. DiagnosticsEngine TmpDiags(PP.getDiagnostics().getDiagnosticIDs(),
  420. &PP.getDiagnostics().getDiagnosticOptions(),
  421. new IgnoringDiagConsumer);
  422. // FIXME: This is a huge hack; we reuse the input preprocessor because we want
  423. // its state, but we aren't actually changing it (we hope). This should really
  424. // construct a copy of the preprocessor.
  425. Preprocessor &TmpPP = const_cast<Preprocessor&>(PP);
  426. DiagnosticsEngine *OldDiags = &TmpPP.getDiagnostics();
  427. TmpPP.setDiagnostics(TmpDiags);
  428. // Inform the preprocessor that we don't want comments.
  429. TmpPP.SetCommentRetentionState(false, false);
  430. // We don't want pragmas either. Although we filtered out #pragma, removing
  431. // _Pragma and __pragma is much harder.
  432. bool PragmasPreviouslyEnabled = TmpPP.getPragmasEnabled();
  433. TmpPP.setPragmasEnabled(false);
  434. // Enter the tokens we just lexed. This will cause them to be macro expanded
  435. // but won't enter sub-files (because we removed #'s).
  436. TmpPP.EnterTokenStream(TokenStream, false);
  437. TokenConcatenation ConcatInfo(TmpPP);
  438. // Lex all the tokens.
  439. Token Tok;
  440. TmpPP.Lex(Tok);
  441. while (Tok.isNot(tok::eof)) {
  442. // Ignore non-macro tokens.
  443. if (!Tok.getLocation().isMacroID()) {
  444. TmpPP.Lex(Tok);
  445. continue;
  446. }
  447. // Okay, we have the first token of a macro expansion: highlight the
  448. // expansion by inserting a start tag before the macro expansion and
  449. // end tag after it.
  450. std::pair<SourceLocation, SourceLocation> LLoc =
  451. SM.getExpansionRange(Tok.getLocation());
  452. // Ignore tokens whose instantiation location was not the main file.
  453. if (SM.getFileID(LLoc.first) != FID) {
  454. TmpPP.Lex(Tok);
  455. continue;
  456. }
  457. assert(SM.getFileID(LLoc.second) == FID &&
  458. "Start and end of expansion must be in the same ultimate file!");
  459. std::string Expansion = EscapeText(TmpPP.getSpelling(Tok));
  460. unsigned LineLen = Expansion.size();
  461. Token PrevPrevTok;
  462. Token PrevTok = Tok;
  463. // Okay, eat this token, getting the next one.
  464. TmpPP.Lex(Tok);
  465. // Skip all the rest of the tokens that are part of this macro
  466. // instantiation. It would be really nice to pop up a window with all the
  467. // spelling of the tokens or something.
  468. while (!Tok.is(tok::eof) &&
  469. SM.getExpansionLoc(Tok.getLocation()) == LLoc.first) {
  470. // Insert a newline if the macro expansion is getting large.
  471. if (LineLen > 60) {
  472. Expansion += "<br>";
  473. LineLen = 0;
  474. }
  475. LineLen -= Expansion.size();
  476. // If the tokens were already space separated, or if they must be to avoid
  477. // them being implicitly pasted, add a space between them.
  478. if (Tok.hasLeadingSpace() ||
  479. ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok))
  480. Expansion += ' ';
  481. // Escape any special characters in the token text.
  482. Expansion += EscapeText(TmpPP.getSpelling(Tok));
  483. LineLen += Expansion.size();
  484. PrevPrevTok = PrevTok;
  485. PrevTok = Tok;
  486. TmpPP.Lex(Tok);
  487. }
  488. // Insert the expansion as the end tag, so that multi-line macros all get
  489. // highlighted.
  490. Expansion = "<span class='expansion'>" + Expansion + "</span></span>";
  491. HighlightRange(R, LLoc.first, LLoc.second,
  492. "<span class='macro'>", Expansion.c_str());
  493. }
  494. // Restore the preprocessor's old state.
  495. TmpPP.setDiagnostics(*OldDiags);
  496. TmpPP.setPragmasEnabled(PragmasPreviouslyEnabled);
  497. }