AnalysisManager.h revision 1d26f48dc2eea1c07431ca1519d7034a21b9bcff
1//== AnalysisManager.h - Path sensitive analysis data 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// This file defines the AnalysisManager class that manages the data and policy
11// for path sensitive analysis.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_GR_ANALYSISMANAGER_H
16#define LLVM_CLANG_GR_ANALYSISMANAGER_H
17
18#include "clang/Analysis/AnalysisContext.h"
19#include "clang/Frontend/AnalyzerOptions.h"
20#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
21#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
22
23namespace clang {
24
25namespace idx {
26  class Indexer;
27  class TranslationUnit;
28}
29
30namespace ento {
31  class CheckerManager;
32
33class AnalysisManager : public BugReporterData {
34  AnalysisDeclContextManager AnaCtxMgr;
35
36  ASTContext &Ctx;
37  DiagnosticsEngine &Diags;
38  const LangOptions &LangInfo;
39
40  llvm::OwningPtr<PathDiagnosticConsumer> PD;
41
42  // Configurable components creators.
43  StoreManagerCreator CreateStoreMgr;
44  ConstraintManagerCreator CreateConstraintMgr;
45
46  CheckerManager *CheckerMgr;
47
48  /// \brief Provide function definitions in other translation units. This is
49  /// NULL if we don't have multiple translation units. AnalysisManager does
50  /// not own the Indexer.
51  idx::Indexer *Idxer;
52
53  enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
54
55  // The maximum number of exploded nodes the analyzer will generate.
56  unsigned MaxNodes;
57
58  // The maximum number of times the analyzer visit a block.
59  unsigned MaxVisit;
60
61  bool VisualizeEGDot;
62  bool VisualizeEGUbi;
63  AnalysisPurgeMode PurgeDead;
64
65  /// EargerlyAssume - A flag indicating how the engine should handle
66  //   expressions such as: 'x = (y != 0)'.  When this flag is true then
67  //   the subexpression 'y != 0' will be eagerly assumed to be true or false,
68  //   thus evaluating it to the integers 0 or 1 respectively.  The upside
69  //   is that this can increase analysis precision until we have a better way
70  //   to lazily evaluate such logic.  The downside is that it eagerly
71  //   bifurcates paths.
72  bool EagerlyAssume;
73  bool TrimGraph;
74  bool InlineCall;
75  bool EagerlyTrimEGraph;
76
77public:
78  AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
79                  const LangOptions &lang, PathDiagnosticConsumer *pd,
80                  StoreManagerCreator storemgr,
81                  ConstraintManagerCreator constraintmgr,
82                  CheckerManager *checkerMgr,
83                  idx::Indexer *idxer,
84                  unsigned maxnodes, unsigned maxvisit,
85                  bool vizdot, bool vizubi, AnalysisPurgeMode purge,
86                  bool eager, bool trim,
87                  bool inlinecall, bool useUnoptimizedCFG,
88                  bool addImplicitDtors, bool addInitializers,
89                  bool eagerlyTrimEGraph);
90
91  /// Construct a clone of the given AnalysisManager with the given ASTContext
92  /// and DiagnosticsEngine.
93  AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
94                  AnalysisManager &ParentAM);
95
96  ~AnalysisManager() { FlushDiagnostics(); }
97
98  void ClearContexts() {
99    AnaCtxMgr.clear();
100  }
101
102  AnalysisDeclContextManager& getAnalysisDeclContextManager() {
103    return AnaCtxMgr;
104  }
105
106  StoreManagerCreator getStoreManagerCreator() {
107    return CreateStoreMgr;
108  }
109
110  ConstraintManagerCreator getConstraintManagerCreator() {
111    return CreateConstraintMgr;
112  }
113
114  CheckerManager *getCheckerManager() const { return CheckerMgr; }
115
116  idx::Indexer *getIndexer() const { return Idxer; }
117
118  virtual ASTContext &getASTContext() {
119    return Ctx;
120  }
121
122  virtual SourceManager &getSourceManager() {
123    return getASTContext().getSourceManager();
124  }
125
126  virtual DiagnosticsEngine &getDiagnostic() {
127    return Diags;
128  }
129
130  const LangOptions &getLangOptions() const {
131    return LangInfo;
132  }
133
134  virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() {
135    return PD.get();
136  }
137
138  void FlushDiagnostics() {
139    if (PD.get())
140      PD->FlushDiagnostics();
141  }
142
143  unsigned getMaxNodes() const { return MaxNodes; }
144
145  unsigned getMaxVisit() const { return MaxVisit; }
146
147  bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
148
149  bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
150
151  bool shouldVisualize() const {
152    return VisualizeEGDot || VisualizeEGUbi;
153  }
154
155  bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
156
157  bool shouldTrimGraph() const { return TrimGraph; }
158
159  AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
160
161  bool shouldEagerlyAssume() const { return EagerlyAssume; }
162
163  bool shouldInlineCall() const { return InlineCall; }
164
165  bool hasIndexer() const { return Idxer != 0; }
166
167  AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D);
168
169  CFG *getCFG(Decl const *D) {
170    return AnaCtxMgr.getContext(D)->getCFG();
171  }
172
173  template <typename T>
174  T *getAnalysis(Decl const *D) {
175    return AnaCtxMgr.getContext(D)->getAnalysis<T>();
176  }
177
178  ParentMap &getParentMap(Decl const *D) {
179    return AnaCtxMgr.getContext(D)->getParentMap();
180  }
181
182  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
183    return AnaCtxMgr.getContext(D);
184  }
185
186  AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) {
187    return AnaCtxMgr.getContext(D, TU);
188  }
189
190};
191
192} // enAnaCtxMgrspace
193
194} // end clang namespace
195
196#endif
197