Environment.h revision 1eb4433ac451dc16f4133a88af2d002ac26c58ef
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  AnalysisContext *ACtx;
45
46  Environment(BindingsTy eb, AnalysisContext *aCtx)
47    : ExprBindings(eb), ACtx(aCtx) {}
48
49public:
50  typedef BindingsTy::iterator iterator;
51  iterator begin() const { return ExprBindings.begin(); }
52  iterator end() const { return ExprBindings.end(); }
53
54  SVal LookupExpr(const Stmt* E) const {
55    const SVal* X = ExprBindings.lookup(E);
56    return X ? *X : UnknownVal();
57  }
58
59  SVal GetSVal(const Stmt* Ex, ValueManager& ValMgr) const;
60
61  AnalysisContext &getAnalysisContext() const { return *ACtx; }
62
63  /// Profile - Profile the contents of an Environment object for use
64  ///  in a FoldingSet.
65  static void Profile(llvm::FoldingSetNodeID& ID, const Environment* E) {
66    E->ExprBindings.Profile(ID);
67  }
68
69  /// Profile - Used to profile the contents of this object for inclusion
70  ///  in a FoldingSet.
71  void Profile(llvm::FoldingSetNodeID& ID) const {
72    Profile(ID, this);
73  }
74
75  bool operator==(const Environment& RHS) const {
76    return ExprBindings == RHS.ExprBindings;
77  }
78};
79
80class EnvironmentManager {
81private:
82  typedef Environment::BindingsTy::Factory FactoryTy;
83  FactoryTy F;
84
85public:
86  EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {}
87  ~EnvironmentManager() {}
88
89  Environment getInitialEnvironment(AnalysisContext *ACtx) {
90    return Environment(F.GetEmptyMap(), ACtx);
91  }
92
93  Environment BindExpr(Environment Env, const Stmt *S, SVal V,
94                       bool Invalidate);
95
96  Environment RemoveDeadBindings(Environment Env, const Stmt *S,
97                                 SymbolReaper &SymReaper, const GRState *ST,
98                          llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
99};
100
101} // end clang namespace
102
103#endif
104