From 40ddb7ac71682a881d9d0cd856295d4f0240dc24 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 5 Jun 2009 08:59:38 +0000 Subject: 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 --- include/klee/Expr.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'include') 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 rebuild(ref 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(this)) + return CE->getConstantValue() == 0; + return false; +} + +inline bool Expr::isTrue() const { + if (const ConstantExpr *CE = dyn_cast(this)) + return (CE->getWidth() == Expr::Bool && + CE->getConstantValue() == 1); + return false; +} + +inline bool Expr::isFalse() const { + if (const ConstantExpr *CE = dyn_cast(this)) + return (CE->getWidth() == Expr::Bool && + CE->getConstantValue() == 0); + return false; +} + } // End klee namespace #endif -- cgit 1.4.1