AnalysisManager.h revision 8235f9c9c8b3d1737d1c6bd57f7ba3f616b92392
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/Frontend/AnalyzerOptions.h" 20#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" 21#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" 22 23namespace clang { 24 25namespace idx { 26 class Indexer; 27 class TranslationUnit; 28} 29 30namespace ento { 31 class CheckerManager; 32 33class AnalysisManager : public BugReporterData { 34 virtual void anchor(); 35 AnalysisDeclContextManager AnaCtxMgr; 36 37 ASTContext &Ctx; 38 DiagnosticsEngine &Diags; 39 const LangOptions &LangInfo; 40 41 OwningPtr<PathDiagnosticConsumer> PD; 42 43 // Configurable components creators. 44 StoreManagerCreator CreateStoreMgr; 45 ConstraintManagerCreator CreateConstraintMgr; 46 47 CheckerManager *CheckerMgr; 48 49 /// \brief Provide function definitions in other translation units. This is 50 /// NULL if we don't have multiple translation units. AnalysisManager does 51 /// not own the Indexer. 52 idx::Indexer *Idxer; 53 54 enum AnalysisScope { ScopeTU, ScopeDecl } AScope; 55 56 /// \brief The maximum number of exploded nodes the analyzer will generate. 57 unsigned MaxNodes; 58 59 /// \brief The maximum number of times the analyzer visits a block. 60 unsigned MaxVisit; 61 62 bool VisualizeEGDot; 63 bool VisualizeEGUbi; 64 AnalysisPurgeMode PurgeDead; 65 66 /// \brief The flag regulates if we should eagerly assume evaluations of 67 /// conditionals, thus, bifurcating the path. 68 /// 69 /// EagerlyAssume - A flag indicating how the engine should handle 70 /// expressions such as: 'x = (y != 0)'. When this flag is true then 71 /// the subexpression 'y != 0' will be eagerly assumed to be true or false, 72 /// thus evaluating it to the integers 0 or 1 respectively. The upside 73 /// is that this can increase analysis precision until we have a better way 74 /// to lazily evaluate such logic. The downside is that it eagerly 75 /// bifurcates paths. 76 bool EagerlyAssume; 77 bool TrimGraph; 78 bool InlineCall; 79 bool EagerlyTrimEGraph; 80 81public: 82 // Settings for inlining tuning. 83 84 /// \brief The inlining stack depth limit. 85 unsigned InlineMaxStackDepth; 86 /// \brief The max number of basic blocks in a function being inlined. 87 unsigned InlineMaxFunctionSize; 88 89public: 90 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 91 const LangOptions &lang, PathDiagnosticConsumer *pd, 92 StoreManagerCreator storemgr, 93 ConstraintManagerCreator constraintmgr, 94 CheckerManager *checkerMgr, 95 idx::Indexer *idxer, 96 unsigned maxnodes, unsigned maxvisit, 97 bool vizdot, bool vizubi, AnalysisPurgeMode purge, 98 bool eager, bool trim, 99 bool inlinecall, bool useUnoptimizedCFG, 100 bool addImplicitDtors, bool addInitializers, 101 bool eagerlyTrimEGraph, 102 unsigned inlineMaxStack, 103 unsigned inlineMaxFunctionSize); 104 105 /// Construct a clone of the given AnalysisManager with the given ASTContext 106 /// and DiagnosticsEngine. 107 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 108 AnalysisManager &ParentAM); 109 110 ~AnalysisManager() { FlushDiagnostics(); } 111 112 void ClearContexts() { 113 AnaCtxMgr.clear(); 114 } 115 116 AnalysisDeclContextManager& getAnalysisDeclContextManager() { 117 return AnaCtxMgr; 118 } 119 120 StoreManagerCreator getStoreManagerCreator() { 121 return CreateStoreMgr; 122 } 123 124 ConstraintManagerCreator getConstraintManagerCreator() { 125 return CreateConstraintMgr; 126 } 127 128 CheckerManager *getCheckerManager() const { return CheckerMgr; } 129 130 idx::Indexer *getIndexer() const { return Idxer; } 131 132 virtual ASTContext &getASTContext() { 133 return Ctx; 134 } 135 136 virtual SourceManager &getSourceManager() { 137 return getASTContext().getSourceManager(); 138 } 139 140 virtual DiagnosticsEngine &getDiagnostic() { 141 return Diags; 142 } 143 144 const LangOptions &getLangOptions() const { 145 return LangInfo; 146 } 147 148 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() { 149 return PD.get(); 150 } 151 152 void FlushDiagnostics() { 153 if (PD.get()) 154 PD->FlushDiagnostics(0); 155 } 156 157 unsigned getMaxNodes() const { return MaxNodes; } 158 159 unsigned getMaxVisit() const { return MaxVisit; } 160 161 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 162 163 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 164 165 bool shouldVisualize() const { 166 return VisualizeEGDot || VisualizeEGUbi; 167 } 168 169 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 170 171 bool shouldTrimGraph() const { return TrimGraph; } 172 173 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; } 174 175 bool shouldEagerlyAssume() const { return EagerlyAssume; } 176 177 bool shouldInlineCall() const { return InlineCall; } 178 179 bool hasIndexer() const { return Idxer != 0; } 180 181 AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D); 182 183 CFG *getCFG(Decl const *D) { 184 return AnaCtxMgr.getContext(D)->getCFG(); 185 } 186 187 template <typename T> 188 T *getAnalysis(Decl const *D) { 189 return AnaCtxMgr.getContext(D)->getAnalysis<T>(); 190 } 191 192 ParentMap &getParentMap(Decl const *D) { 193 return AnaCtxMgr.getContext(D)->getParentMap(); 194 } 195 196 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { 197 return AnaCtxMgr.getContext(D); 198 } 199 200 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) { 201 return AnaCtxMgr.getContext(D, TU); 202 } 203 204}; 205 206} // enAnaCtxMgrspace 207 208} // end clang namespace 209 210#endif 211