Skip to content

Commit 728f30e

Browse files
committed
Java front-end and allocate objects: do not use goto code types
Code that deals with symbol tables only should not create codet structures defined in goto-programs/goto_instruction_code.h.
1 parent 08d5056 commit 728f30e

File tree

6 files changed

+53
-32
lines changed

6 files changed

+53
-32
lines changed

jbmc/src/java_bytecode/assignments_from_json.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -345,43 +345,44 @@ assign_primitive_from_json(const exprt &expr, const jsont &json)
345345
return result;
346346
if(expr.type() == java_boolean_type())
347347
{
348-
result.add(code_assignt{
348+
result.add(code_frontend_assignt{
349349
expr, json.is_true() ? (exprt)true_exprt{} : (exprt)false_exprt{}});
350350
}
351351
else if(
352352
expr.type() == java_int_type() || expr.type() == java_byte_type() ||
353353
expr.type() == java_short_type() || expr.type() == java_long_type())
354354
{
355-
result.add(
356-
code_assignt{expr, from_integer(std::stoll(json.value), expr.type())});
355+
result.add(code_frontend_assignt{
356+
expr, from_integer(std::stoll(json.value), expr.type())});
357357
}
358358
else if(expr.type() == java_double_type())
359359
{
360360
ieee_floatt ieee_float(to_floatbv_type(expr.type()));
361361
ieee_float.from_double(std::stod(json.value));
362-
result.add(code_assignt{expr, ieee_float.to_expr()});
362+
result.add(code_frontend_assignt{expr, ieee_float.to_expr()});
363363
}
364364
else if(expr.type() == java_float_type())
365365
{
366366
ieee_floatt ieee_float(to_floatbv_type(expr.type()));
367367
ieee_float.from_float(std::stof(json.value));
368-
result.add(code_assignt{expr, ieee_float.to_expr()});
368+
result.add(code_frontend_assignt{expr, ieee_float.to_expr()});
369369
}
370370
else if(expr.type() == java_char_type())
371371
{
372372
const std::wstring wide_value = utf8_to_utf16_native_endian(json.value);
373373
PRECONDITION(wide_value.length() == 1);
374-
result.add(
375-
code_assignt{expr, from_integer(wide_value.front(), expr.type())});
374+
result.add(code_frontend_assignt{
375+
expr, from_integer(wide_value.front(), expr.type())});
376376
}
377377
return result;
378378
}
379379

380380
/// One of the base cases of the recursive algorithm. See
381381
/// \ref assign_from_json_rec.
382-
static code_assignt assign_null(const exprt &expr)
382+
static code_frontend_assignt assign_null(const exprt &expr)
383383
{
384-
return code_assignt{expr, null_pointer_exprt{to_pointer_type(expr.type())}};
384+
return code_frontend_assignt{
385+
expr, null_pointer_exprt{to_pointer_type(expr.type())}};
385386
}
386387

387388
/// In the case of an assignment of an array given a JSON representation, this
@@ -405,7 +406,8 @@ static code_with_references_listt assign_array_data_component_from_json(
405406
info.allocate_objects.allocate_automatic_local_object(
406407
data_member_expr.type(), "user_specified_array_data_init");
407408
code_with_references_listt result;
408-
result.add(code_assignt{array_init_data, data_member_expr, info.loc});
409+
result.add(
410+
code_frontend_assignt{array_init_data, data_member_expr, info.loc});
409411

410412
size_t index = 0;
411413
const optionalt<std::string> inferred_element_type =
@@ -432,8 +434,8 @@ nondet_length(allocate_objectst &allocate, source_locationt loc)
432434
symbol_exprt length_expr = allocate.allocate_automatic_local_object(
433435
java_int_type(), "user_specified_array_length");
434436
code_with_references_listt code;
435-
code.add(
436-
code_assignt{length_expr, side_effect_expr_nondett{java_int_type(), loc}});
437+
code.add(code_frontend_assignt{
438+
length_expr, side_effect_expr_nondett{java_int_type(), loc}});
437439
code.add(code_assumet{binary_predicate_exprt{
438440
length_expr, ID_ge, from_integer(0, java_int_type())}});
439441
return std::make_pair(length_expr, std::move(code));
@@ -506,16 +508,16 @@ static code_with_references_listt assign_nondet_length_array_from_json(
506508
/// One of the cases in the recursive algorithm: the case where \p expr
507509
/// represents a string.
508510
/// See \ref assign_from_json_rec.
509-
static code_assignt assign_string_from_json(
511+
static code_frontend_assignt assign_string_from_json(
510512
const jsont &json,
511513
const exprt &expr,
512514
object_creation_infot &info)
513515
{
514516
const auto json_string = get_untyped_string(json);
515517
PRECONDITION(json_string.is_string());
516-
return code_assignt{expr,
517-
get_or_create_string_literal_symbol(
518-
json_string.value, info.symbol_table, true)};
518+
return code_frontend_assignt{expr,
519+
get_or_create_string_literal_symbol(
520+
json_string.value, info.symbol_table, true)};
519521
}
520522

521523
/// Helper function for \ref assign_struct_from_json which recursively assigns
@@ -586,7 +588,7 @@ static code_with_references_listt assign_struct_from_json(
586588
to_struct_expr(*initial_object),
587589
ns,
588590
struct_tag_typet("java::" + id2string(java_class_type.get_tag())));
589-
result.add(code_assignt{expr, *initial_object});
591+
result.add(code_frontend_assignt{expr, *initial_object});
590592
result.append(assign_struct_components_from_json(expr, json, info));
591593
}
592594
return result;
@@ -625,7 +627,10 @@ static code_with_references_listt assign_enum_from_json(
625627
const std::string &enum_name = id2string(java_class_type.get_name());
626628
code_with_references_listt result;
627629
if(const auto func = info.symbol_table.lookup(clinit_wrapper_name(enum_name)))
628-
result.add(code_function_callt{func->symbol_expr()});
630+
{
631+
result.add(code_expressiont{side_effect_expr_function_callt{
632+
func->symbol_expr(), {}, to_code_type(func->type), func->location}});
633+
}
629634

630635
const irep_idt values_name = enum_name + ".$VALUES";
631636
if(!info.symbol_table.has_symbol(values_name))
@@ -646,7 +651,7 @@ static code_with_references_listt assign_enum_from_json(
646651
const exprt ordinal_expr =
647652
from_integer(std::stoi(json["ordinal"].value), java_int_type());
648653

649-
result.add(code_assignt{
654+
result.add(code_frontend_assignt{
650655
expr,
651656
typecast_exprt::conditional_cast(
652657
array_element_from_pointer(values_data, ordinal_expr), expr.type())});
@@ -696,7 +701,8 @@ static code_with_references_listt assign_pointer_with_given_type_from_json(
696701
}
697702

698703
auto result = assign_pointer_from_json(new_symbol, json, info);
699-
result.add(code_assignt{expr, typecast_exprt{new_symbol, pointer_type}});
704+
result.add(
705+
code_frontend_assignt{expr, typecast_exprt{new_symbol, pointer_type}});
700706
return result;
701707
}
702708
else
@@ -828,7 +834,7 @@ static code_with_references_listt assign_reference_from_json(
828834
assign_struct_from_json(dereference_exprt(reference.expr), json, info));
829835
}
830836
}
831-
result.add(code_assignt{
837+
result.add(code_frontend_assignt{
832838
expr, typecast_exprt::conditional_cast(reference.expr, expr.type())});
833839
return result;
834840
}

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,26 @@ static void clinit_wrapper_do_recursive_calls(
244244
const auto base_name = base.type().get_identifier();
245245
irep_idt base_init_routine = clinit_wrapper_name(base_name);
246246
if(const auto base_init_func = symbol_table.lookup(base_init_routine))
247-
init_body.add(code_function_callt{base_init_func->symbol_expr()});
247+
{
248+
init_body.add(code_expressiont{
249+
side_effect_expr_function_callt{base_init_func->symbol_expr(),
250+
{},
251+
to_code_type(base_init_func->type),
252+
base_init_func->location}});
253+
}
248254
}
249255

250256
const irep_idt &clinit_name = replace_clinit
251257
? user_specified_clinit_name(class_name)
252258
: clinit_function_name(class_name);
253259
if(const auto clinit_func = symbol_table.lookup(clinit_name))
254-
init_body.add(code_function_callt{clinit_func->symbol_expr()});
260+
{
261+
init_body.add(code_expressiont{
262+
side_effect_expr_function_callt{clinit_func->symbol_expr(),
263+
{},
264+
to_code_type(clinit_func->type),
265+
clinit_func->location}});
266+
}
255267

256268
// If nondet-static option is given, add a standard nondet initialization for
257269
// each non-final static field of this class. Note this is the same invocation
@@ -580,7 +592,7 @@ code_blockt get_thread_safe_clinit_wrapper_body(
580592

581593
// bool init_complete;
582594
{
583-
code_declt decl(init_complete.symbol_expr());
595+
code_frontend_declt decl(init_complete.symbol_expr());
584596
function_body.add(decl);
585597
}
586598

@@ -855,7 +867,11 @@ code_blockt get_user_specified_clinit_body(
855867
body.append(code_with_ref->to_code(reference_substitution));
856868
return body;
857869
}
858-
return code_blockt{{code_function_callt{clinit_func->symbol_expr()}}};
870+
return code_blockt{{code_expressiont{
871+
side_effect_expr_function_callt{clinit_func->symbol_expr(),
872+
{},
873+
to_code_type(clinit_func->type),
874+
clinit_func->location}}}};
859875
}
860876

861877
/// Create static initializer wrappers and possibly user-specified functions for

jbmc/src/java_bytecode/nondet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ symbol_exprt generate_nondet_int(
4949
// Declare a symbol for the non deterministic integer.
5050
const symbol_exprt &nondet_symbol =
5151
alocate_local_symbol(int_type, basename_prefix);
52-
instructions.add(code_declt(nondet_symbol));
52+
instructions.add(code_frontend_declt(nondet_symbol));
5353

5454
// Assign the symbol any non deterministic integer value.
5555
// int_type name_prefix::nondet_int = NONDET(int_type)

jbmc/src/java_bytecode/simple_method_stubbing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void java_simple_method_stubst::create_method_stub(symbolt &symbol)
188188
symbol.name,
189189
symbol_table);
190190
const symbol_exprt &init_symbol_expression = init_symbol.symbol_expr();
191-
code_assignt get_argument(
191+
code_frontend_assignt get_argument(
192192
init_symbol_expression,
193193
symbol_exprt(this_argument.get_identifier(), this_type));
194194
get_argument.add_source_location() = synthesized_source_location;
@@ -242,7 +242,7 @@ void java_simple_method_stubst::create_method_stub(symbolt &symbol)
242242
0,
243243
false,
244244
false);
245-
new_instructions.add(code_returnt(to_return));
245+
new_instructions.add(code_frontend_returnt(to_return));
246246
}
247247
}
248248

src/goto-programs/allocate_objects.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/pointer_offset_size.h>
1515
#include <util/symbol.h>
1616

17+
#include "goto_instruction_code.h"
18+
1719
/// Allocates a new object, either by creating a local variable with automatic
1820
/// lifetime, a global variable with static lifetime, or by dynamically
1921
/// allocating memory via ALLOCATE(). Code is added to `assignments` which
@@ -232,7 +234,7 @@ void allocate_objectst::declare_created_symbols(code_blockt &init_code)
232234
{
233235
if(!symbol_ptr->is_static_lifetime)
234236
{
235-
code_declt decl(symbol_ptr->symbol_expr());
237+
code_frontend_declt decl(symbol_ptr->symbol_expr());
236238
decl.add_source_location() = source_location;
237239
init_code.add(decl);
238240
}

src/goto-programs/allocate_objects.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_UTIL_ALLOCATE_OBJECTS_H
1010
#define CPROVER_UTIL_ALLOCATE_OBJECTS_H
1111

12-
#include "goto_instruction_code.h"
13-
1412
#include <util/namespace.h>
15-
#include <util/source_location.h>
1613
#include <util/std_code.h>
1714

1815
/// Selects the kind of objects allocated

0 commit comments

Comments
 (0)