Home | History | Annotate | Download | only in PathSensitive
      1 //== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines the AnalysisManager class that manages the data and policy
     11 // for path sensitive analysis.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
     16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
     17 
     18 #include "clang/Analysis/AnalysisContext.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"
     23 
     24 namespace clang {
     25 
     26 class CodeInjector;
     27 
     28 namespace ento {
     29   class CheckerManager;
     30 
     31 class AnalysisManager : public BugReporterData {
     32   virtual void anchor();
     33   AnalysisDeclContextManager AnaCtxMgr;
     34 
     35   ASTContext &Ctx;
     36   DiagnosticsEngine &Diags;
     37   const LangOptions &LangOpts;
     38   PathDiagnosticConsumers PathConsumers;
     39 
     40   // Configurable components creators.
     41   StoreManagerCreator CreateStoreMgr;
     42   ConstraintManagerCreator CreateConstraintMgr;
     43 
     44   CheckerManager *CheckerMgr;
     45 
     46 public:
     47   AnalyzerOptions &options;
     48 
     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);
     57 
     58   ~AnalysisManager() override;
     59 
     60   void ClearContexts() {
     61     AnaCtxMgr.clear();
     62   }
     63 
     64   AnalysisDeclContextManager& getAnalysisDeclContextManager() {
     65     return AnaCtxMgr;
     66   }
     67 
     68   StoreManagerCreator getStoreManagerCreator() {
     69     return CreateStoreMgr;
     70   }
     71 
     72   AnalyzerOptions& getAnalyzerOptions() override {
     73     return options;
     74   }
     75 
     76   ConstraintManagerCreator getConstraintManagerCreator() {
     77     return CreateConstraintMgr;
     78   }
     79 
     80   CheckerManager *getCheckerManager() const { return CheckerMgr; }
     81 
     82   ASTContext &getASTContext() override {
     83     return Ctx;
     84   }
     85 
     86   SourceManager &getSourceManager() override {
     87     return getASTContext().getSourceManager();
     88   }
     89 
     90   DiagnosticsEngine &getDiagnostic() override {
     91     return Diags;
     92   }
     93 
     94   const LangOptions &getLangOpts() const {
     95     return LangOpts;
     96   }
     97 
     98   ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() override {
     99     return PathConsumers;
    100   }
    101 
    102   void FlushDiagnostics();
    103 
    104   bool shouldVisualize() const {
    105     return options.visualizeExplodedGraphWithGraphViz ||
    106            options.visualizeExplodedGraphWithUbiGraph;
    107   }
    108 
    109   bool shouldInlineCall() const {
    110     return options.getIPAMode() != IPAK_None;
    111   }
    112 
    113   CFG *getCFG(Decl const *D) {
    114     return AnaCtxMgr.getContext(D)->getCFG();
    115   }
    116 
    117   template <typename T>
    118   T *getAnalysis(Decl const *D) {
    119     return AnaCtxMgr.getContext(D)->getAnalysis<T>();
    120   }
    121 
    122   ParentMap &getParentMap(Decl const *D) {
    123     return AnaCtxMgr.getContext(D)->getParentMap();
    124   }
    125 
    126   AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
    127     return AnaCtxMgr.getContext(D);
    128   }
    129 };
    130 
    131 } // enAnaCtxMgrspace
    132 
    133 } // end clang namespace
    134 
    135 #endif
    136