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_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
18 #include "clang/Analysis/AnalysisDeclContext.h"
19 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
20 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
21 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
22 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
31 class AnalysisManager : public BugReporterData {
32 virtual void anchor();
33 AnalysisDeclContextManager AnaCtxMgr;
36 DiagnosticsEngine &Diags;
37 const LangOptions &LangOpts;
38 PathDiagnosticConsumers PathConsumers;
40 // Configurable components creators.
41 StoreManagerCreator CreateStoreMgr;
42 ConstraintManagerCreator CreateConstraintMgr;
44 CheckerManager *CheckerMgr;
47 AnalyzerOptions &options;
49 AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
50 const LangOptions &lang,
51 const PathDiagnosticConsumers &Consumers,
52 StoreManagerCreator storemgr,
53 ConstraintManagerCreator constraintmgr,
54 CheckerManager *checkerMgr,
55 AnalyzerOptions &Options,
56 CodeInjector* injector = nullptr);
58 ~AnalysisManager() override;
60 void ClearContexts() {
64 AnalysisDeclContextManager& getAnalysisDeclContextManager() {
68 StoreManagerCreator getStoreManagerCreator() {
69 return CreateStoreMgr;
72 AnalyzerOptions& getAnalyzerOptions() override {
76 ConstraintManagerCreator getConstraintManagerCreator() {
77 return CreateConstraintMgr;
80 CheckerManager *getCheckerManager() const { return CheckerMgr; }
82 ASTContext &getASTContext() override {
86 SourceManager &getSourceManager() override {
87 return getASTContext().getSourceManager();
90 DiagnosticsEngine &getDiagnostic() override {
94 const LangOptions &getLangOpts() const {
98 ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
102 void FlushDiagnostics();
104 bool shouldVisualize() const {
105 return options.visualizeExplodedGraphWithGraphViz ||
106 options.visualizeExplodedGraphWithUbiGraph;
109 bool shouldInlineCall() const {
110 return options.getIPAMode() != IPAK_None;
113 CFG *getCFG(Decl const *D) {
114 return AnaCtxMgr.getContext(D)->getCFG();
117 template <typename T>
118 T *getAnalysis(Decl const *D) {
119 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
122 ParentMap &getParentMap(Decl const *D) {
123 return AnaCtxMgr.getContext(D)->getParentMap();
126 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
127 return AnaCtxMgr.getContext(D);
130 static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
131 if (SM.isInMainFile(SL))
134 // Support the "unified sources" compilation method (eg. WebKit) that
135 // involves producing non-header files that include other non-header files.
136 // We should be included directly from a UnifiedSource* file
137 // and we shouldn't be a header - which is a very safe defensive check.
138 SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
139 if (!IL.isValid() || !SM.isInMainFile(IL))
141 // Should rather be "file name starts with", but the current .getFilename
142 // includes the full path.
143 if (SM.getFilename(IL).contains("UnifiedSource")) {
144 // It might be great to reuse FrontendOptions::getInputKindForExtension()
145 // but for now it doesn't discriminate between code and header files.
146 return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
147 .Cases("c", "m", "mm", "C", "cc", "cp", true)
148 .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
155 bool isInCodeFile(SourceLocation SL) {
156 const SourceManager &SM = getASTContext().getSourceManager();
157 return isInCodeFile(SL, SM);
161 } // enAnaCtxMgrspace
163 } // end clang namespace