Skip to content

Commit b5df13b

Browse files
committed
Refactor dump_ct::cleanup_decl
To avoid repeatedly checking the same condition and so that `value` is only in scope where it is required and non-empty.
1 parent 8a14e67 commit b5df13b

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/goto-instrument/dump_c.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -650,19 +650,15 @@ void dump_ct::cleanup_decl(
650650
std::list<irep_idt> &local_static,
651651
std::list<irep_idt> &local_type_decls)
652652
{
653-
const optionalt<exprt> value = decl.initial_value();
653+
goto_programt tmp;
654+
tmp.add(goto_programt::make_decl(decl.symbol()));
654655

655-
if(value)
656+
if(optionalt<exprt> value = decl.initial_value())
656657
{
657658
decl.set_initial_value({});
659+
tmp.add(goto_programt::make_assignment(decl.symbol(), std::move(*value)));
658660
}
659661

660-
goto_programt tmp;
661-
tmp.add(goto_programt::make_decl(decl.symbol()));
662-
663-
if(value)
664-
tmp.add(goto_programt::make_assignment(decl.symbol(), *value));
665-
666662
tmp.add(goto_programt::make_end_function());
667663

668664
// goto_program2codet requires valid location numbers:

0 commit comments

Comments
 (0)