Skip to content

Use constructors to construct objects #3075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ static codet get_monitor_call(
return code_skipt();

// Otherwise we create a function call
code_function_callt call;
call.function() = symbol_exprt(symbol, it->second.type);
call.lhs().make_nil();
call.arguments().push_back(object);
return call;
return code_function_callt(symbol_exprt(symbol, it->second.type), {object});
}

/// Introduces a monitorexit before every return recursively.
Expand Down Expand Up @@ -288,11 +284,15 @@ static void instrument_start_thread(

// Create global variable __CPROVER__next_thread_id. Used as a counter
// in-order to to assign ids to new threads.
const symbolt &next_symbol =
add_or_get_symbol(
symbol_table, next_thread_id, next_thread_id,
java_int_type(),
from_integer(0, java_int_type()), false, true);
const symbol_exprt next_symbol_expr = add_or_get_symbol(
symbol_table,
next_thread_id,
next_thread_id,
java_int_type(),
from_integer(0, java_int_type()),
false,
true)
.symbol_expr();

// Create thread-local variable __CPROVER__thread_id. Holds the id of
// the thread.
Expand Down Expand Up @@ -320,14 +320,11 @@ static void instrument_start_thread(
codet tmp_a(ID_start_thread);
tmp_a.set(ID_destination, lbl1);
code_gotot tmp_b(lbl2);
code_labelt tmp_c(lbl1);
tmp_c.op0() = codet(ID_skip);
const code_labelt tmp_c(lbl1, code_skipt());

exprt plus(ID_plus, java_int_type());
plus.copy_to_operands(next_symbol.symbol_expr());
plus.copy_to_operands(from_integer(1, java_int_type()));
code_assignt tmp_d(next_symbol.symbol_expr(), plus);
code_assignt tmp_e(current_symbol.symbol_expr(), next_symbol.symbol_expr());
const plus_exprt plus(next_symbol_expr, from_integer(1, java_int_type()));
const code_assignt tmp_d(next_symbol_expr, plus);
const code_assignt tmp_e(current_symbol.symbol_expr(), next_symbol_expr);

code_blockt block;
block.add(tmp_a);
Expand Down Expand Up @@ -368,8 +365,7 @@ static void instrument_end_thread(
// A: codet(id=ID_end_thread)
// B: codet(id=ID_label,label= __CPROVER_THREAD_EXIT_<ID>)
codet tmp_a(ID_end_thread);
code_labelt tmp_b(lbl2);
tmp_b.op0() = codet(ID_skip);
const code_labelt tmp_b(lbl2, code_skipt());

code_blockt block;
block.add(tmp_a);
Expand Down
20 changes: 7 additions & 13 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,7 @@ codet java_bytecode_convert_methodt::get_clinit_call(
return code_skipt();
else
{
code_function_callt ret;
ret.function() = findit->second.symbol_expr();
const code_function_callt ret(findit->second.symbol_expr());
if(needed_lazy_methods)
needed_lazy_methods->add_needed_method(findit->second.name);
return ret;
Expand Down Expand Up @@ -2004,10 +2003,7 @@ codet java_bytecode_convert_methodt::convert_monitorenterexit(
java_method_typet type(
{java_method_typet::parametert(java_reference_type(void_typet()))},
void_typet());
code_function_callt call;
call.function() = symbol_exprt(descriptor, type);
call.lhs().make_nil();
call.arguments().push_back(op[0]);
code_function_callt call(symbol_exprt(descriptor, type), {op[0]});
call.add_source_location() = source_location;
if(needed_lazy_methods && symbol_table.has_symbol(descriptor))
needed_lazy_methods->add_needed_method(descriptor);
Expand Down Expand Up @@ -2737,13 +2733,11 @@ codet java_bytecode_convert_methodt::convert_iinc(
bytecode_write_typet::VARIABLE,
to_symbol_expr(locvar).get_identifier());

code_assignt code_assign;
code_assign.lhs() = variable(arg0, 'i', address, NO_CAST);
exprt arg1_int_type = arg1;
if(arg1.type() != java_int_type())
arg1_int_type.make_typecast(java_int_type());
code_assign.rhs() =
plus_exprt(variable(arg0, 'i', address, CAST_AS_NEEDED), arg1_int_type);
const exprt arg1_int_type =
typecast_exprt::conditional_cast(arg1, java_int_type());
const code_assignt code_assign(
variable(arg0, 'i', address, NO_CAST),
plus_exprt(variable(arg0, 'i', address, CAST_AS_NEEDED), arg1_int_type));
block.copy_to_operands(code_assign);
return block;
}
Expand Down
55 changes: 22 additions & 33 deletions jbmc/src/java_bytecode/java_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,33 +169,26 @@ static void java_static_lifetime_init(
// Argument order is: name, isAnnotation, isArray, isInterface,
// isSynthetic, isLocalClass, isMemberClass, isEnum

code_function_callt initializer_call;
initializer_call.function() = class_literal_init_method->symbol_expr();

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

// this:
args.push_back(address_of_exprt(sym.symbol_expr()));
// name:
args.push_back(address_of_exprt(class_name_literal));
// isAnnotation:
args.push_back(
constant_bool(class_symbol.type.get_bool(ID_is_annotation)));
// isArray:
args.push_back(constant_bool(class_is_array));
// isInterface:
args.push_back(
constant_bool(class_symbol.type.get_bool(ID_interface)));
// isSynthetic:
args.push_back(
constant_bool(class_symbol.type.get_bool(ID_synthetic)));
// isLocalClass:
args.push_back(nondet_bool);
// isMemberClass:
args.push_back(nondet_bool);
// isEnum:
args.push_back(
constant_bool(class_symbol.type.get_bool(ID_enumeration)));
code_function_callt initializer_call(
class_literal_init_method->symbol_expr(),
{// this:
address_of_exprt(sym.symbol_expr()),
// name:
address_of_exprt(class_name_literal),
// isAnnotation:
constant_bool(class_symbol.type.get_bool(ID_is_annotation)),
// isArray:
constant_bool(class_is_array),
// isInterface:
constant_bool(class_symbol.type.get_bool(ID_interface)),
// isSynthetic:
constant_bool(class_symbol.type.get_bool(ID_synthetic)),
// isLocalClass:
nondet_bool,
// isMemberClass:
nondet_bool,
// isEnum:
constant_bool(class_symbol.type.get_bool(ID_enumeration))});

// First initialize the object as prior to a constructor:
namespacet ns(symbol_table);
Expand Down Expand Up @@ -676,10 +669,8 @@ bool generate_java_start_function(
return true; // give up with error
}

code_function_callt call_init;
call_init.lhs().make_nil();
code_function_callt call_init(init_it->second.symbol_expr());
call_init.add_source_location()=symbol.location;
call_init.function()=init_it->second.symbol_expr();

init_code.move_to_operands(call_init);
}
Expand All @@ -689,15 +680,13 @@ bool generate_java_start_function(
// where return is a new variable
// and arg1 ... argn are constructed below as well

code_function_callt call_main;

source_locationt loc=symbol.location;
loc.set_function(symbol.name);
source_locationt &dloc=loc;

// function to call
code_function_callt call_main(symbol.symbol_expr());
call_main.add_source_location()=dloc;
call_main.function()=symbol.symbol_expr();
call_main.function().add_source_location()=dloc;

// if the method return type is not void, store return value in a new variable
Expand Down
7 changes: 3 additions & 4 deletions jbmc/src/java_bytecode/java_object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ exprt allocate_dynamic_object(
ID_java,
symbol_table);
symbols_created.push_back(&malloc_sym);
code_assignt assign=code_assignt(malloc_sym.symbol_expr(), malloc_expr);
code_assignt assign(malloc_sym.symbol_expr(), malloc_expr);
assign.add_source_location()=loc;
output_code.copy_to_operands(assign);
exprt malloc_symbol_expr=malloc_sym.symbol_expr();
Expand Down Expand Up @@ -1392,7 +1392,7 @@ void java_object_factoryt::gen_nondet_array_init(
symbol_table);
symbols_created.push_back(&array_init_symbol);
const auto &array_init_symexpr=array_init_symbol.symbol_expr();
codet data_assign=code_assignt(array_init_symexpr, init_array_expr);
code_assignt data_assign(array_init_symexpr, init_array_expr);
data_assign.add_source_location()=loc;
assignments.copy_to_operands(data_assign);

Expand Down Expand Up @@ -1739,8 +1739,7 @@ void java_object_factoryt::gen_method_call_if_present(
if(const auto func = symbol_table.lookup(method_name))
{
const java_method_typet &type = to_java_method_type(func->type);
code_function_callt fun_call;
fun_call.function() = func->symbol_expr();
code_function_callt fun_call(func->symbol_expr());
if(type.has_this())
fun_call.arguments().push_back(address_of_exprt(instance_expr));
assignments.add(fun_call);
Expand Down
10 changes: 4 additions & 6 deletions jbmc/src/java_bytecode/java_static_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,16 @@ static void clinit_wrapper_do_recursive_calls(
auto findit = symbol_table.symbols.find(base_init_routine);
if(findit == symbol_table.symbols.end())
continue;
code_function_callt call_base;
call_base.function() = findit->second.symbol_expr();
init_body.move_to_operands(call_base);
const code_function_callt call_base(findit->second.symbol_expr());
init_body.add(call_base);
}

const irep_idt &real_clinit_name = clinit_function_name(class_name);
auto find_sym_it = symbol_table.symbols.find(real_clinit_name);
if(find_sym_it != symbol_table.symbols.end())
{
code_function_callt call_real_init;
call_real_init.function() = find_sym_it->second.symbol_expr();
init_body.move_to_operands(call_real_init);
const code_function_callt call_real_init(find_sym_it->second.symbol_expr());
init_body.add(call_real_init);
}

// If nondet-static option is given, add a standard nondet initialization for
Expand Down
10 changes: 5 additions & 5 deletions jbmc/src/java_bytecode/java_string_library_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,11 @@ codet java_string_library_preprocesst::make_object_get_class_code(
loc);

// > class1 = Class.forName(string1)
code_function_callt fun_call;
fun_call.function()=symbol_exprt(
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;");
fun_call.lhs()=class1;
fun_call.arguments().push_back(string1);
code_function_callt fun_call(
class1,
symbol_exprt(
"java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;"),
{string1});
const java_method_typet fun_type(
{java_method_typet::parametert(string_ptr_type)}, class_type);
fun_call.function().type()=fun_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ SCENARIO(
callee.set(ID_C_class, "java::VirtualFunctionsTestParent");
callee.set(ID_component_name, "f:()V");

code_function_callt call;
call.function() = callee;
// Specific argument doesn't matter, so just pass an appropriately typed
// null pointer:
call.arguments().push_back(
null_pointer_exprt(
to_pointer_type(to_code_type(callee.type()).parameters()[0].type())));
const code_function_callt call(
callee,
// Specific argument doesn't matter, so just pass an appropriately typed
// null pointer:
{null_pointer_exprt(
to_pointer_type(to_code_type(callee.type()).parameters()[0].type()))});
virtual_call_inst->code = call;

test_program.add_instruction(END_FUNCTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void check_function_call(
for(const auto &target : targets)
{
REQUIRE(target->type == goto_program_instruction_typet::FUNCTION_CALL);
const code_function_callt call = to_code_function_call(target->code);
const code_function_callt &call = to_code_function_call(target->code);
REQUIRE(call.function().id() == ID_symbol);
REQUIRE(to_symbol_expr(call.function()).get_identifier() == function_name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code)
else
{
auto source_location = code.source_location();
code = codet(ID_skip);
code = code_skipt();
code.add_source_location() = source_location;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8103,7 +8103,7 @@ bool Parser::rExprStatement(codet &statement)
#endif

lex.get_token(tk);
statement=codet(ID_skip);
statement = code_skipt();
set_location(statement, tk);
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/goto-analyzer/taint_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ bool taint_analysist::operator()(
f_it->first!=goto_functionst::entry_point())
{
goto_programt::targett t=calls.add_instruction();
code_function_callt call;
call.function()=ns.lookup(f_it->first).symbol_expr();
const code_function_callt call(ns.lookup(f_it->first).symbol_expr());
t->make_function_call(call);
calls.add_instruction()->make_goto(end.instructions.begin());
goto_programt::targett g=gotos.add_instruction();
Expand Down
8 changes: 3 additions & 5 deletions src/goto-cc/linker_script_merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,13 @@ int linker_script_merget::ls_data2instructions(
goto_programt::instructionst initialize_instructions=gp.instructions;
for(const auto &d : data["regions"].array)
{
code_function_callt f;
const code_typet void_t({}, empty_typet());
f.function()=symbol_exprt(CPROVER_PREFIX "allocated_memory", void_t);
unsigned start=safe_string2unsigned(d["start"].value);
unsigned size=safe_string2unsigned(d["size"].value);
constant_exprt first=from_integer(start, size_type());
constant_exprt second=from_integer(size, size_type());
code_function_callt::argumentst args={first, second};
f.arguments()=args;
const code_typet void_t({}, empty_typet());
code_function_callt f(
symbol_exprt(CPROVER_PREFIX "allocated_memory", void_t), {first, second});

source_locationt loc;
loc.set_file(linker_script);
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/call_sequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static void list_calls_and_arguments(
if(!i_it->is_function_call())
continue;

const code_function_callt call=to_code_function_call(i_it->code);
const code_function_callt &call = to_code_function_call(i_it->code);

const exprt &f=call.function();

Expand Down
1 change: 0 additions & 1 deletion src/goto-instrument/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ code_function_callt function_to_call(
string_constantt function_id_string(argument);

code_function_callt call(
nil_exprt(),
symbol_exprt(s_it->second.name, s_it->second.type),
{typecast_exprt(
address_of_exprt(
Expand Down
13 changes: 4 additions & 9 deletions src/goto-instrument/goto_program2code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,16 +1361,11 @@ goto_programt::const_targett goto_program2codet::convert_start_thread(

system_headers.insert("pthread.h");

code_function_callt f;
// we don't bother setting the type
f.lhs()=cf.lhs();
f.function() =
symbol_exprt("pthread_create", code_typet({}, empty_typet()));
const null_pointer_exprt n(pointer_type(empty_typet()));
f.arguments().push_back(n);
f.arguments().push_back(n);
f.arguments().push_back(cf.function());
f.arguments().push_back(cf.arguments().front());
code_function_callt f(
cf.lhs(),
symbol_exprt("pthread_create", code_typet({}, empty_typet())),
{n, n, cf.function(), cf.arguments().front()});

dest.move_to_operands(f);
return thread_end;
Expand Down
6 changes: 2 additions & 4 deletions src/goto-instrument/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ void interrupt(
const source_locationt &source_location=
original_instruction.source_location;

code_function_callt isr_call;
code_function_callt isr_call(interrupt_handler);
isr_call.add_source_location()=source_location;
isr_call.function()=interrupt_handler;

goto_programt::targett t_goto=i_it;
goto_programt::targett t_call=goto_program.insert_after(t_goto);
Expand Down Expand Up @@ -127,9 +126,8 @@ void interrupt(

const source_locationt &source_location=i_it->source_location;

code_function_callt isr_call;
code_function_callt isr_call(interrupt_handler);
isr_call.add_source_location()=source_location;
isr_call.function()=interrupt_handler;

t_goto->make_goto(t_orig);
t_goto->source_location=source_location;
Expand Down
Loading