Skip to content

Commit 92bb205

Browse files
author
Daniel Kroening
committed
replace instances of to_unsigned_integer by numeric_cast
1 parent 163bc94 commit 92bb205

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,12 +1065,12 @@ codet java_bytecode_convert_methodt::convert_instructions(
10651065
{
10661066
PRECONDITION(!i_it->args.empty());
10671067

1068-
unsigned target;
1069-
bool ret=to_unsigned_integer(to_constant_expr(i_it->args[0]), target);
1070-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1071-
targets.insert(target);
1068+
auto target = numeric_cast<unsigned>(to_constant_expr(i_it->args[0]));
1069+
DATA_INVARIANT(
1070+
target.has_value(), "target expected to be unsigned integer");
1071+
targets.insert(target.value());
10721072

1073-
a_entry.first->second.successors.push_back(target);
1073+
a_entry.first->second.successors.push_back(target.value());
10741074

10751075
if(i_it->statement=="jsr" ||
10761076
i_it->statement=="jsr_w")
@@ -1090,11 +1090,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
10901090
{
10911091
if(is_label)
10921092
{
1093-
unsigned target;
1094-
bool ret=to_unsigned_integer(to_constant_expr(arg), target);
1095-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1096-
targets.insert(target);
1097-
a_entry.first->second.successors.push_back(target);
1093+
auto target = numeric_cast<unsigned>(to_constant_expr(arg));
1094+
DATA_INVARIANT(
1095+
target.has_value(), "target expected to be unsigned integer");
1096+
targets.insert(target.value());
1097+
a_entry.first->second.successors.push_back(target.value());
10981098
}
10991099
is_label=!is_label;
11001100
}

jbmc/src/java_bytecode/java_local_variable_table.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ static bool is_store_to_slot(
193193
{
194194
// Store with an argument:
195195
const auto &arg=inst.args[0];
196-
bool ret=to_unsigned_integer(to_constant_expr(arg), storeslotidx);
197-
CHECK_RETURN(!ret);
196+
auto v = numeric_cast<unsigned>(to_constant_expr(arg));
197+
CHECK_RETURN(v.has_value());
198+
storeslotidx = v.value();
198199
}
199200
else
200201
{

src/solvers/refinement/string_constraint_generator_format.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,12 @@ std::string
483483
utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
484484
{
485485
std::wstring out(length, '?');
486-
unsigned int c;
487486
for(std::size_t i=0; i<arr.operands().size() && i<length; i++)
488487
{
489488
PRECONDITION(arr.operands()[i].id()==ID_constant);
490-
bool conversion_failed=to_unsigned_integer(
491-
to_constant_expr(arr.operands()[i]), c);
492-
INVARIANT(!conversion_failed, "constant should be convertible to unsigned");
493-
out[i]=c;
489+
auto c = numeric_cast<unsigned>(to_constant_expr(arr.operands()[i]));
490+
INVARIANT(c.has_value(), "constant should be convertible to unsigned");
491+
out[i] = c.value();
494492
}
495493
return utf16_native_endian_to_java(out);
496494
}
@@ -520,12 +518,11 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
520518
const array_string_exprt res =
521519
char_array_of_pointer(array_pool, f.arguments()[1], f.arguments()[0]);
522520
const array_string_exprt s1 = get_string_expr(array_pool, f.arguments()[2]);
523-
unsigned int length;
524521

525-
if(s1.length().id()==ID_constant &&
526-
s1.content().id()==ID_array &&
527-
!to_unsigned_integer(to_constant_expr(s1.length()), length))
522+
if(s1.length().id() == ID_constant && s1.content().id() == ID_array)
528523
{
524+
const auto length =
525+
numeric_cast_v<std::size_t>(to_constant_expr(s1.length()));
529526
std::string s=utf16_constant_array_to_java(
530527
to_array_expr(s1.content()), length);
531528
// List of arguments after s

0 commit comments

Comments
 (0)