Skip to content

Commit a78b5bd

Browse files
committed
First part of codet documentation
All documentation is converted to the new Doxygen standard. All functions in codet (except getters/setters) are documented. Some examples are given for some subtypes of codet. It remains to add more details and examples to those subtypes, and to document their functions.
1 parent dbd6988 commit a78b5bd

File tree

3 files changed

+79
-61
lines changed

3 files changed

+79
-61
lines changed

src/util/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ a minus expression then you have to check its [id()](\ref irept::id()) (or use
8585

8686
\subsection codet_section codet
8787

88+
See documentation at \ref codet.
89+
8890
\ref exprt represents expressions and \ref codet represents statements.
8991
\ref codet inherits from \ref exprt, so all [codet](\ref codet)s are
9092
[exprt](\ref exprt)s, with [id()](\ref irept::id()) `ID_code`.

src/util/std_code.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*******************************************************************\
22
3-
Module:
3+
Module: Data structures representing statements in a program
44
55
Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9+
/// \file
10+
/// Data structure representing different types of statements in a program
911

1012
#include "std_code.h"
1113

@@ -21,6 +23,10 @@ const irep_idt &code_deadt::get_identifier() const
2123
return to_symbol_expr(symbol()).get_identifier();
2224
}
2325

26+
/// If this `codet` is a \ref code_blockt (i.e.\ it represents a block of
27+
/// statements), return the unmodified input. Otherwise (i.e.\ the `codet`
28+
/// represents a single statement), convert it to a \ref code_blockt with the
29+
/// original statement as its only operand and return the result.
2430
code_blockt &codet::make_block()
2531
{
2632
if(get_statement()==ID_block)
@@ -35,6 +41,8 @@ code_blockt &codet::make_block()
3541
return static_cast<code_blockt &>(*this);
3642
}
3743

44+
/// In the case of a `codet` type that represents multiple statements, return
45+
/// the first of them. Otherwise return the `codet` itself.
3846
codet &codet::first_statement()
3947
{
4048
const irep_idt &statement=get_statement();
@@ -50,6 +58,7 @@ codet &codet::first_statement()
5058
return *this;
5159
}
5260

61+
/// \copydoc first_statement()
5362
const codet &codet::first_statement() const
5463
{
5564
const irep_idt &statement=get_statement();
@@ -65,6 +74,8 @@ const codet &codet::first_statement() const
6574
return *this;
6675
}
6776

77+
/// In the case of a `codet` type that represents multiple statements, return
78+
/// the last of them. Otherwise return the `codet` itself.
6879
codet &codet::last_statement()
6980
{
7081
const irep_idt &statement=get_statement();
@@ -80,6 +91,7 @@ codet &codet::last_statement()
8091
return *this;
8192
}
8293

94+
/// \copydoc last_statement()
8395
const codet &codet::last_statement() const
8496
{
8597
const irep_idt &statement=get_statement();

src/util/std_code.h

+64-60
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************\
22
3-
Module:
3+
Module: Data structures representing statements in a program
44
55
Author: Daniel Kroening, [email protected]
66
@@ -16,8 +16,17 @@ Author: Daniel Kroening, [email protected]
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`.
2130
class codet:public exprt
2231
{
2332
public:
@@ -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.
89101
class code_blockt:public codet
90102
{
91103
public:
@@ -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.
179190
class code_skipt:public codet
180191
{
181192
public:
@@ -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)`.
196209
class code_assignt:public codet
197210
{
198211
public:
@@ -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)`.
254269
class code_declt:public codet
255270
{
256271
public:
@@ -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.
307322
class code_deadt:public codet
308323
{
309324
public:
@@ -461,8 +476,7 @@ inline code_assertt &to_code_assert(codet &code)
461476
code_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.
466480
class code_ifthenelset:public codet
467481
{
468482
public:
@@ -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.
538551
class code_switcht:public codet
539552
{
540553
public:
@@ -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.
601613
class code_whilet:public codet
602614
{
603615
public:
@@ -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.
664675
class code_dowhilet:public codet
665676
{
666677
public:
@@ -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.
727737
class code_fort:public codet
728738
{
729739
public:
@@ -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.
803812
class code_gotot:public codet
804813
{
805814
public:
@@ -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.
858865
class code_function_callt:public codet
859866
{
860867
public:
@@ -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.
923929
class code_returnt:public codet
924930
{
925931
public:
@@ -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.
977982
class code_labelt:public codet
978983
{
979984
public:
@@ -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`.
10451050
class code_switch_caset:public codet
10461051
{
10471052
public:
@@ -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).
11151120
class code_breakt:public codet
11161121
{
11171122
public:
@@ -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).
11451150
class code_continuet:public codet
11461151
{
11471152
public:
@@ -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.
11751179
class code_asmt:public codet
11761180
{
11771181
public:
@@ -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.
12201224
class code_expressiont:public codet
12211225
{
12221226
public:
@@ -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`.
12711278
class side_effect_exprt:public exprt
12721279
{
12731280
public:
@@ -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.
13401346
class side_effect_expr_nondett:public side_effect_exprt
13411347
{
13421348
public:
@@ -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.
13951400
class side_effect_expr_function_callt:public side_effect_exprt
13961401
{
13971402
public:
@@ -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.
14911496
class side_effect_expr_throwt:public side_effect_exprt
14921497
{
14931498
public:
@@ -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.
15441549
class 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.
17071711
class code_try_catcht:public codet
17081712
{
17091713
public:

0 commit comments

Comments
 (0)