Browse Source

On my way of splitting header/source files in IR to make forward-declaration easy.

main
dehnert 12 years ago
parent
commit
e30c386f23
  1. 7
      src/ir/Module.cpp
  2. 11
      src/ir/Module.h
  3. 71
      src/ir/expressions/BaseExpression.cpp
  4. 211
      src/ir/expressions/BaseExpression.h
  5. 58
      src/ir/expressions/BinaryBooleanFunctionExpression.cpp
  6. 121
      src/ir/expressions/BinaryBooleanFunctionExpression.h
  7. 29
      src/ir/expressions/BinaryExpression.cpp
  8. 70
      src/ir/expressions/BinaryExpression.h
  9. 82
      src/ir/expressions/BinaryNumericalFunctionExpression.cpp
  10. 157
      src/ir/expressions/BinaryNumericalFunctionExpression.h
  11. 66
      src/ir/expressions/BinaryRelationExpression.cpp
  12. 138
      src/ir/expressions/BinaryRelationExpression.h
  13. 62
      src/ir/expressions/BooleanConstantExpression.cpp
  14. 137
      src/ir/expressions/BooleanConstantExpression.h
  15. 62
      src/ir/expressions/BooleanLiteral.h
  16. 40
      src/ir/expressions/BooleanLiteralExpression.cpp
  17. 46
      src/ir/expressions/BooleanLiteralExpression.h
  18. 28
      src/ir/expressions/ConstantExpression.cpp
  19. 84
      src/ir/expressions/ConstantExpression.h
  20. 61
      src/ir/expressions/DoubleConstantExpression.cpp
  21. 130
      src/ir/expressions/DoubleConstantExpression.h
  22. 62
      src/ir/expressions/DoubleLiteral.h
  23. 40
      src/ir/expressions/DoubleLiteralExpression.cpp
  24. 46
      src/ir/expressions/DoubleLiteralExpression.h
  25. 77
      src/ir/expressions/ExpressionVisitor.h
  26. 2
      src/ir/expressions/IntegerConstantExpression.h
  27. 2
      src/ir/expressions/IntegerLiteral.h
  28. 4
      src/ir/expressions/UnaryBooleanFunctionExpression.h
  29. 4
      src/ir/expressions/UnaryNumericalFunctionExpression.h
  30. 107
      src/ir/expressions/VariableExpression.cpp
  31. 166
      src/ir/expressions/VariableExpression.h
  32. 6
      src/parser/prismparser/Includes.h
  33. 6
      src/parser/prismparser/VariableState.h
  34. 69
      src/parser/prismparser/VariableStateInterface.h

7
src/ir/Module.cpp

@ -9,6 +9,7 @@
#include <iostream>
#include "Module.h"
#include "src/parser/prismparser/VariableState.h"
#include "src/exceptions/OutOfRangeException.h"
#include "src/exceptions/InvalidArgumentException.h"
@ -38,7 +39,7 @@ Module::Module(std::string const& moduleName,
this->collectActions();
}
Module::Module(Module const& oldModule, std::string const& newModuleName, std::map<std::string, std::string> const& renaming, std::map<std::string, uint_fast64_t> const& booleanVariableToIndexMap, std::map<std::string, uint_fast64_t> const& integerVariableToIndexMap, std::shared_ptr<VariableStateInterface> const& variableState)
Module::Module(Module const& oldModule, std::string const& newModuleName, std::map<std::string, std::string> const& renaming, std::map<std::string, uint_fast64_t> const& booleanVariableToIndexMap, std::map<std::string, uint_fast64_t> const& integerVariableToIndexMap, parser::prismparser::VariableState const& variableState)
: moduleName(newModuleName), booleanVariableToLocalIndexMap(oldModule.booleanVariableToLocalIndexMap), integerVariableToLocalIndexMap(oldModule.integerVariableToLocalIndexMap) {
LOG4CPLUS_TRACE(logger, "Start renaming " << oldModule.getName() << " to " << moduleName << ".");
@ -52,7 +53,7 @@ Module::Module(Module const& oldModule, std::string const& newModuleName, std::m
throw storm::exceptions::InvalidArgumentException() << "Boolean variable " << moduleName << "." << booleanVariable.getName() << " was not renamed.";
} else {
this->booleanVariables.emplace_back(booleanVariable, renamingPair->second, variableState->getNextGlobalBooleanVariableIndex(), renaming, booleanVariableToIndexMap, integerVariableToIndexMap);
variableState->addBooleanVariable(renamingPair->second);
variableState.addBooleanVariable(renamingPair->second);
}
}
// Now do the same for the integer variables.
@ -64,7 +65,7 @@ Module::Module(Module const& oldModule, std::string const& newModuleName, std::m
throw storm::exceptions::InvalidArgumentException() << "Integer variable " << moduleName << "." << integerVariable.getName() << " was not renamed.";
} else {
this->integerVariables.emplace_back(integerVariable, renamingPair->second, variableState->getNextGlobalIntegerVariableIndex(), renaming, booleanVariableToIndexMap, integerVariableToIndexMap);
variableState->addIntegerVariable(renamingPair->second);
variableState.addIntegerVariable(renamingPair->second);
}
}

11
src/ir/Module.h

@ -14,7 +14,6 @@
#include <vector>
#include <memory>
#include "VariableStateInterface.h"
#include "BooleanVariable.h"
#include "IntegerVariable.h"
#include "Command.h"
@ -22,8 +21,14 @@
namespace storm {
namespace parser {
namespace prismparser {
class VariableState;
} // namespace prismparser
} // namespace parser
namespace ir {
/*!
* A class representing a module.
*/
@ -65,7 +70,7 @@ public:
* @param adder An instance of the VariableAdder interface that keeps track of all the variables in the probabilistic
* program.
*/
Module(Module const& oldModule, std::string const& newModuleName, std::map<std::string, std::string> const& renaming, std::map<std::string, uint_fast64_t> const& booleanVariableToIndexMap, std::map<std::string, uint_fast64_t> const& integerVariableToIndexMap, std::shared_ptr<VariableStateInterface> const& variableState);
Module(Module const& oldModule, std::string const& newModuleName, std::map<std::string, std::string> const& renaming, std::map<std::string, uint_fast64_t> const& booleanVariableToIndexMap, std::map<std::string, uint_fast64_t> const& integerVariableToIndexMap, parser::prismparser::VariableState const& variableState);
/*!
* Retrieves the number of boolean variables in the module.

71
src/ir/expressions/BaseExpression.cpp

@ -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

211
src/ir/expressions/BaseExpression.h

@ -1,5 +1,5 @@
/*
* Expression.h
* BaseExpression.h
*
* Created on: 03.01.2013
* Author: Christian Dehnert
@ -8,98 +8,135 @@
#ifndef STORM_IR_EXPRESSIONS_BASEEXPRESSION_H_
#define STORM_IR_EXPRESSIONS_BASEEXPRESSION_H_
#include "src/exceptions/ExpressionEvaluationException.h"
#include "src/exceptions/NotImplementedException.h"
#include "ExpressionVisitor.h"
#include <string>
#include <vector>
#include <map>
#include <memory>
namespace storm {
namespace ir {
namespace expressions {
class BaseExpression {
public:
enum ReturnType {undefined, bool_, int_, double_};
BaseExpression() : type(undefined) {
}
BaseExpression(ReturnType type) : type(type) {
}
BaseExpression(const BaseExpression& be)
: type(be.type) {
}
virtual ~BaseExpression() {
}
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) = 0;
virtual int_fast64_t 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.";
}
virtual bool 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.";
}
virtual double 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.";
}
virtual void accept(ExpressionVisitor* visitor) {
visitor->visit(this);
}
virtual std::string toString() const = 0;
std::string 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");
}
}
ReturnType getType() const {
return type;
}
virtual std::string dump(std::string prefix) const = 0;
private:
ReturnType type;
};
} // namespace expressions
} // namespace ir
#include "src/exceptions/ExpressionEvaluationException.h"
#include "src/exceptions/NotImplementedException.h"
#include "ExpressionVisitor.h"
namespace storm {
// Forward-declare VariableState.
namespace parser {
namespace prismparser {
class VariableState;
} // namespace prismparser
} // namespace parser
namespace ir {
namespace expressions {
/*!
* The base class for all expressions.
*/
class BaseExpression {
public:
/*!
* Each node in an expression tree has a uniquely defined type from this enum.
*/
enum ReturnType {undefined, bool_, int_, double_};
/*!
* Creates an expression with undefined type.
*/
BaseExpression();
/*!
* Creates an expression with the given type.
*
* @param type The type of the expression.
*/
BaseExpression(ReturnType type);
/*!
* Copy-constructs from the given expression.
*
* @param baseExpression The expression to copy.
*/
BaseExpression(BaseExpression const& baseExpression);
/*!
* Destructor.
*/
virtual ~BaseExpression();
/*!
* Copies the expression tree underneath (including) the current node and performs the provided renaming.
*
* @param renaming A mapping from identifier names to strings they are to be replaced with.
* @param variableState An object knowing about the global variable state.
*/
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const = 0;
/*!
* Retrieves the value of the expression as an integer given the provided variable valuation.
*
* @param variableValues The variable valuation under which to evaluate the expression. If set to null,
* constant expressions can be evaluated without variable values. However, upon encountering a variable
* expression an expression is thrown, because evaluation is impossible without the variable values then.
* @return The value of the expression as an integer.
*/
virtual int_fast64_t getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const;
/*!
* Retrieves the value of the expression as a boolean given the provided variable valuation.
*
* @param variableValues The variable valuation under which to evaluate the expression. If set to null,
* constant expressions can be evaluated without variable values. However, upon encountering a variable
* expression an expression is thrown, because evaluation is impossible without the variable values then.
* @return The value of the expression as a boolean.
*/
virtual bool getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const;
/*!
* Retrieves the value of the expression as a double given the provided variable valuation.
*
* @param variableValues The variable valuation under which to evaluate the expression. If set to null,
* constant expressions can be evaluated without variable values. However, upon encountering a variable
* expression an expression is thrown, because evaluation is impossible without the variable values then.
* @return The value of the expression as a double.
*/
virtual double getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const;
/*!
* Acceptor method for visitor pattern.
*
* @param visitor The visitor that is supposed to visit each node of the expression tree.
*/
virtual void accept(ExpressionVisitor* visitor);
/*!
* Retrieves a string representation of the expression tree underneath the current node.
*
* @return A string representation of the expression tree underneath the current node.
*/
virtual std::string toString() const = 0;
/*!
* Retrieves a string representation of the type to which this node evaluates.
*
* @return A string representation of the type to which this node evaluates.
*/
std::string getTypeName() const;
/*!
* Retrieves the type to which the node evaluates.
*
* @return The type to which the node evaluates.
*/
ReturnType getType() const;
private:
// The type to which this node evaluates.
ReturnType type;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_BASEEXPRESSION_H_ */

58
src/ir/expressions/BinaryBooleanFunctionExpression.cpp

@ -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

121
src/ir/expressions/BinaryBooleanFunctionExpression.h

@ -2,7 +2,7 @@
* BinaryBooleanFunctionExpression.h
*
* Created on: 03.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef STORM_IR_EXPRESSIONS_BINARYBOOLEANFUNCTIONEXPRESSION_H_
@ -10,82 +10,51 @@
#include "src/ir/expressions/BinaryExpression.h"
#include <memory>
#include <sstream>
namespace storm {
namespace ir {
namespace expressions {
class BinaryBooleanFunctionExpression : public BinaryExpression {
public:
enum FunctionType {AND, OR};
BinaryBooleanFunctionExpression(std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right, FunctionType functionType) : BinaryExpression(bool_, left, right), functionType(functionType) {
}
virtual ~BinaryBooleanFunctionExpression() {
}
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 BinaryBooleanFunctionExpression(this->getLeft()->clone(renaming, bools, ints), this->getRight()->clone(renaming, bools, ints), this->functionType));
}
virtual bool 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 << "'.";
}
}
FunctionType getFunctionType() const {
return functionType;
}
virtual void accept(ExpressionVisitor* visitor) {
visitor->visit(this);
}
virtual std::string 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();
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << "BinaryBooleanFunctionExpression" << std::endl;
result << this->getLeft()->dump(prefix + "\t");
switch (functionType) {
case AND: result << prefix << "&" << std::endl; break;
case OR: result << prefix << "|" << std::endl; break;
}
result << this->getRight()->dump(prefix + "\t");
return result.str();
}
private:
FunctionType functionType;
};
} // namespace expressions
} // namespace ir
namespace ir {
namespace expressions {
/*!
* A class representing a binary function expression of boolean type.
*/
class BinaryBooleanFunctionExpression : public BinaryExpression {
public:
/*!
* An enum type specifying the different functions applicable.
*/
enum FunctionType {AND, OR};
/*!
* Creates a binary boolean function expression tree node with the given children and function type.
*
* @param left The left child of the node.
* @param right The right child of the node.
* @param functionType The operator that is to be applied to the two children.
*/
BinaryBooleanFunctionExpression(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right, FunctionType functionType);
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;
/*!
* Retrieves the operator that is associated with this node.
*
* @param The operator that is associated with this node.
*/
FunctionType getFunctionType() const;
virtual void accept(ExpressionVisitor* visitor) override;
virtual std::string toString() const override;
private:
// The operator that is associated with this node.
FunctionType functionType;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_BINARYBOOLEANFUNCTIONEXPRESSION_H_ */

29
src/ir/expressions/BinaryExpression.cpp

@ -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

70
src/ir/expressions/BinaryExpression.h

@ -9,38 +9,48 @@
#define STORM_IR_EXPRESSIONS_BINARYEXPRESSION_H_
#include "src/ir/expressions/BaseExpression.h"
#include <memory>
#include <iostream>
namespace storm {
namespace ir {
namespace expressions {
class BinaryExpression : public BaseExpression {
public:
BinaryExpression(ReturnType type, std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right)
: BaseExpression(type), left(left), right(right) {
}
std::shared_ptr<BaseExpression> const& getLeft() const {
return left;
}
std::shared_ptr<BaseExpression> const& getRight() const {
return right;
}
private:
std::shared_ptr<BaseExpression> left;
std::shared_ptr<BaseExpression> right;
};
} // namespace expressions
} // namespace ir
namespace ir {
namespace expressions {
/*!
* A class representing a generic binary expression.
*/
class BinaryExpression : public BaseExpression {
public:
/*!
* Constructs a binary expression with the given type and children.
* @param type The type of the binary expression.
* @param left The left child of the binary expression.
* @param right The right child of the binary expression.
*/
BinaryExpression(ReturnType type, std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right);
/*!
* Retrieves the left child of the expression node.
*
* @return The left child of the expression node.
*/
std::shared_ptr<BaseExpression> const& getLeft() const;
/*!
* Retrieves the right child of the expression node.
*
* @return The right child of the expression node.
*/
std::shared_ptr<BaseExpression> const& getRight() const;
private:
// The left child of the binary expression.
std::shared_ptr<BaseExpression> left;
// The right child of the binary expression.
std::shared_ptr<BaseExpression> right;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_BINARYEXPRESSION_H_ */

82
src/ir/expressions/BinaryNumericalFunctionExpression.cpp

@ -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

157
src/ir/expressions/BinaryNumericalFunctionExpression.h

@ -2,111 +2,62 @@
* BinaryFunctionExpression.h
*
* Created on: 03.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef BINARYFUNCTIONEXPRESSION_H_
#define BINARYFUNCTIONEXPRESSION_H_
#ifndef STORM_IR_EXPRESSIONS_BINARYFUNCTIONEXPRESSION_H_
#define STORM_IR_EXPRESSIONS_BINARYFUNCTIONEXPRESSION_H_
#include "src/ir/expressions/BaseExpression.h"
#include "src/ir/expressions/BinaryExpression.h"
namespace storm {
namespace ir {
namespace expressions {
class BinaryNumericalFunctionExpression : public BinaryExpression {
public:
enum FunctionType {PLUS, MINUS, TIMES, DIVIDE};
BinaryNumericalFunctionExpression(ReturnType type, std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right, FunctionType functionType) : BinaryExpression(type, left, right), functionType(functionType) {
}
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 BinaryNumericalFunctionExpression(this->getType(), this->getLeft()->clone(renaming, bools, ints), this->getRight()->clone(renaming, bools, ints), this->functionType));
}
virtual ~BinaryNumericalFunctionExpression() {
}
FunctionType getFunctionType() const {
return functionType;
}
virtual int_fast64_t 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 << "'.";
}
}
virtual double 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 << "'.";
}
}
virtual void accept(ExpressionVisitor* visitor) {
visitor->visit(this);
}
virtual std::string toString() const {
std::string 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;
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << "BinaryNumericalFunctionExpression" << std::endl;
result << this->getLeft()->dump(prefix + "\t");
switch (functionType) {
case PLUS: result << prefix << "+" << std::endl; break;
case MINUS: result << prefix << "-" << std::endl; break;
case TIMES: result << prefix << "*" << std::endl; break;
case DIVIDE: result << prefix << "/" << std::endl; break;
}
result << this->getRight()->dump(prefix + "\t");
return result.str();
}
private:
FunctionType functionType;
};
}
}
}
#endif /* BINARYFUNCTIONEXPRESSION_H_ */
namespace ir {
namespace expressions {
/*!
* A class representing a binary function expression of numerical type.
*/
class BinaryNumericalFunctionExpression : public BinaryExpression {
public:
/*!
* An enum type specifying the different functions applicable.
*/
enum FunctionType {PLUS, MINUS, TIMES, DIVIDE};
/*!
* Creates a binary numerical function expression with the given type, children and function type.
*
* @param type The type of the expression tree node.
* @param left The left child of the expression tree node.
* @param right The right child of the expression tree node.
* @param functionType The function that is applied to the children of this node.
*/
BinaryNumericalFunctionExpression(ReturnType type, std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right, FunctionType functionType);
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const override;
/*!
* Retrieves the operator that is associated with this node.
*
* @param The operator that is associated with this node.
*/
FunctionType getFunctionType() const;
virtual int_fast64_t getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) 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 operator that is associated with this node.
FunctionType functionType;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_BINARYFUNCTIONEXPRESSION_H_ */

66
src/ir/expressions/BinaryRelationExpression.cpp

@ -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

138
src/ir/expressions/BinaryRelationExpression.h

@ -2,97 +2,59 @@
* BinaryRelationExpression.h
*
* Created on: 03.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef BINARYRELATIONEXPRESSION_H_
#define BINARYRELATIONEXPRESSION_H_
#ifndef STORM_IR_EXPRESSIONS_BINARYRELATIONEXPRESSION_H_
#define STORM_IR_EXPRESSIONS_BINARYRELATIONEXPRESSION_H_
#include "src/ir/expressions/BinaryExpression.h"
#include <iostream>
namespace storm {
namespace ir {
namespace expressions {
class BinaryRelationExpression : public BinaryExpression {
public:
enum RelationType {EQUAL, NOT_EQUAL, LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL};
BinaryRelationExpression(std::shared_ptr<BaseExpression> left, std::shared_ptr<BaseExpression> right, RelationType relationType) : BinaryExpression(bool_, left, right), relationType(relationType) {
}
virtual ~BinaryRelationExpression() {
}
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 BinaryRelationExpression(this->getLeft()->clone(renaming, bools, ints), this->getRight()->clone(renaming, bools, ints), this->relationType));
}
virtual bool 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 << "'.";
}
}
RelationType getRelationType() const {
return relationType;
}
virtual void accept(ExpressionVisitor* visitor) {
visitor->visit(this);
}
virtual std::string toString() const {
std::string 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;
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << "BinaryRelationExpression" << std::endl;
result << this->getLeft()->dump(prefix + "\t");
switch (relationType) {
case EQUAL: result << prefix << "=" << std::endl; break;
case NOT_EQUAL: result << prefix << "!=" << std::endl; break;
case LESS: result << prefix << "<" << std::endl; break;
case LESS_OR_EQUAL: result << prefix << "<=" << std::endl; break;
case GREATER: result << prefix << ">" << std::endl; break;
case GREATER_OR_EQUAL: result << prefix << ">=" << std::endl; break;
}
result << this->getRight()->dump(prefix + "\t");
return result.str();
}
private:
RelationType relationType;
};
}
}
}
#endif /* BINARYRELATIONEXPRESSION_H_ */
namespace ir {
namespace expressions {
/*!
* A class representing a binary relation expression of boolean type.
*/
class BinaryRelationExpression : public BinaryExpression {
public:
/*!
* An enum type specifying the different relations applicable.
*/
enum RelationType {EQUAL, NOT_EQUAL, LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL};
/*!
* Creates a binary relation expression tree node with the given children and relation type.
*
* @param left The left child of the binary expression.
* @param right The right child of the binary expression.
* @param relationType The type of the relation associated with this node.
*/
BinaryRelationExpression(std::shared_ptr<BaseExpression> const& left, std::shared_ptr<BaseExpression> const& right, RelationType relationType);
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;
/*!
* Retrieves the relation that is associated with this node.
*
* @param The relation that is associated with this node.
*/
RelationType getRelationType() const;
virtual void accept(ExpressionVisitor* visitor) override;
virtual std::string toString() const override;
private:
// The relation operator associated with this node.
RelationType relationType;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_BINARYRELATIONEXPRESSION_H_ */

62
src/ir/expressions/BooleanConstantExpression.cpp

@ -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

137
src/ir/expressions/BooleanConstantExpression.h

@ -2,88 +2,67 @@
* BooleanConstantExpression.h
*
* Created on: 04.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef BOOLEANCONSTANTEXPRESSION_H_
#define BOOLEANCONSTANTEXPRESSION_H_
#ifndef STORM_IR_EXPRESSIONS_BOOLEANCONSTANTEXPRESSION_H_
#define STORM_IR_EXPRESSIONS_BOOLEANCONSTANTEXPRESSION_H_
#include "ConstantExpression.h"
#include <boost/lexical_cast.hpp>
namespace storm {
namespace ir {
namespace expressions {
class BooleanConstantExpression : public ConstantExpression {
public:
BooleanConstantExpression(std::string constantName) : ConstantExpression(bool_, constantName) {
defined = false;
value = false;
}
BooleanConstantExpression(const BooleanConstantExpression& bce)
: ConstantExpression(bce), value(bce.value), defined(bce.defined) {
}
virtual ~BooleanConstantExpression() {
}
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 BooleanConstantExpression(*this));
}
virtual bool 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;
}
}
virtual void accept(ExpressionVisitor* visitor) {
visitor->visit(this);
}
virtual std::string toString() const {
std::string result = this->constantName;
if (defined) {
result += "[" + boost::lexical_cast<std::string>(value) + "]";
}
return result;
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << "BooleanConstantExpression " << this->toString() << std::endl;
return result.str();
}
bool isDefined() {
return defined;
}
bool getValue() {
return value;
}
void define(bool value) {
defined = true;
this->value = value;
}
bool value;
bool defined;
};
}
}
}
#endif /* BOOLEANCONSTANTEXPRESSION_H_ */
namespace ir {
namespace expressions {
/*!
* A class representing a boolean constant expression.
*/
class BooleanConstantExpression : public ConstantExpression {
public:
/*!
* Creates a boolean constant expression with the given constant name.
*
* @param constantName The name of the constant to use.
*/
BooleanConstantExpression(std::string const& constantName);
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;
/*!
* Retrieves whether the constant is defined or not.
*
* @return True if the constant is defined.
*/
bool isDefined() const;
/*!
* Retrieves the value of the constant if it is defined and false otherwise.
*/
bool getValue() const;
/*!
* Defines the constant using the given value.
*
* @param value The value to use for defining the constant.
*/
void define(bool value);
private:
// This member stores the value of the constant if it is defined.
bool value;
// A flag indicating whether the member is defined or not.
bool defined;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_BOOLEANCONSTANTEXPRESSION_H_ */

62
src/ir/expressions/BooleanLiteral.h

@ -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_ */

40
src/ir/expressions/BooleanLiteralExpression.cpp

@ -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

46
src/ir/expressions/BooleanLiteralExpression.h

@ -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_ */

28
src/ir/expressions/ConstantExpression.cpp

@ -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

84
src/ir/expressions/ConstantExpression.h

@ -2,54 +2,48 @@
* ConstantExpression.h
*
* Created on: 03.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef CONSTANTEXPRESSION_H_
#define CONSTANTEXPRESSION_H_
#ifndef STORM_IR_EXPRESSIONS_CONSTANTEXPRESSION_H_
#define STORM_IR_EXPRESSIONS_CONSTANTEXPRESSION_H_
#include "src/ir/expressions/BaseExpression.h"
namespace storm {
namespace ir {
namespace expressions {
class ConstantExpression : public BaseExpression {
public:
std::string constantName;
ConstantExpression(ReturnType type, std::string constantName) : BaseExpression(type), constantName(constantName) {
}
ConstantExpression(const ConstantExpression& ce)
: BaseExpression(ce), constantName(ce.constantName) {
}
virtual ~ConstantExpression() {
}
std::string const& getConstantName() const {
return constantName;
}
virtual std::string toString() const {
return constantName;
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << "ConstantExpression " << this->toString() << std::endl;
return result.str();
}
};
}
}
}
#endif /* CONSTANTEXPRESSION_H_ */
namespace ir {
namespace expressions {
/*!
* A class representing a generic constant expression.
*/
class ConstantExpression : public BaseExpression {
public:
/*!
* Constructs a constant expression of the given type with the given constant name.
*
* @param type The type of the constant.
* @param constantName The name of the constant.
*/
ConstantExpression(ReturnType type, std::string constantName);
/*!
* Retrieves the name of the constant.
*
* @return The name of the constant.
*/
std::string const& getConstantName() const;
virtual std::string toString() const override;
private:
// The name of the constant.
std::string constantName;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_CONSTANTEXPRESSION_H_ */

61
src/ir/expressions/DoubleConstantExpression.cpp

@ -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

130
src/ir/expressions/DoubleConstantExpression.h

@ -2,86 +2,62 @@
* DoubleConstantExpression.h
*
* Created on: 04.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef DOUBLECONSTANTEXPRESSION_H_
#define DOUBLECONSTANTEXPRESSION_H_
#ifndef STORM_IR_EXPRESSIONS_DOUBLECONSTANTEXPRESSION_H_
#define STORM_IR_EXPRESSIONS_DOUBLECONSTANTEXPRESSION_H_
#include "ConstantExpression.h"
namespace storm {
namespace ir {
namespace expressions {
class DoubleConstantExpression : public ConstantExpression {
public:
DoubleConstantExpression(std::string constantName) : ConstantExpression(double_, constantName), defined(false), value(0) {
}
DoubleConstantExpression(const DoubleConstantExpression& dce)
: ConstantExpression(dce), defined(dce.defined), value(dce.value) {
}
virtual ~DoubleConstantExpression() {
}
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 DoubleConstantExpression(*this));
}
virtual double 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 accept(ExpressionVisitor* visitor) {
visitor->visit(this);
}
virtual std::string toString() const {
std::string result = this->constantName;
if (defined) {
result += "[" + boost::lexical_cast<std::string>(value) + "]";
}
return result;
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << "DoubleConstantExpression " << this->toString() << std::endl;
return result.str();
}
bool isDefined() {
return defined;
}
double getValue() {
return value;
}
void define(double value) {
defined = true;
this->value = value;
}
private:
bool defined;
double value;
};
}
}
}
#endif /* DOUBLECONSTANTEXPRESSION_H_ */
namespace ir {
namespace expressions {
/*!
* A class representing a constant expression of type double.
*/
class DoubleConstantExpression : public ConstantExpression {
public:
DoubleConstantExpression(std::string const& constantName);
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;
/*!
* Retrieves whether the constant is defined or not.
*
* @return True if the constant is defined.
*/
bool isDefined() const;
/*!
* Retrieves the value of the constant if it is defined and false otherwise.
*/
double getValue() const;
/*!
* Defines the constant using the given value.
*
* @param value The value to use for defining the constant.
*/
void define(double value);
private:
// This member stores the value of the constant if it is defined.
bool value;
// A flag indicating whether the member is defined or not.
bool defined;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_DOUBLECONSTANTEXPRESSION_H_ */

62
src/ir/expressions/DoubleLiteral.h

@ -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_ */

40
src/ir/expressions/DoubleLiteralExpression.cpp

@ -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

46
src/ir/expressions/DoubleLiteralExpression.h

@ -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_ */

77
src/ir/expressions/ExpressionVisitor.h

@ -9,47 +9,42 @@
#define STORM_IR_EXPRESSIONS_EXPRESSIONVISITOR_H_
namespace storm {
namespace ir {
namespace expressions {
class BaseExpression;
class BinaryBooleanFunctionExpression;
class BinaryNumericalFunctionExpression;
class BinaryRelationExpression;
class BooleanConstantExpression;
class BooleanLiteral;
class DoubleConstantExpression;
class DoubleLiteral;
class IntegerConstantExpression;
class IntegerLiteral;
class UnaryBooleanFunctionExpression;
class UnaryNumericalFunctionExpression;
class VariableExpression;
class ExpressionVisitor {
public:
virtual void visit(BaseExpression* expression) = 0;
virtual void visit(BinaryBooleanFunctionExpression* expression) = 0;
virtual void visit(BinaryNumericalFunctionExpression* expression) = 0;
virtual void visit(BinaryRelationExpression* expression) = 0;
virtual void visit(BooleanConstantExpression* expression) = 0;
virtual void visit(BooleanLiteral* expression) = 0;
virtual void visit(DoubleConstantExpression* expression) = 0;
virtual void visit(DoubleLiteral* expression) = 0;
virtual void visit(IntegerConstantExpression* expression) = 0;
virtual void visit(IntegerLiteral* expression) = 0;
virtual void visit(UnaryBooleanFunctionExpression* expression) = 0;
virtual void visit(UnaryNumericalFunctionExpression* expression) = 0;
virtual void visit(VariableExpression* expression) = 0;
};
} // namespace expressions
} // namespace ir
namespace ir {
namespace expressions {
class BaseExpression;
class BinaryBooleanFunctionExpression;
class BinaryNumericalFunctionExpression;
class BinaryRelationExpression;
class BooleanConstantExpression;
class BooleanLiteral;
class DoubleConstantExpression;
class DoubleLiteral;
class IntegerConstantExpression;
class IntegerLiteral;
class UnaryBooleanFunctionExpression;
class UnaryNumericalFunctionExpression;
class VariableExpression;
class ExpressionVisitor {
public:
virtual void visit(BaseExpression* expression) = 0;
virtual void visit(BinaryBooleanFunctionExpression* expression) = 0;
virtual void visit(BinaryNumericalFunctionExpression* expression) = 0;
virtual void visit(BinaryRelationExpression* expression) = 0;
virtual void visit(BooleanConstantExpression* expression) = 0;
virtual void visit(BooleanLiteral* expression) = 0;
virtual void visit(DoubleConstantExpression* expression) = 0;
virtual void visit(DoubleLiteral* expression) = 0;
virtual void visit(IntegerConstantExpression* expression) = 0;
virtual void visit(IntegerLiteral* expression) = 0;
virtual void visit(UnaryBooleanFunctionExpression* expression) = 0;
virtual void visit(UnaryNumericalFunctionExpression* expression) = 0;
virtual void visit(VariableExpression* expression) = 0;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* STORM_IR_EXPRESSIONS_EXPRESSIONVISITOR_H_ */

2
src/ir/expressions/IntegerConstantExpression.h

@ -28,7 +28,7 @@ public:
}
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) {
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const {
return std::shared_ptr<BaseExpression>(new IntegerConstantExpression(*this));
}

2
src/ir/expressions/IntegerLiteral.h

@ -26,7 +26,7 @@ public:
virtual ~IntegerLiteral() {
}
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) {
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const {
return std::shared_ptr<BaseExpression>(new IntegerLiteral(this->value));
}

4
src/ir/expressions/UnaryBooleanFunctionExpression.h

@ -28,8 +28,8 @@ public:
}
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 UnaryBooleanFunctionExpression(this->getChild()->clone(renaming, bools, ints), this->functionType));
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const {
return std::shared_ptr<BaseExpression>(new UnaryBooleanFunctionExpression(this->getChild()->clone(renaming, variableState), this->functionType));
}
FunctionType getFunctionType() const {

4
src/ir/expressions/UnaryNumericalFunctionExpression.h

@ -28,8 +28,8 @@ public:
}
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 UnaryNumericalFunctionExpression(this->getType(), this->getChild()->clone(renaming, bools, ints), this->functionType));
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const {
return std::shared_ptr<BaseExpression>(new UnaryNumericalFunctionExpression(this->getType(), this->getChild()->clone(renaming, variableState), this->functionType));
}
virtual int_fast64_t getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const {

107
src/ir/expressions/VariableExpression.cpp

@ -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

166
src/ir/expressions/VariableExpression.h

@ -2,7 +2,7 @@
* VariableExpression.h
*
* Created on: 03.01.2013
* Author: chris
* Author: Christian Dehnert
*/
#ifndef VARIABLEEXPRESSION_H_
@ -11,7 +11,6 @@
#include <memory>
#include <iostream>
#include "src/ir/VariableStateInterface.h"
#include "BaseExpression.h"
#include "src/exceptions/InvalidArgumentException.h"
@ -20,124 +19,53 @@
extern log4cplus::Logger logger;
namespace storm {
namespace ir {
namespace expressions {
class VariableExpression : public BaseExpression {
public:
VariableExpression(ReturnType type, std::string variableName) : BaseExpression(type), localIndex(0), globalIndex(0), variableName(variableName) {
// Nothing to do here.
}
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 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() {
// Nothing to do here.
}
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, std::shared_ptr<VariableStateInterface> const& variableState) {
// Perform the proper cloning.
}
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, std::map<std::string, uint_fast64_t> const& booleanVariableToIndexMap, std::map<std::string, uint_fast64_t> const& integerVariableToIndexMap) {
auto renamingPair = renaming.find(this->variableName);
if (renamingPair != renaming.end()) {
if (this->getType() == bool_) {
return std::shared_ptr<BaseExpression>(new VariableExpression(bool_, this->localIndex, booleanVariableToIndexMap.at(renamingPair->second), renamingPair->second));
} else if (this->getType() == int_) {
return std::shared_ptr<BaseExpression>(new VariableExpression(int_, this->localIndex, integerVariableToIndexMap.at(renamingPair->second), renamingPair->second));
} else {
LOG4CPLUS_ERROR(logger, "Renaming variable " << this->variableName << " that is neither bool nor int.");
throw storm::exceptions::InvalidArgumentException() << "Renaming variable " << this->variableName << " that is neither bool nor int.";
}
} else {
return std::shared_ptr<BaseExpression>(new VariableExpression(this->getType(), this->localIndex, this->globalIndex, this->variableName));
}
}
virtual void accept(ExpressionVisitor* visitor) {
std::cout << "Visitor!" << std::endl;
visitor->visit(this);
}
virtual std::string toString() const {
return this->variableName;
}
virtual std::string dump(std::string prefix) const {
std::stringstream result;
result << prefix << this->variableName << " " << index << std::endl;
return result.str();
}
virtual int_fast64_t 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 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 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& getVariableName() const {
return variableName;
}
uint_fast64_t getLocalVariableIndex() const {
return this->localIndex;
}
// Forward-declare VariableState.
namespace parser {
namespace prismparser {
class VariableState;
} // namespace prismparser
} // namespace parser
uint_fast64_t getGlobalVariableIndex() const {
return this->globalIndex;
}
private:
uint_fast64_t localIndex;
uint_fast64_t globalIndex;
std::string variableName;
};
}
}
}
namespace ir {
namespace expressions {
class VariableExpression : public BaseExpression {
public:
VariableExpression(ReturnType type, std::string variableName);
VariableExpression(ReturnType type, uint_fast64_t localIndex, uint_fast64_t globalIndex, std::string variableName);
VariableExpression(VariableExpression const& oldExpression, std::string const& newName, uint_fast64_t newGlobalIndex);
virtual ~VariableExpression();
virtual std::shared_ptr<BaseExpression> clone(std::map<std::string, std::string> const& renaming, parser::prismparser::VariableState const& variableState) const;
virtual void accept(ExpressionVisitor* visitor);
virtual std::string toString() const;
virtual int_fast64_t getValueAsInt(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const;
virtual bool getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const;
virtual double getValueAsDouble(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const;
std::string const& getVariableName() const;
uint_fast64_t getLocalVariableIndex() const;
uint_fast64_t getGlobalVariableIndex() const;
private:
uint_fast64_t localIndex;
uint_fast64_t globalIndex;
std::string variableName;
};
} // namespace expressions
} // namespace ir
} // namespace storm
#endif /* VARIABLEEXPRESSION_H_ */

6
src/parser/prismparser/Includes.h

@ -1,6 +1,6 @@
/*
* File: BoostIncludes.h
* Author: nafur
* File: Includes
* Author: Gereon Kremer
*
* Created on April 10, 2013, 4:46 PM
*/
@ -8,8 +8,6 @@
#ifndef BOOSTINCLUDES_H
#define BOOSTINCLUDES_H
#define DEBUGPRISM
// Used for Boost spirit.
#include <boost/typeof/typeof.hpp>
#include <boost/spirit/include/qi.hpp>

6
src/parser/prismparser/VariableState.h

@ -29,7 +29,7 @@ std::ostream& operator<<(std::ostream& out, qi::symbols<char, T>& symbols);
/*!
* This class contains the internal state that is needed for parsing a PRISM model.
*/
struct VariableState : public storm::ir::VariableAdder {
struct VariableState {
/*!
* Creates a new variable state object. By default, this object will be set to a state in which
@ -115,7 +115,7 @@ struct VariableState : public storm::ir::VariableAdder {
* @param name The name of the variable.
* @return A pair containing the local and global index of the variable.
*/
std::pair<uint_fast64_t, uint_fast64_t> addBooleanVariable(std::string const& name);
virtual std::pair<uint_fast64_t, uint_fast64_t> addBooleanVariable(std::string const& name);
/*!
* Adds a new integer variable with the given name.
@ -123,7 +123,7 @@ struct VariableState : public storm::ir::VariableAdder {
* @param name The name of the variable.
* @return A pair containing the local and global index of the variable.
*/
std::pair<uint_fast64_t, uint_fast64_t> addIntegerVariable(std::string const& name);
virtual std::pair<uint_fast64_t, uint_fast64_t> addIntegerVariable(std::string const& name);
/*!
* Retrieves the variable expression for the boolean variable with the given name.

69
src/parser/prismparser/VariableStateInterface.h

@ -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_ */
Loading…
Cancel
Save