@@ -54,6 +54,7 @@ smt2_convt::smt2_convt(
5454 solvert _solver,
5555 std::ostream &_out)
5656 : use_FPA_theory(false ),
57+ use_as_const(false ),
5758 use_datatypes(false ),
5859 use_array_of_bool(false ),
5960 emit_set_logic(true ),
@@ -79,6 +80,7 @@ smt2_convt::smt2_convt(
7980 break ;
8081
8182 case solvert::CPROVER_SMT2:
83+ use_as_const = true ;
8284 use_array_of_bool = true ;
8385 emit_set_logic = false ;
8486 break ;
@@ -87,6 +89,7 @@ smt2_convt::smt2_convt(
8789 break ;
8890
8991 case solvert::CVC4:
92+ use_as_const = true ;
9093 break ;
9194
9295 case solvert::MATHSAT:
@@ -96,6 +99,7 @@ smt2_convt::smt2_convt(
9699 break ;
97100
98101 case solvert::Z3:
102+ use_as_const = true ;
99103 use_array_of_bool = true ;
100104 emit_set_logic = false ;
101105 use_datatypes = true ;
@@ -1276,18 +1280,29 @@ void smt2_convt::convert_expr(const exprt &expr)
12761280 convert_address_of_rec (
12771281 address_of_expr.object (), to_pointer_type (address_of_expr.type ()));
12781282 }
1279- else if (expr.id ()== ID_array_of)
1283+ else if (expr.id () == ID_array_of)
12801284 {
1281- const array_of_exprt &array_of_expr = to_array_of_expr (expr);
1285+ const auto &array_of_expr = to_array_of_expr (expr);
12821286
12831287 DATA_INVARIANT (
12841288 array_of_expr.type ().id () == ID_array,
12851289 " array of expression shall have array type" );
12861290
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+ }
12911306 }
12921307 else if (expr.id ()==ID_index)
12931308 {
@@ -4367,27 +4382,30 @@ void smt2_convt::find_symbols(const exprt &expr)
43674382 out << " )" << " \n " ;
43684383 }
43694384 }
4370- else if (expr.id ()== ID_array_of)
4385+ else if (expr.id () == ID_array_of)
43714386 {
4372- if (defined_expressions. find (expr)==defined_expressions. end () )
4387+ if (!use_as_const )
43734388 {
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);
43804392
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 " ;
43894399
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+ }
43914409 }
43924410 }
43934411 else if (expr.id ()==ID_array)
0 commit comments