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