Skip to content

Commit 5e08a81

Browse files
committed
Solver factory: make_satcheck_prop does not require dynamic_cast
We can determine at compile time whether a particular solver has harness support for any given call site.
1 parent d635850 commit 5e08a81

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/goto-checker/solver_factory.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,35 @@ static void emit_solver_warning(
188188
}
189189

190190
template <typename SatcheckT>
191-
static std::unique_ptr<SatcheckT>
191+
static typename std::enable_if<
192+
!std::is_base_of<hardness_collectort, SatcheckT>::value,
193+
std::unique_ptr<SatcheckT>>::type
192194
make_satcheck_prop(message_handlert &message_handler, const optionst &options)
193195
{
194196
auto satcheck = std::make_unique<SatcheckT>(message_handler);
195197
if(options.is_set("write-solver-stats-to"))
196198
{
197-
if(
198-
auto hardness_collector = dynamic_cast<hardness_collectort *>(&*satcheck))
199-
{
200-
std::unique_ptr<solver_hardnesst> solver_hardness =
201-
std::make_unique<solver_hardnesst>();
202-
solver_hardness->set_outfile(options.get_option("write-solver-stats-to"));
203-
hardness_collector->solver_hardness = std::move(solver_hardness);
204-
}
205-
else
206-
{
207-
messaget log(message_handler);
208-
log.warning()
209-
<< "Configured solver does not support --write-solver-stats-to. "
210-
<< "Solver stats will not be written." << messaget::eom;
211-
}
199+
messaget log(message_handler);
200+
log.warning()
201+
<< "Configured solver does not support --write-solver-stats-to. "
202+
<< "Solver stats will not be written." << messaget::eom;
203+
}
204+
return satcheck;
205+
}
206+
207+
template <typename SatcheckT>
208+
static typename std::enable_if<
209+
std::is_base_of<hardness_collectort, SatcheckT>::value,
210+
std::unique_ptr<SatcheckT>>::type
211+
make_satcheck_prop(message_handlert &message_handler, const optionst &options)
212+
{
213+
auto satcheck = std::make_unique<SatcheckT>(message_handler);
214+
if(options.is_set("write-solver-stats-to"))
215+
{
216+
std::unique_ptr<solver_hardnesst> solver_hardness =
217+
std::make_unique<solver_hardnesst>();
218+
solver_hardness->set_outfile(options.get_option("write-solver-stats-to"));
219+
satcheck->solver_hardness = std::move(solver_hardness);
212220
}
213221
return satcheck;
214222
}

0 commit comments

Comments
 (0)