Skip to content

Commit 88f5a3f

Browse files
author
Daniel Kroening
committed
added goto_programt::make_X(...)
These new methods avoid repeated assignment of the members of instructiont when used with instructiont::add(...).
1 parent a55d239 commit 88f5a3f

File tree

2 files changed

+196
-11
lines changed

2 files changed

+196
-11
lines changed

src/goto-programs/goto_program.h

Lines changed: 194 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,18 @@ class goto_programt
433433
{
434434
}
435435

436-
/// Constructor that can set all members
436+
/// Constructor that can set all members, passed by value
437437
instructiont(
438-
codet &&_code,
439-
const irep_idt &_function,
440-
source_locationt &&_source_location,
438+
codet _code,
439+
irep_idt _function,
440+
source_locationt _source_location,
441441
goto_program_instruction_typet _type,
442-
exprt &&_guard,
443-
targetst &&_targets)
442+
exprt _guard,
443+
targetst _targets)
444444
: code(std::move(_code)),
445445
function(_function),
446446
source_location(std::move(_source_location)),
447-
type(std::move(_type)),
447+
type(_type),
448448
guard(std::move(_guard)),
449449
targets(std::move(_targets))
450450
{
@@ -807,6 +807,193 @@ class goto_programt
807807
ins.validate(ns, vm);
808808
}
809809
}
810+
811+
static instructiont
812+
make_return(const source_locationt &l = source_locationt::nil())
813+
{
814+
return instructiont(code_returnt(), irep_idt(), l, RETURN, nil_exprt(), {});
815+
}
816+
817+
static instructiont
818+
make_skip(const source_locationt &l = source_locationt::nil())
819+
{
820+
return instructiont(
821+
static_cast<const codet &>(get_nil_irep()),
822+
irep_idt(),
823+
l,
824+
SKIP,
825+
nil_exprt(),
826+
{});
827+
}
828+
829+
static instructiont make_location(const source_locationt &l)
830+
{
831+
return instructiont(
832+
static_cast<const codet &>(get_nil_irep()),
833+
irep_idt(),
834+
l,
835+
LOCATION,
836+
nil_exprt(),
837+
{});
838+
}
839+
840+
static instructiont
841+
make_throw(const source_locationt &l = source_locationt::nil())
842+
{
843+
return instructiont(
844+
static_cast<const codet &>(get_nil_irep()),
845+
irep_idt(),
846+
l,
847+
THROW,
848+
nil_exprt(),
849+
{});
850+
}
851+
852+
static instructiont
853+
make_catch(const source_locationt &l = source_locationt::nil())
854+
{
855+
return instructiont(
856+
static_cast<const codet &>(get_nil_irep()),
857+
irep_idt(),
858+
l,
859+
CATCH,
860+
nil_exprt(),
861+
{});
862+
}
863+
864+
static instructiont make_assertion(
865+
const exprt &g,
866+
const source_locationt &l = source_locationt::nil())
867+
{
868+
return instructiont(
869+
static_cast<const codet &>(get_nil_irep()),
870+
irep_idt(),
871+
l,
872+
ASSERT,
873+
exprt(g),
874+
{});
875+
}
876+
877+
static instructiont make_assumption(
878+
const exprt &g,
879+
const source_locationt &l = source_locationt::nil())
880+
{
881+
return instructiont(
882+
static_cast<const codet &>(get_nil_irep()), irep_idt(), l, ASSUME, g, {});
883+
}
884+
885+
static instructiont make_other(const codet &_code)
886+
{
887+
return instructiont(
888+
_code, irep_idt(), source_locationt::nil(), OTHER, nil_exprt(), {});
889+
}
890+
891+
static instructiont make_decl(
892+
const symbol_exprt &symbol,
893+
const source_locationt &l = source_locationt::nil())
894+
{
895+
return instructiont(
896+
code_declt(symbol), irep_idt(), l, DECL, nil_exprt(), {});
897+
}
898+
899+
static instructiont make_dead(
900+
const symbol_exprt &symbol,
901+
const source_locationt &l = source_locationt::nil())
902+
{
903+
return instructiont(
904+
code_deadt(symbol), irep_idt(), l, DEAD, nil_exprt(), {});
905+
}
906+
907+
static instructiont
908+
make_atomic_begin(const source_locationt &l = source_locationt::nil())
909+
{
910+
return instructiont(
911+
static_cast<const codet &>(get_nil_irep()),
912+
irep_idt(),
913+
l,
914+
ATOMIC_BEGIN,
915+
nil_exprt(),
916+
{});
917+
}
918+
919+
static instructiont
920+
make_atomic_end(const source_locationt &l = source_locationt::nil())
921+
{
922+
return instructiont(
923+
static_cast<const codet &>(get_nil_irep()),
924+
irep_idt(),
925+
l,
926+
ATOMIC_END,
927+
nil_exprt(),
928+
{});
929+
}
930+
931+
static instructiont
932+
make_end_function(const source_locationt &l = source_locationt::nil())
933+
{
934+
return instructiont(
935+
static_cast<const codet &>(get_nil_irep()),
936+
irep_idt(),
937+
l,
938+
END_FUNCTION,
939+
nil_exprt(),
940+
{});
941+
}
942+
943+
static instructiont make_incomplete_goto(
944+
const code_gotot &_code,
945+
const source_locationt &l = source_locationt::nil())
946+
{
947+
return instructiont(_code, irep_idt(), l, INCOMPLETE_GOTO, nil_exprt(), {});
948+
}
949+
950+
static instructiont make_goto(
951+
targett _target,
952+
const source_locationt &l = source_locationt::nil())
953+
{
954+
return instructiont(
955+
static_cast<const codet &>(get_nil_irep()),
956+
irep_idt(),
957+
l,
958+
GOTO,
959+
true_exprt(),
960+
{_target});
961+
}
962+
963+
static instructiont make_goto(
964+
targett _target,
965+
const exprt &g,
966+
const source_locationt &l = source_locationt::nil())
967+
{
968+
return instructiont(
969+
static_cast<const codet &>(get_nil_irep()),
970+
irep_idt(),
971+
l,
972+
GOTO,
973+
g,
974+
{_target});
975+
}
976+
977+
static instructiont make_assignment(
978+
const code_assignt &_code,
979+
const source_locationt &l = source_locationt::nil())
980+
{
981+
return instructiont(_code, irep_idt(), l, ASSIGN, nil_exprt(), {});
982+
}
983+
984+
static instructiont make_decl(
985+
const code_declt &_code,
986+
const source_locationt &l = source_locationt::nil())
987+
{
988+
return instructiont(_code, irep_idt(), l, DECL, nil_exprt(), {});
989+
}
990+
991+
static instructiont make_function_call(
992+
const code_function_callt &_code,
993+
const source_locationt &l = source_locationt::nil())
994+
{
995+
return instructiont(_code, irep_idt(), l, FUNCTION_CALL, nil_exprt(), {});
996+
}
810997
};
811998

812999
/// Get control-flow successors of a given instruction. The instruction is

src/goto-programs/string_abstraction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,9 @@ void string_abstractiont::make_decl_and_def(goto_programt &dest,
283283
const symbolt &symbol=ns.lookup(identifier);
284284
symbol_exprt sym_expr=symbol.symbol_expr();
285285

286-
goto_programt::targett decl1=dest.add_instruction();
287-
decl1->make_decl();
288-
decl1->source_location=ref_instr->source_location;
286+
goto_programt::targett decl1 =
287+
dest.add(goto_programt::make_decl(sym_expr, ref_instr->source_location));
289288
decl1->function=ref_instr->function;
290-
decl1->code=code_declt(sym_expr);
291289
decl1->code.add_source_location()=ref_instr->source_location;
292290

293291
exprt val=symbol.value;

0 commit comments

Comments
 (0)