blob: a4b464949aaf47e46148c8182ecf23f6ae1f869a [file] [log] [blame]
Ted Kremeneka90ccfe2008-01-31 19:34:24 +00001//= RValues.cpp - Abstract RValues for Path-Sens. Value Tracking -*- 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//
Gabor Greif843e9342008-03-06 10:40:09 +000010// This file defines RVal, LVal, and NonLVal, classes that represent
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000011// abstract r-values for use with path-sensitive value tracking.
12//
13//===----------------------------------------------------------------------===//
14
Ted Kremenekcc409b72008-02-14 17:30:51 +000015#include "clang/Analysis/PathSensitive/RValues.h"
Ted Kremenekd70d0b02008-02-16 01:12:31 +000016#include "llvm/Support/Streams.h"
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000017
18using namespace clang;
19using llvm::dyn_cast;
20using llvm::cast;
21using llvm::APSInt;
22
23//===----------------------------------------------------------------------===//
Ted Kremenek90e14812008-02-14 23:25:54 +000024// Symbol Iteration.
25//===----------------------------------------------------------------------===//
Ted Kremeneka6e4d212008-02-01 06:36:40 +000026
Ted Kremenekaa1c4e52008-02-21 18:02:17 +000027RVal::symbol_iterator RVal::symbol_begin() const {
28 if (isa<lval::SymbolVal>(this))
29 return (symbol_iterator) (&Data);
30 else if (isa<nonlval::SymbolVal>(this))
31 return (symbol_iterator) (&Data);
32 else if (isa<nonlval::SymIntConstraintVal>(this)) {
33 const SymIntConstraint& C =
34 cast<nonlval::SymIntConstraintVal>(this)->getConstraint();
35
36 return (symbol_iterator) &C.getSymbol();
Ted Kremenek90e14812008-02-14 23:25:54 +000037 }
38
39 return NULL;
40}
41
Ted Kremenekaa1c4e52008-02-21 18:02:17 +000042RVal::symbol_iterator RVal::symbol_end() const {
Ted Kremenek90e14812008-02-14 23:25:54 +000043 symbol_iterator X = symbol_begin();
44 return X ? X+1 : NULL;
45}
Ted Kremeneka6e4d212008-02-01 06:36:40 +000046
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000047//===----------------------------------------------------------------------===//
Ted Kremenekaa1c4e52008-02-21 18:02:17 +000048// Transfer function dispatch for Non-LVals.
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000049//===----------------------------------------------------------------------===//
Ted Kremeneka6e4d212008-02-01 06:36:40 +000050
Ted Kremenek8cc13ea2008-02-28 20:32:03 +000051RVal
Ted Kremenek240f1f02008-03-07 20:13:31 +000052nonlval::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals, BinaryOperator::Opcode Op,
Ted Kremenekaa1c4e52008-02-21 18:02:17 +000053 const nonlval::ConcreteInt& R) const {
54
Ted Kremenek240f1f02008-03-07 20:13:31 +000055 const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
Ted Kremenek8cc13ea2008-02-28 20:32:03 +000056
57 if (X)
58 return nonlval::ConcreteInt(*X);
59 else
60 return UndefinedVal();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000061}
62
63
64 // Bitwise-Complement.
65
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000066nonlval::ConcreteInt
Ted Kremenek240f1f02008-03-07 20:13:31 +000067nonlval::ConcreteInt::EvalComplement(BasicValueFactory& BasicVals) const {
68 return BasicVals.getValue(~getValue());
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000069}
70
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000071 // Unary Minus.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000072
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000073nonlval::ConcreteInt
Ted Kremenek240f1f02008-03-07 20:13:31 +000074nonlval::ConcreteInt::EvalMinus(BasicValueFactory& BasicVals, UnaryOperator* U) const {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000075 assert (U->getType() == U->getSubExpr()->getType());
76 assert (U->getType()->isIntegerType());
Ted Kremenek240f1f02008-03-07 20:13:31 +000077 return BasicVals.getValue(-getValue());
Ted Kremenekc5d3b4c2008-02-04 16:58:30 +000078}
79
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000080//===----------------------------------------------------------------------===//
Ted Kremenekaa1c4e52008-02-21 18:02:17 +000081// Transfer function dispatch for LVals.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000082//===----------------------------------------------------------------------===//
83
Ted Kremenek8cc13ea2008-02-28 20:32:03 +000084RVal
Ted Kremenek240f1f02008-03-07 20:13:31 +000085lval::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals, BinaryOperator::Opcode Op,
Ted Kremenekaa1c4e52008-02-21 18:02:17 +000086 const lval::ConcreteInt& R) const {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000087
88 assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub ||
89 (Op >= BinaryOperator::LT && Op <= BinaryOperator::NE));
90
Ted Kremenek240f1f02008-03-07 20:13:31 +000091 const llvm::APSInt* X = BasicVals.EvaluateAPSInt(Op, getValue(), R.getValue());
Ted Kremenek8cc13ea2008-02-28 20:32:03 +000092
93 if (X)
94 return lval::ConcreteInt(*X);
95 else
96 return UndefinedVal();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +000097}
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000098
Ted Kremenek240f1f02008-03-07 20:13:31 +000099NonLVal LVal::EQ(BasicValueFactory& BasicVals, const LVal& R) const {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000100
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000101 switch (getSubKind()) {
102 default:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000103 assert(false && "EQ not implemented for this LVal.");
104 break;
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000105
Ted Kremenek0806acf2008-02-05 23:08:41 +0000106 case lval::ConcreteIntKind:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000107 if (isa<lval::ConcreteInt>(R)) {
Ted Kremenek0806acf2008-02-05 23:08:41 +0000108 bool b = cast<lval::ConcreteInt>(this)->getValue() ==
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000109 cast<lval::ConcreteInt>(R).getValue();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000110
Ted Kremenek240f1f02008-03-07 20:13:31 +0000111 return NonLVal::MakeIntTruthVal(BasicVals, b);
Ted Kremenek0806acf2008-02-05 23:08:41 +0000112 }
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000113 else if (isa<lval::SymbolVal>(R)) {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000114
Ted Kremenek0806acf2008-02-05 23:08:41 +0000115 const SymIntConstraint& C =
Ted Kremenek240f1f02008-03-07 20:13:31 +0000116 BasicVals.getConstraint(cast<lval::SymbolVal>(R).getSymbol(),
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000117 BinaryOperator::EQ,
118 cast<lval::ConcreteInt>(this)->getValue());
Ted Kremenek0806acf2008-02-05 23:08:41 +0000119
120 return nonlval::SymIntConstraintVal(C);
121 }
122
123 break;
124
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000125 case lval::SymbolValKind: {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000126 if (isa<lval::ConcreteInt>(R)) {
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000127
128 const SymIntConstraint& C =
Ted Kremenek240f1f02008-03-07 20:13:31 +0000129 BasicVals.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000130 BinaryOperator::EQ,
131 cast<lval::ConcreteInt>(R).getValue());
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000132
133 return nonlval::SymIntConstraintVal(C);
134 }
Ted Kremenek0806acf2008-02-05 23:08:41 +0000135
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000136 assert (!isa<lval::SymbolVal>(R) && "FIXME: Implement unification.");
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000137
138 break;
Ted Kremenek0806acf2008-02-05 23:08:41 +0000139 }
Ted Kremenek0806acf2008-02-05 23:08:41 +0000140
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000141 case lval::DeclValKind:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000142 if (isa<lval::DeclVal>(R)) {
143 bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(R);
Ted Kremenek240f1f02008-03-07 20:13:31 +0000144 return NonLVal::MakeIntTruthVal(BasicVals, b);
Ted Kremenek0806acf2008-02-05 23:08:41 +0000145 }
146
147 break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000148 }
Ted Kremenek0806acf2008-02-05 23:08:41 +0000149
Ted Kremenek240f1f02008-03-07 20:13:31 +0000150 return NonLVal::MakeIntTruthVal(BasicVals, false);
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000151}
152
Ted Kremenek240f1f02008-03-07 20:13:31 +0000153NonLVal LVal::NE(BasicValueFactory& BasicVals, const LVal& R) const {
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000154 switch (getSubKind()) {
155 default:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000156 assert(false && "NE not implemented for this LVal.");
157 break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000158
Ted Kremenek0806acf2008-02-05 23:08:41 +0000159 case lval::ConcreteIntKind:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000160 if (isa<lval::ConcreteInt>(R)) {
Ted Kremenek0806acf2008-02-05 23:08:41 +0000161 bool b = cast<lval::ConcreteInt>(this)->getValue() !=
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000162 cast<lval::ConcreteInt>(R).getValue();
Ted Kremenek0806acf2008-02-05 23:08:41 +0000163
Ted Kremenek240f1f02008-03-07 20:13:31 +0000164 return NonLVal::MakeIntTruthVal(BasicVals, b);
Ted Kremenek0806acf2008-02-05 23:08:41 +0000165 }
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000166 else if (isa<lval::SymbolVal>(R)) {
Ted Kremenek0806acf2008-02-05 23:08:41 +0000167
168 const SymIntConstraint& C =
Ted Kremenek240f1f02008-03-07 20:13:31 +0000169 BasicVals.getConstraint(cast<lval::SymbolVal>(R).getSymbol(),
Ted Kremenek0806acf2008-02-05 23:08:41 +0000170 BinaryOperator::NE,
171 cast<lval::ConcreteInt>(this)->getValue());
172
173 return nonlval::SymIntConstraintVal(C);
174 }
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000175
Ted Kremenek0806acf2008-02-05 23:08:41 +0000176 break;
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000177
Ted Kremenek0806acf2008-02-05 23:08:41 +0000178 case lval::SymbolValKind: {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000179 if (isa<lval::ConcreteInt>(R)) {
Ted Kremenek0806acf2008-02-05 23:08:41 +0000180
181 const SymIntConstraint& C =
Ted Kremenek240f1f02008-03-07 20:13:31 +0000182 BasicVals.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
Ted Kremenek0806acf2008-02-05 23:08:41 +0000183 BinaryOperator::NE,
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000184 cast<lval::ConcreteInt>(R).getValue());
Ted Kremenek0806acf2008-02-05 23:08:41 +0000185
186 return nonlval::SymIntConstraintVal(C);
187 }
188
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000189 assert (!isa<lval::SymbolVal>(R) && "FIXME: Implement sym !=.");
Ted Kremenek0806acf2008-02-05 23:08:41 +0000190
191 break;
192 }
193
194 case lval::DeclValKind:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000195 if (isa<lval::DeclVal>(R)) {
196 bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(R);
Ted Kremenek240f1f02008-03-07 20:13:31 +0000197 return NonLVal::MakeIntTruthVal(BasicVals, b);
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000198 }
Ted Kremenek0806acf2008-02-05 23:08:41 +0000199
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000200 break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000201 }
Ted Kremenek0806acf2008-02-05 23:08:41 +0000202
Ted Kremenek240f1f02008-03-07 20:13:31 +0000203 return NonLVal::MakeIntTruthVal(BasicVals, true);
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000204}
205
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000206//===----------------------------------------------------------------------===//
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000207// Utility methods for constructing Non-LVals.
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000208//===----------------------------------------------------------------------===//
209
Ted Kremenek240f1f02008-03-07 20:13:31 +0000210NonLVal NonLVal::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
211 return nonlval::ConcreteInt(BasicVals.getValue(X, T));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000212}
213
Ted Kremenek240f1f02008-03-07 20:13:31 +0000214NonLVal NonLVal::MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000215
Ted Kremenek240f1f02008-03-07 20:13:31 +0000216 return nonlval::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000217 I->getType()->isUnsignedIntegerType())));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000218}
219
Ted Kremenek240f1f02008-03-07 20:13:31 +0000220NonLVal NonLVal::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
221 return nonlval::ConcreteInt(BasicVals.getTruthValue(b));
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000222}
223
Ted Kremenekd763eb92008-02-26 02:15:56 +0000224RVal RVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000225
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000226 QualType T = D->getType();
227
228 if (T->isPointerType() || T->isReferenceType())
Ted Kremenek329f8542008-02-05 21:52:21 +0000229 return lval::SymbolVal(SymMgr.getSymbol(D));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000230 else
Ted Kremenek329f8542008-02-05 21:52:21 +0000231 return nonlval::SymbolVal(SymMgr.getSymbol(D));
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000232}
233
Ted Kremenek2a502572008-02-12 21:37:56 +0000234//===----------------------------------------------------------------------===//
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000235// Utility methods for constructing LVals.
Ted Kremenek2a502572008-02-12 21:37:56 +0000236//===----------------------------------------------------------------------===//
237
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000238LVal LVal::MakeVal(AddrLabelExpr* E) { return lval::GotoLabel(E->getLabel()); }
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000239
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000240//===----------------------------------------------------------------------===//
Ted Kremenek9b5551d2008-03-09 03:30:59 +0000241// Utility methods for constructing RVals (both NonLVals and LVals).
242//===----------------------------------------------------------------------===//
243
244RVal RVal::MakeVal(BasicValueFactory& BasicVals, DeclRefExpr* E) {
245
246 ValueDecl* D = cast<DeclRefExpr>(E)->getDecl();
247
248 if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
249 return lval::DeclVal(VD);
250 }
251 else if (EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) {
252
253 // FIXME: Do we need to cache a copy of this enum, since it
254 // already has persistent storage? We do this because we
255 // are comparing states using pointer equality. Perhaps there is
256 // a better way, since APInts are fairly lightweight.
257
258 return nonlval::ConcreteInt(BasicVals.getValue(ED->getInitVal()));
259 }
260 else if (FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
261 return lval::FuncVal(FD);
262 }
263
264 assert (false &&
265 "ValueDecl support for this ValueDecl not implemented.");
266
267 return UnknownVal();
268}
269
270//===----------------------------------------------------------------------===//
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000271// Pretty-Printing.
272//===----------------------------------------------------------------------===//
273
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000274void RVal::printStdErr() const { print(*llvm::cerr.stream()); }
Ted Kremenek2a502572008-02-12 21:37:56 +0000275
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000276void RVal::print(std::ostream& Out) const {
277
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000278 switch (getBaseKind()) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000279
Ted Kremenek53c641a2008-02-08 03:02:48 +0000280 case UnknownKind:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000281 Out << "Invalid"; break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000282
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000283 case NonLValKind:
284 cast<NonLVal>(this)->print(Out); break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000285
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000286 case LValKind:
287 cast<LVal>(this)->print(Out); break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000288
Ted Kremenek4a4e5242008-02-28 09:25:22 +0000289 case UndefinedKind:
290 Out << "Undefined"; break;
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000291
292 default:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000293 assert (false && "Invalid RVal.");
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000294 }
295}
296
Ted Kremenek0806acf2008-02-05 23:08:41 +0000297static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000298
299 switch (Op) {
300 case BinaryOperator::Mul: Out << '*' ; break;
301 case BinaryOperator::Div: Out << '/' ; break;
302 case BinaryOperator::Rem: Out << '%' ; break;
303 case BinaryOperator::Add: Out << '+' ; break;
304 case BinaryOperator::Sub: Out << '-' ; break;
Ted Kremenek50d0ac22008-02-15 22:09:30 +0000305 case BinaryOperator::Shl: Out << "<<" ; break;
306 case BinaryOperator::Shr: Out << ">>" ; break;
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000307 case BinaryOperator::LT: Out << "<" ; break;
308 case BinaryOperator::GT: Out << '>' ; break;
309 case BinaryOperator::LE: Out << "<=" ; break;
310 case BinaryOperator::GE: Out << ">=" ; break;
311 case BinaryOperator::EQ: Out << "==" ; break;
312 case BinaryOperator::NE: Out << "!=" ; break;
313 case BinaryOperator::And: Out << '&' ; break;
314 case BinaryOperator::Xor: Out << '^' ; break;
315 case BinaryOperator::Or: Out << '|' ; break;
316
Ted Kremenek0806acf2008-02-05 23:08:41 +0000317 default: assert(false && "Not yet implemented.");
318 }
319}
320
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000321void NonLVal::print(std::ostream& Out) const {
322
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000323 switch (getSubKind()) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000324
Ted Kremenek329f8542008-02-05 21:52:21 +0000325 case nonlval::ConcreteIntKind:
326 Out << cast<nonlval::ConcreteInt>(this)->getValue().toString();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000327
328 if (cast<nonlval::ConcreteInt>(this)->getValue().isUnsigned())
329 Out << 'U';
330
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000331 break;
332
Ted Kremenek329f8542008-02-05 21:52:21 +0000333 case nonlval::SymbolValKind:
Ted Kremenek0806acf2008-02-05 23:08:41 +0000334 Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbol();
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000335 break;
Ted Kremenek0806acf2008-02-05 23:08:41 +0000336
337 case nonlval::SymIntConstraintValKind: {
338 const nonlval::SymIntConstraintVal& C =
339 *cast<nonlval::SymIntConstraintVal>(this);
340
341 Out << '$' << C.getConstraint().getSymbol() << ' ';
342 printOpcode(Out, C.getConstraint().getOpcode());
343 Out << ' ' << C.getConstraint().getInt().toString();
Ted Kremenekcf78b6a2008-02-06 22:50:25 +0000344
345 if (C.getConstraint().getInt().isUnsigned())
346 Out << 'U';
347
Ted Kremenek0806acf2008-02-05 23:08:41 +0000348 break;
349 }
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000350
351 default:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000352 assert (false && "Pretty-printed not implemented for this NonLVal.");
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000353 break;
354 }
355}
356
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000357void LVal::print(std::ostream& Out) const {
358
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000359 switch (getSubKind()) {
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000360
Ted Kremenek329f8542008-02-05 21:52:21 +0000361 case lval::ConcreteIntKind:
362 Out << cast<lval::ConcreteInt>(this)->getValue().toString()
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000363 << " (LVal)";
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000364 break;
365
Ted Kremenek329f8542008-02-05 21:52:21 +0000366 case lval::SymbolValKind:
Ted Kremenek0806acf2008-02-05 23:08:41 +0000367 Out << '$' << cast<lval::SymbolVal>(this)->getSymbol();
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000368 break;
Ted Kremenek2a502572008-02-12 21:37:56 +0000369
370 case lval::GotoLabelKind:
371 Out << "&&"
372 << cast<lval::GotoLabel>(this)->getLabel()->getID()->getName();
373 break;
Ted Kremenek08b66252008-02-06 04:31:33 +0000374
Ted Kremenek329f8542008-02-05 21:52:21 +0000375 case lval::DeclValKind:
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000376 Out << '&'
Ted Kremenekde434242008-02-19 01:44:53 +0000377 << cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName();
378 break;
379
380 case lval::FuncValKind:
381 Out << "function "
382 << cast<lval::FuncVal>(this)->getDecl()->getIdentifier()->getName();
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000383 break;
384
385 default:
Ted Kremenekaa1c4e52008-02-21 18:02:17 +0000386 assert (false && "Pretty-printing not implemented for this LVal.");
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000387 break;
388 }
389}