Skip to content

Commit b0bf2f1

Browse files
mtrberziNikolajBjorner
authored andcommitted
z3str3: recognize two-argument re.loop
1 parent 82c39f8 commit b0bf2f1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/smt/theory_str.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,11 +1922,17 @@ namespace smt {
19221922
} else if (u.re.is_loop(a_regex)) {
19231923
expr * body;
19241924
unsigned lo, hi;
1925-
u.re.is_loop(a_regex, body, lo, hi);
1926-
rational rLo(lo);
1927-
rational rHi(hi);
1928-
zstring bodyStr = get_std_regex_str(body);
1929-
return zstring("(") + bodyStr + zstring("{") + zstring(rLo.to_string().c_str()) + zstring(",") + zstring(rHi.to_string().c_str()) + zstring("})");
1925+
// There are two variants of loop: a 2-argument version and a 3-argument version.
1926+
if (u.re.is_loop(a_regex, body, lo, hi)) {
1927+
rational rLo(lo);
1928+
rational rHi(hi);
1929+
zstring bodyStr = get_std_regex_str(body);
1930+
return zstring("(") + bodyStr + zstring("{") + zstring(rLo.to_string().c_str()) + zstring(",") + zstring(rHi.to_string().c_str()) + zstring("})");
1931+
} else if (u.re.is_loop(a_regex, body, lo)) {
1932+
rational rLo(lo);
1933+
zstring bodyStr = get_std_regex_str(body);
1934+
return zstring("(") + bodyStr + zstring("{") + zstring(rLo.to_string().c_str()) + zstring("+") + zstring("})");
1935+
}
19301936
} else if (u.re.is_full_seq(a_regex)) {
19311937
return zstring("(.*)");
19321938
} else if (u.re.is_full_char(a_regex)) {
@@ -6732,7 +6738,7 @@ namespace smt {
67326738
} else if (u.re.is_star(re, sub1) || u.re.is_plus(re, sub1)) {
67336739
unsigned cx = estimate_regex_complexity(sub1);
67346740
return _qmul(2, cx);
6735-
} else if (u.re.is_loop(re, sub1, lo, hi)) {
6741+
} else if (u.re.is_loop(re, sub1, lo, hi) || u.re.is_loop(re, sub1, lo)) {
67366742
unsigned cx = estimate_regex_complexity(sub1);
67376743
return _qadd(lo, cx);
67386744
} else if (u.re.is_range(re, sub1, sub2)) {
@@ -6775,7 +6781,7 @@ namespace smt {
67756781
unsigned cx1 = estimate_regex_complexity_under_complement(sub1);
67766782
unsigned cx2 = estimate_regex_complexity_under_complement(sub2);
67776783
return _qmul(cx1, cx2);
6778-
} else if (u.re.is_star(re, sub1) || u.re.is_plus(re, sub1) || u.re.is_loop(re, sub1, lo, hi)) {
6784+
} else if (u.re.is_star(re, sub1) || u.re.is_plus(re, sub1) || u.re.is_loop(re, sub1, lo, hi) || u.re.is_loop(re, sub1, lo)) {
67796785
unsigned cx = estimate_regex_complexity_under_complement(sub1);
67806786
return _qmul(2, cx);
67816787
} else if (u.re.is_range(re, sub1, sub2)) {
@@ -6831,7 +6837,7 @@ namespace smt {
68316837
} else if (u.re.is_complement(re)) {
68326838
// TODO can we do better?
68336839
return false;
6834-
} else if (u.re.is_loop(re, sub1, lo, hi)) {
6840+
} else if (u.re.is_loop(re, sub1, lo, hi) || u.re.is_loop(re, sub1, lo)) {
68356841
return check_regex_length_linearity_helper(sub1, already_star);
68366842
} else {
68376843
TRACE("str", tout << "WARNING: unknown regex term " << mk_pp(re, get_manager()) << std::endl;);

0 commit comments

Comments
 (0)