CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
goto_program.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Concrete Goto Program
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_PROGRAMS_GOTO_PROGRAM_H
13#define CPROVER_GOTO_PROGRAMS_GOTO_PROGRAM_H
14
15#include <util/invariant.h>
17
19
20#include <limits>
21#include <list>
22#include <set>
23#include <string>
24
25class code_gotot;
26class namespacet;
27enum class validation_modet;
28
31{
33 GOTO = 1, // branch, possibly guarded
34 ASSUME = 2, // non-failing guarded self loop
35 ASSERT = 3, // assertions
36 OTHER = 4, // anything else
37 SKIP = 5, // just advance the PC
38 START_THREAD = 6, // spawns an asynchronous thread
39 END_THREAD = 7, // end the current thread
40 LOCATION = 8, // semantically like SKIP
41 END_FUNCTION = 9, // exit point of a function
42 ATOMIC_BEGIN = 10, // marks a block without interleavings
43 ATOMIC_END = 11, // end of a block without interleavings
44 SET_RETURN_VALUE = 12, // set function return value (no control-flow change)
45 ASSIGN = 13, // assignment lhs:=rhs
46 DECL = 14, // declare a local variable
47 DEAD = 15, // marks the end-of-live of a local variable
48 FUNCTION_CALL = 16, // call a function
49 THROW = 17, // throw an exception
50 CATCH = 18, // push, pop or enter an exception handler
51 INCOMPLETE_GOTO = 19 // goto where target is yet to be determined
52};
53
54std::ostream &operator<<(std::ostream &, goto_program_instruction_typet);
55
72{
73public:
77
78 // Move operations need to be explicitly enabled as they are deleted with the
79 // copy operations
80 // default for move operations isn't available on Windows yet, so define
81 // explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx
82 // under "Defaulted and Deleted Functions")
83
85 instructions(std::move(other.instructions))
86 {
87 }
88
90 {
91 instructions=std::move(other.instructions);
92 return *this;
93 }
94
179 class instructiont final
180 {
181 protected:
184
185 public:
188 {
189 return _code;
190 }
191
194 {
195 return _code;
196 }
197
199 const exprt &assign_lhs() const
200 {
202 return to_code_assign(_code).lhs();
203 }
204
207 {
209 return to_code_assign(_code).lhs();
210 }
211
213 const exprt &assign_rhs() const
214 {
216 return to_code_assign(_code).rhs();
217 }
218
221 {
223 return to_code_assign(_code).rhs();
224 }
225
228 {
231 return decl.symbol();
232 }
233
236 {
239 return decl.symbol();
240 }
241
244 {
246 return to_code_dead(_code).symbol();
247 }
248
251 {
253 return to_code_dead(_code).symbol();
254 }
255
257 const exprt &return_value() const
258 {
260 return to_code_return(_code).return_value();
261 }
262
265 {
267 return to_code_return(_code).return_value();
268 }
269
271 const exprt &call_function() const
272 {
274 return to_code_function_call(_code).function();
275 }
276
279 {
281 return to_code_function_call(_code).function();
282 }
283
285 const exprt &call_lhs() const
286 {
288 return to_code_function_call(_code).lhs();
289 }
290
293 {
295 return to_code_function_call(_code).lhs();
296 }
297
300 {
302 return to_code_function_call(_code).arguments();
303 }
304
311
314 {
316 return _code;
317 }
318
321 {
323 _code = std::move(c);
324 }
325
328 protected:
330
331 public:
333 {
334 return _source_location;
335 }
336
341
344 {
345 return _type;
346 }
347
348 protected:
349 // Use type() to access. To prevent malformed instructions, no non-const
350 // access method is provided.
352
356
357 public:
359 bool has_condition() const
360 {
361 return is_goto() || is_incomplete_goto() || is_assume() || is_assert();
362 }
363
365 const exprt &condition() const
366 {
368 return guard;
369 }
370
373 {
375 return guard;
376 }
377
378 // The below will eventually become a single target only.
380 typedef std::list<instructiont>::iterator targett;
381 typedef std::list<instructiont>::const_iterator const_targett;
382 typedef std::list<targett> targetst;
383 typedef std::list<const_targett> const_targetst;
384
390 struct target_less_than // NOLINT(readability/identifiers)
391 {
392 static inline bool
394 {
395 const instructiont &_i1 = *i1;
396 const instructiont &_i2 = *i2;
397 return &_i1 < &_i2;
398 }
399
400 inline bool
402 {
403 return order_const_target(i1, i2);
404 }
405
406 inline bool operator()(const targett &i1, const targett &i2) const
407 {
408 return &(*i1) < &(*i2);
409 }
410 };
411
414
418 {
419 PRECONDITION(targets.size() == 1);
420 return targets.front();
421 }
422
426 {
427 PRECONDITION(targets.size()==1);
428 return targets.front();
429 }
430
434 {
435 targets.clear();
436 targets.push_back(t);
437 }
438
439 bool has_target() const
440 {
441 return !targets.empty();
442 }
443
445 typedef std::list<irep_idt> labelst;
447
448 // will go away
449 std::set<targett, target_less_than> incoming_edges;
450
452 bool is_target() const
453 { return target_number!=nil_target; }
454
463
467 {
468 clear(SKIP);
469 }
470
474 {
476 _type = ASSUME;
477 targets.clear();
478 _code.make_nil();
479 }
480
482 {
484 _code.make_nil();
485 targets.push_back(_target);
486 _type = GOTO;
487 }
488
489 // clang-format off
490 bool is_goto () const { return _type == GOTO; }
491 bool is_set_return_value() const { return _type == SET_RETURN_VALUE; }
492 bool is_assign () const { return _type == ASSIGN; }
493 bool is_function_call () const { return _type == FUNCTION_CALL; }
494 bool is_throw () const { return _type == THROW; }
495 bool is_catch () const { return _type == CATCH; }
496 bool is_skip () const { return _type == SKIP; }
497 bool is_location () const { return _type == LOCATION; }
498 bool is_other () const { return _type == OTHER; }
499 bool is_decl () const { return _type == DECL; }
500 bool is_dead () const { return _type == DEAD; }
501 bool is_assume () const { return _type == ASSUME; }
502 bool is_assert () const { return _type == ASSERT; }
503 bool is_atomic_begin () const { return _type == ATOMIC_BEGIN; }
504 bool is_atomic_end () const { return _type == ATOMIC_END; }
505 bool is_start_thread () const { return _type == START_THREAD; }
506 bool is_end_thread () const { return _type == END_THREAD; }
507 bool is_end_function () const { return _type == END_FUNCTION; }
508 bool is_incomplete_goto () const { return _type == INCOMPLETE_GOTO; }
509 // clang-format on
510
512 instructiont(NO_INSTRUCTION_TYPE) // NOLINT(runtime/explicit)
513 {
514 }
515
523
538
540 void swap(instructiont &instruction)
541 {
542 using std::swap;
543 swap(instruction._code, _code);
545 swap(instruction._type, _type);
546 swap(instruction.guard, guard);
547 swap(instruction.targets, targets);
548 swap(instruction.labels, labels);
549 }
550
552 static const unsigned nil_target=
553 std::numeric_limits<unsigned>::max();
554
558 unsigned location_number = 0;
559
561 unsigned loop_number = 0;
562
566
568 bool is_backwards_goto() const
569 {
570 if(!is_goto())
571 return false;
572
573 for(const auto &t : targets)
574 if(t->location_number<=location_number)
575 return true;
576
577 return false;
578 }
579
580 std::string to_string() const
581 {
582 std::ostringstream instruction_id_builder;
584 return instruction_id_builder.str();
585 }
586
591 bool equals(const instructiont &other) const;
592
597 void validate(const namespacet &ns, const validation_modet vm) const;
598
601 void transform(std::function<std::optional<exprt>(exprt)>);
602
604 void apply(std::function<void(const exprt &)>) const;
605
607 std::ostream &output(std::ostream &) const;
608 };
609
610 // Never try to change this to vector-we mutate the list while iterating
611 typedef std::list<instructiont> instructionst;
612
613 typedef instructionst::iterator targett;
614 typedef instructionst::const_iterator const_targett;
615 typedef std::list<targett> targetst;
616 typedef std::list<const_targett> const_targetst;
617 // NOLINTNEXTLINE(readability/identifiers)
619
622
626 {
627 return instructions.erase(t, t);
628 }
629
632 {
633 return t;
634 }
635
636 template <typename Target>
637 std::list<Target> get_successors(Target target) const;
638
640
643 {
644 PRECONDITION(target!=instructions.end());
645 const auto next=std::next(target);
646 instructions.insert(next, instructiont())->swap(*target);
647 }
648
667 void insert_before_swap(targett target, instructiont &instruction)
668 {
669 insert_before_swap(target);
670 target->swap(instruction);
671 }
672
676 targett target,
677 goto_programt &p)
678 {
679 PRECONDITION(target!=instructions.end());
680 if(p.instructions.empty())
681 return;
682 insert_before_swap(target, p.instructions.front());
683 auto next=std::next(target);
684 p.instructions.erase(p.instructions.begin());
685 instructions.splice(next, p.instructions);
686 }
687
692 {
693 return instructions.insert(target, instructiont());
694 }
695
700 {
701 return instructions.insert(target, i);
702 }
703
708 {
709 return instructions.insert(std::next(target), instructiont());
710 }
711
716 {
717 return instructions.insert(std::next(target), i);
718 }
719
722 {
723 instructions.splice(instructions.end(),
724 p.instructions);
725 }
726
730 const_targett target,
731 goto_programt &p)
732 {
733 instructions.splice(target, p.instructions);
734 }
735
738 targett add(instructiont &&instruction)
739 {
740 instructions.push_back(std::move(instruction));
741 return --instructions.end();
742 }
743
747 {
748 return add(instructiont());
749 }
750
757
759 std::ostream &output(std::ostream &out) const;
760
763
766 {
767 for(auto &i : instructions)
768 {
769 INVARIANT(
770 nr != std::numeric_limits<unsigned>::max(),
771 "Too many location numbers assigned");
772 i.location_number=nr++;
773 }
774 }
775
778 {
779 unsigned nr=0;
781 }
782
785
787 void update();
788
790 static irep_idt
791 loop_id(const irep_idt &function_id, const instructiont &instruction)
792 {
793 return id2string(function_id) + "." +
794 std::to_string(instruction.loop_number);
795 }
796
798 bool empty() const
799 {
800 return instructions.empty();
801 }
802
805 {
806 }
807
809 {
810 }
811
813 void swap(goto_programt &program)
814 {
815 program.instructions.swap(instructions);
816 }
817
819 void clear()
820 {
822 }
823
827 {
828 PRECONDITION(!instructions.empty());
829 const auto end_function=std::prev(instructions.end());
830 DATA_INVARIANT(end_function->is_end_function(),
831 "goto program ends on END_FUNCTION");
832 return end_function;
833 }
834
838 {
839 PRECONDITION(!instructions.empty());
840 const auto end_function=std::prev(instructions.end());
841 DATA_INVARIANT(end_function->is_end_function(),
842 "goto program ends on END_FUNCTION");
843 return end_function;
844 }
845
847 void copy_from(const goto_programt &src);
848
850 bool has_assertion() const;
851
852 typedef std::set<irep_idt> decl_identifierst;
855
859 bool equals(const goto_programt &other) const;
860
865 void validate(const namespacet &ns, const validation_modet vm) const
866 {
867 for(const instructiont &ins : instructions)
868 {
869 ins.validate(ns, vm);
870 }
871 }
872
874 exprt return_value,
876 {
877 return instructiont(
878 code_returnt(std::move(return_value)),
879 l,
881 nil_exprt(),
882 {});
883 }
884
886 const code_returnt &code,
887 const source_locationt &l = source_locationt::nil()) = delete;
888
889 static instructiont
891 {
892 return instructiont(
893 static_cast<const goto_instruction_codet &>(get_nil_irep()),
894 l,
895 SKIP,
896 nil_exprt(),
897 {});
898 }
899
901 {
902 return instructiont(
903 static_cast<const goto_instruction_codet &>(get_nil_irep()),
904 l,
905 LOCATION,
906 nil_exprt(),
907 {});
908 }
909
910 static instructiont
912 {
913 return instructiont(
914 static_cast<const goto_instruction_codet &>(get_nil_irep()),
915 l,
916 THROW,
917 nil_exprt(),
918 {});
919 }
920
921 static instructiont
923 {
924 return instructiont(
925 static_cast<const goto_instruction_codet &>(get_nil_irep()),
926 l,
927 CATCH,
928 nil_exprt(),
929 {});
930 }
931
933 const exprt &g,
935 {
936 return instructiont(
937 static_cast<const goto_instruction_codet &>(get_nil_irep()),
938 l,
939 ASSERT,
940 exprt(g),
941 {});
942 }
943
945 const exprt &g,
947 {
948 return instructiont(
949 static_cast<const goto_instruction_codet &>(get_nil_irep()),
950 l,
951 ASSUME,
952 g,
953 {});
954 }
955
957 const goto_instruction_codet &_code,
959 {
960 return instructiont(_code, l, OTHER, nil_exprt(), {});
961 }
962
964 const symbol_exprt &symbol,
966 {
967 return instructiont(code_declt(symbol), l, DECL, nil_exprt(), {});
968 }
969
971 const symbol_exprt &symbol,
973 {
974 return instructiont(code_deadt(symbol), l, DEAD, nil_exprt(), {});
975 }
976
977 static instructiont
979 {
980 return instructiont(
981 static_cast<const goto_instruction_codet &>(get_nil_irep()),
982 l,
984 nil_exprt(),
985 {});
986 }
987
988 static instructiont
990 {
991 return instructiont(
992 static_cast<const goto_instruction_codet &>(get_nil_irep()),
993 l,
995 nil_exprt(),
996 {});
997 }
998
999 static instructiont
1001 {
1002 return instructiont(
1003 static_cast<const goto_instruction_codet &>(get_nil_irep()),
1004 l,
1006 nil_exprt(),
1007 {});
1008 }
1009
1011 const exprt &_cond,
1013 {
1014 PRECONDITION(_cond.is_boolean());
1015 return instructiont(
1016 static_cast<const goto_instruction_codet &>(get_nil_irep()),
1017 l,
1019 _cond,
1020 {});
1021 }
1022
1023 static instructiont
1025 {
1026 return instructiont(
1027 static_cast<const goto_instruction_codet &>(get_nil_irep()),
1028 l,
1030 true_exprt(),
1031 {});
1032 }
1033
1034 static instructiont make_incomplete_goto(
1035 const code_gotot &,
1037
1041 {
1042 return instructiont(
1043 static_cast<const goto_instruction_codet &>(get_nil_irep()),
1044 l,
1045 GOTO,
1046 true_exprt(),
1047 {_target});
1048 }
1049
1052 const exprt &g,
1054 {
1055 return instructiont(
1056 static_cast<const goto_instruction_codet &>(get_nil_irep()),
1057 l,
1058 GOTO,
1059 g,
1060 {_target});
1061 }
1062
1065 const code_assignt &_code,
1067 {
1068 return instructiont(_code, l, ASSIGN, nil_exprt(), {});
1069 }
1070
1073 exprt lhs,
1074 exprt rhs,
1076 {
1077 return instructiont(
1078 code_assignt(std::move(lhs), std::move(rhs)), l, ASSIGN, nil_exprt(), {});
1079 }
1080
1082 const code_declt &_code,
1084 {
1085 return instructiont(_code, l, DECL, nil_exprt(), {});
1086 }
1087
1090 const code_function_callt &_code,
1092 {
1093 return instructiont(_code, l, FUNCTION_CALL, nil_exprt(), {});
1094 }
1095
1098 exprt lhs,
1099 exprt function,
1102 {
1103 return instructiont(
1104 code_function_callt(lhs, std::move(function), std::move(arguments)),
1105 l,
1107 nil_exprt(),
1108 {});
1109 }
1110};
1111
1124template <typename Target>
1126 Target target) const
1127{
1128 if(target==instructions.end())
1129 return std::list<Target>();
1130
1131 const auto next=std::next(target);
1132
1133 const instructiont &i=*target;
1134
1135 if(i.is_goto())
1136 {
1137 std::list<Target> successors(i.targets.begin(), i.targets.end());
1138
1139 if(!i.condition().is_true() && next != instructions.end())
1140 successors.push_back(next);
1141
1142 return successors;
1143 }
1144
1145 if(i.is_start_thread())
1146 {
1147 std::list<Target> successors(i.targets.begin(), i.targets.end());
1148
1149 if(next!=instructions.end())
1150 successors.push_back(next);
1151
1152 return successors;
1153 }
1154
1155 if(i.is_end_thread())
1156 {
1157 // no successors
1158 return std::list<Target>();
1159 }
1160
1161 if(i.is_throw())
1162 {
1163 // the successors are non-obvious
1164 return std::list<Target>();
1165 }
1166
1167 if(i.is_assume())
1168 {
1169 return !i.condition().is_false() && next != instructions.end()
1170 ? std::list<Target>{next}
1171 : std::list<Target>();
1172 }
1173
1174 if(next!=instructions.end())
1175 {
1176 return std::list<Target>{next};
1177 }
1178
1179 return std::list<Target>();
1180}
1181
1182// NOLINTNEXTLINE(readability/identifiers)
1184{
1185 std::size_t operator()(
1186 const goto_programt::const_targett t) const
1187 {
1188 using hash_typet = decltype(&(*t));
1189 return std::hash<hash_typet>{}(&(*t));
1190 }
1191};
1192
1196{
1197 template <class A, class B>
1198 bool operator()(const A &a, const B &b) const
1199 {
1200 return &(*a) == &(*b);
1201 }
1202};
1203
1204template <typename GotoFunctionT, typename PredicateT, typename HandlerT>
1206 GotoFunctionT &&goto_function,
1207 PredicateT predicate,
1209{
1210 auto &&instructions = goto_function.body.instructions;
1211 for(auto it = instructions.begin(); it != instructions.end(); ++it)
1212 {
1213 if(predicate(it))
1214 {
1215 handler(it);
1216 }
1217 }
1218}
1219
1220template <typename GotoFunctionT, typename HandlerT>
1222{
1223 using iterator_t = decltype(goto_function.body.instructions.begin());
1225 goto_function, [](const iterator_t &) { return true; }, handler);
1226}
1227
1228#define forall_goto_program_instructions(it, program) \
1229 for(goto_programt::instructionst::const_iterator \
1230 it=(program).instructions.begin(); \
1231 it!=(program).instructions.end(); it++)
1232
1233#define Forall_goto_program_instructions(it, program) \
1234 for(goto_programt::instructionst::iterator \
1235 it=(program).instructions.begin(); \
1236 it!=(program).instructions.end(); it++)
1237
1238std::list<exprt> objects_read(const goto_programt::instructiont &);
1239std::list<exprt> objects_written(const goto_programt::instructiont &);
1240
1241std::list<exprt> expressions_read(const goto_programt::instructiont &);
1242std::list<exprt> expressions_written(const goto_programt::instructiont &);
1243
1244std::string as_string(
1245 const namespacet &ns,
1246 const irep_idt &function,
1248
1249#endif // CPROVER_GOTO_PROGRAMS_GOTO_PROGRAM_H
virtual void clear()
Reset the abstract state.
Definition ai.h:265
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
A goto_instruction_codet representing an assignment in the program.
A goto_instruction_codet representing the removal of a local variable going out of scope.
A goto_instruction_codet representing the declaration of a local variable.
goto_instruction_codet representation of a function call statement.
codet representation of a goto statement.
Definition std_code.h:841
goto_instruction_codet representation of a "return from a function" statement.
Data structure for representing an arbitrary statement in a program.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
std::vector< exprt > operandst
Definition expr.h:58
This class represents an instruction in the GOTO intermediate representation.
const symbol_exprt & dead_symbol() const
Get the symbol for DEAD.
const exprt & call_lhs() const
Get the lhs of a FUNCTION_CALL (may be nil)
const goto_instruction_codet & get_other() const
Get the statement for OTHER.
unsigned target_number
A number to identify branch targets.
void turn_into_skip()
Transforms an existing instruction into a skip, retaining the source_location.
exprt & call_lhs()
Get the lhs of a FUNCTION_CALL (may be nil)
void complete_goto(targett _target)
bool is_target() const
Is this node a branch target?
const exprt & return_value() const
Get the return value of a SET_RETURN_VALUE instruction.
void set_target(targett t)
Sets the first (and only) successor for the usual case of a single target.
std::list< targett > targetst
const goto_instruction_codet & code() const
Get the code represented by this instruction.
goto_instruction_codet _code
Do not read or modify directly – use code() and code_nonconst() instead.
bool has_condition() const
Does this instruction have a condition?
void apply(std::function< void(const exprt &)>) const
Apply given function to all expressions.
const symbol_exprt & decl_symbol() const
Get the declared symbol for DECL.
targetst targets
The list of successor instructions.
symbol_exprt & dead_symbol()
Get the symbol for DEAD.
exprt & assign_lhs_nonconst()
Get the lhs of the assignment for ASSIGN.
unsigned loop_number
Number unique per function to identify loops.
exprt::operandst & call_arguments()
Get the arguments of a FUNCTION_CALL.
targett get_target()
Returns the first (and only) successor for the usual case of a single target.
void turn_into_assume()
Transforms either an assertion or a GOTO instruction into an assumption, with the same condition.
goto_program_instruction_typet _type
bool equals(const instructiont &other) const
Syntactic equality: two instructiont are equal if they have the same type, code, guard,...
void transform(std::function< std::optional< exprt >(exprt)>)
Apply given transformer to all expressions; no return value means no change needed.
std::string to_string() const
const exprt::operandst & call_arguments() const
Get the arguments of a FUNCTION_CALL.
unsigned location_number
A globally unique number to identify a program location.
bool is_backwards_goto() const
Returns true if the instruction is a backwards branch.
source_locationt _source_location
The location of the instruction in the source file.
const exprt & assign_lhs() const
Get the lhs of the assignment for ASSIGN.
std::list< instructiont >::const_iterator const_targett
static const unsigned nil_target
Uniquely identify an invalid target or location.
const exprt & assign_rhs() const
Get the rhs of the assignment for ASSIGN.
const exprt & call_function() const
Get the function that is called for FUNCTION_CALL.
std::list< const_targett > const_targetst
std::set< targett, target_less_than > incoming_edges
void clear(goto_program_instruction_typet __type)
Clear the node.
std::list< instructiont >::iterator targett
The target for gotos and for start_thread nodes.
std::ostream & output(std::ostream &) const
Output this instruction to the given stream.
instructiont(goto_instruction_codet __code, source_locationt __source_location, goto_program_instruction_typet __type, exprt _guard, targetst _targets)
Constructor that can set all members, passed by value.
exprt guard
Guard for gotos, assume, assert Use condition() method to access.
const exprt & condition() const
Get the condition of gotos, assume, assert.
void set_other(goto_instruction_codet &c)
Set the statement for OTHER.
instructiont(goto_program_instruction_typet __type)
goto_instruction_codet & code_nonconst()
Set the code represented by this instruction.
void swap(instructiont &instruction)
Swap two instructions.
exprt & condition_nonconst()
Get the condition of gotos, assume, assert.
std::list< irep_idt > labelst
Goto target labels.
source_locationt & source_location_nonconst()
exprt & return_value()
Get the return value of a SET_RETURN_VALUE instruction.
exprt & call_function()
Get the function that is called for FUNCTION_CALL.
exprt & assign_rhs_nonconst()
Get the rhs of the assignment for ASSIGN.
const source_locationt & source_location() const
const_targett get_target() const
Returns the first (and only) successor for the usual case of a single target.
goto_program_instruction_typet type() const
What kind of instruction?
void validate(const namespacet &ns, const validation_modet vm) const
Check that the instruction is well-formed.
symbol_exprt & decl_symbol()
Get the declared symbol for DECL.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
void copy_from(const goto_programt &src)
Copy a full goto program, preserving targets.
static instructiont make_set_return_value(exprt return_value, const source_locationt &l=source_locationt::nil())
void clear()
Clear the goto program.
void insert_before_swap(targett target, instructiont &instruction)
Insertion that preserves jumps to "target".
static instructiont make_decl(const code_declt &_code, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const source_locationt &l=source_locationt::nil())
targett insert_after(const_targett target, const instructiont &i)
Insertion after the instruction pointed-to by the given instruction iterator target.
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
void update()
Update all indices.
goto_programt & operator=(goto_programt &&other)
targett const_cast_target(const_targett t)
Convert a const_targett to a targett - use with care and avoid whenever possible.
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
std::ostream & output(std::ostream &out) const
Output goto-program to given stream.
bool has_assertion() const
Does the goto program have an assertion?
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
static irep_idt loop_id(const irep_idt &function_id, const instructiont &instruction)
Human-readable loop name.
goto_programt & operator=(const goto_programt &)=delete
targett insert_before(const_targett target, const instructiont &i)
Insertion before the instruction pointed-to by the given instruction iterator target.
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
instructionst::iterator targett
instructionst::const_iterator const_targett
static instructiont make_set_return_value(const code_returnt &code, const source_locationt &l=source_locationt::nil())=delete
void validate(const namespacet &ns, const validation_modet vm) const
Check that the goto program is well-formed.
targett add_instruction(goto_program_instruction_typet type)
Adds an instruction of given type at the end.
targett add_instruction()
Adds an instruction at the end.
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
static instructiont make_goto(targett _target, const exprt &g, const source_locationt &l=source_locationt::nil())
void insert_before_swap(targett target, goto_programt &p)
Insertion that preserves jumps to "target".
static instructiont make_atomic_end(const source_locationt &l=source_locationt::nil())
goto_programt()
Constructor.
void compute_incoming_edges()
Compute for each instruction the set of instructions it is a successor of.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
targett get_end_function()
Get an instruction iterator pointing to the END_FUNCTION instruction of the goto program.
std::list< instructiont > instructionst
std::set< irep_idt > decl_identifierst
std::list< const_targett > const_targetst
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
goto_programt(const goto_programt &)=delete
Copying is deleted as this class contains pointers that cannot be copied.
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
static instructiont make_throw(const source_locationt &l=source_locationt::nil())
static instructiont make_other(const goto_instruction_codet &_code, const source_locationt &l=source_locationt::nil())
const_targett const_cast_target(const_targett t) const
Dummy for templates with possible const contexts.
void compute_location_numbers(unsigned &nr)
Compute location numbers.
void get_decl_identifiers(decl_identifierst &decl_identifiers) const
get the variables in decl statements
instructiont::target_less_than target_less_than
const_targett get_end_function() const
Get an instruction iterator pointing to the END_FUNCTION instruction of the goto program.
std::list< Target > get_successors(Target target) const
Get control-flow successors of a given instruction.
static instructiont make_catch(const source_locationt &l=source_locationt::nil())
static instructiont make_atomic_begin(const source_locationt &l=source_locationt::nil())
goto_programt(goto_programt &&other)
void compute_location_numbers()
Compute location numbers.
void swap(goto_programt &program)
Swap the goto program.
static instructiont make_location(const source_locationt &l)
void compute_target_numbers()
Compute the target numbers.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
bool empty() const
Is the program empty?
bool equals(const goto_programt &other) const
Syntactic equality: two goto_programt are equal if, and only if, they have the same number of instruc...
static instructiont make_function_call(exprt lhs, exprt function, code_function_callt::argumentst arguments, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
static instructiont make_assignment(exprt lhs, exprt rhs, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
void compute_loop_numbers()
Compute loop numbers.
std::list< targett > targetst
void make_nil()
Definition irep.h:446
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
The NIL expression.
Definition std_expr.h:3208
static const source_locationt & nil()
Expression to hold a symbol (variable)
Definition std_expr.h:131
The Boolean constant true.
Definition std_expr.h:3190
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
const code_deadt & to_code_dead(const goto_instruction_codet &code)
const code_assignt & to_code_assign(const goto_instruction_codet &code)
const code_returnt & to_code_return(const goto_instruction_codet &code)
void for_each_instruction(GotoFunctionT &&goto_function, HandlerT handler)
std::list< exprt > expressions_read(const goto_programt::instructiont &)
std::list< exprt > objects_written(const goto_programt::instructiont &)
std::ostream & operator<<(std::ostream &, goto_program_instruction_typet)
Outputs a string representation of a goto_program_instruction_typet
goto_program_instruction_typet
The type of an instruction in a GOTO program.
@ FUNCTION_CALL
@ ATOMIC_END
@ DEAD
@ LOCATION
@ END_FUNCTION
@ ASSIGN
@ ASSERT
@ SET_RETURN_VALUE
@ ATOMIC_BEGIN
@ CATCH
@ END_THREAD
@ SKIP
@ NO_INSTRUCTION_TYPE
@ START_THREAD
@ THROW
@ DECL
@ OTHER
@ GOTO
@ INCOMPLETE_GOTO
@ ASSUME
std::string as_string(const namespacet &ns, const irep_idt &function, const goto_programt::instructiont &)
std::list< exprt > expressions_written(const goto_programt::instructiont &)
void for_each_instruction_if(GotoFunctionT &&goto_function, PredicateT predicate, HandlerT handler)
std::list< exprt > objects_read(const goto_programt::instructiont &)
const irept & get_nil_irep()
Definition irep.cpp:19
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
STL namespace.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:534
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
std::size_t operator()(const goto_programt::const_targett t) const
A total order over targett and const_targett.
static bool order_const_target(const const_targett i1, const const_targett i2)
bool operator()(const targett &i1, const targett &i2) const
bool operator()(const const_targett &i1, const const_targett &i2) const
Functor to check whether iterators from different collections point at the same object.
bool operator()(const A &a, const B &b) const
validation_modet