Skip to content

Commit db33b01

Browse files
Add a linear_functiont::format for debugging
This can be useful for debugging or testing the class.
1 parent ce4e808 commit db33b01

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/solvers/strings/string_constraint_instantiation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ exprt linear_functiont::solve(
156156
return f.to_expr(positive);
157157
}
158158

159+
std::string linear_functiont::format()
160+
{
161+
std::ostringstream stream;
162+
stream << constant_coefficient;
163+
for(const auto &pair : coefficients)
164+
stream << " + " << pair.second << " * " << ::format(pair.first);
165+
return stream.str();
166+
}
167+
159168
/// Instantiates a string constraint by substituting the quantifiers.
160169
/// For a string constraint of the form `forall q. P(x)`,
161170
/// substitute `q` the universally quantified variable of `axiom`, by

src/solvers/strings/string_constraint_instantiation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class linear_functiont
5858
/// returns the expression `v - x`.
5959
static exprt solve(linear_functiont f, const exprt &var, const exprt &val);
6060

61+
/// Format the linear function as a string, can be used for debugging
62+
std::string format();
63+
6164
private:
6265
mp_integer constant_coefficient;
6366
std::unordered_map<exprt, mp_integer, irep_hash> coefficients;

0 commit comments

Comments
 (0)