namespace clang {
class EnvironmentManager;
+class BasicValueFactory;
class Environment : public llvm::FoldingSetNode {
private:
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) {
/// 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 {
Environment getInitialEnvironment() {
return Environment(F.GetEmptyMap(), F.GetEmptyMap());
}
+
+ Environment SetRVal(const Environment& Env, Expr* E, RVal V,
+ bool isBlkExpr, bool Invalidate);
};
} // end clang namespace
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);
+ }
- ValueState* SetRVal(ValueState* St, LVal LV, RVal V);
+ 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, Expr* E);
RVal GetRVal(ValueState* St, LVal LV, QualType T = QualType());
- RVal GetBlkExprRVal(ValueState* St, Expr* Ex);
-
+ ValueState* SetRVal(ValueState* St, LVal LV, RVal V);
+
void BindVar(ValueState& StImpl, VarDecl* D, RVal V);
void Unbind(ValueState& StImpl, LVal LV);
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.
-//===----------------------------------------------------------------------===//
\ No newline at end of file
+ return isBlkExpr ? AddBlkExpr(Env, E, V) : AddSubExpr(Env, E, V);
+}
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) {