Skip to content

Commit 78b7119

Browse files
author
Daniel Kroening
authored
Merge pull request #2491 from diffblue/std_code_constructors
mark various 'partial constructors' as deprecated
2 parents a99c4ff + 081f743 commit 78b7119

9 files changed

+86
-41
lines changed

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,14 @@ void java_bytecode_instrument_uncaught_exceptions(
604604
const source_locationt &source_location)
605605
{
606606
// check that there is no uncaught exception
607-
code_assertt assert_no_exception;
608-
assert_no_exception.assertion() = equal_exprt(
607+
code_assertt assert_no_exception(equal_exprt(
609608
exc_symbol.symbol_expr(),
610-
null_pointer_exprt(to_pointer_type(exc_symbol.type)));
609+
null_pointer_exprt(to_pointer_type(exc_symbol.type))));
610+
611611
source_locationt assert_location = source_location;
612612
assert_location.set_comment("no uncaught exception");
613613
assert_no_exception.add_source_location() = assert_location;
614+
614615
init_code.move_to_operands(assert_no_exception);
615616
}
616617

src/ansi-c/c_typecheck_code.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,8 @@ void c_typecheck_baset::typecheck_decl(codet &code)
322322
}
323323
else
324324
{
325-
code_declt code;
325+
code_declt code(symbol.symbol_expr());
326326
code.add_source_location()=symbol.location;
327-
code.symbol()=symbol.symbol_expr();
328327
code.symbol().add_source_location()=symbol.location;
329328

330329
// add initializer, if any

src/ansi-c/c_typecheck_expr.cpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,14 @@ void c_typecheck_baset::typecheck_expr_builtin_va_arg(exprt &expr)
461461

462462
implicit_typecast(arg, pointer_type(void_type()));
463463

464+
symbol_exprt function(ID_gcc_builtin_va_arg, new_type);
465+
function.add_source_location() = expr.source_location();
466+
464467
// turn into function call
465-
side_effect_expr_function_callt result;
468+
side_effect_expr_function_callt result(
469+
function, {arg}, new_type.return_type());
470+
466471
result.add_source_location()=expr.source_location();
467-
result.function()=symbol_exprt(ID_gcc_builtin_va_arg);
468-
result.function().add_source_location()=expr.source_location();
469-
result.function().type()=new_type;
470-
result.arguments().push_back(arg);
471-
result.type()=new_type.return_type();
472472

473473
expr.swap(result);
474474

@@ -724,9 +724,8 @@ void c_typecheck_baset::typecheck_expr_operands(exprt &expr)
724724
throw 0;
725725
}
726726

727-
code_declt decl;
727+
code_declt decl(symbol.symbol_expr());
728728
decl.add_source_location()=declaration.source_location();
729-
decl.symbol()=symbol.symbol_expr();
730729

731730
expr.op0()=decl;
732731

@@ -882,15 +881,13 @@ void c_typecheck_baset::typecheck_side_effect_statement_expression(
882881

883882
code_function_callt &fc=to_code_function_call(last);
884883

885-
side_effect_expr_function_callt sideeffect;
884+
auto return_type =
885+
static_cast<const typet &>(fc.function().type().find(ID_return_type));
886886

887-
sideeffect.function()=fc.function();
888-
sideeffect.arguments()=fc.arguments();
887+
side_effect_expr_function_callt sideeffect(
888+
fc.function(), fc.arguments(), return_type);
889889
sideeffect.add_source_location()=fc.source_location();
890890

891-
sideeffect.type()=
892-
static_cast<const typet &>(fc.function().type().find(ID_return_type));
893-
894891
expr.type()=sideeffect.type();
895892

896893
if(fc.lhs().is_nil())

src/goto-programs/builtin_functions.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ void goto_convertt::do_input(
324324
const exprt::operandst &arguments,
325325
goto_programt &dest)
326326
{
327-
codet input_code;
328-
input_code.set_statement(ID_input);
327+
codet input_code(ID_input);
329328
input_code.operands()=arguments;
330329
input_code.add_source_location()=function.source_location();
331330

@@ -344,8 +343,7 @@ void goto_convertt::do_output(
344343
const exprt::operandst &arguments,
345344
goto_programt &dest)
346345
{
347-
codet output_code;
348-
output_code.set_statement(ID_output);
346+
codet output_code(ID_output);
349347
output_code.operands()=arguments;
350348
output_code.add_source_location()=function.source_location();
351349

@@ -605,8 +603,7 @@ void goto_convertt::do_array_op(
605603
throw 0;
606604
}
607605

608-
codet array_op_statement;
609-
array_op_statement.set_statement(id);
606+
codet array_op_statement(id);
610607
array_op_statement.operands()=arguments;
611608
array_op_statement.add_source_location()=function.source_location();
612609

src/goto-programs/goto_convert.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,7 @@ symbolt &goto_convertt::new_tmp_symbol(
19871987
mode,
19881988
symbol_table);
19891989

1990-
code_declt decl;
1991-
decl.symbol()=new_symbol.symbol_expr();
1990+
code_declt decl(new_symbol.symbol_expr());
19921991
decl.add_source_location()=source_location;
19931992
convert_decl(decl, dest, mode);
19941993

src/goto-programs/goto_convert_side_effect.cpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ void goto_convertt::remove_function_call(
390390
symbol_table);
391391

392392
{
393-
code_declt decl;
394-
decl.symbol()=new_symbol.symbol_expr();
393+
code_declt decl(new_symbol.symbol_expr());
395394
decl.add_source_location()=new_symbol.location;
396395
convert_decl(decl, dest, mode);
397396
}
@@ -425,8 +424,6 @@ void goto_convertt::remove_cpp_new(
425424
goto_programt &dest,
426425
bool result_is_used)
427426
{
428-
codet call;
429-
430427
const symbolt &new_symbol = get_fresh_aux_symbol(
431428
expr.type(),
432429
tmp_symbol_prefix,
@@ -435,12 +432,11 @@ void goto_convertt::remove_cpp_new(
435432
ID_cpp,
436433
symbol_table);
437434

438-
code_declt decl;
439-
decl.symbol()=new_symbol.symbol_expr();
435+
code_declt decl(new_symbol.symbol_expr());
440436
decl.add_source_location()=new_symbol.location;
441437
convert_decl(decl, dest, ID_cpp);
442438

443-
call=code_assignt(new_symbol.symbol_expr(), expr);
439+
const code_assignt call(new_symbol.symbol_expr(), expr);
444440

445441
if(result_is_used)
446442
static_cast<exprt &>(expr)=new_symbol.symbol_expr();
@@ -456,9 +452,7 @@ void goto_convertt::remove_cpp_delete(
456452
{
457453
assert(expr.operands().size()==1);
458454

459-
codet tmp;
460-
461-
tmp.set_statement(expr.get_statement());
455+
codet tmp(expr.get_statement());
462456
tmp.add_source_location()=expr.source_location();
463457
tmp.copy_to_operands(expr.op0());
464458
tmp.set(ID_destructor, expr.find(ID_destructor));

src/goto-programs/remove_function_pointers.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,8 @@ void remove_function_pointerst::remove_function_pointer(
420420

421421
// We preserve the original dereferencing to possibly catch
422422
// further pointer-related errors.
423-
code_expressiont code_expression;
423+
code_expressiont code_expression(function);
424424
code_expression.add_source_location()=function.source_location();
425-
code_expression.expression()=function;
426425
target->code.swap(code_expression);
427426
target->type=OTHER;
428427

src/util/std_code.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ code_blockt &codet::make_block()
2929
exprt tmp;
3030
tmp.swap(*this);
3131

32-
*this=codet();
33-
set_statement(ID_block);
32+
*this = codet(ID_block);
3433
move_to_operands(tmp);
3534

3635
return static_cast<code_blockt &>(*this);

src/util/std_code.h

+60
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
class codet:public exprt
2222
{
2323
public:
24+
DEPRECATED("Use codet(statement) instead")
2425
codet():exprt(ID_code, typet(ID_code))
2526
{
2627
}
@@ -253,6 +254,7 @@ inline code_assignt &to_code_assign(codet &code)
253254
class code_declt:public codet
254255
{
255256
public:
257+
DEPRECATED("Use code_declt(symbol) instead")
256258
code_declt():codet(ID_decl)
257259
{
258260
operands().resize(1);
@@ -305,6 +307,7 @@ inline code_declt &to_code_decl(codet &code)
305307
class code_deadt:public codet
306308
{
307309
public:
310+
DEPRECATED("Use code_deadt(symbol) instead")
308311
code_deadt():codet(ID_dead)
309312
{
310313
operands().resize(1);
@@ -354,6 +357,7 @@ inline code_deadt &to_code_dead(codet &code)
354357
class code_assumet:public codet
355358
{
356359
public:
360+
DEPRECATED("Use code_assumet(expr) instead")
357361
code_assumet():codet(ID_assume)
358362
{
359363
operands().resize(1);
@@ -400,6 +404,7 @@ inline code_assumet &to_code_assume(codet &code)
400404
class code_assertt:public codet
401405
{
402406
public:
407+
DEPRECATED("Use code_assertt(expr) instead")
403408
code_assertt():codet(ID_assert)
404409
{
405410
operands().resize(1);
@@ -533,11 +538,19 @@ inline code_ifthenelset &to_code_ifthenelse(codet &code)
533538
class code_switcht:public codet
534539
{
535540
public:
541+
DEPRECATED("Use code_switcht(value, body) instead")
536542
code_switcht():codet(ID_switch)
537543
{
538544
operands().resize(2);
539545
}
540546

547+
code_switcht(const exprt &_value, const codet &_body) : codet(ID_switch)
548+
{
549+
operands().resize(2);
550+
value() = _value;
551+
body() = _body;
552+
}
553+
541554
const exprt &value() const
542555
{
543556
return op0();
@@ -588,11 +601,19 @@ inline code_switcht &to_code_switch(codet &code)
588601
class code_whilet:public codet
589602
{
590603
public:
604+
DEPRECATED("Use code_whilet(cond, body) instead")
591605
code_whilet():codet(ID_while)
592606
{
593607
operands().resize(2);
594608
}
595609

610+
code_whilet(const exprt &_cond, const codet &_body) : codet(ID_while)
611+
{
612+
operands().resize(2);
613+
cond() = _cond;
614+
body() = _body;
615+
}
616+
596617
const exprt &cond() const
597618
{
598619
return op0();
@@ -643,11 +664,19 @@ inline code_whilet &to_code_while(codet &code)
643664
class code_dowhilet:public codet
644665
{
645666
public:
667+
DEPRECATED("Use code_dowhilet(cond, body) instead")
646668
code_dowhilet():codet(ID_dowhile)
647669
{
648670
operands().resize(2);
649671
}
650672

673+
code_dowhilet(const exprt &_cond, const codet &_body) : codet(ID_dowhile)
674+
{
675+
operands().resize(2);
676+
cond() = _cond;
677+
body() = _body;
678+
}
679+
651680
const exprt &cond() const
652681
{
653682
return op0();
@@ -774,6 +803,7 @@ inline code_fort &to_code_for(codet &code)
774803
class code_gotot:public codet
775804
{
776805
public:
806+
DEPRECATED("Use code_gotot(label) instead")
777807
code_gotot():codet(ID_goto)
778808
{
779809
}
@@ -947,6 +977,7 @@ inline code_returnt &to_code_return(codet &code)
947977
class code_labelt:public codet
948978
{
949979
public:
980+
DEPRECATED("Use code_labelt(label) instead")
950981
code_labelt():codet(ID_label)
951982
{
952983
operands().resize(1);
@@ -1014,6 +1045,7 @@ inline code_labelt &to_code_label(codet &code)
10141045
class code_switch_caset:public codet
10151046
{
10161047
public:
1048+
DEPRECATED("Use code_switch_caset(case_op, code) instead")
10171049
code_switch_caset():codet(ID_switch_case)
10181050
{
10191051
operands().resize(2);
@@ -1188,6 +1220,7 @@ inline const code_asmt &to_code_asm(const codet &code)
11881220
class code_expressiont:public codet
11891221
{
11901222
public:
1223+
DEPRECATED("Use code_expressiont(expr) instead")
11911224
code_expressiont():codet(ID_expression)
11921225
{
11931226
operands().resize(1);
@@ -1238,6 +1271,7 @@ inline const code_expressiont &to_code_expression(const codet &code)
12381271
class side_effect_exprt:public exprt
12391272
{
12401273
public:
1274+
DEPRECATED("Use side_effect_exprt(statement, type) instead")
12411275
explicit side_effect_exprt(const irep_idt &statement):
12421276
exprt(ID_side_effect)
12431277
{
@@ -1301,6 +1335,7 @@ inline const side_effect_exprt &to_side_effect_expr(const exprt &expr)
13011335
class side_effect_expr_nondett:public side_effect_exprt
13021336
{
13031337
public:
1338+
DEPRECATED("Use side_effect_expr_nondett(statement, type) instead")
13041339
side_effect_expr_nondett():side_effect_exprt(ID_nondet)
13051340
{
13061341
set_nullable(true);
@@ -1352,12 +1387,36 @@ inline const side_effect_expr_nondett &to_side_effect_expr_nondet(
13521387
class side_effect_expr_function_callt:public side_effect_exprt
13531388
{
13541389
public:
1390+
DEPRECATED("Use side_effect_expr_function_callt(...) instead")
13551391
side_effect_expr_function_callt():side_effect_exprt(ID_function_call)
13561392
{
13571393
operands().resize(2);
13581394
op1().id(ID_arguments);
13591395
}
13601396

1397+
side_effect_expr_function_callt(
1398+
const exprt &_function,
1399+
const exprt::operandst &_arguments)
1400+
: side_effect_exprt(ID_function_call)
1401+
{
1402+
operands().resize(2);
1403+
op1().id(ID_arguments);
1404+
function() = _function;
1405+
arguments() = _arguments;
1406+
}
1407+
1408+
side_effect_expr_function_callt(
1409+
const exprt &_function,
1410+
const exprt::operandst &_arguments,
1411+
const typet &_type)
1412+
: side_effect_exprt(ID_function_call, _type)
1413+
{
1414+
operands().resize(2);
1415+
op1().id(ID_arguments);
1416+
function() = _function;
1417+
arguments() = _arguments;
1418+
}
1419+
13611420
exprt &function()
13621421
{
13631422
return op0();
@@ -1409,6 +1468,7 @@ inline const side_effect_expr_function_callt
14091468
class side_effect_expr_throwt:public side_effect_exprt
14101469
{
14111470
public:
1471+
DEPRECATED("Use side_effect_expr_throwt(exception_list) instead")
14121472
side_effect_expr_throwt():side_effect_exprt(ID_throw)
14131473
{
14141474
}

0 commit comments

Comments
 (0)