Environment.h revision 5a4f98ff943e6a501b0fe47ade007c9bbf96cb88
180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//== Environment.h - Map from Stmt* to Locations/Values ---------*- C++ -*--==// 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// The LLVM Compiler Infrastructure 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// This file is distributed under the University of Illinois Open Source 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// License. See LICENSE.TXT for details. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//===----------------------------------------------------------------------===// 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// This file defined the Environment and EnvironmentManager classes. 11363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger// 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru//===----------------------------------------------------------------------===// 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef LLVM_CLANG_GR_ENVIRONMENT_H 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define LLVM_CLANG_GR_ENVIRONMENT_H 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "clang/GR/PathSensitive/Store.h" 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "clang/GR/PathSensitive/SVals.h" 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "llvm/ADT/ImmutableMap.h" 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querunamespace clang { 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass LiveVariables; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querunamespace GR { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass EnvironmentManager; 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SValBuilder; 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/// Environment - An immutable map from Stmts to their current 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/// symbolic values (SVals). 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/// 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass Environment { 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru friend class EnvironmentManager; 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // Type definitions. 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef llvm::ImmutableMap<const Stmt*,SVal> BindingsTy; 39363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger 40363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger // Data. 41363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger BindingsTy ExprBindings; 42363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger 43363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger Environment(BindingsTy eb) 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru : ExprBindings(eb) {} 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SVal lookupExpr(const Stmt* E) const; 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef BindingsTy::iterator iterator; 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru iterator begin() const { return ExprBindings.begin(); } 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru iterator end() const { return ExprBindings.end(); } 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /// GetSVal - Fetches the current binding of the expression in the 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /// Environment. 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SVal getSVal(const Stmt* Ex, SValBuilder& svalBuilder) const; 57 58 /// Profile - Profile the contents of an Environment object for use 59 /// in a FoldingSet. 60 static void Profile(llvm::FoldingSetNodeID& ID, const Environment* env) { 61 env->ExprBindings.Profile(ID); 62 } 63 64 /// Profile - Used to profile the contents of this object for inclusion 65 /// in a FoldingSet. 66 void Profile(llvm::FoldingSetNodeID& ID) const { 67 Profile(ID, this); 68 } 69 70 bool operator==(const Environment& RHS) const { 71 return ExprBindings == RHS.ExprBindings; 72 } 73}; 74 75class EnvironmentManager { 76private: 77 typedef Environment::BindingsTy::Factory FactoryTy; 78 FactoryTy F; 79 80public: 81 EnvironmentManager(llvm::BumpPtrAllocator& Allocator) : F(Allocator) {} 82 ~EnvironmentManager() {} 83 84 Environment getInitialEnvironment() { 85 return Environment(F.getEmptyMap()); 86 } 87 88 /// Bind the value 'V' to the statement 'S'. 89 Environment bindExpr(Environment Env, const Stmt *S, SVal V, 90 bool Invalidate); 91 92 /// Bind the location 'location' and value 'V' to the statement 'S'. This 93 /// is used when simulating loads/stores. 94 Environment bindExprAndLocation(Environment Env, const Stmt *S, SVal location, 95 SVal V); 96 97 Environment RemoveDeadBindings(Environment Env, 98 SymbolReaper &SymReaper, const GRState *ST, 99 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots); 100}; 101 102} // end GR namespace 103 104} // end clang namespace 105 106#endif 107