Path: blob/main/contrib/llvm-project/clang/lib/Rewrite/HTMLRewrite.cpp
35232 views
//== HTMLRewrite.cpp - Translate source code into prettified HTML --*- C++ -*-//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the HTMLRewriter class, which is used to translate the9// text of a source file into prettified HTML.10//11//===----------------------------------------------------------------------===//1213#include "clang/Rewrite/Core/HTMLRewrite.h"14#include "clang/Basic/SourceManager.h"15#include "clang/Lex/Preprocessor.h"16#include "clang/Lex/TokenConcatenation.h"17#include "clang/Rewrite/Core/Rewriter.h"18#include "llvm/ADT/SmallString.h"19#include "llvm/Support/ErrorHandling.h"20#include "llvm/Support/MemoryBuffer.h"21#include "llvm/Support/raw_ostream.h"22#include <memory>2324using namespace clang;25using namespace llvm;26using namespace html;2728/// HighlightRange - Highlight a range in the source code with the specified29/// start/end tags. B/E must be in the same file. This ensures that30/// start/end tags are placed at the start/end of each line if the range is31/// multiline.32void html::HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,33const char *StartTag, const char *EndTag,34bool IsTokenRange) {35SourceManager &SM = R.getSourceMgr();36B = SM.getExpansionLoc(B);37E = SM.getExpansionLoc(E);38FileID FID = SM.getFileID(B);39assert(SM.getFileID(E) == FID && "B/E not in the same file!");4041unsigned BOffset = SM.getFileOffset(B);42unsigned EOffset = SM.getFileOffset(E);4344// Include the whole end token in the range.45if (IsTokenRange)46EOffset += Lexer::MeasureTokenLength(E, R.getSourceMgr(), R.getLangOpts());4748bool Invalid = false;49const char *BufferStart = SM.getBufferData(FID, &Invalid).data();50if (Invalid)51return;5253HighlightRange(R.getEditBuffer(FID), BOffset, EOffset,54BufferStart, StartTag, EndTag);55}5657/// HighlightRange - This is the same as the above method, but takes58/// decomposed file locations.59void html::HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,60const char *BufferStart,61const char *StartTag, const char *EndTag) {62// Insert the tag at the absolute start/end of the range.63RB.InsertTextAfter(B, StartTag);64RB.InsertTextBefore(E, EndTag);6566// Scan the range to see if there is a \r or \n. If so, and if the line is67// not blank, insert tags on that line as well.68bool HadOpenTag = true;6970unsigned LastNonWhiteSpace = B;71for (unsigned i = B; i != E; ++i) {72switch (BufferStart[i]) {73case '\r':74case '\n':75// Okay, we found a newline in the range. If we have an open tag, we need76// to insert a close tag at the first non-whitespace before the newline.77if (HadOpenTag)78RB.InsertTextBefore(LastNonWhiteSpace+1, EndTag);7980// Instead of inserting an open tag immediately after the newline, we81// wait until we see a non-whitespace character. This prevents us from82// inserting tags around blank lines, and also allows the open tag to83// be put *after* whitespace on a non-blank line.84HadOpenTag = false;85break;86case '\0':87case ' ':88case '\t':89case '\f':90case '\v':91// Ignore whitespace.92break;9394default:95// If there is no tag open, do it now.96if (!HadOpenTag) {97RB.InsertTextAfter(i, StartTag);98HadOpenTag = true;99}100101// Remember this character.102LastNonWhiteSpace = i;103break;104}105}106}107108namespace clang::html {109struct RelexRewriteCache {110// These structs mimic input arguments of HighlightRange().111struct Highlight {112SourceLocation B, E;113std::string StartTag, EndTag;114bool IsTokenRange;115};116struct RawHighlight {117unsigned B, E;118std::string StartTag, EndTag;119};120121// SmallVector isn't appropriate because these vectors are almost never small.122using HighlightList = std::vector<Highlight>;123using RawHighlightList = std::vector<RawHighlight>;124125DenseMap<FileID, RawHighlightList> SyntaxHighlights;126DenseMap<FileID, HighlightList> MacroHighlights;127};128} // namespace clang::html129130html::RelexRewriteCacheRef html::instantiateRelexRewriteCache() {131return std::make_shared<RelexRewriteCache>();132}133134void html::EscapeText(Rewriter &R, FileID FID,135bool EscapeSpaces, bool ReplaceTabs) {136137llvm::MemoryBufferRef Buf = R.getSourceMgr().getBufferOrFake(FID);138const char* C = Buf.getBufferStart();139const char* FileEnd = Buf.getBufferEnd();140141assert (C <= FileEnd);142143RewriteBuffer &RB = R.getEditBuffer(FID);144145unsigned ColNo = 0;146for (unsigned FilePos = 0; C != FileEnd ; ++C, ++FilePos) {147switch (*C) {148default: ++ColNo; break;149case '\n':150case '\r':151ColNo = 0;152break;153154case ' ':155if (EscapeSpaces)156RB.ReplaceText(FilePos, 1, " ");157++ColNo;158break;159case '\f':160RB.ReplaceText(FilePos, 1, "<hr>");161ColNo = 0;162break;163164case '\t': {165if (!ReplaceTabs)166break;167unsigned NumSpaces = 8-(ColNo&7);168if (EscapeSpaces)169RB.ReplaceText(FilePos, 1,170StringRef(" "171" ", 6*NumSpaces));172else173RB.ReplaceText(FilePos, 1, StringRef(" ", NumSpaces));174ColNo += NumSpaces;175break;176}177case '<':178RB.ReplaceText(FilePos, 1, "<");179++ColNo;180break;181182case '>':183RB.ReplaceText(FilePos, 1, ">");184++ColNo;185break;186187case '&':188RB.ReplaceText(FilePos, 1, "&");189++ColNo;190break;191}192}193}194195std::string html::EscapeText(StringRef s, bool EscapeSpaces, bool ReplaceTabs) {196197unsigned len = s.size();198std::string Str;199llvm::raw_string_ostream os(Str);200201for (unsigned i = 0 ; i < len; ++i) {202203char c = s[i];204switch (c) {205default:206os << c; break;207208case ' ':209if (EscapeSpaces) os << " ";210else os << ' ';211break;212213case '\t':214if (ReplaceTabs) {215if (EscapeSpaces)216for (unsigned i = 0; i < 4; ++i)217os << " ";218else219for (unsigned i = 0; i < 4; ++i)220os << " ";221}222else223os << c;224225break;226227case '<': os << "<"; break;228case '>': os << ">"; break;229case '&': os << "&"; break;230}231}232233return Str;234}235236static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo,237unsigned B, unsigned E) {238SmallString<256> Str;239llvm::raw_svector_ostream OS(Str);240241OS << "<tr class=\"codeline\" data-linenumber=\"" << LineNo << "\">"242<< "<td class=\"num\" id=\"LN" << LineNo << "\">" << LineNo243<< "</td><td class=\"line\">";244245if (B == E) { // Handle empty lines.246OS << " </td></tr>";247RB.InsertTextBefore(B, OS.str());248} else {249RB.InsertTextBefore(B, OS.str());250RB.InsertTextBefore(E, "</td></tr>");251}252}253254void html::AddLineNumbers(Rewriter& R, FileID FID) {255256llvm::MemoryBufferRef Buf = R.getSourceMgr().getBufferOrFake(FID);257const char* FileBeg = Buf.getBufferStart();258const char* FileEnd = Buf.getBufferEnd();259const char* C = FileBeg;260RewriteBuffer &RB = R.getEditBuffer(FID);261262assert (C <= FileEnd);263264unsigned LineNo = 0;265unsigned FilePos = 0;266267while (C != FileEnd) {268269++LineNo;270unsigned LineStartPos = FilePos;271unsigned LineEndPos = FileEnd - FileBeg;272273assert (FilePos <= LineEndPos);274assert (C < FileEnd);275276// Scan until the newline (or end-of-file).277278while (C != FileEnd) {279char c = *C;280++C;281282if (c == '\n') {283LineEndPos = FilePos++;284break;285}286287++FilePos;288}289290AddLineNumber(RB, LineNo, LineStartPos, LineEndPos);291}292293// Add one big table tag that surrounds all of the code.294std::string s;295llvm::raw_string_ostream os(s);296os << "<table class=\"code\" data-fileid=\"" << FID.getHashValue() << "\">\n";297RB.InsertTextBefore(0, os.str());298RB.InsertTextAfter(FileEnd - FileBeg, "</table>");299}300301void html::AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID,302StringRef title) {303304llvm::MemoryBufferRef Buf = R.getSourceMgr().getBufferOrFake(FID);305const char* FileStart = Buf.getBufferStart();306const char* FileEnd = Buf.getBufferEnd();307308SourceLocation StartLoc = R.getSourceMgr().getLocForStartOfFile(FID);309SourceLocation EndLoc = StartLoc.getLocWithOffset(FileEnd-FileStart);310311std::string s;312llvm::raw_string_ostream os(s);313os << "<!doctype html>\n" // Use HTML 5 doctype314"<html>\n<head>\n";315316if (!title.empty())317os << "<title>" << html::EscapeText(title) << "</title>\n";318319os << R"<<<(320<style type="text/css">321body { color:#000000; background-color:#ffffff }322body { font-family:Helvetica, sans-serif; font-size:10pt }323h1 { font-size:14pt }324.FileName { margin-top: 5px; margin-bottom: 5px; display: inline; }325.FileNav { margin-left: 5px; margin-right: 5px; display: inline; }326.FileNav a { text-decoration:none; font-size: larger; }327.divider { margin-top: 30px; margin-bottom: 30px; height: 15px; }328.divider { background-color: gray; }329.code { border-collapse:collapse; width:100%; }330.code { font-family: "Monospace", monospace; font-size:10pt }331.code { line-height: 1.2em }332.comment { color: green; font-style: oblique }333.keyword { color: blue }334.string_literal { color: red }335.directive { color: darkmagenta }336337/* Macros and variables could have pop-up notes hidden by default.338- Macro pop-up: expansion of the macro339- Variable pop-up: value (table) of the variable */340.macro_popup, .variable_popup { display: none; }341342/* Pop-up appears on mouse-hover event. */343.macro:hover .macro_popup, .variable:hover .variable_popup {344display: block;345padding: 2px;346-webkit-border-radius:5px;347-webkit-box-shadow:1px 1px 7px #000;348border-radius:5px;349box-shadow:1px 1px 7px #000;350position: absolute;351top: -1em;352left:10em;353z-index: 1354}355356.macro_popup {357border: 2px solid red;358background-color:#FFF0F0;359font-weight: normal;360}361362.variable_popup {363border: 2px solid blue;364background-color:#F0F0FF;365font-weight: bold;366font-family: Helvetica, sans-serif;367font-size: 9pt;368}369370/* Pop-up notes needs a relative position as a base where they pops up. */371.macro, .variable {372background-color: PaleGoldenRod;373position: relative;374}375.macro { color: DarkMagenta; }376377#tooltiphint {378position: fixed;379width: 50em;380margin-left: -25em;381left: 50%;382padding: 10px;383border: 1px solid #b0b0b0;384border-radius: 2px;385box-shadow: 1px 1px 7px black;386background-color: #c0c0c0;387z-index: 2;388}389390.num { width:2.5em; padding-right:2ex; background-color:#eeeeee }391.num { text-align:right; font-size:8pt }392.num { color:#444444 }393.line { padding-left: 1ex; border-left: 3px solid #ccc }394.line { white-space: pre }395.msg { -webkit-box-shadow:1px 1px 7px #000 }396.msg { box-shadow:1px 1px 7px #000 }397.msg { -webkit-border-radius:5px }398.msg { border-radius:5px }399.msg { font-family:Helvetica, sans-serif; font-size:8pt }400.msg { float:left }401.msg { position:relative }402.msg { padding:0.25em 1ex 0.25em 1ex }403.msg { margin-top:10px; margin-bottom:10px }404.msg { font-weight:bold }405.msg { max-width:60em; word-wrap: break-word; white-space: pre-wrap }406.msgT { padding:0x; spacing:0x }407.msgEvent { background-color:#fff8b4; color:#000000 }408.msgControl { background-color:#bbbbbb; color:#000000 }409.msgNote { background-color:#ddeeff; color:#000000 }410.mrange { background-color:#dfddf3 }411.mrange { border-bottom:1px solid #6F9DBE }412.PathIndex { font-weight: bold; padding:0px 5px; margin-right:5px; }413.PathIndex { -webkit-border-radius:8px }414.PathIndex { border-radius:8px }415.PathIndexEvent { background-color:#bfba87 }416.PathIndexControl { background-color:#8c8c8c }417.PathIndexPopUp { background-color: #879abc; }418.PathNav a { text-decoration:none; font-size: larger }419.CodeInsertionHint { font-weight: bold; background-color: #10dd10 }420.CodeRemovalHint { background-color:#de1010 }421.CodeRemovalHint { border-bottom:1px solid #6F9DBE }422.msg.selected{ background-color:orange !important; }423424table.simpletable {425padding: 5px;426font-size:12pt;427margin:20px;428border-collapse: collapse; border-spacing: 0px;429}430td.rowname {431text-align: right;432vertical-align: top;433font-weight: bold;434color:#444444;435padding-right:2ex;436}437438/* Hidden text. */439input.spoilerhider + label {440cursor: pointer;441text-decoration: underline;442display: block;443}444input.spoilerhider {445display: none;446}447input.spoilerhider ~ .spoiler {448overflow: hidden;449margin: 10px auto 0;450height: 0;451opacity: 0;452}453input.spoilerhider:checked + label + .spoiler{454height: auto;455opacity: 1;456}457</style>458</head>459<body>)<<<";460461// Generate header462R.InsertTextBefore(StartLoc, os.str());463// Generate footer464465R.InsertTextAfter(EndLoc, "</body></html>\n");466}467468/// SyntaxHighlight - Relex the specified FileID and annotate the HTML with469/// information about keywords, macro expansions etc. This uses the macro470/// table state from the end of the file, so it won't be perfectly perfect,471/// but it will be reasonably close.472static void SyntaxHighlightImpl(473Rewriter &R, FileID FID, const Preprocessor &PP,474llvm::function_ref<void(RewriteBuffer &, unsigned, unsigned, const char *,475const char *, const char *)>476HighlightRangeCallback) {477478RewriteBuffer &RB = R.getEditBuffer(FID);479const SourceManager &SM = PP.getSourceManager();480llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(FID);481const char *BufferStart = FromFile.getBuffer().data();482483Lexer L(FID, FromFile, SM, PP.getLangOpts());484485// Inform the preprocessor that we want to retain comments as tokens, so we486// can highlight them.487L.SetCommentRetentionState(true);488489// Lex all the tokens in raw mode, to avoid entering #includes or expanding490// macros.491Token Tok;492L.LexFromRawLexer(Tok);493494while (Tok.isNot(tok::eof)) {495// Since we are lexing unexpanded tokens, all tokens are from the main496// FileID.497unsigned TokOffs = SM.getFileOffset(Tok.getLocation());498unsigned TokLen = Tok.getLength();499switch (Tok.getKind()) {500default: break;501case tok::identifier:502llvm_unreachable("tok::identifier in raw lexing mode!");503case tok::raw_identifier: {504// Fill in Result.IdentifierInfo and update the token kind,505// looking up the identifier in the identifier table.506PP.LookUpIdentifierInfo(Tok);507508// If this is a pp-identifier, for a keyword, highlight it as such.509if (Tok.isNot(tok::identifier))510HighlightRangeCallback(RB, TokOffs, TokOffs + TokLen, BufferStart,511"<span class='keyword'>", "</span>");512break;513}514case tok::comment:515HighlightRangeCallback(RB, TokOffs, TokOffs + TokLen, BufferStart,516"<span class='comment'>", "</span>");517break;518case tok::utf8_string_literal:519// Chop off the u part of u8 prefix520++TokOffs;521--TokLen;522// FALL THROUGH to chop the 8523[[fallthrough]];524case tok::wide_string_literal:525case tok::utf16_string_literal:526case tok::utf32_string_literal:527// Chop off the L, u, U or 8 prefix528++TokOffs;529--TokLen;530[[fallthrough]];531case tok::string_literal:532// FIXME: Exclude the optional ud-suffix from the highlighted range.533HighlightRangeCallback(RB, TokOffs, TokOffs + TokLen, BufferStart,534"<span class='string_literal'>", "</span>");535break;536case tok::hash: {537// If this is a preprocessor directive, all tokens to end of line are too.538if (!Tok.isAtStartOfLine())539break;540541// Eat all of the tokens until we get to the next one at the start of542// line.543unsigned TokEnd = TokOffs+TokLen;544L.LexFromRawLexer(Tok);545while (!Tok.isAtStartOfLine() && Tok.isNot(tok::eof)) {546TokEnd = SM.getFileOffset(Tok.getLocation())+Tok.getLength();547L.LexFromRawLexer(Tok);548}549550// Find end of line. This is a hack.551HighlightRangeCallback(RB, TokOffs, TokEnd, BufferStart,552"<span class='directive'>", "</span>");553554// Don't skip the next token.555continue;556}557}558559L.LexFromRawLexer(Tok);560}561}562void html::SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP,563RelexRewriteCacheRef Cache) {564RewriteBuffer &RB = R.getEditBuffer(FID);565const SourceManager &SM = PP.getSourceManager();566llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(FID);567const char *BufferStart = FromFile.getBuffer().data();568569if (Cache) {570auto CacheIt = Cache->SyntaxHighlights.find(FID);571if (CacheIt != Cache->SyntaxHighlights.end()) {572for (const RelexRewriteCache::RawHighlight &H : CacheIt->second) {573HighlightRange(RB, H.B, H.E, BufferStart, H.StartTag.data(),574H.EndTag.data());575}576return;577}578}579580// "Every time you would call HighlightRange, cache the inputs as well."581auto HighlightRangeCallback = [&](RewriteBuffer &RB, unsigned B, unsigned E,582const char *BufferStart,583const char *StartTag, const char *EndTag) {584HighlightRange(RB, B, E, BufferStart, StartTag, EndTag);585586if (Cache)587Cache->SyntaxHighlights[FID].push_back({B, E, StartTag, EndTag});588};589590SyntaxHighlightImpl(R, FID, PP, HighlightRangeCallback);591}592593static void HighlightMacrosImpl(594Rewriter &R, FileID FID, const Preprocessor &PP,595llvm::function_ref<void(Rewriter &, SourceLocation, SourceLocation,596const char *, const char *, bool)>597HighlightRangeCallback) {598599// Re-lex the raw token stream into a token buffer.600const SourceManager &SM = PP.getSourceManager();601std::vector<Token> TokenStream;602603llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(FID);604Lexer L(FID, FromFile, SM, PP.getLangOpts());605606// Lex all the tokens in raw mode, to avoid entering #includes or expanding607// macros.608while (true) {609Token Tok;610L.LexFromRawLexer(Tok);611612// If this is a # at the start of a line, discard it from the token stream.613// We don't want the re-preprocess step to see #defines, #includes or other614// preprocessor directives.615if (Tok.is(tok::hash) && Tok.isAtStartOfLine())616continue;617618// If this is a ## token, change its kind to unknown so that repreprocessing619// it will not produce an error.620if (Tok.is(tok::hashhash))621Tok.setKind(tok::unknown);622623// If this raw token is an identifier, the raw lexer won't have looked up624// the corresponding identifier info for it. Do this now so that it will be625// macro expanded when we re-preprocess it.626if (Tok.is(tok::raw_identifier))627PP.LookUpIdentifierInfo(Tok);628629TokenStream.push_back(Tok);630631if (Tok.is(tok::eof)) break;632}633634// Temporarily change the diagnostics object so that we ignore any generated635// diagnostics from this pass.636DiagnosticsEngine TmpDiags(PP.getDiagnostics().getDiagnosticIDs(),637&PP.getDiagnostics().getDiagnosticOptions(),638new IgnoringDiagConsumer);639640// FIXME: This is a huge hack; we reuse the input preprocessor because we want641// its state, but we aren't actually changing it (we hope). This should really642// construct a copy of the preprocessor.643Preprocessor &TmpPP = const_cast<Preprocessor&>(PP);644DiagnosticsEngine *OldDiags = &TmpPP.getDiagnostics();645TmpPP.setDiagnostics(TmpDiags);646647// Inform the preprocessor that we don't want comments.648TmpPP.SetCommentRetentionState(false, false);649650// We don't want pragmas either. Although we filtered out #pragma, removing651// _Pragma and __pragma is much harder.652bool PragmasPreviouslyEnabled = TmpPP.getPragmasEnabled();653TmpPP.setPragmasEnabled(false);654655// Enter the tokens we just lexed. This will cause them to be macro expanded656// but won't enter sub-files (because we removed #'s).657TmpPP.EnterTokenStream(TokenStream, false, /*IsReinject=*/false);658659TokenConcatenation ConcatInfo(TmpPP);660661// Lex all the tokens.662Token Tok;663TmpPP.Lex(Tok);664while (Tok.isNot(tok::eof)) {665// Ignore non-macro tokens.666if (!Tok.getLocation().isMacroID()) {667TmpPP.Lex(Tok);668continue;669}670671// Okay, we have the first token of a macro expansion: highlight the672// expansion by inserting a start tag before the macro expansion and673// end tag after it.674CharSourceRange LLoc = SM.getExpansionRange(Tok.getLocation());675676// Ignore tokens whose instantiation location was not the main file.677if (SM.getFileID(LLoc.getBegin()) != FID) {678TmpPP.Lex(Tok);679continue;680}681682assert(SM.getFileID(LLoc.getEnd()) == FID &&683"Start and end of expansion must be in the same ultimate file!");684685std::string Expansion = EscapeText(TmpPP.getSpelling(Tok));686unsigned LineLen = Expansion.size();687688Token PrevPrevTok;689Token PrevTok = Tok;690// Okay, eat this token, getting the next one.691TmpPP.Lex(Tok);692693// Skip all the rest of the tokens that are part of this macro694// instantiation. It would be really nice to pop up a window with all the695// spelling of the tokens or something.696while (!Tok.is(tok::eof) &&697SM.getExpansionLoc(Tok.getLocation()) == LLoc.getBegin()) {698// Insert a newline if the macro expansion is getting large.699if (LineLen > 60) {700Expansion += "<br>";701LineLen = 0;702}703704LineLen -= Expansion.size();705706// If the tokens were already space separated, or if they must be to avoid707// them being implicitly pasted, add a space between them.708if (Tok.hasLeadingSpace() ||709ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok))710Expansion += ' ';711712// Escape any special characters in the token text.713Expansion += EscapeText(TmpPP.getSpelling(Tok));714LineLen += Expansion.size();715716PrevPrevTok = PrevTok;717PrevTok = Tok;718TmpPP.Lex(Tok);719}720721// Insert the 'macro_popup' as the end tag, so that multi-line macros all722// get highlighted.723Expansion = "<span class='macro_popup'>" + Expansion + "</span></span>";724725HighlightRangeCallback(R, LLoc.getBegin(), LLoc.getEnd(),726"<span class='macro'>", Expansion.c_str(),727LLoc.isTokenRange());728}729730// Restore the preprocessor's old state.731TmpPP.setDiagnostics(*OldDiags);732TmpPP.setPragmasEnabled(PragmasPreviouslyEnabled);733}734735/// HighlightMacros - This uses the macro table state from the end of the736/// file, to re-expand macros and insert (into the HTML) information about the737/// macro expansions. This won't be perfectly perfect, but it will be738/// reasonably close.739void html::HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP,740RelexRewriteCacheRef Cache) {741if (Cache) {742auto CacheIt = Cache->MacroHighlights.find(FID);743if (CacheIt != Cache->MacroHighlights.end()) {744for (const RelexRewriteCache::Highlight &H : CacheIt->second) {745HighlightRange(R, H.B, H.E, H.StartTag.data(), H.EndTag.data(),746H.IsTokenRange);747}748return;749}750}751752// "Every time you would call HighlightRange, cache the inputs as well."753auto HighlightRangeCallback = [&](Rewriter &R, SourceLocation B,754SourceLocation E, const char *StartTag,755const char *EndTag, bool isTokenRange) {756HighlightRange(R, B, E, StartTag, EndTag, isTokenRange);757758if (Cache) {759Cache->MacroHighlights[FID].push_back(760{B, E, StartTag, EndTag, isTokenRange});761}762};763764HighlightMacrosImpl(R, FID, PP, HighlightRangeCallback);765}766767768