From: Ted Kremenek Date: Tue, 5 Feb 2008 21:52:21 +0000 (+0000) Subject: Moved subclasses of LValue and NonLValue into their own namespaces. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=329f854f217d72594a3ec5572eba6320f81a5efa;p=clang Moved subclasses of LValue and NonLValue into their own namespaces. This noticeably cleans up the naming of these classes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46770 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 69defc8cad..d841eec801 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -154,7 +154,7 @@ public: for (FunctionDecl::param_iterator I=F.param_begin(), E=F.param_end(); I!=E; ++I) - St = SetValue(St, LValueDecl(*I), RValue::GetSymbolValue(SymMgr, *I)); + St = SetValue(St, lval::DeclVal(*I), RValue::GetSymbolValue(SymMgr, *I)); return St; } @@ -540,7 +540,7 @@ void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred, for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator()) if (const VarDecl* VD = dyn_cast(D)) { const Expr* E = VD->getInit(); - St = SetValue(St, LValueDecl(VD), + St = SetValue(St, lval::DeclVal(VD), E ? GetValue(St, E) : UninitializedValue()); } @@ -859,12 +859,12 @@ GRConstants::StateTy GRConstants::Assume(StateTy St, LValue Cond, bool Assumptio assert (false && "'Assume' not implemented for this NonLValue."); return St; - case LValueDeclKind: + case lval::DeclValKind: isFeasible = Assumption; return St; - case ConcreteIntLValueKind: { - bool b = cast(Cond).getValue() != 0; + case lval::ConcreteIntKind: { + bool b = cast(Cond).getValue() != 0; isFeasible = b ? Assumption : !Assumption; return St; } @@ -879,8 +879,8 @@ GRConstants::StateTy GRConstants::Assume(StateTy St, NonLValue Cond, bool Assump assert (false && "'Assume' not implemented for this NonLValue."); return St; - case ConcreteIntKind: { - bool b = cast(Cond).getValue() != 0; + case nonlval::ConcreteIntKind: { + bool b = cast(Cond).getValue() != 0; isFeasible = b ? Assumption : !Assumption; return St; } diff --git a/Analysis/RValues.cpp b/Analysis/RValues.cpp index 8861f576f3..c5c5bdeaa8 100644 --- a/Analysis/RValues.cpp +++ b/Analysis/RValues.cpp @@ -122,29 +122,29 @@ RValue LValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { assert (CastExpr->getType()->isIntegerType()); - if (!isa(*this)) + if (!isa(*this)) return InvalidValue(); - APSInt V = cast(this)->getValue(); + APSInt V = cast(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(this)) + if (!isa(this)) return InvalidValue(); - APSInt V = cast(this)->getValue(); + APSInt V = cast(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)); } //===----------------------------------------------------------------------===// @@ -153,8 +153,8 @@ RValue NonLValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const { switch (getSubKind()) { - case ConcreteIntKind: - return cast(this)->UnaryMinus(ValMgr, U); + case nonlval::ConcreteIntKind: + return cast(this)->UnaryMinus(ValMgr, U); default: return cast(InvalidValue()); } @@ -162,8 +162,8 @@ NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const { NonLValue NonLValue::BitwiseComplement(ValueManager& ValMgr) const { switch (getSubKind()) { - case ConcreteIntKind: - return cast(this)->BitwiseComplement(ValMgr); + case nonlval::ConcreteIntKind: + return cast(this)->BitwiseComplement(ValMgr); default: return cast(InvalidValue()); } @@ -171,12 +171,12 @@ NonLValue NonLValue::BitwiseComplement(ValueManager& ValMgr) const { #define NONLVALUE_DISPATCH_CASE(k1,k2,Op)\ -case (k1##Kind*NumNonLValueKind+k2##Kind):\ +case (k1##Kind*nonlval::NumKind+k2##Kind):\ return cast(*this).Op(ValMgr,cast(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)\ @@ -231,15 +231,15 @@ NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const { assert(false && "EQ not implemented for this LValue."); return cast(InvalidValue()); - case ConcreteIntLValueKind: { - bool b = cast(this)->getValue() == - cast(RHS).getValue(); + case lval::ConcreteIntKind: { + bool b = cast(this)->getValue() == + cast(RHS).getValue(); return NonLValue::GetIntTruthValue(ValMgr, b); } - case LValueDeclKind: { - bool b = cast(*this) == cast(RHS); + case lval::DeclValKind: { + bool b = cast(*this) == cast(RHS); return NonLValue::GetIntTruthValue(ValMgr, b); } } @@ -254,15 +254,15 @@ NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const { assert(false && "EQ not implemented for this LValue."); return cast(InvalidValue()); - case ConcreteIntLValueKind: { - bool b = cast(this)->getValue() != - cast(RHS).getValue(); + case lval::ConcreteIntKind: { + bool b = cast(this)->getValue() != + cast(RHS).getValue(); return NonLValue::GetIntTruthValue(ValMgr, b); } - case LValueDeclKind: { - bool b = cast(*this) != cast(RHS); + case lval::DeclValKind: { + bool b = cast(*this) != cast(RHS); return NonLValue::GetIntTruthValue(ValMgr, b); } } @@ -276,21 +276,21 @@ NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const { 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)); } //===----------------------------------------------------------------------===// @@ -322,12 +322,12 @@ void RValue::print(std::ostream& Out) const { void NonLValue::print(std::ostream& Out) const { switch (getSubKind()) { - case ConcreteIntKind: - Out << cast(this)->getValue().toString(); + case nonlval::ConcreteIntKind: + Out << cast(this)->getValue().toString(); break; - case SymbolicNonLValueKind: - Out << '$' << cast(this)->getSymbolID(); + case nonlval::SymbolValKind: + Out << '$' << cast(this)->getSymbolID(); break; default: @@ -338,18 +338,18 @@ void NonLValue::print(std::ostream& Out) const { void LValue::print(std::ostream& Out) const { switch (getSubKind()) { - case ConcreteIntLValueKind: - Out << cast(this)->getValue().toString() + case lval::ConcreteIntKind: + Out << cast(this)->getValue().toString() << " (LValue)"; break; - case SymbolicLValueKind: - Out << '$' << cast(this)->getSymbolID(); + case lval::SymbolValKind: + Out << '$' << cast(this)->getSymbolID(); break; - case LValueDeclKind: + case lval::DeclValKind: Out << '&' - << cast(this)->getDecl()->getIdentifier()->getName(); + << cast(this)->getDecl()->getIdentifier()->getName(); break; default: diff --git a/Analysis/RValues.h b/Analysis/RValues.h index 6980a9bba4..05ac663dd5 100644 --- a/Analysis/RValues.h +++ b/Analysis/RValues.h @@ -298,174 +298,187 @@ public: // Subclasses of NonLValue. //==------------------------------------------------------------------------==// -enum NonLValueKind { SymbolicNonLValueKind, ConcreteIntKind, NumNonLValueKind }; - -class SymbolicNonLValue : public NonLValue { -public: - SymbolicNonLValue(unsigned SymID) - : NonLValue(SymbolicNonLValueKind, - reinterpret_cast((uintptr_t) SymID)) {} - - SymbolID getSymbolID() const { - return (SymbolID) reinterpret_cast(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(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((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(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(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 support. + static inline bool classof(const RValue* V) { + return V->getSubKind() == ConcreteIntKind; + } + }; - // Implement isa 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((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()); - } +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((uintptr_t) SymID)) {} + + SymbolID getSymbolID() const { + return (SymbolID) reinterpret_cast(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(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 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(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 support. + static inline bool classof(const RValue* V) { + return V->getSubKind() == ConcreteIntKind; + } + }; +} // end clang::lval namespace - // Implement isa support. - static inline bool classof(const RValue* V) { - return V->getSubKind() == ConcreteIntLValueKind; - } -}; } // end clang namespace diff --git a/Analysis/ValueState.cpp b/Analysis/ValueState.cpp index 9bd02a29bd..aa6ddbdd53 100644 --- a/Analysis/ValueState.cpp +++ b/Analysis/ValueState.cpp @@ -17,9 +17,9 @@ using namespace clang; RValue ValueStateManager::GetValue(const StateTy& St, const LValue& LV) { switch (LV.getSubKind()) { - case LValueDeclKind: { + case lval::DeclValKind: { StateTy::VariableBindingsTy::TreeTy* T = - St.getImpl()->VariableBindings.SlimFind(cast(LV).getDecl()); + St.getImpl()->VariableBindings.SlimFind(cast(LV).getDecl()); return T ? T->getValue().second : InvalidValue(); } @@ -47,7 +47,7 @@ RValue ValueStateManager::GetValue(const StateTy& St, Stmt* S, bool* hasVal) { // within the referenced variables. case Stmt::DeclRefExprClass: - return GetValue(St, LValueDecl(cast(S)->getDecl())); + return GetValue(St, lval::DeclVal(cast(S)->getDecl())); // Integer literals evaluate to an RValue. Simply retrieve the // RValue for the literal. @@ -105,7 +105,7 @@ LValue ValueStateManager::GetLValue(const StateTy& St, Stmt* S) { S = P->getSubExpr(); if (DeclRefExpr* DR = dyn_cast(S)) - return LValueDecl(DR->getDecl()); + return lval::DeclVal(DR->getDecl()); return cast(GetValue(St, S)); } @@ -123,9 +123,9 @@ ValueStateManager::StateTy ValueStateManager::SetValue(StateTy St, const LValue& LV, const RValue& V) { switch (LV.getSubKind()) { - case LValueDeclKind: - return V.isValid() ? Add(St, cast(LV).getDecl(), V) - : Remove(St, cast(LV).getDecl()); + case lval::DeclValKind: + return V.isValid() ? Add(St, cast(LV).getDecl(), V) + : Remove(St, cast(LV).getDecl()); default: assert ("SetValue for given LValue type not yet implemented.");