Skip to content

Commit c9a44e3

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 2fdf74a commit c9a44e3

10 files changed

+97
-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: 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>
@@ -112,14 +111,12 @@ 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,
116+
"new_exception",
117+
original_loc,
118+
original_loc.get_function(),
119+
symbol_table);
123120

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

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: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,11 @@ symbol_exprt java_string_library_preprocesst::fresh_array(
251251
const source_locationt &location,
252252
symbol_tablet &symbol_table)
253253
{
254-
symbolt array_symbol=get_fresh_aux_symbol(
254+
symbolt array_symbol = fresh_java_symbol(
255255
type,
256256
"cprover_string_array",
257-
"cprover_string_array",
258257
location,
259-
ID_java,
258+
location.get_function(),
260259
symbol_table);
261260
array_symbol.is_static_lifetime=true;
262261
return array_symbol.symbol_expr();
@@ -464,8 +463,8 @@ refined_string_exprt java_string_library_preprocesst::replace_char_array(
464463
checked_dereference(array_pointer, array_pointer.type().subtype());
465464
// array_data is array_pointer-> data
466465
const exprt array_data = get_data(array, symbol_table);
467-
const symbolt &sym_char_array = get_fresh_aux_symbol(
468-
array_data.type(), "char_array", "char_array", loc, ID_java, symbol_table);
466+
const symbolt &sym_char_array = fresh_java_symbol(
467+
array_data.type(), "char_array", loc, loc.get_function(), symbol_table);
469468
const symbol_exprt char_array = sym_char_array.symbol_expr();
470469
// char_array = array_pointer->data
471470
code.add(code_assignt(char_array, array_data), loc);
@@ -496,8 +495,8 @@ symbol_exprt java_string_library_preprocesst::fresh_string(
496495
const irep_idt &function_id,
497496
symbol_table_baset &symbol_table)
498497
{
499-
symbolt string_symbol=get_fresh_aux_symbol(
500-
type, "cprover_string", "cprover_string", loc, ID_java, symbol_table);
498+
symbolt string_symbol =
499+
fresh_java_symbol(type, "cprover_string", loc, function_id, symbol_table);
501500
string_symbol.is_static_lifetime=true;
502501
return string_symbol.symbol_expr();
503502
}
@@ -515,22 +514,12 @@ refined_string_exprt java_string_library_preprocesst::decl_string_expr(
515514
symbol_table_baset &symbol_table,
516515
code_blockt &code)
517516
{
518-
const symbolt &sym_length = get_fresh_aux_symbol(
519-
index_type,
520-
"cprover_string_length",
521-
"cprover_string_length",
522-
loc,
523-
ID_java,
524-
symbol_table);
517+
const symbolt &sym_length = fresh_java_symbol(
518+
index_type, "cprover_string_length", loc, function_id, symbol_table);
525519
const symbol_exprt length_field = sym_length.symbol_expr();
526520
const pointer_typet array_type = pointer_type(java_char_type());
527-
const symbolt &sym_content = get_fresh_aux_symbol(
528-
array_type,
529-
"cprover_string_content",
530-
"cprover_string_content",
531-
loc,
532-
ID_java,
533-
symbol_table);
521+
const symbolt &sym_content = fresh_java_symbol(
522+
array_type, "cprover_string_content", loc, function_id, symbol_table);
534523
const symbol_exprt content_field = sym_content.symbol_expr();
535524
code.add(code_declt(content_field), loc);
536525
const refined_string_exprt str{
@@ -656,12 +645,11 @@ exprt make_nondet_infinite_char_array(
656645
{
657646
const array_typet array_type(
658647
java_char_type(), infinity_exprt(java_int_type()));
659-
const symbolt data_sym = get_fresh_aux_symbol(
648+
const symbolt data_sym = fresh_java_symbol(
660649
pointer_type(array_type),
661-
id2string(function_id),
662650
"nondet_infinite_array_pointer",
663651
loc,
664-
ID_java,
652+
function_id,
665653
symbol_table);
666654

667655
const symbol_exprt data_pointer = data_sym.symbol_expr();
@@ -691,13 +679,8 @@ void add_pointer_to_array_association(
691679
{
692680
PRECONDITION(array.type().id() == ID_array);
693681
PRECONDITION(pointer.type().id() == ID_pointer);
694-
const symbolt &return_sym = get_fresh_aux_symbol(
695-
java_int_type(),
696-
"return_array",
697-
"return_array",
698-
loc,
699-
ID_java,
700-
symbol_table);
682+
const symbolt &return_sym = fresh_java_symbol(
683+
java_int_type(), "return_array", loc, function_id, symbol_table);
701684
const auto return_expr = return_sym.symbol_expr();
702685
code.add(code_declt(return_expr), loc);
703686
code.add(
@@ -725,13 +708,8 @@ void add_array_to_length_association(
725708
const irep_idt &function_id,
726709
code_blockt &code)
727710
{
728-
const symbolt &return_sym = get_fresh_aux_symbol(
729-
java_int_type(),
730-
"return_array",
731-
"return_array",
732-
loc,
733-
ID_java,
734-
symbol_table);
711+
const symbolt &return_sym = fresh_java_symbol(
712+
java_int_type(), "return_array", loc, function_id, symbol_table);
735713
const auto return_expr = return_sym.symbol_expr();
736714
code.add(code_declt(return_expr), loc);
737715
code.add(
@@ -762,8 +740,8 @@ void add_character_set_constraint(
762740
code_blockt &code)
763741
{
764742
PRECONDITION(pointer.type().id() == ID_pointer);
765-
const symbolt &return_sym = get_fresh_aux_symbol(
766-
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
743+
const symbolt &return_sym = fresh_java_symbol(
744+
java_int_type(), "cnstr_added", loc, loc.get_function(), symbol_table);
767745
const auto return_expr = return_sym.symbol_expr();
768746
code.add(code_declt(return_expr), loc);
769747
const constant_exprt char_set_expr(char_set, string_typet());
@@ -800,12 +778,11 @@ refined_string_exprt java_string_library_preprocesst::string_expr_of_function(
800778
code_blockt &code)
801779
{
802780
// int return_code;
803-
const symbolt &return_code_sym = get_fresh_aux_symbol(
781+
const symbolt return_code_sym = fresh_java_symbol(
804782
java_int_type(),
805783
std::string("return_code_") + function_id.c_str(),
806-
std::string("return_code_") + function_id.c_str(),
807784
loc,
808-
ID_java,
785+
function_id,
809786
symbol_table);
810787
const auto return_code = return_code_sym.symbol_expr();
811788
code.add(code_declt(return_code), loc);
@@ -1265,8 +1242,8 @@ java_string_library_preprocesst::get_primitive_value_of_object(
12651242

12661243
// declare tmp_type_name to hold the value
12671244
const std::string aux_name = "tmp_" + id2string(type_name);
1268-
const symbolt &symbol = get_fresh_aux_symbol(
1269-
value_type, aux_name, aux_name, loc, ID_java, symbol_table);
1245+
const symbolt &symbol = fresh_java_symbol(
1246+
value_type, aux_name, loc, loc.get_function(), symbol_table);
12701247
const auto value = symbol.symbol_expr();
12711248

12721249
// Check that the type of the object is in the symbol table,
@@ -1371,8 +1348,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13711348
if(name!="string_expr")
13721349
{
13731350
std::string tmp_name="tmp_"+id2string(name);
1374-
const symbolt &field_symbol = get_fresh_aux_symbol(
1375-
type, id2string(function_id), tmp_name, loc, ID_java, symbol_table);
1351+
const symbolt &field_symbol = fresh_java_symbol(
1352+
type, tmp_name, loc, loc.get_function(), symbol_table);
13761353
auto field_symbol_expr = field_symbol.symbol_expr();
13771354
field_expr = field_symbol_expr;
13781355
code.add(code_declt(field_symbol_expr), loc);
@@ -1387,13 +1364,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13871364

13881365
// arg_i = argv[index]
13891366
const exprt obj = get_object_at_index(argv, index);
1390-
const symbolt &object_symbol = get_fresh_aux_symbol(
1391-
obj.type(),
1392-
id2string(function_id),
1393-
"tmp_format_obj",
1394-
loc,
1395-
ID_java,
1396-
symbol_table);
1367+
const symbolt &object_symbol = fresh_java_symbol(
1368+
obj.type(), "tmp_format_obj", loc, loc.get_function(), symbol_table);
13971369
const symbol_exprt arg_i = object_symbol.symbol_expr();
13981370

13991371
allocate_objectst allocate_objects(ID_java, loc, function_id, symbol_table);
@@ -1538,8 +1510,8 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
15381510
// > Class class1;
15391511
const pointer_typet class_type =
15401512
java_reference_type(symbol_table.lookup_ref("java::java.lang.Class").type);
1541-
const symbolt &class1_sym = get_fresh_aux_symbol(
1542-
class_type, "class_symbol", "class_symbol", loc, ID_java, symbol_table);
1513+
const symbolt &class1_sym = fresh_java_symbol(
1514+
class_type, "class_symbol", loc, loc.get_function(), symbol_table);
15431515
const symbol_exprt class1 = class1_sym.symbol_expr();
15441516
code.add(code_declt(class1), loc);
15451517

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)