]> granicus.if.org Git - clang/commitdiff
Factor CheckerManager to be able to pass AnalyzerOptions to checkers
authorTed Kremenek <kremenek@apple.com>
Tue, 16 Apr 2013 21:10:05 +0000 (21:10 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 16 Apr 2013 21:10:05 +0000 (21:10 +0000)
during checker registration.  There are no immediate clients of this,
but this provides a way for checkers to query the options table
at startup instead.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179626 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
include/clang/StaticAnalyzer/Core/CheckerManager.h
include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp

index 6dbdbbf89b96b4ae97a1ed1feda9ce8d441002ee..fb35f518ef02cfa73329fe6406309b9eb6f7d9dc 100644 (file)
@@ -232,6 +232,7 @@ private:
   /// \sa getMaxNodesPerTopLevelFunction
   Optional<unsigned> MaxNodesPerTopLevelFunction;
 
+public:
   /// Interprets an option's string value as a boolean.
   ///
   /// Accepts the strings "true" and "false".
@@ -244,7 +245,6 @@ private:
   /// Interprets an option's string value as an integer value.
   int getOptionAsInteger(StringRef Name, int DefaultVal);
 
-public:
   /// \brief Retrieves and sets the UserMode. This is a high-level option,
   /// which is used to set other low-level options. It is not accessible
   /// outside of AnalyzerOptions.
index 6f99fc14577ad79be7c35f00fb63ebb44e5a6496..b2411e6e65446c1de489a26e2cab2b8b60aeba52 100644 (file)
@@ -17,6 +17,7 @@
 #include "clang/Analysis/ProgramPoint.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/SmallVector.h"
@@ -134,9 +135,13 @@ enum PointerEscapeKind {
 
 class CheckerManager {
   const LangOptions LangOpts;
-
+  AnalyzerOptionsRef AOptions;
 public:
-  CheckerManager(const LangOptions &langOpts) : LangOpts(langOpts) { }
+  CheckerManager(const LangOptions &langOpts,
+                 AnalyzerOptionsRef AOptions)
+    : LangOpts(langOpts),
+      AOptions(AOptions) {}
+
   ~CheckerManager();
 
   bool hasPathSensitiveCheckers() const;
@@ -144,6 +149,7 @@ public:
   void finishedCheckerRegistration();
 
   const LangOptions &getLangOpts() const { return LangOpts; }
+  AnalyzerOptions &getAnalyzerOptions() { return *AOptions; }
 
   typedef CheckerBase *CheckerRef;
   typedef const void *CheckerTag;
@@ -170,6 +176,20 @@ public:
     return checker;
   }
 
+  template <typename CHECKER>
+  CHECKER *registerChecker(AnalyzerOptions &AOpts) {
+    CheckerTag tag = getTag<CHECKER>();
+    CheckerRef &ref = CheckerTags[tag];
+    if (ref)
+      return static_cast<CHECKER *>(ref); // already registered.
+
+    CHECKER *checker = new CHECKER(AOpts);
+    CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
+    CHECKER::_register(checker, *this);
+    ref = checker;
+    return checker;
+  }
+
 //===----------------------------------------------------------------------===//
 // Functions for running checkers for AST traversing..
 //===----------------------------------------------------------------------===//
index 492edd4ccb412d3a8d9d7e844255150c4c78fa8b..1df8c098d93d5bf1b40f284614d02e2492f3cb2f 100644 (file)
@@ -21,7 +21,7 @@ namespace clang {
 namespace ento {
   class CheckerManager;
 
-CheckerManager *createCheckerManager(const AnalyzerOptions &opts,
+CheckerManager *createCheckerManager(AnalyzerOptions &opts,
                                      const LangOptions &langOpts,
                                      ArrayRef<std::string> plugins,
                                      DiagnosticsEngine &diags);
index 4fad5a8a7c59e131a65d4ebf45cddc66d84f6b8b..e7def08819648e4473d792a9459f6d62a5074928 100644 (file)
@@ -100,11 +100,12 @@ void ClangCheckerRegistry::warnIncompatible(DiagnosticsEngine *diags,
 }
 
 
-CheckerManager *ento::createCheckerManager(const AnalyzerOptions &opts,
+CheckerManager *ento::createCheckerManager(AnalyzerOptions &opts,
                                            const LangOptions &langOpts,
                                            ArrayRef<std::string> plugins,
                                            DiagnosticsEngine &diags) {
-  OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts));
+  OwningPtr<CheckerManager> checkerMgr(new CheckerManager(langOpts,
+                                                          &opts));
 
   SmallVector<CheckerOptInfo, 8> checkerOpts;
   for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {