|
26 | 26 | #include <solvers/sat/satcheck.h>
|
27 | 27 | #include <solvers/refinement/string_constraint_instantiation.h>
|
28 | 28 | #include <java_bytecode/java_types.h>
|
| 29 | +#include "expr_cast.h" |
29 | 30 |
|
30 | 31 | static exprt substitute_array_with_expr(const exprt &expr, const exprt &index);
|
31 | 32 |
|
@@ -95,63 +96,6 @@ static exprt get_array(
|
95 | 96 | const std::function<exprt(const exprt &)> &super_get,
|
96 | 97 | const exprt &arr);
|
97 | 98 |
|
98 |
| -/// Convert exprt to a specific type. Throw bad_cast if conversion |
99 |
| -/// cannot be performed |
100 |
| -/// Generic case doesn't exist, specialize for different types accordingly |
101 |
| -/// TODO: this should go to util |
102 |
| - |
103 |
| -// Tag dispatching struct |
104 |
| - |
105 |
| -template<typename T> |
106 |
| -struct expr_cast_implt final { }; |
107 |
| - |
108 |
| -template<> |
109 |
| -struct expr_cast_implt<mp_integer> final |
110 |
| -{ |
111 |
| - optionalt<mp_integer> operator()(const exprt &expr) const |
112 |
| - { |
113 |
| - mp_integer out; |
114 |
| - if(to_integer(expr, out)) |
115 |
| - return {}; |
116 |
| - return out; |
117 |
| - } |
118 |
| -}; |
119 |
| - |
120 |
| -template<> |
121 |
| -struct expr_cast_implt<std::size_t> final |
122 |
| -{ |
123 |
| - optionalt<std::size_t> operator()(const exprt &expr) const |
124 |
| - { |
125 |
| - if(const auto tmp=expr_cast_implt<mp_integer>()(expr)) |
126 |
| - if(tmp->is_long() && *tmp>=0) |
127 |
| - return tmp->to_long(); |
128 |
| - return {}; |
129 |
| - } |
130 |
| -}; |
131 |
| - |
132 |
| -template<> |
133 |
| -struct expr_cast_implt<string_exprt> final |
134 |
| -{ |
135 |
| - optionalt<string_exprt> operator()(const exprt &expr) const |
136 |
| - { |
137 |
| - if(is_refined_string_type(expr.type())) |
138 |
| - return to_string_expr(expr); |
139 |
| - return {}; |
140 |
| - } |
141 |
| -}; |
142 |
| - |
143 |
| -template<typename T> |
144 |
| -optionalt<T> expr_cast(const exprt& expr) |
145 |
| -{ return expr_cast_implt<T>()(expr); } |
146 |
| - |
147 |
| -template<typename T> |
148 |
| -T expr_cast_v(const exprt &expr) |
149 |
| -{ |
150 |
| - const auto maybe=expr_cast<T>(expr); |
151 |
| - INVARIANT(maybe, "Bad conversion"); |
152 |
| - return *maybe; |
153 |
| -} |
154 |
| - |
155 | 99 | /// Convert index-value map to a vector of values. If a value for an
|
156 | 100 | /// index is not defined, set it to the value referenced by the next higher
|
157 | 101 | /// index. The length of the resulting vector is the key of the map's
|
|
0 commit comments