@@ -257,60 +257,57 @@ static exprt get_component_in_struct(const struct_exprt &expr,
257
257
// / specifier.
258
258
// / \param fresh_symbol: generator of fresh symbols
259
259
// / \param fs: a format specifier
260
- // / \param arg: a struct containing the possible value of the argument to format
260
+ // / \param get_arg: a function returning the possible value of the argument to
261
+ // / format given their type.
261
262
// / \param index_type: type for indexes in strings
262
263
// / \param char_type: type of characters
263
264
// / \param array_pool: pool of arrays representing strings
264
265
// / \param message: message handler for warnings
265
266
// / \param ns: namespace
266
267
// / \return String expression representing the output of String.format.
267
268
static std::pair<array_string_exprt, string_constraintst>
268
- add_axioms_for_format_specifier (symbol_generatort &fresh_symbol,
269
- const format_specifiert &fs,
270
- const struct_exprt &arg,
271
- const typet &index_type, const typet &char_type,
272
- array_poolt &array_pool,
273
- const messaget &message, const namespacet &ns) {
269
+ add_axioms_for_format_specifier (
270
+ symbol_generatort &fresh_symbol,
271
+ const format_specifiert &fs,
272
+ const std::function<exprt(const irep_idt &)> &get_arg,
273
+ const typet &index_type,
274
+ const typet &char_type,
275
+ array_poolt &array_pool,
276
+ const messaget &message,
277
+ const namespacet &ns)
278
+ {
274
279
string_constraintst constraints;
275
280
const array_string_exprt res = array_pool.fresh_string (index_type, char_type);
276
281
std::pair<exprt, string_constraintst> return_code;
277
282
switch (fs.conversion )
278
283
{
279
284
case format_specifiert::DECIMAL_INTEGER:
280
- return_code = add_axioms_for_string_of_int (
281
- res, get_component_in_struct (arg, ID_int), 0 , ns);
285
+ return_code = add_axioms_for_string_of_int (res, get_arg (ID_int), 0 , ns);
282
286
return {res, std::move (return_code.second )};
283
287
case format_specifiert::HEXADECIMAL_INTEGER:
284
- return_code =
285
- add_axioms_from_int_hex (res, get_component_in_struct (arg, ID_int));
288
+ return_code = add_axioms_from_int_hex (res, get_arg (ID_int));
286
289
return {res, std::move (return_code.second )};
287
290
case format_specifiert::SCIENTIFIC:
288
291
return_code = add_axioms_from_float_scientific_notation (
289
- fresh_symbol, res, get_component_in_struct (arg, ID_float), array_pool,
290
- ns);
292
+ fresh_symbol, res, get_arg (ID_float), array_pool, ns);
291
293
return {res, std::move (return_code.second )};
292
294
case format_specifiert::DECIMAL_FLOAT:
293
295
return_code = add_axioms_for_string_of_float (
294
- fresh_symbol, res, get_component_in_struct (arg, ID_float), array_pool,
295
- ns);
296
+ fresh_symbol, res, get_arg (ID_float), array_pool, ns);
296
297
return {res, std::move (return_code.second )};
297
298
case format_specifiert::CHARACTER:
298
- return_code =
299
- add_axioms_from_char (res, get_component_in_struct (arg, ID_char));
299
+ return_code = add_axioms_from_char (res, get_arg (ID_char));
300
300
return {res, std::move (return_code.second )};
301
301
case format_specifiert::BOOLEAN:
302
- return_code =
303
- add_axioms_from_bool (res, get_component_in_struct (arg, ID_boolean));
302
+ return_code = add_axioms_from_bool (res, get_arg (ID_boolean));
304
303
return {res, std::move (return_code.second )};
305
304
case format_specifiert::STRING:
306
305
{
307
- auto string_expr = get_string_expr (
308
- array_pool, get_component_in_struct (arg, " string_expr" ));
306
+ auto string_expr = get_string_expr (array_pool, get_arg (" string_expr" ));
309
307
return {std::move (string_expr), {}};
310
308
}
311
309
case format_specifiert::HASHCODE:
312
- return_code = add_axioms_for_string_of_int (
313
- res, get_component_in_struct (arg, " hashcode" ), 0 , ns);
310
+ return_code = add_axioms_for_string_of_int (res, get_arg (" hashcode" ), 0 , ns);
314
311
return {res, std::move (return_code.second )};
315
312
case format_specifiert::LINE_SEPARATOR:
316
313
// TODO: the constant should depend on the system: System.lineSeparator()
@@ -330,9 +327,15 @@ add_axioms_for_format_specifier(symbol_generatort &fresh_symbol,
330
327
{
331
328
format_specifiert fs_lower = fs;
332
329
fs_lower.conversion = tolower (fs.conversion );
333
- auto format_specifier_result =
334
- add_axioms_for_format_specifier (fresh_symbol, fs_lower, arg, index_type,
335
- char_type, array_pool, message, ns);
330
+ auto format_specifier_result = add_axioms_for_format_specifier (
331
+ fresh_symbol,
332
+ fs_lower,
333
+ get_arg,
334
+ index_type,
335
+ char_type,
336
+ array_pool,
337
+ message,
338
+ ns);
336
339
337
340
const exprt return_code_upper_case =
338
341
fresh_symbol (" return_code_upper_case" , get_return_code_type ());
@@ -417,8 +420,16 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
417
420
}
418
421
419
422
auto result = add_axioms_for_format_specifier (
420
- fresh_symbol, fs, to_struct_expr (arg), index_type, char_type,
421
- array_pool, message, ns);
423
+ fresh_symbol,
424
+ fs,
425
+ [&](const irep_idt &id) {
426
+ return get_component_in_struct (to_struct_expr (arg), id);
427
+ },
428
+ index_type,
429
+ char_type,
430
+ array_pool,
431
+ message,
432
+ ns);
422
433
merge (constraints, std::move (result.second ));
423
434
intermediary_strings.push_back (result.first );
424
435
}
0 commit comments