Environment.h revision 0fb0bc4067d6c9d7c0e655300ef309b05d3adfc9
1//== Environment.h - Map from Stmt* to Locations/Values ---------*- 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 defined the Environment and EnvironmentManager classes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_ANALYSIS_ENVIRONMENT_H
15#define LLVM_CLANG_ANALYSIS_ENVIRONMENT_H
16
17// For using typedefs in StoreManager. Should find a better place for these
18// typedefs.
19#include "clang/Analysis/PathSensitive/Store.h"
20
21#include "llvm/ADT/ImmutableMap.h"
22#include "llvm/ADT/SmallVector.h"
23#include "clang/Analysis/PathSensitive/SVals.h"
24#include "llvm/Support/Allocator.h"
25#include "llvm/ADT/FoldingSet.h"
26
27namespace clang {
28
29class AnalysisContext;
30class EnvironmentManager;
31class ValueManager;
32class LiveVariables;
33
34
35class Environment {
36private:
37  friend class EnvironmentManager;
38
39  // Type definitions.
40  typedef llvm::ImmutableMap<const Stmt*,SVal> BindingsTy;
41
42  // Data.
43  BindingsTy ExprBindings;
44
45  Environment(BindingsTy eb)
46    : ExprBindings(eb) {}
47
48public:
49  typedef BindingsTy::iterator iterator;
50  iterator begin() const { return ExprBindings.begin(); }
51  iterator end() const { return ExprBindings.end(); }
52
53  SVal LookupExpr(const Stmt* E) const {
54    const SVal* X = ExprBindings.lookup(E);
55    return X ? *X : UnknownVal();
56  }
57
58  SVal GetSVal(const Stmt* Ex, ValueManager& ValMgr) const;
59
60  /// Profile - Profile the contents of an Environment object for use
61  ///  in a FoldingSet.
62  static void Profile(llvm::FoldingSetNodeID& ID, const Environment* E) {
63    E->ExprBindings.Profile(ID);
64  }
65
66  /// Profile - Used to profile the contents of this object for inclusion
67  ///  in a FoldingSet.
68  void Profile(llvm::FoldingSetNodeID& ID) const {
69    Profile(ID, this);
70  }
71
72  bool operator==(const Environment& RHS) const {
73    return ExprBindings == RHS.ExprBindings;
74  }
75};
76
77class EnvironmentManager {
78private:
79  typedef Environment::BindingsTy::Factory FactoryTy;
80  FactoryTy F;
81
82public:
83  EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {}
84  ~EnvironmentManager() {}
85
86  Environment getInitialEnvironment() {
87    return Environment(F.GetEmptyMap());
88  }
89
90  Environment BindExpr(Environment Env, const Stmt *S, SVal V,
91                       bool Invalidate);
92
93  Environment RemoveDeadBindings(Environment Env, const Stmt *S,
94                                 SymbolReaper &SymReaper, const GRState *ST,
95                          llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
96};
97
98} // end clang namespace
99
100#endif
101