Skip to content

Replace cout/cerr in solvers #1875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/cpp/cpp_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Author: Daniel Kroening, [email protected]

#include "cpp_typecheck.h"

#include <cstdlib>
#ifdef DEBUG
#include <iostream>
#endif

#include <util/pointer_offset_size.h>
#include <util/std_types.h>
Expand All @@ -20,6 +22,7 @@ Author: Daniel Kroening, [email protected]
#include <util/config.h>
#include <util/simplify_expr.h>
#include <util/base_type.h>
#include <util/invariant.h>

#include <util/c_types.h>
#include <ansi-c/c_qualifiers.h>
Expand Down Expand Up @@ -69,25 +72,27 @@ void cpp_typecheckt::typecheck_expr_main(exprt &expr)
typecheck_expr_explicit_constructor_call(expr);
else if(expr.is_nil())
{
#if 0
#ifdef DEBUG
std::cerr << "E: " << expr.pretty() << '\n';
std::cerr << "cpp_typecheckt::typecheck_expr_main got nil\n";
#endif
abort();
#endif
UNREACHABLE;
}
else if(expr.id()==ID_code)
{
#if 0
#ifdef DEBUG
std::cerr << "E: " << expr.pretty() << '\n';
std::cerr << "cpp_typecheckt::typecheck_expr_main got code\n";
#endif
abort();
#endif
UNREACHABLE;
}
else if(expr.id()==ID_symbol)
{
#if 0
std::cout << "E: " << expr.pretty() << '\n';
// ignore here
#ifdef DEBUG
std::cerr << "E: " << expr.pretty() << '\n';
std::cerr << "cpp_typecheckt::typecheck_expr_main got symbol\n";
abort();
#endif
#endif
}
else if(expr.id()=="__is_base_of")
{
Expand Down
9 changes: 3 additions & 6 deletions src/goto-symex/goto_symex_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ void goto_symex_statet::level0t::operator()(
return;

const symbolt *s;

if(ns.lookup(obj_identifier, s))
{
std::cerr << "level0: failed to find " << obj_identifier << '\n';
abort();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had abort() calls hidden in the depths of the system :-\ Scary...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - git grep -w 'abort()' should be reviewed, possibly as part of this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const bool found_l0 = !ns.lookup(obj_identifier, s);
DATA_INVARIANT(
found_l0, "level0: failed to find " + id2string(obj_identifier));

// don't rename shared variables or functions
if(s->type.id()==ID_code ||
Expand Down
18 changes: 5 additions & 13 deletions src/solvers/flattening/boolbv_add_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>

#include <util/invariant.h>
#include <util/std_types.h>

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

const exprt &op0=expr.op0();

if(op0.type()!=type)
{
std::cerr << expr.pretty() << '\n';
throw "add/sub with mixed types";
}
DATA_INVARIANT(
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty());

bvt bv=convert_bv(op0);

Expand All @@ -69,11 +64,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)
it=operands.begin()+1;
it!=operands.end(); it++)
{
if(it->type()!=type)
{
std::cerr << expr.pretty() << '\n';
throw "add/sub with mixed types";
}
DATA_INVARIANT(
it->type() == type, "add/sub with mixed types:\n" + expr.pretty());

const bvt &op=convert_bv(*it);

Expand Down
30 changes: 11 additions & 19 deletions src/solvers/flattening/boolbv_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>
#include <util/invariant.h>

bvt boolbvt::convert_case(const exprt &expr)
{
Expand Down Expand Up @@ -49,15 +49,11 @@ bvt boolbvt::convert_case(const exprt &expr)
break;

case COMPARE:
if(compare_bv.size()!=op.size())
{
std::cerr << "compare operand: " << compare_bv.size()
<< "\noperand: " << op.size() << '\n'
<< it->pretty()
<< '\n';

throw "size of compare operand does not match";
}
DATA_INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure I agree with this. CHECK_RETURN (as it's the return value of a previous call to convert) or INVARIANT (as a generic operational property of the algorithm).

compare_bv.size() == op.size(),
std::string("size of compare operand does not match:\n") +
"compare operand: " + std::to_string(compare_bv.size()) +
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());

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

case VALUE:
if(bv.size()!=op.size())
{
std::cerr << "result size: " << bv.size()
<< "\noperand: " << op.size() << '\n'
<< it->pretty()
<< '\n';

throw "size of value operand does not match";
}
DATA_INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

bv.size() == op.size(),
std::string("size of value operand does not match:\n") +
"result size: " + std::to_string(bv.size()) +
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());

{
literalt value_literal=bv_utils.equal(bv, op);
Expand Down
16 changes: 6 additions & 10 deletions src/solvers/flattening/boolbv_cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>
#include <util/invariant.h>

bvt boolbvt::convert_cond(const exprt &expr)
{
Expand Down Expand Up @@ -51,15 +51,11 @@ bvt boolbvt::convert_cond(const exprt &expr)
{
const bvt &op=convert_bv(*it);

if(bv.size()!=op.size())
{
std::cerr << "result size: " << bv.size()
<< "\noperand: " << op.size() << '\n'
<< it->pretty()
<< '\n';

throw "size of value operand does not match";
}
DATA_INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

bv.size() == op.size(),
std::string("size of value operand does not match:\n") +
"result size: " + std::to_string(bv.size()) +
"\noperand: " + std::to_string(op.size()) + '\n' + it->pretty());

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

Expand Down
56 changes: 26 additions & 30 deletions src/solvers/flattening/boolbv_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ Author: Daniel Kroening, [email protected]

#include "boolbv.h"

#include <iostream>

#include <util/std_expr.h>
#include <util/base_type.h>
#include <util/invariant.h>

#include <langapi/language_util.h>

#include "flatten_byte_operators.h"

literalt boolbvt::convert_equality(const equal_exprt &expr)
{
if(!base_type_eq(expr.lhs().type(), expr.rhs().type(), ns))
{
std::cout << "######### lhs: " << expr.lhs().pretty() << '\n';
std::cout << "######### rhs: " << expr.rhs().pretty() << '\n';
throw "equality without matching types";
}
const bool is_base_type_eq =
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
DATA_INVARIANT(
is_base_type_eq,
std::string("equality without matching types:\n") + "######### lhs: " +
expr.lhs().pretty() + '\n' + "######### rhs: " + expr.rhs().pretty());

// see if it is an unbounded array
if(is_unbounded_array(expr.lhs().type()))
Expand All @@ -43,14 +42,12 @@ literalt boolbvt::convert_equality(const equal_exprt &expr)
const bvt &bv0=convert_bv(expr.lhs());
const bvt &bv1=convert_bv(expr.rhs());

if(bv0.size()!=bv1.size())
{
std::cerr << "lhs: " << expr.lhs().pretty() << '\n';
std::cerr << "lhs size: " << bv0.size() << '\n';
std::cerr << "rhs: " << expr.rhs().pretty() << '\n';
std::cerr << "rhs size: " << bv1.size() << '\n';
throw "unexpected size mismatch on equality";
}
DATA_INVARIANT(
bv0.size() == bv1.size(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

std::string("unexpected size mismatch on equality:\n") + "lhs: " +
expr.lhs().pretty() + '\n' + "lhs size: " + std::to_string(bv0.size()) +
'\n' + "rhs: " + expr.rhs().pretty() + '\n' +
"rhs size: " + std::to_string(bv1.size()));

if(bv0.empty())
{
Expand All @@ -68,24 +65,23 @@ literalt boolbvt::convert_verilog_case_equality(
// This is 4-valued comparison, i.e., z===z, x===x etc.
// The result is always Boolean.

if(!base_type_eq(expr.lhs().type(), expr.rhs().type(), ns))
{
std::cout << "######### lhs: " << expr.lhs().pretty() << '\n';
std::cout << "######### rhs: " << expr.rhs().pretty() << '\n';
throw "verilog_case_equality without matching types";
}
const bool is_base_type_eq =
base_type_eq(expr.lhs().type(), expr.rhs().type(), ns);
DATA_INVARIANT(
is_base_type_eq,
std::string("verilog_case_equality without matching types:\n") +
"######### lhs: " + expr.lhs().pretty() + '\n' +
"######### rhs: " + expr.rhs().pretty());

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

if(bv0.size()!=bv1.size())
{
std::cerr << "lhs: " << expr.lhs().pretty() << '\n';
std::cerr << "lhs size: " << bv0.size() << '\n';
std::cerr << "rhs: " << expr.rhs().pretty() << '\n';
std::cerr << "rhs size: " << bv1.size() << '\n';
throw "unexpected size mismatch on verilog_case_equality";
}
DATA_INVARIANT(
bv0.size() == bv1.size(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

std::string("unexpected size mismatch on verilog_case_equality:\n") +
"lhs: " + expr.lhs().pretty() + '\n' + "lhs size: " +
std::to_string(bv0.size()) + '\n' + "rhs: " + expr.rhs().pretty() + '\n' +
"rhs size: " + std::to_string(bv1.size()));

if(expr.id()==ID_verilog_case_inequality)
return !bv_utils.equal(bv0, bv1);
Expand Down
9 changes: 3 additions & 6 deletions src/solvers/flattening/boolbv_floatbv_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr)
bvt bv2=convert_bv(op2);

const typet &type=ns.follow(expr.type());

if(op0.type()!=type || op1.type()!=type)
{
std::cerr << expr.pretty() << '\n';
throw "float op with mixed types";
}
DATA_INVARIANT(
op0.type() == type && op1.type() == type,
"float op with mixed types:\n" + expr.pretty());

float_utilst float_utils(prop);

Expand Down
2 changes: 0 additions & 2 deletions src/solvers/refinement/refine_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ void bv_refinementt::check_SAT(approximationt &a)
<< "==" << integer2binary(result.pack(), spec.width()) << eom;
#endif

// if(a.over_state==1) { debug() << "DISAGREEMENT!\n"; exit(1); }

if(a.over_state<config_.max_node_refinement)
{
bvt r;
Expand Down
19 changes: 10 additions & 9 deletions src/solvers/sat/cnf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Author: Daniel Kroening, [email protected]
#include "cnf.h"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <set>

#include <util/invariant.h>

// #define VERBOSE

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

// we never use 'unused_var_no'
assert(l.var_no()!=literalt::unused_var_no());
INVARIANT(
l.var_no() != literalt::unused_var_no(),
"variable 'unused_var_no' must not be used");

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

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

if(l.var_no()>=_no_variables)
std::cout << "l.var_no()=" << l.var_no()
<< " _no_variables=" << _no_variables << '\n';

assert(l.var_no()<_no_variables);
INVARIANT(
l.var_no() < _no_variables,
"unknown variable " + std::to_string(l.var_no()) +
" (no_variables = " + std::to_string(_no_variables) + " )");
}

// now copy
Expand Down
Loading