Skip to content

Commit 2cf0e70

Browse files
author
Daniel Kroening
authored
Merge pull request #568 from diffblue/solvert-cleanup
cleanup of CBMC solver factory
2 parents a9bafad + 4691a71 commit 2cf0e70

File tree

2 files changed

+60
-139
lines changed

2 files changed

+60
-139
lines changed

src/cbmc/cbmc_solvers.cpp

Lines changed: 18 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -102,100 +102,6 @@ smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const
102102
return s;
103103
}
104104

105-
/*******************************************************************\
106-
107-
Class: cbmc_solver_with_propt
108-
109-
Purpose: Solvers with additional objects
110-
111-
\*******************************************************************/
112-
113-
class cbmc_solver_with_propt:public cbmc_solverst::solvert
114-
{
115-
public:
116-
cbmc_solver_with_propt(
117-
prop_convt *_prop_conv,
118-
propt *_prop):
119-
cbmc_solverst::solvert(_prop_conv),
120-
prop(_prop)
121-
{
122-
assert(_prop!=NULL);
123-
}
124-
125-
~cbmc_solver_with_propt()
126-
{
127-
delete prop;
128-
}
129-
130-
protected:
131-
propt *prop;
132-
};
133-
134-
/*******************************************************************\
135-
136-
Class: cbmc_solver_with_aigpropt
137-
138-
Purpose: Solvers with additional objects
139-
140-
\*******************************************************************/
141-
142-
class cbmc_solver_with_aigpropt:public cbmc_solver_with_propt
143-
{
144-
public:
145-
cbmc_solver_with_aigpropt(
146-
prop_convt *_prop_conv,
147-
propt *_prop,
148-
aigt *_aig):
149-
cbmc_solver_with_propt(_prop_conv, _prop),
150-
aig(_aig)
151-
{
152-
assert(_aig!=NULL);
153-
}
154-
155-
~cbmc_solver_with_aigpropt()
156-
{
157-
// delete prop before the AIG
158-
delete prop;
159-
prop=NULL;
160-
delete aig;
161-
}
162-
163-
protected:
164-
aigt *aig;
165-
};
166-
167-
/*******************************************************************\
168-
169-
Class: cbmc_solver_with_filet
170-
171-
Purpose: Solvers with additional objects
172-
173-
\*******************************************************************/
174-
175-
class cbmc_solver_with_filet:public cbmc_solverst::solvert
176-
{
177-
public:
178-
cbmc_solver_with_filet(
179-
prop_convt *_prop_conv,
180-
std::ofstream *_out):
181-
cbmc_solverst::solvert(_prop_conv),
182-
out(_out)
183-
{
184-
assert(_out!=NULL);
185-
}
186-
187-
~cbmc_solver_with_filet()
188-
{
189-
// delete the prop before the file
190-
delete prop_conv_ptr;
191-
prop_conv_ptr=NULL;
192-
delete out;
193-
}
194-
195-
protected:
196-
std::ofstream *out;
197-
};
198-
199105
/*******************************************************************\
200106
201107
Function: cbmc_solverst::get_default
@@ -210,45 +116,30 @@ Function: cbmc_solverst::get_default
210116

211117
cbmc_solverst::solvert* cbmc_solverst::get_default()
212118
{
213-
solvert *solver;
119+
solvert *solver=new solvert;
214120

215121
if(options.get_bool_option("beautify") ||
216122
!options.get_bool_option("sat-preprocessor")) // no simplifier
217123
{
218124
// simplifier won't work with beautification
219-
propt *prop=new satcheck_no_simplifiert();
220-
prop->set_message_handler(get_message_handler());
221-
222-
bv_cbmct *bv_cbmc=new bv_cbmct(ns, *prop);
223-
224-
if(options.get_option("arrays-uf")=="never")
225-
bv_cbmc->unbounded_array=bv_cbmct::U_NONE;
226-
else if(options.get_option("arrays-uf")=="always")
227-
bv_cbmc->unbounded_array=bv_cbmct::U_ALL;
228-
229-
solver=new cbmc_solver_with_propt(bv_cbmc, prop);
125+
solver->set_prop(new satcheck_no_simplifiert());
230126
}
231127
else // with simplifier
232128
{
233-
#if 1
234-
propt *prop=new satcheckt();
235-
prop->set_message_handler(get_message_handler());
236-
bv_cbmct *bv_cbmc=new bv_cbmct(ns, *prop);
237-
solver=new cbmc_solver_with_propt(bv_cbmc, prop);
238-
#else
239-
aigt *aig=new aigt();
240-
propt *prop=new aig_propt(*aig);
241-
prop->set_message_handler(get_message_handler());
242-
bv_cbmct *bv_cbmc=new bv_cbmct(ns, *prop);
243-
solver=new cbmc_solver_with_aigpropt(bv_cbmc, prop, aig);
244-
#endif
245-
246-
if(options.get_option("arrays-uf")=="never")
247-
bv_cbmc->unbounded_array=bv_cbmct::U_NONE;
248-
else if(options.get_option("arrays-uf")=="always")
249-
bv_cbmc->unbounded_array=bv_cbmct::U_ALL;
129+
solver->set_prop(new satcheckt());
250130
}
251131

132+
solver->prop().set_message_handler(get_message_handler());
133+
134+
bv_cbmct *bv_cbmc=new bv_cbmct(ns, solver->prop());
135+
136+
if(options.get_option("arrays-uf")=="never")
137+
bv_cbmc->unbounded_array=bv_cbmct::U_NONE;
138+
else if(options.get_option("arrays-uf")=="always")
139+
bv_cbmc->unbounded_array=bv_cbmct::U_ALL;
140+
141+
solver->set_prop_conv(bv_cbmc);
142+
252143
return solver;
253144
}
254145

@@ -274,8 +165,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_dimacs()
274165

275166
std::string filename=options.get_option("outfile");
276167

277-
return
278-
new cbmc_solver_with_propt(new cbmc_dimacst(ns, *prop, filename), prop);
168+
return new solvert(new cbmc_dimacst(ns, *prop, filename), prop);
279169
}
280170

281171
/*******************************************************************\
@@ -318,7 +208,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_bv_refinement()
318208
bv_refinement->do_arithmetic_refinement =
319209
options.get_bool_option("refine-arithmetic");
320210

321-
return new cbmc_solver_with_propt(bv_refinement, prop);
211+
return new solvert(bv_refinement, prop);
322212
}
323213

324214
/*******************************************************************\
@@ -398,7 +288,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver)
398288

399289
smt1_conv->set_message_handler(get_message_handler());
400290

401-
return new cbmc_solver_with_filet(smt1_conv, out);
291+
return new solvert(smt1_conv, out);
402292
}
403293
}
404294

@@ -487,7 +377,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver)
487377

488378
smt2_conv->set_message_handler(get_message_handler());
489379

490-
return new cbmc_solver_with_filet(smt2_conv, out);
380+
return new solvert(smt2_conv, out);
491381
}
492382
}
493383

src/cbmc/cbmc_solvers.h

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,62 @@ class cbmc_solverst:public messaget
4747
{
4848
}
4949

50-
// The solver class (that takes care of allocated objects)
50+
// The solver class,
51+
// which owns a variety of allocated objects.
5152
class solvert
5253
{
5354
public:
54-
explicit solvert(prop_convt* _prop_conv)
55+
solvert()
5556
{
56-
assert(_prop_conv!=NULL);
57-
prop_conv_ptr = _prop_conv;
5857
}
5958

60-
~solvert()
59+
explicit solvert(prop_convt *p):prop_conv_ptr(p)
60+
{
61+
}
62+
63+
solvert(prop_convt *p1, propt *p2):
64+
prop_ptr(p2),
65+
prop_conv_ptr(p1)
66+
{
67+
}
68+
69+
solvert(prop_convt *p1, std::ofstream *p2):
70+
ofstream_ptr(p2),
71+
prop_conv_ptr(p1)
6172
{
62-
assert(prop_conv_ptr!=NULL);
63-
delete prop_conv_ptr;
6473
}
6574

66-
// use this to get the prop_conv
6775
prop_convt &prop_conv() const
6876
{
69-
assert(prop_conv_ptr!=NULL);
77+
assert(prop_conv_ptr!=nullptr);
7078
return *prop_conv_ptr;
7179
}
7280

73-
protected:
74-
prop_convt *prop_conv_ptr;
81+
propt &prop() const
82+
{
83+
assert(prop_ptr!=nullptr);
84+
return *prop_ptr;
85+
}
86+
87+
void set_prop_conv(prop_convt *p)
88+
{
89+
prop_conv_ptr=std::unique_ptr<prop_convt>(p);
90+
}
91+
92+
void set_prop(propt *p)
93+
{
94+
prop_ptr=std::unique_ptr<propt>(p);
95+
}
96+
97+
void set_ofstream(std::ofstream *p)
98+
{
99+
ofstream_ptr=std::unique_ptr<std::ofstream>(p);
100+
}
101+
102+
// the objects are deleted in the opposite order they appear below
103+
std::unique_ptr<std::ofstream> ofstream_ptr;
104+
std::unique_ptr<propt> prop_ptr;
105+
std::unique_ptr<prop_convt> prop_conv_ptr;
75106
};
76107

77108
// returns a solvert object

0 commit comments

Comments
 (0)