diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-02-08 20:29:23 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-02-08 20:29:23 +0000 |
commit | d70b62e6ecfb9cbfe05336218488f11eabf8e80d (patch) | |
tree | 411bca10f237eec498f33e176c03cae03cbadf79 | |
parent | c0959fc20d40fbe0c44a88eb1d7fc9395a163840 (diff) |
Changed "GetValue" methods to take an
Expr* instead of a Stmt*, since we only
store bindings for Expr*.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46891 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Analysis/GRConstants.cpp | 67 | ||||
-rw-r--r-- | Analysis/ValueState.cpp | 14 | ||||
-rw-r--r-- | Analysis/ValueState.h | 56 |
3 files changed, 72 insertions, 65 deletions
diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 8a06b725b9..cc8f75cf6f 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -200,30 +200,30 @@ public: return StateMgr.RemoveDeadBindings(St, S, Liveness); } - StateTy SetValue(StateTy St, Stmt* S, const RValue& V); + StateTy SetValue(StateTy St, Expr* S, const RValue& V); - StateTy SetValue(StateTy St, const Stmt* S, const RValue& V) { - return SetValue(St, const_cast<Stmt*>(S), V); + StateTy SetValue(StateTy St, const Expr* S, const RValue& V) { + return SetValue(St, const_cast<Expr*>(S), V); } /// SetValue - This version of SetValue is used to batch process a set /// of different possible RValues and return a set of different states. - const StateTy::BufferTy& SetValue(StateTy St, Stmt* S, + const StateTy::BufferTy& SetValue(StateTy St, Expr* S, const RValue::BufferTy& V, StateTy::BufferTy& RetBuf); StateTy SetValue(StateTy St, const LValue& LV, const RValue& V); - inline RValue GetValue(const StateTy& St, Stmt* S) { + inline RValue GetValue(const StateTy& St, Expr* S) { return StateMgr.GetValue(St, S); } - inline RValue GetValue(const StateTy& St, Stmt* S, bool& hasVal) { + inline RValue GetValue(const StateTy& St, Expr* S, bool& hasVal) { return StateMgr.GetValue(St, S, &hasVal); } - inline RValue GetValue(const StateTy& St, const Stmt* S) { - return GetValue(St, const_cast<Stmt*>(S)); + inline RValue GetValue(const StateTy& St, const Expr* S) { + return GetValue(St, const_cast<Expr*>(S)); } inline RValue GetValue(const StateTy& St, const LValue& LV, @@ -232,7 +232,7 @@ public: return StateMgr.GetValue(St, LV, T); } - inline LValue GetLValue(const StateTy& St, Stmt* S) { + inline LValue GetLValue(const StateTy& St, Expr* S) { return StateMgr.GetLValue(St, S); } @@ -290,7 +290,7 @@ public: void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst); /// VisitGuardedExpr - Transfer function logic for ?, __builtin_choose - void VisitGuardedExpr(Stmt* S, Stmt* LHS, Stmt* RHS, + void VisitGuardedExpr(Expr* S, Expr* LHS, Expr* RHS, NodeTy* Pred, NodeSet& Dst); /// VisitLogicalExpr - Transfer function logic for '&&', '||' @@ -300,7 +300,7 @@ public: GRConstants::StateTy -GRConstants::SetValue(StateTy St, Stmt* S, const RValue& V) { +GRConstants::SetValue(StateTy St, Expr* S, const RValue& V) { if (!StateCleaned) { St = RemoveDeadBindings(CurrentStmt, St); @@ -320,7 +320,7 @@ GRConstants::SetValue(StateTy St, Stmt* S, const RValue& V) { } const GRConstants::StateTy::BufferTy& -GRConstants::SetValue(StateTy St, Stmt* S, const RValue::BufferTy& RB, +GRConstants::SetValue(StateTy St, Expr* S, const RValue::BufferTy& RB, StateTy::BufferTy& RetBuf) { assert (RetBuf.empty()); @@ -585,7 +585,7 @@ void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred, } -void GRConstants::VisitGuardedExpr(Stmt* S, Stmt* LHS, Stmt* RHS, +void GRConstants::VisitGuardedExpr(Expr* S, Expr* LHS, Expr* RHS, NodeTy* Pred, NodeSet& Dst) { StateTy St = Pred->getState(); @@ -886,18 +886,19 @@ void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred, } switch (S->getStmtClass()) { - case Stmt::BinaryOperatorClass: + case Stmt::BinaryOperatorClass: { + BinaryOperator* B = cast<BinaryOperator>(S); - if (cast<BinaryOperator>(S)->isLogicalOp()) { - VisitLogicalExpr(cast<BinaryOperator>(S), Pred, Dst); + if (B->isLogicalOp()) { + VisitLogicalExpr(B, Pred, Dst); break; } - else if (cast<BinaryOperator>(S)->getOpcode() == BinaryOperator::Comma) { + else if (B->getOpcode() == BinaryOperator::Comma) { StateTy St = Pred->getState(); - Stmt* LastStmt = cast<BinaryOperator>(S)->getRHS(); - Nodify(Dst, S, Pred, SetValue(St, S, GetValue(St, LastStmt))); + Nodify(Dst, B, Pred, SetValue(St, B, GetValue(St, B->getRHS()))); break; } + } // Fall-through. @@ -906,9 +907,11 @@ void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred, break; case Stmt::StmtExprClass: { + StmtExpr* SE = cast<StmtExpr>(S); + StateTy St = Pred->getState(); - Stmt* LastStmt = *(cast<StmtExpr>(S)->getSubStmt()->body_rbegin()); - Nodify(Dst, S, Pred, SetValue(St, S, GetValue(St, LastStmt))); + Expr* LastExpr = cast<Expr>(*SE->getSubStmt()->body_rbegin()); + Nodify(Dst, SE, Pred, SetValue(St, SE, GetValue(St, LastExpr))); break; } @@ -938,13 +941,13 @@ void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred, case Stmt::ConditionalOperatorClass: { // '?' operator ConditionalOperator* C = cast<ConditionalOperator>(S); - VisitGuardedExpr(S, C->getLHS(), C->getRHS(), Pred, Dst); + VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst); break; } case Stmt::ChooseExprClass: { // __builtin_choose_expr ChooseExpr* C = cast<ChooseExpr>(S); - VisitGuardedExpr(S, C->getLHS(), C->getRHS(), Pred, Dst); + VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst); break; } @@ -1117,17 +1120,17 @@ template<> struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> : public DefaultDOTGraphTraits { - static void PrintKindLabel(std::ostream& Out, VarBindKey::Kind kind) { + static void PrintKindLabel(std::ostream& Out, ExprBindKey::Kind kind) { switch (kind) { - case VarBindKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break; - case VarBindKey::IsDecl: Out << "Variables:\\l"; break; - case VarBindKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break; - default: assert (false && "Unknown VarBindKey type."); + case ExprBindKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break; + case ExprBindKey::IsDecl: Out << "Variables:\\l"; break; + case ExprBindKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break; + default: assert (false && "Unknown ExprBindKey type."); } } static void PrintKind(std::ostream& Out, GRConstants::StateTy M, - VarBindKey::Kind kind, bool isFirstGroup = false) { + ExprBindKey::Kind kind, bool isFirstGroup = false) { bool isFirst = true; for (GRConstants::StateTy::vb_iterator I=M.begin(), E=M.end();I!=E;++I) { @@ -1258,9 +1261,9 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> : Out << "\\|StateID: " << (void*) N->getState().getImpl() << "\\|"; - PrintKind(Out, N->getState(), VarBindKey::IsDecl, true); - PrintKind(Out, N->getState(), VarBindKey::IsBlkExpr); - PrintKind(Out, N->getState(), VarBindKey::IsSubExpr); + PrintKind(Out, N->getState(), ExprBindKey::IsDecl, true); + PrintKind(Out, N->getState(), ExprBindKey::IsBlkExpr); + PrintKind(Out, N->getState(), ExprBindKey::IsSubExpr); PrintEQ(Out, N->getState()); PrintNE(Out, N->getState()); diff --git a/Analysis/ValueState.cpp b/Analysis/ValueState.cpp index 55451a959e..5f42e11e7a 100644 --- a/Analysis/ValueState.cpp +++ b/Analysis/ValueState.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This files defines SymbolID, VarBindKey, and ValueState. +// This files defines SymbolID, ExprBindKey, and ValueState. // //===----------------------------------------------------------------------===// @@ -167,7 +167,7 @@ ValueStateManager::AddEQ(StateTy St, SymbolID sym, const llvm::APSInt& V) { return getPersistentState(NewStateImpl); } -RValue ValueStateManager::GetValue(const StateTy& St, Stmt* S, bool* hasVal) { +RValue ValueStateManager::GetValue(const StateTy& St, Expr* S, bool* hasVal) { for (;;) { switch (S->getStmtClass()) { @@ -235,7 +235,7 @@ RValue ValueStateManager::GetValue(const StateTy& St, Stmt* S, bool* hasVal) { } } -LValue ValueStateManager::GetLValue(const StateTy& St, Stmt* S) { +LValue ValueStateManager::GetLValue(const StateTy& St, Expr* S) { while (ParenExpr* P = dyn_cast<ParenExpr>(S)) S = P->getSubExpr(); @@ -252,11 +252,11 @@ LValue ValueStateManager::GetLValue(const StateTy& St, Stmt* S) { ValueStateManager::StateTy -ValueStateManager::SetValue(StateTy St, Stmt* S, bool isBlkExpr, +ValueStateManager::SetValue(StateTy St, Expr* S, bool isBlkExpr, const RValue& V) { assert (S); - return V.isKnown() ? Add(St, VarBindKey(S, isBlkExpr), V) : St; + return V.isKnown() ? Add(St, ExprBindKey(S, isBlkExpr), V) : St; } ValueStateManager::StateTy @@ -274,7 +274,7 @@ ValueStateManager::SetValue(StateTy St, const LValue& LV, const RValue& V) { } ValueStateManager::StateTy -ValueStateManager::Remove(StateTy St, VarBindKey K) { +ValueStateManager::Remove(StateTy St, ExprBindKey K) { // Create a new state with the old binding removed. ValueStateImpl NewStateImpl = *St.getImpl(); @@ -286,7 +286,7 @@ ValueStateManager::Remove(StateTy St, VarBindKey K) { } ValueStateManager::StateTy -ValueStateManager::Add(StateTy St, VarBindKey K, const RValue& V) { +ValueStateManager::Add(StateTy St, ExprBindKey K, const RValue& V) { // Create a new state with the old binding removed. ValueStateImpl NewStateImpl = *St.getImpl(); diff --git a/Analysis/ValueState.h b/Analysis/ValueState.h index f431d1e441..1e3730ff4b 100644 --- a/Analysis/ValueState.h +++ b/Analysis/ValueState.h @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This files defines SymbolID, VarBindKey, and ValueState. +// This files defines SymbolID, ExprBindKey, and ValueState. // //===----------------------------------------------------------------------===// @@ -39,11 +39,11 @@ namespace clang { -/// VarBindKey - A variant smart pointer that wraps either a ValueDecl* or a +/// ExprBindKey - A variant smart pointer that wraps either a ValueDecl* or a /// Stmt*. Use cast<> or dyn_cast<> to get actual pointer type -class VarBindKey { +class ExprBindKey { uintptr_t Raw; - void operator=(const VarBindKey& RHS); // Do not implement. + void operator=(const ExprBindKey& RHS); // Do not implement. public: enum Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, // L-Value Bindings. @@ -58,18 +58,22 @@ public: return reinterpret_cast<void*>(Raw & ~Mask); } - VarBindKey(const ValueDecl* VD) + ExprBindKey(const ValueDecl* VD) : Raw(reinterpret_cast<uintptr_t>(VD) | IsDecl) { assert(VD && "ValueDecl cannot be NULL."); } - VarBindKey(Stmt* S, bool isBlkExpr = false) - : Raw(reinterpret_cast<uintptr_t>(S) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){ - assert(S && "Tracked statement cannot be NULL."); + ExprBindKey(Expr* E, bool isBlkExpr = false) + : Raw(reinterpret_cast<uintptr_t>(E) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){ + assert(E && "Tracked statement cannot be NULL."); } bool isSubExpr() const { return getKind() == IsSubExpr; } bool isBlkExpr() const { return getKind() == IsBlkExpr; } + + + + bool isDecl() const { return getKind() == IsDecl; } bool isStmt() const { return getKind() <= IsBlkExpr; } @@ -77,15 +81,15 @@ public: ID.AddPointer(getPtr()); } - inline bool operator==(const VarBindKey& X) const { + inline bool operator==(const ExprBindKey& X) const { return getPtr() == X.getPtr(); } - inline bool operator!=(const VarBindKey& X) const { + inline bool operator!=(const ExprBindKey& X) const { return !operator==(X); } - inline bool operator<(const VarBindKey& X) const { + inline bool operator<(const ExprBindKey& X) const { return getPtr() < X.getPtr(); } }; @@ -97,7 +101,7 @@ public: namespace vstate { typedef llvm::ImmutableSet<llvm::APSInt*> IntSetTy; - typedef llvm::ImmutableMap<VarBindKey,RValue> VarBindingsTy; + typedef llvm::ImmutableMap<ExprBindKey,RValue> VarBindingsTy; typedef llvm::ImmutableMap<SymbolID,IntSetTy> ConstantNotEqTy; typedef llvm::ImmutableMap<SymbolID,const llvm::APSInt*> ConstantEqTy; } @@ -244,18 +248,18 @@ public: StateTy RemoveDeadBindings(StateTy St, Stmt* Loc, const LiveVariables& Liveness); - StateTy SetValue(StateTy St, Stmt* S, bool isBlkExpr, const RValue& V); + StateTy SetValue(StateTy St, Expr* S, bool isBlkExpr, const RValue& V); StateTy SetValue(StateTy St, const LValue& LV, const RValue& V); - RValue GetValue(const StateTy& St, Stmt* S, bool* hasVal = NULL); + RValue GetValue(const StateTy& St, Expr* S, bool* hasVal = NULL); RValue GetValue(const StateTy& St, const LValue& LV, QualType* T = NULL); - LValue GetLValue(const StateTy& St, Stmt* S); + LValue GetLValue(const StateTy& St, Expr* S); - StateTy Add(StateTy St, VarBindKey K, const RValue& V); - StateTy Remove(StateTy St, VarBindKey K); + StateTy Add(StateTy St, ExprBindKey K, const RValue& V); + StateTy Remove(StateTy St, ExprBindKey K); StateTy getPersistentState(const ValueStateImpl& Impl); StateTy AddEQ(StateTy St, SymbolID sym, const llvm::APSInt& V); @@ -265,32 +269,32 @@ public: } // end clang namespace //==------------------------------------------------------------------------==// -// Casting machinery to get cast<> and dyn_cast<> working with VarBindKey. +// Casting machinery to get cast<> and dyn_cast<> working with ExprBindKey. //==------------------------------------------------------------------------==// namespace llvm { template<> inline bool - isa<clang::ValueDecl,clang::VarBindKey>(const clang::VarBindKey& V) { - return V.getKind() == clang::VarBindKey::IsDecl; + isa<clang::ValueDecl,clang::ExprBindKey>(const clang::ExprBindKey& V) { + return V.getKind() == clang::ExprBindKey::IsDecl; } template<> inline bool - isa<clang::Stmt,clang::VarBindKey>(const clang::VarBindKey& V) { - return ((unsigned) V.getKind()) < clang::VarBindKey::IsDecl; + isa<clang::Stmt,clang::ExprBindKey>(const clang::ExprBindKey& V) { + return ((unsigned) V.getKind()) < clang::ExprBindKey::IsDecl; } - template<> struct cast_retty_impl<clang::ValueDecl,clang::VarBindKey> { + template<> struct cast_retty_impl<clang::ValueDecl,clang::ExprBindKey> { typedef const clang::ValueDecl* ret_type; }; - template<> struct cast_retty_impl<clang::Stmt,clang::VarBindKey> { + template<> struct cast_retty_impl<clang::Stmt,clang::ExprBindKey> { typedef const clang::Stmt* ret_type; }; - template<> struct simplify_type<clang::VarBindKey> { + template<> struct simplify_type<clang::ExprBindKey> { typedef void* SimpleType; - static inline SimpleType getSimplifiedValue(const clang::VarBindKey &V) { + static inline SimpleType getSimplifiedValue(const clang::ExprBindKey &V) { return V.getPtr(); } }; |