CheckerManager.h revision 9fb9474c5b267400d4abfbff63c8b39f378235d4
1//===--- CheckerManager.h - Static Analyzer Checker Manager -----*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Defines the Static Analyzer Checker Manager.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SA_CORE_CHECKERMANAGER_H
15#define LLVM_CLANG_SA_CORE_CHECKERMANAGER_H
16
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/DenseMap.h"
19#include <vector>
20
21namespace clang {
22  class Decl;
23
24namespace ento {
25  class ExprEngine;
26  class AnalysisManager;
27  class BugReporter;
28
29class CheckerManager {
30public:
31  ~CheckerManager();
32
33  typedef void *CheckerRef;
34
35//===----------------------------------------------------------------------===//
36// registerChecker
37//===----------------------------------------------------------------------===//
38
39  /// \brief Used to register checkers.
40  template <typename CHECKER>
41  void registerChecker() {
42    CHECKER *checker = new CHECKER();
43    Checkers.push_back(std::make_pair(checker, destruct<CHECKER>));
44    CHECKER::_register(checker, *this);
45  }
46
47  typedef void (*RegisterToEngFunc)(ExprEngine &Eng);
48  void addCheckerRegisterFunction(RegisterToEngFunc fn) {
49    Funcs.push_back(fn);
50  }
51
52//===----------------------------------------------------------------------===//
53// Functions for running checkers.
54//===----------------------------------------------------------------------===//
55
56  /// \brief Run checkers handling Decls.
57  void runCheckersOnASTDecl(const Decl *D, AnalysisManager& mgr,
58                            BugReporter &BR);
59
60  /// \brief Run checkers handling Decls containing a Stmt body.
61  void runCheckersOnASTBody(const Decl *D, AnalysisManager& mgr,
62                            BugReporter &BR);
63
64//===----------------------------------------------------------------------===//
65// Internal registration functions.
66//===----------------------------------------------------------------------===//
67
68  // Functions used by the registration mechanism, checkers should not touch
69  // these directly.
70
71  typedef void (*CheckDeclFunc)(CheckerRef checker, const Decl *D,
72                                AnalysisManager& mgr, BugReporter &BR);
73  typedef bool (*HandlesDeclFunc)(const Decl *D);
74  void _registerForDecl(CheckerRef checker, CheckDeclFunc checkfn,
75                        HandlesDeclFunc isForDeclFn);
76
77  void _registerForBody(CheckerRef checker, CheckDeclFunc checkfn);
78
79  void registerCheckersToEngine(ExprEngine &eng);
80
81private:
82  template <typename CHECKER>
83  static void destruct(void *obj) { delete static_cast<CHECKER *>(obj); }
84
85  std::vector<RegisterToEngFunc> Funcs;
86
87  struct DeclCheckerInfo {
88    CheckerRef Checker;
89    CheckDeclFunc CheckFn;
90    HandlesDeclFunc IsForDeclFn;
91  };
92  std::vector<DeclCheckerInfo> DeclCheckers;
93
94  std::vector<std::pair<CheckerRef, CheckDeclFunc> > BodyCheckers;
95
96  typedef void (*Dtor)(void *);
97  std::vector<std::pair<CheckerRef, Dtor> > Checkers;
98
99  typedef llvm::SmallVector<std::pair<CheckerRef, CheckDeclFunc>, 4>
100      CachedDeclCheckers;
101  typedef llvm::DenseMap<unsigned, CachedDeclCheckers> CachedDeclCheckersMapTy;
102  CachedDeclCheckersMapTy CachedDeclCheckersMap;
103};
104
105} // end ento namespace
106
107} // end clang namespace
108
109#endif
110