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/BugReporter/BugReporter.h"
20 #include "clang/StaticAnalyzer/BugReporter/PathDiagnostic.h"
26 class TranslationUnit
;
31 class AnalysisManager
: public BugReporterData
{
32 AnalysisContextManager AnaCtxMgr
;
33 LocationContextManager LocCtxMgr
;
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.
50 enum AnalysisScope
{ ScopeTU
, ScopeDecl
} AScope
;
52 // The maximum number of exploded nodes the analyzer will generate.
55 // The maximum number of times the analyzer visit a block.
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
74 AnalysisManager(ASTContext
&ctx
, Diagnostic
&diags
,
75 const LangOptions
&lang
, PathDiagnosticClient
*pd
,
76 StoreManagerCreator storemgr
,
77 ConstraintManagerCreator constraintmgr
,
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() {
98 AnalysisContextManager
& getAnalysisContextManager() {
102 StoreManagerCreator
getStoreManagerCreator() {
103 return CreateStoreMgr
;
106 ConstraintManagerCreator
getConstraintManagerCreator() {
107 return CreateConstraintMgr
;
110 idx::Indexer
*getIndexer() const { return Idxer
; }
112 virtual ASTContext
&getASTContext() {
116 virtual SourceManager
&getSourceManager() {
117 return getASTContext().getSourceManager();
120 virtual Diagnostic
&getDiagnostic() {
124 const LangOptions
&getLangOptions() const {
128 virtual PathDiagnosticClient
*getPathDiagnosticClient() {
132 void FlushDiagnostics() {
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
,
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
,
198 const CFGBlock
*Blk
, unsigned Idx
) {
199 return LocCtxMgr
.getStackFrame(AnaCtxMgr
.getContext(D
), Parent
, S
,
204 } // end GR namespace
206 } // end clang namespace