Move some environment methods from ValueState/ValueStateManager to Environment/EnvironmentManager.

llvm-svn: 53412
This commit is contained in:
Ted Kremenek 2008-07-10 17:19:18 +00:00
parent 60de1ae3d9
commit ad4a7e4a69
4 changed files with 135 additions and 135 deletions

View File

@ -22,6 +22,7 @@
namespace clang {
class EnvironmentManager;
class BasicValueFactory;
class Environment : public llvm::FoldingSetNode {
private:
@ -65,6 +66,9 @@ public:
return X ? *X : UnknownVal();
}
RVal GetRVal(Expr* Ex, BasicValueFactory& BasicVals) const;
RVal GetBlkExprRVal(Expr* Ex, BasicValueFactory& BasicVals) const;
/// Profile - Profile the contents of an Environment object for use
/// in a FoldingSet.
static void Profile(llvm::FoldingSetNodeID& ID, const Environment* E) {
@ -76,7 +80,12 @@ public:
/// in a FoldingSet.
void Profile(llvm::FoldingSetNodeID& ID) const {
Profile(ID, this);
}
}
bool operator==(const Environment& RHS) const {
return SubExprBindings == RHS.SubExprBindings &&
BlkExprBindings == RHS.BlkExprBindings;
}
};
class EnvironmentManager {
@ -120,6 +129,9 @@ public:
Environment getInitialEnvironment() {
return Environment(F.GetEmptyMap(), F.GetEmptyMap());
}
Environment SetRVal(const Environment& Env, Expr* E, RVal V,
bool isBlkExpr, bool Invalidate);
};
} // end clang namespace

View File

@ -235,17 +235,37 @@ public:
NewSt.Env = EnvMgr.RemoveSubExprBindings(NewSt.Env);
return getPersistentState(NewSt);
}
// Methods that query & manipulate the Environment.
ValueState* SetRVal(ValueState* St, Expr* E, RVal V, bool isBlkExpr,
bool Invalidate);
RVal GetRVal(ValueState* St, Expr* Ex) {
return St->getEnvironment().GetRVal(Ex, BasicVals);
}
RVal GetBlkExprRVal(ValueState* St, Expr* Ex) {
return St->getEnvironment().GetBlkExprRVal(Ex, BasicVals);
}
ValueState* SetRVal(ValueState* St, Expr* Ex, RVal V, bool isBlkExpr,
bool Invalidate) {
const Environment& OldEnv = St->getEnvironment();
Environment NewEnv = EnvMgr.SetRVal(OldEnv, Ex, V, isBlkExpr, Invalidate);
if (NewEnv == OldEnv)
return St;
ValueState NewSt = *St;
NewSt.Env = NewEnv;
return getPersistentState(NewSt);
}
// Methods that query & manipulate the Store.
RVal GetRVal(ValueState* St, LVal LV, QualType T = QualType());
ValueState* SetRVal(ValueState* St, LVal LV, RVal V);
RVal GetRVal(ValueState* St, Expr* E);
RVal GetRVal(ValueState* St, LVal LV, QualType T = QualType());
RVal GetBlkExprRVal(ValueState* St, Expr* Ex);
void BindVar(ValueState& StImpl, VarDecl* D, RVal V);
void Unbind(ValueState& StImpl, LVal LV);

View File

@ -16,14 +16,101 @@
using namespace clang;
//===----------------------------------------------------------------------===//
// Environment.
//===----------------------------------------------------------------------===//
RVal Environment::GetRVal(Expr* E, BasicValueFactory& BasicVals) const {
for (;;) {
switch (E->getStmtClass()) {
case Stmt::AddrLabelExprClass:
return LVal::MakeVal(cast<AddrLabelExpr>(E));
// ParenExprs are no-ops.
case Stmt::ParenExprClass:
E = cast<ParenExpr>(E)->getSubExpr();
continue;
case Stmt::CharacterLiteralClass: {
CharacterLiteral* C = cast<CharacterLiteral>(E);
return NonLVal::MakeVal(BasicVals, C->getValue(), C->getType());
}
case Stmt::IntegerLiteralClass: {
return NonLVal::MakeVal(BasicVals, cast<IntegerLiteral>(E));
}
case Stmt::StringLiteralClass:
return LVal::MakeVal(cast<StringLiteral>(E));
// Casts where the source and target type are the same
// are no-ops. We blast through these to get the descendant
// subexpression that has a value.
case Stmt::ImplicitCastExprClass: {
ImplicitCastExpr* C = cast<ImplicitCastExpr>(E);
QualType CT = C->getType();
if (CT->isVoidType())
return UnknownVal();
QualType ST = C->getSubExpr()->getType();
break;
}
case Stmt::CastExprClass: {
CastExpr* C = cast<CastExpr>(E);
QualType CT = C->getType();
QualType ST = C->getSubExpr()->getType();
if (CT->isVoidType())
return UnknownVal();
break;
}
// Handle all other Expr* using a lookup.
default:
break;
};
break;
}
return LookupExpr(E);
}
RVal Environment::GetBlkExprRVal(Expr* E, BasicValueFactory& BasicVals) const {
E = E->IgnoreParens();
switch (E->getStmtClass()) {
case Stmt::CharacterLiteralClass: {
CharacterLiteral* C = cast<CharacterLiteral>(E);
return NonLVal::MakeVal(BasicVals, C->getValue(), C->getType());
}
case Stmt::IntegerLiteralClass: {
return NonLVal::MakeVal(BasicVals, cast<IntegerLiteral>(E));
}
default:
return LookupBlkExpr(E);
}
}
Environment EnvironmentManager::SetRVal(const Environment& Env, Expr* E, RVal V,
bool isBlkExpr, bool Invalidate) {
assert (E);
if (V.isUnknown()) {
if (Invalidate)
return isBlkExpr ? RemoveBlkExpr(Env, E) : RemoveSubExpr(Env, E);
else
return Env;
}
//===----------------------------------------------------------------------===//
// Environment Manager.
//===----------------------------------------------------------------------===//
return isBlkExpr ? AddBlkExpr(Env, E, V) : AddSubExpr(Env, E, V);
}

View File

@ -258,125 +258,6 @@ ValueState* ValueStateManager::AddEQ(ValueState* St, SymbolID sym,
return getPersistentState(NewSt);
}
// FIXME: This should all go into the environment.
RVal ValueStateManager::GetRVal(ValueState* St, Expr* E) {
for (;;) {
switch (E->getStmtClass()) {
case Stmt::AddrLabelExprClass:
return LVal::MakeVal(cast<AddrLabelExpr>(E));
// ParenExprs are no-ops.
case Stmt::ParenExprClass:
E = cast<ParenExpr>(E)->getSubExpr();
continue;
case Stmt::CharacterLiteralClass: {
CharacterLiteral* C = cast<CharacterLiteral>(E);
return NonLVal::MakeVal(BasicVals, C->getValue(), C->getType());
}
case Stmt::IntegerLiteralClass: {
return NonLVal::MakeVal(BasicVals, cast<IntegerLiteral>(E));
}
case Stmt::StringLiteralClass:
return LVal::MakeVal(cast<StringLiteral>(E));
// Casts where the source and target type are the same
// are no-ops. We blast through these to get the descendant
// subexpression that has a value.
case Stmt::ImplicitCastExprClass: {
ImplicitCastExpr* C = cast<ImplicitCastExpr>(E);
QualType CT = C->getType();
if (CT->isVoidType())
return UnknownVal();
QualType ST = C->getSubExpr()->getType();
break;
}
case Stmt::CastExprClass: {
CastExpr* C = cast<CastExpr>(E);
QualType CT = C->getType();
QualType ST = C->getSubExpr()->getType();
if (CT->isVoidType())
return UnknownVal();
break;
}
// Handle all other Expr* using a lookup.
default:
break;
};
break;
}
return St->LookupExpr(E);
}
RVal ValueStateManager::GetBlkExprRVal(ValueState* St, Expr* E) {
E = E->IgnoreParens();
switch (E->getStmtClass()) {
case Stmt::CharacterLiteralClass: {
CharacterLiteral* C = cast<CharacterLiteral>(E);
return NonLVal::MakeVal(BasicVals, C->getValue(), C->getType());
}
case Stmt::IntegerLiteralClass: {
return NonLVal::MakeVal(BasicVals, cast<IntegerLiteral>(E));
}
default:
return St->getEnvironment().LookupBlkExpr(E);
}
}
ValueState*
ValueStateManager::SetRVal(ValueState* St, Expr* E, RVal V,
bool isBlkExpr, bool Invalidate) {
assert (E);
if (V.isUnknown()) {
if (Invalidate) {
ValueState NewSt = *St;
if (isBlkExpr)
NewSt.Env = EnvMgr.RemoveBlkExpr(NewSt.Env, E);
else
NewSt.Env = EnvMgr.RemoveSubExpr(NewSt.Env, E);
return getPersistentState(NewSt);
}
return St;
}
ValueState NewSt = *St;
if (isBlkExpr)
NewSt.Env = EnvMgr.AddBlkExpr(NewSt.Env, E, V);
else
NewSt.Env = EnvMgr.AddSubExpr(NewSt.Env, E, V);
return getPersistentState(NewSt);
}
ValueState* ValueStateManager::SetRVal(ValueState* St, LVal LV, RVal V) {