Skip to content

Commit 176ccad

Browse files
thk123Thomas Kiley
thk123
authored and
Thomas Kiley
committed
Introduce throwing bv_conversion expection
Remove suprisous namespace from bv_conversion_exceptions
1 parent da93524 commit 176ccad

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ bvt boolbvt::conversion_failed(const exprt &expr)
152152
return prop.new_variables(width);
153153
}
154154

155+
/// TODO
156+
/// \param expr: TODO
157+
/// \return TODO
158+
/// \throws bitvector_conversion_exceptiont raised if converting byte_extraction
159+
/// goes wrong. TODO: extend for other types of conversion exception).
155160
bvt boolbvt::convert_bitvector(const exprt &expr)
156161
{
157162
if(expr.type().id()==ID_bool)

src/solvers/flattening/boolbv_byte_extract.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/endianness_map.h>
1717

1818
#include "flatten_byte_operators.h"
19+
#include "flatten_byte_extract_exceptions.h"
20+
#include "bv_conversion_exceptions.h"
1921

2022
bvt map_bv(const endianness_mapt &map, const bvt &src)
2123
{
@@ -42,8 +44,16 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
4244
// if we extract from an unbounded array, call the flattening code
4345
if(is_unbounded_array(expr.op().type()))
4446
{
45-
exprt tmp=flatten_byte_extract(expr, ns);
46-
return convert_bv(tmp);
47+
try
48+
{
49+
exprt tmp = flatten_byte_extract(expr, ns);
50+
return convert_bv(tmp);
51+
}
52+
catch(const flatten_byte_extract_exceptiont &byte_extract_flatten_exception)
53+
{
54+
std::throw_with_nested(
55+
bitvector_conversion_exceptiont("Can't convert byte_extraction", expr));
56+
}
4757
}
4858

4959
std::size_t width=boolbv_width(expr.type());
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************\
2+
3+
Module: Bit vector conversion
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Exceptions that can be raised in bv_conversion
11+
12+
#ifndef CPROVER_SOLVERS_FLATTENING_BV_CONVERSION_EXCEPTIONS_H
13+
#define CPROVER_SOLVERS_FLATTENING_BV_CONVERSION_EXCEPTIONS_H
14+
15+
#include "flatten_byte_extract_exceptions.h"
16+
#include "flatten_byte_operators.h"
17+
#include <util/endianness_map.h>
18+
#include <util/arith_tools.h>
19+
#include "boolbv.h"
20+
#include "bv_conversion_exceptions.h"
21+
22+
class bitvector_conversion_exceptiont : public std::runtime_error
23+
{
24+
public:
25+
bitvector_conversion_exceptiont(
26+
const std::string &exception_message,
27+
const exprt &bv_expr)
28+
: runtime_error(exception_message), bv_expr(bv_expr)
29+
{
30+
}
31+
32+
private:
33+
exprt bv_expr;
34+
};
35+
36+
#endif // CPROVER_SOLVERS_FLATTENING_BV_CONVERSION_EXCEPTIONS_H

0 commit comments

Comments
 (0)