mirror of
https://github.com/Z3Prover/z3
synced 2025-05-11 09:44:43 +00:00
add basic string factory
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
75c935a4cb
commit
a8e366aa24
4 changed files with 150 additions and 5 deletions
|
@ -20,8 +20,64 @@ Revision History:
|
|||
#define THEORY_SEQ_EMPTY_H_
|
||||
|
||||
#include "smt_theory.h"
|
||||
#include "seq_decl_plugin.h"
|
||||
|
||||
namespace smt {
|
||||
class seq_factory : public value_factory {
|
||||
typedef hashtable<symbol, symbol_hash_proc, symbol_eq_proc> symbol_set;
|
||||
proto_model& m_model;
|
||||
seq_util u;
|
||||
symbol_set m_strings;
|
||||
unsigned m_next;
|
||||
public:
|
||||
seq_factory(ast_manager & m, family_id fid, proto_model & md):
|
||||
value_factory(m, fid),
|
||||
m_model(md),
|
||||
u(m),
|
||||
m_next(0)
|
||||
{
|
||||
m_strings.insert(symbol(""));
|
||||
m_strings.insert(symbol("a"));
|
||||
m_strings.insert(symbol("b"));
|
||||
}
|
||||
|
||||
virtual expr* get_some_value(sort* s) {
|
||||
if (u.str.is_string(s))
|
||||
return u.str.mk_string(symbol(""));
|
||||
NOT_IMPLEMENTED_YET();
|
||||
return 0;
|
||||
}
|
||||
virtual bool get_some_values(sort* s, expr_ref& v1, expr_ref& v2) {
|
||||
if (u.str.is_string(s)) {
|
||||
v1 = u.str.mk_string("a");
|
||||
v2 = u.str.mk_string("b");
|
||||
return true;
|
||||
}
|
||||
NOT_IMPLEMENTED_YET();
|
||||
return false;
|
||||
}
|
||||
virtual expr* get_fresh_value(sort* s) {
|
||||
if (u.str.is_string(s)) {
|
||||
while (true) {
|
||||
std::ostringstream strm;
|
||||
strm << "S" << m_next++;
|
||||
symbol sym(strm.str().c_str());
|
||||
if (m_strings.contains(sym)) continue;
|
||||
m_strings.insert(sym);
|
||||
return u.str.mk_string(sym);
|
||||
}
|
||||
}
|
||||
NOT_IMPLEMENTED_YET();
|
||||
return 0;
|
||||
}
|
||||
virtual void register_value(expr* n) {
|
||||
std::string sym;
|
||||
if (u.str.is_const(n, sym)) {
|
||||
m_strings.insert(symbol(sym.c_str()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class theory_seq_empty : public theory {
|
||||
bool m_used;
|
||||
virtual final_check_status final_check_eh() { return m_used?FC_GIVEUP:FC_DONE; }
|
||||
|
@ -33,6 +89,10 @@ namespace smt {
|
|||
virtual char const * get_name() const { return "seq-empty"; }
|
||||
public:
|
||||
theory_seq_empty(ast_manager& m):theory(m.mk_family_id("seq")), m_used(false) {}
|
||||
virtual void init_model(model_generator & mg) {
|
||||
mg.register_factory(alloc(seq_factory, get_manager(), get_family_id(), mg.get_model()));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue