Skip to content

Commit 0d524ee

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#1893 from diffblue/expression-printer
Expression printer
2 parents 48024c7 + 5de436b commit 0d524ee

20 files changed

+463
-128
lines changed

src/solvers/flattening/arrays.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ Author: Daniel Kroening, [email protected]
88

99
#include "arrays.h"
1010

11-
#include <langapi/language_util.h>
12-
13-
#include <util/std_expr.h>
14-
#include <util/std_types.h>
1511
#include <util/arith_tools.h>
1612
#include <util/base_type.h>
13+
#include <util/format_expr.h>
1714
#include <util/namespace.h>
15+
#include <util/std_expr.h>
16+
#include <util/std_types.h>
1817

1918
#include <solvers/prop/prop.h>
2019

@@ -402,10 +401,8 @@ void arrayst::update_index_map(bool update_all)
402401
for(const auto &index : index_entry.second)
403402
std::cout << "Index set (" << index_entry.first << " = "
404403
<< arrays.find_number(index_entry.first) << " = "
405-
<< from_expr(ns, "",
406-
arrays[arrays.find_number(index_entry.first)])
407-
<< "): "
408-
<< from_expr(ns, "", index) << '\n';
404+
<< format(arrays[arrays.find_number(index_entry.first)])
405+
<< "): " << format(index) << '\n';
409406
std::cout << "-----\n";
410407
#endif
411408
}

src/solvers/flattening/boolbv_equality.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/std_expr.h>
1414
#include <util/base_type.h>
1515

16-
#include <langapi/language_util.h>
17-
1816
#include "flatten_byte_operators.h"
1917

2018
literalt boolbvt::convert_equality(const equal_exprt &expr)

src/solvers/prop/bdd_expr.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig, [email protected]
1111

1212
#include "bdd_expr.h"
1313

14-
#include <langapi/language_util.h>
15-
1614
#include <util/std_expr.h>
1715
#include <util/expr_util.h>
16+
#include <util/format_expr.h>
17+
18+
#include <sstream>
1819

1920
mini_bddt bdd_exprt::from_expr_rec(const exprt &expr)
2021
{
@@ -83,8 +84,9 @@ mini_bddt bdd_exprt::from_expr_rec(const exprt &expr)
8384

8485
if(entry.second)
8586
{
86-
std::string s=::from_expr(ns, "", expr);
87-
entry.first->second=bdd_mgr.Var(s);
87+
std::ostringstream s;
88+
s << format(expr);
89+
entry.first->second=bdd_mgr.Var(s.str());
8890

8991
node_map.insert(std::make_pair(entry.first->second.var(),
9092
expr));

src/solvers/qbf/qbf_bdd_core.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Author: CM Wintersteiger
1414
#include <util/arith_tools.h>
1515
#include <util/std_expr.h>
1616

17-
#include <langapi/language_util.h>
18-
1917
#include <cuddObj.hh> // CUDD Library
2018

2119
/*! \cond */

src/solvers/refinement/refine_arrays.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Author: Daniel Kroening, [email protected]
1010

1111
#ifdef DEBUG
1212
#include <iostream>
13-
#include <langapi/language_util.h>
1413
#endif
1514

1615
#include <util/std_expr.h>

src/solvers/refinement/string_constraint.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ Author: Romain Brenguier, [email protected]
2020
#ifndef CPROVER_SOLVERS_REFINEMENT_STRING_CONSTRAINT_H
2121
#define CPROVER_SOLVERS_REFINEMENT_STRING_CONSTRAINT_H
2222

23-
#include <solvers/refinement/bv_refinement.h>
24-
#include <solvers/refinement/string_refinement_invariant.h>
23+
#include "bv_refinement.h"
24+
#include "string_refinement_invariant.h"
25+
26+
#include <util/format_expr.h>
27+
#include <util/format_type.h>
2528
#include <util/refined_string_type.h>
2629
#include <util/string_expr.h>
27-
#include <langapi/language_util.h>
2830

2931
/// ### Universally quantified string constraint
3032
///
@@ -147,15 +149,14 @@ extern inline string_constraintt &to_string_constraint(exprt &expr)
147149
/// \param [in] expr: constraint to render
148150
/// \return rendered string
149151
inline std::string from_expr(
150-
const namespacet &ns,
151152
const irep_idt &identifier,
152153
const string_constraintt &expr)
153154
{
154-
return "forall "+from_expr(ns, identifier, expr.univ_var())+" in ["+
155-
from_expr(ns, identifier, expr.lower_bound())+", "+
156-
from_expr(ns, identifier, expr.upper_bound())+"). "+
157-
from_expr(ns, identifier, expr.premise())+" => "+
158-
from_expr(ns, identifier, expr.body());
155+
std::ostringstream out;
156+
out << "forall " << format(expr.univ_var()) << " in ["
157+
<< format(expr.lower_bound()) << ", " << format(expr.upper_bound())
158+
<< "). " << format(expr.premise()) << " => " << format(expr.body());
159+
return out.str();
159160
}
160161

161162
/// Constraints to encode non containement of strings.
@@ -222,18 +223,17 @@ class string_not_contains_constraintt: public exprt
222223
/// \param [in] expr: constraint to render
223224
/// \return rendered string
224225
inline std::string from_expr(
225-
const namespacet &ns,
226226
const irep_idt &identifier,
227227
const string_not_contains_constraintt &expr)
228228
{
229-
return "forall x in ["+
230-
from_expr(ns, identifier, expr.univ_lower_bound())+", "+
231-
from_expr(ns, identifier, expr.univ_upper_bound())+"). "+
232-
from_expr(ns, identifier, expr.premise())+" => ("+
233-
"exists y in ["+from_expr(ns, identifier, expr.exists_lower_bound())+", "+
234-
from_expr(ns, identifier, expr.exists_upper_bound())+"). "+
235-
from_expr(ns, identifier, expr.s0())+"[x+y] != "+
236-
from_expr(ns, identifier, expr.s1())+"[y])";
229+
std::ostringstream out;
230+
out << "forall x in [" << format(expr.univ_lower_bound()) << ", "
231+
<< format(expr.univ_upper_bound()) << "). " << format(expr.premise())
232+
<< " => ("
233+
<< "exists y in [" << format(expr.exists_lower_bound()) << ", "
234+
<< format(expr.exists_upper_bound()) << "). " << format(expr.s0())
235+
<< "[x+y] != " << format(expr.s1()) << "[y])";
236+
return out.str();
237237
}
238238

239239
inline const string_not_contains_constraintt

0 commit comments

Comments
 (0)