[cfe-commits] r46891 - in /cfe/trunk/Analysis: GRConstants.cpp ValueState.cpp ValueState.h

Ted Kremenek kremenek at apple.com
Fri Feb 8 12:29:23 PST 2008


Author: kremenek
Date: Fri Feb  8 14:29:23 2008
New Revision: 46891

URL: http://llvm.org/viewvc/llvm-project?rev=46891&view=rev
Log:
Changed "GetValue" methods to take an
Expr* instead of a Stmt*, since we only
store bindings for Expr*.

Modified:
    cfe/trunk/Analysis/GRConstants.cpp
    cfe/trunk/Analysis/ValueState.cpp
    cfe/trunk/Analysis/ValueState.h

Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46891&r1=46890&r2=46891&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Fri Feb  8 14:29:23 2008
@@ -200,30 +200,30 @@
     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 @@
     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 @@
   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 @@
 
 
 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 @@
 }
 
 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::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 @@
   }
 
   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 @@
       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 @@
       
     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 @@
 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 @@
     
     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());

Modified: cfe/trunk/Analysis/ValueState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ValueState.cpp?rev=46891&r1=46890&r2=46891&view=diff

==============================================================================
--- cfe/trunk/Analysis/ValueState.cpp (original)
+++ cfe/trunk/Analysis/ValueState.cpp Fri Feb  8 14:29:23 2008
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This files defines SymbolID, VarBindKey, and ValueState.
+//  This files defines SymbolID, ExprBindKey, and ValueState.
 //
 //===----------------------------------------------------------------------===//
 
@@ -167,7 +167,7 @@
   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 @@
   }
 }
 
-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 @@
 
 
 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::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::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();

Modified: cfe/trunk/Analysis/ValueState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ValueState.h?rev=46891&r1=46890&r2=46891&view=diff

==============================================================================
--- cfe/trunk/Analysis/ValueState.h (original)
+++ cfe/trunk/Analysis/ValueState.h Fri Feb  8 14:29:23 2008
@@ -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 @@
     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 @@
     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 @@
 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 @@
   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 @@
 } // 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();
     }
   };





More information about the cfe-commits mailing list