From c4a0e57c082e567e81ad3609a32ee492d41f03f9 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 4 Jun 2009 07:09:13 +0000 Subject: Change ConstantExpr::{alloc,create} to return a ref git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@72853 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/klee/Expr.h | 6 +++--- lib/Expr/Parser.cpp | 20 +++++++++++++++++++- unittests/Expr/ExprTest.cpp | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/klee/Expr.h b/include/klee/Expr.h index 69ed60a1..3473784b 100644 --- a/include/klee/Expr.h +++ b/include/klee/Expr.h @@ -330,14 +330,14 @@ public: static ref fromMemory(void *address, Width w); void toMemory(void *address); - static ref alloc(uint64_t v, Width w) { + static ref alloc(uint64_t v, Width w) { // constructs an "optimized" ConstantExpr - ref r(new ConstantExpr(v, w)); + ref r(new ConstantExpr(v, w)); r->computeHash(); return r; } - static ref create(uint64_t v, Width w) { + static ref create(uint64_t v, Width w) { assert(v == bits64::truncateToNBits(v, w) && "invalid constant"); return alloc(v, w); diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp index 3bbe3334..1808ca7b 100644 --- a/lib/Expr/Parser.cpp +++ b/lib/Expr/Parser.cpp @@ -49,8 +49,26 @@ namespace { } }; + class ExprResult { + bool IsValid; + ExprHandle Value; + + public: + ExprResult() : IsValid(false) {} + ExprResult(ExprHandle _Value) : IsValid(true), Value(_Value) {} + ExprResult(ref _Value) : IsValid(true), Value(_Value.get()) {} + ExprResult(bool _IsValid, ExprHandle _Value) : IsValid(_IsValid), Value(_Value) {} + + bool isValid() { + return IsValid; + } + ExprHandle get() { + assert(IsValid && "get() on invalid ParseResult!"); + return Value; + } + }; + typedef ParseResult DeclResult; - typedef ParseResult ExprResult; typedef ParseResult TypeResult; typedef ParseResult VersionResult; diff --git a/unittests/Expr/ExprTest.cpp b/unittests/Expr/ExprTest.cpp index a5e5d5d7..7b37973a 100644 --- a/unittests/Expr/ExprTest.cpp +++ b/unittests/Expr/ExprTest.cpp @@ -22,7 +22,7 @@ ref getConstant(int value, Expr::Width width) { } TEST(ExprTest, BasicConstruction) { - EXPECT_EQ(ConstantExpr::alloc(0, 32), + EXPECT_EQ(ref(ConstantExpr::alloc(0, 32)), SubExpr::create(ConstantExpr::alloc(10, 32), ConstantExpr::alloc(10, 32))); } -- cgit 1.4.1