Skip to content

Commit cad1a55

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 b855ddd commit cad1a55

10 files changed

+98
-122
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.
@@ -116,12 +116,11 @@ 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(
119+
symbolt &aux_symbol = fresh_java_symbol(
120120
op.type(),
121-
id2string(function_identifier),
122121
"nondet_tmp",
123122
source_loc,
124-
ID_java,
123+
goto_programt::get_function_id(goto_program),
125124
symbol_table);
126125

127126
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(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: 29 additions & 57 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);
@@ -501,8 +500,8 @@ symbol_exprt java_string_library_preprocesst::fresh_string(
501500
const irep_idt &function_name,
502501
symbol_table_baset &symbol_table)
503502
{
504-
symbolt string_symbol=get_fresh_aux_symbol(
505-
type, "cprover_string", "cprover_string", loc, ID_java, symbol_table);
503+
symbolt string_symbol =
504+
fresh_java_symbol(type, "cprover_string", loc, function_name, symbol_table);
506505
string_symbol.is_static_lifetime=true;
507506
return string_symbol.symbol_expr();
508507
}
@@ -520,22 +519,12 @@ refined_string_exprt java_string_library_preprocesst::decl_string_expr(
520519
symbol_table_baset &symbol_table,
521520
code_blockt &code)
522521
{
523-
const symbolt sym_length = get_fresh_aux_symbol(
524-
index_type,
525-
"cprover_string_length",
526-
"cprover_string_length",
527-
loc,
528-
ID_java,
529-
symbol_table);
522+
const symbolt sym_length = fresh_java_symbol(
523+
index_type, "cprover_string_length", loc, function_name, symbol_table);
530524
const symbol_exprt length_field = sym_length.symbol_expr();
531525
const pointer_typet array_type = pointer_type(java_char_type());
532-
const symbolt sym_content = get_fresh_aux_symbol(
533-
array_type,
534-
"cprover_string_content",
535-
"cprover_string_content",
536-
loc,
537-
ID_java,
538-
symbol_table);
526+
const symbolt sym_content = fresh_java_symbol(
527+
array_type, "cprover_string_content", loc, function_name, symbol_table);
539528
const symbol_exprt content_field = sym_content.symbol_expr();
540529
code.add(code_declt(content_field), loc);
541530
const refined_string_exprt str(
@@ -559,7 +548,7 @@ refined_string_exprt java_string_library_preprocesst::make_nondet_string_expr(
559548
{
560549
/// \todo refactor with initialize_nonddet_string_struct
561550
const refined_string_exprt str =
562-
decl_string_expr(loc, loc.get_function(), symbol_table, code);
551+
decl_string_expr(loc, function_id, symbol_table, code);
563552

564553
const side_effect_expr_nondett nondet_length(str.length().type(), loc);
565554
code.add(code_assignt(str.length(), nondet_length), loc);
@@ -661,12 +650,11 @@ exprt make_nondet_infinite_char_array(
661650
{
662651
const array_typet array_type(
663652
java_char_type(), infinity_exprt(java_int_type()));
664-
const symbolt data_sym = get_fresh_aux_symbol(
653+
const symbolt data_sym = fresh_java_symbol(
665654
pointer_type(array_type),
666-
id2string(function_id),
667655
"nondet_infinite_array_pointer",
668656
loc,
669-
ID_java,
657+
function_id,
670658
symbol_table);
671659

672660
const symbol_exprt data_pointer = data_sym.symbol_expr();
@@ -696,13 +684,8 @@ void add_pointer_to_array_association(
696684
{
697685
PRECONDITION(array.type().id() == ID_array);
698686
PRECONDITION(pointer.type().id() == ID_pointer);
699-
const symbolt &return_sym = get_fresh_aux_symbol(
700-
java_int_type(),
701-
"return_array",
702-
"return_array",
703-
loc,
704-
ID_java,
705-
symbol_table);
687+
const symbolt &return_sym = fresh_java_symbol(
688+
java_int_type(), "return_array", loc, function_name, symbol_table);
706689
const auto return_expr = return_sym.symbol_expr();
707690
code.add(code_declt(return_expr), loc);
708691
code.add(
@@ -730,13 +713,8 @@ void add_array_to_length_association(
730713
const irep_idt &function_name,
731714
code_blockt &code)
732715
{
733-
const symbolt &return_sym = get_fresh_aux_symbol(
734-
java_int_type(),
735-
"return_array",
736-
"return_array",
737-
loc,
738-
ID_java,
739-
symbol_table);
716+
const symbolt &return_sym = fresh_java_symbol(
717+
java_int_type(), "return_array", loc, function_name, symbol_table);
740718
const auto return_expr = return_sym.symbol_expr();
741719
code.add(code_declt(return_expr), loc);
742720
code.add(
@@ -767,8 +745,8 @@ void add_character_set_constraint(
767745
code_blockt &code)
768746
{
769747
PRECONDITION(pointer.type().id() == ID_pointer);
770-
const symbolt &return_sym = get_fresh_aux_symbol(
771-
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
748+
const symbolt &return_sym = fresh_java_symbol(
749+
java_int_type(), "cnstr_added", loc, loc.get_function(), symbol_table);
772750
const auto return_expr = return_sym.symbol_expr();
773751
code.add(code_declt(return_expr), loc);
774752
const constant_exprt char_set_expr(char_set, string_typet());
@@ -805,12 +783,11 @@ refined_string_exprt java_string_library_preprocesst::string_expr_of_function(
805783
code_blockt &code)
806784
{
807785
// int return_code;
808-
const symbolt return_code_sym = get_fresh_aux_symbol(
786+
const symbolt return_code_sym = fresh_java_symbol(
809787
java_int_type(),
810788
std::string("return_code_") + function_name.c_str(),
811-
std::string("return_code_") + function_name.c_str(),
812789
loc,
813-
ID_java,
790+
function_name,
814791
symbol_table);
815792
const auto return_code = return_code_sym.symbol_expr();
816793
code.add(code_declt(return_code), loc);
@@ -1272,8 +1249,8 @@ java_string_library_preprocesst::get_primitive_value_of_object(
12721249

12731250
// declare tmp_type_name to hold the value
12741251
const std::string aux_name = "tmp_" + id2string(type_name);
1275-
const symbolt symbol = get_fresh_aux_symbol(
1276-
value_type, aux_name, aux_name, loc, ID_java, symbol_table);
1252+
const symbolt symbol = fresh_java_symbol(
1253+
value_type, aux_name, loc, loc.get_function(), symbol_table);
12771254
const auto value = symbol.symbol_expr();
12781255

12791256
// Check that the type of the object is in the symbol table,
@@ -1378,8 +1355,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13781355
if(name!="string_expr")
13791356
{
13801357
std::string tmp_name="tmp_"+id2string(name);
1381-
symbolt field_symbol = get_fresh_aux_symbol(
1382-
type, id2string(function_id), tmp_name, loc, ID_java, symbol_table);
1358+
symbolt field_symbol = fresh_java_symbol(
1359+
type, tmp_name, loc, loc.get_function(), symbol_table);
13831360
auto field_symbol_expr = field_symbol.symbol_expr();
13841361
field_expr = field_symbol_expr;
13851362
code.add(code_declt(field_symbol_expr), loc);
@@ -1394,13 +1371,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13941371

13951372
// arg_i = argv[index]
13961373
const exprt obj = get_object_at_index(argv, index);
1397-
const symbolt object_symbol = get_fresh_aux_symbol(
1398-
obj.type(),
1399-
id2string(function_id),
1400-
"tmp_format_obj",
1401-
loc,
1402-
ID_java,
1403-
symbol_table);
1374+
const symbolt object_symbol = fresh_java_symbol(
1375+
obj.type(), "tmp_format_obj", loc, loc.get_function(), symbol_table);
14041376
const symbol_exprt arg_i = object_symbol.symbol_expr();
14051377

14061378
allocate_objectst allocate_objects(ID_java, loc, function_id, symbol_table);
@@ -1545,8 +1517,8 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
15451517
// > Class class1;
15461518
const pointer_typet class_type =
15471519
java_reference_type(symbol_table.lookup_ref("java::java.lang.Class").type);
1548-
const symbolt class1_sym = get_fresh_aux_symbol(
1549-
class_type, "class_symbol", "class_symbol", loc, ID_java, symbol_table);
1520+
const symbolt class1_sym = fresh_java_symbol(
1521+
class_type, "class_symbol", loc, loc.get_function(), symbol_table);
15501522
const symbol_exprt class1 = class1_sym.symbol_expr();
15511523
code.add(code_declt(class1), loc);
15521524

jbmc/src/java_bytecode/java_utils.cpp

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

2020
#include <set>
2121
#include <unordered_set>
22+
#include <util/fresh_symbol.h>
2223

2324
bool java_is_array_type(const typet &type)
2425
{
@@ -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)