Skip to content

Commit 2dc9574

Browse files
author
Daniel Kroening
authored
Merge pull request #3080 from diffblue/code_blockt_operands
added code_blockt::statements(), which is a vector of codet
2 parents 95fe44b + 7d8b70c commit 2dc9574

12 files changed

+64
-48
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 16 additions & 16 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)
876876
newblock.move_to_operands(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

@@ -920,7 +920,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
920920
return
921921
to_code_block(
922922
to_code_label(
923-
to_code(this_block_children[child_offset])).code());
923+
this_block_children[child_offset]).code());
924924
}
925925

926926
static void gather_symbol_live_ranges(
@@ -1765,12 +1765,12 @@ codet java_bytecode_convert_methodt::convert_instructions(
17651765
last_statement.make_block();
17661766
last_statement.operands().insert(
17671767
last_statement.operands().begin(),
1768-
more_code.operands().begin(),
1769-
more_code.operands().end());
1768+
more_code.statements().begin(),
1769+
more_code.statements().end());
17701770
}
17711771
else
1772-
forall_operands(o_it, more_code)
1773-
c.copy_to_operands(*o_it);
1772+
for(const auto &statement : more_code.statements())
1773+
c.copy_to_operands(statement);
17741774
}
17751775
}
17761776
a_it2->second.stack=stack;
@@ -1844,7 +1844,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
18441844

18451845
if(c.get_statement()!=ID_skip)
18461846
{
1847-
auto &lastlabel=to_code_label(to_code(root_block.operands().back()));
1847+
auto &lastlabel = to_code_label(root_block.statements().back());
18481848
auto &add_to_block=to_code_block(lastlabel.code());
18491849
add_to_block.add(c);
18501850
}
@@ -1908,10 +1908,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
19081908
v.start_pc + v.length,
19091909
std::numeric_limits<method_offsett>::max());
19101910
code_declt d(v.symbol_expr);
1911-
block.operands().insert(block.operands().begin(), d);
1911+
block.statements().insert(block.statements().begin(), d);
19121912
}
19131913

1914-
for(auto &block : root_block.operands())
1914+
for(auto &block : root_block.statements())
19151915
code.move_to_operands(block);
19161916

19171917
return code;

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

jbmc/src/java_bytecode/simple_method_stubbing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ void java_simple_method_stubst::create_method_stub_at(
127127
: update_in_placet::NO_UPDATE_IN_PLACE);
128128

129129
// Insert new_instructions into parent block.
130-
if(!new_instructions.operands().empty())
130+
if(!new_instructions.statements().empty())
131131
{
132-
auto insert_position = parent_block.operands().begin();
132+
auto insert_position = parent_block.statements().begin();
133133
std::advance(insert_position, insert_before_index);
134-
parent_block.operands().insert(
134+
parent_block.statements().insert(
135135
insert_position,
136-
new_instructions.operands().begin(),
137-
new_instructions.operands().end());
136+
new_instructions.statements().begin(),
137+
new_instructions.statements().end());
138138
}
139139
}
140140

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 &statement : src.statements())
28392839
{
2840-
if(it->get(ID_statement)==ID_label)
2841-
dest+=convert_code(to_code(*it), indent);
2840+
if(statement.get_statement() == ID_label)
2841+
dest += convert_code(statement, indent);
28422842
else
2843-
dest+=convert_code(to_code(*it), indent+2);
2843+
dest += convert_code(statement, indent + 2);
28442844

28452845
dest+="\n";
28462846
}

src/cpp/cpp_constructor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
247247

248248
tmp_this=address_of_exprt(object_tc);
249249

250-
if(block.operands().empty())
251-
return to_code(initializer);
250+
const auto &initializer_code=to_code(initializer);
251+
252+
if(block.statements().empty())
253+
return initializer_code;
252254
else
253255
{
254-
block.move_to_operands(initializer);
256+
block.add(initializer_code);
255257
return block;
256258
}
257259
}

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/goto_program2code.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,14 +1690,20 @@ static bool move_label_ifthenelse(
16901690
return false;
16911691

16921692
code_blockt &block=to_code_block(to_code(expr));
1693-
if(!block.has_operands() ||
1694-
to_code(block.operands().back()).get_statement()!=ID_label)
1693+
if(
1694+
!block.has_operands() ||
1695+
block.statements().back().get_statement() != ID_label)
1696+
{
16951697
return false;
1698+
}
1699+
1700+
code_labelt &label = to_code_label(block.statements().back());
16961701

1697-
code_labelt &label=to_code_label(to_code(block.operands().back()));
16981702
if(label.get_label().empty() ||
16991703
label.code().get_statement()!=ID_skip)
1704+
{
17001705
return false;
1706+
}
17011707

17021708
label_dest=label;
17031709
code_skipt s;

src/goto-programs/goto_convert.cpp

Lines changed: 1 addition & 4 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);
550+
for(const auto &b_code : code.statements())
553551
convert(b_code, dest, mode);
554-
}
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 &statement : extra_block.statements())
117117
{
118-
add(to_code(operand));
118+
add(statement);
119119
}
120120
}
121121

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

src/util/std_code.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,21 @@ class code_blockt:public codet
105105
{
106106
}
107107

108+
typedef std::vector<codet> code_operandst;
109+
110+
code_operandst &statements()
111+
{
112+
return (code_operandst &)get_sub();
113+
}
114+
115+
const code_operandst &statements() const
116+
{
117+
return (const code_operandst &)get_sub();
118+
}
119+
108120
explicit code_blockt(const std::list<codet> &_list):codet(ID_block)
109121
{
110-
operandst &o=operands();
122+
auto &o = statements();
111123
reserve_operands(_list.size());
112124
for(std::list<codet>::const_iterator
113125
it=_list.begin();

0 commit comments

Comments
 (0)