Skip to content

Commit 6146855

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 9631e83 commit 6146855

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);
@@ -617,13 +607,8 @@ bool initialize_nondet_string_fields(
617607

618608
/// \todo Refactor with make_nondet_string_expr
619609
// length_expr = nondet(int);
620-
const symbolt length_sym = get_fresh_aux_symbol(
621-
java_int_type(),
622-
id2string(function_id),
623-
"tmp_object_factory",
624-
loc,
625-
ID_java,
626-
symbol_table);
610+
const symbolt length_sym =
611+
fresh_java_symbol(java_int_type(), "tmp_object_factory", loc, symbol_table);
627612
const symbol_exprt length_expr = length_sym.symbol_expr();
628613
const side_effect_expr_nondett nondet_length(length_expr.type(), loc);
629614
code.add(code_declt(length_expr));
@@ -647,8 +632,8 @@ bool initialize_nondet_string_fields(
647632
const typet data_ptr_type = pointer_type(
648633
array_typet(java_char_type(), infinity_exprt(java_int_type())));
649634

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

@@ -940,13 +925,8 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
940925
size_t depth,
941926
const source_locationt &location)
942927
{
943-
symbolt new_symbol = get_fresh_aux_symbol(
944-
replacement_pointer,
945-
id2string(object_factory_parameters.function_id),
946-
"tmp_object_factory",
947-
loc,
948-
ID_java,
949-
symbol_table);
928+
symbolt new_symbol = fresh_java_symbol(
929+
replacement_pointer, "tmp_object_factory", location, symbol_table);
950930

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

@@ -1383,13 +1358,8 @@ void java_object_factoryt::gen_nondet_array_init(
13831358

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

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

0 commit comments

Comments
 (0)