diff --git a/src/util/mathematical_types.cpp b/src/util/mathematical_types.cpp index 874f3e915d0..01fb273bb06 100644 --- a/src/util/mathematical_types.cpp +++ b/src/util/mathematical_types.cpp @@ -12,6 +12,8 @@ Author: Daniel Kroening, kroening@kroening.com #include "mathematical_types.h" +#include "std_expr.h" + /// Returns true if the type is a rational, real, integer, natural, complex, /// unsignedbv, signedbv, floatbv or fixedbv. bool is_number(const typet &type) @@ -21,3 +23,43 @@ bool is_number(const typet &type) id == ID_natural || id == ID_complex || id == ID_unsignedbv || id == ID_signedbv || id == ID_floatbv || id == ID_fixedbv; } + +constant_exprt integer_typet::zero_expr() const +{ + return constant_exprt{ID_0, *this}; +} + +constant_exprt integer_typet::one_expr() const +{ + return constant_exprt{ID_1, *this}; +} + +constant_exprt natural_typet::zero_expr() const +{ + return constant_exprt{ID_0, *this}; +} + +constant_exprt natural_typet::one_expr() const +{ + return constant_exprt{ID_1, *this}; +} + +constant_exprt rational_typet::zero_expr() const +{ + return constant_exprt{ID_0, *this}; +} + +constant_exprt rational_typet::one_expr() const +{ + return constant_exprt{ID_1, *this}; +} + +constant_exprt real_typet::zero_expr() const +{ + return constant_exprt{ID_0, *this}; +} + +constant_exprt real_typet::one_expr() const +{ + return constant_exprt{ID_1, *this}; +} diff --git a/src/util/mathematical_types.h b/src/util/mathematical_types.h index d639ac0d684..48d4438b12e 100644 --- a/src/util/mathematical_types.h +++ b/src/util/mathematical_types.h @@ -17,6 +17,8 @@ Author: Daniel Kroening, kroening@kroening.com #include "invariant.h" #include "type.h" +class constant_exprt; + /// Unbounded, signed integers (mathematical integers, not bitvectors) class integer_typet : public typet { @@ -24,6 +26,9 @@ class integer_typet : public typet integer_typet() : typet(ID_integer) { } + + constant_exprt zero_expr() const; + constant_exprt one_expr() const; }; /// Natural numbers including zero (mathematical integers, not bitvectors) @@ -33,6 +38,9 @@ class natural_typet : public typet natural_typet() : typet(ID_natural) { } + + constant_exprt zero_expr() const; + constant_exprt one_expr() const; }; /// Unbounded, signed rational numbers @@ -42,6 +50,9 @@ class rational_typet : public typet rational_typet() : typet(ID_rational) { } + + constant_exprt zero_expr() const; + constant_exprt one_expr() const; }; /// Unbounded, signed real numbers @@ -51,6 +62,9 @@ class real_typet : public typet real_typet() : typet(ID_real) { } + + constant_exprt zero_expr() const; + constant_exprt one_expr() const; }; /// A type for mathematical functions (do not confuse with functions/methods