Skip to content

Commit 01b8301

Browse files
author
Lukasz A.J. Wrona
committed
static is_valid_string_constraint
1 parent cfb47db commit 01b8301

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/solvers/refinement/string_refinement.cpp

+23-14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ static bool is_char_array(const namespacet &ns, const typet &type);
4242
exprt substitute_array_lists(exprt expr, size_t string_max_length);
4343
exprt concretize_arrays_in_expression(
4444
exprt expr, std::size_t string_max_length);
45+
static bool is_valid_string_constraint(
46+
messaget::mstreamt& stream,
47+
const namespacet& ns,
48+
const string_constraintt &expr);
4549

4650
exprt simplify_sum(const exprt &f);
4751

@@ -563,12 +567,14 @@ decision_proceduret::resultt string_refinementt::dec_solve()
563567
replace_expr(symbol_resolve, axiom);
564568
if(axiom.id()==ID_string_constraint)
565569
{
566-
string_constraintt c=to_string_constraint(axiom);
570+
string_constraintt nc_axiom=
571+
to_string_constraint(axiom);
572+
is_valid_string_constraint(error(), ns, nc_axiom);
567573
DATA_INVARIANT(
568-
is_valid_string_constraint(c),
574+
is_valid_string_constraint(error(), ns, nc_axiom),
569575
string_refinement_invariantt(
570576
"string constraints satisfy their invariant"));
571-
universal_axioms.push_back(c);
577+
universal_axioms.push_back(nc_axiom);
572578
}
573579
else if(axiom.id()==ID_string_not_contains_constraint)
574580
{
@@ -1938,21 +1944,24 @@ static bool universal_only_in_index(const string_constraintt &expr)
19381944
/// \related string_constraintt
19391945
/// \param [in] expr: the string constraint to check
19401946
/// \return whether the constraint satisfies the invariant
1941-
bool string_refinementt::is_valid_string_constraint(
1947+
static bool is_valid_string_constraint(
1948+
messaget::mstreamt& stream,
1949+
const namespacet& ns,
19421950
const string_constraintt &expr)
19431951
{
1952+
const auto eom = messaget::eom;
19441953
// Condition 1: The premise cannot contain any string indices
19451954
const array_index_mapt premise_indices=gather_indices(expr.premise());
19461955
if(!premise_indices.empty())
19471956
{
1948-
error() << "Premise has indices: " << from_expr(ns, "", expr) << ", map: {";
1957+
stream << "Premise has indices: " << from_expr(ns, "", expr) << ", map: {";
19491958
for(const auto &pair : premise_indices)
19501959
{
1951-
error() << from_expr(ns, "", pair.first) << ": {";
1960+
stream << from_expr(ns, "", pair.first) << ": {";
19521961
for(const auto &i : pair.second)
1953-
error() << from_expr(ns, "", i) << ", ";
1962+
stream << from_expr(ns, "", i) << ", ";
19541963
}
1955-
error() << "}}" << eom;
1964+
stream << "}}" << eom;
19561965
return false;
19571966
}
19581967

@@ -1970,26 +1979,26 @@ bool string_refinementt::is_valid_string_constraint(
19701979
const exprt result=simplify_expr(equals, ns);
19711980
if(result.is_false())
19721981
{
1973-
error() << "Indices not equal: " << from_expr(ns, "", expr) << ", str: "
1974-
<< from_expr(ns, "", pair.first) << eom;
1982+
stream << "Indices not equal: " << from_expr(ns, "", expr) << ", str: "
1983+
<< from_expr(ns, "", pair.first) << eom;
19751984
return false;
19761985
}
19771986
}
19781987

19791988
// Condition 3: f must be linear
19801989
if(!is_linear_arithmetic_expr(rep))
19811990
{
1982-
error() << "f is not linear: " << from_expr(ns, "", expr) << ", str: "
1983-
<< from_expr(ns, "", pair.first) << eom;
1991+
stream << "f is not linear: " << from_expr(ns, "", expr) << ", str: "
1992+
<< from_expr(ns, "", pair.first) << eom;
19841993
return false;
19851994
}
19861995

19871996
// Condition 4: the quantified variable can only occur in indices in the
19881997
// body
19891998
if(!universal_only_in_index(expr))
19901999
{
1991-
error() << "Universal variable outside of index:"
1992-
<< from_expr(ns, "", expr) << eom;
2000+
stream << "Universal variable outside of index:"
2001+
<< from_expr(ns, "", expr) << eom;
19932002
return false;
19942003
}
19952004
}

src/solvers/refinement/string_refinement.h

-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ class string_refinementt final: public bv_refinementt
127127

128128
std::map<exprt, int> map_representation_of_sum(const exprt &f) const;
129129

130-
bool is_valid_string_constraint(const string_constraintt &expr);
131-
132130
void concretize_string(const exprt &expr);
133131
void concretize_results();
134132
void concretize_lengths();

0 commit comments

Comments
 (0)