Skip to content

Commit aa3f1fd

Browse files
author
Daniel Kroening
committed
replace instances of to_unsigned_integer by numeric_cast
1 parent 1f487eb commit aa3f1fd

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
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
@@ -1069,12 +1069,12 @@ codet java_bytecode_convert_methodt::convert_instructions(
10691069
{
10701070
PRECONDITION(!i_it->args.empty());
10711071

1072-
unsigned target;
1073-
bool ret=to_unsigned_integer(to_constant_expr(i_it->args[0]), target);
1074-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1075-
targets.insert(target);
1072+
auto target = numeric_cast<unsigned>(to_constant_expr(i_it->args[0]));
1073+
DATA_INVARIANT(
1074+
target.has_value(), "target expected to be unsigned integer");
1075+
targets.insert(target.value());
10761076

1077-
a_entry.first->second.successors.push_back(target);
1077+
a_entry.first->second.successors.push_back(target.value());
10781078

10791079
if(i_it->statement=="jsr" ||
10801080
i_it->statement=="jsr_w")
@@ -1094,11 +1094,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
10941094
{
10951095
if(is_label)
10961096
{
1097-
unsigned target;
1098-
bool ret=to_unsigned_integer(to_constant_expr(arg), target);
1099-
DATA_INVARIANT(!ret, "target expected to be unsigned integer");
1100-
targets.insert(target);
1101-
a_entry.first->second.successors.push_back(target);
1097+
auto target = numeric_cast<unsigned>(to_constant_expr(arg));
1098+
DATA_INVARIANT(
1099+
target.has_value(), "target expected to be unsigned integer");
1100+
targets.insert(target.value());
1101+
a_entry.first->second.successors.push_back(target.value());
11021102
}
11031103
is_label=!is_label;
11041104
}

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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,18 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
482482
std::string
483483
utf16_constant_array_to_java(const array_exprt &arr, std::size_t length)
484484
{
485+
for(const auto &op : arr.operands())
486+
PRECONDITION(op.id() == ID_constant);
487+
485488
std::wstring out(length, '?');
486-
unsigned int c;
489+
487490
for(std::size_t i=0; i<arr.operands().size() && i<length; i++)
488491
{
489-
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;
492+
auto c = numeric_cast<unsigned>(to_constant_expr(arr.operands()[i]));
493+
INVARIANT(c.has_value(), "constant should be convertible to unsigned");
494+
out[i] = c.value();
494495
}
496+
495497
return utf16_native_endian_to_java(out);
496498
}
497499

@@ -520,12 +522,11 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
520522
const array_string_exprt res =
521523
char_array_of_pointer(array_pool, f.arguments()[1], f.arguments()[0]);
522524
const array_string_exprt s1 = get_string_expr(array_pool, f.arguments()[2]);
523-
unsigned int length;
524525

525-
if(s1.length().id()==ID_constant &&
526-
s1.content().id()==ID_array &&
527-
!to_unsigned_integer(to_constant_expr(s1.length()), length))
526+
if(s1.length().id() == ID_constant && s1.content().id() == ID_array)
528527
{
528+
const auto length =
529+
numeric_cast_v<std::size_t>(to_constant_expr(s1.length()));
529530
std::string s=utf16_constant_array_to_java(
530531
to_array_expr(s1.content()), length);
531532
// List of arguments after s

0 commit comments

Comments
 (0)