1
1
/* ******************************************************************\
2
2
3
- Module:
3
+ Module: Data structures representing statements in a program
4
4
5
5
Author: Daniel Kroening, [email protected]
6
6
16
16
#include " expr.h"
17
17
#include " expr_cast.h"
18
18
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`.
21
30
class codet :public exprt
22
31
{
23
32
public:
@@ -26,6 +35,9 @@ class codet:public exprt
26
35
{
27
36
}
28
37
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.
29
41
explicit codet (const irep_idt &statement):
30
42
exprt(ID_code, typet(ID_code))
31
43
{
@@ -84,8 +96,8 @@ inline codet &to_code(exprt &expr)
84
96
return static_cast <codet &>(expr);
85
97
}
86
98
87
- /* ! \brief Sequential composition
88
- */
99
+ // / A \ref codet representing sequential composition of program statements.
100
+ // / Each operand represents a statement in the block.
89
101
class code_blockt :public codet
90
102
{
91
103
public:
@@ -174,8 +186,7 @@ inline code_blockt &to_code_block(codet &code)
174
186
return static_cast <code_blockt &>(code);
175
187
}
176
188
177
- /* ! \brief Skip
178
- */
189
+ // / A \ref codet representing a `skip` statement.
179
190
class code_skipt :public codet
180
191
{
181
192
public:
@@ -191,8 +202,10 @@ template<> inline bool can_cast_expr<code_skipt>(const exprt &base)
191
202
192
203
// there is no to_code_skip, so no validate_expr is provided for code_skipt
193
204
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)`.
196
209
class code_assignt :public codet
197
210
{
198
211
public:
@@ -249,8 +262,10 @@ inline code_assignt &to_code_assign(codet &code)
249
262
return static_cast <code_assignt &>(code);
250
263
}
251
264
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)`.
254
269
class code_declt :public codet
255
270
{
256
271
public:
@@ -302,8 +317,8 @@ inline code_declt &to_code_decl(codet &code)
302
317
return static_cast <code_declt &>(code);
303
318
}
304
319
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.
307
322
class code_deadt :public codet
308
323
{
309
324
public:
@@ -461,8 +476,7 @@ inline code_assertt &to_code_assert(codet &code)
461
476
code_blockt create_fatal_assertion (
462
477
const exprt &condition, const source_locationt &source_location);
463
478
464
- /* ! \brief An if-then-else
465
- */
479
+ // / \ref codet representation of an if-then-else statement.
466
480
class code_ifthenelset :public codet
467
481
{
468
482
public:
@@ -533,8 +547,7 @@ inline code_ifthenelset &to_code_ifthenelse(codet &code)
533
547
return static_cast <code_ifthenelset &>(code);
534
548
}
535
549
536
- /* ! \brief A `switch' instruction
537
- */
550
+ // / \ref codet representing a `switch` statement.
538
551
class code_switcht :public codet
539
552
{
540
553
public:
@@ -596,8 +609,7 @@ inline code_switcht &to_code_switch(codet &code)
596
609
return static_cast <code_switcht &>(code);
597
610
}
598
611
599
- /* ! \brief A `while' instruction
600
- */
612
+ // / \ref codet representing a `while` statement.
601
613
class code_whilet :public codet
602
614
{
603
615
public:
@@ -659,8 +671,7 @@ inline code_whilet &to_code_while(codet &code)
659
671
return static_cast <code_whilet &>(code);
660
672
}
661
673
662
- /* ! \brief A `do while' instruction
663
- */
674
+ // / \ref codet representation of a `do while` statement.
664
675
class code_dowhilet :public codet
665
676
{
666
677
public:
@@ -722,8 +733,7 @@ inline code_dowhilet &to_code_dowhile(codet &code)
722
733
return static_cast <code_dowhilet &>(code);
723
734
}
724
735
725
- /* ! \brief A `for' instruction
726
- */
736
+ // / \ref codet representation of a `for` statement.
727
737
class code_fort :public codet
728
738
{
729
739
public:
@@ -798,8 +808,7 @@ inline code_fort &to_code_for(codet &code)
798
808
return static_cast <code_fort &>(code);
799
809
}
800
810
801
- /* ! \brief A `goto' instruction
802
- */
811
+ // / \ref codet representation of a `goto` statement.
803
812
class code_gotot :public codet
804
813
{
805
814
public:
@@ -848,13 +857,11 @@ inline code_gotot &to_code_goto(codet &code)
848
857
return static_cast <code_gotot &>(code);
849
858
}
850
859
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.
858
865
class code_function_callt :public codet
859
866
{
860
867
public:
@@ -918,8 +925,7 @@ inline code_function_callt &to_code_function_call(codet &code)
918
925
return static_cast <code_function_callt &>(code);
919
926
}
920
927
921
- /* ! \brief Return from a function
922
- */
928
+ // / \ref codet representation of a "return from a function" statement.
923
929
class code_returnt :public codet
924
930
{
925
931
public:
@@ -972,8 +978,7 @@ inline code_returnt &to_code_return(codet &code)
972
978
return static_cast <code_returnt &>(code);
973
979
}
974
980
975
- /* ! \brief A label for branch targets
976
- */
981
+ // / \ref codet representation of a label for branch targets.
977
982
class code_labelt :public codet
978
983
{
979
984
public:
@@ -1040,8 +1045,8 @@ inline code_labelt &to_code_label(codet &code)
1040
1045
return static_cast <code_labelt &>(code);
1041
1046
}
1042
1047
1043
- /* ! \brief A switch-case
1044
- */
1048
+ // / \ref codet representation of a switch-case, i.e.\ a `case` statement within
1049
+ // / a `switch`.
1045
1050
class code_switch_caset :public codet
1046
1051
{
1047
1052
public:
@@ -1110,8 +1115,8 @@ inline code_switch_caset &to_code_switch_case(codet &code)
1110
1115
return static_cast <code_switch_caset &>(code);
1111
1116
}
1112
1117
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).
1115
1120
class code_breakt :public codet
1116
1121
{
1117
1122
public:
@@ -1140,8 +1145,8 @@ inline code_breakt &to_code_break(codet &code)
1140
1145
return static_cast <code_breakt &>(code);
1141
1146
}
1142
1147
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).
1145
1150
class code_continuet :public codet
1146
1151
{
1147
1152
public:
@@ -1170,8 +1175,7 @@ inline code_continuet &to_code_continue(codet &code)
1170
1175
return static_cast <code_continuet &>(code);
1171
1176
}
1172
1177
1173
- /* ! \brief An inline assembler statement
1174
- */
1178
+ // / \ref codet representation of an inline assembler statement.
1175
1179
class code_asmt :public codet
1176
1180
{
1177
1181
public:
@@ -1215,8 +1219,8 @@ inline const code_asmt &to_code_asm(const codet &code)
1215
1219
return static_cast <const code_asmt &>(code);
1216
1220
}
1217
1221
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.
1220
1224
class code_expressiont :public codet
1221
1225
{
1222
1226
public:
@@ -1266,8 +1270,11 @@ inline const code_expressiont &to_code_expression(const codet &code)
1266
1270
return static_cast <const code_expressiont &>(code);
1267
1271
}
1268
1272
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`.
1271
1278
class side_effect_exprt :public exprt
1272
1279
{
1273
1280
public:
@@ -1335,8 +1342,7 @@ inline const side_effect_exprt &to_side_effect_expr(const exprt &expr)
1335
1342
return static_cast <const side_effect_exprt &>(expr);
1336
1343
}
1337
1344
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.
1340
1346
class side_effect_expr_nondett :public side_effect_exprt
1341
1347
{
1342
1348
public:
@@ -1390,8 +1396,7 @@ inline const side_effect_expr_nondett &to_side_effect_expr_nondet(
1390
1396
return static_cast <const side_effect_expr_nondett &>(side_effect_expr_nondet);
1391
1397
}
1392
1398
1393
- /* ! \brief A function call side effect
1394
- */
1399
+ // / A \ref side_effect_exprt representation of a function call side effect.
1395
1400
class side_effect_expr_function_callt :public side_effect_exprt
1396
1401
{
1397
1402
public:
@@ -1486,8 +1491,8 @@ inline const side_effect_expr_function_callt
1486
1491
return static_cast <const side_effect_expr_function_callt &>(expr);
1487
1492
}
1488
1493
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.
1491
1496
class side_effect_expr_throwt :public side_effect_exprt
1492
1497
{
1493
1498
public:
@@ -1534,12 +1539,12 @@ inline const side_effect_expr_throwt &to_side_effect_expr_throw(
1534
1539
// / exception_tag1 -> label1
1535
1540
// / exception_tag2 -> label2
1536
1541
// / ...
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
1539
1544
// / be in one-to-one correspondence with the exception tags.
1540
1545
// / 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
1543
1548
// / time.
1544
1549
class code_push_catcht :public codet
1545
1550
{
@@ -1702,8 +1707,7 @@ static inline const code_landingpadt &to_code_landingpad(const codet &code)
1702
1707
return static_cast <const code_landingpadt &>(code);
1703
1708
}
1704
1709
1705
- /* ! \brief A try/catch block
1706
- */
1710
+ // / \ref codet representation of a try/catch block.
1707
1711
class code_try_catcht :public codet
1708
1712
{
1709
1713
public:
0 commit comments