9 changed files with 228 additions and 8 deletions
-
31src/exceptions/ExceptionMacros.h
-
23src/storage/expressions/BaseExpression.cpp
-
43src/storage/expressions/BaseExpression.h
-
7src/storage/expressions/Expression.cpp
-
8src/storage/expressions/Expression.h
-
17src/storage/expressions/SubstitutionVisitor.cpp
-
4src/storage/expressions/SubstitutionVisitor.h
-
56src/storage/expressions/VariableExpression.cpp
-
47src/storage/expressions/VariableExpression.h
@ -0,0 +1,31 @@ |
|||||
|
#ifndef STORM_EXCEPTIONS_EXCEPTIONMACROS_H_ |
||||
|
#define STORM_EXCEPTIONS_EXCEPTIONMACROS_H_ |
||||
|
|
||||
|
#include <cassert> |
||||
|
|
||||
|
#include "log4cplus/logger.h" |
||||
|
#include "log4cplus/loggingmacros.h" |
||||
|
|
||||
|
extern log4cplus::Logger logger; |
||||
|
|
||||
|
#ifndef NDEBUG |
||||
|
#define LOG_ASSERT(cond, message) \ |
||||
|
{ \ |
||||
|
if (!(cond)) { \ |
||||
|
LOG4CPLUS_ERROR(logger, message); \ |
||||
|
assert(cond); \ |
||||
|
} \ |
||||
|
} while (false) |
||||
|
#define LOG_THROW(cond, exception, message) \ |
||||
|
{ \ |
||||
|
if (!(cond)) { \ |
||||
|
LOG4CPLUS_ERROR(logger, message); \ |
||||
|
throw exception() << message; \ |
||||
|
} \ |
||||
|
} while (false) |
||||
|
#else |
||||
|
#define LOG_ASSERT(cond, message) /* empty */ |
||||
|
#define LOG_THROW(cond, exception, message) /* empty */ |
||||
|
#endif |
||||
|
|
||||
|
#endif /* STORM_EXCEPTIONS_EXCEPTIONMACROS_H_ */ |
@ -0,0 +1,23 @@ |
|||||
|
#include "src/storage/expressions/BaseExpression.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
BaseExpression::BaseExpression() : returnType(undefined) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
BaseExpression::BaseExpression(ExpressionReturnType returnType) : returnType(returnType) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
ExpressionReturnType BaseExpression::getReturnType() const { |
||||
|
return this->returnType; |
||||
|
} |
||||
|
|
||||
|
void BaseExpression::checkType(ExpressionReturnType actualType, ExpressionReturnType expectedType, std::string const& errorMessage) const { |
||||
|
if (actualType != expectedType) { |
||||
|
throw storm::exceptions::InvalidArgumentException() << errorMessage; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
#include <map>
|
||||
|
#include <unordered_map>
|
||||
|
|
||||
|
#include "src/storage/expressions/SubstitutionVisitor.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
template<template<typename... Arguments> class MapType> |
||||
|
Expression SubstitutionVisitor::substitute(BaseExpression const* expression, MapType<std::string, Expression> const& identifierToExpressionMap) { |
||||
|
return Expression(); |
||||
|
} |
||||
|
|
||||
|
// Explicitly instantiate substitute with map and unordered_map.
|
||||
|
template Expression SubstitutionVisitor::substitute<std::map>(BaseExpression const* expression, std::map<std::string, Expression> const& identifierToExpressionMap); |
||||
|
template Expression SubstitutionVisitor::substitute<std::unordered_map>(BaseExpression const* expression, std::unordered_map<std::string, Expression> const& identifierToExpressionMap); |
||||
|
} |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
#include "src/storage/expressions/VariableExpression.h"
|
||||
|
#include "src/exceptions/ExceptionMacros.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
VariableExpression::VariableExpression(ExpressionReturnType returnType, std::string const& variableName) : BaseExpression(returnType), variableName(variableName) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
std::string const& VariableExpression::getVariableName() const { |
||||
|
return this->variableName; |
||||
|
} |
||||
|
|
||||
|
int_fast64_t VariableExpression::evaluateAsInt(Valuation const& evaluation) const { |
||||
|
LOG_ASSERT((this->getReturnType() == ExpressionReturnType::int_), "Cannot evaluate expression as integer: return type is not an integer."); |
||||
|
return evaluation.getIntegerValue(this->getVariableName()); |
||||
|
} |
||||
|
|
||||
|
bool VariableExpression::evaluateAsBool(Valuation const& evaluation) const { |
||||
|
LOG_ASSERT((this->getReturnType() == ExpressionReturnType::bool_), "Cannot evaluate expression as integer: return type is not an integer."); |
||||
|
return evaluation.getBooleanValue(this->getVariableName()); |
||||
|
} |
||||
|
|
||||
|
double VariableExpression::evaluateAsDouble(Valuation const& evaluation) const { |
||||
|
LOG_ASSERT((this->getReturnType() == ExpressionReturnType::double_), "Cannot evaluate expression as integer: return type is not an integer."); |
||||
|
return evaluation.getDoubleValue(this->getVariableName()); |
||||
|
} |
||||
|
|
||||
|
std::unique_ptr<BaseExpression> VariableExpression::operator+(BaseExpression const& other) const { |
||||
|
// FIXME
|
||||
|
return nullptr; |
||||
|
} |
||||
|
|
||||
|
std::unique_ptr<BaseExpression> operator-(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> operator-() const; |
||||
|
std::unique_ptr<BaseExpression> operator*(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> operator/(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> operator&(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> operator|(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> operator~() const; |
||||
|
|
||||
|
std::unique_ptr<BaseExpression> equals(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> notEquals(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> greater(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> greaterOrEqual(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> less(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> lessOrEqual(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> minimum(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> maximum(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> mod(BaseExpression const& other) const; |
||||
|
std::unique_ptr<BaseExpression> floor() const; |
||||
|
std::unique_ptr<BaseExpression> ceil() const; |
||||
|
|
||||
|
void visit(ExpressionVisitor* visitor) const; |
||||
|
} |
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
#ifndef STORM_STORAGE_EXPRESSIONS_VARIABLEEXPRESSION_H_ |
||||
|
#define STORM_STORAGE_EXPRESSIONS_VARIABLEEXPRESSION_H_ |
||||
|
|
||||
|
#include "src/storage/expressions/BaseExpression.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
class VariableExpression : public BaseExpression { |
||||
|
VariableExpression(ExpressionReturnType returnType, std::string const& variableName); |
||||
|
virtual ~VariableExpression() = default; |
||||
|
|
||||
|
std::string const& getVariableName() const; |
||||
|
|
||||
|
virtual int_fast64_t evaluateAsInt(Valuation const& evaluation) const; |
||||
|
virtual bool evaluateAsBool(Valuation const& evaluation) const; |
||||
|
virtual double evaluateAsDouble(Valuation const& evaluation) const; |
||||
|
|
||||
|
virtual std::unique_ptr<BaseExpression> operator+(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator-(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator-() const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator*(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator/(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator&(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator|(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> operator~() const; |
||||
|
|
||||
|
virtual std::unique_ptr<BaseExpression> equals(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> notEquals(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> greater(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> greaterOrEqual(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> less(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> lessOrEqual(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> minimum(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> maximum(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> mod(BaseExpression const& other) const; |
||||
|
virtual std::unique_ptr<BaseExpression> floor() const; |
||||
|
virtual std::unique_ptr<BaseExpression> ceil() const; |
||||
|
|
||||
|
virtual void visit(ExpressionVisitor* visitor) const; |
||||
|
|
||||
|
private: |
||||
|
std::string variableName; |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#endif /* STORM_STORAGE_EXPRESSIONS_VARIABLEEXPRESSION_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue