Environment.h revision 218887
1218887Sdim//== Environment.h - Map from Stmt* to Locations/Values ---------*- C++ -*--==// 2218887Sdim// 3218887Sdim// The LLVM Compiler Infrastructure 4218887Sdim// 5218887Sdim// This file is distributed under the University of Illinois Open Source 6218887Sdim// License. See LICENSE.TXT for details. 7218887Sdim// 8218887Sdim//===----------------------------------------------------------------------===// 9218887Sdim// 10218887Sdim// This file defined the Environment and EnvironmentManager classes. 11218887Sdim// 12218887Sdim//===----------------------------------------------------------------------===// 13218887Sdim 14218887Sdim#ifndef LLVM_CLANG_GR_ENVIRONMENT_H 15218887Sdim#define LLVM_CLANG_GR_ENVIRONMENT_H 16218887Sdim 17218887Sdim#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" 18218887Sdim#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" 19218887Sdim#include "llvm/ADT/ImmutableMap.h" 20218887Sdim 21218887Sdimnamespace clang { 22218887Sdim 23218887Sdimclass LiveVariables; 24218887Sdim 25218887Sdimnamespace ento { 26218887Sdim 27218887Sdimclass EnvironmentManager; 28218887Sdimclass SValBuilder; 29218887Sdim 30218887Sdim/// Environment - An immutable map from Stmts to their current 31218887Sdim/// symbolic values (SVals). 32218887Sdim/// 33218887Sdimclass Environment { 34218887Sdimprivate: 35218887Sdim friend class EnvironmentManager; 36218887Sdim 37218887Sdim // Type definitions. 38218887Sdim typedef llvm::ImmutableMap<const Stmt*,SVal> BindingsTy; 39218887Sdim 40218887Sdim // Data. 41218887Sdim BindingsTy ExprBindings; 42218887Sdim 43218887Sdim Environment(BindingsTy eb) 44218887Sdim : ExprBindings(eb) {} 45218887Sdim 46218887Sdim SVal lookupExpr(const Stmt* E) const; 47218887Sdim 48218887Sdimpublic: 49218887Sdim typedef BindingsTy::iterator iterator; 50218887Sdim iterator begin() const { return ExprBindings.begin(); } 51218887Sdim iterator end() const { return ExprBindings.end(); } 52218887Sdim 53218887Sdim 54218887Sdim /// GetSVal - Fetches the current binding of the expression in the 55218887Sdim /// Environment. 56218887Sdim SVal getSVal(const Stmt* Ex, SValBuilder& svalBuilder) const; 57218887Sdim 58218887Sdim /// Profile - Profile the contents of an Environment object for use 59218887Sdim /// in a FoldingSet. 60218887Sdim static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) { 61218887Sdim env->ExprBindings.Profile(ID); 62218887Sdim } 63218887Sdim 64218887Sdim /// Profile - Used to profile the contents of this object for inclusion 65218887Sdim /// in a FoldingSet. 66218887Sdim void Profile(llvm::FoldingSetNodeID& ID) const { 67218887Sdim Profile(ID, this); 68218887Sdim } 69218887Sdim 70218887Sdim bool operator==(const Environment& RHS) const { 71218887Sdim return ExprBindings == RHS.ExprBindings; 72218887Sdim } 73218887Sdim}; 74218887Sdim 75218887Sdimclass EnvironmentManager { 76218887Sdimprivate: 77218887Sdim typedef Environment::BindingsTy::Factory FactoryTy; 78218887Sdim FactoryTy F; 79218887Sdim 80218887Sdimpublic: 81218887Sdim EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {} 82218887Sdim ~EnvironmentManager() {} 83218887Sdim 84218887Sdim Environment getInitialEnvironment() { 85218887Sdim return Environment(F.getEmptyMap()); 86218887Sdim } 87218887Sdim 88218887Sdim /// Bind the value 'V' to the statement 'S'. 89218887Sdim Environment bindExpr(Environment Env, const Stmt *S, SVal V, 90218887Sdim bool Invalidate); 91218887Sdim 92218887Sdim /// Bind the location 'location' and value 'V' to the statement 'S'. This 93218887Sdim /// is used when simulating loads/stores. 94218887Sdim Environment bindExprAndLocation(Environment Env, const Stmt *S, SVal location, 95218887Sdim SVal V); 96218887Sdim 97218887Sdim Environment removeDeadBindings(Environment Env, 98218887Sdim SymbolReaper &SymReaper, const GRState *ST, 99218887Sdim llvm::SmallVectorImpl<const MemRegion*>& RegionRoots); 100218887Sdim}; 101218887Sdim 102218887Sdim} // end GR namespace 103218887Sdim 104218887Sdim} // end clang namespace 105218887Sdim 106218887Sdim#endif 107