mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
theory_str refactoring
This commit is contained in:
parent
8b077ebbe7
commit
ab71dea82d
9 changed files with 83 additions and 280 deletions
|
@ -304,58 +304,6 @@ format * smt2_pp_environment::mk_float(rational const & val) const {
|
|||
return mk_string(get_manager(), s.c_str());
|
||||
}
|
||||
|
||||
format * smt2_pp_environment::pp_str_literal(app * t) {
|
||||
ast_manager & m = get_manager();
|
||||
str_util & u = get_strutil();
|
||||
TRACE("parse_string", tout << "pp_str_literal\n";);
|
||||
|
||||
SASSERT(u.is_string(t));
|
||||
std::string strVal = u.get_string_constant_value(t);
|
||||
string_buffer<> buf;
|
||||
buf << "\"";
|
||||
|
||||
// we want to scan strVal and escape every non-printable character
|
||||
for (unsigned int i = 0; i < strVal.length(); ++i) {
|
||||
char c = strVal.at(i);
|
||||
if (c == '"') {
|
||||
// SMT-LIB 2.5 string escape
|
||||
buf << "\"\"";
|
||||
} else if (isprint(c)) {
|
||||
buf << c;
|
||||
} else if (c == '\a') {
|
||||
buf << "\\a";
|
||||
} else if (c == '\b') {
|
||||
buf << "\\b";
|
||||
} else if (c == '\e') {
|
||||
buf << "\\e";
|
||||
} else if (c == '\f') {
|
||||
buf << "\\f";
|
||||
} else if (c == '\n') {
|
||||
buf << "\\n";
|
||||
} else if (c == '\r') {
|
||||
buf << "\\r";
|
||||
} else if (c == '\t') {
|
||||
buf << "\\t";
|
||||
} else if (c == '\v') {
|
||||
buf << "\\v";
|
||||
} else if (c == '\\') {
|
||||
buf << "\\" << "\\";
|
||||
} else {
|
||||
// general hex escape
|
||||
buf << "\\x";
|
||||
unsigned int cVal = ((unsigned int)c) & 0x000000FF;
|
||||
const char convtable[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
unsigned int highPart = cVal / 16;
|
||||
unsigned int lowPart = cVal % 16;
|
||||
SASSERT(highPart < 16); SASSERT(lowPart < 16);
|
||||
buf << convtable[highPart] << convtable[lowPart];
|
||||
}
|
||||
}
|
||||
|
||||
buf << "\"";
|
||||
return mk_string(m, buf.c_str());
|
||||
}
|
||||
|
||||
format * smt2_pp_environment::pp_arith_literal(app * t, bool decimal, unsigned decimal_prec) {
|
||||
arith_util & u = get_autil();
|
||||
SASSERT(u.is_numeral(t) || u.is_irrational_algebraic_numeral(t));
|
||||
|
@ -666,9 +614,6 @@ class smt2_printer {
|
|||
else if (m_env.get_dlutil().is_numeral(c)) {
|
||||
f = m_env.pp_datalog_literal(c);
|
||||
}
|
||||
else if (m_env.get_strutil().is_string(c)) {
|
||||
f = m_env.pp_str_literal(c);
|
||||
}
|
||||
else {
|
||||
buffer<symbol> names;
|
||||
if (m().is_label_lit(c, names)) {
|
||||
|
|
|
@ -56,9 +56,8 @@ public:
|
|||
virtual format_ns::format * pp_bv_literal(app * t, bool use_bv_lits, bool bv_neg);
|
||||
virtual format_ns::format * pp_arith_literal(app * t, bool decimal, unsigned prec);
|
||||
virtual format_ns::format * pp_float_literal(app * t, bool use_bv_lits, bool use_float_real_lits);
|
||||
virtual format_ns::format * pp_str_literal(app * t);
|
||||
virtual format_ns::format * pp_datalog_literal(app * t);
|
||||
virtual format_ns::format * pp_string_literal(app * t);
|
||||
virtual format_ns::format * pp_datalog_literal(app * t);
|
||||
virtual format_ns::format * pp_sort(sort * s);
|
||||
virtual format_ns::format * pp_fdecl_ref(func_decl * f);
|
||||
format_ns::format * pp_fdecl_name(symbol const & fname, unsigned & len) const;
|
||||
|
|
|
@ -27,7 +27,6 @@ Notes:
|
|||
#include"dl_rewriter.h"
|
||||
#include"pb_rewriter.h"
|
||||
#include"seq_rewriter.h"
|
||||
#include"str_rewriter.h"
|
||||
#include"rewriter_def.h"
|
||||
#include"expr_substitution.h"
|
||||
#include"ast_smt2_pp.h"
|
||||
|
@ -46,7 +45,6 @@ struct th_rewriter_cfg : public default_rewriter_cfg {
|
|||
dl_rewriter m_dl_rw;
|
||||
pb_rewriter m_pb_rw;
|
||||
seq_rewriter m_seq_rw;
|
||||
str_rewriter m_str_rw;
|
||||
arith_util m_a_util;
|
||||
bv_util m_bv_util;
|
||||
unsigned long long m_max_memory; // in bytes
|
||||
|
@ -81,7 +79,6 @@ struct th_rewriter_cfg : public default_rewriter_cfg {
|
|||
m_ar_rw.updt_params(p);
|
||||
m_f_rw.updt_params(p);
|
||||
m_seq_rw.updt_params(p);
|
||||
m_str_rw.updt_params(p);
|
||||
updt_local_params(p);
|
||||
}
|
||||
|
||||
|
@ -182,8 +179,6 @@ struct th_rewriter_cfg : public default_rewriter_cfg {
|
|||
st = m_ar_rw.mk_eq_core(args[0], args[1], result);
|
||||
else if (s_fid == m_seq_rw.get_fid())
|
||||
st = m_seq_rw.mk_eq_core(args[0], args[1], result);
|
||||
else if (s_fid == m_str_rw.get_fid())
|
||||
st = m_str_rw.mk_eq_core(args[0], args[1], result);
|
||||
|
||||
if (st != BR_FAILED)
|
||||
return st;
|
||||
|
@ -220,8 +215,6 @@ struct th_rewriter_cfg : public default_rewriter_cfg {
|
|||
return m_pb_rw.mk_app_core(f, num, args, result);
|
||||
if (fid == m_seq_rw.get_fid())
|
||||
return m_seq_rw.mk_app_core(f, num, args, result);
|
||||
if (fid == m_str_rw.get_fid())
|
||||
return m_str_rw.mk_app_core(f, num, args, result);
|
||||
return BR_FAILED;
|
||||
}
|
||||
|
||||
|
@ -680,7 +673,6 @@ struct th_rewriter_cfg : public default_rewriter_cfg {
|
|||
m_dl_rw(m),
|
||||
m_pb_rw(m),
|
||||
m_seq_rw(m),
|
||||
m_str_rw(m),
|
||||
m_a_util(m),
|
||||
m_bv_util(m),
|
||||
m_used_dependencies(m),
|
||||
|
|
|
@ -284,8 +284,54 @@ zstring zstring::operator+(zstring const& other) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::ostream& zstring::operator<<(std::ostream& out) const {
|
||||
return out << encode();
|
||||
bool zstring::operator==(const zstring& other) const {
|
||||
// two strings are equal iff they have the same length and characters
|
||||
if (length() != other.length()) {
|
||||
return false;
|
||||
}
|
||||
for (unsigned i = 0; i < length(); ++i) {
|
||||
unsigned Xi = m_buffer[i];
|
||||
unsigned Yi = other[i];
|
||||
if (Xi != Yi) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool zstring::operator!=(const zstring& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &os, const zstring &str) {
|
||||
return os << str.encode();
|
||||
}
|
||||
|
||||
bool operator<(const zstring& lhs, const zstring& rhs) {
|
||||
// This has the same semantics as strcmp()
|
||||
unsigned len = lhs.length();
|
||||
if (rhs.length() < len) {
|
||||
len = rhs.length();
|
||||
}
|
||||
for (unsigned i = 0; i < len; ++i) {
|
||||
unsigned Li = lhs[i];
|
||||
unsigned Ri = rhs[i];
|
||||
if (Li < Ri) {
|
||||
return true;
|
||||
} else if (Li > Ri) {
|
||||
return false;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// at this point, all compared characters are equal,
|
||||
// so decide based on the relative lengths
|
||||
if (lhs.length() < rhs.length()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -114,7 +114,11 @@ public:
|
|||
int indexof(zstring const& other, int offset) const;
|
||||
zstring extract(int lo, int hi) const;
|
||||
zstring operator+(zstring const& other) const;
|
||||
std::ostream& operator<<(std::ostream& out) const;
|
||||
bool operator==(const zstring& other) const;
|
||||
bool operator!=(const zstring& other) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &os, const zstring &str);
|
||||
friend bool operator<(const zstring& lhs, const zstring& rhs);
|
||||
};
|
||||
|
||||
class seq_decl_plugin : public decl_plugin {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue