Environment.h revision 218887
1204076Spjd//== Environment.h - Map from Stmt* to Locations/Values ---------*- C++ -*--==//
2230515Spjd//
3204076Spjd//                     The LLVM Compiler Infrastructure
4204076Spjd//
5230515Spjd// This file is distributed under the University of Illinois Open Source
6204076Spjd// License. See LICENSE.TXT for details.
7204076Spjd//
8204076Spjd//===----------------------------------------------------------------------===//
9204076Spjd//
10204076Spjd//  This file defined the Environment and EnvironmentManager classes.
11204076Spjd//
12204076Spjd//===----------------------------------------------------------------------===//
13204076Spjd
14204076Spjd#ifndef LLVM_CLANG_GR_ENVIRONMENT_H
15204076Spjd#define LLVM_CLANG_GR_ENVIRONMENT_H
16204076Spjd
17204076Spjd#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
18204076Spjd#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
19204076Spjd#include "llvm/ADT/ImmutableMap.h"
20204076Spjd
21204076Spjdnamespace clang {
22204076Spjd
23204076Spjdclass LiveVariables;
24204076Spjd
25204076Spjdnamespace ento {
26204076Spjd
27204076Spjdclass EnvironmentManager;
28204076Spjdclass SValBuilder;
29204076Spjd
30204076Spjd/// Environment - An immutable map from Stmts to their current
31230515Spjd///  symbolic values (SVals).
32204076Spjd///
33204076Spjdclass Environment {
34204076Spjdprivate:
35204076Spjd  friend class EnvironmentManager;
36204076Spjd
37204076Spjd  // Type definitions.
38211397Sjoel  typedef llvm::ImmutableMap<const Stmt*,SVal> BindingsTy;
39204076Spjd
40235337Sgjb  // Data.
41204076Spjd  BindingsTy ExprBindings;
42204076Spjd
43204076Spjd  Environment(BindingsTy eb)
44204076Spjd    : ExprBindings(eb) {}
45204076Spjd
46204076Spjd  SVal lookupExpr(const Stmt* E) const;
47204076Spjd
48204076Spjdpublic:
49204076Spjd  typedef BindingsTy::iterator iterator;
50204076Spjd  iterator begin() const { return ExprBindings.begin(); }
51204076Spjd  iterator end() const { return ExprBindings.end(); }
52204076Spjd
53204076Spjd
54204076Spjd  /// GetSVal - Fetches the current binding of the expression in the
55204076Spjd  ///  Environment.
56204076Spjd  SVal getSVal(const Stmt* Ex, SValBuilder& svalBuilder) const;
57204076Spjd
58204076Spjd  /// Profile - Profile the contents of an Environment object for use
59204076Spjd  ///  in a FoldingSet.
60204076Spjd  static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) {
61204076Spjd    env->ExprBindings.Profile(ID);
62219351Spjd  }
63219354Spjd
64207371Spjd  /// Profile - Used to profile the contents of this object for inclusion
65211887Spjd  ///  in a FoldingSet.
66238538Strociny  void Profile(llvm::FoldingSetNodeID& ID) const {
67226463Spjd    Profile(ID, this);
68204076Spjd  }
69204076Spjd
70204076Spjd  bool operator==(const Environment& RHS) const {
71204076Spjd    return ExprBindings == RHS.ExprBindings;
72204076Spjd  }
73226463Spjd};
74204076Spjd
75204076Spjdclass EnvironmentManager {
76204076Spjdprivate:
77204076Spjd  typedef Environment::BindingsTy::Factory FactoryTy;
78204076Spjd  FactoryTy F;
79204076Spjd
80226463Spjdpublic:
81204076Spjd  EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {}
82204076Spjd  ~EnvironmentManager() {}
83204076Spjd
84204076Spjd  Environment getInitialEnvironment() {
85204076Spjd    return Environment(F.getEmptyMap());
86219351Spjd  }
87219354Spjd
88204076Spjd  /// Bind the value 'V' to the statement 'S'.
89204076Spjd  Environment bindExpr(Environment Env, const Stmt *S, SVal V,
90207371Spjd                       bool Invalidate);
91211887Spjd
92238538Strociny  /// Bind the location 'location' and value 'V' to the statement 'S'.  This
93204076Spjd  /// is used when simulating loads/stores.
94204076Spjd  Environment bindExprAndLocation(Environment Env, const Stmt *S, SVal location,
95204076Spjd                                  SVal V);
96204076Spjd
97204076Spjd  Environment removeDeadBindings(Environment Env,
98204076Spjd                                 SymbolReaper &SymReaper, const GRState *ST,
99238538Strociny                          llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
100204076Spjd};
101204076Spjd
102219818Spjd} // end GR namespace
103204076Spjd
104204076Spjd} // end clang namespace
105204076Spjd
106204076Spjd#endif
107204076Spjd