Skip to content

Commit 6cb91f5

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 3b8be4a commit 6cb91f5

10 files changed

+95
-182
lines changed

jbmc/src/java_bytecode/convert_java_nondet.cpp

Lines changed: 3 additions & 8 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,13 +114,8 @@ 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(
118-
op.type(),
119-
id2string(goto_programt::get_function_id(goto_program)),
120-
"nondet_tmp",
121-
source_loc,
122-
ID_java,
123-
symbol_table);
117+
symbolt &aux_symbol =
118+
fresh_java_symbol(op.type(), "nondet_tmp", source_loc, symbol_table);
124119

125120
const symbol_exprt aux_symbol_expr = aux_symbol.symbol_expr();
126121
op = aux_symbol_expr;

jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

Lines changed: 2 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.
@@ -236,12 +236,10 @@ static void instrument_synchronized_code(
236236
code_pop_catcht catch_pop;
237237

238238
// Create the finally block with the same label targeted in the catch-push
239-
const symbolt &tmp_symbol = get_fresh_aux_symbol(
239+
const symbolt &tmp_symbol = fresh_java_symbol(
240240
java_reference_type(symbol_typet("java::java.lang.Throwable")),
241-
id2string(symbol.name),
242241
"caught-synchronized-exception",
243242
code.source_location(),
244-
ID_java,
245243
symbol_table);
246244
symbol_exprt catch_var(tmp_symbol.name, tmp_symbol.type);
247245
catch_var.set(ID_C_base_name, tmp_symbol.base_name);

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 2 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,8 @@ codet 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, "new_exception", original_loc, symbol_table);
124117

125118
side_effect_exprt new_instance(ID_java_new, exc_ptr_type, original_loc);
126119
code_assignt assign_new(new_symbol.symbol_expr(), new_instance);

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 17 additions & 52 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
{
@@ -205,13 +205,8 @@ exprt allocate_dynamic_object(
205205
// create a symbol for the malloc expression so we can initialize
206206
// without having to do it potentially through a double-deref, which
207207
// breaks the to-SSA phase.
208-
symbolt &malloc_sym = get_fresh_aux_symbol(
209-
pointer_type(allocate_type),
210-
id2string(function_id),
211-
"malloc_site",
212-
loc,
213-
ID_java,
214-
symbol_table);
208+
symbolt &malloc_sym = fresh_java_symbol(
209+
pointer_type(allocate_type), "malloc_site", loc, symbol_table);
215210
symbols_created.push_back(&malloc_sym);
216211
code_assignt assign=code_assignt(malloc_sym.symbol_expr(), malloc_expr);
217212
assign.add_source_location()=loc;
@@ -303,13 +298,8 @@ exprt java_object_factoryt::allocate_object(
303298
case allocation_typet::LOCAL:
304299
case allocation_typet::GLOBAL:
305300
{
306-
symbolt &aux_symbol = get_fresh_aux_symbol(
307-
allocate_type,
308-
id2string(object_factory_parameters.function_id),
309-
"tmp_object_factory",
310-
loc,
311-
ID_java,
312-
symbol_table);
301+
symbolt &aux_symbol = fresh_java_symbol(
302+
allocate_type, "tmp_object_factory", loc, symbol_table);
313303
if(alloc_type==allocation_typet::GLOBAL)
314304
aux_symbol.is_static_lifetime=true;
315305
symbols_created.push_back(&aux_symbol);
@@ -615,13 +605,8 @@ bool initialize_nondet_string_fields(
615605

616606
/// \todo Refactor with make_nondet_string_expr
617607
// length_expr = nondet(int);
618-
const symbolt length_sym = get_fresh_aux_symbol(
619-
java_int_type(),
620-
id2string(function_id),
621-
"tmp_object_factory",
622-
loc,
623-
ID_java,
624-
symbol_table);
608+
const symbolt length_sym =
609+
fresh_java_symbol(java_int_type(), "tmp_object_factory", loc, symbol_table);
625610
const symbol_exprt length_expr = length_sym.symbol_expr();
626611
const side_effect_expr_nondett nondet_length(length_expr.type(), loc);
627612
code.add(code_declt(length_expr));
@@ -646,8 +631,8 @@ bool initialize_nondet_string_fields(
646631
const typet data_ptr_type = pointer_type(
647632
array_typet(java_char_type(), infinity_exprt(java_int_type())));
648633

649-
symbolt &data_pointer_sym = get_fresh_aux_symbol(
650-
data_ptr_type, "", "string_data_pointer", loc, ID_java, symbol_table);
634+
symbolt &data_pointer_sym =
635+
fresh_java_symbol(data_ptr_type, "string_data_pointer", loc, symbol_table);
651636
const auto data_pointer = data_pointer_sym.symbol_expr();
652637
code.add(code_declt(data_pointer));
653638

@@ -939,13 +924,8 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
939924
size_t depth,
940925
const source_locationt &location)
941926
{
942-
symbolt new_symbol = get_fresh_aux_symbol(
943-
replacement_pointer,
944-
id2string(object_factory_parameters.function_id),
945-
"tmp_object_factory",
946-
loc,
947-
ID_java,
948-
symbol_table);
927+
symbolt new_symbol = fresh_java_symbol(
928+
replacement_pointer, "tmp_object_factory", location, symbol_table);
949929

950930
// Generate a new object into this new symbol
951931
gen_nondet_init(
@@ -1260,13 +1240,8 @@ const symbol_exprt java_object_factoryt::gen_nondet_int_init(
12601240
{
12611241
PRECONDITION(min_value_expr.type() == max_value_expr.type());
12621242
// Allocate a new symbol for the int
1263-
const symbolt &int_symbol = get_fresh_aux_symbol(
1264-
min_value_expr.type(),
1265-
id2string(object_factory_parameters.function_id),
1266-
basename_prefix,
1267-
loc,
1268-
ID_java,
1269-
symbol_table);
1243+
const symbolt &int_symbol = fresh_java_symbol(
1244+
min_value_expr.type(), basename_prefix, loc, symbol_table);
12701245
symbols_created.push_back(&int_symbol);
12711246
const auto &int_symbol_expr = int_symbol.symbol_expr();
12721247

@@ -1382,13 +1357,8 @@ void java_object_factoryt::gen_nondet_array_init(
13821357

13831358
// Interpose a new symbol, as the goto-symex stage can't handle array indexing
13841359
// via a cast.
1385-
symbolt &array_init_symbol = get_fresh_aux_symbol(
1386-
init_array_expr.type(),
1387-
id2string(object_factory_parameters.function_id),
1388-
"array_data_init",
1389-
loc,
1390-
ID_java,
1391-
symbol_table);
1360+
symbolt &array_init_symbol = fresh_java_symbol(
1361+
init_array_expr.type(), "array_data_init", loc, symbol_table);
13921362
symbols_created.push_back(&array_init_symbol);
13931363
const auto &array_init_symexpr=array_init_symbol.symbol_expr();
13941364
codet data_assign=code_assignt(array_init_symexpr, init_array_expr);
@@ -1397,13 +1367,8 @@ void java_object_factoryt::gen_nondet_array_init(
13971367

13981368
// Emit init loop for(array_init_iter=0; array_init_iter!=array.length;
13991369
// ++array_init_iter) init(array[array_init_iter]);
1400-
symbolt &counter = get_fresh_aux_symbol(
1401-
length_expr.type(),
1402-
id2string(object_factory_parameters.function_id),
1403-
"array_init_iter",
1404-
loc,
1405-
ID_java,
1406-
symbol_table);
1370+
symbolt &counter =
1371+
fresh_java_symbol(length_expr.type(), "array_init_iter", loc, symbol_table);
14071372
symbols_created.push_back(&counter);
14081373
exprt counter_expr=counter.symbol_expr();
14091374

0 commit comments

Comments
 (0)