Skip to content

Commit 662f90a

Browse files
committed
Change the unstructured commits to invalid_user_input_exceptions and preconditions/invariants.
1 parent 4fb727c commit 662f90a

File tree

4 files changed

+46
-29
lines changed

4 files changed

+46
-29
lines changed

src/cbmc/bmc.cpp

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

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

1920
#include <langapi/language_util.h>
@@ -296,9 +297,8 @@ void bmct::get_memory_model()
296297
memory_model=util_make_unique<memory_model_psot>(ns);
297298
else
298299
{
299-
error() << "Invalid memory model " << mm
300-
<< " -- use one of sc, tso, pso" << eom;
301-
throw "invalid memory model";
300+
throw invalid_user_input_exceptiont(
301+
"Invalid parameter " + mm, "--mm", "values of sc, tso, pso");
302302
}
303303
}
304304

src/cbmc/bv_cbmc.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ 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+
DATA_INVARIANT(expr.operands().size() != 4,
18+
"waitfor expression is expected to have four operands");
2219

2320
const exprt &old_cycle=expr.op0();
2421
const exprt &cycle_var=expr.op1();
@@ -27,12 +24,8 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr)
2724
const exprt new_cycle = make_free_bv_expr(expr.type());
2825

2926
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-
}
27+
bool successful_cast = to_integer(bound, bound_value);
28+
INVARIANT(successful_cast, "waitfor bound must be a constant");
3629

3730
{
3831
// constraint: new_cycle>=old_cycle

src/cbmc/cbmc_solvers.cpp

Lines changed: 35 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+
"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+
"Failed to open suggested file: " + filename, "--outfile");
218222
}
219223

220224
auto smt2_conv=
@@ -237,20 +241,38 @@ 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+
"Sorry, this solver does not support beautification",
250+
"--beautify");
244251
}
245252
}
246253

247254
void cbmc_solverst::no_incremental_check()
248255
{
249-
if(options.get_bool_option("all-properties") ||
250-
options.get_option("cover")!="" ||
251-
options.get_option("incremental-check")!="")
256+
bool all_properties = options.get_bool_option("all-properties");
257+
bool cover = options.get_option("cover") != "";
258+
bool incremental_check = options.get_option("incremental-check") != "";
259+
260+
if(all_properties)
261+
{
262+
throw invalid_user_input_exceptiont(
263+
"Sorry, this solver does not support incremental solving",
264+
"--all_properties");
265+
}
266+
else if(cover)
267+
{
268+
throw invalid_user_input_exceptiont(
269+
"Sorry, this solver does not support incremental solving",
270+
"--cover");
271+
}
272+
else if(incremental_check)
252273
{
253-
error() << "sorry, this solver does not support incremental solving" << eom;
254-
throw 0;
274+
throw invalid_user_input_exceptiont(
275+
"Sorry, this solver does not support incremental solving",
276+
"--incremental-check");
255277
}
256278
}

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+
"Failed to open file: " + filename, "--outfile");
147149
}
148150

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

0 commit comments

Comments
 (0)