[cfe-commits] r46778 - in /cfe/trunk/Analysis: RValues.cpp RValues.h
Ted Kremenek
kremenek at apple.com
Tue Feb 5 15:08:42 PST 2008
Author: kremenek
Date: Tue Feb 5 17:08:41 2008
New Revision: 46778
URL: http://llvm.org/viewvc/llvm-project?rev=46778&view=rev
Log:
Added pretty-printing support for lval::SymIntConstraintVal and
nonlval::SymIntConstraintVal.
Reworked transfer function for '==' and '!=' for LValues to return
SymIntConstraintVal when comparing a symbol with a constant.
Modified:
cfe/trunk/Analysis/RValues.cpp
cfe/trunk/Analysis/RValues.h
Modified: cfe/trunk/Analysis/RValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.cpp?rev=46778&r1=46777&r2=46778&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.cpp (original)
+++ cfe/trunk/Analysis/RValues.cpp Tue Feb 5 17:08:41 2008
@@ -223,49 +223,109 @@
NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const {
- if (getSubKind() != RHS.getSubKind())
- return NonLValue::GetIntTruthValue(ValMgr, false);
-
switch (getSubKind()) {
default:
assert(false && "EQ not implemented for this LValue.");
return cast<NonLValue>(InvalidValue());
- case lval::ConcreteIntKind: {
- bool b = cast<lval::ConcreteInt>(this)->getValue() ==
- cast<lval::ConcreteInt>(RHS).getValue();
-
- return NonLValue::GetIntTruthValue(ValMgr, b);
- }
+ case lval::ConcreteIntKind:
+ if (isa<lval::ConcreteInt>(RHS)) {
+ bool b = cast<lval::ConcreteInt>(this)->getValue() ==
+ cast<lval::ConcreteInt>(RHS).getValue();
+
+ return NonLValue::GetIntTruthValue(ValMgr, b);
+ }
+ else if (isa<lval::SymbolVal>(RHS)) {
+
+ const SymIntConstraint& C =
+ ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(),
+ BinaryOperator::EQ,
+ cast<lval::ConcreteInt>(this)->getValue());
+
+ return nonlval::SymIntConstraintVal(C);
+ }
+
+ break;
+
+ case lval::SymbolValKind: {
+ if (isa<lval::ConcreteInt>(RHS)) {
+
+ const SymIntConstraint& C =
+ ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
+ BinaryOperator::EQ,
+ cast<lval::ConcreteInt>(RHS).getValue());
+
+ return nonlval::SymIntConstraintVal(C);
+ }
+
+ assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement unification.");
- case lval::DeclValKind: {
- bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS);
- return NonLValue::GetIntTruthValue(ValMgr, b);
+ break;
}
+
+ case lval::DeclValKind:
+ if (isa<lval::DeclVal>(RHS)) {
+ bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS);
+ return NonLValue::GetIntTruthValue(ValMgr, b);
+ }
+
+ break;
}
+
+ return NonLValue::GetIntTruthValue(ValMgr, false);
}
NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const {
- if (getSubKind() != RHS.getSubKind())
- return NonLValue::GetIntTruthValue(ValMgr, true);
-
switch (getSubKind()) {
default:
- assert(false && "EQ not implemented for this LValue.");
+ assert(false && "NE not implemented for this LValue.");
return cast<NonLValue>(InvalidValue());
- case lval::ConcreteIntKind: {
- bool b = cast<lval::ConcreteInt>(this)->getValue() !=
- cast<lval::ConcreteInt>(RHS).getValue();
+ case lval::ConcreteIntKind:
+ if (isa<lval::ConcreteInt>(RHS)) {
+ bool b = cast<lval::ConcreteInt>(this)->getValue() !=
+ cast<lval::ConcreteInt>(RHS).getValue();
+
+ return NonLValue::GetIntTruthValue(ValMgr, b);
+ }
+ else if (isa<lval::SymbolVal>(RHS)) {
+
+ const SymIntConstraint& C =
+ ValMgr.getConstraint(cast<lval::SymbolVal>(RHS).getSymbol(),
+ BinaryOperator::NE,
+ cast<lval::ConcreteInt>(this)->getValue());
+
+ return nonlval::SymIntConstraintVal(C);
+ }
- return NonLValue::GetIntTruthValue(ValMgr, b);
- }
+ break;
- case lval::DeclValKind: {
- bool b = cast<lval::DeclVal>(*this) != cast<lval::DeclVal>(RHS);
- return NonLValue::GetIntTruthValue(ValMgr, b);
- }
+ case lval::SymbolValKind: {
+ if (isa<lval::ConcreteInt>(RHS)) {
+
+ const SymIntConstraint& C =
+ ValMgr.getConstraint(cast<lval::SymbolVal>(this)->getSymbol(),
+ BinaryOperator::NE,
+ cast<lval::ConcreteInt>(RHS).getValue());
+
+ return nonlval::SymIntConstraintVal(C);
+ }
+
+ assert (!isa<lval::SymbolVal>(RHS) && "FIXME: Implement sym !=.");
+
+ break;
+ }
+
+ case lval::DeclValKind:
+ if (isa<lval::DeclVal>(RHS)) {
+ bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(RHS);
+ return NonLValue::GetIntTruthValue(ValMgr, b);
+ }
+
+ break;
}
+
+ return NonLValue::GetIntTruthValue(ValMgr, true);
}
@@ -320,6 +380,14 @@
}
}
+static void printOpcode(std::ostream& Out, BinaryOperator::Opcode Op) {
+ switch (Op) {
+ case BinaryOperator::EQ: Out << "=="; break;
+ case BinaryOperator::NE: Out << "!="; break;
+ default: assert(false && "Not yet implemented.");
+ }
+}
+
void NonLValue::print(std::ostream& Out) const {
switch (getSubKind()) {
case nonlval::ConcreteIntKind:
@@ -327,8 +395,18 @@
break;
case nonlval::SymbolValKind:
- Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbolID();
+ Out << '$' << cast<nonlval::SymbolVal>(this)->getSymbol();
break;
+
+ case nonlval::SymIntConstraintValKind: {
+ const nonlval::SymIntConstraintVal& C =
+ *cast<nonlval::SymIntConstraintVal>(this);
+
+ Out << '$' << C.getConstraint().getSymbol() << ' ';
+ printOpcode(Out, C.getConstraint().getOpcode());
+ Out << ' ' << C.getConstraint().getInt().toString();
+ break;
+ }
default:
assert (false && "Pretty-printed not implemented for this NonLValue.");
@@ -336,6 +414,7 @@
}
}
+
void LValue::print(std::ostream& Out) const {
switch (getSubKind()) {
case lval::ConcreteIntKind:
@@ -344,9 +423,19 @@
break;
case lval::SymbolValKind:
- Out << '$' << cast<lval::SymbolVal>(this)->getSymbolID();
+ Out << '$' << cast<lval::SymbolVal>(this)->getSymbol();
break;
+ case lval::SymIntConstraintValKind: {
+ const lval::SymIntConstraintVal& C =
+ *cast<lval::SymIntConstraintVal>(this);
+
+ Out << '$' << C.getConstraint().getSymbol() << ' ';
+ printOpcode(Out, C.getConstraint().getOpcode());
+ Out << ' ' << C.getConstraint().getInt().toString();
+ break;
+ }
+
case lval::DeclValKind:
Out << '&'
<< cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName();
Modified: cfe/trunk/Analysis/RValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.h?rev=46778&r1=46777&r2=46778&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.h (original)
+++ cfe/trunk/Analysis/RValues.h Tue Feb 5 17:08:41 2008
@@ -339,7 +339,7 @@
: NonLValue(SymbolValKind,
reinterpret_cast<void*>((uintptr_t) SymID)) {}
- SymbolID getSymbolID() const {
+ SymbolID getSymbol() const {
return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
}
@@ -442,6 +442,7 @@
namespace lval {
enum Kind { SymbolValKind,
+ SymIntConstraintValKind,
DeclValKind,
ConcreteIntKind,
NumKind };
@@ -451,7 +452,7 @@
SymbolVal(unsigned SymID)
: LValue(SymbolValKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
- SymbolID getSymbolID() const {
+ SymbolID getSymbol() const {
return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
}
@@ -459,6 +460,20 @@
return V->getSubKind() == SymbolValKind;
}
};
+
+ class SymIntConstraintVal : public LValue {
+ public:
+ SymIntConstraintVal(const SymIntConstraint& C)
+ : LValue(SymIntConstraintValKind, reinterpret_cast<const void*>(&C)) {}
+
+ const SymIntConstraint& getConstraint() const {
+ return *reinterpret_cast<SymIntConstraint*>(getRawPtr());
+ }
+
+ static inline bool classof(const RValue* V) {
+ return isa<LValue>(V) && V->getSubKind() == SymIntConstraintValKind;
+ }
+ };
class DeclVal : public LValue {
public:
More information about the cfe-commits
mailing list