aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Analysis/PathSensitive/Store.h
blob: 0014c6dfb522ffd8075af77a8641a62dc765a363 (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
//== Store.h - Interface for maps from Locations to Values ------*- C++ -*--==//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defined the types Store and StoreManager.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_ANALYSIS_STORE_H
#define LLVM_CLANG_ANALYSIS_STORE_H

#include "clang/Analysis/PathSensitive/RValues.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/DenseSet.h"
#include <vector>
#include <iosfwd>

namespace clang {
  
typedef const void* Store;
  
namespace store {
  typedef const void* Binding;
  typedef const void* Region;
  
  class RegionExtent {
  public:
    enum Kind { Unknown = 0, Int = 0, Sym = 1 };
    
  protected:
    const uintptr_t Raw;
    RegionExtent(uintptr_t raw, Kind k) : Raw(raw | k) {}
    uintptr_t getData() const { return Raw & ~0x1; }
    
  public:
    // Folding-set profiling.
    void Profile(llvm::FoldingSetNodeID& ID) const {
      ID.AddPointer((void*) Raw);
    }  
    // Comparing extents.
    bool operator==(const RegionExtent& R) const {
      return Raw == R.Raw;
    }
    bool operator!=(const RegionExtent& R) const {
      return Raw != R.Raw;
    }  
    // Implement isa<T> support.
    Kind getKind() const { return Kind(Raw & 0x1); }
    uintptr_t getRaw() const { return Raw; }
    
    static inline bool classof(const RegionExtent*) {
      return true;
    }
  };
  
  class UnknownExtent : public RegionExtent {
  public:
    UnknownExtent() : RegionExtent(0,Unknown) {}
    
    // Implement isa<T> support.
    static inline bool classof(const RegionExtent* E) {
      return E->getRaw() == 0;
    }  
  };
  
  class IntExtent : public RegionExtent {
  public:
    IntExtent(const llvm::APSInt& X) : RegionExtent((uintptr_t) &X, Int) {}
    
    const llvm::APSInt& getInt() const {
      return *((llvm::APSInt*) getData());
    }
    
    // Implement isa<T> support.
    static inline bool classof(const RegionExtent* E) {
      return E->getKind() == Int && E->getRaw() != 0;
    }
  };
  
  class SymExtent : public RegionExtent {
  public:
    SymExtent(SymbolID S) : RegionExtent(S.getNumber() << 1, Sym) {}
    
    SymbolID getSymbol() const { return SymbolID(getData() >> 1); }
    
    // Implement isa<T> support.
    static inline bool classof(const RegionExtent* E) {
      return E->getKind() == Sym;
    }  
  };
} // end store namespace
  
class GRStateManager;
class LiveVariables;
class Stmt;
  
class StoreManager {
public:
  typedef llvm::SmallSet<SymbolID, 20>      LiveSymbolsTy;
  typedef llvm::DenseSet<SymbolID>          DeadSymbolsTy;
  typedef std::vector<ValueDecl*>           DeclRootsTy;
  
  virtual ~StoreManager() {}
  virtual RVal GetRVal(Store St, LVal LV, QualType T = QualType()) = 0;
  virtual Store SetRVal(Store St, LVal LV, RVal V) = 0;
  virtual Store Remove(Store St, LVal LV) = 0;
  virtual Store getInitialStore(GRStateManager& StateMgr) = 0;
  
  virtual Store RemoveDeadBindings(Store store, Stmt* Loc,
                                   const LiveVariables& Live,
                                   DeclRootsTy& DRoots, LiveSymbolsTy& LSymbols,                                  
                                   DeadSymbolsTy& DSymbols) = 0;

  virtual Store AddDecl(Store store, GRStateManager& StMgr,
                        const VarDecl* VD, Expr* Ex, 
                        RVal InitVal = UndefinedVal(), unsigned Count = 0) = 0;

  virtual void print(Store store, std::ostream& Out,
                     const char* nl, const char *sep) = 0;
    
  /// getExtent - Returns the size of the region in bits.
  virtual store::RegionExtent getExtent(store::Region R) =0;
};
  
} // end clang namespace

#endif