@@ -258,7 +258,8 @@ get_component_in_struct(const struct_exprt &expr, irep_idt component_name)
258
258
// / specifier.
259
259
// / \param fresh_symbol: generator of fresh symbols
260
260
// / \param fs: a format specifier
261
- // / \param arg: a struct containing the possible value of the argument to format
261
+ // / \param get_arg: a function returning the possible value of the argument to
262
+ // / format given their type.
262
263
// / \param index_type: type for indexes in strings
263
264
// / \param char_type: type of characters
264
265
// / \param array_pool: pool of arrays representing strings
@@ -267,61 +268,42 @@ get_component_in_struct(const struct_exprt &expr, irep_idt component_name)
267
268
// / \return String expression representing the output of String.format.
268
269
static std::pair<array_string_exprt, string_constraintst>
269
270
add_axioms_for_format_specifier (
270
- symbol_generatort &fresh_symbol,
271
- const format_specifiert &fs,
272
- const struct_exprt &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
- {
271
+ symbol_generatort &fresh_symbol, const format_specifiert &fs,
272
+ const std::function<exprt(const irep_idt &)> &get_arg,
273
+ const typet &index_type, const typet &char_type, array_poolt &array_pool,
274
+ const messaget &message, const namespacet &ns) {
279
275
string_constraintst constraints;
280
276
const array_string_exprt res = array_pool.fresh_string (index_type, char_type);
281
277
std::pair<exprt, string_constraintst> return_code;
282
278
switch (fs.conversion )
283
279
{
284
280
case format_specifiert::DECIMAL_INTEGER:
285
- return_code = add_axioms_for_string_of_int (
286
- res, get_component_in_struct (arg, ID_int), 0 , ns);
281
+ return_code = add_axioms_for_string_of_int (res, get_arg (ID_int), 0 , ns);
287
282
return {res, std::move (return_code.second )};
288
283
case format_specifiert::HEXADECIMAL_INTEGER:
289
- return_code =
290
- add_axioms_from_int_hex (res, get_component_in_struct (arg, ID_int));
284
+ return_code = add_axioms_from_int_hex (res, get_arg (ID_int));
291
285
return {res, std::move (return_code.second )};
292
286
case format_specifiert::SCIENTIFIC:
293
287
return_code = add_axioms_from_float_scientific_notation (
294
- fresh_symbol,
295
- res,
296
- get_component_in_struct (arg, ID_float),
297
- array_pool,
298
- ns);
288
+ fresh_symbol, res, get_arg (ID_float), array_pool, ns);
299
289
return {res, std::move (return_code.second )};
300
290
case format_specifiert::DECIMAL_FLOAT:
301
291
return_code = add_axioms_for_string_of_float (
302
- fresh_symbol,
303
- res,
304
- get_component_in_struct (arg, ID_float),
305
- array_pool,
306
- ns);
292
+ fresh_symbol, res, get_arg (ID_float), array_pool, ns);
307
293
return {res, std::move (return_code.second )};
308
294
case format_specifiert::CHARACTER:
309
- return_code =
310
- add_axioms_from_char (res, get_component_in_struct (arg, ID_char));
295
+ return_code = add_axioms_from_char (res, get_arg (ID_char));
311
296
return {res, std::move (return_code.second )};
312
297
case format_specifiert::BOOLEAN:
313
- return_code =
314
- add_axioms_from_bool (res, get_component_in_struct (arg, ID_boolean));
298
+ return_code = add_axioms_from_bool (res, get_arg (ID_boolean));
315
299
return {res, std::move (return_code.second )};
316
300
case format_specifiert::STRING:
317
301
{
318
- auto string_expr =
319
- get_string_expr (array_pool, get_component_in_struct (arg, " string_expr" ));
302
+ auto string_expr = get_string_expr (array_pool, get_arg (" string_expr" ));
320
303
return {std::move (string_expr), {}};
321
304
}
322
305
case format_specifiert::HASHCODE:
323
- return_code = add_axioms_for_string_of_int (
324
- res, get_component_in_struct (arg, " hashcode" ), 0 , ns);
306
+ return_code = add_axioms_for_string_of_int (res, get_arg (" hashcode" ), 0 , ns);
325
307
return {res, std::move (return_code.second )};
326
308
case format_specifiert::LINE_SEPARATOR:
327
309
// TODO: the constant should depend on the system: System.lineSeparator()
@@ -342,14 +324,8 @@ add_axioms_for_format_specifier(
342
324
format_specifiert fs_lower = fs;
343
325
fs_lower.conversion = tolower (fs.conversion );
344
326
auto format_specifier_result = add_axioms_for_format_specifier (
345
- fresh_symbol,
346
- fs_lower,
347
- arg,
348
- index_type,
349
- char_type,
350
- array_pool,
351
- message,
352
- ns);
327
+ fresh_symbol, fs_lower, get_arg, index_type, char_type, array_pool,
328
+ message, ns);
353
329
354
330
const exprt return_code_upper_case =
355
331
fresh_symbol (" return_code_upper_case" , get_return_code_type ());
@@ -434,14 +410,11 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
434
410
}
435
411
436
412
auto result = add_axioms_for_format_specifier (
437
- fresh_symbol,
438
- fs,
439
- to_struct_expr (arg),
440
- index_type,
441
- char_type,
442
- array_pool,
443
- message,
444
- ns);
413
+ fresh_symbol, fs,
414
+ [&](const irep_idt &id) {
415
+ return get_component_in_struct (to_struct_expr (arg), id);
416
+ },
417
+ index_type, char_type, array_pool, message, ns);
445
418
merge (constraints, std::move (result.second ));
446
419
intermediary_strings.push_back (result.first );
447
420
}
0 commit comments