about summary refs log tree commit diff homepage
path: root/include
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-05 08:59:38 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-05 08:59:38 +0000
commit40ddb7ac71682a881d9d0cd856295d4f0240dc24 (patch)
tree8802491359a04c11d3eecdcaede883e2201cd3cd /include
parent913279ed60aa9b7cce6db1b45c90e6e9d548c19b (diff)
downloadklee-40ddb7ac71682a881d9d0cd856295d4f0240dc24.tar.gz
Add Expr::is{Zero,True,False} methods.
 - These are too convenient to live without.


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@72937 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/klee/Expr.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/include/klee/Expr.h b/include/klee/Expr.h
index d58fdc81..dd31896a 100644
--- a/include/klee/Expr.h
+++ b/include/klee/Expr.h
@@ -195,7 +195,16 @@ public:
   // but using those children. 
   virtual ref<Expr> rebuild(ref<Expr> kids[/* getNumKids() */]) const = 0;
 
-  ///
+  //
+
+  /// isZero - Is this a constant zero.
+  bool isZero() const;
+  
+  /// isTrue - Is this the true expression.
+  bool isTrue() const;
+
+  /// isFalse - Is this the false expression.
+  bool isFalse() const;
 
   /* Static utility methods */
 
@@ -883,6 +892,28 @@ COMPARISON_EXPR_CLASS(Sle)
 COMPARISON_EXPR_CLASS(Sgt)
 COMPARISON_EXPR_CLASS(Sge)
 
+// Implementations
+
+inline bool Expr::isZero() const {
+  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this))
+    return CE->getConstantValue() == 0;
+  return false;
+}
+  
+inline bool Expr::isTrue() const {
+  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this))
+    return (CE->getWidth() == Expr::Bool &&
+            CE->getConstantValue() == 1);
+  return false;
+}
+  
+inline bool Expr::isFalse() const {
+  if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this))
+    return (CE->getWidth() == Expr::Bool &&
+            CE->getConstantValue() == 0);
+  return false;
+}
+
 } // End klee namespace
 
 #endif