From: Ted Kremenek Date: Wed, 2 Jul 2008 16:49:11 +0000 (+0000) Subject: Migrate CheckerConsumer diagnostics to the new AnalysisConsumer interface. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34d7734b6ed1d9c0f647405e065251eb67f42bad;p=clang Migrate CheckerConsumer diagnostics to the new AnalysisConsumer interface. Remove CheckerConsumer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53029 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index a25468794d..fb8dc80a3d 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -634,104 +634,6 @@ ASTConsumer *clang::CreateLiveVarAnalyzer(const std::string& fname) { return new LivenessVisitor(fname); } -//===----------------------------------------------------------------------===// -// CheckerConsumer - Generic Driver for running intra-procedural path-sensitive -// analyses. - -namespace { - -class CheckerConsumer : public CFGVisitor { -protected: - Diagnostic &Diags; - ASTContext* Ctx; - Preprocessor* PP; - PreprocessorFactory* PPF; - const std::string& HTMLDir; - bool Visualize; - bool TrimGraph; - llvm::OwningPtr PD; - bool AnalyzeAll; -public: - CheckerConsumer(Diagnostic &diags, Preprocessor* pp, PreprocessorFactory* ppf, - const std::string& fname, - const std::string& htmldir, - bool visualize, bool trim, bool analyzeAll) - : CFGVisitor(fname), Diags(diags), PP(pp), PPF(ppf), HTMLDir(htmldir), - Visualize(visualize), TrimGraph(trim), AnalyzeAll(analyzeAll) {} - - virtual void Initialize(ASTContext &Context) { Ctx = &Context; } - virtual void VisitCFG(CFG& C, Decl&); - virtual bool printFuncDeclStart() { return false; } - - virtual const char* getCheckerName() = 0; - virtual void getTransferFunctions(std::vector& TFs) = 0; -}; -} // end anonymous namespace - -void CheckerConsumer::VisitCFG(CFG& C, Decl& CD) { - - if (Diags.hasErrorOccurred()) - return; - - SourceLocation Loc = CD.getLocation(); - - if (!Loc.isFileID()) - return; - - if (!AnalyzeAll && !Ctx->getSourceManager().isFromMainFile(Loc)) - return; - - // Lazily create the diagnostic client. - - if (!HTMLDir.empty() && PD.get() == NULL) - PD.reset(CreateHTMLDiagnosticClient(HTMLDir, PP, PPF)); - - - if (!Visualize) { - - if (FunctionDecl *FD = dyn_cast(&CD)) { - llvm::cerr << "ANALYZE: " - << Ctx->getSourceManager().getSourceName(FD->getLocation()) - << ' ' - << FD->getIdentifier()->getName() - << '\n'; - } - else if (ObjCMethodDecl *MD = dyn_cast(&CD)) { - llvm::cerr << "ANALYZE (ObjC Method): " - << Ctx->getSourceManager().getSourceName(MD->getLocation()) - << " '" - << MD->getSelector().getName() << "'\n"; - } - } - else - llvm::cerr << '\n'; - - std::vector TFs; - getTransferFunctions(TFs); - - while (!TFs.empty()) { - - // Construct the analysis engine. - GRExprEngine Eng(C, CD, *Ctx); - - // Set base transfer functions. - llvm::OwningPtr TF(TFs.back()); - TFs.pop_back(); - - Eng.setTransferFunctions(TF.get()); - - // Execute the worklist algorithm. - Eng.ExecuteWorkList(); - - // Display warnings. - Eng.EmitWarnings(Diags, PD.get()); - - #ifndef NDEBUG - if (Visualize) Eng.ViewGraph(TrimGraph); - #endif - } -} - //===----------------------------------------------------------------------===// // AST Serializer diff --git a/Driver/AnalysisConsumer.cpp b/Driver/AnalysisConsumer.cpp index ea2418610e..2f2e76e677 100644 --- a/Driver/AnalysisConsumer.cpp +++ b/Driver/AnalysisConsumer.cpp @@ -29,6 +29,7 @@ #include "clang/Analysis/LocalCheckers.h" #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" #include "clang/Analysis/PathSensitive/GRExprEngine.h" +#include "llvm/Support/Streams.h" using namespace clang; @@ -101,6 +102,7 @@ namespace { Decl* D; Stmt* Body; AnalysisConsumer& C; + bool DisplayedFunction; llvm::OwningPtr cfg; llvm::OwningPtr liveness; @@ -109,7 +111,7 @@ namespace { public: AnalysisManager(AnalysisConsumer& c, Decl* d, Stmt* b) - : D(d), Body(b), C(c) {} + : D(d), Body(b), C(c), DisplayedFunction(false) {} Decl* getCodeDecl() const { return D; } @@ -148,6 +150,36 @@ namespace { if (!liveness) liveness.reset(new LiveVariables(*getCFG())); return liveness.get(); } + + bool shouldVisualize() const { + return C.Visualize; + } + + bool shouldTrimGraph() const { + return C.TrimGraph; + } + + void DisplayFunction() { + + if (DisplayedFunction) + return; + + DisplayedFunction = true; + + if (FunctionDecl *FD = dyn_cast(getCodeDecl())) { + llvm::cerr << "ANALYZE: " + << getContext().getSourceManager().getSourceName(FD->getLocation()) + << ' ' + << FD->getIdentifier()->getName() + << '\n'; + } + else if (ObjCMethodDecl *MD = dyn_cast(getCodeDecl())) { + llvm::cerr << "ANALYZE (ObjC Method): " + << getContext().getSourceManager().getSourceName(MD->getLocation()) + << " '" + << MD->getSelector().getName() << "'\n"; + } + } }; } // end anonymous namespace @@ -231,6 +263,10 @@ static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf) { llvm::OwningPtr TF(tf); + // Display progress. + if (!mgr.shouldVisualize()) + mgr.DisplayFunction(); + // Construct the analysis engine. GRExprEngine Eng(*mgr.getCFG(), *mgr.getCodeDecl(), mgr.getContext()); Eng.setTransferFunctions(tf); @@ -239,7 +275,11 @@ static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf) { Eng.ExecuteWorkList(); // Display warnings. - Eng.EmitWarnings(mgr.getDiagnostic(), mgr.getPathDiagnosticClient()); + Eng.EmitWarnings(mgr.getDiagnostic(), mgr.getPathDiagnosticClient()); + + // Visualize the exploded graph. + if (mgr.shouldVisualize()) + Eng.ViewGraph(mgr.shouldTrimGraph()); } static void ActionRefLeakCheckerAux(AnalysisManager& mgr, bool GCEnabled,