@@ -428,6 +428,25 @@ std::string recursive_initialization_configt::to_string() const
428
428
429
429
recursive_initializationt::array_convertert
430
430
recursive_initializationt::default_array_member_initialization ()
431
+ irep_idt recursive_initializationt::get_fresh_global_name(
432
+ const std::string &symbol_name,
433
+ const exprt &initial_value) const
434
+ {
435
+ symbolt &fresh_symbol = get_fresh_aux_symbol (
436
+ signed_int_type (),
437
+ CPROVER_PREFIX,
438
+ symbol_name,
439
+ source_locationt{},
440
+ initialization_config.mode ,
441
+ goto_model.symbol_table );
442
+ fresh_symbol.is_static_lifetime = true ;
443
+ fresh_symbol.is_lvalue = true ;
444
+ fresh_symbol.value = initial_value;
445
+ return fresh_symbol.name ;
446
+ }
447
+
448
+ symbol_exprt recursive_initializationt::get_fresh_global_symexpr (
449
+ const std::string &symbol_name) const
431
450
{
432
451
return [this ](
433
452
const exprt &array,
@@ -437,6 +456,140 @@ recursive_initializationt::default_array_member_initialization()
437
456
const recursion_sett &known_tags,
438
457
code_blockt &body) {
439
458
PRECONDITION (array.type ().id () == ID_array);
459
+ symbolt &fresh_symbol = get_fresh_aux_symbol (
460
+ signed_int_type (),
461
+ CPROVER_PREFIX,
462
+ symbol_name,
463
+ source_locationt{},
464
+ initialization_config.mode ,
465
+ goto_model.symbol_table );
466
+ fresh_symbol.is_static_lifetime = true ;
467
+ fresh_symbol.is_lvalue = true ;
468
+ fresh_symbol.value = from_integer (0 , signed_int_type ());
469
+ return fresh_symbol.symbol_expr ();
470
+ }
471
+
472
+ symbol_exprt recursive_initializationt::get_fresh_local_symexpr (
473
+ const std::string &symbol_name) const
474
+ {
475
+ symbolt &fresh_symbol = get_fresh_aux_symbol (
476
+ signed_int_type (),
477
+ CPROVER_PREFIX,
478
+ symbol_name,
479
+ source_locationt{},
480
+ initialization_config.mode ,
481
+ goto_model.symbol_table );
482
+ fresh_symbol.is_lvalue = true ;
483
+ fresh_symbol.value = from_integer (0 , signed_int_type ());
484
+ return fresh_symbol.symbol_expr ();
485
+ }
486
+
487
+ symbol_exprt recursive_initializationt::get_fresh_local_typed_symexpr (
488
+ const std::string &symbol_name,
489
+ const typet &type,
490
+ const exprt &init_value) const
491
+ {
492
+ symbolt &fresh_symbol = get_fresh_aux_symbol (
493
+ type,
494
+ CPROVER_PREFIX,
495
+ symbol_name,
496
+ source_locationt{},
497
+ initialization_config.mode ,
498
+ goto_model.symbol_table );
499
+ fresh_symbol.is_lvalue = true ;
500
+ fresh_symbol.value = init_value;
501
+ return fresh_symbol.symbol_expr ();
502
+ }
503
+
504
+ const symbolt &recursive_initializationt::get_fresh_fun_symbol (
505
+ const std::string &fun_name,
506
+ const typet &fun_type)
507
+ {
508
+ irep_idt fresh_name (fun_name);
509
+
510
+ get_new_name (fresh_name, namespacet{goto_model.symbol_table }, ' _' );
511
+
512
+ // create the function symbol
513
+ symbolt function_symbol{};
514
+ function_symbol.name = function_symbol.base_name =
515
+ function_symbol.pretty_name = fresh_name;
516
+
517
+ function_symbol.is_lvalue = true ;
518
+ function_symbol.mode = initialization_config.mode ;
519
+ function_symbol.type = fun_type;
520
+
521
+ auto r = goto_model.symbol_table .insert (function_symbol);
522
+ CHECK_RETURN (r.second );
523
+ return *goto_model.symbol_table .lookup (fresh_name);
524
+ }
525
+
526
+ symbolt &recursive_initializationt::get_fresh_param_symbol (
527
+ const std::string &symbol_name,
528
+ const typet &symbol_type)
529
+ {
530
+ symbolt ¶m_symbol = get_fresh_aux_symbol (
531
+ symbol_type,
532
+ CPROVER_PREFIX,
533
+ symbol_name,
534
+ source_locationt{},
535
+ initialization_config.mode ,
536
+ goto_model.symbol_table );
537
+ param_symbol.is_parameter = true ;
538
+ param_symbol.is_lvalue = true ;
539
+
540
+ return param_symbol;
541
+ }
542
+
543
+ symbol_exprt
544
+ recursive_initializationt::get_symbol_expr (const irep_idt &symbol_name) const
545
+ {
546
+ auto maybe_symbol = goto_model.symbol_table .lookup (symbol_name);
547
+ CHECK_RETURN (maybe_symbol != nullptr );
548
+ return maybe_symbol->symbol_expr ();
549
+ }
550
+
551
+ std::string recursive_initializationt::type2id (const typet &type) const
552
+ {
553
+ if (type.id () == ID_struct_tag)
554
+ {
555
+ auto st_tag = id2string (to_struct_tag_type (type).get_identifier ());
556
+ std::replace (st_tag.begin (), st_tag.end (), ' -' , ' _' );
557
+ return st_tag;
558
+ }
559
+ else if (type.id () == ID_pointer)
560
+ return " ptr_" + type2id (type.subtype ());
561
+ else if (type.id () == ID_array)
562
+ {
563
+ const auto array_size =
564
+ numeric_cast_v<std::size_t >(to_constant_expr (to_array_type (type).size ()));
565
+ return " arr_" + type2id (type.subtype ()) + " _" + std::to_string (array_size);
566
+ }
567
+ else if (type == char_type ())
568
+ return " char" ;
569
+ else if (type.id () == ID_signedbv)
570
+ return " int" ;
571
+ else if (type.id () == ID_unsignedbv)
572
+ return " uint" ;
573
+ else
574
+ return " " ;
575
+ }
576
+
577
+ symbol_exprt recursive_initializationt::get_free_function ()
578
+ {
579
+ auto free_sym = goto_model.symbol_table .lookup (" free" );
580
+ if (free_sym == nullptr )
581
+ {
582
+ symbolt new_free_sym;
583
+ new_free_sym.type = code_typet{code_typet{
584
+ {code_typet::parametert{pointer_type (empty_typet{})}}, empty_typet{}}};
585
+ new_free_sym.name = new_free_sym.pretty_name = new_free_sym.base_name =
586
+ " free" ;
587
+ new_free_sym.mode = initialization_config.mode ;
588
+ goto_model.symbol_table .insert (new_free_sym);
589
+ return new_free_sym.symbol_expr ();
590
+ }
591
+ return free_sym->symbol_expr ();
592
+ }
440
593
initialize (
441
594
index_exprt{array, from_integer (current_index, size_type ())},
442
595
depth,
0 commit comments