From 84514d0d1084f6d8a4adb1c262635f020ed05f6f Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Thu, 31 Jan 2019 09:04:45 +0000 Subject: [PATCH] Use goto_programt::make_X factories in goto_convert_exceptions and goto_inline_class This reduces code complexity. --- src/goto-programs/goto_convert_exceptions.cpp | 22 ++++++++----------- src/goto-programs/goto_inline_class.cpp | 12 ++++------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/goto-programs/goto_convert_exceptions.cpp b/src/goto-programs/goto_convert_exceptions.cpp index f05214c8fd1..9a61546aab1 100644 --- a/src/goto-programs/goto_convert_exceptions.cpp +++ b/src/goto-programs/goto_convert_exceptions.cpp @@ -83,9 +83,8 @@ void goto_convertt::convert_msc_leave( convert(d_code, dest, mode); } - goto_programt::targett t=dest.add_instruction(); - t->make_goto(targets.leave_target); - t->source_location=code.source_location(); + dest.add( + goto_programt::make_goto(targets.leave_target, code.source_location())); } void goto_convertt::convert_try_catch( @@ -112,8 +111,7 @@ void goto_convertt::convert_try_catch( // add a SKIP target for the end of everything goto_programt end; - goto_programt::targett end_target=end.add_instruction(); - end_target->make_skip(); + goto_programt::targett end_target = end.add(goto_programt::make_skip()); // the first operand is the 'try' block convert(to_code(code.op0()), dest, mode); @@ -124,7 +122,7 @@ void goto_convertt::convert_try_catch( catch_pop_instruction->code=code_pop_catcht(); // add a goto to the end of the 'try' block - dest.add_instruction()->make_goto(end_target); + dest.add(goto_programt::make_goto(end_target)); for(std::size_t i=1; imake_goto(end_target); + dest.add(goto_programt::make_goto(end_target)); } catch_push_instruction->code=push_catch_code; @@ -205,9 +203,8 @@ void goto_convertt::convert_CPROVER_throw( code.source_location(), targets.throw_stack_size, dest, mode); // add goto - goto_programt::targett t=dest.add_instruction(); - t->make_goto(targets.throw_target); - t->source_location=code.source_location(); + dest.add( + goto_programt::make_goto(targets.throw_target, code.source_location())); } else // otherwise, we do a return { @@ -215,9 +212,8 @@ void goto_convertt::convert_CPROVER_throw( unwind_destructor_stack(code.source_location(), 0, dest, mode); // add goto - goto_programt::targett t=dest.add_instruction(); - t->make_goto(targets.return_target); - t->source_location=code.source_location(); + dest.add( + goto_programt::make_goto(targets.return_target, code.source_location())); } } diff --git a/src/goto-programs/goto_inline_class.cpp b/src/goto-programs/goto_inline_class.cpp index 454430cdc69..b313edef65d 100644 --- a/src/goto-programs/goto_inline_class.cpp +++ b/src/goto-programs/goto_inline_class.cpp @@ -61,11 +61,9 @@ void goto_inlinet::parameter_assignments( { const symbolt &symbol=ns.lookup(identifier); - goto_programt::targett decl=dest.add_instruction(); - decl->make_decl(); - decl->code=code_declt(symbol.symbol_expr()); + goto_programt::targett decl = dest.add( + goto_programt::make_decl(symbol.symbol_expr(), source_location)); decl->code.add_source_location()=source_location; - decl->source_location=source_location; decl->function=adjust_function?target->function:function_name; } @@ -169,11 +167,9 @@ void goto_inlinet::parameter_destruction( { const symbolt &symbol=ns.lookup(identifier); - goto_programt::targett dead=dest.add_instruction(); - dead->make_dead(); - dead->code=code_deadt(symbol.symbol_expr()); + goto_programt::targett dead = dest.add( + goto_programt::make_dead(symbol.symbol_expr(), source_location)); dead->code.add_source_location()=source_location; - dead->source_location=source_location; dead->function=adjust_function?target->function:function_name; } }