11/* ******************************************************************\
22
3- Module:
3+ Module: Data structures representing statements in a program
44
55Author: Daniel Kroening, kroening@kroening.com
66
@@ -16,8 +16,17 @@ Author: Daniel Kroening, kroening@kroening.com
1616#include " expr.h"
1717#include " expr_cast.h"
1818
19- /* ! \brief A statement in a programming language
20- */
19+ // / Data structure for representing an arbitrary statement in a program. Every
20+ // / specific type of statement (e.g. block of statements, assignment,
21+ // / if-then-else statement...) is represented by a subtype of `codet`.
22+ // / `codet`s are represented to be subtypes of \ref exprt since statements can
23+ // / occur in an expression context in C: for example, the assignment `x = y;`
24+ // / is an expression with return value `y`. For other types of statements in an
25+ // / expression context, see e.g.
26+ // / https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html.
27+ // / To distinguish a `codet` from other [exprts](\ref exprt), we set its
28+ // / [id()](\ref irept::id) to `ID_code`. To distinguish different types of
29+ // / `codet`, we use a named sub `ID_statement`.
2130class codet :public exprt
2231{
2332public:
@@ -26,6 +35,9 @@ class codet:public exprt
2635 {
2736 }
2837
38+ // / \param statement: Specifies the type of the `codet` to be constructed,
39+ // / e.g. `ID_block` for a \ref code_blockt or `ID_assign` for a
40+ // / \ref code_assignt.
2941 explicit codet (const irep_idt &statement):
3042 exprt(ID_code, typet(ID_code))
3143 {
@@ -84,8 +96,8 @@ inline codet &to_code(exprt &expr)
8496 return static_cast <codet &>(expr);
8597}
8698
87- /* ! \brief Sequential composition
88- */
99+ // / A \ref codet representing sequential composition of program statements.
100+ // / Each operand represents a statement in the block.
89101class code_blockt :public codet
90102{
91103public:
@@ -174,8 +186,7 @@ inline code_blockt &to_code_block(codet &code)
174186 return static_cast <code_blockt &>(code);
175187}
176188
177- /* ! \brief Skip
178- */
189+ // / A \ref codet representing a `skip` statement.
179190class code_skipt :public codet
180191{
181192public:
@@ -191,8 +202,10 @@ template<> inline bool can_cast_expr<code_skipt>(const exprt &base)
191202
192203// there is no to_code_skip, so no validate_expr is provided for code_skipt
193204
194- /* ! \brief Assignment
195- */
205+ // / A \ref codet representing an assignment in the program.
206+ // / For example, if an expression `e1` is represented as an \ref exprt `expr1`
207+ // / and an expression `e2` is represented as an \ref exprt `expr2`, the
208+ // / assignment `e1 = e2;` can be represented as `code_assignt(expr1, expr2)`.
196209class code_assignt :public codet
197210{
198211public:
@@ -249,8 +262,10 @@ inline code_assignt &to_code_assign(codet &code)
249262 return static_cast <code_assignt &>(code);
250263}
251264
252- /* ! \brief A declaration of a local variable
253- */
265+ // / A `codet` representing the declaration of a local variable.
266+ // / For example, if a variable (symbol) `x` is represented as a
267+ // / \ref symbol_exprt `sym`, then the declaration of this variable can be
268+ // / represented as `code_declt(sym)`.
254269class code_declt :public codet
255270{
256271public:
@@ -302,8 +317,8 @@ inline code_declt &to_code_decl(codet &code)
302317 return static_cast <code_declt &>(code);
303318}
304319
305- /* ! \brief A removal of a local variable
306- */
320+ // / A \ref codet representing the removal of a local variable going out of
321+ // / scope.
307322class code_deadt :public codet
308323{
309324public:
@@ -461,8 +476,7 @@ inline code_assertt &to_code_assert(codet &code)
461476code_blockt create_fatal_assertion (
462477 const exprt &condition, const source_locationt &source_location);
463478
464- /* ! \brief An if-then-else
465- */
479+ // / \ref codet representation of an if-then-else statement.
466480class code_ifthenelset :public codet
467481{
468482public:
@@ -533,8 +547,7 @@ inline code_ifthenelset &to_code_ifthenelse(codet &code)
533547 return static_cast <code_ifthenelset &>(code);
534548}
535549
536- /* ! \brief A `switch' instruction
537- */
550+ // / \ref codet representing a `switch` statement.
538551class code_switcht :public codet
539552{
540553public:
@@ -596,8 +609,7 @@ inline code_switcht &to_code_switch(codet &code)
596609 return static_cast <code_switcht &>(code);
597610}
598611
599- /* ! \brief A `while' instruction
600- */
612+ // / \ref codet representing a `while` statement.
601613class code_whilet :public codet
602614{
603615public:
@@ -659,8 +671,7 @@ inline code_whilet &to_code_while(codet &code)
659671 return static_cast <code_whilet &>(code);
660672}
661673
662- /* ! \brief A `do while' instruction
663- */
674+ // / \ref codet representation of a `do while` statement.
664675class code_dowhilet :public codet
665676{
666677public:
@@ -722,8 +733,7 @@ inline code_dowhilet &to_code_dowhile(codet &code)
722733 return static_cast <code_dowhilet &>(code);
723734}
724735
725- /* ! \brief A `for' instruction
726- */
736+ // / \ref codet representation of a `for` statement.
727737class code_fort :public codet
728738{
729739public:
@@ -798,8 +808,7 @@ inline code_fort &to_code_for(codet &code)
798808 return static_cast <code_fort &>(code);
799809}
800810
801- /* ! \brief A `goto' instruction
802- */
811+ // / \ref codet representation of a `goto` statement.
803812class code_gotot :public codet
804813{
805814public:
@@ -848,13 +857,11 @@ inline code_gotot &to_code_goto(codet &code)
848857 return static_cast <code_gotot &>(code);
849858}
850859
851- /* ! \brief A function call
852-
853- The function call instruction has three operands.
854- The first is the expression that is used to store
855- the return value. The second is the function called.
856- The third is a vector of argument values.
857- */
860+ // / \ref codet representation of a function call statement.
861+ // / The function call statement has three operands.
862+ // / The first is the expression that is used to store the return value.
863+ // / The second is the function called.
864+ // / The third is a vector of argument values.
858865class code_function_callt :public codet
859866{
860867public:
@@ -918,8 +925,7 @@ inline code_function_callt &to_code_function_call(codet &code)
918925 return static_cast <code_function_callt &>(code);
919926}
920927
921- /* ! \brief Return from a function
922- */
928+ // / \ref codet representation of a "return from a function" statement.
923929class code_returnt :public codet
924930{
925931public:
@@ -972,8 +978,7 @@ inline code_returnt &to_code_return(codet &code)
972978 return static_cast <code_returnt &>(code);
973979}
974980
975- /* ! \brief A label for branch targets
976- */
981+ // / \ref codet representation of a label for branch targets.
977982class code_labelt :public codet
978983{
979984public:
@@ -1040,8 +1045,8 @@ inline code_labelt &to_code_label(codet &code)
10401045 return static_cast <code_labelt &>(code);
10411046}
10421047
1043- /* ! \brief A switch-case
1044- */
1048+ // / \ref codet representation of a switch-case, i.e.\ a `case` statement within
1049+ // / a `switch`.
10451050class code_switch_caset :public codet
10461051{
10471052public:
@@ -1110,8 +1115,8 @@ inline code_switch_caset &to_code_switch_case(codet &code)
11101115 return static_cast <code_switch_caset &>(code);
11111116}
11121117
1113- /* ! \brief A break for `for' and `while' loops
1114- */
1118+ // / \ref codet representation of a ` break` statement (within a `for` or `while`
1119+ // / loop).
11151120class code_breakt :public codet
11161121{
11171122public:
@@ -1140,8 +1145,8 @@ inline code_breakt &to_code_break(codet &code)
11401145 return static_cast <code_breakt &>(code);
11411146}
11421147
1143- /* ! \brief A continue for `for' and `while' loops
1144- */
1148+ // / \ref codet representation of a `continue` statement (within a `for` or
1149+ // / `while` loop).
11451150class code_continuet :public codet
11461151{
11471152public:
@@ -1170,8 +1175,7 @@ inline code_continuet &to_code_continue(codet &code)
11701175 return static_cast <code_continuet &>(code);
11711176}
11721177
1173- /* ! \brief An inline assembler statement
1174- */
1178+ // / \ref codet representation of an inline assembler statement.
11751179class code_asmt :public codet
11761180{
11771181public:
@@ -1215,8 +1219,8 @@ inline const code_asmt &to_code_asm(const codet &code)
12151219 return static_cast <const code_asmt &>(code);
12161220}
12171221
1218- /* ! \brief An expression statement
1219- */
1222+ // / \ref codet representation of an expression statement.
1223+ // / It has one operand, which is the expression it stores.
12201224class code_expressiont :public codet
12211225{
12221226public:
@@ -1266,8 +1270,11 @@ inline const code_expressiont &to_code_expression(const codet &code)
12661270 return static_cast <const code_expressiont &>(code);
12671271}
12681272
1269- /* ! \brief An expression containing a side effect
1270- */
1273+ // / An expression containing a side effect.
1274+ // / Note that unlike most classes in this file, `side_effect_exprt` and its
1275+ // / subtypes are not subtypes of \ref codet, but they inherit directly from
1276+ // / \ref exprt. They do have a `statement` like [codets](\ref codet), but their
1277+ // / [id()](\ref irept::id) is `ID_side_effect`, not `ID_code`.
12711278class side_effect_exprt :public exprt
12721279{
12731280public:
@@ -1335,8 +1342,7 @@ inline const side_effect_exprt &to_side_effect_expr(const exprt &expr)
13351342 return static_cast <const side_effect_exprt &>(expr);
13361343}
13371344
1338- /* ! \brief A side effect that returns a non-deterministically chosen value
1339- */
1345+ // / A \ref side_effect_exprt that returns a non-deterministically chosen value.
13401346class side_effect_expr_nondett :public side_effect_exprt
13411347{
13421348public:
@@ -1390,8 +1396,7 @@ inline const side_effect_expr_nondett &to_side_effect_expr_nondet(
13901396 return static_cast <const side_effect_expr_nondett &>(side_effect_expr_nondet);
13911397}
13921398
1393- /* ! \brief A function call side effect
1394- */
1399+ // / A \ref side_effect_exprt representation of a function call side effect.
13951400class side_effect_expr_function_callt :public side_effect_exprt
13961401{
13971402public:
@@ -1486,8 +1491,8 @@ inline const side_effect_expr_function_callt
14861491 return static_cast <const side_effect_expr_function_callt &>(expr);
14871492}
14881493
1489- /* ! \brief A side effect that throws an exception
1490- */
1494+ // / A \ref side_effect_exprt representation of a side effect that throws an
1495+ // / exception.
14911496class side_effect_expr_throwt :public side_effect_exprt
14921497{
14931498public:
@@ -1534,12 +1539,12 @@ inline const side_effect_expr_throwt &to_side_effect_expr_throw(
15341539// / exception_tag1 -> label1
15351540// / exception_tag2 -> label2
15361541// / ...
1537- // / When used in a GOTO program instruction , the corresponding
1538- // / opcode must be CATCH, and the instruction 's `targets` must
1542+ // / When used in a GOTO program statement , the corresponding
1543+ // / opcode must be CATCH, and the statement 's `targets` must
15391544// / be in one-to-one correspondence with the exception tags.
15401545// / The labels may be unspecified for the case where
1541- // / there is no corresponding source-language label, in whic
1542- // / case the GOTO instruction targets must be set at the same
1546+ // / there is no corresponding source-language label, in which
1547+ // / case the GOTO statement targets must be set at the same
15431548// / time.
15441549class code_push_catcht :public codet
15451550{
@@ -1702,8 +1707,7 @@ static inline const code_landingpadt &to_code_landingpad(const codet &code)
17021707 return static_cast <const code_landingpadt &>(code);
17031708}
17041709
1705- /* ! \brief A try/catch block
1706- */
1710+ // / \ref codet representation of a try/catch block.
17071711class code_try_catcht :public codet
17081712{
17091713public:
0 commit comments