29 #include "llvm/ADT/ArrayRef.h" 30 #include "llvm/ADT/SmallString.h" 31 #include "llvm/ADT/StringRef.h" 32 #include "llvm/ADT/iterator_range.h" 33 #include "llvm/Support/Casting.h" 34 #include "llvm/Support/Errc.h" 35 #include "llvm/Support/ErrorHandling.h" 36 #include "llvm/Support/FileSystem.h" 37 #include "llvm/Support/MemoryBuffer.h" 38 #include "llvm/Support/Path.h" 39 #include "llvm/Support/raw_ostream.h" 47 #include <system_error> 51 using namespace clang;
60 class HTMLDiagnostics :
public PathDiagnosticConsumer {
61 std::string Directory;
62 bool createdDir =
false;
66 const bool SupportsCrossFileDiagnostics;
70 const std::string& prefix,
72 bool supportsMultipleFiles)
73 : Directory(prefix), PP(pp), AnalyzerOpts(AnalyzerOpts),
74 SupportsCrossFileDiagnostics(supportsMultipleFiles) {}
76 ~HTMLDiagnostics()
override { FlushDiagnostics(
nullptr); }
78 void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
79 FilesMade *filesMade)
override;
81 StringRef
getName()
const override {
82 return "HTMLDiagnostics";
85 bool supportsCrossFileDiagnostics()
const override {
86 return SupportsCrossFileDiagnostics;
89 unsigned ProcessMacroPiece(raw_ostream &os,
90 const PathDiagnosticMacroPiece&
P,
93 void HandlePiece(
Rewriter &R,
FileID BugFileID,
const PathDiagnosticPiece &
P,
94 const std::vector<SourceRange> &PopUpRanges,
unsigned num,
98 const char *HighlightStart =
"<span class=\"mrange\">",
99 const char *HighlightEnd =
"</span>");
101 void ReportDiag(
const PathDiagnostic& D,
102 FilesMade *filesMade);
105 std::string GenerateHTML(
const PathDiagnostic& D,
Rewriter &R,
107 const char *declName);
110 void FinalizeHTML(
const PathDiagnostic& D,
Rewriter &R,
115 void RewriteFile(
Rewriter &R,
const PathPieces& path,
FileID FID);
120 StringRef showHelpJavascript();
123 StringRef generateKeyboardNavigationJavascript();
126 std::string showRelevantLinesJavascript(
127 const PathDiagnostic &D,
const PathPieces &path);
130 void dumpCoverageData(
const PathDiagnostic &D,
131 const PathPieces &path,
132 llvm::raw_string_ostream &os);
139 const std::string& prefix,
141 C.push_back(
new HTMLDiagnostics(AnalyzerOpts, prefix, PP,
true));
144 void ento::createHTMLSingleFileDiagnosticConsumer(
AnalyzerOptions &AnalyzerOpts,
146 const std::string& prefix,
148 C.push_back(
new HTMLDiagnostics(AnalyzerOpts, prefix, PP,
false));
155 void HTMLDiagnostics::FlushDiagnosticsImpl(
156 std::vector<const PathDiagnostic *> &Diags,
157 FilesMade *filesMade) {
158 for (
const auto Diag : Diags)
159 ReportDiag(*
Diag, filesMade);
162 void HTMLDiagnostics::ReportDiag(
const PathDiagnostic& D,
163 FilesMade *filesMade) {
167 if (std::error_code ec = llvm::sys::fs::create_directories(Directory)) {
168 llvm::errs() <<
"warning: could not create directory '" 169 << Directory <<
"': " << ec.message() <<
'\n';
179 PathPieces path = D.path.flatten(
false);
182 assert(!path.empty());
183 const SourceManager &SMgr = path.front()->getLocation().getManager();
191 FileID ReportFile = path.front()->getLocation().asLocation().getExpansionLoc().getFileID();
196 if (
const Decl *DeclWithIssue = D.getDeclWithIssue()) {
197 if (
const auto *ND = dyn_cast<NamedDecl>(DeclWithIssue))
198 declName = ND->getDeclName().getAsString();
200 if (
const Stmt *Body = DeclWithIssue->getBody()) {
204 SMgr.getExpansionLoc(path.back()->getLocation().asLocation()),
206 FullSourceLoc FunL(SMgr.getExpansionLoc(Body->getBeginLoc()), SMgr);
207 offsetDecl = L.getExpansionLineNumber() - FunL.getExpansionLineNumber();
211 std::string report = GenerateHTML(D, R, SMgr, path, declName.c_str());
212 if (report.empty()) {
213 llvm::errs() <<
"warning: no diagnostics generated for main file.\n";
221 if (!AnalyzerOpts.ShouldWriteStableReportFilename) {
222 llvm::sys::path::append(Model, Directory,
"report-%%%%%%.html");
223 if (std::error_code EC =
224 llvm::sys::fs::make_absolute(Model)) {
225 llvm::errs() <<
"warning: could not make '" << Model
226 <<
"' absolute: " << EC.message() <<
'\n';
229 if (std::error_code EC =
230 llvm::sys::fs::createUniqueFile(Model, FD, ResultPath)) {
231 llvm::errs() <<
"warning: could not create file in '" << Directory
232 <<
"': " << EC.message() <<
'\n';
240 const FileEntry* Entry = SMgr.getFileEntryForID(ReportFile);
241 std::stringstream filename;
243 filename <<
"report-" 244 << llvm::sys::path::filename(Entry->
getName()).str()
245 <<
"-" << declName.c_str()
247 <<
"-" << i <<
".html";
248 llvm::sys::path::append(Model, Directory,
250 EC = llvm::sys::fs::openFileForReadWrite(
251 Model, FD, llvm::sys::fs::CD_CreateNew, llvm::sys::fs::OF_None);
252 if (EC && EC != llvm::errc::file_exists) {
253 llvm::errs() <<
"warning: could not create file '" << Model
254 <<
"': " << EC.message() <<
'\n';
261 llvm::raw_fd_ostream os(FD,
true);
264 filesMade->addDiagnostic(D,
getName(),
265 llvm::sys::path::filename(ResultPath));
271 std::string HTMLDiagnostics::GenerateHTML(
const PathDiagnostic& D,
Rewriter &R,
272 const SourceManager& SMgr,
const PathPieces& path,
const char *declName) {
274 std::vector<FileID> FileIDs;
275 for (
auto I : path) {
276 FileID FID = I->getLocation().asLocation().getExpansionLoc().getFileID();
277 if (llvm::is_contained(FileIDs, FID))
280 FileIDs.push_back(FID);
281 RewriteFile(R, path, FID);
284 if (SupportsCrossFileDiagnostics && FileIDs.size() > 1) {
286 for (
auto I = FileIDs.begin(), E = FileIDs.end(); I != E; I++) {
288 llvm::raw_string_ostream os(s);
290 if (I != FileIDs.begin())
291 os <<
"<hr class=divider>\n";
293 os <<
"<div id=File" << I->getHashValue() <<
">\n";
296 if (I != FileIDs.begin())
297 os <<
"<div class=FileNav><a href=\"#File" << (I - 1)->getHashValue()
298 <<
"\">←</a></div>";
305 os <<
"<div class=FileNav><a href=\"#File" << (I + 1)->getHashValue()
306 <<
"\">→</a></div>";
314 for (
auto I : llvm::make_range(FileIDs.begin() + 1, FileIDs.end())) {
316 llvm::raw_string_ostream os(s);
332 path.back()->getLocation().asLocation().getExpansionLoc().getFileID();
334 FinalizeHTML(D, R, SMgr, path, FileIDs[0], Entry, declName);
337 llvm::raw_string_ostream os(file);
344 void HTMLDiagnostics::dumpCoverageData(
345 const PathDiagnostic &D,
346 const PathPieces &path,
347 llvm::raw_string_ostream &os) {
351 os <<
"var relevant_lines = {";
352 for (
auto I = ExecutedLines.begin(),
353 E = ExecutedLines.end(); I != E; ++I) {
354 if (I != ExecutedLines.begin())
357 os <<
"\"" << I->first.getHashValue() <<
"\": {";
358 for (
unsigned LineNo : I->second) {
359 if (LineNo != *(I->second.begin()))
362 os <<
"\"" << LineNo <<
"\": 1";
370 std::string HTMLDiagnostics::showRelevantLinesJavascript(
371 const PathDiagnostic &D,
const PathPieces &path) {
373 llvm::raw_string_ostream os(s);
374 os <<
"<script type='text/javascript'>\n";
375 dumpCoverageData(D, path, os);
378 var filterCounterexample = function (hide) { 379 var tables = document.getElementsByClassName("code"); 380 for (var t=0; t<tables.length; t++) { 381 var table = tables[t]; 382 var file_id = table.getAttribute("data-fileid"); 383 var lines_in_fid = relevant_lines[file_id]; 387 var lines = table.getElementsByClassName("codeline"); 388 for (var i=0; i<lines.length; i++) { 390 var lineNo = el.getAttribute("data-linenumber"); 391 if (!lines_in_fid[lineNo]) { 393 el.setAttribute("hidden", ""); 395 el.removeAttribute("hidden"); 402 window.addEventListener("keydown", function (event) { 403 if (event.defaultPrevented) { 406 if (event.key == "S") { 407 var checked = document.getElementsByName("showCounterexample")[0].checked; 408 filterCounterexample(!checked); 409 document.getElementsByName("showCounterexample")[0].checked = !checked; 413 event.preventDefault(); 416 document.addEventListener("DOMContentLoaded", function() { 417 document.querySelector('input[name="showCounterexample"]').onchange= 419 filterCounterexample(this.checked); 425 <input type="checkbox" name="showCounterexample" id="showCounterexample" /> 426 <label for="showCounterexample"> 427 Show only relevant lines 435 void HTMLDiagnostics::FinalizeHTML(
const PathDiagnostic& D,
Rewriter &R,
437 const FileEntry *Entry,
const char *declName) {
444 if (llvm::sys::path::is_relative(Entry->
getName())) {
445 llvm::sys::fs::current_path(DirName);
449 int LineNumber = path.back()->getLocation().asLocation().getExpansionLineNumber();
450 int ColumnNumber = path.back()->getLocation().asLocation().getExpansionColumnNumber();
455 generateKeyboardNavigationJavascript());
459 showRelevantLinesJavascript(D, path));
464 llvm::raw_string_ostream os(s);
466 os <<
"<!-- REPORTHEADER -->\n" 467 <<
"<h3>Bug Summary</h3>\n<table class=\"simpletable\">\n" 468 "<tr><td class=\"rowname\">File:</td><td>" 471 <<
"</td></tr>\n<tr><td class=\"rowname\">Warning:</td><td>" 472 "<a href=\"#EndPath\">line " 477 << D.getVerboseDescription() <<
"</td></tr>\n";
480 unsigned NumExtraPieces = 0;
481 for (
const auto &Piece : path) {
482 if (
const auto *
P = dyn_cast<PathDiagnosticNotePiece>(Piece.get())) {
484 P->getLocation().asLocation().getExpansionLineNumber();
486 P->getLocation().asLocation().getExpansionColumnNumber();
487 os <<
"<tr><td class=\"rowname\">Note:</td><td>" 488 <<
"<a href=\"#Note" << NumExtraPieces <<
"\">line " 489 << LineNumber <<
", column " << ColumnNumber <<
"</a><br />" 490 <<
P->getString() <<
"</td></tr>";
504 <!-- REPORTSUMMARYEXTRA --> 505 <h3>Annotated Source Code</h3> 506 <p>Press <a href="#" onclick="toggleHelp(); return false;">'?'</a> 507 to see keyboard shortcuts</p> 508 <input type="checkbox" class="spoilerhider" id="showinvocation" /> 509 <label for="showinvocation" >Show analyzer invocation</label> 510 <div class="spoiler">clang -cc1 )<<<"; 514 <div id='tooltiphint' hidden="true"> 515 <p>Keyboard shortcuts: </p> 517 <li>Use 'j/k' keys for keyboard navigation</li> 518 <li>Use 'Shift+S' to show/hide relevant lines</li> 519 <li>Use '?' to toggle this window</li> 521 <a href="#" onclick="toggleHelp(); return false;">Close</a> 530 llvm::raw_string_ostream os(s);
532 StringRef BugDesc = D.getVerboseDescription();
533 if (!BugDesc.empty())
534 os <<
"\n<!-- BUGDESC " << BugDesc <<
" -->\n";
536 StringRef BugType = D.getBugType();
537 if (!BugType.empty())
538 os <<
"\n<!-- BUGTYPE " << BugType <<
" -->\n";
540 PathDiagnosticLocation UPDLoc = D.getUniqueingLoc();
542 ? UPDLoc.asLocation()
543 : D.getLocation().asLocation()),
545 const Decl *DeclWithIssue = D.getDeclWithIssue();
547 StringRef BugCategory = D.getCategory();
548 if (!BugCategory.empty())
549 os <<
"\n<!-- BUGCATEGORY " << BugCategory <<
" -->\n";
551 os <<
"\n<!-- BUGFILE " << DirName << Entry->
getName() <<
" -->\n";
553 os <<
"\n<!-- FILENAME " << llvm::sys::path::filename(Entry->
getName()) <<
" -->\n";
555 os <<
"\n<!-- FUNCTIONNAME " << declName <<
" -->\n";
557 os <<
"\n<!-- ISSUEHASHCONTENTOFLINEINCONTEXT " 558 <<
GetIssueHash(SMgr, L, D.getCheckName(), D.getBugType(), DeclWithIssue,
561 os <<
"\n<!-- BUGLINE " 565 os <<
"\n<!-- BUGCOLUMN " 569 os <<
"\n<!-- BUGPATHLENGTH " << path.size() <<
" -->\n";
572 os <<
"\n<!-- BUGMETAEND -->\n";
581 StringRef HTMLDiagnostics::showHelpJavascript() {
583 <script type='text/javascript'> 585 var toggleHelp = function() { 586 var hint = document.querySelector("#tooltiphint"); 587 var attributeName = "hidden"; 588 if (hint.hasAttribute(attributeName)) { 589 hint.removeAttribute(attributeName); 591 hint.setAttribute("hidden", "true"); 594 window.addEventListener("keydown", function (event) { 595 if (event.defaultPrevented) { 598 if (event.key == "?") { 603 event.preventDefault(); 611 const std::vector<SourceRange> &PopUpRanges) {
612 for (
const auto &Range : PopUpRanges) {
614 "<table class='variable_popup'><tbody>",
620 const PathDiagnosticPopUpPiece &Piece,
621 std::vector<SourceRange> &PopUpRanges,
622 unsigned int LastReportedPieceIndex,
623 unsigned int PopUpPieceIndex) {
625 llvm::raw_svector_ostream Out(Buf);
630 Out <<
"<tr><td valign='top'><div class='PathIndex PathIndexPopUp'>" 631 << LastReportedPieceIndex;
634 Out <<
'.' << PopUpPieceIndex;
636 Out <<
"</div></td><td>" << Piece.getString() <<
"</td></tr>";
639 if (std::find(PopUpRanges.begin(), PopUpRanges.end(), Range) ==
642 PopUpRanges.push_back(Range);
644 Out <<
"</tbody></table></span>";
646 "<span class='variable'>", Buf.c_str(),
656 void HTMLDiagnostics::RewriteFile(
Rewriter &R,
657 const PathPieces& path,
FileID FID) {
660 unsigned TotalPieces = path.size();
661 unsigned TotalNotePieces =
662 std::count_if(path.begin(), path.end(),
663 [](
const std::shared_ptr<PathDiagnosticPiece> &
p) {
664 return isa<PathDiagnosticNotePiece>(*p);
666 unsigned PopUpPieceCount =
667 std::count_if(path.begin(), path.end(),
668 [](
const std::shared_ptr<PathDiagnosticPiece> &
p) {
669 return isa<PathDiagnosticPopUpPiece>(*p);
672 unsigned TotalRegularPieces = TotalPieces - TotalNotePieces - PopUpPieceCount;
673 unsigned NumRegularPieces = TotalRegularPieces;
674 unsigned NumNotePieces = TotalNotePieces;
676 std::map<int, int> IndexMap;
679 std::vector<SourceRange> PopUpRanges;
680 for (
auto I = path.rbegin(), E = path.rend(); I != E; ++I) {
681 const auto &Piece = *I->get();
683 if (isa<PathDiagnosticPopUpPiece>(Piece)) {
684 ++IndexMap[NumRegularPieces];
685 }
else if (isa<PathDiagnosticNotePiece>(Piece)) {
689 HandlePiece(R, FID, Piece, PopUpRanges, NumNotePieces, TotalNotePieces);
692 HandlePiece(R, FID, Piece, PopUpRanges, NumRegularPieces,
700 NumRegularPieces = TotalRegularPieces;
701 for (
auto I = path.rbegin(), E = path.rend(); I != E; ++I) {
702 const auto &Piece = *I->get();
704 if (
const auto *PopUpP = dyn_cast<PathDiagnosticPopUpPiece>(&Piece)) {
705 int PopUpPieceIndex = IndexMap[NumRegularPieces];
715 if (PopUpPieceIndex > 0)
716 --IndexMap[NumRegularPieces];
718 }
else if (!isa<PathDiagnosticNotePiece>(Piece)) {
738 const PathDiagnosticPiece &
P,
739 const std::vector<SourceRange> &PopUpRanges,
740 unsigned num,
unsigned max) {
749 assert(&Pos.
getManager() == &SM &&
"SourceManagers are different!");
752 if (LPosInfo.first != BugFileID)
755 const llvm::MemoryBuffer *Buf = SM.
getBuffer(LPosInfo.first);
756 const char* FileStart = Buf->getBufferStart();
762 const char *LineStart = TokInstantiationPtr-ColNo;
765 const char *LineEnd = TokInstantiationPtr;
766 const char* FileEnd = Buf->getBufferEnd();
767 while (*LineEnd !=
'\n' && LineEnd != FileEnd)
772 for (
const char*
c = LineStart;
c != TokInstantiationPtr; ++
c)
773 PosNo += *
c ==
'\t' ? 8 : 1;
777 const char *
Kind =
nullptr;
779 bool SuppressIndex = (max == 1);
780 switch (P.getKind()) {
788 SuppressIndex =
true;
792 llvm_unreachable(
"Calls and extra notes should already be handled");
796 llvm::raw_string_ostream os(sbuf);
798 os <<
"\n<tr><td class=\"num\"></td><td class=\"line\"><div id=\"";
807 os <<
"\" class=\"msg";
809 os <<
" msg" <<
Kind;
810 os <<
"\" style=\"margin-left:" << PosNo <<
"ex";
813 if (!isa<PathDiagnosticMacroPiece>(P)) {
815 const auto &Msg = P.getString();
816 unsigned max_token = 0;
818 unsigned len = Msg.size();
828 if (cnt > max_token) max_token = cnt;
837 const unsigned max_line = 120;
839 if (max_token >= max_line)
842 unsigned characters = max_line;
843 unsigned lines = len / max_line;
846 for (; characters > max_token; --characters)
847 if (len / characters > lines) {
857 os <<
"; max-width:" << em <<
"em";
860 os <<
"; max-width:100em";
864 if (!SuppressIndex) {
865 os <<
"<table class=\"msgT\"><tr><td valign=\"top\">";
866 os <<
"<div class=\"PathIndex";
867 if (Kind) os <<
" PathIndex" <<
Kind;
868 os <<
"\">" << num <<
"</div>";
871 os <<
"</td><td><div class=\"PathNav\"><a href=\"#Path" 873 <<
"\" title=\"Previous event (" 875 <<
")\">←</a></div></td>";
881 if (
const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(&P)) {
882 os <<
"Within the expansion of the macro '";
890 const char* MacroName = LocInfo.second + BufferInfo.data();
892 BufferInfo.begin(), MacroName, BufferInfo.end());
895 rawLexer.LexFromRawLexer(TheTok);
896 for (
unsigned i = 0, n = TheTok.getLength(); i < n; ++
i)
902 if (!SuppressIndex) {
905 os <<
"<td><div class=\"PathNav\"><a href=\"#";
909 os <<
"Path" << (num + 1);
910 os <<
"\" title=\"Next event (" 912 <<
")\">→</a></div></td>";
915 os <<
"</tr></table>";
919 ProcessMacroPiece(os, *MP, 0);
924 if (!SuppressIndex) {
927 os <<
"<td><div class=\"PathNav\"><a href=\"#";
931 os <<
"Path" << (num + 1);
932 os <<
"\" title=\"Next event (" 934 <<
")\">→</a></div></td>";
937 os <<
"</tr></table>";
941 os <<
"</div></td></tr>";
944 unsigned DisplayPos = LineEnd - FileStart;
952 for (
const auto &Range : Ranges) {
954 if (std::find(PopUpRanges.begin(), PopUpRanges.end(), Range) !=
963 unsigned x = n % (
'z' -
'a');
972 unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os,
973 const PathDiagnosticMacroPiece& P,
975 for (
const auto &subPiece : P.subPieces) {
976 if (
const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(subPiece.get())) {
977 num = ProcessMacroPiece(os, *MP, num);
981 if (
const auto *EP = dyn_cast<PathDiagnosticEventPiece>(subPiece.get())) {
982 os <<
"<div class=\"msg msgEvent\" style=\"width:94%; " 984 "<table class=\"msgT\"><tr>" 985 "<td valign=\"top\"><div class=\"PathIndex PathIndexEvent\">";
987 os <<
"</div></td><td valign=\"top\">" 989 <<
"</td></tr></table></div>\n";
998 const char *HighlightStart,
999 const char *HighlightEnd) {
1009 if (EndLineNo < StartLineNo)
1012 if (SM.
getFileID(InstantiationStart) != BugFileID ||
1013 SM.
getFileID(InstantiationEnd) != BugFileID)
1018 unsigned OldEndColNo = EndColNo;
1034 StringRef HTMLDiagnostics::generateKeyboardNavigationJavascript() {
1036 <script type='text/javascript'> 1037 var digitMatcher = new RegExp("[0-9]+"); 1039 document.addEventListener("DOMContentLoaded", function() { 1040 document.querySelectorAll(".PathNav > a").forEach( 1041 function(currentValue, currentIndex) { 1042 var hrefValue = currentValue.getAttribute("href"); 1043 currentValue.onclick = function() { 1044 scrollTo(document.querySelector(hrefValue)); 1050 var findNum = function() { 1051 var s = document.querySelector(".selected"); 1052 if (!s || s.id == "EndPath") { 1055 var out = parseInt(digitMatcher.exec(s.id)[0]); 1059 var scrollTo = function(el) { 1060 document.querySelectorAll(".selected").forEach(function(s) { 1061 s.classList.remove("selected"); 1063 el.classList.add("selected"); 1064 window.scrollBy(0, el.getBoundingClientRect().top - 1065 (window.innerHeight / 2)); 1068 var move = function(num, up, numItems) { 1069 if (num == 1 && up || num == numItems - 1 && !up) { 1071 } else if (num == 0 && up) { 1072 return numItems - 1; 1073 } else if (num == 0 && !up) { 1074 return 1 % numItems; 1076 return up ? num - 1 : num + 1; 1079 var numToId = function(num) { 1081 return document.getElementById("EndPath") 1083 return document.getElementById("Path" + num); 1086 var navigateTo = function(up) { 1087 var numItems = document.querySelectorAll( 1088 ".line > .msgEvent, .line > .msgControl").length; 1089 var currentSelected = findNum(); 1090 var newSelected = move(currentSelected, up, numItems); 1091 var newEl = numToId(newSelected, numItems); 1093 // Scroll element into center. 1097 window.addEventListener("keydown", function (event) { 1098 if (event.defaultPrevented) { 1101 if (event.key == "j") { 1102 navigateTo(/*up=*/false); 1103 } else if (event.key == "k") { 1104 navigateTo(/*up=*/true); 1108 event.preventDefault(); SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
Defines the clang::FileManager interface and associated types.
FullSourceLoc getExpansionLoc() const
Stmt - This represents one statement.
Defines the SourceManager interface.
Decl - This represents one declaration (or definition), e.g.
unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Return the column # for the specified file position.
llvm::SmallString< 32 > GetIssueHash(const SourceManager &SM, FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef BugType, const Decl *D, const LangOptions &LangOpts)
Get an MD5 hash to help identify bugs.
RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a...
void HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP)
HighlightMacros - This uses the macro table state from the end of the file, to reexpand macros and in...
void AddLineNumbers(Rewriter &R, FileID FID)
Token - This structure provides full information about a lexed token.
__DEVICE__ int max(int __a, int __b)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const LangOptions & getLangOpts() const
std::pair< FileID, unsigned > getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
static void HandlePopUpPieceStartTag(Rewriter &R, const std::vector< SourceRange > &PopUpRanges)
SourceManager & getSourceMgr() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
std::string FullCompilerInvocation
Store full compiler invocation for reproducible instructions in the generated report.
void SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP)
SyntaxHighlight - Relex the specified FileID and annotate the HTML with information about keywords...
static void HandlePopUpPieceEndTag(Rewriter &R, const PathDiagnosticPopUpPiece &Piece, std::vector< SourceRange > &PopUpRanges, unsigned int LastReportedPieceIndex, unsigned int PopUpPieceIndex)
std::pair< FileID, unsigned > getDecomposedLoc() const
Decompose the specified location into a raw FileID + Offset pair.
static unsigned MeasureTokenLength(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
MeasureTokenLength - Relex the token at the specified location and return its length in bytes in the ...
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
static void EmitAlphaCounter(raw_ostream &os, unsigned n)
const char * getCharacterData(bool *Invalid=nullptr) const
Defines the clang::Preprocessor interface.
const SourceManager & getManager() const
SourceLocation getEnd() const
std::map< FileID, std::set< unsigned > > FilesToLineNumsMap
File IDs mapped to sets of line numbers.
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
Encodes a location in the source.
StringRef getName() const
std::vector< PathDiagnosticConsumer * > PathDiagnosticConsumers
void EscapeText(Rewriter &R, FileID FID, bool EscapeSpaces=false, bool ReplaceTabs=false)
EscapeText - HTMLize a specified file so that special characters are are translated so that they are ...
bool InsertTextAfter(SourceLocation Loc, StringRef Str)
InsertTextAfter - Insert the specified string at the specified location in the original buffer...
Cached information about one file (either on disk or in the virtual file system). ...
std::deque< std::string >::const_iterator meta_iterator
const RewriteBuffer * getRewriteBufferFor(FileID FID) const
getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
StringRef getBufferData(bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
bool InsertTextBefore(SourceLocation Loc, StringRef Str)
InsertText - Insert the specified string at the specified location in the original buffer...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
unsigned getExpansionColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
const llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
static std::string getName(const CallEvent &Call)
void AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID, StringRef title)
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
const LangOptions & getLangOpts() const
Stores options for the analyzer from the command line.
Rewriter - This is the main interface to the rewrite buffers.
Defines the clang::SourceLocation class and associated facilities.
void HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E, const char *StartTag, const char *EndTag, bool IsTokenRange=true)
HighlightRange - Highlight a range in the source code with the specified start/end tags...
A SourceLocation and its associated SourceManager.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.