@@ -53,7 +53,8 @@ smt2_convt::smt2_convt(
53
53
const std::string &_logic,
54
54
solvert _solver,
55
55
std::ostream &_out)
56
- : use_FPA_theory(false ),
56
+ : use_as_const(false ),
57
+ use_FPA_theory(false ),
57
58
use_datatypes(false ),
58
59
use_array_of_bool(false ),
59
60
emit_set_logic(true ),
@@ -87,6 +88,7 @@ smt2_convt::smt2_convt(
87
88
break ;
88
89
89
90
case solvert::CVC4:
91
+ use_as_const = true ;
90
92
break ;
91
93
92
94
case solvert::MATHSAT:
@@ -96,6 +98,7 @@ smt2_convt::smt2_convt(
96
98
break ;
97
99
98
100
case solvert::Z3:
101
+ use_as_const = true ;
99
102
use_array_of_bool = true ;
100
103
emit_set_logic = false ;
101
104
use_datatypes = true ;
@@ -1276,18 +1279,29 @@ void smt2_convt::convert_expr(const exprt &expr)
1276
1279
convert_address_of_rec (
1277
1280
address_of_expr.object (), to_pointer_type (address_of_expr.type ()));
1278
1281
}
1279
- else if (expr.id ()== ID_array_of)
1282
+ else if (expr.id () == ID_array_of)
1280
1283
{
1281
- const array_of_exprt &array_of_expr = to_array_of_expr (expr);
1284
+ const auto &array_of_expr = to_array_of_expr (expr);
1282
1285
1283
1286
DATA_INVARIANT (
1284
1287
array_of_expr.type ().id () == ID_array,
1285
1288
" array of expression shall have array type" );
1286
1289
1287
- defined_expressionst::const_iterator it =
1288
- defined_expressions.find (array_of_expr);
1289
- CHECK_RETURN (it != defined_expressions.end ());
1290
- out << it->second ;
1290
+ if (use_as_const)
1291
+ {
1292
+ out << " ((as const " ;
1293
+ convert_type (array_of_expr.type ());
1294
+ out << " ) " ;
1295
+ convert_expr (array_of_expr.what ());
1296
+ out << " )" ;
1297
+ }
1298
+ else
1299
+ {
1300
+ defined_expressionst::const_iterator it =
1301
+ defined_expressions.find (array_of_expr);
1302
+ CHECK_RETURN (it != defined_expressions.end ());
1303
+ out << it->second ;
1304
+ }
1291
1305
}
1292
1306
else if (expr.id ()==ID_index)
1293
1307
{
@@ -4367,27 +4381,31 @@ void smt2_convt::find_symbols(const exprt &expr)
4367
4381
out << " )" << " \n " ;
4368
4382
}
4369
4383
}
4370
- else if (expr.id ()== ID_array_of)
4384
+ else if (expr.id () == ID_array_of)
4371
4385
{
4372
- if (defined_expressions. find (expr)==defined_expressions. end () )
4386
+ if (!use_as_const )
4373
4387
{
4374
- const irep_idt id =
4375
- " array_of." + std::to_string (defined_expressions.size ());
4376
- out << " ; the following is a substitute for lambda i. x" << " \n " ;
4377
- out << " (declare-fun " << id << " () " ;
4378
- convert_type (expr.type ());
4379
- out << " )" << " \n " ;
4380
-
4381
- // use a quantifier instead of the lambda
4382
- #if 0 // not really working in any solver yet!
4383
- out << "(assert (forall ((i ";
4384
- convert_type(array_index_type());
4385
- out << ")) (= (select " << id << " i) ";
4386
- convert_expr(expr.op0());
4387
- out << ")))" << "\n";
4388
- #endif
4388
+ if (defined_expressions.find (expr) == defined_expressions.end ())
4389
+ {
4390
+ const auto &array_of = to_array_of_expr (expr);
4389
4391
4390
- defined_expressions[expr]=id;
4392
+ const irep_idt id =
4393
+ " array_of." + std::to_string (defined_expressions.size ());
4394
+ out << " ; the following is a substitute for lambda i. x\n " ;
4395
+ out << " (declare-fun " << id << " () " ;
4396
+ convert_type (array_of.type ());
4397
+ out << " )\n " ;
4398
+
4399
+ // use a quantifier instead of the lambda
4400
+ // may not work with existing solver, but is a sound translation
4401
+ out << " (assert (forall ((i " ;
4402
+ convert_type (array_of.type ().size ().type ());
4403
+ out << " )) (= (select " << id << " i) " ;
4404
+ convert_expr (array_of.what ());
4405
+ out << " )))\n " ;
4406
+
4407
+ defined_expressions[expr] = id;
4408
+ }
4391
4409
}
4392
4410
}
4393
4411
else if (expr.id ()==ID_array)
0 commit comments