@@ -54,6 +54,7 @@ smt2_convt::smt2_convt(
54
54
solvert _solver,
55
55
std::ostream &_out)
56
56
: use_FPA_theory(false ),
57
+ use_as_const(false ),
57
58
use_datatypes(false ),
58
59
use_array_of_bool(false ),
59
60
emit_set_logic(true ),
@@ -79,6 +80,7 @@ smt2_convt::smt2_convt(
79
80
break ;
80
81
81
82
case solvert::CPROVER_SMT2:
83
+ use_as_const = true ;
82
84
use_array_of_bool = true ;
83
85
emit_set_logic = false ;
84
86
break ;
@@ -87,6 +89,7 @@ smt2_convt::smt2_convt(
87
89
break ;
88
90
89
91
case solvert::CVC4:
92
+ use_as_const = true ;
90
93
break ;
91
94
92
95
case solvert::MATHSAT:
@@ -96,6 +99,7 @@ smt2_convt::smt2_convt(
96
99
break ;
97
100
98
101
case solvert::Z3:
102
+ use_as_const = true ;
99
103
use_array_of_bool = true ;
100
104
emit_set_logic = false ;
101
105
use_datatypes = true ;
@@ -1276,18 +1280,29 @@ void smt2_convt::convert_expr(const exprt &expr)
1276
1280
convert_address_of_rec (
1277
1281
address_of_expr.object (), to_pointer_type (address_of_expr.type ()));
1278
1282
}
1279
- else if (expr.id ()== ID_array_of)
1283
+ else if (expr.id () == ID_array_of)
1280
1284
{
1281
- const array_of_exprt &array_of_expr = to_array_of_expr (expr);
1285
+ const auto &array_of_expr = to_array_of_expr (expr);
1282
1286
1283
1287
DATA_INVARIANT (
1284
1288
array_of_expr.type ().id () == ID_array,
1285
1289
" array of expression shall have array type" );
1286
1290
1287
- defined_expressionst::const_iterator it =
1288
- defined_expressions.find (array_of_expr);
1289
- CHECK_RETURN (it != defined_expressions.end ());
1290
- out << it->second ;
1291
+ if (use_as_const)
1292
+ {
1293
+ out << " ((as const " ;
1294
+ convert_type (array_of_expr.type ());
1295
+ out << " ) " ;
1296
+ convert_expr (array_of_expr.what ());
1297
+ out << " )" ;
1298
+ }
1299
+ else
1300
+ {
1301
+ defined_expressionst::const_iterator it =
1302
+ defined_expressions.find (array_of_expr);
1303
+ CHECK_RETURN (it != defined_expressions.end ());
1304
+ out << it->second ;
1305
+ }
1291
1306
}
1292
1307
else if (expr.id ()==ID_index)
1293
1308
{
@@ -4367,27 +4382,30 @@ void smt2_convt::find_symbols(const exprt &expr)
4367
4382
out << " )" << " \n " ;
4368
4383
}
4369
4384
}
4370
- else if (expr.id ()== ID_array_of)
4385
+ else if (expr.id () == ID_array_of)
4371
4386
{
4372
- if (defined_expressions. find (expr)==defined_expressions. end () )
4387
+ if (!use_as_const )
4373
4388
{
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 " ;
4389
+ if (defined_expressions.find (expr) == defined_expressions.end ())
4390
+ {
4391
+ const auto &array_of = to_array_of_expr (expr);
4380
4392
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
4393
+ const irep_idt id =
4394
+ " array_of." + std::to_string (defined_expressions.size ());
4395
+ out << " ; the following is a substitute for lambda i. x\n " ;
4396
+ out << " (declare-fun " << id << " () " ;
4397
+ convert_type (array_of.type ());
4398
+ out << " )\n " ;
4389
4399
4390
- defined_expressions[expr]=id;
4400
+ // use a quantifier-based initialization instead of lambda
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