blob: 016b070547a15ff8c6a77bdf12ed4b774d9dd0d9 [file] [log] [blame]
Ted Kremenek9153f732008-02-05 07:17:49 +00001//= ValueState.cpp - Path-Sens. "State" for tracking valuues -----*- 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//
Ted Kremenekd70b62e2008-02-08 20:29:23 +000010// This files defines SymbolID, ExprBindKey, and ValueState.
Ted Kremenek9153f732008-02-05 07:17:49 +000011//
12//===----------------------------------------------------------------------===//
13
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +000014#include "ValueState.h"
Ted Kremenek90e14812008-02-14 23:25:54 +000015#include "llvm/ADT/SmallSet.h"
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +000016
17using namespace clang;
18
Ted Kremenek862d5bb2008-02-06 00:54:14 +000019bool ValueState::isNotEqual(SymbolID sym, const llvm::APSInt& V) const {
20 // First, retrieve the NE-set associated with the given symbol.
21 ConstantNotEqTy::TreeTy* T = Data->ConstantNotEq.SlimFind(sym);
22
23 if (!T)
24 return false;
25
26 // Second, see if V is present in the NE-set.
27 return T->getValue().second.contains(&V);
28}
29
30const llvm::APSInt* ValueState::getSymVal(SymbolID sym) const {
31 ConstantEqTy::TreeTy* T = Data->ConstantEq.SlimFind(sym);
32 return T ? T->getValue().second : NULL;
33}
34
Ted Kremenekb87d9092008-02-08 19:17:19 +000035ValueState
36ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc,
37 const LiveVariables& Liveness) {
38
39 // This code essentially performs a "mark-and-sweep" of the VariableBindings.
40 // The roots are any Block-level exprs and Decls that our liveness algorithm
41 // tells us are live. We then see what Decls they may reference, and keep
42 // those around. This code more than likely can be made faster, and the
43 // frequency of which this method is called should be experimented with
44 // for optimum performance.
45
46 llvm::SmallVector<ValueDecl*, 10> WList;
Ted Kremenek90e14812008-02-14 23:25:54 +000047 llvm::SmallPtrSet<ValueDecl*, 10> Marked;
48 llvm::SmallSet<SymbolID, 20> MarkedSymbols;
Ted Kremeneke7d22112008-02-11 19:21:59 +000049
50 ValueStateImpl NewSt = *St;
51
52 // Drop bindings for subexpressions.
53 NewSt.SubExprBindings = EXFactory.GetEmptyMap();
54
55 // Iterate over the block-expr bindings.
56 for (ValueState::beb_iterator I=St.beb_begin(), E=St.beb_end(); I!=E ; ++I) {
Ted Kremenek016f52f2008-02-08 21:10:02 +000057
Ted Kremeneke7d22112008-02-11 19:21:59 +000058 Expr* BlkExpr = I.getKey();
Ted Kremenekb87d9092008-02-08 19:17:19 +000059
Ted Kremeneke7d22112008-02-11 19:21:59 +000060 if (Liveness.isLive(Loc, BlkExpr)) {
Ted Kremenek90e14812008-02-14 23:25:54 +000061 RValue X = I.getData();
62
63 if (isa<lval::DeclVal>(X)) {
64 lval::DeclVal LV = cast<lval::DeclVal>(X);
Ted Kremenek016f52f2008-02-08 21:10:02 +000065 WList.push_back(LV.getDecl());
Ted Kremenekb87d9092008-02-08 19:17:19 +000066 }
Ted Kremenek90e14812008-02-14 23:25:54 +000067
68 for (RValue::symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end();
69 SI != SE; ++SI)
70 MarkedSymbols.insert(*SI);
Ted Kremenekb87d9092008-02-08 19:17:19 +000071 }
Ted Kremenek016f52f2008-02-08 21:10:02 +000072 else
Ted Kremeneke7d22112008-02-11 19:21:59 +000073 NewSt.BlockExprBindings = Remove(NewSt, BlkExpr);
Ted Kremenekb87d9092008-02-08 19:17:19 +000074
Ted Kremenek016f52f2008-02-08 21:10:02 +000075 continue;
Ted Kremenekb87d9092008-02-08 19:17:19 +000076 }
Ted Kremenek016f52f2008-02-08 21:10:02 +000077
Ted Kremeneke7d22112008-02-11 19:21:59 +000078 // Iterate over the variable bindings.
79 for (ValueState::vb_iterator I = St.vb_begin(), E = St.vb_end(); I!=E ; ++I)
Ted Kremenek016f52f2008-02-08 21:10:02 +000080 if (Liveness.isLive(Loc, I.getKey()))
81 WList.push_back(I.getKey());
Ted Kremenek90e14812008-02-14 23:25:54 +000082
Ted Kremenekb87d9092008-02-08 19:17:19 +000083
84 while (!WList.empty()) {
85 ValueDecl* V = WList.back();
86 WList.pop_back();
87
88 if (Marked.count(V))
89 continue;
90
91 Marked.insert(V);
92
93 if (V->getType()->isPointerType()) {
Ted Kremenek50d0ac22008-02-15 22:09:30 +000094 const LValue& LV =
95 cast<LValue>(GetValue(St, lval::DeclVal(cast<VarDecl>(V))));
Ted Kremenek90e14812008-02-14 23:25:54 +000096
97 for (RValue::symbol_iterator SI=LV.symbol_begin(), SE=LV.symbol_end();
98 SI != SE; ++SI)
99 MarkedSymbols.insert(*SI);
Ted Kremenekb87d9092008-02-08 19:17:19 +0000100
101 if (!isa<lval::DeclVal>(LV))
102 continue;
103
104 const lval::DeclVal& LVD = cast<lval::DeclVal>(LV);
105 WList.push_back(LVD.getDecl());
106 }
107 }
108
Ted Kremenek90e14812008-02-14 23:25:54 +0000109 // Remove dead variable bindings.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000110 for (ValueState::vb_iterator I = St.vb_begin(), E = St.vb_end(); I!=E ; ++I)
Ted Kremenek016f52f2008-02-08 21:10:02 +0000111 if (!Marked.count(I.getKey()))
Ted Kremeneke7d22112008-02-11 19:21:59 +0000112 NewSt.VarBindings = Remove(NewSt, I.getKey());
Ted Kremenekb87d9092008-02-08 19:17:19 +0000113
Ted Kremenek90e14812008-02-14 23:25:54 +0000114 // Remove dead symbols.
115 for (ValueState::ce_iterator I = St.ce_begin(), E=St.ce_end(); I!=E; ++I)
116 if (!MarkedSymbols.count(I.getKey()))
117 NewSt.ConstantEq = CEFactory.Remove(NewSt.ConstantEq, I.getKey());
118
119 for (ValueState::cne_iterator I = St.cne_begin(), E=St.cne_end(); I!=E; ++I)
120 if (!MarkedSymbols.count(I.getKey()))
121 NewSt.ConstantNotEq = CNEFactory.Remove(NewSt.ConstantNotEq, I.getKey());
122
Ted Kremeneke7d22112008-02-11 19:21:59 +0000123 return getPersistentState(NewSt);
Ted Kremenekb87d9092008-02-08 19:17:19 +0000124}
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000125
126
Ted Kremeneke7d22112008-02-11 19:21:59 +0000127RValue ValueStateManager::GetValue(ValueState St, const LValue& LV,
Ted Kremenekd131c4f2008-02-07 05:48:01 +0000128 QualType* T) {
Ted Kremenek22031182008-02-08 02:57:34 +0000129 if (isa<UnknownVal>(LV))
130 return UnknownVal();
Ted Kremenek3271f8d2008-02-07 04:16:04 +0000131
Ted Kremenek692416c2008-02-18 22:57:02 +0000132 assert (!isa<UninitializedVal>(LV));
133
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000134 switch (LV.getSubKind()) {
Ted Kremenek329f8542008-02-05 21:52:21 +0000135 case lval::DeclValKind: {
Ted Kremeneke7d22112008-02-11 19:21:59 +0000136 ValueState::VarBindingsTy::TreeTy* T =
Ted Kremenek016f52f2008-02-08 21:10:02 +0000137 // FIXME: We should make lval::DeclVal only contain VarDecl
Ted Kremeneke7d22112008-02-11 19:21:59 +0000138 St->VarBindings.SlimFind(
Ted Kremenek016f52f2008-02-08 21:10:02 +0000139 cast<VarDecl>(cast<lval::DeclVal>(LV).getDecl()));
Ted Kremenek9153f732008-02-05 07:17:49 +0000140
Ted Kremenek22031182008-02-08 02:57:34 +0000141 return T ? T->getValue().second : UnknownVal();
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000142 }
Ted Kremenekd131c4f2008-02-07 05:48:01 +0000143
144 // FIXME: We should bind how far a "ContentsOf" will go...
145
146 case lval::SymbolValKind: {
147 const lval::SymbolVal& SV = cast<lval::SymbolVal>(LV);
148 assert (T);
149
150 if (T->getTypePtr()->isPointerType())
151 return lval::SymbolVal(SymMgr.getContentsOfSymbol(SV.getSymbol()));
152 else
153 return nonlval::SymbolVal(SymMgr.getContentsOfSymbol(SV.getSymbol()));
154 }
155
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000156 default:
157 assert (false && "Invalid LValue.");
158 break;
159 }
160
Ted Kremenek22031182008-02-08 02:57:34 +0000161 return UnknownVal();
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000162}
163
Ted Kremeneke7d22112008-02-11 19:21:59 +0000164ValueState
165ValueStateManager::AddNE(ValueState St, SymbolID sym, const llvm::APSInt& V) {
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000166 // First, retrieve the NE-set associated with the given symbol.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000167 ValueState::ConstantNotEqTy::TreeTy* T = St->ConstantNotEq.SlimFind(sym);
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000168
169 ValueState::IntSetTy S = T ? T->getValue().second : ISetFactory.GetEmptySet();
170
171 // Now add V to the NE set.
172 S = ISetFactory.Add(S, &V);
173
174 // Create a new state with the old binding replaced.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000175 ValueStateImpl NewSt = *St;
176 NewSt.ConstantNotEq = CNEFactory.Add(NewSt.ConstantNotEq,
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000177 sym, S);
178
179 // Get the persistent copy.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000180 return getPersistentState(NewSt);
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000181}
182
Ted Kremeneke7d22112008-02-11 19:21:59 +0000183ValueState
184ValueStateManager::AddEQ(ValueState St, SymbolID sym, const llvm::APSInt& V) {
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000185 // Create a new state with the old binding replaced.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000186 ValueStateImpl NewSt = *St;
187 NewSt.ConstantEq = CEFactory.Add(NewSt.ConstantEq, sym, &V);
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000188
189 // Get the persistent copy.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000190 return getPersistentState(NewSt);
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000191}
192
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000193RValue ValueStateManager::GetValue(ValueState St, Expr* E, bool* hasVal) {
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000194 for (;;) {
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000195 switch (E->getStmtClass()) {
Ted Kremenek2a502572008-02-12 21:37:56 +0000196
197 case Stmt::AddrLabelExprClass:
198 return LValue::GetValue(cast<AddrLabelExpr>(E));
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000199
200 // ParenExprs are no-ops.
201
202 case Stmt::ParenExprClass:
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000203 E = cast<ParenExpr>(E)->getSubExpr();
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000204 continue;
205
206 // DeclRefExprs can either evaluate to an LValue or a Non-LValue
207 // (assuming an implicit "load") depending on the context. In this
208 // context we assume that we are retrieving the value contained
209 // within the referenced variables.
210
Ted Kremenek50d0ac22008-02-15 22:09:30 +0000211 case Stmt::DeclRefExprClass: {
212 ValueDecl* D = cast<DeclRefExpr>(E)->getDecl();
213
214 if (VarDecl* VD = dyn_cast<VarDecl>(D))
215 return GetValue(St, lval::DeclVal(VD));
216 else if (EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) {
217 // FIXME: Do we need to cache a copy of this enum, since it
218 // already has persistent storage? We do this because we
219 // are comparing states using pointer equality. Perhaps there is
220 // a better way, since APInts are fairly lightweight.
221 return nonlval::ConcreteInt(ValMgr.getValue(ED->getInitVal()));
222 }
223
224 assert (false &&
225 "ValueDecl support for this ValueDecl not implemented.");
226
227 return UnknownVal();
228 }
229
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000230
231 // Integer literals evaluate to an RValue. Simply retrieve the
232 // RValue for the literal.
233
234 case Stmt::IntegerLiteralClass:
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000235 return NonLValue::GetValue(ValMgr, cast<IntegerLiteral>(E));
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000236
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000237 case Stmt::CharacterLiteralClass: {
238 CharacterLiteral* C = cast<CharacterLiteral>(E);
239
240 return NonLValue::GetValue(ValMgr, C->getValue(), C->getType(),
241 C->getLoc());
242 }
243
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000244 // Casts where the source and target type are the same
245 // are no-ops. We blast through these to get the descendant
246 // subexpression that has a value.
247
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000248
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000249 case Stmt::ImplicitCastExprClass: {
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000250 ImplicitCastExpr* C = cast<ImplicitCastExpr>(E);
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000251 if (C->getType() == C->getSubExpr()->getType()) {
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000252 E = C->getSubExpr();
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000253 continue;
254 }
255 break;
256 }
257
258 case Stmt::CastExprClass: {
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000259 CastExpr* C = cast<CastExpr>(E);
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000260 if (C->getType() == C->getSubExpr()->getType()) {
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000261 E = C->getSubExpr();
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000262 continue;
263 }
264 break;
265 }
266
267 // Handle all other Stmt* using a lookup.
268
269 default:
270 break;
271 };
272
273 break;
274 }
275
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000276 ValueState::ExprBindingsTy::TreeTy* T = St->SubExprBindings.SlimFind(E);
Ted Kremeneke7d22112008-02-11 19:21:59 +0000277
278 if (T) {
279 if (hasVal) *hasVal = true;
280 return T->getValue().second;
281 }
282
Ted Kremenek5d2986b2008-02-12 18:50:32 +0000283 T = St->BlockExprBindings.SlimFind(E);
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000284
Ted Kremenekf233d482008-02-05 00:26:40 +0000285 if (T) {
286 if (hasVal) *hasVal = true;
287 return T->getValue().second;
288 }
289 else {
290 if (hasVal) *hasVal = false;
Ted Kremenek22031182008-02-08 02:57:34 +0000291 return UnknownVal();
Ted Kremenekf233d482008-02-05 00:26:40 +0000292 }
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000293}
294
Ted Kremeneke7d22112008-02-11 19:21:59 +0000295LValue ValueStateManager::GetLValue(ValueState St, Expr* E) {
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000296
Ted Kremenek016f52f2008-02-08 21:10:02 +0000297 while (ParenExpr* P = dyn_cast<ParenExpr>(E))
298 E = P->getSubExpr();
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000299
Ted Kremenek016f52f2008-02-08 21:10:02 +0000300 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(E))
Ted Kremenek50d0ac22008-02-15 22:09:30 +0000301 return lval::DeclVal(cast<VarDecl>(DR->getDecl()));
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000302
Ted Kremenek016f52f2008-02-08 21:10:02 +0000303 if (UnaryOperator* U = dyn_cast<UnaryOperator>(E))
Ted Kremenek5b6dc2d2008-02-07 01:08:27 +0000304 if (U->getOpcode() == UnaryOperator::Deref)
305 return cast<LValue>(GetValue(St, U->getSubExpr()));
306
Ted Kremenek016f52f2008-02-08 21:10:02 +0000307 return cast<LValue>(GetValue(St, E));
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000308}
309
Ted Kremeneke7d22112008-02-11 19:21:59 +0000310ValueState
311ValueStateManager::SetValue(ValueState St, Expr* E, bool isBlkExpr,
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000312 const RValue& V) {
313
Ted Kremenek016f52f2008-02-08 21:10:02 +0000314 assert (E);
Ted Kremeneke7d22112008-02-11 19:21:59 +0000315
316 if (V.isUnknown())
317 return St;
318
319 ValueStateImpl NewSt = *St;
320
321 if (isBlkExpr)
322 NewSt.BlockExprBindings = EXFactory.Add(NewSt.BlockExprBindings, E, V);
323 else
324 NewSt.SubExprBindings = EXFactory.Add(NewSt.SubExprBindings, E, V);
325
326 return getPersistentState(NewSt);
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000327}
328
Ted Kremeneke7d22112008-02-11 19:21:59 +0000329ValueState
330ValueStateManager::SetValue(ValueState St, const LValue& LV, const RValue& V) {
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000331
Ted Kremenek692416c2008-02-18 22:57:02 +0000332 assert (!isa<UnknownVal>(LV));
333 assert (!isa<UninitializedVal>(LV));
334
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000335 switch (LV.getSubKind()) {
Ted Kremenek329f8542008-02-05 21:52:21 +0000336 case lval::DeclValKind:
Ted Kremenek016f52f2008-02-08 21:10:02 +0000337 return V.isKnown() // FIXME: Have DeclVal only contain VarDecl
Ted Kremeneke7d22112008-02-11 19:21:59 +0000338 ? BindVar(St, cast<VarDecl>(cast<lval::DeclVal>(LV).getDecl()), V)
339 : UnbindVar(St, cast<VarDecl>(cast<lval::DeclVal>(LV).getDecl()));
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000340
341 default:
342 assert ("SetValue for given LValue type not yet implemented.");
343 return St;
344 }
345}
346
Ted Kremeneke7d22112008-02-11 19:21:59 +0000347ValueState
348ValueStateManager::BindVar(ValueState St, VarDecl* D, const RValue& V) {
Ted Kremenek016f52f2008-02-08 21:10:02 +0000349
Ted Kremenek9153f732008-02-05 07:17:49 +0000350 // Create a new state with the old binding removed.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000351 ValueStateImpl NewSt = *St;
352 NewSt.VarBindings = VBFactory.Add(NewSt.VarBindings, D, V);
Ted Kremenek016f52f2008-02-08 21:10:02 +0000353
Ted Kremenek9153f732008-02-05 07:17:49 +0000354 // Get the persistent copy.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000355 return getPersistentState(NewSt);
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000356}
Ted Kremenek9153f732008-02-05 07:17:49 +0000357
Ted Kremeneke7d22112008-02-11 19:21:59 +0000358ValueState
359ValueStateManager::UnbindVar(ValueState St, VarDecl* D) {
Ted Kremenekf66ea2cd2008-02-04 21:59:22 +0000360
Ted Kremenek9153f732008-02-05 07:17:49 +0000361 // Create a new state with the old binding removed.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000362 ValueStateImpl NewSt = *St;
363 NewSt.VarBindings = VBFactory.Remove(NewSt.VarBindings, D);
Ted Kremenek9153f732008-02-05 07:17:49 +0000364
365 // Get the persistent copy.
Ted Kremeneke7d22112008-02-11 19:21:59 +0000366 return getPersistentState(NewSt);
Ted Kremenek9153f732008-02-05 07:17:49 +0000367}
368
Ted Kremeneke7d22112008-02-11 19:21:59 +0000369ValueState
Ted Kremenek9153f732008-02-05 07:17:49 +0000370ValueStateManager::getInitialState() {
371
372 // Create a state with empty variable bindings.
Ted Kremenek016f52f2008-02-08 21:10:02 +0000373 ValueStateImpl StateImpl(EXFactory.GetEmptyMap(),
374 VBFactory.GetEmptyMap(),
Ted Kremenek862d5bb2008-02-06 00:54:14 +0000375 CNEFactory.GetEmptyMap(),
376 CEFactory.GetEmptyMap());
Ted Kremenek9153f732008-02-05 07:17:49 +0000377
378 return getPersistentState(StateImpl);
379}
380
Ted Kremeneke7d22112008-02-11 19:21:59 +0000381ValueState
Ted Kremenek9153f732008-02-05 07:17:49 +0000382ValueStateManager::getPersistentState(const ValueStateImpl &State) {
383
384 llvm::FoldingSetNodeID ID;
385 State.Profile(ID);
Ted Kremeneke7d22112008-02-11 19:21:59 +0000386 void* InsertPos;
Ted Kremenek9153f732008-02-05 07:17:49 +0000387
388 if (ValueStateImpl* I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
389 return I;
390
Ted Kremenek41652a92008-02-06 02:45:20 +0000391 ValueStateImpl* I = (ValueStateImpl*) Alloc.Allocate<ValueStateImpl>();
Ted Kremenek9153f732008-02-05 07:17:49 +0000392 new (I) ValueStateImpl(State);
393 StateSet.InsertNode(I, InsertPos);
394 return I;
395}
Ted Kremeneke7d22112008-02-11 19:21:59 +0000396
397void ValueState::printDOT(std::ostream& Out) const {
398 // Print Variable Bindings
399 Out << "Variables:\\l";
400
401 bool isFirst = true;
402
403 for (vb_iterator I=vb_begin(), E=vb_end(); I!=E; ++I) {
404
405 if (isFirst)
406 isFirst = false;
407 else
408 Out << "\\l";
409
410 Out << ' ' << I.getKey()->getName() << " : ";
411 I.getData().print(Out);
412 }
413
414 // Print Subexpression bindings.
415
416 isFirst = true;
417
418 for (seb_iterator I=seb_begin(), E=seb_end(); I != E;++I) {
419
420 if (isFirst) {
421 Out << "\\l\\lSub-Expressions:\\l";
422 isFirst = false;
423 }
424 else
425 Out << "\\l";
426
427 Out << " (" << (void*) I.getKey() << ") ";
428 I.getKey()->printPretty(Out);
429 Out << " : ";
430 I.getData().print(Out);
431 }
432
433 // Print block-expression bindings.
434
435 isFirst = true;
436
437 for (beb_iterator I=beb_begin(), E=beb_end(); I != E; ++I) {
438
439 if (isFirst) {
440 Out << "\\l\\lBlock-level Expressions:\\l";
441 isFirst = false;
442 }
443 else
444 Out << "\\l";
445
446 Out << " (" << (void*) I.getKey() << ") ";
447 I.getKey()->printPretty(Out);
448 Out << " : ";
449 I.getData().print(Out);
450 }
451
452 // Print equality constraints.
453
454 if (!Data->ConstantEq.isEmpty()) {
455
456 Out << "\\l\\|'==' constraints:";
457
458 for (ConstantEqTy::iterator I=Data->ConstantEq.begin(),
459 E=Data->ConstantEq.end(); I!=E;++I)
460 Out << "\\l $" << I.getKey() << " : " << I.getData()->toString();
461 }
462
463
464 // Print != constraints.
465
466 if (!Data->ConstantNotEq.isEmpty()) {
467
468 Out << "\\l\\|'!=' constraints:";
469
470 for (ConstantNotEqTy::iterator I=Data->ConstantNotEq.begin(),
471 EI=Data->ConstantNotEq.end(); I != EI; ++I) {
472
473 Out << "\\l $" << I.getKey() << " : ";
474 isFirst = true;
475
476 IntSetTy::iterator J=I.getData().begin(), EJ=I.getData().end();
477
478 for ( ; J != EJ; ++J) {
479 if (isFirst) isFirst = false;
480 else Out << ", ";
481
482 Out << (*J)->toString();
483 }
484 }
485 }
486}