From: Ted Kremenek Date: Thu, 31 Jan 2008 22:17:03 +0000 (+0000) Subject: Added skeleton for new LValue class ConcereteIntLValue. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=516f91b0917f2aafdce1a989482d21a7224b40ec;p=clang Added skeleton for new LValue class ConcereteIntLValue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46624 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/RValues.h b/Analysis/RValues.h index 90446a2cc5..989c60bb3f 100644 --- a/Analysis/RValues.h +++ b/Analysis/RValues.h @@ -217,7 +217,8 @@ public: class LValue : public RValue { protected: - LValue(unsigned SubKind, void* D) : RValue(D, true, SubKind) {} + LValue(unsigned SubKind, const void* D) : RValue(const_cast(D), + true, SubKind) {} public: void print(std::ostream& Out) const; @@ -231,49 +232,6 @@ public: return V->getBaseKind() == LValueKind; } }; - -//==------------------------------------------------------------------------==// -// Subclasses of LValue. -//==------------------------------------------------------------------------==// - -enum LValueKind { SymbolicLValueKind, LValueDeclKind, NumLValueKind }; - -class SymbolicLValue : public LValue { -public: - SymbolicLValue(unsigned SymID) - : LValue(SymbolicLValueKind, reinterpret_cast((uintptr_t) SymID)) {} - - SymbolID getSymbolID() const { - return (SymbolID) reinterpret_cast(getRawPtr()); - } - - static inline bool classof(const RValue* V) { - return V->getSubKind() == SymbolicLValueKind; - } -}; - -class LValueDecl : public LValue { -public: - LValueDecl(const ValueDecl* vd) - : LValue(LValueDeclKind,const_cast(vd)) {} - - ValueDecl* getDecl() const { - return static_cast(getRawPtr()); - } - - inline bool operator==(const LValueDecl& R) const { - return getDecl() == R.getDecl(); - } - - inline bool operator!=(const LValueDecl& R) const { - return getDecl() != R.getDecl(); - } - - // Implement isa support. - static inline bool classof(const RValue* V) { - return V->getSubKind() == LValueDeclKind; - } -}; //==------------------------------------------------------------------------==// // Subclasses of NonLValue. @@ -363,6 +321,87 @@ public: return V->getSubKind() == ConcreteIntKind; } }; + +//==------------------------------------------------------------------------==// +// Subclasses of LValue. +//==------------------------------------------------------------------------==// + +enum LValueKind { SymbolicLValueKind, LValueDeclKind, +ConcreteIntLValueKind, NumLValueKind }; + +class SymbolicLValue : public LValue { +public: + SymbolicLValue(unsigned SymID) + : LValue(SymbolicLValueKind, reinterpret_cast((uintptr_t) SymID)) {} + + SymbolID getSymbolID() const { + return (SymbolID) reinterpret_cast(getRawPtr()); + } + + static inline bool classof(const RValue* V) { + return V->getSubKind() == SymbolicLValueKind; + } +}; + +class LValueDecl : public LValue { +public: + LValueDecl(const ValueDecl* vd) : LValue(LValueDeclKind,vd) {} + + ValueDecl* getDecl() const { + return static_cast(getRawPtr()); + } + + inline bool operator==(const LValueDecl& R) const { + return getDecl() == R.getDecl(); + } + + inline bool operator!=(const LValueDecl& R) const { + return getDecl() != R.getDecl(); + } + + // Implement isa support. + static inline bool classof(const RValue* V) { + return V->getSubKind() == LValueDeclKind; + } +}; + +class ConcreteIntLValue : public LValue { +public: + ConcreteIntLValue(const llvm::APSInt& V) : LValue(ConcreteIntLValueKind, &V) {} + + const llvm::APSInt& getValue() const { + return *static_cast(getRawPtr()); + } + + // Arithmetic operators. + + ConcreteIntLValue Add(ValueManager& ValMgr, const ConcreteInt& V) const { + return ValMgr.getValue(getValue() + V.getValue()); + } + + ConcreteIntLValue Sub(ValueManager& ValMgr, const ConcreteInt& V) const { + return ValMgr.getValue(getValue() - V.getValue()); + } + + // Equality operators. + + ConcreteInt EQ(ValueManager& ValMgr, const ConcreteIntLValue& V) const { + const llvm::APSInt& Val = getValue(); + return ValMgr.getValue(Val == V.getValue() ? 1U : 0U, + Val.getBitWidth(), Val.isUnsigned()); + } + + ConcreteInt NE(ValueManager& ValMgr, const ConcreteIntLValue& V) const { + const llvm::APSInt& Val = getValue(); + return ValMgr.getValue(Val != V.getValue() ? 1U : 0U, + Val.getBitWidth(), Val.isUnsigned()); + } + + // Implement isa support. + static inline bool classof(const RValue* V) { + return V->getSubKind() == ConcreteIntLValueKind; + } +}; } // end clang namespace