3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-23 11:37:54 +00:00

move to unicode as stand-alone theory

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2021-01-27 05:46:45 -08:00
parent ecba26beae
commit d0f1d8f59e
12 changed files with 115 additions and 58 deletions

View file

@ -93,3 +93,8 @@ app* char_decl_plugin::mk_char(unsigned u) {
expr* char_decl_plugin::get_some_value(sort* s) {
return mk_char(0);
}
app* char_decl_plugin::mk_le(expr* a, expr* b) {
expr* es[2] = { a, b};
return m_manager->mk_app(m_family_id, OP_CHAR_LE, 2, es);
}

View file

@ -23,7 +23,6 @@ Revision History:
#pragma once
#include "ast/ast.h"
#include "ast/bv_decl_plugin.h"
#include <string>
enum char_sort_kind {
@ -67,7 +66,21 @@ public:
bool are_distinct(app* a, app* b) const override;
expr* get_some_value(sort* s) override;
sort* char_sort() const { return m_char; }
app* mk_char(unsigned u);
expr* get_some_value(sort* s) override;
app* mk_le(expr* a, expr* b);
bool is_le(expr const* e) const { return is_app_of(e, m_family_id, OP_CHAR_LE); }
bool is_const_char(expr const* e, unsigned& c) const {
return is_app_of(e, m_family_id, OP_CHAR_CONST) && (c = to_app(e)->get_parameter(0).get_int(), true);
}
};

View file

@ -49,12 +49,12 @@ void reg_decl_plugins(ast_manager & m) {
if (!m.get_plugin(m.mk_family_id(symbol("datalog_relation")))) {
m.register_plugin(symbol("datalog_relation"), alloc(datalog::dl_decl_plugin));
}
if (!m.get_plugin(m.mk_family_id(symbol("seq")))) {
m.register_plugin(symbol("seq"), alloc(seq_decl_plugin));
}
if (!m.get_plugin(m.mk_family_id(symbol("char")))) {
m.register_plugin(symbol("char"), alloc(char_decl_plugin));
}
if (!m.get_plugin(m.mk_family_id(symbol("seq")))) {
m.register_plugin(symbol("seq"), alloc(seq_decl_plugin));
}
if (!m.get_plugin(m.mk_family_id(symbol("fpa")))) {
m.register_plugin(symbol("fpa"), alloc(fpa_decl_plugin));
}

View file

@ -24,6 +24,8 @@ Revision History:
#include "ast/bv_decl_plugin.h"
#include <sstream>
#define _USE_CHAR_PLUGIN 1
seq_decl_plugin::seq_decl_plugin(): m_init(false),
m_stringc_sym("String"),
@ -283,8 +285,12 @@ void seq_decl_plugin::init() {
void seq_decl_plugin::set_manager(ast_manager* m, family_id id) {
decl_plugin::set_manager(m, id);
bv_util bv(*m);
if (unicode())
m_char = m->mk_sort(symbol("Unicode"), sort_info(m_family_id, _CHAR_SORT, 0, nullptr));
if (unicode())
#if _USE_CHAR_PLUGIN
m_char = get_char_plugin().char_sort();
#else
m_char = m->mk_sort(symbol("Unicode"), sort_info(m_family_id, _CHAR_SORT, 0, nullptr));
#endif
else
m_char = bv.mk_sort(8);
m->inc_ref(m_char);
@ -641,9 +647,6 @@ void seq_decl_plugin::get_sort_names(svector<builtin_name> & sort_names, symbol
sort_names.push_back(builtin_name("Seq", SEQ_SORT));
sort_names.push_back(builtin_name("RegEx", RE_SORT));
// TBD:
// sort_names.push_back(builtin_name("Unicode", CHAR_SORT));
// SMTLIB 2.6 RegLan, String
sort_names.push_back(builtin_name("RegLan", _REGLAN_SORT));
sort_names.push_back(builtin_name("String", _STRING_SORT));
@ -671,9 +674,13 @@ app* seq_decl_plugin::mk_string(zstring const& s) {
app* seq_decl_plugin::mk_char(unsigned u) {
if (unicode()) {
#if _USE_CHAR_PLUGIN
return get_char_plugin().mk_char(u);
#else
parameter param(u);
func_decl* f = m_manager->mk_const_decl(m_charc_sym, m_char, func_decl_info(m_family_id, _OP_CHAR_CONST, 1, &param));
return m_manager->mk_const(f);
#endif
}
else {
bv_util bv(*m_manager);
@ -813,7 +820,11 @@ unsigned seq_util::max_mul(unsigned x, unsigned y) const {
bool seq_util::is_const_char(expr* e, unsigned& c) const {
if (seq.unicode()) {
#if _USE_CHAR_PLUGIN
return ch.is_const_char(e, c);
#else
return is_app_of(e, m_fid, _OP_CHAR_CONST) && (c = to_app(e)->get_parameter(0).get_int(), true);
#endif
}
else {
rational r;
@ -824,7 +835,11 @@ bool seq_util::is_const_char(expr* e, unsigned& c) const {
bool seq_util::is_char_le(expr const* e) const {
if (seq.unicode())
#if _USE_CHAR_PLUGIN
return ch.is_le(e);
#else
return is_app_of(e, m_fid, _OP_CHAR_LE);
#endif
else
return bv().is_bv_ule(e) && is_char(to_app(e)->get_arg(0));
}
@ -840,8 +855,12 @@ app* seq_util::mk_le(expr* ch1, expr* ch2) const {
expr_ref _ch1(ch1, m), _ch2(ch2, m);
if (seq.unicode()) {
#if _USE_CHAR_PLUGIN
return ch.mk_le(ch1, ch2);
#else
expr* es[2] = { ch1, ch2 };
return m.mk_app(m_fid, _OP_CHAR_LE, 2, es);
#endif
}
else {
rational r1, r2;

View file

@ -24,6 +24,7 @@ Revision History:
#include "ast/ast.h"
#include "ast/bv_decl_plugin.h"
#include "ast/char_decl_plugin.h"
#include "util/lbool.h"
#include "util/zstring.h"
@ -204,11 +205,15 @@ public:
sort* char_sort() const { return m_char; }
sort* string_sort() const { return m_string; }
char_decl_plugin& get_char_plugin() { return *static_cast<char_decl_plugin*>(m_manager->get_plugin(m_manager->mk_family_id("char"))); }
};
class seq_util {
ast_manager& m;
seq_decl_plugin& seq;
char_decl_plugin& ch;
family_id m_fid;
mutable scoped_ptr<bv_util> m_bv;
bv_util& bv() const;
@ -571,6 +576,7 @@ public:
seq_util(ast_manager& m):
m(m),
seq(*static_cast<seq_decl_plugin*>(m.get_plugin(m.mk_family_id("seq")))),
ch(seq.get_char_plugin()),
m_fid(seq.get_family_id()),
str(*this),
re(*this) {