@@ -91,29 +91,29 @@ exprt c_typecheck_baset::do_initializer_rec(
91
91
to_array_type (full_type).is_complete ())
92
92
{
93
93
// check size
94
- mp_integer array_size;
95
- if (to_integer ( to_array_type (full_type). size (), array_size ))
94
+ const auto array_size = numeric_cast<mp_integer>( to_array_type (full_type). size ()) ;
95
+ if (!array_size. has_value ( ))
96
96
{
97
97
error ().source_location = value.source_location ();
98
98
error () << " array size needs to be constant, got "
99
99
<< to_string (to_array_type (full_type).size ()) << eom;
100
100
throw 0 ;
101
101
}
102
102
103
- if (array_size<0 )
103
+ if (* array_size<0 )
104
104
{
105
105
error ().source_location = value.source_location ();
106
106
error () << " array size must not be negative" << eom;
107
107
throw 0 ;
108
108
}
109
109
110
- if (mp_integer (tmp.operands ().size ())>array_size)
110
+ if (mp_integer (tmp.operands ().size ())>* array_size)
111
111
{
112
112
// cut off long strings. gcc does a warning for this
113
- tmp.operands ().resize (numeric_cast_v<std::size_t >(array_size));
113
+ tmp.operands ().resize (numeric_cast_v<std::size_t >(* array_size));
114
114
tmp.type ()=type;
115
115
}
116
- else if (mp_integer (tmp.operands ().size ())<array_size)
116
+ else if (mp_integer (tmp.operands ().size ())<* array_size)
117
117
{
118
118
// fill up
119
119
tmp.type ()=type;
@@ -126,7 +126,7 @@ exprt c_typecheck_baset::do_initializer_rec(
126
126
<< to_string (full_type.subtype ()) << " '" << eom;
127
127
throw 0 ;
128
128
}
129
- tmp.operands ().resize (numeric_cast_v<std::size_t >(array_size), *zero);
129
+ tmp.operands ().resize (numeric_cast_v<std::size_t >(* array_size), *zero);
130
130
}
131
131
}
132
132
@@ -152,29 +152,29 @@ exprt c_typecheck_baset::do_initializer_rec(
152
152
to_array_type (full_type).is_complete ())
153
153
{
154
154
// check size
155
- mp_integer array_size;
156
- if (to_integer ( to_array_type (full_type). size (), array_size ))
155
+ const auto array_size = numeric_cast<mp_integer>( to_array_type (full_type). size ()) ;
156
+ if (!array_size. has_value ( ))
157
157
{
158
158
error ().source_location = value.source_location ();
159
159
error () << " array size needs to be constant, got "
160
160
<< to_string (to_array_type (full_type).size ()) << eom;
161
161
throw 0 ;
162
162
}
163
163
164
- if (array_size<0 )
164
+ if (* array_size<0 )
165
165
{
166
166
error ().source_location = value.source_location ();
167
167
error () << " array size must not be negative" << eom;
168
168
throw 0 ;
169
169
}
170
170
171
- if (mp_integer (tmp2.operands ().size ())>array_size)
171
+ if (mp_integer (tmp2.operands ().size ())>* array_size)
172
172
{
173
173
// cut off long strings. gcc does a warning for this
174
- tmp2.operands ().resize (numeric_cast_v<std::size_t >(array_size));
174
+ tmp2.operands ().resize (numeric_cast_v<std::size_t >(* array_size));
175
175
tmp2.type ()=type;
176
176
}
177
- else if (mp_integer (tmp2.operands ().size ())<array_size)
177
+ else if (mp_integer (tmp2.operands ().size ())<* array_size)
178
178
{
179
179
// fill up
180
180
tmp2.type ()=type;
@@ -187,7 +187,7 @@ exprt c_typecheck_baset::do_initializer_rec(
187
187
<< to_string (full_type.subtype ()) << " '" << eom;
188
188
throw 0 ;
189
189
}
190
- tmp2.operands ().resize (numeric_cast_v<std::size_t >(array_size), *zero);
190
+ tmp2.operands ().resize (numeric_cast_v<std::size_t >(* array_size), *zero);
191
191
}
192
192
}
193
193
@@ -319,35 +319,34 @@ void c_typecheck_baset::designator_enter(
319
319
}
320
320
else
321
321
{
322
- mp_integer array_size;
323
-
324
- if (to_integer (array_type.size (), array_size))
322
+ const auto array_size = numeric_cast<mp_integer>(array_type.size ());
323
+ if (!array_size.has_value ())
325
324
{
326
325
error ().source_location = array_type.size ().source_location ();
327
326
error () << " array has non-constant size `"
328
327
<< to_string (array_type.size ()) << " '" << eom;
329
328
throw 0 ;
330
329
}
331
330
332
- entry.size = numeric_cast_v<std::size_t >(array_size);
331
+ entry.size = numeric_cast_v<std::size_t >(* array_size);
333
332
entry.subtype =array_type.subtype ();
334
333
}
335
334
}
336
335
else if (full_type.id ()==ID_vector)
337
336
{
338
337
const vector_typet &vector_type=to_vector_type (full_type);
339
338
340
- mp_integer vector_size;
339
+ const auto vector_size = numeric_cast<mp_integer>(vector_type. size ()) ;
341
340
342
- if (to_integer (vector_type. size (), vector_size ))
341
+ if (!vector_size. has_value ( ))
343
342
{
344
343
error ().source_location = vector_type.size ().source_location ();
345
344
error () << " vector has non-constant size `"
346
345
<< to_string (vector_type.size ()) << " '" << eom;
347
346
throw 0 ;
348
347
}
349
348
350
- entry.size = numeric_cast_v<std::size_t >(vector_size);
349
+ entry.size = numeric_cast_v<std::size_t >(* vector_size);
351
350
entry.subtype =vector_type.subtype ();
352
351
}
353
352
else
@@ -735,7 +734,9 @@ designatort c_typecheck_baset::make_designator(
735
734
736
735
if (to_array_type (full_type).size ().is_nil ())
737
736
size=0 ;
738
- else if (to_integer (to_array_type (full_type).size (), size))
737
+ else if (const auto size_opt = numeric_cast<mp_integer>(to_array_type (full_type).size ()))
738
+ size = *size_opt;
739
+ else
739
740
{
740
741
error ().source_location = d_op.op0 ().source_location ();
741
742
error () << " expected constant array size" << eom;
0 commit comments