Skip to content

Commit 4ffe61a

Browse files
committed
Change the unstructured commits to invalid_user_input_exceptions and preconditions/invariants.
1 parent bbc8518 commit 4ffe61a

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

src/cbmc/bmc.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Author: Daniel Kroening, [email protected]
1414
#include <chrono>
1515
#include <iostream>
1616

17+
#include <util/exception_utils.h>
1718
#include <util/exit_codes.h>
19+
#include <util/exception_utils.h>
1820

1921
#include <langapi/language_util.h>
2022

@@ -296,9 +298,8 @@ void bmct::get_memory_model()
296298
memory_model=util_make_unique<memory_model_psot>(ns);
297299
else
298300
{
299-
error() << "Invalid memory model " << mm
300-
<< " -- use one of sc, tso, pso" << eom;
301-
throw "invalid memory model";
301+
throw invalid_user_input_exceptiont(
302+
"Reason: Invalid parameter " + mm, "--mm", "values of sc, tso, pso");
302303
}
303304
}
304305

src/cbmc/bv_cbmc.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ Author: Daniel Kroening, [email protected]
99
#include "bv_cbmc.h"
1010

1111
#include <util/arith_tools.h>
12+
#include <util/invariant.h>
1213
#include <util/replace_expr.h>
1314

1415
bvt bv_cbmct::convert_waitfor(const exprt &expr)
1516
{
16-
if(expr.operands().size()!=4)
17-
{
18-
error().source_location=expr.find_source_location();
19-
error() << "waitfor expected to have four operands" << eom;
20-
throw 0;
21-
}
17+
PRECONDITION(expr.operands().size() != 4);
2218

2319
const exprt &old_cycle=expr.op0();
2420
const exprt &cycle_var=expr.op1();
@@ -27,12 +23,8 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr)
2723
const exprt new_cycle = make_free_bv_expr(expr.type());
2824

2925
mp_integer bound_value;
30-
if(to_integer(bound, bound_value))
31-
{
32-
error().source_location=expr.find_source_location();
33-
error() << "waitfor bound must be a constant" << eom;
34-
throw 0;
35-
}
26+
bool successful_cast = to_integer(bound, bound_value);
27+
INVARIANT(successful_cast, "waitfor bound must be a constant");
3628

3729
{
3830
// constraint: new_cycle>=old_cycle

src/cbmc/cbmc_solvers.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ Author: Daniel Kroening, [email protected]
1414
#include <fstream>
1515
#include <iostream>
1616
#include <memory>
17+
#include <string>
1718

18-
#include <util/unicode.h>
19+
#include <util/exception_utils.h>
1920
#include <util/make_unique.h>
21+
#include <util/unicode.h>
2022

2123
#include <solvers/sat/satcheck.h>
2224
#include <solvers/refinement/bv_refinement.h>
@@ -168,8 +170,10 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2(
168170
{
169171
if(solver==smt2_dect::solvert::GENERIC)
170172
{
171-
error() << "please use --outfile" << eom;
172-
throw 0;
173+
throw invalid_user_input_exceptiont(
174+
"Reason: Failed to provide a filename",
175+
"--outfile",
176+
"provide a filename with --outfile");
173177
}
174178

175179
auto smt2_dec=
@@ -213,8 +217,8 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2(
213217

214218
if(!*out)
215219
{
216-
error() << "failed to open " << filename << eom;
217-
throw 0;
220+
throw invalid_user_input_exceptiont(
221+
"Reason: Failed to open suggested file: " + filename, "--outfile", "");
218222
}
219223

220224
auto smt2_conv=
@@ -237,20 +241,42 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2(
237241

238242
void cbmc_solverst::no_beautification()
239243
{
240-
if(options.get_bool_option("beautify"))
244+
bool beautify = options.get_bool_option("beautify");
245+
246+
if(beautify)
241247
{
242-
error() << "sorry, this solver does not support beautification" << eom;
243-
throw 0;
248+
throw invalid_user_input_exceptiont(
249+
"Reason: sorry, this solver does not support beautification",
250+
"--beautify",
251+
"");
244252
}
245253
}
246254

247255
void cbmc_solverst::no_incremental_check()
248256
{
249-
if(options.get_bool_option("all-properties") ||
250-
options.get_option("cover")!="" ||
251-
options.get_option("incremental-check")!="")
257+
bool all_properties = options.get_bool_option("all-properties");
258+
bool cover = options.get_option("cover") != "";
259+
bool incremental_check = options.get_option("incremental-check") != "";
260+
261+
if(all_properties)
262+
{
263+
throw invalid_user_input_exceptiont(
264+
"Reason: sorry, this solver does not support incremental solving",
265+
"--all_properties",
266+
"");
267+
}
268+
else if(cover)
269+
{
270+
throw invalid_user_input_exceptiont(
271+
"Reason: sorry, this solver does not support incremental solving",
272+
"--cover",
273+
"");
274+
}
275+
else if(incremental_check)
252276
{
253-
error() << "sorry, this solver does not support incremental solving" << eom;
254-
throw 0;
277+
throw invalid_user_input_exceptiont(
278+
"Reason: sorry, this solver does not support incremental solving",
279+
"--incremental-check",
280+
"");
255281
}
256282
}

src/cbmc/show_vcc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <langapi/mode.h>
1818
#include <langapi/language_util.h>
1919

20+
#include <util/exception_utils.h>
2021
#include <util/json.h>
2122
#include <util/json_expr.h>
2223

@@ -143,7 +144,8 @@ void bmct::show_vcc()
143144
{
144145
of.open(filename);
145146
if(!of)
146-
throw "failed to open file "+filename;
147+
throw invalid_user_input_exceptiont(
148+
"Reason: failed to open suggested file", "--outfile", "");
147149
}
148150

149151
std::ostream &out=have_file?of:std::cout;

0 commit comments

Comments
 (0)