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 | |
Ted Kremenek | cc409b7 | 2008-02-14 17:30:51 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/PathSensitive/RValues.h" |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Streams.h" |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang; |
| 19 | using llvm::dyn_cast; |
| 20 | using llvm::cast; |
| 21 | using llvm::APSInt; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 24 | // Symbol Iteration. |
| 25 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 26 | |
Ted Kremenek | 90e1481 | 2008-02-14 23:25:54 +0000 | [diff] [blame] | 27 | RValue::symbol_iterator RValue::symbol_begin() const { |
| 28 | if (isa<LValue>(this)) { |
| 29 | if (isa<lval::SymbolVal>(this)) |
| 30 | return (symbol_iterator) (&Data); |
| 31 | } |
| 32 | else { |
| 33 | if (isa<nonlval::SymbolVal>(this)) |
| 34 | return (symbol_iterator) (&Data); |
| 35 | else if (isa<nonlval::SymIntConstraintVal>(this)) { |
| 36 | const SymIntConstraint& C = |
| 37 | cast<nonlval::SymIntConstraintVal>(this)->getConstraint(); |
| 38 | return (symbol_iterator) &C.getSymbol(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return NULL; |
| 43 | } |
| 44 | |
| 45 | RValue::symbol_iterator RValue::symbol_end() const { |
| 46 | symbol_iterator X = symbol_begin(); |
| 47 | return X ? X+1 : NULL; |
| 48 | } |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 49 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 50 | //===----------------------------------------------------------------------===// |
| 51 | // Transfer function dispatch for Non-LValues. |
| 52 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 53 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 54 | nonlval::ConcreteInt |
| 55 | nonlval::ConcreteInt::EvalBinaryOp(ValueManager& ValMgr, |
| 56 | BinaryOperator::Opcode Op, |
| 57 | const nonlval::ConcreteInt& RHS) const { |
| 58 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 59 | return ValMgr.EvaluateAPSInt(Op, getValue(), RHS.getValue()); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
| 63 | // Bitwise-Complement. |
| 64 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 65 | |
| 66 | nonlval::ConcreteInt |
| 67 | nonlval::ConcreteInt::EvalComplement(ValueManager& ValMgr) const { |
| 68 | return ValMgr.getValue(~getValue()); |
| 69 | } |
| 70 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 71 | // Unary Minus. |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 72 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 73 | nonlval::ConcreteInt |
| 74 | nonlval::ConcreteInt::EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const { |
| 75 | assert (U->getType() == U->getSubExpr()->getType()); |
| 76 | assert (U->getType()->isIntegerType()); |
| 77 | return ValMgr.getValue(-getValue()); |
Ted Kremenek | c5d3b4c | 2008-02-04 16:58:30 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 80 | //===----------------------------------------------------------------------===// |
| 81 | // Transfer function dispatch for LValues. |
| 82 | //===----------------------------------------------------------------------===// |
| 83 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 84 | lval::ConcreteInt |
| 85 | lval::ConcreteInt::EvalBinaryOp(ValueManager& ValMgr, |
| 86 | BinaryOperator::Opcode Op, |
| 87 | const lval::ConcreteInt& RHS) const { |
| 88 | |
| 89 | assert (Op == BinaryOperator::Add || Op == BinaryOperator::Sub || |
| 90 | (Op >= BinaryOperator::LT && Op <= BinaryOperator::NE)); |
| 91 | |
Ted Kremenek | d70d0b0 | 2008-02-16 01:12:31 +0000 | [diff] [blame] | 92 | return ValMgr.EvaluateAPSInt(Op, getValue(), RHS.getValue()); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 93 | } |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 94 | |
| 95 | NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const { |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 96 | switch (getSubKind()) { |
| 97 | default: |
| 98 | assert(false && "EQ not implemented for this LValue."); |
Ted Kremenek | 2203118 | 2008-02-08 02:57:34 +0000 | [diff] [blame] | 99 | return cast<NonLValue>(UnknownVal()); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 100 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 101 | case lval::ConcreteIntKind: |
| 102 | if (isa<lval::ConcreteInt>(RHS)) { |
| 103 | bool b = cast<lval::ConcreteInt>(this)->getValue() == |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 104 | cast<lval::ConcreteInt>(RHS).getValue(); |
| 105 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 106 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 107 | } |
| 108 | else if (isa<lval::SymbolVal>(RHS)) { |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 109 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 110 | const SymIntConstraint& C = |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 111 | ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(), |
| 112 | BinaryOperator::EQ, |
| 113 | cast<lval::ConcreteInt>(this)->getValue()); |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 114 | |
| 115 | return nonlval::SymIntConstraintVal(C); |
| 116 | } |
| 117 | |
| 118 | break; |
| 119 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 120 | case lval::SymbolValKind: { |
| 121 | if (isa<lval::ConcreteInt>(RHS)) { |
| 122 | |
| 123 | const SymIntConstraint& C = |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 124 | ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(), |
| 125 | BinaryOperator::EQ, |
| 126 | cast<lval::ConcreteInt>(RHS).getValue()); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 127 | |
| 128 | return nonlval::SymIntConstraintVal(C); |
| 129 | } |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 130 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 131 | assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement unification."); |
| 132 | |
| 133 | break; |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 134 | } |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 135 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 136 | case lval::DeclValKind: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 137 | if (isa<lval::DeclVal>(RHS)) { |
| 138 | bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS); |
| 139 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 140 | } |
| 141 | |
| 142 | break; |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 143 | } |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 144 | |
| 145 | return NonLValue::GetIntTruthValue(ValMgr, false); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const { |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 149 | switch (getSubKind()) { |
| 150 | default: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 151 | assert(false && "NE not implemented for this LValue."); |
Ted Kremenek | 2203118 | 2008-02-08 02:57:34 +0000 | [diff] [blame] | 152 | return cast<NonLValue>(UnknownVal()); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 153 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 154 | case lval::ConcreteIntKind: |
| 155 | if (isa<lval::ConcreteInt>(RHS)) { |
| 156 | bool b = cast<lval::ConcreteInt>(this)->getValue() != |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 157 | cast<lval::ConcreteInt>(RHS).getValue(); |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 158 | |
| 159 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 160 | } |
| 161 | else if (isa<lval::SymbolVal>(RHS)) { |
| 162 | |
| 163 | const SymIntConstraint& C = |
| 164 | ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(), |
| 165 | BinaryOperator::NE, |
| 166 | cast<lval::ConcreteInt>(this)->getValue()); |
| 167 | |
| 168 | return nonlval::SymIntConstraintVal(C); |
| 169 | } |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 170 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 171 | break; |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 172 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 173 | case lval::SymbolValKind: { |
| 174 | if (isa<lval::ConcreteInt>(RHS)) { |
| 175 | |
| 176 | const SymIntConstraint& C = |
| 177 | ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(), |
| 178 | BinaryOperator::NE, |
| 179 | cast<lval::ConcreteInt>(RHS).getValue()); |
| 180 | |
| 181 | return nonlval::SymIntConstraintVal(C); |
| 182 | } |
| 183 | |
| 184 | assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement sym !=."); |
| 185 | |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | case lval::DeclValKind: |
| 190 | if (isa<lval::DeclVal>(RHS)) { |
| 191 | bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS); |
| 192 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 193 | } |
| 194 | |
| 195 | break; |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 196 | } |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 197 | |
| 198 | return NonLValue::GetIntTruthValue(ValMgr, true); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 201 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 202 | |
| 203 | //===----------------------------------------------------------------------===// |
| 204 | // Utility methods for constructing Non-LValues. |
| 205 | //===----------------------------------------------------------------------===// |
| 206 | |
| 207 | NonLValue NonLValue::GetValue(ValueManager& ValMgr, uint64_t X, QualType T, |
| 208 | SourceLocation Loc) { |
| 209 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 210 | return nonlval::ConcreteInt(ValMgr.getValue(X, T, Loc)); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 214 | return nonlval::ConcreteInt(ValMgr.getValue(APSInt(I->getValue(), |
| 215 | I->getType()->isUnsignedIntegerType()))); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 218 | NonLValue NonLValue::GetIntTruthValue(ValueManager& ValMgr, bool b) { |
| 219 | return nonlval::ConcreteInt(ValMgr.getTruthValue(b)); |
| 220 | } |
| 221 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 222 | RValue RValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) { |
| 223 | QualType T = D->getType(); |
| 224 | |
| 225 | if (T->isPointerType() || T->isReferenceType()) |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 226 | return lval::SymbolVal(SymMgr.getSymbol(D)); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 227 | else |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 228 | return nonlval::SymbolVal(SymMgr.getSymbol(D)); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Ted Kremenek | 2a50257 | 2008-02-12 21:37:56 +0000 | [diff] [blame] | 231 | //===----------------------------------------------------------------------===// |
| 232 | // Utility methods for constructing LValues. |
| 233 | //===----------------------------------------------------------------------===// |
| 234 | |
| 235 | LValue LValue::GetValue(AddrLabelExpr* E) { |
| 236 | return lval::GotoLabel(E->getLabel()); |
Ted Kremenek | 5b6dc2d | 2008-02-07 01:08:27 +0000 | [diff] [blame] | 237 | } |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 238 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 239 | //===----------------------------------------------------------------------===// |
| 240 | // Pretty-Printing. |
| 241 | //===----------------------------------------------------------------------===// |
| 242 | |
Ted Kremenek | 2a50257 | 2008-02-12 21:37:56 +0000 | [diff] [blame] | 243 | void RValue::print() const { |
| 244 | print(*llvm::cerr.stream()); |
| 245 | } |
| 246 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 247 | void RValue::print(std::ostream& Out) const { |
| 248 | switch (getBaseKind()) { |
Ted Kremenek | 53c641a | 2008-02-08 03:02:48 +0000 | [diff] [blame] | 249 | case UnknownKind: |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 250 | Out << "Invalid"; |
| 251 | break; |
| 252 | |
| 253 | case NonLValueKind: |
| 254 | cast<NonLValue>(this)->print(Out); |
| 255 | break; |
| 256 | |
| 257 | case LValueKind: |
| 258 | cast<LValue>(this)->print(Out); |
| 259 | break; |
| 260 | |
| 261 | case UninitializedKind: |
| 262 | Out << "Uninitialized"; |
| 263 | break; |
| 264 | |
| 265 | default: |
| 266 | assert (false && "Invalid RValue."); |
| 267 | } |
| 268 | } |
| 269 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 270 | static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) { |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 271 | switch (Op) { |
| 272 | case BinaryOperator::Mul: Out << "*"; break; |
| 273 | case BinaryOperator::Div: Out << "/"; break; |
| 274 | case BinaryOperator::Rem: Out << "%" ; break; |
Ted Kremenek | 7e59336 | 2008-02-07 15:20:13 +0000 | [diff] [blame] | 275 | case BinaryOperator::Add: Out << "+" ; break; |
| 276 | case BinaryOperator::Sub: Out << "-" ; break; |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 277 | case BinaryOperator::Shl: Out << "<<" ; break; |
| 278 | case BinaryOperator::Shr: Out << ">>" ; break; |
| 279 | case BinaryOperator::LT: Out << "<" ; break; |
| 280 | case BinaryOperator::GT: Out << ">" ; break; |
| 281 | case BinaryOperator::LE: Out << "<=" ; break; |
| 282 | case BinaryOperator::GE: Out << ">=" ; break; |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 283 | case BinaryOperator::EQ: Out << "=="; break; |
| 284 | case BinaryOperator::NE: Out << "!="; break; |
Ted Kremenek | 50d0ac2 | 2008-02-15 22:09:30 +0000 | [diff] [blame] | 285 | case BinaryOperator::And: Out << "&" ; break; |
| 286 | case BinaryOperator::Xor: Out << "^" ; break; |
| 287 | case BinaryOperator::Or: Out << "|" ; break; |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 288 | default: assert(false && "Not yet implemented."); |
| 289 | } |
| 290 | } |
| 291 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 292 | void NonLValue::print(std::ostream& Out) const { |
| 293 | switch (getSubKind()) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 294 | case nonlval::ConcreteIntKind: |
| 295 | Out << cast<nonlval::ConcreteInt>(this)->getValue().toString(); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 296 | |
| 297 | if (cast<nonlval::ConcreteInt>(this)->getValue().isUnsigned()) |
| 298 | Out << 'U'; |
| 299 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 300 | break; |
| 301 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 302 | case nonlval::SymbolValKind: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 303 | Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbol(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 304 | break; |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 305 | |
| 306 | case nonlval::SymIntConstraintValKind: { |
| 307 | const nonlval::SymIntConstraintVal& C = |
| 308 | *cast<nonlval::SymIntConstraintVal>(this); |
| 309 | |
| 310 | Out << '$' << C.getConstraint().getSymbol() << ' '; |
| 311 | printOpcode(Out, C.getConstraint().getOpcode()); |
| 312 | Out << ' ' << C.getConstraint().getInt().toString(); |
Ted Kremenek | cf78b6a | 2008-02-06 22:50:25 +0000 | [diff] [blame] | 313 | |
| 314 | if (C.getConstraint().getInt().isUnsigned()) |
| 315 | Out << 'U'; |
| 316 | |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 317 | break; |
| 318 | } |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 319 | |
| 320 | default: |
| 321 | assert (false && "Pretty-printed not implemented for this NonLValue."); |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 326 | |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 327 | void LValue::print(std::ostream& Out) const { |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 328 | switch (getSubKind()) { |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 329 | case lval::ConcreteIntKind: |
| 330 | Out << cast<lval::ConcreteInt>(this)->getValue().toString() |
Ted Kremenek | a6e4d21 | 2008-02-01 06:36:40 +0000 | [diff] [blame] | 331 | << " (LValue)"; |
| 332 | break; |
| 333 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 334 | case lval::SymbolValKind: |
Ted Kremenek | 0806acf | 2008-02-05 23:08:41 +0000 | [diff] [blame] | 335 | Out << '$' << cast<lval::SymbolVal>(this)->getSymbol(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 336 | break; |
Ted Kremenek | 2a50257 | 2008-02-12 21:37:56 +0000 | [diff] [blame] | 337 | |
| 338 | case lval::GotoLabelKind: |
| 339 | Out << "&&" |
| 340 | << cast<lval::GotoLabel>(this)->getLabel()->getID()->getName(); |
| 341 | break; |
Ted Kremenek | 08b6625 | 2008-02-06 04:31:33 +0000 | [diff] [blame] | 342 | |
Ted Kremenek | 329f854 | 2008-02-05 21:52:21 +0000 | [diff] [blame] | 343 | case lval::DeclValKind: |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 344 | Out << '&' |
Ted Kremenek | de43424 | 2008-02-19 01:44:53 +0000 | [diff] [blame^] | 345 | << cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName(); |
| 346 | break; |
| 347 | |
| 348 | case lval::FuncValKind: |
| 349 | Out << "function " |
| 350 | << cast<lval::FuncVal>(this)->getDecl()->getIdentifier()->getName(); |
Ted Kremenek | a90ccfe | 2008-01-31 19:34:24 +0000 | [diff] [blame] | 351 | break; |
| 352 | |
| 353 | default: |
| 354 | assert (false && "Pretty-printed not implemented for this LValue."); |
| 355 | break; |
| 356 | } |
| 357 | } |
Ted Kremenek | d131c4f | 2008-02-07 05:48:01 +0000 | [diff] [blame] | 358 | |