Skip to content

Commit fc294f8

Browse files
Use numeric_cast instead of refinement/expr_cast
1 parent 946b6e2 commit fc294f8

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/solvers/refinement/string_constraint_generator_transformation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Author: Romain Brenguier, [email protected]
1313

1414
#include <solvers/refinement/string_refinement_invariant.h>
1515
#include <solvers/refinement/string_constraint_generator.h>
16-
#include "expr_cast.h"
16+
#include <util/arith_tools.h>
1717

1818
/// Reduce or extend a string to have the given length
1919
///
@@ -442,8 +442,8 @@ static optionalt<std::pair<exprt, exprt>> to_char_pair(
442442
return std::make_pair(expr1, expr2);
443443
const auto expr1_str = get_string_expr(expr1);
444444
const auto expr2_str = get_string_expr(expr2);
445-
const auto expr1_length=expr_cast<size_t>(expr1_str.length());
446-
const auto expr2_length=expr_cast<size_t>(expr2_str.length());
445+
const auto expr1_length = numeric_cast<std::size_t>(expr1_str.length());
446+
const auto expr2_length = numeric_cast<std::size_t>(expr2_str.length());
447447
if(expr1_length && expr2_length && *expr1_length==1 && *expr2_length==1)
448448
return std::make_pair(exprt(expr1_str[0]), exprt(expr2_str[0]));
449449
return { };

src/solvers/refinement/string_refinement.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ Author: Alberto Griggio, [email protected]
2222
#include <iomanip>
2323
#include <stack>
2424
#include <util/expr_iterator.h>
25-
#include <util/optional.h>
25+
#include <util/arith_tools.h>
2626
#include <util/simplify_expr.h>
2727
#include <solvers/sat/satcheck.h>
2828
#include <solvers/refinement/string_constraint_instantiation.h>
2929
#include <java_bytecode/java_types.h>
30-
#include "expr_cast.h"
3130

3231
static exprt substitute_array_with_expr(const exprt &expr, const exprt &index);
3332

@@ -852,7 +851,6 @@ static optionalt<exprt> get_array(
852851
/// \return a string
853852
static std::string string_of_array(const array_exprt &arr)
854853
{
855-
unsigned n;
856854
if(arr.type().id()!=ID_array)
857855
return std::string("");
858856

@@ -1010,7 +1008,7 @@ exprt fill_in_array_with_expr(
10101008
std::map<std::size_t, exprt> initial_map;
10111009

10121010
// 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());
1011+
const auto &array_size_opt = numeric_cast<std::size_t>(array_type.size());
10141012
if(array_size_opt && *array_size_opt > 0)
10151013
initial_map.emplace(
10161014
*array_size_opt - 1,
@@ -1022,7 +1020,8 @@ exprt fill_in_array_with_expr(
10221020
// statements
10231021
const with_exprt &with_expr = to_with_expr(it);
10241022
const exprt &then_expr=with_expr.new_value();
1025-
const auto index=expr_cast_v<std::size_t>(with_expr.where());
1023+
const auto index =
1024+
numeric_cast_v<std::size_t>(to_constant_expr(with_expr.where()));
10261025
if(
10271026
index < string_max_length && (!array_size_opt || index < *array_size_opt))
10281027
initial_map.emplace(index, then_expr);
@@ -1047,7 +1046,7 @@ exprt fill_in_array_expr(const array_exprt &expr, std::size_t string_max_length)
10471046

10481047
// Map of the parts of the array that are initialized
10491048
std::map<std::size_t, exprt> initial_map;
1050-
const auto &array_size_opt = expr_cast<std::size_t>(array_type.size());
1049+
const auto &array_size_opt = numeric_cast<std::size_t>(array_type.size());
10511050

10521051
if(array_size_opt && *array_size_opt > 0)
10531052
initial_map.emplace(
@@ -1180,14 +1179,14 @@ static exprt negation_of_not_contains_constraint(
11801179
const exprt &ubu=axiom.univ_upper_bound();
11811180
if(lbu.id()==ID_constant && ubu.id()==ID_constant)
11821181
{
1183-
const auto lb_int=expr_cast<mp_integer>(lbu);
1184-
const auto ub_int=expr_cast<mp_integer>(ubu);
1182+
const auto lb_int = numeric_cast<mp_integer>(lbu);
1183+
const auto ub_int = numeric_cast<mp_integer>(ubu);
11851184
if(!lb_int || !ub_int || *ub_int<=*lb_int)
11861185
return false_exprt();
11871186
}
11881187

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());
1188+
const auto lbe = numeric_cast_v<mp_integer>(axiom.exists_lower_bound());
1189+
const auto ube = numeric_cast_v<mp_integer>(axiom.exists_upper_bound());
11911190

11921191
// If the premise is false, the implication is trivially true, so the
11931192
// negation is false.
@@ -1230,8 +1229,8 @@ static exprt negation_of_constraint(const string_constraintt &axiom)
12301229
const exprt &ub=axiom.upper_bound();
12311230
if(lb.id()==ID_constant && ub.id()==ID_constant)
12321231
{
1233-
const auto lb_int=expr_cast<mp_integer>(lb);
1234-
const auto ub_int=expr_cast<mp_integer>(ub);
1232+
const auto lb_int = numeric_cast<mp_integer>(lb);
1233+
const auto ub_int = numeric_cast<mp_integer>(ub);
12351234
if(!lb_int || !ub_int || ub_int<=lb_int)
12361235
return false_exprt();
12371236
}
@@ -1786,7 +1785,7 @@ static void add_to_index_set(
17861785
exprt i)
17871786
{
17881787
simplify(i, ns);
1789-
const bool is_size_t=expr_cast<std::size_t>(i).has_value();
1788+
const bool is_size_t = numeric_cast<std::size_t>(i).has_value();
17901789
if(i.id()!=ID_constant || is_size_t)
17911790
{
17921791
std::vector<exprt> sub_arrays;
@@ -2047,7 +2046,7 @@ exprt substitute_array_lists(exprt expr, size_t string_max_length)
20472046
{
20482047
const exprt &index=expr.operands()[i];
20492048
const exprt &value=expr.operands()[i+1];
2050-
const auto index_value=expr_cast<std::size_t>(index);
2049+
const auto index_value = numeric_cast<std::size_t>(index);
20512050
if(!index.is_constant() ||
20522051
(index_value && *index_value<string_max_length))
20532052
ret_expr=with_exprt(ret_expr, index, value);
@@ -2097,7 +2096,7 @@ exprt string_refinementt::get(const exprt &expr) const
20972096
if(set.find(arr) != set.end())
20982097
{
20992098
exprt length = super_get(arr.length());
2100-
if(const auto n = expr_cast<std::size_t>(length))
2099+
if(const auto n = numeric_cast<std::size_t>(length))
21012100
{
21022101
exprt arr_model =
21032102
array_exprt(array_typet(arr.type().subtype(), length));

0 commit comments

Comments
 (0)