Environment.h revision 226633
156022Stanimura//== Environment.h - Map from Stmt* to Locations/Values ---------*- C++ -*--==// 256022Stanimura// 356022Stanimura// The LLVM Compiler Infrastructure 456022Stanimura// 556022Stanimura// This file is distributed under the University of Illinois Open Source 656022Stanimura// License. See LICENSE.TXT for details. 756022Stanimura// 856022Stanimura//===----------------------------------------------------------------------===// 956022Stanimura// 1056022Stanimura// This file defined the Environment and EnvironmentManager classes. 1156022Stanimura// 1256022Stanimura//===----------------------------------------------------------------------===// 1356022Stanimura 1456022Stanimura#ifndef LLVM_CLANG_GR_ENVIRONMENT_H 1556022Stanimura#define LLVM_CLANG_GR_ENVIRONMENT_H 1656022Stanimura 1756022Stanimura#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" 1856022Stanimura#include "llvm/ADT/ImmutableMap.h" 1956022Stanimura 2056022Stanimuranamespace clang { 2156022Stanimura 2256022Stanimuraclass LiveVariables; 2356022Stanimura 2456022Stanimuranamespace ento { 2556022Stanimura 2656022Stanimuraclass EnvironmentManager; 2756022Stanimuraclass SValBuilder; 28166800Sjoel 29134938Sru/// Environment - An immutable map from Stmts to their current 3079538Sru/// symbolic values (SVals). 3156022Stanimura/// 32166800Sjoelclass Environment { 33166800Sjoelprivate: 34166800Sjoel friend class EnvironmentManager; 3556022Stanimura 3656022Stanimura // Type definitions. 37153459Sjoel typedef llvm::ImmutableMap<const Stmt*,SVal> BindingsTy; 38153459Sjoel 39153459Sjoel // Data. 40134938Sru BindingsTy ExprBindings; 41134938Sru 42166800Sjoel Environment(BindingsTy eb) 43166800Sjoel : ExprBindings(eb) {} 44153459Sjoel 4556022Stanimura SVal lookupExpr(const Stmt *E) const; 46153459Sjoel 47166800Sjoelpublic: 48153459Sjoel typedef BindingsTy::iterator iterator; 49153459Sjoel iterator begin() const { return ExprBindings.begin(); } 50153459Sjoel iterator end() const { return ExprBindings.end(); } 51166800Sjoel 52166800Sjoel 53153459Sjoel /// getSVal - Fetches the current binding of the expression in the 54153459Sjoel /// Environment. 5586715Sru SVal getSVal(const Stmt *Ex, SValBuilder& svalBuilder, 56153459Sjoel bool useOnlyDirectBindings = false) const; 57153459Sjoel 58153459Sjoel /// Profile - Profile the contents of an Environment object for use 59153459Sjoel /// in a FoldingSet. 60153459Sjoel static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) { 61153459Sjoel env->ExprBindings.Profile(ID); 62153459Sjoel } 63153459Sjoel 6456022Stanimura /// Profile - Used to profile the contents of this object for inclusion 6556022Stanimura /// in a FoldingSet. 6656022Stanimura void Profile(llvm::FoldingSetNodeID& ID) const { 67159748Sbrueffer Profile(ID, this); 68134938Sru } 69166801Sjoel 70166800Sjoel bool operator==(const Environment& RHS) const { 7156022Stanimura return ExprBindings == RHS.ExprBindings; 7257676Ssheldonh } 7357676Ssheldonh}; 74131530Sru 75131530Sruclass EnvironmentManager { 7656022Stanimuraprivate: 77142343Sbrueffer typedef Environment::BindingsTy::Factory FactoryTy; 78142343Sbrueffer FactoryTy F; 79142343Sbrueffer 80146489Sbruefferpublic: 81142343Sbrueffer EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {} 82142343Sbrueffer ~EnvironmentManager() {} 83142343Sbrueffer 84149198Sjoel Environment getInitialEnvironment() { 85142343Sbrueffer return Environment(F.getEmptyMap()); 86149198Sjoel } 87142343Sbrueffer 88149198Sjoel /// Bind the value 'V' to the statement 'S'. 89142343Sbrueffer Environment bindExpr(Environment Env, const Stmt *S, SVal V, 90149198Sjoel bool Invalidate); 91149198Sjoel 92149198Sjoel /// Bind the location 'location' and value 'V' to the statement 'S'. This 93149198Sjoel /// is used when simulating loads/stores. 94149198Sjoel Environment bindExprAndLocation(Environment Env, const Stmt *S, SVal location, 95149198Sjoel SVal V); 96149198Sjoel 97149198Sjoel Environment removeDeadBindings(Environment Env, 98149198Sjoel SymbolReaper &SymReaper, const ProgramState *ST); 99149198Sjoel}; 100149198Sjoel 101149198Sjoel} // end GR namespace 102149198Sjoel 103149198Sjoel} // end clang namespace 104149198Sjoel 105149198Sjoel#endif 106149198Sjoel