Skip to content

Commit d3c0949

Browse files
committed
Restructure code to use constructors and add std::move
This simplifies the code structure and ensures RAII where possible.
1 parent 937d8f3 commit d3c0949

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ static void java_static_lifetime_init(
204204
set_class_identifier(
205205
to_struct_expr(*zero_object), ns, to_symbol_type(sym.type));
206206

207-
code_block.add(code_assignt(sym.symbol_expr(), *zero_object));
207+
code_block.add(
208+
std::move(code_assignt(sym.symbol_expr(), *zero_object)));
208209

209210
// Then call the init function:
210211
code_block.add(std::move(initializer_call));
@@ -762,7 +763,7 @@ bool generate_java_start_function(
762763

763764
// Exceptional return: catch and assign to exc_symbol.
764765
code_landingpadt landingpad(exc_symbol.symbol_expr());
765-
init_code.add(toplevel_catch);
766+
init_code.add(std::move(toplevel_catch));
766767
init_code.add(std::move(landingpad));
767768

768769
// Converge normal and exceptional return:

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,8 @@ code_ifthenelset get_clinit_wrapper_body(
687687
wrapper_body.cond() = check_already_run;
688688

689689
// add the "already-run = false" statement
690-
code_blockt init_body;
691690
code_assignt set_already_run(already_run_symbol.symbol_expr(), true_exprt());
692-
init_body.move(set_already_run);
691+
code_blockt init_body({set_already_run});
693692

694693
clinit_wrapper_do_recursive_calls(
695694
symbol_table,

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
299299
for_body.add(std::move(init_decl));
300300

301301
code_assignt init_subarray(init_sym, sub_java_new);
302+
for_body.add(std::move(init_subarray));
302303
code_assignt assign_subarray(
303304
deref_expr, typecast_exprt(init_sym, deref_expr.type()));
304-
for_body.move(init_subarray);
305305
for_body.add(std::move(assign_subarray));
306306

307307
for_loop.init() = code_assignt(tmp_i, from_integer(0, tmp_i.type()));

src/cpp/cpp_constructor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
192192
side_effect_exprt assign(ID_assign, typet(), source_location);
193193
assign.move_to_operands(member, val);
194194
typecheck_side_effect_assignment(assign);
195-
code_expressiont code_exp(assign);
196-
block.move(code_exp);
195+
block.add(std::move(code_expressiont(assign)));
197196
}
198197

199198
// enter struct scope

src/util/nondet.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ code_blockt generate_nondet_switch(
9595
if(switch_cases.size() == 1)
9696
return code_blockt({switch_cases[0]});
9797

98-
code_switcht result_switch;
9998
code_blockt result_block;
10099

101100
const symbol_exprt &switch_value = generate_nondet_int(
@@ -108,23 +107,20 @@ code_blockt generate_nondet_switch(
108107
symbol_table,
109108
result_block);
110109

111-
result_switch.value() = switch_value;
112-
113110
code_blockt switch_block;
114111
size_t case_number = 0;
115112
for(const auto &switch_case : switch_cases)
116113
{
117114
code_blockt this_block;
118115
this_block.add(switch_case);
119116
this_block.add(code_breakt());
120-
code_switch_caset this_case;
121-
this_case.case_op() = from_integer(case_number, switch_value.type());
122-
this_case.code() = this_block;
123-
switch_block.move(this_case);
117+
code_switch_caset this_case(
118+
from_integer(case_number, switch_value.type()), this_block);
119+
switch_block.add(std::move(this_case));
124120
++case_number;
125121
}
126122

127-
result_switch.body() = switch_block;
123+
code_switcht result_switch(switch_value, switch_block);
128124
result_block.add(std::move(result_switch));
129125
return result_block;
130126
}

0 commit comments

Comments
 (0)