Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 1 | //== BasicStore.cpp - Basic map from Locations to 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 BasicStore and BasicStoreManager classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Ted Kremenek | 5f81c44 | 2008-08-28 23:31:31 +0000 | [diff] [blame] | 14 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/GRState.h" |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/ImmutableMap.h" |
| 17 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Streams.h" |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 22 | typedef llvm::ImmutableMap<const VarDecl*,RVal> VarBindingsTy; |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 23 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 27 | VarBindingsTy::Factory VBFactory; |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 28 | GRStateManager& StateMgr; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 29 | |
| 30 | public: |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 31 | BasicStoreManager(GRStateManager& mgr) : StateMgr(mgr) {} |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 32 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 33 | virtual ~BasicStoreManager() {} |
| 34 | |
| 35 | virtual RVal GetRVal(Store St, LVal LV, QualType T); |
| 36 | virtual Store SetRVal(Store St, LVal LV, RVal V); |
| 37 | virtual Store Remove(Store St, LVal LV); |
| 38 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 39 | virtual Store getInitialStore(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 40 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 41 | virtual Store |
| 42 | RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live, |
| 43 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
| 44 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 45 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 46 | virtual void iterBindings(Store store, BindingsHandler& f); |
| 47 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 48 | virtual Store AddDecl(Store store, |
Ted Kremenek | e53c069 | 2008-08-23 00:50:55 +0000 | [diff] [blame] | 49 | const VarDecl* VD, Expr* Ex, |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 50 | RVal InitVal = UndefinedVal(), unsigned Count = 0); |
| 51 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 52 | static inline VarBindingsTy GetVarBindings(Store store) { |
| 53 | return VarBindingsTy(static_cast<const VarBindingsTy::TreeTy*>(store)); |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | virtual void print(Store store, std::ostream& Out, |
| 57 | const char* nl, const char *sep); |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 58 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 59 | }; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 60 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 61 | } // end anonymous namespace |
| 62 | |
| 63 | |
Ted Kremenek | 5f81c44 | 2008-08-28 23:31:31 +0000 | [diff] [blame] | 64 | StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) { |
| 65 | return new BasicStoreManager(StMgr); |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 68 | RVal BasicStoreManager::GetRVal(Store St, LVal LV, QualType T) { |
| 69 | |
| 70 | if (isa<UnknownVal>(LV)) |
| 71 | return UnknownVal(); |
| 72 | |
| 73 | assert (!isa<UndefinedVal>(LV)); |
| 74 | |
| 75 | switch (LV.getSubKind()) { |
| 76 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 77 | case lval::MemRegionKind: { |
| 78 | VarRegion* R = |
| 79 | dyn_cast<VarRegion>(cast<lval::MemRegionVal>(LV).getRegion()); |
| 80 | |
| 81 | if (!R) |
| 82 | return UnknownVal(); |
| 83 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 84 | VarBindingsTy B(static_cast<const VarBindingsTy::TreeTy*>(St)); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 85 | VarBindingsTy::data_type* T = B.lookup(R->getDecl()); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 86 | return T ? *T : UnknownVal(); |
| 87 | } |
| 88 | |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 89 | case lval::SymbolValKind: |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 90 | return UnknownVal(); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 91 | |
| 92 | case lval::ConcreteIntKind: |
| 93 | // Some clients may call GetRVal with such an option simply because |
| 94 | // they are doing a quick scan through their LVals (potentially to |
| 95 | // invalidate their bindings). Just return Undefined. |
| 96 | return UndefinedVal(); |
| 97 | |
| 98 | case lval::ArrayOffsetKind: |
| 99 | case lval::FieldOffsetKind: |
| 100 | return UnknownVal(); |
| 101 | |
| 102 | case lval::FuncValKind: |
| 103 | return LV; |
| 104 | |
| 105 | case lval::StringLiteralValKind: |
| 106 | // FIXME: Implement better support for fetching characters from strings. |
| 107 | return UnknownVal(); |
| 108 | |
| 109 | default: |
| 110 | assert (false && "Invalid LVal."); |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | return UnknownVal(); |
| 115 | } |
| 116 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 117 | Store BasicStoreManager::SetRVal(Store store, LVal LV, RVal V) { |
| 118 | switch (LV.getSubKind()) { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 119 | case lval::MemRegionKind: { |
| 120 | VarRegion* R = |
| 121 | dyn_cast<VarRegion>(cast<lval::MemRegionVal>(LV).getRegion()); |
| 122 | |
| 123 | if (!R) |
| 124 | return store; |
| 125 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 126 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 127 | return V.isUnknown() |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 128 | ? VBFactory.Remove(B, R->getDecl()).getRoot() |
| 129 | : VBFactory.Add(B, R->getDecl(), V).getRoot(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 130 | } |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 131 | default: |
| 132 | assert ("SetRVal for given LVal type not yet implemented."); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 133 | return store; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 137 | Store BasicStoreManager::Remove(Store store, LVal LV) { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 138 | switch (LV.getSubKind()) { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 139 | case lval::MemRegionKind: { |
| 140 | VarRegion* R = |
| 141 | dyn_cast<VarRegion>(cast<lval::MemRegionVal>(LV).getRegion()); |
| 142 | |
| 143 | if (!R) |
| 144 | return store; |
| 145 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 146 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 147 | return VBFactory.Remove(B,R->getDecl()).getRoot(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 148 | } |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 149 | default: |
| 150 | assert ("Remove for given LVal type not yet implemented."); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 151 | return store; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 154 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 155 | Store |
| 156 | BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, |
| 157 | const LiveVariables& Liveness, |
| 158 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots, |
| 159 | LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) { |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 160 | |
| 161 | VarBindingsTy B = GetVarBindings(store); |
| 162 | typedef RVal::symbol_iterator symbol_iterator; |
| 163 | |
| 164 | // Iterate over the variable bindings. |
| 165 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) |
| 166 | if (Liveness.isLive(Loc, I.getKey())) { |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 167 | RegionRoots.push_back(StateMgr.getRegion(I.getKey())); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 168 | RVal X = I.getData(); |
| 169 | |
| 170 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 171 | LSymbols.insert(*SI); |
| 172 | } |
| 173 | |
| 174 | // Scan for live variables and live symbols. |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 175 | llvm::SmallPtrSet<const VarRegion*, 10> Marked; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 176 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 177 | while (!RegionRoots.empty()) { |
| 178 | const VarRegion* R = cast<VarRegion>(RegionRoots.back()); |
| 179 | RegionRoots.pop_back(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 180 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 181 | if (Marked.count(R)) |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 182 | continue; |
| 183 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 184 | Marked.insert(R); |
| 185 | // FIXME: Do we need the QualType here, since regions are partially |
| 186 | // typed? |
| 187 | RVal X = GetRVal(store, lval::MemRegionVal(R), QualType()); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 188 | |
| 189 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 190 | LSymbols.insert(*SI); |
| 191 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 192 | if (!isa<lval::MemRegionVal>(X)) |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 193 | continue; |
| 194 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 195 | const lval::MemRegionVal& LVD = cast<lval::MemRegionVal>(X); |
| 196 | RegionRoots.push_back(cast<VarRegion>(LVD.getRegion())); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // Remove dead variable bindings. |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 200 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) { |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 201 | const VarRegion* R = cast<VarRegion>(StateMgr.getRegion(I.getKey())); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 202 | |
| 203 | if (!Marked.count(R)) { |
| 204 | store = Remove(store, lval::MemRegionVal(R)); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 205 | RVal X = I.getData(); |
| 206 | |
| 207 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 208 | if (!LSymbols.count(*SI)) DSymbols.insert(*SI); |
| 209 | } |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 212 | return store; |
| 213 | } |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 214 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 215 | Store BasicStoreManager::getInitialStore() { |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 216 | // The LiveVariables information already has a compilation of all VarDecls |
| 217 | // used in the function. Iterate through this set, and "symbolicate" |
| 218 | // any VarDecl whose value originally comes from outside the function. |
| 219 | |
| 220 | typedef LiveVariables::AnalysisDataTy LVDataTy; |
| 221 | LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData(); |
| 222 | |
| 223 | Store St = VBFactory.GetEmptyMap().getRoot(); |
| 224 | |
| 225 | for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { |
| 226 | ScopedDecl* SD = const_cast<ScopedDecl*>(I->first); |
| 227 | |
| 228 | if (VarDecl* VD = dyn_cast<VarDecl>(SD)) { |
| 229 | // Punt on static variables for now. |
| 230 | if (VD->getStorageClass() == VarDecl::Static) |
| 231 | continue; |
| 232 | |
| 233 | // Only handle pointers and integers for now. |
| 234 | QualType T = VD->getType(); |
| 235 | if (LVal::IsLValType(T) || T->isIntegerType()) { |
| 236 | // Initialize globals and parameters to symbolic values. |
| 237 | // Initialize local variables to undefined. |
| 238 | RVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) || |
| 239 | isa<ImplicitParamDecl>(VD)) |
| 240 | ? RVal::GetSymbolValue(StateMgr.getSymbolManager(), VD) |
| 241 | : UndefinedVal(); |
| 242 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 243 | St = SetRVal(St, StateMgr.getLVal(VD), X); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | } |
| 247 | return St; |
| 248 | } |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 249 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 250 | Store BasicStoreManager::AddDecl(Store store, |
Ted Kremenek | e53c069 | 2008-08-23 00:50:55 +0000 | [diff] [blame] | 251 | const VarDecl* VD, Expr* Ex, |
| 252 | RVal InitVal, unsigned Count) { |
| 253 | |
| 254 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
| 255 | SymbolManager& SymMgr = StateMgr.getSymbolManager(); |
| 256 | |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 257 | // BasicStore does not model arrays and structs. |
| 258 | if (VD->getType()->isArrayType() || VD->getType()->isStructureType()) |
| 259 | return store; |
| 260 | |
| 261 | if (VD->hasGlobalStorage()) { |
| 262 | // Handle variables with global storage: extern, static, PrivateExtern. |
| 263 | |
| 264 | // FIXME:: static variables may have an initializer, but the second time a |
| 265 | // function is called those values may not be current. Currently, a function |
| 266 | // will not be called more than once. |
| 267 | |
| 268 | // Static global variables should not be visited here. |
| 269 | assert(!(VD->getStorageClass() == VarDecl::Static && |
| 270 | VD->isFileVarDecl())); |
| 271 | |
| 272 | // Process static variables. |
| 273 | if (VD->getStorageClass() == VarDecl::Static) { |
| 274 | // C99: 6.7.8 Initialization |
| 275 | // If an object that has static storage duration is not initialized |
| 276 | // explicitly, then: |
| 277 | // —if it has pointer type, it is initialized to a null pointer; |
| 278 | // —if it has arithmetic type, it is initialized to (positive or |
| 279 | // unsigned) zero; |
| 280 | if (!Ex) { |
| 281 | QualType T = VD->getType(); |
| 282 | if (LVal::IsLValType(T)) |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 283 | store = SetRVal(store, StateMgr.getLVal(VD), |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 284 | lval::ConcreteInt(BasicVals.getValue(0, T))); |
| 285 | else if (T->isIntegerType()) |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 286 | store = SetRVal(store, StateMgr.getLVal(VD), |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 287 | nonlval::ConcreteInt(BasicVals.getValue(0, T))); |
| 288 | else { |
| 289 | // assert(0 && "ignore other types of variables"); |
| 290 | } |
| 291 | } else { |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 292 | store = SetRVal(store, StateMgr.getLVal(VD), InitVal); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } else { |
| 296 | // Process local scalar variables. |
| 297 | QualType T = VD->getType(); |
| 298 | if (LVal::IsLValType(T) || T->isIntegerType()) { |
| 299 | RVal V = Ex ? InitVal : UndefinedVal(); |
| 300 | |
| 301 | if (Ex && InitVal.isUnknown()) { |
| 302 | // EXPERIMENTAL: "Conjured" symbols. |
| 303 | SymbolID Sym = SymMgr.getConjuredSymbol(Ex, Count); |
| 304 | |
| 305 | V = LVal::IsLValType(Ex->getType()) |
| 306 | ? cast<RVal>(lval::SymbolVal(Sym)) |
| 307 | : cast<RVal>(nonlval::SymbolVal(Sym)); |
| 308 | } |
| 309 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 310 | store = SetRVal(store, StateMgr.getLVal(VD), V); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | return store; |
| 315 | } |
| 316 | |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 317 | void BasicStoreManager::print(Store store, std::ostream& Out, |
| 318 | const char* nl, const char *sep) { |
| 319 | |
| 320 | VarBindingsTy B = GetVarBindings(store); |
| 321 | Out << "Variables:" << nl; |
| 322 | |
| 323 | bool isFirst = true; |
| 324 | |
| 325 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) { |
| 326 | if (isFirst) isFirst = false; |
| 327 | else Out << nl; |
| 328 | |
| 329 | Out << ' ' << I.getKey()->getName() << " : "; |
| 330 | I.getData().print(Out); |
| 331 | } |
| 332 | } |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 333 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 334 | |
| 335 | void BasicStoreManager::iterBindings(Store store, BindingsHandler& f) { |
| 336 | VarBindingsTy B = GetVarBindings(store); |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 337 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 338 | for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 339 | |
Zhongxing Xu | c1d1bbf | 2008-10-05 12:12:48 +0000 | [diff] [blame^] | 340 | f.HandleBinding(*this, store, StateMgr.getRegion(I.getKey()),I.getData()); |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 344 | StoreManager::BindingsHandler::~BindingsHandler() {} |