[analyzer] Refactoring: include/clang/Checker -> include/clang/GR
[clang.git] / include / clang / GR / PathSensitive / AnalysisManager.h
blob42221f2a538c66b4f1ab2730493d6f76612360f4
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISMANAGER_H
16 #define LLVM_CLANG_ANALYSIS_ANALYSISMANAGER_H
18 #include "clang/Analysis/AnalysisContext.h"
19 #include "clang/GR/BugReporter/BugReporter.h"
20 #include "clang/GR/BugReporter/PathDiagnostic.h"
22 namespace clang {
24 namespace idx {
25 class Indexer;
26 class TranslationUnit;
29 class AnalysisManager : public BugReporterData {
30 AnalysisContextManager AnaCtxMgr;
31 LocationContextManager LocCtxMgr;
33 ASTContext &Ctx;
34 Diagnostic &Diags;
35 const LangOptions &LangInfo;
37 llvm::OwningPtr<PathDiagnosticClient> PD;
39 // Configurable components creators.
40 StoreManagerCreator CreateStoreMgr;
41 ConstraintManagerCreator CreateConstraintMgr;
43 /// \brief Provide function definitions in other translation units. This is
44 /// NULL if we don't have multiple translation units. AnalysisManager does
45 /// not own the Indexer.
46 idx::Indexer *Idxer;
48 enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
50 // The maximum number of exploded nodes the analyzer will generate.
51 unsigned MaxNodes;
53 // The maximum number of times the analyzer visit a block.
54 unsigned MaxVisit;
56 bool VisualizeEGDot;
57 bool VisualizeEGUbi;
58 bool PurgeDead;
60 /// EargerlyAssume - A flag indicating how the engine should handle
61 // expressions such as: 'x = (y != 0)'. When this flag is true then
62 // the subexpression 'y != 0' will be eagerly assumed to be true or false,
63 // thus evaluating it to the integers 0 or 1 respectively. The upside
64 // is that this can increase analysis precision until we have a better way
65 // to lazily evaluate such logic. The downside is that it eagerly
66 // bifurcates paths.
67 bool EagerlyAssume;
68 bool TrimGraph;
69 bool InlineCall;
71 public:
72 AnalysisManager(ASTContext &ctx, Diagnostic &diags,
73 const LangOptions &lang, PathDiagnosticClient *pd,
74 StoreManagerCreator storemgr,
75 ConstraintManagerCreator constraintmgr,
76 idx::Indexer *idxer,
77 unsigned maxnodes, unsigned maxvisit,
78 bool vizdot, bool vizubi, bool purge, bool eager, bool trim,
79 bool inlinecall, bool useUnoptimizedCFG,
80 bool addImplicitDtors, bool addInitializers)
82 : AnaCtxMgr(useUnoptimizedCFG, addImplicitDtors, addInitializers),
83 Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd),
84 CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),Idxer(idxer),
85 AScope(ScopeDecl), MaxNodes(maxnodes), MaxVisit(maxvisit),
86 VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
87 EagerlyAssume(eager), TrimGraph(trim), InlineCall(inlinecall) {}
89 ~AnalysisManager() { FlushDiagnostics(); }
91 void ClearContexts() {
92 LocCtxMgr.clear();
93 AnaCtxMgr.clear();
96 AnalysisContextManager& getAnalysisContextManager() {
97 return AnaCtxMgr;
100 StoreManagerCreator getStoreManagerCreator() {
101 return CreateStoreMgr;
104 ConstraintManagerCreator getConstraintManagerCreator() {
105 return CreateConstraintMgr;
108 idx::Indexer *getIndexer() const { return Idxer; }
110 virtual ASTContext &getASTContext() {
111 return Ctx;
114 virtual SourceManager &getSourceManager() {
115 return getASTContext().getSourceManager();
118 virtual Diagnostic &getDiagnostic() {
119 return Diags;
122 const LangOptions &getLangOptions() const {
123 return LangInfo;
126 virtual PathDiagnosticClient *getPathDiagnosticClient() {
127 return PD.get();
130 void FlushDiagnostics() {
131 if (PD.get())
132 PD->FlushDiagnostics();
135 unsigned getMaxNodes() const { return MaxNodes; }
137 unsigned getMaxVisit() const { return MaxVisit; }
139 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
141 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
143 bool shouldVisualize() const {
144 return VisualizeEGDot || VisualizeEGUbi;
147 bool shouldTrimGraph() const { return TrimGraph; }
149 bool shouldPurgeDead() const { return PurgeDead; }
151 bool shouldEagerlyAssume() const { return EagerlyAssume; }
153 bool shouldInlineCall() const { return InlineCall; }
155 bool hasIndexer() const { return Idxer != 0; }
157 AnalysisContext *getAnalysisContextInAnotherTU(const Decl *D);
159 CFG *getCFG(Decl const *D) {
160 return AnaCtxMgr.getContext(D)->getCFG();
163 LiveVariables *getLiveVariables(Decl const *D) {
164 return AnaCtxMgr.getContext(D)->getLiveVariables();
167 ParentMap &getParentMap(Decl const *D) {
168 return AnaCtxMgr.getContext(D)->getParentMap();
171 AnalysisContext *getAnalysisContext(const Decl *D) {
172 return AnaCtxMgr.getContext(D);
175 AnalysisContext *getAnalysisContext(const Decl *D, idx::TranslationUnit *TU) {
176 return AnaCtxMgr.getContext(D, TU);
179 const StackFrameContext *getStackFrame(AnalysisContext *Ctx,
180 LocationContext const *Parent,
181 const Stmt *S,
182 const CFGBlock *Blk, unsigned Idx) {
183 return LocCtxMgr.getStackFrame(Ctx, Parent, S, Blk, Idx);
186 // Get the top level stack frame.
187 const StackFrameContext *getStackFrame(Decl const *D,
188 idx::TranslationUnit *TU) {
189 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0);
192 // Get a stack frame with parent.
193 StackFrameContext const *getStackFrame(const Decl *D,
194 LocationContext const *Parent,
195 const Stmt *S,
196 const CFGBlock *Blk, unsigned Idx) {
197 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), Parent, S,
198 Blk,Idx);
204 #endif