From 5c9d7538a03c0e18b1e99df863058e5218cf0022 Mon Sep 17 00:00:00 2001 From: Murphy Berzish Date: Mon, 13 Mar 2017 14:39:12 -0400 Subject: [PATCH 1/2] add alternate str.at semantics check in seq_rewriter this rewrites to empty string if the index is negative or beyond the length of the string, which is consistent with CVC4's semantics for this term --- src/ast/rewriter/seq_rewriter.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ast/rewriter/seq_rewriter.cpp b/src/ast/rewriter/seq_rewriter.cpp index 26c3e23e4..adb70c30c 100644 --- a/src/ast/rewriter/seq_rewriter.cpp +++ b/src/ast/rewriter/seq_rewriter.cpp @@ -598,14 +598,25 @@ br_status seq_rewriter::mk_seq_contains(expr* a, expr* b, expr_ref& result) { return BR_FAILED; } +/* + * (str.at s i), constants s/i, i < 0 or i >= |s| ==> (str.at s i) = "" + */ br_status seq_rewriter::mk_seq_at(expr* a, expr* b, expr_ref& result) { zstring c; rational r; - if (m_util.str.is_string(a, c) && m_autil.is_numeral(b, r) && r.is_unsigned()) { - unsigned j = r.get_unsigned(); - if (j < c.length()) { - result = m_util.str.mk_string(c.extract(j, 1)); + if (m_util.str.is_string(a, c) && m_autil.is_numeral(b, r)) { + if (r.is_neg()) { + result = m_util.str.mk_string(symbol("")); return BR_DONE; + } else if (r.is_unsigned()) { + unsigned j = r.get_unsigned(); + if (j < c.length()) { + result = m_util.str.mk_string(c.extract(j, 1)); + return BR_DONE; + } else { + result = m_util.str.mk_string(symbol("")); + return BR_DONE; + } } } return BR_FAILED; From 0b1d5645097d41eec4c43946407e08d57b41ad64 Mon Sep 17 00:00:00 2001 From: hume Date: Tue, 14 Mar 2017 18:11:00 +0800 Subject: [PATCH 2/2] added no exception support to z3++.h --- src/api/c++/z3++.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/api/c++/z3++.h b/src/api/c++/z3++.h index bfd4eb2c4..ac0e2c84a 100644 --- a/src/api/c++/z3++.h +++ b/src/api/c++/z3++.h @@ -86,7 +86,13 @@ namespace z3 { }; inline std::ostream & operator<<(std::ostream & out, exception const & e) { out << e.msg(); return out; } - +#if !defined(Z3_THROW) +#if __cpp_exceptions || _CPPUNWIND +#define Z3_THROW(x) throw x +#else +#define Z3_THROW(x) {} +#endif +#endif // !defined(Z3_THROW) /** \brief Z3 global configuration object. @@ -165,7 +171,7 @@ namespace z3 { Z3_error_code check_error() const { Z3_error_code e = Z3_get_error_code(m_ctx); if (e != Z3_OK && enable_exceptions()) - throw exception(Z3_get_error_msg(m_ctx, e)); + Z3_THROW(exception(Z3_get_error_msg(m_ctx, e))); return e; } @@ -701,7 +707,7 @@ namespace z3 { if (!is_numeral_i(result)) { assert(ctx().enable_exceptions()); if (!ctx().enable_exceptions()) return 0; - throw exception("numeral does not fit in machine int"); + Z3_THROW(exception("numeral does not fit in machine int")); } return result; } @@ -721,7 +727,7 @@ namespace z3 { if (!is_numeral_u(result)) { assert(ctx().enable_exceptions()); if (!ctx().enable_exceptions()) return 0; - throw exception("numeral does not fit in machine uint"); + Z3_THROW(exception("numeral does not fit in machine uint")); } return result; } @@ -738,7 +744,7 @@ namespace z3 { if (!is_numeral_i64(result)) { assert(ctx().enable_exceptions()); if (!ctx().enable_exceptions()) return 0; - throw exception("numeral does not fit in machine __int64"); + Z3_THROW(exception("numeral does not fit in machine __int64")); } return result; } @@ -755,7 +761,7 @@ namespace z3 { if (!is_numeral_u64(result)) { assert(ctx().enable_exceptions()); if (!ctx().enable_exceptions()) return 0; - throw exception("numeral does not fit in machine __uint64"); + Z3_THROW(exception("numeral does not fit in machine __uint64")); } return result; } @@ -1699,7 +1705,7 @@ namespace z3 { Z3_bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r); check_error(); if (status == Z3_FALSE && ctx().enable_exceptions()) - throw exception("failed to evaluate expression"); + Z3_THROW(exception("failed to evaluate expression")); return expr(ctx(), r); } @@ -2023,7 +2029,7 @@ namespace z3 { } inline tactic par_or(unsigned n, tactic const* tactics) { if (n == 0) { - throw exception("a non-zero number of tactics need to be passed to par_or"); + Z3_THROW(exception("a non-zero number of tactics need to be passed to par_or")); } array buffer(n); for (unsigned i = 0; i < n; ++i) buffer[i] = tactics[i];