Skip to content

Commit 3dd0a63

Browse files
committed
better typing for statements in code_blockt
1 parent e24d8f4 commit 3dd0a63

16 files changed

+77
-67
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
@@ -787,16 +787,16 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
787787
return this_block;
788788

789789
// Find the child code_blockt where the queried range begins:
790-
auto child_iter=this_block.operands().begin();
790+
auto child_iter=this_block.statements().begin();
791791
// Skip any top-of-block declarations;
792792
// all other children are labelled subblocks.
793-
while(child_iter!=this_block.operands().end() &&
794-
to_code(*child_iter).get_statement()==ID_decl)
793+
while(child_iter!=this_block.statements().end() &&
794+
child_iter->get_statement()==ID_decl)
795795
++child_iter;
796-
assert(child_iter!=this_block.operands().end());
796+
assert(child_iter!=this_block.statements().end());
797797
std::advance(child_iter, child_offset);
798-
assert(child_iter!=this_block.operands().end());
799-
auto &child_label=to_code_label(to_code(*child_iter));
798+
assert(child_iter!=this_block.statements().end());
799+
auto &child_label=to_code_label(*child_iter);
800800
auto &child_block=to_code_block(child_label.code());
801801

802802
bool single_child(afterstart==findlim);
@@ -866,15 +866,15 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
866866
<< findlim_block_start_address << eom;
867867

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

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

@@ -1761,15 +1761,15 @@ codet java_bytecode_convert_methodt::convert_instructions(
17611761
if(last_statement.get_statement()==ID_goto)
17621762
{
17631763
// Insert stack twiddling before branch:
1764-
last_statement.make_block();
1765-
last_statement.operands().insert(
1766-
last_statement.operands().begin(),
1767-
more_code.operands().begin(),
1768-
more_code.operands().end());
1764+
auto &block=last_statement.make_block();
1765+
block.statements().insert(
1766+
block.statements().begin(),
1767+
more_code.statements().begin(),
1768+
more_code.statements().end());
17691769
}
17701770
else
1771-
forall_operands(o_it, more_code)
1772-
c.copy_to_operands(*o_it);
1771+
for(const auto &m_c_s : more_code.statements())
1772+
to_code_block(c).add(m_c_s);
17731773
}
17741774
}
17751775
a_it2->second.stack=stack;
@@ -1843,7 +1843,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
18431843

18441844
if(c.get_statement()!=ID_skip)
18451845
{
1846-
auto &lastlabel=to_code_label(to_code(root_block.operands().back()));
1846+
auto &lastlabel=to_code_label(root_block.statements().back());
18471847
auto &add_to_block=to_code_block(lastlabel.code());
18481848
add_to_block.add(c);
18491849
}
@@ -1907,11 +1907,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
19071907
v.start_pc+v.length,
19081908
std::numeric_limits<unsigned>::max());
19091909
code_declt d(v.symbol_expr);
1910-
block.operands().insert(block.operands().begin(), d);
1910+
block.statements().insert(block.statements().begin(), d);
19111911
}
19121912

1913-
for(auto &block : root_block.operands())
1914-
code.move(to_code(block));
1913+
for(auto &block : root_block.statements())
1914+
code.move(block);
19151915

19161916
return code;
19171917
}

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
@@ -2840,12 +2840,12 @@ std::string expr2ct::convert_code_block(
28402840
std::string dest=indent_str(indent);
28412841
dest+="{\n";
28422842

2843-
forall_operands(it, src)
2843+
for(const auto &c : src.statements())
28442844
{
2845-
if(it->get(ID_statement)==ID_label)
2846-
dest+=convert_code(to_code(*it), indent);
2845+
if(c.get_statement()==ID_label)
2846+
dest+=convert_code(c, indent);
28472847
else
2848-
dest+=convert_code(to_code(*it), indent+2);
2848+
dest+=convert_code(c, indent+2);
28492849

28502850
dest+="\n";
28512851
}

src/cpp/cpp_constructor.cpp

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

267267
tmp_this=address_of_exprt(object_tc);
268268

269-
if(block.operands().empty())
269+
if(block.statements().empty())
270270
return to_code(initializer);
271271
else
272272
{

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
@@ -447,7 +447,7 @@ void cpp_typecheckt::typecheck_decl(codet &code)
447447
code.swap(new_code);
448448
}
449449

450-
void cpp_typecheckt::typecheck_block(codet &code)
450+
void cpp_typecheckt::typecheck_block(code_blockt &code)
451451
{
452452
cpp_save_scopet saved_scope(cpp_scopes);
453453
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
@@ -108,7 +108,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
108108
ptrmember.operands().push_back(exprt("cpp-this"));
109109

110110
code_assignt assign(ptrmember, address);
111-
block.operands().push_back(assign);
111+
block.add(assign);
112112
continue;
113113
}
114114
}

src/goto-instrument/dump_c.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ void dump_ct::cleanup_decl(
624624
system_headers);
625625
p2s();
626626

627-
POSTCONDITION(b.operands().size()==1);
627+
POSTCONDITION(b.statements().size()==1);
628628
decl.swap(b.op0());
629629
}
630630

@@ -936,10 +936,8 @@ void dump_ct::cleanup_harness(code_blockt &b)
936936
decls.add(d);
937937
}
938938

939-
Forall_operands(it, b)
939+
for(auto &code : b.statements())
940940
{
941-
codet &code=to_code(*it);
942-
943941
if(code.get_statement()==ID_function_call)
944942
{
945943
exprt &func=to_code_function_call(code).function();

0 commit comments

Comments
 (0)