| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H |
| 15 | #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H |
| 16 | |
| 17 | #include "clang/Analysis/AnalysisDeclContext.h" |
| 18 | #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" |
| 19 | #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" |
| 20 | #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" |
| 21 | #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h" |
| 22 | |
| 23 | namespace clang { |
| 24 | |
| 25 | class CodeInjector; |
| 26 | |
| 27 | namespace ento { |
| 28 | class CheckerManager; |
| 29 | |
| 30 | class AnalysisManager : public BugReporterData { |
| 31 | virtual void anchor(); |
| 32 | AnalysisDeclContextManager AnaCtxMgr; |
| 33 | |
| 34 | ASTContext &Ctx; |
| 35 | DiagnosticsEngine &Diags; |
| 36 | const LangOptions &LangOpts; |
| 37 | PathDiagnosticConsumers PathConsumers; |
| 38 | |
| 39 | |
| 40 | StoreManagerCreator CreateStoreMgr; |
| 41 | ConstraintManagerCreator CreateConstraintMgr; |
| 42 | |
| 43 | CheckerManager *CheckerMgr; |
| 44 | |
| 45 | public: |
| 46 | AnalyzerOptions &options; |
| 47 | |
| 48 | AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, |
| 49 | const PathDiagnosticConsumers &Consumers, |
| 50 | StoreManagerCreator storemgr, |
| 51 | ConstraintManagerCreator constraintmgr, |
| 52 | CheckerManager *checkerMgr, AnalyzerOptions &Options, |
| 53 | CodeInjector *injector = nullptr); |
| 54 | |
| 55 | ~AnalysisManager() override; |
| 56 | |
| 57 | void ClearContexts() { |
| 58 | AnaCtxMgr.clear(); |
| 59 | } |
| 60 | |
| 61 | AnalysisDeclContextManager& getAnalysisDeclContextManager() { |
| 62 | return AnaCtxMgr; |
| 63 | } |
| 64 | |
| 65 | StoreManagerCreator getStoreManagerCreator() { |
| 66 | return CreateStoreMgr; |
| 67 | } |
| 68 | |
| 69 | AnalyzerOptions& getAnalyzerOptions() override { |
| 70 | return options; |
| 71 | } |
| 72 | |
| 73 | ConstraintManagerCreator getConstraintManagerCreator() { |
| 74 | return CreateConstraintMgr; |
| 75 | } |
| 76 | |
| 77 | CheckerManager *getCheckerManager() const { return CheckerMgr; } |
| 78 | |
| 79 | ASTContext &getASTContext() override { |
| 80 | return Ctx; |
| 81 | } |
| 82 | |
| 83 | SourceManager &getSourceManager() override { |
| 84 | return getASTContext().getSourceManager(); |
| 85 | } |
| 86 | |
| 87 | DiagnosticsEngine &getDiagnostic() override { |
| 88 | return Diags; |
| 89 | } |
| 90 | |
| 91 | const LangOptions &getLangOpts() const { |
| 92 | return LangOpts; |
| 93 | } |
| 94 | |
| 95 | ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override { |
| 96 | return PathConsumers; |
| 97 | } |
| 98 | |
| 99 | void FlushDiagnostics(); |
| 100 | |
| 101 | bool shouldVisualize() const { |
| 102 | return options.visualizeExplodedGraphWithGraphViz; |
| 103 | } |
| 104 | |
| 105 | bool shouldInlineCall() const { |
| 106 | return options.getIPAMode() != IPAK_None; |
| 107 | } |
| 108 | |
| 109 | CFG *getCFG(Decl const *D) { |
| 110 | return AnaCtxMgr.getContext(D)->getCFG(); |
| 111 | } |
| 112 | |
| 113 | template <typename T> |
| 114 | T *getAnalysis(Decl const *D) { |
| 115 | return AnaCtxMgr.getContext(D)->getAnalysis<T>(); |
| 116 | } |
| 117 | |
| 118 | ParentMap &getParentMap(Decl const *D) { |
| 119 | return AnaCtxMgr.getContext(D)->getParentMap(); |
| 120 | } |
| 121 | |
| 122 | AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { |
| 123 | return AnaCtxMgr.getContext(D); |
| 124 | } |
| 125 | |
| 126 | static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) { |
| 127 | if (SM.isInMainFile(SL)) |
| 128 | return true; |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL)); |
| 135 | if (!IL.isValid() || !SM.isInMainFile(IL)) |
| 136 | return false; |
| 137 | |
| 138 | |
| 139 | if (SM.getFilename(IL).contains("UnifiedSource")) { |
| 140 | |
| 141 | |
| 142 | return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second) |
| 143 | .Cases("c", "m", "mm", "C", "cc", "cp", true) |
| 144 | .Cases("cpp", "CPP", "c++", "cxx", "cppm", true) |
| 145 | .Default(false); |
| 146 | } |
| 147 | |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | bool isInCodeFile(SourceLocation SL) { |
| 152 | const SourceManager &SM = getASTContext().getSourceManager(); |
| 153 | return isInCodeFile(SL, SM); |
| 154 | } |
| 155 | }; |
| 156 | |
| 157 | } |
| 158 | |
| 159 | } |
| 160 | |
| 161 | #endif |
| 162 | |