[cfe-commits] r126605 - /cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Feb 27 17:26:28 PST 2011


Author: akirtzidis
Date: Sun Feb 27 19:26:28 2011
New Revision: 126605

URL: http://llvm.org/viewvc/llvm-project?rev=126605&view=rev
Log:
[analyzer] Have CheckerManager::registerChecker return a pointer to the checker object and
only allow a checker to be registered once.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=126605&r1=126604&r2=126605&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Sun Feb 27 19:26:28 2011
@@ -99,6 +99,7 @@
   const LangOptions &getLangOptions() const { return LangOpts; }
 
   typedef void *CheckerRef;
+  typedef void *CheckerTag;
   typedef CheckerFn<> CheckerDtor;
 
 //===----------------------------------------------------------------------===//
@@ -106,11 +107,20 @@
 //===----------------------------------------------------------------------===//
 
   /// \brief Used to register checkers.
+  ///
+  /// \returns a pointer to the checker object.
   template <typename CHECKER>
-  void registerChecker() {
+  CHECKER *registerChecker() {
+    CheckerTag tag = getCheckerTag<CHECKER>();
+    CheckerRef &ref = CheckerTags[tag];
+    if (ref)
+      return static_cast<CHECKER *>(ref); // already registered.
+
     CHECKER *checker = new CHECKER();
     CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
     CHECKER::_register(checker, *this);
+    ref = checker;
+    return checker;
   }
 
 //===----------------------------------------------------------------------===//
@@ -309,6 +319,11 @@
   template <typename CHECKER>
   static void destruct(void *obj) { delete static_cast<CHECKER *>(obj); }
 
+  template <typename CHECKER>
+  static CheckerTag getCheckerTag() { static int tag; return &tag; }
+
+  llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
+
   std::vector<CheckerDtor> CheckerDtors;
 
   struct DeclCheckerInfo {





More information about the cfe-commits mailing list