mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 11:55:51 +00:00
merge seq and string operators
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
70b10d53cf
commit
8bb73c8eae
6 changed files with 186 additions and 145 deletions
|
@ -11,10 +11,12 @@ Abstract:
|
|||
|
||||
Author:
|
||||
|
||||
Nikolaj Bjorner (nbjorner) 2011-14-11
|
||||
Nikolaj Bjorner (nbjorner) 2011-11-14
|
||||
|
||||
Revision History:
|
||||
|
||||
Updated to string sequences 2015-12-5
|
||||
|
||||
--*/
|
||||
#ifndef SEQ_DECL_PLUGIN_H_
|
||||
#define SEQ_DECL_PLUGIN_H_
|
||||
|
@ -25,20 +27,22 @@ Revision History:
|
|||
enum seq_sort_kind {
|
||||
SEQ_SORT,
|
||||
RE_SORT,
|
||||
STRING_SORT,
|
||||
CHAR_SORT
|
||||
_STRING_SORT, // internal only
|
||||
_CHAR_SORT // internal only
|
||||
};
|
||||
|
||||
enum seq_op_kind {
|
||||
OP_SEQ_UNIT,
|
||||
OP_SEQ_EMPTY,
|
||||
OP_SEQ_CONCAT,
|
||||
OP_SEQ_PREFIX_OF,
|
||||
OP_SEQ_SUFFIX_OF,
|
||||
OP_SEQ_SUBSEQ_OF,
|
||||
OP_SEQ_PREFIX,
|
||||
OP_SEQ_SUFFIX,
|
||||
OP_SEQ_CONTAINS,
|
||||
OP_SEQ_EXTRACT,
|
||||
OP_SEQ_NTH,
|
||||
OP_SEQ_AT,
|
||||
OP_SEQ_LENGTH,
|
||||
OP_SEQ_TO_RE,
|
||||
OP_SEQ_IN_RE,
|
||||
|
||||
OP_RE_PLUS,
|
||||
OP_RE_STAR,
|
||||
|
@ -51,28 +55,26 @@ enum seq_op_kind {
|
|||
OP_RE_EMPTY_SET,
|
||||
OP_RE_FULL_SET,
|
||||
OP_RE_EMPTY_SEQ,
|
||||
OP_RE_OF_SEQ,
|
||||
OP_RE_OF_PRED,
|
||||
OP_RE_MEMBER,
|
||||
|
||||
|
||||
// string specific operators.
|
||||
OP_STRING_CONST,
|
||||
_OP_STRING_CONCAT,
|
||||
OP_STRING_LENGTH,
|
||||
OP_STRING_SUBSTR,
|
||||
OP_STRING_STRCTN,
|
||||
OP_STRING_CHARAT,
|
||||
OP_STRING_STRIDOF,
|
||||
OP_STRING_STRREPL,
|
||||
OP_STRING_PREFIX,
|
||||
OP_STRING_SUFFIX,
|
||||
OP_STRING_STRIDOF, // TBD generalize
|
||||
OP_STRING_STRREPL, // TBD generalize
|
||||
OP_STRING_ITOS,
|
||||
OP_STRING_STOI,
|
||||
OP_STRING_IN_REGEXP,
|
||||
OP_STRING_TO_REGEXP,
|
||||
OP_REGEXP_LOOP,
|
||||
|
||||
OP_REGEXP_LOOP, // TBD re-loop: integers as parameters or arguments?
|
||||
// internal only operators. Converted to SEQ variants.
|
||||
_OP_STRING_CONCAT,
|
||||
_OP_STRING_LENGTH,
|
||||
_OP_STRING_STRCTN,
|
||||
_OP_STRING_PREFIX,
|
||||
_OP_STRING_SUFFIX,
|
||||
_OP_STRING_IN_REGEXP,
|
||||
_OP_STRING_TO_REGEXP,
|
||||
_OP_STRING_CHARAT,
|
||||
_OP_STRING_SUBSTR,
|
||||
LAST_SEQ_OP
|
||||
};
|
||||
|
||||
|
@ -110,6 +112,9 @@ class seq_decl_plugin : public decl_plugin {
|
|||
|
||||
bool is_sort_param(sort* s, unsigned& idx);
|
||||
|
||||
func_decl* mk_seq_fun(decl_kind k, unsigned arity, sort* const* domain, sort* range, decl_kind k_string);
|
||||
func_decl* mk_str_fun(decl_kind k, unsigned arity, sort* const* domain, sort* range, decl_kind k_seq);
|
||||
|
||||
void init();
|
||||
|
||||
virtual void set_manager(ast_manager * m, family_id id);
|
||||
|
@ -150,6 +155,7 @@ public:
|
|||
|
||||
bool is_string(sort* s) const { return is_seq(s) && seq.is_char(s->get_parameter(0).get_ast()); }
|
||||
bool is_seq(sort* s) const { return is_sort_of(s, m_fid, SEQ_SORT); }
|
||||
bool is_re(sort* s) const { return is_sort_of(s, m_fid, RE_SORT); }
|
||||
|
||||
class str {
|
||||
seq_util& u;
|
||||
|
@ -162,45 +168,46 @@ public:
|
|||
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())); }
|
||||
app* mk_concat(expr* a, expr* b) { expr* es[2] = { a, b }; return m.mk_app(m_fid, OP_SEQ_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); }
|
||||
app* mk_length(expr* a) { return m.mk_app(m_fid, OP_SEQ_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_SEQ_EXTRACT, 3, es); }
|
||||
app* mk_strctn(expr* a, expr* b) { expr* es[2] = { a, b }; return m.mk_app(m_fid, OP_SEQ_CONTAINS, 2, es); }
|
||||
|
||||
bool is_const(expr const * n) const { return is_app_of(n, m_fid, OP_STRING_CONST); }
|
||||
bool is_string(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(expr const* n, std::string& s) const {
|
||||
return is_string(n) && (s = to_app(n)->get_decl()->get_parameter(0).get_symbol().str(), true);
|
||||
}
|
||||
bool is_const(expr const* n, symbol& s) const {
|
||||
return is_const(n) && (s = to_app(n)->get_decl()->get_parameter(0).get_symbol(), true);
|
||||
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_empty(expr const* n) const { symbol s; return is_app_of(n, m_fid, OP_SEQ_EMPTY) || (is_string(n, s) && !s.is_numerical() && strcmp(s.bare_str(),"") == 0); }
|
||||
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_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_length(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_LENGTH); }
|
||||
bool is_extract(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_EXTRACT); }
|
||||
bool is_contains(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_CONTAINS); }
|
||||
bool is_at(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_AT); }
|
||||
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_prefix(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_PREFIX); }
|
||||
bool is_suffix(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_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); }
|
||||
bool is_in_re(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_IN_RE); }
|
||||
|
||||
|
||||
MATCH_BINARY(is_concat);
|
||||
MATCH_UNARY(is_length);
|
||||
MATCH_TERNARY(is_substr);
|
||||
MATCH_BINARY(is_strctn);
|
||||
MATCH_BINARY(is_charat);
|
||||
MATCH_TERNARY(is_extract);
|
||||
MATCH_BINARY(is_contains);
|
||||
MATCH_BINARY(is_at);
|
||||
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);
|
||||
MATCH_BINARY(is_in_re);
|
||||
|
||||
void get_concat(expr* e, ptr_vector<expr>& es) const;
|
||||
};
|
||||
|
@ -212,7 +219,7 @@ public:
|
|||
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_to_re(expr const* n) const { return is_app_of(n, m_fid, OP_SEQ_TO_RE); }
|
||||
bool is_concat(expr const* n) const { return is_app_of(n, m_fid, OP_RE_CONCAT); }
|
||||
bool is_union(expr const* n) const { return is_app_of(n, m_fid, OP_RE_UNION); }
|
||||
bool is_inter(expr const* n) const { return is_app_of(n, m_fid, OP_RE_INTERSECT); }
|
||||
|
@ -222,7 +229,7 @@ public:
|
|||
bool is_range(expr const* n) const { return is_app_of(n, m_fid, OP_RE_RANGE); }
|
||||
bool is_loop(expr const* n) const { return is_app_of(n, m_fid, OP_REGEXP_LOOP); }
|
||||
|
||||
MATCH_UNARY(is_to_regexp);
|
||||
MATCH_UNARY(is_to_re);
|
||||
MATCH_BINARY(is_concat);
|
||||
MATCH_BINARY(is_union);
|
||||
MATCH_BINARY(is_inter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue