Skip to content

Commit 658c93f

Browse files
author
Daniel Kroening
committed
better typing for statements in code_blockt
1 parent 5a8e79d commit 658c93f

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

@@ -939,10 +939,8 @@ void dump_ct::cleanup_harness(code_blockt &b)
939939
decls.add(d);
940940
}
941941

942-
Forall_operands(it, b)
942+
for(auto &code : b.statements())
943943
{
944-
codet &code=to_code(*it);
945-
946944
if(code.get_statement()==ID_function_call)
947945
{
948946
exprt &func=to_code_function_call(code).function();

src/goto-instrument/goto_program2code.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,19 +1695,19 @@ static bool has_labels(const codet &code)
16951695
}
16961696

16971697
static bool move_label_ifthenelse(
1698-
exprt &expr,
1699-
exprt &label_dest)
1698+
exprt &expr,
1699+
exprt &label_dest)
17001700
{
17011701
if(expr.is_nil() ||
1702-
to_code(expr).get_statement()!=ID_block)
1702+
to_code(expr).get_statement()!=ID_block)
17031703
return false;
17041704

17051705
code_blockt &block=to_code_block(to_code(expr));
1706-
if(!block.has_operands() ||
1707-
to_code(block.operands().back()).get_statement()!=ID_label)
1706+
if(block.statements().empty() ||
1707+
block.statements().back().get_statement()!=ID_label)
17081708
return false;
17091709

1710-
code_labelt &label=to_code_label(to_code(block.operands().back()));
1710+
code_labelt &label=to_code_label(block.statements().back());
17111711
if(label.get_label().empty() ||
17121712
label.code().get_statement()!=ID_skip)
17131713
return false;

src/goto-programs/goto_convert.cpp

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

578578
// now convert block
579-
forall_operands(it, code)
580-
{
581-
const codet &b_code=to_code(*it);
582-
convert(b_code, dest, mode);
583-
}
579+
for(const auto &s : code.statements())
580+
convert(s, dest, mode);
584581

585582
// see if we need to do any destructors -- may have been processed
586583
// 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
@@ -265,7 +265,7 @@ std::ostream &format_rec(std::ostream &os, const exprt &expr)
265265
else if(statement == ID_block)
266266
{
267267
os << '{';
268-
for(const auto &s : to_code_block(code).operands())
268+
for(const auto &s : to_code_block(code).statements())
269269
os << ' ' << format(s);
270270
return os << " }";
271271
}

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: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,39 @@ 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+
{ return (code_operandst &)get_sub(); }
108+
109+
const code_operandst &code_operands() const
110+
{ return (const code_operandst &)get_sub(); }
111+
104112
code_blockt():codet(ID_block)
105113
{
106114
}
107115

108116
explicit code_blockt(const std::list<codet> &_list):codet(ID_block)
109117
{
110-
operandst &o=operands();
111-
reserve_operands(_list.size());
118+
auto &o=code_operands();
119+
o.reserve(_list.size());
112120
for(std::list<codet>::const_iterator
113121
it=_list.begin();
114122
it!=_list.end();
115123
it++)
116124
o.push_back(*it);
117125
}
118126

127+
code_operandst &statements()
128+
{
129+
return code_operands();
130+
}
131+
132+
const code_operandst &statements() const
133+
{
134+
return code_operands();
135+
}
136+
119137
void move(codet &code)
120138
{
121139
exprt::move_to_operands(code);

0 commit comments

Comments
 (0)