Skip to content

Commit 0cb2bd8

Browse files
author
Daniel Kroening
committed
side_effect_exprt now offers constructor with operands
This removes the need to use .add_to_operands() after the construction of the object.
1 parent 3a28687 commit 0cb2bd8

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

src/cpp/cpp_constructor.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
141141
// Override constantness
142142
object_tc.type().set(ID_C_constant, false);
143143
object_tc.set(ID_C_lvalue, true);
144-
side_effect_exprt assign(ID_assign, typet(), source_location);
145-
assign.copy_to_operands(object_tc, operands_tc.front());
144+
side_effect_exprt assign(
145+
ID_assign, {object_tc, operands_tc.front()}, typet(), source_location);
146146
typecheck_side_effect_assignment(assign);
147147
code_expressiont new_code;
148148
new_code.expression()=assign;
@@ -189,9 +189,14 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
189189
if(!component.get_bool(ID_from_base))
190190
val=true_exprt();
191191

192-
side_effect_exprt assign(ID_assign, typet(), source_location);
193-
assign.add_to_operands(std::move(member), std::move(val));
192+
side_effect_exprt assign(
193+
ID_assign,
194+
{std::move(member), std::move(val)},
195+
typet(),
196+
source_location);
197+
194198
typecheck_side_effect_assignment(assign);
199+
195200
block.add(code_expressiont(std::move(assign)));
196201
}
197202

src/cpp/cpp_typecheck_code.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code)
314314
symbol_expr.set(ID_C_lvalue, true);
315315
code.op0().type().remove(ID_C_reference);
316316

317-
side_effect_exprt assign(ID_assign, typet(), code.source_location());
318-
assign.copy_to_operands(symbol_expr, code.op0());
317+
side_effect_exprt assign(
318+
ID_assign,
319+
{symbol_expr, code.op0()},
320+
typet(),
321+
code.source_location());
319322
typecheck_side_effect_assignment(assign);
320323
code_expressiont new_code(assign);
321324
code.swap(new_code);

src/cpp/parse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,8 +6403,8 @@ bool Parser::rPostfixExpr(exprt &exp)
64036403
lex.get_token(op);
64046404

64056405
{
6406-
side_effect_exprt tmp(ID_postdecrement, typet(), source_locationt());
6407-
tmp.add_to_operands(std::move(exp));
6406+
side_effect_exprt tmp(
6407+
ID_postdecrement, {std::move(exp)}, typet(), source_locationt());
64086408
set_location(tmp, op);
64096409
exp.swap(tmp);
64106410
}

src/util/std_code.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ inline const code_expressiont &to_code_expression(const codet &code)
15571557
/// subtypes are not subtypes of \ref codet, but they inherit directly from
15581558
/// \ref exprt. They do have a `statement` like [codets](\ref codet), but their
15591559
/// [id()](\ref irept::id) is `ID_side_effect`, not `ID_code`.
1560-
class side_effect_exprt:public exprt
1560+
class side_effect_exprt : public exprt
15611561
{
15621562
public:
15631563
DEPRECATED("use side_effect_exprt(statement, type, loc) instead")
@@ -1567,8 +1567,8 @@ class side_effect_exprt:public exprt
15671567
}
15681568

15691569
DEPRECATED("use side_effect_exprt(statement, type, loc) instead")
1570-
side_effect_exprt(const irep_idt &statement, const typet &_type):
1571-
exprt(ID_side_effect, _type)
1570+
side_effect_exprt(const irep_idt &statement, const typet &_type)
1571+
: exprt(ID_side_effect, _type)
15721572
{
15731573
set_statement(statement);
15741574
}
@@ -1583,6 +1583,19 @@ class side_effect_exprt:public exprt
15831583
add_source_location() = loc;
15841584
}
15851585

1586+
/// constructor with operands
1587+
side_effect_exprt(
1588+
const irep_idt &statement,
1589+
operandst &&_operands,
1590+
const typet &_type,
1591+
const source_locationt &loc)
1592+
: exprt(ID_side_effect, _type)
1593+
{
1594+
set_statement(statement);
1595+
operands() = std::move(_operands);
1596+
add_source_location() = loc;
1597+
}
1598+
15861599
const irep_idt &get_statement() const
15871600
{
15881601
return get(ID_statement);
@@ -1735,9 +1748,12 @@ class side_effect_expr_function_callt:public side_effect_exprt
17351748
const exprt::operandst &_arguments,
17361749
const typet &_type,
17371750
const source_locationt &loc)
1738-
: side_effect_exprt(ID_function_call, _type, loc)
1751+
: side_effect_exprt(
1752+
ID_function_call,
1753+
{_function, exprt(ID_arguments)},
1754+
_type,
1755+
loc)
17391756
{
1740-
add_to_operands(_function, exprt(ID_arguments));
17411757
arguments() = _arguments;
17421758
}
17431759

0 commit comments

Comments
 (0)