Skip to content

Commit 375b5e0

Browse files
Merge pull request #3588 from peterschrammel/improve-solver-factory
Improve solver factory
2 parents ca49d2e + b76cd5f commit 375b5e0

File tree

2 files changed

+105
-84
lines changed

2 files changed

+105
-84
lines changed

src/goto-checker/solver_factory.cpp

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,99 @@ Author: Daniel Kroening, Peter Schrammel
1111

1212
#include "solver_factory.h"
1313

14-
#include <fstream>
1514
#include <iostream>
16-
#include <memory>
17-
#include <string>
1815

1916
#include <util/exception_utils.h>
2017
#include <util/make_unique.h>
21-
#include <util/unicode.h>
18+
#include <util/message.h>
19+
#include <util/namespace.h>
20+
#include <util/options.h>
21+
#include <util/symbol_table.h>
2222
#include <util/version.h>
2323

24+
#ifdef _MSC_VER
25+
#include <util/unicode.h>
26+
#endif
27+
2428
#include <solvers/flattening/bv_dimacs.h>
29+
#include <solvers/prop/prop.h>
30+
#include <solvers/prop/prop_conv.h>
2531
#include <solvers/refinement/bv_refinement.h>
2632
#include <solvers/refinement/string_refinement.h>
2733
#include <solvers/sat/dimacs_cnf.h>
2834
#include <solvers/sat/satcheck.h>
29-
#include <solvers/smt2/smt2_dec.h>
35+
36+
solver_factoryt::solver_factoryt(
37+
const optionst &_options,
38+
const symbol_tablet &_symbol_table,
39+
message_handlert &_message_handler,
40+
bool _output_xml_in_refinement)
41+
: options(_options),
42+
symbol_table(_symbol_table),
43+
ns(_symbol_table),
44+
message_handler(_message_handler),
45+
output_xml_in_refinement(_output_xml_in_refinement)
46+
{
47+
}
48+
49+
solver_factoryt::solvert::solvert(std::unique_ptr<prop_convt> p)
50+
: prop_conv_ptr(std::move(p))
51+
{
52+
}
53+
54+
solver_factoryt::solvert::solvert(
55+
std::unique_ptr<prop_convt> p1,
56+
std::unique_ptr<propt> p2)
57+
: prop_ptr(std::move(p2)), prop_conv_ptr(std::move(p1))
58+
{
59+
}
60+
61+
solver_factoryt::solvert::solvert(
62+
std::unique_ptr<prop_convt> p1,
63+
std::unique_ptr<std::ofstream> p2)
64+
: ofstream_ptr(std::move(p2)), prop_conv_ptr(std::move(p1))
65+
{
66+
}
67+
68+
prop_convt &solver_factoryt::solvert::prop_conv() const
69+
{
70+
PRECONDITION(prop_conv_ptr != nullptr);
71+
return *prop_conv_ptr;
72+
}
73+
74+
propt &solver_factoryt::solvert::prop() const
75+
{
76+
PRECONDITION(prop_ptr != nullptr);
77+
return *prop_ptr;
78+
}
79+
80+
void solver_factoryt::solvert::set_prop_conv(std::unique_ptr<prop_convt> p)
81+
{
82+
prop_conv_ptr = std::move(p);
83+
}
84+
85+
void solver_factoryt::solvert::set_prop(std::unique_ptr<propt> p)
86+
{
87+
prop_ptr = std::move(p);
88+
}
89+
90+
void solver_factoryt::solvert::set_ofstream(std::unique_ptr<std::ofstream> p)
91+
{
92+
ofstream_ptr = std::move(p);
93+
}
94+
95+
std::unique_ptr<solver_factoryt::solvert> solver_factoryt::get_solver()
96+
{
97+
if(options.get_bool_option("dimacs"))
98+
return get_dimacs();
99+
if(options.get_bool_option("refine"))
100+
return get_bv_refinement();
101+
else if(options.get_bool_option("refine-strings"))
102+
return get_string_refinement();
103+
if(options.get_bool_option("smt2"))
104+
return get_smt2(get_smt2_solver_type());
105+
return get_default();
106+
}
30107

31108
/// Uses the options to pick an SMT 2.0 solver
32109
/// \return An smt2_dect::solvert giving the solver to use.

src/goto-checker/solver_factory.h

Lines changed: 23 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,109 +12,53 @@ Author: Daniel Kroening, Peter Schrammel
1212
#ifndef CPROVER_GOTO_CHECKER_SOLVER_FACTORY_H
1313
#define CPROVER_GOTO_CHECKER_SOLVER_FACTORY_H
1414

15-
#include <list>
16-
#include <map>
1715
#include <memory>
1816

19-
#include <util/options.h>
20-
21-
#include <goto-symex/symex_target_equation.h>
22-
#include <solvers/prop/prop.h>
23-
#include <solvers/prop/prop_conv.h>
24-
#include <solvers/sat/cnf.h>
25-
#include <solvers/sat/satcheck.h>
2617
#include <solvers/smt2/smt2_dec.h>
2718

19+
class message_handlert;
20+
class namespacet;
21+
class optionst;
22+
class propt;
23+
class prop_convt;
24+
class symbol_tablet;
25+
2826
class solver_factoryt
2927
{
3028
public:
3129
solver_factoryt(
3230
const optionst &_options,
3331
const symbol_tablet &_symbol_table,
3432
message_handlert &_message_handler,
35-
bool _output_xml_in_refinement)
36-
: options(_options),
37-
symbol_table(_symbol_table),
38-
ns(_symbol_table),
39-
message_handler(_message_handler),
40-
output_xml_in_refinement(_output_xml_in_refinement)
41-
{
42-
}
33+
bool _output_xml_in_refinement);
4334

4435
// The solver class,
4536
// which owns a variety of allocated objects.
4637
class solvert
4738
{
4839
public:
49-
solvert()
50-
{
51-
}
52-
53-
explicit solvert(std::unique_ptr<prop_convt> p)
54-
: prop_conv_ptr(std::move(p))
55-
{
56-
}
57-
58-
solvert(std::unique_ptr<prop_convt> p1, std::unique_ptr<propt> p2)
59-
: prop_ptr(std::move(p2)), prop_conv_ptr(std::move(p1))
60-
{
61-
}
62-
63-
solvert(std::unique_ptr<prop_convt> p1, std::unique_ptr<std::ofstream> p2)
64-
: ofstream_ptr(std::move(p2)), prop_conv_ptr(std::move(p1))
65-
{
66-
}
67-
68-
prop_convt &prop_conv() const
69-
{
70-
PRECONDITION(prop_conv_ptr != nullptr);
71-
return *prop_conv_ptr;
72-
}
73-
74-
propt &prop() const
75-
{
76-
PRECONDITION(prop_ptr != nullptr);
77-
return *prop_ptr;
78-
}
79-
80-
void set_prop_conv(std::unique_ptr<prop_convt> p)
81-
{
82-
prop_conv_ptr = std::move(p);
83-
}
84-
85-
void set_prop(std::unique_ptr<propt> p)
86-
{
87-
prop_ptr = std::move(p);
88-
}
89-
90-
void set_ofstream(std::unique_ptr<std::ofstream> p)
91-
{
92-
ofstream_ptr = std::move(p);
93-
}
40+
solvert() = default;
41+
explicit solvert(std::unique_ptr<prop_convt> p);
42+
solvert(std::unique_ptr<prop_convt> p1, std::unique_ptr<propt> p2);
43+
solvert(std::unique_ptr<prop_convt> p1, std::unique_ptr<std::ofstream> p2);
44+
45+
prop_convt &prop_conv() const;
46+
propt &prop() const;
47+
48+
void set_prop_conv(std::unique_ptr<prop_convt> p);
49+
void set_prop(std::unique_ptr<propt> p);
50+
void set_ofstream(std::unique_ptr<std::ofstream> p);
9451

9552
// the objects are deleted in the opposite order they appear below
9653
std::unique_ptr<std::ofstream> ofstream_ptr;
9754
std::unique_ptr<propt> prop_ptr;
9855
std::unique_ptr<prop_convt> prop_conv_ptr;
9956
};
10057

101-
// returns a solvert object
102-
virtual std::unique_ptr<solvert> get_solver()
103-
{
104-
if(options.get_bool_option("dimacs"))
105-
return get_dimacs();
106-
if(options.get_bool_option("refine"))
107-
return get_bv_refinement();
108-
else if(options.get_bool_option("refine-strings"))
109-
return get_string_refinement();
110-
if(options.get_bool_option("smt2"))
111-
return get_smt2(get_smt2_solver_type());
112-
return get_default();
113-
}
114-
115-
virtual ~solver_factoryt()
116-
{
117-
}
58+
/// Returns a solvert object
59+
virtual std::unique_ptr<solvert> get_solver();
60+
61+
virtual ~solver_factoryt() = default;
11862

11963
protected:
12064
const optionst &options;

0 commit comments

Comments
 (0)