Skip to content

Commit 145364c

Browse files
String refinement: Improve debug information
Debug information for arrays of pointers Debug information for check_axioms steps Refactoring: put debug information out of check_axioms Replace warning by invariant
1 parent 3e5b3f1 commit 145364c

File tree

1 file changed

+59
-38
lines changed

1 file changed

+59
-38
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ void string_refinementt::set_to(const exprt &expr, bool value)
324324
}
325325
else
326326
{
327-
if(has_char_array_subexpr(expr, ns))
328-
warning() << "WARNING: string_refinement.cpp: "
329-
"non string equation has char array subexpr";
327+
INVARIANT(
328+
!has_char_array_subexpr(expr, ns), "char array only appear in equations");
330329
supert::set_to(expr, value);
331330
}
332331
}
@@ -446,7 +445,13 @@ decision_proceduret::resultt string_refinementt::dec_solve()
446445
#endif
447446

448447
#ifdef DEBUG
449-
generator.debug_arrays_of_pointers(debug());
448+
debug() << "dec_solve: arrays_of_pointers:" << eom;
449+
for(auto pair : generator.get_arrays_of_pointers())
450+
{
451+
debug() << " * " << from_expr(ns, "", pair.first) << "\t--> "
452+
<< from_expr(ns, "", pair.second) << " : "
453+
<< from_type(ns, "", pair.second.type()) << eom;
454+
}
450455
#endif
451456

452457
for(const auto &eq : equations)
@@ -1173,6 +1178,44 @@ exprt concretize_arrays_in_expression(
11731178
return expr;
11741179
}
11751180

1181+
/// Debugging function which outputs the different steps an axiom goes through
1182+
/// to be checked in check axioms.
1183+
static void debug_check_axioms_step(
1184+
messaget::mstreamt &stream,
1185+
const namespacet &ns,
1186+
const exprt &axiom,
1187+
const exprt &axiom_in_model,
1188+
const exprt &negaxiom,
1189+
const exprt &with_concretized_arrays)
1190+
{
1191+
static const std::string indent = " ";
1192+
static const std::string indent2 = " ";
1193+
stream << indent2 << "- axiom:\n" << indent2 << indent;
1194+
1195+
if(axiom.id() == ID_string_constraint)
1196+
stream << from_expr(ns, "", to_string_constraint(axiom));
1197+
else if(axiom.id() == ID_string_not_contains_constraint)
1198+
stream << from_expr(ns, "", to_string_not_contains_constraint(axiom));
1199+
else
1200+
stream << from_expr(ns, "", axiom);
1201+
stream << '\n' << indent2 << "- axiom_in_model:\n" << indent2 << indent;
1202+
1203+
if(axiom_in_model.id() == ID_string_constraint)
1204+
stream << from_expr(ns, "", to_string_constraint(axiom_in_model));
1205+
else if(axiom_in_model.id() == ID_string_not_contains_constraint)
1206+
stream << from_expr(
1207+
ns, "", to_string_not_contains_constraint(axiom_in_model));
1208+
else
1209+
stream << from_expr(ns, "", axiom_in_model);
1210+
1211+
stream << '\n'
1212+
<< indent2 << "- negated_axiom:\n"
1213+
<< indent2 << indent << from_expr(ns, "", negaxiom) << '\n';
1214+
stream << indent2 << "- negated_axiom_with_concretized_arrays:\n"
1215+
<< indent2 << indent << from_expr(ns, "", with_concretized_arrays)
1216+
<< '\n';
1217+
}
1218+
11761219
/// \return true if the current model satisfies all the axioms
11771220
/// \return a Boolean
11781221
static std::pair<bool, std::vector<exprt>> check_axioms(
@@ -1227,28 +1270,14 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
12271270
univ_var, get(bound_inf), get(bound_sup), get(prem), get(body));
12281271

12291272
exprt negaxiom=negation_of_constraint(axiom_in_model);
1230-
1231-
stream << indent << i << ".\n"
1232-
<< indent2 << "- axiom:\n"
1233-
<< indent2 << indent << from_expr(ns, "", axiom) << '\n';
1234-
stream << indent2 << "- axiom_in_model:\n"
1235-
<< indent2 << indent << from_expr(ns, "", axiom_in_model) << '\n';
1236-
stream << indent2 << "- negated_axiom:\n"
1237-
<< indent2 << indent << from_expr(ns, "", negaxiom) << '\n';
12381273
negaxiom = simplify_expr(negaxiom, ns);
1239-
stream << indent2 << "- simplified_negaxiom:\n"
1240-
<< indent2 << indent << from_expr(ns, "", negaxiom) << '\n';
1241-
12421274
exprt with_concretized_arrays =
12431275
concretize_arrays_in_expression(negaxiom, max_string_length, ns);
1244-
stream << indent2 << "- negated_axiom_with_concretized_array_access:\n"
1245-
<< indent2 << indent << from_expr(ns, "", with_concretized_arrays)
1246-
<< '\n';
1247-
12481276
substitute_array_access(with_concretized_arrays);
1249-
stream << indent2 << "- negated_axiom_without_array_access:\n"
1250-
<< indent2 << indent << from_expr(ns, "", with_concretized_arrays)
1251-
<< eom;
1277+
1278+
stream << indent << i << ".\n";
1279+
debug_check_axioms_step(
1280+
stream, ns, axiom, axiom_in_model, negaxiom, with_concretized_arrays);
12521281

12531282
if(const auto &witness=
12541283
find_counter_example(ns, ui, with_concretized_arrays, univ_var))
@@ -1290,24 +1319,16 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
12901319

12911320
exprt negaxiom =
12921321
negation_of_not_contains_constraint(nc_axiom_in_model, univ_var);
1293-
stream << indent << i << ".\n"
1294-
<< indent2 << "- axiom:\n"
1295-
<< indent2 << indent << from_expr(ns, "", nc_axiom) << '\n';
1296-
stream << indent2 << "- axiom_in_model:\n"
1297-
<< indent2 << indent << from_expr(ns, "", nc_axiom_in_model) << '\n';
1298-
stream << indent2 << "- negated_axiom:\n"
1299-
<< indent2 << indent << from_expr(ns, "", negaxiom) << '\n';
13001322

13011323
negaxiom = simplify_expr(negaxiom, ns);
1302-
stream << indent2 << "- simplified_negaxiom:\n"
1303-
<< indent2 << indent << from_expr(ns, "", negaxiom) << '\n';
1304-
negaxiom = concretize_arrays_in_expression(negaxiom, max_string_length, ns);
1305-
stream << indent2 << "- negated_axiom_with_concretized_array_access:\n"
1306-
<< indent2 << indent << from_expr(ns, "", negaxiom) << '\n';
1307-
1308-
substitute_array_access(negaxiom);
1309-
stream << indent2 << "- negated_axiom_without_array_access:\n"
1310-
<< indent2 << indent << from_expr(ns, "", negaxiom) << eom;
1324+
exprt with_concrete_arrays =
1325+
concretize_arrays_in_expression(negaxiom, max_string_length, ns);
1326+
1327+
substitute_array_access(with_concrete_arrays);
1328+
1329+
stream << indent << i << ".\n";
1330+
debug_check_axioms_step(
1331+
stream, ns, nc_axiom, nc_axiom_in_model, negaxiom, with_concrete_arrays);
13111332

13121333
if(const auto witness = find_counter_example(ns, ui, negaxiom, univ_var))
13131334
{

0 commit comments

Comments
 (0)