Skip to content

Commit 41d097d

Browse files
author
Daniel Kroening
committed
use codet constructors with operands
This prevents construction followed by another assignment.
1 parent 06ebe72 commit 41d097d

File tree

1 file changed

+27
-47
lines changed

1 file changed

+27
-47
lines changed

src/util/std_code.h

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ class code_blockt:public codet
187187
return result;
188188
}
189189

190-
explicit code_blockt(const std::vector<codet> &_statements):codet(ID_block)
190+
explicit code_blockt(const std::vector<codet> &_statements)
191+
: codet(ID_block, (const std::vector<exprt> &)_statements)
191192
{
192-
operands()=(const std::vector<exprt> &)_statements;
193193
}
194194

195-
explicit code_blockt(std::vector<codet> &&_statements):codet(ID_block)
195+
explicit code_blockt(std::vector<codet> &&_statements)
196+
: codet(ID_block, std::move((std::vector<exprt> &&) _statements))
196197
{
197-
operands()=std::move((std::vector<exprt> &&)_statements);
198198
}
199199

200200
void add(const codet &code)
@@ -272,9 +272,9 @@ class code_assignt:public codet
272272
operands().resize(2);
273273
}
274274

275-
code_assignt(const exprt &lhs, const exprt &rhs):codet(ID_assign)
275+
code_assignt(const exprt &lhs, const exprt &rhs)
276+
: codet(ID_assign, {lhs, rhs})
276277
{
277-
add_to_operands(lhs, rhs);
278278
}
279279

280280
exprt &lhs()
@@ -435,9 +435,8 @@ inline code_declt &to_code_decl(codet &code)
435435
class code_deadt:public codet
436436
{
437437
public:
438-
explicit code_deadt(const symbol_exprt &symbol) : codet(ID_dead)
438+
explicit code_deadt(const symbol_exprt &symbol) : codet(ID_dead, {symbol})
439439
{
440-
add_to_operands(symbol);
441440
}
442441

443442
symbol_exprt &symbol()
@@ -513,9 +512,8 @@ class code_assumet:public codet
513512
operands().resize(1);
514513
}
515514

516-
explicit code_assumet(const exprt &expr):codet(ID_assume)
515+
explicit code_assumet(const exprt &expr) : codet(ID_assume, {expr})
517516
{
518-
add_to_operands(expr);
519517
}
520518

521519
const exprt &assumption() const
@@ -565,9 +563,8 @@ class code_assertt:public codet
565563
operands().resize(1);
566564
}
567565

568-
explicit code_assertt(const exprt &expr):codet(ID_assert)
566+
explicit code_assertt(const exprt &expr) : codet(ID_assert, {expr})
569567
{
570-
add_to_operands(expr);
571568
}
572569

573570
const exprt &assertion() const
@@ -638,16 +635,14 @@ class code_ifthenelset:public codet
638635
const exprt &condition,
639636
const codet &then_code,
640637
const codet &else_code)
641-
: codet(ID_ifthenelse)
638+
: codet(ID_ifthenelse, {condition, then_code, else_code})
642639
{
643-
add_to_operands(condition, then_code, else_code);
644640
}
645641

646642
/// An if \p condition then \p then_code statement (no "else" case).
647643
code_ifthenelset(const exprt &condition, const codet &then_code)
648-
: codet(ID_ifthenelse)
644+
: codet(ID_ifthenelse, {condition, then_code, nil_exprt()})
649645
{
650-
add_to_operands(condition, then_code, nil_exprt());
651646
}
652647

653648
const exprt &cond() const
@@ -722,11 +717,9 @@ class code_switcht:public codet
722717
operands().resize(2);
723718
}
724719

725-
code_switcht(const exprt &_value, const codet &_body) : codet(ID_switch)
720+
code_switcht(const exprt &_value, const codet &_body)
721+
: codet(ID_switch, {_value, _body})
726722
{
727-
operands().resize(2);
728-
value() = _value;
729-
body() = _body;
730723
}
731724

732725
const exprt &value() const
@@ -784,11 +777,9 @@ class code_whilet:public codet
784777
operands().resize(2);
785778
}
786779

787-
code_whilet(const exprt &_cond, const codet &_body) : codet(ID_while)
780+
code_whilet(const exprt &_cond, const codet &_body)
781+
: codet(ID_while, {_cond, _body})
788782
{
789-
operands().resize(2);
790-
cond() = _cond;
791-
body() = _body;
792783
}
793784

794785
const exprt &cond() const
@@ -846,11 +837,9 @@ class code_dowhilet:public codet
846837
operands().resize(2);
847838
}
848839

849-
code_dowhilet(const exprt &_cond, const codet &_body) : codet(ID_dowhile)
840+
code_dowhilet(const exprt &_cond, const codet &_body)
841+
: codet(ID_dowhile, {_cond, _body})
850842
{
851-
operands().resize(2);
852-
cond() = _cond;
853-
body() = _body;
854843
}
855844

856845
const exprt &cond() const
@@ -917,11 +906,8 @@ class code_fort:public codet
917906
const exprt &_cond,
918907
const exprt &_iter,
919908
const codet &_body)
920-
: codet(ID_for)
909+
: codet(ID_for, {_init, _cond, _iter, _body})
921910
{
922-
reserve_operands(4);
923-
add_to_operands(_init, _cond, _iter);
924-
add_to_operands(_body);
925911
}
926912

927913
// nil or a statement
@@ -1203,9 +1189,8 @@ class code_returnt:public codet
12031189
op0().make_nil();
12041190
}
12051191

1206-
explicit code_returnt(const exprt &_op):codet(ID_return)
1192+
explicit code_returnt(const exprt &_op) : codet(ID_return, {_op})
12071193
{
1208-
add_to_operands(_op);
12091194
}
12101195

12111196
const exprt &return_value() const
@@ -1275,12 +1260,10 @@ class code_labelt:public codet
12751260
set_label(_label);
12761261
}
12771262

1278-
code_labelt(
1279-
const irep_idt &_label, const codet &_code):codet(ID_label)
1263+
code_labelt(const irep_idt &_label, const codet &_code)
1264+
: codet(ID_label, {_code})
12801265
{
1281-
operands().resize(1);
12821266
set_label(_label);
1283-
code()=_code;
12841267
}
12851268

12861269
const irep_idt &get_label() const
@@ -1339,10 +1322,9 @@ class code_switch_caset:public codet
13391322
operands().resize(2);
13401323
}
13411324

1342-
code_switch_caset(
1343-
const exprt &_case_op, const codet &_code):codet(ID_switch_case)
1325+
code_switch_caset(const exprt &_case_op, const codet &_code)
1326+
: codet(ID_switch_case, {_case_op, _code})
13441327
{
1345-
add_to_operands(_case_op, _code);
13461328
}
13471329

13481330
bool is_default() const
@@ -1470,9 +1452,8 @@ class code_asmt:public codet
14701452
{
14711453
}
14721454

1473-
explicit code_asmt(const exprt &expr):codet(ID_asm)
1455+
explicit code_asmt(const exprt &expr) : codet(ID_asm, {expr})
14741456
{
1475-
add_to_operands(expr);
14761457
}
14771458

14781459
const irep_idt &get_flavor() const
@@ -1517,9 +1498,8 @@ class code_expressiont:public codet
15171498
operands().resize(1);
15181499
}
15191500

1520-
explicit code_expressiont(const exprt &expr):codet(ID_expression)
1501+
explicit code_expressiont(const exprt &expr) : codet(ID_expression, {expr})
15211502
{
1522-
add_to_operands(expr);
15231503
}
15241504

15251505
const exprt &expression() const
@@ -2117,9 +2097,9 @@ class code_try_catcht:public codet
21172097
}
21182098

21192099
/// A statement representing try \p _try_code catch ...
2120-
explicit code_try_catcht(const codet &_try_code) : codet(ID_try_catch)
2100+
explicit code_try_catcht(const codet &_try_code)
2101+
: codet(ID_try_catch, {_try_code})
21212102
{
2122-
add_to_operands(_try_code);
21232103
}
21242104

21252105
codet &try_code()

0 commit comments

Comments
 (0)