blob: 8fc438d6a5c5bc39a0cf6547e222fb64001391c1 [file] [log] [blame]
Ted Kremenek4323a572008-07-10 22:03:41 +00001//== 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 Kremenek5f81c442008-08-28 23:31:31 +000014#include "clang/Analysis/Analyses/LiveVariables.h"
Ted Kremenekcaa37242008-08-19 16:51:45 +000015#include "clang/Analysis/PathSensitive/GRState.h"
Ted Kremenek4323a572008-07-10 22:03:41 +000016#include "llvm/ADT/ImmutableMap.h"
17#include "llvm/Support/Compiler.h"
Ted Kremeneka622d8c2008-08-19 22:24:03 +000018#include "llvm/Support/Streams.h"
Ted Kremenek4323a572008-07-10 22:03:41 +000019
20using namespace clang;
21
Zhongxing Xu1c96b242008-10-17 05:57:07 +000022typedef llvm::ImmutableMap<const VarDecl*,SVal> VarBindingsTy;
Ted Kremenek60dbad82008-09-03 03:06:11 +000023
Ted Kremenek4323a572008-07-10 22:03:41 +000024namespace {
25
26class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager {
Ted Kremenek4323a572008-07-10 22:03:41 +000027 VarBindingsTy::Factory VBFactory;
Zhongxing Xuc1d1bbf2008-10-05 12:12:48 +000028 GRStateManager& StateMgr;
Zhongxing Xubc678fd2008-10-07 01:31:04 +000029 MemRegionManager MRMgr;
Ted Kremenek4323a572008-07-10 22:03:41 +000030
31public:
Zhongxing Xubc678fd2008-10-07 01:31:04 +000032 BasicStoreManager(GRStateManager& mgr)
33 : StateMgr(mgr), MRMgr(StateMgr.getAllocator()) {}
Ted Kremenekd0c4b282008-08-25 19:33:03 +000034
Ted Kremenek4323a572008-07-10 22:03:41 +000035 virtual ~BasicStoreManager() {}
36
Zhongxing Xu1c96b242008-10-17 05:57:07 +000037 virtual SVal GetSVal(Store St, Loc LV, QualType T);
38 virtual Store SetSVal(Store St, Loc LV, SVal V);
39 virtual Store Remove(Store St, Loc LV);
Ted Kremenek4323a572008-07-10 22:03:41 +000040
Zhongxing Xuc1d1bbf2008-10-05 12:12:48 +000041 virtual Store getInitialStore();
Zhongxing Xubc678fd2008-10-07 01:31:04 +000042
43 virtual MemRegionManager& getRegionManager() { return MRMgr; }
44
Zhongxing Xu6d69b5d2008-10-16 06:09:51 +000045 // FIXME: Investigate what is using this. This method should be removed.
Zhongxing Xu1c96b242008-10-17 05:57:07 +000046 virtual Loc getLoc(const VarDecl* VD) {
47 return loc::MemRegionVal(MRMgr.getVarRegion(VD));
Zhongxing Xubc678fd2008-10-07 01:31:04 +000048 }
Ted Kremenekd9bc33e2008-10-17 00:51:01 +000049
Zhongxing Xu1c96b242008-10-17 05:57:07 +000050 SVal getLValueVar(const GRState* St, const VarDecl* VD);
51 SVal getLValueIvar(const GRState* St, const ObjCIvarDecl* D, SVal Base);
52 SVal getLValueField(const GRState* St, const FieldDecl* D, SVal Base);
53 SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
Ted Kremenekf59bf482008-07-17 18:38:48 +000054
Ted Kremenek9e240492008-10-04 05:50:14 +000055 virtual Store
56 RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
57 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
58 LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols);
Zhongxing Xubbe8ff42008-08-21 22:34:01 +000059
Ted Kremenek60dbad82008-09-03 03:06:11 +000060 virtual void iterBindings(Store store, BindingsHandler& f);
61
Zhongxing Xuc1d1bbf2008-10-05 12:12:48 +000062 virtual Store AddDecl(Store store,
Ted Kremeneke53c0692008-08-23 00:50:55 +000063 const VarDecl* VD, Expr* Ex,
Zhongxing Xu1c96b242008-10-17 05:57:07 +000064 SVal InitVal = UndefinedVal(), unsigned Count = 0);
Zhongxing Xubbe8ff42008-08-21 22:34:01 +000065
Ted Kremenekf59bf482008-07-17 18:38:48 +000066 static inline VarBindingsTy GetVarBindings(Store store) {
67 return VarBindingsTy(static_cast<const VarBindingsTy::TreeTy*>(store));
Ted Kremeneka622d8c2008-08-19 22:24:03 +000068 }
69
70 virtual void print(Store store, std::ostream& Out,
71 const char* nl, const char *sep);
Zhongxing Xubc678fd2008-10-07 01:31:04 +000072
Ted Kremenek60dbad82008-09-03 03:06:11 +000073};
Ted Kremenek9e240492008-10-04 05:50:14 +000074
Ted Kremenek4323a572008-07-10 22:03:41 +000075} // end anonymous namespace
76
77
Ted Kremenek5f81c442008-08-28 23:31:31 +000078StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) {
79 return new BasicStoreManager(StMgr);
Ted Kremenekd0c4b282008-08-25 19:33:03 +000080}
Zhongxing Xu1c96b242008-10-17 05:57:07 +000081SVal BasicStoreManager::getLValueVar(const GRState* St, const VarDecl* VD) {
82 return loc::MemRegionVal(MRMgr.getVarRegion(VD));
Ted Kremenekd9bc33e2008-10-17 00:51:01 +000083}
84
Zhongxing Xu1c96b242008-10-17 05:57:07 +000085SVal BasicStoreManager::getLValueIvar(const GRState* St, const ObjCIvarDecl* D,
86 SVal Base) {
Ted Kremenekd9bc33e2008-10-17 00:51:01 +000087 return UnknownVal();
88}
89
90
Zhongxing Xu1c96b242008-10-17 05:57:07 +000091SVal BasicStoreManager::getLValueField(const GRState* St, const FieldDecl* D,
92 SVal Base) {
Ted Kremenek993f1c72008-10-17 20:28:54 +000093
94 if (Base.isUnknownOrUndef())
95 return Base;
96
97 Loc BaseL = cast<Loc>(Base);
98 const MemRegion* BaseR = 0;
99
100 switch(BaseL.getSubKind()) {
101 case loc::SymbolValKind:
102 BaseR = MRMgr.getSymbolicRegion(cast<loc::SymbolVal>(&BaseL)->getSymbol());
103 break;
104
105 case loc::GotoLabelKind:
106 case loc::FuncValKind:
107 // Technically we can get here if people do funny things with casts.
108 return UndefinedVal();
109
110 case loc::MemRegionKind:
111 BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
112 break;
113
114 case loc::ConcreteIntKind:
115 case loc::StringLiteralValKind:
116 // While these seem funny, this can happen through casts.
117 // FIXME: What we should return is the field offset. For example,
118 // add the field offset to the integer value. That way funny things
119 // like this work properly: &(((struct foo *) 0xa)->f)
120 return Base;
121
122 default:
123 assert ("Unhandled Base.");
124 return Base;
125 }
126
127 return loc::MemRegionVal(MRMgr.getFieldRegion(D, BaseR));
Ted Kremenekd9bc33e2008-10-17 00:51:01 +0000128}
Ted Kremenekd0c4b282008-08-25 19:33:03 +0000129
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000130SVal BasicStoreManager::getLValueElement(const GRState* St, SVal Base,
131 SVal Offset) {
Ted Kremenek134e7492008-10-17 22:52:40 +0000132 // Total hack: Just return "Base" for now.
133 return Base;
Zhongxing Xu6d69b5d2008-10-16 06:09:51 +0000134}
135
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000136SVal BasicStoreManager::GetSVal(Store St, Loc LV, QualType T) {
Ted Kremenek4323a572008-07-10 22:03:41 +0000137
138 if (isa<UnknownVal>(LV))
139 return UnknownVal();
140
141 assert (!isa<UndefinedVal>(LV));
142
143 switch (LV.getSubKind()) {
144
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000145 case loc::MemRegionKind: {
Ted Kremenek993f1c72008-10-17 20:28:54 +0000146 const VarRegion* R =
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000147 dyn_cast<VarRegion>(cast<loc::MemRegionVal>(LV).getRegion());
Ted Kremenek9e240492008-10-04 05:50:14 +0000148
149 if (!R)
150 return UnknownVal();
151
Ted Kremenek4323a572008-07-10 22:03:41 +0000152 VarBindingsTy B(static_cast<const VarBindingsTy::TreeTy*>(St));
Ted Kremenek9e240492008-10-04 05:50:14 +0000153 VarBindingsTy::data_type* T = B.lookup(R->getDecl());
Ted Kremenek4323a572008-07-10 22:03:41 +0000154 return T ? *T : UnknownVal();
155 }
156
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000157 case loc::SymbolValKind:
Ted Kremenek4323a572008-07-10 22:03:41 +0000158 return UnknownVal();
Ted Kremenek4323a572008-07-10 22:03:41 +0000159
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000160 case loc::ConcreteIntKind:
161 // Some clients may call GetSVal with such an option simply because
162 // they are doing a quick scan through their Locs (potentially to
Ted Kremenek4323a572008-07-10 22:03:41 +0000163 // invalidate their bindings). Just return Undefined.
Ted Kremenekd9bc33e2008-10-17 00:51:01 +0000164 return UndefinedVal();
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000165 case loc::FuncValKind:
Ted Kremenek4323a572008-07-10 22:03:41 +0000166 return LV;
167
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000168 case loc::StringLiteralValKind:
Ted Kremenek4323a572008-07-10 22:03:41 +0000169 // FIXME: Implement better support for fetching characters from strings.
170 return UnknownVal();
171
172 default:
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000173 assert (false && "Invalid Loc.");
Ted Kremenek4323a572008-07-10 22:03:41 +0000174 break;
175 }
176
177 return UnknownVal();
178}
Ted Kremenek97ed4f62008-10-17 00:03:18 +0000179
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000180Store BasicStoreManager::SetSVal(Store store, Loc LV, SVal V) {
Ted Kremenekf59bf482008-07-17 18:38:48 +0000181 switch (LV.getSubKind()) {
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000182 case loc::MemRegionKind: {
Ted Kremenek993f1c72008-10-17 20:28:54 +0000183 const VarRegion* R =
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000184 dyn_cast<VarRegion>(cast<loc::MemRegionVal>(LV).getRegion());
Ted Kremenek9e240492008-10-04 05:50:14 +0000185
186 if (!R)
187 return store;
188
Ted Kremenekf59bf482008-07-17 18:38:48 +0000189 VarBindingsTy B = GetVarBindings(store);
Ted Kremenek4323a572008-07-10 22:03:41 +0000190 return V.isUnknown()
Ted Kremenek9e240492008-10-04 05:50:14 +0000191 ? VBFactory.Remove(B, R->getDecl()).getRoot()
192 : VBFactory.Add(B, R->getDecl(), V).getRoot();
Ted Kremenekf59bf482008-07-17 18:38:48 +0000193 }
Ted Kremenek4323a572008-07-10 22:03:41 +0000194 default:
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000195 assert ("SetSVal for given Loc type not yet implemented.");
Ted Kremenekf59bf482008-07-17 18:38:48 +0000196 return store;
Ted Kremenek4323a572008-07-10 22:03:41 +0000197 }
198}
199
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000200Store BasicStoreManager::Remove(Store store, Loc LV) {
Ted Kremenek4323a572008-07-10 22:03:41 +0000201 switch (LV.getSubKind()) {
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000202 case loc::MemRegionKind: {
Ted Kremenek993f1c72008-10-17 20:28:54 +0000203 const VarRegion* R =
204 dyn_cast<VarRegion>(cast<loc::MemRegionVal>(LV).getRegion());
Ted Kremenek9e240492008-10-04 05:50:14 +0000205
206 if (!R)
207 return store;
208
Ted Kremenekf59bf482008-07-17 18:38:48 +0000209 VarBindingsTy B = GetVarBindings(store);
Ted Kremenek9e240492008-10-04 05:50:14 +0000210 return VBFactory.Remove(B,R->getDecl()).getRoot();
Ted Kremenekf59bf482008-07-17 18:38:48 +0000211 }
Ted Kremenek4323a572008-07-10 22:03:41 +0000212 default:
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000213 assert ("Remove for given Loc type not yet implemented.");
Ted Kremenekf59bf482008-07-17 18:38:48 +0000214 return store;
Ted Kremenek4323a572008-07-10 22:03:41 +0000215 }
216}
Ted Kremenekf59bf482008-07-17 18:38:48 +0000217
Ted Kremenek9e240492008-10-04 05:50:14 +0000218Store
219BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc,
220 const LiveVariables& Liveness,
221 llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
222 LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols) {
Ted Kremenekf59bf482008-07-17 18:38:48 +0000223
224 VarBindingsTy B = GetVarBindings(store);
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000225 typedef SVal::symbol_iterator symbol_iterator;
Ted Kremenekf59bf482008-07-17 18:38:48 +0000226
227 // Iterate over the variable bindings.
228 for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I)
229 if (Liveness.isLive(Loc, I.getKey())) {
Zhongxing Xubc678fd2008-10-07 01:31:04 +0000230 RegionRoots.push_back(MRMgr.getVarRegion(I.getKey()));
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000231 SVal X = I.getData();
Ted Kremenekf59bf482008-07-17 18:38:48 +0000232
233 for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
234 LSymbols.insert(*SI);
235 }
236
237 // Scan for live variables and live symbols.
Ted Kremenek9e240492008-10-04 05:50:14 +0000238 llvm::SmallPtrSet<const VarRegion*, 10> Marked;
Ted Kremenekf59bf482008-07-17 18:38:48 +0000239
Ted Kremenek9e240492008-10-04 05:50:14 +0000240 while (!RegionRoots.empty()) {
Ted Kremenek134e7492008-10-17 22:52:40 +0000241 const MemRegion* MR = RegionRoots.back();
Ted Kremenek9e240492008-10-04 05:50:14 +0000242 RegionRoots.pop_back();
Ted Kremenekf59bf482008-07-17 18:38:48 +0000243
Ted Kremenek134e7492008-10-17 22:52:40 +0000244 while (MR) {
245 if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(MR)) {
246 LSymbols.insert(SymR->getSymbol());
247 break;
248 }
249 else if (const VarRegion* R = dyn_cast<VarRegion>(MR)) {
250 if (Marked.count(R))
251 break;
252
253 Marked.insert(R);
254 SVal X = GetRegionSVal(store, R);
Ted Kremenekf59bf482008-07-17 18:38:48 +0000255
Ted Kremenek134e7492008-10-17 22:52:40 +0000256 // FIXME: We need to handle symbols nested in region definitions.
257 for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
258 LSymbols.insert(*SI);
Ted Kremenekf59bf482008-07-17 18:38:48 +0000259
Ted Kremenek134e7492008-10-17 22:52:40 +0000260 if (!isa<loc::MemRegionVal>(X))
261 break;
Ted Kremenekf59bf482008-07-17 18:38:48 +0000262
Ted Kremenek134e7492008-10-17 22:52:40 +0000263 const loc::MemRegionVal& LVD = cast<loc::MemRegionVal>(X);
264 RegionRoots.push_back(LVD.getRegion());
265 break;
266 }
267 else if (const SubRegion* R = dyn_cast<SubRegion>(MR))
268 MR = R->getSuperRegion();
269 else
270 break;
271 }
Ted Kremenekf59bf482008-07-17 18:38:48 +0000272 }
273
274 // Remove dead variable bindings.
Ted Kremenek9e240492008-10-04 05:50:14 +0000275 for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) {
Zhongxing Xubc678fd2008-10-07 01:31:04 +0000276 const VarRegion* R = cast<VarRegion>(MRMgr.getVarRegion(I.getKey()));
Ted Kremenek9e240492008-10-04 05:50:14 +0000277
278 if (!Marked.count(R)) {
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000279 store = Remove(store, loc::MemRegionVal(R));
280 SVal X = I.getData();
Ted Kremenekf59bf482008-07-17 18:38:48 +0000281
282 for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
283 if (!LSymbols.count(*SI)) DSymbols.insert(*SI);
284 }
Ted Kremenek9e240492008-10-04 05:50:14 +0000285 }
286
Ted Kremenekf59bf482008-07-17 18:38:48 +0000287 return store;
288}
Ted Kremenekcaa37242008-08-19 16:51:45 +0000289
Zhongxing Xuc1d1bbf2008-10-05 12:12:48 +0000290Store BasicStoreManager::getInitialStore() {
Ted Kremenekcaa37242008-08-19 16:51:45 +0000291 // The LiveVariables information already has a compilation of all VarDecls
292 // used in the function. Iterate through this set, and "symbolicate"
293 // any VarDecl whose value originally comes from outside the function.
294
295 typedef LiveVariables::AnalysisDataTy LVDataTy;
296 LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData();
297
298 Store St = VBFactory.GetEmptyMap().getRoot();
299
300 for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
301 ScopedDecl* SD = const_cast<ScopedDecl*>(I->first);
302
303 if (VarDecl* VD = dyn_cast<VarDecl>(SD)) {
304 // Punt on static variables for now.
305 if (VD->getStorageClass() == VarDecl::Static)
306 continue;
307
308 // Only handle pointers and integers for now.
309 QualType T = VD->getType();
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000310 if (Loc::IsLocType(T) || T->isIntegerType()) {
Ted Kremenekcaa37242008-08-19 16:51:45 +0000311 // Initialize globals and parameters to symbolic values.
312 // Initialize local variables to undefined.
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000313 SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
Ted Kremenekcaa37242008-08-19 16:51:45 +0000314 isa<ImplicitParamDecl>(VD))
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000315 ? SVal::GetSymbolValue(StateMgr.getSymbolManager(), VD)
Ted Kremenekcaa37242008-08-19 16:51:45 +0000316 : UndefinedVal();
317
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000318 St = SetSVal(St, loc::MemRegionVal(MRMgr.getVarRegion(VD)), X);
Ted Kremenekcaa37242008-08-19 16:51:45 +0000319 }
320 }
321 }
322 return St;
323}
Ted Kremeneka622d8c2008-08-19 22:24:03 +0000324
Zhongxing Xuc1d1bbf2008-10-05 12:12:48 +0000325Store BasicStoreManager::AddDecl(Store store,
Ted Kremeneke53c0692008-08-23 00:50:55 +0000326 const VarDecl* VD, Expr* Ex,
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000327 SVal InitVal, unsigned Count) {
Ted Kremeneke53c0692008-08-23 00:50:55 +0000328
329 BasicValueFactory& BasicVals = StateMgr.getBasicVals();
330 SymbolManager& SymMgr = StateMgr.getSymbolManager();
331
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000332 // BasicStore does not model arrays and structs.
333 if (VD->getType()->isArrayType() || VD->getType()->isStructureType())
334 return store;
335
336 if (VD->hasGlobalStorage()) {
337 // Handle variables with global storage: extern, static, PrivateExtern.
338
339 // FIXME:: static variables may have an initializer, but the second time a
340 // function is called those values may not be current. Currently, a function
341 // will not be called more than once.
342
343 // Static global variables should not be visited here.
344 assert(!(VD->getStorageClass() == VarDecl::Static &&
345 VD->isFileVarDecl()));
346
347 // Process static variables.
348 if (VD->getStorageClass() == VarDecl::Static) {
349 // C99: 6.7.8 Initialization
350 // If an object that has static storage duration is not initialized
351 // explicitly, then:
352 // —if it has pointer type, it is initialized to a null pointer;
353 // —if it has arithmetic type, it is initialized to (positive or
354 // unsigned) zero;
355 if (!Ex) {
356 QualType T = VD->getType();
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000357 if (Loc::IsLocType(T))
358 store = SetSVal(store, getLoc(VD),
359 loc::ConcreteInt(BasicVals.getValue(0, T)));
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000360 else if (T->isIntegerType())
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000361 store = SetSVal(store, getLoc(VD),
362 nonloc::ConcreteInt(BasicVals.getValue(0, T)));
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000363 else {
364 // assert(0 && "ignore other types of variables");
365 }
366 } else {
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000367 store = SetSVal(store, getLoc(VD), InitVal);
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000368 }
369 }
370 } else {
371 // Process local scalar variables.
372 QualType T = VD->getType();
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000373 if (Loc::IsLocType(T) || T->isIntegerType()) {
374 SVal V = Ex ? InitVal : UndefinedVal();
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000375
376 if (Ex && InitVal.isUnknown()) {
377 // EXPERIMENTAL: "Conjured" symbols.
378 SymbolID Sym = SymMgr.getConjuredSymbol(Ex, Count);
379
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000380 V = Loc::IsLocType(Ex->getType())
381 ? cast<SVal>(loc::SymbolVal(Sym))
382 : cast<SVal>(nonloc::SymbolVal(Sym));
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000383 }
384
Zhongxing Xu1c96b242008-10-17 05:57:07 +0000385 store = SetSVal(store, getLoc(VD), V);
Zhongxing Xubbe8ff42008-08-21 22:34:01 +0000386 }
387 }
388
389 return store;
390}
391
Ted Kremeneka622d8c2008-08-19 22:24:03 +0000392void BasicStoreManager::print(Store store, std::ostream& Out,
393 const char* nl, const char *sep) {
394
395 VarBindingsTy B = GetVarBindings(store);
396 Out << "Variables:" << nl;
397
398 bool isFirst = true;
399
400 for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) {
401 if (isFirst) isFirst = false;
402 else Out << nl;
403
404 Out << ' ' << I.getKey()->getName() << " : ";
405 I.getData().print(Out);
406 }
407}
Ted Kremenek2bc39c62008-08-29 00:47:32 +0000408
Ted Kremenek60dbad82008-09-03 03:06:11 +0000409
410void BasicStoreManager::iterBindings(Store store, BindingsHandler& f) {
411 VarBindingsTy B = GetVarBindings(store);
Ted Kremenek2bc39c62008-08-29 00:47:32 +0000412
Ted Kremenek60dbad82008-09-03 03:06:11 +0000413 for (VarBindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) {
Ted Kremenek9e240492008-10-04 05:50:14 +0000414
Zhongxing Xubc678fd2008-10-07 01:31:04 +0000415 f.HandleBinding(*this, store, MRMgr.getVarRegion(I.getKey()),I.getData());
Ted Kremenek2bc39c62008-08-29 00:47:32 +0000416 }
417}
418
Ted Kremenek60dbad82008-09-03 03:06:11 +0000419StoreManager::BindingsHandler::~BindingsHandler() {}