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_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"
26 class TranslationUnit
;
29 class AnalysisManager
: public BugReporterData
{
30 AnalysisContextManager AnaCtxMgr
;
31 LocationContextManager LocCtxMgr
;
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.
48 enum AnalysisScope
{ ScopeTU
, ScopeDecl
} AScope
;
50 // The maximum number of exploded nodes the analyzer will generate.
53 // The maximum number of times the analyzer visit a block.
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
72 AnalysisManager(ASTContext
&ctx
, Diagnostic
&diags
,
73 const LangOptions
&lang
, PathDiagnosticClient
*pd
,
74 StoreManagerCreator storemgr
,
75 ConstraintManagerCreator constraintmgr
,
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() {
96 AnalysisContextManager
& getAnalysisContextManager() {
100 StoreManagerCreator
getStoreManagerCreator() {
101 return CreateStoreMgr
;
104 ConstraintManagerCreator
getConstraintManagerCreator() {
105 return CreateConstraintMgr
;
108 idx::Indexer
*getIndexer() const { return Idxer
; }
110 virtual ASTContext
&getASTContext() {
114 virtual SourceManager
&getSourceManager() {
115 return getASTContext().getSourceManager();
118 virtual Diagnostic
&getDiagnostic() {
122 const LangOptions
&getLangOptions() const {
126 virtual PathDiagnosticClient
*getPathDiagnosticClient() {
130 void FlushDiagnostics() {
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
,
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
,
196 const CFGBlock
*Blk
, unsigned Idx
) {
197 return LocCtxMgr
.getStackFrame(AnaCtxMgr
.getContext(D
), Parent
, S
,