[cfe-commits] r53029 - in /cfe/trunk/Driver: ASTConsumers.cpp AnalysisConsumer.cpp
Ted Kremenek
kremenek at apple.com
Wed Jul 2 09:49:12 PDT 2008
Author: kremenek
Date: Wed Jul 2 11:49:11 2008
New Revision: 53029
URL: http://llvm.org/viewvc/llvm-project?rev=53029&view=rev
Log:
Migrate CheckerConsumer diagnostics to the new AnalysisConsumer interface.
Remove CheckerConsumer.
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Driver/AnalysisConsumer.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=53029&r1=53028&r2=53029&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Jul 2 11:49:11 2008
@@ -635,104 +635,6 @@
}
//===----------------------------------------------------------------------===//
-// 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 {
Modified: cfe/trunk/Driver/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.cpp?rev=53029&r1=53028&r2=53029&view=diff
==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.cpp (original)
+++ cfe/trunk/Driver/AnalysisConsumer.cpp Wed Jul 2 11:49:11 2008
@@ -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 @@
Decl* D;
Stmt* Body;
AnalysisConsumer& C;
+ bool DisplayedFunction;
llvm::OwningPtr<CFG> cfg;
llvm::OwningPtr<LiveVariables> liveness;
@@ -109,7 +111,7 @@
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 @@
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 @@
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 @@
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,
More information about the cfe-commits
mailing list