]> granicus.if.org Git - clang/commitdiff
Added skeleton for new LValue class ConcereteIntLValue.
authorTed Kremenek <kremenek@apple.com>
Thu, 31 Jan 2008 22:17:03 +0000 (22:17 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 31 Jan 2008 22:17:03 +0000 (22:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46624 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/RValues.h

index 90446a2cc56264bfd1faafce7ef35f5bac58079c..989c60bb3fe32f1899b1f71bbea390a4d2cc0b77 100644 (file)
@@ -217,7 +217,8 @@ public:
 
 class LValue : public RValue {
 protected:
-  LValue(unsigned SubKind, void* D) : RValue(D, true, SubKind) {}
+  LValue(unsigned SubKind, const void* D) : RValue(const_cast<void*>(D), 
+                                                   true, SubKind) {}
   
 public:
   void print(std::ostream& Out) const;
@@ -231,49 +232,6 @@ public:
     return V->getBaseKind() == LValueKind;
   }
 };
-
-//==------------------------------------------------------------------------==//
-//  Subclasses of LValue.
-//==------------------------------------------------------------------------==// 
-  
-enum LValueKind { SymbolicLValueKind, LValueDeclKind, NumLValueKind };
-
-class SymbolicLValue : public LValue {
-public:
-  SymbolicLValue(unsigned SymID)
-  : LValue(SymbolicLValueKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
-  
-  SymbolID getSymbolID() const {
-    return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
-  }
-  
-  static inline bool classof(const RValue* V) {
-    return V->getSubKind() == SymbolicLValueKind;
-  }  
-};
-
-class LValueDecl : public LValue {
-public:
-  LValueDecl(const ValueDecl* vd) 
-  : LValue(LValueDeclKind,const_cast<ValueDecl*>(vd)) {}
-  
-  ValueDecl* getDecl() const {
-    return static_cast<ValueDecl*>(getRawPtr());
-  }
-  
-  inline bool operator==(const LValueDecl& R) const {
-    return getDecl() == R.getDecl();
-  }
-  
-  inline bool operator!=(const LValueDecl& R) const {
-    return getDecl() != R.getDecl();
-  }
-  
-  // Implement isa<T> support.
-  static inline bool classof(const RValue* V) {
-    return V->getSubKind() == LValueDeclKind;
-  }
-};
   
 //==------------------------------------------------------------------------==//
 //  Subclasses of NonLValue.
@@ -363,6 +321,87 @@ public:
     return V->getSubKind() == ConcreteIntKind;
   }
 };
+
+//==------------------------------------------------------------------------==//
+//  Subclasses of LValue.
+//==------------------------------------------------------------------------==// 
+
+enum LValueKind { SymbolicLValueKind, LValueDeclKind,
+ConcreteIntLValueKind, NumLValueKind };
+
+class SymbolicLValue : public LValue {
+public:
+  SymbolicLValue(unsigned SymID)
+  : LValue(SymbolicLValueKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
+  
+  SymbolID getSymbolID() const {
+    return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
+  }
+  
+  static inline bool classof(const RValue* V) {
+    return V->getSubKind() == SymbolicLValueKind;
+  }  
+};
+
+class LValueDecl : public LValue {
+public:
+  LValueDecl(const ValueDecl* vd) : LValue(LValueDeclKind,vd) {}
+  
+  ValueDecl* getDecl() const {
+    return static_cast<ValueDecl*>(getRawPtr());
+  }
+  
+  inline bool operator==(const LValueDecl& R) const {
+    return getDecl() == R.getDecl();
+  }
+  
+  inline bool operator!=(const LValueDecl& R) const {
+    return getDecl() != R.getDecl();
+  }
+  
+  // Implement isa<T> support.
+  static inline bool classof(const RValue* V) {
+    return V->getSubKind() == LValueDeclKind;
+  }
+};
+
+class ConcreteIntLValue : public LValue {
+public:
+  ConcreteIntLValue(const llvm::APSInt& V) : LValue(ConcreteIntLValueKind, &V) {}
+  
+  const llvm::APSInt& getValue() const {
+    return *static_cast<llvm::APSInt*>(getRawPtr());
+  }
+  
+  // Arithmetic operators.
+  
+  ConcreteIntLValue Add(ValueManager& ValMgr, const ConcreteInt& V) const {
+    return ValMgr.getValue(getValue() + V.getValue());
+  }
+  
+  ConcreteIntLValue Sub(ValueManager& ValMgr, const ConcreteInt& V) const {
+    return ValMgr.getValue(getValue() - V.getValue());
+  }
+  
+  // Equality operators.
+  
+  ConcreteInt EQ(ValueManager& ValMgr, const ConcreteIntLValue& V) const {
+    const llvm::APSInt& Val = getValue();    
+    return ValMgr.getValue(Val == V.getValue() ? 1U : 0U,
+                           Val.getBitWidth(), Val.isUnsigned());
+  }
+  
+  ConcreteInt NE(ValueManager& ValMgr, const ConcreteIntLValue& V) const {
+    const llvm::APSInt& Val = getValue();    
+    return ValMgr.getValue(Val != V.getValue() ? 1U : 0U,
+                           Val.getBitWidth(), Val.isUnsigned());
+  }
+  
+  // Implement isa<T> support.
+  static inline bool classof(const RValue* V) {
+    return V->getSubKind() == ConcreteIntLValueKind;
+  }
+};  
   
 } // end clang namespace