Skip to content

Commit c9af02f

Browse files
committed
Java front-end and allocate objects: reduce reliance on goto code types
Code that deals with symbol tables only should not create codet structures defined in goto-programs/goto_instruction_code.h. code_function_callt remains in place as an exception to this rule as the Java front-end wide relies on it.
1 parent 8b1b869 commit c9af02f

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

jbmc/src/java_bytecode/assignments_from_json.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Diffblue Ltd.
1717

1818
#include <goto-programs/allocate_objects.h>
1919
#include <goto-programs/class_identifier.h>
20+
#include <goto-programs/goto_instruction_code.h>
2021

2122
#include <util/arith_tools.h>
2223
#include <util/array_element_from_pointer.h>
@@ -345,43 +346,44 @@ assign_primitive_from_json(const exprt &expr, const jsont &json)
345346
return result;
346347
if(expr.type() == java_boolean_type())
347348
{
348-
result.add(code_assignt{
349+
result.add(code_frontend_assignt{
349350
expr, json.is_true() ? (exprt)true_exprt{} : (exprt)false_exprt{}});
350351
}
351352
else if(
352353
expr.type() == java_int_type() || expr.type() == java_byte_type() ||
353354
expr.type() == java_short_type() || expr.type() == java_long_type())
354355
{
355-
result.add(
356-
code_assignt{expr, from_integer(std::stoll(json.value), expr.type())});
356+
result.add(code_frontend_assignt{
357+
expr, from_integer(std::stoll(json.value), expr.type())});
357358
}
358359
else if(expr.type() == java_double_type())
359360
{
360361
ieee_floatt ieee_float(to_floatbv_type(expr.type()));
361362
ieee_float.from_double(std::stod(json.value));
362-
result.add(code_assignt{expr, ieee_float.to_expr()});
363+
result.add(code_frontend_assignt{expr, ieee_float.to_expr()});
363364
}
364365
else if(expr.type() == java_float_type())
365366
{
366367
ieee_floatt ieee_float(to_floatbv_type(expr.type()));
367368
ieee_float.from_float(std::stof(json.value));
368-
result.add(code_assignt{expr, ieee_float.to_expr()});
369+
result.add(code_frontend_assignt{expr, ieee_float.to_expr()});
369370
}
370371
else if(expr.type() == java_char_type())
371372
{
372373
const std::wstring wide_value = utf8_to_utf16_native_endian(json.value);
373374
PRECONDITION(wide_value.length() == 1);
374-
result.add(
375-
code_assignt{expr, from_integer(wide_value.front(), expr.type())});
375+
result.add(code_frontend_assignt{
376+
expr, from_integer(wide_value.front(), expr.type())});
376377
}
377378
return result;
378379
}
379380

380381
/// One of the base cases of the recursive algorithm. See
381382
/// \ref assign_from_json_rec.
382-
static code_assignt assign_null(const exprt &expr)
383+
static code_frontend_assignt assign_null(const exprt &expr)
383384
{
384-
return code_assignt{expr, null_pointer_exprt{to_pointer_type(expr.type())}};
385+
return code_frontend_assignt{
386+
expr, null_pointer_exprt{to_pointer_type(expr.type())}};
385387
}
386388

387389
/// In the case of an assignment of an array given a JSON representation, this
@@ -405,7 +407,8 @@ static code_with_references_listt assign_array_data_component_from_json(
405407
info.allocate_objects.allocate_automatic_local_object(
406408
data_member_expr.type(), "user_specified_array_data_init");
407409
code_with_references_listt result;
408-
result.add(code_assignt{array_init_data, data_member_expr, info.loc});
410+
result.add(
411+
code_frontend_assignt{array_init_data, data_member_expr, info.loc});
409412

410413
size_t index = 0;
411414
const optionalt<std::string> inferred_element_type =
@@ -432,8 +435,8 @@ nondet_length(allocate_objectst &allocate, source_locationt loc)
432435
symbol_exprt length_expr = allocate.allocate_automatic_local_object(
433436
java_int_type(), "user_specified_array_length");
434437
code_with_references_listt code;
435-
code.add(
436-
code_assignt{length_expr, side_effect_expr_nondett{java_int_type(), loc}});
438+
code.add(code_frontend_assignt{
439+
length_expr, side_effect_expr_nondett{java_int_type(), loc}});
437440
code.add(code_assumet{binary_predicate_exprt{
438441
length_expr, ID_ge, from_integer(0, java_int_type())}});
439442
return std::make_pair(length_expr, std::move(code));
@@ -506,16 +509,16 @@ static code_with_references_listt assign_nondet_length_array_from_json(
506509
/// One of the cases in the recursive algorithm: the case where \p expr
507510
/// represents a string.
508511
/// See \ref assign_from_json_rec.
509-
static code_assignt assign_string_from_json(
512+
static code_frontend_assignt assign_string_from_json(
510513
const jsont &json,
511514
const exprt &expr,
512515
object_creation_infot &info)
513516
{
514517
const auto json_string = get_untyped_string(json);
515518
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)};
519+
return code_frontend_assignt{expr,
520+
get_or_create_string_literal_symbol(
521+
json_string.value, info.symbol_table, true)};
519522
}
520523

521524
/// Helper function for \ref assign_struct_from_json which recursively assigns
@@ -586,7 +589,7 @@ static code_with_references_listt assign_struct_from_json(
586589
to_struct_expr(*initial_object),
587590
ns,
588591
struct_tag_typet("java::" + id2string(java_class_type.get_tag())));
589-
result.add(code_assignt{expr, *initial_object});
592+
result.add(code_frontend_assignt{expr, *initial_object});
590593
result.append(assign_struct_components_from_json(expr, json, info));
591594
}
592595
return result;
@@ -646,7 +649,7 @@ static code_with_references_listt assign_enum_from_json(
646649
const exprt ordinal_expr =
647650
from_integer(std::stoi(json["ordinal"].value), java_int_type());
648651

649-
result.add(code_assignt{
652+
result.add(code_frontend_assignt{
650653
expr,
651654
typecast_exprt::conditional_cast(
652655
array_element_from_pointer(values_data, ordinal_expr), expr.type())});
@@ -696,7 +699,8 @@ static code_with_references_listt assign_pointer_with_given_type_from_json(
696699
}
697700

698701
auto result = assign_pointer_from_json(new_symbol, json, info);
699-
result.add(code_assignt{expr, typecast_exprt{new_symbol, pointer_type}});
702+
result.add(
703+
code_frontend_assignt{expr, typecast_exprt{new_symbol, pointer_type}});
700704
return result;
701705
}
702706
else
@@ -828,7 +832,7 @@ static code_with_references_listt assign_reference_from_json(
828832
assign_struct_from_json(dereference_exprt(reference.expr), json, info));
829833
}
830834
}
831-
result.add(code_assignt{
835+
result.add(code_frontend_assignt{
832836
expr, typecast_exprt::conditional_cast(reference.expr, expr.type())});
833837
return result;
834838
}

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Chris Smowton, [email protected]
1616
#include "java_utils.h"
1717

1818
#include <goto-programs/class_hierarchy.h>
19+
#include <goto-programs/goto_instruction_code.h>
1920

2021
#include <util/arith_tools.h>
2122
#include <util/cprover_prefix.h>
@@ -580,7 +581,7 @@ code_blockt get_thread_safe_clinit_wrapper_body(
580581

581582
// bool init_complete;
582583
{
583-
code_declt decl(init_complete.symbol_expr());
584+
code_frontend_declt decl(init_complete.symbol_expr());
584585
function_body.add(decl);
585586
}
586587

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
@@ -233,7 +235,7 @@ void allocate_objectst::declare_created_symbols(code_blockt &init_code)
233235
const symbolt &symbol = ns.lookup(symbol_id);
234236
if(!symbol.is_static_lifetime)
235237
{
236-
code_declt decl{symbol.symbol_expr()};
238+
code_frontend_declt decl{symbol.symbol_expr()};
237239
decl.add_source_location() = source_location;
238240
init_code.add(decl);
239241
}

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)