Skip to content

Commit 6505e8c

Browse files
Merge pull request diffblue#1875 from peterschrammel/remove-cout-solvers
Replace cout/cerr in solvers
2 parents 066ba51 + 26ef31c commit 6505e8c

File tree

11 files changed

+224
-221
lines changed

11 files changed

+224
-221
lines changed

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "cpp_typecheck.h"
1313

14-
#include <cstdlib>
14+
#ifdef DEBUG
15+
#include <iostream>
16+
#endif
1517

1618
#include <util/pointer_offset_size.h>
1719
#include <util/std_types.h>
@@ -20,6 +22,7 @@ Author: Daniel Kroening, [email protected]
2022
#include <util/config.h>
2123
#include <util/simplify_expr.h>
2224
#include <util/base_type.h>
25+
#include <util/invariant.h>
2326

2427
#include <util/c_types.h>
2528
#include <ansi-c/c_qualifiers.h>
@@ -69,25 +72,27 @@ void cpp_typecheckt::typecheck_expr_main(exprt &expr)
6972
typecheck_expr_explicit_constructor_call(expr);
7073
else if(expr.is_nil())
7174
{
72-
#if 0
75+
#ifdef DEBUG
76+
std::cerr << "E: " << expr.pretty() << '\n';
7377
std::cerr << "cpp_typecheckt::typecheck_expr_main got nil\n";
74-
#endif
75-
abort();
78+
#endif
79+
UNREACHABLE;
7680
}
7781
else if(expr.id()==ID_code)
7882
{
79-
#if 0
83+
#ifdef DEBUG
84+
std::cerr << "E: " << expr.pretty() << '\n';
8085
std::cerr << "cpp_typecheckt::typecheck_expr_main got code\n";
81-
#endif
82-
abort();
86+
#endif
87+
UNREACHABLE;
8388
}
8489
else if(expr.id()==ID_symbol)
8590
{
86-
#if 0
87-
std::cout << "E: " << expr.pretty() << '\n';
91+
// ignore here
92+
#ifdef DEBUG
93+
std::cerr << "E: " << expr.pretty() << '\n';
8894
std::cerr << "cpp_typecheckt::typecheck_expr_main got symbol\n";
89-
abort();
90-
#endif
95+
#endif
9196
}
9297
else if(expr.id()=="__is_base_of")
9398
{

src/goto-symex/goto_symex_state.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ void goto_symex_statet::level0t::operator()(
5050
return;
5151

5252
const symbolt *s;
53-
54-
if(ns.lookup(obj_identifier, s))
55-
{
56-
std::cerr << "level0: failed to find " << obj_identifier << '\n';
57-
abort();
58-
}
53+
const bool found_l0 = !ns.lookup(obj_identifier, s);
54+
DATA_INVARIANT(
55+
found_l0, "level0: failed to find " + id2string(obj_identifier));
5956

6057
// don't rename shared variables or functions
6158
if(s->type.id()==ID_code ||

src/solvers/flattening/boolbv_add_sub.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <iostream>
12-
11+
#include <util/invariant.h>
1312
#include <util/std_types.h>
1413

1514
#include "../floatbv/float_utils.h"
@@ -38,12 +37,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
3837
throw "operator "+expr.id_string()+" takes at least one operand";
3938

4039
const exprt &op0=expr.op0();
41-
42-
if(op0.type()!=type)
43-
{
44-
std::cerr << expr.pretty() << '\n';
45-
throw "add/sub with mixed types";
46-
}
40+
DATA_INVARIANT(
41+
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty());
4742

4843
bvt bv=convert_bv(op0);
4944

@@ -69,11 +64,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
6964
it=operands.begin()+1;
7065
it!=operands.end(); it++)
7166
{
72-
if(it->type()!=type)
73-
{
74-
std::cerr << expr.pretty() << '\n';
75-
throw "add/sub with mixed types";
76-
}
67+
DATA_INVARIANT(
68+
it->type() == type, "add/sub with mixed types:\n" + expr.pretty());
7769

7870
const bvt &op=convert_bv(*it);
7971

src/solvers/flattening/boolbv_case.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <iostream>
11+
#include <util/invariant.h>
1212

1313
bvt boolbvt::convert_case(const exprt &expr)
1414
{
@@ -49,15 +49,11 @@ bvt boolbvt::convert_case(const exprt &expr)
4949
break;
5050

5151
case COMPARE:
52-
if(compare_bv.size()!=op.size())
53-
{
54-
std::cerr << "compare operand: " << compare_bv.size()
55-
<< "\noperand: " << op.size() << '\n'
56-
<< it->pretty()
57-
<< '\n';
58-
59-
throw "size of compare operand does not match";
60-
}
52+
DATA_INVARIANT(
53+
compare_bv.size() == op.size(),
54+
std::string("size of compare operand does not match:\n") +
55+
"compare operand: " + std::to_string(compare_bv.size()) +
56+
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());
6157

6258
compare_literal=bv_utils.equal(compare_bv, op);
6359
compare_literal=prop.land(!previous_compare, compare_literal);
@@ -68,15 +64,11 @@ bvt boolbvt::convert_case(const exprt &expr)
6864
break;
6965

7066
case VALUE:
71-
if(bv.size()!=op.size())
72-
{
73-
std::cerr << "result size: " << bv.size()
74-
<< "\noperand: " << op.size() << '\n'
75-
<< it->pretty()
76-
<< '\n';
77-
78-
throw "size of value operand does not match";
79-
}
67+
DATA_INVARIANT(
68+
bv.size() == op.size(),
69+
std::string("size of value operand does not match:\n") +
70+
"result size: " + std::to_string(bv.size()) +
71+
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());
8072

8173
{
8274
literalt value_literal=bv_utils.equal(bv, op);

src/solvers/flattening/boolbv_cond.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <iostream>
11+
#include <util/invariant.h>
1212

1313
bvt boolbvt::convert_cond(const exprt &expr)
1414
{
@@ -51,15 +51,11 @@ bvt boolbvt::convert_cond(const exprt &expr)
5151
{
5252
const bvt &op=convert_bv(*it);
5353

54-
if(bv.size()!=op.size())
55-
{
56-
std::cerr << "result size: " << bv.size()
57-
<< "\noperand: " << op.size() << '\n'
58-
<< it->pretty()
59-
<< '\n';
60-
61-
throw "size of value operand does not match";
62-
}
54+
DATA_INVARIANT(
55+
bv.size() == op.size(),
56+
std::string("size of value operand does not match:\n") +
57+
"result size: " + std::to_string(bv.size()) +
58+
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());
6359

6460
literalt value_literal=bv_utils.equal(bv, op);
6561

src/solvers/flattening/boolbv_equality.cpp

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <iostream>
12-
1311
#include <util/std_expr.h>
1412
#include <util/base_type.h>
13+
#include <util/invariant.h>
1514

1615
#include "flatten_byte_operators.h"
1716

1817
literalt boolbvt::convert_equality(const equal_exprt &expr)
1918
{
20-
if(!base_type_eq(expr.lhs().type(), expr.rhs().type(), ns))
21-
{
22-
std::cout << "######### lhs: " << expr.lhs().pretty() << '\n';
23-
std::cout << "######### rhs: " << expr.rhs().pretty() << '\n';
24-
throw "equality without matching types";
25-
}
19+
const bool is_base_type_eq =
20+
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
21+
DATA_INVARIANT(
22+
is_base_type_eq,
23+
std::string("equality without matching types:\n") + "######### lhs: " +
24+
expr.lhs().pretty() + '\n' + "######### rhs: " + expr.rhs().pretty());
2625

2726
// see if it is an unbounded array
2827
if(is_unbounded_array(expr.lhs().type()))
@@ -41,14 +40,12 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
4140
const bvt &bv0=convert_bv(expr.lhs());
4241
const bvt &bv1=convert_bv(expr.rhs());
4342

44-
if(bv0.size()!=bv1.size())
45-
{
46-
std::cerr << "lhs: " << expr.lhs().pretty() << '\n';
47-
std::cerr << "lhs size: " << bv0.size() << '\n';
48-
std::cerr << "rhs: " << expr.rhs().pretty() << '\n';
49-
std::cerr << "rhs size: " << bv1.size() << '\n';
50-
throw "unexpected size mismatch on equality";
51-
}
43+
DATA_INVARIANT(
44+
bv0.size() == bv1.size(),
45+
std::string("unexpected size mismatch on equality:\n") + "lhs: " +
46+
expr.lhs().pretty() + '\n' + "lhs size: " + std::to_string(bv0.size()) +
47+
'\n' + "rhs: " + expr.rhs().pretty() + '\n' +
48+
"rhs size: " + std::to_string(bv1.size()));
5249

5350
if(bv0.empty())
5451
{
@@ -66,24 +63,23 @@ literalt boolbvt::convert_verilog_case_equality(
6663
// This is 4-valued comparison, i.e., z===z, x===x etc.
6764
// The result is always Boolean.
6865

69-
if(!base_type_eq(expr.lhs().type(), expr.rhs().type(), ns))
70-
{
71-
std::cout << "######### lhs: " << expr.lhs().pretty() << '\n';
72-
std::cout << "######### rhs: " << expr.rhs().pretty() << '\n';
73-
throw "verilog_case_equality without matching types";
74-
}
66+
const bool is_base_type_eq =
67+
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
68+
DATA_INVARIANT(
69+
is_base_type_eq,
70+
std::string("verilog_case_equality without matching types:\n") +
71+
"######### lhs: " + expr.lhs().pretty() + '\n' +
72+
"######### rhs: " + expr.rhs().pretty());
7573

7674
const bvt &bv0=convert_bv(expr.lhs());
7775
const bvt &bv1=convert_bv(expr.rhs());
7876

79-
if(bv0.size()!=bv1.size())
80-
{
81-
std::cerr << "lhs: " << expr.lhs().pretty() << '\n';
82-
std::cerr << "lhs size: " << bv0.size() << '\n';
83-
std::cerr << "rhs: " << expr.rhs().pretty() << '\n';
84-
std::cerr << "rhs size: " << bv1.size() << '\n';
85-
throw "unexpected size mismatch on verilog_case_equality";
86-
}
77+
DATA_INVARIANT(
78+
bv0.size() == bv1.size(),
79+
std::string("unexpected size mismatch on verilog_case_equality:\n") +
80+
"lhs: " + expr.lhs().pretty() + '\n' + "lhs size: " +
81+
std::to_string(bv0.size()) + '\n' + "rhs: " + expr.rhs().pretty() + '\n' +
82+
"rhs size: " + std::to_string(bv1.size()));
8783

8884
if(expr.id()==ID_verilog_case_inequality)
8985
return !bv_utils.equal(bv0, bv1);

src/solvers/flattening/boolbv_floatbv_op.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,9 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
8888
bvt bv2=convert_bv(op2);
8989

9090
const typet &type=ns.follow(expr.type());
91-
92-
if(op0.type()!=type || op1.type()!=type)
93-
{
94-
std::cerr << expr.pretty() << '\n';
95-
throw "float op with mixed types";
96-
}
91+
DATA_INVARIANT(
92+
op0.type() == type && op1.type() == type,
93+
"float op with mixed types:\n" + expr.pretty());
9794

9895
float_utilst float_utils(prop);
9996

src/solvers/refinement/refine_arithmetic.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ void bv_refinementt::check_SAT(approximationt &a)
226226
<< "==" << integer2binary(result.pack(), spec.width()) << eom;
227227
#endif
228228

229-
// if(a.over_state==1) { debug() << "DISAGREEMENT!\n"; exit(1); }
230-
231229
if(a.over_state<config_.max_node_refinement)
232230
{
233231
bvt r;

src/solvers/sat/cnf.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Author: Daniel Kroening, [email protected]
1212
#include "cnf.h"
1313

1414
#include <algorithm>
15-
#include <cassert>
16-
#include <iostream>
1715
#include <set>
1816

17+
#include <util/invariant.h>
18+
1919
// #define VERBOSE
2020

2121
/// Tseitin encoding of conjunction of two literals
@@ -426,22 +426,23 @@ bool cnft::process_clause(const bvt &bv, bvt &dest)
426426
for(const auto l : bv)
427427
{
428428
// we never use index 0
429-
assert(l.var_no()!=0);
429+
INVARIANT(l.var_no() != 0, "variable 0 must not be used");
430430

431431
// we never use 'unused_var_no'
432-
assert(l.var_no()!=literalt::unused_var_no());
432+
INVARIANT(
433+
l.var_no() != literalt::unused_var_no(),
434+
"variable 'unused_var_no' must not be used");
433435

434436
if(l.is_true())
435437
return true; // clause satisfied
436438

437439
if(l.is_false())
438440
continue; // will remove later
439441

440-
if(l.var_no()>=_no_variables)
441-
std::cout << "l.var_no()=" << l.var_no()
442-
<< " _no_variables=" << _no_variables << '\n';
443-
444-
assert(l.var_no()<_no_variables);
442+
INVARIANT(
443+
l.var_no() < _no_variables,
444+
"unknown variable " + std::to_string(l.var_no()) +
445+
" (no_variables = " + std::to_string(_no_variables) + " )");
445446
}
446447

447448
// now copy

0 commit comments

Comments
 (0)