clang API Documentation

AnalysisManager.h
Go to the documentation of this file.
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_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
00016 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
00017 
00018 #include "clang/Analysis/AnalysisContext.h"
00019 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
00020 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
00021 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
00022 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
00023 
00024 namespace clang {
00025 
00026 class CodeInjector;
00027 
00028 namespace ento {
00029   class CheckerManager;
00030 
00031 class AnalysisManager : public BugReporterData {
00032   virtual void anchor();
00033   AnalysisDeclContextManager AnaCtxMgr;
00034 
00035   ASTContext &Ctx;
00036   DiagnosticsEngine &Diags;
00037   const LangOptions &LangOpts;
00038   PathDiagnosticConsumers PathConsumers;
00039 
00040   // Configurable components creators.
00041   StoreManagerCreator CreateStoreMgr;
00042   ConstraintManagerCreator CreateConstraintMgr;
00043 
00044   CheckerManager *CheckerMgr;
00045 
00046 public:
00047   AnalyzerOptions &options;
00048   
00049   AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
00050                   const LangOptions &lang,
00051                   const PathDiagnosticConsumers &Consumers,
00052                   StoreManagerCreator storemgr,
00053                   ConstraintManagerCreator constraintmgr, 
00054                   CheckerManager *checkerMgr,
00055                   AnalyzerOptions &Options,
00056                   CodeInjector* injector = nullptr);
00057 
00058   ~AnalysisManager();
00059   
00060   void ClearContexts() {
00061     AnaCtxMgr.clear();
00062   }
00063   
00064   AnalysisDeclContextManager& getAnalysisDeclContextManager() {
00065     return AnaCtxMgr;
00066   }
00067 
00068   StoreManagerCreator getStoreManagerCreator() {
00069     return CreateStoreMgr;
00070   }
00071 
00072   AnalyzerOptions& getAnalyzerOptions() override {
00073     return options;
00074   }
00075 
00076   ConstraintManagerCreator getConstraintManagerCreator() {
00077     return CreateConstraintMgr;
00078   }
00079 
00080   CheckerManager *getCheckerManager() const { return CheckerMgr; }
00081 
00082   ASTContext &getASTContext() override {
00083     return Ctx;
00084   }
00085 
00086   SourceManager &getSourceManager() override {
00087     return getASTContext().getSourceManager();
00088   }
00089 
00090   DiagnosticsEngine &getDiagnostic() override {
00091     return Diags;
00092   }
00093 
00094   const LangOptions &getLangOpts() const {
00095     return LangOpts;
00096   }
00097 
00098   ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
00099     return PathConsumers;
00100   }
00101 
00102   void FlushDiagnostics();
00103 
00104   bool shouldVisualize() const {
00105     return options.visualizeExplodedGraphWithGraphViz ||
00106            options.visualizeExplodedGraphWithUbiGraph;
00107   }
00108 
00109   bool shouldInlineCall() const {
00110     return options.getIPAMode() != IPAK_None;
00111   }
00112 
00113   CFG *getCFG(Decl const *D) {
00114     return AnaCtxMgr.getContext(D)->getCFG();
00115   }
00116 
00117   template <typename T>
00118   T *getAnalysis(Decl const *D) {
00119     return AnaCtxMgr.getContext(D)->getAnalysis<T>();
00120   }
00121 
00122   ParentMap &getParentMap(Decl const *D) {
00123     return AnaCtxMgr.getContext(D)->getParentMap();
00124   }
00125 
00126   AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
00127     return AnaCtxMgr.getContext(D);
00128   }
00129 };
00130 
00131 } // enAnaCtxMgrspace
00132 
00133 } // end clang namespace
00134 
00135 #endif