Skip to content

Commit 201ba8c

Browse files
Merge pull request diffblue#2581 from romainbrenguier/refactor/to_code
Remove unnecessary cast to_code
2 parents bb7ea78 + e4b8c44 commit 201ba8c

13 files changed

+57
-63
lines changed

jbmc/src/java_bytecode/replace_java_nondet.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ get_nondet_instruction_info(const goto_programt::const_targett &instr)
9292
{
9393
return nondet_instruction_infot();
9494
}
95-
const auto &code = to_code(instr->code);
96-
if(code.get_statement() != ID_function_call)
97-
{
98-
return nondet_instruction_infot();
99-
}
95+
const auto &code = instr->code;
96+
INVARIANT(
97+
code.get_statement() == ID_function_call,
98+
"function_call should have ID_function_call");
10099
const auto &function_call = to_code_function_call(code);
101100
return is_nondet_returning_object(function_call);
102101
}

src/analyses/flow_insensitive_analysis.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,13 @@ exprt flow_insensitive_abstract_domain_baset::get_guard(
4040
exprt flow_insensitive_abstract_domain_baset::get_return_lhs(locationt to) const
4141
{
4242
// get predecessor of "to"
43-
4443
to--;
4544

4645
if(to->is_end_function())
4746
return static_cast<const exprt &>(get_nil_irep());
4847

4948
// must be the function call
50-
assert(to->is_function_call());
51-
52-
const code_function_callt &code=
53-
to_code_function_call(to_code(to->code));
54-
55-
return code.lhs();
49+
return to_code_function_call(to->code).lhs();
5650
}
5751

5852
void flow_insensitive_analysis_baset::operator()(
@@ -164,8 +158,7 @@ bool flow_insensitive_analysis_baset::visit(
164158
if(l->is_function_call())
165159
{
166160
// this is a big special case
167-
const code_function_callt &code=
168-
to_code_function_call(to_code(l->code));
161+
const code_function_callt &code = to_code_function_call(l->code);
169162

170163
changed=
171164
do_function_call_rec(
@@ -213,8 +206,7 @@ bool flow_insensitive_analysis_baset::do_function_call(
213206

214207
if(!goto_function.body_available())
215208
{
216-
const code_function_callt &code =
217-
to_code_function_call(to_code(l_call->code));
209+
const code_function_callt &code = to_code_function_call(l_call->code);
218210

219211
goto_programt temp;
220212

src/ansi-c/c_typecheck_code.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void c_typecheck_baset::typecheck_ifthenelse(code_ifthenelset &code)
626626

627627
implicit_typecast_bool(cond);
628628

629-
if(to_code(code.then_case()).get_statement()==ID_decl_block)
629+
if(code.then_case().get_statement() == ID_decl_block)
630630
{
631631
code_blockt code_block;
632632
code_block.add_source_location()=code.then_case().source_location();
@@ -635,11 +635,11 @@ void c_typecheck_baset::typecheck_ifthenelse(code_ifthenelset &code)
635635
code.then_case().swap(code_block);
636636
}
637637

638-
typecheck_code(to_code(code.then_case()));
638+
typecheck_code(code.then_case());
639639

640640
if(!code.else_case().is_nil())
641641
{
642-
if(to_code(code.else_case()).get_statement()==ID_decl_block)
642+
if(code.else_case().get_statement() == ID_decl_block)
643643
{
644644
code_blockt code_block;
645645
code_block.add_source_location()=code.else_case().source_location();
@@ -648,7 +648,7 @@ void c_typecheck_baset::typecheck_ifthenelse(code_ifthenelset &code)
648648
code.else_case().swap(code_block);
649649
}
650650

651-
typecheck_code(to_code(code.else_case()));
651+
typecheck_code(code.else_case());
652652
}
653653
}
654654

src/ansi-c/expr2c.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -2593,19 +2593,19 @@ std::string expr2ct::convert_code_ifthenelse(
25932593
dest+=';';
25942594
}
25952595
else
2596-
dest+=convert_code(
2597-
to_code(src.then_case()),
2598-
to_code(src.then_case()).get_statement()==ID_block ? indent : indent+2);
2596+
dest += convert_code(
2597+
src.then_case(),
2598+
src.then_case().get_statement() == ID_block ? indent : indent + 2);
25992599
dest+="\n";
26002600

26012601
if(!src.else_case().is_nil())
26022602
{
26032603
dest+="\n";
26042604
dest+=indent_str(indent);
26052605
dest+="else\n";
2606-
dest+=convert_code(
2607-
to_code(src.else_case()),
2608-
to_code(src.else_case()).get_statement()==ID_block ? indent : indent+2);
2606+
dest += convert_code(
2607+
src.else_case(),
2608+
src.else_case().get_statement() == ID_block ? indent : indent + 2);
26092609
}
26102610

26112611
return dest;

src/goto-instrument/goto_program2code.cpp

+30-26
Original file line numberDiff line numberDiff line change
@@ -1117,17 +1117,17 @@ goto_programt::const_targett goto_program2codet::convert_goto_if(
11171117
if(has_else)
11181118
{
11191119
for(++target; target!=before_else; ++target)
1120-
target=convert_instruction(target, before_else, to_code(i.then_case()));
1120+
target = convert_instruction(target, before_else, i.then_case());
11211121

1122-
convert_labels(before_else, to_code(i.then_case()));
1122+
convert_labels(before_else, i.then_case());
11231123

11241124
for(++target; target!=end_if; ++target)
1125-
target=convert_instruction(target, end_if, to_code(i.else_case()));
1125+
target = convert_instruction(target, end_if, i.else_case());
11261126
}
11271127
else
11281128
{
11291129
for(++target; target!=end_if; ++target)
1130-
target=convert_instruction(target, end_if, to_code(i.then_case()));
1130+
target = convert_instruction(target, end_if, i.then_case());
11311131
}
11321132

11331133
dest.move_to_operands(i);
@@ -1354,12 +1354,12 @@ goto_programt::const_targett goto_program2codet::convert_start_thread(
13541354

13551355
// use pthreads if "code in new thread" is a function call to a function with
13561356
// suitable signature
1357-
if(thread_start->is_function_call() &&
1358-
to_code_function_call(to_code(thread_start->code)).arguments().size()==1 &&
1359-
after_thread_start==thread_end)
1357+
if(
1358+
thread_start->is_function_call() &&
1359+
to_code_function_call(thread_start->code).arguments().size() == 1 &&
1360+
after_thread_start == thread_end)
13601361
{
1361-
const code_function_callt &cf=
1362-
to_code_function_call(to_code(thread_start->code));
1362+
const code_function_callt &cf = to_code_function_call(thread_start->code);
13631363

13641364
system_headers.insert("pthread.h");
13651365

@@ -1730,14 +1730,15 @@ void goto_program2codet::cleanup_code_ifthenelse(
17301730

17311731
// assert(false) expands to if(true) assert(false), simplify again (and also
17321732
// simplify other cases)
1733-
if(cond.is_true() &&
1734-
(i_t_e.else_case().is_nil() || !has_labels(to_code(i_t_e.else_case()))))
1733+
if(
1734+
cond.is_true() &&
1735+
(i_t_e.else_case().is_nil() || !has_labels(i_t_e.else_case())))
17351736
{
17361737
codet tmp;
17371738
tmp.swap(i_t_e.then_case());
17381739
code.swap(tmp);
17391740
}
1740-
else if(cond.is_false() && !has_labels(to_code(i_t_e.then_case())))
1741+
else if(cond.is_false() && !has_labels(i_t_e.then_case()))
17411742
{
17421743
if(i_t_e.else_case().is_nil())
17431744
code=code_skipt();
@@ -1750,8 +1751,9 @@ void goto_program2codet::cleanup_code_ifthenelse(
17501751
}
17511752
else
17521753
{
1753-
if(i_t_e.then_case().is_not_nil() &&
1754-
to_code(i_t_e.then_case()).get_statement()==ID_ifthenelse)
1754+
if(
1755+
i_t_e.then_case().is_not_nil() &&
1756+
i_t_e.then_case().get_statement() == ID_ifthenelse)
17551757
{
17561758
// we re-introduce 1-code blocks with if-then-else to avoid dangling-else
17571759
// ambiguity
@@ -1760,9 +1762,10 @@ void goto_program2codet::cleanup_code_ifthenelse(
17601762
i_t_e.then_case().swap(b);
17611763
}
17621764

1763-
if(i_t_e.else_case().is_not_nil() &&
1764-
to_code(i_t_e.then_case()).get_statement()==ID_skip &&
1765-
to_code(i_t_e.else_case()).get_statement()==ID_ifthenelse)
1765+
if(
1766+
i_t_e.else_case().is_not_nil() &&
1767+
i_t_e.then_case().get_statement() == ID_skip &&
1768+
i_t_e.else_case().get_statement() == ID_ifthenelse)
17661769
{
17671770
// we re-introduce 1-code blocks with if-then-else to avoid dangling-else
17681771
// ambiguity
@@ -1795,8 +1798,9 @@ void goto_program2codet::cleanup_code_ifthenelse(
17951798
}
17961799

17971800
// remove empty then/else
1798-
if(code.get_statement()==ID_ifthenelse &&
1799-
to_code(i_t_e.then_case()).get_statement()==ID_skip)
1801+
if(
1802+
code.get_statement() == ID_ifthenelse &&
1803+
i_t_e.then_case().get_statement() == ID_skip)
18001804
{
18011805
not_exprt tmp(i_t_e.cond());
18021806
simplify(tmp, ns);
@@ -1805,15 +1809,15 @@ void goto_program2codet::cleanup_code_ifthenelse(
18051809
i_t_e.cond().swap(tmp);
18061810
i_t_e.then_case().swap(i_t_e.else_case());
18071811
}
1808-
if(code.get_statement()==ID_ifthenelse &&
1809-
i_t_e.else_case().is_not_nil() &&
1810-
to_code(i_t_e.else_case()).get_statement()==ID_skip)
1812+
if(
1813+
code.get_statement() == ID_ifthenelse && i_t_e.else_case().is_not_nil() &&
1814+
i_t_e.else_case().get_statement() == ID_skip)
18111815
i_t_e.else_case().make_nil();
18121816
// or even remove the if altogether if the then case is now empty
1813-
if(code.get_statement()==ID_ifthenelse &&
1814-
i_t_e.else_case().is_nil() &&
1815-
(i_t_e.then_case().is_nil() ||
1816-
to_code(i_t_e.then_case()).get_statement()==ID_skip))
1817+
if(
1818+
code.get_statement() == ID_ifthenelse && i_t_e.else_case().is_nil() &&
1819+
(i_t_e.then_case().is_nil() ||
1820+
i_t_e.then_case().get_statement() == ID_skip))
18171821
code=code_skipt();
18181822
}
18191823

src/goto-programs/goto_convert.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1569,12 +1569,12 @@ void goto_convertt::convert_ifthenelse(
15691569

15701570
// convert 'then'-branch
15711571
goto_programt tmp_then;
1572-
convert(to_code(code.then_case()), tmp_then, mode);
1572+
convert(code.then_case(), tmp_then, mode);
15731573

15741574
goto_programt tmp_else;
15751575

15761576
if(has_else)
1577-
convert(to_code(code.else_case()), tmp_else, mode);
1577+
convert(code.else_case(), tmp_else, mode);
15781578

15791579
exprt tmp_guard=code.cond();
15801580
clean_expr(tmp_guard, dest, mode);

src/goto-programs/remove_unused_functions.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ void find_used_functions(
7575
{
7676
if(it->type==FUNCTION_CALL)
7777
{
78-
const code_function_callt &call =
79-
to_code_function_call(to_code(it->code));
78+
const code_function_callt &call = to_code_function_call(it->code);
8079

8180
// check that this is actually a simple call
8281
assert(call.function().id()==ID_symbol);

src/goto-symex/memory_model_tso.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void memory_model_tsot::program_order(
107107

108108
if((*e_it2)->is_memory_barrier())
109109
{
110-
const codet &code=to_code((*e_it2)->source.pc->code);
110+
const codet &code = (*e_it2)->source.pc->code;
111111

112112
if((*e_it)->is_shared_read() &&
113113
!code.get_bool(ID_RRfence) &&

src/goto-symex/symex_dead.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void goto_symext::symex_dead(statet &state)
2121
{
2222
const goto_programt::instructiont &instruction=*state.source.pc;
2323

24-
const codet &code=to_code(instruction.code);
24+
const codet &code = instruction.code;
2525

2626
if(code.operands().size()!=1)
2727
throw "dead expects one operand";

src/goto-symex/symex_decl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void goto_symext::symex_decl(statet &state)
2323
{
2424
const goto_programt::instructiont &instruction=*state.source.pc;
2525

26-
const codet &code=to_code(instruction.code);
26+
const codet &code = instruction.code;
2727

2828
if(code.operands().size()==2)
2929
throw "two-operand decl not supported here";

src/goto-symex/symex_other.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void goto_symext::symex_other(
7878
{
7979
const goto_programt::instructiont &instruction=*state.source.pc;
8080

81-
const codet &code=to_code(instruction.code);
81+
const codet &code = instruction.code;
8282

8383
const irep_idt &statement=code.get_statement();
8484

src/jsil/jsil_typecheck.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -832,10 +832,10 @@ void jsil_typecheckt::typecheck_ifthenelse(code_ifthenelset &code)
832832
typecheck_expr(cond);
833833
make_type_compatible(cond, bool_typet(), true);
834834

835-
typecheck_code(to_code(code.then_case()));
835+
typecheck_code(code.then_case());
836836

837837
if(!code.else_case().is_nil())
838-
typecheck_code(to_code(code.else_case()));
838+
typecheck_code(code.else_case());
839839
}
840840

841841
void jsil_typecheckt::typecheck_assign(code_assignt &code)

src/pointer-analysis/goto_program_dereference.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void goto_program_dereferencet::dereference_instruction(
307307
}
308308
else if(i.is_function_call())
309309
{
310-
code_function_callt &function_call=to_code_function_call(to_code(i.code));
310+
code_function_callt &function_call = to_code_function_call(i.code);
311311

312312
if(function_call.lhs().is_not_nil())
313313
dereference_expr(

0 commit comments

Comments
 (0)