34 changed files with 751 additions and 215 deletions
-
12src/storage/expressions/BaseExpression.cpp
-
19src/storage/expressions/BaseExpression.h
-
24src/storage/expressions/BinaryBooleanFunctionExpression.cpp
-
10src/storage/expressions/BinaryBooleanFunctionExpression.h
-
44src/storage/expressions/BinaryNumericalFunctionExpression.cpp
-
10src/storage/expressions/BinaryNumericalFunctionExpression.h
-
26src/storage/expressions/BinaryRelationExpression.cpp
-
10src/storage/expressions/BinaryRelationExpression.h
-
15src/storage/expressions/BooleanConstantExpression.cpp
-
11src/storage/expressions/BooleanConstantExpression.h
-
49src/storage/expressions/BooleanLiteralExpression.cpp
-
49src/storage/expressions/BooleanLiteralExpression.h
-
24src/storage/expressions/ConstantExpression.cpp
-
11src/storage/expressions/ConstantExpression.h
-
14src/storage/expressions/DoubleConstantExpression.cpp
-
16src/storage/expressions/DoubleConstantExpression.h
-
41src/storage/expressions/DoubleLiteralExpression.cpp
-
47src/storage/expressions/DoubleLiteralExpression.h
-
28src/storage/expressions/ExpressionVisitor.h
-
18src/storage/expressions/IntegerConstantExpression.cpp
-
18src/storage/expressions/IntegerConstantExpression.h
-
45src/storage/expressions/IntegerLiteralExpression.cpp
-
48src/storage/expressions/IntegerLiteralExpression.h
-
53src/storage/expressions/SimpleValuation.h
-
2src/storage/expressions/SubstitutionVisitor.h
-
35src/storage/expressions/UnaryBooleanFunctionExpression.cpp
-
35src/storage/expressions/UnaryBooleanFunctionExpression.h
-
26src/storage/expressions/UnaryExpression.cpp
-
34src/storage/expressions/UnaryExpression.h
-
34src/storage/expressions/UnaryNumericalFunctionExpression.cpp
-
36src/storage/expressions/UnaryNumericalFunctionExpression.h
-
24src/storage/expressions/Valuation.h
-
43src/storage/expressions/VariableExpression.cpp
-
55src/storage/expressions/VariableExpression.h
@ -0,0 +1,49 @@ |
|||
#include "src/storage/expressions/BooleanLiteralExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
BooleanLiteralExpression::BooleanLiteralExpression(bool value) : value(value) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
bool BooleanLiteralExpression::evaluateAsBool(Valuation const& valuation) const { |
|||
return this->getValue(); |
|||
} |
|||
|
|||
bool BooleanLiteralExpression::isConstant() const { |
|||
return true; |
|||
} |
|||
|
|||
bool BooleanLiteralExpression::isTrue() const { |
|||
return this->getValue() == true; |
|||
} |
|||
|
|||
bool BooleanLiteralExpression::isFalse() const { |
|||
return this->getValue() == false; |
|||
} |
|||
|
|||
std::set<std::string> BooleanLiteralExpression::getVariables() const { |
|||
return {}; |
|||
} |
|||
|
|||
std::set<std::string> BooleanLiteralExpression::getConstants() const { |
|||
return {}; |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> BooleanLiteralExpression::simplify() const { |
|||
return this->clone(); |
|||
} |
|||
|
|||
void BooleanLiteralExpression::accept(ExpressionVisitor* visitor) const { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> BooleanLiteralExpression::clone() const { |
|||
return std::unique_ptr<BaseExpression>(new BooleanLiteralExpression(*this)); |
|||
} |
|||
|
|||
bool BooleanLiteralExpression::getValue() const { |
|||
return this->value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,49 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_BOOLEANLITERALEXPRESSION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_BOOLEANLITERALEXPRESSION_H_ |
|||
|
|||
#include "src/storage/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class BooleanLiteralExpression : BaseExpression { |
|||
public: |
|||
/*! |
|||
* Creates a boolean literal expression with the given value. |
|||
* |
|||
* @param value The value of the boolean literal. |
|||
*/ |
|||
BooleanLiteralExpression(bool value); |
|||
|
|||
// Instantiate constructors and assignments with their default implementations. |
|||
BooleanLiteralExpression(BooleanLiteralExpression const& other) = default; |
|||
BooleanLiteralExpression& operator=(BooleanLiteralExpression const& other) = default; |
|||
BooleanLiteralExpression(BooleanLiteralExpression&&) = default; |
|||
BooleanLiteralExpression& operator=(BooleanLiteralExpression&&) = default; |
|||
virtual ~BooleanLiteralExpression() = default; |
|||
|
|||
// Override base class methods. |
|||
virtual bool evaluateAsBool(Valuation const& valuation) const override; |
|||
virtual bool isConstant() const override; |
|||
virtual bool isTrue() const override; |
|||
virtual bool isFalse() const override; |
|||
virtual std::set<std::string> getVariables() const override; |
|||
virtual std::set<std::string> getConstants() const override; |
|||
virtual std::unique_ptr<BaseExpression> simplify() const override; |
|||
virtual void accept(ExpressionVisitor* visitor) const override; |
|||
virtual std::unique_ptr<BaseExpression> clone() const override; |
|||
|
|||
/*! |
|||
* Retrieves the value of the boolean literal. |
|||
* |
|||
* @return The value of the boolean literal. |
|||
*/ |
|||
bool getValue() const; |
|||
|
|||
private: |
|||
// The value of the boolean literal. |
|||
bool value; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_BOOLEANLITERALEXPRESSION_H_ */ |
@ -0,0 +1,41 @@ |
|||
#include "src/storage/expressions/DoubleLiteralExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
DoubleLiteralExpression::DoubleLiteralExpression(double value) : value(value) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
double DoubleLiteralExpression::evaluateAsDouble(Valuation const& valuation) const { |
|||
return this->getValue(); |
|||
} |
|||
|
|||
bool DoubleLiteralExpression::isConstant() const { |
|||
return true; |
|||
} |
|||
|
|||
std::set<std::string> DoubleLiteralExpression::getVariables() const { |
|||
return {}; |
|||
} |
|||
|
|||
std::set<std::string> DoubleLiteralExpression::getConstants() const { |
|||
return {}; |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> DoubleLiteralExpression::simplify() const { |
|||
return this->clone(); |
|||
} |
|||
|
|||
void DoubleLiteralExpression::accept(ExpressionVisitor* visitor) const { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> DoubleLiteralExpression::clone() const { |
|||
return std::unique_ptr<BaseExpression>(new DoubleLiteralExpression(*this)); |
|||
} |
|||
|
|||
double DoubleLiteralExpression::getValue() const { |
|||
return this->value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_DOUBLELITERALEXPRESSION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_DOUBLELITERALEXPRESSION_H_ |
|||
|
|||
#include "src/storage/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class DoubleLiteralExpression : BaseExpression { |
|||
public: |
|||
/*! |
|||
* Creates an double literal expression with the given value. |
|||
* |
|||
* @param value The value of the double literal. |
|||
*/ |
|||
DoubleLiteralExpression(double value); |
|||
|
|||
// Instantiate constructors and assignments with their default implementations. |
|||
DoubleLiteralExpression(DoubleLiteralExpression const& other) = default; |
|||
DoubleLiteralExpression& operator=(DoubleLiteralExpression const& other) = default; |
|||
DoubleLiteralExpression(DoubleLiteralExpression&&) = default; |
|||
DoubleLiteralExpression& operator=(DoubleLiteralExpression&&) = default; |
|||
virtual ~DoubleLiteralExpression() = default; |
|||
|
|||
// Override base class methods. |
|||
virtual double evaluateAsDouble(Valuation const& valuation) const override; |
|||
virtual bool isConstant() const override; |
|||
virtual std::set<std::string> getVariables() const override; |
|||
virtual std::set<std::string> getConstants() const override; |
|||
virtual std::unique_ptr<BaseExpression> simplify() const override; |
|||
virtual void accept(ExpressionVisitor* visitor) const override; |
|||
virtual std::unique_ptr<BaseExpression> clone() const override; |
|||
|
|||
/*! |
|||
* Retrieves the value of the double literal. |
|||
* |
|||
* @return The value of the double literal. |
|||
*/ |
|||
double getValue() const; |
|||
|
|||
private: |
|||
// The value of the double literal. |
|||
double value; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_DOUBLELITERALEXPRESSION_H_ */ |
@ -1,18 +1,36 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_EXPRESSIONVISITOR_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_EXPRESSIONVISITOR_H_ |
|||
|
|||
#include "src/storage/expressions/BinaryNumericalFunctionExpression.h" |
|||
#include "src/storage/expressions/BinaryBooleanFunctionExpression.h" |
|||
#include "src/storage/expressions/BinaryRelationExpression.h" |
|||
#include "src/storage/expressions/BooleanConstantExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
// Forward-declare all expression classes. |
|||
class BinaryBooleanFunctionExpression; |
|||
class BinaryNumericalFunctionExpression; |
|||
class BinaryRelationExpression; |
|||
class BooleanConstantExpression; |
|||
class DoubleConstantExpression; |
|||
class IntegerConstantExpression; |
|||
class IntegerConstantExpression; |
|||
class VariableExpression; |
|||
class UnaryBooleanFunctionExpression; |
|||
class UnaryNumericalFunctionExpression; |
|||
class BooleanLiteralExpression; |
|||
class IntegerLiteralExpression; |
|||
class DoubleLiteralExpression; |
|||
|
|||
class ExpressionVisitor { |
|||
virtual void visit(BinaryBooleanFunctionExpression const* expression) = 0; |
|||
virtual void visit(BinaryNumericalFunctionExpression const* expression) = 0; |
|||
virtual void visit(BinaryRelationExpression const* expression) = 0; |
|||
virtual void visit(BooleanConstantExpression const* expression) = 0; |
|||
virtual void visit(DoubleConstantExpression const* expression) = 0; |
|||
virtual void visit(IntegerConstantExpression const* expression) = 0; |
|||
virtual void visit(VariableExpression const* expression) = 0; |
|||
virtual void visit(UnaryBooleanFunctionExpression const* expression) = 0; |
|||
virtual void visit(UnaryNumericalFunctionExpression const* expression) = 0; |
|||
virtual void visit(BooleanLiteralExpression const* expression) = 0; |
|||
virtual void visit(IntegerLiteralExpression const* expression) = 0; |
|||
virtual void visit(DoubleLiteralExpression const* expression) = 0; |
|||
}; |
|||
} |
|||
} |
|||
|
@ -0,0 +1,45 @@ |
|||
#include "src/storage/expressions/IntegerLiteralExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
IntegerLiteralExpression::IntegerLiteralExpression(int_fast64_t value) : value(value) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
int_fast64_t IntegerLiteralExpression::evaluateAsInt(Valuation const& valuation) const { |
|||
return this->getValue(); |
|||
} |
|||
|
|||
double IntegerLiteralExpression::evaluateAsDouble(Valuation const& valuation) const { |
|||
return static_cast<double>(this->getValue()); |
|||
} |
|||
|
|||
bool IntegerLiteralExpression::isConstant() const { |
|||
return true; |
|||
} |
|||
|
|||
std::set<std::string> IntegerLiteralExpression::getVariables() const { |
|||
return {}; |
|||
} |
|||
|
|||
std::set<std::string> IntegerLiteralExpression::getConstants() const { |
|||
return {}; |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> IntegerLiteralExpression::simplify() const { |
|||
return this->clone(); |
|||
} |
|||
|
|||
void IntegerLiteralExpression::accept(ExpressionVisitor* visitor) const { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> IntegerLiteralExpression::clone() const { |
|||
return std::unique_ptr<BaseExpression>(new IntegerLiteralExpression(*this)); |
|||
} |
|||
|
|||
int_fast64_t IntegerLiteralExpression::getValue() const { |
|||
return this->value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_INTEGERLITERALEXPRESSION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_INTEGERLITERALEXPRESSION_H_ |
|||
|
|||
#include "src/storage/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class IntegerLiteralExpression : BaseExpression { |
|||
public: |
|||
/*! |
|||
* Creates an integer literal expression with the given value. |
|||
* |
|||
* @param value The value of the integer literal. |
|||
*/ |
|||
IntegerLiteralExpression(int_fast64_t value); |
|||
|
|||
// Instantiate constructors and assignments with their default implementations. |
|||
IntegerLiteralExpression(IntegerLiteralExpression const& other) = default; |
|||
IntegerLiteralExpression& operator=(IntegerLiteralExpression const& other) = default; |
|||
IntegerLiteralExpression(IntegerLiteralExpression&&) = default; |
|||
IntegerLiteralExpression& operator=(IntegerLiteralExpression&&) = default; |
|||
virtual ~IntegerLiteralExpression() = default; |
|||
|
|||
// Override base class methods. |
|||
virtual int_fast64_t evaluateAsInt(Valuation const& valuation) const override; |
|||
virtual double evaluateAsDouble(Valuation const& valuation) const override; |
|||
virtual bool isConstant() const override; |
|||
virtual std::set<std::string> getVariables() const override; |
|||
virtual std::set<std::string> getConstants() const override; |
|||
virtual std::unique_ptr<BaseExpression> simplify() const override; |
|||
virtual void accept(ExpressionVisitor* visitor) const override; |
|||
virtual std::unique_ptr<BaseExpression> clone() const override; |
|||
|
|||
/*! |
|||
* Retrieves the value of the integer literal. |
|||
* |
|||
* @return The value of the integer literal. |
|||
*/ |
|||
int_fast64_t getValue() const; |
|||
|
|||
private: |
|||
// The value of the integer literal. |
|||
int_fast64_t value; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_INTEGERLITERALEXPRESSION_H_ */ |
@ -1,9 +1,42 @@ |
|||
#include "src/storage/expressions/UnaryBooleanFunctionExpression.h"
|
|||
#include "src/storage/expressions/BooleanLiteralExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
UnaryBooleanFunctionExpression::UnaryBooleanFunctionExpression(ReturnType returnType, std::unique_ptr<BaseExpression>&& argument, FunctionType functionType) : UnaryExpression(returnType, std::move(argument)), functionType(functionType) { |
|||
UnaryBooleanFunctionExpression::UnaryBooleanFunctionExpression(ExpressionReturnType returnType, std::unique_ptr<BaseExpression>&& operand, OperatorType operatorType) : UnaryExpression(returnType, std::move(operand)), operatorType(operatorType) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
OperatorType UnaryBooleanFunctionExpression::getOperatorType() const { |
|||
return this->operatorType; |
|||
} |
|||
|
|||
bool UnaryBooleanFunctionExpression::evaluateAsBool(Valuation const& valuation) const { |
|||
bool operandEvaluated = this->getOperand()->evaluateAsBool(valuation); |
|||
switch (this->getOperatorType()) { |
|||
case OperatorType::Not: return !operandEvaluated; break; |
|||
} |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> UnaryBooleanFunctionExpression::simplify() const { |
|||
std::unique_ptr<BaseExpression> operandSimplified = this->getOperand()->simplify(); |
|||
switch (this->getOperatorType()) { |
|||
case OperatorType::Not: if (operandSimplified->isTrue()) { |
|||
return std::unique_ptr<BaseExpression>(new BooleanLiteralExpression(false)); |
|||
} else { |
|||
return std::unique_ptr<BaseExpression>(new BooleanLiteralExpression(true)); |
|||
} |
|||
} |
|||
|
|||
return UnaryBooleanFunctionExpression(this->getReturnType(), std::move(operandSimplified), this->getOperatorType()); |
|||
} |
|||
|
|||
void UnaryBooleanFunctionExpression::accept(ExpressionVisitor* visitor) const { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> UnaryBooleanFunctionExpression::clone() const { |
|||
return std::unique_ptr<BaseExpression>(new UnaryBooleanFunctionExpression(*this)); |
|||
} |
|||
} |
|||
} |
@ -1,16 +1,44 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_UNARYEXPRESSION_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_UNARYEXPRESSION_H_ |
|||
|
|||
#include "src/storage/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
class UnaryExpression : public BaseExpression { |
|||
public: |
|||
UnaryExpression(ExpressionReturnType returnType, std::unique_ptr<BaseExpression>&& argument); |
|||
/*! |
|||
* Creates a unary expression with the given return type and operand. |
|||
* |
|||
* @param returnType The return type of the expression. |
|||
* @param operand The operand of the unary expression. |
|||
*/ |
|||
UnaryExpression(ExpressionReturnType returnType, std::unique_ptr<BaseExpression>&& operand); |
|||
|
|||
// Provide custom versions of copy construction and assignment. |
|||
UnaryExpression(UnaryExpression const& other); |
|||
UnaryExpression& operator=(UnaryExpression const& other); |
|||
|
|||
// Create default variants of move construction/assignment and virtual destructor. |
|||
UnaryExpression(UnaryExpression&&) = default; |
|||
UnaryExpression& operator=(UnaryExpression&&) = default; |
|||
virtual ~UnaryExpression() = default; |
|||
|
|||
std::unique_ptr<BaseExpression> const& getArgument() const; |
|||
// Override base class methods. |
|||
virtual bool isConstant() const override; |
|||
virtual std::set<std::string> getVariables() const override; |
|||
virtual std::set<std::string> getConstants() const override; |
|||
|
|||
/*! |
|||
* Retrieves the operand of the unary expression. |
|||
* |
|||
* @return The operand of the unary expression. |
|||
*/ |
|||
std::unique_ptr<BaseExpression> const& getOperand() const; |
|||
|
|||
private: |
|||
std::unique_ptr<BaseExpression> argument; |
|||
// The operand of the unary expression. |
|||
std::unique_ptr<BaseExpression> operand; |
|||
}; |
|||
} |
|||
} |
|||
|
@ -1,9 +1,41 @@ |
|||
#include <cmath>
|
|||
|
|||
#include "src/storage/expressions/UnaryNumericalFunctionExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
UnaryNumericalFunctionExpression::UnaryNumericalFunctionExpression(ReturnType returnType, std::unique_ptr<BaseExpression>&& argument, FunctionType functionType) : UnaryExpression(returnType, std::move(argument)), functionType(functionType) { |
|||
UnaryNumericalFunctionExpression::UnaryNumericalFunctionExpression(ExpressionReturnType returnType, std::unique_ptr<BaseExpression>&& operand, OperatorType operatorType) : UnaryExpression(returnType, std::move(operand)), operatorType(operatorType) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
int_fast64_t UnaryNumericalFunctionExpression::evaluateAsInt(Valuation const& valuation) const { |
|||
int_fast64_t operandEvaluated = this->getOperand()->evaluateAsInt(valuation); |
|||
switch (this->getOperatorType()) { |
|||
case OperatorType::Minus: return -operandEvaluated; break; |
|||
case OperatorType::Floor: return std::floor(operandEvaluated); break; |
|||
case OperatorType::Ceil: return std::ceil(operandEvaluated); break; |
|||
} |
|||
} |
|||
|
|||
double UnaryNumericalFunctionExpression::evaluateAsDouble(Valuation const& valuation) const { |
|||
double operandEvaluated = this->getOperand()->evaluateAsDouble(valuation); |
|||
switch (this->getOperatorType()) { |
|||
case OperatorType::Minus: return -operandEvaluated; break; |
|||
case OperatorType::Floor: return std::floor(operandEvaluated); break; |
|||
case OperatorType::Ceil: return std::ceil(operandEvaluated); break; |
|||
} |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> UnaryNumericalFunctionExpression::simplify() const { |
|||
return std::unique_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(this->getReturnType(), this->getOperand()->simplify(), this->getOperatorType())); |
|||
} |
|||
|
|||
void UnaryNumericalFunctionExpression::accept(ExpressionVisitor* visitor) const { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::unique_ptr<BaseExpression> UnaryNumericalFunctionExpression::clone() const { |
|||
return std::unique_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(*this)); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue