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 PathDiagnosticConsumers &Consumers,
51 StoreManagerCreator storemgr,
52 ConstraintManagerCreator constraintmgr,
53 CheckerManager *checkerMgr, AnalyzerOptions &Options,
54 CodeInjector *injector = nullptr);
56 ~AnalysisManager() override;
58 void ClearContexts() {
62 AnalysisDeclContextManager& getAnalysisDeclContextManager() {
66 StoreManagerCreator getStoreManagerCreator() {
67 return CreateStoreMgr;
70 AnalyzerOptions& getAnalyzerOptions() override {
74 ConstraintManagerCreator getConstraintManagerCreator() {
75 return CreateConstraintMgr;
78 CheckerManager *getCheckerManager() const { return CheckerMgr; }
80 ASTContext &getASTContext() override {
84 SourceManager &getSourceManager() override {
85 return getASTContext().getSourceManager();
88 DiagnosticsEngine &getDiagnostic() override {
92 const LangOptions &getLangOpts() const {
96 ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
100 void FlushDiagnostics();
102 bool shouldVisualize() const {
103 return options.visualizeExplodedGraphWithGraphViz;
106 bool shouldInlineCall() const {
107 return options.getIPAMode() != IPAK_None;
110 CFG *getCFG(Decl const *D) {
111 return AnaCtxMgr.getContext(D)->getCFG();
114 template <typename T>
115 T *getAnalysis(Decl const *D) {
116 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
119 ParentMap &getParentMap(Decl const *D) {
120 return AnaCtxMgr.getContext(D)->getParentMap();
123 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
124 return AnaCtxMgr.getContext(D);
127 static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
128 if (SM.isInMainFile(SL))
131 // Support the "unified sources" compilation method (eg. WebKit) that
132 // involves producing non-header files that include other non-header files.
133 // We should be included directly from a UnifiedSource* file
134 // and we shouldn't be a header - which is a very safe defensive check.
135 SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
136 if (!IL.isValid() || !SM.isInMainFile(IL))
138 // Should rather be "file name starts with", but the current .getFilename
139 // includes the full path.
140 if (SM.getFilename(IL).contains("UnifiedSource")) {
141 // It might be great to reuse FrontendOptions::getInputKindForExtension()
142 // but for now it doesn't discriminate between code and header files.
143 return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
144 .Cases("c", "m", "mm", "C", "cc", "cp", true)
145 .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
152 bool isInCodeFile(SourceLocation SL) {
153 const SourceManager &SM = getASTContext().getSourceManager();
154 return isInCodeFile(SL, SM);
158 } // enAnaCtxMgrspace
160 } // end clang namespace