1 //== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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/StaticAnalyzer/Core/BugReporter/BugReporter.h"
20 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
26 class TranslationUnit;
32 class AnalysisManager : public BugReporterData {
33 AnalysisContextManager AnaCtxMgr;
34 LocationContextManager LocCtxMgr;
38 const LangOptions &LangInfo;
40 llvm::OwningPtr<PathDiagnosticClient> PD;
42 // Configurable components creators.
43 StoreManagerCreator CreateStoreMgr;
44 ConstraintManagerCreator CreateConstraintMgr;
46 CheckerManager *CheckerMgr;
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.
53 enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
55 // The maximum number of exploded nodes the analyzer will generate.
58 // The maximum number of times the analyzer visit a block.
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
75 bool EagerlyTrimEGraph;
78 AnalysisManager(ASTContext &ctx, Diagnostic &diags,
79 const LangOptions &lang, PathDiagnosticClient *pd,
80 StoreManagerCreator storemgr,
81 ConstraintManagerCreator constraintmgr,
82 CheckerManager *checkerMgr,
84 unsigned maxnodes, unsigned maxvisit,
85 bool vizdot, bool vizubi, bool purge, bool eager, bool trim,
86 bool inlinecall, bool useUnoptimizedCFG,
87 bool addImplicitDtors, bool addInitializers,
88 bool eagerlyTrimEGraph)
90 : AnaCtxMgr(useUnoptimizedCFG, addImplicitDtors, addInitializers),
91 Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd),
92 CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
93 CheckerMgr(checkerMgr), Idxer(idxer),
94 AScope(ScopeDecl), MaxNodes(maxnodes), MaxVisit(maxvisit),
95 VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
96 EagerlyAssume(eager), TrimGraph(trim), InlineCall(inlinecall),
97 EagerlyTrimEGraph(eagerlyTrimEGraph) {}
99 ~AnalysisManager() { FlushDiagnostics(); }
101 void ClearContexts() {
106 AnalysisContextManager& getAnalysisContextManager() {
110 StoreManagerCreator getStoreManagerCreator() {
111 return CreateStoreMgr;
114 ConstraintManagerCreator getConstraintManagerCreator() {
115 return CreateConstraintMgr;
118 CheckerManager *getCheckerManager() const { return CheckerMgr; }
120 idx::Indexer *getIndexer() const { return Idxer; }
122 virtual ASTContext &getASTContext() {
126 virtual SourceManager &getSourceManager() {
127 return getASTContext().getSourceManager();
130 virtual Diagnostic &getDiagnostic() {
134 const LangOptions &getLangOptions() const {
138 virtual PathDiagnosticClient *getPathDiagnosticClient() {
142 void FlushDiagnostics() {
144 PD->FlushDiagnostics();
147 unsigned getMaxNodes() const { return MaxNodes; }
149 unsigned getMaxVisit() const { return MaxVisit; }
151 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
153 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
155 bool shouldVisualize() const {
156 return VisualizeEGDot || VisualizeEGUbi;
159 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
161 bool shouldTrimGraph() const { return TrimGraph; }
163 bool shouldPurgeDead() const { return PurgeDead; }
165 bool shouldEagerlyAssume() const { return EagerlyAssume; }
167 bool shouldInlineCall() const { return InlineCall; }
169 bool hasIndexer() const { return Idxer != 0; }
171 AnalysisContext *getAnalysisContextInAnotherTU(const Decl *D);
173 CFG *getCFG(Decl const *D) {
174 return AnaCtxMgr.getContext(D)->getCFG();
177 LiveVariables *getLiveVariables(Decl const *D) {
178 return AnaCtxMgr.getContext(D)->getLiveVariables();
181 ParentMap &getParentMap(Decl const *D) {
182 return AnaCtxMgr.getContext(D)->getParentMap();
185 AnalysisContext *getAnalysisContext(const Decl *D) {
186 return AnaCtxMgr.getContext(D);
189 AnalysisContext *getAnalysisContext(const Decl *D, idx::TranslationUnit *TU) {
190 return AnaCtxMgr.getContext(D, TU);
193 const StackFrameContext *getStackFrame(AnalysisContext *Ctx,
194 LocationContext const *Parent,
196 const CFGBlock *Blk, unsigned Idx) {
197 return LocCtxMgr.getStackFrame(Ctx, Parent, S, Blk, Idx);
200 // Get the top level stack frame.
201 const StackFrameContext *getStackFrame(Decl const *D,
202 idx::TranslationUnit *TU) {
203 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0);
206 // Get a stack frame with parent.
207 StackFrameContext const *getStackFrame(const Decl *D,
208 LocationContext const *Parent,
210 const CFGBlock *Blk, unsigned Idx) {
211 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), Parent, S,
216 } // end GR namespace
218 } // end clang namespace