assert (CastExpr->getType()->isIntegerType());
- if (!isa<ConcreteIntLValue>(*this))
+ if (!isa<lval::ConcreteInt>(*this))
return InvalidValue();
- APSInt V = cast<ConcreteIntLValue>(this)->getValue();
+ APSInt V = cast<lval::ConcreteInt>(this)->getValue();
QualType T = CastExpr->getType();
V.setIsUnsigned(T->isUnsignedIntegerType());
V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
- return ConcreteInt(ValMgr.getValue(V));
+ return nonlval::ConcreteInt(ValMgr.getValue(V));
}
RValue NonLValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const {
- if (!isa<ConcreteInt>(this))
+ if (!isa<nonlval::ConcreteInt>(this))
return InvalidValue();
- APSInt V = cast<ConcreteInt>(this)->getValue();
+ APSInt V = cast<nonlval::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));
+ return lval::ConcreteInt(ValMgr.getValue(V));
else
- return ConcreteInt(ValMgr.getValue(V));
+ return nonlval::ConcreteInt(ValMgr.getValue(V));
}
//===----------------------------------------------------------------------===//
NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const {
switch (getSubKind()) {
- case ConcreteIntKind:
- return cast<ConcreteInt>(this)->UnaryMinus(ValMgr, U);
+ case nonlval::ConcreteIntKind:
+ return cast<nonlval::ConcreteInt>(this)->UnaryMinus(ValMgr, U);
default:
return cast<NonLValue>(InvalidValue());
}
NonLValue NonLValue::BitwiseComplement(ValueManager& ValMgr) const {
switch (getSubKind()) {
- case ConcreteIntKind:
- return cast<ConcreteInt>(this)->BitwiseComplement(ValMgr);
+ case nonlval::ConcreteIntKind:
+ return cast<nonlval::ConcreteInt>(this)->BitwiseComplement(ValMgr);
default:
return cast<NonLValue>(InvalidValue());
}
#define NONLVALUE_DISPATCH_CASE(k1,k2,Op)\
-case (k1##Kind*NumNonLValueKind+k2##Kind):\
+case (k1##Kind*nonlval::NumKind+k2##Kind):\
return cast<k1>(*this).Op(ValMgr,cast<k2>(RHS));
#define NONLVALUE_DISPATCH(Op)\
-switch (getSubKind()*NumNonLValueKind+RHS.getSubKind()){\
-NONLVALUE_DISPATCH_CASE(ConcreteInt,ConcreteInt,Op)\
+switch (getSubKind()*nonlval::NumKind+RHS.getSubKind()){\
+NONLVALUE_DISPATCH_CASE(nonlval::ConcreteInt,nonlval::ConcreteInt,Op)\
default:\
if (getBaseKind() == UninitializedKind ||\
RHS.getBaseKind() == UninitializedKind)\
assert(false && "EQ not implemented for this LValue.");
return cast<NonLValue>(InvalidValue());
- case ConcreteIntLValueKind: {
- bool b = cast<ConcreteIntLValue>(this)->getValue() ==
- cast<ConcreteIntLValue>(RHS).getValue();
+ case lval::ConcreteIntKind: {
+ bool b = cast<lval::ConcreteInt>(this)->getValue() ==
+ cast<lval::ConcreteInt>(RHS).getValue();
return NonLValue::GetIntTruthValue(ValMgr, b);
}
- case LValueDeclKind: {
- bool b = cast<LValueDecl>(*this) == cast<LValueDecl>(RHS);
+ case lval::DeclValKind: {
+ bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS);
return NonLValue::GetIntTruthValue(ValMgr, b);
}
}
assert(false && "EQ not implemented for this LValue.");
return cast<NonLValue>(InvalidValue());
- case ConcreteIntLValueKind: {
- bool b = cast<ConcreteIntLValue>(this)->getValue() !=
- cast<ConcreteIntLValue>(RHS).getValue();
+ case lval::ConcreteIntKind: {
+ bool b = cast<lval::ConcreteInt>(this)->getValue() !=
+ cast<lval::ConcreteInt>(RHS).getValue();
return NonLValue::GetIntTruthValue(ValMgr, b);
}
- case LValueDeclKind: {
- bool b = cast<LValueDecl>(*this) != cast<LValueDecl>(RHS);
+ case lval::DeclValKind: {
+ bool b = cast<lval::DeclVal>(*this) != cast<lval::DeclVal>(RHS);
return NonLValue::GetIntTruthValue(ValMgr, b);
}
}
NonLValue NonLValue::GetValue(ValueManager& ValMgr, uint64_t X, QualType T,
SourceLocation Loc) {
- return ConcreteInt(ValMgr.getValue(X, T, Loc));
+ return nonlval::ConcreteInt(ValMgr.getValue(X, T, Loc));
}
NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) {
- return ConcreteInt(ValMgr.getValue(APSInt(I->getValue(),
- I->getType()->isUnsignedIntegerType())));
+ return nonlval::ConcreteInt(ValMgr.getValue(APSInt(I->getValue(),
+ I->getType()->isUnsignedIntegerType())));
}
RValue RValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) {
QualType T = D->getType();
if (T->isPointerType() || T->isReferenceType())
- return SymbolicLValue(SymMgr.getSymbol(D));
+ return lval::SymbolVal(SymMgr.getSymbol(D));
else
- return SymbolicNonLValue(SymMgr.getSymbol(D));
+ return nonlval::SymbolVal(SymMgr.getSymbol(D));
}
//===----------------------------------------------------------------------===//
void NonLValue::print(std::ostream& Out) const {
switch (getSubKind()) {
- case ConcreteIntKind:
- Out << cast<ConcreteInt>(this)->getValue().toString();
+ case nonlval::ConcreteIntKind:
+ Out << cast<nonlval::ConcreteInt>(this)->getValue().toString();
break;
- case SymbolicNonLValueKind:
- Out << '$' << cast<SymbolicNonLValue>(this)->getSymbolID();
+ case nonlval::SymbolValKind:
+ Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbolID();
break;
default:
void LValue::print(std::ostream& Out) const {
switch (getSubKind()) {
- case ConcreteIntLValueKind:
- Out << cast<ConcreteIntLValue>(this)->getValue().toString()
+ case lval::ConcreteIntKind:
+ Out << cast<lval::ConcreteInt>(this)->getValue().toString()
<< " (LValue)";
break;
- case SymbolicLValueKind:
- Out << '$' << cast<SymbolicLValue>(this)->getSymbolID();
+ case lval::SymbolValKind:
+ Out << '$' << cast<lval::SymbolVal>(this)->getSymbolID();
break;
- case LValueDeclKind:
+ case lval::DeclValKind:
Out << '&'
- << cast<LValueDecl>(this)->getDecl()->getIdentifier()->getName();
+ << cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName();
break;
default:
// Subclasses of NonLValue.
//==------------------------------------------------------------------------==//
-enum NonLValueKind { SymbolicNonLValueKind, ConcreteIntKind, NumNonLValueKind };
-
-class SymbolicNonLValue : public NonLValue {
-public:
- SymbolicNonLValue(unsigned SymID)
- : NonLValue(SymbolicNonLValueKind,
- reinterpret_cast<void*>((uintptr_t) SymID)) {}
-
- SymbolID getSymbolID() const {
- return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
- }
-
- static inline bool classof(const RValue* V) {
- return V->getSubKind() == SymbolicNonLValueKind;
- }
-};
-
-class ConcreteInt : public NonLValue {
-public:
- ConcreteInt(const llvm::APSInt& V) : NonLValue(ConcreteIntKind, &V) {}
-
- const llvm::APSInt& getValue() const {
- return *static_cast<llvm::APSInt*>(getRawPtr());
- }
-
- // Arithmetic operators.
-
- ConcreteInt Add(ValueManager& ValMgr, const ConcreteInt& V) const {
- return ValMgr.getValue(getValue() + V.getValue());
- }
-
- ConcreteInt Sub(ValueManager& ValMgr, const ConcreteInt& V) const {
- return ValMgr.getValue(getValue() - V.getValue());
- }
-
- ConcreteInt Mul(ValueManager& ValMgr, const ConcreteInt& V) const {
- return ValMgr.getValue(getValue() * V.getValue());
- }
-
- ConcreteInt Div(ValueManager& ValMgr, const ConcreteInt& V) const {
- return ValMgr.getValue(getValue() / V.getValue());
- }
-
- ConcreteInt Rem(ValueManager& ValMgr, const ConcreteInt& V) const {
- return ValMgr.getValue(getValue() % V.getValue());
- }
-
- ConcreteInt UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const {
- assert (U->getType() == U->getSubExpr()->getType());
- assert (U->getType()->isIntegerType());
- return ValMgr.getValue(-getValue());
- }
-
- ConcreteInt BitwiseComplement(ValueManager& ValMgr) const {
- return ValMgr.getValue(~getValue());
- }
-
- // Casting.
-
- ConcreteInt Cast(ValueManager& ValMgr, Expr* CastExpr) const {
- assert (CastExpr->getType()->isIntegerType());
+namespace nonlval {
+
+ enum Kind { SymbolValKind,
+ SymIntConstraintKind,
+ ConcreteIntKind,
+ NumKind };
+
+ class SymbolVal : public NonLValue {
+ public:
+ SymbolVal(unsigned SymID)
+ : NonLValue(SymbolValKind,
+ reinterpret_cast<void*>((uintptr_t) SymID)) {}
- llvm::APSInt X(getValue());
- X.extOrTrunc(ValMgr.getContext().getTypeSize(CastExpr->getType(),
- CastExpr->getLocStart()));
- return ValMgr.getValue(X);
- }
-
- // Equality operators.
-
- ConcreteInt EQ(ValueManager& ValMgr, const ConcreteInt& V) const {
- const llvm::APSInt& Val = getValue();
- return ValMgr.getValue(Val == V.getValue() ? 1U : 0U,
- Val.getBitWidth(), Val.isUnsigned());
- }
-
- ConcreteInt NE(ValueManager& ValMgr, const ConcreteInt& V) const {
- const llvm::APSInt& Val = getValue();
- return ValMgr.getValue(Val != V.getValue() ? 1U : 0U,
- Val.getBitWidth(), Val.isUnsigned());
- }
+ SymbolID getSymbolID() const {
+ return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
+ }
+
+ static inline bool classof(const RValue* V) {
+ return V->getSubKind() == SymbolValKind;
+ }
+ };
+
+ class ConcreteInt : public NonLValue {
+ public:
+ ConcreteInt(const llvm::APSInt& V) : NonLValue(ConcreteIntKind, &V) {}
+
+ const llvm::APSInt& getValue() const {
+ return *static_cast<llvm::APSInt*>(getRawPtr());
+ }
+
+ // Arithmetic operators.
+
+ ConcreteInt Add(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() + V.getValue());
+ }
+
+ ConcreteInt Sub(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() - V.getValue());
+ }
+
+ ConcreteInt Mul(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() * V.getValue());
+ }
+
+ ConcreteInt Div(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() / V.getValue());
+ }
+
+ ConcreteInt Rem(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() % V.getValue());
+ }
+
+ ConcreteInt UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const {
+ assert (U->getType() == U->getSubExpr()->getType());
+ assert (U->getType()->isIntegerType());
+ return ValMgr.getValue(-getValue());
+ }
+
+ ConcreteInt BitwiseComplement(ValueManager& ValMgr) const {
+ return ValMgr.getValue(~getValue());
+ }
+
+ // Casting.
+
+ ConcreteInt Cast(ValueManager& ValMgr, Expr* CastExpr) const {
+ assert (CastExpr->getType()->isIntegerType());
+
+ llvm::APSInt X(getValue());
+ X.extOrTrunc(ValMgr.getContext().getTypeSize(CastExpr->getType(),
+ CastExpr->getLocStart()));
+ return ValMgr.getValue(X);
+ }
+
+ // Equality operators.
+
+ ConcreteInt EQ(ValueManager& ValMgr, const ConcreteInt& V) const {
+ const llvm::APSInt& Val = getValue();
+ return ValMgr.getValue(Val == V.getValue() ? 1U : 0U,
+ Val.getBitWidth(), Val.isUnsigned());
+ }
+
+ ConcreteInt NE(ValueManager& ValMgr, const ConcreteInt& V) const {
+ const llvm::APSInt& Val = getValue();
+ return ValMgr.getValue(Val != V.getValue() ? 1U : 0U,
+ Val.getBitWidth(), Val.isUnsigned());
+ }
+
+ // Implement isa<T> support.
+ static inline bool classof(const RValue* V) {
+ return V->getSubKind() == ConcreteIntKind;
+ }
+ };
- // Implement isa<T> support.
- static inline bool classof(const RValue* V) {
- return V->getSubKind() == ConcreteIntKind;
- }
-};
+} // end namespace clang::nonlval
//==------------------------------------------------------------------------==//
// Subclasses of LValue.
//==------------------------------------------------------------------------==//
-enum LValueKind { SymbolicLValueKind, LValueDeclKind, ConcreteIntLValueKind,
- NumLValueKind };
-
-class SymbolicLValue : public LValue {
-public:
- SymbolicLValue(unsigned SymID)
- : LValue(SymbolicLValueKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
-
- SymbolID getSymbolID() const {
- return (SymbolID) reinterpret_cast<uintptr_t>(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<ValueDecl*>(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<T> 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<llvm::APSInt*>(getRawPtr());
- }
+namespace lval {
- // 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.
+ enum Kind { SymbolValKind,
+ DeclValKind,
+ ConcreteIntKind,
+ NumKind };
- 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());
- }
+ class SymbolVal : public LValue {
+ public:
+ SymbolVal(unsigned SymID)
+ : LValue(SymbolValKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
+
+ SymbolID getSymbolID() const {
+ return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
+ }
+
+ static inline bool classof(const RValue* V) {
+ return V->getSubKind() == SymbolValKind;
+ }
+ };
+
+ class DeclVal : public LValue {
+ public:
+ DeclVal(const ValueDecl* vd) : LValue(DeclValKind,vd) {}
+
+ ValueDecl* getDecl() const {
+ return static_cast<ValueDecl*>(getRawPtr());
+ }
+
+ inline bool operator==(const DeclVal& R) const {
+ return getDecl() == R.getDecl();
+ }
+
+ inline bool operator!=(const DeclVal& R) const {
+ return getDecl() != R.getDecl();
+ }
+
+ // Implement isa<T> support.
+ static inline bool classof(const RValue* V) {
+ return V->getSubKind() == DeclValKind;
+ }
+ };
+
+ class ConcreteInt : public LValue {
+ public:
+ ConcreteInt(const llvm::APSInt& V) : LValue(ConcreteIntKind, &V) {}
+
+ const llvm::APSInt& getValue() const {
+ return *static_cast<llvm::APSInt*>(getRawPtr());
+ }
+
+ // Arithmetic operators.
+
+ ConcreteInt Add(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() + V.getValue());
+ }
+
+ ConcreteInt Sub(ValueManager& ValMgr, const ConcreteInt& V) const {
+ return ValMgr.getValue(getValue() - V.getValue());
+ }
+
+ // Equality operators.
+
+ ConcreteInt EQ(ValueManager& ValMgr, const ConcreteInt& V) const {
+ const llvm::APSInt& Val = getValue();
+ return ValMgr.getValue(Val == V.getValue() ? 1U : 0U,
+ Val.getBitWidth(), Val.isUnsigned());
+ }
+
+ ConcreteInt NE(ValueManager& ValMgr, const ConcreteInt& V) const {
+ const llvm::APSInt& Val = getValue();
+ return ValMgr.getValue(Val != V.getValue() ? 1U : 0U,
+ Val.getBitWidth(), Val.isUnsigned());
+ }
+
+ // Implement isa<T> support.
+ static inline bool classof(const RValue* V) {
+ return V->getSubKind() == ConcreteIntKind;
+ }
+ };
+} // end clang::lval namespace
- // Implement isa<T> support.
- static inline bool classof(const RValue* V) {
- return V->getSubKind() == ConcreteIntLValueKind;
- }
-};
} // end clang namespace