Skip to content

Commit b8d45ef

Browse files
author
Daniel Kroening
committed
better typing for statements in code_blockt
1 parent c5b9b4f commit b8d45ef

16 files changed

+81
-69
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -789,16 +789,16 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
789789
return this_block;
790790

791791
// Find the child code_blockt where the queried range begins:
792-
auto child_iter=this_block.operands().begin();
792+
auto child_iter = this_block.statements().begin();
793793
// Skip any top-of-block declarations;
794794
// all other children are labelled subblocks.
795-
while(child_iter!=this_block.operands().end() &&
796-
to_code(*child_iter).get_statement()==ID_decl)
795+
while(child_iter != this_block.statements().end() &&
796+
child_iter->get_statement() == ID_decl)
797797
++child_iter;
798-
assert(child_iter!=this_block.operands().end());
798+
assert(child_iter != this_block.statements().end());
799799
std::advance(child_iter, child_offset);
800-
assert(child_iter!=this_block.operands().end());
801-
auto &child_label=to_code_label(to_code(*child_iter));
800+
assert(child_iter != this_block.statements().end());
801+
auto &child_label = to_code_label(*child_iter);
802802
auto &child_block=to_code_block(child_label.code());
803803

804804
bool single_child(afterstart==findlim);
@@ -868,15 +868,15 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
868868
<< findlim_block_start_address << eom;
869869

870870
// Make a new block containing every child of interest:
871-
auto &this_block_children=this_block.operands();
871+
auto &this_block_children = this_block.statements();
872872
assert(tree.branch.size()==this_block_children.size());
873873
for(auto blockidx=child_offset, blocklim=child_offset+nblocks;
874874
blockidx!=blocklim;
875875
++blockidx)
876-
newblock.move(to_code(this_block_children[blockidx]));
876+
newblock.move(this_block_children[blockidx]);
877877

878878
// Relabel the inner header:
879-
to_code_label(to_code(newblock.operands()[0])).set_label(new_label_irep);
879+
to_code_label(newblock.statements()[0]).set_label(new_label_irep);
880880
// Relabel internal gotos:
881881
replace_goto_target(newblock, child_label_name, new_label_irep);
882882

@@ -1763,15 +1763,15 @@ codet java_bytecode_convert_methodt::convert_instructions(
17631763
if(last_statement.get_statement()==ID_goto)
17641764
{
17651765
// Insert stack twiddling before branch:
1766-
last_statement.make_block();
1767-
last_statement.operands().insert(
1768-
last_statement.operands().begin(),
1769-
more_code.operands().begin(),
1770-
more_code.operands().end());
1766+
auto &block = last_statement.make_block();
1767+
block.statements().insert(
1768+
block.statements().begin(),
1769+
more_code.statements().begin(),
1770+
more_code.statements().end());
17711771
}
17721772
else
1773-
forall_operands(o_it, more_code)
1774-
c.copy_to_operands(*o_it);
1773+
for(const auto &m_c_s : more_code.statements())
1774+
to_code_block(c).add(m_c_s);
17751775
}
17761776
}
17771777
a_it2->second.stack=stack;
@@ -1845,7 +1845,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
18451845

18461846
if(c.get_statement()!=ID_skip)
18471847
{
1848-
auto &lastlabel=to_code_label(to_code(root_block.operands().back()));
1848+
auto &lastlabel = to_code_label(root_block.statements().back());
18491849
auto &add_to_block=to_code_block(lastlabel.code());
18501850
add_to_block.add(c);
18511851
}
@@ -1909,11 +1909,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
19091909
v.start_pc + v.length,
19101910
std::numeric_limits<method_offsett>::max());
19111911
code_declt d(v.symbol_expr);
1912-
block.operands().insert(block.operands().begin(), d);
1912+
block.statements().insert(block.statements().begin(), d);
19131913
}
19141914

1915-
for(auto &block : root_block.operands())
1916-
code.move(to_code(block));
1915+
for(auto &block : root_block.statements())
1916+
code.move(block);
19171917

19181918
return code;
19191919
}

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ exprt allocate_dynamic_object_with_decl(
273273
output_code.add(decl);
274274
}
275275

276-
for(const exprt &code : tmp_block.operands())
277-
output_code.add(to_code(code));
276+
for(const auto &code : tmp_block.statements())
277+
output_code.add(code);
278+
278279
return dynamic_object;
279280
}
280281

src/ansi-c/c_typecheck_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class c_typecheck_baset:
125125

126126
virtual void typecheck_assign(codet &expr);
127127
virtual void typecheck_asm(codet &code);
128-
virtual void typecheck_block(codet &code);
128+
virtual void typecheck_block(code_blockt &code);
129129
virtual void typecheck_break(codet &code);
130130
virtual void typecheck_continue(codet &code);
131131
virtual void typecheck_decl(codet &code);

src/ansi-c/c_typecheck_code.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void c_typecheck_baset::typecheck_code(codet &code)
4343
else if(statement==ID_gcc_switch_case_range)
4444
typecheck_gcc_switch_case_range(code);
4545
else if(statement==ID_block)
46-
typecheck_block(code);
46+
typecheck_block(to_code_block(code));
4747
else if(statement==ID_decl_block)
4848
{
4949
}
@@ -181,23 +181,21 @@ void c_typecheck_baset::typecheck_assign(codet &code)
181181
implicit_typecast(code.op1(), code.op0().type());
182182
}
183183

184-
void c_typecheck_baset::typecheck_block(codet &code)
184+
void c_typecheck_baset::typecheck_block(code_blockt &code)
185185
{
186-
Forall_operands(it, code)
187-
typecheck_code(to_code(*it));
186+
for(auto &c : code.statements())
187+
typecheck_code(c);
188188

189189
// do decl-blocks
190190

191191
code_blockt new_ops;
192-
new_ops.operands().reserve(code.operands().size());
192+
new_ops.statements().reserve(code.statements().size());
193193

194-
Forall_operands(it1, code)
194+
for(auto &code_op : code.statements())
195195
{
196-
if(it1->is_nil())
196+
if(code_op.is_nil())
197197
continue;
198198

199-
codet &code_op=to_code(*it1);
200-
201199
if(code_op.get_statement()==ID_label)
202200
{
203201
// these may be nested
@@ -217,7 +215,7 @@ void c_typecheck_baset::typecheck_block(codet &code)
217215
new_ops.move(code_op);
218216
}
219217

220-
code.operands().swap(new_ops.operands());
218+
code.statements().swap(new_ops.statements());
221219
}
222220

223221
void c_typecheck_baset::typecheck_break(codet &code)

src/ansi-c/expr2c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,12 +2835,12 @@ std::string expr2ct::convert_code_block(
28352835
std::string dest=indent_str(indent);
28362836
dest+="{\n";
28372837

2838-
forall_operands(it, src)
2838+
for(const auto &c : src.statements())
28392839
{
2840-
if(it->get(ID_statement)==ID_label)
2841-
dest+=convert_code(to_code(*it), indent);
2840+
if(c.get_statement() == ID_label)
2841+
dest += convert_code(c, indent);
28422842
else
2843-
dest+=convert_code(to_code(*it), indent+2);
2843+
dest += convert_code(c, indent + 2);
28442844

28452845
dest+="\n";
28462846
}

src/cpp/cpp_constructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
259259

260260
tmp_this=address_of_exprt(object_tc);
261261

262-
if(block.operands().empty())
262+
if(block.statements().empty())
263263
return to_code(initializer);
264264
else
265265
{

src/cpp/cpp_typecheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class cpp_typecheckt:public c_typecheck_baset
420420
virtual void typecheck_try_catch(codet &code);
421421
virtual void typecheck_member_initializer(codet &code);
422422
virtual void typecheck_decl(codet &code);
423-
virtual void typecheck_block(codet &code);
423+
virtual void typecheck_block(code_blockt &code);
424424
virtual void typecheck_ifthenelse(code_ifthenelset &code);
425425
virtual void typecheck_while(code_whilet &code);
426426
virtual void typecheck_switch(code_switcht &code);

src/cpp/cpp_typecheck_code.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void cpp_typecheckt::typecheck_decl(codet &code)
450450
code.swap(new_code);
451451
}
452452

453-
void cpp_typecheckt::typecheck_block(codet &code)
453+
void cpp_typecheckt::typecheck_block(code_blockt &code)
454454
{
455455
cpp_save_scopet saved_scope(cpp_scopes);
456456
cpp_scopes.new_block_scope();

src/cpp/cpp_typecheck_destructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
9292
ptrmember.operands().push_back(exprt("cpp-this"));
9393

9494
code_assignt assign(ptrmember, address);
95-
block.operands().push_back(assign);
95+
block.add(assign);
9696
continue;
9797
}
9898
}

src/goto-instrument/dump_c.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ void dump_ct::cleanup_decl(
621621
system_headers);
622622
p2s();
623623

624-
POSTCONDITION(b.operands().size()==1);
624+
POSTCONDITION(b.statements().size() == 1);
625625
decl.swap(b.op0());
626626
}
627627

@@ -943,10 +943,8 @@ void dump_ct::cleanup_harness(code_blockt &b)
943943
decls.add(d);
944944
}
945945

946-
Forall_operands(it, b)
946+
for(auto &code : b.statements())
947947
{
948-
codet &code=to_code(*it);
949-
950948
if(code.get_statement()==ID_function_call)
951949
{
952950
exprt &func=to_code_function_call(code).function();

src/goto-instrument/goto_program2code.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,20 +1686,18 @@ static bool has_labels(const codet &code)
16861686
return false;
16871687
}
16881688

1689-
static bool move_label_ifthenelse(
1690-
exprt &expr,
1691-
exprt &label_dest)
1689+
static bool move_label_ifthenelse(exprt &expr, exprt &label_dest)
16921690
{
1693-
if(expr.is_nil() ||
1694-
to_code(expr).get_statement()!=ID_block)
1691+
if(expr.is_nil() || to_code(expr).get_statement() != ID_block)
16951692
return false;
16961693

16971694
code_blockt &block=to_code_block(to_code(expr));
1698-
if(!block.has_operands() ||
1699-
to_code(block.operands().back()).get_statement()!=ID_label)
1695+
if(
1696+
block.statements().empty() ||
1697+
block.statements().back().get_statement() != ID_label)
17001698
return false;
17011699

1702-
code_labelt &label=to_code_label(to_code(block.operands().back()));
1700+
code_labelt &label = to_code_label(block.statements().back());
17031701
if(label.get_label().empty() ||
17041702
label.code().get_statement()!=ID_skip)
17051703
return false;

src/goto-programs/goto_convert.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,8 @@ void goto_convertt::convert_block(
547547
std::size_t old_stack_size=targets.destructor_stack.size();
548548

549549
// now convert block
550-
forall_operands(it, code)
551-
{
552-
const codet &b_code=to_code(*it);
553-
convert(b_code, dest, mode);
554-
}
550+
for(const auto &s : code.statements())
551+
convert(s, dest, mode);
555552

556553
// see if we need to do any destructors -- may have been processed
557554
// in a prior break/continue/return already, don't create dead code

src/jsil/jsil_parse_tree.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ static bool insert_at_label(
2222
const irep_idt &label,
2323
code_blockt &dest)
2424
{
25-
Forall_operands(it, dest)
25+
for(auto &c : dest.statements())
2626
{
27-
codet &c=to_code(*it);
28-
2927
if(c.get_statement()!=ID_label)
3028
continue;
3129

src/util/format_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ std::ostream &format_rec(std::ostream &os, const exprt &expr)
270270
else if(statement == ID_block)
271271
{
272272
os << '{';
273-
for(const auto &s : to_code_block(code).operands())
273+
for(const auto &s : to_code_block(code).statements())
274274
os << ' ' << format(s);
275275
return os << " }";
276276
}

src/util/std_code.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ const codet &codet::last_statement() const
111111
/// \param extra_block: The input code_blockt
112112
void code_blockt::append(const code_blockt &extra_block)
113113
{
114-
operands().reserve(operands().size()+extra_block.operands().size());
114+
statements().reserve(statements().size() + extra_block.statements().size());
115115

116-
for(const auto &operand : extra_block.operands())
116+
for(const auto &s : extra_block.statements())
117117
{
118-
add(to_code(operand));
118+
add(s);
119119
}
120120
}
121121

@@ -125,8 +125,8 @@ code_blockt create_fatal_assertion(
125125
code_blockt result;
126126
result.add(code_assertt(condition));
127127
result.add(code_assumet(condition));
128-
for(auto &op : result.operands())
129-
op.add_source_location() = loc;
128+
for(auto &s : result.statements())
129+
s.add_source_location() = loc;
130130
result.add_source_location() = loc;
131131
return result;
132132
}

src/util/std_code.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,43 @@ inline codet &to_code(exprt &expr)
101101
class code_blockt:public codet
102102
{
103103
public:
104+
typedef std::vector<codet> code_operandst;
105+
106+
code_operandst &code_operands()
107+
{
108+
return (code_operandst &)get_sub();
109+
}
110+
111+
const code_operandst &code_operands() const
112+
{
113+
return (const code_operandst &)get_sub();
114+
}
115+
104116
code_blockt():codet(ID_block)
105117
{
106118
}
107119

108120
explicit code_blockt(const std::list<codet> &_list):codet(ID_block)
109121
{
110-
operandst &o=operands();
111-
reserve_operands(_list.size());
122+
auto &o = code_operands();
123+
o.reserve(_list.size());
112124
for(std::list<codet>::const_iterator
113125
it=_list.begin();
114126
it!=_list.end();
115127
it++)
116128
o.push_back(*it);
117129
}
118130

131+
code_operandst &statements()
132+
{
133+
return code_operands();
134+
}
135+
136+
const code_operandst &statements() const
137+
{
138+
return code_operands();
139+
}
140+
119141
void move(codet &code)
120142
{
121143
exprt::move_to_operands(code);

0 commit comments

Comments
 (0)