Skip to content

Commit 2bf4046

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 0af2cf2 commit 2bf4046

11 files changed

+93
-125
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.
@@ -116,13 +116,8 @@ static std::pair<goto_programt::targett, bool> insert_nondet_init_code(
116116
// target2: instruction containing op, with op replaced by aux_symbol
117117
// dead aux_symbol
118118

119-
symbolt &aux_symbol = get_fresh_aux_symbol(
120-
op.type(),
121-
id2string(function_identifier),
122-
"nondet_tmp",
123-
source_loc,
124-
ID_java,
125-
symbol_table);
119+
symbolt &aux_symbol = fresh_java_symbol(
120+
op.type(), "nondet_tmp", source_loc, function_identifier, symbol_table);
126121

127122
const symbol_exprt aux_symbol_expr = aux_symbol.symbol_expr();
128123
op = aux_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(struct_tag_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: 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>
@@ -112,14 +111,8 @@ code_ifthenelset java_bytecode_instrumentt::throw_exception(
112111

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

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

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

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,11 @@ exprt::operandst java_build_arguments(
375375
// method(..., param, ...)
376376
//
377377

378-
const symbolt result_symbol = get_fresh_aux_symbol(
378+
const symbolt result_symbol = fresh_java_symbol(
379379
p.type(),
380-
id2string(function.name),
381380
"nondet_parameter_" + std::to_string(param_number),
382381
function.location,
383-
ID_java,
382+
function.name,
384383
symbol_table);
385384
main_arguments[param_number] = result_symbol.symbol_expr();
386385

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 6 additions & 12 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/nondet.h>
1514
#include <util/pointer_offset_size.h>
@@ -20,6 +19,7 @@ Author: Daniel Kroening, [email protected]
2019
#include "generic_parameter_specialization_map_keys.h"
2120
#include "java_root_class.h"
2221
#include "java_string_literals.h"
22+
#include "java_utils.h"
2323

2424
class java_object_factoryt
2525
{
@@ -442,13 +442,8 @@ void initialize_nondet_string_fields(
442442

443443
/// \todo Refactor with make_nondet_string_expr
444444
// length_expr = nondet(int);
445-
const symbolt length_sym = get_fresh_aux_symbol(
446-
java_int_type(),
447-
id2string(function_id),
448-
"tmp_object_factory",
449-
loc,
450-
ID_java,
451-
symbol_table);
445+
const symbolt length_sym = fresh_java_symbol(
446+
java_int_type(), "tmp_object_factory", loc, function_id, symbol_table);
452447
const symbol_exprt length_expr = length_sym.symbol_expr();
453448
const side_effect_expr_nondett nondet_length(length_expr.type(), loc);
454449
code.add(code_declt(length_expr));
@@ -745,12 +740,11 @@ symbol_exprt java_object_factoryt::gen_nondet_subtype_pointer_init(
745740
size_t depth,
746741
const source_locationt &location)
747742
{
748-
symbolt new_symbol = get_fresh_aux_symbol(
743+
symbolt new_symbol = fresh_java_symbol(
749744
replacement_pointer,
750-
id2string(object_factory_parameters.function_id),
751745
"tmp_object_factory",
752-
loc,
753-
ID_java,
746+
location,
747+
object_factory_parameters.function_id,
754748
symbol_table);
755749

756750
// Generate a new object into this new symbol

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ refined_string_exprt java_string_library_preprocesst::replace_char_array(
407407
checked_dereference(array_pointer, array_pointer.type().subtype());
408408
// array_data is array_pointer-> data
409409
const exprt array_data = get_data(array, symbol_table);
410-
const symbolt &sym_char_array = get_fresh_aux_symbol(
411-
array_data.type(), "char_array", "char_array", loc, ID_java, symbol_table);
410+
const symbolt &sym_char_array = fresh_java_symbol(
411+
array_data.type(), "char_array", loc, function_id, symbol_table);
412412
const symbol_exprt char_array = sym_char_array.symbol_expr();
413413
// char_array = array_pointer->data
414414
code.add(code_assignt(char_array, array_data), loc);
@@ -439,8 +439,8 @@ symbol_exprt java_string_library_preprocesst::fresh_string(
439439
const irep_idt &function_id,
440440
symbol_table_baset &symbol_table)
441441
{
442-
symbolt string_symbol=get_fresh_aux_symbol(
443-
type, "cprover_string", "cprover_string", loc, ID_java, symbol_table);
442+
symbolt string_symbol =
443+
fresh_java_symbol(type, "cprover_string", loc, function_id, symbol_table);
444444
string_symbol.is_static_lifetime=true;
445445
return string_symbol.symbol_expr();
446446
}
@@ -458,22 +458,12 @@ refined_string_exprt java_string_library_preprocesst::decl_string_expr(
458458
symbol_table_baset &symbol_table,
459459
code_blockt &code)
460460
{
461-
const symbolt &sym_length = get_fresh_aux_symbol(
462-
index_type,
463-
"cprover_string_length",
464-
"cprover_string_length",
465-
loc,
466-
ID_java,
467-
symbol_table);
461+
const symbolt &sym_length = fresh_java_symbol(
462+
index_type, "cprover_string_length", loc, function_id, symbol_table);
468463
const symbol_exprt length_field = sym_length.symbol_expr();
469464
const pointer_typet array_type = pointer_type(java_char_type());
470-
const symbolt &sym_content = get_fresh_aux_symbol(
471-
array_type,
472-
"cprover_string_content",
473-
"cprover_string_content",
474-
loc,
475-
ID_java,
476-
symbol_table);
465+
const symbolt &sym_content = fresh_java_symbol(
466+
array_type, "cprover_string_content", loc, function_id, symbol_table);
477467
const symbol_exprt content_field = sym_content.symbol_expr();
478468
code.add(code_declt(content_field), loc);
479469
const refined_string_exprt str{
@@ -599,12 +589,11 @@ exprt make_nondet_infinite_char_array(
599589
{
600590
const array_typet array_type(
601591
java_char_type(), infinity_exprt(java_int_type()));
602-
const symbolt data_sym = get_fresh_aux_symbol(
592+
const symbolt data_sym = fresh_java_symbol(
603593
pointer_type(array_type),
604-
id2string(function_id),
605594
"nondet_infinite_array_pointer",
606595
loc,
607-
ID_java,
596+
function_id,
608597
symbol_table);
609598

610599
const symbol_exprt data_pointer = data_sym.symbol_expr();
@@ -634,13 +623,8 @@ void add_pointer_to_array_association(
634623
{
635624
PRECONDITION(array.type().id() == ID_array);
636625
PRECONDITION(pointer.type().id() == ID_pointer);
637-
const symbolt &return_sym = get_fresh_aux_symbol(
638-
java_int_type(),
639-
"return_array",
640-
"return_array",
641-
loc,
642-
ID_java,
643-
symbol_table);
626+
const symbolt &return_sym = fresh_java_symbol(
627+
java_int_type(), "return_array", loc, function_id, symbol_table);
644628
const auto return_expr = return_sym.symbol_expr();
645629
code.add(code_declt(return_expr), loc);
646630
code.add(
@@ -668,13 +652,8 @@ void add_array_to_length_association(
668652
const irep_idt &function_id,
669653
code_blockt &code)
670654
{
671-
const symbolt &return_sym = get_fresh_aux_symbol(
672-
java_int_type(),
673-
"return_array",
674-
"return_array",
675-
loc,
676-
ID_java,
677-
symbol_table);
655+
const symbolt &return_sym = fresh_java_symbol(
656+
java_int_type(), "return_array", loc, function_id, symbol_table);
678657
const auto return_expr = return_sym.symbol_expr();
679658
code.add(code_declt(return_expr), loc);
680659
code.add(
@@ -706,8 +685,8 @@ void add_character_set_constraint(
706685
code_blockt &code)
707686
{
708687
PRECONDITION(pointer.type().id() == ID_pointer);
709-
const symbolt &return_sym = get_fresh_aux_symbol(
710-
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
688+
const symbolt &return_sym = fresh_java_symbol(
689+
java_int_type(), "cnstr_added", loc, function_id, symbol_table);
711690
const auto return_expr = return_sym.symbol_expr();
712691
code.add(code_declt(return_expr), loc);
713692
const constant_exprt char_set_expr(char_set, string_typet());
@@ -744,12 +723,11 @@ refined_string_exprt java_string_library_preprocesst::string_expr_of_function(
744723
code_blockt &code)
745724
{
746725
// int return_code;
747-
const symbolt &return_code_sym = get_fresh_aux_symbol(
726+
const symbolt return_code_sym = fresh_java_symbol(
748727
java_int_type(),
749728
std::string("return_code_") + function_id.c_str(),
750-
std::string("return_code_") + function_id.c_str(),
751729
loc,
752-
ID_java,
730+
function_id,
753731
symbol_table);
754732
const auto return_code = return_code_sym.symbol_expr();
755733
code.add(code_declt(return_code), loc);
@@ -1210,8 +1188,8 @@ java_string_library_preprocesst::get_primitive_value_of_object(
12101188

12111189
// declare tmp_type_name to hold the value
12121190
const std::string aux_name = "tmp_" + id2string(type_name);
1213-
const symbolt &symbol = get_fresh_aux_symbol(
1214-
value_type, aux_name, aux_name, loc, ID_java, symbol_table);
1191+
const symbolt &symbol =
1192+
fresh_java_symbol(value_type, aux_name, loc, function_id, symbol_table);
12151193
const auto value = symbol.symbol_expr();
12161194

12171195
// Check that the type of the object is in the symbol table,
@@ -1316,8 +1294,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13161294
if(name!="string_expr")
13171295
{
13181296
std::string tmp_name="tmp_"+id2string(name);
1319-
const symbolt &field_symbol = get_fresh_aux_symbol(
1320-
type, id2string(function_id), tmp_name, loc, ID_java, symbol_table);
1297+
const symbolt &field_symbol =
1298+
fresh_java_symbol(type, tmp_name, loc, function_id, symbol_table);
13211299
auto field_symbol_expr = field_symbol.symbol_expr();
13221300
field_expr = field_symbol_expr;
13231301
code.add(code_declt(field_symbol_expr), loc);
@@ -1332,13 +1310,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13321310

13331311
// arg_i = argv[index]
13341312
const exprt obj = get_object_at_index(argv, index);
1335-
const symbolt &object_symbol = get_fresh_aux_symbol(
1336-
obj.type(),
1337-
id2string(function_id),
1338-
"tmp_format_obj",
1339-
loc,
1340-
ID_java,
1341-
symbol_table);
1313+
const symbolt &object_symbol = fresh_java_symbol(
1314+
obj.type(), "tmp_format_obj", loc, function_id, symbol_table);
13421315
const symbol_exprt arg_i = object_symbol.symbol_expr();
13431316

13441317
allocate_objectst allocate_objects(ID_java, loc, function_id, symbol_table);
@@ -1483,8 +1456,8 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
14831456
// > Class class1;
14841457
const pointer_typet class_type =
14851458
java_reference_type(symbol_table.lookup_ref("java::java.lang.Class").type);
1486-
const symbolt &class1_sym = get_fresh_aux_symbol(
1487-
class_type, "class_symbol", "class_symbol", loc, ID_java, symbol_table);
1459+
const symbolt &class1_sym = fresh_java_symbol(
1460+
class_type, "class_symbol", loc, function_id, symbol_table);
14881461
const symbol_exprt class1 = class1_sym.symbol_expr();
14891462
code.add(code_declt(class1), loc);
14901463

jbmc/src/java_bytecode/java_utils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include "java_root_class.h"
1212

13+
#include <util/fresh_symbol.h>
1314
#include <util/invariant.h>
1415
#include <util/mathematical_expr.h>
1516
#include <util/message.h>
@@ -433,3 +434,23 @@ const std::unordered_set<std::string> cprover_methods_to_ignore
433434
"endThread",
434435
"getCurrentThreadID"
435436
};
437+
438+
/// \param type: type of new symbol
439+
/// \param basename_prefix: new symbol will be named
440+
/// function_name::basename_prefix$num
441+
/// \param source_location: new symbol source loc
442+
/// \param function_name: name of the function in which the symbol is defined
443+
/// \param symbol_table: table to add the new symbol to
444+
/// \return fresh-named symbol with the requested name pattern
445+
symbolt &fresh_java_symbol(
446+
const typet &type,
447+
const std::string &basename_prefix,
448+
const source_locationt &source_location,
449+
const irep_idt &function_name,
450+
symbol_table_baset &symbol_table)
451+
{
452+
PRECONDITION(!function_name.empty());
453+
const std::string name_prefix = id2string(function_name);
454+
return get_fresh_aux_symbol(
455+
type, name_prefix, basename_prefix, source_location, ID_java, symbol_table);
456+
}

jbmc/src/java_bytecode/java_utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ bool is_non_null_library_global(const irep_idt &);
109109

110110
extern const std::unordered_set<std::string> cprover_methods_to_ignore;
111111

112+
symbolt &fresh_java_symbol(
113+
const typet &type,
114+
const std::string &basename_prefix,
115+
const source_locationt &source_location,
116+
const irep_idt &function_name,
117+
symbol_table_baset &symbol_table);
118+
112119
#endif // CPROVER_JAVA_BYTECODE_JAVA_UTILS_H

0 commit comments

Comments
 (0)