Skip to content

Commit 71ee177

Browse files
authored
Merge pull request #8441 from diffblue/zero_expr
introduce `zero_expr()` and `one_expr()` for number types
2 parents dd54106 + 9fba581 commit 71ee177

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/util/mathematical_types.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include "mathematical_types.h"
1414

15+
#include "std_expr.h"
16+
1517
/// Returns true if the type is a rational, real, integer, natural, complex,
1618
/// unsignedbv, signedbv, floatbv or fixedbv.
1719
bool is_number(const typet &type)
@@ -21,3 +23,43 @@ bool is_number(const typet &type)
2123
id == ID_natural || id == ID_complex || id == ID_unsignedbv ||
2224
id == ID_signedbv || id == ID_floatbv || id == ID_fixedbv;
2325
}
26+
27+
constant_exprt integer_typet::zero_expr() const
28+
{
29+
return constant_exprt{ID_0, *this};
30+
}
31+
32+
constant_exprt integer_typet::one_expr() const
33+
{
34+
return constant_exprt{ID_1, *this};
35+
}
36+
37+
constant_exprt natural_typet::zero_expr() const
38+
{
39+
return constant_exprt{ID_0, *this};
40+
}
41+
42+
constant_exprt natural_typet::one_expr() const
43+
{
44+
return constant_exprt{ID_1, *this};
45+
}
46+
47+
constant_exprt rational_typet::zero_expr() const
48+
{
49+
return constant_exprt{ID_0, *this};
50+
}
51+
52+
constant_exprt rational_typet::one_expr() const
53+
{
54+
return constant_exprt{ID_1, *this};
55+
}
56+
57+
constant_exprt real_typet::zero_expr() const
58+
{
59+
return constant_exprt{ID_0, *this};
60+
}
61+
62+
constant_exprt real_typet::one_expr() const
63+
{
64+
return constant_exprt{ID_1, *this};
65+
}

src/util/mathematical_types.h

+14
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ Author: Daniel Kroening, [email protected]
1717
#include "invariant.h"
1818
#include "type.h"
1919

20+
class constant_exprt;
21+
2022
/// Unbounded, signed integers (mathematical integers, not bitvectors)
2123
class integer_typet : public typet
2224
{
2325
public:
2426
integer_typet() : typet(ID_integer)
2527
{
2628
}
29+
30+
constant_exprt zero_expr() const;
31+
constant_exprt one_expr() const;
2732
};
2833

2934
/// Natural numbers including zero (mathematical integers, not bitvectors)
@@ -33,6 +38,9 @@ class natural_typet : public typet
3338
natural_typet() : typet(ID_natural)
3439
{
3540
}
41+
42+
constant_exprt zero_expr() const;
43+
constant_exprt one_expr() const;
3644
};
3745

3846
/// Unbounded, signed rational numbers
@@ -42,6 +50,9 @@ class rational_typet : public typet
4250
rational_typet() : typet(ID_rational)
4351
{
4452
}
53+
54+
constant_exprt zero_expr() const;
55+
constant_exprt one_expr() const;
4556
};
4657

4758
/// Unbounded, signed real numbers
@@ -51,6 +62,9 @@ class real_typet : public typet
5162
real_typet() : typet(ID_real)
5263
{
5364
}
65+
66+
constant_exprt zero_expr() const;
67+
constant_exprt one_expr() const;
5468
};
5569

5670
/// A type for mathematical functions (do not confuse with functions/methods

0 commit comments

Comments
 (0)