clang API Documentation
00001 //== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the AnalysisManager class that manages the data and policy 00011 // for path sensitive analysis. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_GR_ANALYSISMANAGER_H 00016 #define LLVM_CLANG_GR_ANALYSISMANAGER_H 00017 00018 #include "clang/Analysis/AnalysisContext.h" 00019 #include "clang/Frontend/AnalyzerOptions.h" 00020 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" 00021 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" 00022 00023 namespace clang { 00024 00025 namespace ento { 00026 class CheckerManager; 00027 00028 class AnalysisManager : public BugReporterData { 00029 virtual void anchor(); 00030 AnalysisDeclContextManager AnaCtxMgr; 00031 00032 ASTContext &Ctx; 00033 DiagnosticsEngine &Diags; 00034 const LangOptions &LangOpts; 00035 00036 OwningPtr<PathDiagnosticConsumer> PD; 00037 00038 // Configurable components creators. 00039 StoreManagerCreator CreateStoreMgr; 00040 ConstraintManagerCreator CreateConstraintMgr; 00041 00042 CheckerManager *CheckerMgr; 00043 00044 enum AnalysisScope { ScopeTU, ScopeDecl } AScope; 00045 00046 /// \brief The maximum number of exploded nodes the analyzer will generate. 00047 unsigned MaxNodes; 00048 00049 /// \brief The maximum number of times the analyzer visits a block. 00050 unsigned MaxVisit; 00051 00052 bool VisualizeEGDot; 00053 bool VisualizeEGUbi; 00054 AnalysisPurgeMode PurgeDead; 00055 00056 /// \brief The flag regulates if we should eagerly assume evaluations of 00057 /// conditionals, thus, bifurcating the path. 00058 /// 00059 /// EagerlyAssume - A flag indicating how the engine should handle 00060 /// expressions such as: 'x = (y != 0)'. When this flag is true then 00061 /// the subexpression 'y != 0' will be eagerly assumed to be true or false, 00062 /// thus evaluating it to the integers 0 or 1 respectively. The upside 00063 /// is that this can increase analysis precision until we have a better way 00064 /// to lazily evaluate such logic. The downside is that it eagerly 00065 /// bifurcates paths. 00066 bool EagerlyAssume; 00067 bool TrimGraph; 00068 bool EagerlyTrimEGraph; 00069 00070 public: 00071 // \brief inter-procedural analysis mode. 00072 AnalysisIPAMode IPAMode; 00073 00074 // Settings for inlining tuning. 00075 /// \brief The inlining stack depth limit. 00076 unsigned InlineMaxStackDepth; 00077 /// \brief The max number of basic blocks in a function being inlined. 00078 unsigned InlineMaxFunctionSize; 00079 /// \brief The mode of function selection used during inlining. 00080 AnalysisInliningMode InliningMode; 00081 00082 /// \brief Do not re-analyze paths leading to exhausted nodes with a different 00083 /// strategy. We get better code coverage when retry is enabled. 00084 bool NoRetryExhausted; 00085 00086 public: 00087 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 00088 const LangOptions &lang, PathDiagnosticConsumer *pd, 00089 StoreManagerCreator storemgr, 00090 ConstraintManagerCreator constraintmgr, 00091 CheckerManager *checkerMgr, 00092 unsigned maxnodes, unsigned maxvisit, 00093 bool vizdot, bool vizubi, AnalysisPurgeMode purge, 00094 bool eager, bool trim, 00095 bool useUnoptimizedCFG, 00096 bool addImplicitDtors, bool addInitializers, 00097 bool eagerlyTrimEGraph, 00098 AnalysisIPAMode ipa, 00099 unsigned inlineMaxStack, 00100 unsigned inlineMaxFunctionSize, 00101 AnalysisInliningMode inliningMode, 00102 bool NoRetry); 00103 00104 /// Construct a clone of the given AnalysisManager with the given ASTContext 00105 /// and DiagnosticsEngine. 00106 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 00107 AnalysisManager &ParentAM); 00108 00109 ~AnalysisManager() { FlushDiagnostics(); } 00110 00111 void ClearContexts() { 00112 AnaCtxMgr.clear(); 00113 } 00114 00115 AnalysisDeclContextManager& getAnalysisDeclContextManager() { 00116 return AnaCtxMgr; 00117 } 00118 00119 StoreManagerCreator getStoreManagerCreator() { 00120 return CreateStoreMgr; 00121 } 00122 00123 ConstraintManagerCreator getConstraintManagerCreator() { 00124 return CreateConstraintMgr; 00125 } 00126 00127 CheckerManager *getCheckerManager() const { return CheckerMgr; } 00128 00129 virtual ASTContext &getASTContext() { 00130 return Ctx; 00131 } 00132 00133 virtual SourceManager &getSourceManager() { 00134 return getASTContext().getSourceManager(); 00135 } 00136 00137 virtual DiagnosticsEngine &getDiagnostic() { 00138 return Diags; 00139 } 00140 00141 const LangOptions &getLangOpts() const { 00142 return LangOpts; 00143 } 00144 00145 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() { 00146 return PD.get(); 00147 } 00148 00149 void FlushDiagnostics() { 00150 if (PD.get()) 00151 PD->FlushDiagnostics(0); 00152 } 00153 00154 unsigned getMaxNodes() const { return MaxNodes; } 00155 00156 unsigned getMaxVisit() const { return MaxVisit; } 00157 00158 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 00159 00160 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 00161 00162 bool shouldVisualize() const { 00163 return VisualizeEGDot || VisualizeEGUbi; 00164 } 00165 00166 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 00167 00168 bool shouldTrimGraph() const { return TrimGraph; } 00169 00170 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; } 00171 00172 bool shouldEagerlyAssume() const { return EagerlyAssume; } 00173 00174 bool shouldInlineCall() const { return (IPAMode == Inlining); } 00175 00176 CFG *getCFG(Decl const *D) { 00177 return AnaCtxMgr.getContext(D)->getCFG(); 00178 } 00179 00180 template <typename T> 00181 T *getAnalysis(Decl const *D) { 00182 return AnaCtxMgr.getContext(D)->getAnalysis<T>(); 00183 } 00184 00185 ParentMap &getParentMap(Decl const *D) { 00186 return AnaCtxMgr.getContext(D)->getParentMap(); 00187 } 00188 00189 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { 00190 return AnaCtxMgr.getContext(D); 00191 } 00192 00193 }; 00194 00195 } // enAnaCtxMgrspace 00196 00197 } // end clang namespace 00198 00199 #endif