Skip to content

Commit 293ec8e

Browse files
Add and use fresh_java_symbol function
This prevents forgetting that the basename of the symbol should be the function identifier.
1 parent e222680 commit 293ec8e

10 files changed

+107
-136
lines changed

jbmc/src/java_bytecode/convert_java_nondet.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Author: Reuben Thomas, [email protected]
1515
#include <goto-programs/goto_model.h>
1616
#include <goto-programs/remove_skip.h>
1717

18-
#include <util/fresh_symbol.h>
1918
#include <util/irep_ids.h>
2019

2120
#include <memory>
2221

2322
#include "java_object_factory.h" // gen_nondet_init
23+
#include "java_utils.h"
2424

2525
/// Returns true if `expr` is a nondet pointer that isn't a function pointer or
2626
/// a void* pointer as these can be meaningfully non-det initialized.
@@ -114,12 +114,11 @@ static std::pair<goto_programt::targett, bool> insert_nondet_init_code(
114114
// target2: instruction containing op, with op replaced by aux_symbol
115115
// dead aux_symbol
116116

117-
symbolt &aux_symbol = get_fresh_aux_symbol(
117+
symbolt &aux_symbol = fresh_java_symbol(
118118
op.type(),
119-
id2string(goto_programt::get_function_id(goto_program)),
120119
"nondet_tmp",
121120
source_loc,
122-
ID_java,
121+
goto_programt::get_function_id(goto_program),
123122
symbol_table);
124123

125124
const symbol_exprt aux_symbol_expr = aux_symbol.symbol_expr();

jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Author: Kurt Degiogrio, [email protected]
99
#include "java_bytecode_concurrency_instrumentation.h"
1010
#include "expr2java.h"
1111
#include "java_types.h"
12+
#include "java_utils.h"
1213

1314
#include <util/expr_iterator.h>
1415
#include <util/namespace.h>
1516
#include <util/cprover_prefix.h>
1617
#include <util/std_types.h>
17-
#include <util/fresh_symbol.h>
1818
#include <util/arith_tools.h>
1919

2020
// Disable linter to allow an std::string constant.
@@ -229,12 +229,11 @@ static void instrument_synchronized_code(
229229
code_pop_catcht catch_pop;
230230

231231
// Create the finally block with the same label targeted in the catch-push
232-
const symbolt &tmp_symbol = get_fresh_aux_symbol(
232+
const symbolt &tmp_symbol = fresh_java_symbol(
233233
java_reference_type(symbol_typet("java::java.lang.Throwable")),
234-
id2string(symbol.name),
235234
"caught-synchronized-exception",
236235
code.source_location(),
237-
ID_java,
236+
id2string(symbol.name),
238237
symbol_table);
239238
symbol_exprt catch_var(tmp_symbol.name, tmp_symbol.type);
240239
catch_var.set(ID_C_base_name, tmp_symbol.base_name);

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Date: June 2017
1111
#include "java_bytecode_instrument.h"
1212

1313
#include <util/arith_tools.h>
14-
#include <util/fresh_symbol.h>
1514
#include <util/std_code.h>
1615
#include <util/std_expr.h>
1716
#include <util/c_types.h>
@@ -113,14 +112,12 @@ code_ifthenelset java_bytecode_instrumentt::throw_exception(
113112

114113
// Allocate and throw an instance of the exception class:
115114

116-
symbolt &new_symbol=
117-
get_fresh_aux_symbol(
118-
exc_ptr_type,
119-
"new_exception",
120-
"new_exception",
121-
original_loc,
122-
ID_java,
123-
symbol_table);
115+
symbolt &new_symbol = fresh_java_symbol(
116+
exc_ptr_type,
117+
"new_exception",
118+
original_loc,
119+
original_loc.get_function(),
120+
symbol_table);
124121

125122
side_effect_exprt new_instance(ID_java_new, exc_ptr_type, original_loc);
126123
code_assignt assign_new(new_symbol.symbol_expr(), new_instance);

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Author: Daniel Kroening, [email protected]
99
#include "java_object_factory.h"
1010

1111
#include <util/expr_initializer.h>
12-
#include <util/fresh_symbol.h>
1312
#include <util/nondet_bool.h>
1413
#include <util/pointer_offset_size.h>
1514

@@ -18,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1817

1918
#include "generic_parameter_specialization_map_keys.h"
2019
#include "java_root_class.h"
20+
#include "java_utils.h"
2121

2222
class java_object_factoryt
2323
{
@@ -206,12 +206,11 @@ exprt allocate_dynamic_object(
206206
// create a symbol for the malloc expression so we can initialize
207207
// without having to do it potentially through a double-deref, which
208208
// breaks the to-SSA phase.
209-
symbolt &malloc_sym = get_fresh_aux_symbol(
209+
symbolt &malloc_sym = fresh_java_symbol(
210210
pointer_type(allocate_type),
211-
id2string(function_id),
212211
"malloc_site",
213212
loc,
214-
ID_java,
213+
function_id,
215214
symbol_table);
216215
symbols_created.push_back(&malloc_sym);
217216
code_assignt assign(malloc_sym.symbol_expr(), malloc_expr);
@@ -306,12 +305,11 @@ exprt java_object_factoryt::allocate_object(
306305
case allocation_typet::LOCAL:
307306
case allocation_typet::GLOBAL:
308307
{
309-
symbolt &aux_symbol = get_fresh_aux_symbol(
308+
symbolt &aux_symbol = fresh_java_symbol(
310309
allocate_type,
311-
id2string(object_factory_parameters.function_id),
312310
"tmp_object_factory",
313311
loc,
314-
ID_java,
312+
object_factory_parameters.function_id,
315313
symbol_table);
316314
if(alloc_type==allocation_typet::GLOBAL)
317315
aux_symbol.is_static_lifetime=true;
@@ -610,13 +608,8 @@ bool initialize_nondet_string_fields(
610608

611609
/// \todo Refactor with make_nondet_string_expr
612610
// length_expr = nondet(int);
613-
const symbolt length_sym = get_fresh_aux_symbol(
614-
java_int_type(),
615-
id2string(function_id),
616-
"tmp_object_factory",
617-
loc,
618-
ID_java,
619-
symbol_table);
611+
const symbolt length_sym = fresh_java_symbol(
612+
java_int_type(), "tmp_object_factory", loc, function_id, symbol_table);
620613
const symbol_exprt length_expr = length_sym.symbol_expr();
621614
const side_effect_expr_nondett nondet_length(length_expr.type(), loc);
622615
code.add(code_declt(length_expr));
@@ -918,12 +911,11 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
918911
size_t depth,
919912
const source_locationt &location)
920913
{
921-
symbolt new_symbol = get_fresh_aux_symbol(
914+
symbolt new_symbol = fresh_java_symbol(
922915
replacement_pointer,
923-
id2string(object_factory_parameters.function_id),
924916
"tmp_object_factory",
925-
loc,
926-
ID_java,
917+
location,
918+
object_factory_parameters.function_id,
927919
symbol_table);
928920

929921
// Generate a new object into this new symbol
@@ -1240,12 +1232,11 @@ const symbol_exprt java_object_factoryt::gen_nondet_int_init(
12401232
{
12411233
PRECONDITION(min_value_expr.type() == max_value_expr.type());
12421234
// Allocate a new symbol for the int
1243-
const symbolt &int_symbol = get_fresh_aux_symbol(
1235+
const symbolt &int_symbol = fresh_java_symbol(
12441236
min_value_expr.type(),
1245-
id2string(object_factory_parameters.function_id),
12461237
basename_prefix,
12471238
loc,
1248-
ID_java,
1239+
object_factory_parameters.function_id,
12491240
symbol_table);
12501241
symbols_created.push_back(&int_symbol);
12511242
const auto &int_symbol_expr = int_symbol.symbol_expr();
@@ -1364,12 +1355,11 @@ void java_object_factoryt::gen_nondet_array_init(
13641355

13651356
// Interpose a new symbol, as the goto-symex stage can't handle array indexing
13661357
// via a cast.
1367-
symbolt &array_init_symbol = get_fresh_aux_symbol(
1358+
symbolt &array_init_symbol = fresh_java_symbol(
13681359
init_array_expr.type(),
1369-
id2string(object_factory_parameters.function_id),
13701360
"array_data_init",
13711361
loc,
1372-
ID_java,
1362+
object_factory_parameters.function_id,
13731363
symbol_table);
13741364
symbols_created.push_back(&array_init_symbol);
13751365
const auto &array_init_symexpr=array_init_symbol.symbol_expr();
@@ -1379,12 +1369,11 @@ void java_object_factoryt::gen_nondet_array_init(
13791369

13801370
// Emit init loop for(array_init_iter=0; array_init_iter!=array.length;
13811371
// ++array_init_iter) init(array[array_init_iter]);
1382-
symbolt &counter = get_fresh_aux_symbol(
1372+
symbolt &counter = fresh_java_symbol(
13831373
length_expr.type(),
1384-
id2string(object_factory_parameters.function_id),
13851374
"array_init_iter",
13861375
loc,
1387-
ID_java,
1376+
object_factory_parameters.function_id,
13881377
symbol_table);
13891378
symbols_created.push_back(&counter);
13901379
exprt counter_expr=counter.symbol_expr();

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,11 @@ symbol_exprt java_string_library_preprocesst::fresh_array(
249249
const source_locationt &location,
250250
symbol_tablet &symbol_table)
251251
{
252-
symbolt array_symbol=get_fresh_aux_symbol(
252+
symbolt array_symbol = fresh_java_symbol(
253253
type,
254254
"cprover_string_array",
255-
"cprover_string_array",
256255
location,
257-
ID_java,
256+
location.get_function(),
258257
symbol_table);
259258
array_symbol.is_static_lifetime=true;
260259
return array_symbol.symbol_expr();
@@ -453,8 +452,8 @@ refined_string_exprt java_string_library_preprocesst::replace_char_array(
453452
checked_dereference(array_pointer, array_pointer.type().subtype());
454453
// array_data is array_pointer-> data
455454
const exprt array_data = get_data(array, symbol_table);
456-
const symbolt sym_char_array = get_fresh_aux_symbol(
457-
array_data.type(), "char_array", "char_array", loc, ID_java, symbol_table);
455+
const symbolt sym_char_array = fresh_java_symbol(
456+
array_data.type(), "char_array", loc, loc.get_function(), symbol_table);
458457
const symbol_exprt char_array = sym_char_array.symbol_expr();
459458
// char_array = array_pointer->data
460459
code.add(code_assignt(char_array, array_data), loc);
@@ -483,8 +482,8 @@ symbol_exprt java_string_library_preprocesst::fresh_string(
483482
const source_locationt &loc,
484483
symbol_table_baset &symbol_table)
485484
{
486-
symbolt string_symbol=get_fresh_aux_symbol(
487-
type, "cprover_string", "cprover_string", loc, ID_java, symbol_table);
485+
symbolt string_symbol = fresh_java_symbol(
486+
type, "cprover_string", loc, loc.get_function(), symbol_table);
488487
string_symbol.is_static_lifetime=true;
489488
return string_symbol.symbol_expr();
490489
}
@@ -502,22 +501,12 @@ refined_string_exprt java_string_library_preprocesst::decl_string_expr(
502501
symbol_table_baset &symbol_table,
503502
code_blockt &code)
504503
{
505-
const symbolt sym_length = get_fresh_aux_symbol(
506-
index_type,
507-
"cprover_string_length",
508-
"cprover_string_length",
509-
loc,
510-
ID_java,
511-
symbol_table);
504+
const symbolt sym_length = fresh_java_symbol(
505+
index_type, "cprover_string_length", loc, function_name, symbol_table);
512506
const symbol_exprt length_field = sym_length.symbol_expr();
513507
const pointer_typet array_type = pointer_type(java_char_type());
514-
const symbolt sym_content = get_fresh_aux_symbol(
515-
array_type,
516-
"cprover_string_content",
517-
"cprover_string_content",
518-
loc,
519-
ID_java,
520-
symbol_table);
508+
const symbolt sym_content = fresh_java_symbol(
509+
array_type, "cprover_string_content", loc, function_name, symbol_table);
521510
const symbol_exprt content_field = sym_content.symbol_expr();
522511
code.add(code_declt(content_field), loc);
523512
const refined_string_exprt str(
@@ -648,12 +637,11 @@ exprt make_nondet_infinite_char_array(
648637
{
649638
const array_typet array_type(
650639
java_char_type(), infinity_exprt(java_int_type()));
651-
const symbolt data_sym = get_fresh_aux_symbol(
640+
const symbolt data_sym = fresh_java_symbol(
652641
pointer_type(array_type),
653-
id2string(function_id),
654642
"nondet_infinite_array_pointer",
655643
loc,
656-
ID_java,
644+
loc.get_function(),
657645
symbol_table);
658646

659647
const symbol_exprt data_pointer = data_sym.symbol_expr();
@@ -681,13 +669,8 @@ void add_pointer_to_array_association(
681669
{
682670
PRECONDITION(array.type().id() == ID_array);
683671
PRECONDITION(pointer.type().id() == ID_pointer);
684-
const symbolt &return_sym = get_fresh_aux_symbol(
685-
java_int_type(),
686-
"return_array",
687-
"return_array",
688-
loc,
689-
ID_java,
690-
symbol_table);
672+
const symbolt &return_sym = fresh_java_symbol(
673+
java_int_type(), "return_array", loc, loc.get_function(), symbol_table);
691674
const auto return_expr = return_sym.symbol_expr();
692675
code.add(code_declt(return_expr), loc);
693676
code.add(
@@ -713,13 +696,8 @@ void add_array_to_length_association(
713696
const source_locationt &loc,
714697
code_blockt &code)
715698
{
716-
const symbolt &return_sym = get_fresh_aux_symbol(
717-
java_int_type(),
718-
"return_array",
719-
"return_array",
720-
loc,
721-
ID_java,
722-
symbol_table);
699+
const symbolt &return_sym = fresh_java_symbol(
700+
java_int_type(), "return_array", loc, loc.get_function(), symbol_table);
723701
const auto return_expr = return_sym.symbol_expr();
724702
code.add(code_declt(return_expr), loc);
725703
code.add(
@@ -750,8 +728,8 @@ void add_character_set_constraint(
750728
code_blockt &code)
751729
{
752730
PRECONDITION(pointer.type().id() == ID_pointer);
753-
const symbolt &return_sym = get_fresh_aux_symbol(
754-
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
731+
const symbolt &return_sym = fresh_java_symbol(
732+
java_int_type(), "cnstr_added", loc, loc.get_function(), symbol_table);
755733
const auto return_expr = return_sym.symbol_expr();
756734
code.add(code_declt(return_expr), loc);
757735
const constant_exprt char_set_expr(char_set, string_typet());
@@ -788,12 +766,11 @@ refined_string_exprt java_string_library_preprocesst::string_expr_of_function(
788766
code_blockt &code)
789767
{
790768
// int return_code;
791-
const symbolt return_code_sym = get_fresh_aux_symbol(
769+
const symbolt return_code_sym = fresh_java_symbol(
792770
java_int_type(),
793771
std::string("return_code_") + function_name.c_str(),
794-
std::string("return_code_") + function_name.c_str(),
795772
loc,
796-
ID_java,
773+
loc.get_function(),
797774
symbol_table);
798775
const auto return_code = return_code_sym.symbol_expr();
799776
code.add(code_declt(return_code), loc);
@@ -1237,8 +1214,8 @@ java_string_library_preprocesst::get_primitive_value_of_object(
12371214

12381215
// declare tmp_type_name to hold the value
12391216
const std::string aux_name = "tmp_" + id2string(type_name);
1240-
const symbolt symbol = get_fresh_aux_symbol(
1241-
value_type, aux_name, aux_name, loc, ID_java, symbol_table);
1217+
const symbolt symbol = fresh_java_symbol(
1218+
value_type, aux_name, loc, loc.get_function(), symbol_table);
12421219
const auto value = symbol.symbol_expr();
12431220

12441221
// Check that the type of the object is in the symbol table,
@@ -1347,8 +1324,8 @@ exprt java_string_library_preprocesst::make_argument_for_format(
13471324
if(name!="string_expr")
13481325
{
13491326
std::string tmp_name="tmp_"+id2string(name);
1350-
symbolt field_symbol = get_fresh_aux_symbol(
1351-
type, id2string(function_id), tmp_name, loc, ID_java, symbol_table);
1327+
symbolt field_symbol = fresh_java_symbol(
1328+
type, tmp_name, loc, loc.get_function(), symbol_table);
13521329
auto field_symbol_expr = field_symbol.symbol_expr();
13531330
field_expr = field_symbol_expr;
13541331
code.add(code_declt(field_symbol_expr), loc);
@@ -1363,13 +1340,8 @@ exprt java_string_library_preprocesst::make_argument_for_format(
13631340

13641341
// arg_i = argv[index]
13651342
const exprt obj = get_object_at_index(argv, index);
1366-
const symbolt object_symbol = get_fresh_aux_symbol(
1367-
obj.type(),
1368-
id2string(function_id),
1369-
"tmp_format_obj",
1370-
loc,
1371-
ID_java,
1372-
symbol_table);
1343+
const symbolt object_symbol = fresh_java_symbol(
1344+
obj.type(), "tmp_format_obj", loc, loc.get_function(), symbol_table);
13731345
const symbol_exprt arg_i = object_symbol.symbol_expr();
13741346
allocate_dynamic_object_with_decl(
13751347
arg_i, symbol_table, loc, function_id, code);
@@ -1511,8 +1483,8 @@ codet java_string_library_preprocesst::make_object_get_class_code(
15111483
// > Class class1;
15121484
const pointer_typet class_type =
15131485
java_reference_type(symbol_table.lookup_ref("java::java.lang.Class").type);
1514-
const symbolt class1_sym = get_fresh_aux_symbol(
1515-
class_type, "class_symbol", "class_symbol", loc, ID_java, symbol_table);
1486+
const symbolt class1_sym = fresh_java_symbol(
1487+
class_type, "class_symbol", loc, loc.get_function(), symbol_table);
15161488
const symbol_exprt class1 = class1_sym.symbol_expr();
15171489
code.add(code_declt(class1), loc);
15181490

0 commit comments

Comments
 (0)