mirror of
https://github.com/Z3Prover/z3
synced 2025-06-29 09:28:45 +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
|
@ -156,14 +156,99 @@ public:
|
|||
class seq_util {
|
||||
ast_manager& m;
|
||||
seq_decl_plugin& seq;
|
||||
family_id m_fid;
|
||||
public:
|
||||
|
||||
class str {
|
||||
seq_util& u;
|
||||
ast_manager& m;
|
||||
family_id m_fid;
|
||||
public:
|
||||
str(seq_util& u):u(u), m(u.m), m_fid(u.m_fid) {}
|
||||
|
||||
app* mk_string(symbol const& s);
|
||||
app* mk_string(char const* s) { return mk_string(symbol(s)); }
|
||||
app* mk_concat(expr* a, expr* b) { expr* es[2] = { a, b }; return m.mk_app(m_fid, OP_STRING_CONCAT, 2, es); }
|
||||
app* mk_length(expr* a) { return m.mk_app(m_fid, OP_STRING_LENGTH, 1, &a); }
|
||||
app* mk_substr(expr* a, expr* b, expr* c) { expr* es[3] = { a, b, c }; return m.mk_app(m_fid, OP_STRING_SUBSTR, 3, es); }
|
||||
app* mk_strctn(expr* a, expr* b) { expr* es[2] = { a, b }; return m.mk_app(m_fid, OP_STRING_STRCTN, 2, es); }
|
||||
|
||||
bool is_const(expr const * n) const { return is_app_of(n, m_fid, OP_STRING_CONST); }
|
||||
|
||||
bool is_const(expr const* n, std::string& s) const {
|
||||
return is_const(n) && (s = to_app(n)->get_decl()->get_parameter(0).get_symbol().str(), true);
|
||||
}
|
||||
|
||||
bool is_string(sort* s) const { return is_sort_of(s, m_fid, STRING_SORT); }
|
||||
bool is_concat(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_CONCAT); }
|
||||
bool is_length(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_LENGTH); }
|
||||
bool is_substr(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_SUBSTR); }
|
||||
bool is_strctn(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_STRCTN); }
|
||||
bool is_charat(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_CHARAT); }
|
||||
bool is_stridof(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_STRIDOF); }
|
||||
bool is_repl(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_STRREPL); }
|
||||
bool is_prefix(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_PREFIX); }
|
||||
bool is_suffix(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_SUFFIX); }
|
||||
bool is_itos(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_ITOS); }
|
||||
bool is_stoi(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_STOI); }
|
||||
bool is_in_regexp(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_IN_REGEXP); }
|
||||
|
||||
|
||||
MATCH_BINARY(is_concat);
|
||||
MATCH_UNARY(is_length);
|
||||
MATCH_TERNARY(is_substr);
|
||||
MATCH_BINARY(is_strctn);
|
||||
MATCH_BINARY(is_charat);
|
||||
MATCH_BINARY(is_stridof);
|
||||
MATCH_BINARY(is_repl);
|
||||
MATCH_BINARY(is_prefix);
|
||||
MATCH_BINARY(is_suffix);
|
||||
MATCH_UNARY(is_itos);
|
||||
MATCH_UNARY(is_stoi);
|
||||
MATCH_BINARY(is_in_regexp);
|
||||
};
|
||||
|
||||
class re {
|
||||
seq_util& u;
|
||||
ast_manager& m;
|
||||
family_id m_fid;
|
||||
public:
|
||||
re(seq_util& u):u(u), m(u.m), m_fid(u.m_fid) {}
|
||||
|
||||
bool is_to_regexp(expr const* n) const { return is_app_of(n, m_fid, OP_STRING_TO_REGEXP); }
|
||||
bool is_concat(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_CONCAT); }
|
||||
bool is_union(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_UNION); }
|
||||
bool is_inter(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_INTER); }
|
||||
bool is_star(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_STAR); }
|
||||
bool is_plus(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_PLUS); }
|
||||
bool is_opt(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_OPT); }
|
||||
bool is_range(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_RANGE); }
|
||||
bool is_loop(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_LOOP); }
|
||||
|
||||
MATCH_UNARY(is_to_regexp);
|
||||
MATCH_BINARY(is_concat);
|
||||
MATCH_BINARY(is_union);
|
||||
MATCH_BINARY(is_inter);
|
||||
MATCH_UNARY(is_star);
|
||||
MATCH_UNARY(is_plus);
|
||||
MATCH_UNARY(is_opt);
|
||||
|
||||
};
|
||||
str str;
|
||||
re re;
|
||||
|
||||
seq_util(ast_manager& m):
|
||||
m(m),
|
||||
seq(*static_cast<seq_decl_plugin*>(m.get_plugin(m.mk_family_id("seq")))) {
|
||||
seq(*static_cast<seq_decl_plugin*>(m.get_plugin(m.mk_family_id("seq")))),
|
||||
m_fid(seq.get_family_id()),
|
||||
str(*this),
|
||||
re(*this) {
|
||||
}
|
||||
|
||||
~seq_util() {}
|
||||
|
||||
app* mk_string(symbol const& s);
|
||||
family_id get_family_id() const { return m_fid; }
|
||||
|
||||
};
|
||||
|
||||
#endif /* SEQ_DECL_PLUGIN_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue