aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Analysis/PathSensitive/AnalysisManager.h
blob: 97534c8716939f516215180117247d4e2f359c48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the AnalysisManager class that manages the data and policy
// for path sensitive analysis.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_ANALYSIS_ANALYSISMANAGER_H
#define LLVM_CLANG_ANALYSIS_ANALYSISMANAGER_H

#include "clang/Analysis/PathSensitive/BugReporter.h"
#include "clang/Analysis/PathSensitive/AnalysisContext.h"
#include "clang/Analysis/PathDiagnostic.h"

namespace clang {

class AnalysisManager : public BugReporterData {
  AnalysisContextManager ContextMgr;
  AnalysisContext *EntryContext;

  LocationContextManager LocCtxMgr;

  ASTContext &Ctx;
  Diagnostic &Diags;
  const LangOptions &LangInfo;

  llvm::OwningPtr<PathDiagnosticClient> PD;

  // Configurable components creators.
  StoreManagerCreator CreateStoreMgr;
  ConstraintManagerCreator CreateConstraintMgr;

  enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
      
  bool DisplayedFunction;
  bool VisualizeEGDot;
  bool VisualizeEGUbi;
  bool PurgeDead;

  /// EargerlyAssume - A flag indicating how the engine should handle
  //   expressions such as: 'x = (y != 0)'.  When this flag is true then
  //   the subexpression 'y != 0' will be eagerly assumed to be true or false,
  //   thus evaluating it to the integers 0 or 1 respectively.  The upside
  //   is that this can increase analysis precision until we have a better way
  //   to lazily evaluate such logic.  The downside is that it eagerly
  //   bifurcates paths.
  bool EagerlyAssume;
  bool TrimGraph;

public:
  AnalysisManager(Decl *d, ASTContext &ctx, Diagnostic &diags, 
                  const LangOptions &lang, PathDiagnosticClient *pd,
                  StoreManagerCreator storemgr,
                  ConstraintManagerCreator constraintmgr,
                  bool displayProgress, bool vizdot, bool vizubi, 
                  bool purge, bool eager, bool trim)
    : Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd), 
      CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
      AScope(ScopeDecl), DisplayedFunction(!displayProgress),
      VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
      EagerlyAssume(eager), TrimGraph(trim) {

    EntryContext = ContextMgr.getContext(d);
  }
    
  AnalysisManager(ASTContext &ctx, Diagnostic &diags, 
                  const LangOptions &lang, PathDiagnosticClient *pd,
                  StoreManagerCreator storemgr,
                  ConstraintManagerCreator constraintmgr,
                  bool displayProgress, bool vizdot, bool vizubi, 
                  bool purge, bool eager, bool trim)

    : Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd), 
      CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
      AScope(ScopeDecl), DisplayedFunction(!displayProgress),
      VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
      EagerlyAssume(eager), TrimGraph(trim) {

    EntryContext = 0;
  }

  void setEntryContext(Decl *D) {
    EntryContext = ContextMgr.getContext(D);
    DisplayedFunction = false;
  }
    
  const Decl *getCodeDecl() const { 
    assert (AScope == ScopeDecl);
    return EntryContext->getDecl();
  }
    
  Stmt *getBody() const {
    assert (AScope == ScopeDecl);
    return EntryContext->getBody();
  }
    
  StoreManagerCreator getStoreManagerCreator() {
    return CreateStoreMgr;
  };

  ConstraintManagerCreator getConstraintManagerCreator() {
    return CreateConstraintMgr;
  }
    
  virtual CFG *getCFG() {
    return EntryContext->getCFG();
  }
    
  virtual ParentMap &getParentMap() {
    return EntryContext->getParentMap();
  }

  virtual LiveVariables *getLiveVariables() {
    return EntryContext->getLiveVariables();
  }
    
  virtual ASTContext &getASTContext() {
    return Ctx;
  }
    
  virtual SourceManager &getSourceManager() {
    return getASTContext().getSourceManager();
  }
    
  virtual Diagnostic &getDiagnostic() {
    return Diags;
  }
    
  const LangOptions &getLangOptions() const {
    return LangInfo;
  }
    
  virtual PathDiagnosticClient *getPathDiagnosticClient() {
    return PD.get();      
  }

  StackFrameContext *getEntryStackFrame() {
    return LocCtxMgr.getStackFrame(EntryContext, 0, 0);
  }
    
  bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }

  bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }

  bool shouldVisualize() const {
    return VisualizeEGDot || VisualizeEGUbi;
  }

  bool shouldTrimGraph() const { return TrimGraph; }

  bool shouldPurgeDead() const { return PurgeDead; }

  bool shouldEagerlyAssume() const { return EagerlyAssume; }

  void DisplayFunction();
};

}

#endif