[analyzer] Refactoring: Move stuff into namespace 'GR'.
[clang.git] / include / clang / GR / PathSensitive / AnalysisManager.h
blob59bf416c8577e4a339c81734b1962626db322942
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_GR_ANALYSISMANAGER_H
16 #define LLVM_CLANG_GR_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 namespace GR {
31 class AnalysisManager : public BugReporterData {
32 AnalysisContextManager AnaCtxMgr;
33 LocationContextManager LocCtxMgr;
35 ASTContext &Ctx;
36 Diagnostic &Diags;
37 const LangOptions &LangInfo;
39 llvm::OwningPtr<PathDiagnosticClient> PD;
41 // Configurable components creators.
42 StoreManagerCreator CreateStoreMgr;
43 ConstraintManagerCreator CreateConstraintMgr;
45 /// \brief Provide function definitions in other translation units. This is
46 /// NULL if we don't have multiple translation units. AnalysisManager does
47 /// not own the Indexer.
48 idx::Indexer *Idxer;
50 enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
52 // The maximum number of exploded nodes the analyzer will generate.
53 unsigned MaxNodes;
55 // The maximum number of times the analyzer visit a block.
56 unsigned MaxVisit;
58 bool VisualizeEGDot;
59 bool VisualizeEGUbi;
60 bool PurgeDead;
62 /// EargerlyAssume - A flag indicating how the engine should handle
63 // expressions such as: 'x = (y != 0)'. When this flag is true then
64 // the subexpression 'y != 0' will be eagerly assumed to be true or false,
65 // thus evaluating it to the integers 0 or 1 respectively. The upside
66 // is that this can increase analysis precision until we have a better way
67 // to lazily evaluate such logic. The downside is that it eagerly
68 // bifurcates paths.
69 bool EagerlyAssume;
70 bool TrimGraph;
71 bool InlineCall;
73 public:
74 AnalysisManager(ASTContext &ctx, Diagnostic &diags,
75 const LangOptions &lang, PathDiagnosticClient *pd,
76 StoreManagerCreator storemgr,
77 ConstraintManagerCreator constraintmgr,
78 idx::Indexer *idxer,
79 unsigned maxnodes, unsigned maxvisit,
80 bool vizdot, bool vizubi, bool purge, bool eager, bool trim,
81 bool inlinecall, bool useUnoptimizedCFG,
82 bool addImplicitDtors, bool addInitializers)
84 : AnaCtxMgr(useUnoptimizedCFG, addImplicitDtors, addInitializers),
85 Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd),
86 CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),Idxer(idxer),
87 AScope(ScopeDecl), MaxNodes(maxnodes), MaxVisit(maxvisit),
88 VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
89 EagerlyAssume(eager), TrimGraph(trim), InlineCall(inlinecall) {}
91 ~AnalysisManager() { FlushDiagnostics(); }
93 void ClearContexts() {
94 LocCtxMgr.clear();
95 AnaCtxMgr.clear();
98 AnalysisContextManager& getAnalysisContextManager() {
99 return AnaCtxMgr;
102 StoreManagerCreator getStoreManagerCreator() {
103 return CreateStoreMgr;
106 ConstraintManagerCreator getConstraintManagerCreator() {
107 return CreateConstraintMgr;
110 idx::Indexer *getIndexer() const { return Idxer; }
112 virtual ASTContext &getASTContext() {
113 return Ctx;
116 virtual SourceManager &getSourceManager() {
117 return getASTContext().getSourceManager();
120 virtual Diagnostic &getDiagnostic() {
121 return Diags;
124 const LangOptions &getLangOptions() const {
125 return LangInfo;
128 virtual PathDiagnosticClient *getPathDiagnosticClient() {
129 return PD.get();
132 void FlushDiagnostics() {
133 if (PD.get())
134 PD->FlushDiagnostics();
137 unsigned getMaxNodes() const { return MaxNodes; }
139 unsigned getMaxVisit() const { return MaxVisit; }
141 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
143 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
145 bool shouldVisualize() const {
146 return VisualizeEGDot || VisualizeEGUbi;
149 bool shouldTrimGraph() const { return TrimGraph; }
151 bool shouldPurgeDead() const { return PurgeDead; }
153 bool shouldEagerlyAssume() const { return EagerlyAssume; }
155 bool shouldInlineCall() const { return InlineCall; }
157 bool hasIndexer() const { return Idxer != 0; }
159 AnalysisContext *getAnalysisContextInAnotherTU(const Decl *D);
161 CFG *getCFG(Decl const *D) {
162 return AnaCtxMgr.getContext(D)->getCFG();
165 LiveVariables *getLiveVariables(Decl const *D) {
166 return AnaCtxMgr.getContext(D)->getLiveVariables();
169 ParentMap &getParentMap(Decl const *D) {
170 return AnaCtxMgr.getContext(D)->getParentMap();
173 AnalysisContext *getAnalysisContext(const Decl *D) {
174 return AnaCtxMgr.getContext(D);
177 AnalysisContext *getAnalysisContext(const Decl *D, idx::TranslationUnit *TU) {
178 return AnaCtxMgr.getContext(D, TU);
181 const StackFrameContext *getStackFrame(AnalysisContext *Ctx,
182 LocationContext const *Parent,
183 const Stmt *S,
184 const CFGBlock *Blk, unsigned Idx) {
185 return LocCtxMgr.getStackFrame(Ctx, Parent, S, Blk, Idx);
188 // Get the top level stack frame.
189 const StackFrameContext *getStackFrame(Decl const *D,
190 idx::TranslationUnit *TU) {
191 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0);
194 // Get a stack frame with parent.
195 StackFrameContext const *getStackFrame(const Decl *D,
196 LocationContext const *Parent,
197 const Stmt *S,
198 const CFGBlock *Blk, unsigned Idx) {
199 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), Parent, S,
200 Blk,Idx);
204 } // end GR namespace
206 } // end clang namespace
208 #endif