Skip to content

Commit d917737

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 453c2f9 commit d917737

10 files changed

+98
-126
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: 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();
@@ -463,8 +462,8 @@ refined_string_exprt java_string_library_preprocesst::replace_char_array(
463462
checked_dereference(array_pointer, array_pointer.type().subtype());
464463
// array_data is array_pointer-> data
465464
const exprt array_data = get_data(array, symbol_table);
466-
const symbolt sym_char_array = get_fresh_aux_symbol(
467-
array_data.type(), "char_array", "char_array", loc, ID_java, symbol_table);
465+
const symbolt sym_char_array = fresh_java_symbol(
466+
array_data.type(), "char_array", loc, loc.get_function(), symbol_table);
468467
const symbol_exprt char_array = sym_char_array.symbol_expr();
469468
// char_array = array_pointer->data
470469
code.add(code_assignt(char_array, array_data), loc);
@@ -500,8 +499,8 @@ symbol_exprt java_string_library_preprocesst::fresh_string(
500499
const irep_idt &function_name,
501500
symbol_table_baset &symbol_table)
502501
{
503-
symbolt string_symbol=get_fresh_aux_symbol(
504-
type, "cprover_string", "cprover_string", loc, ID_java, symbol_table);
502+
symbolt string_symbol =
503+
fresh_java_symbol(type, "cprover_string", loc, function_name, symbol_table);
505504
string_symbol.is_static_lifetime=true;
506505
return string_symbol.symbol_expr();
507506
}
@@ -519,22 +518,12 @@ refined_string_exprt java_string_library_preprocesst::decl_string_expr(
519518
symbol_table_baset &symbol_table,
520519
code_blockt &code)
521520
{
522-
const symbolt sym_length = get_fresh_aux_symbol(
523-
index_type,
524-
"cprover_string_length",
525-
"cprover_string_length",
526-
loc,
527-
ID_java,
528-
symbol_table);
521+
const symbolt sym_length = fresh_java_symbol(
522+
index_type, "cprover_string_length", loc, function_name, symbol_table);
529523
const symbol_exprt length_field = sym_length.symbol_expr();
530524
const pointer_typet array_type = pointer_type(java_char_type());
531-
const symbolt sym_content = get_fresh_aux_symbol(
532-
array_type,
533-
"cprover_string_content",
534-
"cprover_string_content",
535-
loc,
536-
ID_java,
537-
symbol_table);
525+
const symbolt sym_content = fresh_java_symbol(
526+
array_type, "cprover_string_content", loc, function_name, symbol_table);
538527
const symbol_exprt content_field = sym_content.symbol_expr();
539528
code.add(code_declt(content_field), loc);
540529
const refined_string_exprt str(
@@ -558,7 +547,7 @@ refined_string_exprt java_string_library_preprocesst::make_nondet_string_expr(
558547
{
559548
/// \todo refactor with initialize_nonddet_string_struct
560549
const refined_string_exprt str =
561-
decl_string_expr(loc, loc.get_function(), symbol_table, code);
550+
decl_string_expr(loc, function_id, symbol_table, code);
562551

563552
const side_effect_expr_nondett nondet_length(str.length().type(), loc);
564553
code.add(code_assignt(str.length(), nondet_length), loc);
@@ -660,12 +649,11 @@ exprt make_nondet_infinite_char_array(
660649
{
661650
const array_typet array_type(
662651
java_char_type(), infinity_exprt(java_int_type()));
663-
const symbolt data_sym = get_fresh_aux_symbol(
652+
const symbolt data_sym = fresh_java_symbol(
664653
pointer_type(array_type),
665-
id2string(function_id),
666654
"nondet_infinite_array_pointer",
667655
loc,
668-
ID_java,
656+
function_id,
669657
symbol_table);
670658

671659
const symbol_exprt data_pointer = data_sym.symbol_expr();
@@ -695,13 +683,8 @@ void add_pointer_to_array_association(
695683
{
696684
PRECONDITION(array.type().id() == ID_array);
697685
PRECONDITION(pointer.type().id() == ID_pointer);
698-
const symbolt &return_sym = get_fresh_aux_symbol(
699-
java_int_type(),
700-
"return_array",
701-
"return_array",
702-
loc,
703-
ID_java,
704-
symbol_table);
686+
const symbolt &return_sym = fresh_java_symbol(
687+
java_int_type(), "return_array", loc, function_name, symbol_table);
705688
const auto return_expr = return_sym.symbol_expr();
706689
code.add(code_declt(return_expr), loc);
707690
code.add(
@@ -729,13 +712,8 @@ void add_array_to_length_association(
729712
const irep_idt &function_name,
730713
code_blockt &code)
731714
{
732-
const symbolt &return_sym = get_fresh_aux_symbol(
733-
java_int_type(),
734-
"return_array",
735-
"return_array",
736-
loc,
737-
ID_java,
738-
symbol_table);
715+
const symbolt &return_sym = fresh_java_symbol(
716+
java_int_type(), "return_array", loc, function_name, symbol_table);
739717
const auto return_expr = return_sym.symbol_expr();
740718
code.add(code_declt(return_expr), loc);
741719
code.add(
@@ -766,8 +744,8 @@ void add_character_set_constraint(
766744
code_blockt &code)
767745
{
768746
PRECONDITION(pointer.type().id() == ID_pointer);
769-
const symbolt &return_sym = get_fresh_aux_symbol(
770-
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
747+
const symbolt &return_sym = fresh_java_symbol(
748+
java_int_type(), "cnstr_added", loc, loc.get_function(), symbol_table);
771749
const auto return_expr = return_sym.symbol_expr();
772750
code.add(code_declt(return_expr), loc);
773751
const constant_exprt char_set_expr(char_set, string_typet());
@@ -804,12 +782,11 @@ refined_string_exprt java_string_library_preprocesst::string_expr_of_function(
804782
code_blockt &code)
805783
{
806784
// int return_code;
807-
const symbolt return_code_sym = get_fresh_aux_symbol(
785+
const symbolt return_code_sym = fresh_java_symbol(
808786
java_int_type(),
809787
std::string("return_code_") + function_name.c_str(),
810-
std::string("return_code_") + function_name.c_str(),
811788
loc,
812-
ID_java,
789+
function_name,
813790
symbol_table);
814791
const auto return_code = return_code_sym.symbol_expr();
815792
code.add(code_declt(return_code), loc);
@@ -1271,8 +1248,8 @@ java_string_library_preprocesst::get_primitive_value_of_object(
12711248

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

12781255
// Check that the type of the object is in the symbol table,
@@ -1377,8 +1354,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13771354
if(name!="string_expr")
13781355
{
13791356
std::string tmp_name="tmp_"+id2string(name);
1380-
symbolt field_symbol = get_fresh_aux_symbol(
1381-
type, id2string(function_id), tmp_name, loc, ID_java, symbol_table);
1357+
symbolt field_symbol = fresh_java_symbol(
1358+
type, tmp_name, loc, loc.get_function(), symbol_table);
13821359
auto field_symbol_expr = field_symbol.symbol_expr();
13831360
field_expr = field_symbol_expr;
13841361
code.add(code_declt(field_symbol_expr), loc);
@@ -1393,13 +1370,8 @@ struct_exprt java_string_library_preprocesst::make_argument_for_format(
13931370

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

14051377
allocate_objectst allocate_objects(ID_java, loc, function_id, symbol_table);
@@ -1544,8 +1516,8 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
15441516
// > Class class1;
15451517
const pointer_typet class_type =
15461518
java_reference_type(symbol_table.lookup_ref("java::java.lang.Class").type);
1547-
const symbolt class1_sym = get_fresh_aux_symbol(
1548-
class_type, "class_symbol", "class_symbol", loc, ID_java, symbol_table);
1519+
const symbolt class1_sym = fresh_java_symbol(
1520+
class_type, "class_symbol", loc, loc.get_function(), symbol_table);
15491521
const symbol_exprt class1 = class1_sym.symbol_expr();
15501522
code.add(code_declt(class1), loc);
15511523

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)