Skip to content

Commit 2dc37a8

Browse files
committed
Use constructors to construct objects
This is some drive-by cleanup resulting from reviewing #3067. Instead of incrementally constructing objects do RAII.
1 parent aca054f commit 2dc37a8

File tree

5 files changed

+20
-32
lines changed

5 files changed

+20
-32
lines changed

jbmc/src/java_bytecode/java_bytecode_concurrency_instrumentation.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void instrument_start_thread(
288288

289289
// Create global variable __CPROVER__next_thread_id. Used as a counter
290290
// in-order to to assign ids to new threads.
291-
const symbolt &next_symbol =
291+
const symbol_exprt next_symbol_expr =
292292
add_or_get_symbol(
293293
symbol_table, next_thread_id, next_thread_id,
294294
java_int_type(),
@@ -320,14 +320,11 @@ static void instrument_start_thread(
320320
codet tmp_a(ID_start_thread);
321321
tmp_a.set(ID_destination, lbl1);
322322
code_gotot tmp_b(lbl2);
323-
code_labelt tmp_c(lbl1);
324-
tmp_c.op0() = codet(ID_skip);
323+
const code_labelt tmp_c(lbl1, codet(ID_skip));
325324

326-
exprt plus(ID_plus, java_int_type());
327-
plus.copy_to_operands(next_symbol.symbol_expr());
328-
plus.copy_to_operands(from_integer(1, java_int_type()));
329-
code_assignt tmp_d(next_symbol.symbol_expr(), plus);
330-
code_assignt tmp_e(current_symbol.symbol_expr(), next_symbol.symbol_expr());
325+
const plus_exprt plus(next_symbol_expr, from_integer(1, java_int_type()));
326+
const code_assignt tmp_d(next_symbol_expr, plus);
327+
const code_assignt tmp_e(current_symbol.symbol_expr(), next_symbol_expr);
331328

332329
code_blockt block;
333330
block.add(tmp_a);
@@ -368,8 +365,7 @@ static void instrument_end_thread(
368365
// A: codet(id=ID_end_thread)
369366
// B: codet(id=ID_label,label= __CPROVER_THREAD_EXIT_<ID>)
370367
codet tmp_a(ID_end_thread);
371-
code_labelt tmp_b(lbl2);
372-
tmp_b.op0() = codet(ID_skip);
368+
const code_labelt tmp_b(lbl2, codet(ID_skip));
373369

374370
code_blockt block;
375371
block.add(tmp_a);

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
17421742
for(auto &expr : stack)
17431743
{
17441744
assert(has_prefix(os_it->get_string(ID_C_base_name), "$stack"));
1745-
symbol_exprt lhs=to_symbol_expr(*os_it);
1745+
const symbol_exprt &lhs = to_symbol_expr(*os_it);
17461746
code_assignt a(lhs, expr);
17471747
more_code.copy_to_operands(a);
17481748

@@ -2737,13 +2737,11 @@ codet java_bytecode_convert_methodt::convert_iinc(
27372737
bytecode_write_typet::VARIABLE,
27382738
to_symbol_expr(locvar).get_identifier());
27392739

2740-
code_assignt code_assign;
2741-
code_assign.lhs() = variable(arg0, 'i', address, NO_CAST);
2742-
exprt arg1_int_type = arg1;
2743-
if(arg1.type() != java_int_type())
2744-
arg1_int_type.make_typecast(java_int_type());
2745-
code_assign.rhs() =
2746-
plus_exprt(variable(arg0, 'i', address, CAST_AS_NEEDED), arg1_int_type);
2740+
const exprt arg1_int_type =
2741+
typecast_exprt::conditional_cast(arg1, java_int_type());
2742+
const code_assignt code_assign(
2743+
variable(arg0, 'i', address, NO_CAST),
2744+
plus_exprt(variable(arg0, 'i', address, CAST_AS_NEEDED), arg1_int_type));
27472745
block.copy_to_operands(code_assign);
27482746
return block;
27492747
}

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ static void java_static_lifetime_init(
169169
// Argument order is: name, isAnnotation, isArray, isInterface,
170170
// isSynthetic, isLocalClass, isMemberClass, isEnum
171171

172-
code_function_callt initializer_call;
173-
initializer_call.function() = class_literal_init_method->symbol_expr();
172+
code_function_callt initializer_call(
173+
class_literal_init_method->symbol_expr());
174174

175175
code_function_callt::argumentst &args = initializer_call.arguments();
176176

@@ -676,10 +676,8 @@ bool generate_java_start_function(
676676
return true; // give up with error
677677
}
678678

679-
code_function_callt call_init;
680-
call_init.lhs().make_nil();
679+
code_function_callt call_init(init_it->second.symbol_expr());
681680
call_init.add_source_location()=symbol.location;
682-
call_init.function()=init_it->second.symbol_expr();
683681

684682
init_code.move_to_operands(call_init);
685683
}
@@ -689,15 +687,13 @@ bool generate_java_start_function(
689687
// where return is a new variable
690688
// and arg1 ... argn are constructed below as well
691689

692-
code_function_callt call_main;
693-
694690
source_locationt loc=symbol.location;
695691
loc.set_function(symbol.name);
696692
source_locationt &dloc=loc;
697693

698694
// function to call
695+
code_function_callt call_main(symbol.symbol_expr());
699696
call_main.add_source_location()=dloc;
700-
call_main.function()=symbol.symbol_expr();
701697
call_main.function().add_source_location()=dloc;
702698

703699
// if the method return type is not void, store return value in a new variable

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ exprt allocate_dynamic_object(
213213
ID_java,
214214
symbol_table);
215215
symbols_created.push_back(&malloc_sym);
216-
code_assignt assign=code_assignt(malloc_sym.symbol_expr(), malloc_expr);
216+
code_assignt assign(malloc_sym.symbol_expr(), malloc_expr);
217217
assign.add_source_location()=loc;
218218
output_code.copy_to_operands(assign);
219219
exprt malloc_symbol_expr=malloc_sym.symbol_expr();
@@ -1391,7 +1391,7 @@ void java_object_factoryt::gen_nondet_array_init(
13911391
symbol_table);
13921392
symbols_created.push_back(&array_init_symbol);
13931393
const auto &array_init_symexpr=array_init_symbol.symbol_expr();
1394-
codet data_assign=code_assignt(array_init_symexpr, init_array_expr);
1394+
code_assignt data_assign(array_init_symexpr, init_array_expr);
13951395
data_assign.add_source_location()=loc;
13961396
assignments.copy_to_operands(data_assign);
13971397

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,15 @@ static void clinit_wrapper_do_recursive_calls(
208208
auto findit = symbol_table.symbols.find(base_init_routine);
209209
if(findit == symbol_table.symbols.end())
210210
continue;
211-
code_function_callt call_base;
212-
call_base.function() = findit->second.symbol_expr();
211+
const code_function_callt call_base(findit->second.symbol_expr());
213212
init_body.move_to_operands(call_base);
214213
}
215214

216215
const irep_idt &real_clinit_name = clinit_function_name(class_name);
217216
auto find_sym_it = symbol_table.symbols.find(real_clinit_name);
218217
if(find_sym_it != symbol_table.symbols.end())
219218
{
220-
code_function_callt call_real_init;
221-
call_real_init.function() = find_sym_it->second.symbol_expr();
219+
const code_function_callt call_real_init(find_sym_it->second.symbol_expr());
222220
init_body.move_to_operands(call_real_init);
223221
}
224222

0 commit comments

Comments
 (0)