Skip to content

Commit 9777d23

Browse files
committed
Use numeric_cast<mp_integer> instead of deprecated to_integer(exprt)
1 parent 2772205 commit 9777d23

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

src/util/endianness_map.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,27 @@ void endianness_mapt::build_big_endian(const typet &src)
9292
const array_typet &array_type=to_array_type(src);
9393

9494
// array size constant?
95-
mp_integer s;
96-
if(!to_integer(array_type.size(), s))
95+
auto s = numeric_cast<mp_integer>(array_type.size());
96+
if(s.has_value())
9797
{
98-
while(s>0)
98+
while(*s > 0)
9999
{
100100
build_big_endian(array_type.subtype());
101-
--s;
101+
--*s;
102102
}
103103
}
104104
}
105105
else if(src.id()==ID_vector)
106106
{
107107
const vector_typet &vector_type=to_vector_type(src);
108108

109-
mp_integer s;
110-
if(to_integer(vector_type.size(), s))
111-
CHECK_RETURN(false);
109+
auto s = numeric_cast<mp_integer>(vector_type.size());
110+
CHECK_RETURN(s.has_value());
112111

113-
while(s>0)
112+
while(*s > 0)
114113
{
115114
build_big_endian(vector_type.subtype());
116-
--s;
115+
--*s;
117116
}
118117
}
119118
else

src/util/expr_initializer.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
144144
exprt tmpval =
145145
expr_initializer_rec(array_type.subtype(), source_location);
146146

147-
mp_integer array_size;
148-
149147
if(array_type.size().id()==ID_infinity)
150148
{
151149
if(nondet)
@@ -159,7 +157,10 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
159157
value.add_source_location()=source_location;
160158
return value;
161159
}
162-
else if(to_integer(array_type.size(), array_size))
160+
161+
auto array_size = numeric_cast<mp_integer>(array_type.size());
162+
163+
if(!array_size.has_value())
163164
{
164165
if(nondet)
165166
{
@@ -175,10 +176,10 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
175176
}
176177

177178
DATA_INVARIANT(
178-
array_size >= 0, "array should not have negative size");
179+
*array_size >= 0, "array should not have negative size");
179180

180181
array_exprt value(array_type);
181-
value.operands().resize(integer2size_t(array_size), tmpval);
182+
value.operands().resize(numeric_cast_v<std::size_t>(*array_size), tmpval);
182183
value.add_source_location()=source_location;
183184
return value;
184185
}
@@ -189,9 +190,9 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
189190

190191
exprt tmpval = expr_initializer_rec(vector_type.subtype(), source_location);
191192

192-
mp_integer vector_size;
193+
auto vector_size = numeric_cast<mp_integer>(vector_type.size());
193194

194-
if(to_integer(vector_type.size(), vector_size))
195+
if(!vector_size.has_value())
195196
{
196197
if(nondet)
197198
{
@@ -207,10 +208,10 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
207208
}
208209

209210
DATA_INVARIANT(
210-
vector_size >= 0, "vector should not have negative size");
211+
*vector_size >= 0, "vector should not have negative size");
211212

212213
vector_exprt value(vector_type);
213-
value.operands().resize(integer2size_t(vector_size), tmpval);
214+
value.operands().resize(numeric_cast_v<std::size_t>(*vector_size), tmpval);
214215
value.add_source_location()=source_location;
215216

216217
return value;

src/util/pointer_offset_size.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,13 @@ mp_integer pointer_offset_bits(
122122
return -1;
123123

124124
// get size
125-
const exprt &size=to_array_type(type).size();
125+
const auto size = numeric_cast<mp_integer>(to_array_type(type).size());
126126

127127
// constant?
128-
mp_integer i;
129-
130-
if(to_integer(size, i))
128+
if(!size.has_value())
131129
return -1; // we cannot distinguish the elements
132130

133-
return sub*i;
131+
return sub * *size;
134132
}
135133
else if(type.id()==ID_vector)
136134
{
@@ -139,15 +137,13 @@ mp_integer pointer_offset_bits(
139137
return -1;
140138

141139
// get size
142-
const exprt &size=to_vector_type(type).size();
140+
const auto size = numeric_cast<mp_integer>(to_vector_type(type).size());
143141

144142
// constant?
145-
mp_integer i;
146-
147-
if(to_integer(size, i))
143+
if(!size.has_value())
148144
return -1; // we cannot distinguish the elements
149145

150-
return sub*i;
146+
return sub * *size;
151147
}
152148
else if(type.id()==ID_complex)
153149
{

0 commit comments

Comments
 (0)