]> granicus.if.org Git - clang/commitdiff
Further refactoring of transfer functions by having APSIntSetOp take
authorTed Kremenek <kremenek@apple.com>
Fri, 25 Jan 2008 23:43:12 +0000 (23:43 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 25 Jan 2008 23:43:12 +0000 (23:43 +0000)
a template-template parameter.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46378 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/GRConstants.cpp

index db897b451212f28a6515e09b91c5513ee22307d4..69a0d9320766ae5b9fcd82813807830c520af21d 100644 (file)
@@ -50,23 +50,26 @@ namespace {
   
 class VISIBILITY_HIDDEN ValueKey {
   uintptr_t Raw;
+  
+  void operator=(const ValueKey& RHS); // Do not implement.
 public:
   enum  Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, Flags=0x3 };
   inline void* getPtr() const { return reinterpret_cast<void*>(Raw & ~Flags); }
   inline Kind getKind() const { return (Kind) (Raw & Flags); }
   
   ValueKey(const ValueDecl* VD)
-    : Raw(reinterpret_cast<uintptr_t>(VD) | IsDecl) {}
+    : Raw(reinterpret_cast<uintptr_t>(VD) | IsDecl) { assert(VD); }
 
   ValueKey(Stmt* S, bool isBlkExpr = false) 
-    : Raw(reinterpret_cast<uintptr_t>(S) | isBlkExpr ? IsBlkExpr : IsSubExpr) {}
+    : Raw(reinterpret_cast<uintptr_t>(S) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){
+      assert(S);
+    }
   
   bool isSubExpr() const { return getKind() == IsSubExpr; }
   bool isDecl() const { return getKind() == IsDecl; }
   
   inline void Profile(llvm::FoldingSetNodeID& ID) const {
     ID.AddPointer(getPtr());
-    ID.AddInteger((unsigned) getKind());
   }
   
   inline bool operator==(const ValueKey& X) const {
@@ -146,16 +149,17 @@ public:
 };
 } // end anonymous namespace
 
-template <typename OpTy>
+template <template <typename T> class OpTy>
 static inline APSIntSetTy APSIntSetOp(ValueManager& ValMgr,
-                                      APSIntSetTy S1, APSIntSetTy S2,
-                                      OpTy Op) {
+                                      APSIntSetTy S1, APSIntSetTy S2) {
   
   APSIntSetTy M = ValMgr.GetEmptyAPSIntSet();
   
+  OpTy<APSInt> Op;
+  
   for (APSIntSetTy::iterator I1=S1.begin(), E1=S2.end(); I1!=E1; ++I1)
     for (APSIntSetTy::iterator I2=S2.begin(), E2=S2.end(); I2!=E2; ++I2)
-      M = ValMgr.AddToSet(M, Op(*I1,*I2));
+      M = ValMgr.AddToSet(M, Op(*I1, *I2));
   
   return M;
 }
@@ -277,26 +281,22 @@ public:
   
   RValEqualityORSet
   EvalAdd(ValueManager& ValMgr, const RValEqualityORSet& V) const {
-    return APSIntSetOp(ValMgr, GetValues(), V.GetValues(),
-                       std::plus<APSInt>());
+    return APSIntSetOp<std::plus>(ValMgr, GetValues(), V.GetValues());
   }
   
   RValEqualityORSet
   EvalSub(ValueManager& ValMgr, const RValEqualityORSet& V) const {
-    return APSIntSetOp(ValMgr, GetValues(), V.GetValues(),
-                       std::minus<APSInt>());
+    return APSIntSetOp<std::minus>(ValMgr, GetValues(), V.GetValues());
   }
   
   RValEqualityORSet
   EvalMul(ValueManager& ValMgr, const RValEqualityORSet& V) const {
-    return APSIntSetOp(ValMgr, GetValues(), V.GetValues(),
-                       std::multiplies<APSInt>());
+    return APSIntSetOp<std::multiplies>(ValMgr, GetValues(), V.GetValues());
   }
   
   RValEqualityORSet
   EvalDiv(ValueManager& ValMgr, const RValEqualityORSet& V) const {
-    return APSIntSetOp(ValMgr, GetValues(), V.GetValues(),
-                       std::divides<APSInt>());
+    return APSIntSetOp<std::divides>(ValMgr, GetValues(), V.GetValues());
   }
 
   RValEqualityORSet
@@ -775,6 +775,7 @@ LValue GRConstants::GetLValue(const StateTy& St, Stmt* S) {
 
 GRConstants::StateTy GRConstants::SetValue(StateTy St, Stmt* S,
                                            const ExprValue& V) {
+  assert (S);
   
   if (!StateCleaned) {
     St = RemoveDeadBindings(CurrentStmt, St);