@@ -186,6 +186,11 @@ static bool check_format_string(std::string s)
186
186
}
187
187
#endif
188
188
189
+ static exprt format_arg_from_string (
190
+ const array_string_exprt &string,
191
+ const irep_idt &id,
192
+ array_poolt &array_pool);
193
+
189
194
// / Helper function for parsing format strings.
190
195
// / This follows the implementation in openJDK of the java.util.Formatter class:
191
196
// / http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/classes/java/util/Formatter.java#l2660
@@ -260,8 +265,7 @@ static exprt is_null(const array_string_exprt &string, array_poolt &array_pool)
260
265
// / on the format specifier.
261
266
// / \param fresh_symbol: generator of fresh symbols
262
267
// / \param fs: a format specifier
263
- // / \param get_arg: a function returning the possible value of the argument to
264
- // / format given their type.
268
+ // / \param string_arg: format string from argument
265
269
// / \param index_type: type for indexes in strings
266
270
// / \param char_type: type of characters
267
271
// / \param array_pool: pool of arrays representing strings
@@ -272,7 +276,7 @@ static std::pair<array_string_exprt, string_constraintst>
272
276
add_axioms_for_format_specifier (
273
277
symbol_generatort &fresh_symbol,
274
278
const format_specifiert &fs,
275
- const std::function<exprt( const irep_idt &)> &get_arg ,
279
+ const array_string_exprt &string_arg ,
276
280
const typet &index_type,
277
281
const typet &char_type,
278
282
array_poolt &array_pool,
@@ -285,24 +289,41 @@ add_axioms_for_format_specifier(
285
289
switch (fs.conversion )
286
290
{
287
291
case format_specifiert::DECIMAL_INTEGER:
288
- return_code =
289
- add_axioms_for_string_of_int (res, get_arg (ID_int), 0 , ns, array_pool);
292
+ return_code = add_axioms_for_string_of_int (
293
+ res,
294
+ format_arg_from_string (string_arg, ID_int, array_pool),
295
+ 0 ,
296
+ ns,
297
+ array_pool);
290
298
return {res, std::move (return_code.second )};
291
299
case format_specifiert::HEXADECIMAL_INTEGER:
292
300
return_code = add_axioms_for_string_of_int_with_radix (
293
- res, get_arg (ID_int), from_integer (16 , index_type), 16 , ns, array_pool);
301
+ res,
302
+ format_arg_from_string (string_arg, ID_int, array_pool),
303
+ from_integer (16 , index_type),
304
+ 16 ,
305
+ ns,
306
+ array_pool);
294
307
return {res, std::move (return_code.second )};
295
308
case format_specifiert::SCIENTIFIC:
296
309
return_code = add_axioms_from_float_scientific_notation (
297
- fresh_symbol, res, get_arg (ID_float), array_pool, ns);
310
+ fresh_symbol,
311
+ res,
312
+ format_arg_from_string (string_arg, ID_float, array_pool),
313
+ array_pool,
314
+ ns);
298
315
return {res, std::move (return_code.second )};
299
316
case format_specifiert::DECIMAL_FLOAT:
300
317
return_code = add_axioms_for_string_of_float (
301
- fresh_symbol, res, get_arg (ID_float), array_pool, ns);
318
+ fresh_symbol,
319
+ res,
320
+ format_arg_from_string (string_arg, ID_float, array_pool),
321
+ array_pool,
322
+ ns);
302
323
return {res, std::move (return_code.second )};
303
324
case format_specifiert::CHARACTER:
304
325
{
305
- exprt arg_string = get_arg ( ID_char);
326
+ exprt arg_string = format_arg_from_string (string_arg, ID_char, array_pool );
306
327
array_string_exprt &string_expr = to_array_string_expr (arg_string);
307
328
// In the case the arg is null, the result will be equal to "null" and
308
329
// and otherwise we just take the 4th character of the string.
@@ -325,17 +346,24 @@ add_axioms_for_format_specifier(
325
346
return {res, constraints};
326
347
}
327
348
case format_specifiert::BOOLEAN:
328
- return_code = add_axioms_from_bool (res, get_arg (ID_boolean), array_pool);
349
+ return_code = add_axioms_from_bool (
350
+ res,
351
+ format_arg_from_string (string_arg, ID_boolean, array_pool),
352
+ array_pool);
329
353
return {res, std::move (return_code.second )};
330
354
case format_specifiert::STRING:
331
355
{
332
- const exprt arg_string = get_arg ( " string_expr " ) ;
356
+ const exprt arg_string = string_arg ;
333
357
const array_string_exprt string_expr = to_array_string_expr (arg_string);
334
358
return {std::move (string_expr), {}};
335
359
}
336
360
case format_specifiert::HASHCODE:
337
- return_code =
338
- add_axioms_for_string_of_int (res, get_arg (" hashcode" ), 0 , ns, array_pool);
361
+ return_code = add_axioms_for_string_of_int (
362
+ res,
363
+ format_arg_from_string (string_arg, " hashcode" , array_pool),
364
+ 0 ,
365
+ ns,
366
+ array_pool);
339
367
return {res, std::move (return_code.second )};
340
368
case format_specifiert::LINE_SEPARATOR:
341
369
// TODO: the constant should depend on the system: System.lineSeparator()
@@ -358,7 +386,7 @@ add_axioms_for_format_specifier(
358
386
auto format_specifier_result = add_axioms_for_format_specifier (
359
387
fresh_symbol,
360
388
fs_lower,
361
- get_arg ,
389
+ string_arg ,
362
390
index_type,
363
391
char_type,
364
392
array_pool,
@@ -463,13 +491,13 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
463
491
const typet &char_type = res.content ().type ().subtype ();
464
492
const typet &index_type = res.length_type ();
465
493
494
+ array_string_exprt string_arg;
495
+
466
496
for (const format_elementt &fe : format_strings)
467
497
{
468
498
if (fe.is_format_specifier ())
469
499
{
470
500
const format_specifiert &fs = fe.get_format_specifier ();
471
- std::function<exprt (const irep_idt &)> get_arg =
472
- [](const irep_idt &) -> exprt { UNREACHABLE; };
473
501
474
502
if (
475
503
fs.conversion != format_specifiert::PERCENT_SIGN &&
@@ -497,17 +525,13 @@ std::pair<exprt, string_constraintst> add_axioms_for_format(
497
525
INVARIANT (
498
526
is_refined_string_type (arg.type ()),
499
527
" arguments of format should be strings" );
500
- const array_string_exprt string_arg = get_string_expr (array_pool, arg);
501
- // / REMOVE get_arg below
502
- get_arg = [&](const irep_idt &id) {
503
- return format_arg_from_string (string_arg, id, array_pool);
504
- };
528
+ string_arg = get_string_expr (array_pool, arg);
505
529
}
506
530
507
531
auto result = add_axioms_for_format_specifier (
508
532
fresh_symbol,
509
533
fs,
510
- get_arg ,
534
+ string_arg ,
511
535
index_type,
512
536
char_type,
513
537
array_pool,
0 commit comments