Skip to content

Commit 8f4e7f4

Browse files
fix #2533
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 9fce5e1 commit 8f4e7f4

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/ast/for_each_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ subterms::iterator& subterms::iterator::operator++() {
8787
m_es.push_back(arg);
8888
}
8989
}
90-
while (m_visited.is_marked(m_es.back())) {
90+
while (!m_es.empty() && m_visited.is_marked(m_es.back())) {
9191
m_es.pop_back();
9292
}
9393
return *this;

src/ast/rewriter/seq_rewriter.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ br_status seq_rewriter::mk_app_core(func_decl * f, unsigned num_args, expr * con
547547
case _OP_STRING_STRIDOF:
548548
UNREACHABLE();
549549
}
550-
CTRACE("seq_verbose", st != BR_FAILED, tout << result << "\n";);
550+
CTRACE("seq_verbose", st != BR_FAILED, tout << f->get_name() << " " << result << "\n";);
551551
return st;
552552
}
553553

@@ -1142,16 +1142,35 @@ br_status seq_rewriter::mk_seq_replace(expr* a, expr* b, expr* c, expr_ref& resu
11421142
result = m_util.str.mk_concat(c, a);
11431143
return BR_REWRITE1;
11441144
}
1145-
1146-
if (m_util.str.is_string(b, s2)) {
1147-
m_lhs.reset();
1148-
m_util.str.get_concat(a, m_lhs);
1149-
if (!m_lhs.empty() && m_util.str.is_string(m_lhs.get(0), s1) &&
1150-
s1.contains(s2)) {
1151-
m_lhs[0] = m_util.str.mk_string(s1.replace(s2, s3));
1152-
result = m_util.str.mk_concat(m_lhs.size(), m_lhs.c_ptr());
1153-
return BR_REWRITE1;
1145+
1146+
m_lhs.reset();
1147+
m_util.str.get_concat(a, m_lhs);
1148+
1149+
// a = "", |b| > 0 -> replace("",b,c) = ""
1150+
if (m_lhs.empty()) {
1151+
unsigned len = 0;
1152+
m_util.str.get_concat(b, m_lhs);
1153+
min_length(m_lhs.size(), m_lhs.c_ptr(), len);
1154+
if (len > 0) {
1155+
result = a;
1156+
return BR_DONE;
11541157
}
1158+
return BR_FAILED;
1159+
}
1160+
1161+
// a := b + rest
1162+
if (m_lhs.get(0) == b) {
1163+
m_lhs[0] = c;
1164+
result = m_util.str.mk_concat(m_lhs.size(), m_lhs.c_ptr());
1165+
return BR_REWRITE1;
1166+
}
1167+
1168+
// a : a' + rest string, b is string, c is string, a' contains b
1169+
if (m_util.str.is_string(b, s2) && m_util.str.is_string(c, s3) &&
1170+
m_util.str.is_string(m_lhs.get(0), s1) && s1.contains(s2) ) {
1171+
m_lhs[0] = m_util.str.mk_string(s1.replace(s2, s3));
1172+
result = m_util.str.mk_concat(m_lhs.size(), m_lhs.c_ptr());
1173+
return BR_REWRITE1;
11551174
}
11561175

11571176
return BR_FAILED;

0 commit comments

Comments
 (0)