]> granicus.if.org Git - clang/commitdiff
Add Checker callback for running a checker at the end of processing an entire Transla...
authorTed Kremenek <kremenek@apple.com>
Thu, 5 May 2011 03:41:17 +0000 (03:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 5 May 2011 03:41:17 +0000 (03:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130913 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/Checker.h
include/clang/StaticAnalyzer/Core/CheckerManager.h
lib/StaticAnalyzer/Core/CheckerManager.cpp
lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

index 86e30eb5239c4f6cf026d3160cb19ee57c01e8e9..eb38bd8951e9b56d40b3e154f15090798a05f321 100644 (file)
@@ -63,6 +63,24 @@ public:
   }
 };
 
+class EndOfTranslationUnit {
+  template <typename CHECKER>
+  static void _checkEndOfTranslationUnit(void *checker,
+                                         const TranslationUnitDecl *TU, 
+                                         AnalysisManager& mgr,
+                                         BugReporter &BR) {
+    ((const CHECKER *)checker)->checkEndOfTranslationUnit(TU, mgr, BR);
+  }
+
+public:
+  template <typename CHECKER>
+  static void _register(CHECKER *checker, CheckerManager &mgr){
+    mgr._registerForEndOfTranslationUnit(
+                              CheckerManager::CheckEndOfTranslationUnit(checker,
+                                          _checkEndOfTranslationUnit<CHECKER>));
+  }
+};
+
 template <typename STMT>
 class PreStmt {
   template <typename CHECKER>
index cee0d4d8bd0ea850c551ffcd6edd681860ad004f..45d38fba04953f0d6a6509c3e883a62edc61c58d 100644 (file)
@@ -252,6 +252,11 @@ public:
                               const ExplodedNodeSet &Src,
                               const CallExpr *CE, ExprEngine &Eng,
                               GraphExpander *defaultEval = 0);
+  
+  /// \brief Run checkers for the entire Translation Unit.
+  void runCheckersOnEndOfTranslationUnit(const TranslationUnitDecl* TU,
+                                         AnalysisManager &mgr,
+                                         BugReporter &BR);
 
 //===----------------------------------------------------------------------===//
 // Internal registration functions for AST traversing.
@@ -312,6 +317,10 @@ public:
   typedef CheckerFn<bool (const CallExpr *, CheckerContext &)>
       EvalCallFunc;
 
+  typedef CheckerFn<void (const TranslationUnitDecl *,
+                          AnalysisManager&, BugReporter &)>
+      CheckEndOfTranslationUnit;
+
   typedef bool (*HandlesStmtFunc)(const Stmt *D);
   void _registerForPreStmt(CheckStmtFunc checkfn,
                            HandlesStmtFunc isForStmtFn);
@@ -342,6 +351,8 @@ public:
 
   void _registerForEvalCall(EvalCallFunc checkfn);
 
+  void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn);
+
 //===----------------------------------------------------------------------===//
 // Internal registration functions for events.
 //===----------------------------------------------------------------------===//
@@ -462,6 +473,8 @@ private:
 
   std::vector<EvalCallFunc> EvalCallCheckers;
 
+  std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
+
   struct EventInfo {
     llvm::SmallVector<CheckEventFunc, 4> Checkers;
     bool HasDispatcher;
index 78c8b8bda225e3bb1c43803168e3f2ceebfdb272..ba7c384e5c3624902fc22a5c797250c58a0221de 100644 (file)
@@ -416,6 +416,15 @@ void CheckerManager::runCheckersForEvalCall(ExplodedNodeSet &Dst,
   }
 }
 
+/// \brief Run checkers for the entire Translation Unit.
+void CheckerManager::runCheckersOnEndOfTranslationUnit(
+                                                  const TranslationUnitDecl *TU,
+                                                  AnalysisManager &mgr,
+                                                  BugReporter &BR) {
+  for (unsigned i = 0, e = EndOfTranslationUnitCheckers.size(); i != e; ++i)
+    EndOfTranslationUnitCheckers[i](TU, mgr, BR);
+}
+
 //===----------------------------------------------------------------------===//
 // Internal registration functions for AST traversing.
 //===----------------------------------------------------------------------===//
@@ -495,6 +504,11 @@ void CheckerManager::_registerForEvalCall(EvalCallFunc checkfn) {
   EvalCallCheckers.push_back(checkfn);
 }
 
+void CheckerManager::_registerForEndOfTranslationUnit(
+                                            CheckEndOfTranslationUnit checkfn) {
+  EndOfTranslationUnitCheckers.push_back(checkfn);
+}
+
 //===----------------------------------------------------------------------===//
 // Implementation details.
 //===----------------------------------------------------------------------===//
index fe6e1fd6bbd2ecb60941fb2ab94be3385f745451..cd2cea47d74c3ce5bcd8185b55c4fdb30529d52b 100644 (file)
@@ -232,6 +232,9 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
   checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
   HandleDeclContext(C, TU);
 
+  // After all decls handled, run checkers on the entire TranslationUnit.
+  checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
+
   // Explicitly destroy the PathDiagnosticClient.  This will flush its output.
   // FIXME: This should be replaced with something that doesn't rely on
   // side-effects in PathDiagnosticClient's destructor. This is required when