Skip to content

Commit 457e405

Browse files
author
Daniel Kroening
committed
pretty formatting of SMT2 types in error messages
1 parent 6747d24 commit 457e405

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <util/arith_tools.h>
1212

13+
std::ostream &operator<<(std::ostream &out, const smt2_parsert::smt2_format &f)
14+
{
15+
if(f.type.id() == ID_unsignedbv)
16+
out << "(_ BitVec " << to_unsignedbv_type(f.type).get_width() << ')';
17+
else if(f.type.id() == ID_bool)
18+
out << "Bool";
19+
else if(f.type.id() == ID_integer)
20+
out << "Int";
21+
else if(f.type.id() == ID_real)
22+
out << "Real";
23+
else
24+
out << "? " << f.type.id();
25+
26+
return out;
27+
}
28+
1329
void smt2_parsert::command_sequence()
1430
{
1531
exit=false;
@@ -360,8 +376,8 @@ exprt smt2_parsert::multi_ary(irep_idt id, const exprt::operandst &op)
360376
{
361377
error() << "expression must have operands with matching types,"
362378
" but got `"
363-
<< op[0].type().pretty()
364-
<< "' and `" << op[i].type().pretty() << '\'' << eom;
379+
<< smt2_format(op[0].type()) << "' and `"
380+
<< smt2_format(op[i].type()) << '\'' << eom;
365381
return nil_exprt();
366382
}
367383
}
@@ -385,8 +401,8 @@ exprt smt2_parsert::binary_predicate(irep_idt id, const exprt::operandst &op)
385401
{
386402
error() << "expression must have operands with matching types,"
387403
" but got `"
388-
<< op[0].type().pretty()
389-
<< "' and `" << op[1].type().pretty() << '\'' << eom;
404+
<< smt2_format(op[0].type()) << "' and `"
405+
<< smt2_format(op[1].type()) << '\'' << eom;
390406
return nil_exprt();
391407
}
392408

src/solvers/smt2/smt2_parser.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ class smt2_parsert:public smt2_tokenizert
4343
using id_mapt=std::map<irep_idt, idt>;
4444
id_mapt id_map;
4545

46+
struct smt2_format
47+
{
48+
explicit smt2_format(const typet &_type) : type(_type)
49+
{
50+
}
51+
52+
const typet type;
53+
};
54+
4655
protected:
4756
bool exit;
4857
void command_sequence();
@@ -82,4 +91,6 @@ class smt2_parsert:public smt2_tokenizert
8291
exprt cast_bv_to_unsigned(const exprt &);
8392
};
8493

94+
std::ostream &operator<<(std::ostream &, const smt2_parsert::smt2_format &);
95+
8596
#endif // CPROVER_SOLVERS_SMT2_SMT2_PARSER_H

0 commit comments

Comments
 (0)