3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-22 16:45:31 +00:00
This commit is contained in:
Nikolaj Bjorner 2019-01-07 09:00:21 -08:00
commit 14f3ff0b63
15 changed files with 875 additions and 94 deletions

View file

@ -1720,6 +1720,10 @@ namespace z3 {
m_vector = s.m_vector;
return *this;
}
ast_vector_tpl& set(unsigned idx, ast& a) {
Z3_ast_vector_set(ctx(), m_vector, idx, a);
return *this;
}
/*
Disabled pending C++98 build upgrade
bool contains(T const& x) const {
@ -1746,6 +1750,9 @@ namespace z3 {
++m_index;
return *this;
}
void set(T& arg) {
Z3_ast_vector_set(m_vector->ctx(), *m_vector, m_index, arg);
}
iterator operator++(int) { iterator tmp = *this; ++m_index; return tmp; }
T * operator->() const { return &(operator*()); }
T operator*() const { return (*m_vector)[m_index]; }

View file

@ -459,6 +459,9 @@ br_status seq_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * con
case OP_SEQ_AT:
SASSERT(num_args == 2);
return mk_seq_at(args[0], args[1], result);
case OP_SEQ_NTH:
SASSERT(num_args == 2);
return mk_seq_nth(args[0], args[1], result);
case OP_SEQ_PREFIX:
SASSERT(num_args == 2);
return mk_seq_prefix(args[0], args[1], result);
@ -877,6 +880,38 @@ br_status seq_rewriter::mk_seq_at(expr* a, expr* b, expr_ref& result) {
return BR_DONE;
}
br_status seq_rewriter::mk_seq_nth(expr* a, expr* b, expr_ref& result) {
zstring c;
rational r;
if (!m_autil.is_numeral(b, r) || !r.is_unsigned()) {
return BR_FAILED;
}
unsigned len = r.get_unsigned();
expr_ref_vector as(m());
m_util.str.get_concat_units(a, as);
for (unsigned i = 0; i < as.size(); ++i) {
expr* a = as.get(i), *u = nullptr;
if (m_util.str.is_unit(a, u)) {
if (len == i) {
result = u;
return BR_REWRITE1;
}
}
else if (i > 0) {
SASSERT(len >= i);
result = m_util.str.mk_concat(as.size() - i, as.c_ptr() + i);
result = m().mk_app(m_util.get_family_id(), OP_SEQ_NTH, result, m_autil.mk_int(len - i));
return BR_REWRITE2;
}
else {
return BR_FAILED;
}
}
return BR_FAILED;
}
br_status seq_rewriter::mk_seq_index(expr* a, expr* b, expr* c, expr_ref& result) {
zstring s1, s2;
rational r;

View file

@ -114,6 +114,7 @@ class seq_rewriter {
br_status mk_seq_extract(expr* a, expr* b, expr* c, expr_ref& result);
br_status mk_seq_contains(expr* a, expr* b, expr_ref& result);
br_status mk_seq_at(expr* a, expr* b, expr_ref& result);
br_status mk_seq_nth(expr* a, expr* b, expr_ref& result);
br_status mk_seq_index(expr* a, expr* b, expr* c, expr_ref& result);
br_status mk_seq_replace(expr* a, expr* b, expr* c, expr_ref& result);
br_status mk_seq_prefix(expr* a, expr* b, expr_ref& result);

View file

@ -501,7 +501,7 @@ public:
expr_ref val(m);
model_evaluator eval(model);
for (expr * f : fmls) {
VERIFY(model.is_true(f));
VERIFY(!model.is_false(f));
}
return true;
}
@ -657,7 +657,7 @@ public:
other_vars.reset();
}
SASSERT(eval.is_true(fml));
SASSERT(!eval.is_false(fml));
vars.reset ();
vars.append(other_vars);

View file

@ -3537,7 +3537,7 @@ expr_ref theory_seq::digit2int(expr* ch) {
// n >= 0 & len(e) = k => is_digit(e_i) for i = 0..k-1
// n >= 0 & len(e) >= i + 1 => is_digit(e_i) for i = 0..k-1
// n >= 0 & len(e) = k => n = sum 10^i*digit(e_i)
// n < 0 & len(e) = k => \/_i ~is_digit(e_i) for i = 0..k-1
// 10^k <= n < 10^{k+1}-1 => len(e) = k
@ -3557,7 +3557,9 @@ void theory_seq::add_si_axiom(expr* e, expr* n, unsigned k) {
for (unsigned i = 0; i < k; ++i) {
ith_char = mk_nth(e, m_autil.mk_int(i));
literal isd = is_digit(ith_char);
add_axiom(~len_eq_k, ~ge0, isd);
literal len_ge_i1 = mk_literal(m_autil.mk_ge(len, m_autil.mk_int(i+1)));
add_axiom(~len_ge_i1, ~ge0, isd);
digits.push_back(~isd);
chars.push_back(m_util.str.mk_unit(ith_char));
nums.push_back(digit2int(ith_char));
}
@ -4585,7 +4587,12 @@ void theory_seq::propagate_in_re(expr* n, bool is_true) {
IF_VERBOSE(11, verbose_stream() << mk_pp(s, m) << " in " << re << "\n");
eautomaton* a = get_automaton(re);
if (!a) return;
if (!a) {
std::stringstream strm;
strm << "expression " << re << " does not correspond to a supported regular expression";
TRACE("seq", tout << strm.str() << "\n";);
throw default_exception(strm.str());
}
m_s_in_re.push_back(s_in_re(lit, s, re, a));
m_trail_stack.push(push_back_vector<theory_seq, vector<s_in_re>>(m_s_in_re));

View file

@ -56,17 +56,17 @@ void finalize_debug() {
void enable_debug(const char * tag) {
init_debug_table();
g_enabled_debug_tags->insert(const_cast<char *>(tag));
g_enabled_debug_tags->insert(tag);
}
void disable_debug(const char * tag) {
init_debug_table();
g_enabled_debug_tags->erase(const_cast<char *>(tag));
g_enabled_debug_tags->erase(tag);
}
bool is_debug_enabled(const char * tag) {
init_debug_table();
return g_enabled_debug_tags->contains(const_cast<char *>(tag));
return g_enabled_debug_tags->contains(tag);
}
#if !defined(_WINDOWS) && !defined(NO_Z3_DEBUGGER)

View file

@ -44,6 +44,13 @@ bool assertions_enabled();
#define DEBUG_CODE(CODE) ((void) 0)
#endif
#ifdef __APPLE__
#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#define NO_Z3_DEBUGGER
#endif
#endif
#ifdef NO_Z3_DEBUGGER
#define INVOKE_DEBUGGER() exit(ERR_INTERNAL_FATAL)
#else

View file

@ -28,7 +28,7 @@ struct str_hash_proc {
unsigned operator()(char const * s) const { return string_hash(s, static_cast<unsigned>(strlen(s)), 17); }
};
struct str_eq_proc { bool operator()(char const * s1, char const * s2) const { return strcmp(s1, s2) == 0; } };
typedef ptr_hashtable<char, str_hash_proc, str_eq_proc> str_hashtable;
typedef ptr_hashtable<const char, str_hash_proc, str_eq_proc> str_hashtable;
#endif /* STR_HASHTABLE_H_ */

View file

@ -35,20 +35,19 @@ class internal_symbol_table {
public:
char const * get_str(char const * d) {
char * result;
const char * result;
#pragma omp critical (cr_symbol)
{
char * r_d = const_cast<char *>(d);
str_hashtable::entry * e;
if (m_table.insert_if_not_there_core(r_d, e)) {
if (m_table.insert_if_not_there_core(d, e)) {
// new entry
size_t l = strlen(d);
// store the hash-code before the string
size_t * mem = static_cast<size_t*>(m_region.allocate(l + 1 + sizeof(size_t)));
*mem = e->get_hash();
mem++;
result = reinterpret_cast<char*>(mem);
memcpy(result, d, l+1);
result = reinterpret_cast<const char*>(mem);
memcpy(mem, d, l+1);
// update the entry with the new ptr.
e->set_data(result);
}

View file

@ -38,7 +38,7 @@ void finalize_trace() {
}
void enable_trace(const char * tag) {
get_enabled_trace_tags().insert(const_cast<char *>(tag));
get_enabled_trace_tags().insert(tag);
}
void enable_all_trace(bool flag) {
@ -46,12 +46,12 @@ void enable_all_trace(bool flag) {
}
void disable_trace(const char * tag) {
get_enabled_trace_tags().erase(const_cast<char *>(tag));
get_enabled_trace_tags().erase(tag);
}
bool is_trace_enabled(const char * tag) {
return g_enable_all_trace_tags ||
(g_enabled_trace_tags && get_enabled_trace_tags().contains(const_cast<char *>(tag)));
(g_enabled_trace_tags && get_enabled_trace_tags().contains(tag));
}
void close_trace() {