@@ -10,6 +10,7 @@ Author: Daniel Kroening, kroening@kroening.com
1010#include < sstream>
1111
1212#include < util/arith_tools.h>
13+ #include < util/fresh_symbol.h>
1314#include < util/std_types.h>
1415#include < util/std_code.h>
1516#include < util/std_expr.h>
@@ -107,8 +108,7 @@ exprt java_object_factoryt::allocate_object(
107108 bool cast_needed=allocate_type_resolved!=target_type;
108109 if (!create_dynamic_objects)
109110 {
110- symbolt &aux_symbol=new_tmp_symbol (symbol_table);
111- aux_symbol.type =allocate_type;
111+ symbolt &aux_symbol=new_tmp_symbol (symbol_table, loc, allocate_type);
112112 aux_symbol.is_static_lifetime =true ;
113113
114114 exprt object=aux_symbol.symbol_expr ();
@@ -136,8 +136,11 @@ exprt java_object_factoryt::allocate_object(
136136 // Create a symbol for the malloc expression so we can initialize
137137 // without having to do it potentially through a double-deref, which
138138 // breaks the to-SSA phase.
139- symbolt &malloc_sym=new_tmp_symbol (symbol_table, " malloc_site" );
140- malloc_sym.type =pointer_typet (allocate_type);
139+ symbolt &malloc_sym=new_tmp_symbol (
140+ symbol_table,
141+ loc,
142+ pointer_typet (allocate_type),
143+ " malloc_site" );
141144 code_assignt assign=code_assignt (malloc_sym.symbol_expr (), malloc_expr);
142145 code_assignt &malloc_assign=assign;
143146 malloc_assign.add_source_location ()=loc;
@@ -211,8 +214,11 @@ void java_object_factoryt::gen_nondet_init(
211214 if (!assume_non_null)
212215 {
213216 auto returns_null_sym=
214- new_tmp_symbol (symbol_table, " opaque_returns_null" );
215- returns_null_sym.type =c_bool_typet (1 );
217+ new_tmp_symbol (
218+ symbol_table,
219+ loc,
220+ c_bool_typet (1 ),
221+ " opaque_returns_null" );
216222 auto returns_null=returns_null_sym.symbol_expr ();
217223 auto assign_returns_null=
218224 code_assignt (returns_null, get_nondet_bool (returns_null_sym.type ));
@@ -365,8 +371,11 @@ void java_object_factoryt::gen_nondet_array_init(
365371 auto max_length_expr=from_integer (max_nondet_array_length, java_int_type ());
366372
367373 typet allocate_type;
368- symbolt &length_sym=new_tmp_symbol (symbol_table, " nondet_array_length" );
369- length_sym.type =java_int_type ();
374+ symbolt &length_sym=new_tmp_symbol (
375+ symbol_table,
376+ loc,
377+ java_int_type (),
378+ " nondet_array_length" );
370379 const auto &length_sym_expr=length_sym.symbol_expr ();
371380
372381 // Initialize array with some undetermined length:
@@ -400,17 +409,23 @@ void java_object_factoryt::gen_nondet_array_init(
400409
401410 // Interpose a new symbol, as the goto-symex stage can't handle array indexing
402411 // via a cast.
403- symbolt &array_init_symbol=new_tmp_symbol (symbol_table, " array_data_init" );
404- array_init_symbol.type =init_array_expr.type ();
412+ symbolt &array_init_symbol=new_tmp_symbol (
413+ symbol_table,
414+ loc,
415+ init_array_expr.type (),
416+ " array_data_init" );
405417 const auto &array_init_symexpr=array_init_symbol.symbol_expr ();
406418 codet data_assign=code_assignt (array_init_symexpr, init_array_expr);
407419 data_assign.add_source_location ()=loc;
408420 init_code.copy_to_operands (data_assign);
409421
410422 // Emit init loop for(array_init_iter=0; array_init_iter!=array.length;
411423 // ++array_init_iter) init(array[array_init_iter]);
412- symbolt &counter=new_tmp_symbol (symbol_table, " array_init_iter" );
413- counter.type =length_sym_expr.type ();
424+ symbolt &counter=new_tmp_symbol (
425+ symbol_table,
426+ loc,
427+ length_sym_expr.type (),
428+ " array_init_iter" );
414429 exprt counter_expr=counter.symbol_expr ();
415430
416431 exprt java_zero=from_integer (0 , java_int_type ());
@@ -512,22 +527,19 @@ Function: new_tmp_symbol
512527
513528\*******************************************************************/
514529
515- symbolt &new_tmp_symbol (symbol_tablet &symbol_table, const std::string &prefix)
530+ symbolt &new_tmp_symbol (
531+ symbol_tablet &symbol_table,
532+ const source_locationt &loc,
533+ const typet &type,
534+ const std::string &prefix)
516535{
517- static size_t temporary_counter=0 ; // TODO encapsulate as class variable
518-
519- auxiliary_symbolt new_symbol;
520- symbolt *symbol_ptr;
521-
522- do
523- {
524- new_symbol.name =" tmp_object_factory$" +std::to_string (++temporary_counter);
525- new_symbol.base_name =new_symbol.name ;
526- new_symbol.mode =ID_java;
527- }
528- while (symbol_table.move (new_symbol, symbol_ptr));
529-
530- return *symbol_ptr;
536+ return get_fresh_aux_symbol (
537+ type,
538+ " " ,
539+ prefix,
540+ loc,
541+ ID_java,
542+ symbol_table);
531543}
532544
533545/* ******************************************************************\
@@ -572,8 +584,10 @@ exprt object_factory(
572584{
573585 if (type.id ()==ID_pointer)
574586 {
575- symbolt &aux_symbol=new_tmp_symbol (symbol_table);
576- aux_symbol.type =type;
587+ symbolt &aux_symbol=new_tmp_symbol (
588+ symbol_table,
589+ loc,
590+ type);
577591 aux_symbol.is_static_lifetime =true ;
578592
579593 exprt object=aux_symbol.symbol_expr ();
0 commit comments