diff options
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp | 90 |
1 files changed, 39 insertions, 51 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp index c6e397fa6aa..b4e73c81e56 100644 --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -1,4 +1,4 @@ -//===--- HTMLDiagnostics.cpp - HTML Diagnostics for Paths ----*- C++ -*-===// +//===- HTMLDiagnostics.cpp - HTML Diagnostics for Paths -------------------===// // // The LLVM Compiler Infrastructure // @@ -11,26 +11,43 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/Stmt.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/Token.h" #include "clang/Rewrite/Core/HTMLRewrite.h" #include "clang/Rewrite/Core/Rewriter.h" +#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" -#include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/IssueHash.h" #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Errc.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cassert> #include <map> +#include <memory> #include <set> #include <sstream> +#include <string> +#include <system_error> +#include <utility> +#include <vector> using namespace clang; using namespace ento; @@ -43,15 +60,19 @@ namespace { class HTMLDiagnostics : public PathDiagnosticConsumer { std::string Directory; - bool createdDir, noDir; + bool createdDir = false; + bool noDir = false; const Preprocessor &PP; AnalyzerOptions &AnalyzerOpts; const bool SupportsCrossFileDiagnostics; + public: HTMLDiagnostics(AnalyzerOptions &AnalyzerOpts, const std::string& prefix, const Preprocessor &pp, - bool supportsMultipleFiles); + bool supportsMultipleFiles) + : Directory(prefix), PP(pp), AnalyzerOpts(AnalyzerOpts), + SupportsCrossFileDiagnostics(supportsMultipleFiles) {} ~HTMLDiagnostics() override { FlushDiagnostics(nullptr); } @@ -98,23 +119,11 @@ public: std::string generateKeyboardNavigationJavascript(); private: - /// \return Javascript for displaying shortcuts help; std::string showHelpJavascript(); }; -} // end anonymous namespace - -HTMLDiagnostics::HTMLDiagnostics(AnalyzerOptions &AnalyzerOpts, - const std::string& prefix, - const Preprocessor &pp, - bool supportsMultipleFiles) - : Directory(prefix), - createdDir(false), - noDir(false), - PP(pp), - AnalyzerOpts(AnalyzerOpts), - SupportsCrossFileDiagnostics(supportsMultipleFiles) {} +} // namespace void ento::createHTMLDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts, PathDiagnosticConsumers &C, @@ -137,24 +146,19 @@ void ento::createHTMLSingleFileDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts, void HTMLDiagnostics::FlushDiagnosticsImpl( std::vector<const PathDiagnostic *> &Diags, FilesMade *filesMade) { - for (std::vector<const PathDiagnostic *>::iterator it = Diags.begin(), - et = Diags.end(); it != et; ++it) { - ReportDiag(**it, filesMade); - } + for (const auto Diag : Diags) + ReportDiag(*Diag, filesMade); } void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, FilesMade *filesMade) { - // Create the HTML directory if it is missing. if (!createdDir) { createdDir = true; if (std::error_code ec = llvm::sys::fs::create_directories(Directory)) { llvm::errs() << "warning: could not create directory '" << Directory << "': " << ec.message() << '\n'; - noDir = true; - return; } } @@ -181,7 +185,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, SmallString<128> declName("unknown"); int offsetDecl = 0; if (const Decl *DeclWithIssue = D.getDeclWithIssue()) { - if (const NamedDecl *ND = dyn_cast<NamedDecl>(DeclWithIssue)) + if (const auto *ND = dyn_cast<NamedDecl>(DeclWithIssue)) declName = ND->getDeclName().getAsString(); if (const Stmt *Body = DeclWithIssue->getBody()) { @@ -219,7 +223,6 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, << "': " << EC.message() << '\n'; return; } - } else { int i = 1; std::error_code EC; @@ -260,7 +263,6 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R, const SourceManager& SMgr, const PathPieces& path, const char *declName) { - // Rewrite source files as HTML for every new file the path crosses std::vector<FileID> FileIDs; for (auto I : path) { @@ -316,7 +318,7 @@ std::string HTMLDiagnostics::GenerateHTML(const PathDiagnostic& D, Rewriter &R, const RewriteBuffer *Buf = R.getRewriteBufferFor(FileIDs[0]); if (!Buf) - return ""; + return {}; // Add CSS, header, and footer. const FileEntry* Entry = SMgr.getFileEntryForID(FileIDs[0]); @@ -335,7 +337,6 @@ static void serializeExecutedLines( const PathDiagnostic &D, const PathPieces &path, llvm::raw_string_ostream &os) { - // Copy executed lines from path diagnostics. std::map<unsigned, std::set<unsigned>> ExecutedLines; for (auto I = D.executedLines_begin(), @@ -501,8 +502,8 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R, // Output any other meta data. - for (PathDiagnostic::meta_iterator I=D.meta_begin(), E=D.meta_end(); - I!=E; ++I) { + for (PathDiagnostic::meta_iterator I = D.meta_begin(), E = D.meta_end(); + I != E; ++I) { os << "<tr><td></td><td>" << html::EscapeText(*I) << "</td></tr>\n"; } @@ -613,9 +614,6 @@ window.addEventListener("keydown", function (event) { )<<<"; } - - - void HTMLDiagnostics::RewriteFile(Rewriter &R, const SourceManager& SMgr, const PathPieces& path, FileID FID) { // Process the path. @@ -660,7 +658,6 @@ void HTMLDiagnostics::RewriteFile(Rewriter &R, const SourceManager& SMgr, void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID, const PathDiagnosticPiece& P, unsigned num, unsigned max) { - // For now, just draw a box above the line in question, and emit the // warning. FullSourceLoc Pos = P.getLocation().asLocation(); @@ -800,9 +797,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID, os << "</td><td>"; } - if (const PathDiagnosticMacroPiece *MP = - dyn_cast<PathDiagnosticMacroPiece>(&P)) { - + if (const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(&P)) { os << "Within the expansion of the macro '"; // Get the name of the macro by relexing it. @@ -873,10 +868,8 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID, // Now highlight the ranges. ArrayRef<SourceRange> Ranges = P.getRanges(); - for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), - E = Ranges.end(); I != E; ++I) { - HighlightRange(R, LPosInfo.first, *I); - } + for (const auto &Range : Ranges) + HighlightRange(R, LPosInfo.first, Range); } static void EmitAlphaCounter(raw_ostream &os, unsigned n) { @@ -892,18 +885,13 @@ static void EmitAlphaCounter(raw_ostream &os, unsigned n) { unsigned HTMLDiagnostics::ProcessMacroPiece(raw_ostream &os, const PathDiagnosticMacroPiece& P, unsigned num) { - - for (PathPieces::const_iterator I = P.subPieces.begin(), E=P.subPieces.end(); - I!=E; ++I) { - - if (const PathDiagnosticMacroPiece *MP = - dyn_cast<PathDiagnosticMacroPiece>(I->get())) { + for (const auto &subPiece : P.subPieces) { + if (const auto *MP = dyn_cast<PathDiagnosticMacroPiece>(subPiece.get())) { num = ProcessMacroPiece(os, *MP, num); continue; } - if (PathDiagnosticEventPiece *EP = - dyn_cast<PathDiagnosticEventPiece>(I->get())) { + if (const auto *EP = dyn_cast<PathDiagnosticEventPiece>(subPiece.get())) { os << "<div class=\"msg msgEvent\" style=\"width:94%; " "margin-left:5px\">" "<table class=\"msgT\"><tr>" |

