From 47abe7690491f28da5978225801ae146810bd388 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 16 Apr 2008 16:39:56 +0000 Subject: [PATCH] Hook up HTMLDiagnostics to use Chris's new syntax highlighting. --html-diags currently doesn't pass in the Preprocessor from the driver, so we don't get syntax highlighting when we create HTMLDiagnostics in that way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49796 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/ASTConsumers.cpp | 35 ++++++++++++++++++++--------------- Driver/ASTConsumers.h | 2 ++ Driver/HTMLDiagnostics.cpp | 21 ++++++++++++++++----- Driver/HTMLDiagnostics.h | 4 +++- Driver/HTMLPrint.cpp | 6 ++++-- Driver/clang.cpp | 6 +++--- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 3f4b4e23d4..16299c46c4 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -624,7 +624,7 @@ ASTConsumer *clang::CreateUnitValsChecker(Diagnostic &Diags) { } //===----------------------------------------------------------------------===// -// CheckeRConsumer - Generic Driver for running intra-procedural path-sensitive +// CheckerConsumer - Generic Driver for running intra-procedural path-sensitive // analyses. namespace { @@ -633,16 +633,18 @@ class CheckerConsumer : public CFGVisitor { protected: Diagnostic &Diags; ASTContext* Ctx; + Preprocessor* PP; const std::string& HTMLDir; bool Visualize; bool TrimGraph; llvm::OwningPtr PD; bool AnalyzeAll; public: - CheckerConsumer(Diagnostic &diags, const std::string& fname, - const std::string& htmldir, - bool visualize, bool trim, bool analyzeAll) - : CFGVisitor(fname), Diags(diags), HTMLDir(htmldir), + CheckerConsumer(Diagnostic &diags, Preprocessor* pp, + const std::string& fname, + const std::string& htmldir, + bool visualize, bool trim, bool analyzeAll) + : CFGVisitor(fname), Diags(diags), PP(pp), HTMLDir(htmldir), Visualize(visualize), TrimGraph(trim), AnalyzeAll(analyzeAll) {} virtual void Initialize(ASTContext &Context) { Ctx = &Context; } @@ -670,7 +672,7 @@ void CheckerConsumer::VisitCFG(CFG& C, Decl& CD) { // Lazily create the diagnostic client. if (!HTMLDir.empty() && PD.get() == NULL) - PD.reset(CreateHTMLDiagnosticClient(HTMLDir)); + PD.reset(CreateHTMLDiagnosticClient(HTMLDir, PP)); if (!Visualize) { @@ -716,10 +718,10 @@ void CheckerConsumer::VisitCFG(CFG& C, Decl& CD) { namespace { class GRSimpleValsVisitor : public CheckerConsumer { public: - GRSimpleValsVisitor(Diagnostic &diags, const std::string& fname, - const std::string& htmldir, + GRSimpleValsVisitor(Diagnostic &diags, Preprocessor* pp, + const std::string& fname, const std::string& htmldir, bool visualize, bool trim, bool analyzeAll) - : CheckerConsumer(diags, fname, htmldir, visualize, trim, analyzeAll) {} + : CheckerConsumer(diags, pp, fname, htmldir, visualize, trim, analyzeAll) {} virtual const char* getCheckerName() { return "GRSimpleVals"; } @@ -730,12 +732,13 @@ public: } // end anonymous namespace ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags, + Preprocessor* PP, const std::string& FunctionName, const std::string& HTMLDir, bool Visualize, bool TrimGraph, bool AnalyzeAll) { - return new GRSimpleValsVisitor(Diags, FunctionName, HTMLDir, + return new GRSimpleValsVisitor(Diags, PP, FunctionName, HTMLDir, Visualize, TrimGraph, AnalyzeAll); } @@ -746,10 +749,11 @@ ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags, namespace { class CFRefCountCheckerVisitor : public CheckerConsumer { public: - CFRefCountCheckerVisitor(Diagnostic &diags, const std::string& fname, - const std::string& htmldir, - bool visualize, bool trim, bool analyzeAll) - : CheckerConsumer(diags, fname, htmldir, visualize, trim, analyzeAll) {} + CFRefCountCheckerVisitor(Diagnostic &diags, Preprocessor* pp, + const std::string& fname, + const std::string& htmldir, + bool visualize, bool trim, bool analyzeAll) + : CheckerConsumer(diags, pp, fname, htmldir, visualize, trim, analyzeAll) {} virtual const char* getCheckerName() { return "CFRefCountChecker"; } @@ -760,12 +764,13 @@ public: } // end anonymous namespace ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags, + Preprocessor* PP, const std::string& FunctionName, const std::string& HTMLDir, bool Visualize, bool TrimGraph, bool AnalyzeAll) { - return new CFRefCountCheckerVisitor(Diags, FunctionName, HTMLDir, + return new CFRefCountCheckerVisitor(Diags, PP, FunctionName, HTMLDir, Visualize, TrimGraph, AnalyzeAll); } diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h index 6054fdf443..391ff02227 100644 --- a/Driver/ASTConsumers.h +++ b/Driver/ASTConsumers.h @@ -44,11 +44,13 @@ ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags); ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags); ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags, + Preprocessor* PP, const std::string& Function, const std::string& HTMLDir, bool Visualize, bool TrimGraph, bool AnalyzeAll); ASTConsumer *CreateCFRefChecker(Diagnostic &Diags, + Preprocessor* PP, const std::string& Function, const std::string& HTMLDir, bool Visualize, bool TrimGraph, bool AnalyzeAll); diff --git a/Driver/HTMLDiagnostics.cpp b/Driver/HTMLDiagnostics.cpp index 327a77f8df..b49586f223 100644 --- a/Driver/HTMLDiagnostics.cpp +++ b/Driver/HTMLDiagnostics.cpp @@ -37,8 +37,9 @@ namespace { class VISIBILITY_HIDDEN HTMLDiagnostics : public PathDiagnosticClient { llvm::sys::Path Directory, FilePrefix; bool createdDir, noDir; + Preprocessor* PP; public: - HTMLDiagnostics(const std::string& prefix); + HTMLDiagnostics(const std::string& prefix, Preprocessor* pp = NULL); virtual ~HTMLDiagnostics() {} @@ -52,17 +53,18 @@ public: } // end anonymous namespace -HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix) - : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false) { +HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp) + : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false), + PP(pp) { // All html files begin with "report" FilePrefix.appendComponent("report"); } PathDiagnosticClient* -clang::CreateHTMLDiagnosticClient(const std::string& prefix) { +clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP) { - return new HTMLDiagnostics(prefix); + return new HTMLDiagnostics(prefix, PP); } //===----------------------------------------------------------------------===// @@ -116,6 +118,15 @@ void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic& D) { html::EscapeText(R, FileID); html::AddLineNumbers(R, FileID); + // If we have a preprocessor, relex the file and syntax highlight. + // We might not have a preprocessor if we come from a deserialized AST file, + // for example. + + if (PP) { + html::SyntaxHighlight(R, FileID, *PP); + html::HighlightMacros(R, FileID, *PP); + } + // Get the full directory name of the analyzed file. const FileEntry* Entry = SMgr.getFileEntryForID(FileID); diff --git a/Driver/HTMLDiagnostics.h b/Driver/HTMLDiagnostics.h index 172c0021c5..146c2cc438 100644 --- a/Driver/HTMLDiagnostics.h +++ b/Driver/HTMLDiagnostics.h @@ -18,8 +18,10 @@ namespace clang { class PathDiagnosticClient; + class Preprocessor; - PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix); + PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix, + Preprocessor* PP); } #endif diff --git a/Driver/HTMLPrint.cpp b/Driver/HTMLPrint.cpp index 2b01489963..54678dea3e 100644 --- a/Driver/HTMLPrint.cpp +++ b/Driver/HTMLPrint.cpp @@ -59,8 +59,10 @@ HTMLPrinter::~HTMLPrinter() { html::AddLineNumbers(R, FileID); html::AddHeaderFooterInternalBuiltinCSS(R, FileID); - // If we have a preprocessor, relex the file and syntax hilight. We might not - // have a preprocessor if we come from a deserialized AST file, for example. + // If we have a preprocessor, relex the file and syntax highlight. + // We might not have a preprocessor if we come from a deserialized AST file, + // for example. + if (PP) { html::SyntaxHighlight(R, FileID, *PP); html::HighlightMacros(R, FileID, *PP); diff --git a/Driver/clang.cpp b/Driver/clang.cpp index a9ae98e555..f6d5fe691a 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -1066,11 +1066,11 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, return CreateUnitValsChecker(Diag); case AnalysisGRSimpleVals: - return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, OutputFile, + return CreateGRSimpleVals(Diag, PP, AnalyzeSpecificFunction, OutputFile, VisualizeEG, TrimGraph, AnalyzeAll); case CheckerCFRef: - return CreateCFRefChecker(Diag, AnalyzeSpecificFunction, OutputFile, + return CreateCFRefChecker(Diag, PP, AnalyzeSpecificFunction, OutputFile, VisualizeEG, TrimGraph, AnalyzeAll); case TestSerialization: @@ -1290,7 +1290,7 @@ int main(int argc, char **argv) { TextDiagnostics* TextDiagClient = NULL; if (!HTMLDiag.empty()) { - DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag)); + DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, NULL)); } else { // Use Text diagnostics. if (!VerifyDiagnostics) { -- 2.40.0