Skip to content

Commit 92a4326

Browse files
author
svorenova
committed
Add documentation to typet
1 parent dbd6988 commit 92a4326

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
lines changed

src/util/type.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
/*******************************************************************\
22
3-
Module:
3+
Module: Data structure for a type of an expression
44
55
Author: Daniel Kroening, [email protected]
6+
Maria Svorenova, [email protected]
67
78
\*******************************************************************/
89

10+
/// \file
11+
/// Data structure for a type of an expression
12+
913
#include "type.h"
1014
#include "std_types.h"
1115
#include "namespace.h"
1216

17+
/// Copy the provided type to the subtypes of this type.
18+
/// \param type The type to add to subtypes
1319
void typet::copy_to_subtypes(const typet &type)
1420
{
1521
subtypes().push_back(type);
1622
}
1723

24+
/// Move the provided type to the subtypes of this type. Destroys the
25+
/// provided type.
26+
/// \param type The type to add to subtypes
1827
void typet::move_to_subtypes(typet &type)
1928
{
2029
subtypest &sub=subtypes();
2130
sub.push_back(static_cast<const typet &>(get_nil_irep()));
2231
sub.back().swap(type);
2332
}
2433

34+
/// Returns true if the type is a rational, real, integer, natural, complex,
35+
/// unsignedbv, signedbv, floatbv or fixedbv.
2536
bool is_number(const typet &type)
2637
{
2738
const irep_idt &id=type.id();
@@ -36,8 +47,8 @@ bool is_number(const typet &type)
3647
id==ID_fixedbv;
3748
}
3849

39-
/// Identify if a given type is constant itself or
40-
/// contains constant components. Examples include:
50+
/// Identify if a given type is constant itself or contains constant components.
51+
/// Examples include:
4152
/// - const int a;
4253
/// - struct contains_constant_pointer { int x; int * const p; };
4354
/// - const int b[3];

src/util/type.h

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/*******************************************************************\
22
3-
Module:
3+
Module: Data structure for a type of an expression
44
55
Author: Daniel Kroening, [email protected]
6+
Maria Svorenova, [email protected]
67
78
\*******************************************************************/
89

10+
/// \file
11+
/// Data structure for a type of an expression
912

1013
#ifndef CPROVER_UTIL_TYPE_H
1114
#define CPROVER_UTIL_TYPE_H
@@ -17,8 +20,37 @@ Author: Daniel Kroening, [email protected]
1720

1821
class namespacet;
1922

20-
/*! \brief The type of an expression
21-
*/
23+
/// The type of an expression, extends irept. Types may have subtypes. This is
24+
/// modeled with two subs named “subtype” (a single type) and “subtypes”
25+
/// (a vector of types). The class typet only adds specialized methods
26+
/// for accessing the subtype information to the interface of irept.
27+
/// Pre-defined types:
28+
/// universe - super type
29+
/// type - another type
30+
/// predicate - predicate expression (subtype and predicate)
31+
/// uninterpreted - uninterpreted type with identifier
32+
/// empty - void
33+
/// bool - true or false
34+
/// abstract - abstract super type
35+
/// struct - with components: each component has name and type,
36+
/// the ordering matters
37+
/// rational
38+
/// real
39+
/// integer
40+
/// complex
41+
/// string
42+
/// enum - with elements, the ordering does not matter
43+
/// tuple - with components: each component has type,
44+
/// the ordering matters
45+
/// mapping - domain -> range
46+
/// bv - no interpretation
47+
/// unsignedbv
48+
/// signedbv - two's complement
49+
/// floatbv - IEEE floating point format
50+
/// code
51+
/// pointer - for ANSI-C (subtype)
52+
/// symbol - look in symbol table (identifier)
53+
/// number - generic number super type
2254
class typet:public irept
2355
{
2456
public:
@@ -90,7 +122,7 @@ class typet:public irept
90122
{ remove(ID_subtype); }
91123
#endif
92124

93-
void move_to_subtypes(typet &type); // destroys expr
125+
void move_to_subtypes(typet &type);
94126

95127
void copy_to_subtypes(const typet &type);
96128

@@ -115,6 +147,7 @@ class typet:public irept
115147
}
116148
};
117149

150+
/// Type with a single subtype.
118151
class type_with_subtypet:public typet
119152
{
120153
public:
@@ -136,6 +169,7 @@ class type_with_subtypet:public typet
136169
#endif
137170
};
138171

172+
/// Type with multiple subtypes.
139173
class type_with_subtypest:public typet
140174
{
141175
public:
@@ -169,43 +203,8 @@ class type_with_subtypest:public typet
169203
for(typet::subtypest::iterator it=(type).subtypes().begin(); \
170204
it!=(type).subtypes().end(); ++it)
171205

172-
/*
173-
174-
pre-defined types:
175-
universe // super type
176-
type // another type
177-
predicate // predicate expression (subtype and predicate)
178-
uninterpreted // uninterpreted type with identifier
179-
empty // void
180-
bool // true or false
181-
abstract // abstract super type
182-
struct // with components: each component has name and type
183-
// the ordering matters
184-
rational
185-
real
186-
integer
187-
complex
188-
string
189-
enum // with elements
190-
// the ordering does not matter
191-
tuple // with components: each component has type
192-
// the ordering matters
193-
mapping // domain -> range
194-
bv // no interpretation
195-
unsignedbv
196-
signedbv // two's complement
197-
floatbv // IEEE floating point format
198-
code
199-
pointer // for ANSI-C (subtype)
200-
symbol // look in symbol table (identifier)
201-
number // generic number super type
202-
203-
*/
204-
205206
bool is_number(const typet &type);
206-
// rational, real, integer, complex, unsignedbv, signedbv, floatbv
207207

208-
// Is the passed in type const qualified?
209208
bool is_constant_or_has_constant_components(
210209
const typet &type,
211210
const namespacet &ns);

0 commit comments

Comments
 (0)