Browse Source

Further work on new expression classes.

Former-commit-id: 4b0a6bca70
tempestpy_adaptions
dehnert 11 years ago
parent
commit
232f72ffaa
  1. 25
      src/storage/expressions/BooleanConstantExpression.cpp
  2. 19
      src/storage/expressions/BooleanConstantExpression.h
  3. 38
      src/storage/expressions/ConstantExpression.cpp
  4. 29
      src/storage/expressions/ConstantExpression.h
  5. 2
      src/storage/expressions/ExpressionVisitor.h

25
src/storage/expressions/BooleanConstantExpression.cpp

@ -2,8 +2,31 @@
namespace storm {
namespace expressions {
BooleanConstantExpression::BooleanConstantExpression(std::string const& constantName) : ConstantExpression(ReturnType::bool_, constantName) {
BooleanConstantExpression::BooleanConstantExpression(std::string const& constantName) : ConstantExpression(ExpressionReturnType::bool_, constantName) {
// Intentionally left empty.
}
BooleanConstantExpression::BooleanConstantExpression(BooleanConstantExpression const& other) : ConstantExpression(other) {
// Intentionally left empty.
}
BooleanConstantExpression& BooleanConstantExpression::operator=(BooleanConstantExpression const& other) {
if (this != &other) {
ConstantExpression::operator=(other);
}
return *this;
}
bool BooleanConstantExpression::evaluateAsBool(Valuation const& valuation) const {
return valuation.getBooleanValue(this->getConstantName());
}
std::unique_ptr<BaseExpression> BooleanConstantExpression::clone() const {
return std::unique_ptr<BaseExpression>(new BooleanConstantExpression(*this));
}
void BooleanConstantExpression::accept(ExpressionVisitor* visitor) const {
visitor->visit(this);
}
}
}

19
src/storage/expressions/BooleanConstantExpression.h

@ -7,8 +7,27 @@ namespace storm {
namespace expressions {
class BooleanConstantExpression : public ConstantExpression {
public:
/*!
* Creates a boolean constant expression with the given return type and constant name.
*
* @param returnType The return type of the expression.
* @param constantName The name of the boolean constant associated with this expression.
*/
BooleanConstantExpression(std::string const& constantName);
// Provide custom versions of copy construction and assignment.
BooleanConstantExpression(BooleanConstantExpression const& other);
BooleanConstantExpression& operator=(BooleanConstantExpression const& other);
// Create default variants of move construction/assignment and virtual destructor.
BooleanConstantExpression(BooleanConstantExpression&&) = default;
BooleanConstantExpression& operator=(BooleanConstantExpression&&) = default;
virtual ~BooleanConstantExpression() = default;
// Override base class methods.
virtual bool evaluateAsBool(Valuation const& valuation) const;
virtual std::unique_ptr<BaseExpression> clone() const;
virtual void accept(ExpressionVisitor* visitor) const;
};
}
}

38
src/storage/expressions/ConstantExpression.cpp

@ -2,10 +2,46 @@
namespace storm {
namespace expressions {
ConstantExpression::ConstantExpression(ReturnType returnType, std::string const& constantName) : BaseExpression(returnType), constantName(constantName) {
ConstantExpression::ConstantExpression(ExpressionReturnType returnType, std::string const& constantName) : BaseExpression(returnType), constantName(constantName) {
// Intentionally left empty.
}
ConstantExpression::ConstantExpression(ConstantExpression const& other) : BaseExpression(other), constantName(other.getConstantName()) {
// Intentionally left empty.
}
ConstantExpression& ConstantExpression::operator=(ConstantExpression const& other) {
if (this != &other) {
BaseExpression::operator=(other);
this->constantName = other.getConstantName();
}
return *this;
}
bool ConstantExpression::isConstant() const {
return false;
}
bool ConstantExpression::isTrue() const {
return false;
}
bool ConstantExpression::isFalse() const {
return false;
}
std::set<std::string> ConstantExpression::getVariables() const {
return std::set<std::string>();
}
std::set<std::string> ConstantExpression::getConstants() const {
return {this->getConstantName()};
}
std::unique_ptr<BaseExpression> ConstantExpression::simplify() const {
return this->clone();
}
std::string const& ConstantExpression::getConstantName() const {
return this->constantName;
}

29
src/storage/expressions/ConstantExpression.h

@ -6,12 +6,41 @@
namespace storm {
namespace expressions {
class ConstantExpression : public BaseExpression {
public:
/*!
* Creates a constant expression with the given return type and constant name.
*
* @param returnType The return type of the expression.
* @param constantName The name of the constant associated with this expression.
*/
ConstantExpression(ExpressionReturnType returnType, std::string const& constantName);
// Provide custom versions of copy construction and assignment.
ConstantExpression(ConstantExpression const& other);
ConstantExpression& operator=(ConstantExpression const& other);
// Create default variants of move construction/assignment and virtual destructor.
ConstantExpression(ConstantExpression&&) = default;
ConstantExpression& operator=(ConstantExpression&&) = default;
virtual ~ConstantExpression() = default;
// Override base class methods.
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;
/*!
* Retrieves the name of the constant.
*
* @return The name of the constant.
*/
std::string const& getConstantName() const;
private:
// The name of the constant.
std::string constantName;
};
}

2
src/storage/expressions/ExpressionVisitor.h

@ -4,6 +4,7 @@
#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 {
@ -11,6 +12,7 @@ namespace storm {
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;
};
}
}
Loading…
Cancel
Save