diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-07-02 16:49:11 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-07-02 16:49:11 +0000 |
commit | 34d7734b6ed1d9c0f647405e065251eb67f42bad (patch) | |
tree | ba5360c0f56b3d84f220c5708f4fa4bc5b517c43 | |
parent | bc46f345838b1c0d420dbd3655c94f5f360fb5b8 (diff) |
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
-rw-r--r-- | Driver/ASTConsumers.cpp | 98 | ||||
-rw-r--r-- | Driver/AnalysisConsumer.cpp | 44 |
2 files changed, 42 insertions, 100 deletions
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index a25468794d..fb8dc80a3d 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -635,104 +635,6 @@ ASTConsumer *clang::CreateLiveVarAnalyzer(const std::string& 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<PathDiagnosticClient> 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<GRTransferFuncs*>& 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<FunctionDecl>(&CD)) { - llvm::cerr << "ANALYZE: " - << Ctx->getSourceManager().getSourceName(FD->getLocation()) - << ' ' - << FD->getIdentifier()->getName() - << '\n'; - } - else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(&CD)) { - llvm::cerr << "ANALYZE (ObjC Method): " - << Ctx->getSourceManager().getSourceName(MD->getLocation()) - << " '" - << MD->getSelector().getName() << "'\n"; - } - } - else - llvm::cerr << '\n'; - - std::vector<GRTransferFuncs*> TFs; - getTransferFunctions(TFs); - - while (!TFs.empty()) { - - // Construct the analysis engine. - GRExprEngine Eng(C, CD, *Ctx); - - // Set base transfer functions. - llvm::OwningPtr<GRTransferFuncs> 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 namespace { 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> cfg; llvm::OwningPtr<LiveVariables> 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<FunctionDecl>(getCodeDecl())) { + llvm::cerr << "ANALYZE: " + << getContext().getSourceManager().getSourceName(FD->getLocation()) + << ' ' + << FD->getIdentifier()->getName() + << '\n'; + } + else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(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<GRTransferFuncs> 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, |