Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 1 | //= 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 | // |
| 10 | // This files defines RValue, LValue, and NonLValue, classes that represent |
| 11 | // abstract r-values for use with path-sensitive value tracking. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "RValues.h" |
| 16 | |
| 17 | using namespace clang; |
| 18 | using llvm::dyn_cast; |
| 19 | using llvm::cast; |
| 20 | using llvm::APSInt; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // SymbolManager. |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | SymbolID SymbolManager::getSymbol(ParmVarDecl* D) { |
| 27 | SymbolID& X = DataToSymbol[D]; |
| 28 | |
| 29 | if (!X.isInitialized()) { |
| 30 | X = SymbolToData.size(); |
| 31 | SymbolToData.push_back(D); |
| 32 | } |
| 33 | |
| 34 | return X; |
| 35 | } |
| 36 | |
| 37 | SymbolManager::SymbolManager() {} |
| 38 | SymbolManager::~SymbolManager() {} |
| 39 | |
| 40 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 1fbdb02 | 2008-02-05 21:32:43 +0000 | [diff] [blame] | 41 | // Values and ValueManager. |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 42 | //===----------------------------------------------------------------------===// |
| 43 | |
| 44 | ValueManager::~ValueManager() { |
| 45 | // Note that the dstor for the contents of APSIntSet will never be called, |
| 46 | // so we iterate over the set and invoke the dstor for each APSInt. This |
| 47 | // frees an aux. memory allocated to represent very large constants. |
| 48 | for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I) |
| 49 | I->getValue().~APSInt(); |
| 50 | } |
| 51 | |
Ted Kremenek | 1fbdb02 | 2008-02-05 21:32:43 +0000 | [diff] [blame] | 52 | const APSInt& ValueManager::getValue(const APSInt& X) { |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 53 | llvm::FoldingSetNodeID ID; |
| 54 | void* InsertPos; |
| 55 | typedef llvm::FoldingSetNodeWrapper<APSInt> FoldNodeTy; |
| 56 | |
| 57 | X.Profile(ID); |
| 58 | FoldNodeTy* P = APSIntSet.FindNodeOrInsertPos(ID, InsertPos); |
| 59 | |
| 60 | if (!P) { |
| 61 | P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); |
| 62 | new (P) FoldNodeTy(X); |
| 63 | APSIntSet.InsertNode(P, InsertPos); |
| 64 | } |
| 65 | |
| 66 | return *P; |
| 67 | } |
| 68 | |
Ted Kremenek | 1fbdb02 | 2008-02-05 21:32:43 +0000 | [diff] [blame] | 69 | const APSInt& ValueManager::getValue(uint64_t X, unsigned BitWidth, |
| 70 | bool isUnsigned) { |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 71 | APSInt V(BitWidth, isUnsigned); |
| 72 | V = X; |
| 73 | return getValue(V); |
| 74 | } |
| 75 | |
Ted Kremenek | 1fbdb02 | 2008-02-05 21:32:43 +0000 | [diff] [blame] | 76 | const APSInt& ValueManager::getValue(uint64_t X, QualType T, |
| 77 | SourceLocation Loc) { |
| 78 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 79 | unsigned bits = Ctx.getTypeSize(T, Loc); |
| 80 | APSInt V(bits, T->isUnsignedIntegerType()); |
| 81 | V = X; |
| 82 | return getValue(V); |
| 83 | } |
| 84 | |
Ted Kremenek | 1fbdb02 | 2008-02-05 21:32:43 +0000 | [diff] [blame] | 85 | const SymIntConstraint& |
| 86 | ValueManager::getConstraint(SymbolID sym, BinaryOperator::Opcode Op, |
| 87 | const llvm::APSInt& V) { |
| 88 | |
| 89 | llvm::FoldingSetNodeID ID; |
| 90 | SymIntConstraint::Profile(ID, sym, Op, V); |
| 91 | void* InsertPos; |
| 92 | |
| 93 | SymIntConstraint* C = SymIntCSet.FindNodeOrInsertPos(ID, InsertPos); |
| 94 | |
| 95 | if (!C) { |
| 96 | C = (SymIntConstraint*) BPAlloc.Allocate<SymIntConstraint>(); |
| 97 | new (C) SymIntConstraint(sym, Op, V); |
| 98 | SymIntCSet.InsertNode(C, InsertPos); |
| 99 | } |
| 100 | |
| 101 | return *C; |
| 102 | } |
| 103 | |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 104 | //===----------------------------------------------------------------------===// |
| 105 | // Transfer function for Casts. |
| 106 | //===----------------------------------------------------------------------===// |
| 107 | |
| 108 | RValue RValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { |
| 109 | switch (getBaseKind()) { |
| 110 | default: assert(false && "Invalid RValue."); break; |
| 111 | case LValueKind: return cast<LValue>(this)->Cast(ValMgr, CastExpr); |
| 112 | case NonLValueKind: return cast<NonLValue>(this)->Cast(ValMgr, CastExpr); |
| 113 | case UninitializedKind: case InvalidKind: break; |
| 114 | } |
| 115 | |
| 116 | return *this; |
| 117 | } |
| 118 | |
| 119 | RValue LValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { |
| 120 | if (CastExpr->getType()->isPointerType()) |
| 121 | return *this; |
| 122 | |
| 123 | assert (CastExpr->getType()->isIntegerType()); |
| 124 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 125 | if (!isa<lval::ConcreteInt>(*this)) |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 126 | return InvalidValue(); |
| 127 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 128 | APSInt V = cast<lval::ConcreteInt>(this)->getValue(); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 129 | QualType T = CastExpr->getType(); |
| 130 | V.setIsUnsigned(T->isUnsignedIntegerType()); |
| 131 | V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart())); |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 132 | return nonlval::ConcreteInt(ValMgr.getValue(V)); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | RValue NonLValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 136 | if (!isa<nonlval::ConcreteInt>(this)) |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 137 | return InvalidValue(); |
| 138 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 139 | APSInt V = cast<nonlval::ConcreteInt>(this)->getValue(); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 140 | QualType T = CastExpr->getType(); |
Ted Kremenek | 08b6625 | 2008-02-06 04:31:33 +0000 | [diff] [blame] | 141 | V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType()); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 142 | V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart())); |
| 143 | |
| 144 | if (CastExpr->getType()->isPointerType()) |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 145 | return lval::ConcreteInt(ValMgr.getValue(V)); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 146 | else |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 147 | return nonlval::ConcreteInt(ValMgr.getValue(V)); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 148 | } |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 149 | |
| 150 | //===----------------------------------------------------------------------===// |
| 151 | // Transfer function dispatch for Non-LValues. |
| 152 | //===----------------------------------------------------------------------===// |
| 153 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 154 | NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const { |
| 155 | switch (getSubKind()) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 156 | case nonlval::ConcreteIntKind: |
| 157 | return cast<nonlval::ConcreteInt>(this)->UnaryMinus(ValMgr, U); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 158 | default: |
| 159 | return cast<NonLValue>(InvalidValue()); |
| 160 | } |
| 161 | } |
| 162 | |
Ted Kremenek | c5d3b4c | 2008-02-04 16:58:30 +0000 | [diff] [blame] | 163 | NonLValue NonLValue::BitwiseComplement(ValueManager& ValMgr) const { |
| 164 | switch (getSubKind()) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 165 | case nonlval::ConcreteIntKind: |
| 166 | return cast<nonlval::ConcreteInt>(this)->BitwiseComplement(ValMgr); |
Ted Kremenek | c5d3b4c | 2008-02-04 16:58:30 +0000 | [diff] [blame] | 167 | default: |
| 168 | return cast<NonLValue>(InvalidValue()); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 173 | #define NONLVALUE_DISPATCH_CASE(k1,k2,Op)\ |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 174 | case (k1##Kind*nonlval::NumKind+k2##Kind):\ |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 175 | return cast<k1>(*this).Op(ValMgr,cast<k2>(RHS)); |
| 176 | |
| 177 | #define NONLVALUE_DISPATCH(Op)\ |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 178 | switch (getSubKind()*nonlval::NumKind+RHS.getSubKind()){\ |
| 179 | NONLVALUE_DISPATCH_CASE(nonlval::ConcreteInt,nonlval::ConcreteInt,Op)\ |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 180 | default:\ |
| 181 | if (getBaseKind() == UninitializedKind ||\ |
| 182 | RHS.getBaseKind() == UninitializedKind)\ |
| 183 | return cast<NonLValue>(UninitializedValue());\ |
| 184 | assert (!isValid() || !RHS.isValid() && "Missing case.");\ |
| 185 | break;\ |
| 186 | }\ |
| 187 | return cast<NonLValue>(InvalidValue()); |
| 188 | |
| 189 | NonLValue NonLValue::Add(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 190 | NONLVALUE_DISPATCH(Add) |
| 191 | } |
| 192 | |
| 193 | NonLValue NonLValue::Sub(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 194 | NONLVALUE_DISPATCH(Sub) |
| 195 | } |
| 196 | |
| 197 | NonLValue NonLValue::Mul(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 198 | NONLVALUE_DISPATCH(Mul) |
| 199 | } |
| 200 | |
| 201 | NonLValue NonLValue::Div(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 202 | NONLVALUE_DISPATCH(Div) |
| 203 | } |
| 204 | |
| 205 | NonLValue NonLValue::Rem(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 206 | NONLVALUE_DISPATCH(Rem) |
| 207 | } |
| 208 | |
| 209 | NonLValue NonLValue::EQ(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 210 | NONLVALUE_DISPATCH(EQ) |
| 211 | } |
| 212 | |
| 213 | NonLValue NonLValue::NE(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 214 | NONLVALUE_DISPATCH(NE) |
| 215 | } |
| 216 | |
| 217 | #undef NONLVALUE_DISPATCH_CASE |
| 218 | #undef NONLVALUE_DISPATCH |
| 219 | |
| 220 | //===----------------------------------------------------------------------===// |
| 221 | // Transfer function dispatch for LValues. |
| 222 | //===----------------------------------------------------------------------===// |
| 223 | |
| 224 | |
| 225 | NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const { |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 226 | switch (getSubKind()) { |
| 227 | default: |
| 228 | assert(false && "EQ not implemented for this LValue."); |
| 229 | return cast<NonLValue>(InvalidValue()); |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 230 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 231 | case lval::ConcreteIntKind: |
| 232 | if (isa<lval::ConcreteInt>(RHS)) { |
| 233 | bool b = cast<lval::ConcreteInt>(this)->getValue() == |
| 234 | cast<lval::ConcreteInt>(RHS).getValue(); |
| 235 | |
| 236 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 237 | } |
| 238 | else if (isa<lval::SymbolVal>(RHS)) { |
| 239 | |
| 240 | const SymIntConstraint& C = |
| 241 | ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(), |
| 242 | BinaryOperator::EQ, |
| 243 | cast<lval::ConcreteInt>(this)->getValue()); |
| 244 | |
| 245 | return nonlval::SymIntConstraintVal(C); |
| 246 | } |
| 247 | |
| 248 | break; |
| 249 | |
| 250 | case lval::SymbolValKind: { |
| 251 | if (isa<lval::ConcreteInt>(RHS)) { |
| 252 | |
| 253 | const SymIntConstraint& C = |
| 254 | ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(), |
| 255 | BinaryOperator::EQ, |
| 256 | cast<lval::ConcreteInt>(RHS).getValue()); |
| 257 | |
| 258 | return nonlval::SymIntConstraintVal(C); |
| 259 | } |
| 260 | |
| 261 | assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement unification."); |
| 262 | |
| 263 | break; |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 264 | } |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 265 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 266 | case lval::DeclValKind: |
| 267 | if (isa<lval::DeclVal>(RHS)) { |
| 268 | bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS); |
| 269 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 270 | } |
| 271 | |
| 272 | break; |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 273 | } |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 274 | |
| 275 | return NonLValue::GetIntTruthValue(ValMgr, false); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const { |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 279 | switch (getSubKind()) { |
| 280 | default: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 281 | assert(false && "NE not implemented for this LValue."); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 282 | return cast<NonLValue>(InvalidValue()); |
| 283 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 284 | case lval::ConcreteIntKind: |
| 285 | if (isa<lval::ConcreteInt>(RHS)) { |
| 286 | bool b = cast<lval::ConcreteInt>(this)->getValue() != |
| 287 | cast<lval::ConcreteInt>(RHS).getValue(); |
| 288 | |
| 289 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 290 | } |
| 291 | else if (isa<lval::SymbolVal>(RHS)) { |
| 292 | |
| 293 | const SymIntConstraint& C = |
| 294 | ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(), |
| 295 | BinaryOperator::NE, |
| 296 | cast<lval::ConcreteInt>(this)->getValue()); |
| 297 | |
| 298 | return nonlval::SymIntConstraintVal(C); |
| 299 | } |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 300 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 301 | break; |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 302 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 303 | case lval::SymbolValKind: { |
| 304 | if (isa<lval::ConcreteInt>(RHS)) { |
| 305 | |
| 306 | const SymIntConstraint& C = |
| 307 | ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(), |
| 308 | BinaryOperator::NE, |
| 309 | cast<lval::ConcreteInt>(RHS).getValue()); |
| 310 | |
| 311 | return nonlval::SymIntConstraintVal(C); |
| 312 | } |
| 313 | |
| 314 | assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement sym !=."); |
| 315 | |
| 316 | break; |
| 317 | } |
| 318 | |
| 319 | case lval::DeclValKind: |
| 320 | if (isa<lval::DeclVal>(RHS)) { |
| 321 | bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS); |
| 322 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 323 | } |
| 324 | |
| 325 | break; |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 326 | } |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 327 | |
| 328 | return NonLValue::GetIntTruthValue(ValMgr, true); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
| 332 | //===----------------------------------------------------------------------===// |
| 333 | // Utility methods for constructing Non-LValues. |
| 334 | //===----------------------------------------------------------------------===// |
| 335 | |
| 336 | NonLValue NonLValue::GetValue(ValueManager& ValMgr, uint64_t X, QualType T, |
| 337 | SourceLocation Loc) { |
| 338 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 339 | return nonlval::ConcreteInt(ValMgr.getValue(X, T, Loc)); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 343 | return nonlval::ConcreteInt(ValMgr.getValue(APSInt(I->getValue(), |
| 344 | I->getType()->isUnsignedIntegerType()))); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | RValue RValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) { |
| 348 | QualType T = D->getType(); |
| 349 | |
| 350 | if (T->isPointerType() || T->isReferenceType()) |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 351 | return lval::SymbolVal(SymMgr.getSymbol(D)); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 352 | else |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 353 | return nonlval::SymbolVal(SymMgr.getSymbol(D)); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | //===----------------------------------------------------------------------===// |
| 357 | // Pretty-Printing. |
| 358 | //===----------------------------------------------------------------------===// |
| 359 | |
| 360 | void RValue::print(std::ostream& Out) const { |
| 361 | switch (getBaseKind()) { |
| 362 | case InvalidKind: |
| 363 | Out << "Invalid"; |
| 364 | break; |
| 365 | |
| 366 | case NonLValueKind: |
| 367 | cast<NonLValue>(this)->print(Out); |
| 368 | break; |
| 369 | |
| 370 | case LValueKind: |
| 371 | cast<LValue>(this)->print(Out); |
| 372 | break; |
| 373 | |
| 374 | case UninitializedKind: |
| 375 | Out << "Uninitialized"; |
| 376 | break; |
| 377 | |
| 378 | default: |
| 379 | assert (false && "Invalid RValue."); |
| 380 | } |
| 381 | } |
| 382 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 383 | static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) { |
| 384 | switch (Op) { |
| 385 | case BinaryOperator::EQ: Out << "=="; break; |
| 386 | case BinaryOperator::NE: Out << "!="; break; |
| 387 | default: assert(false && "Not yet implemented."); |
| 388 | } |
| 389 | } |
| 390 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 391 | void NonLValue::print(std::ostream& Out) const { |
| 392 | switch (getSubKind()) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 393 | case nonlval::ConcreteIntKind: |
| 394 | Out << cast<nonlval::ConcreteInt>(this)->getValue().toString(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 395 | break; |
| 396 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 397 | case nonlval::SymbolValKind: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 398 | Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbol(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 399 | break; |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 400 | |
| 401 | case nonlval::SymIntConstraintValKind: { |
| 402 | const nonlval::SymIntConstraintVal& C = |
| 403 | *cast<nonlval::SymIntConstraintVal>(this); |
| 404 | |
| 405 | Out << '$' << C.getConstraint().getSymbol() << ' '; |
| 406 | printOpcode(Out, C.getConstraint().getOpcode()); |
| 407 | Out << ' ' << C.getConstraint().getInt().toString(); |
| 408 | break; |
| 409 | } |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 410 | |
| 411 | default: |
| 412 | assert (false && "Pretty-printed not implemented for this NonLValue."); |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 417 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 418 | void LValue::print(std::ostream& Out) const { |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 419 | switch (getSubKind()) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 420 | case lval::ConcreteIntKind: |
| 421 | Out << cast<lval::ConcreteInt>(this)->getValue().toString() |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 422 | << " (LValue)"; |
| 423 | break; |
| 424 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 425 | case lval::SymbolValKind: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 426 | Out << '$' << cast<lval::SymbolVal>(this)->getSymbol(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 427 | break; |
Ted Kremenek | 08b6625 | 2008-02-06 04:31:33 +0000 | [diff] [blame] | 428 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 429 | case lval::DeclValKind: |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 430 | Out << '&' |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 431 | << cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 432 | break; |
| 433 | |
| 434 | default: |
| 435 | assert (false && "Pretty-printed not implemented for this LValue."); |
| 436 | break; |
| 437 | } |
| 438 | } |