diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-02-01 06:36:40 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-02-01 06:36:40 +0000 |
commit | a6e4d21dc4fe87fe1b0bcd9c3c3ec43b391aa44b (patch) | |
tree | ee3dcb264d22403333814afea23267c973820a05 /Analysis/RValues.cpp | |
parent | 9415a0cc93117b69add4e1dc0f11146f3479ee1a (diff) |
Implemented casts for ConcreteInt and ConcreteIntLValue.
Implemented '==' and '!=' for ConcreteIntLValue.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46630 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Analysis/RValues.cpp')
-rw-r--r-- | Analysis/RValues.cpp | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/Analysis/RValues.cpp b/Analysis/RValues.cpp index 4008e765e0..f41051ed57 100644 --- a/Analysis/RValues.cpp +++ b/Analysis/RValues.cpp @@ -79,20 +79,56 @@ APSInt& ValueManager::getValue(uint64_t X, QualType T, SourceLocation Loc) { return getValue(V); } - //===----------------------------------------------------------------------===// -// Transfer function dispatch for Non-LValues. +// Transfer function for Casts. //===----------------------------------------------------------------------===// RValue RValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { - switch (getSubKind()) { - case ConcreteIntKind: - return cast<ConcreteInt>(this)->Cast(ValMgr, CastExpr); - default: - return InvalidValue(); + switch (getBaseKind()) { + default: assert(false && "Invalid RValue."); break; + case LValueKind: return cast<LValue>(this)->Cast(ValMgr, CastExpr); + case NonLValueKind: return cast<NonLValue>(this)->Cast(ValMgr, CastExpr); + case UninitializedKind: case InvalidKind: break; } + + return *this; +} + +RValue LValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { + if (CastExpr->getType()->isPointerType()) + return *this; + + assert (CastExpr->getType()->isIntegerType()); + + if (!isa<ConcreteIntLValue>(*this)) + return InvalidValue(); + + APSInt V = cast<ConcreteIntLValue>(this)->getValue(); + QualType T = CastExpr->getType(); + V.setIsUnsigned(T->isUnsignedIntegerType()); + V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart())); + return ConcreteInt(ValMgr.getValue(V)); } +RValue NonLValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { + if (!isa<ConcreteInt>(this)) + return InvalidValue(); + + APSInt V = cast<ConcreteInt>(this)->getValue(); + QualType T = CastExpr->getType(); + V.setIsUnsigned(T->isUnsignedIntegerType()); + V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart())); + + if (CastExpr->getType()->isPointerType()) + return ConcreteIntLValue(ValMgr.getValue(V)); + else + return ConcreteInt(ValMgr.getValue(V)); +} + +//===----------------------------------------------------------------------===// +// Transfer function dispatch for Non-LValues. +//===----------------------------------------------------------------------===// + NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const { switch (getSubKind()) { case ConcreteIntKind: @@ -162,6 +198,13 @@ NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const { default: assert(false && "EQ not implemented for this LValue."); return cast<NonLValue>(InvalidValue()); + + case ConcreteIntLValueKind: { + bool b = cast<ConcreteIntLValue>(this)->getValue() == + cast<ConcreteIntLValue>(RHS).getValue(); + + return NonLValue::GetIntTruthValue(ValMgr, b); + } case LValueDeclKind: { bool b = cast<LValueDecl>(*this) == cast<LValueDecl>(RHS); @@ -179,6 +222,13 @@ NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const { assert(false && "EQ not implemented for this LValue."); return cast<NonLValue>(InvalidValue()); + case ConcreteIntLValueKind: { + bool b = cast<ConcreteIntLValue>(this)->getValue() != + cast<ConcreteIntLValue>(RHS).getValue(); + + return NonLValue::GetIntTruthValue(ValMgr, b); + } + case LValueDeclKind: { bool b = cast<LValueDecl>(*this) != cast<LValueDecl>(RHS); return NonLValue::GetIntTruthValue(ValMgr, b); @@ -255,7 +305,12 @@ void NonLValue::print(std::ostream& Out) const { } void LValue::print(std::ostream& Out) const { - switch (getSubKind()) { + switch (getSubKind()) { + case ConcreteIntLValueKind: + Out << cast<ConcreteIntLValue>(this)->getValue().toString() + << " (LValue)"; + break; + case SymbolicLValueKind: Out << '$' << cast<SymbolicLValue>(this)->getSymbolID(); break; |