10
10
11
11
#include < util/arith_tools.h>
12
12
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
+
13
29
void smt2_parsert::command_sequence ()
14
30
{
15
31
exit =false ;
@@ -360,8 +376,8 @@ exprt smt2_parsert::multi_ary(irep_idt id, const exprt::operandst &op)
360
376
{
361
377
error () << " expression must have operands with matching types,"
362
378
" 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;
365
381
return nil_exprt ();
366
382
}
367
383
}
@@ -385,8 +401,8 @@ exprt smt2_parsert::binary_predicate(irep_idt id, const exprt::operandst &op)
385
401
{
386
402
error () << " expression must have operands with matching types,"
387
403
" 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;
390
406
return nil_exprt ();
391
407
}
392
408
@@ -1187,6 +1203,26 @@ void smt2_parsert::command(const std::string &c)
1187
1203
auto signature=function_signature_definition ();
1188
1204
exprt body=expression ();
1189
1205
1206
+ // check type of body
1207
+ if (signature.id () == ID_mathematical_function)
1208
+ {
1209
+ const auto &f_signature = to_mathematical_function_type (signature);
1210
+ if (body.type () != f_signature.codomain ())
1211
+ {
1212
+ error () << " type mismatch in function definition: expected `"
1213
+ << smt2_format (f_signature.codomain ()) << " ' but got `"
1214
+ << smt2_format (body.type ()) << ' \' ' << eom;
1215
+ return ;
1216
+ }
1217
+ }
1218
+ else if (body.type () != signature)
1219
+ {
1220
+ error () << " type mismatch in function definition: expected `"
1221
+ << smt2_format (signature) << " ' but got `"
1222
+ << smt2_format (body.type ()) << ' \' ' << eom;
1223
+ return ;
1224
+ }
1225
+
1190
1226
// set up the entry
1191
1227
auto &entry=id_map[id];
1192
1228
entry.type =signature;
0 commit comments