|
10 | 10 | #include <sstream> |
11 | 11 |
|
12 | 12 | #include <util/arith_tools.h> |
| 13 | +#include <util/fresh_symbol.h> |
13 | 14 | #include <util/std_types.h> |
14 | 15 | #include <util/std_code.h> |
15 | 16 | #include <util/std_expr.h> |
@@ -107,8 +108,7 @@ exprt java_object_factoryt::allocate_object( |
107 | 108 | bool cast_needed=allocate_type_resolved!=target_type; |
108 | 109 | if(!create_dynamic_objects) |
109 | 110 | { |
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); |
112 | 112 | aux_symbol.is_static_lifetime=true; |
113 | 113 |
|
114 | 114 | exprt object=aux_symbol.symbol_expr(); |
@@ -136,8 +136,11 @@ exprt java_object_factoryt::allocate_object( |
136 | 136 | // Create a symbol for the malloc expression so we can initialize |
137 | 137 | // without having to do it potentially through a double-deref, which |
138 | 138 | // 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"); |
141 | 144 | code_assignt assign=code_assignt(malloc_sym.symbol_expr(), malloc_expr); |
142 | 145 | code_assignt &malloc_assign=assign; |
143 | 146 | malloc_assign.add_source_location()=loc; |
@@ -211,8 +214,11 @@ void java_object_factoryt::gen_nondet_init( |
211 | 214 | if(!assume_non_null) |
212 | 215 | { |
213 | 216 | 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"); |
216 | 222 | auto returns_null=returns_null_sym.symbol_expr(); |
217 | 223 | auto assign_returns_null= |
218 | 224 | code_assignt(returns_null, get_nondet_bool(returns_null_sym.type)); |
@@ -365,8 +371,11 @@ void java_object_factoryt::gen_nondet_array_init( |
365 | 371 | auto max_length_expr=from_integer(max_nondet_array_length, java_int_type()); |
366 | 372 |
|
367 | 373 | 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"); |
370 | 379 | const auto &length_sym_expr=length_sym.symbol_expr(); |
371 | 380 |
|
372 | 381 | // Initialize array with some undetermined length: |
@@ -400,17 +409,23 @@ void java_object_factoryt::gen_nondet_array_init( |
400 | 409 |
|
401 | 410 | // Interpose a new symbol, as the goto-symex stage can't handle array indexing |
402 | 411 | // 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"); |
405 | 417 | const auto &array_init_symexpr=array_init_symbol.symbol_expr(); |
406 | 418 | codet data_assign=code_assignt(array_init_symexpr, init_array_expr); |
407 | 419 | data_assign.add_source_location()=loc; |
408 | 420 | init_code.copy_to_operands(data_assign); |
409 | 421 |
|
410 | 422 | // Emit init loop for(array_init_iter=0; array_init_iter!=array.length; |
411 | 423 | // ++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"); |
414 | 429 | exprt counter_expr=counter.symbol_expr(); |
415 | 430 |
|
416 | 431 | exprt java_zero=from_integer(0, java_int_type()); |
@@ -512,22 +527,19 @@ Function: new_tmp_symbol |
512 | 527 |
|
513 | 528 | \*******************************************************************/ |
514 | 529 |
|
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) |
516 | 535 | { |
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); |
531 | 543 | } |
532 | 544 |
|
533 | 545 | /*******************************************************************\ |
@@ -572,8 +584,10 @@ exprt object_factory( |
572 | 584 | { |
573 | 585 | if(type.id()==ID_pointer) |
574 | 586 | { |
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); |
577 | 591 | aux_symbol.is_static_lifetime=true; |
578 | 592 |
|
579 | 593 | exprt object=aux_symbol.symbol_expr(); |
|
0 commit comments