Skip to content

Commit 85d20eb

Browse files
author
Enrico Steffinlongo
committed
Add SMT2 backend support for nondet_symbol_exprt
1 parent aaa4774 commit 85d20eb

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ static smt_termt convert_expr_to_smt(
124124
const nondet_symbol_exprt &nondet_symbol,
125125
const sub_expression_mapt &converted)
126126
{
127-
UNIMPLEMENTED_FEATURE(
128-
"Generation of SMT formula for nondet symbol expression: " +
129-
nondet_symbol.pretty());
127+
// A nondet_symbol is a reference to an unconstrained function. This function
128+
// will already have been added as a dependency.
129+
return smt_identifier_termt{
130+
nondet_symbol.get_identifier(),
131+
convert_type_to_smt_sort(nondet_symbol.type())};
130132
}
131133

132134
/// \brief Makes a term which is true if \p input is not 0 / false.

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ get_problem_messages(const smt_responset &response)
6262
/// `convert_expr_to_smt`. This is because any sub expressions which
6363
/// `convert_expr_to_smt` translates into function applications, must also be
6464
/// returned by this`gather_dependent_expressions` function.
65+
/// \details `symbol_exprt`, `array_exprt` and `nondet_symbol_exprt` add
66+
/// dependant expressions.
6567
static std::vector<exprt> gather_dependent_expressions(const exprt &expr)
6668
{
6769
std::vector<exprt> dependent_expressions;
6870
expr.visit_pre([&](const exprt &expr_node) {
6971
if(
7072
can_cast_expr<symbol_exprt>(expr_node) ||
71-
can_cast_expr<array_exprt>(expr_node))
73+
can_cast_expr<array_exprt>(expr_node) ||
74+
can_cast_expr<nondet_symbol_exprt>(expr_node))
7275
{
7376
dependent_expressions.push_back(expr_node);
7477
}
@@ -100,6 +103,21 @@ void smt2_incremental_decision_proceduret::define_array_function(
100103
expression_identifiers.emplace(array, array_identifier);
101104
}
102105

106+
void send_function_definition(
107+
const exprt &expr,
108+
const irep_idt &symbol_identifier,
109+
const std::unique_ptr<smt_base_solver_processt> &solver_process,
110+
std::unordered_map<exprt, smt_identifier_termt, irep_hash>
111+
&expression_identifiers)
112+
{
113+
const smt_declare_function_commandt function{
114+
smt_identifier_termt(
115+
symbol_identifier, convert_type_to_smt_sort(expr.type())),
116+
{}};
117+
expression_identifiers.emplace(expr, function.identifier());
118+
solver_process->send(function);
119+
}
120+
103121
/// \brief Defines any functions which \p expr depends on, which have not yet
104122
/// been defined, along with their dependencies in turn.
105123
void smt2_incremental_decision_proceduret::define_dependent_functions(
@@ -134,12 +152,11 @@ void smt2_incremental_decision_proceduret::define_dependent_functions(
134152
const symbolt *symbol = nullptr;
135153
if(ns.lookup(identifier, symbol) || symbol->value.is_nil())
136154
{
137-
const smt_declare_function_commandt function{
138-
smt_identifier_termt(
139-
identifier, convert_type_to_smt_sort(symbol_expr->type())),
140-
{}};
141-
expression_identifiers.emplace(*symbol_expr, function.identifier());
142-
solver_process->send(function);
155+
send_function_definition(
156+
*symbol_expr,
157+
symbol_expr->get_identifier(),
158+
solver_process,
159+
expression_identifiers);
143160
}
144161
else
145162
{
@@ -153,6 +170,16 @@ void smt2_incremental_decision_proceduret::define_dependent_functions(
153170
}
154171
if(const auto array_expr = expr_try_dynamic_cast<array_exprt>(current))
155172
define_array_function(*array_expr);
173+
if(
174+
const auto nondet_symbol =
175+
expr_try_dynamic_cast<nondet_symbol_exprt>(current))
176+
{
177+
send_function_definition(
178+
*nondet_symbol,
179+
nondet_symbol->get_identifier(),
180+
solver_process,
181+
expression_identifiers);
182+
}
156183
to_be_defined.pop();
157184
}
158185
}

0 commit comments

Comments
 (0)