|
1 | 1 | // Author: Diffblue Ltd.
|
2 | 2 |
|
3 |
| -#include <solvers/smt2_incremental/construct_value_expr_from_smt.h> |
4 |
| - |
5 |
| -#include <solvers/smt2_incremental/smt_terms.h> |
6 |
| - |
7 | 3 | #include <util/arith_tools.h>
|
8 | 4 | #include <util/bitvector_types.h>
|
| 5 | +#include <util/pointer_expr.h> |
9 | 6 | #include <util/std_expr.h>
|
10 | 7 | #include <util/std_types.h>
|
11 | 8 | #include <util/type.h>
|
12 | 9 |
|
| 10 | +#include <solvers/smt2_incremental/construct_value_expr_from_smt.h> |
| 11 | +#include <solvers/smt2_incremental/smt_terms.h> |
| 12 | + |
13 | 13 | class value_expr_from_smt_factoryt : public smt_term_const_downcast_visitort
|
14 | 14 | {
|
15 | 15 | private:
|
@@ -37,13 +37,35 @@ class value_expr_from_smt_factoryt : public smt_term_const_downcast_visitort
|
37 | 37 |
|
38 | 38 | void visit(const smt_bit_vector_constant_termt &bit_vector_constant) override
|
39 | 39 | {
|
| 40 | + const auto sort_width = bit_vector_constant.get_sort().bit_width(); |
| 41 | + if( |
| 42 | + const auto pointer_type = |
| 43 | + type_try_dynamic_cast<pointer_typet>(type_to_construct)) |
| 44 | + { |
| 45 | + INVARIANT( |
| 46 | + pointer_type->get_width() == sort_width, |
| 47 | + "Width of smt bit vector term must match the width of pointer type."); |
| 48 | + if(bit_vector_constant.value() == 0) |
| 49 | + { |
| 50 | + result = null_pointer_exprt{*pointer_type}; |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + // The reason we are manually constructing a constant_exprt here is a |
| 55 | + // limitation in the design of `from_integer`, which only allows it to |
| 56 | + // be used with pointer values of 0 (null pointers). |
| 57 | + result = constant_exprt{ |
| 58 | + integer2bvrep(bit_vector_constant.value(), sort_width), |
| 59 | + *pointer_type}; |
| 60 | + } |
| 61 | + return; |
| 62 | + } |
40 | 63 | if(
|
41 | 64 | const auto bitvector_type =
|
42 | 65 | type_try_dynamic_cast<bitvector_typet>(type_to_construct))
|
43 | 66 | {
|
44 | 67 | INVARIANT(
|
45 |
| - bitvector_type->get_width() == |
46 |
| - bit_vector_constant.get_sort().bit_width(), |
| 68 | + bitvector_type->get_width() == sort_width, |
47 | 69 | "Width of smt bit vector term must match the width of bit vector "
|
48 | 70 | "type.");
|
49 | 71 | result = from_integer(bit_vector_constant.value(), type_to_construct);
|
|
0 commit comments