mirror of
https://github.com/Z3Prover/z3
synced 2025-10-05 07:23:58 +00:00
decl and rewriter for Indexof (WIP)
This commit is contained in:
parent
7aeeb599ef
commit
db2a5854e9
4 changed files with 31 additions and 0 deletions
|
@ -112,6 +112,24 @@ br_status str_rewriter::mk_str_Contains(expr * haystack, expr * needle, expr_ref
|
|||
}
|
||||
}
|
||||
|
||||
br_status str_rewriter::mk_str_Indexof(expr * haystack, expr * needle, expr_ref & result) {
|
||||
TRACE("t_str_rw", tout << "rewrite (Indexof " << mk_pp(haystack, m()) << " " << mk_pp(needle, m()) << ")" << std::endl;);
|
||||
if (m_strutil.is_string(haystack) && m_strutil.is_string(needle)) {
|
||||
TRACE("t_str_rw", tout << "evaluating constant Indexof expression" << std::endl;);
|
||||
std::string haystackStr = m_strutil.get_string_constant_value(haystack);
|
||||
std::string needleStr = m_strutil.get_string_constant_value(needle);
|
||||
if (haystackStr.find(needleStr) != std::string::npos) {
|
||||
int index = haystackStr.find(needleStr);
|
||||
result = m_autil.mk_numeral(rational(index), true);
|
||||
} else {
|
||||
result = m_autil.mk_numeral(rational(-1), true);
|
||||
}
|
||||
return BR_DONE;
|
||||
} else {
|
||||
return BR_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
br_status str_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * const * args, expr_ref & result) {
|
||||
SASSERT(f->get_family_id() == get_fid());
|
||||
|
||||
|
@ -131,6 +149,9 @@ br_status str_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * con
|
|||
case OP_STR_CONTAINS:
|
||||
SASSERT(num_args == 2);
|
||||
return mk_str_Contains(args[0], args[1], result);
|
||||
case OP_STR_INDEXOF:
|
||||
SASSERT(num_args == 2);
|
||||
return mk_str_Indexof(args[0], args[1], result);
|
||||
default:
|
||||
return BR_FAILED;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
br_status mk_str_StartsWith(expr * haystack, expr * needle, expr_ref & result);
|
||||
br_status mk_str_EndsWith(expr * haystack, expr * needle, expr_ref & result);
|
||||
br_status mk_str_Contains(expr * haystack, expr * needle, expr_ref & result);
|
||||
br_status mk_str_Indexof(expr * haystack, expr * needle, expr_ref & result);
|
||||
|
||||
bool reduce_eq(expr * l, expr * r, expr_ref_vector & lhs, expr_ref_vector & rhs, bool & change);
|
||||
bool reduce_eq(expr_ref_vector& ls, expr_ref_vector& rs, expr_ref_vector& lhs, expr_ref_vector& rhs, bool& change);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue