22
22
#include < iomanip>
23
23
#include < stack>
24
24
#include < util/expr_iterator.h>
25
- #include < util/optional .h>
25
+ #include < util/arith_tools .h>
26
26
#include < util/simplify_expr.h>
27
27
#include < solvers/sat/satcheck.h>
28
28
#include < solvers/refinement/string_constraint_instantiation.h>
29
29
#include < java_bytecode/java_types.h>
30
- #include " expr_cast.h"
31
30
32
31
static exprt substitute_array_with_expr (const exprt &expr, const exprt &index);
33
32
@@ -795,12 +794,13 @@ static optionalt<exprt> get_array(
795
794
return {};
796
795
}
797
796
798
- unsigned n ;
799
- if (to_unsigned_integer ( to_constant_expr (size_val), n) )
797
+ auto n_opt = numeric_cast<std:: size_t >(size_val) ;
798
+ if (!n_opt )
800
799
{
801
800
stream << " (sr::get_array) size is not valid" << eom;
802
801
return {};
803
802
}
803
+ std::size_t n = *n_opt;
804
804
805
805
const array_typet ret_type (char_type, from_integer (n, index_type));
806
806
array_exprt ret (ret_type);
@@ -825,9 +825,11 @@ static optionalt<exprt> get_array(
825
825
for (size_t i = 0 ; i < arr_val.operands ().size (); i += 2 )
826
826
{
827
827
exprt index = arr_val.operands ()[i];
828
- unsigned idx;
829
- if (!to_unsigned_integer (to_constant_expr (index ), idx) && idx<n)
830
- initial_map[idx] = arr_val.operands ()[i + 1 ];
828
+ if (auto idx = numeric_cast<std::size_t >(index ))
829
+ {
830
+ if (*idx < n)
831
+ initial_map[*idx] = arr_val.operands ()[i + 1 ];
832
+ }
831
833
}
832
834
833
835
// Pad the concretized values to the left to assign the uninitialized
@@ -852,13 +854,11 @@ static optionalt<exprt> get_array(
852
854
// / \return a string
853
855
static std::string string_of_array (const array_exprt &arr)
854
856
{
855
- unsigned n;
856
857
if (arr.type ().id ()!=ID_array)
857
858
return std::string (" " );
858
859
859
860
exprt size_expr=to_array_type (arr.type ()).size ();
860
- PRECONDITION (size_expr.id ()==ID_constant);
861
- to_unsigned_integer (to_constant_expr (size_expr), n);
861
+ auto n = numeric_cast_v<std::size_t >(size_expr);
862
862
return utf16_constant_array_to_java (arr, n);
863
863
}
864
864
@@ -1010,7 +1010,7 @@ exprt fill_in_array_with_expr(
1010
1010
std::map<std::size_t , exprt> initial_map;
1011
1011
1012
1012
// Set the last index to be sure the array will have the right length
1013
- const auto &array_size_opt = expr_cast <std::size_t >(array_type.size ());
1013
+ const auto &array_size_opt = numeric_cast <std::size_t >(array_type.size ());
1014
1014
if (array_size_opt && *array_size_opt > 0 )
1015
1015
initial_map.emplace (
1016
1016
*array_size_opt - 1 ,
@@ -1022,7 +1022,8 @@ exprt fill_in_array_with_expr(
1022
1022
// statements
1023
1023
const with_exprt &with_expr = to_with_expr (it);
1024
1024
const exprt &then_expr=with_expr.new_value ();
1025
- const auto index =expr_cast_v<std::size_t >(with_expr.where ());
1025
+ const auto index =
1026
+ numeric_cast_v<std::size_t >(to_constant_expr (with_expr.where ()));
1026
1027
if (
1027
1028
index < string_max_length && (!array_size_opt || index < *array_size_opt))
1028
1029
initial_map.emplace (index , then_expr);
@@ -1047,7 +1048,7 @@ exprt fill_in_array_expr(const array_exprt &expr, std::size_t string_max_length)
1047
1048
1048
1049
// Map of the parts of the array that are initialized
1049
1050
std::map<std::size_t , exprt> initial_map;
1050
- const auto &array_size_opt = expr_cast <std::size_t >(array_type.size ());
1051
+ const auto &array_size_opt = numeric_cast <std::size_t >(array_type.size ());
1051
1052
1052
1053
if (array_size_opt && *array_size_opt > 0 )
1053
1054
initial_map.emplace (
@@ -1180,14 +1181,14 @@ static exprt negation_of_not_contains_constraint(
1180
1181
const exprt &ubu=axiom.univ_upper_bound ();
1181
1182
if (lbu.id ()==ID_constant && ubu.id ()==ID_constant)
1182
1183
{
1183
- const auto lb_int=expr_cast <mp_integer>(lbu);
1184
- const auto ub_int=expr_cast <mp_integer>(ubu);
1184
+ const auto lb_int = numeric_cast <mp_integer>(lbu);
1185
+ const auto ub_int = numeric_cast <mp_integer>(ubu);
1185
1186
if (!lb_int || !ub_int || *ub_int<=*lb_int)
1186
1187
return false_exprt ();
1187
1188
}
1188
1189
1189
- const auto lbe=expr_cast_v <mp_integer>(axiom.exists_lower_bound ());
1190
- const auto ube=expr_cast_v <mp_integer>(axiom.exists_upper_bound ());
1190
+ const auto lbe = numeric_cast_v <mp_integer>(axiom.exists_lower_bound ());
1191
+ const auto ube = numeric_cast_v <mp_integer>(axiom.exists_upper_bound ());
1191
1192
1192
1193
// If the premise is false, the implication is trivially true, so the
1193
1194
// negation is false.
@@ -1230,8 +1231,8 @@ static exprt negation_of_constraint(const string_constraintt &axiom)
1230
1231
const exprt &ub=axiom.upper_bound ();
1231
1232
if (lb.id ()==ID_constant && ub.id ()==ID_constant)
1232
1233
{
1233
- const auto lb_int=expr_cast <mp_integer>(lb);
1234
- const auto ub_int=expr_cast <mp_integer>(ub);
1234
+ const auto lb_int = numeric_cast <mp_integer>(lb);
1235
+ const auto ub_int = numeric_cast <mp_integer>(ub);
1235
1236
if (!lb_int || !ub_int || ub_int<=lb_int)
1236
1237
return false_exprt ();
1237
1238
}
@@ -1786,7 +1787,7 @@ static void add_to_index_set(
1786
1787
exprt i)
1787
1788
{
1788
1789
simplify (i, ns);
1789
- const bool is_size_t =expr_cast <std::size_t >(i).has_value ();
1790
+ const bool is_size_t = numeric_cast <std::size_t >(i).has_value ();
1790
1791
if (i.id ()!=ID_constant || is_size_t )
1791
1792
{
1792
1793
std::vector<exprt> sub_arrays;
@@ -2047,7 +2048,7 @@ exprt substitute_array_lists(exprt expr, size_t string_max_length)
2047
2048
{
2048
2049
const exprt &index =expr.operands ()[i];
2049
2050
const exprt &value=expr.operands ()[i+1 ];
2050
- const auto index_value=expr_cast <std::size_t >(index );
2051
+ const auto index_value = numeric_cast <std::size_t >(index );
2051
2052
if (!index .is_constant () ||
2052
2053
(index_value && *index_value<string_max_length))
2053
2054
ret_expr=with_exprt (ret_expr, index , value);
@@ -2097,7 +2098,7 @@ exprt string_refinementt::get(const exprt &expr) const
2097
2098
if (set.find (arr) != set.end ())
2098
2099
{
2099
2100
exprt length = super_get (arr.length ());
2100
- if (const auto n = expr_cast <std::size_t >(length))
2101
+ if (const auto n = numeric_cast <std::size_t >(length))
2101
2102
{
2102
2103
exprt arr_model =
2103
2104
array_exprt (array_typet (arr.type ().subtype (), length));
0 commit comments