Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Type.cpp
Go to the documentation of this file.
2
3#include <cmath>
4#include <sstream>
5
9
10namespace storm {
11namespace expressions {
12
14 // Intentionally left empty.
15}
16
17bool BaseType::operator==(BaseType const& other) const {
18 return this->getMask() == other.getMask();
19}
20
22 return false;
23}
24
26 return false;
27}
28
30 return true;
31}
32
34 return false;
35}
36
38 return true;
39}
40
42 return true;
43}
44
46 return false;
47}
48
50 return true;
51}
52
54 return false;
55}
56
58 return true;
59}
60
62 return false;
63}
64
66 return true;
67}
68
70 return false;
71}
72
76
77uint64_t BooleanType::getMask() const {
78 return BooleanType::mask;
79}
80
82 return "bool";
83}
84
85uint64_t IntegerType::getMask() const {
86 return IntegerType::mask;
87}
88
90 return "int";
91}
92
93BitVectorType::BitVectorType(std::size_t width) : width(width) {
94 // Intentionally left empty.
95}
96
97uint64_t BitVectorType::getMask() const {
98 return BitVectorType::mask;
99}
100
102 return "bv[" + std::to_string(width) + "]";
103}
104
105std::size_t BitVectorType::getWidth() const {
106 return width;
107}
108
109bool BitVectorType::operator==(BaseType const& other) const {
110 return BaseType::operator==(other) && this->width == static_cast<BitVectorType const&>(other).getWidth();
111}
112
113uint64_t RationalType::getMask() const {
114 return RationalType::mask;
115}
116
118 return "rational";
119}
120
121ArrayType::ArrayType(Type elementType) : elementType(elementType) {
122 // Intentionally left empty
123}
124
126 return elementType;
127}
128
129bool ArrayType::operator==(BaseType const& other) const {
130 return BaseType::operator==(other) && this->elementType == static_cast<ArrayType const&>(other).getElementType();
131}
132
133uint64_t ArrayType::getMask() const {
134 return ArrayType::mask;
135}
136
138 return "array[" + elementType.getStringRepresentation() + "]";
139}
140
142 return TranscendentalNumberType::mask;
143}
144
146 return "transcendental";
147}
148
149bool operator<(BaseType const& first, BaseType const& second) {
150 if (first.getMask() < second.getMask()) {
151 return true;
152 }
153 if (first.isBitVectorType() && second.isBitVectorType()) {
154 return static_cast<BitVectorType const&>(first).getWidth() < static_cast<BitVectorType const&>(second).getWidth();
155 }
156 if (first.isArrayType() && second.isArrayType()) {
157 return static_cast<ArrayType const&>(first).getElementType() < static_cast<ArrayType const&>(second).getElementType();
158 }
159 return false;
160}
161
162Type::Type() : manager(nullptr), innerType(nullptr) {
163 // Intentionally left empty.
164}
165
166Type::Type(std::shared_ptr<ExpressionManager const> const& manager, std::shared_ptr<BaseType> const& innerType) : manager(manager), innerType(innerType) {
167 // Intentionally left empty.
168}
169
170bool Type::operator==(Type const& other) const {
171 return *this->innerType == *other.innerType;
172}
173
174uint64_t Type::getMask() const {
175 return this->innerType->getMask();
176}
177
179 return this->innerType->isBooleanType();
180}
181
183 return this->innerType->isIntegerType();
184}
185
187 return this->innerType->isBitVectorType();
188}
189
191 return this->isIntegerType() || this->isRationalType() || this->isTranscendentalNumberType();
192}
193
194bool Type::isArrayType() const {
195 return this->innerType->isArrayType();
196}
197
199 return this->innerType->isTranscendentalNumberType();
200}
201
202std::string Type::getStringRepresentation() const {
203 return this->innerType->getStringRepresentation();
204}
205
206std::size_t Type::getWidth() const {
207 return static_cast<BitVectorType const&>(*this->innerType).getWidth();
208}
209
211 return static_cast<ArrayType const&>(*this->innerType).getElementType();
212}
213
215 return this->innerType->isRationalType();
216}
217
219 return *manager;
220}
221
222Type Type::plusMinusTimes(Type const& other) const {
223 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operands.");
224 return std::max(*this, other);
225}
226
228 STORM_LOG_THROW(this->isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operand.");
229 return *this;
230}
231
232Type Type::divide(Type const& other) const {
233 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException,
234 "Operator division requires numerical operands, got " << this->isNumericalType() << " and " << other.isNumericalType() << ".");
235 STORM_LOG_THROW(!this->isBitVectorType() && !other.isBitVectorType(), storm::exceptions::InvalidTypeException, "Operator requires non-bitvector operands.");
236 return std::max(*this, other);
237}
238
239Type Type::modulo(Type const& other) const {
240 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operands.");
241 return std::max(*this, other);
242}
243
244Type Type::logarithm(Type const& other) const {
245 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operands.");
246 return this->getManager().getRationalType();
247}
248
249Type Type::power(Type const& other, bool allowIntegerType) const {
250 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operands.");
251 STORM_LOG_THROW(!this->isBitVectorType() && !other.isBitVectorType(), storm::exceptions::InvalidTypeException, "Operator requires non-bitvector operands.");
252 if (allowIntegerType) {
253 return std::max(*this, other);
254 } else {
255 return this->getManager().getRationalType();
256 }
257}
258
260 STORM_LOG_THROW(this->isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operand.");
261 return this->getManager().getRationalType();
262}
263
264Type Type::logicalConnective(Type const& other) const {
265 STORM_LOG_THROW(this->isBooleanType() && other.isBooleanType(), storm::exceptions::InvalidTypeException, "Operator requires boolean operands.");
266 return *this;
267}
268
270 STORM_LOG_THROW(this->isBooleanType(), storm::exceptions::InvalidTypeException, "Operator requires boolean operand.");
271 return *this;
272}
273
275 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operands.");
276 return this->getManager().getBooleanType();
277}
278
279Type Type::ite(Type const& thenType, Type const& elseType) const {
280 STORM_LOG_THROW(this->isBooleanType(), storm::exceptions::InvalidTypeException, "Operator requires boolean condition.");
281 if (thenType == elseType) {
282 return thenType;
283 } else {
284 STORM_LOG_THROW(thenType.isNumericalType() && elseType.isNumericalType(), storm::exceptions::InvalidTypeException,
285 "Operator 'ite' requires proper types.");
286 return std::max(thenType, elseType);
287 }
288 return thenType;
289}
290
292 STORM_LOG_THROW(this->isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires rational operand.");
293 return this->getManager().getIntegerType();
294}
295
296Type Type::minimumMaximum(Type const& other) const {
297 STORM_LOG_THROW(this->isNumericalType() && other.isNumericalType(), storm::exceptions::InvalidTypeException, "Operator requires numerical operands.");
298 return std::max(*this, other);
299}
300
302 return *type1.innerType < *type2.innerType;
303}
304
305std::ostream& operator<<(std::ostream& stream, Type const& type) {
306 stream << type.getStringRepresentation();
307 return stream;
308}
309} // namespace expressions
310} // namespace storm
virtual std::string getStringRepresentation() const override
Returns a string representation of the type.
Definition Type.cpp:137
Type getElementType() const
Definition Type.cpp:125
ArrayType(Type elementType)
Definition Type.cpp:121
virtual bool operator==(BaseType const &other) const override
Checks whether two types are actually the same.
Definition Type.cpp:129
virtual uint64_t getMask() const override
Retrieves the mask that is associated with this type.
Definition Type.cpp:133
virtual bool isArrayType() const override
Definition Type.cpp:65
virtual bool isBooleanType() const
Definition Type.cpp:25
virtual bool isIntegerType() const
Definition Type.cpp:33
virtual bool isArrayType() const
Definition Type.cpp:61
virtual bool operator==(BaseType const &other) const
Checks whether two types are actually the same.
Definition Type.cpp:17
virtual bool isTranscendentalNumberType() const
Definition Type.cpp:69
virtual bool isRationalType() const
Definition Type.cpp:53
virtual bool isBitVectorType() const
Definition Type.cpp:45
virtual bool isErrorType() const
Definition Type.cpp:21
virtual uint64_t getMask() const =0
Retrieves the mask that is associated with this type.
virtual bool operator==(BaseType const &other) const override
Checks whether two types are actually the same.
Definition Type.cpp:109
virtual std::string getStringRepresentation() const override
Returns a string representation of the type.
Definition Type.cpp:101
std::size_t getWidth() const
Retrieves the bit width of the bounded type.
Definition Type.cpp:105
BitVectorType(std::size_t width)
Creates a new bounded bitvector type with the given bit width.
Definition Type.cpp:93
virtual bool isIntegerType() const override
Definition Type.cpp:41
virtual uint64_t getMask() const override
Retrieves the mask that is associated with this type.
Definition Type.cpp:97
virtual bool isBitVectorType() const override
Definition Type.cpp:49
virtual uint64_t getMask() const override
Retrieves the mask that is associated with this type.
Definition Type.cpp:77
virtual bool isBooleanType() const override
Definition Type.cpp:29
virtual std::string getStringRepresentation() const override
Returns a string representation of the type.
Definition Type.cpp:81
This class is responsible for managing a set of typed variables and all expressions using these varia...
Type const & getBooleanType() const
Retrieves the boolean type.
Type const & getIntegerType() const
Retrieves the unbounded integer type.
Type const & getRationalType() const
Retrieves the rational type.
virtual bool isIntegerType() const override
Definition Type.cpp:37
virtual std::string getStringRepresentation() const override
Returns a string representation of the type.
Definition Type.cpp:89
virtual uint64_t getMask() const override
Retrieves the mask that is associated with this type.
Definition Type.cpp:85
virtual std::string getStringRepresentation() const override
Returns a string representation of the type.
Definition Type.cpp:117
virtual bool isRationalType() const override
Definition Type.cpp:57
virtual uint64_t getMask() const override
Retrieves the mask that is associated with this type.
Definition Type.cpp:113
virtual bool isTranscendentalNumberType() const override
Definition Type.cpp:73
virtual uint64_t getMask() const override
Retrieves the mask that is associated with this type.
Definition Type.cpp:141
virtual std::string getStringRepresentation() const override
Returns a string representation of the type.
Definition Type.cpp:145
Type minus() const
Definition Type.cpp:227
Type getElementType() const
Retrieves the element type of the type, provided that it is an Array type.
Definition Type.cpp:210
bool isBooleanType() const
Checks whether this type is a boolean type.
Definition Type.cpp:178
Type modulo(Type const &other) const
Definition Type.cpp:239
bool operator==(Type const &other) const
Checks whether two types are the same.
Definition Type.cpp:170
Type logarithm(Type const &other) const
Definition Type.cpp:244
Type divide(Type const &other) const
Definition Type.cpp:232
Type power(Type const &other, bool allowIntegerType=false) const
Definition Type.cpp:249
storm::expressions::ExpressionManager const & getManager() const
Retrieves the manager of the type.
Definition Type.cpp:218
std::size_t getWidth() const
Retrieves the bit width of the type, provided that it is a bitvector type.
Definition Type.cpp:206
Type numericalComparison(Type const &other) const
Definition Type.cpp:274
Type plusMinusTimes(Type const &other) const
Definition Type.cpp:222
Type logicalConnective() const
Definition Type.cpp:269
bool isIntegerType() const
Checks whether this type is an integral type.
Definition Type.cpp:182
bool isNumericalType() const
Checks whether this type is a numerical type.
Definition Type.cpp:190
bool isArrayType() const
Checks whether this type is an array type.
Definition Type.cpp:194
std::string getStringRepresentation() const
Retrieves a string representation of the type.
Definition Type.cpp:202
Type ite(Type const &thenType, Type const &elseType) const
Definition Type.cpp:279
uint64_t getMask() const
Retrieves the bit mask of the type.
Definition Type.cpp:174
bool isRationalType() const
Checks whether this type is a rational type.
Definition Type.cpp:214
bool isTranscendentalNumberType() const
Checks whether this type is a transcendental number type.
Definition Type.cpp:198
Type trigonometric() const
Definition Type.cpp:259
bool isBitVectorType() const
Checks whether this type is a bitvector type.
Definition Type.cpp:186
Type minimumMaximum(Type const &other) const
Definition Type.cpp:296
Type floorCeil() const
Definition Type.cpp:291
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
Expression operator<(Expression const &first, Expression const &second)
std::ostream & operator<<(std::ostream &stream, BaseExpression const &expression)
LabParser.cpp.
Definition cli.cpp:18