AnalysisManager.h revision d6471f7c1921c7802804ce3ff6fe9768310f72b9
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. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_GR_ANALYSISMANAGER_H 16#define LLVM_CLANG_GR_ANALYSISMANAGER_H 17 18#include "clang/Analysis/AnalysisContext.h" 19#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" 20#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" 21 22namespace clang { 23 24namespace idx { 25 class Indexer; 26 class TranslationUnit; 27} 28 29namespace ento { 30 class CheckerManager; 31 32class AnalysisManager : public BugReporterData { 33 AnalysisContextManager AnaCtxMgr; 34 LocationContextManager LocCtxMgr; 35 36 ASTContext &Ctx; 37 DiagnosticsEngine &Diags; 38 const LangOptions &LangInfo; 39 40 llvm::OwningPtr<PathDiagnosticClient> PD; 41 42 // Configurable components creators. 43 StoreManagerCreator CreateStoreMgr; 44 ConstraintManagerCreator CreateConstraintMgr; 45 46 CheckerManager *CheckerMgr; 47 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. 51 idx::Indexer *Idxer; 52 53 enum AnalysisScope { ScopeTU, ScopeDecl } AScope; 54 55 // The maximum number of exploded nodes the analyzer will generate. 56 unsigned MaxNodes; 57 58 // The maximum number of times the analyzer visit a block. 59 unsigned MaxVisit; 60 61 bool VisualizeEGDot; 62 bool VisualizeEGUbi; 63 bool PurgeDead; 64 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 71 // bifurcates paths. 72 bool EagerlyAssume; 73 bool TrimGraph; 74 bool InlineCall; 75 bool EagerlyTrimEGraph; 76 77public: 78 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 79 const LangOptions &lang, PathDiagnosticClient *pd, 80 StoreManagerCreator storemgr, 81 ConstraintManagerCreator constraintmgr, 82 CheckerManager *checkerMgr, 83 idx::Indexer *idxer, 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); 89 90 ~AnalysisManager() { FlushDiagnostics(); } 91 92 void ClearContexts() { 93 LocCtxMgr.clear(); 94 AnaCtxMgr.clear(); 95 } 96 97 AnalysisContextManager& getAnalysisContextManager() { 98 return AnaCtxMgr; 99 } 100 101 StoreManagerCreator getStoreManagerCreator() { 102 return CreateStoreMgr; 103 } 104 105 ConstraintManagerCreator getConstraintManagerCreator() { 106 return CreateConstraintMgr; 107 } 108 109 CheckerManager *getCheckerManager() const { return CheckerMgr; } 110 111 idx::Indexer *getIndexer() const { return Idxer; } 112 113 virtual ASTContext &getASTContext() { 114 return Ctx; 115 } 116 117 virtual SourceManager &getSourceManager() { 118 return getASTContext().getSourceManager(); 119 } 120 121 virtual DiagnosticsEngine &getDiagnostic() { 122 return Diags; 123 } 124 125 const LangOptions &getLangOptions() const { 126 return LangInfo; 127 } 128 129 virtual PathDiagnosticClient *getPathDiagnosticClient() { 130 return PD.get(); 131 } 132 133 void FlushDiagnostics() { 134 if (PD.get()) 135 PD->FlushDiagnostics(); 136 } 137 138 unsigned getMaxNodes() const { return MaxNodes; } 139 140 unsigned getMaxVisit() const { return MaxVisit; } 141 142 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 143 144 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 145 146 bool shouldVisualize() const { 147 return VisualizeEGDot || VisualizeEGUbi; 148 } 149 150 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 151 152 bool shouldTrimGraph() const { return TrimGraph; } 153 154 bool shouldPurgeDead() const { return PurgeDead; } 155 156 bool shouldEagerlyAssume() const { return EagerlyAssume; } 157 158 bool shouldInlineCall() const { return InlineCall; } 159 160 bool hasIndexer() const { return Idxer != 0; } 161 162 AnalysisContext *getAnalysisContextInAnotherTU(const Decl *D); 163 164 CFG *getCFG(Decl const *D) { 165 return AnaCtxMgr.getContext(D)->getCFG(); 166 } 167 168 LiveVariables *getLiveVariables(Decl const *D) { 169 return AnaCtxMgr.getContext(D)->getLiveVariables(); 170 } 171 172 ParentMap &getParentMap(Decl const *D) { 173 return AnaCtxMgr.getContext(D)->getParentMap(); 174 } 175 176 AnalysisContext *getAnalysisContext(const Decl *D) { 177 return AnaCtxMgr.getContext(D); 178 } 179 180 AnalysisContext *getAnalysisContext(const Decl *D, idx::TranslationUnit *TU) { 181 return AnaCtxMgr.getContext(D, TU); 182 } 183 184 const StackFrameContext *getStackFrame(AnalysisContext *Ctx, 185 LocationContext const *Parent, 186 const Stmt *S, 187 const CFGBlock *Blk, unsigned Idx) { 188 return LocCtxMgr.getStackFrame(Ctx, Parent, S, Blk, Idx); 189 } 190 191 // Get the top level stack frame. 192 const StackFrameContext *getStackFrame(Decl const *D, 193 idx::TranslationUnit *TU) { 194 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0); 195 } 196 197 // Get a stack frame with parent. 198 StackFrameContext const *getStackFrame(const Decl *D, 199 LocationContext const *Parent, 200 const Stmt *S, 201 const CFGBlock *Blk, unsigned Idx) { 202 return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), Parent, S, 203 Blk,Idx); 204 } 205}; 206 207} // end GR namespace 208 209} // end clang namespace 210 211#endif 212