mirror of
https://github.com/Z3Prover/z3
synced 2025-08-14 06:45:25 +00:00
remove symbol -> zstring -> symbol round-trips
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
5cb0bac41d
commit
20a67e47ca
13 changed files with 68 additions and 62 deletions
|
@ -41,6 +41,9 @@ parameter::~parameter() {
|
|||
if (m_kind == PARAM_RATIONAL) {
|
||||
dealloc(m_rational);
|
||||
}
|
||||
if (m_kind == PARAM_ZSTRING) {
|
||||
dealloc(m_zstring);
|
||||
}
|
||||
}
|
||||
|
||||
parameter::parameter(parameter const& other) {
|
||||
|
@ -64,6 +67,7 @@ parameter& parameter::operator=(parameter const& other) {
|
|||
case PARAM_RATIONAL: m_rational = alloc(rational, other.get_rational()); break;
|
||||
case PARAM_DOUBLE: m_dval = other.m_dval; break;
|
||||
case PARAM_EXTERNAL: m_ext_id = other.m_ext_id; break;
|
||||
case PARAM_ZSTRING: m_zstring = alloc(zstring, other.get_zstring()); break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
|
@ -99,6 +103,7 @@ bool parameter::operator==(parameter const & p) const {
|
|||
case PARAM_RATIONAL: return get_rational() == p.get_rational();
|
||||
case PARAM_DOUBLE: return m_dval == p.m_dval;
|
||||
case PARAM_EXTERNAL: return m_ext_id == p.m_ext_id;
|
||||
case PARAM_ZSTRING: return get_zstring() == p.get_zstring();
|
||||
default: UNREACHABLE(); return false;
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +116,7 @@ unsigned parameter::hash() const {
|
|||
case PARAM_SYMBOL: b = get_symbol().hash(); break;
|
||||
case PARAM_RATIONAL: b = get_rational().hash(); break;
|
||||
case PARAM_DOUBLE: b = static_cast<unsigned>(m_dval); break;
|
||||
case PARAM_ZSTRING: b = get_zstring().hash(); break;
|
||||
case PARAM_EXTERNAL: b = m_ext_id; break;
|
||||
}
|
||||
return (b << 2) | m_kind;
|
||||
|
@ -124,6 +130,7 @@ std::ostream& parameter::display(std::ostream& out) const {
|
|||
case PARAM_AST: return out << "#" << get_ast()->get_id();
|
||||
case PARAM_DOUBLE: return out << m_dval;
|
||||
case PARAM_EXTERNAL: return out << "@" << m_ext_id;
|
||||
case PARAM_ZSTRING: return out << get_zstring();
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return out << "[invalid parameter]";
|
||||
|
|
|
@ -22,6 +22,7 @@ Revision History:
|
|||
#include "util/vector.h"
|
||||
#include "util/hashtable.h"
|
||||
#include "util/buffer.h"
|
||||
#include "util/zstring.h"
|
||||
#include "util/symbol.h"
|
||||
#include "util/rational.h"
|
||||
#include "util/hash.h"
|
||||
|
@ -100,6 +101,7 @@ public:
|
|||
PARAM_INT,
|
||||
PARAM_AST,
|
||||
PARAM_SYMBOL,
|
||||
PARAM_ZSTRING,
|
||||
PARAM_RATIONAL,
|
||||
PARAM_DOUBLE,
|
||||
// PARAM_EXTERNAL is used for handling decl_plugin specific parameters.
|
||||
|
@ -119,6 +121,7 @@ private:
|
|||
ast* m_ast; // for PARAM_AST
|
||||
symbol m_symbol; // for PARAM_SYMBOL
|
||||
rational* m_rational; // for PARAM_RATIONAL
|
||||
zstring* m_zstring; // for PARAM_ZSTRING
|
||||
double m_dval; // for PARAM_DOUBLE (remark: this is not used in float_decl_plugin)
|
||||
unsigned m_ext_id; // for PARAM_EXTERNAL
|
||||
};
|
||||
|
@ -131,7 +134,9 @@ public:
|
|||
explicit parameter(ast * p): m_kind(PARAM_AST), m_ast(p) {}
|
||||
explicit parameter(symbol const & s): m_kind(PARAM_SYMBOL), m_symbol(s) {}
|
||||
explicit parameter(rational const & r): m_kind(PARAM_RATIONAL), m_rational(alloc(rational, r)) {}
|
||||
explicit parameter(rational && r) : m_kind(PARAM_RATIONAL), m_rational(alloc(rational, std::move(r))) {}
|
||||
explicit parameter(rational && r) : m_kind(PARAM_RATIONAL), m_rational(alloc(rational, std::move(r))) {}
|
||||
explicit parameter(zstring const& s): m_kind(PARAM_ZSTRING), m_zstring(alloc(zstring, s)) {}
|
||||
explicit parameter(zstring && s): m_kind(PARAM_ZSTRING), m_zstring(alloc(zstring, std::move(s))) {}
|
||||
explicit parameter(double d):m_kind(PARAM_DOUBLE), m_dval(d) {}
|
||||
explicit parameter(const char *s):m_kind(PARAM_SYMBOL), m_symbol(symbol(s)) {}
|
||||
explicit parameter(const std::string &s):m_kind(PARAM_SYMBOL), m_symbol(symbol(s)) {}
|
||||
|
@ -146,6 +151,7 @@ public:
|
|||
case PARAM_RATIONAL: m_rational = nullptr; std::swap(m_rational, other.m_rational); break;
|
||||
case PARAM_DOUBLE: m_dval = other.m_dval; break;
|
||||
case PARAM_EXTERNAL: m_ext_id = other.m_ext_id; break;
|
||||
case PARAM_ZSTRING: m_zstring = other.m_zstring; break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
|
@ -163,6 +169,7 @@ public:
|
|||
bool is_rational() const { return m_kind == PARAM_RATIONAL; }
|
||||
bool is_double() const { return m_kind == PARAM_DOUBLE; }
|
||||
bool is_external() const { return m_kind == PARAM_EXTERNAL; }
|
||||
bool is_zstring() const { return m_kind == PARAM_ZSTRING; }
|
||||
|
||||
bool is_int(int & i) const { return is_int() && (i = get_int(), true); }
|
||||
bool is_ast(ast * & a) const { return is_ast() && (a = get_ast(), true); }
|
||||
|
@ -170,6 +177,7 @@ public:
|
|||
bool is_rational(rational & r) const { return is_rational() && (r = get_rational(), true); }
|
||||
bool is_double(double & d) const { return is_double() && (d = get_double(), true); }
|
||||
bool is_external(unsigned & id) const { return is_external() && (id = get_ext_id(), true); }
|
||||
bool is_zstring(zstring& s) const { return is_zstring() && (s = get_zstring(), true); }
|
||||
|
||||
/**
|
||||
\brief This method is invoked when the parameter is
|
||||
|
@ -187,6 +195,7 @@ public:
|
|||
ast * get_ast() const { SASSERT(is_ast()); return m_ast; }
|
||||
symbol get_symbol() const { SASSERT(is_symbol()); return m_symbol; }
|
||||
rational const & get_rational() const { SASSERT(is_rational()); return *m_rational; }
|
||||
zstring const& get_zstring() const { SASSERT(is_zstring()); return *m_zstring; }
|
||||
double get_double() const { SASSERT(is_double()); return m_dval; }
|
||||
unsigned get_ext_id() const { SASSERT(is_external()); return m_ext_id; }
|
||||
|
||||
|
|
|
@ -682,7 +682,7 @@ namespace seq {
|
|||
// itos(n) does not start with "0" when n > 0
|
||||
// n = 0 or at(itos(n),0) != "0"
|
||||
// alternative: n >= 0 => itos(stoi(itos(n))) = itos(n)
|
||||
expr_ref zs(seq.str.mk_string(symbol("0")), m);
|
||||
expr_ref zs(seq.str.mk_string("0"), m);
|
||||
m_rewrite(zs);
|
||||
expr_ref eq0 = mk_eq(n, zero);
|
||||
expr_ref at0 = mk_eq(seq.str.mk_at(e, zero), zs);
|
||||
|
|
|
@ -2159,7 +2159,7 @@ br_status seq_rewriter::mk_str_from_code(expr* a, expr_ref& result) {
|
|||
rational r;
|
||||
if (m_autil.is_numeral(a, r)) {
|
||||
if (r.is_neg() || r > u().max_char()) {
|
||||
result = str().mk_string(symbol(""));
|
||||
result = str().mk_string(zstring());
|
||||
}
|
||||
else {
|
||||
unsigned num = r.get_unsigned();
|
||||
|
@ -2207,10 +2207,10 @@ br_status seq_rewriter::mk_str_itos(expr* a, expr_ref& result) {
|
|||
rational r;
|
||||
if (m_autil.is_numeral(a, r)) {
|
||||
if (r.is_int() && !r.is_neg()) {
|
||||
result = str().mk_string(symbol(r.to_string()));
|
||||
result = str().mk_string(zstring(r));
|
||||
}
|
||||
else {
|
||||
result = str().mk_string(symbol(""));
|
||||
result = str().mk_string(zstring());
|
||||
}
|
||||
return BR_DONE;
|
||||
}
|
||||
|
@ -2225,7 +2225,7 @@ br_status seq_rewriter::mk_str_itos(expr* a, expr_ref& result) {
|
|||
eqs.push_back(m().mk_eq(b, str().mk_string(s)));
|
||||
}
|
||||
result = m().mk_or(eqs);
|
||||
result = m().mk_ite(result, b, str().mk_string(symbol("")));
|
||||
result = m().mk_ite(result, b, str().mk_string(zstring()));
|
||||
return BR_REWRITE2;
|
||||
}
|
||||
return BR_FAILED;
|
||||
|
|
|
@ -375,7 +375,7 @@ func_decl * seq_decl_plugin::mk_func_decl(decl_kind k, unsigned num_parameters,
|
|||
case OP_SEQ_EMPTY:
|
||||
match(*m_sigs[k], arity, domain, range, rng);
|
||||
if (rng == m_string) {
|
||||
parameter param(symbol(""));
|
||||
parameter param(zstring(""));
|
||||
return mk_func_decl(OP_STRING_CONST, 1, ¶m, 0, nullptr, m_string);
|
||||
}
|
||||
else {
|
||||
|
@ -474,7 +474,7 @@ func_decl * seq_decl_plugin::mk_func_decl(decl_kind k, unsigned num_parameters,
|
|||
m.raise_exception("Incorrect arguments used for re.^. Expected one non-negative integer parameter");
|
||||
|
||||
case OP_STRING_CONST:
|
||||
if (!(num_parameters == 1 && arity == 0 && parameters[0].is_symbol())) {
|
||||
if (!(num_parameters == 1 && arity == 0 && parameters[0].is_zstring())) {
|
||||
m.raise_exception("invalid string declaration");
|
||||
}
|
||||
return m.mk_const_decl(m_stringc_sym, m_string,
|
||||
|
@ -630,16 +630,8 @@ void seq_decl_plugin::get_sort_names(svector<builtin_name> & sort_names, symbol
|
|||
sort_names.push_back(builtin_name("StringSequence", _STRING_SORT));
|
||||
}
|
||||
|
||||
app* seq_decl_plugin::mk_string(symbol const& s) {
|
||||
parameter param(s);
|
||||
func_decl* f = m_manager->mk_const_decl(m_stringc_sym, m_string,
|
||||
func_decl_info(m_family_id, OP_STRING_CONST, 1, ¶m));
|
||||
return m_manager->mk_const(f);
|
||||
}
|
||||
|
||||
app* seq_decl_plugin::mk_string(zstring const& s) {
|
||||
symbol sym(s.encode());
|
||||
parameter param(sym);
|
||||
parameter param(s);
|
||||
func_decl* f = m_manager->mk_const_decl(m_stringc_sym, m_string,
|
||||
func_decl_info(m_family_id, OP_STRING_CONST, 1, ¶m));
|
||||
return m_manager->mk_const(f);
|
||||
|
@ -792,7 +784,7 @@ app* seq_util::mk_lt(expr* ch1, expr* ch2) const {
|
|||
|
||||
bool seq_util::str::is_string(func_decl const* f, zstring& s) const {
|
||||
if (is_string(f)) {
|
||||
s = zstring(f->get_parameter(0).get_symbol().bare_str());
|
||||
s = f->get_parameter(0).get_zstring();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -191,7 +191,6 @@ public:
|
|||
unsigned max_char() const { return get_char_plugin().max_char(); }
|
||||
unsigned num_bits() const { return get_char_plugin().num_bits(); }
|
||||
|
||||
app* mk_string(symbol const& s);
|
||||
app* mk_string(zstring const& s);
|
||||
app* mk_char(unsigned ch);
|
||||
|
||||
|
@ -262,9 +261,6 @@ public:
|
|||
ast_manager& m;
|
||||
family_id m_fid;
|
||||
|
||||
app* mk_string(char const* s) { return mk_string(symbol(s)); }
|
||||
app* mk_string(std::string const& s) { return mk_string(symbol(s.c_str())); }
|
||||
|
||||
|
||||
public:
|
||||
str(seq_util& u): u(u), m(u.m), m_fid(u.m_fid) {}
|
||||
|
@ -273,7 +269,6 @@ public:
|
|||
sort* mk_string_sort() const { return m.mk_sort(m_fid, _STRING_SORT, 0, nullptr); }
|
||||
app* mk_empty(sort* s) const { return m.mk_const(m.mk_func_decl(m_fid, OP_SEQ_EMPTY, 0, nullptr, 0, (expr*const*)nullptr, s)); }
|
||||
app* mk_string(zstring const& s) const;
|
||||
app* mk_string(symbol const& s) const { return u.seq.mk_string(s); }
|
||||
app* mk_char(unsigned ch) const;
|
||||
app* mk_concat(expr* a, expr* b) const { expr* es[2] = { a, b }; return m.mk_app(m_fid, OP_SEQ_CONCAT, 2, es); }
|
||||
app* mk_concat(expr* a, expr* b, expr* c) const { return mk_concat(a, mk_concat(b, c)); }
|
||||
|
@ -313,14 +308,12 @@ public:
|
|||
bool is_skolem(func_decl const* f) const { return is_decl_of(f, m_fid, _OP_SEQ_SKOLEM); }
|
||||
|
||||
bool is_string(expr const * n) const { return is_app_of(n, m_fid, OP_STRING_CONST); }
|
||||
bool is_string(expr const* n, symbol& s) const {
|
||||
return is_string(n) && (s = to_app(n)->get_decl()->get_parameter(0).get_symbol(), true);
|
||||
}
|
||||
bool is_string(func_decl const* f) const { return is_decl_of(f, m_fid, OP_STRING_CONST); }
|
||||
bool is_string(expr const* n, zstring& s) const;
|
||||
bool is_string(func_decl const* f, zstring& s) const;
|
||||
bool is_empty(expr const* n) const { symbol s;
|
||||
return is_app_of(n, m_fid, OP_SEQ_EMPTY) || (is_string(n, s) && !s.is_numerical() && *s.bare_str() == 0);
|
||||
bool is_empty(expr const* n) const {
|
||||
zstring s;
|
||||
return is_app_of(n, m_fid, OP_SEQ_EMPTY) || (is_string(n, s) && s.empty());
|
||||
}
|
||||
bool is_concat(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_CONCAT); }
|
||||
bool is_length(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_LENGTH); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue