Skip to content

Commit cdd94b9

Browse files
author
Daniel Kroening
authored
Merge pull request #2841 from diffblue/code_function_callt_constructors
added three constructors to code_function_callt
2 parents 141503e + 7c6ea9f commit cdd94b9

15 files changed

+63
-80
lines changed

src/analyses/escape_analysis.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,7 @@ void escape_analysist::insert_cleanup(
406406
const code_typet &function_type=to_code_type(function.type());
407407

408408
goto_function.body.insert_before_swap(location);
409-
code_function_callt code;
410-
code.lhs().make_nil();
411-
code.function()=function;
409+
code_function_callt code(function);
412410
code.function().add_source_location()=source_location;
413411

414412
if(function_type.parameters().size()==1)

src/ansi-c/ansi_c_entry_point.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,16 @@ bool generate_ansi_c_start_function(
213213
return true;
214214
}
215215

216-
code_function_callt call_init;
217-
call_init.lhs().make_nil();
216+
code_function_callt call_init(init_it->second.symbol_expr());
218217
call_init.add_source_location()=symbol.location;
219-
call_init.function()=init_it->second.symbol_expr();
220218

221219
init_code.move_to_operands(call_init);
222220
}
223221

224222
// build call to main function
225223

226-
code_function_callt call_main;
224+
code_function_callt call_main(symbol.symbol_expr());
227225
call_main.add_source_location()=symbol.location;
228-
call_main.function()=symbol.symbol_expr();
229226
call_main.function().add_source_location()=symbol.location;
230227

231228
if(to_code_type(symbol.type).return_type()!=empty_typet())

src/goto-instrument/code_contracts.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ void code_contractst::add_contract_check(
301301
g->source_location=skip->source_location;
302302

303303
// prepare function call including all declarations
304-
code_function_callt call;
305-
call.function()=ns.lookup(function).symbol_expr();
304+
code_function_callt call(ns.lookup(function).symbol_expr());
306305
replace_symbolt replace;
307306

308307
// decl ret

src/goto-instrument/function.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,13 @@ code_function_callt function_to_call(
5959

6060
string_constantt function_id_string(argument);
6161

62-
code_function_callt call;
63-
call.lhs().make_nil();
64-
call.function()=
65-
symbol_exprt(s_it->second.name, s_it->second.type);
66-
call.arguments().resize(1);
67-
call.arguments()[0]=
68-
typecast_exprt(
62+
code_function_callt call(
63+
nil_exprt(),
64+
symbol_exprt(s_it->second.name, s_it->second.type),
65+
{typecast_exprt(
6966
address_of_exprt(
70-
index_exprt(
71-
function_id_string, from_integer(0, index_type()))),
72-
to_code_type(s_it->second.type).parameters()[0].type());
67+
index_exprt(function_id_string, from_integer(0, index_type()))),
68+
to_code_type(s_it->second.type).parameters()[0].type())});
7369

7470
return call;
7571
}

src/goto-instrument/goto_program2code.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,11 @@ goto_programt::const_targett goto_program2codet::convert_instruction(
220220
case ATOMIC_BEGIN:
221221
case ATOMIC_END:
222222
{
223-
code_function_callt f;
224223
const code_typet void_t({}, empty_typet());
225-
f.function()=symbol_exprt(
226-
target->is_atomic_begin() ?
227-
"__CPROVER_atomic_begin" :
228-
"__CPROVER_atomic_end",
229-
void_t);
224+
code_function_callt f(symbol_exprt(
225+
target->is_atomic_begin() ? "__CPROVER_atomic_begin"
226+
: "__CPROVER_atomic_end",
227+
void_t));
230228
dest.move_to_operands(f);
231229
return target;
232230
}

src/goto-programs/builtin_functions.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,7 @@ void goto_convertt::do_scanf(
309309
else
310310
{
311311
// we'll just do nothing
312-
code_function_callt function_call;
313-
function_call.lhs()=lhs;
314-
function_call.function()=function;
315-
function_call.arguments()=arguments;
312+
code_function_callt function_call(lhs, function, arguments);
316313
function_call.add_source_location()=function.source_location();
317314

318315
copy(function_call, FUNCTION_CALL, dest);
@@ -462,8 +459,7 @@ void goto_convertt::do_cpp_new(
462459

463460
tmp_symbol_expr=tmp_symbol.symbol_expr();
464461

465-
code_function_callt new_call;
466-
new_call.function()=new_symbol;
462+
code_function_callt new_call(new_symbol);
467463
if(new_array)
468464
new_call.arguments().push_back(count);
469465
new_call.arguments().push_back(object_size);
@@ -493,8 +489,7 @@ void goto_convertt::do_cpp_new(
493489

494490
tmp_symbol_expr=tmp_symbol.symbol_expr();
495491

496-
code_function_callt new_call;
497-
new_call.function()=new_symbol;
492+
code_function_callt new_call(new_symbol);
498493
if(new_array)
499494
new_call.arguments().push_back(count);
500495
new_call.arguments().push_back(object_size);
@@ -1552,10 +1547,7 @@ void goto_convertt::do_function_call_symbol(
15521547
new_function.set_identifier(name);
15531548
new_function.type()=f_type;
15541549

1555-
code_function_callt function_call;
1556-
function_call.lhs()=lhs;
1557-
function_call.function()=new_function;
1558-
function_call.arguments()=new_arguments;
1550+
code_function_callt function_call(lhs, new_function, new_arguments);
15591551
function_call.add_source_location()=function.source_location();
15601552

15611553
if(!symbol_table.has_symbol(name))
@@ -1575,10 +1567,7 @@ void goto_convertt::do_function_call_symbol(
15751567
do_function_call_symbol(*symbol);
15761568

15771569
// insert function call
1578-
code_function_callt function_call;
1579-
function_call.lhs()=lhs;
1580-
function_call.function()=function;
1581-
function_call.arguments()=arguments;
1570+
code_function_callt function_call(lhs, function, arguments);
15821571
function_call.add_source_location()=function.source_location();
15831572

15841573
copy(function_call, FUNCTION_CALL, dest);

src/goto-programs/destructor.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ code_function_callt get_destructor(
4242
ns.follow(arg_type.subtype())==type)
4343
{
4444
const symbol_exprt symbol_expr(it->get(ID_name), it->type());
45-
46-
code_function_callt function_call;
47-
function_call.function()=symbol_expr;
48-
49-
return function_call;
45+
return code_function_callt(symbol_expr);
5046
}
5147
}
5248
}

src/goto-programs/goto_convert.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,8 @@ void goto_convertt::convert_cpp_delete(
897897
typet arg_type=
898898
to_code_type(delete_symbol.type()).parameters().front().type();
899899

900-
code_function_callt delete_call;
901-
delete_call.function()=delete_symbol;
902-
delete_call.arguments().push_back(typecast_exprt(tmp_op, arg_type));
900+
code_function_callt delete_call(
901+
nil_exprt(), delete_symbol, {typecast_exprt(tmp_op, arg_type)});
903902
delete_call.lhs().make_nil();
904903
delete_call.add_source_location()=code.source_location();
905904

src/goto-programs/goto_convert_function_call.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,8 @@ void goto_convertt::do_function_call_other(
166166
// don't know what to do with it
167167
goto_programt::targett t=dest.add_instruction(FUNCTION_CALL);
168168

169-
code_function_callt function_call;
169+
code_function_callt function_call(lhs, function, arguments);
170170
function_call.add_source_location()=function.source_location();
171-
function_call.lhs()=lhs;
172-
function_call.function()=function;
173-
function_call.arguments()=arguments;
174171

175172
t->source_location=function.source_location();
176173
t->code.swap(function_call);

src/goto-programs/goto_convert_side_effect.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,8 @@ void goto_convertt::remove_function_call(
341341
if(!result_is_used)
342342
{
343343
assert(expr.operands().size()==2);
344-
code_function_callt call;
345-
call.function()=expr.op0();
346-
call.arguments()=expr.op1().operands();
344+
code_function_callt call(nil_exprt(), expr.op0(), expr.op1().operands());
347345
call.add_source_location()=expr.source_location();
348-
call.lhs().make_nil();
349346
convert_function_call(call, dest, mode);
350347
expr.make_nil();
351348
return;
@@ -397,10 +394,8 @@ void goto_convertt::remove_function_call(
397394

398395
{
399396
goto_programt tmp_program2;
400-
code_function_callt call;
401-
call.lhs()=new_symbol.symbol_expr();
402-
call.function()=expr.op0();
403-
call.arguments()=expr.op1().operands();
397+
code_function_callt call(
398+
new_symbol.symbol_expr(), expr.op0(), expr.op1().operands());
404399
call.add_source_location()=new_symbol.location;
405400
convert_function_call(call, dest, mode);
406401
}

src/goto-programs/mm_io.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void mm_io(
5555
const dereference_exprt &d=*deref_expr_r.begin();
5656
source_locationt source_location=it->source_location;
5757
irep_idt function=it->function;
58-
code_function_callt fc;
5958
const code_typet &ct=to_code_type(mm_io_r.type());
6059

6160
irep_idt identifier=to_symbol_expr(mm_io_r).get_identifier();
@@ -67,10 +66,10 @@ void mm_io(
6766
const typet &pt=ct.parameters()[0].type();
6867
const typet &st=ct.parameters()[1].type();
6968
exprt size=size_of_expr(d.type(), ns);
69+
code_function_callt fc(mm_io_r);
7070
fc.arguments().resize(2);
7171
fc.arguments()[0]=typecast_exprt(d.pointer(), pt);
7272
fc.arguments()[1]=typecast_exprt(size, st);
73-
fc.function()=mm_io_r;
7473
goto_function.body.insert_before_swap(it);
7574
it->make_function_call(fc);
7675
it->source_location=source_location;
@@ -86,17 +85,16 @@ void mm_io(
8685
const dereference_exprt &d=to_dereference_expr(a.lhs());
8786
source_locationt source_location=it->source_location;
8887
irep_idt function=it->function;
89-
code_function_callt fc;
9088
const code_typet &ct=to_code_type(mm_io_w.type());
9189
const typet &pt=ct.parameters()[0].type();
9290
const typet &st=ct.parameters()[1].type();
9391
const typet &vt=ct.parameters()[2].type();
9492
exprt size=size_of_expr(d.type(), ns);
93+
code_function_callt fc(mm_io_w);
9594
fc.arguments().resize(3);
9695
fc.arguments()[0]=typecast_exprt(d.pointer(), pt);
9796
fc.arguments()[1]=typecast_exprt(size, st);
9897
fc.arguments()[2]=typecast_exprt(a.rhs(), vt);
99-
fc.function()=mm_io_w;
10098
goto_function.body.insert_before_swap(it);
10199
it->make_function_call(fc);
102100
it->source_location=source_location;

src/jsil/jsil_convert.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ bool jsil_convertt::convert_code(const symbolt &symbol, codet &code)
104104
side_effect_expr_function_callt f_expr=
105105
to_side_effect_expr_function_call(a.rhs());
106106

107-
code_function_callt f;
108-
f.lhs().swap(a.lhs());
109-
f.function().swap(f_expr.function());
110-
f.arguments().swap(f_expr.arguments());
107+
code_function_callt f(a.lhs(), f_expr.function(), f_expr.arguments());
111108
f.add_source_location()=code.source_location();
112109

113110
code.swap(f);

src/jsil/jsil_entry_point.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,15 @@ bool jsil_entry_point(
130130
if(init_it==symbol_table.symbols.end())
131131
throw "failed to find " INITIALIZE_FUNCTION " symbol";
132132

133-
code_function_callt call_init;
134-
call_init.lhs().make_nil();
133+
code_function_callt call_init(init_it->second.symbol_expr());
135134
call_init.add_source_location()=symbol.location;
136-
call_init.function()=init_it->second.symbol_expr();
137-
138135
init_code.move_to_operands(call_init);
139136
}
140137

141138
// build call to main function
142139

143-
code_function_callt call_main;
140+
code_function_callt call_main(symbol.symbol_expr());
144141
call_main.add_source_location()=symbol.location;
145-
call_main.function()=symbol.symbol_expr();
146142
call_main.function().add_source_location()=symbol.location;
147143

148144
init_code.move_to_operands(call_main);

src/linking/static_lifetime_init.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ bool static_lifetime_init(
151151
code_type.return_type().id() == ID_constructor &&
152152
code_type.parameters().empty())
153153
{
154-
code_function_callt function_call;
155-
function_call.function()=symbol.symbol_expr();
154+
code_function_callt function_call(symbol.symbol_expr());
156155
function_call.add_source_location()=source_location;
157156
dest.move_to_operands(function_call);
158157
}

src/util/std_code.h

+31-2
Original file line numberDiff line numberDiff line change
@@ -865,13 +865,44 @@ inline code_gotot &to_code_goto(codet &code)
865865
class code_function_callt:public codet
866866
{
867867
public:
868+
DEPRECATED("Use code_function_callt(...) instead")
868869
code_function_callt():codet(ID_function_call)
869870
{
870871
operands().resize(3);
871872
lhs().make_nil();
872873
op2().id(ID_arguments);
873874
}
874875

876+
explicit code_function_callt(const exprt &_function) : codet(ID_function_call)
877+
{
878+
operands().resize(3);
879+
lhs().make_nil();
880+
op2().id(ID_arguments);
881+
function() = _function;
882+
}
883+
884+
typedef exprt::operandst argumentst;
885+
886+
code_function_callt(
887+
const exprt &_lhs,
888+
const exprt &_function,
889+
argumentst &&_arguments)
890+
: code_function_callt(_function)
891+
{
892+
lhs() = _lhs;
893+
arguments() = std::move(_arguments);
894+
}
895+
896+
code_function_callt(
897+
const exprt &_lhs,
898+
const exprt &_function,
899+
const argumentst &_arguments)
900+
: code_function_callt(_function)
901+
{
902+
lhs() = _lhs;
903+
arguments() = _arguments;
904+
}
905+
875906
exprt &lhs()
876907
{
877908
return op0();
@@ -892,8 +923,6 @@ class code_function_callt:public codet
892923
return op1();
893924
}
894925

895-
typedef exprt::operandst argumentst;
896-
897926
argumentst &arguments()
898927
{
899928
return op2().operands();

0 commit comments

Comments
 (0)