Browse Source
On my way of splitting header/source files in IR to make forward-declaration easy.
main
On my way of splitting header/source files in IR to make forward-declaration easy.
main
34 changed files with 1305 additions and 957 deletions
-
7src/ir/Module.cpp
-
11src/ir/Module.h
-
71src/ir/expressions/BaseExpression.cpp
-
211src/ir/expressions/BaseExpression.h
-
58src/ir/expressions/BinaryBooleanFunctionExpression.cpp
-
121src/ir/expressions/BinaryBooleanFunctionExpression.h
-
29src/ir/expressions/BinaryExpression.cpp
-
70src/ir/expressions/BinaryExpression.h
-
82src/ir/expressions/BinaryNumericalFunctionExpression.cpp
-
157src/ir/expressions/BinaryNumericalFunctionExpression.h
-
66src/ir/expressions/BinaryRelationExpression.cpp
-
138src/ir/expressions/BinaryRelationExpression.h
-
62src/ir/expressions/BooleanConstantExpression.cpp
-
137src/ir/expressions/BooleanConstantExpression.h
-
62src/ir/expressions/BooleanLiteral.h
-
40src/ir/expressions/BooleanLiteralExpression.cpp
-
46src/ir/expressions/BooleanLiteralExpression.h
-
28src/ir/expressions/ConstantExpression.cpp
-
84src/ir/expressions/ConstantExpression.h
-
61src/ir/expressions/DoubleConstantExpression.cpp
-
130src/ir/expressions/DoubleConstantExpression.h
-
62src/ir/expressions/DoubleLiteral.h
-
40src/ir/expressions/DoubleLiteralExpression.cpp
-
46src/ir/expressions/DoubleLiteralExpression.h
-
77src/ir/expressions/ExpressionVisitor.h
-
2src/ir/expressions/IntegerConstantExpression.h
-
2src/ir/expressions/IntegerLiteral.h
-
4src/ir/expressions/UnaryBooleanFunctionExpression.h
-
4src/ir/expressions/UnaryNumericalFunctionExpression.h
-
107src/ir/expressions/VariableExpression.cpp
-
166src/ir/expressions/VariableExpression.h
-
6src/parser/prismparser/Includes.h
-
6src/parser/prismparser/VariableState.h
-
69src/parser/prismparser/VariableStateInterface.h
@ -0,0 +1,71 @@ |
|||
/*
|
|||
* BaseExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include "BaseExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
BaseExpression::BaseExpression() : type(undefined) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
BaseExpression::BaseExpression(ReturnType type) : type(type) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
BaseExpression::~BaseExpression() { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
int_fast64_t BaseExpression::getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (type != int_) { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression of type '" |
|||
<< this->getTypeName() << "' as 'int'."; |
|||
} |
|||
throw storm::exceptions::NotImplementedException() << "Cannot evaluate expression of type '" |
|||
<< this->getTypeName() << " because evaluation implementation is missing."; |
|||
} |
|||
|
|||
bool BaseExpression::getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (type != bool_) { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression of type '" |
|||
<< this->getTypeName() << "' as 'bool'."; |
|||
} |
|||
throw storm::exceptions::NotImplementedException() << "Cannot evaluate expression of type '" |
|||
<< this->getTypeName() << " because evaluation implementation is missing."; |
|||
} |
|||
|
|||
double BaseExpression::getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (type != bool_) { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression of type '" |
|||
<< this->getTypeName() << "' as 'double'."; |
|||
} |
|||
throw storm::exceptions::NotImplementedException() << "Cannot evaluate expression of type '" |
|||
<< this->getTypeName() << " because evaluation implementation is missing."; |
|||
} |
|||
|
|||
void BaseExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::string BaseExpression::getTypeName() const { |
|||
switch(type) { |
|||
case bool_: return std::string("bool"); |
|||
case int_: return std::string("int"); |
|||
case double_: return std::string("double"); |
|||
default: return std::string("undefined"); |
|||
} |
|||
} |
|||
|
|||
BaseExpression::ReturnType BaseExpression::getType() const { |
|||
return type; |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,58 @@ |
|||
/*
|
|||
* BinaryBooleanFunctionExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "BinaryBooleanFunctionExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
BinaryBooleanFunctionExpression::BinaryBooleanFunctionExpression(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right, FunctionType functionType) |
|||
: BinaryExpression(bool_, left, right), functionType(functionType) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> BinaryBooleanFunctionExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new BinaryBooleanFunctionExpression(this->getLeft()->clone(renaming, variableState), this->getRight()->clone(renaming, variableState), this->functionType)); |
|||
} |
|||
|
|||
bool BinaryBooleanFunctionExpression::getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
bool resultLeft = this->getLeft()->getValueAsBool(variableValues); |
|||
bool resultRight = this->getRight()->getValueAsBool(variableValues); |
|||
switch(functionType) { |
|||
case AND: return resultLeft & resultRight; break; |
|||
case OR: return resultLeft | resultRight; break; |
|||
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
|||
<< "Unknown boolean binary operator: '" << functionType << "'."; |
|||
} |
|||
} |
|||
|
|||
BinaryBooleanFunctionExpression::FunctionType BinaryBooleanFunctionExpression::getFunctionType() const { |
|||
return functionType; |
|||
} |
|||
|
|||
void BinaryBooleanFunctionExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::string BinaryBooleanFunctionExpression::toString() const { |
|||
std::stringstream result; |
|||
result << this->getLeft()->toString(); |
|||
switch (functionType) { |
|||
case AND: result << " & "; break; |
|||
case OR: result << " | "; break; |
|||
} |
|||
result << this->getRight()->toString(); |
|||
|
|||
return result.str(); |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,29 @@ |
|||
/*
|
|||
* BinaryBooleanFunctionExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include "BinaryExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
BinaryExpression::BinaryExpression(ReturnType type, std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right) |
|||
: BaseExpression(type), left(left), right(right) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> const& BinaryExpression::getLeft() const { |
|||
return left; |
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> const& BinaryExpression::getRight() const { |
|||
return right; |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,82 @@ |
|||
/*
|
|||
* BinaryBooleanFunctionExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "BinaryNumericalFunctionExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
BinaryNumericalFunctionExpression::BinaryNumericalFunctionExpression(ReturnType type, std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right, FunctionType functionType) |
|||
: BinaryExpression(type, left, right), functionType(functionType) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> BinaryNumericalFunctionExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new BinaryNumericalFunctionExpression(this->getType(), this->getLeft()->clone(renaming, variableState), this->getRight()->clone(renaming, variableState), this->functionType)); |
|||
} |
|||
|
|||
BinaryNumericalFunctionExpression::FunctionType BinaryNumericalFunctionExpression::getFunctionType() const { |
|||
return functionType; |
|||
} |
|||
|
|||
int_fast64_t BinaryNumericalFunctionExpression::getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (this->getType() != int_) { |
|||
BaseExpression::getValueAsInt(variableValues); |
|||
} |
|||
|
|||
int_fast64_t resultLeft = this->getLeft()->getValueAsInt(variableValues); |
|||
int_fast64_t resultRight = this->getRight()->getValueAsInt(variableValues); |
|||
switch(functionType) { |
|||
case PLUS: return resultLeft + resultRight; break; |
|||
case MINUS: return resultLeft - resultRight; break; |
|||
case TIMES: return resultLeft * resultRight; break; |
|||
case DIVIDE: return resultLeft / resultRight; break; |
|||
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
|||
<< "Unknown numeric binary operator: '" << functionType << "'."; |
|||
} |
|||
} |
|||
|
|||
double BinaryNumericalFunctionExpression::getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (this->getType() != double_) { |
|||
BaseExpression::getValueAsDouble(variableValues); |
|||
} |
|||
|
|||
double resultLeft = this->getLeft()->getValueAsDouble(variableValues); |
|||
double resultRight = this->getRight()->getValueAsDouble(variableValues); |
|||
switch(functionType) { |
|||
case PLUS: return resultLeft + resultRight; break; |
|||
case MINUS: return resultLeft - resultRight; break; |
|||
case TIMES: return resultLeft * resultRight; break; |
|||
case DIVIDE: return resultLeft / resultRight; break; |
|||
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
|||
<< "Unknown numeric binary operator: '" << functionType << "'."; |
|||
} |
|||
} |
|||
|
|||
void BinaryNumericalFunctionExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::string BinaryNumericalFunctionExpression::toString() const { |
|||
std::stringstream result; |
|||
result << this->getLeft()->toString(); |
|||
switch (functionType) { |
|||
case PLUS: result << " + "; break; |
|||
case MINUS: result << " - "; break; |
|||
case TIMES: result << " * "; break; |
|||
case DIVIDE: result << " / "; break; |
|||
} |
|||
result << this->getRight()->toString(); |
|||
return result.str(); |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,66 @@ |
|||
/*
|
|||
* BinaryBooleanFunctionExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "BinaryRelationExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
BinaryRelationExpression::BinaryRelationExpression(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right, RelationType relationType) |
|||
: BinaryExpression(bool_, left, right), relationType(relationType) { |
|||
// Nothing to do here
|
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> BinaryRelationExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new BinaryRelationExpression(this->getLeft()->clone(renaming, variableState), this->getRight()->clone(renaming, variableState), this->relationType)); |
|||
} |
|||
|
|||
bool BinaryRelationExpression::getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
int_fast64_t resultLeft = this->getLeft()->getValueAsInt(variableValues); |
|||
int_fast64_t resultRight = this->getRight()->getValueAsInt(variableValues); |
|||
switch(relationType) { |
|||
case EQUAL: return resultLeft == resultRight; break; |
|||
case NOT_EQUAL: return resultLeft != resultRight; break; |
|||
case LESS: return resultLeft < resultRight; break; |
|||
case LESS_OR_EQUAL: return resultLeft <= resultRight; break; |
|||
case GREATER: return resultLeft > resultRight; break; |
|||
case GREATER_OR_EQUAL: return resultLeft >= resultRight; break; |
|||
default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
|||
<< "Unknown boolean binary relation: '" << relationType << "'."; |
|||
} |
|||
} |
|||
|
|||
BinaryRelationExpression::RelationType BinaryRelationExpression::getRelationType() const { |
|||
return relationType; |
|||
} |
|||
|
|||
void BinaryRelationExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::string BinaryRelationExpression::toString() const { |
|||
std::stringstream result; |
|||
result << this->getLeft()->toString(); |
|||
switch (relationType) { |
|||
case EQUAL: result << " = "; break; |
|||
case NOT_EQUAL: result << " != "; break; |
|||
case LESS: result << " < "; break; |
|||
case LESS_OR_EQUAL: result << " <= "; break; |
|||
case GREATER: result << " > "; break; |
|||
case GREATER_OR_EQUAL: result << " >= "; break; |
|||
} |
|||
result << this->getRight()->toString(); |
|||
|
|||
return result.str(); |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,62 @@ |
|||
/*
|
|||
* BooleanConstantExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "BooleanConstantExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
BooleanConstantExpression::BooleanConstantExpression(std::string const& constantName) : ConstantExpression(bool_, constantName) { |
|||
defined = false; |
|||
value = false; |
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> BooleanConstantExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new BooleanConstantExpression(*this)); |
|||
} |
|||
|
|||
bool BooleanConstantExpression::getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (!defined) { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
|||
<< "Boolean constant '" << this->getConstantName() << "' is undefined."; |
|||
} else { |
|||
return value; |
|||
} |
|||
} |
|||
|
|||
void BooleanConstantExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::string BooleanConstantExpression::toString() const { |
|||
std::stringstream result; |
|||
result << this->getConstantName(); |
|||
if (defined) { |
|||
result << "[" << value << "]"; |
|||
} |
|||
return result.str(); |
|||
} |
|||
|
|||
bool BooleanConstantExpression::isDefined() const { |
|||
return defined; |
|||
} |
|||
|
|||
bool BooleanConstantExpression::getValue() const { |
|||
return value; |
|||
} |
|||
|
|||
void BooleanConstantExpression::define(bool value) { |
|||
defined = true; |
|||
this->value = value; |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -1,62 +0,0 @@ |
|||
/* |
|||
* BooleanLiteral.h |
|||
* |
|||
* Created on: 03.01.2013 |
|||
* Author: chris |
|||
*/ |
|||
|
|||
#ifndef BOOLEANLITERAL_H_ |
|||
#define BOOLEANLITERAL_H_ |
|||
|
|||
#include "src/ir/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
class BooleanLiteral : public BaseExpression { |
|||
public: |
|||
bool value; |
|||
|
|||
BooleanLiteral(bool value) : BaseExpression(bool_), value(value) { |
|||
|
|||
} |
|||
|
|||
virtual ~BooleanLiteral() { |
|||
|
|||
} |
|||
|
|||
virtual std::shared_ptr<BaseExpression> clone(const std::map<std::string, std::string>& renaming, const std::map<std::string, uint_fast64_t>& bools, const std::map<std::string, uint_fast64_t>& ints) { |
|||
return std::shared_ptr<BaseExpression>(new BooleanLiteral(this->value)); |
|||
} |
|||
|
|||
virtual bool getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
return value; |
|||
} |
|||
|
|||
virtual void accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
virtual std::string toString() const { |
|||
if (value) { |
|||
return std::string("true"); |
|||
} else { |
|||
return std::string("false"); |
|||
} |
|||
} |
|||
|
|||
virtual std::string dump(std::string prefix) const { |
|||
std::stringstream result; |
|||
result << prefix << "BooleanLiteral " << this->toString() << std::endl; |
|||
return result.str(); |
|||
} |
|||
}; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
#endif /* BOOLEANLITERAL_H_ */ |
@ -0,0 +1,40 @@ |
|||
/*
|
|||
* BooleanLiteralExpression.cpp |
|||
* |
|||
* Created on: 04.01.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include "BooleanLiteralExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
BooleanLiteralExpression::BooleanLiteralExpression(bool value) : BaseExpression(bool_), value(value) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> BooleanLiteralExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new BooleanLiteralExpression(this->value)); |
|||
} |
|||
|
|||
bool BooleanLiteralExpression::getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
return value; |
|||
} |
|||
|
|||
void BooleanLiteralExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
std::string BooleanLiteralExpression::toString() const { |
|||
if (value) { |
|||
return std::string("true"); |
|||
} else { |
|||
return std::string("false"); |
|||
} |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,46 @@ |
|||
/* |
|||
* BooleanLiteralExpression.h |
|||
* |
|||
* Created on: 03.01.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#ifndef STORM_IR_EXPRESSIONS_BOOLEANLITERALEXPRESSION_H_ |
|||
#define STORM_IR_EXPRESSIONS_BOOLEANLITERALEXPRESSION_H_ |
|||
|
|||
#include "src/ir/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
/*! |
|||
* A class representing a boolean literal. |
|||
*/ |
|||
class BooleanLiteralExpression : public BaseExpression { |
|||
public: |
|||
/*! |
|||
* Creates a boolean literal expression with the given value. |
|||
* |
|||
* @param value The value for the boolean literal. |
|||
*/ |
|||
BooleanLiteralExpression(bool value); |
|||
|
|||
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const override; |
|||
|
|||
virtual bool getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const override; |
|||
|
|||
virtual void accept(ExpressionVisitor* visitor) override; |
|||
|
|||
virtual std::string toString() const override; |
|||
|
|||
private: |
|||
// The value of the boolean literal. |
|||
bool value; |
|||
}; |
|||
|
|||
} // namespace expressions |
|||
} // namespace ir |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_IR_EXPRESSIONS_BOOLEANLITERALEXPRESSION_H_ */ |
@ -0,0 +1,28 @@ |
|||
/*
|
|||
* ConstantExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include "src/ir/expressions/ConstantExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
ConstantExpression::ConstantExpression(ReturnType type, std::string constantName) : BaseExpression(type), constantName(constantName) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
std::string const& ConstantExpression::getConstantName() const { |
|||
return constantName; |
|||
} |
|||
|
|||
virtual std::string ConstantExpression::toString() const { |
|||
return constantName; |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,61 @@ |
|||
/*
|
|||
* DoubleConstantExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "DoubleConstantExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
DoubleConstantExpression::DoubleConstantExpression(std::string const& constantName) : ConstantExpression(double_, constantName), defined(false), value(0) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
std::shared_ptr<BaseExpression> DoubleConstantExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new DoubleConstantExpression(*this)); |
|||
} |
|||
|
|||
double DoubleConstantExpression::getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (!defined) { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: " |
|||
<< "Double constant '" << this->getConstantName() << "' is undefined."; |
|||
} else { |
|||
return value; |
|||
} |
|||
} |
|||
|
|||
virtual void DoubleConstantExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
virtual std::string DoubleConstantExpression::toString() const { |
|||
std::stringstream result; |
|||
result << this->constantName; |
|||
if (defined) { |
|||
result << "[" << value << "]"; |
|||
} |
|||
return result.str(); |
|||
} |
|||
|
|||
bool DoubleConstantExpression::isDefined() { |
|||
return defined; |
|||
} |
|||
|
|||
double DoubleConstantExpression::getValue() { |
|||
return value; |
|||
} |
|||
|
|||
void DoubleConstantExpression::define(double value) { |
|||
defined = true; |
|||
this->value = value; |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -1,62 +0,0 @@ |
|||
/* |
|||
* DoubleLiteral.h |
|||
* |
|||
* Created on: 03.01.2013 |
|||
* Author: chris |
|||
*/ |
|||
|
|||
#ifndef DOUBLELITERAL_H_ |
|||
#define DOUBLELITERAL_H_ |
|||
|
|||
#include "src/ir/expressions/BaseExpression.h" |
|||
|
|||
#include "boost/lexical_cast.hpp" |
|||
|
|||
namespace storm { |
|||
|
|||
namespace ir { |
|||
|
|||
namespace expressions { |
|||
|
|||
class DoubleLiteral : public BaseExpression { |
|||
public: |
|||
double value; |
|||
|
|||
DoubleLiteral(double value) : BaseExpression(double_), value(value) { |
|||
|
|||
} |
|||
|
|||
virtual ~DoubleLiteral() { |
|||
|
|||
} |
|||
|
|||
virtual std::shared_ptr<BaseExpression> clone(const std::map<std::string, std::string>& renaming, const std::map<std::string, uint_fast64_t>& bools, const std::map<std::string, uint_fast64_t>& ints) { |
|||
return std::shared_ptr<BaseExpression>(new DoubleLiteral(this->value)); |
|||
} |
|||
|
|||
virtual double getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
return value; |
|||
} |
|||
|
|||
virtual void accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
virtual std::string toString() const { |
|||
return boost::lexical_cast<std::string>(value); |
|||
} |
|||
|
|||
virtual std::string dump(std::string prefix) const { |
|||
std::stringstream result; |
|||
result << prefix << "DoubleLiteral " << this->toString() << std::endl; |
|||
return result.str(); |
|||
} |
|||
}; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
#endif /* DOUBLELITERAL_H_ */ |
@ -0,0 +1,40 @@ |
|||
/*
|
|||
* DoubleLiteralExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "DoubleLiteralExpression.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
DoubleLiteralExpression::DoubleLiteralExpression(double value) : BaseExpression(double_), value(value) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
virtual std::shared_ptr<BaseExpression> DoubleLiteralExpression::clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const { |
|||
return std::shared_ptr<BaseExpression>(new DoubleLiteral(this->value)); |
|||
} |
|||
|
|||
virtual double DoubleLiteralExpression::getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
return value; |
|||
} |
|||
|
|||
virtual void DoubleLiteralExpression::accept(ExpressionVisitor* visitor) { |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
virtual std::string DoubleLiteralExpression::toString() const { |
|||
std::stringstream result; |
|||
result << value; |
|||
return result.str(); |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -0,0 +1,46 @@ |
|||
/* |
|||
* DoubleLiteralExpression.h |
|||
* |
|||
* Created on: 03.01.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#ifndef STORM_IR_EXPRESSIONS_DOUBLELITERALEXPRESSION_H_ |
|||
#define STORM_IR_EXPRESSIONS_DOUBLELITERALEXPRESSION_H_ |
|||
|
|||
#include "src/ir/expressions/BaseExpression.h" |
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
/*! |
|||
* A class representing a double literal. |
|||
*/ |
|||
class DoubleLiteralExpression : public BaseExpression { |
|||
public: |
|||
/*! |
|||
* Creates a double literal expression with the given value. |
|||
* |
|||
* @param value The value for the double literal. |
|||
*/ |
|||
DoubleLiteralExpression(double value); |
|||
|
|||
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const override; |
|||
|
|||
virtual double getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const override; |
|||
|
|||
virtual void accept(ExpressionVisitor* visitor) override; |
|||
|
|||
virtual std::string toString() const override; |
|||
|
|||
private: |
|||
// The value of the boolean literal. |
|||
double value; |
|||
}; |
|||
|
|||
} // namespace expressions |
|||
} // namespace ir |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_IR_EXPRESSIONS_DOUBLELITERALEXPRESSION_H_ */ |
@ -0,0 +1,107 @@ |
|||
/*
|
|||
* VariableExpression.cpp |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#include "VariableExpression.h"
|
|||
#include "src/parser/prismparser/VariableState.h"
|
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
namespace expressions { |
|||
|
|||
VariableExpression::VariableExpression(ReturnType type, std::string variableName) : BaseExpression(type), localIndex(0), globalIndex(0), variableName(variableName) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
VariableExpression::VariableExpression(ReturnType type, uint_fast64_t localIndex, uint_fast64_t globalIndex, std::string variableName) |
|||
: BaseExpression(type), localIndex(localIndex), globalIndex(globalIndex), variableName(variableName) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
VariableExpression::VariableExpression(VariableExpression const& oldExpression, std::string const& newName, uint_fast64_t newGlobalIndex) |
|||
: BaseExpression(oldExpression.getType()), localIndex(oldExpression.localIndex), globalIndex(newGlobalIndex), variableName(newName) { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
virtual VariableExpression::~VariableExpression() { |
|||
// Nothing to do here.
|
|||
} |
|||
|
|||
virtual std::shared_ptr<BaseExpression> VariableExpression::clone(std::map<std::string, std::string> const& renaming, VariableState const& variableState) { |
|||
// Perform the proper cloning.
|
|||
auto renamingPair = renaming.find(this->variableName); |
|||
if (renamingPair != renaming.end()) { |
|||
return variableState.getVariableExpression(renamingPair->second); |
|||
} else { |
|||
return variableState.getVariableExpression(this->variableName); |
|||
} |
|||
} |
|||
|
|||
virtual void VariableExpression::accept(ExpressionVisitor* visitor) { |
|||
std::cout << "Visitor!" << std::endl; |
|||
visitor->visit(this); |
|||
} |
|||
|
|||
virtual std::string VariableExpression::toString() const { |
|||
return this->variableName; |
|||
} |
|||
|
|||
virtual std::string VariableExpression::dump(std::string prefix) const { |
|||
std::stringstream result; |
|||
result << prefix << this->variableName << " " << index << std::endl; |
|||
return result.str(); |
|||
} |
|||
|
|||
virtual int_fast64_t VariableExpression::getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (this->getType() != int_) { |
|||
BaseExpression::getValueAsInt(variableValues); |
|||
} |
|||
|
|||
if (variableValues != nullptr) { |
|||
return variableValues->second[globalIndex]; |
|||
} else { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression" |
|||
<< " involving variables without variable values."; |
|||
} |
|||
} |
|||
|
|||
virtual bool VariableExpression::getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (this->getType() != bool_) { |
|||
BaseExpression::getValueAsBool(variableValues); |
|||
} |
|||
|
|||
if (variableValues != nullptr) { |
|||
return variableValues->first[globalIndex]; |
|||
} else { |
|||
throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression" |
|||
<< " involving variables without variable values."; |
|||
} |
|||
} |
|||
|
|||
virtual double VariableExpression::getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const { |
|||
if (this->getType() != double_) { |
|||
BaseExpression::getValueAsDouble(variableValues); |
|||
} |
|||
|
|||
throw storm::exceptions::NotImplementedException() << "Cannot evaluate expression with " |
|||
<< " variable '" << variableName << "' of type double."; |
|||
} |
|||
|
|||
std::string const& VariableExpression::getVariableName() const { |
|||
return variableName; |
|||
} |
|||
|
|||
uint_fast64_t VariableExpression::getLocalVariableIndex() const { |
|||
return this->localIndex; |
|||
} |
|||
|
|||
uint_fast64_t VariableExpression::getGlobalVariableIndex() const { |
|||
return this->globalIndex; |
|||
} |
|||
|
|||
} // namespace expressions
|
|||
} // namespace ir
|
|||
} // namespace storm
|
@ -1,69 +0,0 @@ |
|||
/* |
|||
* VariableStateInterface.h |
|||
* |
|||
* Created on: 10.06.2013 |
|||
* Author: Christian Dehnert |
|||
*/ |
|||
|
|||
#ifndef STORM_IR_VARIABLESTATEINTERFACE_H_ |
|||
#define STORM_IR_VARIABLESTATEINTERFACE_H_ |
|||
|
|||
namespace storm { |
|||
namespace ir { |
|||
|
|||
struct VariableStateInterface { |
|||
/*! |
|||
* Adds an integer variable with the given name, lower and upper bound. |
|||
* |
|||
* @param name The name of the boolean variable to add. |
|||
*/ |
|||
virtual uint_fast64_t addBooleanVariable(std::string const& name) = 0; |
|||
|
|||
/*! |
|||
* Adds an integer variable with the given name, lower and upper bound. |
|||
* |
|||
* @param name The name of the integer variable to add. |
|||
* @param lower The lower bound of the integer variable. |
|||
* @param upper The upper bound of the integer variable. |
|||
*/ |
|||
virtual uint_fast64_t addIntegerVariable(std::string const& name) = 0; |
|||
|
|||
/*! |
|||
* Retrieves the variable expression for the boolean variable with the given name. |
|||
* |
|||
* @param name The name of the boolean variable for which to retrieve the variable expression. |
|||
* @return The variable expression for the boolean variable with the given name. |
|||
*/ |
|||
std::shared_ptr<VariableExpression> getBooleanVariableExpression(std::string const& name) const = 0; |
|||
|
|||
/*! |
|||
* Retrieves the variable expression for the integer variable with the given name. |
|||
* |
|||
* @param name The name of the integer variable for which to retrieve the variable expression. |
|||
* @return The variable expression for the integer variable with the given name. |
|||
*/ |
|||
std::shared_ptr<VariableExpression> getIntegerVariableExpression(std::string const& name) const = 0; |
|||
|
|||
/*! |
|||
* Retrieve the variable expression for the variable with the given name. |
|||
* |
|||
* @param name The name of the variable for which to retrieve the variable expression. |
|||
* @return The variable expression for the variable with the given name. |
|||
*/ |
|||
std::shared_ptr<VariableExpression> getVariableExpression(std::string const& name) const = 0; |
|||
|
|||
/*! |
|||
* Retrieves the next free (global) index for a boolean variable. |
|||
*/ |
|||
virtual uint_fast64_t getNextGlobalBooleanVariableIndex() const = 0; |
|||
|
|||
/*! |
|||
* Retrieves the next free (global) index for a integer variable. |
|||
*/ |
|||
virtual uint_fast64_t getNextGlobalIntegerVariableIndex() const = 0; |
|||
}; |
|||
|
|||
} // namespace ir |
|||
} // namespace storm |
|||
|
|||
#endif /* STORM_IR_VARIABLESTATEINTERFACE_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue