[cfe-commits] r53412 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Environment.h include/clang/Analysis/PathSensitive/ValueState.h lib/Analysis/Environment.cpp lib/Analysis/ValueState.cpp

Ted Kremenek kremenek at apple.com
Thu Jul 10 10:19:19 PDT 2008


Author: kremenek
Date: Thu Jul 10 12:19:18 2008
New Revision: 53412

URL: http://llvm.org/viewvc/llvm-project?rev=53412&view=rev
Log:
Move some environment methods from ValueState/ValueStateManager to Environment/EnvironmentManager.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h
    cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h
    cfe/trunk/lib/Analysis/Environment.cpp
    cfe/trunk/lib/Analysis/ValueState.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h?rev=53412&r1=53411&r2=53412&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h Thu Jul 10 12:19:18 2008
@@ -22,6 +22,7 @@
 namespace clang {
 
 class EnvironmentManager;
+class BasicValueFactory;
   
 class Environment : public llvm::FoldingSetNode {
 private:
@@ -65,6 +66,9 @@
     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 @@
   ///  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 @@
   Environment getInitialEnvironment() {
     return Environment(F.GetEmptyMap(), F.GetEmptyMap());
   }
+  
+  Environment SetRVal(const Environment& Env, Expr* E, RVal V,
+                      bool isBlkExpr, bool Invalidate);
 };
   
 } // end clang namespace

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h?rev=53412&r1=53411&r2=53412&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h Thu Jul 10 12:19:18 2008
@@ -235,17 +235,37 @@
     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);

Modified: cfe/trunk/lib/Analysis/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Environment.cpp?rev=53412&r1=53411&r2=53412&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/Environment.cpp (original)
+++ cfe/trunk/lib/Analysis/Environment.cpp Thu Jul 10 12:19:18 2008
@@ -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.
-//===----------------------------------------------------------------------===//
\ No newline at end of file
+  return isBlkExpr ? AddBlkExpr(Env, E, V) : AddSubExpr(Env, E, V);
+}

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

==============================================================================
--- cfe/trunk/lib/Analysis/ValueState.cpp (original)
+++ cfe/trunk/lib/Analysis/ValueState.cpp Thu Jul 10 12:19:18 2008
@@ -258,125 +258,6 @@
   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) {
   





More information about the cfe-commits mailing list