Skip to content

Commit 41c0294

Browse files
Add constraints from the string dependencies
We add constraints directly from the constructed graph instead of going through all the equations.
1 parent 8a7d194 commit 41c0294

File tree

4 files changed

+20
-41
lines changed

4 files changed

+20
-41
lines changed

src/solvers/refinement/string_constraint_generator.h

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class string_constraint_generatort final
105105
/// Axioms are of three kinds: universally quantified string constraint,
106106
/// not contains string constraints and simple formulas.
107107
const std::vector<exprt> &get_lemmas() const;
108+
void add_lemma(const exprt &);
108109
const std::vector<string_constraintt> &get_constraints() const;
109110
const std::vector<string_not_contains_constraintt> &
110111
get_not_contains_constraints() const;

src/solvers/refinement/string_constraint_generator_main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ const std::vector<exprt> &string_constraint_generatort::get_lemmas() const
3939
return lemmas;
4040
}
4141

42+
void string_constraint_generatort::add_lemma(const exprt &expr)
43+
{
44+
lemmas.push_back(expr);
45+
}
46+
4247
const std::vector<string_constraintt> &
4348
string_constraint_generatort::get_constraints() const
4449
{

src/solvers/refinement/string_refinement.cpp

+10-40
Original file line numberDiff line numberDiff line change
@@ -251,41 +251,6 @@ static std::vector<exprt> generate_instantiations(
251251
return lemmas;
252252
}
253253

254-
/// Remove functions applications and create the necessary axioms.
255-
/// \param expr: an expression possibly containing function applications
256-
/// \param generator: generator for the string constraints
257-
/// \return an expression containing no function application
258-
static void substitute_function_applications(
259-
exprt &expr,
260-
string_constraint_generatort &generator)
261-
{
262-
for(auto it = expr.depth_begin(), itend = expr.depth_end();
263-
it != itend;) // No ++it
264-
{
265-
if(it->id() == ID_function_application)
266-
{
267-
it.mutate() =
268-
generator.add_axioms_for_function_application(
269-
to_function_application_expr(expr));
270-
it.next_sibling_or_parent();
271-
}
272-
else
273-
++it;
274-
}
275-
}
276-
277-
/// Remove functions applications and create the necessary axioms.
278-
/// \param equations: vector of equations
279-
/// \param generator: generator for the string constraints
280-
/// \return vector of equations where function application have been replaced
281-
static void substitute_function_applications_in_equations(
282-
std::vector<equal_exprt> &equations,
283-
string_constraint_generatort &generator)
284-
{
285-
for(auto &eq : equations)
286-
substitute_function_applications(eq.rhs(), generator);
287-
}
288-
289254
/// Fill the array_pointer correspondence and replace the right hand sides of
290255
/// the corresponding equations
291256
static void make_char_array_pointer_associations(
@@ -680,17 +645,22 @@ decision_proceduret::resultt string_refinementt::dec_solve()
680645
output_equations(debug(), equations, ns);
681646
#endif
682647

683-
debug() << "dec_solve: compute dependency graph:" << eom;
684-
for(const equal_exprt &eq : equations)
685-
add_node(dependencies, eq, generator.array_pool);
648+
debug() << "dec_solve: compute dependency graph and remove function "
649+
<< "applications captured by the dependencies:" << eom;
650+
const auto new_equation_end = std::remove_if(
651+
equations.begin(), equations.end(), [&](const equal_exprt &eq) { // NOLINT
652+
return add_node(dependencies, eq, generator.array_pool);
653+
});
654+
equations.erase(new_equation_end, equations.end());
686655

687656
#ifdef DEBUG
688657
dependencies.output_dot(debug());
689658
#endif
690659

691-
debug() << "dec_solve: Replace function applications" << eom;
660+
debug() << "dec_solve: add constraints" << eom;
692661
// Generator is also used by get, that's why we use a class member
693-
substitute_function_applications_in_equations(equations, generator);
662+
dependencies.add_constraints(generator);
663+
694664
#ifdef DEBUG
695665
output_equations(debug(), equations, ns);
696666
#endif

src/solvers/refinement/string_refinement_util.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,8 @@ void string_dependenciest::add_constraints(
419419
string_constraint_generatort &generator)
420420
{
421421
for(const auto &builtin : builtin_function_nodes)
422-
builtin->add_constraints(generator);
422+
{
423+
const exprt return_value = builtin->add_constraints(generator);
424+
generator.add_lemma(equal_exprt(return_value, builtin->return_code));
425+
}
423426
}

0 commit comments

Comments
 (0)