Skip to content

Commit 23e5054

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 512d79f commit 23e5054

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();
@@ -457,8 +456,8 @@ refined_string_exprt java_string_library_preprocesst::replace_char_array(
457456
checked_dereference(array_pointer, array_pointer.type().subtype());
458457
// array_data is array_pointer-> data
459458
const exprt array_data = get_data(array, symbol_table);
460-
const symbolt sym_char_array = get_fresh_aux_symbol(
461-
array_data.type(), "char_array", "char_array", loc, ID_java, symbol_table);
459+
const symbolt sym_char_array = fresh_java_symbol(
460+
array_data.type(), "char_array", loc, loc.get_function(), symbol_table);
462461
const symbol_exprt char_array = sym_char_array.symbol_expr();
463462
// char_array = array_pointer->data
464463
code.add(code_assignt(char_array, array_data), loc);
@@ -487,8 +486,8 @@ symbol_exprt java_string_library_preprocesst::fresh_string(
487486
const source_locationt &loc,
488487
symbol_table_baset &symbol_table)
489488
{
490-
symbolt string_symbol=get_fresh_aux_symbol(
491-
type, "cprover_string", "cprover_string", loc, ID_java, symbol_table);
489+
symbolt string_symbol = fresh_java_symbol(
490+
type, "cprover_string", loc, loc.get_function(), symbol_table);
492491
string_symbol.is_static_lifetime=true;
493492
return string_symbol.symbol_expr();
494493
}
@@ -505,22 +504,12 @@ refined_string_exprt java_string_library_preprocesst::decl_string_expr(
505504
symbol_table_baset &symbol_table,
506505
code_blockt &code)
507506
{
508-
const symbolt sym_length = get_fresh_aux_symbol(
509-
index_type,
510-
"cprover_string_length",
511-
"cprover_string_length",
512-
loc,
513-
ID_java,
514-
symbol_table);
507+
const symbolt sym_length = fresh_java_symbol(
508+
index_type, "cprover_string_length", loc, function_name, symbol_table);
515509
const symbol_exprt length_field = sym_length.symbol_expr();
516510
const pointer_typet array_type = pointer_type(java_char_type());
517-
const symbolt sym_content = get_fresh_aux_symbol(
518-
array_type,
519-
"cprover_string_content",
520-
"cprover_string_content",
521-
loc,
522-
ID_java,
523-
symbol_table);
511+
const symbolt sym_content = fresh_java_symbol(
512+
array_type, "cprover_string_content", loc, function_name, symbol_table);
524513
const symbol_exprt content_field = sym_content.symbol_expr();
525514
code.add(code_declt(content_field), loc);
526515
const refined_string_exprt str(
@@ -653,12 +642,11 @@ exprt make_nondet_infinite_char_array(
653642
{
654643
const array_typet array_type(
655644
java_char_type(), infinity_exprt(java_int_type()));
656-
const symbolt data_sym = get_fresh_aux_symbol(
645+
const symbolt data_sym = fresh_java_symbol(
657646
pointer_type(array_type),
658-
id2string(function_id),
659647
"nondet_infinite_array_pointer",
660648
loc,
661-
ID_java,
649+
loc.get_function(),
662650
symbol_table);
663651

664652
const symbol_exprt data_pointer = data_sym.symbol_expr();
@@ -686,13 +674,8 @@ void add_pointer_to_array_association(
686674
{
687675
PRECONDITION(array.type().id() == ID_array);
688676
PRECONDITION(pointer.type().id() == ID_pointer);
689-
const symbolt &return_sym = get_fresh_aux_symbol(
690-
java_int_type(),
691-
"return_array",
692-
"return_array",
693-
loc,
694-
ID_java,
695-
symbol_table);
677+
const symbolt &return_sym = fresh_java_symbol(
678+
java_int_type(), "return_array", loc, loc.get_function(), symbol_table);
696679
const auto return_expr = return_sym.symbol_expr();
697680
code.add(code_declt(return_expr), loc);
698681
code.add(
@@ -718,13 +701,8 @@ void add_array_to_length_association(
718701
const source_locationt &loc,
719702
code_blockt &code)
720703
{
721-
const symbolt &return_sym = get_fresh_aux_symbol(
722-
java_int_type(),
723-
"return_array",
724-
"return_array",
725-
loc,
726-
ID_java,
727-
symbol_table);
704+
const symbolt &return_sym = fresh_java_symbol(
705+
java_int_type(), "return_array", loc, loc.get_function(), symbol_table);
728706
const auto return_expr = return_sym.symbol_expr();
729707
code.add(code_declt(return_expr), loc);
730708
code.add(
@@ -755,8 +733,8 @@ void add_character_set_constraint(
755733
code_blockt &code)
756734
{
757735
PRECONDITION(pointer.type().id() == ID_pointer);
758-
const symbolt &return_sym = get_fresh_aux_symbol(
759-
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
736+
const symbolt &return_sym = fresh_java_symbol(
737+
java_int_type(), "cnstr_added", loc, loc.get_function(), symbol_table);
760738
const auto return_expr = return_sym.symbol_expr();
761739
code.add(code_declt(return_expr), loc);
762740
const constant_exprt char_set_expr(char_set, string_typet());
@@ -793,12 +771,11 @@ refined_string_exprt java_string_library_preprocesst::string_expr_of_function(
793771
code_blockt &code)
794772
{
795773
// int return_code;
796-
const symbolt return_code_sym = get_fresh_aux_symbol(
774+
const symbolt return_code_sym = fresh_java_symbol(
797775
java_int_type(),
798776
std::string("return_code_") + function_name.c_str(),
799-
std::string("return_code_") + function_name.c_str(),
800777
loc,
801-
ID_java,
778+
loc.get_function(),
802779
symbol_table);
803780
const auto return_code = return_code_sym.symbol_expr();
804781
code.add(code_declt(return_code), loc);
@@ -1241,8 +1218,8 @@ java_string_library_preprocesst::get_primitive_value_of_object(
12411218

12421219
// declare tmp_type_name to hold the value
12431220
const std::string aux_name = "tmp_" + id2string(type_name);
1244-
const symbolt symbol = get_fresh_aux_symbol(
1245-
value_type, aux_name, aux_name, loc, ID_java, symbol_table);
1221+
const symbolt symbol = fresh_java_symbol(
1222+
value_type, aux_name, loc, loc.get_function(), symbol_table);
12461223
const auto value = symbol.symbol_expr();
12471224

12481225
// Check that the type of the object is in the symbol table,
@@ -1350,8 +1327,8 @@ exprt java_string_library_preprocesst::make_argument_for_format(
13501327
if(name!="string_expr")
13511328
{
13521329
std::string tmp_name="tmp_"+id2string(name);
1353-
symbolt field_symbol = get_fresh_aux_symbol(
1354-
type, id2string(function_id), tmp_name, loc, ID_java, symbol_table);
1330+
symbolt field_symbol = fresh_java_symbol(
1331+
type, tmp_name, loc, loc.get_function(), symbol_table);
13551332
auto field_symbol_expr = field_symbol.symbol_expr();
13561333
field_expr = field_symbol_expr;
13571334
code.add(code_declt(field_symbol_expr), loc);
@@ -1366,13 +1343,8 @@ exprt java_string_library_preprocesst::make_argument_for_format(
13661343

13671344
// arg_i = argv[index]
13681345
const exprt obj = get_object_at_index(argv, index);
1369-
const symbolt object_symbol = get_fresh_aux_symbol(
1370-
obj.type(),
1371-
id2string(function_id),
1372-
"tmp_format_obj",
1373-
loc,
1374-
ID_java,
1375-
symbol_table);
1346+
const symbolt object_symbol = fresh_java_symbol(
1347+
obj.type(), "tmp_format_obj", loc, loc.get_function(), symbol_table);
13761348
const symbol_exprt arg_i = object_symbol.symbol_expr();
13771349
allocate_dynamic_object_with_decl(
13781350
arg_i, symbol_table, loc, function_id, code);
@@ -1512,8 +1484,8 @@ codet java_string_library_preprocesst::make_object_get_class_code(
15121484
// > Class class1;
15131485
const pointer_typet class_type =
15141486
java_reference_type(symbol_table.lookup_ref("java::java.lang.Class").type);
1515-
const symbolt class1_sym = get_fresh_aux_symbol(
1516-
class_type, "class_symbol", "class_symbol", loc, ID_java, symbol_table);
1487+
const symbolt class1_sym = fresh_java_symbol(
1488+
class_type, "class_symbol", loc, loc.get_function(), symbol_table);
15171489
const symbol_exprt class1 = class1_sym.symbol_expr();
15181490
code.add(code_declt(class1), loc);
15191491

0 commit comments

Comments
 (0)