Skip to content

Commit 09c971c

Browse files
author
Owen Jones
committed
Move documentation of irept to be above irept
It was in the documentation for the util folder.
1 parent ec79bdd commit 09c971c

File tree

2 files changed

+74
-73
lines changed

2 files changed

+74
-73
lines changed

src/util/README.md

+3-71
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,11 @@
1010
This section discusses some of the key data-structures used in the
1111
CPROVER codebase.
1212

13-
\subsection irept Irept Data Structure
13+
\subsection irept_section Irept Data Structure
1414

15-
There are a large number of kinds of tree structured or tree-like data in
16-
CPROVER. `irept` provides a single, unified representation for all of
17-
these, allowing structure sharing and reference counting of data. As
18-
such `irept` is the basic unit of data in CPROVER. Each `irept`
19-
contains[^1] a basic unit of data (of type `dt`) which contains four
20-
things:
15+
See \ref irept for more information.
2116

22-
* `data`: A string[^2], which is returned when the `id()` function is
23-
used.
24-
25-
* `named_sub`: A map from `irep_namet` (a string) to `irept`. This
26-
is used for named children, i.e. subexpressions, parameters, etc.
27-
28-
* `comments`: Another map from `irep_namet` to `irept` which is used
29-
for annotations and other ‘non-semantic’ information
30-
31-
* `sub`: A vector of `irept` which is used to store ordered but
32-
unnamed children.
33-
34-
The `irept::pretty` function outputs the contents of an `irept` directly
35-
and can be used to understand and debug problems with `irept`s.
36-
37-
On their own `irept`s do not “mean” anything; they are effectively
38-
generic tree nodes. Their interpretation depends on the contents of
39-
result of the `id` function (the `data`) field. `util/irep_ids.txt`
40-
contains the complete list of `id` values. During the build process it
41-
is used to generate `util/irep_ids.h` which gives constants for each id
42-
(named `ID_`). These can then be used to identify what kind of data
43-
`irept` stores and thus what can be done with it.
44-
45-
To simplify this process, there are a variety of classes that inherit
46-
from `irept`, roughly corresponding to the ids listed (i.e. `ID_or`
47-
(the string `"or”`) corresponds to the class `or_exprt`). These give
48-
semantically relevant accessor functions for the data; effectively
49-
different APIs for the same underlying data structure. None of these
50-
classes add fields (only methods) and so static casting can be used. The
51-
inheritance graph of the subclasses of `irept` is a useful starting
52-
point for working out how to manipulate data.
53-
54-
There are three main groups of classes (or APIs); those derived from
55-
`typet`, `codet` and `exprt` respectively. Although all of these inherit
56-
from `irept`, these are the most abstract level that code should handle
57-
data. If code is manipulating plain `irept`s then something is wrong
58-
with the architecture of the code.
59-
60-
Many of the key descendent of `exprt` are declared in `std_expr.h`. All
61-
expressions have a named subfield / annotation which gives the type of
62-
the expression (slightly simplified from C/C++ as `unsignedbv_typet`,
63-
`signedbv_typet`, `floatbv_typet`, etc.). All type conversions are
64-
explicit with an expression with `id() == ID_typecast` and an ‘interface
65-
class’ named `typecast_exprt`. One key descendent of `exprt` is
66-
`symbol_exprt` which creates `irept` instances with the id of “symbol”.
67-
These are used to represent variables; the name of which can be found
68-
using the `get_identifier` accessor function.
69-
70-
`codet` inherits from `exprt` and is defined in `std_code.h`. It
71-
represents executable code; statements in C rather than expressions. In
72-
the front-end there are versions of these that hold whole code blocks,
73-
but in goto-programs these have been flattened so that each `irept`
74-
represents one sequence point (almost one line of code / one
75-
semi-colon). The most common descendents of `codet` are `code_assignt`
76-
so a common pattern is to cast the `codet` to an assignment and then
77-
recurse on the expression on either side.
78-
79-
[^1]: Or references, if reference counted data sharing is enabled. It is
80-
enabled by default; see the `SHARING` macro.
81-
82-
[^2]: Unless `USE_STD_STRING` is set, this is actually
83-
a `dstring` and thus an integer which is a reference into a string table
84-
85-
\subsection irep_idt Irep_idt and Dstringt
17+
\subsection irep_idt_section Irep_idt and Dstringt
8618

8719
Inside `irept`s, strings are stored as `irep_idt`s, or `irep_namet`s for
8820
keys to `named_sub` or `comments`. If `USE_STD_STRING` is set then both

src/util/irep.h

+71-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,77 @@ inline const std::string &name2string(const irep_namet &n)
8282
class irept;
8383
const irept &get_nil_irep();
8484

85-
/*! \brief Base class for tree-like data structures with sharing
86-
*/
85+
/// \brief Base class for tree-like data structures with sharing
86+
///
87+
/// There are a large number of kinds of tree structured or tree-like data in
88+
/// CPROVER. `irept` provides a single, unified representation for all of
89+
/// these, allowing structure sharing and reference counting of data. As
90+
/// such `irept` is the basic unit of data in CPROVER. Each `irept`
91+
/// contains[^1] a basic unit of data (of type `dt`) which contains four
92+
/// things:
93+
///
94+
/// * `data`: A string[^2], which is returned when the `id()` function is
95+
/// used.
96+
///
97+
/// * `named_sub`: A map from `irep_namet` (a string) to `irept`. This
98+
/// is used for named children, i.e. subexpressions, parameters, etc.
99+
///
100+
/// * `comments`: Another map from `irep_namet` to `irept` which is used
101+
/// for annotations and other ‘non-semantic’ information
102+
///
103+
/// * `sub`: A vector of `irept` which is used to store ordered but
104+
/// unnamed children.
105+
///
106+
/// The `irept::pretty` function outputs the contents of an `irept` directly
107+
/// and can be used to understand and debug problems with `irept`s.
108+
///
109+
/// On their own `irept`s do not “mean” anything; they are effectively
110+
/// generic tree nodes. Their interpretation depends on the contents of
111+
/// result of the `id` function (the `data`) field. `util/irep_ids.txt`
112+
/// contains the complete list of `id` values. During the build process it
113+
/// is used to generate `util/irep_ids.h` which gives constants for each id
114+
/// (named `ID_`). These can then be used to identify what kind of data
115+
/// `irept` stores and thus what can be done with it.
116+
///
117+
/// To simplify this process, there are a variety of classes that inherit
118+
/// from `irept`, roughly corresponding to the ids listed (i.e. `ID_or`
119+
/// (the string `"or”`) corresponds to the class `or_exprt`). These give
120+
/// semantically relevant accessor functions for the data; effectively
121+
/// different APIs for the same underlying data structure. None of these
122+
/// classes add fields (only methods) and so static casting can be used. The
123+
/// inheritance graph of the subclasses of `irept` is a useful starting
124+
/// point for working out how to manipulate data.
125+
///
126+
/// There are three main groups of classes (or APIs); those derived from
127+
/// `typet`, `codet` and `exprt` respectively. Although all of these inherit
128+
/// from `irept`, these are the most abstract level that code should handle
129+
/// data. If code is manipulating plain `irept`s then something is wrong
130+
/// with the architecture of the code.
131+
///
132+
/// Many of the key descendant of `exprt` are declared in `std_expr.h`. All
133+
/// expressions have a named subfield / annotation which gives the type of
134+
/// the expression (slightly simplified from C/C++ as `unsignedbv_typet`,
135+
/// `signedbv_typet`, `floatbv_typet`, etc.). All type conversions are
136+
/// explicit with an expression with `id() == ID_typecast` and an ‘interface
137+
/// class’ named `typecast_exprt`. One key descendant of `exprt` is
138+
/// `symbol_exprt` which creates `irept` instances with the id of “symbol”.
139+
/// These are used to represent variables; the name of which can be found
140+
/// using the `get_identifier` accessor function.
141+
///
142+
/// `codet` inherits from `exprt` and is defined in `std_code.h`. It
143+
/// represents executable code; statements in C rather than expressions. In
144+
/// the front-end there are versions of these that hold whole code blocks,
145+
/// but in goto-programs these have been flattened so that each `irept`
146+
/// represents one sequence point (almost one line of code / one
147+
/// semi-colon). The most common descendants of `codet` are `code_assignt`
148+
/// so a common pattern is to cast the `codet` to an assignment and then
149+
/// recurse on the expression on either side.
150+
///
151+
/// [^1]: Or references, if reference counted data sharing is enabled. It is
152+
/// enabled by default; see the `SHARING` macro.
153+
///
154+
/// [^2]: Unless `USE_STD_STRING` is set, this is actually
155+
/// a `dstring` and thus an integer which is a reference into a string table
87156
class irept
88157
{
89158
public:

0 commit comments

Comments
 (0)